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)
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. */
32 #include "termhooks.h"
33 /* cm.h must come after dispextern.h on Windows. */
34 #include "dispextern.h"
42 #include "intervals.h"
43 #include "blockinput.h"
46 #include "syssignal.h"
50 #endif /* HAVE_X_WINDOWS */
54 #endif /* HAVE_NTGUI */
56 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
61 #define max(a, b) ((a) > (b) ? (a) : (b))
62 #define min(a, b) ((a) < (b) ? (a) : (b))
64 /* Get number of chars of output now in the buffer of a stdio stream.
65 This ought to be built in in stdio, but it isn't.
66 Some s- files override this because their stdio internals differ. */
67 #ifdef __GNU_LIBRARY__
68 /* The s- file might have overridden the definition with one that works for
69 the system's C library. But we are using the GNU C library, so this is
70 the right definition for every system. */
71 #ifdef GNU_LIBRARY_PENDING_OUTPUT_COUNT
72 #define PENDING_OUTPUT_COUNT GNU_LIBRARY_PENDING_OUTPUT_COUNT
74 #undef PENDING_OUTPUT_COUNT
75 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
77 #else /* not __GNU_LIBRARY__ */
78 #ifndef PENDING_OUTPUT_COUNT
79 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
83 static void change_frame_size_1 ();
85 /* Nonzero upon entry to redisplay means do not assume anything about
86 current contents of actual terminal frame; clear and redraw it. */
90 /* Nonzero means last display completed. Zero means it was preempted. */
92 int display_completed
;
94 /* Lisp variable visible-bell; enables use of screen-flash
95 instead of audible bell. */
99 /* Invert the color of the whole frame, at a low level. */
103 /* Line speed of the terminal. */
107 /* nil or a symbol naming the window system under which emacs is
108 running ('x is the only current possibility). */
110 Lisp_Object Vwindow_system
;
112 /* Version number of X windows: 10, 11 or nil. */
113 Lisp_Object Vwindow_system_version
;
115 /* Vector of glyph definitions. Indexed by glyph number,
116 the contents are a string which is how to output the glyph.
118 If Vglyph_table is nil, a glyph is output by using its low 8 bits
119 as a character code. */
121 Lisp_Object Vglyph_table
;
123 /* Display table to use for vectors that don't specify their own. */
125 Lisp_Object Vstandard_display_table
;
127 /* Nonzero means reading single-character input with prompt
128 so put cursor on minibuffer after the prompt.
129 positive means at end of text in echo area;
130 negative means at beginning of line. */
131 int cursor_in_echo_area
;
133 Lisp_Object Qdisplay_table
;
135 /* The currently selected frame.
136 In a single-frame version, this variable always holds the address of
139 FRAME_PTR selected_frame
;
141 /* A frame which is not just a minibuffer, or 0 if there are no such
142 frames. This is usually the most recent such frame that was
143 selected. In a single-frame version, this variable always holds
144 the address of the_only_frame. */
145 FRAME_PTR last_nonminibuf_frame
;
147 /* In a single-frame version, the information that would otherwise
148 exist inside frame objects lives in the following structure instead.
150 NOTE: the_only_frame is not checked for garbage collection; don't
151 store collectible objects in any of its fields!
153 You're not/The only frame in town/... */
156 struct frame the_only_frame
;
159 /* This is a vector, made larger whenever it isn't large enough,
160 which is used inside `update_frame' to hold the old contents
161 of the FRAME_PHYS_LINES of the frame being updated. */
162 struct frame_glyphs
**ophys_lines
;
163 /* Length of vector currently allocated. */
164 int ophys_lines_length
;
166 FILE *termscript
; /* Stdio stream being used for copy of all output. */
168 struct cm Wcm
; /* Structure for info on cursor positioning */
170 int delayed_size_change
; /* 1 means SIGWINCH happened when not safe. */
174 DEFUN ("redraw-frame", Fredraw_frame
, Sredraw_frame
, 1, 1, 0,
175 "Clear frame FRAME and output again what is supposed to appear on it.")
181 CHECK_LIVE_FRAME (frame
, 0);
184 if (FRAME_MSDOS_P (f
))
185 set_terminal_modes ();
187 clear_frame_records (f
);
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);
202 XSETFRAME (frame
, f
);
203 Fredraw_frame (frame
);
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! */
216 set_terminal_modes ();
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);
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
);
243 /* This is used when frame_garbaged is set.
244 Redraw the individual frames marked as garbaged. */
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
;
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
;
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 */
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_charstarts
);
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;
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
;
337 free_frame_glyphs (frame
, glyphs
)
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 */
369 remake_frame_glyphs (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
);
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_WINDOW_P (frame
) || frame
== selected_frame
)
402 SET_FRAME_GARBAGED (frame
);
405 /* Return the hash code of contents of line VPOS in frame-matrix M. */
408 line_hash_code (m
, vpos
)
409 register struct frame_glyphs
*m
;
412 register GLYPH
*body
, *end
;
415 if (!m
->enable
[vpos
])
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
])
423 body
= m
->glyphs
[vpos
];
425 if (must_write_spaces
)
432 h
= (((h
<< 4) + (h
>> 24)) & 0x0fffffff) + g
- SPACEGLYPH
;
441 h
= (((h
<< 4) + (h
>> 24)) & 0x0fffffff) + g
;
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. */
454 line_draw_cost (m
, vpos
)
455 struct frame_glyphs
*m
;
458 register GLYPH
*beg
= m
->glyphs
[vpos
];
459 register GLYPH
*end
= m
->glyphs
[vpos
] + m
->used
[vpos
];
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
))
470 return (0); /* All blank line. */
472 while (*beg
== SPACEGLYPH
)
476 /* If we don't have a glyph-table, each glyph is one character,
477 so return the number of glyphs. */
481 /* Otherwise, scan the glyphs and accumulate their total size in I. */
483 while ((beg
<= end
) && *beg
)
485 register GLYPH g
= *beg
++;
487 if (GLYPH_SIMPLE_P (tbase
, tlen
, g
))
490 i
+= GLYPH_LENGTH (tbase
, g
);
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
)
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. */
519 init_desired_glyphs (frame
)
520 register FRAME_PTR frame
;
522 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (frame
);
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. */
533 get_display_line (frame
, vpos
, hpos
)
534 register FRAME_PTR frame
;
538 register struct frame_glyphs
*glyphs
;
539 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (frame
);
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
;
563 /* Like bcopy except never gets confused by overlap. */
566 safe_bcopy (from
, to
, size
)
570 if (size
<= 0 || from
== to
)
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. */
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. */
595 while (endf
!= from
);
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. */
622 rotate_vector (vector
, size
, distance
)
627 char *temp
= (char *) alloca (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
;
647 register struct frame_glyphs
*current_frame
648 = FRAME_CURRENT_GLYPHS (frame
);
650 int width
= FRAME_WIDTH (frame
);
652 if (!line_ins_del_ok
)
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
693 for (i
= from
+ amount
; i
< end
+ amount
; i
++)
695 int *line
= current_frame
->charstarts
[i
];
697 for (col
= 0; col
< width
; col
++)
699 line
[col
] += pos_adjust
;
701 for (i
= from
; i
< from
+ amount
; i
++)
703 int *line
= current_frame
->charstarts
[i
];
706 for (col
= 0; col
< width
; col
++)
710 /* Mark the lines made empty by scrolling as enabled, empty and
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 */
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
789 for (i
= from
+ amount
; i
< end
+ amount
; i
++)
791 int *line
= current_frame
->charstarts
[i
];
793 for (col
= 0; col
< width
; col
++)
795 line
[col
] += pos_adjust
;
797 for (i
= end
+ amount
; i
< end
; i
++)
799 int *line
= current_frame
->charstarts
[i
];
802 for (col
= 0; col
< width
; col
++)
806 /* Mark the lines made empty by scrolling as enabled, empty and
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 */
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
)
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
])
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
];
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
)
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
)
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
);
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). */
956 adjust_window_charstarts (w
, vpos
, 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
);
967 for (i
= vpos
+ 1; i
< bottom
; i
++)
970 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[i
];
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
)
985 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
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
);
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
++)
1001 int *charstart
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[i
];
1007 /* If we are truncating lines, allow a jump
1008 in charstarts from one line to the next. */
1009 if (charstart
[left
] < next_line
)
1014 if (charstart
[left
] != next_line
)
1019 for (j
= left
; j
< right
; j
++)
1020 if (charstart
[j
] > 0)
1021 last
= charstart
[j
];
1022 /* Record where the next line should start. */
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')
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
)
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
)
1065 register FRAME_PTR frame
= selected_frame
;
1066 register struct frame_glyphs
*current_frame
1067 = FRAME_CURRENT_GLYPHS (frame
);
1069 #ifndef COMPILER_REGISTER_BUG
1071 #endif /* COMPILER_REGISTER_BUG */
1072 struct window
*w
= XWINDOW (selected_window
);
1073 #ifndef COMPILER_REGISTER_BUG
1075 #endif /* COMPILER_REGISTER_BUG */
1076 int hpos
= FRAME_CURSOR_X (frame
);
1077 #ifndef COMPILER_REGISTER_BUG
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
))
1110 /* Give up if w is minibuffer and a message is being displayed there */
1111 || (MINI_WINDOW_P (w
) && echo_area_glyphs
))
1119 if (FRAME_WINDOW_P (frame
) || FRAME_MSDOS_P (frame
))
1120 face
= compute_char_face (frame
, w
, point
- 1, -1, -1, &dummy
, point
, 0);
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 (¤t_frame
->glyphs
[vpos
][hpos
], 1);
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;
1148 direct_output_forward_char (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)
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))
1165 && (FRAME_CURSOR_X (frame
) + 1 >= window_internal_width (w
) - 1))
1166 || cursor_in_echo_area
)
1169 /* Can't use direct output if highlighting a region. */
1170 if (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
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
))
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
,
1189 XSETFASTINT (position
, point
- 1);
1190 if (XFASTINT (position
) >= BEGV
1191 && ! NILP (Fget_char_property (position
,
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
));
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
)
1216 int inhibit_hairy_id
;
1218 register struct frame_glyphs
*current_frame
;
1219 register struct frame_glyphs
*desired_frame
= 0;
1222 int preempt_count
= baud_rate
/ 2400 + 1;
1223 extern input_pending
;
1224 #ifdef HAVE_WINDOW_SYSTEM
1225 register int downto
, leftmost
;
1228 if (baud_rate
!= FRAME_COST_BAUD_RATE (f
))
1229 calculate_costs (f
);
1231 if (preempt_count
<= 0)
1234 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1236 detect_input_pending ();
1237 if (input_pending
&& !force
)
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
])
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
);
1296 || (outq
> 20 && ((i
- 1) % preempt_count
== 0)))
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
);
1308 if (baud_rate
<= outq
&& baud_rate
> 0)
1309 sleep (outq
/ baud_rate
);
1312 if ((i
- 1) % preempt_count
== 0)
1313 detect_input_pending ();
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. */
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
);
1351 if (cursor_in_echo_area
< 0)
1358 /* If the minibuffer is several lines high, find the last
1359 line that has any text on it. */
1360 row
= FRAME_HEIGHT (f
);
1364 if (current_frame
->enable
[row
])
1365 col
= current_frame
->used
[row
];
1369 while (row
> top
&& col
== 0);
1371 if (col
>= FRAME_WIDTH (f
))
1374 if (row
< FRAME_HEIGHT (f
) - 1)
1379 cursor_to (row
, col
);
1382 cursor_to (FRAME_CURSOR_Y (f
), max (min (FRAME_CURSOR_X (f
),
1383 FRAME_WIDTH (f
) - 1), 0));
1389 fflush (termscript
);
1392 /* Here if output is preempted because input is detected. */
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
));
1402 /* Called when about to quit, to check for doing so
1403 at an improper time. */
1409 if (FRAME_DESIRED_GLYPHS (selected_frame
) == 0)
1411 if (FRAME_DESIRED_GLYPHS (selected_frame
)->enable
[0])
1413 if (FRAME_DESIRED_GLYPHS (selected_frame
)->enable
[FRAME_HEIGHT (selected_frame
) - 1])
1418 /* Decide what insert/delete line to do, and do it */
1420 extern void scrolling_1 ();
1425 int unchanged_at_top
, unchanged_at_bottom
;
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));
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. */
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
])
1450 old_hash
[i
] = line_hash_code (current_frame
, i
);
1451 if (! desired_frame
->enable
[i
])
1452 new_hash
[i
] = old_hash
[i
];
1454 new_hash
[i
] = line_hash_code (desired_frame
, i
);
1456 if (old_hash
[i
] != new_hash
[i
])
1459 unchanged_at_bottom
= FRAME_HEIGHT (frame
) - i
- 1;
1461 else if (i
== 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
))
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
1484 10 * scrolling_max_lines_saved (unchanged_at_top
,
1485 FRAME_HEIGHT (frame
) - unchanged_at_bottom
,
1486 old_hash
, new_hash
, draw_cost
)))
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
);
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
;
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
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. */
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)),
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;
1549 return posn
->bufpos
;
1556 register GLYPH
*p
= r
;
1557 while (*p
++ == SPACEGLYPH
);
1562 count_match (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))])
1577 update_line (frame
, vpos
)
1578 register FRAME_PTR frame
;
1581 register GLYPH
*obody
, *nbody
, *op1
, *op2
, *np1
, *temp
;
1584 int osp
, nsp
, begmatch
, endmatch
, olen
, nlen
;
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;
1600 reassert_line_highlight (desired_frame
->highlight
[vpos
], vpos
);
1602 if (! current_frame
->enable
[vpos
])
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
)
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
])
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
)
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
)
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
])
1688 cursor_to (vpos
, i
);
1690 clear_end_of_line (olen
);
1691 write_glyphs (nbody
+ i
, nlen
- i
);
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
]));
1705 /* Output this run of non-matching chars. */
1706 write_glyphs (nbody
+ i
, j
);
1709 /* Now find the next non-match. */
1713 /* Clear the rest of the line, or the non-clear part of it. */
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
;
1735 nsp
= (must_write_spaces
|| desired_frame
->highlight
[vpos
])
1736 ? 0 : count_blanks (nbody
);
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
;
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
);
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
)
1775 while (np1
[begmatch
] == SPACEGLYPH
)
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 */
1788 op2
= op1
+ begmatch
- min (olen
- osp
, nlen
- nsp
);
1789 while (op1
> op2
&& op1
[-1] == np1
[-1])
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. */
1803 /* tem gets the distance to insert or delete.
1804 endmatch is how many characters we save by doing so.
1807 tem
= (nlen
- nsp
) - (olen
- osp
);
1809 && (!char_ins_del_ok
|| endmatch
<= char_ins_del_cost (frame
)[tem
]))
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.
1818 && (!char_ins_del_ok
1819 || begmatch
+ endmatch
<= char_ins_del_cost (frame
)[nsp
- osp
]))
1823 osp
= nsp
= min (osp
, nsp
);
1826 /* Now go through the line, inserting, writing and
1827 deleting as appropriate. */
1831 cursor_to (vpos
, nsp
);
1832 delete_glyphs (osp
- nsp
);
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
);
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
))
1862 write_glyphs (nbody
+ nsp
+ begmatch
, nlen
- tem
);
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);
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
);
1893 else if (olen
> nlen
)
1895 write_glyphs (nbody
+ nsp
+ begmatch
, nlen
- tem
);
1896 delete_glyphs (olen
- nlen
);
1902 /* If any unerased characters remain after the new line, erase them. */
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
;
1941 vecp
= XVECTOR (frame_and_buffer_state
)->contents
;
1942 FOR_EACH_FRAME (tail
, frame
)
1944 if (!EQ (*vecp
++, frame
))
1946 if (!EQ (*vecp
++, XFRAME (frame
)->name
))
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] == ' ')
1959 if (!EQ (*vecp
++, buf
))
1961 if (!EQ (*vecp
++, XBUFFER (buf
)->read_only
))
1963 if (!EQ (*vecp
++, Fbuffer_modified_p (buf
)))
1966 /* Detect deletion of a buffer at the end of the list. */
1967 if (*vecp
== Qlambda
)
1970 /* Start with 1 so there is room for at least one lambda at the end. */
1972 FOR_EACH_FRAME (tail
, frame
)
1974 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
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
)
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] == ' ')
1994 *vecp
++ = XBUFFER (buf
)->read_only
;
1995 *vecp
++ = Fbuffer_modified_p (buf
);
1997 /* Fill up the vector with lambdas (always at least one). */
1999 while (vecp
- XVECTOR (frame_and_buffer_state
)->contents
2000 < XVECTOR (frame_and_buffer_state
)->size
)
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
)
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.")
2016 if (termscript
!= 0) fclose (termscript
);
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
));
2032 window_change_signal (signalnum
) /* If we don't have an argument, */
2033 int signalnum
; /* some compilers complain in signal calls. */
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);
2061 signal (SIGWINCH
, window_change_signal
);
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_WINDOW_P (f
))
2107 /* When using termcap, or on MS-DOS, all frames use
2108 the same screen, so a change in size affects all frames. */
2109 FOR_EACH_FRAME (tail
, frame
)
2110 if (! FRAME_WINDOW_P (XFRAME (frame
)))
2111 change_frame_size_1 (XFRAME (frame
), newheight
, newwidth
,
2115 change_frame_size_1 (f
, newheight
, newwidth
, pretend
, delay
);
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. */
2126 FRAME_NEW_HEIGHT (frame
) = newheight
;
2127 FRAME_NEW_WIDTH (frame
) = newwidth
;
2128 delayed_size_change
= 1;
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. */
2138 newheight
= FRAME_HEIGHT (frame
);
2140 newwidth
= FRAME_WIDTH (frame
);
2142 /* Round up to the smallest acceptable size. */
2143 check_frame_size (frame
, &newheight
, &newwidth
);
2145 /* If we're not changing the frame size, quit now. */
2146 if (newheight
== FRAME_HEIGHT (frame
)
2147 && newwidth
== FRAME_WIDTH (frame
))
2153 /* We only can set screen dimensions to certain values supported
2154 by our video hardware. Try to find the smallest size greater
2155 or equal to the requested dimensions. */
2156 dos_set_window_size (&newheight
, &newwidth
);
2159 if (newheight
!= FRAME_HEIGHT (frame
))
2161 if (FRAME_HAS_MINIBUF_P (frame
)
2162 && ! FRAME_MINIBUF_ONLY_P (frame
))
2164 /* Frame has both root and minibuffer. */
2165 set_window_height (FRAME_ROOT_WINDOW (frame
),
2166 newheight
- 1 - FRAME_MENU_BAR_LINES (frame
), 0);
2167 XSETFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (frame
))->top
,
2169 set_window_height (FRAME_MINIBUF_WINDOW (frame
), 1, 0);
2172 /* Frame has just one top-level window. */
2173 set_window_height (FRAME_ROOT_WINDOW (frame
),
2174 newheight
- FRAME_MENU_BAR_LINES (frame
), 0);
2176 if (FRAME_TERMCAP_P (frame
) && !pretend
)
2177 FrameRows
= newheight
;
2180 if (frame
->output_method
== output_termcap
)
2182 frame_height
= newheight
;
2184 FrameRows
= newheight
;
2189 if (newwidth
!= FRAME_WIDTH (frame
))
2191 set_window_width (FRAME_ROOT_WINDOW (frame
), newwidth
, 0);
2192 if (FRAME_HAS_MINIBUF_P (frame
))
2193 set_window_width (FRAME_MINIBUF_WINDOW (frame
), newwidth
, 0);
2195 if (FRAME_TERMCAP_P (frame
) && !pretend
)
2196 FrameCols
= newwidth
;
2198 if (frame
->output_method
== output_termcap
)
2200 frame_width
= newwidth
;
2202 FrameCols
= newwidth
;
2207 FRAME_HEIGHT (frame
) = newheight
;
2208 FRAME_WIDTH (frame
) = newwidth
;
2210 if (FRAME_CURSOR_X (frame
) >= FRAME_WIDTH (frame
))
2211 FRAME_CURSOR_X (frame
) = FRAME_WIDTH (frame
) - 1;
2212 if (FRAME_CURSOR_Y (frame
) >= FRAME_HEIGHT (frame
))
2213 FRAME_CURSOR_Y (frame
) = FRAME_HEIGHT (frame
) - 1;
2215 remake_frame_glyphs (frame
);
2216 calculate_costs (frame
);
2221 DEFUN ("send-string-to-terminal", Fsend_string_to_terminal
,
2222 Ssend_string_to_terminal
, 1, 1, 0,
2223 "Send STRING to the terminal without alteration.\n\
2224 Control characters in STRING will have terminal-dependent effects.")
2228 CHECK_STRING (string
, 0);
2229 fwrite (XSTRING (string
)->data
, 1, XSTRING (string
)->size
, stdout
);
2233 fwrite (XSTRING (string
)->data
, 1, XSTRING (string
)->size
, termscript
);
2234 fflush (termscript
);
2239 DEFUN ("ding", Fding
, Sding
, 0, 1, 0,
2240 "Beep, or flash the screen.\n\
2241 Also, unless an argument is given,\n\
2242 terminate any keyboard macro currently executing.")
2264 else if (!INTERACTIVE
) /* Stop executing a keyboard macro. */
2265 error ("Keyboard macro terminated by a command ringing the bell");
2271 DEFUN ("sleep-for", Fsleep_for
, Ssleep_for
, 1, 2, 0,
2272 "Pause, without updating display, for SECONDS seconds.\n\
2273 SECONDS may be a floating-point value, meaning that you can wait for a\n\
2274 fraction of a second. Optional second arg MILLISECONDS specifies an\n\
2275 additional wait period, in milliseconds; this may be useful if your\n\
2276 Emacs was built without floating point support.\n\
2277 \(Not all operating systems support waiting for a fraction of a second.)")
2278 (seconds
, milliseconds
)
2279 Lisp_Object seconds
, milliseconds
;
2283 if (NILP (milliseconds
))
2284 XSETINT (milliseconds
, 0);
2286 CHECK_NUMBER (milliseconds
, 1);
2287 usec
= XINT (milliseconds
) * 1000;
2289 #ifdef LISP_FLOAT_TYPE
2291 double duration
= extract_float (seconds
);
2292 sec
= (int) duration
;
2293 usec
+= (duration
- sec
) * 1000000;
2296 CHECK_NUMBER (seconds
, 0);
2297 sec
= XINT (seconds
);
2300 #ifndef EMACS_HAS_USECS
2301 if (sec
== 0 && usec
!= 0)
2302 error ("millisecond `sleep-for' not supported on %s", SYSTEM_TYPE
);
2305 /* Assure that 0 <= usec < 1000000. */
2308 /* We can't rely on the rounding being correct if user is negative. */
2309 if (-1000000 < usec
)
2310 sec
--, usec
+= 1000000;
2312 sec
-= -usec
/ 1000000, usec
= 1000000 - (-usec
% 1000000);
2315 sec
+= usec
/ 1000000, usec
%= 1000000;
2317 if (sec
< 0 || (sec
== 0 && usec
== 0))
2323 XSETFASTINT (zero
, 0);
2324 wait_reading_process_input (sec
, usec
, zero
, 0);
2327 /* We should always have wait_reading_process_input; we have a dummy
2328 implementation for systems which don't support subprocesses. */
2330 /* No wait_reading_process_input */
2337 /* The reason this is done this way
2338 (rather than defined (H_S) && defined (H_T))
2339 is because the VMS preprocessor doesn't grok `defined' */
2341 EMACS_GET_TIME (end_time
);
2342 EMACS_SET_SECS_USECS (timeout
, sec
, usec
);
2343 EMACS_ADD_TIME (end_time
, end_time
, timeout
);
2347 EMACS_GET_TIME (timeout
);
2348 EMACS_SUB_TIME (timeout
, end_time
, timeout
);
2349 if (EMACS_TIME_NEG_P (timeout
)
2350 || !select (1, 0, 0, 0, &timeout
))
2353 #else /* not HAVE_SELECT */
2355 #endif /* HAVE_SELECT */
2356 #endif /* not VMS */
2359 #endif /* no subprocesses */
2364 /* This is just like wait_reading_process_input, except that
2365 it does the redisplay.
2367 It's also much like Fsit_for, except that it can be used for
2368 waiting for input as well. */
2371 sit_for (sec
, usec
, reading
, display
)
2372 int sec
, usec
, reading
, display
;
2374 Lisp_Object read_kbd
;
2376 swallow_events (display
);
2378 if (detect_input_pending_run_timers (display
))
2382 redisplay_preserve_echo_area ();
2384 if (sec
== 0 && usec
== 0)
2391 XSETINT (read_kbd
, reading
? -1 : 1);
2392 wait_reading_process_input (sec
, usec
, read_kbd
, display
);
2395 /* wait_reading_process_input should always be available now; it is
2396 simulated in a simple way on systems that don't support
2399 /* No wait_reading_process_input available. */
2405 input_wait_timeout (XINT (arg
));
2407 #ifndef HAVE_TIMEVAL
2409 select (1, &waitchannels
, 0, 0, &timeout_sec
);
2410 #else /* HAVE_TIMEVAL */
2411 timeout
.tv_sec
= sec
;
2412 timeout
.tv_usec
= usec
;
2413 select (1, &waitchannels
, 0, 0, &timeout
);
2414 #endif /* HAVE_TIMEVAL */
2415 #endif /* not VMS */
2420 return detect_input_pending () ? Qnil
: Qt
;
2423 DEFUN ("sit-for", Fsit_for
, Ssit_for
, 1, 3, 0,
2424 "Perform redisplay, then wait for SECONDS seconds or until input is available.\n\
2425 SECONDS may be a floating-point value, meaning that you can wait for a\n\
2426 fraction of a second. Optional second arg MILLISECONDS specifies an\n\
2427 additional wait period, in milliseconds; this may be useful if your\n\
2428 Emacs was built without floating point support.\n\
2429 \(Not all operating systems support waiting for a fraction of a second.)\n\
2430 Optional third arg NODISP non-nil means don't redisplay, just wait for input.\n\
2431 Redisplay is preempted as always if input arrives, and does not happen\n\
2432 if input is available before it starts.\n\
2433 Value is t if waited the full time with no input arriving.")
2434 (seconds
, milliseconds
, nodisp
)
2435 Lisp_Object seconds
, milliseconds
, nodisp
;
2439 if (NILP (milliseconds
))
2440 XSETINT (milliseconds
, 0);
2442 CHECK_NUMBER (milliseconds
, 1);
2443 usec
= XINT (milliseconds
) * 1000;
2445 #ifdef LISP_FLOAT_TYPE
2447 double duration
= extract_float (seconds
);
2448 sec
= (int) duration
;
2449 usec
+= (duration
- sec
) * 1000000;
2452 CHECK_NUMBER (seconds
, 0);
2453 sec
= XINT (seconds
);
2456 #ifndef EMACS_HAS_USECS
2457 if (usec
!= 0 && sec
== 0)
2458 error ("millisecond `sit-for' not supported on %s", SYSTEM_TYPE
);
2461 return sit_for (sec
, usec
, 0, NILP (nodisp
));
2464 char *terminal_type
;
2466 /* Initialization done when Emacs fork is started, before doing stty. */
2467 /* Determine terminal type and set terminal_driver */
2468 /* Then invoke its decoding routine to set up variables
2469 in the terminal package */
2473 #ifdef HAVE_X_WINDOWS
2474 extern int display_arg
;
2479 cursor_in_echo_area
= 0;
2480 terminal_type
= (char *) 0;
2482 /* Now is the time to initialize this; it's used by init_sys_modes
2484 Vwindow_system
= Qnil
;
2486 /* If the user wants to use a window system, we shouldn't bother
2487 initializing the terminal. This is especially important when the
2488 terminal is so dumb that emacs gives up before and doesn't bother
2489 using the window system.
2491 If the DISPLAY environment variable is set and nonempty,
2492 try to use X, and die with an error message if that doesn't work. */
2494 #ifdef HAVE_X_WINDOWS
2499 display
= getenv ("DECW$DISPLAY");
2501 display
= getenv ("DISPLAY");
2504 display_arg
= (display
!= 0 && *display
!= 0);
2507 if (!inhibit_window_system
&& display_arg
)
2509 Vwindow_system
= intern ("x");
2511 Vwindow_system_version
= make_number (11);
2513 Vwindow_system_version
= make_number (10);
2515 #if defined (LINUX) && defined (HAVE_LIBNCURSES)
2516 /* In some versions of ncurses,
2517 tputs crashes if we have not called tgetent.
2519 { char b
[2044]; tgetent (b
, "xterm");}
2523 #endif /* HAVE_X_WINDOWS */
2526 if (!inhibit_window_system
)
2528 Vwindow_system
= intern ("win32");
2529 Vwindow_system_version
= make_number (1);
2532 #endif /* HAVE_NTGUI */
2534 /* If no window system has been specified, try to use the terminal. */
2537 fprintf (stderr
, "emacs: standard input is not a tty\n");
2541 /* Look at the TERM variable */
2542 terminal_type
= (char *) getenv ("TERM");
2546 fprintf (stderr
, "Please specify your terminal type.\n\
2547 For types defined in VMS, use set term /device=TYPE.\n\
2548 For types not defined in VMS, use define emacs_term \"TYPE\".\n\
2549 \(The quotation marks are necessary since terminal types are lower case.)\n");
2551 fprintf (stderr
, "Please set the environment variable TERM; see tset(1).\n");
2557 /* VMS DCL tends to upcase things, so downcase term type.
2558 Hardly any uppercase letters in terminal types; should be none. */
2560 char *new = (char *) xmalloc (strlen (terminal_type
) + 1);
2563 strcpy (new, terminal_type
);
2565 for (p
= new; *p
; p
++)
2569 terminal_type
= new;
2573 term_init (terminal_type
);
2575 remake_frame_glyphs (selected_frame
);
2576 calculate_costs (selected_frame
);
2578 /* X and Y coordinates of the cursor between updates. */
2579 FRAME_CURSOR_X (selected_frame
) = 0;
2580 FRAME_CURSOR_Y (selected_frame
) = 0;
2585 #endif /* CANNOT_DUMP */
2586 signal (SIGWINCH
, window_change_signal
);
2587 #endif /* SIGWINCH */
2593 defsubr (&Sredraw_frame
);
2595 defsubr (&Sredraw_display
);
2596 defsubr (&Sframe_or_buffer_changed_p
);
2597 defsubr (&Sopen_termscript
);
2599 defsubr (&Ssit_for
);
2600 defsubr (&Ssleep_for
);
2601 defsubr (&Ssend_string_to_terminal
);
2603 frame_and_buffer_state
= Fmake_vector (make_number (20), Qlambda
);
2604 staticpro (&frame_and_buffer_state
);
2606 Qdisplay_table
= intern ("display-table");
2607 staticpro (&Qdisplay_table
);
2609 DEFVAR_INT ("baud-rate", &baud_rate
,
2610 "*The output baud rate of the terminal.\n\
2611 On most systems, changing this value will affect the amount of padding\n\
2612 and the other strategic decisions made during redisplay.");
2613 DEFVAR_BOOL ("inverse-video", &inverse_video
,
2614 "*Non-nil means invert the entire frame display.\n\
2615 This means everything is in inverse video which otherwise would not be.");
2616 DEFVAR_BOOL ("visible-bell", &visible_bell
,
2617 "*Non-nil means try to flash the frame to represent a bell.");
2618 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter
,
2619 "*Non-nil means no need to redraw entire frame after suspending.\n\
2620 A non-nil value is useful if the terminal can automatically preserve\n\
2621 Emacs's frame display when you reenter Emacs.\n\
2622 It is up to you to set this variable if your terminal can do that.");
2623 DEFVAR_LISP ("window-system", &Vwindow_system
,
2624 "A symbol naming the window-system under which Emacs is running\n\
2625 \(such as `x'), or nil if emacs is running on an ordinary terminal.");
2626 DEFVAR_LISP ("window-system-version", &Vwindow_system_version
,
2627 "The version number of the window system in use.\n\
2628 For X windows, this is 10 or 11.");
2629 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area
,
2630 "Non-nil means put cursor in minibuffer, at end of any message there.");
2631 DEFVAR_LISP ("glyph-table", &Vglyph_table
,
2632 "Table defining how to output a glyph code to the frame.\n\
2633 If not nil, this is a vector indexed by glyph code to define the glyph.\n\
2634 Each element can be:\n\
2635 integer: a glyph code which this glyph is an alias for.\n\
2636 string: output this glyph using that string (not impl. in X windows).\n\
2637 nil: this glyph mod 256 is char code to output,\n\
2638 and this glyph / 256 is face code for X windows (see `face-id').");
2639 Vglyph_table
= Qnil
;
2641 DEFVAR_LISP ("standard-display-table", &Vstandard_display_table
,
2642 "Display table to use for buffers that specify none.\n\
2643 See `buffer-display-table' for more information.");
2644 Vstandard_display_table
= Qnil
;
2646 /* Initialize `window-system', unless init_display already decided it. */
2651 Vwindow_system
= Qnil
;
2652 Vwindow_system_version
= Qnil
;