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