fix: remove cape-elisp-symbol from text-mode; corfu TAB tries yas-expand first

This commit is contained in:
2026-02-24 14:35:50 +01:00
parent 1b79d3fa10
commit 4859a4edb4

View File

@@ -589,14 +589,28 @@ and optional priority indicator [#A]."
(use-package! cape (use-package! cape
:after corfu :after corfu
:config :config
(defun martin/cape-capf-setup () (defun martin/cape-capf-setup-text ()
"Set up cape completion sources for prog-mode and text-mode." "Cape sources for text modes (org, markdown, etc.) — no Elisp symbols."
(add-to-list 'completion-at-point-functions #'cape-dabbrev 0) ; words from buffers (add-to-list 'completion-at-point-functions #'cape-dabbrev 0)
(add-to-list 'completion-at-point-functions #'cape-file 0) ; file paths (add-to-list 'completion-at-point-functions #'cape-file 0))
(add-to-list 'completion-at-point-functions #'cape-keyword 0) ; language keywords (defun martin/cape-capf-setup-prog ()
(add-to-list 'completion-at-point-functions #'cape-elisp-symbol 0)) "Cape sources for prog modes — includes Elisp symbols only in Elisp."
(add-hook 'prog-mode-hook #'martin/cape-capf-setup) (add-to-list 'completion-at-point-functions #'cape-dabbrev 0)
(add-hook 'text-mode-hook #'martin/cape-capf-setup)) (add-to-list 'completion-at-point-functions #'cape-file 0)
(add-to-list 'completion-at-point-functions #'cape-keyword 0)
(when (derived-mode-p 'emacs-lisp-mode)
(add-to-list 'completion-at-point-functions #'cape-elisp-symbol 0)))
(add-hook 'text-mode-hook #'martin/cape-capf-setup-text)
(add-hook 'prog-mode-hook #'martin/cape-capf-setup-prog))
;; When corfu popup is active, TAB tries yasnippet first, then completes.
;; Fixes: typing a snippet key (e.g. "adr") + TAB expands the snippet
;; even when the corfu popup is showing unrelated candidates.
(after! (corfu yasnippet)
(define-key corfu-map [tab]
(lambda () (interactive) (or (yas-expand) (corfu-complete))))
(define-key corfu-map (kbd "TAB")
(lambda () (interactive) (or (yas-expand) (corfu-complete)))))
;; Corfu popup in terminal — only needed for Emacs < 31 without child-frame support. ;; Corfu popup in terminal — only needed for Emacs < 31 without child-frame support.
;; Emacs 31 handles corfu natively even in terminal; loading corfu-terminal ;; Emacs 31 handles corfu natively even in terminal; loading corfu-terminal