Function: vertico--arrange-candidates

vertico--arrange-candidates is a byte-compiled function defined in vertico.el.

Signature

(vertico--arrange-candidates)

Documentation

Arrange candidates.

Implementations

(vertico--arrange-candidates (NIL ((&context . vertico-flat-mode) eql t))) in `vertico-flat.el'.

Undocumented

(vertico--arrange-candidates (NIL ((&context . vertico-grid-mode) eql t))) in `vertico-grid.el'.

Undocumented

(vertico--arrange-candidates) in `vertico.el'.

Undocumented

Source Code

;; Defined in ~/.emacs.d/elpa/vertico-20260811.1003/vertico.el
(cl-defgeneric vertico--arrange-candidates ()
  "Arrange candidates."
  (vertico--compute-scroll)
  (let ((curr-line 0) lines)
    ;; Compute group titles
    (let* (title (index vertico--scroll)
           (group-fun (and vertico-group-format (vertico--metadata-get 'group-function)))
           (candidates
            (vertico--affixate
             (cl-loop repeat vertico-count for c in (nthcdr index vertico--candidates)
                      collect (vertico--hilit c)))))
      (pcase-dolist ((and cand `(,str . ,_)) candidates)
        (when-let* ((new-title (and group-fun (funcall group-fun str nil))))
          (unless (equal title new-title)
            (setq title new-title)
            (push (vertico--format-group-title title str) lines))
          (setcar cand (funcall group-fun str 'transform)))
        (when (= index vertico--index)
          (setq curr-line (length lines)))
        (push (cons index cand) lines)
        (incf index)))
    ;; Drop excess lines
    (setq lines (nreverse lines))
    (cl-loop for count from (length lines) above vertico-count do
             (if (< curr-line (/ count 2))
                 (nbutlast lines)
               (setq curr-line (1- curr-line) lines (cdr lines))))
    ;; Format candidates
    (let ((max-width (- (vertico--window-width) 4)) start)
      (cl-loop for line on lines do
               (pcase (car line)
                 (`(,index ,cand ,prefix ,suffix)
                  (setq start (or start index))
                  (when (string-search "\n" cand)
                    (setq cand (vertico--truncate-multiline cand max-width)))
                  (setcar line (vertico--format-candidate cand prefix suffix index start))))))
    lines))