Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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))))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...