gpt4 book ai didi

Emacs:与 TAB 的键绑定(bind)会破坏 minibuffer 中的自动完成功能

转载 作者:行者123 更新时间:2023-12-01 08:29:39 24 4
gpt4 key购买 nike

简单地说,我只是在 TAB 键上设置了一个键绑定(bind),但是现在当我在 minibuffer 中按下 TAB 以自动完成命令时,它会失败并显示以下消息:The mark is not set now, so there is no region .

换句话说,当我的光标在缓冲区(而不是迷你缓冲区)中时,我只需要我的 TAB 键绑定(bind)。

在下面的示例中,当我在缓冲区中处于文本/基本模式时,如何将选项卡设置为缩进,而不会在迷你缓冲区中丢失自动完成功能?我有以下功能和键绑定(bind):

;; Shift the selected region right if distance is postive, left if
;; negative

(defun shift-region (distance)
(let ((mark (mark)))
(save-excursion
(indent-rigidly (region-beginning) (region-end) distance)
(push-mark mark t t)
;; Tell the command loop not to deactivate the mark
;; for transient mark mode
(setq deactivate-mark nil))))

(defun shift-right ()
(interactive)
(shift-region 2))

(defun shift-left ()
(interactive)
(shift-region -2))

;; Bind (shift-right) and (shift-left) function to your favorite keys. I use
;; the following so that Ctrl-Shift-Right Arrow moves selected text one
;; column to the right, Ctrl-Shift-Left Arrow moves selected text one
;; column to the left:

;; (global-set-key [C-S-right] 'shift-right)
;; (global-set-key [C-S-left] 'shift-left)
(global-set-key [tab] 'shift-right)
(global-set-key [backtab] 'shift-left)

最佳答案

问题只是您将命令绑定(bind)到 [tab]而不是 "\t" . tab表示 GUI 下的 TAB 键,但在 tty 下 Emacs 接收的是 TAB 字符(即 ?\t ),所以当你点击 tab Emacs 首先查找 tab绑定(bind),如果没有,则为 function-key-map重新映射将其变为 ?\t并再次尝试。 minibuffer 只绑定(bind) "\t" , 所以任何全局绑定(bind)到 [tab]将优先。

简而言之,使用 (global-set-key "\t" 'shift-right)这个问题就会消失。

关于Emacs:与 TAB 的键绑定(bind)会破坏 minibuffer 中的自动完成功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22522398/

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