diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index cb8cc47cc..17d3cb824 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -67,24 +67,41 @@ If any return non-nil, `corfu-auto' will not invoke as-you-type completion.") (add-to-list 'corfu-continue-commands #'+corfu/smart-sep-toggle-escape) (add-hook 'evil-insert-state-exit-hook #'corfu-quit) - ;; Respect `+corfu-want-minibuffer-completion' + (defun +corfu--other-completion-active-p () + "Return non-nil if another completion framework is already active. + +This checks for several completion systems such as mct, vertico, +auth-source’s read-passwd-map, helm, ido, and ivy. When one of these +systems is active, Corfu should not enable its own completion." + (or (bound-and-true-p mct--active) + (bound-and-true-p vertico--input) + (and (featurep 'auth-source) + (eq local-map read-passwd-map)) + (and (featurep 'helm-core) + (helm--alive-p)) + (and (featurep 'ido) + (ido-active)) + (where-is-internal 'minibuffer-complete (list (current-local-map))) + (memq #'ivy--queue-exhibit post-command-hook))) + + ;; Return non-nil if Corfu should be enabled in the minibuffer. + ;; This respects `+corfu-want-minibuffer-completion'. (defun +corfu-enable-in-minibuffer-p () "Return non-nil if Corfu should be enabled in the minibuffer. -See `+corfu-want-minibuffer-completion'." + +This function respects the value of `+corfu-want-minibuffer-completion': +- If set to nil, Corfu is disabled. +- If set to 'aggressive, enable Corfu when no other completion + framework is active. +- Otherwise, enable Corfu only when there’s a bound completion + command in the current local keymap." (pcase +corfu-want-minibuffer-completion ('nil nil) - ('aggressive - (not (or (bound-and-true-p mct--active) - (bound-and-true-p vertico--input) - (and (featurep 'auth-source) - (eq (current-local-map) read-passwd-map)) - (and (featurep 'helm-core) (helm--alive-p)) - (and (featurep 'ido) (ido-active)) - (where-is-internal 'minibuffer-complete - (list (current-local-map))) - (memq #'ivy--queue-exhibit post-command-hook)))) - (_ (where-is-internal #'completion-at-point - (list (current-local-map)))))) + ('aggressive (not (+corfu--other-completion-active-p))) + (_ (and (where-is-internal #'completion-at-point + (list (current-local-map))) + (not (+corfu--other-completion-active-p)))))) + (setq global-corfu-minibuffer #'+corfu-enable-in-minibuffer-p) ;; HACK: Augments Corfu to respect `+corfu-inhibit-auto-functions'.