Enhancing color scheme

79 views
Skip to first unread message

gar

unread,
Dec 2, 2019, 3:38:31 AM12/2/19
to leo-editor
Good time of day, leo people.

I find color schemes supplied with the leo's distr poor for some languages (for example, javascript still knows nothing about es6/es7, and markdown ignores back quotes) and want to enhance them (and even introduce some more).
I found the document which describes the design of the colorers (https://leoeditor.com/coloring.html#settings-for-syntax-coloring), but it says nothing about what to do in terms of applying the changes.

How should I use changed version? I should edit files in the git repo and then make a pull request?
Or I may create my version of syntax coloring and setup some config option to tell leo use it, leaving core file untouched?
What is the leo way of changing syntax highlighting?

Thanks in advance!

gar

unread,
Dec 5, 2019, 4:51:16 AM12/5/19
to leo-editor
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.

Brian Theado

unread,
Dec 5, 2019, 1:53:38 PM12/5/19
to leo-editor
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>

--
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 leo-editor+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/1560bb5e-6e66-465f-9593-10de1266ec33%40googlegroups.com.

gar

unread,
Dec 5, 2019, 2:53:21 PM12/5/19
to leo-editor
Thanks!
But how can I paste raw xml as a node? Couldnt even imagine that this were possible....

четверг, 5 декабря 2019 г., 21:53:38 UTC+3 пользователь btheado написал:

Brian Theado

unread,
Dec 5, 2019, 3:01:03 PM12/5/19
to leo-editor
Copy the xml text to your clipboard. Open a leo outline and hit ctrl-shift-C. Or right click on a node and select "Paste Node"

--
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 leo-editor+...@googlegroups.com.

Brian Theado

unread,
Dec 5, 2019, 3:05:06 PM12/5/19
to leo-editor
Sorry, I meant ctrl-shift-V

gar

unread,
Dec 5, 2019, 3:27:54 PM12/5/19
to leo-editor
wow, thanks, it works!
going to investigate it
will write back when understand anything

gar

unread,
Dec 6, 2019, 2:56:55 AM12/6/19
to leo-editor
Fantastic, thanks a lot! I am very poor pythonista and learnt something new from your code.
It creates a new dialect from nothing, and that's cool.
But... how can I patch existing dialect? Acquire it, re-define methods of interest and hope that it would work?

четверг, 5 декабря 2019 г., 21:53:38 UTC+3 пользователь btheado написал:
This thread may interest you: "Defining colorizer modes in @script" https://groups.google.com/d/msg/leo-editor/X9tjxbOq6es/lxyaIooWQzsJ.

Brian Theado

unread,
Dec 6, 2019, 10:37:42 AM12/6/19
to leo-editor
gar,

Previously, you wrote this:

> I find color schemes supplied with the leo's distr poor for some languages (for example,
>javascript still knows nothing about es6/es7, and markdown ignores back quotes) and want to
> enhance them (and even introduce some more).

> How should I use changed version? I should edit files in the git repo and then make a pull request?

It sounds like you are making improvements which would benefit everyone. IMO, for those cases it would make sense to edit the files in the git repo and make a pull request.

Brian


--
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 leo-editor+...@googlegroups.com.

gar

unread,
Dec 6, 2019, 10:54:45 AM12/6/19
to leo-e...@googlegroups.com
Brian,
ok, I'll try to implement it.
For now I really miss js/es6/es7 keywords and would love to learn jEdit colorer to highlight them.
But first I want to run pygments colorer and understand how it works. Edward made a great amount of work on it and it must work good, I just failed to understand how to run it.

пт, 6 дек. 2019 г. в 18:37, Brian Theado <brian....@gmail.com>:
Reply all
Reply to author
Forward
0 new messages