fix(corfu): fix default minibuffer completion

After setting +corfu-want-minibuffer-completion to t, I noticed that it
Corfu was still being enabled in Consult when finding files. This change
fixes that by ensuring that Corfu gets disabled in the minibuffer
whenever another completion framework is active.
This commit is contained in:
StrawberryTea
2025-02-02 17:00:29 -05:00
committed by Henrik Lissner
parent 52183d717d
commit 0d1c8942db

View File

@ -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-sources 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 theres 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'.