Marc Weber wrote:
On Thu, Feb 08, 2007 at 11:56:21AM +0100, A.J.Mechelynck wrote:
Marc Weber wrote:
Do I have missed a non quoting version of <f-args> ?

Consider this example:


function! T(...)
 for a in a:000
   echom 'arg:'.string(a)
 endfor
endfunction

------ 8< ------ 8< start test.vim < ------ 8< ------ 8< ------ 8<
        command! -nargs=* -buffer TestAddSeven :call T(7,<f-args>)
command! -nargs=* -buffer Test2 :exec "call T(7,".join([<f-args>],',').')'
        TestAddSeven 4 'abc'
        echo "Test 2"
        Test2 3 'abc'

------ >8 ------ >8 end >8 ------ >8 ------ >8 ------ >8 ------ >8

------ >8 ------ >8 output ------ >8 ------ >8 ------ >8 ------ >8 arg:7 arg:'4' << here you can see that all arguments get extra extra quotes
        arg:'''abc'''
        Test 2
        arg:7
        arg:3
        arg:'abc'
------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8<
So is there a non quoting version of <f-args> which behaves like the
join([<f-args>],', ') part?

Marc

Here are the various ways in which a user-command may pass arguments:

        :command arg1 arg2 arg3 arg4 arg5
        <args> passes
                arg1 arg2 arg3 arg4 arg5
        <q-args> passes
                "arg1 arg2 arg3 arg4 arg5"
        <f-args> passes
                "arg1","arg2","arg3","arg4","arg5"


I did my mistake here:

:command 'arg1 arg2'
<f-args> will pass
 '''arg1' 'arg2'''
, not 'arg1 arg2'

So <f-args> works the way you'd expect but I have to pass the values
without quotes which don't bother vim here in no way..

Marc


In
        :Command arg1 arg2
there are two arguments, and if the command expands to call Function(<f-args>) you get
        call Function('arg1','arg2')
In
        :Command 'arg1 arg2'
there is one argument (whose _value_ contains quotes at beginning and end, and a space in the middle) and the result (with the same command expansion as above) is
        call Function('''arg1 arg2''')
which is the same as
        call Function("'arg1 arg2'")
Finally, in
        :Command arg1\ arg2
there is one argument with a space in the middle, and it would invoke
        call Function('arg1 arg2')

You can test it (IIUC) with

        command Command -bar -nargs=* call Function(<f-args>)
        function Function(...)
                let n = a:0
                echomsg "Number of arguments:" n
                let i=1
                while i <= n
                        echomsg "Argument" i . ": «" . a:{i} . "»"
                        i = i + 1
                endwhile
        endfunction

Best regards,
Tony.
--
Of all the animals, the boy is the most unmanageable.
                -- Plato

Reply via email to