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