]> code.delx.au - gnu-emacs/blob - src/xdisp.c
(prepare_menu_bars): Do the frame titles last.
[gnu-emacs] / src / xdisp.c
1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
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.
10
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.
15
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. */
19
20
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
38 #ifdef USE_X_TOOLKIT
39 extern void set_frame_menubar ();
40 #endif
41
42 extern int interrupt_input;
43 extern int command_loop_level;
44
45 extern Lisp_Object Qface;
46
47 /* Nonzero means print newline to stdout before next minibuffer message. */
48
49 int noninteractive_need_newline;
50
51 /* Nonzero means print newline to message log before next message. */
52
53 static int message_log_need_newline;
54
55 #define min(a, b) ((a) < (b) ? (a) : (b))
56 #define max(a, b) ((a) > (b) ? (a) : (b))
57
58 /* The buffer position of the first character appearing
59 entirely or partially on the current frame line.
60 Or zero, which disables the optimization for the current frame line. */
61 static int this_line_bufpos;
62
63 /* Number of characters past the end of this line,
64 including the terminating newline */
65 static int this_line_endpos;
66
67 /* The vertical position of this frame line. */
68 static int this_line_vpos;
69
70 /* Hpos value for start of display on this frame line.
71 Usually zero, but negative if first character really began
72 on previous line */
73 static int this_line_start_hpos;
74
75 /* Buffer that this_line variables are describing. */
76 static struct buffer *this_line_buffer;
77
78 /* Set by try_window_id to the vpos of first of any lines
79 scrolled on to the bottom of the frame. These lines should
80 not be included in any general scroll computation. */
81 static int scroll_bottom_vpos;
82
83 /* Value of echo_area_glyphs when it was last acted on.
84 If this is nonzero, there is a message on the frame
85 in the minibuffer and it should be erased as soon
86 as it is no longer requested to appear. */
87 char *previous_echo_glyphs;
88
89 /* Nonzero means truncate lines in all windows less wide than the frame */
90 int truncate_partial_width_windows;
91
92 /* Nonzero means we have more than one non-minibuffer-only frame.
93 Not guaranteed to be accurate except while parsing frame-title-format. */
94 int multiple_frames;
95
96 Lisp_Object Vglobal_mode_string;
97
98 /* Marker for where to display an arrow on top of the buffer text. */
99 Lisp_Object Voverlay_arrow_position;
100
101 /* String to display for the arrow. */
102 Lisp_Object Voverlay_arrow_string;
103
104 /* Like mode-line-format, but for the titlebar on a visible frame. */
105 Lisp_Object Vframe_title_format;
106
107 /* Like mode-line-format, but for the titlebar on an iconified frame. */
108 Lisp_Object Vicon_title_format;
109
110 /* List of functions to call when a window's size changes. These
111 functions get one arg, a frame on which one or more windows' sizes
112 have changed. */
113 static Lisp_Object Vwindow_size_change_functions;
114
115 /* Values of those variables at last redisplay. */
116 static Lisp_Object last_arrow_position, last_arrow_string;
117
118 Lisp_Object Qmenu_bar_update_hook;
119
120 /* Nonzero if overlay arrow has been displayed once in this window. */
121 static int overlay_arrow_seen;
122
123 /* Nonzero means highlight the region even in nonselected windows. */
124 static int highlight_nonselected_windows;
125
126 /* If cursor motion alone moves point off frame,
127 Try scrolling this many lines up or down if that will bring it back. */
128 int scroll_step;
129
130 /* Nonzero if try_window_id has made blank lines at window bottom
131 since the last redisplay that paused */
132 static int blank_end_of_window;
133
134 /* Number of windows showing the buffer of the selected window
135 (or another buffer with the same base buffer).
136 keyboard.c refers to this. */
137 int buffer_shared;
138
139 /* display_text_line sets these to the frame position (origin 0) of point,
140 whether the window is selected or not.
141 Set one to -1 first to determine whether point was found afterwards. */
142
143 static int cursor_vpos;
144 static int cursor_hpos;
145
146 int debug_end_pos;
147
148 /* Nonzero means display mode line highlighted */
149 int mode_line_inverse_video;
150
151 static int message_log_check_duplicate ();
152 static void echo_area_display ();
153 void mark_window_display_accurate ();
154 static void redisplay_windows ();
155 static void redisplay_window ();
156 static void update_menu_bars ();
157 static void update_menu_bar ();
158 static void try_window ();
159 static int try_window_id ();
160 static struct position *display_text_line ();
161 static void display_mode_line ();
162 static int display_mode_element ();
163 static char *fmodetrunc ();
164 static char *decode_mode_spec ();
165 static int display_string ();
166 static void display_menu_bar ();
167 static int display_count_lines ();
168
169 /* Prompt to display in front of the minibuffer contents */
170 Lisp_Object minibuf_prompt;
171
172 /* Width in columns of current minibuffer prompt. */
173 int minibuf_prompt_width;
174
175 /* Message to display instead of minibuffer contents
176 This is what the functions error and message make,
177 and command echoing uses it as well.
178 It overrides the minibuf_prompt as well as the buffer. */
179 char *echo_area_glyphs;
180
181 /* This is the length of the message in echo_area_glyphs. */
182 int echo_area_glyphs_length;
183
184 /* true iff we should redraw the mode lines on the next redisplay */
185 int update_mode_lines;
186
187 /* Smallest number of characters before the gap
188 at any time since last redisplay that finished.
189 Valid for current buffer when try_window_id can be called. */
190 int beg_unchanged;
191
192 /* Smallest number of characters after the gap
193 at any time since last redisplay that finished.
194 Valid for current buffer when try_window_id can be called. */
195 int end_unchanged;
196
197 /* MODIFF as of last redisplay that finished;
198 if it matches MODIFF, beg_unchanged and end_unchanged
199 contain no useful information */
200 int unchanged_modified;
201
202 /* Nonzero if head_clip or tail_clip of current buffer has changed
203 since last redisplay that finished */
204 int clip_changed;
205
206 /* Nonzero if window sizes or contents have changed
207 since last redisplay that finished */
208 int windows_or_buffers_changed;
209
210 /* Nonzero after display_mode_line if %l was used
211 and it displayed a line number. */
212 int line_number_displayed;
213
214 /* Maximum buffer size for which to display line numbers. */
215 int line_number_display_limit;
216
217 /* Number of lines to keep in the message log buffer.
218 t means infinite. nil means don't log at all. */
219 Lisp_Object Vmessage_log_max;
220 \f
221 void
222 message_log_maybe_newline ()
223 {
224 if (message_log_need_newline)
225 message_dolog ("", 0, 1);
226 }
227
228
229 /* Add a string to the message log, optionally terminated with a newline.
230 This function calls low-level routines in order to bypass text property
231 hooks, etc. which might not be safe to run. */
232
233 void
234 message_dolog (m, len, nlflag)
235 char *m;
236 int len, nlflag;
237 {
238 if (!NILP (Vmessage_log_max))
239 {
240 struct buffer *oldbuf;
241 int oldpoint, oldbegv, oldzv;
242
243 oldbuf = current_buffer;
244 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
245 oldpoint = PT;
246 oldbegv = BEGV;
247 oldzv = ZV;
248 BEGV = BEG;
249 ZV = Z;
250 if (oldpoint == Z)
251 oldpoint += len + nlflag;
252 if (oldzv == Z)
253 oldzv += len + nlflag;
254 TEMP_SET_PT (Z);
255 if (len)
256 insert_1 (m, len, 1, 0);
257 if (nlflag)
258 {
259 int this_bol, prev_bol, dup;
260 insert_1 ("\n", 1, 1, 0);
261
262 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
263 if (this_bol > BEG)
264 {
265 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
266 dup = message_log_check_duplicate (prev_bol, this_bol);
267 if (dup)
268 {
269 if (oldpoint > prev_bol)
270 oldpoint -= min (this_bol, oldpoint) - prev_bol;
271 if (oldbegv > prev_bol)
272 oldbegv -= min (this_bol, oldbegv) - prev_bol;
273 if (oldzv > prev_bol)
274 oldzv -= min (this_bol, oldzv) - prev_bol;
275 del_range_1 (prev_bol, this_bol, 0);
276 if (dup > 1)
277 {
278 char dupstr[40];
279 int duplen;
280
281 /* If you change this format, don't forget to also
282 change message_log_check_duplicate. */
283 sprintf (dupstr, " [%d times]", dup);
284 duplen = strlen (dupstr);
285 TEMP_SET_PT (Z-1);
286 if (oldpoint == Z)
287 oldpoint += duplen;
288 if (oldzv == Z)
289 oldzv += duplen;
290 insert_1 (dupstr, duplen, 1, 0);
291 }
292 }
293 }
294
295 if (NATNUMP (Vmessage_log_max))
296 {
297 int pos = scan_buffer ('\n', Z, 0,
298 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
299 oldpoint -= min (pos, oldpoint) - BEG;
300 oldbegv -= min (pos, oldbegv) - BEG;
301 oldzv -= min (pos, oldzv) - BEG;
302 del_range_1 (BEG, pos, 0);
303 }
304 }
305 BEGV = oldbegv;
306 ZV = oldzv;
307 TEMP_SET_PT (oldpoint);
308 set_buffer_internal (oldbuf);
309 message_log_need_newline = !nlflag;
310 }
311 }
312
313
314 /* We are at the end of the buffer after just having inserted a newline.
315 (Note: We depend on the fact we won't be crossing the gap.)
316 Check to see if the most recent message looks a lot like the previous one.
317 Return 0 if different, 1 if the new one should just replace it, or a
318 value N > 1 if we should also append " [N times]". */
319 static int
320 message_log_check_duplicate (prev_bol, this_bol)
321 int prev_bol, this_bol;
322 {
323 int i;
324 int len = Z - 1 - this_bol;
325 int seen_dots = 0;
326 char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
327 char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
328
329 for (i = 0; i < len; i++)
330 {
331 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
332 && p1[i] != '\n')
333 seen_dots = 1;
334 if (p1[i] != p2[i])
335 return seen_dots;
336 }
337 p1 += len;
338 if (*p1 == '\n')
339 return 2;
340 if (*p1++ == ' ' && *p1++ == '[')
341 {
342 int n = 0;
343 while (*p1 >= '0' && *p1 <= '9')
344 n = n * 10 + *p1++ - '0';
345 if (strncmp (p1, " times]\n", 8) == 0)
346 return n+1;
347 }
348 return 0;
349 }
350
351 /* Display an echo area message M with a specified length of LEN chars.
352 The string may include null characters. If m is 0, clear out any
353 existing message, and let the minibuffer text show through.
354 Do not pass text that is stored in a Lisp string. */
355
356 void
357 message2 (m, len)
358 char *m;
359 int len;
360 {
361 /* First flush out any partial line written with print. */
362 message_log_maybe_newline ();
363 if (m)
364 message_dolog (m, len, 1);
365 message2_nolog (m, len);
366 }
367
368
369 /* The non-logging part of that function. */
370
371 void
372 message2_nolog (m, len)
373 char *m;
374 int len;
375 {
376 if (noninteractive)
377 {
378 if (noninteractive_need_newline)
379 putc ('\n', stderr);
380 noninteractive_need_newline = 0;
381 fwrite (m, len, 1, stderr);
382 if (cursor_in_echo_area == 0)
383 fprintf (stderr, "\n");
384 fflush (stderr);
385 }
386 /* A null message buffer means that the frame hasn't really been
387 initialized yet. Error messages get reported properly by
388 cmd_error, so this must be just an informative message; toss it. */
389 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
390 {
391 #ifdef MULTI_FRAME
392 Lisp_Object minibuf_frame;
393
394 choose_minibuf_frame ();
395 minibuf_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
396 FRAME_SAMPLE_VISIBILITY (XFRAME (minibuf_frame));
397 if (FRAME_VISIBLE_P (selected_frame)
398 && ! FRAME_VISIBLE_P (XFRAME (minibuf_frame)))
399 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (minibuf_window)));
400 #endif
401
402 if (m)
403 {
404 echo_area_glyphs = m;
405 echo_area_glyphs_length = len;
406 }
407 else
408 echo_area_glyphs = previous_echo_glyphs = 0;
409
410 do_pending_window_change ();
411 echo_area_display ();
412 update_frame (XFRAME (XWINDOW (minibuf_window)->frame), 1, 1);
413 do_pending_window_change ();
414 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
415 (*frame_up_to_date_hook) (XFRAME (XWINDOW (minibuf_window)->frame));
416 }
417 }
418
419 void
420 message1 (m)
421 char *m;
422 {
423 message2 (m, (m ? strlen (m) : 0));
424 }
425
426 void
427 message1_nolog (m)
428 char *m;
429 {
430 message2_nolog (m, (m ? strlen (m) : 0));
431 }
432
433 /* Truncate what will be displayed in the echo area
434 the next time we display it--but don't redisplay it now. */
435
436 void
437 truncate_echo_area (len)
438 int len;
439 {
440 /* A null message buffer means that the frame hasn't really been
441 initialized yet. Error messages get reported properly by
442 cmd_error, so this must be just an informative message; toss it. */
443 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
444 echo_area_glyphs_length = len;
445 }
446
447 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
448 zero if being used by message. */
449 int message_buf_print;
450
451 /* Dump an informative message to the minibuf. If m is 0, clear out
452 any existing message, and let the minibuffer text show through. */
453 /* VARARGS 1 */
454 void
455 message (m, a1, a2, a3)
456 char *m;
457 EMACS_INT a1, a2, a3;
458 {
459 if (noninteractive)
460 {
461 if (m)
462 {
463 if (noninteractive_need_newline)
464 putc ('\n', stderr);
465 noninteractive_need_newline = 0;
466 fprintf (stderr, m, a1, a2, a3);
467 if (cursor_in_echo_area == 0)
468 fprintf (stderr, "\n");
469 fflush (stderr);
470 }
471 }
472 else if (INTERACTIVE)
473 {
474 /* The frame whose minibuffer we're going to display the message on.
475 It may be larger than the selected frame, so we need
476 to use its buffer, not the selected frame's buffer. */
477 FRAME_PTR echo_frame;
478 #ifdef MULTI_FRAME
479 choose_minibuf_frame ();
480 echo_frame = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
481 #else
482 echo_frame = selected_frame;
483 #endif
484
485 /* A null message buffer means that the frame hasn't really been
486 initialized yet. Error messages get reported properly by
487 cmd_error, so this must be just an informative message; toss it. */
488 if (FRAME_MESSAGE_BUF (echo_frame))
489 {
490 if (m)
491 {
492 int len;
493 #ifdef NO_ARG_ARRAY
494 EMACS_INT a[3];
495 a[0] = a1;
496 a[1] = a2;
497 a[2] = a3;
498
499 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
500 FRAME_WIDTH (echo_frame), m, 0, 3, a);
501 #else
502 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
503 FRAME_WIDTH (echo_frame), m, 0, 3, &a1);
504 #endif /* NO_ARG_ARRAY */
505
506 message2 (FRAME_MESSAGE_BUF (echo_frame), len);
507 }
508 else
509 message1 (0);
510
511 /* Print should start at the beginning of the message
512 buffer next time. */
513 message_buf_print = 0;
514 }
515 }
516 }
517
518 /* The non-logging version of that function. */
519 void
520 message_nolog (m, a1, a2, a3)
521 char *m;
522 EMACS_INT a1, a2, a3;
523 {
524 Lisp_Object old_log_max;
525 old_log_max = Vmessage_log_max;
526 Vmessage_log_max = Qnil;
527 message (m, a1, a2, a3);
528 Vmessage_log_max = old_log_max;
529 }
530
531 void
532 update_echo_area ()
533 {
534 message2 (echo_area_glyphs, echo_area_glyphs_length);
535 }
536
537 static void
538 echo_area_display ()
539 {
540 register int vpos;
541 FRAME_PTR f;
542
543 #ifdef MULTI_FRAME
544 choose_minibuf_frame ();
545 #endif
546
547 f = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
548
549 if (! FRAME_VISIBLE_P (f))
550 return;
551
552 if (frame_garbaged)
553 {
554 redraw_garbaged_frames ();
555 frame_garbaged = 0;
556 }
557
558 if (echo_area_glyphs || minibuf_level == 0)
559 {
560 vpos = XFASTINT (XWINDOW (minibuf_window)->top);
561 get_display_line (f, vpos, 0);
562 display_string (XWINDOW (minibuf_window), vpos,
563 echo_area_glyphs ? echo_area_glyphs : "",
564 echo_area_glyphs ? echo_area_glyphs_length : -1,
565 0, 0, 0, 0, FRAME_WIDTH (f));
566
567 /* If desired cursor location is on this line, put it at end of text */
568 if (FRAME_CURSOR_Y (f) == vpos)
569 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
570
571 /* Fill the rest of the minibuffer window with blank lines. */
572 {
573 int i;
574
575 for (i = vpos + 1;
576 i < vpos + XFASTINT (XWINDOW (minibuf_window)->height); i++)
577 {
578 get_display_line (f, i, 0);
579 display_string (XWINDOW (minibuf_window), vpos,
580 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f));
581 }
582 }
583 }
584 else if (!EQ (minibuf_window, selected_window))
585 windows_or_buffers_changed++;
586
587 if (EQ (minibuf_window, selected_window))
588 this_line_bufpos = 0;
589
590 previous_echo_glyphs = echo_area_glyphs;
591 }
592
593 #ifdef HAVE_X_WINDOWS
594 static char frame_title_buf[512];
595 static char *frame_title_ptr;
596
597 static int
598 store_frame_title (str, mincol, maxcol)
599 char *str;
600 int mincol, maxcol;
601 {
602 char *limit;
603 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
604 maxcol = sizeof (frame_title_buf);
605 limit = &frame_title_buf[maxcol];
606 while (*str != '\0' && frame_title_ptr < limit)
607 *frame_title_ptr++ = *str++;
608 while (frame_title_ptr < &frame_title_buf[mincol])
609 *frame_title_ptr++ = ' ';
610 return frame_title_ptr - frame_title_buf;
611 }
612
613 static void
614 x_consider_frame_title (frame)
615 Lisp_Object frame;
616 {
617 Lisp_Object fmt;
618 struct buffer *obuf;
619 int len;
620 FRAME_PTR f = XFRAME (frame);
621
622 if (!FRAME_X_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name)
623 return;
624 multiple_frames = !EQ (Fnext_frame (frame, Qnil), frame);
625 obuf = current_buffer;
626 Fset_buffer (XWINDOW (f->selected_window)->buffer);
627 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
628 frame_title_ptr = frame_title_buf;
629 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
630 0, sizeof (frame_title_buf), fmt);
631 frame_title_ptr = 0;
632 set_buffer_internal (obuf);
633 /* Set the name only if it's changed. This avoids consing
634 in the common case where it hasn't. (If it turns out that we've
635 already wasted too much time by walking through the list with
636 display_mode_element, then we might need to optimize at a higher
637 level than this.) */
638 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
639 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
640 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
641 }
642 #else
643 #define frame_title_ptr ((char *)0)
644 #define store_frame_title(str, mincol, maxcol) 0
645 #endif
646 \f
647 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
648 This can't be done in `redisplay' itself because it can call eval. */
649
650 void
651 prepare_menu_bars ()
652 {
653 register struct window *w = XWINDOW (selected_window);
654 int all_windows;
655 struct gcpro gcpro1, gcpro2;
656
657 if (noninteractive)
658 return;
659
660 /* Set the visible flags for all frames.
661 Do this before checking for resized or garbaged frames; they want
662 to know if their frames are visible.
663 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
664 {
665 Lisp_Object tail, frame;
666
667 FOR_EACH_FRAME (tail, frame)
668 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
669 }
670
671 /* Notice any pending interrupt request to change frame size. */
672 do_pending_window_change ();
673
674 if (frame_garbaged)
675 {
676 redraw_garbaged_frames ();
677 frame_garbaged = 0;
678 }
679
680 all_windows = (update_mode_lines || buffer_shared > 1
681 || clip_changed || windows_or_buffers_changed);
682
683 /* Update the menu bar item lists, if appropriate.
684 This has to be done before any actual redisplay
685 or generation of display lines. */
686 if (all_windows)
687 {
688 Lisp_Object tail, frame;
689
690 FOR_EACH_FRAME (tail, frame)
691 {
692 /* If a window on this frame changed size,
693 report that to the user and clear the size-change flag. */
694 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
695 {
696 Lisp_Object functions;
697 functions = Vwindow_size_change_functions;
698 GCPRO2 (tail, functions);
699 while (CONSP (functions))
700 {
701 call1 (XCONS (functions)->car, frame);
702 functions = XCONS (functions)->cdr;
703 }
704 UNGCPRO;
705 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
706 }
707 GCPRO1 (tail);
708 update_menu_bar (XFRAME (frame));
709 UNGCPRO;
710 }
711 }
712 else
713 update_menu_bar (selected_frame);
714
715 /* Update all frame titles based on their buffer names, etc.
716 We do this after the menu bars so that the frame will first
717 create its menu bar using the name `emacs' if no other name
718 has yet been specified. */
719 #ifdef HAVE_X_WINDOWS
720 if (windows_or_buffers_changed)
721 {
722 Lisp_Object tail, frame;
723
724 FOR_EACH_FRAME (tail, frame)
725 if (FRAME_VISIBLE_P (XFRAME (frame))
726 || FRAME_ICONIFIED_P (XFRAME (frame)))
727 x_consider_frame_title (frame);
728 }
729 #endif
730 }
731 \f
732 /* Do a frame update, taking possible shortcuts into account.
733 This is the main external entry point for redisplay.
734
735 If the last redisplay displayed an echo area message and that
736 message is no longer requested, we clear the echo area
737 or bring back the minibuffer if that is in use.
738
739 Do not call eval from within this function.
740 Calls to eval after the call to echo_area_display would confuse
741 the display_line mechanism and would cause a crash.
742 Calls to eval before that point will work most of the time,
743 but can still lose, because this function
744 can be called from signal handlers; with alarms set up;
745 or with synchronous processes running.
746
747 See Fcall_process; if you called it from here, it could be
748 entered recursively. */
749
750 static int do_verify_charstarts;
751
752 /* Counter is used to clear the face cache
753 no more than once ever 1000 redisplays. */
754 static int clear_face_cache_count;
755
756 void
757 redisplay ()
758 {
759 register struct window *w = XWINDOW (selected_window);
760 register int pause;
761 int must_finish = 0;
762 int all_windows;
763 register int tlbufpos, tlendpos;
764 struct position pos;
765
766 if (noninteractive)
767 return;
768
769 /* Set the visible flags for all frames.
770 Do this before checking for resized or garbaged frames; they want
771 to know if their frames are visible.
772 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
773 {
774 Lisp_Object tail, frame;
775
776 FOR_EACH_FRAME (tail, frame)
777 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
778 }
779
780 /* Notice any pending interrupt request to change frame size. */
781 do_pending_window_change ();
782
783 if (frame_garbaged)
784 {
785 redraw_garbaged_frames ();
786 frame_garbaged = 0;
787 }
788
789 if (clip_changed || windows_or_buffers_changed
790 || (!NILP (w->column_number_displayed)
791 && XFASTINT (w->column_number_displayed) != current_column ()))
792 update_mode_lines++;
793
794 /* Detect case that we need to write a star in the mode line. */
795 if (XFASTINT (w->last_modified) < MODIFF
796 && XFASTINT (w->last_modified) <= SAVE_MODIFF)
797 {
798 w->update_mode_line = Qt;
799 if (buffer_shared > 1)
800 update_mode_lines++;
801 }
802
803 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
804
805 all_windows = update_mode_lines || buffer_shared > 1;
806
807 /* If specs for an arrow have changed, do thorough redisplay
808 to ensure we remove any arrow that should no longer exist. */
809 if (! EQ (Voverlay_arrow_position, last_arrow_position)
810 || ! EQ (Voverlay_arrow_string, last_arrow_string))
811 all_windows = 1, clip_changed = 1;
812
813 /* Normally the message* functions will have already displayed and
814 updated the echo area, but the frame may have been trashed, or
815 the update may have been preempted, so display the echo area
816 again here. */
817 if (echo_area_glyphs || previous_echo_glyphs)
818 {
819 echo_area_display ();
820 must_finish = 1;
821 }
822
823 /* If showing region, and mark has changed, must redisplay whole window. */
824 if (((!NILP (Vtransient_mark_mode)
825 && !NILP (XBUFFER (w->buffer)->mark_active))
826 != !NILP (w->region_showing))
827 || (!NILP (w->region_showing)
828 && !EQ (w->region_showing,
829 Fmarker_position (XBUFFER (w->buffer)->mark))))
830 this_line_bufpos = -1;
831
832 tlbufpos = this_line_bufpos;
833 tlendpos = this_line_endpos;
834 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
835 && FRAME_VISIBLE_P (XFRAME (w->frame))
836 /* Make sure recorded data applies to current buffer, etc */
837 && this_line_buffer == current_buffer
838 && current_buffer == XBUFFER (w->buffer)
839 && NILP (w->force_start)
840 /* Point must be on the line that we have info recorded about */
841 && PT >= tlbufpos
842 && PT <= Z - tlendpos
843 /* All text outside that line, including its final newline,
844 must be unchanged */
845 && (XFASTINT (w->last_modified) >= MODIFF
846 || (beg_unchanged >= tlbufpos - 1
847 && GPT >= tlbufpos
848 /* If selective display, can't optimize
849 if the changes start at the beginning of the line. */
850 && ((INTEGERP (current_buffer->selective_display)
851 && XINT (current_buffer->selective_display) > 0
852 ? (beg_unchanged >= tlbufpos
853 && GPT > tlbufpos)
854 : 1))
855 && end_unchanged >= tlendpos
856 && Z - GPT >= tlendpos)))
857 {
858 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
859 && (tlbufpos == ZV
860 || FETCH_CHAR (tlbufpos) == '\n'))
861 /* Former continuation line has disappeared by becoming empty */
862 goto cancel;
863 else if (XFASTINT (w->last_modified) < MODIFF
864 || MINI_WINDOW_P (w))
865 {
866 cursor_vpos = -1;
867 overlay_arrow_seen = 0;
868 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
869 pos_tab_offset (w, tlbufpos));
870 /* If line contains point, is not continued,
871 and ends at same distance from eob as before, we win */
872 if (cursor_vpos >= 0 && this_line_bufpos
873 && this_line_endpos == tlendpos)
874 {
875 /* If this is not the window's last line,
876 we must adjust the charstarts of the lines below. */
877 if (this_line_vpos + 1
878 < XFASTINT (w->top) + window_internal_height (w))
879 {
880 int left = XFASTINT (w->left);
881 int *charstart_next_line
882 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
883 int adjust;
884
885 if (Z - tlendpos == ZV)
886 /* This line ends at end of (accessible part of) buffer.
887 There is no newline to count. */
888 adjust = Z - tlendpos - charstart_next_line[left];
889 else
890 /* This line ends in a newline.
891 Must take account of the newline and the rest of the
892 text that follows. */
893 adjust = Z - tlendpos + 1 - charstart_next_line[left];
894
895 adjust_window_charstarts (w, this_line_vpos, adjust);
896 }
897
898 if (XFASTINT (w->width) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w))))
899 preserve_other_columns (w);
900 goto update;
901 }
902 else
903 goto cancel;
904 }
905 else if (PT == XFASTINT (w->last_point))
906 {
907 if (!must_finish)
908 {
909 do_pending_window_change ();
910 return;
911 }
912 goto update;
913 }
914 /* If highlighting the region, we can't just move the cursor. */
915 else if (! (!NILP (Vtransient_mark_mode)
916 && !NILP (current_buffer->mark_active))
917 && NILP (w->region_showing))
918 {
919 pos = *compute_motion (tlbufpos, 0,
920 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
921 PT, 2, - (1 << (SHORTBITS - 1)),
922 window_internal_width (w) - 1,
923 XINT (w->hscroll),
924 pos_tab_offset (w, tlbufpos), w);
925 if (pos.vpos < 1)
926 {
927 FRAME_CURSOR_X (selected_frame)
928 = XFASTINT (w->left) + max (pos.hpos, 0);
929 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
930 goto update;
931 }
932 else
933 goto cancel;
934 }
935 cancel:
936 /* Text changed drastically or point moved off of line */
937 cancel_line (this_line_vpos, selected_frame);
938 }
939
940 this_line_bufpos = 0;
941 all_windows |= buffer_shared > 1;
942
943 clear_face_cache_count++;
944
945 if (all_windows)
946 {
947 Lisp_Object tail, frame;
948
949 #ifdef HAVE_FACES
950 /* Clear the face cache, only when we do a full redisplay
951 and not too often either. */
952 if (clear_face_cache_count > 1000)
953 {
954 clear_face_cache ();
955 clear_face_cache_count = 0;
956 }
957 #endif
958
959 /* Recompute # windows showing selected buffer.
960 This will be incremented each time such a window is displayed. */
961 buffer_shared = 0;
962
963 FOR_EACH_FRAME (tail, frame)
964 {
965 FRAME_PTR f = XFRAME (frame);
966 if (! FRAME_TERMCAP_P (f) || f == selected_frame)
967 {
968
969 /* Mark all the scroll bars to be removed; we'll redeem the ones
970 we want when we redisplay their windows. */
971 if (condemn_scroll_bars_hook)
972 (*condemn_scroll_bars_hook) (f);
973
974 if (FRAME_VISIBLE_P (f))
975 redisplay_windows (FRAME_ROOT_WINDOW (f));
976
977 /* Any scroll bars which redisplay_windows should have nuked
978 should now go away. */
979 if (judge_scroll_bars_hook)
980 (*judge_scroll_bars_hook) (f);
981 }
982 }
983 }
984 else if (FRAME_VISIBLE_P (selected_frame))
985 {
986 redisplay_window (selected_window, 1);
987 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
988 preserve_other_columns (w);
989 }
990
991 update:
992 /* Prevent various kinds of signals during display update.
993 stdio is not robust about handling signals,
994 which can cause an apparent I/O error. */
995 if (interrupt_input)
996 unrequest_sigio ();
997 stop_polling ();
998
999 #ifdef MULTI_FRAME
1000 if (all_windows)
1001 {
1002 Lisp_Object tail;
1003
1004 pause = 0;
1005
1006 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
1007 {
1008 FRAME_PTR f;
1009
1010 if (!FRAMEP (XCONS (tail)->car))
1011 continue;
1012
1013 f = XFRAME (XCONS (tail)->car);
1014 if (FRAME_VISIBLE_P (f))
1015 {
1016 pause |= update_frame (f, 0, 0);
1017 if (!pause)
1018 {
1019 mark_window_display_accurate (f->root_window, 1);
1020 if (frame_up_to_date_hook != 0)
1021 (*frame_up_to_date_hook) (f);
1022 }
1023 }
1024 }
1025 }
1026 else
1027 #endif /* MULTI_FRAME */
1028 {
1029 if (FRAME_VISIBLE_P (selected_frame))
1030 pause = update_frame (selected_frame, 0, 0);
1031 else
1032 pause = 0;
1033
1034 /* We may have called echo_area_display at the top of this
1035 function. If the echo area is on another frame, that may
1036 have put text on a frame other than the selected one, so the
1037 above call to update_frame would not have caught it. Catch
1038 it here. */
1039 {
1040 FRAME_PTR mini_frame
1041 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
1042
1043 if (mini_frame != selected_frame)
1044 pause |= update_frame (mini_frame, 0, 0);
1045 }
1046 }
1047
1048 /* If frame does not match, prevent doing single-line-update next time.
1049 Also, don't forget to check every line to update the arrow. */
1050 if (pause)
1051 {
1052 this_line_bufpos = 0;
1053 if (!NILP (last_arrow_position))
1054 {
1055 last_arrow_position = Qt;
1056 last_arrow_string = Qt;
1057 }
1058 /* If we pause after scrolling, some lines in current_frame
1059 may be null, so preserve_other_columns won't be able to
1060 preserve all the vertical-bar separators. So, avoid using it
1061 in that case. */
1062 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
1063 update_mode_lines = 1;
1064 }
1065
1066 /* Now text on frame agrees with windows, so
1067 put info into the windows for partial redisplay to follow */
1068
1069 if (!pause)
1070 {
1071 register struct buffer *b = XBUFFER (w->buffer);
1072
1073 blank_end_of_window = 0;
1074 clip_changed = 0;
1075 unchanged_modified = BUF_MODIFF (b);
1076 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1077 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1078
1079 XSETFASTINT (w->last_point, BUF_PT (b));
1080 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1081 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1082
1083 if (all_windows)
1084 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1085 else
1086 {
1087 w->update_mode_line = Qnil;
1088 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1089 w->window_end_valid = w->buffer;
1090 last_arrow_position = Voverlay_arrow_position;
1091 last_arrow_string = Voverlay_arrow_string;
1092 if (do_verify_charstarts)
1093 verify_charstarts (w);
1094 if (frame_up_to_date_hook != 0)
1095 (*frame_up_to_date_hook) (selected_frame);
1096 }
1097 update_mode_lines = 0;
1098 windows_or_buffers_changed = 0;
1099 }
1100
1101 /* Start SIGIO interrupts coming again.
1102 Having them off during the code above
1103 makes it less likely one will discard output,
1104 but not impossible, since there might be stuff
1105 in the system buffer here.
1106 But it is much hairier to try to do anything about that. */
1107
1108 if (interrupt_input)
1109 request_sigio ();
1110 start_polling ();
1111
1112 /* Change frame size now if a change is pending. */
1113 do_pending_window_change ();
1114
1115 /* If we just did a pending size change, redisplay again
1116 for the new size. */
1117 if (windows_or_buffers_changed && !pause)
1118 redisplay ();
1119 }
1120
1121 /* Redisplay, but leave alone any recent echo area message
1122 unless another message has been requested in its place.
1123
1124 This is useful in situations where you need to redisplay but no
1125 user action has occurred, making it inappropriate for the message
1126 area to be cleared. See tracking_off and
1127 wait_reading_process_input for examples of these situations. */
1128
1129 redisplay_preserve_echo_area ()
1130 {
1131 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1132 {
1133 echo_area_glyphs = previous_echo_glyphs;
1134 redisplay ();
1135 echo_area_glyphs = 0;
1136 }
1137 else
1138 redisplay ();
1139 }
1140
1141 void
1142 mark_window_display_accurate (window, flag)
1143 Lisp_Object window;
1144 int flag;
1145 {
1146 register struct window *w;
1147
1148 for (;!NILP (window); window = w->next)
1149 {
1150 if (!WINDOWP (window)) abort ();
1151 w = XWINDOW (window);
1152
1153 if (!NILP (w->buffer))
1154 {
1155 XSETFASTINT (w->last_modified,
1156 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1157
1158 /* Record if we are showing a region, so can make sure to
1159 update it fully at next redisplay. */
1160 w->region_showing = (!NILP (Vtransient_mark_mode)
1161 && !NILP (XBUFFER (w->buffer)->mark_active)
1162 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1163 : Qnil);
1164 }
1165
1166 w->window_end_valid = w->buffer;
1167 w->update_mode_line = Qnil;
1168
1169 if (!NILP (w->vchild))
1170 mark_window_display_accurate (w->vchild, flag);
1171 if (!NILP (w->hchild))
1172 mark_window_display_accurate (w->hchild, flag);
1173 }
1174
1175 if (flag)
1176 {
1177 last_arrow_position = Voverlay_arrow_position;
1178 last_arrow_string = Voverlay_arrow_string;
1179 }
1180 else
1181 {
1182 /* t is unequal to any useful value of Voverlay_arrow_... */
1183 last_arrow_position = Qt;
1184 last_arrow_string = Qt;
1185 }
1186 }
1187 \f
1188 /* Update the menu bar item list for frame F.
1189 This has to be done before we start to fill in any display lines,
1190 because it can call eval. */
1191
1192 static void
1193 update_menu_bar (f)
1194 FRAME_PTR f;
1195 {
1196 struct buffer *old = current_buffer;
1197 Lisp_Object window;
1198 register struct window *w;
1199 window = FRAME_SELECTED_WINDOW (f);
1200 w = XWINDOW (window);
1201
1202 if (update_mode_lines)
1203 w->update_mode_line = Qt;
1204
1205 if (
1206 #ifdef USE_X_TOOLKIT
1207 FRAME_EXTERNAL_MENU_BAR (f)
1208 #else
1209 FRAME_MENU_BAR_LINES (f) > 0
1210 #endif
1211 )
1212 {
1213 /* If the user has switched buffers or windows, we need to
1214 recompute to reflect the new bindings. But we'll
1215 recompute when update_mode_lines is set too; that means
1216 that people can use force-mode-line-update to request
1217 that the menu bar be recomputed. The adverse effect on
1218 the rest of the redisplay algorithm is about the same as
1219 windows_or_buffers_changed anyway. */
1220 if (windows_or_buffers_changed
1221 || !NILP (w->update_mode_line)
1222 || (XFASTINT (w->last_modified) < MODIFF
1223 && (XFASTINT (w->last_modified)
1224 <= BUF_SAVE_MODIFF (XBUFFER (w->buffer)))))
1225 {
1226 struct buffer *prev = current_buffer;
1227 call1 (Vrun_hooks, Qmenu_bar_update_hook);
1228 current_buffer = XBUFFER (w->buffer);
1229 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1230 current_buffer = prev;
1231 #ifdef USE_X_TOOLKIT
1232 set_frame_menubar (f, 0);
1233 #endif /* USE_X_TOOLKIT */
1234 }
1235 }
1236 }
1237 \f
1238 int do_id = 1;
1239
1240 /* Redisplay WINDOW and its subwindows and siblings. */
1241
1242 static void
1243 redisplay_windows (window)
1244 Lisp_Object window;
1245 {
1246 for (; !NILP (window); window = XWINDOW (window)->next)
1247 redisplay_window (window, 0);
1248 }
1249
1250 /* Redisplay window WINDOW and its subwindows. */
1251
1252 static void
1253 redisplay_window (window, just_this_one)
1254 Lisp_Object window;
1255 int just_this_one;
1256 {
1257 register struct window *w = XWINDOW (window);
1258 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1259 int height;
1260 register int lpoint = PT;
1261 struct buffer *old = current_buffer;
1262 register int width = window_internal_width (w) - 1;
1263 register int startp;
1264 register int hscroll = XINT (w->hscroll);
1265 struct position pos;
1266 int opoint = PT;
1267 int tem;
1268 int update_mode_line;
1269
1270 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1271
1272 /* If this is a combination window, do its children; that's all. */
1273
1274 if (!NILP (w->vchild))
1275 {
1276 redisplay_windows (w->vchild);
1277 return;
1278 }
1279 if (!NILP (w->hchild))
1280 {
1281 redisplay_windows (w->hchild);
1282 return;
1283 }
1284 if (NILP (w->buffer))
1285 abort ();
1286
1287 height = window_internal_height (w);
1288 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1289
1290 if (MINI_WINDOW_P (w))
1291 {
1292 if (w == XWINDOW (minibuf_window))
1293 {
1294 if (echo_area_glyphs)
1295 /* We've already displayed the echo area glyphs, if any. */
1296 goto finish_scroll_bars;
1297 }
1298 else
1299 {
1300 /* This is a minibuffer, but it's not the currently active one, so
1301 clear it. */
1302 int vpos = XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top);
1303 int i;
1304
1305 for (i = 0; i < height; i++)
1306 {
1307 get_display_line (f, vpos + i, 0);
1308 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
1309 }
1310
1311 goto finish_scroll_bars;
1312 }
1313 }
1314
1315 /* Otherwise set up data on this window; select its buffer and point value */
1316
1317 if (update_mode_line)
1318 set_buffer_internal (XBUFFER (w->buffer));
1319 else
1320 set_buffer_temp (XBUFFER (w->buffer));
1321
1322 opoint = PT;
1323
1324 /* Count number of windows showing the selected buffer.
1325 An indirect buffer counts as its base buffer. */
1326
1327 if (!just_this_one)
1328 {
1329 struct buffer *current_base, *window_base;
1330 current_base = current_buffer;
1331 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1332 if (current_base->base_buffer)
1333 current_base = current_base->base_buffer;
1334 if (window_base->base_buffer)
1335 window_base = window_base->base_buffer;
1336 if (current_base == window_base)
1337 buffer_shared++;
1338 }
1339
1340 /* POINT refers normally to the selected window.
1341 For any other window, set up appropriate value. */
1342
1343 if (!EQ (window, selected_window))
1344 {
1345 int new_pt = marker_position (w->pointm);
1346 if (new_pt < BEGV)
1347 {
1348 new_pt = BEGV;
1349 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1350 }
1351 else if (new_pt > (ZV - 1))
1352 {
1353 new_pt = ZV;
1354 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1355 }
1356 /* We don't use SET_PT so that the point-motion hooks don't run. */
1357 BUF_PT (current_buffer) = new_pt;
1358 }
1359
1360 /* If any of the character widths specified in the display table
1361 have changed, invalidate the width run cache. It's true that this
1362 may be a bit late to catch such changes, but the rest of
1363 redisplay goes (non-fatally) haywire when the display table is
1364 changed, so why should we worry about doing any better? */
1365 if (current_buffer->width_run_cache)
1366 {
1367 struct Lisp_Vector *disptab = buffer_display_table ();
1368
1369 if (! disptab_matches_widthtab (disptab,
1370 XVECTOR (current_buffer->width_table)))
1371 {
1372 invalidate_region_cache (current_buffer,
1373 current_buffer->width_run_cache,
1374 BEG, Z);
1375 recompute_width_table (current_buffer, disptab);
1376 }
1377 }
1378
1379 /* If window-start is screwed up, choose a new one. */
1380 if (XMARKER (w->start)->buffer != current_buffer)
1381 goto recenter;
1382
1383 startp = marker_position (w->start);
1384
1385 /* Handle case where place to start displaying has been specified,
1386 unless the specified location is outside the accessible range. */
1387 if (!NILP (w->force_start))
1388 {
1389 /* Forget any recorded base line for line number display. */
1390 w->base_line_number = Qnil;
1391 /* Redisplay the mode line. Select the buffer properly for that. */
1392 if (!update_mode_line)
1393 {
1394 set_buffer_temp (old);
1395 set_buffer_internal (XBUFFER (w->buffer));
1396 update_mode_line = 1;
1397 w->update_mode_line = Qt;
1398 }
1399 w->force_start = Qnil;
1400 XSETFASTINT (w->last_modified, 0);
1401 if (startp < BEGV) startp = BEGV;
1402 if (startp > ZV) startp = ZV;
1403 try_window (window, startp);
1404 if (cursor_vpos < 0)
1405 {
1406 /* If point does not appear, move point so it does appear */
1407 pos = *compute_motion (startp, 0,
1408 ((EQ (window, minibuf_window) && startp == 1)
1409 ? minibuf_prompt_width : 0)
1410 +
1411 (hscroll ? 1 - hscroll : 0),
1412 ZV, height / 2,
1413 - (1 << (SHORTBITS - 1)),
1414 width, hscroll, pos_tab_offset (w, startp), w);
1415 BUF_PT (current_buffer) = pos.bufpos;
1416 if (w != XWINDOW (selected_window))
1417 Fset_marker (w->pointm, make_number (PT), Qnil);
1418 else
1419 {
1420 if (current_buffer == old)
1421 lpoint = PT;
1422 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1423 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1424 }
1425 /* If we are highlighting the region,
1426 then we just changed the region, so redisplay to show it. */
1427 if (!NILP (Vtransient_mark_mode)
1428 && !NILP (current_buffer->mark_active))
1429 {
1430 cancel_my_columns (XWINDOW (window));
1431 try_window (window, startp);
1432 }
1433 }
1434 goto done;
1435 }
1436
1437 /* Handle case where text has not changed, only point,
1438 and it has not moved off the frame */
1439
1440 /* This code is not used for minibuffer for the sake of
1441 the case of redisplaying to replace an echo area message;
1442 since in that case the minibuffer contents per se are usually unchanged.
1443 This code is of no real use in the minibuffer since
1444 the handling of this_line_bufpos, etc.,
1445 in redisplay handles the same cases. */
1446
1447 if (XFASTINT (w->last_modified) >= MODIFF
1448 && PT >= startp && !clip_changed
1449 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
1450 /* If force-mode-line-update was called, really redisplay;
1451 that's how redisplay is forced after e.g. changing
1452 buffer-invisibility-spec. */
1453 && NILP (w->update_mode_line)
1454 /* Can't use this case if highlighting a region. */
1455 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1456 && NILP (w->region_showing)
1457 /* If end pos is out of date, scroll bar and percentage will be wrong */
1458 && INTEGERP (w->window_end_vpos)
1459 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1460 && !EQ (window, minibuf_window))
1461 {
1462 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0),
1463 PT, height, 0, width, hscroll,
1464 pos_tab_offset (w, startp), w);
1465
1466 if (pos.vpos < height)
1467 {
1468 /* Ok, point is still on frame */
1469 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1470 {
1471 /* These variables are supposed to be origin 1 */
1472 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1473 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1474 }
1475 /* This doesn't do the trick, because if a window to the right of
1476 this one must be redisplayed, this does nothing because there
1477 is nothing in DesiredFrame yet, and then the other window is
1478 redisplayed, making likes that are empty in this window's columns.
1479 if (XFASTINT (w->width) != FRAME_WIDTH (f))
1480 preserve_my_columns (w);
1481 */
1482 goto done;
1483 }
1484 /* Don't bother trying redisplay with same start;
1485 we already know it will lose */
1486 }
1487 /* If current starting point was originally the beginning of a line
1488 but no longer is, find a new starting point. */
1489 else if (!NILP (w->start_at_line_beg)
1490 && !(startp <= BEGV
1491 || FETCH_CHAR (startp - 1) == '\n'))
1492 {
1493 goto recenter;
1494 }
1495 else if (just_this_one && !MINI_WINDOW_P (w)
1496 && PT >= startp
1497 && XFASTINT (w->last_modified)
1498 /* or else vmotion on first line won't work. */
1499 && ! NILP (w->start_at_line_beg)
1500 && ! EQ (w->window_end_valid, Qnil)
1501 && do_id && !clip_changed
1502 && !blank_end_of_window
1503 && XFASTINT (w->width) == FRAME_WIDTH (f)
1504 /* Can't use this case if highlighting a region. */
1505 && !(!NILP (Vtransient_mark_mode)
1506 && !NILP (current_buffer->mark_active))
1507 && NILP (w->region_showing)
1508 && EQ (last_arrow_position, Voverlay_arrow_position)
1509 && EQ (last_arrow_string, Voverlay_arrow_string)
1510 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1511 && tem != -2)
1512 {
1513 /* tem > 0 means success. tem == -1 means choose new start.
1514 tem == -2 means try again with same start,
1515 and nothing but whitespace follows the changed stuff.
1516 tem == 0 means try again with same start. */
1517 if (tem > 0)
1518 goto done;
1519 }
1520 else if (startp >= BEGV && startp <= ZV
1521 /* Avoid starting display at end of buffer! */
1522 && (startp < ZV || startp == BEGV
1523 || (XFASTINT (w->last_modified) >= MODIFF)))
1524 {
1525 /* Try to redisplay starting at same place as before */
1526 /* If point has not moved off frame, accept the results */
1527 try_window (window, startp);
1528 if (cursor_vpos >= 0)
1529 {
1530 if (!just_this_one || clip_changed || beg_unchanged < startp)
1531 /* Forget any recorded base line for line number display. */
1532 w->base_line_number = Qnil;
1533 goto done;
1534 }
1535 else
1536 cancel_my_columns (w);
1537 }
1538
1539 XSETFASTINT (w->last_modified, 0);
1540 /* Redisplay the mode line. Select the buffer properly for that. */
1541 if (!update_mode_line)
1542 {
1543 set_buffer_temp (old);
1544 set_buffer_internal (XBUFFER (w->buffer));
1545 update_mode_line = 1;
1546 w->update_mode_line = Qt;
1547 }
1548
1549 /* Try to scroll by specified few lines */
1550
1551 if (scroll_step && !clip_changed)
1552 {
1553 if (PT > startp)
1554 {
1555 pos = *vmotion (Z - XFASTINT (w->window_end_pos),
1556 scroll_step, width, hscroll, window);
1557 if (pos.vpos >= height)
1558 goto scroll_fail;
1559 }
1560
1561 pos = *vmotion (startp, PT < startp ? - scroll_step : scroll_step,
1562 width, hscroll, window);
1563
1564 if (PT >= pos.bufpos)
1565 {
1566 try_window (window, pos.bufpos);
1567 if (cursor_vpos >= 0)
1568 {
1569 if (!just_this_one || clip_changed || beg_unchanged < startp)
1570 /* Forget any recorded base line for line number display. */
1571 w->base_line_number = Qnil;
1572 goto done;
1573 }
1574 else
1575 cancel_my_columns (w);
1576 }
1577 scroll_fail: ;
1578 }
1579
1580 /* Finally, just choose place to start which centers point */
1581
1582 recenter:
1583 /* Forget any previously recorded base line for line number display. */
1584 w->base_line_number = Qnil;
1585
1586 pos = *vmotion (PT, - (height / 2), width, hscroll, window);
1587 try_window (window, pos.bufpos);
1588
1589 startp = marker_position (w->start);
1590 w->start_at_line_beg
1591 = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
1592
1593 done:
1594 if ((update_mode_line
1595 /* If window not full width, must redo its mode line
1596 if the window to its side is being redone */
1597 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
1598 || INTEGERP (w->base_line_pos)
1599 || (!NILP (w->column_number_displayed)
1600 && XFASTINT (w->column_number_displayed) != current_column ()))
1601 && height != XFASTINT (w->height))
1602 display_mode_line (w);
1603 if (! line_number_displayed
1604 && ! BUFFERP (w->base_line_pos))
1605 {
1606 w->base_line_pos = Qnil;
1607 w->base_line_number = Qnil;
1608 }
1609
1610 /* When we reach a frame's selected window, redo the frame's menu bar. */
1611 if (update_mode_line
1612 #ifdef USE_X_TOOLKIT
1613 && FRAME_EXTERNAL_MENU_BAR (f)
1614 #else
1615 && FRAME_MENU_BAR_LINES (f) > 0
1616 #endif
1617 && EQ (FRAME_SELECTED_WINDOW (f), window))
1618 display_menu_bar (w);
1619
1620 finish_scroll_bars:
1621 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
1622 {
1623 int start, end, whole;
1624
1625 /* Calculate the start and end positions for the current window.
1626 At some point, it would be nice to choose between scrollbars
1627 which reflect the whole buffer size, with special markers
1628 indicating narrowing, and scrollbars which reflect only the
1629 visible region.
1630
1631 Note that minibuffers sometimes aren't displaying any text. */
1632 if (! MINI_WINDOW_P (w)
1633 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1634 {
1635 whole = ZV - BEGV;
1636 start = marker_position (w->start) - BEGV;
1637 /* I don't think this is guaranteed to be right. For the
1638 moment, we'll pretend it is. */
1639 end = (Z - XINT (w->window_end_pos)) - BEGV;
1640
1641 if (end < start) end = start;
1642 if (whole < (end - start)) whole = end - start;
1643 }
1644 else
1645 start = end = whole = 0;
1646
1647 /* Indicate what this scroll bar ought to be displaying now. */
1648 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
1649
1650 /* Note that we actually used the scroll bar attached to this window,
1651 so it shouldn't be deleted at the end of redisplay. */
1652 (*redeem_scroll_bar_hook) (w);
1653 }
1654
1655 BUF_PT (current_buffer) = opoint;
1656 if (update_mode_line)
1657 set_buffer_internal (old);
1658 else
1659 set_buffer_temp (old);
1660 BUF_PT (current_buffer) = lpoint;
1661 }
1662 \f
1663 /* Do full redisplay on one window, starting at position `pos'. */
1664
1665 static void
1666 try_window (window, pos)
1667 Lisp_Object window;
1668 register int pos;
1669 {
1670 register struct window *w = XWINDOW (window);
1671 register int height = window_internal_height (w);
1672 register int vpos = XFASTINT (w->top);
1673 register int last_text_vpos = vpos;
1674 int tab_offset = pos_tab_offset (w, pos);
1675 FRAME_PTR f = XFRAME (w->frame);
1676 int width = window_internal_width (w) - 1;
1677 struct position val;
1678
1679 Fset_marker (w->start, make_number (pos), Qnil);
1680 cursor_vpos = -1;
1681 overlay_arrow_seen = 0;
1682 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1683
1684 while (--height >= 0)
1685 {
1686 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1687 tab_offset += width;
1688 /* For the first line displayed, display_text_line
1689 subtracts the prompt width from the tab offset.
1690 But it does not affect the value of our variable tab_offset.
1691 So we do the subtraction again,
1692 for the sake of continuation lines of that first line. */
1693 if (MINI_WINDOW_P (w) && vpos == XFASTINT (w->top))
1694 tab_offset -= minibuf_prompt_width;
1695
1696 if (val.vpos) tab_offset = 0;
1697 vpos++;
1698 if (pos != val.bufpos)
1699 {
1700 int invis = 0;
1701 #ifdef USE_TEXT_PROPERTIES
1702 Lisp_Object invis_prop;
1703 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
1704 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
1705 #endif
1706
1707 last_text_vpos
1708 /* Next line, unless prev line ended in end of buffer with no cr */
1709 = vpos - (val.vpos
1710 && (FETCH_CHAR (val.bufpos - 1) != '\n' || invis));
1711 }
1712 pos = val.bufpos;
1713 }
1714
1715 /* If last line is continued in middle of character,
1716 include the split character in the text considered on the frame */
1717 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1718 pos++;
1719
1720 /* If bottom just moved off end of frame, change mode line percentage. */
1721 if (XFASTINT (w->window_end_pos) == 0
1722 && Z != pos)
1723 w->update_mode_line = Qt;
1724
1725 /* Say where last char on frame will be, once redisplay is finished. */
1726 XSETFASTINT (w->window_end_pos, Z - pos);
1727 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
1728 /* But that is not valid info until redisplay finishes. */
1729 w->window_end_valid = Qnil;
1730 }
1731 \f
1732 /* Try to redisplay when buffer is modified locally,
1733 computing insert/delete line to preserve text outside
1734 the bounds of the changes.
1735 Return 1 if successful, 0 if if cannot tell what to do,
1736 or -1 to tell caller to find a new window start,
1737 or -2 to tell caller to do normal redisplay with same window start. */
1738
1739 static int
1740 try_window_id (window)
1741 Lisp_Object window;
1742 {
1743 int pos;
1744 register struct window *w = XWINDOW (window);
1745 register int height = window_internal_height (w);
1746 FRAME_PTR f = XFRAME (w->frame);
1747 int top = XFASTINT (w->top);
1748 int start = marker_position (w->start);
1749 int width = window_internal_width (w) - 1;
1750 int hscroll = XINT (w->hscroll);
1751 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
1752 register int vpos;
1753 register int i, tem;
1754 int last_text_vpos = 0;
1755 int stop_vpos;
1756 int selective = (INTEGERP (current_buffer->selective_display)
1757 ? XINT (current_buffer->selective_display)
1758 : !NILP (current_buffer->selective_display) ? -1 : 0);
1759
1760 struct position val, bp, ep, xp, pp;
1761 int scroll_amount = 0;
1762 int delta;
1763 int tab_offset, epto;
1764
1765 if (GPT - BEG < beg_unchanged)
1766 beg_unchanged = GPT - BEG;
1767 if (Z - GPT < end_unchanged)
1768 end_unchanged = Z - GPT;
1769
1770 if (beg_unchanged + BEG < start)
1771 return 0; /* Give up if changes go above top of window */
1772
1773 /* Find position before which nothing is changed. */
1774 bp = *compute_motion (start, 0, lmargin,
1775 min (ZV, beg_unchanged + BEG), height, 0,
1776 width, hscroll, pos_tab_offset (w, start), w);
1777 if (bp.vpos >= height)
1778 {
1779 if (PT < bp.bufpos)
1780 {
1781 /* All changes are below the frame, and point is on the frame.
1782 We don't need to change the frame at all.
1783 But we need to update window_end_pos to account for
1784 any change in buffer size. */
1785 bp = *compute_motion (start, 0, lmargin,
1786 Z, height, 0,
1787 width, hscroll, pos_tab_offset (w, start), w);
1788 XSETFASTINT (w->window_end_vpos, height);
1789 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
1790 goto findpoint;
1791 }
1792 return 0;
1793 }
1794
1795 vpos = bp.vpos;
1796
1797 /* Find beginning of that frame line. Must display from there. */
1798 bp = *vmotion (bp.bufpos, 0, width, hscroll, window);
1799
1800 pos = bp.bufpos;
1801 val.hpos = lmargin;
1802 if (pos < start)
1803 return -1;
1804
1805 /* If about to start displaying at the beginning of a continuation line,
1806 really start with previous frame line, in case it was not
1807 continued when last redisplayed */
1808 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
1809 ||
1810 /* Likewise if we have to worry about selective display. */
1811 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
1812 {
1813 bp = *vmotion (bp.bufpos, -1, width, hscroll, window);
1814 --vpos;
1815 pos = bp.bufpos;
1816 }
1817
1818 if (bp.contin && bp.hpos != lmargin)
1819 {
1820 val.hpos = bp.prevhpos - width + lmargin;
1821 pos--;
1822 }
1823
1824 bp.vpos = vpos;
1825
1826 /* Find first visible newline after which no more is changed. */
1827 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
1828 if (selective > 0)
1829 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
1830 tem = find_next_newline (tem, 1);
1831
1832 /* Compute the cursor position after that newline. */
1833 ep = *compute_motion (pos, vpos, val.hpos, tem,
1834 height, - (1 << (SHORTBITS - 1)),
1835 width, hscroll, pos_tab_offset (w, bp.bufpos), w);
1836
1837 /* If changes reach past the text available on the frame,
1838 just display rest of frame. */
1839 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
1840 stop_vpos = height;
1841 else
1842 stop_vpos = ep.vpos;
1843
1844 /* If no newline before ep, the line ep is on includes some changes
1845 that must be displayed. Make sure we don't stop before it. */
1846 /* Also, if changes reach all the way until ep.bufpos,
1847 it is possible that something was deleted after the
1848 newline before it, so the following line must be redrawn. */
1849 if (stop_vpos == ep.vpos
1850 && (ep.bufpos == BEGV
1851 || FETCH_CHAR (ep.bufpos - 1) != '\n'
1852 || ep.bufpos == Z - end_unchanged))
1853 stop_vpos = ep.vpos + 1;
1854
1855 cursor_vpos = -1;
1856 overlay_arrow_seen = 0;
1857
1858 /* If changes do not reach to bottom of window,
1859 figure out how much to scroll the rest of the window */
1860 if (stop_vpos < height)
1861 {
1862 /* Now determine how far up or down the rest of the window has moved */
1863 epto = pos_tab_offset (w, ep.bufpos);
1864 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1865 Z - XFASTINT (w->window_end_pos),
1866 10000, 0, width, hscroll, epto, w);
1867 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
1868
1869 /* Is everything on frame below the changes whitespace?
1870 If so, no scrolling is really necessary. */
1871 for (i = ep.bufpos; i < xp.bufpos; i++)
1872 {
1873 tem = FETCH_CHAR (i);
1874 if (tem != ' ' && tem != '\n' && tem != '\t')
1875 break;
1876 }
1877 if (i == xp.bufpos)
1878 return -2;
1879
1880 XSETFASTINT (w->window_end_vpos,
1881 XFASTINT (w->window_end_vpos) + scroll_amount);
1882
1883 /* Before doing any scrolling, verify that point will be on frame. */
1884 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height))
1885 {
1886 if (PT <= xp.bufpos)
1887 {
1888 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1889 PT, height, - (1 << (SHORTBITS - 1)),
1890 width, hscroll, epto, w);
1891 }
1892 else
1893 {
1894 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos,
1895 PT, height, - (1 << (SHORTBITS - 1)),
1896 width, hscroll,
1897 pos_tab_offset (w, xp.bufpos), w);
1898 }
1899 if (pp.bufpos < PT || pp.vpos == height)
1900 return 0;
1901 cursor_vpos = pp.vpos + top;
1902 cursor_hpos = pp.hpos + XFASTINT (w->left);
1903 }
1904
1905 if (stop_vpos - scroll_amount >= height
1906 || ep.bufpos == xp.bufpos)
1907 {
1908 if (scroll_amount < 0)
1909 stop_vpos -= scroll_amount;
1910 scroll_amount = 0;
1911 /* In this path, we have altered window_end_vpos
1912 and not left it negative.
1913 We must make sure that, in case display is preempted
1914 before the frame changes to reflect what we do here,
1915 further updates will not come to try_window_id
1916 and assume the frame and window_end_vpos match. */
1917 blank_end_of_window = 1;
1918 }
1919 else if (!scroll_amount)
1920 {
1921 /* Even if we don't need to scroll, we must adjust the
1922 charstarts of subsequent lines (that we won't redisplay)
1923 according to the amount of text inserted or deleted. */
1924 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1925 int adjust = ep.bufpos - oldpos;
1926 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
1927 }
1928 else if (bp.bufpos == Z - end_unchanged)
1929 {
1930 /* If reprinting everything is nearly as fast as scrolling,
1931 don't bother scrolling. Can happen if lines are short. */
1932 if (scroll_cost (f, bp.vpos + top - scroll_amount,
1933 top + height - max (0, scroll_amount),
1934 scroll_amount)
1935 > xp.bufpos - bp.bufpos - 20)
1936 /* Return "try normal display with same window-start."
1937 Too bad we can't prevent further scroll-thinking. */
1938 return -2;
1939 /* If pure deletion, scroll up as many lines as possible.
1940 In common case of killing a line, this can save the
1941 following line from being overwritten by scrolling
1942 and therefore having to be redrawn. */
1943 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
1944 top + height - max (0, scroll_amount),
1945 scroll_amount, bp.bufpos);
1946 if (!tem)
1947 stop_vpos = height;
1948 else
1949 {
1950 /* scroll_frame_lines did not properly adjust subsequent
1951 lines' charstarts in the case where the text of the
1952 screen line at bp.vpos has changed.
1953 (This can happen in a deletion that ends in mid-line.)
1954 To adjust properly, we need to make things constent at
1955 the position ep.
1956 So do a second adjust to make that happen.
1957 Note that stop_vpos >= ep.vpos, so it is sufficient
1958 to update the charstarts for lines at ep.vpos and below. */
1959 int oldstart
1960 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1961 adjust_window_charstarts (w, ep.vpos + top - 1,
1962 ep.bufpos - oldstart);
1963 }
1964 }
1965 else if (scroll_amount)
1966 {
1967 /* If reprinting everything is nearly as fast as scrolling,
1968 don't bother scrolling. Can happen if lines are short. */
1969 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1970 overestimate of cost of reprinting, since xp.bufpos
1971 would end up below the bottom of the window. */
1972 if (scroll_cost (f, ep.vpos + top - scroll_amount,
1973 top + height - max (0, scroll_amount),
1974 scroll_amount)
1975 > xp.bufpos - ep.bufpos - 20)
1976 /* Return "try normal display with same window-start."
1977 Too bad we can't prevent further scroll-thinking. */
1978 return -2;
1979 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
1980 top + height - max (0, scroll_amount),
1981 scroll_amount, ep.bufpos);
1982 if (!tem) stop_vpos = height;
1983 }
1984 }
1985
1986 /* In any case, do not display past bottom of window */
1987 if (stop_vpos >= height)
1988 {
1989 stop_vpos = height;
1990 scroll_amount = 0;
1991 }
1992
1993 /* Handle case where pos is before w->start --
1994 can happen if part of line had been clipped and is not clipped now */
1995 if (vpos == 0 && pos < marker_position (w->start))
1996 Fset_marker (w->start, make_number (pos), Qnil);
1997
1998 /* Redisplay the lines where the text was changed */
1999 last_text_vpos = vpos;
2000 tab_offset = pos_tab_offset (w, pos);
2001 /* If we are starting display in mid-character, correct tab_offset
2002 to account for passing the line that that character really starts in. */
2003 if (val.hpos < lmargin)
2004 tab_offset += width;
2005 while (vpos < stop_vpos)
2006 {
2007 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2008 tab_offset += width;
2009 if (val.vpos) tab_offset = 0;
2010 if (pos != val.bufpos)
2011 last_text_vpos
2012 /* Next line, unless prev line ended in end of buffer with no cr */
2013 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
2014 pos = val.bufpos;
2015 }
2016
2017 /* There are two cases:
2018 1) we have displayed down to the bottom of the window
2019 2) we have scrolled lines below stop_vpos by scroll_amount */
2020
2021 if (vpos == height)
2022 {
2023 /* If last line is continued in middle of character,
2024 include the split character in the text considered on the frame */
2025 if (val.hpos < lmargin)
2026 val.bufpos++;
2027 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2028 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2029 }
2030
2031 /* If scrolling made blank lines at window bottom,
2032 redisplay to fill those lines */
2033 if (scroll_amount < 0)
2034 {
2035 /* Don't consider these lines for general-purpose scrolling.
2036 That will save time in the scrolling computation. */
2037 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2038 vpos = xp.vpos;
2039 pos = xp.bufpos;
2040 val.hpos = lmargin;
2041 if (pos == ZV)
2042 vpos = height + scroll_amount;
2043 else if (xp.contin && xp.hpos != lmargin)
2044 {
2045 val.hpos = xp.prevhpos - width + lmargin;
2046 pos--;
2047 }
2048
2049 blank_end_of_window = 1;
2050 tab_offset = pos_tab_offset (w, pos);
2051 /* If we are starting display in mid-character, correct tab_offset
2052 to account for passing the line that that character starts in. */
2053 if (val.hpos < lmargin)
2054 tab_offset += width;
2055
2056 while (vpos < height)
2057 {
2058 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2059 tab_offset += width;
2060 if (val.vpos) tab_offset = 0;
2061 pos = val.bufpos;
2062 }
2063
2064 /* Here is a case where display_text_line sets cursor_vpos wrong.
2065 Make it be fixed up, below. */
2066 if (xp.bufpos == ZV
2067 && xp.bufpos == PT)
2068 cursor_vpos = -1;
2069 }
2070
2071 /* If bottom just moved off end of frame, change mode line percentage. */
2072 if (XFASTINT (w->window_end_pos) == 0
2073 && Z != val.bufpos)
2074 w->update_mode_line = Qt;
2075
2076 /* Attempt to adjust end-of-text positions to new bottom line */
2077 if (scroll_amount)
2078 {
2079 delta = height - xp.vpos;
2080 if (delta < 0
2081 || (delta > 0 && xp.bufpos <= ZV)
2082 || (delta == 0 && xp.hpos))
2083 {
2084 val = *vmotion (Z - XFASTINT (w->window_end_pos),
2085 delta, width, hscroll, window);
2086 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2087 XSETFASTINT (w->window_end_vpos,
2088 XFASTINT (w->window_end_vpos) + val.vpos);
2089 }
2090 }
2091
2092 w->window_end_valid = Qnil;
2093
2094 /* If point was not in a line that was displayed, find it */
2095 if (cursor_vpos < 0)
2096 {
2097 findpoint:
2098 val = *compute_motion (start, 0, lmargin, PT, 10000, 10000,
2099 width, hscroll, pos_tab_offset (w, start), w);
2100 /* Admit failure if point is off frame now */
2101 if (val.vpos >= height)
2102 {
2103 for (vpos = 0; vpos < height; vpos++)
2104 cancel_line (vpos + top, f);
2105 return 0;
2106 }
2107 cursor_vpos = val.vpos + top;
2108 cursor_hpos = val.hpos + XFASTINT (w->left);
2109 }
2110
2111 FRAME_CURSOR_X (f) = max (0, cursor_hpos);
2112 FRAME_CURSOR_Y (f) = cursor_vpos;
2113
2114 if (debug_end_pos)
2115 {
2116 val = *compute_motion (start, 0, lmargin, ZV,
2117 height, - (1 << (SHORTBITS - 1)),
2118 width, hscroll, pos_tab_offset (w, start), w);
2119 if (val.vpos != XFASTINT (w->window_end_vpos))
2120 abort ();
2121 if (XFASTINT (w->window_end_pos)
2122 != Z - val.bufpos)
2123 abort ();
2124 }
2125
2126 return 1;
2127 }
2128 \f
2129 /* Mark a section of BUF as modified, but only for the sake of redisplay.
2130 This is useful for recording changes to overlays.
2131
2132 We increment the buffer's modification timestamp and set the
2133 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
2134 as if the region of text between START and END had been modified;
2135 the redisplay code will check this against the windows' timestamps,
2136 and redraw the appropriate area of the buffer.
2137
2138 However, if the buffer is unmodified, we bump the last-save
2139 timestamp as well, so that incrementing the timestamp doesn't fool
2140 Emacs into thinking that the buffer's text has been modified.
2141
2142 Tweaking the timestamps shouldn't hurt the first-modification
2143 timestamps recorded in the undo records; those values aren't
2144 written until just before a real text modification is made, so they
2145 will never catch the timestamp value just before this function gets
2146 called. */
2147
2148 void
2149 redisplay_region (buf, start, end)
2150 struct buffer *buf;
2151 int start, end;
2152 {
2153 if (start == end)
2154 return;
2155
2156 if (start > end)
2157 {
2158 int temp = start;
2159 start = end; end = temp;
2160 }
2161
2162 /* If this is a buffer not in the selected window,
2163 we must do other windows. */
2164 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2165 windows_or_buffers_changed = 1;
2166 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2167 else if (buf != current_buffer)
2168 windows_or_buffers_changed = 1;
2169 /* If multiple windows show this buffer, we must do other windows. */
2170 else if (buffer_shared > 1)
2171 windows_or_buffers_changed = 1;
2172 else
2173 {
2174 if (unchanged_modified == MODIFF)
2175 {
2176 beg_unchanged = start - BEG;
2177 end_unchanged = Z - end;
2178 }
2179 else
2180 {
2181 if (Z - end < end_unchanged)
2182 end_unchanged = Z - end;
2183 if (start - BEG < beg_unchanged)
2184 beg_unchanged = start - BEG;
2185 }
2186 }
2187
2188 /* Increment the buffer's time stamp, but also increment the save
2189 and autosave timestamps, so as not to screw up that timekeeping. */
2190 if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf))
2191 BUF_SAVE_MODIFF (buf)++;
2192 if (BUF_MODIFF (buf) == buf->auto_save_modified)
2193 buf->auto_save_modified++;
2194
2195 BUF_MODIFF (buf) ++;
2196 }
2197
2198 \f
2199 /* Copy LEN glyphs starting address FROM to the rope TO.
2200 But don't actually copy the parts that would come in before S.
2201 Value is TO, advanced past the copied data.
2202 F is the frame we are displaying in. */
2203
2204 static GLYPH *
2205 copy_part_of_rope (f, to, s, from, len, face)
2206 FRAME_PTR f;
2207 register GLYPH *to; /* Copy to here. */
2208 register GLYPH *s; /* Starting point. */
2209 Lisp_Object *from; /* Data to copy. */
2210 int len;
2211 int face; /* Face to apply to glyphs which don't specify one. */
2212 {
2213 int n = len;
2214 register Lisp_Object *fp = from;
2215 /* These cache the results of the last call to compute_glyph_face. */
2216 int last_code = -1;
2217 int last_merged = 0;
2218
2219 #ifdef HAVE_FACES
2220 if (! FRAME_TERMCAP_P (f))
2221 while (n--)
2222 {
2223 int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2224 int facecode;
2225
2226 if (FAST_GLYPH_FACE (glyph) == 0)
2227 /* If GLYPH has no face code, use FACE. */
2228 facecode = face;
2229 else if (FAST_GLYPH_FACE (glyph) == last_code)
2230 /* If it's same as previous glyph, use same result. */
2231 facecode = last_merged;
2232 else
2233 {
2234 /* Merge this glyph's face and remember the result. */
2235 last_code = FAST_GLYPH_FACE (glyph);
2236 last_merged = facecode = compute_glyph_face (f, last_code, face);
2237 }
2238
2239 if (to >= s)
2240 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
2241 ++to;
2242 ++fp;
2243 }
2244 else
2245 #endif
2246 while (n--)
2247 {
2248 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2249 ++to;
2250 ++fp;
2251 }
2252 return to;
2253 }
2254
2255 /* Correct a glyph by replacing its specified user-level face code
2256 with a displayable computed face code. */
2257
2258 static GLYPH
2259 fix_glyph (f, glyph, cface)
2260 FRAME_PTR f;
2261 GLYPH glyph;
2262 int cface;
2263 {
2264 #ifdef HAVE_FACES
2265 if (! FRAME_TERMCAP_P (f))
2266 {
2267 if (FAST_GLYPH_FACE (glyph) != 0)
2268 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2269 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2270 }
2271 #endif
2272 return glyph;
2273 }
2274 \f
2275 /* Display one line of window W, starting at position START in W's buffer.
2276
2277 Display starting at horizontal position HPOS, expressed relative to
2278 W's left edge. In situations where the text at START shouldn't
2279 start at the left margin (i.e. when the window is hscrolled, or
2280 we're continuing a line which left off in the midst of a
2281 multi-column character), HPOS should be negative; we throw away
2282 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2283 account.
2284
2285 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2286
2287 Display on position VPOS on the frame. It is origin 0, relative to
2288 the top of the frame, not W.
2289
2290 Returns a STRUCT POSITION giving character to start next line with
2291 and where to display it, including a zero or negative hpos.
2292 The vpos field is not really a vpos; it is 1 unless the line is continued */
2293
2294 struct position val_display_text_line;
2295
2296 static struct position *
2297 display_text_line (w, start, vpos, hpos, taboffset)
2298 struct window *w;
2299 int start;
2300 int vpos;
2301 int hpos;
2302 int taboffset;
2303 {
2304 register int pos = start;
2305 register int c;
2306 register GLYPH *p1;
2307 int end;
2308 register int pause;
2309 register unsigned char *p;
2310 GLYPH *endp;
2311 register GLYPH *leftmargin;
2312 register GLYPH *p1prev = 0;
2313 register GLYPH *p1start;
2314 int *charstart;
2315 FRAME_PTR f = XFRAME (w->frame);
2316 int tab_width = XINT (current_buffer->tab_width);
2317 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2318 int width = window_internal_width (w) - 1;
2319 struct position val;
2320 int lastpos;
2321 int invis;
2322 int last_invis_skip = 0;
2323 Lisp_Object last_invis_prop;
2324 int hscroll = XINT (w->hscroll);
2325 int truncate = (hscroll
2326 || (truncate_partial_width_windows
2327 && XFASTINT (w->width) < FRAME_WIDTH (f))
2328 || !NILP (current_buffer->truncate_lines));
2329
2330 /* 1 if we should highlight the region. */
2331 int highlight_region
2332 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
2333 int region_beg, region_end;
2334
2335 int selective = (INTEGERP (current_buffer->selective_display)
2336 ? XINT (current_buffer->selective_display)
2337 : !NILP (current_buffer->selective_display) ? -1 : 0);
2338 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2339 register struct Lisp_Vector *dp = window_display_table (w);
2340
2341 Lisp_Object default_invis_vector[3];
2342 /* Number of characters of ellipsis to display after an invisible line
2343 if it calls for an ellipsis.
2344 Note that this value can be nonzero regardless of whether
2345 selective display is enabled--you must check that separately. */
2346 int selective_rlen
2347 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2348 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2349 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
2350 /* This is the sequence of Lisp objects to display
2351 when there are invisible lines. */
2352 Lisp_Object *invis_vector_contents
2353 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2354 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2355 : default_invis_vector);
2356
2357 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2358 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2359 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2360 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2361
2362 /* The next buffer location at which the face should change, due
2363 to overlays or text property changes. */
2364 int next_face_change;
2365
2366 #ifdef USE_TEXT_PROPERTIES
2367 /* The next location where the `invisible' property changes */
2368 int next_invisible;
2369 #endif
2370
2371 /* The face we're currently using. */
2372 int current_face = 0;
2373 int i;
2374
2375 XSETFASTINT (default_invis_vector[2], '.');
2376 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2377
2378 hpos += XFASTINT (w->left);
2379 get_display_line (f, vpos, XFASTINT (w->left));
2380 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2381
2382 /* Show where to highlight the region. */
2383 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2384 /* Maybe highlight only in selected window. */
2385 && (highlight_nonselected_windows
2386 || w == XWINDOW (selected_window)))
2387 {
2388 region_beg = marker_position (current_buffer->mark);
2389 if (PT < region_beg)
2390 {
2391 region_end = region_beg;
2392 region_beg = PT;
2393 }
2394 else
2395 region_end = PT;
2396 w->region_showing = Qt;
2397 }
2398 else
2399 region_beg = region_end = -1;
2400
2401 if (MINI_WINDOW_P (w)
2402 && start == 1
2403 && vpos == XFASTINT (w->top))
2404 {
2405 if (! NILP (minibuf_prompt))
2406 {
2407 minibuf_prompt_width
2408 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2409 XSTRING (minibuf_prompt)->size, hpos,
2410 /* Display a space if we truncate. */
2411 ' ',
2412 1, -1,
2413 /* Truncate the prompt a little before the
2414 margin, so user input can at least start
2415 on the first line. */
2416 w->width > 10 ? w->width - 4 : -1)
2417 - hpos);
2418 hpos += minibuf_prompt_width;
2419 taboffset -= minibuf_prompt_width;
2420 }
2421 else
2422 minibuf_prompt_width = 0;
2423 }
2424
2425 end = ZV;
2426
2427 /* If we're hscrolled at all, use compute_motion to skip over any
2428 text off the left edge of the window. compute_motion may know
2429 tricks to do this faster than we can. */
2430 if (hpos < 0)
2431 {
2432 struct position *left_edge
2433 = compute_motion (pos, vpos, hpos,
2434 end, vpos, 0,
2435 width, hscroll, taboffset, w);
2436
2437 /* Retrieve the buffer position and column provided by
2438 compute_motion. We can't assume that the column will be
2439 zero, because you may have multi-column characters crossing
2440 the left margin.
2441
2442 compute_motion may have moved us past the screen position we
2443 requested, if we hit a multi-column character, or the end of
2444 the line. If so, back up. */
2445 if (left_edge->vpos > vpos
2446 || left_edge->hpos > 0)
2447 {
2448 pos = left_edge->bufpos - 1;
2449 hpos = left_edge->prevhpos;
2450 }
2451 else
2452 {
2453 pos = left_edge->bufpos;
2454 hpos = left_edge->hpos;
2455 }
2456 }
2457
2458 desired_glyphs->bufp[vpos] = start;
2459 p1 = desired_glyphs->glyphs[vpos] + hpos;
2460 p1start = p1;
2461 charstart = desired_glyphs->charstarts[vpos] + hpos;
2462 /* In case we don't ever write anything into it... */
2463 desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1;
2464 leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2465 endp = leftmargin + width;
2466
2467 /* Arrange the overlays nicely for our purposes. Usually, we call
2468 display_text_line on only one line at a time, in which case this
2469 can't really hurt too much, or we call it on lines which appear
2470 one after another in the buffer, in which case all calls to
2471 recenter_overlay_lists but the first will be pretty cheap. */
2472 recenter_overlay_lists (current_buffer, pos);
2473
2474 /* Loop generating characters.
2475 Stop at end of buffer, before newline,
2476 if reach or pass continuation column,
2477 or at face change. */
2478 pause = pos;
2479 next_face_change = pos;
2480 #ifdef USE_TEXT_PROPERTIES
2481 next_invisible = pos;
2482 #endif
2483 while (1)
2484 {
2485 /* Record which glyph starts a character,
2486 and the character position of that character. */
2487 if (p1 >= leftmargin)
2488 charstart[p1 - p1start] = pos;
2489
2490 if (p1 >= endp)
2491 break;
2492
2493 p1prev = p1;
2494 if (pos >= pause)
2495 {
2496 /* Did we hit the end of the visible region of the buffer?
2497 Stop here. */
2498 if (pos >= end)
2499 break;
2500
2501 /* Did we reach point? Record the cursor location. */
2502 if (pos == PT && cursor_vpos < 0)
2503 {
2504 cursor_vpos = vpos;
2505 cursor_hpos = p1 - leftmargin;
2506 }
2507
2508 #ifdef USE_TEXT_PROPERTIES
2509 /* if the `invisible' property is set to t, we can skip to
2510 the next property change */
2511 while (pos == next_invisible && pos < end)
2512 {
2513 Lisp_Object position, limit, endpos, prop, ww;
2514 XSETFASTINT (position, pos);
2515 XSETWINDOW (ww, w);
2516 prop = Fget_char_property (position, Qinvisible, ww);
2517 /* This is just an estimate to give reasonable
2518 performance; nothing should go wrong if it is too small. */
2519 limit = Fnext_overlay_change (position);
2520 if (XFASTINT (limit) > pos + 50)
2521 XSETFASTINT (limit, pos + 50);
2522 endpos = Fnext_single_property_change (position, Qinvisible,
2523 Fcurrent_buffer (),
2524 limit);
2525 if (INTEGERP (endpos))
2526 next_invisible = XINT (endpos);
2527 else
2528 next_invisible = end;
2529 if (TEXT_PROP_MEANS_INVISIBLE (prop))
2530 {
2531 if (pos < PT && next_invisible >= PT)
2532 {
2533 cursor_vpos = vpos;
2534 cursor_hpos = p1 - leftmargin;
2535 }
2536 pos = next_invisible;
2537 last_invis_skip = pos;
2538 last_invis_prop = prop;
2539 }
2540 }
2541 if (pos >= end)
2542 break;
2543 #endif
2544
2545 #ifdef HAVE_FACES
2546 /* Did we hit a face change? Figure out what face we should
2547 use now. We also hit this the first time through the
2548 loop, to see what face we should start with. */
2549 if (pos >= next_face_change && FRAME_X_P (f))
2550 current_face = compute_char_face (f, w, pos,
2551 region_beg, region_end,
2552 &next_face_change, pos + 50, 0);
2553 #endif
2554
2555 pause = end;
2556
2557 #ifdef USE_TEXT_PROPERTIES
2558 if (pos < next_invisible && next_invisible < pause)
2559 pause = next_invisible;
2560 #endif
2561 if (pos < next_face_change && next_face_change < pause)
2562 pause = next_face_change;
2563
2564 /* Wouldn't you hate to read the next line to someone over
2565 the phone? */
2566 if (pos < PT && PT < pause)
2567 pause = PT;
2568 if (pos < GPT && GPT < pause)
2569 pause = GPT;
2570
2571 p = &FETCH_CHAR (pos);
2572 }
2573 c = *p++;
2574 /* Let a display table override all standard display methods. */
2575 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
2576 {
2577 p1 = copy_part_of_rope (f, p1, leftmargin,
2578 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2579 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2580 current_face);
2581 }
2582 else if (c >= 040 && c < 0177)
2583 {
2584 if (p1 >= leftmargin)
2585 *p1 = MAKE_GLYPH (f, c, current_face);
2586 p1++;
2587 }
2588 else if (c == '\n')
2589 {
2590 invis = 0;
2591 if (last_invis_skip == pos
2592 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
2593 invis = 1;
2594 while (pos + 1 < end
2595 && selective > 0
2596 && indented_beyond_p (pos + 1, selective))
2597 {
2598 invis = 1;
2599 pos = find_next_newline (pos + 1, 1);
2600 if (FETCH_CHAR (pos - 1) == '\n')
2601 pos--;
2602 }
2603 if (invis && selective_rlen > 0 && p1 >= leftmargin)
2604 {
2605 p1 += selective_rlen;
2606 if (p1 - leftmargin > width)
2607 p1 = endp;
2608 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2609 (p1 - p1prev), current_face);
2610 }
2611 #ifdef HAVE_FACES
2612 /* Draw the face of the newline character as extending all the
2613 way to the end of the frame line. */
2614 if (current_face)
2615 {
2616 if (p1 < leftmargin)
2617 p1 = leftmargin;
2618 while (p1 < endp)
2619 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2620 }
2621 #endif
2622 break;
2623 }
2624 else if (c == '\t')
2625 {
2626 do
2627 {
2628 if (p1 >= leftmargin && p1 < endp)
2629 *p1 = MAKE_GLYPH (f, ' ', current_face);
2630 p1++;
2631 }
2632 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
2633 % tab_width);
2634 }
2635 else if (c == Ctl ('M') && selective == -1)
2636 {
2637 pos = find_next_newline (pos, 1);
2638 if (FETCH_CHAR (pos - 1) == '\n')
2639 pos--;
2640 if (selective_rlen > 0)
2641 {
2642 p1 += selective_rlen;
2643 if (p1 - leftmargin > width)
2644 p1 = endp;
2645 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2646 (p1 - p1prev), current_face);
2647 }
2648 #ifdef HAVE_FACES
2649 /* Draw the face of the newline character as extending all the
2650 way to the end of the frame line. */
2651 if (current_face)
2652 {
2653 if (p1 < leftmargin)
2654 p1 = leftmargin;
2655 while (p1 < endp)
2656 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2657 }
2658 #endif
2659 break;
2660 }
2661 else if (c < 0200 && ctl_arrow)
2662 {
2663 if (p1 >= leftmargin)
2664 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
2665 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
2666 current_face);
2667 p1++;
2668 if (p1 >= leftmargin && p1 < endp)
2669 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
2670 p1++;
2671 }
2672 else
2673 {
2674 if (p1 >= leftmargin)
2675 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
2676 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
2677 current_face);
2678 p1++;
2679 if (p1 >= leftmargin && p1 < endp)
2680 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
2681 p1++;
2682 if (p1 >= leftmargin && p1 < endp)
2683 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
2684 p1++;
2685 if (p1 >= leftmargin && p1 < endp)
2686 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
2687 p1++;
2688 }
2689
2690 /* Do nothing here for a char that's entirely off the left edge. */
2691 if (p1 >= leftmargin)
2692 {
2693 /* For all the glyphs occupied by this character, except for the
2694 first, store -1 in charstarts. */
2695 if (p1 != p1prev)
2696 {
2697 int *p2x = &charstart[p1prev - p1start];
2698 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2699
2700 /* The window's left column should always
2701 contain a character position.
2702 And don't clobber anything to the left of that. */
2703 if (p1prev < leftmargin)
2704 {
2705 p2x = charstart + (leftmargin - p1start);
2706 *p2x = pos;
2707 }
2708
2709 /* This loop skips over the char p2x initially points to. */
2710 while (++p2x < p2)
2711 *p2x = -1;
2712 }
2713 }
2714
2715 pos++;
2716 }
2717
2718 val.hpos = - XINT (w->hscroll);
2719 if (val.hpos)
2720 val.hpos++;
2721
2722 val.vpos = 1;
2723
2724 lastpos = pos;
2725
2726 /* Store 0 in this charstart line for the positions where
2727 there is no character. But do leave what was recorded
2728 for the character that ended the line. */
2729 /* Add 1 in the endtest to compensate for the fact that ENDP was
2730 made from WIDTH, which is 1 less than the window's actual
2731 internal width. */
2732 i = p1 - p1start + 1;
2733 if (p1 < leftmargin)
2734 i += leftmargin - p1;
2735 for (; i < endp - p1start + 1; i++)
2736 charstart[i] = 0;
2737
2738 /* Handle continuation in middle of a character */
2739 /* by backing up over it */
2740 if (p1 > endp)
2741 {
2742 /* Don't back up if we never actually displayed any text.
2743 This occurs when the minibuffer prompt takes up the whole line. */
2744 if (p1prev)
2745 {
2746 /* Start the next line with that same character */
2747 pos--;
2748 /* but at negative hpos, to skip the columns output on this line. */
2749 val.hpos += p1prev - endp;
2750 }
2751
2752 /* Keep in this line everything up to the continuation column. */
2753 p1 = endp;
2754 }
2755
2756 /* Finish deciding which character to start the next line on,
2757 and what hpos to start it at.
2758 Also set `lastpos' to the last position which counts as "on this line"
2759 for cursor-positioning. */
2760
2761 if (pos < ZV)
2762 {
2763 if (FETCH_CHAR (pos) == '\n')
2764 {
2765 /* If stopped due to a newline, start next line after it */
2766 pos++;
2767 /* Check again for hidden lines, in case the newline occurred exactly
2768 at the right margin. */
2769 while (pos < ZV && selective > 0
2770 && indented_beyond_p (pos, selective))
2771 pos = find_next_newline (pos, 1);
2772 }
2773 else
2774 /* Stopped due to right margin of window */
2775 {
2776 if (truncate)
2777 {
2778 *p1++ = fix_glyph (f, truncator, 0);
2779 /* Truncating => start next line after next newline,
2780 and point is on this line if it is before the newline,
2781 and skip none of first char of next line */
2782 do
2783 pos = find_next_newline (pos, 1);
2784 while (pos < ZV && selective > 0
2785 && indented_beyond_p (pos, selective));
2786 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2787
2788 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
2789 }
2790 else
2791 {
2792 *p1++ = fix_glyph (f, continuer, 0);
2793 val.vpos = 0;
2794 lastpos--;
2795 }
2796 }
2797 }
2798
2799 /* If point is at eol or in invisible text at eol,
2800 record its frame location now. */
2801
2802 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
2803 {
2804 cursor_vpos = vpos;
2805 cursor_hpos = p1 - leftmargin;
2806 }
2807
2808 if (cursor_vpos == vpos)
2809 {
2810 if (cursor_hpos < 0) cursor_hpos = 0;
2811 if (cursor_hpos > width) cursor_hpos = width;
2812 cursor_hpos += XFASTINT (w->left);
2813 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
2814 {
2815 FRAME_CURSOR_Y (f) = cursor_vpos;
2816 FRAME_CURSOR_X (f) = cursor_hpos;
2817
2818 if (w == XWINDOW (selected_window))
2819 {
2820 /* Line is not continued and did not start
2821 in middle of character */
2822 if ((hpos - XFASTINT (w->left)
2823 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2824 && val.vpos)
2825 {
2826 this_line_bufpos = start;
2827 this_line_buffer = current_buffer;
2828 this_line_vpos = cursor_vpos;
2829 this_line_start_hpos = hpos;
2830 this_line_endpos = Z - lastpos;
2831 }
2832 else
2833 this_line_bufpos = 0;
2834 }
2835 }
2836 }
2837
2838 /* If hscroll and line not empty, insert truncation-at-left marker */
2839 if (hscroll && lastpos != start)
2840 {
2841 *leftmargin = fix_glyph (f, truncator, 0);
2842 if (p1 <= leftmargin)
2843 p1 = leftmargin + 1;
2844 }
2845
2846 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
2847 {
2848 endp++;
2849 if (p1 < leftmargin) p1 = leftmargin;
2850 while (p1 < endp) *p1++ = SPACEGLYPH;
2851
2852 /* Don't draw vertical bars if we're using scroll bars. They're
2853 covered up by the scroll bars, and it's distracting to see
2854 them when the scroll bar windows are flickering around to be
2855 reconfigured. */
2856 *p1++ = (FRAME_HAS_VERTICAL_SCROLL_BARS (f)
2857 ? ' '
2858 : (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
2859 ? DISP_BORDER_GLYPH (dp)
2860 : '|'));
2861 }
2862 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
2863 p1 - desired_glyphs->glyphs[vpos]);
2864 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
2865
2866 /* If the start of this line is the overlay arrow-position,
2867 then put the arrow string into the display-line. */
2868
2869 if (MARKERP (Voverlay_arrow_position)
2870 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
2871 && start == marker_position (Voverlay_arrow_position)
2872 && STRINGP (Voverlay_arrow_string)
2873 && ! overlay_arrow_seen)
2874 {
2875 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
2876 int i;
2877 int len = XSTRING (Voverlay_arrow_string)->size;
2878 int arrow_end;
2879
2880 if (len > width)
2881 len = width;
2882 #ifdef HAVE_FACES
2883 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
2884 {
2885 /* If the arrow string has text props, obey them when displaying. */
2886 for (i = 0; i < len; i++)
2887 {
2888 int c = p[i];
2889 Lisp_Object face, ilisp;
2890 int newface;
2891
2892 XSETFASTINT (ilisp, i);
2893 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
2894 newface = compute_glyph_face_1 (f, face, 0);
2895 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
2896 }
2897 }
2898 else
2899 #endif /* HAVE_FACES */
2900 {
2901 for (i = 0; i < len; i++)
2902 leftmargin[i] = p[i];
2903 }
2904
2905 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
2906 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
2907 if (desired_glyphs->used[vpos] < arrow_end)
2908 desired_glyphs->used[vpos] = arrow_end;
2909
2910 overlay_arrow_seen = 1;
2911 }
2912
2913 val.bufpos = pos;
2914 val_display_text_line = val;
2915 return &val_display_text_line;
2916 }
2917 \f
2918 /* Redisplay the menu bar in the frame for window W. */
2919
2920 static void
2921 display_menu_bar (w)
2922 struct window *w;
2923 {
2924 Lisp_Object items, tail;
2925 register int vpos = 0;
2926 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2927 int maxendcol = FRAME_WIDTH (f);
2928 int hpos = 0;
2929 int i;
2930
2931 #ifndef USE_X_TOOLKIT
2932 if (FRAME_MENU_BAR_LINES (f) <= 0)
2933 return;
2934
2935 get_display_line (f, vpos, 0);
2936
2937 items = FRAME_MENU_BAR_ITEMS (f);
2938 for (i = 0; i < XVECTOR (items)->size; i += 3)
2939 {
2940 Lisp_Object pos, string;
2941 string = XVECTOR (items)->contents[i + 1];
2942 if (NILP (string))
2943 break;
2944
2945 XSETFASTINT (XVECTOR (items)->contents[i + 2], hpos);
2946
2947 if (hpos < maxendcol)
2948 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
2949 XSTRING (string)->data,
2950 XSTRING (string)->size,
2951 hpos, 0, 0, hpos, maxendcol);
2952 /* Put a space between items. */
2953 if (hpos < maxendcol)
2954 {
2955 int hpos1 = hpos + 1;
2956 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
2957 min (hpos1, maxendcol), maxendcol);
2958 }
2959 }
2960
2961 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
2962 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
2963
2964 /* Fill out the line with spaces. */
2965 if (maxendcol > hpos)
2966 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
2967
2968 /* Clear the rest of the lines allocated to the menu bar. */
2969 vpos++;
2970 while (vpos < FRAME_MENU_BAR_LINES (f))
2971 get_display_line (f, vpos++, 0);
2972 #endif /* not USE_X_TOOLKIT */
2973 }
2974 \f
2975 /* Display the mode line for window w */
2976
2977 static void
2978 display_mode_line (w)
2979 struct window *w;
2980 {
2981 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
2982 register int left = XFASTINT (w->left);
2983 register int right = XFASTINT (w->width) + left;
2984 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2985
2986 line_number_displayed = 0;
2987 w->column_number_displayed = Qnil;
2988
2989 get_display_line (f, vpos, left);
2990 #ifdef MULTI_KBOARD
2991 {
2992 /* Sigh, mode-line-format can reference kboard-local variables like
2993 defining-kbd-macro. Use the one associated with the frame we're
2994 updating. */
2995 KBOARD *orig_kboard = current_kboard;
2996 current_kboard = FRAME_KBOARD (f);
2997 #endif
2998 display_mode_element (w, vpos, left, 0, right, right,
2999 current_buffer->mode_line_format);
3000 #ifdef MULTI_KBOARD
3001 current_kboard = orig_kboard;
3002 }
3003 #endif
3004 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3005
3006 /* Make the mode line inverse video if the entire line
3007 is made of mode lines.
3008 I.e. if this window is full width,
3009 or if it is the child of a full width window
3010 (which implies that that window is split side-by-side
3011 and the rest of this line is mode lines of the sibling windows). */
3012 if (XFASTINT (w->width) == FRAME_WIDTH (f)
3013 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
3014 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3015 #ifdef HAVE_FACES
3016 else if (! FRAME_TERMCAP_P (f))
3017 {
3018 /* For a partial width window, explicitly set face of each glyph. */
3019 int i;
3020 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3021 for (i = left; i < right; ++i)
3022 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
3023 }
3024 #endif
3025 }
3026
3027 /* Contribute ELT to the mode line for window W.
3028 How it translates into text depends on its data type.
3029
3030 VPOS is the position of the mode line being displayed.
3031
3032 HPOS is the position (absolute on frame) where this element's text
3033 should start. The output is truncated automatically at the right
3034 edge of window W.
3035
3036 DEPTH is the depth in recursion. It is used to prevent
3037 infinite recursion here.
3038
3039 MINENDCOL is the hpos before which the element may not end.
3040 The element is padded at the right with spaces if nec
3041 to reach this column.
3042
3043 MAXENDCOL is the hpos past which this element may not extend.
3044 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3045 (This is necessary to make nested padding and truncation work.)
3046
3047 Returns the hpos of the end of the text generated by ELT.
3048 The next element will receive that value as its HPOS arg,
3049 so as to concatenate the elements. */
3050
3051 static int
3052 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3053 struct window *w;
3054 register int vpos, hpos;
3055 int depth;
3056 int minendcol;
3057 register int maxendcol;
3058 register Lisp_Object elt;
3059 {
3060 tail_recurse:
3061 if (depth > 10)
3062 goto invalid;
3063
3064 depth++;
3065
3066 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3067 {
3068 case Lisp_String:
3069 {
3070 /* A string: output it and check for %-constructs within it. */
3071 register unsigned char c;
3072 register unsigned char *this = XSTRING (elt)->data;
3073
3074 while (hpos < maxendcol && *this)
3075 {
3076 unsigned char *last = this;
3077 while ((c = *this++) != '\0' && c != '%')
3078 ;
3079 if (this - 1 != last)
3080 {
3081 register int lim = --this - last + hpos;
3082 if (frame_title_ptr)
3083 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3084 else
3085 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3086 hpos, min (lim, maxendcol));
3087 }
3088 else /* c == '%' */
3089 {
3090 register int spec_width = 0;
3091
3092 /* We can't allow -ve args due to the "%-" construct */
3093 /* Argument specifies minwidth but not maxwidth
3094 (maxwidth can be specified by
3095 (<negative-number> . <stuff>) mode-line elements) */
3096
3097 while ((c = *this++) >= '0' && c <= '9')
3098 {
3099 spec_width = spec_width * 10 + (c - '0');
3100 }
3101
3102 spec_width += hpos;
3103 if (spec_width > maxendcol)
3104 spec_width = maxendcol;
3105
3106 if (c == 'M')
3107 hpos = display_mode_element (w, vpos, hpos, depth,
3108 spec_width, maxendcol,
3109 Vglobal_mode_string);
3110 else if (c != 0)
3111 {
3112 char *spec = decode_mode_spec (w, c, maxendcol - hpos);
3113 if (frame_title_ptr)
3114 hpos = store_frame_title (spec, spec_width, maxendcol);
3115 else
3116 hpos = display_string (w, vpos, spec, -1,
3117 hpos, 0, 1,
3118 spec_width, maxendcol);
3119 }
3120 }
3121 }
3122 }
3123 break;
3124
3125 case Lisp_Symbol:
3126 /* A symbol: process the value of the symbol recursively
3127 as if it appeared here directly. Avoid error if symbol void.
3128 Special case: if value of symbol is a string, output the string
3129 literally. */
3130 {
3131 register Lisp_Object tem;
3132 tem = Fboundp (elt);
3133 if (!NILP (tem))
3134 {
3135 tem = Fsymbol_value (elt);
3136 /* If value is a string, output that string literally:
3137 don't check for % within it. */
3138 if (STRINGP (tem))
3139 {
3140 if (frame_title_ptr)
3141 hpos = store_frame_title (XSTRING (tem)->data,
3142 minendcol, maxendcol);
3143 else
3144 hpos = display_string (w, vpos, XSTRING (tem)->data,
3145 XSTRING (tem)->size,
3146 hpos, 0, 1, minendcol, maxendcol);
3147 }
3148 /* Give up right away for nil or t. */
3149 else if (!EQ (tem, elt))
3150 { elt = tem; goto tail_recurse; }
3151 }
3152 }
3153 break;
3154
3155 case Lisp_Cons:
3156 {
3157 register Lisp_Object car, tem;
3158
3159 /* A cons cell: three distinct cases.
3160 If first element is a string or a cons, process all the elements
3161 and effectively concatenate them.
3162 If first element is a negative number, truncate displaying cdr to
3163 at most that many characters. If positive, pad (with spaces)
3164 to at least that many characters.
3165 If first element is a symbol, process the cadr or caddr recursively
3166 according to whether the symbol's value is non-nil or nil. */
3167 car = XCONS (elt)->car;
3168 if (SYMBOLP (car))
3169 {
3170 tem = Fboundp (car);
3171 elt = XCONS (elt)->cdr;
3172 if (!CONSP (elt))
3173 goto invalid;
3174 /* elt is now the cdr, and we know it is a cons cell.
3175 Use its car if CAR has a non-nil value. */
3176 if (!NILP (tem))
3177 {
3178 tem = Fsymbol_value (car);
3179 if (!NILP (tem))
3180 { elt = XCONS (elt)->car; goto tail_recurse; }
3181 }
3182 /* Symbol's value is nil (or symbol is unbound)
3183 Get the cddr of the original list
3184 and if possible find the caddr and use that. */
3185 elt = XCONS (elt)->cdr;
3186 if (NILP (elt))
3187 break;
3188 else if (!CONSP (elt))
3189 goto invalid;
3190 elt = XCONS (elt)->car;
3191 goto tail_recurse;
3192 }
3193 else if (INTEGERP (car))
3194 {
3195 register int lim = XINT (car);
3196 elt = XCONS (elt)->cdr;
3197 if (lim < 0)
3198 /* Negative int means reduce maximum width.
3199 DO NOT change MINENDCOL here!
3200 (20 -10 . foo) should truncate foo to 10 col
3201 and then pad to 20. */
3202 maxendcol = min (maxendcol, hpos - lim);
3203 else if (lim > 0)
3204 {
3205 /* Padding specified. Don't let it be more than
3206 current maximum. */
3207 lim += hpos;
3208 if (lim > maxendcol)
3209 lim = maxendcol;
3210 /* If that's more padding than already wanted, queue it.
3211 But don't reduce padding already specified even if
3212 that is beyond the current truncation point. */
3213 if (lim > minendcol)
3214 minendcol = lim;
3215 }
3216 goto tail_recurse;
3217 }
3218 else if (STRINGP (car) || CONSP (car))
3219 {
3220 register int limit = 50;
3221 /* LIMIT is to protect against circular lists. */
3222 while (CONSP (elt) && --limit > 0
3223 && hpos < maxendcol)
3224 {
3225 hpos = display_mode_element (w, vpos, hpos, depth,
3226 hpos, maxendcol,
3227 XCONS (elt)->car);
3228 elt = XCONS (elt)->cdr;
3229 }
3230 }
3231 }
3232 break;
3233
3234 default:
3235 invalid:
3236 if (frame_title_ptr)
3237 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3238 else
3239 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3240 minendcol, maxendcol);
3241 return hpos;
3242 }
3243
3244 if (minendcol > hpos)
3245 if (frame_title_ptr)
3246 hpos = store_frame_title ("", minendcol, maxendcol);
3247 else
3248 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
3249 return hpos;
3250 }
3251 \f
3252 /* Return a string for the output of a mode line %-spec for window W,
3253 generated by character C and width MAXWIDTH. */
3254
3255 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3256
3257 static char *
3258 decode_mode_spec (w, c, maxwidth)
3259 struct window *w;
3260 register char c;
3261 register int maxwidth;
3262 {
3263 Lisp_Object obj;
3264 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3265 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
3266 struct buffer *b = XBUFFER (w->buffer);
3267
3268 obj = Qnil;
3269 if (maxwidth > FRAME_WIDTH (f))
3270 maxwidth = FRAME_WIDTH (f);
3271
3272 switch (c)
3273 {
3274 case 'b':
3275 obj = b->name;
3276 #if 0
3277 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
3278 {
3279 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
3280 decode_mode_spec_buf[maxwidth - 1] = '\\';
3281 decode_mode_spec_buf[maxwidth] = '\0';
3282 return decode_mode_spec_buf;
3283 }
3284 #endif
3285 break;
3286
3287 case 'f':
3288 obj = b->filename;
3289 #if 0
3290 if (NILP (obj))
3291 return "[none]";
3292 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
3293 {
3294 bcopy ("...", decode_mode_spec_buf, 3);
3295 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
3296 decode_mode_spec_buf + 3, maxwidth - 3);
3297 return decode_mode_spec_buf;
3298 }
3299 #endif
3300 break;
3301
3302 case 'c':
3303 {
3304 int col = current_column ();
3305 XSETFASTINT (w->column_number_displayed, col);
3306 sprintf (decode_mode_spec_buf, "%d", col);
3307 return decode_mode_spec_buf;
3308 }
3309
3310 case 'l':
3311 {
3312 int startpos = marker_position (w->start);
3313 int line, linepos, topline;
3314 int nlines, junk;
3315 Lisp_Object tem;
3316 int height = XFASTINT (w->height);
3317
3318 /* If we decided that this buffer isn't suitable for line numbers,
3319 don't forget that too fast. */
3320 if (EQ (w->base_line_pos, w->buffer))
3321 return "??";
3322
3323 /* If the buffer is very big, don't waste time. */
3324 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
3325 {
3326 w->base_line_pos = Qnil;
3327 w->base_line_number = Qnil;
3328 return "??";
3329 }
3330
3331 if (!NILP (w->base_line_number)
3332 && !NILP (w->base_line_pos)
3333 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
3334 {
3335 line = XFASTINT (w->base_line_number);
3336 linepos = XFASTINT (w->base_line_pos);
3337 }
3338 else
3339 {
3340 line = 1;
3341 linepos = BUF_BEGV (b);
3342 }
3343
3344 /* Count lines from base line to window start position. */
3345 nlines = display_count_lines (linepos, startpos, startpos, &junk);
3346
3347 topline = nlines + line;
3348
3349 /* Determine a new base line, if the old one is too close
3350 or too far away, or if we did not have one.
3351 "Too close" means it's plausible a scroll-down would
3352 go back past it. */
3353 if (startpos == BUF_BEGV (b))
3354 {
3355 XSETFASTINT (w->base_line_number, topline);
3356 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
3357 }
3358 else if (nlines < height + 25 || nlines > height * 3 + 50
3359 || linepos == BUF_BEGV (b))
3360 {
3361 int limit = BUF_BEGV (b);
3362 int position;
3363 int distance = (height * 2 + 30) * 200;
3364
3365 if (startpos - distance > limit)
3366 limit = startpos - distance;
3367
3368 nlines = display_count_lines (startpos, limit,
3369 -(height * 2 + 30),
3370 &position);
3371 /* If we couldn't find the lines we wanted within
3372 200 chars per line,
3373 give up on line numbers for this window. */
3374 if (position == startpos - distance)
3375 {
3376 w->base_line_pos = w->buffer;
3377 w->base_line_number = Qnil;
3378 return "??";
3379 }
3380
3381 XSETFASTINT (w->base_line_number, topline - nlines);
3382 XSETFASTINT (w->base_line_pos, position);
3383 }
3384
3385 /* Now count lines from the start pos to point. */
3386 nlines = display_count_lines (startpos, PT, PT, &junk);
3387
3388 /* Record that we did display the line number. */
3389 line_number_displayed = 1;
3390
3391 /* Make the string to show. */
3392 sprintf (decode_mode_spec_buf, "%d", topline + nlines);
3393 return decode_mode_spec_buf;
3394 }
3395 break;
3396
3397 case 'm':
3398 obj = b->mode_name;
3399 break;
3400
3401 case 'n':
3402 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
3403 return " Narrow";
3404 break;
3405
3406 case '*':
3407 if (!NILP (b->read_only))
3408 return "%";
3409 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3410 return "*";
3411 return "-";
3412
3413 case '+':
3414 /* This differs from %* only for a modified read-only buffer. */
3415 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3416 return "*";
3417 if (!NILP (b->read_only))
3418 return "%";
3419 return "-";
3420
3421 case '&':
3422 /* This differs from %* in ignoring read-only-ness. */
3423 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3424 return "*";
3425 return "-";
3426
3427 case 's':
3428 /* status of process */
3429 obj = Fget_buffer_process (w->buffer);
3430 if (NILP (obj))
3431 return "no process";
3432 #ifdef subprocesses
3433 obj = Fsymbol_name (Fprocess_status (obj));
3434 #endif
3435 break;
3436
3437 case 't': /* indicate TEXT or BINARY */
3438 #ifdef MODE_LINE_BINARY_TEXT
3439 return MODE_LINE_BINARY_TEXT (b);
3440 #else
3441 return "T";
3442 #endif
3443
3444 case 'p':
3445 {
3446 int pos = marker_position (w->start);
3447 int total = BUF_ZV (b) - BUF_BEGV (b);
3448
3449 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
3450 {
3451 if (pos <= BUF_BEGV (b))
3452 return "All";
3453 else
3454 return "Bottom";
3455 }
3456 else if (pos <= BUF_BEGV (b))
3457 return "Top";
3458 else
3459 {
3460 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
3461 /* We can't normally display a 3-digit number,
3462 so get us a 2-digit number that is close. */
3463 if (total == 100)
3464 total = 99;
3465 sprintf (decode_mode_spec_buf, "%2d%%", total);
3466 return decode_mode_spec_buf;
3467 }
3468 }
3469
3470 /* Display percentage of size above the bottom of the screen. */
3471 case 'P':
3472 {
3473 int toppos = marker_position (w->start);
3474 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
3475 int total = BUF_ZV (b) - BUF_BEGV (b);
3476
3477 if (botpos >= BUF_ZV (b))
3478 {
3479 if (toppos <= BUF_BEGV (b))
3480 return "All";
3481 else
3482 return "Bottom";
3483 }
3484 else
3485 {
3486 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
3487 /* We can't normally display a 3-digit number,
3488 so get us a 2-digit number that is close. */
3489 if (total == 100)
3490 total = 99;
3491 if (toppos <= BUF_BEGV (b))
3492 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
3493 else
3494 sprintf (decode_mode_spec_buf, "%2d%%", total);
3495 return decode_mode_spec_buf;
3496 }
3497 }
3498
3499 case '%':
3500 return "%";
3501
3502 case '[':
3503 {
3504 int i;
3505 char *p;
3506
3507 if (command_loop_level > 5)
3508 return "[[[... ";
3509 p = decode_mode_spec_buf;
3510 for (i = 0; i < command_loop_level; i++)
3511 *p++ = '[';
3512 *p = 0;
3513 return decode_mode_spec_buf;
3514 }
3515
3516 case ']':
3517 {
3518 int i;
3519 char *p;
3520
3521 if (command_loop_level > 5)
3522 return " ...]]]";
3523 p = decode_mode_spec_buf;
3524 for (i = 0; i < command_loop_level; i++)
3525 *p++ = ']';
3526 *p = 0;
3527 return decode_mode_spec_buf;
3528 }
3529
3530 case '-':
3531 {
3532 register char *p;
3533 register int i;
3534
3535 if (maxwidth < sizeof (lots_of_dashes))
3536 return lots_of_dashes;
3537 else
3538 {
3539 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3540 *p++ = '-';
3541 *p = '\0';
3542 }
3543 return decode_mode_spec_buf;
3544 }
3545 }
3546
3547 if (STRINGP (obj))
3548 return (char *) XSTRING (obj)->data;
3549 else
3550 return "";
3551 }
3552 \f
3553 /* Search for COUNT instances of a line boundary, which means either a
3554 newline or (if selective display enabled) a carriage return.
3555 Start at START. If COUNT is negative, search backwards.
3556
3557 If we find COUNT instances, set *SHORTAGE to zero, and return the
3558 position after the COUNTth match. Note that for reverse motion
3559 this is not the same as the usual convention for Emacs motion commands.
3560
3561 If we don't find COUNT instances before reaching the end of the
3562 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3563 the number of line boundaries left unfound, and return the end of the
3564 buffer we bumped up against. */
3565
3566 static int
3567 display_scan_buffer (start, count, shortage)
3568 int *shortage, start;
3569 register int count;
3570 {
3571 int limit = ((count > 0) ? ZV - 1 : BEGV);
3572 int direction = ((count > 0) ? 1 : -1);
3573
3574 register unsigned char *cursor;
3575 unsigned char *base;
3576
3577 register int ceiling;
3578 register unsigned char *ceiling_addr;
3579
3580 /* If we are not in selective display mode,
3581 check only for newlines. */
3582 if (! (!NILP (current_buffer->selective_display)
3583 && !INTEGERP (current_buffer->selective_display)))
3584 return scan_buffer ('\n', start, 0, count, shortage, 0);
3585
3586 /* The code that follows is like scan_buffer
3587 but checks for either newline or carriage return. */
3588
3589 if (shortage != 0)
3590 *shortage = 0;
3591
3592 if (count > 0)
3593 while (start != limit + 1)
3594 {
3595 ceiling = BUFFER_CEILING_OF (start);
3596 ceiling = min (limit, ceiling);
3597 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
3598 base = (cursor = &FETCH_CHAR (start));
3599 while (1)
3600 {
3601 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
3602 ;
3603 if (cursor != ceiling_addr)
3604 {
3605 if (--count == 0)
3606 {
3607 immediate_quit = 0;
3608 return (start + cursor - base + 1);
3609 }
3610 else
3611 if (++cursor == ceiling_addr)
3612 break;
3613 }
3614 else
3615 break;
3616 }
3617 start += cursor - base;
3618 }
3619 else
3620 {
3621 start--; /* first character we scan */
3622 while (start > limit - 1)
3623 { /* we WILL scan under start */
3624 ceiling = BUFFER_FLOOR_OF (start);
3625 ceiling = max (limit, ceiling);
3626 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
3627 base = (cursor = &FETCH_CHAR (start));
3628 cursor++;
3629 while (1)
3630 {
3631 while (--cursor != ceiling_addr
3632 && *cursor != '\n' && *cursor != 015)
3633 ;
3634 if (cursor != ceiling_addr)
3635 {
3636 if (++count == 0)
3637 {
3638 immediate_quit = 0;
3639 return (start + cursor - base + 1);
3640 }
3641 }
3642 else
3643 break;
3644 }
3645 start += cursor - base;
3646 }
3647 }
3648
3649 if (shortage != 0)
3650 *shortage = count * direction;
3651 return (start + ((direction == 1 ? 0 : 1)));
3652 }
3653
3654 /* Count up to N lines starting from FROM.
3655 But don't go beyond LIMIT.
3656 Return the number of lines thus found (always positive).
3657 Store the position after what was found into *POS_PTR. */
3658
3659 static int
3660 display_count_lines (from, limit, n, pos_ptr)
3661 int from, limit, n;
3662 int *pos_ptr;
3663 {
3664 int oldbegv = BEGV;
3665 int oldzv = ZV;
3666 int shortage = 0;
3667
3668 if (limit < from)
3669 BEGV = limit;
3670 else
3671 ZV = limit;
3672
3673 *pos_ptr = display_scan_buffer (from, n, &shortage);
3674
3675 ZV = oldzv;
3676 BEGV = oldbegv;
3677
3678 if (n < 0)
3679 /* When scanning backwards, scan_buffer stops *after* the last newline
3680 it finds, but does count it. Compensate for that. */
3681 return - n - shortage - (*pos_ptr != limit);
3682 return n - shortage;
3683 }
3684 \f
3685 /* Display STRING on one line of window W, starting at HPOS.
3686 Display at position VPOS. Caller should have done get_display_line.
3687 If VPOS == -1, display it as the current frame's title.
3688 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
3689
3690 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
3691
3692 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
3693 MAXCOL is the last column ok to end at. Truncate here.
3694 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
3695 Both count from the left edge of the frame, as does HPOS.
3696 The right edge of W is an implicit maximum.
3697 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
3698
3699 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
3700 at the place where the current window ends in this line
3701 and not display anything beyond there. Otherwise, only MAXCOL
3702 controls where to stop output.
3703
3704 Returns ending hpos. */
3705
3706 static int
3707 display_string (w, vpos, string, length, hpos, truncate,
3708 obey_window_width, mincol, maxcol)
3709 struct window *w;
3710 unsigned char *string;
3711 int length;
3712 int vpos, hpos;
3713 GLYPH truncate;
3714 int obey_window_width;
3715 int mincol, maxcol;
3716 {
3717 register int c;
3718 register GLYPH *p1;
3719 int hscroll = XINT (w->hscroll);
3720 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
3721 register GLYPH *start;
3722 register GLYPH *end;
3723 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3724 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
3725 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
3726 int window_width = XFASTINT (w->width);
3727
3728 /* Use the standard display table, not the window's display table.
3729 We don't want the mode line in rot13. */
3730 register struct Lisp_Vector *dp = 0;
3731 int i;
3732
3733 if (VECTORP (Vstandard_display_table)
3734 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
3735 dp = XVECTOR (Vstandard_display_table);
3736
3737 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
3738
3739 p1 = p1start;
3740 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
3741
3742 if (obey_window_width)
3743 {
3744 end = start + window_width - (truncate != 0);
3745
3746 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
3747 {
3748 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3749 {
3750 int i;
3751
3752 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3753 *end-- = ' ';
3754 }
3755 else
3756 *end-- = '|';
3757 }
3758 }
3759
3760 if (! obey_window_width
3761 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
3762 end = desired_glyphs->glyphs[vpos] + maxcol;
3763
3764 /* Store 0 in charstart for these columns. */
3765 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
3766 desired_glyphs->charstarts[vpos][i] = 0;
3767
3768 if (maxcol >= 0 && mincol > maxcol)
3769 mincol = maxcol;
3770
3771 while (p1 < end)
3772 {
3773 if (length == 0)
3774 break;
3775 c = *string++;
3776 /* Specified length. */
3777 if (length >= 0)
3778 length--;
3779 /* Unspecified length (null-terminated string). */
3780 else if (c == 0)
3781 break;
3782
3783 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3784 {
3785 p1 = copy_part_of_rope (f, p1, start,
3786 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3787 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3788 0);
3789 }
3790 else if (c >= 040 && c < 0177)
3791 {
3792 if (p1 >= start)
3793 *p1 = c;
3794 p1++;
3795 }
3796 else if (c == '\t')
3797 {
3798 do
3799 {
3800 if (p1 >= start && p1 < end)
3801 *p1 = SPACEGLYPH;
3802 p1++;
3803 }
3804 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
3805 }
3806 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
3807 {
3808 if (p1 >= start)
3809 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
3810 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3811 0);
3812 p1++;
3813 if (p1 >= start && p1 < end)
3814 *p1 = c ^ 0100;
3815 p1++;
3816 }
3817 else
3818 {
3819 if (p1 >= start)
3820 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
3821 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3822 0);
3823 p1++;
3824 if (p1 >= start && p1 < end)
3825 *p1 = (c >> 6) + '0';
3826 p1++;
3827 if (p1 >= start && p1 < end)
3828 *p1 = (7 & (c >> 3)) + '0';
3829 p1++;
3830 if (p1 >= start && p1 < end)
3831 *p1 = (7 & c) + '0';
3832 p1++;
3833 }
3834 }
3835
3836 if (c && length > 0)
3837 {
3838 p1 = end;
3839 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
3840 }
3841 else if (mincol >= 0)
3842 {
3843 end = desired_glyphs->glyphs[vpos] + mincol;
3844 while (p1 < end)
3845 *p1++ = SPACEGLYPH;
3846 }
3847
3848 {
3849 register int len = p1 - desired_glyphs->glyphs[vpos];
3850
3851 if (len > desired_glyphs->used[vpos])
3852 desired_glyphs->used[vpos] = len;
3853 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3854
3855 return len;
3856 }
3857 }
3858 \f
3859 /* This is like a combination of memq and assq.
3860 Return 1 if PROPVAL appears as an element of LIST
3861 or as the car of an element of LIST.
3862 If PROPVAL is a list, compare each element against LIST
3863 in that way, and return 1 if any element of PROPVAL is found in LIST.
3864 Otherwise return 0.
3865 This function cannot quit. */
3866
3867 int
3868 invisible_p (propval, list)
3869 register Lisp_Object propval;
3870 Lisp_Object list;
3871 {
3872 register Lisp_Object tail, proptail;
3873 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3874 {
3875 register Lisp_Object tem;
3876 tem = XCONS (tail)->car;
3877 if (EQ (propval, tem))
3878 return 1;
3879 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
3880 return 1;
3881 }
3882 if (CONSP (propval))
3883 for (proptail = propval; CONSP (proptail);
3884 proptail = XCONS (proptail)->cdr)
3885 {
3886 Lisp_Object propelt;
3887 propelt = XCONS (proptail)->car;
3888 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3889 {
3890 register Lisp_Object tem;
3891 tem = XCONS (tail)->car;
3892 if (EQ (propelt, tem))
3893 return 1;
3894 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
3895 return 1;
3896 }
3897 }
3898 return 0;
3899 }
3900
3901 /* Return 1 if PROPVAL appears as the car of an element of LIST
3902 and the cdr of that element is non-nil.
3903 If PROPVAL is a list, check each element of PROPVAL in that way,
3904 and the first time some element is found,
3905 return 1 if the cdr of that element is non-nil.
3906 Otherwise return 0.
3907 This function cannot quit. */
3908
3909 int
3910 invisible_ellipsis_p (propval, list)
3911 register Lisp_Object propval;
3912 Lisp_Object list;
3913 {
3914 register Lisp_Object tail, proptail;
3915 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3916 {
3917 register Lisp_Object tem;
3918 tem = XCONS (tail)->car;
3919 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
3920 return ! NILP (XCONS (tem)->cdr);
3921 }
3922 if (CONSP (propval))
3923 for (proptail = propval; CONSP (proptail);
3924 proptail = XCONS (proptail)->cdr)
3925 {
3926 Lisp_Object propelt;
3927 propelt = XCONS (proptail)->car;
3928 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3929 {
3930 register Lisp_Object tem;
3931 tem = XCONS (tail)->car;
3932 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
3933 return ! NILP (XCONS (tem)->cdr);
3934 }
3935 }
3936 return 0;
3937 }
3938 \f
3939 void
3940 syms_of_xdisp ()
3941 {
3942 staticpro (&Qmenu_bar_update_hook);
3943 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
3944
3945 staticpro (&last_arrow_position);
3946 staticpro (&last_arrow_string);
3947 last_arrow_position = Qnil;
3948 last_arrow_string = Qnil;
3949
3950 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
3951 "String (or mode line construct) included (normally) in `mode-line-format'.");
3952 Vglobal_mode_string = Qnil;
3953
3954 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
3955 "Marker for where to display an arrow on top of the buffer text.\n\
3956 This must be the beginning of a line in order to work.\n\
3957 See also `overlay-arrow-string'.");
3958 Voverlay_arrow_position = Qnil;
3959
3960 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
3961 "String to display as an arrow. See also `overlay-arrow-position'.");
3962 Voverlay_arrow_string = Qnil;
3963
3964 DEFVAR_INT ("scroll-step", &scroll_step,
3965 "*The number of lines to try scrolling a window by when point moves out.\n\
3966 If that fails to bring point back on frame, point is centered instead.\n\
3967 If this is zero, point is always centered after it moves off frame.");
3968
3969 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
3970
3971 DEFVAR_BOOL ("truncate-partial-width-windows",
3972 &truncate_partial_width_windows,
3973 "*Non-nil means truncate lines in all windows less than full frame wide.");
3974 truncate_partial_width_windows = 1;
3975
3976 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
3977 "*Non-nil means use inverse video for the mode line.");
3978 mode_line_inverse_video = 1;
3979
3980 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
3981 "*Maximum buffer size for which line number should be displayed.");
3982 line_number_display_limit = 1000000;
3983
3984 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
3985 "*Non-nil means highlight region even in nonselected windows.");
3986 highlight_nonselected_windows = 1;
3987
3988 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
3989 "Non-nil means more than one frame is in use, not counting minibuffer frames.\n\
3990 Not guaranteed to be accurate except while parsing frame-title-format.");
3991
3992 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
3993 "Template for displaying the titlebar of visible frames.\n\
3994 \(Assuming the window manager supports this feature.)\n\
3995 This variable has the same structure as `mode-line-format' (which see),\n\
3996 and is used only on frames for which no explicit name has been set\n\
3997 \(see `modify-frame-parameters').");
3998 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
3999 "Template for displaying the titlebar of an iconified frame.\n\
4000 \(Assuming the window manager supports this feature.)\n\
4001 This variable has the same structure as `mode-line-format' (which see),\n\
4002 and is used only on frames for which no explicit name has been set\n\
4003 \(see `modify-frame-parameters').");
4004 Vicon_title_format
4005 = Vframe_title_format
4006 = Fcons (intern ("multiple-frames"),
4007 Fcons (build_string ("%b"),
4008 Fcons (Fcons (build_string (""),
4009 Fcons (intern ("invocation-name"),
4010 Fcons (build_string ("@"),
4011 Fcons (intern ("system-name"),
4012 Qnil)))),
4013 Qnil)));
4014
4015 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
4016 "Maximum number of lines to keep in the message log buffer.\n\
4017 If nil, disable message logging. If t, log messages but don't truncate\n\
4018 the buffer when it becomes large.");
4019 XSETFASTINT (Vmessage_log_max, 50);
4020
4021 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
4022 "Functions called before redisplay, if window sizes have changed.\n\
4023 The value should be a list of functions that take one argument.\n\
4024 Just before redisplay, for each frame, if any of its windows have changed\n\
4025 size since the last redisplay, or have been split or deleted,\n\
4026 all the functions in the list are called, with the frame as argument.");
4027 Vwindow_size_change_functions = Qnil;
4028 }
4029
4030 /* initialize the window system */
4031 init_xdisp ()
4032 {
4033 Lisp_Object root_window;
4034 #ifndef COMPILER_REGISTER_BUG
4035 register
4036 #endif /* COMPILER_REGISTER_BUG */
4037 struct window *mini_w;
4038
4039 this_line_bufpos = 0;
4040
4041 mini_w = XWINDOW (minibuf_window);
4042 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
4043
4044 echo_area_glyphs = 0;
4045 previous_echo_glyphs = 0;
4046
4047 if (!noninteractive)
4048 {
4049 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
4050 XSETFASTINT (XWINDOW (root_window)->top, 0);
4051 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
4052 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
4053 set_window_height (minibuf_window, 1, 0);
4054
4055 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
4056 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));
4057 }
4058 }