15

I want to put some config outside my init.el file into .dir-locals.el, i.e the following:

((nil
  (let ((dirs '(".cask" "core" "packages" "modules" "snippets" "themes")))
   (mapc #'(lambda (path) (add-to-list 'projectile-globally-ignored-directories path)) dirs))))

But each time i'm trying to open any file in my .emacs.d folder, emacs asks me if it's save to apply this code. I've tried to silence it by setting file local vars:

;; -*- enable-local-variables: t; enable-local-eval: t -*-

and it didn't help at all, on the contrary adds another message to trust these local settings. How can i make it trust my .dir-locals.el code?

Drew
  • 75,699
  • 9
  • 109
  • 225
4lex1v
  • 603
  • 3
  • 12

1 Answers1

13

You can customize safe-local-variable-values in your init file. This will require you to also specify which values you consider safe.

(add-to-list 'safe-local-variable-values '(var . value))

This is OK if you know the set of possible values, as your question implies you do.

If you want to make a variable safe for all values that satisfy a predicate, you can do:

(put 'var 'safe-local-variable #'stringp) 
erikstokes
  • 12,686
  • 2
  • 34
  • 56
InHarmsWay
  • 1,309
  • 7
  • 8
  • Thank you for this approach, but as i wrote i want to put this config in `.dir-locals.el` – 4lex1v Dec 11 '15 at 16:42
  • You would still configure the projectile setting in a .dir-locals.el. But you will continue to receive warnings upon loading that file, until you take one of these actions. Have you tried the 2nd? That code, in your init file, replacing 'var with projectile-globally-ignored-directories, should prevent the warnings when the .dir-locals.el is loaded. – InHarmsWay Dec 11 '15 at 17:58
  • Although thinking about it, you may need '#listp rather than '#stringp, since you are setting the bar to a list of strings. – InHarmsWay Dec 11 '15 at 18:01