15

The variable safe-local-variable-values can store name/value pairs that are safe as file-local or directory-local. However sometimes I want to say any value is valid for a given variable. The manual page I linked to says that any integer value is considered safe for fill-column. Is there a way to do this for my own variables?

3
  • Try using identity as test.
    – wasamasa
    Apr 12, 2016 at 6:23
  • 1
    @wasamasa I think (lambda (_) t) is better, for the nil case.
    – user227
    Apr 12, 2016 at 6:57
  • (lambda (_) t) is also predefined as always
    – scry
    Apr 24 at 6:32

1 Answer 1

22

Set the safe-local-variable property to a function that validates the value. For example, fill-column has a safe-local-variable property set to integerp. Use (lambda (x) t) as the validation function if any value is valid.

(defvar my-variable-with-any-safe-value …)
(put 'my-variable-with-any-safe-value 'safe-local-variable
     (lambda (x) t))

or

(defcustom my-variable-with-any-safe-value …
  :safe (lambda (x) t))

Having any valid value is pretty rare. It's far more common to restrict to a specific type, e.g. integerp, stringp, etc.

Your Answer

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

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