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