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