[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7397bec 114/167: Allow user-specified matched candidate so
From: |
Oleh Krehel |
Subject: |
[elpa] master 7397bec 114/167: Allow user-specified matched candidate sorting |
Date: |
Tue, 08 Dec 2015 10:50:23 +0000 |
branch: master
commit 7397beca3aab05bc5a5439a7c8be3b998a5a5df7
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Allow user-specified matched candidate sorting
* ivy.el (ivy-prefix-sort): Remove defcustom.
(ivy--filter): Forward sorting of matched candidates to `ivy--sort'.
(ivy-sort-matches-functions-alist): New defcustom.
(ivy--sort): New defun.
Fixes #269
Fixes #265
---
ivy.el | 41 +++++++++++++++++++++++++++++++----------
1 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/ivy.el b/ivy.el
index fda42a2..0f62ab9 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1663,10 +1663,6 @@ You can toggle this to make `case-fold-search' nil
regardless of input."
;; reset cache so that the candidate list updates
(setq ivy--old-re nil))
-(defcustom ivy-prefix-sort nil
- "When non-nil, put prefix matches ahead of the other matches."
- :type 'boolean)
-
(defun ivy--filter (name candidates)
"Return all items that match NAME in CANDIDATES.
CANDIDATES are assumed to be static."
@@ -1714,12 +1710,37 @@ CANDIDATES are assumed to be static."
res)))))
(ivy--recompute-index name re-str cands)
(setq ivy--old-re (if cands re-str ""))
- (if (and (require 'flx nil 'noerror)
- (eq ivy--regex-function 'ivy--regex-fuzzy))
- (setq cands (ivy--flx-sort name cands))
- (when ivy-prefix-sort
- (setq cands (ivy--prefix-sort name cands))))
- (setq ivy--old-cands cands)))))
+ (setq ivy--old-cands (ivy--sort name cands))))))
+
+(defcustom ivy-sort-matches-functions-alist '((t . nil))
+ "An alist of functions used to sort the matching candidates.
+
+This is different from `ivy-sort-functions-alist', which is used
+to sort the whole collection only once. The functions taken from
+here are instead used on each input change, but they are used
+only on already matching candidates, not on all of them.
+
+The alist KEY is a collection function or t to match previously
+not matched collection functions.
+
+The alist VAL is a sorting function with the signature of
+`ivy--prefix-sort'.")
+
+(defun ivy--sort (name candidates)
+ "Re-sort CANDIDATES according to NAME.
+All CANDIDATES are assumed to match NAME."
+ (let ((key (or (ivy-state-caller ivy-last)
+ (when (functionp (ivy-state-collection ivy-last))
+ (ivy-state-collection ivy-last))))
+ fun)
+ (cond ((and (require 'flx nil 'noerror)
+ (eq ivy--regex-function 'ivy--regex-fuzzy))
+ (ivy--flx-sort name candidates))
+ ((setq fun (cdr (or (assoc key ivy-sort-matches-functions-alist)
+ (assoc t ivy-sort-matches-functions-alist))))
+ (funcall fun name candidates))
+ (t
+ candidates))))
(defun ivy--prefix-sort (name candidates)
"Re-sort CANDIDATES.
- [elpa] master d89abf2 104/167: counsel.el (counsel--find-symbol): Silence byte compiler, (continued)
- [elpa] master d89abf2 104/167: counsel.el (counsel--find-symbol): Silence byte compiler, Oleh Krehel, 2015/12/08
- [elpa] master c4562e0 109/167: swiper.el (swiper-font-lock-ensure): Add occur-mode, Oleh Krehel, 2015/12/08
- [elpa] master 5d90542 112/167: ivy.el (ivy-sort-functions-alist): Update doc, Oleh Krehel, 2015/12/08
- [elpa] master adac116 126/167: Make ivy-completing-read handle history as cons, Oleh Krehel, 2015/12/08
- [elpa] master c580fe9 108/167: ivy.el (ivy-occur): Give full counsel-git-grep cands, Oleh Krehel, 2015/12/08
- [elpa] master bb68b67 122/167: Intermediate fix for :preselect with visual-line-mode, Oleh Krehel, 2015/12/08
- [elpa] master 5751119 124/167: README.md: Add more bindings, Oleh Krehel, 2015/12/08
- [elpa] master e47ec14 128/167: ivy.el (ivy-completing-read): Fix off by one, Oleh Krehel, 2015/12/08
- [elpa] master d5489af 100/167: doc/ivy.org: Start writing a manual, Oleh Krehel, 2015/12/08
- [elpa] master c4c1878 121/167: Fix swiper preselect issue with similar or identical lines, Oleh Krehel, 2015/12/08
- [elpa] master 7397bec 114/167: Allow user-specified matched candidate sorting,
Oleh Krehel <=
- [elpa] master ce557d1 119/167: swiper.el (swiper--candidates): Replace "\t" with " ", Oleh Krehel, 2015/12/08
- [elpa] master 5a99dda 118/167: ivy.el (ivy--truncate-string): New defun, Oleh Krehel, 2015/12/08
- [elpa] master 3101efd 136/167: swiper.el (swiper--action): push-mark only if exited the minibuffer, Oleh Krehel, 2015/12/08
- [elpa] master 63f3498 123/167: Add precise preselect for swiper with visual-line-mode, Oleh Krehel, 2015/12/08
- [elpa] master 74bb138 144/167: Update ivy format functions., Oleh Krehel, 2015/12/08
- [elpa] master 39e6733 129/167: Improve ivy TRAMP support, Oleh Krehel, 2015/12/08
- [elpa] master 63e714c 130/167: Allow access to TRAMP from "// C-j", Oleh Krehel, 2015/12/08
- [elpa] master 85bd44b 125/167: swiper.el: Modify the behavior with org-mode and visual-line-mode, Oleh Krehel, 2015/12/08
- [elpa] master 8fdf210 127/167: Switch to using ivy-exit-with-action, Oleh Krehel, 2015/12/08
- [elpa] master ce6ab7a 135/167: Perform string-match in the original buffer, Oleh Krehel, 2015/12/08