Extend 'e' in edebug to pretty-print the values

* doc/lispref/edebug.texi (Edebug Eval): Document it.

* lisp/emacs-lisp/edebug.el (edebug-eval-expression): Allow
displaying the full value in a different buffer.
This commit is contained in:
Lars Ingebrigtsen 2022-06-18 00:17:40 +02:00
parent c1370d83cb
commit 0d103e6f79
3 changed files with 42 additions and 21 deletions

View file

@ -701,7 +701,11 @@ on this process.
@item e @var{exp} @key{RET}
Evaluate expression @var{exp} in the context outside of Edebug
(@code{edebug-eval-expression}). That is, Edebug tries to minimize
its interference with the evaluation. By default, this command
its interference with the evaluation. The result is shown in the echo
area, or, if this command is given a prefix, pop up a new buffer and
pretty-print the result there.
By default, this command
suppresses the debugger during evaluation, so that an error in the
evaluated expression won't add a new error on top of the existing one.
Set the @code{debug-allow-recursive-debug} user option to a

View file

@ -1019,6 +1019,9 @@ buffer or while edebugging) and 'C-x C-e' (while edebugging) commands
lead to a (further) backtrace. By default, this variable is nil,
which is a change in behaviour from previous Emacs versions.
+++
*** 'e' in edebug can now take a prefix to pretty-print the results.
** Compile
+++

View file

@ -3707,30 +3707,44 @@ Return the result of the last expression."
(defalias 'edebug-format #'format-message)
(defalias 'edebug-message #'message)
(defun edebug-eval-expression (expr)
(defun edebug-eval-expression (expr &optional pp)
"Evaluate an expression in the outside environment.
If interactive, prompt for the expression.
Print result in minibuffer."
(interactive (list (read--expression "Eval: ")))
Print result in minibuffer by default, but if PP is non-nil open
a new window and pretty-print the result there. (Interactively,
this is the prefix key.)"
(interactive (list (read--expression "Edebug eval: ")
current-prefix-arg))
(let* ((errored nil)
(result
(value
(edebug-outside-excursion
(let ((result (if debug-allow-recursive-debug
(edebug-eval expr)
(condition-case err
(edebug-eval expr)
(error
(setq errored
(format "%s: %s"
(get (car err) 'error-message)
(car (cdr err)))))))))
(unless errored
(values--store-value result)
(concat (edebug-safe-prin1-to-string result)
(eval-expression-print-format result)))))))
(if errored
(message "Error: %s" errored)
(princ result))))
(if debug-allow-recursive-debug
(edebug-eval expr)
(condition-case err
(edebug-eval expr)
(error
(setq errored
(format "%s: %s"
(get (car err) 'error-message)
(car (cdr err)))))))))
(result
(unless errored
(values--store-value value)
(concat (edebug-safe-prin1-to-string value)
(eval-expression-print-format value)))))
(cond
(errored
(message "Error: %s" errored))
(pp
(save-selected-window
(pop-to-buffer "*Edebug Results*")
(erase-buffer)
(pp value (current-buffer))
(goto-char (point-min))
(lisp-data-mode)))
(t
(princ result)))))
(defun edebug-eval-last-sexp (&optional no-truncate)
"Evaluate sexp before point in the outside environment.