如何使用<escape>(有条件地)作为修饰键 [英] How to use <escape> (conditionally) as a modifier key

查看:21
本文介绍了如何使用<escape>(有条件地)作为修饰键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让 在某些条件存在时激活函数,但在不满足这些条件时表现得像一个修饰键?

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

<小时>

根据 Stefan 提供的 awesome 解决方案/答案,以下说明了如何在多个条件下使用他的代码(例如,如果是 ABC,则执行 X;如果是 DEF,然后做Y).我为像我这样学习速度慢的人提供了这个例子——也就是说,我花了一些时间来理解如何正确应用代码.


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

推荐答案

您可以执行以下操作:

(define-key lawlist-mode-map [?e]
  `(menu-item "" ,(lambda () (interactive) (message "You have satisfied condition ABC."))
              :filter ,(lambda (binding) (if (ABC ...) binding))))

这篇关于如何使用&lt;escape&gt;(有条件地)作为修饰键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆