branch: elpa/helm
commit 3f7624aaa4d1e5294d0217b8db106e18d17f07cf
Merge: ab19bdccfc f50e7254f5
Author: Thierry Volpiatto <thie...@posteo.net>
Commit: GitHub <nore...@github.com>

    Merge pull request #2731 from taquangtrung/helm-grep-ag-project
    
    helm-grep: run ag from the current project root
---
 helm-grep.el | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/helm-grep.el b/helm-grep.el
index 4c312465f9..2962f0b294 100644
--- a/helm-grep.el
+++ b/helm-grep.el
@@ -22,6 +22,7 @@
 (require 'helm)
 (require 'helm-help)
 (require 'helm-regexp)
+(require 'project)
 
 ;;; load wgrep proxy if it's available
 (require 'wgrep-helm nil t)
@@ -1848,6 +1849,25 @@ version."
   (require 'helm-files)
   (helm-grep-ag (expand-file-name default-directory) arg))
 
+;;;###autoload
+(defun helm-do-grep-ag-project (arg)
+  "Preconfigured `helm' for grepping with AG from the current project root.
+With prefix arg prompt for type if available with your AG version."
+  (interactive "P")
+  (require 'helm-files)
+  (require 'project)
+  (helm-aif (project-current)
+      (let* ((project-type (car it))
+             (project-root (cond ((equal project-type 'vc)
+                                  (car (last it)))
+                                 ((equal project-type 'projectile)
+                                  (cdr it))
+                                 (t default-directory)))
+             (project-root-abs (expand-file-name project-root))
+             (default-directory project-root-abs))
+        (helm-grep-ag project-root-abs arg))
+    (message "Not in any project!")))
+
 ;;;###autoload
 (defun helm-grep-do-git-grep (arg)
   "Preconfigured `helm' for git-grepping `default-directory'.

Reply via email to