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?

elemakil
  • 2,517
  • 1
  • 18
  • 26

2 Answers2

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"))
Stefan
  • 26,154
  • 3
  • 46
  • 84
  • 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 https://github.com/emacs-mirror/emacs/blob/61e83e902b388490b609677a76f3d49740439f24/lisp/files.el#L3484-L3487 – Dan Midwood Jan 05 '16 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 '16 at 02:51
4

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.

  • 4
    You can also do `(advice-add 'risky-local-variable-p :override #'ignore)`, which has the advantage of being undoable via `advice-remove`. – npostavs Sep 06 '18 at 23:57