annotate src/scroll.c @ 11654:47ceabade5b2

(kbd_buffer_get_event): New arg USED_MOUSE_MENU. [USE_X_TOOLKIT]: Set *USED_MOUSE_MENU if returning menu-bar symbols. (read_char): Pass used_mouse_menu to kbd_buffer_get_event. This variable is now meaningful for toolkit menus as well as non-toolkit menus.
author Karl Heuer <kwzh@gnu.org>
date Tue, 02 May 1995 04:41:26 +0000
parents 4face60ac721
children 5c4c0319a6e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Calculate what line insertion or deletion to do, and do it,
7307
cd81dba38a49 Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 6888
diff changeset
2 Copyright (C) 1985, 1986, 1990, 1993, 1994 Free Software Foundation, Inc.
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
732
a8d94735277e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 529
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 3356
diff changeset
21 #include <config.h>
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 #include "termchar.h"
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 #include "lisp.h"
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "dispextern.h"
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
25 #include "frame.h"
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 extern struct display_line **ophys_lines;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 #define max(a, b) ((a) > (b) ? (a) : (b))
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #define min(a, b) ((a) < (b) ? (a) : (b))
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 /* All costs measured in characters.
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
33 So no cost can exceed the area of a frame, measured in characters.
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
34 Let's hope this is never more than 1000000 characters. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
36 #define INFINITY 1000000
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 struct matrix_elt
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 /* Cost of outputting through this line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 if no insert/delete is done just above it. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
42 int writecost;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 /* Cost of outputting through this line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 if an insert is done just above it. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
45 int insertcost;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 /* Cost of outputting through this line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 if a delete is done just above it. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
48 int deletecost;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 /* Number of inserts so far in this run of inserts,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 for the cost in insertcost. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
51 unsigned char insertcount;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 /* Number of deletes so far in this run of deletes,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 for the cost in deletecost. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
54 unsigned char deletecount;
10262
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
55 /* Number of writes so far since the last insert
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
56 or delete for the cost in writecost. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
57 unsigned char writecount;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 };
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60
10262
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
61 /* Determine, in matrix[i,j], the cost of updating the first j old
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
62 lines into the first i new lines using the general scrolling method.
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 This involves using insert or delete somewhere if i != j.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 For each matrix elements, three kinds of costs are recorded:
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 the smallest cost that ends with an insert, the smallest
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 cost that ends with a delete, and the smallest cost that
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 ends with neither one. These are kept separate because
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 on some terminals the cost of doing an insert varies
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 depending on whether one was just done, etc. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 /* draw_cost[VPOS] is the cost of outputting new line at VPOS.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 old_hash[VPOS] is the hash code of the old line at VPOS.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 new_hash[VPOS] is the hash code of the new line at VPOS.
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
74 Note that these are not true frame vpos's, but relative
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 to the place at which the first mismatch between old and
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 new contents appears. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 static void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
79 calculate_scrolling (frame, matrix, window_size, lines_below,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 draw_cost, old_hash, new_hash,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 free_at_end)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
82 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 /* matrix is of size window_size + 1 on each side. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 struct matrix_elt *matrix;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 int window_size;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 int *draw_cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 int *old_hash;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 int *new_hash;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 int free_at_end;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 register int i, j;
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
92 int frame_height = FRAME_HEIGHT (frame);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 register struct matrix_elt *p, *p1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 register int cost, cost1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 int lines_moved = window_size + (scroll_region_ok ? 0 : lines_below);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 /* first_insert_cost[I] is the cost of doing the first insert-line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 at the I'th line of the lines we are considering,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 where I is origin 1 (as it is below). */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 int *first_insert_cost
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
101 = &FRAME_INSERT_COST (frame)[frame_height - 1 - lines_moved];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 int *first_delete_cost
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
103 = &FRAME_DELETE_COST (frame)[frame_height - 1 - lines_moved];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 int *next_insert_cost
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
105 = &FRAME_INSERTN_COST (frame)[frame_height - 1 - lines_moved];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 int *next_delete_cost
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
107 = &FRAME_DELETEN_COST (frame)[frame_height - 1 - lines_moved];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 /* Discourage long scrolls on fast lines.
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
110 Don't scroll nearly a full frame height unless it saves
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 at least 1/4 second. */
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
112 int extra_cost = baud_rate / (10 * 4 * FRAME_HEIGHT (frame));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113
3356
09759a9653c5 (calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
114 if (baud_rate <= 0)
09759a9653c5 (calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
115 extra_cost = 1;
09759a9653c5 (calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
116
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 /* initialize the top left corner of the matrix */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 matrix->writecost = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 matrix->insertcost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 matrix->deletecost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 matrix->insertcount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 matrix->deletecount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 /* initialize the left edge of the matrix */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 cost = first_insert_cost[1] - next_insert_cost[1];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 for (i = 1; i <= window_size; i++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 p = matrix + i * (window_size + 1);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 cost += draw_cost[i] + next_insert_cost[i] + extra_cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 p->insertcost = cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 p->writecost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 p->deletecost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 p->insertcount = i;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 p->deletecount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 /* initialize the top edge of the matrix */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 cost = first_delete_cost[1] - next_delete_cost[1];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 for (j = 1; j <= window_size; j++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 cost += next_delete_cost[j];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 matrix[j].deletecost = cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 matrix[j].writecost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 matrix[j].insertcost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 matrix[j].deletecount = j;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 matrix[j].insertcount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
149 /* `i' represents the vpos among new frame contents.
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
150 `j' represents the vpos among the old frame contents. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 p = matrix + window_size + 2; /* matrix [1, 1] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 for (i = 1; i <= window_size; i++, p++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 for (j = 1; j <= window_size; j++, p++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 /* p contains the address of matrix [i, j] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 /* First calculate the cost assuming we do
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 not insert or delete above this line.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 That is, if we update through line i-1
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 based on old lines through j-1,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 and then just change old line j to new line i. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 p1 = p - window_size - 2; /* matrix [i-1, j-1] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 cost = p1->writecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 if (cost > p1->insertcost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 cost = p1->insertcost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 if (cost > p1->deletecost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 cost = p1->deletecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 if (old_hash[j] != new_hash[i])
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 cost += draw_cost[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 p->writecost = cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 /* Calculate the cost if we do an insert-line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 before outputting this line.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 That is, we update through line i-1
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 based on old lines through j,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 do an insert-line on line i,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 and then output line i from scratch,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 leaving old lines starting from j for reuse below. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 p1 = p - window_size - 1; /* matrix [i-1, j] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 /* No need to think about doing a delete followed
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 immediately by an insert. It cannot be as good
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 as not doing either of them. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 if (free_at_end == i)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 cost = p1->writecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 cost1 = p1->insertcost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 else
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 cost = p1->writecost + first_insert_cost[i];
6888
a39caeb88721 (calculate_scrolling): Add explicit casts, to avoid compiler warnings.
Karl Heuer <kwzh@gnu.org>
parents: 6773
diff changeset
191 if ((int) p1->insertcount > i)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 abort ();
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 cost1 = p1->insertcost + next_insert_cost[i - p1->insertcount];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 p->insertcost = min (cost, cost1) + draw_cost[i] + extra_cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 p->insertcount = (cost < cost1) ? 1 : p1->insertcount + 1;
6888
a39caeb88721 (calculate_scrolling): Add explicit casts, to avoid compiler warnings.
Karl Heuer <kwzh@gnu.org>
parents: 6773
diff changeset
197 if ((int) p->insertcount > i)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 abort ();
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 /* Calculate the cost if we do a delete line after
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 outputting this line.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 That is, we update through line i
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 based on old lines through j-1,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 and throw away old line j. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 p1 = p - 1; /* matrix [i, j-1] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 /* No need to think about doing an insert followed
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 immediately by a delete. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 if (free_at_end == i)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 cost = p1->writecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 cost1 = p1->deletecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 else
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 cost = p1->writecost + first_delete_cost[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 cost1 = p1->deletecost + next_delete_cost[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 p->deletecost = min (cost, cost1);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 p->deletecount = (cost < cost1) ? 1 : p1->deletecount + 1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222
10262
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
223 /* Perform insert-lines and delete-lines operations on FRAME according
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
224 to the costs in MATRIX, using the general scrolling method.
6647
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
225 Update the frame's current_glyphs info to record what was done.
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
226
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
227 WINDOW_SIZE is the number of lines being considered for scrolling
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
228 and UNCHANGED_AT_TOP is the vpos of the first line being considered.
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
229 These two arguments can specify any contiguous range of lines.
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
230
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
231 We also shuffle the charstarts vectors for the lines
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
232 along with the glyphs; but the results are not quite right,
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
233 since we cannot offset them for changes in amount of text
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
234 in this line or that line. Luckily it doesn't matter,
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
235 since update_frame and update_line will copy in the proper
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
236 new charstarts vectors from the frame's desired_glyphs. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 static void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
239 do_scrolling (frame, matrix, window_size, unchanged_at_top)
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
240 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 struct matrix_elt *matrix;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 int window_size;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 int unchanged_at_top;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 register struct matrix_elt *p;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 register int i, j;
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
247 register struct frame_glyphs *current_frame;
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
248 /* temp_frame->enable[i] means line i has been moved to current_frame. */
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
249 register struct frame_glyphs *temp_frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 struct queue { int count, pos; } *queue;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 int offset = unchanged_at_top;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 int qi = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 int window = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 register int tem;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 int next;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
257 queue = (struct queue *) alloca (FRAME_HEIGHT (frame)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 * sizeof (struct queue));
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
260 current_frame = FRAME_CURRENT_GLYPHS (frame);
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
261 temp_frame = FRAME_TEMP_GLYPHS (frame);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
263 bcopy (current_frame->glyphs, temp_frame->glyphs,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
264 current_frame->height * sizeof (GLYPH *));
6647
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
265 bcopy (current_frame->charstarts, temp_frame->charstarts,
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
266 current_frame->height * sizeof (GLYPH *));
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
267 bcopy (current_frame->used, temp_frame->used,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
268 current_frame->height * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
269 bcopy (current_frame->highlight, temp_frame->highlight,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
270 current_frame->height * sizeof (char));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
271 bzero (temp_frame->enable, temp_frame->height * sizeof (char));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
272 bcopy (current_frame->bufp, temp_frame->bufp,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
273 current_frame->height * sizeof (int));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 #ifdef HAVE_X_WINDOWS
968
861714452cb3 * scroll.c (FRAME_IS_TERMCAP, FRAME_IS_X, FRAME_HAS_MINIBUF):
Jim Blandy <jimb@redhat.com>
parents: 766
diff changeset
276 if (FRAME_X_P (frame))
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
278 bcopy (current_frame->top_left_x, temp_frame->top_left_x,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
279 current_frame->height * sizeof (short));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
280 bcopy (current_frame->top_left_y, temp_frame->top_left_y,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
281 current_frame->height * sizeof (short));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
282 bcopy (current_frame->pix_width, temp_frame->pix_width,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
283 current_frame->height * sizeof (short));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
284 bcopy (current_frame->pix_height, temp_frame->pix_height,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
285 current_frame->height * sizeof (short));
1410
9b29df8c7cb3 * scroll.c (do_scrolling): Don't bcopy non-existant `nruns' or
Joseph Arceneaux <jla@gnu.org>
parents: 968
diff changeset
286 bcopy (current_frame->max_ascent, temp_frame->max_ascent,
1714
2a1dbc7de507 * scroll.c (do_scrolling): When bcopying the max_ascent field from
Jim Blandy <jimb@redhat.com>
parents: 1410
diff changeset
287 current_frame->height * sizeof (short));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 #endif
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 i = j = window_size;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 while (i > 0 || j > 0)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 p = matrix + i * (window_size + 1) + j;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 tem = p->insertcost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 if (tem < p->writecost && tem < p->deletecost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 /* Insert should be done at vpos i-1, plus maybe some before */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 queue[qi].count = p->insertcount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 i -= p->insertcount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 queue[qi++].pos = i + unchanged_at_top;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 else if (p->deletecost < p->writecost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 /* Old line at vpos j-1, and maybe some before it,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 should be deleted */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 j -= p->deletecount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 if (!window)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 set_terminal_window (window_size + unchanged_at_top);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 window = 1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 ins_del_lines (j + unchanged_at_top, - p->deletecount);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 else
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 /* Best thing done here is no insert or delete */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 /* Old line at vpos j-1 ends up at vpos i-1 */
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
320 current_frame->glyphs[i + offset - 1]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
321 = temp_frame->glyphs[j + offset - 1];
6647
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
322 current_frame->charstarts[i + offset - 1]
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
323 = temp_frame->charstarts[j + offset - 1];
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
324 current_frame->used[i + offset - 1]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
325 = temp_frame->used[j + offset - 1];
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
326 current_frame->highlight[i + offset - 1]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
327 = temp_frame->highlight[j + offset - 1];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
329 temp_frame->enable[j + offset - 1] = 1;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 i--;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 j--;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 if (!window && qi)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 set_terminal_window (window_size + unchanged_at_top);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 window = 1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 /* Now do all insertions */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 next = unchanged_at_top;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 for (i = qi - 1; i >= 0; i--)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 ins_del_lines (queue[i].pos, queue[i].count);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 /* Mark the inserted lines as clear,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 and put into them the line-contents strings
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 that were discarded during the deletions.
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
351 Those are the ones for which temp_frame->enable was not set. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 tem = queue[i].pos;
320
81130da351be *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 154
diff changeset
353 for (j = tem + queue[i].count - 1; j >= tem; j--)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
355 current_frame->enable[j] = 0;
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
356 while (temp_frame->enable[next])
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 next++;
6647
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
358 current_frame->glyphs[j] = temp_frame->glyphs[next];
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
359 current_frame->charstarts[j] = temp_frame->charstarts[next++];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 if (window)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 set_terminal_window (0);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366
10262
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
367 /* Determine, in matrix[i,j], the cost of updating the first j
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
368 old lines into the first i new lines using the direct
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
369 scrolling method. When the old line and the new line have
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
370 different hash codes, the calculated cost of updating old
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
371 line j into new line i includes the cost of outputting new
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
372 line i, and if i != j, the cost of outputting the old line j
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
373 is also included, as a penalty for moving the line and then
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
374 erasing it. In addition, the cost of updating a sequence of
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
375 lines with constant i - j includes the cost of scrolling the
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
376 old lines into their new positions, unless i == j. Scrolling
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
377 is achieved by setting the screen window to avoid affecting
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
378 other lines below, and inserting or deleting lines at the top
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
379 of the scrolled region. The cost of scrolling a sequence of
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
380 lines includes the fixed cost of specifying a scroll region,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
381 plus a variable cost which can depend upon the number of lines
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
382 involved and the distance by which they are scrolled, and an
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
383 extra cost to discourage long scrolls.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
384
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
385 As reflected in the matrix, an insert or delete does not
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
386 correspond directly to the insertion or deletion which is
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
387 used in scrolling lines. An insert means that the value of i
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
388 has increased without a corresponding increase in the value
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
389 of j. A delete means that the value of j has increased
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
390 without a corresponding increase in the value of i. A write
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
391 means that i and j are both increased by the same amount, and
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
392 that the old lines will be moved to their new positions.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
393
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
394 An insert following a delete is allowed only if i > j.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
395 A delete following an insert is allowed only if i < j.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
396 These restrictions ensure that the new lines in an insert
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
397 will always be blank as an effect of the neighboring writes.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
398 Thus the calculated cost of an insert is simply the cost of
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
399 outputting the new line contents. The direct cost of a
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
400 delete is zero. Inserts and deletes indirectly affect the
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
401 total cost through their influence on subsequent writes. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
402
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
403 /* The vectors draw_cost, old_hash, and new_hash have the same
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
404 meanings here as in calculate_scrolling, and old_draw_cost
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
405 is the equivalent of draw_cost for the old line contents */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
406
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
407 static void
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
408 calculate_direct_scrolling (frame, matrix, window_size, lines_below,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
409 draw_cost, old_draw_cost, old_hash, new_hash,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
410 free_at_end)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
411 FRAME_PTR frame;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
412 /* matrix is of size window_size + 1 on each side. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
413 struct matrix_elt *matrix;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
414 int window_size;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
415 int *draw_cost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
416 int *old_draw_cost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
417 int *old_hash;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
418 int *new_hash;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
419 int free_at_end;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
420 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
421 register int i, j;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
422 int frame_height = FRAME_HEIGHT (frame);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
423 register struct matrix_elt *p, *p1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
424 register int cost, cost1, delta;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
425
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
426 /* first_insert_cost[-I] is the cost of doing the first insert-line
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
427 at a position I lines above the bottom line in the scroll window. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
428 int *first_insert_cost
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
429 = &FRAME_INSERT_COST (frame)[frame_height - 1];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
430 int *first_delete_cost
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
431 = &FRAME_DELETE_COST (frame)[frame_height - 1];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
432 int *next_insert_cost
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
433 = &FRAME_INSERTN_COST (frame)[frame_height - 1];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
434 int *next_delete_cost
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
435 = &FRAME_DELETEN_COST (frame)[frame_height - 1];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
436
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
437 int scroll_overhead;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
438
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
439 /* Discourage long scrolls on fast lines.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
440 Don't scroll nearly a full frame height unless it saves
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
441 at least 1/4 second. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
442 int extra_cost = baud_rate / (10 * 4 * FRAME_HEIGHT (frame));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
443
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
444 if (baud_rate <= 0)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
445 extra_cost = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
446
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
447 /* Overhead of setting the scroll window, plus the extra cost
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
448 cost of scrolling by a distance of one. The extra cost is
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
449 added once for consistency with the cost vectors */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
450 scroll_overhead = scroll_region_cost + extra_cost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
451
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
452 /* initialize the top left corner of the matrix */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
453 matrix->writecost = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
454 matrix->insertcost = INFINITY;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
455 matrix->deletecost = INFINITY;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
456 matrix->writecount = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
457 matrix->insertcount = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
458 matrix->deletecount = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
459
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
460 /* initialize the left edge of the matrix */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
461 cost = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
462 for (i = 1; i <= window_size; i++)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
463 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
464 p = matrix + i * (window_size + 1);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
465 cost += draw_cost[i];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
466 p->insertcost = cost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
467 p->writecost = INFINITY;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
468 p->deletecost = INFINITY;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
469 p->insertcount = i;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
470 p->writecount = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
471 p->deletecount = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
472 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
473
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
474 /* initialize the top edge of the matrix */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
475 for (j = 1; j <= window_size; j++)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
476 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
477 matrix[j].deletecost = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
478 matrix[j].writecost = INFINITY;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
479 matrix[j].insertcost = INFINITY;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
480 matrix[j].deletecount = j;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
481 matrix[j].writecount = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
482 matrix[j].insertcount = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
483 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
484
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
485 /* `i' represents the vpos among new frame contents.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
486 `j' represents the vpos among the old frame contents. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
487 p = matrix + window_size + 2; /* matrix [1, 1] */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
488
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
489 for (i = 1; i <= window_size; i++, p++)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
490 for (j = 1; j <= window_size; j++, p++)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
491 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
492 /* p contains the address of matrix [i, j] */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
493
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
494 /* First calculate the cost assuming we do
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
495 not insert or delete above this line.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
496 That is, if we update through line i-1
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
497 based on old lines through j-1,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
498 and then just change old line j to new line i.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
499
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
500 Depending on which choice gives the lower cost,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
501 this usually involves either scrolling a single line
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
502 or extending a sequence of scrolled lines, but
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
503 when i == j, no scrolling is required. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
504 p1 = p - window_size - 2; /* matrix [i-1, j-1] */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
505 cost = p1->insertcost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
506 if (cost > p1->deletecost)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
507 cost = p1->deletecost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
508 cost1 = p1->writecost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
509 if (i == j)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
510 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
511 if (cost > cost1)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
512 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
513 cost = cost1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
514 p->writecount = p1->writecount + 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
515 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
516 else
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
517 p->writecount = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
518 if (old_hash[j] != new_hash[i])
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
519 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
520 cost += draw_cost[i];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
521 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
522 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
523 else
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
524 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
525 if (i > j)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
526 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
527 delta = i - j;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
528
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
529 /* The cost added here for scrolling the first line by
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
530 a distance N includes the overhead of setting the
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
531 scroll window, the cost of inserting N lines at a
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
532 position N lines above the bottom line of the window,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
533 and an extra cost which is proportional to N. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
534 cost += scroll_overhead + first_insert_cost[-delta] +
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
535 (delta-1) * (next_insert_cost[-delta] + extra_cost);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
536
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
537 /* In the most general case, the insertion overhead and
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
538 the multiply factor can grow linearly as the distance
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
539 from the bottom of the window increases. The incremental
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
540 cost of scrolling an additional line depends upon the
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
541 rate of change of these two parameters. Each of these
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
542 growth rates can be determined by a simple difference.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
543 To reduce the cumulative effects of rounding error, we
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
544 vary the position at which the difference is computed. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
545 cost1 += first_insert_cost[-j] - first_insert_cost[1-j] +
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
546 (delta-1) * (next_insert_cost[-j] - next_insert_cost[1-j]);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
547 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
548 else
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
549 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
550 delta = j - i;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
551 cost += scroll_overhead + first_delete_cost[-delta] +
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
552 (delta-1) * (next_delete_cost[-delta] + extra_cost);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
553 cost1 += first_delete_cost[-i] - first_delete_cost[1-i] +
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
554 (delta-1) * ( next_delete_cost[-i] - next_delete_cost[1-i]);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
555 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
556 if (cost1 < cost)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
557 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
558 cost = cost1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
559 p->writecount = p1->writecount + 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
560 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
561 else
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
562 p->writecount = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
563 if (old_hash[j] != new_hash[i])
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
564 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
565 cost += draw_cost[i] + old_draw_cost[j];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
566 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
567 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
568 p->writecost = cost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
569
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
570 /* Calculate the cost if we do an insert-line
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
571 before outputting this line.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
572 That is, we update through line i-1
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
573 based on old lines through j,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
574 do an insert-line on line i,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
575 and then output line i from scratch,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
576 leaving old lines starting from j for reuse below. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
577 p1 = p - window_size - 1; /* matrix [i-1, j] */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
578 cost = p1->writecost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
579 /* If i > j, an insert is allowed after a delete. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
580 if (i > j && p1->deletecost < cost)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
581 cost = p1->deletecost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
582 if (p1->insertcost <= cost)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
583 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
584 cost = p1->insertcost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
585 p->insertcount = p1->insertcount + 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
586 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
587 else
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
588 p->insertcount = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
589 cost += draw_cost[i];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
590 p->insertcost = cost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
591
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
592 /* Calculate the cost if we do a delete line after
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
593 outputting this line.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
594 That is, we update through line i
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
595 based on old lines through j-1,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
596 and throw away old line j. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
597 p1 = p - 1; /* matrix [i, j-1] */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
598 cost = p1->writecost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
599 /* If i < j, a delete is allowed after an insert. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
600 if (i < j && p1->insertcost < cost)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
601 cost = p1->insertcost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
602 cost1 = p1->deletecost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
603 if (p1->deletecost <= cost)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
604 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
605 cost = p1->deletecost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
606 p->deletecount = p1->deletecount + 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
607 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
608 else
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
609 p->deletecount = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
610 p->deletecost = cost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
611 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
612 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
613
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
614 /* Perform insert-lines and delete-lines operations on FRAME according
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
615 to the costs in MATRIX, using the direct scrolling method.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
616 Update the frame's current_glyphs info to record what was done.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
617
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
618 WINDOW_SIZE is the number of lines being considered for scrolling
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
619 and UNCHANGED_AT_TOP is the vpos of the first line being considered.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
620 These two arguments can specify any contiguous range of lines.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
621
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
622 We also shuffle the charstarts vectors for the lines
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
623 along with the glyphs; but the results are not quite right,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
624 since we cannot offset them for changes in amount of text
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
625 in this line or that line. Luckily it doesn't matter,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
626 since update_frame and update_line will copy in the proper
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
627 new charstarts vectors from the frame's desired_glyphs.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
628
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
629 In the direct scrolling method, a new scroll window is selected
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
630 before each insertion or deletion, so that groups of lines can be
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
631 scrolled directly to their final vertical positions. This method
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
632 is described in more detail in calculate_direct_scrolling,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
633 where the cost matrix for this approach is constructed. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
634
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
635 static void
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
636 do_direct_scrolling (frame, matrix, window_size, unchanged_at_top)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
637 FRAME_PTR frame;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
638 struct matrix_elt *matrix;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
639 int window_size;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
640 int unchanged_at_top;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
641 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
642 register struct matrix_elt *p;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
643 register int i, j;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
644 register struct frame_glyphs *current_frame;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
645 /* temp_frame->enable[i] means line i has been moved to current_frame. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
646 register struct frame_glyphs *temp_frame;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
647 struct alt_queue { int count, pos, window; } *queue;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
648 int offset = unchanged_at_top;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
649 int qi = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
650 int window = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
651 register int tem;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
652 int next;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
653
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
654 /* A nonzero value of write_follows indicates that a write has been
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
655 selected, allowing either an insert or a delete to be selected next.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
656 When write_follows is zero, a delete cannot be selected unless j < i,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
657 and an insert cannot be selected unless i < j. This corresponds to
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
658 a similar restriction (with the ordering reversed) in
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
659 calculate_direct_scrolling, which is intended to ensure that lines
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
660 marked as inserted will be blank. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
661 int write_follows = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
662
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
663 queue = (struct alt_queue *) alloca (FRAME_HEIGHT (frame)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
664 * sizeof (struct alt_queue));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
665
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
666 current_frame = FRAME_CURRENT_GLYPHS (frame);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
667 temp_frame = FRAME_TEMP_GLYPHS (frame);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
668
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
669 bcopy (current_frame->glyphs, temp_frame->glyphs,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
670 current_frame->height * sizeof (GLYPH *));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
671 bcopy (current_frame->charstarts, temp_frame->charstarts,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
672 current_frame->height * sizeof (GLYPH *));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
673 bcopy (current_frame->used, temp_frame->used,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
674 current_frame->height * sizeof (int));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
675 bcopy (current_frame->highlight, temp_frame->highlight,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
676 current_frame->height * sizeof (char));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
677 bzero (temp_frame->enable, temp_frame->height * sizeof (char));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
678 bcopy (current_frame->bufp, temp_frame->bufp,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
679 current_frame->height * sizeof (int));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
680
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
681 #ifdef HAVE_X_WINDOWS
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
682 if (FRAME_X_P (frame))
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
683 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
684 bcopy (current_frame->top_left_x, temp_frame->top_left_x,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
685 current_frame->height * sizeof (short));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
686 bcopy (current_frame->top_left_y, temp_frame->top_left_y,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
687 current_frame->height * sizeof (short));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
688 bcopy (current_frame->pix_width, temp_frame->pix_width,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
689 current_frame->height * sizeof (short));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
690 bcopy (current_frame->pix_height, temp_frame->pix_height,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
691 current_frame->height * sizeof (short));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
692 bcopy (current_frame->max_ascent, temp_frame->max_ascent,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
693 current_frame->height * sizeof (short));
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
694 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
695 #endif
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
696
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
697 i = j = window_size;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
698
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
699 while (i > 0 || j > 0)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
700 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
701 p = matrix + i * (window_size + 1) + j;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
702 tem = p->insertcost;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
703 if (tem < p->writecost && tem < p->deletecost
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
704 && (write_follows || i < j))
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
705 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
706 /* Insert should be done at vpos i-1, plus maybe some before.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
707 Setting count to 0 in the queue marks this as an insert. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
708 write_follows = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
709 queue[qi].window = i + unchanged_at_top;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
710 queue[qi].count = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
711 i -= p->insertcount;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
712 queue[qi++].pos = i + unchanged_at_top;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
713 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
714 else if (p->deletecost < p->writecost && (write_follows || i > j))
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
715 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
716 /* Delete should be done at vpos j-1, plus maybe some before. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
717 write_follows = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
718 j -= p->deletecount;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
719 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
720 else
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
721 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
722 /* One or more lines should be retained. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
723 write_follows = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
724 tem = p->writecount;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
725 if (i > j)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
726 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
727 /* Immediately scroll a group of lines downward */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
728 set_terminal_window (i + unchanged_at_top);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
729 window = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
730 ins_del_lines (j - tem + unchanged_at_top, i - j);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
731 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
732 else if (i < j)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
733 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
734 /* Queue the upward scrolling of a group of lines */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
735 queue[qi].pos = i - tem + unchanged_at_top;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
736 queue[qi].window = j + unchanged_at_top;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
737 queue[qi++].count = i - j;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
738 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
739
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
740 /* Now copy the line-contents strings */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
741 while (tem > 0)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
742 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
743 i--;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
744 j--;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
745 tem--;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
746 current_frame->glyphs[i + offset]
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
747 = temp_frame->glyphs[j + offset];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
748 current_frame->charstarts[i + offset]
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
749 = temp_frame->charstarts[j + offset];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
750 current_frame->used[i + offset]
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
751 = temp_frame->used[j + offset];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
752 current_frame->highlight[i + offset]
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
753 = temp_frame->highlight[j + offset];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
754
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
755 temp_frame->enable[j + offset] = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
756 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
757 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
758 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
759
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
760 /* Now do all the upward scrolling, and copy the line-contents
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
761 strings for the blank lines of the recorded inserts. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
762
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
763 next = unchanged_at_top;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
764 for (i = qi - 1; i >= 0; i--)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
765 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
766 if (queue[i].count)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
767 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
768 set_terminal_window (queue[i].window);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
769 window = 1;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
770 ins_del_lines (queue[i].pos, queue[i].count);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
771 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
772 else
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
773 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
774 /* Mark the inserted lines as clear,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
775 and put into them the line-contents strings
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
776 that were discarded during the deletions.
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
777 Those are the ones for which temp_frame->enable was not set. */
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
778 tem = queue[i].pos;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
779 for (j = queue[i].window - 1; j >= tem; j--)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
780 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
781 current_frame->enable[j] = 0;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
782 while (temp_frame->enable[next])
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
783 next++;
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
784 current_frame->glyphs[j] = temp_frame->glyphs[next];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
785 current_frame->charstarts[j] = temp_frame->charstarts[next++];
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
786 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
787 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
788 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
789
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
790 if (window)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
791 set_terminal_window (0);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
792 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
793
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
794 void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
795 scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
10262
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
796 draw_cost, old_draw_cost, old_hash, new_hash, free_at_end)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
797 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
798 int window_size, unchanged_at_top, unchanged_at_bottom;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
799 int *draw_cost;
10262
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
800 int *old_draw_cost;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801 int *old_hash;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
802 int *new_hash;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
803 int free_at_end;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
804 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
805 struct matrix_elt *matrix;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
806 matrix = ((struct matrix_elt *)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
807 alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix));
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
808
10262
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
809 if (scroll_region_ok)
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
810 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
811 calculate_direct_scrolling (frame, matrix, window_size,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
812 unchanged_at_bottom,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
813 draw_cost, old_draw_cost,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
814 old_hash, new_hash, free_at_end);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
815 do_direct_scrolling (frame, matrix, window_size, unchanged_at_top);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
816 }
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
817 else
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
818 {
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
819 calculate_scrolling (frame, matrix, window_size, unchanged_at_bottom,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
820 draw_cost, old_hash, new_hash,
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
821 free_at_end);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
822 do_scrolling (frame, matrix, window_size, unchanged_at_top);
4face60ac721 (scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents: 10109
diff changeset
823 }
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
824 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
825
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
826 /* Return number of lines in common between current and desired frame contents
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
827 described to us only as vectors of hash codes OLDHASH and NEWHASH.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
828 Consider only vpos range START to END (not including END).
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
829 Ignore short lines on the assumption that
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
830 avoiding redrawing such a line will have little weight. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
831
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
832 int
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
833 scrolling_max_lines_saved (start, end, oldhash, newhash, cost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
834 int start, end;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
835 int *oldhash, *newhash, *cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
836 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
837 struct { int hash; int count; } lines[01000];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
838 register int i, h;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
839 register int matchcount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
840 int avg_length = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
841 int threshold;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
842
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
843 /* Compute a threshold which is 1/4 of average length of these lines. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
844
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
845 for (i = start; i < end; i++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
846 avg_length += cost[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
847
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
848 avg_length /= end - start;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
849 threshold = avg_length / 4;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
850
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
851 bzero (lines, sizeof lines);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
852
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853 /* Put new lines' hash codes in hash table.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
854 Ignore lines shorter than the threshold.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
855 Thus, if the lines that are in common
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
856 are mainly the ones that are short,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
857 they won't count. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
858 for (i = start; i < end; i++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
859 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
860 if (cost[i] > threshold)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
861 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
862 h = newhash[i] & 0777;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
863 lines[h].hash = newhash[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
864 lines[h].count++;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
865 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
866 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
867
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
868 /* Look up old line hash codes in the hash table.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
869 Count number of matches between old lines and new. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
870
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
871 for (i = start; i < end; i++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
872 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
873 h = oldhash[i] & 0777;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
874 if (oldhash[i] == lines[h].hash)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
875 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
876 matchcount++;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
877 if (--lines[h].count == 0)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
878 lines[h].hash = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
879 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
880 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
881
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
882 return matchcount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
883 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
884
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
885 /* Return a measure of the cost of moving the lines
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
886 starting with vpos FROM, up to but not including vpos TO,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
887 down by AMOUNT lines (AMOUNT may be negative).
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
888 These are the same arguments that might be given to
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
889 scroll_frame_lines to perform this scrolling. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
891 scroll_cost (frame, from, to, amount)
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
892 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 int from, to, amount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
894 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
895 /* Compute how many lines, at bottom of frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
896 will not be involved in actual motion. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
897 int limit = to;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
898 int offset;
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
899 int height = FRAME_HEIGHT (frame);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
900
421
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
901 if (amount == 0)
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
902 return 0;
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
903
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904 if (! scroll_region_ok)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
905 limit = height;
421
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
906 else if (amount > 0)
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
907 limit += amount;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
908
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909 if (amount < 0)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
911 int temp = to;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
912 to = from + amount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
913 from = temp + amount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
914 amount = - amount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
915 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
916
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
917 offset = height - limit;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
918
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
919 return
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
920 (FRAME_INSERT_COST (frame)[offset + from]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
921 + (amount - 1) * FRAME_INSERTN_COST (frame)[offset + from]
10109
869e177ca872 (scroll_cost): FRAME_DELETE_COST and FRAME_DELETEN_COSTS were confused. Fixed.
Richard M. Stallman <rms@gnu.org>
parents: 9576
diff changeset
922 + FRAME_DELETE_COST (frame)[offset + to]
869e177ca872 (scroll_cost): FRAME_DELETE_COST and FRAME_DELETEN_COSTS were confused. Fixed.
Richard M. Stallman <rms@gnu.org>
parents: 9576
diff changeset
923 + (amount - 1) * FRAME_DELETEN_COST (frame)[offset + to]);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
924 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
925
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
926 /* Calculate the line insertion/deletion
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
927 overhead and multiply factor values */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
928
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
929 static void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
930 line_ins_del (frame, ov1, pf1, ovn, pfn, ov, mf)
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
931 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
932 int ov1, ovn;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
933 int pf1, pfn;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
934 register int *ov, *mf;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
935 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
936 register int i;
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
937 register int frame_height = FRAME_HEIGHT (frame);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
938 register int insert_overhead = ov1 * 10;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
939 register int next_insert_cost = ovn * 10;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
940
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
941 for (i = frame_height-1; i >= 0; i--)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
942 {
529
413127b220ef *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 421
diff changeset
943 mf[i] = next_insert_cost / 10;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
944 next_insert_cost += pfn;
529
413127b220ef *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 421
diff changeset
945 ov[i] = (insert_overhead + next_insert_cost) / 10;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
946 insert_overhead += pf1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
947 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
948 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
949
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
950 static void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
951 ins_del_costs (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
952 one_line_string, multi_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
953 setup_string, cleanup_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
954 costvec, ncostvec, coefficient)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
955 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
956 char *one_line_string, *multi_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
957 char *setup_string, *cleanup_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
958 int *costvec, *ncostvec;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
959 int coefficient;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
960 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
961 if (multi_string)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
962 line_ins_del (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963 string_cost (multi_string) * coefficient,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
964 per_line_cost (multi_string) * coefficient,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
965 0, 0, costvec, ncostvec);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
966 else if (one_line_string)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
967 line_ins_del (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
968 string_cost (setup_string) + string_cost (cleanup_string), 0,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
969 string_cost (one_line_string),
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
970 per_line_cost (one_line_string),
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
971 costvec, ncostvec);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
972 else
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
973 line_ins_del (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
974 9999, 0, 9999, 0,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
975 costvec, ncostvec);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
976 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
977
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
978 /* Calculate the insert and delete line costs.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
979 Note that this is done even when running with a window system
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
980 because we want to know how long scrolling takes (and avoid it).
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
981 This must be redone whenever the frame height changes.
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
982
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
983 We keep the ID costs in a precomputed array based on the position
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
984 at which the I or D is performed. Also, there are two kinds of ID
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
985 costs: the "once-only" and the "repeated". This is to handle both
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
986 those terminals that are able to insert N lines at a time (once-
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
987 only) and those that must repeatedly insert one line.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
988
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
989 The cost to insert N lines at line L is
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
990 [tt.t_ILov + (frame_height + 1 - L) * tt.t_ILpf] +
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
991 N * [tt.t_ILnov + (frame_height + 1 - L) * tt.t_ILnpf]
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
992
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
993 ILov represents the basic insert line overhead. ILpf is the padding
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
994 required to allow the terminal time to move a line: insertion at line
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
995 L changes (frame_height + 1 - L) lines.
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
996
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
997 The first bracketed expression above is the overhead; the second is
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
998 the multiply factor. Both are dependent only on the position at
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
999 which the insert is performed. We store the overhead in
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1000 FRAME_INSERT_COST (frame) and the multiply factor in
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1001 FRAME_INSERTN_COST (frame). Note however that any insertion
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1002 must include at least one multiply factor. Rather than compute this
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1003 as FRAME_INSERT_COST (frame)[line]+FRAME_INSERTN_COST (frame)[line],
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1004 we add FRAME_INSERTN_COST (frame) into FRAME_INSERT_COST (frame).
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1005 This is reasonable because of the particular algorithm used in calcM.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1006
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1007 Deletion is essentially the same as insertion.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1008 */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1009
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1010 do_line_insertion_deletion_costs (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1011 ins_line_string, multi_ins_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1012 del_line_string, multi_del_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1013 setup_string, cleanup_string, coefficient)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1014 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1015 char *ins_line_string, *multi_ins_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1016 char *del_line_string, *multi_del_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1017 char *setup_string, *cleanup_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1018 int coefficient;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1019 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1020 if (FRAME_INSERT_COST (frame) != 0)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1021 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1022 FRAME_INSERT_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1023 (int *) xrealloc (FRAME_INSERT_COST (frame),
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1024 FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1025 FRAME_DELETEN_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1026 (int *) xrealloc (FRAME_DELETEN_COST (frame),
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1027 FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1028 FRAME_INSERTN_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1029 (int *) xrealloc (FRAME_INSERTN_COST (frame),
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1030 FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1031 FRAME_DELETE_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1032 (int *) xrealloc (FRAME_DELETE_COST (frame),
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1033 FRAME_HEIGHT (frame) * sizeof (int));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1034 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1035 else
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1036 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1037 FRAME_INSERT_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1038 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1039 FRAME_DELETEN_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1040 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1041 FRAME_INSERTN_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1042 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1043 FRAME_DELETE_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1044 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1045 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1046
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1047 ins_del_costs (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1048 ins_line_string, multi_ins_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1049 setup_string, cleanup_string,
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1050 FRAME_INSERT_COST (frame), FRAME_INSERTN_COST (frame),
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1051 coefficient);
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
1052 ins_del_costs (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1053 del_line_string, multi_del_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1054 setup_string, cleanup_string,
9576
14cd96eda0e3 (do_line_insertion_deletion_costs): Fix argument order.
Karl Heuer <kwzh@gnu.org>
parents: 7307
diff changeset
1055 FRAME_DELETE_COST (frame), FRAME_DELETEN_COST (frame),
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1056 coefficient);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1057 }