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