]> git.eshelyaron.com Git - emacs.git/commitdiff
(eval-expression): Fix bug#67196
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 19 Dec 2023 04:47:56 +0000 (23:47 -0500)
committerEshel Yaron <me@eshelyaron.com>
Fri, 5 Jan 2024 08:18:34 +0000 (09:18 +0100)
* lisp/simple.el (eval-expression--debug): New function.
(eval-expression): Use it together with `handler-bind` instead of
let-binding `debug-on-error`.

(cherry picked from commit 7959a63ce258c90eb3c7947ab3318c5531eb37d9)

lisp/simple.el

index 4c50ec99cd80e598a4483ab61ed4babd7a5771c2..13177671d628fcd4f2f90a3799501badaea20400 100644 (file)
@@ -2099,6 +2099,9 @@ of the prefix argument for `eval-expression' and
                 ((= num -1) most-positive-fixnum)
                 (t eval-expression-print-maximum-character)))))
 
+(defun eval-expression--debug (err)
+  (funcall debugger 'error err :backtrace-base #'eval-expression--debug))
+
 ;; We define this, rather than making `eval' interactive,
 ;; for the sake of completion of names like eval-region, eval-buffer.
 (defun eval-expression (exp &optional insert-value no-truncate char-print-limit)
@@ -2132,23 +2135,17 @@ this command arranges for all errors to enter the debugger."
    (cons (read--expression "Eval: ")
          (eval-expression-get-print-arguments current-prefix-arg)))
 
-  (let (result)
+  (let* (result
+         (runfun
+          (lambda ()
+            (setq result
+                  (values--store-value
+                   (eval (let ((lexical-binding t)) (macroexpand-all exp))
+                         t))))))
     (if (null eval-expression-debug-on-error)
-        (setq result
-              (values--store-value
-               (eval (let ((lexical-binding t)) (macroexpand-all exp)) t)))
-      (let ((old-value (make-symbol "t")) new-value)
-        ;; Bind debug-on-error to something unique so that we can
-        ;; detect when evalled code changes it.
-        (let ((debug-on-error old-value))
-          (setq result
-               (values--store-value
-                 (eval (let ((lexical-binding t)) (macroexpand-all exp)) t)))
-         (setq new-value debug-on-error))
-        ;; If evalled code has changed the value of debug-on-error,
-        ;; propagate that change to the global binding.
-        (unless (eq old-value new-value)
-         (setq debug-on-error new-value))))
+        (funcall runfun)
+      (handler-bind ((error #'eval-expression--debug))
+        (funcall runfun)))
 
     (let ((print-length (unless no-truncate eval-expression-print-length))
           (print-level  (unless no-truncate eval-expression-print-level))