I am going to edit the original question for clarity.  Everything in 
[square brackets] are my edits. Please correct me if I have misunderstood 
anything.

This is a very interesting question.  It raises possibilities that I never 
considered before.

On Wednesday, November 29, 2017 at 7:21:17 AM UTC-6, Zoom.Quiet wrote:

> config leo/modes/python.py [contains this] Syntax coloring [table]:

# Keywords dict for python_main ruleset.
python_main_keywords_dict = {
    "ArithmeticError": "keyword3",
    "AssertionError": "keyword3",
    "AttributeError": "keyword3",
    [big snip]

> [I would like to add the following entries...to color other things:]
 
   "self": "keyword4",
   "format": "keyword4",
   "LOG": "keyword4",

> [Extending this idea, I would like to syntax color the following 
everywhere]:

XCFG.SMCeTS

> XCFG means this is [a] global object [imported] from far away.  [I want 
to bind an alert color to it].

> [Is this possible? Does the python_main_keywords_dict...support regular 
expressions?]

A great question!  I never considered patching the tables as you suggest, 
but this definitely is possible.

The keys in the python_main_keywords_dict must be strings, not regular 
expressions.  However, it definitely would be possible to add entries to 
the rules dict:

# Rules dict for python_main ruleset.
rulesDict1 = {
    ...
}

The keys are lead-in-characters, the values are rules.

As you can see, python_rule21 handles all python identifiers.  You could 
add a new rule, say python_zoom_rule1, to all the entries in rulesDict1 
that contain python_rule_21 as a value.

Here is tested code:

import leo.modes.python as py

def python_zoom_rule1(self, s, i):
    '''See jedit.match_keywords for a template.'''
    g.trace(i, repr(s[i:]))
    return 0 # Fail
   
d = py.rulesDict1
for key, val in d.items():
    print('key', repr(val))
    if val and py.python_rule21 in val:
        val.insert(0, python_zoom_rule1)
        d[key] = val

g.printList(d)

This does patch the tables correctly, but it doesn't look like the 
colorizer ever executes python_zoom_rule1. This is likely due to caching in 
Leo's colorizer.

I have to go now, but I'm pretty sure that the patches can be made to 
work.  I have created #613 
<https://github.com/leo-editor/leo-editor/issues/613> to discuss this topic.

Edward

-- 
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to