Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I want to write a function that gets the working value of a buffer local variable. Customarily if a buffer local variables is not defined, it might have a default
value set up.
You can use (with-current-buffer BUFFER VARIABLE). If the variable is buffer-local, that buffer-local value will be returned. If the variable is global, then the global value will be returned. As mentioned in a separate thread recently, the default value of a variable can be obtained with the function default-value.
You don't need a function for that (assuming that you are "in" the buffer - i.e. that the buffer is the current buffer): you just reference the variable. @lawlist tells you how to get the value of the variable if the relevant buffer is not the current buffer (it will work for the current buffer too, but it's computationally more expensive and much less convenient than referencing the variable directly).
The documentation says that the forms in BODY are executed. How can I work with (with-current-buffer BUFFER VARIABLE) for a particular variable? In order to get the value.
"if a buffer local variables is not defined, it might have a default value set up." Why is that a problem - that is the value of the variable in the buffer (and everywhere else it doesn't have a buffer-local value). The question is unclear.
Because I want to get the value of a variable so I can store it. Will be resetting the value temporarily and want to be able to toggle it to its original value.
(with-current-buffer BUFFER VARIABLE). If the variable is buffer-local, that buffer-local value will be returned. If the variable is global, then the global value will be returned. As mentioned in a separate thread recently, the default value of a variable can be obtained with the functiondefault-value.(with-current-buffer BUFFER VARIABLE)for a particular variable? In order to get the value.