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