Wednesday, October 2, 2013

RE: Skip includes in comment with checkpath option.

Hi Ben,

Thank You for your reply.

>>> it is NOT used for the :checkpath command.
Now I see, I misunderstood the documentation.

>>> ^\s*include\s\+
With that solution :checkpath skips includes in comment lines but I am not
able to use gf command also.

>>> ^\%(\%(\*\*\)\@!.\)*include\s\+
I need some time to understand this :-)
But I think it will be the same issue as with above (not working gf command
for comment lines).

At the end I went with:

setlocal include=\\c\*include\\s*,\\s*input\\s*=
setlocal includeexpr=substitute(v:fname,'.*=','','')

command! -buffer Checkpath :call <SID>Checkpath(0)
command! -buffer CheckpathList :call <SID>Checkpath(1)
function! s:Checkpath(arg)
let includeOld = &include
let &include = "\\c^\*include\\s*,\\s*input\\s*="
if a:arg == 0
checkpath
elseif a:arg == 1
checkpath!
endif
let &include = includeOld
endfunction

Now gf and :checkpath command works for both comment and uncomment lines.
And with :Checkpath I can test only not comment includes.
Only thing is that I was not able to use command name Checkpath!, it looks
like there is some limitation.
However I did not find clear information about this in VIM documentation.

Once again thank you for your help.

Best,
Bartosz

-----Original Message-----
From: vim_use@googlegroups.com [mailto:vim_use@googlegroups.com] On Behalf
Of Ben Fritz
Sent: Tuesday, October 01, 2013 8:23 PM
To: vim_use@googlegroups.com
Cc: vim@vim.org; bartosz.gradzik@yahoo.com
Subject: 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.


-----
Nie znaleziono wirusów w tej wiadomosci.
Sprawdzone przez AVG - www.avg.com
Wersja: 2013.0.3408 / Baza danych wirusów: 3222/6714 - Data wydania:
2013-10-01


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