Loading ...
Sorry, an error occurred while loading the content.

Skip includes in comment with checkpath option.

Expand Messages
  • Bartosz Gradzik
    Hi, I would like checkpath option with VIM. My include definition is: setlocal include=
    Message 1 of 5 , Oct 1, 2013
    • 0 Attachment

      Hi,

       

      I would like checkpath option with VIM.

       

      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+=”:**”

       

      But it does not work. When I use checkpath option VIM is checking all include definition also those in comment line.

       

      How can I ask VIM to not check includes in comment line?

       

      Thanks & Regards,

      Bartosz

       

      --
      --
      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@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Ben Fritz
      ... 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
      Message 2 of 5 , Oct 1, 2013
      • 0 Attachment
        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@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Bartosz Gradzik
        Hi Ben, Thank You for your reply. ... Now I see, I misunderstood the documentation. ... With that solution :checkpath skips includes in comment lines but I am
        Message 3 of 5 , Oct 2, 2013
        • 0 Attachment
          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@... [mailto:vim_use@...] On Behalf
          Of Ben Fritz
          Sent: Tuesday, October 01, 2013 8:23 PM
          To: vim_use@...
          Cc: vim@...; bartosz.gradzik@...
          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@....
          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@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Ben Fritz
          ... 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
          Message 4 of 5 , Oct 2, 2013
          • 0 Attachment
            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@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Bartosz Gradzik
            Hi Ben, ... 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
            Message 5 of 5 , Oct 2, 2013
            • 0 Attachment
              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@... [mailto:vim_use@...] On Behalf
              Of Ben Fritz
              Sent: Wednesday, October 02, 2013 9:11 PM
              To: vim_use@...
              Cc: bartosz.gradzik@...
              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@....
              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@....
              For more options, visit https://groups.google.com/groups/opt_out.
            Your message has been successfully submitted and would be delivered to recipients shortly.