Search code examples
variablesemacselisp

In Emacs how do I make a local variable safe to be set in a file for all possible values


In Elisp I have introduced for a special custom mode a variable like:

(defvar leo-special-var "")
(make-variable-buffer-local 'leo-special-var)

Now I set this variable in files I with the lines (in the file to edit):

# Local Variables:
# leo-special-var: "-d http://www.google.com.au"
# End:

And I want to consider this variable as "safe for all its values. That's why safe-local-variable-values doesn't help. Instead I tried (in the lisp code):

# setting the symbol property of the variable
(put 'leo-special-var 'safe-local-variable 'booleanp)

but without success. Do I do something wrong when setting the symbol property? Or is there another way?


Solution

  • If you really want to state that it is safe for all values then use this:

    (put 'leo-special-var 'safe-local-variable (lambda (_) t))
    

    The function to test safety here returns non-nil for any value.

    (But I'd think that you probably do not want to state that a variable is safe for any value.)