Is this a good way to return the value of a buffer variable
(if (local-variable-p variable buffer)
(buffer-local-value variable buffer)
(default-value variable))
Is this a good way to return the value of a buffer variable
(if (local-variable-p variable buffer)
(buffer-local-value variable buffer)
(default-value variable))
The simplest way to know whether a variable has a buffer-local binding in buffer is to use C-h v
, the default keybinding for the function describe-variable
.
It will do exactly what are asking for: it will tell you whether the variable has a buffer-local binding, what that local value is, and what the global value is.
buffer-local-value
takes care of returning the default value if the variable has no buffer-local value. I suspect an X-Y problem, what are you actually trying to achieve? – rpluim Jul 05 '23 at 20:42