Monday, February 21, 2011

Re: C syntax, and spurious semicolons

> On Mon, Feb 21, 2011 at 4:56 PM, Ben Schmidt <mail_ben_schmidt@yahoo.com.au
> <mailto:mail_ben_schmidt@yahoo.com.au>> wrote:
>
> If you only concern about the semicolon after if statements,
> you can try add following to your vimrc file:
>
> autocmd BufEnter *.c match Grp_semi /if\s*(.\+)\s*;/
> highlight Grp_semi guibg=red
>
> This will highlight the if statement with red background if he put
> semicolon after
> a if statement.
>
>
> Except it will also catch things like this:
>
> if (whatever) something();
>
> which you almost certainly don't want, and why I didn't suggest this
> kind of approach.
>
> Yes, we can change it to this:
>
> autocmd BufEnter *.c match Grp_semi /if\s*([^)]\+)\s*;/
> highlight Grp_semi guibg=red

Which will then not work on something like this:

if ((ch=getchar())==EOF) ;

(or anything with nested parentheses).

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: