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