Debug UDL language styling

Posted by toddw on 2010-01-07 19:48

How can I visualize how Komodo is styling (colorizing) my files?


Here is a helper macro to be able to see exactly how Komodo is styling the current editor document. Just drag/drop the visualize styling.kpz into Komodo (or alternatively place the below code into a new Python macro in your Komodo toolbox).

The code is shown below for easy viewing:

from xpcom.server import UnwrapObject
from komodo import components, document

# Convert the current editor document to html.
buf = UnwrapObject(document.ciBuf)
html = buf.to_html(include_styling=True, include_html=True,
                   title=document.baseName, do_trg=False, do_eval=False)

# Write the html to a file.
fileSvc = components.classes[";1"].getService(components.interfaces.koIFileService)
f = fileSvc.makeTempFile(".html", "w")

# Open it in the default web browser.
webbrowser = components.classes[';1'].getService(components.interfaces.koIWebbrowser)


  • double-click on the macro
  • after a few seconds a new html page should be opened in your default browser
  • hovering over pieces of the html text will show what the underlying style name is (displayed in the upper right hand corner)

You can also tweak the html settings (do_trg and do_eval to True) to show codeintel completion points and the evaluation data (completion data and calltips). Neat huh?

visualize styling.kpz1.34 KB

ActiveState Staff
Fri, 2010-01-08 16:55

If you get a macro error such as:
AttributeError: 'NoneType' object has no attribute 'tokenize_by_style'

It's likely that your not using a UDL based language (or one of the main Komodo dynamic languages - Perl, Python, etc...) or that your language extension is not getting registered correctly.

mozey | Sun, 2011-05-29 08:56

I get the attribute error for *.txt. But when running this macro for *.py nothing happens. Should it also work in Komodo Edit 6?