24

In many of my projects I use .dir-locals.el files to setup project specific variables such as compile commands. Upon opening a file within a directory containing such a file, emacs complains about "risky local variables", specifically:

The local variables list in $DIR$/ contains variables that are risky (**) Do you want to apply it? You can type y -- to apply the local variables list. n -- to ignore the local variables list. ** LaTeX-command : "lualatex -shell-escape" 

I don't want to turn this feature off but I would like to be asked only once (during an emacs session) for a specific .dir-locals.el file.

I am using some plugins which want to parse the whole sourcetree and it is quite annoying to hit y hundreds of times just to parse everything.

So, the actual question:

Can emacs' local-variable loading mechanism be configure / modified such that it allows to allow / deny loading of a specific local variables list for the entirety of an emacs session?

3 Answers 3

10

Emacs should offer (and normally does offer) the option to accept and remember the choice for later sessions. I suggest you M-x report-emacs-bug about this missing choice in your case.

In the mean time, you can add the following to your ~/.emacs:

(add-to-list 'safe-local-variable-values  '(LaTeX-command . "lualatex -shell-escape")) 
2
  • 5
    No option to remember isn't a bug, it's intentional for risky variables. If the variable is not in the safe list then Emacs will report that it may be unsafe and prompt with y/n options plus ! to remember. If the variable name matches a certain regex then it is deemed risky and you're only given the y/n options. The regex for determining whether something is risky is in files.el at github.com/emacs-mirror/emacs/blob/… Commented Jan 5, 2016 at 17:59
  • Maybe it was done intentionally, but I think it was mistaken and the OP seems to agree, so I think it deserves a bug report. Commented Oct 18, 2016 at 2:51
6

You can disable this "don't remember risky variables" feature by putting the following in your ~/.emacs:

;; allow remembering risky variables (defun risky-local-variable-p (sym &optional _ignored) nil) 

Then it'll only re-confirm when you edit one.

1
  • 5
    You can also do (advice-add 'risky-local-variable-p :override #'ignore), which has the advantage of being undoable via advice-remove. Commented Sep 6, 2018 at 23:57
1

I often use ./.dir-locals.el in development checkouts of various projects to refer to development tools installed in the checkout, for example to set flycheck-*-*-executable variables to point to ./.tox/*/bin/*, ./node_modules/.bin/*, etc.. In those cases I think it makes more sense to add those checkout directories to the safe-local-variable-directories variable, available since v30.0.50 I think.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.