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