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