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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 5ae677c 41/63: Simplify counsel-git-grep logic


From: Oleh Krehel
Subject: [elpa] master 5ae677c 41/63: Simplify counsel-git-grep logic
Date: Fri, 21 Aug 2015 12:08:42 +0000

branch: master
commit 5ae677c092d48caf10b6baa3a7ca32d3eea6b55f
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Simplify counsel-git-grep logic
    
    * ivy.el (ivy--exhibit): Remove the condition on (eq ivy--full-length -1).
    
    * counsel.el (counsel-git-grep-function): Simplify.
    (counsel-gg-state): New defvar. Use this instead of
    (setq ivy--full-length -1).
    (counsel--gg-candidates): Set `counsel-gg-state' to -2. There are two
    async processes to wait for until `ivy--exhibit' can be called:
    - get the candidate count
    - get the candidates
    Each of the async processes will increase the number, and call
    `ivy--exhibit' if the number reaches 0.
    (counsel--gg-sentinel): Update.
    (counsel--gg-count): Update.
---
 counsel.el |   31 +++++++++++++------------------
 ivy.el     |   21 ++++++++++-----------
 2 files changed, 23 insertions(+), 29 deletions(-)

diff --git a/counsel.el b/counsel.el
index 6004891..91bb04b 100644
--- a/counsel.el
+++ b/counsel.el
@@ -280,22 +280,14 @@
   "Grep in the current git repository for STRING."
   (if (and (> counsel--git-grep-count 20000)
            (< (length string) 3))
-      (progn
-        (setq ivy--full-length counsel--git-grep-count)
-        (list ""
-              (format "%d chars more" (- 3 (length ivy-text)))))
+      (list ""
+            (format "%d chars more" (- 3 (length ivy-text))))
     (let* ((default-directory counsel--git-grep-dir)
            (cmd (format "git --no-pager grep --full-name -n --no-color -i -e 
%S"
-                        (ivy--regex string t)))
-           res)
+                        (ivy--regex string t))))
       (if (<= counsel--git-grep-count 20000)
-          (progn
-            (setq res (shell-command-to-string cmd))
-            (setq ivy--full-length nil)
-            (split-string res "\n" t))
-        (setq ivy--full-length -1)
-        (counsel--gg-candidates (ivy--regex string))
-        nil))))
+          (split-string (shell-command-to-string cmd) "\n" t)
+        (counsel--gg-candidates (ivy--regex string))))))
 
 (defvar counsel-git-grep-map
   (let ((map (make-sparse-keymap)))
@@ -557,8 +549,12 @@ The libraries are offered from `load-path'."
                          (get-text-property 0 'full-name x)))
               :keymap counsel-describe-map)))
 
+(defvar counsel-gg-state nil
+  "The current state of candidates / count sync.")
+
 (defun counsel--gg-candidates (regex)
   "Return git grep candidates for REGEX."
+  (setq counsel-gg-state -2)
   (counsel--gg-count regex)
   (let* ((default-directory counsel--git-grep-dir)
          (counsel-gg-process " *counsel-gg*")
@@ -583,9 +579,8 @@ The libraries are offered from `load-path'."
         (with-current-buffer (process-buffer process)
           (setq ivy--all-candidates (split-string (buffer-string) "\n" t))
           (setq ivy--old-cands ivy--all-candidates))
-        (unless (eq ivy--full-length -1)
-          (ivy--insert-minibuffer
-           (ivy--format ivy--all-candidates))))
+        (when (= 0 (cl-incf counsel-gg-state))
+          (ivy--exhibit)))
     (if (string= event "exited abnormally with code 1\n")
         (message "Error"))))
 
@@ -614,8 +609,8 @@ When NO-ASYNC is non-nil, do it synchronously."
              (when (string= event "finished\n")
                (with-current-buffer (process-buffer process)
                  (setq ivy--full-length (string-to-number (buffer-string))))
-               (ivy--insert-minibuffer
-                (ivy--format ivy--all-candidates)))))))))
+               (when (= 0 (cl-incf counsel-gg-state))
+                 (ivy--exhibit)))))))))
 
 (defun counsel--M-x-transformer (cmd)
   "Add a binding to CMD if it's bound in the current window.
diff --git a/ivy.el b/ivy.el
index 97113c4..e42504e 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1292,22 +1292,21 @@ Should be run via minibuffer `post-command-hook'."
             ;; dynamic collection should take care of everything
             (funcall (ivy-state-dynamic-collection ivy-last) ivy-text)
             (setq ivy--old-text ivy-text)))
-        (unless (eq ivy--full-length -1)
-          (ivy--insert-minibuffer
-           (ivy--format ivy--all-candidates))))
+        (ivy--insert-minibuffer
+         (ivy--format ivy--all-candidates)))
     (cond (ivy--directory
            (if (string-match "/\\'" ivy-text)
                (if (member ivy-text ivy--all-candidates)
                    (ivy--cd (expand-file-name ivy-text ivy--directory))
                  (when (string-match "//\\'" ivy-text)
-                  (if (and default-directory
-                           (string-match "\\`[[:alpha:]]:/" default-directory))
-                      (ivy--cd (match-string 0 default-directory))
-                    (ivy--cd "/")))
-                (when (string-match "[[:alpha:]]:/" ivy-text)
-                  (let ((drive-root (match-string 0 ivy-text)))
-                    (when (file-exists-p drive-root)
-                      (ivy--cd drive-root)))))
+                   (if (and default-directory
+                            (string-match "\\`[[:alpha:]]:/" 
default-directory))
+                       (ivy--cd (match-string 0 default-directory))
+                     (ivy--cd "/")))
+                 (when (string-match "[[:alpha:]]:/" ivy-text)
+                   (let ((drive-root (match-string 0 ivy-text)))
+                     (when (file-exists-p drive-root)
+                       (ivy--cd drive-root)))))
              (if (string-match "\\`~\\'" ivy-text)
                  (ivy--cd (expand-file-name "~/")))))
           ((eq (ivy-state-collection ivy-last) 'internal-complete-buffer)



reply via email to

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