.
I never followed through on avoiding the need for the monkey patch. I don't use this code anymore and when I tested it didn't work. I made a small change (highlighted in bold below) and now it is working again. To test it yourself, "Paste as node" the following xml. Then highlight "sol colorizing" node and hit ctrl-b to execute it. Then select "colorizing test" node and see the highlighted date string.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo:
http://leoeditor.com/leo_toc.html -->
<leo_file xmlns:leo="
http://leoeditor.com/namespaces/leo-python-editor/1.1" >
<leo_header file_format="2"/>
<vnodes>
<v t="btheado.20191205134802.1"><vh>colorizing sample</vh>
<v t="btheado.20191205134802.2"><vh>sol colorizing</vh>
<v t="btheado.20191205134802.3"><vh>class sol</vh>
<v t="btheado.20191205134802.4"><vh>timestamp colorizer rules</vh></v>
</v>
<v t="btheado.20191205134802.5"><vh>load rule</vh></v>
</v>
<v t="btheado.20191205134802.6"><vh>colorizing test</vh></v>
</v>
</vnodes>
<tnodes>
<t tx="btheado.20191205134802.1">@language python</t>
<t tx="btheado.20191205134802.2">@others
# Monkey-patch this method to also recognize the
# 'sol' mode as I didn't figure out how to fix this
# in general
def isValidLanguage (self,language):
fn = g.os_path_join(g.app.loadDir,'..','modes','%s.py' % (language))
return g.os_path_exists(fn) or language == 'sol'
from types import MethodType
c.frame.body.colorizer.isValidLanguage = \
MethodType(isValidLanguage, c.frame.body.colorizer)
</t>
<t tx="btheado.20191205134802.3">class sol:
@others</t>
<t tx="btheado.20191205134802.4">@language python
# Leo colorizer control file for sol mode.
# This file is in the public domain.
# This mode colorizes timestamp strings like
# '2011/12/04 20:31:16 -' which appear at the
# start of a line
properties = { }
# Attributes dict for solt_main ruleset.
sol_main_attributes_dict = {
"default": "null",
"digit_re": "",
"escape": "",
"highlight_digits": "false",
"ignore_case": "false",
"no_word_sep": "",
}
# Dictionary of attributes dictionaries for sol mode.
attributesDictDict = {
"sol_main": sol_main_attributes_dict,
}
# Keywords dict for sol_main ruleset.
sol_main_keywords_dict = {}
# Dictionary of keywords dictionaries for sol mode.
keywordsDictDict = {
"sol_main": sol_main_keywords_dict,
}
# Rules for sol_main ruleset.
import leo.core.leoGlobals as g
# Rule for the date/timestamp coloring
def sol_rule0(colorer, s, i):
#re = r"\d{8} \d\d:\d\d:\d\d -"
re = r"\d\d\d\d/?\d\d/?\d\d \d\d:\d\d:\d\d -"
m = colorer.match_seq_regexp(s, i, kind="keyword2", regexp=re,
at_line_start=True, at_whitespace_end=False,
at_word_start=False, delegate="")
return m
# Rule for **bold**
def sol_bold(colorer, s, i):
return colorer.match_seq_regexp(s, i, kind="keyword3", regexp="\\*\\*[^*]+\\*\\*",
at_line_start=False, at_whitespace_end=False, at_word_start=True, delegate="")
# Rule for *italics*
def sol_italics(colorer, s, i):
return colorer.match_seq_regexp(s, i, kind="keyword4", regexp="\\*[^\\s*][^*]*\\*",
at_line_start=False, at_whitespace_end=False, at_word_start=True, delegate="")
# Rules dict for sol_main ruleset. All of the possible first
# matching characters for each rule must have a mapping enumerated
# here. The 'sol_rule0' for example has \d at the front of the
# regexp and so any numeral can match
rulesDict1 = {
"0": [sol_rule0,],
"1": [sol_rule0,],
"2": [sol_rule0,],
"3": [sol_rule0,],
"4": [sol_rule0,],
"5": [sol_rule0,],
"6": [sol_rule0,],
"7": [sol_rule0,],
"8": [sol_rule0,],
"9": [sol_rule0,],
"*": [sol_bold, sol_italics],
}
# x.rulesDictDict for sol mode.
rulesDictDict = {
"sol_main": rulesDict1,
}
# Import dict for sol mode.
importDict = {}
</t>
<t tx="btheado.20191205134802.5">c.frame.body.colorizer.highlighter.
colorizer.init_mode_from_module('sol', sol)</t>
<t tx="btheado.20191205134802.6">@language sol
2013/11/27 14:05:29 - The date string should be highlighted</t>
</tnodes>
</leo_file>