如果我使用 dabbrev-expand
为了扩展,Emacs 搜索当前缓冲区,然后搜索其他具有相同模式的缓冲区。这是由 dabbrev-friend-buffer-function
处理的默认设置为 dabbrev--same-major-mode-p
.
这很好用,但我想使用 hippie-expand
.
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-all-buffers))
这会从所有缓冲区中提取完成,即使是与我当前的主要模式不匹配的缓冲区。
我如何使用
hippie-expand
dabbrev 完成仅来自使用与当前缓冲区相同的主要模式的缓冲区?
最佳答案
快速而肮脏的解决方案:复制函数的源代码try-expand-dabbrev-all-buffers
到一个新位置,重命名它(比如)try-expand-dabbrev-all-buffers-same-mode
,并替换表达式 (buffer-list)
用表达式:
(remove-if-not (lambda (x) (eq major-mode (with-current-buffer x major-mode)))
(buffer-list))
(您需要使用
(require 'cl)
来获得 remove-if-not
,或者根据 mapcar
和 delq
重新实现它。)然后,当然,替换
try-expand-dabbrev-all-buffers
与 try-expand-dabbrev-all-buffers-same-mode
在 hippie-expand-try-functions-list
.您可以获得
try-expand-dabbrev-all-buffers
的来源使用 C-hf。
关于emacs - 在 hippie-expand 中模拟 dabbrev-expand,限制为匹配缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13957861/