(compilation-error-regexp-alist): In "Cray C" regexp, don't allow newlines.
[bpt/emacs.git] / src / xdisp.c
CommitLineData
a2889657 1/* Display generation from window structure and buffer text.
5992c4f7 2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
a2889657
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
b1d1124b 8the Free Software Foundation; either version 2, or (at your option)
a2889657
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
18160b98 21#include <config.h>
a2889657
JB
22#include <stdio.h>
23/*#include <ctype.h>*/
24#undef NULL
25#include "lisp.h"
44fa5b1e 26#include "frame.h"
a2889657
JB
27#include "window.h"
28#include "termchar.h"
29#include "dispextern.h"
30#include "buffer.h"
31#include "indent.h"
32#include "commands.h"
33#include "macros.h"
34#include "disptab.h"
30c566e4 35#include "termhooks.h"
b0a0fbda 36#include "intervals.h"
a2889657 37
76412d64
RS
38#ifdef USE_X_TOOLKIT
39extern void set_frame_menubar ();
40#endif
41
a2889657
JB
42extern int interrupt_input;
43extern int command_loop_level;
44
c4628384
RS
45extern Lisp_Object Qface;
46
f88eb0b6 47/* Nonzero means print newline to stdout before next minibuffer message. */
a2889657
JB
48
49int noninteractive_need_newline;
50
f88eb0b6
KH
51/* Nonzero means print newline to message log before next message. */
52
3c6595e0 53static int message_log_need_newline;
f88eb0b6 54
a2889657
JB
55#define min(a, b) ((a) < (b) ? (a) : (b))
56#define max(a, b) ((a) > (b) ? (a) : (b))
210e752f
KH
57#define minmax(floor, val, ceil) \
58 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
a2889657
JB
59
60/* The buffer position of the first character appearing
44fa5b1e
JB
61 entirely or partially on the current frame line.
62 Or zero, which disables the optimization for the current frame line. */
a2889657
JB
63static int this_line_bufpos;
64
65/* Number of characters past the end of this line,
66 including the terminating newline */
67static int this_line_endpos;
68
44fa5b1e 69/* The vertical position of this frame line. */
a2889657
JB
70static int this_line_vpos;
71
44fa5b1e 72/* Hpos value for start of display on this frame line.
a2889657
JB
73 Usually zero, but negative if first character really began
74 on previous line */
75static int this_line_start_hpos;
76
77/* Buffer that this_line variables are describing. */
78static struct buffer *this_line_buffer;
79
a2889657 80/* Value of echo_area_glyphs when it was last acted on.
44fa5b1e 81 If this is nonzero, there is a message on the frame
a2889657
JB
82 in the minibuffer and it should be erased as soon
83 as it is no longer requested to appear. */
84char *previous_echo_glyphs;
85
44fa5b1e 86/* Nonzero means truncate lines in all windows less wide than the frame */
a2889657
JB
87int truncate_partial_width_windows;
88
d39b6696
KH
89/* Nonzero means we have more than one non-minibuffer-only frame.
90 Not guaranteed to be accurate except while parsing frame-title-format. */
91int multiple_frames;
92
a2889657
JB
93Lisp_Object Vglobal_mode_string;
94
95/* Marker for where to display an arrow on top of the buffer text. */
96Lisp_Object Voverlay_arrow_position;
97
98/* String to display for the arrow. */
99Lisp_Object Voverlay_arrow_string;
100
d39b6696
KH
101/* Like mode-line-format, but for the titlebar on a visible frame. */
102Lisp_Object Vframe_title_format;
103
104/* Like mode-line-format, but for the titlebar on an iconified frame. */
105Lisp_Object Vicon_title_format;
106
08b610e4
RS
107/* List of functions to call when a window's size changes. These
108 functions get one arg, a frame on which one or more windows' sizes
109 have changed. */
110static Lisp_Object Vwindow_size_change_functions;
111
a2889657 112/* Values of those variables at last redisplay. */
ded34426 113static Lisp_Object last_arrow_position, last_arrow_string;
a2889657 114
cf074754
RS
115Lisp_Object Qmenu_bar_update_hook;
116
a2889657
JB
117/* Nonzero if overlay arrow has been displayed once in this window. */
118static int overlay_arrow_seen;
119
ca26e1c8
KH
120/* Nonzero if visible end of buffer has already been displayed once
121 in this window. (We need this variable in case there are overlay
122 strings that get displayed there.) */
123static int zv_strings_seen;
124
fba9ce76
RS
125/* Nonzero means highlight the region even in nonselected windows. */
126static int highlight_nonselected_windows;
127
44fa5b1e 128/* If cursor motion alone moves point off frame,
a2889657 129 Try scrolling this many lines up or down if that will bring it back. */
14510fee 130static int scroll_step;
a2889657
JB
131
132/* Nonzero if try_window_id has made blank lines at window bottom
133 since the last redisplay that paused */
134static int blank_end_of_window;
135
42640f83
RS
136/* Number of windows showing the buffer of the selected window
137 (or another buffer with the same base buffer).
a2889657
JB
138 keyboard.c refers to this. */
139int buffer_shared;
140
44fa5b1e 141/* display_text_line sets these to the frame position (origin 0) of point,
a2889657
JB
142 whether the window is selected or not.
143 Set one to -1 first to determine whether point was found afterwards. */
144
145static int cursor_vpos;
146static int cursor_hpos;
147
14510fee 148static int debug_end_pos;
a2889657
JB
149
150/* Nonzero means display mode line highlighted */
151int mode_line_inverse_video;
152
ff6c30e5 153static int message_log_check_duplicate ();
a2889657
JB
154static void echo_area_display ();
155void mark_window_display_accurate ();
156static void redisplay_windows ();
157static void redisplay_window ();
90adcf20 158static void update_menu_bar ();
a2889657
JB
159static void try_window ();
160static int try_window_id ();
161static struct position *display_text_line ();
162static void display_mode_line ();
163static int display_mode_element ();
a2889657
JB
164static char *decode_mode_spec ();
165static int display_string ();
7ce2c095 166static void display_menu_bar ();
aa6d10fa 167static int display_count_lines ();
a2889657
JB
168
169/* Prompt to display in front of the minibuffer contents */
8c5b6a0a 170Lisp_Object minibuf_prompt;
a2889657
JB
171
172/* Width in columns of current minibuffer prompt. */
173int minibuf_prompt_width;
174
175/* Message to display instead of minibuffer contents
176 This is what the functions error and message make,
177 and command echoing uses it as well.
178 It overrides the minibuf_prompt as well as the buffer. */
179char *echo_area_glyphs;
180
90adcf20
RS
181/* This is the length of the message in echo_area_glyphs. */
182int echo_area_glyphs_length;
183
a2889657
JB
184/* true iff we should redraw the mode lines on the next redisplay */
185int update_mode_lines;
186
187/* Smallest number of characters before the gap
188 at any time since last redisplay that finished.
189 Valid for current buffer when try_window_id can be called. */
190int beg_unchanged;
191
192/* Smallest number of characters after the gap
193 at any time since last redisplay that finished.
194 Valid for current buffer when try_window_id can be called. */
195int end_unchanged;
196
197/* MODIFF as of last redisplay that finished;
198 if it matches MODIFF, beg_unchanged and end_unchanged
199 contain no useful information */
200int unchanged_modified;
201
202/* Nonzero if head_clip or tail_clip of current buffer has changed
203 since last redisplay that finished */
204int clip_changed;
205
206/* Nonzero if window sizes or contents have changed
207 since last redisplay that finished */
208int windows_or_buffers_changed;
209
aa6d10fa
RS
210/* Nonzero after display_mode_line if %l was used
211 and it displayed a line number. */
212int line_number_displayed;
213
214/* Maximum buffer size for which to display line numbers. */
14510fee 215static int line_number_display_limit;
5992c4f7
KH
216
217/* Number of lines to keep in the message log buffer.
218 t means infinite. nil means don't log at all. */
219Lisp_Object Vmessage_log_max;
a2889657 220\f
3c6595e0
KH
221void
222message_log_maybe_newline ()
223{
224 if (message_log_need_newline)
225 message_dolog ("", 0, 1);
226}
227
228
d917be71
KH
229/* Add a string to the message log, optionally terminated with a newline.
230 This function calls low-level routines in order to bypass text property
231 hooks, etc. which might not be safe to run. */
90adcf20
RS
232
233void
f88eb0b6 234message_dolog (m, len, nlflag)
90adcf20 235 char *m;
f88eb0b6 236 int len, nlflag;
5992c4f7 237{
f88eb0b6 238 if (!NILP (Vmessage_log_max))
5992c4f7
KH
239 {
240 struct buffer *oldbuf;
241 int oldpoint, oldbegv, oldzv;
242
243 oldbuf = current_buffer;
3c6595e0 244 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
16c300fb 245 current_buffer->undo_list = Qt;
5992c4f7
KH
246 oldpoint = PT;
247 oldbegv = BEGV;
248 oldzv = ZV;
d917be71
KH
249 BEGV = BEG;
250 ZV = Z;
5992c4f7 251 if (oldpoint == Z)
f88eb0b6 252 oldpoint += len + nlflag;
5992c4f7 253 if (oldzv == Z)
f88eb0b6 254 oldzv += len + nlflag;
5992c4f7 255 TEMP_SET_PT (Z);
f88eb0b6
KH
256 if (len)
257 insert_1 (m, len, 1, 0);
258 if (nlflag)
5992c4f7 259 {
ff6c30e5
KH
260 int this_bol, prev_bol, dup;
261 insert_1 ("\n", 1, 1, 0);
262
263 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
264 if (this_bol > BEG)
265 {
266 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
267 dup = message_log_check_duplicate (prev_bol, this_bol);
268 if (dup)
269 {
270 if (oldpoint > prev_bol)
271 oldpoint -= min (this_bol, oldpoint) - prev_bol;
272 if (oldbegv > prev_bol)
273 oldbegv -= min (this_bol, oldbegv) - prev_bol;
274 if (oldzv > prev_bol)
275 oldzv -= min (this_bol, oldzv) - prev_bol;
276 del_range_1 (prev_bol, this_bol, 0);
277 if (dup > 1)
278 {
279 char dupstr[40];
280 int duplen;
281
282 /* If you change this format, don't forget to also
283 change message_log_check_duplicate. */
284 sprintf (dupstr, " [%d times]", dup);
285 duplen = strlen (dupstr);
286 TEMP_SET_PT (Z-1);
287 if (oldpoint == Z)
288 oldpoint += duplen;
289 if (oldzv == Z)
290 oldzv += duplen;
291 insert_1 (dupstr, duplen, 1, 0);
292 }
293 }
294 }
295
296 if (NATNUMP (Vmessage_log_max))
297 {
298 int pos = scan_buffer ('\n', Z, 0,
299 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
300 oldpoint -= min (pos, oldpoint) - BEG;
301 oldbegv -= min (pos, oldbegv) - BEG;
302 oldzv -= min (pos, oldzv) - BEG;
303 del_range_1 (BEG, pos, 0);
304 }
5992c4f7
KH
305 }
306 BEGV = oldbegv;
307 ZV = oldzv;
308 TEMP_SET_PT (oldpoint);
309 set_buffer_internal (oldbuf);
3c6595e0 310 message_log_need_newline = !nlflag;
5992c4f7 311 }
f88eb0b6
KH
312}
313
314
ff6c30e5
KH
315/* We are at the end of the buffer after just having inserted a newline.
316 (Note: We depend on the fact we won't be crossing the gap.)
317 Check to see if the most recent message looks a lot like the previous one.
318 Return 0 if different, 1 if the new one should just replace it, or a
319 value N > 1 if we should also append " [N times]". */
f82aff7c 320
ff6c30e5
KH
321static int
322message_log_check_duplicate (prev_bol, this_bol)
323 int prev_bol, this_bol;
324{
325 int i;
326 int len = Z - 1 - this_bol;
327 int seen_dots = 0;
f82aff7c
RS
328 unsigned char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
329 unsigned char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
ff6c30e5
KH
330
331 for (i = 0; i < len; i++)
332 {
333 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
334 && p1[i] != '\n')
335 seen_dots = 1;
336 if (p1[i] != p2[i])
337 return seen_dots;
338 }
339 p1 += len;
340 if (*p1 == '\n')
341 return 2;
342 if (*p1++ == ' ' && *p1++ == '[')
343 {
344 int n = 0;
345 while (*p1 >= '0' && *p1 <= '9')
346 n = n * 10 + *p1++ - '0';
347 if (strncmp (p1, " times]\n", 8) == 0)
348 return n+1;
349 }
350 return 0;
351}
352
f88eb0b6
KH
353/* Display an echo area message M with a specified length of LEN chars.
354 The string may include null characters. If m is 0, clear out any
355 existing message, and let the minibuffer text show through.
356 Do not pass text that is stored in a Lisp string. */
357
358void
359message2 (m, len)
360 char *m;
361 int len;
362{
363 /* First flush out any partial line written with print. */
3c6595e0 364 message_log_maybe_newline ();
f88eb0b6
KH
365 if (m)
366 message_dolog (m, len, 1);
5992c4f7
KH
367 message2_nolog (m, len);
368}
369
370
371/* The non-logging part of that function. */
372
373void
374message2_nolog (m, len)
375 char *m;
376 int len;
90adcf20
RS
377{
378 if (noninteractive)
379 {
380 if (noninteractive_need_newline)
381 putc ('\n', stderr);
382 noninteractive_need_newline = 0;
383 fwrite (m, len, 1, stderr);
384 if (cursor_in_echo_area == 0)
385 fprintf (stderr, "\n");
386 fflush (stderr);
387 }
388 /* A null message buffer means that the frame hasn't really been
389 initialized yet. Error messages get reported properly by
390 cmd_error, so this must be just an informative message; toss it. */
391 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
392 {
393#ifdef MULTI_FRAME
394 Lisp_Object minibuf_frame;
395
396 choose_minibuf_frame ();
397 minibuf_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
398 FRAME_SAMPLE_VISIBILITY (XFRAME (minibuf_frame));
399 if (FRAME_VISIBLE_P (selected_frame)
400 && ! FRAME_VISIBLE_P (XFRAME (minibuf_frame)))
401 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (minibuf_window)));
402#endif
403
404 if (m)
405 {
406 echo_area_glyphs = m;
407 echo_area_glyphs_length = len;
408 }
ded34426
JB
409 else
410 echo_area_glyphs = previous_echo_glyphs = 0;
411
412 do_pending_window_change ();
413 echo_area_display ();
414 update_frame (XFRAME (XWINDOW (minibuf_window)->frame), 1, 1);
415 do_pending_window_change ();
853cf346
RS
416 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
417 (*frame_up_to_date_hook) (XFRAME (XWINDOW (minibuf_window)->frame));
ded34426
JB
418 }
419}
420
48ae5f0a
KH
421void
422message1 (m)
423 char *m;
424{
425 message2 (m, (m ? strlen (m) : 0));
426}
427
0b1005ef
KH
428void
429message1_nolog (m)
430 char *m;
431{
432 message2_nolog (m, (m ? strlen (m) : 0));
433}
434
76412d64
RS
435/* Truncate what will be displayed in the echo area
436 the next time we display it--but don't redisplay it now. */
437
438void
439truncate_echo_area (len)
440 int len;
441{
442 /* A null message buffer means that the frame hasn't really been
443 initialized yet. Error messages get reported properly by
444 cmd_error, so this must be just an informative message; toss it. */
445 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
446 echo_area_glyphs_length = len;
447}
448
44fa5b1e 449/* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
9c74a0dd
JB
450 zero if being used by message. */
451int message_buf_print;
452
81d478f3
JB
453/* Dump an informative message to the minibuf. If m is 0, clear out
454 any existing message, and let the minibuffer text show through. */
a2889657 455/* VARARGS 1 */
a2889657
JB
456void
457message (m, a1, a2, a3)
458 char *m;
5d5ed907 459 EMACS_INT a1, a2, a3;
a2889657
JB
460{
461 if (noninteractive)
462 {
81d478f3
JB
463 if (m)
464 {
465 if (noninteractive_need_newline)
466 putc ('\n', stderr);
467 noninteractive_need_newline = 0;
468 fprintf (stderr, m, a1, a2, a3);
c4f14ccb
RS
469 if (cursor_in_echo_area == 0)
470 fprintf (stderr, "\n");
81d478f3
JB
471 fflush (stderr);
472 }
a2889657 473 }
1f40cad2 474 else if (INTERACTIVE)
a2889657 475 {
1f40cad2
JB
476 /* The frame whose minibuffer we're going to display the message on.
477 It may be larger than the selected frame, so we need
478 to use its buffer, not the selected frame's buffer. */
479 FRAME_PTR echo_frame;
480#ifdef MULTI_FRAME
481 choose_minibuf_frame ();
482 echo_frame = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
483#else
484 echo_frame = selected_frame;
485#endif
486
487 /* A null message buffer means that the frame hasn't really been
488 initialized yet. Error messages get reported properly by
489 cmd_error, so this must be just an informative message; toss it. */
490 if (FRAME_MESSAGE_BUF (echo_frame))
81d478f3 491 {
1f40cad2
JB
492 if (m)
493 {
90adcf20 494 int len;
a2889657 495#ifdef NO_ARG_ARRAY
5d5ed907 496 EMACS_INT a[3];
90adcf20
RS
497 a[0] = a1;
498 a[1] = a2;
499 a[2] = a3;
a2889657 500
90adcf20 501 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
d99d5863 502 FRAME_WIDTH (echo_frame), m, (char *)0, 3, a);
a2889657 503#else
90adcf20 504 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
d99d5863 505 FRAME_WIDTH (echo_frame), m, (char *)0, 3, &a1);
1f40cad2 506#endif /* NO_ARG_ARRAY */
1f40cad2 507
90adcf20 508 message2 (FRAME_MESSAGE_BUF (echo_frame), len);
1f40cad2
JB
509 }
510 else
511 message1 (0);
512
513 /* Print should start at the beginning of the message
514 buffer next time. */
515 message_buf_print = 0;
81d478f3 516 }
a2889657
JB
517 }
518}
519
6c4429a5
KH
520/* The non-logging version of that function. */
521void
522message_nolog (m, a1, a2, a3)
523 char *m;
524 EMACS_INT a1, a2, a3;
525{
526 Lisp_Object old_log_max;
527 old_log_max = Vmessage_log_max;
528 Vmessage_log_max = Qnil;
529 message (m, a1, a2, a3);
530 Vmessage_log_max = old_log_max;
531}
532
131f2133
RS
533void
534update_echo_area ()
535{
536 message2 (echo_area_glyphs, echo_area_glyphs_length);
537}
538
a2889657
JB
539static void
540echo_area_display ()
541{
542 register int vpos;
44fa5b1e 543 FRAME_PTR f;
a2889657 544
44fa5b1e
JB
545#ifdef MULTI_FRAME
546 choose_minibuf_frame ();
b1d1124b
JB
547#endif
548
44fa5b1e 549 f = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
a2889657 550
44fa5b1e 551 if (! FRAME_VISIBLE_P (f))
a2889657 552 return;
a2889657 553
44fa5b1e 554 if (frame_garbaged)
a2889657 555 {
02a9b6e4 556 redraw_garbaged_frames ();
44fa5b1e 557 frame_garbaged = 0;
a2889657
JB
558 }
559
560 if (echo_area_glyphs || minibuf_level == 0)
561 {
562 vpos = XFASTINT (XWINDOW (minibuf_window)->top);
44fa5b1e 563 get_display_line (f, vpos, 0);
a2889657
JB
564 display_string (XWINDOW (minibuf_window), vpos,
565 echo_area_glyphs ? echo_area_glyphs : "",
90adcf20 566 echo_area_glyphs ? echo_area_glyphs_length : -1,
278feba9 567 0, 0, 0, 0, FRAME_WIDTH (f));
a2889657
JB
568
569 /* If desired cursor location is on this line, put it at end of text */
b5bbc9a5
KH
570 if (cursor_in_echo_area)
571 FRAME_CURSOR_Y (f) = vpos;
44fa5b1e
JB
572 if (FRAME_CURSOR_Y (f) == vpos)
573 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
daa37602
JB
574
575 /* Fill the rest of the minibuffer window with blank lines. */
576 {
577 int i;
578
b2a76982
RS
579 for (i = vpos + 1;
580 i < vpos + XFASTINT (XWINDOW (minibuf_window)->height); i++)
daa37602 581 {
44fa5b1e 582 get_display_line (f, i, 0);
daa37602 583 display_string (XWINDOW (minibuf_window), vpos,
278feba9 584 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f));
daa37602
JB
585 }
586 }
a2889657
JB
587 }
588 else if (!EQ (minibuf_window, selected_window))
589 windows_or_buffers_changed++;
590
591 if (EQ (minibuf_window, selected_window))
592 this_line_bufpos = 0;
593
594 previous_echo_glyphs = echo_area_glyphs;
595}
96a410bc
KH
596
597#ifdef HAVE_X_WINDOWS
d39b6696
KH
598static char frame_title_buf[512];
599static char *frame_title_ptr;
96a410bc 600
d39b6696
KH
601static int
602store_frame_title (str, mincol, maxcol)
603 char *str;
604 int mincol, maxcol;
605{
606 char *limit;
607 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
608 maxcol = sizeof (frame_title_buf);
609 limit = &frame_title_buf[maxcol];
610 while (*str != '\0' && frame_title_ptr < limit)
611 *frame_title_ptr++ = *str++;
612 while (frame_title_ptr < &frame_title_buf[mincol])
613 *frame_title_ptr++ = ' ';
614 return frame_title_ptr - frame_title_buf;
615}
96a410bc 616
96a410bc
KH
617static void
618x_consider_frame_title (frame)
619 Lisp_Object frame;
620{
d39b6696
KH
621 Lisp_Object fmt;
622 struct buffer *obuf;
623 int len;
96a410bc
KH
624 FRAME_PTR f = XFRAME (frame);
625
d39b6696
KH
626 if (!FRAME_X_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name)
627 return;
3450d04c
KH
628
629 /* Do we have more than one visible frame on this X display? */
630 {
631 Lisp_Object tail;
632
633 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
634 {
635 FRAME_PTR tf = XFRAME (XCONS (tail)->car);
636
c9492f08
KH
637 if (tf != f && FRAME_KBOARD (tf) == FRAME_KBOARD (f)
638 && !FRAME_MINIBUF_ONLY_P (tf)
3450d04c
KH
639 && (FRAME_VISIBLE_P (tf) || FRAME_ICONIFIED_P (tf)))
640 break;
641 }
642
643 multiple_frames = CONSP (tail);
644 }
645
d39b6696
KH
646 obuf = current_buffer;
647 Fset_buffer (XWINDOW (f->selected_window)->buffer);
648 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
649 frame_title_ptr = frame_title_buf;
650 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
651 0, sizeof (frame_title_buf), fmt);
652 frame_title_ptr = 0;
653 set_buffer_internal (obuf);
654 /* Set the name only if it's changed. This avoids consing
655 in the common case where it hasn't. (If it turns out that we've
656 already wasted too much time by walking through the list with
657 display_mode_element, then we might need to optimize at a higher
658 level than this.) */
659 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
660 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
661 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
96a410bc 662}
c7c9ca97
KH
663#else
664#define frame_title_ptr ((char *)0)
e39322d9 665#define store_frame_title(str, mincol, maxcol) 0
96a410bc 666#endif
a2889657 667\f
90adcf20 668/* Prepare for redisplay by updating menu-bar item lists when appropriate.
87382820 669 This can call eval. */
90adcf20
RS
670
671void
672prepare_menu_bars ()
673{
674 register struct window *w = XWINDOW (selected_window);
675 int all_windows;
08b610e4 676 struct gcpro gcpro1, gcpro2;
90adcf20 677
ecf7de9b
RS
678 all_windows = (update_mode_lines || buffer_shared > 1
679 || clip_changed || windows_or_buffers_changed);
90adcf20 680
feb0c42f
KH
681 /* Update all frame titles based on their buffer names, etc.
682 We do this before the menu bars so that the buffer-menu
683 will show the up-to-date frame titles.
684
685 This used to be done after the menu bars, for a reason that
686 was stated as follows but which I do not understand:
687 "We do this after the menu bars so that the frame will first
688 create its menu bar using the name `emacs' if no other name
689 has yet been specified."
690 I think that is no longer a concern. */
691#ifdef HAVE_X_WINDOWS
692 if (windows_or_buffers_changed)
693 {
694 Lisp_Object tail, frame;
695
696 FOR_EACH_FRAME (tail, frame)
697 if (FRAME_VISIBLE_P (XFRAME (frame))
698 || FRAME_ICONIFIED_P (XFRAME (frame)))
699 x_consider_frame_title (frame);
700 }
701#endif
702
90adcf20
RS
703 /* Update the menu bar item lists, if appropriate.
704 This has to be done before any actual redisplay
705 or generation of display lines. */
706 if (all_windows)
707 {
708 Lisp_Object tail, frame;
a2725ab2
RS
709 int count = specpdl_ptr - specpdl;
710
711 record_unwind_protect (Fstore_match_data, Fmatch_data ());
90adcf20
RS
712
713 FOR_EACH_FRAME (tail, frame)
08b610e4
RS
714 {
715 /* If a window on this frame changed size,
716 report that to the user and clear the size-change flag. */
717 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
718 {
719 Lisp_Object functions;
14510fee
RS
720 /* Clear flag first in case we get error below. */
721 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
08b610e4
RS
722 functions = Vwindow_size_change_functions;
723 GCPRO2 (tail, functions);
724 while (CONSP (functions))
725 {
726 call1 (XCONS (functions)->car, frame);
727 functions = XCONS (functions)->cdr;
728 }
729 UNGCPRO;
08b610e4
RS
730 }
731 GCPRO1 (tail);
a2725ab2 732 update_menu_bar (XFRAME (frame), 0);
08b610e4
RS
733 UNGCPRO;
734 }
a2725ab2
RS
735
736 unbind_to (count, Qnil);
90adcf20 737 }
ecf7de9b 738 else
a2725ab2 739 update_menu_bar (selected_frame, 1);
90adcf20
RS
740}
741\f
44fa5b1e 742/* Do a frame update, taking possible shortcuts into account.
a2889657
JB
743 This is the main external entry point for redisplay.
744
745 If the last redisplay displayed an echo area message and that
746 message is no longer requested, we clear the echo area
747 or bring back the minibuffer if that is in use.
748
90adcf20
RS
749 Do not call eval from within this function.
750 Calls to eval after the call to echo_area_display would confuse
751 the display_line mechanism and would cause a crash.
752 Calls to eval before that point will work most of the time,
753 but can still lose, because this function
754 can be called from signal handlers; with alarms set up;
a2889657 755 or with synchronous processes running.
90adcf20 756
a2889657
JB
757 See Fcall_process; if you called it from here, it could be
758 entered recursively. */
759
0d231165
RS
760static int do_verify_charstarts;
761
463f6b91
RS
762/* Counter is used to clear the face cache
763 no more than once ever 1000 redisplays. */
764static int clear_face_cache_count;
765
a2889657
JB
766void
767redisplay ()
768{
769 register struct window *w = XWINDOW (selected_window);
770 register int pause;
771 int must_finish = 0;
772 int all_windows;
773 register int tlbufpos, tlendpos;
774 struct position pos;
a2889657
JB
775
776 if (noninteractive)
777 return;
778
d724d989
JB
779 /* Set the visible flags for all frames.
780 Do this before checking for resized or garbaged frames; they want
781 to know if their frames are visible.
782 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
783 {
35f56f96 784 Lisp_Object tail, frame;
d724d989 785
35f56f96 786 FOR_EACH_FRAME (tail, frame)
f82aff7c
RS
787 {
788 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
789
790 /* Clear out all the display lines in which we will generate the
791 glyphs to display. */
792 init_desired_glyphs (XFRAME (frame));
793 }
d724d989
JB
794 }
795
44fa5b1e 796 /* Notice any pending interrupt request to change frame size. */
a2889657
JB
797 do_pending_window_change ();
798
44fa5b1e 799 if (frame_garbaged)
a2889657 800 {
02a9b6e4 801 redraw_garbaged_frames ();
44fa5b1e 802 frame_garbaged = 0;
a2889657
JB
803 }
804
f82aff7c
RS
805 prepare_menu_bars ();
806
155ef550
KH
807 if (clip_changed || windows_or_buffers_changed
808 || (!NILP (w->column_number_displayed)
809 && XFASTINT (w->column_number_displayed) != current_column ()))
a2889657
JB
810 update_mode_lines++;
811
812 /* Detect case that we need to write a star in the mode line. */
813 if (XFASTINT (w->last_modified) < MODIFF
42640f83 814 && XFASTINT (w->last_modified) <= SAVE_MODIFF)
a2889657
JB
815 {
816 w->update_mode_line = Qt;
817 if (buffer_shared > 1)
818 update_mode_lines++;
819 }
820
44fa5b1e 821 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
a2889657
JB
822
823 all_windows = update_mode_lines || buffer_shared > 1;
a2889657
JB
824
825 /* If specs for an arrow have changed, do thorough redisplay
826 to ensure we remove any arrow that should no longer exist. */
ded34426
JB
827 if (! EQ (Voverlay_arrow_position, last_arrow_position)
828 || ! EQ (Voverlay_arrow_string, last_arrow_string))
a2889657
JB
829 all_windows = 1, clip_changed = 1;
830
90adcf20
RS
831 /* Normally the message* functions will have already displayed and
832 updated the echo area, but the frame may have been trashed, or
833 the update may have been preempted, so display the echo area
834 again here. */
835 if (echo_area_glyphs || previous_echo_glyphs)
836 {
837 echo_area_display ();
838 must_finish = 1;
839 }
840
bd66d1ba
RS
841 /* If showing region, and mark has changed, must redisplay whole window. */
842 if (((!NILP (Vtransient_mark_mode)
843 && !NILP (XBUFFER (w->buffer)->mark_active))
844 != !NILP (w->region_showing))
82d04750
JB
845 || (!NILP (w->region_showing)
846 && !EQ (w->region_showing,
847 Fmarker_position (XBUFFER (w->buffer)->mark))))
bd66d1ba
RS
848 this_line_bufpos = -1;
849
a2889657
JB
850 tlbufpos = this_line_bufpos;
851 tlendpos = this_line_endpos;
265a9e55 852 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
44fa5b1e 853 && FRAME_VISIBLE_P (XFRAME (w->frame))
a2889657
JB
854 /* Make sure recorded data applies to current buffer, etc */
855 && this_line_buffer == current_buffer
856 && current_buffer == XBUFFER (w->buffer)
265a9e55 857 && NILP (w->force_start)
a2889657 858 /* Point must be on the line that we have info recorded about */
ae3b1442
KH
859 && PT >= tlbufpos
860 && PT <= Z - tlendpos
a2889657
JB
861 /* All text outside that line, including its final newline,
862 must be unchanged */
863 && (XFASTINT (w->last_modified) >= MODIFF
864 || (beg_unchanged >= tlbufpos - 1
865 && GPT >= tlbufpos
05ba02eb
JB
866 /* If selective display, can't optimize
867 if the changes start at the beginning of the line. */
e24c997d 868 && ((INTEGERP (current_buffer->selective_display)
05ba02eb
JB
869 && XINT (current_buffer->selective_display) > 0
870 ? (beg_unchanged >= tlbufpos
871 && GPT > tlbufpos)
872 : 1))
a2889657
JB
873 && end_unchanged >= tlendpos
874 && Z - GPT >= tlendpos)))
875 {
876 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
877 && (tlbufpos == ZV
878 || FETCH_CHAR (tlbufpos) == '\n'))
879 /* Former continuation line has disappeared by becoming empty */
880 goto cancel;
881 else if (XFASTINT (w->last_modified) < MODIFF
882 || MINI_WINDOW_P (w))
883 {
884 cursor_vpos = -1;
885 overlay_arrow_seen = 0;
ca26e1c8 886 zv_strings_seen = 0;
a2889657
JB
887 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
888 pos_tab_offset (w, tlbufpos));
889 /* If line contains point, is not continued,
890 and ends at same distance from eob as before, we win */
891 if (cursor_vpos >= 0 && this_line_bufpos
892 && this_line_endpos == tlendpos)
893 {
0d231165
RS
894 /* If this is not the window's last line,
895 we must adjust the charstarts of the lines below. */
896 if (this_line_vpos + 1
897 < XFASTINT (w->top) + window_internal_height (w))
85bcef6c
RS
898 {
899 int left = XFASTINT (w->left);
900 int *charstart_next_line
901 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
85bcef6c
RS
902 int adjust;
903
904 if (Z - tlendpos == ZV)
905 /* This line ends at end of (accessible part of) buffer.
906 There is no newline to count. */
907 adjust = Z - tlendpos - charstart_next_line[left];
908 else
909 /* This line ends in a newline.
910 Must take account of the newline and the rest of the
911 text that follows. */
912 adjust = Z - tlendpos + 1 - charstart_next_line[left];
913
914 adjust_window_charstarts (w, this_line_vpos, adjust);
915 }
46db8486 916
44fa5b1e 917 if (XFASTINT (w->width) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w))))
a2889657
JB
918 preserve_other_columns (w);
919 goto update;
920 }
921 else
922 goto cancel;
923 }
ae3b1442 924 else if (PT == XFASTINT (w->last_point))
a2889657
JB
925 {
926 if (!must_finish)
927 {
928 do_pending_window_change ();
929 return;
930 }
931 goto update;
932 }
8b51f1e3
KH
933 /* If highlighting the region, or if the cursor is in the echo area,
934 then we can't just move the cursor. */
bd66d1ba
RS
935 else if (! (!NILP (Vtransient_mark_mode)
936 && !NILP (current_buffer->mark_active))
8b51f1e3
KH
937 && NILP (w->region_showing)
938 && !cursor_in_echo_area)
a2889657
JB
939 {
940 pos = *compute_motion (tlbufpos, 0,
941 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
ca26e1c8 942 0,
ae3b1442 943 PT, 2, - (1 << (SHORTBITS - 1)),
b1d1124b 944 window_internal_width (w) - 1,
de3e8b15 945 XINT (w->hscroll),
e37f06d7 946 pos_tab_offset (w, tlbufpos), w);
a2889657
JB
947 if (pos.vpos < 1)
948 {
210e752f 949 int width = window_internal_width (w) - 1;
44fa5b1e 950 FRAME_CURSOR_X (selected_frame)
210e752f 951 = XFASTINT (w->left) + minmax (0, pos.hpos, width);
44fa5b1e 952 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
a2889657
JB
953 goto update;
954 }
955 else
956 goto cancel;
957 }
958 cancel:
959 /* Text changed drastically or point moved off of line */
44fa5b1e 960 cancel_line (this_line_vpos, selected_frame);
a2889657
JB
961 }
962
963 this_line_bufpos = 0;
964 all_windows |= buffer_shared > 1;
965
463f6b91
RS
966 clear_face_cache_count++;
967
a2889657
JB
968 if (all_windows)
969 {
35f56f96 970 Lisp_Object tail, frame;
a2889657 971
87485d6f 972#ifdef HAVE_FACES
463f6b91
RS
973 /* Clear the face cache, only when we do a full redisplay
974 and not too often either. */
975 if (clear_face_cache_count > 1000)
976 {
977 clear_face_cache ();
978 clear_face_cache_count = 0;
979 }
31b24551
JB
980#endif
981
a2889657 982 /* Recompute # windows showing selected buffer.
8de2d90b 983 This will be incremented each time such a window is displayed. */
a2889657
JB
984 buffer_shared = 0;
985
35f56f96 986 FOR_EACH_FRAME (tail, frame)
30c566e4 987 {
35f56f96 988 FRAME_PTR f = XFRAME (frame);
9769686d
RS
989 if (! FRAME_TERMCAP_P (f) || f == selected_frame)
990 {
35f56f96 991
9769686d
RS
992 /* Mark all the scroll bars to be removed; we'll redeem the ones
993 we want when we redisplay their windows. */
994 if (condemn_scroll_bars_hook)
995 (*condemn_scroll_bars_hook) (f);
30c566e4 996
9769686d
RS
997 if (FRAME_VISIBLE_P (f))
998 redisplay_windows (FRAME_ROOT_WINDOW (f));
30c566e4 999
9769686d
RS
1000 /* Any scroll bars which redisplay_windows should have nuked
1001 should now go away. */
1002 if (judge_scroll_bars_hook)
1003 (*judge_scroll_bars_hook) (f);
1004 }
30c566e4 1005 }
a2889657 1006 }
44fa5b1e 1007 else if (FRAME_VISIBLE_P (selected_frame))
a2889657
JB
1008 {
1009 redisplay_window (selected_window, 1);
44fa5b1e 1010 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
a2889657
JB
1011 preserve_other_columns (w);
1012 }
1013
1014update:
1015 /* Prevent various kinds of signals during display update.
1016 stdio is not robust about handling signals,
1017 which can cause an apparent I/O error. */
1018 if (interrupt_input)
1019 unrequest_sigio ();
1020 stop_polling ();
1021
44fa5b1e 1022#ifdef MULTI_FRAME
a2889657
JB
1023 if (all_windows)
1024 {
1025 Lisp_Object tail;
1026
1027 pause = 0;
1028
44fa5b1e 1029 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
a2889657 1030 {
44fa5b1e 1031 FRAME_PTR f;
a2889657 1032
e24c997d 1033 if (!FRAMEP (XCONS (tail)->car))
a2889657
JB
1034 continue;
1035
44fa5b1e 1036 f = XFRAME (XCONS (tail)->car);
1af9f229
RS
1037
1038 if ((! FRAME_TERMCAP_P (f) || f == selected_frame)
1039 && FRAME_VISIBLE_P (f))
a2889657 1040 {
44fa5b1e 1041 pause |= update_frame (f, 0, 0);
a2889657 1042 if (!pause)
efc63ef0
RS
1043 {
1044 mark_window_display_accurate (f->root_window, 1);
1045 if (frame_up_to_date_hook != 0)
1046 (*frame_up_to_date_hook) (f);
1047 }
a2889657
JB
1048 }
1049 }
1050 }
1051 else
44fa5b1e 1052#endif /* MULTI_FRAME */
6e8290aa 1053 {
44fa5b1e
JB
1054 if (FRAME_VISIBLE_P (selected_frame))
1055 pause = update_frame (selected_frame, 0, 0);
4d641a15
KH
1056 else
1057 pause = 0;
d724d989 1058
8de2d90b 1059 /* We may have called echo_area_display at the top of this
44fa5b1e
JB
1060 function. If the echo area is on another frame, that may
1061 have put text on a frame other than the selected one, so the
1062 above call to update_frame would not have caught it. Catch
8de2d90b
JB
1063 it here. */
1064 {
efc63ef0
RS
1065 FRAME_PTR mini_frame
1066 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
8de2d90b 1067
44fa5b1e
JB
1068 if (mini_frame != selected_frame)
1069 pause |= update_frame (mini_frame, 0, 0);
8de2d90b 1070 }
6e8290aa 1071 }
a2889657 1072
44fa5b1e 1073 /* If frame does not match, prevent doing single-line-update next time.
a2889657
JB
1074 Also, don't forget to check every line to update the arrow. */
1075 if (pause)
1076 {
1077 this_line_bufpos = 0;
265a9e55 1078 if (!NILP (last_arrow_position))
a2889657
JB
1079 {
1080 last_arrow_position = Qt;
1081 last_arrow_string = Qt;
1082 }
44fa5b1e 1083 /* If we pause after scrolling, some lines in current_frame
a2889657
JB
1084 may be null, so preserve_other_columns won't be able to
1085 preserve all the vertical-bar separators. So, avoid using it
1086 in that case. */
44fa5b1e 1087 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
a2889657
JB
1088 update_mode_lines = 1;
1089 }
1090
44fa5b1e 1091 /* Now text on frame agrees with windows, so
a2889657
JB
1092 put info into the windows for partial redisplay to follow */
1093
1094 if (!pause)
1095 {
1096 register struct buffer *b = XBUFFER (w->buffer);
1097
1098 blank_end_of_window = 0;
1099 clip_changed = 0;
1100 unchanged_modified = BUF_MODIFF (b);
1101 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1102 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1103
c2213350
KH
1104 XSETFASTINT (w->last_point, BUF_PT (b));
1105 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1106 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
a2889657
JB
1107
1108 if (all_windows)
11e82b76 1109 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
a2889657
JB
1110 else
1111 {
1112 w->update_mode_line = Qnil;
c2213350 1113 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
d2f84654 1114 w->window_end_valid = w->buffer;
a2889657
JB
1115 last_arrow_position = Voverlay_arrow_position;
1116 last_arrow_string = Voverlay_arrow_string;
0d231165
RS
1117 if (do_verify_charstarts)
1118 verify_charstarts (w);
efc63ef0
RS
1119 if (frame_up_to_date_hook != 0)
1120 (*frame_up_to_date_hook) (selected_frame);
a2889657
JB
1121 }
1122 update_mode_lines = 0;
1123 windows_or_buffers_changed = 0;
1124 }
1125
1126 /* Start SIGIO interrupts coming again.
1127 Having them off during the code above
1128 makes it less likely one will discard output,
1129 but not impossible, since there might be stuff
1130 in the system buffer here.
1131 But it is much hairier to try to do anything about that. */
1132
1133 if (interrupt_input)
1134 request_sigio ();
1135 start_polling ();
1136
44fa5b1e 1137 /* Change frame size now if a change is pending. */
a2889657 1138 do_pending_window_change ();
d8e242fd
RS
1139
1140 /* If we just did a pending size change, redisplay again
1141 for the new size. */
3c8c72e0 1142 if (windows_or_buffers_changed && !pause)
d8e242fd 1143 redisplay ();
a2889657
JB
1144}
1145
1146/* Redisplay, but leave alone any recent echo area message
1147 unless another message has been requested in its place.
1148
1149 This is useful in situations where you need to redisplay but no
1150 user action has occurred, making it inappropriate for the message
1151 area to be cleared. See tracking_off and
1152 wait_reading_process_input for examples of these situations. */
1153
1154redisplay_preserve_echo_area ()
1155{
1156 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1157 {
1158 echo_area_glyphs = previous_echo_glyphs;
1159 redisplay ();
1160 echo_area_glyphs = 0;
1161 }
1162 else
1163 redisplay ();
1164}
1165
1166void
1167mark_window_display_accurate (window, flag)
1168 Lisp_Object window;
1169 int flag;
1170{
1171 register struct window *w;
1172
265a9e55 1173 for (;!NILP (window); window = w->next)
a2889657 1174 {
e24c997d 1175 if (!WINDOWP (window)) abort ();
a2889657
JB
1176 w = XWINDOW (window);
1177
265a9e55 1178 if (!NILP (w->buffer))
bd66d1ba 1179 {
c2213350
KH
1180 XSETFASTINT (w->last_modified,
1181 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
bd66d1ba
RS
1182
1183 /* Record if we are showing a region, so can make sure to
1184 update it fully at next redisplay. */
1185 w->region_showing = (!NILP (Vtransient_mark_mode)
1186 && !NILP (XBUFFER (w->buffer)->mark_active)
1187 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1188 : Qnil);
1189 }
1190
d2f84654 1191 w->window_end_valid = w->buffer;
a2889657
JB
1192 w->update_mode_line = Qnil;
1193
265a9e55 1194 if (!NILP (w->vchild))
a2889657 1195 mark_window_display_accurate (w->vchild, flag);
265a9e55 1196 if (!NILP (w->hchild))
a2889657
JB
1197 mark_window_display_accurate (w->hchild, flag);
1198 }
1199
1200 if (flag)
1201 {
1202 last_arrow_position = Voverlay_arrow_position;
1203 last_arrow_string = Voverlay_arrow_string;
1204 }
1205 else
1206 {
1207 /* t is unequal to any useful value of Voverlay_arrow_... */
1208 last_arrow_position = Qt;
1209 last_arrow_string = Qt;
1210 }
1211}
1212\f
ecf7de9b 1213/* Update the menu bar item list for frame F.
90adcf20 1214 This has to be done before we start to fill in any display lines,
a2725ab2
RS
1215 because it can call eval.
1216
1217 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
90adcf20
RS
1218
1219static void
a2725ab2 1220update_menu_bar (f, save_match_data)
ecf7de9b 1221 FRAME_PTR f;
a2725ab2 1222 int save_match_data;
90adcf20 1223{
90adcf20 1224 struct buffer *old = current_buffer;
ecf7de9b
RS
1225 Lisp_Object window;
1226 register struct window *w;
a2725ab2 1227
ecf7de9b
RS
1228 window = FRAME_SELECTED_WINDOW (f);
1229 w = XWINDOW (window);
90adcf20
RS
1230
1231 if (update_mode_lines)
1232 w->update_mode_line = Qt;
1233
cf074754 1234 if (
78614721 1235#ifdef USE_X_TOOLKIT
cf074754 1236 FRAME_EXTERNAL_MENU_BAR (f)
78614721 1237#else
cf074754 1238 FRAME_MENU_BAR_LINES (f) > 0
78614721 1239#endif
ecf7de9b 1240 )
90adcf20
RS
1241 {
1242 /* If the user has switched buffers or windows, we need to
1243 recompute to reflect the new bindings. But we'll
1244 recompute when update_mode_lines is set too; that means
1245 that people can use force-mode-line-update to request
1246 that the menu bar be recomputed. The adverse effect on
1247 the rest of the redisplay algorithm is about the same as
1248 windows_or_buffers_changed anyway. */
1249 if (windows_or_buffers_changed
cf074754 1250 || !NILP (w->update_mode_line)
90adcf20
RS
1251 || (XFASTINT (w->last_modified) < MODIFF
1252 && (XFASTINT (w->last_modified)
42640f83 1253 <= BUF_SAVE_MODIFF (XBUFFER (w->buffer)))))
90adcf20
RS
1254 {
1255 struct buffer *prev = current_buffer;
a2725ab2
RS
1256 int count = specpdl_ptr - specpdl;
1257
eac4251c 1258 if (save_match_data)
a2725ab2
RS
1259 record_unwind_protect (Fstore_match_data, Fmatch_data ());
1260
cf074754 1261 call1 (Vrun_hooks, Qmenu_bar_update_hook);
90adcf20 1262 current_buffer = XBUFFER (w->buffer);
8351baf2 1263 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
76412d64 1264#ifdef USE_X_TOOLKIT
01a054bc 1265 set_frame_menubar (f, 0);
76412d64 1266#endif /* USE_X_TOOLKIT */
a2725ab2 1267
dcb9e676 1268 current_buffer = prev;
a2725ab2 1269 unbind_to (count, Qnil);
90adcf20
RS
1270 }
1271 }
1272}
1273\f
a2889657
JB
1274int do_id = 1;
1275
90adcf20
RS
1276/* Redisplay WINDOW and its subwindows and siblings. */
1277
a2889657
JB
1278static void
1279redisplay_windows (window)
1280 Lisp_Object window;
1281{
265a9e55 1282 for (; !NILP (window); window = XWINDOW (window)->next)
a2889657
JB
1283 redisplay_window (window, 0);
1284}
1285
90adcf20
RS
1286/* Redisplay window WINDOW and its subwindows. */
1287
a2889657
JB
1288static void
1289redisplay_window (window, just_this_one)
1290 Lisp_Object window;
1291 int just_this_one;
1292{
1293 register struct window *w = XWINDOW (window);
30c566e4 1294 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
a2889657 1295 int height;
ae3b1442 1296 register int lpoint = PT;
a2889657 1297 struct buffer *old = current_buffer;
b1d1124b 1298 register int width = window_internal_width (w) - 1;
a2889657
JB
1299 register int startp;
1300 register int hscroll = XINT (w->hscroll);
1301 struct position pos;
ae3b1442 1302 int opoint = PT;
a2889657 1303 int tem;
e481f960 1304 int update_mode_line;
23c852cb 1305 struct Lisp_Vector *dp = window_display_table (w);
a2889657 1306
44fa5b1e 1307 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
a2889657
JB
1308
1309 /* If this is a combination window, do its children; that's all. */
1310
265a9e55 1311 if (!NILP (w->vchild))
a2889657
JB
1312 {
1313 redisplay_windows (w->vchild);
1314 return;
1315 }
265a9e55 1316 if (!NILP (w->hchild))
a2889657
JB
1317 {
1318 redisplay_windows (w->hchild);
1319 return;
1320 }
265a9e55 1321 if (NILP (w->buffer))
a2889657 1322 abort ();
8de2d90b
JB
1323
1324 height = window_internal_height (w);
4d641a15 1325 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
8de2d90b
JB
1326
1327 if (MINI_WINDOW_P (w))
1328 {
1329 if (w == XWINDOW (minibuf_window))
1330 {
1331 if (echo_area_glyphs)
1332 /* We've already displayed the echo area glyphs, if any. */
88f22aff 1333 goto finish_scroll_bars;
8de2d90b
JB
1334 }
1335 else
1336 {
1337 /* This is a minibuffer, but it's not the currently active one, so
1338 clear it. */
44fa5b1e 1339 int vpos = XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top);
8de2d90b
JB
1340 int i;
1341
1342 for (i = 0; i < height; i++)
1343 {
44fa5b1e 1344 get_display_line (f, vpos + i, 0);
278feba9 1345 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
8de2d90b
JB
1346 }
1347
88f22aff 1348 goto finish_scroll_bars;
8de2d90b
JB
1349 }
1350 }
a2889657 1351
a2889657
JB
1352 /* Otherwise set up data on this window; select its buffer and point value */
1353
e481f960 1354 if (update_mode_line)
f72df6ac 1355 set_buffer_internal_1 (XBUFFER (w->buffer));
e481f960
RS
1356 else
1357 set_buffer_temp (XBUFFER (w->buffer));
1358
ae3b1442 1359 opoint = PT;
a2889657 1360
42640f83
RS
1361 /* Count number of windows showing the selected buffer.
1362 An indirect buffer counts as its base buffer. */
a2889657 1363
42640f83
RS
1364 if (!just_this_one)
1365 {
1366 struct buffer *current_base, *window_base;
1367 current_base = current_buffer;
1368 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1369 if (current_base->base_buffer)
1370 current_base = current_base->base_buffer;
1371 if (window_base->base_buffer)
1372 window_base = window_base->base_buffer;
1373 if (current_base == window_base)
1374 buffer_shared++;
1375 }
a2889657
JB
1376
1377 /* POINT refers normally to the selected window.
1378 For any other window, set up appropriate value. */
1379
1380 if (!EQ (window, selected_window))
1381 {
f67a0f51
RS
1382 int new_pt = marker_position (w->pointm);
1383 if (new_pt < BEGV)
a2889657 1384 {
f67a0f51
RS
1385 new_pt = BEGV;
1386 Fset_marker (w->pointm, make_number (new_pt), Qnil);
a2889657 1387 }
f67a0f51 1388 else if (new_pt > (ZV - 1))
a2889657 1389 {
f67a0f51
RS
1390 new_pt = ZV;
1391 Fset_marker (w->pointm, make_number (new_pt), Qnil);
a2889657 1392 }
f67a0f51
RS
1393 /* We don't use SET_PT so that the point-motion hooks don't run. */
1394 BUF_PT (current_buffer) = new_pt;
a2889657
JB
1395 }
1396
f4faa47c
JB
1397 /* If any of the character widths specified in the display table
1398 have changed, invalidate the width run cache. It's true that this
1399 may be a bit late to catch such changes, but the rest of
1400 redisplay goes (non-fatally) haywire when the display table is
1401 changed, so why should we worry about doing any better? */
1402 if (current_buffer->width_run_cache)
1403 {
1404 struct Lisp_Vector *disptab = buffer_display_table ();
1405
1406 if (! disptab_matches_widthtab (disptab,
1407 XVECTOR (current_buffer->width_table)))
1408 {
1409 invalidate_region_cache (current_buffer,
1410 current_buffer->width_run_cache,
1411 BEG, Z);
1412 recompute_width_table (current_buffer, disptab);
1413 }
1414 }
1415
a2889657 1416 /* If window-start is screwed up, choose a new one. */
a2889657
JB
1417 if (XMARKER (w->start)->buffer != current_buffer)
1418 goto recenter;
1419
1420 startp = marker_position (w->start);
1421
8de2d90b 1422 /* Handle case where place to start displaying has been specified,
aa6d10fa 1423 unless the specified location is outside the accessible range. */
265a9e55 1424 if (!NILP (w->force_start))
a2889657 1425 {
aa6d10fa
RS
1426 /* Forget any recorded base line for line number display. */
1427 w->base_line_number = Qnil;
e481f960
RS
1428 /* Redisplay the mode line. Select the buffer properly for that. */
1429 if (!update_mode_line)
1430 {
1431 set_buffer_temp (old);
f72df6ac 1432 set_buffer_internal_1 (XBUFFER (w->buffer));
e481f960
RS
1433 update_mode_line = 1;
1434 w->update_mode_line = Qt;
1435 }
a2889657 1436 w->force_start = Qnil;
c2213350 1437 XSETFASTINT (w->last_modified, 0);
8de2d90b
JB
1438 if (startp < BEGV) startp = BEGV;
1439 if (startp > ZV) startp = ZV;
a2889657
JB
1440 try_window (window, startp);
1441 if (cursor_vpos < 0)
1442 {
1443 /* If point does not appear, move point so it does appear */
1444 pos = *compute_motion (startp, 0,
ca26e1c8
KH
1445 (((EQ (window, minibuf_window)
1446 && startp == BEG)
1447 ? minibuf_prompt_width : 0)
1448 + (hscroll ? 1 - hscroll : 0)),
1449 0,
1450 ZV, height / 2,
1451 - (1 << (SHORTBITS - 1)),
1452 width, hscroll, pos_tab_offset (w, startp), w);
f67a0f51 1453 BUF_PT (current_buffer) = pos.bufpos;
90adcf20 1454 if (w != XWINDOW (selected_window))
ae3b1442 1455 Fset_marker (w->pointm, make_number (PT), Qnil);
a2889657
JB
1456 else
1457 {
9d6a6bb9 1458 if (current_buffer == old)
ae3b1442 1459 lpoint = PT;
210e752f
KH
1460 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1461 + minmax (0, pos.hpos, width));
44fa5b1e 1462 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
a2889657 1463 }
df0b5ea1
RS
1464 /* If we are highlighting the region,
1465 then we just changed the region, so redisplay to show it. */
df0b5ea1
RS
1466 if (!NILP (Vtransient_mark_mode)
1467 && !NILP (current_buffer->mark_active))
6f27fa9b
RS
1468 {
1469 cancel_my_columns (XWINDOW (window));
1470 try_window (window, startp);
1471 }
a2889657
JB
1472 }
1473 goto done;
1474 }
1475
1476 /* Handle case where text has not changed, only point,
44fa5b1e 1477 and it has not moved off the frame */
a2889657
JB
1478
1479 /* This code is not used for minibuffer for the sake of
1480 the case of redisplaying to replace an echo area message;
1481 since in that case the minibuffer contents per se are usually unchanged.
1482 This code is of no real use in the minibuffer since
1483 the handling of this_line_bufpos, etc.,
1484 in redisplay handles the same cases. */
1485
1486 if (XFASTINT (w->last_modified) >= MODIFF
ae3b1442 1487 && PT >= startp && !clip_changed
44fa5b1e 1488 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
b1aa6cb3
RS
1489 /* If force-mode-line-update was called, really redisplay;
1490 that's how redisplay is forced after e.g. changing
1491 buffer-invisibility-spec. */
632ab665 1492 && NILP (w->update_mode_line)
bd66d1ba
RS
1493 /* Can't use this case if highlighting a region. */
1494 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1495 && NILP (w->region_showing)
15495c73
KH
1496 /* If end pos is out of date, scroll bar and percentage will be wrong */
1497 && INTEGERP (w->window_end_vpos)
1498 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
a2889657
JB
1499 && !EQ (window, minibuf_window))
1500 {
ca26e1c8 1501 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0,
632ab665 1502 PT, height, 0, width, hscroll,
e37f06d7 1503 pos_tab_offset (w, startp), w);
a2889657
JB
1504
1505 if (pos.vpos < height)
1506 {
44fa5b1e
JB
1507 /* Ok, point is still on frame */
1508 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
a2889657
JB
1509 {
1510 /* These variables are supposed to be origin 1 */
210e752f
KH
1511 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1512 + minmax (0, pos.hpos, width));
44fa5b1e 1513 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
a2889657
JB
1514 }
1515 /* This doesn't do the trick, because if a window to the right of
1516 this one must be redisplayed, this does nothing because there
44fa5b1e 1517 is nothing in DesiredFrame yet, and then the other window is
a2889657 1518 redisplayed, making likes that are empty in this window's columns.
44fa5b1e 1519 if (XFASTINT (w->width) != FRAME_WIDTH (f))
a2889657
JB
1520 preserve_my_columns (w);
1521 */
1522 goto done;
1523 }
1524 /* Don't bother trying redisplay with same start;
1525 we already know it will lose */
1526 }
1527 /* If current starting point was originally the beginning of a line
1528 but no longer is, find a new starting point. */
265a9e55 1529 else if (!NILP (w->start_at_line_beg)
b16234d8 1530 && !(startp <= BEGV
a2889657
JB
1531 || FETCH_CHAR (startp - 1) == '\n'))
1532 {
1533 goto recenter;
1534 }
1535 else if (just_this_one && !MINI_WINDOW_P (w)
ae3b1442 1536 && PT >= startp
a2889657 1537 && XFASTINT (w->last_modified)
14709f21
JB
1538 /* or else vmotion on first line won't work. */
1539 && ! NILP (w->start_at_line_beg)
a2889657
JB
1540 && ! EQ (w->window_end_valid, Qnil)
1541 && do_id && !clip_changed
1542 && !blank_end_of_window
44fa5b1e 1543 && XFASTINT (w->width) == FRAME_WIDTH (f)
bd66d1ba
RS
1544 /* Can't use this case if highlighting a region. */
1545 && !(!NILP (Vtransient_mark_mode)
1546 && !NILP (current_buffer->mark_active))
23c852cb
KH
1547 /* Don't use try_window_id if newline
1548 doesn't display as the end of a line. */
1549 && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n')))
bd66d1ba 1550 && NILP (w->region_showing)
a2889657
JB
1551 && EQ (last_arrow_position, Voverlay_arrow_position)
1552 && EQ (last_arrow_string, Voverlay_arrow_string)
44fa5b1e 1553 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
a2889657
JB
1554 && tem != -2)
1555 {
1556 /* tem > 0 means success. tem == -1 means choose new start.
1557 tem == -2 means try again with same start,
1558 and nothing but whitespace follows the changed stuff.
1559 tem == 0 means try again with same start. */
1560 if (tem > 0)
1561 goto done;
1562 }
1563 else if (startp >= BEGV && startp <= ZV
1564 /* Avoid starting display at end of buffer! */
8de2d90b 1565 && (startp < ZV || startp == BEGV
a2889657
JB
1566 || (XFASTINT (w->last_modified) >= MODIFF)))
1567 {
1568 /* Try to redisplay starting at same place as before */
44fa5b1e 1569 /* If point has not moved off frame, accept the results */
a2889657
JB
1570 try_window (window, startp);
1571 if (cursor_vpos >= 0)
aa6d10fa
RS
1572 {
1573 if (!just_this_one || clip_changed || beg_unchanged < startp)
1574 /* Forget any recorded base line for line number display. */
1575 w->base_line_number = Qnil;
1576 goto done;
1577 }
a2889657
JB
1578 else
1579 cancel_my_columns (w);
1580 }
1581
c2213350 1582 XSETFASTINT (w->last_modified, 0);
e481f960
RS
1583 /* Redisplay the mode line. Select the buffer properly for that. */
1584 if (!update_mode_line)
1585 {
1586 set_buffer_temp (old);
f72df6ac 1587 set_buffer_internal_1 (XBUFFER (w->buffer));
e481f960
RS
1588 update_mode_line = 1;
1589 w->update_mode_line = Qt;
1590 }
a2889657
JB
1591
1592 /* Try to scroll by specified few lines */
1593
1594 if (scroll_step && !clip_changed)
1595 {
ae3b1442 1596 if (PT > startp)
a2889657 1597 {
210e752f 1598 pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w);
a2889657
JB
1599 if (pos.vpos >= height)
1600 goto scroll_fail;
1601 }
1602
210e752f 1603 pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w);
a2889657 1604
ae3b1442 1605 if (PT >= pos.bufpos)
a2889657
JB
1606 {
1607 try_window (window, pos.bufpos);
1608 if (cursor_vpos >= 0)
aa6d10fa
RS
1609 {
1610 if (!just_this_one || clip_changed || beg_unchanged < startp)
1611 /* Forget any recorded base line for line number display. */
1612 w->base_line_number = Qnil;
1613 goto done;
1614 }
a2889657
JB
1615 else
1616 cancel_my_columns (w);
1617 }
1618 scroll_fail: ;
1619 }
1620
1621 /* Finally, just choose place to start which centers point */
1622
1623recenter:
aa6d10fa
RS
1624 /* Forget any previously recorded base line for line number display. */
1625 w->base_line_number = Qnil;
1626
210e752f 1627 pos = *vmotion (PT, - (height / 2), w);
a2889657
JB
1628 try_window (window, pos.bufpos);
1629
1630 startp = marker_position (w->start);
ca26e1c8 1631 w->start_at_line_beg
b16234d8 1632 = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
a2889657
JB
1633
1634done:
e481f960 1635 if ((update_mode_line
aa6d10fa
RS
1636 /* If window not full width, must redo its mode line
1637 if the window to its side is being redone */
1638 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
155ef550
KH
1639 || INTEGERP (w->base_line_pos)
1640 || (!NILP (w->column_number_displayed)
1641 && XFASTINT (w->column_number_displayed) != current_column ()))
a2889657
JB
1642 && height != XFASTINT (w->height))
1643 display_mode_line (w);
aa6d10fa
RS
1644 if (! line_number_displayed
1645 && ! BUFFERP (w->base_line_pos))
1646 {
1647 w->base_line_pos = Qnil;
1648 w->base_line_number = Qnil;
1649 }
a2889657 1650
7ce2c095 1651 /* When we reach a frame's selected window, redo the frame's menu bar. */
e481f960 1652 if (update_mode_line
76412d64
RS
1653#ifdef USE_X_TOOLKIT
1654 && FRAME_EXTERNAL_MENU_BAR (f)
1655#else
7ce2c095 1656 && FRAME_MENU_BAR_LINES (f) > 0
76412d64 1657#endif
7ce2c095
RS
1658 && EQ (FRAME_SELECTED_WINDOW (f), window))
1659 display_menu_bar (w);
1660
88f22aff
JB
1661 finish_scroll_bars:
1662 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
30c566e4 1663 {
b1d1124b 1664 int start, end, whole;
30c566e4 1665
b1d1124b 1666 /* Calculate the start and end positions for the current window.
3505ea70
JB
1667 At some point, it would be nice to choose between scrollbars
1668 which reflect the whole buffer size, with special markers
1669 indicating narrowing, and scrollbars which reflect only the
1670 visible region.
1671
b1d1124b
JB
1672 Note that minibuffers sometimes aren't displaying any text. */
1673 if (! MINI_WINDOW_P (w)
1674 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1675 {
8a9311d7 1676 whole = ZV - BEGV;
4d641a15 1677 start = marker_position (w->start) - BEGV;
b1d1124b
JB
1678 /* I don't think this is guaranteed to be right. For the
1679 moment, we'll pretend it is. */
85f26be9 1680 end = (Z - XINT (w->window_end_pos)) - BEGV;
3505ea70
JB
1681
1682 if (end < start) end = start;
8a9311d7 1683 if (whole < (end - start)) whole = end - start;
b1d1124b
JB
1684 }
1685 else
1686 start = end = whole = 0;
30c566e4 1687
88f22aff 1688 /* Indicate what this scroll bar ought to be displaying now. */
7eb9ba41 1689 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
30c566e4 1690
88f22aff 1691 /* Note that we actually used the scroll bar attached to this window,
30c566e4 1692 so it shouldn't be deleted at the end of redisplay. */
88f22aff 1693 (*redeem_scroll_bar_hook) (w);
30c566e4 1694 }
b1d1124b 1695
f67a0f51 1696 BUF_PT (current_buffer) = opoint;
e481f960 1697 if (update_mode_line)
f72df6ac 1698 set_buffer_internal_1 (old);
e481f960
RS
1699 else
1700 set_buffer_temp (old);
f67a0f51 1701 BUF_PT (current_buffer) = lpoint;
a2889657
JB
1702}
1703\f
1704/* Do full redisplay on one window, starting at position `pos'. */
1705
1706static void
1707try_window (window, pos)
1708 Lisp_Object window;
1709 register int pos;
1710{
1711 register struct window *w = XWINDOW (window);
1712 register int height = window_internal_height (w);
1713 register int vpos = XFASTINT (w->top);
1714 register int last_text_vpos = vpos;
1715 int tab_offset = pos_tab_offset (w, pos);
44fa5b1e 1716 FRAME_PTR f = XFRAME (w->frame);
b1d1124b 1717 int width = window_internal_width (w) - 1;
a2889657
JB
1718 struct position val;
1719
1720 Fset_marker (w->start, make_number (pos), Qnil);
1721 cursor_vpos = -1;
1722 overlay_arrow_seen = 0;
ca26e1c8 1723 zv_strings_seen = 0;
a2889657
JB
1724 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1725
1726 while (--height >= 0)
1727 {
1728 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1729 tab_offset += width;
2b050fec
RS
1730 /* For the first line displayed, display_text_line
1731 subtracts the prompt width from the tab offset.
1732 But it does not affect the value of our variable tab_offset.
1733 So we do the subtraction again,
1734 for the sake of continuation lines of that first line. */
1735 if (MINI_WINDOW_P (w) && vpos == XFASTINT (w->top))
1736 tab_offset -= minibuf_prompt_width;
1737
a2889657
JB
1738 if (val.vpos) tab_offset = 0;
1739 vpos++;
1740 if (pos != val.bufpos)
642eefc6
RS
1741 {
1742 int invis = 0;
e885523c 1743#ifdef USE_TEXT_PROPERTIES
642eefc6
RS
1744 Lisp_Object invis_prop;
1745 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
1746 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
e885523c 1747#endif
642eefc6
RS
1748
1749 last_text_vpos
1750 /* Next line, unless prev line ended in end of buffer with no cr */
1751 = vpos - (val.vpos
1752 && (FETCH_CHAR (val.bufpos - 1) != '\n' || invis));
1753 }
a2889657
JB
1754 pos = val.bufpos;
1755 }
1756
1757 /* If last line is continued in middle of character,
44fa5b1e 1758 include the split character in the text considered on the frame */
a2889657
JB
1759 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1760 pos++;
1761
44fa5b1e 1762 /* If bottom just moved off end of frame, change mode line percentage. */
a2889657
JB
1763 if (XFASTINT (w->window_end_pos) == 0
1764 && Z != pos)
1765 w->update_mode_line = Qt;
1766
44fa5b1e 1767 /* Say where last char on frame will be, once redisplay is finished. */
c2213350
KH
1768 XSETFASTINT (w->window_end_pos, Z - pos);
1769 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
a2889657
JB
1770 /* But that is not valid info until redisplay finishes. */
1771 w->window_end_valid = Qnil;
1772}
1773\f
1774/* Try to redisplay when buffer is modified locally,
1775 computing insert/delete line to preserve text outside
1776 the bounds of the changes.
1777 Return 1 if successful, 0 if if cannot tell what to do,
1778 or -1 to tell caller to find a new window start,
1779 or -2 to tell caller to do normal redisplay with same window start. */
1780
1781static int
1782try_window_id (window)
1783 Lisp_Object window;
1784{
1785 int pos;
1786 register struct window *w = XWINDOW (window);
1787 register int height = window_internal_height (w);
44fa5b1e 1788 FRAME_PTR f = XFRAME (w->frame);
a2889657
JB
1789 int top = XFASTINT (w->top);
1790 int start = marker_position (w->start);
b1d1124b 1791 int width = window_internal_width (w) - 1;
a2889657
JB
1792 int hscroll = XINT (w->hscroll);
1793 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
ca26e1c8 1794 int did_motion;
a2889657
JB
1795 register int vpos;
1796 register int i, tem;
1797 int last_text_vpos = 0;
1798 int stop_vpos;
e24c997d
KH
1799 int selective = (INTEGERP (current_buffer->selective_display)
1800 ? XINT (current_buffer->selective_display)
1801 : !NILP (current_buffer->selective_display) ? -1 : 0);
a2889657
JB
1802
1803 struct position val, bp, ep, xp, pp;
1804 int scroll_amount = 0;
1805 int delta;
1806 int tab_offset, epto;
1807
1808 if (GPT - BEG < beg_unchanged)
1809 beg_unchanged = GPT - BEG;
1810 if (Z - GPT < end_unchanged)
1811 end_unchanged = Z - GPT;
1812
6a1dc7ac 1813 if (beg_unchanged + BEG < start)
a2889657
JB
1814 return 0; /* Give up if changes go above top of window */
1815
1816 /* Find position before which nothing is changed. */
ca26e1c8 1817 bp = *compute_motion (start, 0, lmargin, 0,
632ab665 1818 min (ZV, beg_unchanged + BEG), height, 0,
e37f06d7 1819 width, hscroll, pos_tab_offset (w, start), w);
a2889657 1820 if (bp.vpos >= height)
6e8290aa 1821 {
632ab665 1822 if (PT < bp.bufpos)
6e8290aa 1823 {
44fa5b1e
JB
1824 /* All changes are below the frame, and point is on the frame.
1825 We don't need to change the frame at all.
6e8290aa
JB
1826 But we need to update window_end_pos to account for
1827 any change in buffer size. */
ca26e1c8 1828 bp = *compute_motion (start, 0, lmargin, 0,
f7be7f78 1829 Z, height, 0,
e37f06d7 1830 width, hscroll, pos_tab_offset (w, start), w);
c2213350
KH
1831 XSETFASTINT (w->window_end_vpos, height);
1832 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
4d641a15 1833 goto findpoint;
6e8290aa
JB
1834 }
1835 return 0;
1836 }
a2889657
JB
1837
1838 vpos = bp.vpos;
1839
44fa5b1e 1840 /* Find beginning of that frame line. Must display from there. */
210e752f 1841 bp = *vmotion (bp.bufpos, 0, w);
a2889657
JB
1842
1843 pos = bp.bufpos;
1844 val.hpos = lmargin;
1845 if (pos < start)
1846 return -1;
1847
ca26e1c8 1848 did_motion = 0;
a2889657 1849 /* If about to start displaying at the beginning of a continuation line,
44fa5b1e 1850 really start with previous frame line, in case it was not
a2889657 1851 continued when last redisplayed */
05ba02eb
JB
1852 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
1853 ||
1854 /* Likewise if we have to worry about selective display. */
9f412332 1855 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
a2889657 1856 {
210e752f 1857 bp = *vmotion (bp.bufpos, -1, w);
a2889657
JB
1858 --vpos;
1859 pos = bp.bufpos;
1860 }
1861
1862 if (bp.contin && bp.hpos != lmargin)
1863 {
1864 val.hpos = bp.prevhpos - width + lmargin;
ca26e1c8 1865 did_motion = 1;
a2889657
JB
1866 pos--;
1867 }
1868
1869 bp.vpos = vpos;
1870
1871 /* Find first visible newline after which no more is changed. */
1872 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
9f412332
KH
1873 if (selective > 0)
1874 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
a2889657
JB
1875 tem = find_next_newline (tem, 1);
1876
1877 /* Compute the cursor position after that newline. */
ca26e1c8 1878 ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem,
a2889657 1879 height, - (1 << (SHORTBITS - 1)),
e37f06d7 1880 width, hscroll, pos_tab_offset (w, bp.bufpos), w);
a2889657 1881
44fa5b1e
JB
1882 /* If changes reach past the text available on the frame,
1883 just display rest of frame. */
a2889657
JB
1884 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
1885 stop_vpos = height;
1886 else
1887 stop_vpos = ep.vpos;
1888
1889 /* If no newline before ep, the line ep is on includes some changes
1890 that must be displayed. Make sure we don't stop before it. */
1891 /* Also, if changes reach all the way until ep.bufpos,
1892 it is possible that something was deleted after the
1893 newline before it, so the following line must be redrawn. */
1894 if (stop_vpos == ep.vpos
1895 && (ep.bufpos == BEGV
1896 || FETCH_CHAR (ep.bufpos - 1) != '\n'
1897 || ep.bufpos == Z - end_unchanged))
1898 stop_vpos = ep.vpos + 1;
1899
1900 cursor_vpos = -1;
1901 overlay_arrow_seen = 0;
ca26e1c8 1902 zv_strings_seen = 0;
a2889657
JB
1903
1904 /* If changes do not reach to bottom of window,
1905 figure out how much to scroll the rest of the window */
1906 if (stop_vpos < height)
1907 {
1908 /* Now determine how far up or down the rest of the window has moved */
1909 epto = pos_tab_offset (w, ep.bufpos);
ca26e1c8 1910 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
a2889657 1911 Z - XFASTINT (w->window_end_pos),
e37f06d7 1912 10000, 0, width, hscroll, epto, w);
a2889657
JB
1913 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
1914
44fa5b1e 1915 /* Is everything on frame below the changes whitespace?
a2889657
JB
1916 If so, no scrolling is really necessary. */
1917 for (i = ep.bufpos; i < xp.bufpos; i++)
1918 {
1919 tem = FETCH_CHAR (i);
1920 if (tem != ' ' && tem != '\n' && tem != '\t')
1921 break;
1922 }
1923 if (i == xp.bufpos)
1924 return -2;
1925
e8e536a9
KH
1926 XSETFASTINT (w->window_end_vpos,
1927 XFASTINT (w->window_end_vpos) + scroll_amount);
a2889657 1928
44fa5b1e 1929 /* Before doing any scrolling, verify that point will be on frame. */
ae3b1442 1930 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height))
a2889657 1931 {
ae3b1442 1932 if (PT <= xp.bufpos)
a2889657 1933 {
ca26e1c8 1934 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
ae3b1442 1935 PT, height, - (1 << (SHORTBITS - 1)),
e37f06d7 1936 width, hscroll, epto, w);
a2889657
JB
1937 }
1938 else
1939 {
ca26e1c8 1940 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1,
ae3b1442 1941 PT, height, - (1 << (SHORTBITS - 1)),
e37f06d7
KH
1942 width, hscroll,
1943 pos_tab_offset (w, xp.bufpos), w);
a2889657 1944 }
ae3b1442 1945 if (pp.bufpos < PT || pp.vpos == height)
a2889657
JB
1946 return 0;
1947 cursor_vpos = pp.vpos + top;
210e752f 1948 cursor_hpos = XFASTINT (w->left) + minmax (0, pp.hpos, width);
a2889657
JB
1949 }
1950
1951 if (stop_vpos - scroll_amount >= height
1952 || ep.bufpos == xp.bufpos)
1953 {
1954 if (scroll_amount < 0)
1955 stop_vpos -= scroll_amount;
1956 scroll_amount = 0;
1957 /* In this path, we have altered window_end_vpos
1958 and not left it negative.
1959 We must make sure that, in case display is preempted
44fa5b1e 1960 before the frame changes to reflect what we do here,
a2889657 1961 further updates will not come to try_window_id
44fa5b1e 1962 and assume the frame and window_end_vpos match. */
a2889657
JB
1963 blank_end_of_window = 1;
1964 }
1965 else if (!scroll_amount)
0d231165
RS
1966 {
1967 /* Even if we don't need to scroll, we must adjust the
1968 charstarts of subsequent lines (that we won't redisplay)
1969 according to the amount of text inserted or deleted. */
1970 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1971 int adjust = ep.bufpos - oldpos;
1972 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
1973 }
a2889657
JB
1974 else if (bp.bufpos == Z - end_unchanged)
1975 {
1976 /* If reprinting everything is nearly as fast as scrolling,
1977 don't bother scrolling. Can happen if lines are short. */
44fa5b1e 1978 if (scroll_cost (f, bp.vpos + top - scroll_amount,
a2889657
JB
1979 top + height - max (0, scroll_amount),
1980 scroll_amount)
1981 > xp.bufpos - bp.bufpos - 20)
1982 /* Return "try normal display with same window-start."
1983 Too bad we can't prevent further scroll-thinking. */
1984 return -2;
1985 /* If pure deletion, scroll up as many lines as possible.
1986 In common case of killing a line, this can save the
1987 following line from being overwritten by scrolling
1988 and therefore having to be redrawn. */
44fa5b1e 1989 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
d1cb44a4
RS
1990 top + height - max (0, scroll_amount),
1991 scroll_amount, bp.bufpos);
d2f84654
RS
1992 if (!tem)
1993 stop_vpos = height;
1994 else
1995 {
1996 /* scroll_frame_lines did not properly adjust subsequent
1997 lines' charstarts in the case where the text of the
1998 screen line at bp.vpos has changed.
1999 (This can happen in a deletion that ends in mid-line.)
2000 To adjust properly, we need to make things constent at
2001 the position ep.
2002 So do a second adjust to make that happen.
2003 Note that stop_vpos >= ep.vpos, so it is sufficient
2004 to update the charstarts for lines at ep.vpos and below. */
2005 int oldstart
2006 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2007 adjust_window_charstarts (w, ep.vpos + top - 1,
2008 ep.bufpos - oldstart);
2009 }
a2889657
JB
2010 }
2011 else if (scroll_amount)
2012 {
2013 /* If reprinting everything is nearly as fast as scrolling,
2014 don't bother scrolling. Can happen if lines are short. */
2015 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2016 overestimate of cost of reprinting, since xp.bufpos
2017 would end up below the bottom of the window. */
44fa5b1e 2018 if (scroll_cost (f, ep.vpos + top - scroll_amount,
a2889657
JB
2019 top + height - max (0, scroll_amount),
2020 scroll_amount)
2021 > xp.bufpos - ep.bufpos - 20)
2022 /* Return "try normal display with same window-start."
2023 Too bad we can't prevent further scroll-thinking. */
2024 return -2;
44fa5b1e 2025 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
a2889657 2026 top + height - max (0, scroll_amount),
d1cb44a4 2027 scroll_amount, ep.bufpos);
a2889657
JB
2028 if (!tem) stop_vpos = height;
2029 }
2030 }
2031
2032 /* In any case, do not display past bottom of window */
2033 if (stop_vpos >= height)
2034 {
2035 stop_vpos = height;
2036 scroll_amount = 0;
2037 }
2038
2039 /* Handle case where pos is before w->start --
2040 can happen if part of line had been clipped and is not clipped now */
2041 if (vpos == 0 && pos < marker_position (w->start))
2042 Fset_marker (w->start, make_number (pos), Qnil);
2043
2044 /* Redisplay the lines where the text was changed */
2045 last_text_vpos = vpos;
2046 tab_offset = pos_tab_offset (w, pos);
2047 /* If we are starting display in mid-character, correct tab_offset
2048 to account for passing the line that that character really starts in. */
2049 if (val.hpos < lmargin)
2050 tab_offset += width;
2051 while (vpos < stop_vpos)
2052 {
2053 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2054 tab_offset += width;
2055 if (val.vpos) tab_offset = 0;
2056 if (pos != val.bufpos)
2057 last_text_vpos
2058 /* Next line, unless prev line ended in end of buffer with no cr */
2059 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
2060 pos = val.bufpos;
2061 }
2062
2063 /* There are two cases:
2064 1) we have displayed down to the bottom of the window
2065 2) we have scrolled lines below stop_vpos by scroll_amount */
2066
2067 if (vpos == height)
2068 {
2069 /* If last line is continued in middle of character,
44fa5b1e 2070 include the split character in the text considered on the frame */
a2889657
JB
2071 if (val.hpos < lmargin)
2072 val.bufpos++;
c2213350
KH
2073 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2074 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
a2889657
JB
2075 }
2076
2077 /* If scrolling made blank lines at window bottom,
2078 redisplay to fill those lines */
2079 if (scroll_amount < 0)
2080 {
2081 /* Don't consider these lines for general-purpose scrolling.
2082 That will save time in the scrolling computation. */
44fa5b1e 2083 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
a2889657
JB
2084 vpos = xp.vpos;
2085 pos = xp.bufpos;
2086 val.hpos = lmargin;
2087 if (pos == ZV)
2088 vpos = height + scroll_amount;
2089 else if (xp.contin && xp.hpos != lmargin)
2090 {
2091 val.hpos = xp.prevhpos - width + lmargin;
2092 pos--;
2093 }
2094
2095 blank_end_of_window = 1;
2096 tab_offset = pos_tab_offset (w, pos);
2097 /* If we are starting display in mid-character, correct tab_offset
2098 to account for passing the line that that character starts in. */
2099 if (val.hpos < lmargin)
2100 tab_offset += width;
2101
2102 while (vpos < height)
2103 {
2104 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2105 tab_offset += width;
2106 if (val.vpos) tab_offset = 0;
2107 pos = val.bufpos;
2108 }
2109
2110 /* Here is a case where display_text_line sets cursor_vpos wrong.
2111 Make it be fixed up, below. */
2112 if (xp.bufpos == ZV
ae3b1442 2113 && xp.bufpos == PT)
a2889657
JB
2114 cursor_vpos = -1;
2115 }
2116
44fa5b1e 2117 /* If bottom just moved off end of frame, change mode line percentage. */
a2889657
JB
2118 if (XFASTINT (w->window_end_pos) == 0
2119 && Z != val.bufpos)
2120 w->update_mode_line = Qt;
2121
2122 /* Attempt to adjust end-of-text positions to new bottom line */
2123 if (scroll_amount)
2124 {
2125 delta = height - xp.vpos;
2126 if (delta < 0
2127 || (delta > 0 && xp.bufpos <= ZV)
2128 || (delta == 0 && xp.hpos))
2129 {
210e752f 2130 val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w);
c2213350 2131 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
e8e536a9
KH
2132 XSETFASTINT (w->window_end_vpos,
2133 XFASTINT (w->window_end_vpos) + val.vpos);
a2889657
JB
2134 }
2135 }
2136
2137 w->window_end_valid = Qnil;
2138
2139 /* If point was not in a line that was displayed, find it */
2140 if (cursor_vpos < 0)
2141 {
4d641a15 2142 findpoint:
ca26e1c8 2143 val = *compute_motion (start, 0, lmargin, 0, PT, 10000, 10000,
e37f06d7 2144 width, hscroll, pos_tab_offset (w, start), w);
44fa5b1e 2145 /* Admit failure if point is off frame now */
a2889657
JB
2146 if (val.vpos >= height)
2147 {
2148 for (vpos = 0; vpos < height; vpos++)
44fa5b1e 2149 cancel_line (vpos + top, f);
a2889657
JB
2150 return 0;
2151 }
2152 cursor_vpos = val.vpos + top;
210e752f 2153 cursor_hpos = XFASTINT (w->left) + minmax (0, val.hpos, width);
a2889657
JB
2154 }
2155
210e752f 2156 FRAME_CURSOR_X (f) = cursor_hpos;
44fa5b1e 2157 FRAME_CURSOR_Y (f) = cursor_vpos;
a2889657
JB
2158
2159 if (debug_end_pos)
2160 {
ca26e1c8 2161 val = *compute_motion (start, 0, lmargin, 0, ZV,
a2889657 2162 height, - (1 << (SHORTBITS - 1)),
e37f06d7 2163 width, hscroll, pos_tab_offset (w, start), w);
a2889657
JB
2164 if (val.vpos != XFASTINT (w->window_end_vpos))
2165 abort ();
2166 if (XFASTINT (w->window_end_pos)
2167 != Z - val.bufpos)
2168 abort ();
2169 }
2170
2171 return 1;
2172}
2173\f
31b24551
JB
2174/* Mark a section of BUF as modified, but only for the sake of redisplay.
2175 This is useful for recording changes to overlays.
2176
2177 We increment the buffer's modification timestamp and set the
2178 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
2179 as if the region of text between START and END had been modified;
2180 the redisplay code will check this against the windows' timestamps,
2181 and redraw the appropriate area of the buffer.
2182
2183 However, if the buffer is unmodified, we bump the last-save
2184 timestamp as well, so that incrementing the timestamp doesn't fool
2185 Emacs into thinking that the buffer's text has been modified.
2186
2187 Tweaking the timestamps shouldn't hurt the first-modification
2188 timestamps recorded in the undo records; those values aren't
2189 written until just before a real text modification is made, so they
2190 will never catch the timestamp value just before this function gets
2191 called. */
2192
2193void
2194redisplay_region (buf, start, end)
2195 struct buffer *buf;
2196 int start, end;
2197{
2198 if (start == end)
2199 return;
2200
2201 if (start > end)
2202 {
2203 int temp = start;
2204 start = end; end = temp;
2205 }
2206
70bcb498
RS
2207 /* If this is a buffer not in the selected window,
2208 we must do other windows. */
2209 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2210 windows_or_buffers_changed = 1;
99b9e975
RS
2211 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2212 else if (buf != current_buffer)
2213 windows_or_buffers_changed = 1;
70bcb498
RS
2214 /* If multiple windows show this buffer, we must do other windows. */
2215 else if (buffer_shared > 1)
31b24551
JB
2216 windows_or_buffers_changed = 1;
2217 else
2218 {
2219 if (unchanged_modified == MODIFF)
2220 {
2221 beg_unchanged = start - BEG;
2222 end_unchanged = Z - end;
2223 }
2224 else
2225 {
2226 if (Z - end < end_unchanged)
2227 end_unchanged = Z - end;
2228 if (start - BEG < beg_unchanged)
2229 beg_unchanged = start - BEG;
2230 }
2231 }
2232
2233 /* Increment the buffer's time stamp, but also increment the save
42640f83
RS
2234 and autosave timestamps, so as not to screw up that timekeeping. */
2235 if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf))
2236 BUF_SAVE_MODIFF (buf)++;
31b24551
JB
2237 if (BUF_MODIFF (buf) == buf->auto_save_modified)
2238 buf->auto_save_modified++;
2239
2240 BUF_MODIFF (buf) ++;
2241}
2242
2243\f
278feba9 2244/* Copy LEN glyphs starting address FROM to the rope TO.
f7430cb6 2245 But don't actually copy the parts that would come in before S.
278feba9
RS
2246 Value is TO, advanced past the copied data.
2247 F is the frame we are displaying in. */
a2889657 2248
278feba9
RS
2249static GLYPH *
2250copy_part_of_rope (f, to, s, from, len, face)
2251 FRAME_PTR f;
2252 register GLYPH *to; /* Copy to here. */
a2889657 2253 register GLYPH *s; /* Starting point. */
278feba9
RS
2254 Lisp_Object *from; /* Data to copy. */
2255 int len;
1c2250c2 2256 int face; /* Face to apply to glyphs which don't specify one. */
a2889657 2257{
278feba9
RS
2258 int n = len;
2259 register Lisp_Object *fp = from;
2260 /* These cache the results of the last call to compute_glyph_face. */
2261 int last_code = -1;
2262 int last_merged = 0;
c581d710 2263
87485d6f 2264#ifdef HAVE_FACES
4cdc65eb
KH
2265 if (! FRAME_TERMCAP_P (f))
2266 while (n--)
2267 {
dedd1182 2268 int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
4cdc65eb
KH
2269 int facecode;
2270
2271 if (FAST_GLYPH_FACE (glyph) == 0)
2272 /* If GLYPH has no face code, use FACE. */
2273 facecode = face;
2274 else if (FAST_GLYPH_FACE (glyph) == last_code)
2275 /* If it's same as previous glyph, use same result. */
2276 facecode = last_merged;
2277 else
2278 {
2279 /* Merge this glyph's face and remember the result. */
2280 last_code = FAST_GLYPH_FACE (glyph);
2281 last_merged = facecode = compute_glyph_face (f, last_code, face);
2282 }
b2a76982 2283
4cdc65eb
KH
2284 if (to >= s)
2285 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
2286 ++to;
2287 ++fp;
2288 }
2289 else
2290#endif
2291 while (n--)
2292 {
dedd1182 2293 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
4cdc65eb
KH
2294 ++to;
2295 ++fp;
2296 }
278feba9 2297 return to;
c581d710
RS
2298}
2299
278feba9
RS
2300/* Correct a glyph by replacing its specified user-level face code
2301 with a displayable computed face code. */
c581d710 2302
278feba9 2303static GLYPH
659a218f 2304fix_glyph (f, glyph, cface)
278feba9
RS
2305 FRAME_PTR f;
2306 GLYPH glyph;
659a218f 2307 int cface;
c581d710 2308{
87485d6f 2309#ifdef HAVE_FACES
659a218f
KH
2310 if (! FRAME_TERMCAP_P (f))
2311 {
2312 if (FAST_GLYPH_FACE (glyph) != 0)
2313 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2314 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2315 }
4cdc65eb
KH
2316#endif
2317 return glyph;
a2889657
JB
2318}
2319\f
f4faa47c
JB
2320/* Display one line of window W, starting at position START in W's buffer.
2321
2322 Display starting at horizontal position HPOS, expressed relative to
2323 W's left edge. In situations where the text at START shouldn't
2324 start at the left margin (i.e. when the window is hscrolled, or
2325 we're continuing a line which left off in the midst of a
2326 multi-column character), HPOS should be negative; we throw away
2327 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2328 account.
a2889657
JB
2329
2330 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2331
f4faa47c
JB
2332 Display on position VPOS on the frame. It is origin 0, relative to
2333 the top of the frame, not W.
a2889657
JB
2334
2335 Returns a STRUCT POSITION giving character to start next line with
2336 and where to display it, including a zero or negative hpos.
2337 The vpos field is not really a vpos; it is 1 unless the line is continued */
2338
2339struct position val_display_text_line;
2340
2341static struct position *
2342display_text_line (w, start, vpos, hpos, taboffset)
2343 struct window *w;
2344 int start;
2345 int vpos;
2346 int hpos;
2347 int taboffset;
2348{
2349 register int pos = start;
2350 register int c;
2351 register GLYPH *p1;
a2889657
JB
2352 register int pause;
2353 register unsigned char *p;
2354 GLYPH *endp;
d2f84654 2355 register GLYPH *leftmargin;
ca26e1c8 2356 register GLYPH *p1prev;
efc63ef0 2357 register GLYPH *p1start;
ca26e1c8 2358 int prevpos;
efc63ef0 2359 int *charstart;
44fa5b1e 2360 FRAME_PTR f = XFRAME (w->frame);
a2889657 2361 int tab_width = XINT (current_buffer->tab_width);
265a9e55 2362 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
b1d1124b 2363 int width = window_internal_width (w) - 1;
a2889657
JB
2364 struct position val;
2365 int lastpos;
2366 int invis;
642eefc6
RS
2367 int last_invis_skip = 0;
2368 Lisp_Object last_invis_prop;
a2889657 2369 int hscroll = XINT (w->hscroll);
d2f84654
RS
2370 int truncate = (hscroll
2371 || (truncate_partial_width_windows
2372 && XFASTINT (w->width) < FRAME_WIDTH (f))
2373 || !NILP (current_buffer->truncate_lines));
bd66d1ba
RS
2374
2375 /* 1 if we should highlight the region. */
2376 int highlight_region
2377 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
2378 int region_beg, region_end;
2379
e24c997d
KH
2380 int selective = (INTEGERP (current_buffer->selective_display)
2381 ? XINT (current_buffer->selective_display)
2382 : !NILP (current_buffer->selective_display) ? -1 : 0);
44fa5b1e 2383 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
a2889657 2384 register struct Lisp_Vector *dp = window_display_table (w);
68a37fa8
RS
2385
2386 Lisp_Object default_invis_vector[3];
642eefc6
RS
2387 /* Number of characters of ellipsis to display after an invisible line
2388 if it calls for an ellipsis.
2389 Note that this value can be nonzero regardless of whether
2390 selective display is enabled--you must check that separately. */
a2889657 2391 int selective_rlen
642eefc6 2392 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
68a37fa8 2393 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
642eefc6 2394 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
68a37fa8
RS
2395 /* This is the sequence of Lisp objects to display
2396 when there are invisible lines. */
2397 Lisp_Object *invis_vector_contents
e24c997d 2398 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
68a37fa8
RS
2399 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2400 : default_invis_vector);
2401
e24c997d 2402 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
278feba9 2403 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
e24c997d 2404 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
278feba9 2405 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
a2889657 2406
31b24551
JB
2407 /* The next buffer location at which the face should change, due
2408 to overlays or text property changes. */
2409 int next_face_change;
2410
ca26e1c8
KH
2411 /* The next location where the `invisible' property changes, or an
2412 overlay starts or ends. */
2413 int next_boundary;
2414
31b24551 2415 /* The face we're currently using. */
1c2250c2 2416 int current_face = 0;
efc63ef0 2417 int i;
31b24551 2418
c2213350 2419 XSETFASTINT (default_invis_vector[2], '.');
68a37fa8
RS
2420 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2421
a2889657 2422 hpos += XFASTINT (w->left);
44fa5b1e 2423 get_display_line (f, vpos, XFASTINT (w->left));
54ff581a 2424 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
a2889657 2425
bd66d1ba 2426 /* Show where to highlight the region. */
1613b757 2427 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
fba9ce76
RS
2428 /* Maybe highlight only in selected window. */
2429 && (highlight_nonselected_windows
6f139a45 2430 || w == XWINDOW (selected_window)))
bd66d1ba
RS
2431 {
2432 region_beg = marker_position (current_buffer->mark);
2433 if (PT < region_beg)
2434 {
2435 region_end = region_beg;
2436 region_beg = PT;
2437 }
2438 else
2439 region_end = PT;
2440 w->region_showing = Qt;
2441 }
2442 else
2443 region_beg = region_end = -1;
2444
f4faa47c 2445 if (MINI_WINDOW_P (w)
ca26e1c8 2446 && start == BEG
a2889657
JB
2447 && vpos == XFASTINT (w->top))
2448 {
8c5b6a0a 2449 if (! NILP (minibuf_prompt))
f7b4b63a
KH
2450 {
2451 minibuf_prompt_width
8c5b6a0a
KH
2452 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2453 XSTRING (minibuf_prompt)->size, hpos,
ce006f69
RS
2454 /* Display a space if we truncate. */
2455 ' ',
2456 1, -1,
2457 /* Truncate the prompt a little before the
2458 margin, so user input can at least start
2459 on the first line. */
2460 w->width > 10 ? w->width - 4 : -1)
f7b4b63a
KH
2461 - hpos);
2462 hpos += minibuf_prompt_width;
2b050fec 2463 taboffset -= minibuf_prompt_width;
f7b4b63a
KH
2464 }
2465 else
2466 minibuf_prompt_width = 0;
a2889657
JB
2467 }
2468
f4faa47c
JB
2469 /* If we're hscrolled at all, use compute_motion to skip over any
2470 text off the left edge of the window. compute_motion may know
2471 tricks to do this faster than we can. */
2472 if (hpos < 0)
2473 {
2474 struct position *left_edge
ca26e1c8
KH
2475 = compute_motion (pos, vpos, hpos, 0,
2476 ZV, vpos, 0,
f4faa47c
JB
2477 width, hscroll, taboffset, w);
2478
2479 /* Retrieve the buffer position and column provided by
2480 compute_motion. We can't assume that the column will be
2481 zero, because you may have multi-column characters crossing
2482 the left margin.
2483
2484 compute_motion may have moved us past the screen position we
2485 requested, if we hit a multi-column character, or the end of
2486 the line. If so, back up. */
2487 if (left_edge->vpos > vpos
2488 || left_edge->hpos > 0)
2489 {
2490 pos = left_edge->bufpos - 1;
2491 hpos = left_edge->prevhpos;
2492 }
2493 else
2494 {
2495 pos = left_edge->bufpos;
2496 hpos = left_edge->hpos;
2497 }
2498 }
2499
2500 desired_glyphs->bufp[vpos] = start;
a2889657 2501 p1 = desired_glyphs->glyphs[vpos] + hpos;
efc63ef0
RS
2502 p1start = p1;
2503 charstart = desired_glyphs->charstarts[vpos] + hpos;
2504 /* In case we don't ever write anything into it... */
a007eef6 2505 desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1;
d2f84654
RS
2506 leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2507 endp = leftmargin + width;
a2889657 2508
1c2250c2
JB
2509 /* Arrange the overlays nicely for our purposes. Usually, we call
2510 display_text_line on only one line at a time, in which case this
2511 can't really hurt too much, or we call it on lines which appear
2512 one after another in the buffer, in which case all calls to
2513 recenter_overlay_lists but the first will be pretty cheap. */
2514 recenter_overlay_lists (current_buffer, pos);
2515
a2889657
JB
2516 /* Loop generating characters.
2517 Stop at end of buffer, before newline,
31b24551
JB
2518 if reach or pass continuation column,
2519 or at face change. */
a2889657 2520 pause = pos;
31b24551 2521 next_face_change = pos;
ca26e1c8
KH
2522 next_boundary = pos;
2523 p1prev = p1;
2524 prevpos = pos;
85bcef6c 2525 while (1)
a2889657 2526 {
31b24551 2527 if (pos >= pause)
a2889657 2528 {
ca26e1c8 2529 while (pos == next_boundary)
a2889657 2530 {
ca26e1c8
KH
2531 Lisp_Object position, limit, prop, ww;
2532
2533 /* Display the overlay strings here, unless we're at ZV
2534 and have already displayed the appropriate strings
2535 on an earlier line. */
2536 if (pos < ZV || !zv_strings_seen++)
2537 {
2538 int ovlen;
2539 char *ovstr;
2540 ovlen = overlay_strings (pos, w, &ovstr);
2541 for (; ovlen; ovlen--, ovstr++)
2542 {
2543 if (p1 >= leftmargin && p1 < endp)
2544 *p1 = MAKE_GLYPH (f, *ovstr, current_face);
2545 p1++;
2546 }
2547 }
2548
2549 /* Did we reach point? Record the cursor location. */
2550 if (pos == PT && cursor_vpos < 0)
2551 {
2552 cursor_vpos = vpos;
2553 cursor_hpos = p1 - leftmargin;
2554 }
2555
2556 if (pos >= ZV)
2557 break;
a2889657 2558
c2213350 2559 XSETFASTINT (position, pos);
ca26e1c8
KH
2560 limit = Fnext_overlay_change (position);
2561#ifdef USE_TEXT_PROPERTIES
dfabd9a0
RS
2562 /* This is just an estimate to give reasonable
2563 performance; nothing should go wrong if it is too small. */
fe3d6921 2564 if (XFASTINT (limit) > pos + 50)
c2213350 2565 XSETFASTINT (limit, pos + 50);
ca26e1c8
KH
2566 limit = Fnext_single_property_change (position, Qinvisible,
2567 Fcurrent_buffer (), limit);
2568#endif
2569 next_boundary = XFASTINT (limit);
2570 /* if the `invisible' property is set, we can skip to
2571 the next property change. */
2572 XSETWINDOW (ww, w);
2573 prop = Fget_char_property (position, Qinvisible, ww);
642eefc6 2574 if (TEXT_PROP_MEANS_INVISIBLE (prop))
dfabd9a0 2575 {
ca26e1c8 2576 if (pos < PT && next_boundary >= PT)
dfabd9a0
RS
2577 {
2578 cursor_vpos = vpos;
d2f84654 2579 cursor_hpos = p1 - leftmargin;
dfabd9a0 2580 }
ca26e1c8 2581 pos = next_boundary;
642eefc6
RS
2582 last_invis_skip = pos;
2583 last_invis_prop = prop;
dfabd9a0 2584 }
b0a0fbda 2585 }
ca26e1c8
KH
2586
2587 /* Did we reach point? Record the cursor location. */
2588 if (pos == PT && cursor_vpos < 0)
2589 {
2590 cursor_vpos = vpos;
2591 cursor_hpos = p1 - leftmargin;
2592 }
2593
2594 /* Did we hit the end of the visible region of the buffer?
2595 Stop here. */
2596 if (pos >= ZV)
b0a0fbda 2597 break;
b0a0fbda 2598
87485d6f 2599#ifdef HAVE_FACES
31b24551
JB
2600 /* Did we hit a face change? Figure out what face we should
2601 use now. We also hit this the first time through the
2602 loop, to see what face we should start with. */
b0a0fbda 2603 if (pos >= next_face_change && FRAME_X_P (f))
bd66d1ba
RS
2604 current_face = compute_char_face (f, w, pos,
2605 region_beg, region_end,
efc63ef0 2606 &next_face_change, pos + 50, 0);
9dbd4b48 2607#endif
31b24551 2608
ca26e1c8 2609 pause = ZV;
1c2250c2 2610
ca26e1c8
KH
2611 if (pos < next_boundary && next_boundary < pause)
2612 pause = next_boundary;
1c2250c2
JB
2613 if (pos < next_face_change && next_face_change < pause)
2614 pause = next_face_change;
2615
31b24551
JB
2616 /* Wouldn't you hate to read the next line to someone over
2617 the phone? */
ae3b1442
KH
2618 if (pos < PT && PT < pause)
2619 pause = PT;
a2889657
JB
2620 if (pos < GPT && GPT < pause)
2621 pause = GPT;
2622
2623 p = &FETCH_CHAR (pos);
2624 }
ca26e1c8 2625
ca26e1c8
KH
2626 if (p1 >= endp)
2627 break;
2628
2629 p1prev = p1;
2630
a2889657 2631 c = *p++;
376b0e59
RS
2632 /* Let a display table override all standard display methods. */
2633 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
2634 {
2635 p1 = copy_part_of_rope (f, p1, leftmargin,
2636 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2637 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2638 current_face);
2639 }
2640 else if (c >= 040 && c < 0177)
a2889657 2641 {
d2f84654 2642 if (p1 >= leftmargin)
4cdc65eb 2643 *p1 = MAKE_GLYPH (f, c, current_face);
a2889657
JB
2644 p1++;
2645 }
2646 else if (c == '\n')
2647 {
2648 invis = 0;
642eefc6
RS
2649 if (last_invis_skip == pos
2650 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
2651 invis = 1;
ca26e1c8 2652 while (pos + 1 < ZV
a2889657 2653 && selective > 0
9f412332 2654 && indented_beyond_p (pos + 1, selective))
a2889657
JB
2655 {
2656 invis = 1;
2657 pos = find_next_newline (pos + 1, 1);
2658 if (FETCH_CHAR (pos - 1) == '\n')
2659 pos--;
2660 }
d2f84654 2661 if (invis && selective_rlen > 0 && p1 >= leftmargin)
a2889657
JB
2662 {
2663 p1 += selective_rlen;
d2f84654 2664 if (p1 - leftmargin > width)
a2889657 2665 p1 = endp;
278feba9 2666 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
1c2250c2 2667 (p1 - p1prev), current_face);
a2889657 2668 }
87485d6f 2669#ifdef HAVE_FACES
3c5c35c5
JB
2670 /* Draw the face of the newline character as extending all the
2671 way to the end of the frame line. */
2672 if (current_face)
1105ff20
KH
2673 {
2674 if (p1 < leftmargin)
2675 p1 = leftmargin;
2676 while (p1 < endp)
2677 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2678 }
3c5c35c5 2679#endif
545e04f6
KH
2680
2681 /* Update charstarts for the newline that ended this line. */
2682 /* Do nothing here for a char that's entirely off the left edge
2683 or if it starts at the right edge. */
2684 if (p1 >= leftmargin && p1prev != endp)
2685 {
2686 /* Store the newline's position into charstarts
2687 for the column where the newline starts.
2688 Store -1 for the rest of the glyphs it occupies. */
2689 int *p2x = &charstart[(p1prev < leftmargin
2690 ? leftmargin : p1prev)
2691 - p1start];
2692 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2693
2694 *p2x++ = pos;
2695 while (p2x < p2)
2696 *p2x++ = -1;
2697 }
2698
68a37fa8 2699 break;
a2889657
JB
2700 }
2701 else if (c == '\t')
2702 {
2703 do
2704 {
d2f84654 2705 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2706 *p1 = MAKE_GLYPH (f, ' ', current_face);
a2889657
JB
2707 p1++;
2708 }
d2f84654 2709 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
a2889657
JB
2710 % tab_width);
2711 }
6e8290aa 2712 else if (c == Ctl ('M') && selective == -1)
a2889657
JB
2713 {
2714 pos = find_next_newline (pos, 1);
2715 if (FETCH_CHAR (pos - 1) == '\n')
2716 pos--;
2717 if (selective_rlen > 0)
2718 {
2719 p1 += selective_rlen;
d2f84654 2720 if (p1 - leftmargin > width)
a2889657 2721 p1 = endp;
278feba9 2722 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
1c2250c2 2723 (p1 - p1prev), current_face);
a2889657 2724 }
87485d6f 2725#ifdef HAVE_FACES
3c5c35c5
JB
2726 /* Draw the face of the newline character as extending all the
2727 way to the end of the frame line. */
2728 if (current_face)
1105ff20
KH
2729 {
2730 if (p1 < leftmargin)
2731 p1 = leftmargin;
2732 while (p1 < endp)
2733 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2734 }
3c5c35c5 2735#endif
545e04f6
KH
2736
2737 /* Update charstarts for the ^M that ended this line. */
2738 /* Do nothing here for a char that's entirely off the left edge
2739 or if it starts at the right edge. */
2740 if (p1 >= leftmargin && p1prev != endp)
2741 {
2742 /* Store the newline's position into charstarts
2743 for the column where the newline starts.
2744 Store -1 for the rest of the glyphs it occupies. */
2745 int *p2x = &charstart[(p1prev < leftmargin
2746 ? leftmargin : p1prev)
2747 - p1start];
2748 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2749
2750 *p2x++ = pos;
2751 while (p2x < p2)
2752 *p2x++ = -1;
2753 }
68a37fa8 2754 break;
a2889657 2755 }
a2889657
JB
2756 else if (c < 0200 && ctl_arrow)
2757 {
d2f84654 2758 if (p1 >= leftmargin)
e24c997d 2759 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
278feba9
RS
2760 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
2761 current_face);
a2889657 2762 p1++;
d2f84654 2763 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2764 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
a2889657
JB
2765 p1++;
2766 }
2767 else
2768 {
d2f84654 2769 if (p1 >= leftmargin)
e24c997d 2770 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
278feba9
RS
2771 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
2772 current_face);
a2889657 2773 p1++;
d2f84654 2774 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2775 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
a2889657 2776 p1++;
d2f84654 2777 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2778 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
a2889657 2779 p1++;
d2f84654 2780 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2781 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
a2889657
JB
2782 p1++;
2783 }
31b24551 2784
ca26e1c8 2785 prevpos = pos;
a2889657 2786 pos++;
545e04f6
KH
2787
2788 /* Update charstarts for the character just output. */
2789
2790 /* Do nothing here for a char that's entirely off the left edge. */
2791 if (p1 >= leftmargin)
2792 {
2793 /* Store the char's position into charstarts
2794 for the first glyph occupied by this char.
2795 Store -1 for the rest of the glyphs it occupies. */
2796 if (p1 != p1prev)
2797 {
2798 int *p2x = &charstart[(p1prev < leftmargin
2799 ? leftmargin : p1prev)
2800 - p1start];
2801 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2802
2803 if (p2x < p2)
2804 *p2x++ = prevpos;
2805 while (p2x < p2)
2806 *p2x++ = -1;
2807 }
2808 }
a2889657
JB
2809 }
2810
2811 val.hpos = - XINT (w->hscroll);
2812 if (val.hpos)
2813 val.hpos++;
2814
2815 val.vpos = 1;
2816
2817 lastpos = pos;
2818
efc63ef0
RS
2819 /* Store 0 in this charstart line for the positions where
2820 there is no character. But do leave what was recorded
2821 for the character that ended the line. */
85bcef6c
RS
2822 /* Add 1 in the endtest to compensate for the fact that ENDP was
2823 made from WIDTH, which is 1 less than the window's actual
2824 internal width. */
a007eef6
RS
2825 i = p1 - p1start + 1;
2826 if (p1 < leftmargin)
2827 i += leftmargin - p1;
2828 for (; i < endp - p1start + 1; i++)
efc63ef0
RS
2829 charstart[i] = 0;
2830
a2889657
JB
2831 /* Handle continuation in middle of a character */
2832 /* by backing up over it */
2833 if (p1 > endp)
2834 {
5fcbb24d
JB
2835 /* Don't back up if we never actually displayed any text.
2836 This occurs when the minibuffer prompt takes up the whole line. */
2837 if (p1prev)
2838 {
2839 /* Start the next line with that same character */
2840 pos--;
2841 /* but at negative hpos, to skip the columns output on this line. */
2842 val.hpos += p1prev - endp;
2843 }
2844
a2889657
JB
2845 /* Keep in this line everything up to the continuation column. */
2846 p1 = endp;
2847 }
2848
2849 /* Finish deciding which character to start the next line on,
2850 and what hpos to start it at.
2851 Also set `lastpos' to the last position which counts as "on this line"
2852 for cursor-positioning. */
2853
2854 if (pos < ZV)
2855 {
2856 if (FETCH_CHAR (pos) == '\n')
dd5f6267
KH
2857 {
2858 /* If stopped due to a newline, start next line after it */
2859 pos++;
2860 /* Check again for hidden lines, in case the newline occurred exactly
2861 at the right margin. */
2862 while (pos < ZV && selective > 0
2863 && indented_beyond_p (pos, selective))
2864 pos = find_next_newline (pos, 1);
2865 }
a2889657
JB
2866 else
2867 /* Stopped due to right margin of window */
2868 {
2869 if (truncate)
2870 {
278feba9 2871 *p1++ = fix_glyph (f, truncator, 0);
a2889657
JB
2872 /* Truncating => start next line after next newline,
2873 and point is on this line if it is before the newline,
2874 and skip none of first char of next line */
dd5f6267
KH
2875 do
2876 pos = find_next_newline (pos, 1);
2877 while (pos < ZV && selective > 0
2878 && indented_beyond_p (pos, selective));
a2889657
JB
2879 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2880
2881 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
2882 }
2883 else
2884 {
278feba9 2885 *p1++ = fix_glyph (f, continuer, 0);
a2889657
JB
2886 val.vpos = 0;
2887 lastpos--;
2888 }
2889 }
2890 }
2891
2892 /* If point is at eol or in invisible text at eol,
44fa5b1e 2893 record its frame location now. */
a2889657 2894
ae3b1442 2895 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
a2889657
JB
2896 {
2897 cursor_vpos = vpos;
d2f84654 2898 cursor_hpos = p1 - leftmargin;
a2889657
JB
2899 }
2900
2901 if (cursor_vpos == vpos)
2902 {
2903 if (cursor_hpos < 0) cursor_hpos = 0;
2904 if (cursor_hpos > width) cursor_hpos = width;
2905 cursor_hpos += XFASTINT (w->left);
44fa5b1e 2906 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
a2889657 2907 {
b5bbc9a5
KH
2908 if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f)
2909 && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window)))
2910 {
2911 FRAME_CURSOR_Y (f) = cursor_vpos;
2912 FRAME_CURSOR_X (f) = cursor_hpos;
2913 }
a2889657
JB
2914
2915 if (w == XWINDOW (selected_window))
2916 {
2917 /* Line is not continued and did not start
2918 in middle of character */
2919 if ((hpos - XFASTINT (w->left)
2920 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2921 && val.vpos)
2922 {
2923 this_line_bufpos = start;
2924 this_line_buffer = current_buffer;
2925 this_line_vpos = cursor_vpos;
2926 this_line_start_hpos = hpos;
2927 this_line_endpos = Z - lastpos;
2928 }
2929 else
2930 this_line_bufpos = 0;
2931 }
2932 }
2933 }
2934
2935 /* If hscroll and line not empty, insert truncation-at-left marker */
2936 if (hscroll && lastpos != start)
2937 {
d2f84654
RS
2938 *leftmargin = fix_glyph (f, truncator, 0);
2939 if (p1 <= leftmargin)
2940 p1 = leftmargin + 1;
a2889657
JB
2941 }
2942
44fa5b1e 2943 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
a2889657
JB
2944 {
2945 endp++;
d2f84654 2946 if (p1 < leftmargin) p1 = leftmargin;
a2889657 2947 while (p1 < endp) *p1++ = SPACEGLYPH;
b1d1124b 2948
88f22aff
JB
2949 /* Don't draw vertical bars if we're using scroll bars. They're
2950 covered up by the scroll bars, and it's distracting to see
2951 them when the scroll bar windows are flickering around to be
b1d1124b 2952 reconfigured. */
88f22aff 2953 *p1++ = (FRAME_HAS_VERTICAL_SCROLL_BARS (f)
a45e35e1
JB
2954 ? ' '
2955 : (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
2956 ? DISP_BORDER_GLYPH (dp)
2957 : '|'));
a2889657
JB
2958 }
2959 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
2960 p1 - desired_glyphs->glyphs[vpos]);
2961 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
2962
2963 /* If the start of this line is the overlay arrow-position,
2964 then put the arrow string into the display-line. */
2965
e24c997d 2966 if (MARKERP (Voverlay_arrow_position)
a2889657
JB
2967 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
2968 && start == marker_position (Voverlay_arrow_position)
e24c997d 2969 && STRINGP (Voverlay_arrow_string)
a2889657
JB
2970 && ! overlay_arrow_seen)
2971 {
2972 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
2973 int i;
2974 int len = XSTRING (Voverlay_arrow_string)->size;
142be3dd 2975 int arrow_end;
a2889657 2976
b1d1124b
JB
2977 if (len > width)
2978 len = width;
87485d6f 2979#ifdef HAVE_FACES
c4628384
RS
2980 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
2981 {
2982 /* If the arrow string has text props, obey them when displaying. */
2983 for (i = 0; i < len; i++)
2984 {
2985 int c = p[i];
2986 Lisp_Object face, ilisp;
2987 int newface;
2988
c2213350 2989 XSETFASTINT (ilisp, i);
c4628384
RS
2990 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
2991 newface = compute_glyph_face_1 (f, face, 0);
2992 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
2993 }
2994 }
2995 else
87485d6f 2996#endif /* HAVE_FACES */
c4628384
RS
2997 {
2998 for (i = 0; i < len; i++)
2999 leftmargin[i] = p[i];
3000 }
142be3dd
JB
3001
3002 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
d2f84654 3003 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
142be3dd
JB
3004 if (desired_glyphs->used[vpos] < arrow_end)
3005 desired_glyphs->used[vpos] = arrow_end;
a2889657
JB
3006
3007 overlay_arrow_seen = 1;
3008 }
3009
3010 val.bufpos = pos;
3011 val_display_text_line = val;
3012 return &val_display_text_line;
3013}
3014\f
7ce2c095
RS
3015/* Redisplay the menu bar in the frame for window W. */
3016
3017static void
3018display_menu_bar (w)
3019 struct window *w;
3020{
3021 Lisp_Object items, tail;
3022 register int vpos = 0;
3023 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3024 int maxendcol = FRAME_WIDTH (f);
3025 int hpos = 0;
8351baf2 3026 int i;
7ce2c095 3027
76412d64 3028#ifndef USE_X_TOOLKIT
7ce2c095
RS
3029 if (FRAME_MENU_BAR_LINES (f) <= 0)
3030 return;
3031
3032 get_display_line (f, vpos, 0);
3033
8351baf2
RS
3034 items = FRAME_MENU_BAR_ITEMS (f);
3035 for (i = 0; i < XVECTOR (items)->size; i += 3)
7ce2c095 3036 {
8351baf2
RS
3037 Lisp_Object pos, string;
3038 string = XVECTOR (items)->contents[i + 1];
3039 if (NILP (string))
3040 break;
2d66ad19 3041
c2213350 3042 XSETFASTINT (XVECTOR (items)->contents[i + 2], hpos);
7ce2c095
RS
3043
3044 if (hpos < maxendcol)
3045 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
3046 XSTRING (string)->data,
90adcf20 3047 XSTRING (string)->size,
278feba9 3048 hpos, 0, 0, hpos, maxendcol);
6b1bbc46 3049 /* Put a space between items. */
2d66ad19
RS
3050 if (hpos < maxendcol)
3051 {
6b1bbc46 3052 int hpos1 = hpos + 1;
278feba9 3053 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
2d66ad19
RS
3054 min (hpos1, maxendcol), maxendcol);
3055 }
7ce2c095
RS
3056 }
3057
3058 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3059 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
2d66ad19
RS
3060
3061 /* Fill out the line with spaces. */
3062 if (maxendcol > hpos)
278feba9 3063 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
db6f348c
JB
3064
3065 /* Clear the rest of the lines allocated to the menu bar. */
3066 vpos++;
3067 while (vpos < FRAME_MENU_BAR_LINES (f))
3068 get_display_line (f, vpos++, 0);
76412d64 3069#endif /* not USE_X_TOOLKIT */
7ce2c095
RS
3070}
3071\f
a2889657
JB
3072/* Display the mode line for window w */
3073
3074static void
3075display_mode_line (w)
3076 struct window *w;
3077{
3078 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
3079 register int left = XFASTINT (w->left);
3080 register int right = XFASTINT (w->width) + left;
44fa5b1e 3081 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
a2889657 3082
aa6d10fa 3083 line_number_displayed = 0;
155ef550 3084 w->column_number_displayed = Qnil;
aa6d10fa 3085
44fa5b1e 3086 get_display_line (f, vpos, left);
03b294dc
RS
3087
3088 /* Temporarily make frame F's kboard the current kboard
3089 so that kboard-local variables in the mode_line_format
3090 will get the right values. */
3091 push_frame_kboard (f);
3092
3093 display_mode_element (w, vpos, left, 0, right, right,
3094 current_buffer->mode_line_format);
3095
3096 pop_frame_kboard ();
3097
44fa5b1e 3098 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
a2889657
JB
3099
3100 /* Make the mode line inverse video if the entire line
3101 is made of mode lines.
3102 I.e. if this window is full width,
3103 or if it is the child of a full width window
3104 (which implies that that window is split side-by-side
3105 and the rest of this line is mode lines of the sibling windows). */
44fa5b1e
JB
3106 if (XFASTINT (w->width) == FRAME_WIDTH (f)
3107 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
3108 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
87485d6f 3109#ifdef HAVE_FACES
03b294dc 3110 else if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video)
d7eb09a0
RS
3111 {
3112 /* For a partial width window, explicitly set face of each glyph. */
3113 int i;
3114 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3115 for (i = left; i < right; ++i)
4cdc65eb 3116 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
d7eb09a0 3117 }
4cdc65eb 3118#endif
a2889657
JB
3119}
3120
3121/* Contribute ELT to the mode line for window W.
3122 How it translates into text depends on its data type.
3123
3124 VPOS is the position of the mode line being displayed.
3125
44fa5b1e 3126 HPOS is the position (absolute on frame) where this element's text
a2889657
JB
3127 should start. The output is truncated automatically at the right
3128 edge of window W.
3129
3130 DEPTH is the depth in recursion. It is used to prevent
3131 infinite recursion here.
3132
3133 MINENDCOL is the hpos before which the element may not end.
3134 The element is padded at the right with spaces if nec
3135 to reach this column.
3136
3137 MAXENDCOL is the hpos past which this element may not extend.
3138 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3139 (This is necessary to make nested padding and truncation work.)
3140
3141 Returns the hpos of the end of the text generated by ELT.
3142 The next element will receive that value as its HPOS arg,
3143 so as to concatenate the elements. */
3144
3145static int
3146display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3147 struct window *w;
3148 register int vpos, hpos;
3149 int depth;
3150 int minendcol;
3151 register int maxendcol;
3152 register Lisp_Object elt;
3153{
3154 tail_recurse:
3155 if (depth > 10)
3156 goto invalid;
3157
3158 depth++;
3159
0220c518 3160 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
a2889657
JB
3161 {
3162 case Lisp_String:
3163 {
3164 /* A string: output it and check for %-constructs within it. */
3165 register unsigned char c;
3166 register unsigned char *this = XSTRING (elt)->data;
3167
3168 while (hpos < maxendcol && *this)
3169 {
3170 unsigned char *last = this;
3171 while ((c = *this++) != '\0' && c != '%')
3172 ;
3173 if (this - 1 != last)
3174 {
3175 register int lim = --this - last + hpos;
d39b6696
KH
3176 if (frame_title_ptr)
3177 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3178 else
3179 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3180 hpos, min (lim, maxendcol));
a2889657
JB
3181 }
3182 else /* c == '%' */
3183 {
3184 register int spec_width = 0;
3185
3186 /* We can't allow -ve args due to the "%-" construct */
3187 /* Argument specifies minwidth but not maxwidth
3188 (maxwidth can be specified by
3189 (<negative-number> . <stuff>) mode-line elements) */
3190
3191 while ((c = *this++) >= '0' && c <= '9')
3192 {
3193 spec_width = spec_width * 10 + (c - '0');
3194 }
3195
3196 spec_width += hpos;
3197 if (spec_width > maxendcol)
3198 spec_width = maxendcol;
3199
3200 if (c == 'M')
3201 hpos = display_mode_element (w, vpos, hpos, depth,
3202 spec_width, maxendcol,
3203 Vglobal_mode_string);
3204 else if (c != 0)
d39b6696
KH
3205 {
3206 char *spec = decode_mode_spec (w, c, maxendcol - hpos);
3207 if (frame_title_ptr)
3208 hpos = store_frame_title (spec, spec_width, maxendcol);
3209 else
3210 hpos = display_string (w, vpos, spec, -1,
3211 hpos, 0, 1,
3212 spec_width, maxendcol);
3213 }
a2889657
JB
3214 }
3215 }
3216 }
3217 break;
3218
3219 case Lisp_Symbol:
3220 /* A symbol: process the value of the symbol recursively
3221 as if it appeared here directly. Avoid error if symbol void.
3222 Special case: if value of symbol is a string, output the string
3223 literally. */
3224 {
3225 register Lisp_Object tem;
3226 tem = Fboundp (elt);
265a9e55 3227 if (!NILP (tem))
a2889657
JB
3228 {
3229 tem = Fsymbol_value (elt);
3230 /* If value is a string, output that string literally:
3231 don't check for % within it. */
e24c997d 3232 if (STRINGP (tem))
d39b6696
KH
3233 {
3234 if (frame_title_ptr)
3235 hpos = store_frame_title (XSTRING (tem)->data,
3236 minendcol, maxendcol);
3237 else
3238 hpos = display_string (w, vpos, XSTRING (tem)->data,
3239 XSTRING (tem)->size,
3240 hpos, 0, 1, minendcol, maxendcol);
3241 }
a2889657
JB
3242 /* Give up right away for nil or t. */
3243 else if (!EQ (tem, elt))
3244 { elt = tem; goto tail_recurse; }
3245 }
3246 }
3247 break;
3248
3249 case Lisp_Cons:
3250 {
3251 register Lisp_Object car, tem;
3252
3253 /* A cons cell: three distinct cases.
3254 If first element is a string or a cons, process all the elements
3255 and effectively concatenate them.
3256 If first element is a negative number, truncate displaying cdr to
3257 at most that many characters. If positive, pad (with spaces)
3258 to at least that many characters.
3259 If first element is a symbol, process the cadr or caddr recursively
3260 according to whether the symbol's value is non-nil or nil. */
3261 car = XCONS (elt)->car;
e24c997d 3262 if (SYMBOLP (car))
a2889657
JB
3263 {
3264 tem = Fboundp (car);
3265 elt = XCONS (elt)->cdr;
e24c997d 3266 if (!CONSP (elt))
a2889657
JB
3267 goto invalid;
3268 /* elt is now the cdr, and we know it is a cons cell.
3269 Use its car if CAR has a non-nil value. */
265a9e55 3270 if (!NILP (tem))
a2889657
JB
3271 {
3272 tem = Fsymbol_value (car);
265a9e55 3273 if (!NILP (tem))
a2889657
JB
3274 { elt = XCONS (elt)->car; goto tail_recurse; }
3275 }
3276 /* Symbol's value is nil (or symbol is unbound)
3277 Get the cddr of the original list
3278 and if possible find the caddr and use that. */
3279 elt = XCONS (elt)->cdr;
265a9e55 3280 if (NILP (elt))
a2889657 3281 break;
e24c997d 3282 else if (!CONSP (elt))
a2889657
JB
3283 goto invalid;
3284 elt = XCONS (elt)->car;
3285 goto tail_recurse;
3286 }
e24c997d 3287 else if (INTEGERP (car))
a2889657
JB
3288 {
3289 register int lim = XINT (car);
3290 elt = XCONS (elt)->cdr;
3291 if (lim < 0)
3292 /* Negative int means reduce maximum width.
3293 DO NOT change MINENDCOL here!
3294 (20 -10 . foo) should truncate foo to 10 col
3295 and then pad to 20. */
3296 maxendcol = min (maxendcol, hpos - lim);
3297 else if (lim > 0)
3298 {
3299 /* Padding specified. Don't let it be more than
3300 current maximum. */
3301 lim += hpos;
3302 if (lim > maxendcol)
3303 lim = maxendcol;
3304 /* If that's more padding than already wanted, queue it.
3305 But don't reduce padding already specified even if
3306 that is beyond the current truncation point. */
3307 if (lim > minendcol)
3308 minendcol = lim;
3309 }
3310 goto tail_recurse;
3311 }
e24c997d 3312 else if (STRINGP (car) || CONSP (car))
a2889657
JB
3313 {
3314 register int limit = 50;
3315 /* LIMIT is to protect against circular lists. */
e24c997d 3316 while (CONSP (elt) && --limit > 0
a2889657
JB
3317 && hpos < maxendcol)
3318 {
3319 hpos = display_mode_element (w, vpos, hpos, depth,
3320 hpos, maxendcol,
3321 XCONS (elt)->car);
3322 elt = XCONS (elt)->cdr;
3323 }
3324 }
3325 }
3326 break;
3327
3328 default:
3329 invalid:
d39b6696
KH
3330 if (frame_title_ptr)
3331 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3332 else
3333 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3334 minendcol, maxendcol);
3335 return hpos;
a2889657
JB
3336 }
3337
a2889657 3338 if (minendcol > hpos)
d39b6696
KH
3339 if (frame_title_ptr)
3340 hpos = store_frame_title ("", minendcol, maxendcol);
3341 else
3342 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
a2889657
JB
3343 return hpos;
3344}
3345\f
3346/* Return a string for the output of a mode line %-spec for window W,
3347 generated by character C and width MAXWIDTH. */
3348
11e82b76
JB
3349static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3350
a2889657
JB
3351static char *
3352decode_mode_spec (w, c, maxwidth)
3353 struct window *w;
3354 register char c;
3355 register int maxwidth;
3356{
0b67772d 3357 Lisp_Object obj;
44fa5b1e
JB
3358 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3359 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
d39b6696 3360 struct buffer *b = XBUFFER (w->buffer);
a2889657 3361
0b67772d 3362 obj = Qnil;
44fa5b1e
JB
3363 if (maxwidth > FRAME_WIDTH (f))
3364 maxwidth = FRAME_WIDTH (f);
a2889657
JB
3365
3366 switch (c)
3367 {
1af9f229
RS
3368 case '*':
3369 if (!NILP (b->read_only))
3370 return "%";
3371 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3372 return "*";
3373 return "-";
3374
3375 case '+':
3376 /* This differs from %* only for a modified read-only buffer. */
3377 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3378 return "*";
3379 if (!NILP (b->read_only))
3380 return "%";
3381 return "-";
3382
3383 case '&':
3384 /* This differs from %* in ignoring read-only-ness. */
3385 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3386 return "*";
3387 return "-";
3388
3389 case '%':
3390 return "%";
3391
3392 case '[':
3393 {
3394 int i;
3395 char *p;
3396
3397 if (command_loop_level > 5)
3398 return "[[[... ";
3399 p = decode_mode_spec_buf;
3400 for (i = 0; i < command_loop_level; i++)
3401 *p++ = '[';
3402 *p = 0;
3403 return decode_mode_spec_buf;
3404 }
3405
3406 case ']':
3407 {
3408 int i;
3409 char *p;
3410
3411 if (command_loop_level > 5)
3412 return " ...]]]";
3413 p = decode_mode_spec_buf;
3414 for (i = 0; i < command_loop_level; i++)
3415 *p++ = ']';
3416 *p = 0;
3417 return decode_mode_spec_buf;
3418 }
3419
3420 case '-':
3421 {
3422 register char *p;
3423 register int i;
3424
3425 if (maxwidth < sizeof (lots_of_dashes))
3426 return lots_of_dashes;
3427 else
3428 {
3429 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3430 *p++ = '-';
3431 *p = '\0';
3432 }
3433 return decode_mode_spec_buf;
3434 }
3435
a2889657 3436 case 'b':
d39b6696 3437 obj = b->name;
a2889657
JB
3438#if 0
3439 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
3440 {
3441 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
3442 decode_mode_spec_buf[maxwidth - 1] = '\\';
3443 decode_mode_spec_buf[maxwidth] = '\0';
3444 return decode_mode_spec_buf;
3445 }
3446#endif
3447 break;
3448
1af9f229
RS
3449 case 'c':
3450 {
3451 int col = current_column ();
3452 XSETFASTINT (w->column_number_displayed, col);
3453 sprintf (decode_mode_spec_buf, "%d", col);
3454 return decode_mode_spec_buf;
3455 }
3456
3457 case 'F':
3458 /* %F displays the frame name. */
3459 return (char *) XSTRING (selected_frame->name)->data;
3460
a2889657 3461 case 'f':
d39b6696 3462 obj = b->filename;
a2889657 3463#if 0
265a9e55 3464 if (NILP (obj))
a2889657 3465 return "[none]";
e24c997d 3466 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
a2889657
JB
3467 {
3468 bcopy ("...", decode_mode_spec_buf, 3);
3469 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
3470 decode_mode_spec_buf + 3, maxwidth - 3);
3471 return decode_mode_spec_buf;
3472 }
3473#endif
3474 break;
3475
aa6d10fa
RS
3476 case 'l':
3477 {
3478 int startpos = marker_position (w->start);
3479 int line, linepos, topline;
3480 int nlines, junk;
3481 Lisp_Object tem;
3482 int height = XFASTINT (w->height);
3483
3484 /* If we decided that this buffer isn't suitable for line numbers,
3485 don't forget that too fast. */
3486 if (EQ (w->base_line_pos, w->buffer))
3487 return "??";
3488
3489 /* If the buffer is very big, don't waste time. */
d39b6696 3490 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
aa6d10fa
RS
3491 {
3492 w->base_line_pos = Qnil;
3493 w->base_line_number = Qnil;
3494 return "??";
3495 }
3496
3497 if (!NILP (w->base_line_number)
3498 && !NILP (w->base_line_pos)
3499 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
3500 {
3501 line = XFASTINT (w->base_line_number);
3502 linepos = XFASTINT (w->base_line_pos);
3503 }
3504 else
3505 {
3506 line = 1;
d39b6696 3507 linepos = BUF_BEGV (b);
aa6d10fa
RS
3508 }
3509
3510 /* Count lines from base line to window start position. */
3511 nlines = display_count_lines (linepos, startpos, startpos, &junk);
3512
3513 topline = nlines + line;
3514
3515 /* Determine a new base line, if the old one is too close
3516 or too far away, or if we did not have one.
3517 "Too close" means it's plausible a scroll-down would
3518 go back past it. */
d39b6696 3519 if (startpos == BUF_BEGV (b))
aa6d10fa 3520 {
c2213350
KH
3521 XSETFASTINT (w->base_line_number, topline);
3522 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
aa6d10fa
RS
3523 }
3524 else if (nlines < height + 25 || nlines > height * 3 + 50
d39b6696 3525 || linepos == BUF_BEGV (b))
aa6d10fa 3526 {
d39b6696 3527 int limit = BUF_BEGV (b);
aa6d10fa
RS
3528 int position;
3529 int distance = (height * 2 + 30) * 200;
3530
3531 if (startpos - distance > limit)
3532 limit = startpos - distance;
3533
3534 nlines = display_count_lines (startpos, limit,
3535 -(height * 2 + 30),
3536 &position);
3537 /* If we couldn't find the lines we wanted within
3538 200 chars per line,
3539 give up on line numbers for this window. */
3540 if (position == startpos - distance)
3541 {
3542 w->base_line_pos = w->buffer;
3543 w->base_line_number = Qnil;
3544 return "??";
3545 }
3546
c2213350
KH
3547 XSETFASTINT (w->base_line_number, topline - nlines);
3548 XSETFASTINT (w->base_line_pos, position);
aa6d10fa
RS
3549 }
3550
3551 /* Now count lines from the start pos to point. */
3552 nlines = display_count_lines (startpos, PT, PT, &junk);
3553
3554 /* Record that we did display the line number. */
3555 line_number_displayed = 1;
3556
3557 /* Make the string to show. */
3558 sprintf (decode_mode_spec_buf, "%d", topline + nlines);
3559 return decode_mode_spec_buf;
3560 }
3561 break;
3562
a2889657 3563 case 'm':
d39b6696 3564 obj = b->mode_name;
a2889657
JB
3565 break;
3566
3567 case 'n':
d39b6696 3568 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
a2889657
JB
3569 return " Narrow";
3570 break;
3571
a2889657
JB
3572 case 'p':
3573 {
3574 int pos = marker_position (w->start);
d39b6696 3575 int total = BUF_ZV (b) - BUF_BEGV (b);
a2889657 3576
d39b6696 3577 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
a2889657 3578 {
d39b6696 3579 if (pos <= BUF_BEGV (b))
a2889657
JB
3580 return "All";
3581 else
3582 return "Bottom";
3583 }
d39b6696 3584 else if (pos <= BUF_BEGV (b))
a2889657
JB
3585 return "Top";
3586 else
3587 {
d39b6696 3588 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
a2889657
JB
3589 /* We can't normally display a 3-digit number,
3590 so get us a 2-digit number that is close. */
3591 if (total == 100)
3592 total = 99;
3593 sprintf (decode_mode_spec_buf, "%2d%%", total);
3594 return decode_mode_spec_buf;
3595 }
3596 }
3597
8ffcb79f
RS
3598 /* Display percentage of size above the bottom of the screen. */
3599 case 'P':
3600 {
3601 int toppos = marker_position (w->start);
d39b6696
KH
3602 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
3603 int total = BUF_ZV (b) - BUF_BEGV (b);
8ffcb79f 3604
d39b6696 3605 if (botpos >= BUF_ZV (b))
8ffcb79f 3606 {
d39b6696 3607 if (toppos <= BUF_BEGV (b))
8ffcb79f
RS
3608 return "All";
3609 else
3610 return "Bottom";
3611 }
3612 else
3613 {
d39b6696 3614 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
8ffcb79f
RS
3615 /* We can't normally display a 3-digit number,
3616 so get us a 2-digit number that is close. */
3617 if (total == 100)
3618 total = 99;
d39b6696 3619 if (toppos <= BUF_BEGV (b))
8ffcb79f
RS
3620 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
3621 else
3622 sprintf (decode_mode_spec_buf, "%2d%%", total);
3623 return decode_mode_spec_buf;
3624 }
3625 }
3626
1af9f229
RS
3627 case 's':
3628 /* status of process */
3629 obj = Fget_buffer_process (w->buffer);
3630 if (NILP (obj))
3631 return "no process";
3632#ifdef subprocesses
3633 obj = Fsymbol_name (Fprocess_status (obj));
3634#endif
3635 break;
d39b6696 3636
1af9f229
RS
3637 case 't': /* indicate TEXT or BINARY */
3638#ifdef MODE_LINE_BINARY_TEXT
3639 return MODE_LINE_BINARY_TEXT (b);
3640#else
3641 return "T";
3642#endif
a2889657 3643 }
d39b6696 3644
e24c997d 3645 if (STRINGP (obj))
a2889657
JB
3646 return (char *) XSTRING (obj)->data;
3647 else
3648 return "";
3649}
59b49f63
RS
3650\f
3651/* Search for COUNT instances of a line boundary, which means either a
3652 newline or (if selective display enabled) a carriage return.
3653 Start at START. If COUNT is negative, search backwards.
3654
3655 If we find COUNT instances, set *SHORTAGE to zero, and return the
3656 position after the COUNTth match. Note that for reverse motion
3657 this is not the same as the usual convention for Emacs motion commands.
3658
3659 If we don't find COUNT instances before reaching the end of the
3660 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3661 the number of line boundaries left unfound, and return the end of the
3662 buffer we bumped up against. */
3663
3664static int
3665display_scan_buffer (start, count, shortage)
3666 int *shortage, start;
3667 register int count;
3668{
3669 int limit = ((count > 0) ? ZV - 1 : BEGV);
3670 int direction = ((count > 0) ? 1 : -1);
3671
3672 register unsigned char *cursor;
3673 unsigned char *base;
3674
3675 register int ceiling;
3676 register unsigned char *ceiling_addr;
3677
3678 /* If we are not in selective display mode,
3679 check only for newlines. */
3680 if (! (!NILP (current_buffer->selective_display)
3681 && !INTEGERP (current_buffer->selective_display)))
ae474ea9 3682 return scan_buffer ('\n', start, 0, count, shortage, 0);
59b49f63
RS
3683
3684 /* The code that follows is like scan_buffer
3685 but checks for either newline or carriage return. */
3686
3687 if (shortage != 0)
3688 *shortage = 0;
3689
3690 if (count > 0)
3691 while (start != limit + 1)
3692 {
3693 ceiling = BUFFER_CEILING_OF (start);
3694 ceiling = min (limit, ceiling);
3695 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
3696 base = (cursor = &FETCH_CHAR (start));
3697 while (1)
3698 {
3699 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
3700 ;
3701 if (cursor != ceiling_addr)
3702 {
3703 if (--count == 0)
3704 {
3705 immediate_quit = 0;
3706 return (start + cursor - base + 1);
3707 }
3708 else
3709 if (++cursor == ceiling_addr)
3710 break;
3711 }
3712 else
3713 break;
3714 }
3715 start += cursor - base;
3716 }
3717 else
3718 {
3719 start--; /* first character we scan */
3720 while (start > limit - 1)
3721 { /* we WILL scan under start */
3722 ceiling = BUFFER_FLOOR_OF (start);
3723 ceiling = max (limit, ceiling);
3724 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
3725 base = (cursor = &FETCH_CHAR (start));
3726 cursor++;
3727 while (1)
3728 {
3729 while (--cursor != ceiling_addr
3730 && *cursor != '\n' && *cursor != 015)
3731 ;
3732 if (cursor != ceiling_addr)
3733 {
3734 if (++count == 0)
3735 {
3736 immediate_quit = 0;
3737 return (start + cursor - base + 1);
3738 }
3739 }
3740 else
3741 break;
3742 }
3743 start += cursor - base;
3744 }
3745 }
3746
3747 if (shortage != 0)
3748 *shortage = count * direction;
3749 return (start + ((direction == 1 ? 0 : 1)));
3750}
aa6d10fa
RS
3751
3752/* Count up to N lines starting from FROM.
3753 But don't go beyond LIMIT.
3754 Return the number of lines thus found (always positive).
3755 Store the position after what was found into *POS_PTR. */
3756
3757static int
3758display_count_lines (from, limit, n, pos_ptr)
3759 int from, limit, n;
3760 int *pos_ptr;
3761{
3762 int oldbegv = BEGV;
3763 int oldzv = ZV;
3764 int shortage = 0;
3765
3766 if (limit < from)
3767 BEGV = limit;
3768 else
3769 ZV = limit;
3770
59b49f63 3771 *pos_ptr = display_scan_buffer (from, n, &shortage);
aa6d10fa
RS
3772
3773 ZV = oldzv;
3774 BEGV = oldbegv;
3775
3776 if (n < 0)
3777 /* When scanning backwards, scan_buffer stops *after* the last newline
3778 it finds, but does count it. Compensate for that. */
3779 return - n - shortage - (*pos_ptr != limit);
3780 return n - shortage;
3781}
a2889657
JB
3782\f
3783/* Display STRING on one line of window W, starting at HPOS.
3784 Display at position VPOS. Caller should have done get_display_line.
11e82b76 3785 If VPOS == -1, display it as the current frame's title.
90adcf20 3786 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
a2889657
JB
3787
3788 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
3789
3790 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
3791 MAXCOL is the last column ok to end at. Truncate here.
3792 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
44fa5b1e 3793 Both count from the left edge of the frame, as does HPOS.
a2889657
JB
3794 The right edge of W is an implicit maximum.
3795 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
3796
278feba9
RS
3797 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
3798 at the place where the current window ends in this line
3799 and not display anything beyond there. Otherwise, only MAXCOL
3800 controls where to stop output.
3801
3802 Returns ending hpos. */
a2889657
JB
3803
3804static int
278feba9
RS
3805display_string (w, vpos, string, length, hpos, truncate,
3806 obey_window_width, mincol, maxcol)
a2889657
JB
3807 struct window *w;
3808 unsigned char *string;
90adcf20 3809 int length;
a2889657
JB
3810 int vpos, hpos;
3811 GLYPH truncate;
278feba9 3812 int obey_window_width;
a2889657
JB
3813 int mincol, maxcol;
3814{
3815 register int c;
3816 register GLYPH *p1;
3817 int hscroll = XINT (w->hscroll);
253c7d2f 3818 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
a2889657
JB
3819 register GLYPH *start;
3820 register GLYPH *end;
b1d1124b
JB
3821 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3822 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
a2889657
JB
3823 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
3824 int window_width = XFASTINT (w->width);
3825
3826 /* Use the standard display table, not the window's display table.
3827 We don't want the mode line in rot13. */
3828 register struct Lisp_Vector *dp = 0;
efc63ef0 3829 int i;
a2889657 3830
e24c997d 3831 if (VECTORP (Vstandard_display_table)
a2889657
JB
3832 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
3833 dp = XVECTOR (Vstandard_display_table);
3834
54ff581a 3835 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
a2889657
JB
3836
3837 p1 = p1start;
3838 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
a2889657 3839
278feba9 3840 if (obey_window_width)
b1d1124b 3841 {
278feba9
RS
3842 end = start + window_width - (truncate != 0);
3843
3844 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
b1d1124b 3845 {
278feba9
RS
3846 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3847 {
3848 int i;
b1d1124b 3849
5802e919 3850 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
278feba9
RS
3851 *end-- = ' ';
3852 }
3853 else
3854 *end-- = '|';
b1d1124b 3855 }
b1d1124b 3856 }
a2889657 3857
278feba9
RS
3858 if (! obey_window_width
3859 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
a2889657 3860 end = desired_glyphs->glyphs[vpos] + maxcol;
278feba9 3861
efc63ef0 3862 /* Store 0 in charstart for these columns. */
bd5dec8e 3863 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
efc63ef0
RS
3864 desired_glyphs->charstarts[vpos][i] = 0;
3865
a2889657
JB
3866 if (maxcol >= 0 && mincol > maxcol)
3867 mincol = maxcol;
3868
3869 while (p1 < end)
3870 {
90adcf20
RS
3871 if (length == 0)
3872 break;
a2889657 3873 c = *string++;
90adcf20
RS
3874 /* Specified length. */
3875 if (length >= 0)
3876 length--;
3877 /* Unspecified length (null-terminated string). */
3878 else if (c == 0)
3879 break;
3880
376b0e59
RS
3881 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3882 {
3883 p1 = copy_part_of_rope (f, p1, start,
3884 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3885 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3886 0);
3887 }
3888 else if (c >= 040 && c < 0177)
a2889657
JB
3889 {
3890 if (p1 >= start)
3891 *p1 = c;
3892 p1++;
3893 }
3894 else if (c == '\t')
3895 {
3896 do
3897 {
3898 if (p1 >= start && p1 < end)
3899 *p1 = SPACEGLYPH;
3900 p1++;
3901 }
3902 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
3903 }
ded34426 3904 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
a2889657
JB
3905 {
3906 if (p1 >= start)
e24c997d 3907 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
278feba9
RS
3908 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3909 0);
a2889657 3910 p1++;
6e8290aa 3911 if (p1 >= start && p1 < end)
a2889657
JB
3912 *p1 = c ^ 0100;
3913 p1++;
3914 }
3915 else
3916 {
3917 if (p1 >= start)
e24c997d 3918 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
278feba9
RS
3919 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3920 0);
a2889657 3921 p1++;
6e8290aa 3922 if (p1 >= start && p1 < end)
a2889657
JB
3923 *p1 = (c >> 6) + '0';
3924 p1++;
6e8290aa 3925 if (p1 >= start && p1 < end)
a2889657
JB
3926 *p1 = (7 & (c >> 3)) + '0';
3927 p1++;
6e8290aa 3928 if (p1 >= start && p1 < end)
a2889657
JB
3929 *p1 = (7 & c) + '0';
3930 p1++;
3931 }
3932 }
3933
90adcf20 3934 if (c && length > 0)
a2889657
JB
3935 {
3936 p1 = end;
278feba9 3937 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
a2889657
JB
3938 }
3939 else if (mincol >= 0)
3940 {
3941 end = desired_glyphs->glyphs[vpos] + mincol;
3942 while (p1 < end)
3943 *p1++ = SPACEGLYPH;
3944 }
3945
3946 {
3947 register int len = p1 - desired_glyphs->glyphs[vpos];
3948
3949 if (len > desired_glyphs->used[vpos])
3950 desired_glyphs->used[vpos] = len;
3951 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3952
3953 return len;
3954 }
3955}
3956\f
642eefc6
RS
3957/* This is like a combination of memq and assq.
3958 Return 1 if PROPVAL appears as an element of LIST
3959 or as the car of an element of LIST.
af460d46
RS
3960 If PROPVAL is a list, compare each element against LIST
3961 in that way, and return 1 if any element of PROPVAL is found in LIST.
642eefc6
RS
3962 Otherwise return 0.
3963 This function cannot quit. */
3964
3965int
3966invisible_p (propval, list)
3967 register Lisp_Object propval;
3968 Lisp_Object list;
3969{
af460d46
RS
3970 register Lisp_Object tail, proptail;
3971 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
642eefc6
RS
3972 {
3973 register Lisp_Object tem;
af460d46 3974 tem = XCONS (tail)->car;
642eefc6
RS
3975 if (EQ (propval, tem))
3976 return 1;
3977 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
3978 return 1;
3979 }
af460d46
RS
3980 if (CONSP (propval))
3981 for (proptail = propval; CONSP (proptail);
3982 proptail = XCONS (proptail)->cdr)
3983 {
3984 Lisp_Object propelt;
3985 propelt = XCONS (proptail)->car;
3986 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3987 {
3988 register Lisp_Object tem;
3989 tem = XCONS (tail)->car;
3990 if (EQ (propelt, tem))
3991 return 1;
3992 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
3993 return 1;
3994 }
3995 }
642eefc6
RS
3996 return 0;
3997}
3998
3999/* Return 1 if PROPVAL appears as the car of an element of LIST
4000 and the cdr of that element is non-nil.
af460d46
RS
4001 If PROPVAL is a list, check each element of PROPVAL in that way,
4002 and the first time some element is found,
4003 return 1 if the cdr of that element is non-nil.
642eefc6
RS
4004 Otherwise return 0.
4005 This function cannot quit. */
4006
4007int
4008invisible_ellipsis_p (propval, list)
4009 register Lisp_Object propval;
4010 Lisp_Object list;
4011{
af460d46
RS
4012 register Lisp_Object tail, proptail;
4013 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
642eefc6
RS
4014 {
4015 register Lisp_Object tem;
af460d46 4016 tem = XCONS (tail)->car;
642eefc6
RS
4017 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4018 return ! NILP (XCONS (tem)->cdr);
4019 }
af460d46
RS
4020 if (CONSP (propval))
4021 for (proptail = propval; CONSP (proptail);
4022 proptail = XCONS (proptail)->cdr)
4023 {
4024 Lisp_Object propelt;
4025 propelt = XCONS (proptail)->car;
4026 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4027 {
4028 register Lisp_Object tem;
4029 tem = XCONS (tail)->car;
4030 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4031 return ! NILP (XCONS (tem)->cdr);
4032 }
4033 }
642eefc6
RS
4034 return 0;
4035}
4036\f
a2889657
JB
4037void
4038syms_of_xdisp ()
4039{
cf074754
RS
4040 staticpro (&Qmenu_bar_update_hook);
4041 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
4042
a2889657
JB
4043 staticpro (&last_arrow_position);
4044 staticpro (&last_arrow_string);
4045 last_arrow_position = Qnil;
4046 last_arrow_string = Qnil;
4047
4048 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
8c45d522 4049 "String (or mode line construct) included (normally) in `mode-line-format'.");
a2889657
JB
4050 Vglobal_mode_string = Qnil;
4051
4052 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
4053 "Marker for where to display an arrow on top of the buffer text.\n\
4054This must be the beginning of a line in order to work.\n\
4055See also `overlay-arrow-string'.");
4056 Voverlay_arrow_position = Qnil;
4057
4058 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
4059 "String to display as an arrow. See also `overlay-arrow-position'.");
4060 Voverlay_arrow_string = Qnil;
4061
4062 DEFVAR_INT ("scroll-step", &scroll_step,
4063 "*The number of lines to try scrolling a window by when point moves out.\n\
44fa5b1e
JB
4064If that fails to bring point back on frame, point is centered instead.\n\
4065If this is zero, point is always centered after it moves off frame.");
a2889657
JB
4066
4067 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
4068
4069 DEFVAR_BOOL ("truncate-partial-width-windows",
4070 &truncate_partial_width_windows,
44fa5b1e 4071 "*Non-nil means truncate lines in all windows less than full frame wide.");
a2889657
JB
4072 truncate_partial_width_windows = 1;
4073
4074 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
4075 "*Non-nil means use inverse video for the mode line.");
4076 mode_line_inverse_video = 1;
aa6d10fa
RS
4077
4078 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
4079 "*Maximum buffer size for which line number should be displayed.");
4080 line_number_display_limit = 1000000;
fba9ce76
RS
4081
4082 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
4083 "*Non-nil means highlight region even in nonselected windows.");
4084 highlight_nonselected_windows = 1;
d39b6696
KH
4085
4086 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
3450d04c
KH
4087 "Non-nil if more than one frame is visible on this display.\n\
4088Minibuffer-only frames don't count, but iconified frames do.\n\
4089This variable is not guaranteed to be accurate except while parsing\n\
4090frame-title-format.");
d39b6696
KH
4091
4092 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
4093 "Template for displaying the titlebar of visible frames.\n\
4094\(Assuming the window manager supports this feature.)\n\
4095This variable has the same structure as `mode-line-format' (which see),\n\
4096and is used only on frames for which no explicit name has been set\n\
4097\(see `modify-frame-parameters').");
4098 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
4099 "Template for displaying the titlebar of an iconified frame.\n\
4100\(Assuming the window manager supports this feature.)\n\
4101This variable has the same structure as `mode-line-format' (which see),\n\
4102and is used only on frames for which no explicit name has been set\n\
4103\(see `modify-frame-parameters').");
4104 Vicon_title_format
4105 = Vframe_title_format
4106 = Fcons (intern ("multiple-frames"),
4107 Fcons (build_string ("%b"),
4108 Fcons (Fcons (build_string (""),
4109 Fcons (intern ("invocation-name"),
4110 Fcons (build_string ("@"),
4111 Fcons (intern ("system-name"),
4112 Qnil)))),
4113 Qnil)));
5992c4f7
KH
4114
4115 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
4116 "Maximum number of lines to keep in the message log buffer.\n\
4117If nil, disable message logging. If t, log messages but don't truncate\n\
4118the buffer when it becomes large.");
4119 XSETFASTINT (Vmessage_log_max, 50);
08b610e4
RS
4120
4121 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
4122 "Functions called before redisplay, if window sizes have changed.\n\
4123The value should be a list of functions that take one argument.\n\
4124Just before redisplay, for each frame, if any of its windows have changed\n\
4125size since the last redisplay, or have been split or deleted,\n\
4126all the functions in the list are called, with the frame as argument.");
4127 Vwindow_size_change_functions = Qnil;
a2889657
JB
4128}
4129
4130/* initialize the window system */
4131init_xdisp ()
4132{
4133 Lisp_Object root_window;
4134#ifndef COMPILER_REGISTER_BUG
4135 register
4136#endif /* COMPILER_REGISTER_BUG */
4137 struct window *mini_w;
4138
4139 this_line_bufpos = 0;
4140
4141 mini_w = XWINDOW (minibuf_window);
11e82b76 4142 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
a2889657
JB
4143
4144 echo_area_glyphs = 0;
4145 previous_echo_glyphs = 0;
4146
4147 if (!noninteractive)
4148 {
44fa5b1e 4149 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
c2213350 4150 XSETFASTINT (XWINDOW (root_window)->top, 0);
44fa5b1e 4151 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
c2213350 4152 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
a2889657
JB
4153 set_window_height (minibuf_window, 1, 0);
4154
c2213350
KH
4155 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
4156 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));
a2889657
JB
4157 }
4158}