我按照Corfu和Cape的方法配置Corfu,希望能常规使用 (add-to-list 'completion-at-point-functions #'cape-symbol) (add-to-list 'completion-at-point-functions #'cape-file) (add-to-list 'completion-at-point-functions #'cape-dabbrev)
这三个后端,可是发现每当打开文件时,completion-at-point-functions 总是会被该模式特有的后端覆盖;比如打开elisp文件,后端就成了elisp-completion-at-point;我怎么才能让我定义的几个后端始终可以生效,并放在该模式的特有后端的后面呢?
不会每个模式都需要写hook函数吧?
emacs-lisp-mode
中你看到的 completion-at-point-functions
是 local variables
,最后的 t
代表 fallback 到 global variables
。然后 capf 按序请求,在 elisp-completion-at-point
没有返回之后会请求你设置的别的后端,一般情况下这样已经可以满足需求了,如果希望所有 backends 合并,可以用 cape-super-capf
我想用 cape-super-capf写一个可以混合几个后端的函数,用来在发现默认的第一个后端不对时尝试手工调用,可是发现这个cape-super-capf函数好像不是返回后端可调用内容的;我是不是需要新创建一个后端然后用这个函数来进行输出? 还没太搞清楚这个函数的实现机制;不知您有研究吗?
多谢;
没有研究
你可以问问作者哈哈哈,我原来用 company-hard,如果能实现挺好的
corfu + cape 能实现类似 company 的 :with 效果吗?
point at | company-capf | company-dabbrev |
---|---|---|
"foo|" |
||
foo.| |
||
foo| |
糊了个能用的,基本实现了上面的效果
(defun lsp-trigger-chars ()
(->> (lsp--server-capabilities)
(lsp:server-capabilities-completion-provider?)
(lsp:completion-options-trigger-characters?)))
(defun trigger-char-p (sym)
(let ((trigger-chars (lsp-trigger-chars)))
(not (save-excursion
(goto-char (or (car (bounds-of-thing-at-point 'symbol)) (point)))
(and (lsp-completion--looking-back-trigger-characterp trigger-chars) t)))))
(defun yas-trigger-char-p (sym)
(let ((trigger-chars (append (lsp-trigger-chars)
'("\'" "\""))))
(not (save-excursion
(goto-char (or (car (bounds-of-thing-at-point 'symbol)) (point)))
(and (lsp-completion--looking-back-trigger-characterp trigger-chars) t))))
)
(setq completion-at-point-functions
(list (cape-capf-buster
(cape-super-capf
(cape-capf-predicate #'cape-file #'trigger-char-p)
#'lsp-completion-at-point
(cape-capf-predicate #'cape-dabbrev #'trigger-char-p)
(cape-capf-predicate (cape-company-to-capf #'company-yasnippet) #'yas-trigger-char-p))
'equal
)))
(setq completion-at-point-functions
(list (cape-capf-buster
(cape-super-capf
(cape-capf-predicate #'cape-file #'trigger-char-p)
#'lsp-completion-at-point
(cape-capf-predicate #'cape-dabbrev #'trigger-char-p)
(cape-capf-predicate (cape-company-to-capf #'company-yasnippet) #'yas-trigger-char-p))
'equal
)))
如果只是 :with
,cape-super-capf
应该就可以了。复杂版过滤可能还是得自己实现。