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

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

[elpa] master 4adc074 06/22: Fix the default-directory for `counsel-git-


From: Oleh Krehel
Subject: [elpa] master 4adc074 06/22: Fix the default-directory for `counsel-git-grep'
Date: Wed, 22 Apr 2015 19:51:47 +0000

branch: master
commit 4adc07474f7fb0feb608327483bb47f6724925bd
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Fix the default-directory for `counsel-git-grep'
    
    * counsel.el (counsel--git-grep-dir): New defvar.
    (counsel-git-grep-count): Update.
    (counsel-git-grep-function): Update.
    (counsel-git-grep): Update.
---
 counsel.el |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/counsel.el b/counsel.el
index e00bc59..5a2ac72 100644
--- a/counsel.el
+++ b/counsel.el
@@ -181,11 +181,15 @@
     (when file
       (find-file file))))
 
+(defvar counsel--git-grep-dir nil
+  "Store the base git directory.")
+
 (defun counsel-git-grep-count (str)
   "Quickly count the amount of git grep STR matches."
-  (let ((out (shell-command-to-string
-              (format "git grep -i -c '%s' | sed 's/.*:\\(.*\\)/\\1/g' | awk 
'{s+=$1} END {print s}'"
-                      (ivy--regex str)))))
+  (let* ((default-directory counsel--git-grep-dir)
+         (out (shell-command-to-string
+               (format "git grep -i -c '%s' | sed 's/.*:\\(.*\\)/\\1/g' | awk 
'{s+=$1} END {print s}'"
+                       (ivy--regex str)))))
     (string-to-number out)))
 
 (defvar counsel--git-grep-count nil
@@ -199,14 +203,15 @@
         (setq ivy--full-length counsel--git-grep-count)
         (list ""
               (format "%d chars more" (- 3 (length ivy-text)))))
-    (let ((cmd (format "git --no-pager grep --full-name -n --no-color -i -e 
\"%s\""
-                       (ivy--regex string t)))
-          res)
+    (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)
       (if (<= counsel--git-grep-count 20000)
           (progn
             (setq res (shell-command-to-string cmd))
             (setq ivy--full-length nil))
-        (setq res (shell-command-to-string (concat cmd " | head -n 5000")))
+        (setq res (shell-command-to-string (concat cmd " | head -n 2000")))
         (setq ivy--full-length (counsel-git-grep-count ivy-text)))
       (split-string res "\n" t))))
 
@@ -214,14 +219,14 @@
   "Grep for a string in the current git repository."
   (interactive)
   (unwind-protect
-       (let* ((counsel--git-grep-count (counsel-git-grep-count ""))
+       (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))
-              (git-dir (locate-dominating-file
-                        default-directory ".git"))
               (ivy--persistent-action (lambda (x)
                                         (setq lst (split-string x ":"))
-                                        (find-file (expand-file-name (car lst) 
git-dir))
+                                        (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))



reply via email to

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