136796Re: redir and glob
- Mar 19, 2013On 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: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:
> function! BuildFileList()
> s:dir_list = ['dir1', 'dir2', 'dir3']
> s:output_file = 'cscope.files'
> redir! > s:output_file
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_listHere 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:
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 ENDI'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.
> silent call BuildFileList
> I'm getting the following errors when I execute this function:Yup, with both. Good insight :-)
> 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?
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.
- << Previous post in topic Next post in topic >>