Tuesday, October 1, 2013

Re: Skip includes in comment with checkpath option.

On Tuesday, October 1, 2013 11:50:37 AM UTC-5, Bartosz Gradzik wrote:
> Hi,
>  
> I would like checkpath option with VIM.
>  

You mean the :checkpath command, I assume.

WOW! I didn't know this command existed 10 minutes ago. Thanks! I see now it's mentioned right in :help 'path' that you can search 'path' for include files. I'll be using this...

> My include definition is:
> setlocal include=\\<\\c^*include\\s*,\\s*input\\s*=
> setlocal includeexpr=substitute(v:fname,'.*=','','')
>  
> It works fine, now I want to skip include which are in comment line.
> Comment line is each line which start with **.
> So I went with:
> setlocal comments+=":**"

I'm going to assume you threw in those quotes for the email but they're not part of the Vim command you used. Regardless, this won't work, because 'comments' is only use for auto-formatting comments, it is NOT used for the :checkpath command. The only relevant options for that, as far as I can tell, are 'path', 'include', and 'includeexpr'.

In your case, you need to tweak your regular expression given to your 'include' option. You've explicitly set it to match everywhere where "include" matches at start-of-word. You need to limit that to lines that don't have ** before the include.

Do you ever use other commands before "include"? Or is "include" always by itself on the line (maybe with whitespace)? If it is always by itself, your pattern can be:

^\s*include\s\+

Otherwise, it gets more complicated, you must rule out only lines with a ** before the include:

^\%(\%(\*\*\)\@!.\)*include\s\+

Here, I use ^ to force the match to start at beginning of line. Then \%(...\) is grouping without saving off a backreference. The \%(\*\*\)\@! therefore matches with zero-width wherever there is NOT a literal ** string. The . matches anything, but we already know it doesn't start a ** string. So this way we match anything not a ** string, from the beginning of the line to the "include".

:help /\%(
:help /\@!

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: