Wednesday, October 2, 2013

RE: Skip includes in comment with checkpath option.

Hi Ben,

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

Not comment line has to start at first column and it looks like this:
*Include, input=path
Comment line is when I put ** at the beginning, so it maybe be:
**Include, input=path
***Include, input=path
** *Include, input=path

It means I can get not comment include line for :checkpath command with:
\\c^\*include\\s*,\\s*input\\s*=
and comment and not comment include line for gf command with:
\\c\*include\\s*,\\s*input\\s*=

>>> but it won't match "include" without the * either.
You are right but it is not a problem for me since syntax "Include,
input=path" is incorrect and should never occur.

>>> You don't define a Checkpath! command, you define a Checkpath command
and handle the !
>>> :help :command-bang
>>> :help <bang>
Awesome! Now my function is:

command! -buffer -bang Checkpath :call <SID>Checkpath("<bang>")
function! s:Checkpath(bang)
let includeOld = &include
let &include = "\\c^\*include\\s*,\\s*input\\s*="
execute "checkpath" . a:bang
let &include = includeOld
endfunction

So :checkpath is looking for all includes and :Checkpath for not commented.
Perfect, that's all what I need.

Thanks!

Regards,
Bartosz

-----Original Message-----
From: vim_use@googlegroups.com [mailto:vim_use@googlegroups.com] On Behalf
Of Ben Fritz
Sent: Wednesday, October 02, 2013 9:11 PM
To: vim_use@googlegroups.com
Cc: bartosz.gradzik@yahoo.com
Subject: 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.


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


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

Post a Comment