From bf0c0615392b7f796c23690e10620e21a5926ad4 Mon Sep 17 00:00:00 2001 From: Philip Date: Wed, 26 Aug 2015 09:34:12 +0000 Subject: [PATCH] Document and fix behavior of window/pre-redisplay hooks. * xdisp.c (redisplay_internal): Call `pre-redisplay-function' after resizing mini-windows rather than before. * window.c (Fset_window_configuration): Only set the window size change flag if a window actually changed size. * windows.texi (Window Configurations): Document `window-size-change-functions' isn't called for mini-window resizes. (Window Hooks): Likewise, likewise for `window-configuration-change-hook'. --- doc/lispref/windows.texi | 34 ++++++++++++++++------------------ src/window.c | 8 +++++++- src/xdisp.c | 46 +++++++++++++++++++++++++--------------------- 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 4656938..bb9a5d2 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -3971,11 +3971,7 @@ was created for. The argument @var{configuration} must be a value that was previously returned by @code{current-window-configuration}. The configuration is restored in the frame from which @var{configuration} was made, whether -that frame is selected or not. This always counts as a window size -change and triggers execution of the @code{window-size-change-functions} -(@pxref{Window Hooks}), because @code{set-window-configuration} doesn't -know how to tell whether the new configuration actually differs from the -old one. +that frame is selected or not. If the frame from which @var{configuration} was saved is dead, all this function does is restore the three variables @code{window-min-height}, @@ -4010,8 +4006,8 @@ windows might be opened in other frames (@pxref{Choosing Window}), and configuration on the current frame. Do not use this macro in @code{window-size-change-functions}; exiting -the macro triggers execution of @code{window-size-change-functions}, -leading to an endless loop. +the macro can trigger execution of +@code{window-size-change-functions}, leading to an endless loop. @end defmac @defun window-configuration-p object @@ -4262,10 +4258,9 @@ work. @end defvar @defvar window-size-change-functions -This variable holds a list of functions to be called if the size of any -window changes for any reason. The functions are called just once per -redisplay, and just once for each frame on which size changes have -occurred. +This variable holds a list of functions to be called if the size of +any window changes. The functions are called just once per redisplay, +and just once for each frame on which size changes have occurred. Each function receives the frame as its sole argument. There is no direct way to find out which windows on that frame have changed size, or @@ -4275,20 +4270,23 @@ present sizes and the previous sizes. Creating or deleting windows counts as a size change, and therefore causes these functions to be called. Changing the frame size also -counts, because it changes the sizes of the existing windows. +counts, because it changes the sizes of the existing windows. When +the minibuffer or echo area grows or shrinks, these functions are not +called. You may use @code{save-selected-window} in these functions (@pxref{Selecting Windows}). However, do not use @code{save-window-excursion} (@pxref{Window Configurations}); exiting -that macro counts as a size change, which would cause these functions -to be called over and over. +that macro can count as a size change, which would cause these +functions to be called over and over. @end defvar @defvar window-configuration-change-hook -A normal hook that is run every time you change the window configuration -of an existing frame. This includes splitting or deleting windows, -changing the sizes of windows, or displaying a different buffer in a -window. +A normal hook that is run every time you change the window +configuration of an existing frame. This includes splitting or +deleting windows, changing the sizes of windows, or displaying a +different buffer in a window. However, this hook is not run for a size +change that is solely due to a resized minibuffer or echo area. The buffer-local part of this hook is run once for each window on the affected frame, with the relevant window selected and its buffer diff --git a/src/window.c b/src/window.c index 863a792..be1693c 100644 --- a/src/window.c +++ b/src/window.c @@ -6072,7 +6072,6 @@ the return value is nil. Otherwise the value is t. */) } fset_redisplay (f); - FRAME_WINDOW_SIZES_CHANGED (f) = true; /* Problem: Freeing all matrices and later allocating them again is a serious redisplay flickering problem. What we would @@ -6124,6 +6123,13 @@ the return value is nil. Otherwise the value is t. */) /* If we squirreled away the buffer, restore it now. */ if (BUFFERP (w->combination_limit)) wset_buffer (w, w->combination_limit); + if (!FRAME_WINDOW_SIZES_CHANGED (f)) { + if (w->pixel_left != XFASTINT (p->pixel_left) || + w->pixel_top != XFASTINT (p->pixel_top) || + w->pixel_width != XFASTINT (p->pixel_width) || + w->pixel_height != XFASTINT (p->pixel_height)) + FRAME_WINDOW_SIZES_CHANGED (f) = true; + } w->pixel_left = XFASTINT (p->pixel_left); w->pixel_top = XFASTINT (p->pixel_top); w->pixel_width = XFASTINT (p->pixel_width); diff --git a/src/xdisp.c b/src/xdisp.c index 8be7497..97fc0d8 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -11566,27 +11566,6 @@ prepare_menu_bars (void) tooltip_frame = Qnil; #endif - if (FUNCTIONP (Vpre_redisplay_function)) - { - Lisp_Object windows = all_windows ? Qt : Qnil; - if (all_windows && some_windows) - { - Lisp_Object ws = window_list (); - for (windows = Qnil; CONSP (ws); ws = XCDR (ws)) - { - Lisp_Object this = XCAR (ws); - struct window *w = XWINDOW (this); - if (w->redisplay - || XFRAME (w->frame)->redisplay - || XBUFFER (w->contents)->text->redisplay) - { - windows = Fcons (this, windows); - } - } - } - safe__call1 (true, Vpre_redisplay_function, windows); - } - /* Update all frame titles based on their buffer names, etc. We do this before the menu bars so that the buffer-menu will show the up-to-date frame titles. */ @@ -13514,6 +13493,31 @@ redisplay_internal (void) clear_garbaged_frames (); } + if (FUNCTIONP (Vpre_redisplay_function)) + { + bool all_windows = windows_or_buffers_changed || update_mode_lines; + bool some_windows = REDISPLAY_SOME_P (); + Lisp_Object windows = all_windows ? Qt : Qnil; + + if (all_windows && some_windows) + { + Lisp_Object ws = window_list (); + for (windows = Qnil; CONSP (ws); ws = XCDR (ws)) + { + Lisp_Object this = XCAR (ws); + struct window *w = XWINDOW (this); + if (w->redisplay + || XFRAME (w->frame)->redisplay + || XBUFFER (w->contents)->text->redisplay) + { + windows = Fcons (this, windows); + } + } + } + safe__call1 (true, Vpre_redisplay_function, windows); + } + + if (windows_or_buffers_changed && !update_mode_lines) /* Code that sets windows_or_buffers_changed doesn't distinguish whether only the windows's contents needs to be refreshed, or whether the -- 2.5.0