Question

I am implementing a syntax highlight for a proprietary C expansion that we use in VIM.
The syntax is this:

int __event(foobar) my_foobar_function()
{
    //whatever
    if(foobar)
        // do something
}

Now what I would like to do is to highlight __event(foobar), so I wrote this:

syn region xREG start=/__event(/ end=/)/ contains=xFOO
syn keyword xFOO foobar contained

hi xREG ctermfg=darkblue
hi xFOO ctermfg=cyan

This highlights the __event() correctly, however, the foobar in if(foobar) also gets highlighted.

My question is how can I restrict the xFOO group to be highlighted ONLY in xREG and nowhere else.

Thank you.

Était-ce utile?

La solution

When you extend an existing syntax (like C), you need to consider the existing syntax items. The following line from syntax/c.vim causes the inclusion of your xFOO group via the ALLBUT=:

syn region  cParen      transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell

Fortunately, it provides an extension point: You have to add your group to the @cParenGroup cluster:

syn cluster cParenGroup add=xFoo

That should do the trick!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top