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