(iso-languages): For Latin-2, add ^I and ^i. Fix ~a.
[emacs.git] / src / xdisp.c
blob91036b56fa0428df836b611b9cad9c85de582bf9
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 "charset.h"
33 #include "indent.h"
34 #include "commands.h"
35 #include "macros.h"
36 #include "disptab.h"
37 #include "termhooks.h"
38 #include "intervals.h"
39 #include "keyboard.h"
40 #include "coding.h"
41 #include "process.h"
43 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
44 extern void set_frame_menubar ();
45 extern int pending_menu_activation;
46 #endif
48 extern int interrupt_input;
49 extern int command_loop_level;
51 extern int minibuffer_auto_raise;
53 extern Lisp_Object Qface;
55 extern Lisp_Object Voverriding_local_map;
56 extern Lisp_Object Voverriding_local_map_menu_flag;
58 Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
59 Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
60 Lisp_Object Qredisplay_end_trigger_functions;
62 /* Nonzero means print newline to stdout before next minibuffer message. */
64 int noninteractive_need_newline;
66 /* Nonzero means print newline to message log before next message. */
68 static int message_log_need_newline;
70 #define min(a, b) ((a) < (b) ? (a) : (b))
71 #define max(a, b) ((a) > (b) ? (a) : (b))
72 #define minmax(floor, val, ceil) \
73 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
75 /* The buffer position of the first character appearing
76 entirely or partially on the current frame line.
77 Or zero, which disables the optimization for the current frame line. */
78 static int this_line_bufpos;
80 /* Number of characters past the end of this line,
81 including the terminating newline */
82 static int this_line_endpos;
84 /* The vertical position of this frame line. */
85 static int this_line_vpos;
87 /* Hpos value for start of display on this frame line.
88 Usually zero, but negative if first character really began
89 on previous line */
90 static int this_line_start_hpos;
92 /* Buffer that this_line variables are describing. */
93 static struct buffer *this_line_buffer;
95 /* Value of echo_area_glyphs when it was last acted on.
96 If this is nonzero, there is a message on the frame
97 in the minibuffer and it should be erased as soon
98 as it is no longer requested to appear. */
99 char *previous_echo_glyphs;
101 /* Nonzero means truncate lines in all windows less wide than the frame */
102 int truncate_partial_width_windows;
104 /* Nonzero means we have more than one non-minibuffer-only frame.
105 Not guaranteed to be accurate except while parsing frame-title-format. */
106 int multiple_frames;
108 Lisp_Object Vglobal_mode_string;
110 /* Marker for where to display an arrow on top of the buffer text. */
111 Lisp_Object Voverlay_arrow_position;
113 /* String to display for the arrow. */
114 Lisp_Object Voverlay_arrow_string;
116 /* Like mode-line-format, but for the titlebar on a visible frame. */
117 Lisp_Object Vframe_title_format;
119 /* Like mode-line-format, but for the titlebar on an iconified frame. */
120 Lisp_Object Vicon_title_format;
122 /* List of functions to call when a window's size changes. These
123 functions get one arg, a frame on which one or more windows' sizes
124 have changed. */
125 static Lisp_Object Vwindow_size_change_functions;
127 /* Values of those variables at last redisplay. */
128 static Lisp_Object last_arrow_position, last_arrow_string;
130 Lisp_Object Qmenu_bar_update_hook;
132 /* Nonzero if overlay arrow has been displayed once in this window. */
133 static int overlay_arrow_seen;
135 /* Nonzero if visible end of buffer has already been displayed once
136 in this window. (We need this variable in case there are overlay
137 strings that get displayed there.) */
138 static int zv_strings_seen;
140 /* Nonzero means highlight the region even in nonselected windows. */
141 static int highlight_nonselected_windows;
143 /* If cursor motion alone moves point off frame,
144 Try scrolling this many lines up or down if that will bring it back. */
145 static int scroll_step;
147 /* Non-0 means scroll just far enough to bring point back on the screen,
148 when appropriate. */
149 static int scroll_conservatively;
151 /* Recenter the window whenever point gets within this many lines
152 of the top or bottom of the window. */
153 int scroll_margin;
155 /* Nonzero if try_window_id has made blank lines at window bottom
156 since the last redisplay that paused */
157 static int blank_end_of_window;
159 /* Number of windows showing the buffer of the selected window
160 (or another buffer with the same base buffer).
161 keyboard.c refers to this. */
162 int buffer_shared;
164 /* display_text_line sets these to the frame position (origin 0) of point,
165 whether the window is selected or not.
166 Set one to -1 first to determine whether point was found afterwards. */
168 static int cursor_vpos;
169 static int cursor_hpos;
171 static int debug_end_pos;
173 /* Nonzero means display mode line highlighted */
174 int mode_line_inverse_video;
176 static void redisplay_internal ();
177 static int message_log_check_duplicate ();
178 static void echo_area_display ();
179 void mark_window_display_accurate ();
180 static void redisplay_windows ();
181 static void redisplay_window ();
182 static void update_menu_bar ();
183 static void try_window ();
184 static int try_window_id ();
185 static struct position *display_text_line ();
186 static void display_mode_line ();
187 static int display_mode_element ();
188 static char *decode_mode_spec ();
189 static int display_string ();
190 static void display_menu_bar ();
191 static int display_count_lines ();
193 /* Prompt to display in front of the minibuffer contents */
194 Lisp_Object minibuf_prompt;
196 /* Width in columns of current minibuffer prompt. */
197 int minibuf_prompt_width;
199 /* Message to display instead of minibuffer contents
200 This is what the functions error and message make,
201 and command echoing uses it as well.
202 It overrides the minibuf_prompt as well as the buffer. */
203 char *echo_area_glyphs;
205 /* This is the length of the message in echo_area_glyphs. */
206 int echo_area_glyphs_length;
208 /* This is the window where the echo area message was displayed.
209 It is always a minibuffer window, but it may not be the
210 same window currently active as a minibuffer. */
211 Lisp_Object echo_area_window;
213 /* true iff we should redraw the mode lines on the next redisplay */
214 int update_mode_lines;
216 /* Smallest number of characters before the gap
217 at any time since last redisplay that finished.
218 Valid for current buffer when try_window_id can be called. */
219 int beg_unchanged;
221 /* Smallest number of characters after the gap
222 at any time since last redisplay that finished.
223 Valid for current buffer when try_window_id can be called. */
224 int end_unchanged;
226 /* MODIFF as of last redisplay that finished;
227 if it matches MODIFF, and overlay_unchanged_modified
228 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
229 contain no useful information */
230 int unchanged_modified;
232 /* OVERLAY_MODIFF as of last redisplay that finished. */
233 int overlay_unchanged_modified;
235 /* Nonzero if window sizes or contents have changed
236 since last redisplay that finished */
237 int windows_or_buffers_changed;
239 /* Nonzero after display_mode_line if %l was used
240 and it displayed a line number. */
241 int line_number_displayed;
243 /* Maximum buffer size for which to display line numbers. */
244 static int line_number_display_limit;
246 /* Number of lines to keep in the message log buffer.
247 t means infinite. nil means don't log at all. */
248 Lisp_Object Vmessage_log_max;
250 /* Output a newline in the *Messages* buffer if "needs" one. */
252 void
253 message_log_maybe_newline ()
255 if (message_log_need_newline)
256 message_dolog ("", 0, 1);
260 /* Add a string to the message log, optionally terminated with a newline.
261 This function calls low-level routines in order to bypass text property
262 hooks, etc. which might not be safe to run. */
264 void
265 message_dolog (m, len, nlflag)
266 char *m;
267 int len, nlflag;
269 if (!NILP (Vmessage_log_max))
271 struct buffer *oldbuf;
272 int oldpoint, oldbegv, oldzv;
273 int old_windows_or_buffers_changed = windows_or_buffers_changed;
275 oldbuf = current_buffer;
276 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
277 current_buffer->undo_list = Qt;
278 oldpoint = PT;
279 oldbegv = BEGV;
280 oldzv = ZV;
281 BEGV = BEG;
282 ZV = Z;
283 if (oldpoint == Z)
284 oldpoint += len + nlflag;
285 if (oldzv == Z)
286 oldzv += len + nlflag;
287 TEMP_SET_PT (Z);
288 if (len)
289 insert_1 (m, len, 1, 0);
290 if (nlflag)
292 int this_bol, prev_bol, dup;
293 insert_1 ("\n", 1, 1, 0);
295 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
296 if (this_bol > BEG)
298 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
299 dup = message_log_check_duplicate (prev_bol, this_bol);
300 if (dup)
302 if (oldpoint > prev_bol)
303 oldpoint -= min (this_bol, oldpoint) - prev_bol;
304 if (oldbegv > prev_bol)
305 oldbegv -= min (this_bol, oldbegv) - prev_bol;
306 if (oldzv > prev_bol)
307 oldzv -= min (this_bol, oldzv) - prev_bol;
308 del_range_1 (prev_bol, this_bol, 0);
309 if (dup > 1)
311 char dupstr[40];
312 int duplen;
314 /* If you change this format, don't forget to also
315 change message_log_check_duplicate. */
316 sprintf (dupstr, " [%d times]", dup);
317 duplen = strlen (dupstr);
318 TEMP_SET_PT (Z-1);
319 if (oldpoint == Z)
320 oldpoint += duplen;
321 if (oldzv == Z)
322 oldzv += duplen;
323 insert_1 (dupstr, duplen, 1, 0);
328 if (NATNUMP (Vmessage_log_max))
330 int pos = scan_buffer ('\n', Z, 0,
331 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
332 oldpoint -= min (pos, oldpoint) - BEG;
333 oldbegv -= min (pos, oldbegv) - BEG;
334 oldzv -= min (pos, oldzv) - BEG;
335 del_range_1 (BEG, pos, 0);
338 BEGV = oldbegv;
339 ZV = oldzv;
340 TEMP_SET_PT (oldpoint);
341 set_buffer_internal (oldbuf);
342 windows_or_buffers_changed = old_windows_or_buffers_changed;
343 message_log_need_newline = !nlflag;
347 /* We are at the end of the buffer after just having inserted a newline.
348 (Note: We depend on the fact we won't be crossing the gap.)
349 Check to see if the most recent message looks a lot like the previous one.
350 Return 0 if different, 1 if the new one should just replace it, or a
351 value N > 1 if we should also append " [N times]". */
353 static int
354 message_log_check_duplicate (prev_bol, this_bol)
355 int prev_bol, this_bol;
357 int i;
358 int len = Z - 1 - this_bol;
359 int seen_dots = 0;
360 unsigned char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
361 unsigned char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
363 for (i = 0; i < len; i++)
365 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
366 && p1[i] != '\n')
367 seen_dots = 1;
368 if (p1[i] != p2[i])
369 return seen_dots;
371 p1 += len;
372 if (*p1 == '\n')
373 return 2;
374 if (*p1++ == ' ' && *p1++ == '[')
376 int n = 0;
377 while (*p1 >= '0' && *p1 <= '9')
378 n = n * 10 + *p1++ - '0';
379 if (strncmp (p1, " times]\n", 8) == 0)
380 return n+1;
382 return 0;
385 /* Display an echo area message M with a specified length of LEN chars.
386 The string may include null characters. If M is 0, clear out any
387 existing message, and let the minibuffer text show through.
389 The buffer M must continue to exist until after the echo area
390 gets cleared or some other message gets displayed there.
392 Do not pass text that is stored in a Lisp string.
393 Do not pass text in a buffer that was alloca'd. */
395 void
396 message2 (m, len)
397 char *m;
398 int len;
400 /* First flush out any partial line written with print. */
401 message_log_maybe_newline ();
402 if (m)
403 message_dolog (m, len, 1);
404 message2_nolog (m, len);
408 /* The non-logging counterpart of message2. */
410 void
411 message2_nolog (m, len)
412 char *m;
413 int len;
415 if (noninteractive)
417 if (noninteractive_need_newline)
418 putc ('\n', stderr);
419 noninteractive_need_newline = 0;
420 fwrite (m, len, 1, stderr);
421 if (cursor_in_echo_area == 0)
422 fprintf (stderr, "\n");
423 fflush (stderr);
425 /* A null message buffer means that the frame hasn't really been
426 initialized yet. Error messages get reported properly by
427 cmd_error, so this must be just an informative message; toss it. */
428 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
430 Lisp_Object mini_window;
431 FRAME_PTR f;
433 /* Get the frame containing the minibuffer
434 that the selected frame is using. */
435 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
436 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
438 FRAME_SAMPLE_VISIBILITY (f);
439 if (FRAME_VISIBLE_P (selected_frame)
440 && ! FRAME_VISIBLE_P (f))
441 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window)));
443 if (m)
445 echo_area_glyphs = m;
446 echo_area_glyphs_length = len;
448 if (minibuffer_auto_raise)
449 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window)));
451 else
452 echo_area_glyphs = previous_echo_glyphs = 0;
454 do_pending_window_change ();
455 echo_area_display ();
456 update_frame (f, 1, 1);
457 do_pending_window_change ();
458 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
459 (*frame_up_to_date_hook) (f);
463 /* Display a null-terminated echo area message M. If M is 0, clear out any
464 existing message, and let the minibuffer text show through.
466 The buffer M must continue to exist until after the echo area
467 gets cleared or some other message gets displayed there.
469 Do not pass text that is stored in a Lisp string.
470 Do not pass text in a buffer that was alloca'd. */
472 void
473 message1 (m)
474 char *m;
476 message2 (m, (m ? strlen (m) : 0));
479 void
480 message1_nolog (m)
481 char *m;
483 message2_nolog (m, (m ? strlen (m) : 0));
486 /* Truncate what will be displayed in the echo area
487 the next time we display it--but don't redisplay it now. */
489 void
490 truncate_echo_area (len)
491 int len;
493 /* A null message buffer means that the frame hasn't really been
494 initialized yet. Error messages get reported properly by
495 cmd_error, so this must be just an informative message; toss it. */
496 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
497 echo_area_glyphs_length = len;
500 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
501 zero if being used by message. */
502 int message_buf_print;
504 /* Dump an informative message to the minibuf. If M is 0, clear out
505 any existing message, and let the minibuffer text show through. */
507 /* VARARGS 1 */
508 void
509 message (m, a1, a2, a3)
510 char *m;
511 EMACS_INT a1, a2, a3;
513 if (noninteractive)
515 if (m)
517 if (noninteractive_need_newline)
518 putc ('\n', stderr);
519 noninteractive_need_newline = 0;
520 fprintf (stderr, m, a1, a2, a3);
521 if (cursor_in_echo_area == 0)
522 fprintf (stderr, "\n");
523 fflush (stderr);
526 else if (INTERACTIVE)
528 /* The frame whose minibuffer we're going to display the message on.
529 It may be larger than the selected frame, so we need
530 to use its buffer, not the selected frame's buffer. */
531 Lisp_Object mini_window;
532 FRAME_PTR f;
534 /* Get the frame containing the minibuffer
535 that the selected frame is using. */
536 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
537 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
539 /* A null message buffer means that the frame hasn't really been
540 initialized yet. Error messages get reported properly by
541 cmd_error, so this must be just an informative message; toss it. */
542 if (FRAME_MESSAGE_BUF (f))
544 if (m)
546 int len;
547 #ifdef NO_ARG_ARRAY
548 EMACS_INT a[3];
549 a[0] = a1;
550 a[1] = a2;
551 a[2] = a3;
553 len = doprnt (FRAME_MESSAGE_BUF (f),
554 FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, a);
555 #else
556 len = doprnt (FRAME_MESSAGE_BUF (f),
557 FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, &a1);
558 #endif /* NO_ARG_ARRAY */
560 message2 (FRAME_MESSAGE_BUF (f), len);
562 else
563 message1 (0);
565 /* Print should start at the beginning of the message
566 buffer next time. */
567 message_buf_print = 0;
572 /* The non-logging version of message. */
573 void
574 message_nolog (m, a1, a2, a3)
575 char *m;
576 EMACS_INT a1, a2, a3;
578 Lisp_Object old_log_max;
579 old_log_max = Vmessage_log_max;
580 Vmessage_log_max = Qnil;
581 message (m, a1, a2, a3);
582 Vmessage_log_max = old_log_max;
585 void
586 update_echo_area ()
588 message2 (echo_area_glyphs, echo_area_glyphs_length);
591 static void
592 echo_area_display ()
594 register int vpos;
595 FRAME_PTR f;
596 Lisp_Object mini_window;
598 /* Choose the minibuffer window for this display.
599 It is the minibuffer window used by the selected frame. */
600 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
601 /* This is the frame that window is in. */
602 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
604 if (! FRAME_VISIBLE_P (f))
605 return;
607 if (frame_garbaged)
609 redraw_garbaged_frames ();
610 frame_garbaged = 0;
613 if (echo_area_glyphs || minibuf_level == 0)
615 int i;
617 echo_area_window = mini_window;
619 vpos = XFASTINT (XWINDOW (mini_window)->top);
620 get_display_line (f, vpos, 0);
622 /* Make sure the columns that overlap a left-hand scroll bar
623 are always clear. */
624 for (i = 0; i < FRAME_LEFT_SCROLL_BAR_WIDTH (f); i++)
625 f->desired_glyphs->glyphs[vpos][i] = SPACEGLYPH;
627 display_string (XWINDOW (mini_window), vpos,
628 echo_area_glyphs ? echo_area_glyphs : "",
629 echo_area_glyphs ? echo_area_glyphs_length : -1,
630 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
631 0, 0, 0, FRAME_WIDTH (f));
633 #if 0 /* This just gets in the way. update_frame does the job. */
634 /* If desired cursor location is on this line, put it at end of text */
635 if (cursor_in_echo_area)
636 FRAME_CURSOR_Y (f) = vpos;
637 if (FRAME_CURSOR_Y (f) == vpos)
638 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
639 #endif
641 /* Fill the rest of the minibuffer window with blank lines. */
643 int i;
645 for (i = vpos + 1;
646 i < vpos + XFASTINT (XWINDOW (mini_window)->height); i++)
648 get_display_line (f, i, 0);
649 display_string (XWINDOW (mini_window), vpos,
650 "", 0,
651 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
652 0, 0, 0, FRAME_WIDTH (f));
656 else if (!EQ (mini_window, selected_window))
657 windows_or_buffers_changed++;
659 if (EQ (mini_window, selected_window))
660 this_line_bufpos = 0;
662 previous_echo_glyphs = echo_area_glyphs;
665 /* Update frame titles. */
667 #ifdef HAVE_WINDOW_SYSTEM
668 static char frame_title_buf[512];
669 static char *frame_title_ptr;
671 static int
672 store_frame_title (str, mincol, maxcol)
673 char *str;
674 int mincol, maxcol;
676 char *limit;
677 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
678 maxcol = sizeof (frame_title_buf);
679 limit = &frame_title_buf[maxcol];
680 while (*str != '\0' && frame_title_ptr < limit)
681 *frame_title_ptr++ = *str++;
682 while (frame_title_ptr < &frame_title_buf[mincol])
683 *frame_title_ptr++ = ' ';
684 return frame_title_ptr - frame_title_buf;
687 static void
688 x_consider_frame_title (frame)
689 Lisp_Object frame;
691 Lisp_Object fmt;
692 struct buffer *obuf;
693 int len;
694 FRAME_PTR f = XFRAME (frame);
696 if (!(FRAME_WINDOW_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name))
697 return;
699 /* Do we have more than one visible frame on this X display? */
701 Lisp_Object tail;
703 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
705 FRAME_PTR tf = XFRAME (XCONS (tail)->car);
707 if (tf != f && FRAME_KBOARD (tf) == FRAME_KBOARD (f)
708 && !FRAME_MINIBUF_ONLY_P (tf)
709 && (FRAME_VISIBLE_P (tf) || FRAME_ICONIFIED_P (tf)))
710 break;
713 multiple_frames = CONSP (tail);
716 obuf = current_buffer;
717 Fset_buffer (XWINDOW (f->selected_window)->buffer);
718 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
719 frame_title_ptr = frame_title_buf;
720 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
721 0, sizeof (frame_title_buf), fmt);
722 frame_title_ptr = 0;
723 set_buffer_internal (obuf);
724 /* Set the name only if it's changed. This avoids consing
725 in the common case where it hasn't. (If it turns out that we've
726 already wasted too much time by walking through the list with
727 display_mode_element, then we might need to optimize at a higher
728 level than this.) */
729 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
730 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
731 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
733 #else
734 #define frame_title_ptr ((char *)0)
735 #define store_frame_title(str, mincol, maxcol) 0
736 #endif
738 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
739 This can call eval. */
741 void
742 prepare_menu_bars ()
744 register struct window *w = XWINDOW (selected_window);
745 int all_windows;
746 struct gcpro gcpro1, gcpro2;
748 all_windows = (update_mode_lines || buffer_shared > 1
749 || windows_or_buffers_changed);
751 /* Update all frame titles based on their buffer names, etc.
752 We do this before the menu bars so that the buffer-menu
753 will show the up-to-date frame titles.
755 This used to be done after the menu bars, for a reason that
756 was stated as follows but which I do not understand:
757 "We do this after the menu bars so that the frame will first
758 create its menu bar using the name `emacs' if no other name
759 has yet been specified."
760 I think that is no longer a concern. */
761 #ifdef HAVE_WINDOW_SYSTEM
762 if (windows_or_buffers_changed || update_mode_lines)
764 Lisp_Object tail, frame;
766 FOR_EACH_FRAME (tail, frame)
767 if (FRAME_VISIBLE_P (XFRAME (frame))
768 || FRAME_ICONIFIED_P (XFRAME (frame)))
769 x_consider_frame_title (frame);
771 #endif
773 /* Update the menu bar item lists, if appropriate.
774 This has to be done before any actual redisplay
775 or generation of display lines. */
776 if (all_windows)
778 Lisp_Object tail, frame;
779 int count = specpdl_ptr - specpdl;
781 record_unwind_protect (Fstore_match_data, Fmatch_data (Qnil, Qnil));
783 FOR_EACH_FRAME (tail, frame)
785 /* If a window on this frame changed size,
786 report that to the user and clear the size-change flag. */
787 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
789 Lisp_Object functions;
790 /* Clear flag first in case we get error below. */
791 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
792 functions = Vwindow_size_change_functions;
793 GCPRO2 (tail, functions);
794 while (CONSP (functions))
796 call1 (XCONS (functions)->car, frame);
797 functions = XCONS (functions)->cdr;
799 UNGCPRO;
801 GCPRO1 (tail);
802 update_menu_bar (XFRAME (frame), 0);
803 UNGCPRO;
806 unbind_to (count, Qnil);
808 else
809 update_menu_bar (selected_frame, 1);
811 /* Motif needs this. See comment in xmenu.c.
812 Turn it off when pending_menu_activation is not defined. */
813 #ifdef USE_X_TOOLKIT
814 pending_menu_activation = 0;
815 #endif
818 /* Do a frame update, taking possible shortcuts into account.
819 This is the main external entry point for redisplay.
821 If the last redisplay displayed an echo area message and that
822 message is no longer requested, we clear the echo area
823 or bring back the minibuffer if that is in use.
825 Do not call eval from within this function.
826 Calls to eval after the call to echo_area_display would confuse
827 the display_line mechanism and would cause a crash.
828 Calls to eval before that point will work most of the time,
829 but can still lose, because this function
830 can be called from signal handlers; with alarms set up;
831 or with synchronous processes running.
833 See Fcall_process; if you called it from here, it could be
834 entered recursively. */
836 static int do_verify_charstarts;
838 /* Counter is used to clear the face cache
839 no more than once ever 1000 redisplays. */
840 static int clear_face_cache_count;
842 /* Record the previous terminal frame we displayed. */
843 static FRAME_PTR previous_terminal_frame;
845 void
846 redisplay ()
848 redisplay_internal (0);
851 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
852 is not in response to any user action; therefore, we should
853 preserve the echo area. (Actually, our caller does that job.)
854 Perhaps in the future avoid recentering windows
855 if it is not necessary; currently that causes some problems. */
857 static void
858 redisplay_internal (preserve_echo_area)
859 int preserve_echo_area;
861 register struct window *w = XWINDOW (selected_window);
862 register int pause;
863 int must_finish = 0;
864 int all_windows;
865 register int tlbufpos, tlendpos;
866 struct position pos;
868 if (noninteractive)
869 return;
871 #ifdef USE_X_TOOLKIT
872 if (popup_activated ())
873 return;
874 #endif
876 if (! FRAME_WINDOW_P (selected_frame)
877 && previous_terminal_frame != selected_frame)
879 /* Since frames on an ASCII terminal share the same display area,
880 displaying a different frame means redisplay the whole thing. */
881 windows_or_buffers_changed++;
882 SET_FRAME_GARBAGED (selected_frame);
883 XSETFRAME (Vterminal_frame, selected_frame);
885 previous_terminal_frame = selected_frame;
887 /* Set the visible flags for all frames.
888 Do this before checking for resized or garbaged frames; they want
889 to know if their frames are visible.
890 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
892 Lisp_Object tail, frame;
894 FOR_EACH_FRAME (tail, frame)
896 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
898 /* Clear out all the display lines in which we will generate the
899 glyphs to display. */
900 init_desired_glyphs (XFRAME (frame));
904 /* Notice any pending interrupt request to change frame size. */
905 do_pending_window_change ();
907 if (frame_garbaged)
909 redraw_garbaged_frames ();
910 frame_garbaged = 0;
913 prepare_menu_bars ();
915 if (windows_or_buffers_changed)
916 update_mode_lines++;
918 /* Detect case that we need to write or remove a star in the mode line. */
919 if ((SAVE_MODIFF < MODIFF) != !NILP (w->last_had_star))
921 w->update_mode_line = Qt;
922 if (buffer_shared > 1)
923 update_mode_lines++;
926 /* If %c is in use, update it if needed. */
927 if (!NILP (w->column_number_displayed)
928 /* This alternative quickly identifies a common case
929 where no change is needed. */
930 && !(PT == XFASTINT (w->last_point)
931 && XFASTINT (w->last_modified) >= MODIFF
932 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)
933 && XFASTINT (w->column_number_displayed) != current_column ())
934 w->update_mode_line = Qt;
936 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
938 all_windows = update_mode_lines || buffer_shared > 1;
940 /* If specs for an arrow have changed, do thorough redisplay
941 to ensure we remove any arrow that should no longer exist. */
942 if (! EQ (Voverlay_arrow_position, last_arrow_position)
943 || ! EQ (Voverlay_arrow_string, last_arrow_string))
944 all_windows = 1;
946 /* Normally the message* functions will have already displayed and
947 updated the echo area, but the frame may have been trashed, or
948 the update may have been preempted, so display the echo area
949 again here. */
950 if (echo_area_glyphs || previous_echo_glyphs)
952 echo_area_display ();
953 must_finish = 1;
956 /* If showing region, and mark has changed, must redisplay whole window. */
957 if (((!NILP (Vtransient_mark_mode)
958 && !NILP (XBUFFER (w->buffer)->mark_active))
959 != !NILP (w->region_showing))
960 || (!NILP (w->region_showing)
961 && !EQ (w->region_showing,
962 Fmarker_position (XBUFFER (w->buffer)->mark))))
963 this_line_bufpos = -1;
965 tlbufpos = this_line_bufpos;
966 tlendpos = this_line_endpos;
967 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
968 && !current_buffer->clip_changed
969 && FRAME_VISIBLE_P (XFRAME (w->frame))
970 /* Make sure recorded data applies to current buffer, etc */
971 && this_line_buffer == current_buffer
972 && current_buffer == XBUFFER (w->buffer)
973 && NILP (w->force_start)
974 /* Point must be on the line that we have info recorded about */
975 && PT >= tlbufpos
976 && PT <= Z - tlendpos
977 /* All text outside that line, including its final newline,
978 must be unchanged */
979 && ((XFASTINT (w->last_modified) >= MODIFF
980 && (XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF))
981 || (beg_unchanged >= tlbufpos - 1
982 && GPT >= tlbufpos
983 /* If selective display, can't optimize
984 if the changes start at the beginning of the line. */
985 && ((INTEGERP (current_buffer->selective_display)
986 && XINT (current_buffer->selective_display) > 0
987 ? (beg_unchanged >= tlbufpos
988 && GPT > tlbufpos)
989 : 1))
990 && end_unchanged >= tlendpos
991 && Z - GPT >= tlendpos)))
993 if (tlbufpos > BEGV && FETCH_BYTE (tlbufpos - 1) != '\n'
994 && (tlbufpos == ZV
995 || FETCH_BYTE (tlbufpos) == '\n'))
996 /* Former continuation line has disappeared by becoming empty */
997 goto cancel;
998 else if (XFASTINT (w->last_modified) < MODIFF
999 || XFASTINT (w->last_overlay_modified) < OVERLAY_MODIFF
1000 || MINI_WINDOW_P (w))
1002 /* We have to handle the case of continuation around a
1003 wide-column character (See the comment in indent.c around
1004 line 885).
1006 For instance, in the following case:
1008 -------- Insert --------
1009 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1010 J_I_ ==> J_I_ `^^' are cursors.
1011 ^^ ^^
1012 -------- --------
1014 As we have to redraw the line above, we should goto cancel. */
1016 struct position val;
1017 int prevline;
1019 prevline = find_next_newline (tlbufpos, -1);
1020 val = *compute_motion (prevline, 0,
1021 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1023 tlbufpos,
1024 1 << (BITS_PER_SHORT - 1),
1025 1 << (BITS_PER_SHORT - 1),
1026 window_internal_width (w) - 1,
1027 XINT (w->hscroll), 0, w);
1028 if (val.hpos != this_line_start_hpos)
1029 goto cancel;
1031 cursor_vpos = -1;
1032 overlay_arrow_seen = 0;
1033 zv_strings_seen = 0;
1034 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
1035 pos_tab_offset (w, tlbufpos), 0);
1036 /* If line contains point, is not continued,
1037 and ends at same distance from eob as before, we win */
1038 if (cursor_vpos >= 0 && this_line_bufpos
1039 && this_line_endpos == tlendpos)
1041 /* If this is not the window's last line,
1042 we must adjust the charstarts of the lines below. */
1043 if (this_line_vpos + 1
1044 < XFASTINT (w->top) + window_internal_height (w))
1046 int left = WINDOW_LEFT_MARGIN (w);
1047 int *charstart_next_line
1048 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
1049 int adjust;
1051 if (Z - tlendpos == ZV)
1052 /* This line ends at end of (accessible part of) buffer.
1053 There is no newline to count. */
1054 adjust = Z - tlendpos - charstart_next_line[left];
1055 else
1056 /* This line ends in a newline.
1057 Must take account of the newline and the rest of the
1058 text that follows. */
1059 adjust = Z - tlendpos + 1 - charstart_next_line[left];
1061 adjust_window_charstarts (w, this_line_vpos, adjust);
1064 if (!WINDOW_FULL_WIDTH_P (w))
1065 preserve_other_columns (w);
1066 goto update;
1068 else
1069 goto cancel;
1071 else if (PT == XFASTINT (w->last_point)
1072 /* Make sure the cursor was last displayed
1073 in this window. Otherwise we have to reposition it. */
1074 && XINT (w->top) <= FRAME_CURSOR_Y (selected_frame)
1075 && (XINT (w->top) + XINT (w->height)
1076 > FRAME_CURSOR_Y (selected_frame)))
1078 if (!must_finish)
1080 do_pending_window_change ();
1081 return;
1083 goto update;
1085 /* If highlighting the region, or if the cursor is in the echo area,
1086 then we can't just move the cursor. */
1087 else if (! (!NILP (Vtransient_mark_mode)
1088 && !NILP (current_buffer->mark_active))
1089 && (w == XWINDOW (current_buffer->last_selected_window)
1090 || highlight_nonselected_windows)
1091 && NILP (w->region_showing)
1092 && !cursor_in_echo_area)
1094 pos = *compute_motion (tlbufpos, 0,
1095 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1097 PT, 2, - (1 << (BITS_PER_SHORT - 1)),
1098 window_internal_width (w) - 1,
1099 XINT (w->hscroll),
1100 pos_tab_offset (w, tlbufpos), w);
1101 if (pos.vpos < 1)
1103 int width = window_internal_width (w) - 1;
1104 FRAME_CURSOR_X (selected_frame)
1105 = WINDOW_LEFT_MARGIN (w) + minmax (0, pos.hpos, width);
1106 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
1107 goto update;
1109 else
1110 goto cancel;
1112 cancel:
1113 /* Text changed drastically or point moved off of line */
1114 cancel_line (this_line_vpos, selected_frame);
1117 this_line_bufpos = 0;
1118 all_windows |= buffer_shared > 1;
1120 clear_face_cache_count++;
1122 if (all_windows)
1124 Lisp_Object tail, frame;
1126 #ifdef HAVE_FACES
1127 /* Clear the face cache, only when we do a full redisplay
1128 and not too often either. */
1129 if (clear_face_cache_count > 1000)
1131 clear_face_cache ();
1132 clear_face_cache_count = 0;
1134 #endif
1136 /* Recompute # windows showing selected buffer.
1137 This will be incremented each time such a window is displayed. */
1138 buffer_shared = 0;
1140 FOR_EACH_FRAME (tail, frame)
1142 FRAME_PTR f = XFRAME (frame);
1143 if (FRAME_WINDOW_P (f) || f == selected_frame)
1146 /* Mark all the scroll bars to be removed; we'll redeem the ones
1147 we want when we redisplay their windows. */
1148 if (condemn_scroll_bars_hook)
1149 (*condemn_scroll_bars_hook) (f);
1151 if (FRAME_VISIBLE_P (f))
1152 redisplay_windows (FRAME_ROOT_WINDOW (f), preserve_echo_area);
1154 /* Any scroll bars which redisplay_windows should have nuked
1155 should now go away. */
1156 if (judge_scroll_bars_hook)
1157 (*judge_scroll_bars_hook) (f);
1161 else if (FRAME_VISIBLE_P (selected_frame))
1163 redisplay_window (selected_window, 1, preserve_echo_area);
1164 if (!WINDOW_FULL_WIDTH_P (w))
1165 preserve_other_columns (w);
1168 update:
1169 /* Prevent various kinds of signals during display update.
1170 stdio is not robust about handling signals,
1171 which can cause an apparent I/O error. */
1172 if (interrupt_input)
1173 unrequest_sigio ();
1174 stop_polling ();
1176 if (all_windows)
1178 Lisp_Object tail;
1180 pause = 0;
1182 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
1184 FRAME_PTR f;
1186 if (!FRAMEP (XCONS (tail)->car))
1187 continue;
1189 f = XFRAME (XCONS (tail)->car);
1191 if ((FRAME_WINDOW_P (f) || f == selected_frame)
1192 && FRAME_VISIBLE_P (f))
1194 pause |= update_frame (f, 0, 0);
1195 if (!pause)
1197 mark_window_display_accurate (f->root_window, 1);
1198 if (frame_up_to_date_hook != 0)
1199 (*frame_up_to_date_hook) (f);
1204 else
1206 if (FRAME_VISIBLE_P (selected_frame))
1207 pause = update_frame (selected_frame, 0, 0);
1208 else
1209 pause = 0;
1211 /* We may have called echo_area_display at the top of this
1212 function. If the echo area is on another frame, that may
1213 have put text on a frame other than the selected one, so the
1214 above call to update_frame would not have caught it. Catch
1215 it here. */
1217 Lisp_Object mini_window;
1218 FRAME_PTR mini_frame;
1220 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
1221 mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
1223 if (mini_frame != selected_frame && FRAME_WINDOW_P (mini_frame))
1224 pause |= update_frame (mini_frame, 0, 0);
1228 /* If frame does not match, prevent doing single-line-update next time.
1229 Also, don't forget to check every line to update the arrow. */
1230 if (pause)
1232 this_line_bufpos = 0;
1233 if (!NILP (last_arrow_position))
1235 last_arrow_position = Qt;
1236 last_arrow_string = Qt;
1238 /* If we pause after scrolling, some lines in current_frame
1239 may be null, so preserve_other_columns won't be able to
1240 preserve all the vertical-bar separators. So, avoid using it
1241 in that case. */
1242 if (!WINDOW_FULL_WIDTH_P (w))
1243 update_mode_lines = 1;
1246 /* Now text on frame agrees with windows, so
1247 put info into the windows for partial redisplay to follow */
1249 if (!pause)
1251 register struct buffer *b = XBUFFER (w->buffer);
1253 blank_end_of_window = 0;
1254 unchanged_modified = BUF_MODIFF (b);
1255 overlay_unchanged_modified = BUF_OVERLAY_MODIFF (b);
1256 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1257 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1259 XSETFASTINT (w->last_point, BUF_PT (b));
1260 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1261 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1263 if (all_windows)
1264 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1265 else
1267 b->clip_changed = 0;
1268 w->update_mode_line = Qnil;
1269 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1270 XSETFASTINT (w->last_overlay_modified, BUF_OVERLAY_MODIFF (b));
1271 w->last_had_star
1272 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1273 ? Qt : Qnil);
1275 /* Record if we are showing a region, so can make sure to
1276 update it fully at next redisplay. */
1277 w->region_showing = (!NILP (Vtransient_mark_mode)
1278 && (w == XWINDOW (current_buffer->last_selected_window)
1279 || highlight_nonselected_windows)
1280 && !NILP (XBUFFER (w->buffer)->mark_active)
1281 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1282 : Qnil);
1284 w->window_end_valid = w->buffer;
1285 last_arrow_position = Voverlay_arrow_position;
1286 last_arrow_string = Voverlay_arrow_string;
1287 if (do_verify_charstarts)
1288 verify_charstarts (w);
1289 if (frame_up_to_date_hook != 0)
1290 (*frame_up_to_date_hook) (selected_frame);
1292 update_mode_lines = 0;
1293 windows_or_buffers_changed = 0;
1296 /* Start SIGIO interrupts coming again.
1297 Having them off during the code above
1298 makes it less likely one will discard output,
1299 but not impossible, since there might be stuff
1300 in the system buffer here.
1301 But it is much hairier to try to do anything about that. */
1303 if (interrupt_input)
1304 request_sigio ();
1305 start_polling ();
1307 /* Change frame size now if a change is pending. */
1308 do_pending_window_change ();
1310 /* If we just did a pending size change, redisplay again
1311 for the new size. */
1312 if (windows_or_buffers_changed && !pause)
1313 redisplay ();
1316 /* Redisplay, but leave alone any recent echo area message
1317 unless another message has been requested in its place.
1319 This is useful in situations where you need to redisplay but no
1320 user action has occurred, making it inappropriate for the message
1321 area to be cleared. See tracking_off and
1322 wait_reading_process_input for examples of these situations. */
1324 redisplay_preserve_echo_area ()
1326 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1328 echo_area_glyphs = previous_echo_glyphs;
1329 redisplay_internal (1);
1330 echo_area_glyphs = 0;
1332 else
1333 redisplay_internal (1);
1336 void
1337 mark_window_display_accurate (window, flag)
1338 Lisp_Object window;
1339 int flag;
1341 register struct window *w;
1343 for (;!NILP (window); window = w->next)
1345 if (!WINDOWP (window)) abort ();
1346 w = XWINDOW (window);
1348 if (!NILP (w->buffer))
1350 XSETFASTINT (w->last_modified,
1351 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1352 XSETFASTINT (w->last_overlay_modified,
1353 !flag ? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w->buffer)));
1354 w->last_had_star
1355 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1356 ? Qt : Qnil);
1358 /* Record if we are showing a region, so can make sure to
1359 update it fully at next redisplay. */
1360 w->region_showing = (!NILP (Vtransient_mark_mode)
1361 && (w == XWINDOW (current_buffer->last_selected_window)
1362 || highlight_nonselected_windows)
1363 && !NILP (XBUFFER (w->buffer)->mark_active)
1364 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1365 : Qnil);
1368 w->window_end_valid = w->buffer;
1369 w->update_mode_line = Qnil;
1370 if (!NILP (w->buffer) && flag)
1371 XBUFFER (w->buffer)->clip_changed = 0;
1373 if (!NILP (w->vchild))
1374 mark_window_display_accurate (w->vchild, flag);
1375 if (!NILP (w->hchild))
1376 mark_window_display_accurate (w->hchild, flag);
1379 if (flag)
1381 last_arrow_position = Voverlay_arrow_position;
1382 last_arrow_string = Voverlay_arrow_string;
1384 else
1386 /* t is unequal to any useful value of Voverlay_arrow_... */
1387 last_arrow_position = Qt;
1388 last_arrow_string = Qt;
1392 /* Update the menu bar item list for frame F.
1393 This has to be done before we start to fill in any display lines,
1394 because it can call eval.
1396 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1398 static void
1399 update_menu_bar (f, save_match_data)
1400 FRAME_PTR f;
1401 int save_match_data;
1403 struct buffer *old = current_buffer;
1404 Lisp_Object window;
1405 register struct window *w;
1407 window = FRAME_SELECTED_WINDOW (f);
1408 w = XWINDOW (window);
1410 if (update_mode_lines)
1411 w->update_mode_line = Qt;
1413 if (FRAME_WINDOW_P (f)
1415 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1416 FRAME_EXTERNAL_MENU_BAR (f)
1417 #else
1418 FRAME_MENU_BAR_LINES (f) > 0
1419 #endif
1420 : FRAME_MENU_BAR_LINES (f) > 0)
1422 /* If the user has switched buffers or windows, we need to
1423 recompute to reflect the new bindings. But we'll
1424 recompute when update_mode_lines is set too; that means
1425 that people can use force-mode-line-update to request
1426 that the menu bar be recomputed. The adverse effect on
1427 the rest of the redisplay algorithm is about the same as
1428 windows_or_buffers_changed anyway. */
1429 if (windows_or_buffers_changed
1430 || !NILP (w->update_mode_line)
1431 || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1432 < BUF_MODIFF (XBUFFER (w->buffer)))
1433 != !NILP (w->last_had_star))
1434 || ((!NILP (Vtransient_mark_mode)
1435 && !NILP (XBUFFER (w->buffer)->mark_active))
1436 != !NILP (w->region_showing)))
1438 struct buffer *prev = current_buffer;
1439 int count = specpdl_ptr - specpdl;
1441 set_buffer_internal_1 (XBUFFER (w->buffer));
1442 if (save_match_data)
1443 record_unwind_protect (Fstore_match_data, Fmatch_data (Qnil, Qnil));
1444 if (NILP (Voverriding_local_map_menu_flag))
1446 specbind (Qoverriding_terminal_local_map, Qnil);
1447 specbind (Qoverriding_local_map, Qnil);
1450 /* Run the Lucid hook. */
1451 call1 (Vrun_hooks, Qactivate_menubar_hook);
1452 /* If it has changed current-menubar from previous value,
1453 really recompute the menubar from the value. */
1454 if (! NILP (Vlucid_menu_bar_dirty_flag))
1455 call0 (Qrecompute_lucid_menubar);
1456 safe_run_hooks (Qmenu_bar_update_hook);
1457 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1458 /* Redisplay the menu bar in case we changed it. */
1459 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1460 if (FRAME_WINDOW_P (f))
1461 set_frame_menubar (f, 0, 0);
1462 else
1463 /* On a terminal screen, the menu bar is an ordinary screen
1464 line, and this makes it get updated. */
1465 w->update_mode_line = Qt;
1466 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1467 /* In the non-toolkit version, the menu bar is an ordinary screen
1468 line, and this makes it get updated. */
1469 w->update_mode_line = Qt;
1470 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1472 unbind_to (count, Qnil);
1473 set_buffer_internal_1 (prev);
1478 int do_id = 1;
1480 /* Redisplay WINDOW and its subwindows and siblings. */
1482 static void
1483 redisplay_windows (window, preserve_echo_area)
1484 Lisp_Object window;
1485 int preserve_echo_area;
1487 for (; !NILP (window); window = XWINDOW (window)->next)
1488 redisplay_window (window, 0, preserve_echo_area);
1491 /* Return value in display table DP (Lisp_Char_Table *) for character
1492 C. Since a display table doesn't have any parent, we don't have to
1493 follow parent. Do not call this function directly but use the
1494 macro DISP_CHAR_VECTOR. */
1495 Lisp_Object
1496 disp_char_vector (dp, c)
1497 struct Lisp_Char_Table *dp;
1498 int c;
1500 int code[4], i;
1501 Lisp_Object val;
1503 if (SINGLE_BYTE_CHAR_P (c)) return (dp->contents[c]);
1505 SPLIT_NON_ASCII_CHAR (c, code[0], code[1], code[2]);
1506 if (code[0] != CHARSET_COMPOSITION)
1508 if (code[1] < 32) code[1] = -1;
1509 else if (code[2] < 32) code[2] = -1;
1511 /* Here, the possible range of CODE[0] (== charset ID) is
1512 128..MAX_CHARSET. Since the top level char table contains data
1513 for multibyte characters after 256th element, we must increment
1514 CODE[0] by 128 to get a correct index. */
1515 code[0] += 128;
1516 code[3] = -1; /* anchor */
1518 for (i = 0; code[i] >= 0; i++, dp = XCHAR_TABLE (val))
1520 val = dp->contents[code[i]];
1521 if (!SUB_CHAR_TABLE_P (val))
1522 return (NILP (val) ? dp->defalt : val);
1524 /* Here, VAL is a sub char table. We return the default value of it. */
1525 return (dp->defalt);
1528 /* Redisplay window WINDOW and its subwindows. */
1530 static void
1531 redisplay_window (window, just_this_one, preserve_echo_area)
1532 Lisp_Object window;
1533 int just_this_one, preserve_echo_area;
1535 register struct window *w = XWINDOW (window);
1536 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1537 int height;
1538 register int lpoint = PT;
1539 struct buffer *old = current_buffer;
1540 register int width = window_internal_width (w) - 1;
1541 register int startp;
1542 register int hscroll = XINT (w->hscroll);
1543 struct position pos;
1544 int opoint = PT;
1545 int tem;
1546 int update_mode_line;
1547 struct Lisp_Char_Table *dp = window_display_table (w);
1549 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1551 /* If this is a combination window, do its children; that's all. */
1553 if (!NILP (w->vchild))
1555 redisplay_windows (w->vchild, preserve_echo_area);
1556 return;
1558 if (!NILP (w->hchild))
1560 redisplay_windows (w->hchild, preserve_echo_area);
1561 return;
1563 if (NILP (w->buffer))
1564 abort ();
1566 height = window_internal_height (w);
1567 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1568 if (XBUFFER (w->buffer)->clip_changed)
1569 update_mode_line = 1;
1571 if (MINI_WINDOW_P (w))
1573 if (w == XWINDOW (echo_area_window) && echo_area_glyphs)
1574 /* We've already displayed the echo area glyphs in this window. */
1575 goto finish_scroll_bars;
1576 else if (w != XWINDOW (minibuf_window))
1578 /* This is a minibuffer, but it's not the currently active one,
1579 so clear it. */
1580 int vpos = XFASTINT (w->top);
1581 int i;
1583 for (i = 0; i < height; i++)
1585 get_display_line (f, vpos + i, 0);
1586 display_string (w, vpos + i, "", 0,
1587 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
1588 0, 1, 0, width);
1591 goto finish_scroll_bars;
1595 /* Otherwise set up data on this window; select its buffer and point value */
1597 if (update_mode_line)
1598 set_buffer_internal_1 (XBUFFER (w->buffer));
1599 else
1600 set_buffer_temp (XBUFFER (w->buffer));
1602 opoint = PT;
1604 /* If %c is in mode line, update it if needed. */
1605 if (!NILP (w->column_number_displayed)
1606 /* This alternative quickly identifies a common case
1607 where no change is needed. */
1608 && !(PT == XFASTINT (w->last_point)
1609 && XFASTINT (w->last_modified) >= MODIFF
1610 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)
1611 && XFASTINT (w->column_number_displayed) != current_column ())
1612 update_mode_line = 1;
1614 /* Count number of windows showing the selected buffer.
1615 An indirect buffer counts as its base buffer. */
1617 if (!just_this_one)
1619 struct buffer *current_base, *window_base;
1620 current_base = current_buffer;
1621 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1622 if (current_base->base_buffer)
1623 current_base = current_base->base_buffer;
1624 if (window_base->base_buffer)
1625 window_base = window_base->base_buffer;
1626 if (current_base == window_base)
1627 buffer_shared++;
1630 /* POINT refers normally to the selected window.
1631 For any other window, set up appropriate value. */
1633 if (!EQ (window, selected_window))
1635 int new_pt = marker_position (w->pointm);
1636 if (new_pt < BEGV)
1638 new_pt = BEGV;
1639 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1641 else if (new_pt > (ZV - 1))
1643 new_pt = ZV;
1644 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1646 /* We don't use SET_PT so that the point-motion hooks don't run. */
1647 BUF_PT (current_buffer) = new_pt;
1650 /* If any of the character widths specified in the display table
1651 have changed, invalidate the width run cache. It's true that this
1652 may be a bit late to catch such changes, but the rest of
1653 redisplay goes (non-fatally) haywire when the display table is
1654 changed, so why should we worry about doing any better? */
1655 if (current_buffer->width_run_cache)
1657 struct Lisp_Char_Table *disptab = buffer_display_table ();
1659 if (! disptab_matches_widthtab (disptab,
1660 XVECTOR (current_buffer->width_table)))
1662 invalidate_region_cache (current_buffer,
1663 current_buffer->width_run_cache,
1664 BEG, Z);
1665 recompute_width_table (current_buffer, disptab);
1669 /* If window-start is screwed up, choose a new one. */
1670 if (XMARKER (w->start)->buffer != current_buffer)
1671 goto recenter;
1673 startp = marker_position (w->start);
1675 /* If someone specified a new starting point but did not insist,
1676 check whether it can be used. */
1677 if (!NILP (w->optional_new_start))
1679 w->optional_new_start = Qnil;
1680 /* Check whether this start pos is usable given where point is. */
1682 pos = *compute_motion (startp, 0,
1683 (((EQ (window, minibuf_window)
1684 && startp == BEG)
1685 ? minibuf_prompt_width : 0)
1686 + (hscroll ? 1 - hscroll : 0)),
1688 PT, height,
1689 /* BUG FIX: See the comment of
1690 Fpos_visible_in_window_p (window.c). */
1691 - (1 << (BITS_PER_SHORT - 1)),
1692 width, hscroll, pos_tab_offset (w, startp), w);
1693 /* If PT does fit on the screen, we will use this start pos,
1694 so do so by setting force_start. */
1695 if (pos.bufpos == PT)
1696 w->force_start = Qt;
1699 /* Handle case where place to start displaying has been specified,
1700 unless the specified location is outside the accessible range. */
1701 if (!NILP (w->force_start))
1703 w->force_start = Qnil;
1704 /* Forget any recorded base line for line number display. */
1705 w->base_line_number = Qnil;
1706 /* Redisplay the mode line. Select the buffer properly for that.
1707 Also, run the hook window-scroll-functions
1708 because we have scrolled. */
1709 /* Note, we do this after clearing force_start because
1710 if there's an error, it is better to forget about force_start
1711 than to get into an infinite loop calling the hook functions
1712 and having them get more errors. */
1713 if (!update_mode_line
1714 || ! NILP (Vwindow_scroll_functions))
1716 Lisp_Object temp[3];
1718 set_buffer_temp (old);
1719 set_buffer_internal_1 (XBUFFER (w->buffer));
1720 update_mode_line = 1;
1721 w->update_mode_line = Qt;
1722 if (! NILP (Vwindow_scroll_functions))
1724 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1725 make_number (startp));
1726 startp = marker_position (w->start);
1729 XSETFASTINT (w->last_modified, 0);
1730 XSETFASTINT (w->last_overlay_modified, 0);
1731 if (startp < BEGV) startp = BEGV;
1732 if (startp > ZV) startp = ZV;
1733 try_window (window, startp);
1734 if (cursor_vpos < 0)
1736 /* If point does not appear, move point so it does appear */
1737 pos = *compute_motion (startp, 0,
1738 (((EQ (window, minibuf_window)
1739 && startp == BEG)
1740 ? minibuf_prompt_width : 0)
1741 + (hscroll ? 1 - hscroll : 0)),
1743 ZV, height / 2,
1744 - (1 << (BITS_PER_SHORT - 1)),
1745 width, hscroll, pos_tab_offset (w, startp), w);
1746 BUF_PT (current_buffer) = pos.bufpos;
1747 if (w != XWINDOW (selected_window))
1748 Fset_marker (w->pointm, make_number (PT), Qnil);
1749 else
1751 if (current_buffer == old)
1752 lpoint = PT;
1753 FRAME_CURSOR_X (f) = (WINDOW_LEFT_MARGIN (w)
1754 + minmax (0, pos.hpos, width));
1755 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1757 /* If we are highlighting the region,
1758 then we just changed the region, so redisplay to show it. */
1759 if (!NILP (Vtransient_mark_mode)
1760 && !NILP (current_buffer->mark_active))
1762 cancel_my_columns (XWINDOW (window));
1763 try_window (window, startp);
1766 goto done;
1769 /* Handle case where text has not changed, only point,
1770 and it has not moved off the frame. */
1772 /* This code is not used for minibuffer for the sake of
1773 the case of redisplaying to replace an echo area message;
1774 since in that case the minibuffer contents per se are usually unchanged.
1775 This code is of no real use in the minibuffer since
1776 the handling of this_line_bufpos, etc.,
1777 in redisplay handles the same cases. */
1779 if (XFASTINT (w->last_modified) >= MODIFF
1780 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF
1781 && PT >= startp && !current_buffer->clip_changed
1782 && (just_this_one || WINDOW_FULL_WIDTH_P (w))
1783 /* If force-mode-line-update was called, really redisplay;
1784 that's how redisplay is forced after e.g. changing
1785 buffer-invisibility-spec. */
1786 && NILP (w->update_mode_line)
1787 /* Can't use this case if highlighting a region. */
1788 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1789 && NILP (w->region_showing)
1790 /* If end pos is out of date, scroll bar and percentage will be wrong */
1791 && INTEGERP (w->window_end_vpos)
1792 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1793 && !EQ (window, minibuf_window))
1795 int this_scroll_margin = scroll_margin;
1797 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0,
1798 PT, height,
1799 /* BUG FIX: See the comment of
1800 Fpos_visible_in_window_p (window.c). */
1801 - (1 << (BITS_PER_SHORT - 1)),
1802 width, hscroll,
1803 pos_tab_offset (w, startp), w);
1805 /* Don't use a scroll margin that is negative or too large. */
1806 if (this_scroll_margin < 0)
1807 this_scroll_margin = 0;
1809 if (XINT (w->height) < 4 * scroll_margin)
1810 this_scroll_margin = XINT (w->height) / 4;
1812 /* If point fits on the screen, and not within the scroll margin,
1813 we are ok. */
1814 if (pos.vpos < height - this_scroll_margin
1815 && (pos.vpos >= this_scroll_margin || startp == BEGV))
1817 /* Ok, point is still on frame */
1818 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1820 /* These variables are supposed to be origin 1 */
1821 FRAME_CURSOR_X (f) = (WINDOW_LEFT_MARGIN (w)
1822 + minmax (0, pos.hpos, width));
1823 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1825 /* This doesn't do the trick, because if a window to the right of
1826 this one must be redisplayed, this does nothing because there
1827 is nothing in DesiredFrame yet, and then the other window is
1828 redisplayed, making likes that are empty in this window's columns.
1829 if (WINDOW_FULL_WIDTH_P (w))
1830 preserve_my_columns (w);
1832 goto done;
1834 /* Don't bother trying redisplay with same start;
1835 we already know it will lose */
1837 /* If current starting point was originally the beginning of a line
1838 but no longer is, find a new starting point. */
1839 else if (!NILP (w->start_at_line_beg)
1840 && !(startp <= BEGV
1841 || FETCH_BYTE (startp - 1) == '\n'))
1843 goto recenter;
1845 else if (just_this_one && !MINI_WINDOW_P (w)
1846 && PT >= startp
1847 && XFASTINT (w->last_modified)
1848 /* or else vmotion on first line won't work. */
1849 && ! NILP (w->start_at_line_beg)
1850 && ! EQ (w->window_end_valid, Qnil)
1851 && do_id && !current_buffer->clip_changed
1852 && !blank_end_of_window
1853 && WINDOW_FULL_WIDTH_P (w)
1854 /* Can't use this case if highlighting a region. */
1855 && !(!NILP (Vtransient_mark_mode)
1856 && !NILP (current_buffer->mark_active))
1857 /* Don't use try_window_id if newline
1858 doesn't display as the end of a line. */
1859 && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n')))
1860 && NILP (w->region_showing)
1861 && EQ (last_arrow_position, Voverlay_arrow_position)
1862 && EQ (last_arrow_string, Voverlay_arrow_string)
1863 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1864 && tem != -2)
1866 /* tem > 0 means success. tem == -1 means choose new start.
1867 tem == -2 means try again with same start,
1868 and nothing but whitespace follows the changed stuff.
1869 tem == 0 means try again with same start. */
1870 if (tem > 0)
1871 goto done;
1873 else if (startp >= BEGV && startp <= ZV
1874 && (startp < ZV
1875 /* Avoid starting at end of buffer. */
1876 #if 0 /* This change causes trouble for M-! finger & RET.
1877 It will have to be considered later. */
1878 || ! EQ (window, selected_window)
1879 /* Don't do the recentering if redisplay
1880 is not for no user action. */
1881 || preserve_echo_area
1882 #endif
1883 || startp == BEGV
1884 || (XFASTINT (w->last_modified) >= MODIFF
1885 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)))
1887 /* Try to redisplay starting at same place as before */
1888 /* If point has not moved off frame, accept the results */
1889 try_window (window, startp);
1890 if (cursor_vpos >= 0)
1892 if (!just_this_one || current_buffer->clip_changed
1893 || beg_unchanged < startp)
1894 /* Forget any recorded base line for line number display. */
1895 w->base_line_number = Qnil;
1896 goto done;
1898 else
1899 cancel_my_columns (w);
1902 XSETFASTINT (w->last_modified, 0);
1903 XSETFASTINT (w->last_overlay_modified, 0);
1904 /* Redisplay the mode line. Select the buffer properly for that. */
1905 if (!update_mode_line)
1907 set_buffer_temp (old);
1908 set_buffer_internal_1 (XBUFFER (w->buffer));
1909 update_mode_line = 1;
1910 w->update_mode_line = Qt;
1913 /* Try to scroll by specified few lines */
1915 if (scroll_conservatively && !current_buffer->clip_changed
1916 && startp >= BEGV && startp <= ZV)
1918 int this_scroll_margin = scroll_margin;
1920 /* Don't use a scroll margin that is negative or too large. */
1921 if (this_scroll_margin < 0)
1922 this_scroll_margin = 0;
1924 if (XINT (w->height) < 4 * scroll_margin)
1925 this_scroll_margin = XINT (w->height) / 4;
1927 if (PT >= Z - XFASTINT (w->window_end_pos))
1929 struct position pos;
1930 pos = *compute_motion (Z - XFASTINT (w->window_end_pos), 0, 0, 0,
1931 PT, XFASTINT (w->height), 0,
1932 XFASTINT (w->width), XFASTINT (w->hscroll),
1933 pos_tab_offset (w, startp), w);
1934 if (pos.vpos > scroll_conservatively)
1935 goto scroll_fail_1;
1937 pos = *vmotion (startp, pos.vpos + 1 + this_scroll_margin, w);
1939 if (! NILP (Vwindow_scroll_functions))
1941 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
1942 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1943 make_number (pos.bufpos));
1944 pos.bufpos = marker_position (w->start);
1946 try_window (window, pos.bufpos);
1947 if (cursor_vpos >= 0)
1949 if (!just_this_one || current_buffer->clip_changed
1950 || beg_unchanged < startp)
1951 /* Forget any recorded base line for line number display. */
1952 w->base_line_number = Qnil;
1953 goto done;
1955 else
1956 cancel_my_columns (w);
1958 if (PT < startp)
1960 struct position pos;
1961 pos = *compute_motion (PT, 0, 0, 0,
1962 startp, XFASTINT (w->height), 0,
1963 XFASTINT (w->width), XFASTINT (w->hscroll),
1964 pos_tab_offset (w, startp), w);
1965 if (pos.vpos >= scroll_conservatively)
1966 goto scroll_fail_1;
1968 pos = *vmotion (startp, - pos.vpos - this_scroll_margin, w);
1970 if (! NILP (Vwindow_scroll_functions))
1972 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
1973 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1974 make_number (pos.bufpos));
1975 pos.bufpos = marker_position (w->start);
1977 try_window (window, pos.bufpos);
1978 if (cursor_vpos >= 0)
1980 if (!just_this_one || current_buffer->clip_changed
1981 || beg_unchanged < startp)
1982 /* Forget any recorded base line for line number display. */
1983 w->base_line_number = Qnil;
1984 goto done;
1986 else
1987 cancel_my_columns (w);
1989 scroll_fail_1: ;
1992 if (scroll_step && !current_buffer->clip_changed
1993 && startp >= BEGV && startp <= ZV)
1995 if (PT > startp)
1997 pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w);
1998 if (pos.vpos >= height)
1999 goto scroll_fail;
2002 pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w);
2004 if (PT >= pos.bufpos)
2006 if (! NILP (Vwindow_scroll_functions))
2008 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
2009 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2010 make_number (pos.bufpos));
2011 pos.bufpos = marker_position (w->start);
2013 try_window (window, pos.bufpos);
2014 if (cursor_vpos >= 0)
2016 if (!just_this_one || current_buffer->clip_changed
2017 || beg_unchanged < startp)
2018 /* Forget any recorded base line for line number display. */
2019 w->base_line_number = Qnil;
2020 goto done;
2022 else
2023 cancel_my_columns (w);
2025 scroll_fail: ;
2028 /* Finally, just choose place to start which centers point */
2030 recenter:
2031 /* Forget any previously recorded base line for line number display. */
2032 w->base_line_number = Qnil;
2034 pos = *vmotion (PT, - (height / 2), w);
2035 /* Set startp here explicitly in case that helps avoid an infinite loop
2036 in case the window-scroll-functions functions get errors. */
2037 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
2038 if (! NILP (Vwindow_scroll_functions))
2040 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2041 make_number (pos.bufpos));
2042 pos.bufpos = marker_position (w->start);
2044 try_window (window, pos.bufpos);
2046 startp = marker_position (w->start);
2047 w->start_at_line_beg
2048 = (startp == BEGV || FETCH_BYTE (startp - 1) == '\n') ? Qt : Qnil;
2050 done:
2051 if ((update_mode_line
2052 /* If window not full width, must redo its mode line
2053 if the window to its side is being redone */
2054 || (!just_this_one && !WINDOW_FULL_WIDTH_P (w))
2055 || INTEGERP (w->base_line_pos)
2056 || (!NILP (w->column_number_displayed)
2057 && XFASTINT (w->column_number_displayed) != current_column ()))
2058 && height != XFASTINT (w->height))
2059 display_mode_line (w);
2060 if (! line_number_displayed
2061 && ! BUFFERP (w->base_line_pos))
2063 w->base_line_pos = Qnil;
2064 w->base_line_number = Qnil;
2067 /* When we reach a frame's selected window, redo the frame's menu bar. */
2068 if (update_mode_line
2069 && (FRAME_WINDOW_P (f)
2071 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2072 FRAME_EXTERNAL_MENU_BAR (f)
2073 #else
2074 FRAME_MENU_BAR_LINES (f) > 0
2075 #endif
2076 : FRAME_MENU_BAR_LINES (f) > 0)
2077 && EQ (FRAME_SELECTED_WINDOW (f), window))
2078 display_menu_bar (w);
2080 finish_scroll_bars:
2081 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
2083 int start, end, whole;
2085 /* Calculate the start and end positions for the current window.
2086 At some point, it would be nice to choose between scrollbars
2087 which reflect the whole buffer size, with special markers
2088 indicating narrowing, and scrollbars which reflect only the
2089 visible region.
2091 Note that minibuffers sometimes aren't displaying any text. */
2092 if (! MINI_WINDOW_P (w)
2093 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
2095 whole = ZV - BEGV;
2096 start = marker_position (w->start) - BEGV;
2097 /* I don't think this is guaranteed to be right. For the
2098 moment, we'll pretend it is. */
2099 end = (Z - XINT (w->window_end_pos)) - BEGV;
2101 if (end < start) end = start;
2102 if (whole < (end - start)) whole = end - start;
2104 else
2105 start = end = whole = 0;
2107 /* Indicate what this scroll bar ought to be displaying now. */
2108 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
2110 /* Note that we actually used the scroll bar attached to this window,
2111 so it shouldn't be deleted at the end of redisplay. */
2112 (*redeem_scroll_bar_hook) (w);
2115 BUF_PT (current_buffer) = opoint;
2116 if (update_mode_line)
2117 set_buffer_internal_1 (old);
2118 else
2119 set_buffer_temp (old);
2120 BUF_PT (current_buffer) = lpoint;
2123 /* Do full redisplay on one window, starting at position `pos'. */
2125 static void
2126 try_window (window, pos)
2127 Lisp_Object window;
2128 register int pos;
2130 register struct window *w = XWINDOW (window);
2131 register int height = window_internal_height (w);
2132 register int vpos = XFASTINT (w->top);
2133 register int last_text_vpos = vpos;
2134 FRAME_PTR f = XFRAME (w->frame);
2135 int width = window_internal_width (w) - 1;
2136 struct position val;
2138 /* POS should never be out of range! */
2139 if (pos < XBUFFER (w->buffer)->begv
2140 || pos > XBUFFER (w->buffer)->zv)
2141 abort ();
2143 Fset_marker (w->start, make_number (pos), Qnil);
2144 cursor_vpos = -1;
2145 overlay_arrow_seen = 0;
2146 zv_strings_seen = 0;
2147 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2148 val.ovstring_chars_done = 0;
2149 val.tab_offset = pos_tab_offset (w, pos);
2151 while (--height >= 0)
2153 val = *display_text_line (w, pos, vpos, val.hpos, val.tab_offset,
2154 val.ovstring_chars_done);
2155 /* The following code is omitted because we maintain tab_offset
2156 in VAL. */
2157 #if 0
2158 tab_offset += width;
2159 if (val.vpos) tab_offset = 0;
2160 #endif /* 0 */
2161 vpos++;
2162 if (pos != val.bufpos)
2164 int invis = 0;
2165 #ifdef USE_TEXT_PROPERTIES
2166 Lisp_Object invis_prop;
2167 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
2168 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
2169 #endif
2171 last_text_vpos
2172 /* Next line, unless prev line ended in end of buffer with no cr */
2173 = vpos - (val.vpos
2174 && (FETCH_BYTE (val.bufpos - 1) != '\n' || invis));
2176 pos = val.bufpos;
2179 /* If last line is continued in middle of character,
2180 include the split character in the text considered on the frame */
2181 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2182 pos++;
2184 /* If bottom just moved off end of frame, change mode line percentage. */
2185 if (XFASTINT (w->window_end_pos) == 0
2186 && Z != pos)
2187 w->update_mode_line = Qt;
2189 /* Say where last char on frame will be, once redisplay is finished. */
2190 XSETFASTINT (w->window_end_pos, Z - pos);
2191 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
2192 /* But that is not valid info until redisplay finishes. */
2193 w->window_end_valid = Qnil;
2196 /* Try to redisplay when buffer is modified locally,
2197 computing insert/delete line to preserve text outside
2198 the bounds of the changes.
2199 Return 1 if successful, 0 if if cannot tell what to do,
2200 or -1 to tell caller to find a new window start,
2201 or -2 to tell caller to do normal redisplay with same window start. */
2203 static int
2204 try_window_id (window)
2205 Lisp_Object window;
2207 int pos;
2208 register struct window *w = XWINDOW (window);
2209 register int height = window_internal_height (w);
2210 FRAME_PTR f = XFRAME (w->frame);
2211 int top = XFASTINT (w->top);
2212 int start = marker_position (w->start);
2213 int width = window_internal_width (w) - 1;
2214 int hscroll = XINT (w->hscroll);
2215 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
2216 int did_motion;
2217 register int vpos;
2218 register int i, tem;
2219 int last_text_vpos = 0;
2220 int stop_vpos;
2221 int selective = (INTEGERP (current_buffer->selective_display)
2222 ? XINT (current_buffer->selective_display)
2223 : !NILP (current_buffer->selective_display) ? -1 : 0);
2225 struct position val, bp, ep, xp, pp;
2226 int scroll_amount = 0;
2227 int delta;
2228 int epto, old_tick;
2230 if (GPT - BEG < beg_unchanged)
2231 beg_unchanged = GPT - BEG;
2232 if (Z - GPT < end_unchanged)
2233 end_unchanged = Z - GPT;
2235 if (beg_unchanged + BEG < start)
2236 return 0; /* Give up if changes go above top of window */
2238 /* Find position before which nothing is changed. */
2239 bp = *compute_motion (start, 0, lmargin, 0,
2240 min (ZV, beg_unchanged + BEG), height,
2241 /* BUG FIX: See the comment of
2242 Fpos_visible_in_window_p() (window.c). */
2243 - (1 << (BITS_PER_SHORT - 1)),
2244 width, hscroll, pos_tab_offset (w, start), w);
2245 if (bp.vpos >= height)
2247 if (PT < bp.bufpos)
2249 /* All changes are beyond the window end, and point is on the screen.
2250 We don't need to change the text at all.
2251 But we need to update window_end_pos to account for
2252 any change in buffer size. */
2253 bp = *compute_motion (start, 0, lmargin, 0,
2254 ZV, height,
2255 /* BUG FIX: See the comment of
2256 Fpos_visible_in_window_p() (window.c). */
2257 - (1 << (BITS_PER_SHORT - 1)),
2258 width, hscroll, pos_tab_offset (w, start), w);
2259 XSETFASTINT (w->window_end_vpos, height);
2260 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
2261 goto findpoint;
2263 return 0;
2266 vpos = bp.vpos;
2268 /* Find beginning of that frame line. Must display from there. */
2269 bp = *vmotion (bp.bufpos, 0, w);
2271 pos = bp.bufpos;
2272 val.hpos = lmargin;
2273 if (pos < start)
2274 return -1;
2276 did_motion = 0;
2277 /* If about to start displaying at the beginning of a continuation line,
2278 really start with previous frame line, in case it was not
2279 continued when last redisplayed */
2280 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
2282 /* Likewise if we have to worry about selective display. */
2283 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
2285 bp = *vmotion (bp.bufpos, -1, w);
2286 --vpos;
2287 pos = bp.bufpos;
2289 val.tab_offset = bp.tab_offset; /* Update tab offset. */
2291 if (bp.contin && bp.hpos != lmargin)
2293 val.hpos = bp.prevhpos - width + lmargin;
2294 val.tab_offset = bp.tab_offset + bp.prevhpos - width;
2295 did_motion = 1;
2296 DEC_POS (pos);
2299 bp.vpos = vpos;
2301 /* Find first visible newline after which no more is changed. */
2302 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
2303 if (selective > 0)
2304 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
2305 tem = find_next_newline (tem, 1);
2307 /* Compute the cursor position after that newline. */
2308 ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem,
2309 height, - (1 << (BITS_PER_SHORT - 1)),
2310 width, hscroll,
2311 /* We have tab offset in VAL, use it. */
2312 val.tab_offset, w);
2314 /* If changes reach past the text available on the frame,
2315 just display rest of frame. */
2316 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
2317 stop_vpos = height;
2318 else
2319 stop_vpos = ep.vpos;
2321 /* If no newline before ep, the line ep is on includes some changes
2322 that must be displayed. Make sure we don't stop before it. */
2323 /* Also, if changes reach all the way until ep.bufpos,
2324 it is possible that something was deleted after the
2325 newline before it, so the following line must be redrawn. */
2326 if (stop_vpos == ep.vpos
2327 && (ep.bufpos == BEGV
2328 || FETCH_BYTE (ep.bufpos - 1) != '\n'
2329 || ep.bufpos == Z - end_unchanged))
2330 stop_vpos = ep.vpos + 1;
2332 cursor_vpos = -1;
2333 overlay_arrow_seen = 0;
2334 zv_strings_seen = 0;
2336 /* If changes do not reach to bottom of window,
2337 figure out how much to scroll the rest of the window */
2338 if (stop_vpos < height)
2340 /* Now determine how far up or down the rest of the window has moved */
2341 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2342 Z - XFASTINT (w->window_end_pos),
2343 /* Don't care for VPOS... */
2344 1 << (BITS_PER_SHORT - 1),
2345 /* ... nor HPOS. */
2346 1 << (BITS_PER_SHORT - 1),
2347 width, hscroll, ep.tab_offset, w);
2348 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
2350 /* Is everything on frame below the changes whitespace?
2351 If so, no scrolling is really necessary. */
2352 for (i = ep.bufpos; i < xp.bufpos; i++)
2354 tem = FETCH_BYTE (i);
2355 if (tem != ' ' && tem != '\n' && tem != '\t')
2356 break;
2358 if (i == xp.bufpos)
2359 return -2;
2361 XSETFASTINT (w->window_end_vpos,
2362 XFASTINT (w->window_end_vpos) + scroll_amount);
2364 /* Before doing any scrolling, verify that point will be on frame. */
2365 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.vpos < height))
2367 if (PT <= xp.bufpos)
2369 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2370 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2371 width, hscroll,
2372 /* We have tab offset in EP, use it. */
2373 ep.tab_offset, w);
2375 else
2377 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1,
2378 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2379 width, hscroll,
2380 /* We have tab offset in XP, use it. */
2381 xp.tab_offset, w);
2383 if (pp.bufpos < PT || pp.vpos == height)
2384 return 0;
2385 cursor_vpos = pp.vpos + top;
2386 cursor_hpos = WINDOW_LEFT_MARGIN (w) + minmax (0, pp.hpos, width);
2389 if (stop_vpos - scroll_amount >= height
2390 || ep.bufpos == xp.bufpos)
2392 if (scroll_amount < 0)
2393 stop_vpos -= scroll_amount;
2394 scroll_amount = 0;
2395 /* In this path, we have altered window_end_vpos
2396 and not left it negative.
2397 We must make sure that, in case display is preempted
2398 before the frame changes to reflect what we do here,
2399 further updates will not come to try_window_id
2400 and assume the frame and window_end_vpos match. */
2401 blank_end_of_window = 1;
2403 else if (!scroll_amount)
2405 /* Even if we don't need to scroll, we must adjust the
2406 charstarts of subsequent lines (that we won't redisplay)
2407 according to the amount of text inserted or deleted. */
2408 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2409 int adjust = ep.bufpos - oldpos;
2410 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
2412 else if (bp.bufpos == Z - end_unchanged)
2414 /* If reprinting everything is nearly as fast as scrolling,
2415 don't bother scrolling. Can happen if lines are short. */
2416 if (scroll_cost (f, bp.vpos + top - scroll_amount,
2417 top + height - max (0, scroll_amount),
2418 scroll_amount)
2419 > xp.bufpos - bp.bufpos - 20)
2420 /* Return "try normal display with same window-start."
2421 Too bad we can't prevent further scroll-thinking. */
2422 return -2;
2423 /* If pure deletion, scroll up as many lines as possible.
2424 In common case of killing a line, this can save the
2425 following line from being overwritten by scrolling
2426 and therefore having to be redrawn. */
2427 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
2428 top + height - max (0, scroll_amount),
2429 scroll_amount, bp.bufpos);
2430 if (!tem)
2431 stop_vpos = height;
2432 else
2434 /* scroll_frame_lines did not properly adjust subsequent
2435 lines' charstarts in the case where the text of the
2436 screen line at bp.vpos has changed.
2437 (This can happen in a deletion that ends in mid-line.)
2438 To adjust properly, we need to make things consistent
2439 at the position ep.
2440 So do a second adjust to make that happen.
2441 Note that stop_vpos >= ep.vpos, so it is sufficient
2442 to update the charstarts for lines at ep.vpos and below. */
2443 int oldstart
2444 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2445 adjust_window_charstarts (w, ep.vpos + top - 1,
2446 ep.bufpos - oldstart);
2449 else if (scroll_amount)
2451 /* If reprinting everything is nearly as fast as scrolling,
2452 don't bother scrolling. Can happen if lines are short. */
2453 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2454 overestimate of cost of reprinting, since xp.bufpos
2455 would end up below the bottom of the window. */
2456 if (scroll_cost (f, ep.vpos + top - scroll_amount,
2457 top + height - max (0, scroll_amount),
2458 scroll_amount)
2459 > xp.bufpos - ep.bufpos - 20)
2460 /* Return "try normal display with same window-start."
2461 Too bad we can't prevent further scroll-thinking. */
2462 return -2;
2463 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
2464 top + height - max (0, scroll_amount),
2465 scroll_amount, ep.bufpos);
2466 if (!tem) stop_vpos = height;
2470 /* In any case, do not display past bottom of window */
2471 if (stop_vpos >= height)
2473 stop_vpos = height;
2474 scroll_amount = 0;
2477 /* Handle case where pos is before w->start --
2478 can happen if part of line had been clipped and is not clipped now */
2479 if (vpos == 0 && pos < marker_position (w->start))
2480 Fset_marker (w->start, make_number (pos), Qnil);
2482 /* Redisplay the lines where the text was changed */
2483 last_text_vpos = vpos;
2484 /* The following code is omitted because we maintain tab offset in
2485 val.tab_offset. */
2486 #if 0
2487 tab_offset = pos_tab_offset (w, pos);
2488 /* If we are starting display in mid-character, correct tab_offset
2489 to account for passing the line that that character really starts in. */
2490 if (val.hpos < lmargin)
2491 tab_offset += width;
2492 #endif /* 0 */
2493 old_tick = MODIFF;
2494 while (vpos < stop_vpos)
2496 val = *display_text_line (w, pos, top + vpos++, val.hpos, val.tab_offset,
2497 val.ovstring_chars_done);
2498 /* If display_text_line ran a hook and changed some text,
2499 redisplay all the way to bottom of buffer
2500 So that we show the changes. */
2501 if (old_tick != MODIFF)
2502 stop_vpos = height;
2503 /* The following code is omitted because we maintain tab offset
2504 in val.tab_offset. */
2505 #if 0
2506 tab_offset += width;
2507 if (val.vpos) tab_offset = 0;
2508 #endif
2509 if (pos != val.bufpos)
2510 last_text_vpos
2511 /* Next line, unless prev line ended in end of buffer with no cr */
2512 = vpos - (val.vpos && FETCH_BYTE (val.bufpos - 1) != '\n');
2513 pos = val.bufpos;
2516 /* There are two cases:
2517 1) we have displayed down to the bottom of the window
2518 2) we have scrolled lines below stop_vpos by scroll_amount */
2520 if (vpos == height)
2522 /* If last line is continued in middle of character,
2523 include the split character in the text considered on the frame */
2524 if (val.hpos < lmargin)
2525 val.bufpos++;
2526 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2527 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2530 /* If scrolling made blank lines at window bottom,
2531 redisplay to fill those lines */
2532 if (scroll_amount < 0)
2534 /* Don't consider these lines for general-purpose scrolling.
2535 That will save time in the scrolling computation. */
2536 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2537 vpos = xp.vpos;
2538 pos = xp.bufpos;
2539 val.hpos = xp.hpos;
2540 val.tab_offset = xp.tab_offset;
2541 if (pos == ZV)
2542 { /* Display from next line */
2543 vpos = height + scroll_amount;
2544 val.hpos = lmargin;
2545 val.tab_offset = 0;
2547 else if (xp.contin && xp.hpos != lmargin)
2549 val.hpos = xp.prevhpos - width + lmargin;
2550 val.tab_offset = xp.tab_offset + bp.prevhpos - width;
2551 DEC_POS (pos);
2554 blank_end_of_window = 1;
2555 /* The following code is omitted because we maintain tab offset
2556 in val.tab_offset. */
2557 #if 0
2558 tab_offset = pos_tab_offset (w, pos);
2559 /* If we are starting display in mid-character, correct tab_offset
2560 to account for passing the line that that character starts in. */
2561 if (val.hpos < lmargin)
2562 tab_offset += width;
2563 #endif
2564 while (vpos < height)
2566 val = *display_text_line (w, pos, top + vpos++, val.hpos,
2567 val.tab_offset, val.ovstring_chars_done);
2568 /* The following code is omitted because we maintain tab
2569 offset in val.tab_offset. */
2570 #if 0
2571 tab_offset += width;
2572 if (val.vpos) tab_offset = 0;
2573 #endif /* 0 */
2574 pos = val.bufpos;
2577 /* Here is a case where display_text_line sets cursor_vpos wrong.
2578 Make it be fixed up, below. */
2579 if (xp.bufpos == ZV
2580 && xp.bufpos == PT)
2581 cursor_vpos = -1;
2584 /* If bottom just moved off end of frame, change mode line percentage. */
2585 if (XFASTINT (w->window_end_pos) == 0
2586 && Z != val.bufpos)
2587 w->update_mode_line = Qt;
2589 /* Attempt to adjust end-of-text positions to new bottom line */
2590 if (scroll_amount)
2592 delta = height - xp.vpos;
2593 if (delta < 0
2594 || (delta > 0 && xp.bufpos <= ZV)
2595 || (delta == 0 && xp.hpos))
2597 val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w);
2598 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2599 XSETFASTINT (w->window_end_vpos,
2600 XFASTINT (w->window_end_vpos) + val.vpos);
2604 w->window_end_valid = Qnil;
2606 /* If point was not in a line that was displayed, find it */
2607 if (cursor_vpos < 0)
2609 findpoint:
2610 val = *compute_motion (start, 0, lmargin, 0, PT,
2611 /* Don't care for VPOS... */
2612 1 << (BITS_PER_SHORT - 1),
2613 /* ... nor HPOS. */
2614 1 << (BITS_PER_SHORT - 1),
2615 width, hscroll, pos_tab_offset (w, start), w);
2616 /* Admit failure if point is off frame now */
2617 if (val.vpos >= height)
2619 for (vpos = 0; vpos < height; vpos++)
2620 cancel_line (vpos + top, f);
2621 return 0;
2623 cursor_vpos = val.vpos + top;
2624 cursor_hpos = WINDOW_LEFT_MARGIN (w) + minmax (0, val.hpos, width);
2627 FRAME_CURSOR_X (f) = cursor_hpos;
2628 FRAME_CURSOR_Y (f) = cursor_vpos;
2630 if (debug_end_pos)
2632 val = *compute_motion (start, 0, lmargin, 0, ZV,
2633 height, - (1 << (BITS_PER_SHORT - 1)),
2634 width, hscroll, pos_tab_offset (w, start), w);
2635 if (val.vpos != XFASTINT (w->window_end_vpos))
2636 abort ();
2637 if (XFASTINT (w->window_end_pos)
2638 != Z - val.bufpos)
2639 abort ();
2642 return 1;
2645 /* Copy LEN glyphs starting address FROM to the rope TO.
2646 But don't actually copy the parts that would come in before S.
2647 Value is TO, advanced past the copied data.
2648 F is the frame we are displaying in. */
2650 static GLYPH *
2651 copy_part_of_rope (f, to, s, from, len, face)
2652 FRAME_PTR f;
2653 register GLYPH *to; /* Copy to here. */
2654 register GLYPH *s; /* Starting point. */
2655 Lisp_Object *from; /* Data to copy. */
2656 int len;
2657 int face; /* Face to apply to glyphs which don't specify one. */
2659 int n = len;
2660 register Lisp_Object *fp = from;
2661 /* These cache the results of the last call to compute_glyph_face. */
2662 int last_code = -1;
2663 int last_merged = 0;
2665 #ifdef HAVE_FACES
2666 if (! FRAME_TERMCAP_P (f))
2667 while (n--)
2669 GLYPH glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2670 int facecode;
2671 unsigned int c = FAST_GLYPH_CHAR (glyph);
2673 if (c > MAX_CHAR)
2674 /* For an invalid character code, use space. */
2675 c = ' ';
2677 if (FAST_GLYPH_FACE (glyph) == 0)
2678 /* If GLYPH has no face code, use FACE. */
2679 facecode = face;
2680 else if (FAST_GLYPH_FACE (glyph) == last_code)
2681 /* If it's same as previous glyph, use same result. */
2682 facecode = last_merged;
2683 else
2685 /* Merge this glyph's face and remember the result. */
2686 last_code = FAST_GLYPH_FACE (glyph);
2687 last_merged = facecode = compute_glyph_face (f, last_code, face);
2690 if (to >= s)
2691 *to = FAST_MAKE_GLYPH (c, facecode);
2692 ++to;
2693 ++fp;
2695 else
2696 #endif
2697 while (n--)
2699 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2700 ++to;
2701 ++fp;
2703 return to;
2706 /* Correct a glyph by replacing its specified user-level face code
2707 with a displayable computed face code. */
2709 static GLYPH
2710 fix_glyph (f, glyph, cface)
2711 FRAME_PTR f;
2712 GLYPH glyph;
2713 int cface;
2715 #ifdef HAVE_FACES
2716 if (! FRAME_TERMCAP_P (f))
2718 if (FAST_GLYPH_FACE (glyph) != 0)
2719 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2720 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2722 #endif
2723 return glyph;
2726 /* Display one line of window W, starting at position START in W's buffer.
2728 Display starting at horizontal position HPOS, expressed relative to
2729 W's left edge. In situations where the text at START shouldn't
2730 start at the left margin (i.e. when the window is hscrolled, or
2731 we're continuing a line which left off in the midst of a
2732 multi-column character), HPOS should be negative; we throw away
2733 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2734 account.
2736 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2738 OVSTR_DONE is the number of chars of overlay before/after strings
2739 at this position which have already been processed.
2741 Display on position VPOS on the frame. It is origin 0, relative to
2742 the top of the frame, not W.
2744 Returns a STRUCT POSITION giving character to start next line with
2745 and where to display it, including a zero or negative hpos.
2746 The vpos field is not really a vpos; it is 1 unless the line is continued */
2748 struct position val_display_text_line;
2750 static struct position *
2751 display_text_line (w, start, vpos, hpos, taboffset, ovstr_done)
2752 struct window *w;
2753 int start;
2754 int vpos;
2755 int hpos;
2756 int taboffset;
2757 int ovstr_done;
2759 register int pos = start;
2760 register int c;
2761 register GLYPH *p1;
2762 register int pause;
2763 register unsigned char *p;
2764 GLYPH *endp;
2765 register GLYPH *leftmargin;
2766 register GLYPH *p1prev;
2767 register GLYPH *p1start;
2768 int prevpos;
2769 int *charstart;
2770 FRAME_PTR f = XFRAME (w->frame);
2771 int tab_width = XINT (current_buffer->tab_width);
2772 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2773 int width = window_internal_width (w) - 1;
2774 struct position val;
2775 int lastpos;
2776 int invis;
2777 int last_invis_skip = 0;
2778 Lisp_Object last_invis_prop;
2779 int hscroll = XINT (w->hscroll);
2780 int truncate = (hscroll
2781 || (truncate_partial_width_windows
2782 && !WINDOW_FULL_WIDTH_P (w))
2783 || !NILP (current_buffer->truncate_lines));
2785 /* 1 if we should highlight the region. */
2786 int highlight_region
2787 = (!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active)
2788 && (XWINDOW (current_buffer->last_selected_window) == w
2789 || highlight_nonselected_windows));
2790 int region_beg, region_end;
2792 int selective = (INTEGERP (current_buffer->selective_display)
2793 ? XINT (current_buffer->selective_display)
2794 : !NILP (current_buffer->selective_display) ? -1 : 0);
2795 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2796 register struct Lisp_Char_Table *dp = window_display_table (w);
2798 Lisp_Object default_invis_vector[3];
2799 /* Number of characters of ellipsis to display after an invisible line
2800 if it calls for an ellipsis.
2801 Note that this value can be nonzero regardless of whether
2802 selective display is enabled--you must check that separately. */
2803 int selective_rlen
2804 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2805 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2806 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
2807 /* This is the sequence of Lisp objects to display
2808 when there are invisible lines. */
2809 Lisp_Object *invis_vector_contents
2810 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2811 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2812 : default_invis_vector);
2814 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2815 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp)))
2816 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2817 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2818 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp)))
2819 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2821 /* If 1, we must handle multibyte characters. */
2822 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
2823 /* Length of multibyte form of each character. */
2824 int len;
2825 /* Glyphs generated should be set this bit mask if text must be
2826 displayed from right to left. */
2827 GLYPH rev_dir_bit = (NILP (current_buffer->direction_reversed)
2828 ? 0 : GLYPH_MASK_REV_DIR);
2830 /* The next buffer location at which the face should change, due
2831 to overlays or text property changes. */
2832 int next_face_change;
2834 /* The next location where the `invisible' property changes, or an
2835 overlay starts or ends. */
2836 int next_boundary;
2838 /* The face we're currently using. */
2839 int current_face = 0;
2840 int i;
2842 XSETFASTINT (default_invis_vector[2], '.');
2843 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2845 hpos += WINDOW_LEFT_MARGIN (w);
2846 get_display_line (f, vpos, WINDOW_LEFT_MARGIN (w));
2847 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2849 /* Show where to highlight the region. */
2850 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2851 /* Maybe highlight only in selected window. */
2852 && (highlight_nonselected_windows
2853 || w == XWINDOW (selected_window)))
2855 region_beg = marker_position (current_buffer->mark);
2856 if (PT < region_beg)
2858 region_end = region_beg;
2859 region_beg = PT;
2861 else
2862 region_end = PT;
2863 w->region_showing = Qt;
2865 else
2867 region_beg = region_end = -1;
2868 w->region_showing = Qnil;
2871 if (MINI_WINDOW_P (w)
2872 && start == BEG
2873 && vpos == XFASTINT (w->top))
2875 if (! NILP (minibuf_prompt))
2877 minibuf_prompt_width
2878 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2879 XSTRING (minibuf_prompt)->size, hpos,
2880 /* Display a space if we truncate. */
2881 ' ',
2882 1, -1,
2883 /* Truncate the prompt a little before the
2884 margin, so user input can at least start
2885 on the first line. */
2886 (XFASTINT (w->width) > 10
2887 ? XFASTINT (w->width) - 4 : -1))
2888 - hpos);
2889 hpos += minibuf_prompt_width;
2890 taboffset -= minibuf_prompt_width;
2892 else
2893 minibuf_prompt_width = 0;
2896 /* If we're hscrolled at all, use compute_motion to skip over any
2897 text off the left edge of the window. compute_motion may know
2898 tricks to do this faster than we can. */
2899 if (hpos < 0)
2901 struct position *left_edge
2902 = compute_motion (pos, vpos, hpos, 0,
2903 ZV, vpos, 0,
2904 width, hscroll, taboffset, w);
2906 /* Retrieve the buffer position and column provided by
2907 compute_motion. We can't assume that the column will be
2908 zero, because you may have multi-column characters crossing
2909 the left margin.
2911 compute_motion may have moved us past the screen position we
2912 requested, if we hit a multi-column character, or the end of
2913 the line. If so, back up. */
2914 if (left_edge->vpos > vpos
2915 || left_edge->hpos > 0)
2917 pos = left_edge->bufpos;
2918 /* Since this should not be a valid multibyte character, we
2919 can decrease POS by 1. */
2920 pos--;
2921 hpos = left_edge->prevhpos;
2923 else
2925 pos = left_edge->bufpos;
2926 hpos = left_edge->hpos;
2930 desired_glyphs->bufp[vpos] = start;
2931 p1 = desired_glyphs->glyphs[vpos] + hpos;
2932 p1start = p1;
2933 charstart = desired_glyphs->charstarts[vpos] + hpos;
2934 /* In case we don't ever write anything into it... */
2935 desired_glyphs->charstarts[vpos][WINDOW_LEFT_MARGIN (w)] = -1;
2936 leftmargin = desired_glyphs->glyphs[vpos] + WINDOW_LEFT_MARGIN (w);
2937 endp = leftmargin + width;
2939 /* Arrange the overlays nicely for our purposes. Usually, we call
2940 display_text_line on only one line at a time, in which case this
2941 can't really hurt too much, or we call it on lines which appear
2942 one after another in the buffer, in which case all calls to
2943 recenter_overlay_lists but the first will be pretty cheap. */
2944 recenter_overlay_lists (current_buffer, pos);
2946 /* Loop generating characters.
2947 Stop at end of buffer, before newline,
2948 if reach or pass continuation column,
2949 or at face change. */
2950 pause = pos;
2951 next_face_change = pos;
2952 next_boundary = pos;
2953 p1prev = p1;
2954 prevpos = pos;
2955 while (1)
2957 if (pos >= pause)
2959 int e_t_h;
2961 while (pos == next_boundary)
2963 Lisp_Object position, limit, prop, ww;
2965 /* Display the overlay strings here, unless we're at ZV
2966 and have already displayed the appropriate strings
2967 on an earlier line. */
2968 if (pos < ZV || !zv_strings_seen++)
2970 int ovlen;
2971 unsigned char *ovstr;
2972 ovlen = overlay_strings (pos, w, &ovstr);
2974 if (ovlen > 0)
2976 /* Skip the ones we did in a previous line. */
2977 ovstr += ovstr_done;
2978 ovlen -= ovstr_done;
2980 while (ovlen > 0)
2982 int charset, cols;
2983 GLYPH g;
2985 if (multibyte)
2987 c = STRING_CHAR_AND_LENGTH (ovstr, ovlen, len);
2988 ovstr += len, ovlen -= len, ovstr_done += len;
2989 charset = CHAR_CHARSET (c);
2990 cols = (charset == CHARSET_COMPOSITION
2991 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
2992 : CHARSET_WIDTH (charset));
2994 else
2996 c = *ovstr++, ovlen--, ovstr_done++;
2997 cols = 1;
2999 g = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3000 while (cols-- > 0)
3002 if (p1 >= leftmargin && p1 < endp)
3003 *p1 = g, g |= GLYPH_MASK_PADDING;
3004 p1++;
3007 /* If we did all the overlay strings
3008 and we have room for text, clear ovstr_done
3009 just for neatness' sake. */
3010 if (ovlen == 0 && p1 < endp)
3011 ovstr_done = 0;
3015 /* Did we reach point? Record the cursor location. */
3016 if (pos == PT && cursor_vpos < 0)
3018 cursor_vpos = vpos;
3019 cursor_hpos = p1 - leftmargin;
3022 if (pos >= ZV)
3023 break;
3025 XSETFASTINT (position, pos);
3026 limit = Fnext_overlay_change (position);
3027 #ifdef USE_TEXT_PROPERTIES
3028 /* This is just an estimate to give reasonable
3029 performance; nothing should go wrong if it is too small. */
3030 if (XFASTINT (limit) > pos + 50)
3032 int limitpos = pos + 50;
3033 if (limitpos < Z)
3034 INC_POS (limitpos); /* Adjust to character boundary. */
3035 XSETFASTINT (limit, limitpos);
3037 limit = Fnext_single_property_change (position, Qinvisible,
3038 Fcurrent_buffer (), limit);
3039 #endif
3040 next_boundary = XFASTINT (limit);
3041 /* if the `invisible' property is set, we can skip to
3042 the next property change. */
3043 XSETWINDOW (ww, w);
3044 prop = Fget_char_property (position, Qinvisible, ww);
3045 if (TEXT_PROP_MEANS_INVISIBLE (prop))
3047 if (pos < PT && next_boundary >= PT)
3049 cursor_vpos = vpos;
3050 cursor_hpos = p1 - leftmargin;
3052 pos = next_boundary;
3053 last_invis_skip = pos;
3054 last_invis_prop = prop;
3058 /* Did we reach point? Record the cursor location. */
3059 if (pos == PT && cursor_vpos < 0)
3061 cursor_vpos = vpos;
3062 cursor_hpos = p1 - leftmargin;
3065 /* Did we hit the end of the visible region of the buffer?
3066 Stop here. */
3067 if (pos >= ZV)
3069 /* Update charstarts for the end of this line. */
3070 /* Do nothing if off the left edge or at the right edge. */
3071 if (p1 >= leftmargin && p1 + 1 != endp)
3073 int *p2x = &charstart[(p1 < leftmargin
3074 ? leftmargin : p1)
3075 - p1start];
3076 *p2x++ = pos;
3078 break;
3081 /* Figure out where (if at all) the
3082 redisplay_end_trigger-hook should run. */
3083 if (MARKERP (w->redisplay_end_trigger)
3084 && XMARKER (w->redisplay_end_trigger)->buffer != 0)
3085 e_t_h = marker_position (w->redisplay_end_trigger);
3086 else if (INTEGERP (w->redisplay_end_trigger))
3087 e_t_h = XINT (w->redisplay_end_trigger);
3088 else
3089 e_t_h = ZV;
3091 /* If we've gone past the place to run a hook,
3092 run the hook. */
3093 if (pos >= e_t_h && e_t_h != ZV)
3095 Lisp_Object args[3];
3097 args[0] = Qredisplay_end_trigger_functions;
3098 XSETWINDOW (args[1], w);
3099 XSETINT (args[2], e_t_h);
3101 /* Since we are *trying* to run these functions,
3102 don't try to run them again, even if they get an error. */
3103 w->redisplay_end_trigger = Qnil;
3104 Frun_hook_with_args (3, args);
3106 e_t_h = ZV;
3107 /* Notice if it changed the face of this character. */
3108 next_face_change = pos;
3111 #ifdef HAVE_FACES
3112 /* Did we hit a face change? Figure out what face we should
3113 use now. We also hit this the first time through the
3114 loop, to see what face we should start with. */
3115 if (pos >= next_face_change
3116 && (FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f)))
3118 int limit = pos + 50;
3120 if (limit < Z && !CHAR_HEAD_P (POS_ADDR (limit)))
3121 INC_POS (limit); /* Adjust to character boundary. */
3122 current_face = compute_char_face (f, w, pos,
3123 region_beg, region_end,
3124 &next_face_change, limit, 0);
3126 #endif
3128 /* Compute the next place we need to stop
3129 and do something special; set PAUSE. */
3131 pause = ZV;
3133 if (pos < next_boundary && next_boundary < pause)
3134 pause = next_boundary;
3135 if (pos < next_face_change && next_face_change < pause)
3136 pause = next_face_change;
3138 if (e_t_h < pause)
3139 pause = e_t_h;
3141 /* Wouldn't you hate to read the next line to someone over
3142 the phone? */
3143 if (pos < PT && PT < pause)
3144 pause = PT;
3145 if (pos < GPT && GPT < pause)
3146 pause = GPT;
3148 p = POS_ADDR (pos);
3151 if (p1 >= endp)
3152 break;
3154 p1prev = p1;
3156 if (multibyte)
3157 /* PAUSE is surely at character boundary. */
3158 c = STRING_CHAR_AND_LENGTH (p, pause - pos, len), p += len;
3159 else
3160 c = *p++, len = 1;
3161 /* Let a display table override all standard display methods. */
3162 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3164 p1 = copy_part_of_rope (f, p1, leftmargin,
3165 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3166 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3167 current_face, rev_dir_bit);
3169 else if (c >= 040 && c < 0177)
3171 if (p1 >= leftmargin)
3172 *p1 = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3173 p1++;
3175 else if (c == '\n')
3177 invis = 0;
3178 if (last_invis_skip == pos
3179 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
3180 invis = 1;
3181 while (pos + 1 < ZV
3182 && selective > 0
3183 && indented_beyond_p (pos + 1, selective))
3185 invis = 1;
3186 pos = find_next_newline (pos + 1, 1);
3187 if (FETCH_BYTE (pos - 1) == '\n')
3188 pos--;
3190 if (invis && selective_rlen > 0 && p1 >= leftmargin)
3192 p1 += selective_rlen;
3193 if (p1 - leftmargin > width)
3194 p1 = endp;
3195 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
3196 (p1 - p1prev), current_face, rev_dir_bit);
3198 #ifdef HAVE_FACES
3199 /* Draw the face of the newline character as extending all the
3200 way to the end of the frame line. */
3201 if (current_face)
3203 if (p1 < leftmargin)
3204 p1 = leftmargin;
3205 while (p1 < endp)
3206 *p1++ = FAST_MAKE_GLYPH (' ', current_face) | rev_dir_bit;
3208 #endif
3210 /* Update charstarts for the newline that ended this line. */
3211 /* Do nothing here for a char that's entirely off the left edge
3212 or if it starts at the right edge. */
3213 if (p1 >= leftmargin && p1prev != endp)
3215 /* Store the newline's position into charstarts
3216 for the column where the newline starts.
3217 Store -1 for the rest of the glyphs it occupies. */
3218 int *p2x = &charstart[(p1prev < leftmargin
3219 ? leftmargin : p1prev)
3220 - p1start];
3221 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3223 *p2x++ = pos;
3224 while (p2x < p2)
3225 *p2x++ = -1;
3228 break;
3230 else if (c == '\t')
3234 if (p1 >= leftmargin && p1 < endp)
3235 *p1 = MAKE_GLYPH (f, ' ', current_face) | rev_dir_bit;
3236 p1++;
3238 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
3239 % tab_width);
3241 else if (c == Ctl ('M') && selective == -1)
3243 pos = find_next_newline (pos, 1);
3244 if (FETCH_BYTE (pos - 1) == '\n')
3245 pos--;
3246 if (selective_rlen > 0)
3248 p1 += selective_rlen;
3249 if (p1 - leftmargin > width)
3250 p1 = endp;
3251 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
3252 (p1 - p1prev), current_face, rev_dir_bit);
3254 #ifdef HAVE_FACES
3255 /* Draw the face of the newline character as extending all the
3256 way to the end of the frame line. */
3257 if (current_face)
3259 if (p1 < leftmargin)
3260 p1 = leftmargin;
3261 while (p1 < endp)
3262 *p1++ = FAST_MAKE_GLYPH (' ', current_face) | rev_dir_bit;
3264 #endif
3266 /* Update charstarts for the ^M that ended this line. */
3267 /* Do nothing here for a char that's entirely off the left edge
3268 or if it starts at the right edge. */
3269 if (p1 >= leftmargin && p1prev != endp)
3271 /* Store the newline's position into charstarts
3272 for the column where the newline starts.
3273 Store -1 for the rest of the glyphs it occupies. */
3274 int *p2x = &charstart[(p1prev < leftmargin
3275 ? leftmargin : p1prev)
3276 - p1start];
3277 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3279 *p2x++ = pos;
3280 while (p2x < p2)
3281 *p2x++ = -1;
3283 break;
3285 else if (c < 0200 && ctl_arrow)
3287 if (p1 >= leftmargin)
3288 *p1 = (fix_glyph
3289 (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
3290 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp)))
3291 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3292 current_face)
3293 | rev_dir_bit);
3294 p1++;
3295 if (p1 >= leftmargin && p1 < endp)
3296 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face) | rev_dir_bit;
3297 p1++;
3299 else if (len == 1)
3301 /* C is not a multibyte character. */
3302 if (p1 >= leftmargin)
3303 *p1 = (fix_glyph
3304 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
3305 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
3306 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3307 current_face)
3308 | rev_dir_bit);
3309 p1++;
3310 if (p1 >= leftmargin && p1 < endp)
3311 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face) | rev_dir_bit;
3312 p1++;
3313 if (p1 >= leftmargin && p1 < endp)
3314 *p1 = (MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face)
3315 | rev_dir_bit);
3316 p1++;
3317 if (p1 >= leftmargin && p1 < endp)
3318 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face) | rev_dir_bit;
3319 p1++;
3321 else
3323 /* C is a multibyte character. */
3324 int charset = CHAR_CHARSET (c);
3325 int columns = (charset == CHARSET_COMPOSITION
3326 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
3327 : CHARSET_WIDTH (charset));
3328 GLYPH g = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3330 while (columns--)
3332 if (p1 >= leftmargin && p1 < endp)
3333 *p1 = g, g |= GLYPH_MASK_PADDING;
3334 p1++;
3338 prevpos = pos;
3339 pos += len;
3341 /* Update charstarts for the character just output. */
3343 /* Do nothing here for a char that's entirely off the left edge. */
3344 if (p1 >= leftmargin)
3346 /* Store the char's position into charstarts
3347 for the first glyph occupied by this char.
3348 Store -1 for the rest of the glyphs it occupies. */
3349 if (p1 != p1prev)
3351 int *p2x = &charstart[(p1prev < leftmargin
3352 ? leftmargin : p1prev)
3353 - p1start];
3354 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3356 if (p2x < p2)
3357 *p2x++ = prevpos;
3358 while (p2x < p2)
3359 *p2x++ = -1;
3364 val.hpos = - XINT (w->hscroll);
3365 if (val.hpos)
3366 val.hpos++;
3368 val.vpos = 1;
3370 lastpos = pos;
3372 /* Store 0 in this charstart line for the positions where
3373 there is no character. But do leave what was recorded
3374 for the character that ended the line. */
3375 /* Add 1 in the endtest to compensate for the fact that ENDP was
3376 made from WIDTH, which is 1 less than the window's actual
3377 internal width. */
3378 i = p1 - p1start + 1;
3379 if (p1 < leftmargin)
3380 i += leftmargin - p1;
3381 for (; i < endp - p1start + 1; i++)
3382 charstart[i] = 0;
3384 /* Handle continuation in middle of a character */
3385 /* by backing up over it */
3386 if (p1 > endp)
3388 /* Don't back up if we never actually displayed any text.
3389 This occurs when the minibuffer prompt takes up the whole line. */
3390 if (p1prev)
3392 /* Start the next line with that same character whose
3393 character code is C and the length of multi-byte form is
3394 LEN. */
3395 pos = prevpos;
3397 if (len == 1)
3398 /* C is not a multi-byte character. We can break it and
3399 start from the middle column in the next line. So,
3400 adjust VAL.HPOS to skip the columns output on this
3401 line. */
3402 val.hpos += p1prev - endp;
3403 else
3405 /* C is a multibyte character. Since we can't broke it
3406 in the middle, the whole character should be driven
3407 into the next line. */
3408 /* As the result, the actual columns occupied by the
3409 text on this line is less than WIDTH. VAL.TAB_OFFSET
3410 must be adjusted. */
3411 taboffset = taboffset + (p1prev - endp);
3412 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3414 GLYPH g = fix_glyph (f, truncate ? truncator : continuer, 0);
3415 while (p1prev < endp)
3416 *p1prev++ = g;
3418 /* If POINT is at POS, cursor should not on this line. */
3419 lastpos = pos;
3420 if (PT == pos)
3421 cursor_vpos = -1;
3425 /* Keep in this line everything up to the continuation column. */
3426 p1 = endp;
3429 /* Finish deciding which character to start the next line on,
3430 and what hpos to start it at.
3431 Also set `lastpos' to the last position which counts as "on this line"
3432 for cursor-positioning. */
3434 if (pos < ZV)
3436 if (FETCH_BYTE (pos) == '\n')
3438 /* If stopped due to a newline, start next line after it */
3439 pos++;
3440 val.tab_offset = 0;
3441 /* Check again for hidden lines, in case the newline occurred exactly
3442 at the right margin. */
3443 while (pos < ZV && selective > 0
3444 && indented_beyond_p (pos, selective))
3445 pos = find_next_newline (pos, 1);
3447 else
3448 /* Stopped due to right margin of window */
3450 if (truncate)
3452 *p1++ = fix_glyph (f, truncator, 0);
3453 /* Truncating => start next line after next newline,
3454 and point is on this line if it is before the newline,
3455 and skip none of first char of next line */
3457 pos = find_next_newline (pos, 1);
3458 while (pos < ZV && selective > 0
3459 && indented_beyond_p (pos, selective));
3460 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
3462 lastpos = pos - (FETCH_BYTE (pos - 1) == '\n');
3463 val.tab_offset = 0;
3465 else
3467 *p1++ = fix_glyph (f, continuer, 0);
3468 val.vpos = 0;
3469 lastpos--;
3470 val.tab_offset = taboffset + width;
3474 else
3475 val.tab_offset = 0;
3477 /* If point is at eol or in invisible text at eol,
3478 record its frame location now. */
3480 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
3482 cursor_vpos = vpos;
3483 cursor_hpos = p1 - leftmargin;
3486 if (cursor_vpos == vpos)
3488 if (cursor_hpos < 0) cursor_hpos = 0;
3489 if (cursor_hpos > width) cursor_hpos = width;
3490 cursor_hpos += WINDOW_LEFT_MARGIN (w);
3491 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
3493 if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f)
3494 && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window)))
3496 FRAME_CURSOR_Y (f) = cursor_vpos;
3497 FRAME_CURSOR_X (f) = cursor_hpos;
3500 if (w == XWINDOW (selected_window))
3502 /* Line is not continued and did not start
3503 in middle of character */
3504 if ((hpos - WINDOW_LEFT_MARGIN (w)
3505 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
3506 && val.vpos)
3508 this_line_bufpos = start;
3509 this_line_buffer = current_buffer;
3510 this_line_vpos = cursor_vpos;
3511 this_line_start_hpos = hpos;
3512 this_line_endpos = Z - lastpos;
3514 else
3515 this_line_bufpos = 0;
3520 /* If hscroll and line not empty, insert truncation-at-left marker */
3521 if (hscroll && lastpos != start)
3523 GLYPH g = fix_glyph (f, truncator, 0);
3524 *leftmargin = g;
3525 if (p1 <= leftmargin)
3526 p1 = leftmargin + 1;
3527 else /* MULE: it may be a wide-column character */
3529 p1prev = leftmargin + 1;
3530 while (p1prev < p1 && *p1prev & GLYPH_MASK_PADDING)
3531 *p1prev++ = g;
3535 if (!WINDOW_RIGHTMOST_P (w))
3537 endp++;
3538 if (p1 < leftmargin) p1 = leftmargin;
3539 while (p1 < endp) *p1++ = SPACEGLYPH;
3541 /* Don't draw vertical bars if we're using scroll bars. They're
3542 covered up by the scroll bars, and it's distracting to see
3543 them when the scroll bar windows are flickering around to be
3544 reconfigured. */
3545 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3547 int i;
3548 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3549 *p1++ = SPACEGLYPH;
3551 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3552 *p1++ = (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
3553 ? XINT (DISP_BORDER_GLYPH (dp))
3554 : '|');
3556 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
3557 p1 - desired_glyphs->glyphs[vpos]);
3558 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3560 /* If the start of this line is the overlay arrow-position,
3561 then put the arrow string into the display-line. */
3563 if (MARKERP (Voverlay_arrow_position)
3564 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
3565 && start == marker_position (Voverlay_arrow_position)
3566 && STRINGP (Voverlay_arrow_string)
3567 && ! overlay_arrow_seen)
3569 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
3570 int i;
3571 int len = XSTRING (Voverlay_arrow_string)->size;
3572 int arrow_end;
3574 if (len > width)
3575 len = width;
3576 #ifdef HAVE_FACES
3577 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
3579 /* If the arrow string has text props, obey them when displaying. */
3580 for (i = 0; i < len; i++)
3582 int c = p[i];
3583 Lisp_Object face, ilisp;
3584 int newface;
3586 XSETFASTINT (ilisp, i);
3587 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
3588 newface = compute_glyph_face_1 (f, face, 0);
3589 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
3592 else
3593 #endif /* HAVE_FACES */
3595 for (i = 0; i < len; i++)
3596 leftmargin[i] = p[i];
3599 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3600 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
3601 if (desired_glyphs->used[vpos] < arrow_end)
3602 desired_glyphs->used[vpos] = arrow_end;
3604 overlay_arrow_seen = 1;
3607 val.bufpos = pos;
3608 val.ovstring_chars_done = ovstr_done;
3609 val_display_text_line = val;
3610 return &val_display_text_line;
3613 /* Redisplay the menu bar in the frame for window W. */
3615 static void
3616 display_menu_bar (w)
3617 struct window *w;
3619 Lisp_Object items, tail;
3620 register int vpos = 0;
3621 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3622 int maxendcol = FRAME_WIDTH (f);
3623 int hpos = 0;
3624 int i;
3626 #ifdef HAVE_NTGUI
3627 if (!NILP (Vwindow_system))
3628 return;
3629 #endif
3631 #ifdef USE_X_TOOLKIT
3632 if (FRAME_X_P (f))
3633 return;
3634 #endif /* USE_X_TOOLKIT */
3636 get_display_line (f, vpos, 0);
3638 items = FRAME_MENU_BAR_ITEMS (f);
3639 for (i = 0; i < XVECTOR (items)->size; i += 4)
3641 Lisp_Object pos, string;
3642 string = XVECTOR (items)->contents[i + 1];
3643 if (NILP (string))
3644 break;
3646 XSETFASTINT (XVECTOR (items)->contents[i + 3], hpos);
3648 if (hpos < maxendcol)
3649 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
3650 XSTRING (string)->data,
3651 XSTRING (string)->size,
3652 hpos, 0, 0, hpos, maxendcol);
3653 /* Put a space between items. */
3654 if (hpos < maxendcol)
3656 int hpos1 = hpos + 1;
3657 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
3658 min (hpos1, maxendcol), maxendcol);
3662 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3663 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3665 /* Fill out the line with spaces. */
3666 if (maxendcol > hpos)
3667 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
3669 /* Clear the rest of the lines allocated to the menu bar. */
3670 vpos++;
3671 while (vpos < FRAME_MENU_BAR_LINES (f))
3672 get_display_line (f, vpos++, 0);
3675 /* Display the mode line for window w */
3677 static void
3678 display_mode_line (w)
3679 struct window *w;
3681 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
3682 register int left = WINDOW_LEFT_MARGIN (w);
3683 register int right = WINDOW_RIGHT_MARGIN (w);
3684 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3686 line_number_displayed = 0;
3687 w->column_number_displayed = Qnil;
3689 get_display_line (f, vpos, left);
3691 /* Temporarily make frame F's kboard the current kboard
3692 so that kboard-local variables in the mode_line_format
3693 will get the right values. */
3694 push_frame_kboard (f);
3696 display_mode_element (w, vpos, left, 0, right, right,
3697 current_buffer->mode_line_format);
3699 pop_frame_kboard ();
3701 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3703 /* Put the mode line in inverse video.
3704 Use faces if possible, since that lets us handle
3705 partial-width windows and avoid inverting the scroll bar columns. */
3706 #ifdef HAVE_FACES
3707 if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video)
3709 /* For a partial width window, explicitly set face of each glyph. */
3710 int i;
3711 unsigned int padding;
3712 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3713 for (i = left; i < right; ++i)
3715 padding = ptr[i] & GLYPH_MASK_PADDING;
3716 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1) | padding;
3719 else
3720 #endif
3722 /* Make the mode line inverse video if the entire line
3723 is made of mode lines.
3724 I.e. if this window is full width,
3725 or if it is the child of a full width window
3726 (which implies that that window is split side-by-side
3727 and the rest of this line is mode lines of the sibling windows). */
3728 if (WINDOW_FULL_WIDTH_P (w)
3729 || WINDOW_FULL_WIDTH_P (XWINDOW (w->parent)))
3730 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3733 /* Contribute ELT to the mode line for window W.
3734 How it translates into text depends on its data type.
3736 VPOS is the position of the mode line being displayed.
3738 HPOS is the position (absolute on frame) where this element's text
3739 should start. The output is truncated automatically at the right
3740 edge of window W.
3742 DEPTH is the depth in recursion. It is used to prevent
3743 infinite recursion here.
3745 MINENDCOL is the hpos before which the element may not end.
3746 The element is padded at the right with spaces if nec
3747 to reach this column.
3749 MAXENDCOL is the hpos past which this element may not extend.
3750 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3751 (This is necessary to make nested padding and truncation work.)
3753 Returns the hpos of the end of the text generated by ELT.
3754 The next element will receive that value as its HPOS arg,
3755 so as to concatenate the elements. */
3757 static int
3758 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3759 struct window *w;
3760 register int vpos, hpos;
3761 int depth;
3762 int minendcol;
3763 register int maxendcol;
3764 register Lisp_Object elt;
3766 tail_recurse:
3767 if (depth > 10)
3768 goto invalid;
3770 depth++;
3772 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3774 case Lisp_String:
3776 /* A string: output it and check for %-constructs within it. */
3777 register unsigned char c;
3778 register unsigned char *this = XSTRING (elt)->data;
3780 while (hpos < maxendcol && *this)
3782 unsigned char *last = this;
3783 while ((c = *this++) != '\0' && c != '%')
3785 if (this - 1 != last)
3787 register int lim = --this - last + hpos;
3788 if (frame_title_ptr)
3789 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3790 else
3791 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3792 hpos, min (lim, maxendcol));
3794 else /* c == '%' */
3796 register int minendcol;
3797 register int spec_width = 0;
3799 /* We can't allow -ve args due to the "%-" construct */
3800 /* Argument specifies minwidth but not maxwidth
3801 (maxwidth can be specified by
3802 (<negative-number> . <stuff>) mode-line elements) */
3804 while ((c = *this++) >= '0' && c <= '9')
3806 spec_width = spec_width * 10 + (c - '0');
3809 minendcol = hpos + spec_width;
3810 if (minendcol > maxendcol)
3812 spec_width = maxendcol - hpos;
3813 minendcol = maxendcol;
3816 if (c == 'M')
3817 hpos = display_mode_element (w, vpos, hpos, depth,
3818 spec_width, maxendcol,
3819 Vglobal_mode_string);
3820 else if (c != 0)
3822 char *spec = decode_mode_spec (w, c, spec_width,
3823 maxendcol - hpos);
3824 if (frame_title_ptr)
3825 hpos = store_frame_title (spec, minendcol, maxendcol);
3826 else
3827 hpos = display_string (w, vpos, spec, -1,
3828 hpos, 0, 1,
3829 minendcol, maxendcol);
3834 break;
3836 case Lisp_Symbol:
3837 /* A symbol: process the value of the symbol recursively
3838 as if it appeared here directly. Avoid error if symbol void.
3839 Special case: if value of symbol is a string, output the string
3840 literally. */
3842 register Lisp_Object tem;
3843 tem = Fboundp (elt);
3844 if (!NILP (tem))
3846 tem = Fsymbol_value (elt);
3847 /* If value is a string, output that string literally:
3848 don't check for % within it. */
3849 if (STRINGP (tem))
3851 if (frame_title_ptr)
3852 hpos = store_frame_title (XSTRING (tem)->data,
3853 minendcol, maxendcol);
3854 else
3855 hpos = display_string (w, vpos, XSTRING (tem)->data,
3856 XSTRING (tem)->size,
3857 hpos, 0, 1, minendcol, maxendcol);
3859 /* Give up right away for nil or t. */
3860 else if (!EQ (tem, elt))
3861 { elt = tem; goto tail_recurse; }
3864 break;
3866 case Lisp_Cons:
3868 register Lisp_Object car, tem;
3870 /* A cons cell: three distinct cases.
3871 If first element is a string or a cons, process all the elements
3872 and effectively concatenate them.
3873 If first element is a negative number, truncate displaying cdr to
3874 at most that many characters. If positive, pad (with spaces)
3875 to at least that many characters.
3876 If first element is a symbol, process the cadr or caddr recursively
3877 according to whether the symbol's value is non-nil or nil. */
3878 car = XCONS (elt)->car;
3879 if (SYMBOLP (car))
3881 tem = Fboundp (car);
3882 elt = XCONS (elt)->cdr;
3883 if (!CONSP (elt))
3884 goto invalid;
3885 /* elt is now the cdr, and we know it is a cons cell.
3886 Use its car if CAR has a non-nil value. */
3887 if (!NILP (tem))
3889 tem = Fsymbol_value (car);
3890 if (!NILP (tem))
3891 { elt = XCONS (elt)->car; goto tail_recurse; }
3893 /* Symbol's value is nil (or symbol is unbound)
3894 Get the cddr of the original list
3895 and if possible find the caddr and use that. */
3896 elt = XCONS (elt)->cdr;
3897 if (NILP (elt))
3898 break;
3899 else if (!CONSP (elt))
3900 goto invalid;
3901 elt = XCONS (elt)->car;
3902 goto tail_recurse;
3904 else if (INTEGERP (car))
3906 register int lim = XINT (car);
3907 elt = XCONS (elt)->cdr;
3908 if (lim < 0)
3909 /* Negative int means reduce maximum width.
3910 DO NOT change MINENDCOL here!
3911 (20 -10 . foo) should truncate foo to 10 col
3912 and then pad to 20. */
3913 maxendcol = min (maxendcol, hpos - lim);
3914 else if (lim > 0)
3916 /* Padding specified. Don't let it be more than
3917 current maximum. */
3918 lim += hpos;
3919 if (lim > maxendcol)
3920 lim = maxendcol;
3921 /* If that's more padding than already wanted, queue it.
3922 But don't reduce padding already specified even if
3923 that is beyond the current truncation point. */
3924 if (lim > minendcol)
3925 minendcol = lim;
3927 goto tail_recurse;
3929 else if (STRINGP (car) || CONSP (car))
3931 register int limit = 50;
3932 /* LIMIT is to protect against circular lists. */
3933 while (CONSP (elt) && --limit > 0
3934 && hpos < maxendcol)
3936 hpos = display_mode_element (w, vpos, hpos, depth,
3937 hpos, maxendcol,
3938 XCONS (elt)->car);
3939 elt = XCONS (elt)->cdr;
3943 break;
3945 default:
3946 invalid:
3947 if (frame_title_ptr)
3948 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3949 else
3950 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3951 minendcol, maxendcol);
3952 return hpos;
3955 if (minendcol > hpos)
3956 if (frame_title_ptr)
3957 hpos = store_frame_title ("", minendcol, maxendcol);
3958 else
3959 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
3960 return hpos;
3963 /* Write a null-terminated, right justified decimal representation of
3964 the positive integer D to BUF using a minimal field width WIDTH. */
3966 static void
3967 pint2str (buf, width, d)
3968 register char *buf;
3969 register int width;
3970 register int d;
3972 register char *p = buf;
3974 if (d <= 0)
3975 *p++ = '0';
3976 else
3977 while (d > 0)
3979 *p++ = d % 10 + '0';
3980 d /= 10;
3982 for (width -= (int) (p - buf); width > 0; --width) *p++ = ' ';
3983 *p-- = '\0';
3984 while (p > buf)
3986 d = *buf;
3987 *buf++ = *p;
3988 *p-- = d;
3992 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
3993 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
3994 type of CODING_SYSTEM. Return updated pointer into BUF. */
3996 static char *
3997 decode_mode_spec_coding (coding_system, buf, eol_flag)
3998 Lisp_Object coding_system;
3999 register char *buf;
4000 int eol_flag;
4002 register Lisp_Object val = coding_system;
4004 if (NILP (val)) /* Not yet decided. */
4006 *buf++ = '-';
4007 if (eol_flag) *buf++ = eol_mnemonic_undecided;
4009 else
4011 while (!NILP (val) && SYMBOLP (val))
4012 val = Fget (val, Qcoding_system);
4013 *buf++ = XFASTINT (XVECTOR (val)->contents[1]);
4014 if (eol_flag)
4016 val = Fget (coding_system, Qeol_type);
4018 if (NILP (val)) /* Not yet decided. */
4019 *buf++ = eol_mnemonic_undecided;
4020 else if (VECTORP (val)) /* Not yet decided. */
4021 *buf++ = eol_mnemonic_undecided;
4022 else /* INTEGERP (val) -- 1:LF, 2:CRLF, 3:CR */
4023 *buf++ = (XFASTINT (val) == 1
4024 ? eol_mnemonic_unix
4025 : (XFASTINT (val) == 2
4026 ? eol_mnemonic_dos : eol_mnemonic_mac));
4029 return buf;
4032 /* Return a string for the output of a mode line %-spec for window W,
4033 generated by character C. SPEC_WIDTH is the field width when
4034 padding to the left (%c, %l). The value returned from this
4035 function will later be truncated to width MAXWIDTH. */
4037 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4039 static char *
4040 decode_mode_spec (w, c, spec_width, maxwidth)
4041 struct window *w;
4042 register char c;
4043 register int spec_width;
4044 register int maxwidth;
4046 Lisp_Object obj;
4047 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4048 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
4049 struct buffer *b = XBUFFER (w->buffer);
4051 obj = Qnil;
4052 if (maxwidth > FRAME_WIDTH (f))
4053 maxwidth = FRAME_WIDTH (f);
4055 switch (c)
4057 case '*':
4058 if (!NILP (b->read_only))
4059 return "%";
4060 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4061 return "*";
4062 return "-";
4064 case '+':
4065 /* This differs from %* only for a modified read-only buffer. */
4066 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4067 return "*";
4068 if (!NILP (b->read_only))
4069 return "%";
4070 return "-";
4072 case '&':
4073 /* This differs from %* in ignoring read-only-ness. */
4074 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4075 return "*";
4076 return "-";
4078 case '%':
4079 return "%";
4081 case '[':
4083 int i;
4084 char *p;
4086 if (command_loop_level > 5)
4087 return "[[[... ";
4088 p = decode_mode_spec_buf;
4089 for (i = 0; i < command_loop_level; i++)
4090 *p++ = '[';
4091 *p = 0;
4092 return decode_mode_spec_buf;
4095 case ']':
4097 int i;
4098 char *p;
4100 if (command_loop_level > 5)
4101 return " ...]]]";
4102 p = decode_mode_spec_buf;
4103 for (i = 0; i < command_loop_level; i++)
4104 *p++ = ']';
4105 *p = 0;
4106 return decode_mode_spec_buf;
4109 case '-':
4111 register char *p;
4112 register int i;
4114 if (maxwidth < sizeof (lots_of_dashes))
4115 return lots_of_dashes;
4116 else
4118 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
4119 *p++ = '-';
4120 *p = '\0';
4122 return decode_mode_spec_buf;
4125 case 'b':
4126 obj = b->name;
4127 #if 0
4128 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
4130 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
4131 decode_mode_spec_buf[maxwidth - 1] = '\\';
4132 decode_mode_spec_buf[maxwidth] = '\0';
4133 return decode_mode_spec_buf;
4135 #endif
4136 break;
4138 case 'c':
4140 int col = current_column ();
4141 XSETFASTINT (w->column_number_displayed, col);
4142 pint2str (decode_mode_spec_buf, spec_width, col);
4143 return decode_mode_spec_buf;
4146 case 'F':
4147 /* %F displays the frame name. */
4148 if (!NILP (f->title))
4149 return (char *) XSTRING (f->title)->data;
4150 if (f->explicit_name || ! FRAME_WINDOW_P (f))
4151 return (char *) XSTRING (f->name)->data;
4152 return "Emacs";
4154 case 'f':
4155 obj = b->filename;
4156 #if 0
4157 if (NILP (obj))
4158 return "[none]";
4159 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
4161 bcopy ("...", decode_mode_spec_buf, 3);
4162 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
4163 decode_mode_spec_buf + 3, maxwidth - 3);
4164 return decode_mode_spec_buf;
4166 #endif
4167 break;
4169 case 'l':
4171 int startpos = marker_position (w->start);
4172 int line, linepos, topline;
4173 int nlines, junk;
4174 Lisp_Object tem;
4175 int height = XFASTINT (w->height);
4177 /* If we decided that this buffer isn't suitable for line numbers,
4178 don't forget that too fast. */
4179 if (EQ (w->base_line_pos, w->buffer))
4180 goto no_value;
4181 /* But do forget it, if the window shows a different buffer now. */
4182 else if (BUFFERP (w->base_line_pos))
4183 w->base_line_pos = Qnil;
4185 /* If the buffer is very big, don't waste time. */
4186 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
4188 w->base_line_pos = Qnil;
4189 w->base_line_number = Qnil;
4190 goto no_value;
4193 if (!NILP (w->base_line_number)
4194 && !NILP (w->base_line_pos)
4195 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
4197 line = XFASTINT (w->base_line_number);
4198 linepos = XFASTINT (w->base_line_pos);
4200 else
4202 line = 1;
4203 linepos = BUF_BEGV (b);
4206 /* Count lines from base line to window start position. */
4207 nlines = display_count_lines (linepos, startpos, startpos, &junk);
4209 topline = nlines + line;
4211 /* Determine a new base line, if the old one is too close
4212 or too far away, or if we did not have one.
4213 "Too close" means it's plausible a scroll-down would
4214 go back past it. */
4215 if (startpos == BUF_BEGV (b))
4217 XSETFASTINT (w->base_line_number, topline);
4218 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
4220 else if (nlines < height + 25 || nlines > height * 3 + 50
4221 || linepos == BUF_BEGV (b))
4223 int limit = BUF_BEGV (b);
4224 int position;
4225 int distance = (height * 2 + 30) * 200;
4227 if (startpos - distance > limit)
4228 limit = startpos - distance;
4230 nlines = display_count_lines (startpos, limit,
4231 -(height * 2 + 30),
4232 &position);
4233 /* If we couldn't find the lines we wanted within
4234 200 chars per line,
4235 give up on line numbers for this window. */
4236 if (position == startpos - distance)
4238 w->base_line_pos = w->buffer;
4239 w->base_line_number = Qnil;
4240 goto no_value;
4243 XSETFASTINT (w->base_line_number, topline - nlines);
4244 XSETFASTINT (w->base_line_pos, position);
4247 /* Now count lines from the start pos to point. */
4248 nlines = display_count_lines (startpos, PT, PT, &junk);
4250 /* Record that we did display the line number. */
4251 line_number_displayed = 1;
4253 /* Make the string to show. */
4254 pint2str (decode_mode_spec_buf, spec_width, topline + nlines);
4255 return decode_mode_spec_buf;
4256 no_value:
4258 char* p = decode_mode_spec_buf;
4259 for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' ';
4260 strcpy (p, "??");
4261 return decode_mode_spec_buf;
4264 break;
4266 case 'm':
4267 obj = b->mode_name;
4268 break;
4270 case 'n':
4271 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
4272 return " Narrow";
4273 break;
4275 case 'p':
4277 int pos = marker_position (w->start);
4278 int total = BUF_ZV (b) - BUF_BEGV (b);
4280 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
4282 if (pos <= BUF_BEGV (b))
4283 return "All";
4284 else
4285 return "Bottom";
4287 else if (pos <= BUF_BEGV (b))
4288 return "Top";
4289 else
4291 if (total > 1000000)
4292 /* Do it differently for a large value, to avoid overflow. */
4293 total = ((pos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
4294 else
4295 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
4296 /* We can't normally display a 3-digit number,
4297 so get us a 2-digit number that is close. */
4298 if (total == 100)
4299 total = 99;
4300 sprintf (decode_mode_spec_buf, "%2d%%", total);
4301 return decode_mode_spec_buf;
4305 /* Display percentage of size above the bottom of the screen. */
4306 case 'P':
4308 int toppos = marker_position (w->start);
4309 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
4310 int total = BUF_ZV (b) - BUF_BEGV (b);
4312 if (botpos >= BUF_ZV (b))
4314 if (toppos <= BUF_BEGV (b))
4315 return "All";
4316 else
4317 return "Bottom";
4319 else
4321 if (total > 1000000)
4322 /* Do it differently for a large value, to avoid overflow. */
4323 total = ((botpos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
4324 else
4325 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
4326 /* We can't normally display a 3-digit number,
4327 so get us a 2-digit number that is close. */
4328 if (total == 100)
4329 total = 99;
4330 if (toppos <= BUF_BEGV (b))
4331 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
4332 else
4333 sprintf (decode_mode_spec_buf, "%2d%%", total);
4334 return decode_mode_spec_buf;
4338 case 's':
4339 /* status of process */
4340 obj = Fget_buffer_process (w->buffer);
4341 if (NILP (obj))
4342 return "no process";
4343 #ifdef subprocesses
4344 obj = Fsymbol_name (Fprocess_status (obj));
4345 #endif
4346 break;
4348 case 't': /* indicate TEXT or BINARY */
4349 #ifdef MODE_LINE_BINARY_TEXT
4350 return MODE_LINE_BINARY_TEXT (b);
4351 #else
4352 return "T";
4353 #endif
4355 case 'z':
4356 /* coding-system (not including end-of-line format) */
4357 case 'Z':
4358 /* coding-system (including end-of-line type) */
4360 int eol_flag = (c == 'Z');
4361 char *p;
4363 p = decode_mode_spec_coding
4364 (find_symbol_value (Qbuffer_file_coding_system),
4365 decode_mode_spec_buf, eol_flag);
4366 if (FRAME_TERMCAP_P (f))
4368 p = decode_mode_spec_coding (keyboard_coding.symbol, p, eol_flag);
4369 p = decode_mode_spec_coding (terminal_coding.symbol, p, eol_flag);
4371 #ifdef subprocesses
4372 obj = Fget_buffer_process (Fcurrent_buffer ());
4373 if (PROCESSP (obj))
4375 p = decode_mode_spec_coding (XPROCESS (obj)->decode_coding_system,
4376 p, eol_flag);
4377 p = decode_mode_spec_coding (XPROCESS (obj)->encode_coding_system,
4378 p, eol_flag);
4380 #endif /* subprocesses */
4381 *p = 0;
4382 return decode_mode_spec_buf;
4386 if (STRINGP (obj))
4387 return (char *) XSTRING (obj)->data;
4388 else
4389 return "";
4392 /* Search for COUNT instances of a line boundary, which means either a
4393 newline or (if selective display enabled) a carriage return.
4394 Start at START. If COUNT is negative, search backwards.
4396 If we find COUNT instances, set *SHORTAGE to zero, and return the
4397 position after the COUNTth match. Note that for reverse motion
4398 this is not the same as the usual convention for Emacs motion commands.
4400 If we don't find COUNT instances before reaching the end of the
4401 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
4402 the number of line boundaries left unfound, and return the end of the
4403 buffer we bumped up against. */
4405 static int
4406 display_scan_buffer (start, count, shortage)
4407 int *shortage, start;
4408 register int count;
4410 int limit = ((count > 0) ? ZV - 1 : BEGV);
4411 int direction = ((count > 0) ? 1 : -1);
4413 register unsigned char *cursor;
4414 unsigned char *base;
4416 register int ceiling;
4417 register unsigned char *ceiling_addr;
4419 /* If we are not in selective display mode,
4420 check only for newlines. */
4421 if (! (!NILP (current_buffer->selective_display)
4422 && !INTEGERP (current_buffer->selective_display)))
4423 return scan_buffer ('\n', start, 0, count, shortage, 0);
4425 /* The code that follows is like scan_buffer
4426 but checks for either newline or carriage return. */
4428 if (shortage != 0)
4429 *shortage = 0;
4431 if (count > 0)
4432 while (start != limit + 1)
4434 ceiling = BUFFER_CEILING_OF (start);
4435 ceiling = min (limit, ceiling);
4436 ceiling_addr = POS_ADDR (ceiling) + 1;
4437 base = (cursor = POS_ADDR (start));
4438 while (1)
4440 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
4442 if (cursor != ceiling_addr)
4444 if (--count == 0)
4446 immediate_quit = 0;
4447 return (start + cursor - base + 1);
4449 else
4450 if (++cursor == ceiling_addr)
4451 break;
4453 else
4454 break;
4456 start += cursor - base;
4458 else
4460 start--; /* first character we scan */
4461 while (start > limit - 1)
4462 { /* we WILL scan under start */
4463 ceiling = BUFFER_FLOOR_OF (start);
4464 ceiling = max (limit, ceiling);
4465 ceiling_addr = POS_ADDR (ceiling) - 1;
4466 base = (cursor = POS_ADDR (start));
4467 cursor++;
4468 while (1)
4470 while (--cursor != ceiling_addr
4471 && *cursor != '\n' && *cursor != 015)
4473 if (cursor != ceiling_addr)
4475 if (++count == 0)
4477 immediate_quit = 0;
4478 return (start + cursor - base + 1);
4481 else
4482 break;
4484 start += cursor - base;
4488 if (shortage != 0)
4489 *shortage = count * direction;
4490 return (start + ((direction == 1 ? 0 : 1)));
4493 /* Count up to N lines starting from FROM.
4494 But don't go beyond LIMIT.
4495 Return the number of lines thus found (always positive).
4496 Store the position after what was found into *POS_PTR. */
4498 static int
4499 display_count_lines (from, limit, n, pos_ptr)
4500 int from, limit, n;
4501 int *pos_ptr;
4503 int oldbegv = BEGV;
4504 int oldzv = ZV;
4505 int shortage = 0;
4507 if (limit < from)
4508 BEGV = limit;
4509 else
4510 ZV = limit;
4512 *pos_ptr = display_scan_buffer (from, n, &shortage);
4514 ZV = oldzv;
4515 BEGV = oldbegv;
4517 if (n < 0)
4518 /* When scanning backwards, scan_buffer stops *after* the last newline
4519 it finds, but does count it. Compensate for that. */
4520 return - n - shortage - (*pos_ptr != limit);
4521 return n - shortage;
4524 /* Display STRING on one line of window W, starting at HPOS.
4525 Display at position VPOS. Caller should have done get_display_line.
4526 If VPOS == -1, display it as the current frame's title.
4527 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4529 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4531 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4532 MAXCOL is the last column ok to end at. Truncate here.
4533 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4534 Both count from the left edge of the frame, as does HPOS.
4535 The right edge of W is an implicit maximum.
4536 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4538 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4539 at the place where the current window ends in this line
4540 and not display anything beyond there. Otherwise, only MAXCOL
4541 controls where to stop output.
4543 Returns ending hpos. */
4545 static int
4546 display_string (w, vpos, string, length, hpos, truncate,
4547 obey_window_width, mincol, maxcol)
4548 struct window *w;
4549 unsigned char *string;
4550 int length;
4551 int vpos, hpos;
4552 GLYPH truncate;
4553 int obey_window_width;
4554 int mincol, maxcol;
4556 register int c;
4557 int truncated;
4558 register GLYPH *p1;
4559 int hscroll = XINT (w->hscroll);
4560 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
4561 register GLYPH *start;
4562 register GLYPH *end;
4563 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4564 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
4565 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
4566 int window_width = XFASTINT (w->width);
4567 /* If 1, we must display multibyte characters. */
4568 int multibyte = !NILP (XBUFFER (w->buffer)->enable_multibyte_characters);
4570 /* Use the standard display table, not the window's display table.
4571 We don't want the mode line in rot13. */
4572 register struct Lisp_Char_Table *dp = 0;
4573 int i;
4575 if (DISP_TABLE_P (Vstandard_display_table))
4576 dp = XCHAR_TABLE (Vstandard_display_table);
4578 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
4580 p1 = p1start;
4581 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
4583 if (obey_window_width)
4585 end = start + window_width - (truncate != 0);
4587 if (!WINDOW_RIGHTMOST_P (w))
4589 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
4591 int i;
4593 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
4594 *end-- = ' ';
4596 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4597 *end-- = '|';
4601 if (! obey_window_width
4602 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
4603 end = desired_glyphs->glyphs[vpos] + maxcol;
4605 /* Store 0 in charstart for these columns. */
4606 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
4607 desired_glyphs->charstarts[vpos][i] = 0;
4609 if (maxcol >= 0 && mincol > maxcol)
4610 mincol = maxcol;
4612 if (length < 0)
4613 /* We need this value for multibyte characters. */
4614 length = strlen (string);
4616 /* We set truncated to 1 if we get stopped by trying to pass END
4617 (that is, trying to pass MAXCOL.) */
4618 truncated = 0;
4619 while (1)
4621 int len;
4623 if (length <= 0)
4624 break;
4625 if (multibyte)
4626 c = STRING_CHAR_AND_LENGTH (string, length, len);
4627 else
4628 c = *string, len = 1;
4630 string += len, length -= len;
4632 if (p1 >= end)
4634 truncated = 1;
4635 break;
4638 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
4640 p1 = copy_part_of_rope (f, p1, start,
4641 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
4642 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
4645 else if (c >= 040 && c < 0177)
4647 if (p1 >= start)
4648 *p1 = c;
4649 p1++;
4651 else if (c == '\t')
4655 if (p1 >= start && p1 < end)
4656 *p1 = SPACEGLYPH;
4657 p1++;
4659 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
4661 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
4663 if (p1 >= start)
4664 *p1 = (fix_glyph
4665 (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
4666 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp)))
4667 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
4668 0));
4669 p1++;
4670 if (p1 >= start && p1 < end)
4671 *p1 = c ^ 0100;
4672 p1++;
4674 else if (len == 1)
4676 /* C is a control character or a binary byte data. */
4677 if (p1 >= start)
4678 *p1 = (fix_glyph
4679 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
4680 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
4681 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
4682 0));
4683 p1++;
4684 if (p1 >= start && p1 < end)
4685 *p1 = (c >> 6) + '0';
4686 p1++;
4687 if (p1 >= start && p1 < end)
4688 *p1 = (7 & (c >> 3)) + '0';
4689 p1++;
4690 if (p1 >= start && p1 < end)
4691 *p1 = (7 & c) + '0';
4692 p1++;
4694 else
4696 /* C is a multibyte character. */
4697 int charset = CHAR_CHARSET (c);
4698 int columns = (charset == CHARSET_COMPOSITION
4699 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
4700 : CHARSET_WIDTH (charset));
4702 if (p1 < start)
4704 /* Since we can't show the left part of C, fill all
4705 columns with spaces. */
4706 columns -= start - p1;
4707 p1 = start;
4708 while (columns--)
4710 if (p1 < end)
4711 *p1 = SPACEGLYPH;
4712 p1++;
4715 else if (p1 + columns > end)
4717 /* Since we can't show the right part of C, fill all
4718 columns with TRUNCATE if TRUNCATE is specified. */
4719 if (truncate)
4721 while (p1 < end)
4722 *p1++ = fix_glyph (f, truncate, 0);
4723 /* And tell the line is truncated. */
4724 truncated = 1;
4726 break;
4728 else
4730 /* We can show the whole glyph of C. */
4731 *p1++ = c;
4732 while (--columns)
4733 *p1++ = c | GLYPH_MASK_PADDING;
4738 if (truncated)
4740 p1 = end;
4741 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
4743 else if (mincol >= 0)
4745 end = desired_glyphs->glyphs[vpos] + mincol;
4746 while (p1 < end)
4747 *p1++ = SPACEGLYPH;
4751 register int len = p1 - desired_glyphs->glyphs[vpos];
4753 if (len > desired_glyphs->used[vpos])
4754 desired_glyphs->used[vpos] = len;
4755 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
4757 return len;
4761 /* This is like a combination of memq and assq.
4762 Return 1 if PROPVAL appears as an element of LIST
4763 or as the car of an element of LIST.
4764 If PROPVAL is a list, compare each element against LIST
4765 in that way, and return 1 if any element of PROPVAL is found in LIST.
4766 Otherwise return 0.
4767 This function cannot quit. */
4770 invisible_p (propval, list)
4771 register Lisp_Object propval;
4772 Lisp_Object list;
4774 register Lisp_Object tail, proptail;
4775 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4777 register Lisp_Object tem;
4778 tem = XCONS (tail)->car;
4779 if (EQ (propval, tem))
4780 return 1;
4781 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4782 return 1;
4784 if (CONSP (propval))
4785 for (proptail = propval; CONSP (proptail);
4786 proptail = XCONS (proptail)->cdr)
4788 Lisp_Object propelt;
4789 propelt = XCONS (proptail)->car;
4790 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4792 register Lisp_Object tem;
4793 tem = XCONS (tail)->car;
4794 if (EQ (propelt, tem))
4795 return 1;
4796 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4797 return 1;
4800 return 0;
4803 /* Return 1 if PROPVAL appears as the car of an element of LIST
4804 and the cdr of that element is non-nil.
4805 If PROPVAL is a list, check each element of PROPVAL in that way,
4806 and the first time some element is found,
4807 return 1 if the cdr of that element is non-nil.
4808 Otherwise return 0.
4809 This function cannot quit. */
4812 invisible_ellipsis_p (propval, list)
4813 register Lisp_Object propval;
4814 Lisp_Object list;
4816 register Lisp_Object tail, proptail;
4817 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4819 register Lisp_Object tem;
4820 tem = XCONS (tail)->car;
4821 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4822 return ! NILP (XCONS (tem)->cdr);
4824 if (CONSP (propval))
4825 for (proptail = propval; CONSP (proptail);
4826 proptail = XCONS (proptail)->cdr)
4828 Lisp_Object propelt;
4829 propelt = XCONS (proptail)->car;
4830 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4832 register Lisp_Object tem;
4833 tem = XCONS (tail)->car;
4834 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4835 return ! NILP (XCONS (tem)->cdr);
4838 return 0;
4841 void
4842 syms_of_xdisp ()
4844 staticpro (&Qmenu_bar_update_hook);
4845 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
4847 staticpro (&Qoverriding_terminal_local_map);
4848 Qoverriding_terminal_local_map = intern ("overriding-terminal-local-map");
4850 staticpro (&Qoverriding_local_map);
4851 Qoverriding_local_map = intern ("overriding-local-map");
4853 staticpro (&Qwindow_scroll_functions);
4854 Qwindow_scroll_functions = intern ("window-scroll-functions");
4856 staticpro (&Qredisplay_end_trigger_functions);
4857 Qredisplay_end_trigger_functions = intern ("redisplay-end-trigger-functions");
4859 staticpro (&last_arrow_position);
4860 staticpro (&last_arrow_string);
4861 last_arrow_position = Qnil;
4862 last_arrow_string = Qnil;
4864 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
4865 "String (or mode line construct) included (normally) in `mode-line-format'.");
4866 Vglobal_mode_string = Qnil;
4868 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
4869 "Marker for where to display an arrow on top of the buffer text.\n\
4870 This must be the beginning of a line in order to work.\n\
4871 See also `overlay-arrow-string'.");
4872 Voverlay_arrow_position = Qnil;
4874 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
4875 "String to display as an arrow. See also `overlay-arrow-position'.");
4876 Voverlay_arrow_string = Qnil;
4878 DEFVAR_INT ("scroll-step", &scroll_step,
4879 "*The number of lines to try scrolling a window by when point moves out.\n\
4880 If that fails to bring point back on frame, point is centered instead.\n\
4881 If this is zero, point is always centered after it moves off frame.");
4883 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively,
4884 "*Scroll up to this many lines, to bring point back on screen.");
4885 scroll_conservatively = 0;
4887 DEFVAR_INT ("scroll-margin", &scroll_margin,
4888 "*Number of lines of margin at the top and bottom of a window.\n\
4889 Recenter the window whenever point gets within this many lines\n\
4890 of the top or bottom of the window.");
4891 scroll_margin = 0;
4893 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
4895 DEFVAR_BOOL ("truncate-partial-width-windows",
4896 &truncate_partial_width_windows,
4897 "*Non-nil means truncate lines in all windows less than full frame wide.");
4898 truncate_partial_width_windows = 1;
4900 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
4901 "*Non-nil means use inverse video for the mode line.");
4902 mode_line_inverse_video = 1;
4904 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
4905 "*Maximum buffer size for which line number should be displayed.");
4906 line_number_display_limit = 1000000;
4908 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
4909 "*Non-nil means highlight region even in nonselected windows.");
4910 highlight_nonselected_windows = 0;
4912 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
4913 "Non-nil if more than one frame is visible on this display.\n\
4914 Minibuffer-only frames don't count, but iconified frames do.\n\
4915 This variable is not guaranteed to be accurate except while processing\n\
4916 `frame-title-format' and `icon-title-format'.");
4918 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
4919 "Template for displaying the titlebar of visible frames.\n\
4920 \(Assuming the window manager supports this feature.)\n\
4921 This variable has the same structure as `mode-line-format' (which see),\n\
4922 and is used only on frames for which no explicit name has been set\n\
4923 \(see `modify-frame-parameters').");
4924 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
4925 "Template for displaying the titlebar of an iconified frame.\n\
4926 \(Assuming the window manager supports this feature.)\n\
4927 This variable has the same structure as `mode-line-format' (which see),\n\
4928 and is used only on frames for which no explicit name has been set\n\
4929 \(see `modify-frame-parameters').");
4930 Vicon_title_format
4931 = Vframe_title_format
4932 = Fcons (intern ("multiple-frames"),
4933 Fcons (build_string ("%b"),
4934 Fcons (Fcons (build_string (""),
4935 Fcons (intern ("invocation-name"),
4936 Fcons (build_string ("@"),
4937 Fcons (intern ("system-name"),
4938 Qnil)))),
4939 Qnil)));
4941 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
4942 "Maximum number of lines to keep in the message log buffer.\n\
4943 If nil, disable message logging. If t, log messages but don't truncate\n\
4944 the buffer when it becomes large.");
4945 XSETFASTINT (Vmessage_log_max, 50);
4947 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
4948 "Functions called before redisplay, if window sizes have changed.\n\
4949 The value should be a list of functions that take one argument.\n\
4950 Just before redisplay, for each frame, if any of its windows have changed\n\
4951 size since the last redisplay, or have been split or deleted,\n\
4952 all the functions in the list are called, with the frame as argument.");
4953 Vwindow_size_change_functions = Qnil;
4955 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions,
4956 "List of Functions to call before redisplaying a window with scrolling.\n\
4957 Each function is called with two arguments, the window\n\
4958 and its new display-start position. Note that the value of `window-end'\n\
4959 is not valid when these functions are called.");
4960 Vwindow_scroll_functions = Qnil;
4963 /* initialize the window system */
4964 init_xdisp ()
4966 Lisp_Object root_window;
4967 #ifndef COMPILER_REGISTER_BUG
4968 register
4969 #endif /* COMPILER_REGISTER_BUG */
4970 struct window *mini_w;
4972 this_line_bufpos = 0;
4974 mini_w = XWINDOW (minibuf_window);
4975 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
4977 echo_area_glyphs = 0;
4978 previous_echo_glyphs = 0;
4980 if (!noninteractive)
4982 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
4983 XSETFASTINT (XWINDOW (root_window)->top, 0);
4984 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
4985 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
4986 set_window_height (minibuf_window, 1, 0);
4988 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
4989 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));