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.
5 This file is part of GNU Emacs.
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)
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.
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. */
25 /*#include <ctype.h>*/
31 #include "dispextern.h"
38 #include "termhooks.h"
39 #include "intervals.h"
43 #include "region-cache.h"
49 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
50 extern void set_frame_menubar ();
51 extern int pending_menu_activation
;
54 extern int interrupt_input
;
55 extern int command_loop_level
;
57 extern int minibuffer_auto_raise
;
59 extern Lisp_Object Qface
;
61 extern Lisp_Object Voverriding_local_map
;
62 extern Lisp_Object Voverriding_local_map_menu_flag
;
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
;
69 /* Non-nil means don't actually do any redisplay. */
71 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
73 /* Nonzero means print newline to stdout before next minibuffer message. */
75 int noninteractive_need_newline
;
77 /* Nonzero means print newline to message log before next message. */
79 static int message_log_need_newline
;
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))
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
;
91 /* Number of characters past the end of this line,
92 including the terminating newline */
93 static int this_line_endpos
;
95 /* The vertical position of this frame line. */
96 static int this_line_vpos
;
98 /* Hpos value for start of display on this frame line.
99 Usually zero, but negative if first character really began
101 static int this_line_start_hpos
;
103 /* Buffer that this_line variables are describing. */
104 static struct buffer
*this_line_buffer
;
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
;
112 /* Nonzero means truncate lines in all windows less wide than the frame */
113 int truncate_partial_width_windows
;
115 /* Nonzero means we have more than one non-minibuffer-only frame.
116 Not guaranteed to be accurate except while parsing frame-title-format. */
119 Lisp_Object Vglobal_mode_string
;
121 /* Marker for where to display an arrow on top of the buffer text. */
122 Lisp_Object Voverlay_arrow_position
;
124 /* String to display for the arrow. */
125 Lisp_Object Voverlay_arrow_string
;
127 /* Values of those variables at last redisplay.
128 However, if Voverlay_arrow_position is a marker,
129 last_arrow_position is its numerical position. */
130 static Lisp_Object last_arrow_position
, last_arrow_string
;
132 /* Like mode-line-format, but for the titlebar on a visible frame. */
133 Lisp_Object Vframe_title_format
;
135 /* Like mode-line-format, but for the titlebar on an iconified frame. */
136 Lisp_Object Vicon_title_format
;
138 /* List of functions to call when a window's size changes. These
139 functions get one arg, a frame on which one or more windows' sizes
141 static Lisp_Object Vwindow_size_change_functions
;
143 Lisp_Object Qmenu_bar_update_hook
;
145 /* Nonzero if overlay arrow has been displayed once in this window. */
146 static int overlay_arrow_seen
;
148 /* Nonzero if visible end of buffer has already been displayed once
149 in this window. (We need this variable in case there are overlay
150 strings that get displayed there.) */
151 static int zv_strings_seen
;
153 /* Nonzero means highlight the region even in nonselected windows. */
154 static int highlight_nonselected_windows
;
156 /* If cursor motion alone moves point off frame,
157 Try scrolling this many lines up or down if that will bring it back. */
158 static int scroll_step
;
160 /* Non-0 means scroll just far enough to bring point back on the screen,
162 static int scroll_conservatively
;
164 /* Recenter the window whenever point gets within this many lines
165 of the top or bottom of the window. */
168 /* Number of characters of overlap to show,
169 when scrolling a one-line window such as a minibuffer. */
170 static int minibuffer_scroll_overlap
;
172 /* Nonzero if try_window_id has made blank lines at window bottom
173 since the last redisplay that paused */
174 static int blank_end_of_window
;
176 /* Number of windows showing the buffer of the selected window
177 (or another buffer with the same base buffer).
178 keyboard.c refers to this. */
181 /* display_text_line sets these to the frame position (origin 0) of point,
182 whether the window is selected or not.
183 Set one to -1 first to determine whether point was found afterwards. */
185 static int cursor_vpos
;
186 static int cursor_hpos
;
188 static int debug_end_pos
;
190 /* Nonzero means display mode line highlighted */
191 int mode_line_inverse_video
;
193 static void redisplay_internal ();
194 static int message_log_check_duplicate ();
195 static void echo_area_display ();
196 void mark_window_display_accurate ();
197 static void redisplay_windows ();
198 static void redisplay_window ();
199 static void update_menu_bar ();
200 static void try_window ();
201 static int try_window_id ();
202 static struct position
*display_text_line ();
203 static void display_mode_line ();
204 static int display_mode_element ();
205 static char *decode_mode_spec ();
206 static int display_string ();
207 static void display_menu_bar ();
208 static int display_count_lines ();
210 /* Prompt to display in front of the minibuffer contents */
211 Lisp_Object minibuf_prompt
;
213 /* Width in columns of current minibuffer prompt. */
214 int minibuf_prompt_width
;
216 /* Message to display instead of minibuffer contents
217 This is what the functions error and message make,
218 and command echoing uses it as well.
219 It overrides the minibuf_prompt as well as the buffer. */
220 char *echo_area_glyphs
;
222 /* This is the length of the message in echo_area_glyphs. */
223 int echo_area_glyphs_length
;
225 /* This is the window where the echo area message was displayed.
226 It is always a minibuffer window, but it may not be the
227 same window currently active as a minibuffer. */
228 Lisp_Object echo_area_window
;
230 /* Nonzero means multibyte characters were enabled when the echo area
231 message was specified. */
232 int message_enable_multibyte
;
234 /* true iff we should redraw the mode lines on the next redisplay */
235 int update_mode_lines
;
237 /* Smallest number of characters before the gap
238 at any time since last redisplay that finished.
239 Valid for current buffer when try_window_id can be called. */
242 /* Smallest number of characters after the gap
243 at any time since last redisplay that finished.
244 Valid for current buffer when try_window_id can be called. */
247 /* MODIFF as of last redisplay that finished;
248 if it matches MODIFF, and overlay_unchanged_modified
249 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
250 contain no useful information */
251 int unchanged_modified
;
253 /* OVERLAY_MODIFF as of last redisplay that finished. */
254 int overlay_unchanged_modified
;
256 /* Nonzero if window sizes or contents have changed
257 since last redisplay that finished */
258 int windows_or_buffers_changed
;
260 /* Nonzero after display_mode_line if %l was used
261 and it displayed a line number. */
262 int line_number_displayed
;
264 /* Maximum buffer size for which to display line numbers. */
265 static int line_number_display_limit
;
267 /* Number of lines to keep in the message log buffer.
268 t means infinite. nil means don't log at all. */
269 Lisp_Object Vmessage_log_max
;
271 #define COERCE_MARKER(X) \
272 (MARKERP ((X)) ? Fmarker_position (X) : (X))
274 static int pos_tab_offset
P_ ((struct window
*, int, int));
276 /* Output a newline in the *Messages* buffer if "needs" one. */
279 message_log_maybe_newline ()
281 if (message_log_need_newline
)
282 message_dolog ("", 0, 1, 0);
286 /* Add a string to the message log, optionally terminated with a newline.
287 This function calls low-level routines in order to bypass text property
288 hooks, etc. which might not be safe to run.
289 MULTIBYTE, if nonzero, means interpret the contents of M as multibyte. */
292 message_dolog (m
, len
, nlflag
, multibyte
)
294 int len
, nlflag
, multibyte
;
296 if (!NILP (Vmessage_log_max
))
298 struct buffer
*oldbuf
;
299 Lisp_Object oldpoint
, oldbegv
, oldzv
;
300 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
301 int point_at_end
= 0;
303 Lisp_Object old_deactivate_mark
, tem
;
304 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
306 old_deactivate_mark
= Vdeactivate_mark
;
307 oldbuf
= current_buffer
;
308 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
309 current_buffer
->undo_list
= Qt
;
311 oldpoint
= Fpoint_marker ();
312 oldbegv
= Fpoint_min_marker ();
313 oldzv
= Fpoint_max_marker ();
314 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
322 BEGV_BYTE
= BEG_BYTE
;
325 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
327 /* Insert the string--maybe converting multibyte to single byte
328 or vice versa, so that all the text fits the buffer. */
330 && NILP (current_buffer
->enable_multibyte_characters
))
333 unsigned char work
[1];
334 /* Convert a multibyte string to single-byte
335 for the *Message* buffer. */
336 for (i
= 0; i
< len
; i
+= nbytes
)
338 c
= STRING_CHAR_AND_LENGTH (m
+ i
, len
- i
, nbytes
);
339 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
341 : multibyte_char_to_unibyte (c
, Qnil
));
342 insert_1_both (work
, 1, 1, 1, 0, 0);
346 && ! NILP (current_buffer
->enable_multibyte_characters
))
349 unsigned char *msg
= (unsigned char *) m
;
350 unsigned char *str
, work
[4];
351 /* Convert a single-byte string to multibyte
352 for the *Message* buffer. */
353 for (i
= 0; i
< len
; i
++)
355 c
= unibyte_char_to_multibyte (msg
[i
]);
356 nbytes
= CHAR_STRING (c
, work
, str
);
357 insert_1_both (work
, 1, nbytes
, 1, 0, 0);
361 insert_1 (m
, len
, 1, 0, 0);
365 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
366 insert_1 ("\n", 1, 1, 0, 0);
368 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
370 this_bol_byte
= PT_BYTE
;
374 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
376 prev_bol_byte
= PT_BYTE
;
378 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
379 this_bol
, this_bol_byte
);
382 del_range_both (prev_bol
, prev_bol_byte
,
383 this_bol
, this_bol_byte
, 0);
389 /* If you change this format, don't forget to also
390 change message_log_check_duplicate. */
391 sprintf (dupstr
, " [%d times]", dup
);
392 duplen
= strlen (dupstr
);
393 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
394 insert_1 (dupstr
, duplen
, 1, 0, 1);
399 if (NATNUMP (Vmessage_log_max
))
401 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
402 -XFASTINT (Vmessage_log_max
) - 1, 0);
403 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
406 BEGV
= XMARKER (oldbegv
)->charpos
;
407 BEGV_BYTE
= marker_byte_position (oldbegv
);
416 ZV
= XMARKER (oldzv
)->charpos
;
417 ZV_BYTE
= marker_byte_position (oldzv
);
421 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
423 /* We can't do Fgoto_char (oldpoint) because it will run some
425 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
426 XMARKER (oldpoint
)->bytepos
);
429 free_marker (oldpoint
);
430 free_marker (oldbegv
);
433 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
434 set_buffer_internal (oldbuf
);
436 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
437 message_log_need_newline
= !nlflag
;
438 Vdeactivate_mark
= old_deactivate_mark
;
442 /* We are at the end of the buffer after just having inserted a newline.
443 (Note: We depend on the fact we won't be crossing the gap.)
444 Check to see if the most recent message looks a lot like the previous one.
445 Return 0 if different, 1 if the new one should just replace it, or a
446 value N > 1 if we should also append " [N times]". */
449 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
450 int prev_bol
, this_bol
;
451 int prev_bol_byte
, this_bol_byte
;
454 int len
= Z_BYTE
- 1 - this_bol_byte
;
456 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
457 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
459 for (i
= 0; i
< len
; i
++)
461 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
470 if (*p1
++ == ' ' && *p1
++ == '[')
473 while (*p1
>= '0' && *p1
<= '9')
474 n
= n
* 10 + *p1
++ - '0';
475 if (strncmp (p1
, " times]\n", 8) == 0)
481 /* Display an echo area message M with a specified length of LEN chars.
482 The string may include null characters. If M is 0, clear out any
483 existing message, and let the minibuffer text show through.
485 The buffer M must continue to exist until after the echo area
486 gets cleared or some other message gets displayed there.
488 Do not pass text that is stored in a Lisp string.
489 Do not pass text in a buffer that was alloca'd. */
492 message2 (m
, len
, multibyte
)
497 /* First flush out any partial line written with print. */
498 message_log_maybe_newline ();
500 message_dolog (m
, len
, 1, multibyte
);
501 message2_nolog (m
, len
, multibyte
);
505 /* The non-logging counterpart of message2. */
508 message2_nolog (m
, len
, multibyte
)
512 message_enable_multibyte
= multibyte
;
516 if (noninteractive_need_newline
)
518 noninteractive_need_newline
= 0;
520 fwrite (m
, len
, 1, stderr
);
521 if (cursor_in_echo_area
== 0)
522 fprintf (stderr
, "\n");
525 /* A null message buffer means that the frame hasn't really been
526 initialized yet. Error messages get reported properly by
527 cmd_error, so this must be just an informative message; toss it. */
528 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
530 Lisp_Object mini_window
;
533 /* Get the frame containing the minibuffer
534 that the selected frame is using. */
535 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
536 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
538 FRAME_SAMPLE_VISIBILITY (f
);
539 if (FRAME_VISIBLE_P (selected_frame
)
540 && ! FRAME_VISIBLE_P (f
))
541 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
545 echo_area_glyphs
= m
;
546 echo_area_glyphs_length
= len
;
548 if (minibuffer_auto_raise
)
549 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
552 echo_area_glyphs
= previous_echo_glyphs
= 0;
554 do_pending_window_change ();
555 echo_area_display ();
556 update_frame (f
, 1, 1);
557 do_pending_window_change ();
558 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
559 (*frame_up_to_date_hook
) (f
);
563 /* Display in echo area the null-terminated ASCII-only string M.
564 If M is 0, clear out any existing message,
565 and let the minibuffer text show through.
567 The string M must continue to exist until after the echo area
568 gets cleared or some other message gets displayed there.
570 Do not pass text that is stored in a Lisp string.
571 Do not pass text in a buffer that was alloca'd. */
577 message2 (m
, (m
? strlen (m
) : 0), 0);
584 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
587 /* Display a message M which contains a single %s
588 which gets replaced with STRING. */
591 message_with_string (m
, string
, log
)
600 if (noninteractive_need_newline
)
602 noninteractive_need_newline
= 0;
603 fprintf (stderr
, m
, XSTRING (string
)->data
);
604 if (cursor_in_echo_area
== 0)
605 fprintf (stderr
, "\n");
609 else if (INTERACTIVE
)
611 /* The frame whose minibuffer we're going to display the message on.
612 It may be larger than the selected frame, so we need
613 to use its buffer, not the selected frame's buffer. */
614 Lisp_Object mini_window
;
617 /* Get the frame containing the minibuffer
618 that the selected frame is using. */
619 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
620 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
622 /* A null message buffer means that the frame hasn't really been
623 initialized yet. Error messages get reported properly by
624 cmd_error, so this must be just an informative message; toss it. */
625 if (FRAME_MESSAGE_BUF (f
))
629 a
[0] = (char *) XSTRING (string
)->data
;
631 len
= doprnt (FRAME_MESSAGE_BUF (f
),
632 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
635 message2 (FRAME_MESSAGE_BUF (f
), len
,
636 STRING_MULTIBYTE (string
));
638 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
639 STRING_MULTIBYTE (string
));
641 /* Print should start at the beginning of the message
643 message_buf_print
= 0;
648 /* Truncate what will be displayed in the echo area
649 the next time we display it--but don't redisplay it now. */
652 truncate_echo_area (len
)
655 /* A null message buffer means that the frame hasn't really been
656 initialized yet. Error messages get reported properly by
657 cmd_error, so this must be just an informative message; toss it. */
658 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
659 echo_area_glyphs_length
= len
;
662 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
663 zero if being used by message. */
664 int message_buf_print
;
666 /* Dump an informative message to the minibuf. If M is 0, clear out
667 any existing message, and let the minibuffer text show through. */
671 message (m
, a1
, a2
, a3
)
673 EMACS_INT a1
, a2
, a3
;
679 if (noninteractive_need_newline
)
681 noninteractive_need_newline
= 0;
682 fprintf (stderr
, m
, a1
, a2
, a3
);
683 if (cursor_in_echo_area
== 0)
684 fprintf (stderr
, "\n");
688 else if (INTERACTIVE
)
690 /* The frame whose minibuffer we're going to display the message on.
691 It may be larger than the selected frame, so we need
692 to use its buffer, not the selected frame's buffer. */
693 Lisp_Object mini_window
;
696 /* Get the frame containing the minibuffer
697 that the selected frame is using. */
698 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
699 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
701 /* A null message buffer means that the frame hasn't really been
702 initialized yet. Error messages get reported properly by
703 cmd_error, so this must be just an informative message; toss it. */
704 if (FRAME_MESSAGE_BUF (f
))
715 len
= doprnt (FRAME_MESSAGE_BUF (f
),
716 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
718 len
= doprnt (FRAME_MESSAGE_BUF (f
),
719 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
721 #endif /* NO_ARG_ARRAY */
723 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
728 /* Print should start at the beginning of the message
730 message_buf_print
= 0;
735 /* The non-logging version of message. */
737 message_nolog (m
, a1
, a2
, a3
)
739 EMACS_INT a1
, a2
, a3
;
741 Lisp_Object old_log_max
;
742 old_log_max
= Vmessage_log_max
;
743 Vmessage_log_max
= Qnil
;
744 message (m
, a1
, a2
, a3
);
745 Vmessage_log_max
= old_log_max
;
751 message2 (echo_area_glyphs
, echo_area_glyphs_length
,
752 ! NILP (current_buffer
->enable_multibyte_characters
));
760 Lisp_Object mini_window
;
762 /* Choose the minibuffer window for this display.
763 It is the minibuffer window used by the selected frame. */
764 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
765 /* This is the frame that window is in. */
766 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
768 if (! FRAME_VISIBLE_P (f
))
773 redraw_garbaged_frames ();
777 if (echo_area_glyphs
|| minibuf_level
== 0)
781 echo_area_window
= mini_window
;
783 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
784 get_display_line (f
, vpos
, 0);
786 /* Make sure the columns that overlap a left-hand scroll bar
788 for (i
= 0; i
< FRAME_LEFT_SCROLL_BAR_WIDTH (f
); i
++)
789 f
->desired_glyphs
->glyphs
[vpos
][i
] = SPACEGLYPH
;
791 display_string (XWINDOW (mini_window
), vpos
,
792 echo_area_glyphs
? echo_area_glyphs
: "",
793 echo_area_glyphs
? echo_area_glyphs_length
: -1,
794 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
796 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
797 message_enable_multibyte
);
799 #if 0 /* This just gets in the way. update_frame does the job. */
800 /* If desired cursor location is on this line, put it at end of text */
801 if (cursor_in_echo_area
)
802 FRAME_CURSOR_Y (f
) = vpos
;
803 if (FRAME_CURSOR_Y (f
) == vpos
)
804 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
807 /* Fill the rest of the minibuffer window with blank lines. */
812 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
814 get_display_line (f
, i
, 0);
815 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
816 hpos, because it is good to clear whatever is behind the
817 scroll bar. This does not affect the scroll bar itself. */
818 display_string (XWINDOW (mini_window
), i
,
821 0, FRAME_WIDTH (f
) + FRAME_SCROLL_BAR_WIDTH (f
),
826 else if (!EQ (mini_window
, selected_window
))
827 windows_or_buffers_changed
++;
829 if (EQ (mini_window
, selected_window
))
830 this_line_bufpos
= 0;
832 previous_echo_glyphs
= echo_area_glyphs
;
835 /* Update frame titles. */
837 #ifdef HAVE_WINDOW_SYSTEM
838 static char frame_title_buf
[512];
839 static char *frame_title_ptr
;
842 store_frame_title (str
, mincol
, maxcol
)
847 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
848 maxcol
= sizeof (frame_title_buf
);
849 limit
= &frame_title_buf
[maxcol
];
850 while (*str
!= '\0' && frame_title_ptr
< limit
)
851 *frame_title_ptr
++ = *str
++;
852 while (frame_title_ptr
< &frame_title_buf
[mincol
])
853 *frame_title_ptr
++ = ' ';
854 return frame_title_ptr
- frame_title_buf
;
858 x_consider_frame_title (frame
)
864 FRAME_PTR f
= XFRAME (frame
);
866 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
869 /* Do we have more than one visible frame on this X display? */
873 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
875 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
877 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
878 && !FRAME_MINIBUF_ONLY_P (tf
)
879 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
883 multiple_frames
= CONSP (tail
);
886 obuf
= current_buffer
;
887 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
888 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
889 frame_title_ptr
= frame_title_buf
;
890 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
891 0, sizeof (frame_title_buf
), fmt
);
893 set_buffer_internal (obuf
);
894 /* Set the name only if it's changed. This avoids consing
895 in the common case where it hasn't. (If it turns out that we've
896 already wasted too much time by walking through the list with
897 display_mode_element, then we might need to optimize at a higher
899 if (! STRINGP (f
->name
) || STRING_BYTES (XSTRING (f
->name
)) != len
900 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
901 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
904 #define frame_title_ptr ((char *)0)
905 #define store_frame_title(str, mincol, maxcol) 0
908 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
909 This can call eval. */
914 register struct window
*w
= XWINDOW (selected_window
);
916 struct gcpro gcpro1
, gcpro2
;
918 all_windows
= (update_mode_lines
|| buffer_shared
> 1
919 || windows_or_buffers_changed
);
921 /* Update all frame titles based on their buffer names, etc.
922 We do this before the menu bars so that the buffer-menu
923 will show the up-to-date frame titles.
925 This used to be done after the menu bars, for a reason that
926 was stated as follows but which I do not understand:
927 "We do this after the menu bars so that the frame will first
928 create its menu bar using the name `emacs' if no other name
929 has yet been specified."
930 I think that is no longer a concern. */
931 #ifdef HAVE_WINDOW_SYSTEM
932 if (windows_or_buffers_changed
|| update_mode_lines
)
934 Lisp_Object tail
, frame
;
936 FOR_EACH_FRAME (tail
, frame
)
937 if (FRAME_VISIBLE_P (XFRAME (frame
))
938 || FRAME_ICONIFIED_P (XFRAME (frame
)))
939 x_consider_frame_title (frame
);
943 /* Update the menu bar item lists, if appropriate.
944 This has to be done before any actual redisplay
945 or generation of display lines. */
948 Lisp_Object tail
, frame
;
949 int count
= specpdl_ptr
- specpdl
;
951 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
953 FOR_EACH_FRAME (tail
, frame
)
955 /* If a window on this frame changed size,
956 report that to the user and clear the size-change flag. */
957 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
959 Lisp_Object functions
;
960 /* Clear flag first in case we get error below. */
961 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
962 functions
= Vwindow_size_change_functions
;
963 GCPRO2 (tail
, functions
);
964 while (CONSP (functions
))
966 call1 (XCONS (functions
)->car
, frame
);
967 functions
= XCONS (functions
)->cdr
;
972 update_menu_bar (XFRAME (frame
), 0);
976 unbind_to (count
, Qnil
);
979 update_menu_bar (selected_frame
, 1);
981 /* Motif needs this. See comment in xmenu.c.
982 Turn it off when pending_menu_activation is not defined. */
984 pending_menu_activation
= 0;
988 /* Do a frame update, taking possible shortcuts into account.
989 This is the main external entry point for redisplay.
991 If the last redisplay displayed an echo area message and that
992 message is no longer requested, we clear the echo area
993 or bring back the minibuffer if that is in use.
995 Do not call eval from within this function.
996 Calls to eval after the call to echo_area_display would confuse
997 the display_line mechanism and would cause a crash.
998 Calls to eval before that point will work most of the time,
999 but can still lose, because this function
1000 can be called from signal handlers; with alarms set up;
1001 or with synchronous processes running.
1003 See Fcall_process; if you called it from here, it could be
1004 entered recursively. */
1006 static int do_verify_charstarts
;
1008 /* Counter is used to clear the face cache
1009 no more than once ever 1000 redisplays. */
1010 static int clear_face_cache_count
;
1012 /* Record the previous terminal frame we displayed. */
1013 static FRAME_PTR previous_terminal_frame
;
1018 redisplay_internal (0);
1021 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
1022 is not in response to any user action; therefore, we should
1023 preserve the echo area. (Actually, our caller does that job.)
1024 Perhaps in the future avoid recentering windows
1025 if it is not necessary; currently that causes some problems. */
1028 redisplay_internal (preserve_echo_area
)
1029 int preserve_echo_area
;
1031 register struct window
*w
= XWINDOW (selected_window
);
1033 int must_finish
= 0;
1035 register int tlbufpos
, tlendpos
;
1036 struct position pos
;
1037 int number_of_visible_frames
;
1042 #ifdef USE_X_TOOLKIT
1043 if (popup_activated ())
1047 if (! NILP (Vinhibit_redisplay
))
1052 if (! FRAME_WINDOW_P (selected_frame
)
1053 && previous_terminal_frame
!= selected_frame
)
1055 /* Since frames on an ASCII terminal share the same display area,
1056 displaying a different frame means redisplay the whole thing. */
1057 windows_or_buffers_changed
++;
1058 SET_FRAME_GARBAGED (selected_frame
);
1059 XSETFRAME (Vterminal_frame
, selected_frame
);
1061 previous_terminal_frame
= selected_frame
;
1063 /* Set the visible flags for all frames.
1064 Do this before checking for resized or garbaged frames; they want
1065 to know if their frames are visible.
1066 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
1068 Lisp_Object tail
, frame
;
1070 number_of_visible_frames
= 0;
1072 FOR_EACH_FRAME (tail
, frame
)
1074 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1076 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1077 number_of_visible_frames
++;
1079 /* Clear out all the display lines in which we will generate the
1080 glyphs to display. */
1081 init_desired_glyphs (XFRAME (frame
));
1085 /* Notice any pending interrupt request to change frame size. */
1086 do_pending_window_change ();
1090 redraw_garbaged_frames ();
1094 prepare_menu_bars ();
1096 if (windows_or_buffers_changed
)
1097 update_mode_lines
++;
1099 /* Detect case that we need to write or remove a star in the mode line. */
1100 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
1102 w
->update_mode_line
= Qt
;
1103 if (buffer_shared
> 1)
1104 update_mode_lines
++;
1107 /* If %c is in use, update it if needed. */
1108 if (!NILP (w
->column_number_displayed
)
1109 /* This alternative quickly identifies a common case
1110 where no change is needed. */
1111 && !(PT
== XFASTINT (w
->last_point
)
1112 && XFASTINT (w
->last_modified
) >= MODIFF
1113 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1114 && XFASTINT (w
->column_number_displayed
) != current_column ())
1115 w
->update_mode_line
= Qt
;
1117 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
1119 all_windows
= update_mode_lines
|| buffer_shared
> 1;
1121 /* If specs for an arrow have changed, do thorough redisplay
1122 to ensure we remove any arrow that should no longer exist. */
1123 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
1124 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
1127 /* Normally the message* functions will have already displayed and
1128 updated the echo area, but the frame may have been trashed, or
1129 the update may have been preempted, so display the echo area
1131 if (echo_area_glyphs
|| previous_echo_glyphs
)
1133 echo_area_display ();
1137 /* If showing region, and mark has changed, must redisplay whole window. */
1138 if (((!NILP (Vtransient_mark_mode
)
1139 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1140 != !NILP (w
->region_showing
))
1141 || (!NILP (w
->region_showing
)
1142 && !EQ (w
->region_showing
,
1143 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
1144 this_line_bufpos
= -1;
1146 tlbufpos
= this_line_bufpos
;
1147 tlendpos
= this_line_endpos
;
1148 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
1149 && !current_buffer
->clip_changed
1150 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
1151 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
1152 /* Make sure recorded data applies to current buffer, etc */
1153 && this_line_buffer
== current_buffer
1154 && current_buffer
== XBUFFER (w
->buffer
)
1155 && NILP (w
->force_start
)
1156 /* Point must be on the line that we have info recorded about */
1158 && PT
<= Z
- tlendpos
1159 /* All text outside that line, including its final newline,
1160 must be unchanged */
1161 && ((XFASTINT (w
->last_modified
) >= MODIFF
1162 && (XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
))
1163 || (beg_unchanged
>= tlbufpos
- 1
1165 /* If selective display, can't optimize
1166 if the changes start at the beginning of the line. */
1167 && ((INTEGERP (current_buffer
->selective_display
)
1168 && XINT (current_buffer
->selective_display
) > 0
1169 ? (beg_unchanged
>= tlbufpos
1172 && end_unchanged
>= tlendpos
1173 && Z
- GPT
>= tlendpos
)))
1175 int tlbufpos_byte
= CHAR_TO_BYTE (tlbufpos
);
1176 if (tlbufpos
> BEGV
&& FETCH_BYTE (tlbufpos_byte
- 1) != '\n'
1178 || FETCH_BYTE (tlbufpos_byte
) == '\n'))
1179 /* Former continuation line has disappeared by becoming empty */
1181 else if (XFASTINT (w
->last_modified
) < MODIFF
1182 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
1183 || MINI_WINDOW_P (w
))
1185 /* We have to handle the case of continuation around a
1186 wide-column character (See the comment in indent.c around
1189 For instance, in the following case:
1191 -------- Insert --------
1192 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1193 J_I_ ==> J_I_ `^^' are cursors.
1197 As we have to redraw the line above, we should goto cancel. */
1199 struct position val
;
1201 int opoint
= PT
, opoint_byte
= PT_BYTE
;
1203 scan_newline (tlbufpos
, tlbufpos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
1205 val
= *compute_motion (PT
, 0,
1206 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1209 1 << (BITS_PER_SHORT
- 1),
1210 1 << (BITS_PER_SHORT
- 1),
1211 window_internal_width (w
) - 1,
1212 XINT (w
->hscroll
), 0, w
);
1213 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
1214 if (val
.hpos
!= this_line_start_hpos
)
1218 overlay_arrow_seen
= 0;
1219 zv_strings_seen
= 0;
1220 display_text_line (w
, tlbufpos
, tlbufpos_byte
,
1221 this_line_vpos
, this_line_start_hpos
,
1222 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
), 0);
1223 /* If line contains point, is not continued,
1224 and ends at same distance from eob as before, we win */
1225 if (cursor_vpos
>= 0 && this_line_bufpos
1226 && this_line_endpos
== tlendpos
)
1228 /* If this is not the window's last line,
1229 we must adjust the charstarts of the lines below. */
1230 if (this_line_vpos
+ 1
1231 < XFASTINT (w
->top
) + window_internal_height (w
))
1233 int left
= WINDOW_LEFT_MARGIN (w
);
1234 int *charstart_next_line
1235 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
1238 if (Z
- tlendpos
== ZV
)
1239 /* This line ends at end of (accessible part of) buffer.
1240 There is no newline to count. */
1241 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
1243 /* This line ends in a newline.
1244 Must take account of the newline and the rest of the
1245 text that follows. */
1246 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
1248 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
1251 if (!WINDOW_FULL_WIDTH_P (w
))
1252 preserve_other_columns (w
);
1258 else if (PT
== XFASTINT (w
->last_point
)
1259 /* Make sure the cursor was last displayed
1260 in this window. Otherwise we have to reposition it. */
1261 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
1262 && (XINT (w
->top
) + XINT (w
->height
)
1263 > FRAME_CURSOR_Y (selected_frame
)))
1267 do_pending_window_change ();
1272 /* If highlighting the region, or if the cursor is in the echo area,
1273 then we can't just move the cursor. */
1274 else if (! (!NILP (Vtransient_mark_mode
)
1275 && !NILP (current_buffer
->mark_active
))
1276 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1277 || highlight_nonselected_windows
)
1278 && NILP (w
->region_showing
)
1279 && !cursor_in_echo_area
)
1281 pos
= *compute_motion (tlbufpos
, 0,
1282 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1284 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
1285 window_internal_width (w
) - 1,
1287 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
),
1291 int width
= window_internal_width (w
) - 1;
1292 FRAME_CURSOR_X (selected_frame
)
1293 = WINDOW_LEFT_MARGIN (w
) + minmax (0, pos
.hpos
, width
);
1294 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1301 /* Text changed drastically or point moved off of line */
1302 cancel_line (this_line_vpos
, selected_frame
);
1305 this_line_bufpos
= 0;
1306 all_windows
|= buffer_shared
> 1;
1308 clear_face_cache_count
++;
1312 Lisp_Object tail
, frame
;
1315 /* Clear the face cache, only when we do a full redisplay
1316 and not too often either. */
1317 if (clear_face_cache_count
> 1000)
1319 clear_face_cache ();
1320 clear_face_cache_count
= 0;
1324 /* Recompute # windows showing selected buffer.
1325 This will be incremented each time such a window is displayed. */
1328 FOR_EACH_FRAME (tail
, frame
)
1330 FRAME_PTR f
= XFRAME (frame
);
1331 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
1334 /* Mark all the scroll bars to be removed; we'll redeem the ones
1335 we want when we redisplay their windows. */
1336 if (condemn_scroll_bars_hook
)
1337 (*condemn_scroll_bars_hook
) (f
);
1339 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1340 redisplay_windows (FRAME_ROOT_WINDOW (f
), preserve_echo_area
);
1342 /* Any scroll bars which redisplay_windows should have nuked
1343 should now go away. */
1344 if (judge_scroll_bars_hook
)
1345 (*judge_scroll_bars_hook
) (f
);
1349 else if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1351 redisplay_window (selected_window
, 1, preserve_echo_area
);
1352 if (!WINDOW_FULL_WIDTH_P (w
))
1353 preserve_other_columns (w
);
1357 /* Prevent various kinds of signals during display update.
1358 stdio is not robust about handling signals,
1359 which can cause an apparent I/O error. */
1360 if (interrupt_input
)
1370 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1374 if (!FRAMEP (XCONS (tail
)->car
))
1377 f
= XFRAME (XCONS (tail
)->car
);
1379 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
1380 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1382 pause
|= update_frame (f
, 0, 0);
1385 mark_window_display_accurate (f
->root_window
, 1);
1386 if (frame_up_to_date_hook
!= 0)
1387 (*frame_up_to_date_hook
) (f
);
1394 if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1395 pause
= update_frame (selected_frame
, 0, 0);
1399 /* We may have called echo_area_display at the top of this
1400 function. If the echo area is on another frame, that may
1401 have put text on a frame other than the selected one, so the
1402 above call to update_frame would not have caught it. Catch
1405 Lisp_Object mini_window
;
1406 FRAME_PTR mini_frame
;
1408 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1409 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1411 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
1412 pause
|= update_frame (mini_frame
, 0, 0);
1416 /* If frame does not match, prevent doing single-line-update next time.
1417 Also, don't forget to check every line to update the arrow. */
1420 this_line_bufpos
= 0;
1421 if (!NILP (last_arrow_position
))
1423 last_arrow_position
= Qt
;
1424 last_arrow_string
= Qt
;
1426 /* If we pause after scrolling, some lines in current_frame
1427 may be null, so preserve_other_columns won't be able to
1428 preserve all the vertical-bar separators. So, avoid using it
1430 if (!WINDOW_FULL_WIDTH_P (w
))
1431 update_mode_lines
= 1;
1434 /* Now text on frame agrees with windows, so
1435 put info into the windows for partial redisplay to follow */
1439 register struct buffer
*b
= XBUFFER (w
->buffer
);
1441 blank_end_of_window
= 0;
1442 unchanged_modified
= BUF_MODIFF (b
);
1443 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
1444 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1445 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1447 /* Record the last place cursor was displayed in this window.
1448 But not if cursor is in the echo area, because in that case
1449 FRAME_CURSOR_X and FRAME_CURSOR_Y are in the echo area. */
1450 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (selected_frame
)
1451 && EQ (FRAME_MINIBUF_WINDOW (selected_frame
), minibuf_window
)))
1453 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1454 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1455 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1458 /* Make last_point invalid, since we don't really know
1459 where the cursor would be if it were not in the echo area. */
1460 XSETINT (w
->last_point
, -1);
1463 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1466 b
->clip_changed
= 0;
1467 w
->update_mode_line
= Qnil
;
1468 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1469 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
1471 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1474 /* Record if we are showing a region, so can make sure to
1475 update it fully at next redisplay. */
1476 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1477 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1478 || highlight_nonselected_windows
)
1479 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1480 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1483 w
->window_end_valid
= w
->buffer
;
1484 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1485 last_arrow_string
= Voverlay_arrow_string
;
1486 if (do_verify_charstarts
)
1487 verify_charstarts (w
);
1488 if (frame_up_to_date_hook
!= 0)
1489 (*frame_up_to_date_hook
) (selected_frame
);
1491 update_mode_lines
= 0;
1492 windows_or_buffers_changed
= 0;
1495 /* Start SIGIO interrupts coming again.
1496 Having them off during the code above
1497 makes it less likely one will discard output,
1498 but not impossible, since there might be stuff
1499 in the system buffer here.
1500 But it is much hairier to try to do anything about that. */
1502 if (interrupt_input
)
1506 /* If something has become visible now which was not before,
1507 redisplay again, so that we get them. */
1510 Lisp_Object tail
, frame
;
1513 FOR_EACH_FRAME (tail
, frame
)
1515 int this_is_visible
= 0;
1517 if (XFRAME (frame
)->visible
)
1518 this_is_visible
= 1;
1519 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1520 if (XFRAME (frame
)->visible
)
1521 this_is_visible
= 1;
1523 if (this_is_visible
)
1527 if (new_count
!= number_of_visible_frames
)
1528 windows_or_buffers_changed
++;
1531 /* Change frame size now if a change is pending. */
1532 do_pending_window_change ();
1534 /* If we just did a pending size change, or have additional
1535 visible frames, redisplay again. */
1536 if (windows_or_buffers_changed
&& !pause
)
1540 /* Redisplay, but leave alone any recent echo area message
1541 unless another message has been requested in its place.
1543 This is useful in situations where you need to redisplay but no
1544 user action has occurred, making it inappropriate for the message
1545 area to be cleared. See tracking_off and
1546 wait_reading_process_input for examples of these situations. */
1549 redisplay_preserve_echo_area ()
1551 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1553 echo_area_glyphs
= previous_echo_glyphs
;
1554 redisplay_internal (1);
1555 echo_area_glyphs
= 0;
1558 redisplay_internal (1);
1562 mark_window_display_accurate (window
, flag
)
1566 register struct window
*w
;
1568 for (;!NILP (window
); window
= w
->next
)
1570 if (!WINDOWP (window
)) abort ();
1571 w
= XWINDOW (window
);
1573 if (!NILP (w
->buffer
))
1575 XSETFASTINT (w
->last_modified
,
1576 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1577 XSETFASTINT (w
->last_overlay_modified
,
1578 !flag
? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)));
1580 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1583 /* Record if we are showing a region, so can make sure to
1584 update it fully at next redisplay. */
1585 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1586 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1587 || highlight_nonselected_windows
)
1588 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1589 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1593 w
->window_end_valid
= w
->buffer
;
1594 w
->update_mode_line
= Qnil
;
1595 if (!NILP (w
->buffer
) && flag
)
1596 XBUFFER (w
->buffer
)->clip_changed
= 0;
1598 if (!NILP (w
->vchild
))
1599 mark_window_display_accurate (w
->vchild
, flag
);
1600 if (!NILP (w
->hchild
))
1601 mark_window_display_accurate (w
->hchild
, flag
);
1606 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1607 last_arrow_string
= Voverlay_arrow_string
;
1611 /* t is unequal to any useful value of Voverlay_arrow_... */
1612 last_arrow_position
= Qt
;
1613 last_arrow_string
= Qt
;
1617 /* Update the menu bar item list for frame F.
1618 This has to be done before we start to fill in any display lines,
1619 because it can call eval.
1621 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1624 update_menu_bar (f
, save_match_data
)
1626 int save_match_data
;
1628 struct buffer
*old
= current_buffer
;
1630 register struct window
*w
;
1632 window
= FRAME_SELECTED_WINDOW (f
);
1633 w
= XWINDOW (window
);
1635 if (update_mode_lines
)
1636 w
->update_mode_line
= Qt
;
1638 if (FRAME_WINDOW_P (f
)
1640 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1641 FRAME_EXTERNAL_MENU_BAR (f
)
1643 FRAME_MENU_BAR_LINES (f
) > 0
1645 : FRAME_MENU_BAR_LINES (f
) > 0)
1647 /* If the user has switched buffers or windows, we need to
1648 recompute to reflect the new bindings. But we'll
1649 recompute when update_mode_lines is set too; that means
1650 that people can use force-mode-line-update to request
1651 that the menu bar be recomputed. The adverse effect on
1652 the rest of the redisplay algorithm is about the same as
1653 windows_or_buffers_changed anyway. */
1654 if (windows_or_buffers_changed
1655 || !NILP (w
->update_mode_line
)
1656 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1657 < BUF_MODIFF (XBUFFER (w
->buffer
)))
1658 != !NILP (w
->last_had_star
))
1659 || ((!NILP (Vtransient_mark_mode
)
1660 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1661 != !NILP (w
->region_showing
)))
1663 struct buffer
*prev
= current_buffer
;
1664 int count
= specpdl_ptr
- specpdl
;
1666 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1667 if (save_match_data
)
1668 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1669 if (NILP (Voverriding_local_map_menu_flag
))
1671 specbind (Qoverriding_terminal_local_map
, Qnil
);
1672 specbind (Qoverriding_local_map
, Qnil
);
1675 /* Run the Lucid hook. */
1676 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1677 /* If it has changed current-menubar from previous value,
1678 really recompute the menubar from the value. */
1679 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1680 call0 (Qrecompute_lucid_menubar
);
1681 safe_run_hooks (Qmenu_bar_update_hook
);
1682 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1683 /* Redisplay the menu bar in case we changed it. */
1684 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1685 if (FRAME_WINDOW_P (f
))
1686 set_frame_menubar (f
, 0, 0);
1688 /* On a terminal screen, the menu bar is an ordinary screen
1689 line, and this makes it get updated. */
1690 w
->update_mode_line
= Qt
;
1691 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1692 /* In the non-toolkit version, the menu bar is an ordinary screen
1693 line, and this makes it get updated. */
1694 w
->update_mode_line
= Qt
;
1695 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1697 unbind_to (count
, Qnil
);
1698 set_buffer_internal_1 (prev
);
1705 /* Redisplay WINDOW and its subwindows and siblings. */
1708 redisplay_windows (window
, preserve_echo_area
)
1710 int preserve_echo_area
;
1712 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1713 redisplay_window (window
, 0, preserve_echo_area
);
1716 /* Return value in display table DP (Lisp_Char_Table *) for character
1717 C. Since a display table doesn't have any parent, we don't have to
1718 follow parent. Do not call this function directly but use the
1719 macro DISP_CHAR_VECTOR. */
1721 disp_char_vector (dp
, c
)
1722 struct Lisp_Char_Table
*dp
;
1728 if (SINGLE_BYTE_CHAR_P (c
)) return (dp
->contents
[c
]);
1730 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
1731 if (code
[0] != CHARSET_COMPOSITION
)
1733 if (code
[1] < 32) code
[1] = -1;
1734 else if (code
[2] < 32) code
[2] = -1;
1736 /* Here, the possible range of CODE[0] (== charset ID) is
1737 128..MAX_CHARSET. Since the top level char table contains data
1738 for multibyte characters after 256th element, we must increment
1739 CODE[0] by 128 to get a correct index. */
1741 code
[3] = -1; /* anchor */
1743 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
1745 val
= dp
->contents
[code
[i
]];
1746 if (!SUB_CHAR_TABLE_P (val
))
1747 return (NILP (val
) ? dp
->defalt
: val
);
1749 /* Here, VAL is a sub char table. We return the default value of it. */
1750 return (dp
->defalt
);
1753 /* Redisplay window WINDOW and its subwindows. */
1756 redisplay_window (window
, just_this_one
, preserve_echo_area
)
1758 int just_this_one
, preserve_echo_area
;
1760 register struct window
*w
= XWINDOW (window
);
1761 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1764 int lpoint_byte
= PT_BYTE
;
1765 struct buffer
*old
= current_buffer
;
1766 register int width
= window_internal_width (w
) - 1;
1767 register int startp
, startp_byte
;
1768 register int hscroll
= XINT (w
->hscroll
);
1769 struct position pos
;
1771 int opoint_byte
= PT_BYTE
;
1773 int update_mode_line
;
1774 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1775 int really_switched_buffer
= 0;
1776 int count
= specpdl_ptr
- specpdl
;
1778 if (Z
== Z_BYTE
&& lpoint
!= lpoint_byte
)
1780 if (lpoint_byte
< lpoint
)
1783 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1785 /* If this is a combination window, do its children; that's all. */
1787 if (!NILP (w
->vchild
))
1789 redisplay_windows (w
->vchild
, preserve_echo_area
);
1792 if (!NILP (w
->hchild
))
1794 redisplay_windows (w
->hchild
, preserve_echo_area
);
1797 if (NILP (w
->buffer
))
1800 specbind (Qinhibit_point_motion_hooks
, Qt
);
1802 height
= window_internal_height (w
);
1803 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1804 if (XBUFFER (w
->buffer
)->clip_changed
)
1805 update_mode_line
= 1;
1807 if (MINI_WINDOW_P (w
))
1809 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1810 /* We've already displayed the echo area glyphs in this window. */
1811 goto finish_scroll_bars
;
1812 else if (w
!= XWINDOW (minibuf_window
))
1814 /* This is a minibuffer, but it's not the currently active one,
1816 int vpos
= XFASTINT (w
->top
);
1819 for (i
= 0; i
< height
; i
++)
1821 get_display_line (f
, vpos
+ i
, 0);
1822 display_string (w
, vpos
+ i
, "", 0,
1823 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
1827 goto finish_scroll_bars
;
1831 /* Otherwise set up data on this window; select its buffer and point value */
1833 if (update_mode_line
)
1834 /* Really select the buffer, for the sake of buffer-local variables. */
1836 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1837 really_switched_buffer
= 1;
1840 set_buffer_temp (XBUFFER (w
->buffer
));
1843 opoint_byte
= PT_BYTE
;
1845 if (Z
== Z_BYTE
&& opoint
!= opoint_byte
)
1847 if (opoint_byte
< opoint
)
1850 /* If %c is in mode line, update it if needed. */
1851 if (!NILP (w
->column_number_displayed
)
1852 /* This alternative quickly identifies a common case
1853 where no change is needed. */
1854 && !(PT
== XFASTINT (w
->last_point
)
1855 && XFASTINT (w
->last_modified
) >= MODIFF
1856 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1857 && XFASTINT (w
->column_number_displayed
) != current_column ())
1858 update_mode_line
= 1;
1860 /* Count number of windows showing the selected buffer.
1861 An indirect buffer counts as its base buffer. */
1865 struct buffer
*current_base
, *window_base
;
1866 current_base
= current_buffer
;
1867 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1868 if (current_base
->base_buffer
)
1869 current_base
= current_base
->base_buffer
;
1870 if (window_base
->base_buffer
)
1871 window_base
= window_base
->base_buffer
;
1872 if (current_base
== window_base
)
1876 /* POINT refers normally to the selected window.
1877 For any other window, set up appropriate value. */
1879 if (!EQ (window
, selected_window
))
1881 int new_pt
= XMARKER (w
->pointm
)->charpos
;
1882 int new_pt_byte
= marker_byte_position (w
->pointm
);
1886 new_pt_byte
= BEGV_BYTE
;
1887 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
1889 else if (new_pt
> (ZV
- 1))
1892 new_pt_byte
= ZV_BYTE
;
1893 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
1895 /* We don't use SET_PT so that the point-motion hooks don't run. */
1896 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
1899 /* If any of the character widths specified in the display table
1900 have changed, invalidate the width run cache. It's true that this
1901 may be a bit late to catch such changes, but the rest of
1902 redisplay goes (non-fatally) haywire when the display table is
1903 changed, so why should we worry about doing any better? */
1904 if (current_buffer
->width_run_cache
)
1906 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1908 if (! disptab_matches_widthtab (disptab
,
1909 XVECTOR (current_buffer
->width_table
)))
1911 invalidate_region_cache (current_buffer
,
1912 current_buffer
->width_run_cache
,
1914 recompute_width_table (current_buffer
, disptab
);
1918 /* If window-start is screwed up, choose a new one. */
1919 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1922 startp
= marker_position (w
->start
);
1923 startp_byte
= marker_byte_position (w
->start
);
1925 /* If someone specified a new starting point but did not insist,
1926 check whether it can be used. */
1927 if (!NILP (w
->optional_new_start
)
1928 && startp
>= BEGV
&& startp
<= ZV
)
1930 w
->optional_new_start
= Qnil
;
1931 /* Check whether this start pos is usable given where point is. */
1933 pos
= *compute_motion (startp
, 0,
1934 (((EQ (window
, minibuf_window
)
1936 ? minibuf_prompt_width
: 0)
1937 + (hscroll
? 1 - hscroll
: 0)),
1940 /* BUG FIX: See the comment of
1941 Fpos_visible_in_window_p (window.c). */
1942 - (1 << (BITS_PER_SHORT
- 1)),
1944 pos_tab_offset (w
, startp
, startp_byte
), w
);
1945 /* If PT does fit on the screen, we will use this start pos,
1946 so do so by setting force_start. */
1947 if (pos
.bufpos
== PT
)
1948 w
->force_start
= Qt
;
1951 /* Handle case where place to start displaying has been specified,
1952 unless the specified location is outside the accessible range. */
1953 if (!NILP (w
->force_start
))
1955 w
->force_start
= Qnil
;
1956 /* Forget any recorded base line for line number display. */
1957 w
->base_line_number
= Qnil
;
1958 /* The old bottom-of-screen position is no longer valid. */
1959 w
->window_end_valid
= Qnil
;
1960 /* Redisplay the mode line. Select the buffer properly for that.
1961 Also, run the hook window-scroll-functions
1962 because we have scrolled. */
1963 /* Note, we do this after clearing force_start because
1964 if there's an error, it is better to forget about force_start
1965 than to get into an infinite loop calling the hook functions
1966 and having them get more errors. */
1967 if (!update_mode_line
1968 || ! NILP (Vwindow_scroll_functions
))
1970 Lisp_Object temp
[3];
1972 if (!really_switched_buffer
)
1974 set_buffer_temp (old
);
1975 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1977 really_switched_buffer
= 1;
1978 update_mode_line
= 1;
1979 w
->update_mode_line
= Qt
;
1980 if (! NILP (Vwindow_scroll_functions
))
1982 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1983 make_number (startp
));
1984 startp
= marker_position (w
->start
);
1985 startp_byte
= marker_byte_position (w
->start
);
1988 XSETFASTINT (w
->last_modified
, 0);
1989 XSETFASTINT (w
->last_overlay_modified
, 0);
1990 if (startp
< BEGV
) startp
= BEGV
, startp_byte
= BEGV_BYTE
;
1991 if (startp
> ZV
) startp
= ZV
, startp
= ZV_BYTE
;
1992 try_window (window
, startp
);
1993 if (cursor_vpos
< 0)
1995 /* If point does not appear, move point so it does appear */
1996 pos
= *compute_motion (startp
, 0,
1997 (((EQ (window
, minibuf_window
)
1999 ? minibuf_prompt_width
: 0)
2000 + (hscroll
? 1 - hscroll
: 0)),
2003 - (1 << (BITS_PER_SHORT
- 1)),
2005 pos_tab_offset (w
, startp
, startp_byte
),
2007 TEMP_SET_PT_BOTH (pos
.bufpos
, pos
.bytepos
);
2008 if (w
!= XWINDOW (selected_window
))
2009 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
2012 if (current_buffer
== old
)
2015 lpoint_byte
= PT_BYTE
;
2017 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2018 + minmax (0, pos
.hpos
, width
));
2019 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2021 /* If we are highlighting the region,
2022 then we just changed the region, so redisplay to show it. */
2023 if (!NILP (Vtransient_mark_mode
)
2024 && !NILP (current_buffer
->mark_active
))
2026 cancel_my_columns (XWINDOW (window
));
2027 try_window (window
, startp
);
2033 /* Handle case where text has not changed, only point,
2034 and it has not moved off the frame. */
2036 /* This code is not used for minibuffer for the sake of
2037 the case of redisplaying to replace an echo area message;
2038 since in that case the minibuffer contents per se are usually unchanged.
2039 This code is of no real use in the minibuffer since
2040 the handling of this_line_bufpos, etc.,
2041 in redisplay handles the same cases. */
2043 if (XFASTINT (w
->last_modified
) >= MODIFF
2044 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
2045 && PT
>= startp
&& !current_buffer
->clip_changed
2046 && (just_this_one
|| WINDOW_FULL_WIDTH_P (w
))
2047 /* If force-mode-line-update was called, really redisplay;
2048 that's how redisplay is forced after e.g. changing
2049 buffer-invisibility-spec. */
2050 && NILP (w
->update_mode_line
)
2051 /* Can't use this case if highlighting a region. */
2052 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
2053 && NILP (w
->region_showing
)
2054 /* If end pos is out of date, scroll bar and percentage will be wrong */
2055 && INTEGERP (w
->window_end_vpos
)
2056 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
2057 && !EQ (window
, minibuf_window
)
2058 && (!MARKERP (Voverlay_arrow_position
)
2059 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
2061 /* All positions in this clause are relative to the window edge. */
2063 int this_scroll_margin
= scroll_margin
;
2064 int last_point_y
= XFASTINT (w
->last_point_y
) - XINT (w
->top
);
2065 int last_point_x
= (XFASTINT (w
->last_point_x
) - WINDOW_LEFT_MARGIN (w
));
2067 /* Find where PT is located now on the frame. */
2068 /* Check just_this_one as a way of verifying that the
2069 window edges have not changed. */
2070 if (PT
== XFASTINT (w
->last_point
) && just_this_one
2071 /* If CURSOR_IN_ECHO_AREA, last_point_x and last_point_y
2072 refer to the echo area and are not related to this window. */
2073 && ! cursor_in_echo_area
)
2075 pos
.hpos
= last_point_x
;
2076 pos
.vpos
= last_point_y
;
2079 else if (PT
> XFASTINT (w
->last_point
)
2080 && ! cursor_in_echo_area
2081 && XFASTINT (w
->last_point
) > startp
&& just_this_one
2082 /* We can't use this if point is in the left margin of a
2083 hscrolled window, because w->last_point_x has been
2084 clipped to the window edges. */
2085 && !(last_point_x
<= 0 && hscroll
))
2087 int last_point
= XFASTINT (w
->last_point
);
2088 int last_point_byte
= CHAR_TO_BYTE (last_point
);
2089 int tab_offset
= (pos_tab_offset (w
, last_point
, last_point_byte
)
2090 - (last_point_x
+ hscroll
- !! hscroll
));
2092 pos
= *compute_motion (last_point
, last_point_y
, last_point_x
, 0,
2094 /* BUG FIX: See the comment of
2095 Fpos_visible_in_window_p (window.c). */
2096 - (1 << (BITS_PER_SHORT
- 1)),
2103 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
2105 /* BUG FIX: See the comment of
2106 Fpos_visible_in_window_p (window.c). */
2107 - (1 << (BITS_PER_SHORT
- 1)),
2109 pos_tab_offset (w
, startp
, startp_byte
),
2113 /* Don't use a scroll margin that is negative or too large. */
2114 if (this_scroll_margin
< 0)
2115 this_scroll_margin
= 0;
2117 if (XINT (w
->height
) < 4 * scroll_margin
)
2118 this_scroll_margin
= XINT (w
->height
) / 4;
2120 /* If point fits on the screen, and not within the scroll margin,
2122 if (pos
.vpos
< height
- this_scroll_margin
2123 && (pos
.vpos
>= this_scroll_margin
|| startp
== BEGV
))
2125 /* Ok, point is still on frame */
2126 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
2128 /* These variables are supposed to be origin 1 */
2129 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2130 + minmax (0, pos
.hpos
, width
));
2131 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2133 /* This doesn't do the trick, because if a window to the right of
2134 this one must be redisplayed, this does nothing because there
2135 is nothing in DesiredFrame yet, and then the other window is
2136 redisplayed, making likes that are empty in this window's columns.
2137 if (WINDOW_FULL_WIDTH_P (w))
2138 preserve_my_columns (w);
2140 if (current_buffer
->clip_changed
2141 && ! NILP (Vwindow_scroll_functions
))
2142 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2143 make_number (marker_position (w
->start
)));
2147 /* Don't bother trying redisplay with same start;
2148 we already know it will lose. */
2150 /* If current starting point was originally the beginning of a line
2151 but no longer is, find a new starting point. */
2152 else if (!NILP (w
->start_at_line_beg
)
2154 || FETCH_BYTE (startp_byte
- 1) == '\n'))
2158 else if (just_this_one
&& !MINI_WINDOW_P (w
)
2160 && XFASTINT (w
->last_modified
)
2161 /* or else vmotion on first line won't work. */
2162 && ! NILP (w
->start_at_line_beg
)
2163 && ! EQ (w
->window_end_valid
, Qnil
)
2164 && do_id
&& !current_buffer
->clip_changed
2165 && !blank_end_of_window
2166 && WINDOW_FULL_WIDTH_P (w
)
2167 /* Can't use this case if highlighting a region. */
2168 && !(!NILP (Vtransient_mark_mode
)
2169 && !NILP (current_buffer
->mark_active
))
2170 /* Don't use try_window_id if newline
2171 doesn't display as the end of a line. */
2172 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
2173 && NILP (w
->region_showing
)
2174 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
2175 && EQ (last_arrow_string
, Voverlay_arrow_string
)
2176 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
2179 /* tem > 0 means success. tem == -1 means choose new start.
2180 tem == -2 means try again with same start,
2181 and nothing but whitespace follows the changed stuff.
2182 tem == 0 means try again with same start. */
2186 else if (startp
>= BEGV
&& startp
<= ZV
2188 /* Avoid starting at end of buffer. */
2189 #if 0 /* This change causes trouble for M-! finger & RET.
2190 It will have to be considered later. */
2191 || ! EQ (window
, selected_window
)
2192 /* Don't do the recentering if redisplay
2193 is not for no user action. */
2194 || preserve_echo_area
2197 || (XFASTINT (w
->last_modified
) >= MODIFF
2198 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
2200 /* Try to redisplay starting at same place as before */
2201 /* If point has not moved off frame, accept the results */
2202 try_window (window
, startp
);
2203 if (cursor_vpos
>= 0)
2205 if (!just_this_one
|| current_buffer
->clip_changed
2206 || beg_unchanged
< startp
)
2207 /* Forget any recorded base line for line number display. */
2208 w
->base_line_number
= Qnil
;
2210 if (current_buffer
->clip_changed
2211 && ! NILP (Vwindow_scroll_functions
))
2212 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2213 make_number (marker_position (w
->start
)));
2218 cancel_my_columns (w
);
2221 XSETFASTINT (w
->last_modified
, 0);
2222 XSETFASTINT (w
->last_overlay_modified
, 0);
2223 /* Redisplay the mode line. Select the buffer properly for that. */
2224 if (!update_mode_line
)
2226 if (!really_switched_buffer
)
2228 set_buffer_temp (old
);
2229 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2231 update_mode_line
= 1;
2232 w
->update_mode_line
= Qt
;
2235 /* Try to scroll by specified few lines */
2237 if ((scroll_conservatively
|| scroll_step
)
2238 && !current_buffer
->clip_changed
2239 && startp
>= BEGV
&& startp
<= ZV
)
2241 int this_scroll_margin
= scroll_margin
;
2242 int scroll_margin_pos
, scroll_margin_bytepos
;
2243 int scroll_max
= scroll_step
;
2246 if (scroll_conservatively
)
2247 scroll_max
= scroll_conservatively
;
2249 /* Don't use a scroll margin that is negative or too large. */
2250 if (this_scroll_margin
< 0)
2251 this_scroll_margin
= 0;
2253 if (XINT (w
->height
) < 4 * this_scroll_margin
)
2254 this_scroll_margin
= XINT (w
->height
) / 4;
2256 ltemp
= Fwindow_end (window
, Qt
);
2257 scroll_margin_pos
= XINT (ltemp
);
2259 if (this_scroll_margin
)
2261 pos
= *vmotion (scroll_margin_pos
, -this_scroll_margin
, w
);
2262 scroll_margin_pos
= pos
.bufpos
;
2263 scroll_margin_bytepos
= pos
.bytepos
;
2266 scroll_margin_bytepos
= CHAR_TO_BYTE (scroll_margin_pos
);
2268 if (PT
>= scroll_margin_pos
)
2270 struct position pos
;
2271 pos
= *compute_motion (scroll_margin_pos
, 0, 0, 0,
2272 PT
, XFASTINT (w
->height
), 0,
2273 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2274 pos_tab_offset (w
, scroll_margin_pos
,
2275 scroll_margin_bytepos
),
2277 if (pos
.vpos
>= scroll_max
)
2280 pos
= *vmotion (startp
,
2281 scroll_conservatively
? pos
.vpos
+ 1 : scroll_step
,
2284 /* The old bottom-of-screen position is no longer valid. */
2285 w
->window_end_valid
= Qnil
;
2286 if (! NILP (Vwindow_scroll_functions
))
2288 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2289 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2290 make_number (pos
.bufpos
));
2291 pos
.bufpos
= marker_position (w
->start
);
2293 try_window (window
, pos
.bufpos
);
2294 if (cursor_vpos
>= 0)
2296 if (!just_this_one
|| current_buffer
->clip_changed
2297 || beg_unchanged
< startp
)
2298 /* Forget any recorded base line for line number display. */
2299 w
->base_line_number
= Qnil
;
2303 cancel_my_columns (w
);
2306 scroll_margin_pos
= startp
;
2307 if (this_scroll_margin
)
2309 pos
= *vmotion (scroll_margin_pos
, this_scroll_margin
, w
);
2310 scroll_margin_pos
= pos
.bufpos
;
2312 if (PT
< scroll_margin_pos
)
2314 struct position pos
;
2315 pos
= *compute_motion (PT
, 0, 0, 0,
2316 scroll_margin_pos
, XFASTINT (w
->height
), 0,
2317 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2318 pos_tab_offset (w
, PT
, PT_BYTE
),
2320 if (pos
.vpos
> scroll_max
)
2323 pos
= *vmotion (startp
,
2324 scroll_conservatively
? -pos
.vpos
: - scroll_step
,
2327 /* The old bottom-of-screen position is no longer valid. */
2328 w
->window_end_valid
= Qnil
;
2329 if (! NILP (Vwindow_scroll_functions
))
2331 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2332 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2333 make_number (pos
.bufpos
));
2334 pos
.bufpos
= marker_position (w
->start
);
2336 try_window (window
, pos
.bufpos
);
2337 if (cursor_vpos
>= 0)
2339 if (!just_this_one
|| current_buffer
->clip_changed
2340 || beg_unchanged
< startp
)
2341 /* Forget any recorded base line for line number display. */
2342 w
->base_line_number
= Qnil
;
2346 cancel_my_columns (w
);
2352 if (scroll_step
&& ! scroll_margin
&& !current_buffer
->clip_changed
2353 && startp
>= BEGV
&& startp
<= ZV
)
2355 if (margin_call
== 0)
2356 margin_call
= (PT
> startp
? 1 : -1);
2357 if (margin_call
> 0)
2359 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
2360 if (pos
.vpos
>= height
)
2364 pos
= *vmotion (startp
, (margin_call
< 0 ? - scroll_step
: scroll_step
),
2367 if (PT
>= pos
.bufpos
)
2369 /* The old bottom-of-screen position is no longer valid. */
2370 w
->window_end_valid
= Qnil
;
2372 if (! NILP (Vwindow_scroll_functions
))
2374 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2375 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2376 make_number (pos
.bufpos
));
2377 pos
.bufpos
= marker_position (w
->start
);
2379 try_window (window
, pos
.bufpos
);
2380 if (cursor_vpos
>= 0)
2382 if (!just_this_one
|| current_buffer
->clip_changed
2383 || beg_unchanged
< startp
)
2384 /* Forget any recorded base line for line number display. */
2385 w
->base_line_number
= Qnil
;
2389 cancel_my_columns (w
);
2395 /* Finally, just choose place to start which centers point */
2398 /* Forget any previously recorded base line for line number display. */
2399 w
->base_line_number
= Qnil
;
2401 pos
= *vmotion (PT
, - (height
/ 2), w
);
2403 /* The minibuffer is often just one line. Ordinary scrolling
2404 gives little overlap and looks bad. So show 20 chars before point. */
2406 && (pos
.bufpos
>= PT
- minibuffer_scroll_overlap
2407 /* If we scrolled less than 1/2 line forward, we will
2408 get too much overlap, so change to the usual amount. */
2409 || pos
.bufpos
< startp
+ width
/ 2)
2410 && PT
> BEGV
+ minibuffer_scroll_overlap
2411 /* If we scrolled to an actual line boundary,
2412 that's different; don't ignore line boundaries. */
2413 && FETCH_BYTE (pos
.bytepos
- 1) != '\n')
2415 pos
.bufpos
= PT
- minibuffer_scroll_overlap
;
2416 pos
.bytepos
= CHAR_TO_BYTE (pos
.bufpos
);
2419 /* Set startp here explicitly in case that helps avoid an infinite loop
2420 in case the window-scroll-functions functions get errors. */
2421 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2423 /* The old bottom-of-screen position is no longer valid. */
2424 w
->window_end_valid
= Qnil
;
2425 if (! NILP (Vwindow_scroll_functions
))
2427 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2428 make_number (pos
.bufpos
));
2429 pos
.bufpos
= marker_position (w
->start
);
2430 pos
.bytepos
= marker_byte_position (w
->start
);
2432 try_window (window
, pos
.bufpos
);
2434 startp
= marker_position (w
->start
);
2435 startp_byte
= marker_byte_position (w
->start
);
2436 w
->start_at_line_beg
2437 = (startp
== BEGV
|| FETCH_BYTE (startp_byte
- 1) == '\n') ? Qt
: Qnil
;
2440 if ((update_mode_line
2441 /* If window not full width, must redo its mode line
2442 if the window to its side is being redone */
2443 || (!just_this_one
&& !WINDOW_FULL_WIDTH_P (w
))
2444 || INTEGERP (w
->base_line_pos
)
2445 || (!NILP (w
->column_number_displayed
)
2446 && XFASTINT (w
->column_number_displayed
) != current_column ()))
2447 && height
!= XFASTINT (w
->height
))
2449 FRAME_PTR oframe
= selected_frame
;
2450 if (!really_switched_buffer
)
2452 set_buffer_temp (old
);
2453 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2454 really_switched_buffer
= 1;
2457 display_mode_line (w
);
2458 selected_frame
= oframe
;
2460 if (! line_number_displayed
2461 && ! BUFFERP (w
->base_line_pos
))
2463 w
->base_line_pos
= Qnil
;
2464 w
->base_line_number
= Qnil
;
2467 /* When we reach a frame's selected window, redo the frame's menu bar. */
2468 if (update_mode_line
2469 && (FRAME_WINDOW_P (f
)
2471 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2472 FRAME_EXTERNAL_MENU_BAR (f
)
2474 FRAME_MENU_BAR_LINES (f
) > 0
2476 : FRAME_MENU_BAR_LINES (f
) > 0)
2477 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
2478 display_menu_bar (w
);
2481 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2483 int start
, end
, whole
;
2485 /* Calculate the start and end positions for the current window.
2486 At some point, it would be nice to choose between scrollbars
2487 which reflect the whole buffer size, with special markers
2488 indicating narrowing, and scrollbars which reflect only the
2491 Note that minibuffers sometimes aren't displaying any text. */
2492 if (! MINI_WINDOW_P (w
)
2493 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
2496 start
= marker_position (w
->start
) - BEGV
;
2497 /* I don't think this is guaranteed to be right. For the
2498 moment, we'll pretend it is. */
2499 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
2501 if (end
< start
) end
= start
;
2502 if (whole
< (end
- start
)) whole
= end
- start
;
2505 start
= end
= whole
= 0;
2507 /* Indicate what this scroll bar ought to be displaying now. */
2508 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
2510 /* Note that we actually used the scroll bar attached to this window,
2511 so it shouldn't be deleted at the end of redisplay. */
2512 (*redeem_scroll_bar_hook
) (w
);
2515 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
2516 if (really_switched_buffer
)
2517 set_buffer_internal_1 (old
);
2519 set_buffer_temp (old
);
2520 TEMP_SET_PT_BOTH (lpoint
, lpoint_byte
);
2522 unbind_to (count
, Qnil
);
2525 /* Do full redisplay on one window, starting at position `pos'. */
2528 try_window (window
, pos
)
2532 register struct window
*w
= XWINDOW (window
);
2533 register int height
= window_internal_height (w
);
2534 register int vpos
= XFASTINT (w
->top
);
2535 register int last_text_vpos
= vpos
;
2536 FRAME_PTR f
= XFRAME (w
->frame
);
2537 int width
= window_internal_width (w
) - 1;
2538 struct position val
;
2540 /* POS should never be out of range! */
2541 if (pos
< XBUFFER (w
->buffer
)->begv
2542 || pos
> XBUFFER (w
->buffer
)->zv
)
2545 if (XMARKER (w
->start
)->charpos
!= pos
)
2546 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2549 overlay_arrow_seen
= 0;
2550 zv_strings_seen
= 0;
2551 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2552 val
.ovstring_chars_done
= 0;
2553 val
.bytepos
= marker_byte_position (w
->start
);
2554 val
.tab_offset
= pos_tab_offset (w
, pos
, val
.bytepos
);
2556 while (--height
>= 0)
2558 val
= *display_text_line (w
, pos
, val
.bytepos
, vpos
,
2559 val
.hpos
, val
.tab_offset
,
2560 val
.ovstring_chars_done
);
2561 /* The following code is omitted because we maintain tab_offset
2564 tab_offset
+= width
;
2565 if (val
.vpos
) tab_offset
= 0;
2568 if (pos
!= val
.bufpos
)
2571 #ifdef USE_TEXT_PROPERTIES
2572 Lisp_Object invis_prop
;
2573 invis_prop
= Fget_char_property (make_number (val
.bufpos
- 1),
2574 Qinvisible
, window
);
2575 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
2579 /* Next line, unless prev line ended in end of buffer with no cr */
2581 && (FETCH_BYTE (val
.bytepos
- 1) != '\n' || invis
));
2586 /* If last line is continued in middle of character,
2587 include the split character in the text considered on the frame */
2588 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2591 /* If bottom just moved off end of frame, change mode line percentage. */
2592 if (XFASTINT (w
->window_end_pos
) == 0
2594 w
->update_mode_line
= Qt
;
2596 /* Say where last char on frame will be, once redisplay is finished. */
2597 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
2598 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
2599 /* But that is not valid info until redisplay finishes. */
2600 w
->window_end_valid
= Qnil
;
2603 /* Try to redisplay when buffer is modified locally,
2604 computing insert/delete line to preserve text outside
2605 the bounds of the changes.
2606 Return 1 if successful, 0 if if cannot tell what to do,
2607 or -1 to tell caller to find a new window start,
2608 or -2 to tell caller to do normal redisplay with same window start. */
2611 try_window_id (window
)
2615 int opoint
, opoint_byte
;
2616 register struct window
*w
= XWINDOW (window
);
2617 register int height
= window_internal_height (w
);
2618 FRAME_PTR f
= XFRAME (w
->frame
);
2619 int top
= XFASTINT (w
->top
);
2620 int start
= marker_position (w
->start
);
2621 int width
= window_internal_width (w
) - 1;
2622 int hscroll
= XINT (w
->hscroll
);
2623 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
2626 register int i
, tem
;
2627 int last_text_vpos
= 0;
2629 int selective
= (INTEGERP (current_buffer
->selective_display
)
2630 ? XINT (current_buffer
->selective_display
)
2631 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2632 struct position val
, bp
, ep
, xp
, pp
;
2633 int scroll_amount
= 0;
2637 int start_byte
= marker_byte_position (w
->start
);
2639 if (GPT
- BEG
< beg_unchanged
)
2640 beg_unchanged
= GPT
- BEG
;
2641 if (Z
- GPT
< end_unchanged
)
2642 end_unchanged
= Z
- GPT
;
2644 if (beg_unchanged
+ BEG
< start
)
2645 return 0; /* Give up if changes go above top of window */
2647 /* Find position before which nothing is changed. */
2648 bp
= *compute_motion (start
, 0, lmargin
, 0,
2649 min (ZV
, beg_unchanged
+ BEG
), height
,
2650 /* BUG FIX: See the comment of
2651 Fpos_visible_in_window_p (window.c). */
2652 - (1 << (BITS_PER_SHORT
- 1)),
2654 pos_tab_offset (w
, start
, start_byte
),
2656 if (bp
.vpos
>= height
)
2660 /* All changes are beyond the window end, and point is on the screen.
2661 We don't need to change the text at all.
2662 But we need to update window_end_pos to account for
2663 any change in buffer size. */
2664 bp
= *compute_motion (start
, 0, lmargin
, 0,
2666 /* BUG FIX: See the comment of
2667 Fpos_visible_in_window_p() (window.c). */
2668 - (1 << (BITS_PER_SHORT
- 1)),
2670 pos_tab_offset (w
, start
, start_byte
), w
);
2671 XSETFASTINT (w
->window_end_vpos
, height
);
2672 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
2680 /* Find beginning of that frame line. Must display from there. */
2681 bp
= *vmotion (bp
.bufpos
, 0, w
);
2684 pos_byte
= bp
.bytepos
;
2690 /* If about to start displaying at the beginning of a continuation line,
2691 really start with previous frame line, in case it was not
2692 continued when last redisplayed */
2693 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
2695 /* Likewise if we have to worry about selective display. */
2696 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
2698 bp
= *vmotion (bp
.bufpos
, -1, w
);
2701 pos_byte
= bp
.bytepos
;
2703 val
.tab_offset
= bp
.tab_offset
; /* Update tab offset. */
2705 if (bp
.contin
&& bp
.hpos
!= lmargin
)
2707 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
2708 val
.tab_offset
= bp
.tab_offset
+ bp
.prevhpos
- width
;
2710 DEC_BOTH (pos
, pos_byte
);
2715 /* Find first visible newline after which no more is changed. */
2716 opoint
= PT
, opoint_byte
= PT_BYTE
;
2717 TEMP_SET_PT (Z
- max (end_unchanged
, Z
- ZV
));
2718 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2720 while (PT
< ZV
- 1 && indented_beyond_p (PT
, PT_BYTE
, selective
))
2721 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2723 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
2725 /* Compute the cursor position after that newline. */
2726 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
2727 height
, - (1 << (BITS_PER_SHORT
- 1)),
2729 /* We have tab offset in VAL, use it. */
2732 /* If changes reach past the text available on the frame,
2733 just display rest of frame. */
2734 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
2737 stop_vpos
= ep
.vpos
;
2739 /* If no newline before ep, the line ep is on includes some changes
2740 that must be displayed. Make sure we don't stop before it. */
2741 /* Also, if changes reach all the way until ep.bufpos,
2742 it is possible that something was deleted after the
2743 newline before it, so the following line must be redrawn. */
2744 if (stop_vpos
== ep
.vpos
2745 && (ep
.bufpos
== BEGV
2746 || FETCH_BYTE (ep
.bytepos
- 1) != '\n'
2747 || ep
.bufpos
== Z
- end_unchanged
))
2748 stop_vpos
= ep
.vpos
+ 1;
2751 overlay_arrow_seen
= 0;
2752 zv_strings_seen
= 0;
2754 /* If changes do not reach to bottom of window,
2755 figure out how much to scroll the rest of the window */
2756 if (stop_vpos
< height
)
2758 /* Now determine how far up or down the rest of the window has moved */
2759 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2760 Z
- XFASTINT (w
->window_end_pos
),
2761 /* Don't care for VPOS... */
2762 1 << (BITS_PER_SHORT
- 1),
2764 1 << (BITS_PER_SHORT
- 1),
2765 width
, hscroll
, ep
.tab_offset
, w
);
2766 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2768 /* Is everything on frame below the changes whitespace?
2769 If so, no scrolling is really necessary. */
2770 for (i
= ep
.bytepos
; i
< xp
.bytepos
; i
++)
2772 tem
= FETCH_BYTE (i
);
2773 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2776 if (i
== xp
.bytepos
)
2779 XSETFASTINT (w
->window_end_vpos
,
2780 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2782 /* Before doing any scrolling, verify that point will be on frame. */
2783 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.vpos
< height
))
2785 if (PT
<= xp
.bufpos
)
2787 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2788 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2790 /* We have tab offset in EP, use it. */
2795 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2796 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2798 /* We have tab offset in XP, use it. */
2801 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2803 cursor_vpos
= pp
.vpos
+ top
;
2804 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, pp
.hpos
, width
);
2807 if (stop_vpos
- scroll_amount
>= height
2808 || ep
.bufpos
== xp
.bufpos
)
2810 if (scroll_amount
< 0)
2811 stop_vpos
-= scroll_amount
;
2813 /* In this path, we have altered window_end_vpos
2814 and not left it negative.
2815 We must make sure that, in case display is preempted
2816 before the frame changes to reflect what we do here,
2817 further updates will not come to try_window_id
2818 and assume the frame and window_end_vpos match. */
2819 blank_end_of_window
= 1;
2821 else if (!scroll_amount
)
2823 /* Even if we don't need to scroll, we must adjust the
2824 charstarts of subsequent lines (that we won't redisplay)
2825 according to the amount of text inserted or deleted. */
2826 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2827 int adjust
= ep
.bufpos
- oldpos
;
2828 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2830 else if (bp
.bufpos
== Z
- end_unchanged
)
2832 /* If reprinting everything is nearly as fast as scrolling,
2833 don't bother scrolling. Can happen if lines are short. */
2834 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2835 top
+ height
- max (0, scroll_amount
),
2837 > xp
.bufpos
- bp
.bufpos
- 20)
2838 /* Return "try normal display with same window-start."
2839 Too bad we can't prevent further scroll-thinking. */
2841 /* If pure deletion, scroll up as many lines as possible.
2842 In common case of killing a line, this can save the
2843 following line from being overwritten by scrolling
2844 and therefore having to be redrawn. */
2845 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2846 top
+ height
- max (0, scroll_amount
),
2847 scroll_amount
, bp
.bufpos
);
2852 /* scroll_frame_lines did not properly adjust subsequent
2853 lines' charstarts in the case where the text of the
2854 screen line at bp.vpos has changed.
2855 (This can happen in a deletion that ends in mid-line.)
2856 To adjust properly, we need to make things consistent
2858 So do a second adjust to make that happen.
2859 Note that stop_vpos >= ep.vpos, so it is sufficient
2860 to update the charstarts for lines at ep.vpos and below. */
2862 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2863 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2864 ep
.bufpos
- oldstart
);
2867 else if (scroll_amount
)
2869 /* If reprinting everything is nearly as fast as scrolling,
2870 don't bother scrolling. Can happen if lines are short. */
2871 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2872 overestimate of cost of reprinting, since xp.bufpos
2873 would end up below the bottom of the window. */
2874 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2875 top
+ height
- max (0, scroll_amount
),
2877 > xp
.bufpos
- ep
.bufpos
- 20)
2878 /* Return "try normal display with same window-start."
2879 Too bad we can't prevent further scroll-thinking. */
2881 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2882 top
+ height
- max (0, scroll_amount
),
2883 scroll_amount
, ep
.bufpos
);
2884 if (!tem
) stop_vpos
= height
;
2888 /* In any case, do not display past bottom of window */
2889 if (stop_vpos
>= height
)
2895 /* Handle case where pos is before w->start --
2896 can happen if part of line had been clipped and is not clipped now */
2897 if (vpos
== 0 && pos
< marker_position (w
->start
))
2898 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2900 val
.bytepos
= pos_byte
;
2901 val
.ovstring_chars_done
= 0;
2903 /* Redisplay the lines where the text was changed */
2904 last_text_vpos
= vpos
;
2905 /* The following code is omitted because we maintain tab offset in
2908 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2909 /* If we are starting display in mid-character, correct tab_offset
2910 to account for passing the line that that character really starts in. */
2911 if (val
.hpos
< lmargin
)
2912 tab_offset
+= width
;
2915 while (vpos
< stop_vpos
)
2917 val
= *display_text_line (w
, pos
, val
.bytepos
, top
+ vpos
++,
2918 val
.hpos
, val
.tab_offset
,
2919 val
.ovstring_chars_done
);
2920 /* If display_text_line ran a hook and changed some text,
2921 redisplay all the way to bottom of buffer
2922 So that we show the changes. */
2923 if (old_tick
!= MODIFF
)
2925 /* The following code is omitted because we maintain tab offset
2926 in val.tab_offset. */
2928 tab_offset
+= width
;
2929 if (val
.vpos
) tab_offset
= 0;
2931 if (pos
!= val
.bufpos
)
2933 /* Next line, unless prev line ended in end of buffer with no cr */
2934 = vpos
- (val
.vpos
&& FETCH_BYTE (val
.bytepos
- 1) != '\n');
2938 /* There are two cases:
2939 1) we have displayed down to the bottom of the window
2940 2) we have scrolled lines below stop_vpos by scroll_amount */
2944 /* If last line is continued in middle of character,
2945 include the split character in the text considered on the frame */
2946 if (val
.hpos
< lmargin
)
2948 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2949 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2952 /* If scrolling made blank lines at window bottom,
2953 redisplay to fill those lines */
2954 if (scroll_amount
< 0)
2956 /* Don't consider these lines for general-purpose scrolling.
2957 That will save time in the scrolling computation. */
2958 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2961 pos_byte
= xp
.bytepos
;
2963 val
.tab_offset
= xp
.tab_offset
;
2965 { /* Display from next line */
2966 vpos
= height
+ scroll_amount
;
2970 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2972 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2973 val
.tab_offset
= xp
.tab_offset
+ bp
.prevhpos
- width
;
2974 DEC_BOTH (pos
, pos_byte
);
2977 blank_end_of_window
= 1;
2978 /* The following code is omitted because we maintain tab offset
2979 in val.tab_offset. */
2981 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2982 /* If we are starting display in mid-character, correct tab_offset
2983 to account for passing the line that that character starts in. */
2984 if (val
.hpos
< lmargin
)
2985 tab_offset
+= width
;
2987 val
.bytepos
= pos_byte
;
2988 while (vpos
< height
)
2990 val
= *display_text_line (w
, pos
, val
.bytepos
,
2991 top
+ vpos
++, val
.hpos
,
2992 val
.tab_offset
, val
.ovstring_chars_done
);
2993 /* The following code is omitted because we maintain tab
2994 offset in val.tab_offset. */
2996 tab_offset
+= width
;
2997 if (val
.vpos
) tab_offset
= 0;
3002 /* Here is a case where display_text_line sets cursor_vpos wrong.
3003 Make it be fixed up, below. */
3009 /* If bottom just moved off end of frame, change mode line percentage. */
3010 if (XFASTINT (w
->window_end_pos
) == 0
3012 w
->update_mode_line
= Qt
;
3014 /* Attempt to adjust end-of-text positions to new bottom line */
3017 delta
= height
- xp
.vpos
;
3019 || (delta
> 0 && xp
.bufpos
<= ZV
)
3020 || (delta
== 0 && xp
.hpos
))
3022 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
3023 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
3024 XSETFASTINT (w
->window_end_vpos
,
3025 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
3029 w
->window_end_valid
= Qnil
;
3031 /* If point was not in a line that was displayed, find it */
3032 if (cursor_vpos
< 0)
3035 val
= *compute_motion (start
, 0, lmargin
, 0, PT
,
3036 /* Don't care for VPOS... */
3037 1 << (BITS_PER_SHORT
- 1),
3039 1 << (BITS_PER_SHORT
- 1),
3041 pos_tab_offset (w
, start
, start_byte
),
3043 /* Admit failure if point is off frame now */
3044 if (val
.vpos
>= height
)
3046 for (vpos
= 0; vpos
< height
; vpos
++)
3047 cancel_line (vpos
+ top
, f
);
3050 cursor_vpos
= val
.vpos
+ top
;
3051 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, val
.hpos
, width
);
3054 FRAME_CURSOR_X (f
) = cursor_hpos
;
3055 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3059 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
3060 height
, - (1 << (BITS_PER_SHORT
- 1)),
3062 pos_tab_offset (w
, start
, start_byte
),
3064 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
3066 if (XFASTINT (w
->window_end_pos
)
3074 /* Copy LEN glyphs starting address FROM to the rope TO.
3075 But don't actually copy the parts that would come in before S.
3076 Value is TO, advanced past the copied data.
3077 F is the frame we are displaying in. */
3080 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
3082 register GLYPH
*to
; /* Copy to here. */
3083 register GLYPH
*s
; /* Starting point. */
3084 Lisp_Object
*from
; /* Data to copy. */
3086 int face
; /* Face to apply to glyphs which don't specify one. */
3089 register Lisp_Object
*fp
= from
;
3090 /* These cache the results of the last call to compute_glyph_face. */
3092 int last_merged
= 0;
3095 if (! FRAME_TERMCAP_P (f
))
3098 GLYPH glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3100 unsigned int c
= FAST_GLYPH_CHAR (glyph
);
3103 /* For an invalid character code, use space. */
3106 if (FAST_GLYPH_FACE (glyph
) == 0)
3107 /* If GLYPH has no face code, use FACE. */
3109 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
3110 /* If it's same as previous glyph, use same result. */
3111 facecode
= last_merged
;
3114 /* Merge this glyph's face and remember the result. */
3115 last_code
= FAST_GLYPH_FACE (glyph
);
3116 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
3120 *to
= FAST_MAKE_GLYPH (c
, facecode
);
3128 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3135 /* Correct a glyph by replacing its specified user-level face code
3136 with a displayable computed face code. */
3139 fix_glyph (f
, glyph
, cface
)
3145 if (! FRAME_TERMCAP_P (f
))
3147 if (FAST_GLYPH_FACE (glyph
) != 0)
3148 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
3149 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
3155 /* Return the column of position POS / POS_BYTE in window W's buffer.
3156 When used on the character at the beginning of a line,
3157 starting at column 0, this says how much to subtract from
3158 the column position of any character in the line
3159 to get its horizontal position on the screen. */
3162 pos_tab_offset (w
, pos
, pos_byte
)
3164 register int pos
, pos_byte
;
3167 int opoint_byte
= PT_BYTE
;
3169 int width
= window_internal_width (w
) - 1;
3172 return MINI_WINDOW_P (w
) ? -minibuf_prompt_width
: 0;
3174 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3177 TEMP_SET_PT_BOTH (pos
, pos_byte
);
3178 col
= current_column ();
3179 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3184 /* Display one line of window W, starting at char position START in W's buffer.
3185 START_BYTE is the corresponding byte position.
3187 Display starting at horizontal position HPOS, expressed relative to
3188 W's left edge. In situations where the text at START shouldn't
3189 start at the left margin (i.e. when the window is hscrolled, or
3190 we're continuing a line which left off in the midst of a
3191 multi-column character), HPOS should be negative; we throw away
3192 characters up 'til hpos = 0. So, HPOS must take hscrolling into
3195 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
3197 OVSTR_DONE is the number of chars of overlay before/after strings
3198 at this position which have already been processed.
3200 Display on position VPOS on the frame. It is origin 0, relative to
3201 the top of the frame, not W.
3203 Returns a STRUCT POSITION giving character to start next line with
3204 and where to display it, including a zero or negative hpos.
3205 The vpos field is not really a vpos; it is 1 unless the line is continued */
3207 struct position val_display_text_line
;
3209 static struct position
*
3210 display_text_line (w
, start
, start_byte
, vpos
, hpos
, taboffset
, ovstr_done
)
3218 register int pos
= start
;
3219 int pos_byte
= start_byte
;
3222 int pause
, limit_byte
;
3223 register unsigned char *p
;
3225 register GLYPH
*leftmargin
;
3226 register GLYPH
*p1prev
;
3227 register GLYPH
*p1start
;
3228 GLYPH
*p1_wide_column_end
= (GLYPH
*) 0;
3229 int prevpos
, prevpos_byte
;
3231 FRAME_PTR f
= XFRAME (w
->frame
);
3232 int tab_width
= XINT (current_buffer
->tab_width
);
3233 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
3234 int width
= window_internal_width (w
) - 1;
3235 struct position val
;
3236 int lastpos
, lastpos_byte
;
3238 int last_invis_skip
= 0;
3239 Lisp_Object last_invis_prop
;
3240 int hscroll
= XINT (w
->hscroll
);
3241 int truncate
= (hscroll
3242 || (truncate_partial_width_windows
3243 && !WINDOW_FULL_WIDTH_P (w
))
3244 || !NILP (current_buffer
->truncate_lines
));
3246 /* 1 if this buffer has a region to highlight. */
3247 int highlight_region
3248 = (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
)
3249 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
3250 int region_beg
, region_end
;
3252 int selective
= (INTEGERP (current_buffer
->selective_display
)
3253 ? XINT (current_buffer
->selective_display
)
3254 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
3255 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
3256 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
3258 Lisp_Object default_invis_vector
[3];
3259 /* Number of characters of ellipsis to display after an invisible line
3260 if it calls for an ellipsis.
3261 Note that this value can be nonzero regardless of whether
3262 selective display is enabled--you must check that separately. */
3264 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3265 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
3266 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
3267 /* This is the sequence of Lisp objects to display
3268 when there are invisible lines. */
3269 Lisp_Object
*invis_vector_contents
3270 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3271 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
3272 : default_invis_vector
);
3274 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
3275 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp
)))
3276 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
3277 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
3278 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp
)))
3279 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
3281 /* If 1, we must handle multibyte characters. */
3282 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
3283 /* Length of multibyte form of each character. */
3285 /* Glyphs generated should be set this bit mask if text must be
3286 displayed from right to left. */
3287 GLYPH rev_dir_bit
= (NILP (current_buffer
->direction_reversed
)
3288 ? 0 : GLYPH_MASK_REV_DIR
);
3290 /* The next buffer location at which the face should change, due
3291 to overlays or text property changes. */
3292 int next_face_change
;
3294 /* The next location where the `invisible' property changes, or an
3295 overlay starts or ends. */
3298 /* The face we're currently using. */
3299 int current_face
= 0;
3302 XSETFASTINT (default_invis_vector
[2], '.');
3303 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
3305 get_display_line (f
, vpos
, WINDOW_LEFT_MARGIN (w
));
3306 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
3308 /* Show where to highlight the region. */
3309 if (highlight_region
3310 /* Maybe highlight only in selected window. */
3311 && (highlight_nonselected_windows
3312 || w
== XWINDOW (selected_window
)
3313 || (MINI_WINDOW_P (XWINDOW (selected_window
))
3314 && w
== XWINDOW (Vminibuf_scroll_window
))))
3316 region_beg
= marker_position (current_buffer
->mark
);
3317 if (PT
< region_beg
)
3319 region_end
= region_beg
;
3324 w
->region_showing
= Qt
;
3328 region_beg
= region_end
= -1;
3329 w
->region_showing
= Qnil
;
3332 if (MINI_WINDOW_P (w
)
3334 && vpos
== XFASTINT (w
->top
))
3336 if (! NILP (minibuf_prompt
))
3338 int old_width
= minibuf_prompt_width
;
3340 minibuf_prompt_width
3341 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
3342 STRING_BYTES (XSTRING (minibuf_prompt
)),
3343 hpos
+ WINDOW_LEFT_MARGIN (w
),
3344 /* Display a space if we truncate. */
3347 /* Truncate the prompt a little before the
3348 margin, so user input can at least start
3349 on the first line. */
3350 (XFASTINT (w
->width
) > 10
3351 ? XFASTINT (w
->width
) - 4 : -1),
3352 STRING_MULTIBYTE (minibuf_prompt
))
3353 - hpos
- WINDOW_LEFT_MARGIN (w
));
3354 hpos
+= minibuf_prompt_width
;
3355 taboffset
-= minibuf_prompt_width
- old_width
;
3358 minibuf_prompt_width
= 0;
3361 /* If we're hscrolled at all, use compute_motion to skip over any
3362 text off the left edge of the window. compute_motion may know
3363 tricks to do this faster than we can. */
3366 struct position
*left_edge
3367 = compute_motion (pos
, vpos
, hpos
, 0,
3369 width
, hscroll
, taboffset
, w
);
3371 /* Retrieve the buffer position and column provided by
3372 compute_motion. We can't assume that the column will be
3373 zero, because you may have multi-column characters crossing
3376 compute_motion may have moved us past the screen position we
3377 requested, if we hit a multi-column character, or the end of
3378 the line. If so, back up. */
3379 if ((left_edge
->vpos
> vpos
3380 || left_edge
->hpos
> 0)
3381 && left_edge
->bufpos
> pos
)
3383 pos
= left_edge
->bufpos
;
3384 pos_byte
= left_edge
->bytepos
;
3385 DEC_BOTH (pos
, pos_byte
);
3386 hpos
= left_edge
->prevhpos
;
3390 pos
= left_edge
->bufpos
;
3391 pos_byte
= left_edge
->bytepos
;
3392 hpos
= left_edge
->hpos
;
3396 hpos
+= WINDOW_LEFT_MARGIN (w
);
3398 desired_glyphs
->bufp
[vpos
] = start
;
3399 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
3401 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
3402 /* In case we don't ever write anything into it... */
3403 desired_glyphs
->charstarts
[vpos
][WINDOW_LEFT_MARGIN (w
)] = -1;
3404 leftmargin
= desired_glyphs
->glyphs
[vpos
] + WINDOW_LEFT_MARGIN (w
);
3405 endp
= leftmargin
+ width
;
3407 /* Arrange the overlays nicely for our purposes. Usually, we call
3408 display_text_line on only one line at a time, in which case this
3409 can't really hurt too much, or we call it on lines which appear
3410 one after another in the buffer, in which case all calls to
3411 recenter_overlay_lists but the first will be pretty cheap. */
3412 recenter_overlay_lists (current_buffer
, pos
);
3414 /* Loop generating characters.
3415 Stop at end of buffer, before newline,
3416 if reach or pass continuation column,
3417 or at face change. */
3419 limit_byte
= pos_byte
;
3420 next_face_change
= pos
;
3421 next_boundary
= pos
;
3424 prevpos_byte
= pos_byte
;
3426 /* If the window is hscrolled and point is in the invisible part of the
3427 current line beyond the left margin we can record the cursor location
3429 if (hscroll
&& start
<= PT
&& PT
< pos
&& cursor_vpos
< 0)
3432 cursor_hpos
= p1
- leftmargin
;
3441 while (pos
== next_boundary
)
3443 Lisp_Object position
, limit
, prop
, ww
;
3445 /* Display the overlay strings here, unless we're at ZV
3446 and have already displayed the appropriate strings
3447 on an earlier line. */
3448 if (pos
< ZV
|| !zv_strings_seen
++)
3451 unsigned char *ovstr
;
3452 ovlen
= overlay_strings (pos
, w
, &ovstr
);
3456 /* Skip the ones we did in a previous line. */
3457 ovstr
+= ovstr_done
;
3458 ovlen
-= ovstr_done
;
3467 c
= STRING_CHAR_AND_LENGTH (ovstr
, ovlen
, len
);
3468 ovstr
+= len
, ovlen
-= len
, ovstr_done
+= len
;
3469 charset
= CHAR_CHARSET (c
);
3470 cols
= (charset
== CHARSET_COMPOSITION
3471 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3472 : CHARSET_WIDTH (charset
));
3476 c
= *ovstr
++, ovlen
--, ovstr_done
++;
3479 g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3482 if (p1
>= leftmargin
&& p1
< endp
)
3483 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3487 /* If we did all the overlay strings
3488 and we have room for text, clear ovstr_done
3489 just for neatness' sake. */
3490 if (ovlen
== 0 && p1
< endp
)
3495 /* Did we reach point? Record the cursor location. */
3496 if (pos
== PT
&& cursor_vpos
< 0)
3499 cursor_hpos
= p1
- leftmargin
;
3505 XSETFASTINT (position
, pos
);
3506 limit
= Fnext_overlay_change (position
);
3507 #ifdef USE_TEXT_PROPERTIES
3508 /* This is just an estimate to give reasonable
3509 performance; nothing should go wrong if it is too small. */
3510 if (XFASTINT (limit
) > pos
+ 50)
3512 int limitpos
= pos
+ 50;
3513 XSETFASTINT (limit
, limitpos
);
3515 limit
= Fnext_single_property_change (position
, Qinvisible
,
3516 Fcurrent_buffer (), limit
);
3518 next_boundary
= XFASTINT (limit
);
3519 /* if the `invisible' property is set, we can skip to
3520 the next property change. */
3522 prop
= Fget_char_property (position
, Qinvisible
, ww
);
3523 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3525 if (pos
< PT
&& next_boundary
>= PT
)
3528 cursor_hpos
= p1
- leftmargin
;
3530 pos
= next_boundary
;
3531 pos_byte
= CHAR_TO_BYTE (pos
);
3532 last_invis_skip
= pos
;
3533 last_invis_prop
= prop
;
3537 /* Did we reach point? Record the cursor location. */
3538 if (pos
== PT
&& cursor_vpos
< 0)
3541 cursor_hpos
= p1
- leftmargin
;
3544 /* Did we hit the end of the visible region of the buffer?
3548 /* Update charstarts for the end of this line. */
3549 /* Do nothing if off the left edge or at the right edge. */
3550 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
3552 int *p2x
= &charstart
[(p1
< leftmargin
3560 /* Figure out where (if at all) the
3561 redisplay_end_trigger-hook should run. */
3562 if (MARKERP (w
->redisplay_end_trigger
)
3563 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
3564 e_t_h
= marker_position (w
->redisplay_end_trigger
);
3565 else if (INTEGERP (w
->redisplay_end_trigger
))
3566 e_t_h
= XINT (w
->redisplay_end_trigger
);
3570 /* If we've gone past the place to run a hook,
3572 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
3574 Lisp_Object args
[3];
3576 args
[0] = Qredisplay_end_trigger_functions
;
3577 XSETWINDOW (args
[1], w
);
3578 XSETINT (args
[2], e_t_h
);
3580 /* Since we are *trying* to run these functions,
3581 don't try to run them again, even if they get an error. */
3582 w
->redisplay_end_trigger
= Qnil
;
3583 Frun_hook_with_args (3, args
);
3586 /* Notice if it changed the face of this character. */
3587 next_face_change
= pos
;
3591 /* Did we hit a face change? Figure out what face we should
3592 use now. We also hit this the first time through the
3593 loop, to see what face we should start with. */
3594 if (pos
>= next_face_change
3595 && (FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
)))
3597 int limit
= pos
+ 50;
3599 current_face
= compute_char_face (f
, w
, pos
,
3600 region_beg
, region_end
,
3601 &next_face_change
, limit
, 0);
3605 /* Compute the next place we need to stop
3606 and do something special; set PAUSE. */
3610 if (pos
< next_boundary
&& next_boundary
< pause
)
3611 pause
= next_boundary
;
3612 if (pos
< next_face_change
&& next_face_change
< pause
)
3613 pause
= next_face_change
;
3618 /* Wouldn't you hate to read the next line to someone over
3620 if (pos
< PT
&& PT
< pause
)
3622 if (pos
< GPT
&& GPT
< pause
)
3625 /* LIMIT_BYTE is not the same place in the buffer as PAUSE.
3626 It is a limit on valid characters.
3627 We use it to bound STRING_CHAR_AND_LENGTH. */
3628 limit_byte
= ZV_BYTE
;
3629 if (pos
< GPT
&& GPT_BYTE
< limit_byte
)
3630 limit_byte
= GPT_BYTE
;
3633 int temp
= CHAR_TO_BYTE (pos
);
3634 p
= BYTE_POS_ADDR (temp
);
3642 p1_wide_column_end
= (GLYPH
*) 0;
3645 c
= STRING_CHAR_AND_LENGTH (p
, limit_byte
- pos_byte
, len
), p
+= len
;
3648 /* Let a display table override all standard display methods. */
3649 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3651 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
3652 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3653 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3654 current_face
, rev_dir_bit
);
3656 else if (c
>= 040 && c
< 0177)
3658 if (p1
>= leftmargin
)
3659 *p1
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3665 /* Same as p1prev, but after the invis_vector_contents text
3666 (if we have that on this line). */
3667 GLYPH
*p1prev_modified
;
3671 if (last_invis_skip
== pos
3672 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
3676 && indented_beyond_p (pos
+ 1, pos_byte
+ 1, selective
))
3678 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3681 INC_BOTH (pos
, pos_byte
);
3682 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3683 pos
= PT
, pos_byte
= PT_BYTE
;
3684 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3689 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3691 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
3696 cs
= charstart
+ (p1
- p1start
);
3699 p1
+= selective_rlen
;
3700 if (p1
- leftmargin
> width
)
3703 #if 0 /* This needs more work; charstarts needs to record
3704 both whether a position ho;ds an ellipsis character
3705 and what buffer position it corresponds to. */
3706 csend
= charstart
+ (p1
- p1start
);
3709 /* The idea is to use p1prev_modified instead of p1prev
3710 in the loop below over p2x. */
3711 p1prev_modified
= p1
;
3714 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3715 (p1
- p1prev
), current_face
, rev_dir_bit
);
3718 /* Update charstarts for the newline that ended this line. */
3719 /* Do nothing here for a char that's entirely off the left edge
3720 or if it starts at the right edge. */
3721 if (p1
>= leftmargin
&& p1prev
!= endp
)
3723 /* Store the newline's position into charstarts
3724 for the column where the newline starts.
3725 Store -1 for the rest of the glyphs it occupies. */
3726 int *p2x
= &charstart
[(p1prev
< leftmargin
3727 ? leftmargin
: p1prev
)
3729 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3736 /* Draw the face of the newline character as extending all the
3737 way to the end of the frame line. */
3740 if (p1
< leftmargin
)
3743 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3753 if (p1
>= leftmargin
&& p1
< endp
)
3754 *p1
= MAKE_GLYPH (f
, ' ', current_face
) | rev_dir_bit
;
3757 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
3760 else if (c
== Ctl ('M') && selective
== -1)
3762 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3763 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3764 pos
= PT
, pos_byte
= PT_BYTE
;
3765 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3767 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3769 if (selective_rlen
> 0)
3771 p1
+= selective_rlen
;
3772 if (p1
- leftmargin
> width
)
3774 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3775 (p1
- p1prev
), current_face
, rev_dir_bit
);
3778 /* Draw the face of the newline character as extending all the
3779 way to the end of the frame line. */
3782 if (p1
< leftmargin
)
3785 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3789 /* Update charstarts for the ^M that ended this line. */
3790 /* Do nothing here for a char that's entirely off the left edge
3791 or if it starts at the right edge. */
3792 if (p1
>= leftmargin
&& p1prev
!= endp
)
3794 /* Store the newline's position into charstarts
3795 for the column where the newline starts.
3796 Store -1 for the rest of the glyphs it occupies. */
3797 int *p2x
= &charstart
[(p1prev
< leftmargin
3798 ? leftmargin
: p1prev
)
3800 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3808 else if (c
< 0200 && ctl_arrow
)
3810 if (p1
>= leftmargin
)
3812 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3813 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
3814 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3818 if (p1
>= leftmargin
&& p1
< endp
)
3819 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
) | rev_dir_bit
;
3824 /* C is a multibyte character or a character to be displayed
3826 int remaining_bytes
= len
;
3828 if (c
>= 0400 && CHAR_VALID_P (c
, 0))
3830 /* C is a multibyte character. */
3831 int charset
= CHAR_CHARSET (c
);
3832 int columns
= (charset
== CHARSET_COMPOSITION
3833 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3834 : CHARSET_WIDTH (charset
));
3835 GLYPH g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3839 if (p1
>= leftmargin
&& p1
< endp
)
3840 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3843 p1_wide_column_end
= p1
;
3844 remaining_bytes
-= CHARSET_BYTES (charset
);
3847 while (remaining_bytes
> 0)
3849 c
= *(p
- remaining_bytes
--);
3851 if (p1
>= leftmargin
&& p1
< endp
)
3854 (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3855 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
3856 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3860 if (p1
>= leftmargin
&& p1
< endp
)
3861 *p1
= (MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
)
3864 if (p1
>= leftmargin
&& p1
< endp
)
3865 *p1
= (MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
)
3868 if (p1
>= leftmargin
&& p1
< endp
)
3869 *p1
= (MAKE_GLYPH (f
, (7 & c
) + '0', current_face
)
3876 prevpos_byte
= pos_byte
;
3880 /* Update charstarts for the character just output. */
3882 /* Do nothing here for a char that's entirely off the left edge. */
3883 if (p1
>= leftmargin
)
3885 /* Store the char's position into charstarts
3886 for the first glyph occupied by this char.
3887 Store -1 for the rest of the glyphs it occupies. */
3890 int *p2x
= &charstart
[(p1prev
< leftmargin
3891 ? leftmargin
: p1prev
)
3893 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3903 val
.hpos
= - XINT (w
->hscroll
);
3910 lastpos_byte
= pos_byte
;
3912 /* Store 0 in this charstart line for the positions where
3913 there is no character. But do leave what was recorded
3914 for the character that ended the line. */
3915 /* Add 1 in the endtest to compensate for the fact that ENDP was
3916 made from WIDTH, which is 1 less than the window's actual
3918 i
= p1
- p1start
+ 1;
3919 if (p1
< leftmargin
)
3920 i
+= leftmargin
- p1
;
3921 for (; i
< endp
- p1start
+ 1; i
++)
3924 /* Handle continuation in middle of a character */
3925 /* by backing up over it */
3928 /* Don't back up if we never actually displayed any text.
3929 This occurs when the minibuffer prompt takes up the whole line. */
3932 /* Start the next line with that same character whose
3933 character code is C and the length of multi-byte form is
3936 pos_byte
= prevpos_byte
;
3938 if (p1_wide_column_end
< endp
)
3939 /* As ENDP is not in the middle of wide-column character,
3940 we can break the line at ENDP and start from the middle
3941 column in the next line. So, adjust VAL.HPOS to skip
3942 the columns output on this line. */
3943 val
.hpos
+= p1prev
- endp
;
3946 /* We displayed a wide-column character at around ENDP.
3947 Since we can't broke it in the middle, the whole
3948 character should be driven into the next line. */
3949 /* As the result, the actual columns occupied by the
3950 text on this line is less than WIDTH. VAL.TAB_OFFSET
3951 must be adjusted. */
3952 taboffset
= taboffset
+ (p1prev
- endp
);
3953 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3955 GLYPH g
= fix_glyph (f
, truncate
? truncator
: continuer
, 0);
3956 while (p1prev
< endp
)
3959 /* If POINT is at POS, cursor should not on this line. */
3961 lastpos_byte
= pos_byte
;
3967 /* Keep in this line everything up to the continuation column. */
3971 /* Finish deciding which character to start the next line on,
3972 and what hpos to start it at.
3973 Also set `lastpos' to the last position which counts as "on this line"
3974 for cursor-positioning. */
3978 if (FETCH_BYTE (pos_byte
) == '\n')
3980 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3982 /* If stopped due to a newline, start next line after it */
3983 TEMP_SET_PT_BOTH (pos
+ 1, pos_byte
+ 1);
3986 /* Check again for hidden lines, in case the newline occurred exactly
3987 at the right margin. */
3988 while (PT
< ZV
&& selective
> 0
3989 && indented_beyond_p (PT
, PT_BYTE
, selective
))
3990 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
3992 pos
= PT
, pos_byte
= PT_BYTE
;
3993 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3996 /* Stopped due to right margin of window */
4000 int opoint
= PT
, opoint_byte
= PT_BYTE
;
4002 TEMP_SET_PT_BOTH (pos
, pos_byte
);
4003 *p1
++ = fix_glyph (f
, truncator
, 0);
4004 /* Truncating => start next line after next newline,
4005 and point is on this line if it is before the newline,
4006 and skip none of first char of next line */
4008 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
4009 while (PT
< ZV
&& selective
> 0
4010 && indented_beyond_p (PT
, PT_BYTE
, selective
));
4011 pos
= PT
, pos_byte
= PT_BYTE
;
4012 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
4013 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
4015 lastpos
= pos
- (FETCH_BYTE (pos_byte
- 1) == '\n');
4016 lastpos_byte
= CHAR_TO_BYTE (lastpos
);
4021 *p1
++ = fix_glyph (f
, continuer
, 0);
4023 DEC_BOTH (lastpos
, lastpos_byte
);
4024 val
.tab_offset
= taboffset
+ width
;
4031 /* If point is at eol or in invisible text at eol,
4032 record its frame location now. */
4034 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
4037 cursor_hpos
= p1
- leftmargin
;
4040 if (cursor_vpos
== vpos
)
4042 if (cursor_hpos
< 0) cursor_hpos
= 0;
4043 if (cursor_hpos
> width
) cursor_hpos
= width
;
4044 cursor_hpos
+= WINDOW_LEFT_MARGIN (w
);
4045 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
4047 this_line_bufpos
= 0;
4049 /* If this frame's cursor will be in its echo area,
4050 don't record a cursor from the window text,
4051 and turn off the optimization for cursor-motion-only case. */
4052 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
4053 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
4055 FRAME_CURSOR_Y (f
) = cursor_vpos
;
4056 FRAME_CURSOR_X (f
) = cursor_hpos
;
4058 if (w
== XWINDOW (selected_window
))
4060 /* Line is not continued and did not start
4061 in middle of character */
4062 if ((hpos
- WINDOW_LEFT_MARGIN (w
)
4063 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
4066 this_line_bufpos
= start
;
4067 this_line_buffer
= current_buffer
;
4068 this_line_vpos
= cursor_vpos
;
4069 this_line_start_hpos
= hpos
- WINDOW_LEFT_MARGIN (w
);
4070 this_line_endpos
= Z
- lastpos
;
4077 /* If hscroll and line not empty, insert truncation-at-left marker */
4078 if (hscroll
&& lastpos
!= start
)
4080 GLYPH g
= fix_glyph (f
, truncator
, 0);
4082 if (p1
<= leftmargin
)
4083 p1
= leftmargin
+ 1;
4084 else /* MULE: it may be a wide-column character */
4086 p1prev
= leftmargin
+ 1;
4087 while (p1prev
< p1
&& *p1prev
& GLYPH_MASK_PADDING
)
4092 if (!WINDOW_RIGHTMOST_P (w
))
4095 if (p1
< leftmargin
) p1
= leftmargin
;
4096 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
4098 /* Don't draw vertical bars if we're using scroll bars. They're
4099 covered up by the scroll bars, and it's distracting to see
4100 them when the scroll bar windows are flickering around to be
4102 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4105 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4108 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4109 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
4110 ? XINT (DISP_BORDER_GLYPH (dp
))
4113 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
4114 p1
- desired_glyphs
->glyphs
[vpos
]);
4115 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
4117 /* If the start of this line is the overlay arrow-position,
4118 then put the arrow string into the display-line. */
4120 if (MARKERP (Voverlay_arrow_position
)
4121 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
4122 && start
== marker_position (Voverlay_arrow_position
)
4123 && STRINGP (Voverlay_arrow_string
)
4124 && ! overlay_arrow_seen
)
4127 int len
= XSTRING (Voverlay_arrow_string
)->size
;
4133 /* If the arrow string has text props, obey them when displaying. */
4134 for (i
= 0, i_byte
= 0; i
< len
; )
4137 Lisp_Object face
, ilisp
;
4141 if (STRING_MULTIBYTE (Voverlay_arrow_string
))
4142 FETCH_STRING_CHAR_ADVANCE (c
, Voverlay_arrow_string
, i
, i_byte
);
4144 c
= XSTRING (Voverlay_arrow_string
)->data
[i
++];
4146 XSETFASTINT (ilisp
, i
);
4148 if (FRAME_WINDOW_P (f
))
4150 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
4151 newface
= compute_glyph_face_1 (f
, face
, 0);
4152 c
= FAST_MAKE_GLYPH (c
, newface
);
4154 #endif /* HAVE_FACES */
4155 leftmargin
[idx
] = c
;
4158 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
4159 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
4160 if (desired_glyphs
->used
[vpos
] < arrow_end
)
4161 desired_glyphs
->used
[vpos
] = arrow_end
;
4163 overlay_arrow_seen
= 1;
4167 val
.bytepos
= pos_byte
;
4168 val
.ovstring_chars_done
= ovstr_done
;
4169 val_display_text_line
= val
;
4170 return &val_display_text_line
;
4173 /* Redisplay the menu bar in the frame for window W. */
4176 display_menu_bar (w
)
4179 Lisp_Object items
, tail
;
4180 register int vpos
= 0;
4181 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4182 int maxendcol
= FRAME_WIDTH (f
);
4187 if (!NILP (Vwindow_system
))
4191 #ifdef USE_X_TOOLKIT
4194 #endif /* USE_X_TOOLKIT */
4196 get_display_line (f
, vpos
, 0);
4198 items
= FRAME_MENU_BAR_ITEMS (f
);
4199 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4201 Lisp_Object pos
, string
;
4202 string
= XVECTOR (items
)->contents
[i
+ 1];
4206 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], hpos
);
4208 if (hpos
< maxendcol
)
4209 hpos
= display_string (w
, vpos
,
4210 XSTRING (string
)->data
,
4211 STRING_BYTES (XSTRING (string
)),
4212 hpos
, 0, 0, hpos
, maxendcol
,
4213 STRING_MULTIBYTE (string
));
4214 /* Put a space between items. */
4215 if (hpos
< maxendcol
)
4217 int hpos1
= hpos
+ 1;
4218 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
4219 min (hpos1
, maxendcol
), maxendcol
, 0);
4223 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4224 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4226 /* Fill out the line with spaces. */
4227 if (maxendcol
> hpos
)
4228 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
, 0);
4230 /* Clear the rest of the lines allocated to the menu bar. */
4232 while (vpos
< FRAME_MENU_BAR_LINES (f
))
4233 get_display_line (f
, vpos
++, 0);
4236 /* Display the mode line for window w */
4239 display_mode_line (w
)
4242 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
4243 register int left
= WINDOW_LEFT_MARGIN (w
);
4244 register int right
= WINDOW_RIGHT_MARGIN (w
);
4245 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4247 line_number_displayed
= 0;
4248 w
->column_number_displayed
= Qnil
;
4250 get_display_line (f
, vpos
, left
);
4252 /* Temporarily make frame F's kboard the current kboard
4253 so that kboard-local variables in the mode_line_format
4254 will get the right values. */
4255 push_frame_kboard (f
);
4257 display_mode_element (w
, vpos
, left
, 0, right
, right
,
4258 current_buffer
->mode_line_format
);
4260 pop_frame_kboard ();
4262 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4264 /* Put the mode line in inverse video.
4265 Use faces if possible, since that lets us handle
4266 partial-width windows and avoid inverting the scroll bar columns. */
4268 if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
4270 /* For a partial width window, explicitly set face of each glyph. */
4272 unsigned int padding
;
4273 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
4274 for (i
= left
; i
< right
; ++i
)
4276 padding
= ptr
[i
] & GLYPH_MASK_PADDING
;
4277 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1) | padding
;
4283 /* Make the mode line inverse video if the entire line
4284 is made of mode lines.
4285 I.e. if this window is full width,
4286 or if it is the child of a full width window
4287 (which implies that that window is split side-by-side
4288 and the rest of this line is mode lines of the sibling windows). */
4289 if (WINDOW_FULL_WIDTH_P (w
)
4290 || WINDOW_FULL_WIDTH_P (XWINDOW (w
->parent
)))
4291 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4294 /* Contribute ELT to the mode line for window W.
4295 How it translates into text depends on its data type.
4297 VPOS is the position of the mode line being displayed.
4299 HPOS is the position (absolute on frame) where this element's text
4300 should start. The output is truncated automatically at the right
4303 DEPTH is the depth in recursion. It is used to prevent
4304 infinite recursion here.
4306 MINENDCOL is the hpos before which the element may not end.
4307 The element is padded at the right with spaces if nec
4308 to reach this column.
4310 MAXENDCOL is the hpos past which this element may not extend.
4311 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
4312 (This is necessary to make nested padding and truncation work.)
4314 Returns the hpos of the end of the text generated by ELT.
4315 The next element will receive that value as its HPOS arg,
4316 so as to concatenate the elements. */
4319 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
4321 register int vpos
, hpos
;
4324 register int maxendcol
;
4325 register Lisp_Object elt
;
4333 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
4337 /* A string: output it and check for %-constructs within it. */
4338 register unsigned char c
;
4339 register unsigned char *this = XSTRING (elt
)->data
;
4341 while (hpos
< maxendcol
&& *this)
4343 unsigned char *last
= this;
4344 while ((c
= *this++) != '\0' && c
!= '%')
4346 if (this - 1 != last
)
4348 register int lim
= --this - last
+ hpos
;
4349 if (frame_title_ptr
)
4350 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
4352 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
4353 hpos
, min (lim
, maxendcol
),
4354 STRING_MULTIBYTE (elt
));
4358 register int minendcol
;
4359 register int spec_width
= 0;
4361 /* We can't allow -ve args due to the "%-" construct */
4362 /* Argument specifies minwidth but not maxwidth
4363 (maxwidth can be specified by
4364 (<negative-number> . <stuff>) mode-line elements) */
4366 while ((c
= *this++) >= '0' && c
<= '9')
4368 spec_width
= spec_width
* 10 + (c
- '0');
4371 minendcol
= hpos
+ spec_width
;
4372 if (minendcol
> maxendcol
)
4374 spec_width
= maxendcol
- hpos
;
4375 minendcol
= maxendcol
;
4379 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4380 spec_width
, maxendcol
,
4381 Vglobal_mode_string
);
4384 char *spec
= decode_mode_spec (w
, c
, spec_width
,
4386 if (frame_title_ptr
)
4387 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
4389 hpos
= display_string (w
, vpos
, spec
, -1,
4391 minendcol
, maxendcol
, -1);
4399 /* A symbol: process the value of the symbol recursively
4400 as if it appeared here directly. Avoid error if symbol void.
4401 Special case: if value of symbol is a string, output the string
4404 register Lisp_Object tem
;
4405 tem
= Fboundp (elt
);
4408 tem
= Fsymbol_value (elt
);
4409 /* If value is a string, output that string literally:
4410 don't check for % within it. */
4413 if (frame_title_ptr
)
4414 hpos
= store_frame_title (XSTRING (tem
)->data
,
4415 minendcol
, maxendcol
);
4417 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
4418 STRING_BYTES (XSTRING (tem
)),
4419 hpos
, 0, 1, minendcol
, maxendcol
,
4420 STRING_MULTIBYTE (tem
));
4422 /* Give up right away for nil or t. */
4423 else if (!EQ (tem
, elt
))
4424 { elt
= tem
; goto tail_recurse
; }
4431 register Lisp_Object car
, tem
;
4433 /* A cons cell: three distinct cases.
4434 If first element is a string or a cons, process all the elements
4435 and effectively concatenate them.
4436 If first element is a negative number, truncate displaying cdr to
4437 at most that many characters. If positive, pad (with spaces)
4438 to at least that many characters.
4439 If first element is a symbol, process the cadr or caddr recursively
4440 according to whether the symbol's value is non-nil or nil. */
4441 car
= XCONS (elt
)->car
;
4444 tem
= Fboundp (car
);
4445 elt
= XCONS (elt
)->cdr
;
4448 /* elt is now the cdr, and we know it is a cons cell.
4449 Use its car if CAR has a non-nil value. */
4452 tem
= Fsymbol_value (car
);
4454 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
4456 /* Symbol's value is nil (or symbol is unbound)
4457 Get the cddr of the original list
4458 and if possible find the caddr and use that. */
4459 elt
= XCONS (elt
)->cdr
;
4462 else if (!CONSP (elt
))
4464 elt
= XCONS (elt
)->car
;
4467 else if (INTEGERP (car
))
4469 register int lim
= XINT (car
);
4470 elt
= XCONS (elt
)->cdr
;
4472 /* Negative int means reduce maximum width.
4473 DO NOT change MINENDCOL here!
4474 (20 -10 . foo) should truncate foo to 10 col
4475 and then pad to 20. */
4476 maxendcol
= min (maxendcol
, hpos
- lim
);
4479 /* Padding specified. Don't let it be more than
4482 if (lim
> maxendcol
)
4484 /* If that's more padding than already wanted, queue it.
4485 But don't reduce padding already specified even if
4486 that is beyond the current truncation point. */
4487 if (lim
> minendcol
)
4492 else if (STRINGP (car
) || CONSP (car
))
4494 register int limit
= 50;
4495 /* LIMIT is to protect against circular lists. */
4496 while (CONSP (elt
) && --limit
> 0
4497 && hpos
< maxendcol
)
4499 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4502 elt
= XCONS (elt
)->cdr
;
4510 if (frame_title_ptr
)
4511 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
4513 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
4514 minendcol
, maxendcol
, 0);
4518 if (minendcol
> hpos
)
4519 if (frame_title_ptr
)
4520 hpos
= store_frame_title ("", minendcol
, maxendcol
);
4522 hpos
= display_string (w
, vpos
, "", 0, hpos
,
4523 0, 1, minendcol
, maxendcol
, 0);
4527 /* Write a null-terminated, right justified decimal representation of
4528 the positive integer D to BUF using a minimal field width WIDTH. */
4531 pint2str (buf
, width
, d
)
4536 register char *p
= buf
;
4543 *p
++ = d
% 10 + '0';
4546 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
4556 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4557 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4558 type of CODING_SYSTEM. Return updated pointer into BUF. */
4560 static char invalid_eol_type
[] = "(*invalid*)";
4563 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
4564 Lisp_Object coding_system
;
4569 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
4570 unsigned char *eol_str
;
4572 /* The EOL conversion we are using. */
4573 Lisp_Object eoltype
;
4575 val
= coding_system
;
4577 if (NILP (val
)) /* Not yet decided. */
4582 eoltype
= eol_mnemonic_undecided
;
4583 /* Don't mention EOL conversion if it isn't decided. */
4587 Lisp_Object eolvalue
;
4589 eolvalue
= Fget (coding_system
, Qeol_type
);
4591 while (!NILP (val
) && SYMBOLP (val
))
4593 val
= Fget (val
, Qcoding_system
);
4594 if (NILP (eolvalue
))
4595 eolvalue
= Fget (val
, Qeol_type
);
4599 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
4603 /* The EOL conversion that is normal on this system. */
4605 if (NILP (eolvalue
)) /* Not yet decided. */
4606 eoltype
= eol_mnemonic_undecided
;
4607 else if (VECTORP (eolvalue
)) /* Not yet decided. */
4608 eoltype
= eol_mnemonic_undecided
;
4609 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4610 eoltype
= (XFASTINT (eolvalue
) == 0
4612 : (XFASTINT (eolvalue
) == 1
4613 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
4619 /* Mention the EOL conversion if it is not the usual one. */
4620 if (STRINGP (eoltype
))
4622 eol_str
= XSTRING (eoltype
)->data
;
4623 eol_str_len
= XSTRING (eoltype
)->size
;
4625 else if (INTEGERP (eoltype
)
4626 && CHAR_VALID_P (XINT (eoltype
), 0))
4628 int c
= XINT (eoltype
);
4629 unsigned char work
[4];
4631 eol_str_len
= CHAR_STRING (XINT (eoltype
), work
, eol_str
);
4635 eol_str
= invalid_eol_type
;
4636 eol_str_len
= sizeof (invalid_eol_type
) - 1;
4638 bcopy (eol_str
, buf
, eol_str_len
);
4645 /* Return a string for the output of a mode line %-spec for window W,
4646 generated by character C. SPEC_WIDTH is the field width when
4647 padding to the left (%c, %l). The value returned from this
4648 function will later be truncated to width MAXWIDTH. */
4650 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4653 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
4656 register int spec_width
;
4657 register int maxwidth
;
4660 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4661 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
4662 struct buffer
*b
= XBUFFER (w
->buffer
);
4665 if (maxwidth
> FRAME_WIDTH (f
))
4666 maxwidth
= FRAME_WIDTH (f
);
4671 if (!NILP (b
->read_only
))
4673 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4678 /* This differs from %* only for a modified read-only buffer. */
4679 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4681 if (!NILP (b
->read_only
))
4686 /* This differs from %* in ignoring read-only-ness. */
4687 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4699 if (command_loop_level
> 5)
4701 p
= decode_mode_spec_buf
;
4702 for (i
= 0; i
< command_loop_level
; i
++)
4705 return decode_mode_spec_buf
;
4713 if (command_loop_level
> 5)
4715 p
= decode_mode_spec_buf
;
4716 for (i
= 0; i
< command_loop_level
; i
++)
4719 return decode_mode_spec_buf
;
4727 if (maxwidth
< sizeof (lots_of_dashes
))
4728 return lots_of_dashes
;
4731 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
4735 return decode_mode_spec_buf
;
4741 if (maxwidth
>= 3 && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4743 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
4744 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
4745 decode_mode_spec_buf
[maxwidth
] = '\0';
4746 return decode_mode_spec_buf
;
4753 int col
= current_column ();
4754 XSETFASTINT (w
->column_number_displayed
, col
);
4755 pint2str (decode_mode_spec_buf
, spec_width
, col
);
4756 return decode_mode_spec_buf
;
4760 /* %F displays the frame name. */
4761 /* Systems that can only display a single frame at a time should
4762 NOT replace the frame name with the (constant) frame title,
4763 since then they won't be able to tell which frame is that. */
4764 if (FRAME_WINDOW_P (f
) && !NILP (f
->title
))
4765 return (char *) XSTRING (f
->title
)->data
;
4766 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
4767 return (char *) XSTRING (f
->name
)->data
;
4775 else if (STRINGP (obj
) && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4777 bcopy ("...", decode_mode_spec_buf
, 3);
4778 bcopy (XSTRING (obj
)->data
+ STRING_BYTES (XSTRING (obj
)) - maxwidth
+ 3,
4779 decode_mode_spec_buf
+ 3, maxwidth
- 3);
4780 return decode_mode_spec_buf
;
4787 int startpos
= XMARKER (w
->start
)->charpos
;
4788 int startpos_byte
= marker_byte_position (w
->start
);
4789 int line
, linepos
, linepos_byte
, topline
;
4792 int height
= XFASTINT (w
->height
);
4794 /* If we decided that this buffer isn't suitable for line numbers,
4795 don't forget that too fast. */
4796 if (EQ (w
->base_line_pos
, w
->buffer
))
4798 /* But do forget it, if the window shows a different buffer now. */
4799 else if (BUFFERP (w
->base_line_pos
))
4800 w
->base_line_pos
= Qnil
;
4802 /* If the buffer is very big, don't waste time. */
4803 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
4805 w
->base_line_pos
= Qnil
;
4806 w
->base_line_number
= Qnil
;
4810 if (!NILP (w
->base_line_number
)
4811 && !NILP (w
->base_line_pos
)
4812 && XFASTINT (w
->base_line_pos
) <= startpos
)
4814 line
= XFASTINT (w
->base_line_number
);
4815 linepos
= XFASTINT (w
->base_line_pos
);
4816 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
4821 linepos
= BUF_BEGV (b
);
4822 linepos_byte
= BUF_BEGV_BYTE (b
);
4825 /* Count lines from base line to window start position. */
4826 nlines
= display_count_lines (linepos
, linepos_byte
,
4830 topline
= nlines
+ line
;
4832 /* Determine a new base line, if the old one is too close
4833 or too far away, or if we did not have one.
4834 "Too close" means it's plausible a scroll-down would
4836 if (startpos
== BUF_BEGV (b
))
4838 XSETFASTINT (w
->base_line_number
, topline
);
4839 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
4841 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
4842 || linepos
== BUF_BEGV (b
))
4844 int limit
= BUF_BEGV (b
);
4845 int limit_byte
= BUF_BEGV_BYTE (b
);
4847 int distance
= (height
* 2 + 30) * 200;
4849 if (startpos
- distance
> limit
)
4851 limit
= startpos
- distance
;
4852 limit_byte
= CHAR_TO_BYTE (limit
);
4855 nlines
= display_count_lines (startpos
, startpos_byte
,
4857 - (height
* 2 + 30),
4859 /* If we couldn't find the lines we wanted within
4861 give up on line numbers for this window. */
4862 if (position
== limit_byte
&& limit
== startpos
- distance
)
4864 w
->base_line_pos
= w
->buffer
;
4865 w
->base_line_number
= Qnil
;
4869 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
4870 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
4873 /* Now count lines from the start pos to point. */
4874 nlines
= display_count_lines (startpos
, startpos_byte
,
4875 PT_BYTE
, PT
, &junk
);
4877 /* Record that we did display the line number. */
4878 line_number_displayed
= 1;
4880 /* Make the string to show. */
4881 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
4882 return decode_mode_spec_buf
;
4885 char* p
= decode_mode_spec_buf
;
4886 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
4888 return decode_mode_spec_buf
;
4898 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
4904 int pos
= marker_position (w
->start
);
4905 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4907 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
4909 if (pos
<= BUF_BEGV (b
))
4914 else if (pos
<= BUF_BEGV (b
))
4918 if (total
> 1000000)
4919 /* Do it differently for a large value, to avoid overflow. */
4920 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4922 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4923 /* We can't normally display a 3-digit number,
4924 so get us a 2-digit number that is close. */
4927 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4928 return decode_mode_spec_buf
;
4932 /* Display percentage of size above the bottom of the screen. */
4935 int toppos
= marker_position (w
->start
);
4936 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
4937 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4939 if (botpos
>= BUF_ZV (b
))
4941 if (toppos
<= BUF_BEGV (b
))
4948 if (total
> 1000000)
4949 /* Do it differently for a large value, to avoid overflow. */
4950 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4952 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4953 /* We can't normally display a 3-digit number,
4954 so get us a 2-digit number that is close. */
4957 if (toppos
<= BUF_BEGV (b
))
4958 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
4960 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4961 return decode_mode_spec_buf
;
4966 /* status of process */
4967 obj
= Fget_buffer_process (w
->buffer
);
4969 return "no process";
4971 obj
= Fsymbol_name (Fprocess_status (obj
));
4975 case 't': /* indicate TEXT or BINARY */
4976 #ifdef MODE_LINE_BINARY_TEXT
4977 return MODE_LINE_BINARY_TEXT (b
);
4983 /* coding-system (not including end-of-line format) */
4985 /* coding-system (including end-of-line type) */
4987 int eol_flag
= (c
== 'Z');
4988 char *p
= decode_mode_spec_buf
;
4990 if (! FRAME_WINDOW_P (f
))
4992 /* No need to mention EOL here--the terminal never needs
4993 to do EOL conversion. */
4994 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
4995 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
4997 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
5000 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
5002 obj
= Fget_buffer_process (Fcurrent_buffer ());
5005 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
5007 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
5010 #endif /* subprocesses */
5013 return decode_mode_spec_buf
;
5018 return (char *) XSTRING (obj
)->data
;
5023 /* Count up to COUNT lines starting from START / START_BYTE.
5024 But don't go beyond LIMIT_BYTE.
5025 Return the number of lines thus found (always nonnegative).
5027 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
5030 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
5031 int start
, start_byte
, limit_byte
, count
;
5034 register unsigned char *cursor
;
5035 unsigned char *base
;
5037 register int ceiling
;
5038 register unsigned char *ceiling_addr
;
5039 int orig_count
= count
;
5041 /* If we are not in selective display mode,
5042 check only for newlines. */
5043 int selective_display
= (!NILP (current_buffer
->selective_display
)
5044 && !INTEGERP (current_buffer
->selective_display
));
5048 while (start_byte
< limit_byte
)
5050 ceiling
= BUFFER_CEILING_OF (start_byte
);
5051 ceiling
= min (limit_byte
- 1, ceiling
);
5052 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
5053 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
5056 if (selective_display
)
5057 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
5060 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
5063 if (cursor
!= ceiling_addr
)
5067 start_byte
+= cursor
- base
+ 1;
5068 *byte_pos_ptr
= start_byte
;
5072 if (++cursor
== ceiling_addr
)
5078 start_byte
+= cursor
- base
;
5083 while (start_byte
> limit_byte
)
5085 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
5086 ceiling
= max (limit_byte
, ceiling
);
5087 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
5088 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
5091 if (selective_display
)
5092 while (--cursor
!= ceiling_addr
5093 && *cursor
!= '\n' && *cursor
!= 015)
5096 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
5099 if (cursor
!= ceiling_addr
)
5103 start_byte
+= cursor
- base
+ 1;
5104 *byte_pos_ptr
= start_byte
;
5105 /* When scanning backwards, we should
5106 not count the newline posterior to which we stop. */
5107 return - orig_count
- 1;
5113 /* Here we add 1 to compensate for the last decrement
5114 of CURSOR, which took it past the valid range. */
5115 start_byte
+= cursor
- base
+ 1;
5119 *byte_pos_ptr
= limit_byte
;
5122 return - orig_count
+ count
;
5123 return orig_count
- count
;
5127 /* Display STRING on one line of window W, starting at HPOS.
5128 Display at position VPOS. Caller should have done get_display_line.
5129 If VPOS == -1, display it as the current frame's title.
5130 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
5132 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
5134 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
5135 MAXCOL is the last column ok to end at. Truncate here.
5136 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
5137 Both count from the left edge of the frame, as does HPOS.
5138 The right edge of W is an implicit maximum.
5139 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
5141 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
5142 at the place where the current window ends in this line
5143 and not display anything beyond there. Otherwise, only MAXCOL
5144 controls where to stop output.
5146 MULTIBYTE can be 0 meaning do not display multibyte chars,
5147 1 meaning do display them, or -1 meaning obey the current buffer's
5148 value of enable_multibyte_characters.
5150 Returns ending hpos. */
5153 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
5154 obey_window_width
, mincol
, maxcol
, multibyte
)
5156 unsigned char *string
;
5160 int obey_window_width
;
5167 int hscroll
= XINT (w
->hscroll
);
5168 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
5169 register GLYPH
*start
;
5170 register GLYPH
*end
;
5171 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
5172 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
5173 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
5174 int window_width
= XFASTINT (w
->width
);
5176 /* Use the standard display table, not the window's display table.
5177 We don't want the mode line in rot13. */
5178 register struct Lisp_Char_Table
*dp
= 0;
5181 if (multibyte
== -1)
5182 multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
5183 /* Now multibyte is 1 if we should display multibyte characters. */
5185 if (DISP_TABLE_P (Vstandard_display_table
))
5186 dp
= XCHAR_TABLE (Vstandard_display_table
);
5188 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
5191 start
= desired_glyphs
->glyphs
[vpos
];
5193 if (obey_window_width
)
5195 start
+= XFASTINT (w
->left
);
5196 end
= start
+ window_width
- (truncate
!= 0);
5198 if (!WINDOW_RIGHTMOST_P (w
))
5200 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5204 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
5207 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5212 if (! obey_window_width
5213 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
5214 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
5216 /* Store 0 in charstart for these columns. */
5217 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
5218 desired_glyphs
->charstarts
[vpos
][i
] = 0;
5220 if (maxcol
>= 0 && mincol
> maxcol
)
5224 /* We need this value for multibyte characters. */
5225 length
= strlen (string
);
5227 /* We set truncated to 1 if we get stopped by trying to pass END
5228 (that is, trying to pass MAXCOL.) */
5237 c
= STRING_CHAR_AND_LENGTH (string
, length
, len
);
5239 c
= *string
, len
= 1;
5241 string
+= len
, length
-= len
;
5249 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
5251 p1
= copy_part_of_rope (f
, p1
, start
,
5252 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
5253 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
5256 else if (c
>= 040 && c
< 0177)
5266 if (p1
>= start
&& p1
< end
)
5270 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
5272 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
5276 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
5277 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
5278 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
5281 if (p1
>= start
&& p1
< end
)
5287 /* C is a multibyte character, control character or a binary
5289 int remaining_bytes
= len
;
5291 if (c
>= 0400 && CHAR_VALID_P (c
, 0))
5293 /* C is a multibyte character. */
5294 int charset
= CHAR_CHARSET (c
);
5295 int columns
= (charset
== CHARSET_COMPOSITION
5296 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
5297 : CHARSET_WIDTH (charset
));
5299 remaining_bytes
-= CHARSET_BYTES (charset
);
5302 /* Since we can't show the left part of C, fill all
5303 columns with spaces. */
5304 columns
-= start
- p1
;
5313 else if (p1
+ columns
> end
)
5315 /* Since we can't show the right part of C, fill all
5316 columns with TRUNCATE if TRUNCATE is specified. */
5320 *p1
++ = fix_glyph (f
, truncate
, 0);
5321 /* And tell the line is truncated. */
5328 /* We can show the whole glyph of C. */
5331 *p1
++ = c
| GLYPH_MASK_PADDING
;
5335 while (remaining_bytes
> 0)
5337 c
= *(string
- remaining_bytes
--);
5341 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
5342 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
5343 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
5346 if (p1
>= start
&& p1
< end
)
5347 *p1
= (c
>> 6) + '0';
5349 if (p1
>= start
&& p1
< end
)
5350 *p1
= (7 & (c
>> 3)) + '0';
5352 if (p1
>= start
&& p1
< end
)
5353 *p1
= (7 & c
) + '0';
5362 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
5364 else if (mincol
>= 0)
5366 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
5372 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
5374 if (len
> desired_glyphs
->used
[vpos
])
5375 desired_glyphs
->used
[vpos
] = len
;
5376 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
5382 /* This is like a combination of memq and assq.
5383 Return 1 if PROPVAL appears as an element of LIST
5384 or as the car of an element of LIST.
5385 If PROPVAL is a list, compare each element against LIST
5386 in that way, and return 1 if any element of PROPVAL is found in LIST.
5388 This function cannot quit. */
5391 invisible_p (propval
, list
)
5392 register Lisp_Object propval
;
5395 register Lisp_Object tail
, proptail
;
5396 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5398 register Lisp_Object tem
;
5399 tem
= XCONS (tail
)->car
;
5400 if (EQ (propval
, tem
))
5402 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5405 if (CONSP (propval
))
5406 for (proptail
= propval
; CONSP (proptail
);
5407 proptail
= XCONS (proptail
)->cdr
)
5409 Lisp_Object propelt
;
5410 propelt
= XCONS (proptail
)->car
;
5411 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5413 register Lisp_Object tem
;
5414 tem
= XCONS (tail
)->car
;
5415 if (EQ (propelt
, tem
))
5417 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5424 /* Return 1 if PROPVAL appears as the car of an element of LIST
5425 and the cdr of that element is non-nil.
5426 If PROPVAL is a list, check each element of PROPVAL in that way,
5427 and the first time some element is found,
5428 return 1 if the cdr of that element is non-nil.
5430 This function cannot quit. */
5433 invisible_ellipsis_p (propval
, list
)
5434 register Lisp_Object propval
;
5437 register Lisp_Object tail
, proptail
;
5438 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5440 register Lisp_Object tem
;
5441 tem
= XCONS (tail
)->car
;
5442 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5443 return ! NILP (XCONS (tem
)->cdr
);
5445 if (CONSP (propval
))
5446 for (proptail
= propval
; CONSP (proptail
);
5447 proptail
= XCONS (proptail
)->cdr
)
5449 Lisp_Object propelt
;
5450 propelt
= XCONS (proptail
)->car
;
5451 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5453 register Lisp_Object tem
;
5454 tem
= XCONS (tail
)->car
;
5455 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5456 return ! NILP (XCONS (tem
)->cdr
);
5465 staticpro (&Qinhibit_redisplay
);
5466 Qinhibit_redisplay
= intern ("inhibit-redisplay");
5468 staticpro (&Qmenu_bar_update_hook
);
5469 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
5471 staticpro (&Qoverriding_terminal_local_map
);
5472 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
5474 staticpro (&Qoverriding_local_map
);
5475 Qoverriding_local_map
= intern ("overriding-local-map");
5477 staticpro (&Qwindow_scroll_functions
);
5478 Qwindow_scroll_functions
= intern ("window-scroll-functions");
5480 staticpro (&Qredisplay_end_trigger_functions
);
5481 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
5483 staticpro (&Qinhibit_point_motion_hooks
);
5484 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
5486 staticpro (&last_arrow_position
);
5487 staticpro (&last_arrow_string
);
5488 last_arrow_position
= Qnil
;
5489 last_arrow_string
= Qnil
;
5491 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
5492 "Non-nil means don't actually do any redisplay.\n\
5493 This is used for internal purposes.");
5494 Vinhibit_redisplay
= Qnil
;
5496 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
5497 "String (or mode line construct) included (normally) in `mode-line-format'.");
5498 Vglobal_mode_string
= Qnil
;
5500 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
5501 "Marker for where to display an arrow on top of the buffer text.\n\
5502 This must be the beginning of a line in order to work.\n\
5503 See also `overlay-arrow-string'.");
5504 Voverlay_arrow_position
= Qnil
;
5506 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
5507 "String to display as an arrow. See also `overlay-arrow-position'.");
5508 Voverlay_arrow_string
= Qnil
;
5510 DEFVAR_INT ("scroll-step", &scroll_step
,
5511 "*The number of lines to try scrolling a window by when point moves out.\n\
5512 If that fails to bring point back on frame, point is centered instead.\n\
5513 If this is zero, point is always centered after it moves off frame.");
5515 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
5516 "*Scroll up to this many lines, to bring point back on screen.");
5517 scroll_conservatively
= 0;
5519 DEFVAR_INT ("scroll-margin", &scroll_margin
,
5520 "*Number of lines of margin at the top and bottom of a window.\n\
5521 Recenter the window whenever point gets within this many lines\n\
5522 of the top or bottom of the window.");
5525 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
5527 DEFVAR_BOOL ("truncate-partial-width-windows",
5528 &truncate_partial_width_windows
,
5529 "*Non-nil means truncate lines in all windows less than full frame wide.");
5530 truncate_partial_width_windows
= 1;
5532 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
5533 "*Non-nil means use inverse video for the mode line.");
5534 mode_line_inverse_video
= 1;
5536 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
5537 "*Maximum buffer size (in characters) for line number display\n\
5538 If the buffer is bigger than this, the line number does not appear\n\
5539 in the mode line..");
5540 line_number_display_limit
= 1000000;
5542 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
5543 "*Non-nil means highlight region even in nonselected windows.");
5544 highlight_nonselected_windows
= 0;
5546 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
5547 "Non-nil if more than one frame is visible on this display.\n\
5548 Minibuffer-only frames don't count, but iconified frames do.\n\
5549 This variable is not guaranteed to be accurate except while processing\n\
5550 `frame-title-format' and `icon-title-format'.");
5552 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
5553 "Template for displaying the titlebar of visible frames.\n\
5554 \(Assuming the window manager supports this feature.)\n\
5555 This variable has the same structure as `mode-line-format' (which see),\n\
5556 and is used only on frames for which no explicit name has been set\n\
5557 \(see `modify-frame-parameters').");
5558 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
5559 "Template for displaying the titlebar of an iconified frame.\n\
5560 \(Assuming the window manager supports this feature.)\n\
5561 This variable has the same structure as `mode-line-format' (which see),\n\
5562 and is used only on frames for which no explicit name has been set\n\
5563 \(see `modify-frame-parameters').");
5565 = Vframe_title_format
5566 = Fcons (intern ("multiple-frames"),
5567 Fcons (build_string ("%b"),
5568 Fcons (Fcons (build_string (""),
5569 Fcons (intern ("invocation-name"),
5570 Fcons (build_string ("@"),
5571 Fcons (intern ("system-name"),
5575 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
5576 "Maximum number of lines to keep in the message log buffer.\n\
5577 If nil, disable message logging. If t, log messages but don't truncate\n\
5578 the buffer when it becomes large.");
5579 XSETFASTINT (Vmessage_log_max
, 50);
5581 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
5582 "Functions called before redisplay, if window sizes have changed.\n\
5583 The value should be a list of functions that take one argument.\n\
5584 Just before redisplay, for each frame, if any of its windows have changed\n\
5585 size since the last redisplay, or have been split or deleted,\n\
5586 all the functions in the list are called, with the frame as argument.");
5587 Vwindow_size_change_functions
= Qnil
;
5589 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
5590 "List of functions to call before redisplaying a window with scrolling.\n\
5591 Each function is called with two arguments, the window\n\
5592 and its new display-start position. Note that the value of `window-end'\n\
5593 is not valid when these functions are called.");
5594 Vwindow_scroll_functions
= Qnil
;
5596 DEFVAR_INT ("minibuffer-scroll-overlap", &minibuffer_scroll_overlap
,
5597 "*Number of characters of overlap when scrolling a one-line window.\n\
5598 This commonly affects the minibuffer window, hence the name of the variable.");
5599 minibuffer_scroll_overlap
= 20;
5602 /* initialize the window system */
5606 Lisp_Object root_window
;
5607 #ifndef COMPILER_REGISTER_BUG
5609 #endif /* COMPILER_REGISTER_BUG */
5610 struct window
*mini_w
;
5612 this_line_bufpos
= 0;
5614 mini_w
= XWINDOW (minibuf_window
);
5615 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
5617 echo_area_glyphs
= 0;
5618 previous_echo_glyphs
= 0;
5620 if (!noninteractive
)
5622 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
5623 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_MENU_BAR_LINES (f
));
5624 set_window_height (root_window
,
5625 FRAME_HEIGHT (f
) - 1 - FRAME_MENU_BAR_LINES (f
),
5627 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
5628 set_window_height (minibuf_window
, 1, 0);
5630 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
5631 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));