branch: externals/corfu commit 101002411e6266b719fc252ce02f1418782d552f Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Update changelog --- CHANGELOG.org | 5 +++-- extensions/corfu-history.el | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index a88528b7f0..89c4efec67 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -4,8 +4,9 @@ * Development -- ~corfu-history-duplicate~: Prioritize duplicate history elements when sorting by - history via ~corfu-history-mode~. +- =corfu-history-duplicate= and =corfu-history-decay=: New customization options to + adjust the rank of duplicate history elements, such that they appear earlier + in the completion list. * Version 2.0 (2025-03-28) diff --git a/extensions/corfu-history.el b/extensions/corfu-history.el index 5ff6039c09..4280cbe32a 100644 --- a/extensions/corfu-history.el +++ b/extensions/corfu-history.el @@ -77,13 +77,13 @@ See also `corfu-history-duplicate'." (unless corfu-history--hash (let ((ht (make-hash-table :test #'equal :size (length corfu-history)))) (cl-loop for elem in corfu-history for idx from 0 - for w = (if-let ((w (gethash elem ht))) - ;; Reduce duplicate weight with exponential decay. - (- w (round (* corfu-history-duplicate + for r = (if-let ((r (gethash elem ht))) + ;; Reduce duplicate rank with exponential decay. + (- r (round (* corfu-history-duplicate (exp (* -1.0 corfu-history-decay idx))))) ;; Never outrank the most recent element. (if (= idx 0) (/ most-negative-fixnum 2) idx)) - do (puthash elem w ht)) + do (puthash elem r ht)) (setq corfu-history--hash ht))) (cl-loop for ht = corfu-history--hash for max = most-positive-fixnum for cand on cands do