On 01-May-2013 13:21 +0200, mattn wrote:

> Hi, list.
> 
> I wrote a patch to add new function 'capture()'.
> When you want to get a list of all commands/functions/mappings with using vim 
> script, probably, you'll do like follow.
> 
> ---------------------------------
> let funcs = ''
> redir => funcs
> silent! function
> redir END
> ---------------------------------
> 
> I guess, most of vim script programmers want to get the result as expression. 
>  not command, want to get more easily.
> If vim have 'capture()' which allow to getting those command line 'function', 
> I guess this is very useful.
> 
> For example, getting :Command list as array.
> ---------------------------------
> :echo map(split(capture("command"), "\n")[1:], 'split(v:val[4:])[0]')
> ---------------------------------
> 
> One more thing. vim doesn't support nest of :redir.
> ---------------------------------
> function! s:foo()
>   let a = ''
>   redir => a
>   silent echo "foo"
>   redir END
>   return a
> endfunction
> 
> function! s:bar()
>   let a = ''
>   redir => a
>   call s:foo() 
>   redir END
>   return a
> endfunction
> 
> echo s:bar()
> ---------------------------------
> 
> This 'echo s:bar()' doesn't show anything. But capture() can do it.
> ---------------------------------
> echo capture("s:bar()")
> 
> foo
> ---------------------------------
> 
> capture() is working on sandbox. so you can't use this in modeline.
> 
> Below is a patch. How about this new feature?
> 
> https://gist.github.com/mattn/5449425

While :redir has its uses in the interactive command-line, its
restriction of not allowing nesting is very bad for plugins, and I've
already been affected by this. (I had to send a patch for another plugin
so that its :redir failed gracefully when it ran inside of my plugin.)

You've shown that capture() handles a nested :redir. Just to be clear,
does it also handle a nested capture() inside a capture() execution?! (I
would expect that the outer capture gets the results of the inner
capture as well.)

If that's the case, +1 from me for inclusion.

In addition to taking commands and Lists of commands, it might also be
handy to take Funcrefs.

-- regards, ingo

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Raspunde prin e-mail lui