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