emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]