I try to extend the cmake syntax highlighting by our in-house cmake functions. For this I drafted a file to be saved in ~/.vim/after/syntax/cmake.vim
, such that one extends the default cmake syntax highlighting, as suggested in this stackoverflow post.
What I am struggeling with is that we use INCLUDE_DIRS
as keyword, whereas standard cmake uses INCLUDE_DIRECTORIES
, and I want the syntax highlighting to point out to a developer that they used the wrong convention for the function at hand. (Yes, I could also try to push towards fixing our inhouse style, but the general problem of what-are-possible-keywords-here would remain).
The standard cmake syntax file I'm testing against is here
So, I want
add_library( # this is a standard cmake function
....
INCLUDE_DIRECTORIES somepath # highlight the first word here, it's spelled right
INCLUDE_DIRS otherpath # don't highlight this, it's spelled wrong
)
fancy_wrapper( # this is from the inhouse modules
...
INCLUDE_DIRECTORIES somepath # don't highlight
INCLUDE_DIRS otherpath) # highlight
)
My understanding was that I can use in my extension the following:
if exists("b:current_syntax")
if b:current_syntax != "cmake"
finish
endif
endif
let s:keepcpo= &cpo
set cpo&vim
syn region OurArgs start="(" end=")" contains=OurArguments
syn case match
syn keyword OurArguments contained
\ INCLUDE_DIRS
syn case ignore
syn keyword cmakeOurs
\ fancy_wrapper
\ nextgroup=OurArgs
hi def link cmakeOurs Function
hi def link OurArguments ModeMsg
let &cpo = s:keepcpo
unlet s:keepcpo
my understanding is that fancy_wrapper
now gets recognised as an inhouse function and the next group will be a OurArgs
region instead of the normal cmakeArguments
. And for the normal add_library
the official cmake style should kick in (copy and pasting their code):
syn keyword cmakeCommand
...
\ add_library
...
\ nextgroup=cmakeArguments
Such that the parentheses thereafter are a cmakeArguments
region and INCLUDE_DIRECTORIES
gets recognized therein.
However, what I observe is that INCLUDE_DIRECTORIES
never gets highlighted and INCLUDE_DIRS
always gets highlighted. Using the debugging hints here) I see that the region after add_library
is recognized as OurArgs
(last definition taking precedence, afaiu. instead of - what i had hoped - the nextgroup
deciding what happens).
So my question is:
- How can I highlight different sets of keywords within parentheses regions, that all look the same in
start=
andend=
? Is that not whatnextgroup
is good for? - Ideally (depending how the answer on the first turns out), can I still do that without modifying kitware's cmake.vim file?