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