Thiiink: Ideas, Imagination, and Innovation in GIS


Self Scheming
June 6, 2009, 9:40 am
Filed under: Python

Anyone working with schemes for Python in Komodo would likely have seen the keywords2 entry in the Element Type (Edit Preferences>Fonts and Colors>Lang-Specific) drop down.  For the longest time I was wondering what was in this list of keywords so I spent some time on the ActiveState forums to see what could be found.

All I was able to unearth was a short post from the development team mentioning the koPythonLanguage.py file that lives under the installation folder.  Poking around a bit I found that by default there are no values in keyword2  (note that in another post I see that keywords2 might be deprecated, sure hope not it is quite useful!). 

The post didn’t specifically say what needed to be changed but I was able to find some similarities in the other Python files living in the same folder.  I should mention that my motivation here was to get some specific keywords highlighted, well, maybe they aren’t real keywords but they are “by convention” keywords and it is really handy to be able to see these more clearly when working.

Cutting to the chase, to make the keywords2 element type behave as expected (aka do something) then all you need to do is add a line into the KoPythonLexerLanguageService class (line 75 in the screen capture below).

image

As you can see the self and cls keywords have been added and now I’m able to add highlighting to these.  Another nice thing in the koPythonLanguage.py file is the Python Sample Text, I’ve updated mine so that I have decorator and number examples.

image