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