]> code.delx.au - gnu-emacs/blobdiff - src/scroll.c
*** empty log message ***
[gnu-emacs] / src / scroll.c
index fcb2e0e791a7e543368bfb12c63c8e828771a6a4..6e633d4e60b00352f02ca688de26fbf580574591 100644 (file)
@@ -1,5 +1,6 @@
 /* Calculate what line insertion or deletion to do, and do it,
 /* Calculate what line insertion or deletion to do, and do it,
-   Copyright (C) 1985, 1986, 1990, 1993, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1990, 1993, 1994, 2002, 2003, 2004,
+                 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 
 This file is part of GNU Emacs.
 
@@ -15,8 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 
 #include <config.h>
 
 
 #include <config.h>
@@ -25,12 +26,10 @@ Boston, MA 02111-1307, USA.  */
 #include "termchar.h"
 #include "lisp.h"
 #include "dispextern.h"
 #include "termchar.h"
 #include "lisp.h"
 #include "dispextern.h"
+#include "keyboard.h"
 #include "frame.h"
 #include "window.h"
 
 #include "frame.h"
 #include "window.h"
 
-#define max(a, b) ((a) > (b) ? (a) : (b))
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
 /* All costs measured in characters.
    So no cost can exceed the area of a frame, measured in characters.
    Let's hope this is never more than 1000000 characters.  */
 /* All costs measured in characters.
    So no cost can exceed the area of a frame, measured in characters.
    Let's hope this is never more than 1000000 characters.  */
@@ -91,14 +90,14 @@ calculate_scrolling (frame, matrix, window_size, lines_below,
      FRAME_PTR frame;
      /* matrix is of size window_size + 1 on each side.  */
      struct matrix_elt *matrix;
      FRAME_PTR frame;
      /* matrix is of size window_size + 1 on each side.  */
      struct matrix_elt *matrix;
-     int window_size;
+     int window_size, lines_below;
      int *draw_cost;
      int *old_hash;
      int *new_hash;
      int free_at_end;
 {
   register int i, j;
      int *draw_cost;
      int *old_hash;
      int *new_hash;
      int free_at_end;
 {
   register int i, j;
-  int frame_height = FRAME_HEIGHT (frame);
+  int frame_lines = FRAME_LINES (frame);
   register struct matrix_elt *p, *p1;
   register int cost, cost1;
 
   register struct matrix_elt *p, *p1;
   register int cost, cost1;
 
@@ -107,18 +106,18 @@ calculate_scrolling (frame, matrix, window_size, lines_below,
      at the i'th line of the lines we are considering,
      where I is origin 1 (as it is below).  */
   int *first_insert_cost
      at the i'th line of the lines we are considering,
      where I is origin 1 (as it is below).  */
   int *first_insert_cost
-    = &FRAME_INSERT_COST (frame)[frame_height - 1 - lines_moved];
+    = &FRAME_INSERT_COST (frame)[frame_lines - 1 - lines_moved];
   int *first_delete_cost
   int *first_delete_cost
-    = &FRAME_DELETE_COST (frame)[frame_height - 1 - lines_moved];
+    = &FRAME_DELETE_COST (frame)[frame_lines - 1 - lines_moved];
   int *next_insert_cost
   int *next_insert_cost
-    = &FRAME_INSERTN_COST (frame)[frame_height - 1 - lines_moved];
+    = &FRAME_INSERTN_COST (frame)[frame_lines - 1 - lines_moved];
   int *next_delete_cost
   int *next_delete_cost
-    = &FRAME_DELETEN_COST (frame)[frame_height - 1 - lines_moved];
+    = &FRAME_DELETEN_COST (frame)[frame_lines - 1 - lines_moved];
 
   /* Discourage long scrolls on fast lines.
      Don't scroll nearly a full frame height unless it saves
      at least 1/4 second.  */
 
   /* Discourage long scrolls on fast lines.
      Don't scroll nearly a full frame height unless it saves
      at least 1/4 second.  */
-  int extra_cost = baud_rate / (10 * 4 * FRAME_HEIGHT (frame));
+  int extra_cost = baud_rate / (10 * 4 * FRAME_LINES (frame));
 
   if (baud_rate <= 0)
     extra_cost = 1;
 
   if (baud_rate <= 0)
     extra_cost = 1;
@@ -234,13 +233,13 @@ calculate_scrolling (frame, matrix, window_size, lines_below,
 /* Perform insert-lines and delete-lines operations on CURRENT_MATRIX
    according to the costs in MATRIX, using the general scrolling
    method that is used if the terminal does not support the setting of
 /* Perform insert-lines and delete-lines operations on CURRENT_MATRIX
    according to the costs in MATRIX, using the general scrolling
    method that is used if the terminal does not support the setting of
-   scroll windows (scroll_region_ok == 0).  
+   scroll windows (scroll_region_ok == 0).
 
    WINDOW_SIZE is the number of lines being considered for scrolling
    and UNCHANGED_AT_TOP is the vpos of the first line being
    considered.  These two arguments can specify any contiguous range
    of lines.  */
 
    WINDOW_SIZE is the number of lines being considered for scrolling
    and UNCHANGED_AT_TOP is the vpos of the first line being
    considered.  These two arguments can specify any contiguous range
    of lines.  */
+
 static void
 do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
      struct glyph_matrix *current_matrix;
 static void
 do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
      struct glyph_matrix *current_matrix;
@@ -260,7 +259,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
   struct queue *queue_start
     = (struct queue *) alloca (current_matrix->nrows * sizeof (struct queue));
   struct queue *queue = queue_start;
   struct queue *queue_start
     = (struct queue *) alloca (current_matrix->nrows * sizeof (struct queue));
   struct queue *queue = queue_start;
-  
+
   char *retained_p = (char *) alloca (window_size * sizeof (char));
   int *copy_from = (int *) alloca (window_size * sizeof (int));
 
   char *retained_p = (char *) alloca (window_size * sizeof (char));
   int *copy_from = (int *) alloca (window_size * sizeof (int));
 
@@ -285,7 +284,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
   while (i > 0 || j > 0)
     {
       p = matrix + i * (window_size + 1) + j;
   while (i > 0 || j > 0)
     {
       p = matrix + i * (window_size + 1) + j;
-      
+
       if (p->insertcost < p->writecost && p->insertcost < p->deletecost)
        {
          /* Insert should be done at vpos i-1, plus maybe some before.
       if (p->insertcost < p->writecost && p->insertcost < p->deletecost)
        {
          /* Insert should be done at vpos i-1, plus maybe some before.
@@ -367,7 +366,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
            }
        }
       while (queue > queue_start);
            }
        }
       while (queue > queue_start);
-         
+
     }
 
   for (k = 0; k < window_size; ++k)
     }
 
   for (k = 0; k < window_size; ++k)
@@ -379,7 +378,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
 
   /* Some sanity checks if GLYPH_DEBUG != 0.  */
   CHECK_MATRIX (current_matrix);
 
   /* Some sanity checks if GLYPH_DEBUG != 0.  */
   CHECK_MATRIX (current_matrix);
-  
+
   if (terminal_window_p)
     set_terminal_window (0);
 }
   if (terminal_window_p)
     set_terminal_window (0);
 }
@@ -432,7 +431,7 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
      FRAME_PTR frame;
      /* matrix is of size window_size + 1 on each side.  */
      struct matrix_elt *matrix;
      FRAME_PTR frame;
      /* matrix is of size window_size + 1 on each side.  */
      struct matrix_elt *matrix;
-     int window_size;
+     int window_size, lines_below;
      int *draw_cost;
      int *old_draw_cost;
      int *old_hash;
      int *draw_cost;
      int *old_draw_cost;
      int *old_hash;
@@ -440,27 +439,27 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
      int free_at_end;
 {
   register int i, j;
      int free_at_end;
 {
   register int i, j;
-  int frame_height = FRAME_HEIGHT (frame);
+  int frame_lines = FRAME_LINES (frame);
   register struct matrix_elt *p, *p1;
   register int cost, cost1, delta;
 
   /* first_insert_cost[-I] is the cost of doing the first insert-line
      at a position I lines above the bottom line in the scroll window. */
   int *first_insert_cost
   register struct matrix_elt *p, *p1;
   register int cost, cost1, delta;
 
   /* first_insert_cost[-I] is the cost of doing the first insert-line
      at a position I lines above the bottom line in the scroll window. */
   int *first_insert_cost
-    = &FRAME_INSERT_COST (frame)[frame_height - 1];
+    = &FRAME_INSERT_COST (frame)[frame_lines - 1];
   int *first_delete_cost
   int *first_delete_cost
-    = &FRAME_DELETE_COST (frame)[frame_height - 1];
+    = &FRAME_DELETE_COST (frame)[frame_lines - 1];
   int *next_insert_cost
   int *next_insert_cost
-    = &FRAME_INSERTN_COST (frame)[frame_height - 1];
+    = &FRAME_INSERTN_COST (frame)[frame_lines - 1];
   int *next_delete_cost
   int *next_delete_cost
-    = &FRAME_DELETEN_COST (frame)[frame_height - 1];
+    = &FRAME_DELETEN_COST (frame)[frame_lines - 1];
 
   int scroll_overhead;
 
   /* Discourage long scrolls on fast lines.
      Don't scroll nearly a full frame height unless it saves
      at least 1/4 second.  */
 
   int scroll_overhead;
 
   /* Discourage long scrolls on fast lines.
      Don't scroll nearly a full frame height unless it saves
      at least 1/4 second.  */
-  int extra_cost = baud_rate / (10 * 4 * FRAME_HEIGHT (frame));
+  int extra_cost = baud_rate / (10 * 4 * FRAME_LINES (frame));
 
   if (baud_rate <= 0)
     extra_cost = 1;
 
   if (baud_rate <= 0)
     extra_cost = 1;
@@ -564,7 +563,7 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
                   To reduce the cumulative effects of rounding error, we
                   vary the position at which the difference is computed. */
                cost1 += first_insert_cost[-j] - first_insert_cost[1-j] +
                   To reduce the cumulative effects of rounding error, we
                   vary the position at which the difference is computed. */
                cost1 += first_insert_cost[-j] - first_insert_cost[1-j] +
-                 (delta-1) * (next_insert_cost[-j] - next_insert_cost[1-j]); 
+                 (delta-1) * (next_insert_cost[-j] - next_insert_cost[1-j]);
              }
            else
              {
              }
            else
              {
@@ -572,7 +571,7 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
                cost += scroll_overhead + first_delete_cost[-delta] +
                  (delta-1) * (next_delete_cost[-delta] + extra_cost);
                cost1 += first_delete_cost[-i] - first_delete_cost[1-i] +
                cost += scroll_overhead + first_delete_cost[-delta] +
                  (delta-1) * (next_delete_cost[-delta] + extra_cost);
                cost1 += first_delete_cost[-i] - first_delete_cost[1-i] +
-                 (delta-1) * ( next_delete_cost[-i] - next_delete_cost[1-i]); 
+                 (delta-1) * ( next_delete_cost[-i] - next_delete_cost[1-i]);
              }
            if (cost1 < cost)
              {
              }
            if (cost1 < cost)
              {
@@ -643,7 +642,7 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
    and UNCHANGED_AT_TOP is the vpos of the first line being
    considered.  These two arguments can specify any contiguous range
    of lines.
    and UNCHANGED_AT_TOP is the vpos of the first line being
    considered.  These two arguments can specify any contiguous range
    of lines.
+
    In the direct scrolling method, a new scroll window is selected
    before each insertion or deletion, so that groups of lines can be
    scrolled directly to their final vertical positions.  This method
    In the direct scrolling method, a new scroll window is selected
    before each insertion or deletion, so that groups of lines can be
    scrolled directly to their final vertical positions.  This method
@@ -703,11 +702,11 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
      without also decrementing i, this corresponds to omitting these
      lines in the new rows, i.e. rows are deleted.  */
   i = j = window_size;
      without also decrementing i, this corresponds to omitting these
      lines in the new rows, i.e. rows are deleted.  */
   i = j = window_size;
-  
+
   while (i > 0 || j > 0)
     {
       p = cost_matrix + i * (window_size + 1) + j;
   while (i > 0 || j > 0)
     {
       p = cost_matrix + i * (window_size + 1) + j;
-      
+
       if (p->insertcost < p->writecost
          && p->insertcost < p->deletecost
          && (write_follows_p || i < j))
       if (p->insertcost < p->writecost
          && p->insertcost < p->deletecost
          && (write_follows_p || i < j))
@@ -719,7 +718,7 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
          queue->window = i;
          queue->pos = i - p->insertcount;
          ++queue;
          queue->window = i;
          queue->pos = i - p->insertcount;
          ++queue;
-         
+
          i -= p->insertcount;
          write_follows_p = 0;
        }
          i -= p->insertcount;
          write_follows_p = 0;
        }
@@ -738,7 +737,7 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
             place they belong.  */
          int n_to_write = p->writecount;
          write_follows_p = 1;
             place they belong.  */
          int n_to_write = p->writecount;
          write_follows_p = 1;
-         xassert (n_to_write > 0); 
+         xassert (n_to_write > 0);
 
          if (i > j)
            {
 
          if (i > j)
            {
@@ -824,7 +823,7 @@ scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
     {
       calculate_direct_scrolling (frame, matrix, window_size,
                                  unchanged_at_bottom,
     {
       calculate_direct_scrolling (frame, matrix, window_size,
                                  unchanged_at_bottom,
-                                 draw_cost, old_draw_cost, 
+                                 draw_cost, old_draw_cost,
                                  old_hash, new_hash, free_at_end);
       do_direct_scrolling (frame->current_matrix,
                           matrix, window_size, unchanged_at_top);
                                  old_hash, new_hash, free_at_end);
       do_direct_scrolling (frame->current_matrix,
                           matrix, window_size, unchanged_at_top);
@@ -911,7 +910,7 @@ scroll_cost (frame, from, to, amount)
      will not be involved in actual motion.  */
   int limit = to;
   int offset;
      will not be involved in actual motion.  */
   int limit = to;
   int offset;
-  int height = FRAME_HEIGHT (frame);
+  int height = FRAME_LINES (frame);
 
   if (amount == 0)
     return 0;
 
   if (amount == 0)
     return 0;
@@ -949,11 +948,11 @@ line_ins_del (frame, ov1, pf1, ovn, pfn, ov, mf)
      register int *ov, *mf;
 {
   register int i;
      register int *ov, *mf;
 {
   register int i;
-  register int frame_height = FRAME_HEIGHT (frame);
+  register int frame_lines = FRAME_LINES (frame);
   register int insert_overhead = ov1 * 10;
   register int next_insert_cost = ovn * 10;
 
   register int insert_overhead = ov1 * 10;
   register int next_insert_cost = ovn * 10;
 
-  for (i = frame_height-1; i >= 0; i--)
+  for (i = frame_lines-1; i >= 0; i--)
     {
       mf[i] = next_insert_cost / 10;
       next_insert_cost += pfn;
     {
       mf[i] = next_insert_cost / 10;
       next_insert_cost += pfn;
@@ -1002,12 +1001,12 @@ ins_del_costs (frame,
    only) and those that must repeatedly insert one line.
 
    The cost to insert N lines at line L is
    only) and those that must repeatedly insert one line.
 
    The cost to insert N lines at line L is
-           [tt.t_ILov  + (frame_height + 1 - L) * tt.t_ILpf] +
-       N * [tt.t_ILnov + (frame_height + 1 - L) * tt.t_ILnpf]
+           [tt.t_ILov  + (frame_lines + 1 - L) * tt.t_ILpf] +
+       N * [tt.t_ILnov + (frame_lines + 1 - L) * tt.t_ILnpf]
 
    ILov represents the basic insert line overhead.  ILpf is the padding
    required to allow the terminal time to move a line: insertion at line
 
    ILov represents the basic insert line overhead.  ILpf is the padding
    required to allow the terminal time to move a line: insertion at line
-   L changes (frame_height + 1 - L) lines.
+   L changes (frame_lines + 1 - L) lines.
 
    The first bracketed expression above is the overhead; the second is
    the multiply factor.  Both are dependent only on the position at
 
    The first bracketed expression above is the overhead; the second is
    the multiply factor.  Both are dependent only on the position at
@@ -1037,27 +1036,27 @@ do_line_insertion_deletion_costs (frame,
     {
       FRAME_INSERT_COST (frame) =
        (int *) xrealloc (FRAME_INSERT_COST (frame),
     {
       FRAME_INSERT_COST (frame) =
        (int *) xrealloc (FRAME_INSERT_COST (frame),
-                         FRAME_HEIGHT (frame) * sizeof (int));
+                         FRAME_LINES (frame) * sizeof (int));
       FRAME_DELETEN_COST (frame) =
        (int *) xrealloc (FRAME_DELETEN_COST (frame),
       FRAME_DELETEN_COST (frame) =
        (int *) xrealloc (FRAME_DELETEN_COST (frame),
-                         FRAME_HEIGHT (frame) * sizeof (int));
+                         FRAME_LINES (frame) * sizeof (int));
       FRAME_INSERTN_COST (frame) =
        (int *) xrealloc (FRAME_INSERTN_COST (frame),
       FRAME_INSERTN_COST (frame) =
        (int *) xrealloc (FRAME_INSERTN_COST (frame),
-                         FRAME_HEIGHT (frame) * sizeof (int));
+                         FRAME_LINES (frame) * sizeof (int));
       FRAME_DELETE_COST (frame) =
        (int *) xrealloc (FRAME_DELETE_COST (frame),
       FRAME_DELETE_COST (frame) =
        (int *) xrealloc (FRAME_DELETE_COST (frame),
-                         FRAME_HEIGHT (frame) * sizeof (int));
+                         FRAME_LINES (frame) * sizeof (int));
     }
   else
     {
       FRAME_INSERT_COST (frame) =
     }
   else
     {
       FRAME_INSERT_COST (frame) =
-       (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
+       (int *) xmalloc (FRAME_LINES (frame) * sizeof (int));
       FRAME_DELETEN_COST (frame) =
       FRAME_DELETEN_COST (frame) =
-       (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
+       (int *) xmalloc (FRAME_LINES (frame) * sizeof (int));
       FRAME_INSERTN_COST (frame) =
       FRAME_INSERTN_COST (frame) =
-       (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
-      FRAME_DELETE_COST (frame) = 
-       (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
+       (int *) xmalloc (FRAME_LINES (frame) * sizeof (int));
+      FRAME_DELETE_COST (frame) =
+       (int *) xmalloc (FRAME_LINES (frame) * sizeof (int));
     }
 
   ins_del_costs (frame,
     }
 
   ins_del_costs (frame,
@@ -1071,3 +1070,6 @@ do_line_insertion_deletion_costs (frame,
                 FRAME_DELETE_COST (frame), FRAME_DELETEN_COST (frame),
                 coefficient);
 }
                 FRAME_DELETE_COST (frame), FRAME_DELETEN_COST (frame),
                 coefficient);
 }
+
+/* arch-tag: cdb7149c-48e7-4793-a948-2786c8e45485
+   (do not change this comment) */