Projectile: Search all file names with ag -g

Created on 8 Oct 2015  路  12Comments  路  Source: bbatsov/projectile

I substituted the custom file search engine in ctrl-p with ag -g to search for file names and there were a few advantages that I miss. I had incredibly fast searching and I could share all of my ag ignored files with ctrl-p. Could this feature be used in projectile as well?

Feature Request Help Wanted Stale

Most helpful comment

@lethjakman

I use ag for all projectile caching. Even on RHEL 6, projectile-enable-caching set to nil is not snappy because my projects have about 7k files _after_ filtering out all the unwanted files. So I have set that to t and have to below to use ag for all caching.

;; Use `ag' all the time if available
(defun modi/advice-projectile-use-ag ()
  "Always use `ag' for getting a list of all files in the project."
  (mapconcat 'identity
             (append '("\\ag") ; used unaliased version of `ag': \ag
                     modi/ag-arguments
                     '("-0" ; output null separated results
                       "-g ''")) ; get file names matching the regex '' (all files)
             " "))
(when (executable-find "ag")
  (advice-add 'projectile-get-ext-command :override
              #'modi/advice-projectile-use-ag))

;; Make the file list creation faster by NOT calling `projectile-get-sub-projects-files'
(defun modi/advice-projectile-no-sub-project-files ()
  "Directly call `projectile-get-ext-command'. No need to try to get a
list of sub-project files if the vcs is git."
  (projectile-files-via-ext-command (projectile-get-ext-command)))
(advice-add 'projectile-get-repo-files :override
            #'modi/advice-projectile-no-sub-project-files)

where the value of modi/ag-arguments is '("--nogroup" "--skip-vcs-ignores" "--numbers" "--smart-case" "--follow").
Source

All 12 comments

It's there any benefit over projectile-find-file?

Maybe if of could help produce the file index cache, that would be useful for non-git projects.

No idea what this does, seems to me the vc commands we normally use are pretty fast (and they handle properly the ignore configs for the respective vcs). More info would be useful.

I guess it might be useful when the vc is not supported (e.g. perforce )

But we're already using GNU Find for those, which is pretty fast itself. Maybe the non-vc backend should be configurable...

_cough_ Windows

Well, altering the existing fallback code would be pretty easy, so we can definitely do this.

The reason I suggested this is because there is a significant performance increase over gnu find (to the point that you don't even need to cache) and it natively ignores vc ignored files. I got the idea from this article back when I used Vim:
https://robots.thoughtbot.com/faster-grepping-in-vim

I doubt that the performance is worth it on windows over caching, maybe faster than find. Ag is very slow on my work machine.

Perhaps that's a system specific thing? I'm on osx with a fairly fast ssd, that could be why it's faster for me.

@lethjakman

I use ag for all projectile caching. Even on RHEL 6, projectile-enable-caching set to nil is not snappy because my projects have about 7k files _after_ filtering out all the unwanted files. So I have set that to t and have to below to use ag for all caching.

;; Use `ag' all the time if available
(defun modi/advice-projectile-use-ag ()
  "Always use `ag' for getting a list of all files in the project."
  (mapconcat 'identity
             (append '("\\ag") ; used unaliased version of `ag': \ag
                     modi/ag-arguments
                     '("-0" ; output null separated results
                       "-g ''")) ; get file names matching the regex '' (all files)
             " "))
(when (executable-find "ag")
  (advice-add 'projectile-get-ext-command :override
              #'modi/advice-projectile-use-ag))

;; Make the file list creation faster by NOT calling `projectile-get-sub-projects-files'
(defun modi/advice-projectile-no-sub-project-files ()
  "Directly call `projectile-get-ext-command'. No need to try to get a
list of sub-project files if the vcs is git."
  (projectile-files-via-ext-command (projectile-get-ext-command)))
(advice-add 'projectile-get-repo-files :override
            #'modi/advice-projectile-no-sub-project-files)

where the value of modi/ag-arguments is '("--nogroup" "--skip-vcs-ignores" "--numbers" "--smart-case" "--follow").
Source

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.

Was this page helpful?
0 / 5 - 0 ratings