Function: vertico-sort--history

vertico-sort--history is a byte-compiled function defined in vertico-sort.el.

Signature

(vertico-sort--history)

Documentation

Recompute history hash table and return it.

Source Code

;; Defined in ~/.emacs.d/elpa/vertico-20260913.1525/vertico-sort.el
(defun vertico-sort--history ()
  "Recompute history hash table and return it."
  (or (and (equal (car vertico-sort--history) vertico--base) (cdr vertico-sort--history))
      (let* ((base vertico--base)
             (base-len (length base))
             (hist (and (not (eq minibuffer-history-variable t)) ;; Disabled for `t'.
                        (symbol-value minibuffer-history-variable)))
             (ht (make-hash-table :test #'equal :size (length hist)))
             (file-p (and (> base-len 0) ;; Step-wise completion, unlike `project-find-file'
                          (eq minibuffer-history-variable 'file-name-history)))
             (curr-file (when-let* ((win (and file-p (minibuffer-selected-window)))
                                    (file (buffer-file-name (window-buffer win))))
                          (abbreviate-file-name file)))
             (decay (/ -1.0 (* vertico-sort-history-duplicate vertico-sort-history-decay))))
        (cl-loop for elem in hist for idx from 0 do
                 (when (and (not (equal curr-file elem)) ;; Deprioritize current file
                            (or (= base-len 0)
                                (and (>= (length elem) base-len)
                                     (eq t (compare-strings base 0 base-len elem 0 base-len)))))
                   (let ((file-sep (and file-p (string-search "/" elem base-len))))
                     ;; Drop base string from history elements & special file handling.
                     (when (or (> base-len 0) file-sep)
                       (setq elem (substring elem base-len (and file-sep (1+ file-sep)))))
                     (let ((r (if-let* ((r (gethash elem ht)))
                                  ;; Reduce duplicate rank with exponential decay.
                                  (- r (round (* vertico-sort-history-duplicate
                                                 (exp (* decay idx)))))
                                ;; Never outrank the most recent element.
                                (if (= idx 0) (/ most-negative-fixnum 2) idx))))
                       (puthash elem r ht)))))
        (cdr (setq vertico-sort--history (cons base ht))))))