w = XWINDOW (window);
other_window = ! EQ (window, selected_window);
- /* If given window's buffer isn't current, make it current for
- the moment. But don't screw up if window_scroll gets an error. */
+ /* If given window's buffer isn't current, make it current for the
+ moment. If the window's buffer is the same, but it is not the
+ selected window, we need to save-excursion to avoid affecting
+ point in the selected window (which would cause the selected
+ window to scroll). Don't screw up if window_scroll gets an
+ error. */
if (other_window || XBUFFER (w->contents) != current_buffer)
{
record_unwind_protect_excursion ();
- Fset_buffer (w->contents);
+ if (XBUFFER (w->contents) != current_buffer)
+ Fset_buffer (w->contents);
}
if (other_window)