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

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

RE: HELP: One Bindkey for Two Different Commands


From: Drew Adams
Subject: RE: HELP: One Bindkey for Two Different Commands
Date: Wed, 21 Nov 2007 01:33:57 -0800

> >> Why waste two bindkeys on two similar commands when you can simply
> >> write a function to choose the between commands based on context?
> >>
> >> Unfortunately,  this very simple idea doesn't seem to work for me.
> >> Here's what I have in my .emacs so far:
> >>
> >> (defun ya-ya ()
> >>   (if (cdr (window-list))
> >>       'other-window
> >>     'switch-to-buffer))
> >>
> >> (global-set-key "\M-o" (ya-ya))
> >> Any ideas how this might be accomplished?
> >
> > To turn a function into a command, add an `interactive' spec.
> >
> > The functions other-window and switch-to-buffer require arguments.
>
> Your point being?  other-window and switch-to-buffer both have an
> interactive spec.

Just trying to help.

To be more clear: You need to call function `other-window' or
`switch-to-buffer', not just return the symbol. And calling them means
providing their required arguments - use either (call-interactively
'other-window) or (other-window <some-window-number>).

> > The second argument to global-set-key is a command, not a list such as
> > you have supplied.
>
> He does not supply a list.  He supplies a command.

Sorry, I misread '(ya-ya) instead of (ya-ya).

> The problem merely is that he makes his choice of command at
> the time of global-set-key, not at keypress time.

To be more helpful: You need to pass the symbol `ya-ya', instead of calling
the function `ya-ya': (global-set-key "\M-o" 'ya-ya). A key is bound to a
command (or its symbol), not to the result of calling the command.

This is the opposite mistake from that made with `other-window' (returning
the symbol instead of calling the function). As David suggested, you called
`ya-ya' at key-binding time, so one of the symbols it returns at that time,
not `ya-ya', gets bound to `M-o'.





reply via email to

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