summaryrefslogtreecommitdiff
path: root/helm.el
diff options
context:
space:
mode:
authorAdam Porter <adam@alphapapa.net>2017-03-29 07:34:29 -0500
committerAdam Porter <adam@alphapapa.net>2017-03-29 07:44:58 -0500
commit35b2ddf2792259bee73b8190cbfa1cabf67499a1 (patch)
treed4acb3f864e3f1c8c8b14b115eb91ce1130b16e1 /helm.el
parent3b2a975bc93bbd08fd56893417649209356cfac8 (diff)
Preserve order when fuzzy matching in helm-recentf
Currently, when helm-recentf-fuzzy-match is enabled, matches with equal fuzzy score (e.g. same filename, different path length) are sorted by path length, which partially defeats the purpose of recentf as they are no longer in order of recency. With this commit, tied fuzzy matches in helm-recentf will preserve their original ordering by recency, making helm-recentf more useful. * helm.el: (helm-fuzzy-matching-default-sort-fn-1): Do it. (helm-fuzzy-matching-sort-fn-preserve-ties-order): Add function. * helm-files.el (helm-recentf-fuzzy-match): Do it.
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 7b2496d0..e0846a20 100644
--- a/helm.el
+++ b/helm.el
@@ -3131,15 +3131,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)))
@@ -3175,13 +3176,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))