6

I toggled edebug-defun on a function I'm studying. Once the debugger kicks in, how can I fire a REPL with access to the symbols being debugged?

I know it's possible to evaluate commands with e in edebug-mode, but that's on the minibuffer and not as flexible as a proper REPL.

Daniel
  • 3,563
  • 16
  • 41

3 Answers3

3

The REPL interaction mode you are looking for is probably met by ielm (Inferior Emacs Lisp mode).

Here's the start of a solution:

Open ielm-mode with M-x ielm.

Advise ielm-eval-input to wrap the expressions with edebug-eval-expression:

(defun my/ielm-edebug-eval-input (orig-func input-string &rest args)
  "Wrapper function for evaluating expressions in an edebug context."
  (apply orig-func (format "(edebug-eval-expression (quote %s))" input-string) args))

(advice-add 'ielm-eval-input :around #'my/ielm-edebug-eval-input)

†: I'm not sure the best way to guard this particular advice because it blows up with Symbol’s value as variable is void: edebug-outside-windows when edebug is not active. Wrapping with condition-case might be useful, but could cause expressions to be evaluated twice.

ebpa
  • 7,319
  • 26
  • 53
0

Partially it is already there in GNU Emacs 26.2 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-04-12.

If you save a file test.el with the following contents, instrument f for edebug, step into f, and call ilem you can access the local variables x, y, and i in the ielm repl.

(defun f (x)
  (let ((y (+ x 1)))
    (cl-loop for i from 0 below 100 do
         (setq x (+ x y i)))))

(f 1)

But:

  1. It does not work with lexical-binding set to t.
  2. It does not work in the scratch buffer.

(I know that this does not qualify as a full answer but maybe it is interesting to know.)

Tobias
  • 32,569
  • 1
  • 34
  • 75
0

As an answer I cite here the page M-: (info "(elisp)Eval List") of

emacs-version: GNU Emacs 26.2 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-04-12 (the feature is actually rather old)

You can use the “evaluation list buffer”, called ‘edebug’, to evaluate expressions interactively. You can also set up the “evaluation list” of expressions to be evaluated automatically each time Edebug updates the display.

‘E’ Switch to the evaluation list buffer ‘edebug’ (‘edebug-visit-eval-list’).

... There follows much more info on the corresponding info manual page.

Especially the evaluation lists should be interesting for you:

The expressions you enter interactively (and their results) are lost when you continue execution; but you can set up an evaluation list consisting of expressions to be evaluated each time execution stops.

To do this, write one or more evaluation list groups in the evaluation list buffer. An evaluation list group consists of one or more Lisp expressions. Groups are separated by comment lines.

The command C-c C-u (edebug-update-eval-list) rebuilds the evaluation list, scanning the buffer and using the first expression of each group. (The idea is that the second expression of the group is the value previously computed and displayed.)

Tobias
  • 32,569
  • 1
  • 34
  • 75