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