unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Eli Zaretskii <eliz@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 67196@debbugs.gnu.org, acm@muc.de
Subject: bug#67196: M-: uses a wrong value of debug-on-error when it is nil.
Date: Fri, 24 Nov 2023 20:54:45 +0000	[thread overview]
Message-ID: <ZWENlc6fj9odIdt6@ACM> (raw)
In-Reply-To: <83ttpbdm2f.fsf@gnu.org>

Hello, Eli and Stefan.

On Fri, Nov 24, 2023 at 20:48:40 +0200, Eli Zaretskii wrote:
> > Date: Fri, 24 Nov 2023 17:10:47 +0000
> > Cc: Eli Zaretskii <eliz@gnu.org>, 67196@debbugs.gnu.org
> > From: Alan Mackenzie <acm@muc.de>

> > Firstly, though, there is a bug in the doc string of
> > eval-expression-debug-on-error: rather than stating what the meaning of
> > the variable is, what it's for, it states the low level details of how
> > it achieves the desired effect.  This is needlessly restrictive.  I
> > propose changing that doc string from:

> >     If non-nil set `debug-on-error' to t in `eval-expression'.
> >     If nil, don't change the value of `debug-on-error'.

> > to something like:

> >     Non-nil means enter debugger on an error in a call from `eval-expression'.
> >     Does not apply to errors handled by `condition-case' or those
> >     matched by `debug-ignored-errors'.
> >     A nil value for this variable will not prevent an entry to
> >     the debugger caused by other variables such as `debug-on-error'.

> First, the last two sentences above should be transposed, as the
> second one is not related to the 1st one, but the 3rd one is.

Done.

> And second, please try to reword so that the text is less complicated
> and easier to understand.

I'm perhaps a bit too close to it.  Apart from the first line (for which
too much information needs squashing in), I can't really see much scope
for improvement.

> Thanks.

Anyway, here's the patch of the current state.  With it, M-:
debug-on-error RET shows nil, when that is the case.  M-: (foo) enters
the debugger when an error gets signalled, assuming
eval-expression-debug-on-error is t (or a suitable list), but doesn't
enter the debugger when e-e-d-o-error is nil.

There's a slight disadvantage to the approach, namely the introduction of
a new internal variable debug-from--eval-expression which is tested from
signal_or_quit.  On the other hand, eval-expression itself has been
noticeably simplified.



diff --git a/lisp/simple.el b/lisp/simple.el
index 02c68912dba..e8a9a795c0b 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1981,11 +1981,17 @@ eval-expression-print-length
   :version "21.1")
 
 (defcustom eval-expression-debug-on-error t
-  "If non-nil set `debug-on-error' to t in `eval-expression'.
-If nil, don't change the value of `debug-on-error'."
+  "Non-nil means enter debugger on error on a call from `eval-expression'.
+Does not apply to errors handled by `condition-case' or those
+matched by `debug-ignored-errors'.
+Like `debug-on-error', this variable's value can also be a list,
+with the same meaning as for `debug-on-error'.
+
+A nil value for this variable will not prevent an entry to
+the debugger caused by other variables such as `debug-on-error'."
   :group 'lisp
   :type 'boolean
-  :version "21.1")
+  :version "30.1")
 
 (defcustom eval-expression-print-maximum-character 127
   "The largest integer that will be displayed as a character.
@@ -2120,34 +2126,19 @@ eval-expression
    (cons (read--expression "Eval: ")
          (eval-expression-get-print-arguments current-prefix-arg)))
 
-  (let (result)
-    (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))))
-
-    (let ((print-length (unless no-truncate eval-expression-print-length))
-          (print-level  (unless no-truncate eval-expression-print-level))
-          (eval-expression-print-maximum-character char-print-limit)
-          (deactivate-mark))
-      (let ((out (if insert-value (current-buffer) t)))
-        (prog1
-            (prin1 result out)
-          (let ((str (and char-print-limit
-                          (eval-expression-print-format result))))
-            (when str (princ str out))))))))
+  (let* ((debug-from--eval-expression eval-expression-debug-on-error)
+         (result (values--store-value
+                  (eval (let ((lexical-binding t)) (macroexpand-all exp)) t)))
+         (print-length (unless no-truncate eval-expression-print-length))
+         (print-level  (unless no-truncate eval-expression-print-level))
+         (eval-expression-print-maximum-character char-print-limit)
+         (deactivate-mark)
+         (out (if insert-value (current-buffer) t)))
+    (prog1
+        (prin1 result out)
+      (let ((str (and char-print-limit
+                      (eval-expression-print-format result))))
+        (when str (princ str out))))))
 
 (defun edit-and-eval-command (prompt command)
   "Prompting with PROMPT, let user edit COMMAND and eval result.
diff --git a/src/eval.c b/src/eval.c
index 12e811ce264..6cadda01efb 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2033,7 +2033,8 @@ maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, Lisp_Object data)
       /* Does user want to enter debugger for this kind of error?  */
       && (signal_quit_p (sig)
 	  ? debug_on_quit
-	  : wants_debugger (Vdebug_on_error, conditions))
+	  : (wants_debugger (Vdebug_from__eval_expression, conditions)
+	     || wants_debugger (Vdebug_on_error, conditions)))
       && ! skip_debugger (conditions, combined_data)
       /* See commentary on definition of
          `internal-when-entered-debugger'.  */
@@ -4299,6 +4300,13 @@ syms_of_eval (void)
 See also the variable `debug-on-quit' and `inhibit-debugger'.  */);
   Vdebug_on_error = Qnil;
 
+  DEFVAR_LISP ("debug-from--eval-expression", Vdebug_from__eval_expression,
+	       doc: /* Non-nil means enter debugger if an error is signaled.
+This only applies in forms called by `eval-expression'.  This variable
+has the same semantics as `debug-on-error'.  It is an internal variable
+only.  */);
+  Vdebug_from__eval_expression = Qnil;
+
   DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors,
     doc: /* List of errors for which the debugger should not be called.
 Each element may be a condition-name or a regexp that matches error messages.


-- 
Alan Mackenzie (Nuremberg, Germany).





  reply	other threads:[~2023-11-24 20:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-15 13:48 bug#67196: M-: uses a wrong value of debug-on-error when it is nil Alan Mackenzie
2023-11-15 17:19 ` Eli Zaretskii
2023-11-15 17:55   ` Alan Mackenzie
2023-11-19 17:19     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-19 17:33       ` Eli Zaretskii
     [not found]         ` <87a5r9efj0.fsf@dick>
2023-11-19 19:30           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-24 17:10       ` Alan Mackenzie
2023-11-24 18:48         ` Eli Zaretskii
2023-11-24 20:54           ` Alan Mackenzie [this message]
2023-11-24 21:25             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-24 22:21               ` Alan Mackenzie
2023-11-25  7:59                 ` Eli Zaretskii
2023-11-25 10:32                   ` Alan Mackenzie
2023-11-25 11:15                     ` Eli Zaretskii
2023-11-25 12:40                       ` Alan Mackenzie
2023-11-25 13:04                         ` Eli Zaretskii
2023-11-25 14:14                           ` Alan Mackenzie
2023-11-25 15:50                             ` Eli Zaretskii
2023-11-25 16:40                               ` Alan Mackenzie
2023-11-25 16:46                                 ` Eli Zaretskii
2023-11-25 16:57                                   ` Alan Mackenzie
2023-11-25 17:36                                     ` Alan Mackenzie
2023-11-25 18:12                                     ` Andreas Schwab
2023-11-25 14:23                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-17  4:23                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-19  3:54                         ` Richard Stallman
2023-12-19  5:05                           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-25  3:41                             ` Richard Stallman
2023-12-26  2:39                               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-27  4:54                                 ` Richard Stallman
2023-11-25  7:30             ` Eli Zaretskii
2023-11-24 20:22         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZWENlc6fj9odIdt6@ACM \
    --to=acm@muc.de \
    --cc=67196@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).