Lisp HUG Maillist Archive

Changing editor behavior and syntax highlighting

Hi,

I wrote a reader macro to be able to write objective c syntax inline, for example

[[NSColor colorWithDeviceRed: 0.1 green: 0.2 blue: 0.3 alpha: 0.4] redComponent]
which expands to
(objc:invoke (objc:invoke "NSColor" "colorWithDeviceRed:green:blue:alpha:" 0.1 0.2 0.3 0.4) "redComponent")

(If anyone's interested, I can post the macro definition)


Now, despite its elegancy, it's not quite as useful as it could be, because the LW editor (of course) doesn't recognize the objective c syntax. In particular:
1) The brackets are not treated like parens (you cannot double click them, balancing is not enforced etc)
2) Indentation doesn't work (probably because of 1)
3) There is no syntax highlighting, so the named parameters in the above statement are in a way *less* readable than with the default obj:invoke syntax


I'm not aiming for using the LW editor to replace XCode, so I don't expect or need it to have a very "intelligent" behavior in this case. Rather, I would be very happy with a simple solution that works in most cases. So I thought the following would do the trick:
1) Treat all brackets as parenthesis
2) Highlight all words ending with a colon

This won't break much, as brackets are rarely used, and space is normally not allowed after a colon.


So I looked into the editor source code that comes with the LW distribution. But while it is indeed interesting to read, it doesn't compile! I ran into some undefined macros, which I found in user-macros.lisp, but the function move-syntax-table is also missing, and the definition is not present in any of the source files.

A hack for 1) was given in this thread (a long time ago, admittedly):

http://osdir.com/ml/lisp.lispworks.general/2002-05/msg00037.html

But it doesn't work, for the same reason – move-syntax-table is missing.


Anyone with experience of these sort of things?

Erik



_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Changing editor behavior and syntax highlighting

Hi!
1.
> Treat all brackets as parenthesis
(editor::set-vector-value
 (slot-value editor::*default-syntax-table* 'editor::table) '(#\[ #\{) 2)
(editor::set-vector-value
 (slot-value editor::*default-syntax-table* 'editor::table) '(#\] #\}) 3)

This works at global level and satisfies me.

2. There is an example of custom syntax highlighting in an examples directory:
..../examples/editor/syntax-coloring

AFAIK it compiles.

For highlighting to work automatically, some additional work is
required. I don't know how to do that.

Try inspecting editor::*mode-names*. Traversing its value you'll get
access to mode objects. Necessary fontifying functions and data are
stored there.

Maybe you'd try to convert existing lisp mode into Objective C mode.
If editor source does not compile, you can at least try to use
defadvice on some functions and alter some data.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:34 UTC