模式特定的按键绑定
我有一个小模式,同时也有一个全局模式。该模式有一些键绑定,我希望用户能够指定哪些绑定适用于每种模式。
(my-minor-mode-bindings-for-mode 'some-mode '(key1 key2 ...))
(my-minor-mode-bindings-for-mode 'some-other-mode '(key3 key4 ...))
所以我需要某种模式/缓冲区本地键映射。本地缓冲区是一个 有点问题,因为用户可以更改主要模式。
我尝试过一些解决方案,但都没有效果。
- 始终绑定所有可能的键,当用户键入该键时,检查该键是否应在该模式下处于活动状态。如果为 true 则执行操作,否则回退。
- 与前一种情况类似,只是没有绑定任何键。相反,我使用预命令挂钩并检查按下的键是否应该执行任何操作。
- 对于每个缓冲区更新(无论这意味着什么),运行一个函数,首先清除键映射,然后使用该特定模式的绑定更新它。
我尝试过这些方法,但发现它们都存在问题。您知道有什么好的方法可以解决这个问题吗?
谢谢!
I have a minor mode that also comes with a global mode. The mode have some key bindings and I want the user to have the posibility to specify what bindings should work for each mode.
(my-minor-mode-bindings-for-mode 'some-mode '(key1 key2 ...))
(my-minor-mode-bindings-for-mode 'some-other-mode '(key3 key4 ...))
So I need some kind of mode/buffer-local key map. Buffer local is a
bit problematic since the user can change the major mode.
I have tried some solutions of which neither works any good.
- Bind all possible keys always and when the user types the key, check if the key should be active in that mode. Execute action if true, otherwise fall back.
- Like the previous case only that no keys are bound. Instead I use a pre command hook and check if the key pressed should do anything.
- For each buffer update (whatever that means), run a function that first clears the key map and then updates it with the bindings for that particular mode.
I have tried these approaches and I found problems with all of them. Do you know of any good way to solve this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你可以添加键绑定是一个钩子:
匿名函数当然可能更复杂,你可以做任何你想做的检查。当然,如果您需要交互地更改绑定,您可以简单地使用一些交互功能......
You may add the key bindings is a hook I guess:
The anonymous function may be more complex of course and you can do whatever checks you'd like to do. Of course if you need to change the bindings interactively you can simply use some interactive function...
将
some-mode-map
变量缓冲区设为本地,当启用some-mode
时,它将检查要安装哪组按键绑定。因为some-mode-map
是缓冲区本地的,所以键绑定应该是该缓冲区本地的(并且不会影响其他缓冲区)。Make the
some-mode-map
variable buffer local, and whensome-mode
is enabled, it'll check to see which of the sets of key bindings to install. Because thesome-mode-map
is buffer local, the key bindings should be local to that buffer (and not affect the other buffers).