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