(save-match-data): Use save-match-data-internal
[emacs.git] / src / xdisp.c
blobd01775f5e222c1c29696a40e67468f6359c3d74d
1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include <config.h>
23 #include <stdio.h>
24 /*#include <ctype.h>*/
25 #undef NULL
26 #include "lisp.h"
27 #include "frame.h"
28 #include "window.h"
29 #include "termchar.h"
30 #include "dispextern.h"
31 #include "buffer.h"
32 #include "indent.h"
33 #include "commands.h"
34 #include "macros.h"
35 #include "disptab.h"
36 #include "termhooks.h"
37 #include "intervals.h"
38 #include "keyboard.h"
40 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
41 extern void set_frame_menubar ();
42 extern int pending_menu_activation;
43 #endif
45 extern int interrupt_input;
46 extern int command_loop_level;
48 extern Lisp_Object Qface;
50 extern Lisp_Object Voverriding_local_map;
51 extern Lisp_Object Voverriding_local_map_menu_flag;
53 Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
54 Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
55 Lisp_Object Qredisplay_end_trigger_functions;
57 /* Nonzero means print newline to stdout before next minibuffer message. */
59 int noninteractive_need_newline;
61 /* Nonzero means print newline to message log before next message. */
63 static int message_log_need_newline;
65 #define min(a, b) ((a) < (b) ? (a) : (b))
66 #define max(a, b) ((a) > (b) ? (a) : (b))
67 #define minmax(floor, val, ceil) \
68 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
70 /* The buffer position of the first character appearing
71 entirely or partially on the current frame line.
72 Or zero, which disables the optimization for the current frame line. */
73 static int this_line_bufpos;
75 /* Number of characters past the end of this line,
76 including the terminating newline */
77 static int this_line_endpos;
79 /* The vertical position of this frame line. */
80 static int this_line_vpos;
82 /* Hpos value for start of display on this frame line.
83 Usually zero, but negative if first character really began
84 on previous line */
85 static int this_line_start_hpos;
87 /* Buffer that this_line variables are describing. */
88 static struct buffer *this_line_buffer;
90 /* Value of echo_area_glyphs when it was last acted on.
91 If this is nonzero, there is a message on the frame
92 in the minibuffer and it should be erased as soon
93 as it is no longer requested to appear. */
94 char *previous_echo_glyphs;
96 /* Nonzero means truncate lines in all windows less wide than the frame */
97 int truncate_partial_width_windows;
99 /* Nonzero means we have more than one non-minibuffer-only frame.
100 Not guaranteed to be accurate except while parsing frame-title-format. */
101 int multiple_frames;
103 Lisp_Object Vglobal_mode_string;
105 /* Marker for where to display an arrow on top of the buffer text. */
106 Lisp_Object Voverlay_arrow_position;
108 /* String to display for the arrow. */
109 Lisp_Object Voverlay_arrow_string;
111 /* Like mode-line-format, but for the titlebar on a visible frame. */
112 Lisp_Object Vframe_title_format;
114 /* Like mode-line-format, but for the titlebar on an iconified frame. */
115 Lisp_Object Vicon_title_format;
117 /* List of functions to call when a window's size changes. These
118 functions get one arg, a frame on which one or more windows' sizes
119 have changed. */
120 static Lisp_Object Vwindow_size_change_functions;
122 /* Values of those variables at last redisplay. */
123 static Lisp_Object last_arrow_position, last_arrow_string;
125 Lisp_Object Qmenu_bar_update_hook;
127 /* Nonzero if overlay arrow has been displayed once in this window. */
128 static int overlay_arrow_seen;
130 /* Nonzero if visible end of buffer has already been displayed once
131 in this window. (We need this variable in case there are overlay
132 strings that get displayed there.) */
133 static int zv_strings_seen;
135 /* Nonzero means highlight the region even in nonselected windows. */
136 static int highlight_nonselected_windows;
138 /* If cursor motion alone moves point off frame,
139 Try scrolling this many lines up or down if that will bring it back. */
140 static int scroll_step;
142 /* Nonzero if try_window_id has made blank lines at window bottom
143 since the last redisplay that paused */
144 static int blank_end_of_window;
146 /* Number of windows showing the buffer of the selected window
147 (or another buffer with the same base buffer).
148 keyboard.c refers to this. */
149 int buffer_shared;
151 /* display_text_line sets these to the frame position (origin 0) of point,
152 whether the window is selected or not.
153 Set one to -1 first to determine whether point was found afterwards. */
155 static int cursor_vpos;
156 static int cursor_hpos;
158 static int debug_end_pos;
160 /* Nonzero means display mode line highlighted */
161 int mode_line_inverse_video;
163 static void redisplay_internal ();
164 static int message_log_check_duplicate ();
165 static void echo_area_display ();
166 void mark_window_display_accurate ();
167 static void redisplay_windows ();
168 static void redisplay_window ();
169 static void update_menu_bar ();
170 static void try_window ();
171 static int try_window_id ();
172 static struct position *display_text_line ();
173 static void display_mode_line ();
174 static int display_mode_element ();
175 static char *decode_mode_spec ();
176 static int display_string ();
177 static void display_menu_bar ();
178 static int display_count_lines ();
180 /* Prompt to display in front of the minibuffer contents */
181 Lisp_Object minibuf_prompt;
183 /* Width in columns of current minibuffer prompt. */
184 int minibuf_prompt_width;
186 /* Message to display instead of minibuffer contents
187 This is what the functions error and message make,
188 and command echoing uses it as well.
189 It overrides the minibuf_prompt as well as the buffer. */
190 char *echo_area_glyphs;
192 /* This is the length of the message in echo_area_glyphs. */
193 int echo_area_glyphs_length;
195 /* This is the window where the echo area message was displayed.
196 It is always a minibuffer window, but it may not be the
197 same window currently active as a minibuffer. */
198 Lisp_Object echo_area_window;
200 /* true iff we should redraw the mode lines on the next redisplay */
201 int update_mode_lines;
203 /* Smallest number of characters before the gap
204 at any time since last redisplay that finished.
205 Valid for current buffer when try_window_id can be called. */
206 int beg_unchanged;
208 /* Smallest number of characters after the gap
209 at any time since last redisplay that finished.
210 Valid for current buffer when try_window_id can be called. */
211 int end_unchanged;
213 /* MODIFF as of last redisplay that finished;
214 if it matches MODIFF, beg_unchanged and end_unchanged
215 contain no useful information */
216 int unchanged_modified;
218 /* Nonzero if window sizes or contents have changed
219 since last redisplay that finished */
220 int windows_or_buffers_changed;
222 /* Nonzero after display_mode_line if %l was used
223 and it displayed a line number. */
224 int line_number_displayed;
226 /* Maximum buffer size for which to display line numbers. */
227 static int line_number_display_limit;
229 /* Number of lines to keep in the message log buffer.
230 t means infinite. nil means don't log at all. */
231 Lisp_Object Vmessage_log_max;
233 /* Output a newline in the *Messages* buffer if "needs" one. */
235 void
236 message_log_maybe_newline ()
238 if (message_log_need_newline)
239 message_dolog ("", 0, 1);
243 /* Add a string to the message log, optionally terminated with a newline.
244 This function calls low-level routines in order to bypass text property
245 hooks, etc. which might not be safe to run. */
247 void
248 message_dolog (m, len, nlflag)
249 char *m;
250 int len, nlflag;
252 if (!NILP (Vmessage_log_max))
254 struct buffer *oldbuf;
255 int oldpoint, oldbegv, oldzv;
256 int old_windows_or_buffers_changed = windows_or_buffers_changed;
258 oldbuf = current_buffer;
259 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
260 current_buffer->undo_list = Qt;
261 oldpoint = PT;
262 oldbegv = BEGV;
263 oldzv = ZV;
264 BEGV = BEG;
265 ZV = Z;
266 if (oldpoint == Z)
267 oldpoint += len + nlflag;
268 if (oldzv == Z)
269 oldzv += len + nlflag;
270 TEMP_SET_PT (Z);
271 if (len)
272 insert_1 (m, len, 1, 0);
273 if (nlflag)
275 int this_bol, prev_bol, dup;
276 insert_1 ("\n", 1, 1, 0);
278 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
279 if (this_bol > BEG)
281 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
282 dup = message_log_check_duplicate (prev_bol, this_bol);
283 if (dup)
285 if (oldpoint > prev_bol)
286 oldpoint -= min (this_bol, oldpoint) - prev_bol;
287 if (oldbegv > prev_bol)
288 oldbegv -= min (this_bol, oldbegv) - prev_bol;
289 if (oldzv > prev_bol)
290 oldzv -= min (this_bol, oldzv) - prev_bol;
291 del_range_1 (prev_bol, this_bol, 0);
292 if (dup > 1)
294 char dupstr[40];
295 int duplen;
297 /* If you change this format, don't forget to also
298 change message_log_check_duplicate. */
299 sprintf (dupstr, " [%d times]", dup);
300 duplen = strlen (dupstr);
301 TEMP_SET_PT (Z-1);
302 if (oldpoint == Z)
303 oldpoint += duplen;
304 if (oldzv == Z)
305 oldzv += duplen;
306 insert_1 (dupstr, duplen, 1, 0);
311 if (NATNUMP (Vmessage_log_max))
313 int pos = scan_buffer ('\n', Z, 0,
314 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
315 oldpoint -= min (pos, oldpoint) - BEG;
316 oldbegv -= min (pos, oldbegv) - BEG;
317 oldzv -= min (pos, oldzv) - BEG;
318 del_range_1 (BEG, pos, 0);
321 BEGV = oldbegv;
322 ZV = oldzv;
323 TEMP_SET_PT (oldpoint);
324 set_buffer_internal (oldbuf);
325 windows_or_buffers_changed = old_windows_or_buffers_changed;
326 message_log_need_newline = !nlflag;
330 /* We are at the end of the buffer after just having inserted a newline.
331 (Note: We depend on the fact we won't be crossing the gap.)
332 Check to see if the most recent message looks a lot like the previous one.
333 Return 0 if different, 1 if the new one should just replace it, or a
334 value N > 1 if we should also append " [N times]". */
336 static int
337 message_log_check_duplicate (prev_bol, this_bol)
338 int prev_bol, this_bol;
340 int i;
341 int len = Z - 1 - this_bol;
342 int seen_dots = 0;
343 unsigned char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
344 unsigned char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
346 for (i = 0; i < len; i++)
348 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
349 && p1[i] != '\n')
350 seen_dots = 1;
351 if (p1[i] != p2[i])
352 return seen_dots;
354 p1 += len;
355 if (*p1 == '\n')
356 return 2;
357 if (*p1++ == ' ' && *p1++ == '[')
359 int n = 0;
360 while (*p1 >= '0' && *p1 <= '9')
361 n = n * 10 + *p1++ - '0';
362 if (strncmp (p1, " times]\n", 8) == 0)
363 return n+1;
365 return 0;
368 /* Display an echo area message M with a specified length of LEN chars.
369 The string may include null characters. If M is 0, clear out any
370 existing message, and let the minibuffer text show through.
372 The buffer M must continue to exist until after the echo area
373 gets cleared or some other message gets displayed there.
375 Do not pass text that is stored in a Lisp string.
376 Do not pass text in a buffer that was alloca'd. */
378 void
379 message2 (m, len)
380 char *m;
381 int len;
383 /* First flush out any partial line written with print. */
384 message_log_maybe_newline ();
385 if (m)
386 message_dolog (m, len, 1);
387 message2_nolog (m, len);
391 /* The non-logging counterpart of message2. */
393 void
394 message2_nolog (m, len)
395 char *m;
396 int len;
398 if (noninteractive)
400 if (noninteractive_need_newline)
401 putc ('\n', stderr);
402 noninteractive_need_newline = 0;
403 fwrite (m, len, 1, stderr);
404 if (cursor_in_echo_area == 0)
405 fprintf (stderr, "\n");
406 fflush (stderr);
408 /* A null message buffer means that the frame hasn't really been
409 initialized yet. Error messages get reported properly by
410 cmd_error, so this must be just an informative message; toss it. */
411 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
413 Lisp_Object mini_window;
414 FRAME_PTR f;
416 /* Get the frame containing the minibuffer
417 that the selected frame is using. */
418 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
419 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
421 #ifdef MULTI_FRAME
422 FRAME_SAMPLE_VISIBILITY (f);
423 if (FRAME_VISIBLE_P (selected_frame)
424 && ! FRAME_VISIBLE_P (f))
425 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window)));
426 #endif
428 if (m)
430 echo_area_glyphs = m;
431 echo_area_glyphs_length = len;
433 else
434 echo_area_glyphs = previous_echo_glyphs = 0;
436 do_pending_window_change ();
437 echo_area_display ();
438 update_frame (f, 1, 1);
439 do_pending_window_change ();
440 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
441 (*frame_up_to_date_hook) (f);
445 /* Display a null-terminated echo area message M. If M is 0, clear out any
446 existing message, and let the minibuffer text show through.
448 The buffer M must continue to exist until after the echo area
449 gets cleared or some other message gets displayed there.
451 Do not pass text that is stored in a Lisp string.
452 Do not pass text in a buffer that was alloca'd. */
454 void
455 message1 (m)
456 char *m;
458 message2 (m, (m ? strlen (m) : 0));
461 void
462 message1_nolog (m)
463 char *m;
465 message2_nolog (m, (m ? strlen (m) : 0));
468 /* Truncate what will be displayed in the echo area
469 the next time we display it--but don't redisplay it now. */
471 void
472 truncate_echo_area (len)
473 int len;
475 /* A null message buffer means that the frame hasn't really been
476 initialized yet. Error messages get reported properly by
477 cmd_error, so this must be just an informative message; toss it. */
478 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
479 echo_area_glyphs_length = len;
482 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
483 zero if being used by message. */
484 int message_buf_print;
486 /* Dump an informative message to the minibuf. If M is 0, clear out
487 any existing message, and let the minibuffer text show through. */
489 /* VARARGS 1 */
490 void
491 message (m, a1, a2, a3)
492 char *m;
493 EMACS_INT a1, a2, a3;
495 if (noninteractive)
497 if (m)
499 if (noninteractive_need_newline)
500 putc ('\n', stderr);
501 noninteractive_need_newline = 0;
502 fprintf (stderr, m, a1, a2, a3);
503 if (cursor_in_echo_area == 0)
504 fprintf (stderr, "\n");
505 fflush (stderr);
508 else if (INTERACTIVE)
510 /* The frame whose minibuffer we're going to display the message on.
511 It may be larger than the selected frame, so we need
512 to use its buffer, not the selected frame's buffer. */
513 Lisp_Object mini_window;
514 FRAME_PTR f;
516 /* Get the frame containing the minibuffer
517 that the selected frame is using. */
518 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
519 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
521 /* A null message buffer means that the frame hasn't really been
522 initialized yet. Error messages get reported properly by
523 cmd_error, so this must be just an informative message; toss it. */
524 if (FRAME_MESSAGE_BUF (f))
526 if (m)
528 int len;
529 #ifdef NO_ARG_ARRAY
530 EMACS_INT a[3];
531 a[0] = a1;
532 a[1] = a2;
533 a[2] = a3;
535 len = doprnt (FRAME_MESSAGE_BUF (f),
536 FRAME_WIDTH (f), m, (char *)0, 3, a);
537 #else
538 len = doprnt (FRAME_MESSAGE_BUF (f),
539 FRAME_WIDTH (f), m, (char *)0, 3, &a1);
540 #endif /* NO_ARG_ARRAY */
542 message2 (FRAME_MESSAGE_BUF (f), len);
544 else
545 message1 (0);
547 /* Print should start at the beginning of the message
548 buffer next time. */
549 message_buf_print = 0;
554 /* The non-logging version of message. */
555 void
556 message_nolog (m, a1, a2, a3)
557 char *m;
558 EMACS_INT a1, a2, a3;
560 Lisp_Object old_log_max;
561 old_log_max = Vmessage_log_max;
562 Vmessage_log_max = Qnil;
563 message (m, a1, a2, a3);
564 Vmessage_log_max = old_log_max;
567 void
568 update_echo_area ()
570 message2 (echo_area_glyphs, echo_area_glyphs_length);
573 static void
574 echo_area_display ()
576 register int vpos;
577 FRAME_PTR f;
578 Lisp_Object mini_window;
580 /* Choose the minibuffer window for this display.
581 It is the minibuffer window used by the selected frame. */
582 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
583 /* This is the frame that window is in. */
584 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
586 if (! FRAME_VISIBLE_P (f))
587 return;
589 if (frame_garbaged)
591 redraw_garbaged_frames ();
592 frame_garbaged = 0;
595 if (echo_area_glyphs || minibuf_level == 0)
597 echo_area_window = mini_window;
599 vpos = XFASTINT (XWINDOW (mini_window)->top);
600 get_display_line (f, vpos, 0);
601 display_string (XWINDOW (mini_window), vpos,
602 echo_area_glyphs ? echo_area_glyphs : "",
603 echo_area_glyphs ? echo_area_glyphs_length : -1,
604 0, 0, 0, 0, FRAME_WIDTH (f));
606 #if 0 /* This just gets in the way. update_frame does the job. */
607 /* If desired cursor location is on this line, put it at end of text */
608 if (cursor_in_echo_area)
609 FRAME_CURSOR_Y (f) = vpos;
610 if (FRAME_CURSOR_Y (f) == vpos)
611 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
612 #endif
614 /* Fill the rest of the minibuffer window with blank lines. */
616 int i;
618 for (i = vpos + 1;
619 i < vpos + XFASTINT (XWINDOW (mini_window)->height); i++)
621 get_display_line (f, i, 0);
622 display_string (XWINDOW (mini_window), vpos,
623 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f));
627 else if (!EQ (mini_window, selected_window))
628 windows_or_buffers_changed++;
630 if (EQ (mini_window, selected_window))
631 this_line_bufpos = 0;
633 previous_echo_glyphs = echo_area_glyphs;
636 /* Update frame titles. */
638 #ifdef HAVE_WINDOW_SYSTEM
639 static char frame_title_buf[512];
640 static char *frame_title_ptr;
642 static int
643 store_frame_title (str, mincol, maxcol)
644 char *str;
645 int mincol, maxcol;
647 char *limit;
648 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
649 maxcol = sizeof (frame_title_buf);
650 limit = &frame_title_buf[maxcol];
651 while (*str != '\0' && frame_title_ptr < limit)
652 *frame_title_ptr++ = *str++;
653 while (frame_title_ptr < &frame_title_buf[mincol])
654 *frame_title_ptr++ = ' ';
655 return frame_title_ptr - frame_title_buf;
658 static void
659 x_consider_frame_title (frame)
660 Lisp_Object frame;
662 Lisp_Object fmt;
663 struct buffer *obuf;
664 int len;
665 FRAME_PTR f = XFRAME (frame);
667 if (!(FRAME_WINDOW_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name))
668 return;
670 /* Do we have more than one visible frame on this X display? */
672 Lisp_Object tail;
674 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
676 FRAME_PTR tf = XFRAME (XCONS (tail)->car);
678 if (tf != f && FRAME_KBOARD (tf) == FRAME_KBOARD (f)
679 && !FRAME_MINIBUF_ONLY_P (tf)
680 && (FRAME_VISIBLE_P (tf) || FRAME_ICONIFIED_P (tf)))
681 break;
684 multiple_frames = CONSP (tail);
687 obuf = current_buffer;
688 Fset_buffer (XWINDOW (f->selected_window)->buffer);
689 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
690 frame_title_ptr = frame_title_buf;
691 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
692 0, sizeof (frame_title_buf), fmt);
693 frame_title_ptr = 0;
694 set_buffer_internal (obuf);
695 /* Set the name only if it's changed. This avoids consing
696 in the common case where it hasn't. (If it turns out that we've
697 already wasted too much time by walking through the list with
698 display_mode_element, then we might need to optimize at a higher
699 level than this.) */
700 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
701 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
702 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
704 #else
705 #define frame_title_ptr ((char *)0)
706 #define store_frame_title(str, mincol, maxcol) 0
707 #endif
709 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
710 This can call eval. */
712 void
713 prepare_menu_bars ()
715 register struct window *w = XWINDOW (selected_window);
716 int all_windows;
717 struct gcpro gcpro1, gcpro2;
719 all_windows = (update_mode_lines || buffer_shared > 1
720 || windows_or_buffers_changed);
722 /* Update all frame titles based on their buffer names, etc.
723 We do this before the menu bars so that the buffer-menu
724 will show the up-to-date frame titles.
726 This used to be done after the menu bars, for a reason that
727 was stated as follows but which I do not understand:
728 "We do this after the menu bars so that the frame will first
729 create its menu bar using the name `emacs' if no other name
730 has yet been specified."
731 I think that is no longer a concern. */
732 #ifdef HAVE_WINDOW_SYSTEM
733 if (windows_or_buffers_changed || update_mode_lines)
735 Lisp_Object tail, frame;
737 FOR_EACH_FRAME (tail, frame)
738 if (FRAME_VISIBLE_P (XFRAME (frame))
739 || FRAME_ICONIFIED_P (XFRAME (frame)))
740 x_consider_frame_title (frame);
742 #endif
744 /* Update the menu bar item lists, if appropriate.
745 This has to be done before any actual redisplay
746 or generation of display lines. */
747 if (all_windows)
749 Lisp_Object tail, frame;
750 int count = specpdl_ptr - specpdl;
752 record_unwind_protect (Fstore_match_data, Fmatch_data ());
754 FOR_EACH_FRAME (tail, frame)
756 /* If a window on this frame changed size,
757 report that to the user and clear the size-change flag. */
758 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
760 Lisp_Object functions;
761 /* Clear flag first in case we get error below. */
762 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
763 functions = Vwindow_size_change_functions;
764 GCPRO2 (tail, functions);
765 while (CONSP (functions))
767 call1 (XCONS (functions)->car, frame);
768 functions = XCONS (functions)->cdr;
770 UNGCPRO;
772 GCPRO1 (tail);
773 update_menu_bar (XFRAME (frame), 0);
774 UNGCPRO;
777 unbind_to (count, Qnil);
779 else
780 update_menu_bar (selected_frame, 1);
782 /* Motif needs this. See comment in xmenu.c.
783 Turn it off when pending_menu_activation is not defined. */
784 #ifdef USE_X_TOOLKIT
785 pending_menu_activation = 0;
786 #endif
789 /* Do a frame update, taking possible shortcuts into account.
790 This is the main external entry point for redisplay.
792 If the last redisplay displayed an echo area message and that
793 message is no longer requested, we clear the echo area
794 or bring back the minibuffer if that is in use.
796 Do not call eval from within this function.
797 Calls to eval after the call to echo_area_display would confuse
798 the display_line mechanism and would cause a crash.
799 Calls to eval before that point will work most of the time,
800 but can still lose, because this function
801 can be called from signal handlers; with alarms set up;
802 or with synchronous processes running.
804 See Fcall_process; if you called it from here, it could be
805 entered recursively. */
807 static int do_verify_charstarts;
809 /* Counter is used to clear the face cache
810 no more than once ever 1000 redisplays. */
811 static int clear_face_cache_count;
813 /* Record the previous terminal frame we displayed. */
814 static FRAME_PTR previous_terminal_frame;
816 void
817 redisplay ()
819 redisplay_internal (0);
822 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
823 is not in response to any user action; therefore, we should
824 preserve the echo area. (Actually, our caller does that job.)
825 Perhaps in the future avoid recentering windows
826 if it is not necessary; currently that causes some problems. */
828 static void
829 redisplay_internal (preserve_echo_area)
830 int preserve_echo_area;
832 register struct window *w = XWINDOW (selected_window);
833 register int pause;
834 int must_finish = 0;
835 int all_windows;
836 register int tlbufpos, tlendpos;
837 struct position pos;
839 if (noninteractive)
840 return;
842 #ifdef USE_X_TOOLKIT
843 if (popup_activated ())
844 return;
845 #endif
847 #ifdef MULTI_FRAME
848 if (! FRAME_WINDOW_P (selected_frame)
849 && previous_terminal_frame != selected_frame)
851 /* Since frames on an ASCII terminal share the same display area,
852 displaying a different frame means redisplay the whole thing. */
853 windows_or_buffers_changed++;
854 SET_FRAME_GARBAGED (selected_frame);
855 XSETFRAME (Vterminal_frame, selected_frame);
857 previous_terminal_frame = selected_frame;
858 #endif
860 /* Set the visible flags for all frames.
861 Do this before checking for resized or garbaged frames; they want
862 to know if their frames are visible.
863 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
865 Lisp_Object tail, frame;
867 FOR_EACH_FRAME (tail, frame)
869 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
871 /* Clear out all the display lines in which we will generate the
872 glyphs to display. */
873 init_desired_glyphs (XFRAME (frame));
877 /* Notice any pending interrupt request to change frame size. */
878 do_pending_window_change ();
880 if (frame_garbaged)
882 redraw_garbaged_frames ();
883 frame_garbaged = 0;
886 prepare_menu_bars ();
888 if (windows_or_buffers_changed)
889 update_mode_lines++;
891 /* Detect case that we need to write or remove a star in the mode line. */
892 if ((SAVE_MODIFF < MODIFF) != !NILP (w->last_had_star))
894 w->update_mode_line = Qt;
895 if (buffer_shared > 1)
896 update_mode_lines++;
899 /* If %c is in use, update it if needed. */
900 if (!NILP (w->column_number_displayed)
901 /* This alternative quickly identifies a common case
902 where no change is needed. */
903 && !(PT == XFASTINT (w->last_point)
904 && XFASTINT (w->last_modified) >= MODIFF)
905 && XFASTINT (w->column_number_displayed) != current_column ())
906 w->update_mode_line = Qt;
908 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
910 all_windows = update_mode_lines || buffer_shared > 1;
912 /* If specs for an arrow have changed, do thorough redisplay
913 to ensure we remove any arrow that should no longer exist. */
914 if (! EQ (Voverlay_arrow_position, last_arrow_position)
915 || ! EQ (Voverlay_arrow_string, last_arrow_string))
916 all_windows = 1;
918 /* Normally the message* functions will have already displayed and
919 updated the echo area, but the frame may have been trashed, or
920 the update may have been preempted, so display the echo area
921 again here. */
922 if (echo_area_glyphs || previous_echo_glyphs)
924 echo_area_display ();
925 must_finish = 1;
928 /* If showing region, and mark has changed, must redisplay whole window. */
929 if (((!NILP (Vtransient_mark_mode)
930 && !NILP (XBUFFER (w->buffer)->mark_active))
931 != !NILP (w->region_showing))
932 || (!NILP (w->region_showing)
933 && !EQ (w->region_showing,
934 Fmarker_position (XBUFFER (w->buffer)->mark))))
935 this_line_bufpos = -1;
937 tlbufpos = this_line_bufpos;
938 tlendpos = this_line_endpos;
939 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
940 && !current_buffer->clip_changed
941 && FRAME_VISIBLE_P (XFRAME (w->frame))
942 /* Make sure recorded data applies to current buffer, etc */
943 && this_line_buffer == current_buffer
944 && current_buffer == XBUFFER (w->buffer)
945 && NILP (w->force_start)
946 /* Point must be on the line that we have info recorded about */
947 && PT >= tlbufpos
948 && PT <= Z - tlendpos
949 /* All text outside that line, including its final newline,
950 must be unchanged */
951 && (XFASTINT (w->last_modified) >= MODIFF
952 || (beg_unchanged >= tlbufpos - 1
953 && GPT >= tlbufpos
954 /* If selective display, can't optimize
955 if the changes start at the beginning of the line. */
956 && ((INTEGERP (current_buffer->selective_display)
957 && XINT (current_buffer->selective_display) > 0
958 ? (beg_unchanged >= tlbufpos
959 && GPT > tlbufpos)
960 : 1))
961 && end_unchanged >= tlendpos
962 && Z - GPT >= tlendpos)))
964 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
965 && (tlbufpos == ZV
966 || FETCH_CHAR (tlbufpos) == '\n'))
967 /* Former continuation line has disappeared by becoming empty */
968 goto cancel;
969 else if (XFASTINT (w->last_modified) < MODIFF
970 || MINI_WINDOW_P (w))
972 cursor_vpos = -1;
973 overlay_arrow_seen = 0;
974 zv_strings_seen = 0;
975 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
976 pos_tab_offset (w, tlbufpos));
977 /* If line contains point, is not continued,
978 and ends at same distance from eob as before, we win */
979 if (cursor_vpos >= 0 && this_line_bufpos
980 && this_line_endpos == tlendpos)
982 /* If this is not the window's last line,
983 we must adjust the charstarts of the lines below. */
984 if (this_line_vpos + 1
985 < XFASTINT (w->top) + window_internal_height (w))
987 int left = XFASTINT (w->left);
988 int *charstart_next_line
989 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
990 int adjust;
992 if (Z - tlendpos == ZV)
993 /* This line ends at end of (accessible part of) buffer.
994 There is no newline to count. */
995 adjust = Z - tlendpos - charstart_next_line[left];
996 else
997 /* This line ends in a newline.
998 Must take account of the newline and the rest of the
999 text that follows. */
1000 adjust = Z - tlendpos + 1 - charstart_next_line[left];
1002 adjust_window_charstarts (w, this_line_vpos, adjust);
1005 if (XFASTINT (w->width) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w))))
1006 preserve_other_columns (w);
1007 goto update;
1009 else
1010 goto cancel;
1012 else if (PT == XFASTINT (w->last_point)
1013 /* Make sure the cursor was last displayed
1014 in this window. Otherwise we have to reposition it. */
1015 && XINT (w->top) <= FRAME_CURSOR_Y (selected_frame)
1016 && (XINT (w->top) + XINT (w->height)
1017 > FRAME_CURSOR_Y (selected_frame)))
1019 if (!must_finish)
1021 do_pending_window_change ();
1022 return;
1024 goto update;
1026 /* If highlighting the region, or if the cursor is in the echo area,
1027 then we can't just move the cursor. */
1028 else if (! (!NILP (Vtransient_mark_mode)
1029 && !NILP (current_buffer->mark_active))
1030 && NILP (w->region_showing)
1031 && !cursor_in_echo_area)
1033 pos = *compute_motion (tlbufpos, 0,
1034 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1036 PT, 2, - (1 << (BITS_PER_SHORT - 1)),
1037 window_internal_width (w) - 1,
1038 XINT (w->hscroll),
1039 pos_tab_offset (w, tlbufpos), w);
1040 if (pos.vpos < 1)
1042 int width = window_internal_width (w) - 1;
1043 FRAME_CURSOR_X (selected_frame)
1044 = XFASTINT (w->left) + minmax (0, pos.hpos, width);
1045 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
1046 goto update;
1048 else
1049 goto cancel;
1051 cancel:
1052 /* Text changed drastically or point moved off of line */
1053 cancel_line (this_line_vpos, selected_frame);
1056 this_line_bufpos = 0;
1057 all_windows |= buffer_shared > 1;
1059 clear_face_cache_count++;
1061 if (all_windows)
1063 Lisp_Object tail, frame;
1065 #ifdef HAVE_FACES
1066 /* Clear the face cache, only when we do a full redisplay
1067 and not too often either. */
1068 if (clear_face_cache_count > 1000)
1070 clear_face_cache ();
1071 clear_face_cache_count = 0;
1073 #endif
1075 /* Recompute # windows showing selected buffer.
1076 This will be incremented each time such a window is displayed. */
1077 buffer_shared = 0;
1079 FOR_EACH_FRAME (tail, frame)
1081 FRAME_PTR f = XFRAME (frame);
1082 if (FRAME_WINDOW_P (f) || f == selected_frame)
1085 /* Mark all the scroll bars to be removed; we'll redeem the ones
1086 we want when we redisplay their windows. */
1087 if (condemn_scroll_bars_hook)
1088 (*condemn_scroll_bars_hook) (f);
1090 if (FRAME_VISIBLE_P (f))
1091 redisplay_windows (FRAME_ROOT_WINDOW (f), preserve_echo_area);
1093 /* Any scroll bars which redisplay_windows should have nuked
1094 should now go away. */
1095 if (judge_scroll_bars_hook)
1096 (*judge_scroll_bars_hook) (f);
1100 else if (FRAME_VISIBLE_P (selected_frame))
1102 redisplay_window (selected_window, 1, preserve_echo_area);
1103 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
1104 preserve_other_columns (w);
1107 update:
1108 /* Prevent various kinds of signals during display update.
1109 stdio is not robust about handling signals,
1110 which can cause an apparent I/O error. */
1111 if (interrupt_input)
1112 unrequest_sigio ();
1113 stop_polling ();
1115 #ifdef MULTI_FRAME
1116 if (all_windows)
1118 Lisp_Object tail;
1120 pause = 0;
1122 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
1124 FRAME_PTR f;
1126 if (!FRAMEP (XCONS (tail)->car))
1127 continue;
1129 f = XFRAME (XCONS (tail)->car);
1131 if ((FRAME_WINDOW_P (f) || f == selected_frame)
1132 && FRAME_VISIBLE_P (f))
1134 pause |= update_frame (f, 0, 0);
1135 if (!pause)
1137 mark_window_display_accurate (f->root_window, 1);
1138 if (frame_up_to_date_hook != 0)
1139 (*frame_up_to_date_hook) (f);
1144 else
1145 #endif /* MULTI_FRAME */
1147 if (FRAME_VISIBLE_P (selected_frame))
1148 pause = update_frame (selected_frame, 0, 0);
1149 else
1150 pause = 0;
1152 /* We may have called echo_area_display at the top of this
1153 function. If the echo area is on another frame, that may
1154 have put text on a frame other than the selected one, so the
1155 above call to update_frame would not have caught it. Catch
1156 it here. */
1158 Lisp_Object mini_window;
1159 FRAME_PTR mini_frame;
1161 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
1162 mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
1164 if (mini_frame != selected_frame && FRAME_WINDOW_P (mini_frame))
1165 pause |= update_frame (mini_frame, 0, 0);
1169 /* If frame does not match, prevent doing single-line-update next time.
1170 Also, don't forget to check every line to update the arrow. */
1171 if (pause)
1173 this_line_bufpos = 0;
1174 if (!NILP (last_arrow_position))
1176 last_arrow_position = Qt;
1177 last_arrow_string = Qt;
1179 /* If we pause after scrolling, some lines in current_frame
1180 may be null, so preserve_other_columns won't be able to
1181 preserve all the vertical-bar separators. So, avoid using it
1182 in that case. */
1183 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
1184 update_mode_lines = 1;
1187 /* Now text on frame agrees with windows, so
1188 put info into the windows for partial redisplay to follow */
1190 if (!pause)
1192 register struct buffer *b = XBUFFER (w->buffer);
1194 blank_end_of_window = 0;
1195 unchanged_modified = BUF_MODIFF (b);
1196 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1197 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1199 XSETFASTINT (w->last_point, BUF_PT (b));
1200 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1201 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1203 if (all_windows)
1204 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1205 else
1207 b->clip_changed = 0;
1208 w->update_mode_line = Qnil;
1209 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1210 w->last_had_star
1211 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1212 ? Qt : Qnil);
1213 w->window_end_valid = w->buffer;
1214 last_arrow_position = Voverlay_arrow_position;
1215 last_arrow_string = Voverlay_arrow_string;
1216 if (do_verify_charstarts)
1217 verify_charstarts (w);
1218 if (frame_up_to_date_hook != 0)
1219 (*frame_up_to_date_hook) (selected_frame);
1221 update_mode_lines = 0;
1222 windows_or_buffers_changed = 0;
1225 /* Start SIGIO interrupts coming again.
1226 Having them off during the code above
1227 makes it less likely one will discard output,
1228 but not impossible, since there might be stuff
1229 in the system buffer here.
1230 But it is much hairier to try to do anything about that. */
1232 if (interrupt_input)
1233 request_sigio ();
1234 start_polling ();
1236 /* Change frame size now if a change is pending. */
1237 do_pending_window_change ();
1239 /* If we just did a pending size change, redisplay again
1240 for the new size. */
1241 if (windows_or_buffers_changed && !pause)
1242 redisplay ();
1245 /* Redisplay, but leave alone any recent echo area message
1246 unless another message has been requested in its place.
1248 This is useful in situations where you need to redisplay but no
1249 user action has occurred, making it inappropriate for the message
1250 area to be cleared. See tracking_off and
1251 wait_reading_process_input for examples of these situations. */
1253 redisplay_preserve_echo_area ()
1255 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1257 echo_area_glyphs = previous_echo_glyphs;
1258 redisplay_internal (1);
1259 echo_area_glyphs = 0;
1261 else
1262 redisplay_internal (1);
1265 void
1266 mark_window_display_accurate (window, flag)
1267 Lisp_Object window;
1268 int flag;
1270 register struct window *w;
1272 for (;!NILP (window); window = w->next)
1274 if (!WINDOWP (window)) abort ();
1275 w = XWINDOW (window);
1277 if (!NILP (w->buffer))
1279 XSETFASTINT (w->last_modified,
1280 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1281 w->last_had_star
1282 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1283 ? Qt : Qnil);
1285 /* Record if we are showing a region, so can make sure to
1286 update it fully at next redisplay. */
1287 w->region_showing = (!NILP (Vtransient_mark_mode)
1288 && !NILP (XBUFFER (w->buffer)->mark_active)
1289 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1290 : Qnil);
1293 w->window_end_valid = w->buffer;
1294 w->update_mode_line = Qnil;
1295 if (!NILP (w->buffer) && flag)
1296 XBUFFER (w->buffer)->clip_changed = 0;
1298 if (!NILP (w->vchild))
1299 mark_window_display_accurate (w->vchild, flag);
1300 if (!NILP (w->hchild))
1301 mark_window_display_accurate (w->hchild, flag);
1304 if (flag)
1306 last_arrow_position = Voverlay_arrow_position;
1307 last_arrow_string = Voverlay_arrow_string;
1309 else
1311 /* t is unequal to any useful value of Voverlay_arrow_... */
1312 last_arrow_position = Qt;
1313 last_arrow_string = Qt;
1317 /* Update the menu bar item list for frame F.
1318 This has to be done before we start to fill in any display lines,
1319 because it can call eval.
1321 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1323 static void
1324 update_menu_bar (f, save_match_data)
1325 FRAME_PTR f;
1326 int save_match_data;
1328 struct buffer *old = current_buffer;
1329 Lisp_Object window;
1330 register struct window *w;
1332 window = FRAME_SELECTED_WINDOW (f);
1333 w = XWINDOW (window);
1335 if (update_mode_lines)
1336 w->update_mode_line = Qt;
1338 if (FRAME_WINDOW_P (f)
1340 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1341 FRAME_EXTERNAL_MENU_BAR (f)
1342 #else
1343 FRAME_MENU_BAR_LINES (f) > 0
1344 #endif
1345 : FRAME_MENU_BAR_LINES (f) > 0)
1347 /* If the user has switched buffers or windows, we need to
1348 recompute to reflect the new bindings. But we'll
1349 recompute when update_mode_lines is set too; that means
1350 that people can use force-mode-line-update to request
1351 that the menu bar be recomputed. The adverse effect on
1352 the rest of the redisplay algorithm is about the same as
1353 windows_or_buffers_changed anyway. */
1354 if (windows_or_buffers_changed
1355 || !NILP (w->update_mode_line)
1356 || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1357 < BUF_MODIFF (XBUFFER (w->buffer)))
1358 != !NILP (w->last_had_star))
1359 || ((!NILP (Vtransient_mark_mode)
1360 && !NILP (XBUFFER (w->buffer)->mark_active))
1361 != !NILP (w->region_showing)))
1363 struct buffer *prev = current_buffer;
1364 int count = specpdl_ptr - specpdl;
1366 set_buffer_internal_1 (XBUFFER (w->buffer));
1367 if (save_match_data)
1368 record_unwind_protect (Fstore_match_data, Fmatch_data ());
1369 if (NILP (Voverriding_local_map_menu_flag))
1371 specbind (Qoverriding_terminal_local_map, Qnil);
1372 specbind (Qoverriding_local_map, Qnil);
1375 /* Run the Lucid hook. */
1376 call1 (Vrun_hooks, Qactivate_menubar_hook);
1377 /* If it has changed current-menubar from previous value,
1378 really recompute the menubar from the value. */
1379 if (! NILP (Vlucid_menu_bar_dirty_flag))
1380 call0 (Qrecompute_lucid_menubar);
1381 safe_run_hooks (Qmenu_bar_update_hook);
1382 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1383 /* Redisplay the menu bar in case we changed it. */
1384 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1385 if (FRAME_WINDOW_P (f))
1386 set_frame_menubar (f, 0, 0);
1387 else
1388 /* On a terminal screen, the menu bar is an ordinary screen
1389 line, and this makes it get updated. */
1390 w->update_mode_line = Qt;
1391 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1392 /* In the non-toolkit version, the menu bar is an ordinary screen
1393 line, and this makes it get updated. */
1394 w->update_mode_line = Qt;
1395 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1397 unbind_to (count, Qnil);
1398 set_buffer_internal_1 (prev);
1403 int do_id = 1;
1405 /* Redisplay WINDOW and its subwindows and siblings. */
1407 static void
1408 redisplay_windows (window, preserve_echo_area)
1409 Lisp_Object window;
1410 int preserve_echo_area;
1412 for (; !NILP (window); window = XWINDOW (window)->next)
1413 redisplay_window (window, 0, preserve_echo_area);
1416 /* Redisplay window WINDOW and its subwindows. */
1418 static void
1419 redisplay_window (window, just_this_one, preserve_echo_area)
1420 Lisp_Object window;
1421 int just_this_one, preserve_echo_area;
1423 register struct window *w = XWINDOW (window);
1424 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1425 int height;
1426 register int lpoint = PT;
1427 struct buffer *old = current_buffer;
1428 register int width = window_internal_width (w) - 1;
1429 register int startp;
1430 register int hscroll = XINT (w->hscroll);
1431 struct position pos;
1432 int opoint = PT;
1433 int tem;
1434 int update_mode_line;
1435 struct Lisp_Char_Table *dp = window_display_table (w);
1437 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1439 /* If this is a combination window, do its children; that's all. */
1441 if (!NILP (w->vchild))
1443 redisplay_windows (w->vchild, preserve_echo_area);
1444 return;
1446 if (!NILP (w->hchild))
1448 redisplay_windows (w->hchild, preserve_echo_area);
1449 return;
1451 if (NILP (w->buffer))
1452 abort ();
1454 height = window_internal_height (w);
1455 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1456 if (XBUFFER (w->buffer)->clip_changed)
1457 update_mode_line = 1;
1459 if (MINI_WINDOW_P (w))
1461 if (w == XWINDOW (echo_area_window) && echo_area_glyphs)
1462 /* We've already displayed the echo area glyphs in this window. */
1463 goto finish_scroll_bars;
1464 else if (w != XWINDOW (minibuf_window))
1466 /* This is a minibuffer, but it's not the currently active one,
1467 so clear it. */
1468 int vpos = XFASTINT (w->top);
1469 int i;
1471 for (i = 0; i < height; i++)
1473 get_display_line (f, vpos + i, 0);
1474 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
1477 goto finish_scroll_bars;
1481 /* Otherwise set up data on this window; select its buffer and point value */
1483 if (update_mode_line)
1484 set_buffer_internal_1 (XBUFFER (w->buffer));
1485 else
1486 set_buffer_temp (XBUFFER (w->buffer));
1488 opoint = PT;
1490 /* If %c is in mode line, update it if needed. */
1491 if (!NILP (w->column_number_displayed)
1492 /* This alternative quickly identifies a common case
1493 where no change is needed. */
1494 && !(PT == XFASTINT (w->last_point)
1495 && XFASTINT (w->last_modified) >= MODIFF)
1496 && XFASTINT (w->column_number_displayed) != current_column ())
1497 update_mode_line = 1;
1499 /* Count number of windows showing the selected buffer.
1500 An indirect buffer counts as its base buffer. */
1502 if (!just_this_one)
1504 struct buffer *current_base, *window_base;
1505 current_base = current_buffer;
1506 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1507 if (current_base->base_buffer)
1508 current_base = current_base->base_buffer;
1509 if (window_base->base_buffer)
1510 window_base = window_base->base_buffer;
1511 if (current_base == window_base)
1512 buffer_shared++;
1515 /* POINT refers normally to the selected window.
1516 For any other window, set up appropriate value. */
1518 if (!EQ (window, selected_window))
1520 int new_pt = marker_position (w->pointm);
1521 if (new_pt < BEGV)
1523 new_pt = BEGV;
1524 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1526 else if (new_pt > (ZV - 1))
1528 new_pt = ZV;
1529 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1531 /* We don't use SET_PT so that the point-motion hooks don't run. */
1532 BUF_PT (current_buffer) = new_pt;
1535 /* If any of the character widths specified in the display table
1536 have changed, invalidate the width run cache. It's true that this
1537 may be a bit late to catch such changes, but the rest of
1538 redisplay goes (non-fatally) haywire when the display table is
1539 changed, so why should we worry about doing any better? */
1540 if (current_buffer->width_run_cache)
1542 struct Lisp_Char_Table *disptab = buffer_display_table ();
1544 if (! disptab_matches_widthtab (disptab,
1545 XVECTOR (current_buffer->width_table)))
1547 invalidate_region_cache (current_buffer,
1548 current_buffer->width_run_cache,
1549 BEG, Z);
1550 recompute_width_table (current_buffer, disptab);
1554 /* If window-start is screwed up, choose a new one. */
1555 if (XMARKER (w->start)->buffer != current_buffer)
1556 goto recenter;
1558 startp = marker_position (w->start);
1560 /* Handle case where place to start displaying has been specified,
1561 unless the specified location is outside the accessible range. */
1562 if (!NILP (w->force_start))
1564 w->force_start = Qnil;
1565 /* Forget any recorded base line for line number display. */
1566 w->base_line_number = Qnil;
1567 /* Redisplay the mode line. Select the buffer properly for that.
1568 Also, run the hook window-scroll-functions
1569 because we have scrolled. */
1570 /* Note, we do this after clearing force_start because
1571 if there's an error, it is better to forget about force_start
1572 than to get into an infinite loop calling the hook functions
1573 and having them get more errors. */
1574 if (!update_mode_line
1575 || ! NILP (Vwindow_scroll_functions))
1577 Lisp_Object temp[3];
1579 set_buffer_temp (old);
1580 set_buffer_internal_1 (XBUFFER (w->buffer));
1581 update_mode_line = 1;
1582 w->update_mode_line = Qt;
1583 if (! NILP (Vwindow_scroll_functions))
1585 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1586 make_number (startp));
1587 startp = marker_position (w->start);
1590 XSETFASTINT (w->last_modified, 0);
1591 if (startp < BEGV) startp = BEGV;
1592 if (startp > ZV) startp = ZV;
1593 try_window (window, startp);
1594 if (cursor_vpos < 0)
1596 /* If point does not appear, move point so it does appear */
1597 pos = *compute_motion (startp, 0,
1598 (((EQ (window, minibuf_window)
1599 && startp == BEG)
1600 ? minibuf_prompt_width : 0)
1601 + (hscroll ? 1 - hscroll : 0)),
1603 ZV, height / 2,
1604 - (1 << (BITS_PER_SHORT - 1)),
1605 width, hscroll, pos_tab_offset (w, startp), w);
1606 BUF_PT (current_buffer) = pos.bufpos;
1607 if (w != XWINDOW (selected_window))
1608 Fset_marker (w->pointm, make_number (PT), Qnil);
1609 else
1611 if (current_buffer == old)
1612 lpoint = PT;
1613 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1614 + minmax (0, pos.hpos, width));
1615 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1617 /* If we are highlighting the region,
1618 then we just changed the region, so redisplay to show it. */
1619 if (!NILP (Vtransient_mark_mode)
1620 && !NILP (current_buffer->mark_active))
1622 cancel_my_columns (XWINDOW (window));
1623 try_window (window, startp);
1626 goto done;
1629 /* Handle case where text has not changed, only point,
1630 and it has not moved off the frame. */
1632 /* This code is not used for minibuffer for the sake of
1633 the case of redisplaying to replace an echo area message;
1634 since in that case the minibuffer contents per se are usually unchanged.
1635 This code is of no real use in the minibuffer since
1636 the handling of this_line_bufpos, etc.,
1637 in redisplay handles the same cases. */
1639 if (XFASTINT (w->last_modified) >= MODIFF
1640 && PT >= startp && !current_buffer->clip_changed
1641 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
1642 /* If force-mode-line-update was called, really redisplay;
1643 that's how redisplay is forced after e.g. changing
1644 buffer-invisibility-spec. */
1645 && NILP (w->update_mode_line)
1646 /* Can't use this case if highlighting a region. */
1647 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1648 && NILP (w->region_showing)
1649 /* If end pos is out of date, scroll bar and percentage will be wrong */
1650 && INTEGERP (w->window_end_vpos)
1651 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1652 && !EQ (window, minibuf_window))
1654 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0,
1655 PT, height, 0, width, hscroll,
1656 pos_tab_offset (w, startp), w);
1658 if (pos.vpos < height)
1660 /* Ok, point is still on frame */
1661 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1663 /* These variables are supposed to be origin 1 */
1664 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1665 + minmax (0, pos.hpos, width));
1666 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1668 /* This doesn't do the trick, because if a window to the right of
1669 this one must be redisplayed, this does nothing because there
1670 is nothing in DesiredFrame yet, and then the other window is
1671 redisplayed, making likes that are empty in this window's columns.
1672 if (XFASTINT (w->width) != FRAME_WIDTH (f))
1673 preserve_my_columns (w);
1675 goto done;
1677 /* Don't bother trying redisplay with same start;
1678 we already know it will lose */
1680 /* If current starting point was originally the beginning of a line
1681 but no longer is, find a new starting point. */
1682 else if (!NILP (w->start_at_line_beg)
1683 && !(startp <= BEGV
1684 || FETCH_CHAR (startp - 1) == '\n'))
1686 goto recenter;
1688 else if (just_this_one && !MINI_WINDOW_P (w)
1689 && PT >= startp
1690 && XFASTINT (w->last_modified)
1691 /* or else vmotion on first line won't work. */
1692 && ! NILP (w->start_at_line_beg)
1693 && ! EQ (w->window_end_valid, Qnil)
1694 && do_id && !current_buffer->clip_changed
1695 && !blank_end_of_window
1696 && XFASTINT (w->width) == FRAME_WIDTH (f)
1697 /* Can't use this case if highlighting a region. */
1698 && !(!NILP (Vtransient_mark_mode)
1699 && !NILP (current_buffer->mark_active))
1700 /* Don't use try_window_id if newline
1701 doesn't display as the end of a line. */
1702 && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n')))
1703 && NILP (w->region_showing)
1704 && EQ (last_arrow_position, Voverlay_arrow_position)
1705 && EQ (last_arrow_string, Voverlay_arrow_string)
1706 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1707 && tem != -2)
1709 /* tem > 0 means success. tem == -1 means choose new start.
1710 tem == -2 means try again with same start,
1711 and nothing but whitespace follows the changed stuff.
1712 tem == 0 means try again with same start. */
1713 if (tem > 0)
1714 goto done;
1716 else if (startp >= BEGV && startp <= ZV
1717 && (startp < ZV
1718 /* Avoid starting at end of buffer. */
1719 #if 0 /* This change causes trouble for M-! finger & RET.
1720 It will have to be considered later. */
1721 || ! EQ (window, selected_window)
1722 /* Don't do the recentering if redisplay
1723 is not for no user action. */
1724 || preserve_echo_area
1725 #endif
1726 || startp == BEGV
1727 || (XFASTINT (w->last_modified) >= MODIFF)))
1729 /* Try to redisplay starting at same place as before */
1730 /* If point has not moved off frame, accept the results */
1731 try_window (window, startp);
1732 if (cursor_vpos >= 0)
1734 if (!just_this_one || current_buffer->clip_changed
1735 || beg_unchanged < startp)
1736 /* Forget any recorded base line for line number display. */
1737 w->base_line_number = Qnil;
1738 goto done;
1740 else
1741 cancel_my_columns (w);
1744 XSETFASTINT (w->last_modified, 0);
1745 /* Redisplay the mode line. Select the buffer properly for that. */
1746 if (!update_mode_line)
1748 set_buffer_temp (old);
1749 set_buffer_internal_1 (XBUFFER (w->buffer));
1750 update_mode_line = 1;
1751 w->update_mode_line = Qt;
1754 /* Try to scroll by specified few lines */
1756 if (scroll_step && !current_buffer->clip_changed
1757 && startp >= BEGV && startp <= ZV)
1759 if (PT > startp)
1761 pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w);
1762 if (pos.vpos >= height)
1763 goto scroll_fail;
1766 pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w);
1768 if (PT >= pos.bufpos)
1770 if (! NILP (Vwindow_scroll_functions))
1772 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
1773 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1774 make_number (pos.bufpos));
1775 pos.bufpos = marker_position (w->start);
1777 try_window (window, pos.bufpos);
1778 if (cursor_vpos >= 0)
1780 if (!just_this_one || current_buffer->clip_changed
1781 || beg_unchanged < startp)
1782 /* Forget any recorded base line for line number display. */
1783 w->base_line_number = Qnil;
1784 goto done;
1786 else
1787 cancel_my_columns (w);
1789 scroll_fail: ;
1792 /* Finally, just choose place to start which centers point */
1794 recenter:
1795 /* Forget any previously recorded base line for line number display. */
1796 w->base_line_number = Qnil;
1798 pos = *vmotion (PT, - (height / 2), w);
1799 /* Set startp here explicitly in case that helps avoid an infinite loop
1800 in case the window-scroll-functions functions get errors. */
1801 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
1802 if (! NILP (Vwindow_scroll_functions))
1804 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1805 make_number (pos.bufpos));
1806 pos.bufpos = marker_position (w->start);
1808 try_window (window, pos.bufpos);
1810 startp = marker_position (w->start);
1811 w->start_at_line_beg
1812 = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
1814 done:
1815 if ((update_mode_line
1816 /* If window not full width, must redo its mode line
1817 if the window to its side is being redone */
1818 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
1819 || INTEGERP (w->base_line_pos)
1820 || (!NILP (w->column_number_displayed)
1821 && XFASTINT (w->column_number_displayed) != current_column ()))
1822 && height != XFASTINT (w->height))
1823 display_mode_line (w);
1824 if (! line_number_displayed
1825 && ! BUFFERP (w->base_line_pos))
1827 w->base_line_pos = Qnil;
1828 w->base_line_number = Qnil;
1831 /* When we reach a frame's selected window, redo the frame's menu bar. */
1832 if (update_mode_line
1833 && (FRAME_WINDOW_P (f)
1835 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1836 FRAME_EXTERNAL_MENU_BAR (f)
1837 #else
1838 FRAME_MENU_BAR_LINES (f) > 0
1839 #endif
1840 : FRAME_MENU_BAR_LINES (f) > 0)
1841 && EQ (FRAME_SELECTED_WINDOW (f), window))
1842 display_menu_bar (w);
1844 finish_scroll_bars:
1845 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
1847 int start, end, whole;
1849 /* Calculate the start and end positions for the current window.
1850 At some point, it would be nice to choose between scrollbars
1851 which reflect the whole buffer size, with special markers
1852 indicating narrowing, and scrollbars which reflect only the
1853 visible region.
1855 Note that minibuffers sometimes aren't displaying any text. */
1856 if (! MINI_WINDOW_P (w)
1857 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1859 whole = ZV - BEGV;
1860 start = marker_position (w->start) - BEGV;
1861 /* I don't think this is guaranteed to be right. For the
1862 moment, we'll pretend it is. */
1863 end = (Z - XINT (w->window_end_pos)) - BEGV;
1865 if (end < start) end = start;
1866 if (whole < (end - start)) whole = end - start;
1868 else
1869 start = end = whole = 0;
1871 /* Indicate what this scroll bar ought to be displaying now. */
1872 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
1874 /* Note that we actually used the scroll bar attached to this window,
1875 so it shouldn't be deleted at the end of redisplay. */
1876 (*redeem_scroll_bar_hook) (w);
1879 BUF_PT (current_buffer) = opoint;
1880 if (update_mode_line)
1881 set_buffer_internal_1 (old);
1882 else
1883 set_buffer_temp (old);
1884 BUF_PT (current_buffer) = lpoint;
1887 /* Do full redisplay on one window, starting at position `pos'. */
1889 static void
1890 try_window (window, pos)
1891 Lisp_Object window;
1892 register int pos;
1894 register struct window *w = XWINDOW (window);
1895 register int height = window_internal_height (w);
1896 register int vpos = XFASTINT (w->top);
1897 register int last_text_vpos = vpos;
1898 int tab_offset = pos_tab_offset (w, pos);
1899 FRAME_PTR f = XFRAME (w->frame);
1900 int width = window_internal_width (w) - 1;
1901 struct position val;
1903 Fset_marker (w->start, make_number (pos), Qnil);
1904 cursor_vpos = -1;
1905 overlay_arrow_seen = 0;
1906 zv_strings_seen = 0;
1907 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1909 while (--height >= 0)
1911 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1912 tab_offset += width;
1913 /* For the first line displayed, display_text_line
1914 subtracts the prompt width from the tab offset.
1915 But it does not affect the value of our variable tab_offset.
1916 So we do the subtraction again,
1917 for the sake of continuation lines of that first line. */
1918 if (MINI_WINDOW_P (w) && vpos == XFASTINT (w->top))
1919 tab_offset -= minibuf_prompt_width;
1921 if (val.vpos) tab_offset = 0;
1922 vpos++;
1923 if (pos != val.bufpos)
1925 int invis = 0;
1926 #ifdef USE_TEXT_PROPERTIES
1927 Lisp_Object invis_prop;
1928 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
1929 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
1930 #endif
1932 last_text_vpos
1933 /* Next line, unless prev line ended in end of buffer with no cr */
1934 = vpos - (val.vpos
1935 && (FETCH_CHAR (val.bufpos - 1) != '\n' || invis));
1937 pos = val.bufpos;
1940 /* If last line is continued in middle of character,
1941 include the split character in the text considered on the frame */
1942 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1943 pos++;
1945 /* If bottom just moved off end of frame, change mode line percentage. */
1946 if (XFASTINT (w->window_end_pos) == 0
1947 && Z != pos)
1948 w->update_mode_line = Qt;
1950 /* Say where last char on frame will be, once redisplay is finished. */
1951 XSETFASTINT (w->window_end_pos, Z - pos);
1952 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
1953 /* But that is not valid info until redisplay finishes. */
1954 w->window_end_valid = Qnil;
1957 /* Try to redisplay when buffer is modified locally,
1958 computing insert/delete line to preserve text outside
1959 the bounds of the changes.
1960 Return 1 if successful, 0 if if cannot tell what to do,
1961 or -1 to tell caller to find a new window start,
1962 or -2 to tell caller to do normal redisplay with same window start. */
1964 static int
1965 try_window_id (window)
1966 Lisp_Object window;
1968 int pos;
1969 register struct window *w = XWINDOW (window);
1970 register int height = window_internal_height (w);
1971 FRAME_PTR f = XFRAME (w->frame);
1972 int top = XFASTINT (w->top);
1973 int start = marker_position (w->start);
1974 int width = window_internal_width (w) - 1;
1975 int hscroll = XINT (w->hscroll);
1976 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
1977 int did_motion;
1978 register int vpos;
1979 register int i, tem;
1980 int last_text_vpos = 0;
1981 int stop_vpos;
1982 int selective = (INTEGERP (current_buffer->selective_display)
1983 ? XINT (current_buffer->selective_display)
1984 : !NILP (current_buffer->selective_display) ? -1 : 0);
1986 struct position val, bp, ep, xp, pp;
1987 int scroll_amount = 0;
1988 int delta;
1989 int tab_offset, epto, old_tick;
1991 if (GPT - BEG < beg_unchanged)
1992 beg_unchanged = GPT - BEG;
1993 if (Z - GPT < end_unchanged)
1994 end_unchanged = Z - GPT;
1996 if (beg_unchanged + BEG < start)
1997 return 0; /* Give up if changes go above top of window */
1999 /* Find position before which nothing is changed. */
2000 bp = *compute_motion (start, 0, lmargin, 0,
2001 min (ZV, beg_unchanged + BEG), height, 0,
2002 width, hscroll, pos_tab_offset (w, start), w);
2003 if (bp.vpos >= height)
2005 if (PT < bp.bufpos)
2007 /* All changes are beyond the window end, and point is on the screen.
2008 We don't need to change the text at all.
2009 But we need to update window_end_pos to account for
2010 any change in buffer size. */
2011 bp = *compute_motion (start, 0, lmargin, 0,
2012 ZV, height, 0,
2013 width, hscroll, pos_tab_offset (w, start), w);
2014 XSETFASTINT (w->window_end_vpos, height);
2015 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
2016 goto findpoint;
2018 return 0;
2021 vpos = bp.vpos;
2023 /* Find beginning of that frame line. Must display from there. */
2024 bp = *vmotion (bp.bufpos, 0, w);
2026 pos = bp.bufpos;
2027 val.hpos = lmargin;
2028 if (pos < start)
2029 return -1;
2031 did_motion = 0;
2032 /* If about to start displaying at the beginning of a continuation line,
2033 really start with previous frame line, in case it was not
2034 continued when last redisplayed */
2035 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
2037 /* Likewise if we have to worry about selective display. */
2038 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
2040 bp = *vmotion (bp.bufpos, -1, w);
2041 --vpos;
2042 pos = bp.bufpos;
2045 if (bp.contin && bp.hpos != lmargin)
2047 val.hpos = bp.prevhpos - width + lmargin;
2048 did_motion = 1;
2049 pos--;
2052 bp.vpos = vpos;
2054 /* Find first visible newline after which no more is changed. */
2055 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
2056 if (selective > 0)
2057 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
2058 tem = find_next_newline (tem, 1);
2060 /* Compute the cursor position after that newline. */
2061 ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem,
2062 height, - (1 << (BITS_PER_SHORT - 1)),
2063 width, hscroll, pos_tab_offset (w, bp.bufpos), w);
2065 /* If changes reach past the text available on the frame,
2066 just display rest of frame. */
2067 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
2068 stop_vpos = height;
2069 else
2070 stop_vpos = ep.vpos;
2072 /* If no newline before ep, the line ep is on includes some changes
2073 that must be displayed. Make sure we don't stop before it. */
2074 /* Also, if changes reach all the way until ep.bufpos,
2075 it is possible that something was deleted after the
2076 newline before it, so the following line must be redrawn. */
2077 if (stop_vpos == ep.vpos
2078 && (ep.bufpos == BEGV
2079 || FETCH_CHAR (ep.bufpos - 1) != '\n'
2080 || ep.bufpos == Z - end_unchanged))
2081 stop_vpos = ep.vpos + 1;
2083 cursor_vpos = -1;
2084 overlay_arrow_seen = 0;
2085 zv_strings_seen = 0;
2087 /* If changes do not reach to bottom of window,
2088 figure out how much to scroll the rest of the window */
2089 if (stop_vpos < height)
2091 /* Now determine how far up or down the rest of the window has moved */
2092 epto = pos_tab_offset (w, ep.bufpos);
2093 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2094 Z - XFASTINT (w->window_end_pos),
2095 10000, 0, width, hscroll, epto, w);
2096 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
2098 /* Is everything on frame below the changes whitespace?
2099 If so, no scrolling is really necessary. */
2100 for (i = ep.bufpos; i < xp.bufpos; i++)
2102 tem = FETCH_CHAR (i);
2103 if (tem != ' ' && tem != '\n' && tem != '\t')
2104 break;
2106 if (i == xp.bufpos)
2107 return -2;
2109 XSETFASTINT (w->window_end_vpos,
2110 XFASTINT (w->window_end_vpos) + scroll_amount);
2112 /* Before doing any scrolling, verify that point will be on frame. */
2113 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height))
2115 if (PT <= xp.bufpos)
2117 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2118 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2119 width, hscroll, epto, w);
2121 else
2123 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1,
2124 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2125 width, hscroll,
2126 pos_tab_offset (w, xp.bufpos), w);
2128 if (pp.bufpos < PT || pp.vpos == height)
2129 return 0;
2130 cursor_vpos = pp.vpos + top;
2131 cursor_hpos = XFASTINT (w->left) + minmax (0, pp.hpos, width);
2134 if (stop_vpos - scroll_amount >= height
2135 || ep.bufpos == xp.bufpos)
2137 if (scroll_amount < 0)
2138 stop_vpos -= scroll_amount;
2139 scroll_amount = 0;
2140 /* In this path, we have altered window_end_vpos
2141 and not left it negative.
2142 We must make sure that, in case display is preempted
2143 before the frame changes to reflect what we do here,
2144 further updates will not come to try_window_id
2145 and assume the frame and window_end_vpos match. */
2146 blank_end_of_window = 1;
2148 else if (!scroll_amount)
2150 /* Even if we don't need to scroll, we must adjust the
2151 charstarts of subsequent lines (that we won't redisplay)
2152 according to the amount of text inserted or deleted. */
2153 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2154 int adjust = ep.bufpos - oldpos;
2155 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
2157 else if (bp.bufpos == Z - end_unchanged)
2159 /* If reprinting everything is nearly as fast as scrolling,
2160 don't bother scrolling. Can happen if lines are short. */
2161 if (scroll_cost (f, bp.vpos + top - scroll_amount,
2162 top + height - max (0, scroll_amount),
2163 scroll_amount)
2164 > xp.bufpos - bp.bufpos - 20)
2165 /* Return "try normal display with same window-start."
2166 Too bad we can't prevent further scroll-thinking. */
2167 return -2;
2168 /* If pure deletion, scroll up as many lines as possible.
2169 In common case of killing a line, this can save the
2170 following line from being overwritten by scrolling
2171 and therefore having to be redrawn. */
2172 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
2173 top + height - max (0, scroll_amount),
2174 scroll_amount, bp.bufpos);
2175 if (!tem)
2176 stop_vpos = height;
2177 else
2179 /* scroll_frame_lines did not properly adjust subsequent
2180 lines' charstarts in the case where the text of the
2181 screen line at bp.vpos has changed.
2182 (This can happen in a deletion that ends in mid-line.)
2183 To adjust properly, we need to make things consistent
2184 at the position ep.
2185 So do a second adjust to make that happen.
2186 Note that stop_vpos >= ep.vpos, so it is sufficient
2187 to update the charstarts for lines at ep.vpos and below. */
2188 int oldstart
2189 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2190 adjust_window_charstarts (w, ep.vpos + top - 1,
2191 ep.bufpos - oldstart);
2194 else if (scroll_amount)
2196 /* If reprinting everything is nearly as fast as scrolling,
2197 don't bother scrolling. Can happen if lines are short. */
2198 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2199 overestimate of cost of reprinting, since xp.bufpos
2200 would end up below the bottom of the window. */
2201 if (scroll_cost (f, ep.vpos + top - scroll_amount,
2202 top + height - max (0, scroll_amount),
2203 scroll_amount)
2204 > xp.bufpos - ep.bufpos - 20)
2205 /* Return "try normal display with same window-start."
2206 Too bad we can't prevent further scroll-thinking. */
2207 return -2;
2208 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
2209 top + height - max (0, scroll_amount),
2210 scroll_amount, ep.bufpos);
2211 if (!tem) stop_vpos = height;
2215 /* In any case, do not display past bottom of window */
2216 if (stop_vpos >= height)
2218 stop_vpos = height;
2219 scroll_amount = 0;
2222 /* Handle case where pos is before w->start --
2223 can happen if part of line had been clipped and is not clipped now */
2224 if (vpos == 0 && pos < marker_position (w->start))
2225 Fset_marker (w->start, make_number (pos), Qnil);
2227 /* Redisplay the lines where the text was changed */
2228 last_text_vpos = vpos;
2229 tab_offset = pos_tab_offset (w, pos);
2230 /* If we are starting display in mid-character, correct tab_offset
2231 to account for passing the line that that character really starts in. */
2232 if (val.hpos < lmargin)
2233 tab_offset += width;
2234 old_tick = MODIFF;
2235 while (vpos < stop_vpos)
2237 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2238 /* If display_text_line ran a hook and changed some text,
2239 redisplay all the way to bottom of buffer
2240 So that we show the changes. */
2241 if (old_tick != MODIFF)
2242 stop_vpos = height;
2243 tab_offset += width;
2244 if (val.vpos) tab_offset = 0;
2245 if (pos != val.bufpos)
2246 last_text_vpos
2247 /* Next line, unless prev line ended in end of buffer with no cr */
2248 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
2249 pos = val.bufpos;
2252 /* There are two cases:
2253 1) we have displayed down to the bottom of the window
2254 2) we have scrolled lines below stop_vpos by scroll_amount */
2256 if (vpos == height)
2258 /* If last line is continued in middle of character,
2259 include the split character in the text considered on the frame */
2260 if (val.hpos < lmargin)
2261 val.bufpos++;
2262 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2263 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2266 /* If scrolling made blank lines at window bottom,
2267 redisplay to fill those lines */
2268 if (scroll_amount < 0)
2270 /* Don't consider these lines for general-purpose scrolling.
2271 That will save time in the scrolling computation. */
2272 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2273 vpos = xp.vpos;
2274 pos = xp.bufpos;
2275 val.hpos = lmargin;
2276 if (pos == ZV)
2277 vpos = height + scroll_amount;
2278 else if (xp.contin && xp.hpos != lmargin)
2280 val.hpos = xp.prevhpos - width + lmargin;
2281 pos--;
2284 blank_end_of_window = 1;
2285 tab_offset = pos_tab_offset (w, pos);
2286 /* If we are starting display in mid-character, correct tab_offset
2287 to account for passing the line that that character starts in. */
2288 if (val.hpos < lmargin)
2289 tab_offset += width;
2291 while (vpos < height)
2293 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2294 tab_offset += width;
2295 if (val.vpos) tab_offset = 0;
2296 pos = val.bufpos;
2299 /* Here is a case where display_text_line sets cursor_vpos wrong.
2300 Make it be fixed up, below. */
2301 if (xp.bufpos == ZV
2302 && xp.bufpos == PT)
2303 cursor_vpos = -1;
2306 /* If bottom just moved off end of frame, change mode line percentage. */
2307 if (XFASTINT (w->window_end_pos) == 0
2308 && Z != val.bufpos)
2309 w->update_mode_line = Qt;
2311 /* Attempt to adjust end-of-text positions to new bottom line */
2312 if (scroll_amount)
2314 delta = height - xp.vpos;
2315 if (delta < 0
2316 || (delta > 0 && xp.bufpos <= ZV)
2317 || (delta == 0 && xp.hpos))
2319 val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w);
2320 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2321 XSETFASTINT (w->window_end_vpos,
2322 XFASTINT (w->window_end_vpos) + val.vpos);
2326 w->window_end_valid = Qnil;
2328 /* If point was not in a line that was displayed, find it */
2329 if (cursor_vpos < 0)
2331 findpoint:
2332 val = *compute_motion (start, 0, lmargin, 0, PT, 10000, 10000,
2333 width, hscroll, pos_tab_offset (w, start), w);
2334 /* Admit failure if point is off frame now */
2335 if (val.vpos >= height)
2337 for (vpos = 0; vpos < height; vpos++)
2338 cancel_line (vpos + top, f);
2339 return 0;
2341 cursor_vpos = val.vpos + top;
2342 cursor_hpos = XFASTINT (w->left) + minmax (0, val.hpos, width);
2345 FRAME_CURSOR_X (f) = cursor_hpos;
2346 FRAME_CURSOR_Y (f) = cursor_vpos;
2348 if (debug_end_pos)
2350 val = *compute_motion (start, 0, lmargin, 0, ZV,
2351 height, - (1 << (BITS_PER_SHORT - 1)),
2352 width, hscroll, pos_tab_offset (w, start), w);
2353 if (val.vpos != XFASTINT (w->window_end_vpos))
2354 abort ();
2355 if (XFASTINT (w->window_end_pos)
2356 != Z - val.bufpos)
2357 abort ();
2360 return 1;
2363 /* Mark a section of BUF as modified, but only for the sake of redisplay.
2364 This is useful for recording changes to overlays.
2366 We increment the buffer's modification timestamp and set the
2367 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
2368 as if the region of text between START and END had been modified;
2369 the redisplay code will check this against the windows' timestamps,
2370 and redraw the appropriate area of the buffer.
2372 However, if the buffer is unmodified, we bump the last-save
2373 timestamp as well, so that incrementing the timestamp doesn't fool
2374 Emacs into thinking that the buffer's text has been modified.
2376 Tweaking the timestamps shouldn't hurt the first-modification
2377 timestamps recorded in the undo records; those values aren't
2378 written until just before a real text modification is made, so they
2379 will never catch the timestamp value just before this function gets
2380 called. */
2382 void
2383 redisplay_region (buf, start, end)
2384 struct buffer *buf;
2385 int start, end;
2387 if (start == end)
2388 return;
2390 if (start > end)
2392 int temp = start;
2393 start = end; end = temp;
2396 /* If this is a buffer not in the selected window,
2397 we must do other windows. */
2398 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2399 windows_or_buffers_changed = 1;
2400 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2401 else if (buf != current_buffer)
2402 windows_or_buffers_changed = 1;
2403 /* If multiple windows show this buffer, we must do other windows. */
2404 else if (buffer_shared > 1)
2405 windows_or_buffers_changed = 1;
2406 else
2408 if (unchanged_modified == MODIFF)
2410 beg_unchanged = start - BEG;
2411 end_unchanged = Z - end;
2413 else
2415 if (Z - end < end_unchanged)
2416 end_unchanged = Z - end;
2417 if (start - BEG < beg_unchanged)
2418 beg_unchanged = start - BEG;
2422 /* Increment the buffer's time stamp, but also increment the save
2423 and autosave timestamps, so as not to screw up that timekeeping. */
2424 if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf))
2425 BUF_SAVE_MODIFF (buf)++;
2426 if (BUF_MODIFF (buf) == buf->auto_save_modified)
2427 buf->auto_save_modified++;
2429 BUF_MODIFF (buf) ++;
2433 /* Copy LEN glyphs starting address FROM to the rope TO.
2434 But don't actually copy the parts that would come in before S.
2435 Value is TO, advanced past the copied data.
2436 F is the frame we are displaying in. */
2438 static GLYPH *
2439 copy_part_of_rope (f, to, s, from, len, face)
2440 FRAME_PTR f;
2441 register GLYPH *to; /* Copy to here. */
2442 register GLYPH *s; /* Starting point. */
2443 Lisp_Object *from; /* Data to copy. */
2444 int len;
2445 int face; /* Face to apply to glyphs which don't specify one. */
2447 int n = len;
2448 register Lisp_Object *fp = from;
2449 /* These cache the results of the last call to compute_glyph_face. */
2450 int last_code = -1;
2451 int last_merged = 0;
2453 #ifdef HAVE_FACES
2454 if (! FRAME_TERMCAP_P (f))
2455 while (n--)
2457 int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2458 int facecode;
2460 if (FAST_GLYPH_FACE (glyph) == 0)
2461 /* If GLYPH has no face code, use FACE. */
2462 facecode = face;
2463 else if (FAST_GLYPH_FACE (glyph) == last_code)
2464 /* If it's same as previous glyph, use same result. */
2465 facecode = last_merged;
2466 else
2468 /* Merge this glyph's face and remember the result. */
2469 last_code = FAST_GLYPH_FACE (glyph);
2470 last_merged = facecode = compute_glyph_face (f, last_code, face);
2473 if (to >= s)
2474 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
2475 ++to;
2476 ++fp;
2478 else
2479 #endif
2480 while (n--)
2482 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2483 ++to;
2484 ++fp;
2486 return to;
2489 /* Correct a glyph by replacing its specified user-level face code
2490 with a displayable computed face code. */
2492 static GLYPH
2493 fix_glyph (f, glyph, cface)
2494 FRAME_PTR f;
2495 GLYPH glyph;
2496 int cface;
2498 #ifdef HAVE_FACES
2499 if (! FRAME_TERMCAP_P (f))
2501 if (FAST_GLYPH_FACE (glyph) != 0)
2502 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2503 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2505 #endif
2506 return glyph;
2509 /* Display one line of window W, starting at position START in W's buffer.
2511 Display starting at horizontal position HPOS, expressed relative to
2512 W's left edge. In situations where the text at START shouldn't
2513 start at the left margin (i.e. when the window is hscrolled, or
2514 we're continuing a line which left off in the midst of a
2515 multi-column character), HPOS should be negative; we throw away
2516 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2517 account.
2519 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2521 Display on position VPOS on the frame. It is origin 0, relative to
2522 the top of the frame, not W.
2524 Returns a STRUCT POSITION giving character to start next line with
2525 and where to display it, including a zero or negative hpos.
2526 The vpos field is not really a vpos; it is 1 unless the line is continued */
2528 struct position val_display_text_line;
2530 static struct position *
2531 display_text_line (w, start, vpos, hpos, taboffset)
2532 struct window *w;
2533 int start;
2534 int vpos;
2535 int hpos;
2536 int taboffset;
2538 register int pos = start;
2539 register int c;
2540 register GLYPH *p1;
2541 register int pause;
2542 register unsigned char *p;
2543 GLYPH *endp;
2544 register GLYPH *leftmargin;
2545 register GLYPH *p1prev;
2546 register GLYPH *p1start;
2547 int prevpos;
2548 int *charstart;
2549 FRAME_PTR f = XFRAME (w->frame);
2550 int tab_width = XINT (current_buffer->tab_width);
2551 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2552 int width = window_internal_width (w) - 1;
2553 struct position val;
2554 int lastpos;
2555 int invis;
2556 int last_invis_skip = 0;
2557 Lisp_Object last_invis_prop;
2558 int hscroll = XINT (w->hscroll);
2559 int truncate = (hscroll
2560 || (truncate_partial_width_windows
2561 && XFASTINT (w->width) < FRAME_WIDTH (f))
2562 || !NILP (current_buffer->truncate_lines));
2564 /* 1 if we should highlight the region. */
2565 int highlight_region
2566 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
2567 int region_beg, region_end;
2569 int selective = (INTEGERP (current_buffer->selective_display)
2570 ? XINT (current_buffer->selective_display)
2571 : !NILP (current_buffer->selective_display) ? -1 : 0);
2572 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2573 register struct Lisp_Char_Table *dp = window_display_table (w);
2575 Lisp_Object default_invis_vector[3];
2576 /* Number of characters of ellipsis to display after an invisible line
2577 if it calls for an ellipsis.
2578 Note that this value can be nonzero regardless of whether
2579 selective display is enabled--you must check that separately. */
2580 int selective_rlen
2581 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2582 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2583 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
2584 /* This is the sequence of Lisp objects to display
2585 when there are invisible lines. */
2586 Lisp_Object *invis_vector_contents
2587 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2588 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2589 : default_invis_vector);
2591 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2592 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2593 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2594 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2596 /* The next buffer location at which the face should change, due
2597 to overlays or text property changes. */
2598 int next_face_change;
2600 /* The next location where the `invisible' property changes, or an
2601 overlay starts or ends. */
2602 int next_boundary;
2604 /* The face we're currently using. */
2605 int current_face = 0;
2606 int i;
2608 XSETFASTINT (default_invis_vector[2], '.');
2609 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2611 hpos += XFASTINT (w->left);
2612 get_display_line (f, vpos, XFASTINT (w->left));
2613 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2615 /* Show where to highlight the region. */
2616 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2617 /* Maybe highlight only in selected window. */
2618 && (highlight_nonselected_windows
2619 || w == XWINDOW (selected_window)))
2621 region_beg = marker_position (current_buffer->mark);
2622 if (PT < region_beg)
2624 region_end = region_beg;
2625 region_beg = PT;
2627 else
2628 region_end = PT;
2629 w->region_showing = Qt;
2631 else
2632 region_beg = region_end = -1;
2634 if (MINI_WINDOW_P (w)
2635 && start == BEG
2636 && vpos == XFASTINT (w->top))
2638 if (! NILP (minibuf_prompt))
2640 minibuf_prompt_width
2641 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2642 XSTRING (minibuf_prompt)->size, hpos,
2643 /* Display a space if we truncate. */
2644 ' ',
2645 1, -1,
2646 /* Truncate the prompt a little before the
2647 margin, so user input can at least start
2648 on the first line. */
2649 w->width > 10 ? w->width - 4 : -1)
2650 - hpos);
2651 hpos += minibuf_prompt_width;
2652 taboffset -= minibuf_prompt_width;
2654 else
2655 minibuf_prompt_width = 0;
2658 /* If we're hscrolled at all, use compute_motion to skip over any
2659 text off the left edge of the window. compute_motion may know
2660 tricks to do this faster than we can. */
2661 if (hpos < 0)
2663 struct position *left_edge
2664 = compute_motion (pos, vpos, hpos, 0,
2665 ZV, vpos, 0,
2666 width, hscroll, taboffset, w);
2668 /* Retrieve the buffer position and column provided by
2669 compute_motion. We can't assume that the column will be
2670 zero, because you may have multi-column characters crossing
2671 the left margin.
2673 compute_motion may have moved us past the screen position we
2674 requested, if we hit a multi-column character, or the end of
2675 the line. If so, back up. */
2676 if (left_edge->vpos > vpos
2677 || left_edge->hpos > 0)
2679 pos = left_edge->bufpos - 1;
2680 hpos = left_edge->prevhpos;
2682 else
2684 pos = left_edge->bufpos;
2685 hpos = left_edge->hpos;
2689 desired_glyphs->bufp[vpos] = start;
2690 p1 = desired_glyphs->glyphs[vpos] + hpos;
2691 p1start = p1;
2692 charstart = desired_glyphs->charstarts[vpos] + hpos;
2693 /* In case we don't ever write anything into it... */
2694 desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1;
2695 leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2696 endp = leftmargin + width;
2698 /* Arrange the overlays nicely for our purposes. Usually, we call
2699 display_text_line on only one line at a time, in which case this
2700 can't really hurt too much, or we call it on lines which appear
2701 one after another in the buffer, in which case all calls to
2702 recenter_overlay_lists but the first will be pretty cheap. */
2703 recenter_overlay_lists (current_buffer, pos);
2705 /* Loop generating characters.
2706 Stop at end of buffer, before newline,
2707 if reach or pass continuation column,
2708 or at face change. */
2709 pause = pos;
2710 next_face_change = pos;
2711 next_boundary = pos;
2712 p1prev = p1;
2713 prevpos = pos;
2714 while (1)
2716 if (pos >= pause)
2718 int e_t_h;
2720 while (pos == next_boundary)
2722 Lisp_Object position, limit, prop, ww;
2724 /* Display the overlay strings here, unless we're at ZV
2725 and have already displayed the appropriate strings
2726 on an earlier line. */
2727 if (pos < ZV || !zv_strings_seen++)
2729 int ovlen;
2730 char *ovstr;
2731 ovlen = overlay_strings (pos, w, &ovstr);
2732 for (; ovlen; ovlen--, ovstr++)
2734 if (p1 >= leftmargin && p1 < endp)
2735 *p1 = MAKE_GLYPH (f, *ovstr, current_face);
2736 p1++;
2740 /* Did we reach point? Record the cursor location. */
2741 if (pos == PT && cursor_vpos < 0)
2743 cursor_vpos = vpos;
2744 cursor_hpos = p1 - leftmargin;
2747 if (pos >= ZV)
2748 break;
2750 XSETFASTINT (position, pos);
2751 limit = Fnext_overlay_change (position);
2752 #ifdef USE_TEXT_PROPERTIES
2753 /* This is just an estimate to give reasonable
2754 performance; nothing should go wrong if it is too small. */
2755 if (XFASTINT (limit) > pos + 50)
2756 XSETFASTINT (limit, pos + 50);
2757 limit = Fnext_single_property_change (position, Qinvisible,
2758 Fcurrent_buffer (), limit);
2759 #endif
2760 next_boundary = XFASTINT (limit);
2761 /* if the `invisible' property is set, we can skip to
2762 the next property change. */
2763 XSETWINDOW (ww, w);
2764 prop = Fget_char_property (position, Qinvisible, ww);
2765 if (TEXT_PROP_MEANS_INVISIBLE (prop))
2767 if (pos < PT && next_boundary >= PT)
2769 cursor_vpos = vpos;
2770 cursor_hpos = p1 - leftmargin;
2772 pos = next_boundary;
2773 last_invis_skip = pos;
2774 last_invis_prop = prop;
2778 /* Did we reach point? Record the cursor location. */
2779 if (pos == PT && cursor_vpos < 0)
2781 cursor_vpos = vpos;
2782 cursor_hpos = p1 - leftmargin;
2785 /* Did we hit the end of the visible region of the buffer?
2786 Stop here. */
2787 if (pos >= ZV)
2789 /* Update charstarts for the end of this line. */
2790 /* Do nothing if off the left edge or at the right edge. */
2791 if (p1 >= leftmargin && p1 + 1 != endp)
2793 int *p2x = &charstart[(p1 < leftmargin
2794 ? leftmargin : p1)
2795 - p1start];
2796 *p2x++ = pos;
2798 break;
2801 /* Figure out where (if at all) the
2802 redisplay_end_trigger-hook should run. */
2803 if (MARKERP (w->redisplay_end_trigger)
2804 && XMARKER (w->redisplay_end_trigger)->buffer != 0)
2805 e_t_h = marker_position (w->redisplay_end_trigger);
2806 else if (INTEGERP (w->redisplay_end_trigger))
2807 e_t_h = XINT (w->redisplay_end_trigger);
2808 else
2809 e_t_h = ZV;
2811 /* If we've gone past the place to run a hook,
2812 run the hook. */
2813 if (pos >= e_t_h && e_t_h != ZV)
2815 Lisp_Object args[3];
2817 args[0] = Qredisplay_end_trigger_functions;
2818 XSETWINDOW (args[1], w);
2819 XSETINT (args[2], e_t_h);
2821 /* Since we are *trying* to run these functions,
2822 don't try to run them again, even if they get an error. */
2823 w->redisplay_end_trigger = Qnil;
2824 Frun_hook_with_args (3, args);
2826 e_t_h = ZV;
2827 /* Notice if it changed the face of this character. */
2828 next_face_change = pos;
2831 #ifdef HAVE_FACES
2832 /* Did we hit a face change? Figure out what face we should
2833 use now. We also hit this the first time through the
2834 loop, to see what face we should start with. */
2835 if (pos >= next_face_change
2836 && (FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f)))
2837 current_face = compute_char_face (f, w, pos,
2838 region_beg, region_end,
2839 &next_face_change, pos + 50, 0);
2840 #endif
2842 /* Compute the next place we need to stop
2843 and do something special; set PAUSE. */
2845 pause = ZV;
2847 if (pos < next_boundary && next_boundary < pause)
2848 pause = next_boundary;
2849 if (pos < next_face_change && next_face_change < pause)
2850 pause = next_face_change;
2852 if (e_t_h < pause)
2853 pause = e_t_h;
2855 /* Wouldn't you hate to read the next line to someone over
2856 the phone? */
2857 if (pos < PT && PT < pause)
2858 pause = PT;
2859 if (pos < GPT && GPT < pause)
2860 pause = GPT;
2862 p = &FETCH_CHAR (pos);
2865 if (p1 >= endp)
2866 break;
2868 p1prev = p1;
2870 c = *p++;
2871 /* Let a display table override all standard display methods. */
2872 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
2874 p1 = copy_part_of_rope (f, p1, leftmargin,
2875 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2876 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2877 current_face);
2879 else if (c >= 040 && c < 0177)
2881 if (p1 >= leftmargin)
2882 *p1 = MAKE_GLYPH (f, c, current_face);
2883 p1++;
2885 else if (c == '\n')
2887 invis = 0;
2888 if (last_invis_skip == pos
2889 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
2890 invis = 1;
2891 while (pos + 1 < ZV
2892 && selective > 0
2893 && indented_beyond_p (pos + 1, selective))
2895 invis = 1;
2896 pos = find_next_newline (pos + 1, 1);
2897 if (FETCH_CHAR (pos - 1) == '\n')
2898 pos--;
2900 if (invis && selective_rlen > 0 && p1 >= leftmargin)
2902 p1 += selective_rlen;
2903 if (p1 - leftmargin > width)
2904 p1 = endp;
2905 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2906 (p1 - p1prev), current_face);
2908 #ifdef HAVE_FACES
2909 /* Draw the face of the newline character as extending all the
2910 way to the end of the frame line. */
2911 if (current_face)
2913 if (p1 < leftmargin)
2914 p1 = leftmargin;
2915 while (p1 < endp)
2916 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2918 #endif
2920 /* Update charstarts for the newline that ended this line. */
2921 /* Do nothing here for a char that's entirely off the left edge
2922 or if it starts at the right edge. */
2923 if (p1 >= leftmargin && p1prev != endp)
2925 /* Store the newline's position into charstarts
2926 for the column where the newline starts.
2927 Store -1 for the rest of the glyphs it occupies. */
2928 int *p2x = &charstart[(p1prev < leftmargin
2929 ? leftmargin : p1prev)
2930 - p1start];
2931 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2933 *p2x++ = pos;
2934 while (p2x < p2)
2935 *p2x++ = -1;
2938 break;
2940 else if (c == '\t')
2944 if (p1 >= leftmargin && p1 < endp)
2945 *p1 = MAKE_GLYPH (f, ' ', current_face);
2946 p1++;
2948 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
2949 % tab_width);
2951 else if (c == Ctl ('M') && selective == -1)
2953 pos = find_next_newline (pos, 1);
2954 if (FETCH_CHAR (pos - 1) == '\n')
2955 pos--;
2956 if (selective_rlen > 0)
2958 p1 += selective_rlen;
2959 if (p1 - leftmargin > width)
2960 p1 = endp;
2961 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2962 (p1 - p1prev), current_face);
2964 #ifdef HAVE_FACES
2965 /* Draw the face of the newline character as extending all the
2966 way to the end of the frame line. */
2967 if (current_face)
2969 if (p1 < leftmargin)
2970 p1 = leftmargin;
2971 while (p1 < endp)
2972 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2974 #endif
2976 /* Update charstarts for the ^M that ended this line. */
2977 /* Do nothing here for a char that's entirely off the left edge
2978 or if it starts at the right edge. */
2979 if (p1 >= leftmargin && p1prev != endp)
2981 /* Store the newline's position into charstarts
2982 for the column where the newline starts.
2983 Store -1 for the rest of the glyphs it occupies. */
2984 int *p2x = &charstart[(p1prev < leftmargin
2985 ? leftmargin : p1prev)
2986 - p1start];
2987 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2989 *p2x++ = pos;
2990 while (p2x < p2)
2991 *p2x++ = -1;
2993 break;
2995 else if (c < 0200 && ctl_arrow)
2997 if (p1 >= leftmargin)
2998 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
2999 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3000 current_face);
3001 p1++;
3002 if (p1 >= leftmargin && p1 < endp)
3003 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
3004 p1++;
3006 else
3008 if (p1 >= leftmargin)
3009 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
3010 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3011 current_face);
3012 p1++;
3013 if (p1 >= leftmargin && p1 < endp)
3014 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
3015 p1++;
3016 if (p1 >= leftmargin && p1 < endp)
3017 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
3018 p1++;
3019 if (p1 >= leftmargin && p1 < endp)
3020 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
3021 p1++;
3024 prevpos = pos;
3025 pos++;
3027 /* Update charstarts for the character just output. */
3029 /* Do nothing here for a char that's entirely off the left edge. */
3030 if (p1 >= leftmargin)
3032 /* Store the char's position into charstarts
3033 for the first glyph occupied by this char.
3034 Store -1 for the rest of the glyphs it occupies. */
3035 if (p1 != p1prev)
3037 int *p2x = &charstart[(p1prev < leftmargin
3038 ? leftmargin : p1prev)
3039 - p1start];
3040 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3042 if (p2x < p2)
3043 *p2x++ = prevpos;
3044 while (p2x < p2)
3045 *p2x++ = -1;
3050 val.hpos = - XINT (w->hscroll);
3051 if (val.hpos)
3052 val.hpos++;
3054 val.vpos = 1;
3056 lastpos = pos;
3058 /* Store 0 in this charstart line for the positions where
3059 there is no character. But do leave what was recorded
3060 for the character that ended the line. */
3061 /* Add 1 in the endtest to compensate for the fact that ENDP was
3062 made from WIDTH, which is 1 less than the window's actual
3063 internal width. */
3064 i = p1 - p1start + 1;
3065 if (p1 < leftmargin)
3066 i += leftmargin - p1;
3067 for (; i < endp - p1start + 1; i++)
3068 charstart[i] = 0;
3070 /* Handle continuation in middle of a character */
3071 /* by backing up over it */
3072 if (p1 > endp)
3074 /* Don't back up if we never actually displayed any text.
3075 This occurs when the minibuffer prompt takes up the whole line. */
3076 if (p1prev)
3078 /* Start the next line with that same character */
3079 pos--;
3080 /* but at negative hpos, to skip the columns output on this line. */
3081 val.hpos += p1prev - endp;
3084 /* Keep in this line everything up to the continuation column. */
3085 p1 = endp;
3088 /* Finish deciding which character to start the next line on,
3089 and what hpos to start it at.
3090 Also set `lastpos' to the last position which counts as "on this line"
3091 for cursor-positioning. */
3093 if (pos < ZV)
3095 if (FETCH_CHAR (pos) == '\n')
3097 /* If stopped due to a newline, start next line after it */
3098 pos++;
3099 /* Check again for hidden lines, in case the newline occurred exactly
3100 at the right margin. */
3101 while (pos < ZV && selective > 0
3102 && indented_beyond_p (pos, selective))
3103 pos = find_next_newline (pos, 1);
3105 else
3106 /* Stopped due to right margin of window */
3108 if (truncate)
3110 *p1++ = fix_glyph (f, truncator, 0);
3111 /* Truncating => start next line after next newline,
3112 and point is on this line if it is before the newline,
3113 and skip none of first char of next line */
3115 pos = find_next_newline (pos, 1);
3116 while (pos < ZV && selective > 0
3117 && indented_beyond_p (pos, selective));
3118 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
3120 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
3122 else
3124 *p1++ = fix_glyph (f, continuer, 0);
3125 val.vpos = 0;
3126 lastpos--;
3131 /* If point is at eol or in invisible text at eol,
3132 record its frame location now. */
3134 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
3136 cursor_vpos = vpos;
3137 cursor_hpos = p1 - leftmargin;
3140 if (cursor_vpos == vpos)
3142 if (cursor_hpos < 0) cursor_hpos = 0;
3143 if (cursor_hpos > width) cursor_hpos = width;
3144 cursor_hpos += XFASTINT (w->left);
3145 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
3147 if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f)
3148 && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window)))
3150 FRAME_CURSOR_Y (f) = cursor_vpos;
3151 FRAME_CURSOR_X (f) = cursor_hpos;
3154 if (w == XWINDOW (selected_window))
3156 /* Line is not continued and did not start
3157 in middle of character */
3158 if ((hpos - XFASTINT (w->left)
3159 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
3160 && val.vpos)
3162 this_line_bufpos = start;
3163 this_line_buffer = current_buffer;
3164 this_line_vpos = cursor_vpos;
3165 this_line_start_hpos = hpos;
3166 this_line_endpos = Z - lastpos;
3168 else
3169 this_line_bufpos = 0;
3174 /* If hscroll and line not empty, insert truncation-at-left marker */
3175 if (hscroll && lastpos != start)
3177 *leftmargin = fix_glyph (f, truncator, 0);
3178 if (p1 <= leftmargin)
3179 p1 = leftmargin + 1;
3182 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
3184 endp++;
3185 if (p1 < leftmargin) p1 = leftmargin;
3186 while (p1 < endp) *p1++ = SPACEGLYPH;
3188 /* Don't draw vertical bars if we're using scroll bars. They're
3189 covered up by the scroll bars, and it's distracting to see
3190 them when the scroll bar windows are flickering around to be
3191 reconfigured. */
3192 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3194 int i;
3195 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3196 *p1++ = SPACEGLYPH;
3198 else
3199 *p1++ = (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
3200 ? DISP_BORDER_GLYPH (dp)
3201 : '|');
3203 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
3204 p1 - desired_glyphs->glyphs[vpos]);
3205 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3207 /* If the start of this line is the overlay arrow-position,
3208 then put the arrow string into the display-line. */
3210 if (MARKERP (Voverlay_arrow_position)
3211 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
3212 && start == marker_position (Voverlay_arrow_position)
3213 && STRINGP (Voverlay_arrow_string)
3214 && ! overlay_arrow_seen)
3216 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
3217 int i;
3218 int len = XSTRING (Voverlay_arrow_string)->size;
3219 int arrow_end;
3221 if (len > width)
3222 len = width;
3223 #ifdef HAVE_FACES
3224 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
3226 /* If the arrow string has text props, obey them when displaying. */
3227 for (i = 0; i < len; i++)
3229 int c = p[i];
3230 Lisp_Object face, ilisp;
3231 int newface;
3233 XSETFASTINT (ilisp, i);
3234 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
3235 newface = compute_glyph_face_1 (f, face, 0);
3236 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
3239 else
3240 #endif /* HAVE_FACES */
3242 for (i = 0; i < len; i++)
3243 leftmargin[i] = p[i];
3246 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3247 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
3248 if (desired_glyphs->used[vpos] < arrow_end)
3249 desired_glyphs->used[vpos] = arrow_end;
3251 overlay_arrow_seen = 1;
3254 val.bufpos = pos;
3255 val_display_text_line = val;
3256 return &val_display_text_line;
3259 /* Redisplay the menu bar in the frame for window W. */
3261 static void
3262 display_menu_bar (w)
3263 struct window *w;
3265 Lisp_Object items, tail;
3266 register int vpos = 0;
3267 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3268 int maxendcol = FRAME_WIDTH (f);
3269 int hpos = 0;
3270 int i;
3272 #ifdef HAVE_NTGUI
3273 if (!NILP (Vwindow_system))
3274 return;
3275 #endif
3277 #ifdef USE_X_TOOLKIT
3278 if (FRAME_X_P (f))
3279 return;
3280 #endif /* USE_X_TOOLKIT */
3282 get_display_line (f, vpos, 0);
3284 items = FRAME_MENU_BAR_ITEMS (f);
3285 for (i = 0; i < XVECTOR (items)->size; i += 4)
3287 Lisp_Object pos, string;
3288 string = XVECTOR (items)->contents[i + 1];
3289 if (NILP (string))
3290 break;
3292 XSETFASTINT (XVECTOR (items)->contents[i + 3], hpos);
3294 if (hpos < maxendcol)
3295 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
3296 XSTRING (string)->data,
3297 XSTRING (string)->size,
3298 hpos, 0, 0, hpos, maxendcol);
3299 /* Put a space between items. */
3300 if (hpos < maxendcol)
3302 int hpos1 = hpos + 1;
3303 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
3304 min (hpos1, maxendcol), maxendcol);
3308 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3309 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3311 /* Fill out the line with spaces. */
3312 if (maxendcol > hpos)
3313 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
3315 /* Clear the rest of the lines allocated to the menu bar. */
3316 vpos++;
3317 while (vpos < FRAME_MENU_BAR_LINES (f))
3318 get_display_line (f, vpos++, 0);
3321 /* Display the mode line for window w */
3323 static void
3324 display_mode_line (w)
3325 struct window *w;
3327 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
3328 register int left = XFASTINT (w->left);
3329 register int right = XFASTINT (w->width) + left;
3330 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3332 line_number_displayed = 0;
3333 w->column_number_displayed = Qnil;
3335 get_display_line (f, vpos, left);
3337 /* Temporarily make frame F's kboard the current kboard
3338 so that kboard-local variables in the mode_line_format
3339 will get the right values. */
3340 push_frame_kboard (f);
3342 display_mode_element (w, vpos, left, 0, right, right,
3343 current_buffer->mode_line_format);
3345 pop_frame_kboard ();
3347 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3349 /* Make the mode line inverse video if the entire line
3350 is made of mode lines.
3351 I.e. if this window is full width,
3352 or if it is the child of a full width window
3353 (which implies that that window is split side-by-side
3354 and the rest of this line is mode lines of the sibling windows). */
3355 if (XFASTINT (w->width) == FRAME_WIDTH (f)
3356 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
3357 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3358 #ifdef HAVE_FACES
3359 else if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video)
3361 /* For a partial width window, explicitly set face of each glyph. */
3362 int i;
3363 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3364 for (i = left; i < right; ++i)
3365 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
3367 #endif
3370 /* Contribute ELT to the mode line for window W.
3371 How it translates into text depends on its data type.
3373 VPOS is the position of the mode line being displayed.
3375 HPOS is the position (absolute on frame) where this element's text
3376 should start. The output is truncated automatically at the right
3377 edge of window W.
3379 DEPTH is the depth in recursion. It is used to prevent
3380 infinite recursion here.
3382 MINENDCOL is the hpos before which the element may not end.
3383 The element is padded at the right with spaces if nec
3384 to reach this column.
3386 MAXENDCOL is the hpos past which this element may not extend.
3387 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3388 (This is necessary to make nested padding and truncation work.)
3390 Returns the hpos of the end of the text generated by ELT.
3391 The next element will receive that value as its HPOS arg,
3392 so as to concatenate the elements. */
3394 static int
3395 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3396 struct window *w;
3397 register int vpos, hpos;
3398 int depth;
3399 int minendcol;
3400 register int maxendcol;
3401 register Lisp_Object elt;
3403 tail_recurse:
3404 if (depth > 10)
3405 goto invalid;
3407 depth++;
3409 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3411 case Lisp_String:
3413 /* A string: output it and check for %-constructs within it. */
3414 register unsigned char c;
3415 register unsigned char *this = XSTRING (elt)->data;
3417 while (hpos < maxendcol && *this)
3419 unsigned char *last = this;
3420 while ((c = *this++) != '\0' && c != '%')
3422 if (this - 1 != last)
3424 register int lim = --this - last + hpos;
3425 if (frame_title_ptr)
3426 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3427 else
3428 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3429 hpos, min (lim, maxendcol));
3431 else /* c == '%' */
3433 register int minendcol;
3434 register int spec_width = 0;
3436 /* We can't allow -ve args due to the "%-" construct */
3437 /* Argument specifies minwidth but not maxwidth
3438 (maxwidth can be specified by
3439 (<negative-number> . <stuff>) mode-line elements) */
3441 while ((c = *this++) >= '0' && c <= '9')
3443 spec_width = spec_width * 10 + (c - '0');
3446 minendcol = hpos + spec_width;
3447 if (minendcol > maxendcol)
3449 spec_width = maxendcol - hpos;
3450 minendcol = maxendcol;
3453 if (c == 'M')
3454 hpos = display_mode_element (w, vpos, hpos, depth,
3455 spec_width, maxendcol,
3456 Vglobal_mode_string);
3457 else if (c != 0)
3459 char *spec = decode_mode_spec (w, c, spec_width,
3460 maxendcol - hpos);
3461 if (frame_title_ptr)
3462 hpos = store_frame_title (spec, minendcol, maxendcol);
3463 else
3464 hpos = display_string (w, vpos, spec, -1,
3465 hpos, 0, 1,
3466 minendcol, maxendcol);
3471 break;
3473 case Lisp_Symbol:
3474 /* A symbol: process the value of the symbol recursively
3475 as if it appeared here directly. Avoid error if symbol void.
3476 Special case: if value of symbol is a string, output the string
3477 literally. */
3479 register Lisp_Object tem;
3480 tem = Fboundp (elt);
3481 if (!NILP (tem))
3483 tem = Fsymbol_value (elt);
3484 /* If value is a string, output that string literally:
3485 don't check for % within it. */
3486 if (STRINGP (tem))
3488 if (frame_title_ptr)
3489 hpos = store_frame_title (XSTRING (tem)->data,
3490 minendcol, maxendcol);
3491 else
3492 hpos = display_string (w, vpos, XSTRING (tem)->data,
3493 XSTRING (tem)->size,
3494 hpos, 0, 1, minendcol, maxendcol);
3496 /* Give up right away for nil or t. */
3497 else if (!EQ (tem, elt))
3498 { elt = tem; goto tail_recurse; }
3501 break;
3503 case Lisp_Cons:
3505 register Lisp_Object car, tem;
3507 /* A cons cell: three distinct cases.
3508 If first element is a string or a cons, process all the elements
3509 and effectively concatenate them.
3510 If first element is a negative number, truncate displaying cdr to
3511 at most that many characters. If positive, pad (with spaces)
3512 to at least that many characters.
3513 If first element is a symbol, process the cadr or caddr recursively
3514 according to whether the symbol's value is non-nil or nil. */
3515 car = XCONS (elt)->car;
3516 if (SYMBOLP (car))
3518 tem = Fboundp (car);
3519 elt = XCONS (elt)->cdr;
3520 if (!CONSP (elt))
3521 goto invalid;
3522 /* elt is now the cdr, and we know it is a cons cell.
3523 Use its car if CAR has a non-nil value. */
3524 if (!NILP (tem))
3526 tem = Fsymbol_value (car);
3527 if (!NILP (tem))
3528 { elt = XCONS (elt)->car; goto tail_recurse; }
3530 /* Symbol's value is nil (or symbol is unbound)
3531 Get the cddr of the original list
3532 and if possible find the caddr and use that. */
3533 elt = XCONS (elt)->cdr;
3534 if (NILP (elt))
3535 break;
3536 else if (!CONSP (elt))
3537 goto invalid;
3538 elt = XCONS (elt)->car;
3539 goto tail_recurse;
3541 else if (INTEGERP (car))
3543 register int lim = XINT (car);
3544 elt = XCONS (elt)->cdr;
3545 if (lim < 0)
3546 /* Negative int means reduce maximum width.
3547 DO NOT change MINENDCOL here!
3548 (20 -10 . foo) should truncate foo to 10 col
3549 and then pad to 20. */
3550 maxendcol = min (maxendcol, hpos - lim);
3551 else if (lim > 0)
3553 /* Padding specified. Don't let it be more than
3554 current maximum. */
3555 lim += hpos;
3556 if (lim > maxendcol)
3557 lim = maxendcol;
3558 /* If that's more padding than already wanted, queue it.
3559 But don't reduce padding already specified even if
3560 that is beyond the current truncation point. */
3561 if (lim > minendcol)
3562 minendcol = lim;
3564 goto tail_recurse;
3566 else if (STRINGP (car) || CONSP (car))
3568 register int limit = 50;
3569 /* LIMIT is to protect against circular lists. */
3570 while (CONSP (elt) && --limit > 0
3571 && hpos < maxendcol)
3573 hpos = display_mode_element (w, vpos, hpos, depth,
3574 hpos, maxendcol,
3575 XCONS (elt)->car);
3576 elt = XCONS (elt)->cdr;
3580 break;
3582 default:
3583 invalid:
3584 if (frame_title_ptr)
3585 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3586 else
3587 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3588 minendcol, maxendcol);
3589 return hpos;
3592 if (minendcol > hpos)
3593 if (frame_title_ptr)
3594 hpos = store_frame_title ("", minendcol, maxendcol);
3595 else
3596 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
3597 return hpos;
3600 /* Write a null-terminated, right justified decimal representation of
3601 the positive integer D to BUF using a minimal field width WIDTH. */
3603 static void
3604 pint2str (buf, width, d)
3605 register char *buf;
3606 register int width;
3607 register int d;
3609 register char *p = buf;
3611 if (d <= 0)
3612 *p++ = '0';
3613 else
3614 while (d > 0)
3616 *p++ = d % 10 + '0';
3617 d /= 10;
3619 for (width -= (int) (p - buf); width > 0; --width) *p++ = ' ';
3620 *p-- = '\0';
3621 while (p > buf)
3623 d = *buf;
3624 *buf++ = *p;
3625 *p-- = d;
3629 /* Return a string for the output of a mode line %-spec for window W,
3630 generated by character C. SPEC_WIDTH is the field width when
3631 padding to the left (%c, %l). The value returned from this
3632 function will later be truncated to width MAXWIDTH. */
3634 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3636 static char *
3637 decode_mode_spec (w, c, spec_width, maxwidth)
3638 struct window *w;
3639 register char c;
3640 register int spec_width;
3641 register int maxwidth;
3643 Lisp_Object obj;
3644 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3645 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
3646 struct buffer *b = XBUFFER (w->buffer);
3648 obj = Qnil;
3649 if (maxwidth > FRAME_WIDTH (f))
3650 maxwidth = FRAME_WIDTH (f);
3652 switch (c)
3654 case '*':
3655 if (!NILP (b->read_only))
3656 return "%";
3657 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3658 return "*";
3659 return "-";
3661 case '+':
3662 /* This differs from %* only for a modified read-only buffer. */
3663 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3664 return "*";
3665 if (!NILP (b->read_only))
3666 return "%";
3667 return "-";
3669 case '&':
3670 /* This differs from %* in ignoring read-only-ness. */
3671 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3672 return "*";
3673 return "-";
3675 case '%':
3676 return "%";
3678 case '[':
3680 int i;
3681 char *p;
3683 if (command_loop_level > 5)
3684 return "[[[... ";
3685 p = decode_mode_spec_buf;
3686 for (i = 0; i < command_loop_level; i++)
3687 *p++ = '[';
3688 *p = 0;
3689 return decode_mode_spec_buf;
3692 case ']':
3694 int i;
3695 char *p;
3697 if (command_loop_level > 5)
3698 return " ...]]]";
3699 p = decode_mode_spec_buf;
3700 for (i = 0; i < command_loop_level; i++)
3701 *p++ = ']';
3702 *p = 0;
3703 return decode_mode_spec_buf;
3706 case '-':
3708 register char *p;
3709 register int i;
3711 if (maxwidth < sizeof (lots_of_dashes))
3712 return lots_of_dashes;
3713 else
3715 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3716 *p++ = '-';
3717 *p = '\0';
3719 return decode_mode_spec_buf;
3722 case 'b':
3723 obj = b->name;
3724 #if 0
3725 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
3727 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
3728 decode_mode_spec_buf[maxwidth - 1] = '\\';
3729 decode_mode_spec_buf[maxwidth] = '\0';
3730 return decode_mode_spec_buf;
3732 #endif
3733 break;
3735 case 'c':
3737 int col = current_column ();
3738 XSETFASTINT (w->column_number_displayed, col);
3739 pint2str (decode_mode_spec_buf, spec_width, col);
3740 return decode_mode_spec_buf;
3743 case 'F':
3744 /* %F displays the frame name. */
3745 #ifdef MULTI_FRAME
3746 if (!NILP (f->title))
3747 return (char *) XSTRING (f->title)->data;
3748 if (f->explicit_name || ! FRAME_WINDOW_P (f))
3749 return (char *) XSTRING (f->name)->data;
3750 #endif
3751 return "Emacs";
3753 case 'f':
3754 obj = b->filename;
3755 #if 0
3756 if (NILP (obj))
3757 return "[none]";
3758 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
3760 bcopy ("...", decode_mode_spec_buf, 3);
3761 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
3762 decode_mode_spec_buf + 3, maxwidth - 3);
3763 return decode_mode_spec_buf;
3765 #endif
3766 break;
3768 case 'l':
3770 int startpos = marker_position (w->start);
3771 int line, linepos, topline;
3772 int nlines, junk;
3773 Lisp_Object tem;
3774 int height = XFASTINT (w->height);
3776 /* If we decided that this buffer isn't suitable for line numbers,
3777 don't forget that too fast. */
3778 if (EQ (w->base_line_pos, w->buffer))
3779 goto no_value;
3781 /* If the buffer is very big, don't waste time. */
3782 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
3784 w->base_line_pos = Qnil;
3785 w->base_line_number = Qnil;
3786 goto no_value;
3789 if (!NILP (w->base_line_number)
3790 && !NILP (w->base_line_pos)
3791 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
3793 line = XFASTINT (w->base_line_number);
3794 linepos = XFASTINT (w->base_line_pos);
3796 else
3798 line = 1;
3799 linepos = BUF_BEGV (b);
3802 /* Count lines from base line to window start position. */
3803 nlines = display_count_lines (linepos, startpos, startpos, &junk);
3805 topline = nlines + line;
3807 /* Determine a new base line, if the old one is too close
3808 or too far away, or if we did not have one.
3809 "Too close" means it's plausible a scroll-down would
3810 go back past it. */
3811 if (startpos == BUF_BEGV (b))
3813 XSETFASTINT (w->base_line_number, topline);
3814 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
3816 else if (nlines < height + 25 || nlines > height * 3 + 50
3817 || linepos == BUF_BEGV (b))
3819 int limit = BUF_BEGV (b);
3820 int position;
3821 int distance = (height * 2 + 30) * 200;
3823 if (startpos - distance > limit)
3824 limit = startpos - distance;
3826 nlines = display_count_lines (startpos, limit,
3827 -(height * 2 + 30),
3828 &position);
3829 /* If we couldn't find the lines we wanted within
3830 200 chars per line,
3831 give up on line numbers for this window. */
3832 if (position == startpos - distance)
3834 w->base_line_pos = w->buffer;
3835 w->base_line_number = Qnil;
3836 goto no_value;
3839 XSETFASTINT (w->base_line_number, topline - nlines);
3840 XSETFASTINT (w->base_line_pos, position);
3843 /* Now count lines from the start pos to point. */
3844 nlines = display_count_lines (startpos, PT, PT, &junk);
3846 /* Record that we did display the line number. */
3847 line_number_displayed = 1;
3849 /* Make the string to show. */
3850 pint2str (decode_mode_spec_buf, spec_width, topline + nlines);
3851 return decode_mode_spec_buf;
3852 no_value:
3854 char* p = decode_mode_spec_buf;
3855 for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' ';
3856 strcpy (p, "??");
3857 return decode_mode_spec_buf;
3860 break;
3862 case 'm':
3863 obj = b->mode_name;
3864 break;
3866 case 'n':
3867 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
3868 return " Narrow";
3869 break;
3871 case 'p':
3873 int pos = marker_position (w->start);
3874 int total = BUF_ZV (b) - BUF_BEGV (b);
3876 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
3878 if (pos <= BUF_BEGV (b))
3879 return "All";
3880 else
3881 return "Bottom";
3883 else if (pos <= BUF_BEGV (b))
3884 return "Top";
3885 else
3887 if (total > 1000000)
3888 /* Do it differently for a large value, to avoid overflow. */
3889 total = ((pos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
3890 else
3891 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
3892 /* We can't normally display a 3-digit number,
3893 so get us a 2-digit number that is close. */
3894 if (total == 100)
3895 total = 99;
3896 sprintf (decode_mode_spec_buf, "%2d%%", total);
3897 return decode_mode_spec_buf;
3901 /* Display percentage of size above the bottom of the screen. */
3902 case 'P':
3904 int toppos = marker_position (w->start);
3905 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
3906 int total = BUF_ZV (b) - BUF_BEGV (b);
3908 if (botpos >= BUF_ZV (b))
3910 if (toppos <= BUF_BEGV (b))
3911 return "All";
3912 else
3913 return "Bottom";
3915 else
3917 if (total > 1000000)
3918 /* Do it differently for a large value, to avoid overflow. */
3919 total = ((botpos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
3920 else
3921 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
3922 /* We can't normally display a 3-digit number,
3923 so get us a 2-digit number that is close. */
3924 if (total == 100)
3925 total = 99;
3926 if (toppos <= BUF_BEGV (b))
3927 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
3928 else
3929 sprintf (decode_mode_spec_buf, "%2d%%", total);
3930 return decode_mode_spec_buf;
3934 case 's':
3935 /* status of process */
3936 obj = Fget_buffer_process (w->buffer);
3937 if (NILP (obj))
3938 return "no process";
3939 #ifdef subprocesses
3940 obj = Fsymbol_name (Fprocess_status (obj));
3941 #endif
3942 break;
3944 case 't': /* indicate TEXT or BINARY */
3945 #ifdef MODE_LINE_BINARY_TEXT
3946 return MODE_LINE_BINARY_TEXT (b);
3947 #else
3948 return "T";
3949 #endif
3952 if (STRINGP (obj))
3953 return (char *) XSTRING (obj)->data;
3954 else
3955 return "";
3958 /* Search for COUNT instances of a line boundary, which means either a
3959 newline or (if selective display enabled) a carriage return.
3960 Start at START. If COUNT is negative, search backwards.
3962 If we find COUNT instances, set *SHORTAGE to zero, and return the
3963 position after the COUNTth match. Note that for reverse motion
3964 this is not the same as the usual convention for Emacs motion commands.
3966 If we don't find COUNT instances before reaching the end of the
3967 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3968 the number of line boundaries left unfound, and return the end of the
3969 buffer we bumped up against. */
3971 static int
3972 display_scan_buffer (start, count, shortage)
3973 int *shortage, start;
3974 register int count;
3976 int limit = ((count > 0) ? ZV - 1 : BEGV);
3977 int direction = ((count > 0) ? 1 : -1);
3979 register unsigned char *cursor;
3980 unsigned char *base;
3982 register int ceiling;
3983 register unsigned char *ceiling_addr;
3985 /* If we are not in selective display mode,
3986 check only for newlines. */
3987 if (! (!NILP (current_buffer->selective_display)
3988 && !INTEGERP (current_buffer->selective_display)))
3989 return scan_buffer ('\n', start, 0, count, shortage, 0);
3991 /* The code that follows is like scan_buffer
3992 but checks for either newline or carriage return. */
3994 if (shortage != 0)
3995 *shortage = 0;
3997 if (count > 0)
3998 while (start != limit + 1)
4000 ceiling = BUFFER_CEILING_OF (start);
4001 ceiling = min (limit, ceiling);
4002 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
4003 base = (cursor = &FETCH_CHAR (start));
4004 while (1)
4006 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
4008 if (cursor != ceiling_addr)
4010 if (--count == 0)
4012 immediate_quit = 0;
4013 return (start + cursor - base + 1);
4015 else
4016 if (++cursor == ceiling_addr)
4017 break;
4019 else
4020 break;
4022 start += cursor - base;
4024 else
4026 start--; /* first character we scan */
4027 while (start > limit - 1)
4028 { /* we WILL scan under start */
4029 ceiling = BUFFER_FLOOR_OF (start);
4030 ceiling = max (limit, ceiling);
4031 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
4032 base = (cursor = &FETCH_CHAR (start));
4033 cursor++;
4034 while (1)
4036 while (--cursor != ceiling_addr
4037 && *cursor != '\n' && *cursor != 015)
4039 if (cursor != ceiling_addr)
4041 if (++count == 0)
4043 immediate_quit = 0;
4044 return (start + cursor - base + 1);
4047 else
4048 break;
4050 start += cursor - base;
4054 if (shortage != 0)
4055 *shortage = count * direction;
4056 return (start + ((direction == 1 ? 0 : 1)));
4059 /* Count up to N lines starting from FROM.
4060 But don't go beyond LIMIT.
4061 Return the number of lines thus found (always positive).
4062 Store the position after what was found into *POS_PTR. */
4064 static int
4065 display_count_lines (from, limit, n, pos_ptr)
4066 int from, limit, n;
4067 int *pos_ptr;
4069 int oldbegv = BEGV;
4070 int oldzv = ZV;
4071 int shortage = 0;
4073 if (limit < from)
4074 BEGV = limit;
4075 else
4076 ZV = limit;
4078 *pos_ptr = display_scan_buffer (from, n, &shortage);
4080 ZV = oldzv;
4081 BEGV = oldbegv;
4083 if (n < 0)
4084 /* When scanning backwards, scan_buffer stops *after* the last newline
4085 it finds, but does count it. Compensate for that. */
4086 return - n - shortage - (*pos_ptr != limit);
4087 return n - shortage;
4090 /* Display STRING on one line of window W, starting at HPOS.
4091 Display at position VPOS. Caller should have done get_display_line.
4092 If VPOS == -1, display it as the current frame's title.
4093 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4095 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4097 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4098 MAXCOL is the last column ok to end at. Truncate here.
4099 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4100 Both count from the left edge of the frame, as does HPOS.
4101 The right edge of W is an implicit maximum.
4102 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4104 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4105 at the place where the current window ends in this line
4106 and not display anything beyond there. Otherwise, only MAXCOL
4107 controls where to stop output.
4109 Returns ending hpos. */
4111 static int
4112 display_string (w, vpos, string, length, hpos, truncate,
4113 obey_window_width, mincol, maxcol)
4114 struct window *w;
4115 unsigned char *string;
4116 int length;
4117 int vpos, hpos;
4118 GLYPH truncate;
4119 int obey_window_width;
4120 int mincol, maxcol;
4122 register int c;
4123 int truncated;
4124 register GLYPH *p1;
4125 int hscroll = XINT (w->hscroll);
4126 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
4127 register GLYPH *start;
4128 register GLYPH *end;
4129 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4130 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
4131 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
4132 int window_width = XFASTINT (w->width);
4134 /* Use the standard display table, not the window's display table.
4135 We don't want the mode line in rot13. */
4136 register struct Lisp_Char_Table *dp = 0;
4137 int i;
4139 if (DISP_TABLE_P (Vstandard_display_table))
4140 dp = XCHAR_TABLE (Vstandard_display_table);
4142 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
4144 p1 = p1start;
4145 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
4147 if (obey_window_width)
4149 end = start + window_width - (truncate != 0);
4151 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
4153 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4155 int i;
4157 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
4158 *end-- = ' ';
4160 else
4161 *end-- = '|';
4165 if (! obey_window_width
4166 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
4167 end = desired_glyphs->glyphs[vpos] + maxcol;
4169 /* Store 0 in charstart for these columns. */
4170 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
4171 desired_glyphs->charstarts[vpos][i] = 0;
4173 if (maxcol >= 0 && mincol > maxcol)
4174 mincol = maxcol;
4176 /* We set truncated to 1 if we get stopped by trying to pass END
4177 (that is, trying to pass MAXCOL.) */
4178 truncated = 0;
4179 while (1)
4181 if (length == 0)
4182 break;
4183 c = *string++;
4184 /* Specified length. */
4185 if (length >= 0)
4186 length--;
4187 /* Unspecified length (null-terminated string). */
4188 else if (c == 0)
4189 break;
4191 if (p1 >= end)
4193 truncated = 1;
4194 break;
4197 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
4199 p1 = copy_part_of_rope (f, p1, start,
4200 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
4201 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
4204 else if (c >= 040 && c < 0177)
4206 if (p1 >= start)
4207 *p1 = c;
4208 p1++;
4210 else if (c == '\t')
4214 if (p1 >= start && p1 < end)
4215 *p1 = SPACEGLYPH;
4216 p1++;
4218 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
4220 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
4222 if (p1 >= start)
4223 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
4224 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
4226 p1++;
4227 if (p1 >= start && p1 < end)
4228 *p1 = c ^ 0100;
4229 p1++;
4231 else
4233 if (p1 >= start)
4234 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
4235 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
4237 p1++;
4238 if (p1 >= start && p1 < end)
4239 *p1 = (c >> 6) + '0';
4240 p1++;
4241 if (p1 >= start && p1 < end)
4242 *p1 = (7 & (c >> 3)) + '0';
4243 p1++;
4244 if (p1 >= start && p1 < end)
4245 *p1 = (7 & c) + '0';
4246 p1++;
4250 if (truncated)
4252 p1 = end;
4253 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
4255 else if (mincol >= 0)
4257 end = desired_glyphs->glyphs[vpos] + mincol;
4258 while (p1 < end)
4259 *p1++ = SPACEGLYPH;
4263 register int len = p1 - desired_glyphs->glyphs[vpos];
4265 if (len > desired_glyphs->used[vpos])
4266 desired_glyphs->used[vpos] = len;
4267 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
4269 return len;
4273 /* This is like a combination of memq and assq.
4274 Return 1 if PROPVAL appears as an element of LIST
4275 or as the car of an element of LIST.
4276 If PROPVAL is a list, compare each element against LIST
4277 in that way, and return 1 if any element of PROPVAL is found in LIST.
4278 Otherwise return 0.
4279 This function cannot quit. */
4282 invisible_p (propval, list)
4283 register Lisp_Object propval;
4284 Lisp_Object list;
4286 register Lisp_Object tail, proptail;
4287 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4289 register Lisp_Object tem;
4290 tem = XCONS (tail)->car;
4291 if (EQ (propval, tem))
4292 return 1;
4293 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4294 return 1;
4296 if (CONSP (propval))
4297 for (proptail = propval; CONSP (proptail);
4298 proptail = XCONS (proptail)->cdr)
4300 Lisp_Object propelt;
4301 propelt = XCONS (proptail)->car;
4302 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4304 register Lisp_Object tem;
4305 tem = XCONS (tail)->car;
4306 if (EQ (propelt, tem))
4307 return 1;
4308 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4309 return 1;
4312 return 0;
4315 /* Return 1 if PROPVAL appears as the car of an element of LIST
4316 and the cdr of that element is non-nil.
4317 If PROPVAL is a list, check each element of PROPVAL in that way,
4318 and the first time some element is found,
4319 return 1 if the cdr of that element is non-nil.
4320 Otherwise return 0.
4321 This function cannot quit. */
4324 invisible_ellipsis_p (propval, list)
4325 register Lisp_Object propval;
4326 Lisp_Object list;
4328 register Lisp_Object tail, proptail;
4329 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4331 register Lisp_Object tem;
4332 tem = XCONS (tail)->car;
4333 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4334 return ! NILP (XCONS (tem)->cdr);
4336 if (CONSP (propval))
4337 for (proptail = propval; CONSP (proptail);
4338 proptail = XCONS (proptail)->cdr)
4340 Lisp_Object propelt;
4341 propelt = XCONS (proptail)->car;
4342 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4344 register Lisp_Object tem;
4345 tem = XCONS (tail)->car;
4346 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4347 return ! NILP (XCONS (tem)->cdr);
4350 return 0;
4353 void
4354 syms_of_xdisp ()
4356 staticpro (&Qmenu_bar_update_hook);
4357 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
4359 staticpro (&Qoverriding_terminal_local_map);
4360 Qoverriding_terminal_local_map = intern ("overriding-terminal-local-map");
4362 staticpro (&Qoverriding_local_map);
4363 Qoverriding_local_map = intern ("overriding-local-map");
4365 staticpro (&Qwindow_scroll_functions);
4366 Qwindow_scroll_functions = intern ("window-scroll-functions");
4368 staticpro (&Qredisplay_end_trigger_functions);
4369 Qredisplay_end_trigger_functions = intern ("redisplay-end-trigger-functions");
4371 staticpro (&last_arrow_position);
4372 staticpro (&last_arrow_string);
4373 last_arrow_position = Qnil;
4374 last_arrow_string = Qnil;
4376 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
4377 "String (or mode line construct) included (normally) in `mode-line-format'.");
4378 Vglobal_mode_string = Qnil;
4380 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
4381 "Marker for where to display an arrow on top of the buffer text.\n\
4382 This must be the beginning of a line in order to work.\n\
4383 See also `overlay-arrow-string'.");
4384 Voverlay_arrow_position = Qnil;
4386 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
4387 "String to display as an arrow. See also `overlay-arrow-position'.");
4388 Voverlay_arrow_string = Qnil;
4390 DEFVAR_INT ("scroll-step", &scroll_step,
4391 "*The number of lines to try scrolling a window by when point moves out.\n\
4392 If that fails to bring point back on frame, point is centered instead.\n\
4393 If this is zero, point is always centered after it moves off frame.");
4395 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
4397 DEFVAR_BOOL ("truncate-partial-width-windows",
4398 &truncate_partial_width_windows,
4399 "*Non-nil means truncate lines in all windows less than full frame wide.");
4400 truncate_partial_width_windows = 1;
4402 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
4403 "*Non-nil means use inverse video for the mode line.");
4404 mode_line_inverse_video = 1;
4406 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
4407 "*Maximum buffer size for which line number should be displayed.");
4408 line_number_display_limit = 1000000;
4410 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
4411 "*Non-nil means highlight region even in nonselected windows.");
4412 highlight_nonselected_windows = 1;
4414 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
4415 "Non-nil if more than one frame is visible on this display.\n\
4416 Minibuffer-only frames don't count, but iconified frames do.\n\
4417 This variable is not guaranteed to be accurate except while processing\n\
4418 `frame-title-format' and `icon-title-format'.");
4420 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
4421 "Template for displaying the titlebar of visible frames.\n\
4422 \(Assuming the window manager supports this feature.)\n\
4423 This variable has the same structure as `mode-line-format' (which see),\n\
4424 and is used only on frames for which no explicit name has been set\n\
4425 \(see `modify-frame-parameters').");
4426 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
4427 "Template for displaying the titlebar of an iconified frame.\n\
4428 \(Assuming the window manager supports this feature.)\n\
4429 This variable has the same structure as `mode-line-format' (which see),\n\
4430 and is used only on frames for which no explicit name has been set\n\
4431 \(see `modify-frame-parameters').");
4432 Vicon_title_format
4433 = Vframe_title_format
4434 = Fcons (intern ("multiple-frames"),
4435 Fcons (build_string ("%b"),
4436 Fcons (Fcons (build_string (""),
4437 Fcons (intern ("invocation-name"),
4438 Fcons (build_string ("@"),
4439 Fcons (intern ("system-name"),
4440 Qnil)))),
4441 Qnil)));
4443 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
4444 "Maximum number of lines to keep in the message log buffer.\n\
4445 If nil, disable message logging. If t, log messages but don't truncate\n\
4446 the buffer when it becomes large.");
4447 XSETFASTINT (Vmessage_log_max, 50);
4449 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
4450 "Functions called before redisplay, if window sizes have changed.\n\
4451 The value should be a list of functions that take one argument.\n\
4452 Just before redisplay, for each frame, if any of its windows have changed\n\
4453 size since the last redisplay, or have been split or deleted,\n\
4454 all the functions in the list are called, with the frame as argument.");
4455 Vwindow_size_change_functions = Qnil;
4457 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions,
4458 "List of Functions to call before redisplaying a window with scrolling.\n\
4459 Each function is called with two arguments, the window\n\
4460 and its new display-start position. Note that the value of `window-end'\n\
4461 is not valid when these functions are called.");
4462 Vwindow_scroll_functions = Qnil;
4465 /* initialize the window system */
4466 init_xdisp ()
4468 Lisp_Object root_window;
4469 #ifndef COMPILER_REGISTER_BUG
4470 register
4471 #endif /* COMPILER_REGISTER_BUG */
4472 struct window *mini_w;
4474 this_line_bufpos = 0;
4476 mini_w = XWINDOW (minibuf_window);
4477 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
4479 echo_area_glyphs = 0;
4480 previous_echo_glyphs = 0;
4482 if (!noninteractive)
4484 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
4485 XSETFASTINT (XWINDOW (root_window)->top, 0);
4486 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
4487 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
4488 set_window_height (minibuf_window, 1, 0);
4490 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
4491 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));