pol*_*lot 15 emacs elisp dot-emacs
编辑:我知道有键盘退出(通常绑定到Cg); 但我更感兴趣的是如何处理Emacs附带的编辑功能(就像在这种情况下).当我想改变一些内置函数时,我经常遇到这种情况.
在emacs中,当你按下M-ESC ESC(或ESC三次)时,你可以摆脱很多情况,比如瞬态标记等.但是我习惯性地按下了逃生键(我实际上将其重新映射到了逃脱键)比我想要的更多,并最终杀死我的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))))
Run Code Online (Sandbox Code Playgroud)
我可以看到我不想要这些线条:
((not (one-window-p t))
(delete-other-windows))
Run Code Online (Sandbox Code Playgroud)
但修改此功能的最佳方法是什么?我只能看到两种方式:1)修改simple.el 2)将此函数复制到我的.emacs文件并在那里进行修改.两种方式都不是很好 ; 理想情况下,我希望在defadvice线上看到一些东西,但在这种情况下我无法看到我能做到的.
sco*_*zer 15
您可以使用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)))))
Run Code Online (Sandbox Code Playgroud)
这种行为类似于(let ...)但必须更复杂,因为您需要覆盖有限范围的函数而不是变量.
我经常发现'键盘退出(Cg)可以摆脱所有这些情况.
但是,如果你真的想拥有这个函数的变体,我认为复制到你的.emacs文件(并重命名,我通常会使用bp的前缀)并在那里进行编辑可能是最好的选择.
编辑,响应编辑:一般情况下,每当我想要编辑版本的emacs函数时,我要么自己编写,要么将其复制到我的.emacs,重命名为bp-whotever,然后进行适当的编辑.
这种情况的缺点是我的.emacs是巨大的,并且可能超常使用不再使用的古老功能...好处是每当我需要写一些新东西时,我有大量的示例代码可供查看...
这是另一个更简单的建议,它利用了关闭窗口之前keyboard-escape-quit调用的事实:buffer-quit-function
(defadvice keyboard-escape-quit
(around keyboard-escape-quit-dont-close-windows activate)
(let ((buffer-quit-function (lambda () ())))
ad-do-it))
Run Code Online (Sandbox Code Playgroud)
适用于 Emacs 25.1。(我最初使用了 @scottfrazer 的建议,但在 25.1 中不太满意。还没有费心调试。)
| 归档时间: |
|
| 查看次数: |
2139 次 |
| 最近记录: |