gpt4 book ai didi

emacs - 在 Emacs 中,keyboard-escape-quit 不破坏其他窗口的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-03 20:08:05 25 4
gpt4 key购买 nike

编辑:我知道有键盘退出(通常绑定(bind)到 C-g);但我更想知道如何处理 Emacs 附带的编辑功能(就像在这种情况下)。当我想更改一些内置函数时,我不时会遇到这种情况。

在emacs中,当您按M-ESC ESC(或ESC 3次)时,您可以摆脱很多情况,例如 transient 标记等。但是我习惯性地按了escape键(实际上我将其重新映射为单次点击转义键)超出了我的预期,这最终会杀死我的 Windows 配置,这很烦人。函数keyboard-escape-quit在simple.el中定义:

(defun keyboard-escape-quit ()
"Exit the current \"mode\" (in a generalized sense of the word).
This command can exit an interactive command such as `query-replace',
can clear out a prefix argument or a region,
can get out of the minibuffer or other recursive edit,
cancel the use of the current buffer (for special-purpose buffers),
or go back to just one window (by deleting all but the selected window)."
(interactive)
(cond ((eq last-command 'mode-exited) nil)
((> (minibuffer-depth) 0)
(abort-recursive-edit))
(current-prefix-arg
nil)
((and transient-mark-mode mark-active)
(deactivate-mark))
((> (recursion-depth) 0)
(exit-recursive-edit))
(buffer-quit-function
(funcall buffer-quit-function))
((not (one-window-p t))
(delete-other-windows))
((string-match "^ \\*" (buffer-name (current-buffer)))
(bury-buffer))))

而且我可以看到我不想要这些线条:
    ((not (one-window-p t))
(delete-other-windows))

但是修改此功能的最佳方法是什么?我只能看到两种方法:1)修改 simple.el 2)将此函数复制到我的 .emacs 文件并在那里进行修改。两种方式都不是很好。理想情况下,我希望在 defadvice 上看到一些东西,但我不知道在这种情况下我该怎么做。

最佳答案

您可以使用 around 建议并重新定义违规函数来执行您想要的操作(即 one-window-p 应该始终返回 t):

(defadvice keyboard-escape-quit (around my-keyboard-escape-quit activate)
(let (orig-one-window-p)
(fset 'orig-one-window-p (symbol-function 'one-window-p))
(fset 'one-window-p (lambda (&optional nomini all-frames) t))
(unwind-protect
ad-do-it
(fset 'one-window-p (symbol-function 'orig-one-window-p)))))

这种行为类似于 (let ...) 但必须更复杂,因为您需要覆盖有限范围的函数而不是变量。

关于emacs - 在 Emacs 中,keyboard-escape-quit 不破坏其他窗口的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/557282/

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