Wednesday, May 23, 2012

syntax highlighting question

Lisp symbols can usually contain ':', but I'm using a dialect where
':' is special syntax. I'd like to highlight it like parens.


A) My first attempt was the following:

au BufReadPost *.lisp syntax match Delimiter /:/

(The autocmd is to apply this after any other settings.)

This works on the following file x.lisp:

abc:def

The ':' is highlighted as expected.


B) However, it doesn't work inside lists:

(abc:def)

Now the ':' isn't highlighted.

I used this awesome tip to see what was going on:
http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor.
Position cursor on the unhighlighted ':', hit <F10> and it shows me
that it thinks the ':' belongs to lispSymbol.

So I dug into the definition of lispSymbol and updated it to not include ':'

au BufReadPost *.lisp syn clear lispSymbol
au BufReadPost *.lisp syn match lispSymbol contained ![^()'`,"; \t:]\+!


C) Still no dice. <F10> now shows ':' inside lists to be of type
lispList. Turns out I need to tell vim that lispList can contain
Delimiters:
au BufReadPost *.lisp syn cluster lispListCluster add=Delimiter

It works!


D) Now I want to make sure a leading ':' at the start of a symbol *is*
treated as part of the symbol. So we only highlight ':' in the middle
or end of a word.

au BufReadPost *.lisp syn match Delimiter /[^ ]\zs:/

But this again doesn't work inside lists. <F10> shows the ':' is
considered part of lispList just as before I made change (C).

Anybody have any ideas on why? I've attached both the test vimrc and
test x.lisp file. I'm using vim 7.3 and have tested it with the latest
runtime files.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment