문제

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.

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top