changeset 87847:800f21c9f989

(set_window_buffer): Don't unnecessarily reset hscroll and vscroll if we're setting window-buffer to the value it already has.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 19 Jan 2008 05:11:02 +0000
parents 50aec4a9ce08
children 7471059517c8
files src/ChangeLog src/window.c
diffstat 2 files changed, 28 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sat Jan 19 03:13:35 2008 +0000
+++ b/src/ChangeLog	Sat Jan 19 05:11:02 2008 +0000
@@ -1,3 +1,8 @@
+2008-01-19  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* window.c (set_window_buffer): Don't unnecessarily reset hscroll and
+	vscroll if we're setting window-buffer to the value it already has.
+
 2008-01-18  Dan Nicolaescu  <dann@ics.uci.edu>
 
 	* m/intel386.h: Remove references to XENIX.
--- a/src/window.c	Sat Jan 19 03:13:35 2008 +0000
+++ b/src/window.c	Sat Jan 19 05:11:02 2008 +0000
@@ -3321,6 +3321,7 @@
   struct window *w = XWINDOW (window);
   struct buffer *b = XBUFFER (buffer);
   int count = SPECPDL_INDEX ();
+  int samebuf = EQ (buffer, w->buffer);
 
   w->buffer = buffer;
 
@@ -3339,16 +3340,28 @@
   XSETFASTINT (w->window_end_vpos, 0);
   bzero (&w->last_cursor, sizeof w->last_cursor);
   w->window_end_valid = Qnil;
-  w->hscroll = w->min_hscroll = make_number (0);
-  w->vscroll = 0;
-  set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
-  set_marker_restricted (w->start,
-			 make_number (b->last_window_start),
-			 buffer);
-  w->start_at_line_beg = Qnil;
-  w->force_start = Qnil;
-  XSETFASTINT (w->last_modified, 0);
-  XSETFASTINT (w->last_overlay_modified, 0);
+  if (!(keep_margins_p && samebuf))
+    { /* If we're not actually changing the buffer, Don't reset hscroll and
+	 vscroll.  This case happens for example when called from
+	 change_frame_size_1, where we use a dummy call to
+	 Fset_window_buffer on the frame's selected window (and no other)
+	 just in order to run window-configuration-change-hook.
+	 Resetting hscroll and vscroll here is problematic for things like
+	 image-mode and doc-view-mode since it resets the image's position
+	 whenever we resize the frame.  */
+      w->hscroll = w->min_hscroll = make_number (0);
+      w->vscroll = 0;
+      set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
+      set_marker_restricted (w->start,
+			     make_number (b->last_window_start),
+			     buffer);
+      w->start_at_line_beg = Qnil;
+      w->force_start = Qnil;
+      XSETFASTINT (w->last_modified, 0);
+      XSETFASTINT (w->last_overlay_modified, 0);
+    }
+  /* Maybe we could move this into the `if' but it's not obviously safe and
+     I doubt it's worth the trouble.  */
   windows_or_buffers_changed++;
 
   /* We must select BUFFER for running the window-scroll-functions.