]> code.delx.au - gnu-emacs/commitdiff
(window_scroll_pixel_based): Only look at
authorRichard M. Stallman <rms@gnu.org>
Fri, 31 Dec 2004 15:07:48 +0000 (15:07 +0000)
committerRichard M. Stallman <rms@gnu.org>
Fri, 31 Dec 2004 15:07:48 +0000 (15:07 +0000)
Vscroll_preserve_screen_position if the old PT can't be kept.
(syms_of_window) <scroll-preserve-screen-position>: Doc fix.

src/window.c

index 6fe547b97c785951fd8eab43c1a003775171de0e..d42ff11d7dd58448d32339118b3d2df96bcc6ec9 100644 (file)
@@ -4671,30 +4671,32 @@ window_scroll_pixel_based (window, n, whole, noerror)
      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)
+  /* 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)
     {
-      /* If we have a header line, take account of it.  */
-      if (WINDOW_WANTS_HEADER_LINE_P (w))
-       preserve_y -= CURRENT_HEADER_LINE_HEIGHT (w);
+      /* 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)
+       {
+         /* 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_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y);
+         SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
+       }
+      else
        {
-         /* 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);
          while (it.current_y < this_scroll_margin)
            {
              int prev = it.current_y;
@@ -4704,22 +4706,44 @@ window_scroll_pixel_based (window, n, whole, noerror)
            }
          SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
        }
-      else if (n < 0)
-       {
-         int charpos, bytepos;
+    }
+  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);
+      /* 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)
+       {
+         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 @@ If there is only one window, it is split regardless of this value.  */);
 
   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",