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