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

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

[elpa] master 2bd9118 44/63: counsel.el (counsel-ag): New command


From: Oleh Krehel
Subject: [elpa] master 2bd9118 44/63: counsel.el (counsel-ag): New command
Date: Fri, 21 Aug 2015 12:08:43 +0000

branch: master
commit 2bd91185243b5aae569be655a17fa0ffadd2aaa1
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-ag): New command
    
    * counsel.el (counsel-ag-function): New defun.
    (counsel-git-grep): Update prompt.
    
    Going from sync to async now is as simple as:
    
    - add :dynamic-collection t
    - replace `shell-command-to-string' with `counsel--async-command'
---
 counsel.el |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/counsel.el b/counsel.el
index 161d789..cb87e8a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -332,7 +332,7 @@ INITIAL-INPUT can be given as the initial minibuffer input."
   (if (null counsel--git-grep-dir)
       (error "Not in a git repository")
     (setq counsel--git-grep-count (counsel--gg-count "" t))
-    (ivy-read "pattern: " 'counsel-git-grep-function
+    (ivy-read "git grep: " 'counsel-git-grep-function
               :initial-input initial-input
               :matcher #'counsel-git-grep-matcher
               :dynamic-collection (> counsel--git-grep-count 20000)
@@ -826,6 +826,31 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and
               :history 'org-tags-history
               :action 'counsel-org-tag-action)))
 
+(defun counsel-ag-function (string &optional _pred &rest _unused)
+  "Grep in the current directory for STRING."
+  (if (< (length string) 3)
+      (counsel-more-chars 3)
+    (let ((regex (replace-regexp-in-string
+                  "\\\\)" ")"
+                  (replace-regexp-in-string
+                   "\\\\(" "("
+                   (ivy--regex string)))))
+      (counsel--async-command
+       (format "ag --noheading --nocolor %S" regex))
+      nil)))
+
+(defun counsel-ag (&optional initial-input)
+  "Grep for a string in the current directory using ag.
+INITIAL-INPUT can be given as the initial minibuffer input."
+  (interactive)
+  (setq counsel--git-grep-dir default-directory)
+  (ivy-read "ag: " 'counsel-ag-function
+            :initial-input initial-input
+            :dynamic-collection t
+            :history 'counsel-git-grep-history
+            :action #'counsel-git-grep-action
+            :unwind #'swiper--cleanup))
+
 (provide 'counsel)
 
 ;;; counsel.el ends here



reply via email to

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