branch: master
commit 3256d68f17c9cf6247185419323c7b9ecfc48873
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Change the :matcher interface
* ivy.el (ivy--filter): The matcher is now a function that takes a
regexp and candidates and returns the filtered candidates.
* counsel.el (counsel-git-grep-matcher): Cache matched candidates. This
is very important for "C-n" / "C-p", especially near the threshold
where a switch to :dynamic-collection is made.
---
counsel.el | 38 +++++++++++++++++++++++---------------
ivy.el | 3 +--
2 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/counsel.el b/counsel.el
index c0581e5..400684c 100644
--- a/counsel.el
+++ b/counsel.el
@@ -251,21 +251,29 @@
:action #'counsel-git-grep-action
:unwind #'swiper--cleanup)))
-(defun counsel-git-grep-matcher (x)
- (ignore-errors
- (when (string-match "^[^:]+:[^:]+:" x)
- (setq x (substring x (match-end 0)))
- (if (stringp ivy--old-re)
- (string-match ivy--old-re x)
- (let ((res t))
- (dolist (re ivy--old-re)
- (setq res
- (and res
- (ignore-errors
- (if (cdr re)
- (string-match (car re) x)
- (not (string-match (car re) x)))))))
- res)))))
+(defun counsel-git-grep-matcher (regexp candidates)
+ (or (and (equal regexp ivy--old-re)
+ ivy--old-cands)
+ (prog1
+ (setq ivy--old-cands
+ (cl-remove-if-not
+ (lambda (x)
+ (ignore-errors
+ (when (string-match "^[^:]+:[^:]+:" x)
+ (setq x (substring x (match-end 0)))
+ (if (stringp regexp)
+ (string-match regexp x)
+ (let ((res t))
+ (dolist (re regexp)
+ (setq res
+ (and res
+ (ignore-errors
+ (if (cdr re)
+ (string-match (car re) x)
+ (not (string-match (car re)
x)))))))
+ res)))))
+ candidates))
+ (setq ivy--old-re regexp))))
(defun counsel-locate-function (str &rest _u)
(if (< (length str) 3)
diff --git a/ivy.el b/ivy.el
index e8299fa..9fc4624 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1080,8 +1080,7 @@ CANDIDATES are assumed to be static."
(matcher (ivy-state-matcher ivy-last))
(cands (cond
(matcher
- (let ((ivy--old-re re))
- (cl-remove-if-not matcher candidates)))
+ (funcall matcher re candidates))
((and (equal re ivy--old-re)
ivy--old-cands)
ivy--old-cands)