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