Is it possible to have <escape>
activate functions when certain conditions exist, yet behave like a modifier key when those conditions are not met?
(define-key lawlist-mode-map (kbd "<escape>") (lambda () (interactive)
(cond
((ABC . . .)
(message "You have satisfied condition ABC."))
((DEF . . .)
(message "You have satisfied condition DEF."))
(t (The <escape> key shall behave like a modifier key: ESC- )) )))
EDIT: ?Based upon the awesome solution / answer provide by Stefan, the following is an illustration of how to use his code with multiple conditions (e.g., if ABC, then do X; if DEF, then do Y). I am including this example for slow-learners like myself -- i.e., it took me some time to understand how to apply the code correctly.
(global-set-key (kbd "<escape>") `(menu-item ""
,(lambda () (interactive)
(cond
((Set forth condition ABC.)
(message "You have satisfied condition ABC."))
((Set forth condition DEF.)
(message "You have satisfied condition DEF."))))
:filter ,(lambda (binding)
(if (or (Set forth condition ABC.)
(Set forth condition DEF.))
binding))))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…