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