Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...