=== modified file 'src/window.c' --- src/window.c 2013-02-01 07:23:18 +0000 +++ src/window.c 2013-02-07 05:31:20 +0000 @@ -269,9 +269,10 @@ } /* Called when W's buffer slot is changed. ARG -1 means that W is about to - cease its buffer, and 1 means that W is about to set up the new one. */ + cease its buffer, and 1 means that W is about to set up the new one. + Return W's buffer if it's a buffer or NULL otherwise. */ -static void +static struct buffer * adjust_window_count (struct window *w, int arg) { eassert (eabs (arg) == 1); @@ -283,21 +284,34 @@ b = b->base_buffer; b->window_count += arg; eassert (b->window_count >= 0); - /* These should be recalculated by redisplay code. */ - w->window_end_valid = 0; - w->base_line_pos = 0; + return b; } + return NULL; } -/* Set W's buffer slot to VAL and recompute number - of windows showing VAL if it is a buffer. */ +/* Set W's buffer slot to VAL and recompute number of windows showing + VAL if it is a buffer, catch some redisplay's attention if needed. */ void wset_buffer (struct window *w, Lisp_Object val) { - adjust_window_count (w, -1); + struct buffer *oldb, *newb; + + oldb = adjust_window_count (w, -1); w->buffer = val; - adjust_window_count (w, 1); + newb = adjust_window_count (w, 1); + if ((oldb && oldb == newb + && ((BUF_UNCHANGED_MODIFIED (oldb) < BUF_MODIFF (oldb)) + || (BUF_OVERLAY_UNCHANGED_MODIFIED (oldb) + < BUF_OVERLAY_MODIFF (oldb)))) + || (!oldb && newb)) + { + /* If W's buffer was changed since last redisplay or W + is switched to another buffer from no buffer, next + redisplay should recalculate these fields. */ + w->window_end_valid = 0; + w->base_line_pos = 0; + } } /* Build a frequently used 4-integer (X Y W H) list. */