Emacs key binding fallback
Posted
by rejeep
on Stack Overflow
See other posts from Stack Overflow
or by rejeep
Published on 2010-03-22T16:48:14Z
Indexed on
2010/03/22
16:51 UTC
Read the original article
Hit count: 376
Hey,
I have a minor mode. If that mode is active and the user hits DEL, I want to do some action, but only if some condition holds. If the condition holds and the action is executed I want to do nothing more after that. But if the condition fails, I don't want to do anything and let the default DEL action execute.
Not sure how I could solve this. But I guess I could do it in two ways:
1) I could rebind the DEL key to a function in the minor mode and then check if the conditions holds ot not. But then how do I know what the default command to DEL is?
2) I could add a pre command hook like this. Execute the command and then break the chain. But how do I break the chain?
(add-hook 'pre-command-hook
(lambda()
(when (equal last-input-event 'backspace)
;; Do something and then stop (do not execute the
;; command that backspace is bound to)
)))
In what way would you solve it? Thanks!
© Stack Overflow or respective owner