Function: consult--multi-state
consult--multi-state is a byte-compiled function defined in
consult.el.
Signature
(consult--multi-state SOURCES)
Documentation
State function given SOURCES.
Source Code
;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
(defun consult--multi-state (sources)
"State function given SOURCES."
(when-let* ((states (delq nil (mapcar (lambda (src)
(when-let* ((fun (plist-get src :state)))
(cons src (funcall fun))))
sources))))
(let (last-fun)
(pcase-lambda (action `(,cand . ,src))
(pcase action
('setup
(pcase-dolist (`(,_ . ,fun) states)
(funcall fun 'setup nil)))
('exit
(pcase-dolist (`(,_ . ,fun) states)
(funcall fun 'exit nil)))
('preview
(let ((selected-fun (cdr (assq src states))))
;; If the candidate source changed during preview communicate to
;; the last source, that none of its candidates is previewed anymore.
(when (and last-fun (not (eq last-fun selected-fun)))
(funcall last-fun 'preview nil))
(setq last-fun selected-fun)
(when selected-fun
(funcall selected-fun 'preview cand))))
('return
(let ((selected-fun (cdr (assq src states))))
;; Finish all the sources, except the selected one.
(pcase-dolist (`(,_ . ,fun) states)
(unless (eq fun selected-fun)
(funcall fun 'return nil)))
;; Finish the source with the selected candidate
(when selected-fun
(funcall selected-fun 'return cand)))))))))