如何在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足够的时间后,我可以按 =
之类的键(或显式地按 Cg $ c $
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屋!
查看全文