314
|
1 /* Updating of data structures for redisplay.
|
|
2 Copyright (C) 1985, 1986, 1987, 1988, 1990 Free Software Foundation, Inc.
|
|
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
|
|
8 the Free Software Foundation; either version 1, or (at your option)
|
|
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
|
|
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
19
|
|
20
|
|
21 #include <signal.h>
|
|
22
|
|
23 #include "config.h"
|
|
24 #include <stdio.h>
|
|
25 #include <ctype.h>
|
|
26
|
|
27 #ifdef NEED_TIME_H
|
|
28 #include <time.h>
|
|
29 #else /* not NEED_TIME_H */
|
|
30 #ifdef HAVE_TIMEVAL
|
|
31 #include <sys/time.h>
|
|
32 #endif /* HAVE_TIMEVAL */
|
|
33 #endif /* not NEED_TIME_H */
|
|
34
|
|
35 #ifdef HAVE_TERMIO
|
|
36 #include <termio.h>
|
|
37 #ifdef TCOUTQ
|
|
38 #undef TIOCOUTQ
|
|
39 #define TIOCOUTQ TCOUTQ
|
|
40 #endif /* TCOUTQ defined */
|
|
41 #include <fcntl.h>
|
|
42 #else
|
|
43 #ifndef VMS
|
|
44 #include <sys/ioctl.h>
|
|
45 #endif /* not VMS */
|
|
46 #endif /* not HAVE_TERMIO */
|
|
47
|
|
48 /* Allow m- file to inhibit use of FIONREAD. */
|
|
49 #ifdef BROKEN_FIONREAD
|
|
50 #undef FIONREAD
|
|
51 #endif
|
|
52
|
|
53 /* Interupt input is not used if there is no FIONREAD. */
|
|
54 #ifndef FIONREAD
|
|
55 #undef SIGIO
|
|
56 #endif
|
|
57
|
|
58 #include "termchar.h"
|
|
59 #include "termopts.h"
|
|
60 #include "cm.h"
|
|
61 #include "lisp.h"
|
|
62 #include "dispextern.h"
|
|
63 #include "buffer.h"
|
|
64 #include "screen.h"
|
|
65 #include "window.h"
|
|
66 #include "commands.h"
|
|
67 #include "disptab.h"
|
|
68 #include "indent.h"
|
|
69
|
|
70 #ifdef HAVE_X_WINDOWS
|
|
71 #include "xterm.h"
|
|
72 #endif /* HAVE_X_WINDOWS */
|
|
73
|
|
74 #define max(a, b) ((a) > (b) ? (a) : (b))
|
|
75 #define min(a, b) ((a) < (b) ? (a) : (b))
|
|
76
|
|
77 #ifndef PENDING_OUTPUT_COUNT
|
|
78 /* Get number of chars of output now in the buffer of a stdio stream.
|
|
79 This ought to be built in in stdio, but it isn't.
|
|
80 Some s- files override this because their stdio internals differ. */
|
|
81 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
|
|
82 #endif
|
|
83
|
|
84 /* Nonzero means do not assume anything about current
|
|
85 contents of actual terminal screen */
|
|
86
|
|
87 int screen_garbaged;
|
|
88
|
|
89 /* Nonzero means last display completed. Zero means it was preempted. */
|
|
90
|
|
91 int display_completed;
|
|
92
|
|
93 /* Lisp variable visible-bell; enables use of screen-flash
|
|
94 instead of audible bell. */
|
|
95
|
|
96 int visible_bell;
|
|
97
|
|
98 /* Invert the color of the whole screen, at a low level. */
|
|
99
|
|
100 int inverse_video;
|
|
101
|
|
102 /* Line speed of the terminal. */
|
|
103
|
|
104 int baud_rate;
|
|
105
|
|
106 /* nil or a symbol naming the window system under which emacs is
|
|
107 running ('x is the only current possibility). */
|
|
108
|
|
109 Lisp_Object Vwindow_system;
|
|
110
|
|
111 /* Version number of X windows: 10, 11 or nil. */
|
|
112 Lisp_Object Vwindow_system_version;
|
|
113
|
|
114 /* Vector of glyph definitions. Indexed by glyph number,
|
|
115 the contents are a string which is how to output the glyph.
|
|
116
|
|
117 If Vglyph_table is nil, a glyph is output by using its low 8 bits
|
|
118 as a character code. */
|
|
119
|
|
120 Lisp_Object Vglyph_table;
|
|
121
|
|
122 /* Display table to use for vectors that don't specify their own. */
|
|
123
|
|
124 Lisp_Object Vstandard_display_table;
|
|
125
|
|
126 /* Nonzero means reading single-character input with prompt
|
|
127 so put cursor on minibuffer after the prompt. */
|
|
128
|
|
129 int cursor_in_echo_area;
|
|
130
|
|
131 /* The currently selected screen.
|
|
132 In a single-screen version, this variable always remains 0. */
|
|
133
|
|
134 SCREEN_PTR selected_screen;
|
|
135
|
|
136 /* In a single-screen version, the information that would otherwise
|
|
137 exist inside a `struct screen' lives in the following variables instead. */
|
|
138
|
|
139 #ifndef MULTI_SCREEN
|
|
140
|
|
141 /* Desired terminal cursor position (to show position of point),
|
|
142 origin zero */
|
|
143
|
|
144 int cursX, cursY;
|
|
145
|
|
146 /* Description of current screen contents */
|
|
147
|
|
148 struct screen_glyphs *current_glyphs;
|
|
149
|
|
150 /* Description of desired screen contents */
|
|
151
|
|
152 struct screen_glyphs *desired_glyphs;
|
|
153
|
|
154 #endif /* not MULTI_SCREEN */
|
|
155
|
|
156 /* This is a vector, made larger whenever it isn't large enough,
|
|
157 which is used inside `update_screen' to hold the old contents
|
|
158 of the SCREEN_PHYS_LINES of the screen being updated. */
|
|
159 struct screen_glyphs **ophys_lines;
|
|
160 /* Length of vector currently allocated. */
|
|
161 int ophys_lines_length;
|
|
162
|
|
163 FILE *termscript; /* Stdio stream being used for copy of all output. */
|
|
164
|
|
165 struct cm Wcm; /* Structure for info on cursor positioning */
|
|
166
|
|
167 extern short ospeed; /* Output speed (from sg_ospeed) */
|
|
168
|
|
169 int in_display; /* 1 if in redisplay: can't handle SIGWINCH now. */
|
|
170
|
|
171 int delayed_size_change; /* 1 means SIGWINCH happened when not safe. */
|
|
172 int delayed_screen_height; /* Remembered new screen height. */
|
|
173 int delayed_screen_width; /* Remembered new screen width. */
|
|
174
|
|
175 #ifdef MULTI_SCREEN
|
|
176
|
|
177 DEFUN ("redraw-screen", Fredraw_screen, Sredraw_screen, 1, 1, 0,
|
|
178 "Clear screen SCREEN and output again what is supposed to appear on it.")
|
|
179 (screen)
|
|
180 Lisp_Object screen;
|
|
181 {
|
|
182 SCREEN_PTR s;
|
|
183
|
493
|
184 CHECK_LIVE_SCREEN (screen, 0);
|
314
|
185 s = XSCREEN (screen);
|
|
186 update_begin (s);
|
|
187 /* set_terminal_modes (); */
|
|
188 clear_screen ();
|
|
189 update_end (s);
|
|
190 fflush (stdout);
|
|
191 clear_screen_records (s);
|
|
192 windows_or_buffers_changed++;
|
|
193 /* Mark all windows as INaccurate,
|
|
194 so that every window will have its redisplay done. */
|
|
195 mark_window_display_accurate (SCREEN_ROOT_WINDOW (s), 0);
|
|
196 s->garbaged = 0;
|
|
197 return Qnil;
|
|
198 }
|
|
199
|
|
200 DEFUN ("redraw-display", Fredraw_display, Sredraw_display, 0, 0, "",
|
|
201 "Redraw all screens marked as having their images garbled.")
|
|
202 ()
|
|
203 {
|
|
204 Lisp_Object screen, tail;
|
|
205
|
|
206 for (tail = Vscreen_list; CONSP (tail); tail = XCONS (tail)->cdr)
|
|
207 {
|
|
208 screen = XCONS (tail)->car;
|
|
209 if (XSCREEN (screen)->garbaged && XSCREEN (screen)->visible)
|
|
210 Fredraw_screen (screen);
|
|
211 }
|
|
212 return Qnil;
|
|
213 }
|
|
214
|
|
215 redraw_screen (s)
|
|
216 SCREEN_PTR s;
|
|
217 {
|
|
218 Lisp_Object screen;
|
|
219 XSET (screen, Lisp_Screen, s);
|
|
220 Fredraw_screen (screen);
|
|
221 }
|
|
222
|
|
223 #else /* not MULTI_SCREEN */
|
|
224
|
|
225 DEFUN ("redraw-display", Fredraw_display, Sredraw_display, 0, 0, 0,
|
|
226 "Clear screen and output again what is supposed to appear on it.")
|
|
227 ()
|
|
228 {
|
|
229 update_begin (0);
|
|
230 set_terminal_modes ();
|
|
231 clear_screen ();
|
|
232 update_end (0);
|
|
233 fflush (stdout);
|
|
234 clear_screen_records (0);
|
|
235 windows_or_buffers_changed++;
|
|
236 /* Mark all windows as INaccurate,
|
|
237 so that every window will have its redisplay done. */
|
|
238 mark_window_display_accurate (XWINDOW (minibuf_window)->prev, 0);
|
|
239 return Qnil;
|
|
240 }
|
|
241
|
|
242 #endif /* not MULTI_SCREEN */
|
|
243
|
|
244 static struct screen_glyphs *
|
|
245 make_screen_glyphs (screen, empty)
|
|
246 register SCREEN_PTR screen;
|
|
247 int empty;
|
|
248 {
|
|
249 register int i;
|
|
250 register width = SCREEN_WIDTH (screen);
|
|
251 register height = SCREEN_HEIGHT (screen);
|
|
252 register struct screen_glyphs *new =
|
|
253 (struct screen_glyphs *) xmalloc (sizeof (struct screen_glyphs));
|
|
254
|
|
255 SET_GLYPHS_SCREEN (new, screen);
|
|
256 new->height = height;
|
|
257 new->width = width;
|
|
258 new->used = (int *) xmalloc (height * sizeof (int));
|
|
259 new->glyphs = (GLYPH **) xmalloc (height * sizeof (GLYPH *));
|
|
260 new->highlight = (char *) xmalloc (height * sizeof (char));
|
|
261 new->enable = (char *) xmalloc (height * sizeof (char));
|
|
262 bzero (new->enable, height * sizeof (char));
|
|
263 new->bufp = (int *) xmalloc (height * sizeof (int));
|
|
264
|
|
265 #ifdef HAVE_X_WINDOWS
|
|
266 if (SCREEN_IS_X (screen))
|
|
267 {
|
|
268 new->nruns = (int *) xmalloc (height * sizeof (int));
|
|
269 new->face_list
|
|
270 = (struct run **) xmalloc (height * sizeof (struct run *));
|
|
271 new->top_left_x = (short *) xmalloc (height * sizeof (short));
|
|
272 new->top_left_y = (short *) xmalloc (height * sizeof (short));
|
|
273 new->pix_width = (short *) xmalloc (height * sizeof (short));
|
|
274 new->pix_height = (short *) xmalloc (height * sizeof (short));
|
|
275 }
|
|
276 #endif
|
|
277
|
|
278 if (empty)
|
|
279 {
|
|
280 /* Make the buffer used by decode_mode_spec. This buffer is also
|
|
281 used as temporary storage when updating the screen. See scroll.c. */
|
|
282 unsigned int total_glyphs = (width + 2) * sizeof (GLYPH);
|
|
283
|
|
284 new->total_contents = (GLYPH *) xmalloc (total_glyphs);
|
|
285 bzero (new->total_contents, total_glyphs);
|
|
286 }
|
|
287 else
|
|
288 {
|
|
289 unsigned int total_glyphs = height * (width + 2) * sizeof (GLYPH);
|
|
290
|
|
291 new->total_contents = (GLYPH *) xmalloc (total_glyphs);
|
|
292 bzero (new->total_contents, total_glyphs);
|
|
293 for (i = 0; i < height; i++)
|
|
294 new->glyphs[i] = new->total_contents + i * (width + 2) + 1;
|
|
295 }
|
|
296
|
|
297 return new;
|
|
298 }
|
|
299
|
|
300 static void
|
|
301 free_screen_glyphs (screen, glyphs)
|
|
302 SCREEN_PTR screen;
|
|
303 struct screen_glyphs *glyphs;
|
|
304 {
|
|
305 if (glyphs->total_contents)
|
|
306 free (glyphs->total_contents);
|
|
307
|
|
308 free (glyphs->used);
|
|
309 free (glyphs->glyphs);
|
|
310 free (glyphs->highlight);
|
|
311 free (glyphs->enable);
|
|
312 free (glyphs->bufp);
|
|
313
|
|
314 #ifdef HAVE_X_WINDOWS
|
|
315 if (SCREEN_IS_X (screen))
|
|
316 {
|
|
317 free (glyphs->nruns);
|
|
318 free (glyphs->face_list);
|
|
319 free (glyphs->top_left_x);
|
|
320 free (glyphs->top_left_y);
|
|
321 free (glyphs->pix_width);
|
|
322 free (glyphs->pix_height);
|
|
323 }
|
|
324 #endif
|
|
325
|
|
326 free (glyphs);
|
|
327 }
|
|
328
|
|
329 static void
|
|
330 remake_screen_glyphs (screen)
|
|
331 SCREEN_PTR screen;
|
|
332 {
|
|
333 if (SCREEN_CURRENT_GLYPHS (screen))
|
|
334 free_screen_glyphs (screen, SCREEN_CURRENT_GLYPHS (screen));
|
|
335 if (SCREEN_DESIRED_GLYPHS (screen))
|
|
336 free_screen_glyphs (screen, SCREEN_DESIRED_GLYPHS (screen));
|
|
337 if (SCREEN_TEMP_GLYPHS (screen))
|
|
338 free_screen_glyphs (screen, SCREEN_TEMP_GLYPHS (screen));
|
|
339
|
|
340 if (SCREEN_MESSAGE_BUF (screen))
|
|
341 SCREEN_MESSAGE_BUF (screen)
|
|
342 = (char *) xrealloc (SCREEN_MESSAGE_BUF (screen),
|
|
343 SCREEN_WIDTH (screen) + 1);
|
|
344 else
|
|
345 SCREEN_MESSAGE_BUF (screen)
|
|
346 = (char *) xmalloc (SCREEN_WIDTH (screen) + 1);
|
|
347
|
|
348 SCREEN_CURRENT_GLYPHS (screen) = make_screen_glyphs (screen, 0);
|
|
349 SCREEN_DESIRED_GLYPHS (screen) = make_screen_glyphs (screen, 0);
|
|
350 SCREEN_TEMP_GLYPHS (screen) = make_screen_glyphs (screen, 1);
|
|
351 SET_SCREEN_GARBAGED (screen);
|
|
352 }
|
|
353
|
|
354 /* Return the hash code of contents of line VPOS in screen-matrix M. */
|
|
355
|
|
356 static int
|
|
357 line_hash_code (m, vpos)
|
|
358 register struct screen_glyphs *m;
|
|
359 int vpos;
|
|
360 {
|
|
361 register GLYPH *body, *end;
|
|
362 register int h = 0;
|
|
363
|
|
364 if (!m->enable[vpos])
|
|
365 return 0;
|
|
366
|
|
367 /* Give all lighlighted lines the same hash code
|
|
368 so as to encourage scrolling to leave them in place. */
|
|
369 if (m->highlight[vpos])
|
|
370 return -1;
|
|
371
|
|
372 body = m->glyphs[vpos];
|
|
373
|
|
374 if (must_write_spaces)
|
|
375 while (1)
|
|
376 {
|
|
377 GLYPH g = *body++;
|
|
378
|
|
379 if (g == 0)
|
|
380 break;
|
|
381 h = (((h << 4) + (h >> 24)) & 0x0fffffff) + g - SPACEGLYPH;
|
|
382 }
|
|
383 else
|
|
384 while (1)
|
|
385 {
|
|
386 GLYPH g = *body++;
|
|
387
|
|
388 if (g == 0)
|
|
389 break;
|
|
390 h = (((h << 4) + (h >> 24)) & 0x0fffffff) + g;
|
|
391 }
|
|
392
|
|
393 if (h)
|
|
394 return h;
|
|
395 return 1;
|
|
396 }
|
|
397
|
|
398 /* Return number of characters in line in M at vpos VPOS,
|
|
399 except don't count leading and trailing spaces
|
|
400 unless the terminal requires those to be explicitly output. */
|
|
401
|
|
402 static unsigned int
|
|
403 line_draw_cost (m, vpos)
|
|
404 struct screen_glyphs *m;
|
|
405 int vpos;
|
|
406 {
|
|
407 register GLYPH *beg = m->glyphs[vpos];
|
|
408 register GLYPH *end = m->glyphs[vpos] + m->used[vpos];
|
|
409 register int i;
|
|
410 register int tlen = GLYPH_TABLE_LENGTH;
|
|
411 register Lisp_Object *tbase = GLYPH_TABLE_BASE;
|
|
412
|
|
413 /* Ignore trailing and leading spaces if we can. */
|
|
414 if (!must_write_spaces)
|
|
415 {
|
|
416 while ((end != beg) && (*end == SPACEGLYPH))
|
|
417 --end;
|
|
418 if (end == beg)
|
|
419 return (0); /* All blank line. */
|
|
420
|
|
421 while (*beg == SPACEGLYPH)
|
|
422 ++beg;
|
|
423 }
|
|
424
|
|
425 /* If we don't have a glyph-table, each glyph is one character,
|
|
426 so return the number of glyphs. */
|
|
427 if (tbase == 0)
|
|
428 return end - beg;
|
|
429
|
|
430 /* Otherwise, scan the glyphs and accumulate their total size in I. */
|
|
431 i = 0;
|
|
432 while ((beg <= end) && *beg)
|
|
433 {
|
|
434 register GLYPH g = *beg++;
|
|
435
|
|
436 if (GLYPH_SIMPLE_P (tbase, tlen, g))
|
|
437 i += 1;
|
|
438 else
|
|
439 i += GLYPH_LENGTH (tbase, g);
|
|
440 }
|
|
441 return i;
|
|
442 }
|
|
443
|
|
444 /* The functions on this page are the interface from xdisp.c to redisplay.
|
|
445
|
|
446 The only other interface into redisplay is through setting
|
|
447 SCREEN_CURSOR_X (screen) and SCREEN_CURSOR_Y (screen)
|
|
448 and SET_SCREEN_GARBAGED (screen). */
|
|
449
|
|
450 /* cancel_line eliminates any request to display a line at position `vpos' */
|
|
451
|
|
452 cancel_line (vpos, screen)
|
|
453 int vpos;
|
|
454 register SCREEN_PTR screen;
|
|
455 {
|
|
456 SCREEN_DESIRED_GLYPHS (screen)->enable[vpos] = 0;
|
|
457 }
|
|
458
|
|
459 clear_screen_records (screen)
|
|
460 register SCREEN_PTR screen;
|
|
461 {
|
|
462 bzero (SCREEN_CURRENT_GLYPHS (screen)->enable, SCREEN_HEIGHT (screen));
|
|
463 }
|
|
464
|
|
465 /* Prepare to display on line VPOS starting at HPOS within it. */
|
|
466
|
|
467 void
|
|
468 get_display_line (screen, vpos, hpos)
|
|
469 register SCREEN_PTR screen;
|
|
470 int vpos;
|
|
471 register int hpos;
|
|
472 {
|
|
473 register struct screen_glyphs *glyphs;
|
|
474 register struct screen_glyphs *desired_glyphs = SCREEN_DESIRED_GLYPHS (screen);
|
|
475 register GLYPH *p;
|
|
476
|
|
477 if (vpos < 0 || (! SCREEN_VISIBLE_P (screen)))
|
|
478 abort ();
|
|
479
|
|
480 if ((desired_glyphs->enable[vpos]) && desired_glyphs->used[vpos] > hpos)
|
|
481 abort ();
|
|
482
|
|
483 if (! desired_glyphs->enable[vpos])
|
|
484 {
|
|
485 desired_glyphs->used[vpos] = 0;
|
|
486 desired_glyphs->highlight[vpos] = 0;
|
|
487 desired_glyphs->enable[vpos] = 1;
|
|
488 }
|
|
489
|
|
490 if (hpos > desired_glyphs->used[vpos])
|
|
491 {
|
|
492 GLYPH *g = desired_glyphs->glyphs[vpos] + desired_glyphs->used[vpos];
|
|
493 GLYPH *end = desired_glyphs->glyphs[vpos] + hpos;
|
|
494
|
|
495 desired_glyphs->used[vpos] = hpos;
|
|
496 while (g != end)
|
|
497 *g++ = SPACEGLYPH;
|
|
498 }
|
|
499 }
|
|
500
|
|
501 /* Like bcopy except never gets confused by overlap. */
|
|
502
|
|
503 void
|
|
504 safe_bcopy (from, to, size)
|
|
505 char *from, *to;
|
|
506 int size;
|
|
507 {
|
|
508 register char *endf;
|
|
509 register char *endt;
|
|
510
|
|
511 if (size == 0)
|
|
512 return;
|
|
513
|
|
514 /* If destination is higher in memory, and overlaps source zone,
|
|
515 copy from the end. */
|
|
516 if (from < to && from + size > to)
|
|
517 {
|
|
518 endf = from + size;
|
|
519 endt = to + size;
|
|
520
|
|
521 /* If TO - FROM is large, then we should break the copy into
|
|
522 nonoverlapping chunks of TO - FROM bytes each. However, if
|
|
523 TO - FROM is small, then the bcopy function call overhead
|
|
524 makes this not worth it. The crossover point could be about
|
|
525 anywhere. Since I don't think the obvious copy loop is ever
|
|
526 too bad, I'm trying to err in its favor. */
|
|
527 if (to - from < 64)
|
|
528 {
|
|
529 do
|
|
530 *--endt = *--endf;
|
|
531 while (endf != from);
|
|
532 }
|
|
533 else
|
|
534 {
|
352
|
535 /* Since TO - FROM >= 64, the overlap is less than SIZE,
|
|
536 so we can always safely do this loop once. */
|
314
|
537 while (endt > to)
|
|
538 {
|
|
539 endt -= (to - from);
|
|
540 endf -= (to - from);
|
|
541
|
|
542 bcopy (endf, endt, to - from);
|
|
543 }
|
|
544
|
|
545 /* If TO - FROM wasn't a multiple of SIZE, there will be a
|
|
546 little left over. The amount left over is
|
|
547 (endt + (to - from)) - to, which is endt - from. */
|
|
548 bcopy (from, to, endt - from);
|
|
549 }
|
|
550 }
|
|
551 else
|
|
552 bcopy (from, to, size);
|
|
553 }
|
|
554
|
|
555 #if 0
|
|
556 void
|
|
557 safe_bcopy (from, to, size)
|
|
558 char *from, *to;
|
|
559 int size;
|
|
560 {
|
|
561 register char *endf;
|
|
562 register char *endt;
|
|
563
|
|
564 if (size == 0)
|
|
565 return;
|
|
566
|
|
567 /* If destination is higher in memory, and overlaps source zone,
|
|
568 copy from the end. */
|
|
569 if (from < to && from + size > to)
|
|
570 {
|
|
571 endf = from + size;
|
|
572 endt = to + size;
|
|
573
|
|
574 do
|
|
575 *--endt = *--endf;
|
|
576 while (endf != from);
|
|
577
|
|
578 return;
|
|
579 }
|
|
580
|
|
581 bcopy (from, to, size);
|
|
582 }
|
|
583 #endif
|
|
584
|
352
|
585 /* Rotate a vector of SIZE bytes right, by DISTANCE bytes.
|
314
|
586 DISTANCE may be negative. */
|
|
587
|
|
588 static void
|
|
589 rotate_vector (vector, size, distance)
|
|
590 char *vector;
|
|
591 int size;
|
|
592 int distance;
|
|
593 {
|
|
594 char *temp = (char *) alloca (size);
|
|
595
|
|
596 if (distance < 0)
|
|
597 distance += size;
|
|
598
|
|
599 bcopy (vector, temp + distance, size - distance);
|
|
600 bcopy (vector + size - distance, temp, distance);
|
|
601 bcopy (temp, vector, size);
|
|
602 }
|
|
603
|
|
604 /* Scroll lines from vpos FROM up to but not including vpos END
|
|
605 down by AMOUNT lines (AMOUNT may be negative).
|
|
606 Returns nonzero if done, zero if terminal cannot scroll them. */
|
|
607
|
|
608 int
|
|
609 scroll_screen_lines (screen, from, end, amount)
|
|
610 register SCREEN_PTR screen;
|
|
611 int from, end, amount;
|
|
612 {
|
|
613 register int i;
|
|
614 register struct screen_glyphs *current_screen
|
|
615 = SCREEN_CURRENT_GLYPHS (screen);
|
|
616
|
|
617 if (!line_ins_del_ok)
|
|
618 return 0;
|
|
619
|
|
620 if (amount == 0)
|
|
621 return 1;
|
|
622
|
|
623 if (amount > 0)
|
|
624 {
|
|
625 update_begin (screen);
|
|
626 set_terminal_window (end + amount);
|
|
627 if (!scroll_region_ok)
|
|
628 ins_del_lines (end, -amount);
|
|
629 ins_del_lines (from, amount);
|
|
630 set_terminal_window (0);
|
|
631
|
|
632 rotate_vector (current_screen->glyphs + from,
|
|
633 sizeof (GLYPH *) * (end + amount - from),
|
|
634 amount * sizeof (GLYPH *));
|
|
635
|
|
636 safe_bcopy (current_screen->used + from,
|
|
637 current_screen->used + from + amount,
|
|
638 (end - from) * sizeof current_screen->used[0]);
|
|
639
|
|
640 safe_bcopy (current_screen->highlight + from,
|
|
641 current_screen->highlight + from + amount,
|
|
642 (end - from) * sizeof current_screen->highlight[0]);
|
|
643
|
|
644 safe_bcopy (current_screen->enable + from,
|
|
645 current_screen->enable + from + amount,
|
|
646 (end - from) * sizeof current_screen->enable[0]);
|
|
647
|
|
648 /* Mark the lines made empty by scrolling as enabled, empty and
|
|
649 normal video. */
|
|
650 bzero (current_screen->used + from,
|
|
651 amount * sizeof current_screen->used[0]);
|
|
652 bzero (current_screen->highlight + from,
|
|
653 amount * sizeof current_screen->highlight[0]);
|
|
654 for (i = from; i < from + amount; i++)
|
|
655 {
|
|
656 current_screen->glyphs[i][0] = '\0';
|
|
657 current_screen->enable[i] = 1;
|
|
658 }
|
|
659
|
|
660 safe_bcopy (current_screen->bufp + from,
|
|
661 current_screen->bufp + from + amount,
|
|
662 (end - from) * sizeof current_screen->bufp[0]);
|
|
663
|
|
664 #ifdef HAVE_X_WINDOWS
|
|
665 if (SCREEN_IS_X (screen))
|
|
666 {
|
|
667 safe_bcopy (current_screen->nruns + from,
|
|
668 current_screen->nruns + from + amount,
|
|
669 (end - from) * sizeof current_screen->nruns[0]);
|
|
670
|
|
671 safe_bcopy (current_screen->face_list + from,
|
|
672 current_screen->face_list + from + amount,
|
|
673 (end - from) * sizeof current_screen->face_list[0]);
|
|
674
|
|
675 safe_bcopy (current_screen->top_left_x + from,
|
|
676 current_screen->top_left_x + from + amount,
|
|
677 (end - from) * sizeof current_screen->top_left_x[0]);
|
|
678
|
|
679 safe_bcopy (current_screen->top_left_y + from,
|
|
680 current_screen->top_left_y + from + amount,
|
|
681 (end - from) * sizeof current_screen->top_left_y[0]);
|
|
682
|
|
683 safe_bcopy (current_screen->pix_width + from,
|
|
684 current_screen->pix_width + from + amount,
|
|
685 (end - from) * sizeof current_screen->pix_width[0]);
|
|
686
|
|
687 safe_bcopy (current_screen->pix_height + from,
|
|
688 current_screen->pix_height + from + amount,
|
|
689 (end - from) * sizeof current_screen->pix_height[0]);
|
|
690 }
|
|
691 #endif /* HAVE_X_WINDOWS */
|
|
692
|
|
693 update_end (screen);
|
|
694 }
|
|
695 if (amount < 0)
|
|
696 {
|
|
697 update_begin (screen);
|
|
698 set_terminal_window (end);
|
|
699 ins_del_lines (from + amount, amount);
|
|
700 if (!scroll_region_ok)
|
|
701 ins_del_lines (end + amount, -amount);
|
|
702 set_terminal_window (0);
|
|
703
|
|
704 rotate_vector (current_screen->glyphs + from + amount,
|
|
705 sizeof (GLYPH *) * (end - from - amount),
|
|
706 amount * sizeof (GLYPH *));
|
|
707
|
|
708 safe_bcopy (current_screen->used + from,
|
|
709 current_screen->used + from + amount,
|
|
710 (end - from) * sizeof current_screen->used[0]);
|
|
711
|
|
712 safe_bcopy (current_screen->highlight + from,
|
|
713 current_screen->highlight + from + amount,
|
|
714 (end - from) * sizeof current_screen->highlight[0]);
|
|
715
|
|
716 safe_bcopy (current_screen->enable + from,
|
|
717 current_screen->enable + from + amount,
|
|
718 (end - from) * sizeof current_screen->enable[0]);
|
|
719
|
|
720 /* Mark the lines made empty by scrolling as enabled, empty and
|
|
721 normal video. */
|
|
722 bzero (current_screen->used + end + amount,
|
|
723 - amount * sizeof current_screen->used[0]);
|
|
724 bzero (current_screen->highlight + end + amount,
|
|
725 - amount * sizeof current_screen->highlight[0]);
|
|
726 for (i = end + amount; i < end; i++)
|
|
727 {
|
|
728 current_screen->glyphs[i][0] = '\0';
|
|
729 current_screen->enable[i] = 1;
|
|
730 }
|
|
731
|
|
732 safe_bcopy (current_screen->bufp + from,
|
|
733 current_screen->bufp + from + amount,
|
|
734 (end - from) * sizeof current_screen->bufp[0]);
|
|
735
|
|
736 #ifdef HAVE_X_WINDOWS
|
|
737 if (SCREEN_IS_X (screen))
|
|
738 {
|
|
739 safe_bcopy (current_screen->nruns + from,
|
|
740 current_screen->nruns + from + amount,
|
|
741 (end - from) * sizeof current_screen->nruns[0]);
|
|
742
|
|
743 safe_bcopy (current_screen->face_list + from,
|
|
744 current_screen->face_list + from + amount,
|
|
745 (end - from) * sizeof current_screen->face_list[0]);
|
|
746
|
|
747 safe_bcopy (current_screen->top_left_x + from,
|
|
748 current_screen->top_left_x + from + amount,
|
|
749 (end - from) * sizeof current_screen->top_left_x[0]);
|
|
750
|
|
751 safe_bcopy (current_screen->top_left_y + from,
|
|
752 current_screen->top_left_y + from + amount,
|
|
753 (end - from) * sizeof current_screen->top_left_y[0]);
|
|
754
|
|
755 safe_bcopy (current_screen->pix_width + from,
|
|
756 current_screen->pix_width + from + amount,
|
|
757 (end - from) * sizeof current_screen->pix_width[0]);
|
|
758
|
|
759 safe_bcopy (current_screen->pix_height + from,
|
|
760 current_screen->pix_height + from + amount,
|
|
761 (end - from) * sizeof current_screen->pix_height[0]);
|
|
762 }
|
|
763 #endif /* HAVE_X_WINDOWS */
|
|
764
|
|
765 update_end (screen);
|
|
766 }
|
|
767 return 1;
|
|
768 }
|
|
769
|
|
770 /* After updating a window W that isn't the full screen wide,
|
|
771 copy all the columns that W does not occupy
|
|
772 into the SCREEN_DESIRED_GLYPHS (screen) from the SCREEN_PHYS_GLYPHS (screen)
|
|
773 so that update_screen will not change those columns. */
|
|
774
|
|
775 preserve_other_columns (w)
|
|
776 struct window *w;
|
|
777 {
|
|
778 register int vpos;
|
|
779 register struct screen_glyphs *current_screen, *desired_screen;
|
|
780 register SCREEN_PTR screen = XSCREEN (w->screen);
|
|
781 int start = XFASTINT (w->left);
|
|
782 int end = XFASTINT (w->left) + XFASTINT (w->width);
|
|
783 int bot = XFASTINT (w->top) + XFASTINT (w->height);
|
|
784
|
|
785 current_screen = SCREEN_CURRENT_GLYPHS (screen);
|
|
786 desired_screen = SCREEN_DESIRED_GLYPHS (screen);
|
|
787
|
|
788 for (vpos = XFASTINT (w->top); vpos < bot; vpos++)
|
|
789 {
|
|
790 if (current_screen->enable[vpos] && desired_screen->enable[vpos])
|
|
791 {
|
|
792 if (start > 0)
|
|
793 {
|
|
794 int len;
|
|
795
|
|
796 bcopy (current_screen->glyphs[vpos],
|
|
797 desired_screen->glyphs[vpos], start);
|
|
798 len = min (start, current_screen->used[vpos]);
|
|
799 if (desired_screen->used[vpos] < len)
|
|
800 desired_screen->used[vpos] = len;
|
|
801 }
|
|
802 if (current_screen->used[vpos] > end
|
|
803 && desired_screen->used[vpos] < current_screen->used[vpos])
|
|
804 {
|
|
805 while (desired_screen->used[vpos] < end)
|
|
806 desired_screen->glyphs[vpos][desired_screen->used[vpos]++]
|
|
807 = SPACEGLYPH;
|
|
808 bcopy (current_screen->glyphs[vpos] + end,
|
|
809 desired_screen->glyphs[vpos] + end,
|
|
810 current_screen->used[vpos] - end);
|
|
811 desired_screen->used[vpos] = current_screen->used[vpos];
|
|
812 }
|
|
813 }
|
|
814 }
|
|
815 }
|
|
816
|
|
817 #if 0
|
|
818
|
|
819 /* If window w does not need to be updated and isn't the full screen wide,
|
|
820 copy all the columns that w does occupy
|
|
821 into the SCREEN_DESIRED_LINES (screen) from the SCREEN_PHYS_LINES (screen)
|
|
822 so that update_screen will not change those columns.
|
|
823
|
|
824 Have not been able to figure out how to use this correctly. */
|
|
825
|
|
826 preserve_my_columns (w)
|
|
827 struct window *w;
|
|
828 {
|
|
829 register int vpos, fin;
|
|
830 register struct screen_glyphs *l1, *l2;
|
|
831 register SCREEN_PTR screen = XSCREEN (w->screen);
|
|
832 int start = XFASTINT (w->left);
|
|
833 int end = XFASTINT (w->left) + XFASTINT (w->width);
|
|
834 int bot = XFASTINT (w->top) + XFASTINT (w->height);
|
|
835
|
|
836 for (vpos = XFASTINT (w->top); vpos < bot; vpos++)
|
|
837 {
|
|
838 if ((l1 = SCREEN_DESIRED_GLYPHS (screen)->glyphs[vpos + 1])
|
|
839 && (l2 = SCREEN_PHYS_GLYPHS (screen)->glyphs[vpos + 1]))
|
|
840 {
|
|
841 if (l2->length > start && l1->length < l2->length)
|
|
842 {
|
|
843 fin = l2->length;
|
|
844 if (fin > end) fin = end;
|
|
845 while (l1->length < start)
|
|
846 l1->body[l1->length++] = ' ';
|
|
847 bcopy (l2->body + start, l1->body + start, fin - start);
|
|
848 l1->length = fin;
|
|
849 }
|
|
850 }
|
|
851 }
|
|
852 }
|
|
853
|
|
854 #endif
|
|
855
|
|
856 /* On discovering that the redisplay for a window was no good,
|
|
857 cancel the columns of that window, so that when the window is
|
|
858 displayed over again get_display_line will not complain. */
|
|
859
|
|
860 cancel_my_columns (w)
|
|
861 struct window *w;
|
|
862 {
|
|
863 register int vpos;
|
|
864 register SCREEN_PTR screen = XSCREEN (w->screen);
|
|
865 register struct screen_glyphs *desired_glyphs = screen->desired_glyphs;
|
|
866 register int start = XFASTINT (w->left);
|
|
867 register int bot = XFASTINT (w->top) + XFASTINT (w->height);
|
|
868
|
|
869 for (vpos = XFASTINT (w->top); vpos < bot; vpos++)
|
|
870 if (desired_glyphs->enable[vpos]
|
|
871 && desired_glyphs->used[vpos] >= start)
|
|
872 desired_glyphs->used[vpos] = start;
|
|
873 }
|
|
874
|
|
875 /* These functions try to perform directly and immediately on the screen
|
|
876 the necessary output for one change in the buffer.
|
|
877 They may return 0 meaning nothing was done if anything is difficult,
|
|
878 or 1 meaning the output was performed properly.
|
|
879 They assume that the screen was up to date before the buffer
|
|
880 change being displayed. THey make various other assumptions too;
|
|
881 see command_loop_1 where these are called. */
|
|
882
|
|
883 int
|
|
884 direct_output_for_insert (g)
|
|
885 int g;
|
|
886 {
|
|
887 register SCREEN_PTR screen = selected_screen;
|
|
888 register struct screen_glyphs *current_screen
|
|
889 = SCREEN_CURRENT_GLYPHS (screen);
|
|
890
|
|
891 #ifndef COMPILER_REGISTER_BUG
|
|
892 register
|
|
893 #endif /* COMPILER_REGISTER_BUG */
|
|
894 struct window *w = XWINDOW (selected_window);
|
|
895 #ifndef COMPILER_REGISTER_BUG
|
|
896 register
|
|
897 #endif /* COMPILER_REGISTER_BUG */
|
|
898 int hpos = SCREEN_CURSOR_X (screen);
|
|
899 #ifndef COMPILER_REGISTER_BUG
|
|
900 register
|
|
901 #endif /* COMPILER_REGISTER_BUG */
|
|
902 int vpos = SCREEN_CURSOR_Y (screen);
|
|
903
|
|
904 /* Give up if about to continue line */
|
|
905 if (hpos - XFASTINT (w->left) + 1 + 1 >= XFASTINT (w->width)
|
|
906
|
|
907 /* Avoid losing if cursor is in invisible text off left margin */
|
|
908 || (XINT (w->hscroll) && hpos == XFASTINT (w->left))
|
|
909
|
|
910 /* Give up if cursor outside window (in minibuf, probably) */
|
|
911 || SCREEN_CURSOR_Y (screen) < XFASTINT (w->top)
|
|
912 || SCREEN_CURSOR_Y (screen) >= XFASTINT (w->top) + XFASTINT (w->height)
|
|
913
|
|
914 /* Give up if cursor not really at SCREEN_CURSOR_X, SCREEN_CURSOR_Y */
|
|
915 || !display_completed
|
|
916
|
|
917 /* Give up if buffer appears in two places. */
|
|
918 || buffer_shared > 1
|
|
919
|
|
920 /* Give up if w is minibuffer and a message is being displayed there */
|
|
921 || (MINI_WINDOW_P (w) && echo_area_glyphs))
|
|
922 return 0;
|
|
923
|
|
924 current_screen->glyphs[vpos][hpos] = g;
|
|
925 unchanged_modified = MODIFF;
|
|
926 beg_unchanged = GPT - BEG;
|
|
927 XFASTINT (w->last_point) = point;
|
|
928 XFASTINT (w->last_point_x) = hpos;
|
|
929 XFASTINT (w->last_modified) = MODIFF;
|
|
930
|
|
931 reassert_line_highlight (0, vpos);
|
|
932 write_glyphs (¤t_screen->glyphs[vpos][hpos], 1);
|
|
933 fflush (stdout);
|
|
934 ++SCREEN_CURSOR_X (screen);
|
|
935 if (hpos == current_screen->used[vpos])
|
|
936 {
|
|
937 current_screen->used[vpos] = hpos + 1;
|
|
938 current_screen->glyphs[vpos][hpos + 1] = 0;
|
|
939 }
|
|
940
|
|
941 return 1;
|
|
942 }
|
|
943
|
|
944 int
|
|
945 direct_output_forward_char (n)
|
|
946 int n;
|
|
947 {
|
|
948 register SCREEN_PTR screen = selected_screen;
|
|
949 register struct window *w = XWINDOW (selected_window);
|
|
950
|
543
|
951 /* Avoid losing if cursor is in invisible text off left margin
|
|
952 or about to go off either side of window. */
|
|
953 if ((SCREEN_CURSOR_X (screen) == XFASTINT (w->left)
|
|
954 && (XINT (w->hscroll) || n < 0))
|
|
955 || (n > 0
|
|
956 && (SCREEN_CURSOR_X (screen) + 1
|
|
957 >= (XFASTINT (w->left) + XFASTINT (w->width)
|
|
958 - (XFASTINT (w->width) < SCREEN_WIDTH (screen))
|
|
959 - 1))))
|
314
|
960 return 0;
|
|
961
|
|
962 SCREEN_CURSOR_X (screen) += n;
|
|
963 XFASTINT (w->last_point_x) = SCREEN_CURSOR_X (screen);
|
|
964 XFASTINT (w->last_point) = point;
|
|
965 cursor_to (SCREEN_CURSOR_Y (screen), SCREEN_CURSOR_X (screen));
|
|
966 fflush (stdout);
|
|
967 return 1;
|
|
968 }
|
|
969
|
|
970 static void update_line ();
|
|
971
|
|
972 /* Update screen S based on the data in SCREEN_DESIRED_GLYPHS.
|
|
973 Value is nonzero if redisplay stopped due to pending input.
|
|
974 FORCE nonzero means do not stop for pending input. */
|
|
975
|
|
976 int
|
|
977 update_screen (s, force, inhibit_hairy_id)
|
|
978 SCREEN_PTR s;
|
|
979 int force;
|
|
980 int inhibit_hairy_id;
|
|
981 {
|
|
982 register struct screen_glyphs *current_screen = SCREEN_CURRENT_GLYPHS (s);
|
|
983 register struct screen_glyphs *desired_screen = SCREEN_DESIRED_GLYPHS (s);
|
|
984 register int i;
|
|
985 int pause;
|
|
986 int preempt_count = baud_rate / 2400 + 1;
|
|
987 extern input_pending;
|
|
988 #ifdef HAVE_X_WINDOWS
|
|
989 register int downto, leftmost;
|
|
990 #endif
|
|
991
|
|
992 if (SCREEN_HEIGHT (s) == 0) abort (); /* Some bug zeros some core */
|
|
993
|
|
994 detect_input_pending ();
|
|
995 if (input_pending && !force)
|
|
996 {
|
|
997 pause = 1;
|
|
998 goto do_pause;
|
|
999 }
|
|
1000
|
|
1001 update_begin (s);
|
|
1002
|
|
1003 if (!line_ins_del_ok)
|
|
1004 inhibit_hairy_id = 1;
|
|
1005
|
493
|
1006 /* See if any of the desired lines are enabled; don't compute for
|
|
1007 i/d line if just want cursor motion. */
|
314
|
1008 for (i = 0; i < SCREEN_HEIGHT (s); i++)
|
|
1009 if (desired_screen->enable[i])
|
|
1010 break;
|
|
1011
|
|
1012 /* Try doing i/d line, if not yet inhibited. */
|
|
1013 if (!inhibit_hairy_id && i < SCREEN_HEIGHT (s))
|
|
1014 force |= scrolling (s);
|
|
1015
|
|
1016 /* Update the individual lines as needed. Do bottom line first. */
|
|
1017
|
|
1018 if (desired_screen->enable[SCREEN_HEIGHT (s) - 1])
|
|
1019 update_line (s, SCREEN_HEIGHT (s) - 1);
|
|
1020
|
|
1021 #ifdef HAVE_X_WINDOWS
|
|
1022 if (SCREEN_IS_X (s))
|
|
1023 {
|
|
1024 leftmost = downto = s->display.x->internal_border_width;
|
|
1025 if (desired_screen->enable[0])
|
|
1026 {
|
|
1027 current_screen->top_left_x[SCREEN_HEIGHT (s) - 1] = leftmost;
|
|
1028 current_screen->top_left_y[SCREEN_HEIGHT (s) - 1]
|
|
1029 = PIXEL_HEIGHT (s) - s->display.x->internal_border_width
|
|
1030 - LINE_HEIGHT(s, SCREEN_HEIGHT (s) - 1);
|
|
1031 current_screen->top_left_x[0] = leftmost;
|
|
1032 current_screen->top_left_y[0] = downto;
|
|
1033 }
|
|
1034 }
|
|
1035 #endif /* HAVE_X_WINDOWS */
|
|
1036
|
|
1037 /* Now update the rest of the lines. */
|
|
1038 for (i = 0; i < SCREEN_HEIGHT (s) - 1 && (force || !input_pending); i++)
|
|
1039 {
|
|
1040 if (desired_screen->enable[i])
|
|
1041 {
|
|
1042 if (SCREEN_IS_TERMCAP (s))
|
|
1043 {
|
|
1044 /* Flush out every so many lines.
|
|
1045 Also flush out if likely to have more than 1k buffered
|
|
1046 otherwise. I'm told that some telnet connections get
|
|
1047 really screwed by more than 1k output at once. */
|
|
1048 int outq = PENDING_OUTPUT_COUNT (stdout);
|
|
1049 if (outq > 900
|
|
1050 || (outq > 20 && ((i - 1) % preempt_count == 0)))
|
|
1051 {
|
|
1052 fflush (stdout);
|
|
1053 if (preempt_count == 1)
|
|
1054 {
|
|
1055 #ifdef TIOCOUTQ
|
|
1056 if (ioctl (0, TIOCOUTQ, &outq) < 0)
|
|
1057 /* Probably not a tty. Ignore the error and reset
|
|
1058 * the outq count. */
|
|
1059 outq = PENDING_OUTPUT_COUNT (stdout);
|
|
1060 #endif
|
|
1061 outq *= 10;
|
|
1062 sleep (outq / baud_rate);
|
|
1063 }
|
|
1064 }
|
|
1065 if ((i - 1) % preempt_count == 0)
|
|
1066 detect_input_pending ();
|
|
1067 }
|
|
1068
|
|
1069 update_line (s, i);
|
|
1070 #ifdef HAVE_X_WINDOWS
|
|
1071 if (SCREEN_IS_X (s))
|
|
1072 {
|
|
1073 current_screen->top_left_y[i] = downto;
|
|
1074 current_screen->top_left_x[i] = leftmost;
|
|
1075 }
|
|
1076 #endif /* HAVE_X_WINDOWS */
|
|
1077 }
|
|
1078
|
|
1079 if (SCREEN_IS_X (s))
|
|
1080 downto += LINE_HEIGHT(s, i);
|
|
1081 }
|
|
1082 pause = (i < SCREEN_HEIGHT (s) - 1) ? i : 0;
|
|
1083
|
|
1084 /* Now just clean up termcap drivers and set cursor, etc. */
|
|
1085 if (!pause)
|
|
1086 {
|
|
1087
|
|
1088 if (s == selected_screen && cursor_in_echo_area < 0)
|
|
1089 cursor_to (SCREEN_HEIGHT (s) - 1, 0);
|
|
1090 else if (s == selected_screen && cursor_in_echo_area
|
|
1091 && !desired_screen->used[SCREEN_HEIGHT (s) - 1])
|
|
1092 cursor_to (SCREEN_HEIGHT (s), 0);
|
|
1093 else if (cursor_in_echo_area)
|
|
1094 cursor_to (SCREEN_HEIGHT (s) - 1,
|
|
1095 min (SCREEN_WIDTH (s) - 1,
|
|
1096 desired_screen->used[SCREEN_HEIGHT (s) - 1]));
|
|
1097 else
|
|
1098 cursor_to (SCREEN_CURSOR_Y (s), max (min (SCREEN_CURSOR_X (s),
|
|
1099 SCREEN_WIDTH (s) - 1), 0));
|
|
1100 }
|
|
1101
|
|
1102 update_end (s);
|
|
1103
|
|
1104 if (termscript)
|
|
1105 fflush (termscript);
|
|
1106 fflush (stdout);
|
|
1107
|
|
1108 /* Here if output is preempted because input is detected. */
|
|
1109 do_pause:
|
|
1110
|
|
1111 if (SCREEN_HEIGHT (s) == 0) abort (); /* Some bug zeros some core */
|
|
1112 display_completed = !pause;
|
|
1113
|
|
1114 bzero (desired_screen->enable, SCREEN_HEIGHT (s));
|
|
1115 return pause;
|
|
1116 }
|
|
1117
|
|
1118 /* Called when about to quit, to check for doing so
|
|
1119 at an improper time. */
|
|
1120
|
|
1121 void
|
|
1122 quit_error_check ()
|
|
1123 {
|
|
1124 if (SCREEN_DESIRED_GLYPHS (selected_screen) == 0)
|
|
1125 return;
|
|
1126 if (SCREEN_DESIRED_GLYPHS (selected_screen)->enable[0])
|
|
1127 abort ();
|
|
1128 if (SCREEN_DESIRED_GLYPHS (selected_screen)->enable[SCREEN_HEIGHT (selected_screen) - 1])
|
|
1129 abort ();
|
|
1130 }
|
|
1131
|
|
1132 /* Decide what insert/delete line to do, and do it */
|
|
1133
|
|
1134 extern void scrolling_1 ();
|
|
1135
|
|
1136 scrolling (screen)
|
|
1137 SCREEN_PTR screen;
|
|
1138 {
|
|
1139 int unchanged_at_top, unchanged_at_bottom;
|
|
1140 int window_size;
|
|
1141 int changed_lines;
|
|
1142 int *old_hash = (int *) alloca (SCREEN_HEIGHT (screen) * sizeof (int));
|
|
1143 int *new_hash = (int *) alloca (SCREEN_HEIGHT (screen) * sizeof (int));
|
|
1144 int *draw_cost = (int *) alloca (SCREEN_HEIGHT (screen) * sizeof (int));
|
|
1145 register int i;
|
|
1146 int free_at_end_vpos = SCREEN_HEIGHT (screen);
|
|
1147 register struct screen_glyphs *current_screen = SCREEN_CURRENT_GLYPHS (screen);
|
|
1148 register struct screen_glyphs *desired_screen = SCREEN_DESIRED_GLYPHS (screen);
|
|
1149
|
|
1150 /* Compute hash codes of all the lines.
|
|
1151 Also calculate number of changed lines,
|
|
1152 number of unchanged lines at the beginning,
|
|
1153 and number of unchanged lines at the end. */
|
|
1154
|
|
1155 changed_lines = 0;
|
|
1156 unchanged_at_top = 0;
|
|
1157 unchanged_at_bottom = SCREEN_HEIGHT (screen);
|
|
1158 for (i = 0; i < SCREEN_HEIGHT (screen); i++)
|
|
1159 {
|
|
1160 /* Give up on this scrolling if some old lines are not enabled. */
|
|
1161 if (!current_screen->enable[i])
|
|
1162 return 0;
|
|
1163 old_hash[i] = line_hash_code (current_screen, i);
|
|
1164 if (! desired_screen->enable[i])
|
|
1165 new_hash[i] = old_hash[i];
|
|
1166 else
|
|
1167 new_hash[i] = line_hash_code (desired_screen, i);
|
|
1168
|
|
1169 if (old_hash[i] != new_hash[i])
|
|
1170 {
|
|
1171 changed_lines++;
|
|
1172 unchanged_at_bottom = SCREEN_HEIGHT (screen) - i - 1;
|
|
1173 }
|
|
1174 else if (i == unchanged_at_top)
|
|
1175 unchanged_at_top++;
|
|
1176 draw_cost[i] = line_draw_cost (desired_screen, i);
|
|
1177 }
|
|
1178
|
|
1179 /* If changed lines are few, don't allow preemption, don't scroll. */
|
|
1180 if (changed_lines < baud_rate / 2400
|
|
1181 || unchanged_at_bottom == SCREEN_HEIGHT (screen))
|
|
1182 return 1;
|
|
1183
|
|
1184 window_size = (SCREEN_HEIGHT (screen) - unchanged_at_top
|
|
1185 - unchanged_at_bottom);
|
|
1186
|
|
1187 if (scroll_region_ok)
|
|
1188 free_at_end_vpos -= unchanged_at_bottom;
|
|
1189 else if (memory_below_screen)
|
|
1190 free_at_end_vpos = -1;
|
|
1191
|
|
1192 /* If large window, fast terminal and few lines in common between
|
|
1193 current screen and desired screen, don't bother with i/d calc. */
|
|
1194 if (window_size >= 18 && baud_rate > 2400
|
|
1195 && (window_size >=
|
|
1196 10 * scrolling_max_lines_saved (unchanged_at_top,
|
|
1197 SCREEN_HEIGHT (screen) - unchanged_at_bottom,
|
|
1198 old_hash, new_hash, draw_cost)))
|
|
1199 return 0;
|
|
1200
|
|
1201 scrolling_1 (screen, window_size, unchanged_at_top, unchanged_at_bottom,
|
|
1202 draw_cost + unchanged_at_top - 1,
|
|
1203 old_hash + unchanged_at_top - 1,
|
|
1204 new_hash + unchanged_at_top - 1,
|
|
1205 free_at_end_vpos - unchanged_at_top);
|
|
1206
|
|
1207 return 0;
|
|
1208 }
|
|
1209
|
|
1210 /* Return the offset in its buffer of the character at location col, line
|
|
1211 in the given window. */
|
|
1212 int
|
|
1213 buffer_posn_from_coords (window, col, line)
|
|
1214 struct window *window;
|
|
1215 int col, line;
|
|
1216 {
|
|
1217 int window_left = XFASTINT (window->left);
|
|
1218
|
|
1219 /* The actual width of the window is window->width less one for the
|
493
|
1220 DISP_CONTINUE_GLYPH, and less one if it's not the rightmost
|
|
1221 window. */
|
314
|
1222 int window_width = (XFASTINT (window->width) - 1
|
|
1223 - (XFASTINT (window->width) + window_left
|
|
1224 != SCREEN_WIDTH (XSCREEN (window->screen))));
|
|
1225
|
493
|
1226 int startp = marker_position (window->start);
|
314
|
1227
|
|
1228 /* Since compute_motion will only operate on the current buffer,
|
|
1229 we need to save the old one and restore it when we're done. */
|
|
1230 struct buffer *old_current_buffer = current_buffer;
|
493
|
1231 struct position *posn;
|
314
|
1232
|
|
1233 current_buffer = XBUFFER (window->buffer);
|
|
1234
|
493
|
1235 /* It would be nice if we could use SCREEN_CURRENT_GLYPHS (XSCREEN
|
|
1236 (window->screen))->bufp to avoid scanning from the very top of
|
|
1237 the window, but it isn't maintained correctly, and I'm not even
|
|
1238 sure I will keep it. */
|
|
1239 posn = compute_motion (startp, 0,
|
|
1240 (window == XWINDOW (minibuf_window) && startp == 1
|
|
1241 ? minibuf_prompt_width : 0),
|
|
1242 ZV, line, col - window_left,
|
|
1243 window_width, XINT (window->hscroll), 0);
|
314
|
1244
|
|
1245 current_buffer = old_current_buffer;
|
|
1246
|
493
|
1247 /* compute_motion considers screen points past the end of a line
|
|
1248 to be *after* the newline, i.e. at the start of the next line.
|
|
1249 This is reasonable, but not really what we want. So if the
|
|
1250 result is on a line below LINE, back it up one character. */
|
|
1251 if (posn->vpos > line)
|
|
1252 return posn->bufpos - 1;
|
|
1253 else
|
|
1254 return posn->bufpos;
|
314
|
1255 }
|
|
1256
|
|
1257 static int
|
|
1258 count_blanks (r)
|
|
1259 register GLYPH *r;
|
|
1260 {
|
|
1261 register GLYPH *p = r;
|
|
1262 while (*r++ == SPACEGLYPH);
|
|
1263 return r - p - 1;
|
|
1264 }
|
|
1265
|
|
1266 static int
|
|
1267 count_match (str1, str2)
|
|
1268 GLYPH *str1, *str2;
|
|
1269 {
|
|
1270 register GLYPH *p1 = str1;
|
|
1271 register GLYPH *p2 = str2;
|
|
1272 while (*p1++ == *p2++);
|
|
1273 return p1 - str1 - 1;
|
|
1274 }
|
|
1275
|
|
1276 /* Char insertion/deletion cost vector, from term.c */
|
|
1277 extern int *char_ins_del_vector;
|
|
1278
|
|
1279 #define char_ins_del_cost(s) (&char_ins_del_vector[SCREEN_HEIGHT((s))])
|
|
1280
|
|
1281 static void
|
|
1282 update_line (screen, vpos)
|
|
1283 register SCREEN_PTR screen;
|
|
1284 int vpos;
|
|
1285 {
|
|
1286 register GLYPH *obody, *nbody, *op1, *op2, *np1, *temp;
|
|
1287 int tem;
|
|
1288 int osp, nsp, begmatch, endmatch, olen, nlen;
|
|
1289 int save;
|
|
1290 register struct screen_glyphs *current_screen
|
|
1291 = SCREEN_CURRENT_GLYPHS (screen);
|
|
1292 register struct screen_glyphs *desired_screen
|
|
1293 = SCREEN_DESIRED_GLYPHS (screen);
|
|
1294
|
|
1295 if (desired_screen->highlight[vpos]
|
|
1296 != (current_screen->enable[vpos] && current_screen->highlight[vpos]))
|
|
1297 {
|
|
1298 change_line_highlight (desired_screen->highlight[vpos], vpos,
|
|
1299 (current_screen->enable[vpos] ?
|
|
1300 current_screen->used[vpos] : 0));
|
|
1301 current_screen->enable[vpos] = 0;
|
|
1302 }
|
|
1303 else
|
|
1304 reassert_line_highlight (desired_screen->highlight[vpos], vpos);
|
|
1305
|
|
1306 if (! current_screen->enable[vpos])
|
|
1307 {
|
|
1308 olen = 0;
|
|
1309 }
|
|
1310 else
|
|
1311 {
|
|
1312 obody = current_screen->glyphs[vpos];
|
|
1313 olen = current_screen->used[vpos];
|
|
1314 if (! current_screen->highlight[vpos])
|
|
1315 {
|
|
1316 if (!must_write_spaces)
|
|
1317 while (obody[olen - 1] == SPACEGLYPH && olen > 0)
|
|
1318 olen--;
|
|
1319 }
|
|
1320 else
|
|
1321 {
|
|
1322 /* For an inverse-video line, remember we gave it
|
|
1323 spaces all the way to the screen edge
|
|
1324 so that the reverse video extends all the way across. */
|
|
1325
|
|
1326 while (olen < SCREEN_WIDTH (screen) - 1)
|
|
1327 obody[olen++] = SPACEGLYPH;
|
|
1328 }
|
|
1329 }
|
|
1330
|
|
1331 /* One way or another, this will enable the line being updated. */
|
|
1332 current_screen->enable[vpos] = 1;
|
|
1333 current_screen->used[vpos] = desired_screen->used[vpos];
|
|
1334 current_screen->highlight[vpos] = desired_screen->highlight[vpos];
|
|
1335 current_screen->bufp[vpos] = desired_screen->bufp[vpos];
|
|
1336
|
|
1337 #ifdef HAVE_X_WINDOWS
|
|
1338 if (SCREEN_IS_X (screen))
|
|
1339 {
|
|
1340 current_screen->pix_width[vpos]
|
|
1341 = current_screen->used[vpos]
|
|
1342 * FONT_WIDTH (screen->display.x->font);
|
|
1343 current_screen->pix_height[vpos]
|
|
1344 = FONT_HEIGHT (screen->display.x->font);
|
|
1345 }
|
|
1346 #endif /* HAVE_X_WINDOWS */
|
|
1347
|
|
1348 if (!desired_screen->enable[vpos])
|
|
1349 {
|
|
1350 nlen = 0;
|
|
1351 goto just_erase;
|
|
1352 }
|
|
1353
|
|
1354 nbody = desired_screen->glyphs[vpos];
|
|
1355 nlen = desired_screen->used[vpos];
|
|
1356
|
|
1357 /* Pretend trailing spaces are not there at all,
|
|
1358 unless for one reason or another we must write all spaces. */
|
|
1359 if (! desired_screen->highlight[vpos])
|
|
1360 {
|
|
1361 if (!must_write_spaces)
|
|
1362 /* We know that the previous character byte contains 0. */
|
|
1363 while (nbody[nlen - 1] == SPACEGLYPH)
|
|
1364 nlen--;
|
|
1365 }
|
|
1366 else
|
|
1367 {
|
|
1368 /* For an inverse-video line, give it extra trailing spaces
|
|
1369 all the way to the screen edge
|
|
1370 so that the reverse video extends all the way across. */
|
|
1371
|
|
1372 while (nlen < SCREEN_WIDTH (screen) - 1)
|
|
1373 nbody[nlen++] = SPACEGLYPH;
|
|
1374 }
|
|
1375
|
|
1376 /* If there's no i/d char, quickly do the best we can without it. */
|
|
1377 if (!char_ins_del_ok)
|
|
1378 {
|
|
1379 int i,j;
|
|
1380
|
|
1381 for (i = 0; i < nlen; i++)
|
|
1382 {
|
|
1383 if (i >= olen || nbody[i] != obody[i]) /* A non-matching char. */
|
|
1384 {
|
|
1385 cursor_to (vpos, i);
|
|
1386 for (j = 1; (i + j < nlen &&
|
|
1387 (i + j >= olen || nbody[i+j] != obody[i+j]));
|
|
1388 j++);
|
|
1389
|
|
1390 /* Output this run of non-matching chars. */
|
|
1391 write_glyphs (nbody + i, j);
|
|
1392 i += j - 1;
|
|
1393
|
|
1394 /* Now find the next non-match. */
|
|
1395 }
|
|
1396 }
|
|
1397
|
|
1398 /* Clear the rest of the line, or the non-clear part of it. */
|
|
1399 if (olen > nlen)
|
|
1400 {
|
|
1401 cursor_to (vpos, nlen);
|
|
1402 clear_end_of_line (olen);
|
|
1403 }
|
|
1404
|
|
1405 /* Exchange contents between current_screen and new_screen. */
|
|
1406 temp = desired_screen->glyphs[vpos];
|
|
1407 desired_screen->glyphs[vpos] = current_screen->glyphs[vpos];
|
|
1408 current_screen->glyphs[vpos] = temp;
|
|
1409
|
|
1410 return;
|
|
1411 }
|
|
1412
|
|
1413 if (!olen)
|
|
1414 {
|
|
1415 nsp = (must_write_spaces || desired_screen->highlight[vpos])
|
|
1416 ? 0 : count_blanks (nbody);
|
|
1417 if (nlen > nsp)
|
|
1418 {
|
|
1419 cursor_to (vpos, nsp);
|
|
1420 write_glyphs (nbody + nsp, nlen - nsp);
|
|
1421 }
|
|
1422
|
|
1423 /* Exchange contents between current_screen and new_screen. */
|
|
1424 temp = desired_screen->glyphs[vpos];
|
|
1425 desired_screen->glyphs[vpos] = current_screen->glyphs[vpos];
|
|
1426 current_screen->glyphs[vpos] = temp;
|
|
1427
|
|
1428 return;
|
|
1429 }
|
|
1430
|
|
1431 obody[olen] = 1;
|
|
1432 save = nbody[nlen];
|
|
1433 nbody[nlen] = 0;
|
|
1434
|
|
1435 /* Compute number of leading blanks in old and new contents. */
|
|
1436 osp = count_blanks (obody);
|
|
1437 if (!desired_screen->highlight[vpos])
|
|
1438 nsp = count_blanks (nbody);
|
|
1439 else
|
|
1440 nsp = 0;
|
|
1441
|
|
1442 /* Compute number of matching chars starting with first nonblank. */
|
|
1443 begmatch = count_match (obody + osp, nbody + nsp);
|
|
1444
|
|
1445 /* Spaces in new match implicit space past the end of old. */
|
|
1446 /* A bug causing this to be a no-op was fixed in 18.29. */
|
|
1447 if (!must_write_spaces && osp + begmatch == olen)
|
|
1448 {
|
|
1449 np1 = nbody + nsp;
|
|
1450 while (np1[begmatch] == SPACEGLYPH)
|
|
1451 begmatch++;
|
|
1452 }
|
|
1453
|
|
1454 /* Avoid doing insert/delete char
|
|
1455 just cause number of leading spaces differs
|
|
1456 when the following text does not match. */
|
|
1457 if (begmatch == 0 && osp != nsp)
|
|
1458 osp = nsp = min (osp, nsp);
|
|
1459
|
|
1460 /* Find matching characters at end of line */
|
|
1461 op1 = obody + olen;
|
|
1462 np1 = nbody + nlen;
|
|
1463 op2 = op1 + begmatch - min (olen - osp, nlen - nsp);
|
|
1464 while (op1 > op2 && op1[-1] == np1[-1])
|
|
1465 {
|
|
1466 op1--;
|
|
1467 np1--;
|
|
1468 }
|
|
1469 endmatch = obody + olen - op1;
|
|
1470
|
|
1471 /* Put correct value back in nbody[nlen].
|
|
1472 This is important because direct_output_for_insert
|
|
1473 can write into the line at a later point.
|
|
1474 If this screws up the zero at the end of the line, re-establish it. */
|
|
1475 nbody[nlen] = save;
|
|
1476 obody[olen] = 0;
|
|
1477
|
|
1478 /* tem gets the distance to insert or delete.
|
|
1479 endmatch is how many characters we save by doing so.
|
|
1480 Is it worth it? */
|
|
1481
|
|
1482 tem = (nlen - nsp) - (olen - osp);
|
|
1483 if (endmatch && tem
|
|
1484 && (!char_ins_del_ok || endmatch <= char_ins_del_cost (screen)[tem]))
|
|
1485 endmatch = 0;
|
|
1486
|
|
1487 /* nsp - osp is the distance to insert or delete.
|
|
1488 If that is nonzero, begmatch is known to be nonzero also.
|
|
1489 begmatch + endmatch is how much we save by doing the ins/del.
|
|
1490 Is it worth it? */
|
|
1491
|
|
1492 if (nsp != osp
|
|
1493 && (!char_ins_del_ok
|
|
1494 || begmatch + endmatch <= char_ins_del_cost (screen)[nsp - osp]))
|
|
1495 {
|
|
1496 begmatch = 0;
|
|
1497 endmatch = 0;
|
|
1498 osp = nsp = min (osp, nsp);
|
|
1499 }
|
|
1500
|
|
1501 /* Now go through the line, inserting, writing and
|
|
1502 deleting as appropriate. */
|
|
1503
|
|
1504 if (osp > nsp)
|
|
1505 {
|
|
1506 cursor_to (vpos, nsp);
|
|
1507 delete_glyphs (osp - nsp);
|
|
1508 }
|
|
1509 else if (nsp > osp)
|
|
1510 {
|
|
1511 /* If going to delete chars later in line
|
|
1512 and insert earlier in the line,
|
|
1513 must delete first to avoid losing data in the insert */
|
|
1514 if (endmatch && nlen < olen + nsp - osp)
|
|
1515 {
|
|
1516 cursor_to (vpos, nlen - endmatch + osp - nsp);
|
|
1517 delete_glyphs (olen + nsp - osp - nlen);
|
|
1518 olen = nlen - (nsp - osp);
|
|
1519 }
|
|
1520 cursor_to (vpos, osp);
|
|
1521 insert_glyphs ((char *)0, nsp - osp);
|
|
1522 }
|
|
1523 olen += nsp - osp;
|
|
1524
|
|
1525 tem = nsp + begmatch + endmatch;
|
|
1526 if (nlen != tem || olen != tem)
|
|
1527 {
|
|
1528 cursor_to (vpos, nsp + begmatch);
|
|
1529 if (!endmatch || nlen == olen)
|
|
1530 {
|
|
1531 /* If new text being written reaches right margin,
|
|
1532 there is no need to do clear-to-eol at the end.
|
|
1533 (and it would not be safe, since cursor is not
|
|
1534 going to be "at the margin" after the text is done) */
|
|
1535 if (nlen == SCREEN_WIDTH (screen))
|
|
1536 olen = 0;
|
|
1537 write_glyphs (nbody + nsp + begmatch, nlen - tem);
|
|
1538
|
|
1539 #ifdef obsolete
|
|
1540
|
|
1541 /* the following code loses disastrously if tem == nlen.
|
|
1542 Rather than trying to fix that case, I am trying the simpler
|
|
1543 solution found above. */
|
|
1544
|
|
1545 /* If the text reaches to the right margin,
|
|
1546 it will lose one way or another (depending on AutoWrap)
|
|
1547 to clear to end of line after outputting all the text.
|
|
1548 So pause with one character to go and clear the line then. */
|
|
1549 if (nlen == SCREEN_WIDTH (screen) && fast_clear_end_of_line && olen > nlen)
|
|
1550 {
|
|
1551 /* endmatch must be zero, and tem must equal nsp + begmatch */
|
|
1552 write_glyphs (nbody + tem, nlen - tem - 1);
|
|
1553 clear_end_of_line (olen);
|
|
1554 olen = 0; /* Don't let it be cleared again later */
|
|
1555 write_glyphs (nbody + nlen - 1, 1);
|
|
1556 }
|
|
1557 else
|
|
1558 write_glyphs (nbody + nsp + begmatch, nlen - tem);
|
|
1559 #endif /* OBSOLETE */
|
|
1560
|
|
1561 }
|
|
1562 else if (nlen > olen)
|
|
1563 {
|
|
1564 write_glyphs (nbody + nsp + begmatch, olen - tem);
|
|
1565 insert_glyphs (nbody + nsp + begmatch + olen - tem, nlen - olen);
|
|
1566 olen = nlen;
|
|
1567 }
|
|
1568 else if (olen > nlen)
|
|
1569 {
|
|
1570 write_glyphs (nbody + nsp + begmatch, nlen - tem);
|
|
1571 delete_glyphs (olen - nlen);
|
|
1572 olen = nlen;
|
|
1573 }
|
|
1574 }
|
|
1575
|
|
1576 just_erase:
|
|
1577 /* If any unerased characters remain after the new line, erase them. */
|
|
1578 if (olen > nlen)
|
|
1579 {
|
|
1580 cursor_to (vpos, nlen);
|
|
1581 clear_end_of_line (olen);
|
|
1582 }
|
|
1583
|
|
1584 /* Exchange contents between current_screen and new_screen. */
|
|
1585 temp = desired_screen->glyphs[vpos];
|
|
1586 desired_screen->glyphs[vpos] = current_screen->glyphs[vpos];
|
|
1587 current_screen->glyphs[vpos] = temp;
|
|
1588 }
|
|
1589
|
|
1590 DEFUN ("open-termscript", Fopen_termscript, Sopen_termscript,
|
|
1591 1, 1, "FOpen termscript file: ",
|
|
1592 "Start writing all terminal output to FILE as well as the terminal.\n\
|
|
1593 FILE = nil means just close any termscript file currently open.")
|
|
1594 (file)
|
|
1595 Lisp_Object file;
|
|
1596 {
|
|
1597 if (termscript != 0) fclose (termscript);
|
|
1598 termscript = 0;
|
|
1599
|
493
|
1600 if (! NILP (file))
|
314
|
1601 {
|
|
1602 file = Fexpand_file_name (file, Qnil);
|
|
1603 termscript = fopen (XSTRING (file)->data, "w");
|
|
1604 if (termscript == 0)
|
|
1605 report_file_error ("Opening termscript", Fcons (file, Qnil));
|
|
1606 }
|
|
1607 return Qnil;
|
|
1608 }
|
|
1609
|
|
1610
|
|
1611 #ifdef SIGWINCH
|
493
|
1612 SIGTYPE
|
314
|
1613 window_change_signal ()
|
|
1614 {
|
|
1615 int width, height;
|
|
1616 extern int errno;
|
|
1617 int old_errno = errno;
|
|
1618
|
|
1619 get_screen_size (&width, &height);
|
|
1620
|
|
1621 /* The screen size change obviously applies to a termcap-controlled
|
|
1622 screen. Find such a screen in the list, and assume it's the only
|
|
1623 one (since the redisplay code always writes to stdout, not a
|
|
1624 FILE * specified in the screen structure). Record the new size,
|
|
1625 but don't reallocate the data structures now. Let that be done
|
|
1626 later outside of the signal handler. */
|
|
1627
|
|
1628 {
|
|
1629 Lisp_Object tail;
|
|
1630
|
|
1631 for (tail = Vscreen_list; CONSP (tail); tail = XCONS (tail)->cdr)
|
|
1632 {
|
|
1633 SCREEN_PTR s = XSCREEN (XCONS (tail)->car);
|
|
1634
|
493
|
1635 if (SCREEN_IS_TERMCAP (s))
|
314
|
1636 {
|
|
1637 ++in_display;
|
|
1638 change_screen_size (s, height, width, 0);
|
|
1639 --in_display;
|
|
1640 break;
|
|
1641 }
|
|
1642 }
|
|
1643 }
|
|
1644
|
|
1645 signal (SIGWINCH, window_change_signal);
|
|
1646 errno = old_errno;
|
|
1647 }
|
|
1648 #endif /* SIGWINCH */
|
|
1649
|
|
1650
|
|
1651 /* Do any change in screen size that was requested by a signal. */
|
|
1652
|
|
1653 do_pending_window_change ()
|
|
1654 {
|
|
1655 /* If window_change_signal should have run before, run it now. */
|
|
1656 while (delayed_size_change)
|
|
1657 {
|
|
1658 Lisp_Object tail;
|
|
1659
|
|
1660 delayed_size_change = 0;
|
|
1661
|
|
1662 for (tail = Vscreen_list; CONSP (tail); tail = XCONS (tail)->cdr)
|
|
1663 {
|
|
1664 SCREEN_PTR s = XSCREEN (XCONS (tail)->car);
|
|
1665 int height = SCREEN_NEW_HEIGHT (s);
|
|
1666 int width = SCREEN_NEW_WIDTH (s);
|
|
1667
|
|
1668 SCREEN_NEW_HEIGHT (s) = 0;
|
|
1669 SCREEN_NEW_WIDTH (s) = 0;
|
|
1670
|
|
1671 if (height != 0)
|
|
1672 change_screen_size (s, height, width, 0);
|
|
1673 }
|
|
1674 }
|
|
1675 }
|
|
1676
|
|
1677
|
|
1678 /* Change the screen height and/or width. Values may be given as zero to
|
|
1679 indicate no change is to take place. */
|
|
1680
|
|
1681 change_screen_size (screen, newlength, newwidth, pretend)
|
|
1682 register SCREEN_PTR screen;
|
|
1683 register int newlength, newwidth, pretend;
|
|
1684 {
|
|
1685 /* If we can't deal with the change now, queue it for later. */
|
|
1686 if (in_display)
|
|
1687 {
|
|
1688 SCREEN_NEW_HEIGHT (screen) = newlength;
|
|
1689 SCREEN_NEW_WIDTH (screen) = newwidth;
|
|
1690 delayed_size_change = 1;
|
|
1691 return;
|
|
1692 }
|
|
1693
|
|
1694 /* This size-change overrides any pending one for this screen. */
|
|
1695 SCREEN_NEW_HEIGHT (screen) = 0;
|
|
1696 SCREEN_NEW_WIDTH (screen) = 0;
|
|
1697
|
|
1698 if ((newlength == 0 || newlength == SCREEN_HEIGHT (screen))
|
|
1699 && (newwidth == 0 || newwidth == SCREEN_WIDTH (screen)))
|
|
1700 return;
|
|
1701
|
|
1702 if (newlength && newlength != SCREEN_HEIGHT (screen))
|
|
1703 {
|
493
|
1704 if (SCREEN_HAS_MINIBUF (screen)
|
|
1705 && ! SCREEN_MINIBUF_ONLY_P (screen))
|
314
|
1706 {
|
|
1707 /* Screen has both root and minibuffer. */
|
|
1708 set_window_height (SCREEN_ROOT_WINDOW (screen),
|
|
1709 newlength - 1, 0);
|
|
1710 XFASTINT (XWINDOW (SCREEN_MINIBUF_WINDOW (screen))->top)
|
|
1711 = newlength - 1;
|
|
1712 set_window_height (SCREEN_MINIBUF_WINDOW (screen), 1, 0);
|
|
1713 }
|
|
1714 else
|
|
1715 /* Screen has just one top-level window. */
|
|
1716 set_window_height (SCREEN_ROOT_WINDOW (screen), newlength, 0);
|
|
1717
|
493
|
1718 if (SCREEN_IS_TERMCAP (screen) && !pretend)
|
314
|
1719 ScreenRows = newlength;
|
|
1720
|
|
1721 #if 0
|
|
1722 if (screen->output_method == output_termcap)
|
|
1723 {
|
|
1724 screen_height = newlength;
|
|
1725 if (!pretend)
|
|
1726 ScreenRows = newlength;
|
|
1727 }
|
|
1728 #endif
|
|
1729 }
|
|
1730
|
|
1731 if (newwidth && newwidth != SCREEN_WIDTH (screen))
|
|
1732 {
|
|
1733 set_window_width (SCREEN_ROOT_WINDOW (screen), newwidth, 0);
|
493
|
1734 if (SCREEN_HAS_MINIBUF (screen))
|
314
|
1735 set_window_width (SCREEN_MINIBUF_WINDOW (screen), newwidth, 0);
|
|
1736 SCREEN_WIDTH (screen) = newwidth;
|
|
1737
|
|
1738 if (SCREEN_IS_TERMCAP (screen) && !pretend)
|
|
1739 ScreenCols = newwidth;
|
|
1740 #if 0
|
|
1741 if (screen->output_method == output_termcap)
|
|
1742 {
|
|
1743 screen_width = newwidth;
|
|
1744 if (!pretend)
|
|
1745 ScreenCols = newwidth;
|
|
1746 }
|
|
1747 #endif
|
|
1748 }
|
|
1749
|
|
1750 if (newlength)
|
|
1751 SCREEN_HEIGHT (screen) = newlength;
|
|
1752
|
|
1753 remake_screen_glyphs (screen);
|
|
1754 calculate_costs (screen);
|
|
1755 }
|
|
1756
|
|
1757 DEFUN ("send-string-to-terminal", Fsend_string_to_terminal,
|
|
1758 Ssend_string_to_terminal, 1, 1, 0,
|
|
1759 "Send STRING to the terminal without alteration.\n\
|
|
1760 Control characters in STRING will have terminal-dependent effects.")
|
|
1761 (str)
|
|
1762 Lisp_Object str;
|
|
1763 {
|
|
1764 CHECK_STRING (str, 0);
|
|
1765 fwrite (XSTRING (str)->data, 1, XSTRING (str)->size, stdout);
|
|
1766 fflush (stdout);
|
|
1767 if (termscript)
|
|
1768 {
|
|
1769 fwrite (XSTRING (str)->data, 1, XSTRING (str)->size, termscript);
|
|
1770 fflush (termscript);
|
|
1771 }
|
|
1772 return Qnil;
|
|
1773 }
|
|
1774
|
|
1775 DEFUN ("ding", Fding, Sding, 0, 1, 0,
|
|
1776 "Beep, or flash the screen.\n\
|
|
1777 Also, unless an argument is given,\n\
|
|
1778 terminate any keyboard macro currently executing.")
|
|
1779 (arg)
|
|
1780 Lisp_Object arg;
|
|
1781 {
|
493
|
1782 if (!NILP (arg))
|
314
|
1783 {
|
|
1784 ring_bell ();
|
|
1785 fflush (stdout);
|
|
1786 }
|
|
1787 else
|
|
1788 bitch_at_user ();
|
|
1789
|
|
1790 return Qnil;
|
|
1791 }
|
|
1792
|
|
1793 bitch_at_user ()
|
|
1794 {
|
|
1795 if (noninteractive)
|
|
1796 putchar (07);
|
|
1797 else if (!INTERACTIVE) /* Stop executing a keyboard macro. */
|
|
1798 error ("Keyboard macro terminated by a command ringing the bell");
|
|
1799 else
|
|
1800 ring_bell ();
|
|
1801 fflush (stdout);
|
|
1802 }
|
|
1803
|
|
1804 DEFUN ("sleep-for", Fsleep_for, Ssleep_for, 1, 2, 0,
|
|
1805 "Pause, without updating display, for ARG seconds.\n\
|
|
1806 Optional second arg non-nil means ARG is measured in milliseconds.\n\
|
|
1807 \(Not all operating systems support milliseconds.)")
|
|
1808 (n, millisec)
|
|
1809 Lisp_Object n, millisec;
|
|
1810 {
|
|
1811 #ifndef subprocesses
|
|
1812 #ifdef HAVE_TIMEVAL
|
|
1813 struct timeval timeout, end_time, garbage1;
|
|
1814 #endif /* HAVE_TIMEVAL */
|
|
1815 #endif /* no subprocesses */
|
|
1816 int usec = 0;
|
|
1817 int sec;
|
|
1818
|
|
1819 CHECK_NUMBER (n, 0);
|
|
1820 sec = XINT (n);
|
|
1821 if (sec <= 0)
|
|
1822 return Qnil;
|
|
1823
|
493
|
1824 if (!NILP (millisec))
|
314
|
1825 {
|
|
1826 #ifndef HAVE_TIMEVAL
|
|
1827 error ("millisecond sit-for not supported on %s", SYSTEM_TYPE);
|
|
1828 #else
|
|
1829 usec = sec % 1000 * 1000;
|
|
1830 sec /= 1000;
|
|
1831 #endif
|
|
1832 }
|
|
1833
|
|
1834 #ifdef subprocesses
|
|
1835 wait_reading_process_input (sec, usec, 0, 0);
|
|
1836 #else /* No subprocesses */
|
|
1837 immediate_quit = 1;
|
|
1838 QUIT;
|
|
1839
|
|
1840 #ifdef VMS
|
|
1841 sys_sleep (sec);
|
|
1842 #else /* not VMS */
|
|
1843 /* The reason this is done this way
|
|
1844 (rather than defined (H_S) && defined (H_T))
|
|
1845 is because the VMS preprocessor doesn't grok `defined' */
|
|
1846 #ifdef HAVE_SELECT
|
|
1847 #ifdef HAVE_TIMEVAL
|
|
1848 gettimeofday (&end_time, &garbage1);
|
|
1849 end_time.tv_sec += sec;
|
|
1850 end_time.tv_usec += usec;
|
|
1851 if (end_time.tv_usec >= 1000000)
|
|
1852 end_time.tv_sec++, end_time.tv_usec -= 1000000;
|
|
1853
|
|
1854 while (1)
|
|
1855 {
|
|
1856 gettimeofday (&timeout, &garbage1);
|
|
1857 timeout.tv_sec = end_time.tv_sec - timeout.tv_sec;
|
|
1858 timeout.tv_usec = end_time.tv_usec - timeout.tv_usec;
|
|
1859 if (timeout.tv_usec < 0)
|
|
1860 timeout.tv_usec += 1000000, timeout.tv_sec--;
|
|
1861 if (timeout.tv_sec < 0)
|
|
1862 break;
|
|
1863 if (!select (1, 0, 0, 0, &timeout))
|
|
1864 break;
|
|
1865 }
|
|
1866 #else /* not HAVE_TIMEVAL */
|
|
1867 /* Is it safe to quit out of `sleep'? I'm afraid to trust it. */
|
|
1868 sleep (sec);
|
|
1869 #endif /* HAVE_TIMEVAL */
|
|
1870 #else /* not HAVE_SELECT */
|
|
1871 sleep (sec);
|
|
1872 #endif /* HAVE_SELECT */
|
|
1873 #endif /* not VMS */
|
|
1874
|
|
1875 immediate_quit = 0;
|
|
1876 #endif /* no subprocesses */
|
|
1877
|
|
1878 return Qnil;
|
|
1879 }
|
|
1880
|
|
1881 DEFUN ("sit-for", Fsit_for, Ssit_for, 1, 3, 0,
|
|
1882 "Perform redisplay, then wait for ARG seconds or until input is available.\n\
|
|
1883 Optional second arg non-nil means ARG counts in milliseconds.\n\
|
|
1884 Optional third arg non-nil means don't redisplay, just wait for input.\n\
|
|
1885 Redisplay is preempted as always if input arrives, and does not happen\n\
|
|
1886 if input is available before it starts.\n\
|
|
1887 Value is t if waited the full time with no input arriving.")
|
|
1888 (n, millisec, nodisp)
|
|
1889 Lisp_Object n, millisec, nodisp;
|
|
1890 {
|
|
1891 #ifndef subprocesses
|
|
1892 #ifdef HAVE_TIMEVAL
|
|
1893 struct timeval timeout;
|
|
1894 #else
|
|
1895 int timeout_sec;
|
|
1896 #endif
|
|
1897 int waitchannels;
|
|
1898 #endif /* no subprocesses */
|
|
1899 int usec = 0;
|
|
1900 int sec;
|
|
1901
|
|
1902 CHECK_NUMBER (n, 0);
|
|
1903
|
|
1904 if (detect_input_pending ())
|
|
1905 return Qnil;
|
|
1906
|
|
1907 if (EQ (nodisp, Qnil))
|
|
1908 redisplay_preserve_echo_area ();
|
|
1909
|
|
1910 sec = XINT (n);
|
|
1911 if (sec <= 0)
|
|
1912 return Qt;
|
|
1913
|
493
|
1914 if (!NILP (millisec))
|
314
|
1915 {
|
|
1916 #ifndef HAVE_TIMEVAL
|
|
1917 error ("millisecond sleep-for not supported on %s", SYSTEM_TYPE);
|
|
1918 #else
|
|
1919 usec = sec % 1000 * 1000;
|
|
1920 sec /= 1000;
|
|
1921 #endif
|
|
1922 }
|
|
1923
|
|
1924 #ifdef subprocesses
|
|
1925 #ifdef SIGIO
|
|
1926 gobble_input ();
|
|
1927 #endif /* SIGIO */
|
|
1928 wait_reading_process_input (sec, usec, 1, 1);
|
|
1929 #else /* no subprocesses */
|
|
1930 immediate_quit = 1;
|
|
1931 QUIT;
|
|
1932
|
|
1933 waitchannels = 1;
|
|
1934 #ifdef VMS
|
|
1935 input_wait_timeout (XINT (n));
|
|
1936 #else /* not VMS */
|
|
1937 #ifndef HAVE_TIMEVAL
|
|
1938 timeout_sec = sec;
|
|
1939 select (1, &waitchannels, 0, 0, &timeout_sec);
|
|
1940 #else /* HAVE_TIMEVAL */
|
|
1941 timeout.tv_sec = sec;
|
|
1942 timeout.tv_usec = usec;
|
|
1943 select (1, &waitchannels, 0, 0, &timeout);
|
|
1944 #endif /* HAVE_TIMEVAL */
|
|
1945 #endif /* not VMS */
|
|
1946
|
|
1947 immediate_quit = 0;
|
|
1948 #endif /* no subprocesses */
|
|
1949
|
|
1950 return detect_input_pending () ? Qnil : Qt;
|
|
1951 }
|
|
1952
|
|
1953 DEFUN ("sleep-for-millisecs", Fsleep_for_millisecs, Ssleep_for_millisecs,
|
|
1954 1, 1, 0,
|
|
1955 "Pause, without updating display, for ARG milliseconds.")
|
|
1956 (n)
|
|
1957 Lisp_Object n;
|
|
1958 {
|
|
1959 #ifndef HAVE_TIMEVAL
|
|
1960 error ("sleep-for-millisecs not supported on %s", SYSTEM_TYPE);
|
|
1961 #else
|
|
1962 CHECK_NUMBER (n, 0);
|
|
1963 wait_reading_process_input (XINT (n) / 1000, XINT (n) % 1000 * 1000,
|
|
1964 0, 0);
|
|
1965 return Qnil;
|
|
1966 #endif /* HAVE_TIMEVAL */
|
|
1967 }
|
|
1968
|
|
1969 char *terminal_type;
|
|
1970
|
|
1971 /* Initialization done when Emacs fork is started, before doing stty. */
|
|
1972 /* Determine terminal type and set terminal_driver */
|
|
1973 /* Then invoke its decoding routine to set up variables
|
|
1974 in the terminal package */
|
|
1975
|
|
1976 init_display ()
|
|
1977 {
|
|
1978 #ifdef HAVE_X_WINDOWS
|
|
1979 extern int display_arg;
|
|
1980 #endif
|
|
1981
|
|
1982 meta_key = 0;
|
|
1983 inverse_video = 0;
|
|
1984 cursor_in_echo_area = 0;
|
|
1985 terminal_type = (char *) 0;
|
|
1986
|
|
1987 /* If the DISPLAY environment variable is set, try to use X, and
|
|
1988 die with an error message if that doesn't work. */
|
|
1989
|
|
1990 /* Check if we're using a window system here before trying to
|
|
1991 initialize the terminal. If we check the terminal first,
|
|
1992
|
|
1993 If someone has indicated that they want
|
|
1994 to use a window system, we shouldn't bother initializing the
|
|
1995 terminal. This is especially important when the terminal is so
|
|
1996 dumb that emacs gives up before and doesn't bother using the window
|
|
1997 system. */
|
|
1998
|
|
1999 #ifdef HAVE_X_WINDOWS
|
493
|
2000 if (!inhibit_window_system && (display_arg || getenv ("DISPLAY")))
|
314
|
2001 {
|
|
2002 Vwindow_system = intern ("x");
|
|
2003 #ifdef HAVE_X11
|
|
2004 Vwindow_system_version = make_number (11);
|
|
2005 #else
|
|
2006 Vwindow_system_version = make_number (10);
|
|
2007 #endif
|
|
2008 return;
|
|
2009 }
|
|
2010 #endif /* HAVE_X_WINDOWS */
|
|
2011
|
|
2012 /* If no window system has been specified, try to use the terminal. */
|
|
2013 if (! isatty (0))
|
|
2014 {
|
|
2015 fprintf (stderr, "emacs: standard input is not a tty\n");
|
|
2016 exit (1);
|
|
2017 }
|
|
2018
|
|
2019 /* Look at the TERM variable */
|
|
2020 terminal_type = (char *) getenv ("TERM");
|
|
2021 if (!terminal_type)
|
|
2022 {
|
|
2023 #ifdef VMS
|
|
2024 fprintf (stderr, "Please specify your terminal type.\n\
|
|
2025 For types defined in VMS, use set term /device=TYPE.\n\
|
|
2026 For types not defined in VMS, use define emacs_term \"TYPE\".\n\
|
|
2027 \(The quotation marks are necessary since terminal types are lower case.)\n");
|
|
2028 #else
|
|
2029 fprintf (stderr, "Please set the environment variable TERM; see tset(1).\n");
|
|
2030 #endif
|
|
2031 exit (1);
|
|
2032 }
|
|
2033
|
|
2034 #ifdef VMS
|
|
2035 /* VMS DCL tends to upcase things, so downcase term type.
|
|
2036 Hardly any uppercase letters in terminal types; should be none. */
|
|
2037 {
|
|
2038 char *new = (char *) xmalloc (strlen (terminal_type) + 1);
|
|
2039 char *p;
|
|
2040
|
|
2041 strcpy (new, terminal_type);
|
|
2042
|
|
2043 for (p = new; *p; p++)
|
|
2044 if (isupper (*p))
|
|
2045 *p = tolower (*p);
|
|
2046
|
|
2047 terminal_type = new;
|
|
2048 }
|
|
2049 #endif
|
|
2050
|
|
2051 term_init (terminal_type);
|
|
2052
|
|
2053 remake_screen_glyphs (selected_screen);
|
|
2054 calculate_costs (selected_screen);
|
|
2055
|
|
2056 /* X and Y coordinates of the cursor between updates. */
|
|
2057 SCREEN_CURSOR_X (selected_screen) = 0;
|
|
2058 SCREEN_CURSOR_Y (selected_screen) = 0;
|
|
2059
|
|
2060 #ifdef SIGWINCH
|
|
2061 #ifndef CANNOT_DUMP
|
|
2062 if (initialized)
|
|
2063 #endif /* CANNOT_DUMP */
|
|
2064 signal (SIGWINCH, window_change_signal);
|
|
2065 #endif /* SIGWINCH */
|
|
2066 }
|
|
2067
|
|
2068 syms_of_display ()
|
|
2069 {
|
|
2070 #ifdef MULTI_SCREEN
|
|
2071 defsubr (&Sredraw_screen);
|
|
2072 #endif
|
|
2073 defsubr (&Sredraw_display);
|
|
2074 defsubr (&Sopen_termscript);
|
|
2075 defsubr (&Sding);
|
|
2076 defsubr (&Ssit_for);
|
|
2077 defsubr (&Ssleep_for);
|
|
2078 defsubr (&Ssend_string_to_terminal);
|
|
2079
|
|
2080 DEFVAR_INT ("baud-rate", &baud_rate,
|
|
2081 "The output baud rate of the terminal.\n\
|
|
2082 On most systems, changing this value will affect the amount of padding\n\
|
|
2083 and the other strategic decisions made during redisplay.");
|
|
2084 DEFVAR_BOOL ("inverse-video", &inverse_video,
|
|
2085 "*Non-nil means invert the entire screen display.\n\
|
|
2086 This means everything is in inverse video which otherwise would not be.");
|
|
2087 DEFVAR_BOOL ("visible-bell", &visible_bell,
|
|
2088 "*Non-nil means try to flash the screen to represent a bell.");
|
|
2089 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter,
|
|
2090 "*Non-nil means no need to redraw entire screen after suspending.\n\
|
|
2091 A non-nil value is useful if the terminal can automatically preserve\n\
|
|
2092 Emacs's screen display when you reenter Emacs.\n\
|
|
2093 It is up to you to set this variable if your terminal can do that.");
|
|
2094 DEFVAR_LISP ("window-system", &Vwindow_system,
|
|
2095 "A symbol naming the window-system under which Emacs is running\n\
|
|
2096 \(such as `x'), or nil if emacs is running on an ordinary terminal.");
|
|
2097 DEFVAR_LISP ("window-system-version", &Vwindow_system_version,
|
|
2098 "The version number of the window system in use.\n\
|
|
2099 For X windows, this is 10 or 11.");
|
|
2100 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area,
|
|
2101 "Non-nil means put cursor in minibuffer, at end of any message there.");
|
|
2102 DEFVAR_LISP ("glyph-table", &Vglyph_table,
|
|
2103 "Table defining how to output a glyph code to the screen.\n\
|
|
2104 If not nil, this is a vector indexed by glyph code to define the glyph.\n\
|
|
2105 Each element can be:\n\
|
|
2106 integer: a glyph code which this glyph is an alias for.\n\
|
|
2107 string: output this glyph using that string (not impl. in X windows).\n\
|
|
2108 nil: this glyph mod 256 is char code to output,\n\
|
|
2109 and this glyph / 256 is face code for X windows (see `x-set-face').");
|
|
2110 Vglyph_table = Qnil;
|
|
2111
|
|
2112 DEFVAR_LISP ("standard-display-table", &Vstandard_display_table,
|
|
2113 "Display table to use for buffers that specify none.\n\
|
|
2114 See `buffer-display-table' for more information.");
|
|
2115 Vstandard_display_table = Qnil;
|
|
2116
|
|
2117 /* Initialize `window-system', unless init_display already decided it. */
|
|
2118 #ifdef CANNOT_DUMP
|
|
2119 if (noninteractive)
|
|
2120 #endif
|
|
2121 {
|
|
2122 Vwindow_system = Qnil;
|
|
2123 Vwindow_system_version = Qnil;
|
|
2124 }
|
|
2125 }
|
|
2126
|