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