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

Re: redir and glob

Expand Messages
  • Nazri Ramliy
    ... To redir to the s:output_file variable do this: redir = s:output_file Also you may be able to simplify your BuildFileList() using globpath() instead: let
    Message 1 of 7 , Mar 18 10:34 PM
    • 0 Attachment
      On Tue, Mar 19, 2013 at 6:39 AM, FlashBurn <rail.shafigulin@...> wrote:
      > Obviously there is something wrong with the way I use redir and glob,
      > but I can't get my finger on it. Does anybody know what am I doing
      > wrong?

      To redir to the s:output_file variable do this:

      redir => s:output_file

      Also you may be able to simplify your BuildFileList() using globpath()
      instead:

      let files = globpath('dir1,dir2,dir3', '*.[ch]')

      nazri

      --
      --
      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.
    • Gary Johnson
      ... Even more so by also using writefile(): call writefile(split(globpath( dir1,dir2,dir3 , **/*.[hc] )), cscope.files ) Note that **/*.[hc] causes
      Message 2 of 7 , Mar 18 11:15 PM
      • 0 Attachment
        On 2013-03-19, Nazri Ramliy wrote:

        > Also you may be able to simplify your BuildFileList() using globpath()
        > instead:
        >
        > let files = globpath('dir1,dir2,dir3', '*.[ch]')

        Even more so by also using writefile():

        call writefile(split(globpath('dir1,dir2,dir3', '**/*.[hc]')), 'cscope.files')

        Note that '**/*.[hc]' causes globpath to search recursively in each
        of the directories. If you don't want that, just use '*.[hc]'.

        Regards,
        Gary

        --
        --
        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
        ... OK, so the task is to write to a file. ... Here other responses have assumed you are wanting to write to a variable. But, you ve said you want to write to
        Message 3 of 7 , Mar 19 6:52 AM
        • 0 Attachment
          On Monday, March 18, 2013 5:39:14 PM UTC-5, FlashBurn wrote:
          > I want to create a list of files that my project is using. This list will be stored in a file and subsequently will be used by cscope.
          >

          OK, so the task is to write to a file.

          > Here is what I have so far:
          >
          > function! BuildFileList()
          > s:dir_list = ['dir1', 'dir2', 'dir3']
          > s:output_file = 'cscope.files'
          > redir! > s:output_file

          Here other responses have assumed you are wanting to write to a variable. But, you've said you want to write to a file. So your problem is the classing "didn't realize you can't use variables on the cmd line" problem. To use a variable name in most ex commands, you need to build a string and then execute it rather than inserting the variable name directly. In your case, like this:

          execute "redir! > ".s:output_file

          As Gary points out, it can be more efficient not to use redir at all, but rather to call the writefile function to write directly from a script.

          > for dir in s:dir_list
          > glob(dir.'*.[ch]')
          > endfor

          Here you're attempting to call the glob() function, which returns (but does NOT display) a list. Since you have an active redirection, you should be displaying the output to capture it in the redirection. To accomplish this, use the "echo" command:

          echo glob(dir.'*.[ch]')

          An alternate, better approach is to not use the redirection at all. You can either store the result of glob into a string or list, or just pass the result into the writefile function. See Gary's response.

          > redir END
          > endfunction
          >
          > silent call BuildFileList
          >

          I'm amazed this function call works. I always thought you need to add parentheses at the end like "call BuildFileList()", but apparently it works enough to execute the function and give you error messages! I just learned something...which I will probably continue to not use.

          > I'm getting the following errors when I execute this function:
          > E190: Cannot open "s:output_file" for writing
          > E486: Pattern not found: dir."*.[ch]"
          >
          > Obviously there is something wrong with the way I use redir and glob, but I can't get my finger on it. Does anybody know what am I doing wrong?
          >

          Yup, with both. Good insight :-)

          --
          --
          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
          ... classing ? What s wrong with me today?! I meant classic if you can t guess. -- -- You received this message from the vim_use maillist. Do not
          Message 4 of 7 , Mar 19 6:53 AM
          • 0 Attachment
            On Tuesday, March 19, 2013 8:52:09 AM UTC-5, Ben Fritz wrote:
            > But, you've said you want to write to a file. So your problem is the classing "didn't realize you can't use variables on the cmd line" problem.

            "classing"? What's wrong with me today?! I meant "classic" if you can't guess.

            --
            --
            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.
          • FlashBurn
            ... Oops, as it turns out I didn t copy my code properly. This function call doesn t work without the parentheses. ... -- -- You received this message from the
            Message 5 of 7 , Mar 19 7:23 AM
            • 0 Attachment
              On Tuesday, March 19, 2013 9:52:09 AM UTC-4, Ben Fritz wrote:
              > On Monday, March 18, 2013 5:39:14 PM UTC-5, FlashBurn wrote:
              > > I want to create a list of files that my project is using. This list will be stored in a file and subsequently will be used by cscope.
              > >
              >
              > OK, so the task is to write to a file.
              >
              > > Here is what I have so far:
              > >
              > > function! BuildFileList()
              > > s:dir_list = ['dir1', 'dir2', 'dir3']
              > > s:output_file = 'cscope.files'
              > > redir! > s:output_file
              >
              > Here other responses have assumed you are wanting to write to a variable. But, you've said you want to write to a file. So your problem is the classing "didn't realize you can't use variables on the cmd line" problem. To use a variable name in most ex commands, you need to build a string and then execute it rather than inserting the variable name directly. In your case, like this:
              >
              > execute "redir! > ".s:output_file
              >
              > As Gary points out, it can be more efficient not to use redir at all, but rather to call the writefile function to write directly from a script.
              >
              > > for dir in s:dir_list
              > > glob(dir.'*.[ch]')
              > > endfor
              >
              > Here you're attempting to call the glob() function, which returns (but does NOT display) a list. Since you have an active redirection, you should be displaying the output to capture it in the redirection. To accomplish this, use the "echo" command:
              >
              > echo glob(dir.'*.[ch]')
              >
              > An alternate, better approach is to not use the redirection at all. You can either store the result of glob into a string or list, or just pass the result into the writefile function. See Gary's response.
              >
              > > redir END
              > > endfunction
              > >
              > > silent call BuildFileList
              > >
              >
              > I'm amazed this function call works. I always thought you need to add parentheses at the end like "call BuildFileList()", but apparently it works enough to execute the function and give you error messages! I just learned something...which I will probably continue to not use.
              >

              Oops, as it turns out I didn't copy my code properly. This function call doesn't work without the parentheses.

              > > I'm getting the following errors when I execute this function:
              > > E190: Cannot open "s:output_file" for writing
              > > E486: Pattern not found: dir."*.[ch]"
              > >
              > > Obviously there is something wrong with the way I use redir and glob, but I can't get my finger on it. Does anybody know what am I doing wrong?
              > >
              >
              > Yup, with both. Good insight :-)

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