Add 2009 to copyright years.
[bpt/emacs.git] / src / xdisp.c
index b7c05f9..cea8616 100644 (file)
@@ -1,7 +1,7 @@
 /* Display generation from window structure and buffer text.
    Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
                  1997, 1998, 1999, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -1323,7 +1323,7 @@ pos_visible_p (w, charpos, x, y, rtop, rbot, rowh, vpos)
   int visible_p = 0;
   struct buffer *old_buffer = NULL;
 
-  if (noninteractive)
+  if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w))))
     return visible_p;
 
   if (XBUFFER (w->buffer) != current_buffer)
@@ -7206,7 +7206,8 @@ move_it_to (it, to_charpos, to_x, to_y, to_vpos, op)
            break;
        }
       else if (BUFFERP (it->object)
-              && it->method == GET_FROM_BUFFER
+              && (it->method == GET_FROM_BUFFER
+                  || it->method == GET_FROM_STRETCH)
               && IT_CHARPOS (*it) >= to_charpos)
        skip = MOVE_POS_MATCH_OR_ZV;
       else
@@ -7891,7 +7892,7 @@ message2_nolog (m, nbytes, multibyte)
   struct frame *sf = SELECTED_FRAME ();
   message_enable_multibyte = multibyte;
 
-  if (noninteractive)
+  if (FRAME_INITIAL_P (sf))
     {
       if (noninteractive_need_newline)
        putc ('\n', stderr);
@@ -7990,7 +7991,7 @@ message3_nolog (m, nbytes, multibyte)
   struct frame *sf = SELECTED_FRAME ();
   message_enable_multibyte = multibyte;
 
-  if (noninteractive)
+  if (FRAME_INITIAL_P (sf))
     {
       if (noninteractive_need_newline)
        putc ('\n', stderr);
@@ -8088,7 +8089,7 @@ message_with_string (m, string, log)
            putc ('\n', stderr);
          noninteractive_need_newline = 0;
          fprintf (stderr, m, SDATA (string));
-         if (cursor_in_echo_area == 0)
+         if (!cursor_in_echo_area)
            fprintf (stderr, "\n");
          fflush (stderr);
        }
@@ -11300,7 +11301,7 @@ redisplay_internal (preserve_echo_area)
   /* No redisplay if running in batch mode or frame is not yet fully
      initialized, or redisplay is explicitly turned off by setting
      Vinhibit_redisplay.  */
-  if (noninteractive
+  if (FRAME_INITIAL_P (SELECTED_FRAME ())
       || !NILP (Vinhibit_redisplay))
     return;
 
@@ -12636,17 +12637,15 @@ try_scrolling (window, just_this_one_p, scroll_conservatively,
   /* Compute scroll margin height in pixels.  We scroll when point is
      within this distance from the top or bottom of the window.  */
   if (scroll_margin > 0)
-    {
-      this_scroll_margin = min (scroll_margin, WINDOW_TOTAL_LINES (w) / 4);
-      this_scroll_margin *= FRAME_LINE_HEIGHT (f);
-    }
+    this_scroll_margin = min (scroll_margin, WINDOW_TOTAL_LINES (w) / 4)
+      * FRAME_LINE_HEIGHT (f);
   else
     this_scroll_margin = 0;
 
   /* Force scroll_conservatively to have a reasonable value, to avoid
-     overflow while computing how much to scroll.  Note that it's
-     fairly common for users to supply scroll-conservatively equal to
-     `most-positive-fixnum', which can be larger than INT_MAX.  */
+     overflow while computing how much to scroll.  Note that the user
+     can supply scroll-conservatively equal to `most-positive-fixnum',
+     which can be larger than INT_MAX.  */
   if (scroll_conservatively > scroll_limit)
     {
       scroll_conservatively = scroll_limit;
@@ -12668,7 +12667,7 @@ try_scrolling (window, just_this_one_p, scroll_conservatively,
 
  too_near_end:
 
-  /* Decide whether we have to scroll down.  */
+  /* Decide whether to scroll down.  */
   if (PT > CHARPOS (startp))
     {
       int scroll_margin_y;
@@ -12683,17 +12682,17 @@ try_scrolling (window, just_this_one_p, scroll_conservatively,
 
       if (PT > CHARPOS (it.current.pos))
        {
-         /* Point is in the scroll margin at the bottom of the
-            window, or below.  Compute the distance from the scroll
-            margin to PT, and give up if the distance is greater than
-            scroll_max.  */
-         move_it_to (&it, PT, -1, it.last_visible_y - 1, -1,
-                     MOVE_TO_POS | MOVE_TO_Y);
+         int y0 = line_bottom_y (&it);
 
-         /* To make point visible, we must move the window start down
-            so that the cursor line is visible, which means we have
-            to add in the height of the cursor line.  */
-         dy = line_bottom_y (&it) - scroll_margin_y;
+         /* Compute the distance from the scroll margin to PT
+            (including the height of the cursor line).  Moving the
+            iterator unconditionally to PT can be slow if PT is far
+            away, so stop 10 lines past the window bottom (is there a
+            way to do the right thing quickly?).  */
+         move_it_to (&it, PT, -1,
+                     it.last_visible_y + 10 * FRAME_LINE_HEIGHT (f),
+                     -1, MOVE_TO_POS | MOVE_TO_Y);
+         dy = line_bottom_y (&it) - y0;
 
          if (dy > scroll_max)
            return SCROLLING_FAILED;
@@ -12704,14 +12703,11 @@ try_scrolling (window, just_this_one_p, scroll_conservatively,
 
   if (scroll_down_p)
     {
-      /* Move the window start down.  If scrolling conservatively,
-        move it just enough down to make point visible.  If
-        scroll_step is set, move it down by scroll_step.  */
-      start_display (&it, w, startp);
-
+      /* Point is in or below the bottom scroll margin, so move the
+        window start down.  If scrolling conservatively, move it just
+        enough down to make point visible.  If scroll_step is set,
+        move it down by scroll_step.  */
       if (scroll_conservatively)
-       /* Set AMOUNT_TO_SCROLL to at least one line,
-          and at most scroll_conservatively lines.  */
        amount_to_scroll
          = min (max (dy, FRAME_LINE_HEIGHT (f)),
                 FRAME_LINE_HEIGHT (f) * scroll_conservatively);
@@ -12733,10 +12729,10 @@ try_scrolling (window, just_this_one_p, scroll_conservatively,
       if (amount_to_scroll <= 0)
        return SCROLLING_FAILED;
 
-      /* If moving by amount_to_scroll leaves STARTP unchanged,
-        move it down one screen line.  */
-
+      start_display (&it, w, startp);
       move_it_vertically (&it, amount_to_scroll);
+
+      /* If STARTP is unchanged, move it down another screen line.  */
       if (CHARPOS (it.current.pos) == CHARPOS (startp))
        move_it_by_lines (&it, 1, 1);
       startp = it.current.pos;
@@ -14398,13 +14394,6 @@ try_window_reusing_current_matrix (w)
        if (display_line (&it))
          last_text_row = it.glyph_row - 1;
 
-      /* Give up If point isn't in a row displayed or reused.  */
-      if (w->cursor.vpos < 0)
-       {
-         clear_glyph_matrix (w->desired_matrix);
-         return 0;
-       }
-
       /* If point is in a reused row, adjust y and vpos of the cursor
         position.  */
       if (pt_row)
@@ -14413,6 +14402,16 @@ try_window_reusing_current_matrix (w)
          w->cursor.y -= first_reusable_row->y - start_row->y;
        }
 
+      /* Give up if point isn't in a row displayed or reused.  (This
+        also handles the case where w->cursor.vpos < nrows_scrolled
+        after the calls to display_line, which can happen with scroll
+        margins.  See bug#1295.)  */
+      if (w->cursor.vpos < 0)
+       {
+         clear_glyph_matrix (w->desired_matrix);
+         return 0;
+       }
+
       /* Scroll the display.  */
       run.current_y = first_reusable_row->y;
       run.desired_y = WINDOW_HEADER_LINE_HEIGHT (w);
@@ -25064,9 +25063,10 @@ all the functions in the list are called, with the frame as argument.  */);
 
   DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions,
     doc: /* List of functions to call before redisplaying a window with scrolling.
-Each function is called with two arguments, the window
-and its new display-start position.  Note that the value of `window-end'
-is not valid when these functions are called.  */);
+Each function is called with two arguments, the window and its new
+display-start position.  Note that these functions are also called by
+`set-window-buffer'.  Also note that the value of `window-end' is not
+valid when these functions are called.  */);
   Vwindow_scroll_functions = Qnil;
 
   DEFVAR_LISP ("window-text-change-functions",