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