bbatsov / helm-projectile

Helm UI for Projectile
329 stars 71 forks source link

ripgrep support #61

Closed nickserv closed 6 years ago

nickserv commented 7 years ago

I love the helm integration with projectile-ag, but I would like to switch to ripgrep (specifically ripgrep.el) for its performance and ignoring features over ag. There's a nice ripgrep-projectile package, but it doesn't have helm integration, so it would be great to have something built into helm-projectile.

jwinder commented 7 years ago

Along with this, helm-grep now has support for ag, pt and rg.

A suggestion might be to remove the dependency on helm-ag, and instead of helm-projectile-ag delegating to helm-do-ag (in helm-ag), it delegates to helm-do-grep-ag (built into helm).

Edit -- I have realized that unfortunately helm-grep does not have a function similar to helm-ag-edit, one of my favorite features of helm-ag. So I withdraw my suggestion for now.

humitos commented 7 years ago

I'm pretty sure that this is not the correct way of implementing it, but it could help if someone want to give this a try in the research. I modify helm.el from https://github.com/emacs-helm/helm and helm-projectile.el from https://github.com/bbatsov/helm-projectile (using the master version in both cases)

diff --git a/helm-grep.el b/helm-grep.el
index b30ba48d..bb7ec7b8 100644
--- a/helm-grep.el
+++ b/helm-grep.el
@@ -484,7 +484,7 @@ It is intended to use as a let-bound variable, DON'T set this globaly.")
                                 default-directory))
          (zgrep (string-match "\\`zgrep" cmd-line))
          ;; Use pipe only with grep, zgrep or git-grep.
-         (process-connection-type (and (not zgrep) (helm-grep-use-ack-p)))
+         (process-connection-type t)
          (tramp-verbose helm-tramp-verbose)
          (start-time (float-time))
          (proc-name (if helm-grep-use-zgrep
diff --git a/helm-projectile.el b/helm-projectile.el
index 8f69867..58f4358 100644
--- a/helm-projectile.el
+++ b/helm-projectile.el
@@ -769,6 +769,7 @@ can be customized using `helm-ag-insert-at-point'."
   :group 'helm-projectile
   :type 'boolean)

+
 (defun helm-projectile-grep-or-ack (&optional dir use-ack-p ack-ignored-pattern ack-executable)
   "Perform helm-grep at project root.
 DIR directory where to search
@@ -787,7 +788,7 @@ If it is nil, or ack/ack-grep not found then use default grep command."
           (cl-union (mapcar 'directory-file-name (projectile-ignored-directories-rel))
                     grep-find-ignored-directories))
          (helm-grep-default-command (if use-ack-p
-                                        (concat ack-executable " -H --no-group --no-color " ack-ignored-pattern " %p %f")
+                                        (concat ack-executable " -H --smart-case --no-heading --color always --line-number %p")
                                       (if (and projectile-use-git-grep (eq (projectile-project-vcs) 'git))
                                           "git --no-pager grep --no-color -n%c -e %p -- %f"
                                         "grep -a -r %e -n%cH -e %p %f .")))
@@ -842,6 +843,16 @@ If it is nil, or ack/ack-grep not found then use default grep command."
   (helm-projectile-toggle -1))

 ;;;###autoload
+(defun helm-projectile-ripgrep (&optional dir)
+  ""
+  (interactive)
+  (let ((project-root (or dir (projectile-project-root) (error "You're not in a project"))))
+    (funcall 'run-with-timer 0.01 nil
+             #'helm-projectile-grep-or-ack project-root t nil "rg")))
+
+
+
+;;;###autoload
 (defun helm-projectile-grep (&optional dir)
   "Helm version of `projectile-grep'.
 DIR is the project root, if not set then current directory is used"

With these modifications I made ripgrep to work in my computer with helm support and presenting the results in an async way :D

We could make this changes cleaner and propose a PR but not right now, it's 3:26 am :)

xiongtx commented 6 years ago

I don't use ripgrep myself, so if someone wants to contribute a PR, it'd be appreciated!

xiongtx commented 6 years ago

Should be fixed by #107.