[Idle-dev] re: User-defined "keywords"

Arthur ajsiegel at optonline.net
Wed Feb 25 09:55:19 EST 2004

I had written -

>Hi all.

>I had found that I missed, in IDLE, the ability to define domain 
>specific keywords for highlighting, ala Scite and TextPad.

>I discover that doing so by hand is quite simple enough:

> -  provide ColorDelegator.py with lists of keywords,
>    e.g.  KEYWORD2 = ["newkw1", newkw2"]

> -  add a line to make_pat:
>        kw2= r"\b" + any("KEYWORD2", pygeokeys.KEYWORD2) + r"\b" 

> -  edit the make_pat return
>        return kw + "|" + kw2 ....

>-   provide self.tagdefs in LoadTagDefs a tag:
>        "KEYWORD2": {'background':'ffffff','foreground':'#007FFF'},

>The end

A little further delving let's me understand that what I am after is even
closer than I had originally thought. (I am really just getting my feet wet
as to the features of the new Idle).

By simply placing a config-extensions.cfg file in my .idlerc directory with
the format



the new levels of "keywords" become available to ColorDelegator.py.

add to make_pat:

kw2= r"\b" + any("KEYWORD2",
idleConf.GetOption('extensions','Keyword2','kw2')) + \b"

etc. (how many levels should be made possible?)

edit the make_pat return to:

    return kw + "|" + kw2 + ...

And use a config-highlight.cfg file in .ilderc to specify color options for
the extensions keyword levels and have them picked up in the LoadTags method
(2 lines of code).

It seems to me (this isn't fully tested) if no such files exist, there is no
impact, i.e.  no additional testing code necessary.  If the files are there
they have the intended functionality.  (It may however be cleanest, or even
necessary to add kw2 ...  to the default highlighting themes). 

If the extension and user files are not present, we go on exactly as before.

Seems to me a no lose situation: negligible touching of existing code,
useful and high impact feature addition. 

So - 

Am I going over old ground, somehow?

Is the availability of this feature consistent with Idle intentions?  It
seems to me it is  - consistent, for example, with the ability to add user
defined help files.

Is there a technical or other downside I am missing? Perhaps what I am after
can be accomplished purely as an extension with no need to touch the code
base? If so, I don't see it.


More information about the IDLE-dev mailing list