(Fx_create_frame): Make sure icon_name is a string or nil.
[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)
94bb7f9b
KH
1253 <= BUF_SAVE_MODIFF (XBUFFER (w->buffer))))
1254 || ((!NILP (Vtransient_mark_mode)
1255 && !NILP (XBUFFER (w->buffer)->mark_active))
1256 != !NILP (w->region_showing)))
90adcf20
RS
1257 {
1258 struct buffer *prev = current_buffer;
a2725ab2
RS
1259 int count = specpdl_ptr - specpdl;
1260
eac4251c 1261 if (save_match_data)
a2725ab2
RS
1262 record_unwind_protect (Fstore_match_data, Fmatch_data ());
1263
cf074754 1264 call1 (Vrun_hooks, Qmenu_bar_update_hook);
90adcf20 1265 current_buffer = XBUFFER (w->buffer);
8351baf2 1266 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
76412d64 1267#ifdef USE_X_TOOLKIT
01a054bc 1268 set_frame_menubar (f, 0);
76412d64 1269#endif /* USE_X_TOOLKIT */
a2725ab2 1270
dcb9e676 1271 current_buffer = prev;
a2725ab2 1272 unbind_to (count, Qnil);
90adcf20
RS
1273 }
1274 }
1275}
1276\f
a2889657
JB
1277int do_id = 1;
1278
90adcf20
RS
1279/* Redisplay WINDOW and its subwindows and siblings. */
1280
a2889657
JB
1281static void
1282redisplay_windows (window)
1283 Lisp_Object window;
1284{
265a9e55 1285 for (; !NILP (window); window = XWINDOW (window)->next)
a2889657
JB
1286 redisplay_window (window, 0);
1287}
1288
90adcf20
RS
1289/* Redisplay window WINDOW and its subwindows. */
1290
a2889657
JB
1291static void
1292redisplay_window (window, just_this_one)
1293 Lisp_Object window;
1294 int just_this_one;
1295{
1296 register struct window *w = XWINDOW (window);
30c566e4 1297 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
a2889657 1298 int height;
ae3b1442 1299 register int lpoint = PT;
a2889657 1300 struct buffer *old = current_buffer;
b1d1124b 1301 register int width = window_internal_width (w) - 1;
a2889657
JB
1302 register int startp;
1303 register int hscroll = XINT (w->hscroll);
1304 struct position pos;
ae3b1442 1305 int opoint = PT;
a2889657 1306 int tem;
e481f960 1307 int update_mode_line;
23c852cb 1308 struct Lisp_Vector *dp = window_display_table (w);
a2889657 1309
44fa5b1e 1310 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
a2889657
JB
1311
1312 /* If this is a combination window, do its children; that's all. */
1313
265a9e55 1314 if (!NILP (w->vchild))
a2889657
JB
1315 {
1316 redisplay_windows (w->vchild);
1317 return;
1318 }
265a9e55 1319 if (!NILP (w->hchild))
a2889657
JB
1320 {
1321 redisplay_windows (w->hchild);
1322 return;
1323 }
265a9e55 1324 if (NILP (w->buffer))
a2889657 1325 abort ();
8de2d90b
JB
1326
1327 height = window_internal_height (w);
4d641a15 1328 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
8de2d90b
JB
1329
1330 if (MINI_WINDOW_P (w))
1331 {
1332 if (w == XWINDOW (minibuf_window))
1333 {
1334 if (echo_area_glyphs)
1335 /* We've already displayed the echo area glyphs, if any. */
88f22aff 1336 goto finish_scroll_bars;
8de2d90b
JB
1337 }
1338 else
1339 {
1340 /* This is a minibuffer, but it's not the currently active one, so
1341 clear it. */
44fa5b1e 1342 int vpos = XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top);
8de2d90b
JB
1343 int i;
1344
1345 for (i = 0; i < height; i++)
1346 {
44fa5b1e 1347 get_display_line (f, vpos + i, 0);
278feba9 1348 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
8de2d90b
JB
1349 }
1350
88f22aff 1351 goto finish_scroll_bars;
8de2d90b
JB
1352 }
1353 }
a2889657 1354
a2889657
JB
1355 /* Otherwise set up data on this window; select its buffer and point value */
1356
e481f960 1357 if (update_mode_line)
f72df6ac 1358 set_buffer_internal_1 (XBUFFER (w->buffer));
e481f960
RS
1359 else
1360 set_buffer_temp (XBUFFER (w->buffer));
1361
ae3b1442 1362 opoint = PT;
a2889657 1363
42640f83
RS
1364 /* Count number of windows showing the selected buffer.
1365 An indirect buffer counts as its base buffer. */
a2889657 1366
42640f83
RS
1367 if (!just_this_one)
1368 {
1369 struct buffer *current_base, *window_base;
1370 current_base = current_buffer;
1371 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1372 if (current_base->base_buffer)
1373 current_base = current_base->base_buffer;
1374 if (window_base->base_buffer)
1375 window_base = window_base->base_buffer;
1376 if (current_base == window_base)
1377 buffer_shared++;
1378 }
a2889657
JB
1379
1380 /* POINT refers normally to the selected window.
1381 For any other window, set up appropriate value. */
1382
1383 if (!EQ (window, selected_window))
1384 {
f67a0f51
RS
1385 int new_pt = marker_position (w->pointm);
1386 if (new_pt < BEGV)
a2889657 1387 {
f67a0f51
RS
1388 new_pt = BEGV;
1389 Fset_marker (w->pointm, make_number (new_pt), Qnil);
a2889657 1390 }
f67a0f51 1391 else if (new_pt > (ZV - 1))
a2889657 1392 {
f67a0f51
RS
1393 new_pt = ZV;
1394 Fset_marker (w->pointm, make_number (new_pt), Qnil);
a2889657 1395 }
f67a0f51
RS
1396 /* We don't use SET_PT so that the point-motion hooks don't run. */
1397 BUF_PT (current_buffer) = new_pt;
a2889657
JB
1398 }
1399
f4faa47c
JB
1400 /* If any of the character widths specified in the display table
1401 have changed, invalidate the width run cache. It's true that this
1402 may be a bit late to catch such changes, but the rest of
1403 redisplay goes (non-fatally) haywire when the display table is
1404 changed, so why should we worry about doing any better? */
1405 if (current_buffer->width_run_cache)
1406 {
1407 struct Lisp_Vector *disptab = buffer_display_table ();
1408
1409 if (! disptab_matches_widthtab (disptab,
1410 XVECTOR (current_buffer->width_table)))
1411 {
1412 invalidate_region_cache (current_buffer,
1413 current_buffer->width_run_cache,
1414 BEG, Z);
1415 recompute_width_table (current_buffer, disptab);
1416 }
1417 }
1418
a2889657 1419 /* If window-start is screwed up, choose a new one. */
a2889657
JB
1420 if (XMARKER (w->start)->buffer != current_buffer)
1421 goto recenter;
1422
1423 startp = marker_position (w->start);
1424
8de2d90b 1425 /* Handle case where place to start displaying has been specified,
aa6d10fa 1426 unless the specified location is outside the accessible range. */
265a9e55 1427 if (!NILP (w->force_start))
a2889657 1428 {
aa6d10fa
RS
1429 /* Forget any recorded base line for line number display. */
1430 w->base_line_number = Qnil;
e481f960
RS
1431 /* Redisplay the mode line. Select the buffer properly for that. */
1432 if (!update_mode_line)
1433 {
1434 set_buffer_temp (old);
f72df6ac 1435 set_buffer_internal_1 (XBUFFER (w->buffer));
e481f960
RS
1436 update_mode_line = 1;
1437 w->update_mode_line = Qt;
1438 }
a2889657 1439 w->force_start = Qnil;
c2213350 1440 XSETFASTINT (w->last_modified, 0);
8de2d90b
JB
1441 if (startp < BEGV) startp = BEGV;
1442 if (startp > ZV) startp = ZV;
a2889657
JB
1443 try_window (window, startp);
1444 if (cursor_vpos < 0)
1445 {
1446 /* If point does not appear, move point so it does appear */
1447 pos = *compute_motion (startp, 0,
ca26e1c8
KH
1448 (((EQ (window, minibuf_window)
1449 && startp == BEG)
1450 ? minibuf_prompt_width : 0)
1451 + (hscroll ? 1 - hscroll : 0)),
1452 0,
1453 ZV, height / 2,
1454 - (1 << (SHORTBITS - 1)),
1455 width, hscroll, pos_tab_offset (w, startp), w);
f67a0f51 1456 BUF_PT (current_buffer) = pos.bufpos;
90adcf20 1457 if (w != XWINDOW (selected_window))
ae3b1442 1458 Fset_marker (w->pointm, make_number (PT), Qnil);
a2889657
JB
1459 else
1460 {
9d6a6bb9 1461 if (current_buffer == old)
ae3b1442 1462 lpoint = PT;
210e752f
KH
1463 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1464 + minmax (0, pos.hpos, width));
44fa5b1e 1465 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
a2889657 1466 }
df0b5ea1
RS
1467 /* If we are highlighting the region,
1468 then we just changed the region, so redisplay to show it. */
df0b5ea1
RS
1469 if (!NILP (Vtransient_mark_mode)
1470 && !NILP (current_buffer->mark_active))
6f27fa9b
RS
1471 {
1472 cancel_my_columns (XWINDOW (window));
1473 try_window (window, startp);
1474 }
a2889657
JB
1475 }
1476 goto done;
1477 }
1478
1479 /* Handle case where text has not changed, only point,
44fa5b1e 1480 and it has not moved off the frame */
a2889657
JB
1481
1482 /* This code is not used for minibuffer for the sake of
1483 the case of redisplaying to replace an echo area message;
1484 since in that case the minibuffer contents per se are usually unchanged.
1485 This code is of no real use in the minibuffer since
1486 the handling of this_line_bufpos, etc.,
1487 in redisplay handles the same cases. */
1488
1489 if (XFASTINT (w->last_modified) >= MODIFF
ae3b1442 1490 && PT >= startp && !clip_changed
44fa5b1e 1491 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
b1aa6cb3
RS
1492 /* If force-mode-line-update was called, really redisplay;
1493 that's how redisplay is forced after e.g. changing
1494 buffer-invisibility-spec. */
632ab665 1495 && NILP (w->update_mode_line)
bd66d1ba
RS
1496 /* Can't use this case if highlighting a region. */
1497 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1498 && NILP (w->region_showing)
15495c73
KH
1499 /* If end pos is out of date, scroll bar and percentage will be wrong */
1500 && INTEGERP (w->window_end_vpos)
1501 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
a2889657
JB
1502 && !EQ (window, minibuf_window))
1503 {
ca26e1c8 1504 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0,
632ab665 1505 PT, height, 0, width, hscroll,
e37f06d7 1506 pos_tab_offset (w, startp), w);
a2889657
JB
1507
1508 if (pos.vpos < height)
1509 {
44fa5b1e
JB
1510 /* Ok, point is still on frame */
1511 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
a2889657
JB
1512 {
1513 /* These variables are supposed to be origin 1 */
210e752f
KH
1514 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1515 + minmax (0, pos.hpos, width));
44fa5b1e 1516 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
a2889657
JB
1517 }
1518 /* This doesn't do the trick, because if a window to the right of
1519 this one must be redisplayed, this does nothing because there
44fa5b1e 1520 is nothing in DesiredFrame yet, and then the other window is
a2889657 1521 redisplayed, making likes that are empty in this window's columns.
44fa5b1e 1522 if (XFASTINT (w->width) != FRAME_WIDTH (f))
a2889657
JB
1523 preserve_my_columns (w);
1524 */
1525 goto done;
1526 }
1527 /* Don't bother trying redisplay with same start;
1528 we already know it will lose */
1529 }
1530 /* If current starting point was originally the beginning of a line
1531 but no longer is, find a new starting point. */
265a9e55 1532 else if (!NILP (w->start_at_line_beg)
b16234d8 1533 && !(startp <= BEGV
a2889657
JB
1534 || FETCH_CHAR (startp - 1) == '\n'))
1535 {
1536 goto recenter;
1537 }
1538 else if (just_this_one && !MINI_WINDOW_P (w)
ae3b1442 1539 && PT >= startp
a2889657 1540 && XFASTINT (w->last_modified)
14709f21
JB
1541 /* or else vmotion on first line won't work. */
1542 && ! NILP (w->start_at_line_beg)
a2889657
JB
1543 && ! EQ (w->window_end_valid, Qnil)
1544 && do_id && !clip_changed
1545 && !blank_end_of_window
44fa5b1e 1546 && XFASTINT (w->width) == FRAME_WIDTH (f)
bd66d1ba
RS
1547 /* Can't use this case if highlighting a region. */
1548 && !(!NILP (Vtransient_mark_mode)
1549 && !NILP (current_buffer->mark_active))
23c852cb
KH
1550 /* Don't use try_window_id if newline
1551 doesn't display as the end of a line. */
1552 && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n')))
bd66d1ba 1553 && NILP (w->region_showing)
a2889657
JB
1554 && EQ (last_arrow_position, Voverlay_arrow_position)
1555 && EQ (last_arrow_string, Voverlay_arrow_string)
44fa5b1e 1556 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
a2889657
JB
1557 && tem != -2)
1558 {
1559 /* tem > 0 means success. tem == -1 means choose new start.
1560 tem == -2 means try again with same start,
1561 and nothing but whitespace follows the changed stuff.
1562 tem == 0 means try again with same start. */
1563 if (tem > 0)
1564 goto done;
1565 }
1566 else if (startp >= BEGV && startp <= ZV
1567 /* Avoid starting display at end of buffer! */
8de2d90b 1568 && (startp < ZV || startp == BEGV
a2889657
JB
1569 || (XFASTINT (w->last_modified) >= MODIFF)))
1570 {
1571 /* Try to redisplay starting at same place as before */
44fa5b1e 1572 /* If point has not moved off frame, accept the results */
a2889657
JB
1573 try_window (window, startp);
1574 if (cursor_vpos >= 0)
aa6d10fa
RS
1575 {
1576 if (!just_this_one || clip_changed || beg_unchanged < startp)
1577 /* Forget any recorded base line for line number display. */
1578 w->base_line_number = Qnil;
1579 goto done;
1580 }
a2889657
JB
1581 else
1582 cancel_my_columns (w);
1583 }
1584
c2213350 1585 XSETFASTINT (w->last_modified, 0);
e481f960
RS
1586 /* Redisplay the mode line. Select the buffer properly for that. */
1587 if (!update_mode_line)
1588 {
1589 set_buffer_temp (old);
f72df6ac 1590 set_buffer_internal_1 (XBUFFER (w->buffer));
e481f960
RS
1591 update_mode_line = 1;
1592 w->update_mode_line = Qt;
1593 }
a2889657
JB
1594
1595 /* Try to scroll by specified few lines */
1596
1597 if (scroll_step && !clip_changed)
1598 {
ae3b1442 1599 if (PT > startp)
a2889657 1600 {
210e752f 1601 pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w);
a2889657
JB
1602 if (pos.vpos >= height)
1603 goto scroll_fail;
1604 }
1605
210e752f 1606 pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w);
a2889657 1607
ae3b1442 1608 if (PT >= pos.bufpos)
a2889657
JB
1609 {
1610 try_window (window, pos.bufpos);
1611 if (cursor_vpos >= 0)
aa6d10fa
RS
1612 {
1613 if (!just_this_one || clip_changed || beg_unchanged < startp)
1614 /* Forget any recorded base line for line number display. */
1615 w->base_line_number = Qnil;
1616 goto done;
1617 }
a2889657
JB
1618 else
1619 cancel_my_columns (w);
1620 }
1621 scroll_fail: ;
1622 }
1623
1624 /* Finally, just choose place to start which centers point */
1625
1626recenter:
aa6d10fa
RS
1627 /* Forget any previously recorded base line for line number display. */
1628 w->base_line_number = Qnil;
1629
210e752f 1630 pos = *vmotion (PT, - (height / 2), w);
a2889657
JB
1631 try_window (window, pos.bufpos);
1632
1633 startp = marker_position (w->start);
ca26e1c8 1634 w->start_at_line_beg
b16234d8 1635 = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
a2889657
JB
1636
1637done:
e481f960 1638 if ((update_mode_line
aa6d10fa
RS
1639 /* If window not full width, must redo its mode line
1640 if the window to its side is being redone */
1641 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
155ef550
KH
1642 || INTEGERP (w->base_line_pos)
1643 || (!NILP (w->column_number_displayed)
1644 && XFASTINT (w->column_number_displayed) != current_column ()))
a2889657
JB
1645 && height != XFASTINT (w->height))
1646 display_mode_line (w);
aa6d10fa
RS
1647 if (! line_number_displayed
1648 && ! BUFFERP (w->base_line_pos))
1649 {
1650 w->base_line_pos = Qnil;
1651 w->base_line_number = Qnil;
1652 }
a2889657 1653
7ce2c095 1654 /* When we reach a frame's selected window, redo the frame's menu bar. */
e481f960 1655 if (update_mode_line
76412d64
RS
1656#ifdef USE_X_TOOLKIT
1657 && FRAME_EXTERNAL_MENU_BAR (f)
1658#else
7ce2c095 1659 && FRAME_MENU_BAR_LINES (f) > 0
76412d64 1660#endif
7ce2c095
RS
1661 && EQ (FRAME_SELECTED_WINDOW (f), window))
1662 display_menu_bar (w);
1663
88f22aff
JB
1664 finish_scroll_bars:
1665 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
30c566e4 1666 {
b1d1124b 1667 int start, end, whole;
30c566e4 1668
b1d1124b 1669 /* Calculate the start and end positions for the current window.
3505ea70
JB
1670 At some point, it would be nice to choose between scrollbars
1671 which reflect the whole buffer size, with special markers
1672 indicating narrowing, and scrollbars which reflect only the
1673 visible region.
1674
b1d1124b
JB
1675 Note that minibuffers sometimes aren't displaying any text. */
1676 if (! MINI_WINDOW_P (w)
1677 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1678 {
8a9311d7 1679 whole = ZV - BEGV;
4d641a15 1680 start = marker_position (w->start) - BEGV;
b1d1124b
JB
1681 /* I don't think this is guaranteed to be right. For the
1682 moment, we'll pretend it is. */
85f26be9 1683 end = (Z - XINT (w->window_end_pos)) - BEGV;
3505ea70
JB
1684
1685 if (end < start) end = start;
8a9311d7 1686 if (whole < (end - start)) whole = end - start;
b1d1124b
JB
1687 }
1688 else
1689 start = end = whole = 0;
30c566e4 1690
88f22aff 1691 /* Indicate what this scroll bar ought to be displaying now. */
7eb9ba41 1692 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
30c566e4 1693
88f22aff 1694 /* Note that we actually used the scroll bar attached to this window,
30c566e4 1695 so it shouldn't be deleted at the end of redisplay. */
88f22aff 1696 (*redeem_scroll_bar_hook) (w);
30c566e4 1697 }
b1d1124b 1698
f67a0f51 1699 BUF_PT (current_buffer) = opoint;
e481f960 1700 if (update_mode_line)
f72df6ac 1701 set_buffer_internal_1 (old);
e481f960
RS
1702 else
1703 set_buffer_temp (old);
f67a0f51 1704 BUF_PT (current_buffer) = lpoint;
a2889657
JB
1705}
1706\f
1707/* Do full redisplay on one window, starting at position `pos'. */
1708
1709static void
1710try_window (window, pos)
1711 Lisp_Object window;
1712 register int pos;
1713{
1714 register struct window *w = XWINDOW (window);
1715 register int height = window_internal_height (w);
1716 register int vpos = XFASTINT (w->top);
1717 register int last_text_vpos = vpos;
1718 int tab_offset = pos_tab_offset (w, pos);
44fa5b1e 1719 FRAME_PTR f = XFRAME (w->frame);
b1d1124b 1720 int width = window_internal_width (w) - 1;
a2889657
JB
1721 struct position val;
1722
1723 Fset_marker (w->start, make_number (pos), Qnil);
1724 cursor_vpos = -1;
1725 overlay_arrow_seen = 0;
ca26e1c8 1726 zv_strings_seen = 0;
a2889657
JB
1727 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1728
1729 while (--height >= 0)
1730 {
1731 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1732 tab_offset += width;
2b050fec
RS
1733 /* For the first line displayed, display_text_line
1734 subtracts the prompt width from the tab offset.
1735 But it does not affect the value of our variable tab_offset.
1736 So we do the subtraction again,
1737 for the sake of continuation lines of that first line. */
1738 if (MINI_WINDOW_P (w) && vpos == XFASTINT (w->top))
1739 tab_offset -= minibuf_prompt_width;
1740
a2889657
JB
1741 if (val.vpos) tab_offset = 0;
1742 vpos++;
1743 if (pos != val.bufpos)
642eefc6
RS
1744 {
1745 int invis = 0;
e885523c 1746#ifdef USE_TEXT_PROPERTIES
642eefc6
RS
1747 Lisp_Object invis_prop;
1748 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
1749 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
e885523c 1750#endif
642eefc6
RS
1751
1752 last_text_vpos
1753 /* Next line, unless prev line ended in end of buffer with no cr */
1754 = vpos - (val.vpos
1755 && (FETCH_CHAR (val.bufpos - 1) != '\n' || invis));
1756 }
a2889657
JB
1757 pos = val.bufpos;
1758 }
1759
1760 /* If last line is continued in middle of character,
44fa5b1e 1761 include the split character in the text considered on the frame */
a2889657
JB
1762 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1763 pos++;
1764
44fa5b1e 1765 /* If bottom just moved off end of frame, change mode line percentage. */
a2889657
JB
1766 if (XFASTINT (w->window_end_pos) == 0
1767 && Z != pos)
1768 w->update_mode_line = Qt;
1769
44fa5b1e 1770 /* Say where last char on frame will be, once redisplay is finished. */
c2213350
KH
1771 XSETFASTINT (w->window_end_pos, Z - pos);
1772 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
a2889657
JB
1773 /* But that is not valid info until redisplay finishes. */
1774 w->window_end_valid = Qnil;
1775}
1776\f
1777/* Try to redisplay when buffer is modified locally,
1778 computing insert/delete line to preserve text outside
1779 the bounds of the changes.
1780 Return 1 if successful, 0 if if cannot tell what to do,
1781 or -1 to tell caller to find a new window start,
1782 or -2 to tell caller to do normal redisplay with same window start. */
1783
1784static int
1785try_window_id (window)
1786 Lisp_Object window;
1787{
1788 int pos;
1789 register struct window *w = XWINDOW (window);
1790 register int height = window_internal_height (w);
44fa5b1e 1791 FRAME_PTR f = XFRAME (w->frame);
a2889657
JB
1792 int top = XFASTINT (w->top);
1793 int start = marker_position (w->start);
b1d1124b 1794 int width = window_internal_width (w) - 1;
a2889657
JB
1795 int hscroll = XINT (w->hscroll);
1796 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
ca26e1c8 1797 int did_motion;
a2889657
JB
1798 register int vpos;
1799 register int i, tem;
1800 int last_text_vpos = 0;
1801 int stop_vpos;
e24c997d
KH
1802 int selective = (INTEGERP (current_buffer->selective_display)
1803 ? XINT (current_buffer->selective_display)
1804 : !NILP (current_buffer->selective_display) ? -1 : 0);
a2889657
JB
1805
1806 struct position val, bp, ep, xp, pp;
1807 int scroll_amount = 0;
1808 int delta;
1809 int tab_offset, epto;
1810
1811 if (GPT - BEG < beg_unchanged)
1812 beg_unchanged = GPT - BEG;
1813 if (Z - GPT < end_unchanged)
1814 end_unchanged = Z - GPT;
1815
6a1dc7ac 1816 if (beg_unchanged + BEG < start)
a2889657
JB
1817 return 0; /* Give up if changes go above top of window */
1818
1819 /* Find position before which nothing is changed. */
ca26e1c8 1820 bp = *compute_motion (start, 0, lmargin, 0,
632ab665 1821 min (ZV, beg_unchanged + BEG), height, 0,
e37f06d7 1822 width, hscroll, pos_tab_offset (w, start), w);
a2889657 1823 if (bp.vpos >= height)
6e8290aa 1824 {
632ab665 1825 if (PT < bp.bufpos)
6e8290aa 1826 {
44fa5b1e
JB
1827 /* All changes are below the frame, and point is on the frame.
1828 We don't need to change the frame at all.
6e8290aa
JB
1829 But we need to update window_end_pos to account for
1830 any change in buffer size. */
ca26e1c8 1831 bp = *compute_motion (start, 0, lmargin, 0,
f7be7f78 1832 Z, height, 0,
e37f06d7 1833 width, hscroll, pos_tab_offset (w, start), w);
c2213350
KH
1834 XSETFASTINT (w->window_end_vpos, height);
1835 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
4d641a15 1836 goto findpoint;
6e8290aa
JB
1837 }
1838 return 0;
1839 }
a2889657
JB
1840
1841 vpos = bp.vpos;
1842
44fa5b1e 1843 /* Find beginning of that frame line. Must display from there. */
210e752f 1844 bp = *vmotion (bp.bufpos, 0, w);
a2889657
JB
1845
1846 pos = bp.bufpos;
1847 val.hpos = lmargin;
1848 if (pos < start)
1849 return -1;
1850
ca26e1c8 1851 did_motion = 0;
a2889657 1852 /* If about to start displaying at the beginning of a continuation line,
44fa5b1e 1853 really start with previous frame line, in case it was not
a2889657 1854 continued when last redisplayed */
05ba02eb
JB
1855 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
1856 ||
1857 /* Likewise if we have to worry about selective display. */
9f412332 1858 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
a2889657 1859 {
210e752f 1860 bp = *vmotion (bp.bufpos, -1, w);
a2889657
JB
1861 --vpos;
1862 pos = bp.bufpos;
1863 }
1864
1865 if (bp.contin && bp.hpos != lmargin)
1866 {
1867 val.hpos = bp.prevhpos - width + lmargin;
ca26e1c8 1868 did_motion = 1;
a2889657
JB
1869 pos--;
1870 }
1871
1872 bp.vpos = vpos;
1873
1874 /* Find first visible newline after which no more is changed. */
1875 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
9f412332
KH
1876 if (selective > 0)
1877 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
a2889657
JB
1878 tem = find_next_newline (tem, 1);
1879
1880 /* Compute the cursor position after that newline. */
ca26e1c8 1881 ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem,
a2889657 1882 height, - (1 << (SHORTBITS - 1)),
e37f06d7 1883 width, hscroll, pos_tab_offset (w, bp.bufpos), w);
a2889657 1884
44fa5b1e
JB
1885 /* If changes reach past the text available on the frame,
1886 just display rest of frame. */
a2889657
JB
1887 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
1888 stop_vpos = height;
1889 else
1890 stop_vpos = ep.vpos;
1891
1892 /* If no newline before ep, the line ep is on includes some changes
1893 that must be displayed. Make sure we don't stop before it. */
1894 /* Also, if changes reach all the way until ep.bufpos,
1895 it is possible that something was deleted after the
1896 newline before it, so the following line must be redrawn. */
1897 if (stop_vpos == ep.vpos
1898 && (ep.bufpos == BEGV
1899 || FETCH_CHAR (ep.bufpos - 1) != '\n'
1900 || ep.bufpos == Z - end_unchanged))
1901 stop_vpos = ep.vpos + 1;
1902
1903 cursor_vpos = -1;
1904 overlay_arrow_seen = 0;
ca26e1c8 1905 zv_strings_seen = 0;
a2889657
JB
1906
1907 /* If changes do not reach to bottom of window,
1908 figure out how much to scroll the rest of the window */
1909 if (stop_vpos < height)
1910 {
1911 /* Now determine how far up or down the rest of the window has moved */
1912 epto = pos_tab_offset (w, ep.bufpos);
ca26e1c8 1913 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
a2889657 1914 Z - XFASTINT (w->window_end_pos),
e37f06d7 1915 10000, 0, width, hscroll, epto, w);
a2889657
JB
1916 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
1917
44fa5b1e 1918 /* Is everything on frame below the changes whitespace?
a2889657
JB
1919 If so, no scrolling is really necessary. */
1920 for (i = ep.bufpos; i < xp.bufpos; i++)
1921 {
1922 tem = FETCH_CHAR (i);
1923 if (tem != ' ' && tem != '\n' && tem != '\t')
1924 break;
1925 }
1926 if (i == xp.bufpos)
1927 return -2;
1928
e8e536a9
KH
1929 XSETFASTINT (w->window_end_vpos,
1930 XFASTINT (w->window_end_vpos) + scroll_amount);
a2889657 1931
44fa5b1e 1932 /* Before doing any scrolling, verify that point will be on frame. */
ae3b1442 1933 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height))
a2889657 1934 {
ae3b1442 1935 if (PT <= xp.bufpos)
a2889657 1936 {
ca26e1c8 1937 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
ae3b1442 1938 PT, height, - (1 << (SHORTBITS - 1)),
e37f06d7 1939 width, hscroll, epto, w);
a2889657
JB
1940 }
1941 else
1942 {
ca26e1c8 1943 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1,
ae3b1442 1944 PT, height, - (1 << (SHORTBITS - 1)),
e37f06d7
KH
1945 width, hscroll,
1946 pos_tab_offset (w, xp.bufpos), w);
a2889657 1947 }
ae3b1442 1948 if (pp.bufpos < PT || pp.vpos == height)
a2889657
JB
1949 return 0;
1950 cursor_vpos = pp.vpos + top;
210e752f 1951 cursor_hpos = XFASTINT (w->left) + minmax (0, pp.hpos, width);
a2889657
JB
1952 }
1953
1954 if (stop_vpos - scroll_amount >= height
1955 || ep.bufpos == xp.bufpos)
1956 {
1957 if (scroll_amount < 0)
1958 stop_vpos -= scroll_amount;
1959 scroll_amount = 0;
1960 /* In this path, we have altered window_end_vpos
1961 and not left it negative.
1962 We must make sure that, in case display is preempted
44fa5b1e 1963 before the frame changes to reflect what we do here,
a2889657 1964 further updates will not come to try_window_id
44fa5b1e 1965 and assume the frame and window_end_vpos match. */
a2889657
JB
1966 blank_end_of_window = 1;
1967 }
1968 else if (!scroll_amount)
0d231165
RS
1969 {
1970 /* Even if we don't need to scroll, we must adjust the
1971 charstarts of subsequent lines (that we won't redisplay)
1972 according to the amount of text inserted or deleted. */
1973 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1974 int adjust = ep.bufpos - oldpos;
1975 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
1976 }
a2889657
JB
1977 else if (bp.bufpos == Z - end_unchanged)
1978 {
1979 /* If reprinting everything is nearly as fast as scrolling,
1980 don't bother scrolling. Can happen if lines are short. */
44fa5b1e 1981 if (scroll_cost (f, bp.vpos + top - scroll_amount,
a2889657
JB
1982 top + height - max (0, scroll_amount),
1983 scroll_amount)
1984 > xp.bufpos - bp.bufpos - 20)
1985 /* Return "try normal display with same window-start."
1986 Too bad we can't prevent further scroll-thinking. */
1987 return -2;
1988 /* If pure deletion, scroll up as many lines as possible.
1989 In common case of killing a line, this can save the
1990 following line from being overwritten by scrolling
1991 and therefore having to be redrawn. */
44fa5b1e 1992 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
d1cb44a4
RS
1993 top + height - max (0, scroll_amount),
1994 scroll_amount, bp.bufpos);
d2f84654
RS
1995 if (!tem)
1996 stop_vpos = height;
1997 else
1998 {
1999 /* scroll_frame_lines did not properly adjust subsequent
2000 lines' charstarts in the case where the text of the
2001 screen line at bp.vpos has changed.
2002 (This can happen in a deletion that ends in mid-line.)
2003 To adjust properly, we need to make things constent at
2004 the position ep.
2005 So do a second adjust to make that happen.
2006 Note that stop_vpos >= ep.vpos, so it is sufficient
2007 to update the charstarts for lines at ep.vpos and below. */
2008 int oldstart
2009 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2010 adjust_window_charstarts (w, ep.vpos + top - 1,
2011 ep.bufpos - oldstart);
2012 }
a2889657
JB
2013 }
2014 else if (scroll_amount)
2015 {
2016 /* If reprinting everything is nearly as fast as scrolling,
2017 don't bother scrolling. Can happen if lines are short. */
2018 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2019 overestimate of cost of reprinting, since xp.bufpos
2020 would end up below the bottom of the window. */
44fa5b1e 2021 if (scroll_cost (f, ep.vpos + top - scroll_amount,
a2889657
JB
2022 top + height - max (0, scroll_amount),
2023 scroll_amount)
2024 > xp.bufpos - ep.bufpos - 20)
2025 /* Return "try normal display with same window-start."
2026 Too bad we can't prevent further scroll-thinking. */
2027 return -2;
44fa5b1e 2028 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
a2889657 2029 top + height - max (0, scroll_amount),
d1cb44a4 2030 scroll_amount, ep.bufpos);
a2889657
JB
2031 if (!tem) stop_vpos = height;
2032 }
2033 }
2034
2035 /* In any case, do not display past bottom of window */
2036 if (stop_vpos >= height)
2037 {
2038 stop_vpos = height;
2039 scroll_amount = 0;
2040 }
2041
2042 /* Handle case where pos is before w->start --
2043 can happen if part of line had been clipped and is not clipped now */
2044 if (vpos == 0 && pos < marker_position (w->start))
2045 Fset_marker (w->start, make_number (pos), Qnil);
2046
2047 /* Redisplay the lines where the text was changed */
2048 last_text_vpos = vpos;
2049 tab_offset = pos_tab_offset (w, pos);
2050 /* If we are starting display in mid-character, correct tab_offset
2051 to account for passing the line that that character really starts in. */
2052 if (val.hpos < lmargin)
2053 tab_offset += width;
2054 while (vpos < stop_vpos)
2055 {
2056 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2057 tab_offset += width;
2058 if (val.vpos) tab_offset = 0;
2059 if (pos != val.bufpos)
2060 last_text_vpos
2061 /* Next line, unless prev line ended in end of buffer with no cr */
2062 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
2063 pos = val.bufpos;
2064 }
2065
2066 /* There are two cases:
2067 1) we have displayed down to the bottom of the window
2068 2) we have scrolled lines below stop_vpos by scroll_amount */
2069
2070 if (vpos == height)
2071 {
2072 /* If last line is continued in middle of character,
44fa5b1e 2073 include the split character in the text considered on the frame */
a2889657
JB
2074 if (val.hpos < lmargin)
2075 val.bufpos++;
c2213350
KH
2076 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2077 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
a2889657
JB
2078 }
2079
2080 /* If scrolling made blank lines at window bottom,
2081 redisplay to fill those lines */
2082 if (scroll_amount < 0)
2083 {
2084 /* Don't consider these lines for general-purpose scrolling.
2085 That will save time in the scrolling computation. */
44fa5b1e 2086 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
a2889657
JB
2087 vpos = xp.vpos;
2088 pos = xp.bufpos;
2089 val.hpos = lmargin;
2090 if (pos == ZV)
2091 vpos = height + scroll_amount;
2092 else if (xp.contin && xp.hpos != lmargin)
2093 {
2094 val.hpos = xp.prevhpos - width + lmargin;
2095 pos--;
2096 }
2097
2098 blank_end_of_window = 1;
2099 tab_offset = pos_tab_offset (w, pos);
2100 /* If we are starting display in mid-character, correct tab_offset
2101 to account for passing the line that that character starts in. */
2102 if (val.hpos < lmargin)
2103 tab_offset += width;
2104
2105 while (vpos < height)
2106 {
2107 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2108 tab_offset += width;
2109 if (val.vpos) tab_offset = 0;
2110 pos = val.bufpos;
2111 }
2112
2113 /* Here is a case where display_text_line sets cursor_vpos wrong.
2114 Make it be fixed up, below. */
2115 if (xp.bufpos == ZV
ae3b1442 2116 && xp.bufpos == PT)
a2889657
JB
2117 cursor_vpos = -1;
2118 }
2119
44fa5b1e 2120 /* If bottom just moved off end of frame, change mode line percentage. */
a2889657
JB
2121 if (XFASTINT (w->window_end_pos) == 0
2122 && Z != val.bufpos)
2123 w->update_mode_line = Qt;
2124
2125 /* Attempt to adjust end-of-text positions to new bottom line */
2126 if (scroll_amount)
2127 {
2128 delta = height - xp.vpos;
2129 if (delta < 0
2130 || (delta > 0 && xp.bufpos <= ZV)
2131 || (delta == 0 && xp.hpos))
2132 {
210e752f 2133 val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w);
c2213350 2134 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
e8e536a9
KH
2135 XSETFASTINT (w->window_end_vpos,
2136 XFASTINT (w->window_end_vpos) + val.vpos);
a2889657
JB
2137 }
2138 }
2139
2140 w->window_end_valid = Qnil;
2141
2142 /* If point was not in a line that was displayed, find it */
2143 if (cursor_vpos < 0)
2144 {
4d641a15 2145 findpoint:
ca26e1c8 2146 val = *compute_motion (start, 0, lmargin, 0, PT, 10000, 10000,
e37f06d7 2147 width, hscroll, pos_tab_offset (w, start), w);
44fa5b1e 2148 /* Admit failure if point is off frame now */
a2889657
JB
2149 if (val.vpos >= height)
2150 {
2151 for (vpos = 0; vpos < height; vpos++)
44fa5b1e 2152 cancel_line (vpos + top, f);
a2889657
JB
2153 return 0;
2154 }
2155 cursor_vpos = val.vpos + top;
210e752f 2156 cursor_hpos = XFASTINT (w->left) + minmax (0, val.hpos, width);
a2889657
JB
2157 }
2158
210e752f 2159 FRAME_CURSOR_X (f) = cursor_hpos;
44fa5b1e 2160 FRAME_CURSOR_Y (f) = cursor_vpos;
a2889657
JB
2161
2162 if (debug_end_pos)
2163 {
ca26e1c8 2164 val = *compute_motion (start, 0, lmargin, 0, ZV,
a2889657 2165 height, - (1 << (SHORTBITS - 1)),
e37f06d7 2166 width, hscroll, pos_tab_offset (w, start), w);
a2889657
JB
2167 if (val.vpos != XFASTINT (w->window_end_vpos))
2168 abort ();
2169 if (XFASTINT (w->window_end_pos)
2170 != Z - val.bufpos)
2171 abort ();
2172 }
2173
2174 return 1;
2175}
2176\f
31b24551
JB
2177/* Mark a section of BUF as modified, but only for the sake of redisplay.
2178 This is useful for recording changes to overlays.
2179
2180 We increment the buffer's modification timestamp and set the
2181 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
2182 as if the region of text between START and END had been modified;
2183 the redisplay code will check this against the windows' timestamps,
2184 and redraw the appropriate area of the buffer.
2185
2186 However, if the buffer is unmodified, we bump the last-save
2187 timestamp as well, so that incrementing the timestamp doesn't fool
2188 Emacs into thinking that the buffer's text has been modified.
2189
2190 Tweaking the timestamps shouldn't hurt the first-modification
2191 timestamps recorded in the undo records; those values aren't
2192 written until just before a real text modification is made, so they
2193 will never catch the timestamp value just before this function gets
2194 called. */
2195
2196void
2197redisplay_region (buf, start, end)
2198 struct buffer *buf;
2199 int start, end;
2200{
2201 if (start == end)
2202 return;
2203
2204 if (start > end)
2205 {
2206 int temp = start;
2207 start = end; end = temp;
2208 }
2209
70bcb498
RS
2210 /* If this is a buffer not in the selected window,
2211 we must do other windows. */
2212 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2213 windows_or_buffers_changed = 1;
99b9e975
RS
2214 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2215 else if (buf != current_buffer)
2216 windows_or_buffers_changed = 1;
70bcb498
RS
2217 /* If multiple windows show this buffer, we must do other windows. */
2218 else if (buffer_shared > 1)
31b24551
JB
2219 windows_or_buffers_changed = 1;
2220 else
2221 {
2222 if (unchanged_modified == MODIFF)
2223 {
2224 beg_unchanged = start - BEG;
2225 end_unchanged = Z - end;
2226 }
2227 else
2228 {
2229 if (Z - end < end_unchanged)
2230 end_unchanged = Z - end;
2231 if (start - BEG < beg_unchanged)
2232 beg_unchanged = start - BEG;
2233 }
2234 }
2235
2236 /* Increment the buffer's time stamp, but also increment the save
42640f83
RS
2237 and autosave timestamps, so as not to screw up that timekeeping. */
2238 if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf))
2239 BUF_SAVE_MODIFF (buf)++;
31b24551
JB
2240 if (BUF_MODIFF (buf) == buf->auto_save_modified)
2241 buf->auto_save_modified++;
2242
2243 BUF_MODIFF (buf) ++;
2244}
2245
2246\f
278feba9 2247/* Copy LEN glyphs starting address FROM to the rope TO.
f7430cb6 2248 But don't actually copy the parts that would come in before S.
278feba9
RS
2249 Value is TO, advanced past the copied data.
2250 F is the frame we are displaying in. */
a2889657 2251
278feba9
RS
2252static GLYPH *
2253copy_part_of_rope (f, to, s, from, len, face)
2254 FRAME_PTR f;
2255 register GLYPH *to; /* Copy to here. */
a2889657 2256 register GLYPH *s; /* Starting point. */
278feba9
RS
2257 Lisp_Object *from; /* Data to copy. */
2258 int len;
1c2250c2 2259 int face; /* Face to apply to glyphs which don't specify one. */
a2889657 2260{
278feba9
RS
2261 int n = len;
2262 register Lisp_Object *fp = from;
2263 /* These cache the results of the last call to compute_glyph_face. */
2264 int last_code = -1;
2265 int last_merged = 0;
c581d710 2266
87485d6f 2267#ifdef HAVE_FACES
4cdc65eb
KH
2268 if (! FRAME_TERMCAP_P (f))
2269 while (n--)
2270 {
dedd1182 2271 int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
4cdc65eb
KH
2272 int facecode;
2273
2274 if (FAST_GLYPH_FACE (glyph) == 0)
2275 /* If GLYPH has no face code, use FACE. */
2276 facecode = face;
2277 else if (FAST_GLYPH_FACE (glyph) == last_code)
2278 /* If it's same as previous glyph, use same result. */
2279 facecode = last_merged;
2280 else
2281 {
2282 /* Merge this glyph's face and remember the result. */
2283 last_code = FAST_GLYPH_FACE (glyph);
2284 last_merged = facecode = compute_glyph_face (f, last_code, face);
2285 }
b2a76982 2286
4cdc65eb
KH
2287 if (to >= s)
2288 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
2289 ++to;
2290 ++fp;
2291 }
2292 else
2293#endif
2294 while (n--)
2295 {
dedd1182 2296 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
4cdc65eb
KH
2297 ++to;
2298 ++fp;
2299 }
278feba9 2300 return to;
c581d710
RS
2301}
2302
278feba9
RS
2303/* Correct a glyph by replacing its specified user-level face code
2304 with a displayable computed face code. */
c581d710 2305
278feba9 2306static GLYPH
659a218f 2307fix_glyph (f, glyph, cface)
278feba9
RS
2308 FRAME_PTR f;
2309 GLYPH glyph;
659a218f 2310 int cface;
c581d710 2311{
87485d6f 2312#ifdef HAVE_FACES
659a218f
KH
2313 if (! FRAME_TERMCAP_P (f))
2314 {
2315 if (FAST_GLYPH_FACE (glyph) != 0)
2316 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2317 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2318 }
4cdc65eb
KH
2319#endif
2320 return glyph;
a2889657
JB
2321}
2322\f
f4faa47c
JB
2323/* Display one line of window W, starting at position START in W's buffer.
2324
2325 Display starting at horizontal position HPOS, expressed relative to
2326 W's left edge. In situations where the text at START shouldn't
2327 start at the left margin (i.e. when the window is hscrolled, or
2328 we're continuing a line which left off in the midst of a
2329 multi-column character), HPOS should be negative; we throw away
2330 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2331 account.
a2889657
JB
2332
2333 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2334
f4faa47c
JB
2335 Display on position VPOS on the frame. It is origin 0, relative to
2336 the top of the frame, not W.
a2889657
JB
2337
2338 Returns a STRUCT POSITION giving character to start next line with
2339 and where to display it, including a zero or negative hpos.
2340 The vpos field is not really a vpos; it is 1 unless the line is continued */
2341
2342struct position val_display_text_line;
2343
2344static struct position *
2345display_text_line (w, start, vpos, hpos, taboffset)
2346 struct window *w;
2347 int start;
2348 int vpos;
2349 int hpos;
2350 int taboffset;
2351{
2352 register int pos = start;
2353 register int c;
2354 register GLYPH *p1;
a2889657
JB
2355 register int pause;
2356 register unsigned char *p;
2357 GLYPH *endp;
d2f84654 2358 register GLYPH *leftmargin;
ca26e1c8 2359 register GLYPH *p1prev;
efc63ef0 2360 register GLYPH *p1start;
ca26e1c8 2361 int prevpos;
efc63ef0 2362 int *charstart;
44fa5b1e 2363 FRAME_PTR f = XFRAME (w->frame);
a2889657 2364 int tab_width = XINT (current_buffer->tab_width);
265a9e55 2365 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
b1d1124b 2366 int width = window_internal_width (w) - 1;
a2889657
JB
2367 struct position val;
2368 int lastpos;
2369 int invis;
642eefc6
RS
2370 int last_invis_skip = 0;
2371 Lisp_Object last_invis_prop;
a2889657 2372 int hscroll = XINT (w->hscroll);
d2f84654
RS
2373 int truncate = (hscroll
2374 || (truncate_partial_width_windows
2375 && XFASTINT (w->width) < FRAME_WIDTH (f))
2376 || !NILP (current_buffer->truncate_lines));
bd66d1ba
RS
2377
2378 /* 1 if we should highlight the region. */
2379 int highlight_region
2380 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
2381 int region_beg, region_end;
2382
e24c997d
KH
2383 int selective = (INTEGERP (current_buffer->selective_display)
2384 ? XINT (current_buffer->selective_display)
2385 : !NILP (current_buffer->selective_display) ? -1 : 0);
44fa5b1e 2386 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
a2889657 2387 register struct Lisp_Vector *dp = window_display_table (w);
68a37fa8
RS
2388
2389 Lisp_Object default_invis_vector[3];
642eefc6
RS
2390 /* Number of characters of ellipsis to display after an invisible line
2391 if it calls for an ellipsis.
2392 Note that this value can be nonzero regardless of whether
2393 selective display is enabled--you must check that separately. */
a2889657 2394 int selective_rlen
642eefc6 2395 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
68a37fa8 2396 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
642eefc6 2397 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
68a37fa8
RS
2398 /* This is the sequence of Lisp objects to display
2399 when there are invisible lines. */
2400 Lisp_Object *invis_vector_contents
e24c997d 2401 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
68a37fa8
RS
2402 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2403 : default_invis_vector);
2404
e24c997d 2405 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
278feba9 2406 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
e24c997d 2407 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
278feba9 2408 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
a2889657 2409
31b24551
JB
2410 /* The next buffer location at which the face should change, due
2411 to overlays or text property changes. */
2412 int next_face_change;
2413
ca26e1c8
KH
2414 /* The next location where the `invisible' property changes, or an
2415 overlay starts or ends. */
2416 int next_boundary;
2417
31b24551 2418 /* The face we're currently using. */
1c2250c2 2419 int current_face = 0;
efc63ef0 2420 int i;
31b24551 2421
c2213350 2422 XSETFASTINT (default_invis_vector[2], '.');
68a37fa8
RS
2423 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2424
a2889657 2425 hpos += XFASTINT (w->left);
44fa5b1e 2426 get_display_line (f, vpos, XFASTINT (w->left));
54ff581a 2427 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
a2889657 2428
bd66d1ba 2429 /* Show where to highlight the region. */
1613b757 2430 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
fba9ce76
RS
2431 /* Maybe highlight only in selected window. */
2432 && (highlight_nonselected_windows
6f139a45 2433 || w == XWINDOW (selected_window)))
bd66d1ba
RS
2434 {
2435 region_beg = marker_position (current_buffer->mark);
2436 if (PT < region_beg)
2437 {
2438 region_end = region_beg;
2439 region_beg = PT;
2440 }
2441 else
2442 region_end = PT;
2443 w->region_showing = Qt;
2444 }
2445 else
2446 region_beg = region_end = -1;
2447
f4faa47c 2448 if (MINI_WINDOW_P (w)
ca26e1c8 2449 && start == BEG
a2889657
JB
2450 && vpos == XFASTINT (w->top))
2451 {
8c5b6a0a 2452 if (! NILP (minibuf_prompt))
f7b4b63a
KH
2453 {
2454 minibuf_prompt_width
8c5b6a0a
KH
2455 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2456 XSTRING (minibuf_prompt)->size, hpos,
ce006f69
RS
2457 /* Display a space if we truncate. */
2458 ' ',
2459 1, -1,
2460 /* Truncate the prompt a little before the
2461 margin, so user input can at least start
2462 on the first line. */
2463 w->width > 10 ? w->width - 4 : -1)
f7b4b63a
KH
2464 - hpos);
2465 hpos += minibuf_prompt_width;
2b050fec 2466 taboffset -= minibuf_prompt_width;
f7b4b63a
KH
2467 }
2468 else
2469 minibuf_prompt_width = 0;
a2889657
JB
2470 }
2471
f4faa47c
JB
2472 /* If we're hscrolled at all, use compute_motion to skip over any
2473 text off the left edge of the window. compute_motion may know
2474 tricks to do this faster than we can. */
2475 if (hpos < 0)
2476 {
2477 struct position *left_edge
ca26e1c8
KH
2478 = compute_motion (pos, vpos, hpos, 0,
2479 ZV, vpos, 0,
f4faa47c
JB
2480 width, hscroll, taboffset, w);
2481
2482 /* Retrieve the buffer position and column provided by
2483 compute_motion. We can't assume that the column will be
2484 zero, because you may have multi-column characters crossing
2485 the left margin.
2486
2487 compute_motion may have moved us past the screen position we
2488 requested, if we hit a multi-column character, or the end of
2489 the line. If so, back up. */
2490 if (left_edge->vpos > vpos
2491 || left_edge->hpos > 0)
2492 {
2493 pos = left_edge->bufpos - 1;
2494 hpos = left_edge->prevhpos;
2495 }
2496 else
2497 {
2498 pos = left_edge->bufpos;
2499 hpos = left_edge->hpos;
2500 }
2501 }
2502
2503 desired_glyphs->bufp[vpos] = start;
a2889657 2504 p1 = desired_glyphs->glyphs[vpos] + hpos;
efc63ef0
RS
2505 p1start = p1;
2506 charstart = desired_glyphs->charstarts[vpos] + hpos;
2507 /* In case we don't ever write anything into it... */
a007eef6 2508 desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1;
d2f84654
RS
2509 leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2510 endp = leftmargin + width;
a2889657 2511
1c2250c2
JB
2512 /* Arrange the overlays nicely for our purposes. Usually, we call
2513 display_text_line on only one line at a time, in which case this
2514 can't really hurt too much, or we call it on lines which appear
2515 one after another in the buffer, in which case all calls to
2516 recenter_overlay_lists but the first will be pretty cheap. */
2517 recenter_overlay_lists (current_buffer, pos);
2518
a2889657
JB
2519 /* Loop generating characters.
2520 Stop at end of buffer, before newline,
31b24551
JB
2521 if reach or pass continuation column,
2522 or at face change. */
a2889657 2523 pause = pos;
31b24551 2524 next_face_change = pos;
ca26e1c8
KH
2525 next_boundary = pos;
2526 p1prev = p1;
2527 prevpos = pos;
85bcef6c 2528 while (1)
a2889657 2529 {
31b24551 2530 if (pos >= pause)
a2889657 2531 {
ca26e1c8 2532 while (pos == next_boundary)
a2889657 2533 {
ca26e1c8
KH
2534 Lisp_Object position, limit, prop, ww;
2535
2536 /* Display the overlay strings here, unless we're at ZV
2537 and have already displayed the appropriate strings
2538 on an earlier line. */
2539 if (pos < ZV || !zv_strings_seen++)
2540 {
2541 int ovlen;
2542 char *ovstr;
2543 ovlen = overlay_strings (pos, w, &ovstr);
2544 for (; ovlen; ovlen--, ovstr++)
2545 {
2546 if (p1 >= leftmargin && p1 < endp)
2547 *p1 = MAKE_GLYPH (f, *ovstr, current_face);
2548 p1++;
2549 }
2550 }
2551
2552 /* Did we reach point? Record the cursor location. */
2553 if (pos == PT && cursor_vpos < 0)
2554 {
2555 cursor_vpos = vpos;
2556 cursor_hpos = p1 - leftmargin;
2557 }
2558
2559 if (pos >= ZV)
2560 break;
a2889657 2561
c2213350 2562 XSETFASTINT (position, pos);
ca26e1c8
KH
2563 limit = Fnext_overlay_change (position);
2564#ifdef USE_TEXT_PROPERTIES
dfabd9a0
RS
2565 /* This is just an estimate to give reasonable
2566 performance; nothing should go wrong if it is too small. */
fe3d6921 2567 if (XFASTINT (limit) > pos + 50)
c2213350 2568 XSETFASTINT (limit, pos + 50);
ca26e1c8
KH
2569 limit = Fnext_single_property_change (position, Qinvisible,
2570 Fcurrent_buffer (), limit);
2571#endif
2572 next_boundary = XFASTINT (limit);
2573 /* if the `invisible' property is set, we can skip to
2574 the next property change. */
2575 XSETWINDOW (ww, w);
2576 prop = Fget_char_property (position, Qinvisible, ww);
642eefc6 2577 if (TEXT_PROP_MEANS_INVISIBLE (prop))
dfabd9a0 2578 {
ca26e1c8 2579 if (pos < PT && next_boundary >= PT)
dfabd9a0
RS
2580 {
2581 cursor_vpos = vpos;
d2f84654 2582 cursor_hpos = p1 - leftmargin;
dfabd9a0 2583 }
ca26e1c8 2584 pos = next_boundary;
642eefc6
RS
2585 last_invis_skip = pos;
2586 last_invis_prop = prop;
dfabd9a0 2587 }
b0a0fbda 2588 }
ca26e1c8
KH
2589
2590 /* Did we reach point? Record the cursor location. */
2591 if (pos == PT && cursor_vpos < 0)
2592 {
2593 cursor_vpos = vpos;
2594 cursor_hpos = p1 - leftmargin;
2595 }
2596
2597 /* Did we hit the end of the visible region of the buffer?
2598 Stop here. */
2599 if (pos >= ZV)
b0a0fbda 2600 break;
b0a0fbda 2601
87485d6f 2602#ifdef HAVE_FACES
31b24551
JB
2603 /* Did we hit a face change? Figure out what face we should
2604 use now. We also hit this the first time through the
2605 loop, to see what face we should start with. */
b0a0fbda 2606 if (pos >= next_face_change && FRAME_X_P (f))
bd66d1ba
RS
2607 current_face = compute_char_face (f, w, pos,
2608 region_beg, region_end,
efc63ef0 2609 &next_face_change, pos + 50, 0);
9dbd4b48 2610#endif
31b24551 2611
ca26e1c8 2612 pause = ZV;
1c2250c2 2613
ca26e1c8
KH
2614 if (pos < next_boundary && next_boundary < pause)
2615 pause = next_boundary;
1c2250c2
JB
2616 if (pos < next_face_change && next_face_change < pause)
2617 pause = next_face_change;
2618
31b24551
JB
2619 /* Wouldn't you hate to read the next line to someone over
2620 the phone? */
ae3b1442
KH
2621 if (pos < PT && PT < pause)
2622 pause = PT;
a2889657
JB
2623 if (pos < GPT && GPT < pause)
2624 pause = GPT;
2625
2626 p = &FETCH_CHAR (pos);
2627 }
ca26e1c8 2628
ca26e1c8
KH
2629 if (p1 >= endp)
2630 break;
2631
2632 p1prev = p1;
2633
a2889657 2634 c = *p++;
376b0e59
RS
2635 /* Let a display table override all standard display methods. */
2636 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
2637 {
2638 p1 = copy_part_of_rope (f, p1, leftmargin,
2639 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2640 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2641 current_face);
2642 }
2643 else if (c >= 040 && c < 0177)
a2889657 2644 {
d2f84654 2645 if (p1 >= leftmargin)
4cdc65eb 2646 *p1 = MAKE_GLYPH (f, c, current_face);
a2889657
JB
2647 p1++;
2648 }
2649 else if (c == '\n')
2650 {
2651 invis = 0;
642eefc6
RS
2652 if (last_invis_skip == pos
2653 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
2654 invis = 1;
ca26e1c8 2655 while (pos + 1 < ZV
a2889657 2656 && selective > 0
9f412332 2657 && indented_beyond_p (pos + 1, selective))
a2889657
JB
2658 {
2659 invis = 1;
2660 pos = find_next_newline (pos + 1, 1);
2661 if (FETCH_CHAR (pos - 1) == '\n')
2662 pos--;
2663 }
d2f84654 2664 if (invis && selective_rlen > 0 && p1 >= leftmargin)
a2889657
JB
2665 {
2666 p1 += selective_rlen;
d2f84654 2667 if (p1 - leftmargin > width)
a2889657 2668 p1 = endp;
278feba9 2669 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
1c2250c2 2670 (p1 - p1prev), current_face);
a2889657 2671 }
87485d6f 2672#ifdef HAVE_FACES
3c5c35c5
JB
2673 /* Draw the face of the newline character as extending all the
2674 way to the end of the frame line. */
2675 if (current_face)
1105ff20
KH
2676 {
2677 if (p1 < leftmargin)
2678 p1 = leftmargin;
2679 while (p1 < endp)
2680 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2681 }
3c5c35c5 2682#endif
545e04f6
KH
2683
2684 /* Update charstarts for the newline that ended this line. */
2685 /* Do nothing here for a char that's entirely off the left edge
2686 or if it starts at the right edge. */
2687 if (p1 >= leftmargin && p1prev != endp)
2688 {
2689 /* Store the newline's position into charstarts
2690 for the column where the newline starts.
2691 Store -1 for the rest of the glyphs it occupies. */
2692 int *p2x = &charstart[(p1prev < leftmargin
2693 ? leftmargin : p1prev)
2694 - p1start];
2695 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2696
2697 *p2x++ = pos;
2698 while (p2x < p2)
2699 *p2x++ = -1;
2700 }
2701
68a37fa8 2702 break;
a2889657
JB
2703 }
2704 else if (c == '\t')
2705 {
2706 do
2707 {
d2f84654 2708 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2709 *p1 = MAKE_GLYPH (f, ' ', current_face);
a2889657
JB
2710 p1++;
2711 }
d2f84654 2712 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
a2889657
JB
2713 % tab_width);
2714 }
6e8290aa 2715 else if (c == Ctl ('M') && selective == -1)
a2889657
JB
2716 {
2717 pos = find_next_newline (pos, 1);
2718 if (FETCH_CHAR (pos - 1) == '\n')
2719 pos--;
2720 if (selective_rlen > 0)
2721 {
2722 p1 += selective_rlen;
d2f84654 2723 if (p1 - leftmargin > width)
a2889657 2724 p1 = endp;
278feba9 2725 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
1c2250c2 2726 (p1 - p1prev), current_face);
a2889657 2727 }
87485d6f 2728#ifdef HAVE_FACES
3c5c35c5
JB
2729 /* Draw the face of the newline character as extending all the
2730 way to the end of the frame line. */
2731 if (current_face)
1105ff20
KH
2732 {
2733 if (p1 < leftmargin)
2734 p1 = leftmargin;
2735 while (p1 < endp)
2736 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2737 }
3c5c35c5 2738#endif
545e04f6
KH
2739
2740 /* Update charstarts for the ^M that ended this line. */
2741 /* Do nothing here for a char that's entirely off the left edge
2742 or if it starts at the right edge. */
2743 if (p1 >= leftmargin && p1prev != endp)
2744 {
2745 /* Store the newline's position into charstarts
2746 for the column where the newline starts.
2747 Store -1 for the rest of the glyphs it occupies. */
2748 int *p2x = &charstart[(p1prev < leftmargin
2749 ? leftmargin : p1prev)
2750 - p1start];
2751 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2752
2753 *p2x++ = pos;
2754 while (p2x < p2)
2755 *p2x++ = -1;
2756 }
68a37fa8 2757 break;
a2889657 2758 }
a2889657
JB
2759 else if (c < 0200 && ctl_arrow)
2760 {
d2f84654 2761 if (p1 >= leftmargin)
e24c997d 2762 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
278feba9
RS
2763 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
2764 current_face);
a2889657 2765 p1++;
d2f84654 2766 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2767 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
a2889657
JB
2768 p1++;
2769 }
2770 else
2771 {
d2f84654 2772 if (p1 >= leftmargin)
e24c997d 2773 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
278feba9
RS
2774 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
2775 current_face);
a2889657 2776 p1++;
d2f84654 2777 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2778 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
a2889657 2779 p1++;
d2f84654 2780 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2781 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
a2889657 2782 p1++;
d2f84654 2783 if (p1 >= leftmargin && p1 < endp)
4cdc65eb 2784 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
a2889657
JB
2785 p1++;
2786 }
31b24551 2787
ca26e1c8 2788 prevpos = pos;
a2889657 2789 pos++;
545e04f6
KH
2790
2791 /* Update charstarts for the character just output. */
2792
2793 /* Do nothing here for a char that's entirely off the left edge. */
2794 if (p1 >= leftmargin)
2795 {
2796 /* Store the char's position into charstarts
2797 for the first glyph occupied by this char.
2798 Store -1 for the rest of the glyphs it occupies. */
2799 if (p1 != p1prev)
2800 {
2801 int *p2x = &charstart[(p1prev < leftmargin
2802 ? leftmargin : p1prev)
2803 - p1start];
2804 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2805
2806 if (p2x < p2)
2807 *p2x++ = prevpos;
2808 while (p2x < p2)
2809 *p2x++ = -1;
2810 }
2811 }
a2889657
JB
2812 }
2813
2814 val.hpos = - XINT (w->hscroll);
2815 if (val.hpos)
2816 val.hpos++;
2817
2818 val.vpos = 1;
2819
2820 lastpos = pos;
2821
efc63ef0
RS
2822 /* Store 0 in this charstart line for the positions where
2823 there is no character. But do leave what was recorded
2824 for the character that ended the line. */
85bcef6c
RS
2825 /* Add 1 in the endtest to compensate for the fact that ENDP was
2826 made from WIDTH, which is 1 less than the window's actual
2827 internal width. */
a007eef6
RS
2828 i = p1 - p1start + 1;
2829 if (p1 < leftmargin)
2830 i += leftmargin - p1;
2831 for (; i < endp - p1start + 1; i++)
efc63ef0
RS
2832 charstart[i] = 0;
2833
a2889657
JB
2834 /* Handle continuation in middle of a character */
2835 /* by backing up over it */
2836 if (p1 > endp)
2837 {
5fcbb24d
JB
2838 /* Don't back up if we never actually displayed any text.
2839 This occurs when the minibuffer prompt takes up the whole line. */
2840 if (p1prev)
2841 {
2842 /* Start the next line with that same character */
2843 pos--;
2844 /* but at negative hpos, to skip the columns output on this line. */
2845 val.hpos += p1prev - endp;
2846 }
2847
a2889657
JB
2848 /* Keep in this line everything up to the continuation column. */
2849 p1 = endp;
2850 }
2851
2852 /* Finish deciding which character to start the next line on,
2853 and what hpos to start it at.
2854 Also set `lastpos' to the last position which counts as "on this line"
2855 for cursor-positioning. */
2856
2857 if (pos < ZV)
2858 {
2859 if (FETCH_CHAR (pos) == '\n')
dd5f6267
KH
2860 {
2861 /* If stopped due to a newline, start next line after it */
2862 pos++;
2863 /* Check again for hidden lines, in case the newline occurred exactly
2864 at the right margin. */
2865 while (pos < ZV && selective > 0
2866 && indented_beyond_p (pos, selective))
2867 pos = find_next_newline (pos, 1);
2868 }
a2889657
JB
2869 else
2870 /* Stopped due to right margin of window */
2871 {
2872 if (truncate)
2873 {
278feba9 2874 *p1++ = fix_glyph (f, truncator, 0);
a2889657
JB
2875 /* Truncating => start next line after next newline,
2876 and point is on this line if it is before the newline,
2877 and skip none of first char of next line */
dd5f6267
KH
2878 do
2879 pos = find_next_newline (pos, 1);
2880 while (pos < ZV && selective > 0
2881 && indented_beyond_p (pos, selective));
a2889657
JB
2882 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2883
2884 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
2885 }
2886 else
2887 {
278feba9 2888 *p1++ = fix_glyph (f, continuer, 0);
a2889657
JB
2889 val.vpos = 0;
2890 lastpos--;
2891 }
2892 }
2893 }
2894
2895 /* If point is at eol or in invisible text at eol,
44fa5b1e 2896 record its frame location now. */
a2889657 2897
ae3b1442 2898 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
a2889657
JB
2899 {
2900 cursor_vpos = vpos;
d2f84654 2901 cursor_hpos = p1 - leftmargin;
a2889657
JB
2902 }
2903
2904 if (cursor_vpos == vpos)
2905 {
2906 if (cursor_hpos < 0) cursor_hpos = 0;
2907 if (cursor_hpos > width) cursor_hpos = width;
2908 cursor_hpos += XFASTINT (w->left);
44fa5b1e 2909 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
a2889657 2910 {
b5bbc9a5
KH
2911 if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f)
2912 && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window)))
2913 {
2914 FRAME_CURSOR_Y (f) = cursor_vpos;
2915 FRAME_CURSOR_X (f) = cursor_hpos;
2916 }
a2889657
JB
2917
2918 if (w == XWINDOW (selected_window))
2919 {
2920 /* Line is not continued and did not start
2921 in middle of character */
2922 if ((hpos - XFASTINT (w->left)
2923 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2924 && val.vpos)
2925 {
2926 this_line_bufpos = start;
2927 this_line_buffer = current_buffer;
2928 this_line_vpos = cursor_vpos;
2929 this_line_start_hpos = hpos;
2930 this_line_endpos = Z - lastpos;
2931 }
2932 else
2933 this_line_bufpos = 0;
2934 }
2935 }
2936 }
2937
2938 /* If hscroll and line not empty, insert truncation-at-left marker */
2939 if (hscroll && lastpos != start)
2940 {
d2f84654
RS
2941 *leftmargin = fix_glyph (f, truncator, 0);
2942 if (p1 <= leftmargin)
2943 p1 = leftmargin + 1;
a2889657
JB
2944 }
2945
44fa5b1e 2946 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
a2889657
JB
2947 {
2948 endp++;
d2f84654 2949 if (p1 < leftmargin) p1 = leftmargin;
a2889657 2950 while (p1 < endp) *p1++ = SPACEGLYPH;
b1d1124b 2951
88f22aff
JB
2952 /* Don't draw vertical bars if we're using scroll bars. They're
2953 covered up by the scroll bars, and it's distracting to see
2954 them when the scroll bar windows are flickering around to be
b1d1124b 2955 reconfigured. */
88f22aff 2956 *p1++ = (FRAME_HAS_VERTICAL_SCROLL_BARS (f)
a45e35e1
JB
2957 ? ' '
2958 : (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
2959 ? DISP_BORDER_GLYPH (dp)
2960 : '|'));
a2889657
JB
2961 }
2962 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
2963 p1 - desired_glyphs->glyphs[vpos]);
2964 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
2965
2966 /* If the start of this line is the overlay arrow-position,
2967 then put the arrow string into the display-line. */
2968
e24c997d 2969 if (MARKERP (Voverlay_arrow_position)
a2889657
JB
2970 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
2971 && start == marker_position (Voverlay_arrow_position)
e24c997d 2972 && STRINGP (Voverlay_arrow_string)
a2889657
JB
2973 && ! overlay_arrow_seen)
2974 {
2975 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
2976 int i;
2977 int len = XSTRING (Voverlay_arrow_string)->size;
142be3dd 2978 int arrow_end;
a2889657 2979
b1d1124b
JB
2980 if (len > width)
2981 len = width;
87485d6f 2982#ifdef HAVE_FACES
c4628384
RS
2983 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
2984 {
2985 /* If the arrow string has text props, obey them when displaying. */
2986 for (i = 0; i < len; i++)
2987 {
2988 int c = p[i];
2989 Lisp_Object face, ilisp;
2990 int newface;
2991
c2213350 2992 XSETFASTINT (ilisp, i);
c4628384
RS
2993 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
2994 newface = compute_glyph_face_1 (f, face, 0);
2995 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
2996 }
2997 }
2998 else
87485d6f 2999#endif /* HAVE_FACES */
c4628384
RS
3000 {
3001 for (i = 0; i < len; i++)
3002 leftmargin[i] = p[i];
3003 }
142be3dd
JB
3004
3005 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
d2f84654 3006 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
142be3dd
JB
3007 if (desired_glyphs->used[vpos] < arrow_end)
3008 desired_glyphs->used[vpos] = arrow_end;
a2889657
JB
3009
3010 overlay_arrow_seen = 1;
3011 }
3012
3013 val.bufpos = pos;
3014 val_display_text_line = val;
3015 return &val_display_text_line;
3016}
3017\f
7ce2c095
RS
3018/* Redisplay the menu bar in the frame for window W. */
3019
3020static void
3021display_menu_bar (w)
3022 struct window *w;
3023{
3024 Lisp_Object items, tail;
3025 register int vpos = 0;
3026 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3027 int maxendcol = FRAME_WIDTH (f);
3028 int hpos = 0;
8351baf2 3029 int i;
7ce2c095 3030
76412d64 3031#ifndef USE_X_TOOLKIT
7ce2c095
RS
3032 if (FRAME_MENU_BAR_LINES (f) <= 0)
3033 return;
3034
3035 get_display_line (f, vpos, 0);
3036
8351baf2
RS
3037 items = FRAME_MENU_BAR_ITEMS (f);
3038 for (i = 0; i < XVECTOR (items)->size; i += 3)
7ce2c095 3039 {
8351baf2
RS
3040 Lisp_Object pos, string;
3041 string = XVECTOR (items)->contents[i + 1];
3042 if (NILP (string))
3043 break;
2d66ad19 3044
c2213350 3045 XSETFASTINT (XVECTOR (items)->contents[i + 2], hpos);
7ce2c095
RS
3046
3047 if (hpos < maxendcol)
3048 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
3049 XSTRING (string)->data,
90adcf20 3050 XSTRING (string)->size,
278feba9 3051 hpos, 0, 0, hpos, maxendcol);
6b1bbc46 3052 /* Put a space between items. */
2d66ad19
RS
3053 if (hpos < maxendcol)
3054 {
6b1bbc46 3055 int hpos1 = hpos + 1;
278feba9 3056 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
2d66ad19
RS
3057 min (hpos1, maxendcol), maxendcol);
3058 }
7ce2c095
RS
3059 }
3060
3061 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3062 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
2d66ad19
RS
3063
3064 /* Fill out the line with spaces. */
3065 if (maxendcol > hpos)
278feba9 3066 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
db6f348c
JB
3067
3068 /* Clear the rest of the lines allocated to the menu bar. */
3069 vpos++;
3070 while (vpos < FRAME_MENU_BAR_LINES (f))
3071 get_display_line (f, vpos++, 0);
76412d64 3072#endif /* not USE_X_TOOLKIT */
7ce2c095
RS
3073}
3074\f
a2889657
JB
3075/* Display the mode line for window w */
3076
3077static void
3078display_mode_line (w)
3079 struct window *w;
3080{
3081 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
3082 register int left = XFASTINT (w->left);
3083 register int right = XFASTINT (w->width) + left;
44fa5b1e 3084 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
a2889657 3085
aa6d10fa 3086 line_number_displayed = 0;
155ef550 3087 w->column_number_displayed = Qnil;
aa6d10fa 3088
44fa5b1e 3089 get_display_line (f, vpos, left);
03b294dc
RS
3090
3091 /* Temporarily make frame F's kboard the current kboard
3092 so that kboard-local variables in the mode_line_format
3093 will get the right values. */
3094 push_frame_kboard (f);
3095
3096 display_mode_element (w, vpos, left, 0, right, right,
3097 current_buffer->mode_line_format);
3098
3099 pop_frame_kboard ();
3100
44fa5b1e 3101 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
a2889657
JB
3102
3103 /* Make the mode line inverse video if the entire line
3104 is made of mode lines.
3105 I.e. if this window is full width,
3106 or if it is the child of a full width window
3107 (which implies that that window is split side-by-side
3108 and the rest of this line is mode lines of the sibling windows). */
44fa5b1e
JB
3109 if (XFASTINT (w->width) == FRAME_WIDTH (f)
3110 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
3111 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
87485d6f 3112#ifdef HAVE_FACES
03b294dc 3113 else if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video)
d7eb09a0
RS
3114 {
3115 /* For a partial width window, explicitly set face of each glyph. */
3116 int i;
3117 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3118 for (i = left; i < right; ++i)
4cdc65eb 3119 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
d7eb09a0 3120 }
4cdc65eb 3121#endif
a2889657
JB
3122}
3123
3124/* Contribute ELT to the mode line for window W.
3125 How it translates into text depends on its data type.
3126
3127 VPOS is the position of the mode line being displayed.
3128
44fa5b1e 3129 HPOS is the position (absolute on frame) where this element's text
a2889657
JB
3130 should start. The output is truncated automatically at the right
3131 edge of window W.
3132
3133 DEPTH is the depth in recursion. It is used to prevent
3134 infinite recursion here.
3135
3136 MINENDCOL is the hpos before which the element may not end.
3137 The element is padded at the right with spaces if nec
3138 to reach this column.
3139
3140 MAXENDCOL is the hpos past which this element may not extend.
3141 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3142 (This is necessary to make nested padding and truncation work.)
3143
3144 Returns the hpos of the end of the text generated by ELT.
3145 The next element will receive that value as its HPOS arg,
3146 so as to concatenate the elements. */
3147
3148static int
3149display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3150 struct window *w;
3151 register int vpos, hpos;
3152 int depth;
3153 int minendcol;
3154 register int maxendcol;
3155 register Lisp_Object elt;
3156{
3157 tail_recurse:
3158 if (depth > 10)
3159 goto invalid;
3160
3161 depth++;
3162
0220c518 3163 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
a2889657
JB
3164 {
3165 case Lisp_String:
3166 {
3167 /* A string: output it and check for %-constructs within it. */
3168 register unsigned char c;
3169 register unsigned char *this = XSTRING (elt)->data;
3170
3171 while (hpos < maxendcol && *this)
3172 {
3173 unsigned char *last = this;
3174 while ((c = *this++) != '\0' && c != '%')
3175 ;
3176 if (this - 1 != last)
3177 {
3178 register int lim = --this - last + hpos;
d39b6696
KH
3179 if (frame_title_ptr)
3180 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3181 else
3182 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3183 hpos, min (lim, maxendcol));
a2889657
JB
3184 }
3185 else /* c == '%' */
3186 {
3187 register int spec_width = 0;
3188
3189 /* We can't allow -ve args due to the "%-" construct */
3190 /* Argument specifies minwidth but not maxwidth
3191 (maxwidth can be specified by
3192 (<negative-number> . <stuff>) mode-line elements) */
3193
3194 while ((c = *this++) >= '0' && c <= '9')
3195 {
3196 spec_width = spec_width * 10 + (c - '0');
3197 }
3198
3199 spec_width += hpos;
3200 if (spec_width > maxendcol)
3201 spec_width = maxendcol;
3202
3203 if (c == 'M')
3204 hpos = display_mode_element (w, vpos, hpos, depth,
3205 spec_width, maxendcol,
3206 Vglobal_mode_string);
3207 else if (c != 0)
d39b6696
KH
3208 {
3209 char *spec = decode_mode_spec (w, c, maxendcol - hpos);
3210 if (frame_title_ptr)
3211 hpos = store_frame_title (spec, spec_width, maxendcol);
3212 else
3213 hpos = display_string (w, vpos, spec, -1,
3214 hpos, 0, 1,
3215 spec_width, maxendcol);
3216 }
a2889657
JB
3217 }
3218 }
3219 }
3220 break;
3221
3222 case Lisp_Symbol:
3223 /* A symbol: process the value of the symbol recursively
3224 as if it appeared here directly. Avoid error if symbol void.
3225 Special case: if value of symbol is a string, output the string
3226 literally. */
3227 {
3228 register Lisp_Object tem;
3229 tem = Fboundp (elt);
265a9e55 3230 if (!NILP (tem))
a2889657
JB
3231 {
3232 tem = Fsymbol_value (elt);
3233 /* If value is a string, output that string literally:
3234 don't check for % within it. */
e24c997d 3235 if (STRINGP (tem))
d39b6696
KH
3236 {
3237 if (frame_title_ptr)
3238 hpos = store_frame_title (XSTRING (tem)->data,
3239 minendcol, maxendcol);
3240 else
3241 hpos = display_string (w, vpos, XSTRING (tem)->data,
3242 XSTRING (tem)->size,
3243 hpos, 0, 1, minendcol, maxendcol);
3244 }
a2889657
JB
3245 /* Give up right away for nil or t. */
3246 else if (!EQ (tem, elt))
3247 { elt = tem; goto tail_recurse; }
3248 }
3249 }
3250 break;
3251
3252 case Lisp_Cons:
3253 {
3254 register Lisp_Object car, tem;
3255
3256 /* A cons cell: three distinct cases.
3257 If first element is a string or a cons, process all the elements
3258 and effectively concatenate them.
3259 If first element is a negative number, truncate displaying cdr to
3260 at most that many characters. If positive, pad (with spaces)
3261 to at least that many characters.
3262 If first element is a symbol, process the cadr or caddr recursively
3263 according to whether the symbol's value is non-nil or nil. */
3264 car = XCONS (elt)->car;
e24c997d 3265 if (SYMBOLP (car))
a2889657
JB
3266 {
3267 tem = Fboundp (car);
3268 elt = XCONS (elt)->cdr;
e24c997d 3269 if (!CONSP (elt))
a2889657
JB
3270 goto invalid;
3271 /* elt is now the cdr, and we know it is a cons cell.
3272 Use its car if CAR has a non-nil value. */
265a9e55 3273 if (!NILP (tem))
a2889657
JB
3274 {
3275 tem = Fsymbol_value (car);
265a9e55 3276 if (!NILP (tem))
a2889657
JB
3277 { elt = XCONS (elt)->car; goto tail_recurse; }
3278 }
3279 /* Symbol's value is nil (or symbol is unbound)
3280 Get the cddr of the original list
3281 and if possible find the caddr and use that. */
3282 elt = XCONS (elt)->cdr;
265a9e55 3283 if (NILP (elt))
a2889657 3284 break;
e24c997d 3285 else if (!CONSP (elt))
a2889657
JB
3286 goto invalid;
3287 elt = XCONS (elt)->car;
3288 goto tail_recurse;
3289 }
e24c997d 3290 else if (INTEGERP (car))
a2889657
JB
3291 {
3292 register int lim = XINT (car);
3293 elt = XCONS (elt)->cdr;
3294 if (lim < 0)
3295 /* Negative int means reduce maximum width.
3296 DO NOT change MINENDCOL here!
3297 (20 -10 . foo) should truncate foo to 10 col
3298 and then pad to 20. */
3299 maxendcol = min (maxendcol, hpos - lim);
3300 else if (lim > 0)
3301 {
3302 /* Padding specified. Don't let it be more than
3303 current maximum. */
3304 lim += hpos;
3305 if (lim > maxendcol)
3306 lim = maxendcol;
3307 /* If that's more padding than already wanted, queue it.
3308 But don't reduce padding already specified even if
3309 that is beyond the current truncation point. */
3310 if (lim > minendcol)
3311 minendcol = lim;
3312 }
3313 goto tail_recurse;
3314 }
e24c997d 3315 else if (STRINGP (car) || CONSP (car))
a2889657
JB
3316 {
3317 register int limit = 50;
3318 /* LIMIT is to protect against circular lists. */
e24c997d 3319 while (CONSP (elt) && --limit > 0
a2889657
JB
3320 && hpos < maxendcol)
3321 {
3322 hpos = display_mode_element (w, vpos, hpos, depth,
3323 hpos, maxendcol,
3324 XCONS (elt)->car);
3325 elt = XCONS (elt)->cdr;
3326 }
3327 }
3328 }
3329 break;
3330
3331 default:
3332 invalid:
d39b6696
KH
3333 if (frame_title_ptr)
3334 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3335 else
3336 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3337 minendcol, maxendcol);
3338 return hpos;
a2889657
JB
3339 }
3340
a2889657 3341 if (minendcol > hpos)
d39b6696
KH
3342 if (frame_title_ptr)
3343 hpos = store_frame_title ("", minendcol, maxendcol);
3344 else
3345 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
a2889657
JB
3346 return hpos;
3347}
3348\f
3349/* Return a string for the output of a mode line %-spec for window W,
3350 generated by character C and width MAXWIDTH. */
3351
11e82b76
JB
3352static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3353
a2889657
JB
3354static char *
3355decode_mode_spec (w, c, maxwidth)
3356 struct window *w;
3357 register char c;
3358 register int maxwidth;
3359{
0b67772d 3360 Lisp_Object obj;
44fa5b1e
JB
3361 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3362 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
d39b6696 3363 struct buffer *b = XBUFFER (w->buffer);
a2889657 3364
0b67772d 3365 obj = Qnil;
44fa5b1e
JB
3366 if (maxwidth > FRAME_WIDTH (f))
3367 maxwidth = FRAME_WIDTH (f);
a2889657
JB
3368
3369 switch (c)
3370 {
1af9f229
RS
3371 case '*':
3372 if (!NILP (b->read_only))
3373 return "%";
3374 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3375 return "*";
3376 return "-";
3377
3378 case '+':
3379 /* This differs from %* only for a modified read-only buffer. */
3380 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3381 return "*";
3382 if (!NILP (b->read_only))
3383 return "%";
3384 return "-";
3385
3386 case '&':
3387 /* This differs from %* in ignoring read-only-ness. */
3388 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3389 return "*";
3390 return "-";
3391
3392 case '%':
3393 return "%";
3394
3395 case '[':
3396 {
3397 int i;
3398 char *p;
3399
3400 if (command_loop_level > 5)
3401 return "[[[... ";
3402 p = decode_mode_spec_buf;
3403 for (i = 0; i < command_loop_level; i++)
3404 *p++ = '[';
3405 *p = 0;
3406 return decode_mode_spec_buf;
3407 }
3408
3409 case ']':
3410 {
3411 int i;
3412 char *p;
3413
3414 if (command_loop_level > 5)
3415 return " ...]]]";
3416 p = decode_mode_spec_buf;
3417 for (i = 0; i < command_loop_level; i++)
3418 *p++ = ']';
3419 *p = 0;
3420 return decode_mode_spec_buf;
3421 }
3422
3423 case '-':
3424 {
3425 register char *p;
3426 register int i;
3427
3428 if (maxwidth < sizeof (lots_of_dashes))
3429 return lots_of_dashes;
3430 else
3431 {
3432 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3433 *p++ = '-';
3434 *p = '\0';
3435 }
3436 return decode_mode_spec_buf;
3437 }
3438
a2889657 3439 case 'b':
d39b6696 3440 obj = b->name;
a2889657
JB
3441#if 0
3442 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
3443 {
3444 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
3445 decode_mode_spec_buf[maxwidth - 1] = '\\';
3446 decode_mode_spec_buf[maxwidth] = '\0';
3447 return decode_mode_spec_buf;
3448 }
3449#endif
3450 break;
3451
1af9f229
RS
3452 case 'c':
3453 {
3454 int col = current_column ();
3455 XSETFASTINT (w->column_number_displayed, col);
3456 sprintf (decode_mode_spec_buf, "%d", col);
3457 return decode_mode_spec_buf;
3458 }
3459
3460 case 'F':
3461 /* %F displays the frame name. */
3462 return (char *) XSTRING (selected_frame->name)->data;
3463
a2889657 3464 case 'f':
d39b6696 3465 obj = b->filename;
a2889657 3466#if 0
265a9e55 3467 if (NILP (obj))
a2889657 3468 return "[none]";
e24c997d 3469 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
a2889657
JB
3470 {
3471 bcopy ("...", decode_mode_spec_buf, 3);
3472 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
3473 decode_mode_spec_buf + 3, maxwidth - 3);
3474 return decode_mode_spec_buf;
3475 }
3476#endif
3477 break;
3478
aa6d10fa
RS
3479 case 'l':
3480 {
3481 int startpos = marker_position (w->start);
3482 int line, linepos, topline;
3483 int nlines, junk;
3484 Lisp_Object tem;
3485 int height = XFASTINT (w->height);
3486
3487 /* If we decided that this buffer isn't suitable for line numbers,
3488 don't forget that too fast. */
3489 if (EQ (w->base_line_pos, w->buffer))
3490 return "??";
3491
3492 /* If the buffer is very big, don't waste time. */
d39b6696 3493 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
aa6d10fa
RS
3494 {
3495 w->base_line_pos = Qnil;
3496 w->base_line_number = Qnil;
3497 return "??";
3498 }
3499
3500 if (!NILP (w->base_line_number)
3501 && !NILP (w->base_line_pos)
3502 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
3503 {
3504 line = XFASTINT (w->base_line_number);
3505 linepos = XFASTINT (w->base_line_pos);
3506 }
3507 else
3508 {
3509 line = 1;
d39b6696 3510 linepos = BUF_BEGV (b);
aa6d10fa
RS
3511 }
3512
3513 /* Count lines from base line to window start position. */
3514 nlines = display_count_lines (linepos, startpos, startpos, &junk);
3515
3516 topline = nlines + line;
3517
3518 /* Determine a new base line, if the old one is too close
3519 or too far away, or if we did not have one.
3520 "Too close" means it's plausible a scroll-down would
3521 go back past it. */
d39b6696 3522 if (startpos == BUF_BEGV (b))
aa6d10fa 3523 {
c2213350
KH
3524 XSETFASTINT (w->base_line_number, topline);
3525 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
aa6d10fa
RS
3526 }
3527 else if (nlines < height + 25 || nlines > height * 3 + 50
d39b6696 3528 || linepos == BUF_BEGV (b))
aa6d10fa 3529 {
d39b6696 3530 int limit = BUF_BEGV (b);
aa6d10fa
RS
3531 int position;
3532 int distance = (height * 2 + 30) * 200;
3533
3534 if (startpos - distance > limit)
3535 limit = startpos - distance;
3536
3537 nlines = display_count_lines (startpos, limit,
3538 -(height * 2 + 30),
3539 &position);
3540 /* If we couldn't find the lines we wanted within
3541 200 chars per line,
3542 give up on line numbers for this window. */
3543 if (position == startpos - distance)
3544 {
3545 w->base_line_pos = w->buffer;
3546 w->base_line_number = Qnil;
3547 return "??";
3548 }
3549
c2213350
KH
3550 XSETFASTINT (w->base_line_number, topline - nlines);
3551 XSETFASTINT (w->base_line_pos, position);
aa6d10fa
RS
3552 }
3553
3554 /* Now count lines from the start pos to point. */
3555 nlines = display_count_lines (startpos, PT, PT, &junk);
3556
3557 /* Record that we did display the line number. */
3558 line_number_displayed = 1;
3559
3560 /* Make the string to show. */
3561 sprintf (decode_mode_spec_buf, "%d", topline + nlines);
3562 return decode_mode_spec_buf;
3563 }
3564 break;
3565
a2889657 3566 case 'm':
d39b6696 3567 obj = b->mode_name;
a2889657
JB
3568 break;
3569
3570 case 'n':
d39b6696 3571 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
a2889657
JB
3572 return " Narrow";
3573 break;
3574
a2889657
JB
3575 case 'p':
3576 {
3577 int pos = marker_position (w->start);
d39b6696 3578 int total = BUF_ZV (b) - BUF_BEGV (b);
a2889657 3579
d39b6696 3580 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
a2889657 3581 {
d39b6696 3582 if (pos <= BUF_BEGV (b))
a2889657
JB
3583 return "All";
3584 else
3585 return "Bottom";
3586 }
d39b6696 3587 else if (pos <= BUF_BEGV (b))
a2889657
JB
3588 return "Top";
3589 else
3590 {
d39b6696 3591 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
a2889657
JB
3592 /* We can't normally display a 3-digit number,
3593 so get us a 2-digit number that is close. */
3594 if (total == 100)
3595 total = 99;
3596 sprintf (decode_mode_spec_buf, "%2d%%", total);
3597 return decode_mode_spec_buf;
3598 }
3599 }
3600
8ffcb79f
RS
3601 /* Display percentage of size above the bottom of the screen. */
3602 case 'P':
3603 {
3604 int toppos = marker_position (w->start);
d39b6696
KH
3605 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
3606 int total = BUF_ZV (b) - BUF_BEGV (b);
8ffcb79f 3607
d39b6696 3608 if (botpos >= BUF_ZV (b))
8ffcb79f 3609 {
d39b6696 3610 if (toppos <= BUF_BEGV (b))
8ffcb79f
RS
3611 return "All";
3612 else
3613 return "Bottom";
3614 }
3615 else
3616 {
d39b6696 3617 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
8ffcb79f
RS
3618 /* We can't normally display a 3-digit number,
3619 so get us a 2-digit number that is close. */
3620 if (total == 100)
3621 total = 99;
d39b6696 3622 if (toppos <= BUF_BEGV (b))
8ffcb79f
RS
3623 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
3624 else
3625 sprintf (decode_mode_spec_buf, "%2d%%", total);
3626 return decode_mode_spec_buf;
3627 }
3628 }
3629
1af9f229
RS
3630 case 's':
3631 /* status of process */
3632 obj = Fget_buffer_process (w->buffer);
3633 if (NILP (obj))
3634 return "no process";
3635#ifdef subprocesses
3636 obj = Fsymbol_name (Fprocess_status (obj));
3637#endif
3638 break;
d39b6696 3639
1af9f229
RS
3640 case 't': /* indicate TEXT or BINARY */
3641#ifdef MODE_LINE_BINARY_TEXT
3642 return MODE_LINE_BINARY_TEXT (b);
3643#else
3644 return "T";
3645#endif
a2889657 3646 }
d39b6696 3647
e24c997d 3648 if (STRINGP (obj))
a2889657
JB
3649 return (char *) XSTRING (obj)->data;
3650 else
3651 return "";
3652}
59b49f63
RS
3653\f
3654/* Search for COUNT instances of a line boundary, which means either a
3655 newline or (if selective display enabled) a carriage return.
3656 Start at START. If COUNT is negative, search backwards.
3657
3658 If we find COUNT instances, set *SHORTAGE to zero, and return the
3659 position after the COUNTth match. Note that for reverse motion
3660 this is not the same as the usual convention for Emacs motion commands.
3661
3662 If we don't find COUNT instances before reaching the end of the
3663 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3664 the number of line boundaries left unfound, and return the end of the
3665 buffer we bumped up against. */
3666
3667static int
3668display_scan_buffer (start, count, shortage)
3669 int *shortage, start;
3670 register int count;
3671{
3672 int limit = ((count > 0) ? ZV - 1 : BEGV);
3673 int direction = ((count > 0) ? 1 : -1);
3674
3675 register unsigned char *cursor;
3676 unsigned char *base;
3677
3678 register int ceiling;
3679 register unsigned char *ceiling_addr;
3680
3681 /* If we are not in selective display mode,
3682 check only for newlines. */
3683 if (! (!NILP (current_buffer->selective_display)
3684 && !INTEGERP (current_buffer->selective_display)))
ae474ea9 3685 return scan_buffer ('\n', start, 0, count, shortage, 0);
59b49f63
RS
3686
3687 /* The code that follows is like scan_buffer
3688 but checks for either newline or carriage return. */
3689
3690 if (shortage != 0)
3691 *shortage = 0;
3692
3693 if (count > 0)
3694 while (start != limit + 1)
3695 {
3696 ceiling = BUFFER_CEILING_OF (start);
3697 ceiling = min (limit, ceiling);
3698 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
3699 base = (cursor = &FETCH_CHAR (start));
3700 while (1)
3701 {
3702 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
3703 ;
3704 if (cursor != ceiling_addr)
3705 {
3706 if (--count == 0)
3707 {
3708 immediate_quit = 0;
3709 return (start + cursor - base + 1);
3710 }
3711 else
3712 if (++cursor == ceiling_addr)
3713 break;
3714 }
3715 else
3716 break;
3717 }
3718 start += cursor - base;
3719 }
3720 else
3721 {
3722 start--; /* first character we scan */
3723 while (start > limit - 1)
3724 { /* we WILL scan under start */
3725 ceiling = BUFFER_FLOOR_OF (start);
3726 ceiling = max (limit, ceiling);
3727 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
3728 base = (cursor = &FETCH_CHAR (start));
3729 cursor++;
3730 while (1)
3731 {
3732 while (--cursor != ceiling_addr
3733 && *cursor != '\n' && *cursor != 015)
3734 ;
3735 if (cursor != ceiling_addr)
3736 {
3737 if (++count == 0)
3738 {
3739 immediate_quit = 0;
3740 return (start + cursor - base + 1);
3741 }
3742 }
3743 else
3744 break;
3745 }
3746 start += cursor - base;
3747 }
3748 }
3749
3750 if (shortage != 0)
3751 *shortage = count * direction;
3752 return (start + ((direction == 1 ? 0 : 1)));
3753}
aa6d10fa
RS
3754
3755/* Count up to N lines starting from FROM.
3756 But don't go beyond LIMIT.
3757 Return the number of lines thus found (always positive).
3758 Store the position after what was found into *POS_PTR. */
3759
3760static int
3761display_count_lines (from, limit, n, pos_ptr)
3762 int from, limit, n;
3763 int *pos_ptr;
3764{
3765 int oldbegv = BEGV;
3766 int oldzv = ZV;
3767 int shortage = 0;
3768
3769 if (limit < from)
3770 BEGV = limit;
3771 else
3772 ZV = limit;
3773
59b49f63 3774 *pos_ptr = display_scan_buffer (from, n, &shortage);
aa6d10fa
RS
3775
3776 ZV = oldzv;
3777 BEGV = oldbegv;
3778
3779 if (n < 0)
3780 /* When scanning backwards, scan_buffer stops *after* the last newline
3781 it finds, but does count it. Compensate for that. */
3782 return - n - shortage - (*pos_ptr != limit);
3783 return n - shortage;
3784}
a2889657
JB
3785\f
3786/* Display STRING on one line of window W, starting at HPOS.
3787 Display at position VPOS. Caller should have done get_display_line.
11e82b76 3788 If VPOS == -1, display it as the current frame's title.
90adcf20 3789 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
a2889657
JB
3790
3791 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
3792
3793 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
3794 MAXCOL is the last column ok to end at. Truncate here.
3795 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
44fa5b1e 3796 Both count from the left edge of the frame, as does HPOS.
a2889657
JB
3797 The right edge of W is an implicit maximum.
3798 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
3799
278feba9
RS
3800 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
3801 at the place where the current window ends in this line
3802 and not display anything beyond there. Otherwise, only MAXCOL
3803 controls where to stop output.
3804
3805 Returns ending hpos. */
a2889657
JB
3806
3807static int
278feba9
RS
3808display_string (w, vpos, string, length, hpos, truncate,
3809 obey_window_width, mincol, maxcol)
a2889657
JB
3810 struct window *w;
3811 unsigned char *string;
90adcf20 3812 int length;
a2889657
JB
3813 int vpos, hpos;
3814 GLYPH truncate;
278feba9 3815 int obey_window_width;
a2889657
JB
3816 int mincol, maxcol;
3817{
3818 register int c;
3819 register GLYPH *p1;
3820 int hscroll = XINT (w->hscroll);
253c7d2f 3821 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
a2889657
JB
3822 register GLYPH *start;
3823 register GLYPH *end;
b1d1124b
JB
3824 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3825 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
a2889657
JB
3826 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
3827 int window_width = XFASTINT (w->width);
3828
3829 /* Use the standard display table, not the window's display table.
3830 We don't want the mode line in rot13. */
3831 register struct Lisp_Vector *dp = 0;
efc63ef0 3832 int i;
a2889657 3833
e24c997d 3834 if (VECTORP (Vstandard_display_table)
a2889657
JB
3835 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
3836 dp = XVECTOR (Vstandard_display_table);
3837
54ff581a 3838 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
a2889657
JB
3839
3840 p1 = p1start;
3841 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
a2889657 3842
278feba9 3843 if (obey_window_width)
b1d1124b 3844 {
278feba9
RS
3845 end = start + window_width - (truncate != 0);
3846
3847 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
b1d1124b 3848 {
278feba9
RS
3849 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3850 {
3851 int i;
b1d1124b 3852
5802e919 3853 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
278feba9
RS
3854 *end-- = ' ';
3855 }
3856 else
3857 *end-- = '|';
b1d1124b 3858 }
b1d1124b 3859 }
a2889657 3860
278feba9
RS
3861 if (! obey_window_width
3862 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
a2889657 3863 end = desired_glyphs->glyphs[vpos] + maxcol;
278feba9 3864
efc63ef0 3865 /* Store 0 in charstart for these columns. */
bd5dec8e 3866 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
efc63ef0
RS
3867 desired_glyphs->charstarts[vpos][i] = 0;
3868
a2889657
JB
3869 if (maxcol >= 0 && mincol > maxcol)
3870 mincol = maxcol;
3871
3872 while (p1 < end)
3873 {
90adcf20
RS
3874 if (length == 0)
3875 break;
a2889657 3876 c = *string++;
90adcf20
RS
3877 /* Specified length. */
3878 if (length >= 0)
3879 length--;
3880 /* Unspecified length (null-terminated string). */
3881 else if (c == 0)
3882 break;
3883
376b0e59
RS
3884 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3885 {
3886 p1 = copy_part_of_rope (f, p1, start,
3887 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3888 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3889 0);
3890 }
3891 else if (c >= 040 && c < 0177)
a2889657
JB
3892 {
3893 if (p1 >= start)
3894 *p1 = c;
3895 p1++;
3896 }
3897 else if (c == '\t')
3898 {
3899 do
3900 {
3901 if (p1 >= start && p1 < end)
3902 *p1 = SPACEGLYPH;
3903 p1++;
3904 }
3905 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
3906 }
ded34426 3907 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
a2889657
JB
3908 {
3909 if (p1 >= start)
e24c997d 3910 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
278feba9
RS
3911 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3912 0);
a2889657 3913 p1++;
6e8290aa 3914 if (p1 >= start && p1 < end)
a2889657
JB
3915 *p1 = c ^ 0100;
3916 p1++;
3917 }
3918 else
3919 {
3920 if (p1 >= start)
e24c997d 3921 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
278feba9
RS
3922 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3923 0);
a2889657 3924 p1++;
6e8290aa 3925 if (p1 >= start && p1 < end)
a2889657
JB
3926 *p1 = (c >> 6) + '0';
3927 p1++;
6e8290aa 3928 if (p1 >= start && p1 < end)
a2889657
JB
3929 *p1 = (7 & (c >> 3)) + '0';
3930 p1++;
6e8290aa 3931 if (p1 >= start && p1 < end)
a2889657
JB
3932 *p1 = (7 & c) + '0';
3933 p1++;
3934 }
3935 }
3936
90adcf20 3937 if (c && length > 0)
a2889657
JB
3938 {
3939 p1 = end;
278feba9 3940 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
a2889657
JB
3941 }
3942 else if (mincol >= 0)
3943 {
3944 end = desired_glyphs->glyphs[vpos] + mincol;
3945 while (p1 < end)
3946 *p1++ = SPACEGLYPH;
3947 }
3948
3949 {
3950 register int len = p1 - desired_glyphs->glyphs[vpos];
3951
3952 if (len > desired_glyphs->used[vpos])
3953 desired_glyphs->used[vpos] = len;
3954 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3955
3956 return len;
3957 }
3958}
3959\f
642eefc6
RS
3960/* This is like a combination of memq and assq.
3961 Return 1 if PROPVAL appears as an element of LIST
3962 or as the car of an element of LIST.
af460d46
RS
3963 If PROPVAL is a list, compare each element against LIST
3964 in that way, and return 1 if any element of PROPVAL is found in LIST.
642eefc6
RS
3965 Otherwise return 0.
3966 This function cannot quit. */
3967
3968int
3969invisible_p (propval, list)
3970 register Lisp_Object propval;
3971 Lisp_Object list;
3972{
af460d46
RS
3973 register Lisp_Object tail, proptail;
3974 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
642eefc6
RS
3975 {
3976 register Lisp_Object tem;
af460d46 3977 tem = XCONS (tail)->car;
642eefc6
RS
3978 if (EQ (propval, tem))
3979 return 1;
3980 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
3981 return 1;
3982 }
af460d46
RS
3983 if (CONSP (propval))
3984 for (proptail = propval; CONSP (proptail);
3985 proptail = XCONS (proptail)->cdr)
3986 {
3987 Lisp_Object propelt;
3988 propelt = XCONS (proptail)->car;
3989 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3990 {
3991 register Lisp_Object tem;
3992 tem = XCONS (tail)->car;
3993 if (EQ (propelt, tem))
3994 return 1;
3995 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
3996 return 1;
3997 }
3998 }
642eefc6
RS
3999 return 0;
4000}
4001
4002/* Return 1 if PROPVAL appears as the car of an element of LIST
4003 and the cdr of that element is non-nil.
af460d46
RS
4004 If PROPVAL is a list, check each element of PROPVAL in that way,
4005 and the first time some element is found,
4006 return 1 if the cdr of that element is non-nil.
642eefc6
RS
4007 Otherwise return 0.
4008 This function cannot quit. */
4009
4010int
4011invisible_ellipsis_p (propval, list)
4012 register Lisp_Object propval;
4013 Lisp_Object list;
4014{
af460d46
RS
4015 register Lisp_Object tail, proptail;
4016 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
642eefc6
RS
4017 {
4018 register Lisp_Object tem;
af460d46 4019 tem = XCONS (tail)->car;
642eefc6
RS
4020 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4021 return ! NILP (XCONS (tem)->cdr);
4022 }
af460d46
RS
4023 if (CONSP (propval))
4024 for (proptail = propval; CONSP (proptail);
4025 proptail = XCONS (proptail)->cdr)
4026 {
4027 Lisp_Object propelt;
4028 propelt = XCONS (proptail)->car;
4029 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4030 {
4031 register Lisp_Object tem;
4032 tem = XCONS (tail)->car;
4033 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4034 return ! NILP (XCONS (tem)->cdr);
4035 }
4036 }
642eefc6
RS
4037 return 0;
4038}
4039\f
a2889657
JB
4040void
4041syms_of_xdisp ()
4042{
cf074754
RS
4043 staticpro (&Qmenu_bar_update_hook);
4044 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
4045
a2889657
JB
4046 staticpro (&last_arrow_position);
4047 staticpro (&last_arrow_string);
4048 last_arrow_position = Qnil;
4049 last_arrow_string = Qnil;
4050
4051 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
8c45d522 4052 "String (or mode line construct) included (normally) in `mode-line-format'.");
a2889657
JB
4053 Vglobal_mode_string = Qnil;
4054
4055 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
4056 "Marker for where to display an arrow on top of the buffer text.\n\
4057This must be the beginning of a line in order to work.\n\
4058See also `overlay-arrow-string'.");
4059 Voverlay_arrow_position = Qnil;
4060
4061 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
4062 "String to display as an arrow. See also `overlay-arrow-position'.");
4063 Voverlay_arrow_string = Qnil;
4064
4065 DEFVAR_INT ("scroll-step", &scroll_step,
4066 "*The number of lines to try scrolling a window by when point moves out.\n\
44fa5b1e
JB
4067If that fails to bring point back on frame, point is centered instead.\n\
4068If this is zero, point is always centered after it moves off frame.");
a2889657
JB
4069
4070 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
4071
4072 DEFVAR_BOOL ("truncate-partial-width-windows",
4073 &truncate_partial_width_windows,
44fa5b1e 4074 "*Non-nil means truncate lines in all windows less than full frame wide.");
a2889657
JB
4075 truncate_partial_width_windows = 1;
4076
4077 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
4078 "*Non-nil means use inverse video for the mode line.");
4079 mode_line_inverse_video = 1;
aa6d10fa
RS
4080
4081 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
4082 "*Maximum buffer size for which line number should be displayed.");
4083 line_number_display_limit = 1000000;
fba9ce76
RS
4084
4085 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
4086 "*Non-nil means highlight region even in nonselected windows.");
4087 highlight_nonselected_windows = 1;
d39b6696
KH
4088
4089 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
3450d04c
KH
4090 "Non-nil if more than one frame is visible on this display.\n\
4091Minibuffer-only frames don't count, but iconified frames do.\n\
4092This variable is not guaranteed to be accurate except while parsing\n\
4093frame-title-format.");
d39b6696
KH
4094
4095 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
4096 "Template for displaying the titlebar of visible frames.\n\
4097\(Assuming the window manager supports this feature.)\n\
4098This variable has the same structure as `mode-line-format' (which see),\n\
4099and is used only on frames for which no explicit name has been set\n\
4100\(see `modify-frame-parameters').");
4101 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
4102 "Template for displaying the titlebar of an iconified frame.\n\
4103\(Assuming the window manager supports this feature.)\n\
4104This variable has the same structure as `mode-line-format' (which see),\n\
4105and is used only on frames for which no explicit name has been set\n\
4106\(see `modify-frame-parameters').");
4107 Vicon_title_format
4108 = Vframe_title_format
4109 = Fcons (intern ("multiple-frames"),
4110 Fcons (build_string ("%b"),
4111 Fcons (Fcons (build_string (""),
4112 Fcons (intern ("invocation-name"),
4113 Fcons (build_string ("@"),
4114 Fcons (intern ("system-name"),
4115 Qnil)))),
4116 Qnil)));
5992c4f7
KH
4117
4118 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
4119 "Maximum number of lines to keep in the message log buffer.\n\
4120If nil, disable message logging. If t, log messages but don't truncate\n\
4121the buffer when it becomes large.");
4122 XSETFASTINT (Vmessage_log_max, 50);
08b610e4
RS
4123
4124 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
4125 "Functions called before redisplay, if window sizes have changed.\n\
4126The value should be a list of functions that take one argument.\n\
4127Just before redisplay, for each frame, if any of its windows have changed\n\
4128size since the last redisplay, or have been split or deleted,\n\
4129all the functions in the list are called, with the frame as argument.");
4130 Vwindow_size_change_functions = Qnil;
a2889657
JB
4131}
4132
4133/* initialize the window system */
4134init_xdisp ()
4135{
4136 Lisp_Object root_window;
4137#ifndef COMPILER_REGISTER_BUG
4138 register
4139#endif /* COMPILER_REGISTER_BUG */
4140 struct window *mini_w;
4141
4142 this_line_bufpos = 0;
4143
4144 mini_w = XWINDOW (minibuf_window);
11e82b76 4145 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
a2889657
JB
4146
4147 echo_area_glyphs = 0;
4148 previous_echo_glyphs = 0;
4149
4150 if (!noninteractive)
4151 {
44fa5b1e 4152 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
c2213350 4153 XSETFASTINT (XWINDOW (root_window)->top, 0);
44fa5b1e 4154 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
c2213350 4155 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
a2889657
JB
4156 set_window_height (minibuf_window, 1, 0);
4157
c2213350
KH
4158 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
4159 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));
a2889657
JB
4160 }
4161}