(timeout-event-p): Function deleted.
[emacs.git] / src / dispnew.c
blob201f4a579e79aa45a7396ce0fcaa6de34c124a07
1 /* Updating of data structures for redisplay.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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 2, or (at your option)
9 any later version.
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.
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, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include <signal.h>
24 #include <config.h>
26 #include <stdio.h>
27 #include <ctype.h>
29 #include "lisp.h"
30 #include "termchar.h"
31 #include "termopts.h"
32 #include "termhooks.h"
33 /* cm.h must come after dispextern.h on Windows. */
34 #include "dispextern.h"
35 #include "cm.h"
36 #include "buffer.h"
37 #include "frame.h"
38 #include "window.h"
39 #include "commands.h"
40 #include "disptab.h"
41 #include "indent.h"
42 #include "intervals.h"
44 #include "systty.h"
45 #include "syssignal.h"
47 #ifdef HAVE_X_WINDOWS
48 #include "xterm.h"
49 #endif /* HAVE_X_WINDOWS */
51 #ifdef HAVE_NTGUI
52 #include "w32term.h"
53 #endif /* HAVE_NTGUI */
55 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
56 #include "systime.h"
58 #include <errno.h>
60 #define max(a, b) ((a) > (b) ? (a) : (b))
61 #define min(a, b) ((a) < (b) ? (a) : (b))
63 /* Get number of chars of output now in the buffer of a stdio stream.
64 This ought to be built in in stdio, but it isn't.
65 Some s- files override this because their stdio internals differ. */
66 #ifdef __GNU_LIBRARY__
67 /* The s- file might have overridden the definition with one that works for
68 the system's C library. But we are using the GNU C library, so this is
69 the right definition for every system. */
70 #ifdef GNU_LIBRARY_PENDING_OUTPUT_COUNT
71 #define PENDING_OUTPUT_COUNT GNU_LIBRARY_PENDING_OUTPUT_COUNT
72 #else
73 #undef PENDING_OUTPUT_COUNT
74 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
75 #endif
76 #else /* not __GNU_LIBRARY__ */
77 #ifndef PENDING_OUTPUT_COUNT
78 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
79 #endif
80 #endif
82 static void change_frame_size_1 ();
84 /* Nonzero upon entry to redisplay means do not assume anything about
85 current contents of actual terminal frame; clear and redraw it. */
87 int frame_garbaged;
89 /* Nonzero means last display completed. Zero means it was preempted. */
91 int display_completed;
93 /* Lisp variable visible-bell; enables use of screen-flash
94 instead of audible bell. */
96 int visible_bell;
98 /* Invert the color of the whole frame, at a low level. */
100 int inverse_video;
102 /* Line speed of the terminal. */
104 int baud_rate;
106 /* nil or a symbol naming the window system under which emacs is
107 running ('x is the only current possibility). */
109 Lisp_Object Vwindow_system;
111 /* Version number of X windows: 10, 11 or nil. */
112 Lisp_Object Vwindow_system_version;
114 /* Vector of glyph definitions. Indexed by glyph number,
115 the contents are a string which is how to output the glyph.
117 If Vglyph_table is nil, a glyph is output by using its low 8 bits
118 as a character code. */
120 Lisp_Object Vglyph_table;
122 /* Display table to use for vectors that don't specify their own. */
124 Lisp_Object Vstandard_display_table;
126 /* Nonzero means reading single-character input with prompt
127 so put cursor on minibuffer after the prompt.
128 positive means at end of text in echo area;
129 negative means at beginning of line. */
130 int cursor_in_echo_area;
132 Lisp_Object Qdisplay_table;
134 /* The currently selected frame.
135 In a single-frame version, this variable always holds the address of
136 the_only_frame. */
138 FRAME_PTR selected_frame;
140 /* A frame which is not just a minibuffer, or 0 if there are no such
141 frames. This is usually the most recent such frame that was
142 selected. In a single-frame version, this variable always holds
143 the address of the_only_frame. */
144 FRAME_PTR last_nonminibuf_frame;
146 /* In a single-frame version, the information that would otherwise
147 exist inside frame objects lives in the following structure instead.
149 NOTE: the_only_frame is not checked for garbage collection; don't
150 store collectible objects in any of its fields!
152 You're not/The only frame in town/... */
154 #ifndef MULTI_FRAME
155 struct frame the_only_frame;
156 #endif
158 /* This is a vector, made larger whenever it isn't large enough,
159 which is used inside `update_frame' to hold the old contents
160 of the FRAME_PHYS_LINES of the frame being updated. */
161 struct frame_glyphs **ophys_lines;
162 /* Length of vector currently allocated. */
163 int ophys_lines_length;
165 FILE *termscript; /* Stdio stream being used for copy of all output. */
167 struct cm Wcm; /* Structure for info on cursor positioning */
169 extern short ospeed; /* Output speed (from sg_ospeed) */
171 int delayed_size_change; /* 1 means SIGWINCH happened when not safe. */
173 #ifdef MULTI_FRAME
175 DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0,
176 "Clear frame FRAME and output again what is supposed to appear on it.")
177 (frame)
178 Lisp_Object frame;
180 FRAME_PTR f;
182 CHECK_LIVE_FRAME (frame, 0);
183 f = XFRAME (frame);
184 update_begin (f);
185 /* set_terminal_modes (); */
186 clear_frame ();
187 clear_frame_records (f);
188 update_end (f);
189 fflush (stdout);
190 windows_or_buffers_changed++;
191 /* Mark all windows as INaccurate,
192 so that every window will have its redisplay done. */
193 mark_window_display_accurate (FRAME_ROOT_WINDOW (f), 0);
194 f->garbaged = 0;
195 return Qnil;
198 redraw_frame (f)
199 FRAME_PTR f;
201 Lisp_Object frame;
202 XSETFRAME (frame, f);
203 Fredraw_frame (frame);
206 #else
208 DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0,
209 /* Don't confuse make-docfile by having two doc strings for this function.
210 make-docfile does not pay attention to #if, for good reason! */
212 (frame)
213 Lisp_Object frame;
215 update_begin (0);
216 set_terminal_modes ();
217 clear_frame ();
218 update_end (0);
219 fflush (stdout);
220 clear_frame_records (0);
221 windows_or_buffers_changed++;
222 /* Mark all windows as INaccurate,
223 so that every window will have its redisplay done. */
224 mark_window_display_accurate (FRAME_ROOT_WINDOW (0), 0);
225 return Qnil;
228 #endif
230 DEFUN ("redraw-display", Fredraw_display, Sredraw_display, 0, 0, "",
231 "Clear and redisplay all visible frames.")
234 Lisp_Object tail, frame;
236 FOR_EACH_FRAME (tail, frame)
237 if (FRAME_VISIBLE_P (XFRAME (frame)))
238 Fredraw_frame (frame);
240 return Qnil;
243 /* This is used when frame_garbaged is set.
244 Redraw the individual frames marked as garbaged. */
246 void
247 redraw_garbaged_frames ()
249 Lisp_Object tail, frame;
251 FOR_EACH_FRAME (tail, frame)
252 if (FRAME_VISIBLE_P (XFRAME (frame))
253 && FRAME_GARBAGED_P (XFRAME (frame)))
254 Fredraw_frame (frame);
258 static struct frame_glyphs *
259 make_frame_glyphs (frame, empty)
260 register FRAME_PTR frame;
261 int empty;
263 register int i;
264 register width = FRAME_WIDTH (frame);
265 register height = FRAME_HEIGHT (frame);
266 register struct frame_glyphs *new
267 = (struct frame_glyphs *) xmalloc (sizeof (struct frame_glyphs));
269 SET_GLYPHS_FRAME (new, frame);
270 new->height = height;
271 new->width = width;
272 new->used = (int *) xmalloc (height * sizeof (int));
273 new->glyphs = (GLYPH **) xmalloc (height * sizeof (GLYPH *));
274 new->charstarts = (int **) xmalloc (height * sizeof (int *));
275 new->highlight = (char *) xmalloc (height * sizeof (char));
276 new->enable = (char *) xmalloc (height * sizeof (char));
277 bzero (new->enable, height * sizeof (char));
278 new->bufp = (int *) xmalloc (height * sizeof (int));
280 #ifdef HAVE_WINDOW_SYSTEM
281 if (FRAME_WINDOW_P (frame))
283 new->top_left_x = (short *) xmalloc (height * sizeof (short));
284 new->top_left_y = (short *) xmalloc (height * sizeof (short));
285 new->pix_width = (short *) xmalloc (height * sizeof (short));
286 new->pix_height = (short *) xmalloc (height * sizeof (short));
287 new->max_ascent = (short *) xmalloc (height * sizeof (short));
289 #endif /* HAVE_WINDOW_SYSTEM */
291 if (empty)
293 /* Make the buffer used by decode_mode_spec. This buffer is also
294 used as temporary storage when updating the frame. See scroll.c. */
295 unsigned int total_glyphs = (width + 2) * sizeof (GLYPH);
296 unsigned int total_charstarts = (width + 2) * sizeof (int);
298 new->total_contents = (GLYPH *) xmalloc (total_glyphs);
299 bzero (new->total_contents, total_glyphs);
301 new->total_charstarts = (int *) xmalloc (total_charstarts);
302 bzero (new->total_charstarts, total_glyphs);
304 else
306 unsigned int total_glyphs = height * (width + 2) * sizeof (GLYPH);
308 new->total_contents = (GLYPH *) xmalloc (total_glyphs);
309 bzero (new->total_contents, total_glyphs);
310 for (i = 0; i < height; i++)
311 new->glyphs[i] = new->total_contents + i * (width + 2) + 1;
313 if (!FRAME_TERMCAP_P (frame))
315 unsigned int total_charstarts = height * (width + 2) * sizeof (int);
317 new->total_charstarts = (int *) xmalloc (total_charstarts);
318 bzero (new->total_charstarts, total_charstarts);
319 for (i = 0; i < height; i++)
320 new->charstarts[i] = new->total_charstarts + i * (width + 2) + 1;
322 else
324 /* Without a window system, we don't really need charstarts.
325 So use a small amount of space to make enough data structure
326 to prevent crashes in display_text_line. */
327 new->total_charstarts = (int *) xmalloc ((width + 2) * sizeof (int));
328 for (i = 0; i < height; i++)
329 new->charstarts[i] = new->total_charstarts;
333 return new;
336 void
337 free_frame_glyphs (frame, glyphs)
338 FRAME_PTR frame;
339 struct frame_glyphs *glyphs;
341 if (glyphs->total_contents)
342 xfree (glyphs->total_contents);
343 if (glyphs->total_charstarts)
344 xfree (glyphs->total_charstarts);
346 xfree (glyphs->used);
347 xfree (glyphs->glyphs);
348 xfree (glyphs->highlight);
349 xfree (glyphs->enable);
350 xfree (glyphs->bufp);
351 if (glyphs->charstarts)
352 xfree (glyphs->charstarts);
354 #ifdef HAVE_WINDOW_SYSTEM
355 if (FRAME_WINDOW_P (frame))
357 xfree (glyphs->top_left_x);
358 xfree (glyphs->top_left_y);
359 xfree (glyphs->pix_width);
360 xfree (glyphs->pix_height);
361 xfree (glyphs->max_ascent);
363 #endif /* HAVE_WINDOW_SYSTEM */
365 xfree (glyphs);
368 void
369 remake_frame_glyphs (frame)
370 FRAME_PTR frame;
372 if (FRAME_CURRENT_GLYPHS (frame))
373 free_frame_glyphs (frame, FRAME_CURRENT_GLYPHS (frame));
374 if (FRAME_DESIRED_GLYPHS (frame))
375 free_frame_glyphs (frame, FRAME_DESIRED_GLYPHS (frame));
376 if (FRAME_TEMP_GLYPHS (frame))
377 free_frame_glyphs (frame, FRAME_TEMP_GLYPHS (frame));
379 if (FRAME_MESSAGE_BUF (frame))
381 /* Reallocate the frame's message buffer; remember that
382 echo_area_glyphs may be pointing here. */
383 char *old_message_buf = FRAME_MESSAGE_BUF (frame);
385 FRAME_MESSAGE_BUF (frame)
386 = (char *) xrealloc (FRAME_MESSAGE_BUF (frame),
387 FRAME_WIDTH (frame) + 1);
389 if (echo_area_glyphs == old_message_buf)
390 echo_area_glyphs = FRAME_MESSAGE_BUF (frame);
391 if (previous_echo_glyphs == old_message_buf)
392 previous_echo_glyphs = FRAME_MESSAGE_BUF (frame);
394 else
395 FRAME_MESSAGE_BUF (frame)
396 = (char *) xmalloc (FRAME_WIDTH (frame) + 1);
398 FRAME_CURRENT_GLYPHS (frame) = make_frame_glyphs (frame, 0);
399 FRAME_DESIRED_GLYPHS (frame) = make_frame_glyphs (frame, 0);
400 FRAME_TEMP_GLYPHS (frame) = make_frame_glyphs (frame, 1);
401 if (! FRAME_TERMCAP_P (frame) || frame == selected_frame)
402 SET_FRAME_GARBAGED (frame);
405 /* Return the hash code of contents of line VPOS in frame-matrix M. */
407 static int
408 line_hash_code (m, vpos)
409 register struct frame_glyphs *m;
410 int vpos;
412 register GLYPH *body, *end;
413 register int h = 0;
415 if (!m->enable[vpos])
416 return 0;
418 /* Give all highlighted lines the same hash code
419 so as to encourage scrolling to leave them in place. */
420 if (m->highlight[vpos])
421 return -1;
423 body = m->glyphs[vpos];
425 if (must_write_spaces)
426 while (1)
428 GLYPH g = *body++;
430 if (g == 0)
431 break;
432 h = (((h << 4) + (h >> 24)) & 0x0fffffff) + g - SPACEGLYPH;
434 else
435 while (1)
437 GLYPH g = *body++;
439 if (g == 0)
440 break;
441 h = (((h << 4) + (h >> 24)) & 0x0fffffff) + g;
444 if (h)
445 return h;
446 return 1;
449 /* Return number of characters in line in M at vpos VPOS,
450 except don't count leading and trailing spaces
451 unless the terminal requires those to be explicitly output. */
453 static unsigned int
454 line_draw_cost (m, vpos)
455 struct frame_glyphs *m;
456 int vpos;
458 register GLYPH *beg = m->glyphs[vpos];
459 register GLYPH *end = m->glyphs[vpos] + m->used[vpos];
460 register int i;
461 register int tlen = GLYPH_TABLE_LENGTH;
462 register Lisp_Object *tbase = GLYPH_TABLE_BASE;
464 /* Ignore trailing and leading spaces if we can. */
465 if (!must_write_spaces)
467 while ((end != beg) && (*end == SPACEGLYPH))
468 --end;
469 if (end == beg)
470 return (0); /* All blank line. */
472 while (*beg == SPACEGLYPH)
473 ++beg;
476 /* If we don't have a glyph-table, each glyph is one character,
477 so return the number of glyphs. */
478 if (tbase == 0)
479 return end - beg;
481 /* Otherwise, scan the glyphs and accumulate their total size in I. */
482 i = 0;
483 while ((beg <= end) && *beg)
485 register GLYPH g = *beg++;
487 if (GLYPH_SIMPLE_P (tbase, tlen, g))
488 i += 1;
489 else
490 i += GLYPH_LENGTH (tbase, g);
492 return i;
495 /* The functions on this page are the interface from xdisp.c to redisplay.
497 The only other interface into redisplay is through setting
498 FRAME_CURSOR_X (frame) and FRAME_CURSOR_Y (frame)
499 and SET_FRAME_GARBAGED (frame). */
501 /* cancel_line eliminates any request to display a line at position `vpos' */
503 cancel_line (vpos, frame)
504 int vpos;
505 register FRAME_PTR frame;
507 FRAME_DESIRED_GLYPHS (frame)->enable[vpos] = 0;
510 clear_frame_records (frame)
511 register FRAME_PTR frame;
513 bzero (FRAME_CURRENT_GLYPHS (frame)->enable, FRAME_HEIGHT (frame));
516 /* Clear out all display lines for a coming redisplay. */
518 void
519 init_desired_glyphs (frame)
520 register FRAME_PTR frame;
522 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (frame);
523 int vpos;
524 int height = FRAME_HEIGHT (frame);
526 for (vpos = 0; vpos < height; vpos++)
527 desired_glyphs->enable[vpos] = 0;
530 /* Prepare to display on line VPOS starting at HPOS within it. */
532 void
533 get_display_line (frame, vpos, hpos)
534 register FRAME_PTR frame;
535 int vpos;
536 register int hpos;
538 register struct frame_glyphs *glyphs;
539 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (frame);
540 register GLYPH *p;
542 if (vpos < 0)
543 abort ();
545 if (! desired_glyphs->enable[vpos])
547 desired_glyphs->used[vpos] = 0;
548 desired_glyphs->highlight[vpos] = 0;
549 desired_glyphs->enable[vpos] = 1;
552 if (hpos > desired_glyphs->used[vpos])
554 GLYPH *g = desired_glyphs->glyphs[vpos] + desired_glyphs->used[vpos];
555 GLYPH *end = desired_glyphs->glyphs[vpos] + hpos;
557 desired_glyphs->used[vpos] = hpos;
558 while (g != end)
559 *g++ = SPACEGLYPH;
563 /* Like bcopy except never gets confused by overlap. */
565 void
566 safe_bcopy (from, to, size)
567 char *from, *to;
568 int size;
570 if (size <= 0 || from == to)
571 return;
573 /* If the source and destination don't overlap, then bcopy can
574 handle it. If they do overlap, but the destination is lower in
575 memory than the source, we'll assume bcopy can handle that. */
576 if (to < from || from + size <= to)
577 bcopy (from, to, size);
579 /* Otherwise, we'll copy from the end. */
580 else
582 register char *endf = from + size;
583 register char *endt = to + size;
585 /* If TO - FROM is large, then we should break the copy into
586 nonoverlapping chunks of TO - FROM bytes each. However, if
587 TO - FROM is small, then the bcopy function call overhead
588 makes this not worth it. The crossover point could be about
589 anywhere. Since I don't think the obvious copy loop is too
590 bad, I'm trying to err in its favor. */
591 if (to - from < 64)
594 *--endt = *--endf;
595 while (endf != from);
597 else
599 for (;;)
601 endt -= (to - from);
602 endf -= (to - from);
604 if (endt < to)
605 break;
607 bcopy (endf, endt, to - from);
610 /* If SIZE wasn't a multiple of TO - FROM, there will be a
611 little left over. The amount left over is
612 (endt + (to - from)) - to, which is endt - from. */
613 bcopy (from, to, endt - from);
618 /* Rotate a vector of SIZE bytes right, by DISTANCE bytes.
619 DISTANCE may be negative. */
621 static void
622 rotate_vector (vector, size, distance)
623 char *vector;
624 int size;
625 int distance;
627 char *temp = (char *) alloca (size);
629 if (distance < 0)
630 distance += size;
632 bcopy (vector, temp + distance, size - distance);
633 bcopy (vector + size - distance, temp, distance);
634 bcopy (temp, vector, size);
637 /* Scroll lines from vpos FROM up to but not including vpos END
638 down by AMOUNT lines (AMOUNT may be negative).
639 Returns nonzero if done, zero if terminal cannot scroll them. */
642 scroll_frame_lines (frame, from, end, amount, newpos)
643 register FRAME_PTR frame;
644 int from, end, amount, newpos;
646 register int i;
647 register struct frame_glyphs *current_frame
648 = FRAME_CURRENT_GLYPHS (frame);
649 int pos_adjust;
650 int width = FRAME_WIDTH (frame);
652 if (!line_ins_del_ok)
653 return 0;
655 if (amount == 0)
656 return 1;
658 if (amount > 0)
660 update_begin (frame);
661 set_terminal_window (end + amount);
662 if (!scroll_region_ok)
663 ins_del_lines (end, -amount);
664 ins_del_lines (from, amount);
665 set_terminal_window (0);
667 rotate_vector (current_frame->glyphs + from,
668 sizeof (GLYPH *) * (end + amount - from),
669 amount * sizeof (GLYPH *));
671 rotate_vector (current_frame->charstarts + from,
672 sizeof (int *) * (end + amount - from),
673 amount * sizeof (int *));
675 safe_bcopy (current_frame->used + from,
676 current_frame->used + from + amount,
677 (end - from) * sizeof current_frame->used[0]);
679 safe_bcopy (current_frame->highlight + from,
680 current_frame->highlight + from + amount,
681 (end - from) * sizeof current_frame->highlight[0]);
683 safe_bcopy (current_frame->enable + from,
684 current_frame->enable + from + amount,
685 (end - from) * sizeof current_frame->enable[0]);
687 /* Adjust the lines by an amount
688 that puts the first of them at NEWPOS. */
689 pos_adjust = newpos - current_frame->charstarts[from + amount][0];
691 /* Offset each char position in the charstarts lines we moved
692 by pos_adjust. */
693 for (i = from + amount; i < end + amount; i++)
695 int *line = current_frame->charstarts[i];
696 int col;
697 for (col = 0; col < width; col++)
698 if (line[col] > 0)
699 line[col] += pos_adjust;
701 for (i = from; i < from + amount; i++)
703 int *line = current_frame->charstarts[i];
704 int col;
705 line[0] = -1;
706 for (col = 0; col < width; col++)
707 line[col] = 0;
710 /* Mark the lines made empty by scrolling as enabled, empty and
711 normal video. */
712 bzero (current_frame->used + from,
713 amount * sizeof current_frame->used[0]);
714 bzero (current_frame->highlight + from,
715 amount * sizeof current_frame->highlight[0]);
716 for (i = from; i < from + amount; i++)
718 current_frame->glyphs[i][0] = '\0';
719 current_frame->charstarts[i][0] = -1;
720 current_frame->enable[i] = 1;
723 safe_bcopy (current_frame->bufp + from,
724 current_frame->bufp + from + amount,
725 (end - from) * sizeof current_frame->bufp[0]);
727 #ifdef HAVE_WINDOW_SYSTEM
728 if (FRAME_WINDOW_P (frame))
730 safe_bcopy (current_frame->top_left_x + from,
731 current_frame->top_left_x + from + amount,
732 (end - from) * sizeof current_frame->top_left_x[0]);
734 safe_bcopy (current_frame->top_left_y + from,
735 current_frame->top_left_y + from + amount,
736 (end - from) * sizeof current_frame->top_left_y[0]);
738 safe_bcopy (current_frame->pix_width + from,
739 current_frame->pix_width + from + amount,
740 (end - from) * sizeof current_frame->pix_width[0]);
742 safe_bcopy (current_frame->pix_height + from,
743 current_frame->pix_height + from + amount,
744 (end - from) * sizeof current_frame->pix_height[0]);
746 safe_bcopy (current_frame->max_ascent + from,
747 current_frame->max_ascent + from + amount,
748 (end - from) * sizeof current_frame->max_ascent[0]);
750 #endif /* HAVE_WINDOW_SYSTEM */
752 update_end (frame);
754 if (amount < 0)
756 update_begin (frame);
757 set_terminal_window (end);
758 ins_del_lines (from + amount, amount);
759 if (!scroll_region_ok)
760 ins_del_lines (end + amount, -amount);
761 set_terminal_window (0);
763 rotate_vector (current_frame->glyphs + from + amount,
764 sizeof (GLYPH *) * (end - from - amount),
765 amount * sizeof (GLYPH *));
767 rotate_vector (current_frame->charstarts + from + amount,
768 sizeof (int *) * (end - from - amount),
769 amount * sizeof (int *));
771 safe_bcopy (current_frame->used + from,
772 current_frame->used + from + amount,
773 (end - from) * sizeof current_frame->used[0]);
775 safe_bcopy (current_frame->highlight + from,
776 current_frame->highlight + from + amount,
777 (end - from) * sizeof current_frame->highlight[0]);
779 safe_bcopy (current_frame->enable + from,
780 current_frame->enable + from + amount,
781 (end - from) * sizeof current_frame->enable[0]);
783 /* Adjust the lines by an amount
784 that puts the first of them at NEWPOS. */
785 pos_adjust = newpos - current_frame->charstarts[from + amount][0];
787 /* Offset each char position in the charstarts lines we moved
788 by pos_adjust. */
789 for (i = from + amount; i < end + amount; i++)
791 int *line = current_frame->charstarts[i];
792 int col;
793 for (col = 0; col < width; col++)
794 if (line[col] > 0)
795 line[col] += pos_adjust;
797 for (i = end + amount; i < end; i++)
799 int *line = current_frame->charstarts[i];
800 int col;
801 line[0] = -1;
802 for (col = 0; col < width; col++)
803 line[col] = 0;
806 /* Mark the lines made empty by scrolling as enabled, empty and
807 normal video. */
808 bzero (current_frame->used + end + amount,
809 - amount * sizeof current_frame->used[0]);
810 bzero (current_frame->highlight + end + amount,
811 - amount * sizeof current_frame->highlight[0]);
812 for (i = end + amount; i < end; i++)
814 current_frame->glyphs[i][0] = '\0';
815 current_frame->charstarts[i][0] = 0;
816 current_frame->enable[i] = 1;
819 safe_bcopy (current_frame->bufp + from,
820 current_frame->bufp + from + amount,
821 (end - from) * sizeof current_frame->bufp[0]);
823 #ifdef HAVE_WINDOW_SYSTEM
824 if (FRAME_WINDOW_P (frame))
826 safe_bcopy (current_frame->top_left_x + from,
827 current_frame->top_left_x + from + amount,
828 (end - from) * sizeof current_frame->top_left_x[0]);
830 safe_bcopy (current_frame->top_left_y + from,
831 current_frame->top_left_y + from + amount,
832 (end - from) * sizeof current_frame->top_left_y[0]);
834 safe_bcopy (current_frame->pix_width + from,
835 current_frame->pix_width + from + amount,
836 (end - from) * sizeof current_frame->pix_width[0]);
838 safe_bcopy (current_frame->pix_height + from,
839 current_frame->pix_height + from + amount,
840 (end - from) * sizeof current_frame->pix_height[0]);
842 safe_bcopy (current_frame->max_ascent + from,
843 current_frame->max_ascent + from + amount,
844 (end - from) * sizeof current_frame->max_ascent[0]);
846 #endif /* HAVE_WINDOW_SYSTEM */
848 update_end (frame);
850 return 1;
853 /* After updating a window W that isn't the full frame wide,
854 copy all the columns that W does not occupy
855 into the FRAME_DESIRED_GLYPHS (frame) from the FRAME_PHYS_GLYPHS (frame)
856 so that update_frame will not change those columns. */
858 preserve_other_columns (w)
859 struct window *w;
861 register int vpos;
862 register struct frame_glyphs *current_frame, *desired_frame;
863 register FRAME_PTR frame = XFRAME (w->frame);
864 int start = XFASTINT (w->left);
865 int end = XFASTINT (w->left) + XFASTINT (w->width);
866 int bot = XFASTINT (w->top) + XFASTINT (w->height);
868 current_frame = FRAME_CURRENT_GLYPHS (frame);
869 desired_frame = FRAME_DESIRED_GLYPHS (frame);
871 for (vpos = XFASTINT (w->top); vpos < bot; vpos++)
873 if (current_frame->enable[vpos] && desired_frame->enable[vpos])
875 if (start > 0)
877 int len;
879 bcopy (current_frame->glyphs[vpos],
880 desired_frame->glyphs[vpos],
881 start * sizeof (current_frame->glyphs[vpos][0]));
882 bcopy (current_frame->charstarts[vpos],
883 desired_frame->charstarts[vpos],
884 start * sizeof (current_frame->charstarts[vpos][0]));
885 len = min (start, current_frame->used[vpos]);
886 if (desired_frame->used[vpos] < len)
887 desired_frame->used[vpos] = len;
889 if (current_frame->used[vpos] > end
890 && desired_frame->used[vpos] < current_frame->used[vpos])
892 while (desired_frame->used[vpos] < end)
894 int used = desired_frame->used[vpos]++;
895 desired_frame->glyphs[vpos][used] = SPACEGLYPH;
896 desired_frame->glyphs[vpos][used] = 0;
898 bcopy (current_frame->glyphs[vpos] + end,
899 desired_frame->glyphs[vpos] + end,
900 ((current_frame->used[vpos] - end)
901 * sizeof (current_frame->glyphs[vpos][0])));
902 bcopy (current_frame->charstarts[vpos] + end,
903 desired_frame->charstarts[vpos] + end,
904 ((current_frame->used[vpos] - end)
905 * sizeof (current_frame->charstarts[vpos][0])));
906 desired_frame->used[vpos] = current_frame->used[vpos];
912 #if 0
914 /* If window w does not need to be updated and isn't the full frame wide,
915 copy all the columns that w does occupy
916 into the FRAME_DESIRED_LINES (frame) from the FRAME_PHYS_LINES (frame)
917 so that update_frame will not change those columns.
919 Have not been able to figure out how to use this correctly. */
921 preserve_my_columns (w)
922 struct window *w;
924 register int vpos, fin;
925 register struct frame_glyphs *l1, *l2;
926 register FRAME_PTR frame = XFRAME (w->frame);
927 int start = XFASTINT (w->left);
928 int end = XFASTINT (w->left) + XFASTINT (w->width);
929 int bot = XFASTINT (w->top) + XFASTINT (w->height);
931 for (vpos = XFASTINT (w->top); vpos < bot; vpos++)
933 if ((l1 = FRAME_DESIRED_GLYPHS (frame)->glyphs[vpos + 1])
934 && (l2 = FRAME_PHYS_GLYPHS (frame)->glyphs[vpos + 1]))
936 if (l2->length > start && l1->length < l2->length)
938 fin = l2->length;
939 if (fin > end) fin = end;
940 while (l1->length < start)
941 l1->body[l1->length++] = ' ';
942 bcopy (l2->body + start, l1->body + start, fin - start);
943 l1->length = fin;
949 #endif
951 /* Adjust by ADJUST the charstart values in window W
952 after vpos VPOS, which counts relative to the frame
953 (not relative to W itself). */
955 void
956 adjust_window_charstarts (w, vpos, adjust)
957 struct window *w;
958 int vpos;
959 int adjust;
961 int left = XFASTINT (w->left);
962 int top = XFASTINT (w->top);
963 int right = left + window_internal_width (w);
964 int bottom = top + window_internal_height (w);
965 int i;
967 for (i = vpos + 1; i < bottom; i++)
969 int *charstart
970 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[i];
971 int j;
972 for (j = left; j < right; j++)
973 if (charstart[j] > 0)
974 charstart[j] += adjust;
978 /* Check the charstarts values in the area of window W
979 for internal consistency. We cannot check that they are "right";
980 we can only look for something nonsensical. */
982 verify_charstarts (w)
983 struct window *w;
985 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
986 int i;
987 int top = XFASTINT (w->top);
988 int bottom = top + window_internal_height (w);
989 int left = XFASTINT (w->left);
990 int right = left + window_internal_width (w);
991 int next_line;
992 int truncate = (XINT (w->hscroll)
993 || (truncate_partial_width_windows
994 && (XFASTINT (w->width) < FRAME_WIDTH (f)))
995 || !NILP (XBUFFER (w->buffer)->truncate_lines));
997 for (i = top; i < bottom; i++)
999 int j;
1000 int last;
1001 int *charstart = FRAME_CURRENT_GLYPHS (f)->charstarts[i];
1003 if (i != top)
1005 if (truncate)
1007 /* If we are truncating lines, allow a jump
1008 in charstarts from one line to the next. */
1009 if (charstart[left] < next_line)
1010 abort ();
1012 else
1014 if (charstart[left] != next_line)
1015 abort ();
1019 for (j = left; j < right; j++)
1020 if (charstart[j] > 0)
1021 last = charstart[j];
1022 /* Record where the next line should start. */
1023 next_line = last;
1024 if (BUF_ZV (XBUFFER (w->buffer)) != last)
1026 /* If there's a newline between the two lines, count that. */
1027 int endchar = *BUF_CHAR_ADDRESS (XBUFFER (w->buffer), last);
1028 if (endchar == '\n')
1029 next_line++;
1034 /* On discovering that the redisplay for a window was no good,
1035 cancel the columns of that window, so that when the window is
1036 displayed over again get_display_line will not complain. */
1038 cancel_my_columns (w)
1039 struct window *w;
1041 register int vpos;
1042 register struct frame_glyphs *desired_glyphs
1043 = FRAME_DESIRED_GLYPHS (XFRAME (w->frame));
1044 register int start = XFASTINT (w->left);
1045 register int bot = XFASTINT (w->top) + XFASTINT (w->height);
1047 for (vpos = XFASTINT (w->top); vpos < bot; vpos++)
1048 if (desired_glyphs->enable[vpos]
1049 && desired_glyphs->used[vpos] >= start)
1050 desired_glyphs->used[vpos] = start;
1053 /* These functions try to perform directly and immediately on the frame
1054 the necessary output for one change in the buffer.
1055 They may return 0 meaning nothing was done if anything is difficult,
1056 or 1 meaning the output was performed properly.
1057 They assume that the frame was up to date before the buffer
1058 change being displayed. They make various other assumptions too;
1059 see command_loop_1 where these are called. */
1062 direct_output_for_insert (g)
1063 int g;
1065 register FRAME_PTR frame = selected_frame;
1066 register struct frame_glyphs *current_frame
1067 = FRAME_CURRENT_GLYPHS (frame);
1069 #ifndef COMPILER_REGISTER_BUG
1070 register
1071 #endif /* COMPILER_REGISTER_BUG */
1072 struct window *w = XWINDOW (selected_window);
1073 #ifndef COMPILER_REGISTER_BUG
1074 register
1075 #endif /* COMPILER_REGISTER_BUG */
1076 int hpos = FRAME_CURSOR_X (frame);
1077 #ifndef COMPILER_REGISTER_BUG
1078 register
1079 #endif /* COMPILER_REGISTER_BUG */
1080 int vpos = FRAME_CURSOR_Y (frame);
1082 /* Give up if about to continue line. */
1083 if (hpos >= XFASTINT (w->left) + window_internal_width (w) - 1
1085 /* Avoid losing if cursor is in invisible text off left margin */
1086 || (XINT (w->hscroll) && hpos == XFASTINT (w->left))
1088 /* Give up if cursor outside window (in minibuf, probably) */
1089 || cursor_in_echo_area
1090 || FRAME_CURSOR_Y (frame) < XFASTINT (w->top)
1091 || FRAME_CURSOR_Y (frame) >= XFASTINT (w->top) + XFASTINT (w->height)
1093 /* Give up if cursor not really at FRAME_CURSOR_X, FRAME_CURSOR_Y */
1094 || !display_completed
1096 /* Give up if buffer appears in two places. */
1097 || buffer_shared > 1
1099 #ifdef USE_TEXT_PROPERTIES
1100 /* Intervals have already been adjusted, point is after the
1101 character that was just inserted. */
1102 /* Give up if character is invisible. */
1103 /* Give up if character has a face property.
1104 At the moment we only lose at end of line or end of buffer
1105 and only with faces that have some background */
1106 /* Instead of wasting time, give up if character has any text properties */
1107 || ! NILP (Ftext_properties_at (make_number (point - 1), Qnil))
1108 #endif
1110 /* Give up if w is minibuffer and a message is being displayed there */
1111 || (MINI_WINDOW_P (w) && echo_area_glyphs))
1112 return 0;
1115 int face = 0;
1116 #ifdef HAVE_FACES
1117 int dummy;
1119 if (FRAME_WINDOW_P (frame))
1120 face = compute_char_face (frame, w, point - 1, -1, -1, &dummy, point, 0);
1121 #endif
1122 current_frame->glyphs[vpos][hpos] = MAKE_GLYPH (frame, g, face);
1123 current_frame->charstarts[vpos][hpos] = point - 1;
1124 /* Record the entry for after the newly inserted character. */
1125 current_frame->charstarts[vpos][hpos + 1] = point;
1126 adjust_window_charstarts (w, vpos, 1);
1128 unchanged_modified = MODIFF;
1129 beg_unchanged = GPT - BEG;
1130 XSETFASTINT (w->last_point, point);
1131 XSETFASTINT (w->last_point_x, hpos);
1132 XSETFASTINT (w->last_modified, MODIFF);
1134 reassert_line_highlight (0, vpos);
1135 write_glyphs (&current_frame->glyphs[vpos][hpos], 1);
1136 fflush (stdout);
1137 ++FRAME_CURSOR_X (frame);
1138 if (hpos == current_frame->used[vpos])
1140 current_frame->used[vpos] = hpos + 1;
1141 current_frame->glyphs[vpos][hpos + 1] = 0;
1144 return 1;
1148 direct_output_forward_char (n)
1149 int n;
1151 register FRAME_PTR frame = selected_frame;
1152 register struct window *w = XWINDOW (selected_window);
1153 Lisp_Object position;
1154 int hpos = FRAME_CURSOR_X (frame);
1156 /* Give up if in truncated text at end of line. */
1157 if (hpos >= XFASTINT (w->left) + window_internal_width (w) - 1)
1158 return 0;
1160 /* Avoid losing if cursor is in invisible text off left margin
1161 or about to go off either side of window. */
1162 if ((FRAME_CURSOR_X (frame) == XFASTINT (w->left)
1163 && (XINT (w->hscroll) || n < 0))
1164 || (n > 0
1165 && (FRAME_CURSOR_X (frame) + 1 >= window_internal_width (w) - 1))
1166 || cursor_in_echo_area)
1167 return 0;
1169 /* Can't use direct output if highlighting a region. */
1170 if (!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1171 return 0;
1173 /* Can't use direct output at an overlay boundary; it might have
1174 before-string or after-string properties. */
1175 if (overlay_touches_p (PT) || overlay_touches_p (PT - n))
1176 return 0;
1178 #ifdef USE_TEXT_PROPERTIES
1179 /* Don't use direct output next to an invisible character
1180 since we might need to do something special. */
1182 XSETFASTINT (position, point);
1183 if (XFASTINT (position) < ZV
1184 && ! NILP (Fget_char_property (position,
1185 Qinvisible,
1186 selected_window)))
1187 return 0;
1189 XSETFASTINT (position, point - 1);
1190 if (XFASTINT (position) >= BEGV
1191 && ! NILP (Fget_char_property (position,
1192 Qinvisible,
1193 selected_window)))
1194 return 0;
1195 #endif
1197 FRAME_CURSOR_X (frame) += n;
1198 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (frame));
1199 XSETFASTINT (w->last_point, point);
1200 cursor_to (FRAME_CURSOR_Y (frame), FRAME_CURSOR_X (frame));
1201 fflush (stdout);
1203 return 1;
1206 static void update_line ();
1208 /* Update frame F based on the data in FRAME_DESIRED_GLYPHS.
1209 Value is nonzero if redisplay stopped due to pending input.
1210 FORCE nonzero means do not stop for pending input. */
1213 update_frame (f, force, inhibit_hairy_id)
1214 FRAME_PTR f;
1215 int force;
1216 int inhibit_hairy_id;
1218 register struct frame_glyphs *current_frame;
1219 register struct frame_glyphs *desired_frame = 0;
1220 register int i;
1221 int pause;
1222 int preempt_count = baud_rate / 2400 + 1;
1223 extern input_pending;
1224 #ifdef HAVE_WINDOW_SYSTEM
1225 register int downto, leftmost;
1226 #endif
1228 if (baud_rate != FRAME_COST_BAUD_RATE (f))
1229 calculate_costs (f);
1231 if (preempt_count <= 0)
1232 preempt_count = 1;
1234 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1236 detect_input_pending ();
1237 if (input_pending && !force)
1239 pause = 1;
1240 goto do_pause;
1243 update_begin (f);
1245 if (!line_ins_del_ok)
1246 inhibit_hairy_id = 1;
1248 /* These are separate to avoid a possible bug in the AIX C compiler. */
1249 current_frame = FRAME_CURRENT_GLYPHS (f);
1250 desired_frame = FRAME_DESIRED_GLYPHS (f);
1252 /* See if any of the desired lines are enabled; don't compute for
1253 i/d line if just want cursor motion. */
1254 for (i = 0; i < FRAME_HEIGHT (f); i++)
1255 if (desired_frame->enable[i])
1256 break;
1258 /* Try doing i/d line, if not yet inhibited. */
1259 if (!inhibit_hairy_id && i < FRAME_HEIGHT (f))
1260 force |= scrolling (f);
1262 /* Update the individual lines as needed. Do bottom line first. */
1264 if (desired_frame->enable[FRAME_HEIGHT (f) - 1])
1265 update_line (f, FRAME_HEIGHT (f) - 1);
1267 #ifdef HAVE_WINDOW_SYSTEM
1268 if (FRAME_WINDOW_P (f))
1270 leftmost = downto = FRAME_INTERNAL_BORDER_WIDTH (f);
1271 if (desired_frame->enable[0])
1273 current_frame->top_left_x[FRAME_HEIGHT (f) - 1] = leftmost;
1274 current_frame->top_left_y[FRAME_HEIGHT (f) - 1]
1275 = PIXEL_HEIGHT (f) - FRAME_INTERNAL_BORDER_WIDTH (f)
1276 - current_frame->pix_height[FRAME_HEIGHT (f) - 1];
1277 current_frame->top_left_x[0] = leftmost;
1278 current_frame->top_left_y[0] = downto;
1281 #endif /* HAVE_WINDOW_SYSTEM */
1283 /* Now update the rest of the lines. */
1284 for (i = 0; i < FRAME_HEIGHT (f) - 1 && (force || !input_pending); i++)
1286 if (desired_frame->enable[i])
1288 if (FRAME_TERMCAP_P (f))
1290 /* Flush out every so many lines.
1291 Also flush out if likely to have more than 1k buffered
1292 otherwise. I'm told that some telnet connections get
1293 really screwed by more than 1k output at once. */
1294 int outq = PENDING_OUTPUT_COUNT (stdout);
1295 if (outq > 900
1296 || (outq > 20 && ((i - 1) % preempt_count == 0)))
1298 fflush (stdout);
1299 if (preempt_count == 1)
1301 #ifdef EMACS_OUTQSIZE
1302 if (EMACS_OUTQSIZE (0, &outq) < 0)
1303 /* Probably not a tty. Ignore the error and reset
1304 * the outq count. */
1305 outq = PENDING_OUTPUT_COUNT (stdout);
1306 #endif
1307 outq *= 10;
1308 if (baud_rate <= outq && baud_rate > 0)
1309 sleep (outq / baud_rate);
1312 if ((i - 1) % preempt_count == 0)
1313 detect_input_pending ();
1316 update_line (f, i);
1317 #ifdef HAVE_WINDOW_SYSTEM
1318 if (FRAME_WINDOW_P (f))
1320 current_frame->top_left_y[i] = downto;
1321 current_frame->top_left_x[i] = leftmost;
1323 #endif /* HAVE_WINDOW_SYSTEM */
1326 #ifdef HAVE_WINDOW_SYSTEM
1327 if (FRAME_WINDOW_P (f))
1328 downto += current_frame->pix_height[i];
1329 #endif /* HAVE_WINDOW_SYSTEM */
1331 pause = (i < FRAME_HEIGHT (f) - 1) ? i : 0;
1333 /* Now just clean up termcap drivers and set cursor, etc. */
1334 if (!pause)
1336 if ((cursor_in_echo_area
1337 /* If we are showing a message instead of the minibuffer,
1338 show the cursor for the message instead of for the
1339 (now hidden) minibuffer contents. */
1340 || (EQ (minibuf_window, selected_window)
1341 && EQ (minibuf_window, echo_area_window)
1342 && echo_area_glyphs != 0))
1343 /* These cases apply only to the frame that contains
1344 the active minibuffer window. */
1345 && FRAME_HAS_MINIBUF_P (f)
1346 && EQ (FRAME_MINIBUF_WINDOW (f), echo_area_window))
1348 int top = XINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top);
1349 int row, col;
1351 if (cursor_in_echo_area < 0)
1353 row = top;
1354 col = 0;
1356 else
1358 /* If the minibuffer is several lines high, find the last
1359 line that has any text on it. */
1360 row = FRAME_HEIGHT (f);
1363 row--;
1364 if (current_frame->enable[row])
1365 col = current_frame->used[row];
1366 else
1367 col = 0;
1369 while (row > top && col == 0);
1371 if (col >= FRAME_WIDTH (f))
1373 col = 0;
1374 if (row < FRAME_HEIGHT (f) - 1)
1375 row++;
1379 cursor_to (row, col);
1381 else
1382 cursor_to (FRAME_CURSOR_Y (f), max (min (FRAME_CURSOR_X (f),
1383 FRAME_WIDTH (f) - 1), 0));
1386 update_end (f);
1388 if (termscript)
1389 fflush (termscript);
1390 fflush (stdout);
1392 /* Here if output is preempted because input is detected. */
1393 do_pause:
1395 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1396 display_completed = !pause;
1398 bzero (FRAME_DESIRED_GLYPHS (f)->enable, FRAME_HEIGHT (f));
1399 return pause;
1402 /* Called when about to quit, to check for doing so
1403 at an improper time. */
1405 void
1406 quit_error_check ()
1408 #if 0
1409 if (FRAME_DESIRED_GLYPHS (selected_frame) == 0)
1410 return;
1411 if (FRAME_DESIRED_GLYPHS (selected_frame)->enable[0])
1412 abort ();
1413 if (FRAME_DESIRED_GLYPHS (selected_frame)->enable[FRAME_HEIGHT (selected_frame) - 1])
1414 abort ();
1415 #endif
1418 /* Decide what insert/delete line to do, and do it */
1420 extern void scrolling_1 ();
1422 scrolling (frame)
1423 FRAME_PTR frame;
1425 int unchanged_at_top, unchanged_at_bottom;
1426 int window_size;
1427 int changed_lines;
1428 int *old_hash = (int *) alloca (FRAME_HEIGHT (frame) * sizeof (int));
1429 int *new_hash = (int *) alloca (FRAME_HEIGHT (frame) * sizeof (int));
1430 int *draw_cost = (int *) alloca (FRAME_HEIGHT (frame) * sizeof (int));
1431 int *old_draw_cost = (int *) alloca (FRAME_HEIGHT (frame) * sizeof (int));
1432 register int i;
1433 int free_at_end_vpos = FRAME_HEIGHT (frame);
1434 register struct frame_glyphs *current_frame = FRAME_CURRENT_GLYPHS (frame);
1435 register struct frame_glyphs *desired_frame = FRAME_DESIRED_GLYPHS (frame);
1437 /* Compute hash codes of all the lines.
1438 Also calculate number of changed lines,
1439 number of unchanged lines at the beginning,
1440 and number of unchanged lines at the end. */
1442 changed_lines = 0;
1443 unchanged_at_top = 0;
1444 unchanged_at_bottom = FRAME_HEIGHT (frame);
1445 for (i = 0; i < FRAME_HEIGHT (frame); i++)
1447 /* Give up on this scrolling if some old lines are not enabled. */
1448 if (!current_frame->enable[i])
1449 return 0;
1450 old_hash[i] = line_hash_code (current_frame, i);
1451 if (! desired_frame->enable[i])
1452 new_hash[i] = old_hash[i];
1453 else
1454 new_hash[i] = line_hash_code (desired_frame, i);
1456 if (old_hash[i] != new_hash[i])
1458 changed_lines++;
1459 unchanged_at_bottom = FRAME_HEIGHT (frame) - i - 1;
1461 else if (i == unchanged_at_top)
1462 unchanged_at_top++;
1463 draw_cost[i] = line_draw_cost (desired_frame, i);
1464 old_draw_cost[i] = line_draw_cost (current_frame, i);
1467 /* If changed lines are few, don't allow preemption, don't scroll. */
1468 if (!scroll_region_ok && changed_lines < baud_rate / 2400
1469 || unchanged_at_bottom == FRAME_HEIGHT (frame))
1470 return 1;
1472 window_size = (FRAME_HEIGHT (frame) - unchanged_at_top
1473 - unchanged_at_bottom);
1475 if (scroll_region_ok)
1476 free_at_end_vpos -= unchanged_at_bottom;
1477 else if (memory_below_frame)
1478 free_at_end_vpos = -1;
1480 /* If large window, fast terminal and few lines in common between
1481 current frame and desired frame, don't bother with i/d calc. */
1482 if (!scroll_region_ok && window_size >= 18 && baud_rate > 2400
1483 && (window_size >=
1484 10 * scrolling_max_lines_saved (unchanged_at_top,
1485 FRAME_HEIGHT (frame) - unchanged_at_bottom,
1486 old_hash, new_hash, draw_cost)))
1487 return 0;
1489 scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
1490 draw_cost + unchanged_at_top - 1,
1491 old_draw_cost + unchanged_at_top - 1,
1492 old_hash + unchanged_at_top - 1,
1493 new_hash + unchanged_at_top - 1,
1494 free_at_end_vpos - unchanged_at_top);
1496 return 0;
1499 /* Return the offset in its buffer of the character at location col, line
1500 in the given window. */
1502 buffer_posn_from_coords (window, col, line)
1503 struct window *window;
1504 int col, line;
1506 int hscroll = XINT (window->hscroll);
1507 int window_left = XFASTINT (window->left);
1509 /* The actual width of the window is window->width less one for the
1510 DISP_CONTINUE_GLYPH, and less one if it's not the rightmost
1511 window. */
1512 int window_width = window_internal_width (window) - 1;
1514 int startp = marker_position (window->start);
1516 /* Since compute_motion will only operate on the current buffer,
1517 we need to save the old one and restore it when we're done. */
1518 struct buffer *old_current_buffer = current_buffer;
1519 struct position *posn;
1521 current_buffer = XBUFFER (window->buffer);
1523 /* We can't get a correct result in this case,
1524 but at least prevent compute_motion from crashing. */
1525 if (startp < BEGV)
1526 startp = BEGV;
1528 /* It would be nice if we could use FRAME_CURRENT_GLYPHS (XFRAME
1529 (window->frame))->bufp to avoid scanning from the very top of
1530 the window, but it isn't maintained correctly, and I'm not even
1531 sure I will keep it. */
1532 posn = compute_motion (startp, 0,
1533 ((window == XWINDOW (minibuf_window) && startp == BEG
1534 ? minibuf_prompt_width : 0)
1535 + (hscroll ? 1 - hscroll : 0)),
1537 ZV, line, col,
1538 window_width, hscroll, 0, window);
1540 current_buffer = old_current_buffer;
1542 /* compute_motion considers frame points past the end of a line
1543 to be *after* the newline, i.e. at the start of the next line.
1544 This is reasonable, but not really what we want. So if the
1545 result is on a line below LINE, back it up one character. */
1546 if (posn->vpos > line)
1547 return posn->bufpos - 1;
1548 else
1549 return posn->bufpos;
1552 static int
1553 count_blanks (r)
1554 register GLYPH *r;
1556 register GLYPH *p = r;
1557 while (*p++ == SPACEGLYPH);
1558 return p - r - 1;
1561 static int
1562 count_match (str1, str2)
1563 GLYPH *str1, *str2;
1565 register GLYPH *p1 = str1;
1566 register GLYPH *p2 = str2;
1567 while (*p1++ == *p2++);
1568 return p1 - str1 - 1;
1571 /* Char insertion/deletion cost vector, from term.c */
1572 extern int *char_ins_del_vector;
1574 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_WIDTH((f))])
1576 static void
1577 update_line (frame, vpos)
1578 register FRAME_PTR frame;
1579 int vpos;
1581 register GLYPH *obody, *nbody, *op1, *op2, *np1, *temp;
1582 int *temp1;
1583 int tem;
1584 int osp, nsp, begmatch, endmatch, olen, nlen;
1585 int save;
1586 register struct frame_glyphs *current_frame
1587 = FRAME_CURRENT_GLYPHS (frame);
1588 register struct frame_glyphs *desired_frame
1589 = FRAME_DESIRED_GLYPHS (frame);
1591 if (desired_frame->highlight[vpos]
1592 != (current_frame->enable[vpos] && current_frame->highlight[vpos]))
1594 change_line_highlight (desired_frame->highlight[vpos], vpos,
1595 (current_frame->enable[vpos] ?
1596 current_frame->used[vpos] : 0));
1597 current_frame->enable[vpos] = 0;
1599 else
1600 reassert_line_highlight (desired_frame->highlight[vpos], vpos);
1602 if (! current_frame->enable[vpos])
1604 olen = 0;
1606 else
1608 obody = current_frame->glyphs[vpos];
1609 olen = current_frame->used[vpos];
1610 if (! current_frame->highlight[vpos])
1612 if (!must_write_spaces)
1613 while (olen > 0 && obody[olen - 1] == SPACEGLYPH)
1614 olen--;
1616 else
1618 /* For an inverse-video line, remember we gave it
1619 spaces all the way to the frame edge
1620 so that the reverse video extends all the way across. */
1622 while (olen < FRAME_WIDTH (frame) - 1)
1623 obody[olen++] = SPACEGLYPH;
1627 /* One way or another, this will enable the line being updated. */
1628 current_frame->enable[vpos] = 1;
1629 current_frame->used[vpos] = desired_frame->used[vpos];
1630 current_frame->highlight[vpos] = desired_frame->highlight[vpos];
1631 current_frame->bufp[vpos] = desired_frame->bufp[vpos];
1633 #ifdef HAVE_WINDOW_SYSTEM
1634 if (FRAME_WINDOW_P (frame))
1636 current_frame->pix_width[vpos]
1637 = current_frame->used[vpos]
1638 * FONT_WIDTH (FRAME_FONT (frame));
1639 current_frame->pix_height[vpos]
1640 = FRAME_LINE_HEIGHT (frame);
1642 #endif /* HAVE_WINDOW_SYSTEM */
1644 if (!desired_frame->enable[vpos])
1646 nlen = 0;
1647 goto just_erase;
1650 nbody = desired_frame->glyphs[vpos];
1651 nlen = desired_frame->used[vpos];
1653 /* Pretend trailing spaces are not there at all,
1654 unless for one reason or another we must write all spaces. */
1655 if (! desired_frame->highlight[vpos])
1657 if (!must_write_spaces)
1658 /* We know that the previous character byte contains 0. */
1659 while (nbody[nlen - 1] == SPACEGLYPH)
1660 nlen--;
1662 else
1664 /* For an inverse-video line, give it extra trailing spaces
1665 all the way to the frame edge
1666 so that the reverse video extends all the way across. */
1668 while (nlen < FRAME_WIDTH (frame) - 1)
1669 nbody[nlen++] = SPACEGLYPH;
1672 /* If there's no i/d char, quickly do the best we can without it. */
1673 if (!char_ins_del_ok)
1675 int i,j;
1677 #if 0
1678 if (FRAME_X_P (frame))
1680 /* Under X, erase everything we are going to rewrite,
1681 and rewrite everything from the first char that's changed.
1682 This is part of supporting fonts like Courier
1683 whose chars can overlap outside the char width. */
1684 for (i = 0; i < nlen; i++)
1685 if (i >= olen || nbody[i] != obody[i])
1686 break;
1688 cursor_to (vpos, i);
1689 if (i != olen)
1690 clear_end_of_line (olen);
1691 write_glyphs (nbody + i, nlen - i);
1693 else
1695 #endif /* 0 */
1696 for (i = 0; i < nlen; i++)
1698 if (i >= olen || nbody[i] != obody[i]) /* A non-matching char. */
1700 cursor_to (vpos, i);
1701 for (j = 1; (i + j < nlen &&
1702 (i + j >= olen || nbody[i+j] != obody[i+j]));
1703 j++);
1705 /* Output this run of non-matching chars. */
1706 write_glyphs (nbody + i, j);
1707 i += j - 1;
1709 /* Now find the next non-match. */
1713 /* Clear the rest of the line, or the non-clear part of it. */
1714 if (olen > nlen)
1716 cursor_to (vpos, nlen);
1717 clear_end_of_line (olen);
1720 /* Exchange contents between current_frame and new_frame. */
1721 temp = desired_frame->glyphs[vpos];
1722 desired_frame->glyphs[vpos] = current_frame->glyphs[vpos];
1723 current_frame->glyphs[vpos] = temp;
1725 /* Exchange charstarts between current_frame and new_frame. */
1726 temp1 = desired_frame->charstarts[vpos];
1727 desired_frame->charstarts[vpos] = current_frame->charstarts[vpos];
1728 current_frame->charstarts[vpos] = temp1;
1730 return;
1733 if (!olen)
1735 nsp = (must_write_spaces || desired_frame->highlight[vpos])
1736 ? 0 : count_blanks (nbody);
1737 if (nlen > nsp)
1739 cursor_to (vpos, nsp);
1740 write_glyphs (nbody + nsp, nlen - nsp);
1743 /* Exchange contents between current_frame and new_frame. */
1744 temp = desired_frame->glyphs[vpos];
1745 desired_frame->glyphs[vpos] = current_frame->glyphs[vpos];
1746 current_frame->glyphs[vpos] = temp;
1748 /* Exchange charstarts between current_frame and new_frame. */
1749 temp1 = desired_frame->charstarts[vpos];
1750 desired_frame->charstarts[vpos] = current_frame->charstarts[vpos];
1751 current_frame->charstarts[vpos] = temp1;
1753 return;
1756 obody[olen] = 1;
1757 save = nbody[nlen];
1758 nbody[nlen] = 0;
1760 /* Compute number of leading blanks in old and new contents. */
1761 osp = count_blanks (obody);
1762 if (!desired_frame->highlight[vpos])
1763 nsp = count_blanks (nbody);
1764 else
1765 nsp = 0;
1767 /* Compute number of matching chars starting with first nonblank. */
1768 begmatch = count_match (obody + osp, nbody + nsp);
1770 /* Spaces in new match implicit space past the end of old. */
1771 /* A bug causing this to be a no-op was fixed in 18.29. */
1772 if (!must_write_spaces && osp + begmatch == olen)
1774 np1 = nbody + nsp;
1775 while (np1[begmatch] == SPACEGLYPH)
1776 begmatch++;
1779 /* Avoid doing insert/delete char
1780 just cause number of leading spaces differs
1781 when the following text does not match. */
1782 if (begmatch == 0 && osp != nsp)
1783 osp = nsp = min (osp, nsp);
1785 /* Find matching characters at end of line */
1786 op1 = obody + olen;
1787 np1 = nbody + nlen;
1788 op2 = op1 + begmatch - min (olen - osp, nlen - nsp);
1789 while (op1 > op2 && op1[-1] == np1[-1])
1791 op1--;
1792 np1--;
1794 endmatch = obody + olen - op1;
1796 /* Put correct value back in nbody[nlen].
1797 This is important because direct_output_for_insert
1798 can write into the line at a later point.
1799 If this screws up the zero at the end of the line, re-establish it. */
1800 nbody[nlen] = save;
1801 obody[olen] = 0;
1803 /* tem gets the distance to insert or delete.
1804 endmatch is how many characters we save by doing so.
1805 Is it worth it? */
1807 tem = (nlen - nsp) - (olen - osp);
1808 if (endmatch && tem
1809 && (!char_ins_del_ok || endmatch <= char_ins_del_cost (frame)[tem]))
1810 endmatch = 0;
1812 /* nsp - osp is the distance to insert or delete.
1813 If that is nonzero, begmatch is known to be nonzero also.
1814 begmatch + endmatch is how much we save by doing the ins/del.
1815 Is it worth it? */
1817 if (nsp != osp
1818 && (!char_ins_del_ok
1819 || begmatch + endmatch <= char_ins_del_cost (frame)[nsp - osp]))
1821 begmatch = 0;
1822 endmatch = 0;
1823 osp = nsp = min (osp, nsp);
1826 /* Now go through the line, inserting, writing and
1827 deleting as appropriate. */
1829 if (osp > nsp)
1831 cursor_to (vpos, nsp);
1832 delete_glyphs (osp - nsp);
1834 else if (nsp > osp)
1836 /* If going to delete chars later in line
1837 and insert earlier in the line,
1838 must delete first to avoid losing data in the insert */
1839 if (endmatch && nlen < olen + nsp - osp)
1841 cursor_to (vpos, nlen - endmatch + osp - nsp);
1842 delete_glyphs (olen + nsp - osp - nlen);
1843 olen = nlen - (nsp - osp);
1845 cursor_to (vpos, osp);
1846 insert_glyphs ((char *)0, nsp - osp);
1848 olen += nsp - osp;
1850 tem = nsp + begmatch + endmatch;
1851 if (nlen != tem || olen != tem)
1853 cursor_to (vpos, nsp + begmatch);
1854 if (!endmatch || nlen == olen)
1856 /* If new text being written reaches right margin,
1857 there is no need to do clear-to-eol at the end.
1858 (and it would not be safe, since cursor is not
1859 going to be "at the margin" after the text is done) */
1860 if (nlen == FRAME_WIDTH (frame))
1861 olen = 0;
1862 write_glyphs (nbody + nsp + begmatch, nlen - tem);
1864 #ifdef obsolete
1866 /* the following code loses disastrously if tem == nlen.
1867 Rather than trying to fix that case, I am trying the simpler
1868 solution found above. */
1870 /* If the text reaches to the right margin,
1871 it will lose one way or another (depending on AutoWrap)
1872 to clear to end of line after outputting all the text.
1873 So pause with one character to go and clear the line then. */
1874 if (nlen == FRAME_WIDTH (frame) && fast_clear_end_of_line && olen > nlen)
1876 /* endmatch must be zero, and tem must equal nsp + begmatch */
1877 write_glyphs (nbody + tem, nlen - tem - 1);
1878 clear_end_of_line (olen);
1879 olen = 0; /* Don't let it be cleared again later */
1880 write_glyphs (nbody + nlen - 1, 1);
1882 else
1883 write_glyphs (nbody + nsp + begmatch, nlen - tem);
1884 #endif /* OBSOLETE */
1887 else if (nlen > olen)
1889 write_glyphs (nbody + nsp + begmatch, olen - tem);
1890 insert_glyphs (nbody + nsp + begmatch + olen - tem, nlen - olen);
1891 olen = nlen;
1893 else if (olen > nlen)
1895 write_glyphs (nbody + nsp + begmatch, nlen - tem);
1896 delete_glyphs (olen - nlen);
1897 olen = nlen;
1901 just_erase:
1902 /* If any unerased characters remain after the new line, erase them. */
1903 if (olen > nlen)
1905 cursor_to (vpos, nlen);
1906 clear_end_of_line (olen);
1909 /* Exchange contents between current_frame and new_frame. */
1910 temp = desired_frame->glyphs[vpos];
1911 desired_frame->glyphs[vpos] = current_frame->glyphs[vpos];
1912 current_frame->glyphs[vpos] = temp;
1914 /* Exchange charstarts between current_frame and new_frame. */
1915 temp1 = desired_frame->charstarts[vpos];
1916 desired_frame->charstarts[vpos] = current_frame->charstarts[vpos];
1917 current_frame->charstarts[vpos] = temp1;
1920 /* A vector of size >= 2 * NFRAMES + 3 * NBUFFERS + 1, containing the
1921 session's frames, frame names, buffers, buffer-read-only flags, and
1922 buffer-modified-flags, and a trailing sentinel (so we don't need to
1923 add length checks). */
1924 static Lisp_Object frame_and_buffer_state;
1926 DEFUN ("frame-or-buffer-changed-p", Fframe_or_buffer_changed_p,
1927 Sframe_or_buffer_changed_p, 0, 0, 0,
1928 "Return non-nil if the frame and buffer state appears to have changed.\n\
1929 The state variable is an internal vector containing all frames and buffers,\n\
1930 aside from buffers whose names start with space,\n\
1931 along with the buffers' read-only and modified flags, which allows a fast\n\
1932 check to see whether the menu bars might need to be recomputed.\n\
1933 If this function returns non-nil, it updates the internal vector to reflect\n\
1934 the current state.\n")
1937 Lisp_Object tail, frame, buf;
1938 Lisp_Object *vecp;
1939 int n;
1941 vecp = XVECTOR (frame_and_buffer_state)->contents;
1942 FOR_EACH_FRAME (tail, frame)
1944 if (!EQ (*vecp++, frame))
1945 goto changed;
1946 if (!EQ (*vecp++, XFRAME (frame)->name))
1947 goto changed;
1949 /* Check that the buffer info matches.
1950 No need to test for the end of the vector
1951 because the last element of the vector is lambda
1952 and that will always cause a mismatch. */
1953 for (tail = Vbuffer_alist; CONSP (tail); tail = XCONS (tail)->cdr)
1955 buf = XCONS (XCONS (tail)->car)->cdr;
1956 /* Ignore buffers that aren't included in buffer lists. */
1957 if (XSTRING (XBUFFER (buf)->name)->data[0] == ' ')
1958 continue;
1959 if (!EQ (*vecp++, buf))
1960 goto changed;
1961 if (!EQ (*vecp++, XBUFFER (buf)->read_only))
1962 goto changed;
1963 if (!EQ (*vecp++, Fbuffer_modified_p (buf)))
1964 goto changed;
1966 /* Detect deletion of a buffer at the end of the list. */
1967 if (*vecp == Qlambda)
1968 return Qnil;
1969 changed:
1970 /* Start with 1 so there is room for at least one lambda at the end. */
1971 n = 1;
1972 FOR_EACH_FRAME (tail, frame)
1973 n += 2;
1974 for (tail = Vbuffer_alist; CONSP (tail); tail = XCONS (tail)->cdr)
1975 n += 3;
1976 /* Reallocate the vector if it's grown, or if it's shrunk a lot. */
1977 if (n > XVECTOR (frame_and_buffer_state)->size
1978 || n + 20 < XVECTOR (frame_and_buffer_state)->size / 2)
1979 /* Add 20 extra so we grow it less often. */
1980 frame_and_buffer_state = Fmake_vector (make_number (n + 20), Qlambda);
1981 vecp = XVECTOR (frame_and_buffer_state)->contents;
1982 FOR_EACH_FRAME (tail, frame)
1984 *vecp++ = frame;
1985 *vecp++ = XFRAME (frame)->name;
1987 for (tail = Vbuffer_alist; CONSP (tail); tail = XCONS (tail)->cdr)
1989 buf = XCONS (XCONS (tail)->car)->cdr;
1990 /* Ignore buffers that aren't included in buffer lists. */
1991 if (XSTRING (XBUFFER (buf)->name)->data[0] == ' ')
1992 continue;
1993 *vecp++ = buf;
1994 *vecp++ = XBUFFER (buf)->read_only;
1995 *vecp++ = Fbuffer_modified_p (buf);
1997 /* Fill up the vector with lambdas (always at least one). */
1998 *vecp++ = Qlambda;
1999 while (vecp - XVECTOR (frame_and_buffer_state)->contents
2000 < XVECTOR (frame_and_buffer_state)->size)
2001 *vecp++ = Qlambda;
2002 /* Make sure we didn't overflow the vector. */
2003 if (vecp - XVECTOR (frame_and_buffer_state)->contents
2004 > XVECTOR (frame_and_buffer_state)->size)
2005 abort ();
2006 return Qt;
2009 DEFUN ("open-termscript", Fopen_termscript, Sopen_termscript,
2010 1, 1, "FOpen termscript file: ",
2011 "Start writing all terminal output to FILE as well as the terminal.\n\
2012 FILE = nil means just close any termscript file currently open.")
2013 (file)
2014 Lisp_Object file;
2016 if (termscript != 0) fclose (termscript);
2017 termscript = 0;
2019 if (! NILP (file))
2021 file = Fexpand_file_name (file, Qnil);
2022 termscript = fopen (XSTRING (file)->data, "w");
2023 if (termscript == 0)
2024 report_file_error ("Opening termscript", Fcons (file, Qnil));
2026 return Qnil;
2030 #ifdef SIGWINCH
2031 SIGTYPE
2032 window_change_signal (signalnum) /* If we don't have an argument, */
2033 int signalnum; /* some compilers complain in signal calls. */
2035 int width, height;
2036 extern int errno;
2037 int old_errno = errno;
2039 get_frame_size (&width, &height);
2041 /* The frame size change obviously applies to a termcap-controlled
2042 frame. Find such a frame in the list, and assume it's the only
2043 one (since the redisplay code always writes to stdout, not a
2044 FILE * specified in the frame structure). Record the new size,
2045 but don't reallocate the data structures now. Let that be done
2046 later outside of the signal handler. */
2049 Lisp_Object tail, frame;
2051 FOR_EACH_FRAME (tail, frame)
2053 if (FRAME_TERMCAP_P (XFRAME (frame)))
2055 change_frame_size (XFRAME (frame), height, width, 0, 1);
2056 break;
2061 signal (SIGWINCH, window_change_signal);
2062 errno = old_errno;
2064 #endif /* SIGWINCH */
2067 /* Do any change in frame size that was requested by a signal. */
2069 do_pending_window_change ()
2071 /* If window_change_signal should have run before, run it now. */
2072 while (delayed_size_change)
2074 Lisp_Object tail, frame;
2076 delayed_size_change = 0;
2078 FOR_EACH_FRAME (tail, frame)
2080 FRAME_PTR f = XFRAME (frame);
2082 int height = FRAME_NEW_HEIGHT (f);
2083 int width = FRAME_NEW_WIDTH (f);
2085 if (height != 0 || width != 0)
2086 change_frame_size (f, height, width, 0, 0);
2092 /* Change the frame height and/or width. Values may be given as zero to
2093 indicate no change is to take place.
2095 If DELAY is non-zero, then assume we're being called from a signal
2096 handler, and queue the change for later - perhaps the next
2097 redisplay. Since this tries to resize windows, we can't call it
2098 from a signal handler. */
2100 change_frame_size (f, newheight, newwidth, pretend, delay)
2101 register FRAME_PTR f;
2102 int newheight, newwidth, pretend;
2104 Lisp_Object tail, frame;
2105 if (FRAME_TERMCAP_P (f))
2107 /* When using termcap, all frames use the same screen,
2108 so a change in size affects all termcap frames. */
2109 FOR_EACH_FRAME (tail, frame)
2110 if (FRAME_TERMCAP_P (XFRAME (frame)))
2111 change_frame_size_1 (XFRAME (frame), newheight, newwidth,
2112 pretend, delay);
2114 else
2115 change_frame_size_1 (f, newheight, newwidth, pretend, delay);
2118 static void
2119 change_frame_size_1 (frame, newheight, newwidth, pretend, delay)
2120 register FRAME_PTR frame;
2121 int newheight, newwidth, pretend, delay;
2123 /* If we can't deal with the change now, queue it for later. */
2124 if (delay)
2126 FRAME_NEW_HEIGHT (frame) = newheight;
2127 FRAME_NEW_WIDTH (frame) = newwidth;
2128 delayed_size_change = 1;
2129 return;
2132 /* This size-change overrides any pending one for this frame. */
2133 FRAME_NEW_HEIGHT (frame) = 0;
2134 FRAME_NEW_WIDTH (frame) = 0;
2136 /* If an argument is zero, set it to the current value. */
2137 newheight || (newheight = FRAME_HEIGHT (frame));
2138 newwidth || (newwidth = FRAME_WIDTH (frame));
2140 /* Round up to the smallest acceptable size. */
2141 check_frame_size (frame, &newheight, &newwidth);
2143 /* If we're not changing the frame size, quit now. */
2144 if (newheight == FRAME_HEIGHT (frame)
2145 && newwidth == FRAME_WIDTH (frame))
2146 return;
2148 #ifdef MSDOS
2149 /* We only can set screen dimensions to certain values supported
2150 by our video hardware. Try to find the smallest size greater
2151 or equal to the requested dimensions. */
2152 dos_set_window_size (&newheight, &newwidth);
2153 #endif
2155 if (newheight != FRAME_HEIGHT (frame))
2157 if (FRAME_HAS_MINIBUF_P (frame)
2158 && ! FRAME_MINIBUF_ONLY_P (frame))
2160 /* Frame has both root and minibuffer. */
2161 set_window_height (FRAME_ROOT_WINDOW (frame),
2162 newheight - 1 - FRAME_MENU_BAR_LINES (frame), 0);
2163 XSETFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (frame))->top,
2164 newheight - 1);
2165 set_window_height (FRAME_MINIBUF_WINDOW (frame), 1, 0);
2167 else
2168 /* Frame has just one top-level window. */
2169 set_window_height (FRAME_ROOT_WINDOW (frame),
2170 newheight - FRAME_MENU_BAR_LINES (frame), 0);
2172 if (FRAME_TERMCAP_P (frame) && !pretend)
2173 FrameRows = newheight;
2175 #if 0
2176 if (frame->output_method == output_termcap)
2178 frame_height = newheight;
2179 if (!pretend)
2180 FrameRows = newheight;
2182 #endif
2185 if (newwidth != FRAME_WIDTH (frame))
2187 set_window_width (FRAME_ROOT_WINDOW (frame), newwidth, 0);
2188 if (FRAME_HAS_MINIBUF_P (frame))
2189 set_window_width (FRAME_MINIBUF_WINDOW (frame), newwidth, 0);
2191 if (FRAME_TERMCAP_P (frame) && !pretend)
2192 FrameCols = newwidth;
2193 #if 0
2194 if (frame->output_method == output_termcap)
2196 frame_width = newwidth;
2197 if (!pretend)
2198 FrameCols = newwidth;
2200 #endif
2203 FRAME_HEIGHT (frame) = newheight;
2204 FRAME_WIDTH (frame) = newwidth;
2206 if (FRAME_CURSOR_X (frame) >= FRAME_WIDTH (frame))
2207 FRAME_CURSOR_X (frame) = FRAME_WIDTH (frame) - 1;
2208 if (FRAME_CURSOR_Y (frame) >= FRAME_HEIGHT (frame))
2209 FRAME_CURSOR_Y (frame) = FRAME_HEIGHT (frame) - 1;
2211 remake_frame_glyphs (frame);
2212 calculate_costs (frame);
2215 DEFUN ("send-string-to-terminal", Fsend_string_to_terminal,
2216 Ssend_string_to_terminal, 1, 1, 0,
2217 "Send STRING to the terminal without alteration.\n\
2218 Control characters in STRING will have terminal-dependent effects.")
2219 (string)
2220 Lisp_Object string;
2222 CHECK_STRING (string, 0);
2223 fwrite (XSTRING (string)->data, 1, XSTRING (string)->size, stdout);
2224 fflush (stdout);
2225 if (termscript)
2227 fwrite (XSTRING (string)->data, 1, XSTRING (string)->size, termscript);
2228 fflush (termscript);
2230 return Qnil;
2233 DEFUN ("ding", Fding, Sding, 0, 1, 0,
2234 "Beep, or flash the screen.\n\
2235 Also, unless an argument is given,\n\
2236 terminate any keyboard macro currently executing.")
2237 (arg)
2238 Lisp_Object arg;
2240 if (!NILP (arg))
2242 if (noninteractive)
2243 putchar (07);
2244 else
2245 ring_bell ();
2246 fflush (stdout);
2248 else
2249 bitch_at_user ();
2251 return Qnil;
2254 bitch_at_user ()
2256 if (noninteractive)
2257 putchar (07);
2258 else if (!INTERACTIVE) /* Stop executing a keyboard macro. */
2259 error ("Keyboard macro terminated by a command ringing the bell");
2260 else
2261 ring_bell ();
2262 fflush (stdout);
2265 DEFUN ("sleep-for", Fsleep_for, Ssleep_for, 1, 2, 0,
2266 "Pause, without updating display, for SECONDS seconds.\n\
2267 SECONDS may be a floating-point value, meaning that you can wait for a\n\
2268 fraction of a second. Optional second arg MILLISECONDS specifies an\n\
2269 additional wait period, in milliseconds; this may be useful if your\n\
2270 Emacs was built without floating point support.\n\
2271 \(Not all operating systems support waiting for a fraction of a second.)")
2272 (seconds, milliseconds)
2273 Lisp_Object seconds, milliseconds;
2275 int sec, usec;
2277 if (NILP (milliseconds))
2278 XSETINT (milliseconds, 0);
2279 else
2280 CHECK_NUMBER (milliseconds, 1);
2281 usec = XINT (milliseconds) * 1000;
2283 #ifdef LISP_FLOAT_TYPE
2285 double duration = extract_float (seconds);
2286 sec = (int) duration;
2287 usec += (duration - sec) * 1000000;
2289 #else
2290 CHECK_NUMBER (seconds, 0);
2291 sec = XINT (seconds);
2292 #endif
2294 #ifndef EMACS_HAS_USECS
2295 if (sec == 0 && usec != 0)
2296 error ("millisecond `sleep-for' not supported on %s", SYSTEM_TYPE);
2297 #endif
2299 /* Assure that 0 <= usec < 1000000. */
2300 if (usec < 0)
2302 /* We can't rely on the rounding being correct if user is negative. */
2303 if (-1000000 < usec)
2304 sec--, usec += 1000000;
2305 else
2306 sec -= -usec / 1000000, usec = 1000000 - (-usec % 1000000);
2308 else
2309 sec += usec / 1000000, usec %= 1000000;
2311 if (sec < 0 || (sec == 0 && usec == 0))
2312 return Qnil;
2315 Lisp_Object zero;
2317 XSETFASTINT (zero, 0);
2318 wait_reading_process_input (sec, usec, zero, 0);
2321 /* We should always have wait_reading_process_input; we have a dummy
2322 implementation for systems which don't support subprocesses. */
2323 #if 0
2324 /* No wait_reading_process_input */
2325 immediate_quit = 1;
2326 QUIT;
2328 #ifdef VMS
2329 sys_sleep (sec);
2330 #else /* not VMS */
2331 /* The reason this is done this way
2332 (rather than defined (H_S) && defined (H_T))
2333 is because the VMS preprocessor doesn't grok `defined' */
2334 #ifdef HAVE_SELECT
2335 EMACS_GET_TIME (end_time);
2336 EMACS_SET_SECS_USECS (timeout, sec, usec);
2337 EMACS_ADD_TIME (end_time, end_time, timeout);
2339 while (1)
2341 EMACS_GET_TIME (timeout);
2342 EMACS_SUB_TIME (timeout, end_time, timeout);
2343 if (EMACS_TIME_NEG_P (timeout)
2344 || !select (1, 0, 0, 0, &timeout))
2345 break;
2347 #else /* not HAVE_SELECT */
2348 sleep (sec);
2349 #endif /* HAVE_SELECT */
2350 #endif /* not VMS */
2352 immediate_quit = 0;
2353 #endif /* no subprocesses */
2355 return Qnil;
2358 /* This is just like wait_reading_process_input, except that
2359 it does the redisplay.
2361 It's also much like Fsit_for, except that it can be used for
2362 waiting for input as well. */
2364 Lisp_Object
2365 sit_for (sec, usec, reading, display)
2366 int sec, usec, reading, display;
2368 Lisp_Object read_kbd;
2370 if (detect_input_pending ())
2371 return Qnil;
2373 if (display)
2374 redisplay_preserve_echo_area ();
2376 if (sec == 0 && usec == 0)
2377 return Qt;
2379 #ifdef SIGIO
2380 gobble_input (0);
2381 #endif
2383 XSETINT (read_kbd, reading ? -1 : 1);
2384 wait_reading_process_input (sec, usec, read_kbd, display);
2387 /* wait_reading_process_input should always be available now; it is
2388 simulated in a simple way on systems that don't support
2389 subprocesses. */
2390 #if 0
2391 /* No wait_reading_process_input available. */
2392 immediate_quit = 1;
2393 QUIT;
2395 waitchannels = 1;
2396 #ifdef VMS
2397 input_wait_timeout (XINT (arg));
2398 #else /* not VMS */
2399 #ifndef HAVE_TIMEVAL
2400 timeout_sec = sec;
2401 select (1, &waitchannels, 0, 0, &timeout_sec);
2402 #else /* HAVE_TIMEVAL */
2403 timeout.tv_sec = sec;
2404 timeout.tv_usec = usec;
2405 select (1, &waitchannels, 0, 0, &timeout);
2406 #endif /* HAVE_TIMEVAL */
2407 #endif /* not VMS */
2409 immediate_quit = 0;
2410 #endif
2412 return detect_input_pending () ? Qnil : Qt;
2415 DEFUN ("sit-for", Fsit_for, Ssit_for, 1, 3, 0,
2416 "Perform redisplay, then wait for SECONDS seconds or until input is available.\n\
2417 SECONDS may be a floating-point value, meaning that you can wait for a\n\
2418 fraction of a second. Optional second arg MILLISECONDS specifies an\n\
2419 additional wait period, in milliseconds; this may be useful if your\n\
2420 Emacs was built without floating point support.\n\
2421 \(Not all operating systems support waiting for a fraction of a second.)\n\
2422 Optional third arg NODISP non-nil means don't redisplay, just wait for input.\n\
2423 Redisplay is preempted as always if input arrives, and does not happen\n\
2424 if input is available before it starts.\n\
2425 Value is t if waited the full time with no input arriving.")
2426 (seconds, milliseconds, nodisp)
2427 Lisp_Object seconds, milliseconds, nodisp;
2429 int sec, usec;
2431 if (NILP (milliseconds))
2432 XSETINT (milliseconds, 0);
2433 else
2434 CHECK_NUMBER (milliseconds, 1);
2435 usec = XINT (milliseconds) * 1000;
2437 #ifdef LISP_FLOAT_TYPE
2439 double duration = extract_float (seconds);
2440 sec = (int) duration;
2441 usec += (duration - sec) * 1000000;
2443 #else
2444 CHECK_NUMBER (seconds, 0);
2445 sec = XINT (seconds);
2446 #endif
2448 #ifndef EMACS_HAS_USECS
2449 if (usec != 0 && sec == 0)
2450 error ("millisecond `sit-for' not supported on %s", SYSTEM_TYPE);
2451 #endif
2453 return sit_for (sec, usec, 0, NILP (nodisp));
2456 char *terminal_type;
2458 /* Initialization done when Emacs fork is started, before doing stty. */
2459 /* Determine terminal type and set terminal_driver */
2460 /* Then invoke its decoding routine to set up variables
2461 in the terminal package */
2463 init_display ()
2465 #ifdef HAVE_X_WINDOWS
2466 extern int display_arg;
2467 #endif
2469 meta_key = 0;
2470 inverse_video = 0;
2471 cursor_in_echo_area = 0;
2472 terminal_type = (char *) 0;
2474 /* Now is the time to initialize this; it's used by init_sys_modes
2475 during startup. */
2476 Vwindow_system = Qnil;
2478 /* If the user wants to use a window system, we shouldn't bother
2479 initializing the terminal. This is especially important when the
2480 terminal is so dumb that emacs gives up before and doesn't bother
2481 using the window system.
2483 If the DISPLAY environment variable is set and nonempty,
2484 try to use X, and die with an error message if that doesn't work. */
2486 #ifdef HAVE_X_WINDOWS
2487 if (! display_arg)
2489 char *display;
2490 #ifdef VMS
2491 display = getenv ("DECW$DISPLAY");
2492 #else
2493 display = getenv ("DISPLAY");
2494 #endif
2496 display_arg = (display != 0 && *display != 0);
2499 if (!inhibit_window_system && display_arg)
2501 Vwindow_system = intern ("x");
2502 #ifdef HAVE_X11
2503 Vwindow_system_version = make_number (11);
2504 #else
2505 Vwindow_system_version = make_number (10);
2506 #endif
2507 return;
2509 #endif /* HAVE_X_WINDOWS */
2511 #ifdef HAVE_NTGUI
2512 if (!inhibit_window_system)
2514 Vwindow_system = intern ("win32");
2515 Vwindow_system_version = make_number (1);
2516 return;
2518 #endif /* HAVE_NTGUI */
2520 /* If no window system has been specified, try to use the terminal. */
2521 if (! isatty (0))
2523 fprintf (stderr, "emacs: standard input is not a tty\n");
2524 exit (1);
2527 /* Look at the TERM variable */
2528 terminal_type = (char *) getenv ("TERM");
2529 if (!terminal_type)
2531 #ifdef VMS
2532 fprintf (stderr, "Please specify your terminal type.\n\
2533 For types defined in VMS, use set term /device=TYPE.\n\
2534 For types not defined in VMS, use define emacs_term \"TYPE\".\n\
2535 \(The quotation marks are necessary since terminal types are lower case.)\n");
2536 #else
2537 fprintf (stderr, "Please set the environment variable TERM; see tset(1).\n");
2538 #endif
2539 exit (1);
2542 #ifdef VMS
2543 /* VMS DCL tends to upcase things, so downcase term type.
2544 Hardly any uppercase letters in terminal types; should be none. */
2546 char *new = (char *) xmalloc (strlen (terminal_type) + 1);
2547 char *p;
2549 strcpy (new, terminal_type);
2551 for (p = new; *p; p++)
2552 if (isupper (*p))
2553 *p = tolower (*p);
2555 terminal_type = new;
2557 #endif
2559 term_init (terminal_type);
2561 remake_frame_glyphs (selected_frame);
2562 calculate_costs (selected_frame);
2564 /* X and Y coordinates of the cursor between updates. */
2565 FRAME_CURSOR_X (selected_frame) = 0;
2566 FRAME_CURSOR_Y (selected_frame) = 0;
2568 #ifdef SIGWINCH
2569 #ifndef CANNOT_DUMP
2570 if (initialized)
2571 #endif /* CANNOT_DUMP */
2572 signal (SIGWINCH, window_change_signal);
2573 #endif /* SIGWINCH */
2576 syms_of_display ()
2578 #ifdef MULTI_FRAME
2579 defsubr (&Sredraw_frame);
2580 #endif
2581 defsubr (&Sredraw_display);
2582 defsubr (&Sframe_or_buffer_changed_p);
2583 defsubr (&Sopen_termscript);
2584 defsubr (&Sding);
2585 defsubr (&Ssit_for);
2586 defsubr (&Ssleep_for);
2587 defsubr (&Ssend_string_to_terminal);
2589 frame_and_buffer_state = Fmake_vector (make_number (20), Qlambda);
2590 staticpro (&frame_and_buffer_state);
2592 Qdisplay_table = intern ("display-table");
2593 staticpro (&Qdisplay_table);
2595 DEFVAR_INT ("baud-rate", &baud_rate,
2596 "*The output baud rate of the terminal.\n\
2597 On most systems, changing this value will affect the amount of padding\n\
2598 and the other strategic decisions made during redisplay.");
2599 DEFVAR_BOOL ("inverse-video", &inverse_video,
2600 "*Non-nil means invert the entire frame display.\n\
2601 This means everything is in inverse video which otherwise would not be.");
2602 DEFVAR_BOOL ("visible-bell", &visible_bell,
2603 "*Non-nil means try to flash the frame to represent a bell.");
2604 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter,
2605 "*Non-nil means no need to redraw entire frame after suspending.\n\
2606 A non-nil value is useful if the terminal can automatically preserve\n\
2607 Emacs's frame display when you reenter Emacs.\n\
2608 It is up to you to set this variable if your terminal can do that.");
2609 DEFVAR_LISP ("window-system", &Vwindow_system,
2610 "A symbol naming the window-system under which Emacs is running\n\
2611 \(such as `x'), or nil if emacs is running on an ordinary terminal.");
2612 DEFVAR_LISP ("window-system-version", &Vwindow_system_version,
2613 "The version number of the window system in use.\n\
2614 For X windows, this is 10 or 11.");
2615 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area,
2616 "Non-nil means put cursor in minibuffer, at end of any message there.");
2617 DEFVAR_LISP ("glyph-table", &Vglyph_table,
2618 "Table defining how to output a glyph code to the frame.\n\
2619 If not nil, this is a vector indexed by glyph code to define the glyph.\n\
2620 Each element can be:\n\
2621 integer: a glyph code which this glyph is an alias for.\n\
2622 string: output this glyph using that string (not impl. in X windows).\n\
2623 nil: this glyph mod 256 is char code to output,\n\
2624 and this glyph / 256 is face code for X windows (see `face-id').");
2625 Vglyph_table = Qnil;
2627 DEFVAR_LISP ("standard-display-table", &Vstandard_display_table,
2628 "Display table to use for buffers that specify none.\n\
2629 See `buffer-display-table' for more information.");
2630 Vstandard_display_table = Qnil;
2632 /* Initialize `window-system', unless init_display already decided it. */
2633 #ifdef CANNOT_DUMP
2634 if (noninteractive)
2635 #endif
2637 Vwindow_system = Qnil;
2638 Vwindow_system_version = Qnil;