changeset 59258:e5b68c4be92b

(window_scroll_pixel_based): Only look at Vscroll_preserve_screen_position if the old PT can't be kept. (syms_of_window) <scroll-preserve-screen-position>: Doc fix.
author Richard M. Stallman <rms@gnu.org>
date Fri, 31 Dec 2004 15:07:48 +0000
parents e828ce1ff4bb
children 07897e1a19b5
files src/window.c
diffstat 1 files changed, 58 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/window.c	Fri Dec 31 15:04:25 2004 +0000
+++ b/src/window.c	Fri Dec 31 15:07:48 2004 +0000
@@ -4671,30 +4671,32 @@
      not including the height of the header line if any.  */
   it.current_y = it.vpos = 0;
 
-  /* Preserve the screen position if we should.  */
-  if (preserve_y >= 0)
-    {
-      /* If we have a header line, take account of it.  */
-      if (WINDOW_WANTS_HEADER_LINE_P (w))
-	preserve_y -= CURRENT_HEADER_LINE_HEIGHT (w);
-
-      move_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y);
-      SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
-    }
-  else
+  /* Move PT out of scroll margins.
+     This code wants current_y to be zero at the window start position
+     even if there is a header line.  */
+  this_scroll_margin = max (0, scroll_margin);
+  this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
+  this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
+
+  if (n > 0)
     {
-      /* Move PT out of scroll margins.
-	 This code wants current_y to be zero at the window start position
-	 even if there is a header line.  */
-      this_scroll_margin = max (0, scroll_margin);
-      this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
-      this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
-
-      if (n > 0)
+      /* We moved the window start towards ZV, so PT may be now
+	 in the scroll margin at the top.  */
+      move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
+      if (IT_CHARPOS (it) == PT && it.current_y >= this_scroll_margin)
+	/* We found PT at a legitimate height.  Leave it alone.  */
+	;
+      else if (preserve_y >= 0)
 	{
-	  /* We moved the window start towards ZV, so PT may be now
-	     in the scroll margin at the top.  */
-	  move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
+	  /* If we have a header line, take account of it.  */
+	  if (WINDOW_WANTS_HEADER_LINE_P (w))
+	    preserve_y -= CURRENT_HEADER_LINE_HEIGHT (w);
+
+	  move_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y);
+	  SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
+	}
+      else
+	{
 	  while (it.current_y < this_scroll_margin)
 	    {
 	      int prev = it.current_y;
@@ -4704,22 +4706,44 @@
 	    }
 	  SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
 	}
-      else if (n < 0)
+    }
+  else if (n < 0)
+    {
+      int charpos, bytepos;
+
+      /* Save our position, for the preserve_y case.  */
+      charpos = IT_CHARPOS (it);
+      bytepos = IT_BYTEPOS (it);
+
+      /* We moved the window start towards BEGV, so PT may be now
+	 in the scroll margin at the bottom.  */
+      move_it_to (&it, PT, -1,
+		  it.last_visible_y - this_scroll_margin - 1, -1,
+		  MOVE_TO_POS | MOVE_TO_Y);
+
+      if (IT_CHARPOS (it) == PT)
+	/* We found PT before we found the display margin, so PT is ok.  */
+	;
+      else if (preserve_y >= 0)
 	{
-	  int charpos, bytepos;
-
-	  /* We moved the window start towards BEGV, so PT may be now
-	     in the scroll margin at the bottom.  */
-	  move_it_to (&it, PT, -1,
-		      it.last_visible_y - this_scroll_margin - 1, -1,
-		      MOVE_TO_POS | MOVE_TO_Y);
-
+	  SET_TEXT_POS_FROM_MARKER (start, w->start);
+	  start_display (&it, w, start);
+	  /* If we have a header line, take account of it.  */
+	  if (WINDOW_WANTS_HEADER_LINE_P (w))
+	    preserve_y -= CURRENT_HEADER_LINE_HEIGHT (w);
+
+	  move_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y);
+	  SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
+	}
+      else
+	{
 	  /* Save our position, in case it's correct.  */
 	  charpos = IT_CHARPOS (it);
 	  bytepos = IT_BYTEPOS (it);
 
 	  /* See if point is on a partially visible line at the end.  */
 	  move_it_by_lines (&it, 1, 1);
+
 	  if (it.current_y > it.last_visible_y)
 	    /* The last line was only partially visible, so back up two
 	       lines to make sure we're on a fully visible line.  */
@@ -6753,7 +6777,9 @@
 
   DEFVAR_LISP ("scroll-preserve-screen-position",
 	       &Vscroll_preserve_screen_position,
-	       doc: /* *Non-nil means scroll commands move point to keep its screen line unchanged.  */);
+	       doc: /* *Non-nil means scroll commands move point to keep its screen line unchanged.
+This is only when it is impossible to keep point fixed and still
+scroll as specified.  */);
   Vscroll_preserve_screen_position = Qnil;
 
   DEFVAR_LISP ("window-configuration-change-hook",