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:
# 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["@activestate.com/koFileService;1"].getService(components.interfaces.koIFileService)
f = fileSvc.makeTempFile(".html", "w")
f.puts(html.encode("utf-8"))
f.close()
# Open it in the default web browser.
webbrowser = components.classes['@activestate.com/koWebbrowser;1'].getService(components.interfaces.koIWebbrowser)
webbrowser.open_new(f.path)
Usage:
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?
| Attachment | Size |
|---|---|
| visualize styling.kpz | 1.34 KB |
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.
I get the attribute error for *.txt. But when running this macro for *.py nothing happens. Should it also work in Komodo Edit 6?