]> code.delx.au - gnu-emacs/blobdiff - src/scroll.c
*** empty log message ***
[gnu-emacs] / src / scroll.c
index df40d33c5e5256606e808eb05d11c940b6368e65..64dfd9aef251d6ee69c38944126c903e343f90e9 100644 (file)
@@ -237,6 +237,7 @@ do_scrolling (screen, matrix, window_size, unchanged_at_top)
   register struct matrix_elt *p;
   register int i, j;
   register struct screen_glyphs *current_screen;
+  /* temp_screen->enable[i] means line i has been moved to current_screen.  */
   register struct screen_glyphs *temp_screen;
   struct queue { int count, pos; } *queue;
   int offset = unchanged_at_top;
@@ -339,7 +340,7 @@ do_scrolling (screen, matrix, window_size, unchanged_at_top)
         that were discarded during the deletions.
         Those are the ones for which temp_screen->enable was not set.  */
       tem = queue[i].pos;
-      for (j = tem + queue[i].count - 1; j > tem; j--)
+      for (j = tem + queue[i].count - 1; j >= tem; j--)
        {
          current_screen->enable[j] = 0;
          while (temp_screen->enable[next])
@@ -447,14 +448,14 @@ scroll_cost (screen, from, to, amount)
   int offset;
   int height = SCREEN_HEIGHT (screen);
 
-  if (amount > 0)
-    limit += amount;
-  if (! scroll_region_ok)
-    limit = height;
-
   if (amount == 0)
     return 0;
 
+  if (! scroll_region_ok)
+    limit = height;
+  else if (amount > 0)
+    limit += amount;
+
   if (amount < 0)
     {
       int temp = to;
@@ -487,11 +488,11 @@ line_ins_del (screen, ov1, pf1, ovn, pfn, ov, mf)
   register int insert_overhead = ov1 * 10;
   register int next_insert_cost = ovn * 10;
 
-  for (i = 0; i <= screen_height; i++)
+  for (i = screen_height-1; i >= 0; i--)
     {
-      mf[screen_height - i] = next_insert_cost / 10;
+      mf[i] = next_insert_cost / 10;
       next_insert_cost += pfn;
-      ov[screen_height - i] = (insert_overhead + next_insert_cost) / 10;
+      ov[i] = (insert_overhead + next_insert_cost) / 10;
       insert_overhead += pf1;
     }
 }
@@ -568,29 +569,29 @@ do_line_insertion_deletion_costs (screen,
 {
   if (SCREEN_INSERT_COST (screen) != 0)
     {
-      SCREEN_INSERT_COST (screen)
-       (int *) xrealloc (SCREEN_INSERT_COST (screen),
-                           SCREEN_HEIGHT (screen) * sizeof (int));
-      SCREEN_DELETEN_COST (screen)
-       (int *) xrealloc (SCREEN_DELETEN_COST (screen),
-                           SCREEN_HEIGHT (screen) * sizeof (int));
-      SCREEN_INSERTN_COST (screen)
-       (int *) xrealloc (SCREEN_INSERTN_COST (screen),
-                           SCREEN_HEIGHT (screen) * sizeof (int));
-      SCREEN_DELETE_COST (screen)
-       (int *) xrealloc (SCREEN_DELETE_COST (screen),
-                           SCREEN_HEIGHT (screen) * sizeof (int));
+      SCREEN_INSERT_COST (screen) =
+       (int *) xrealloc (SCREEN_INSERT_COST (screen),
+                         SCREEN_HEIGHT (screen) * sizeof (int));
+      SCREEN_DELETEN_COST (screen) =
+       (int *) xrealloc (SCREEN_DELETEN_COST (screen),
+                         SCREEN_HEIGHT (screen) * sizeof (int));
+      SCREEN_INSERTN_COST (screen) =
+       (int *) xrealloc (SCREEN_INSERTN_COST (screen),
+                         SCREEN_HEIGHT (screen) * sizeof (int));
+      SCREEN_DELETE_COST (screen) =
+       (int *) xrealloc (SCREEN_DELETE_COST (screen),
+                         SCREEN_HEIGHT (screen) * sizeof (int));
     }
   else
     {
-      SCREEN_INSERT_COST (screen)
-       (int *) xmalloc (SCREEN_HEIGHT (screen) * sizeof (int));
-      SCREEN_DELETEN_COST (screen)
-       (int *) xmalloc (SCREEN_HEIGHT (screen) * sizeof (int));
-      SCREEN_INSERTN_COST (screen)
-       (int *) xmalloc (SCREEN_HEIGHT (screen) * sizeof (int));
-      SCREEN_DELETE_COST (screen)
-       (int *) xmalloc (SCREEN_HEIGHT (screen) * sizeof (int));
+      SCREEN_INSERT_COST (screen) =
+       (int *) xmalloc (SCREEN_HEIGHT (screen) * sizeof (int));
+      SCREEN_DELETEN_COST (screen) =
+       (int *) xmalloc (SCREEN_HEIGHT (screen) * sizeof (int));
+      SCREEN_INSERTN_COST (screen) =
+       (int *) xmalloc (SCREEN_HEIGHT (screen) * sizeof (int));
+      SCREEN_DELETE_COST (screen) = 
+       (int *) xmalloc (SCREEN_HEIGHT (screen) * sizeof (int));
     }
 
   ins_del_costs (screen,