all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Run Non-Interactive Function with Prefix
@ 2005-10-18 16:41 Kenneth Jacker
  2005-10-18 16:55 ` Lennart Borgman
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Kenneth Jacker @ 2005-10-18 16:41 UTC (permalink / raw)


If I want to execute a function that supports a "prefix" argument
interactively, I enter something like:

     C-u M-x foobar

How can I do the same thing but *non*-interactively?

This will just run 'foobar',

     (foobar)

But how to request it to be run with a prefix arg?


Something simple I am sure, but I can't seem to find a way to do it.

Thanks for your ideas!
-- 
Prof Kenneth H Jacker       khj@cs.appstate.edu
Computer Science Dept       www.cs.appstate.edu/~khj
Appalachian State Univ
Boone, NC  28608  USA        

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Run Non-Interactive Function with Prefix
  2005-10-18 16:41 Run Non-Interactive Function with Prefix Kenneth Jacker
@ 2005-10-18 16:55 ` Lennart Borgman
  2005-10-18 17:00   ` Kenneth Jacker
       [not found]   ` <mailman.11763.1129656007.20277.help-gnu-emacs@gnu.org>
  2005-10-18 18:33 ` Kevin Rodgers
       [not found] ` <mailman.11782.1129660891.20277.help-gnu-emacs@gnu.org>
  2 siblings, 2 replies; 8+ messages in thread
From: Lennart Borgman @ 2005-10-18 16:55 UTC (permalink / raw)
  Cc: help-gnu-emacs

Kenneth Jacker wrote:

>If I want to execute a function that supports a "prefix" argument
>interactively, I enter something like:
>
>     C-u M-x foobar
>
>How can I do the same thing but *non*-interactively?
>
>This will just run 'foobar',
>
>     (foobar)
>
>But how to request it to be run with a prefix arg?
>  
>
Do you mean (foobar ARG), perhaps (foobar t) or (foobar 1)?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Run Non-Interactive Function with Prefix
  2005-10-18 16:55 ` Lennart Borgman
@ 2005-10-18 17:00   ` Kenneth Jacker
  2005-10-18 17:40     ` Lennart Borgman
       [not found]   ` <mailman.11763.1129656007.20277.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Kenneth Jacker @ 2005-10-18 17:00 UTC (permalink / raw)
  Cc: help-gnu-emacs

  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?

  -Kenneth

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Run Non-Interactive Function with Prefix
  2005-10-18 17:00   ` Kenneth Jacker
@ 2005-10-18 17:40     ` Lennart Borgman
  0 siblings, 0 replies; 8+ messages in thread
From: Lennart Borgman @ 2005-10-18 17:40 UTC (permalink / raw)
  Cc: help-gnu-emacs

Kenneth Jacker wrote:

>  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?
>
>  -Kenneth
>  
>
I am not sure I understand (or rather "I am sure I do not understand" ;-)

In the CVS version of Emacs there is information about this Info:

   (elisp) Prefix Command Arguments

Maybe that can help you?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Run Non-Interactive Function with Prefix
       [not found]   ` <mailman.11763.1129656007.20277.help-gnu-emacs@gnu.org>
@ 2005-10-18 18:09     ` Pascal Bourguignon
  2005-10-18 18:37     ` Anselm Helbig
  1 sibling, 0 replies; 8+ messages in thread
From: Pascal Bourguignon @ 2005-10-18 18:09 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Run Non-Interactive Function with Prefix
  2005-10-18 16:41 Run Non-Interactive Function with Prefix Kenneth Jacker
  2005-10-18 16:55 ` Lennart Borgman
@ 2005-10-18 18:33 ` Kevin Rodgers
       [not found] ` <mailman.11782.1129660891.20277.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 8+ messages in thread
From: Kevin Rodgers @ 2005-10-18 18:33 UTC (permalink / raw)


Kenneth Jacker wrote:
 > If I want to execute a function that supports a "prefix" argument
 > interactively, I enter something like:
 >
 >      C-u M-x foobar
 >
 > How can I do the same thing but *non*-interactively?
 >
 > This will just run 'foobar',
 >
 >      (foobar)
 >
 > But how to request it to be run with a prefix arg?

(let ((prefix-arg '(4))) ; C-u
   (call-interactively 'foobar))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Run Non-Interactive Function with Prefix
       [not found]   ` <mailman.11763.1129656007.20277.help-gnu-emacs@gnu.org>
  2005-10-18 18:09     ` Pascal Bourguignon
@ 2005-10-18 18:37     ` Anselm Helbig
  1 sibling, 0 replies; 8+ messages in thread
From: Anselm Helbig @ 2005-10-18 18:37 UTC (permalink / raw)


hi, 

for interactive functions, the prefix argument becomes part of the
argument list, if it is referenced in the interactive declaration. you
can read more about it here:

	(info "(elisp)Prefix Command Arguments")

so if you want to call an interactive function from a program, you
have to figure out which argument corresponds to the prefix
argument. in the worst case scenario, you have to parse the
interactive declaration yourself. but since there already is code that
does just that, chances are you don't have to. 

regards, 

anselm

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Run Non-Interactive Function with Prefix
       [not found] ` <mailman.11782.1129660891.20277.help-gnu-emacs@gnu.org>
@ 2005-10-21 10:31   ` Kenneth Jacker
  0 siblings, 0 replies; 8+ messages in thread
From: Kenneth Jacker @ 2005-10-21 10:31 UTC (permalink / raw)


  kr> (let ((prefix-arg '(4))) ; C-u
  kr>    (call-interactively 'foobar))

Just what I needed!

Thanks for your and everyone else's comments ...

  -Kenneth

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-10-21 10:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-18 16:41 Run Non-Interactive Function with Prefix Kenneth Jacker
2005-10-18 16:55 ` Lennart Borgman
2005-10-18 17:00   ` Kenneth Jacker
2005-10-18 17:40     ` Lennart Borgman
     [not found]   ` <mailman.11763.1129656007.20277.help-gnu-emacs@gnu.org>
2005-10-18 18:09     ` Pascal Bourguignon
2005-10-18 18:37     ` Anselm Helbig
2005-10-18 18:33 ` Kevin Rodgers
     [not found] ` <mailman.11782.1129660891.20277.help-gnu-emacs@gnu.org>
2005-10-21 10:31   ` Kenneth Jacker

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.