Incorrect preprocessor highlighting in cpp filetype

2011-09-05 Thread François Ingelrest
Hi all,

The following code is highlighted incorrectly when using the cpp filetype:

#if defined FOO
#elif defined BAR
#endif

The part "defined BAR" is not highlighted, while "defined FOO" is.
AFAICT, my runtime files are up to date.

I don't know much about Vim syntax files, so I can't tell where
exactly is the problem.

-- 
You received this message from the "vim_dev" 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


Re: Incorrect preprocessor highlighting in cpp filetype

2011-09-05 Thread Christian Brabandt
Hi François!

On Mo, 05 Sep 2011, François Ingelrest wrote:

> Hi all,
> 
> The following code is highlighted incorrectly when using the cpp filetype:
> 
> #if defined FOO
> #elif defined BAR
> #endif
> 
> The part "defined BAR" is not highlighted, while "defined FOO" is.
> AFAICT, my runtime files are up to date.
> 
> I don't know much about Vim syntax files, so I can't tell where
> exactly is the problem.

Hm, I think, the syn match takes precedence over the defined region 
there. If one makes the regular expression for the syn-match tighter, it 
should work. Something like this seems to work:

chrisbra@R500 ~/local/share/vim/vim73/syntax % diff -u c.vim{,.new}
--- c.vim   2011-09-05 10:23:24.074758311 +0200
+++ c.vim.new   2011-09-05 10:23:21.584754659 +0200
@@ -273,7 +273,7 @@
 
 " Accept %: for # (C99)
 syn region cPreCondit  
start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" 
keepend 
contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
-syn match  cPreConditMatch display 
"^\s*\(%:\|#\)\s*\(else\|endif\|elif\)\>"
+syn match  cPreConditMatch display 
"^\s*\(%:\|#\)\s*\(else\|endif\|elif\)\>$"
 if !exists("c_no_if0")
   syn cluster  cCppOutInGroup  
contains=cCppInIf,cCppInElse,cCppInElse2,cCppOutIf,cCppOutIf2,cCppOutElse,cCppInSkip,cCppOutSkip
   syn region   cCppOutWrapper  
start="^\s*\(%:\|#\)\s*if\s\+0\+\s*\($\|//\|/\*\|&\)" end=".\@=\|$" 
contains=cCppOutIf,cCppOutElse fold

But Bram knows best, whether this is right.

regards,
Christian

-- 
You received this message from the "vim_dev" 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


Re: Incorrect preprocessor highlighting in cpp filetype

2011-09-07 Thread Bram Moolenaar

Christian Brabandt wrote:

> Hi François!
> 
> On Mo, 05 Sep 2011, François Ingelrest wrote:
> 
> > Hi all,
> > 
> > The following code is highlighted incorrectly when using the cpp filetype:
> > 
> > #if defined FOO
> > #elif defined BAR
> > #endif
> > 
> > The part "defined BAR" is not highlighted, while "defined FOO" is.
> > AFAICT, my runtime files are up to date.
> > 
> > I don't know much about Vim syntax files, so I can't tell where
> > exactly is the problem.
> 
> Hm, I think, the syn match takes precedence over the defined region 
> there. If one makes the regular expression for the syn-match tighter, it 
> should work. Something like this seems to work:

The "elif" should not be in the cPreConditMatch rule, it's already in
the rule just above it.  Thanks for the hint though.

-- 
Managers are like cats in a litter box.  They instinctively shuffle things
around to conceal what they've done.
(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
You received this message from the "vim_dev" 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