emacs 中特定于文件的键绑定 [英] File-specific key-binding in emacs
本文介绍了emacs 中特定于文件的键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 emacs 中定义特定于文件的键绑定?我想可以创建一个次要模式并在特定文件打开时加载它,但只有一个键绑定似乎有点矫枉过正.
Is it possible to define file specific key-bindings in emacs? I suppose it would be possible to create a minor mode and have it loaded when the particular file is open but for only one key-binding that seems overkill.
推荐答案
如果将代码组合到 local-set-key
和 在 Emacs 中缓冲本地覆盖次要模式键绑定 然后你可能会得到这样的结果:
If you combine the code to local-set-key
and Buffer-locally overriding minor-mode key bindings in Emacs then you could end up with something like this:
(defun my-buffer-local-set-key (key command)
(interactive "KSet key buffer-locally:
CSet key %s buffer-locally to command: ")
(let ((oldmap (current-local-map))
(newmap (make-sparse-keymap)))
(when oldmap
(set-keymap-parent newmap oldmap))
(define-key newmap key command)
(use-local-map newmap)))
然后,根据 Barmar 的回答:
and then, as per Barmar's answer:
;; Local Variables:
;; eval: (my-buffer-local-set-key (kbd "C-c C-c") 'foo)
;; End:
请注意,次要模式地图优先于本地地图.
Note that minor mode maps take precedence over the local map.
这篇关于emacs 中特定于文件的键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文