]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix printing the result by 'eval-print-last-sexp'
authorEli Zaretskii <eliz@gnu.org>
Sat, 18 May 2024 09:55:34 +0000 (12:55 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 18 May 2024 18:55:48 +0000 (20:55 +0200)
* lisp/progmodes/elisp-mode.el (elisp--eval-last-sexp): Record the
desired output stream before evaluating the expression.
(Bug#70931)

(cherry picked from commit 82a31e27e6ceed17a116286d2f0f9810be2e1772)

lisp/progmodes/elisp-mode.el

index 44dc4a5d5eec24515394f2ffe4f05546a821b14d..9e727bd4543d763bf475747b62a33233c9062749 100644 (file)
@@ -1556,13 +1556,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)