Function: vertico--compute

vertico--compute is a byte-compiled function defined in vertico.el.

Signature

(vertico--compute INPUT)

Documentation

Compute state given INPUT.

Source Code

;; Defined in ~/.emacs.d/elpa/vertico-20260811.1003/vertico.el
(defun vertico--compute (input)
  "Compute state given INPUT."
  (pcase-let* ((`(,str . ,pt) input)
               (table minibuffer-completion-table)
               (pred minibuffer-completion-predicate)
               (before (substring str 0 pt))
               (after (substring str pt))
               ;; bug#47678: `completion-boundaries' fails for `partial-completion'
               ;; if the cursor is moved before the slashes of "~//".
               ;; See also corfu.el which has the same issue.
               (bounds (condition-case nil
                           (completion-boundaries before table pred after)
                         (t (cons 0 (length after)))))
               (field (substring str (car bounds) (+ pt (cdr bounds))))
               ;; bug#75910: category instead of `minibuffer-completing-file-name'
               (completing-file (eq 'file (vertico--metadata-get 'category)))
               (`(,all . ,hl) (vertico--filter-completions str table pred pt vertico--metadata))
               (base (or (when-let* ((z (last all))) (prog1 (cdr z) (setcdr z nil))) 0))
               (vertico--base (substring str 0 base))
               (def (or (car-safe minibuffer-default) minibuffer-default))
               (groups) (def-missing) (lock))
    ;; Filter the ignored file extensions. We cannot use modified predicate for this filtering,
    ;; since this breaks the special casing in the `completion-file-name-table' for `file-exists-p'
    ;; and `file-directory-p'.
    (when completing-file (setq all (completion-pcm--filename-try-filter all)))
    ;; Sort using the `display-sort-function' or the Vertico sort functions
    (setq all (funcall (or (vertico--sort-function) #'identity) all))
    ;; Move special candidates: "field" appears at the top, before "field/", before default value
    (when (stringp def)
      (setq all (vertico--move-to-front def all)))
    (when (and completing-file (not (string-suffix-p "/" field)))
      (setq all (vertico--move-to-front (concat field "/") all)))
    (setq all (delete-consecutive-dups (vertico--move-to-front field all)))
    (when-let* ((fun (and all (vertico--metadata-get 'group-function))))
      (setq groups (vertico--group-by fun all) all (car groups)))
    (setq def-missing (and def (equal str "") (not (member def all)))
          lock (and vertico--lock-candidate ;; Locked position of old candidate.
                    (if (< vertico--index 0) -1
                      (seq-position all (nth vertico--index vertico--candidates)))))
    `((vertico--input . ,input)
      (vertico--base . ,vertico--base)
      (vertico--metadata . ,vertico--metadata)
      (vertico--candidates . ,all)
      (vertico--total . ,(length all))
      (vertico--hilit . ,(or hl #'identity))
      (vertico--allow-prompt . ,(and (not (eq vertico-preselect 'no-prompt))
                                     (or def-missing (eq vertico-preselect 'prompt)
                                         (memq minibuffer--require-match
                                               '(nil confirm confirm-after-completion)))))
      (vertico--lock-candidate . ,lock)
      (vertico--groups . ,(cdr groups))
      (vertico--index . ,(or lock
                             (if (or def-missing (eq vertico-preselect 'prompt) (not all)
                                     (and completing-file (eq vertico-preselect 'directory)
                                          (= (length vertico--base) (length str))
                                          (test-completion str table pred)))
                                 -1 0))))))