all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Short-circuiting keybindings?
@ 2010-11-09 21:06 Elena
       [not found] ` <87k4kmf3at.fsf@kuiper.lan.informatimago.com>
  2010-11-10 18:19 ` Stefan Monnier
  0 siblings, 2 replies; 3+ messages in thread
From: Elena @ 2010-11-09 21:06 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

is there a generic way to create "short-circuiting" keybindings?  I
mean: let's say I want "C-b" to issue a command only whenever a
condition is met, otherwise if "C-b" is a prefix key then Emacs should
continue listening for keystrokes and execute commands when
appropriate.

Any idea?  Thanks.


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

* Re: Short-circuiting keybindings?
       [not found] ` <87k4kmf3at.fsf@kuiper.lan.informatimago.com>
@ 2010-11-10 11:15   ` Elena
  0 siblings, 0 replies; 3+ messages in thread
From: Elena @ 2010-11-10 11:15 UTC (permalink / raw)
  To: help-gnu-emacs

On 10 Nov, 00:08, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> Elena <egarr...@gmail.com> writes:
> > is there a generic way to create "short-circuiting" keybindings?  I
> > mean: let's say I want "C-b" to issue a command only whenever a
> > condition is met, otherwise if "C-b" is a prefix key then Emacs should
> > continue listening for keystrokes and execute commands when
> > appropriate.
>
> Really, to do what you have in mind, the easiest and cleanest would be
> to modify the core of emacs, in the C sources.

Ouch!  That would be cumbersome.

> > You could add hooks, or change the mechanisms.

Thanks for your suggestion.  Such goal can be achieved on case basis.
For instance, let's say we want "C-b" to be bound to a command, thus
shadowing "C-b C-c", only when region is active.  We could bind "C-b C-
b" globally, while binding "C-b" in `activate-mark-hook' and unbinding
it in `deactivate-mark-hook'.  Right?


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

* Re: Short-circuiting keybindings?
  2010-11-09 21:06 Short-circuiting keybindings? Elena
       [not found] ` <87k4kmf3at.fsf@kuiper.lan.informatimago.com>
@ 2010-11-10 18:19 ` Stefan Monnier
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2010-11-10 18:19 UTC (permalink / raw)
  To: help-gnu-emacs

> is there a generic way to create "short-circuiting" keybindings?  I
> mean: let's say I want "C-b" to issue a command only whenever a
> condition is met, otherwise if "C-b" is a prefix key then Emacs should
> continue listening for keystrokes and execute commands when
> appropriate.

You can create conditional key bindings:

  (define-key map [?\C-b] '(menu-item "dummy" <command>
                            :filter (lambda (binding)
                                      (if <condition> binding))))
                                      
The filter function will receive <command> as argument (this is so that
the same filter function can be used for several bindings) and can opt
to return it or not or to return anything else (so you can create
dynamic bindings, which is typically used to construct dynamic menus,
such as the Buffers menu).
The <command> you put as the "static binding" that gets passed to the
filter is only used in cases such as where-is.


        Stefan


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

end of thread, other threads:[~2010-11-10 18:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-09 21:06 Short-circuiting keybindings? Elena
     [not found] ` <87k4kmf3at.fsf@kuiper.lan.informatimago.com>
2010-11-10 11:15   ` Elena
2010-11-10 18:19 ` Stefan Monnier

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.