summaryrefslogtreecommitdiff
path: root/helm-adaptive.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thierry.volpiatto@gmail.com>2017-02-23 08:39:56 +0100
committerThierry Volpiatto <thierry.volpiatto@gmail.com>2017-02-23 08:49:28 +0100
commit4f667a09761afc0e903e2b87d0c6628c7036892d (patch)
tree9ab5076f72d67ef202b5f00852c9eceffae55e0d /helm-adaptive.el
parent6a8beabab655f911f25ced99999f68d32d7c2fc9 (diff)
Change adaptive sort from frequency to frequency+recentest.
* helm-adaptive.el (helm-adaptive-store-selection): Store timestamp. (helm-adaptive-sort): Measure frequency+recentest score to sort, use a coefficient of 5 for freq and 2 for recent for now.
Diffstat (limited to 'helm-adaptive.el')
-rw-r--r--helm-adaptive.el32
1 files changed, 20 insertions, 12 deletions
diff --git a/helm-adaptive.el b/helm-adaptive.el
index e4eea155..e0b69a77 100644
--- a/helm-adaptive.el
+++ b/helm-adaptive.el
@@ -122,7 +122,6 @@ Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ..
(if (not found)
;; new entry
(cons helm-pattern 0)
-
;; move entry to the beginning of the
;; list, so if two patterns used the
;; same number of times then the one
@@ -131,12 +130,16 @@ Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ..
(delete found (cdr selection-info)))
found))
(cdr selection-info)))
- (cadr selection-info))))
-
- ;; increase usage count
+ (cadr selection-info)))
+ (timestamp-info (helm-aif (assq 'timestamp (cdr selection-info))
+ it
+ (setcdr selection-info (cons (cons 'timestamp 0) (cdr selection-info)))
+ (cadr selection-info))))
+ ;; Increase usage count.
(setcdr pattern-info (1+ (cdr pattern-info)))
-
- ;; truncate history if needed
+ ;; Update timestamp.
+ (setcdr timestamp-info (float-time))
+ ;; Truncate history if needed.
(if (> (length (cdr selection-info)) helm-adaptive-history-length)
(setcdr selection-info
(cl-subseq (cdr selection-info) 0 helm-adaptive-history-length))))))))
@@ -172,21 +175,26 @@ This is a filtered candidate transformer you can use with the
;; Loop in the SOURCE entry of `helm-adaptive-history'
;; and assemble a list containing the (CANDIDATE
;; . USAGE-COUNT) pairs.
- (cl-loop for (src-cand . infos) in (cdr source-info)
- for count = 0
+ (cl-loop with cf = 5
+ with cr = 2
+ for (src-cand . infos) in (cdr source-info)
+ for count-freq = 0
+ for count-rec = (helm-aif (assq 'timestamp infos)
+ (* cr (+ (float-time) (cdr it)))
+ 0)
do (cl-loop for (pattern . score) in infos
;; If current pattern is equal to
;; the previously used one then
;; this candidate has priority
- ;; (that's why its count is
+ ;; (that's why its count-freq is
;; boosted by 10000) and it only
;; has to compete with other
;; candidates which were also
;; selected with the same pattern.
if (equal pattern helm-pattern)
- return (setq count (+ 10000 score))
- else do (cl-incf count score))
- and collect (cons src-cand count) into results
+ return (setq count-freq (+ 10000 score))
+ else do (cl-incf count-freq score))
+ and collect (cons src-cand (+ (* count-freq cf) count-rec)) into results
;; Sort the list in descending order, so
;; candidates with highest priority come
;; first.