summaryrefslogtreecommitdiff
path: root/helm-adaptive.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thierry.volpiatto@gmail.com>2016-06-11 08:04:05 +0200
committerThierry Volpiatto <thierry.volpiatto@gmail.com>2016-06-11 08:04:05 +0200
commit51d91f9850381fe62adfd45da8f0c67c65e4ee4c (patch)
tree6bc97c2b17ca6dc73d343d33cc19b3bf11676344 /helm-adaptive.el
parent57c984c3b231c186d5a587fffcf2d56187ecb4d2 (diff)
Rewrite helm-adaptive-sort.
* helm-adaptive.el (helm-adaptive-sort): Use cl-loop.
Diffstat (limited to 'helm-adaptive.el')
-rw-r--r--helm-adaptive.el66
1 files changed, 30 insertions, 36 deletions
diff --git a/helm-adaptive.el b/helm-adaptive.el
index 3a378d47..fc338636 100644
--- a/helm-adaptive.el
+++ b/helm-adaptive.el
@@ -175,42 +175,36 @@ This is a filtered candidate transformer you can use with the
(source-info (assoc source-name helm-adaptive-history)))
(if source-info
(let ((usage
- ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
- ;; pairs
- (mapcar (lambda (candidate-info)
- (let ((count 0))
- (cl-dolist (pattern-info (cdr candidate-info))
- (if (not (equal (car pattern-info)
- helm-pattern))
- (cl-incf count (cdr pattern-info))
-
- ;; if current pattern is equal to the previously
- ;; used one then this candidate has priority
- ;; (that's why its count is boosted by 10000) and
- ;; it only has to compete with other candidates
- ;; which were also selected with the same pattern
- (setq count (+ 10000 (cdr pattern-info)))
- (cl-return)))
- (cons (car candidate-info) count)))
- (cdr source-info))))
- (if (and usage (consp usage))
- ;; sort the list in descending order, so candidates with highest
- ;; priorty come first
- (progn
- (setq usage (sort usage (lambda (first second)
- (> (cdr first) (cdr second)))))
-
- ;; put those candidates first which have the highest usage count
- (cl-loop for (info . _freq) in usage
- for mlinfo = (and (assq 'multiline source)
- (replace-regexp-in-string "\n\\'" "" info))
- for member = (cl-member (or mlinfo info) candidates
- :test 'helm-adaptive-compare)
- when member collect (car member) into sorted
- and do
- (setq candidates (cl-remove (or mlinfo info) candidates
- :test 'helm-adaptive-compare))
- finally return (append sorted candidates)))
+ ;; Assemble a list containing the (CANDIDATE . USAGE-COUNT) pairs.
+ (cl-loop with count = 0
+ for (sn . infos) in (cdr source-info)
+ do (cl-loop for (pattern . score) in infos
+ if (not (equal pattern helm-pattern))
+ do (cl-incf count score)
+ else return
+ ;; If current pattern is equal to the previously
+ ;; used one then this candidate has priority
+ ;; (that's why its count is boosted by 10000) and
+ ;; it only has to compete with other candidates
+ ;; which were also selected with the same pattern.
+ (setq count (+ 10000 score)))
+ and collect (cons sn count) into results
+ ;; Sort the list in descending order, so candidates with highest
+ ;; priority come first.
+ finally return (sort results (lambda (first second)
+ (> (cdr first) (cdr second)))))))
+ (if (consp usage)
+ ;; Put those candidates first which have the highest usage count.
+ (cl-loop for (info . _freq) in usage
+ for mlinfo = (and (assq 'multiline source)
+ (replace-regexp-in-string "\n\\'" "" info))
+ for member = (cl-member (or mlinfo info) candidates
+ :test 'helm-adaptive-compare)
+ when member collect (car member) into sorted
+ and do
+ (setq candidates (cl-remove (or mlinfo info) candidates
+ :test 'helm-adaptive-compare))
+ finally return (append sorted candidates))
(message "Your `%s' is maybe corrupted or too old, \
you should reinitialize it with `helm-reset-adaptive-history'"
helm-adaptive-history-file)