Function: consult--read-1

consult--read-1 is a byte-compiled function defined in consult.el.

Signature

(consult--read-1 TABLE &key PROMPT PREDICATE REQUIRE-MATCH HISTORY DEFAULT KEYMAP CATEGORY INITIAL NARROW INITIAL-NARROW ADD-HISTORY ANNOTATE STATE PREVIEW-KEY SORT LOOKUP GROUP INHERIT-INPUT-METHOD ASYNC-WRAP)

Documentation

See consult--read for documentation.

Source Code

;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
(cl-defun consult--read-1 ( table &key
                            prompt predicate require-match history default keymap category
                            initial narrow initial-narrow add-history annotate state
                            preview-key sort lookup group inherit-input-method async-wrap)
  "See `consult--read' for documentation."
  (when (and async-wrap (consult--async-p table))
    (setq table (funcall (funcall async-wrap table) (consult--async-sink))))
  (minibuffer-with-setup-hook
      (:append (lambda ()
                 (add-hook 'after-change-functions #'consult--tofu-hide-in-minibuffer nil 'local)
                 (consult--setup-keymap keymap (consult--async-p table) narrow preview-key)
                 (when initial-narrow (consult-narrow initial-narrow))
                 (setq-local minibuffer-default-add-function
                             (apply-partially #'consult--add-history (consult--async-p table) add-history)
                             kill-transform-function #'consult--tofu-strip)))
    (consult--with-async table
      (consult--with-preview
          preview-key state
          (lambda (narrow input cand)
            (funcall lookup cand (funcall table nil) input narrow))
          (apply-partially #'run-hook-with-args-until-success
                           'consult--completion-candidate-hook)
          (pcase-exhaustive history
            (`(:input ,var) var)
            ((pred symbolp)))
        ;; Do not unnecessarily let-bind the lambdas to avoid over-capturing in
        ;; the interpreter.  This will make closures and the lambda string
        ;; representation larger, which makes debugging much worse.  Fortunately
        ;; the over-capturing problem does not affect the bytecode interpreter
        ;; which does a proper scope analysis.
        (let* ((metadata `(metadata
                           ,@(when category `((category . ,category)))
                           ,@(when group `((group-function . ,group)))
                           ,@(when annotate
                               `((affixation-function
                                  . ,(apply-partially #'consult--read-affixate annotate))))
                           ,@(unless sort '((cycle-sort-function . identity)
                                            (display-sort-function . identity)))))
               (consult--annotate-align-width 0)
               (selected
                (completing-read
                 prompt
                 (lambda (str pred action)
                   (let ((result (complete-with-action action (funcall table nil) str pred)))
                     (if (eq action 'metadata)
                         (if (and (eq (car result) 'metadata) (cdr result))
                             ;; Merge metadata
                             `(metadata ,@(cdr metadata) ,@(cdr result))
                           metadata)
                       result)))
                 predicate require-match initial
                 (if (symbolp history) history (cadr history))
                 default
                 inherit-input-method)))
          ;; Repair the null completion semantics. `completing-read' may return
          ;; an empty string even if REQUIRE-MATCH is non-nil. One can always
          ;; opt-in to null completion by passing the empty string for DEFAULT.
          (when (and (eq require-match t) (not default) (equal selected ""))
            (user-error "No selection"))
          selected)))))