问题
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))))
回答1:
You can do something like:
(define-key lawlist-mode-map [?\e]
`(menu-item "" ,(lambda () (interactive) (message "You have satisfied condition ABC."))
:filter ,(lambda (binding) (if (ABC ...) binding))))
来源:https://stackoverflow.com/questions/20026083/how-to-use-escape-conditionally-as-a-modifier-key