fix(yasnippet): add yasnippet-capf first in CAPF list for corfu integration

This commit is contained in:
2026-02-24 14:39:24 +01:00
parent 4859a4edb4
commit 8ba2c65fcf

View File

@@ -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