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