]> git.eshelyaron.com Git - emacs.git/commitdiff
* src/dispnew.c (sit_for): Fix bug#45292
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 23 Dec 2020 23:31:28 +0000 (18:31 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Wed, 23 Dec 2020 23:31:52 +0000 (18:31 -0500)
When reading, prefer staying in the selected-window over preserving
the current-buffer.

src/dispnew.c

index 89dd32ad0fb85e15c0da85b5b133eebf99f2a4be..e0a647619049d48f0c1a6d93d0ea3918c15d130f 100644 (file)
@@ -6057,6 +6057,8 @@ sit_for (Lisp_Object timeout, bool reading, int display_option)
   intmax_t sec;
   int nsec;
   bool do_display = display_option > 0;
+  bool curbuf_eq_winbuf
+    = (current_buffer == XBUFFER (XWINDOW (selected_window)->contents));
 
   swallow_events (do_display);
 
@@ -6111,6 +6113,13 @@ sit_for (Lisp_Object timeout, bool reading, int display_option)
   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
+       window (e.g. in response to a connection from emacsclient), in which
+       case we should follow it (unless we weren't in the selected-window's
+       buffer to start with).  */
+    set_buffer_internal (XBUFFER (XWINDOW (selected_window)->contents));
+
   return detect_input_pending () ? Qnil : Qt;
 }