From 8ba2c65fcf0ef6e2ea0e4b044aad88a101eebde5 Mon Sep 17 00:00:00 2001 From: Daneel Date: Tue, 24 Feb 2026 14:39:24 +0100 Subject: [PATCH] fix(yasnippet): add yasnippet-capf first in CAPF list for corfu integration --- config.el | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/config.el b/config.el index bb7bd37..d31796e 100644 --- a/config.el +++ b/config.el @@ -603,14 +603,14 @@ and optional priority indicator [#A]." (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))))) +;; Ensure yasnippet-capf is FIRST in completion-at-point-functions +;; so corfu shows snippets and TAB expands them (not inserts plain text). +;; Depth 0 + local=t puts it before cape backends. (GitHub issue #8183) +(after! (yasnippet corfu) + (dolist (hook '(org-mode-hook markdown-mode-hook text-mode-hook prog-mode-hook)) + (add-hook hook + (lambda () + (add-hook 'completion-at-point-functions #'yasnippet-capf 0 t))))) ;; Corfu popup in terminal — only needed for Emacs < 31 without child-frame support. ;; Emacs 31 handles corfu natively even in terminal; loading corfu-terminal @@ -1257,15 +1257,10 @@ Otherwise: runs interactive ement-connect, then opens rooms after sync." (push (expand-file-name "snippets/" org-directory) yas-snippet-dirs) (yas-reload-all) - ;; In Evil insert state, TAB first tries yas-expand, then falls back - ;; to the default TAB behaviour (indent / org-cycle / corfu). - ;; This lets you type a snippet key (e.g. "adr") and press TAB to expand, - ;; without breaking org-mode cycling or completion. - (map! :i [tab] - (lambda () - (interactive) - (or (yas-expand) - (indent-for-tab-command))))) + ;; TAB in Evil insert: with yasnippet-capf first in CAPF list, + ;; corfu shows snippets as expandable items — no manual TAB override needed. + ;; Standard indent-for-tab-command handles org-cycle / indent fallback. + ) ;;; ============================================================ ;;; NAVIGATION — link-hint, avy