On 5/16/06, Hari Krishna Dara <[EMAIL PROTECTED]> wrote:
On Tue, 16 May 2006 at 2:43pm, Bob Hiestand wrote:
> Hi all,
>
> I'm re-writing my cvscommand.vim plugin to handle both CVS and
> Subversion version control systems. I'm currently implementing some
> of the functionality through function references that define common
> operations for each source control system in a dictionary specfic to
> that system. I have a situation where I have a generic dispatch
> function that identifies which dictionary to dereference to obtain the
> function reference.
>
> The problem is that the function eventually called behind the
> function reference may have any number of arguments. Therefore, the
> dispatch function takes any number of arguments to pass through. This
> leads to the actual call, which looks like this (all on one line):
>
> function! s:ExecuteVCSCommand(command, ...)
> " find the proper functionMap dictionary, and then:
> execute "return functionMap[a:command](" . join(map(copy(a:000),
> "'\"' . v:val . '\"'"), ",") . ")"
>
> My question is whether there is a simpler way to pass an unknown
> number of arguments from the current function to a function which
> accepts a variable-length list of arguments.
>
> Thank you,
>
> Bob
My suggestion would be to have the underlying methods always accept a
list of arguments, then you can just pass a:000 straight-through.
Yes, I've changed the implementation functions in this way per Yakov. Thanks.
BTW, your approach to enclose the arguments in double-quotes is a
bad-idea, especially if you are handling paths on windows with
back-slashes in them (among various others). Imagine what would happen
if the argument is "c:\dev\tst\newfile", both \t and \n will result
in getting expanded to tab and newline. What you should do is to use
single-quotes to avoid accidental transformations, but then escape the
existing single-quotes themselves (if any). Take a look at the
MakeArgumentString() function in my genutils.vim.
--
HTH,
Hari
Yes, I've changed the implementation functions in this way per Yakov. Thanks.
With your heads-up about the double quote in mind, I'm glad that I'm
not using execute now, as the equivalent expression looks to be:
execute 'return functionMap[a:command](' . join(map(copy(b:alist),
''''''''' . v:val . ''''''''')), ',') . ')'
which is fairly difficult for me to read.
Thank you,
Bob