The general format for .dir-locals.el described here:
To evaluate the code, you must use the special pseudo-variable name eval , as described in:
eg:.
((nil . ((indent-tabs-mode . t) (eval . (eval-after-load "grep" '(add-to-list 'grep-find-ignored-directories "blur"))) (fill-column . 80))) (c-mode . ((c-file-style . "BSD") (subdirs . nil))))
However, grep-find-ignored-directories not an automatic buffer local variable, and we don’t explicitly set it as a local directory variable here (the “local variable” is set here eval ), so when grep-find-ignored-directories set this way, that it is installed globally, which, of course, does not mean that you intended 1 .
You can try something like this:
((nil . ((eval . (eval-after-load "grep" '(add-to-list (make-local-variable 'grep-find-ignored-directories) "blur"))))))
but in fact it’s still not the case, as soon as you visited the file under this directory, that eval-after-load (which is a global parameter) will be launched as soon as grep loads, no matter what buffer you could at that time it would be easy to add your own “blur” value locally in some unwanted buffer from which you called grep, and also could not add it to any of the buffers you previously visited in which you wanted it.
The simplest solution is probably to force grep before setting the variable:
((nil . ((eval . (progn (require 'grep) (add-to-list (make-local-variable 'grep-find-ignored-directories) "blur"))))))
This ensures that all the files in the directory get the local value (and the files will not be in another place).
Now this approach to the general problem, but taking a look at this specific case and Ch v grep-find-ignored-directories , this variable provides some functionality that can simplify the solution and does not require grep to load unnecessarily.
Your .dir-locals.el file can set a local variable like this:
((nil . ((my-ignore-blur-p . t))))
And in your .emacs you can do the following:
(defun my-ignore-blur-p (dir) "Return non-nil when the `my-ignore-blur-p' local variable is set." (local-variable-if-set-p 'my-ignore-blur-p)) (eval-after-load "grep" '(add-to-list 'grep-find-ignored-directories (cons 'my-ignore-blur-p "blur")))
Then, when you execute rgrep from any buffer in which this local variable is set, the user-defined function specified in the global variable grep-find-ignored-directories will return a value not nil , which will result in a “blur” for inclusion in the list of ignored directories.
(nb I used the same name for both the function and the variable, because I can - elisp has separate namespaces for variables and functions, but this is optional. For clarity, I mean the function in eval-after-load and a variable in the function code and the .dir-locals.el file).
Or you could just base the behavior of the my-ignore-blur-p function on the dir argument (which is a normal directory) and generally ignore local variables. This would make the decision to include or exclude "blurring" from a list that is completely independent of the buffer from which you initiated the rgrep command, which may be even more desirable.
1 If adding “blur” to grep-find-ignored-directories globally is what you wanted, then don’t use .dir-locals.el at all — just add your eval-after-load call to your .emacs file .