How to use <escape> (conditionally) as a modifier key

独自空忆成欢 提交于 2019-11-27 08:01:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!