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