newLISP-TK with syntax highlighting

Notices and updates
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

newLISP-TK with syntax highlighting

Post by HPW »

Inspired from:

http://www.alh.net/newlisp/phpbb/viewtopic.php?t=941

I gave it a try and get it working with a few changes to ctext:

Image

The line numbering is a little side effect! ;-)

Now is there a list what commands are grouped together in what color?
Hans-Peter

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Nice! I see my GTK version gets competition :-)

For the syntax highlighting I used more or less the VIM scheme. So texts between double quotes are highlighted, keywords, and parenthesis. VIM also highlights numbers.

Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

ctext has the following highlight commands:
ctext::addHighlightClass $txt commands blue
  • #ctext::addHighlightClass $txt flags color [list ???]
    #ctext::addHighlightClassWithOnlyCharStart $txt vars color "\$"
    #ctext::addHighlightClassForSpecialChars $txt brackets green {[]{}}
    #ctext::addHighlightClassForRegexp $txt paths lightblue {\.[a-zA-Z0-9\_\-]+}
So I start with the first one.
Another idea is to put the keywords in groups with their own color.
That could happen external in newlisp-tk.config so:

set Ide(newLISPCommands) [list set setq list .....]
set Ide(newLISPControl) [list if while for .....]
Hans-Peter

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Hm, grouping commands will maybe lead you into problems? There are commands which can be used for strings, but also for lists...? So which criteria you have to use?

How does the TK version highlight the syntax anyway? It seems a function within TCL/TK itself? In the GTK version I have to perform the low-level coloring myself.

Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

How does the TK version highlight the syntax anyway? It seems a function within TCL/TK itself?
TCL/TK has grown over years and has a lot of extensions.
ctext is a megawidget and part of TKlib.

http://tcllib.sourceforge.net/doc/ctext.html
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

A bit more work:

Code: Select all

;Helperlisp for getting keywords

(device (open "keywords.txt" "w"))
(dolist (s (symbols)) (if (primitive? (eval s)) (println s)))
(close (device))

(device (open "keywords.tcl" "w"))
(setq commandstring "set Ide(newLISPCommands) [list ")
(dolist (s (symbols)) (if (primitive? (eval s)) (setq commandstring (string commandstring s " "))))
(setq commandstring (string commandstring "]"))
(println commandstring)
(close (device))
You get:
set Ide(newLISPCommands) [list ! != $ % & * + - / < << <= = > >= >> NaN? ^ abs ..... ]

Put in newlsip-tk.config:
set Ide(newLISPCommands) [list ! != $ % & * + - / < << <= = > >= >> NaN? ^ abs ..... ]
set Ide(CommandColor) blue
set Ide(StringColor) orange
set Ide(CommentColor) turquoise4
Using now in newlisp-tk.tcl:

Code: Select all

	ctext::addHighlightClass $txt commands $Ide(CommandColor) $Ide(newLISPCommands)
	ctext::addHighlightClassForSpecialChars $txt paranthesis red {()}
	ctext::addHighlightClassForSpecialChars $txt brackets darkred {[]}
	ctext::addHighlightClassForRegexp $txt dstrings $Ide(StringColor) {\".*\"}
	ctext::addHighlightClassForRegexp $txt cstrings $Ide(StringColor) {{.*}}
	ctext::addHighlightClassForRegexp $txt tstrings $Ide(StringColor) {\[text\].*\[/text\]}
	ctext::addHighlightClassForRegexp $txt comments $Ide(CommentColor) {;.*}
Image

Other ideas for regexpressions for highlighting?

Modified sources (TK V1.34?) here:

http://www.hpwsoft.de//anmeldung//html1 ... Khighl.zip
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Added ctext to the editor:

Image

Don't know why line 1 is not highlighting correctly on a fresh view.
When I edit it then it does it.

I updated:
http://www.hpwsoft.de//anmeldung//html1 ... Khighl.zip
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

I added to the newlisp-tk.config:
set Ide(ConsoleLineMap) 1
set Ide(EditLineMap) 0
Enable/Disable the linemap in console and editor.

(As a workaround I add a \n to the editor-content-begin. Then highlighting does work on the whole content)
There still is a problem with the initial focus, which does not work as before.
I updated:
http://www.hpwsoft.de//anmeldung//html1 ... Khighl.zip
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Very nice! This could go into one of the next versions. Is ctext part of the normal Tcl/Tk 8.4 library? I mean do I get it with the Freewrap distribution? Or would it be an add-on like BWidget?

Lutz

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Is ctext part of the normal Tcl/Tk 8.4 library?
Not absolute sure.
TKlib 0.4 is part of the ActiveState free TCL-distribution.
Freewrap 6.2 states that it is based on 8.4.12 (latest version).
I mean do I get it with the Freewrap distribution? Or would it be an add-on like BWidget?
It could be so. Give it a simple try first.
Anyway it should be easy since it only is a 24 KB pure tcl source.

But there are still the 2 problems with:
Not highlighting first line in editor (my workaround isn't really good)
Initial focus not in console/editor window.

Without that it could get real nice.
Hans-Peter

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

TKlib is a standallown package and not part of the default TclTK distribution.
Though indeed ActiveState links it (as it links all kinds of tk stuff with its distribitions)..

But I think it should not be too difficult to create yours own
Highlighting "widget" inside tk.. (perhaps wiki.tk has some topics..)


Or!! even better.. Rip-out the Ctext part from the TKLib and distribute it
with the newlisp-tk version.. that better i think..

Btw...Nice going HPW ;-)
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

On MacOS X 10.4 it seems to be part of the standard install and is just one file of about 24k: /System/Library/Tcl/tklib0.2/ctext/ctext.tcl

I guess it will work everywhere, not only MacOS X.

Lutz

Locked