On 02-May-2013 15:34 +0200, Christian Brabandt wrote:
> Hi mattn!
>
> On Mi, 01 Mai 2013, mattn wrote:
>
>> 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.
>
> Perhaps we should first fix redir before we introduce another similar
> function?
That would work, too. On the other hand, here's an idea from a
practitioner that might justify a separate function: Almost always, the
captured text is split() into a list of lines (mattn's example does
this, too). Why not have capture() return a list of lines in the first
place?! We obviously cannot change the original :redir interface, but a
new function could offer this and spare all plugins from doing that.
-- 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.