[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/handler-bind-2 235907e1764 12/16: Add `redisplay-counter` to cat
From: |
Stefan Monnier |
Subject: |
scratch/handler-bind-2 235907e1764 12/16: Add `redisplay-counter` to catched nested redisplays and abort outer one |
Date: |
Wed, 27 Dec 2023 23:53:31 -0500 (EST) |
branch: scratch/handler-bind-2
commit 235907e17647f2cb924de759bfaca88eb0a35e08
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
Add `redisplay-counter` to catched nested redisplays and abort outer one
---
src/eval.c | 8 --------
src/xdisp.c | 22 +++++++++++++++++++++-
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/eval.c b/src/eval.c
index a821312b5ff..7bb26abc616 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -304,14 +304,6 @@ call_debugger (Lisp_Object arg)
val = apply1 (Vdebugger, arg);
- /* Interrupting redisplay and resuming it later is not safe under
- all circumstances. So, when the debugger returns, abort the
- interrupted redisplay by going back to the top-level. */
- /* FIXME: Move this to the redisplay code? */
- if (debug_while_redisplaying
- && !EQ (Vdebugger, Qdebug_early))
- Ftop_level ();
-
return unbind_to (count, val);
}
diff --git a/src/xdisp.c b/src/xdisp.c
index aa1d4433914..551887e9207 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3031,6 +3031,17 @@ hscrolling_current_line_p (struct window *w)
Lisp form evaluation
***********************************************************************/
+/* The redisplay is not re-entrant. But we can run ELisp code during
+ redisplay, which in turn can trigger redisplay.
+ We try to make this inner redisplay work correctly, but it messes up
+ the state of the outer redisplay, so when we return to this outer
+ redisplay, we need to abort it.
+ To dect this case, we keep a counter that identifies every call to the
+ redisplay, so we can detect when a nested redisplay happened by the
+ fact that the counter has changed. */
+
+static int redisplay_counter = 0;
+
/* Error handler for dsafe_eval and dsafe_call. */
static Lisp_Object
@@ -3062,10 +3073,17 @@ dsafe__call (bool inhibit_quit, Lisp_Object (f)
(ptrdiff_t, Lisp_Object *),
specbind (Qinhibit_redisplay, Qt);
if (inhibit_quit)
specbind (Qinhibit_quit, Qt);
+ int redisplay_counter_before = redisplay_counter;
/* Use Qt to ensure debugger does not run,
- so there is no possibility of wanting to redisplay. */
+ to reduce the risk of wanting to redisplay. */
val = internal_condition_case_n (f, nargs, args, Qt,
dsafe_eval_handler);
+ if (redisplay_counter_before != redisplay_counter)
+ /* A nested redisplay happened, abort this one! */
+ /* FIXME: Rather than jump all the way to to `top-level`
+ we should exit only the current redisplay. */
+ Ftop_level ();
+
val = unbind_to (count, val);
}
@@ -16663,6 +16681,8 @@ redisplay_internal (void)
bool polling_stopped_here = false;
Lisp_Object tail, frame;
+ redisplay_counter++;
+
/* Set a limit to the number of retries we perform due to horizontal
scrolling, this avoids getting stuck in an uninterruptible
infinite loop (Bug #24633). */
- scratch/handler-bind-2 40437afc8ee 09/16: (signal_or_quit): Preserve error object identity, (continued)
- scratch/handler-bind-2 40437afc8ee 09/16: (signal_or_quit): Preserve error object identity, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 19f1d2a9f51 02/16: (eval-expression): Fix bug#67196, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 10e04044c7b 06/16: (macroexp--with-extended-form-stack): Use plain `let`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 617d568f4b6 03/16: ert.el: Use `handler-bind` to record backtraces, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 b21a22c86cc 13/16: Allow the `error-message` property to be a function, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 5a3ed126ccc 14/16: tramp.el: Use `handler-bind` instead of `signal-hook-function`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 c03598f1323 11/16: src/eval.c (call_debugger): Don't bind `Qinhibit_changing_match_data`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 bb9e093a106 08/16: Use handler-bind to repair bytecomp-tests, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 bc5500be3b0 15/16: (edebug-format): Make it obsolete, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 d9f047e2da5 05/16: Move batch backtrace code to `top_level_2`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 235907e1764 12/16: Add `redisplay-counter` to catched nested redisplays and abort outer one,
Stefan Monnier <=
- scratch/handler-bind-2 857f1d37037 04/16: startup.el: Use `handler-bind` to implement `--debug-init`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 94b11fc0c9b 16/16: edebug.el: Use `handler-bind` instead of `signal-hook-function`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 1c5f2f854d9 10/16: (backtrace-on-redisplay-error): Use `handler-bind`, Stefan Monnier, 2023/12/27