This thread may interest you: "Defining colorizer modes in @script" https://groups.google.com/d/msg/leo-editor/X9tjxbOq6es/lxyaIooWQzsJ.
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> On Thu, Dec 5, 2019 at 4:51 AM gar <[email protected]> wrote: > What I've discovered. > > There are 3 coloring engines are in leo: > * *jedit* (default and fallback) > * *pygments* (@bool use-pygments) > * *scintilla* (@bool qt-use-scintilla) > > jedit engine can be customized via changing the parts of leo distr (so you > cannot keep it around w/o polluting leo's sources). > pygments has disgusting coloring for anything different from python. > scintilla is critically outdated and cannot be used at all. > > So despite the choice availble - there's actually no choice. All end user > is suitable for is jedit colorizer. > So I am going to adopt it for my needs. And maybe later I'll get an idea > how to avoid polluting leo's git. > > A hope left that pygments can be in any way configured (installing > pygments-lexer-babylon didnt help). I'll be investigating further more. > > -- > You received this message because you are subscribed to the Google Groups > "leo-editor" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/leo-editor/1560bb5e-6e66-465f-9593-10de1266ec33%40googlegroups.com > <https://groups.google.com/d/msgid/leo-editor/1560bb5e-6e66-465f-9593-10de1266ec33%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/CAO5X8CyTL-Sw3X_E5eiL%3Dr-%3DC_CJd%3Divd9mVPK34A1ggkwr%2B%2BA%40mail.gmail.com.
