【发布时间】:2014-02-19 13:25:14
【问题描述】:
已经有somequestions关于可重复的emacs命令的主题(即C-x z[repeat-command]的行为,其中每个后续z重复最后一个命令),但是,自动解决方案 都不能处理非前缀键绑定(我的术语:C-c p 是前缀为 C-c 的前缀键绑定,另一方面,击键 M-s-+ 是非前缀键绑定)。
在我的设置中,我将M-s-+ 绑定到text-scale-increase 和M-s-- 绑定到text-scale-decrease。在初始命令后点击+ 或- 进行重复缩放会很好。这可以通过以下 elisp 来实现:
(defvar text-scale-temp-keymap (make-sparse-keymap))
(define-key text-scale-temp-keymap (kbd "+") 'text-scale-increase)
(define-key text-scale-temp-keymap (kbd "-") 'text-scale-decrease)
(defun text-scale-increase-rep (inc)
(interactive "p")
(text-scale-increase inc)
(set-temporary-overlay-map text-scale-temp-keymap t))
(defun text-scale-decrease-rep (inc)
(interactive "p")
(text-scale-decrease inc)
(set-temporary-overlay-map text-scale-temp-keymap t))
(global-set-key (kbd "M-s-+") 'text-scale-increase-rep)
(global-set-key (kbd "M-s--") 'text-scale-decrease-rep)
但是,每次我想创建可重复的键绑定时都重复此代码既麻烦又不必要。我正在寻求一种使任务自动化的方法。图片此代码
(make-repeatable-command 'text-scale-increase '(("+" . text-scale-increase)
("-" . text-scale-decrease)))
将创建名为 text-scale-increase-rep 的命令和名为 text-scale-increase-temporary-map 的覆盖键映射以及相应的键。
我认为这是可能的,但如何?
【问题讨论】: