diff options
author | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2017-02-23 09:19:59 +0100 |
---|---|---|
committer | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2017-02-23 09:50:37 +0100 |
commit | 56628b7a553e86d652225245ba3f53fdd5a16f6a (patch) | |
tree | 7325d3bfa67ab93a33bf067060cc0fd48f0ecf62 /helm-adaptive.el | |
parent | 4f667a09761afc0e903e2b87d0c6628c7036892d (diff) |
Allow customizing sort in adaptive.
* helm-adaptive.el (helm-adaptive-sort-by-frequent-recent-usage): New.
(helm-adaptive-freq-coefficient): New.
(helm-adaptive-recent-coefficient): New.
(helm-adaptive-sort): Do it.
Diffstat (limited to 'helm-adaptive.el')
-rw-r--r-- | helm-adaptive.el | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/helm-adaptive.el b/helm-adaptive.el index e0b69a77..27f30a01 100644 --- a/helm-adaptive.el +++ b/helm-adaptive.el @@ -39,6 +39,21 @@ :type 'number :group 'helm-adapt) +(defcustom helm-adaptive-sort-by-frequent-recent-usage t + "Try to sort on an average of frequent and recent usage when non-nil. + +When nil sort on frequency usage only. + +Only frequency: +When candidate have low frequency, you have to hit on it many times to +make it going up on top. + +Frequency+recent: +Even with a low frequency, candidate go up on top. If a candidate +have a high frequency but it is not used since some time, it goes +down slowly, but as soon you reuse it it go up on top quickly." + :group 'helm-adapt + :type 'boolean) ;; Internal (defvar helm-adaptive-done nil @@ -49,6 +64,9 @@ selection.") "Contains the stored history information. Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)") +(defconst helm-adaptive-freq-coefficient 5) +(defconst helm-adaptive-recent-coefficient 2) + (defun helm-adaptive-done-reset () (setq helm-adaptive-done nil)) @@ -175,13 +193,16 @@ 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 with cf = 5 - with cr = 2 + (cl-loop with cf = (if helm-adaptive-sort-by-frequent-recent-usage + helm-adaptive-freq-coefficient 1) + with cr = helm-adaptive-recent-coefficient 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) + for count-rec = + (helm-aif (and helm-adaptive-sort-by-frequent-recent-usage + (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 @@ -194,7 +215,8 @@ This is a filtered candidate transformer you can use with the if (equal pattern helm-pattern) 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 + 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. |