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

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

Re: Run Non-Interactive Function with Prefix


From: Pascal Bourguignon
Subject: Re: Run Non-Interactive Function with Prefix
Date: Tue, 18 Oct 2005 20:09:29 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Kenneth Jacker <khj@be.cs.appstate.edu> writes:

>   lb> Do you mean (foobar ARG), perhaps (foobar t) or (foobar 1)?
>
> No.  The function 'foobar' might or might not require an ARG.  
>
>
> What I want to do is specify a *prefix* before invoking 'foobar'.
> Note that this is independent of whether the function has a required
> argument or not.
>
> I specify this interactively with "C-u", but how to do it *non*-interactively?

But really, prefixes are awkward.  We cope with them for interactive
commands, but for functions it is silly to try to use them.

For functions, the best is to pass arguments.  If you have optional
arguments, then declare them optional: 

(defun foo (mandatory-arg-1 mandatory-arg-2 
            &optional optional-arg-1 optional-arg-2)
     ...)

When you call interactively a function, you must type:
M-: (foo "arg1" 2 :optional-value-1) RET


In some cases you can use global variables:
(defvar *parameter-for-foo* :default-value)

(defun foo ()
    ...
    *parameter-for-foo* 
    ...)

When you call interactively a function, you must type:

M-: (let ((*parameter-for-foo* :my-value)) (foo)) RET

or:

M-: (setf *parameter-for-foo* :new-value) RET
M-: (foo) RET


If you insist on prefix, then write a command! Just insert
(interactive) at the right place.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Grace personified,
I leap into the window.
I meant to do that.


reply via email to

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