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