branch: externals/vertico commit f78f0e98786bfb519eb146c714fdf28f82959dda Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Constant step size --- extensions/vertico-sort.el | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/extensions/vertico-sort.el b/extensions/vertico-sort.el index 5b9af5da28..b8c71d4488 100644 --- a/extensions/vertico-sort.el +++ b/extensions/vertico-sort.el @@ -38,14 +38,12 @@ (defvar-local vertico-sort--history nil "History hash table and corresponding base string.") -(defcustom vertico-sort-history-duplicate 1.0 - "Weight of duplicate elements, multiplied by the length of the history. -Duplicate elements in the history are prioritized such that they appear -earlier in the completion list. The value should be between 0.0 and -1.0. For 0, only the recency of history elements matters. If the value -is 1.0, frequency is more relevant than recency. Note that duplicates -occur only if `history-delete-duplicates' is disabled." - :type 'float +(defcustom vertico-sort-history-duplicate 10 + "Number of history positions gained by duplicate history elements. +The more often a duplicate element occurs in the history, the earlier it +appears in the completion list. Note that duplicates occur only if +`history-delete-duplicates' is disabled." + :type 'natum :group 'vertico) (defun vertico-sort--history () @@ -55,14 +53,12 @@ occur only if `history-delete-duplicates' is disabled." (base-len (length base)) (hist (and (not (eq minibuffer-history-variable t)) ;; Disabled for `t'. (symbol-value minibuffer-history-variable))) - (hist-len (length hist)) - (ht (make-hash-table :test #'equal :size hist-len)) + (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))) - (dup (round (* hist-len vertico-sort-history-duplicate)))) + (abbreviate-file-name file)))) (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) @@ -72,7 +68,10 @@ occur only if `history-delete-duplicates' is disabled." ;; 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))))) - (puthash elem (if-let ((n (gethash elem ht))) (- n dup) idx) ht)))) + (puthash elem (if-let ((n (gethash elem ht))) + (- n vertico-sort-history-duplicate) + (if (= idx 0) (/ most-negative-fixnum 2) idx)) + ht)))) (cdr (setq vertico-sort--history (cons base ht)))))) (defun vertico-sort--length-string< (x y)