39

I am using the helm-projectile setup from prelude and it has been a huge improvement to my workflow. The only remaining issue are auto-generated files (e.g. generated by CMake) which show up during helm-grep and similar operations.

Question: is there a way to exclude files in the projects folder tree from Projectile?

33

Looking at projectile it seems to offer four customizations for ignoring files/directories globally. I am listing each of them below, with their documentation

projectile-globally-ignored-files

A list of files globally ignored by projectile.

projectile-globally-ignored-directories

A list of directories globally ignored by projectile.

projectile-globally-ignored-file-suffixes

A list of file suffixes globally ignored by projectile.

projectile-globally-ignored-modes

A list of regular expressions for major modes ignored by projectile.

If a buffer is using a given major mode, projectile will ignore it for functions working with buffers.

Please note that these are global options so for example a directory in projectile-globally-ignored-directories will be ignored irrespective of the project you are working with. To ignore a file/directory for a particular project you can add a .projectile file to the project's root and add the paths to ignore prefixed with - to it like following

-/CMake

See the documentation of projectile-parse-dirconfig-file (or projectile's docs) for more info

Parse project ignore file and return directories to ignore and keep.

The return value will be a cons, the car being the list of directories to keep, and the cdr being the list of files or directories to ignore.

Strings starting with + will be added to the list of directories to keep, and strings starting with - will be added to the list of directories to ignore. For backward compatibility, without a prefix the string will be assumed to be an ignore string.

  • 2
    I'm unable to get projectile-globally-ignored-file-suffixes to work as (I think) it is intended. Should this contain just the suffix (i.e. "o" for object files), a file glob (i.e. "*.o") or something else? Frankly I've tried every combo I can think of and it hasn't worked. – Bklyn Nov 20 '17 at 15:17
  • I am using Scala with ensime, and projectile already defines .ensime_cache as globally ignored. However C-c p h brings up helm-projectile and shows all the .ensime_cache files. Any ideas? – Arne Mar 28 at 12:48
23

Yes, in your .projectile file, on each line specify similar to: each line looks like:

- /path/to/somefile

Each line contains one file path.

See the official documentation on ignoring files

7

Another solution would be to use ag(the_silver_searcher) or rg (ripgrep) to generate project files. Here's how you can do it with rg:

(setq projectile-enable-caching t)

;;; Default rg arguments
  ;; https://github.com/BurntSushi/ripgrep
  (when (executable-find "rg")
    (progn
      (defconst modi/rg-arguments
        `("--line-number"                     ; line numbers
          "--smart-case"
          "--follow"                          ; follow symlinks
          "--mmap")                           ; apply memory map optimization when possible
        "Default rg arguments used in the functions in `projectile' package.")

      (defun modi/advice-projectile-use-rg ()
        "Always use `rg' for getting a list of all files in the project."
        (mapconcat 'identity
                   (append '("\\rg") ; used unaliased version of `rg': \rg
                           modi/rg-arguments
                           '("--null" ; output null separated results,
                             "--files")) ; get file names matching the regex '' (all files)
                   " "))

      (advice-add 'projectile-get-ext-command :override #'modi/advice-projectile-use-rg)))

In your project directory, specify the files you want to ignore in .gitignore and you're good to go :)

Code is from kaushalmodi's emacs config.

2

search that respects ignored dirs/files:

  1. install ack (An alternative to grep. I install via homebrew.)

  2. put --ignore-case in your ~.ackrc file (assuming you want to ignore case)

  3. bind helm-projectile-ack to a key. I do this in my emacs init via:

(use-package helm
  ...
  :bind (...
         ("C-c p s a" . helm-projectile-ack)
        )
  ...
)
  1. create a .projectile file. E.g.,
-.dot
-.jcs
-.svg
-.txt

use

C-c p s a     ;; search that respects .projectile ignore

or

C-c s p g     ;; search everything

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.