]> code.delx.au - gnu-emacs/blob - src/xdisp.c
(make-comint): Error, if start-process is not fboundp.
[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
1015 if ((! FRAME_TERMCAP_P (f) || f == selected_frame)
1016 && FRAME_VISIBLE_P (f))
1017 {
1018 pause |= update_frame (f, 0, 0);
1019 if (!pause)
1020 {
1021 mark_window_display_accurate (f->root_window, 1);
1022 if (frame_up_to_date_hook != 0)
1023 (*frame_up_to_date_hook) (f);
1024 }
1025 }
1026 }
1027 }
1028 else
1029 #endif /* MULTI_FRAME */
1030 {
1031 if (FRAME_VISIBLE_P (selected_frame))
1032 pause = update_frame (selected_frame, 0, 0);
1033 else
1034 pause = 0;
1035
1036 /* We may have called echo_area_display at the top of this
1037 function. If the echo area is on another frame, that may
1038 have put text on a frame other than the selected one, so the
1039 above call to update_frame would not have caught it. Catch
1040 it here. */
1041 {
1042 FRAME_PTR mini_frame
1043 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
1044
1045 if (mini_frame != selected_frame)
1046 pause |= update_frame (mini_frame, 0, 0);
1047 }
1048 }
1049
1050 /* If frame does not match, prevent doing single-line-update next time.
1051 Also, don't forget to check every line to update the arrow. */
1052 if (pause)
1053 {
1054 this_line_bufpos = 0;
1055 if (!NILP (last_arrow_position))
1056 {
1057 last_arrow_position = Qt;
1058 last_arrow_string = Qt;
1059 }
1060 /* If we pause after scrolling, some lines in current_frame
1061 may be null, so preserve_other_columns won't be able to
1062 preserve all the vertical-bar separators. So, avoid using it
1063 in that case. */
1064 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
1065 update_mode_lines = 1;
1066 }
1067
1068 /* Now text on frame agrees with windows, so
1069 put info into the windows for partial redisplay to follow */
1070
1071 if (!pause)
1072 {
1073 register struct buffer *b = XBUFFER (w->buffer);
1074
1075 blank_end_of_window = 0;
1076 clip_changed = 0;
1077 unchanged_modified = BUF_MODIFF (b);
1078 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1079 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1080
1081 XSETFASTINT (w->last_point, BUF_PT (b));
1082 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1083 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1084
1085 if (all_windows)
1086 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1087 else
1088 {
1089 w->update_mode_line = Qnil;
1090 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1091 w->window_end_valid = w->buffer;
1092 last_arrow_position = Voverlay_arrow_position;
1093 last_arrow_string = Voverlay_arrow_string;
1094 if (do_verify_charstarts)
1095 verify_charstarts (w);
1096 if (frame_up_to_date_hook != 0)
1097 (*frame_up_to_date_hook) (selected_frame);
1098 }
1099 update_mode_lines = 0;
1100 windows_or_buffers_changed = 0;
1101 }
1102
1103 /* Start SIGIO interrupts coming again.
1104 Having them off during the code above
1105 makes it less likely one will discard output,
1106 but not impossible, since there might be stuff
1107 in the system buffer here.
1108 But it is much hairier to try to do anything about that. */
1109
1110 if (interrupt_input)
1111 request_sigio ();
1112 start_polling ();
1113
1114 /* Change frame size now if a change is pending. */
1115 do_pending_window_change ();
1116
1117 /* If we just did a pending size change, redisplay again
1118 for the new size. */
1119 if (windows_or_buffers_changed && !pause)
1120 redisplay ();
1121 }
1122
1123 /* Redisplay, but leave alone any recent echo area message
1124 unless another message has been requested in its place.
1125
1126 This is useful in situations where you need to redisplay but no
1127 user action has occurred, making it inappropriate for the message
1128 area to be cleared. See tracking_off and
1129 wait_reading_process_input for examples of these situations. */
1130
1131 redisplay_preserve_echo_area ()
1132 {
1133 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1134 {
1135 echo_area_glyphs = previous_echo_glyphs;
1136 redisplay ();
1137 echo_area_glyphs = 0;
1138 }
1139 else
1140 redisplay ();
1141 }
1142
1143 void
1144 mark_window_display_accurate (window, flag)
1145 Lisp_Object window;
1146 int flag;
1147 {
1148 register struct window *w;
1149
1150 for (;!NILP (window); window = w->next)
1151 {
1152 if (!WINDOWP (window)) abort ();
1153 w = XWINDOW (window);
1154
1155 if (!NILP (w->buffer))
1156 {
1157 XSETFASTINT (w->last_modified,
1158 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1159
1160 /* Record if we are showing a region, so can make sure to
1161 update it fully at next redisplay. */
1162 w->region_showing = (!NILP (Vtransient_mark_mode)
1163 && !NILP (XBUFFER (w->buffer)->mark_active)
1164 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1165 : Qnil);
1166 }
1167
1168 w->window_end_valid = w->buffer;
1169 w->update_mode_line = Qnil;
1170
1171 if (!NILP (w->vchild))
1172 mark_window_display_accurate (w->vchild, flag);
1173 if (!NILP (w->hchild))
1174 mark_window_display_accurate (w->hchild, flag);
1175 }
1176
1177 if (flag)
1178 {
1179 last_arrow_position = Voverlay_arrow_position;
1180 last_arrow_string = Voverlay_arrow_string;
1181 }
1182 else
1183 {
1184 /* t is unequal to any useful value of Voverlay_arrow_... */
1185 last_arrow_position = Qt;
1186 last_arrow_string = Qt;
1187 }
1188 }
1189 \f
1190 /* Update the menu bar item list for frame F.
1191 This has to be done before we start to fill in any display lines,
1192 because it can call eval. */
1193
1194 static void
1195 update_menu_bar (f)
1196 FRAME_PTR f;
1197 {
1198 struct buffer *old = current_buffer;
1199 Lisp_Object window;
1200 register struct window *w;
1201 window = FRAME_SELECTED_WINDOW (f);
1202 w = XWINDOW (window);
1203
1204 if (update_mode_lines)
1205 w->update_mode_line = Qt;
1206
1207 if (
1208 #ifdef USE_X_TOOLKIT
1209 FRAME_EXTERNAL_MENU_BAR (f)
1210 #else
1211 FRAME_MENU_BAR_LINES (f) > 0
1212 #endif
1213 )
1214 {
1215 /* If the user has switched buffers or windows, we need to
1216 recompute to reflect the new bindings. But we'll
1217 recompute when update_mode_lines is set too; that means
1218 that people can use force-mode-line-update to request
1219 that the menu bar be recomputed. The adverse effect on
1220 the rest of the redisplay algorithm is about the same as
1221 windows_or_buffers_changed anyway. */
1222 if (windows_or_buffers_changed
1223 || !NILP (w->update_mode_line)
1224 || (XFASTINT (w->last_modified) < MODIFF
1225 && (XFASTINT (w->last_modified)
1226 <= BUF_SAVE_MODIFF (XBUFFER (w->buffer)))))
1227 {
1228 struct buffer *prev = current_buffer;
1229 call1 (Vrun_hooks, Qmenu_bar_update_hook);
1230 current_buffer = XBUFFER (w->buffer);
1231 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1232 current_buffer = prev;
1233 #ifdef USE_X_TOOLKIT
1234 set_frame_menubar (f, 0);
1235 #endif /* USE_X_TOOLKIT */
1236 }
1237 }
1238 }
1239 \f
1240 int do_id = 1;
1241
1242 /* Redisplay WINDOW and its subwindows and siblings. */
1243
1244 static void
1245 redisplay_windows (window)
1246 Lisp_Object window;
1247 {
1248 for (; !NILP (window); window = XWINDOW (window)->next)
1249 redisplay_window (window, 0);
1250 }
1251
1252 /* Redisplay window WINDOW and its subwindows. */
1253
1254 static void
1255 redisplay_window (window, just_this_one)
1256 Lisp_Object window;
1257 int just_this_one;
1258 {
1259 register struct window *w = XWINDOW (window);
1260 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1261 int height;
1262 register int lpoint = PT;
1263 struct buffer *old = current_buffer;
1264 register int width = window_internal_width (w) - 1;
1265 register int startp;
1266 register int hscroll = XINT (w->hscroll);
1267 struct position pos;
1268 int opoint = PT;
1269 int tem;
1270 int update_mode_line;
1271
1272 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1273
1274 /* If this is a combination window, do its children; that's all. */
1275
1276 if (!NILP (w->vchild))
1277 {
1278 redisplay_windows (w->vchild);
1279 return;
1280 }
1281 if (!NILP (w->hchild))
1282 {
1283 redisplay_windows (w->hchild);
1284 return;
1285 }
1286 if (NILP (w->buffer))
1287 abort ();
1288
1289 height = window_internal_height (w);
1290 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1291
1292 if (MINI_WINDOW_P (w))
1293 {
1294 if (w == XWINDOW (minibuf_window))
1295 {
1296 if (echo_area_glyphs)
1297 /* We've already displayed the echo area glyphs, if any. */
1298 goto finish_scroll_bars;
1299 }
1300 else
1301 {
1302 /* This is a minibuffer, but it's not the currently active one, so
1303 clear it. */
1304 int vpos = XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top);
1305 int i;
1306
1307 for (i = 0; i < height; i++)
1308 {
1309 get_display_line (f, vpos + i, 0);
1310 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
1311 }
1312
1313 goto finish_scroll_bars;
1314 }
1315 }
1316
1317 /* Otherwise set up data on this window; select its buffer and point value */
1318
1319 if (update_mode_line)
1320 set_buffer_internal (XBUFFER (w->buffer));
1321 else
1322 set_buffer_temp (XBUFFER (w->buffer));
1323
1324 opoint = PT;
1325
1326 /* Count number of windows showing the selected buffer.
1327 An indirect buffer counts as its base buffer. */
1328
1329 if (!just_this_one)
1330 {
1331 struct buffer *current_base, *window_base;
1332 current_base = current_buffer;
1333 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1334 if (current_base->base_buffer)
1335 current_base = current_base->base_buffer;
1336 if (window_base->base_buffer)
1337 window_base = window_base->base_buffer;
1338 if (current_base == window_base)
1339 buffer_shared++;
1340 }
1341
1342 /* POINT refers normally to the selected window.
1343 For any other window, set up appropriate value. */
1344
1345 if (!EQ (window, selected_window))
1346 {
1347 int new_pt = marker_position (w->pointm);
1348 if (new_pt < BEGV)
1349 {
1350 new_pt = BEGV;
1351 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1352 }
1353 else if (new_pt > (ZV - 1))
1354 {
1355 new_pt = ZV;
1356 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1357 }
1358 /* We don't use SET_PT so that the point-motion hooks don't run. */
1359 BUF_PT (current_buffer) = new_pt;
1360 }
1361
1362 /* If any of the character widths specified in the display table
1363 have changed, invalidate the width run cache. It's true that this
1364 may be a bit late to catch such changes, but the rest of
1365 redisplay goes (non-fatally) haywire when the display table is
1366 changed, so why should we worry about doing any better? */
1367 if (current_buffer->width_run_cache)
1368 {
1369 struct Lisp_Vector *disptab = buffer_display_table ();
1370
1371 if (! disptab_matches_widthtab (disptab,
1372 XVECTOR (current_buffer->width_table)))
1373 {
1374 invalidate_region_cache (current_buffer,
1375 current_buffer->width_run_cache,
1376 BEG, Z);
1377 recompute_width_table (current_buffer, disptab);
1378 }
1379 }
1380
1381 /* If window-start is screwed up, choose a new one. */
1382 if (XMARKER (w->start)->buffer != current_buffer)
1383 goto recenter;
1384
1385 startp = marker_position (w->start);
1386
1387 /* Handle case where place to start displaying has been specified,
1388 unless the specified location is outside the accessible range. */
1389 if (!NILP (w->force_start))
1390 {
1391 /* Forget any recorded base line for line number display. */
1392 w->base_line_number = Qnil;
1393 /* Redisplay the mode line. Select the buffer properly for that. */
1394 if (!update_mode_line)
1395 {
1396 set_buffer_temp (old);
1397 set_buffer_internal (XBUFFER (w->buffer));
1398 update_mode_line = 1;
1399 w->update_mode_line = Qt;
1400 }
1401 w->force_start = Qnil;
1402 XSETFASTINT (w->last_modified, 0);
1403 if (startp < BEGV) startp = BEGV;
1404 if (startp > ZV) startp = ZV;
1405 try_window (window, startp);
1406 if (cursor_vpos < 0)
1407 {
1408 /* If point does not appear, move point so it does appear */
1409 pos = *compute_motion (startp, 0,
1410 ((EQ (window, minibuf_window) && startp == 1)
1411 ? minibuf_prompt_width : 0)
1412 +
1413 (hscroll ? 1 - hscroll : 0),
1414 ZV, height / 2,
1415 - (1 << (SHORTBITS - 1)),
1416 width, hscroll, pos_tab_offset (w, startp), w);
1417 BUF_PT (current_buffer) = pos.bufpos;
1418 if (w != XWINDOW (selected_window))
1419 Fset_marker (w->pointm, make_number (PT), Qnil);
1420 else
1421 {
1422 if (current_buffer == old)
1423 lpoint = PT;
1424 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1425 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1426 }
1427 /* If we are highlighting the region,
1428 then we just changed the region, so redisplay to show it. */
1429 if (!NILP (Vtransient_mark_mode)
1430 && !NILP (current_buffer->mark_active))
1431 {
1432 cancel_my_columns (XWINDOW (window));
1433 try_window (window, startp);
1434 }
1435 }
1436 goto done;
1437 }
1438
1439 /* Handle case where text has not changed, only point,
1440 and it has not moved off the frame */
1441
1442 /* This code is not used for minibuffer for the sake of
1443 the case of redisplaying to replace an echo area message;
1444 since in that case the minibuffer contents per se are usually unchanged.
1445 This code is of no real use in the minibuffer since
1446 the handling of this_line_bufpos, etc.,
1447 in redisplay handles the same cases. */
1448
1449 if (XFASTINT (w->last_modified) >= MODIFF
1450 && PT >= startp && !clip_changed
1451 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
1452 /* If force-mode-line-update was called, really redisplay;
1453 that's how redisplay is forced after e.g. changing
1454 buffer-invisibility-spec. */
1455 && NILP (w->update_mode_line)
1456 /* Can't use this case if highlighting a region. */
1457 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1458 && NILP (w->region_showing)
1459 /* If end pos is out of date, scroll bar and percentage will be wrong */
1460 && INTEGERP (w->window_end_vpos)
1461 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1462 && !EQ (window, minibuf_window))
1463 {
1464 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0),
1465 PT, height, 0, width, hscroll,
1466 pos_tab_offset (w, startp), w);
1467
1468 if (pos.vpos < height)
1469 {
1470 /* Ok, point is still on frame */
1471 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1472 {
1473 /* These variables are supposed to be origin 1 */
1474 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1475 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1476 }
1477 /* This doesn't do the trick, because if a window to the right of
1478 this one must be redisplayed, this does nothing because there
1479 is nothing in DesiredFrame yet, and then the other window is
1480 redisplayed, making likes that are empty in this window's columns.
1481 if (XFASTINT (w->width) != FRAME_WIDTH (f))
1482 preserve_my_columns (w);
1483 */
1484 goto done;
1485 }
1486 /* Don't bother trying redisplay with same start;
1487 we already know it will lose */
1488 }
1489 /* If current starting point was originally the beginning of a line
1490 but no longer is, find a new starting point. */
1491 else if (!NILP (w->start_at_line_beg)
1492 && !(startp <= BEGV
1493 || FETCH_CHAR (startp - 1) == '\n'))
1494 {
1495 goto recenter;
1496 }
1497 else if (just_this_one && !MINI_WINDOW_P (w)
1498 && PT >= startp
1499 && XFASTINT (w->last_modified)
1500 /* or else vmotion on first line won't work. */
1501 && ! NILP (w->start_at_line_beg)
1502 && ! EQ (w->window_end_valid, Qnil)
1503 && do_id && !clip_changed
1504 && !blank_end_of_window
1505 && XFASTINT (w->width) == FRAME_WIDTH (f)
1506 /* Can't use this case if highlighting a region. */
1507 && !(!NILP (Vtransient_mark_mode)
1508 && !NILP (current_buffer->mark_active))
1509 && NILP (w->region_showing)
1510 && EQ (last_arrow_position, Voverlay_arrow_position)
1511 && EQ (last_arrow_string, Voverlay_arrow_string)
1512 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1513 && tem != -2)
1514 {
1515 /* tem > 0 means success. tem == -1 means choose new start.
1516 tem == -2 means try again with same start,
1517 and nothing but whitespace follows the changed stuff.
1518 tem == 0 means try again with same start. */
1519 if (tem > 0)
1520 goto done;
1521 }
1522 else if (startp >= BEGV && startp <= ZV
1523 /* Avoid starting display at end of buffer! */
1524 && (startp < ZV || startp == BEGV
1525 || (XFASTINT (w->last_modified) >= MODIFF)))
1526 {
1527 /* Try to redisplay starting at same place as before */
1528 /* If point has not moved off frame, accept the results */
1529 try_window (window, startp);
1530 if (cursor_vpos >= 0)
1531 {
1532 if (!just_this_one || clip_changed || beg_unchanged < startp)
1533 /* Forget any recorded base line for line number display. */
1534 w->base_line_number = Qnil;
1535 goto done;
1536 }
1537 else
1538 cancel_my_columns (w);
1539 }
1540
1541 XSETFASTINT (w->last_modified, 0);
1542 /* Redisplay the mode line. Select the buffer properly for that. */
1543 if (!update_mode_line)
1544 {
1545 set_buffer_temp (old);
1546 set_buffer_internal (XBUFFER (w->buffer));
1547 update_mode_line = 1;
1548 w->update_mode_line = Qt;
1549 }
1550
1551 /* Try to scroll by specified few lines */
1552
1553 if (scroll_step && !clip_changed)
1554 {
1555 if (PT > startp)
1556 {
1557 pos = *vmotion (Z - XFASTINT (w->window_end_pos),
1558 scroll_step, width, hscroll, window);
1559 if (pos.vpos >= height)
1560 goto scroll_fail;
1561 }
1562
1563 pos = *vmotion (startp, PT < startp ? - scroll_step : scroll_step,
1564 width, hscroll, window);
1565
1566 if (PT >= pos.bufpos)
1567 {
1568 try_window (window, pos.bufpos);
1569 if (cursor_vpos >= 0)
1570 {
1571 if (!just_this_one || clip_changed || beg_unchanged < startp)
1572 /* Forget any recorded base line for line number display. */
1573 w->base_line_number = Qnil;
1574 goto done;
1575 }
1576 else
1577 cancel_my_columns (w);
1578 }
1579 scroll_fail: ;
1580 }
1581
1582 /* Finally, just choose place to start which centers point */
1583
1584 recenter:
1585 /* Forget any previously recorded base line for line number display. */
1586 w->base_line_number = Qnil;
1587
1588 pos = *vmotion (PT, - (height / 2), width, hscroll, window);
1589 try_window (window, pos.bufpos);
1590
1591 startp = marker_position (w->start);
1592 w->start_at_line_beg
1593 = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
1594
1595 done:
1596 if ((update_mode_line
1597 /* If window not full width, must redo its mode line
1598 if the window to its side is being redone */
1599 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
1600 || INTEGERP (w->base_line_pos)
1601 || (!NILP (w->column_number_displayed)
1602 && XFASTINT (w->column_number_displayed) != current_column ()))
1603 && height != XFASTINT (w->height))
1604 display_mode_line (w);
1605 if (! line_number_displayed
1606 && ! BUFFERP (w->base_line_pos))
1607 {
1608 w->base_line_pos = Qnil;
1609 w->base_line_number = Qnil;
1610 }
1611
1612 /* When we reach a frame's selected window, redo the frame's menu bar. */
1613 if (update_mode_line
1614 #ifdef USE_X_TOOLKIT
1615 && FRAME_EXTERNAL_MENU_BAR (f)
1616 #else
1617 && FRAME_MENU_BAR_LINES (f) > 0
1618 #endif
1619 && EQ (FRAME_SELECTED_WINDOW (f), window))
1620 display_menu_bar (w);
1621
1622 finish_scroll_bars:
1623 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
1624 {
1625 int start, end, whole;
1626
1627 /* Calculate the start and end positions for the current window.
1628 At some point, it would be nice to choose between scrollbars
1629 which reflect the whole buffer size, with special markers
1630 indicating narrowing, and scrollbars which reflect only the
1631 visible region.
1632
1633 Note that minibuffers sometimes aren't displaying any text. */
1634 if (! MINI_WINDOW_P (w)
1635 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1636 {
1637 whole = ZV - BEGV;
1638 start = marker_position (w->start) - BEGV;
1639 /* I don't think this is guaranteed to be right. For the
1640 moment, we'll pretend it is. */
1641 end = (Z - XINT (w->window_end_pos)) - BEGV;
1642
1643 if (end < start) end = start;
1644 if (whole < (end - start)) whole = end - start;
1645 }
1646 else
1647 start = end = whole = 0;
1648
1649 /* Indicate what this scroll bar ought to be displaying now. */
1650 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
1651
1652 /* Note that we actually used the scroll bar attached to this window,
1653 so it shouldn't be deleted at the end of redisplay. */
1654 (*redeem_scroll_bar_hook) (w);
1655 }
1656
1657 BUF_PT (current_buffer) = opoint;
1658 if (update_mode_line)
1659 set_buffer_internal (old);
1660 else
1661 set_buffer_temp (old);
1662 BUF_PT (current_buffer) = lpoint;
1663 }
1664 \f
1665 /* Do full redisplay on one window, starting at position `pos'. */
1666
1667 static void
1668 try_window (window, pos)
1669 Lisp_Object window;
1670 register int pos;
1671 {
1672 register struct window *w = XWINDOW (window);
1673 register int height = window_internal_height (w);
1674 register int vpos = XFASTINT (w->top);
1675 register int last_text_vpos = vpos;
1676 int tab_offset = pos_tab_offset (w, pos);
1677 FRAME_PTR f = XFRAME (w->frame);
1678 int width = window_internal_width (w) - 1;
1679 struct position val;
1680
1681 Fset_marker (w->start, make_number (pos), Qnil);
1682 cursor_vpos = -1;
1683 overlay_arrow_seen = 0;
1684 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1685
1686 while (--height >= 0)
1687 {
1688 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1689 tab_offset += width;
1690 /* For the first line displayed, display_text_line
1691 subtracts the prompt width from the tab offset.
1692 But it does not affect the value of our variable tab_offset.
1693 So we do the subtraction again,
1694 for the sake of continuation lines of that first line. */
1695 if (MINI_WINDOW_P (w) && vpos == XFASTINT (w->top))
1696 tab_offset -= minibuf_prompt_width;
1697
1698 if (val.vpos) tab_offset = 0;
1699 vpos++;
1700 if (pos != val.bufpos)
1701 {
1702 int invis = 0;
1703 #ifdef USE_TEXT_PROPERTIES
1704 Lisp_Object invis_prop;
1705 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
1706 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
1707 #endif
1708
1709 last_text_vpos
1710 /* Next line, unless prev line ended in end of buffer with no cr */
1711 = vpos - (val.vpos
1712 && (FETCH_CHAR (val.bufpos - 1) != '\n' || invis));
1713 }
1714 pos = val.bufpos;
1715 }
1716
1717 /* If last line is continued in middle of character,
1718 include the split character in the text considered on the frame */
1719 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1720 pos++;
1721
1722 /* If bottom just moved off end of frame, change mode line percentage. */
1723 if (XFASTINT (w->window_end_pos) == 0
1724 && Z != pos)
1725 w->update_mode_line = Qt;
1726
1727 /* Say where last char on frame will be, once redisplay is finished. */
1728 XSETFASTINT (w->window_end_pos, Z - pos);
1729 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
1730 /* But that is not valid info until redisplay finishes. */
1731 w->window_end_valid = Qnil;
1732 }
1733 \f
1734 /* Try to redisplay when buffer is modified locally,
1735 computing insert/delete line to preserve text outside
1736 the bounds of the changes.
1737 Return 1 if successful, 0 if if cannot tell what to do,
1738 or -1 to tell caller to find a new window start,
1739 or -2 to tell caller to do normal redisplay with same window start. */
1740
1741 static int
1742 try_window_id (window)
1743 Lisp_Object window;
1744 {
1745 int pos;
1746 register struct window *w = XWINDOW (window);
1747 register int height = window_internal_height (w);
1748 FRAME_PTR f = XFRAME (w->frame);
1749 int top = XFASTINT (w->top);
1750 int start = marker_position (w->start);
1751 int width = window_internal_width (w) - 1;
1752 int hscroll = XINT (w->hscroll);
1753 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
1754 register int vpos;
1755 register int i, tem;
1756 int last_text_vpos = 0;
1757 int stop_vpos;
1758 int selective = (INTEGERP (current_buffer->selective_display)
1759 ? XINT (current_buffer->selective_display)
1760 : !NILP (current_buffer->selective_display) ? -1 : 0);
1761
1762 struct position val, bp, ep, xp, pp;
1763 int scroll_amount = 0;
1764 int delta;
1765 int tab_offset, epto;
1766
1767 if (GPT - BEG < beg_unchanged)
1768 beg_unchanged = GPT - BEG;
1769 if (Z - GPT < end_unchanged)
1770 end_unchanged = Z - GPT;
1771
1772 if (beg_unchanged + BEG < start)
1773 return 0; /* Give up if changes go above top of window */
1774
1775 /* Find position before which nothing is changed. */
1776 bp = *compute_motion (start, 0, lmargin,
1777 min (ZV, beg_unchanged + BEG), height, 0,
1778 width, hscroll, pos_tab_offset (w, start), w);
1779 if (bp.vpos >= height)
1780 {
1781 if (PT < bp.bufpos)
1782 {
1783 /* All changes are below the frame, and point is on the frame.
1784 We don't need to change the frame at all.
1785 But we need to update window_end_pos to account for
1786 any change in buffer size. */
1787 bp = *compute_motion (start, 0, lmargin,
1788 Z, height, 0,
1789 width, hscroll, pos_tab_offset (w, start), w);
1790 XSETFASTINT (w->window_end_vpos, height);
1791 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
1792 goto findpoint;
1793 }
1794 return 0;
1795 }
1796
1797 vpos = bp.vpos;
1798
1799 /* Find beginning of that frame line. Must display from there. */
1800 bp = *vmotion (bp.bufpos, 0, width, hscroll, window);
1801
1802 pos = bp.bufpos;
1803 val.hpos = lmargin;
1804 if (pos < start)
1805 return -1;
1806
1807 /* If about to start displaying at the beginning of a continuation line,
1808 really start with previous frame line, in case it was not
1809 continued when last redisplayed */
1810 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
1811 ||
1812 /* Likewise if we have to worry about selective display. */
1813 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
1814 {
1815 bp = *vmotion (bp.bufpos, -1, width, hscroll, window);
1816 --vpos;
1817 pos = bp.bufpos;
1818 }
1819
1820 if (bp.contin && bp.hpos != lmargin)
1821 {
1822 val.hpos = bp.prevhpos - width + lmargin;
1823 pos--;
1824 }
1825
1826 bp.vpos = vpos;
1827
1828 /* Find first visible newline after which no more is changed. */
1829 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
1830 if (selective > 0)
1831 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
1832 tem = find_next_newline (tem, 1);
1833
1834 /* Compute the cursor position after that newline. */
1835 ep = *compute_motion (pos, vpos, val.hpos, tem,
1836 height, - (1 << (SHORTBITS - 1)),
1837 width, hscroll, pos_tab_offset (w, bp.bufpos), w);
1838
1839 /* If changes reach past the text available on the frame,
1840 just display rest of frame. */
1841 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
1842 stop_vpos = height;
1843 else
1844 stop_vpos = ep.vpos;
1845
1846 /* If no newline before ep, the line ep is on includes some changes
1847 that must be displayed. Make sure we don't stop before it. */
1848 /* Also, if changes reach all the way until ep.bufpos,
1849 it is possible that something was deleted after the
1850 newline before it, so the following line must be redrawn. */
1851 if (stop_vpos == ep.vpos
1852 && (ep.bufpos == BEGV
1853 || FETCH_CHAR (ep.bufpos - 1) != '\n'
1854 || ep.bufpos == Z - end_unchanged))
1855 stop_vpos = ep.vpos + 1;
1856
1857 cursor_vpos = -1;
1858 overlay_arrow_seen = 0;
1859
1860 /* If changes do not reach to bottom of window,
1861 figure out how much to scroll the rest of the window */
1862 if (stop_vpos < height)
1863 {
1864 /* Now determine how far up or down the rest of the window has moved */
1865 epto = pos_tab_offset (w, ep.bufpos);
1866 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1867 Z - XFASTINT (w->window_end_pos),
1868 10000, 0, width, hscroll, epto, w);
1869 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
1870
1871 /* Is everything on frame below the changes whitespace?
1872 If so, no scrolling is really necessary. */
1873 for (i = ep.bufpos; i < xp.bufpos; i++)
1874 {
1875 tem = FETCH_CHAR (i);
1876 if (tem != ' ' && tem != '\n' && tem != '\t')
1877 break;
1878 }
1879 if (i == xp.bufpos)
1880 return -2;
1881
1882 XSETFASTINT (w->window_end_vpos,
1883 XFASTINT (w->window_end_vpos) + scroll_amount);
1884
1885 /* Before doing any scrolling, verify that point will be on frame. */
1886 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height))
1887 {
1888 if (PT <= xp.bufpos)
1889 {
1890 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1891 PT, height, - (1 << (SHORTBITS - 1)),
1892 width, hscroll, epto, w);
1893 }
1894 else
1895 {
1896 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos,
1897 PT, height, - (1 << (SHORTBITS - 1)),
1898 width, hscroll,
1899 pos_tab_offset (w, xp.bufpos), w);
1900 }
1901 if (pp.bufpos < PT || pp.vpos == height)
1902 return 0;
1903 cursor_vpos = pp.vpos + top;
1904 cursor_hpos = pp.hpos + XFASTINT (w->left);
1905 }
1906
1907 if (stop_vpos - scroll_amount >= height
1908 || ep.bufpos == xp.bufpos)
1909 {
1910 if (scroll_amount < 0)
1911 stop_vpos -= scroll_amount;
1912 scroll_amount = 0;
1913 /* In this path, we have altered window_end_vpos
1914 and not left it negative.
1915 We must make sure that, in case display is preempted
1916 before the frame changes to reflect what we do here,
1917 further updates will not come to try_window_id
1918 and assume the frame and window_end_vpos match. */
1919 blank_end_of_window = 1;
1920 }
1921 else if (!scroll_amount)
1922 {
1923 /* Even if we don't need to scroll, we must adjust the
1924 charstarts of subsequent lines (that we won't redisplay)
1925 according to the amount of text inserted or deleted. */
1926 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1927 int adjust = ep.bufpos - oldpos;
1928 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
1929 }
1930 else if (bp.bufpos == Z - end_unchanged)
1931 {
1932 /* If reprinting everything is nearly as fast as scrolling,
1933 don't bother scrolling. Can happen if lines are short. */
1934 if (scroll_cost (f, bp.vpos + top - scroll_amount,
1935 top + height - max (0, scroll_amount),
1936 scroll_amount)
1937 > xp.bufpos - bp.bufpos - 20)
1938 /* Return "try normal display with same window-start."
1939 Too bad we can't prevent further scroll-thinking. */
1940 return -2;
1941 /* If pure deletion, scroll up as many lines as possible.
1942 In common case of killing a line, this can save the
1943 following line from being overwritten by scrolling
1944 and therefore having to be redrawn. */
1945 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
1946 top + height - max (0, scroll_amount),
1947 scroll_amount, bp.bufpos);
1948 if (!tem)
1949 stop_vpos = height;
1950 else
1951 {
1952 /* scroll_frame_lines did not properly adjust subsequent
1953 lines' charstarts in the case where the text of the
1954 screen line at bp.vpos has changed.
1955 (This can happen in a deletion that ends in mid-line.)
1956 To adjust properly, we need to make things constent at
1957 the position ep.
1958 So do a second adjust to make that happen.
1959 Note that stop_vpos >= ep.vpos, so it is sufficient
1960 to update the charstarts for lines at ep.vpos and below. */
1961 int oldstart
1962 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
1963 adjust_window_charstarts (w, ep.vpos + top - 1,
1964 ep.bufpos - oldstart);
1965 }
1966 }
1967 else if (scroll_amount)
1968 {
1969 /* If reprinting everything is nearly as fast as scrolling,
1970 don't bother scrolling. Can happen if lines are short. */
1971 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1972 overestimate of cost of reprinting, since xp.bufpos
1973 would end up below the bottom of the window. */
1974 if (scroll_cost (f, ep.vpos + top - scroll_amount,
1975 top + height - max (0, scroll_amount),
1976 scroll_amount)
1977 > xp.bufpos - ep.bufpos - 20)
1978 /* Return "try normal display with same window-start."
1979 Too bad we can't prevent further scroll-thinking. */
1980 return -2;
1981 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
1982 top + height - max (0, scroll_amount),
1983 scroll_amount, ep.bufpos);
1984 if (!tem) stop_vpos = height;
1985 }
1986 }
1987
1988 /* In any case, do not display past bottom of window */
1989 if (stop_vpos >= height)
1990 {
1991 stop_vpos = height;
1992 scroll_amount = 0;
1993 }
1994
1995 /* Handle case where pos is before w->start --
1996 can happen if part of line had been clipped and is not clipped now */
1997 if (vpos == 0 && pos < marker_position (w->start))
1998 Fset_marker (w->start, make_number (pos), Qnil);
1999
2000 /* Redisplay the lines where the text was changed */
2001 last_text_vpos = vpos;
2002 tab_offset = pos_tab_offset (w, pos);
2003 /* If we are starting display in mid-character, correct tab_offset
2004 to account for passing the line that that character really starts in. */
2005 if (val.hpos < lmargin)
2006 tab_offset += width;
2007 while (vpos < stop_vpos)
2008 {
2009 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2010 tab_offset += width;
2011 if (val.vpos) tab_offset = 0;
2012 if (pos != val.bufpos)
2013 last_text_vpos
2014 /* Next line, unless prev line ended in end of buffer with no cr */
2015 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
2016 pos = val.bufpos;
2017 }
2018
2019 /* There are two cases:
2020 1) we have displayed down to the bottom of the window
2021 2) we have scrolled lines below stop_vpos by scroll_amount */
2022
2023 if (vpos == height)
2024 {
2025 /* If last line is continued in middle of character,
2026 include the split character in the text considered on the frame */
2027 if (val.hpos < lmargin)
2028 val.bufpos++;
2029 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2030 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2031 }
2032
2033 /* If scrolling made blank lines at window bottom,
2034 redisplay to fill those lines */
2035 if (scroll_amount < 0)
2036 {
2037 /* Don't consider these lines for general-purpose scrolling.
2038 That will save time in the scrolling computation. */
2039 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2040 vpos = xp.vpos;
2041 pos = xp.bufpos;
2042 val.hpos = lmargin;
2043 if (pos == ZV)
2044 vpos = height + scroll_amount;
2045 else if (xp.contin && xp.hpos != lmargin)
2046 {
2047 val.hpos = xp.prevhpos - width + lmargin;
2048 pos--;
2049 }
2050
2051 blank_end_of_window = 1;
2052 tab_offset = pos_tab_offset (w, pos);
2053 /* If we are starting display in mid-character, correct tab_offset
2054 to account for passing the line that that character starts in. */
2055 if (val.hpos < lmargin)
2056 tab_offset += width;
2057
2058 while (vpos < height)
2059 {
2060 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
2061 tab_offset += width;
2062 if (val.vpos) tab_offset = 0;
2063 pos = val.bufpos;
2064 }
2065
2066 /* Here is a case where display_text_line sets cursor_vpos wrong.
2067 Make it be fixed up, below. */
2068 if (xp.bufpos == ZV
2069 && xp.bufpos == PT)
2070 cursor_vpos = -1;
2071 }
2072
2073 /* If bottom just moved off end of frame, change mode line percentage. */
2074 if (XFASTINT (w->window_end_pos) == 0
2075 && Z != val.bufpos)
2076 w->update_mode_line = Qt;
2077
2078 /* Attempt to adjust end-of-text positions to new bottom line */
2079 if (scroll_amount)
2080 {
2081 delta = height - xp.vpos;
2082 if (delta < 0
2083 || (delta > 0 && xp.bufpos <= ZV)
2084 || (delta == 0 && xp.hpos))
2085 {
2086 val = *vmotion (Z - XFASTINT (w->window_end_pos),
2087 delta, width, hscroll, window);
2088 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2089 XSETFASTINT (w->window_end_vpos,
2090 XFASTINT (w->window_end_vpos) + val.vpos);
2091 }
2092 }
2093
2094 w->window_end_valid = Qnil;
2095
2096 /* If point was not in a line that was displayed, find it */
2097 if (cursor_vpos < 0)
2098 {
2099 findpoint:
2100 val = *compute_motion (start, 0, lmargin, PT, 10000, 10000,
2101 width, hscroll, pos_tab_offset (w, start), w);
2102 /* Admit failure if point is off frame now */
2103 if (val.vpos >= height)
2104 {
2105 for (vpos = 0; vpos < height; vpos++)
2106 cancel_line (vpos + top, f);
2107 return 0;
2108 }
2109 cursor_vpos = val.vpos + top;
2110 cursor_hpos = val.hpos + XFASTINT (w->left);
2111 }
2112
2113 FRAME_CURSOR_X (f) = max (0, cursor_hpos);
2114 FRAME_CURSOR_Y (f) = cursor_vpos;
2115
2116 if (debug_end_pos)
2117 {
2118 val = *compute_motion (start, 0, lmargin, ZV,
2119 height, - (1 << (SHORTBITS - 1)),
2120 width, hscroll, pos_tab_offset (w, start), w);
2121 if (val.vpos != XFASTINT (w->window_end_vpos))
2122 abort ();
2123 if (XFASTINT (w->window_end_pos)
2124 != Z - val.bufpos)
2125 abort ();
2126 }
2127
2128 return 1;
2129 }
2130 \f
2131 /* Mark a section of BUF as modified, but only for the sake of redisplay.
2132 This is useful for recording changes to overlays.
2133
2134 We increment the buffer's modification timestamp and set the
2135 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
2136 as if the region of text between START and END had been modified;
2137 the redisplay code will check this against the windows' timestamps,
2138 and redraw the appropriate area of the buffer.
2139
2140 However, if the buffer is unmodified, we bump the last-save
2141 timestamp as well, so that incrementing the timestamp doesn't fool
2142 Emacs into thinking that the buffer's text has been modified.
2143
2144 Tweaking the timestamps shouldn't hurt the first-modification
2145 timestamps recorded in the undo records; those values aren't
2146 written until just before a real text modification is made, so they
2147 will never catch the timestamp value just before this function gets
2148 called. */
2149
2150 void
2151 redisplay_region (buf, start, end)
2152 struct buffer *buf;
2153 int start, end;
2154 {
2155 if (start == end)
2156 return;
2157
2158 if (start > end)
2159 {
2160 int temp = start;
2161 start = end; end = temp;
2162 }
2163
2164 /* If this is a buffer not in the selected window,
2165 we must do other windows. */
2166 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2167 windows_or_buffers_changed = 1;
2168 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2169 else if (buf != current_buffer)
2170 windows_or_buffers_changed = 1;
2171 /* If multiple windows show this buffer, we must do other windows. */
2172 else if (buffer_shared > 1)
2173 windows_or_buffers_changed = 1;
2174 else
2175 {
2176 if (unchanged_modified == MODIFF)
2177 {
2178 beg_unchanged = start - BEG;
2179 end_unchanged = Z - end;
2180 }
2181 else
2182 {
2183 if (Z - end < end_unchanged)
2184 end_unchanged = Z - end;
2185 if (start - BEG < beg_unchanged)
2186 beg_unchanged = start - BEG;
2187 }
2188 }
2189
2190 /* Increment the buffer's time stamp, but also increment the save
2191 and autosave timestamps, so as not to screw up that timekeeping. */
2192 if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf))
2193 BUF_SAVE_MODIFF (buf)++;
2194 if (BUF_MODIFF (buf) == buf->auto_save_modified)
2195 buf->auto_save_modified++;
2196
2197 BUF_MODIFF (buf) ++;
2198 }
2199
2200 \f
2201 /* Copy LEN glyphs starting address FROM to the rope TO.
2202 But don't actually copy the parts that would come in before S.
2203 Value is TO, advanced past the copied data.
2204 F is the frame we are displaying in. */
2205
2206 static GLYPH *
2207 copy_part_of_rope (f, to, s, from, len, face)
2208 FRAME_PTR f;
2209 register GLYPH *to; /* Copy to here. */
2210 register GLYPH *s; /* Starting point. */
2211 Lisp_Object *from; /* Data to copy. */
2212 int len;
2213 int face; /* Face to apply to glyphs which don't specify one. */
2214 {
2215 int n = len;
2216 register Lisp_Object *fp = from;
2217 /* These cache the results of the last call to compute_glyph_face. */
2218 int last_code = -1;
2219 int last_merged = 0;
2220
2221 #ifdef HAVE_FACES
2222 if (! FRAME_TERMCAP_P (f))
2223 while (n--)
2224 {
2225 int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2226 int facecode;
2227
2228 if (FAST_GLYPH_FACE (glyph) == 0)
2229 /* If GLYPH has no face code, use FACE. */
2230 facecode = face;
2231 else if (FAST_GLYPH_FACE (glyph) == last_code)
2232 /* If it's same as previous glyph, use same result. */
2233 facecode = last_merged;
2234 else
2235 {
2236 /* Merge this glyph's face and remember the result. */
2237 last_code = FAST_GLYPH_FACE (glyph);
2238 last_merged = facecode = compute_glyph_face (f, last_code, face);
2239 }
2240
2241 if (to >= s)
2242 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
2243 ++to;
2244 ++fp;
2245 }
2246 else
2247 #endif
2248 while (n--)
2249 {
2250 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2251 ++to;
2252 ++fp;
2253 }
2254 return to;
2255 }
2256
2257 /* Correct a glyph by replacing its specified user-level face code
2258 with a displayable computed face code. */
2259
2260 static GLYPH
2261 fix_glyph (f, glyph, cface)
2262 FRAME_PTR f;
2263 GLYPH glyph;
2264 int cface;
2265 {
2266 #ifdef HAVE_FACES
2267 if (! FRAME_TERMCAP_P (f))
2268 {
2269 if (FAST_GLYPH_FACE (glyph) != 0)
2270 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2271 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2272 }
2273 #endif
2274 return glyph;
2275 }
2276 \f
2277 /* Display one line of window W, starting at position START in W's buffer.
2278
2279 Display starting at horizontal position HPOS, expressed relative to
2280 W's left edge. In situations where the text at START shouldn't
2281 start at the left margin (i.e. when the window is hscrolled, or
2282 we're continuing a line which left off in the midst of a
2283 multi-column character), HPOS should be negative; we throw away
2284 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2285 account.
2286
2287 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2288
2289 Display on position VPOS on the frame. It is origin 0, relative to
2290 the top of the frame, not W.
2291
2292 Returns a STRUCT POSITION giving character to start next line with
2293 and where to display it, including a zero or negative hpos.
2294 The vpos field is not really a vpos; it is 1 unless the line is continued */
2295
2296 struct position val_display_text_line;
2297
2298 static struct position *
2299 display_text_line (w, start, vpos, hpos, taboffset)
2300 struct window *w;
2301 int start;
2302 int vpos;
2303 int hpos;
2304 int taboffset;
2305 {
2306 register int pos = start;
2307 register int c;
2308 register GLYPH *p1;
2309 int end;
2310 register int pause;
2311 register unsigned char *p;
2312 GLYPH *endp;
2313 register GLYPH *leftmargin;
2314 register GLYPH *p1prev = 0;
2315 register GLYPH *p1start;
2316 int *charstart;
2317 FRAME_PTR f = XFRAME (w->frame);
2318 int tab_width = XINT (current_buffer->tab_width);
2319 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2320 int width = window_internal_width (w) - 1;
2321 struct position val;
2322 int lastpos;
2323 int invis;
2324 int last_invis_skip = 0;
2325 Lisp_Object last_invis_prop;
2326 int hscroll = XINT (w->hscroll);
2327 int truncate = (hscroll
2328 || (truncate_partial_width_windows
2329 && XFASTINT (w->width) < FRAME_WIDTH (f))
2330 || !NILP (current_buffer->truncate_lines));
2331
2332 /* 1 if we should highlight the region. */
2333 int highlight_region
2334 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
2335 int region_beg, region_end;
2336
2337 int selective = (INTEGERP (current_buffer->selective_display)
2338 ? XINT (current_buffer->selective_display)
2339 : !NILP (current_buffer->selective_display) ? -1 : 0);
2340 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2341 register struct Lisp_Vector *dp = window_display_table (w);
2342
2343 Lisp_Object default_invis_vector[3];
2344 /* Number of characters of ellipsis to display after an invisible line
2345 if it calls for an ellipsis.
2346 Note that this value can be nonzero regardless of whether
2347 selective display is enabled--you must check that separately. */
2348 int selective_rlen
2349 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2350 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2351 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
2352 /* This is the sequence of Lisp objects to display
2353 when there are invisible lines. */
2354 Lisp_Object *invis_vector_contents
2355 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2356 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2357 : default_invis_vector);
2358
2359 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2360 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2361 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2362 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2363
2364 /* The next buffer location at which the face should change, due
2365 to overlays or text property changes. */
2366 int next_face_change;
2367
2368 #ifdef USE_TEXT_PROPERTIES
2369 /* The next location where the `invisible' property changes */
2370 int next_invisible;
2371 #endif
2372
2373 /* The face we're currently using. */
2374 int current_face = 0;
2375 int i;
2376
2377 XSETFASTINT (default_invis_vector[2], '.');
2378 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2379
2380 hpos += XFASTINT (w->left);
2381 get_display_line (f, vpos, XFASTINT (w->left));
2382 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2383
2384 /* Show where to highlight the region. */
2385 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2386 /* Maybe highlight only in selected window. */
2387 && (highlight_nonselected_windows
2388 || w == XWINDOW (selected_window)))
2389 {
2390 region_beg = marker_position (current_buffer->mark);
2391 if (PT < region_beg)
2392 {
2393 region_end = region_beg;
2394 region_beg = PT;
2395 }
2396 else
2397 region_end = PT;
2398 w->region_showing = Qt;
2399 }
2400 else
2401 region_beg = region_end = -1;
2402
2403 if (MINI_WINDOW_P (w)
2404 && start == 1
2405 && vpos == XFASTINT (w->top))
2406 {
2407 if (! NILP (minibuf_prompt))
2408 {
2409 minibuf_prompt_width
2410 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2411 XSTRING (minibuf_prompt)->size, hpos,
2412 /* Display a space if we truncate. */
2413 ' ',
2414 1, -1,
2415 /* Truncate the prompt a little before the
2416 margin, so user input can at least start
2417 on the first line. */
2418 w->width > 10 ? w->width - 4 : -1)
2419 - hpos);
2420 hpos += minibuf_prompt_width;
2421 taboffset -= minibuf_prompt_width;
2422 }
2423 else
2424 minibuf_prompt_width = 0;
2425 }
2426
2427 end = ZV;
2428
2429 /* If we're hscrolled at all, use compute_motion to skip over any
2430 text off the left edge of the window. compute_motion may know
2431 tricks to do this faster than we can. */
2432 if (hpos < 0)
2433 {
2434 struct position *left_edge
2435 = compute_motion (pos, vpos, hpos,
2436 end, vpos, 0,
2437 width, hscroll, taboffset, w);
2438
2439 /* Retrieve the buffer position and column provided by
2440 compute_motion. We can't assume that the column will be
2441 zero, because you may have multi-column characters crossing
2442 the left margin.
2443
2444 compute_motion may have moved us past the screen position we
2445 requested, if we hit a multi-column character, or the end of
2446 the line. If so, back up. */
2447 if (left_edge->vpos > vpos
2448 || left_edge->hpos > 0)
2449 {
2450 pos = left_edge->bufpos - 1;
2451 hpos = left_edge->prevhpos;
2452 }
2453 else
2454 {
2455 pos = left_edge->bufpos;
2456 hpos = left_edge->hpos;
2457 }
2458 }
2459
2460 desired_glyphs->bufp[vpos] = start;
2461 p1 = desired_glyphs->glyphs[vpos] + hpos;
2462 p1start = p1;
2463 charstart = desired_glyphs->charstarts[vpos] + hpos;
2464 /* In case we don't ever write anything into it... */
2465 desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1;
2466 leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2467 endp = leftmargin + width;
2468
2469 /* Arrange the overlays nicely for our purposes. Usually, we call
2470 display_text_line on only one line at a time, in which case this
2471 can't really hurt too much, or we call it on lines which appear
2472 one after another in the buffer, in which case all calls to
2473 recenter_overlay_lists but the first will be pretty cheap. */
2474 recenter_overlay_lists (current_buffer, pos);
2475
2476 /* Loop generating characters.
2477 Stop at end of buffer, before newline,
2478 if reach or pass continuation column,
2479 or at face change. */
2480 pause = pos;
2481 next_face_change = pos;
2482 #ifdef USE_TEXT_PROPERTIES
2483 next_invisible = pos;
2484 #endif
2485 while (1)
2486 {
2487 /* Record which glyph starts a character,
2488 and the character position of that character. */
2489 if (p1 >= leftmargin)
2490 charstart[p1 - p1start] = pos;
2491
2492 if (p1 >= endp)
2493 break;
2494
2495 p1prev = p1;
2496 if (pos >= pause)
2497 {
2498 /* Did we hit the end of the visible region of the buffer?
2499 Stop here. */
2500 if (pos >= end)
2501 break;
2502
2503 /* Did we reach point? Record the cursor location. */
2504 if (pos == PT && cursor_vpos < 0)
2505 {
2506 cursor_vpos = vpos;
2507 cursor_hpos = p1 - leftmargin;
2508 }
2509
2510 #ifdef USE_TEXT_PROPERTIES
2511 /* if the `invisible' property is set to t, we can skip to
2512 the next property change */
2513 while (pos == next_invisible && pos < end)
2514 {
2515 Lisp_Object position, limit, endpos, prop, ww;
2516 XSETFASTINT (position, pos);
2517 XSETWINDOW (ww, w);
2518 prop = Fget_char_property (position, Qinvisible, ww);
2519 /* This is just an estimate to give reasonable
2520 performance; nothing should go wrong if it is too small. */
2521 limit = Fnext_overlay_change (position);
2522 if (XFASTINT (limit) > pos + 50)
2523 XSETFASTINT (limit, pos + 50);
2524 endpos = Fnext_single_property_change (position, Qinvisible,
2525 Fcurrent_buffer (),
2526 limit);
2527 if (INTEGERP (endpos))
2528 next_invisible = XINT (endpos);
2529 else
2530 next_invisible = end;
2531 if (TEXT_PROP_MEANS_INVISIBLE (prop))
2532 {
2533 if (pos < PT && next_invisible >= PT)
2534 {
2535 cursor_vpos = vpos;
2536 cursor_hpos = p1 - leftmargin;
2537 }
2538 pos = next_invisible;
2539 last_invis_skip = pos;
2540 last_invis_prop = prop;
2541 }
2542 }
2543 if (pos >= end)
2544 break;
2545 #endif
2546
2547 #ifdef HAVE_FACES
2548 /* Did we hit a face change? Figure out what face we should
2549 use now. We also hit this the first time through the
2550 loop, to see what face we should start with. */
2551 if (pos >= next_face_change && FRAME_X_P (f))
2552 current_face = compute_char_face (f, w, pos,
2553 region_beg, region_end,
2554 &next_face_change, pos + 50, 0);
2555 #endif
2556
2557 pause = end;
2558
2559 #ifdef USE_TEXT_PROPERTIES
2560 if (pos < next_invisible && next_invisible < pause)
2561 pause = next_invisible;
2562 #endif
2563 if (pos < next_face_change && next_face_change < pause)
2564 pause = next_face_change;
2565
2566 /* Wouldn't you hate to read the next line to someone over
2567 the phone? */
2568 if (pos < PT && PT < pause)
2569 pause = PT;
2570 if (pos < GPT && GPT < pause)
2571 pause = GPT;
2572
2573 p = &FETCH_CHAR (pos);
2574 }
2575 c = *p++;
2576 /* Let a display table override all standard display methods. */
2577 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
2578 {
2579 p1 = copy_part_of_rope (f, p1, leftmargin,
2580 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2581 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2582 current_face);
2583 }
2584 else if (c >= 040 && c < 0177)
2585 {
2586 if (p1 >= leftmargin)
2587 *p1 = MAKE_GLYPH (f, c, current_face);
2588 p1++;
2589 }
2590 else if (c == '\n')
2591 {
2592 invis = 0;
2593 if (last_invis_skip == pos
2594 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
2595 invis = 1;
2596 while (pos + 1 < end
2597 && selective > 0
2598 && indented_beyond_p (pos + 1, selective))
2599 {
2600 invis = 1;
2601 pos = find_next_newline (pos + 1, 1);
2602 if (FETCH_CHAR (pos - 1) == '\n')
2603 pos--;
2604 }
2605 if (invis && selective_rlen > 0 && p1 >= leftmargin)
2606 {
2607 p1 += selective_rlen;
2608 if (p1 - leftmargin > width)
2609 p1 = endp;
2610 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2611 (p1 - p1prev), current_face);
2612 }
2613 #ifdef HAVE_FACES
2614 /* Draw the face of the newline character as extending all the
2615 way to the end of the frame line. */
2616 if (current_face)
2617 {
2618 if (p1 < leftmargin)
2619 p1 = leftmargin;
2620 while (p1 < endp)
2621 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2622 }
2623 #endif
2624 break;
2625 }
2626 else if (c == '\t')
2627 {
2628 do
2629 {
2630 if (p1 >= leftmargin && p1 < endp)
2631 *p1 = MAKE_GLYPH (f, ' ', current_face);
2632 p1++;
2633 }
2634 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
2635 % tab_width);
2636 }
2637 else if (c == Ctl ('M') && selective == -1)
2638 {
2639 pos = find_next_newline (pos, 1);
2640 if (FETCH_CHAR (pos - 1) == '\n')
2641 pos--;
2642 if (selective_rlen > 0)
2643 {
2644 p1 += selective_rlen;
2645 if (p1 - leftmargin > width)
2646 p1 = endp;
2647 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
2648 (p1 - p1prev), current_face);
2649 }
2650 #ifdef HAVE_FACES
2651 /* Draw the face of the newline character as extending all the
2652 way to the end of the frame line. */
2653 if (current_face)
2654 {
2655 if (p1 < leftmargin)
2656 p1 = leftmargin;
2657 while (p1 < endp)
2658 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
2659 }
2660 #endif
2661 break;
2662 }
2663 else if (c < 0200 && ctl_arrow)
2664 {
2665 if (p1 >= leftmargin)
2666 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
2667 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
2668 current_face);
2669 p1++;
2670 if (p1 >= leftmargin && p1 < endp)
2671 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
2672 p1++;
2673 }
2674 else
2675 {
2676 if (p1 >= leftmargin)
2677 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
2678 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
2679 current_face);
2680 p1++;
2681 if (p1 >= leftmargin && p1 < endp)
2682 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
2683 p1++;
2684 if (p1 >= leftmargin && p1 < endp)
2685 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
2686 p1++;
2687 if (p1 >= leftmargin && p1 < endp)
2688 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
2689 p1++;
2690 }
2691
2692 /* Do nothing here for a char that's entirely off the left edge. */
2693 if (p1 >= leftmargin)
2694 {
2695 /* For all the glyphs occupied by this character, except for the
2696 first, store -1 in charstarts. */
2697 if (p1 != p1prev)
2698 {
2699 int *p2x = &charstart[p1prev - p1start];
2700 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
2701
2702 /* The window's left column should always
2703 contain a character position.
2704 And don't clobber anything to the left of that. */
2705 if (p1prev < leftmargin)
2706 {
2707 p2x = charstart + (leftmargin - p1start);
2708 *p2x = pos;
2709 }
2710
2711 /* This loop skips over the char p2x initially points to. */
2712 while (++p2x < p2)
2713 *p2x = -1;
2714 }
2715 }
2716
2717 pos++;
2718 }
2719
2720 val.hpos = - XINT (w->hscroll);
2721 if (val.hpos)
2722 val.hpos++;
2723
2724 val.vpos = 1;
2725
2726 lastpos = pos;
2727
2728 /* Store 0 in this charstart line for the positions where
2729 there is no character. But do leave what was recorded
2730 for the character that ended the line. */
2731 /* Add 1 in the endtest to compensate for the fact that ENDP was
2732 made from WIDTH, which is 1 less than the window's actual
2733 internal width. */
2734 i = p1 - p1start + 1;
2735 if (p1 < leftmargin)
2736 i += leftmargin - p1;
2737 for (; i < endp - p1start + 1; i++)
2738 charstart[i] = 0;
2739
2740 /* Handle continuation in middle of a character */
2741 /* by backing up over it */
2742 if (p1 > endp)
2743 {
2744 /* Don't back up if we never actually displayed any text.
2745 This occurs when the minibuffer prompt takes up the whole line. */
2746 if (p1prev)
2747 {
2748 /* Start the next line with that same character */
2749 pos--;
2750 /* but at negative hpos, to skip the columns output on this line. */
2751 val.hpos += p1prev - endp;
2752 }
2753
2754 /* Keep in this line everything up to the continuation column. */
2755 p1 = endp;
2756 }
2757
2758 /* Finish deciding which character to start the next line on,
2759 and what hpos to start it at.
2760 Also set `lastpos' to the last position which counts as "on this line"
2761 for cursor-positioning. */
2762
2763 if (pos < ZV)
2764 {
2765 if (FETCH_CHAR (pos) == '\n')
2766 {
2767 /* If stopped due to a newline, start next line after it */
2768 pos++;
2769 /* Check again for hidden lines, in case the newline occurred exactly
2770 at the right margin. */
2771 while (pos < ZV && selective > 0
2772 && indented_beyond_p (pos, selective))
2773 pos = find_next_newline (pos, 1);
2774 }
2775 else
2776 /* Stopped due to right margin of window */
2777 {
2778 if (truncate)
2779 {
2780 *p1++ = fix_glyph (f, truncator, 0);
2781 /* Truncating => start next line after next newline,
2782 and point is on this line if it is before the newline,
2783 and skip none of first char of next line */
2784 do
2785 pos = find_next_newline (pos, 1);
2786 while (pos < ZV && selective > 0
2787 && indented_beyond_p (pos, selective));
2788 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2789
2790 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
2791 }
2792 else
2793 {
2794 *p1++ = fix_glyph (f, continuer, 0);
2795 val.vpos = 0;
2796 lastpos--;
2797 }
2798 }
2799 }
2800
2801 /* If point is at eol or in invisible text at eol,
2802 record its frame location now. */
2803
2804 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
2805 {
2806 cursor_vpos = vpos;
2807 cursor_hpos = p1 - leftmargin;
2808 }
2809
2810 if (cursor_vpos == vpos)
2811 {
2812 if (cursor_hpos < 0) cursor_hpos = 0;
2813 if (cursor_hpos > width) cursor_hpos = width;
2814 cursor_hpos += XFASTINT (w->left);
2815 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
2816 {
2817 FRAME_CURSOR_Y (f) = cursor_vpos;
2818 FRAME_CURSOR_X (f) = cursor_hpos;
2819
2820 if (w == XWINDOW (selected_window))
2821 {
2822 /* Line is not continued and did not start
2823 in middle of character */
2824 if ((hpos - XFASTINT (w->left)
2825 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2826 && val.vpos)
2827 {
2828 this_line_bufpos = start;
2829 this_line_buffer = current_buffer;
2830 this_line_vpos = cursor_vpos;
2831 this_line_start_hpos = hpos;
2832 this_line_endpos = Z - lastpos;
2833 }
2834 else
2835 this_line_bufpos = 0;
2836 }
2837 }
2838 }
2839
2840 /* If hscroll and line not empty, insert truncation-at-left marker */
2841 if (hscroll && lastpos != start)
2842 {
2843 *leftmargin = fix_glyph (f, truncator, 0);
2844 if (p1 <= leftmargin)
2845 p1 = leftmargin + 1;
2846 }
2847
2848 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
2849 {
2850 endp++;
2851 if (p1 < leftmargin) p1 = leftmargin;
2852 while (p1 < endp) *p1++ = SPACEGLYPH;
2853
2854 /* Don't draw vertical bars if we're using scroll bars. They're
2855 covered up by the scroll bars, and it's distracting to see
2856 them when the scroll bar windows are flickering around to be
2857 reconfigured. */
2858 *p1++ = (FRAME_HAS_VERTICAL_SCROLL_BARS (f)
2859 ? ' '
2860 : (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
2861 ? DISP_BORDER_GLYPH (dp)
2862 : '|'));
2863 }
2864 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
2865 p1 - desired_glyphs->glyphs[vpos]);
2866 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
2867
2868 /* If the start of this line is the overlay arrow-position,
2869 then put the arrow string into the display-line. */
2870
2871 if (MARKERP (Voverlay_arrow_position)
2872 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
2873 && start == marker_position (Voverlay_arrow_position)
2874 && STRINGP (Voverlay_arrow_string)
2875 && ! overlay_arrow_seen)
2876 {
2877 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
2878 int i;
2879 int len = XSTRING (Voverlay_arrow_string)->size;
2880 int arrow_end;
2881
2882 if (len > width)
2883 len = width;
2884 #ifdef HAVE_FACES
2885 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
2886 {
2887 /* If the arrow string has text props, obey them when displaying. */
2888 for (i = 0; i < len; i++)
2889 {
2890 int c = p[i];
2891 Lisp_Object face, ilisp;
2892 int newface;
2893
2894 XSETFASTINT (ilisp, i);
2895 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
2896 newface = compute_glyph_face_1 (f, face, 0);
2897 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
2898 }
2899 }
2900 else
2901 #endif /* HAVE_FACES */
2902 {
2903 for (i = 0; i < len; i++)
2904 leftmargin[i] = p[i];
2905 }
2906
2907 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
2908 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
2909 if (desired_glyphs->used[vpos] < arrow_end)
2910 desired_glyphs->used[vpos] = arrow_end;
2911
2912 overlay_arrow_seen = 1;
2913 }
2914
2915 val.bufpos = pos;
2916 val_display_text_line = val;
2917 return &val_display_text_line;
2918 }
2919 \f
2920 /* Redisplay the menu bar in the frame for window W. */
2921
2922 static void
2923 display_menu_bar (w)
2924 struct window *w;
2925 {
2926 Lisp_Object items, tail;
2927 register int vpos = 0;
2928 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2929 int maxendcol = FRAME_WIDTH (f);
2930 int hpos = 0;
2931 int i;
2932
2933 #ifndef USE_X_TOOLKIT
2934 if (FRAME_MENU_BAR_LINES (f) <= 0)
2935 return;
2936
2937 get_display_line (f, vpos, 0);
2938
2939 items = FRAME_MENU_BAR_ITEMS (f);
2940 for (i = 0; i < XVECTOR (items)->size; i += 3)
2941 {
2942 Lisp_Object pos, string;
2943 string = XVECTOR (items)->contents[i + 1];
2944 if (NILP (string))
2945 break;
2946
2947 XSETFASTINT (XVECTOR (items)->contents[i + 2], hpos);
2948
2949 if (hpos < maxendcol)
2950 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
2951 XSTRING (string)->data,
2952 XSTRING (string)->size,
2953 hpos, 0, 0, hpos, maxendcol);
2954 /* Put a space between items. */
2955 if (hpos < maxendcol)
2956 {
2957 int hpos1 = hpos + 1;
2958 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
2959 min (hpos1, maxendcol), maxendcol);
2960 }
2961 }
2962
2963 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
2964 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
2965
2966 /* Fill out the line with spaces. */
2967 if (maxendcol > hpos)
2968 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
2969
2970 /* Clear the rest of the lines allocated to the menu bar. */
2971 vpos++;
2972 while (vpos < FRAME_MENU_BAR_LINES (f))
2973 get_display_line (f, vpos++, 0);
2974 #endif /* not USE_X_TOOLKIT */
2975 }
2976 \f
2977 /* Display the mode line for window w */
2978
2979 static void
2980 display_mode_line (w)
2981 struct window *w;
2982 {
2983 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
2984 register int left = XFASTINT (w->left);
2985 register int right = XFASTINT (w->width) + left;
2986 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2987
2988 line_number_displayed = 0;
2989 w->column_number_displayed = Qnil;
2990
2991 get_display_line (f, vpos, left);
2992 #ifdef MULTI_KBOARD
2993 {
2994 /* Sigh, mode-line-format can reference kboard-local variables like
2995 defining-kbd-macro. Use the one associated with the frame we're
2996 updating. */
2997 KBOARD *orig_kboard = current_kboard;
2998 current_kboard = FRAME_KBOARD (f);
2999 #endif
3000 display_mode_element (w, vpos, left, 0, right, right,
3001 current_buffer->mode_line_format);
3002 #ifdef MULTI_KBOARD
3003 current_kboard = orig_kboard;
3004 }
3005 #endif
3006 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3007
3008 /* Make the mode line inverse video if the entire line
3009 is made of mode lines.
3010 I.e. if this window is full width,
3011 or if it is the child of a full width window
3012 (which implies that that window is split side-by-side
3013 and the rest of this line is mode lines of the sibling windows). */
3014 if (XFASTINT (w->width) == FRAME_WIDTH (f)
3015 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
3016 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3017 #ifdef HAVE_FACES
3018 else if (! FRAME_TERMCAP_P (f))
3019 {
3020 /* For a partial width window, explicitly set face of each glyph. */
3021 int i;
3022 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3023 for (i = left; i < right; ++i)
3024 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
3025 }
3026 #endif
3027 }
3028
3029 /* Contribute ELT to the mode line for window W.
3030 How it translates into text depends on its data type.
3031
3032 VPOS is the position of the mode line being displayed.
3033
3034 HPOS is the position (absolute on frame) where this element's text
3035 should start. The output is truncated automatically at the right
3036 edge of window W.
3037
3038 DEPTH is the depth in recursion. It is used to prevent
3039 infinite recursion here.
3040
3041 MINENDCOL is the hpos before which the element may not end.
3042 The element is padded at the right with spaces if nec
3043 to reach this column.
3044
3045 MAXENDCOL is the hpos past which this element may not extend.
3046 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3047 (This is necessary to make nested padding and truncation work.)
3048
3049 Returns the hpos of the end of the text generated by ELT.
3050 The next element will receive that value as its HPOS arg,
3051 so as to concatenate the elements. */
3052
3053 static int
3054 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3055 struct window *w;
3056 register int vpos, hpos;
3057 int depth;
3058 int minendcol;
3059 register int maxendcol;
3060 register Lisp_Object elt;
3061 {
3062 tail_recurse:
3063 if (depth > 10)
3064 goto invalid;
3065
3066 depth++;
3067
3068 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3069 {
3070 case Lisp_String:
3071 {
3072 /* A string: output it and check for %-constructs within it. */
3073 register unsigned char c;
3074 register unsigned char *this = XSTRING (elt)->data;
3075
3076 while (hpos < maxendcol && *this)
3077 {
3078 unsigned char *last = this;
3079 while ((c = *this++) != '\0' && c != '%')
3080 ;
3081 if (this - 1 != last)
3082 {
3083 register int lim = --this - last + hpos;
3084 if (frame_title_ptr)
3085 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3086 else
3087 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3088 hpos, min (lim, maxendcol));
3089 }
3090 else /* c == '%' */
3091 {
3092 register int spec_width = 0;
3093
3094 /* We can't allow -ve args due to the "%-" construct */
3095 /* Argument specifies minwidth but not maxwidth
3096 (maxwidth can be specified by
3097 (<negative-number> . <stuff>) mode-line elements) */
3098
3099 while ((c = *this++) >= '0' && c <= '9')
3100 {
3101 spec_width = spec_width * 10 + (c - '0');
3102 }
3103
3104 spec_width += hpos;
3105 if (spec_width > maxendcol)
3106 spec_width = maxendcol;
3107
3108 if (c == 'M')
3109 hpos = display_mode_element (w, vpos, hpos, depth,
3110 spec_width, maxendcol,
3111 Vglobal_mode_string);
3112 else if (c != 0)
3113 {
3114 char *spec = decode_mode_spec (w, c, maxendcol - hpos);
3115 if (frame_title_ptr)
3116 hpos = store_frame_title (spec, spec_width, maxendcol);
3117 else
3118 hpos = display_string (w, vpos, spec, -1,
3119 hpos, 0, 1,
3120 spec_width, maxendcol);
3121 }
3122 }
3123 }
3124 }
3125 break;
3126
3127 case Lisp_Symbol:
3128 /* A symbol: process the value of the symbol recursively
3129 as if it appeared here directly. Avoid error if symbol void.
3130 Special case: if value of symbol is a string, output the string
3131 literally. */
3132 {
3133 register Lisp_Object tem;
3134 tem = Fboundp (elt);
3135 if (!NILP (tem))
3136 {
3137 tem = Fsymbol_value (elt);
3138 /* If value is a string, output that string literally:
3139 don't check for % within it. */
3140 if (STRINGP (tem))
3141 {
3142 if (frame_title_ptr)
3143 hpos = store_frame_title (XSTRING (tem)->data,
3144 minendcol, maxendcol);
3145 else
3146 hpos = display_string (w, vpos, XSTRING (tem)->data,
3147 XSTRING (tem)->size,
3148 hpos, 0, 1, minendcol, maxendcol);
3149 }
3150 /* Give up right away for nil or t. */
3151 else if (!EQ (tem, elt))
3152 { elt = tem; goto tail_recurse; }
3153 }
3154 }
3155 break;
3156
3157 case Lisp_Cons:
3158 {
3159 register Lisp_Object car, tem;
3160
3161 /* A cons cell: three distinct cases.
3162 If first element is a string or a cons, process all the elements
3163 and effectively concatenate them.
3164 If first element is a negative number, truncate displaying cdr to
3165 at most that many characters. If positive, pad (with spaces)
3166 to at least that many characters.
3167 If first element is a symbol, process the cadr or caddr recursively
3168 according to whether the symbol's value is non-nil or nil. */
3169 car = XCONS (elt)->car;
3170 if (SYMBOLP (car))
3171 {
3172 tem = Fboundp (car);
3173 elt = XCONS (elt)->cdr;
3174 if (!CONSP (elt))
3175 goto invalid;
3176 /* elt is now the cdr, and we know it is a cons cell.
3177 Use its car if CAR has a non-nil value. */
3178 if (!NILP (tem))
3179 {
3180 tem = Fsymbol_value (car);
3181 if (!NILP (tem))
3182 { elt = XCONS (elt)->car; goto tail_recurse; }
3183 }
3184 /* Symbol's value is nil (or symbol is unbound)
3185 Get the cddr of the original list
3186 and if possible find the caddr and use that. */
3187 elt = XCONS (elt)->cdr;
3188 if (NILP (elt))
3189 break;
3190 else if (!CONSP (elt))
3191 goto invalid;
3192 elt = XCONS (elt)->car;
3193 goto tail_recurse;
3194 }
3195 else if (INTEGERP (car))
3196 {
3197 register int lim = XINT (car);
3198 elt = XCONS (elt)->cdr;
3199 if (lim < 0)
3200 /* Negative int means reduce maximum width.
3201 DO NOT change MINENDCOL here!
3202 (20 -10 . foo) should truncate foo to 10 col
3203 and then pad to 20. */
3204 maxendcol = min (maxendcol, hpos - lim);
3205 else if (lim > 0)
3206 {
3207 /* Padding specified. Don't let it be more than
3208 current maximum. */
3209 lim += hpos;
3210 if (lim > maxendcol)
3211 lim = maxendcol;
3212 /* If that's more padding than already wanted, queue it.
3213 But don't reduce padding already specified even if
3214 that is beyond the current truncation point. */
3215 if (lim > minendcol)
3216 minendcol = lim;
3217 }
3218 goto tail_recurse;
3219 }
3220 else if (STRINGP (car) || CONSP (car))
3221 {
3222 register int limit = 50;
3223 /* LIMIT is to protect against circular lists. */
3224 while (CONSP (elt) && --limit > 0
3225 && hpos < maxendcol)
3226 {
3227 hpos = display_mode_element (w, vpos, hpos, depth,
3228 hpos, maxendcol,
3229 XCONS (elt)->car);
3230 elt = XCONS (elt)->cdr;
3231 }
3232 }
3233 }
3234 break;
3235
3236 default:
3237 invalid:
3238 if (frame_title_ptr)
3239 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3240 else
3241 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3242 minendcol, maxendcol);
3243 return hpos;
3244 }
3245
3246 if (minendcol > hpos)
3247 if (frame_title_ptr)
3248 hpos = store_frame_title ("", minendcol, maxendcol);
3249 else
3250 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
3251 return hpos;
3252 }
3253 \f
3254 /* Return a string for the output of a mode line %-spec for window W,
3255 generated by character C and width MAXWIDTH. */
3256
3257 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3258
3259 static char *
3260 decode_mode_spec (w, c, maxwidth)
3261 struct window *w;
3262 register char c;
3263 register int maxwidth;
3264 {
3265 Lisp_Object obj;
3266 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3267 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
3268 struct buffer *b = XBUFFER (w->buffer);
3269
3270 obj = Qnil;
3271 if (maxwidth > FRAME_WIDTH (f))
3272 maxwidth = FRAME_WIDTH (f);
3273
3274 switch (c)
3275 {
3276 case '*':
3277 if (!NILP (b->read_only))
3278 return "%";
3279 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3280 return "*";
3281 return "-";
3282
3283 case '+':
3284 /* This differs from %* only for a modified read-only buffer. */
3285 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3286 return "*";
3287 if (!NILP (b->read_only))
3288 return "%";
3289 return "-";
3290
3291 case '&':
3292 /* This differs from %* in ignoring read-only-ness. */
3293 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
3294 return "*";
3295 return "-";
3296
3297 case '%':
3298 return "%";
3299
3300 case '[':
3301 {
3302 int i;
3303 char *p;
3304
3305 if (command_loop_level > 5)
3306 return "[[[... ";
3307 p = decode_mode_spec_buf;
3308 for (i = 0; i < command_loop_level; i++)
3309 *p++ = '[';
3310 *p = 0;
3311 return decode_mode_spec_buf;
3312 }
3313
3314 case ']':
3315 {
3316 int i;
3317 char *p;
3318
3319 if (command_loop_level > 5)
3320 return " ...]]]";
3321 p = decode_mode_spec_buf;
3322 for (i = 0; i < command_loop_level; i++)
3323 *p++ = ']';
3324 *p = 0;
3325 return decode_mode_spec_buf;
3326 }
3327
3328 case '-':
3329 {
3330 register char *p;
3331 register int i;
3332
3333 if (maxwidth < sizeof (lots_of_dashes))
3334 return lots_of_dashes;
3335 else
3336 {
3337 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3338 *p++ = '-';
3339 *p = '\0';
3340 }
3341 return decode_mode_spec_buf;
3342 }
3343
3344 case 'b':
3345 obj = b->name;
3346 #if 0
3347 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
3348 {
3349 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
3350 decode_mode_spec_buf[maxwidth - 1] = '\\';
3351 decode_mode_spec_buf[maxwidth] = '\0';
3352 return decode_mode_spec_buf;
3353 }
3354 #endif
3355 break;
3356
3357 case 'c':
3358 {
3359 int col = current_column ();
3360 XSETFASTINT (w->column_number_displayed, col);
3361 sprintf (decode_mode_spec_buf, "%d", col);
3362 return decode_mode_spec_buf;
3363 }
3364
3365 case 'F':
3366 /* %F displays the frame name. */
3367 return (char *) XSTRING (selected_frame->name)->data;
3368
3369 case 'f':
3370 obj = b->filename;
3371 #if 0
3372 if (NILP (obj))
3373 return "[none]";
3374 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
3375 {
3376 bcopy ("...", decode_mode_spec_buf, 3);
3377 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
3378 decode_mode_spec_buf + 3, maxwidth - 3);
3379 return decode_mode_spec_buf;
3380 }
3381 #endif
3382 break;
3383
3384 case 'l':
3385 {
3386 int startpos = marker_position (w->start);
3387 int line, linepos, topline;
3388 int nlines, junk;
3389 Lisp_Object tem;
3390 int height = XFASTINT (w->height);
3391
3392 /* If we decided that this buffer isn't suitable for line numbers,
3393 don't forget that too fast. */
3394 if (EQ (w->base_line_pos, w->buffer))
3395 return "??";
3396
3397 /* If the buffer is very big, don't waste time. */
3398 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
3399 {
3400 w->base_line_pos = Qnil;
3401 w->base_line_number = Qnil;
3402 return "??";
3403 }
3404
3405 if (!NILP (w->base_line_number)
3406 && !NILP (w->base_line_pos)
3407 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
3408 {
3409 line = XFASTINT (w->base_line_number);
3410 linepos = XFASTINT (w->base_line_pos);
3411 }
3412 else
3413 {
3414 line = 1;
3415 linepos = BUF_BEGV (b);
3416 }
3417
3418 /* Count lines from base line to window start position. */
3419 nlines = display_count_lines (linepos, startpos, startpos, &junk);
3420
3421 topline = nlines + line;
3422
3423 /* Determine a new base line, if the old one is too close
3424 or too far away, or if we did not have one.
3425 "Too close" means it's plausible a scroll-down would
3426 go back past it. */
3427 if (startpos == BUF_BEGV (b))
3428 {
3429 XSETFASTINT (w->base_line_number, topline);
3430 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
3431 }
3432 else if (nlines < height + 25 || nlines > height * 3 + 50
3433 || linepos == BUF_BEGV (b))
3434 {
3435 int limit = BUF_BEGV (b);
3436 int position;
3437 int distance = (height * 2 + 30) * 200;
3438
3439 if (startpos - distance > limit)
3440 limit = startpos - distance;
3441
3442 nlines = display_count_lines (startpos, limit,
3443 -(height * 2 + 30),
3444 &position);
3445 /* If we couldn't find the lines we wanted within
3446 200 chars per line,
3447 give up on line numbers for this window. */
3448 if (position == startpos - distance)
3449 {
3450 w->base_line_pos = w->buffer;
3451 w->base_line_number = Qnil;
3452 return "??";
3453 }
3454
3455 XSETFASTINT (w->base_line_number, topline - nlines);
3456 XSETFASTINT (w->base_line_pos, position);
3457 }
3458
3459 /* Now count lines from the start pos to point. */
3460 nlines = display_count_lines (startpos, PT, PT, &junk);
3461
3462 /* Record that we did display the line number. */
3463 line_number_displayed = 1;
3464
3465 /* Make the string to show. */
3466 sprintf (decode_mode_spec_buf, "%d", topline + nlines);
3467 return decode_mode_spec_buf;
3468 }
3469 break;
3470
3471 case 'm':
3472 obj = b->mode_name;
3473 break;
3474
3475 case 'n':
3476 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
3477 return " Narrow";
3478 break;
3479
3480 case 'p':
3481 {
3482 int pos = marker_position (w->start);
3483 int total = BUF_ZV (b) - BUF_BEGV (b);
3484
3485 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
3486 {
3487 if (pos <= BUF_BEGV (b))
3488 return "All";
3489 else
3490 return "Bottom";
3491 }
3492 else if (pos <= BUF_BEGV (b))
3493 return "Top";
3494 else
3495 {
3496 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
3497 /* We can't normally display a 3-digit number,
3498 so get us a 2-digit number that is close. */
3499 if (total == 100)
3500 total = 99;
3501 sprintf (decode_mode_spec_buf, "%2d%%", total);
3502 return decode_mode_spec_buf;
3503 }
3504 }
3505
3506 /* Display percentage of size above the bottom of the screen. */
3507 case 'P':
3508 {
3509 int toppos = marker_position (w->start);
3510 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
3511 int total = BUF_ZV (b) - BUF_BEGV (b);
3512
3513 if (botpos >= BUF_ZV (b))
3514 {
3515 if (toppos <= BUF_BEGV (b))
3516 return "All";
3517 else
3518 return "Bottom";
3519 }
3520 else
3521 {
3522 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
3523 /* We can't normally display a 3-digit number,
3524 so get us a 2-digit number that is close. */
3525 if (total == 100)
3526 total = 99;
3527 if (toppos <= BUF_BEGV (b))
3528 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
3529 else
3530 sprintf (decode_mode_spec_buf, "%2d%%", total);
3531 return decode_mode_spec_buf;
3532 }
3533 }
3534
3535 case 's':
3536 /* status of process */
3537 obj = Fget_buffer_process (w->buffer);
3538 if (NILP (obj))
3539 return "no process";
3540 #ifdef subprocesses
3541 obj = Fsymbol_name (Fprocess_status (obj));
3542 #endif
3543 break;
3544
3545 case 't': /* indicate TEXT or BINARY */
3546 #ifdef MODE_LINE_BINARY_TEXT
3547 return MODE_LINE_BINARY_TEXT (b);
3548 #else
3549 return "T";
3550 #endif
3551 }
3552
3553 if (STRINGP (obj))
3554 return (char *) XSTRING (obj)->data;
3555 else
3556 return "";
3557 }
3558 \f
3559 /* Search for COUNT instances of a line boundary, which means either a
3560 newline or (if selective display enabled) a carriage return.
3561 Start at START. If COUNT is negative, search backwards.
3562
3563 If we find COUNT instances, set *SHORTAGE to zero, and return the
3564 position after the COUNTth match. Note that for reverse motion
3565 this is not the same as the usual convention for Emacs motion commands.
3566
3567 If we don't find COUNT instances before reaching the end of the
3568 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3569 the number of line boundaries left unfound, and return the end of the
3570 buffer we bumped up against. */
3571
3572 static int
3573 display_scan_buffer (start, count, shortage)
3574 int *shortage, start;
3575 register int count;
3576 {
3577 int limit = ((count > 0) ? ZV - 1 : BEGV);
3578 int direction = ((count > 0) ? 1 : -1);
3579
3580 register unsigned char *cursor;
3581 unsigned char *base;
3582
3583 register int ceiling;
3584 register unsigned char *ceiling_addr;
3585
3586 /* If we are not in selective display mode,
3587 check only for newlines. */
3588 if (! (!NILP (current_buffer->selective_display)
3589 && !INTEGERP (current_buffer->selective_display)))
3590 return scan_buffer ('\n', start, 0, count, shortage, 0);
3591
3592 /* The code that follows is like scan_buffer
3593 but checks for either newline or carriage return. */
3594
3595 if (shortage != 0)
3596 *shortage = 0;
3597
3598 if (count > 0)
3599 while (start != limit + 1)
3600 {
3601 ceiling = BUFFER_CEILING_OF (start);
3602 ceiling = min (limit, ceiling);
3603 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
3604 base = (cursor = &FETCH_CHAR (start));
3605 while (1)
3606 {
3607 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
3608 ;
3609 if (cursor != ceiling_addr)
3610 {
3611 if (--count == 0)
3612 {
3613 immediate_quit = 0;
3614 return (start + cursor - base + 1);
3615 }
3616 else
3617 if (++cursor == ceiling_addr)
3618 break;
3619 }
3620 else
3621 break;
3622 }
3623 start += cursor - base;
3624 }
3625 else
3626 {
3627 start--; /* first character we scan */
3628 while (start > limit - 1)
3629 { /* we WILL scan under start */
3630 ceiling = BUFFER_FLOOR_OF (start);
3631 ceiling = max (limit, ceiling);
3632 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
3633 base = (cursor = &FETCH_CHAR (start));
3634 cursor++;
3635 while (1)
3636 {
3637 while (--cursor != ceiling_addr
3638 && *cursor != '\n' && *cursor != 015)
3639 ;
3640 if (cursor != ceiling_addr)
3641 {
3642 if (++count == 0)
3643 {
3644 immediate_quit = 0;
3645 return (start + cursor - base + 1);
3646 }
3647 }
3648 else
3649 break;
3650 }
3651 start += cursor - base;
3652 }
3653 }
3654
3655 if (shortage != 0)
3656 *shortage = count * direction;
3657 return (start + ((direction == 1 ? 0 : 1)));
3658 }
3659
3660 /* Count up to N lines starting from FROM.
3661 But don't go beyond LIMIT.
3662 Return the number of lines thus found (always positive).
3663 Store the position after what was found into *POS_PTR. */
3664
3665 static int
3666 display_count_lines (from, limit, n, pos_ptr)
3667 int from, limit, n;
3668 int *pos_ptr;
3669 {
3670 int oldbegv = BEGV;
3671 int oldzv = ZV;
3672 int shortage = 0;
3673
3674 if (limit < from)
3675 BEGV = limit;
3676 else
3677 ZV = limit;
3678
3679 *pos_ptr = display_scan_buffer (from, n, &shortage);
3680
3681 ZV = oldzv;
3682 BEGV = oldbegv;
3683
3684 if (n < 0)
3685 /* When scanning backwards, scan_buffer stops *after* the last newline
3686 it finds, but does count it. Compensate for that. */
3687 return - n - shortage - (*pos_ptr != limit);
3688 return n - shortage;
3689 }
3690 \f
3691 /* Display STRING on one line of window W, starting at HPOS.
3692 Display at position VPOS. Caller should have done get_display_line.
3693 If VPOS == -1, display it as the current frame's title.
3694 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
3695
3696 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
3697
3698 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
3699 MAXCOL is the last column ok to end at. Truncate here.
3700 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
3701 Both count from the left edge of the frame, as does HPOS.
3702 The right edge of W is an implicit maximum.
3703 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
3704
3705 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
3706 at the place where the current window ends in this line
3707 and not display anything beyond there. Otherwise, only MAXCOL
3708 controls where to stop output.
3709
3710 Returns ending hpos. */
3711
3712 static int
3713 display_string (w, vpos, string, length, hpos, truncate,
3714 obey_window_width, mincol, maxcol)
3715 struct window *w;
3716 unsigned char *string;
3717 int length;
3718 int vpos, hpos;
3719 GLYPH truncate;
3720 int obey_window_width;
3721 int mincol, maxcol;
3722 {
3723 register int c;
3724 register GLYPH *p1;
3725 int hscroll = XINT (w->hscroll);
3726 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
3727 register GLYPH *start;
3728 register GLYPH *end;
3729 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3730 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
3731 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
3732 int window_width = XFASTINT (w->width);
3733
3734 /* Use the standard display table, not the window's display table.
3735 We don't want the mode line in rot13. */
3736 register struct Lisp_Vector *dp = 0;
3737 int i;
3738
3739 if (VECTORP (Vstandard_display_table)
3740 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
3741 dp = XVECTOR (Vstandard_display_table);
3742
3743 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
3744
3745 p1 = p1start;
3746 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
3747
3748 if (obey_window_width)
3749 {
3750 end = start + window_width - (truncate != 0);
3751
3752 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
3753 {
3754 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3755 {
3756 int i;
3757
3758 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3759 *end-- = ' ';
3760 }
3761 else
3762 *end-- = '|';
3763 }
3764 }
3765
3766 if (! obey_window_width
3767 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
3768 end = desired_glyphs->glyphs[vpos] + maxcol;
3769
3770 /* Store 0 in charstart for these columns. */
3771 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
3772 desired_glyphs->charstarts[vpos][i] = 0;
3773
3774 if (maxcol >= 0 && mincol > maxcol)
3775 mincol = maxcol;
3776
3777 while (p1 < end)
3778 {
3779 if (length == 0)
3780 break;
3781 c = *string++;
3782 /* Specified length. */
3783 if (length >= 0)
3784 length--;
3785 /* Unspecified length (null-terminated string). */
3786 else if (c == 0)
3787 break;
3788
3789 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3790 {
3791 p1 = copy_part_of_rope (f, p1, start,
3792 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3793 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3794 0);
3795 }
3796 else if (c >= 040 && c < 0177)
3797 {
3798 if (p1 >= start)
3799 *p1 = c;
3800 p1++;
3801 }
3802 else if (c == '\t')
3803 {
3804 do
3805 {
3806 if (p1 >= start && p1 < end)
3807 *p1 = SPACEGLYPH;
3808 p1++;
3809 }
3810 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
3811 }
3812 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
3813 {
3814 if (p1 >= start)
3815 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
3816 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3817 0);
3818 p1++;
3819 if (p1 >= start && p1 < end)
3820 *p1 = c ^ 0100;
3821 p1++;
3822 }
3823 else
3824 {
3825 if (p1 >= start)
3826 *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
3827 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3828 0);
3829 p1++;
3830 if (p1 >= start && p1 < end)
3831 *p1 = (c >> 6) + '0';
3832 p1++;
3833 if (p1 >= start && p1 < end)
3834 *p1 = (7 & (c >> 3)) + '0';
3835 p1++;
3836 if (p1 >= start && p1 < end)
3837 *p1 = (7 & c) + '0';
3838 p1++;
3839 }
3840 }
3841
3842 if (c && length > 0)
3843 {
3844 p1 = end;
3845 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
3846 }
3847 else if (mincol >= 0)
3848 {
3849 end = desired_glyphs->glyphs[vpos] + mincol;
3850 while (p1 < end)
3851 *p1++ = SPACEGLYPH;
3852 }
3853
3854 {
3855 register int len = p1 - desired_glyphs->glyphs[vpos];
3856
3857 if (len > desired_glyphs->used[vpos])
3858 desired_glyphs->used[vpos] = len;
3859 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3860
3861 return len;
3862 }
3863 }
3864 \f
3865 /* This is like a combination of memq and assq.
3866 Return 1 if PROPVAL appears as an element of LIST
3867 or as the car of an element of LIST.
3868 If PROPVAL is a list, compare each element against LIST
3869 in that way, and return 1 if any element of PROPVAL is found in LIST.
3870 Otherwise return 0.
3871 This function cannot quit. */
3872
3873 int
3874 invisible_p (propval, list)
3875 register Lisp_Object propval;
3876 Lisp_Object list;
3877 {
3878 register Lisp_Object tail, proptail;
3879 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3880 {
3881 register Lisp_Object tem;
3882 tem = XCONS (tail)->car;
3883 if (EQ (propval, tem))
3884 return 1;
3885 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
3886 return 1;
3887 }
3888 if (CONSP (propval))
3889 for (proptail = propval; CONSP (proptail);
3890 proptail = XCONS (proptail)->cdr)
3891 {
3892 Lisp_Object propelt;
3893 propelt = XCONS (proptail)->car;
3894 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3895 {
3896 register Lisp_Object tem;
3897 tem = XCONS (tail)->car;
3898 if (EQ (propelt, tem))
3899 return 1;
3900 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
3901 return 1;
3902 }
3903 }
3904 return 0;
3905 }
3906
3907 /* Return 1 if PROPVAL appears as the car of an element of LIST
3908 and the cdr of that element is non-nil.
3909 If PROPVAL is a list, check each element of PROPVAL in that way,
3910 and the first time some element is found,
3911 return 1 if the cdr of that element is non-nil.
3912 Otherwise return 0.
3913 This function cannot quit. */
3914
3915 int
3916 invisible_ellipsis_p (propval, list)
3917 register Lisp_Object propval;
3918 Lisp_Object list;
3919 {
3920 register Lisp_Object tail, proptail;
3921 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3922 {
3923 register Lisp_Object tem;
3924 tem = XCONS (tail)->car;
3925 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
3926 return ! NILP (XCONS (tem)->cdr);
3927 }
3928 if (CONSP (propval))
3929 for (proptail = propval; CONSP (proptail);
3930 proptail = XCONS (proptail)->cdr)
3931 {
3932 Lisp_Object propelt;
3933 propelt = XCONS (proptail)->car;
3934 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
3935 {
3936 register Lisp_Object tem;
3937 tem = XCONS (tail)->car;
3938 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
3939 return ! NILP (XCONS (tem)->cdr);
3940 }
3941 }
3942 return 0;
3943 }
3944 \f
3945 void
3946 syms_of_xdisp ()
3947 {
3948 staticpro (&Qmenu_bar_update_hook);
3949 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
3950
3951 staticpro (&last_arrow_position);
3952 staticpro (&last_arrow_string);
3953 last_arrow_position = Qnil;
3954 last_arrow_string = Qnil;
3955
3956 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
3957 "String (or mode line construct) included (normally) in `mode-line-format'.");
3958 Vglobal_mode_string = Qnil;
3959
3960 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
3961 "Marker for where to display an arrow on top of the buffer text.\n\
3962 This must be the beginning of a line in order to work.\n\
3963 See also `overlay-arrow-string'.");
3964 Voverlay_arrow_position = Qnil;
3965
3966 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
3967 "String to display as an arrow. See also `overlay-arrow-position'.");
3968 Voverlay_arrow_string = Qnil;
3969
3970 DEFVAR_INT ("scroll-step", &scroll_step,
3971 "*The number of lines to try scrolling a window by when point moves out.\n\
3972 If that fails to bring point back on frame, point is centered instead.\n\
3973 If this is zero, point is always centered after it moves off frame.");
3974
3975 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
3976
3977 DEFVAR_BOOL ("truncate-partial-width-windows",
3978 &truncate_partial_width_windows,
3979 "*Non-nil means truncate lines in all windows less than full frame wide.");
3980 truncate_partial_width_windows = 1;
3981
3982 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
3983 "*Non-nil means use inverse video for the mode line.");
3984 mode_line_inverse_video = 1;
3985
3986 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
3987 "*Maximum buffer size for which line number should be displayed.");
3988 line_number_display_limit = 1000000;
3989
3990 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
3991 "*Non-nil means highlight region even in nonselected windows.");
3992 highlight_nonselected_windows = 1;
3993
3994 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
3995 "Non-nil means more than one frame is in use, not counting minibuffer frames.\n\
3996 Not guaranteed to be accurate except while parsing frame-title-format.");
3997
3998 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
3999 "Template for displaying the titlebar of visible frames.\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 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
4005 "Template for displaying the titlebar of an iconified frame.\n\
4006 \(Assuming the window manager supports this feature.)\n\
4007 This variable has the same structure as `mode-line-format' (which see),\n\
4008 and is used only on frames for which no explicit name has been set\n\
4009 \(see `modify-frame-parameters').");
4010 Vicon_title_format
4011 = Vframe_title_format
4012 = Fcons (intern ("multiple-frames"),
4013 Fcons (build_string ("%b"),
4014 Fcons (Fcons (build_string (""),
4015 Fcons (intern ("invocation-name"),
4016 Fcons (build_string ("@"),
4017 Fcons (intern ("system-name"),
4018 Qnil)))),
4019 Qnil)));
4020
4021 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
4022 "Maximum number of lines to keep in the message log buffer.\n\
4023 If nil, disable message logging. If t, log messages but don't truncate\n\
4024 the buffer when it becomes large.");
4025 XSETFASTINT (Vmessage_log_max, 50);
4026
4027 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
4028 "Functions called before redisplay, if window sizes have changed.\n\
4029 The value should be a list of functions that take one argument.\n\
4030 Just before redisplay, for each frame, if any of its windows have changed\n\
4031 size since the last redisplay, or have been split or deleted,\n\
4032 all the functions in the list are called, with the frame as argument.");
4033 Vwindow_size_change_functions = Qnil;
4034 }
4035
4036 /* initialize the window system */
4037 init_xdisp ()
4038 {
4039 Lisp_Object root_window;
4040 #ifndef COMPILER_REGISTER_BUG
4041 register
4042 #endif /* COMPILER_REGISTER_BUG */
4043 struct window *mini_w;
4044
4045 this_line_bufpos = 0;
4046
4047 mini_w = XWINDOW (minibuf_window);
4048 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
4049
4050 echo_area_glyphs = 0;
4051 previous_echo_glyphs = 0;
4052
4053 if (!noninteractive)
4054 {
4055 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
4056 XSETFASTINT (XWINDOW (root_window)->top, 0);
4057 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
4058 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
4059 set_window_height (minibuf_window, 1, 0);
4060
4061 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
4062 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));
4063 }
4064 }