From 4859a4edb41dfee890d881a10792ff8e4322bb12 Mon Sep 17 00:00:00 2001 From: Daneel Date: Tue, 24 Feb 2026 14:35:50 +0100 Subject: [PATCH] fix: remove cape-elisp-symbol from text-mode; corfu TAB tries yas-expand first --- config.el | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/config.el b/config.el index 916ffad..bb7bd37 100644 --- a/config.el +++ b/config.el @@ -589,14 +589,28 @@ and optional priority indicator [#A]." (use-package! cape :after corfu :config - (defun martin/cape-capf-setup () - "Set up cape completion sources for prog-mode and text-mode." - (add-to-list 'completion-at-point-functions #'cape-dabbrev 0) ; words from buffers - (add-to-list 'completion-at-point-functions #'cape-file 0) ; file paths - (add-to-list 'completion-at-point-functions #'cape-keyword 0) ; language keywords - (add-to-list 'completion-at-point-functions #'cape-elisp-symbol 0)) - (add-hook 'prog-mode-hook #'martin/cape-capf-setup) - (add-hook 'text-mode-hook #'martin/cape-capf-setup)) + (defun martin/cape-capf-setup-text () + "Cape sources for text modes (org, markdown, etc.) — no Elisp symbols." + (add-to-list 'completion-at-point-functions #'cape-dabbrev 0) + (add-to-list 'completion-at-point-functions #'cape-file 0)) + (defun martin/cape-capf-setup-prog () + "Cape sources for prog modes — includes Elisp symbols only in Elisp." + (add-to-list 'completion-at-point-functions #'cape-dabbrev 0) + (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. ;; Emacs 31 handles corfu natively even in terminal; loading corfu-terminal