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.

4
  • 1
    There isn't really a need for that. Use e to eval any expression in the current context.
    – wasamasa
    Commented Nov 16, 2017 at 23:08
  • 1
    Still, is there a way for me to get a REPL? For many reasons I find it more comfortable than the eval minibuffer.
    – Daniel
    Commented Nov 17, 2017 at 0:15
  • FWIW: You'll have "half" of a repl if you open up the *Messages* buffer.
    – ebpa
    Commented Nov 20, 2017 at 5:42
  • 1
    I think what the OP talks about is a really cool feature to have, wondering how hard would it be get it implemented Commented May 28, 2019 at 14:28

3 Answers 3

3
+50

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.

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.)

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.)

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.