11

I'm trying to ignore some file patterns while performing helm-projectile-grep and some with helm-projectile-find-file. I've found that it could be achieved using .dir-locals.el here.
Following this chunk of documentation I've made my .dir-locals.el looks like:

((nil
  (grep-find-ignored-files . '("*.log"))
  (projectile-globally-ignored-files . '("*.log"))))

When helm-projectile-grep is called it yields an error in helm-projectile:

Error running timer `helm-projectile-grep-or-ack': (wrong-type-argument stringp quote)

Since both emacs manual and projectile docs are sketchy about .dir-locals.el and it's usage I have few questions?

  • How .dir-locals.el works? Does it merge global and dir-local value of an variable? If I have a variable a which is '("a" "b") and set it in dir-local to '("c"), what is its value that Emacs use when I perform an operation in certain scope of .dir-locals.el?
  • What kind of structure is expected in .dir-locals.el for grep-find-ignored-files and projectile-globally-ignored-files?

On Projectile itself:

  • Why Projectile helm-projectile-grep and helm-projectile-find-file don't ignore file patterns which are already ignored in .gitignore? Is it turned off somewhere in my config?

Solution

According to accepted answer, if you want to ignore e.g all the .md files from Projectile operations in your project using .dir-locals.el you should do something like this:

((nil
  (eval . (set (make-local-variable 'projectile-globally-ignored-files)
               (append projectile-globally-ignored-files
                       (f-entries (projectile-project-root)
                                  (lambda (f) (string-match "\\.md$" f)) t))))))
yujaiyu
  • 896
  • 8
  • 22
  • I can't reproduce your error with the same setup. You need to toggle-debug-on-error to see where it's coming from. 2. projectile does ignore files in .gitignore, at least I am certain about helm-projectile-find-files. It's impossible to say why you see a different behavior without dissecting your init.el.
  • – Yuri Steinschreiber Jul 28 '16 at 20:14
  • @YuriSteinschreiber Sorry, I've forgot to mention that one should call helm-projectile-grep after visiting some file in project to see exactly the same error as I've seen. Question is updated now. – yujaiyu Jul 28 '16 at 21:47
  • @YuriSteinschreiber You didn't even got wrong-type-argument stringp quote on visiting file when you use .dir-locals.el from above? Debugger says that projectile try to expand-file-name(quote "/my/project/root/"). It would be very strange to me if your Projectile doesn't try to do the same. – yujaiyu Jul 28 '16 at 21:57
  • Now after visiting a file I get the same behavior, and it is coming from the fact that the value is interpreted literally, so it's a list with a quote symbol as the first element. Which is not a string, and that's the error. Looks weird and doesn't match either Projectile docs or my understanding. I have deleted my partial answer while I am trying to understand the reason (and maybe correct myself if I was wrong somewhere.) – Yuri Steinschreiber Jul 28 '16 at 22:19
  • Yes, that's what confusing me - it looks like variable values are interpreted literally. Thank you for your effort anyway. – yujaiyu Jul 28 '16 at 22:30
  • Ok, figured it out. Took a bit more effort than I intended to expend, but couldn't stop already :) The values are left unevaluated, the emacs manual is a bit scattered about it, so needed to dig the sources. If you leave the quote out it works, see my answer. – Yuri Steinschreiber Jul 28 '16 at 22:47
  • Re: your problem with .gitignore. Funny thing - I've just stumbled over the same problem, and it turned out that .gitignore is itself ignored by Projectile unless the project is indeed under git. Check if your project has a git repository, if it doesn't - init it and get the first commit. Then see if Projectile takes it into account. (I will update my answer soon.) – Yuri Steinschreiber Jul 29 '16 at 19:43