Mercurial > emacs
annotate src/scroll.c @ 56570:059dc717baef
(event-modifiers, event-basic-type): Doc fixes.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Sat, 31 Jul 2004 15:45:30 +0000 |
parents | 695cf19ef79e |
children | 4250e7e26247 a8fa7c632ee4 375f2633d815 |
rev | line source |
---|---|
154 | 1 /* Calculate what line insertion or deletion to do, and do it, |
7307 | 2 Copyright (C) 1985, 1986, 1990, 1993, 1994 Free Software Foundation, Inc. |
154 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
732 | 8 the Free Software Foundation; either version 2, or (at your option) |
154 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13415
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13415
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
154 | 20 |
21 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
3356
diff
changeset
|
22 #include <config.h> |
25004 | 23 #include <stdio.h> |
24 #include <string.h> | |
154 | 25 #include "termchar.h" |
26 #include "lisp.h" | |
27 #include "dispextern.h" | |
31102
6a0caa788013
Include keyboard.h before frame.h.
Andrew Innes <andrewi@gnu.org>
parents:
28407
diff
changeset
|
28 #include "keyboard.h" |
766 | 29 #include "frame.h" |
25004 | 30 #include "window.h" |
154 | 31 |
32 /* All costs measured in characters. | |
766 | 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 | 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 | 37 |
38 struct matrix_elt | |
39 { | |
40 /* Cost of outputting through this line | |
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 | 43 /* Cost of outputting through this line |
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 | 46 /* Cost of outputting through this line |
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 | 49 /* Number of inserts so far in this run of inserts, |
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 | 52 /* Number of deletes so far in this run of deletes, |
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 | 58 }; |
59 | |
25004 | 60 static void do_direct_scrolling P_ ((struct glyph_matrix *, |
61 struct matrix_elt *, | |
62 int, int)); | |
63 static void do_scrolling P_ ((struct glyph_matrix *, | |
64 struct matrix_elt *, | |
65 int, int)); | |
66 | |
154 | 67 |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
68 /* 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
|
69 lines into the first i new lines using the general scrolling method. |
154 | 70 This involves using insert or delete somewhere if i != j. |
71 For each matrix elements, three kinds of costs are recorded: | |
72 the smallest cost that ends with an insert, the smallest | |
73 cost that ends with a delete, and the smallest cost that | |
74 ends with neither one. These are kept separate because | |
75 on some terminals the cost of doing an insert varies | |
76 depending on whether one was just done, etc. */ | |
77 | |
78 /* draw_cost[VPOS] is the cost of outputting new line at VPOS. | |
79 old_hash[VPOS] is the hash code of the old line at VPOS. | |
80 new_hash[VPOS] is the hash code of the new line at VPOS. | |
766 | 81 Note that these are not true frame vpos's, but relative |
154 | 82 to the place at which the first mismatch between old and |
83 new contents appears. */ | |
84 | |
85 static void | |
766 | 86 calculate_scrolling (frame, matrix, window_size, lines_below, |
154 | 87 draw_cost, old_hash, new_hash, |
88 free_at_end) | |
766 | 89 FRAME_PTR frame; |
154 | 90 /* matrix is of size window_size + 1 on each side. */ |
91 struct matrix_elt *matrix; | |
48323
3aa5ba8c3ef4
(calculate_scrolling, calculate_direct_scrolling):
Dave Love <fx@gnu.org>
parents:
39682
diff
changeset
|
92 int window_size, lines_below; |
154 | 93 int *draw_cost; |
94 int *old_hash; | |
95 int *new_hash; | |
96 int free_at_end; | |
97 { | |
98 register int i, j; | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
99 int frame_lines = FRAME_LINES (frame); |
154 | 100 register struct matrix_elt *p, *p1; |
101 register int cost, cost1; | |
102 | |
103 int lines_moved = window_size + (scroll_region_ok ? 0 : lines_below); | |
104 /* first_insert_cost[I] is the cost of doing the first insert-line | |
25004 | 105 at the i'th line of the lines we are considering, |
154 | 106 where I is origin 1 (as it is below). */ |
107 int *first_insert_cost | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
108 = &FRAME_INSERT_COST (frame)[frame_lines - 1 - lines_moved]; |
154 | 109 int *first_delete_cost |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
110 = &FRAME_DELETE_COST (frame)[frame_lines - 1 - lines_moved]; |
154 | 111 int *next_insert_cost |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
112 = &FRAME_INSERTN_COST (frame)[frame_lines - 1 - lines_moved]; |
154 | 113 int *next_delete_cost |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
114 = &FRAME_DELETEN_COST (frame)[frame_lines - 1 - lines_moved]; |
154 | 115 |
116 /* Discourage long scrolls on fast lines. | |
766 | 117 Don't scroll nearly a full frame height unless it saves |
154 | 118 at least 1/4 second. */ |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
119 int extra_cost = baud_rate / (10 * 4 * FRAME_LINES (frame)); |
154 | 120 |
3356
09759a9653c5
(calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
121 if (baud_rate <= 0) |
09759a9653c5
(calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
122 extra_cost = 1; |
09759a9653c5
(calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
123 |
154 | 124 /* initialize the top left corner of the matrix */ |
125 matrix->writecost = 0; | |
126 matrix->insertcost = INFINITY; | |
127 matrix->deletecost = INFINITY; | |
128 matrix->insertcount = 0; | |
129 matrix->deletecount = 0; | |
130 | |
131 /* initialize the left edge of the matrix */ | |
132 cost = first_insert_cost[1] - next_insert_cost[1]; | |
133 for (i = 1; i <= window_size; i++) | |
134 { | |
135 p = matrix + i * (window_size + 1); | |
136 cost += draw_cost[i] + next_insert_cost[i] + extra_cost; | |
137 p->insertcost = cost; | |
138 p->writecost = INFINITY; | |
139 p->deletecost = INFINITY; | |
140 p->insertcount = i; | |
141 p->deletecount = 0; | |
142 } | |
143 | |
144 /* initialize the top edge of the matrix */ | |
145 cost = first_delete_cost[1] - next_delete_cost[1]; | |
146 for (j = 1; j <= window_size; j++) | |
147 { | |
148 cost += next_delete_cost[j]; | |
149 matrix[j].deletecost = cost; | |
150 matrix[j].writecost = INFINITY; | |
151 matrix[j].insertcost = INFINITY; | |
152 matrix[j].deletecount = j; | |
153 matrix[j].insertcount = 0; | |
154 } | |
155 | |
766 | 156 /* `i' represents the vpos among new frame contents. |
157 `j' represents the vpos among the old frame contents. */ | |
154 | 158 p = matrix + window_size + 2; /* matrix [1, 1] */ |
159 for (i = 1; i <= window_size; i++, p++) | |
160 for (j = 1; j <= window_size; j++, p++) | |
161 { | |
162 /* p contains the address of matrix [i, j] */ | |
163 | |
164 /* First calculate the cost assuming we do | |
165 not insert or delete above this line. | |
166 That is, if we update through line i-1 | |
167 based on old lines through j-1, | |
168 and then just change old line j to new line i. */ | |
169 p1 = p - window_size - 2; /* matrix [i-1, j-1] */ | |
170 cost = p1->writecost; | |
171 if (cost > p1->insertcost) | |
172 cost = p1->insertcost; | |
173 if (cost > p1->deletecost) | |
174 cost = p1->deletecost; | |
175 if (old_hash[j] != new_hash[i]) | |
176 cost += draw_cost[i]; | |
177 p->writecost = cost; | |
178 | |
179 /* Calculate the cost if we do an insert-line | |
180 before outputting this line. | |
181 That is, we update through line i-1 | |
182 based on old lines through j, | |
183 do an insert-line on line i, | |
184 and then output line i from scratch, | |
185 leaving old lines starting from j for reuse below. */ | |
186 p1 = p - window_size - 1; /* matrix [i-1, j] */ | |
187 /* No need to think about doing a delete followed | |
188 immediately by an insert. It cannot be as good | |
189 as not doing either of them. */ | |
190 if (free_at_end == i) | |
191 { | |
192 cost = p1->writecost; | |
193 cost1 = p1->insertcost; | |
194 } | |
195 else | |
196 { | |
197 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
|
198 if ((int) p1->insertcount > i) |
154 | 199 abort (); |
200 cost1 = p1->insertcost + next_insert_cost[i - p1->insertcount]; | |
201 } | |
202 p->insertcost = min (cost, cost1) + draw_cost[i] + extra_cost; | |
203 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
|
204 if ((int) p->insertcount > i) |
154 | 205 abort (); |
206 | |
207 /* Calculate the cost if we do a delete line after | |
208 outputting this line. | |
209 That is, we update through line i | |
210 based on old lines through j-1, | |
211 and throw away old line j. */ | |
212 p1 = p - 1; /* matrix [i, j-1] */ | |
213 /* No need to think about doing an insert followed | |
214 immediately by a delete. */ | |
215 if (free_at_end == i) | |
216 { | |
217 cost = p1->writecost; | |
218 cost1 = p1->deletecost; | |
219 } | |
220 else | |
221 { | |
222 cost = p1->writecost + first_delete_cost[i]; | |
223 cost1 = p1->deletecost + next_delete_cost[i]; | |
224 } | |
225 p->deletecost = min (cost, cost1); | |
226 p->deletecount = (cost < cost1) ? 1 : p1->deletecount + 1; | |
227 } | |
228 } | |
25004 | 229 |
230 | |
154 | 231 |
25004 | 232 /* Perform insert-lines and delete-lines operations on CURRENT_MATRIX |
233 according to the costs in MATRIX, using the general scrolling | |
234 method that is used if the terminal does not support the setting of | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
235 scroll windows (scroll_region_ok == 0). |
6647
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
236 |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
237 WINDOW_SIZE is the number of lines being considered for scrolling |
25004 | 238 and UNCHANGED_AT_TOP is the vpos of the first line being |
239 considered. These two arguments can specify any contiguous range | |
240 of lines. */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
241 |
154 | 242 static void |
25004 | 243 do_scrolling (current_matrix, matrix, window_size, unchanged_at_top) |
244 struct glyph_matrix *current_matrix; | |
154 | 245 struct matrix_elt *matrix; |
246 int window_size; | |
247 int unchanged_at_top; | |
248 { | |
25004 | 249 struct matrix_elt *p; |
250 int i, j, k; | |
251 | |
252 /* Set to 1 if we have set a terminal window with | |
253 set_terminal_window. */ | |
254 int terminal_window_p = 0; | |
154 | 255 |
25004 | 256 /* A queue for line insertions to be done. */ |
257 struct queue { int count, pos; }; | |
258 struct queue *queue_start | |
259 = (struct queue *) alloca (current_matrix->nrows * sizeof (struct queue)); | |
260 struct queue *queue = queue_start; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
261 |
25004 | 262 char *retained_p = (char *) alloca (window_size * sizeof (char)); |
263 int *copy_from = (int *) alloca (window_size * sizeof (int)); | |
154 | 264 |
25004 | 265 /* Zero means line is empty. */ |
266 bzero (retained_p, window_size * sizeof (char)); | |
267 for (k = 0; k < window_size; ++k) | |
268 copy_from[k] = -1; | |
154 | 269 |
28407
f15029804aba
* scroll.c (CHECK_BOUNDS): Renamed from CHECK.
Ken Raeburn <raeburn@raeburn.org>
parents:
25004
diff
changeset
|
270 #define CHECK_BOUNDS \ |
25004 | 271 do \ |
272 { \ | |
273 int k; \ | |
274 for (k = 0; k < window_size; ++k) \ | |
275 xassert (copy_from[k] == -1 \ | |
276 || (copy_from[k] >= 0 && copy_from[k] < window_size)); \ | |
277 } \ | |
278 while (0); | |
154 | 279 |
25004 | 280 /* When j is advanced, this corresponds to deleted lines. |
281 When i is advanced, this corresponds to inserted lines. */ | |
154 | 282 i = j = window_size; |
283 while (i > 0 || j > 0) | |
284 { | |
285 p = matrix + i * (window_size + 1) + j; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
286 |
25004 | 287 if (p->insertcost < p->writecost && p->insertcost < p->deletecost) |
154 | 288 { |
25004 | 289 /* Insert should be done at vpos i-1, plus maybe some before. |
290 Queue the screen operation to be performed. */ | |
291 queue->count = p->insertcount; | |
292 queue->pos = i + unchanged_at_top - p->insertcount; | |
293 ++queue; | |
294 | |
295 /* By incrementing I, we leave room in the result rows | |
296 for the empty rows opened up. */ | |
154 | 297 i -= p->insertcount; |
298 } | |
299 else if (p->deletecost < p->writecost) | |
300 { | |
25004 | 301 /* Old line at vpos j-1, and maybe some before it, should be |
302 deleted. By decrementing J, we skip some lines in the | |
303 temp_rows which is equivalent to omitting these lines in | |
304 the result rows, thus deleting them. */ | |
154 | 305 j -= p->deletecount; |
25004 | 306 |
307 /* Set the terminal window, if not done already. */ | |
308 if (! terminal_window_p) | |
154 | 309 { |
310 set_terminal_window (window_size + unchanged_at_top); | |
25004 | 311 terminal_window_p = 1; |
154 | 312 } |
25004 | 313 |
314 /* Delete lines on the terminal. */ | |
154 | 315 ins_del_lines (j + unchanged_at_top, - p->deletecount); |
316 } | |
317 else | |
318 { | |
25004 | 319 /* Best thing done here is no insert or delete, i.e. a write. */ |
320 --i, --j; | |
321 xassert (i >= 0 && i < window_size); | |
322 xassert (j >= 0 && j < window_size); | |
323 copy_from[i] = j; | |
324 retained_p[j] = 1; | |
154 | 325 |
25004 | 326 #if GLYPH_DEBUG |
28407
f15029804aba
* scroll.c (CHECK_BOUNDS): Renamed from CHECK.
Ken Raeburn <raeburn@raeburn.org>
parents:
25004
diff
changeset
|
327 CHECK_BOUNDS; |
25004 | 328 #endif |
154 | 329 } |
330 } | |
331 | |
25004 | 332 /* Now do all insertions queued above. */ |
333 if (queue > queue_start) | |
154 | 334 { |
25004 | 335 int next = -1; |
336 | |
337 /* Set the terminal window if not yet done. */ | |
338 if (!terminal_window_p) | |
339 { | |
340 set_terminal_window (window_size + unchanged_at_top); | |
341 terminal_window_p = 1; | |
342 } | |
343 | |
344 do | |
345 { | |
346 --queue; | |
347 | |
348 /* Do the deletion on the terminal. */ | |
349 ins_del_lines (queue->pos, queue->count); | |
350 | |
351 /* All lines in the range deleted become empty in the glyph | |
352 matrix. Assign to them glyph rows that are not retained. | |
353 K is the starting position of the deleted range relative | |
354 to the window we are working in. */ | |
355 k = queue->pos - unchanged_at_top; | |
356 for (j = 0; j < queue->count; ++j) | |
357 { | |
358 /* Find the next row not retained. */ | |
359 while (retained_p[++next]) | |
360 ; | |
361 | |
362 /* Record that this row is to be used for the empty | |
363 glyph row j. */ | |
364 copy_from[k + j] = next; | |
365 } | |
366 } | |
367 while (queue > queue_start); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
368 |
154 | 369 } |
370 | |
25004 | 371 for (k = 0; k < window_size; ++k) |
372 xassert (copy_from[k] >= 0 && copy_from[k] < window_size); | |
154 | 373 |
25004 | 374 /* Perform the row swizzling. */ |
375 mirrored_line_dance (current_matrix, unchanged_at_top, window_size, | |
376 copy_from, retained_p); | |
154 | 377 |
25004 | 378 /* Some sanity checks if GLYPH_DEBUG != 0. */ |
379 CHECK_MATRIX (current_matrix); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
380 |
25004 | 381 if (terminal_window_p) |
154 | 382 set_terminal_window (0); |
383 } | |
25004 | 384 |
154 | 385 |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
386 /* 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 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
|
402 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
|
403 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
413 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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
422 /* 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
|
423 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
|
424 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
|
425 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
426 static void |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
427 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
|
428 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
|
429 free_at_end) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
430 FRAME_PTR frame; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
431 /* 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
|
432 struct matrix_elt *matrix; |
48323
3aa5ba8c3ef4
(calculate_scrolling, calculate_direct_scrolling):
Dave Love <fx@gnu.org>
parents:
39682
diff
changeset
|
433 int window_size, lines_below; |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
434 int *draw_cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
435 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
|
436 int *old_hash; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
437 int *new_hash; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
438 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
|
439 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
440 register int i, j; |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
441 int frame_lines = FRAME_LINES (frame); |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
442 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
|
443 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
|
444 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
445 /* 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
|
446 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
|
447 int *first_insert_cost |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
448 = &FRAME_INSERT_COST (frame)[frame_lines - 1]; |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
449 int *first_delete_cost |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
450 = &FRAME_DELETE_COST (frame)[frame_lines - 1]; |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
451 int *next_insert_cost |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
452 = &FRAME_INSERTN_COST (frame)[frame_lines - 1]; |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
453 int *next_delete_cost |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
454 = &FRAME_DELETEN_COST (frame)[frame_lines - 1]; |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
455 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
456 int scroll_overhead; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
457 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
458 /* 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
|
459 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
|
460 at least 1/4 second. */ |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
461 int extra_cost = baud_rate / (10 * 4 * FRAME_LINES (frame)); |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
462 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
463 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
|
464 extra_cost = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
465 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
466 /* 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
|
467 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
|
468 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
|
469 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
|
470 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
471 /* 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
|
472 matrix->writecost = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
473 matrix->insertcost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
474 matrix->deletecost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
475 matrix->writecount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
476 matrix->insertcount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
477 matrix->deletecount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
478 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
479 /* 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
|
480 cost = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
481 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
|
482 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
483 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
|
484 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
|
485 p->insertcost = cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
486 p->writecost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
487 p->deletecost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
488 p->insertcount = i; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
489 p->writecount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
490 p->deletecount = 0; |
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 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
493 /* 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
|
494 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
|
495 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
496 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 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
|
502 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
503 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
504 /* `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
|
505 `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
|
506 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
|
507 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
508 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
|
509 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
|
510 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
511 /* 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
|
512 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
513 /* 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
519 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
|
520 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
|
521 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
|
522 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
|
523 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
|
524 cost = p1->insertcost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
525 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
|
526 cost = p1->deletecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
527 cost1 = p1->writecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
528 if (i == j) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
529 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
530 if (cost > cost1) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
531 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
532 cost = cost1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
533 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
|
534 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
535 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
536 p->writecount = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
537 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
|
538 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
539 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
|
540 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
541 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
542 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
543 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
544 if (i > j) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
545 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
546 delta = i - 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 /* 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
|
549 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
|
550 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
|
551 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
|
552 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
|
553 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
|
554 (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
|
555 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
556 /* 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
|
557 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
|
558 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
|
559 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
|
560 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
|
561 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
|
562 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
|
563 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
|
564 cost1 += first_insert_cost[-j] - first_insert_cost[1-j] + |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
565 (delta-1) * (next_insert_cost[-j] - next_insert_cost[1-j]); |
10262
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 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
568 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
569 delta = j - i; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
570 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
|
571 (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
|
572 cost1 += first_delete_cost[-i] - first_delete_cost[1-i] + |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
573 (delta-1) * ( next_delete_cost[-i] - next_delete_cost[1-i]); |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
574 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
575 if (cost1 < cost) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
576 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
577 cost = cost1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
578 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
|
579 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
580 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
581 p->writecount = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
582 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
|
583 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
584 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
|
585 } |
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 p->writecost = cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
588 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
589 /* 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
|
590 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 cost = p1->writecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
598 /* 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
|
599 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
|
600 cost = p1->deletecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
601 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
|
602 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
603 cost = p1->insertcost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
604 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
|
605 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
606 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
607 p->insertcount = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
608 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
|
609 p->insertcost = cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
610 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
611 /* 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
|
612 outputting this line. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
613 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
|
614 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
|
615 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
|
616 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
|
617 cost = p1->writecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
618 /* 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
|
619 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
|
620 cost = p1->insertcost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
621 cost1 = p1->deletecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
622 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
|
623 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
624 cost = p1->deletecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
625 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
|
626 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
627 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
628 p->deletecount = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
629 p->deletecost = cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
630 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
631 } |
25004 | 632 |
633 | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
634 |
25004 | 635 /* Perform insert-lines and delete-lines operations on CURRENT_MATRIX |
636 according to the costs in MATRIX, using the direct scrolling method | |
637 which is used when the terminal supports setting a scroll window | |
638 (scroll_region_ok). | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
639 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
640 WINDOW_SIZE is the number of lines being considered for scrolling |
25004 | 641 and UNCHANGED_AT_TOP is the vpos of the first line being |
642 considered. These two arguments can specify any contiguous range | |
643 of lines. | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
644 |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
645 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
|
646 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
|
647 scrolled directly to their final vertical positions. This method |
25004 | 648 is described in more detail in calculate_direct_scrolling, where |
649 the cost matrix for this approach is constructed. */ | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
650 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
651 static void |
25004 | 652 do_direct_scrolling (current_matrix, cost_matrix, window_size, |
653 unchanged_at_top) | |
654 struct glyph_matrix *current_matrix; | |
655 struct matrix_elt *cost_matrix; | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
656 int window_size; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
657 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
|
658 { |
25004 | 659 struct matrix_elt *p; |
660 int i, j; | |
661 | |
662 /* A queue of deletions and insertions to be performed. */ | |
663 struct alt_queue { int count, pos, window; }; | |
664 struct alt_queue *queue_start = (struct alt_queue *) | |
665 alloca (window_size * sizeof *queue_start); | |
666 struct alt_queue *queue = queue_start; | |
667 | |
668 /* Set to 1 if a terminal window has been set with | |
669 set_terminal_window: */ | |
670 int terminal_window_p = 0; | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
671 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
672 /* A nonzero value of write_follows indicates that a write has been |
25004 | 673 selected, allowing either an insert or a delete to be selected |
674 next. When write_follows is zero, a delete cannot be selected | |
675 unless j < i, and an insert cannot be selected unless i < j. | |
676 This corresponds to a similar restriction (with the ordering | |
677 reversed) in calculate_direct_scrolling, which is intended to | |
678 ensure that lines marked as inserted will be blank. */ | |
679 int write_follows_p = 1; | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
680 |
25004 | 681 /* For each row in the new matrix what row of the old matrix it is. */ |
682 int *copy_from = (int *) alloca (window_size * sizeof (int)); | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
683 |
25004 | 684 /* Non-zero for each row in the new matrix that is retained from the |
685 old matrix. Lines not retained are empty. */ | |
686 char *retained_p = (char *) alloca (window_size * sizeof (char)); | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
687 |
25004 | 688 bzero (retained_p, window_size * sizeof (char)); |
689 | |
690 /* Perform some sanity checks when GLYPH_DEBUG is on. */ | |
691 CHECK_MATRIX (current_matrix); | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
692 |
25004 | 693 /* We are working on the line range UNCHANGED_AT_TOP ... |
694 UNCHANGED_AT_TOP + WINDOW_SIZE (not including) in CURRENT_MATRIX. | |
695 We step through lines in this range from the end to the start. I | |
696 is an index into new lines, j an index into old lines. The cost | |
697 matrix determines what to do for ranges of indices. | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
698 |
25004 | 699 If i is decremented without also decrementing j, this corresponds |
700 to inserting empty lines in the result. If j is decremented | |
701 without also decrementing i, this corresponds to omitting these | |
702 lines in the new rows, i.e. rows are deleted. */ | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
703 i = j = window_size; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
704 |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
705 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
|
706 { |
25004 | 707 p = cost_matrix + i * (window_size + 1) + j; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
708 |
25004 | 709 if (p->insertcost < p->writecost |
710 && p->insertcost < p->deletecost | |
711 && (write_follows_p || i < j)) | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
712 { |
25004 | 713 /* Insert is cheaper than deleting or writing lines. Leave |
714 a hole in the result display that will be filled with | |
715 empty lines when the queue is emptied. */ | |
716 queue->count = 0; | |
717 queue->window = i; | |
718 queue->pos = i - p->insertcount; | |
719 ++queue; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
720 |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
721 i -= p->insertcount; |
25004 | 722 write_follows_p = 0; |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
723 } |
25004 | 724 else if (p->deletecost < p->writecost |
725 && (write_follows_p || i > j)) | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
726 { |
25004 | 727 /* Deleting lines is cheaper. By decrementing J, omit |
728 deletecount lines from the original. */ | |
729 write_follows_p = 0; | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
730 j -= p->deletecount; |
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 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
733 { |
25004 | 734 /* One or more lines should be written. In the direct |
735 scrolling method we do this by scrolling the lines to the | |
736 place they belong. */ | |
737 int n_to_write = p->writecount; | |
738 write_follows_p = 1; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
739 xassert (n_to_write > 0); |
25004 | 740 |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
741 if (i > j) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
742 { |
25004 | 743 /* Immediately insert lines */ |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
744 set_terminal_window (i + unchanged_at_top); |
25004 | 745 terminal_window_p = 1; |
746 ins_del_lines (j - n_to_write + unchanged_at_top, i - j); | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
747 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
748 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
|
749 { |
25004 | 750 /* Queue the deletion of a group of lines */ |
751 queue->pos = i - n_to_write + unchanged_at_top; | |
752 queue->window = j + unchanged_at_top; | |
753 queue->count = i - j; | |
754 ++queue; | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
755 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
756 |
25004 | 757 while (n_to_write > 0) |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
758 { |
25004 | 759 --i, --j, --n_to_write; |
760 copy_from[i] = j; | |
761 retained_p[j] = 1; | |
10262
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 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
764 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
765 |
25004 | 766 /* Do queued operations. */ |
767 if (queue > queue_start) | |
768 { | |
769 int next = -1; | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
770 |
25004 | 771 do |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
772 { |
25004 | 773 --queue; |
774 if (queue->count) | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
775 { |
25004 | 776 set_terminal_window (queue->window); |
777 terminal_window_p = 1; | |
778 ins_del_lines (queue->pos, queue->count); | |
779 } | |
780 else | |
781 { | |
782 for (j = queue->window - 1; j >= queue->pos; --j) | |
783 { | |
784 while (retained_p[++next]) | |
785 ; | |
786 copy_from[j] = next; | |
787 } | |
10262
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 } |
25004 | 790 while (queue > queue_start); |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
791 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
792 |
25004 | 793 /* Now, for each row I in the range of rows we are working on, |
794 copy_from[i] gives the original line to copy to I, and | |
795 retained_p[copy_from[i]] is zero if line I in the new display is | |
796 empty. */ | |
797 mirrored_line_dance (current_matrix, unchanged_at_top, window_size, | |
798 copy_from, retained_p); | |
799 | |
800 if (terminal_window_p) | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
801 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
|
802 } |
25004 | 803 |
804 | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
805 |
154 | 806 void |
766 | 807 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
|
808 draw_cost, old_draw_cost, old_hash, new_hash, free_at_end) |
766 | 809 FRAME_PTR frame; |
154 | 810 int window_size, unchanged_at_top, unchanged_at_bottom; |
811 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
|
812 int *old_draw_cost; |
154 | 813 int *old_hash; |
814 int *new_hash; | |
815 int free_at_end; | |
816 { | |
817 struct matrix_elt *matrix; | |
818 matrix = ((struct matrix_elt *) | |
819 alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix)); | |
820 | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
821 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
|
822 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
823 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
|
824 unchanged_at_bottom, |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
825 draw_cost, old_draw_cost, |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
826 old_hash, new_hash, free_at_end); |
25004 | 827 do_direct_scrolling (frame->current_matrix, |
828 matrix, window_size, unchanged_at_top); | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
829 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
830 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
831 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
832 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
|
833 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
|
834 free_at_end); |
25004 | 835 do_scrolling (frame->current_matrix, matrix, window_size, |
836 unchanged_at_top); | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
837 } |
154 | 838 } |
25004 | 839 |
840 | |
154 | 841 |
25004 | 842 /* Return number of lines in common between current and desired frame |
843 contents described to us only as vectors of hash codes OLDHASH and | |
844 NEWHASH. Consider only vpos range START to END (not including | |
845 END). Ignore short lines on the assumption that avoiding redrawing | |
846 such a line will have little weight. */ | |
154 | 847 |
848 int | |
849 scrolling_max_lines_saved (start, end, oldhash, newhash, cost) | |
850 int start, end; | |
851 int *oldhash, *newhash, *cost; | |
852 { | |
853 struct { int hash; int count; } lines[01000]; | |
854 register int i, h; | |
855 register int matchcount = 0; | |
856 int avg_length = 0; | |
857 int threshold; | |
858 | |
859 /* Compute a threshold which is 1/4 of average length of these lines. */ | |
860 | |
861 for (i = start; i < end; i++) | |
862 avg_length += cost[i]; | |
863 | |
864 avg_length /= end - start; | |
865 threshold = avg_length / 4; | |
866 | |
867 bzero (lines, sizeof lines); | |
868 | |
25004 | 869 /* Put new lines' hash codes in hash table. Ignore lines shorter |
870 than the threshold. Thus, if the lines that are in common are | |
871 mainly the ones that are short, they won't count. */ | |
154 | 872 for (i = start; i < end; i++) |
873 { | |
874 if (cost[i] > threshold) | |
875 { | |
876 h = newhash[i] & 0777; | |
877 lines[h].hash = newhash[i]; | |
878 lines[h].count++; | |
879 } | |
880 } | |
881 | |
25004 | 882 /* Look up old line hash codes in the hash table. Count number of |
883 matches between old lines and new. */ | |
154 | 884 for (i = start; i < end; i++) |
885 { | |
886 h = oldhash[i] & 0777; | |
887 if (oldhash[i] == lines[h].hash) | |
888 { | |
889 matchcount++; | |
890 if (--lines[h].count == 0) | |
891 lines[h].hash = 0; | |
892 } | |
893 } | |
894 | |
895 return matchcount; | |
896 } | |
897 | |
25004 | 898 /* Return a measure of the cost of moving the lines starting with vpos |
899 FROM, up to but not including vpos TO, down by AMOUNT lines (AMOUNT | |
900 may be negative). These are the same arguments that might be given | |
901 to scroll_frame_lines to perform this scrolling. */ | |
154 | 902 |
21514 | 903 int |
766 | 904 scroll_cost (frame, from, to, amount) |
905 FRAME_PTR frame; | |
154 | 906 int from, to, amount; |
907 { | |
766 | 908 /* Compute how many lines, at bottom of frame, |
154 | 909 will not be involved in actual motion. */ |
910 int limit = to; | |
911 int offset; | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
912 int height = FRAME_LINES (frame); |
154 | 913 |
421 | 914 if (amount == 0) |
915 return 0; | |
916 | |
154 | 917 if (! scroll_region_ok) |
918 limit = height; | |
421 | 919 else if (amount > 0) |
920 limit += amount; | |
154 | 921 |
922 if (amount < 0) | |
923 { | |
924 int temp = to; | |
925 to = from + amount; | |
926 from = temp + amount; | |
927 amount = - amount; | |
928 } | |
929 | |
930 offset = height - limit; | |
931 | |
932 return | |
766 | 933 (FRAME_INSERT_COST (frame)[offset + from] |
934 + (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
|
935 + 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
|
936 + (amount - 1) * FRAME_DELETEN_COST (frame)[offset + to]); |
154 | 937 } |
938 | |
939 /* Calculate the line insertion/deletion | |
940 overhead and multiply factor values */ | |
941 | |
942 static void | |
766 | 943 line_ins_del (frame, ov1, pf1, ovn, pfn, ov, mf) |
944 FRAME_PTR frame; | |
154 | 945 int ov1, ovn; |
946 int pf1, pfn; | |
947 register int *ov, *mf; | |
948 { | |
949 register int i; | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
950 register int frame_lines = FRAME_LINES (frame); |
154 | 951 register int insert_overhead = ov1 * 10; |
952 register int next_insert_cost = ovn * 10; | |
953 | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
954 for (i = frame_lines-1; i >= 0; i--) |
154 | 955 { |
529 | 956 mf[i] = next_insert_cost / 10; |
154 | 957 next_insert_cost += pfn; |
529 | 958 ov[i] = (insert_overhead + next_insert_cost) / 10; |
154 | 959 insert_overhead += pf1; |
960 } | |
961 } | |
962 | |
963 static void | |
766 | 964 ins_del_costs (frame, |
154 | 965 one_line_string, multi_string, |
966 setup_string, cleanup_string, | |
967 costvec, ncostvec, coefficient) | |
766 | 968 FRAME_PTR frame; |
154 | 969 char *one_line_string, *multi_string; |
970 char *setup_string, *cleanup_string; | |
971 int *costvec, *ncostvec; | |
972 int coefficient; | |
973 { | |
974 if (multi_string) | |
766 | 975 line_ins_del (frame, |
154 | 976 string_cost (multi_string) * coefficient, |
977 per_line_cost (multi_string) * coefficient, | |
978 0, 0, costvec, ncostvec); | |
979 else if (one_line_string) | |
766 | 980 line_ins_del (frame, |
154 | 981 string_cost (setup_string) + string_cost (cleanup_string), 0, |
982 string_cost (one_line_string), | |
983 per_line_cost (one_line_string), | |
984 costvec, ncostvec); | |
985 else | |
766 | 986 line_ins_del (frame, |
154 | 987 9999, 0, 9999, 0, |
988 costvec, ncostvec); | |
989 } | |
990 | |
991 /* Calculate the insert and delete line costs. | |
992 Note that this is done even when running with a window system | |
993 because we want to know how long scrolling takes (and avoid it). | |
766 | 994 This must be redone whenever the frame height changes. |
154 | 995 |
996 We keep the ID costs in a precomputed array based on the position | |
997 at which the I or D is performed. Also, there are two kinds of ID | |
998 costs: the "once-only" and the "repeated". This is to handle both | |
999 those terminals that are able to insert N lines at a time (once- | |
1000 only) and those that must repeatedly insert one line. | |
1001 | |
1002 The cost to insert N lines at line L is | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1003 [tt.t_ILov + (frame_lines + 1 - L) * tt.t_ILpf] + |
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1004 N * [tt.t_ILnov + (frame_lines + 1 - L) * tt.t_ILnpf] |
154 | 1005 |
1006 ILov represents the basic insert line overhead. ILpf is the padding | |
1007 required to allow the terminal time to move a line: insertion at line | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1008 L changes (frame_lines + 1 - L) lines. |
154 | 1009 |
1010 The first bracketed expression above is the overhead; the second is | |
1011 the multiply factor. Both are dependent only on the position at | |
1012 which the insert is performed. We store the overhead in | |
766 | 1013 FRAME_INSERT_COST (frame) and the multiply factor in |
1014 FRAME_INSERTN_COST (frame). Note however that any insertion | |
154 | 1015 must include at least one multiply factor. Rather than compute this |
766 | 1016 as FRAME_INSERT_COST (frame)[line]+FRAME_INSERTN_COST (frame)[line], |
1017 we add FRAME_INSERTN_COST (frame) into FRAME_INSERT_COST (frame). | |
154 | 1018 This is reasonable because of the particular algorithm used in calcM. |
1019 | |
1020 Deletion is essentially the same as insertion. | |
1021 */ | |
1022 | |
21514 | 1023 void |
766 | 1024 do_line_insertion_deletion_costs (frame, |
154 | 1025 ins_line_string, multi_ins_string, |
1026 del_line_string, multi_del_string, | |
1027 setup_string, cleanup_string, coefficient) | |
766 | 1028 FRAME_PTR frame; |
154 | 1029 char *ins_line_string, *multi_ins_string; |
1030 char *del_line_string, *multi_del_string; | |
1031 char *setup_string, *cleanup_string; | |
1032 int coefficient; | |
1033 { | |
766 | 1034 if (FRAME_INSERT_COST (frame) != 0) |
154 | 1035 { |
766 | 1036 FRAME_INSERT_COST (frame) = |
1037 (int *) xrealloc (FRAME_INSERT_COST (frame), | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1038 FRAME_LINES (frame) * sizeof (int)); |
766 | 1039 FRAME_DELETEN_COST (frame) = |
1040 (int *) xrealloc (FRAME_DELETEN_COST (frame), | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1041 FRAME_LINES (frame) * sizeof (int)); |
766 | 1042 FRAME_INSERTN_COST (frame) = |
1043 (int *) xrealloc (FRAME_INSERTN_COST (frame), | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1044 FRAME_LINES (frame) * sizeof (int)); |
766 | 1045 FRAME_DELETE_COST (frame) = |
1046 (int *) xrealloc (FRAME_DELETE_COST (frame), | |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1047 FRAME_LINES (frame) * sizeof (int)); |
154 | 1048 } |
1049 else | |
1050 { | |
766 | 1051 FRAME_INSERT_COST (frame) = |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1052 (int *) xmalloc (FRAME_LINES (frame) * sizeof (int)); |
766 | 1053 FRAME_DELETEN_COST (frame) = |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1054 (int *) xmalloc (FRAME_LINES (frame) * sizeof (int)); |
766 | 1055 FRAME_INSERTN_COST (frame) = |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1056 (int *) xmalloc (FRAME_LINES (frame) * sizeof (int)); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48323
diff
changeset
|
1057 FRAME_DELETE_COST (frame) = |
51212
332134065648
Make (some) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
1058 (int *) xmalloc (FRAME_LINES (frame) * sizeof (int)); |
154 | 1059 } |
1060 | |
766 | 1061 ins_del_costs (frame, |
154 | 1062 ins_line_string, multi_ins_string, |
1063 setup_string, cleanup_string, | |
766 | 1064 FRAME_INSERT_COST (frame), FRAME_INSERTN_COST (frame), |
154 | 1065 coefficient); |
766 | 1066 ins_del_costs (frame, |
154 | 1067 del_line_string, multi_del_string, |
1068 setup_string, cleanup_string, | |
9576
14cd96eda0e3
(do_line_insertion_deletion_costs): Fix argument order.
Karl Heuer <kwzh@gnu.org>
parents:
7307
diff
changeset
|
1069 FRAME_DELETE_COST (frame), FRAME_DELETEN_COST (frame), |
154 | 1070 coefficient); |
1071 } | |
52401 | 1072 |
1073 /* arch-tag: cdb7149c-48e7-4793-a948-2786c8e45485 | |
1074 (do not change this comment) */ |