summaryrefslogtreecommitdiff
path: root/helm.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thierry.volpiatto@gmail.com>2017-03-30 06:59:25 +0200
committerGitHub <noreply@github.com>2017-03-30 06:59:25 +0200
commit7a1193909cf6e93b63b0a1c28e205d5ff38ed88b (patch)
tree1d6f78d96694acbd817678acbb61ff7e49240975 /helm.el
parentd8cebf80279dd94159230d31e09d30c687420323 (diff)
parent35b2ddf2792259bee73b8190cbfa1cabf67499a1 (diff)
Merge pull request #1733 from alphapapa/recentf-fuzzy-preserve-order-2
Preserve order when fuzzy matching in helm-recentf
Diffstat (limited to 'helm.el')
-rw-r--r--helm.el22
1 files changed, 16 insertions, 6 deletions
diff --git a/helm.el b/helm.el
index 3c48c7cf..9a14913f 100644
--- a/helm.el
+++ b/helm.el
@@ -3134,15 +3134,16 @@ CANDIDATE. Contiguous matches get a coefficient of 2."
pat-lookup str-lookup :test 'equal))
2)))))
-(defun helm-fuzzy-matching-default-sort-fn-1 (candidates &optional use-real basename)
+(defun helm-fuzzy-matching-default-sort-fn-1 (candidates &optional use-real basename preserve-tie-order)
"The transformer for sorting candidates in fuzzy matching.
It sorts on the display part by default.
Sorts CANDIDATES by their scores as calculated by
-`helm-score-candidate-for-pattern'. Ties in scores are sorted by
-length of the candidates. Set USE-REAL to non-`nil' to sort on the
-real part. If BASENAME is non-nil assume we are completing filenames
-and sort on basename of candidates."
+`helm-score-candidate-for-pattern'. Set USE-REAL to non-`nil' to
+sort on the real part. If BASENAME is non-nil assume we are
+completing filenames and sort on basename of candidates. If
+PRESERVE-TIE-ORDER is nil, ties in scores are sorted by length of
+the candidates."
(if (string= helm-pattern "")
candidates
(let ((table-scr (make-hash-table :test 'equal)))
@@ -3178,13 +3179,22 @@ and sort on basename of candidates."
(scr1 (car data1))
(scr2 (car data2)))
(cond ((= scr1 scr2)
- (< len1 len2))
+ (unless preserve-tie-order
+ (< len1 len2)))
((> scr1 scr2)))))))))
(defun helm-fuzzy-matching-default-sort-fn (candidates _source &optional use-real)
"Default `filtered-candidate-transformer' to sort candidates in fuzzy matching."
(helm-fuzzy-matching-default-sort-fn-1 candidates use-real))
+(defun helm-fuzzy-matching-sort-fn-preserve-ties-order (candidates _source &optional use-real)
+ "`filtered-candidate-transformer' to sort candidates in fuzzy matching, preserving order of ties.
+The default function, `helm-fuzzy-matching-default-sort-fn',
+sorts ties by length, shortest first. This function may be more
+useful when the order of the candidates is meaningful, e.g. with
+`recentf-list'."
+ (helm-fuzzy-matching-default-sort-fn-1 candidates use-real t))
+
(defun helm--maybe-get-migemo-pattern (pattern)
(or (and helm-migemo-mode
(assoc-default pattern helm-mm--previous-migemo-info))