The hl_tcl v0.9.44 package is a syntax highlighter for Tcl/Tk code.
Note that hl_tcl is contained in apave package as sort of subpackage and can be used independently. On the other hand, having installed apave, you need not to install hl_tcl.
The hl_tcl can be applied to a Tk text widget or to a static html page.
The Tk text widget may be made read-only or editable. Also, the hl_tcl may take an argument, sort of command to watch the viewing / editing.
When applied to html pages, the hl_tcl highlights Tcl/Tk code snippets embedded between <code> </code> tags.
The hl_tcl has highlighted its own code in Reference .
The Tcl being incredibly dynamic language sets a lot of problems before any Tcl syntax highlighter. Probably, the usage of quotes and esp. the strings spanning several lines are the main challenges.
Below is a line that brings most (not hl_tcl, as seen in Reference ) of Tcl highlighters in a stupor:
if {[set i [string first {"} $line $i]]==-1} {return no}
... as well as this one:
regsub -all {(([^A-Z@]|\\@)[.?!]("|'|'')?([])])?) } $fieldText {\1 } fieldText
Good luck for a highlighter when the second line (or similar) follows the first, giving it a matching quote and thus bringing it out of the stupor.
Those orphan quotes are often used in regexp and regsub Tcl commands, so that when a honest Tcl highlighter (like Geany ) stumbles upon an orphan quote, it tries its best to highlight the rest of code as a string, till the next unmatched quote.
Thus, we have
... instead of
There are "tricky" highlighters (like Gedit ) that behave more wisely at the stumbling an orphan quote: they permit only a one-line Tcl strings (if not continued with \), so that the string highlighting would be most likely finished in the same line it started. No problems except for this silly line. And no delays due to the highlighting the rest of code...
... as seen in:
alited. Probably, the best lite IDE for Tcl/Tk programming. The alited uses hl_tcl package. That's it.
Geany IDE . The great programming tool of general purpose. And excellent Tcl/Tk highlighter. Still, it has few drawbacks:
Vim . Probably, the fastest Tcl highlighter. Great and awful. Nonetheless:
Kate . As nearly good as Geany. As nearly florid as Vim (set set set). Doesn't highlight ttk and TclOO.
TKE . Written in Tcl/Tk, it might be the best of all to highlight the Tcl/Tk. In spite of its suspended state it still can. Has issues with highlighting strings and the performance.
Pluma and Gedit seem to use the same Tcl highlighting engine that gives rather good results. Still, the mentioned above drawbacks are here too. And no highlighting of tk, ttk, TclOO.
Notepad++ . Very fast Tcl highlighter. And very basic. All the same drawbacks. No highlighting of tk, ttk, TclOO. Plus an obsolete version of Tcl, i.e. no highlighting lset, lassign etc.
To develop an ideal (correct and fast) Tcl/Tk highlighter, we would have to dive into Tcl core. Though, no hopes to achieve the ideal through repeating the core in Tcl/Tk or massively using the regular expressions.
That said, while implementing Tcl/Tk highlighter in pure Tcl/Tk, we might hope to achieve a reasonable compromise between the performance and the elimination of blunders.
It seems hl_tcl got close to this compromise. Specifically, it provides:
The hl_tcl doesn't provide the following:
These are in no way critical drawbacks. A little less florid Tcl code might be even preferable for other tastes.
The Tcl can arrange its pitfalls for hl_tcl (I know where). Also, tricky practices or tastes can make a fool of hl_tcl. Still hopefully these pranks are few and rare to encounter.
The code below:
package require hl_tcl proc ::stub {} {puts "stub: [$::txt index end]"} ::hl_tcl::hl_init $::txt -readonly yes -cmd ::stub #... inserting a text into the text widget ::hl_tcl::hl_text $::txt $readonly $multi ::stub
sets an example of hl_tcl usage. Here are the details:
The hl_init takes arguments:
The args is a list of -option value where -option may be:
The rest of hl_tcl procedures are:
See details in Reference .
In the hl_tcl.zip , there is a Tcl script named tcl_html.tcl that highlights Tcl snippets of static html page(s).
It runs as follows:
tclsh tcl_html.tcl "glob-pattern-of-html-files"
For example:
tclsh ~/UTILS/hl_tcl/tcl_html.tcl "~/UTILS/mulster/tasks/ruff/src/*"
In this example, the html files are located in ~/UTILS/mulster/tasks/ruff/src.
Perhaps, you would want to modify the tcl_html.tcl, then try and go this way:
These are arguments of ::hl_tcl_html::highlight procedure. The tag pairs can be multiple if the html pages contain them, e.g.:
::hl_tcl_html::highlight $fhtml no \ {<code class="tcl">} {</code>} \ {<pre class="code">} {</pre>}
Note that hl_tcl is still disposed to be updated.