Saturday, March 24, 2012

Re: E172 error

Hi Marcin!

On Sa, 24 Mär 2012, Marcin Szamotulski wrote:

> On 13:45 Fri 23 Mar , Ben Fritz wrote:
> > On Friday, March 23, 2012 2:47:22 PM UTC-5, Christian Brabandt wrote:
> > > Hi Marcin!
> > >
> > > On Fr, 23 M�r 2012, Marcin Szamotulski wrote:
> > >
> > > > Hello,
> > > >
> > > > I'm trying to make a nice interface for :call system(...). For this I made the
> > > > following function:
> > > >
> > > > function! System(arg)
> > > > " Expand %, %:p (all modifiers are allowed except :s?pat?sub? and
> > > > " :gs?pat?sub?
> > > > return system(substitute(a:arg, '\(%\%(:[p8~.htre]\)*\)', '\=expand(submatch(0))', 'g'))
> > > > endfunction
> > > >
> > > > The command
> > > > command! -nargs=1 System :echo System("<args>")
> > > > works as expected, but when I change it to:
> > >
> > > I am surprised, this actually works and you didn't get E176.
> > >
> > > >
> > > > command! -nargs=1 -complete=file System :echo System("<args>")
> > > >
> > > > and use it
> > > > :System ls /tmp
> > > > I get the E172 error. Any ideas why?
> > >
> > > You called the command with 2 arguments, but defined it to only accept
> > > one. That's wrong use -nargs=+ and possibly instead of "<args>" you can
> > > also use <q-args>
> > >
> >
> > That's exactly what my first thought was, but then I saw :he :command-nargs, "-nargs=1 Exactly one argument is require, it includes spaces". Unless I'm mistaken, this actually means it will always include the rest of the command-line (up to a " or | potentially), and include the spaces.
>
> Hi,
>
> command! -nargs=+ -complete=file System :call System("<args>")
>
> works fine. I though that <args> separetes arguments with a comma rather than
> spaces (what does <f-args>). That's why I though that -nargs=1 is fine.
> But actually the small test shows that <args> passes exactly one argument:
>
> fun! Test(...)
> echo a:0
> endfun
> com! -nargs=+ Test :call Test("<args>")
>
> :Test a b c
> echoes 1,
> also ':Test a,b,c' echoes 1.

:Test a b "c"
produces
E116: Invalid arguments for function Test
That's why, use
com! -nargs=+ Test :call Test(<q-args>)

regards,
Christian
--

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

No comments: