将多个Emacs键绑定分配给单个命令?
我给ErgoEmacs模式尝试看看我能否更舒适地使用Emacs。它的一些键绑定非常直观,但在很多情况下,我不想直接替换默认设置。例如,在ErgoEmacs的导航快捷键结构中,M-h作为C-a的替代品是有意义的 - 但我希望能够同时使用这两种,而不仅仅是M-h。我试图简单地复制命令:将多个Emacs键绑定分配给单个命令?
;; Move to beginning/ending of line
(defconst ergoemacs-move-beginning-of-line-key (kbd "C-a")) ; original
(defconst ergoemacs-move-end-of-line-key (kbd "C-e")) ; original
(defconst ergoemacs-move-beginning-of-line-key (kbd "M-h")) ; ergoemacs
(defconst ergoemacs-move-end-of-line-key (kbd "M-H")) ; ergoemacs
但Emacs只是用第二个覆盖第一个键绑定。解决这个问题的最好方法是什么?
事实证明,ErgoEmacs使用两个文件来定义键绑定。一个是主要的ergoemacs-mode.el文件,另一个是您选择的特定键盘布局(例如ergoemacs-layout-us.el)。后者文件创建一个常数,前者用来创建键绑定。所以虽然我以为我是在复制键盘绑定,但我实际上正在改变随后用于此目的的常量。
解决方案:
在ergomacs-mode.el:
;; Move to beginning/ending of line
(define-key ergoemacs-keymap ergoemacs-move-beginning-of-line-key 'move-beginning-of-line)
(define-key ergoemacs-keymap ergoemacs-move-end-of-line-key 'move-end-of-line)
(define-key ergoemacs-keymap ergoemacs-move-beginning-of-line-key2 'move-beginning-of-line) ; new
(define-key ergoemacs-keymap ergoemacs-move-end-of-line-key2 'move-end-of-line) ; new
在ergoemacs布局-us.el:从
;; Move to beginning/ending of line
(defconst ergoemacs-move-beginning-of-line-key (kbd "M-h"))
(defconst ergoemacs-move-end-of-line-key (kbd "M-H"))
(defconst ergoemacs-move-beginning-of-line-key2 (kbd "C-a")) ; new
(defconst ergoemacs-move-end-of-line-key2 (kbd "C-e")) ; new
咦? ErgoEmacs的每个功能都有一条唯一的途径,一条黄金原则?因为正常的键绑定方式完全相反:您一次指定一个键并指定它应该做什么。如果一个模式定义了一个全局变量来表示“行结束的关键”,那么当然可以只有一个值,但是使用普通的绑定命令,你可以将相同的函数绑定到你喜欢。事实上,每一个我所见过的使用键联结看着喜欢这样
(global-set-key [(meta space)] 'just-one-space)
或类似这样的
(add-hook 'c-mode-hook 'my-c-mode-hook)
(defun my-c-mode-hook()
(define-key c-mode-map [(control c) b] 'c-insert-block))
,如果这只是一个特定的模式。
要重新发表回复ergo-emacs mailing list:
Xah Lee说:
这很容易。
在 ergoemacs-mode.el文件中,有这个 行(加载“ergoemacs-unbind”)只是 注释掉。这应该是你需要做的全部 。但是,请注意, ErgoEmacs键绑定定义了那些 常用快捷方式,如打开,关闭, 新建,保存...使用键Ctrl + o, Ctrl + w,Ctrl + n,Ctrl + s等。或者。所以,我认为这些 中的一些会与emacs传统的 绑定。如果你是 ErgoEmacs的新手,并试图探索它, 你可能只是尝试从几个 键开始。这页可能有一些 有用的信息: http://code.google.com/p/ergoemacs/wiki/adoption 感谢您检查ErgoEmacs!
XahΣhttp://xahlee.org/
谢谢,Kilian--那是导致我找到答案的线索。原来ErgoEmacs根据映射在ergoemacs-mode.el中定义了键绑定,这个映射在我上面粘贴的'defconst'中定义。 – Dan 2010-06-15 21:34:15