emacs - 在 hippie-expand 中模拟 dabbrev-expand,限制为匹配缓冲区

标签 emacs autocomplete elisp emacs24

如果我使用 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 ,或者根据 mapcardelq 重新实现它。)

然后,当然,替换 try-expand-dabbrev-all-bufferstry-expand-dabbrev-all-buffers-same-modehippie-expand-try-functions-list .

您可以获得try-expand-dabbrev-all-buffers的来源使用 C-hf。

关于emacs - 在 hippie-expand 中模拟 dabbrev-expand,限制为匹配缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13957861/

相关文章:

emacs - 如何让 emacs 停止加载 viper 模式?

jquery自动完成从下拉菜单中删除选定的li项目

autocomplete - 自动完成Sublime Text中的自定义JavaScript函数

lisp - 如何在 LISP 中调用 lambda 传递参数

emacs - Emacs Shell出了点问题

python - emacs Python 文件退格键不起作用

python - 使用 emacs 的 unicode (Python 3/Julia) 选项卡完成?

bash 别名不自动完成与别名相同

emacs - 如何检查 Emacs Lisp 中的字符串是否为空?

regex - 在 Emacs 正则表达式中匹配双花括号?