如何在 emacs 中编写键绑定以方便重复? [英] How to write a key bindings in emacs for easy repeat?
本文介绍了如何在 emacs 中编写键绑定以方便重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我将密钥绑定到某个函数,如下所示:
Let's say I bind the key to a certain function as follows:
(global-set-key (kbd "C-c =") 'function-foo)
现在,我希望键绑定可以作为:
我第一次按Cc =
后,如果我想重复函数-foo,我不需要再次按Cc
,只需重复按=
.然后,在调用函数 foo 足够多的次数后,我只需按 =
以外的键(或明确按 C-g
)即可退出.
Now, I want the key binding to work as:
After I press C-c =
for the first time, if I want to repeat the function-foo, I don't need to press C-c
again, but simply repeat pressing =
. Then, after I call the function-foo for enough times, I can just press keys other than =
(or explicitly press C-g
) to quit.
如何做到这一点?
推荐答案
这可能就是您要找的东西:
This may be the thing you are looking for:
(defun function-foo ()
(interactive)
(do-your-thing)
(set-temporary-overlay-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "=") 'function-foo)
map)))
这篇关于如何在 emacs 中编写键绑定以方便重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文