Added (load "ediff-hook") after loading vc-hook.
[emacs.git] / src / xdisp.c
blob9fec2ee6c311ba15c9041d50d7241de11aac3174
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"
37 #include "keyboard.h"
39 #ifdef USE_X_TOOLKIT
40 extern void set_frame_menubar ();
41 #endif
43 extern int interrupt_input;
44 extern int command_loop_level;
46 extern Lisp_Object Qface;
48 extern Lisp_Object Voverriding_local_map;
49 extern Lisp_Object Voverriding_local_map_menu_flag;
51 Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
52 Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
54 /* Nonzero means print newline to stdout before next minibuffer message. */
56 int noninteractive_need_newline;
58 /* Nonzero means print newline to message log before next message. */
60 static int message_log_need_newline;
62 #define min(a, b) ((a) < (b) ? (a) : (b))
63 #define max(a, b) ((a) > (b) ? (a) : (b))
64 #define minmax(floor, val, ceil) \
65 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
67 /* The buffer position of the first character appearing
68 entirely or partially on the current frame line.
69 Or zero, which disables the optimization for the current frame line. */
70 static int this_line_bufpos;
72 /* Number of characters past the end of this line,
73 including the terminating newline */
74 static int this_line_endpos;
76 /* The vertical position of this frame line. */
77 static int this_line_vpos;
79 /* Hpos value for start of display on this frame line.
80 Usually zero, but negative if first character really began
81 on previous line */
82 static int this_line_start_hpos;
84 /* Buffer that this_line variables are describing. */
85 static struct buffer *this_line_buffer;
87 /* Value of echo_area_glyphs when it was last acted on.
88 If this is nonzero, there is a message on the frame
89 in the minibuffer and it should be erased as soon
90 as it is no longer requested to appear. */
91 char *previous_echo_glyphs;
93 /* Nonzero means truncate lines in all windows less wide than the frame */
94 int truncate_partial_width_windows;
96 /* Nonzero means we have more than one non-minibuffer-only frame.
97 Not guaranteed to be accurate except while parsing frame-title-format. */
98 int multiple_frames;
100 Lisp_Object Vglobal_mode_string;
102 /* Marker for where to display an arrow on top of the buffer text. */
103 Lisp_Object Voverlay_arrow_position;
105 /* String to display for the arrow. */
106 Lisp_Object Voverlay_arrow_string;
108 /* Like mode-line-format, but for the titlebar on a visible frame. */
109 Lisp_Object Vframe_title_format;
111 /* Like mode-line-format, but for the titlebar on an iconified frame. */
112 Lisp_Object Vicon_title_format;
114 /* List of functions to call when a window's size changes. These
115 functions get one arg, a frame on which one or more windows' sizes
116 have changed. */
117 static Lisp_Object Vwindow_size_change_functions;
119 /* Values of those variables at last redisplay. */
120 static Lisp_Object last_arrow_position, last_arrow_string;
122 Lisp_Object Qmenu_bar_update_hook;
124 /* Nonzero if overlay arrow has been displayed once in this window. */
125 static int overlay_arrow_seen;
127 /* Nonzero if visible end of buffer has already been displayed once
128 in this window. (We need this variable in case there are overlay
129 strings that get displayed there.) */
130 static int zv_strings_seen;
132 /* Nonzero means highlight the region even in nonselected windows. */
133 static int highlight_nonselected_windows;
135 /* If cursor motion alone moves point off frame,
136 Try scrolling this many lines up or down if that will bring it back. */
137 static int scroll_step;
139 /* Nonzero if try_window_id has made blank lines at window bottom
140 since the last redisplay that paused */
141 static int blank_end_of_window;
143 /* Number of windows showing the buffer of the selected window
144 (or another buffer with the same base buffer).
145 keyboard.c refers to this. */
146 int buffer_shared;
148 /* display_text_line sets these to the frame position (origin 0) of point,
149 whether the window is selected or not.
150 Set one to -1 first to determine whether point was found afterwards. */
152 static int cursor_vpos;
153 static int cursor_hpos;
155 static int debug_end_pos;
157 /* Nonzero means display mode line highlighted */
158 int mode_line_inverse_video;
160 static int message_log_check_duplicate ();
161 static void echo_area_display ();
162 void mark_window_display_accurate ();
163 static void redisplay_windows ();
164 static void redisplay_window ();
165 static void update_menu_bar ();
166 static void try_window ();
167 static int try_window_id ();
168 static struct position *display_text_line ();
169 static void display_mode_line ();
170 static int display_mode_element ();
171 static char *decode_mode_spec ();
172 static int display_string ();
173 static void display_menu_bar ();
174 static int display_count_lines ();
176 /* Prompt to display in front of the minibuffer contents */
177 Lisp_Object minibuf_prompt;
179 /* Width in columns of current minibuffer prompt. */
180 int minibuf_prompt_width;
182 /* Message to display instead of minibuffer contents
183 This is what the functions error and message make,
184 and command echoing uses it as well.
185 It overrides the minibuf_prompt as well as the buffer. */
186 char *echo_area_glyphs;
188 /* This is the length of the message in echo_area_glyphs. */
189 int echo_area_glyphs_length;
191 /* This is the window where the echo area message was displayed.
192 It is always a minibuffer window, but it may not be the
193 same window currently active as a minibuffer. */
194 Lisp_Object echo_area_window;
196 /* true iff we should redraw the mode lines on the next redisplay */
197 int update_mode_lines;
199 /* Smallest number of characters before the gap
200 at any time since last redisplay that finished.
201 Valid for current buffer when try_window_id can be called. */
202 int beg_unchanged;
204 /* Smallest number of characters after the gap
205 at any time since last redisplay that finished.
206 Valid for current buffer when try_window_id can be called. */
207 int end_unchanged;
209 /* MODIFF as of last redisplay that finished;
210 if it matches MODIFF, beg_unchanged and end_unchanged
211 contain no useful information */
212 int unchanged_modified;
214 /* Nonzero if window sizes or contents have changed
215 since last redisplay that finished */
216 int windows_or_buffers_changed;
218 /* Nonzero after display_mode_line if %l was used
219 and it displayed a line number. */
220 int line_number_displayed;
222 /* Maximum buffer size for which to display line numbers. */
223 static int line_number_display_limit;
225 /* Number of lines to keep in the message log buffer.
226 t means infinite. nil means don't log at all. */
227 Lisp_Object Vmessage_log_max;
229 void
230 message_log_maybe_newline ()
232 if (message_log_need_newline)
233 message_dolog ("", 0, 1);
237 /* Add a string to the message log, optionally terminated with a newline.
238 This function calls low-level routines in order to bypass text property
239 hooks, etc. which might not be safe to run. */
241 void
242 message_dolog (m, len, nlflag)
243 char *m;
244 int len, nlflag;
246 if (!NILP (Vmessage_log_max))
248 struct buffer *oldbuf;
249 int oldpoint, oldbegv, oldzv;
251 oldbuf = current_buffer;
252 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
253 current_buffer->undo_list = Qt;
254 oldpoint = PT;
255 oldbegv = BEGV;
256 oldzv = ZV;
257 BEGV = BEG;
258 ZV = Z;
259 if (oldpoint == Z)
260 oldpoint += len + nlflag;
261 if (oldzv == Z)
262 oldzv += len + nlflag;
263 TEMP_SET_PT (Z);
264 if (len)
265 insert_1 (m, len, 1, 0);
266 if (nlflag)
268 int this_bol, prev_bol, dup;
269 insert_1 ("\n", 1, 1, 0);
271 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
272 if (this_bol > BEG)
274 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
275 dup = message_log_check_duplicate (prev_bol, this_bol);
276 if (dup)
278 if (oldpoint > prev_bol)
279 oldpoint -= min (this_bol, oldpoint) - prev_bol;
280 if (oldbegv > prev_bol)
281 oldbegv -= min (this_bol, oldbegv) - prev_bol;
282 if (oldzv > prev_bol)
283 oldzv -= min (this_bol, oldzv) - prev_bol;
284 del_range_1 (prev_bol, this_bol, 0);
285 if (dup > 1)
287 char dupstr[40];
288 int duplen;
290 /* If you change this format, don't forget to also
291 change message_log_check_duplicate. */
292 sprintf (dupstr, " [%d times]", dup);
293 duplen = strlen (dupstr);
294 TEMP_SET_PT (Z-1);
295 if (oldpoint == Z)
296 oldpoint += duplen;
297 if (oldzv == Z)
298 oldzv += duplen;
299 insert_1 (dupstr, duplen, 1, 0);
304 if (NATNUMP (Vmessage_log_max))
306 int pos = scan_buffer ('\n', Z, 0,
307 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
308 oldpoint -= min (pos, oldpoint) - BEG;
309 oldbegv -= min (pos, oldbegv) - BEG;
310 oldzv -= min (pos, oldzv) - BEG;
311 del_range_1 (BEG, pos, 0);
314 BEGV = oldbegv;
315 ZV = oldzv;
316 TEMP_SET_PT (oldpoint);
317 set_buffer_internal (oldbuf);
318 message_log_need_newline = !nlflag;
323 /* We are at the end of the buffer after just having inserted a newline.
324 (Note: We depend on the fact we won't be crossing the gap.)
325 Check to see if the most recent message looks a lot like the previous one.
326 Return 0 if different, 1 if the new one should just replace it, or a
327 value N > 1 if we should also append " [N times]". */
329 static int
330 message_log_check_duplicate (prev_bol, this_bol)
331 int prev_bol, this_bol;
333 int i;
334 int len = Z - 1 - this_bol;
335 int seen_dots = 0;
336 unsigned char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
337 unsigned char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
339 for (i = 0; i < len; i++)
341 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
342 && p1[i] != '\n')
343 seen_dots = 1;
344 if (p1[i] != p2[i])
345 return seen_dots;
347 p1 += len;
348 if (*p1 == '\n')
349 return 2;
350 if (*p1++ == ' ' && *p1++ == '[')
352 int n = 0;
353 while (*p1 >= '0' && *p1 <= '9')
354 n = n * 10 + *p1++ - '0';
355 if (strncmp (p1, " times]\n", 8) == 0)
356 return n+1;
358 return 0;
361 /* Display an echo area message M with a specified length of LEN chars.
362 The string may include null characters. If m is 0, clear out any
363 existing message, and let the minibuffer text show through.
364 Do not pass text that is stored in a Lisp string. */
366 void
367 message2 (m, len)
368 char *m;
369 int len;
371 /* First flush out any partial line written with print. */
372 message_log_maybe_newline ();
373 if (m)
374 message_dolog (m, len, 1);
375 message2_nolog (m, len);
379 /* The non-logging part of that function. */
381 void
382 message2_nolog (m, len)
383 char *m;
384 int len;
386 if (noninteractive)
388 if (noninteractive_need_newline)
389 putc ('\n', stderr);
390 noninteractive_need_newline = 0;
391 fwrite (m, len, 1, stderr);
392 if (cursor_in_echo_area == 0)
393 fprintf (stderr, "\n");
394 fflush (stderr);
396 /* A null message buffer means that the frame hasn't really been
397 initialized yet. Error messages get reported properly by
398 cmd_error, so this must be just an informative message; toss it. */
399 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
401 Lisp_Object mini_window;
402 FRAME_PTR f;
404 /* Get the frame containing the minibuffer
405 that the selected frame is using. */
406 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
407 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
409 #ifdef MULTI_FRAME
410 FRAME_SAMPLE_VISIBILITY (f);
411 if (FRAME_VISIBLE_P (selected_frame)
412 && ! FRAME_VISIBLE_P (f))
413 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window)));
414 #endif
416 if (m)
418 echo_area_glyphs = m;
419 echo_area_glyphs_length = len;
421 else
422 echo_area_glyphs = previous_echo_glyphs = 0;
424 do_pending_window_change ();
425 echo_area_display ();
426 update_frame (f, 1, 1);
427 do_pending_window_change ();
428 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
429 (*frame_up_to_date_hook) (f);
433 void
434 message1 (m)
435 char *m;
437 message2 (m, (m ? strlen (m) : 0));
440 void
441 message1_nolog (m)
442 char *m;
444 message2_nolog (m, (m ? strlen (m) : 0));
447 /* Truncate what will be displayed in the echo area
448 the next time we display it--but don't redisplay it now. */
450 void
451 truncate_echo_area (len)
452 int len;
454 /* A null message buffer means that the frame hasn't really been
455 initialized yet. Error messages get reported properly by
456 cmd_error, so this must be just an informative message; toss it. */
457 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
458 echo_area_glyphs_length = len;
461 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
462 zero if being used by message. */
463 int message_buf_print;
465 /* Dump an informative message to the minibuf. If m is 0, clear out
466 any existing message, and let the minibuffer text show through. */
467 /* VARARGS 1 */
468 void
469 message (m, a1, a2, a3)
470 char *m;
471 EMACS_INT a1, a2, a3;
473 if (noninteractive)
475 if (m)
477 if (noninteractive_need_newline)
478 putc ('\n', stderr);
479 noninteractive_need_newline = 0;
480 fprintf (stderr, m, a1, a2, a3);
481 if (cursor_in_echo_area == 0)
482 fprintf (stderr, "\n");
483 fflush (stderr);
486 else if (INTERACTIVE)
488 /* The frame whose minibuffer we're going to display the message on.
489 It may be larger than the selected frame, so we need
490 to use its buffer, not the selected frame's buffer. */
491 Lisp_Object mini_window;
492 FRAME_PTR f;
494 /* Get the frame containing the minibuffer
495 that the selected frame is using. */
496 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
497 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
499 /* A null message buffer means that the frame hasn't really been
500 initialized yet. Error messages get reported properly by
501 cmd_error, so this must be just an informative message; toss it. */
502 if (FRAME_MESSAGE_BUF (f))
504 if (m)
506 int len;
507 #ifdef NO_ARG_ARRAY
508 EMACS_INT a[3];
509 a[0] = a1;
510 a[1] = a2;
511 a[2] = a3;
513 len = doprnt (FRAME_MESSAGE_BUF (f),
514 FRAME_WIDTH (f), m, (char *)0, 3, a);
515 #else
516 len = doprnt (FRAME_MESSAGE_BUF (f),
517 FRAME_WIDTH (f), m, (char *)0, 3, &a1);
518 #endif /* NO_ARG_ARRAY */
520 message2 (FRAME_MESSAGE_BUF (f), len);
522 else
523 message1 (0);
525 /* Print should start at the beginning of the message
526 buffer next time. */
527 message_buf_print = 0;
532 /* The non-logging version of that function. */
533 void
534 message_nolog (m, a1, a2, a3)
535 char *m;
536 EMACS_INT a1, a2, a3;
538 Lisp_Object old_log_max;
539 old_log_max = Vmessage_log_max;
540 Vmessage_log_max = Qnil;
541 message (m, a1, a2, a3);
542 Vmessage_log_max = old_log_max;
545 void
546 update_echo_area ()
548 message2 (echo_area_glyphs, echo_area_glyphs_length);
551 static void
552 echo_area_display ()
554 register int vpos;
555 FRAME_PTR f;
556 Lisp_Object mini_window;
558 /* Choose the minibuffer window for this display.
559 It is the minibuffer window used by the selected frame. */
560 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
561 /* This is the frame that window is in. */
562 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
564 if (! FRAME_VISIBLE_P (f))
565 return;
567 if (frame_garbaged)
569 redraw_garbaged_frames ();
570 frame_garbaged = 0;
573 if (echo_area_glyphs || minibuf_level == 0)
575 echo_area_window = mini_window;
577 vpos = XFASTINT (XWINDOW (mini_window)->top);
578 get_display_line (f, vpos, 0);
579 display_string (XWINDOW (mini_window), vpos,
580 echo_area_glyphs ? echo_area_glyphs : "",
581 echo_area_glyphs ? echo_area_glyphs_length : -1,
582 0, 0, 0, 0, FRAME_WIDTH (f));
584 #if 0 /* This just gets in the way. update_frame does the job. */
585 /* If desired cursor location is on this line, put it at end of text */
586 if (cursor_in_echo_area)
587 FRAME_CURSOR_Y (f) = vpos;
588 if (FRAME_CURSOR_Y (f) == vpos)
589 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
590 #endif
592 /* Fill the rest of the minibuffer window with blank lines. */
594 int i;
596 for (i = vpos + 1;
597 i < vpos + XFASTINT (XWINDOW (mini_window)->height); i++)
599 get_display_line (f, i, 0);
600 display_string (XWINDOW (mini_window), vpos,
601 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f));
605 else if (!EQ (mini_window, selected_window))
606 windows_or_buffers_changed++;
608 if (EQ (mini_window, selected_window))
609 this_line_bufpos = 0;
611 previous_echo_glyphs = echo_area_glyphs;
614 #ifdef HAVE_X_WINDOWS
615 static char frame_title_buf[512];
616 static char *frame_title_ptr;
618 static int
619 store_frame_title (str, mincol, maxcol)
620 char *str;
621 int mincol, maxcol;
623 char *limit;
624 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
625 maxcol = sizeof (frame_title_buf);
626 limit = &frame_title_buf[maxcol];
627 while (*str != '\0' && frame_title_ptr < limit)
628 *frame_title_ptr++ = *str++;
629 while (frame_title_ptr < &frame_title_buf[mincol])
630 *frame_title_ptr++ = ' ';
631 return frame_title_ptr - frame_title_buf;
634 static void
635 x_consider_frame_title (frame)
636 Lisp_Object frame;
638 Lisp_Object fmt;
639 struct buffer *obuf;
640 int len;
641 FRAME_PTR f = XFRAME (frame);
643 if (!FRAME_X_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name)
644 return;
646 /* Do we have more than one visible frame on this X display? */
648 Lisp_Object tail;
650 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
652 FRAME_PTR tf = XFRAME (XCONS (tail)->car);
654 if (tf != f && FRAME_KBOARD (tf) == FRAME_KBOARD (f)
655 && !FRAME_MINIBUF_ONLY_P (tf)
656 && (FRAME_VISIBLE_P (tf) || FRAME_ICONIFIED_P (tf)))
657 break;
660 multiple_frames = CONSP (tail);
663 obuf = current_buffer;
664 Fset_buffer (XWINDOW (f->selected_window)->buffer);
665 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
666 frame_title_ptr = frame_title_buf;
667 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
668 0, sizeof (frame_title_buf), fmt);
669 frame_title_ptr = 0;
670 set_buffer_internal (obuf);
671 /* Set the name only if it's changed. This avoids consing
672 in the common case where it hasn't. (If it turns out that we've
673 already wasted too much time by walking through the list with
674 display_mode_element, then we might need to optimize at a higher
675 level than this.) */
676 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
677 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
678 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
680 #else
681 #define frame_title_ptr ((char *)0)
682 #define store_frame_title(str, mincol, maxcol) 0
683 #endif
685 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
686 This can call eval. */
688 void
689 prepare_menu_bars ()
691 register struct window *w = XWINDOW (selected_window);
692 int all_windows;
693 struct gcpro gcpro1, gcpro2;
695 all_windows = (update_mode_lines || buffer_shared > 1
696 || windows_or_buffers_changed);
698 /* Update all frame titles based on their buffer names, etc.
699 We do this before the menu bars so that the buffer-menu
700 will show the up-to-date frame titles.
702 This used to be done after the menu bars, for a reason that
703 was stated as follows but which I do not understand:
704 "We do this after the menu bars so that the frame will first
705 create its menu bar using the name `emacs' if no other name
706 has yet been specified."
707 I think that is no longer a concern. */
708 #ifdef HAVE_X_WINDOWS
709 if (windows_or_buffers_changed)
711 Lisp_Object tail, frame;
713 FOR_EACH_FRAME (tail, frame)
714 if (FRAME_VISIBLE_P (XFRAME (frame))
715 || FRAME_ICONIFIED_P (XFRAME (frame)))
716 x_consider_frame_title (frame);
718 #endif
720 /* Update the menu bar item lists, if appropriate.
721 This has to be done before any actual redisplay
722 or generation of display lines. */
723 if (all_windows)
725 Lisp_Object tail, frame;
726 int count = specpdl_ptr - specpdl;
728 record_unwind_protect (Fstore_match_data, Fmatch_data ());
730 FOR_EACH_FRAME (tail, frame)
732 /* If a window on this frame changed size,
733 report that to the user and clear the size-change flag. */
734 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
736 Lisp_Object functions;
737 /* Clear flag first in case we get error below. */
738 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
739 functions = Vwindow_size_change_functions;
740 GCPRO2 (tail, functions);
741 while (CONSP (functions))
743 call1 (XCONS (functions)->car, frame);
744 functions = XCONS (functions)->cdr;
746 UNGCPRO;
748 GCPRO1 (tail);
749 update_menu_bar (XFRAME (frame), 0);
750 UNGCPRO;
753 unbind_to (count, Qnil);
755 else
756 update_menu_bar (selected_frame, 1);
759 /* Do a frame update, taking possible shortcuts into account.
760 This is the main external entry point for redisplay.
762 If the last redisplay displayed an echo area message and that
763 message is no longer requested, we clear the echo area
764 or bring back the minibuffer if that is in use.
766 Do not call eval from within this function.
767 Calls to eval after the call to echo_area_display would confuse
768 the display_line mechanism and would cause a crash.
769 Calls to eval before that point will work most of the time,
770 but can still lose, because this function
771 can be called from signal handlers; with alarms set up;
772 or with synchronous processes running.
774 See Fcall_process; if you called it from here, it could be
775 entered recursively. */
777 static int do_verify_charstarts;
779 /* Counter is used to clear the face cache
780 no more than once ever 1000 redisplays. */
781 static int clear_face_cache_count;
783 /* Record the previous terminal frame we displayed. */
784 static FRAME_PTR previous_terminal_frame;
786 void
787 redisplay ()
789 register struct window *w = XWINDOW (selected_window);
790 register int pause;
791 int must_finish = 0;
792 int all_windows;
793 register int tlbufpos, tlendpos;
794 struct position pos;
796 if (noninteractive)
797 return;
799 #ifdef MULTI_FRAME
800 if (FRAME_TERMCAP_P (selected_frame)
801 && previous_terminal_frame != selected_frame)
803 /* Since frames on an ASCII terminal share the same display area,
804 displaying a different frame means redisplay the whole thing. */
805 windows_or_buffers_changed++;
806 SET_FRAME_GARBAGED (selected_frame);
807 XSETFRAME (Vterminal_frame, selected_frame);
809 previous_terminal_frame = selected_frame;
810 #endif
812 /* Set the visible flags for all frames.
813 Do this before checking for resized or garbaged frames; they want
814 to know if their frames are visible.
815 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
817 Lisp_Object tail, frame;
819 FOR_EACH_FRAME (tail, frame)
821 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
823 /* Clear out all the display lines in which we will generate the
824 glyphs to display. */
825 init_desired_glyphs (XFRAME (frame));
829 /* Notice any pending interrupt request to change frame size. */
830 do_pending_window_change ();
832 if (frame_garbaged)
834 redraw_garbaged_frames ();
835 frame_garbaged = 0;
838 prepare_menu_bars ();
840 if (windows_or_buffers_changed)
841 update_mode_lines++;
843 /* Detect case that we need to write a star in the mode line. */
844 if (XFASTINT (w->last_modified) < MODIFF
845 && XFASTINT (w->last_modified) <= SAVE_MODIFF)
847 w->update_mode_line = Qt;
848 if (buffer_shared > 1)
849 update_mode_lines++;
852 /* If %c is in use, update it if needed. */
853 if (!NILP (w->column_number_displayed)
854 /* This alternative quickly identifies a common case
855 where no change is needed. */
856 && !(PT == XFASTINT (w->last_point)
857 && XFASTINT (w->last_modified) >= MODIFF)
858 && XFASTINT (w->column_number_displayed) != current_column ())
859 w->update_mode_line = Qt;
861 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
863 all_windows = update_mode_lines || buffer_shared > 1;
865 /* If specs for an arrow have changed, do thorough redisplay
866 to ensure we remove any arrow that should no longer exist. */
867 if (! EQ (Voverlay_arrow_position, last_arrow_position)
868 || ! EQ (Voverlay_arrow_string, last_arrow_string))
869 all_windows = 1;
871 /* Normally the message* functions will have already displayed and
872 updated the echo area, but the frame may have been trashed, or
873 the update may have been preempted, so display the echo area
874 again here. */
875 if (echo_area_glyphs || previous_echo_glyphs)
877 echo_area_display ();
878 must_finish = 1;
881 /* If showing region, and mark has changed, must redisplay whole window. */
882 if (((!NILP (Vtransient_mark_mode)
883 && !NILP (XBUFFER (w->buffer)->mark_active))
884 != !NILP (w->region_showing))
885 || (!NILP (w->region_showing)
886 && !EQ (w->region_showing,
887 Fmarker_position (XBUFFER (w->buffer)->mark))))
888 this_line_bufpos = -1;
890 tlbufpos = this_line_bufpos;
891 tlendpos = this_line_endpos;
892 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
893 && !current_buffer->clip_changed
894 && FRAME_VISIBLE_P (XFRAME (w->frame))
895 /* Make sure recorded data applies to current buffer, etc */
896 && this_line_buffer == current_buffer
897 && current_buffer == XBUFFER (w->buffer)
898 && NILP (w->force_start)
899 /* Point must be on the line that we have info recorded about */
900 && PT >= tlbufpos
901 && PT <= Z - tlendpos
902 /* All text outside that line, including its final newline,
903 must be unchanged */
904 && (XFASTINT (w->last_modified) >= MODIFF
905 || (beg_unchanged >= tlbufpos - 1
906 && GPT >= tlbufpos
907 /* If selective display, can't optimize
908 if the changes start at the beginning of the line. */
909 && ((INTEGERP (current_buffer->selective_display)
910 && XINT (current_buffer->selective_display) > 0
911 ? (beg_unchanged >= tlbufpos
912 && GPT > tlbufpos)
913 : 1))
914 && end_unchanged >= tlendpos
915 && Z - GPT >= tlendpos)))
917 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
918 && (tlbufpos == ZV
919 || FETCH_CHAR (tlbufpos) == '\n'))
920 /* Former continuation line has disappeared by becoming empty */
921 goto cancel;
922 else if (XFASTINT (w->last_modified) < MODIFF
923 || MINI_WINDOW_P (w))
925 cursor_vpos = -1;
926 overlay_arrow_seen = 0;
927 zv_strings_seen = 0;
928 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
929 pos_tab_offset (w, tlbufpos));
930 /* If line contains point, is not continued,
931 and ends at same distance from eob as before, we win */
932 if (cursor_vpos >= 0 && this_line_bufpos
933 && this_line_endpos == tlendpos)
935 /* If this is not the window's last line,
936 we must adjust the charstarts of the lines below. */
937 if (this_line_vpos + 1
938 < XFASTINT (w->top) + window_internal_height (w))
940 int left = XFASTINT (w->left);
941 int *charstart_next_line
942 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
943 int adjust;
945 if (Z - tlendpos == ZV)
946 /* This line ends at end of (accessible part of) buffer.
947 There is no newline to count. */
948 adjust = Z - tlendpos - charstart_next_line[left];
949 else
950 /* This line ends in a newline.
951 Must take account of the newline and the rest of the
952 text that follows. */
953 adjust = Z - tlendpos + 1 - charstart_next_line[left];
955 adjust_window_charstarts (w, this_line_vpos, adjust);
958 if (XFASTINT (w->width) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w))))
959 preserve_other_columns (w);
960 goto update;
962 else
963 goto cancel;
965 else if (PT == XFASTINT (w->last_point)
966 /* Make sure the cursor was last displayed
967 in this window. Otherwise we have to reposition it. */
968 && XINT (w->top) <= FRAME_CURSOR_Y (selected_frame)
969 && (XINT (w->top) + XINT (w->height)
970 > FRAME_CURSOR_Y (selected_frame)))
972 if (!must_finish)
974 do_pending_window_change ();
975 return;
977 goto update;
979 /* If highlighting the region, or if the cursor is in the echo area,
980 then we can't just move the cursor. */
981 else if (! (!NILP (Vtransient_mark_mode)
982 && !NILP (current_buffer->mark_active))
983 && NILP (w->region_showing)
984 && !cursor_in_echo_area)
986 pos = *compute_motion (tlbufpos, 0,
987 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
989 PT, 2, - (1 << (SHORTBITS - 1)),
990 window_internal_width (w) - 1,
991 XINT (w->hscroll),
992 pos_tab_offset (w, tlbufpos), w);
993 if (pos.vpos < 1)
995 int width = window_internal_width (w) - 1;
996 FRAME_CURSOR_X (selected_frame)
997 = XFASTINT (w->left) + minmax (0, pos.hpos, width);
998 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
999 goto update;
1001 else
1002 goto cancel;
1004 cancel:
1005 /* Text changed drastically or point moved off of line */
1006 cancel_line (this_line_vpos, selected_frame);
1009 this_line_bufpos = 0;
1010 all_windows |= buffer_shared > 1;
1012 clear_face_cache_count++;
1014 if (all_windows)
1016 Lisp_Object tail, frame;
1018 #ifdef HAVE_FACES
1019 /* Clear the face cache, only when we do a full redisplay
1020 and not too often either. */
1021 if (clear_face_cache_count > 1000)
1023 clear_face_cache ();
1024 clear_face_cache_count = 0;
1026 #endif
1028 /* Recompute # windows showing selected buffer.
1029 This will be incremented each time such a window is displayed. */
1030 buffer_shared = 0;
1032 FOR_EACH_FRAME (tail, frame)
1034 FRAME_PTR f = XFRAME (frame);
1035 if (! FRAME_TERMCAP_P (f) || f == selected_frame)
1038 /* Mark all the scroll bars to be removed; we'll redeem the ones
1039 we want when we redisplay their windows. */
1040 if (condemn_scroll_bars_hook)
1041 (*condemn_scroll_bars_hook) (f);
1043 if (FRAME_VISIBLE_P (f))
1044 redisplay_windows (FRAME_ROOT_WINDOW (f));
1046 /* Any scroll bars which redisplay_windows should have nuked
1047 should now go away. */
1048 if (judge_scroll_bars_hook)
1049 (*judge_scroll_bars_hook) (f);
1053 else if (FRAME_VISIBLE_P (selected_frame))
1055 redisplay_window (selected_window, 1);
1056 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
1057 preserve_other_columns (w);
1060 update:
1061 /* Prevent various kinds of signals during display update.
1062 stdio is not robust about handling signals,
1063 which can cause an apparent I/O error. */
1064 if (interrupt_input)
1065 unrequest_sigio ();
1066 stop_polling ();
1068 #ifdef MULTI_FRAME
1069 if (all_windows)
1071 Lisp_Object tail;
1073 pause = 0;
1075 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
1077 FRAME_PTR f;
1079 if (!FRAMEP (XCONS (tail)->car))
1080 continue;
1082 f = XFRAME (XCONS (tail)->car);
1084 if ((! FRAME_TERMCAP_P (f) || f == selected_frame)
1085 && FRAME_VISIBLE_P (f))
1087 pause |= update_frame (f, 0, 0);
1088 if (!pause)
1090 mark_window_display_accurate (f->root_window, 1);
1091 if (frame_up_to_date_hook != 0)
1092 (*frame_up_to_date_hook) (f);
1097 else
1098 #endif /* MULTI_FRAME */
1100 if (FRAME_VISIBLE_P (selected_frame))
1101 pause = update_frame (selected_frame, 0, 0);
1102 else
1103 pause = 0;
1105 /* We may have called echo_area_display at the top of this
1106 function. If the echo area is on another frame, that may
1107 have put text on a frame other than the selected one, so the
1108 above call to update_frame would not have caught it. Catch
1109 it here. */
1111 Lisp_Object mini_window;
1112 FRAME_PTR mini_frame;
1114 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
1115 mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
1117 if (mini_frame != selected_frame
1118 && ! FRAME_TERMCAP_P (mini_frame))
1119 pause |= update_frame (mini_frame, 0, 0);
1123 /* If frame does not match, prevent doing single-line-update next time.
1124 Also, don't forget to check every line to update the arrow. */
1125 if (pause)
1127 this_line_bufpos = 0;
1128 if (!NILP (last_arrow_position))
1130 last_arrow_position = Qt;
1131 last_arrow_string = Qt;
1133 /* If we pause after scrolling, some lines in current_frame
1134 may be null, so preserve_other_columns won't be able to
1135 preserve all the vertical-bar separators. So, avoid using it
1136 in that case. */
1137 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
1138 update_mode_lines = 1;
1141 /* Now text on frame agrees with windows, so
1142 put info into the windows for partial redisplay to follow */
1144 if (!pause)
1146 register struct buffer *b = XBUFFER (w->buffer);
1148 blank_end_of_window = 0;
1149 unchanged_modified = BUF_MODIFF (b);
1150 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1151 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1153 XSETFASTINT (w->last_point, BUF_PT (b));
1154 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1155 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1157 if (all_windows)
1158 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1159 else
1161 b->clip_changed = 0;
1162 w->update_mode_line = Qnil;
1163 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1164 w->window_end_valid = w->buffer;
1165 last_arrow_position = Voverlay_arrow_position;
1166 last_arrow_string = Voverlay_arrow_string;
1167 if (do_verify_charstarts)
1168 verify_charstarts (w);
1169 if (frame_up_to_date_hook != 0)
1170 (*frame_up_to_date_hook) (selected_frame);
1172 update_mode_lines = 0;
1173 windows_or_buffers_changed = 0;
1176 /* Start SIGIO interrupts coming again.
1177 Having them off during the code above
1178 makes it less likely one will discard output,
1179 but not impossible, since there might be stuff
1180 in the system buffer here.
1181 But it is much hairier to try to do anything about that. */
1183 if (interrupt_input)
1184 request_sigio ();
1185 start_polling ();
1187 /* Change frame size now if a change is pending. */
1188 do_pending_window_change ();
1190 /* If we just did a pending size change, redisplay again
1191 for the new size. */
1192 if (windows_or_buffers_changed && !pause)
1193 redisplay ();
1196 /* Redisplay, but leave alone any recent echo area message
1197 unless another message has been requested in its place.
1199 This is useful in situations where you need to redisplay but no
1200 user action has occurred, making it inappropriate for the message
1201 area to be cleared. See tracking_off and
1202 wait_reading_process_input for examples of these situations. */
1204 redisplay_preserve_echo_area ()
1206 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1208 echo_area_glyphs = previous_echo_glyphs;
1209 redisplay ();
1210 echo_area_glyphs = 0;
1212 else
1213 redisplay ();
1216 void
1217 mark_window_display_accurate (window, flag)
1218 Lisp_Object window;
1219 int flag;
1221 register struct window *w;
1223 for (;!NILP (window); window = w->next)
1225 if (!WINDOWP (window)) abort ();
1226 w = XWINDOW (window);
1228 if (!NILP (w->buffer))
1230 XSETFASTINT (w->last_modified,
1231 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1233 /* Record if we are showing a region, so can make sure to
1234 update it fully at next redisplay. */
1235 w->region_showing = (!NILP (Vtransient_mark_mode)
1236 && !NILP (XBUFFER (w->buffer)->mark_active)
1237 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1238 : Qnil);
1241 w->window_end_valid = w->buffer;
1242 w->update_mode_line = Qnil;
1243 if (!NILP (w->buffer))
1244 XBUFFER (w->buffer)->clip_changed = 0;
1246 if (!NILP (w->vchild))
1247 mark_window_display_accurate (w->vchild, flag);
1248 if (!NILP (w->hchild))
1249 mark_window_display_accurate (w->hchild, flag);
1252 if (flag)
1254 last_arrow_position = Voverlay_arrow_position;
1255 last_arrow_string = Voverlay_arrow_string;
1257 else
1259 /* t is unequal to any useful value of Voverlay_arrow_... */
1260 last_arrow_position = Qt;
1261 last_arrow_string = Qt;
1265 /* Update the menu bar item list for frame F.
1266 This has to be done before we start to fill in any display lines,
1267 because it can call eval.
1269 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1271 static void
1272 update_menu_bar (f, save_match_data)
1273 FRAME_PTR f;
1274 int save_match_data;
1276 struct buffer *old = current_buffer;
1277 Lisp_Object window;
1278 register struct window *w;
1280 window = FRAME_SELECTED_WINDOW (f);
1281 w = XWINDOW (window);
1283 if (update_mode_lines)
1284 w->update_mode_line = Qt;
1286 if (
1287 #ifdef USE_X_TOOLKIT
1288 FRAME_EXTERNAL_MENU_BAR (f)
1289 #else
1290 FRAME_MENU_BAR_LINES (f) > 0
1291 #endif
1294 /* If the user has switched buffers or windows, we need to
1295 recompute to reflect the new bindings. But we'll
1296 recompute when update_mode_lines is set too; that means
1297 that people can use force-mode-line-update to request
1298 that the menu bar be recomputed. The adverse effect on
1299 the rest of the redisplay algorithm is about the same as
1300 windows_or_buffers_changed anyway. */
1301 if (windows_or_buffers_changed
1302 || !NILP (w->update_mode_line)
1303 || (XFASTINT (w->last_modified) < MODIFF
1304 && (XFASTINT (w->last_modified)
1305 <= BUF_SAVE_MODIFF (XBUFFER (w->buffer))))
1306 || ((!NILP (Vtransient_mark_mode)
1307 && !NILP (XBUFFER (w->buffer)->mark_active))
1308 != !NILP (w->region_showing)))
1310 struct buffer *prev = current_buffer;
1311 int count = specpdl_ptr - specpdl;
1313 set_buffer_internal_1 (XBUFFER (w->buffer));
1314 if (save_match_data)
1315 record_unwind_protect (Fstore_match_data, Fmatch_data ());
1316 if (NILP (Voverriding_local_map_menu_flag))
1318 specbind (Qoverriding_terminal_local_map, Qnil);
1319 specbind (Qoverriding_local_map, Qnil);
1322 /* Run the Lucid hook. */
1323 call1 (Vrun_hooks, Qactivate_menubar_hook);
1324 /* If it has changed current-menubar from previous value,
1325 really recompute the menubar from the value. */
1326 if (! NILP (Vlucid_menu_bar_dirty_flag))
1327 call0 (Qrecompute_lucid_menubar);
1328 call1 (Vrun_hooks, Qmenu_bar_update_hook);
1329 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1330 #ifdef USE_X_TOOLKIT
1331 set_frame_menubar (f, 0, 0);
1332 #endif /* USE_X_TOOLKIT */
1334 unbind_to (count, Qnil);
1335 set_buffer_internal_1 (prev);
1340 int do_id = 1;
1342 /* Redisplay WINDOW and its subwindows and siblings. */
1344 static void
1345 redisplay_windows (window)
1346 Lisp_Object window;
1348 for (; !NILP (window); window = XWINDOW (window)->next)
1349 redisplay_window (window, 0);
1352 /* Redisplay window WINDOW and its subwindows. */
1354 static void
1355 redisplay_window (window, just_this_one)
1356 Lisp_Object window;
1357 int just_this_one;
1359 register struct window *w = XWINDOW (window);
1360 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1361 int height;
1362 register int lpoint = PT;
1363 struct buffer *old = current_buffer;
1364 register int width = window_internal_width (w) - 1;
1365 register int startp;
1366 register int hscroll = XINT (w->hscroll);
1367 struct position pos;
1368 int opoint = PT;
1369 int tem;
1370 int update_mode_line;
1371 struct Lisp_Vector *dp = window_display_table (w);
1373 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1375 /* If this is a combination window, do its children; that's all. */
1377 if (!NILP (w->vchild))
1379 redisplay_windows (w->vchild);
1380 return;
1382 if (!NILP (w->hchild))
1384 redisplay_windows (w->hchild);
1385 return;
1387 if (NILP (w->buffer))
1388 abort ();
1390 height = window_internal_height (w);
1391 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1392 if (XBUFFER (w->buffer)->clip_changed)
1393 update_mode_line = 1;
1395 if (MINI_WINDOW_P (w))
1397 if (w == XWINDOW (echo_area_window) && echo_area_glyphs)
1398 /* We've already displayed the echo area glyphs in this window. */
1399 goto finish_scroll_bars;
1400 else if (w != XWINDOW (minibuf_window))
1402 /* This is a minibuffer, but it's not the currently active one,
1403 so clear it. */
1404 int vpos = XFASTINT (w->top);
1405 int i;
1407 for (i = 0; i < height; i++)
1409 get_display_line (f, vpos + i, 0);
1410 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
1413 goto finish_scroll_bars;
1417 /* Otherwise set up data on this window; select its buffer and point value */
1419 if (update_mode_line)
1420 set_buffer_internal_1 (XBUFFER (w->buffer));
1421 else
1422 set_buffer_temp (XBUFFER (w->buffer));
1424 opoint = PT;
1426 /* If %c is in mode line, update it if needed. */
1427 if (!NILP (w->column_number_displayed)
1428 /* This alternative quickly identifies a common case
1429 where no change is needed. */
1430 && !(PT == XFASTINT (w->last_point)
1431 && XFASTINT (w->last_modified) >= MODIFF)
1432 && XFASTINT (w->column_number_displayed) != current_column ())
1433 update_mode_line = 1;
1435 /* Count number of windows showing the selected buffer.
1436 An indirect buffer counts as its base buffer. */
1438 if (!just_this_one)
1440 struct buffer *current_base, *window_base;
1441 current_base = current_buffer;
1442 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1443 if (current_base->base_buffer)
1444 current_base = current_base->base_buffer;
1445 if (window_base->base_buffer)
1446 window_base = window_base->base_buffer;
1447 if (current_base == window_base)
1448 buffer_shared++;
1451 /* POINT refers normally to the selected window.
1452 For any other window, set up appropriate value. */
1454 if (!EQ (window, selected_window))
1456 int new_pt = marker_position (w->pointm);
1457 if (new_pt < BEGV)
1459 new_pt = BEGV;
1460 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1462 else if (new_pt > (ZV - 1))
1464 new_pt = ZV;
1465 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1467 /* We don't use SET_PT so that the point-motion hooks don't run. */
1468 BUF_PT (current_buffer) = new_pt;
1471 /* If any of the character widths specified in the display table
1472 have changed, invalidate the width run cache. It's true that this
1473 may be a bit late to catch such changes, but the rest of
1474 redisplay goes (non-fatally) haywire when the display table is
1475 changed, so why should we worry about doing any better? */
1476 if (current_buffer->width_run_cache)
1478 struct Lisp_Vector *disptab = buffer_display_table ();
1480 if (! disptab_matches_widthtab (disptab,
1481 XVECTOR (current_buffer->width_table)))
1483 invalidate_region_cache (current_buffer,
1484 current_buffer->width_run_cache,
1485 BEG, Z);
1486 recompute_width_table (current_buffer, disptab);
1490 /* If window-start is screwed up, choose a new one. */
1491 if (XMARKER (w->start)->buffer != current_buffer)
1492 goto recenter;
1494 startp = marker_position (w->start);
1496 /* Handle case where place to start displaying has been specified,
1497 unless the specified location is outside the accessible range. */
1498 if (!NILP (w->force_start))
1500 /* Forget any recorded base line for line number display. */
1501 w->base_line_number = Qnil;
1502 /* Redisplay the mode line. Select the buffer properly for that.
1503 Also, run the hook window-scroll-functions
1504 because we have scrolled. */
1505 if (!update_mode_line
1506 || ! NILP (Vwindow_scroll_functions))
1508 Lisp_Object temp[3];
1510 set_buffer_temp (old);
1511 set_buffer_internal_1 (XBUFFER (w->buffer));
1512 update_mode_line = 1;
1513 w->update_mode_line = Qt;
1514 if (! NILP (Vwindow_scroll_functions))
1515 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1516 make_number (startp));
1518 w->force_start = Qnil;
1519 XSETFASTINT (w->last_modified, 0);
1520 if (startp < BEGV) startp = BEGV;
1521 if (startp > ZV) startp = ZV;
1522 try_window (window, startp);
1523 if (cursor_vpos < 0)
1525 /* If point does not appear, move point so it does appear */
1526 pos = *compute_motion (startp, 0,
1527 (((EQ (window, minibuf_window)
1528 && startp == BEG)
1529 ? minibuf_prompt_width : 0)
1530 + (hscroll ? 1 - hscroll : 0)),
1532 ZV, height / 2,
1533 - (1 << (SHORTBITS - 1)),
1534 width, hscroll, pos_tab_offset (w, startp), w);
1535 BUF_PT (current_buffer) = pos.bufpos;
1536 if (w != XWINDOW (selected_window))
1537 Fset_marker (w->pointm, make_number (PT), Qnil);
1538 else
1540 if (current_buffer == old)
1541 lpoint = PT;
1542 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1543 + minmax (0, pos.hpos, width));
1544 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1546 /* If we are highlighting the region,
1547 then we just changed the region, so redisplay to show it. */
1548 if (!NILP (Vtransient_mark_mode)
1549 && !NILP (current_buffer->mark_active))
1551 cancel_my_columns (XWINDOW (window));
1552 try_window (window, startp);
1555 goto done;
1558 /* Handle case where text has not changed, only point,
1559 and it has not moved off the frame */
1561 /* This code is not used for minibuffer for the sake of
1562 the case of redisplaying to replace an echo area message;
1563 since in that case the minibuffer contents per se are usually unchanged.
1564 This code is of no real use in the minibuffer since
1565 the handling of this_line_bufpos, etc.,
1566 in redisplay handles the same cases. */
1568 if (XFASTINT (w->last_modified) >= MODIFF
1569 && PT >= startp && !current_buffer->clip_changed
1570 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
1571 /* If force-mode-line-update was called, really redisplay;
1572 that's how redisplay is forced after e.g. changing
1573 buffer-invisibility-spec. */
1574 && NILP (w->update_mode_line)
1575 /* Can't use this case if highlighting a region. */
1576 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1577 && NILP (w->region_showing)
1578 /* If end pos is out of date, scroll bar and percentage will be wrong */
1579 && INTEGERP (w->window_end_vpos)
1580 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1581 && !EQ (window, minibuf_window))
1583 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0,
1584 PT, height, 0, width, hscroll,
1585 pos_tab_offset (w, startp), w);
1587 if (pos.vpos < height)
1589 /* Ok, point is still on frame */
1590 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1592 /* These variables are supposed to be origin 1 */
1593 FRAME_CURSOR_X (f) = (XFASTINT (w->left)
1594 + minmax (0, pos.hpos, width));
1595 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1597 /* This doesn't do the trick, because if a window to the right of
1598 this one must be redisplayed, this does nothing because there
1599 is nothing in DesiredFrame yet, and then the other window is
1600 redisplayed, making likes that are empty in this window's columns.
1601 if (XFASTINT (w->width) != FRAME_WIDTH (f))
1602 preserve_my_columns (w);
1604 goto done;
1606 /* Don't bother trying redisplay with same start;
1607 we already know it will lose */
1609 /* If current starting point was originally the beginning of a line
1610 but no longer is, find a new starting point. */
1611 else if (!NILP (w->start_at_line_beg)
1612 && !(startp <= BEGV
1613 || FETCH_CHAR (startp - 1) == '\n'))
1615 goto recenter;
1617 else if (just_this_one && !MINI_WINDOW_P (w)
1618 && PT >= startp
1619 && XFASTINT (w->last_modified)
1620 /* or else vmotion on first line won't work. */
1621 && ! NILP (w->start_at_line_beg)
1622 && ! EQ (w->window_end_valid, Qnil)
1623 && do_id && !current_buffer->clip_changed
1624 && !blank_end_of_window
1625 && XFASTINT (w->width) == FRAME_WIDTH (f)
1626 /* Can't use this case if highlighting a region. */
1627 && !(!NILP (Vtransient_mark_mode)
1628 && !NILP (current_buffer->mark_active))
1629 /* Don't use try_window_id if newline
1630 doesn't display as the end of a line. */
1631 && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n')))
1632 && NILP (w->region_showing)
1633 && EQ (last_arrow_position, Voverlay_arrow_position)
1634 && EQ (last_arrow_string, Voverlay_arrow_string)
1635 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1636 && tem != -2)
1638 /* tem > 0 means success. tem == -1 means choose new start.
1639 tem == -2 means try again with same start,
1640 and nothing but whitespace follows the changed stuff.
1641 tem == 0 means try again with same start. */
1642 if (tem > 0)
1643 goto done;
1645 else if (startp >= BEGV && startp <= ZV
1646 /* Avoid starting display at end of buffer! */
1647 && (startp < ZV || startp == BEGV
1648 || (XFASTINT (w->last_modified) >= MODIFF)))
1650 /* Try to redisplay starting at same place as before */
1651 /* If point has not moved off frame, accept the results */
1652 try_window (window, startp);
1653 if (cursor_vpos >= 0)
1655 if (!just_this_one || current_buffer->clip_changed
1656 || beg_unchanged < startp)
1657 /* Forget any recorded base line for line number display. */
1658 w->base_line_number = Qnil;
1659 goto done;
1661 else
1662 cancel_my_columns (w);
1665 XSETFASTINT (w->last_modified, 0);
1666 /* Redisplay the mode line. Select the buffer properly for that. */
1667 if (!update_mode_line)
1669 set_buffer_temp (old);
1670 set_buffer_internal_1 (XBUFFER (w->buffer));
1671 update_mode_line = 1;
1672 w->update_mode_line = Qt;
1675 /* Try to scroll by specified few lines */
1677 if (scroll_step && !current_buffer->clip_changed)
1679 if (PT > startp)
1681 pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w);
1682 if (pos.vpos >= height)
1683 goto scroll_fail;
1686 pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w);
1688 if (PT >= pos.bufpos)
1690 if (! NILP (Vwindow_scroll_functions))
1691 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1692 make_number (pos.bufpos));
1693 try_window (window, pos.bufpos);
1694 if (cursor_vpos >= 0)
1696 if (!just_this_one || current_buffer->clip_changed
1697 || beg_unchanged < startp)
1698 /* Forget any recorded base line for line number display. */
1699 w->base_line_number = Qnil;
1700 goto done;
1702 else
1703 cancel_my_columns (w);
1705 scroll_fail: ;
1708 /* Finally, just choose place to start which centers point */
1710 recenter:
1711 /* Forget any previously recorded base line for line number display. */
1712 w->base_line_number = Qnil;
1714 pos = *vmotion (PT, - (height / 2), w);
1715 if (! NILP (Vwindow_scroll_functions))
1716 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1717 make_number (pos.bufpos));
1718 try_window (window, pos.bufpos);
1720 startp = marker_position (w->start);
1721 w->start_at_line_beg
1722 = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
1724 done:
1725 if ((update_mode_line
1726 /* If window not full width, must redo its mode line
1727 if the window to its side is being redone */
1728 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
1729 || INTEGERP (w->base_line_pos)
1730 || (!NILP (w->column_number_displayed)
1731 && XFASTINT (w->column_number_displayed) != current_column ()))
1732 && height != XFASTINT (w->height))
1733 display_mode_line (w);
1734 if (! line_number_displayed
1735 && ! BUFFERP (w->base_line_pos))
1737 w->base_line_pos = Qnil;
1738 w->base_line_number = Qnil;
1741 /* When we reach a frame's selected window, redo the frame's menu bar. */
1742 if (update_mode_line
1743 #ifdef USE_X_TOOLKIT
1744 && FRAME_EXTERNAL_MENU_BAR (f)
1745 #else
1746 && FRAME_MENU_BAR_LINES (f) > 0
1747 #endif
1748 && EQ (FRAME_SELECTED_WINDOW (f), window))
1749 display_menu_bar (w);
1751 finish_scroll_bars:
1752 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
1754 int start, end, whole;
1756 /* Calculate the start and end positions for the current window.
1757 At some point, it would be nice to choose between scrollbars
1758 which reflect the whole buffer size, with special markers
1759 indicating narrowing, and scrollbars which reflect only the
1760 visible region.
1762 Note that minibuffers sometimes aren't displaying any text. */
1763 if (! MINI_WINDOW_P (w)
1764 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1766 whole = ZV - BEGV;
1767 start = marker_position (w->start) - BEGV;
1768 /* I don't think this is guaranteed to be right. For the
1769 moment, we'll pretend it is. */
1770 end = (Z - XINT (w->window_end_pos)) - BEGV;
1772 if (end < start) end = start;
1773 if (whole < (end - start)) whole = end - start;
1775 else
1776 start = end = whole = 0;
1778 /* Indicate what this scroll bar ought to be displaying now. */
1779 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
1781 /* Note that we actually used the scroll bar attached to this window,
1782 so it shouldn't be deleted at the end of redisplay. */
1783 (*redeem_scroll_bar_hook) (w);
1786 BUF_PT (current_buffer) = opoint;
1787 if (update_mode_line)
1788 set_buffer_internal_1 (old);
1789 else
1790 set_buffer_temp (old);
1791 BUF_PT (current_buffer) = lpoint;
1794 /* Do full redisplay on one window, starting at position `pos'. */
1796 static void
1797 try_window (window, pos)
1798 Lisp_Object window;
1799 register int pos;
1801 register struct window *w = XWINDOW (window);
1802 register int height = window_internal_height (w);
1803 register int vpos = XFASTINT (w->top);
1804 register int last_text_vpos = vpos;
1805 int tab_offset = pos_tab_offset (w, pos);
1806 FRAME_PTR f = XFRAME (w->frame);
1807 int width = window_internal_width (w) - 1;
1808 struct position val;
1810 Fset_marker (w->start, make_number (pos), Qnil);
1811 cursor_vpos = -1;
1812 overlay_arrow_seen = 0;
1813 zv_strings_seen = 0;
1814 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1816 while (--height >= 0)
1818 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1819 tab_offset += width;
1820 /* For the first line displayed, display_text_line
1821 subtracts the prompt width from the tab offset.
1822 But it does not affect the value of our variable tab_offset.
1823 So we do the subtraction again,
1824 for the sake of continuation lines of that first line. */
1825 if (MINI_WINDOW_P (w) && vpos == XFASTINT (w->top))
1826 tab_offset -= minibuf_prompt_width;
1828 if (val.vpos) tab_offset = 0;
1829 vpos++;
1830 if (pos != val.bufpos)
1832 int invis = 0;
1833 #ifdef USE_TEXT_PROPERTIES
1834 Lisp_Object invis_prop;
1835 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
1836 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
1837 #endif
1839 last_text_vpos
1840 /* Next line, unless prev line ended in end of buffer with no cr */
1841 = vpos - (val.vpos
1842 && (FETCH_CHAR (val.bufpos - 1) != '\n' || invis));
1844 pos = val.bufpos;
1847 /* If last line is continued in middle of character,
1848 include the split character in the text considered on the frame */
1849 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1850 pos++;
1852 /* If bottom just moved off end of frame, change mode line percentage. */
1853 if (XFASTINT (w->window_end_pos) == 0
1854 && Z != pos)
1855 w->update_mode_line = Qt;
1857 /* Say where last char on frame will be, once redisplay is finished. */
1858 XSETFASTINT (w->window_end_pos, Z - pos);
1859 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
1860 /* But that is not valid info until redisplay finishes. */
1861 w->window_end_valid = Qnil;
1864 /* Try to redisplay when buffer is modified locally,
1865 computing insert/delete line to preserve text outside
1866 the bounds of the changes.
1867 Return 1 if successful, 0 if if cannot tell what to do,
1868 or -1 to tell caller to find a new window start,
1869 or -2 to tell caller to do normal redisplay with same window start. */
1871 static int
1872 try_window_id (window)
1873 Lisp_Object window;
1875 int pos;
1876 register struct window *w = XWINDOW (window);
1877 register int height = window_internal_height (w);
1878 FRAME_PTR f = XFRAME (w->frame);
1879 int top = XFASTINT (w->top);
1880 int start = marker_position (w->start);
1881 int width = window_internal_width (w) - 1;
1882 int hscroll = XINT (w->hscroll);
1883 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
1884 int did_motion;
1885 register int vpos;
1886 register int i, tem;
1887 int last_text_vpos = 0;
1888 int stop_vpos;
1889 int selective = (INTEGERP (current_buffer->selective_display)
1890 ? XINT (current_buffer->selective_display)
1891 : !NILP (current_buffer->selective_display) ? -1 : 0);
1893 struct position val, bp, ep, xp, pp;
1894 int scroll_amount = 0;
1895 int delta;
1896 int tab_offset, epto;
1898 if (GPT - BEG < beg_unchanged)
1899 beg_unchanged = GPT - BEG;
1900 if (Z - GPT < end_unchanged)
1901 end_unchanged = Z - GPT;
1903 if (beg_unchanged + BEG < start)
1904 return 0; /* Give up if changes go above top of window */
1906 /* Find position before which nothing is changed. */
1907 bp = *compute_motion (start, 0, lmargin, 0,
1908 min (ZV, beg_unchanged + BEG), height, 0,
1909 width, hscroll, pos_tab_offset (w, start), w);
1910 if (bp.vpos >= height)
1912 if (PT < bp.bufpos)
1914 /* All changes are below the frame, and point is on the frame.
1915 We don't need to change the frame at all.
1916 But we need to update window_end_pos to account for
1917 any change in buffer size. */
1918 bp = *compute_motion (start, 0, lmargin, 0,
1919 Z, height, 0,
1920 width, hscroll, pos_tab_offset (w, start), w);
1921 XSETFASTINT (w->window_end_vpos, height);
1922 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
1923 goto findpoint;
1925 return 0;
1928 vpos = bp.vpos;
1930 /* Find beginning of that frame line. Must display from there. */
1931 bp = *vmotion (bp.bufpos, 0, w);
1933 pos = bp.bufpos;
1934 val.hpos = lmargin;
1935 if (pos < start)
1936 return -1;
1938 did_motion = 0;
1939 /* If about to start displaying at the beginning of a continuation line,
1940 really start with previous frame line, in case it was not
1941 continued when last redisplayed */
1942 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
1944 /* Likewise if we have to worry about selective display. */
1945 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
1947 bp = *vmotion (bp.bufpos, -1, w);
1948 --vpos;
1949 pos = bp.bufpos;
1952 if (bp.contin && bp.hpos != lmargin)
1954 val.hpos = bp.prevhpos - width + lmargin;
1955 did_motion = 1;
1956 pos--;
1959 bp.vpos = vpos;
1961 /* Find first visible newline after which no more is changed. */
1962 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
1963 if (selective > 0)
1964 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
1965 tem = find_next_newline (tem, 1);
1967 /* Compute the cursor position after that newline. */
1968 ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem,
1969 height, - (1 << (SHORTBITS - 1)),
1970 width, hscroll, pos_tab_offset (w, bp.bufpos), w);
1972 /* If changes reach past the text available on the frame,
1973 just display rest of frame. */
1974 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
1975 stop_vpos = height;
1976 else
1977 stop_vpos = ep.vpos;
1979 /* If no newline before ep, the line ep is on includes some changes
1980 that must be displayed. Make sure we don't stop before it. */
1981 /* Also, if changes reach all the way until ep.bufpos,
1982 it is possible that something was deleted after the
1983 newline before it, so the following line must be redrawn. */
1984 if (stop_vpos == ep.vpos
1985 && (ep.bufpos == BEGV
1986 || FETCH_CHAR (ep.bufpos - 1) != '\n'
1987 || ep.bufpos == Z - end_unchanged))
1988 stop_vpos = ep.vpos + 1;
1990 cursor_vpos = -1;
1991 overlay_arrow_seen = 0;
1992 zv_strings_seen = 0;
1994 /* If changes do not reach to bottom of window,
1995 figure out how much to scroll the rest of the window */
1996 if (stop_vpos < height)
1998 /* Now determine how far up or down the rest of the window has moved */
1999 epto = pos_tab_offset (w, ep.bufpos);
2000 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2001 Z - XFASTINT (w->window_end_pos),
2002 10000, 0, width, hscroll, epto, w);
2003 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
2005 /* Is everything on frame below the changes whitespace?
2006 If so, no scrolling is really necessary. */
2007 for (i = ep.bufpos; i < xp.bufpos; i++)
2009 tem = FETCH_CHAR (i);
2010 if (tem != ' ' && tem != '\n' && tem != '\t')
2011 break;
2013 if (i == xp.bufpos)
2014 return -2;
2016 XSETFASTINT (w->window_end_vpos,
2017 XFASTINT (w->window_end_vpos) + scroll_amount);
2019 /* Before doing any scrolling, verify that point will be on frame. */
2020 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height))
2022 if (PT <= xp.bufpos)
2024 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2025 PT, height, - (1 << (SHORTBITS - 1)),
2026 width, hscroll, epto, w);
2028 else
2030 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1,
2031 PT, height, - (1 << (SHORTBITS - 1)),
2032 width, hscroll,
2033 pos_tab_offset (w, xp.bufpos), w);
2035 if (pp.bufpos < PT || pp.vpos == height)
2036 return 0;
2037 cursor_vpos = pp.vpos + top;
2038 cursor_hpos = XFASTINT (w->left) + minmax (0, pp.hpos, width);
2041 if (stop_vpos - scroll_amount >= height
2042 || ep.bufpos == xp.bufpos)
2044 if (scroll_amount < 0)
2045 stop_vpos -= scroll_amount;
2046 scroll_amount = 0;
2047 /* In this path, we have altered window_end_vpos
2048 and not left it negative.
2049 We must make sure that, in case display is preempted
2050 before the frame changes to reflect what we do here,
2051 further updates will not come to try_window_id
2052 and assume the frame and window_end_vpos match. */
2053 blank_end_of_window = 1;
2055 else if (!scroll_amount)
2057 /* Even if we don't need to scroll, we must adjust the
2058 charstarts of subsequent lines (that we won't redisplay)
2059 according to the amount of text inserted or deleted. */
2060 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2061 int adjust = ep.bufpos - oldpos;
2062 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
2064 else if (bp.bufpos == Z - end_unchanged)
2066 /* If reprinting everything is nearly as fast as scrolling,
2067 don't bother scrolling. Can happen if lines are short. */
2068 if (scroll_cost (f, bp.vpos + top - scroll_amount,
2069 top + height - max (0, scroll_amount),
2070 scroll_amount)
2071 > xp.bufpos - bp.bufpos - 20)
2072 /* Return "try normal display with same window-start."
2073 Too bad we can't prevent further scroll-thinking. */
2074 return -2;
2075 /* If pure deletion, scroll up as many lines as possible.
2076 In common case of killing a line, this can save the
2077 following line from being overwritten by scrolling
2078 and therefore having to be redrawn. */
2079 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
2080 top + height - max (0, scroll_amount),
2081 scroll_amount, bp.bufpos);
2082 if (!tem)
2083 stop_vpos = height;
2084 else
2086 /* scroll_frame_lines did not properly adjust subsequent
2087 lines' charstarts in the case where the text of the
2088 screen line at bp.vpos has changed.
2089 (This can happen in a deletion that ends in mid-line.)
2090 To adjust properly, we need to make things constent at
2091 the position ep.
2092 So do a second adjust to make that happen.
2093 Note that stop_vpos >= ep.vpos, so it is sufficient
2094 to update the charstarts for lines at ep.vpos and below. */
2095 int oldstart
2096 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2097 adjust_window_charstarts (w, ep.vpos + top - 1,
2098 ep.bufpos - oldstart);
2101 else if (scroll_amount)
2103 /* If reprinting everything is nearly as fast as scrolling,
2104 don't bother scrolling. Can happen if lines are short. */
2105 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2106 overestimate of cost of reprinting, since xp.bufpos
2107 would end up below the bottom of the window. */
2108 if (scroll_cost (f, ep.vpos + top - scroll_amount,
2109 top + height - max (0, scroll_amount),
2110 scroll_amount)
2111 > xp.bufpos - ep.bufpos - 20)
2112 /* Return "try normal display with same window-start."
2113 Too bad we can't prevent further scroll-thinking. */
2114 return -2;
2115 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
2116 top + height - max (0, scroll_amount),
2117 scroll_amount, ep.bufpos);
2118 if (!tem) stop_vpos = height;
2122 /* In any case, do not display past bottom of window */
2123 if (stop_vpos >= height)
2125 stop_vpos = height;
2126 scroll_amount = 0;
2129 /* Handle case where pos is before w->start --
2130 can happen if part of line had been clipped and is not clipped now */
2131 if (vpos == 0 && pos < marker_position (w->start))
2132 Fset_marker (w->start, make_number (pos), Qnil);
2134 /* Redisplay the lines where the text was changed */
2135 last_text_vpos = vpos;
2136 tab_offset = pos_tab_offset (w, pos);
2137 /* If we are starting display in mid-character, correct tab_offset
2138 to account for passing the line that that character really starts in. */
2139 if (val.hpos < lmargin)
2140 tab_offset += width;
2141 while (vpos < stop_vpos)
2143 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2144 tab_offset += width;
2145 if (val.vpos) tab_offset = 0;
2146 if (pos != val.bufpos)
2147 last_text_vpos
2148 /* Next line, unless prev line ended in end of buffer with no cr */
2149 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
2150 pos = val.bufpos;
2153 /* There are two cases:
2154 1) we have displayed down to the bottom of the window
2155 2) we have scrolled lines below stop_vpos by scroll_amount */
2157 if (vpos == height)
2159 /* If last line is continued in middle of character,
2160 include the split character in the text considered on the frame */
2161 if (val.hpos < lmargin)
2162 val.bufpos++;
2163 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2164 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2167 /* If scrolling made blank lines at window bottom,
2168 redisplay to fill those lines */
2169 if (scroll_amount < 0)
2171 /* Don't consider these lines for general-purpose scrolling.
2172 That will save time in the scrolling computation. */
2173 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2174 vpos = xp.vpos;
2175 pos = xp.bufpos;
2176 val.hpos = lmargin;
2177 if (pos == ZV)
2178 vpos = height + scroll_amount;
2179 else if (xp.contin && xp.hpos != lmargin)
2181 val.hpos = xp.prevhpos - width + lmargin;
2182 pos--;
2185 blank_end_of_window = 1;
2186 tab_offset = pos_tab_offset (w, pos);
2187 /* If we are starting display in mid-character, correct tab_offset
2188 to account for passing the line that that character starts in. */
2189 if (val.hpos < lmargin)
2190 tab_offset += width;
2192 while (vpos < height)
2194 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2195 tab_offset += width;
2196 if (val.vpos) tab_offset = 0;
2197 pos = val.bufpos;
2200 /* Here is a case where display_text_line sets cursor_vpos wrong.
2201 Make it be fixed up, below. */
2202 if (xp.bufpos == ZV
2203 && xp.bufpos == PT)
2204 cursor_vpos = -1;
2207 /* If bottom just moved off end of frame, change mode line percentage. */
2208 if (XFASTINT (w->window_end_pos) == 0
2209 && Z != val.bufpos)
2210 w->update_mode_line = Qt;
2212 /* Attempt to adjust end-of-text positions to new bottom line */
2213 if (scroll_amount)
2215 delta = height - xp.vpos;
2216 if (delta < 0
2217 || (delta > 0 && xp.bufpos <= ZV)
2218 || (delta == 0 && xp.hpos))
2220 val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w);
2221 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2222 XSETFASTINT (w->window_end_vpos,
2223 XFASTINT (w->window_end_vpos) + val.vpos);
2227 w->window_end_valid = Qnil;
2229 /* If point was not in a line that was displayed, find it */
2230 if (cursor_vpos < 0)
2232 findpoint:
2233 val = *compute_motion (start, 0, lmargin, 0, PT, 10000, 10000,
2234 width, hscroll, pos_tab_offset (w, start), w);
2235 /* Admit failure if point is off frame now */
2236 if (val.vpos >= height)
2238 for (vpos = 0; vpos < height; vpos++)
2239 cancel_line (vpos + top, f);
2240 return 0;
2242 cursor_vpos = val.vpos + top;
2243 cursor_hpos = XFASTINT (w->left) + minmax (0, val.hpos, width);
2246 FRAME_CURSOR_X (f) = cursor_hpos;
2247 FRAME_CURSOR_Y (f) = cursor_vpos;
2249 if (debug_end_pos)
2251 val = *compute_motion (start, 0, lmargin, 0, ZV,
2252 height, - (1 << (SHORTBITS - 1)),
2253 width, hscroll, pos_tab_offset (w, start), w);
2254 if (val.vpos != XFASTINT (w->window_end_vpos))
2255 abort ();
2256 if (XFASTINT (w->window_end_pos)
2257 != Z - val.bufpos)
2258 abort ();
2261 return 1;
2264 /* Mark a section of BUF as modified, but only for the sake of redisplay.
2265 This is useful for recording changes to overlays.
2267 We increment the buffer's modification timestamp and set the
2268 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
2269 as if the region of text between START and END had been modified;
2270 the redisplay code will check this against the windows' timestamps,
2271 and redraw the appropriate area of the buffer.
2273 However, if the buffer is unmodified, we bump the last-save
2274 timestamp as well, so that incrementing the timestamp doesn't fool
2275 Emacs into thinking that the buffer's text has been modified.
2277 Tweaking the timestamps shouldn't hurt the first-modification
2278 timestamps recorded in the undo records; those values aren't
2279 written until just before a real text modification is made, so they
2280 will never catch the timestamp value just before this function gets
2281 called. */
2283 void
2284 redisplay_region (buf, start, end)
2285 struct buffer *buf;
2286 int start, end;
2288 if (start == end)
2289 return;
2291 if (start > end)
2293 int temp = start;
2294 start = end; end = temp;
2297 /* If this is a buffer not in the selected window,
2298 we must do other windows. */
2299 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2300 windows_or_buffers_changed = 1;
2301 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2302 else if (buf != current_buffer)
2303 windows_or_buffers_changed = 1;
2304 /* If multiple windows show this buffer, we must do other windows. */
2305 else if (buffer_shared > 1)
2306 windows_or_buffers_changed = 1;
2307 else
2309 if (unchanged_modified == MODIFF)
2311 beg_unchanged = start - BEG;
2312 end_unchanged = Z - end;
2314 else
2316 if (Z - end < end_unchanged)
2317 end_unchanged = Z - end;
2318 if (start - BEG < beg_unchanged)
2319 beg_unchanged = start - BEG;
2323 /* Increment the buffer's time stamp, but also increment the save
2324 and autosave timestamps, so as not to screw up that timekeeping. */
2325 if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf))
2326 BUF_SAVE_MODIFF (buf)++;
2327 if (BUF_MODIFF (buf) == buf->auto_save_modified)
2328 buf->auto_save_modified++;
2330 BUF_MODIFF (buf) ++;
2334 /* Copy LEN glyphs starting address FROM to the rope TO.
2335 But don't actually copy the parts that would come in before S.
2336 Value is TO, advanced past the copied data.
2337 F is the frame we are displaying in. */
2339 static GLYPH *
2340 copy_part_of_rope (f, to, s, from, len, face)
2341 FRAME_PTR f;
2342 register GLYPH *to; /* Copy to here. */
2343 register GLYPH *s; /* Starting point. */
2344 Lisp_Object *from; /* Data to copy. */
2345 int len;
2346 int face; /* Face to apply to glyphs which don't specify one. */
2348 int n = len;
2349 register Lisp_Object *fp = from;
2350 /* These cache the results of the last call to compute_glyph_face. */
2351 int last_code = -1;
2352 int last_merged = 0;
2354 #ifdef HAVE_FACES
2355 if (! FRAME_TERMCAP_P (f))
2356 while (n--)
2358 int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2359 int facecode;
2361 if (FAST_GLYPH_FACE (glyph) == 0)
2362 /* If GLYPH has no face code, use FACE. */
2363 facecode = face;
2364 else if (FAST_GLYPH_FACE (glyph) == last_code)
2365 /* If it's same as previous glyph, use same result. */
2366 facecode = last_merged;
2367 else
2369 /* Merge this glyph's face and remember the result. */
2370 last_code = FAST_GLYPH_FACE (glyph);
2371 last_merged = facecode = compute_glyph_face (f, last_code, face);
2374 if (to >= s)
2375 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
2376 ++to;
2377 ++fp;
2379 else
2380 #endif
2381 while (n--)
2383 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2384 ++to;
2385 ++fp;
2387 return to;
2390 /* Correct a glyph by replacing its specified user-level face code
2391 with a displayable computed face code. */
2393 static GLYPH
2394 fix_glyph (f, glyph, cface)
2395 FRAME_PTR f;
2396 GLYPH glyph;
2397 int cface;
2399 #ifdef HAVE_FACES
2400 if (! FRAME_TERMCAP_P (f))
2402 if (FAST_GLYPH_FACE (glyph) != 0)
2403 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2404 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2406 #endif
2407 return glyph;
2410 /* Display one line of window W, starting at position START in W's buffer.
2412 Display starting at horizontal position HPOS, expressed relative to
2413 W's left edge. In situations where the text at START shouldn't
2414 start at the left margin (i.e. when the window is hscrolled, or
2415 we're continuing a line which left off in the midst of a
2416 multi-column character), HPOS should be negative; we throw away
2417 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2418 account.
2420 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2422 Display on position VPOS on the frame. It is origin 0, relative to
2423 the top of the frame, not W.
2425 Returns a STRUCT POSITION giving character to start next line with
2426 and where to display it, including a zero or negative hpos.
2427 The vpos field is not really a vpos; it is 1 unless the line is continued */
2429 struct position val_display_text_line;
2431 static struct position *
2432 display_text_line (w, start, vpos, hpos, taboffset)
2433 struct window *w;
2434 int start;
2435 int vpos;
2436 int hpos;
2437 int taboffset;
2439 register int pos = start;
2440 register int c;
2441 register GLYPH *p1;
2442 register int pause;
2443 register unsigned char *p;
2444 GLYPH *endp;
2445 register GLYPH *leftmargin;
2446 register GLYPH *p1prev;
2447 register GLYPH *p1start;
2448 int prevpos;
2449 int *charstart;
2450 FRAME_PTR f = XFRAME (w->frame);
2451 int tab_width = XINT (current_buffer->tab_width);
2452 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2453 int width = window_internal_width (w) - 1;
2454 struct position val;
2455 int lastpos;
2456 int invis;
2457 int last_invis_skip = 0;
2458 Lisp_Object last_invis_prop;
2459 int hscroll = XINT (w->hscroll);
2460 int truncate = (hscroll
2461 || (truncate_partial_width_windows
2462 && XFASTINT (w->width) < FRAME_WIDTH (f))
2463 || !NILP (current_buffer->truncate_lines));
2465 /* 1 if we should highlight the region. */
2466 int highlight_region
2467 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
2468 int region_beg, region_end;
2470 int selective = (INTEGERP (current_buffer->selective_display)
2471 ? XINT (current_buffer->selective_display)
2472 : !NILP (current_buffer->selective_display) ? -1 : 0);
2473 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2474 register struct Lisp_Vector *dp = window_display_table (w);
2476 Lisp_Object default_invis_vector[3];
2477 /* Number of characters of ellipsis to display after an invisible line
2478 if it calls for an ellipsis.
2479 Note that this value can be nonzero regardless of whether
2480 selective display is enabled--you must check that separately. */
2481 int selective_rlen
2482 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2483 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2484 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
2485 /* This is the sequence of Lisp objects to display
2486 when there are invisible lines. */
2487 Lisp_Object *invis_vector_contents
2488 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2489 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2490 : default_invis_vector);
2492 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2493 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2494 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2495 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2497 /* The next buffer location at which the face should change, due
2498 to overlays or text property changes. */
2499 int next_face_change;
2501 /* The next location where the `invisible' property changes, or an
2502 overlay starts or ends. */
2503 int next_boundary;
2505 /* The face we're currently using. */
2506 int current_face = 0;
2507 int i;
2509 XSETFASTINT (default_invis_vector[2], '.');
2510 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2512 hpos += XFASTINT (w->left);
2513 get_display_line (f, vpos, XFASTINT (w->left));
2514 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2516 /* Show where to highlight the region. */
2517 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2518 /* Maybe highlight only in selected window. */
2519 && (highlight_nonselected_windows
2520 || w == XWINDOW (selected_window)))
2522 region_beg = marker_position (current_buffer->mark);
2523 if (PT < region_beg)
2525 region_end = region_beg;
2526 region_beg = PT;
2528 else
2529 region_end = PT;
2530 w->region_showing = Qt;
2532 else
2533 region_beg = region_end = -1;
2535 if (MINI_WINDOW_P (w)
2536 && start == BEG
2537 && vpos == XFASTINT (w->top))
2539 if (! NILP (minibuf_prompt))
2541 minibuf_prompt_width
2542 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2543 XSTRING (minibuf_prompt)->size, hpos,
2544 /* Display a space if we truncate. */
2545 ' ',
2546 1, -1,
2547 /* Truncate the prompt a little before the
2548 margin, so user input can at least start
2549 on the first line. */
2550 w->width > 10 ? w->width - 4 : -1)
2551 - hpos);
2552 hpos += minibuf_prompt_width;
2553 taboffset -= minibuf_prompt_width;
2555 else
2556 minibuf_prompt_width = 0;
2559 /* If we're hscrolled at all, use compute_motion to skip over any
2560 text off the left edge of the window. compute_motion may know
2561 tricks to do this faster than we can. */
2562 if (hpos < 0)
2564 struct position *left_edge
2565 = compute_motion (pos, vpos, hpos, 0,
2566 ZV, vpos, 0,
2567 width, hscroll, taboffset, w);
2569 /* Retrieve the buffer position and column provided by
2570 compute_motion. We can't assume that the column will be
2571 zero, because you may have multi-column characters crossing
2572 the left margin.
2574 compute_motion may have moved us past the screen position we
2575 requested, if we hit a multi-column character, or the end of
2576 the line. If so, back up. */
2577 if (left_edge->vpos > vpos
2578 || left_edge->hpos > 0)
2580 pos = left_edge->bufpos - 1;
2581 hpos = left_edge->prevhpos;
2583 else
2585 pos = left_edge->bufpos;
2586 hpos = left_edge->hpos;
2590 desired_glyphs->bufp[vpos] = start;
2591 p1 = desired_glyphs->glyphs[vpos] + hpos;
2592 p1start = p1;
2593 charstart = desired_glyphs->charstarts[vpos] + hpos;
2594 /* In case we don't ever write anything into it... */
2595 desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1;
2596 leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2597 endp = leftmargin + width;
2599 /* Arrange the overlays nicely for our purposes. Usually, we call
2600 display_text_line on only one line at a time, in which case this
2601 can't really hurt too much, or we call it on lines which appear
2602 one after another in the buffer, in which case all calls to
2603 recenter_overlay_lists but the first will be pretty cheap. */
2604 recenter_overlay_lists (current_buffer, pos);
2606 /* Loop generating characters.
2607 Stop at end of buffer, before newline,
2608 if reach or pass continuation column,
2609 or at face change. */
2610 pause = pos;
2611 next_face_change = pos;
2612 next_boundary = pos;
2613 p1prev = p1;
2614 prevpos = pos;
2615 while (1)
2617 if (pos >= pause)
2619 while (pos == next_boundary)
2621 Lisp_Object position, limit, prop, ww;
2623 /* Display the overlay strings here, unless we're at ZV
2624 and have already displayed the appropriate strings
2625 on an earlier line. */
2626 if (pos < ZV || !zv_strings_seen++)
2628 int ovlen;
2629 char *ovstr;
2630 ovlen = overlay_strings (pos, w, &ovstr);
2631 for (; ovlen; ovlen--, ovstr++)
2633 if (p1 >= leftmargin && p1 < endp)
2634 *p1 = MAKE_GLYPH (f, *ovstr, current_face);
2635 p1++;
2639 /* Did we reach point? Record the cursor location. */
2640 if (pos == PT && cursor_vpos < 0)
2642 cursor_vpos = vpos;
2643 cursor_hpos = p1 - leftmargin;
2646 if (pos >= ZV)
2647 break;
2649 XSETFASTINT (position, pos);
2650 limit = Fnext_overlay_change (position);
2651 #ifdef USE_TEXT_PROPERTIES
2652 /* This is just an estimate to give reasonable
2653 performance; nothing should go wrong if it is too small. */
2654 if (XFASTINT (limit) > pos + 50)
2655 XSETFASTINT (limit, pos + 50);
2656 limit = Fnext_single_property_change (position, Qinvisible,
2657 Fcurrent_buffer (), limit);
2658 #endif
2659 next_boundary = XFASTINT (limit);
2660 /* if the `invisible' property is set, we can skip to
2661 the next property change. */
2662 XSETWINDOW (ww, w);
2663 prop = Fget_char_property (position, Qinvisible, ww);
2664 if (TEXT_PROP_MEANS_INVISIBLE (prop))
2666 if (pos < PT && next_boundary >= PT)
2668 cursor_vpos = vpos;
2669 cursor_hpos = p1 - leftmargin;
2671 pos = next_boundary;
2672 last_invis_skip = pos;
2673 last_invis_prop = prop;
2677 /* Did we reach point? Record the cursor location. */
2678 if (pos == PT && cursor_vpos < 0)
2680 cursor_vpos = vpos;
2681 cursor_hpos = p1 - leftmargin;
2684 /* Did we hit the end of the visible region of the buffer?
2685 Stop here. */
2686 if (pos >= ZV)
2688 /* Update charstarts for the end of this line. */
2689 /* Do nothing if off the left edge or at the right edge. */
2690 if (p1 >= leftmargin && p1 + 1 != endp)
2692 int *p2x = &charstart[(p1 < leftmargin
2693 ? leftmargin : p1)
2694 - p1start];
2695 *p2x++ = pos;
2697 break;
2700 #ifdef HAVE_FACES
2701 /* Did we hit a face change? Figure out what face we should
2702 use now. We also hit this the first time through the
2703 loop, to see what face we should start with. */
2704 if (pos >= next_face_change && FRAME_X_P (f))
2705 current_face = compute_char_face (f, w, pos,
2706 region_beg, region_end,
2707 &next_face_change, pos + 50, 0);
2708 #endif
2710 pause = ZV;
2712 if (pos < next_boundary && next_boundary < pause)
2713 pause = next_boundary;
2714 if (pos < next_face_change && next_face_change < pause)
2715 pause = next_face_change;
2717 /* Wouldn't you hate to read the next line to someone over
2718 the phone? */
2719 if (pos < PT && PT < pause)
2720 pause = PT;
2721 if (pos < GPT && GPT < pause)
2722 pause = GPT;
2724 p = &FETCH_CHAR (pos);
2727 if (p1 >= endp)
2728 break;
2730 p1prev = p1;
2732 c = *p++;
2733 /* Let a display table override all standard display methods. */
2734 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
2736 p1 = copy_part_of_rope (f, p1, leftmargin,
2737 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2738 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2739 current_face);
2741 else if (c >= 040 && c < 0177)
2743 if (p1 >= leftmargin)
2744 *p1 = MAKE_GLYPH (f, c, current_face);
2745 p1++;
2747 else if (c == '\n')
2749 invis = 0;
2750 if (last_invis_skip == pos
2751 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
2752 invis = 1;
2753 while (pos + 1 < ZV
2754 && selective > 0
2755 && indented_beyond_p (pos + 1, selective))
2757 invis = 1;
2758 pos = find_next_newline (pos + 1, 1);
2759 if (FETCH_CHAR (pos - 1) == '\n')
2760 pos--;
2762 if (invis && selective_rlen > 0 && p1 >= leftmargin)
2764 p1 += selective_rlen;
2765 if (p1 - leftmargin > width)
2766 p1 = endp;
2767 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2768 (p1 - p1prev), current_face);
2770 #ifdef HAVE_FACES
2771 /* Draw the face of the newline character as extending all the
2772 way to the end of the frame line. */
2773 if (current_face)
2775 if (p1 < leftmargin)
2776 p1 = leftmargin;
2777 while (p1 < endp)
2778 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2780 #endif
2782 /* Update charstarts for the newline that ended this line. */
2783 /* Do nothing here for a char that's entirely off the left edge
2784 or if it starts at the right edge. */
2785 if (p1 >= leftmargin && p1prev != endp)
2787 /* Store the newline's position into charstarts
2788 for the column where the newline starts.
2789 Store -1 for the rest of the glyphs it occupies. */
2790 int *p2x = &charstart[(p1prev < leftmargin
2791 ? leftmargin : p1prev)
2792 - p1start];
2793 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2795 *p2x++ = pos;
2796 while (p2x < p2)
2797 *p2x++ = -1;
2800 break;
2802 else if (c == '\t')
2806 if (p1 >= leftmargin && p1 < endp)
2807 *p1 = MAKE_GLYPH (f, ' ', current_face);
2808 p1++;
2810 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
2811 % tab_width);
2813 else if (c == Ctl ('M') && selective == -1)
2815 pos = find_next_newline (pos, 1);
2816 if (FETCH_CHAR (pos - 1) == '\n')
2817 pos--;
2818 if (selective_rlen > 0)
2820 p1 += selective_rlen;
2821 if (p1 - leftmargin > width)
2822 p1 = endp;
2823 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2824 (p1 - p1prev), current_face);
2826 #ifdef HAVE_FACES
2827 /* Draw the face of the newline character as extending all the
2828 way to the end of the frame line. */
2829 if (current_face)
2831 if (p1 < leftmargin)
2832 p1 = leftmargin;
2833 while (p1 < endp)
2834 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2836 #endif
2838 /* Update charstarts for the ^M that ended this line. */
2839 /* Do nothing here for a char that's entirely off the left edge
2840 or if it starts at the right edge. */
2841 if (p1 >= leftmargin && p1prev != endp)
2843 /* Store the newline's position into charstarts
2844 for the column where the newline starts.
2845 Store -1 for the rest of the glyphs it occupies. */
2846 int *p2x = &charstart[(p1prev < leftmargin
2847 ? leftmargin : p1prev)
2848 - p1start];
2849 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2851 *p2x++ = pos;
2852 while (p2x < p2)
2853 *p2x++ = -1;
2855 break;
2857 else if (c < 0200 && ctl_arrow)
2859 if (p1 >= leftmargin)
2860 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
2861 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
2862 current_face);
2863 p1++;
2864 if (p1 >= leftmargin && p1 < endp)
2865 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
2866 p1++;
2868 else
2870 if (p1 >= leftmargin)
2871 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
2872 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
2873 current_face);
2874 p1++;
2875 if (p1 >= leftmargin && p1 < endp)
2876 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
2877 p1++;
2878 if (p1 >= leftmargin && p1 < endp)
2879 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
2880 p1++;
2881 if (p1 >= leftmargin && p1 < endp)
2882 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
2883 p1++;
2886 prevpos = pos;
2887 pos++;
2889 /* Update charstarts for the character just output. */
2891 /* Do nothing here for a char that's entirely off the left edge. */
2892 if (p1 >= leftmargin)
2894 /* Store the char's position into charstarts
2895 for the first glyph occupied by this char.
2896 Store -1 for the rest of the glyphs it occupies. */
2897 if (p1 != p1prev)
2899 int *p2x = &charstart[(p1prev < leftmargin
2900 ? leftmargin : p1prev)
2901 - p1start];
2902 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2904 if (p2x < p2)
2905 *p2x++ = prevpos;
2906 while (p2x < p2)
2907 *p2x++ = -1;
2912 val.hpos = - XINT (w->hscroll);
2913 if (val.hpos)
2914 val.hpos++;
2916 val.vpos = 1;
2918 lastpos = pos;
2920 /* Store 0 in this charstart line for the positions where
2921 there is no character. But do leave what was recorded
2922 for the character that ended the line. */
2923 /* Add 1 in the endtest to compensate for the fact that ENDP was
2924 made from WIDTH, which is 1 less than the window's actual
2925 internal width. */
2926 i = p1 - p1start + 1;
2927 if (p1 < leftmargin)
2928 i += leftmargin - p1;
2929 for (; i < endp - p1start + 1; i++)
2930 charstart[i] = 0;
2932 /* Handle continuation in middle of a character */
2933 /* by backing up over it */
2934 if (p1 > endp)
2936 /* Don't back up if we never actually displayed any text.
2937 This occurs when the minibuffer prompt takes up the whole line. */
2938 if (p1prev)
2940 /* Start the next line with that same character */
2941 pos--;
2942 /* but at negative hpos, to skip the columns output on this line. */
2943 val.hpos += p1prev - endp;
2946 /* Keep in this line everything up to the continuation column. */
2947 p1 = endp;
2950 /* Finish deciding which character to start the next line on,
2951 and what hpos to start it at.
2952 Also set `lastpos' to the last position which counts as "on this line"
2953 for cursor-positioning. */
2955 if (pos < ZV)
2957 if (FETCH_CHAR (pos) == '\n')
2959 /* If stopped due to a newline, start next line after it */
2960 pos++;
2961 /* Check again for hidden lines, in case the newline occurred exactly
2962 at the right margin. */
2963 while (pos < ZV && selective > 0
2964 && indented_beyond_p (pos, selective))
2965 pos = find_next_newline (pos, 1);
2967 else
2968 /* Stopped due to right margin of window */
2970 if (truncate)
2972 *p1++ = fix_glyph (f, truncator, 0);
2973 /* Truncating => start next line after next newline,
2974 and point is on this line if it is before the newline,
2975 and skip none of first char of next line */
2977 pos = find_next_newline (pos, 1);
2978 while (pos < ZV && selective > 0
2979 && indented_beyond_p (pos, selective));
2980 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2982 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
2984 else
2986 *p1++ = fix_glyph (f, continuer, 0);
2987 val.vpos = 0;
2988 lastpos--;
2993 /* If point is at eol or in invisible text at eol,
2994 record its frame location now. */
2996 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
2998 cursor_vpos = vpos;
2999 cursor_hpos = p1 - leftmargin;
3002 if (cursor_vpos == vpos)
3004 if (cursor_hpos < 0) cursor_hpos = 0;
3005 if (cursor_hpos > width) cursor_hpos = width;
3006 cursor_hpos += XFASTINT (w->left);
3007 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
3009 if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f)
3010 && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window)))
3012 FRAME_CURSOR_Y (f) = cursor_vpos;
3013 FRAME_CURSOR_X (f) = cursor_hpos;
3016 if (w == XWINDOW (selected_window))
3018 /* Line is not continued and did not start
3019 in middle of character */
3020 if ((hpos - XFASTINT (w->left)
3021 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
3022 && val.vpos)
3024 this_line_bufpos = start;
3025 this_line_buffer = current_buffer;
3026 this_line_vpos = cursor_vpos;
3027 this_line_start_hpos = hpos;
3028 this_line_endpos = Z - lastpos;
3030 else
3031 this_line_bufpos = 0;
3036 /* If hscroll and line not empty, insert truncation-at-left marker */
3037 if (hscroll && lastpos != start)
3039 *leftmargin = fix_glyph (f, truncator, 0);
3040 if (p1 <= leftmargin)
3041 p1 = leftmargin + 1;
3044 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
3046 endp++;
3047 if (p1 < leftmargin) p1 = leftmargin;
3048 while (p1 < endp) *p1++ = SPACEGLYPH;
3050 /* Don't draw vertical bars if we're using scroll bars. They're
3051 covered up by the scroll bars, and it's distracting to see
3052 them when the scroll bar windows are flickering around to be
3053 reconfigured. */
3054 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3056 int i;
3057 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3058 *p1++ = SPACEGLYPH;
3060 else
3061 *p1++ = (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
3062 ? DISP_BORDER_GLYPH (dp)
3063 : '|');
3065 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
3066 p1 - desired_glyphs->glyphs[vpos]);
3067 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3069 /* If the start of this line is the overlay arrow-position,
3070 then put the arrow string into the display-line. */
3072 if (MARKERP (Voverlay_arrow_position)
3073 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
3074 && start == marker_position (Voverlay_arrow_position)
3075 && STRINGP (Voverlay_arrow_string)
3076 && ! overlay_arrow_seen)
3078 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
3079 int i;
3080 int len = XSTRING (Voverlay_arrow_string)->size;
3081 int arrow_end;
3083 if (len > width)
3084 len = width;
3085 #ifdef HAVE_FACES
3086 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
3088 /* If the arrow string has text props, obey them when displaying. */
3089 for (i = 0; i < len; i++)
3091 int c = p[i];
3092 Lisp_Object face, ilisp;
3093 int newface;
3095 XSETFASTINT (ilisp, i);
3096 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
3097 newface = compute_glyph_face_1 (f, face, 0);
3098 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
3101 else
3102 #endif /* HAVE_FACES */
3104 for (i = 0; i < len; i++)
3105 leftmargin[i] = p[i];
3108 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3109 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
3110 if (desired_glyphs->used[vpos] < arrow_end)
3111 desired_glyphs->used[vpos] = arrow_end;
3113 overlay_arrow_seen = 1;
3116 val.bufpos = pos;
3117 val_display_text_line = val;
3118 return &val_display_text_line;
3121 /* Redisplay the menu bar in the frame for window W. */
3123 static void
3124 display_menu_bar (w)
3125 struct window *w;
3127 Lisp_Object items, tail;
3128 register int vpos = 0;
3129 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3130 int maxendcol = FRAME_WIDTH (f);
3131 int hpos = 0;
3132 int i;
3134 #ifndef USE_X_TOOLKIT
3135 if (FRAME_MENU_BAR_LINES (f) <= 0)
3136 return;
3138 get_display_line (f, vpos, 0);
3140 items = FRAME_MENU_BAR_ITEMS (f);
3141 for (i = 0; i < XVECTOR (items)->size; i += 3)
3143 Lisp_Object pos, string;
3144 string = XVECTOR (items)->contents[i + 1];
3145 if (NILP (string))
3146 break;
3148 XSETFASTINT (XVECTOR (items)->contents[i + 2], hpos);
3150 if (hpos < maxendcol)
3151 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
3152 XSTRING (string)->data,
3153 XSTRING (string)->size,
3154 hpos, 0, 0, hpos, maxendcol);
3155 /* Put a space between items. */
3156 if (hpos < maxendcol)
3158 int hpos1 = hpos + 1;
3159 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
3160 min (hpos1, maxendcol), maxendcol);
3164 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3165 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3167 /* Fill out the line with spaces. */
3168 if (maxendcol > hpos)
3169 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
3171 /* Clear the rest of the lines allocated to the menu bar. */
3172 vpos++;
3173 while (vpos < FRAME_MENU_BAR_LINES (f))
3174 get_display_line (f, vpos++, 0);
3175 #endif /* not USE_X_TOOLKIT */
3178 /* Display the mode line for window w */
3180 static void
3181 display_mode_line (w)
3182 struct window *w;
3184 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
3185 register int left = XFASTINT (w->left);
3186 register int right = XFASTINT (w->width) + left;
3187 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3189 line_number_displayed = 0;
3190 w->column_number_displayed = Qnil;
3192 get_display_line (f, vpos, left);
3194 /* Temporarily make frame F's kboard the current kboard
3195 so that kboard-local variables in the mode_line_format
3196 will get the right values. */
3197 push_frame_kboard (f);
3199 display_mode_element (w, vpos, left, 0, right, right,
3200 current_buffer->mode_line_format);
3202 pop_frame_kboard ();
3204 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3206 /* Make the mode line inverse video if the entire line
3207 is made of mode lines.
3208 I.e. if this window is full width,
3209 or if it is the child of a full width window
3210 (which implies that that window is split side-by-side
3211 and the rest of this line is mode lines of the sibling windows). */
3212 if (XFASTINT (w->width) == FRAME_WIDTH (f)
3213 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
3214 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3215 #ifdef HAVE_FACES
3216 else if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video)
3218 /* For a partial width window, explicitly set face of each glyph. */
3219 int i;
3220 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3221 for (i = left; i < right; ++i)
3222 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
3224 #endif
3227 /* Contribute ELT to the mode line for window W.
3228 How it translates into text depends on its data type.
3230 VPOS is the position of the mode line being displayed.
3232 HPOS is the position (absolute on frame) where this element's text
3233 should start. The output is truncated automatically at the right
3234 edge of window W.
3236 DEPTH is the depth in recursion. It is used to prevent
3237 infinite recursion here.
3239 MINENDCOL is the hpos before which the element may not end.
3240 The element is padded at the right with spaces if nec
3241 to reach this column.
3243 MAXENDCOL is the hpos past which this element may not extend.
3244 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3245 (This is necessary to make nested padding and truncation work.)
3247 Returns the hpos of the end of the text generated by ELT.
3248 The next element will receive that value as its HPOS arg,
3249 so as to concatenate the elements. */
3251 static int
3252 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3253 struct window *w;
3254 register int vpos, hpos;
3255 int depth;
3256 int minendcol;
3257 register int maxendcol;
3258 register Lisp_Object elt;
3260 tail_recurse:
3261 if (depth > 10)
3262 goto invalid;
3264 depth++;
3266 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3268 case Lisp_String:
3270 /* A string: output it and check for %-constructs within it. */
3271 register unsigned char c;
3272 register unsigned char *this = XSTRING (elt)->data;
3274 while (hpos < maxendcol && *this)
3276 unsigned char *last = this;
3277 while ((c = *this++) != '\0' && c != '%')
3279 if (this - 1 != last)
3281 register int lim = --this - last + hpos;
3282 if (frame_title_ptr)
3283 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3284 else
3285 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3286 hpos, min (lim, maxendcol));
3288 else /* c == '%' */
3290 register int minendcol;
3291 register int spec_width = 0;
3293 /* We can't allow -ve args due to the "%-" construct */
3294 /* Argument specifies minwidth but not maxwidth
3295 (maxwidth can be specified by
3296 (<negative-number> . <stuff>) mode-line elements) */
3298 while ((c = *this++) >= '0' && c <= '9')
3300 spec_width = spec_width * 10 + (c - '0');
3303 minendcol = hpos + spec_width;
3304 if (minendcol > maxendcol)
3306 spec_width = maxendcol - hpos;
3307 minendcol = maxendcol;
3310 if (c == 'M')
3311 hpos = display_mode_element (w, vpos, hpos, depth,
3312 spec_width, maxendcol,
3313 Vglobal_mode_string);
3314 else if (c != 0)
3316 char *spec = decode_mode_spec (w, c, spec_width,
3317 maxendcol - hpos);
3318 if (frame_title_ptr)
3319 hpos = store_frame_title (spec, minendcol, maxendcol);
3320 else
3321 hpos = display_string (w, vpos, spec, -1,
3322 hpos, 0, 1,
3323 minendcol, maxendcol);
3328 break;
3330 case Lisp_Symbol:
3331 /* A symbol: process the value of the symbol recursively
3332 as if it appeared here directly. Avoid error if symbol void.
3333 Special case: if value of symbol is a string, output the string
3334 literally. */
3336 register Lisp_Object tem;
3337 tem = Fboundp (elt);
3338 if (!NILP (tem))
3340 tem = Fsymbol_value (elt);
3341 /* If value is a string, output that string literally:
3342 don't check for % within it. */
3343 if (STRINGP (tem))
3345 if (frame_title_ptr)
3346 hpos = store_frame_title (XSTRING (tem)->data,
3347 minendcol, maxendcol);
3348 else
3349 hpos = display_string (w, vpos, XSTRING (tem)->data,
3350 XSTRING (tem)->size,
3351 hpos, 0, 1, minendcol, maxendcol);
3353 /* Give up right away for nil or t. */
3354 else if (!EQ (tem, elt))
3355 { elt = tem; goto tail_recurse; }
3358 break;
3360 case Lisp_Cons:
3362 register Lisp_Object car, tem;
3364 /* A cons cell: three distinct cases.
3365 If first element is a string or a cons, process all the elements
3366 and effectively concatenate them.
3367 If first element is a negative number, truncate displaying cdr to
3368 at most that many characters. If positive, pad (with spaces)
3369 to at least that many characters.
3370 If first element is a symbol, process the cadr or caddr recursively
3371 according to whether the symbol's value is non-nil or nil. */
3372 car = XCONS (elt)->car;
3373 if (SYMBOLP (car))
3375 tem = Fboundp (car);
3376 elt = XCONS (elt)->cdr;
3377 if (!CONSP (elt))
3378 goto invalid;
3379 /* elt is now the cdr, and we know it is a cons cell.
3380 Use its car if CAR has a non-nil value. */
3381 if (!NILP (tem))
3383 tem = Fsymbol_value (car);
3384 if (!NILP (tem))
3385 { elt = XCONS (elt)->car; goto tail_recurse; }
3387 /* Symbol's value is nil (or symbol is unbound)
3388 Get the cddr of the original list
3389 and if possible find the caddr and use that. */
3390 elt = XCONS (elt)->cdr;
3391 if (NILP (elt))
3392 break;
3393 else if (!CONSP (elt))
3394 goto invalid;
3395 elt = XCONS (elt)->car;
3396 goto tail_recurse;
3398 else if (INTEGERP (car))
3400 register int lim = XINT (car);
3401 elt = XCONS (elt)->cdr;
3402 if (lim < 0)
3403 /* Negative int means reduce maximum width.
3404 DO NOT change MINENDCOL here!
3405 (20 -10 . foo) should truncate foo to 10 col
3406 and then pad to 20. */
3407 maxendcol = min (maxendcol, hpos - lim);
3408 else if (lim > 0)
3410 /* Padding specified. Don't let it be more than
3411 current maximum. */
3412 lim += hpos;
3413 if (lim > maxendcol)
3414 lim = maxendcol;
3415 /* If that's more padding than already wanted, queue it.
3416 But don't reduce padding already specified even if
3417 that is beyond the current truncation point. */
3418 if (lim > minendcol)
3419 minendcol = lim;
3421 goto tail_recurse;
3423 else if (STRINGP (car) || CONSP (car))
3425 register int limit = 50;
3426 /* LIMIT is to protect against circular lists. */
3427 while (CONSP (elt) && --limit > 0
3428 && hpos < maxendcol)
3430 hpos = display_mode_element (w, vpos, hpos, depth,
3431 hpos, maxendcol,
3432 XCONS (elt)->car);
3433 elt = XCONS (elt)->cdr;
3437 break;
3439 default:
3440 invalid:
3441 if (frame_title_ptr)
3442 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3443 else
3444 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3445 minendcol, maxendcol);
3446 return hpos;
3449 if (minendcol > hpos)
3450 if (frame_title_ptr)
3451 hpos = store_frame_title ("", minendcol, maxendcol);
3452 else
3453 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
3454 return hpos;
3457 /* Write a null-terminated, right justified decimal representation of
3458 the positive integer D to BUF using a minimal field width WIDTH. */
3460 static void
3461 pint2str (buf, width, d)
3462 register char *buf;
3463 register int width;
3464 register int d;
3466 register char *p = buf;
3468 if (d <= 0)
3469 *p++ = '0';
3470 else
3471 while (d > 0)
3473 *p++ = d % 10 + '0';
3474 d /= 10;
3476 for (width -= (int) (p - buf); width > 0; --width) *p++ = ' ';
3477 *p-- = '\0';
3478 while (p > buf)
3480 d = *buf;
3481 *buf++ = *p;
3482 *p-- = d;
3486 /* Return a string for the output of a mode line %-spec for window W,
3487 generated by character C. SPEC_WIDTH is the field width when
3488 padding to the left (%c, %l). The value returned from this
3489 function will later be truncated to width MAXWIDTH. */
3491 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3493 static char *
3494 decode_mode_spec (w, c, spec_width, maxwidth)
3495 struct window *w;
3496 register char c;
3497 register int spec_width;
3498 register int maxwidth;
3500 Lisp_Object obj;
3501 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3502 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
3503 struct buffer *b = XBUFFER (w->buffer);
3505 obj = Qnil;
3506 if (maxwidth > FRAME_WIDTH (f))
3507 maxwidth = FRAME_WIDTH (f);
3509 switch (c)
3511 case '*':
3512 if (!NILP (b->read_only))
3513 return "%";
3514 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3515 return "*";
3516 return "-";
3518 case '+':
3519 /* This differs from %* only for a modified read-only buffer. */
3520 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3521 return "*";
3522 if (!NILP (b->read_only))
3523 return "%";
3524 return "-";
3526 case '&':
3527 /* This differs from %* in ignoring read-only-ness. */
3528 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3529 return "*";
3530 return "-";
3532 case '%':
3533 return "%";
3535 case '[':
3537 int i;
3538 char *p;
3540 if (command_loop_level > 5)
3541 return "[[[... ";
3542 p = decode_mode_spec_buf;
3543 for (i = 0; i < command_loop_level; i++)
3544 *p++ = '[';
3545 *p = 0;
3546 return decode_mode_spec_buf;
3549 case ']':
3551 int i;
3552 char *p;
3554 if (command_loop_level > 5)
3555 return " ...]]]";
3556 p = decode_mode_spec_buf;
3557 for (i = 0; i < command_loop_level; i++)
3558 *p++ = ']';
3559 *p = 0;
3560 return decode_mode_spec_buf;
3563 case '-':
3565 register char *p;
3566 register int i;
3568 if (maxwidth < sizeof (lots_of_dashes))
3569 return lots_of_dashes;
3570 else
3572 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3573 *p++ = '-';
3574 *p = '\0';
3576 return decode_mode_spec_buf;
3579 case 'b':
3580 obj = b->name;
3581 #if 0
3582 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
3584 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
3585 decode_mode_spec_buf[maxwidth - 1] = '\\';
3586 decode_mode_spec_buf[maxwidth] = '\0';
3587 return decode_mode_spec_buf;
3589 #endif
3590 break;
3592 case 'c':
3594 int col = current_column ();
3595 XSETFASTINT (w->column_number_displayed, col);
3596 pint2str (decode_mode_spec_buf, spec_width, col);
3597 return decode_mode_spec_buf;
3600 case 'F':
3601 /* %F displays the frame name. */
3602 #ifdef MULTI_FRAME
3603 return (char *) XSTRING (selected_frame->name)->data;
3604 #else
3605 return "Emacs";
3606 #endif
3608 case 'f':
3609 obj = b->filename;
3610 #if 0
3611 if (NILP (obj))
3612 return "[none]";
3613 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
3615 bcopy ("...", decode_mode_spec_buf, 3);
3616 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
3617 decode_mode_spec_buf + 3, maxwidth - 3);
3618 return decode_mode_spec_buf;
3620 #endif
3621 break;
3623 case 'l':
3625 int startpos = marker_position (w->start);
3626 int line, linepos, topline;
3627 int nlines, junk;
3628 Lisp_Object tem;
3629 int height = XFASTINT (w->height);
3631 /* If we decided that this buffer isn't suitable for line numbers,
3632 don't forget that too fast. */
3633 if (EQ (w->base_line_pos, w->buffer))
3634 goto no_value;
3636 /* If the buffer is very big, don't waste time. */
3637 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
3639 w->base_line_pos = Qnil;
3640 w->base_line_number = Qnil;
3641 goto no_value;
3644 if (!NILP (w->base_line_number)
3645 && !NILP (w->base_line_pos)
3646 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
3648 line = XFASTINT (w->base_line_number);
3649 linepos = XFASTINT (w->base_line_pos);
3651 else
3653 line = 1;
3654 linepos = BUF_BEGV (b);
3657 /* Count lines from base line to window start position. */
3658 nlines = display_count_lines (linepos, startpos, startpos, &junk);
3660 topline = nlines + line;
3662 /* Determine a new base line, if the old one is too close
3663 or too far away, or if we did not have one.
3664 "Too close" means it's plausible a scroll-down would
3665 go back past it. */
3666 if (startpos == BUF_BEGV (b))
3668 XSETFASTINT (w->base_line_number, topline);
3669 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
3671 else if (nlines < height + 25 || nlines > height * 3 + 50
3672 || linepos == BUF_BEGV (b))
3674 int limit = BUF_BEGV (b);
3675 int position;
3676 int distance = (height * 2 + 30) * 200;
3678 if (startpos - distance > limit)
3679 limit = startpos - distance;
3681 nlines = display_count_lines (startpos, limit,
3682 -(height * 2 + 30),
3683 &position);
3684 /* If we couldn't find the lines we wanted within
3685 200 chars per line,
3686 give up on line numbers for this window. */
3687 if (position == startpos - distance)
3689 w->base_line_pos = w->buffer;
3690 w->base_line_number = Qnil;
3691 goto no_value;
3694 XSETFASTINT (w->base_line_number, topline - nlines);
3695 XSETFASTINT (w->base_line_pos, position);
3698 /* Now count lines from the start pos to point. */
3699 nlines = display_count_lines (startpos, PT, PT, &junk);
3701 /* Record that we did display the line number. */
3702 line_number_displayed = 1;
3704 /* Make the string to show. */
3705 pint2str (decode_mode_spec_buf, spec_width, topline + nlines);
3706 return decode_mode_spec_buf;
3707 no_value:
3709 char* p = decode_mode_spec_buf;
3710 for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' ';
3711 strcpy (p, "??");
3712 return decode_mode_spec_buf;
3715 break;
3717 case 'm':
3718 obj = b->mode_name;
3719 break;
3721 case 'n':
3722 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
3723 return " Narrow";
3724 break;
3726 case 'p':
3728 int pos = marker_position (w->start);
3729 int total = BUF_ZV (b) - BUF_BEGV (b);
3731 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
3733 if (pos <= BUF_BEGV (b))
3734 return "All";
3735 else
3736 return "Bottom";
3738 else if (pos <= BUF_BEGV (b))
3739 return "Top";
3740 else
3742 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
3743 /* We can't normally display a 3-digit number,
3744 so get us a 2-digit number that is close. */
3745 if (total == 100)
3746 total = 99;
3747 sprintf (decode_mode_spec_buf, "%2d%%", total);
3748 return decode_mode_spec_buf;
3752 /* Display percentage of size above the bottom of the screen. */
3753 case 'P':
3755 int toppos = marker_position (w->start);
3756 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
3757 int total = BUF_ZV (b) - BUF_BEGV (b);
3759 if (botpos >= BUF_ZV (b))
3761 if (toppos <= BUF_BEGV (b))
3762 return "All";
3763 else
3764 return "Bottom";
3766 else
3768 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
3769 /* We can't normally display a 3-digit number,
3770 so get us a 2-digit number that is close. */
3771 if (total == 100)
3772 total = 99;
3773 if (toppos <= BUF_BEGV (b))
3774 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
3775 else
3776 sprintf (decode_mode_spec_buf, "%2d%%", total);
3777 return decode_mode_spec_buf;
3781 case 's':
3782 /* status of process */
3783 obj = Fget_buffer_process (w->buffer);
3784 if (NILP (obj))
3785 return "no process";
3786 #ifdef subprocesses
3787 obj = Fsymbol_name (Fprocess_status (obj));
3788 #endif
3789 break;
3791 case 't': /* indicate TEXT or BINARY */
3792 #ifdef MODE_LINE_BINARY_TEXT
3793 return MODE_LINE_BINARY_TEXT (b);
3794 #else
3795 return "T";
3796 #endif
3799 if (STRINGP (obj))
3800 return (char *) XSTRING (obj)->data;
3801 else
3802 return "";
3805 /* Search for COUNT instances of a line boundary, which means either a
3806 newline or (if selective display enabled) a carriage return.
3807 Start at START. If COUNT is negative, search backwards.
3809 If we find COUNT instances, set *SHORTAGE to zero, and return the
3810 position after the COUNTth match. Note that for reverse motion
3811 this is not the same as the usual convention for Emacs motion commands.
3813 If we don't find COUNT instances before reaching the end of the
3814 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3815 the number of line boundaries left unfound, and return the end of the
3816 buffer we bumped up against. */
3818 static int
3819 display_scan_buffer (start, count, shortage)
3820 int *shortage, start;
3821 register int count;
3823 int limit = ((count > 0) ? ZV - 1 : BEGV);
3824 int direction = ((count > 0) ? 1 : -1);
3826 register unsigned char *cursor;
3827 unsigned char *base;
3829 register int ceiling;
3830 register unsigned char *ceiling_addr;
3832 /* If we are not in selective display mode,
3833 check only for newlines. */
3834 if (! (!NILP (current_buffer->selective_display)
3835 && !INTEGERP (current_buffer->selective_display)))
3836 return scan_buffer ('\n', start, 0, count, shortage, 0);
3838 /* The code that follows is like scan_buffer
3839 but checks for either newline or carriage return. */
3841 if (shortage != 0)
3842 *shortage = 0;
3844 if (count > 0)
3845 while (start != limit + 1)
3847 ceiling = BUFFER_CEILING_OF (start);
3848 ceiling = min (limit, ceiling);
3849 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
3850 base = (cursor = &FETCH_CHAR (start));
3851 while (1)
3853 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
3855 if (cursor != ceiling_addr)
3857 if (--count == 0)
3859 immediate_quit = 0;
3860 return (start + cursor - base + 1);
3862 else
3863 if (++cursor == ceiling_addr)
3864 break;
3866 else
3867 break;
3869 start += cursor - base;
3871 else
3873 start--; /* first character we scan */
3874 while (start > limit - 1)
3875 { /* we WILL scan under start */
3876 ceiling = BUFFER_FLOOR_OF (start);
3877 ceiling = max (limit, ceiling);
3878 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
3879 base = (cursor = &FETCH_CHAR (start));
3880 cursor++;
3881 while (1)
3883 while (--cursor != ceiling_addr
3884 && *cursor != '\n' && *cursor != 015)
3886 if (cursor != ceiling_addr)
3888 if (++count == 0)
3890 immediate_quit = 0;
3891 return (start + cursor - base + 1);
3894 else
3895 break;
3897 start += cursor - base;
3901 if (shortage != 0)
3902 *shortage = count * direction;
3903 return (start + ((direction == 1 ? 0 : 1)));
3906 /* Count up to N lines starting from FROM.
3907 But don't go beyond LIMIT.
3908 Return the number of lines thus found (always positive).
3909 Store the position after what was found into *POS_PTR. */
3911 static int
3912 display_count_lines (from, limit, n, pos_ptr)
3913 int from, limit, n;
3914 int *pos_ptr;
3916 int oldbegv = BEGV;
3917 int oldzv = ZV;
3918 int shortage = 0;
3920 if (limit < from)
3921 BEGV = limit;
3922 else
3923 ZV = limit;
3925 *pos_ptr = display_scan_buffer (from, n, &shortage);
3927 ZV = oldzv;
3928 BEGV = oldbegv;
3930 if (n < 0)
3931 /* When scanning backwards, scan_buffer stops *after* the last newline
3932 it finds, but does count it. Compensate for that. */
3933 return - n - shortage - (*pos_ptr != limit);
3934 return n - shortage;
3937 /* Display STRING on one line of window W, starting at HPOS.
3938 Display at position VPOS. Caller should have done get_display_line.
3939 If VPOS == -1, display it as the current frame's title.
3940 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
3942 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
3944 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
3945 MAXCOL is the last column ok to end at. Truncate here.
3946 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
3947 Both count from the left edge of the frame, as does HPOS.
3948 The right edge of W is an implicit maximum.
3949 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
3951 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
3952 at the place where the current window ends in this line
3953 and not display anything beyond there. Otherwise, only MAXCOL
3954 controls where to stop output.
3956 Returns ending hpos. */
3958 static int
3959 display_string (w, vpos, string, length, hpos, truncate,
3960 obey_window_width, mincol, maxcol)
3961 struct window *w;
3962 unsigned char *string;
3963 int length;
3964 int vpos, hpos;
3965 GLYPH truncate;
3966 int obey_window_width;
3967 int mincol, maxcol;
3969 register int c;
3970 register GLYPH *p1;
3971 int hscroll = XINT (w->hscroll);
3972 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
3973 register GLYPH *start;
3974 register GLYPH *end;
3975 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3976 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
3977 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
3978 int window_width = XFASTINT (w->width);
3980 /* Use the standard display table, not the window's display table.
3981 We don't want the mode line in rot13. */
3982 register struct Lisp_Vector *dp = 0;
3983 int i;
3985 if (VECTORP (Vstandard_display_table)
3986 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
3987 dp = XVECTOR (Vstandard_display_table);
3989 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
3991 p1 = p1start;
3992 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
3994 if (obey_window_width)
3996 end = start + window_width - (truncate != 0);
3998 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
4000 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4002 int i;
4004 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
4005 *end-- = ' ';
4007 else
4008 *end-- = '|';
4012 if (! obey_window_width
4013 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
4014 end = desired_glyphs->glyphs[vpos] + maxcol;
4016 /* Store 0 in charstart for these columns. */
4017 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
4018 desired_glyphs->charstarts[vpos][i] = 0;
4020 if (maxcol >= 0 && mincol > maxcol)
4021 mincol = maxcol;
4023 while (p1 < end)
4025 if (length == 0)
4026 break;
4027 c = *string++;
4028 /* Specified length. */
4029 if (length >= 0)
4030 length--;
4031 /* Unspecified length (null-terminated string). */
4032 else if (c == 0)
4033 break;
4035 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
4037 p1 = copy_part_of_rope (f, p1, start,
4038 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
4039 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
4042 else if (c >= 040 && c < 0177)
4044 if (p1 >= start)
4045 *p1 = c;
4046 p1++;
4048 else if (c == '\t')
4052 if (p1 >= start && p1 < end)
4053 *p1 = SPACEGLYPH;
4054 p1++;
4056 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
4058 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
4060 if (p1 >= start)
4061 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
4062 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
4064 p1++;
4065 if (p1 >= start && p1 < end)
4066 *p1 = c ^ 0100;
4067 p1++;
4069 else
4071 if (p1 >= start)
4072 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
4073 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
4075 p1++;
4076 if (p1 >= start && p1 < end)
4077 *p1 = (c >> 6) + '0';
4078 p1++;
4079 if (p1 >= start && p1 < end)
4080 *p1 = (7 & (c >> 3)) + '0';
4081 p1++;
4082 if (p1 >= start && p1 < end)
4083 *p1 = (7 & c) + '0';
4084 p1++;
4088 if (c && length > 0)
4090 p1 = end;
4091 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
4093 else if (mincol >= 0)
4095 end = desired_glyphs->glyphs[vpos] + mincol;
4096 while (p1 < end)
4097 *p1++ = SPACEGLYPH;
4101 register int len = p1 - desired_glyphs->glyphs[vpos];
4103 if (len > desired_glyphs->used[vpos])
4104 desired_glyphs->used[vpos] = len;
4105 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
4107 return len;
4111 /* This is like a combination of memq and assq.
4112 Return 1 if PROPVAL appears as an element of LIST
4113 or as the car of an element of LIST.
4114 If PROPVAL is a list, compare each element against LIST
4115 in that way, and return 1 if any element of PROPVAL is found in LIST.
4116 Otherwise return 0.
4117 This function cannot quit. */
4120 invisible_p (propval, list)
4121 register Lisp_Object propval;
4122 Lisp_Object list;
4124 register Lisp_Object tail, proptail;
4125 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4127 register Lisp_Object tem;
4128 tem = XCONS (tail)->car;
4129 if (EQ (propval, tem))
4130 return 1;
4131 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4132 return 1;
4134 if (CONSP (propval))
4135 for (proptail = propval; CONSP (proptail);
4136 proptail = XCONS (proptail)->cdr)
4138 Lisp_Object propelt;
4139 propelt = XCONS (proptail)->car;
4140 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4142 register Lisp_Object tem;
4143 tem = XCONS (tail)->car;
4144 if (EQ (propelt, tem))
4145 return 1;
4146 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4147 return 1;
4150 return 0;
4153 /* Return 1 if PROPVAL appears as the car of an element of LIST
4154 and the cdr of that element is non-nil.
4155 If PROPVAL is a list, check each element of PROPVAL in that way,
4156 and the first time some element is found,
4157 return 1 if the cdr of that element is non-nil.
4158 Otherwise return 0.
4159 This function cannot quit. */
4162 invisible_ellipsis_p (propval, list)
4163 register Lisp_Object propval;
4164 Lisp_Object list;
4166 register Lisp_Object tail, proptail;
4167 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4169 register Lisp_Object tem;
4170 tem = XCONS (tail)->car;
4171 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4172 return ! NILP (XCONS (tem)->cdr);
4174 if (CONSP (propval))
4175 for (proptail = propval; CONSP (proptail);
4176 proptail = XCONS (proptail)->cdr)
4178 Lisp_Object propelt;
4179 propelt = XCONS (proptail)->car;
4180 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4182 register Lisp_Object tem;
4183 tem = XCONS (tail)->car;
4184 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4185 return ! NILP (XCONS (tem)->cdr);
4188 return 0;
4191 void
4192 syms_of_xdisp ()
4194 staticpro (&Qmenu_bar_update_hook);
4195 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
4197 staticpro (&Qoverriding_terminal_local_map);
4198 Qoverriding_terminal_local_map = intern ("overriding-terminal-local-map");
4200 staticpro (&Qoverriding_local_map);
4201 Qoverriding_local_map = intern ("overriding-local-map");
4203 staticpro (&Qwindow_scroll_functions);
4204 Qwindow_scroll_functions = intern ("window-scroll-functions");
4206 staticpro (&last_arrow_position);
4207 staticpro (&last_arrow_string);
4208 last_arrow_position = Qnil;
4209 last_arrow_string = Qnil;
4211 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
4212 "String (or mode line construct) included (normally) in `mode-line-format'.");
4213 Vglobal_mode_string = Qnil;
4215 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
4216 "Marker for where to display an arrow on top of the buffer text.\n\
4217 This must be the beginning of a line in order to work.\n\
4218 See also `overlay-arrow-string'.");
4219 Voverlay_arrow_position = Qnil;
4221 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
4222 "String to display as an arrow. See also `overlay-arrow-position'.");
4223 Voverlay_arrow_string = Qnil;
4225 DEFVAR_INT ("scroll-step", &scroll_step,
4226 "*The number of lines to try scrolling a window by when point moves out.\n\
4227 If that fails to bring point back on frame, point is centered instead.\n\
4228 If this is zero, point is always centered after it moves off frame.");
4230 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
4232 DEFVAR_BOOL ("truncate-partial-width-windows",
4233 &truncate_partial_width_windows,
4234 "*Non-nil means truncate lines in all windows less than full frame wide.");
4235 truncate_partial_width_windows = 1;
4237 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
4238 "*Non-nil means use inverse video for the mode line.");
4239 mode_line_inverse_video = 1;
4241 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
4242 "*Maximum buffer size for which line number should be displayed.");
4243 line_number_display_limit = 1000000;
4245 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
4246 "*Non-nil means highlight region even in nonselected windows.");
4247 highlight_nonselected_windows = 1;
4249 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
4250 "Non-nil if more than one frame is visible on this display.\n\
4251 Minibuffer-only frames don't count, but iconified frames do.\n\
4252 This variable is not guaranteed to be accurate except while processing\n\
4253 `frame-title-format' and `icon-title-format'.");
4255 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
4256 "Template for displaying the titlebar of visible frames.\n\
4257 \(Assuming the window manager supports this feature.)\n\
4258 This variable has the same structure as `mode-line-format' (which see),\n\
4259 and is used only on frames for which no explicit name has been set\n\
4260 \(see `modify-frame-parameters').");
4261 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
4262 "Template for displaying the titlebar of an iconified frame.\n\
4263 \(Assuming the window manager supports this feature.)\n\
4264 This variable has the same structure as `mode-line-format' (which see),\n\
4265 and is used only on frames for which no explicit name has been set\n\
4266 \(see `modify-frame-parameters').");
4267 Vicon_title_format
4268 = Vframe_title_format
4269 = Fcons (intern ("multiple-frames"),
4270 Fcons (build_string ("%b"),
4271 Fcons (Fcons (build_string (""),
4272 Fcons (intern ("invocation-name"),
4273 Fcons (build_string ("@"),
4274 Fcons (intern ("system-name"),
4275 Qnil)))),
4276 Qnil)));
4278 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
4279 "Maximum number of lines to keep in the message log buffer.\n\
4280 If nil, disable message logging. If t, log messages but don't truncate\n\
4281 the buffer when it becomes large.");
4282 XSETFASTINT (Vmessage_log_max, 50);
4284 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
4285 "Functions called before redisplay, if window sizes have changed.\n\
4286 The value should be a list of functions that take one argument.\n\
4287 Just before redisplay, for each frame, if any of its windows have changed\n\
4288 size since the last redisplay, or have been split or deleted,\n\
4289 all the functions in the list are called, with the frame as argument.");
4290 Vwindow_size_change_functions = Qnil;
4292 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions,
4293 "Functions to call when a window is redisplayed with scrolling.\n\
4294 Each function is called with two arguments, the window\n\
4295 and its new display-start position.");
4296 Vwindow_scroll_functions = Qnil;
4299 /* initialize the window system */
4300 init_xdisp ()
4302 Lisp_Object root_window;
4303 #ifndef COMPILER_REGISTER_BUG
4304 register
4305 #endif /* COMPILER_REGISTER_BUG */
4306 struct window *mini_w;
4308 this_line_bufpos = 0;
4310 mini_w = XWINDOW (minibuf_window);
4311 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
4313 echo_area_glyphs = 0;
4314 previous_echo_glyphs = 0;
4316 if (!noninteractive)
4318 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
4319 XSETFASTINT (XWINDOW (root_window)->top, 0);
4320 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
4321 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
4322 set_window_height (minibuf_window, 1, 0);
4324 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
4325 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));