diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2025-04-06 00:54:53 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2025-04-06 02:09:49 +0200 |
| commit | eea39b5d4e9fcaad89afe94dd15e313aeb82d1ba (patch) | |
| tree | b75c00f84a7f0d462237ae72a8762a0ddfc5d532 | |
| parent | a7fbcb6a2029790dd1b1bbc9c316a862152a0cd5 (diff) | |
history-length can be t, don't use it.
| -rw-r--r-- | extensions/corfu-history.el | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/extensions/corfu-history.el b/extensions/corfu-history.el index a93bc14..0022fbc 100644 --- a/extensions/corfu-history.el +++ b/extensions/corfu-history.el @@ -50,7 +50,7 @@ or the property `history-length' of `corfu-history'.") "Hash table of Corfu candidates.") (defcustom corfu-history-duplicate 1.0 - "Weight of duplicate elements, multiplied with `history-length'. + "Weight of duplicate elements, multiplied with 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 @@ -68,11 +68,12 @@ is 1.0, frequency is more relevant than recency. Note that (defun corfu-history--sort (cands) "Sort CANDS by history." (unless corfu-history--hash - (setq corfu-history--hash (make-hash-table :test #'equal :size (length corfu-history))) - (cl-loop for weight = (round (* history-length corfu-history-duplicate)) - for elem in corfu-history for idx from 0 - for dup = (gethash elem corfu-history--hash) do - (puthash elem (if dup (- dup weight) idx) corfu-history--hash))) + (let* ((len (length corfu-history)) + (weight (round (* len corfu-history-duplicate)))) + (setq corfu-history--hash (make-hash-table :test #'equal :size len)) + (cl-loop for elem in corfu-history for idx from 0 + for dup = (gethash elem corfu-history--hash) do + (puthash elem (if dup (- dup weight) idx) corfu-history--hash)))) (cl-loop for max = most-positive-fixnum for cand on cands do (setcar cand (cons (car cand) (gethash (car cand) corfu-history--hash max)))) (setq cands (sort cands #'corfu-history--sort-predicate)) |
