Q:

Read find-grep exclusion patterns from a .findignore file

I am aware that you can customise the "find" command executed when using "find-grep" with "setq grep-find-command" and define which file-patterns to ignore in the search. I would like to take this further and be able to read the patterns to ignore from a file.
Each framework or tool might generate different files that I would like to be ignored in search. For example, SASS generates ".sass-cache" folder, the Symfony framework stores the "logs" and the "cache" in respectively named folders, while Haskell stack creates a ".stack-work" folder.
Instead of customising the "find-grep" command to exclude all patterns from different frameworks/tools, I would prefer a system where you can add a ".findignore" file in the root folder of the project and "find-grep" should be picking up the exclusions from there.
A couple of questions:
1) Is there such a solution already out there?
2) If not, advice on how to go about the following two requirements would help me get started:

How can I detect the .findignore file upwards up to the root folder of the project (just like .gitignore).
How to load each line and sequence it as an argument to "find-grep"

I haven't done advanced emacs customisations so any hints would be appreciated.

A:

Preferred solution
I have settled with using "ag" (The Silver Searcher) for search and "helm-ag" or "ag.el" for Emacs integration. "ag" allows you to specify a ".agignore" file where you can add file/directory patterns that will be ignored for the search - exactly what I was looking for. For example:
# .agignore
folder
file.txt
*.js

It also takes ".gitignore" and ".hgignore" into account

Install "ag" (https://github.com/ggreer/the_silver_searcher)
Use "helm-ag" mode if you're using "helm" (https://github.com/syohex/emacs-helm-ag)
Use "ag" mode if you're not using "helm" (https://github.com/Wilfred/ag.el)

Less favourable solution
Achieving the same with "rgrep" or "grep-find" is more difficult. You can set the "grep-find-ignore-directories" or "grep-find-ignore-files" (for rgrep) as directory-local variables in a dir-locals.el file, like so:
# Reference: http://stackoverflow.com/a/16247272/1505303
((nil . ((eval . (progn
                   (require 'grep)
                   (add-to-list 
                    (make-local-variable 'grep-find-ignored-directories)
                    "folder-to-ignore"))))))

or (thanks to @phils answer for the direction):
((nil . ((grep-find-ignored-directories . ("folder-to-ignore"))
         (grep-find-ignored-files . ("file-to-ignore")))))

Both of these solutions though have the drawback that the directory-local variables are set from the folder defined and below. This means that if I make a search from the root folder of the project, or any parent folder, the undesired files will be included in the search.
Additionally, they are a bit more cumbersome and difficult to set up, especially for emacs beginners that do not understand elisp well enough.
It may be possible to write a function that looks for ".findignore" or ".grepignore" files in in the folder the search is being executed and below, convert the patterns from each file as relative to the folder, and then pass them as arguments to "find" or "grep". That would certainly be much slower than "ag" though, so it may not be worth developing.

