[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 2cedcf5 37/57: Introduce :matcher for counsel-git-grep
From: |
Oleh Krehel |
Subject: |
[elpa] master 2cedcf5 37/57: Introduce :matcher for counsel-git-grep |
Date: |
Tue, 19 May 2015 14:21:35 +0000 |
branch: master
commit 2cedcf59cf1063d92488a26aa80ef50069f6fe11
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Introduce :matcher for counsel-git-grep
* ivy.el (ivy-state): Add MATCHER field.
(ivy-resume): Update.
(ivy-read): Add MATCHER argument. To make things faster, MATCHER can
reuse `ivy--old-re', but it's not required. MATCHER is a function that
takes a candidate and returns non-nil if it matches.
* counsel.el (counsel-git-grep): Use :matcher.
(counsel-git-grep-matcher): New defun. Skip the file name and line
number, then match as usual.
Fixes #99
---
counsel.el | 16 ++++++++++++
ivy.el | 80 +++++++++++++++++++++++++++++++++--------------------------
2 files changed, 61 insertions(+), 35 deletions(-)
diff --git a/counsel.el b/counsel.el
index ce64c3a..54f3a56 100644
--- a/counsel.el
+++ b/counsel.el
@@ -222,6 +222,7 @@
'counsel-git-grep-function)))
(ivy-read "pattern: " 'counsel-git-grep-function
:initial-input initial-input
+ :matcher #'counsel-git-grep-matcher
:action
(lambda ()
(let ((lst (split-string ivy--current ":")))
@@ -233,6 +234,21 @@
(swiper--add-overlays (ivy--regex ivy-text))))))
(swiper--cleanup)))
+(defun counsel-git-grep-matcher (x)
+ (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-locate-function (str &rest _u)
(if (< (length str) 3)
(list ""
diff --git a/ivy.el b/ivy.el
index 4d0647b..17a5546 100644
--- a/ivy.el
+++ b/ivy.el
@@ -137,7 +137,8 @@ Only \"./\" and \"../\" apply here. They appear in reverse
order."
window
action
unwind
- re-builder)
+ re-builder
+ matcher)
(defvar ivy-last nil
"The last parameters passed to `ivy-read'.")
@@ -348,7 +349,8 @@ candidate."
:sort (ivy-state-sort ivy-last)
:action (ivy-state-action ivy-last)
:unwind (ivy-state-unwind ivy-last)
- :re-builder (ivy-state-re-builder ivy-last)))
+ :re-builder (ivy-state-re-builder ivy-last)
+ :matcher (ivy-state-matcher ivy-last)))
(defun ivy-beginning-of-buffer ()
"Select the first completion candidate."
@@ -564,7 +566,7 @@ Directories come first."
(cl-defun ivy-read (prompt collection
&key predicate require-match initial-input
history preselect keymap update-fn sort
- action unwind re-builder)
+ action unwind re-builder matcher)
"Read a string in the minibuffer, with completion.
PROMPT is a string to prompt with; normally it ends in a colon
@@ -589,7 +591,9 @@ ACTION is a lambda to call after a result was selected.
UNWIND is a lambda to call before exiting.
-RE-BUILDER is a lambda that transforms text into a regex."
+RE-BUILDER is a lambda that transforms text into a regex.
+
+MATCHER can completely override matching."
(setq ivy-last
(make-ivy-state
:prompt prompt
@@ -605,7 +609,8 @@ RE-BUILDER is a lambda that transforms text into a regex."
:action action
:window (selected-window)
:unwind unwind
- :re-builder re-builder))
+ :re-builder re-builder
+ :matcher matcher))
(setq ivy--directory nil)
(setq ivy--regex-function
(or re-builder
@@ -1015,36 +1020,41 @@ Should be run via minibuffer `post-command-hook'."
"Return all items that match NAME in CANDIDATES.
CANDIDATES are assumed to be static."
(let* ((re (funcall ivy--regex-function name))
- (cands (cond ((and (equal re ivy--old-re)
- ivy--old-cands)
- ivy--old-cands)
- ((and ivy--old-re
- (stringp re)
- (stringp ivy--old-re)
- (not (string-match "\\\\" ivy--old-re))
- (not (equal ivy--old-re ""))
- (memq (cl-search
- (if (string-match "\\\\)$" ivy--old-re)
- (substring ivy--old-re 0 -2)
- ivy--old-re)
- re) '(0 2)))
- (ignore-errors
- (cl-remove-if-not
- (lambda (x) (string-match re x))
- ivy--old-cands)))
- (t
- (let ((re-list (if (stringp re) (list (cons re t)) re))
- (res candidates))
- (dolist (re re-list)
- (setq res
- (ignore-errors
- (funcall
- (if (cdr re)
- #'cl-remove-if-not
- #'cl-remove-if)
- `(lambda (x) (string-match ,(car re) x))
- res))))
- res))))
+ (matcher (ivy-state-matcher ivy-last))
+ (cands (cond
+ (matcher
+ (let ((ivy--old-re re))
+ (cl-remove-if-not matcher candidates)))
+ ((and (equal re ivy--old-re)
+ ivy--old-cands)
+ ivy--old-cands)
+ ((and ivy--old-re
+ (stringp re)
+ (stringp ivy--old-re)
+ (not (string-match "\\\\" ivy--old-re))
+ (not (equal ivy--old-re ""))
+ (memq (cl-search
+ (if (string-match "\\\\)$" ivy--old-re)
+ (substring ivy--old-re 0 -2)
+ ivy--old-re)
+ re) '(0 2)))
+ (ignore-errors
+ (cl-remove-if-not
+ (lambda (x) (string-match re x))
+ ivy--old-cands)))
+ (t
+ (let ((re-list (if (stringp re) (list (cons re t)) re))
+ (res candidates))
+ (dolist (re re-list)
+ (setq res
+ (ignore-errors
+ (funcall
+ (if (cdr re)
+ #'cl-remove-if-not
+ #'cl-remove-if)
+ `(lambda (x) (string-match ,(car re) x))
+ res))))
+ res))))
(tail (nthcdr ivy--index ivy--old-cands))
idx)
(when (and tail ivy--old-cands)
- [elpa] master b63c358 35/57: Properly update virtual buffers for "^ " interaction, (continued)
- [elpa] master b63c358 35/57: Properly update virtual buffers for "^ " interaction, Oleh Krehel, 2015/05/19
- [elpa] master d8f79fa 43/57: ivy.el (ivy-partial-or-done): Update doc, Oleh Krehel, 2015/05/19
- [elpa] master ce0efb3 29/57: Allow to customize the minibuffer formatter, Oleh Krehel, 2015/05/19
- [elpa] master 9a2083a 27/57: Swiper should use the :re-builder argument, Oleh Krehel, 2015/05/19
- [elpa] master d8c2ef3 45/57: ivy.el (ivy-partial-or-done): More predictability, Oleh Krehel, 2015/05/19
- [elpa] master e05e3b7 39/57: ivy.el (ivy-read): Keep the last ivy--index for :dynamic-collection, Oleh Krehel, 2015/05/19
- [elpa] master 1cdb6ed 32/57: ivy.el (ivy-partial-or-done): Fixup, Oleh Krehel, 2015/05/19
- [elpa] master 5f2cf0c 28/57: Update test, Oleh Krehel, 2015/05/19
- [elpa] master 6405cb3 42/57: ivy.el (ivy-partial-or-done): Always forward to `ivy-alt-done', Oleh Krehel, 2015/05/19
- [elpa] master 10f9954 50/57: counsel.el (counsel-git-grep): Warn if not in a repository, Oleh Krehel, 2015/05/19
- [elpa] master 2cedcf5 37/57: Introduce :matcher for counsel-git-grep,
Oleh Krehel <=
- [elpa] master 93faef3 41/57: ivy.el (ivy-delete-char): Add and bind to "C-d", Oleh Krehel, 2015/05/19
- [elpa] master 8630048 47/57: Fixed ivy--preselect-index on windows where the drives folders ends with a backslash (C:\, D:\), Oleh Krehel, 2015/05/19
- [elpa] master 1c0703e 36/57: Forward to minibuffer-complete for filenames only if "^/", Oleh Krehel, 2015/05/19
- [elpa] master 70c8c8a 40/57: ivy.el (ivy-switch-buffer): Preselect other-buffer, Oleh Krehel, 2015/05/19
- [elpa] master 9da8e53 54/57: counsel.el (counsel-info-lookup-symbol): Turn on sorting, Oleh Krehel, 2015/05/19
- [elpa] master e0b6c0c 46/57: Update the way spaces are quoted using ivy, Oleh Krehel, 2015/05/19
- [elpa] master 323efda 38/57: counsel-git-grep now works with ivy-resume, Oleh Krehel, 2015/05/19
- [elpa] master 88f4508 49/57: ivy.el (ivy-kill-word): Add and bind to "M-d", Oleh Krehel, 2015/05/19
- [elpa] master de5833e 51/57: Don't error on incomplete bad regexp in counsel-git-grep, Oleh Krehel, 2015/05/19
- [elpa] master 89b9e9a 48/57: README.md: Add sample init, Oleh Krehel, 2015/05/19