* dispnew.c (scrolling_window): Return 1 if we scrolled,
[bpt/emacs.git] / src / dispnew.c
index 061058b..0457d65 100644 (file)
@@ -1,7 +1,5 @@
 /* Updating of data structures for redisplay.
-   Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
-                 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1985-1988, 1993-1995, 1997-2011 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -123,11 +121,12 @@ static int required_matrix_width (struct window *);
 static void allocate_matrices_for_window_redisplay (struct window *);
 static int realloc_glyph_pool (struct glyph_pool *, struct dim);
 static void adjust_frame_glyphs (struct frame *);
-struct glyph_matrix *new_glyph_matrix (struct glyph_pool *);
+static struct glyph_matrix *new_glyph_matrix (struct glyph_pool *);
 static void free_glyph_matrix (struct glyph_matrix *);
 static void adjust_glyph_matrix (struct window *, struct glyph_matrix *,
                                  int, int, struct dim);
 static void change_frame_size_1 (struct frame *, int, int, int, int, int);
+static void increment_row_positions (struct glyph_row *, EMACS_INT, EMACS_INT);
 static void swap_glyph_pointers (struct glyph_row *, struct glyph_row *);
 #if GLYPH_DEBUG
 static int glyph_row_slice_p (struct glyph_row *, struct glyph_row *);
@@ -165,6 +164,7 @@ static void mirror_line_dance (struct window *, int, int, int *, char *);
 static int update_window_tree (struct window *, int);
 static int update_window (struct window *, int);
 static int update_frame_1 (struct frame *, int, int);
+static int scrolling (struct frame *);
 static void set_window_cursor_after_update (struct window *);
 static void adjust_frame_glyphs_for_window_redisplay (struct frame *);
 static void adjust_frame_glyphs_for_frame_redisplay (struct frame *);
@@ -214,7 +214,7 @@ struct frame *last_nonminibuf_frame;
 
 /* 1 means SIGWINCH happened when not safe.  */
 
-int delayed_size_change;
+static int delayed_size_change;
 
 /* 1 means glyph initialization has been completed at startup.  */
 
@@ -236,8 +236,8 @@ struct glyph space_glyph;
 /* Counts of allocated structures.  These counts serve to diagnose
    memory leaks and double frees.  */
 
-int glyph_matrix_count;
-int glyph_pool_count;
+static int glyph_matrix_count;
+static int glyph_pool_count;
 
 /* If non-null, the frame whose frame matrices are manipulated.  If
    null, window matrices are worked on.  */
@@ -312,7 +312,7 @@ add_window_display_history (struct window *w, char *msg, int paused_p)
           w,
           ((BUFFERP (w->buffer)
             && STRINGP (XBUFFER (w->buffer)->name))
-           ? (char *) SDATA (XBUFFER (w->buffer)->name)
+           ? SSDATA (XBUFFER (w->buffer)->name)
            : "???"),
           paused_p ? " ***paused***" : "");
   strcat (buf, msg);
@@ -385,7 +385,7 @@ safe_bcopy (const char *from, char *to, int size)
    member `pool' of the glyph matrix structure returned is set to
    POOL, the structure is otherwise zeroed.  */
 
-struct glyph_matrix *
+static struct glyph_matrix *
 new_glyph_matrix (struct glyph_pool *pool)
 {
   struct glyph_matrix *result;
@@ -1023,7 +1023,7 @@ blank_row (struct window *w, struct glyph_row *row, int y)
    the used count of the text area is zero.  Such rows display line
    ends.  */
 
-void
+static void
 increment_row_positions (struct glyph_row *row,
                         EMACS_INT delta, EMACS_INT delta_bytes)
 {
@@ -1131,32 +1131,6 @@ copy_row_except_pointers (struct glyph_row *to, struct glyph_row *from)
 }
 
 
-/* Copy contents of glyph row FROM to glyph row TO.  Glyph pointers in
-   TO and FROM are left unchanged.  Glyph contents are copied from the
-   glyph memory of FROM to the glyph memory of TO.  Increment buffer
-   positions in row TO by DELTA/ DELTA_BYTES.  */
-
-void
-copy_glyph_row_contents (struct glyph_row *to, struct glyph_row *from,
-                        EMACS_INT delta, EMACS_INT delta_bytes)
-{
-  int area;
-
-  /* This is like a structure assignment TO = FROM, except that
-     glyph pointers in the rows are left unchanged.  */
-  copy_row_except_pointers (to, from);
-
-  /* Copy glyphs from FROM to TO.  */
-  for (area = 0; area < LAST_AREA; ++area)
-    if (from->used[area])
-      memcpy (to->glyphs[area], from->glyphs[area],
-             from->used[area] * sizeof (struct glyph));
-
-  /* Increment buffer positions in TO by DELTA.  */
-  increment_row_positions (to, delta, delta_bytes);
-}
-
-
 /* Assign glyph row FROM to glyph row TO.  This works like a structure
    assignment TO = FROM, except that glyph pointers are not copied but
    exchanged between TO and FROM.  Pointers must be exchanged to avoid
@@ -1325,13 +1299,11 @@ line_draw_cost (struct glyph_matrix *matrix, int vpos)
 
 
 /* Test two glyph rows A and B for equality.  Value is non-zero if A
-   and B have equal contents.  W is the window to which the glyphs
-   rows A and B belong.  It is needed here to test for partial row
-   visibility.  MOUSE_FACE_P non-zero means compare the mouse_face_p
-   flags of A and B, too.  */
+   and B have equal contents.  MOUSE_FACE_P non-zero means compare the
+   mouse_face_p flags of A and B, too.  */
 
 static INLINE int
-row_equal_p (struct window *w, struct glyph_row *a, struct glyph_row *b, int mouse_face_p)
+row_equal_p (struct glyph_row *a, struct glyph_row *b, int mouse_face_p)
 {
   if (a == b)
     return 1;
@@ -2225,8 +2197,6 @@ adjust_frame_glyphs_for_frame_redisplay (struct frame *f)
 static void
 adjust_frame_glyphs_for_window_redisplay (struct frame *f)
 {
-  struct window *w;
-
   xassert (FRAME_WINDOW_P (f) && FRAME_LIVE_P (f));
 
   /* Allocate/reallocate window matrices.  */
@@ -2238,6 +2208,7 @@ adjust_frame_glyphs_for_window_redisplay (struct frame *f)
 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
   {
     /* Allocate a dummy window if not already done.  */
+    struct window *w;
     if (NILP (f->menu_bar_window))
       {
        f->menu_bar_window = make_window ();
@@ -2260,23 +2231,26 @@ adjust_frame_glyphs_for_window_redisplay (struct frame *f)
 #endif /* HAVE_X_WINDOWS */
 
 #ifndef USE_GTK
-  /* Allocate/ reallocate matrices of the tool bar window.  If we
-     don't have a tool bar window yet, make one.  */
-  if (NILP (f->tool_bar_window))
-    {
-      f->tool_bar_window = make_window ();
+  {
+    /* Allocate/ reallocate matrices of the tool bar window.  If we
+       don't have a tool bar window yet, make one.  */
+    struct window *w;
+    if (NILP (f->tool_bar_window))
+      {
+       f->tool_bar_window = make_window ();
+       w = XWINDOW (f->tool_bar_window);
+       XSETFRAME (w->frame, f);
+       w->pseudo_window_p = 1;
+      }
+    else
       w = XWINDOW (f->tool_bar_window);
-      XSETFRAME (w->frame, f);
-      w->pseudo_window_p = 1;
-    }
-  else
-    w = XWINDOW (f->tool_bar_window);
 
-  XSETFASTINT (w->top_line, FRAME_MENU_BAR_LINES (f));
-  XSETFASTINT (w->left_col, 0);
-  XSETFASTINT (w->total_lines, FRAME_TOOL_BAR_LINES (f));
-  XSETFASTINT (w->total_cols, FRAME_TOTAL_COLS (f));
-  allocate_matrices_for_window_redisplay (w);
+    XSETFASTINT (w->top_line, FRAME_MENU_BAR_LINES (f));
+    XSETFASTINT (w->left_col, 0);
+    XSETFASTINT (w->total_lines, FRAME_TOOL_BAR_LINES (f));
+    XSETFASTINT (w->total_cols, FRAME_TOTAL_COLS (f));
+    allocate_matrices_for_window_redisplay (w);
+  }
 #endif
 }
 
@@ -2926,7 +2900,7 @@ sync_window_with_frame_matrix_rows (struct window *w)
 /* Return the window in the window tree rooted in W containing frame
    row ROW.  Value is null if none is found.  */
 
-struct window *
+static struct window *
 frame_row_to_window (struct window *w, int row)
 {
   struct window *found = NULL;
@@ -3228,21 +3202,6 @@ DEFUN ("redraw-display", Fredraw_display, Sredraw_display, 0, 0, "",
 }
 
 
-/* This is used when frame_garbaged is set.  Call Fredraw_frame on all
-   visible frames marked as garbaged.  */
-
-void
-redraw_garbaged_frames (void)
-{
-  Lisp_Object tail, frame;
-
-  FOR_EACH_FRAME (tail, frame)
-    if (FRAME_VISIBLE_P (XFRAME (frame))
-       && FRAME_GARBAGED_P (XFRAME (frame)))
-      Fredraw_frame (frame);
-}
-
-
 \f
 /***********************************************************************
                             Frame Update
@@ -3564,12 +3523,12 @@ redraw_overlapping_rows (struct window *w, int yb)
 #endif /* HAVE_WINDOW_SYSTEM */
 
 
-#ifdef GLYPH_DEBUG
+#if defined GLYPH_DEBUG && 0
 
 /* Check that no row in the current matrix of window W is enabled
    which is below what's displayed in the window.  */
 
-void
+static void
 check_current_matrix_flags (struct window *w)
 {
   int last_seen_p = 0;
@@ -3618,7 +3577,10 @@ update_window (struct window *w, int force_p)
       struct glyph_row *row, *end;
       struct glyph_row *mode_line_row;
       struct glyph_row *header_line_row;
-      int yb, changed_p = 0, mouse_face_overwritten_p = 0, n_updated;
+      int yb, changed_p = 0, mouse_face_overwritten_p = 0;
+#if ! PERIODIC_PREEMPTION_CHECKING
+      int n_updated = 0;
+#endif
 
       rif->update_window_begin_hook (w);
       yb = window_text_bottom_y (w);
@@ -3671,7 +3633,7 @@ update_window (struct window *w, int force_p)
        }
 
       /* Update the rest of the lines.  */
-      for (n_updated = 0; row < end && (force_p || !input_pending); ++row)
+      for (; row < end && (force_p || !input_pending); ++row)
        if (row->enabled_p)
          {
            int vpos = MATRIX_ROW_VPOS (row, desired_matrix);
@@ -4016,7 +3978,7 @@ update_text_area (struct window *w, int vpos)
        {
          /* Otherwise clear to the end of the old row.  Everything
             after that position should be clear already.  */
-         int x;
+         int xlim;
 
          if (i >= desired_row->used[TEXT_AREA])
            rif->cursor_to (vpos, i, desired_row->y,
@@ -4033,11 +3995,11 @@ update_text_area (struct window *w, int vpos)
                  : (w->phys_cursor.hpos >= desired_row->used[TEXT_AREA])))
            {
              w->phys_cursor_on_p = 0;
-             x = -1;
+             xlim = -1;
            }
          else
-           x = current_row->pixel_width;
-         rif->clear_end_of_line (x);
+           xlim = current_row->pixel_width;
+         rif->clear_end_of_line (xlim);
          changed_p = 1;
        }
     }
@@ -4277,17 +4239,16 @@ static int runs_size;
 
 static struct run **runs;
 
-/* Add glyph row ROW to the scrolling hash table during the scrolling
-   of window W.  */
+/* Add glyph row ROW to the scrolling hash table.  */
 
 static INLINE struct row_entry *
-add_row_entry (struct window *w, struct glyph_row *row)
+add_row_entry (struct glyph_row *row)
 {
   struct row_entry *entry;
   int i = row->hash % row_table_size;
 
   entry = row_table[i];
-  while (entry && !row_equal_p (w, entry->row, row, 1))
+  while (entry && !row_equal_p (entry->row, row, 1))
     entry = entry->next;
 
   if (entry == NULL)
@@ -4354,7 +4315,7 @@ scrolling_window (struct window *w, int header_line_p)
          && c->y == d->y
          && MATRIX_ROW_BOTTOM_Y (c) <= yb
          && MATRIX_ROW_BOTTOM_Y (d) <= yb
-         && row_equal_p (w, c, d, 1))
+         && row_equal_p (c, d, 1))
        {
          assign_row (c, d);
          d->enabled_p = 0;
@@ -4407,8 +4368,7 @@ scrolling_window (struct window *w, int header_line_p)
         && (MATRIX_ROW (current_matrix, i - 1)->y
             == MATRIX_ROW (desired_matrix, j - 1)->y)
         && !MATRIX_ROW (desired_matrix, j - 1)->redraw_fringe_bitmaps_p
-         && row_equal_p (w,
-                        MATRIX_ROW (desired_matrix, i - 1),
+         && row_equal_p (MATRIX_ROW (desired_matrix, i - 1),
                          MATRIX_ROW (current_matrix, j - 1), 1))
     --i, --j;
   last_new = i;
@@ -4469,7 +4429,7 @@ scrolling_window (struct window *w, int header_line_p)
     {
       if (MATRIX_ROW (current_matrix, i)->enabled_p)
        {
-         entry = add_row_entry (w, MATRIX_ROW (current_matrix, i));
+         entry = add_row_entry (MATRIX_ROW (current_matrix, i));
          old_lines[i] = entry;
          ++entry->old_uses;
        }
@@ -4480,7 +4440,7 @@ scrolling_window (struct window *w, int header_line_p)
   for (i = first_new; i < last_new; ++i)
     {
       xassert (MATRIX_ROW_ENABLED_P (desired_matrix, i));
-      entry = add_row_entry (w, MATRIX_ROW (desired_matrix, i));
+      entry = add_row_entry (MATRIX_ROW (desired_matrix, i));
       ++entry->new_uses;
       entry->new_line_number = i;
       new_lines[i] = entry;
@@ -4493,7 +4453,7 @@ scrolling_window (struct window *w, int header_line_p)
        && old_lines[i]->old_uses == 1
         && old_lines[i]->new_uses == 1)
       {
-       int j, k;
+       int p, q;
        int new_line = old_lines[i]->new_line_number;
        struct run *run = run_pool + run_idx++;
 
@@ -4506,33 +4466,33 @@ scrolling_window (struct window *w, int header_line_p)
        run->height = MATRIX_ROW (current_matrix, i)->height;
 
        /* Extend backward.  */
-       j = i - 1;
-       k = new_line - 1;
-       while (j > first_old
-              && k > first_new
-              && old_lines[j] == new_lines[k])
+       p = i - 1;
+       q = new_line - 1;
+       while (p > first_old
+              && q > first_new
+              && old_lines[p] == new_lines[q])
          {
-           int h = MATRIX_ROW (current_matrix, j)->height;
+           int h = MATRIX_ROW (current_matrix, p)->height;
            --run->current_vpos;
            --run->desired_vpos;
            ++run->nrows;
            run->height += h;
            run->desired_y -= h;
            run->current_y -= h;
-           --j, --k;
+           --p, --q;
          }
 
        /* Extend forward.  */
-       j = i + 1;
-       k = new_line + 1;
-       while (j < last_old
-              && k < last_new
-              && old_lines[j] == new_lines[k])
+       p = i + 1;
+       q = new_line + 1;
+       while (p < last_old
+              && q < last_new
+              && old_lines[p] == new_lines[q])
          {
-           int h = MATRIX_ROW (current_matrix, j)->height;
+           int h = MATRIX_ROW (current_matrix, p)->height;
            ++run->nrows;
            run->height += h;
-           ++j, ++k;
+           ++p, ++q;
          }
 
        /* Insert run into list of all runs.  Order runs by copied
@@ -4540,11 +4500,11 @@ scrolling_window (struct window *w, int header_line_p)
           be copied because they are already in place.  This is done
           because we can avoid calling update_window_line in this
           case.  */
-       for (j = 0; j < nruns && runs[j]->height > run->height; ++j)
+       for (p = 0; p < nruns && runs[p]->height > run->height; ++p)
          ;
-       for (k = nruns; k > j; --k)
-         runs[k] = runs[k - 1];
-       runs[j] = run;
+       for (q = nruns; q > p; --q)
+         runs[q] = runs[q - 1];
+       runs[p] = run;
        ++nruns;
 
        i += run->nrows;
@@ -4616,8 +4576,8 @@ scrolling_window (struct window *w, int header_line_p)
   for (i = 0; i < row_entry_idx; ++i)
     row_table[row_entry_pool[i].bucket] = NULL;
 
-  /* Value is > 0 to indicate that we scrolled the display.  */
-  return nruns;
+  /* Value is 1 to indicate that we scrolled the display.  */
+  return 0 < nruns;
 }
 
 
@@ -4641,7 +4601,7 @@ update_frame_1 (struct frame *f, int force_p, int inhibit_id_p)
   struct glyph_matrix *current_matrix = f->current_matrix;
   struct glyph_matrix *desired_matrix = f->desired_matrix;
   int i;
-  int pause;
+  int pause_p;
   int preempt_count = baud_rate / 2400 + 1;
 
   xassert (current_matrix && desired_matrix);
@@ -4655,7 +4615,7 @@ update_frame_1 (struct frame *f, int force_p, int inhibit_id_p)
 #if !PERIODIC_PREEMPTION_CHECKING
   if (!force_p && detect_input_pending_ignore_squeezables ())
     {
-      pause = 1;
+      pause_p = 1;
       goto do_pause;
     }
 #endif
@@ -4735,10 +4695,10 @@ update_frame_1 (struct frame *f, int force_p, int inhibit_id_p)
        }
     }
 
-  pause = (i < FRAME_LINES (f) - 1) ? i : 0;
+  pause_p = (i < FRAME_LINES (f) - 1) ? i : 0;
 
   /* Now just clean up termcap drivers and set cursor, etc.  */
-  if (!pause)
+  if (!pause_p)
     {
       if ((cursor_in_echo_area
           /* If we are showing a message instead of the mini-buffer,
@@ -4839,13 +4799,13 @@ update_frame_1 (struct frame *f, int force_p, int inhibit_id_p)
 #endif
 
   clear_desired_matrices (f);
-  return pause;
+  return pause_p;
 }
 
 
 /* Do line insertions/deletions on frame F for frame-based redisplay.  */
 
-int
+static int
 scrolling (struct frame *frame)
 {
   int unchanged_at_top, unchanged_at_bottom;
@@ -5596,7 +5556,7 @@ marginal_area_string (struct window *w, enum window_part part,
 
 #ifdef SIGWINCH
 
-SIGTYPE
+static void
 window_change_signal (int signalnum) /* If we don't have an argument, */
                                /* some compilers complain in signal calls.  */
 {
@@ -5851,7 +5811,7 @@ FILE = nil means just close any termscript file currently open.  */)
   if (! NILP (file))
     {
       file = Fexpand_file_name (file, Qnil);
-      tty->termscript = fopen (SDATA (file), "w");
+      tty->termscript = fopen (SSDATA (file), "w");
       if (tty->termscript == 0)
        report_file_error ("Opening termscript", Fcons (file, Qnil));
     }
@@ -6113,7 +6073,7 @@ pass nil for VARIABLE.  */)
     state = frame_and_buffer_state;
 
   vecp = XVECTOR (state)->contents;
-  end = vecp + XVECTOR (state)->size;
+  end = vecp + ASIZE (state);
 
   FOR_EACH_FRAME (tail, frame)
     {
@@ -6131,7 +6091,7 @@ pass nil for VARIABLE.  */)
     {
       buf = XCDR (XCAR (tail));
       /* Ignore buffers that aren't included in buffer lists.  */
-      if (SREF (XBUFFER (buf)->name, 0) == ' ')
+      if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
        continue;
       if (vecp == end)
        goto changed;
@@ -6139,7 +6099,7 @@ pass nil for VARIABLE.  */)
        goto changed;
       if (vecp == end)
        goto changed;
-      if (!EQ (*vecp++, XBUFFER (buf)->read_only))
+      if (!EQ (*vecp++, BVAR (XBUFFER (buf), read_only)))
        goto changed;
       if (vecp == end)
        goto changed;
@@ -6164,8 +6124,8 @@ pass nil for VARIABLE.  */)
   /* Reallocate the vector if data has grown to need it,
      or if it has shrunk a lot.  */
   if (! VECTORP (state)
-      || n > XVECTOR (state)->size
-      || n + 20 < XVECTOR (state)->size / 2)
+      || n > ASIZE (state)
+      || n + 20 < ASIZE (state) / 2)
     /* Add 20 extra so we grow it less often.  */
     {
       state = Fmake_vector (make_number (n + 20), Qlambda);
@@ -6186,20 +6146,20 @@ pass nil for VARIABLE.  */)
     {
       buf = XCDR (XCAR (tail));
       /* Ignore buffers that aren't included in buffer lists.  */
-      if (SREF (XBUFFER (buf)->name, 0) == ' ')
+      if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
        continue;
       *vecp++ = buf;
-      *vecp++ = XBUFFER (buf)->read_only;
+      *vecp++ = BVAR (XBUFFER (buf), read_only);
       *vecp++ = Fbuffer_modified_p (buf);
     }
   /* Fill up the vector with lambdas (always at least one).  */
   *vecp++ = Qlambda;
   while (vecp - XVECTOR (state)->contents
-        < XVECTOR (state)->size)
+        < ASIZE (state))
     *vecp++ = Qlambda;
   /* Make sure we didn't overflow the vector.  */
   if (vecp - XVECTOR (state)->contents
-      > XVECTOR (state)->size)
+      > ASIZE (state))
     abort ();
   return Qt;
 }
@@ -6592,4 +6552,3 @@ If nil, never pre-empt redisplay.  */);
       Vwindow_system_version = Qnil;
     }
 }
-