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