gpt4 book ai didi

emacs - 如何在不更改 TAB 的情况下将命令绑定(bind)到 C-i?

转载 作者:行者123 更新时间:2023-12-03 00:39:54 26 4
gpt4 key购买 nike

在 emacs 中,我想将命令绑定(bind)到 C-i。所以我把 (global-set-key "\C-i"'forward-word)

在我的 .emacs 文件中。这是可行的,只不过现在 TAB 键也绑定(bind)到“forward-word”。

如何在不更改 TAB 的情况下将命令绑定(bind)到 C-i?

最佳答案

简而言之,这应该可以解决您的问题:

(setq local-function-key-map (delq '(kp-tab . [9]) local-function-key-map))
(global-set-key (kbd "C-i") 'forward-word)

更长的版本:

摘自 function keys 上的 emacs lisp 文档:

In ASCII, C-i and <TAB> are the same character. If the terminal can distinguish between them, Emacs conveys the distinction to Lisp programs by representing the former as the integer 9, and the latter as the symbol tab.

Most of the time, it's not useful to distinguish the two. So normally local-function-key-map (see Translation Keymaps) is set up to map tab into 9. Thus, a key binding for character code 9 (the character C-i) also applies to tab. Likewise for the other symbols in this group. The function read-char likewise converts these events into characters.

因此,一旦执行以下操作,您就可以看到键绑定(bind)的差异:

(setq local-function-key-map (delq '(kp-tab . [9]) local-function-key-map))

;; this is C-i
(global-set-key (kbd "C-i") (lambda () (interactive) (message "C-i")))
;; this is <tab> key
(global-set-key (kbd "<tab>") (lambda () (interactive) (message "<tab>")))

请注意,每种模式都会以不同的方式设置各种 TAB 绑定(bind),因此您可能需要针对您关心的每种模式进行自定义。

版本依赖:

以上适用于 Emacs 23.1。来自新闻文件:

Function key sequences are now mapped using `local-function-key-map', a new variable. This inherits from the global variable function-key-map, which is not used directly any more.

这意味着,在版本 22 及更早版本中,您可以通过使用变量 function-key-map 获得相同的效果。我对此进行了测试,发现它可以与 Emacs 21 一起使用。

(setq local-function-key-map (delq '(kp-tab . [9]) function-key-map))
(global-set-key (kbd "C-i") 'forward-word)

关于emacs - 如何在不更改 TAB 的情况下将命令绑定(bind)到 C-i?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1792326/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com