Initial revision
[emacs.git] / src / xdisp.c
blobe58a1cdd0693a49fbc268b12433db0d30b8c136b
1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #include <config.h>
22 #include <stdio.h>
23 /*#include <ctype.h>*/
24 #undef NULL
25 #include "lisp.h"
26 #include "frame.h"
27 #include "window.h"
28 #include "termchar.h"
29 #include "dispextern.h"
30 #include "buffer.h"
31 #include "indent.h"
32 #include "commands.h"
33 #include "macros.h"
34 #include "disptab.h"
35 #include "termhooks.h"
36 #include "intervals.h"
38 #ifdef USE_X_TOOLKIT
39 extern void set_frame_menubar ();
40 #endif
42 extern int interrupt_input;
43 extern int command_loop_level;
45 extern Lisp_Object Qface;
47 /* Nonzero means print newline to stdout before next minibuffer message. */
49 int noninteractive_need_newline;
51 /* Nonzero means print newline to message log before next message. */
53 int message_log_need_newline;
55 #define min(a, b) ((a) < (b) ? (a) : (b))
56 #define max(a, b) ((a) > (b) ? (a) : (b))
58 /* The buffer position of the first character appearing
59 entirely or partially on the current frame line.
60 Or zero, which disables the optimization for the current frame line. */
61 static int this_line_bufpos;
63 /* Number of characters past the end of this line,
64 including the terminating newline */
65 static int this_line_endpos;
67 /* The vertical position of this frame line. */
68 static int this_line_vpos;
70 /* Hpos value for start of display on this frame line.
71 Usually zero, but negative if first character really began
72 on previous line */
73 static int this_line_start_hpos;
75 /* Buffer that this_line variables are describing. */
76 static struct buffer *this_line_buffer;
78 /* Set by try_window_id to the vpos of first of any lines
79 scrolled on to the bottom of the frame. These lines should
80 not be included in any general scroll computation. */
81 static int scroll_bottom_vpos;
83 /* Value of echo_area_glyphs when it was last acted on.
84 If this is nonzero, there is a message on the frame
85 in the minibuffer and it should be erased as soon
86 as it is no longer requested to appear. */
87 char *previous_echo_glyphs;
89 /* Nonzero means truncate lines in all windows less wide than the frame */
90 int truncate_partial_width_windows;
92 /* Nonzero means we have more than one non-minibuffer-only frame.
93 Not guaranteed to be accurate except while parsing frame-title-format. */
94 int multiple_frames;
96 Lisp_Object Vglobal_mode_string;
98 /* Marker for where to display an arrow on top of the buffer text. */
99 Lisp_Object Voverlay_arrow_position;
101 /* String to display for the arrow. */
102 Lisp_Object Voverlay_arrow_string;
104 /* Like mode-line-format, but for the titlebar on a visible frame. */
105 Lisp_Object Vframe_title_format;
107 /* Like mode-line-format, but for the titlebar on an iconified frame. */
108 Lisp_Object Vicon_title_format;
110 /* Values of those variables at last redisplay. */
111 static Lisp_Object last_arrow_position, last_arrow_string;
113 Lisp_Object Qmenu_bar_update_hook;
115 /* Nonzero if overlay arrow has been displayed once in this window. */
116 static int overlay_arrow_seen;
118 /* Nonzero means highlight the region even in nonselected windows. */
119 static int highlight_nonselected_windows;
121 /* If cursor motion alone moves point off frame,
122 Try scrolling this many lines up or down if that will bring it back. */
123 int scroll_step;
125 /* Nonzero if try_window_id has made blank lines at window bottom
126 since the last redisplay that paused */
127 static int blank_end_of_window;
129 /* Number of windows showing the buffer of the selected window
130 (or another buffer with the same base buffer).
131 keyboard.c refers to this. */
132 int buffer_shared;
134 /* display_text_line sets these to the frame position (origin 0) of point,
135 whether the window is selected or not.
136 Set one to -1 first to determine whether point was found afterwards. */
138 static int cursor_vpos;
139 static int cursor_hpos;
141 int debug_end_pos;
143 /* Nonzero means display mode line highlighted */
144 int mode_line_inverse_video;
146 static void echo_area_display ();
147 void mark_window_display_accurate ();
148 static void redisplay_windows ();
149 static void redisplay_window ();
150 static void update_menu_bars ();
151 static void update_menu_bar ();
152 static void try_window ();
153 static int try_window_id ();
154 static struct position *display_text_line ();
155 static void display_mode_line ();
156 static int display_mode_element ();
157 static char *fmodetrunc ();
158 static char *decode_mode_spec ();
159 static int display_string ();
160 static void display_menu_bar ();
161 static int display_count_lines ();
163 /* Prompt to display in front of the minibuffer contents */
164 Lisp_Object minibuf_prompt;
166 /* Width in columns of current minibuffer prompt. */
167 int minibuf_prompt_width;
169 /* Message to display instead of minibuffer contents
170 This is what the functions error and message make,
171 and command echoing uses it as well.
172 It overrides the minibuf_prompt as well as the buffer. */
173 char *echo_area_glyphs;
175 /* This is the length of the message in echo_area_glyphs. */
176 int echo_area_glyphs_length;
178 /* true iff we should redraw the mode lines on the next redisplay */
179 int update_mode_lines;
181 /* Smallest number of characters before the gap
182 at any time since last redisplay that finished.
183 Valid for current buffer when try_window_id can be called. */
184 int beg_unchanged;
186 /* Smallest number of characters after the gap
187 at any time since last redisplay that finished.
188 Valid for current buffer when try_window_id can be called. */
189 int end_unchanged;
191 /* MODIFF as of last redisplay that finished;
192 if it matches MODIFF, beg_unchanged and end_unchanged
193 contain no useful information */
194 int unchanged_modified;
196 /* Nonzero if head_clip or tail_clip of current buffer has changed
197 since last redisplay that finished */
198 int clip_changed;
200 /* Nonzero if window sizes or contents have changed
201 since last redisplay that finished */
202 int windows_or_buffers_changed;
204 /* Nonzero after display_mode_line if %l was used
205 and it displayed a line number. */
206 int line_number_displayed;
208 /* Maximum buffer size for which to display line numbers. */
209 int line_number_display_limit;
211 /* Number of lines to keep in the message log buffer.
212 t means infinite. nil means don't log at all. */
213 Lisp_Object Vmessage_log_max;
215 /* Add a string to the message log, optionally terminated with a newline.
216 This function calls low-level routines in order to bypass text property
217 hooks, etc. which might not be safe to run. */
219 void
220 message_dolog (m, len, nlflag)
221 char *m;
222 int len, nlflag;
224 if (!NILP (Vmessage_log_max))
226 struct buffer *oldbuf;
227 int oldpoint, oldbegv, oldzv;
229 oldbuf = current_buffer;
230 Fset_buffer (Fget_buffer_create (build_string (" *Messages*")));
231 oldpoint = PT;
232 oldbegv = BEGV;
233 oldzv = ZV;
234 BEGV = BEG;
235 ZV = Z;
236 if (oldpoint == Z)
237 oldpoint += len + nlflag;
238 if (oldzv == Z)
239 oldzv += len + nlflag;
240 TEMP_SET_PT (Z);
241 if (len)
242 insert_1 (m, len, 1, 0);
243 if (nlflag)
244 insert_1 ("\n", 1, 1, 0);
245 if (NATNUMP (Vmessage_log_max))
247 int pos = scan_buffer ('\n', PT, 0,
248 -XFASTINT (Vmessage_log_max) - 1, 0, 1);
249 oldpoint -= min (pos, oldpoint) - BEG;
250 oldbegv -= min (pos, oldbegv) - BEG;
251 oldzv -= min (pos, oldzv) - BEG;
252 del_range_1 (BEG, pos, 0);
254 BEGV = oldbegv;
255 ZV = oldzv;
256 TEMP_SET_PT (oldpoint);
257 set_buffer_internal (oldbuf);
262 /* Display an echo area message M with a specified length of LEN chars.
263 The string may include null characters. If m is 0, clear out any
264 existing message, and let the minibuffer text show through.
265 Do not pass text that is stored in a Lisp string. */
267 void
268 message2 (m, len)
269 char *m;
270 int len;
272 /* First flush out any partial line written with print. */
273 if (message_log_need_newline)
274 message_dolog ("", 0, 1);
275 message_log_need_newline = 0;
276 if (m)
277 message_dolog (m, len, 1);
278 message2_nolog (m, len);
282 /* The non-logging part of that function. */
284 void
285 message2_nolog (m, len)
286 char *m;
287 int len;
289 if (noninteractive)
291 if (noninteractive_need_newline)
292 putc ('\n', stderr);
293 noninteractive_need_newline = 0;
294 fwrite (m, len, 1, stderr);
295 if (cursor_in_echo_area == 0)
296 fprintf (stderr, "\n");
297 fflush (stderr);
299 /* A null message buffer means that the frame hasn't really been
300 initialized yet. Error messages get reported properly by
301 cmd_error, so this must be just an informative message; toss it. */
302 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
304 #ifdef MULTI_FRAME
305 Lisp_Object minibuf_frame;
307 choose_minibuf_frame ();
308 minibuf_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
309 FRAME_SAMPLE_VISIBILITY (XFRAME (minibuf_frame));
310 if (FRAME_VISIBLE_P (selected_frame)
311 && ! FRAME_VISIBLE_P (XFRAME (minibuf_frame)))
312 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (minibuf_window)));
313 #endif
315 if (m)
317 echo_area_glyphs = m;
318 echo_area_glyphs_length = len;
320 else
321 echo_area_glyphs = previous_echo_glyphs = 0;
323 do_pending_window_change ();
324 echo_area_display ();
325 update_frame (XFRAME (XWINDOW (minibuf_window)->frame), 1, 1);
326 do_pending_window_change ();
327 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
328 (*frame_up_to_date_hook) (XFRAME (XWINDOW (minibuf_window)->frame));
332 void
333 message1 (m)
334 char *m;
336 message2 (m, (m ? strlen (m) : 0));
339 void
340 message1_nolog (m)
341 char *m;
343 message2_nolog (m, (m ? strlen (m) : 0));
346 /* Truncate what will be displayed in the echo area
347 the next time we display it--but don't redisplay it now. */
349 void
350 truncate_echo_area (len)
351 int len;
353 /* A null message buffer means that the frame hasn't really been
354 initialized yet. Error messages get reported properly by
355 cmd_error, so this must be just an informative message; toss it. */
356 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
357 echo_area_glyphs_length = len;
360 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
361 zero if being used by message. */
362 int message_buf_print;
364 /* Dump an informative message to the minibuf. If m is 0, clear out
365 any existing message, and let the minibuffer text show through. */
366 /* VARARGS 1 */
367 void
368 message (m, a1, a2, a3)
369 char *m;
370 EMACS_INT a1, a2, a3;
372 if (noninteractive)
374 if (m)
376 if (noninteractive_need_newline)
377 putc ('\n', stderr);
378 noninteractive_need_newline = 0;
379 fprintf (stderr, m, a1, a2, a3);
380 if (cursor_in_echo_area == 0)
381 fprintf (stderr, "\n");
382 fflush (stderr);
385 else if (INTERACTIVE)
387 /* The frame whose minibuffer we're going to display the message on.
388 It may be larger than the selected frame, so we need
389 to use its buffer, not the selected frame's buffer. */
390 FRAME_PTR echo_frame;
391 #ifdef MULTI_FRAME
392 choose_minibuf_frame ();
393 echo_frame = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
394 #else
395 echo_frame = selected_frame;
396 #endif
398 /* A null message buffer means that the frame hasn't really been
399 initialized yet. Error messages get reported properly by
400 cmd_error, so this must be just an informative message; toss it. */
401 if (FRAME_MESSAGE_BUF (echo_frame))
403 if (m)
405 int len;
406 #ifdef NO_ARG_ARRAY
407 EMACS_INT a[3];
408 a[0] = a1;
409 a[1] = a2;
410 a[2] = a3;
412 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
413 FRAME_WIDTH (echo_frame), m, 0, 3, a);
414 #else
415 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
416 FRAME_WIDTH (echo_frame), m, 0, 3, &a1);
417 #endif /* NO_ARG_ARRAY */
419 message2 (FRAME_MESSAGE_BUF (echo_frame), len);
421 else
422 message1 (0);
424 /* Print should start at the beginning of the message
425 buffer next time. */
426 message_buf_print = 0;
431 void
432 update_echo_area ()
434 message2 (echo_area_glyphs, echo_area_glyphs_length);
437 static void
438 echo_area_display ()
440 register int vpos;
441 FRAME_PTR f;
443 #ifdef MULTI_FRAME
444 choose_minibuf_frame ();
445 #endif
447 f = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
449 if (! FRAME_VISIBLE_P (f))
450 return;
452 if (frame_garbaged)
454 redraw_garbaged_frames ();
455 frame_garbaged = 0;
458 if (echo_area_glyphs || minibuf_level == 0)
460 vpos = XFASTINT (XWINDOW (minibuf_window)->top);
461 get_display_line (f, vpos, 0);
462 display_string (XWINDOW (minibuf_window), vpos,
463 echo_area_glyphs ? echo_area_glyphs : "",
464 echo_area_glyphs ? echo_area_glyphs_length : -1,
465 0, 0, 0, 0, FRAME_WIDTH (f));
467 /* If desired cursor location is on this line, put it at end of text */
468 if (FRAME_CURSOR_Y (f) == vpos)
469 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
471 /* Fill the rest of the minibuffer window with blank lines. */
473 int i;
475 for (i = vpos + 1;
476 i < vpos + XFASTINT (XWINDOW (minibuf_window)->height); i++)
478 get_display_line (f, i, 0);
479 display_string (XWINDOW (minibuf_window), vpos,
480 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f));
484 else if (!EQ (minibuf_window, selected_window))
485 windows_or_buffers_changed++;
487 if (EQ (minibuf_window, selected_window))
488 this_line_bufpos = 0;
490 previous_echo_glyphs = echo_area_glyphs;
493 #ifdef HAVE_X_WINDOWS
494 static char frame_title_buf[512];
495 static char *frame_title_ptr;
497 static int
498 store_frame_title (str, mincol, maxcol)
499 char *str;
500 int mincol, maxcol;
502 char *limit;
503 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
504 maxcol = sizeof (frame_title_buf);
505 limit = &frame_title_buf[maxcol];
506 while (*str != '\0' && frame_title_ptr < limit)
507 *frame_title_ptr++ = *str++;
508 while (frame_title_ptr < &frame_title_buf[mincol])
509 *frame_title_ptr++ = ' ';
510 return frame_title_ptr - frame_title_buf;
513 static void
514 x_consider_frame_title (frame)
515 Lisp_Object frame;
517 Lisp_Object fmt;
518 struct buffer *obuf;
519 int len;
520 FRAME_PTR f = XFRAME (frame);
522 if (!FRAME_X_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name)
523 return;
524 multiple_frames = !EQ (Fnext_frame (frame, Qnil), frame);
525 obuf = current_buffer;
526 Fset_buffer (XWINDOW (f->selected_window)->buffer);
527 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
528 frame_title_ptr = frame_title_buf;
529 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
530 0, sizeof (frame_title_buf), fmt);
531 frame_title_ptr = 0;
532 set_buffer_internal (obuf);
533 /* Set the name only if it's changed. This avoids consing
534 in the common case where it hasn't. (If it turns out that we've
535 already wasted too much time by walking through the list with
536 display_mode_element, then we might need to optimize at a higher
537 level than this.) */
538 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
539 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
540 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
542 #else
543 #define frame_title_ptr ((char *)0)
544 #define store_frame_title(str, mincol, maxcol) 0
545 #endif
547 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
548 This can't be done in `redisplay' itself because it can call eval. */
550 void
551 prepare_menu_bars ()
553 register struct window *w = XWINDOW (selected_window);
554 int all_windows;
556 if (noninteractive)
557 return;
559 /* Set the visible flags for all frames.
560 Do this before checking for resized or garbaged frames; they want
561 to know if their frames are visible.
562 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
564 Lisp_Object tail, frame;
566 FOR_EACH_FRAME (tail, frame)
567 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
570 /* Notice any pending interrupt request to change frame size. */
571 do_pending_window_change ();
573 if (frame_garbaged)
575 redraw_garbaged_frames ();
576 frame_garbaged = 0;
579 all_windows = (update_mode_lines || buffer_shared > 1
580 || clip_changed || windows_or_buffers_changed);
582 #ifdef HAVE_X_WINDOWS
583 if (windows_or_buffers_changed)
585 Lisp_Object tail, frame;
587 FOR_EACH_FRAME (tail, frame)
588 if (FRAME_VISIBLE_P (XFRAME (frame))
589 || FRAME_ICONIFIED_P (XFRAME (frame)))
590 x_consider_frame_title (frame);
592 #endif
594 /* Update the menu bar item lists, if appropriate.
595 This has to be done before any actual redisplay
596 or generation of display lines. */
597 if (all_windows)
599 Lisp_Object tail, frame;
601 FOR_EACH_FRAME (tail, frame)
602 update_menu_bar (XFRAME (frame));
604 else
605 update_menu_bar (selected_frame);
608 /* Do a frame update, taking possible shortcuts into account.
609 This is the main external entry point for redisplay.
611 If the last redisplay displayed an echo area message and that
612 message is no longer requested, we clear the echo area
613 or bring back the minibuffer if that is in use.
615 Do not call eval from within this function.
616 Calls to eval after the call to echo_area_display would confuse
617 the display_line mechanism and would cause a crash.
618 Calls to eval before that point will work most of the time,
619 but can still lose, because this function
620 can be called from signal handlers; with alarms set up;
621 or with synchronous processes running.
623 See Fcall_process; if you called it from here, it could be
624 entered recursively. */
626 static int do_verify_charstarts;
628 /* Counter is used to clear the face cache
629 no more than once ever 1000 redisplays. */
630 static int clear_face_cache_count;
632 void
633 redisplay ()
635 register struct window *w = XWINDOW (selected_window);
636 register int pause;
637 int must_finish = 0;
638 int all_windows;
639 register int tlbufpos, tlendpos;
640 struct position pos;
641 extern int input_pending;
643 if (noninteractive)
644 return;
646 /* Set the visible flags for all frames.
647 Do this before checking for resized or garbaged frames; they want
648 to know if their frames are visible.
649 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
651 Lisp_Object tail, frame;
653 FOR_EACH_FRAME (tail, frame)
654 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
657 /* Notice any pending interrupt request to change frame size. */
658 do_pending_window_change ();
660 if (frame_garbaged)
662 redraw_garbaged_frames ();
663 frame_garbaged = 0;
666 if (clip_changed || windows_or_buffers_changed
667 || (!NILP (w->column_number_displayed)
668 && XFASTINT (w->column_number_displayed) != current_column ()))
669 update_mode_lines++;
671 /* Detect case that we need to write a star in the mode line. */
672 if (XFASTINT (w->last_modified) < MODIFF
673 && XFASTINT (w->last_modified) <= SAVE_MODIFF)
675 w->update_mode_line = Qt;
676 if (buffer_shared > 1)
677 update_mode_lines++;
680 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
682 all_windows = update_mode_lines || buffer_shared > 1;
684 /* If specs for an arrow have changed, do thorough redisplay
685 to ensure we remove any arrow that should no longer exist. */
686 if (! EQ (Voverlay_arrow_position, last_arrow_position)
687 || ! EQ (Voverlay_arrow_string, last_arrow_string))
688 all_windows = 1, clip_changed = 1;
690 /* Normally the message* functions will have already displayed and
691 updated the echo area, but the frame may have been trashed, or
692 the update may have been preempted, so display the echo area
693 again here. */
694 if (echo_area_glyphs || previous_echo_glyphs)
696 echo_area_display ();
697 must_finish = 1;
700 /* If showing region, and mark has changed, must redisplay whole window. */
701 if (((!NILP (Vtransient_mark_mode)
702 && !NILP (XBUFFER (w->buffer)->mark_active))
703 != !NILP (w->region_showing))
704 || (!NILP (w->region_showing)
705 && !EQ (w->region_showing,
706 Fmarker_position (XBUFFER (w->buffer)->mark))))
707 this_line_bufpos = -1;
709 tlbufpos = this_line_bufpos;
710 tlendpos = this_line_endpos;
711 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
712 && FRAME_VISIBLE_P (XFRAME (w->frame))
713 /* Make sure recorded data applies to current buffer, etc */
714 && this_line_buffer == current_buffer
715 && current_buffer == XBUFFER (w->buffer)
716 && NILP (w->force_start)
717 /* Point must be on the line that we have info recorded about */
718 && PT >= tlbufpos
719 && PT <= Z - tlendpos
720 /* All text outside that line, including its final newline,
721 must be unchanged */
722 && (XFASTINT (w->last_modified) >= MODIFF
723 || (beg_unchanged >= tlbufpos - 1
724 && GPT >= tlbufpos
725 /* If selective display, can't optimize
726 if the changes start at the beginning of the line. */
727 && ((INTEGERP (current_buffer->selective_display)
728 && XINT (current_buffer->selective_display) > 0
729 ? (beg_unchanged >= tlbufpos
730 && GPT > tlbufpos)
731 : 1))
732 && end_unchanged >= tlendpos
733 && Z - GPT >= tlendpos)))
735 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
736 && (tlbufpos == ZV
737 || FETCH_CHAR (tlbufpos) == '\n'))
738 /* Former continuation line has disappeared by becoming empty */
739 goto cancel;
740 else if (XFASTINT (w->last_modified) < MODIFF
741 || MINI_WINDOW_P (w))
743 cursor_vpos = -1;
744 overlay_arrow_seen = 0;
745 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
746 pos_tab_offset (w, tlbufpos));
747 /* If line contains point, is not continued,
748 and ends at same distance from eob as before, we win */
749 if (cursor_vpos >= 0 && this_line_bufpos
750 && this_line_endpos == tlendpos)
752 /* If this is not the window's last line,
753 we must adjust the charstarts of the lines below. */
754 if (this_line_vpos + 1
755 < XFASTINT (w->top) + window_internal_height (w))
757 int left = XFASTINT (w->left);
758 int *charstart_next_line
759 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
760 int i;
761 int adjust;
763 if (Z - tlendpos == ZV)
764 /* This line ends at end of (accessible part of) buffer.
765 There is no newline to count. */
766 adjust = Z - tlendpos - charstart_next_line[left];
767 else
768 /* This line ends in a newline.
769 Must take account of the newline and the rest of the
770 text that follows. */
771 adjust = Z - tlendpos + 1 - charstart_next_line[left];
773 adjust_window_charstarts (w, this_line_vpos, adjust);
776 if (XFASTINT (w->width) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w))))
777 preserve_other_columns (w);
778 goto update;
780 else
781 goto cancel;
783 else if (PT == XFASTINT (w->last_point))
785 if (!must_finish)
787 do_pending_window_change ();
788 return;
790 goto update;
792 /* If highlighting the region, we can't just move the cursor. */
793 else if (! (!NILP (Vtransient_mark_mode)
794 && !NILP (current_buffer->mark_active))
795 && NILP (w->region_showing))
797 pos = *compute_motion (tlbufpos, 0,
798 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
799 PT, 2, - (1 << (SHORTBITS - 1)),
800 window_internal_width (w) - 1,
801 XINT (w->hscroll),
802 pos_tab_offset (w, tlbufpos), w);
803 if (pos.vpos < 1)
805 FRAME_CURSOR_X (selected_frame)
806 = XFASTINT (w->left) + max (pos.hpos, 0);
807 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
808 goto update;
810 else
811 goto cancel;
813 cancel:
814 /* Text changed drastically or point moved off of line */
815 cancel_line (this_line_vpos, selected_frame);
818 this_line_bufpos = 0;
819 all_windows |= buffer_shared > 1;
821 clear_face_cache_count++;
823 if (all_windows)
825 Lisp_Object tail, frame;
827 #ifdef HAVE_FACES
828 /* Clear the face cache, only when we do a full redisplay
829 and not too often either. */
830 if (clear_face_cache_count > 1000)
832 clear_face_cache ();
833 clear_face_cache_count = 0;
835 #endif
837 /* Recompute # windows showing selected buffer.
838 This will be incremented each time such a window is displayed. */
839 buffer_shared = 0;
841 FOR_EACH_FRAME (tail, frame)
843 FRAME_PTR f = XFRAME (frame);
845 /* Mark all the scroll bars to be removed; we'll redeem the ones
846 we want when we redisplay their windows. */
847 if (condemn_scroll_bars_hook)
848 (*condemn_scroll_bars_hook) (f);
850 if (FRAME_VISIBLE_P (f))
851 redisplay_windows (FRAME_ROOT_WINDOW (f));
853 /* Any scroll bars which redisplay_windows should have nuked
854 should now go away. */
855 if (judge_scroll_bars_hook)
856 (*judge_scroll_bars_hook) (f);
859 else if (FRAME_VISIBLE_P (selected_frame))
861 redisplay_window (selected_window, 1);
862 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
863 preserve_other_columns (w);
866 update:
867 /* Prevent various kinds of signals during display update.
868 stdio is not robust about handling signals,
869 which can cause an apparent I/O error. */
870 if (interrupt_input)
871 unrequest_sigio ();
872 stop_polling ();
874 #ifdef MULTI_FRAME
875 if (all_windows)
877 Lisp_Object tail;
879 pause = 0;
881 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
883 FRAME_PTR f;
885 if (!FRAMEP (XCONS (tail)->car))
886 continue;
888 f = XFRAME (XCONS (tail)->car);
889 if (FRAME_VISIBLE_P (f))
891 pause |= update_frame (f, 0, 0);
892 if (!pause)
894 mark_window_display_accurate (f->root_window, 1);
895 if (frame_up_to_date_hook != 0)
896 (*frame_up_to_date_hook) (f);
901 else
902 #endif /* MULTI_FRAME */
904 if (FRAME_VISIBLE_P (selected_frame))
905 pause = update_frame (selected_frame, 0, 0);
907 /* We may have called echo_area_display at the top of this
908 function. If the echo area is on another frame, that may
909 have put text on a frame other than the selected one, so the
910 above call to update_frame would not have caught it. Catch
911 it here. */
913 FRAME_PTR mini_frame
914 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
916 if (mini_frame != selected_frame)
917 pause |= update_frame (mini_frame, 0, 0);
921 /* If frame does not match, prevent doing single-line-update next time.
922 Also, don't forget to check every line to update the arrow. */
923 if (pause)
925 this_line_bufpos = 0;
926 if (!NILP (last_arrow_position))
928 last_arrow_position = Qt;
929 last_arrow_string = Qt;
931 /* If we pause after scrolling, some lines in current_frame
932 may be null, so preserve_other_columns won't be able to
933 preserve all the vertical-bar separators. So, avoid using it
934 in that case. */
935 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
936 update_mode_lines = 1;
939 /* Now text on frame agrees with windows, so
940 put info into the windows for partial redisplay to follow */
942 if (!pause)
944 register struct buffer *b = XBUFFER (w->buffer);
946 blank_end_of_window = 0;
947 clip_changed = 0;
948 unchanged_modified = BUF_MODIFF (b);
949 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
950 end_unchanged = BUF_Z (b) - BUF_GPT (b);
952 XSETFASTINT (w->last_point, BUF_PT (b));
953 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
954 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
956 if (all_windows)
957 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
958 else
960 w->update_mode_line = Qnil;
961 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
962 w->window_end_valid = w->buffer;
963 last_arrow_position = Voverlay_arrow_position;
964 last_arrow_string = Voverlay_arrow_string;
965 if (do_verify_charstarts)
966 verify_charstarts (w);
967 if (frame_up_to_date_hook != 0)
968 (*frame_up_to_date_hook) (selected_frame);
970 update_mode_lines = 0;
971 windows_or_buffers_changed = 0;
974 /* Start SIGIO interrupts coming again.
975 Having them off during the code above
976 makes it less likely one will discard output,
977 but not impossible, since there might be stuff
978 in the system buffer here.
979 But it is much hairier to try to do anything about that. */
981 if (interrupt_input)
982 request_sigio ();
983 start_polling ();
985 /* Change frame size now if a change is pending. */
986 do_pending_window_change ();
988 /* If we just did a pending size change, redisplay again
989 for the new size. */
990 if (windows_or_buffers_changed && !pause)
991 redisplay ();
994 /* Redisplay, but leave alone any recent echo area message
995 unless another message has been requested in its place.
997 This is useful in situations where you need to redisplay but no
998 user action has occurred, making it inappropriate for the message
999 area to be cleared. See tracking_off and
1000 wait_reading_process_input for examples of these situations. */
1002 redisplay_preserve_echo_area ()
1004 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1006 echo_area_glyphs = previous_echo_glyphs;
1007 redisplay ();
1008 echo_area_glyphs = 0;
1010 else
1011 redisplay ();
1014 void
1015 mark_window_display_accurate (window, flag)
1016 Lisp_Object window;
1017 int flag;
1019 register struct window *w;
1021 for (;!NILP (window); window = w->next)
1023 if (!WINDOWP (window)) abort ();
1024 w = XWINDOW (window);
1026 if (!NILP (w->buffer))
1028 XSETFASTINT (w->last_modified,
1029 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1031 /* Record if we are showing a region, so can make sure to
1032 update it fully at next redisplay. */
1033 w->region_showing = (!NILP (Vtransient_mark_mode)
1034 && !NILP (XBUFFER (w->buffer)->mark_active)
1035 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1036 : Qnil);
1039 w->window_end_valid = w->buffer;
1040 w->update_mode_line = Qnil;
1042 if (!NILP (w->vchild))
1043 mark_window_display_accurate (w->vchild, flag);
1044 if (!NILP (w->hchild))
1045 mark_window_display_accurate (w->hchild, flag);
1048 if (flag)
1050 last_arrow_position = Voverlay_arrow_position;
1051 last_arrow_string = Voverlay_arrow_string;
1053 else
1055 /* t is unequal to any useful value of Voverlay_arrow_... */
1056 last_arrow_position = Qt;
1057 last_arrow_string = Qt;
1061 /* Update the menu bar item list for frame F.
1062 This has to be done before we start to fill in any display lines,
1063 because it can call eval. */
1065 static void
1066 update_menu_bar (f)
1067 FRAME_PTR f;
1069 struct buffer *old = current_buffer;
1070 Lisp_Object window;
1071 register struct window *w;
1072 window = FRAME_SELECTED_WINDOW (f);
1073 w = XWINDOW (window);
1075 if (update_mode_lines)
1076 w->update_mode_line = Qt;
1078 if (
1079 #ifdef USE_X_TOOLKIT
1080 FRAME_EXTERNAL_MENU_BAR (f)
1081 #else
1082 FRAME_MENU_BAR_LINES (f) > 0
1083 #endif
1086 /* If the user has switched buffers or windows, we need to
1087 recompute to reflect the new bindings. But we'll
1088 recompute when update_mode_lines is set too; that means
1089 that people can use force-mode-line-update to request
1090 that the menu bar be recomputed. The adverse effect on
1091 the rest of the redisplay algorithm is about the same as
1092 windows_or_buffers_changed anyway. */
1093 if (windows_or_buffers_changed
1094 || !NILP (w->update_mode_line)
1095 || (XFASTINT (w->last_modified) < MODIFF
1096 && (XFASTINT (w->last_modified)
1097 <= BUF_SAVE_MODIFF (XBUFFER (w->buffer)))))
1099 struct buffer *prev = current_buffer;
1100 call1 (Vrun_hooks, Qmenu_bar_update_hook);
1101 current_buffer = XBUFFER (w->buffer);
1102 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1103 current_buffer = prev;
1104 #ifdef USE_X_TOOLKIT
1105 set_frame_menubar (f, 0);
1106 #endif /* USE_X_TOOLKIT */
1111 int do_id = 1;
1113 /* Redisplay WINDOW and its subwindows and siblings. */
1115 static void
1116 redisplay_windows (window)
1117 Lisp_Object window;
1119 for (; !NILP (window); window = XWINDOW (window)->next)
1120 redisplay_window (window, 0);
1123 /* Redisplay window WINDOW and its subwindows. */
1125 static void
1126 redisplay_window (window, just_this_one)
1127 Lisp_Object window;
1128 int just_this_one;
1130 register struct window *w = XWINDOW (window);
1131 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1132 int height;
1133 register int lpoint = PT;
1134 struct buffer *old = current_buffer;
1135 register int width = window_internal_width (w) - 1;
1136 register int startp;
1137 register int hscroll = XINT (w->hscroll);
1138 struct position pos;
1139 int opoint = PT;
1140 int tem;
1141 int window_needs_modeline;
1143 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1145 /* If this is a combination window, do its children; that's all. */
1147 if (!NILP (w->vchild))
1149 redisplay_windows (w->vchild);
1150 return;
1152 if (!NILP (w->hchild))
1154 redisplay_windows (w->hchild);
1155 return;
1157 if (NILP (w->buffer))
1158 abort ();
1160 height = window_internal_height (w);
1162 if (MINI_WINDOW_P (w))
1164 if (w == XWINDOW (minibuf_window))
1166 if (echo_area_glyphs)
1167 /* We've already displayed the echo area glyphs, if any. */
1168 goto finish_scroll_bars;
1170 else
1172 /* This is a minibuffer, but it's not the currently active one, so
1173 clear it. */
1174 int vpos = XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top);
1175 int i;
1177 for (i = 0; i < height; i++)
1179 get_display_line (f, vpos + i, 0);
1180 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
1183 goto finish_scroll_bars;
1187 if (update_mode_lines)
1188 w->update_mode_line = Qt;
1190 /* Otherwise set up data on this window; select its buffer and point value */
1192 set_buffer_temp (XBUFFER (w->buffer));
1193 opoint = PT;
1195 /* Count number of windows showing the selected buffer.
1196 An indirect buffer counts as its base buffer. */
1198 if (!just_this_one)
1200 struct buffer *current_base, *window_base;
1201 current_base = current_buffer;
1202 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1203 if (current_base->base_buffer)
1204 current_base = current_base->base_buffer;
1205 if (window_base->base_buffer)
1206 window_base = window_base->base_buffer;
1207 if (current_base == window_base)
1208 buffer_shared++;
1211 /* POINT refers normally to the selected window.
1212 For any other window, set up appropriate value. */
1214 if (!EQ (window, selected_window))
1216 int new_pt = marker_position (w->pointm);
1217 if (new_pt < BEGV)
1219 new_pt = BEGV;
1220 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1222 else if (new_pt > (ZV - 1))
1224 new_pt = ZV;
1225 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1227 /* We don't use SET_PT so that the point-motion hooks don't run. */
1228 BUF_PT (current_buffer) = new_pt;
1231 /* If any of the character widths specified in the display table
1232 have changed, invalidate the width run cache. It's true that this
1233 may be a bit late to catch such changes, but the rest of
1234 redisplay goes (non-fatally) haywire when the display table is
1235 changed, so why should we worry about doing any better? */
1236 if (current_buffer->width_run_cache)
1238 struct Lisp_Vector *disptab = buffer_display_table ();
1240 if (! disptab_matches_widthtab (disptab,
1241 XVECTOR (current_buffer->width_table)))
1243 invalidate_region_cache (current_buffer,
1244 current_buffer->width_run_cache,
1245 BEG, Z);
1246 recompute_width_table (current_buffer, disptab);
1250 /* If window-start is screwed up, choose a new one. */
1251 if (XMARKER (w->start)->buffer != current_buffer)
1252 goto recenter;
1254 startp = marker_position (w->start);
1256 /* Handle case where place to start displaying has been specified,
1257 unless the specified location is outside the accessible range. */
1258 if (!NILP (w->force_start))
1260 /* Forget any recorded base line for line number display. */
1261 w->base_line_number = Qnil;
1262 w->update_mode_line = Qt;
1263 w->force_start = Qnil;
1264 XSETFASTINT (w->last_modified, 0);
1265 if (startp < BEGV) startp = BEGV;
1266 if (startp > ZV) startp = ZV;
1267 try_window (window, startp);
1268 if (cursor_vpos < 0)
1270 /* If point does not appear, move point so it does appear */
1271 pos = *compute_motion (startp, 0,
1272 ((EQ (window, minibuf_window) && startp == 1)
1273 ? minibuf_prompt_width : 0)
1275 (hscroll ? 1 - hscroll : 0),
1276 ZV, height / 2,
1277 - (1 << (SHORTBITS - 1)),
1278 width, hscroll, pos_tab_offset (w, startp), w);
1279 BUF_PT (current_buffer) = pos.bufpos;
1280 if (w != XWINDOW (selected_window))
1281 Fset_marker (w->pointm, make_number (PT), Qnil);
1282 else
1284 if (current_buffer == old)
1285 lpoint = PT;
1286 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1287 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1289 /* If we are highlighting the region,
1290 then we just changed the region, so redisplay to show it. */
1291 if (!NILP (Vtransient_mark_mode)
1292 && !NILP (current_buffer->mark_active))
1294 cancel_my_columns (XWINDOW (window));
1295 try_window (window, startp);
1298 goto done;
1301 /* Handle case where text has not changed, only point,
1302 and it has not moved off the frame */
1304 /* This code is not used for minibuffer for the sake of
1305 the case of redisplaying to replace an echo area message;
1306 since in that case the minibuffer contents per se are usually unchanged.
1307 This code is of no real use in the minibuffer since
1308 the handling of this_line_bufpos, etc.,
1309 in redisplay handles the same cases. */
1311 if (XFASTINT (w->last_modified) >= MODIFF
1312 && PT >= startp && !clip_changed
1313 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
1314 /* Can't use this case if highlighting a region. */
1315 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1316 && NILP (w->region_showing)
1317 /* If end pos is out of date, scroll bar and percentage will be wrong */
1318 && INTEGERP (w->window_end_vpos)
1319 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1320 && !EQ (window, minibuf_window))
1322 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0),
1323 PT, height + 1, 10000, width, hscroll,
1324 pos_tab_offset (w, startp), w);
1326 if (pos.vpos < height)
1328 /* Ok, point is still on frame */
1329 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1331 /* These variables are supposed to be origin 1 */
1332 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1333 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1335 /* This doesn't do the trick, because if a window to the right of
1336 this one must be redisplayed, this does nothing because there
1337 is nothing in DesiredFrame yet, and then the other window is
1338 redisplayed, making likes that are empty in this window's columns.
1339 if (XFASTINT (w->width) != FRAME_WIDTH (f))
1340 preserve_my_columns (w);
1342 goto done;
1344 /* Don't bother trying redisplay with same start;
1345 we already know it will lose */
1347 /* If current starting point was originally the beginning of a line
1348 but no longer is, find a new starting point. */
1349 else if (!NILP (w->start_at_line_beg)
1350 && !(startp <= BEGV
1351 || FETCH_CHAR (startp - 1) == '\n'))
1353 goto recenter;
1355 else if (just_this_one && !MINI_WINDOW_P (w)
1356 && PT >= startp
1357 && XFASTINT (w->last_modified)
1358 /* or else vmotion on first line won't work. */
1359 && ! NILP (w->start_at_line_beg)
1360 && ! EQ (w->window_end_valid, Qnil)
1361 && do_id && !clip_changed
1362 && !blank_end_of_window
1363 && XFASTINT (w->width) == FRAME_WIDTH (f)
1364 /* Can't use this case if highlighting a region. */
1365 && !(!NILP (Vtransient_mark_mode)
1366 && !NILP (current_buffer->mark_active))
1367 && NILP (w->region_showing)
1368 && EQ (last_arrow_position, Voverlay_arrow_position)
1369 && EQ (last_arrow_string, Voverlay_arrow_string)
1370 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1371 && tem != -2)
1373 /* tem > 0 means success. tem == -1 means choose new start.
1374 tem == -2 means try again with same start,
1375 and nothing but whitespace follows the changed stuff.
1376 tem == 0 means try again with same start. */
1377 if (tem > 0)
1378 goto done;
1380 else if (startp >= BEGV && startp <= ZV
1381 /* Avoid starting display at end of buffer! */
1382 && (startp < ZV || startp == BEGV
1383 || (XFASTINT (w->last_modified) >= MODIFF)))
1385 /* Try to redisplay starting at same place as before */
1386 /* If point has not moved off frame, accept the results */
1387 try_window (window, startp);
1388 if (cursor_vpos >= 0)
1390 if (!just_this_one || clip_changed || beg_unchanged < startp)
1391 /* Forget any recorded base line for line number display. */
1392 w->base_line_number = Qnil;
1393 goto done;
1395 else
1396 cancel_my_columns (w);
1399 XSETFASTINT (w->last_modified, 0);
1400 w->update_mode_line = Qt;
1402 /* Try to scroll by specified few lines */
1404 if (scroll_step && !clip_changed)
1406 if (PT > startp)
1408 pos = *vmotion (Z - XFASTINT (w->window_end_pos),
1409 scroll_step, width, hscroll, window);
1410 if (pos.vpos >= height)
1411 goto scroll_fail;
1414 pos = *vmotion (startp, PT < startp ? - scroll_step : scroll_step,
1415 width, hscroll, window);
1417 if (PT >= pos.bufpos)
1419 try_window (window, pos.bufpos);
1420 if (cursor_vpos >= 0)
1422 if (!just_this_one || clip_changed || beg_unchanged < startp)
1423 /* Forget any recorded base line for line number display. */
1424 w->base_line_number = Qnil;
1425 goto done;
1427 else
1428 cancel_my_columns (w);
1430 scroll_fail: ;
1433 /* Finally, just choose place to start which centers point */
1435 recenter:
1436 /* Forget any previously recorded base line for line number display. */
1437 w->base_line_number = Qnil;
1439 pos = *vmotion (PT, - (height / 2), width, hscroll, window);
1440 try_window (window, pos.bufpos);
1442 startp = marker_position (w->start);
1443 w->start_at_line_beg
1444 = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
1446 done:
1447 if ((!NILP (w->update_mode_line)
1448 /* If window not full width, must redo its mode line
1449 if the window to its side is being redone */
1450 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
1451 || INTEGERP (w->base_line_pos)
1452 || (!NILP (w->column_number_displayed)
1453 && XFASTINT (w->column_number_displayed) != current_column ()))
1454 && height != XFASTINT (w->height))
1455 display_mode_line (w);
1456 if (! line_number_displayed
1457 && ! BUFFERP (w->base_line_pos))
1459 w->base_line_pos = Qnil;
1460 w->base_line_number = Qnil;
1463 /* When we reach a frame's selected window, redo the frame's menu bar. */
1464 if (!NILP (w->update_mode_line)
1465 #ifdef USE_X_TOOLKIT
1466 && FRAME_EXTERNAL_MENU_BAR (f)
1467 #else
1468 && FRAME_MENU_BAR_LINES (f) > 0
1469 #endif
1470 && EQ (FRAME_SELECTED_WINDOW (f), window))
1471 display_menu_bar (w);
1473 finish_scroll_bars:
1474 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
1476 int start, end, whole;
1478 /* Calculate the start and end positions for the current window.
1479 At some point, it would be nice to choose between scrollbars
1480 which reflect the whole buffer size, with special markers
1481 indicating narrowing, and scrollbars which reflect only the
1482 visible region.
1484 Note that minibuffers sometimes aren't displaying any text. */
1485 if (! MINI_WINDOW_P (w)
1486 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1488 whole = ZV - BEGV;
1489 start = startp - BEGV;
1490 /* I don't think this is guaranteed to be right. For the
1491 moment, we'll pretend it is. */
1492 end = (Z - XINT (w->window_end_pos)) - BEGV;
1494 if (end < start) end = start;
1495 if (whole < (end - start)) whole = end - start;
1497 else
1498 start = end = whole = 0;
1500 /* Indicate what this scroll bar ought to be displaying now. */
1501 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
1503 /* Note that we actually used the scroll bar attached to this window,
1504 so it shouldn't be deleted at the end of redisplay. */
1505 (*redeem_scroll_bar_hook) (w);
1508 BUF_PT (current_buffer) = opoint;
1509 set_buffer_temp (old);
1510 BUF_PT (current_buffer) = lpoint;
1513 /* Do full redisplay on one window, starting at position `pos'. */
1515 static void
1516 try_window (window, pos)
1517 Lisp_Object window;
1518 register int pos;
1520 register struct window *w = XWINDOW (window);
1521 register int height = window_internal_height (w);
1522 register int vpos = XFASTINT (w->top);
1523 register int last_text_vpos = vpos;
1524 int tab_offset = pos_tab_offset (w, pos);
1525 FRAME_PTR f = XFRAME (w->frame);
1526 int width = window_internal_width (w) - 1;
1527 struct position val;
1529 Fset_marker (w->start, make_number (pos), Qnil);
1530 cursor_vpos = -1;
1531 overlay_arrow_seen = 0;
1532 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1534 while (--height >= 0)
1536 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1537 tab_offset += width;
1538 if (val.vpos) tab_offset = 0;
1539 vpos++;
1540 if (pos != val.bufpos)
1541 last_text_vpos
1542 /* Next line, unless prev line ended in end of buffer with no cr */
1543 = vpos - (val.vpos && (FETCH_CHAR (val.bufpos - 1) != '\n'
1544 #ifdef USE_TEXT_PROPERTIES
1545 || ! NILP (Fget_char_property (val.bufpos-1,
1546 Qinvisible,
1547 window))
1548 #endif
1550 pos = val.bufpos;
1553 /* If last line is continued in middle of character,
1554 include the split character in the text considered on the frame */
1555 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1556 pos++;
1558 /* If bottom just moved off end of frame, change mode line percentage. */
1559 if (XFASTINT (w->window_end_pos) == 0
1560 && Z != pos)
1561 w->update_mode_line = Qt;
1563 /* Say where last char on frame will be, once redisplay is finished. */
1564 XSETFASTINT (w->window_end_pos, Z - pos);
1565 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
1566 /* But that is not valid info until redisplay finishes. */
1567 w->window_end_valid = Qnil;
1570 /* Try to redisplay when buffer is modified locally,
1571 computing insert/delete line to preserve text outside
1572 the bounds of the changes.
1573 Return 1 if successful, 0 if if cannot tell what to do,
1574 or -1 to tell caller to find a new window start,
1575 or -2 to tell caller to do normal redisplay with same window start. */
1577 static int
1578 try_window_id (window)
1579 Lisp_Object window;
1581 int pos;
1582 register struct window *w = XWINDOW (window);
1583 register int height = window_internal_height (w);
1584 FRAME_PTR f = XFRAME (w->frame);
1585 int top = XFASTINT (w->top);
1586 int start = marker_position (w->start);
1587 int width = window_internal_width (w) - 1;
1588 int hscroll = XINT (w->hscroll);
1589 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
1590 register int vpos;
1591 register int i, tem;
1592 int last_text_vpos = 0;
1593 int stop_vpos;
1594 int selective = (INTEGERP (current_buffer->selective_display)
1595 ? XINT (current_buffer->selective_display)
1596 : !NILP (current_buffer->selective_display) ? -1 : 0);
1598 struct position val, bp, ep, xp, pp;
1599 int scroll_amount = 0;
1600 int delta;
1601 int tab_offset, epto;
1603 if (GPT - BEG < beg_unchanged)
1604 beg_unchanged = GPT - BEG;
1605 if (Z - GPT < end_unchanged)
1606 end_unchanged = Z - GPT;
1608 if (beg_unchanged + BEG < start)
1609 return 0; /* Give up if changes go above top of window */
1611 /* Find position before which nothing is changed. */
1612 bp = *compute_motion (start, 0, lmargin,
1613 min (ZV, beg_unchanged + BEG), height + 1, 0,
1614 width, hscroll, pos_tab_offset (w, start), w);
1615 if (bp.vpos >= height)
1617 if (PT < bp.bufpos && !bp.contin)
1619 /* All changes are below the frame, and point is on the frame.
1620 We don't need to change the frame at all.
1621 But we need to update window_end_pos to account for
1622 any change in buffer size. */
1623 bp = *compute_motion (start, 0, lmargin,
1624 Z, height, 0,
1625 width, hscroll, pos_tab_offset (w, start), w);
1626 XSETFASTINT (w->window_end_vpos, height);
1627 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
1628 return 1;
1630 return 0;
1633 vpos = bp.vpos;
1635 /* Find beginning of that frame line. Must display from there. */
1636 bp = *vmotion (bp.bufpos, 0, width, hscroll, window);
1638 pos = bp.bufpos;
1639 val.hpos = lmargin;
1640 if (pos < start)
1641 return -1;
1643 /* If about to start displaying at the beginning of a continuation line,
1644 really start with previous frame line, in case it was not
1645 continued when last redisplayed */
1646 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
1648 /* Likewise if we have to worry about selective display. */
1649 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
1651 bp = *vmotion (bp.bufpos, -1, width, hscroll, window);
1652 --vpos;
1653 pos = bp.bufpos;
1656 if (bp.contin && bp.hpos != lmargin)
1658 val.hpos = bp.prevhpos - width + lmargin;
1659 pos--;
1662 bp.vpos = vpos;
1664 /* Find first visible newline after which no more is changed. */
1665 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
1666 if (selective > 0)
1667 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
1668 tem = find_next_newline (tem, 1);
1670 /* Compute the cursor position after that newline. */
1671 ep = *compute_motion (pos, vpos, val.hpos, tem,
1672 height, - (1 << (SHORTBITS - 1)),
1673 width, hscroll, pos_tab_offset (w, bp.bufpos), w);
1675 /* If changes reach past the text available on the frame,
1676 just display rest of frame. */
1677 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
1678 stop_vpos = height;
1679 else
1680 stop_vpos = ep.vpos;
1682 /* If no newline before ep, the line ep is on includes some changes
1683 that must be displayed. Make sure we don't stop before it. */
1684 /* Also, if changes reach all the way until ep.bufpos,
1685 it is possible that something was deleted after the
1686 newline before it, so the following line must be redrawn. */
1687 if (stop_vpos == ep.vpos
1688 && (ep.bufpos == BEGV
1689 || FETCH_CHAR (ep.bufpos - 1) != '\n'
1690 || ep.bufpos == Z - end_unchanged))
1691 stop_vpos = ep.vpos + 1;
1693 cursor_vpos = -1;
1694 overlay_arrow_seen = 0;
1696 /* If changes do not reach to bottom of window,
1697 figure out how much to scroll the rest of the window */
1698 if (stop_vpos < height)
1700 /* Now determine how far up or down the rest of the window has moved */
1701 epto = pos_tab_offset (w, ep.bufpos);
1702 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1703 Z - XFASTINT (w->window_end_pos),
1704 10000, 0, width, hscroll, epto, w);
1705 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
1707 /* Is everything on frame below the changes whitespace?
1708 If so, no scrolling is really necessary. */
1709 for (i = ep.bufpos; i < xp.bufpos; i++)
1711 tem = FETCH_CHAR (i);
1712 if (tem != ' ' && tem != '\n' && tem != '\t')
1713 break;
1715 if (i == xp.bufpos)
1716 return -2;
1718 XSETFASTINT (w->window_end_vpos,
1719 XFASTINT (w->window_end_vpos) + scroll_amount);
1721 /* Before doing any scrolling, verify that point will be on frame. */
1722 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height))
1724 if (PT <= xp.bufpos)
1726 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1727 PT, height, - (1 << (SHORTBITS - 1)),
1728 width, hscroll, epto, w);
1730 else
1732 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos,
1733 PT, height, - (1 << (SHORTBITS - 1)),
1734 width, hscroll,
1735 pos_tab_offset (w, xp.bufpos), w);
1737 if (pp.bufpos < PT || pp.vpos == height)
1738 return 0;
1739 cursor_vpos = pp.vpos + top;
1740 cursor_hpos = pp.hpos + XFASTINT (w->left);
1743 if (stop_vpos - scroll_amount >= height
1744 || ep.bufpos == xp.bufpos)
1746 if (scroll_amount < 0)
1747 stop_vpos -= scroll_amount;
1748 scroll_amount = 0;
1749 /* In this path, we have altered window_end_vpos
1750 and not left it negative.
1751 We must make sure that, in case display is preempted
1752 before the frame changes to reflect what we do here,
1753 further updates will not come to try_window_id
1754 and assume the frame and window_end_vpos match. */
1755 blank_end_of_window = 1;
1757 else if (!scroll_amount)
1759 /* Even if we don't need to scroll, we must adjust the
1760 charstarts of subsequent lines (that we won't redisplay)
1761 according to the amount of text inserted or deleted. */
1762 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1763 int adjust = ep.bufpos - oldpos;
1764 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
1766 else if (bp.bufpos == Z - end_unchanged)
1768 /* If reprinting everything is nearly as fast as scrolling,
1769 don't bother scrolling. Can happen if lines are short. */
1770 if (scroll_cost (f, bp.vpos + top - scroll_amount,
1771 top + height - max (0, scroll_amount),
1772 scroll_amount)
1773 > xp.bufpos - bp.bufpos - 20)
1774 /* Return "try normal display with same window-start."
1775 Too bad we can't prevent further scroll-thinking. */
1776 return -2;
1777 /* If pure deletion, scroll up as many lines as possible.
1778 In common case of killing a line, this can save the
1779 following line from being overwritten by scrolling
1780 and therefore having to be redrawn. */
1781 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
1782 top + height - max (0, scroll_amount),
1783 scroll_amount, bp.bufpos);
1784 if (!tem)
1785 stop_vpos = height;
1786 else
1788 /* scroll_frame_lines did not properly adjust subsequent
1789 lines' charstarts in the case where the text of the
1790 screen line at bp.vpos has changed.
1791 (This can happen in a deletion that ends in mid-line.)
1792 To adjust properly, we need to make things constent at
1793 the position ep.
1794 So do a second adjust to make that happen.
1795 Note that stop_vpos >= ep.vpos, so it is sufficient
1796 to update the charstarts for lines at ep.vpos and below. */
1797 int oldstart
1798 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1799 adjust_window_charstarts (w, ep.vpos + top - 1,
1800 ep.bufpos - oldstart);
1803 else if (scroll_amount)
1805 /* If reprinting everything is nearly as fast as scrolling,
1806 don't bother scrolling. Can happen if lines are short. */
1807 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1808 overestimate of cost of reprinting, since xp.bufpos
1809 would end up below the bottom of the window. */
1810 if (scroll_cost (f, ep.vpos + top - scroll_amount,
1811 top + height - max (0, scroll_amount),
1812 scroll_amount)
1813 > xp.bufpos - ep.bufpos - 20)
1814 /* Return "try normal display with same window-start."
1815 Too bad we can't prevent further scroll-thinking. */
1816 return -2;
1817 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
1818 top + height - max (0, scroll_amount),
1819 scroll_amount, ep.bufpos);
1820 if (!tem) stop_vpos = height;
1824 /* In any case, do not display past bottom of window */
1825 if (stop_vpos >= height)
1827 stop_vpos = height;
1828 scroll_amount = 0;
1831 /* Handle case where pos is before w->start --
1832 can happen if part of line had been clipped and is not clipped now */
1833 if (vpos == 0 && pos < marker_position (w->start))
1834 Fset_marker (w->start, make_number (pos), Qnil);
1836 /* Redisplay the lines where the text was changed */
1837 last_text_vpos = vpos;
1838 tab_offset = pos_tab_offset (w, pos);
1839 /* If we are starting display in mid-character, correct tab_offset
1840 to account for passing the line that that character really starts in. */
1841 if (val.hpos < lmargin)
1842 tab_offset += width;
1843 while (vpos < stop_vpos)
1845 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
1846 tab_offset += width;
1847 if (val.vpos) tab_offset = 0;
1848 if (pos != val.bufpos)
1849 last_text_vpos
1850 /* Next line, unless prev line ended in end of buffer with no cr */
1851 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
1852 pos = val.bufpos;
1855 /* There are two cases:
1856 1) we have displayed down to the bottom of the window
1857 2) we have scrolled lines below stop_vpos by scroll_amount */
1859 if (vpos == height)
1861 /* If last line is continued in middle of character,
1862 include the split character in the text considered on the frame */
1863 if (val.hpos < lmargin)
1864 val.bufpos++;
1865 XSETFASTINT (w->window_end_vpos, last_text_vpos);
1866 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
1869 /* If scrolling made blank lines at window bottom,
1870 redisplay to fill those lines */
1871 if (scroll_amount < 0)
1873 /* Don't consider these lines for general-purpose scrolling.
1874 That will save time in the scrolling computation. */
1875 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
1876 vpos = xp.vpos;
1877 pos = xp.bufpos;
1878 val.hpos = lmargin;
1879 if (pos == ZV)
1880 vpos = height + scroll_amount;
1881 else if (xp.contin && xp.hpos != lmargin)
1883 val.hpos = xp.prevhpos - width + lmargin;
1884 pos--;
1887 blank_end_of_window = 1;
1888 tab_offset = pos_tab_offset (w, pos);
1889 /* If we are starting display in mid-character, correct tab_offset
1890 to account for passing the line that that character starts in. */
1891 if (val.hpos < lmargin)
1892 tab_offset += width;
1894 while (vpos < height)
1896 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
1897 tab_offset += width;
1898 if (val.vpos) tab_offset = 0;
1899 pos = val.bufpos;
1902 /* Here is a case where display_text_line sets cursor_vpos wrong.
1903 Make it be fixed up, below. */
1904 if (xp.bufpos == ZV
1905 && xp.bufpos == PT)
1906 cursor_vpos = -1;
1909 /* If bottom just moved off end of frame, change mode line percentage. */
1910 if (XFASTINT (w->window_end_pos) == 0
1911 && Z != val.bufpos)
1912 w->update_mode_line = Qt;
1914 /* Attempt to adjust end-of-text positions to new bottom line */
1915 if (scroll_amount)
1917 delta = height - xp.vpos;
1918 if (delta < 0
1919 || (delta > 0 && xp.bufpos <= ZV)
1920 || (delta == 0 && xp.hpos))
1922 val = *vmotion (Z - XFASTINT (w->window_end_pos),
1923 delta, width, hscroll, window);
1924 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
1925 XSETFASTINT (w->window_end_vpos,
1926 XFASTINT (w->window_end_vpos) + val.vpos);
1930 w->window_end_valid = Qnil;
1932 /* If point was not in a line that was displayed, find it */
1933 if (cursor_vpos < 0)
1935 val = *compute_motion (start, 0, lmargin, PT, 10000, 10000,
1936 width, hscroll, pos_tab_offset (w, start), w);
1937 /* Admit failure if point is off frame now */
1938 if (val.vpos >= height)
1940 for (vpos = 0; vpos < height; vpos++)
1941 cancel_line (vpos + top, f);
1942 return 0;
1944 cursor_vpos = val.vpos + top;
1945 cursor_hpos = val.hpos + XFASTINT (w->left);
1948 FRAME_CURSOR_X (f) = max (0, cursor_hpos);
1949 FRAME_CURSOR_Y (f) = cursor_vpos;
1951 if (debug_end_pos)
1953 val = *compute_motion (start, 0, lmargin, ZV,
1954 height, - (1 << (SHORTBITS - 1)),
1955 width, hscroll, pos_tab_offset (w, start), w);
1956 if (val.vpos != XFASTINT (w->window_end_vpos))
1957 abort ();
1958 if (XFASTINT (w->window_end_pos)
1959 != Z - val.bufpos)
1960 abort ();
1963 return 1;
1966 /* Mark a section of BUF as modified, but only for the sake of redisplay.
1967 This is useful for recording changes to overlays.
1969 We increment the buffer's modification timestamp and set the
1970 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
1971 as if the region of text between START and END had been modified;
1972 the redisplay code will check this against the windows' timestamps,
1973 and redraw the appropriate area of the buffer.
1975 However, if the buffer is unmodified, we bump the last-save
1976 timestamp as well, so that incrementing the timestamp doesn't fool
1977 Emacs into thinking that the buffer's text has been modified.
1979 Tweaking the timestamps shouldn't hurt the first-modification
1980 timestamps recorded in the undo records; those values aren't
1981 written until just before a real text modification is made, so they
1982 will never catch the timestamp value just before this function gets
1983 called. */
1985 void
1986 redisplay_region (buf, start, end)
1987 struct buffer *buf;
1988 int start, end;
1990 if (start == end)
1991 return;
1993 if (start > end)
1995 int temp = start;
1996 start = end; end = temp;
1999 /* If this is a buffer not in the selected window,
2000 we must do other windows. */
2001 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2002 windows_or_buffers_changed = 1;
2003 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2004 else if (buf != current_buffer)
2005 windows_or_buffers_changed = 1;
2006 /* If multiple windows show this buffer, we must do other windows. */
2007 else if (buffer_shared > 1)
2008 windows_or_buffers_changed = 1;
2009 else
2011 if (unchanged_modified == MODIFF)
2013 beg_unchanged = start - BEG;
2014 end_unchanged = Z - end;
2016 else
2018 if (Z - end < end_unchanged)
2019 end_unchanged = Z - end;
2020 if (start - BEG < beg_unchanged)
2021 beg_unchanged = start - BEG;
2025 /* Increment the buffer's time stamp, but also increment the save
2026 and autosave timestamps, so as not to screw up that timekeeping. */
2027 if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf))
2028 BUF_SAVE_MODIFF (buf)++;
2029 if (BUF_MODIFF (buf) == buf->auto_save_modified)
2030 buf->auto_save_modified++;
2032 BUF_MODIFF (buf) ++;
2036 /* Copy LEN glyphs starting address FROM to the rope TO.
2037 But don't actually copy the parts that would come in before S.
2038 Value is TO, advanced past the copied data.
2039 F is the frame we are displaying in. */
2041 static GLYPH *
2042 copy_part_of_rope (f, to, s, from, len, face)
2043 FRAME_PTR f;
2044 register GLYPH *to; /* Copy to here. */
2045 register GLYPH *s; /* Starting point. */
2046 Lisp_Object *from; /* Data to copy. */
2047 int len;
2048 int face; /* Face to apply to glyphs which don't specify one. */
2050 int n = len;
2051 register Lisp_Object *fp = from;
2052 /* These cache the results of the last call to compute_glyph_face. */
2053 int last_code = -1;
2054 int last_merged = 0;
2056 #ifdef HAVE_FACES
2057 if (! FRAME_TERMCAP_P (f))
2058 while (n--)
2060 int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2061 int facecode;
2063 if (FAST_GLYPH_FACE (glyph) == 0)
2064 /* If GLYPH has no face code, use FACE. */
2065 facecode = face;
2066 else if (FAST_GLYPH_FACE (glyph) == last_code)
2067 /* If it's same as previous glyph, use same result. */
2068 facecode = last_merged;
2069 else
2071 /* Merge this glyph's face and remember the result. */
2072 last_code = FAST_GLYPH_FACE (glyph);
2073 last_merged = facecode = compute_glyph_face (f, last_code, face);
2076 if (to >= s)
2077 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
2078 ++to;
2079 ++fp;
2081 else
2082 #endif
2083 while (n--)
2085 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2086 ++to;
2087 ++fp;
2089 return to;
2092 /* Correct a glyph by replacing its specified user-level face code
2093 with a displayable computed face code. */
2095 static GLYPH
2096 fix_glyph (f, glyph, cface)
2097 FRAME_PTR f;
2098 GLYPH glyph;
2099 int cface;
2101 #ifdef HAVE_FACES
2102 if (! FRAME_TERMCAP_P (f))
2104 if (FAST_GLYPH_FACE (glyph) != 0)
2105 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2106 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2108 #endif
2109 return glyph;
2112 /* Display one line of window W, starting at position START in W's buffer.
2114 Display starting at horizontal position HPOS, expressed relative to
2115 W's left edge. In situations where the text at START shouldn't
2116 start at the left margin (i.e. when the window is hscrolled, or
2117 we're continuing a line which left off in the midst of a
2118 multi-column character), HPOS should be negative; we throw away
2119 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2120 account.
2122 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2124 Display on position VPOS on the frame. It is origin 0, relative to
2125 the top of the frame, not W.
2127 Returns a STRUCT POSITION giving character to start next line with
2128 and where to display it, including a zero or negative hpos.
2129 The vpos field is not really a vpos; it is 1 unless the line is continued */
2131 struct position val_display_text_line;
2133 static struct position *
2134 display_text_line (w, start, vpos, hpos, taboffset)
2135 struct window *w;
2136 int start;
2137 int vpos;
2138 int hpos;
2139 int taboffset;
2141 register int pos = start;
2142 register int c;
2143 register GLYPH *p1;
2144 int end;
2145 register int pause;
2146 register unsigned char *p;
2147 GLYPH *endp;
2148 register GLYPH *leftmargin;
2149 register GLYPH *p1prev = 0;
2150 register GLYPH *p1start;
2151 int *charstart;
2152 FRAME_PTR f = XFRAME (w->frame);
2153 int tab_width = XINT (current_buffer->tab_width);
2154 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2155 int width = window_internal_width (w) - 1;
2156 struct position val;
2157 int lastpos;
2158 int invis;
2159 int hscroll = XINT (w->hscroll);
2160 int truncate = (hscroll
2161 || (truncate_partial_width_windows
2162 && XFASTINT (w->width) < FRAME_WIDTH (f))
2163 || !NILP (current_buffer->truncate_lines));
2165 /* 1 if we should highlight the region. */
2166 int highlight_region
2167 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
2168 int region_beg, region_end;
2170 int selective = (INTEGERP (current_buffer->selective_display)
2171 ? XINT (current_buffer->selective_display)
2172 : !NILP (current_buffer->selective_display) ? -1 : 0);
2173 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2174 register struct Lisp_Vector *dp = window_display_table (w);
2176 Lisp_Object default_invis_vector[3];
2177 /* Nonzero means display something where there are invisible lines.
2178 The precise value is the number of glyphs to display. */
2179 int selective_rlen
2180 = (selective && dp && VECTORP (DISP_INVIS_VECTOR (dp))
2181 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2182 : selective && !NILP (current_buffer->selective_display_ellipses)
2183 ? 3 : 0);
2184 /* This is the sequence of Lisp objects to display
2185 when there are invisible lines. */
2186 Lisp_Object *invis_vector_contents
2187 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2188 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2189 : default_invis_vector);
2191 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2192 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2193 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2194 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2196 /* The next buffer location at which the face should change, due
2197 to overlays or text property changes. */
2198 int next_face_change;
2200 #ifdef USE_TEXT_PROPERTIES
2201 /* The next location where the `invisible' property changes */
2202 int next_invisible;
2203 #endif
2205 /* The face we're currently using. */
2206 int current_face = 0;
2207 int i;
2209 XSETFASTINT (default_invis_vector[2], '.');
2210 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2212 hpos += XFASTINT (w->left);
2213 get_display_line (f, vpos, XFASTINT (w->left));
2214 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2216 /* Show where to highlight the region. */
2217 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2218 /* Maybe highlight only in selected window. */
2219 && (highlight_nonselected_windows
2220 || w == XWINDOW (selected_window)))
2222 region_beg = marker_position (current_buffer->mark);
2223 if (PT < region_beg)
2225 region_end = region_beg;
2226 region_beg = PT;
2228 else
2229 region_end = PT;
2230 w->region_showing = Qt;
2232 else
2233 region_beg = region_end = -1;
2235 if (MINI_WINDOW_P (w)
2236 && start == 1
2237 && vpos == XFASTINT (w->top))
2239 if (! NILP (minibuf_prompt))
2241 minibuf_prompt_width
2242 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2243 XSTRING (minibuf_prompt)->size, hpos,
2244 /* Display a space if we truncate. */
2245 ' ',
2246 1, -1,
2247 /* Truncate the prompt a little before the
2248 margin, so user input can at least start
2249 on the first line. */
2250 w->width > 10 ? w->width - 4 : -1)
2251 - hpos);
2252 hpos += minibuf_prompt_width;
2254 else
2255 minibuf_prompt_width = 0;
2258 end = ZV;
2260 /* If we're hscrolled at all, use compute_motion to skip over any
2261 text off the left edge of the window. compute_motion may know
2262 tricks to do this faster than we can. */
2263 if (hpos < 0)
2265 struct position *left_edge
2266 = compute_motion (pos, vpos, hpos,
2267 end, vpos, 0,
2268 width, hscroll, taboffset, w);
2270 /* Retrieve the buffer position and column provided by
2271 compute_motion. We can't assume that the column will be
2272 zero, because you may have multi-column characters crossing
2273 the left margin.
2275 compute_motion may have moved us past the screen position we
2276 requested, if we hit a multi-column character, or the end of
2277 the line. If so, back up. */
2278 if (left_edge->vpos > vpos
2279 || left_edge->hpos > 0)
2281 pos = left_edge->bufpos - 1;
2282 hpos = left_edge->prevhpos;
2284 else
2286 pos = left_edge->bufpos;
2287 hpos = left_edge->hpos;
2291 desired_glyphs->bufp[vpos] = start;
2292 p1 = desired_glyphs->glyphs[vpos] + hpos;
2293 p1start = p1;
2294 charstart = desired_glyphs->charstarts[vpos] + hpos;
2295 /* In case we don't ever write anything into it... */
2296 desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1;
2297 leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2298 endp = leftmargin + width;
2300 /* Arrange the overlays nicely for our purposes. Usually, we call
2301 display_text_line on only one line at a time, in which case this
2302 can't really hurt too much, or we call it on lines which appear
2303 one after another in the buffer, in which case all calls to
2304 recenter_overlay_lists but the first will be pretty cheap. */
2305 recenter_overlay_lists (current_buffer, pos);
2307 /* Loop generating characters.
2308 Stop at end of buffer, before newline,
2309 if reach or pass continuation column,
2310 or at face change. */
2311 pause = pos;
2312 next_face_change = pos;
2313 #ifdef USE_TEXT_PROPERTIES
2314 next_invisible = pos;
2315 #endif
2316 while (1)
2318 /* Record which glyph starts a character,
2319 and the character position of that character. */
2320 if (p1 >= leftmargin)
2321 charstart[p1 - p1start] = pos;
2323 if (p1 >= endp)
2324 break;
2326 p1prev = p1;
2327 if (pos >= pause)
2329 /* Did we hit the end of the visible region of the buffer?
2330 Stop here. */
2331 if (pos >= end)
2332 break;
2334 /* Did we reach point? Record the cursor location. */
2335 if (pos == PT && cursor_vpos < 0)
2337 cursor_vpos = vpos;
2338 cursor_hpos = p1 - leftmargin;
2341 #ifdef USE_TEXT_PROPERTIES
2342 /* if the `invisible' property is set to t, we can skip to
2343 the next property change */
2344 while (pos == next_invisible && pos < end)
2346 Lisp_Object position, limit, endpos, prop, ww;
2347 XSETFASTINT (position, pos);
2348 XSETWINDOW (ww, w);
2349 prop = Fget_char_property (position, Qinvisible, ww);
2350 /* This is just an estimate to give reasonable
2351 performance; nothing should go wrong if it is too small. */
2352 limit = Fnext_overlay_change (position);
2353 if (XFASTINT (limit) > pos + 50)
2354 XSETFASTINT (limit, pos + 50);
2355 endpos = Fnext_single_property_change (position, Qinvisible,
2356 Fcurrent_buffer (), limit);
2357 if (INTEGERP (endpos))
2358 next_invisible = XINT (endpos);
2359 else
2360 next_invisible = end;
2361 if (! NILP (prop))
2363 if (pos < PT && next_invisible >= PT)
2365 cursor_vpos = vpos;
2366 cursor_hpos = p1 - leftmargin;
2368 pos = next_invisible;
2371 if (pos >= end)
2372 break;
2373 #endif
2375 #ifdef HAVE_FACES
2376 /* Did we hit a face change? Figure out what face we should
2377 use now. We also hit this the first time through the
2378 loop, to see what face we should start with. */
2379 if (pos >= next_face_change && FRAME_X_P (f))
2380 current_face = compute_char_face (f, w, pos,
2381 region_beg, region_end,
2382 &next_face_change, pos + 50, 0);
2383 #endif
2385 pause = end;
2387 #ifdef USE_TEXT_PROPERTIES
2388 if (pos < next_invisible && next_invisible < pause)
2389 pause = next_invisible;
2390 #endif
2391 if (pos < next_face_change && next_face_change < pause)
2392 pause = next_face_change;
2394 /* Wouldn't you hate to read the next line to someone over
2395 the phone? */
2396 if (pos < PT && PT < pause)
2397 pause = PT;
2398 if (pos < GPT && GPT < pause)
2399 pause = GPT;
2401 p = &FETCH_CHAR (pos);
2403 c = *p++;
2404 if (c >= 040 && c < 0177
2405 && (dp == 0 || !VECTORP (DISP_CHAR_VECTOR (dp, c))))
2407 if (p1 >= leftmargin)
2408 *p1 = MAKE_GLYPH (f, c, current_face);
2409 p1++;
2411 else if (c == '\n')
2413 invis = 0;
2414 while (pos + 1 < end
2415 && selective > 0
2416 && indented_beyond_p (pos + 1, selective))
2418 invis = 1;
2419 pos = find_next_newline (pos + 1, 1);
2420 if (FETCH_CHAR (pos - 1) == '\n')
2421 pos--;
2423 if (invis && selective_rlen > 0 && p1 >= leftmargin)
2425 p1 += selective_rlen;
2426 if (p1 - leftmargin > width)
2427 p1 = endp;
2428 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2429 (p1 - p1prev), current_face);
2431 #ifdef HAVE_FACES
2432 /* Draw the face of the newline character as extending all the
2433 way to the end of the frame line. */
2434 if (current_face)
2436 if (p1 < leftmargin)
2437 p1 = leftmargin;
2438 while (p1 < endp)
2439 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2441 #endif
2442 break;
2444 else if (c == '\t')
2448 if (p1 >= leftmargin && p1 < endp)
2449 *p1 = MAKE_GLYPH (f, ' ', current_face);
2450 p1++;
2452 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
2453 % tab_width);
2455 else if (c == Ctl ('M') && selective == -1)
2457 pos = find_next_newline (pos, 1);
2458 if (FETCH_CHAR (pos - 1) == '\n')
2459 pos--;
2460 if (selective_rlen > 0)
2462 p1 += selective_rlen;
2463 if (p1 - leftmargin > width)
2464 p1 = endp;
2465 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2466 (p1 - p1prev), current_face);
2468 #ifdef HAVE_FACES
2469 /* Draw the face of the newline character as extending all the
2470 way to the end of the frame line. */
2471 if (current_face)
2473 if (p1 < leftmargin)
2474 p1 = leftmargin;
2475 while (p1 < endp)
2476 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2478 #endif
2479 break;
2481 else if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
2483 p1 = copy_part_of_rope (f, p1, leftmargin,
2484 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2485 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2486 current_face);
2488 else if (c < 0200 && ctl_arrow)
2490 if (p1 >= leftmargin)
2491 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
2492 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
2493 current_face);
2494 p1++;
2495 if (p1 >= leftmargin && p1 < endp)
2496 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
2497 p1++;
2499 else
2501 if (p1 >= leftmargin)
2502 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
2503 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
2504 current_face);
2505 p1++;
2506 if (p1 >= leftmargin && p1 < endp)
2507 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
2508 p1++;
2509 if (p1 >= leftmargin && p1 < endp)
2510 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
2511 p1++;
2512 if (p1 >= leftmargin && p1 < endp)
2513 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
2514 p1++;
2517 /* Do nothing here for a char that's entirely off the left edge. */
2518 if (p1 >= leftmargin)
2520 /* For all the glyphs occupied by this character, except for the
2521 first, store -1 in charstarts. */
2522 if (p1 != p1prev)
2524 int *p2x = &charstart[p1prev - p1start];
2525 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2527 /* The window's left column should always
2528 contain a character position.
2529 And don't clobber anything to the left of that. */
2530 if (p1prev < leftmargin)
2532 p2x = charstart + (leftmargin - p1start);
2533 *p2x = pos;
2536 /* This loop skips over the char p2x initially points to. */
2537 while (++p2x < p2)
2538 *p2x = -1;
2542 pos++;
2545 val.hpos = - XINT (w->hscroll);
2546 if (val.hpos)
2547 val.hpos++;
2549 val.vpos = 1;
2551 lastpos = pos;
2553 /* Store 0 in this charstart line for the positions where
2554 there is no character. But do leave what was recorded
2555 for the character that ended the line. */
2556 /* Add 1 in the endtest to compensate for the fact that ENDP was
2557 made from WIDTH, which is 1 less than the window's actual
2558 internal width. */
2559 i = p1 - p1start + 1;
2560 if (p1 < leftmargin)
2561 i += leftmargin - p1;
2562 for (; i < endp - p1start + 1; i++)
2563 charstart[i] = 0;
2565 /* Handle continuation in middle of a character */
2566 /* by backing up over it */
2567 if (p1 > endp)
2569 /* Don't back up if we never actually displayed any text.
2570 This occurs when the minibuffer prompt takes up the whole line. */
2571 if (p1prev)
2573 /* Start the next line with that same character */
2574 pos--;
2575 /* but at negative hpos, to skip the columns output on this line. */
2576 val.hpos += p1prev - endp;
2579 /* Keep in this line everything up to the continuation column. */
2580 p1 = endp;
2583 /* Finish deciding which character to start the next line on,
2584 and what hpos to start it at.
2585 Also set `lastpos' to the last position which counts as "on this line"
2586 for cursor-positioning. */
2588 if (pos < ZV)
2590 if (FETCH_CHAR (pos) == '\n')
2592 /* If stopped due to a newline, start next line after it */
2593 pos++;
2594 /* Check again for hidden lines, in case the newline occurred exactly
2595 at the right margin. */
2596 while (pos < ZV && selective > 0
2597 && indented_beyond_p (pos, selective))
2598 pos = find_next_newline (pos, 1);
2600 else
2601 /* Stopped due to right margin of window */
2603 if (truncate)
2605 *p1++ = fix_glyph (f, truncator, 0);
2606 /* Truncating => start next line after next newline,
2607 and point is on this line if it is before the newline,
2608 and skip none of first char of next line */
2610 pos = find_next_newline (pos, 1);
2611 while (pos < ZV && selective > 0
2612 && indented_beyond_p (pos, selective));
2613 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2615 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
2617 else
2619 *p1++ = fix_glyph (f, continuer, 0);
2620 val.vpos = 0;
2621 lastpos--;
2626 /* If point is at eol or in invisible text at eol,
2627 record its frame location now. */
2629 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
2631 cursor_vpos = vpos;
2632 cursor_hpos = p1 - leftmargin;
2635 if (cursor_vpos == vpos)
2637 if (cursor_hpos < 0) cursor_hpos = 0;
2638 if (cursor_hpos > width) cursor_hpos = width;
2639 cursor_hpos += XFASTINT (w->left);
2640 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
2642 FRAME_CURSOR_Y (f) = cursor_vpos;
2643 FRAME_CURSOR_X (f) = cursor_hpos;
2645 if (w == XWINDOW (selected_window))
2647 /* Line is not continued and did not start
2648 in middle of character */
2649 if ((hpos - XFASTINT (w->left)
2650 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2651 && val.vpos)
2653 this_line_bufpos = start;
2654 this_line_buffer = current_buffer;
2655 this_line_vpos = cursor_vpos;
2656 this_line_start_hpos = hpos;
2657 this_line_endpos = Z - lastpos;
2659 else
2660 this_line_bufpos = 0;
2665 /* If hscroll and line not empty, insert truncation-at-left marker */
2666 if (hscroll && lastpos != start)
2668 *leftmargin = fix_glyph (f, truncator, 0);
2669 if (p1 <= leftmargin)
2670 p1 = leftmargin + 1;
2673 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
2675 endp++;
2676 if (p1 < leftmargin) p1 = leftmargin;
2677 while (p1 < endp) *p1++ = SPACEGLYPH;
2679 /* Don't draw vertical bars if we're using scroll bars. They're
2680 covered up by the scroll bars, and it's distracting to see
2681 them when the scroll bar windows are flickering around to be
2682 reconfigured. */
2683 *p1++ = (FRAME_HAS_VERTICAL_SCROLL_BARS (f)
2684 ? ' '
2685 : (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
2686 ? DISP_BORDER_GLYPH (dp)
2687 : '|'));
2689 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
2690 p1 - desired_glyphs->glyphs[vpos]);
2691 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
2693 /* If the start of this line is the overlay arrow-position,
2694 then put the arrow string into the display-line. */
2696 if (MARKERP (Voverlay_arrow_position)
2697 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
2698 && start == marker_position (Voverlay_arrow_position)
2699 && STRINGP (Voverlay_arrow_string)
2700 && ! overlay_arrow_seen)
2702 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
2703 int i;
2704 int len = XSTRING (Voverlay_arrow_string)->size;
2705 int arrow_end;
2707 if (len > width)
2708 len = width;
2709 #ifdef HAVE_FACES
2710 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
2712 /* If the arrow string has text props, obey them when displaying. */
2713 for (i = 0; i < len; i++)
2715 int c = p[i];
2716 Lisp_Object face, ilisp;
2717 int newface;
2719 XSETFASTINT (ilisp, i);
2720 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
2721 newface = compute_glyph_face_1 (f, face, 0);
2722 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
2725 else
2726 #endif /* HAVE_FACES */
2728 for (i = 0; i < len; i++)
2729 leftmargin[i] = p[i];
2732 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
2733 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
2734 if (desired_glyphs->used[vpos] < arrow_end)
2735 desired_glyphs->used[vpos] = arrow_end;
2737 overlay_arrow_seen = 1;
2740 val.bufpos = pos;
2741 val_display_text_line = val;
2742 return &val_display_text_line;
2745 /* Redisplay the menu bar in the frame for window W. */
2747 static void
2748 display_menu_bar (w)
2749 struct window *w;
2751 Lisp_Object items, tail;
2752 register int vpos = 0;
2753 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2754 int maxendcol = FRAME_WIDTH (f);
2755 int hpos = 0;
2756 int i;
2758 #ifndef USE_X_TOOLKIT
2759 if (FRAME_MENU_BAR_LINES (f) <= 0)
2760 return;
2762 get_display_line (f, vpos, 0);
2764 items = FRAME_MENU_BAR_ITEMS (f);
2765 for (i = 0; i < XVECTOR (items)->size; i += 3)
2767 Lisp_Object pos, string;
2768 string = XVECTOR (items)->contents[i + 1];
2769 if (NILP (string))
2770 break;
2772 XSETFASTINT (XVECTOR (items)->contents[i + 2], hpos);
2774 if (hpos < maxendcol)
2775 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
2776 XSTRING (string)->data,
2777 XSTRING (string)->size,
2778 hpos, 0, 0, hpos, maxendcol);
2779 /* Put a gap of 3 spaces between items. */
2780 if (hpos < maxendcol)
2782 int hpos1 = hpos + 3;
2783 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
2784 min (hpos1, maxendcol), maxendcol);
2788 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
2789 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
2791 /* Fill out the line with spaces. */
2792 if (maxendcol > hpos)
2793 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
2795 /* Clear the rest of the lines allocated to the menu bar. */
2796 vpos++;
2797 while (vpos < FRAME_MENU_BAR_LINES (f))
2798 get_display_line (f, vpos++, 0);
2799 #endif /* not USE_X_TOOLKIT */
2802 /* Display the mode line for window w */
2804 static void
2805 display_mode_line (w)
2806 struct window *w;
2808 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
2809 register int left = XFASTINT (w->left);
2810 register int right = XFASTINT (w->width) + left;
2811 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2813 line_number_displayed = 0;
2814 w->column_number_displayed = Qnil;
2816 get_display_line (f, vpos, left);
2817 display_mode_element (w, vpos, left, 0, right, right,
2818 current_buffer->mode_line_format);
2819 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
2821 /* Make the mode line inverse video if the entire line
2822 is made of mode lines.
2823 I.e. if this window is full width,
2824 or if it is the child of a full width window
2825 (which implies that that window is split side-by-side
2826 and the rest of this line is mode lines of the sibling windows). */
2827 if (XFASTINT (w->width) == FRAME_WIDTH (f)
2828 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
2829 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
2830 #ifdef HAVE_FACES
2831 else if (! FRAME_TERMCAP_P (f))
2833 /* For a partial width window, explicitly set face of each glyph. */
2834 int i;
2835 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
2836 for (i = left; i < right; ++i)
2837 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
2839 #endif
2842 /* Contribute ELT to the mode line for window W.
2843 How it translates into text depends on its data type.
2845 VPOS is the position of the mode line being displayed.
2847 HPOS is the position (absolute on frame) where this element's text
2848 should start. The output is truncated automatically at the right
2849 edge of window W.
2851 DEPTH is the depth in recursion. It is used to prevent
2852 infinite recursion here.
2854 MINENDCOL is the hpos before which the element may not end.
2855 The element is padded at the right with spaces if nec
2856 to reach this column.
2858 MAXENDCOL is the hpos past which this element may not extend.
2859 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
2860 (This is necessary to make nested padding and truncation work.)
2862 Returns the hpos of the end of the text generated by ELT.
2863 The next element will receive that value as its HPOS arg,
2864 so as to concatenate the elements. */
2866 static int
2867 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
2868 struct window *w;
2869 register int vpos, hpos;
2870 int depth;
2871 int minendcol;
2872 register int maxendcol;
2873 register Lisp_Object elt;
2875 tail_recurse:
2876 if (depth > 10)
2877 goto invalid;
2879 depth++;
2881 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
2883 case Lisp_String:
2885 /* A string: output it and check for %-constructs within it. */
2886 register unsigned char c;
2887 register unsigned char *this = XSTRING (elt)->data;
2889 while (hpos < maxendcol && *this)
2891 unsigned char *last = this;
2892 while ((c = *this++) != '\0' && c != '%')
2894 if (this - 1 != last)
2896 register int lim = --this - last + hpos;
2897 if (frame_title_ptr)
2898 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
2899 else
2900 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
2901 hpos, min (lim, maxendcol));
2903 else /* c == '%' */
2905 register int spec_width = 0;
2907 /* We can't allow -ve args due to the "%-" construct */
2908 /* Argument specifies minwidth but not maxwidth
2909 (maxwidth can be specified by
2910 (<negative-number> . <stuff>) mode-line elements) */
2912 while ((c = *this++) >= '0' && c <= '9')
2914 spec_width = spec_width * 10 + (c - '0');
2917 spec_width += hpos;
2918 if (spec_width > maxendcol)
2919 spec_width = maxendcol;
2921 if (c == 'M')
2922 hpos = display_mode_element (w, vpos, hpos, depth,
2923 spec_width, maxendcol,
2924 Vglobal_mode_string);
2925 else if (c != 0)
2927 char *spec = decode_mode_spec (w, c, maxendcol - hpos);
2928 if (frame_title_ptr)
2929 hpos = store_frame_title (spec, spec_width, maxendcol);
2930 else
2931 hpos = display_string (w, vpos, spec, -1,
2932 hpos, 0, 1,
2933 spec_width, maxendcol);
2938 break;
2940 case Lisp_Symbol:
2941 /* A symbol: process the value of the symbol recursively
2942 as if it appeared here directly. Avoid error if symbol void.
2943 Special case: if value of symbol is a string, output the string
2944 literally. */
2946 register Lisp_Object tem;
2947 tem = Fboundp (elt);
2948 if (!NILP (tem))
2950 tem = Fsymbol_value (elt);
2951 /* If value is a string, output that string literally:
2952 don't check for % within it. */
2953 if (STRINGP (tem))
2955 if (frame_title_ptr)
2956 hpos = store_frame_title (XSTRING (tem)->data,
2957 minendcol, maxendcol);
2958 else
2959 hpos = display_string (w, vpos, XSTRING (tem)->data,
2960 XSTRING (tem)->size,
2961 hpos, 0, 1, minendcol, maxendcol);
2963 /* Give up right away for nil or t. */
2964 else if (!EQ (tem, elt))
2965 { elt = tem; goto tail_recurse; }
2968 break;
2970 case Lisp_Cons:
2972 register Lisp_Object car, tem;
2974 /* A cons cell: three distinct cases.
2975 If first element is a string or a cons, process all the elements
2976 and effectively concatenate them.
2977 If first element is a negative number, truncate displaying cdr to
2978 at most that many characters. If positive, pad (with spaces)
2979 to at least that many characters.
2980 If first element is a symbol, process the cadr or caddr recursively
2981 according to whether the symbol's value is non-nil or nil. */
2982 car = XCONS (elt)->car;
2983 if (SYMBOLP (car))
2985 tem = Fboundp (car);
2986 elt = XCONS (elt)->cdr;
2987 if (!CONSP (elt))
2988 goto invalid;
2989 /* elt is now the cdr, and we know it is a cons cell.
2990 Use its car if CAR has a non-nil value. */
2991 if (!NILP (tem))
2993 tem = Fsymbol_value (car);
2994 if (!NILP (tem))
2995 { elt = XCONS (elt)->car; goto tail_recurse; }
2997 /* Symbol's value is nil (or symbol is unbound)
2998 Get the cddr of the original list
2999 and if possible find the caddr and use that. */
3000 elt = XCONS (elt)->cdr;
3001 if (NILP (elt))
3002 break;
3003 else if (!CONSP (elt))
3004 goto invalid;
3005 elt = XCONS (elt)->car;
3006 goto tail_recurse;
3008 else if (INTEGERP (car))
3010 register int lim = XINT (car);
3011 elt = XCONS (elt)->cdr;
3012 if (lim < 0)
3013 /* Negative int means reduce maximum width.
3014 DO NOT change MINENDCOL here!
3015 (20 -10 . foo) should truncate foo to 10 col
3016 and then pad to 20. */
3017 maxendcol = min (maxendcol, hpos - lim);
3018 else if (lim > 0)
3020 /* Padding specified. Don't let it be more than
3021 current maximum. */
3022 lim += hpos;
3023 if (lim > maxendcol)
3024 lim = maxendcol;
3025 /* If that's more padding than already wanted, queue it.
3026 But don't reduce padding already specified even if
3027 that is beyond the current truncation point. */
3028 if (lim > minendcol)
3029 minendcol = lim;
3031 goto tail_recurse;
3033 else if (STRINGP (car) || CONSP (car))
3035 register int limit = 50;
3036 /* LIMIT is to protect against circular lists. */
3037 while (CONSP (elt) && --limit > 0
3038 && hpos < maxendcol)
3040 hpos = display_mode_element (w, vpos, hpos, depth,
3041 hpos, maxendcol,
3042 XCONS (elt)->car);
3043 elt = XCONS (elt)->cdr;
3047 break;
3049 default:
3050 invalid:
3051 if (frame_title_ptr)
3052 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3053 else
3054 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3055 minendcol, maxendcol);
3056 return hpos;
3059 if (minendcol > hpos)
3060 if (frame_title_ptr)
3061 hpos = store_frame_title ("", minendcol, maxendcol);
3062 else
3063 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
3064 return hpos;
3067 /* Return a string for the output of a mode line %-spec for window W,
3068 generated by character C and width MAXWIDTH. */
3070 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3072 static char *
3073 decode_mode_spec (w, c, maxwidth)
3074 struct window *w;
3075 register char c;
3076 register int maxwidth;
3078 Lisp_Object obj;
3079 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3080 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
3081 struct buffer *b = XBUFFER (w->buffer);
3083 obj = Qnil;
3084 if (maxwidth > FRAME_WIDTH (f))
3085 maxwidth = FRAME_WIDTH (f);
3087 switch (c)
3089 case 'b':
3090 obj = b->name;
3091 #if 0
3092 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
3094 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
3095 decode_mode_spec_buf[maxwidth - 1] = '\\';
3096 decode_mode_spec_buf[maxwidth] = '\0';
3097 return decode_mode_spec_buf;
3099 #endif
3100 break;
3102 case 'f':
3103 obj = b->filename;
3104 #if 0
3105 if (NILP (obj))
3106 return "[none]";
3107 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
3109 bcopy ("...", decode_mode_spec_buf, 3);
3110 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
3111 decode_mode_spec_buf + 3, maxwidth - 3);
3112 return decode_mode_spec_buf;
3114 #endif
3115 break;
3117 case 'c':
3119 int col = current_column ();
3120 XSETFASTINT (w->column_number_displayed, col);
3121 sprintf (decode_mode_spec_buf, "%d", col);
3122 return decode_mode_spec_buf;
3125 case 'l':
3127 int startpos = marker_position (w->start);
3128 int line, linepos, topline;
3129 int nlines, junk;
3130 Lisp_Object tem;
3131 int height = XFASTINT (w->height);
3133 /* If we decided that this buffer isn't suitable for line numbers,
3134 don't forget that too fast. */
3135 if (EQ (w->base_line_pos, w->buffer))
3136 return "??";
3138 /* If the buffer is very big, don't waste time. */
3139 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
3141 w->base_line_pos = Qnil;
3142 w->base_line_number = Qnil;
3143 return "??";
3146 if (!NILP (w->base_line_number)
3147 && !NILP (w->base_line_pos)
3148 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
3150 line = XFASTINT (w->base_line_number);
3151 linepos = XFASTINT (w->base_line_pos);
3153 else
3155 line = 1;
3156 linepos = BUF_BEGV (b);
3159 /* Count lines from base line to window start position. */
3160 nlines = display_count_lines (linepos, startpos, startpos, &junk);
3162 topline = nlines + line;
3164 /* Determine a new base line, if the old one is too close
3165 or too far away, or if we did not have one.
3166 "Too close" means it's plausible a scroll-down would
3167 go back past it. */
3168 if (startpos == BUF_BEGV (b))
3170 XSETFASTINT (w->base_line_number, topline);
3171 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
3173 else if (nlines < height + 25 || nlines > height * 3 + 50
3174 || linepos == BUF_BEGV (b))
3176 int limit = BUF_BEGV (b);
3177 int position;
3178 int distance = (height * 2 + 30) * 200;
3180 if (startpos - distance > limit)
3181 limit = startpos - distance;
3183 nlines = display_count_lines (startpos, limit,
3184 -(height * 2 + 30),
3185 &position);
3186 /* If we couldn't find the lines we wanted within
3187 200 chars per line,
3188 give up on line numbers for this window. */
3189 if (position == startpos - distance)
3191 w->base_line_pos = w->buffer;
3192 w->base_line_number = Qnil;
3193 return "??";
3196 XSETFASTINT (w->base_line_number, topline - nlines);
3197 XSETFASTINT (w->base_line_pos, position);
3200 /* Now count lines from the start pos to point. */
3201 nlines = display_count_lines (startpos, PT, PT, &junk);
3203 /* Record that we did display the line number. */
3204 line_number_displayed = 1;
3206 /* Make the string to show. */
3207 sprintf (decode_mode_spec_buf, "%d", topline + nlines);
3208 return decode_mode_spec_buf;
3210 break;
3212 case 'm':
3213 obj = b->mode_name;
3214 break;
3216 case 'n':
3217 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
3218 return " Narrow";
3219 break;
3221 case '*':
3222 if (!NILP (b->read_only))
3223 return "%";
3224 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3225 return "*";
3226 return "-";
3228 case '+':
3229 /* This differs from %* only for a modified read-only buffer. */
3230 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3231 return "*";
3232 if (!NILP (b->read_only))
3233 return "%";
3234 return "-";
3236 case '&':
3237 /* This differs from %* in ignoring read-only-ness. */
3238 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3239 return "*";
3240 return "-";
3242 case 's':
3243 /* status of process */
3244 obj = Fget_buffer_process (w->buffer);
3245 if (NILP (obj))
3246 return "no process";
3247 #ifdef subprocesses
3248 obj = Fsymbol_name (Fprocess_status (obj));
3249 #endif
3250 break;
3252 case 't': /* indicate TEXT or BINARY */
3253 #ifdef MODE_LINE_BINARY_TEXT
3254 return MODE_LINE_BINARY_TEXT (b);
3255 #else
3256 return "T";
3257 #endif
3259 case 'p':
3261 int pos = marker_position (w->start);
3262 int total = BUF_ZV (b) - BUF_BEGV (b);
3264 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
3266 if (pos <= BUF_BEGV (b))
3267 return "All";
3268 else
3269 return "Bottom";
3271 else if (pos <= BUF_BEGV (b))
3272 return "Top";
3273 else
3275 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
3276 /* We can't normally display a 3-digit number,
3277 so get us a 2-digit number that is close. */
3278 if (total == 100)
3279 total = 99;
3280 sprintf (decode_mode_spec_buf, "%2d%%", total);
3281 return decode_mode_spec_buf;
3285 /* Display percentage of size above the bottom of the screen. */
3286 case 'P':
3288 int toppos = marker_position (w->start);
3289 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
3290 int total = BUF_ZV (b) - BUF_BEGV (b);
3292 if (botpos >= BUF_ZV (b))
3294 if (toppos <= BUF_BEGV (b))
3295 return "All";
3296 else
3297 return "Bottom";
3299 else
3301 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
3302 /* We can't normally display a 3-digit number,
3303 so get us a 2-digit number that is close. */
3304 if (total == 100)
3305 total = 99;
3306 if (toppos <= BUF_BEGV (b))
3307 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
3308 else
3309 sprintf (decode_mode_spec_buf, "%2d%%", total);
3310 return decode_mode_spec_buf;
3314 case '%':
3315 return "%";
3317 case '[':
3319 int i;
3320 char *p;
3322 if (command_loop_level > 5)
3323 return "[[[... ";
3324 p = decode_mode_spec_buf;
3325 for (i = 0; i < command_loop_level; i++)
3326 *p++ = '[';
3327 *p = 0;
3328 return decode_mode_spec_buf;
3331 case ']':
3333 int i;
3334 char *p;
3336 if (command_loop_level > 5)
3337 return " ...]]]";
3338 p = decode_mode_spec_buf;
3339 for (i = 0; i < command_loop_level; i++)
3340 *p++ = ']';
3341 *p = 0;
3342 return decode_mode_spec_buf;
3345 case '-':
3347 register char *p;
3348 register int i;
3350 if (maxwidth < sizeof (lots_of_dashes))
3351 return lots_of_dashes;
3352 else
3354 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3355 *p++ = '-';
3356 *p = '\0';
3358 return decode_mode_spec_buf;
3362 if (STRINGP (obj))
3363 return (char *) XSTRING (obj)->data;
3364 else
3365 return "";
3368 /* Search for COUNT instances of a line boundary, which means either a
3369 newline or (if selective display enabled) a carriage return.
3370 Start at START. If COUNT is negative, search backwards.
3372 If we find COUNT instances, set *SHORTAGE to zero, and return the
3373 position after the COUNTth match. Note that for reverse motion
3374 this is not the same as the usual convention for Emacs motion commands.
3376 If we don't find COUNT instances before reaching the end of the
3377 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3378 the number of line boundaries left unfound, and return the end of the
3379 buffer we bumped up against. */
3381 static int
3382 display_scan_buffer (start, count, shortage)
3383 int *shortage, start;
3384 register int count;
3386 int limit = ((count > 0) ? ZV - 1 : BEGV);
3387 int direction = ((count > 0) ? 1 : -1);
3389 register unsigned char *cursor;
3390 unsigned char *base;
3392 register int ceiling;
3393 register unsigned char *ceiling_addr;
3395 /* If we are not in selective display mode,
3396 check only for newlines. */
3397 if (! (!NILP (current_buffer->selective_display)
3398 && !INTEGERP (current_buffer->selective_display)))
3399 return scan_buffer ('\n', start, 0, count, shortage, 0);
3401 /* The code that follows is like scan_buffer
3402 but checks for either newline or carriage return. */
3404 if (shortage != 0)
3405 *shortage = 0;
3407 if (count > 0)
3408 while (start != limit + 1)
3410 ceiling = BUFFER_CEILING_OF (start);
3411 ceiling = min (limit, ceiling);
3412 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
3413 base = (cursor = &FETCH_CHAR (start));
3414 while (1)
3416 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
3418 if (cursor != ceiling_addr)
3420 if (--count == 0)
3422 immediate_quit = 0;
3423 return (start + cursor - base + 1);
3425 else
3426 if (++cursor == ceiling_addr)
3427 break;
3429 else
3430 break;
3432 start += cursor - base;
3434 else
3436 start--; /* first character we scan */
3437 while (start > limit - 1)
3438 { /* we WILL scan under start */
3439 ceiling = BUFFER_FLOOR_OF (start);
3440 ceiling = max (limit, ceiling);
3441 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
3442 base = (cursor = &FETCH_CHAR (start));
3443 cursor++;
3444 while (1)
3446 while (--cursor != ceiling_addr
3447 && *cursor != '\n' && *cursor != 015)
3449 if (cursor != ceiling_addr)
3451 if (++count == 0)
3453 immediate_quit = 0;
3454 return (start + cursor - base + 1);
3457 else
3458 break;
3460 start += cursor - base;
3464 if (shortage != 0)
3465 *shortage = count * direction;
3466 return (start + ((direction == 1 ? 0 : 1)));
3469 /* Count up to N lines starting from FROM.
3470 But don't go beyond LIMIT.
3471 Return the number of lines thus found (always positive).
3472 Store the position after what was found into *POS_PTR. */
3474 static int
3475 display_count_lines (from, limit, n, pos_ptr)
3476 int from, limit, n;
3477 int *pos_ptr;
3479 int oldbegv = BEGV;
3480 int oldzv = ZV;
3481 int shortage = 0;
3483 if (limit < from)
3484 BEGV = limit;
3485 else
3486 ZV = limit;
3488 *pos_ptr = display_scan_buffer (from, n, &shortage);
3490 ZV = oldzv;
3491 BEGV = oldbegv;
3493 if (n < 0)
3494 /* When scanning backwards, scan_buffer stops *after* the last newline
3495 it finds, but does count it. Compensate for that. */
3496 return - n - shortage - (*pos_ptr != limit);
3497 return n - shortage;
3500 /* Display STRING on one line of window W, starting at HPOS.
3501 Display at position VPOS. Caller should have done get_display_line.
3502 If VPOS == -1, display it as the current frame's title.
3503 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
3505 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
3507 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
3508 MAXCOL is the last column ok to end at. Truncate here.
3509 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
3510 Both count from the left edge of the frame, as does HPOS.
3511 The right edge of W is an implicit maximum.
3512 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
3514 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
3515 at the place where the current window ends in this line
3516 and not display anything beyond there. Otherwise, only MAXCOL
3517 controls where to stop output.
3519 Returns ending hpos. */
3521 static int
3522 display_string (w, vpos, string, length, hpos, truncate,
3523 obey_window_width, mincol, maxcol)
3524 struct window *w;
3525 unsigned char *string;
3526 int length;
3527 int vpos, hpos;
3528 GLYPH truncate;
3529 int obey_window_width;
3530 int mincol, maxcol;
3532 register int c;
3533 register GLYPH *p1;
3534 int hscroll = XINT (w->hscroll);
3535 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
3536 register GLYPH *start;
3537 register GLYPH *end;
3538 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3539 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
3540 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
3541 int window_width = XFASTINT (w->width);
3543 /* Use the standard display table, not the window's display table.
3544 We don't want the mode line in rot13. */
3545 register struct Lisp_Vector *dp = 0;
3546 int i;
3548 if (VECTORP (Vstandard_display_table)
3549 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
3550 dp = XVECTOR (Vstandard_display_table);
3552 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
3554 p1 = p1start;
3555 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
3557 if (obey_window_width)
3559 end = start + window_width - (truncate != 0);
3561 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
3563 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3565 int i;
3567 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3568 *end-- = ' ';
3570 else
3571 *end-- = '|';
3575 if (! obey_window_width
3576 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
3577 end = desired_glyphs->glyphs[vpos] + maxcol;
3579 /* Store 0 in charstart for these columns. */
3580 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
3581 desired_glyphs->charstarts[vpos][i] = 0;
3583 if (maxcol >= 0 && mincol > maxcol)
3584 mincol = maxcol;
3586 while (p1 < end)
3588 if (length == 0)
3589 break;
3590 c = *string++;
3591 /* Specified length. */
3592 if (length >= 0)
3593 length--;
3594 /* Unspecified length (null-terminated string). */
3595 else if (c == 0)
3596 break;
3598 if (c >= 040 && c < 0177
3599 && (dp == 0 || !VECTORP (DISP_CHAR_VECTOR (dp, c))))
3601 if (p1 >= start)
3602 *p1 = c;
3603 p1++;
3605 else if (c == '\t')
3609 if (p1 >= start && p1 < end)
3610 *p1 = SPACEGLYPH;
3611 p1++;
3613 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
3615 else if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3617 p1 = copy_part_of_rope (f, p1, start,
3618 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3619 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3622 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
3624 if (p1 >= start)
3625 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
3626 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3628 p1++;
3629 if (p1 >= start && p1 < end)
3630 *p1 = c ^ 0100;
3631 p1++;
3633 else
3635 if (p1 >= start)
3636 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
3637 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3639 p1++;
3640 if (p1 >= start && p1 < end)
3641 *p1 = (c >> 6) + '0';
3642 p1++;
3643 if (p1 >= start && p1 < end)
3644 *p1 = (7 & (c >> 3)) + '0';
3645 p1++;
3646 if (p1 >= start && p1 < end)
3647 *p1 = (7 & c) + '0';
3648 p1++;
3652 if (c && length > 0)
3654 p1 = end;
3655 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
3657 else if (mincol >= 0)
3659 end = desired_glyphs->glyphs[vpos] + mincol;
3660 while (p1 < end)
3661 *p1++ = SPACEGLYPH;
3665 register int len = p1 - desired_glyphs->glyphs[vpos];
3667 if (len > desired_glyphs->used[vpos])
3668 desired_glyphs->used[vpos] = len;
3669 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3671 return len;
3675 void
3676 syms_of_xdisp ()
3678 staticpro (&Qmenu_bar_update_hook);
3679 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
3681 staticpro (&last_arrow_position);
3682 staticpro (&last_arrow_string);
3683 last_arrow_position = Qnil;
3684 last_arrow_string = Qnil;
3686 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
3687 "String (or mode line construct) included (normally) in `mode-line-format'.");
3688 Vglobal_mode_string = Qnil;
3690 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
3691 "Marker for where to display an arrow on top of the buffer text.\n\
3692 This must be the beginning of a line in order to work.\n\
3693 See also `overlay-arrow-string'.");
3694 Voverlay_arrow_position = Qnil;
3696 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
3697 "String to display as an arrow. See also `overlay-arrow-position'.");
3698 Voverlay_arrow_string = Qnil;
3700 DEFVAR_INT ("scroll-step", &scroll_step,
3701 "*The number of lines to try scrolling a window by when point moves out.\n\
3702 If that fails to bring point back on frame, point is centered instead.\n\
3703 If this is zero, point is always centered after it moves off frame.");
3705 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
3707 DEFVAR_BOOL ("truncate-partial-width-windows",
3708 &truncate_partial_width_windows,
3709 "*Non-nil means truncate lines in all windows less than full frame wide.");
3710 truncate_partial_width_windows = 1;
3712 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
3713 "*Non-nil means use inverse video for the mode line.");
3714 mode_line_inverse_video = 1;
3716 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
3717 "*Maximum buffer size for which line number should be displayed.");
3718 line_number_display_limit = 1000000;
3720 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
3721 "*Non-nil means highlight region even in nonselected windows.");
3722 highlight_nonselected_windows = 1;
3724 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
3725 "Non-nil means more than one frame is in use, not counting minibuffer frames.\n\
3726 Not guaranteed to be accurate except while parsing frame-title-format.");
3728 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
3729 "Template for displaying the titlebar of visible frames.\n\
3730 \(Assuming the window manager supports this feature.)\n\
3731 This variable has the same structure as `mode-line-format' (which see),\n\
3732 and is used only on frames for which no explicit name has been set\n\
3733 \(see `modify-frame-parameters').");
3734 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
3735 "Template for displaying the titlebar of an iconified frame.\n\
3736 \(Assuming the window manager supports this feature.)\n\
3737 This variable has the same structure as `mode-line-format' (which see),\n\
3738 and is used only on frames for which no explicit name has been set\n\
3739 \(see `modify-frame-parameters').");
3740 Vicon_title_format
3741 = Vframe_title_format
3742 = Fcons (intern ("multiple-frames"),
3743 Fcons (build_string ("%b"),
3744 Fcons (Fcons (build_string (""),
3745 Fcons (intern ("invocation-name"),
3746 Fcons (build_string ("@"),
3747 Fcons (intern ("system-name"),
3748 Qnil)))),
3749 Qnil)));
3751 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
3752 "Maximum number of lines to keep in the message log buffer.\n\
3753 If nil, disable message logging. If t, log messages but don't truncate\n\
3754 the buffer when it becomes large.");
3755 XSETFASTINT (Vmessage_log_max, 50);
3758 /* initialize the window system */
3759 init_xdisp ()
3761 Lisp_Object root_window;
3762 #ifndef COMPILER_REGISTER_BUG
3763 register
3764 #endif /* COMPILER_REGISTER_BUG */
3765 struct window *mini_w;
3767 this_line_bufpos = 0;
3769 mini_w = XWINDOW (minibuf_window);
3770 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
3772 echo_area_glyphs = 0;
3773 previous_echo_glyphs = 0;
3775 if (!noninteractive)
3777 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
3778 XSETFASTINT (XWINDOW (root_window)->top, 0);
3779 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
3780 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
3781 set_window_height (minibuf_window, 1, 0);
3783 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
3784 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));