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