0

For example, I debug a function, I'm stepping in it, I want to check a local variable's value and C-h v says: variable is not bound

I can eval the variable, by pressing e and tpying its name, only describe-variable can't pick it up.

Why is that? I seem to remember it worked fine in the past when I used debugging.

It's Emacs 27.

2
  • If you mean "local" as in "buffer-local" then remember that C-h v shows you the binding for the buffer in which you are typing C-h v (so if that's the debugger's buffer, you wouldn't expect it to have the same value).
    – phils
    Mar 30, 2022 at 22:47
  • I took local to mean let-bound in the function.
    – NickD
    Mar 31, 2022 at 1:17

2 Answers 2

1

AFAIK, that has always been the case: variables that are let-bound in a function are not known to the C-h v (aka describe-variable) mechanism. I don't think edebug does anything to change this.

Try the following experiment:

(defun foo ()
  (let ((bar "baz"))
    (setq bar "hunoz")
    (princ bar)
    (describe-variable 'bar)))

When you call the function with (foo) in the *scratch* buffer, you get the most recent value printed out (hunoz), but describe-variable does not know about it, so the return value of foo (which is what the describe-variable call returns) says that bar is void as a variable:

hunoz#("bar is void as a variable.

Not documented as a variable.

  Probably introduced at or before Emacs version 16.

" 108 110 (button (t) category help-news-button help-args ("/usr/local/share/emacs/29.0.50/etc/NEWS.1-17" 43356)))

OTOH, if you try

(defun foo ()
  (let ((bar "baz"))
    (setq bar "hunoz")
    (princ bar)
    (describe-variable 'bar)
    (describe-variable 'major-mode)
    ))

the same value is printed out, but the return value now is what the last call of describe-variable returns which is the description of major-mode:

hunoz#("major-mode is a variable defined in ‘C source code’.

Its value is ‘lisp-interaction-mode’
Original value was ‘fundamental-mode’
Local in buffer *scratch*; global value is fundamental-mode

Symbol for current buffer’s major mode.
The default value (normally ‘fundamental-mode’) affects new buffers.
A value of nil means to use the current buffer’s major mode, provided
it is not marked as \"special\".

  Automatically becomes buffer-local when set.
  You can customize this variable.

" 37 50 (help-args (major-mode C-source) category help-variable-def-button button (t)) 458 467 (help-args (major-mode) category help-customize-variable-button button (t)))

That shows that edebug has nothing to do with it.

EDIT: It seems that the behavior the OP describes was lost when lexical binding became the default for let-bound variables. As @phils says in a comment:

describe-variable is looking at the symbol (there's a boundp call), so a lexically-bound value is invisible to it. So I think this sounds normal. Under dynamic binding if I call (debug) or (recursive-edit) then I can see the let-bound value via its symbol.

EDIT: in order to evaluate expresssions in Edebug, use e <EXP> (you can use minibuffer history with M-n/M-p to avoid typing an expresssion more than once) or C-x C-e for the expression before point - see Edebug eval.

6
  • Check out this older questions, it says "When using edebug one can get a local variable by command describe-variable (C-h v)" , so clearly the asker used C-h v for that and I too seem to remember doing it. emacs.stackexchange.com/questions/35732/…
    – Tom
    Mar 30, 2022 at 20:50
  • It may be that the lexical scoping changes changed what describe--variable can do. But we'll have to wait for somebody who is au courant with those changes to tell us. Maybe @Drew or @phils will be able to enlighten us.
    – NickD
    Mar 30, 2022 at 21:16
  • 1
    Yes, describe-variable is looking at the symbol (there's a boundp call), so a lexically-bound value is invisible to it. So I think this sounds normal. Under dynamic binding if I call (debug) or (recursive-edit) then I can see the let-bound value via its symbol.
    – phils
    Mar 30, 2022 at 22:45
  • If this is the case then what is the recommended way of inspecting the value of a variable under the cursor in edebug which does not involve typing its name manually? It's such a basic operation for debugging, where one often inspects variables, there must be some way to do it.
    – Tom
    Mar 31, 2022 at 3:32
  • 1
    I think your options are e (or R) and v (or C-u v). Not specifically what you're asking, but the latter doesn't involve much typing, and you can use history as normal with the former. (I never do a ton with the standard debugger, so that's all I know. Be sure to check the manual.)
    – phils
    Mar 31, 2022 at 19:52
0

locals and let bound can be examined using "e" for edebug-eval-expression

1
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    – Drew
    Jan 24 at 17:01

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.