(timeout-event-p): Function deleted.
[emacs.git] / src / xdisp.c
blob744fb83c89134f046be85f63e58b60d219ac2480
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 #endif
44 extern int interrupt_input;
45 extern int command_loop_level;
47 extern Lisp_Object Qface;
49 extern Lisp_Object Voverriding_local_map;
50 extern Lisp_Object Voverriding_local_map_menu_flag;
52 Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
53 Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
54 Lisp_Object Qredisplay_end_trigger_functions;
56 /* Nonzero means print newline to stdout before next minibuffer message. */
58 int noninteractive_need_newline;
60 /* Nonzero means print newline to message log before next message. */
62 static int message_log_need_newline;
64 #define min(a, b) ((a) < (b) ? (a) : (b))
65 #define max(a, b) ((a) > (b) ? (a) : (b))
66 #define minmax(floor, val, ceil) \
67 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
69 /* The buffer position of the first character appearing
70 entirely or partially on the current frame line.
71 Or zero, which disables the optimization for the current frame line. */
72 static int this_line_bufpos;
74 /* Number of characters past the end of this line,
75 including the terminating newline */
76 static int this_line_endpos;
78 /* The vertical position of this frame line. */
79 static int this_line_vpos;
81 /* Hpos value for start of display on this frame line.
82 Usually zero, but negative if first character really began
83 on previous line */
84 static int this_line_start_hpos;
86 /* Buffer that this_line variables are describing. */
87 static struct buffer *this_line_buffer;
89 /* Value of echo_area_glyphs when it was last acted on.
90 If this is nonzero, there is a message on the frame
91 in the minibuffer and it should be erased as soon
92 as it is no longer requested to appear. */
93 char *previous_echo_glyphs;
95 /* Nonzero means truncate lines in all windows less wide than the frame */
96 int truncate_partial_width_windows;
98 /* Nonzero means we have more than one non-minibuffer-only frame.
99 Not guaranteed to be accurate except while parsing frame-title-format. */
100 int multiple_frames;
102 Lisp_Object Vglobal_mode_string;
104 /* Marker for where to display an arrow on top of the buffer text. */
105 Lisp_Object Voverlay_arrow_position;
107 /* String to display for the arrow. */
108 Lisp_Object Voverlay_arrow_string;
110 /* Like mode-line-format, but for the titlebar on a visible frame. */
111 Lisp_Object Vframe_title_format;
113 /* Like mode-line-format, but for the titlebar on an iconified frame. */
114 Lisp_Object Vicon_title_format;
116 /* List of functions to call when a window's size changes. These
117 functions get one arg, a frame on which one or more windows' sizes
118 have changed. */
119 static Lisp_Object Vwindow_size_change_functions;
121 /* Values of those variables at last redisplay. */
122 static Lisp_Object last_arrow_position, last_arrow_string;
124 Lisp_Object Qmenu_bar_update_hook;
126 /* Nonzero if overlay arrow has been displayed once in this window. */
127 static int overlay_arrow_seen;
129 /* Nonzero if visible end of buffer has already been displayed once
130 in this window. (We need this variable in case there are overlay
131 strings that get displayed there.) */
132 static int zv_strings_seen;
134 /* Nonzero means highlight the region even in nonselected windows. */
135 static int highlight_nonselected_windows;
137 /* If cursor motion alone moves point off frame,
138 Try scrolling this many lines up or down if that will bring it back. */
139 static int scroll_step;
141 /* Nonzero if try_window_id has made blank lines at window bottom
142 since the last redisplay that paused */
143 static int blank_end_of_window;
145 /* Number of windows showing the buffer of the selected window
146 (or another buffer with the same base buffer).
147 keyboard.c refers to this. */
148 int buffer_shared;
150 /* display_text_line sets these to the frame position (origin 0) of point,
151 whether the window is selected or not.
152 Set one to -1 first to determine whether point was found afterwards. */
154 static int cursor_vpos;
155 static int cursor_hpos;
157 static int debug_end_pos;
159 /* Nonzero means display mode line highlighted */
160 int mode_line_inverse_video;
162 static void redisplay_internal ();
163 static int message_log_check_duplicate ();
164 static void echo_area_display ();
165 void mark_window_display_accurate ();
166 static void redisplay_windows ();
167 static void redisplay_window ();
168 static void update_menu_bar ();
169 static void try_window ();
170 static int try_window_id ();
171 static struct position *display_text_line ();
172 static void display_mode_line ();
173 static int display_mode_element ();
174 static char *decode_mode_spec ();
175 static int display_string ();
176 static void display_menu_bar ();
177 static int display_count_lines ();
179 /* Prompt to display in front of the minibuffer contents */
180 Lisp_Object minibuf_prompt;
182 /* Width in columns of current minibuffer prompt. */
183 int minibuf_prompt_width;
185 /* Message to display instead of minibuffer contents
186 This is what the functions error and message make,
187 and command echoing uses it as well.
188 It overrides the minibuf_prompt as well as the buffer. */
189 char *echo_area_glyphs;
191 /* This is the length of the message in echo_area_glyphs. */
192 int echo_area_glyphs_length;
194 /* This is the window where the echo area message was displayed.
195 It is always a minibuffer window, but it may not be the
196 same window currently active as a minibuffer. */
197 Lisp_Object echo_area_window;
199 /* true iff we should redraw the mode lines on the next redisplay */
200 int update_mode_lines;
202 /* Smallest number of characters before the gap
203 at any time since last redisplay that finished.
204 Valid for current buffer when try_window_id can be called. */
205 int beg_unchanged;
207 /* Smallest number of characters after the gap
208 at any time since last redisplay that finished.
209 Valid for current buffer when try_window_id can be called. */
210 int end_unchanged;
212 /* MODIFF as of last redisplay that finished;
213 if it matches MODIFF, beg_unchanged and end_unchanged
214 contain no useful information */
215 int unchanged_modified;
217 /* Nonzero if window sizes or contents have changed
218 since last redisplay that finished */
219 int windows_or_buffers_changed;
221 /* Nonzero after display_mode_line if %l was used
222 and it displayed a line number. */
223 int line_number_displayed;
225 /* Maximum buffer size for which to display line numbers. */
226 static int line_number_display_limit;
228 /* Number of lines to keep in the message log buffer.
229 t means infinite. nil means don't log at all. */
230 Lisp_Object Vmessage_log_max;
232 /* Output a newline in the *Messages* buffer if "needs" one. */
234 void
235 message_log_maybe_newline ()
237 if (message_log_need_newline)
238 message_dolog ("", 0, 1);
242 /* Add a string to the message log, optionally terminated with a newline.
243 This function calls low-level routines in order to bypass text property
244 hooks, etc. which might not be safe to run. */
246 void
247 message_dolog (m, len, nlflag)
248 char *m;
249 int len, nlflag;
251 if (!NILP (Vmessage_log_max))
253 struct buffer *oldbuf;
254 int oldpoint, oldbegv, oldzv;
255 int old_windows_or_buffers_changed = windows_or_buffers_changed;
257 oldbuf = current_buffer;
258 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
259 current_buffer->undo_list = Qt;
260 oldpoint = PT;
261 oldbegv = BEGV;
262 oldzv = ZV;
263 BEGV = BEG;
264 ZV = Z;
265 if (oldpoint == Z)
266 oldpoint += len + nlflag;
267 if (oldzv == Z)
268 oldzv += len + nlflag;
269 TEMP_SET_PT (Z);
270 if (len)
271 insert_1 (m, len, 1, 0);
272 if (nlflag)
274 int this_bol, prev_bol, dup;
275 insert_1 ("\n", 1, 1, 0);
277 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
278 if (this_bol > BEG)
280 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
281 dup = message_log_check_duplicate (prev_bol, this_bol);
282 if (dup)
284 if (oldpoint > prev_bol)
285 oldpoint -= min (this_bol, oldpoint) - prev_bol;
286 if (oldbegv > prev_bol)
287 oldbegv -= min (this_bol, oldbegv) - prev_bol;
288 if (oldzv > prev_bol)
289 oldzv -= min (this_bol, oldzv) - prev_bol;
290 del_range_1 (prev_bol, this_bol, 0);
291 if (dup > 1)
293 char dupstr[40];
294 int duplen;
296 /* If you change this format, don't forget to also
297 change message_log_check_duplicate. */
298 sprintf (dupstr, " [%d times]", dup);
299 duplen = strlen (dupstr);
300 TEMP_SET_PT (Z-1);
301 if (oldpoint == Z)
302 oldpoint += duplen;
303 if (oldzv == Z)
304 oldzv += duplen;
305 insert_1 (dupstr, duplen, 1, 0);
310 if (NATNUMP (Vmessage_log_max))
312 int pos = scan_buffer ('\n', Z, 0,
313 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
314 oldpoint -= min (pos, oldpoint) - BEG;
315 oldbegv -= min (pos, oldbegv) - BEG;
316 oldzv -= min (pos, oldzv) - BEG;
317 del_range_1 (BEG, pos, 0);
320 BEGV = oldbegv;
321 ZV = oldzv;
322 TEMP_SET_PT (oldpoint);
323 set_buffer_internal (oldbuf);
324 windows_or_buffers_changed = old_windows_or_buffers_changed;
325 message_log_need_newline = !nlflag;
329 /* We are at the end of the buffer after just having inserted a newline.
330 (Note: We depend on the fact we won't be crossing the gap.)
331 Check to see if the most recent message looks a lot like the previous one.
332 Return 0 if different, 1 if the new one should just replace it, or a
333 value N > 1 if we should also append " [N times]". */
335 static int
336 message_log_check_duplicate (prev_bol, this_bol)
337 int prev_bol, this_bol;
339 int i;
340 int len = Z - 1 - this_bol;
341 int seen_dots = 0;
342 unsigned char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
343 unsigned char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
345 for (i = 0; i < len; i++)
347 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
348 && p1[i] != '\n')
349 seen_dots = 1;
350 if (p1[i] != p2[i])
351 return seen_dots;
353 p1 += len;
354 if (*p1 == '\n')
355 return 2;
356 if (*p1++ == ' ' && *p1++ == '[')
358 int n = 0;
359 while (*p1 >= '0' && *p1 <= '9')
360 n = n * 10 + *p1++ - '0';
361 if (strncmp (p1, " times]\n", 8) == 0)
362 return n+1;
364 return 0;
367 /* Display an echo area message M with a specified length of LEN chars.
368 The string may include null characters. If M is 0, clear out any
369 existing message, and let the minibuffer text show through.
371 The buffer M must continue to exist until after the echo area
372 gets cleared or some other message gets displayed there.
374 Do not pass text that is stored in a Lisp string.
375 Do not pass text in a buffer that was alloca'd. */
377 void
378 message2 (m, len)
379 char *m;
380 int len;
382 /* First flush out any partial line written with print. */
383 message_log_maybe_newline ();
384 if (m)
385 message_dolog (m, len, 1);
386 message2_nolog (m, len);
390 /* The non-logging counterpart of message2. */
392 void
393 message2_nolog (m, len)
394 char *m;
395 int len;
397 if (noninteractive)
399 if (noninteractive_need_newline)
400 putc ('\n', stderr);
401 noninteractive_need_newline = 0;
402 fwrite (m, len, 1, stderr);
403 if (cursor_in_echo_area == 0)
404 fprintf (stderr, "\n");
405 fflush (stderr);
407 /* A null message buffer means that the frame hasn't really been
408 initialized yet. Error messages get reported properly by
409 cmd_error, so this must be just an informative message; toss it. */
410 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
412 Lisp_Object mini_window;
413 FRAME_PTR f;
415 /* Get the frame containing the minibuffer
416 that the selected frame is using. */
417 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
418 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
420 #ifdef MULTI_FRAME
421 FRAME_SAMPLE_VISIBILITY (f);
422 if (FRAME_VISIBLE_P (selected_frame)
423 && ! FRAME_VISIBLE_P (f))
424 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window)));
425 #endif
427 if (m)
429 echo_area_glyphs = m;
430 echo_area_glyphs_length = len;
432 else
433 echo_area_glyphs = previous_echo_glyphs = 0;
435 do_pending_window_change ();
436 echo_area_display ();
437 update_frame (f, 1, 1);
438 do_pending_window_change ();
439 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
440 (*frame_up_to_date_hook) (f);
444 /* Display a null-terminated echo area message M. If M is 0, clear out any
445 existing message, and let the minibuffer text show through.
447 The buffer M must continue to exist until after the echo area
448 gets cleared or some other message gets displayed there.
450 Do not pass text that is stored in a Lisp string.
451 Do not pass text in a buffer that was alloca'd. */
453 void
454 message1 (m)
455 char *m;
457 message2 (m, (m ? strlen (m) : 0));
460 void
461 message1_nolog (m)
462 char *m;
464 message2_nolog (m, (m ? strlen (m) : 0));
467 /* Truncate what will be displayed in the echo area
468 the next time we display it--but don't redisplay it now. */
470 void
471 truncate_echo_area (len)
472 int len;
474 /* A null message buffer means that the frame hasn't really been
475 initialized yet. Error messages get reported properly by
476 cmd_error, so this must be just an informative message; toss it. */
477 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
478 echo_area_glyphs_length = len;
481 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
482 zero if being used by message. */
483 int message_buf_print;
485 /* Dump an informative message to the minibuf. If M is 0, clear out
486 any existing message, and let the minibuffer text show through. */
488 /* VARARGS 1 */
489 void
490 message (m, a1, a2, a3)
491 char *m;
492 EMACS_INT a1, a2, a3;
494 if (noninteractive)
496 if (m)
498 if (noninteractive_need_newline)
499 putc ('\n', stderr);
500 noninteractive_need_newline = 0;
501 fprintf (stderr, m, a1, a2, a3);
502 if (cursor_in_echo_area == 0)
503 fprintf (stderr, "\n");
504 fflush (stderr);
507 else if (INTERACTIVE)
509 /* The frame whose minibuffer we're going to display the message on.
510 It may be larger than the selected frame, so we need
511 to use its buffer, not the selected frame's buffer. */
512 Lisp_Object mini_window;
513 FRAME_PTR f;
515 /* Get the frame containing the minibuffer
516 that the selected frame is using. */
517 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
518 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
520 /* A null message buffer means that the frame hasn't really been
521 initialized yet. Error messages get reported properly by
522 cmd_error, so this must be just an informative message; toss it. */
523 if (FRAME_MESSAGE_BUF (f))
525 if (m)
527 int len;
528 #ifdef NO_ARG_ARRAY
529 EMACS_INT a[3];
530 a[0] = a1;
531 a[1] = a2;
532 a[2] = a3;
534 len = doprnt (FRAME_MESSAGE_BUF (f),
535 FRAME_WIDTH (f), m, (char *)0, 3, a);
536 #else
537 len = doprnt (FRAME_MESSAGE_BUF (f),
538 FRAME_WIDTH (f), m, (char *)0, 3, &a1);
539 #endif /* NO_ARG_ARRAY */
541 message2 (FRAME_MESSAGE_BUF (f), len);
543 else
544 message1 (0);
546 /* Print should start at the beginning of the message
547 buffer next time. */
548 message_buf_print = 0;
553 /* The non-logging version of message. */
554 void
555 message_nolog (m, a1, a2, a3)
556 char *m;
557 EMACS_INT a1, a2, a3;
559 Lisp_Object old_log_max;
560 old_log_max = Vmessage_log_max;
561 Vmessage_log_max = Qnil;
562 message (m, a1, a2, a3);
563 Vmessage_log_max = old_log_max;
566 void
567 update_echo_area ()
569 message2 (echo_area_glyphs, echo_area_glyphs_length);
572 static void
573 echo_area_display ()
575 register int vpos;
576 FRAME_PTR f;
577 Lisp_Object mini_window;
579 /* Choose the minibuffer window for this display.
580 It is the minibuffer window used by the selected frame. */
581 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
582 /* This is the frame that window is in. */
583 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
585 if (! FRAME_VISIBLE_P (f))
586 return;
588 if (frame_garbaged)
590 redraw_garbaged_frames ();
591 frame_garbaged = 0;
594 if (echo_area_glyphs || minibuf_level == 0)
596 echo_area_window = mini_window;
598 vpos = XFASTINT (XWINDOW (mini_window)->top);
599 get_display_line (f, vpos, 0);
600 display_string (XWINDOW (mini_window), vpos,
601 echo_area_glyphs ? echo_area_glyphs : "",
602 echo_area_glyphs ? echo_area_glyphs_length : -1,
603 0, 0, 0, 0, FRAME_WIDTH (f));
605 #if 0 /* This just gets in the way. update_frame does the job. */
606 /* If desired cursor location is on this line, put it at end of text */
607 if (cursor_in_echo_area)
608 FRAME_CURSOR_Y (f) = vpos;
609 if (FRAME_CURSOR_Y (f) == vpos)
610 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
611 #endif
613 /* Fill the rest of the minibuffer window with blank lines. */
615 int i;
617 for (i = vpos + 1;
618 i < vpos + XFASTINT (XWINDOW (mini_window)->height); i++)
620 get_display_line (f, i, 0);
621 display_string (XWINDOW (mini_window), vpos,
622 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f));
626 else if (!EQ (mini_window, selected_window))
627 windows_or_buffers_changed++;
629 if (EQ (mini_window, selected_window))
630 this_line_bufpos = 0;
632 previous_echo_glyphs = echo_area_glyphs;
635 /* Update frame titles. */
637 #ifdef HAVE_WINDOW_SYSTEM
638 static char frame_title_buf[512];
639 static char *frame_title_ptr;
641 static int
642 store_frame_title (str, mincol, maxcol)
643 char *str;
644 int mincol, maxcol;
646 char *limit;
647 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
648 maxcol = sizeof (frame_title_buf);
649 limit = &frame_title_buf[maxcol];
650 while (*str != '\0' && frame_title_ptr < limit)
651 *frame_title_ptr++ = *str++;
652 while (frame_title_ptr < &frame_title_buf[mincol])
653 *frame_title_ptr++ = ' ';
654 return frame_title_ptr - frame_title_buf;
657 static void
658 x_consider_frame_title (frame)
659 Lisp_Object frame;
661 Lisp_Object fmt;
662 struct buffer *obuf;
663 int len;
664 FRAME_PTR f = XFRAME (frame);
666 if (!(FRAME_WINDOW_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name))
667 return;
669 /* Do we have more than one visible frame on this X display? */
671 Lisp_Object tail;
673 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
675 FRAME_PTR tf = XFRAME (XCONS (tail)->car);
677 if (tf != f && FRAME_KBOARD (tf) == FRAME_KBOARD (f)
678 && !FRAME_MINIBUF_ONLY_P (tf)
679 && (FRAME_VISIBLE_P (tf) || FRAME_ICONIFIED_P (tf)))
680 break;
683 multiple_frames = CONSP (tail);
686 obuf = current_buffer;
687 Fset_buffer (XWINDOW (f->selected_window)->buffer);
688 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
689 frame_title_ptr = frame_title_buf;
690 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
691 0, sizeof (frame_title_buf), fmt);
692 frame_title_ptr = 0;
693 set_buffer_internal (obuf);
694 /* Set the name only if it's changed. This avoids consing
695 in the common case where it hasn't. (If it turns out that we've
696 already wasted too much time by walking through the list with
697 display_mode_element, then we might need to optimize at a higher
698 level than this.) */
699 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
700 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
701 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
703 #else
704 #define frame_title_ptr ((char *)0)
705 #define store_frame_title(str, mincol, maxcol) 0
706 #endif
708 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
709 This can call eval. */
711 void
712 prepare_menu_bars ()
714 register struct window *w = XWINDOW (selected_window);
715 int all_windows;
716 struct gcpro gcpro1, gcpro2;
718 all_windows = (update_mode_lines || buffer_shared > 1
719 || windows_or_buffers_changed);
721 /* Update all frame titles based on their buffer names, etc.
722 We do this before the menu bars so that the buffer-menu
723 will show the up-to-date frame titles.
725 This used to be done after the menu bars, for a reason that
726 was stated as follows but which I do not understand:
727 "We do this after the menu bars so that the frame will first
728 create its menu bar using the name `emacs' if no other name
729 has yet been specified."
730 I think that is no longer a concern. */
731 #ifdef HAVE_WINDOW_SYSTEM
732 if (windows_or_buffers_changed || update_mode_lines)
734 Lisp_Object tail, frame;
736 FOR_EACH_FRAME (tail, frame)
737 if (FRAME_VISIBLE_P (XFRAME (frame))
738 || FRAME_ICONIFIED_P (XFRAME (frame)))
739 x_consider_frame_title (frame);
741 #endif
743 /* Update the menu bar item lists, if appropriate.
744 This has to be done before any actual redisplay
745 or generation of display lines. */
746 if (all_windows)
748 Lisp_Object tail, frame;
749 int count = specpdl_ptr - specpdl;
751 record_unwind_protect (Fstore_match_data, Fmatch_data ());
753 FOR_EACH_FRAME (tail, frame)
755 /* If a window on this frame changed size,
756 report that to the user and clear the size-change flag. */
757 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
759 Lisp_Object functions;
760 /* Clear flag first in case we get error below. */
761 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
762 functions = Vwindow_size_change_functions;
763 GCPRO2 (tail, functions);
764 while (CONSP (functions))
766 call1 (XCONS (functions)->car, frame);
767 functions = XCONS (functions)->cdr;
769 UNGCPRO;
771 GCPRO1 (tail);
772 update_menu_bar (XFRAME (frame), 0);
773 UNGCPRO;
776 unbind_to (count, Qnil);
778 else
779 update_menu_bar (selected_frame, 1);
782 /* Do a frame update, taking possible shortcuts into account.
783 This is the main external entry point for redisplay.
785 If the last redisplay displayed an echo area message and that
786 message is no longer requested, we clear the echo area
787 or bring back the minibuffer if that is in use.
789 Do not call eval from within this function.
790 Calls to eval after the call to echo_area_display would confuse
791 the display_line mechanism and would cause a crash.
792 Calls to eval before that point will work most of the time,
793 but can still lose, because this function
794 can be called from signal handlers; with alarms set up;
795 or with synchronous processes running.
797 See Fcall_process; if you called it from here, it could be
798 entered recursively. */
800 static int do_verify_charstarts;
802 /* Counter is used to clear the face cache
803 no more than once ever 1000 redisplays. */
804 static int clear_face_cache_count;
806 /* Record the previous terminal frame we displayed. */
807 static FRAME_PTR previous_terminal_frame;
809 void
810 redisplay ()
812 redisplay_internal (0);
815 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
816 is not in response to any user action; therefore, we should
817 preserve the echo area. (Actually, our caller does that job.)
818 Perhaps in the future avoid recentering windows
819 if it is not necessary; currently that causes some problems. */
821 static void
822 redisplay_internal (preserve_echo_area)
823 int preserve_echo_area;
825 register struct window *w = XWINDOW (selected_window);
826 register int pause;
827 int must_finish = 0;
828 int all_windows;
829 register int tlbufpos, tlendpos;
830 struct position pos;
832 if (noninteractive)
833 return;
835 #ifdef USE_X_TOOLKIT
836 if (popup_activated ())
837 return;
838 #endif
840 #ifdef MULTI_FRAME
841 if (FRAME_TERMCAP_P (selected_frame)
842 && previous_terminal_frame != selected_frame)
844 /* Since frames on an ASCII terminal share the same display area,
845 displaying a different frame means redisplay the whole thing. */
846 windows_or_buffers_changed++;
847 SET_FRAME_GARBAGED (selected_frame);
848 XSETFRAME (Vterminal_frame, selected_frame);
850 previous_terminal_frame = selected_frame;
851 #endif
853 /* Set the visible flags for all frames.
854 Do this before checking for resized or garbaged frames; they want
855 to know if their frames are visible.
856 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
858 Lisp_Object tail, frame;
860 FOR_EACH_FRAME (tail, frame)
862 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
864 /* Clear out all the display lines in which we will generate the
865 glyphs to display. */
866 init_desired_glyphs (XFRAME (frame));
870 /* Notice any pending interrupt request to change frame size. */
871 do_pending_window_change ();
873 if (frame_garbaged)
875 redraw_garbaged_frames ();
876 frame_garbaged = 0;
879 prepare_menu_bars ();
881 if (windows_or_buffers_changed)
882 update_mode_lines++;
884 /* Detect case that we need to write a star in the mode line. */
885 if (XFASTINT (w->last_modified) < MODIFF
886 && XFASTINT (w->last_modified) <= SAVE_MODIFF)
888 w->update_mode_line = Qt;
889 if (buffer_shared > 1)
890 update_mode_lines++;
893 /* If %c is in use, update it if needed. */
894 if (!NILP (w->column_number_displayed)
895 /* This alternative quickly identifies a common case
896 where no change is needed. */
897 && !(PT == XFASTINT (w->last_point)
898 && XFASTINT (w->last_modified) >= MODIFF)
899 && XFASTINT (w->column_number_displayed) != current_column ())
900 w->update_mode_line = Qt;
902 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
904 all_windows = update_mode_lines || buffer_shared > 1;
906 /* If specs for an arrow have changed, do thorough redisplay
907 to ensure we remove any arrow that should no longer exist. */
908 if (! EQ (Voverlay_arrow_position, last_arrow_position)
909 || ! EQ (Voverlay_arrow_string, last_arrow_string))
910 all_windows = 1;
912 /* Normally the message* functions will have already displayed and
913 updated the echo area, but the frame may have been trashed, or
914 the update may have been preempted, so display the echo area
915 again here. */
916 if (echo_area_glyphs || previous_echo_glyphs)
918 echo_area_display ();
919 must_finish = 1;
922 /* If showing region, and mark has changed, must redisplay whole window. */
923 if (((!NILP (Vtransient_mark_mode)
924 && !NILP (XBUFFER (w->buffer)->mark_active))
925 != !NILP (w->region_showing))
926 || (!NILP (w->region_showing)
927 && !EQ (w->region_showing,
928 Fmarker_position (XBUFFER (w->buffer)->mark))))
929 this_line_bufpos = -1;
931 tlbufpos = this_line_bufpos;
932 tlendpos = this_line_endpos;
933 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
934 && !current_buffer->clip_changed
935 && FRAME_VISIBLE_P (XFRAME (w->frame))
936 /* Make sure recorded data applies to current buffer, etc */
937 && this_line_buffer == current_buffer
938 && current_buffer == XBUFFER (w->buffer)
939 && NILP (w->force_start)
940 /* Point must be on the line that we have info recorded about */
941 && PT >= tlbufpos
942 && PT <= Z - tlendpos
943 /* All text outside that line, including its final newline,
944 must be unchanged */
945 && (XFASTINT (w->last_modified) >= MODIFF
946 || (beg_unchanged >= tlbufpos - 1
947 && GPT >= tlbufpos
948 /* If selective display, can't optimize
949 if the changes start at the beginning of the line. */
950 && ((INTEGERP (current_buffer->selective_display)
951 && XINT (current_buffer->selective_display) > 0
952 ? (beg_unchanged >= tlbufpos
953 && GPT > tlbufpos)
954 : 1))
955 && end_unchanged >= tlendpos
956 && Z - GPT >= tlendpos)))
958 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
959 && (tlbufpos == ZV
960 || FETCH_CHAR (tlbufpos) == '\n'))
961 /* Former continuation line has disappeared by becoming empty */
962 goto cancel;
963 else if (XFASTINT (w->last_modified) < MODIFF
964 || MINI_WINDOW_P (w))
966 cursor_vpos = -1;
967 overlay_arrow_seen = 0;
968 zv_strings_seen = 0;
969 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
970 pos_tab_offset (w, tlbufpos));
971 /* If line contains point, is not continued,
972 and ends at same distance from eob as before, we win */
973 if (cursor_vpos >= 0 && this_line_bufpos
974 && this_line_endpos == tlendpos)
976 /* If this is not the window's last line,
977 we must adjust the charstarts of the lines below. */
978 if (this_line_vpos + 1
979 < XFASTINT (w->top) + window_internal_height (w))
981 int left = XFASTINT (w->left);
982 int *charstart_next_line
983 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
984 int adjust;
986 if (Z - tlendpos == ZV)
987 /* This line ends at end of (accessible part of) buffer.
988 There is no newline to count. */
989 adjust = Z - tlendpos - charstart_next_line[left];
990 else
991 /* This line ends in a newline.
992 Must take account of the newline and the rest of the
993 text that follows. */
994 adjust = Z - tlendpos + 1 - charstart_next_line[left];
996 adjust_window_charstarts (w, this_line_vpos, adjust);
999 if (XFASTINT (w->width) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w))))
1000 preserve_other_columns (w);
1001 goto update;
1003 else
1004 goto cancel;
1006 else if (PT == XFASTINT (w->last_point)
1007 /* Make sure the cursor was last displayed
1008 in this window. Otherwise we have to reposition it. */
1009 && XINT (w->top) <= FRAME_CURSOR_Y (selected_frame)
1010 && (XINT (w->top) + XINT (w->height)
1011 > FRAME_CURSOR_Y (selected_frame)))
1013 if (!must_finish)
1015 do_pending_window_change ();
1016 return;
1018 goto update;
1020 /* If highlighting the region, or if the cursor is in the echo area,
1021 then we can't just move the cursor. */
1022 else if (! (!NILP (Vtransient_mark_mode)
1023 && !NILP (current_buffer->mark_active))
1024 && NILP (w->region_showing)
1025 && !cursor_in_echo_area)
1027 pos = *compute_motion (tlbufpos, 0,
1028 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1030 PT, 2, - (1 << (BITS_PER_SHORT - 1)),
1031 window_internal_width (w) - 1,
1032 XINT (w->hscroll),
1033 pos_tab_offset (w, tlbufpos), w);
1034 if (pos.vpos < 1)
1036 int width = window_internal_width (w) - 1;
1037 FRAME_CURSOR_X (selected_frame)
1038 = XFASTINT (w->left) + minmax (0, pos.hpos, width);
1039 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
1040 goto update;
1042 else
1043 goto cancel;
1045 cancel:
1046 /* Text changed drastically or point moved off of line */
1047 cancel_line (this_line_vpos, selected_frame);
1050 this_line_bufpos = 0;
1051 all_windows |= buffer_shared > 1;
1053 clear_face_cache_count++;
1055 if (all_windows)
1057 Lisp_Object tail, frame;
1059 #ifdef HAVE_FACES
1060 /* Clear the face cache, only when we do a full redisplay
1061 and not too often either. */
1062 if (clear_face_cache_count > 1000)
1064 clear_face_cache ();
1065 clear_face_cache_count = 0;
1067 #endif
1069 /* Recompute # windows showing selected buffer.
1070 This will be incremented each time such a window is displayed. */
1071 buffer_shared = 0;
1073 FOR_EACH_FRAME (tail, frame)
1075 FRAME_PTR f = XFRAME (frame);
1076 if (! FRAME_TERMCAP_P (f) || f == selected_frame)
1079 /* Mark all the scroll bars to be removed; we'll redeem the ones
1080 we want when we redisplay their windows. */
1081 if (condemn_scroll_bars_hook)
1082 (*condemn_scroll_bars_hook) (f);
1084 if (FRAME_VISIBLE_P (f))
1085 redisplay_windows (FRAME_ROOT_WINDOW (f), preserve_echo_area);
1087 /* Any scroll bars which redisplay_windows should have nuked
1088 should now go away. */
1089 if (judge_scroll_bars_hook)
1090 (*judge_scroll_bars_hook) (f);
1094 else if (FRAME_VISIBLE_P (selected_frame))
1096 redisplay_window (selected_window, 1, preserve_echo_area);
1097 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
1098 preserve_other_columns (w);
1101 update:
1102 /* Prevent various kinds of signals during display update.
1103 stdio is not robust about handling signals,
1104 which can cause an apparent I/O error. */
1105 if (interrupt_input)
1106 unrequest_sigio ();
1107 stop_polling ();
1109 #ifdef MULTI_FRAME
1110 if (all_windows)
1112 Lisp_Object tail;
1114 pause = 0;
1116 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
1118 FRAME_PTR f;
1120 if (!FRAMEP (XCONS (tail)->car))
1121 continue;
1123 f = XFRAME (XCONS (tail)->car);
1125 if ((! FRAME_TERMCAP_P (f) || f == selected_frame)
1126 && FRAME_VISIBLE_P (f))
1128 pause |= update_frame (f, 0, 0);
1129 if (!pause)
1131 mark_window_display_accurate (f->root_window, 1);
1132 if (frame_up_to_date_hook != 0)
1133 (*frame_up_to_date_hook) (f);
1138 else
1139 #endif /* MULTI_FRAME */
1141 if (FRAME_VISIBLE_P (selected_frame))
1142 pause = update_frame (selected_frame, 0, 0);
1143 else
1144 pause = 0;
1146 /* We may have called echo_area_display at the top of this
1147 function. If the echo area is on another frame, that may
1148 have put text on a frame other than the selected one, so the
1149 above call to update_frame would not have caught it. Catch
1150 it here. */
1152 Lisp_Object mini_window;
1153 FRAME_PTR mini_frame;
1155 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
1156 mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
1158 if (mini_frame != selected_frame
1159 && ! FRAME_TERMCAP_P (mini_frame))
1160 pause |= update_frame (mini_frame, 0, 0);
1164 /* If frame does not match, prevent doing single-line-update next time.
1165 Also, don't forget to check every line to update the arrow. */
1166 if (pause)
1168 this_line_bufpos = 0;
1169 if (!NILP (last_arrow_position))
1171 last_arrow_position = Qt;
1172 last_arrow_string = Qt;
1174 /* If we pause after scrolling, some lines in current_frame
1175 may be null, so preserve_other_columns won't be able to
1176 preserve all the vertical-bar separators. So, avoid using it
1177 in that case. */
1178 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
1179 update_mode_lines = 1;
1182 /* Now text on frame agrees with windows, so
1183 put info into the windows for partial redisplay to follow */
1185 if (!pause)
1187 register struct buffer *b = XBUFFER (w->buffer);
1189 blank_end_of_window = 0;
1190 unchanged_modified = BUF_MODIFF (b);
1191 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1192 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1194 XSETFASTINT (w->last_point, BUF_PT (b));
1195 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1196 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1198 if (all_windows)
1199 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1200 else
1202 b->clip_changed = 0;
1203 w->update_mode_line = Qnil;
1204 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1205 w->window_end_valid = w->buffer;
1206 last_arrow_position = Voverlay_arrow_position;
1207 last_arrow_string = Voverlay_arrow_string;
1208 if (do_verify_charstarts)
1209 verify_charstarts (w);
1210 if (frame_up_to_date_hook != 0)
1211 (*frame_up_to_date_hook) (selected_frame);
1213 update_mode_lines = 0;
1214 windows_or_buffers_changed = 0;
1217 /* Start SIGIO interrupts coming again.
1218 Having them off during the code above
1219 makes it less likely one will discard output,
1220 but not impossible, since there might be stuff
1221 in the system buffer here.
1222 But it is much hairier to try to do anything about that. */
1224 if (interrupt_input)
1225 request_sigio ();
1226 start_polling ();
1228 /* Change frame size now if a change is pending. */
1229 do_pending_window_change ();
1231 /* If we just did a pending size change, redisplay again
1232 for the new size. */
1233 if (windows_or_buffers_changed && !pause)
1234 redisplay ();
1237 /* Redisplay, but leave alone any recent echo area message
1238 unless another message has been requested in its place.
1240 This is useful in situations where you need to redisplay but no
1241 user action has occurred, making it inappropriate for the message
1242 area to be cleared. See tracking_off and
1243 wait_reading_process_input for examples of these situations. */
1245 redisplay_preserve_echo_area ()
1247 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1249 echo_area_glyphs = previous_echo_glyphs;
1250 redisplay_internal (1);
1251 echo_area_glyphs = 0;
1253 else
1254 redisplay_internal (1);
1257 void
1258 mark_window_display_accurate (window, flag)
1259 Lisp_Object window;
1260 int flag;
1262 register struct window *w;
1264 for (;!NILP (window); window = w->next)
1266 if (!WINDOWP (window)) abort ();
1267 w = XWINDOW (window);
1269 if (!NILP (w->buffer))
1271 XSETFASTINT (w->last_modified,
1272 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1274 /* Record if we are showing a region, so can make sure to
1275 update it fully at next redisplay. */
1276 w->region_showing = (!NILP (Vtransient_mark_mode)
1277 && !NILP (XBUFFER (w->buffer)->mark_active)
1278 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1279 : Qnil);
1282 w->window_end_valid = w->buffer;
1283 w->update_mode_line = Qnil;
1284 if (!NILP (w->buffer) && flag)
1285 XBUFFER (w->buffer)->clip_changed = 0;
1287 if (!NILP (w->vchild))
1288 mark_window_display_accurate (w->vchild, flag);
1289 if (!NILP (w->hchild))
1290 mark_window_display_accurate (w->hchild, flag);
1293 if (flag)
1295 last_arrow_position = Voverlay_arrow_position;
1296 last_arrow_string = Voverlay_arrow_string;
1298 else
1300 /* t is unequal to any useful value of Voverlay_arrow_... */
1301 last_arrow_position = Qt;
1302 last_arrow_string = Qt;
1306 /* Update the menu bar item list for frame F.
1307 This has to be done before we start to fill in any display lines,
1308 because it can call eval.
1310 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1312 static void
1313 update_menu_bar (f, save_match_data)
1314 FRAME_PTR f;
1315 int save_match_data;
1317 struct buffer *old = current_buffer;
1318 Lisp_Object window;
1319 register struct window *w;
1321 window = FRAME_SELECTED_WINDOW (f);
1322 w = XWINDOW (window);
1324 if (update_mode_lines)
1325 w->update_mode_line = Qt;
1327 if (FRAME_WINDOW_P (f)
1329 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1330 FRAME_EXTERNAL_MENU_BAR (f)
1331 #else
1332 FRAME_MENU_BAR_LINES (f) > 0
1333 #endif
1334 : FRAME_MENU_BAR_LINES (f) > 0)
1336 /* If the user has switched buffers or windows, we need to
1337 recompute to reflect the new bindings. But we'll
1338 recompute when update_mode_lines is set too; that means
1339 that people can use force-mode-line-update to request
1340 that the menu bar be recomputed. The adverse effect on
1341 the rest of the redisplay algorithm is about the same as
1342 windows_or_buffers_changed anyway. */
1343 if (windows_or_buffers_changed
1344 || !NILP (w->update_mode_line)
1345 || (XFASTINT (w->last_modified) < MODIFF
1346 && (XFASTINT (w->last_modified)
1347 <= BUF_SAVE_MODIFF (XBUFFER (w->buffer))))
1348 || ((!NILP (Vtransient_mark_mode)
1349 && !NILP (XBUFFER (w->buffer)->mark_active))
1350 != !NILP (w->region_showing)))
1352 struct buffer *prev = current_buffer;
1353 int count = specpdl_ptr - specpdl;
1355 set_buffer_internal_1 (XBUFFER (w->buffer));
1356 if (save_match_data)
1357 record_unwind_protect (Fstore_match_data, Fmatch_data ());
1358 if (NILP (Voverriding_local_map_menu_flag))
1360 specbind (Qoverriding_terminal_local_map, Qnil);
1361 specbind (Qoverriding_local_map, Qnil);
1364 /* Run the Lucid hook. */
1365 call1 (Vrun_hooks, Qactivate_menubar_hook);
1366 /* If it has changed current-menubar from previous value,
1367 really recompute the menubar from the value. */
1368 if (! NILP (Vlucid_menu_bar_dirty_flag))
1369 call0 (Qrecompute_lucid_menubar);
1370 safe_run_hooks (Qmenu_bar_update_hook);
1371 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1372 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1373 if (FRAME_WINDOW_P (f))
1374 set_frame_menubar (f, 0, 0);
1375 #endif /* USE_X_TOOLKIT || HAVE_NTGUI */
1377 unbind_to (count, Qnil);
1378 set_buffer_internal_1 (prev);
1383 int do_id = 1;
1385 /* Redisplay WINDOW and its subwindows and siblings. */
1387 static void
1388 redisplay_windows (window, preserve_echo_area)
1389 Lisp_Object window;
1390 int preserve_echo_area;
1392 for (; !NILP (window); window = XWINDOW (window)->next)
1393 redisplay_window (window, 0, preserve_echo_area);
1396 /* Redisplay window WINDOW and its subwindows. */
1398 static void
1399 redisplay_window (window, just_this_one, preserve_echo_area)
1400 Lisp_Object window;
1401 int just_this_one, preserve_echo_area;
1403 register struct window *w = XWINDOW (window);
1404 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1405 int height;
1406 register int lpoint = PT;
1407 struct buffer *old = current_buffer;
1408 register int width = window_internal_width (w) - 1;
1409 register int startp;
1410 register int hscroll = XINT (w->hscroll);
1411 struct position pos;
1412 int opoint = PT;
1413 int tem;
1414 int update_mode_line;
1415 struct Lisp_Char_Table *dp = window_display_table (w);
1417 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1419 /* If this is a combination window, do its children; that's all. */
1421 if (!NILP (w->vchild))
1423 redisplay_windows (w->vchild, preserve_echo_area);
1424 return;
1426 if (!NILP (w->hchild))
1428 redisplay_windows (w->hchild, preserve_echo_area);
1429 return;
1431 if (NILP (w->buffer))
1432 abort ();
1434 height = window_internal_height (w);
1435 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1436 if (XBUFFER (w->buffer)->clip_changed)
1437 update_mode_line = 1;
1439 if (MINI_WINDOW_P (w))
1441 if (w == XWINDOW (echo_area_window) && echo_area_glyphs)
1442 /* We've already displayed the echo area glyphs in this window. */
1443 goto finish_scroll_bars;
1444 else if (w != XWINDOW (minibuf_window))
1446 /* This is a minibuffer, but it's not the currently active one,
1447 so clear it. */
1448 int vpos = XFASTINT (w->top);
1449 int i;
1451 for (i = 0; i < height; i++)
1453 get_display_line (f, vpos + i, 0);
1454 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
1457 goto finish_scroll_bars;
1461 /* Otherwise set up data on this window; select its buffer and point value */
1463 if (update_mode_line)
1464 set_buffer_internal_1 (XBUFFER (w->buffer));
1465 else
1466 set_buffer_temp (XBUFFER (w->buffer));
1468 opoint = PT;
1470 /* If %c is in mode line, update it if needed. */
1471 if (!NILP (w->column_number_displayed)
1472 /* This alternative quickly identifies a common case
1473 where no change is needed. */
1474 && !(PT == XFASTINT (w->last_point)
1475 && XFASTINT (w->last_modified) >= MODIFF)
1476 && XFASTINT (w->column_number_displayed) != current_column ())
1477 update_mode_line = 1;
1479 /* Count number of windows showing the selected buffer.
1480 An indirect buffer counts as its base buffer. */
1482 if (!just_this_one)
1484 struct buffer *current_base, *window_base;
1485 current_base = current_buffer;
1486 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1487 if (current_base->base_buffer)
1488 current_base = current_base->base_buffer;
1489 if (window_base->base_buffer)
1490 window_base = window_base->base_buffer;
1491 if (current_base == window_base)
1492 buffer_shared++;
1495 /* POINT refers normally to the selected window.
1496 For any other window, set up appropriate value. */
1498 if (!EQ (window, selected_window))
1500 int new_pt = marker_position (w->pointm);
1501 if (new_pt < BEGV)
1503 new_pt = BEGV;
1504 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1506 else if (new_pt > (ZV - 1))
1508 new_pt = ZV;
1509 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1511 /* We don't use SET_PT so that the point-motion hooks don't run. */
1512 BUF_PT (current_buffer) = new_pt;
1515 /* If any of the character widths specified in the display table
1516 have changed, invalidate the width run cache. It's true that this
1517 may be a bit late to catch such changes, but the rest of
1518 redisplay goes (non-fatally) haywire when the display table is
1519 changed, so why should we worry about doing any better? */
1520 if (current_buffer->width_run_cache)
1522 struct Lisp_Char_Table *disptab = buffer_display_table ();
1524 if (! disptab_matches_widthtab (disptab,
1525 XVECTOR (current_buffer->width_table)))
1527 invalidate_region_cache (current_buffer,
1528 current_buffer->width_run_cache,
1529 BEG, Z);
1530 recompute_width_table (current_buffer, disptab);
1534 /* If window-start is screwed up, choose a new one. */
1535 if (XMARKER (w->start)->buffer != current_buffer)
1536 goto recenter;
1538 startp = marker_position (w->start);
1540 /* Handle case where place to start displaying has been specified,
1541 unless the specified location is outside the accessible range. */
1542 if (!NILP (w->force_start))
1544 w->force_start = Qnil;
1545 /* Forget any recorded base line for line number display. */
1546 w->base_line_number = Qnil;
1547 /* Redisplay the mode line. Select the buffer properly for that.
1548 Also, run the hook window-scroll-functions
1549 because we have scrolled. */
1550 /* Note, we do this after clearing force_start because
1551 if there's an error, it is better to forget about force_start
1552 than to get into an infinite loop calling the hook functions
1553 and having them get more errors. */
1554 if (!update_mode_line
1555 || ! NILP (Vwindow_scroll_functions))
1557 Lisp_Object temp[3];
1559 set_buffer_temp (old);
1560 set_buffer_internal_1 (XBUFFER (w->buffer));
1561 update_mode_line = 1;
1562 w->update_mode_line = Qt;
1563 if (! NILP (Vwindow_scroll_functions))
1565 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1566 make_number (startp));
1567 startp = marker_position (w->start);
1570 XSETFASTINT (w->last_modified, 0);
1571 if (startp < BEGV) startp = BEGV;
1572 if (startp > ZV) startp = ZV;
1573 try_window (window, startp);
1574 if (cursor_vpos < 0)
1576 /* If point does not appear, move point so it does appear */
1577 pos = *compute_motion (startp, 0,
1578 (((EQ (window, minibuf_window)
1579 && startp == BEG)
1580 ? minibuf_prompt_width : 0)
1581 + (hscroll ? 1 - hscroll : 0)),
1583 ZV, height / 2,
1584 - (1 << (BITS_PER_SHORT - 1)),
1585 width, hscroll, pos_tab_offset (w, startp), w);
1586 BUF_PT (current_buffer) = pos.bufpos;
1587 if (w != XWINDOW (selected_window))
1588 Fset_marker (w->pointm, make_number (PT), Qnil);
1589 else
1591 if (current_buffer == old)
1592 lpoint = PT;
1593 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1594 + minmax (0, pos.hpos, width));
1595 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1597 /* If we are highlighting the region,
1598 then we just changed the region, so redisplay to show it. */
1599 if (!NILP (Vtransient_mark_mode)
1600 && !NILP (current_buffer->mark_active))
1602 cancel_my_columns (XWINDOW (window));
1603 try_window (window, startp);
1606 goto done;
1609 /* Handle case where text has not changed, only point,
1610 and it has not moved off the frame. */
1612 /* This code is not used for minibuffer for the sake of
1613 the case of redisplaying to replace an echo area message;
1614 since in that case the minibuffer contents per se are usually unchanged.
1615 This code is of no real use in the minibuffer since
1616 the handling of this_line_bufpos, etc.,
1617 in redisplay handles the same cases. */
1619 if (XFASTINT (w->last_modified) >= MODIFF
1620 && PT >= startp && !current_buffer->clip_changed
1621 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
1622 /* If force-mode-line-update was called, really redisplay;
1623 that's how redisplay is forced after e.g. changing
1624 buffer-invisibility-spec. */
1625 && NILP (w->update_mode_line)
1626 /* Can't use this case if highlighting a region. */
1627 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1628 && NILP (w->region_showing)
1629 /* If end pos is out of date, scroll bar and percentage will be wrong */
1630 && INTEGERP (w->window_end_vpos)
1631 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1632 && !EQ (window, minibuf_window))
1634 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0,
1635 PT, height, 0, width, hscroll,
1636 pos_tab_offset (w, startp), w);
1638 if (pos.vpos < height)
1640 /* Ok, point is still on frame */
1641 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1643 /* These variables are supposed to be origin 1 */
1644 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1645 + minmax (0, pos.hpos, width));
1646 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1648 /* This doesn't do the trick, because if a window to the right of
1649 this one must be redisplayed, this does nothing because there
1650 is nothing in DesiredFrame yet, and then the other window is
1651 redisplayed, making likes that are empty in this window's columns.
1652 if (XFASTINT (w->width) != FRAME_WIDTH (f))
1653 preserve_my_columns (w);
1655 goto done;
1657 /* Don't bother trying redisplay with same start;
1658 we already know it will lose */
1660 /* If current starting point was originally the beginning of a line
1661 but no longer is, find a new starting point. */
1662 else if (!NILP (w->start_at_line_beg)
1663 && !(startp <= BEGV
1664 || FETCH_CHAR (startp - 1) == '\n'))
1666 goto recenter;
1668 else if (just_this_one && !MINI_WINDOW_P (w)
1669 && PT >= startp
1670 && XFASTINT (w->last_modified)
1671 /* or else vmotion on first line won't work. */
1672 && ! NILP (w->start_at_line_beg)
1673 && ! EQ (w->window_end_valid, Qnil)
1674 && do_id && !current_buffer->clip_changed
1675 && !blank_end_of_window
1676 && XFASTINT (w->width) == FRAME_WIDTH (f)
1677 /* Can't use this case if highlighting a region. */
1678 && !(!NILP (Vtransient_mark_mode)
1679 && !NILP (current_buffer->mark_active))
1680 /* Don't use try_window_id if newline
1681 doesn't display as the end of a line. */
1682 && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n')))
1683 && NILP (w->region_showing)
1684 && EQ (last_arrow_position, Voverlay_arrow_position)
1685 && EQ (last_arrow_string, Voverlay_arrow_string)
1686 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1687 && tem != -2)
1689 /* tem > 0 means success. tem == -1 means choose new start.
1690 tem == -2 means try again with same start,
1691 and nothing but whitespace follows the changed stuff.
1692 tem == 0 means try again with same start. */
1693 if (tem > 0)
1694 goto done;
1696 else if (startp >= BEGV && startp <= ZV
1697 && (startp < ZV
1698 /* Avoid starting at end of buffer. */
1699 #if 0 /* This change causes trouble for M-! finger & RET.
1700 It will have to be considered later. */
1701 || ! EQ (window, selected_window)
1702 /* Don't do the recentering if redisplay
1703 is not for no user action. */
1704 || preserve_echo_area
1705 #endif
1706 || startp == BEGV
1707 || (XFASTINT (w->last_modified) >= MODIFF)))
1709 /* Try to redisplay starting at same place as before */
1710 /* If point has not moved off frame, accept the results */
1711 try_window (window, startp);
1712 if (cursor_vpos >= 0)
1714 if (!just_this_one || current_buffer->clip_changed
1715 || beg_unchanged < startp)
1716 /* Forget any recorded base line for line number display. */
1717 w->base_line_number = Qnil;
1718 goto done;
1720 else
1721 cancel_my_columns (w);
1724 XSETFASTINT (w->last_modified, 0);
1725 /* Redisplay the mode line. Select the buffer properly for that. */
1726 if (!update_mode_line)
1728 set_buffer_temp (old);
1729 set_buffer_internal_1 (XBUFFER (w->buffer));
1730 update_mode_line = 1;
1731 w->update_mode_line = Qt;
1734 /* Try to scroll by specified few lines */
1736 if (scroll_step && !current_buffer->clip_changed
1737 && startp >= BEGV && startp <= ZV)
1739 if (PT > startp)
1741 pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w);
1742 if (pos.vpos >= height)
1743 goto scroll_fail;
1746 pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w);
1748 if (PT >= pos.bufpos)
1750 if (! NILP (Vwindow_scroll_functions))
1752 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1753 make_number (pos.bufpos));
1754 pos.bufpos = marker_position (w->start);
1756 try_window (window, pos.bufpos);
1757 if (cursor_vpos >= 0)
1759 if (!just_this_one || current_buffer->clip_changed
1760 || beg_unchanged < startp)
1761 /* Forget any recorded base line for line number display. */
1762 w->base_line_number = Qnil;
1763 goto done;
1765 else
1766 cancel_my_columns (w);
1768 scroll_fail: ;
1771 /* Finally, just choose place to start which centers point */
1773 recenter:
1774 /* Forget any previously recorded base line for line number display. */
1775 w->base_line_number = Qnil;
1777 pos = *vmotion (PT, - (height / 2), w);
1778 /* Set startp here explicitly in case that helps avoid an infinite loop
1779 in case the window-scroll-functions functions get errors. */
1780 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
1781 if (! NILP (Vwindow_scroll_functions))
1783 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1784 make_number (pos.bufpos));
1785 pos.bufpos = marker_position (w->start);
1787 try_window (window, pos.bufpos);
1789 startp = marker_position (w->start);
1790 w->start_at_line_beg
1791 = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
1793 done:
1794 if ((update_mode_line
1795 /* If window not full width, must redo its mode line
1796 if the window to its side is being redone */
1797 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
1798 || INTEGERP (w->base_line_pos)
1799 || (!NILP (w->column_number_displayed)
1800 && XFASTINT (w->column_number_displayed) != current_column ()))
1801 && height != XFASTINT (w->height))
1802 display_mode_line (w);
1803 if (! line_number_displayed
1804 && ! BUFFERP (w->base_line_pos))
1806 w->base_line_pos = Qnil;
1807 w->base_line_number = Qnil;
1810 /* When we reach a frame's selected window, redo the frame's menu bar. */
1811 if (update_mode_line
1812 && (FRAME_WINDOW_P (f)
1814 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1815 FRAME_EXTERNAL_MENU_BAR (f)
1816 #else
1817 FRAME_MENU_BAR_LINES (f) > 0
1818 #endif
1819 : FRAME_MENU_BAR_LINES (f) > 0)
1820 && EQ (FRAME_SELECTED_WINDOW (f), window))
1821 display_menu_bar (w);
1823 finish_scroll_bars:
1824 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
1826 int start, end, whole;
1828 /* Calculate the start and end positions for the current window.
1829 At some point, it would be nice to choose between scrollbars
1830 which reflect the whole buffer size, with special markers
1831 indicating narrowing, and scrollbars which reflect only the
1832 visible region.
1834 Note that minibuffers sometimes aren't displaying any text. */
1835 if (! MINI_WINDOW_P (w)
1836 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1838 whole = ZV - BEGV;
1839 start = marker_position (w->start) - BEGV;
1840 /* I don't think this is guaranteed to be right. For the
1841 moment, we'll pretend it is. */
1842 end = (Z - XINT (w->window_end_pos)) - BEGV;
1844 if (end < start) end = start;
1845 if (whole < (end - start)) whole = end - start;
1847 else
1848 start = end = whole = 0;
1850 /* Indicate what this scroll bar ought to be displaying now. */
1851 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
1853 /* Note that we actually used the scroll bar attached to this window,
1854 so it shouldn't be deleted at the end of redisplay. */
1855 (*redeem_scroll_bar_hook) (w);
1858 BUF_PT (current_buffer) = opoint;
1859 if (update_mode_line)
1860 set_buffer_internal_1 (old);
1861 else
1862 set_buffer_temp (old);
1863 BUF_PT (current_buffer) = lpoint;
1866 /* Do full redisplay on one window, starting at position `pos'. */
1868 static void
1869 try_window (window, pos)
1870 Lisp_Object window;
1871 register int pos;
1873 register struct window *w = XWINDOW (window);
1874 register int height = window_internal_height (w);
1875 register int vpos = XFASTINT (w->top);
1876 register int last_text_vpos = vpos;
1877 int tab_offset = pos_tab_offset (w, pos);
1878 FRAME_PTR f = XFRAME (w->frame);
1879 int width = window_internal_width (w) - 1;
1880 struct position val;
1882 Fset_marker (w->start, make_number (pos), Qnil);
1883 cursor_vpos = -1;
1884 overlay_arrow_seen = 0;
1885 zv_strings_seen = 0;
1886 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1888 while (--height >= 0)
1890 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1891 tab_offset += width;
1892 /* For the first line displayed, display_text_line
1893 subtracts the prompt width from the tab offset.
1894 But it does not affect the value of our variable tab_offset.
1895 So we do the subtraction again,
1896 for the sake of continuation lines of that first line. */
1897 if (MINI_WINDOW_P (w) && vpos == XFASTINT (w->top))
1898 tab_offset -= minibuf_prompt_width;
1900 if (val.vpos) tab_offset = 0;
1901 vpos++;
1902 if (pos != val.bufpos)
1904 int invis = 0;
1905 #ifdef USE_TEXT_PROPERTIES
1906 Lisp_Object invis_prop;
1907 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
1908 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
1909 #endif
1911 last_text_vpos
1912 /* Next line, unless prev line ended in end of buffer with no cr */
1913 = vpos - (val.vpos
1914 && (FETCH_CHAR (val.bufpos - 1) != '\n' || invis));
1916 pos = val.bufpos;
1919 /* If last line is continued in middle of character,
1920 include the split character in the text considered on the frame */
1921 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1922 pos++;
1924 /* If bottom just moved off end of frame, change mode line percentage. */
1925 if (XFASTINT (w->window_end_pos) == 0
1926 && Z != pos)
1927 w->update_mode_line = Qt;
1929 /* Say where last char on frame will be, once redisplay is finished. */
1930 XSETFASTINT (w->window_end_pos, Z - pos);
1931 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
1932 /* But that is not valid info until redisplay finishes. */
1933 w->window_end_valid = Qnil;
1936 /* Try to redisplay when buffer is modified locally,
1937 computing insert/delete line to preserve text outside
1938 the bounds of the changes.
1939 Return 1 if successful, 0 if if cannot tell what to do,
1940 or -1 to tell caller to find a new window start,
1941 or -2 to tell caller to do normal redisplay with same window start. */
1943 static int
1944 try_window_id (window)
1945 Lisp_Object window;
1947 int pos;
1948 register struct window *w = XWINDOW (window);
1949 register int height = window_internal_height (w);
1950 FRAME_PTR f = XFRAME (w->frame);
1951 int top = XFASTINT (w->top);
1952 int start = marker_position (w->start);
1953 int width = window_internal_width (w) - 1;
1954 int hscroll = XINT (w->hscroll);
1955 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
1956 int did_motion;
1957 register int vpos;
1958 register int i, tem;
1959 int last_text_vpos = 0;
1960 int stop_vpos;
1961 int selective = (INTEGERP (current_buffer->selective_display)
1962 ? XINT (current_buffer->selective_display)
1963 : !NILP (current_buffer->selective_display) ? -1 : 0);
1965 struct position val, bp, ep, xp, pp;
1966 int scroll_amount = 0;
1967 int delta;
1968 int tab_offset, epto, old_tick;
1970 if (GPT - BEG < beg_unchanged)
1971 beg_unchanged = GPT - BEG;
1972 if (Z - GPT < end_unchanged)
1973 end_unchanged = Z - GPT;
1975 if (beg_unchanged + BEG < start)
1976 return 0; /* Give up if changes go above top of window */
1978 /* Find position before which nothing is changed. */
1979 bp = *compute_motion (start, 0, lmargin, 0,
1980 min (ZV, beg_unchanged + BEG), height, 0,
1981 width, hscroll, pos_tab_offset (w, start), w);
1982 if (bp.vpos >= height)
1984 if (PT < bp.bufpos)
1986 /* All changes are beyond the window end, and point is on the screen.
1987 We don't need to change the text at all.
1988 But we need to update window_end_pos to account for
1989 any change in buffer size. */
1990 bp = *compute_motion (start, 0, lmargin, 0,
1991 ZV, height, 0,
1992 width, hscroll, pos_tab_offset (w, start), w);
1993 XSETFASTINT (w->window_end_vpos, height);
1994 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
1995 goto findpoint;
1997 return 0;
2000 vpos = bp.vpos;
2002 /* Find beginning of that frame line. Must display from there. */
2003 bp = *vmotion (bp.bufpos, 0, w);
2005 pos = bp.bufpos;
2006 val.hpos = lmargin;
2007 if (pos < start)
2008 return -1;
2010 did_motion = 0;
2011 /* If about to start displaying at the beginning of a continuation line,
2012 really start with previous frame line, in case it was not
2013 continued when last redisplayed */
2014 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
2016 /* Likewise if we have to worry about selective display. */
2017 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
2019 bp = *vmotion (bp.bufpos, -1, w);
2020 --vpos;
2021 pos = bp.bufpos;
2024 if (bp.contin && bp.hpos != lmargin)
2026 val.hpos = bp.prevhpos - width + lmargin;
2027 did_motion = 1;
2028 pos--;
2031 bp.vpos = vpos;
2033 /* Find first visible newline after which no more is changed. */
2034 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
2035 if (selective > 0)
2036 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
2037 tem = find_next_newline (tem, 1);
2039 /* Compute the cursor position after that newline. */
2040 ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem,
2041 height, - (1 << (BITS_PER_SHORT - 1)),
2042 width, hscroll, pos_tab_offset (w, bp.bufpos), w);
2044 /* If changes reach past the text available on the frame,
2045 just display rest of frame. */
2046 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
2047 stop_vpos = height;
2048 else
2049 stop_vpos = ep.vpos;
2051 /* If no newline before ep, the line ep is on includes some changes
2052 that must be displayed. Make sure we don't stop before it. */
2053 /* Also, if changes reach all the way until ep.bufpos,
2054 it is possible that something was deleted after the
2055 newline before it, so the following line must be redrawn. */
2056 if (stop_vpos == ep.vpos
2057 && (ep.bufpos == BEGV
2058 || FETCH_CHAR (ep.bufpos - 1) != '\n'
2059 || ep.bufpos == Z - end_unchanged))
2060 stop_vpos = ep.vpos + 1;
2062 cursor_vpos = -1;
2063 overlay_arrow_seen = 0;
2064 zv_strings_seen = 0;
2066 /* If changes do not reach to bottom of window,
2067 figure out how much to scroll the rest of the window */
2068 if (stop_vpos < height)
2070 /* Now determine how far up or down the rest of the window has moved */
2071 epto = pos_tab_offset (w, ep.bufpos);
2072 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2073 Z - XFASTINT (w->window_end_pos),
2074 10000, 0, width, hscroll, epto, w);
2075 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
2077 /* Is everything on frame below the changes whitespace?
2078 If so, no scrolling is really necessary. */
2079 for (i = ep.bufpos; i < xp.bufpos; i++)
2081 tem = FETCH_CHAR (i);
2082 if (tem != ' ' && tem != '\n' && tem != '\t')
2083 break;
2085 if (i == xp.bufpos)
2086 return -2;
2088 XSETFASTINT (w->window_end_vpos,
2089 XFASTINT (w->window_end_vpos) + scroll_amount);
2091 /* Before doing any scrolling, verify that point will be on frame. */
2092 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height))
2094 if (PT <= xp.bufpos)
2096 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2097 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2098 width, hscroll, epto, w);
2100 else
2102 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1,
2103 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2104 width, hscroll,
2105 pos_tab_offset (w, xp.bufpos), w);
2107 if (pp.bufpos < PT || pp.vpos == height)
2108 return 0;
2109 cursor_vpos = pp.vpos + top;
2110 cursor_hpos = XFASTINT (w->left) + minmax (0, pp.hpos, width);
2113 if (stop_vpos - scroll_amount >= height
2114 || ep.bufpos == xp.bufpos)
2116 if (scroll_amount < 0)
2117 stop_vpos -= scroll_amount;
2118 scroll_amount = 0;
2119 /* In this path, we have altered window_end_vpos
2120 and not left it negative.
2121 We must make sure that, in case display is preempted
2122 before the frame changes to reflect what we do here,
2123 further updates will not come to try_window_id
2124 and assume the frame and window_end_vpos match. */
2125 blank_end_of_window = 1;
2127 else if (!scroll_amount)
2129 /* Even if we don't need to scroll, we must adjust the
2130 charstarts of subsequent lines (that we won't redisplay)
2131 according to the amount of text inserted or deleted. */
2132 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2133 int adjust = ep.bufpos - oldpos;
2134 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
2136 else if (bp.bufpos == Z - end_unchanged)
2138 /* If reprinting everything is nearly as fast as scrolling,
2139 don't bother scrolling. Can happen if lines are short. */
2140 if (scroll_cost (f, bp.vpos + top - scroll_amount,
2141 top + height - max (0, scroll_amount),
2142 scroll_amount)
2143 > xp.bufpos - bp.bufpos - 20)
2144 /* Return "try normal display with same window-start."
2145 Too bad we can't prevent further scroll-thinking. */
2146 return -2;
2147 /* If pure deletion, scroll up as many lines as possible.
2148 In common case of killing a line, this can save the
2149 following line from being overwritten by scrolling
2150 and therefore having to be redrawn. */
2151 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
2152 top + height - max (0, scroll_amount),
2153 scroll_amount, bp.bufpos);
2154 if (!tem)
2155 stop_vpos = height;
2156 else
2158 /* scroll_frame_lines did not properly adjust subsequent
2159 lines' charstarts in the case where the text of the
2160 screen line at bp.vpos has changed.
2161 (This can happen in a deletion that ends in mid-line.)
2162 To adjust properly, we need to make things consistent
2163 at the position ep.
2164 So do a second adjust to make that happen.
2165 Note that stop_vpos >= ep.vpos, so it is sufficient
2166 to update the charstarts for lines at ep.vpos and below. */
2167 int oldstart
2168 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2169 adjust_window_charstarts (w, ep.vpos + top - 1,
2170 ep.bufpos - oldstart);
2173 else if (scroll_amount)
2175 /* If reprinting everything is nearly as fast as scrolling,
2176 don't bother scrolling. Can happen if lines are short. */
2177 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2178 overestimate of cost of reprinting, since xp.bufpos
2179 would end up below the bottom of the window. */
2180 if (scroll_cost (f, ep.vpos + top - scroll_amount,
2181 top + height - max (0, scroll_amount),
2182 scroll_amount)
2183 > xp.bufpos - ep.bufpos - 20)
2184 /* Return "try normal display with same window-start."
2185 Too bad we can't prevent further scroll-thinking. */
2186 return -2;
2187 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
2188 top + height - max (0, scroll_amount),
2189 scroll_amount, ep.bufpos);
2190 if (!tem) stop_vpos = height;
2194 /* In any case, do not display past bottom of window */
2195 if (stop_vpos >= height)
2197 stop_vpos = height;
2198 scroll_amount = 0;
2201 /* Handle case where pos is before w->start --
2202 can happen if part of line had been clipped and is not clipped now */
2203 if (vpos == 0 && pos < marker_position (w->start))
2204 Fset_marker (w->start, make_number (pos), Qnil);
2206 /* Redisplay the lines where the text was changed */
2207 last_text_vpos = vpos;
2208 tab_offset = pos_tab_offset (w, pos);
2209 /* If we are starting display in mid-character, correct tab_offset
2210 to account for passing the line that that character really starts in. */
2211 if (val.hpos < lmargin)
2212 tab_offset += width;
2213 old_tick = MODIFF;
2214 while (vpos < stop_vpos)
2216 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2217 /* If display_text_line ran a hook and changed some text,
2218 redisplay all the way to bottom of buffer
2219 So that we show the changes. */
2220 if (old_tick != MODIFF)
2221 stop_vpos = height;
2222 tab_offset += width;
2223 if (val.vpos) tab_offset = 0;
2224 if (pos != val.bufpos)
2225 last_text_vpos
2226 /* Next line, unless prev line ended in end of buffer with no cr */
2227 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
2228 pos = val.bufpos;
2231 /* There are two cases:
2232 1) we have displayed down to the bottom of the window
2233 2) we have scrolled lines below stop_vpos by scroll_amount */
2235 if (vpos == height)
2237 /* If last line is continued in middle of character,
2238 include the split character in the text considered on the frame */
2239 if (val.hpos < lmargin)
2240 val.bufpos++;
2241 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2242 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2245 /* If scrolling made blank lines at window bottom,
2246 redisplay to fill those lines */
2247 if (scroll_amount < 0)
2249 /* Don't consider these lines for general-purpose scrolling.
2250 That will save time in the scrolling computation. */
2251 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2252 vpos = xp.vpos;
2253 pos = xp.bufpos;
2254 val.hpos = lmargin;
2255 if (pos == ZV)
2256 vpos = height + scroll_amount;
2257 else if (xp.contin && xp.hpos != lmargin)
2259 val.hpos = xp.prevhpos - width + lmargin;
2260 pos--;
2263 blank_end_of_window = 1;
2264 tab_offset = pos_tab_offset (w, pos);
2265 /* If we are starting display in mid-character, correct tab_offset
2266 to account for passing the line that that character starts in. */
2267 if (val.hpos < lmargin)
2268 tab_offset += width;
2270 while (vpos < height)
2272 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2273 tab_offset += width;
2274 if (val.vpos) tab_offset = 0;
2275 pos = val.bufpos;
2278 /* Here is a case where display_text_line sets cursor_vpos wrong.
2279 Make it be fixed up, below. */
2280 if (xp.bufpos == ZV
2281 && xp.bufpos == PT)
2282 cursor_vpos = -1;
2285 /* If bottom just moved off end of frame, change mode line percentage. */
2286 if (XFASTINT (w->window_end_pos) == 0
2287 && Z != val.bufpos)
2288 w->update_mode_line = Qt;
2290 /* Attempt to adjust end-of-text positions to new bottom line */
2291 if (scroll_amount)
2293 delta = height - xp.vpos;
2294 if (delta < 0
2295 || (delta > 0 && xp.bufpos <= ZV)
2296 || (delta == 0 && xp.hpos))
2298 val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w);
2299 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2300 XSETFASTINT (w->window_end_vpos,
2301 XFASTINT (w->window_end_vpos) + val.vpos);
2305 w->window_end_valid = Qnil;
2307 /* If point was not in a line that was displayed, find it */
2308 if (cursor_vpos < 0)
2310 findpoint:
2311 val = *compute_motion (start, 0, lmargin, 0, PT, 10000, 10000,
2312 width, hscroll, pos_tab_offset (w, start), w);
2313 /* Admit failure if point is off frame now */
2314 if (val.vpos >= height)
2316 for (vpos = 0; vpos < height; vpos++)
2317 cancel_line (vpos + top, f);
2318 return 0;
2320 cursor_vpos = val.vpos + top;
2321 cursor_hpos = XFASTINT (w->left) + minmax (0, val.hpos, width);
2324 FRAME_CURSOR_X (f) = cursor_hpos;
2325 FRAME_CURSOR_Y (f) = cursor_vpos;
2327 if (debug_end_pos)
2329 val = *compute_motion (start, 0, lmargin, 0, ZV,
2330 height, - (1 << (BITS_PER_SHORT - 1)),
2331 width, hscroll, pos_tab_offset (w, start), w);
2332 if (val.vpos != XFASTINT (w->window_end_vpos))
2333 abort ();
2334 if (XFASTINT (w->window_end_pos)
2335 != Z - val.bufpos)
2336 abort ();
2339 return 1;
2342 /* Mark a section of BUF as modified, but only for the sake of redisplay.
2343 This is useful for recording changes to overlays.
2345 We increment the buffer's modification timestamp and set the
2346 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
2347 as if the region of text between START and END had been modified;
2348 the redisplay code will check this against the windows' timestamps,
2349 and redraw the appropriate area of the buffer.
2351 However, if the buffer is unmodified, we bump the last-save
2352 timestamp as well, so that incrementing the timestamp doesn't fool
2353 Emacs into thinking that the buffer's text has been modified.
2355 Tweaking the timestamps shouldn't hurt the first-modification
2356 timestamps recorded in the undo records; those values aren't
2357 written until just before a real text modification is made, so they
2358 will never catch the timestamp value just before this function gets
2359 called. */
2361 void
2362 redisplay_region (buf, start, end)
2363 struct buffer *buf;
2364 int start, end;
2366 if (start == end)
2367 return;
2369 if (start > end)
2371 int temp = start;
2372 start = end; end = temp;
2375 /* If this is a buffer not in the selected window,
2376 we must do other windows. */
2377 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2378 windows_or_buffers_changed = 1;
2379 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2380 else if (buf != current_buffer)
2381 windows_or_buffers_changed = 1;
2382 /* If multiple windows show this buffer, we must do other windows. */
2383 else if (buffer_shared > 1)
2384 windows_or_buffers_changed = 1;
2385 else
2387 if (unchanged_modified == MODIFF)
2389 beg_unchanged = start - BEG;
2390 end_unchanged = Z - end;
2392 else
2394 if (Z - end < end_unchanged)
2395 end_unchanged = Z - end;
2396 if (start - BEG < beg_unchanged)
2397 beg_unchanged = start - BEG;
2401 /* Increment the buffer's time stamp, but also increment the save
2402 and autosave timestamps, so as not to screw up that timekeeping. */
2403 if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf))
2404 BUF_SAVE_MODIFF (buf)++;
2405 if (BUF_MODIFF (buf) == buf->auto_save_modified)
2406 buf->auto_save_modified++;
2408 BUF_MODIFF (buf) ++;
2412 /* Copy LEN glyphs starting address FROM to the rope TO.
2413 But don't actually copy the parts that would come in before S.
2414 Value is TO, advanced past the copied data.
2415 F is the frame we are displaying in. */
2417 static GLYPH *
2418 copy_part_of_rope (f, to, s, from, len, face)
2419 FRAME_PTR f;
2420 register GLYPH *to; /* Copy to here. */
2421 register GLYPH *s; /* Starting point. */
2422 Lisp_Object *from; /* Data to copy. */
2423 int len;
2424 int face; /* Face to apply to glyphs which don't specify one. */
2426 int n = len;
2427 register Lisp_Object *fp = from;
2428 /* These cache the results of the last call to compute_glyph_face. */
2429 int last_code = -1;
2430 int last_merged = 0;
2432 #ifdef HAVE_FACES
2433 if (! FRAME_TERMCAP_P (f))
2434 while (n--)
2436 int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2437 int facecode;
2439 if (FAST_GLYPH_FACE (glyph) == 0)
2440 /* If GLYPH has no face code, use FACE. */
2441 facecode = face;
2442 else if (FAST_GLYPH_FACE (glyph) == last_code)
2443 /* If it's same as previous glyph, use same result. */
2444 facecode = last_merged;
2445 else
2447 /* Merge this glyph's face and remember the result. */
2448 last_code = FAST_GLYPH_FACE (glyph);
2449 last_merged = facecode = compute_glyph_face (f, last_code, face);
2452 if (to >= s)
2453 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
2454 ++to;
2455 ++fp;
2457 else
2458 #endif
2459 while (n--)
2461 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2462 ++to;
2463 ++fp;
2465 return to;
2468 /* Correct a glyph by replacing its specified user-level face code
2469 with a displayable computed face code. */
2471 static GLYPH
2472 fix_glyph (f, glyph, cface)
2473 FRAME_PTR f;
2474 GLYPH glyph;
2475 int cface;
2477 #ifdef HAVE_FACES
2478 if (! FRAME_TERMCAP_P (f))
2480 if (FAST_GLYPH_FACE (glyph) != 0)
2481 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2482 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2484 #endif
2485 return glyph;
2488 /* Display one line of window W, starting at position START in W's buffer.
2490 Display starting at horizontal position HPOS, expressed relative to
2491 W's left edge. In situations where the text at START shouldn't
2492 start at the left margin (i.e. when the window is hscrolled, or
2493 we're continuing a line which left off in the midst of a
2494 multi-column character), HPOS should be negative; we throw away
2495 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2496 account.
2498 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2500 Display on position VPOS on the frame. It is origin 0, relative to
2501 the top of the frame, not W.
2503 Returns a STRUCT POSITION giving character to start next line with
2504 and where to display it, including a zero or negative hpos.
2505 The vpos field is not really a vpos; it is 1 unless the line is continued */
2507 struct position val_display_text_line;
2509 static struct position *
2510 display_text_line (w, start, vpos, hpos, taboffset)
2511 struct window *w;
2512 int start;
2513 int vpos;
2514 int hpos;
2515 int taboffset;
2517 register int pos = start;
2518 register int c;
2519 register GLYPH *p1;
2520 register int pause;
2521 register unsigned char *p;
2522 GLYPH *endp;
2523 register GLYPH *leftmargin;
2524 register GLYPH *p1prev;
2525 register GLYPH *p1start;
2526 int prevpos;
2527 int *charstart;
2528 FRAME_PTR f = XFRAME (w->frame);
2529 int tab_width = XINT (current_buffer->tab_width);
2530 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2531 int width = window_internal_width (w) - 1;
2532 struct position val;
2533 int lastpos;
2534 int invis;
2535 int last_invis_skip = 0;
2536 Lisp_Object last_invis_prop;
2537 int hscroll = XINT (w->hscroll);
2538 int truncate = (hscroll
2539 || (truncate_partial_width_windows
2540 && XFASTINT (w->width) < FRAME_WIDTH (f))
2541 || !NILP (current_buffer->truncate_lines));
2543 /* 1 if we should highlight the region. */
2544 int highlight_region
2545 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
2546 int region_beg, region_end;
2548 int selective = (INTEGERP (current_buffer->selective_display)
2549 ? XINT (current_buffer->selective_display)
2550 : !NILP (current_buffer->selective_display) ? -1 : 0);
2551 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2552 register struct Lisp_Char_Table *dp = window_display_table (w);
2554 Lisp_Object default_invis_vector[3];
2555 /* Number of characters of ellipsis to display after an invisible line
2556 if it calls for an ellipsis.
2557 Note that this value can be nonzero regardless of whether
2558 selective display is enabled--you must check that separately. */
2559 int selective_rlen
2560 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2561 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2562 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
2563 /* This is the sequence of Lisp objects to display
2564 when there are invisible lines. */
2565 Lisp_Object *invis_vector_contents
2566 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2567 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2568 : default_invis_vector);
2570 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2571 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2572 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2573 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2575 /* The next buffer location at which the face should change, due
2576 to overlays or text property changes. */
2577 int next_face_change;
2579 /* The next location where the `invisible' property changes, or an
2580 overlay starts or ends. */
2581 int next_boundary;
2583 /* The face we're currently using. */
2584 int current_face = 0;
2585 int i;
2587 XSETFASTINT (default_invis_vector[2], '.');
2588 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2590 hpos += XFASTINT (w->left);
2591 get_display_line (f, vpos, XFASTINT (w->left));
2592 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2594 /* Show where to highlight the region. */
2595 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2596 /* Maybe highlight only in selected window. */
2597 && (highlight_nonselected_windows
2598 || w == XWINDOW (selected_window)))
2600 region_beg = marker_position (current_buffer->mark);
2601 if (PT < region_beg)
2603 region_end = region_beg;
2604 region_beg = PT;
2606 else
2607 region_end = PT;
2608 w->region_showing = Qt;
2610 else
2611 region_beg = region_end = -1;
2613 if (MINI_WINDOW_P (w)
2614 && start == BEG
2615 && vpos == XFASTINT (w->top))
2617 if (! NILP (minibuf_prompt))
2619 minibuf_prompt_width
2620 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2621 XSTRING (minibuf_prompt)->size, hpos,
2622 /* Display a space if we truncate. */
2623 ' ',
2624 1, -1,
2625 /* Truncate the prompt a little before the
2626 margin, so user input can at least start
2627 on the first line. */
2628 w->width > 10 ? w->width - 4 : -1)
2629 - hpos);
2630 hpos += minibuf_prompt_width;
2631 taboffset -= minibuf_prompt_width;
2633 else
2634 minibuf_prompt_width = 0;
2637 /* If we're hscrolled at all, use compute_motion to skip over any
2638 text off the left edge of the window. compute_motion may know
2639 tricks to do this faster than we can. */
2640 if (hpos < 0)
2642 struct position *left_edge
2643 = compute_motion (pos, vpos, hpos, 0,
2644 ZV, vpos, 0,
2645 width, hscroll, taboffset, w);
2647 /* Retrieve the buffer position and column provided by
2648 compute_motion. We can't assume that the column will be
2649 zero, because you may have multi-column characters crossing
2650 the left margin.
2652 compute_motion may have moved us past the screen position we
2653 requested, if we hit a multi-column character, or the end of
2654 the line. If so, back up. */
2655 if (left_edge->vpos > vpos
2656 || left_edge->hpos > 0)
2658 pos = left_edge->bufpos - 1;
2659 hpos = left_edge->prevhpos;
2661 else
2663 pos = left_edge->bufpos;
2664 hpos = left_edge->hpos;
2668 desired_glyphs->bufp[vpos] = start;
2669 p1 = desired_glyphs->glyphs[vpos] + hpos;
2670 p1start = p1;
2671 charstart = desired_glyphs->charstarts[vpos] + hpos;
2672 /* In case we don't ever write anything into it... */
2673 desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1;
2674 leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2675 endp = leftmargin + width;
2677 /* Arrange the overlays nicely for our purposes. Usually, we call
2678 display_text_line on only one line at a time, in which case this
2679 can't really hurt too much, or we call it on lines which appear
2680 one after another in the buffer, in which case all calls to
2681 recenter_overlay_lists but the first will be pretty cheap. */
2682 recenter_overlay_lists (current_buffer, pos);
2684 /* Loop generating characters.
2685 Stop at end of buffer, before newline,
2686 if reach or pass continuation column,
2687 or at face change. */
2688 pause = pos;
2689 next_face_change = pos;
2690 next_boundary = pos;
2691 p1prev = p1;
2692 prevpos = pos;
2693 while (1)
2695 if (pos >= pause)
2697 int e_t_h;
2699 while (pos == next_boundary)
2701 Lisp_Object position, limit, prop, ww;
2703 /* Display the overlay strings here, unless we're at ZV
2704 and have already displayed the appropriate strings
2705 on an earlier line. */
2706 if (pos < ZV || !zv_strings_seen++)
2708 int ovlen;
2709 char *ovstr;
2710 ovlen = overlay_strings (pos, w, &ovstr);
2711 for (; ovlen; ovlen--, ovstr++)
2713 if (p1 >= leftmargin && p1 < endp)
2714 *p1 = MAKE_GLYPH (f, *ovstr, current_face);
2715 p1++;
2719 /* Did we reach point? Record the cursor location. */
2720 if (pos == PT && cursor_vpos < 0)
2722 cursor_vpos = vpos;
2723 cursor_hpos = p1 - leftmargin;
2726 if (pos >= ZV)
2727 break;
2729 XSETFASTINT (position, pos);
2730 limit = Fnext_overlay_change (position);
2731 #ifdef USE_TEXT_PROPERTIES
2732 /* This is just an estimate to give reasonable
2733 performance; nothing should go wrong if it is too small. */
2734 if (XFASTINT (limit) > pos + 50)
2735 XSETFASTINT (limit, pos + 50);
2736 limit = Fnext_single_property_change (position, Qinvisible,
2737 Fcurrent_buffer (), limit);
2738 #endif
2739 next_boundary = XFASTINT (limit);
2740 /* if the `invisible' property is set, we can skip to
2741 the next property change. */
2742 XSETWINDOW (ww, w);
2743 prop = Fget_char_property (position, Qinvisible, ww);
2744 if (TEXT_PROP_MEANS_INVISIBLE (prop))
2746 if (pos < PT && next_boundary >= PT)
2748 cursor_vpos = vpos;
2749 cursor_hpos = p1 - leftmargin;
2751 pos = next_boundary;
2752 last_invis_skip = pos;
2753 last_invis_prop = prop;
2757 /* Did we reach point? Record the cursor location. */
2758 if (pos == PT && cursor_vpos < 0)
2760 cursor_vpos = vpos;
2761 cursor_hpos = p1 - leftmargin;
2764 /* Did we hit the end of the visible region of the buffer?
2765 Stop here. */
2766 if (pos >= ZV)
2768 /* Update charstarts for the end of this line. */
2769 /* Do nothing if off the left edge or at the right edge. */
2770 if (p1 >= leftmargin && p1 + 1 != endp)
2772 int *p2x = &charstart[(p1 < leftmargin
2773 ? leftmargin : p1)
2774 - p1start];
2775 *p2x++ = pos;
2777 break;
2780 /* Figure out where (if at all) the
2781 redisplay_end_trigger-hook should run. */
2782 if (MARKERP (w->redisplay_end_trigger)
2783 && XMARKER (w->redisplay_end_trigger)->buffer != 0)
2784 e_t_h = marker_position (w->redisplay_end_trigger);
2785 else if (INTEGERP (w->redisplay_end_trigger))
2786 e_t_h = XINT (w->redisplay_end_trigger);
2787 else
2788 e_t_h = ZV;
2790 /* If we've gone past the place to run a hook,
2791 run the hook. */
2792 if (pos >= e_t_h && e_t_h != ZV)
2794 Lisp_Object args[3];
2796 args[0] = Qredisplay_end_trigger_functions;
2797 XSETWINDOW (args[1], w);
2798 XSETINT (args[2], e_t_h);
2800 /* Since we are *trying* to run these functions,
2801 don't try to run them again, even if they get an error. */
2802 w->redisplay_end_trigger = Qnil;
2803 Frun_hook_with_args (3, args);
2805 e_t_h = ZV;
2806 /* Notice if it changed the face of this character. */
2807 next_face_change = pos;
2810 #ifdef HAVE_FACES
2811 /* Did we hit a face change? Figure out what face we should
2812 use now. We also hit this the first time through the
2813 loop, to see what face we should start with. */
2814 if (pos >= next_face_change && (FRAME_WINDOW_P (f)))
2815 current_face = compute_char_face (f, w, pos,
2816 region_beg, region_end,
2817 &next_face_change, pos + 50, 0);
2818 #endif
2820 /* Compute the next place we need to stop
2821 and do something special; set PAUSE. */
2823 pause = ZV;
2825 if (pos < next_boundary && next_boundary < pause)
2826 pause = next_boundary;
2827 if (pos < next_face_change && next_face_change < pause)
2828 pause = next_face_change;
2830 if (e_t_h < pause)
2831 pause = e_t_h;
2833 /* Wouldn't you hate to read the next line to someone over
2834 the phone? */
2835 if (pos < PT && PT < pause)
2836 pause = PT;
2837 if (pos < GPT && GPT < pause)
2838 pause = GPT;
2840 p = &FETCH_CHAR (pos);
2843 if (p1 >= endp)
2844 break;
2846 p1prev = p1;
2848 c = *p++;
2849 /* Let a display table override all standard display methods. */
2850 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
2852 p1 = copy_part_of_rope (f, p1, leftmargin,
2853 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2854 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2855 current_face);
2857 else if (c >= 040 && c < 0177)
2859 if (p1 >= leftmargin)
2860 *p1 = MAKE_GLYPH (f, c, current_face);
2861 p1++;
2863 else if (c == '\n')
2865 invis = 0;
2866 if (last_invis_skip == pos
2867 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
2868 invis = 1;
2869 while (pos + 1 < ZV
2870 && selective > 0
2871 && indented_beyond_p (pos + 1, selective))
2873 invis = 1;
2874 pos = find_next_newline (pos + 1, 1);
2875 if (FETCH_CHAR (pos - 1) == '\n')
2876 pos--;
2878 if (invis && selective_rlen > 0 && p1 >= leftmargin)
2880 p1 += selective_rlen;
2881 if (p1 - leftmargin > width)
2882 p1 = endp;
2883 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2884 (p1 - p1prev), current_face);
2886 #ifdef HAVE_FACES
2887 /* Draw the face of the newline character as extending all the
2888 way to the end of the frame line. */
2889 if (current_face)
2891 if (p1 < leftmargin)
2892 p1 = leftmargin;
2893 while (p1 < endp)
2894 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2896 #endif
2898 /* Update charstarts for the newline that ended this line. */
2899 /* Do nothing here for a char that's entirely off the left edge
2900 or if it starts at the right edge. */
2901 if (p1 >= leftmargin && p1prev != endp)
2903 /* Store the newline's position into charstarts
2904 for the column where the newline starts.
2905 Store -1 for the rest of the glyphs it occupies. */
2906 int *p2x = &charstart[(p1prev < leftmargin
2907 ? leftmargin : p1prev)
2908 - p1start];
2909 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2911 *p2x++ = pos;
2912 while (p2x < p2)
2913 *p2x++ = -1;
2916 break;
2918 else if (c == '\t')
2922 if (p1 >= leftmargin && p1 < endp)
2923 *p1 = MAKE_GLYPH (f, ' ', current_face);
2924 p1++;
2926 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
2927 % tab_width);
2929 else if (c == Ctl ('M') && selective == -1)
2931 pos = find_next_newline (pos, 1);
2932 if (FETCH_CHAR (pos - 1) == '\n')
2933 pos--;
2934 if (selective_rlen > 0)
2936 p1 += selective_rlen;
2937 if (p1 - leftmargin > width)
2938 p1 = endp;
2939 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2940 (p1 - p1prev), current_face);
2942 #ifdef HAVE_FACES
2943 /* Draw the face of the newline character as extending all the
2944 way to the end of the frame line. */
2945 if (current_face)
2947 if (p1 < leftmargin)
2948 p1 = leftmargin;
2949 while (p1 < endp)
2950 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2952 #endif
2954 /* Update charstarts for the ^M that ended this line. */
2955 /* Do nothing here for a char that's entirely off the left edge
2956 or if it starts at the right edge. */
2957 if (p1 >= leftmargin && p1prev != endp)
2959 /* Store the newline's position into charstarts
2960 for the column where the newline starts.
2961 Store -1 for the rest of the glyphs it occupies. */
2962 int *p2x = &charstart[(p1prev < leftmargin
2963 ? leftmargin : p1prev)
2964 - p1start];
2965 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2967 *p2x++ = pos;
2968 while (p2x < p2)
2969 *p2x++ = -1;
2971 break;
2973 else if (c < 0200 && ctl_arrow)
2975 if (p1 >= leftmargin)
2976 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
2977 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
2978 current_face);
2979 p1++;
2980 if (p1 >= leftmargin && p1 < endp)
2981 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
2982 p1++;
2984 else
2986 if (p1 >= leftmargin)
2987 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
2988 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
2989 current_face);
2990 p1++;
2991 if (p1 >= leftmargin && p1 < endp)
2992 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
2993 p1++;
2994 if (p1 >= leftmargin && p1 < endp)
2995 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
2996 p1++;
2997 if (p1 >= leftmargin && p1 < endp)
2998 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
2999 p1++;
3002 prevpos = pos;
3003 pos++;
3005 /* Update charstarts for the character just output. */
3007 /* Do nothing here for a char that's entirely off the left edge. */
3008 if (p1 >= leftmargin)
3010 /* Store the char's position into charstarts
3011 for the first glyph occupied by this char.
3012 Store -1 for the rest of the glyphs it occupies. */
3013 if (p1 != p1prev)
3015 int *p2x = &charstart[(p1prev < leftmargin
3016 ? leftmargin : p1prev)
3017 - p1start];
3018 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3020 if (p2x < p2)
3021 *p2x++ = prevpos;
3022 while (p2x < p2)
3023 *p2x++ = -1;
3028 val.hpos = - XINT (w->hscroll);
3029 if (val.hpos)
3030 val.hpos++;
3032 val.vpos = 1;
3034 lastpos = pos;
3036 /* Store 0 in this charstart line for the positions where
3037 there is no character. But do leave what was recorded
3038 for the character that ended the line. */
3039 /* Add 1 in the endtest to compensate for the fact that ENDP was
3040 made from WIDTH, which is 1 less than the window's actual
3041 internal width. */
3042 i = p1 - p1start + 1;
3043 if (p1 < leftmargin)
3044 i += leftmargin - p1;
3045 for (; i < endp - p1start + 1; i++)
3046 charstart[i] = 0;
3048 /* Handle continuation in middle of a character */
3049 /* by backing up over it */
3050 if (p1 > endp)
3052 /* Don't back up if we never actually displayed any text.
3053 This occurs when the minibuffer prompt takes up the whole line. */
3054 if (p1prev)
3056 /* Start the next line with that same character */
3057 pos--;
3058 /* but at negative hpos, to skip the columns output on this line. */
3059 val.hpos += p1prev - endp;
3062 /* Keep in this line everything up to the continuation column. */
3063 p1 = endp;
3066 /* Finish deciding which character to start the next line on,
3067 and what hpos to start it at.
3068 Also set `lastpos' to the last position which counts as "on this line"
3069 for cursor-positioning. */
3071 if (pos < ZV)
3073 if (FETCH_CHAR (pos) == '\n')
3075 /* If stopped due to a newline, start next line after it */
3076 pos++;
3077 /* Check again for hidden lines, in case the newline occurred exactly
3078 at the right margin. */
3079 while (pos < ZV && selective > 0
3080 && indented_beyond_p (pos, selective))
3081 pos = find_next_newline (pos, 1);
3083 else
3084 /* Stopped due to right margin of window */
3086 if (truncate)
3088 *p1++ = fix_glyph (f, truncator, 0);
3089 /* Truncating => start next line after next newline,
3090 and point is on this line if it is before the newline,
3091 and skip none of first char of next line */
3093 pos = find_next_newline (pos, 1);
3094 while (pos < ZV && selective > 0
3095 && indented_beyond_p (pos, selective));
3096 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
3098 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
3100 else
3102 *p1++ = fix_glyph (f, continuer, 0);
3103 val.vpos = 0;
3104 lastpos--;
3109 /* If point is at eol or in invisible text at eol,
3110 record its frame location now. */
3112 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
3114 cursor_vpos = vpos;
3115 cursor_hpos = p1 - leftmargin;
3118 if (cursor_vpos == vpos)
3120 if (cursor_hpos < 0) cursor_hpos = 0;
3121 if (cursor_hpos > width) cursor_hpos = width;
3122 cursor_hpos += XFASTINT (w->left);
3123 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
3125 if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f)
3126 && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window)))
3128 FRAME_CURSOR_Y (f) = cursor_vpos;
3129 FRAME_CURSOR_X (f) = cursor_hpos;
3132 if (w == XWINDOW (selected_window))
3134 /* Line is not continued and did not start
3135 in middle of character */
3136 if ((hpos - XFASTINT (w->left)
3137 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
3138 && val.vpos)
3140 this_line_bufpos = start;
3141 this_line_buffer = current_buffer;
3142 this_line_vpos = cursor_vpos;
3143 this_line_start_hpos = hpos;
3144 this_line_endpos = Z - lastpos;
3146 else
3147 this_line_bufpos = 0;
3152 /* If hscroll and line not empty, insert truncation-at-left marker */
3153 if (hscroll && lastpos != start)
3155 *leftmargin = fix_glyph (f, truncator, 0);
3156 if (p1 <= leftmargin)
3157 p1 = leftmargin + 1;
3160 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
3162 endp++;
3163 if (p1 < leftmargin) p1 = leftmargin;
3164 while (p1 < endp) *p1++ = SPACEGLYPH;
3166 /* Don't draw vertical bars if we're using scroll bars. They're
3167 covered up by the scroll bars, and it's distracting to see
3168 them when the scroll bar windows are flickering around to be
3169 reconfigured. */
3170 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3172 int i;
3173 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3174 *p1++ = SPACEGLYPH;
3176 else
3177 *p1++ = (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
3178 ? DISP_BORDER_GLYPH (dp)
3179 : '|');
3181 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
3182 p1 - desired_glyphs->glyphs[vpos]);
3183 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3185 /* If the start of this line is the overlay arrow-position,
3186 then put the arrow string into the display-line. */
3188 if (MARKERP (Voverlay_arrow_position)
3189 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
3190 && start == marker_position (Voverlay_arrow_position)
3191 && STRINGP (Voverlay_arrow_string)
3192 && ! overlay_arrow_seen)
3194 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
3195 int i;
3196 int len = XSTRING (Voverlay_arrow_string)->size;
3197 int arrow_end;
3199 if (len > width)
3200 len = width;
3201 #ifdef HAVE_FACES
3202 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
3204 /* If the arrow string has text props, obey them when displaying. */
3205 for (i = 0; i < len; i++)
3207 int c = p[i];
3208 Lisp_Object face, ilisp;
3209 int newface;
3211 XSETFASTINT (ilisp, i);
3212 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
3213 newface = compute_glyph_face_1 (f, face, 0);
3214 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
3217 else
3218 #endif /* HAVE_FACES */
3220 for (i = 0; i < len; i++)
3221 leftmargin[i] = p[i];
3224 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3225 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
3226 if (desired_glyphs->used[vpos] < arrow_end)
3227 desired_glyphs->used[vpos] = arrow_end;
3229 overlay_arrow_seen = 1;
3232 val.bufpos = pos;
3233 val_display_text_line = val;
3234 return &val_display_text_line;
3237 /* Redisplay the menu bar in the frame for window W. */
3239 static void
3240 display_menu_bar (w)
3241 struct window *w;
3243 Lisp_Object items, tail;
3244 register int vpos = 0;
3245 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3246 int maxendcol = FRAME_WIDTH (f);
3247 int hpos = 0;
3248 int i;
3250 #ifdef HAVE_NTGUI
3251 return;
3252 #endif
3254 #ifdef USE_X_TOOLKIT
3255 if (FRAME_X_P (f))
3256 return;
3257 #endif /* USE_X_TOOLKIT */
3259 get_display_line (f, vpos, 0);
3261 items = FRAME_MENU_BAR_ITEMS (f);
3262 for (i = 0; i < XVECTOR (items)->size; i += 3)
3264 Lisp_Object pos, string;
3265 string = XVECTOR (items)->contents[i + 1];
3266 if (NILP (string))
3267 break;
3269 XSETFASTINT (XVECTOR (items)->contents[i + 2], hpos);
3271 if (hpos < maxendcol)
3272 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
3273 XSTRING (string)->data,
3274 XSTRING (string)->size,
3275 hpos, 0, 0, hpos, maxendcol);
3276 /* Put a space between items. */
3277 if (hpos < maxendcol)
3279 int hpos1 = hpos + 1;
3280 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
3281 min (hpos1, maxendcol), maxendcol);
3285 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3286 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3288 /* Fill out the line with spaces. */
3289 if (maxendcol > hpos)
3290 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
3292 /* Clear the rest of the lines allocated to the menu bar. */
3293 vpos++;
3294 while (vpos < FRAME_MENU_BAR_LINES (f))
3295 get_display_line (f, vpos++, 0);
3298 /* Display the mode line for window w */
3300 static void
3301 display_mode_line (w)
3302 struct window *w;
3304 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
3305 register int left = XFASTINT (w->left);
3306 register int right = XFASTINT (w->width) + left;
3307 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3309 line_number_displayed = 0;
3310 w->column_number_displayed = Qnil;
3312 get_display_line (f, vpos, left);
3314 /* Temporarily make frame F's kboard the current kboard
3315 so that kboard-local variables in the mode_line_format
3316 will get the right values. */
3317 push_frame_kboard (f);
3319 display_mode_element (w, vpos, left, 0, right, right,
3320 current_buffer->mode_line_format);
3322 pop_frame_kboard ();
3324 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3326 /* Make the mode line inverse video if the entire line
3327 is made of mode lines.
3328 I.e. if this window is full width,
3329 or if it is the child of a full width window
3330 (which implies that that window is split side-by-side
3331 and the rest of this line is mode lines of the sibling windows). */
3332 if (XFASTINT (w->width) == FRAME_WIDTH (f)
3333 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
3334 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3335 #ifdef HAVE_FACES
3336 else if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video)
3338 /* For a partial width window, explicitly set face of each glyph. */
3339 int i;
3340 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3341 for (i = left; i < right; ++i)
3342 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
3344 #endif
3347 /* Contribute ELT to the mode line for window W.
3348 How it translates into text depends on its data type.
3350 VPOS is the position of the mode line being displayed.
3352 HPOS is the position (absolute on frame) where this element's text
3353 should start. The output is truncated automatically at the right
3354 edge of window W.
3356 DEPTH is the depth in recursion. It is used to prevent
3357 infinite recursion here.
3359 MINENDCOL is the hpos before which the element may not end.
3360 The element is padded at the right with spaces if nec
3361 to reach this column.
3363 MAXENDCOL is the hpos past which this element may not extend.
3364 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3365 (This is necessary to make nested padding and truncation work.)
3367 Returns the hpos of the end of the text generated by ELT.
3368 The next element will receive that value as its HPOS arg,
3369 so as to concatenate the elements. */
3371 static int
3372 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3373 struct window *w;
3374 register int vpos, hpos;
3375 int depth;
3376 int minendcol;
3377 register int maxendcol;
3378 register Lisp_Object elt;
3380 tail_recurse:
3381 if (depth > 10)
3382 goto invalid;
3384 depth++;
3386 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3388 case Lisp_String:
3390 /* A string: output it and check for %-constructs within it. */
3391 register unsigned char c;
3392 register unsigned char *this = XSTRING (elt)->data;
3394 while (hpos < maxendcol && *this)
3396 unsigned char *last = this;
3397 while ((c = *this++) != '\0' && c != '%')
3399 if (this - 1 != last)
3401 register int lim = --this - last + hpos;
3402 if (frame_title_ptr)
3403 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3404 else
3405 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3406 hpos, min (lim, maxendcol));
3408 else /* c == '%' */
3410 register int minendcol;
3411 register int spec_width = 0;
3413 /* We can't allow -ve args due to the "%-" construct */
3414 /* Argument specifies minwidth but not maxwidth
3415 (maxwidth can be specified by
3416 (<negative-number> . <stuff>) mode-line elements) */
3418 while ((c = *this++) >= '0' && c <= '9')
3420 spec_width = spec_width * 10 + (c - '0');
3423 minendcol = hpos + spec_width;
3424 if (minendcol > maxendcol)
3426 spec_width = maxendcol - hpos;
3427 minendcol = maxendcol;
3430 if (c == 'M')
3431 hpos = display_mode_element (w, vpos, hpos, depth,
3432 spec_width, maxendcol,
3433 Vglobal_mode_string);
3434 else if (c != 0)
3436 char *spec = decode_mode_spec (w, c, spec_width,
3437 maxendcol - hpos);
3438 if (frame_title_ptr)
3439 hpos = store_frame_title (spec, minendcol, maxendcol);
3440 else
3441 hpos = display_string (w, vpos, spec, -1,
3442 hpos, 0, 1,
3443 minendcol, maxendcol);
3448 break;
3450 case Lisp_Symbol:
3451 /* A symbol: process the value of the symbol recursively
3452 as if it appeared here directly. Avoid error if symbol void.
3453 Special case: if value of symbol is a string, output the string
3454 literally. */
3456 register Lisp_Object tem;
3457 tem = Fboundp (elt);
3458 if (!NILP (tem))
3460 tem = Fsymbol_value (elt);
3461 /* If value is a string, output that string literally:
3462 don't check for % within it. */
3463 if (STRINGP (tem))
3465 if (frame_title_ptr)
3466 hpos = store_frame_title (XSTRING (tem)->data,
3467 minendcol, maxendcol);
3468 else
3469 hpos = display_string (w, vpos, XSTRING (tem)->data,
3470 XSTRING (tem)->size,
3471 hpos, 0, 1, minendcol, maxendcol);
3473 /* Give up right away for nil or t. */
3474 else if (!EQ (tem, elt))
3475 { elt = tem; goto tail_recurse; }
3478 break;
3480 case Lisp_Cons:
3482 register Lisp_Object car, tem;
3484 /* A cons cell: three distinct cases.
3485 If first element is a string or a cons, process all the elements
3486 and effectively concatenate them.
3487 If first element is a negative number, truncate displaying cdr to
3488 at most that many characters. If positive, pad (with spaces)
3489 to at least that many characters.
3490 If first element is a symbol, process the cadr or caddr recursively
3491 according to whether the symbol's value is non-nil or nil. */
3492 car = XCONS (elt)->car;
3493 if (SYMBOLP (car))
3495 tem = Fboundp (car);
3496 elt = XCONS (elt)->cdr;
3497 if (!CONSP (elt))
3498 goto invalid;
3499 /* elt is now the cdr, and we know it is a cons cell.
3500 Use its car if CAR has a non-nil value. */
3501 if (!NILP (tem))
3503 tem = Fsymbol_value (car);
3504 if (!NILP (tem))
3505 { elt = XCONS (elt)->car; goto tail_recurse; }
3507 /* Symbol's value is nil (or symbol is unbound)
3508 Get the cddr of the original list
3509 and if possible find the caddr and use that. */
3510 elt = XCONS (elt)->cdr;
3511 if (NILP (elt))
3512 break;
3513 else if (!CONSP (elt))
3514 goto invalid;
3515 elt = XCONS (elt)->car;
3516 goto tail_recurse;
3518 else if (INTEGERP (car))
3520 register int lim = XINT (car);
3521 elt = XCONS (elt)->cdr;
3522 if (lim < 0)
3523 /* Negative int means reduce maximum width.
3524 DO NOT change MINENDCOL here!
3525 (20 -10 . foo) should truncate foo to 10 col
3526 and then pad to 20. */
3527 maxendcol = min (maxendcol, hpos - lim);
3528 else if (lim > 0)
3530 /* Padding specified. Don't let it be more than
3531 current maximum. */
3532 lim += hpos;
3533 if (lim > maxendcol)
3534 lim = maxendcol;
3535 /* If that's more padding than already wanted, queue it.
3536 But don't reduce padding already specified even if
3537 that is beyond the current truncation point. */
3538 if (lim > minendcol)
3539 minendcol = lim;
3541 goto tail_recurse;
3543 else if (STRINGP (car) || CONSP (car))
3545 register int limit = 50;
3546 /* LIMIT is to protect against circular lists. */
3547 while (CONSP (elt) && --limit > 0
3548 && hpos < maxendcol)
3550 hpos = display_mode_element (w, vpos, hpos, depth,
3551 hpos, maxendcol,
3552 XCONS (elt)->car);
3553 elt = XCONS (elt)->cdr;
3557 break;
3559 default:
3560 invalid:
3561 if (frame_title_ptr)
3562 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3563 else
3564 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3565 minendcol, maxendcol);
3566 return hpos;
3569 if (minendcol > hpos)
3570 if (frame_title_ptr)
3571 hpos = store_frame_title ("", minendcol, maxendcol);
3572 else
3573 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
3574 return hpos;
3577 /* Write a null-terminated, right justified decimal representation of
3578 the positive integer D to BUF using a minimal field width WIDTH. */
3580 static void
3581 pint2str (buf, width, d)
3582 register char *buf;
3583 register int width;
3584 register int d;
3586 register char *p = buf;
3588 if (d <= 0)
3589 *p++ = '0';
3590 else
3591 while (d > 0)
3593 *p++ = d % 10 + '0';
3594 d /= 10;
3596 for (width -= (int) (p - buf); width > 0; --width) *p++ = ' ';
3597 *p-- = '\0';
3598 while (p > buf)
3600 d = *buf;
3601 *buf++ = *p;
3602 *p-- = d;
3606 /* Return a string for the output of a mode line %-spec for window W,
3607 generated by character C. SPEC_WIDTH is the field width when
3608 padding to the left (%c, %l). The value returned from this
3609 function will later be truncated to width MAXWIDTH. */
3611 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3613 static char *
3614 decode_mode_spec (w, c, spec_width, maxwidth)
3615 struct window *w;
3616 register char c;
3617 register int spec_width;
3618 register int maxwidth;
3620 Lisp_Object obj;
3621 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3622 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
3623 struct buffer *b = XBUFFER (w->buffer);
3625 obj = Qnil;
3626 if (maxwidth > FRAME_WIDTH (f))
3627 maxwidth = FRAME_WIDTH (f);
3629 switch (c)
3631 case '*':
3632 if (!NILP (b->read_only))
3633 return "%";
3634 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3635 return "*";
3636 return "-";
3638 case '+':
3639 /* This differs from %* only for a modified read-only buffer. */
3640 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3641 return "*";
3642 if (!NILP (b->read_only))
3643 return "%";
3644 return "-";
3646 case '&':
3647 /* This differs from %* in ignoring read-only-ness. */
3648 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3649 return "*";
3650 return "-";
3652 case '%':
3653 return "%";
3655 case '[':
3657 int i;
3658 char *p;
3660 if (command_loop_level > 5)
3661 return "[[[... ";
3662 p = decode_mode_spec_buf;
3663 for (i = 0; i < command_loop_level; i++)
3664 *p++ = '[';
3665 *p = 0;
3666 return decode_mode_spec_buf;
3669 case ']':
3671 int i;
3672 char *p;
3674 if (command_loop_level > 5)
3675 return " ...]]]";
3676 p = decode_mode_spec_buf;
3677 for (i = 0; i < command_loop_level; i++)
3678 *p++ = ']';
3679 *p = 0;
3680 return decode_mode_spec_buf;
3683 case '-':
3685 register char *p;
3686 register int i;
3688 if (maxwidth < sizeof (lots_of_dashes))
3689 return lots_of_dashes;
3690 else
3692 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3693 *p++ = '-';
3694 *p = '\0';
3696 return decode_mode_spec_buf;
3699 case 'b':
3700 obj = b->name;
3701 #if 0
3702 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
3704 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
3705 decode_mode_spec_buf[maxwidth - 1] = '\\';
3706 decode_mode_spec_buf[maxwidth] = '\0';
3707 return decode_mode_spec_buf;
3709 #endif
3710 break;
3712 case 'c':
3714 int col = current_column ();
3715 XSETFASTINT (w->column_number_displayed, col);
3716 pint2str (decode_mode_spec_buf, spec_width, col);
3717 return decode_mode_spec_buf;
3720 case 'F':
3721 /* %F displays the frame name. */
3722 #ifdef MULTI_FRAME
3723 if (!NILP (selected_frame->title))
3724 return (char *) XSTRING (selected_frame->title)->data;
3725 return (char *) XSTRING (selected_frame->name)->data;
3726 #else
3727 return "Emacs";
3728 #endif
3730 case 'f':
3731 obj = b->filename;
3732 #if 0
3733 if (NILP (obj))
3734 return "[none]";
3735 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
3737 bcopy ("...", decode_mode_spec_buf, 3);
3738 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
3739 decode_mode_spec_buf + 3, maxwidth - 3);
3740 return decode_mode_spec_buf;
3742 #endif
3743 break;
3745 case 'l':
3747 int startpos = marker_position (w->start);
3748 int line, linepos, topline;
3749 int nlines, junk;
3750 Lisp_Object tem;
3751 int height = XFASTINT (w->height);
3753 /* If we decided that this buffer isn't suitable for line numbers,
3754 don't forget that too fast. */
3755 if (EQ (w->base_line_pos, w->buffer))
3756 goto no_value;
3758 /* If the buffer is very big, don't waste time. */
3759 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
3761 w->base_line_pos = Qnil;
3762 w->base_line_number = Qnil;
3763 goto no_value;
3766 if (!NILP (w->base_line_number)
3767 && !NILP (w->base_line_pos)
3768 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
3770 line = XFASTINT (w->base_line_number);
3771 linepos = XFASTINT (w->base_line_pos);
3773 else
3775 line = 1;
3776 linepos = BUF_BEGV (b);
3779 /* Count lines from base line to window start position. */
3780 nlines = display_count_lines (linepos, startpos, startpos, &junk);
3782 topline = nlines + line;
3784 /* Determine a new base line, if the old one is too close
3785 or too far away, or if we did not have one.
3786 "Too close" means it's plausible a scroll-down would
3787 go back past it. */
3788 if (startpos == BUF_BEGV (b))
3790 XSETFASTINT (w->base_line_number, topline);
3791 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
3793 else if (nlines < height + 25 || nlines > height * 3 + 50
3794 || linepos == BUF_BEGV (b))
3796 int limit = BUF_BEGV (b);
3797 int position;
3798 int distance = (height * 2 + 30) * 200;
3800 if (startpos - distance > limit)
3801 limit = startpos - distance;
3803 nlines = display_count_lines (startpos, limit,
3804 -(height * 2 + 30),
3805 &position);
3806 /* If we couldn't find the lines we wanted within
3807 200 chars per line,
3808 give up on line numbers for this window. */
3809 if (position == startpos - distance)
3811 w->base_line_pos = w->buffer;
3812 w->base_line_number = Qnil;
3813 goto no_value;
3816 XSETFASTINT (w->base_line_number, topline - nlines);
3817 XSETFASTINT (w->base_line_pos, position);
3820 /* Now count lines from the start pos to point. */
3821 nlines = display_count_lines (startpos, PT, PT, &junk);
3823 /* Record that we did display the line number. */
3824 line_number_displayed = 1;
3826 /* Make the string to show. */
3827 pint2str (decode_mode_spec_buf, spec_width, topline + nlines);
3828 return decode_mode_spec_buf;
3829 no_value:
3831 char* p = decode_mode_spec_buf;
3832 for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' ';
3833 strcpy (p, "??");
3834 return decode_mode_spec_buf;
3837 break;
3839 case 'm':
3840 obj = b->mode_name;
3841 break;
3843 case 'n':
3844 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
3845 return " Narrow";
3846 break;
3848 case 'p':
3850 int pos = marker_position (w->start);
3851 int total = BUF_ZV (b) - BUF_BEGV (b);
3853 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
3855 if (pos <= BUF_BEGV (b))
3856 return "All";
3857 else
3858 return "Bottom";
3860 else if (pos <= BUF_BEGV (b))
3861 return "Top";
3862 else
3864 if (total > 1000000)
3865 /* Do it differently for a large value, to avoid overflow. */
3866 total = ((pos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
3867 else
3868 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
3869 /* We can't normally display a 3-digit number,
3870 so get us a 2-digit number that is close. */
3871 if (total == 100)
3872 total = 99;
3873 sprintf (decode_mode_spec_buf, "%2d%%", total);
3874 return decode_mode_spec_buf;
3878 /* Display percentage of size above the bottom of the screen. */
3879 case 'P':
3881 int toppos = marker_position (w->start);
3882 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
3883 int total = BUF_ZV (b) - BUF_BEGV (b);
3885 if (botpos >= BUF_ZV (b))
3887 if (toppos <= BUF_BEGV (b))
3888 return "All";
3889 else
3890 return "Bottom";
3892 else
3894 if (total > 1000000)
3895 /* Do it differently for a large value, to avoid overflow. */
3896 total = ((botpos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
3897 else
3898 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
3899 /* We can't normally display a 3-digit number,
3900 so get us a 2-digit number that is close. */
3901 if (total == 100)
3902 total = 99;
3903 if (toppos <= BUF_BEGV (b))
3904 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
3905 else
3906 sprintf (decode_mode_spec_buf, "%2d%%", total);
3907 return decode_mode_spec_buf;
3911 case 's':
3912 /* status of process */
3913 obj = Fget_buffer_process (w->buffer);
3914 if (NILP (obj))
3915 return "no process";
3916 #ifdef subprocesses
3917 obj = Fsymbol_name (Fprocess_status (obj));
3918 #endif
3919 break;
3921 case 't': /* indicate TEXT or BINARY */
3922 #ifdef MODE_LINE_BINARY_TEXT
3923 return MODE_LINE_BINARY_TEXT (b);
3924 #else
3925 return "T";
3926 #endif
3929 if (STRINGP (obj))
3930 return (char *) XSTRING (obj)->data;
3931 else
3932 return "";
3935 /* Search for COUNT instances of a line boundary, which means either a
3936 newline or (if selective display enabled) a carriage return.
3937 Start at START. If COUNT is negative, search backwards.
3939 If we find COUNT instances, set *SHORTAGE to zero, and return the
3940 position after the COUNTth match. Note that for reverse motion
3941 this is not the same as the usual convention for Emacs motion commands.
3943 If we don't find COUNT instances before reaching the end of the
3944 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3945 the number of line boundaries left unfound, and return the end of the
3946 buffer we bumped up against. */
3948 static int
3949 display_scan_buffer (start, count, shortage)
3950 int *shortage, start;
3951 register int count;
3953 int limit = ((count > 0) ? ZV - 1 : BEGV);
3954 int direction = ((count > 0) ? 1 : -1);
3956 register unsigned char *cursor;
3957 unsigned char *base;
3959 register int ceiling;
3960 register unsigned char *ceiling_addr;
3962 /* If we are not in selective display mode,
3963 check only for newlines. */
3964 if (! (!NILP (current_buffer->selective_display)
3965 && !INTEGERP (current_buffer->selective_display)))
3966 return scan_buffer ('\n', start, 0, count, shortage, 0);
3968 /* The code that follows is like scan_buffer
3969 but checks for either newline or carriage return. */
3971 if (shortage != 0)
3972 *shortage = 0;
3974 if (count > 0)
3975 while (start != limit + 1)
3977 ceiling = BUFFER_CEILING_OF (start);
3978 ceiling = min (limit, ceiling);
3979 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
3980 base = (cursor = &FETCH_CHAR (start));
3981 while (1)
3983 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
3985 if (cursor != ceiling_addr)
3987 if (--count == 0)
3989 immediate_quit = 0;
3990 return (start + cursor - base + 1);
3992 else
3993 if (++cursor == ceiling_addr)
3994 break;
3996 else
3997 break;
3999 start += cursor - base;
4001 else
4003 start--; /* first character we scan */
4004 while (start > limit - 1)
4005 { /* we WILL scan under start */
4006 ceiling = BUFFER_FLOOR_OF (start);
4007 ceiling = max (limit, ceiling);
4008 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
4009 base = (cursor = &FETCH_CHAR (start));
4010 cursor++;
4011 while (1)
4013 while (--cursor != ceiling_addr
4014 && *cursor != '\n' && *cursor != 015)
4016 if (cursor != ceiling_addr)
4018 if (++count == 0)
4020 immediate_quit = 0;
4021 return (start + cursor - base + 1);
4024 else
4025 break;
4027 start += cursor - base;
4031 if (shortage != 0)
4032 *shortage = count * direction;
4033 return (start + ((direction == 1 ? 0 : 1)));
4036 /* Count up to N lines starting from FROM.
4037 But don't go beyond LIMIT.
4038 Return the number of lines thus found (always positive).
4039 Store the position after what was found into *POS_PTR. */
4041 static int
4042 display_count_lines (from, limit, n, pos_ptr)
4043 int from, limit, n;
4044 int *pos_ptr;
4046 int oldbegv = BEGV;
4047 int oldzv = ZV;
4048 int shortage = 0;
4050 if (limit < from)
4051 BEGV = limit;
4052 else
4053 ZV = limit;
4055 *pos_ptr = display_scan_buffer (from, n, &shortage);
4057 ZV = oldzv;
4058 BEGV = oldbegv;
4060 if (n < 0)
4061 /* When scanning backwards, scan_buffer stops *after* the last newline
4062 it finds, but does count it. Compensate for that. */
4063 return - n - shortage - (*pos_ptr != limit);
4064 return n - shortage;
4067 /* Display STRING on one line of window W, starting at HPOS.
4068 Display at position VPOS. Caller should have done get_display_line.
4069 If VPOS == -1, display it as the current frame's title.
4070 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4072 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4074 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4075 MAXCOL is the last column ok to end at. Truncate here.
4076 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4077 Both count from the left edge of the frame, as does HPOS.
4078 The right edge of W is an implicit maximum.
4079 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4081 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4082 at the place where the current window ends in this line
4083 and not display anything beyond there. Otherwise, only MAXCOL
4084 controls where to stop output.
4086 Returns ending hpos. */
4088 static int
4089 display_string (w, vpos, string, length, hpos, truncate,
4090 obey_window_width, mincol, maxcol)
4091 struct window *w;
4092 unsigned char *string;
4093 int length;
4094 int vpos, hpos;
4095 GLYPH truncate;
4096 int obey_window_width;
4097 int mincol, maxcol;
4099 register int c;
4100 int truncated;
4101 register GLYPH *p1;
4102 int hscroll = XINT (w->hscroll);
4103 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
4104 register GLYPH *start;
4105 register GLYPH *end;
4106 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4107 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
4108 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
4109 int window_width = XFASTINT (w->width);
4111 /* Use the standard display table, not the window's display table.
4112 We don't want the mode line in rot13. */
4113 register struct Lisp_Char_Table *dp = 0;
4114 int i;
4116 if (DISP_TABLE_P (Vstandard_display_table))
4117 dp = XCHAR_TABLE (Vstandard_display_table);
4119 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
4121 p1 = p1start;
4122 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
4124 if (obey_window_width)
4126 end = start + window_width - (truncate != 0);
4128 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
4130 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4132 int i;
4134 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
4135 *end-- = ' ';
4137 else
4138 *end-- = '|';
4142 if (! obey_window_width
4143 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
4144 end = desired_glyphs->glyphs[vpos] + maxcol;
4146 /* Store 0 in charstart for these columns. */
4147 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
4148 desired_glyphs->charstarts[vpos][i] = 0;
4150 if (maxcol >= 0 && mincol > maxcol)
4151 mincol = maxcol;
4153 /* We set truncated to 1 if we get stopped by trying to pass END
4154 (that is, trying to pass MAXCOL.) */
4155 truncated = 0;
4156 while (1)
4158 if (length == 0)
4159 break;
4160 c = *string++;
4161 /* Specified length. */
4162 if (length >= 0)
4163 length--;
4164 /* Unspecified length (null-terminated string). */
4165 else if (c == 0)
4166 break;
4168 if (p1 >= end)
4170 truncated = 1;
4171 break;
4174 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
4176 p1 = copy_part_of_rope (f, p1, start,
4177 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
4178 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
4181 else if (c >= 040 && c < 0177)
4183 if (p1 >= start)
4184 *p1 = c;
4185 p1++;
4187 else if (c == '\t')
4191 if (p1 >= start && p1 < end)
4192 *p1 = SPACEGLYPH;
4193 p1++;
4195 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
4197 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
4199 if (p1 >= start)
4200 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
4201 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
4203 p1++;
4204 if (p1 >= start && p1 < end)
4205 *p1 = c ^ 0100;
4206 p1++;
4208 else
4210 if (p1 >= start)
4211 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
4212 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
4214 p1++;
4215 if (p1 >= start && p1 < end)
4216 *p1 = (c >> 6) + '0';
4217 p1++;
4218 if (p1 >= start && p1 < end)
4219 *p1 = (7 & (c >> 3)) + '0';
4220 p1++;
4221 if (p1 >= start && p1 < end)
4222 *p1 = (7 & c) + '0';
4223 p1++;
4227 if (truncated)
4229 p1 = end;
4230 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
4232 else if (mincol >= 0)
4234 end = desired_glyphs->glyphs[vpos] + mincol;
4235 while (p1 < end)
4236 *p1++ = SPACEGLYPH;
4240 register int len = p1 - desired_glyphs->glyphs[vpos];
4242 if (len > desired_glyphs->used[vpos])
4243 desired_glyphs->used[vpos] = len;
4244 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
4246 return len;
4250 /* This is like a combination of memq and assq.
4251 Return 1 if PROPVAL appears as an element of LIST
4252 or as the car of an element of LIST.
4253 If PROPVAL is a list, compare each element against LIST
4254 in that way, and return 1 if any element of PROPVAL is found in LIST.
4255 Otherwise return 0.
4256 This function cannot quit. */
4259 invisible_p (propval, list)
4260 register Lisp_Object propval;
4261 Lisp_Object list;
4263 register Lisp_Object tail, proptail;
4264 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4266 register Lisp_Object tem;
4267 tem = XCONS (tail)->car;
4268 if (EQ (propval, tem))
4269 return 1;
4270 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4271 return 1;
4273 if (CONSP (propval))
4274 for (proptail = propval; CONSP (proptail);
4275 proptail = XCONS (proptail)->cdr)
4277 Lisp_Object propelt;
4278 propelt = XCONS (proptail)->car;
4279 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4281 register Lisp_Object tem;
4282 tem = XCONS (tail)->car;
4283 if (EQ (propelt, tem))
4284 return 1;
4285 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4286 return 1;
4289 return 0;
4292 /* Return 1 if PROPVAL appears as the car of an element of LIST
4293 and the cdr of that element is non-nil.
4294 If PROPVAL is a list, check each element of PROPVAL in that way,
4295 and the first time some element is found,
4296 return 1 if the cdr of that element is non-nil.
4297 Otherwise return 0.
4298 This function cannot quit. */
4301 invisible_ellipsis_p (propval, list)
4302 register Lisp_Object propval;
4303 Lisp_Object list;
4305 register Lisp_Object tail, proptail;
4306 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4308 register Lisp_Object tem;
4309 tem = XCONS (tail)->car;
4310 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4311 return ! NILP (XCONS (tem)->cdr);
4313 if (CONSP (propval))
4314 for (proptail = propval; CONSP (proptail);
4315 proptail = XCONS (proptail)->cdr)
4317 Lisp_Object propelt;
4318 propelt = XCONS (proptail)->car;
4319 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4321 register Lisp_Object tem;
4322 tem = XCONS (tail)->car;
4323 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4324 return ! NILP (XCONS (tem)->cdr);
4327 return 0;
4330 void
4331 syms_of_xdisp ()
4333 staticpro (&Qmenu_bar_update_hook);
4334 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
4336 staticpro (&Qoverriding_terminal_local_map);
4337 Qoverriding_terminal_local_map = intern ("overriding-terminal-local-map");
4339 staticpro (&Qoverriding_local_map);
4340 Qoverriding_local_map = intern ("overriding-local-map");
4342 staticpro (&Qwindow_scroll_functions);
4343 Qwindow_scroll_functions = intern ("window-scroll-functions");
4345 staticpro (&Qredisplay_end_trigger_functions);
4346 Qredisplay_end_trigger_functions = intern ("redisplay-end-trigger-functions");
4348 staticpro (&last_arrow_position);
4349 staticpro (&last_arrow_string);
4350 last_arrow_position = Qnil;
4351 last_arrow_string = Qnil;
4353 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
4354 "String (or mode line construct) included (normally) in `mode-line-format'.");
4355 Vglobal_mode_string = Qnil;
4357 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
4358 "Marker for where to display an arrow on top of the buffer text.\n\
4359 This must be the beginning of a line in order to work.\n\
4360 See also `overlay-arrow-string'.");
4361 Voverlay_arrow_position = Qnil;
4363 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
4364 "String to display as an arrow. See also `overlay-arrow-position'.");
4365 Voverlay_arrow_string = Qnil;
4367 DEFVAR_INT ("scroll-step", &scroll_step,
4368 "*The number of lines to try scrolling a window by when point moves out.\n\
4369 If that fails to bring point back on frame, point is centered instead.\n\
4370 If this is zero, point is always centered after it moves off frame.");
4372 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
4374 DEFVAR_BOOL ("truncate-partial-width-windows",
4375 &truncate_partial_width_windows,
4376 "*Non-nil means truncate lines in all windows less than full frame wide.");
4377 truncate_partial_width_windows = 1;
4379 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
4380 "*Non-nil means use inverse video for the mode line.");
4381 mode_line_inverse_video = 1;
4383 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
4384 "*Maximum buffer size for which line number should be displayed.");
4385 line_number_display_limit = 1000000;
4387 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
4388 "*Non-nil means highlight region even in nonselected windows.");
4389 highlight_nonselected_windows = 1;
4391 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
4392 "Non-nil if more than one frame is visible on this display.\n\
4393 Minibuffer-only frames don't count, but iconified frames do.\n\
4394 This variable is not guaranteed to be accurate except while processing\n\
4395 `frame-title-format' and `icon-title-format'.");
4397 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
4398 "Template for displaying the titlebar of visible frames.\n\
4399 \(Assuming the window manager supports this feature.)\n\
4400 This variable has the same structure as `mode-line-format' (which see),\n\
4401 and is used only on frames for which no explicit name has been set\n\
4402 \(see `modify-frame-parameters').");
4403 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
4404 "Template for displaying the titlebar of an iconified frame.\n\
4405 \(Assuming the window manager supports this feature.)\n\
4406 This variable has the same structure as `mode-line-format' (which see),\n\
4407 and is used only on frames for which no explicit name has been set\n\
4408 \(see `modify-frame-parameters').");
4409 Vicon_title_format
4410 = Vframe_title_format
4411 = Fcons (intern ("multiple-frames"),
4412 Fcons (build_string ("%b"),
4413 Fcons (Fcons (build_string (""),
4414 Fcons (intern ("invocation-name"),
4415 Fcons (build_string ("@"),
4416 Fcons (intern ("system-name"),
4417 Qnil)))),
4418 Qnil)));
4420 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
4421 "Maximum number of lines to keep in the message log buffer.\n\
4422 If nil, disable message logging. If t, log messages but don't truncate\n\
4423 the buffer when it becomes large.");
4424 XSETFASTINT (Vmessage_log_max, 50);
4426 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
4427 "Functions called before redisplay, if window sizes have changed.\n\
4428 The value should be a list of functions that take one argument.\n\
4429 Just before redisplay, for each frame, if any of its windows have changed\n\
4430 size since the last redisplay, or have been split or deleted,\n\
4431 all the functions in the list are called, with the frame as argument.");
4432 Vwindow_size_change_functions = Qnil;
4434 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions,
4435 "List of Functions to call before redisplaying a window with scrolling.\n\
4436 Each function is called with two arguments, the window\n\
4437 and its new display-start position. Note that the value of `window-end'\n\
4438 is not valid when these functions are called.");
4439 Vwindow_scroll_functions = Qnil;
4442 /* initialize the window system */
4443 init_xdisp ()
4445 Lisp_Object root_window;
4446 #ifndef COMPILER_REGISTER_BUG
4447 register
4448 #endif /* COMPILER_REGISTER_BUG */
4449 struct window *mini_w;
4451 this_line_bufpos = 0;
4453 mini_w = XWINDOW (minibuf_window);
4454 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
4456 echo_area_glyphs = 0;
4457 previous_echo_glyphs = 0;
4459 if (!noninteractive)
4461 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
4462 XSETFASTINT (XWINDOW (root_window)->top, 0);
4463 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
4464 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
4465 set_window_height (minibuf_window, 1, 0);
4467 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
4468 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));