(imenu--cleanup): Set alist to its default just once, at the beginning.
[emacs.git] / src / xdisp.c
blobe800c42d754a8f2398319588bb6105affb92d9ff
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 static 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 /* List of functions to call when a window's size changes. These
111 functions get one arg, a frame on which one or more windows' sizes
112 have changed. */
113 static Lisp_Object Vwindow_size_change_functions;
115 /* Values of those variables at last redisplay. */
116 static Lisp_Object last_arrow_position, last_arrow_string;
118 Lisp_Object Qmenu_bar_update_hook;
120 /* Nonzero if overlay arrow has been displayed once in this window. */
121 static int overlay_arrow_seen;
123 /* Nonzero means highlight the region even in nonselected windows. */
124 static int highlight_nonselected_windows;
126 /* If cursor motion alone moves point off frame,
127 Try scrolling this many lines up or down if that will bring it back. */
128 int scroll_step;
130 /* Nonzero if try_window_id has made blank lines at window bottom
131 since the last redisplay that paused */
132 static int blank_end_of_window;
134 /* Number of windows showing the buffer of the selected window
135 (or another buffer with the same base buffer).
136 keyboard.c refers to this. */
137 int buffer_shared;
139 /* display_text_line sets these to the frame position (origin 0) of point,
140 whether the window is selected or not.
141 Set one to -1 first to determine whether point was found afterwards. */
143 static int cursor_vpos;
144 static int cursor_hpos;
146 int debug_end_pos;
148 /* Nonzero means display mode line highlighted */
149 int mode_line_inverse_video;
151 static int message_log_check_duplicate ();
152 static void echo_area_display ();
153 void mark_window_display_accurate ();
154 static void redisplay_windows ();
155 static void redisplay_window ();
156 static void update_menu_bars ();
157 static void update_menu_bar ();
158 static void try_window ();
159 static int try_window_id ();
160 static struct position *display_text_line ();
161 static void display_mode_line ();
162 static int display_mode_element ();
163 static char *fmodetrunc ();
164 static char *decode_mode_spec ();
165 static int display_string ();
166 static void display_menu_bar ();
167 static int display_count_lines ();
169 /* Prompt to display in front of the minibuffer contents */
170 Lisp_Object minibuf_prompt;
172 /* Width in columns of current minibuffer prompt. */
173 int minibuf_prompt_width;
175 /* Message to display instead of minibuffer contents
176 This is what the functions error and message make,
177 and command echoing uses it as well.
178 It overrides the minibuf_prompt as well as the buffer. */
179 char *echo_area_glyphs;
181 /* This is the length of the message in echo_area_glyphs. */
182 int echo_area_glyphs_length;
184 /* true iff we should redraw the mode lines on the next redisplay */
185 int update_mode_lines;
187 /* Smallest number of characters before the gap
188 at any time since last redisplay that finished.
189 Valid for current buffer when try_window_id can be called. */
190 int beg_unchanged;
192 /* Smallest number of characters after the gap
193 at any time since last redisplay that finished.
194 Valid for current buffer when try_window_id can be called. */
195 int end_unchanged;
197 /* MODIFF as of last redisplay that finished;
198 if it matches MODIFF, beg_unchanged and end_unchanged
199 contain no useful information */
200 int unchanged_modified;
202 /* Nonzero if head_clip or tail_clip of current buffer has changed
203 since last redisplay that finished */
204 int clip_changed;
206 /* Nonzero if window sizes or contents have changed
207 since last redisplay that finished */
208 int windows_or_buffers_changed;
210 /* Nonzero after display_mode_line if %l was used
211 and it displayed a line number. */
212 int line_number_displayed;
214 /* Maximum buffer size for which to display line numbers. */
215 int line_number_display_limit;
217 /* Number of lines to keep in the message log buffer.
218 t means infinite. nil means don't log at all. */
219 Lisp_Object Vmessage_log_max;
221 void
222 message_log_maybe_newline ()
224 if (message_log_need_newline)
225 message_dolog ("", 0, 1);
229 /* Add a string to the message log, optionally terminated with a newline.
230 This function calls low-level routines in order to bypass text property
231 hooks, etc. which might not be safe to run. */
233 void
234 message_dolog (m, len, nlflag)
235 char *m;
236 int len, nlflag;
238 if (!NILP (Vmessage_log_max))
240 struct buffer *oldbuf;
241 int oldpoint, oldbegv, oldzv;
243 oldbuf = current_buffer;
244 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
245 oldpoint = PT;
246 oldbegv = BEGV;
247 oldzv = ZV;
248 BEGV = BEG;
249 ZV = Z;
250 if (oldpoint == Z)
251 oldpoint += len + nlflag;
252 if (oldzv == Z)
253 oldzv += len + nlflag;
254 TEMP_SET_PT (Z);
255 if (len)
256 insert_1 (m, len, 1, 0);
257 if (nlflag)
259 int this_bol, prev_bol, dup;
260 insert_1 ("\n", 1, 1, 0);
262 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
263 if (this_bol > BEG)
265 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
266 dup = message_log_check_duplicate (prev_bol, this_bol);
267 if (dup)
269 if (oldpoint > prev_bol)
270 oldpoint -= min (this_bol, oldpoint) - prev_bol;
271 if (oldbegv > prev_bol)
272 oldbegv -= min (this_bol, oldbegv) - prev_bol;
273 if (oldzv > prev_bol)
274 oldzv -= min (this_bol, oldzv) - prev_bol;
275 del_range_1 (prev_bol, this_bol, 0);
276 if (dup > 1)
278 char dupstr[40];
279 int duplen;
281 /* If you change this format, don't forget to also
282 change message_log_check_duplicate. */
283 sprintf (dupstr, " [%d times]", dup);
284 duplen = strlen (dupstr);
285 TEMP_SET_PT (Z-1);
286 if (oldpoint == Z)
287 oldpoint += duplen;
288 if (oldzv == Z)
289 oldzv += duplen;
290 insert_1 (dupstr, duplen, 1, 0);
295 if (NATNUMP (Vmessage_log_max))
297 int pos = scan_buffer ('\n', Z, 0,
298 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
299 oldpoint -= min (pos, oldpoint) - BEG;
300 oldbegv -= min (pos, oldbegv) - BEG;
301 oldzv -= min (pos, oldzv) - BEG;
302 del_range_1 (BEG, pos, 0);
305 BEGV = oldbegv;
306 ZV = oldzv;
307 TEMP_SET_PT (oldpoint);
308 set_buffer_internal (oldbuf);
309 message_log_need_newline = !nlflag;
314 /* We are at the end of the buffer after just having inserted a newline.
315 (Note: We depend on the fact we won't be crossing the gap.)
316 Check to see if the most recent message looks a lot like the previous one.
317 Return 0 if different, 1 if the new one should just replace it, or a
318 value N > 1 if we should also append " [N times]". */
319 static int
320 message_log_check_duplicate (prev_bol, this_bol)
321 int prev_bol, this_bol;
323 int i;
324 int len = Z - 1 - this_bol;
325 int seen_dots = 0;
326 char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
327 char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
329 for (i = 0; i < len; i++)
331 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
332 && p1[i] != '\n')
333 seen_dots = 1;
334 if (p1[i] != p2[i])
335 return seen_dots;
337 p1 += len;
338 if (*p1 == '\n')
339 return 2;
340 if (*p1++ == ' ' && *p1++ == '[')
342 int n = 0;
343 while (*p1 >= '0' && *p1 <= '9')
344 n = n * 10 + *p1++ - '0';
345 if (strncmp (p1, " times]\n", 8) == 0)
346 return n+1;
348 return 0;
351 /* Display an echo area message M with a specified length of LEN chars.
352 The string may include null characters. If m is 0, clear out any
353 existing message, and let the minibuffer text show through.
354 Do not pass text that is stored in a Lisp string. */
356 void
357 message2 (m, len)
358 char *m;
359 int len;
361 /* First flush out any partial line written with print. */
362 message_log_maybe_newline ();
363 if (m)
364 message_dolog (m, len, 1);
365 message2_nolog (m, len);
369 /* The non-logging part of that function. */
371 void
372 message2_nolog (m, len)
373 char *m;
374 int len;
376 if (noninteractive)
378 if (noninteractive_need_newline)
379 putc ('\n', stderr);
380 noninteractive_need_newline = 0;
381 fwrite (m, len, 1, stderr);
382 if (cursor_in_echo_area == 0)
383 fprintf (stderr, "\n");
384 fflush (stderr);
386 /* A null message buffer means that the frame hasn't really been
387 initialized yet. Error messages get reported properly by
388 cmd_error, so this must be just an informative message; toss it. */
389 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
391 #ifdef MULTI_FRAME
392 Lisp_Object minibuf_frame;
394 choose_minibuf_frame ();
395 minibuf_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
396 FRAME_SAMPLE_VISIBILITY (XFRAME (minibuf_frame));
397 if (FRAME_VISIBLE_P (selected_frame)
398 && ! FRAME_VISIBLE_P (XFRAME (minibuf_frame)))
399 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (minibuf_window)));
400 #endif
402 if (m)
404 echo_area_glyphs = m;
405 echo_area_glyphs_length = len;
407 else
408 echo_area_glyphs = previous_echo_glyphs = 0;
410 do_pending_window_change ();
411 echo_area_display ();
412 update_frame (XFRAME (XWINDOW (minibuf_window)->frame), 1, 1);
413 do_pending_window_change ();
414 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
415 (*frame_up_to_date_hook) (XFRAME (XWINDOW (minibuf_window)->frame));
419 void
420 message1 (m)
421 char *m;
423 message2 (m, (m ? strlen (m) : 0));
426 void
427 message1_nolog (m)
428 char *m;
430 message2_nolog (m, (m ? strlen (m) : 0));
433 /* Truncate what will be displayed in the echo area
434 the next time we display it--but don't redisplay it now. */
436 void
437 truncate_echo_area (len)
438 int len;
440 /* A null message buffer means that the frame hasn't really been
441 initialized yet. Error messages get reported properly by
442 cmd_error, so this must be just an informative message; toss it. */
443 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
444 echo_area_glyphs_length = len;
447 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
448 zero if being used by message. */
449 int message_buf_print;
451 /* Dump an informative message to the minibuf. If m is 0, clear out
452 any existing message, and let the minibuffer text show through. */
453 /* VARARGS 1 */
454 void
455 message (m, a1, a2, a3)
456 char *m;
457 EMACS_INT a1, a2, a3;
459 if (noninteractive)
461 if (m)
463 if (noninteractive_need_newline)
464 putc ('\n', stderr);
465 noninteractive_need_newline = 0;
466 fprintf (stderr, m, a1, a2, a3);
467 if (cursor_in_echo_area == 0)
468 fprintf (stderr, "\n");
469 fflush (stderr);
472 else if (INTERACTIVE)
474 /* The frame whose minibuffer we're going to display the message on.
475 It may be larger than the selected frame, so we need
476 to use its buffer, not the selected frame's buffer. */
477 FRAME_PTR echo_frame;
478 #ifdef MULTI_FRAME
479 choose_minibuf_frame ();
480 echo_frame = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
481 #else
482 echo_frame = selected_frame;
483 #endif
485 /* A null message buffer means that the frame hasn't really been
486 initialized yet. Error messages get reported properly by
487 cmd_error, so this must be just an informative message; toss it. */
488 if (FRAME_MESSAGE_BUF (echo_frame))
490 if (m)
492 int len;
493 #ifdef NO_ARG_ARRAY
494 EMACS_INT a[3];
495 a[0] = a1;
496 a[1] = a2;
497 a[2] = a3;
499 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
500 FRAME_WIDTH (echo_frame), m, 0, 3, a);
501 #else
502 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
503 FRAME_WIDTH (echo_frame), m, 0, 3, &a1);
504 #endif /* NO_ARG_ARRAY */
506 message2 (FRAME_MESSAGE_BUF (echo_frame), len);
508 else
509 message1 (0);
511 /* Print should start at the beginning of the message
512 buffer next time. */
513 message_buf_print = 0;
518 void
519 update_echo_area ()
521 message2 (echo_area_glyphs, echo_area_glyphs_length);
524 static void
525 echo_area_display ()
527 register int vpos;
528 FRAME_PTR f;
530 #ifdef MULTI_FRAME
531 choose_minibuf_frame ();
532 #endif
534 f = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
536 if (! FRAME_VISIBLE_P (f))
537 return;
539 if (frame_garbaged)
541 redraw_garbaged_frames ();
542 frame_garbaged = 0;
545 if (echo_area_glyphs || minibuf_level == 0)
547 vpos = XFASTINT (XWINDOW (minibuf_window)->top);
548 get_display_line (f, vpos, 0);
549 display_string (XWINDOW (minibuf_window), vpos,
550 echo_area_glyphs ? echo_area_glyphs : "",
551 echo_area_glyphs ? echo_area_glyphs_length : -1,
552 0, 0, 0, 0, FRAME_WIDTH (f));
554 /* If desired cursor location is on this line, put it at end of text */
555 if (FRAME_CURSOR_Y (f) == vpos)
556 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
558 /* Fill the rest of the minibuffer window with blank lines. */
560 int i;
562 for (i = vpos + 1;
563 i < vpos + XFASTINT (XWINDOW (minibuf_window)->height); i++)
565 get_display_line (f, i, 0);
566 display_string (XWINDOW (minibuf_window), vpos,
567 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f));
571 else if (!EQ (minibuf_window, selected_window))
572 windows_or_buffers_changed++;
574 if (EQ (minibuf_window, selected_window))
575 this_line_bufpos = 0;
577 previous_echo_glyphs = echo_area_glyphs;
580 #ifdef HAVE_X_WINDOWS
581 static char frame_title_buf[512];
582 static char *frame_title_ptr;
584 static int
585 store_frame_title (str, mincol, maxcol)
586 char *str;
587 int mincol, maxcol;
589 char *limit;
590 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
591 maxcol = sizeof (frame_title_buf);
592 limit = &frame_title_buf[maxcol];
593 while (*str != '\0' && frame_title_ptr < limit)
594 *frame_title_ptr++ = *str++;
595 while (frame_title_ptr < &frame_title_buf[mincol])
596 *frame_title_ptr++ = ' ';
597 return frame_title_ptr - frame_title_buf;
600 static void
601 x_consider_frame_title (frame)
602 Lisp_Object frame;
604 Lisp_Object fmt;
605 struct buffer *obuf;
606 int len;
607 FRAME_PTR f = XFRAME (frame);
609 if (!FRAME_X_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name)
610 return;
611 multiple_frames = !EQ (Fnext_frame (frame, Qnil), frame);
612 obuf = current_buffer;
613 Fset_buffer (XWINDOW (f->selected_window)->buffer);
614 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
615 frame_title_ptr = frame_title_buf;
616 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
617 0, sizeof (frame_title_buf), fmt);
618 frame_title_ptr = 0;
619 set_buffer_internal (obuf);
620 /* Set the name only if it's changed. This avoids consing
621 in the common case where it hasn't. (If it turns out that we've
622 already wasted too much time by walking through the list with
623 display_mode_element, then we might need to optimize at a higher
624 level than this.) */
625 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
626 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
627 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
629 #else
630 #define frame_title_ptr ((char *)0)
631 #define store_frame_title(str, mincol, maxcol) 0
632 #endif
634 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
635 This can't be done in `redisplay' itself because it can call eval. */
637 void
638 prepare_menu_bars ()
640 register struct window *w = XWINDOW (selected_window);
641 int all_windows;
642 struct gcpro gcpro1, gcpro2;
644 if (noninteractive)
645 return;
647 /* Set the visible flags for all frames.
648 Do this before checking for resized or garbaged frames; they want
649 to know if their frames are visible.
650 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
652 Lisp_Object tail, frame;
654 FOR_EACH_FRAME (tail, frame)
655 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
658 /* Notice any pending interrupt request to change frame size. */
659 do_pending_window_change ();
661 if (frame_garbaged)
663 redraw_garbaged_frames ();
664 frame_garbaged = 0;
667 all_windows = (update_mode_lines || buffer_shared > 1
668 || clip_changed || windows_or_buffers_changed);
670 #ifdef HAVE_X_WINDOWS
671 if (windows_or_buffers_changed)
673 Lisp_Object tail, frame;
675 FOR_EACH_FRAME (tail, frame)
676 if (FRAME_VISIBLE_P (XFRAME (frame))
677 || FRAME_ICONIFIED_P (XFRAME (frame)))
678 x_consider_frame_title (frame);
680 #endif
682 /* Update the menu bar item lists, if appropriate.
683 This has to be done before any actual redisplay
684 or generation of display lines. */
685 if (all_windows)
687 Lisp_Object tail, frame;
689 FOR_EACH_FRAME (tail, frame)
691 /* If a window on this frame changed size,
692 report that to the user and clear the size-change flag. */
693 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
695 Lisp_Object functions;
696 functions = Vwindow_size_change_functions;
697 GCPRO2 (tail, functions);
698 while (CONSP (functions))
700 call1 (XCONS (functions)->car, frame);
701 functions = XCONS (functions)->cdr;
703 UNGCPRO;
704 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
706 GCPRO1 (tail);
707 update_menu_bar (XFRAME (frame));
708 UNGCPRO;
711 else
712 update_menu_bar (selected_frame);
715 /* Do a frame update, taking possible shortcuts into account.
716 This is the main external entry point for redisplay.
718 If the last redisplay displayed an echo area message and that
719 message is no longer requested, we clear the echo area
720 or bring back the minibuffer if that is in use.
722 Do not call eval from within this function.
723 Calls to eval after the call to echo_area_display would confuse
724 the display_line mechanism and would cause a crash.
725 Calls to eval before that point will work most of the time,
726 but can still lose, because this function
727 can be called from signal handlers; with alarms set up;
728 or with synchronous processes running.
730 See Fcall_process; if you called it from here, it could be
731 entered recursively. */
733 static int do_verify_charstarts;
735 /* Counter is used to clear the face cache
736 no more than once ever 1000 redisplays. */
737 static int clear_face_cache_count;
739 void
740 redisplay ()
742 register struct window *w = XWINDOW (selected_window);
743 register int pause;
744 int must_finish = 0;
745 int all_windows;
746 register int tlbufpos, tlendpos;
747 struct position pos;
748 extern int input_pending;
750 if (noninteractive)
751 return;
753 /* Set the visible flags for all frames.
754 Do this before checking for resized or garbaged frames; they want
755 to know if their frames are visible.
756 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
758 Lisp_Object tail, frame;
760 FOR_EACH_FRAME (tail, frame)
761 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
764 /* Notice any pending interrupt request to change frame size. */
765 do_pending_window_change ();
767 if (frame_garbaged)
769 redraw_garbaged_frames ();
770 frame_garbaged = 0;
773 if (clip_changed || windows_or_buffers_changed
774 || (!NILP (w->column_number_displayed)
775 && XFASTINT (w->column_number_displayed) != current_column ()))
776 update_mode_lines++;
778 /* Detect case that we need to write a star in the mode line. */
779 if (XFASTINT (w->last_modified) < MODIFF
780 && XFASTINT (w->last_modified) <= SAVE_MODIFF)
782 w->update_mode_line = Qt;
783 if (buffer_shared > 1)
784 update_mode_lines++;
787 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
789 all_windows = update_mode_lines || buffer_shared > 1;
791 /* If specs for an arrow have changed, do thorough redisplay
792 to ensure we remove any arrow that should no longer exist. */
793 if (! EQ (Voverlay_arrow_position, last_arrow_position)
794 || ! EQ (Voverlay_arrow_string, last_arrow_string))
795 all_windows = 1, clip_changed = 1;
797 /* Normally the message* functions will have already displayed and
798 updated the echo area, but the frame may have been trashed, or
799 the update may have been preempted, so display the echo area
800 again here. */
801 if (echo_area_glyphs || previous_echo_glyphs)
803 echo_area_display ();
804 must_finish = 1;
807 /* If showing region, and mark has changed, must redisplay whole window. */
808 if (((!NILP (Vtransient_mark_mode)
809 && !NILP (XBUFFER (w->buffer)->mark_active))
810 != !NILP (w->region_showing))
811 || (!NILP (w->region_showing)
812 && !EQ (w->region_showing,
813 Fmarker_position (XBUFFER (w->buffer)->mark))))
814 this_line_bufpos = -1;
816 tlbufpos = this_line_bufpos;
817 tlendpos = this_line_endpos;
818 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
819 && FRAME_VISIBLE_P (XFRAME (w->frame))
820 /* Make sure recorded data applies to current buffer, etc */
821 && this_line_buffer == current_buffer
822 && current_buffer == XBUFFER (w->buffer)
823 && NILP (w->force_start)
824 /* Point must be on the line that we have info recorded about */
825 && PT >= tlbufpos
826 && PT <= Z - tlendpos
827 /* All text outside that line, including its final newline,
828 must be unchanged */
829 && (XFASTINT (w->last_modified) >= MODIFF
830 || (beg_unchanged >= tlbufpos - 1
831 && GPT >= tlbufpos
832 /* If selective display, can't optimize
833 if the changes start at the beginning of the line. */
834 && ((INTEGERP (current_buffer->selective_display)
835 && XINT (current_buffer->selective_display) > 0
836 ? (beg_unchanged >= tlbufpos
837 && GPT > tlbufpos)
838 : 1))
839 && end_unchanged >= tlendpos
840 && Z - GPT >= tlendpos)))
842 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
843 && (tlbufpos == ZV
844 || FETCH_CHAR (tlbufpos) == '\n'))
845 /* Former continuation line has disappeared by becoming empty */
846 goto cancel;
847 else if (XFASTINT (w->last_modified) < MODIFF
848 || MINI_WINDOW_P (w))
850 cursor_vpos = -1;
851 overlay_arrow_seen = 0;
852 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
853 pos_tab_offset (w, tlbufpos));
854 /* If line contains point, is not continued,
855 and ends at same distance from eob as before, we win */
856 if (cursor_vpos >= 0 && this_line_bufpos
857 && this_line_endpos == tlendpos)
859 /* If this is not the window's last line,
860 we must adjust the charstarts of the lines below. */
861 if (this_line_vpos + 1
862 < XFASTINT (w->top) + window_internal_height (w))
864 int left = XFASTINT (w->left);
865 int *charstart_next_line
866 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
867 int i;
868 int adjust;
870 if (Z - tlendpos == ZV)
871 /* This line ends at end of (accessible part of) buffer.
872 There is no newline to count. */
873 adjust = Z - tlendpos - charstart_next_line[left];
874 else
875 /* This line ends in a newline.
876 Must take account of the newline and the rest of the
877 text that follows. */
878 adjust = Z - tlendpos + 1 - charstart_next_line[left];
880 adjust_window_charstarts (w, this_line_vpos, adjust);
883 if (XFASTINT (w->width) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w))))
884 preserve_other_columns (w);
885 goto update;
887 else
888 goto cancel;
890 else if (PT == XFASTINT (w->last_point))
892 if (!must_finish)
894 do_pending_window_change ();
895 return;
897 goto update;
899 /* If highlighting the region, we can't just move the cursor. */
900 else if (! (!NILP (Vtransient_mark_mode)
901 && !NILP (current_buffer->mark_active))
902 && NILP (w->region_showing))
904 pos = *compute_motion (tlbufpos, 0,
905 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
906 PT, 2, - (1 << (SHORTBITS - 1)),
907 window_internal_width (w) - 1,
908 XINT (w->hscroll),
909 pos_tab_offset (w, tlbufpos), w);
910 if (pos.vpos < 1)
912 FRAME_CURSOR_X (selected_frame)
913 = XFASTINT (w->left) + max (pos.hpos, 0);
914 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
915 goto update;
917 else
918 goto cancel;
920 cancel:
921 /* Text changed drastically or point moved off of line */
922 cancel_line (this_line_vpos, selected_frame);
925 this_line_bufpos = 0;
926 all_windows |= buffer_shared > 1;
928 clear_face_cache_count++;
930 if (all_windows)
932 Lisp_Object tail, frame;
934 #ifdef HAVE_FACES
935 /* Clear the face cache, only when we do a full redisplay
936 and not too often either. */
937 if (clear_face_cache_count > 1000)
939 clear_face_cache ();
940 clear_face_cache_count = 0;
942 #endif
944 /* Recompute # windows showing selected buffer.
945 This will be incremented each time such a window is displayed. */
946 buffer_shared = 0;
948 FOR_EACH_FRAME (tail, frame)
950 FRAME_PTR f = XFRAME (frame);
951 if (! FRAME_TERMCAP_P (f) || f == selected_frame)
954 /* Mark all the scroll bars to be removed; we'll redeem the ones
955 we want when we redisplay their windows. */
956 if (condemn_scroll_bars_hook)
957 (*condemn_scroll_bars_hook) (f);
959 if (FRAME_VISIBLE_P (f))
960 redisplay_windows (FRAME_ROOT_WINDOW (f));
962 /* Any scroll bars which redisplay_windows should have nuked
963 should now go away. */
964 if (judge_scroll_bars_hook)
965 (*judge_scroll_bars_hook) (f);
969 else if (FRAME_VISIBLE_P (selected_frame))
971 redisplay_window (selected_window, 1);
972 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
973 preserve_other_columns (w);
976 update:
977 /* Prevent various kinds of signals during display update.
978 stdio is not robust about handling signals,
979 which can cause an apparent I/O error. */
980 if (interrupt_input)
981 unrequest_sigio ();
982 stop_polling ();
984 #ifdef MULTI_FRAME
985 if (all_windows)
987 Lisp_Object tail;
989 pause = 0;
991 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
993 FRAME_PTR f;
995 if (!FRAMEP (XCONS (tail)->car))
996 continue;
998 f = XFRAME (XCONS (tail)->car);
999 if (FRAME_VISIBLE_P (f))
1001 pause |= update_frame (f, 0, 0);
1002 if (!pause)
1004 mark_window_display_accurate (f->root_window, 1);
1005 if (frame_up_to_date_hook != 0)
1006 (*frame_up_to_date_hook) (f);
1011 else
1012 #endif /* MULTI_FRAME */
1014 if (FRAME_VISIBLE_P (selected_frame))
1015 pause = update_frame (selected_frame, 0, 0);
1017 /* We may have called echo_area_display at the top of this
1018 function. If the echo area is on another frame, that may
1019 have put text on a frame other than the selected one, so the
1020 above call to update_frame would not have caught it. Catch
1021 it here. */
1023 FRAME_PTR mini_frame
1024 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
1026 if (mini_frame != selected_frame)
1027 pause |= update_frame (mini_frame, 0, 0);
1031 /* If frame does not match, prevent doing single-line-update next time.
1032 Also, don't forget to check every line to update the arrow. */
1033 if (pause)
1035 this_line_bufpos = 0;
1036 if (!NILP (last_arrow_position))
1038 last_arrow_position = Qt;
1039 last_arrow_string = Qt;
1041 /* If we pause after scrolling, some lines in current_frame
1042 may be null, so preserve_other_columns won't be able to
1043 preserve all the vertical-bar separators. So, avoid using it
1044 in that case. */
1045 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
1046 update_mode_lines = 1;
1049 /* Now text on frame agrees with windows, so
1050 put info into the windows for partial redisplay to follow */
1052 if (!pause)
1054 register struct buffer *b = XBUFFER (w->buffer);
1056 blank_end_of_window = 0;
1057 clip_changed = 0;
1058 unchanged_modified = BUF_MODIFF (b);
1059 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1060 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1062 XSETFASTINT (w->last_point, BUF_PT (b));
1063 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1064 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1066 if (all_windows)
1067 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1068 else
1070 w->update_mode_line = Qnil;
1071 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1072 w->window_end_valid = w->buffer;
1073 last_arrow_position = Voverlay_arrow_position;
1074 last_arrow_string = Voverlay_arrow_string;
1075 if (do_verify_charstarts)
1076 verify_charstarts (w);
1077 if (frame_up_to_date_hook != 0)
1078 (*frame_up_to_date_hook) (selected_frame);
1080 update_mode_lines = 0;
1081 windows_or_buffers_changed = 0;
1084 /* Start SIGIO interrupts coming again.
1085 Having them off during the code above
1086 makes it less likely one will discard output,
1087 but not impossible, since there might be stuff
1088 in the system buffer here.
1089 But it is much hairier to try to do anything about that. */
1091 if (interrupt_input)
1092 request_sigio ();
1093 start_polling ();
1095 /* Change frame size now if a change is pending. */
1096 do_pending_window_change ();
1098 /* If we just did a pending size change, redisplay again
1099 for the new size. */
1100 if (windows_or_buffers_changed && !pause)
1101 redisplay ();
1104 /* Redisplay, but leave alone any recent echo area message
1105 unless another message has been requested in its place.
1107 This is useful in situations where you need to redisplay but no
1108 user action has occurred, making it inappropriate for the message
1109 area to be cleared. See tracking_off and
1110 wait_reading_process_input for examples of these situations. */
1112 redisplay_preserve_echo_area ()
1114 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1116 echo_area_glyphs = previous_echo_glyphs;
1117 redisplay ();
1118 echo_area_glyphs = 0;
1120 else
1121 redisplay ();
1124 void
1125 mark_window_display_accurate (window, flag)
1126 Lisp_Object window;
1127 int flag;
1129 register struct window *w;
1131 for (;!NILP (window); window = w->next)
1133 if (!WINDOWP (window)) abort ();
1134 w = XWINDOW (window);
1136 if (!NILP (w->buffer))
1138 XSETFASTINT (w->last_modified,
1139 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1141 /* Record if we are showing a region, so can make sure to
1142 update it fully at next redisplay. */
1143 w->region_showing = (!NILP (Vtransient_mark_mode)
1144 && !NILP (XBUFFER (w->buffer)->mark_active)
1145 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1146 : Qnil);
1149 w->window_end_valid = w->buffer;
1150 w->update_mode_line = Qnil;
1152 if (!NILP (w->vchild))
1153 mark_window_display_accurate (w->vchild, flag);
1154 if (!NILP (w->hchild))
1155 mark_window_display_accurate (w->hchild, flag);
1158 if (flag)
1160 last_arrow_position = Voverlay_arrow_position;
1161 last_arrow_string = Voverlay_arrow_string;
1163 else
1165 /* t is unequal to any useful value of Voverlay_arrow_... */
1166 last_arrow_position = Qt;
1167 last_arrow_string = Qt;
1171 /* Update the menu bar item list for frame F.
1172 This has to be done before we start to fill in any display lines,
1173 because it can call eval. */
1175 static void
1176 update_menu_bar (f)
1177 FRAME_PTR f;
1179 struct buffer *old = current_buffer;
1180 Lisp_Object window;
1181 register struct window *w;
1182 window = FRAME_SELECTED_WINDOW (f);
1183 w = XWINDOW (window);
1185 if (update_mode_lines)
1186 w->update_mode_line = Qt;
1188 if (
1189 #ifdef USE_X_TOOLKIT
1190 FRAME_EXTERNAL_MENU_BAR (f)
1191 #else
1192 FRAME_MENU_BAR_LINES (f) > 0
1193 #endif
1196 /* If the user has switched buffers or windows, we need to
1197 recompute to reflect the new bindings. But we'll
1198 recompute when update_mode_lines is set too; that means
1199 that people can use force-mode-line-update to request
1200 that the menu bar be recomputed. The adverse effect on
1201 the rest of the redisplay algorithm is about the same as
1202 windows_or_buffers_changed anyway. */
1203 if (windows_or_buffers_changed
1204 || !NILP (w->update_mode_line)
1205 || (XFASTINT (w->last_modified) < MODIFF
1206 && (XFASTINT (w->last_modified)
1207 <= BUF_SAVE_MODIFF (XBUFFER (w->buffer)))))
1209 struct buffer *prev = current_buffer;
1210 call1 (Vrun_hooks, Qmenu_bar_update_hook);
1211 current_buffer = XBUFFER (w->buffer);
1212 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1213 current_buffer = prev;
1214 #ifdef USE_X_TOOLKIT
1215 set_frame_menubar (f, 0);
1216 #endif /* USE_X_TOOLKIT */
1221 int do_id = 1;
1223 /* Redisplay WINDOW and its subwindows and siblings. */
1225 static void
1226 redisplay_windows (window)
1227 Lisp_Object window;
1229 for (; !NILP (window); window = XWINDOW (window)->next)
1230 redisplay_window (window, 0);
1233 /* Redisplay window WINDOW and its subwindows. */
1235 static void
1236 redisplay_window (window, just_this_one)
1237 Lisp_Object window;
1238 int just_this_one;
1240 register struct window *w = XWINDOW (window);
1241 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1242 int height;
1243 register int lpoint = PT;
1244 struct buffer *old = current_buffer;
1245 register int width = window_internal_width (w) - 1;
1246 register int startp;
1247 register int hscroll = XINT (w->hscroll);
1248 struct position pos;
1249 int opoint = PT;
1250 int tem;
1251 int update_mode_line;
1253 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1255 /* If this is a combination window, do its children; that's all. */
1257 if (!NILP (w->vchild))
1259 redisplay_windows (w->vchild);
1260 return;
1262 if (!NILP (w->hchild))
1264 redisplay_windows (w->hchild);
1265 return;
1267 if (NILP (w->buffer))
1268 abort ();
1270 height = window_internal_height (w);
1272 if (MINI_WINDOW_P (w))
1274 if (w == XWINDOW (minibuf_window))
1276 if (echo_area_glyphs)
1277 /* We've already displayed the echo area glyphs, if any. */
1278 goto finish_scroll_bars;
1280 else
1282 /* This is a minibuffer, but it's not the currently active one, so
1283 clear it. */
1284 int vpos = XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top);
1285 int i;
1287 for (i = 0; i < height; i++)
1289 get_display_line (f, vpos + i, 0);
1290 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
1293 goto finish_scroll_bars;
1297 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1299 /* Otherwise set up data on this window; select its buffer and point value */
1301 if (update_mode_line)
1302 set_buffer_internal (XBUFFER (w->buffer));
1303 else
1304 set_buffer_temp (XBUFFER (w->buffer));
1306 opoint = PT;
1308 /* Count number of windows showing the selected buffer.
1309 An indirect buffer counts as its base buffer. */
1311 if (!just_this_one)
1313 struct buffer *current_base, *window_base;
1314 current_base = current_buffer;
1315 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1316 if (current_base->base_buffer)
1317 current_base = current_base->base_buffer;
1318 if (window_base->base_buffer)
1319 window_base = window_base->base_buffer;
1320 if (current_base == window_base)
1321 buffer_shared++;
1324 /* POINT refers normally to the selected window.
1325 For any other window, set up appropriate value. */
1327 if (!EQ (window, selected_window))
1329 int new_pt = marker_position (w->pointm);
1330 if (new_pt < BEGV)
1332 new_pt = BEGV;
1333 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1335 else if (new_pt > (ZV - 1))
1337 new_pt = ZV;
1338 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1340 /* We don't use SET_PT so that the point-motion hooks don't run. */
1341 BUF_PT (current_buffer) = new_pt;
1344 /* If any of the character widths specified in the display table
1345 have changed, invalidate the width run cache. It's true that this
1346 may be a bit late to catch such changes, but the rest of
1347 redisplay goes (non-fatally) haywire when the display table is
1348 changed, so why should we worry about doing any better? */
1349 if (current_buffer->width_run_cache)
1351 struct Lisp_Vector *disptab = buffer_display_table ();
1353 if (! disptab_matches_widthtab (disptab,
1354 XVECTOR (current_buffer->width_table)))
1356 invalidate_region_cache (current_buffer,
1357 current_buffer->width_run_cache,
1358 BEG, Z);
1359 recompute_width_table (current_buffer, disptab);
1363 /* If window-start is screwed up, choose a new one. */
1364 if (XMARKER (w->start)->buffer != current_buffer)
1365 goto recenter;
1367 startp = marker_position (w->start);
1369 /* Handle case where place to start displaying has been specified,
1370 unless the specified location is outside the accessible range. */
1371 if (!NILP (w->force_start))
1373 /* Forget any recorded base line for line number display. */
1374 w->base_line_number = Qnil;
1375 /* Redisplay the mode line. Select the buffer properly for that. */
1376 if (!update_mode_line)
1378 set_buffer_temp (old);
1379 set_buffer_internal (XBUFFER (w->buffer));
1380 update_mode_line = 1;
1381 w->update_mode_line = Qt;
1383 w->force_start = Qnil;
1384 XSETFASTINT (w->last_modified, 0);
1385 if (startp < BEGV) startp = BEGV;
1386 if (startp > ZV) startp = ZV;
1387 try_window (window, startp);
1388 if (cursor_vpos < 0)
1390 /* If point does not appear, move point so it does appear */
1391 pos = *compute_motion (startp, 0,
1392 ((EQ (window, minibuf_window) && startp == 1)
1393 ? minibuf_prompt_width : 0)
1395 (hscroll ? 1 - hscroll : 0),
1396 ZV, height / 2,
1397 - (1 << (SHORTBITS - 1)),
1398 width, hscroll, pos_tab_offset (w, startp), w);
1399 BUF_PT (current_buffer) = pos.bufpos;
1400 if (w != XWINDOW (selected_window))
1401 Fset_marker (w->pointm, make_number (PT), Qnil);
1402 else
1404 if (current_buffer == old)
1405 lpoint = PT;
1406 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1407 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1409 /* If we are highlighting the region,
1410 then we just changed the region, so redisplay to show it. */
1411 if (!NILP (Vtransient_mark_mode)
1412 && !NILP (current_buffer->mark_active))
1414 cancel_my_columns (XWINDOW (window));
1415 try_window (window, startp);
1418 goto done;
1421 /* Handle case where text has not changed, only point,
1422 and it has not moved off the frame */
1424 /* This code is not used for minibuffer for the sake of
1425 the case of redisplaying to replace an echo area message;
1426 since in that case the minibuffer contents per se are usually unchanged.
1427 This code is of no real use in the minibuffer since
1428 the handling of this_line_bufpos, etc.,
1429 in redisplay handles the same cases. */
1431 if (XFASTINT (w->last_modified) >= MODIFF
1432 && PT >= startp && !clip_changed
1433 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
1434 /* Can't use this case if highlighting a region. */
1435 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1436 && NILP (w->region_showing)
1437 /* If end pos is out of date, scroll bar and percentage will be wrong */
1438 && INTEGERP (w->window_end_vpos)
1439 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1440 && !EQ (window, minibuf_window))
1442 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0),
1443 PT, height + 1, 10000, width, hscroll,
1444 pos_tab_offset (w, startp), w);
1446 if (pos.vpos < height)
1448 /* Ok, point is still on frame */
1449 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1451 /* These variables are supposed to be origin 1 */
1452 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1453 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1455 /* This doesn't do the trick, because if a window to the right of
1456 this one must be redisplayed, this does nothing because there
1457 is nothing in DesiredFrame yet, and then the other window is
1458 redisplayed, making likes that are empty in this window's columns.
1459 if (XFASTINT (w->width) != FRAME_WIDTH (f))
1460 preserve_my_columns (w);
1462 goto done;
1464 /* Don't bother trying redisplay with same start;
1465 we already know it will lose */
1467 /* If current starting point was originally the beginning of a line
1468 but no longer is, find a new starting point. */
1469 else if (!NILP (w->start_at_line_beg)
1470 && !(startp <= BEGV
1471 || FETCH_CHAR (startp - 1) == '\n'))
1473 goto recenter;
1475 else if (just_this_one && !MINI_WINDOW_P (w)
1476 && PT >= startp
1477 && XFASTINT (w->last_modified)
1478 /* or else vmotion on first line won't work. */
1479 && ! NILP (w->start_at_line_beg)
1480 && ! EQ (w->window_end_valid, Qnil)
1481 && do_id && !clip_changed
1482 && !blank_end_of_window
1483 && XFASTINT (w->width) == FRAME_WIDTH (f)
1484 /* Can't use this case if highlighting a region. */
1485 && !(!NILP (Vtransient_mark_mode)
1486 && !NILP (current_buffer->mark_active))
1487 && NILP (w->region_showing)
1488 && EQ (last_arrow_position, Voverlay_arrow_position)
1489 && EQ (last_arrow_string, Voverlay_arrow_string)
1490 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1491 && tem != -2)
1493 /* tem > 0 means success. tem == -1 means choose new start.
1494 tem == -2 means try again with same start,
1495 and nothing but whitespace follows the changed stuff.
1496 tem == 0 means try again with same start. */
1497 if (tem > 0)
1498 goto done;
1500 else if (startp >= BEGV && startp <= ZV
1501 /* Avoid starting display at end of buffer! */
1502 && (startp < ZV || startp == BEGV
1503 || (XFASTINT (w->last_modified) >= MODIFF)))
1505 /* Try to redisplay starting at same place as before */
1506 /* If point has not moved off frame, accept the results */
1507 try_window (window, startp);
1508 if (cursor_vpos >= 0)
1510 if (!just_this_one || clip_changed || beg_unchanged < startp)
1511 /* Forget any recorded base line for line number display. */
1512 w->base_line_number = Qnil;
1513 goto done;
1515 else
1516 cancel_my_columns (w);
1519 XSETFASTINT (w->last_modified, 0);
1520 /* Redisplay the mode line. Select the buffer properly for that. */
1521 if (!update_mode_line)
1523 set_buffer_temp (old);
1524 set_buffer_internal (XBUFFER (w->buffer));
1525 update_mode_line = 1;
1526 w->update_mode_line = Qt;
1529 /* Try to scroll by specified few lines */
1531 if (scroll_step && !clip_changed)
1533 if (PT > startp)
1535 pos = *vmotion (Z - XFASTINT (w->window_end_pos),
1536 scroll_step, width, hscroll, window);
1537 if (pos.vpos >= height)
1538 goto scroll_fail;
1541 pos = *vmotion (startp, PT < startp ? - scroll_step : scroll_step,
1542 width, hscroll, window);
1544 if (PT >= pos.bufpos)
1546 try_window (window, pos.bufpos);
1547 if (cursor_vpos >= 0)
1549 if (!just_this_one || clip_changed || beg_unchanged < startp)
1550 /* Forget any recorded base line for line number display. */
1551 w->base_line_number = Qnil;
1552 goto done;
1554 else
1555 cancel_my_columns (w);
1557 scroll_fail: ;
1560 /* Finally, just choose place to start which centers point */
1562 recenter:
1563 /* Forget any previously recorded base line for line number display. */
1564 w->base_line_number = Qnil;
1566 pos = *vmotion (PT, - (height / 2), width, hscroll, window);
1567 try_window (window, pos.bufpos);
1569 startp = marker_position (w->start);
1570 w->start_at_line_beg
1571 = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
1573 done:
1574 if ((update_mode_line
1575 /* If window not full width, must redo its mode line
1576 if the window to its side is being redone */
1577 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
1578 || INTEGERP (w->base_line_pos)
1579 || (!NILP (w->column_number_displayed)
1580 && XFASTINT (w->column_number_displayed) != current_column ()))
1581 && height != XFASTINT (w->height))
1582 display_mode_line (w);
1583 if (! line_number_displayed
1584 && ! BUFFERP (w->base_line_pos))
1586 w->base_line_pos = Qnil;
1587 w->base_line_number = Qnil;
1590 /* When we reach a frame's selected window, redo the frame's menu bar. */
1591 if (update_mode_line
1592 #ifdef USE_X_TOOLKIT
1593 && FRAME_EXTERNAL_MENU_BAR (f)
1594 #else
1595 && FRAME_MENU_BAR_LINES (f) > 0
1596 #endif
1597 && EQ (FRAME_SELECTED_WINDOW (f), window))
1598 display_menu_bar (w);
1600 finish_scroll_bars:
1601 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
1603 int start, end, whole;
1605 /* Calculate the start and end positions for the current window.
1606 At some point, it would be nice to choose between scrollbars
1607 which reflect the whole buffer size, with special markers
1608 indicating narrowing, and scrollbars which reflect only the
1609 visible region.
1611 Note that minibuffers sometimes aren't displaying any text. */
1612 if (! MINI_WINDOW_P (w)
1613 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1615 whole = ZV - BEGV;
1616 start = startp - BEGV;
1617 /* I don't think this is guaranteed to be right. For the
1618 moment, we'll pretend it is. */
1619 end = (Z - XINT (w->window_end_pos)) - BEGV;
1621 if (end < start) end = start;
1622 if (whole < (end - start)) whole = end - start;
1624 else
1625 start = end = whole = 0;
1627 /* Indicate what this scroll bar ought to be displaying now. */
1628 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
1630 /* Note that we actually used the scroll bar attached to this window,
1631 so it shouldn't be deleted at the end of redisplay. */
1632 (*redeem_scroll_bar_hook) (w);
1635 BUF_PT (current_buffer) = opoint;
1636 if (update_mode_line)
1637 set_buffer_internal (old);
1638 else
1639 set_buffer_temp (old);
1640 BUF_PT (current_buffer) = lpoint;
1643 /* Do full redisplay on one window, starting at position `pos'. */
1645 static void
1646 try_window (window, pos)
1647 Lisp_Object window;
1648 register int pos;
1650 register struct window *w = XWINDOW (window);
1651 register int height = window_internal_height (w);
1652 register int vpos = XFASTINT (w->top);
1653 register int last_text_vpos = vpos;
1654 int tab_offset = pos_tab_offset (w, pos);
1655 FRAME_PTR f = XFRAME (w->frame);
1656 int width = window_internal_width (w) - 1;
1657 struct position val;
1659 Fset_marker (w->start, make_number (pos), Qnil);
1660 cursor_vpos = -1;
1661 overlay_arrow_seen = 0;
1662 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1664 while (--height >= 0)
1666 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1667 tab_offset += width;
1668 /* For the first line displayed, display_text_line
1669 subtracts the prompt width from the tab offset.
1670 But it does not affect the value of our variable tab_offset.
1671 So we do the subtraction again,
1672 for the sake of continuation lines of that first line. */
1673 if (MINI_WINDOW_P (w) && vpos == XFASTINT (w->top))
1674 tab_offset -= minibuf_prompt_width;
1676 if (val.vpos) tab_offset = 0;
1677 vpos++;
1678 if (pos != val.bufpos)
1679 last_text_vpos
1680 /* Next line, unless prev line ended in end of buffer with no cr */
1681 = vpos - (val.vpos && (FETCH_CHAR (val.bufpos - 1) != '\n'
1682 #ifdef USE_TEXT_PROPERTIES
1683 || ! NILP (Fget_char_property (val.bufpos-1,
1684 Qinvisible,
1685 window))
1686 #endif
1688 pos = val.bufpos;
1691 /* If last line is continued in middle of character,
1692 include the split character in the text considered on the frame */
1693 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1694 pos++;
1696 /* If bottom just moved off end of frame, change mode line percentage. */
1697 if (XFASTINT (w->window_end_pos) == 0
1698 && Z != pos)
1699 w->update_mode_line = Qt;
1701 /* Say where last char on frame will be, once redisplay is finished. */
1702 XSETFASTINT (w->window_end_pos, Z - pos);
1703 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
1704 /* But that is not valid info until redisplay finishes. */
1705 w->window_end_valid = Qnil;
1708 /* Try to redisplay when buffer is modified locally,
1709 computing insert/delete line to preserve text outside
1710 the bounds of the changes.
1711 Return 1 if successful, 0 if if cannot tell what to do,
1712 or -1 to tell caller to find a new window start,
1713 or -2 to tell caller to do normal redisplay with same window start. */
1715 static int
1716 try_window_id (window)
1717 Lisp_Object window;
1719 int pos;
1720 register struct window *w = XWINDOW (window);
1721 register int height = window_internal_height (w);
1722 FRAME_PTR f = XFRAME (w->frame);
1723 int top = XFASTINT (w->top);
1724 int start = marker_position (w->start);
1725 int width = window_internal_width (w) - 1;
1726 int hscroll = XINT (w->hscroll);
1727 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
1728 register int vpos;
1729 register int i, tem;
1730 int last_text_vpos = 0;
1731 int stop_vpos;
1732 int selective = (INTEGERP (current_buffer->selective_display)
1733 ? XINT (current_buffer->selective_display)
1734 : !NILP (current_buffer->selective_display) ? -1 : 0);
1736 struct position val, bp, ep, xp, pp;
1737 int scroll_amount = 0;
1738 int delta;
1739 int tab_offset, epto;
1741 if (GPT - BEG < beg_unchanged)
1742 beg_unchanged = GPT - BEG;
1743 if (Z - GPT < end_unchanged)
1744 end_unchanged = Z - GPT;
1746 if (beg_unchanged + BEG < start)
1747 return 0; /* Give up if changes go above top of window */
1749 /* Find position before which nothing is changed. */
1750 bp = *compute_motion (start, 0, lmargin,
1751 min (ZV, beg_unchanged + BEG), height + 1, 0,
1752 width, hscroll, pos_tab_offset (w, start), w);
1753 if (bp.vpos >= height)
1755 if (PT < bp.bufpos && !bp.contin)
1757 /* All changes are below the frame, and point is on the frame.
1758 We don't need to change the frame at all.
1759 But we need to update window_end_pos to account for
1760 any change in buffer size. */
1761 bp = *compute_motion (start, 0, lmargin,
1762 Z, height, 0,
1763 width, hscroll, pos_tab_offset (w, start), w);
1764 XSETFASTINT (w->window_end_vpos, height);
1765 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
1766 return 1;
1768 return 0;
1771 vpos = bp.vpos;
1773 /* Find beginning of that frame line. Must display from there. */
1774 bp = *vmotion (bp.bufpos, 0, width, hscroll, window);
1776 pos = bp.bufpos;
1777 val.hpos = lmargin;
1778 if (pos < start)
1779 return -1;
1781 /* If about to start displaying at the beginning of a continuation line,
1782 really start with previous frame line, in case it was not
1783 continued when last redisplayed */
1784 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
1786 /* Likewise if we have to worry about selective display. */
1787 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
1789 bp = *vmotion (bp.bufpos, -1, width, hscroll, window);
1790 --vpos;
1791 pos = bp.bufpos;
1794 if (bp.contin && bp.hpos != lmargin)
1796 val.hpos = bp.prevhpos - width + lmargin;
1797 pos--;
1800 bp.vpos = vpos;
1802 /* Find first visible newline after which no more is changed. */
1803 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
1804 if (selective > 0)
1805 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
1806 tem = find_next_newline (tem, 1);
1808 /* Compute the cursor position after that newline. */
1809 ep = *compute_motion (pos, vpos, val.hpos, tem,
1810 height, - (1 << (SHORTBITS - 1)),
1811 width, hscroll, pos_tab_offset (w, bp.bufpos), w);
1813 /* If changes reach past the text available on the frame,
1814 just display rest of frame. */
1815 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
1816 stop_vpos = height;
1817 else
1818 stop_vpos = ep.vpos;
1820 /* If no newline before ep, the line ep is on includes some changes
1821 that must be displayed. Make sure we don't stop before it. */
1822 /* Also, if changes reach all the way until ep.bufpos,
1823 it is possible that something was deleted after the
1824 newline before it, so the following line must be redrawn. */
1825 if (stop_vpos == ep.vpos
1826 && (ep.bufpos == BEGV
1827 || FETCH_CHAR (ep.bufpos - 1) != '\n'
1828 || ep.bufpos == Z - end_unchanged))
1829 stop_vpos = ep.vpos + 1;
1831 cursor_vpos = -1;
1832 overlay_arrow_seen = 0;
1834 /* If changes do not reach to bottom of window,
1835 figure out how much to scroll the rest of the window */
1836 if (stop_vpos < height)
1838 /* Now determine how far up or down the rest of the window has moved */
1839 epto = pos_tab_offset (w, ep.bufpos);
1840 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1841 Z - XFASTINT (w->window_end_pos),
1842 10000, 0, width, hscroll, epto, w);
1843 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
1845 /* Is everything on frame below the changes whitespace?
1846 If so, no scrolling is really necessary. */
1847 for (i = ep.bufpos; i < xp.bufpos; i++)
1849 tem = FETCH_CHAR (i);
1850 if (tem != ' ' && tem != '\n' && tem != '\t')
1851 break;
1853 if (i == xp.bufpos)
1854 return -2;
1856 XSETFASTINT (w->window_end_vpos,
1857 XFASTINT (w->window_end_vpos) + scroll_amount);
1859 /* Before doing any scrolling, verify that point will be on frame. */
1860 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height))
1862 if (PT <= xp.bufpos)
1864 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1865 PT, height, - (1 << (SHORTBITS - 1)),
1866 width, hscroll, epto, w);
1868 else
1870 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos,
1871 PT, height, - (1 << (SHORTBITS - 1)),
1872 width, hscroll,
1873 pos_tab_offset (w, xp.bufpos), w);
1875 if (pp.bufpos < PT || pp.vpos == height)
1876 return 0;
1877 cursor_vpos = pp.vpos + top;
1878 cursor_hpos = pp.hpos + XFASTINT (w->left);
1881 if (stop_vpos - scroll_amount >= height
1882 || ep.bufpos == xp.bufpos)
1884 if (scroll_amount < 0)
1885 stop_vpos -= scroll_amount;
1886 scroll_amount = 0;
1887 /* In this path, we have altered window_end_vpos
1888 and not left it negative.
1889 We must make sure that, in case display is preempted
1890 before the frame changes to reflect what we do here,
1891 further updates will not come to try_window_id
1892 and assume the frame and window_end_vpos match. */
1893 blank_end_of_window = 1;
1895 else if (!scroll_amount)
1897 /* Even if we don't need to scroll, we must adjust the
1898 charstarts of subsequent lines (that we won't redisplay)
1899 according to the amount of text inserted or deleted. */
1900 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1901 int adjust = ep.bufpos - oldpos;
1902 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
1904 else if (bp.bufpos == Z - end_unchanged)
1906 /* If reprinting everything is nearly as fast as scrolling,
1907 don't bother scrolling. Can happen if lines are short. */
1908 if (scroll_cost (f, bp.vpos + top - scroll_amount,
1909 top + height - max (0, scroll_amount),
1910 scroll_amount)
1911 > xp.bufpos - bp.bufpos - 20)
1912 /* Return "try normal display with same window-start."
1913 Too bad we can't prevent further scroll-thinking. */
1914 return -2;
1915 /* If pure deletion, scroll up as many lines as possible.
1916 In common case of killing a line, this can save the
1917 following line from being overwritten by scrolling
1918 and therefore having to be redrawn. */
1919 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
1920 top + height - max (0, scroll_amount),
1921 scroll_amount, bp.bufpos);
1922 if (!tem)
1923 stop_vpos = height;
1924 else
1926 /* scroll_frame_lines did not properly adjust subsequent
1927 lines' charstarts in the case where the text of the
1928 screen line at bp.vpos has changed.
1929 (This can happen in a deletion that ends in mid-line.)
1930 To adjust properly, we need to make things constent at
1931 the position ep.
1932 So do a second adjust to make that happen.
1933 Note that stop_vpos >= ep.vpos, so it is sufficient
1934 to update the charstarts for lines at ep.vpos and below. */
1935 int oldstart
1936 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1937 adjust_window_charstarts (w, ep.vpos + top - 1,
1938 ep.bufpos - oldstart);
1941 else if (scroll_amount)
1943 /* If reprinting everything is nearly as fast as scrolling,
1944 don't bother scrolling. Can happen if lines are short. */
1945 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1946 overestimate of cost of reprinting, since xp.bufpos
1947 would end up below the bottom of the window. */
1948 if (scroll_cost (f, ep.vpos + top - scroll_amount,
1949 top + height - max (0, scroll_amount),
1950 scroll_amount)
1951 > xp.bufpos - ep.bufpos - 20)
1952 /* Return "try normal display with same window-start."
1953 Too bad we can't prevent further scroll-thinking. */
1954 return -2;
1955 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
1956 top + height - max (0, scroll_amount),
1957 scroll_amount, ep.bufpos);
1958 if (!tem) stop_vpos = height;
1962 /* In any case, do not display past bottom of window */
1963 if (stop_vpos >= height)
1965 stop_vpos = height;
1966 scroll_amount = 0;
1969 /* Handle case where pos is before w->start --
1970 can happen if part of line had been clipped and is not clipped now */
1971 if (vpos == 0 && pos < marker_position (w->start))
1972 Fset_marker (w->start, make_number (pos), Qnil);
1974 /* Redisplay the lines where the text was changed */
1975 last_text_vpos = vpos;
1976 tab_offset = pos_tab_offset (w, pos);
1977 /* If we are starting display in mid-character, correct tab_offset
1978 to account for passing the line that that character really starts in. */
1979 if (val.hpos < lmargin)
1980 tab_offset += width;
1981 while (vpos < stop_vpos)
1983 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
1984 tab_offset += width;
1985 if (val.vpos) tab_offset = 0;
1986 if (pos != val.bufpos)
1987 last_text_vpos
1988 /* Next line, unless prev line ended in end of buffer with no cr */
1989 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
1990 pos = val.bufpos;
1993 /* There are two cases:
1994 1) we have displayed down to the bottom of the window
1995 2) we have scrolled lines below stop_vpos by scroll_amount */
1997 if (vpos == height)
1999 /* If last line is continued in middle of character,
2000 include the split character in the text considered on the frame */
2001 if (val.hpos < lmargin)
2002 val.bufpos++;
2003 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2004 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2007 /* If scrolling made blank lines at window bottom,
2008 redisplay to fill those lines */
2009 if (scroll_amount < 0)
2011 /* Don't consider these lines for general-purpose scrolling.
2012 That will save time in the scrolling computation. */
2013 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2014 vpos = xp.vpos;
2015 pos = xp.bufpos;
2016 val.hpos = lmargin;
2017 if (pos == ZV)
2018 vpos = height + scroll_amount;
2019 else if (xp.contin && xp.hpos != lmargin)
2021 val.hpos = xp.prevhpos - width + lmargin;
2022 pos--;
2025 blank_end_of_window = 1;
2026 tab_offset = pos_tab_offset (w, pos);
2027 /* If we are starting display in mid-character, correct tab_offset
2028 to account for passing the line that that character starts in. */
2029 if (val.hpos < lmargin)
2030 tab_offset += width;
2032 while (vpos < height)
2034 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2035 tab_offset += width;
2036 if (val.vpos) tab_offset = 0;
2037 pos = val.bufpos;
2040 /* Here is a case where display_text_line sets cursor_vpos wrong.
2041 Make it be fixed up, below. */
2042 if (xp.bufpos == ZV
2043 && xp.bufpos == PT)
2044 cursor_vpos = -1;
2047 /* If bottom just moved off end of frame, change mode line percentage. */
2048 if (XFASTINT (w->window_end_pos) == 0
2049 && Z != val.bufpos)
2050 w->update_mode_line = Qt;
2052 /* Attempt to adjust end-of-text positions to new bottom line */
2053 if (scroll_amount)
2055 delta = height - xp.vpos;
2056 if (delta < 0
2057 || (delta > 0 && xp.bufpos <= ZV)
2058 || (delta == 0 && xp.hpos))
2060 val = *vmotion (Z - XFASTINT (w->window_end_pos),
2061 delta, width, hscroll, window);
2062 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2063 XSETFASTINT (w->window_end_vpos,
2064 XFASTINT (w->window_end_vpos) + val.vpos);
2068 w->window_end_valid = Qnil;
2070 /* If point was not in a line that was displayed, find it */
2071 if (cursor_vpos < 0)
2073 val = *compute_motion (start, 0, lmargin, PT, 10000, 10000,
2074 width, hscroll, pos_tab_offset (w, start), w);
2075 /* Admit failure if point is off frame now */
2076 if (val.vpos >= height)
2078 for (vpos = 0; vpos < height; vpos++)
2079 cancel_line (vpos + top, f);
2080 return 0;
2082 cursor_vpos = val.vpos + top;
2083 cursor_hpos = val.hpos + XFASTINT (w->left);
2086 FRAME_CURSOR_X (f) = max (0, cursor_hpos);
2087 FRAME_CURSOR_Y (f) = cursor_vpos;
2089 if (debug_end_pos)
2091 val = *compute_motion (start, 0, lmargin, ZV,
2092 height, - (1 << (SHORTBITS - 1)),
2093 width, hscroll, pos_tab_offset (w, start), w);
2094 if (val.vpos != XFASTINT (w->window_end_vpos))
2095 abort ();
2096 if (XFASTINT (w->window_end_pos)
2097 != Z - val.bufpos)
2098 abort ();
2101 return 1;
2104 /* Mark a section of BUF as modified, but only for the sake of redisplay.
2105 This is useful for recording changes to overlays.
2107 We increment the buffer's modification timestamp and set the
2108 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
2109 as if the region of text between START and END had been modified;
2110 the redisplay code will check this against the windows' timestamps,
2111 and redraw the appropriate area of the buffer.
2113 However, if the buffer is unmodified, we bump the last-save
2114 timestamp as well, so that incrementing the timestamp doesn't fool
2115 Emacs into thinking that the buffer's text has been modified.
2117 Tweaking the timestamps shouldn't hurt the first-modification
2118 timestamps recorded in the undo records; those values aren't
2119 written until just before a real text modification is made, so they
2120 will never catch the timestamp value just before this function gets
2121 called. */
2123 void
2124 redisplay_region (buf, start, end)
2125 struct buffer *buf;
2126 int start, end;
2128 if (start == end)
2129 return;
2131 if (start > end)
2133 int temp = start;
2134 start = end; end = temp;
2137 /* If this is a buffer not in the selected window,
2138 we must do other windows. */
2139 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2140 windows_or_buffers_changed = 1;
2141 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2142 else if (buf != current_buffer)
2143 windows_or_buffers_changed = 1;
2144 /* If multiple windows show this buffer, we must do other windows. */
2145 else if (buffer_shared > 1)
2146 windows_or_buffers_changed = 1;
2147 else
2149 if (unchanged_modified == MODIFF)
2151 beg_unchanged = start - BEG;
2152 end_unchanged = Z - end;
2154 else
2156 if (Z - end < end_unchanged)
2157 end_unchanged = Z - end;
2158 if (start - BEG < beg_unchanged)
2159 beg_unchanged = start - BEG;
2163 /* Increment the buffer's time stamp, but also increment the save
2164 and autosave timestamps, so as not to screw up that timekeeping. */
2165 if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf))
2166 BUF_SAVE_MODIFF (buf)++;
2167 if (BUF_MODIFF (buf) == buf->auto_save_modified)
2168 buf->auto_save_modified++;
2170 BUF_MODIFF (buf) ++;
2174 /* Copy LEN glyphs starting address FROM to the rope TO.
2175 But don't actually copy the parts that would come in before S.
2176 Value is TO, advanced past the copied data.
2177 F is the frame we are displaying in. */
2179 static GLYPH *
2180 copy_part_of_rope (f, to, s, from, len, face)
2181 FRAME_PTR f;
2182 register GLYPH *to; /* Copy to here. */
2183 register GLYPH *s; /* Starting point. */
2184 Lisp_Object *from; /* Data to copy. */
2185 int len;
2186 int face; /* Face to apply to glyphs which don't specify one. */
2188 int n = len;
2189 register Lisp_Object *fp = from;
2190 /* These cache the results of the last call to compute_glyph_face. */
2191 int last_code = -1;
2192 int last_merged = 0;
2194 #ifdef HAVE_FACES
2195 if (! FRAME_TERMCAP_P (f))
2196 while (n--)
2198 int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2199 int facecode;
2201 if (FAST_GLYPH_FACE (glyph) == 0)
2202 /* If GLYPH has no face code, use FACE. */
2203 facecode = face;
2204 else if (FAST_GLYPH_FACE (glyph) == last_code)
2205 /* If it's same as previous glyph, use same result. */
2206 facecode = last_merged;
2207 else
2209 /* Merge this glyph's face and remember the result. */
2210 last_code = FAST_GLYPH_FACE (glyph);
2211 last_merged = facecode = compute_glyph_face (f, last_code, face);
2214 if (to >= s)
2215 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
2216 ++to;
2217 ++fp;
2219 else
2220 #endif
2221 while (n--)
2223 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2224 ++to;
2225 ++fp;
2227 return to;
2230 /* Correct a glyph by replacing its specified user-level face code
2231 with a displayable computed face code. */
2233 static GLYPH
2234 fix_glyph (f, glyph, cface)
2235 FRAME_PTR f;
2236 GLYPH glyph;
2237 int cface;
2239 #ifdef HAVE_FACES
2240 if (! FRAME_TERMCAP_P (f))
2242 if (FAST_GLYPH_FACE (glyph) != 0)
2243 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2244 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2246 #endif
2247 return glyph;
2250 /* Display one line of window W, starting at position START in W's buffer.
2252 Display starting at horizontal position HPOS, expressed relative to
2253 W's left edge. In situations where the text at START shouldn't
2254 start at the left margin (i.e. when the window is hscrolled, or
2255 we're continuing a line which left off in the midst of a
2256 multi-column character), HPOS should be negative; we throw away
2257 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2258 account.
2260 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2262 Display on position VPOS on the frame. It is origin 0, relative to
2263 the top of the frame, not W.
2265 Returns a STRUCT POSITION giving character to start next line with
2266 and where to display it, including a zero or negative hpos.
2267 The vpos field is not really a vpos; it is 1 unless the line is continued */
2269 struct position val_display_text_line;
2271 static struct position *
2272 display_text_line (w, start, vpos, hpos, taboffset)
2273 struct window *w;
2274 int start;
2275 int vpos;
2276 int hpos;
2277 int taboffset;
2279 register int pos = start;
2280 register int c;
2281 register GLYPH *p1;
2282 int end;
2283 register int pause;
2284 register unsigned char *p;
2285 GLYPH *endp;
2286 register GLYPH *leftmargin;
2287 register GLYPH *p1prev = 0;
2288 register GLYPH *p1start;
2289 int *charstart;
2290 FRAME_PTR f = XFRAME (w->frame);
2291 int tab_width = XINT (current_buffer->tab_width);
2292 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2293 int width = window_internal_width (w) - 1;
2294 struct position val;
2295 int lastpos;
2296 int invis;
2297 int hscroll = XINT (w->hscroll);
2298 int truncate = (hscroll
2299 || (truncate_partial_width_windows
2300 && XFASTINT (w->width) < FRAME_WIDTH (f))
2301 || !NILP (current_buffer->truncate_lines));
2303 /* 1 if we should highlight the region. */
2304 int highlight_region
2305 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
2306 int region_beg, region_end;
2308 int selective = (INTEGERP (current_buffer->selective_display)
2309 ? XINT (current_buffer->selective_display)
2310 : !NILP (current_buffer->selective_display) ? -1 : 0);
2311 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2312 register struct Lisp_Vector *dp = window_display_table (w);
2314 Lisp_Object default_invis_vector[3];
2315 /* Nonzero means display something where there are invisible lines.
2316 The precise value is the number of glyphs to display. */
2317 int selective_rlen
2318 = (selective && dp && VECTORP (DISP_INVIS_VECTOR (dp))
2319 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2320 : selective && !NILP (current_buffer->selective_display_ellipses)
2321 ? 3 : 0);
2322 /* This is the sequence of Lisp objects to display
2323 when there are invisible lines. */
2324 Lisp_Object *invis_vector_contents
2325 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2326 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2327 : default_invis_vector);
2329 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2330 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2331 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2332 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2334 /* The next buffer location at which the face should change, due
2335 to overlays or text property changes. */
2336 int next_face_change;
2338 #ifdef USE_TEXT_PROPERTIES
2339 /* The next location where the `invisible' property changes */
2340 int next_invisible;
2341 #endif
2343 /* The face we're currently using. */
2344 int current_face = 0;
2345 int i;
2347 XSETFASTINT (default_invis_vector[2], '.');
2348 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2350 hpos += XFASTINT (w->left);
2351 get_display_line (f, vpos, XFASTINT (w->left));
2352 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2354 /* Show where to highlight the region. */
2355 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2356 /* Maybe highlight only in selected window. */
2357 && (highlight_nonselected_windows
2358 || w == XWINDOW (selected_window)))
2360 region_beg = marker_position (current_buffer->mark);
2361 if (PT < region_beg)
2363 region_end = region_beg;
2364 region_beg = PT;
2366 else
2367 region_end = PT;
2368 w->region_showing = Qt;
2370 else
2371 region_beg = region_end = -1;
2373 if (MINI_WINDOW_P (w)
2374 && start == 1
2375 && vpos == XFASTINT (w->top))
2377 if (! NILP (minibuf_prompt))
2379 minibuf_prompt_width
2380 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2381 XSTRING (minibuf_prompt)->size, hpos,
2382 /* Display a space if we truncate. */
2383 ' ',
2384 1, -1,
2385 /* Truncate the prompt a little before the
2386 margin, so user input can at least start
2387 on the first line. */
2388 w->width > 10 ? w->width - 4 : -1)
2389 - hpos);
2390 hpos += minibuf_prompt_width;
2391 taboffset -= minibuf_prompt_width;
2393 else
2394 minibuf_prompt_width = 0;
2397 end = ZV;
2399 /* If we're hscrolled at all, use compute_motion to skip over any
2400 text off the left edge of the window. compute_motion may know
2401 tricks to do this faster than we can. */
2402 if (hpos < 0)
2404 struct position *left_edge
2405 = compute_motion (pos, vpos, hpos,
2406 end, vpos, 0,
2407 width, hscroll, taboffset, w);
2409 /* Retrieve the buffer position and column provided by
2410 compute_motion. We can't assume that the column will be
2411 zero, because you may have multi-column characters crossing
2412 the left margin.
2414 compute_motion may have moved us past the screen position we
2415 requested, if we hit a multi-column character, or the end of
2416 the line. If so, back up. */
2417 if (left_edge->vpos > vpos
2418 || left_edge->hpos > 0)
2420 pos = left_edge->bufpos - 1;
2421 hpos = left_edge->prevhpos;
2423 else
2425 pos = left_edge->bufpos;
2426 hpos = left_edge->hpos;
2430 desired_glyphs->bufp[vpos] = start;
2431 p1 = desired_glyphs->glyphs[vpos] + hpos;
2432 p1start = p1;
2433 charstart = desired_glyphs->charstarts[vpos] + hpos;
2434 /* In case we don't ever write anything into it... */
2435 desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1;
2436 leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2437 endp = leftmargin + width;
2439 /* Arrange the overlays nicely for our purposes. Usually, we call
2440 display_text_line on only one line at a time, in which case this
2441 can't really hurt too much, or we call it on lines which appear
2442 one after another in the buffer, in which case all calls to
2443 recenter_overlay_lists but the first will be pretty cheap. */
2444 recenter_overlay_lists (current_buffer, pos);
2446 /* Loop generating characters.
2447 Stop at end of buffer, before newline,
2448 if reach or pass continuation column,
2449 or at face change. */
2450 pause = pos;
2451 next_face_change = pos;
2452 #ifdef USE_TEXT_PROPERTIES
2453 next_invisible = pos;
2454 #endif
2455 while (1)
2457 /* Record which glyph starts a character,
2458 and the character position of that character. */
2459 if (p1 >= leftmargin)
2460 charstart[p1 - p1start] = pos;
2462 if (p1 >= endp)
2463 break;
2465 p1prev = p1;
2466 if (pos >= pause)
2468 /* Did we hit the end of the visible region of the buffer?
2469 Stop here. */
2470 if (pos >= end)
2471 break;
2473 /* Did we reach point? Record the cursor location. */
2474 if (pos == PT && cursor_vpos < 0)
2476 cursor_vpos = vpos;
2477 cursor_hpos = p1 - leftmargin;
2480 #ifdef USE_TEXT_PROPERTIES
2481 /* if the `invisible' property is set to t, we can skip to
2482 the next property change */
2483 while (pos == next_invisible && pos < end)
2485 Lisp_Object position, limit, endpos, prop, ww;
2486 XSETFASTINT (position, pos);
2487 XSETWINDOW (ww, w);
2488 prop = Fget_char_property (position, Qinvisible, ww);
2489 /* This is just an estimate to give reasonable
2490 performance; nothing should go wrong if it is too small. */
2491 limit = Fnext_overlay_change (position);
2492 if (XFASTINT (limit) > pos + 50)
2493 XSETFASTINT (limit, pos + 50);
2494 endpos = Fnext_single_property_change (position, Qinvisible,
2495 Fcurrent_buffer (), limit);
2496 if (INTEGERP (endpos))
2497 next_invisible = XINT (endpos);
2498 else
2499 next_invisible = end;
2500 if (! NILP (prop))
2502 if (pos < PT && next_invisible >= PT)
2504 cursor_vpos = vpos;
2505 cursor_hpos = p1 - leftmargin;
2507 pos = next_invisible;
2510 if (pos >= end)
2511 break;
2512 #endif
2514 #ifdef HAVE_FACES
2515 /* Did we hit a face change? Figure out what face we should
2516 use now. We also hit this the first time through the
2517 loop, to see what face we should start with. */
2518 if (pos >= next_face_change && FRAME_X_P (f))
2519 current_face = compute_char_face (f, w, pos,
2520 region_beg, region_end,
2521 &next_face_change, pos + 50, 0);
2522 #endif
2524 pause = end;
2526 #ifdef USE_TEXT_PROPERTIES
2527 if (pos < next_invisible && next_invisible < pause)
2528 pause = next_invisible;
2529 #endif
2530 if (pos < next_face_change && next_face_change < pause)
2531 pause = next_face_change;
2533 /* Wouldn't you hate to read the next line to someone over
2534 the phone? */
2535 if (pos < PT && PT < pause)
2536 pause = PT;
2537 if (pos < GPT && GPT < pause)
2538 pause = GPT;
2540 p = &FETCH_CHAR (pos);
2542 c = *p++;
2543 if (c >= 040 && c < 0177
2544 && (dp == 0 || !VECTORP (DISP_CHAR_VECTOR (dp, c))))
2546 if (p1 >= leftmargin)
2547 *p1 = MAKE_GLYPH (f, c, current_face);
2548 p1++;
2550 else if (c == '\n')
2552 invis = 0;
2553 while (pos + 1 < end
2554 && selective > 0
2555 && indented_beyond_p (pos + 1, selective))
2557 invis = 1;
2558 pos = find_next_newline (pos + 1, 1);
2559 if (FETCH_CHAR (pos - 1) == '\n')
2560 pos--;
2562 if (invis && selective_rlen > 0 && p1 >= leftmargin)
2564 p1 += selective_rlen;
2565 if (p1 - leftmargin > width)
2566 p1 = endp;
2567 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2568 (p1 - p1prev), current_face);
2570 #ifdef HAVE_FACES
2571 /* Draw the face of the newline character as extending all the
2572 way to the end of the frame line. */
2573 if (current_face)
2575 if (p1 < leftmargin)
2576 p1 = leftmargin;
2577 while (p1 < endp)
2578 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2580 #endif
2581 break;
2583 else if (c == '\t')
2587 if (p1 >= leftmargin && p1 < endp)
2588 *p1 = MAKE_GLYPH (f, ' ', current_face);
2589 p1++;
2591 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
2592 % tab_width);
2594 else if (c == Ctl ('M') && selective == -1)
2596 pos = find_next_newline (pos, 1);
2597 if (FETCH_CHAR (pos - 1) == '\n')
2598 pos--;
2599 if (selective_rlen > 0)
2601 p1 += selective_rlen;
2602 if (p1 - leftmargin > width)
2603 p1 = endp;
2604 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2605 (p1 - p1prev), current_face);
2607 #ifdef HAVE_FACES
2608 /* Draw the face of the newline character as extending all the
2609 way to the end of the frame line. */
2610 if (current_face)
2612 if (p1 < leftmargin)
2613 p1 = leftmargin;
2614 while (p1 < endp)
2615 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2617 #endif
2618 break;
2620 else if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
2622 p1 = copy_part_of_rope (f, p1, leftmargin,
2623 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2624 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2625 current_face);
2627 else if (c < 0200 && ctl_arrow)
2629 if (p1 >= leftmargin)
2630 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
2631 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
2632 current_face);
2633 p1++;
2634 if (p1 >= leftmargin && p1 < endp)
2635 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
2636 p1++;
2638 else
2640 if (p1 >= leftmargin)
2641 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
2642 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
2643 current_face);
2644 p1++;
2645 if (p1 >= leftmargin && p1 < endp)
2646 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
2647 p1++;
2648 if (p1 >= leftmargin && p1 < endp)
2649 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
2650 p1++;
2651 if (p1 >= leftmargin && p1 < endp)
2652 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
2653 p1++;
2656 /* Do nothing here for a char that's entirely off the left edge. */
2657 if (p1 >= leftmargin)
2659 /* For all the glyphs occupied by this character, except for the
2660 first, store -1 in charstarts. */
2661 if (p1 != p1prev)
2663 int *p2x = &charstart[p1prev - p1start];
2664 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2666 /* The window's left column should always
2667 contain a character position.
2668 And don't clobber anything to the left of that. */
2669 if (p1prev < leftmargin)
2671 p2x = charstart + (leftmargin - p1start);
2672 *p2x = pos;
2675 /* This loop skips over the char p2x initially points to. */
2676 while (++p2x < p2)
2677 *p2x = -1;
2681 pos++;
2684 val.hpos = - XINT (w->hscroll);
2685 if (val.hpos)
2686 val.hpos++;
2688 val.vpos = 1;
2690 lastpos = pos;
2692 /* Store 0 in this charstart line for the positions where
2693 there is no character. But do leave what was recorded
2694 for the character that ended the line. */
2695 /* Add 1 in the endtest to compensate for the fact that ENDP was
2696 made from WIDTH, which is 1 less than the window's actual
2697 internal width. */
2698 i = p1 - p1start + 1;
2699 if (p1 < leftmargin)
2700 i += leftmargin - p1;
2701 for (; i < endp - p1start + 1; i++)
2702 charstart[i] = 0;
2704 /* Handle continuation in middle of a character */
2705 /* by backing up over it */
2706 if (p1 > endp)
2708 /* Don't back up if we never actually displayed any text.
2709 This occurs when the minibuffer prompt takes up the whole line. */
2710 if (p1prev)
2712 /* Start the next line with that same character */
2713 pos--;
2714 /* but at negative hpos, to skip the columns output on this line. */
2715 val.hpos += p1prev - endp;
2718 /* Keep in this line everything up to the continuation column. */
2719 p1 = endp;
2722 /* Finish deciding which character to start the next line on,
2723 and what hpos to start it at.
2724 Also set `lastpos' to the last position which counts as "on this line"
2725 for cursor-positioning. */
2727 if (pos < ZV)
2729 if (FETCH_CHAR (pos) == '\n')
2731 /* If stopped due to a newline, start next line after it */
2732 pos++;
2733 /* Check again for hidden lines, in case the newline occurred exactly
2734 at the right margin. */
2735 while (pos < ZV && selective > 0
2736 && indented_beyond_p (pos, selective))
2737 pos = find_next_newline (pos, 1);
2739 else
2740 /* Stopped due to right margin of window */
2742 if (truncate)
2744 *p1++ = fix_glyph (f, truncator, 0);
2745 /* Truncating => start next line after next newline,
2746 and point is on this line if it is before the newline,
2747 and skip none of first char of next line */
2749 pos = find_next_newline (pos, 1);
2750 while (pos < ZV && selective > 0
2751 && indented_beyond_p (pos, selective));
2752 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2754 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
2756 else
2758 *p1++ = fix_glyph (f, continuer, 0);
2759 val.vpos = 0;
2760 lastpos--;
2765 /* If point is at eol or in invisible text at eol,
2766 record its frame location now. */
2768 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
2770 cursor_vpos = vpos;
2771 cursor_hpos = p1 - leftmargin;
2774 if (cursor_vpos == vpos)
2776 if (cursor_hpos < 0) cursor_hpos = 0;
2777 if (cursor_hpos > width) cursor_hpos = width;
2778 cursor_hpos += XFASTINT (w->left);
2779 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
2781 FRAME_CURSOR_Y (f) = cursor_vpos;
2782 FRAME_CURSOR_X (f) = cursor_hpos;
2784 if (w == XWINDOW (selected_window))
2786 /* Line is not continued and did not start
2787 in middle of character */
2788 if ((hpos - XFASTINT (w->left)
2789 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2790 && val.vpos)
2792 this_line_bufpos = start;
2793 this_line_buffer = current_buffer;
2794 this_line_vpos = cursor_vpos;
2795 this_line_start_hpos = hpos;
2796 this_line_endpos = Z - lastpos;
2798 else
2799 this_line_bufpos = 0;
2804 /* If hscroll and line not empty, insert truncation-at-left marker */
2805 if (hscroll && lastpos != start)
2807 *leftmargin = fix_glyph (f, truncator, 0);
2808 if (p1 <= leftmargin)
2809 p1 = leftmargin + 1;
2812 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
2814 endp++;
2815 if (p1 < leftmargin) p1 = leftmargin;
2816 while (p1 < endp) *p1++ = SPACEGLYPH;
2818 /* Don't draw vertical bars if we're using scroll bars. They're
2819 covered up by the scroll bars, and it's distracting to see
2820 them when the scroll bar windows are flickering around to be
2821 reconfigured. */
2822 *p1++ = (FRAME_HAS_VERTICAL_SCROLL_BARS (f)
2823 ? ' '
2824 : (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
2825 ? DISP_BORDER_GLYPH (dp)
2826 : '|'));
2828 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
2829 p1 - desired_glyphs->glyphs[vpos]);
2830 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
2832 /* If the start of this line is the overlay arrow-position,
2833 then put the arrow string into the display-line. */
2835 if (MARKERP (Voverlay_arrow_position)
2836 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
2837 && start == marker_position (Voverlay_arrow_position)
2838 && STRINGP (Voverlay_arrow_string)
2839 && ! overlay_arrow_seen)
2841 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
2842 int i;
2843 int len = XSTRING (Voverlay_arrow_string)->size;
2844 int arrow_end;
2846 if (len > width)
2847 len = width;
2848 #ifdef HAVE_FACES
2849 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
2851 /* If the arrow string has text props, obey them when displaying. */
2852 for (i = 0; i < len; i++)
2854 int c = p[i];
2855 Lisp_Object face, ilisp;
2856 int newface;
2858 XSETFASTINT (ilisp, i);
2859 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
2860 newface = compute_glyph_face_1 (f, face, 0);
2861 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
2864 else
2865 #endif /* HAVE_FACES */
2867 for (i = 0; i < len; i++)
2868 leftmargin[i] = p[i];
2871 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
2872 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
2873 if (desired_glyphs->used[vpos] < arrow_end)
2874 desired_glyphs->used[vpos] = arrow_end;
2876 overlay_arrow_seen = 1;
2879 val.bufpos = pos;
2880 val_display_text_line = val;
2881 return &val_display_text_line;
2884 /* Redisplay the menu bar in the frame for window W. */
2886 static void
2887 display_menu_bar (w)
2888 struct window *w;
2890 Lisp_Object items, tail;
2891 register int vpos = 0;
2892 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2893 int maxendcol = FRAME_WIDTH (f);
2894 int hpos = 0;
2895 int i;
2897 #ifndef USE_X_TOOLKIT
2898 if (FRAME_MENU_BAR_LINES (f) <= 0)
2899 return;
2901 get_display_line (f, vpos, 0);
2903 items = FRAME_MENU_BAR_ITEMS (f);
2904 for (i = 0; i < XVECTOR (items)->size; i += 3)
2906 Lisp_Object pos, string;
2907 string = XVECTOR (items)->contents[i + 1];
2908 if (NILP (string))
2909 break;
2911 XSETFASTINT (XVECTOR (items)->contents[i + 2], hpos);
2913 if (hpos < maxendcol)
2914 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
2915 XSTRING (string)->data,
2916 XSTRING (string)->size,
2917 hpos, 0, 0, hpos, maxendcol);
2918 /* Put a gap of 3 spaces between items. */
2919 if (hpos < maxendcol)
2921 int hpos1 = hpos + 3;
2922 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
2923 min (hpos1, maxendcol), maxendcol);
2927 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
2928 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
2930 /* Fill out the line with spaces. */
2931 if (maxendcol > hpos)
2932 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
2934 /* Clear the rest of the lines allocated to the menu bar. */
2935 vpos++;
2936 while (vpos < FRAME_MENU_BAR_LINES (f))
2937 get_display_line (f, vpos++, 0);
2938 #endif /* not USE_X_TOOLKIT */
2941 /* Display the mode line for window w */
2943 static void
2944 display_mode_line (w)
2945 struct window *w;
2947 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
2948 register int left = XFASTINT (w->left);
2949 register int right = XFASTINT (w->width) + left;
2950 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2952 line_number_displayed = 0;
2953 w->column_number_displayed = Qnil;
2955 get_display_line (f, vpos, left);
2956 display_mode_element (w, vpos, left, 0, right, right,
2957 current_buffer->mode_line_format);
2958 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
2960 /* Make the mode line inverse video if the entire line
2961 is made of mode lines.
2962 I.e. if this window is full width,
2963 or if it is the child of a full width window
2964 (which implies that that window is split side-by-side
2965 and the rest of this line is mode lines of the sibling windows). */
2966 if (XFASTINT (w->width) == FRAME_WIDTH (f)
2967 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
2968 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
2969 #ifdef HAVE_FACES
2970 else if (! FRAME_TERMCAP_P (f))
2972 /* For a partial width window, explicitly set face of each glyph. */
2973 int i;
2974 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
2975 for (i = left; i < right; ++i)
2976 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
2978 #endif
2981 /* Contribute ELT to the mode line for window W.
2982 How it translates into text depends on its data type.
2984 VPOS is the position of the mode line being displayed.
2986 HPOS is the position (absolute on frame) where this element's text
2987 should start. The output is truncated automatically at the right
2988 edge of window W.
2990 DEPTH is the depth in recursion. It is used to prevent
2991 infinite recursion here.
2993 MINENDCOL is the hpos before which the element may not end.
2994 The element is padded at the right with spaces if nec
2995 to reach this column.
2997 MAXENDCOL is the hpos past which this element may not extend.
2998 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
2999 (This is necessary to make nested padding and truncation work.)
3001 Returns the hpos of the end of the text generated by ELT.
3002 The next element will receive that value as its HPOS arg,
3003 so as to concatenate the elements. */
3005 static int
3006 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3007 struct window *w;
3008 register int vpos, hpos;
3009 int depth;
3010 int minendcol;
3011 register int maxendcol;
3012 register Lisp_Object elt;
3014 tail_recurse:
3015 if (depth > 10)
3016 goto invalid;
3018 depth++;
3020 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3022 case Lisp_String:
3024 /* A string: output it and check for %-constructs within it. */
3025 register unsigned char c;
3026 register unsigned char *this = XSTRING (elt)->data;
3028 while (hpos < maxendcol && *this)
3030 unsigned char *last = this;
3031 while ((c = *this++) != '\0' && c != '%')
3033 if (this - 1 != last)
3035 register int lim = --this - last + hpos;
3036 if (frame_title_ptr)
3037 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3038 else
3039 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3040 hpos, min (lim, maxendcol));
3042 else /* c == '%' */
3044 register int spec_width = 0;
3046 /* We can't allow -ve args due to the "%-" construct */
3047 /* Argument specifies minwidth but not maxwidth
3048 (maxwidth can be specified by
3049 (<negative-number> . <stuff>) mode-line elements) */
3051 while ((c = *this++) >= '0' && c <= '9')
3053 spec_width = spec_width * 10 + (c - '0');
3056 spec_width += hpos;
3057 if (spec_width > maxendcol)
3058 spec_width = maxendcol;
3060 if (c == 'M')
3061 hpos = display_mode_element (w, vpos, hpos, depth,
3062 spec_width, maxendcol,
3063 Vglobal_mode_string);
3064 else if (c != 0)
3066 char *spec = decode_mode_spec (w, c, maxendcol - hpos);
3067 if (frame_title_ptr)
3068 hpos = store_frame_title (spec, spec_width, maxendcol);
3069 else
3070 hpos = display_string (w, vpos, spec, -1,
3071 hpos, 0, 1,
3072 spec_width, maxendcol);
3077 break;
3079 case Lisp_Symbol:
3080 /* A symbol: process the value of the symbol recursively
3081 as if it appeared here directly. Avoid error if symbol void.
3082 Special case: if value of symbol is a string, output the string
3083 literally. */
3085 register Lisp_Object tem;
3086 tem = Fboundp (elt);
3087 if (!NILP (tem))
3089 tem = Fsymbol_value (elt);
3090 /* If value is a string, output that string literally:
3091 don't check for % within it. */
3092 if (STRINGP (tem))
3094 if (frame_title_ptr)
3095 hpos = store_frame_title (XSTRING (tem)->data,
3096 minendcol, maxendcol);
3097 else
3098 hpos = display_string (w, vpos, XSTRING (tem)->data,
3099 XSTRING (tem)->size,
3100 hpos, 0, 1, minendcol, maxendcol);
3102 /* Give up right away for nil or t. */
3103 else if (!EQ (tem, elt))
3104 { elt = tem; goto tail_recurse; }
3107 break;
3109 case Lisp_Cons:
3111 register Lisp_Object car, tem;
3113 /* A cons cell: three distinct cases.
3114 If first element is a string or a cons, process all the elements
3115 and effectively concatenate them.
3116 If first element is a negative number, truncate displaying cdr to
3117 at most that many characters. If positive, pad (with spaces)
3118 to at least that many characters.
3119 If first element is a symbol, process the cadr or caddr recursively
3120 according to whether the symbol's value is non-nil or nil. */
3121 car = XCONS (elt)->car;
3122 if (SYMBOLP (car))
3124 tem = Fboundp (car);
3125 elt = XCONS (elt)->cdr;
3126 if (!CONSP (elt))
3127 goto invalid;
3128 /* elt is now the cdr, and we know it is a cons cell.
3129 Use its car if CAR has a non-nil value. */
3130 if (!NILP (tem))
3132 tem = Fsymbol_value (car);
3133 if (!NILP (tem))
3134 { elt = XCONS (elt)->car; goto tail_recurse; }
3136 /* Symbol's value is nil (or symbol is unbound)
3137 Get the cddr of the original list
3138 and if possible find the caddr and use that. */
3139 elt = XCONS (elt)->cdr;
3140 if (NILP (elt))
3141 break;
3142 else if (!CONSP (elt))
3143 goto invalid;
3144 elt = XCONS (elt)->car;
3145 goto tail_recurse;
3147 else if (INTEGERP (car))
3149 register int lim = XINT (car);
3150 elt = XCONS (elt)->cdr;
3151 if (lim < 0)
3152 /* Negative int means reduce maximum width.
3153 DO NOT change MINENDCOL here!
3154 (20 -10 . foo) should truncate foo to 10 col
3155 and then pad to 20. */
3156 maxendcol = min (maxendcol, hpos - lim);
3157 else if (lim > 0)
3159 /* Padding specified. Don't let it be more than
3160 current maximum. */
3161 lim += hpos;
3162 if (lim > maxendcol)
3163 lim = maxendcol;
3164 /* If that's more padding than already wanted, queue it.
3165 But don't reduce padding already specified even if
3166 that is beyond the current truncation point. */
3167 if (lim > minendcol)
3168 minendcol = lim;
3170 goto tail_recurse;
3172 else if (STRINGP (car) || CONSP (car))
3174 register int limit = 50;
3175 /* LIMIT is to protect against circular lists. */
3176 while (CONSP (elt) && --limit > 0
3177 && hpos < maxendcol)
3179 hpos = display_mode_element (w, vpos, hpos, depth,
3180 hpos, maxendcol,
3181 XCONS (elt)->car);
3182 elt = XCONS (elt)->cdr;
3186 break;
3188 default:
3189 invalid:
3190 if (frame_title_ptr)
3191 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3192 else
3193 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3194 minendcol, maxendcol);
3195 return hpos;
3198 if (minendcol > hpos)
3199 if (frame_title_ptr)
3200 hpos = store_frame_title ("", minendcol, maxendcol);
3201 else
3202 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
3203 return hpos;
3206 /* Return a string for the output of a mode line %-spec for window W,
3207 generated by character C and width MAXWIDTH. */
3209 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3211 static char *
3212 decode_mode_spec (w, c, maxwidth)
3213 struct window *w;
3214 register char c;
3215 register int maxwidth;
3217 Lisp_Object obj;
3218 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3219 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
3220 struct buffer *b = XBUFFER (w->buffer);
3222 obj = Qnil;
3223 if (maxwidth > FRAME_WIDTH (f))
3224 maxwidth = FRAME_WIDTH (f);
3226 switch (c)
3228 case 'b':
3229 obj = b->name;
3230 #if 0
3231 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
3233 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
3234 decode_mode_spec_buf[maxwidth - 1] = '\\';
3235 decode_mode_spec_buf[maxwidth] = '\0';
3236 return decode_mode_spec_buf;
3238 #endif
3239 break;
3241 case 'f':
3242 obj = b->filename;
3243 #if 0
3244 if (NILP (obj))
3245 return "[none]";
3246 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
3248 bcopy ("...", decode_mode_spec_buf, 3);
3249 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
3250 decode_mode_spec_buf + 3, maxwidth - 3);
3251 return decode_mode_spec_buf;
3253 #endif
3254 break;
3256 case 'c':
3258 int col = current_column ();
3259 XSETFASTINT (w->column_number_displayed, col);
3260 sprintf (decode_mode_spec_buf, "%d", col);
3261 return decode_mode_spec_buf;
3264 case 'l':
3266 int startpos = marker_position (w->start);
3267 int line, linepos, topline;
3268 int nlines, junk;
3269 Lisp_Object tem;
3270 int height = XFASTINT (w->height);
3272 /* If we decided that this buffer isn't suitable for line numbers,
3273 don't forget that too fast. */
3274 if (EQ (w->base_line_pos, w->buffer))
3275 return "??";
3277 /* If the buffer is very big, don't waste time. */
3278 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
3280 w->base_line_pos = Qnil;
3281 w->base_line_number = Qnil;
3282 return "??";
3285 if (!NILP (w->base_line_number)
3286 && !NILP (w->base_line_pos)
3287 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
3289 line = XFASTINT (w->base_line_number);
3290 linepos = XFASTINT (w->base_line_pos);
3292 else
3294 line = 1;
3295 linepos = BUF_BEGV (b);
3298 /* Count lines from base line to window start position. */
3299 nlines = display_count_lines (linepos, startpos, startpos, &junk);
3301 topline = nlines + line;
3303 /* Determine a new base line, if the old one is too close
3304 or too far away, or if we did not have one.
3305 "Too close" means it's plausible a scroll-down would
3306 go back past it. */
3307 if (startpos == BUF_BEGV (b))
3309 XSETFASTINT (w->base_line_number, topline);
3310 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
3312 else if (nlines < height + 25 || nlines > height * 3 + 50
3313 || linepos == BUF_BEGV (b))
3315 int limit = BUF_BEGV (b);
3316 int position;
3317 int distance = (height * 2 + 30) * 200;
3319 if (startpos - distance > limit)
3320 limit = startpos - distance;
3322 nlines = display_count_lines (startpos, limit,
3323 -(height * 2 + 30),
3324 &position);
3325 /* If we couldn't find the lines we wanted within
3326 200 chars per line,
3327 give up on line numbers for this window. */
3328 if (position == startpos - distance)
3330 w->base_line_pos = w->buffer;
3331 w->base_line_number = Qnil;
3332 return "??";
3335 XSETFASTINT (w->base_line_number, topline - nlines);
3336 XSETFASTINT (w->base_line_pos, position);
3339 /* Now count lines from the start pos to point. */
3340 nlines = display_count_lines (startpos, PT, PT, &junk);
3342 /* Record that we did display the line number. */
3343 line_number_displayed = 1;
3345 /* Make the string to show. */
3346 sprintf (decode_mode_spec_buf, "%d", topline + nlines);
3347 return decode_mode_spec_buf;
3349 break;
3351 case 'm':
3352 obj = b->mode_name;
3353 break;
3355 case 'n':
3356 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
3357 return " Narrow";
3358 break;
3360 case '*':
3361 if (!NILP (b->read_only))
3362 return "%";
3363 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3364 return "*";
3365 return "-";
3367 case '+':
3368 /* This differs from %* only for a modified read-only buffer. */
3369 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3370 return "*";
3371 if (!NILP (b->read_only))
3372 return "%";
3373 return "-";
3375 case '&':
3376 /* This differs from %* in ignoring read-only-ness. */
3377 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3378 return "*";
3379 return "-";
3381 case 's':
3382 /* status of process */
3383 obj = Fget_buffer_process (w->buffer);
3384 if (NILP (obj))
3385 return "no process";
3386 #ifdef subprocesses
3387 obj = Fsymbol_name (Fprocess_status (obj));
3388 #endif
3389 break;
3391 case 't': /* indicate TEXT or BINARY */
3392 #ifdef MODE_LINE_BINARY_TEXT
3393 return MODE_LINE_BINARY_TEXT (b);
3394 #else
3395 return "T";
3396 #endif
3398 case 'p':
3400 int pos = marker_position (w->start);
3401 int total = BUF_ZV (b) - BUF_BEGV (b);
3403 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
3405 if (pos <= BUF_BEGV (b))
3406 return "All";
3407 else
3408 return "Bottom";
3410 else if (pos <= BUF_BEGV (b))
3411 return "Top";
3412 else
3414 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
3415 /* We can't normally display a 3-digit number,
3416 so get us a 2-digit number that is close. */
3417 if (total == 100)
3418 total = 99;
3419 sprintf (decode_mode_spec_buf, "%2d%%", total);
3420 return decode_mode_spec_buf;
3424 /* Display percentage of size above the bottom of the screen. */
3425 case 'P':
3427 int toppos = marker_position (w->start);
3428 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
3429 int total = BUF_ZV (b) - BUF_BEGV (b);
3431 if (botpos >= BUF_ZV (b))
3433 if (toppos <= BUF_BEGV (b))
3434 return "All";
3435 else
3436 return "Bottom";
3438 else
3440 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
3441 /* We can't normally display a 3-digit number,
3442 so get us a 2-digit number that is close. */
3443 if (total == 100)
3444 total = 99;
3445 if (toppos <= BUF_BEGV (b))
3446 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
3447 else
3448 sprintf (decode_mode_spec_buf, "%2d%%", total);
3449 return decode_mode_spec_buf;
3453 case '%':
3454 return "%";
3456 case '[':
3458 int i;
3459 char *p;
3461 if (command_loop_level > 5)
3462 return "[[[... ";
3463 p = decode_mode_spec_buf;
3464 for (i = 0; i < command_loop_level; i++)
3465 *p++ = '[';
3466 *p = 0;
3467 return decode_mode_spec_buf;
3470 case ']':
3472 int i;
3473 char *p;
3475 if (command_loop_level > 5)
3476 return " ...]]]";
3477 p = decode_mode_spec_buf;
3478 for (i = 0; i < command_loop_level; i++)
3479 *p++ = ']';
3480 *p = 0;
3481 return decode_mode_spec_buf;
3484 case '-':
3486 register char *p;
3487 register int i;
3489 if (maxwidth < sizeof (lots_of_dashes))
3490 return lots_of_dashes;
3491 else
3493 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3494 *p++ = '-';
3495 *p = '\0';
3497 return decode_mode_spec_buf;
3501 if (STRINGP (obj))
3502 return (char *) XSTRING (obj)->data;
3503 else
3504 return "";
3507 /* Search for COUNT instances of a line boundary, which means either a
3508 newline or (if selective display enabled) a carriage return.
3509 Start at START. If COUNT is negative, search backwards.
3511 If we find COUNT instances, set *SHORTAGE to zero, and return the
3512 position after the COUNTth match. Note that for reverse motion
3513 this is not the same as the usual convention for Emacs motion commands.
3515 If we don't find COUNT instances before reaching the end of the
3516 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3517 the number of line boundaries left unfound, and return the end of the
3518 buffer we bumped up against. */
3520 static int
3521 display_scan_buffer (start, count, shortage)
3522 int *shortage, start;
3523 register int count;
3525 int limit = ((count > 0) ? ZV - 1 : BEGV);
3526 int direction = ((count > 0) ? 1 : -1);
3528 register unsigned char *cursor;
3529 unsigned char *base;
3531 register int ceiling;
3532 register unsigned char *ceiling_addr;
3534 /* If we are not in selective display mode,
3535 check only for newlines. */
3536 if (! (!NILP (current_buffer->selective_display)
3537 && !INTEGERP (current_buffer->selective_display)))
3538 return scan_buffer ('\n', start, 0, count, shortage, 0);
3540 /* The code that follows is like scan_buffer
3541 but checks for either newline or carriage return. */
3543 if (shortage != 0)
3544 *shortage = 0;
3546 if (count > 0)
3547 while (start != limit + 1)
3549 ceiling = BUFFER_CEILING_OF (start);
3550 ceiling = min (limit, ceiling);
3551 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
3552 base = (cursor = &FETCH_CHAR (start));
3553 while (1)
3555 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
3557 if (cursor != ceiling_addr)
3559 if (--count == 0)
3561 immediate_quit = 0;
3562 return (start + cursor - base + 1);
3564 else
3565 if (++cursor == ceiling_addr)
3566 break;
3568 else
3569 break;
3571 start += cursor - base;
3573 else
3575 start--; /* first character we scan */
3576 while (start > limit - 1)
3577 { /* we WILL scan under start */
3578 ceiling = BUFFER_FLOOR_OF (start);
3579 ceiling = max (limit, ceiling);
3580 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
3581 base = (cursor = &FETCH_CHAR (start));
3582 cursor++;
3583 while (1)
3585 while (--cursor != ceiling_addr
3586 && *cursor != '\n' && *cursor != 015)
3588 if (cursor != ceiling_addr)
3590 if (++count == 0)
3592 immediate_quit = 0;
3593 return (start + cursor - base + 1);
3596 else
3597 break;
3599 start += cursor - base;
3603 if (shortage != 0)
3604 *shortage = count * direction;
3605 return (start + ((direction == 1 ? 0 : 1)));
3608 /* Count up to N lines starting from FROM.
3609 But don't go beyond LIMIT.
3610 Return the number of lines thus found (always positive).
3611 Store the position after what was found into *POS_PTR. */
3613 static int
3614 display_count_lines (from, limit, n, pos_ptr)
3615 int from, limit, n;
3616 int *pos_ptr;
3618 int oldbegv = BEGV;
3619 int oldzv = ZV;
3620 int shortage = 0;
3622 if (limit < from)
3623 BEGV = limit;
3624 else
3625 ZV = limit;
3627 *pos_ptr = display_scan_buffer (from, n, &shortage);
3629 ZV = oldzv;
3630 BEGV = oldbegv;
3632 if (n < 0)
3633 /* When scanning backwards, scan_buffer stops *after* the last newline
3634 it finds, but does count it. Compensate for that. */
3635 return - n - shortage - (*pos_ptr != limit);
3636 return n - shortage;
3639 /* Display STRING on one line of window W, starting at HPOS.
3640 Display at position VPOS. Caller should have done get_display_line.
3641 If VPOS == -1, display it as the current frame's title.
3642 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
3644 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
3646 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
3647 MAXCOL is the last column ok to end at. Truncate here.
3648 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
3649 Both count from the left edge of the frame, as does HPOS.
3650 The right edge of W is an implicit maximum.
3651 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
3653 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
3654 at the place where the current window ends in this line
3655 and not display anything beyond there. Otherwise, only MAXCOL
3656 controls where to stop output.
3658 Returns ending hpos. */
3660 static int
3661 display_string (w, vpos, string, length, hpos, truncate,
3662 obey_window_width, mincol, maxcol)
3663 struct window *w;
3664 unsigned char *string;
3665 int length;
3666 int vpos, hpos;
3667 GLYPH truncate;
3668 int obey_window_width;
3669 int mincol, maxcol;
3671 register int c;
3672 register GLYPH *p1;
3673 int hscroll = XINT (w->hscroll);
3674 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
3675 register GLYPH *start;
3676 register GLYPH *end;
3677 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3678 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
3679 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
3680 int window_width = XFASTINT (w->width);
3682 /* Use the standard display table, not the window's display table.
3683 We don't want the mode line in rot13. */
3684 register struct Lisp_Vector *dp = 0;
3685 int i;
3687 if (VECTORP (Vstandard_display_table)
3688 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
3689 dp = XVECTOR (Vstandard_display_table);
3691 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
3693 p1 = p1start;
3694 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
3696 if (obey_window_width)
3698 end = start + window_width - (truncate != 0);
3700 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
3702 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3704 int i;
3706 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3707 *end-- = ' ';
3709 else
3710 *end-- = '|';
3714 if (! obey_window_width
3715 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
3716 end = desired_glyphs->glyphs[vpos] + maxcol;
3718 /* Store 0 in charstart for these columns. */
3719 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
3720 desired_glyphs->charstarts[vpos][i] = 0;
3722 if (maxcol >= 0 && mincol > maxcol)
3723 mincol = maxcol;
3725 while (p1 < end)
3727 if (length == 0)
3728 break;
3729 c = *string++;
3730 /* Specified length. */
3731 if (length >= 0)
3732 length--;
3733 /* Unspecified length (null-terminated string). */
3734 else if (c == 0)
3735 break;
3737 if (c >= 040 && c < 0177
3738 && (dp == 0 || !VECTORP (DISP_CHAR_VECTOR (dp, c))))
3740 if (p1 >= start)
3741 *p1 = c;
3742 p1++;
3744 else if (c == '\t')
3748 if (p1 >= start && p1 < end)
3749 *p1 = SPACEGLYPH;
3750 p1++;
3752 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
3754 else if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3756 p1 = copy_part_of_rope (f, p1, start,
3757 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3758 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3761 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
3763 if (p1 >= start)
3764 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
3765 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3767 p1++;
3768 if (p1 >= start && p1 < end)
3769 *p1 = c ^ 0100;
3770 p1++;
3772 else
3774 if (p1 >= start)
3775 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
3776 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3778 p1++;
3779 if (p1 >= start && p1 < end)
3780 *p1 = (c >> 6) + '0';
3781 p1++;
3782 if (p1 >= start && p1 < end)
3783 *p1 = (7 & (c >> 3)) + '0';
3784 p1++;
3785 if (p1 >= start && p1 < end)
3786 *p1 = (7 & c) + '0';
3787 p1++;
3791 if (c && length > 0)
3793 p1 = end;
3794 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
3796 else if (mincol >= 0)
3798 end = desired_glyphs->glyphs[vpos] + mincol;
3799 while (p1 < end)
3800 *p1++ = SPACEGLYPH;
3804 register int len = p1 - desired_glyphs->glyphs[vpos];
3806 if (len > desired_glyphs->used[vpos])
3807 desired_glyphs->used[vpos] = len;
3808 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3810 return len;
3814 void
3815 syms_of_xdisp ()
3817 staticpro (&Qmenu_bar_update_hook);
3818 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
3820 staticpro (&last_arrow_position);
3821 staticpro (&last_arrow_string);
3822 last_arrow_position = Qnil;
3823 last_arrow_string = Qnil;
3825 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
3826 "String (or mode line construct) included (normally) in `mode-line-format'.");
3827 Vglobal_mode_string = Qnil;
3829 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
3830 "Marker for where to display an arrow on top of the buffer text.\n\
3831 This must be the beginning of a line in order to work.\n\
3832 See also `overlay-arrow-string'.");
3833 Voverlay_arrow_position = Qnil;
3835 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
3836 "String to display as an arrow. See also `overlay-arrow-position'.");
3837 Voverlay_arrow_string = Qnil;
3839 DEFVAR_INT ("scroll-step", &scroll_step,
3840 "*The number of lines to try scrolling a window by when point moves out.\n\
3841 If that fails to bring point back on frame, point is centered instead.\n\
3842 If this is zero, point is always centered after it moves off frame.");
3844 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
3846 DEFVAR_BOOL ("truncate-partial-width-windows",
3847 &truncate_partial_width_windows,
3848 "*Non-nil means truncate lines in all windows less than full frame wide.");
3849 truncate_partial_width_windows = 1;
3851 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
3852 "*Non-nil means use inverse video for the mode line.");
3853 mode_line_inverse_video = 1;
3855 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
3856 "*Maximum buffer size for which line number should be displayed.");
3857 line_number_display_limit = 1000000;
3859 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
3860 "*Non-nil means highlight region even in nonselected windows.");
3861 highlight_nonselected_windows = 1;
3863 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
3864 "Non-nil means more than one frame is in use, not counting minibuffer frames.\n\
3865 Not guaranteed to be accurate except while parsing frame-title-format.");
3867 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
3868 "Template for displaying the titlebar of visible frames.\n\
3869 \(Assuming the window manager supports this feature.)\n\
3870 This variable has the same structure as `mode-line-format' (which see),\n\
3871 and is used only on frames for which no explicit name has been set\n\
3872 \(see `modify-frame-parameters').");
3873 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
3874 "Template for displaying the titlebar of an iconified frame.\n\
3875 \(Assuming the window manager supports this feature.)\n\
3876 This variable has the same structure as `mode-line-format' (which see),\n\
3877 and is used only on frames for which no explicit name has been set\n\
3878 \(see `modify-frame-parameters').");
3879 Vicon_title_format
3880 = Vframe_title_format
3881 = Fcons (intern ("multiple-frames"),
3882 Fcons (build_string ("%b"),
3883 Fcons (Fcons (build_string (""),
3884 Fcons (intern ("invocation-name"),
3885 Fcons (build_string ("@"),
3886 Fcons (intern ("system-name"),
3887 Qnil)))),
3888 Qnil)));
3890 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
3891 "Maximum number of lines to keep in the message log buffer.\n\
3892 If nil, disable message logging. If t, log messages but don't truncate\n\
3893 the buffer when it becomes large.");
3894 XSETFASTINT (Vmessage_log_max, 50);
3896 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
3897 "Functions called before redisplay, if window sizes have changed.\n\
3898 The value should be a list of functions that take one argument.\n\
3899 Just before redisplay, for each frame, if any of its windows have changed\n\
3900 size since the last redisplay, or have been split or deleted,\n\
3901 all the functions in the list are called, with the frame as argument.");
3902 Vwindow_size_change_functions = Qnil;
3905 /* initialize the window system */
3906 init_xdisp ()
3908 Lisp_Object root_window;
3909 #ifndef COMPILER_REGISTER_BUG
3910 register
3911 #endif /* COMPILER_REGISTER_BUG */
3912 struct window *mini_w;
3914 this_line_bufpos = 0;
3916 mini_w = XWINDOW (minibuf_window);
3917 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
3919 echo_area_glyphs = 0;
3920 previous_echo_glyphs = 0;
3922 if (!noninteractive)
3924 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
3925 XSETFASTINT (XWINDOW (root_window)->top, 0);
3926 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
3927 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
3928 set_window_height (minibuf_window, 1, 0);
3930 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
3931 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));