emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 5d68170: * src/dispnew.c (sit_for): Return nil when interrupted b


From: Stefan Monnier
Subject: master 5d68170: * src/dispnew.c (sit_for): Return nil when interrupted by process output
Date: Fri, 15 Jan 2021 22:39:00 -0500 (EST)

branch: master
commit 5d6817086d6485bc6e3dde054d877c0759656ddd
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * src/dispnew.c (sit_for): Return nil when interrupted by process output
    
    Before adbb4eacc2a984c0fc0b65ec761368fd9067d6c5,
    `read_and_dispose_of_process_output` called
    `record_asynch_buffer_change` which added "artificial" input events
    (in the form of BUFFER_SWITCH_EVENTs), causing sit_for to return
    Qnil when interrupted by process output.  Without those 
BUFFER_SWITCH_EVENTs,
    sit_for now tends to return Qt when interrupted by process output
    making `read_char` believe that we've waited the whole timeout,
    As consequence incoming process output tended to cause premature
    auto-saving of files (sometimes right after almost every key press).
    
    This patch recovers the previous behavior, which is not ideal
    (incoming process output can delay auto-save indefinitely), but has
    been good enough for many years.
---
 src/dispnew.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/dispnew.c b/src/dispnew.c
index 36a6dd8..e603c67 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -6049,7 +6049,14 @@ additional wait period, in milliseconds; this is for 
backwards compatibility.
    READING is true if reading input.
    If DISPLAY_OPTION is >0 display process output while waiting.
    If DISPLAY_OPTION is >1 perform an initial redisplay before waiting.
-*/
+
+   Returns a boolean Qt if we waited the full time and returns Qnil if the
+   wait was interrupted by incoming process output or keyboard events.
+
+   FIXME: When `wait_reading_process_output` returns early because of
+   process output, instead of returning nil we should loop and wait some
+   more (i.e. until either there's pending input events or the timeout
+   expired).  */
 
 Lisp_Object
 sit_for (Lisp_Object timeout, bool reading, int display_option)
@@ -6110,8 +6117,9 @@ sit_for (Lisp_Object timeout, bool reading, int 
display_option)
   gobble_input ();
 #endif
 
-  wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display,
-                              Qnil, NULL, 0);
+  int nbytes
+    = wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display,
+                                  Qnil, NULL, 0);
 
   if (reading && curbuf_eq_winbuf)
     /* Timers and process filters/sentinels may have changed the selected
@@ -6120,7 +6128,7 @@ sit_for (Lisp_Object timeout, bool reading, int 
display_option)
        buffer to start with).  */
     set_buffer_internal (XBUFFER (XWINDOW (selected_window)->contents));
 
-  return detect_input_pending () ? Qnil : Qt;
+  return (nbytes > 0 || detect_input_pending ()) ? Qnil : Qt;
 }
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]