(updates): Add missing semicolons.
[emacs.git] / src / xdisp.c
blobd088023e6b5fdf7dbe05e0223e5b9d816c7b8f20
1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 1997
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include <config.h>
24 #include <stdio.h>
25 /*#include <ctype.h>*/
26 #undef NULL
27 #include "lisp.h"
28 #include "frame.h"
29 #include "window.h"
30 #include "termchar.h"
31 #include "dispextern.h"
32 #include "buffer.h"
33 #include "charset.h"
34 #include "indent.h"
35 #include "commands.h"
36 #include "macros.h"
37 #include "disptab.h"
38 #include "termhooks.h"
39 #include "intervals.h"
40 #include "keyboard.h"
41 #include "coding.h"
42 #include "process.h"
44 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
45 extern void set_frame_menubar ();
46 extern int pending_menu_activation;
47 #endif
49 extern int interrupt_input;
50 extern int command_loop_level;
52 extern int minibuffer_auto_raise;
54 extern Lisp_Object Qface;
56 extern Lisp_Object Voverriding_local_map;
57 extern Lisp_Object Voverriding_local_map_menu_flag;
59 Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
60 Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
61 Lisp_Object Qredisplay_end_trigger_functions;
63 /* Nonzero means print newline to stdout before next minibuffer message. */
65 int noninteractive_need_newline;
67 /* Nonzero means print newline to message log before next message. */
69 static int message_log_need_newline;
71 #define min(a, b) ((a) < (b) ? (a) : (b))
72 #define max(a, b) ((a) > (b) ? (a) : (b))
73 #define minmax(floor, val, ceil) \
74 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
76 /* The buffer position of the first character appearing
77 entirely or partially on the current frame line.
78 Or zero, which disables the optimization for the current frame line. */
79 static int this_line_bufpos;
81 /* Number of characters past the end of this line,
82 including the terminating newline */
83 static int this_line_endpos;
85 /* The vertical position of this frame line. */
86 static int this_line_vpos;
88 /* Hpos value for start of display on this frame line.
89 Usually zero, but negative if first character really began
90 on previous line */
91 static int this_line_start_hpos;
93 /* Buffer that this_line variables are describing. */
94 static struct buffer *this_line_buffer;
96 /* Value of echo_area_glyphs when it was last acted on.
97 If this is nonzero, there is a message on the frame
98 in the minibuffer and it should be erased as soon
99 as it is no longer requested to appear. */
100 char *previous_echo_glyphs;
102 /* Nonzero means truncate lines in all windows less wide than the frame */
103 int truncate_partial_width_windows;
105 /* Nonzero means we have more than one non-minibuffer-only frame.
106 Not guaranteed to be accurate except while parsing frame-title-format. */
107 int multiple_frames;
109 Lisp_Object Vglobal_mode_string;
111 /* Marker for where to display an arrow on top of the buffer text. */
112 Lisp_Object Voverlay_arrow_position;
114 /* String to display for the arrow. */
115 Lisp_Object Voverlay_arrow_string;
117 /* Like mode-line-format, but for the titlebar on a visible frame. */
118 Lisp_Object Vframe_title_format;
120 /* Like mode-line-format, but for the titlebar on an iconified frame. */
121 Lisp_Object Vicon_title_format;
123 /* List of functions to call when a window's size changes. These
124 functions get one arg, a frame on which one or more windows' sizes
125 have changed. */
126 static Lisp_Object Vwindow_size_change_functions;
128 /* Values of those variables at last redisplay. */
129 static Lisp_Object last_arrow_position, last_arrow_string;
131 Lisp_Object Qmenu_bar_update_hook;
133 /* Nonzero if overlay arrow has been displayed once in this window. */
134 static int overlay_arrow_seen;
136 /* Nonzero if visible end of buffer has already been displayed once
137 in this window. (We need this variable in case there are overlay
138 strings that get displayed there.) */
139 static int zv_strings_seen;
141 /* Nonzero means highlight the region even in nonselected windows. */
142 static int highlight_nonselected_windows;
144 /* If cursor motion alone moves point off frame,
145 Try scrolling this many lines up or down if that will bring it back. */
146 static int scroll_step;
148 /* Non-0 means scroll just far enough to bring point back on the screen,
149 when appropriate. */
150 static int scroll_conservatively;
152 /* Recenter the window whenever point gets within this many lines
153 of the top or bottom of the window. */
154 int scroll_margin;
156 /* Nonzero if try_window_id has made blank lines at window bottom
157 since the last redisplay that paused */
158 static int blank_end_of_window;
160 /* Number of windows showing the buffer of the selected window
161 (or another buffer with the same base buffer).
162 keyboard.c refers to this. */
163 int buffer_shared;
165 /* display_text_line sets these to the frame position (origin 0) of point,
166 whether the window is selected or not.
167 Set one to -1 first to determine whether point was found afterwards. */
169 static int cursor_vpos;
170 static int cursor_hpos;
172 static int debug_end_pos;
174 /* Nonzero means display mode line highlighted */
175 int mode_line_inverse_video;
177 static void redisplay_internal ();
178 static int message_log_check_duplicate ();
179 static void echo_area_display ();
180 void mark_window_display_accurate ();
181 static void redisplay_windows ();
182 static void redisplay_window ();
183 static void update_menu_bar ();
184 static void try_window ();
185 static int try_window_id ();
186 static struct position *display_text_line ();
187 static void display_mode_line ();
188 static int display_mode_element ();
189 static char *decode_mode_spec ();
190 static int display_string ();
191 static void display_menu_bar ();
192 static int display_count_lines ();
194 /* Prompt to display in front of the minibuffer contents */
195 Lisp_Object minibuf_prompt;
197 /* Width in columns of current minibuffer prompt. */
198 int minibuf_prompt_width;
200 /* Message to display instead of minibuffer contents
201 This is what the functions error and message make,
202 and command echoing uses it as well.
203 It overrides the minibuf_prompt as well as the buffer. */
204 char *echo_area_glyphs;
206 /* This is the length of the message in echo_area_glyphs. */
207 int echo_area_glyphs_length;
209 /* This is the window where the echo area message was displayed.
210 It is always a minibuffer window, but it may not be the
211 same window currently active as a minibuffer. */
212 Lisp_Object echo_area_window;
214 /* true iff we should redraw the mode lines on the next redisplay */
215 int update_mode_lines;
217 /* Smallest number of characters before the gap
218 at any time since last redisplay that finished.
219 Valid for current buffer when try_window_id can be called. */
220 int beg_unchanged;
222 /* Smallest number of characters after the gap
223 at any time since last redisplay that finished.
224 Valid for current buffer when try_window_id can be called. */
225 int end_unchanged;
227 /* MODIFF as of last redisplay that finished;
228 if it matches MODIFF, and overlay_unchanged_modified
229 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
230 contain no useful information */
231 int unchanged_modified;
233 /* OVERLAY_MODIFF as of last redisplay that finished. */
234 int overlay_unchanged_modified;
236 /* Nonzero if window sizes or contents have changed
237 since last redisplay that finished */
238 int windows_or_buffers_changed;
240 /* Nonzero after display_mode_line if %l was used
241 and it displayed a line number. */
242 int line_number_displayed;
244 /* Maximum buffer size for which to display line numbers. */
245 static int line_number_display_limit;
247 /* Number of lines to keep in the message log buffer.
248 t means infinite. nil means don't log at all. */
249 Lisp_Object Vmessage_log_max;
251 /* Output a newline in the *Messages* buffer if "needs" one. */
253 void
254 message_log_maybe_newline ()
256 if (message_log_need_newline)
257 message_dolog ("", 0, 1);
261 /* Add a string to the message log, optionally terminated with a newline.
262 This function calls low-level routines in order to bypass text property
263 hooks, etc. which might not be safe to run. */
265 void
266 message_dolog (m, len, nlflag)
267 char *m;
268 int len, nlflag;
270 if (!NILP (Vmessage_log_max))
272 struct buffer *oldbuf;
273 int oldpoint, oldbegv, oldzv;
274 int old_windows_or_buffers_changed = windows_or_buffers_changed;
276 oldbuf = current_buffer;
277 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
278 current_buffer->undo_list = Qt;
279 oldpoint = PT;
280 oldbegv = BEGV;
281 oldzv = ZV;
282 BEGV = BEG;
283 ZV = Z;
284 if (oldpoint == Z)
285 oldpoint += len + nlflag;
286 if (oldzv == Z)
287 oldzv += len + nlflag;
288 TEMP_SET_PT (Z);
289 if (len)
290 insert_1 (m, len, 1, 0);
291 if (nlflag)
293 int this_bol, prev_bol, dup;
294 insert_1 ("\n", 1, 1, 0);
296 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
297 if (this_bol > BEG)
299 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
300 dup = message_log_check_duplicate (prev_bol, this_bol);
301 if (dup)
303 if (oldpoint > prev_bol)
304 oldpoint -= min (this_bol, oldpoint) - prev_bol;
305 if (oldbegv > prev_bol)
306 oldbegv -= min (this_bol, oldbegv) - prev_bol;
307 if (oldzv > prev_bol)
308 oldzv -= min (this_bol, oldzv) - prev_bol;
309 del_range_1 (prev_bol, this_bol, 0);
310 if (dup > 1)
312 char dupstr[40];
313 int duplen;
315 /* If you change this format, don't forget to also
316 change message_log_check_duplicate. */
317 sprintf (dupstr, " [%d times]", dup);
318 duplen = strlen (dupstr);
319 TEMP_SET_PT (Z-1);
320 if (oldpoint == Z)
321 oldpoint += duplen;
322 if (oldzv == Z)
323 oldzv += duplen;
324 insert_1 (dupstr, duplen, 1, 0);
329 if (NATNUMP (Vmessage_log_max))
331 int pos = scan_buffer ('\n', Z, 0,
332 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
333 oldpoint -= min (pos, oldpoint) - BEG;
334 oldbegv -= min (pos, oldbegv) - BEG;
335 oldzv -= min (pos, oldzv) - BEG;
336 del_range_1 (BEG, pos, 0);
339 BEGV = oldbegv;
340 ZV = oldzv;
341 TEMP_SET_PT (oldpoint);
342 set_buffer_internal (oldbuf);
343 windows_or_buffers_changed = old_windows_or_buffers_changed;
344 message_log_need_newline = !nlflag;
348 /* We are at the end of the buffer after just having inserted a newline.
349 (Note: We depend on the fact we won't be crossing the gap.)
350 Check to see if the most recent message looks a lot like the previous one.
351 Return 0 if different, 1 if the new one should just replace it, or a
352 value N > 1 if we should also append " [N times]". */
354 static int
355 message_log_check_duplicate (prev_bol, this_bol)
356 int prev_bol, this_bol;
358 int i;
359 int len = Z - 1 - this_bol;
360 int seen_dots = 0;
361 unsigned char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
362 unsigned char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
364 for (i = 0; i < len; i++)
366 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
367 && p1[i] != '\n')
368 seen_dots = 1;
369 if (p1[i] != p2[i])
370 return seen_dots;
372 p1 += len;
373 if (*p1 == '\n')
374 return 2;
375 if (*p1++ == ' ' && *p1++ == '[')
377 int n = 0;
378 while (*p1 >= '0' && *p1 <= '9')
379 n = n * 10 + *p1++ - '0';
380 if (strncmp (p1, " times]\n", 8) == 0)
381 return n+1;
383 return 0;
386 /* Display an echo area message M with a specified length of LEN chars.
387 The string may include null characters. If M is 0, clear out any
388 existing message, and let the minibuffer text show through.
390 The buffer M must continue to exist until after the echo area
391 gets cleared or some other message gets displayed there.
393 Do not pass text that is stored in a Lisp string.
394 Do not pass text in a buffer that was alloca'd. */
396 void
397 message2 (m, len)
398 char *m;
399 int len;
401 /* First flush out any partial line written with print. */
402 message_log_maybe_newline ();
403 if (m)
404 message_dolog (m, len, 1);
405 message2_nolog (m, len);
409 /* The non-logging counterpart of message2. */
411 void
412 message2_nolog (m, len)
413 char *m;
414 int len;
416 if (noninteractive)
418 if (noninteractive_need_newline)
419 putc ('\n', stderr);
420 noninteractive_need_newline = 0;
421 if (m)
422 fwrite (m, len, 1, stderr);
423 if (cursor_in_echo_area == 0)
424 fprintf (stderr, "\n");
425 fflush (stderr);
427 /* A null message buffer means that the frame hasn't really been
428 initialized yet. Error messages get reported properly by
429 cmd_error, so this must be just an informative message; toss it. */
430 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
432 Lisp_Object mini_window;
433 FRAME_PTR f;
435 /* Get the frame containing the minibuffer
436 that the selected frame is using. */
437 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
438 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
440 FRAME_SAMPLE_VISIBILITY (f);
441 if (FRAME_VISIBLE_P (selected_frame)
442 && ! FRAME_VISIBLE_P (f))
443 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window)));
445 if (m)
447 echo_area_glyphs = m;
448 echo_area_glyphs_length = len;
450 if (minibuffer_auto_raise)
451 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window)));
453 else
454 echo_area_glyphs = previous_echo_glyphs = 0;
456 do_pending_window_change ();
457 echo_area_display ();
458 update_frame (f, 1, 1);
459 do_pending_window_change ();
460 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
461 (*frame_up_to_date_hook) (f);
465 /* Display a null-terminated echo area message M. If M is 0, clear out any
466 existing message, and let the minibuffer text show through.
468 The buffer M must continue to exist until after the echo area
469 gets cleared or some other message gets displayed there.
471 Do not pass text that is stored in a Lisp string.
472 Do not pass text in a buffer that was alloca'd. */
474 void
475 message1 (m)
476 char *m;
478 message2 (m, (m ? strlen (m) : 0));
481 void
482 message1_nolog (m)
483 char *m;
485 message2_nolog (m, (m ? strlen (m) : 0));
488 /* Truncate what will be displayed in the echo area
489 the next time we display it--but don't redisplay it now. */
491 void
492 truncate_echo_area (len)
493 int len;
495 /* A null message buffer means that the frame hasn't really been
496 initialized yet. Error messages get reported properly by
497 cmd_error, so this must be just an informative message; toss it. */
498 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
499 echo_area_glyphs_length = len;
502 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
503 zero if being used by message. */
504 int message_buf_print;
506 /* Dump an informative message to the minibuf. If M is 0, clear out
507 any existing message, and let the minibuffer text show through. */
509 /* VARARGS 1 */
510 void
511 message (m, a1, a2, a3)
512 char *m;
513 EMACS_INT a1, a2, a3;
515 if (noninteractive)
517 if (m)
519 if (noninteractive_need_newline)
520 putc ('\n', stderr);
521 noninteractive_need_newline = 0;
522 fprintf (stderr, m, a1, a2, a3);
523 if (cursor_in_echo_area == 0)
524 fprintf (stderr, "\n");
525 fflush (stderr);
528 else if (INTERACTIVE)
530 /* The frame whose minibuffer we're going to display the message on.
531 It may be larger than the selected frame, so we need
532 to use its buffer, not the selected frame's buffer. */
533 Lisp_Object mini_window;
534 FRAME_PTR f;
536 /* Get the frame containing the minibuffer
537 that the selected frame is using. */
538 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
539 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
541 /* A null message buffer means that the frame hasn't really been
542 initialized yet. Error messages get reported properly by
543 cmd_error, so this must be just an informative message; toss it. */
544 if (FRAME_MESSAGE_BUF (f))
546 if (m)
548 int len;
549 #ifdef NO_ARG_ARRAY
550 EMACS_INT a[3];
551 a[0] = a1;
552 a[1] = a2;
553 a[2] = a3;
555 len = doprnt (FRAME_MESSAGE_BUF (f),
556 FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, a);
557 #else
558 len = doprnt (FRAME_MESSAGE_BUF (f),
559 FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, &a1);
560 #endif /* NO_ARG_ARRAY */
562 message2 (FRAME_MESSAGE_BUF (f), len);
564 else
565 message1 (0);
567 /* Print should start at the beginning of the message
568 buffer next time. */
569 message_buf_print = 0;
574 /* The non-logging version of message. */
575 void
576 message_nolog (m, a1, a2, a3)
577 char *m;
578 EMACS_INT a1, a2, a3;
580 Lisp_Object old_log_max;
581 old_log_max = Vmessage_log_max;
582 Vmessage_log_max = Qnil;
583 message (m, a1, a2, a3);
584 Vmessage_log_max = old_log_max;
587 void
588 update_echo_area ()
590 message2 (echo_area_glyphs, echo_area_glyphs_length);
593 static void
594 echo_area_display ()
596 register int vpos;
597 FRAME_PTR f;
598 Lisp_Object mini_window;
600 /* Choose the minibuffer window for this display.
601 It is the minibuffer window used by the selected frame. */
602 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
603 /* This is the frame that window is in. */
604 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
606 if (! FRAME_VISIBLE_P (f))
607 return;
609 if (frame_garbaged)
611 redraw_garbaged_frames ();
612 frame_garbaged = 0;
615 if (echo_area_glyphs || minibuf_level == 0)
617 int i;
619 echo_area_window = mini_window;
621 vpos = XFASTINT (XWINDOW (mini_window)->top);
622 get_display_line (f, vpos, 0);
624 /* Make sure the columns that overlap a left-hand scroll bar
625 are always clear. */
626 for (i = 0; i < FRAME_LEFT_SCROLL_BAR_WIDTH (f); i++)
627 f->desired_glyphs->glyphs[vpos][i] = SPACEGLYPH;
629 display_string (XWINDOW (mini_window), vpos,
630 echo_area_glyphs ? echo_area_glyphs : "",
631 echo_area_glyphs ? echo_area_glyphs_length : -1,
632 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
633 0, 0, 0,
634 FRAME_WIDTH (f) + FRAME_LEFT_SCROLL_BAR_WIDTH (f));
636 #if 0 /* This just gets in the way. update_frame does the job. */
637 /* If desired cursor location is on this line, put it at end of text */
638 if (cursor_in_echo_area)
639 FRAME_CURSOR_Y (f) = vpos;
640 if (FRAME_CURSOR_Y (f) == vpos)
641 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
642 #endif
644 /* Fill the rest of the minibuffer window with blank lines. */
646 int i;
648 for (i = vpos + 1;
649 i < vpos + XFASTINT (XWINDOW (mini_window)->height); i++)
651 get_display_line (f, i, 0);
652 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
653 hpos, because it is good to clear whatever is behind the
654 scroll bar. This does not affect the scroll bar itself. */
655 display_string (XWINDOW (mini_window), i,
656 "", 0,
657 0, 0, 0,
658 0, FRAME_WIDTH (f) + FRAME_SCROLL_BAR_WIDTH (f));
662 else if (!EQ (mini_window, selected_window))
663 windows_or_buffers_changed++;
665 if (EQ (mini_window, selected_window))
666 this_line_bufpos = 0;
668 previous_echo_glyphs = echo_area_glyphs;
671 /* Update frame titles. */
673 #ifdef HAVE_WINDOW_SYSTEM
674 static char frame_title_buf[512];
675 static char *frame_title_ptr;
677 static int
678 store_frame_title (str, mincol, maxcol)
679 char *str;
680 int mincol, maxcol;
682 char *limit;
683 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
684 maxcol = sizeof (frame_title_buf);
685 limit = &frame_title_buf[maxcol];
686 while (*str != '\0' && frame_title_ptr < limit)
687 *frame_title_ptr++ = *str++;
688 while (frame_title_ptr < &frame_title_buf[mincol])
689 *frame_title_ptr++ = ' ';
690 return frame_title_ptr - frame_title_buf;
693 static void
694 x_consider_frame_title (frame)
695 Lisp_Object frame;
697 Lisp_Object fmt;
698 struct buffer *obuf;
699 int len;
700 FRAME_PTR f = XFRAME (frame);
702 if (!(FRAME_WINDOW_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name))
703 return;
705 /* Do we have more than one visible frame on this X display? */
707 Lisp_Object tail;
709 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
711 FRAME_PTR tf = XFRAME (XCONS (tail)->car);
713 if (tf != f && FRAME_KBOARD (tf) == FRAME_KBOARD (f)
714 && !FRAME_MINIBUF_ONLY_P (tf)
715 && (FRAME_VISIBLE_P (tf) || FRAME_ICONIFIED_P (tf)))
716 break;
719 multiple_frames = CONSP (tail);
722 obuf = current_buffer;
723 Fset_buffer (XWINDOW (f->selected_window)->buffer);
724 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
725 frame_title_ptr = frame_title_buf;
726 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
727 0, sizeof (frame_title_buf), fmt);
728 frame_title_ptr = 0;
729 set_buffer_internal (obuf);
730 /* Set the name only if it's changed. This avoids consing
731 in the common case where it hasn't. (If it turns out that we've
732 already wasted too much time by walking through the list with
733 display_mode_element, then we might need to optimize at a higher
734 level than this.) */
735 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
736 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
737 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
739 #else
740 #define frame_title_ptr ((char *)0)
741 #define store_frame_title(str, mincol, maxcol) 0
742 #endif
744 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
745 This can call eval. */
747 void
748 prepare_menu_bars ()
750 register struct window *w = XWINDOW (selected_window);
751 int all_windows;
752 struct gcpro gcpro1, gcpro2;
754 all_windows = (update_mode_lines || buffer_shared > 1
755 || windows_or_buffers_changed);
757 /* Update all frame titles based on their buffer names, etc.
758 We do this before the menu bars so that the buffer-menu
759 will show the up-to-date frame titles.
761 This used to be done after the menu bars, for a reason that
762 was stated as follows but which I do not understand:
763 "We do this after the menu bars so that the frame will first
764 create its menu bar using the name `emacs' if no other name
765 has yet been specified."
766 I think that is no longer a concern. */
767 #ifdef HAVE_WINDOW_SYSTEM
768 if (windows_or_buffers_changed || update_mode_lines)
770 Lisp_Object tail, frame;
772 FOR_EACH_FRAME (tail, frame)
773 if (FRAME_VISIBLE_P (XFRAME (frame))
774 || FRAME_ICONIFIED_P (XFRAME (frame)))
775 x_consider_frame_title (frame);
777 #endif
779 /* Update the menu bar item lists, if appropriate.
780 This has to be done before any actual redisplay
781 or generation of display lines. */
782 if (all_windows)
784 Lisp_Object tail, frame;
785 int count = specpdl_ptr - specpdl;
787 record_unwind_protect (Fstore_match_data, Fmatch_data (Qnil, Qnil));
789 FOR_EACH_FRAME (tail, frame)
791 /* If a window on this frame changed size,
792 report that to the user and clear the size-change flag. */
793 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
795 Lisp_Object functions;
796 /* Clear flag first in case we get error below. */
797 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
798 functions = Vwindow_size_change_functions;
799 GCPRO2 (tail, functions);
800 while (CONSP (functions))
802 call1 (XCONS (functions)->car, frame);
803 functions = XCONS (functions)->cdr;
805 UNGCPRO;
807 GCPRO1 (tail);
808 update_menu_bar (XFRAME (frame), 0);
809 UNGCPRO;
812 unbind_to (count, Qnil);
814 else
815 update_menu_bar (selected_frame, 1);
817 /* Motif needs this. See comment in xmenu.c.
818 Turn it off when pending_menu_activation is not defined. */
819 #ifdef USE_X_TOOLKIT
820 pending_menu_activation = 0;
821 #endif
824 /* Do a frame update, taking possible shortcuts into account.
825 This is the main external entry point for redisplay.
827 If the last redisplay displayed an echo area message and that
828 message is no longer requested, we clear the echo area
829 or bring back the minibuffer if that is in use.
831 Do not call eval from within this function.
832 Calls to eval after the call to echo_area_display would confuse
833 the display_line mechanism and would cause a crash.
834 Calls to eval before that point will work most of the time,
835 but can still lose, because this function
836 can be called from signal handlers; with alarms set up;
837 or with synchronous processes running.
839 See Fcall_process; if you called it from here, it could be
840 entered recursively. */
842 static int do_verify_charstarts;
844 /* Counter is used to clear the face cache
845 no more than once ever 1000 redisplays. */
846 static int clear_face_cache_count;
848 /* Record the previous terminal frame we displayed. */
849 static FRAME_PTR previous_terminal_frame;
851 void
852 redisplay ()
854 redisplay_internal (0);
857 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
858 is not in response to any user action; therefore, we should
859 preserve the echo area. (Actually, our caller does that job.)
860 Perhaps in the future avoid recentering windows
861 if it is not necessary; currently that causes some problems. */
863 static void
864 redisplay_internal (preserve_echo_area)
865 int preserve_echo_area;
867 register struct window *w = XWINDOW (selected_window);
868 register int pause;
869 int must_finish = 0;
870 int all_windows;
871 register int tlbufpos, tlendpos;
872 struct position pos;
873 int number_of_visible_frames;
875 if (noninteractive)
876 return;
878 #ifdef USE_X_TOOLKIT
879 if (popup_activated ())
880 return;
881 #endif
883 retry:
885 if (! FRAME_WINDOW_P (selected_frame)
886 && previous_terminal_frame != selected_frame)
888 /* Since frames on an ASCII terminal share the same display area,
889 displaying a different frame means redisplay the whole thing. */
890 windows_or_buffers_changed++;
891 SET_FRAME_GARBAGED (selected_frame);
892 XSETFRAME (Vterminal_frame, selected_frame);
894 previous_terminal_frame = selected_frame;
896 /* Set the visible flags for all frames.
897 Do this before checking for resized or garbaged frames; they want
898 to know if their frames are visible.
899 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
901 Lisp_Object tail, frame;
903 number_of_visible_frames = 0;
905 FOR_EACH_FRAME (tail, frame)
907 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
909 number_of_visible_frames++;
911 /* Clear out all the display lines in which we will generate the
912 glyphs to display. */
913 init_desired_glyphs (XFRAME (frame));
917 /* Notice any pending interrupt request to change frame size. */
918 do_pending_window_change ();
920 if (frame_garbaged)
922 redraw_garbaged_frames ();
923 frame_garbaged = 0;
926 prepare_menu_bars ();
928 if (windows_or_buffers_changed)
929 update_mode_lines++;
931 /* Detect case that we need to write or remove a star in the mode line. */
932 if ((SAVE_MODIFF < MODIFF) != !NILP (w->last_had_star))
934 w->update_mode_line = Qt;
935 if (buffer_shared > 1)
936 update_mode_lines++;
939 /* If %c is in use, update it if needed. */
940 if (!NILP (w->column_number_displayed)
941 /* This alternative quickly identifies a common case
942 where no change is needed. */
943 && !(PT == XFASTINT (w->last_point)
944 && XFASTINT (w->last_modified) >= MODIFF
945 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)
946 && XFASTINT (w->column_number_displayed) != current_column ())
947 w->update_mode_line = Qt;
949 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
951 all_windows = update_mode_lines || buffer_shared > 1;
953 /* If specs for an arrow have changed, do thorough redisplay
954 to ensure we remove any arrow that should no longer exist. */
955 if (! EQ (Voverlay_arrow_position, last_arrow_position)
956 || ! EQ (Voverlay_arrow_string, last_arrow_string))
957 all_windows = 1;
959 /* Normally the message* functions will have already displayed and
960 updated the echo area, but the frame may have been trashed, or
961 the update may have been preempted, so display the echo area
962 again here. */
963 if (echo_area_glyphs || previous_echo_glyphs)
965 echo_area_display ();
966 must_finish = 1;
969 /* If showing region, and mark has changed, must redisplay whole window. */
970 if (((!NILP (Vtransient_mark_mode)
971 && !NILP (XBUFFER (w->buffer)->mark_active))
972 != !NILP (w->region_showing))
973 || (!NILP (w->region_showing)
974 && !EQ (w->region_showing,
975 Fmarker_position (XBUFFER (w->buffer)->mark))))
976 this_line_bufpos = -1;
978 tlbufpos = this_line_bufpos;
979 tlendpos = this_line_endpos;
980 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
981 && !current_buffer->clip_changed
982 && FRAME_VISIBLE_P (XFRAME (w->frame))
983 /* Make sure recorded data applies to current buffer, etc */
984 && this_line_buffer == current_buffer
985 && current_buffer == XBUFFER (w->buffer)
986 && NILP (w->force_start)
987 /* Point must be on the line that we have info recorded about */
988 && PT >= tlbufpos
989 && PT <= Z - tlendpos
990 /* All text outside that line, including its final newline,
991 must be unchanged */
992 && ((XFASTINT (w->last_modified) >= MODIFF
993 && (XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF))
994 || (beg_unchanged >= tlbufpos - 1
995 && GPT >= tlbufpos
996 /* If selective display, can't optimize
997 if the changes start at the beginning of the line. */
998 && ((INTEGERP (current_buffer->selective_display)
999 && XINT (current_buffer->selective_display) > 0
1000 ? (beg_unchanged >= tlbufpos
1001 && GPT > tlbufpos)
1002 : 1))
1003 && end_unchanged >= tlendpos
1004 && Z - GPT >= tlendpos)))
1006 if (tlbufpos > BEGV && FETCH_BYTE (tlbufpos - 1) != '\n'
1007 && (tlbufpos == ZV
1008 || FETCH_BYTE (tlbufpos) == '\n'))
1009 /* Former continuation line has disappeared by becoming empty */
1010 goto cancel;
1011 else if (XFASTINT (w->last_modified) < MODIFF
1012 || XFASTINT (w->last_overlay_modified) < OVERLAY_MODIFF
1013 || MINI_WINDOW_P (w))
1015 /* We have to handle the case of continuation around a
1016 wide-column character (See the comment in indent.c around
1017 line 885).
1019 For instance, in the following case:
1021 -------- Insert --------
1022 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1023 J_I_ ==> J_I_ `^^' are cursors.
1024 ^^ ^^
1025 -------- --------
1027 As we have to redraw the line above, we should goto cancel. */
1029 struct position val;
1030 int prevline;
1032 prevline = find_next_newline (tlbufpos, -1);
1033 val = *compute_motion (prevline, 0,
1034 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1036 tlbufpos,
1037 1 << (BITS_PER_SHORT - 1),
1038 1 << (BITS_PER_SHORT - 1),
1039 window_internal_width (w) - 1,
1040 XINT (w->hscroll), 0, w);
1041 if (val.hpos != this_line_start_hpos)
1042 goto cancel;
1044 cursor_vpos = -1;
1045 overlay_arrow_seen = 0;
1046 zv_strings_seen = 0;
1047 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
1048 pos_tab_offset (w, tlbufpos), 0);
1049 /* If line contains point, is not continued,
1050 and ends at same distance from eob as before, we win */
1051 if (cursor_vpos >= 0 && this_line_bufpos
1052 && this_line_endpos == tlendpos)
1054 /* If this is not the window's last line,
1055 we must adjust the charstarts of the lines below. */
1056 if (this_line_vpos + 1
1057 < XFASTINT (w->top) + window_internal_height (w))
1059 int left = WINDOW_LEFT_MARGIN (w);
1060 int *charstart_next_line
1061 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
1062 int adjust;
1064 if (Z - tlendpos == ZV)
1065 /* This line ends at end of (accessible part of) buffer.
1066 There is no newline to count. */
1067 adjust = Z - tlendpos - charstart_next_line[left];
1068 else
1069 /* This line ends in a newline.
1070 Must take account of the newline and the rest of the
1071 text that follows. */
1072 adjust = Z - tlendpos + 1 - charstart_next_line[left];
1074 adjust_window_charstarts (w, this_line_vpos, adjust);
1077 if (!WINDOW_FULL_WIDTH_P (w))
1078 preserve_other_columns (w);
1079 goto update;
1081 else
1082 goto cancel;
1084 else if (PT == XFASTINT (w->last_point)
1085 /* Make sure the cursor was last displayed
1086 in this window. Otherwise we have to reposition it. */
1087 && XINT (w->top) <= FRAME_CURSOR_Y (selected_frame)
1088 && (XINT (w->top) + XINT (w->height)
1089 > FRAME_CURSOR_Y (selected_frame)))
1091 if (!must_finish)
1093 do_pending_window_change ();
1094 return;
1096 goto update;
1098 /* If highlighting the region, or if the cursor is in the echo area,
1099 then we can't just move the cursor. */
1100 else if (! (!NILP (Vtransient_mark_mode)
1101 && !NILP (current_buffer->mark_active))
1102 && (w == XWINDOW (current_buffer->last_selected_window)
1103 || highlight_nonselected_windows)
1104 && NILP (w->region_showing)
1105 && !cursor_in_echo_area)
1107 pos = *compute_motion (tlbufpos, 0,
1108 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1110 PT, 2, - (1 << (BITS_PER_SHORT - 1)),
1111 window_internal_width (w) - 1,
1112 XINT (w->hscroll),
1113 pos_tab_offset (w, tlbufpos), w);
1114 if (pos.vpos < 1)
1116 int width = window_internal_width (w) - 1;
1117 FRAME_CURSOR_X (selected_frame)
1118 = WINDOW_LEFT_MARGIN (w) + minmax (0, pos.hpos, width);
1119 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
1120 goto update;
1122 else
1123 goto cancel;
1125 cancel:
1126 /* Text changed drastically or point moved off of line */
1127 cancel_line (this_line_vpos, selected_frame);
1130 this_line_bufpos = 0;
1131 all_windows |= buffer_shared > 1;
1133 clear_face_cache_count++;
1135 if (all_windows)
1137 Lisp_Object tail, frame;
1139 #ifdef HAVE_FACES
1140 /* Clear the face cache, only when we do a full redisplay
1141 and not too often either. */
1142 if (clear_face_cache_count > 1000)
1144 clear_face_cache ();
1145 clear_face_cache_count = 0;
1147 #endif
1149 /* Recompute # windows showing selected buffer.
1150 This will be incremented each time such a window is displayed. */
1151 buffer_shared = 0;
1153 FOR_EACH_FRAME (tail, frame)
1155 FRAME_PTR f = XFRAME (frame);
1156 if (FRAME_WINDOW_P (f) || f == selected_frame)
1159 /* Mark all the scroll bars to be removed; we'll redeem the ones
1160 we want when we redisplay their windows. */
1161 if (condemn_scroll_bars_hook)
1162 (*condemn_scroll_bars_hook) (f);
1164 if (FRAME_VISIBLE_P (f))
1165 redisplay_windows (FRAME_ROOT_WINDOW (f), preserve_echo_area);
1167 /* Any scroll bars which redisplay_windows should have nuked
1168 should now go away. */
1169 if (judge_scroll_bars_hook)
1170 (*judge_scroll_bars_hook) (f);
1174 else if (FRAME_VISIBLE_P (selected_frame))
1176 redisplay_window (selected_window, 1, preserve_echo_area);
1177 if (!WINDOW_FULL_WIDTH_P (w))
1178 preserve_other_columns (w);
1181 update:
1182 /* Prevent various kinds of signals during display update.
1183 stdio is not robust about handling signals,
1184 which can cause an apparent I/O error. */
1185 if (interrupt_input)
1186 unrequest_sigio ();
1187 stop_polling ();
1189 if (all_windows)
1191 Lisp_Object tail;
1193 pause = 0;
1195 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
1197 FRAME_PTR f;
1199 if (!FRAMEP (XCONS (tail)->car))
1200 continue;
1202 f = XFRAME (XCONS (tail)->car);
1204 if ((FRAME_WINDOW_P (f) || f == selected_frame)
1205 && FRAME_VISIBLE_P (f))
1207 pause |= update_frame (f, 0, 0);
1208 if (!pause)
1210 mark_window_display_accurate (f->root_window, 1);
1211 if (frame_up_to_date_hook != 0)
1212 (*frame_up_to_date_hook) (f);
1217 else
1219 if (FRAME_VISIBLE_P (selected_frame))
1220 pause = update_frame (selected_frame, 0, 0);
1221 else
1222 pause = 0;
1224 /* We may have called echo_area_display at the top of this
1225 function. If the echo area is on another frame, that may
1226 have put text on a frame other than the selected one, so the
1227 above call to update_frame would not have caught it. Catch
1228 it here. */
1230 Lisp_Object mini_window;
1231 FRAME_PTR mini_frame;
1233 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
1234 mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
1236 if (mini_frame != selected_frame && FRAME_WINDOW_P (mini_frame))
1237 pause |= update_frame (mini_frame, 0, 0);
1241 /* If frame does not match, prevent doing single-line-update next time.
1242 Also, don't forget to check every line to update the arrow. */
1243 if (pause)
1245 this_line_bufpos = 0;
1246 if (!NILP (last_arrow_position))
1248 last_arrow_position = Qt;
1249 last_arrow_string = Qt;
1251 /* If we pause after scrolling, some lines in current_frame
1252 may be null, so preserve_other_columns won't be able to
1253 preserve all the vertical-bar separators. So, avoid using it
1254 in that case. */
1255 if (!WINDOW_FULL_WIDTH_P (w))
1256 update_mode_lines = 1;
1259 /* Now text on frame agrees with windows, so
1260 put info into the windows for partial redisplay to follow */
1262 if (!pause)
1264 register struct buffer *b = XBUFFER (w->buffer);
1266 blank_end_of_window = 0;
1267 unchanged_modified = BUF_MODIFF (b);
1268 overlay_unchanged_modified = BUF_OVERLAY_MODIFF (b);
1269 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1270 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1272 XSETFASTINT (w->last_point, BUF_PT (b));
1273 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1274 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1276 if (all_windows)
1277 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1278 else
1280 b->clip_changed = 0;
1281 w->update_mode_line = Qnil;
1282 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1283 XSETFASTINT (w->last_overlay_modified, BUF_OVERLAY_MODIFF (b));
1284 w->last_had_star
1285 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1286 ? Qt : Qnil);
1288 /* Record if we are showing a region, so can make sure to
1289 update it fully at next redisplay. */
1290 w->region_showing = (!NILP (Vtransient_mark_mode)
1291 && (w == XWINDOW (current_buffer->last_selected_window)
1292 || highlight_nonselected_windows)
1293 && !NILP (XBUFFER (w->buffer)->mark_active)
1294 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1295 : Qnil);
1297 w->window_end_valid = w->buffer;
1298 last_arrow_position = Voverlay_arrow_position;
1299 last_arrow_string = Voverlay_arrow_string;
1300 if (do_verify_charstarts)
1301 verify_charstarts (w);
1302 if (frame_up_to_date_hook != 0)
1303 (*frame_up_to_date_hook) (selected_frame);
1305 update_mode_lines = 0;
1306 windows_or_buffers_changed = 0;
1309 /* Start SIGIO interrupts coming again.
1310 Having them off during the code above
1311 makes it less likely one will discard output,
1312 but not impossible, since there might be stuff
1313 in the system buffer here.
1314 But it is much hairier to try to do anything about that. */
1316 if (interrupt_input)
1317 request_sigio ();
1318 start_polling ();
1320 /* If something has become visible now which was not before,
1321 redisplay again, so that we get them. */
1322 if (!pause)
1324 Lisp_Object tail, frame;
1325 int new_count = 0;
1327 FOR_EACH_FRAME (tail, frame)
1329 int this_is_visible = 0;
1330 if (FRAME_WINDOW_P (XFRAME (frame))
1331 || XFRAME (frame) == selected_frame)
1333 if (XFRAME (frame)->visible)
1334 this_is_visible = 1;
1335 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1336 if (XFRAME (frame)->visible)
1337 this_is_visible = 1;
1340 if (this_is_visible)
1341 new_count++;
1344 if (new_count != number_of_visible_frames)
1345 windows_or_buffers_changed++;
1348 /* Change frame size now if a change is pending. */
1349 do_pending_window_change ();
1351 /* If we just did a pending size change, or have additional
1352 visible frames, redisplay again. */
1353 if (windows_or_buffers_changed && !pause)
1354 goto retry;
1357 /* Redisplay, but leave alone any recent echo area message
1358 unless another message has been requested in its place.
1360 This is useful in situations where you need to redisplay but no
1361 user action has occurred, making it inappropriate for the message
1362 area to be cleared. See tracking_off and
1363 wait_reading_process_input for examples of these situations. */
1365 redisplay_preserve_echo_area ()
1367 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1369 echo_area_glyphs = previous_echo_glyphs;
1370 redisplay_internal (1);
1371 echo_area_glyphs = 0;
1373 else
1374 redisplay_internal (1);
1377 void
1378 mark_window_display_accurate (window, flag)
1379 Lisp_Object window;
1380 int flag;
1382 register struct window *w;
1384 for (;!NILP (window); window = w->next)
1386 if (!WINDOWP (window)) abort ();
1387 w = XWINDOW (window);
1389 if (!NILP (w->buffer))
1391 XSETFASTINT (w->last_modified,
1392 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1393 XSETFASTINT (w->last_overlay_modified,
1394 !flag ? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w->buffer)));
1395 w->last_had_star
1396 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1397 ? Qt : Qnil);
1399 /* Record if we are showing a region, so can make sure to
1400 update it fully at next redisplay. */
1401 w->region_showing = (!NILP (Vtransient_mark_mode)
1402 && (w == XWINDOW (current_buffer->last_selected_window)
1403 || highlight_nonselected_windows)
1404 && !NILP (XBUFFER (w->buffer)->mark_active)
1405 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1406 : Qnil);
1409 w->window_end_valid = w->buffer;
1410 w->update_mode_line = Qnil;
1411 if (!NILP (w->buffer) && flag)
1412 XBUFFER (w->buffer)->clip_changed = 0;
1414 if (!NILP (w->vchild))
1415 mark_window_display_accurate (w->vchild, flag);
1416 if (!NILP (w->hchild))
1417 mark_window_display_accurate (w->hchild, flag);
1420 if (flag)
1422 last_arrow_position = Voverlay_arrow_position;
1423 last_arrow_string = Voverlay_arrow_string;
1425 else
1427 /* t is unequal to any useful value of Voverlay_arrow_... */
1428 last_arrow_position = Qt;
1429 last_arrow_string = Qt;
1433 /* Update the menu bar item list for frame F.
1434 This has to be done before we start to fill in any display lines,
1435 because it can call eval.
1437 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1439 static void
1440 update_menu_bar (f, save_match_data)
1441 FRAME_PTR f;
1442 int save_match_data;
1444 struct buffer *old = current_buffer;
1445 Lisp_Object window;
1446 register struct window *w;
1448 window = FRAME_SELECTED_WINDOW (f);
1449 w = XWINDOW (window);
1451 if (update_mode_lines)
1452 w->update_mode_line = Qt;
1454 if (FRAME_WINDOW_P (f)
1456 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1457 FRAME_EXTERNAL_MENU_BAR (f)
1458 #else
1459 FRAME_MENU_BAR_LINES (f) > 0
1460 #endif
1461 : FRAME_MENU_BAR_LINES (f) > 0)
1463 /* If the user has switched buffers or windows, we need to
1464 recompute to reflect the new bindings. But we'll
1465 recompute when update_mode_lines is set too; that means
1466 that people can use force-mode-line-update to request
1467 that the menu bar be recomputed. The adverse effect on
1468 the rest of the redisplay algorithm is about the same as
1469 windows_or_buffers_changed anyway. */
1470 if (windows_or_buffers_changed
1471 || !NILP (w->update_mode_line)
1472 || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1473 < BUF_MODIFF (XBUFFER (w->buffer)))
1474 != !NILP (w->last_had_star))
1475 || ((!NILP (Vtransient_mark_mode)
1476 && !NILP (XBUFFER (w->buffer)->mark_active))
1477 != !NILP (w->region_showing)))
1479 struct buffer *prev = current_buffer;
1480 int count = specpdl_ptr - specpdl;
1482 set_buffer_internal_1 (XBUFFER (w->buffer));
1483 if (save_match_data)
1484 record_unwind_protect (Fstore_match_data, Fmatch_data (Qnil, Qnil));
1485 if (NILP (Voverriding_local_map_menu_flag))
1487 specbind (Qoverriding_terminal_local_map, Qnil);
1488 specbind (Qoverriding_local_map, Qnil);
1491 /* Run the Lucid hook. */
1492 call1 (Vrun_hooks, Qactivate_menubar_hook);
1493 /* If it has changed current-menubar from previous value,
1494 really recompute the menubar from the value. */
1495 if (! NILP (Vlucid_menu_bar_dirty_flag))
1496 call0 (Qrecompute_lucid_menubar);
1497 safe_run_hooks (Qmenu_bar_update_hook);
1498 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1499 /* Redisplay the menu bar in case we changed it. */
1500 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1501 if (FRAME_WINDOW_P (f))
1502 set_frame_menubar (f, 0, 0);
1503 else
1504 /* On a terminal screen, the menu bar is an ordinary screen
1505 line, and this makes it get updated. */
1506 w->update_mode_line = Qt;
1507 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1508 /* In the non-toolkit version, the menu bar is an ordinary screen
1509 line, and this makes it get updated. */
1510 w->update_mode_line = Qt;
1511 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1513 unbind_to (count, Qnil);
1514 set_buffer_internal_1 (prev);
1519 int do_id = 1;
1521 /* Redisplay WINDOW and its subwindows and siblings. */
1523 static void
1524 redisplay_windows (window, preserve_echo_area)
1525 Lisp_Object window;
1526 int preserve_echo_area;
1528 for (; !NILP (window); window = XWINDOW (window)->next)
1529 redisplay_window (window, 0, preserve_echo_area);
1532 /* Return value in display table DP (Lisp_Char_Table *) for character
1533 C. Since a display table doesn't have any parent, we don't have to
1534 follow parent. Do not call this function directly but use the
1535 macro DISP_CHAR_VECTOR. */
1536 Lisp_Object
1537 disp_char_vector (dp, c)
1538 struct Lisp_Char_Table *dp;
1539 int c;
1541 int code[4], i;
1542 Lisp_Object val;
1544 if (SINGLE_BYTE_CHAR_P (c)) return (dp->contents[c]);
1546 SPLIT_NON_ASCII_CHAR (c, code[0], code[1], code[2]);
1547 if (code[0] != CHARSET_COMPOSITION)
1549 if (code[1] < 32) code[1] = -1;
1550 else if (code[2] < 32) code[2] = -1;
1552 /* Here, the possible range of CODE[0] (== charset ID) is
1553 128..MAX_CHARSET. Since the top level char table contains data
1554 for multibyte characters after 256th element, we must increment
1555 CODE[0] by 128 to get a correct index. */
1556 code[0] += 128;
1557 code[3] = -1; /* anchor */
1559 for (i = 0; code[i] >= 0; i++, dp = XCHAR_TABLE (val))
1561 val = dp->contents[code[i]];
1562 if (!SUB_CHAR_TABLE_P (val))
1563 return (NILP (val) ? dp->defalt : val);
1565 /* Here, VAL is a sub char table. We return the default value of it. */
1566 return (dp->defalt);
1569 /* Redisplay window WINDOW and its subwindows. */
1571 static void
1572 redisplay_window (window, just_this_one, preserve_echo_area)
1573 Lisp_Object window;
1574 int just_this_one, preserve_echo_area;
1576 register struct window *w = XWINDOW (window);
1577 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1578 int height;
1579 register int lpoint = PT;
1580 struct buffer *old = current_buffer;
1581 register int width = window_internal_width (w) - 1;
1582 register int startp;
1583 register int hscroll = XINT (w->hscroll);
1584 struct position pos;
1585 int opoint = PT;
1586 int tem;
1587 int update_mode_line;
1588 struct Lisp_Char_Table *dp = window_display_table (w);
1590 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1592 /* If this is a combination window, do its children; that's all. */
1594 if (!NILP (w->vchild))
1596 redisplay_windows (w->vchild, preserve_echo_area);
1597 return;
1599 if (!NILP (w->hchild))
1601 redisplay_windows (w->hchild, preserve_echo_area);
1602 return;
1604 if (NILP (w->buffer))
1605 abort ();
1607 height = window_internal_height (w);
1608 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1609 if (XBUFFER (w->buffer)->clip_changed)
1610 update_mode_line = 1;
1612 if (MINI_WINDOW_P (w))
1614 if (w == XWINDOW (echo_area_window) && echo_area_glyphs)
1615 /* We've already displayed the echo area glyphs in this window. */
1616 goto finish_scroll_bars;
1617 else if (w != XWINDOW (minibuf_window))
1619 /* This is a minibuffer, but it's not the currently active one,
1620 so clear it. */
1621 int vpos = XFASTINT (w->top);
1622 int i;
1624 for (i = 0; i < height; i++)
1626 get_display_line (f, vpos + i, 0);
1627 display_string (w, vpos + i, "", 0,
1628 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
1629 0, 1, 0, width);
1632 goto finish_scroll_bars;
1636 /* Otherwise set up data on this window; select its buffer and point value */
1638 if (update_mode_line)
1639 set_buffer_internal_1 (XBUFFER (w->buffer));
1640 else
1641 set_buffer_temp (XBUFFER (w->buffer));
1643 opoint = PT;
1645 /* If %c is in mode line, update it if needed. */
1646 if (!NILP (w->column_number_displayed)
1647 /* This alternative quickly identifies a common case
1648 where no change is needed. */
1649 && !(PT == XFASTINT (w->last_point)
1650 && XFASTINT (w->last_modified) >= MODIFF
1651 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)
1652 && XFASTINT (w->column_number_displayed) != current_column ())
1653 update_mode_line = 1;
1655 /* Count number of windows showing the selected buffer.
1656 An indirect buffer counts as its base buffer. */
1658 if (!just_this_one)
1660 struct buffer *current_base, *window_base;
1661 current_base = current_buffer;
1662 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1663 if (current_base->base_buffer)
1664 current_base = current_base->base_buffer;
1665 if (window_base->base_buffer)
1666 window_base = window_base->base_buffer;
1667 if (current_base == window_base)
1668 buffer_shared++;
1671 /* POINT refers normally to the selected window.
1672 For any other window, set up appropriate value. */
1674 if (!EQ (window, selected_window))
1676 int new_pt = marker_position (w->pointm);
1677 if (new_pt < BEGV)
1679 new_pt = BEGV;
1680 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1682 else if (new_pt > (ZV - 1))
1684 new_pt = ZV;
1685 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1687 /* We don't use SET_PT so that the point-motion hooks don't run. */
1688 BUF_PT (current_buffer) = new_pt;
1691 /* If any of the character widths specified in the display table
1692 have changed, invalidate the width run cache. It's true that this
1693 may be a bit late to catch such changes, but the rest of
1694 redisplay goes (non-fatally) haywire when the display table is
1695 changed, so why should we worry about doing any better? */
1696 if (current_buffer->width_run_cache)
1698 struct Lisp_Char_Table *disptab = buffer_display_table ();
1700 if (! disptab_matches_widthtab (disptab,
1701 XVECTOR (current_buffer->width_table)))
1703 invalidate_region_cache (current_buffer,
1704 current_buffer->width_run_cache,
1705 BEG, Z);
1706 recompute_width_table (current_buffer, disptab);
1710 /* If window-start is screwed up, choose a new one. */
1711 if (XMARKER (w->start)->buffer != current_buffer)
1712 goto recenter;
1714 startp = marker_position (w->start);
1716 /* If someone specified a new starting point but did not insist,
1717 check whether it can be used. */
1718 if (!NILP (w->optional_new_start))
1720 w->optional_new_start = Qnil;
1721 /* Check whether this start pos is usable given where point is. */
1723 pos = *compute_motion (startp, 0,
1724 (((EQ (window, minibuf_window)
1725 && startp == BEG)
1726 ? minibuf_prompt_width : 0)
1727 + (hscroll ? 1 - hscroll : 0)),
1729 PT, height,
1730 /* BUG FIX: See the comment of
1731 Fpos_visible_in_window_p (window.c). */
1732 - (1 << (BITS_PER_SHORT - 1)),
1733 width, hscroll, pos_tab_offset (w, startp), w);
1734 /* If PT does fit on the screen, we will use this start pos,
1735 so do so by setting force_start. */
1736 if (pos.bufpos == PT)
1737 w->force_start = Qt;
1740 /* Handle case where place to start displaying has been specified,
1741 unless the specified location is outside the accessible range. */
1742 if (!NILP (w->force_start))
1744 w->force_start = Qnil;
1745 /* Forget any recorded base line for line number display. */
1746 w->base_line_number = Qnil;
1747 /* Redisplay the mode line. Select the buffer properly for that.
1748 Also, run the hook window-scroll-functions
1749 because we have scrolled. */
1750 /* Note, we do this after clearing force_start because
1751 if there's an error, it is better to forget about force_start
1752 than to get into an infinite loop calling the hook functions
1753 and having them get more errors. */
1754 if (!update_mode_line
1755 || ! NILP (Vwindow_scroll_functions))
1757 Lisp_Object temp[3];
1759 set_buffer_temp (old);
1760 set_buffer_internal_1 (XBUFFER (w->buffer));
1761 update_mode_line = 1;
1762 w->update_mode_line = Qt;
1763 if (! NILP (Vwindow_scroll_functions))
1765 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1766 make_number (startp));
1767 startp = marker_position (w->start);
1770 XSETFASTINT (w->last_modified, 0);
1771 XSETFASTINT (w->last_overlay_modified, 0);
1772 if (startp < BEGV) startp = BEGV;
1773 if (startp > ZV) startp = ZV;
1774 try_window (window, startp);
1775 if (cursor_vpos < 0)
1777 /* If point does not appear, move point so it does appear */
1778 pos = *compute_motion (startp, 0,
1779 (((EQ (window, minibuf_window)
1780 && startp == BEG)
1781 ? minibuf_prompt_width : 0)
1782 + (hscroll ? 1 - hscroll : 0)),
1784 ZV, height / 2,
1785 - (1 << (BITS_PER_SHORT - 1)),
1786 width, hscroll, pos_tab_offset (w, startp), w);
1787 BUF_PT (current_buffer) = pos.bufpos;
1788 if (w != XWINDOW (selected_window))
1789 Fset_marker (w->pointm, make_number (PT), Qnil);
1790 else
1792 if (current_buffer == old)
1793 lpoint = PT;
1794 FRAME_CURSOR_X (f) = (WINDOW_LEFT_MARGIN (w)
1795 + minmax (0, pos.hpos, width));
1796 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1798 /* If we are highlighting the region,
1799 then we just changed the region, so redisplay to show it. */
1800 if (!NILP (Vtransient_mark_mode)
1801 && !NILP (current_buffer->mark_active))
1803 cancel_my_columns (XWINDOW (window));
1804 try_window (window, startp);
1807 goto done;
1810 /* Handle case where text has not changed, only point,
1811 and it has not moved off the frame. */
1813 /* This code is not used for minibuffer for the sake of
1814 the case of redisplaying to replace an echo area message;
1815 since in that case the minibuffer contents per se are usually unchanged.
1816 This code is of no real use in the minibuffer since
1817 the handling of this_line_bufpos, etc.,
1818 in redisplay handles the same cases. */
1820 if (XFASTINT (w->last_modified) >= MODIFF
1821 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF
1822 && PT >= startp && !current_buffer->clip_changed
1823 && (just_this_one || WINDOW_FULL_WIDTH_P (w))
1824 /* If force-mode-line-update was called, really redisplay;
1825 that's how redisplay is forced after e.g. changing
1826 buffer-invisibility-spec. */
1827 && NILP (w->update_mode_line)
1828 /* Can't use this case if highlighting a region. */
1829 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1830 && NILP (w->region_showing)
1831 /* If end pos is out of date, scroll bar and percentage will be wrong */
1832 && INTEGERP (w->window_end_vpos)
1833 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1834 && !EQ (window, minibuf_window))
1836 int this_scroll_margin = scroll_margin;
1837 int last_point_y = w->last_point_y - XINT (w->top);
1838 int last_point_x = (w->last_point_x
1839 + (hscroll ? 1 - hscroll : 0)
1840 - WINDOW_LEFT_MARGIN (w));
1842 /* Find where PT is located now on the frame. */
1843 /* Check just_this_one as a way of verifying that the
1844 window edges have not changed. */
1845 if (PT == w->last_point && just_this_one)
1847 pos.hpos = last_point_x;
1848 pos.vpos = last_point_y;
1849 pos.bufpos = PT;
1851 else if (PT > w->last_point && w->last_point > startp && just_this_one)
1853 pos = *compute_motion (w->last_point, last_point_y, last_point_x, 0,
1854 PT, height,
1855 /* BUG FIX: See the comment of
1856 Fpos_visible_in_window_p (window.c). */
1857 - (1 << (BITS_PER_SHORT - 1)),
1858 width, hscroll,
1859 pos_tab_offset (w, startp), w);
1861 else
1863 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0,
1864 PT, height,
1865 /* BUG FIX: See the comment of
1866 Fpos_visible_in_window_p (window.c). */
1867 - (1 << (BITS_PER_SHORT - 1)),
1868 width, hscroll,
1869 pos_tab_offset (w, startp), w);
1872 /* Don't use a scroll margin that is negative or too large. */
1873 if (this_scroll_margin < 0)
1874 this_scroll_margin = 0;
1876 if (XINT (w->height) < 4 * scroll_margin)
1877 this_scroll_margin = XINT (w->height) / 4;
1879 /* If point fits on the screen, and not within the scroll margin,
1880 we are ok. */
1881 if (pos.vpos < height - this_scroll_margin
1882 && (pos.vpos >= this_scroll_margin || startp == BEGV))
1884 /* Ok, point is still on frame */
1885 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1887 /* These variables are supposed to be origin 1 */
1888 FRAME_CURSOR_X (f) = (WINDOW_LEFT_MARGIN (w)
1889 + minmax (0, pos.hpos, width));
1890 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1892 /* This doesn't do the trick, because if a window to the right of
1893 this one must be redisplayed, this does nothing because there
1894 is nothing in DesiredFrame yet, and then the other window is
1895 redisplayed, making likes that are empty in this window's columns.
1896 if (WINDOW_FULL_WIDTH_P (w))
1897 preserve_my_columns (w);
1899 goto done;
1901 /* Don't bother trying redisplay with same start;
1902 we already know it will lose */
1904 /* If current starting point was originally the beginning of a line
1905 but no longer is, find a new starting point. */
1906 else if (!NILP (w->start_at_line_beg)
1907 && !(startp <= BEGV
1908 || FETCH_BYTE (startp - 1) == '\n'))
1910 goto recenter;
1912 else if (just_this_one && !MINI_WINDOW_P (w)
1913 && PT >= startp
1914 && XFASTINT (w->last_modified)
1915 /* or else vmotion on first line won't work. */
1916 && ! NILP (w->start_at_line_beg)
1917 && ! EQ (w->window_end_valid, Qnil)
1918 && do_id && !current_buffer->clip_changed
1919 && !blank_end_of_window
1920 && WINDOW_FULL_WIDTH_P (w)
1921 /* Can't use this case if highlighting a region. */
1922 && !(!NILP (Vtransient_mark_mode)
1923 && !NILP (current_buffer->mark_active))
1924 /* Don't use try_window_id if newline
1925 doesn't display as the end of a line. */
1926 && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n')))
1927 && NILP (w->region_showing)
1928 && EQ (last_arrow_position, Voverlay_arrow_position)
1929 && EQ (last_arrow_string, Voverlay_arrow_string)
1930 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1931 && tem != -2)
1933 /* tem > 0 means success. tem == -1 means choose new start.
1934 tem == -2 means try again with same start,
1935 and nothing but whitespace follows the changed stuff.
1936 tem == 0 means try again with same start. */
1937 if (tem > 0)
1938 goto done;
1940 else if (startp >= BEGV && startp <= ZV
1941 && (startp < ZV
1942 /* Avoid starting at end of buffer. */
1943 #if 0 /* This change causes trouble for M-! finger & RET.
1944 It will have to be considered later. */
1945 || ! EQ (window, selected_window)
1946 /* Don't do the recentering if redisplay
1947 is not for no user action. */
1948 || preserve_echo_area
1949 #endif
1950 || startp == BEGV
1951 || (XFASTINT (w->last_modified) >= MODIFF
1952 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)))
1954 /* Try to redisplay starting at same place as before */
1955 /* If point has not moved off frame, accept the results */
1956 try_window (window, startp);
1957 if (cursor_vpos >= 0)
1959 if (!just_this_one || current_buffer->clip_changed
1960 || beg_unchanged < startp)
1961 /* Forget any recorded base line for line number display. */
1962 w->base_line_number = Qnil;
1963 goto done;
1965 else
1966 cancel_my_columns (w);
1969 XSETFASTINT (w->last_modified, 0);
1970 XSETFASTINT (w->last_overlay_modified, 0);
1971 /* Redisplay the mode line. Select the buffer properly for that. */
1972 if (!update_mode_line)
1974 set_buffer_temp (old);
1975 set_buffer_internal_1 (XBUFFER (w->buffer));
1976 update_mode_line = 1;
1977 w->update_mode_line = Qt;
1980 /* Try to scroll by specified few lines */
1982 if (scroll_conservatively && !current_buffer->clip_changed
1983 && startp >= BEGV && startp <= ZV)
1985 int this_scroll_margin = scroll_margin;
1987 /* Don't use a scroll margin that is negative or too large. */
1988 if (this_scroll_margin < 0)
1989 this_scroll_margin = 0;
1991 if (XINT (w->height) < 4 * scroll_margin)
1992 this_scroll_margin = XINT (w->height) / 4;
1994 if (PT >= Z - XFASTINT (w->window_end_pos))
1996 struct position pos;
1997 pos = *compute_motion (Z - XFASTINT (w->window_end_pos), 0, 0, 0,
1998 PT, XFASTINT (w->height), 0,
1999 XFASTINT (w->width), XFASTINT (w->hscroll),
2000 pos_tab_offset (w, startp), w);
2001 if (pos.vpos > scroll_conservatively)
2002 goto scroll_fail_1;
2004 pos = *vmotion (startp, pos.vpos + 1 + this_scroll_margin, w);
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 if (PT < startp)
2027 struct position pos;
2028 pos = *compute_motion (PT, 0, 0, 0,
2029 startp, XFASTINT (w->height), 0,
2030 XFASTINT (w->width), XFASTINT (w->hscroll),
2031 pos_tab_offset (w, startp), w);
2032 if (pos.vpos > scroll_conservatively)
2033 goto scroll_fail_1;
2035 pos = *vmotion (startp, - pos.vpos - this_scroll_margin, w);
2037 if (! NILP (Vwindow_scroll_functions))
2039 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
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);
2045 if (cursor_vpos >= 0)
2047 if (!just_this_one || current_buffer->clip_changed
2048 || beg_unchanged < startp)
2049 /* Forget any recorded base line for line number display. */
2050 w->base_line_number = Qnil;
2051 goto done;
2053 else
2054 cancel_my_columns (w);
2056 scroll_fail_1: ;
2059 if (scroll_step && !current_buffer->clip_changed
2060 && startp >= BEGV && startp <= ZV)
2062 if (PT > startp)
2064 pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w);
2065 if (pos.vpos >= height)
2066 goto scroll_fail;
2069 pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w);
2071 if (PT >= pos.bufpos)
2073 if (! NILP (Vwindow_scroll_functions))
2075 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
2076 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2077 make_number (pos.bufpos));
2078 pos.bufpos = marker_position (w->start);
2080 try_window (window, pos.bufpos);
2081 if (cursor_vpos >= 0)
2083 if (!just_this_one || current_buffer->clip_changed
2084 || beg_unchanged < startp)
2085 /* Forget any recorded base line for line number display. */
2086 w->base_line_number = Qnil;
2087 goto done;
2089 else
2090 cancel_my_columns (w);
2092 scroll_fail: ;
2095 /* Finally, just choose place to start which centers point */
2097 recenter:
2098 /* Forget any previously recorded base line for line number display. */
2099 w->base_line_number = Qnil;
2101 pos = *vmotion (PT, - (height / 2), w);
2102 /* Set startp here explicitly in case that helps avoid an infinite loop
2103 in case the window-scroll-functions functions get errors. */
2104 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
2105 if (! NILP (Vwindow_scroll_functions))
2107 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2108 make_number (pos.bufpos));
2109 pos.bufpos = marker_position (w->start);
2111 try_window (window, pos.bufpos);
2113 startp = marker_position (w->start);
2114 w->start_at_line_beg
2115 = (startp == BEGV || FETCH_BYTE (startp - 1) == '\n') ? Qt : Qnil;
2117 done:
2118 if ((update_mode_line
2119 /* If window not full width, must redo its mode line
2120 if the window to its side is being redone */
2121 || (!just_this_one && !WINDOW_FULL_WIDTH_P (w))
2122 || INTEGERP (w->base_line_pos)
2123 || (!NILP (w->column_number_displayed)
2124 && XFASTINT (w->column_number_displayed) != current_column ()))
2125 && height != XFASTINT (w->height))
2126 display_mode_line (w);
2127 if (! line_number_displayed
2128 && ! BUFFERP (w->base_line_pos))
2130 w->base_line_pos = Qnil;
2131 w->base_line_number = Qnil;
2134 /* When we reach a frame's selected window, redo the frame's menu bar. */
2135 if (update_mode_line
2136 && (FRAME_WINDOW_P (f)
2138 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2139 FRAME_EXTERNAL_MENU_BAR (f)
2140 #else
2141 FRAME_MENU_BAR_LINES (f) > 0
2142 #endif
2143 : FRAME_MENU_BAR_LINES (f) > 0)
2144 && EQ (FRAME_SELECTED_WINDOW (f), window))
2145 display_menu_bar (w);
2147 finish_scroll_bars:
2148 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
2150 int start, end, whole;
2152 /* Calculate the start and end positions for the current window.
2153 At some point, it would be nice to choose between scrollbars
2154 which reflect the whole buffer size, with special markers
2155 indicating narrowing, and scrollbars which reflect only the
2156 visible region.
2158 Note that minibuffers sometimes aren't displaying any text. */
2159 if (! MINI_WINDOW_P (w)
2160 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
2162 whole = ZV - BEGV;
2163 start = marker_position (w->start) - BEGV;
2164 /* I don't think this is guaranteed to be right. For the
2165 moment, we'll pretend it is. */
2166 end = (Z - XINT (w->window_end_pos)) - BEGV;
2168 if (end < start) end = start;
2169 if (whole < (end - start)) whole = end - start;
2171 else
2172 start = end = whole = 0;
2174 /* Indicate what this scroll bar ought to be displaying now. */
2175 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
2177 /* Note that we actually used the scroll bar attached to this window,
2178 so it shouldn't be deleted at the end of redisplay. */
2179 (*redeem_scroll_bar_hook) (w);
2182 BUF_PT (current_buffer) = opoint;
2183 if (update_mode_line)
2184 set_buffer_internal_1 (old);
2185 else
2186 set_buffer_temp (old);
2187 BUF_PT (current_buffer) = lpoint;
2190 /* Do full redisplay on one window, starting at position `pos'. */
2192 static void
2193 try_window (window, pos)
2194 Lisp_Object window;
2195 register int pos;
2197 register struct window *w = XWINDOW (window);
2198 register int height = window_internal_height (w);
2199 register int vpos = XFASTINT (w->top);
2200 register int last_text_vpos = vpos;
2201 FRAME_PTR f = XFRAME (w->frame);
2202 int width = window_internal_width (w) - 1;
2203 struct position val;
2205 /* POS should never be out of range! */
2206 if (pos < XBUFFER (w->buffer)->begv
2207 || pos > XBUFFER (w->buffer)->zv)
2208 abort ();
2210 Fset_marker (w->start, make_number (pos), Qnil);
2211 cursor_vpos = -1;
2212 overlay_arrow_seen = 0;
2213 zv_strings_seen = 0;
2214 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2215 val.ovstring_chars_done = 0;
2216 val.tab_offset = pos_tab_offset (w, pos);
2218 while (--height >= 0)
2220 val = *display_text_line (w, pos, vpos, val.hpos, val.tab_offset,
2221 val.ovstring_chars_done);
2222 /* The following code is omitted because we maintain tab_offset
2223 in VAL. */
2224 #if 0
2225 tab_offset += width;
2226 if (val.vpos) tab_offset = 0;
2227 #endif /* 0 */
2228 vpos++;
2229 if (pos != val.bufpos)
2231 int invis = 0;
2232 #ifdef USE_TEXT_PROPERTIES
2233 Lisp_Object invis_prop;
2234 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
2235 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
2236 #endif
2238 last_text_vpos
2239 /* Next line, unless prev line ended in end of buffer with no cr */
2240 = vpos - (val.vpos
2241 && (FETCH_BYTE (val.bufpos - 1) != '\n' || invis));
2243 pos = val.bufpos;
2246 /* If last line is continued in middle of character,
2247 include the split character in the text considered on the frame */
2248 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2249 pos++;
2251 /* If bottom just moved off end of frame, change mode line percentage. */
2252 if (XFASTINT (w->window_end_pos) == 0
2253 && Z != pos)
2254 w->update_mode_line = Qt;
2256 /* Say where last char on frame will be, once redisplay is finished. */
2257 XSETFASTINT (w->window_end_pos, Z - pos);
2258 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
2259 /* But that is not valid info until redisplay finishes. */
2260 w->window_end_valid = Qnil;
2263 /* Try to redisplay when buffer is modified locally,
2264 computing insert/delete line to preserve text outside
2265 the bounds of the changes.
2266 Return 1 if successful, 0 if if cannot tell what to do,
2267 or -1 to tell caller to find a new window start,
2268 or -2 to tell caller to do normal redisplay with same window start. */
2270 static int
2271 try_window_id (window)
2272 Lisp_Object window;
2274 int pos;
2275 register struct window *w = XWINDOW (window);
2276 register int height = window_internal_height (w);
2277 FRAME_PTR f = XFRAME (w->frame);
2278 int top = XFASTINT (w->top);
2279 int start = marker_position (w->start);
2280 int width = window_internal_width (w) - 1;
2281 int hscroll = XINT (w->hscroll);
2282 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
2283 int did_motion;
2284 register int vpos;
2285 register int i, tem;
2286 int last_text_vpos = 0;
2287 int stop_vpos;
2288 int selective = (INTEGERP (current_buffer->selective_display)
2289 ? XINT (current_buffer->selective_display)
2290 : !NILP (current_buffer->selective_display) ? -1 : 0);
2292 struct position val, bp, ep, xp, pp;
2293 int scroll_amount = 0;
2294 int delta;
2295 int epto, old_tick;
2297 if (GPT - BEG < beg_unchanged)
2298 beg_unchanged = GPT - BEG;
2299 if (Z - GPT < end_unchanged)
2300 end_unchanged = Z - GPT;
2302 if (beg_unchanged + BEG < start)
2303 return 0; /* Give up if changes go above top of window */
2305 /* Find position before which nothing is changed. */
2306 bp = *compute_motion (start, 0, lmargin, 0,
2307 min (ZV, beg_unchanged + BEG), height,
2308 /* BUG FIX: See the comment of
2309 Fpos_visible_in_window_p() (window.c). */
2310 - (1 << (BITS_PER_SHORT - 1)),
2311 width, hscroll, pos_tab_offset (w, start), w);
2312 if (bp.vpos >= height)
2314 if (PT < bp.bufpos)
2316 /* All changes are beyond the window end, and point is on the screen.
2317 We don't need to change the text at all.
2318 But we need to update window_end_pos to account for
2319 any change in buffer size. */
2320 bp = *compute_motion (start, 0, lmargin, 0,
2321 ZV, height,
2322 /* BUG FIX: See the comment of
2323 Fpos_visible_in_window_p() (window.c). */
2324 - (1 << (BITS_PER_SHORT - 1)),
2325 width, hscroll, pos_tab_offset (w, start), w);
2326 XSETFASTINT (w->window_end_vpos, height);
2327 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
2328 goto findpoint;
2330 return 0;
2333 vpos = bp.vpos;
2335 /* Find beginning of that frame line. Must display from there. */
2336 bp = *vmotion (bp.bufpos, 0, w);
2338 pos = bp.bufpos;
2339 val.hpos = lmargin;
2340 if (pos < start)
2341 return -1;
2343 did_motion = 0;
2344 /* If about to start displaying at the beginning of a continuation line,
2345 really start with previous frame line, in case it was not
2346 continued when last redisplayed */
2347 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
2349 /* Likewise if we have to worry about selective display. */
2350 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
2352 bp = *vmotion (bp.bufpos, -1, w);
2353 --vpos;
2354 pos = bp.bufpos;
2356 val.tab_offset = bp.tab_offset; /* Update tab offset. */
2358 if (bp.contin && bp.hpos != lmargin)
2360 val.hpos = bp.prevhpos - width + lmargin;
2361 val.tab_offset = bp.tab_offset + bp.prevhpos - width;
2362 did_motion = 1;
2363 DEC_POS (pos);
2366 bp.vpos = vpos;
2368 /* Find first visible newline after which no more is changed. */
2369 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
2370 if (selective > 0)
2371 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
2372 tem = find_next_newline (tem, 1);
2374 /* Compute the cursor position after that newline. */
2375 ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem,
2376 height, - (1 << (BITS_PER_SHORT - 1)),
2377 width, hscroll,
2378 /* We have tab offset in VAL, use it. */
2379 val.tab_offset, w);
2381 /* If changes reach past the text available on the frame,
2382 just display rest of frame. */
2383 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
2384 stop_vpos = height;
2385 else
2386 stop_vpos = ep.vpos;
2388 /* If no newline before ep, the line ep is on includes some changes
2389 that must be displayed. Make sure we don't stop before it. */
2390 /* Also, if changes reach all the way until ep.bufpos,
2391 it is possible that something was deleted after the
2392 newline before it, so the following line must be redrawn. */
2393 if (stop_vpos == ep.vpos
2394 && (ep.bufpos == BEGV
2395 || FETCH_BYTE (ep.bufpos - 1) != '\n'
2396 || ep.bufpos == Z - end_unchanged))
2397 stop_vpos = ep.vpos + 1;
2399 cursor_vpos = -1;
2400 overlay_arrow_seen = 0;
2401 zv_strings_seen = 0;
2403 /* If changes do not reach to bottom of window,
2404 figure out how much to scroll the rest of the window */
2405 if (stop_vpos < height)
2407 /* Now determine how far up or down the rest of the window has moved */
2408 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2409 Z - XFASTINT (w->window_end_pos),
2410 /* Don't care for VPOS... */
2411 1 << (BITS_PER_SHORT - 1),
2412 /* ... nor HPOS. */
2413 1 << (BITS_PER_SHORT - 1),
2414 width, hscroll, ep.tab_offset, w);
2415 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
2417 /* Is everything on frame below the changes whitespace?
2418 If so, no scrolling is really necessary. */
2419 for (i = ep.bufpos; i < xp.bufpos; i++)
2421 tem = FETCH_BYTE (i);
2422 if (tem != ' ' && tem != '\n' && tem != '\t')
2423 break;
2425 if (i == xp.bufpos)
2426 return -2;
2428 XSETFASTINT (w->window_end_vpos,
2429 XFASTINT (w->window_end_vpos) + scroll_amount);
2431 /* Before doing any scrolling, verify that point will be on frame. */
2432 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.vpos < height))
2434 if (PT <= xp.bufpos)
2436 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2437 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2438 width, hscroll,
2439 /* We have tab offset in EP, use it. */
2440 ep.tab_offset, w);
2442 else
2444 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1,
2445 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2446 width, hscroll,
2447 /* We have tab offset in XP, use it. */
2448 xp.tab_offset, w);
2450 if (pp.bufpos < PT || pp.vpos == height)
2451 return 0;
2452 cursor_vpos = pp.vpos + top;
2453 cursor_hpos = WINDOW_LEFT_MARGIN (w) + minmax (0, pp.hpos, width);
2456 if (stop_vpos - scroll_amount >= height
2457 || ep.bufpos == xp.bufpos)
2459 if (scroll_amount < 0)
2460 stop_vpos -= scroll_amount;
2461 scroll_amount = 0;
2462 /* In this path, we have altered window_end_vpos
2463 and not left it negative.
2464 We must make sure that, in case display is preempted
2465 before the frame changes to reflect what we do here,
2466 further updates will not come to try_window_id
2467 and assume the frame and window_end_vpos match. */
2468 blank_end_of_window = 1;
2470 else if (!scroll_amount)
2472 /* Even if we don't need to scroll, we must adjust the
2473 charstarts of subsequent lines (that we won't redisplay)
2474 according to the amount of text inserted or deleted. */
2475 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2476 int adjust = ep.bufpos - oldpos;
2477 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
2479 else if (bp.bufpos == Z - end_unchanged)
2481 /* If reprinting everything is nearly as fast as scrolling,
2482 don't bother scrolling. Can happen if lines are short. */
2483 if (scroll_cost (f, bp.vpos + top - scroll_amount,
2484 top + height - max (0, scroll_amount),
2485 scroll_amount)
2486 > xp.bufpos - bp.bufpos - 20)
2487 /* Return "try normal display with same window-start."
2488 Too bad we can't prevent further scroll-thinking. */
2489 return -2;
2490 /* If pure deletion, scroll up as many lines as possible.
2491 In common case of killing a line, this can save the
2492 following line from being overwritten by scrolling
2493 and therefore having to be redrawn. */
2494 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
2495 top + height - max (0, scroll_amount),
2496 scroll_amount, bp.bufpos);
2497 if (!tem)
2498 stop_vpos = height;
2499 else
2501 /* scroll_frame_lines did not properly adjust subsequent
2502 lines' charstarts in the case where the text of the
2503 screen line at bp.vpos has changed.
2504 (This can happen in a deletion that ends in mid-line.)
2505 To adjust properly, we need to make things consistent
2506 at the position ep.
2507 So do a second adjust to make that happen.
2508 Note that stop_vpos >= ep.vpos, so it is sufficient
2509 to update the charstarts for lines at ep.vpos and below. */
2510 int oldstart
2511 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2512 adjust_window_charstarts (w, ep.vpos + top - 1,
2513 ep.bufpos - oldstart);
2516 else if (scroll_amount)
2518 /* If reprinting everything is nearly as fast as scrolling,
2519 don't bother scrolling. Can happen if lines are short. */
2520 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2521 overestimate of cost of reprinting, since xp.bufpos
2522 would end up below the bottom of the window. */
2523 if (scroll_cost (f, ep.vpos + top - scroll_amount,
2524 top + height - max (0, scroll_amount),
2525 scroll_amount)
2526 > xp.bufpos - ep.bufpos - 20)
2527 /* Return "try normal display with same window-start."
2528 Too bad we can't prevent further scroll-thinking. */
2529 return -2;
2530 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
2531 top + height - max (0, scroll_amount),
2532 scroll_amount, ep.bufpos);
2533 if (!tem) stop_vpos = height;
2537 /* In any case, do not display past bottom of window */
2538 if (stop_vpos >= height)
2540 stop_vpos = height;
2541 scroll_amount = 0;
2544 /* Handle case where pos is before w->start --
2545 can happen if part of line had been clipped and is not clipped now */
2546 if (vpos == 0 && pos < marker_position (w->start))
2547 Fset_marker (w->start, make_number (pos), Qnil);
2549 /* Redisplay the lines where the text was changed */
2550 last_text_vpos = vpos;
2551 /* The following code is omitted because we maintain tab offset in
2552 val.tab_offset. */
2553 #if 0
2554 tab_offset = pos_tab_offset (w, pos);
2555 /* If we are starting display in mid-character, correct tab_offset
2556 to account for passing the line that that character really starts in. */
2557 if (val.hpos < lmargin)
2558 tab_offset += width;
2559 #endif /* 0 */
2560 old_tick = MODIFF;
2561 while (vpos < stop_vpos)
2563 val = *display_text_line (w, pos, top + vpos++, val.hpos, val.tab_offset,
2564 val.ovstring_chars_done);
2565 /* If display_text_line ran a hook and changed some text,
2566 redisplay all the way to bottom of buffer
2567 So that we show the changes. */
2568 if (old_tick != MODIFF)
2569 stop_vpos = height;
2570 /* The following code is omitted because we maintain tab offset
2571 in val.tab_offset. */
2572 #if 0
2573 tab_offset += width;
2574 if (val.vpos) tab_offset = 0;
2575 #endif
2576 if (pos != val.bufpos)
2577 last_text_vpos
2578 /* Next line, unless prev line ended in end of buffer with no cr */
2579 = vpos - (val.vpos && FETCH_BYTE (val.bufpos - 1) != '\n');
2580 pos = val.bufpos;
2583 /* There are two cases:
2584 1) we have displayed down to the bottom of the window
2585 2) we have scrolled lines below stop_vpos by scroll_amount */
2587 if (vpos == height)
2589 /* If last line is continued in middle of character,
2590 include the split character in the text considered on the frame */
2591 if (val.hpos < lmargin)
2592 val.bufpos++;
2593 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2594 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2597 /* If scrolling made blank lines at window bottom,
2598 redisplay to fill those lines */
2599 if (scroll_amount < 0)
2601 /* Don't consider these lines for general-purpose scrolling.
2602 That will save time in the scrolling computation. */
2603 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2604 vpos = xp.vpos;
2605 pos = xp.bufpos;
2606 val.hpos = xp.hpos;
2607 val.tab_offset = xp.tab_offset;
2608 if (pos == ZV)
2609 { /* Display from next line */
2610 vpos = height + scroll_amount;
2611 val.hpos = lmargin;
2612 val.tab_offset = 0;
2614 else if (xp.contin && xp.hpos != lmargin)
2616 val.hpos = xp.prevhpos - width + lmargin;
2617 val.tab_offset = xp.tab_offset + bp.prevhpos - width;
2618 DEC_POS (pos);
2621 blank_end_of_window = 1;
2622 /* The following code is omitted because we maintain tab offset
2623 in val.tab_offset. */
2624 #if 0
2625 tab_offset = pos_tab_offset (w, pos);
2626 /* If we are starting display in mid-character, correct tab_offset
2627 to account for passing the line that that character starts in. */
2628 if (val.hpos < lmargin)
2629 tab_offset += width;
2630 #endif
2631 while (vpos < height)
2633 val = *display_text_line (w, pos, top + vpos++, val.hpos,
2634 val.tab_offset, val.ovstring_chars_done);
2635 /* The following code is omitted because we maintain tab
2636 offset in val.tab_offset. */
2637 #if 0
2638 tab_offset += width;
2639 if (val.vpos) tab_offset = 0;
2640 #endif /* 0 */
2641 pos = val.bufpos;
2644 /* Here is a case where display_text_line sets cursor_vpos wrong.
2645 Make it be fixed up, below. */
2646 if (xp.bufpos == ZV
2647 && xp.bufpos == PT)
2648 cursor_vpos = -1;
2651 /* If bottom just moved off end of frame, change mode line percentage. */
2652 if (XFASTINT (w->window_end_pos) == 0
2653 && Z != val.bufpos)
2654 w->update_mode_line = Qt;
2656 /* Attempt to adjust end-of-text positions to new bottom line */
2657 if (scroll_amount)
2659 delta = height - xp.vpos;
2660 if (delta < 0
2661 || (delta > 0 && xp.bufpos <= ZV)
2662 || (delta == 0 && xp.hpos))
2664 val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w);
2665 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2666 XSETFASTINT (w->window_end_vpos,
2667 XFASTINT (w->window_end_vpos) + val.vpos);
2671 w->window_end_valid = Qnil;
2673 /* If point was not in a line that was displayed, find it */
2674 if (cursor_vpos < 0)
2676 findpoint:
2677 val = *compute_motion (start, 0, lmargin, 0, PT,
2678 /* Don't care for VPOS... */
2679 1 << (BITS_PER_SHORT - 1),
2680 /* ... nor HPOS. */
2681 1 << (BITS_PER_SHORT - 1),
2682 width, hscroll, pos_tab_offset (w, start), w);
2683 /* Admit failure if point is off frame now */
2684 if (val.vpos >= height)
2686 for (vpos = 0; vpos < height; vpos++)
2687 cancel_line (vpos + top, f);
2688 return 0;
2690 cursor_vpos = val.vpos + top;
2691 cursor_hpos = WINDOW_LEFT_MARGIN (w) + minmax (0, val.hpos, width);
2694 FRAME_CURSOR_X (f) = cursor_hpos;
2695 FRAME_CURSOR_Y (f) = cursor_vpos;
2697 if (debug_end_pos)
2699 val = *compute_motion (start, 0, lmargin, 0, ZV,
2700 height, - (1 << (BITS_PER_SHORT - 1)),
2701 width, hscroll, pos_tab_offset (w, start), w);
2702 if (val.vpos != XFASTINT (w->window_end_vpos))
2703 abort ();
2704 if (XFASTINT (w->window_end_pos)
2705 != Z - val.bufpos)
2706 abort ();
2709 return 1;
2712 /* Copy LEN glyphs starting address FROM to the rope TO.
2713 But don't actually copy the parts that would come in before S.
2714 Value is TO, advanced past the copied data.
2715 F is the frame we are displaying in. */
2717 static GLYPH *
2718 copy_part_of_rope (f, to, s, from, len, face)
2719 FRAME_PTR f;
2720 register GLYPH *to; /* Copy to here. */
2721 register GLYPH *s; /* Starting point. */
2722 Lisp_Object *from; /* Data to copy. */
2723 int len;
2724 int face; /* Face to apply to glyphs which don't specify one. */
2726 int n = len;
2727 register Lisp_Object *fp = from;
2728 /* These cache the results of the last call to compute_glyph_face. */
2729 int last_code = -1;
2730 int last_merged = 0;
2732 #ifdef HAVE_FACES
2733 if (! FRAME_TERMCAP_P (f))
2734 while (n--)
2736 GLYPH glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2737 int facecode;
2738 unsigned int c = FAST_GLYPH_CHAR (glyph);
2740 if (c > MAX_CHAR)
2741 /* For an invalid character code, use space. */
2742 c = ' ';
2744 if (FAST_GLYPH_FACE (glyph) == 0)
2745 /* If GLYPH has no face code, use FACE. */
2746 facecode = face;
2747 else if (FAST_GLYPH_FACE (glyph) == last_code)
2748 /* If it's same as previous glyph, use same result. */
2749 facecode = last_merged;
2750 else
2752 /* Merge this glyph's face and remember the result. */
2753 last_code = FAST_GLYPH_FACE (glyph);
2754 last_merged = facecode = compute_glyph_face (f, last_code, face);
2757 if (to >= s)
2758 *to = FAST_MAKE_GLYPH (c, facecode);
2759 ++to;
2760 ++fp;
2762 else
2763 #endif
2764 while (n--)
2766 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2767 ++to;
2768 ++fp;
2770 return to;
2773 /* Correct a glyph by replacing its specified user-level face code
2774 with a displayable computed face code. */
2776 static GLYPH
2777 fix_glyph (f, glyph, cface)
2778 FRAME_PTR f;
2779 GLYPH glyph;
2780 int cface;
2782 #ifdef HAVE_FACES
2783 if (! FRAME_TERMCAP_P (f))
2785 if (FAST_GLYPH_FACE (glyph) != 0)
2786 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2787 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2789 #endif
2790 return glyph;
2793 /* Display one line of window W, starting at position START in W's buffer.
2795 Display starting at horizontal position HPOS, expressed relative to
2796 W's left edge. In situations where the text at START shouldn't
2797 start at the left margin (i.e. when the window is hscrolled, or
2798 we're continuing a line which left off in the midst of a
2799 multi-column character), HPOS should be negative; we throw away
2800 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2801 account.
2803 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2805 OVSTR_DONE is the number of chars of overlay before/after strings
2806 at this position which have already been processed.
2808 Display on position VPOS on the frame. It is origin 0, relative to
2809 the top of the frame, not W.
2811 Returns a STRUCT POSITION giving character to start next line with
2812 and where to display it, including a zero or negative hpos.
2813 The vpos field is not really a vpos; it is 1 unless the line is continued */
2815 struct position val_display_text_line;
2817 static struct position *
2818 display_text_line (w, start, vpos, hpos, taboffset, ovstr_done)
2819 struct window *w;
2820 int start;
2821 int vpos;
2822 int hpos;
2823 int taboffset;
2824 int ovstr_done;
2826 register int pos = start;
2827 register int c;
2828 register GLYPH *p1;
2829 register int pause;
2830 register unsigned char *p;
2831 GLYPH *endp;
2832 register GLYPH *leftmargin;
2833 register GLYPH *p1prev;
2834 register GLYPH *p1start;
2835 int prevpos;
2836 int *charstart;
2837 FRAME_PTR f = XFRAME (w->frame);
2838 int tab_width = XINT (current_buffer->tab_width);
2839 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2840 int width = window_internal_width (w) - 1;
2841 struct position val;
2842 int lastpos;
2843 int invis;
2844 int last_invis_skip = 0;
2845 Lisp_Object last_invis_prop;
2846 int hscroll = XINT (w->hscroll);
2847 int truncate = (hscroll
2848 || (truncate_partial_width_windows
2849 && !WINDOW_FULL_WIDTH_P (w))
2850 || !NILP (current_buffer->truncate_lines));
2852 /* 1 if we should highlight the region. */
2853 int highlight_region
2854 = (!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active)
2855 && (XWINDOW (current_buffer->last_selected_window) == w
2856 || highlight_nonselected_windows));
2857 int region_beg, region_end;
2859 int selective = (INTEGERP (current_buffer->selective_display)
2860 ? XINT (current_buffer->selective_display)
2861 : !NILP (current_buffer->selective_display) ? -1 : 0);
2862 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2863 register struct Lisp_Char_Table *dp = window_display_table (w);
2865 Lisp_Object default_invis_vector[3];
2866 /* Number of characters of ellipsis to display after an invisible line
2867 if it calls for an ellipsis.
2868 Note that this value can be nonzero regardless of whether
2869 selective display is enabled--you must check that separately. */
2870 int selective_rlen
2871 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2872 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2873 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
2874 /* This is the sequence of Lisp objects to display
2875 when there are invisible lines. */
2876 Lisp_Object *invis_vector_contents
2877 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2878 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2879 : default_invis_vector);
2881 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2882 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp)))
2883 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2884 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2885 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp)))
2886 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2888 /* If 1, we must handle multibyte characters. */
2889 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
2890 /* Length of multibyte form of each character. */
2891 int len;
2892 /* Glyphs generated should be set this bit mask if text must be
2893 displayed from right to left. */
2894 GLYPH rev_dir_bit = (NILP (current_buffer->direction_reversed)
2895 ? 0 : GLYPH_MASK_REV_DIR);
2897 /* The next buffer location at which the face should change, due
2898 to overlays or text property changes. */
2899 int next_face_change;
2901 /* The next location where the `invisible' property changes, or an
2902 overlay starts or ends. */
2903 int next_boundary;
2905 /* The face we're currently using. */
2906 int current_face = 0;
2907 int i;
2909 XSETFASTINT (default_invis_vector[2], '.');
2910 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2912 hpos += WINDOW_LEFT_MARGIN (w);
2913 get_display_line (f, vpos, WINDOW_LEFT_MARGIN (w));
2914 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2916 /* Show where to highlight the region. */
2917 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2918 /* Maybe highlight only in selected window. */
2919 && (highlight_nonselected_windows
2920 || w == XWINDOW (selected_window)))
2922 region_beg = marker_position (current_buffer->mark);
2923 if (PT < region_beg)
2925 region_end = region_beg;
2926 region_beg = PT;
2928 else
2929 region_end = PT;
2930 w->region_showing = Qt;
2932 else
2934 region_beg = region_end = -1;
2935 w->region_showing = Qnil;
2938 if (MINI_WINDOW_P (w)
2939 && start == BEG
2940 && vpos == XFASTINT (w->top))
2942 if (! NILP (minibuf_prompt))
2944 int old_width = minibuf_prompt_width;
2946 minibuf_prompt_width
2947 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2948 XSTRING (minibuf_prompt)->size, hpos,
2949 /* Display a space if we truncate. */
2950 ' ',
2951 1, -1,
2952 /* Truncate the prompt a little before the
2953 margin, so user input can at least start
2954 on the first line. */
2955 (XFASTINT (w->width) > 10
2956 ? XFASTINT (w->width) - 4 : -1))
2957 - hpos);
2958 hpos += minibuf_prompt_width;
2959 taboffset -= minibuf_prompt_width - old_width;
2961 else
2962 minibuf_prompt_width = 0;
2965 /* If we're hscrolled at all, use compute_motion to skip over any
2966 text off the left edge of the window. compute_motion may know
2967 tricks to do this faster than we can. */
2968 if (hpos < 0)
2970 struct position *left_edge
2971 = compute_motion (pos, vpos, hpos, 0,
2972 ZV, vpos, 0,
2973 width, hscroll, taboffset, w);
2975 /* Retrieve the buffer position and column provided by
2976 compute_motion. We can't assume that the column will be
2977 zero, because you may have multi-column characters crossing
2978 the left margin.
2980 compute_motion may have moved us past the screen position we
2981 requested, if we hit a multi-column character, or the end of
2982 the line. If so, back up. */
2983 if (left_edge->vpos > vpos
2984 || left_edge->hpos > 0)
2986 pos = left_edge->bufpos;
2987 /* Since this should not be a valid multibyte character, we
2988 can decrease POS by 1. */
2989 pos--;
2990 hpos = left_edge->prevhpos;
2992 else
2994 pos = left_edge->bufpos;
2995 hpos = left_edge->hpos;
2999 desired_glyphs->bufp[vpos] = start;
3000 p1 = desired_glyphs->glyphs[vpos] + hpos;
3001 p1start = p1;
3002 charstart = desired_glyphs->charstarts[vpos] + hpos;
3003 /* In case we don't ever write anything into it... */
3004 desired_glyphs->charstarts[vpos][WINDOW_LEFT_MARGIN (w)] = -1;
3005 leftmargin = desired_glyphs->glyphs[vpos] + WINDOW_LEFT_MARGIN (w);
3006 endp = leftmargin + width;
3008 /* Arrange the overlays nicely for our purposes. Usually, we call
3009 display_text_line on only one line at a time, in which case this
3010 can't really hurt too much, or we call it on lines which appear
3011 one after another in the buffer, in which case all calls to
3012 recenter_overlay_lists but the first will be pretty cheap. */
3013 recenter_overlay_lists (current_buffer, pos);
3015 /* Loop generating characters.
3016 Stop at end of buffer, before newline,
3017 if reach or pass continuation column,
3018 or at face change. */
3019 pause = pos;
3020 next_face_change = pos;
3021 next_boundary = pos;
3022 p1prev = p1;
3023 prevpos = pos;
3025 /* If the window is hscrolled and point is in the invisible part of the
3026 current line beyond the left margin we can record the cursor location
3027 right away. */
3028 if (hscroll && start <= PT && PT < pos && cursor_vpos < 0)
3030 cursor_vpos = vpos;
3031 cursor_hpos = p1 - leftmargin;
3034 while (p1 < endp)
3036 if (pos >= pause)
3038 int e_t_h;
3040 while (pos == next_boundary)
3042 Lisp_Object position, limit, prop, ww;
3044 /* Display the overlay strings here, unless we're at ZV
3045 and have already displayed the appropriate strings
3046 on an earlier line. */
3047 if (pos < ZV || !zv_strings_seen++)
3049 int ovlen;
3050 unsigned char *ovstr;
3051 ovlen = overlay_strings (pos, w, &ovstr);
3053 if (ovlen > 0)
3055 /* Skip the ones we did in a previous line. */
3056 ovstr += ovstr_done;
3057 ovlen -= ovstr_done;
3059 while (ovlen > 0)
3061 int charset, cols;
3062 GLYPH g;
3064 if (multibyte)
3066 c = STRING_CHAR_AND_LENGTH (ovstr, ovlen, len);
3067 ovstr += len, ovlen -= len, ovstr_done += len;
3068 charset = CHAR_CHARSET (c);
3069 cols = (charset == CHARSET_COMPOSITION
3070 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
3071 : CHARSET_WIDTH (charset));
3073 else
3075 c = *ovstr++, ovlen--, ovstr_done++;
3076 cols = 1;
3078 g = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3079 while (cols-- > 0)
3081 if (p1 >= leftmargin && p1 < endp)
3082 *p1 = g, g |= GLYPH_MASK_PADDING;
3083 p1++;
3086 /* If we did all the overlay strings
3087 and we have room for text, clear ovstr_done
3088 just for neatness' sake. */
3089 if (ovlen == 0 && p1 < endp)
3090 ovstr_done = 0;
3094 /* Did we reach point? Record the cursor location. */
3095 if (pos == PT && cursor_vpos < 0)
3097 cursor_vpos = vpos;
3098 cursor_hpos = p1 - leftmargin;
3101 if (pos >= ZV)
3102 break;
3104 XSETFASTINT (position, pos);
3105 limit = Fnext_overlay_change (position);
3106 #ifdef USE_TEXT_PROPERTIES
3107 /* This is just an estimate to give reasonable
3108 performance; nothing should go wrong if it is too small. */
3109 if (XFASTINT (limit) > pos + 50)
3111 int limitpos = pos + 50;
3112 if (limitpos < Z)
3113 INC_POS (limitpos); /* Adjust to character boundary. */
3114 XSETFASTINT (limit, limitpos);
3116 limit = Fnext_single_property_change (position, Qinvisible,
3117 Fcurrent_buffer (), limit);
3118 #endif
3119 next_boundary = XFASTINT (limit);
3120 /* if the `invisible' property is set, we can skip to
3121 the next property change. */
3122 XSETWINDOW (ww, w);
3123 prop = Fget_char_property (position, Qinvisible, ww);
3124 if (TEXT_PROP_MEANS_INVISIBLE (prop))
3126 if (pos < PT && next_boundary >= PT)
3128 cursor_vpos = vpos;
3129 cursor_hpos = p1 - leftmargin;
3131 pos = next_boundary;
3132 last_invis_skip = pos;
3133 last_invis_prop = prop;
3137 /* Did we reach point? Record the cursor location. */
3138 if (pos == PT && cursor_vpos < 0)
3140 cursor_vpos = vpos;
3141 cursor_hpos = p1 - leftmargin;
3144 /* Did we hit the end of the visible region of the buffer?
3145 Stop here. */
3146 if (pos >= ZV)
3148 /* Update charstarts for the end of this line. */
3149 /* Do nothing if off the left edge or at the right edge. */
3150 if (p1 >= leftmargin && p1 + 1 != endp)
3152 int *p2x = &charstart[(p1 < leftmargin
3153 ? leftmargin : p1)
3154 - p1start];
3155 *p2x++ = pos;
3157 break;
3160 /* Figure out where (if at all) the
3161 redisplay_end_trigger-hook should run. */
3162 if (MARKERP (w->redisplay_end_trigger)
3163 && XMARKER (w->redisplay_end_trigger)->buffer != 0)
3164 e_t_h = marker_position (w->redisplay_end_trigger);
3165 else if (INTEGERP (w->redisplay_end_trigger))
3166 e_t_h = XINT (w->redisplay_end_trigger);
3167 else
3168 e_t_h = ZV;
3170 /* If we've gone past the place to run a hook,
3171 run the hook. */
3172 if (pos >= e_t_h && e_t_h != ZV)
3174 Lisp_Object args[3];
3176 args[0] = Qredisplay_end_trigger_functions;
3177 XSETWINDOW (args[1], w);
3178 XSETINT (args[2], e_t_h);
3180 /* Since we are *trying* to run these functions,
3181 don't try to run them again, even if they get an error. */
3182 w->redisplay_end_trigger = Qnil;
3183 Frun_hook_with_args (3, args);
3185 e_t_h = ZV;
3186 /* Notice if it changed the face of this character. */
3187 next_face_change = pos;
3190 #ifdef HAVE_FACES
3191 /* Did we hit a face change? Figure out what face we should
3192 use now. We also hit this the first time through the
3193 loop, to see what face we should start with. */
3194 if (pos >= next_face_change
3195 && (FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f)))
3197 int limit = pos + 50;
3199 if (limit < Z && !CHAR_HEAD_P (POS_ADDR (limit)))
3200 INC_POS (limit); /* Adjust to character boundary. */
3201 current_face = compute_char_face (f, w, pos,
3202 region_beg, region_end,
3203 &next_face_change, limit, 0);
3205 #endif
3207 /* Compute the next place we need to stop
3208 and do something special; set PAUSE. */
3210 pause = ZV;
3212 if (pos < next_boundary && next_boundary < pause)
3213 pause = next_boundary;
3214 if (pos < next_face_change && next_face_change < pause)
3215 pause = next_face_change;
3217 if (e_t_h < pause)
3218 pause = e_t_h;
3220 /* Wouldn't you hate to read the next line to someone over
3221 the phone? */
3222 if (pos < PT && PT < pause)
3223 pause = PT;
3224 if (pos < GPT && GPT < pause)
3225 pause = GPT;
3227 p = POS_ADDR (pos);
3230 if (p1 >= endp)
3231 break;
3233 p1prev = p1;
3235 if (multibyte)
3236 /* PAUSE is surely at character boundary. */
3237 c = STRING_CHAR_AND_LENGTH (p, pause - pos, len), p += len;
3238 else
3239 c = *p++, len = 1;
3240 /* Let a display table override all standard display methods. */
3241 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3243 p1 = copy_part_of_rope (f, p1, leftmargin,
3244 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3245 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3246 current_face, rev_dir_bit);
3248 else if (c >= 040 && c < 0177)
3250 if (p1 >= leftmargin)
3251 *p1 = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3252 p1++;
3254 else if (c == '\n')
3256 #if 0
3257 /* Same as p1prev, but after the invis_vector_contents text
3258 (if we have that on this line). */
3259 GLYPH *p1prev_modified;
3260 #endif
3262 invis = 0;
3263 if (last_invis_skip == pos
3264 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
3265 invis = 1;
3266 while (pos + 1 < ZV
3267 && selective > 0
3268 && indented_beyond_p (pos + 1, selective))
3270 invis = 1;
3271 pos = find_next_newline (pos + 1, 1);
3272 if (FETCH_BYTE (pos - 1) == '\n')
3273 pos--;
3275 if (invis && selective_rlen > 0 && p1 >= leftmargin)
3277 #if 0
3278 GLYPH *cs, *csend;
3280 cs = charstart + (p1 - p1start);
3281 #endif
3283 p1 += selective_rlen;
3284 if (p1 - leftmargin > width)
3285 p1 = endp;
3287 #if 0 /* This needs more work; charstarts needs to record
3288 both whether a position ho;ds an ellipsis character
3289 and what buffer position it corresponds to. */
3290 csend = charstart + (p1 - p1start);
3291 while (cs != csend)
3292 *cs++ = -2;
3293 /* The idea is to use p1prev_modified instead of p1prev
3294 in the loop below over p2x. */
3295 p1prev_modified = p1;
3296 #endif
3298 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
3299 (p1 - p1prev), current_face, rev_dir_bit);
3302 /* Update charstarts for the newline that ended this line. */
3303 /* Do nothing here for a char that's entirely off the left edge
3304 or if it starts at the right edge. */
3305 if (p1 >= leftmargin && p1prev != endp)
3307 /* Store the newline's position into charstarts
3308 for the column where the newline starts.
3309 Store -1 for the rest of the glyphs it occupies. */
3310 int *p2x = &charstart[(p1prev < leftmargin
3311 ? leftmargin : p1prev)
3312 - p1start];
3313 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3315 *p2x++ = pos;
3316 while (p2x < p2)
3317 *p2x++ = -1;
3319 #ifdef HAVE_FACES
3320 /* Draw the face of the newline character as extending all the
3321 way to the end of the frame line. */
3322 if (current_face)
3324 if (p1 < leftmargin)
3325 p1 = leftmargin;
3326 while (p1 < endp)
3327 *p1++ = FAST_MAKE_GLYPH (' ', current_face) | rev_dir_bit;
3329 #endif
3331 break;
3333 else if (c == '\t')
3337 if (p1 >= leftmargin && p1 < endp)
3338 *p1 = MAKE_GLYPH (f, ' ', current_face) | rev_dir_bit;
3339 p1++;
3341 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
3342 % tab_width);
3344 else if (c == Ctl ('M') && selective == -1)
3346 pos = find_next_newline (pos, 1);
3347 if (FETCH_BYTE (pos - 1) == '\n')
3348 pos--;
3349 if (selective_rlen > 0)
3351 p1 += selective_rlen;
3352 if (p1 - leftmargin > width)
3353 p1 = endp;
3354 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
3355 (p1 - p1prev), current_face, rev_dir_bit);
3357 #ifdef HAVE_FACES
3358 /* Draw the face of the newline character as extending all the
3359 way to the end of the frame line. */
3360 if (current_face)
3362 if (p1 < leftmargin)
3363 p1 = leftmargin;
3364 while (p1 < endp)
3365 *p1++ = FAST_MAKE_GLYPH (' ', current_face) | rev_dir_bit;
3367 #endif
3369 /* Update charstarts for the ^M that ended this line. */
3370 /* Do nothing here for a char that's entirely off the left edge
3371 or if it starts at the right edge. */
3372 if (p1 >= leftmargin && p1prev != endp)
3374 /* Store the newline's position into charstarts
3375 for the column where the newline starts.
3376 Store -1 for the rest of the glyphs it occupies. */
3377 int *p2x = &charstart[(p1prev < leftmargin
3378 ? leftmargin : p1prev)
3379 - p1start];
3380 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3382 *p2x++ = pos;
3383 while (p2x < p2)
3384 *p2x++ = -1;
3386 break;
3388 else if (c < 0200 && ctl_arrow)
3390 if (p1 >= leftmargin)
3391 *p1 = (fix_glyph
3392 (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
3393 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp)))
3394 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3395 current_face)
3396 | rev_dir_bit);
3397 p1++;
3398 if (p1 >= leftmargin && p1 < endp)
3399 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face) | rev_dir_bit;
3400 p1++;
3402 else if (len == 1)
3404 /* C is not a multibyte character. */
3405 if (p1 >= leftmargin)
3406 *p1 = (fix_glyph
3407 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
3408 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
3409 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3410 current_face)
3411 | rev_dir_bit);
3412 p1++;
3413 if (p1 >= leftmargin && p1 < endp)
3414 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face) | rev_dir_bit;
3415 p1++;
3416 if (p1 >= leftmargin && p1 < endp)
3417 *p1 = (MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face)
3418 | rev_dir_bit);
3419 p1++;
3420 if (p1 >= leftmargin && p1 < endp)
3421 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face) | rev_dir_bit;
3422 p1++;
3424 else
3426 /* C is a multibyte character. */
3427 int charset = CHAR_CHARSET (c);
3428 int columns = (charset == CHARSET_COMPOSITION
3429 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
3430 : CHARSET_WIDTH (charset));
3431 GLYPH g = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3433 while (columns--)
3435 if (p1 >= leftmargin && p1 < endp)
3436 *p1 = g, g |= GLYPH_MASK_PADDING;
3437 p1++;
3441 prevpos = pos;
3442 pos += len;
3444 /* Update charstarts for the character just output. */
3446 /* Do nothing here for a char that's entirely off the left edge. */
3447 if (p1 >= leftmargin)
3449 /* Store the char's position into charstarts
3450 for the first glyph occupied by this char.
3451 Store -1 for the rest of the glyphs it occupies. */
3452 if (p1 != p1prev)
3454 int *p2x = &charstart[(p1prev < leftmargin
3455 ? leftmargin : p1prev)
3456 - p1start];
3457 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3459 if (p2x < p2)
3460 *p2x++ = prevpos;
3461 while (p2x < p2)
3462 *p2x++ = -1;
3467 val.hpos = - XINT (w->hscroll);
3468 if (val.hpos)
3469 val.hpos++;
3471 val.vpos = 1;
3473 lastpos = pos;
3475 /* Store 0 in this charstart line for the positions where
3476 there is no character. But do leave what was recorded
3477 for the character that ended the line. */
3478 /* Add 1 in the endtest to compensate for the fact that ENDP was
3479 made from WIDTH, which is 1 less than the window's actual
3480 internal width. */
3481 i = p1 - p1start + 1;
3482 if (p1 < leftmargin)
3483 i += leftmargin - p1;
3484 for (; i < endp - p1start + 1; i++)
3485 charstart[i] = 0;
3487 /* Handle continuation in middle of a character */
3488 /* by backing up over it */
3489 if (p1 > endp)
3491 /* Don't back up if we never actually displayed any text.
3492 This occurs when the minibuffer prompt takes up the whole line. */
3493 if (p1prev)
3495 /* Start the next line with that same character whose
3496 character code is C and the length of multi-byte form is
3497 LEN. */
3498 pos = prevpos;
3500 if (len == 1)
3501 /* C is not a multi-byte character. We can break it and
3502 start from the middle column in the next line. So,
3503 adjust VAL.HPOS to skip the columns output on this
3504 line. */
3505 val.hpos += p1prev - endp;
3506 else
3508 /* C is a multibyte character. Since we can't broke it
3509 in the middle, the whole character should be driven
3510 into the next line. */
3511 /* As the result, the actual columns occupied by the
3512 text on this line is less than WIDTH. VAL.TAB_OFFSET
3513 must be adjusted. */
3514 taboffset = taboffset + (p1prev - endp);
3515 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3517 GLYPH g = fix_glyph (f, truncate ? truncator : continuer, 0);
3518 while (p1prev < endp)
3519 *p1prev++ = g;
3521 /* If POINT is at POS, cursor should not on this line. */
3522 lastpos = pos;
3523 if (PT == pos)
3524 cursor_vpos = -1;
3528 /* Keep in this line everything up to the continuation column. */
3529 p1 = endp;
3532 /* Finish deciding which character to start the next line on,
3533 and what hpos to start it at.
3534 Also set `lastpos' to the last position which counts as "on this line"
3535 for cursor-positioning. */
3537 if (pos < ZV)
3539 if (FETCH_BYTE (pos) == '\n')
3541 /* If stopped due to a newline, start next line after it */
3542 pos++;
3543 val.tab_offset = 0;
3544 /* Check again for hidden lines, in case the newline occurred exactly
3545 at the right margin. */
3546 while (pos < ZV && selective > 0
3547 && indented_beyond_p (pos, selective))
3548 pos = find_next_newline (pos, 1);
3550 else
3551 /* Stopped due to right margin of window */
3553 if (truncate)
3555 *p1++ = fix_glyph (f, truncator, 0);
3556 /* Truncating => start next line after next newline,
3557 and point is on this line if it is before the newline,
3558 and skip none of first char of next line */
3560 pos = find_next_newline (pos, 1);
3561 while (pos < ZV && selective > 0
3562 && indented_beyond_p (pos, selective));
3563 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
3565 lastpos = pos - (FETCH_BYTE (pos - 1) == '\n');
3566 val.tab_offset = 0;
3568 else
3570 *p1++ = fix_glyph (f, continuer, 0);
3571 val.vpos = 0;
3572 lastpos--;
3573 val.tab_offset = taboffset + width;
3577 else
3578 val.tab_offset = 0;
3580 /* If point is at eol or in invisible text at eol,
3581 record its frame location now. */
3583 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
3585 cursor_vpos = vpos;
3586 cursor_hpos = p1 - leftmargin;
3589 if (cursor_vpos == vpos)
3591 if (cursor_hpos < 0) cursor_hpos = 0;
3592 if (cursor_hpos > width) cursor_hpos = width;
3593 cursor_hpos += WINDOW_LEFT_MARGIN (w);
3594 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
3596 if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f)
3597 && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window)))
3599 FRAME_CURSOR_Y (f) = cursor_vpos;
3600 FRAME_CURSOR_X (f) = cursor_hpos;
3603 if (w == XWINDOW (selected_window))
3605 /* Line is not continued and did not start
3606 in middle of character */
3607 if ((hpos - WINDOW_LEFT_MARGIN (w)
3608 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
3609 && val.vpos)
3611 this_line_bufpos = start;
3612 this_line_buffer = current_buffer;
3613 this_line_vpos = cursor_vpos;
3614 this_line_start_hpos = hpos - WINDOW_LEFT_MARGIN (w);
3615 this_line_endpos = Z - lastpos;
3617 else
3618 this_line_bufpos = 0;
3623 /* If hscroll and line not empty, insert truncation-at-left marker */
3624 if (hscroll && lastpos != start)
3626 GLYPH g = fix_glyph (f, truncator, 0);
3627 *leftmargin = g;
3628 if (p1 <= leftmargin)
3629 p1 = leftmargin + 1;
3630 else /* MULE: it may be a wide-column character */
3632 p1prev = leftmargin + 1;
3633 while (p1prev < p1 && *p1prev & GLYPH_MASK_PADDING)
3634 *p1prev++ = g;
3638 if (!WINDOW_RIGHTMOST_P (w))
3640 endp++;
3641 if (p1 < leftmargin) p1 = leftmargin;
3642 while (p1 < endp) *p1++ = SPACEGLYPH;
3644 /* Don't draw vertical bars if we're using scroll bars. They're
3645 covered up by the scroll bars, and it's distracting to see
3646 them when the scroll bar windows are flickering around to be
3647 reconfigured. */
3648 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3650 int i;
3651 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3652 *p1++ = SPACEGLYPH;
3654 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3655 *p1++ = (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
3656 ? XINT (DISP_BORDER_GLYPH (dp))
3657 : '|');
3659 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
3660 p1 - desired_glyphs->glyphs[vpos]);
3661 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3663 /* If the start of this line is the overlay arrow-position,
3664 then put the arrow string into the display-line. */
3666 if (MARKERP (Voverlay_arrow_position)
3667 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
3668 && start == marker_position (Voverlay_arrow_position)
3669 && STRINGP (Voverlay_arrow_string)
3670 && ! overlay_arrow_seen)
3672 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
3673 int i;
3674 int len = XSTRING (Voverlay_arrow_string)->size;
3675 int arrow_end;
3677 if (len > width)
3678 len = width;
3679 #ifdef HAVE_FACES
3680 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
3682 /* If the arrow string has text props, obey them when displaying. */
3683 for (i = 0; i < len; i++)
3685 int c = p[i];
3686 Lisp_Object face, ilisp;
3687 int newface;
3689 XSETFASTINT (ilisp, i);
3690 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
3691 newface = compute_glyph_face_1 (f, face, 0);
3692 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
3695 else
3696 #endif /* HAVE_FACES */
3698 for (i = 0; i < len; i++)
3699 leftmargin[i] = p[i];
3702 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3703 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
3704 if (desired_glyphs->used[vpos] < arrow_end)
3705 desired_glyphs->used[vpos] = arrow_end;
3707 overlay_arrow_seen = 1;
3710 val.bufpos = pos;
3711 val.ovstring_chars_done = ovstr_done;
3712 val_display_text_line = val;
3713 return &val_display_text_line;
3716 /* Redisplay the menu bar in the frame for window W. */
3718 static void
3719 display_menu_bar (w)
3720 struct window *w;
3722 Lisp_Object items, tail;
3723 register int vpos = 0;
3724 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3725 int maxendcol = FRAME_WIDTH (f);
3726 int hpos = 0;
3727 int i;
3729 #ifdef HAVE_NTGUI
3730 if (!NILP (Vwindow_system))
3731 return;
3732 #endif
3734 #ifdef USE_X_TOOLKIT
3735 if (FRAME_X_P (f))
3736 return;
3737 #endif /* USE_X_TOOLKIT */
3739 get_display_line (f, vpos, 0);
3741 items = FRAME_MENU_BAR_ITEMS (f);
3742 for (i = 0; i < XVECTOR (items)->size; i += 4)
3744 Lisp_Object pos, string;
3745 string = XVECTOR (items)->contents[i + 1];
3746 if (NILP (string))
3747 break;
3749 XSETFASTINT (XVECTOR (items)->contents[i + 3], hpos);
3751 if (hpos < maxendcol)
3752 hpos = display_string (w, vpos,
3753 XSTRING (string)->data,
3754 XSTRING (string)->size,
3755 hpos, 0, 0, hpos, maxendcol);
3756 /* Put a space between items. */
3757 if (hpos < maxendcol)
3759 int hpos1 = hpos + 1;
3760 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
3761 min (hpos1, maxendcol), maxendcol);
3765 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3766 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3768 /* Fill out the line with spaces. */
3769 if (maxendcol > hpos)
3770 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
3772 /* Clear the rest of the lines allocated to the menu bar. */
3773 vpos++;
3774 while (vpos < FRAME_MENU_BAR_LINES (f))
3775 get_display_line (f, vpos++, 0);
3778 /* Display the mode line for window w */
3780 static void
3781 display_mode_line (w)
3782 struct window *w;
3784 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
3785 register int left = WINDOW_LEFT_MARGIN (w);
3786 register int right = WINDOW_RIGHT_MARGIN (w);
3787 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3789 line_number_displayed = 0;
3790 w->column_number_displayed = Qnil;
3792 get_display_line (f, vpos, left);
3794 /* Temporarily make frame F's kboard the current kboard
3795 so that kboard-local variables in the mode_line_format
3796 will get the right values. */
3797 push_frame_kboard (f);
3799 display_mode_element (w, vpos, left, 0, right, right,
3800 current_buffer->mode_line_format);
3802 pop_frame_kboard ();
3804 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3806 /* Put the mode line in inverse video.
3807 Use faces if possible, since that lets us handle
3808 partial-width windows and avoid inverting the scroll bar columns. */
3809 #ifdef HAVE_FACES
3810 if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video)
3812 /* For a partial width window, explicitly set face of each glyph. */
3813 int i;
3814 unsigned int padding;
3815 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3816 for (i = left; i < right; ++i)
3818 padding = ptr[i] & GLYPH_MASK_PADDING;
3819 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1) | padding;
3822 else
3823 #endif
3825 /* Make the mode line inverse video if the entire line
3826 is made of mode lines.
3827 I.e. if this window is full width,
3828 or if it is the child of a full width window
3829 (which implies that that window is split side-by-side
3830 and the rest of this line is mode lines of the sibling windows). */
3831 if (WINDOW_FULL_WIDTH_P (w)
3832 || WINDOW_FULL_WIDTH_P (XWINDOW (w->parent)))
3833 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3836 /* Contribute ELT to the mode line for window W.
3837 How it translates into text depends on its data type.
3839 VPOS is the position of the mode line being displayed.
3841 HPOS is the position (absolute on frame) where this element's text
3842 should start. The output is truncated automatically at the right
3843 edge of window W.
3845 DEPTH is the depth in recursion. It is used to prevent
3846 infinite recursion here.
3848 MINENDCOL is the hpos before which the element may not end.
3849 The element is padded at the right with spaces if nec
3850 to reach this column.
3852 MAXENDCOL is the hpos past which this element may not extend.
3853 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3854 (This is necessary to make nested padding and truncation work.)
3856 Returns the hpos of the end of the text generated by ELT.
3857 The next element will receive that value as its HPOS arg,
3858 so as to concatenate the elements. */
3860 static int
3861 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3862 struct window *w;
3863 register int vpos, hpos;
3864 int depth;
3865 int minendcol;
3866 register int maxendcol;
3867 register Lisp_Object elt;
3869 tail_recurse:
3870 if (depth > 10)
3871 goto invalid;
3873 depth++;
3875 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3877 case Lisp_String:
3879 /* A string: output it and check for %-constructs within it. */
3880 register unsigned char c;
3881 register unsigned char *this = XSTRING (elt)->data;
3883 while (hpos < maxendcol && *this)
3885 unsigned char *last = this;
3886 while ((c = *this++) != '\0' && c != '%')
3888 if (this - 1 != last)
3890 register int lim = --this - last + hpos;
3891 if (frame_title_ptr)
3892 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3893 else
3894 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3895 hpos, min (lim, maxendcol));
3897 else /* c == '%' */
3899 register int minendcol;
3900 register int spec_width = 0;
3902 /* We can't allow -ve args due to the "%-" construct */
3903 /* Argument specifies minwidth but not maxwidth
3904 (maxwidth can be specified by
3905 (<negative-number> . <stuff>) mode-line elements) */
3907 while ((c = *this++) >= '0' && c <= '9')
3909 spec_width = spec_width * 10 + (c - '0');
3912 minendcol = hpos + spec_width;
3913 if (minendcol > maxendcol)
3915 spec_width = maxendcol - hpos;
3916 minendcol = maxendcol;
3919 if (c == 'M')
3920 hpos = display_mode_element (w, vpos, hpos, depth,
3921 spec_width, maxendcol,
3922 Vglobal_mode_string);
3923 else if (c != 0)
3925 char *spec = decode_mode_spec (w, c, spec_width,
3926 maxendcol - hpos);
3927 if (frame_title_ptr)
3928 hpos = store_frame_title (spec, minendcol, maxendcol);
3929 else
3930 hpos = display_string (w, vpos, spec, -1,
3931 hpos, 0, 1,
3932 minendcol, maxendcol);
3937 break;
3939 case Lisp_Symbol:
3940 /* A symbol: process the value of the symbol recursively
3941 as if it appeared here directly. Avoid error if symbol void.
3942 Special case: if value of symbol is a string, output the string
3943 literally. */
3945 register Lisp_Object tem;
3946 tem = Fboundp (elt);
3947 if (!NILP (tem))
3949 tem = Fsymbol_value (elt);
3950 /* If value is a string, output that string literally:
3951 don't check for % within it. */
3952 if (STRINGP (tem))
3954 if (frame_title_ptr)
3955 hpos = store_frame_title (XSTRING (tem)->data,
3956 minendcol, maxendcol);
3957 else
3958 hpos = display_string (w, vpos, XSTRING (tem)->data,
3959 XSTRING (tem)->size,
3960 hpos, 0, 1, minendcol, maxendcol);
3962 /* Give up right away for nil or t. */
3963 else if (!EQ (tem, elt))
3964 { elt = tem; goto tail_recurse; }
3967 break;
3969 case Lisp_Cons:
3971 register Lisp_Object car, tem;
3973 /* A cons cell: three distinct cases.
3974 If first element is a string or a cons, process all the elements
3975 and effectively concatenate them.
3976 If first element is a negative number, truncate displaying cdr to
3977 at most that many characters. If positive, pad (with spaces)
3978 to at least that many characters.
3979 If first element is a symbol, process the cadr or caddr recursively
3980 according to whether the symbol's value is non-nil or nil. */
3981 car = XCONS (elt)->car;
3982 if (SYMBOLP (car))
3984 tem = Fboundp (car);
3985 elt = XCONS (elt)->cdr;
3986 if (!CONSP (elt))
3987 goto invalid;
3988 /* elt is now the cdr, and we know it is a cons cell.
3989 Use its car if CAR has a non-nil value. */
3990 if (!NILP (tem))
3992 tem = Fsymbol_value (car);
3993 if (!NILP (tem))
3994 { elt = XCONS (elt)->car; goto tail_recurse; }
3996 /* Symbol's value is nil (or symbol is unbound)
3997 Get the cddr of the original list
3998 and if possible find the caddr and use that. */
3999 elt = XCONS (elt)->cdr;
4000 if (NILP (elt))
4001 break;
4002 else if (!CONSP (elt))
4003 goto invalid;
4004 elt = XCONS (elt)->car;
4005 goto tail_recurse;
4007 else if (INTEGERP (car))
4009 register int lim = XINT (car);
4010 elt = XCONS (elt)->cdr;
4011 if (lim < 0)
4012 /* Negative int means reduce maximum width.
4013 DO NOT change MINENDCOL here!
4014 (20 -10 . foo) should truncate foo to 10 col
4015 and then pad to 20. */
4016 maxendcol = min (maxendcol, hpos - lim);
4017 else if (lim > 0)
4019 /* Padding specified. Don't let it be more than
4020 current maximum. */
4021 lim += hpos;
4022 if (lim > maxendcol)
4023 lim = maxendcol;
4024 /* If that's more padding than already wanted, queue it.
4025 But don't reduce padding already specified even if
4026 that is beyond the current truncation point. */
4027 if (lim > minendcol)
4028 minendcol = lim;
4030 goto tail_recurse;
4032 else if (STRINGP (car) || CONSP (car))
4034 register int limit = 50;
4035 /* LIMIT is to protect against circular lists. */
4036 while (CONSP (elt) && --limit > 0
4037 && hpos < maxendcol)
4039 hpos = display_mode_element (w, vpos, hpos, depth,
4040 hpos, maxendcol,
4041 XCONS (elt)->car);
4042 elt = XCONS (elt)->cdr;
4046 break;
4048 default:
4049 invalid:
4050 if (frame_title_ptr)
4051 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
4052 else
4053 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
4054 minendcol, maxendcol);
4055 return hpos;
4058 if (minendcol > hpos)
4059 if (frame_title_ptr)
4060 hpos = store_frame_title ("", minendcol, maxendcol);
4061 else
4062 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
4063 return hpos;
4066 /* Write a null-terminated, right justified decimal representation of
4067 the positive integer D to BUF using a minimal field width WIDTH. */
4069 static void
4070 pint2str (buf, width, d)
4071 register char *buf;
4072 register int width;
4073 register int d;
4075 register char *p = buf;
4077 if (d <= 0)
4078 *p++ = '0';
4079 else
4080 while (d > 0)
4082 *p++ = d % 10 + '0';
4083 d /= 10;
4085 for (width -= (int) (p - buf); width > 0; --width) *p++ = ' ';
4086 *p-- = '\0';
4087 while (p > buf)
4089 d = *buf;
4090 *buf++ = *p;
4091 *p-- = d;
4095 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4096 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4097 type of CODING_SYSTEM. Return updated pointer into BUF. */
4099 static char *
4100 decode_mode_spec_coding (coding_system, buf, eol_flag)
4101 Lisp_Object coding_system;
4102 register char *buf;
4103 int eol_flag;
4105 Lisp_Object val;
4106 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
4108 val = coding_system;
4110 if (NILP (val)) /* Not yet decided. */
4112 if (multibyte)
4113 *buf++ = '-';
4114 if (eol_flag)
4115 *buf++ = eol_mnemonic_undecided;
4116 /* Don't mention EOL conversion if it isn't decided. */
4118 else
4120 Lisp_Object eolvalue;
4122 eolvalue = Fget (coding_system, Qeol_type);
4124 while (!NILP (val) && SYMBOLP (val))
4126 val = Fget (val, Qcoding_system);
4127 if (NILP (eolvalue))
4128 eolvalue = Fget (val, Qeol_type);
4131 if (multibyte)
4132 *buf++ = XFASTINT (XVECTOR (val)->contents[1]);
4134 if (eol_flag)
4136 /* The EOL conversion we are using. */
4137 int eoltype;
4138 /* The EOL conversion that is normal on this system. */
4140 if (NILP (eolvalue)) /* Not yet decided. */
4141 eoltype = eol_mnemonic_undecided;
4142 else if (VECTORP (eolvalue)) /* Not yet decided. */
4143 eoltype = eol_mnemonic_undecided;
4144 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4145 eoltype = (XFASTINT (eolvalue) == 0
4146 ? eol_mnemonic_unix
4147 : (XFASTINT (eolvalue) == 1
4148 ? eol_mnemonic_dos : eol_mnemonic_mac));
4150 /* Mention the EOL conversion if it is not the usual one. */
4151 *buf++ = eoltype;
4154 return buf;
4157 /* Return a string for the output of a mode line %-spec for window W,
4158 generated by character C. SPEC_WIDTH is the field width when
4159 padding to the left (%c, %l). The value returned from this
4160 function will later be truncated to width MAXWIDTH. */
4162 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4164 static char *
4165 decode_mode_spec (w, c, spec_width, maxwidth)
4166 struct window *w;
4167 register char c;
4168 register int spec_width;
4169 register int maxwidth;
4171 Lisp_Object obj;
4172 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4173 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
4174 struct buffer *b = XBUFFER (w->buffer);
4176 obj = Qnil;
4177 if (maxwidth > FRAME_WIDTH (f))
4178 maxwidth = FRAME_WIDTH (f);
4180 switch (c)
4182 case '*':
4183 if (!NILP (b->read_only))
4184 return "%";
4185 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4186 return "*";
4187 return "-";
4189 case '+':
4190 /* This differs from %* only for a modified read-only buffer. */
4191 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4192 return "*";
4193 if (!NILP (b->read_only))
4194 return "%";
4195 return "-";
4197 case '&':
4198 /* This differs from %* in ignoring read-only-ness. */
4199 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4200 return "*";
4201 return "-";
4203 case '%':
4204 return "%";
4206 case '[':
4208 int i;
4209 char *p;
4211 if (command_loop_level > 5)
4212 return "[[[... ";
4213 p = decode_mode_spec_buf;
4214 for (i = 0; i < command_loop_level; i++)
4215 *p++ = '[';
4216 *p = 0;
4217 return decode_mode_spec_buf;
4220 case ']':
4222 int i;
4223 char *p;
4225 if (command_loop_level > 5)
4226 return " ...]]]";
4227 p = decode_mode_spec_buf;
4228 for (i = 0; i < command_loop_level; i++)
4229 *p++ = ']';
4230 *p = 0;
4231 return decode_mode_spec_buf;
4234 case '-':
4236 register char *p;
4237 register int i;
4239 if (maxwidth < sizeof (lots_of_dashes))
4240 return lots_of_dashes;
4241 else
4243 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
4244 *p++ = '-';
4245 *p = '\0';
4247 return decode_mode_spec_buf;
4250 case 'b':
4251 obj = b->name;
4252 #if 0
4253 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
4255 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
4256 decode_mode_spec_buf[maxwidth - 1] = '\\';
4257 decode_mode_spec_buf[maxwidth] = '\0';
4258 return decode_mode_spec_buf;
4260 #endif
4261 break;
4263 case 'c':
4265 int col = current_column ();
4266 XSETFASTINT (w->column_number_displayed, col);
4267 pint2str (decode_mode_spec_buf, spec_width, col);
4268 return decode_mode_spec_buf;
4271 case 'F':
4272 /* %F displays the frame name. */
4273 if (!NILP (f->title))
4274 return (char *) XSTRING (f->title)->data;
4275 if (f->explicit_name || ! FRAME_WINDOW_P (f))
4276 return (char *) XSTRING (f->name)->data;
4277 return "Emacs";
4279 case 'f':
4280 obj = b->filename;
4281 #if 0
4282 if (NILP (obj))
4283 return "[none]";
4284 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
4286 bcopy ("...", decode_mode_spec_buf, 3);
4287 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
4288 decode_mode_spec_buf + 3, maxwidth - 3);
4289 return decode_mode_spec_buf;
4291 #endif
4292 break;
4294 case 'l':
4296 int startpos = marker_position (w->start);
4297 int line, linepos, topline;
4298 int nlines, junk;
4299 Lisp_Object tem;
4300 int height = XFASTINT (w->height);
4302 /* If we decided that this buffer isn't suitable for line numbers,
4303 don't forget that too fast. */
4304 if (EQ (w->base_line_pos, w->buffer))
4305 goto no_value;
4306 /* But do forget it, if the window shows a different buffer now. */
4307 else if (BUFFERP (w->base_line_pos))
4308 w->base_line_pos = Qnil;
4310 /* If the buffer is very big, don't waste time. */
4311 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
4313 w->base_line_pos = Qnil;
4314 w->base_line_number = Qnil;
4315 goto no_value;
4318 if (!NILP (w->base_line_number)
4319 && !NILP (w->base_line_pos)
4320 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
4322 line = XFASTINT (w->base_line_number);
4323 linepos = XFASTINT (w->base_line_pos);
4325 else
4327 line = 1;
4328 linepos = BUF_BEGV (b);
4331 /* Count lines from base line to window start position. */
4332 nlines = display_count_lines (linepos, startpos, startpos, &junk);
4334 topline = nlines + line;
4336 /* Determine a new base line, if the old one is too close
4337 or too far away, or if we did not have one.
4338 "Too close" means it's plausible a scroll-down would
4339 go back past it. */
4340 if (startpos == BUF_BEGV (b))
4342 XSETFASTINT (w->base_line_number, topline);
4343 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
4345 else if (nlines < height + 25 || nlines > height * 3 + 50
4346 || linepos == BUF_BEGV (b))
4348 int limit = BUF_BEGV (b);
4349 int position;
4350 int distance = (height * 2 + 30) * 200;
4352 if (startpos - distance > limit)
4353 limit = startpos - distance;
4355 nlines = display_count_lines (startpos, limit,
4356 -(height * 2 + 30),
4357 &position);
4358 /* If we couldn't find the lines we wanted within
4359 200 chars per line,
4360 give up on line numbers for this window. */
4361 if (position == startpos - distance)
4363 w->base_line_pos = w->buffer;
4364 w->base_line_number = Qnil;
4365 goto no_value;
4368 XSETFASTINT (w->base_line_number, topline - nlines);
4369 XSETFASTINT (w->base_line_pos, position);
4372 /* Now count lines from the start pos to point. */
4373 nlines = display_count_lines (startpos, PT, PT, &junk);
4375 /* Record that we did display the line number. */
4376 line_number_displayed = 1;
4378 /* Make the string to show. */
4379 pint2str (decode_mode_spec_buf, spec_width, topline + nlines);
4380 return decode_mode_spec_buf;
4381 no_value:
4383 char* p = decode_mode_spec_buf;
4384 for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' ';
4385 strcpy (p, "??");
4386 return decode_mode_spec_buf;
4389 break;
4391 case 'm':
4392 obj = b->mode_name;
4393 break;
4395 case 'n':
4396 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
4397 return " Narrow";
4398 break;
4400 case 'p':
4402 int pos = marker_position (w->start);
4403 int total = BUF_ZV (b) - BUF_BEGV (b);
4405 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
4407 if (pos <= BUF_BEGV (b))
4408 return "All";
4409 else
4410 return "Bottom";
4412 else if (pos <= BUF_BEGV (b))
4413 return "Top";
4414 else
4416 if (total > 1000000)
4417 /* Do it differently for a large value, to avoid overflow. */
4418 total = ((pos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
4419 else
4420 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
4421 /* We can't normally display a 3-digit number,
4422 so get us a 2-digit number that is close. */
4423 if (total == 100)
4424 total = 99;
4425 sprintf (decode_mode_spec_buf, "%2d%%", total);
4426 return decode_mode_spec_buf;
4430 /* Display percentage of size above the bottom of the screen. */
4431 case 'P':
4433 int toppos = marker_position (w->start);
4434 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
4435 int total = BUF_ZV (b) - BUF_BEGV (b);
4437 if (botpos >= BUF_ZV (b))
4439 if (toppos <= BUF_BEGV (b))
4440 return "All";
4441 else
4442 return "Bottom";
4444 else
4446 if (total > 1000000)
4447 /* Do it differently for a large value, to avoid overflow. */
4448 total = ((botpos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
4449 else
4450 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
4451 /* We can't normally display a 3-digit number,
4452 so get us a 2-digit number that is close. */
4453 if (total == 100)
4454 total = 99;
4455 if (toppos <= BUF_BEGV (b))
4456 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
4457 else
4458 sprintf (decode_mode_spec_buf, "%2d%%", total);
4459 return decode_mode_spec_buf;
4463 case 's':
4464 /* status of process */
4465 obj = Fget_buffer_process (w->buffer);
4466 if (NILP (obj))
4467 return "no process";
4468 #ifdef subprocesses
4469 obj = Fsymbol_name (Fprocess_status (obj));
4470 #endif
4471 break;
4473 case 't': /* indicate TEXT or BINARY */
4474 #ifdef MODE_LINE_BINARY_TEXT
4475 return MODE_LINE_BINARY_TEXT (b);
4476 #else
4477 return "T";
4478 #endif
4480 case 'z':
4481 /* coding-system (not including end-of-line format) */
4482 case 'Z':
4483 /* coding-system (including end-of-line type) */
4485 int eol_flag = (c == 'Z');
4486 char *p = decode_mode_spec_buf;
4488 if (FRAME_TERMCAP_P (f))
4490 /* No need to mention EOL here--the terminal never needs
4491 to do EOL conversion. */
4492 p = decode_mode_spec_coding (keyboard_coding.symbol, p, 0);
4493 p = decode_mode_spec_coding (terminal_coding.symbol, p, 0);
4495 p = decode_mode_spec_coding (b->buffer_file_coding_system,
4496 p, eol_flag);
4498 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
4499 #ifdef subprocesses
4500 obj = Fget_buffer_process (Fcurrent_buffer ());
4501 if (PROCESSP (obj))
4503 p = decode_mode_spec_coding (XPROCESS (obj)->decode_coding_system,
4504 p, eol_flag);
4505 p = decode_mode_spec_coding (XPROCESS (obj)->encode_coding_system,
4506 p, eol_flag);
4508 #endif /* subprocesses */
4509 #endif /* 0 */
4510 *p = 0;
4511 return decode_mode_spec_buf;
4515 if (STRINGP (obj))
4516 return (char *) XSTRING (obj)->data;
4517 else
4518 return "";
4521 /* Search for COUNT instances of a line boundary, which means either a
4522 newline or (if selective display enabled) a carriage return.
4523 Start at START. If COUNT is negative, search backwards.
4525 If we find COUNT instances, set *SHORTAGE to zero, and return the
4526 position after the COUNTth match. Note that for reverse motion
4527 this is not the same as the usual convention for Emacs motion commands.
4529 If we don't find COUNT instances before reaching the end of the
4530 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
4531 the number of line boundaries left unfound, and return the end of the
4532 buffer we bumped up against. */
4534 static int
4535 display_scan_buffer (start, count, shortage)
4536 int *shortage, start;
4537 register int count;
4539 int limit = ((count > 0) ? ZV - 1 : BEGV);
4540 int direction = ((count > 0) ? 1 : -1);
4542 register unsigned char *cursor;
4543 unsigned char *base;
4545 register int ceiling;
4546 register unsigned char *ceiling_addr;
4548 /* If we are not in selective display mode,
4549 check only for newlines. */
4550 if (! (!NILP (current_buffer->selective_display)
4551 && !INTEGERP (current_buffer->selective_display)))
4552 return scan_buffer ('\n', start, 0, count, shortage, 0);
4554 /* The code that follows is like scan_buffer
4555 but checks for either newline or carriage return. */
4557 if (shortage != 0)
4558 *shortage = 0;
4560 if (count > 0)
4561 while (start != limit + 1)
4563 ceiling = BUFFER_CEILING_OF (start);
4564 ceiling = min (limit, ceiling);
4565 ceiling_addr = POS_ADDR (ceiling) + 1;
4566 base = (cursor = POS_ADDR (start));
4567 while (1)
4569 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
4571 if (cursor != ceiling_addr)
4573 if (--count == 0)
4575 immediate_quit = 0;
4576 return (start + cursor - base + 1);
4578 else
4579 if (++cursor == ceiling_addr)
4580 break;
4582 else
4583 break;
4585 start += cursor - base;
4587 else
4589 start--; /* first character we scan */
4590 while (start > limit - 1)
4591 { /* we WILL scan under start */
4592 ceiling = BUFFER_FLOOR_OF (start);
4593 ceiling = max (limit, ceiling);
4594 ceiling_addr = POS_ADDR (ceiling) - 1;
4595 base = (cursor = POS_ADDR (start));
4596 cursor++;
4597 while (1)
4599 while (--cursor != ceiling_addr
4600 && *cursor != '\n' && *cursor != 015)
4602 if (cursor != ceiling_addr)
4604 if (++count == 0)
4606 immediate_quit = 0;
4607 return (start + cursor - base + 1);
4610 else
4611 break;
4613 start += cursor - base;
4617 if (shortage != 0)
4618 *shortage = count * direction;
4619 return (start + ((direction == 1 ? 0 : 1)));
4622 /* Count up to N lines starting from FROM.
4623 But don't go beyond LIMIT.
4624 Return the number of lines thus found (always positive).
4625 Store the position after what was found into *POS_PTR. */
4627 static int
4628 display_count_lines (from, limit, n, pos_ptr)
4629 int from, limit, n;
4630 int *pos_ptr;
4632 int oldbegv = BEGV;
4633 int oldzv = ZV;
4634 int shortage = 0;
4636 if (limit < from)
4637 BEGV = limit;
4638 else
4639 ZV = limit;
4641 *pos_ptr = display_scan_buffer (from, n, &shortage);
4643 ZV = oldzv;
4644 BEGV = oldbegv;
4646 if (n < 0)
4647 /* When scanning backwards, scan_buffer stops *after* the last newline
4648 it finds, but does count it. Compensate for that. */
4649 return - n - shortage - (*pos_ptr != limit);
4650 return n - shortage;
4653 /* Display STRING on one line of window W, starting at HPOS.
4654 Display at position VPOS. Caller should have done get_display_line.
4655 If VPOS == -1, display it as the current frame's title.
4656 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4658 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4660 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4661 MAXCOL is the last column ok to end at. Truncate here.
4662 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4663 Both count from the left edge of the frame, as does HPOS.
4664 The right edge of W is an implicit maximum.
4665 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4667 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4668 at the place where the current window ends in this line
4669 and not display anything beyond there. Otherwise, only MAXCOL
4670 controls where to stop output.
4672 Returns ending hpos. */
4674 static int
4675 display_string (w, vpos, string, length, hpos, truncate,
4676 obey_window_width, mincol, maxcol)
4677 struct window *w;
4678 unsigned char *string;
4679 int length;
4680 int vpos, hpos;
4681 GLYPH truncate;
4682 int obey_window_width;
4683 int mincol, maxcol;
4685 register int c;
4686 int truncated;
4687 register GLYPH *p1;
4688 int hscroll = XINT (w->hscroll);
4689 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
4690 register GLYPH *start;
4691 register GLYPH *end;
4692 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4693 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
4694 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
4695 int window_width = XFASTINT (w->width);
4696 /* If 1, we must display multibyte characters. */
4697 int multibyte = !NILP (XBUFFER (w->buffer)->enable_multibyte_characters);
4699 /* Use the standard display table, not the window's display table.
4700 We don't want the mode line in rot13. */
4701 register struct Lisp_Char_Table *dp = 0;
4702 int i;
4704 if (DISP_TABLE_P (Vstandard_display_table))
4705 dp = XCHAR_TABLE (Vstandard_display_table);
4707 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
4709 p1 = p1start;
4710 start = desired_glyphs->glyphs[vpos];
4712 if (obey_window_width)
4714 start += XFASTINT (w->left);
4715 end = start + window_width - (truncate != 0);
4717 if (!WINDOW_RIGHTMOST_P (w))
4719 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
4721 int i;
4723 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
4724 *end-- = ' ';
4726 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4727 *end-- = '|';
4731 if (! obey_window_width
4732 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
4733 end = desired_glyphs->glyphs[vpos] + maxcol;
4735 /* Store 0 in charstart for these columns. */
4736 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
4737 desired_glyphs->charstarts[vpos][i] = 0;
4739 if (maxcol >= 0 && mincol > maxcol)
4740 mincol = maxcol;
4742 if (length < 0)
4743 /* We need this value for multibyte characters. */
4744 length = strlen (string);
4746 /* We set truncated to 1 if we get stopped by trying to pass END
4747 (that is, trying to pass MAXCOL.) */
4748 truncated = 0;
4749 while (1)
4751 int len;
4753 if (length <= 0)
4754 break;
4755 if (multibyte)
4756 c = STRING_CHAR_AND_LENGTH (string, length, len);
4757 else
4758 c = *string, len = 1;
4760 string += len, length -= len;
4762 if (p1 >= end)
4764 truncated = 1;
4765 break;
4768 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
4770 p1 = copy_part_of_rope (f, p1, start,
4771 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
4772 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
4775 else if (c >= 040 && c < 0177)
4777 if (p1 >= start)
4778 *p1 = c;
4779 p1++;
4781 else if (c == '\t')
4785 if (p1 >= start && p1 < end)
4786 *p1 = SPACEGLYPH;
4787 p1++;
4789 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
4791 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
4793 if (p1 >= start)
4794 *p1 = (fix_glyph
4795 (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
4796 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp)))
4797 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
4798 0));
4799 p1++;
4800 if (p1 >= start && p1 < end)
4801 *p1 = c ^ 0100;
4802 p1++;
4804 else if (len == 1)
4806 /* C is a control character or a binary byte data. */
4807 if (p1 >= start)
4808 *p1 = (fix_glyph
4809 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
4810 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
4811 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
4812 0));
4813 p1++;
4814 if (p1 >= start && p1 < end)
4815 *p1 = (c >> 6) + '0';
4816 p1++;
4817 if (p1 >= start && p1 < end)
4818 *p1 = (7 & (c >> 3)) + '0';
4819 p1++;
4820 if (p1 >= start && p1 < end)
4821 *p1 = (7 & c) + '0';
4822 p1++;
4824 else
4826 /* C is a multibyte character. */
4827 int charset = CHAR_CHARSET (c);
4828 int columns = (charset == CHARSET_COMPOSITION
4829 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
4830 : CHARSET_WIDTH (charset));
4832 if (p1 < start)
4834 /* Since we can't show the left part of C, fill all
4835 columns with spaces. */
4836 columns -= start - p1;
4837 p1 = start;
4838 while (columns--)
4840 if (p1 < end)
4841 *p1 = SPACEGLYPH;
4842 p1++;
4845 else if (p1 + columns > end)
4847 /* Since we can't show the right part of C, fill all
4848 columns with TRUNCATE if TRUNCATE is specified. */
4849 if (truncate)
4851 while (p1 < end)
4852 *p1++ = fix_glyph (f, truncate, 0);
4853 /* And tell the line is truncated. */
4854 truncated = 1;
4856 break;
4858 else
4860 /* We can show the whole glyph of C. */
4861 *p1++ = c;
4862 while (--columns)
4863 *p1++ = c | GLYPH_MASK_PADDING;
4868 if (truncated)
4870 p1 = end;
4871 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
4873 else if (mincol >= 0)
4875 end = desired_glyphs->glyphs[vpos] + mincol;
4876 while (p1 < end)
4877 *p1++ = SPACEGLYPH;
4881 register int len = p1 - desired_glyphs->glyphs[vpos];
4883 if (len > desired_glyphs->used[vpos])
4884 desired_glyphs->used[vpos] = len;
4885 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
4887 return len;
4891 /* This is like a combination of memq and assq.
4892 Return 1 if PROPVAL appears as an element of LIST
4893 or as the car of an element of LIST.
4894 If PROPVAL is a list, compare each element against LIST
4895 in that way, and return 1 if any element of PROPVAL is found in LIST.
4896 Otherwise return 0.
4897 This function cannot quit. */
4900 invisible_p (propval, list)
4901 register Lisp_Object propval;
4902 Lisp_Object list;
4904 register Lisp_Object tail, proptail;
4905 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4907 register Lisp_Object tem;
4908 tem = XCONS (tail)->car;
4909 if (EQ (propval, tem))
4910 return 1;
4911 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4912 return 1;
4914 if (CONSP (propval))
4915 for (proptail = propval; CONSP (proptail);
4916 proptail = XCONS (proptail)->cdr)
4918 Lisp_Object propelt;
4919 propelt = XCONS (proptail)->car;
4920 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4922 register Lisp_Object tem;
4923 tem = XCONS (tail)->car;
4924 if (EQ (propelt, tem))
4925 return 1;
4926 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4927 return 1;
4930 return 0;
4933 /* Return 1 if PROPVAL appears as the car of an element of LIST
4934 and the cdr of that element is non-nil.
4935 If PROPVAL is a list, check each element of PROPVAL in that way,
4936 and the first time some element is found,
4937 return 1 if the cdr of that element is non-nil.
4938 Otherwise return 0.
4939 This function cannot quit. */
4942 invisible_ellipsis_p (propval, list)
4943 register Lisp_Object propval;
4944 Lisp_Object list;
4946 register Lisp_Object tail, proptail;
4947 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4949 register Lisp_Object tem;
4950 tem = XCONS (tail)->car;
4951 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4952 return ! NILP (XCONS (tem)->cdr);
4954 if (CONSP (propval))
4955 for (proptail = propval; CONSP (proptail);
4956 proptail = XCONS (proptail)->cdr)
4958 Lisp_Object propelt;
4959 propelt = XCONS (proptail)->car;
4960 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4962 register Lisp_Object tem;
4963 tem = XCONS (tail)->car;
4964 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4965 return ! NILP (XCONS (tem)->cdr);
4968 return 0;
4971 void
4972 syms_of_xdisp ()
4974 staticpro (&Qmenu_bar_update_hook);
4975 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
4977 staticpro (&Qoverriding_terminal_local_map);
4978 Qoverriding_terminal_local_map = intern ("overriding-terminal-local-map");
4980 staticpro (&Qoverriding_local_map);
4981 Qoverriding_local_map = intern ("overriding-local-map");
4983 staticpro (&Qwindow_scroll_functions);
4984 Qwindow_scroll_functions = intern ("window-scroll-functions");
4986 staticpro (&Qredisplay_end_trigger_functions);
4987 Qredisplay_end_trigger_functions = intern ("redisplay-end-trigger-functions");
4989 staticpro (&last_arrow_position);
4990 staticpro (&last_arrow_string);
4991 last_arrow_position = Qnil;
4992 last_arrow_string = Qnil;
4994 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
4995 "String (or mode line construct) included (normally) in `mode-line-format'.");
4996 Vglobal_mode_string = Qnil;
4998 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
4999 "Marker for where to display an arrow on top of the buffer text.\n\
5000 This must be the beginning of a line in order to work.\n\
5001 See also `overlay-arrow-string'.");
5002 Voverlay_arrow_position = Qnil;
5004 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
5005 "String to display as an arrow. See also `overlay-arrow-position'.");
5006 Voverlay_arrow_string = Qnil;
5008 DEFVAR_INT ("scroll-step", &scroll_step,
5009 "*The number of lines to try scrolling a window by when point moves out.\n\
5010 If that fails to bring point back on frame, point is centered instead.\n\
5011 If this is zero, point is always centered after it moves off frame.");
5013 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively,
5014 "*Scroll up to this many lines, to bring point back on screen.");
5015 scroll_conservatively = 0;
5017 DEFVAR_INT ("scroll-margin", &scroll_margin,
5018 "*Number of lines of margin at the top and bottom of a window.\n\
5019 Recenter the window whenever point gets within this many lines\n\
5020 of the top or bottom of the window.");
5021 scroll_margin = 0;
5023 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
5025 DEFVAR_BOOL ("truncate-partial-width-windows",
5026 &truncate_partial_width_windows,
5027 "*Non-nil means truncate lines in all windows less than full frame wide.");
5028 truncate_partial_width_windows = 1;
5030 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
5031 "*Non-nil means use inverse video for the mode line.");
5032 mode_line_inverse_video = 1;
5034 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
5035 "*Maximum buffer size for which line number should be displayed.");
5036 line_number_display_limit = 1000000;
5038 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
5039 "*Non-nil means highlight region even in nonselected windows.");
5040 highlight_nonselected_windows = 0;
5042 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
5043 "Non-nil if more than one frame is visible on this display.\n\
5044 Minibuffer-only frames don't count, but iconified frames do.\n\
5045 This variable is not guaranteed to be accurate except while processing\n\
5046 `frame-title-format' and `icon-title-format'.");
5048 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
5049 "Template for displaying the titlebar of visible frames.\n\
5050 \(Assuming the window manager supports this feature.)\n\
5051 This variable has the same structure as `mode-line-format' (which see),\n\
5052 and is used only on frames for which no explicit name has been set\n\
5053 \(see `modify-frame-parameters').");
5054 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
5055 "Template for displaying the titlebar of an iconified frame.\n\
5056 \(Assuming the window manager supports this feature.)\n\
5057 This variable has the same structure as `mode-line-format' (which see),\n\
5058 and is used only on frames for which no explicit name has been set\n\
5059 \(see `modify-frame-parameters').");
5060 Vicon_title_format
5061 = Vframe_title_format
5062 = Fcons (intern ("multiple-frames"),
5063 Fcons (build_string ("%b"),
5064 Fcons (Fcons (build_string (""),
5065 Fcons (intern ("invocation-name"),
5066 Fcons (build_string ("@"),
5067 Fcons (intern ("system-name"),
5068 Qnil)))),
5069 Qnil)));
5071 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
5072 "Maximum number of lines to keep in the message log buffer.\n\
5073 If nil, disable message logging. If t, log messages but don't truncate\n\
5074 the buffer when it becomes large.");
5075 XSETFASTINT (Vmessage_log_max, 50);
5077 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
5078 "Functions called before redisplay, if window sizes have changed.\n\
5079 The value should be a list of functions that take one argument.\n\
5080 Just before redisplay, for each frame, if any of its windows have changed\n\
5081 size since the last redisplay, or have been split or deleted,\n\
5082 all the functions in the list are called, with the frame as argument.");
5083 Vwindow_size_change_functions = Qnil;
5085 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions,
5086 "List of Functions to call before redisplaying a window with scrolling.\n\
5087 Each function is called with two arguments, the window\n\
5088 and its new display-start position. Note that the value of `window-end'\n\
5089 is not valid when these functions are called.");
5090 Vwindow_scroll_functions = Qnil;
5093 /* initialize the window system */
5094 init_xdisp ()
5096 Lisp_Object root_window;
5097 #ifndef COMPILER_REGISTER_BUG
5098 register
5099 #endif /* COMPILER_REGISTER_BUG */
5100 struct window *mini_w;
5102 this_line_bufpos = 0;
5104 mini_w = XWINDOW (minibuf_window);
5105 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
5107 echo_area_glyphs = 0;
5108 previous_echo_glyphs = 0;
5110 if (!noninteractive)
5112 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
5113 XSETFASTINT (XWINDOW (root_window)->top, FRAME_MENU_BAR_LINES (f));
5114 set_window_height (root_window,
5115 FRAME_HEIGHT (f) - 1 - FRAME_MENU_BAR_LINES (f),
5117 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
5118 set_window_height (minibuf_window, 1, 0);
5120 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
5121 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));