From: Eli Zaretskii Date: Sat, 18 May 2024 09:55:34 +0000 (+0300) Subject: Fix printing the result by 'eval-print-last-sexp' X-Git-Tag: archive/raspbian/1%30.1+1-3+rpi1^2~2^2~20^2~1464 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=82a31e27e6ceed17a116286d2f0f9810be2e1772;p=emacs.git Fix printing the result by 'eval-print-last-sexp' * lisp/progmodes/elisp-mode.el (elisp--eval-last-sexp): Record the desired output stream before evaluating the expression. (Bug#70931) --- diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 84814c9eaac..7d0312eb2a4 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -1557,13 +1557,16 @@ character)." (pcase-let* ((`(,insert-value ,no-truncate ,char-print-limit) (eval-expression-get-print-arguments eval-last-sexp-arg-internal))) - ;; Setup the lexical environment if lexical-binding is enabled. - (elisp--eval-last-sexp-print-value - (eval (macroexpand-all - (eval-sexp-add-defvars - (elisp--eval-defun-1 (macroexpand (elisp--preceding-sexp))))) - lexical-binding) - (if insert-value (current-buffer) t) no-truncate char-print-limit))) + ;; The expression might change to a different buffer, so record the + ;; desired output stream now. + (let ((output (if insert-value (current-buffer) t))) + ;; Setup the lexical environment if lexical-binding is enabled. + (elisp--eval-last-sexp-print-value + (eval (macroexpand-all + (eval-sexp-add-defvars + (elisp--eval-defun-1 (macroexpand (elisp--preceding-sexp))))) + lexical-binding) + output no-truncate char-print-limit)))) (defun elisp--eval-last-sexp-print-value (value output &optional no-truncate char-print-limit)