Wednesday, October 2, 2013

Re: Skip includes in comment with checkpath option.

On Wednesday, October 2, 2013 12:09:24 PM UTC-5, Bartosz Gradzik wrote:
> 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.
>
>

I modeled this regex after the default value. I did not expect this modification to have *any* effect on the gf command. But now I see the problem.

gf normally uses 'isfname' to find the file under the cursor. In your case, the = and everything else in your include statement also are in 'isfname' so your gf command will get the whole command.

According to :help 'include' you should be able to add \zs\f* to the end of your pattern to match all filename characters AFTER the include syntax, and use those for gf.

>
> >>> ^\%(\%(\*\*\)\@!.\)*include\s\+
>
> I need some time to understand this :-)

Was my explanation not clear? At a high level, this replaces "any whitespace" with "anything not containing **".

>
> But I think it will be the same issue as with above (not working gf command
>
> for comment lines).
>
>

The solution should be the same: append \zs\f*

>
> At the end I went with:
>
>
>
> setlocal include=\\c\*include\\s*,\\s*input\\s*=
>
> setlocal includeexpr=substitute(v:fname,'.*=','','')
>
>

I don't see how this avoids comment lines. I actually don't see how it your include pattern at all. I interpret this as:

\c - case-insensitive search
* - match a literal '*' character
etc. as normal

>
> 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*="

And then this one matches only on lines that start with "*include". So I suppose it won't match "**include" comments, but it won't match "include" without the * either.

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

You don't define a Checkpath! command, you define a Checkpath command and handle the !

>
> However I did not find clear information about this in VIM documentation.
>
>

:help :command-bang
:help <bang>

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