0

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))
3
  • 2
    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 5, 2023 at 20:42
  • I want to know whether the default value is being used or whether the buffer-local-value was set. And report what the values are.
    – Dilna
    Jul 5, 2023 at 21:47
  • What's one to do to know whether a variable has a buffer-local binding in buffer ? And report what is what.
    – Dilna
    Jul 5, 2023 at 23:04

1 Answer 1

0

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.