I would like to define a list of trusted paths.

  • Where dir-locals.el can be loaded without asking me.
  • Without having to be concerned with safe-local-variable-values
    Which isn't very practical if the value contains code which might be edited/modified.

Instead, I would like to have a list of paths, similar to .gitignore, which are "trusted" and won't prompt me to trust expressions.

1 Answer 1


This can be done by advising hack-local-variables-filter.

(defvar my-trusted-paths
(defvar my-trusted-paths-prefix

(defun my-trusted-paths-filter (dir-name)
  (catch 'result
    (dolist (p my-trusted-paths)
      (when (string-equal p dir-name)
        (throw 'result t)))
    (dolist (p my-trusted-paths-prefix)
      (when (string-prefix-p p dir-name)
        (throw 'result t)))))

(advice-add 'hack-local-variables-filter
  (lambda (old-fn &rest args)
    (pcase-let ((`(,_variables ,dir-name) args))
      (if (my-trusted-paths-filter dir-name)
        (cl-letf (((symbol-function 'safe-local-variable-p) (lambda (&rest _) t)))
          (apply old-fn args)
          ;; Always accept paths matching.
        (apply old-fn args)))))

NOTE: I've since moved to a package that is an alternative to dir-locals that allows out-of-source locals called sidecar-locals.

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.