[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)
- [elpa] master e91a4eb 31/63: ivy.el (ivy-dispatching-done): Display the candidate, (continued)
- [elpa] master e91a4eb 31/63: ivy.el (ivy-dispatching-done): Display the candidate, Oleh Krehel, 2015/08/21
- [elpa] master 3464362 33/63: Add actions for counsel-describe-variable, Oleh Krehel, 2015/08/21
- [elpa] master 31d664a 32/63: ivy.el (ivy-dispatching-done): Add a trailing newline, Oleh Krehel, 2015/08/21
- [elpa] master 107ebff 34/63: Add actions for counsel-describe-function, Oleh Krehel, 2015/08/21
- [elpa] master 2fbcfb9 29/63: ivy.el (ivy--preselect-index): Add matcher to arglist, Oleh Krehel, 2015/08/21
- [elpa] master cb0cf02 35/63: ivy.el (ivy-call): Remove with-selected-window, Oleh Krehel, 2015/08/21
- [elpa] master 08bd5b4 25/63: counsel.el (counsel-variable-list): Add, Oleh Krehel, 2015/08/21
- [elpa] master ae77d93 36/63: counsel.el (counsel-org-tag): Replace org-set-tags, Oleh Krehel, 2015/08/21
- [elpa] master 1e483c5 37/63: Fixup counsel-org-tag, Oleh Krehel, 2015/08/21
- [elpa] master a9ff1f1 38/63: counsel.el (counsel-org-change-tags): Improve removing tags, Oleh Krehel, 2015/08/21
- [elpa] master 5ae677c 41/63: Simplify counsel-git-grep logic,
Oleh Krehel <=
- [elpa] master c1b9f5a 39/63: Allow "M-o j" to switch to virtual buffers in other window, Oleh Krehel, 2015/08/21
- [elpa] master f71a562 40/63: Fix "DEL" generating a "Quit" sometimes for counsel-git-grep, Oleh Krehel, 2015/08/21
- [elpa] master 36e8fe3 46/63: counsel.el (counsel-org-tag): No need to be at heading, Oleh Krehel, 2015/08/21
- [elpa] master acf4485 42/63: ivy.el (ivy--exhibit): Check if in post-command-hook, Oleh Krehel, 2015/08/21
- [elpa] master 8a06271 43/63: Update :dynamic-collection to be a boolean, Oleh Krehel, 2015/08/21
- [elpa] master 2bd9118 44/63: counsel.el (counsel-ag): New command, Oleh Krehel, 2015/08/21
- [elpa] master 8152577 45/63: counsel.el (counsel-recoll): New command, Oleh Krehel, 2015/08/21
- [elpa] master 6ab519f 48/63: counsel.el (counsel-org-tag): Delete dups, Oleh Krehel, 2015/08/21
- [elpa] master e7d778b 47/63: counsel.el (counsel-recoll): Simplify, Oleh Krehel, 2015/08/21
- [elpa] master 5b61577 49/63: Use recoll -t instead of recollq, Oleh Krehel, 2015/08/21