help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Argument-list in function with variable number of arguments...


From: Pascal Bourguignon
Subject: Re: Argument-list in function with variable number of arguments...
Date: Fri, 20 May 2005 17:00:59 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

address@hidden writes:

> Is there a way to have a variable number of arguments in
> a function argument-list?
> I know how to write a function in which a fixed number of arguments
> is expected for ex.
>
> ( defun my-function ( first second )
>    (interactive "sFirst : \nsSecond : ")
>    (insert ""first"\n"
>                 ""second"\n")
> )
>
> So I'm asked for "first" and for "second"...and my-function
> inserts the two of them in a buffer.
> I would like to have more arguments (let's say n) and being
> asked for them interactively, for instance:
> How many arguments? : 5 <Ret>
> First : first_argument <Ret>
> Second : second_argument <Ret>
> Third : third_argument <Ret>
> ...and so on without knowing their number in advance.
>
> Is it possible?
> Thank you very much,
> Luca.

Yes.  C-h f interactive RET

"If the argument is not a string, it is evaluated to get a list of
 arguments to pass to the function."

So:

(require 'cl)
(defun my-command (&rest arguments)
   (interactive (loop while (y-or-n-p "Another argument? ")
                         collect (read-from-minibuffer "Next argument: ")))
   (insert (format "%S" arguments)))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Kitty like plastic.
Confuses for litter box.
Don't leave tarp around.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]