在哪个文件中定义了键绑定?
考虑 Emacs 中的击键,例如 Cx Cs。 我可以通过输入 Ch c keytrip 找出它调用的函数,但是如何找到定义此键绑定的位置?
(也许正确的答案是无法决定,因为键盘映射不存储此类信息。)
Considering a keystroke in Emacs, e.g. C-x C-s. I can figure out which function it invokes by typing C-h c keystroke, but how can I find where this keybinding was defined?
(Maybe the right answer is that it cannot be decided, because the keymaps don't store this kind of information.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Emacs 不保留有关键绑定与函数关联的位置的信息。 事实上,答案通常是不确定的。
很多时候,键绑定被设置为次要模式的副作用,或者通过模式挂钩设置。 次要模式的按键绑定通常存储在一些变量中,例如 comint-mode-map 。 该键盘映射通过设置模式变量
comint-mode
来启用。 但是,该模式映射是一个全局变量,任何人、任何地方都可以向其添加键绑定。 因此,做你想做的事本质上就是跟踪谁设置了具有特定值的变量。 类似地,对于仅通过模式挂钩在本地设置的键绑定(使用local-set-key
)。 另外,您甚至可以通过 文件变量。 所有这些只是说明 Emacs 中的键绑定是短暂的。您能做的最好的事情就是找到与该键关联的功能,然后查看该文件(如果模式拆分为多个文件,则查看任何相关文件)。
由于可以通过多种方式设置/关联击键(全局、主要模式、次要模式、覆盖次要模式、本地缓冲区、文本属性等),emacs 中的键绑定查找相当复杂。 如需快速概览,请查看此文档。
您可以编写这样的函数来查看次要模式,以查看可能在哪里设置键绑定,但当然我的第一个测试显示那里没有定义键绑定。 但也许代码会有启发性。
您是否有想要解决的特定问题(除了这个问题)?
The information as to where keybindings are associated with functions is not kept by Emacs. In fact, the answer is usually undefined.
Many times key bindings are set up as a side-effect of a minor mode, or through mode-hooks. The key binding for minor modes is often stored in some variable like
comint-mode-map
. This keymap is enabled by setting the mode-variablecomint-mode
. However, that mode map is a global variable and anyone, anywhere can add key bindings to it. So, doing what you want is essentially tracking who set a variable with a particular value. Similarly for key bindings that are just set locally through mode hooks (usinglocal-set-key
). Plus you can even set up key bindings through file variables. All of this is just to say that the key bindings in Emacs are ephemeral.About the best you can do is find the function associated with the key, and look in that file (or any related files if the mode is split into multiple files).
Key binding lookup in emacs is fairly involved due to the myriad of ways you can set/associate key strokes (globally, major mode, minor modes, overriding minor modes, local to buffers, text properties, etc.). For a quick overview, check out this documentation.
You can write a function like this to look in the minor modes to see where a keybinding might be set, but of course my first test showed the keybinding wasn't defined there. But perhaps the code will be instructive.
Is there a specific problem you're trying to solve (other than this question)?
只需执行 Mx find-function
来自 Emacs 文档:
Just do M-x find-function
From Emacs doc: