Following this answer, I put the following lines in a .dir-locals.el file:

  (TeX-engine . default)
  (mode . latex )
  (TeX-master . "main")
   "TODO" "SDP" "MDPC" "GJE" "fpc" "QGJE" "GJI" "QGJI" "Bachmann" "Varshamov"))

However, each time I open a new file, I get a prompt asking to confirm if the values in the ispell-buffer-session-localwords are safe or not. Is there any way to specify that all the possible strings are safe values for this variable? Are there any cons in doing so?

2 Answers 2


C-hig (elisp)File Local Variables says:

You can specify safe values for a variable with a ‘safe-local-variable’ property. The property has to be a function of one argument; any value is safe if the function returns non-‘nil’ given that value. Many commonly-encountered file variables have ‘safe-local-variable’ properties; these include ‘fill-column’, ‘fill-prefix’, and ‘indent-tabs-mode’. For boolean-valued variables that are safe, use ‘booleanp’ as the property value.

In your case you could do this:

(defun list-of-strings-p (list)
  "Non-nil if LIST is a list of strings."
  (not (catch 'non-string
         (dolist (x list nil)
           (unless (stringp x)
             (throw 'non-string t))))))

(put 'ispell-buffer-session-localwords 'safe-local-variable

To mark as safe for the variables you know they are safe,

(add-hook 'latex-mode-hook (lambda () (setq enable-local-variables :safe)))

But in your case, it looks like you have to use :all instead of :safe.

Emacs manual: Safety of File Variables

  • But this will mark ALL the variables as safe, isn't it?
    – tigerjack
    Commented May 22, 2023 at 12:48
  • Yes, but it is limited to variables defined for latex-mode by the add-hook
    – roomworoof
    Commented May 22, 2023 at 13:11
  • enable-local-variables is not automatically buffer-local. You are setting the global value for every buffer as soon as any latex file is visited.
    – phils
    Commented May 22, 2023 at 13:14
  • @phils I actually tried it and it only worked in latex-mode and the prompt still appears at the other modes. Why does it seem to be working as expected?
    – roomworoof
    Commented May 22, 2023 at 13:20
  • Ah, yes I was wrong about it setting the global value -- it looks like this variable is let-bound when the major mode hook runs, so your hook function only modifies that temporary value, and the original value is restored soon afterwards.
    – phils
    Commented May 22, 2023 at 22:37

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.