From 606275e91ec57cccabeb4ac2feb93753f734cb00 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 18 Jun 2022 13:26:14 +0200 Subject: [PATCH] Allow pretty-printing results from `C-x C-e' in edebug * 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. --- doc/lispref/edebug.texi | 3 ++- etc/NEWS | 6 ++++++ lisp/emacs-lisp/edebug.el | 28 ++++++++++++++++------------ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/doc/lispref/edebug.texi b/doc/lispref/edebug.texi index 377cd21da86..622578bcf1c 100644 --- a/doc/lispref/edebug.texi +++ b/doc/lispref/edebug.texi @@ -719,7 +719,8 @@ Evaluate expression @var{exp} in the context of Edebug itself Evaluate the expression before point, in the context outside of Edebug (@code{edebug-eval-last-sexp}). With the prefix argument of zero (@kbd{C-u 0 C-x C-e}), don't shorten long items (like strings and -lists). +lists). Any other prefix will result in the value being +pretty-printed in a separate buffer. @end table @cindex lexical binding (Edebug) diff --git a/etc/NEWS b/etc/NEWS index f195a721f4d..a9c8957dfbb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1030,6 +1030,12 @@ which is a change in behaviour from previous Emacs versions. When invoked with a prefix argument, as in 'C-u e', this command will pop up a new buffer and show the full pretty-printed value there. ++++ +*** 'C-x C-e' now interprets a non-zero prefix arg to pretty-print the results. +When invoked with a non-zero prefix argument, as in 'C-u C-x C-e', +this command will pop up a new buffer and show the full pretty-printed +value there. + ** Compile +++ diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index 58cfd47abdf..ad66cfc2b81 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -3746,21 +3746,25 @@ this is the prefix key.)" (t (princ result))))) -(defun edebug-eval-last-sexp (&optional no-truncate) +(defun edebug-eval-last-sexp (&optional display-type) "Evaluate sexp before point in the outside environment. -Print value in minibuffer. - -If NO-TRUNCATE is non-nil (or interactively with a prefix -argument of zero), show the full length of the expression, not -limited by `edebug-print-length' or `edebug-print-level'." +If DISPLAY-TYPE is `pretty-print' (interactively, a non-zero +prefix argument), pretty-print the value in a separate buffer. +Otherwise, print the value in minibuffer. If DISPLAY-TYPE is any +other non-nil value (or interactively with a prefix argument of +zero), show the full length of the expression, not limited by +`edebug-print-length' or `edebug-print-level'." (interactive (list (and current-prefix-arg - (zerop (prefix-numeric-value current-prefix-arg))))) - (if no-truncate - (let ((edebug-print-length nil) - (edebug-print-level nil)) - (edebug-eval-expression (edebug-last-sexp))) - (edebug-eval-expression (edebug-last-sexp)))) + (if (zerop (prefix-numeric-value current-prefix-arg)) + 'no-truncate + 'pretty-print)))) + (if (or (null display-type) + (eq display-type 'pretty-print)) + (edebug-eval-expression (edebug-last-sexp) display-type) + (let ((edebug-print-length nil) + (edebug-print-level nil)) + (edebug-eval-expression (edebug-last-sexp))))) (defun edebug-eval-print-last-sexp (&optional no-truncate) "Evaluate sexp before point in outside environment; insert value. -- 2.39.2