Monday, June 18, 2012

Re: syntax highlighting question

On 24/05/12 9:29 AM, Kartik Agaram wrote:
> 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.

I tried this (I changed the way autocommands were handled so I could
easily source the file multiple times while testing):

augroup Test
au!
au BufReadPost *.lisp call MyLispModifications()
augroup END
func! MyLispModifications()
syn clear lispSymbol
syn match lispSymbol contained !:\?[^()'`,"; \t:]\+!
syn match Delimiter /\(\<\)\@!:/
syn cluster lispListCluster add=Delimiter
endfunc

Note that the ordering of the syn commands is important.

The combination of optionally including : in a symbol, and not
recognising it as a delimiter at the beginning of a word seems to do the
trick for me.

Ben.



--
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