起因是在Windows下使用consult
包特别是其预览功能感觉有一点点卡,另外consult-buffer
对bookmark、recent file等类型“buffer”的聚合对我而言有点繁杂。最近把consult
drop掉了,但是切换buffer时具备的过滤功能还是很有必要的,所以对switch-to-buffer
进行了配置。
(defvar buffer:skip-regexp
(rx bos
?*
(or
"Messages"
"Output"
"Compile-Log"
"Completions"
"Flymake log"
"Warnings"
"Flymake diagnostics"
"Async Shell Command"
"Async-native-compile-log"
"Native-compile-Log"
"Apropos"
"Backtrace"
"prodigy"
"help"
)
(* anything)
?*
eos))
(advice-add 'read-buffer-to-switch :around #'buffer:skip-read-buffer-to-switch)
(defun buffer:skip-read-buffer-to-switch (fn &rest args)
;; 避免 `other-buffer' 选取需要忽略的buffer
(unless (frame-parameter nil 'buffer-predicate)
(set-frame-parameter nil 'buffer-predicate
(lambda (buffer)
(not (string-match-p buffer:skip-regexp
(buffer-name buffer))))))
(minibuffer-with-setup-hook
(lambda ()
;; 将需要忽略的buffer从 `minibuffer-completion-table' 中过滤
(setq-local minibuffer-completion-predicate
(lambda (name)
(not (string-match-p buffer:skip-regexp
(if (consp name) (car name) name))))))
(apply fn args)))
目前用了下好像还行,就是不知道有没有其它副作用,特别是设置了buffer-predicate
这个frame参数。