[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Get a command by its keybinding and also respecting key translation
From: |
Stefan Monnier |
Subject: |
Re: Get a command by its keybinding and also respecting key translation |
Date: |
Sat, 18 Dec 2010 11:23:10 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
>> (define-key outline-minor-mode-map
>> (kdb "<tab>")
>> `(menu-item "dummy" org-cycle
>> :filter ,(lambda (cmd)
>> (if (th-outline-context-p) cmd))))
> This is cool, but sadly not equivalent, because I cannot add multiple
> binding for one key in the same keymap.
Very good point. I bumped into the same problem a while ago for the
case where the "key" is the default [t] binding (where I wanted to have
a single binding cover a whole bunch of keys at a time).
You can hack around this limitation by using
(setcdr outline-minor-mode-map
(cons (cons 'tab `(menu-item "dummy" org-cycle
:filter ,(lambda (cmd)
(if (th-outline-context-p) cmd))))
(cdr outline-minor-mode-map)))
which might work. But that's *really* ugly, and I wouldn't be surprised
if it didn't work right in some cases.
> So do I go to implement that behavior in a more standard way?
> The docs state, that the :filter may also switch the REAL-BINDING to
> some other command, so I could write a macro that expands according to
> your definition with a (cond ((PRED1) (CMD1)) ((PRED2) (CMD2))) instead
> of the if.
Yes, of course, that will work just fine. The disadvantage being of
course that you lose modularity: you can't add PRED1/CMD1 and
PRED2/CMD2 separately.
> And is this approach not pretty slow? I mean, my approach did the
> predicate checks only when that key was typed, but I think that your
> approach does the checks on any redisplay, right?
No, it'll do the check only when the key is pressed and will definitely
not interact with redisplay.
Stefan
- Re: Get a command by its keybinding and also respecting key translation, (continued)
Re: Get a command by its keybinding and also respecting key translation, Tassilo Horn, 2010/12/15
RE: Get a command by its keybinding and also respecting keytranslation, Drew Adams, 2010/12/15
Re: Get a command by its keybinding and also respecting keytranslation, Tassilo Horn, 2010/12/15
RE: Get a command by its keybinding and also respecting keytranslation, Drew Adams, 2010/12/15
Re: Get a command by its keybinding and also respecting keytranslation, Stefan Monnier, 2010/12/18
Re: Get a command by its keybinding and also respecting key translation,
Stefan Monnier <=