0

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.

6
  • 1
    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. Commented Dec 2, 2022 at 0:12
  • 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). Commented Dec 2, 2022 at 0:19
  • 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. Commented Dec 2, 2022 at 1:48
  • "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. Commented Dec 2, 2022 at 3:00
  • 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. Commented Dec 2, 2022 at 3:21

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.