diff options
author | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2019-11-23 11:02:50 +0100 |
---|---|---|
committer | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2019-11-23 11:06:29 +0100 |
commit | 1261d5f58f8aefecba2b460b342865b15626a3c5 (patch) | |
tree | 4c117b8feb39bd50754bc5d0d076c0ab7e8a882c /helm-utils.el | |
parent | 216348504308ddfb177b8e2dfb3e0194493b9ce4 (diff) |
Add flex scoring for helm-fuzzy style
* helm-mode.el (helm-fuzzy-completion-all-completions): Bind pattern.
(helm-fuzzy-add-score-as-prop): Add score props to candidates.
(helm-completion--fuzzy-all-completions): Use it.
(helm-fuzzy-completion--adjust-metadata): Add the sort fn.
* helm-utils.el (helm-generic-sort-fn): Sort with score props if some.
Diffstat (limited to 'helm-utils.el')
-rw-r--r-- | helm-utils.el | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/helm-utils.el b/helm-utils.el index 71cffcba..def6f81a 100644 --- a/helm-utils.el +++ b/helm-utils.el @@ -646,14 +646,18 @@ that is sorting is done against real value of candidate." ((string-match r2 str) 2) ((string-match r3 str) 1) (t 0))))) - (sc1 (funcall score str1 reg1 reg2 reg3 split)) - (sc2 (funcall score str2 reg1 reg2 reg3 split))) - (cond ((or (zerop (string-width qpattern)) - (and (zerop sc1) (zerop sc2))) + (sc1 (get-text-property 0 'completion-score str1)) + (sc2 (get-text-property 0 'completion-score str2)) + (sc3 (unless sc1 (funcall score str1 reg1 reg2 reg3 split))) + (sc4 (unless sc2 (funcall score str2 reg1 reg2 reg3 split)))) + (cond ((and sc1 sc2) + (> sc1 sc2)) + ((or (zerop (string-width qpattern)) + (and (zerop sc3) (zerop sc4))) (string-lessp str1 str2)) - ((= sc1 sc2) + ((= sc3 sc4) (< (length str1) (length str2))) - (t (> sc1 sc2))))) + (t (> sc3 sc4))))) (cl-defun helm-file-human-size (size &optional (kbsize helm-default-kbsize)) "Return a string showing SIZE of a file in human readable form. |