全局覆盖Emacs中的键绑定 [英] Globally override key binding in Emacs

查看:118
本文介绍了全局覆盖Emacs中的键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置全局覆盖的密钥绑定,并优先于该密钥的所有其他绑定?我想覆盖所有主/次模式地图,并确保我的绑定总是有效。

How can I set a key binding that globally overrides and takes precedence over all other bindings for that key? I want to override all major/minor mode maps and make sure my binding is always in effect.

这当然不起作用:

(global-set-key "\C-i" 'some-function)

它适用于文本模式,但是当我使用 lisp-mode Ci 反弹到 lisp-indent-line

It works in text-mode, but when I use lisp-mode, C-i is rebound to lisp-indent-line.

我可以在 lisp-mode 中逐个覆盖这个绑定,并且在每个其他模式中都可以单独地覆盖这个绑定,但是必须有一个更简单的方法。每次我为新的文件类型安装一个新的模式时,我必须返回并检查以确保我的所有键绑定没有被新的模式覆盖。

I can go through and override this binding in lisp-mode and in every other mode individually, but there must be an easier way. Every time I install a new mode for a new file type, I'd have to go back and check to make sure that all of my key bindings aren't being overridden by the new mode.

我想这样做,是因为我想要模拟我已经从其他编辑器学到并根深蒂固的绑定。

I want to do this because I want to emulate bindings I've already learned and ingrained from other editors.

推荐答案

我对所有我的覆盖键绑定使用次模式:

I use a minor mode for all my "override" key bindings:

(defvar my-keys-minor-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-i") 'some-function)
    map)
  "my-keys-minor-mode keymap.")

(define-minor-mode my-keys-minor-mode
  "A minor mode so that my key settings override annoying major modes."
  :init-value t
  :lighter " my-keys")

(my-keys-minor-mode 1)

这有一个额外的好处是能够一举关闭所有的修改(只是禁用次要模式),以防其他人博士或者如果我需要看到一个默认的键绑定功能。

This has the added benefit of being able to turn off all my modifications in one fell swoop (just disable the minor mode) in case someone else is driving the keyboard or if I need to see what a default key binding does.

请注意,您可能需要在minibuffer中关闭它:

Note that you may need to turn this off in the minibuffer:

(defun my-minibuffer-setup-hook ()
  (my-keys-minor-mode 0))

(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)

这篇关于全局覆盖Emacs中的键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆