Subject: Re: bug#19576: write-file writes the wrong buffer

From: martin rudalics <[email-masked]>
Date: Mon, 30 Nov 2015 14:30:31 +0100

>> Here with emacs -Q evaluating
 >>
 >> (message "...\n")
 >>
 >> runs ‘window-size-change-functions’.  Evaluating
 >>
 >> (read-file-name "...\n")
 >>
 >> doesn't.  If this is intentional it should be documented.
 >
 > I don't know if it's intentional.  Could you please look into this and
 > publish what you find?  I really could use some help here.

The attached patch runs ‘window-size-change-functions’ for any call of
‘read-from-minibuffer’ that changes the size of the minibuffer window
either via the prompt or user input.  I have no idea whether it handles
all possible cases nor whether it might baldy interact with the part
that traces messages resizing the echo area.

Also, saving match data around the ‘window-size-change-functions’ calls
and not saving current buffer and selected window constitutes a gross
inconsistency IMHO.  So I'd rather prefer to close my eyes to this part
of the code, if possible.

martin
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -13581,6 +13581,27 @@ redisplay_internal (void)
 	   && (current_buffer->clip_changed || window_outdated (w))
 	   && resize_mini_window (w, false))
     {
+      if (sf->redisplay)
+	{
+	  Lisp_Object functions;
+	  ptrdiff_t count1 = SPECPDL_INDEX ();
+
+	  record_unwind_save_match_data ();
+
+	  /* Clear flag first in case we get an error below.  */
+	  FRAME_WINDOW_SIZES_CHANGED (sf) = false;
+	  functions = Vwindow_size_change_functions;
+
+	  while (CONSP (functions))
+	    {
+	      if (!EQ (XCAR (functions), Qt))
+		call1 (XCAR (functions), selected_frame);
+	      functions = XCDR (functions);
+	    }
+
+	  unbind_to (count1, Qnil);
+	}
+
       /* Resized active mini-window to fit the size of what it is
          showing if its contents might have changed.  */
       must_finish = true;