22

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?

2 Answers 2

9

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
  • 4
    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/… 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.
    – Stefan
    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.
    – npostavs
    Sep 6, 2018 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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