[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Short-circuiting keybindings?
From: |
Stefan Monnier |
Subject: |
Re: Short-circuiting keybindings? |
Date: |
Wed, 08 Dec 2010 15:35:24 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
> 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