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