Emacs 全局设置键到 C-TAB
我正在尝试在 Emacs 中设置 Ctrl+TAB 的键绑定。 我使用了以下调用:
(global-set-key (read-kbd-macro "C-TAB") 'my-func)
但是,每当我使用它时,我都会收到一条
<C-tab> is undefined
错误消息。 尝试将绑定设置为“C-tab”会导致错误消息。
如何设置与 C-TAB 的绑定?
I'm trying to set a key-binding to Ctrl+TAB in Emacs. I used the following call:
(global-set-key (read-kbd-macro "C-TAB") 'my-func)
However, whenever I use it, I get a
<C-tab> is undefined
error message. Trying to set the binding to "C-tab" results in an error message.
How can I set my binding to C-TAB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
与其他人建议的不同,如果您想使用相同的内容,最好使用
kbd
(或read-kbd-macro
,这基本上是相同的东西)其他版本的 Emacs 中的配置文件;kbd
适用于 Emacs 和 XEmacs 的多个版本,其中按键序列的内部表示不同。read-kbd-macro
使用的输入格式记录在edmacro-mode
的文档字符串中:这写得有些不幸; 第一个要点中提到的 TAB 是 TAB 的 ASCII 字符,添加 Control 修饰符会对其执行一些无意义的操作。 当您按下 Control-Tab 时,Emacs 将其视为带有 Control 修饰符的
(通过您的窗口系统;它无法在文本终端中工作),您可以将其表示为C-
或
。Unlike others have suggested, it is a good idea to use
kbd
(orread-kbd-macro
which is basically the same thing) in case you ever want to use the same configuration files in other versions of Emacs;kbd
works across several versions of Emacs and XEmacs, where the internal representation of key sequences are different.The input format used by
read-kbd-macro
is documented in the docstring ofedmacro-mode
:This is written somewhat unfortunately; the TAB referred to in the first bullet point is the ASCII character for TAB, and adding the Control modifier does something nonsensical to it. When you press Control-Tab, Emacs sees it (via your windowing system; it will not work in a text terminal) as
<tab>
with a Control modifier, which you can represent asC-<tab>
or<C-tab>
.这是因为您错误地使用了
read-kbd-macro
。 当您看到绑定到某个键的内容时:Emacs 会告诉您:
您需要包含 <> 在调用
read-kbd-macro
时。而且,我不知道如何生成
,但它与
不一样。It's because you are using
read-kbd-macro
incorrectly. When you see what is bound to a key:Emacs tells you:
You need to include the <> in your invocation of
read-kbd-macro
.And, I don't know how to generate
<C-TAB>
, but it's not the same as<C-tab>
.请注意,您还可以交互调用
global-set-key
。 然后,您可以使用repeat-complex-command
查看正确的绑定命令(另请参阅 KeybindingGuide ):Mx: global-set-key
使用
Cx ESC ESC
(repeat-complex-command< /code>) 查看适当的命令。 在你的情况下,我得到:
Note that you can also call
global-set-key
interactively. You can then see the correct binding command withrepeat-complex-command
(see also KeybindingGuide):M-x: global-set-key
Use
C-x ESC ESC
(repeat-complex-command
) to see the apropiate command. In your case I get:尝试使用更简单的语法而不是使用
read-kbd-macro
?也许更简单的语法会有所不同?
更多关于 read-kbd-macro 和 全局设置键。
Instead of using
read-kbd-macro
, try using the more plain syntax?Perhaps the plainer syntax will make a difference?
More on read-kbd-macro and global-set-key.
在 gnu emacs lisp 参考手册第 21.1 节“按键序列”中,他们引用使用 \t 来表示 tab 键。
使用 Lisp 参考手册中显示的语法,我将使用以下命令:
(global-set-key (kbd "C-\t") 'my-func)
In the gnu emacs lisp reference manual, section 21.1 "Key Sequences", they reference using \t to represent the tab key.
Using the syntax shown in the Lisp reference manual, I would use the following command:
(global-set-key (kbd "C-\t") 'my-func)