From f3c188ceb01e38ddeeb9ed99ecb947fbaa4ae369 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Tue, 10 Jun 2025 11:28:47 -0700 Subject: [PATCH] Add redisplay-can-quit to keep redisplay atomic by default * src/xdisp.c (redisplay_internal): Bind inhibit-quit when redisplay-can-quit is nil to ensure atomic redisplay updates. (syms_of_xdisp): New variable redisplay-can-quit. * etc/NEWS: Document the new variable. --- etc/NEWS | 7 +++++++ src/xdisp.c | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index f23937fb4b8..3bad14e2f9d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2455,6 +2455,13 @@ Binding 'inhibit-message' to a non-nil value will now suppress both the display of messages and the clearing of the echo area, such as caused by calling 'message' with a nil argument. +--- +** New variable 'redisplay-can-quit' to allow quit during redisplay. +This variable is normally nil to ensure redisplay completes atomically. +Setting it to t allows C-g to interrupt redisplay, which can be useful +for debugging redisplay hangs but may leave the display in an +inconsistent state. + ** Special Events +++ diff --git a/src/xdisp.c b/src/xdisp.c index 291e069395b..2810c970c46 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -17160,6 +17160,9 @@ redisplay_internal (void) /* Record a function that clears redisplaying_p when we leave this function. */ specpdl_ref count = SPECPDL_INDEX (); + if (!redisplay_can_quit) + specbind (Qinhibit_quit, Qt); + record_unwind_protect_void (unwind_redisplay); redisplaying_p = true; block_buffer_flips (); @@ -38753,6 +38756,14 @@ The recommended non-zero value is between 100000 and 1000000, depending on your patience and the speed of your system. */); max_redisplay_ticks = 0; + DEFVAR_BOOL ("redisplay-can-quit", + redisplay_can_quit, + doc: /* If true allow quit to interrupt redisplay. +Normally, we inhibit quit in redisplay to ensure each update completes +atomically and leaves the display in a known-good state. You may want to +set this variable to t to help debug redisplay hangs. */); + redisplay_can_quit = false; + /* Called by decode_mode_spec. */ DEFSYM (Qfile_remote_p, "file-remote-p");