全局覆盖 emacs 键绑定

发布于 2024-10-22 20:36:08 字数 247 浏览 5 评论 0原文

是否有一个命令可以全局覆盖键绑定,以便它甚至覆盖主要模式的本地设置? global-set-key 被主要模式绑定覆盖,如下所述: http://www.gnu.org/software/emacs/manual/html_node/emacs/Rebinding.html

Is there a command to globally override a keybinding such that it overrides even the local settings of major modes? global-set-key is overridden by major mode bindings, as stated here: http://www.gnu.org/software/emacs/manual/html_node/emacs/Rebinding.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眸 2024-10-29 20:36:08

不,没有(内置)方法可以设置覆盖所有其他键绑定的键绑定。通过阅读 "搜索活动键盘映射" 了解 Emacs 如何搜索键盘映射

您可以将 overriding-terminal-local-mapoverriding-local-map 设置为包含所需绑定的键盘映射,但这会阻止您的缓冲区具有任何缓冲区/overlay/minor-mode 键映射,几乎禁用了大多数 Emacs。

Emacs 寻找绑定的下一个区域是当前点的字符属性 - 它可能不会在所有地方使用,但这是覆盖绑定的一种方式(除非您使用字符属性来定义您的键,真是恶心)。

Emacs 下一个查找的地方是变量 emulation-mode-map-alists,这可能是您最好的选择。它是为要处理多个次要模式键盘映射的情况而设置的包。

创建一个全局次要模式(请参阅定义次要模式),将您的键绑定放在那里,将您的次要模式和键盘映射添加到emulation-mode-map-alists中,然后打开您的次要模式。

您的键绑定现在将优先于所有其他键绑定,除了 emulation-mode-map-alist 列表中较早的键绑定、或在字符属性中找到的键绑定或在 overriding-local-map< /code>...

我相信这是你能做的最好的事情,无需破解 Emacs 源代码。

No, there is no (built-in) way to set up a key binding that overrides all others. Look at how Emacs searches the keymap by reading "Searching the Active Keymaps".

You could set overriding-terminal-local-map or overriding-local-map to a keymap containing the binding you want, but that'd prevent your buffer from having any buffer/overlay/minor-mode keymaps, pretty much disabling the majority of Emacs.

The next area Emacs looks for a binding is in the character property at the current point - which probably isn't used all over the place, but it's one way your binding would be overridden (unless you muck with character properties to define your key everywhere, really icky).

The next place Emacs looks is in the variable emulation-mode-map-alists, which is probably your best bet. It was set up for packages to use in cases where there are multiple minor-mode keymaps it wants to juggle.

Make a global minor mode (see Defining Minor Modes), put your key binding in there, add your minor mode and keymap into the emulation-mode-map-alists, and turn on your minor mode.

Your key binding will now have precedence over all others, except those earlier in the emulation-mode-map-alist list, or found in character properties, or in the overriding-local-map...

I believe that's the best you can do, w/out hacking Emacs source.

驱逐舰岛风号 2024-10-29 20:36:08

在次要模式键绑定覆盖我个人的全局绑定的情况下,我很幸运地使用了 add-hook + local-unset-key

(add-hook 'undo-tree-mode
(拉姆达()
(本地未设置键“C-/”)))

In the case of minor mode keybindings overriding my personal global bindings i have had luck using add-hook + local-unset-key

(add-hook 'undo-tree-mode
(lambda ()
(local-unset-key "C-/")))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文