[comp.emacs] syntax for function with argument

ag@sics.se (Anders G|ransson) (09/18/90)

Hello


Suppose you want to assign a key-combination to a function by putting
(define-key-fully global-map "xyz" *something*) in your init-file but
you want to use the variant of the function you get when it is
supplied with an argument.
That is, you want to achieve the result of "C-u (arg)  M-x foo"
by the key-combination "xyz". What is the *something* in this case?


I guess this is explained in the manual somewhere but I haven't
been able to find it. So if some kind soul could email me the
answer I'd be grateful.


--
  name(!): Anders G|ransson, (Not a very serious character).

merlyn@iwarp.intel.com (Randal Schwartz) (09/18/90)

In article <1990Sep17.224911.22873@sics.se>, ag@sics (Anders G|ransson) writes:
| Suppose you want to assign a key-combination to a function by putting
| (define-key-fully global-map "xyz" *something*) in your init-file but
| you want to use the variant of the function you get when it is
| supplied with an argument.
| That is, you want to achieve the result of "C-u (arg)  M-x foo"
| by the key-combination "xyz". What is the *something* in this case?
| 
| 
| I guess this is explained in the manual somewhere but I haven't
| been able to find it. So if some kind soul could email me the
| answer I'd be grateful.

Nope.  It may be in the manual, and if it is, I haven't seen it,
but it'd be something more like this:

(define xyz-with-prefix ()
  (interactive)
  (let prefix-arg '(1)			; or whatever you're calling with
					; see (describe-variable 'prefix-arg)
       (call-interactively 'xyz)))

(define-key global-map "f" 'xyz-with-prefix)

There's no way to do it from just define-key.

Alternatively, you can lookup the arglist of 'xyz (at the proper place in
the source), and feed it arguments like:

(define xyz-with-prefix ()
  (interactive)
  (xyz some-arg some-other-arg))

Just another elisp hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

tale@turing.cs.rpi.edu (David C Lawrence) (09/19/90)

In <1990Sep17.224911.22873@sics.se>, ag@sics (Anders G|ransson) writes:
| Suppose you want to assign a key-combination to a function by putting
| (define-key-fully global-map "xyz" *something*) in your init-file but
| you want to use the variant of the function you get when it is
| supplied with an argument.
| That is, you want to achieve the result of "C-u (arg)  M-x foo"
| by the key-combination "xyz". What is the *something* in this case?

If it is a function which does not read from the minibuffer then
*something* is "\C-uARG\M-xfoo".  

| I guess this is explained in the manual somewhere but I haven't
| been able to find it. So if some kind soul could email me the
| answer I'd be grateful.

In <1990Sep18.035904.5608@iwarp.intel.com> merlyn@iwarp.intel.com
(Randal Schwartz) writes:

> Nope.  It may be in the manual, and if it is, I haven't seen it,
> but it'd be something more like this:

The function documentation for define-key mentions that DEF can be a
string which is treated as keyboard macros.  Note however that
keyboard macros are very simplistic and don't cope at all well at
being asked to stop half way into an interactive command -- "\C-u\M-!"
just won't work as a keyboard macro in vanilla GNU Emacs; it reads
nothing in response to the Shell command: prompt rather than stopping
and waiting for you to enter something.

If you have a function which needs to read from the minibuffer then
you must do it like Randal suggests, though I would use:

(define-key xyz-with-prefix (arg)
  (interactive "P")
  (call-interactively (function xyz))

rather than his (btw, the ``let'' isn't syntactically correct):

> (define xyz-with-prefix ()
>   (interactive)
>   (let prefix-arg '(1)		; or whatever you're calling with
>                                       ; see (describe-variable 'prefix-arg)
>         (call-interactively 'xyz)))

> Alternatively, you can lookup the arglist of 'xyz (at the proper place in
> the source), and feed it arguments like:

> (define xyz-with-prefix ()
>   (interactive)
>   (xyz some-arg some-other-arg))

Some functions, however, behave differently depending on whether they
are interactive-p.  The former method makes sure that the results you
get are the same as if you had given a prefix argument to the command
interactively.
--
   (setq mail '("tale@cs.rpi.edu" "tale@ai.mit.edu" "tale@rpitsmts.bitnet"))
    I'm worried about the baggage retrieval system they've got at Heathrow.