From: Lars Ingebrigtsen Date: Fri, 17 Jun 2022 22:17:40 +0000 (+0200) Subject: Extend 'e' in edebug to pretty-print the values X-Git-Tag: emacs-29.0.90~1447^2~1657 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0d103e6f79d374766b64e56fb05e440076f4df5c;p=emacs.git 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. --- diff --git a/doc/lispref/edebug.texi b/doc/lispref/edebug.texi index 0fc5271d5ad..377cd21da86 100644 --- a/doc/lispref/edebug.texi +++ b/doc/lispref/edebug.texi @@ -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 diff --git a/etc/NEWS b/etc/NEWS index b9a22617353..d18af0502d2 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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 +++ diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index 9dc5a1315e5..58cfd47abdf 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -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.