Function: vertico-sort--define

vertico-sort--define is a macro defined in vertico-sort.el.

Signature

(vertico-sort--define BY BSIZE BINDEX BPRED PRED)

Documentation

Generate optimized sorting function.

The function is configured by BY, BSIZE, BINDEX, BPRED and PRED.

Source Code

;; Defined in ~/.emacs.d/elpa/vertico-20260913.1525/vertico-sort.el
(defmacro vertico-sort--define (by bsize bindex bpred pred)
  "Generate optimized sorting function.
The function is configured by BY, BSIZE, BINDEX, BPRED and PRED."
  `(defun ,(intern (mapconcat #'symbol-name `(vertico sort ,@by) "-")) (candidates)
     ,(concat "Sort candidates by " (mapconcat #'symbol-name by ", ") ".")
     (let ((buckets (make-vector ,bsize nil)) last
           ,@(and (eq (car by) 'history) '((hhash (vertico-sort--history)) hcands)))
       (dolist (% candidates)
         ;; Find recent candidate in history or fill bucket
         (,@(if (not (eq (car by) 'history)) `(progn)
              `(if-let* ((idx (gethash % hhash))) (push (cons idx %) hcands)))
          (let ((i ,bindex)) (if (< i ,bsize) (push % (aref buckets i)) (push % last)))))
       (nconc ,@(and (eq (car by) 'history) '((vertico-sort--decorated hcands)))
              (mapcan (lambda (bucket) (sort bucket #',bpred)) buckets)
              (sort last #',pred)))))