emacs-devel
[Top][All Lists]
Advanced

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

Re: A whole lotta auto-saving going


From: Stefan Monnier
Subject: Re: A whole lotta auto-saving going
Date: Mon, 11 Jan 2021 11:00:04 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>> Does someone here understanding something of what
>> `wait_reading_process_output` does and what it is expected to do?
> You mean, in general? or in this specific case?

Both.

> The latter is described by the comment above this fragment.

It gives an idea, yes, but not enough to know what is expected in the
specific case that corresponds to how it's called from `sit_for`.

>> Why does it exit here before the end of the timeout?  IIUC it is
>> supposed to exit as soon as we got some output from `wait_proc`, but in
>> this case `wait_proc` is NULL.  Is it also supposed to exit when some
>> process output arrives?  If so, shouldn't `sit_for` wrap the call to
>> `wait_reading_process_output` inside a loop to make sure we wait the
>> whole timeout?
> I think sitting for the entire period is undesirable, since receiving
> output from a process might require redisplay.
> In that case, waiting could make Emacs seem unresponsive or busy,
> whereas it really isn't.

But the `do_display` argument indicates that if redisplay is needed it
can happen without returning from `wait_reading_process_output`.

> I think a simple solution to this would be to check the time passed
> after sit_for returns, and if some of the wait time is left, not call
> auto-save.  This would mimic what happened before the offending
> changeset.

The patch below implements that option.

There's one other call to `sit_for` which can be affected:

          tem0 = sit_for (Vecho_keystrokes, 1, 1);
          unbind_to (count, Qnil);
          if (EQ (tem0, Qt)
              && ! CONSP (Vunread_command_events))
            echo_now ();

I believe it's an improvement there as well.


        Stefan


diff --git a/src/dispnew.c b/src/dispnew.c
index 36a6dd8a09..39adbb2229 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -6049,7 +6049,9 @@ DEFUN ("sleep-for", Fsleep_for, Ssleep_for, 1, 2, 0,
    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.  */
 
 Lisp_Object
 sit_for (Lisp_Object timeout, bool reading, int display_option)
@@ -6110,8 +6112,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 +6123,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]