[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 323efda 38/57: counsel-git-grep now works with ivy-resume
From: |
Oleh Krehel |
Subject: |
[elpa] master 323efda 38/57: counsel-git-grep now works with ivy-resume |
Date: |
Tue, 19 May 2015 14:21:35 +0000 |
branch: master
commit 323efda5fda651d5fd4f9924370a3f30f5a3d332
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel-git-grep now works with ivy-resume
* ivy.el (ivy-state): New field DYNAMIC-COLLECTION.
(ivy-resume): Update.
(ivy-read): New argument DYNAMIC-COLLECTION. When this is non-nil,
ignore collection and matchers etc, and just obtain the filtered
candidates by calling DYNAMIC-COLLECTION each time the input changes.
Fixes #100
---
counsel.el | 38 +++++++++++++++++++-------------------
ivy.el | 30 +++++++++++++++++-------------
2 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/counsel.el b/counsel.el
index 54f3a56..447371d 100644
--- a/counsel.el
+++ b/counsel.el
@@ -214,25 +214,25 @@
(defun counsel-git-grep (&optional initial-input)
"Grep for a string in the current git repository."
(interactive)
- (unwind-protect
- (let* ((counsel--git-grep-dir (locate-dominating-file
- default-directory ".git"))
- (counsel--git-grep-count (counsel-git-grep-count ""))
- (ivy--dynamic-function (when (> counsel--git-grep-count 20000)
- '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 ":")))
- (find-file (expand-file-name (car lst)
counsel--git-grep-dir))
- (goto-char (point-min))
- (forward-line (1- (string-to-number (cadr lst))))
- (setq swiper--window (selected-window))
- (swiper--cleanup)
- (swiper--add-overlays (ivy--regex ivy-text))))))
- (swiper--cleanup)))
+ (setq counsel--git-grep-dir
+ (locate-dominating-file default-directory ".git"))
+ (setq counsel--git-grep-count (counsel-git-grep-count ""))
+ (ivy-read "pattern: " 'counsel-git-grep-function
+ :initial-input initial-input
+ :matcher #'counsel-git-grep-matcher
+ :dynamic-collection (when (> counsel--git-grep-count 20000)
+ 'counsel-git-grep-function)
+ :action
+ (lambda ()
+ (let ((lst (split-string ivy--current ":")))
+ (find-file (expand-file-name (car lst) counsel--git-grep-dir))
+ (goto-char (point-min))
+ (forward-line (1- (string-to-number (cadr lst))))
+ (unless (eq ivy-exit 'done)
+ (setq swiper--window (selected-window))
+ (swiper--cleanup)
+ (swiper--add-overlays (ivy--regex ivy-text)))))
+ :unwind #'swiper--cleanup))
(defun counsel-git-grep-matcher (x)
(when (string-match "^[^:]+:[^:]+:" x)
diff --git a/ivy.el b/ivy.el
index 17a5546..96e20dc 100644
--- a/ivy.el
+++ b/ivy.el
@@ -138,7 +138,9 @@ Only \"./\" and \"../\" apply here. They appear in reverse
order."
action
unwind
re-builder
- matcher)
+ matcher
+ ;; When this is non-nil, call it for each input change to get new candidates
+ dynamic-collection)
(defvar ivy-last nil
"The last parameters passed to `ivy-read'.")
@@ -350,7 +352,8 @@ candidate."
:action (ivy-state-action ivy-last)
:unwind (ivy-state-unwind ivy-last)
:re-builder (ivy-state-re-builder ivy-last)
- :matcher (ivy-state-matcher ivy-last)))
+ :matcher (ivy-state-matcher ivy-last)
+ :dynamic-collection (ivy-state-dynamic-collection ivy-last)))
(defun ivy-beginning-of-buffer ()
"Select the first completion candidate."
@@ -566,7 +569,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 matcher)
+ action unwind re-builder matcher dynamic-collection)
"Read a string in the minibuffer, with completion.
PROMPT is a string to prompt with; normally it ends in a colon
@@ -593,7 +596,10 @@ UNWIND is a lambda to call before exiting.
RE-BUILDER is a lambda that transforms text into a regex.
-MATCHER can completely override matching."
+MATCHER can completely override matching.
+
+DYNAMIC-COLLECTION is a function to call to update the list of
+candidates with each input."
(setq ivy-last
(make-ivy-state
:prompt prompt
@@ -610,7 +616,8 @@ MATCHER can completely override matching."
:window (selected-window)
:unwind unwind
:re-builder re-builder
- :matcher matcher))
+ :matcher matcher
+ :dynamic-collection dynamic-collection))
(setq ivy--directory nil)
(setq ivy--regex-function
(or re-builder
@@ -889,11 +896,8 @@ Everything after \"!\" should not match."
(goto-char (minibuffer-prompt-end))
(delete-region (line-end-position) (point-max))))
-(defvar ivy--dynamic-function nil
- "When this is non-nil, call it for each input change to get new candidates.")
-
(defvar ivy--full-length nil
- "When `ivy--dynamic-function' is non-nil, this can be the total amount of
candidates.")
+ "When :dynamic-collection is non-nil, this can be the total amount of
candidates.")
(defvar ivy--old-text ""
"Store old `ivy-text' for dynamic completion.")
@@ -921,7 +925,7 @@ Everything after \"!\" should not match."
(if ivy--directory
(abbreviate-file-name ivy--directory)
""))
- (or (and ivy--dynamic-function
+ (or (and (ivy-state-dynamic-collection ivy-last)
ivy--full-length)
ivy--length))))
(save-excursion
@@ -953,14 +957,14 @@ Everything after \"!\" should not match."
"Insert Ivy completions display.
Should be run via minibuffer `post-command-hook'."
(setq ivy-text (ivy--input))
- (if ivy--dynamic-function
+ (if (ivy-state-dynamic-collection ivy-last)
;; while-no-input would cause annoying
;; "Waiting for process to die...done" message interruptions
(let ((inhibit-message t))
(while-no-input
(unless (equal ivy--old-text ivy-text)
- (let ((store ivy--dynamic-function)
- (ivy--dynamic-function nil))
+ (cl-letf ((store (ivy-state-dynamic-collection ivy-last))
+ ((ivy-state-dynamic-collection ivy-last) nil))
(setq ivy--all-candidates (funcall store ivy-text))))
(ivy--insert-minibuffer (ivy--format ivy--all-candidates))))
(cond (ivy--directory
- [elpa] master 5f2cf0c 28/57: Update test, (continued)
- [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, 2015/05/19
- [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 <=
- [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
- [elpa] master 28cb795 53/57: Don't try to call permanent action if there's none, Oleh Krehel, 2015/05/19
- [elpa] master 75a059c 44/57: Allow to recenter with "C-l" during counsel-git-grep, Oleh Krehel, 2015/05/19
- [elpa] master 4f75381 55/57: When building a regex, consider ^ only at start, Oleh Krehel, 2015/05/19
- [elpa] master 5afceff 52/57: ivy.el (ivy-forward-char): Add and bind to "C-f", Oleh Krehel, 2015/05/19
- [elpa] master 155f2a6 57/57: Merge commit 'bc335af4d94d80d3605b66ed51a15d2476ad2179' from swiper, Oleh Krehel, 2015/05/19
- [elpa] master bc335af 56/57: Fixup compilation warnings, Oleh Krehel, 2015/05/19