在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: \nCSet 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屋!
查看全文