Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 622
halloleo Avatar asked Nov 06 '13 07:11

halloleo


People also ask

How do you assign a local variable?

local - Assign a local variable in a function qsh uses dynamic scoping, so that if you make the variable alpha local to function foo, which then calls function bar, references to the variable alpha made inside bar will refer to the variable declared inside foo, not to the global variable named alpha.

How do you declare local variables in Appians?

Local variables are a specific type of variable that are only available within the context of a particular expression and can only be accessed within the function that defines them. Local variables are useful when you only need that data within a particular expression.


2 Answers

You want to use

(put 'leo-special-var 'safe-local-variable #'stringp)

to say that it is safe as long as it's a string.

like image 115
Stefan Avatar answered Oct 14 '22 21:10

Stefan


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.)

like image 26
Drew Avatar answered Oct 14 '22 21:10

Drew