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))
Dilna
  • 1
  • 3
  • 11
  • 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 05 '23 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 05 '23 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 05 '23 at 23:04

1 Answers1

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.

Trevoke
  • 2,440
  • 22
  • 34