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 /* A flag to control how to display unibyte 8-bit character. */
116 int unibyte_display_via_language_environment
;
118 /* Nonzero means we have more than one non-minibuffer-only frame.
119 Not guaranteed to be accurate except while parsing frame-title-format. */
122 Lisp_Object Vglobal_mode_string
;
124 /* Marker for where to display an arrow on top of the buffer text. */
125 Lisp_Object Voverlay_arrow_position
;
127 /* String to display for the arrow. */
128 Lisp_Object Voverlay_arrow_string
;
130 /* Values of those variables at last redisplay.
131 However, if Voverlay_arrow_position is a marker,
132 last_arrow_position is its numerical position. */
133 static Lisp_Object last_arrow_position
, last_arrow_string
;
135 /* Like mode-line-format, but for the titlebar on a visible frame. */
136 Lisp_Object Vframe_title_format
;
138 /* Like mode-line-format, but for the titlebar on an iconified frame. */
139 Lisp_Object Vicon_title_format
;
141 /* List of functions to call when a window's size changes. These
142 functions get one arg, a frame on which one or more windows' sizes
144 static Lisp_Object Vwindow_size_change_functions
;
146 Lisp_Object Qmenu_bar_update_hook
;
148 /* Nonzero if overlay arrow has been displayed once in this window. */
149 static int overlay_arrow_seen
;
151 /* Nonzero if visible end of buffer has already been displayed once
152 in this window. (We need this variable in case there are overlay
153 strings that get displayed there.) */
154 static int zv_strings_seen
;
156 /* Nonzero means highlight the region even in nonselected windows. */
157 static int highlight_nonselected_windows
;
159 /* If cursor motion alone moves point off frame,
160 Try scrolling this many lines up or down if that will bring it back. */
161 static int scroll_step
;
163 /* Non-0 means scroll just far enough to bring point back on the screen,
165 static int scroll_conservatively
;
167 /* Recenter the window whenever point gets within this many lines
168 of the top or bottom of the window. */
171 /* Number of characters of overlap to show,
172 when scrolling a one-line window such as a minibuffer. */
173 static int minibuffer_scroll_overlap
;
175 /* Nonzero if try_window_id has made blank lines at window bottom
176 since the last redisplay that paused */
177 static int blank_end_of_window
;
179 /* Number of windows showing the buffer of the selected window
180 (or another buffer with the same base buffer).
181 keyboard.c refers to this. */
184 /* display_text_line sets these to the frame position (origin 0) of point,
185 whether the window is selected or not.
186 Set one to -1 first to determine whether point was found afterwards. */
188 static int cursor_vpos
;
189 static int cursor_hpos
;
191 static int debug_end_pos
;
193 /* Nonzero means display mode line highlighted */
194 int mode_line_inverse_video
;
196 static void redisplay_internal ();
197 static int message_log_check_duplicate ();
198 static void echo_area_display ();
199 void mark_window_display_accurate ();
200 static void redisplay_windows ();
201 static void redisplay_window ();
202 static void update_menu_bar ();
203 static void try_window ();
204 static int try_window_id ();
205 static struct position
*display_text_line ();
206 static void display_mode_line ();
207 static int display_mode_element ();
208 static char *decode_mode_spec ();
209 static int display_string ();
210 static void display_menu_bar ();
211 static int display_count_lines ();
213 /* Prompt to display in front of the minibuffer contents */
214 Lisp_Object minibuf_prompt
;
216 /* Width in columns of current minibuffer prompt. */
217 int minibuf_prompt_width
;
219 /* Message to display instead of minibuffer contents
220 This is what the functions error and message make,
221 and command echoing uses it as well.
222 It overrides the minibuf_prompt as well as the buffer. */
223 char *echo_area_glyphs
;
225 /* This is the length of the message in echo_area_glyphs. */
226 int echo_area_glyphs_length
;
228 /* This is the window where the echo area message was displayed.
229 It is always a minibuffer window, but it may not be the
230 same window currently active as a minibuffer. */
231 Lisp_Object echo_area_window
;
233 /* Nonzero means multibyte characters were enabled when the echo area
234 message was specified. */
235 int message_enable_multibyte
;
237 /* true iff we should redraw the mode lines on the next redisplay */
238 int update_mode_lines
;
240 /* Smallest number of characters before the gap
241 at any time since last redisplay that finished.
242 Valid for current buffer when try_window_id can be called. */
245 /* Smallest number of characters after the gap
246 at any time since last redisplay that finished.
247 Valid for current buffer when try_window_id can be called. */
250 /* MODIFF as of last redisplay that finished;
251 if it matches MODIFF, and overlay_unchanged_modified
252 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
253 contain no useful information */
254 int unchanged_modified
;
256 /* OVERLAY_MODIFF as of last redisplay that finished. */
257 int overlay_unchanged_modified
;
259 /* Nonzero if window sizes or contents have changed
260 since last redisplay that finished */
261 int windows_or_buffers_changed
;
263 /* Nonzero after display_mode_line if %l was used
264 and it displayed a line number. */
265 int line_number_displayed
;
267 /* Maximum buffer size for which to display line numbers. */
268 static int line_number_display_limit
;
270 /* Number of lines to keep in the message log buffer.
271 t means infinite. nil means don't log at all. */
272 Lisp_Object Vmessage_log_max
;
274 #define COERCE_MARKER(X) \
275 (MARKERP ((X)) ? Fmarker_position (X) : (X))
277 static int pos_tab_offset
P_ ((struct window
*, int, int));
279 /* Output a newline in the *Messages* buffer if "needs" one. */
282 message_log_maybe_newline ()
284 if (message_log_need_newline
)
285 message_dolog ("", 0, 1, 0);
289 /* Add a string to the message log, optionally terminated with a newline.
290 This function calls low-level routines in order to bypass text property
291 hooks, etc. which might not be safe to run.
292 MULTIBYTE, if nonzero, means interpret the contents of M as multibyte. */
295 message_dolog (m
, len
, nlflag
, multibyte
)
297 int len
, nlflag
, multibyte
;
299 if (!NILP (Vmessage_log_max
))
301 struct buffer
*oldbuf
;
302 Lisp_Object oldpoint
, oldbegv
, oldzv
;
303 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
304 int point_at_end
= 0;
306 Lisp_Object old_deactivate_mark
, tem
;
307 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
309 old_deactivate_mark
= Vdeactivate_mark
;
310 oldbuf
= current_buffer
;
311 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
312 current_buffer
->undo_list
= Qt
;
314 oldpoint
= Fpoint_marker ();
315 oldbegv
= Fpoint_min_marker ();
316 oldzv
= Fpoint_max_marker ();
317 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
325 BEGV_BYTE
= BEG_BYTE
;
328 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
330 /* Insert the string--maybe converting multibyte to single byte
331 or vice versa, so that all the text fits the buffer. */
333 && NILP (current_buffer
->enable_multibyte_characters
))
336 unsigned char work
[1];
337 /* Convert a multibyte string to single-byte
338 for the *Message* buffer. */
339 for (i
= 0; i
< len
; i
+= nbytes
)
341 c
= STRING_CHAR_AND_LENGTH (m
+ i
, len
- i
, nbytes
);
342 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
344 : multibyte_char_to_unibyte (c
, Qnil
));
345 insert_1_both (work
, 1, 1, 1, 0, 0);
349 && ! NILP (current_buffer
->enable_multibyte_characters
))
352 unsigned char *msg
= (unsigned char *) m
;
353 unsigned char *str
, work
[4];
354 /* Convert a single-byte string to multibyte
355 for the *Message* buffer. */
356 for (i
= 0; i
< len
; i
++)
358 c
= unibyte_char_to_multibyte (msg
[i
]);
359 nbytes
= CHAR_STRING (c
, work
, str
);
360 insert_1_both (work
, 1, nbytes
, 1, 0, 0);
364 insert_1 (m
, len
, 1, 0, 0);
368 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
369 insert_1 ("\n", 1, 1, 0, 0);
371 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
373 this_bol_byte
= PT_BYTE
;
377 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
379 prev_bol_byte
= PT_BYTE
;
381 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
382 this_bol
, this_bol_byte
);
385 del_range_both (prev_bol
, prev_bol_byte
,
386 this_bol
, this_bol_byte
, 0);
392 /* If you change this format, don't forget to also
393 change message_log_check_duplicate. */
394 sprintf (dupstr
, " [%d times]", dup
);
395 duplen
= strlen (dupstr
);
396 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
397 insert_1 (dupstr
, duplen
, 1, 0, 1);
402 if (NATNUMP (Vmessage_log_max
))
404 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
405 -XFASTINT (Vmessage_log_max
) - 1, 0);
406 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
409 BEGV
= XMARKER (oldbegv
)->charpos
;
410 BEGV_BYTE
= marker_byte_position (oldbegv
);
419 ZV
= XMARKER (oldzv
)->charpos
;
420 ZV_BYTE
= marker_byte_position (oldzv
);
424 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
426 /* We can't do Fgoto_char (oldpoint) because it will run some
428 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
429 XMARKER (oldpoint
)->bytepos
);
432 free_marker (oldpoint
);
433 free_marker (oldbegv
);
436 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
437 set_buffer_internal (oldbuf
);
439 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
440 message_log_need_newline
= !nlflag
;
441 Vdeactivate_mark
= old_deactivate_mark
;
445 /* We are at the end of the buffer after just having inserted a newline.
446 (Note: We depend on the fact we won't be crossing the gap.)
447 Check to see if the most recent message looks a lot like the previous one.
448 Return 0 if different, 1 if the new one should just replace it, or a
449 value N > 1 if we should also append " [N times]". */
452 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
453 int prev_bol
, this_bol
;
454 int prev_bol_byte
, this_bol_byte
;
457 int len
= Z_BYTE
- 1 - this_bol_byte
;
459 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
460 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
462 for (i
= 0; i
< len
; i
++)
464 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
473 if (*p1
++ == ' ' && *p1
++ == '[')
476 while (*p1
>= '0' && *p1
<= '9')
477 n
= n
* 10 + *p1
++ - '0';
478 if (strncmp (p1
, " times]\n", 8) == 0)
484 /* Display an echo area message M with a specified length of LEN chars.
485 The string may include null characters. If M is 0, clear out any
486 existing message, and let the minibuffer text show through.
488 The buffer M must continue to exist until after the echo area
489 gets cleared or some other message gets displayed there.
491 Do not pass text that is stored in a Lisp string.
492 Do not pass text in a buffer that was alloca'd. */
495 message2 (m
, len
, multibyte
)
500 /* First flush out any partial line written with print. */
501 message_log_maybe_newline ();
503 message_dolog (m
, len
, 1, multibyte
);
504 message2_nolog (m
, len
, multibyte
);
508 /* The non-logging counterpart of message2. */
511 message2_nolog (m
, len
, multibyte
)
515 message_enable_multibyte
= multibyte
;
519 if (noninteractive_need_newline
)
521 noninteractive_need_newline
= 0;
523 fwrite (m
, len
, 1, stderr
);
524 if (cursor_in_echo_area
== 0)
525 fprintf (stderr
, "\n");
528 /* A null message buffer means that the frame hasn't really been
529 initialized yet. Error messages get reported properly by
530 cmd_error, so this must be just an informative message; toss it. */
531 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
533 Lisp_Object mini_window
;
536 /* Get the frame containing the minibuffer
537 that the selected frame is using. */
538 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
539 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
541 FRAME_SAMPLE_VISIBILITY (f
);
542 if (FRAME_VISIBLE_P (selected_frame
)
543 && ! FRAME_VISIBLE_P (f
))
544 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
548 echo_area_glyphs
= m
;
549 echo_area_glyphs_length
= len
;
551 if (minibuffer_auto_raise
)
552 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
555 echo_area_glyphs
= previous_echo_glyphs
= 0;
557 do_pending_window_change ();
558 echo_area_display ();
559 update_frame (f
, 1, 1);
560 do_pending_window_change ();
561 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
562 (*frame_up_to_date_hook
) (f
);
566 /* Display in echo area the null-terminated ASCII-only string M.
567 If M is 0, clear out any existing message,
568 and let the minibuffer text show through.
570 The string M must continue to exist until after the echo area
571 gets cleared or some other message gets displayed there.
573 Do not pass text that is stored in a Lisp string.
574 Do not pass text in a buffer that was alloca'd. */
580 message2 (m
, (m
? strlen (m
) : 0), 0);
587 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
590 /* Display a message M which contains a single %s
591 which gets replaced with STRING. */
594 message_with_string (m
, string
, log
)
603 if (noninteractive_need_newline
)
605 noninteractive_need_newline
= 0;
606 fprintf (stderr
, m
, XSTRING (string
)->data
);
607 if (cursor_in_echo_area
== 0)
608 fprintf (stderr
, "\n");
612 else if (INTERACTIVE
)
614 /* The frame whose minibuffer we're going to display the message on.
615 It may be larger than the selected frame, so we need
616 to use its buffer, not the selected frame's buffer. */
617 Lisp_Object mini_window
;
620 /* Get the frame containing the minibuffer
621 that the selected frame is using. */
622 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
623 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
625 /* A null message buffer means that the frame hasn't really been
626 initialized yet. Error messages get reported properly by
627 cmd_error, so this must be just an informative message; toss it. */
628 if (FRAME_MESSAGE_BUF (f
))
632 a
[0] = (char *) XSTRING (string
)->data
;
634 len
= doprnt (FRAME_MESSAGE_BUF (f
),
635 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
638 message2 (FRAME_MESSAGE_BUF (f
), len
,
639 STRING_MULTIBYTE (string
));
641 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
642 STRING_MULTIBYTE (string
));
644 /* Print should start at the beginning of the message
646 message_buf_print
= 0;
651 /* Truncate what will be displayed in the echo area
652 the next time we display it--but don't redisplay it now. */
655 truncate_echo_area (len
)
658 /* A null message buffer means that the frame hasn't really been
659 initialized yet. Error messages get reported properly by
660 cmd_error, so this must be just an informative message; toss it. */
661 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
662 echo_area_glyphs_length
= len
;
665 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
666 zero if being used by message. */
667 int message_buf_print
;
669 /* Dump an informative message to the minibuf. If M is 0, clear out
670 any existing message, and let the minibuffer text show through. */
674 message (m
, a1
, a2
, a3
)
676 EMACS_INT a1
, a2
, a3
;
682 if (noninteractive_need_newline
)
684 noninteractive_need_newline
= 0;
685 fprintf (stderr
, m
, a1
, a2
, a3
);
686 if (cursor_in_echo_area
== 0)
687 fprintf (stderr
, "\n");
691 else if (INTERACTIVE
)
693 /* The frame whose minibuffer we're going to display the message on.
694 It may be larger than the selected frame, so we need
695 to use its buffer, not the selected frame's buffer. */
696 Lisp_Object mini_window
;
699 /* Get the frame containing the minibuffer
700 that the selected frame is using. */
701 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
702 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
704 /* A null message buffer means that the frame hasn't really been
705 initialized yet. Error messages get reported properly by
706 cmd_error, so this must be just an informative message; toss it. */
707 if (FRAME_MESSAGE_BUF (f
))
718 len
= doprnt (FRAME_MESSAGE_BUF (f
),
719 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
721 len
= doprnt (FRAME_MESSAGE_BUF (f
),
722 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
724 #endif /* NO_ARG_ARRAY */
726 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
731 /* Print should start at the beginning of the message
733 message_buf_print
= 0;
738 /* The non-logging version of message. */
740 message_nolog (m
, a1
, a2
, a3
)
742 EMACS_INT a1
, a2
, a3
;
744 Lisp_Object old_log_max
;
745 old_log_max
= Vmessage_log_max
;
746 Vmessage_log_max
= Qnil
;
747 message (m
, a1
, a2
, a3
);
748 Vmessage_log_max
= old_log_max
;
754 message2 (echo_area_glyphs
, echo_area_glyphs_length
,
755 ! NILP (current_buffer
->enable_multibyte_characters
));
763 Lisp_Object mini_window
;
765 /* Choose the minibuffer window for this display.
766 It is the minibuffer window used by the selected frame. */
767 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
768 /* This is the frame that window is in. */
769 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
771 if (! FRAME_VISIBLE_P (f
))
776 redraw_garbaged_frames ();
780 if (echo_area_glyphs
|| minibuf_level
== 0)
784 echo_area_window
= mini_window
;
786 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
787 get_display_line (f
, vpos
, 0);
789 /* Make sure the columns that overlap a left-hand scroll bar
791 for (i
= 0; i
< FRAME_LEFT_SCROLL_BAR_WIDTH (f
); i
++)
792 f
->desired_glyphs
->glyphs
[vpos
][i
] = SPACEGLYPH
;
794 display_string (XWINDOW (mini_window
), vpos
,
795 echo_area_glyphs
? echo_area_glyphs
: "",
796 echo_area_glyphs
? echo_area_glyphs_length
: -1,
797 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
799 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
800 message_enable_multibyte
);
802 #if 0 /* This just gets in the way. update_frame does the job. */
803 /* If desired cursor location is on this line, put it at end of text */
804 if (cursor_in_echo_area
)
805 FRAME_CURSOR_Y (f
) = vpos
;
806 if (FRAME_CURSOR_Y (f
) == vpos
)
807 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
810 /* Fill the rest of the minibuffer window with blank lines. */
815 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
817 get_display_line (f
, i
, 0);
818 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
819 hpos, because it is good to clear whatever is behind the
820 scroll bar. This does not affect the scroll bar itself. */
821 display_string (XWINDOW (mini_window
), i
,
824 0, FRAME_WIDTH (f
) + FRAME_SCROLL_BAR_WIDTH (f
),
829 else if (!EQ (mini_window
, selected_window
))
830 windows_or_buffers_changed
++;
832 if (EQ (mini_window
, selected_window
))
833 this_line_bufpos
= 0;
835 previous_echo_glyphs
= echo_area_glyphs
;
838 /* Update frame titles. */
840 #ifdef HAVE_WINDOW_SYSTEM
841 static char frame_title_buf
[512];
842 static char *frame_title_ptr
;
845 store_frame_title (str
, mincol
, maxcol
)
850 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
851 maxcol
= sizeof (frame_title_buf
);
852 limit
= &frame_title_buf
[maxcol
];
853 while (*str
!= '\0' && frame_title_ptr
< limit
)
854 *frame_title_ptr
++ = *str
++;
855 while (frame_title_ptr
< &frame_title_buf
[mincol
])
856 *frame_title_ptr
++ = ' ';
857 return frame_title_ptr
- frame_title_buf
;
861 x_consider_frame_title (frame
)
867 FRAME_PTR f
= XFRAME (frame
);
869 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
872 /* Do we have more than one visible frame on this X display? */
876 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
878 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
880 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
881 && !FRAME_MINIBUF_ONLY_P (tf
)
882 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
886 multiple_frames
= CONSP (tail
);
889 obuf
= current_buffer
;
890 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
891 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
892 frame_title_ptr
= frame_title_buf
;
893 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
894 0, sizeof (frame_title_buf
), fmt
);
896 set_buffer_internal (obuf
);
897 /* Set the name only if it's changed. This avoids consing
898 in the common case where it hasn't. (If it turns out that we've
899 already wasted too much time by walking through the list with
900 display_mode_element, then we might need to optimize at a higher
902 if (! STRINGP (f
->name
) || STRING_BYTES (XSTRING (f
->name
)) != len
903 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
904 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
907 #define frame_title_ptr ((char *)0)
908 #define store_frame_title(str, mincol, maxcol) 0
911 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
912 This can call eval. */
917 register struct window
*w
= XWINDOW (selected_window
);
919 struct gcpro gcpro1
, gcpro2
;
921 all_windows
= (update_mode_lines
|| buffer_shared
> 1
922 || windows_or_buffers_changed
);
924 /* Update all frame titles based on their buffer names, etc.
925 We do this before the menu bars so that the buffer-menu
926 will show the up-to-date frame titles.
928 This used to be done after the menu bars, for a reason that
929 was stated as follows but which I do not understand:
930 "We do this after the menu bars so that the frame will first
931 create its menu bar using the name `emacs' if no other name
932 has yet been specified."
933 I think that is no longer a concern. */
934 #ifdef HAVE_WINDOW_SYSTEM
935 if (windows_or_buffers_changed
|| update_mode_lines
)
937 Lisp_Object tail
, frame
;
939 FOR_EACH_FRAME (tail
, frame
)
940 if (FRAME_VISIBLE_P (XFRAME (frame
))
941 || FRAME_ICONIFIED_P (XFRAME (frame
)))
942 x_consider_frame_title (frame
);
946 /* Update the menu bar item lists, if appropriate.
947 This has to be done before any actual redisplay
948 or generation of display lines. */
951 Lisp_Object tail
, frame
;
952 int count
= specpdl_ptr
- specpdl
;
954 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
956 FOR_EACH_FRAME (tail
, frame
)
958 /* If a window on this frame changed size,
959 report that to the user and clear the size-change flag. */
960 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
962 Lisp_Object functions
;
963 /* Clear flag first in case we get error below. */
964 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
965 functions
= Vwindow_size_change_functions
;
966 GCPRO2 (tail
, functions
);
967 while (CONSP (functions
))
969 call1 (XCONS (functions
)->car
, frame
);
970 functions
= XCONS (functions
)->cdr
;
975 update_menu_bar (XFRAME (frame
), 0);
979 unbind_to (count
, Qnil
);
982 update_menu_bar (selected_frame
, 1);
984 /* Motif needs this. See comment in xmenu.c.
985 Turn it off when pending_menu_activation is not defined. */
987 pending_menu_activation
= 0;
991 /* Do a frame update, taking possible shortcuts into account.
992 This is the main external entry point for redisplay.
994 If the last redisplay displayed an echo area message and that
995 message is no longer requested, we clear the echo area
996 or bring back the minibuffer if that is in use.
998 Do not call eval from within this function.
999 Calls to eval after the call to echo_area_display would confuse
1000 the display_line mechanism and would cause a crash.
1001 Calls to eval before that point will work most of the time,
1002 but can still lose, because this function
1003 can be called from signal handlers; with alarms set up;
1004 or with synchronous processes running.
1006 See Fcall_process; if you called it from here, it could be
1007 entered recursively. */
1009 static int do_verify_charstarts
;
1011 /* Counter is used to clear the face cache
1012 no more than once ever 1000 redisplays. */
1013 static int clear_face_cache_count
;
1015 /* Record the previous terminal frame we displayed. */
1016 static FRAME_PTR previous_terminal_frame
;
1021 redisplay_internal (0);
1024 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
1025 is not in response to any user action; therefore, we should
1026 preserve the echo area. (Actually, our caller does that job.)
1027 Perhaps in the future avoid recentering windows
1028 if it is not necessary; currently that causes some problems. */
1031 redisplay_internal (preserve_echo_area
)
1032 int preserve_echo_area
;
1034 register struct window
*w
= XWINDOW (selected_window
);
1036 int must_finish
= 0;
1038 register int tlbufpos
, tlendpos
;
1039 struct position pos
;
1040 int number_of_visible_frames
;
1045 #ifdef USE_X_TOOLKIT
1046 if (popup_activated ())
1050 if (! NILP (Vinhibit_redisplay
))
1055 if (! FRAME_WINDOW_P (selected_frame
)
1056 && previous_terminal_frame
!= selected_frame
)
1058 /* Since frames on an ASCII terminal share the same display area,
1059 displaying a different frame means redisplay the whole thing. */
1060 windows_or_buffers_changed
++;
1061 SET_FRAME_GARBAGED (selected_frame
);
1062 XSETFRAME (Vterminal_frame
, selected_frame
);
1064 previous_terminal_frame
= selected_frame
;
1066 /* Set the visible flags for all frames.
1067 Do this before checking for resized or garbaged frames; they want
1068 to know if their frames are visible.
1069 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
1071 Lisp_Object tail
, frame
;
1073 number_of_visible_frames
= 0;
1075 FOR_EACH_FRAME (tail
, frame
)
1077 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1079 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1080 number_of_visible_frames
++;
1082 /* Clear out all the display lines in which we will generate the
1083 glyphs to display. */
1084 init_desired_glyphs (XFRAME (frame
));
1088 /* Notice any pending interrupt request to change frame size. */
1089 do_pending_window_change ();
1093 redraw_garbaged_frames ();
1097 prepare_menu_bars ();
1099 if (windows_or_buffers_changed
)
1100 update_mode_lines
++;
1102 /* Detect case that we need to write or remove a star in the mode line. */
1103 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
1105 w
->update_mode_line
= Qt
;
1106 if (buffer_shared
> 1)
1107 update_mode_lines
++;
1110 /* If %c is in use, update it if needed. */
1111 if (!NILP (w
->column_number_displayed
)
1112 /* This alternative quickly identifies a common case
1113 where no change is needed. */
1114 && !(PT
== XFASTINT (w
->last_point
)
1115 && XFASTINT (w
->last_modified
) >= MODIFF
1116 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1117 && XFASTINT (w
->column_number_displayed
) != current_column ())
1118 w
->update_mode_line
= Qt
;
1120 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
1122 all_windows
= update_mode_lines
|| buffer_shared
> 1;
1124 /* If specs for an arrow have changed, do thorough redisplay
1125 to ensure we remove any arrow that should no longer exist. */
1126 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
1127 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
1130 /* Normally the message* functions will have already displayed and
1131 updated the echo area, but the frame may have been trashed, or
1132 the update may have been preempted, so display the echo area
1134 if (echo_area_glyphs
|| previous_echo_glyphs
)
1136 echo_area_display ();
1140 /* If showing region, and mark has changed, must redisplay whole window. */
1141 if (((!NILP (Vtransient_mark_mode
)
1142 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1143 != !NILP (w
->region_showing
))
1144 || (!NILP (w
->region_showing
)
1145 && !EQ (w
->region_showing
,
1146 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
1147 this_line_bufpos
= -1;
1149 tlbufpos
= this_line_bufpos
;
1150 tlendpos
= this_line_endpos
;
1151 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
1152 && !current_buffer
->clip_changed
1153 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
1154 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
1155 /* Make sure recorded data applies to current buffer, etc */
1156 && this_line_buffer
== current_buffer
1157 && current_buffer
== XBUFFER (w
->buffer
)
1158 && NILP (w
->force_start
)
1159 /* Point must be on the line that we have info recorded about */
1161 && PT
<= Z
- tlendpos
1162 /* All text outside that line, including its final newline,
1163 must be unchanged */
1164 && ((XFASTINT (w
->last_modified
) >= MODIFF
1165 && (XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
))
1166 || (beg_unchanged
>= tlbufpos
- 1
1168 /* If selective display, can't optimize
1169 if the changes start at the beginning of the line. */
1170 && ((INTEGERP (current_buffer
->selective_display
)
1171 && XINT (current_buffer
->selective_display
) > 0
1172 ? (beg_unchanged
>= tlbufpos
1175 && end_unchanged
>= tlendpos
1176 && Z
- GPT
>= tlendpos
)))
1178 int tlbufpos_byte
= CHAR_TO_BYTE (tlbufpos
);
1179 if (tlbufpos
> BEGV
&& FETCH_BYTE (tlbufpos_byte
- 1) != '\n'
1181 || FETCH_BYTE (tlbufpos_byte
) == '\n'))
1182 /* Former continuation line has disappeared by becoming empty */
1184 else if (XFASTINT (w
->last_modified
) < MODIFF
1185 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
1186 || MINI_WINDOW_P (w
))
1188 /* We have to handle the case of continuation around a
1189 wide-column character (See the comment in indent.c around
1192 For instance, in the following case:
1194 -------- Insert --------
1195 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1196 J_I_ ==> J_I_ `^^' are cursors.
1200 As we have to redraw the line above, we should goto cancel. */
1202 struct position val
;
1204 int opoint
= PT
, opoint_byte
= PT_BYTE
;
1206 scan_newline (tlbufpos
, tlbufpos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
1208 val
= *compute_motion (PT
, 0,
1209 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1212 1 << (BITS_PER_SHORT
- 1),
1213 1 << (BITS_PER_SHORT
- 1),
1214 window_internal_width (w
) - 1,
1215 XINT (w
->hscroll
), 0, w
);
1216 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
1217 if (val
.hpos
!= this_line_start_hpos
)
1221 overlay_arrow_seen
= 0;
1222 zv_strings_seen
= 0;
1223 display_text_line (w
, tlbufpos
, tlbufpos_byte
,
1224 this_line_vpos
, this_line_start_hpos
,
1225 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
), 0);
1226 /* If line contains point, is not continued,
1227 and ends at same distance from eob as before, we win */
1228 if (cursor_vpos
>= 0 && this_line_bufpos
1229 && this_line_endpos
== tlendpos
)
1231 /* If this is not the window's last line,
1232 we must adjust the charstarts of the lines below. */
1233 if (this_line_vpos
+ 1
1234 < XFASTINT (w
->top
) + window_internal_height (w
))
1236 int left
= WINDOW_LEFT_MARGIN (w
);
1237 int *charstart_next_line
1238 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
1241 if (Z
- tlendpos
== ZV
)
1242 /* This line ends at end of (accessible part of) buffer.
1243 There is no newline to count. */
1244 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
1246 /* This line ends in a newline.
1247 Must take account of the newline and the rest of the
1248 text that follows. */
1249 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
1251 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
1254 if (!WINDOW_FULL_WIDTH_P (w
))
1255 preserve_other_columns (w
);
1261 else if (PT
== XFASTINT (w
->last_point
)
1262 /* Make sure the cursor was last displayed
1263 in this window. Otherwise we have to reposition it. */
1264 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
1265 && (XINT (w
->top
) + XINT (w
->height
)
1266 > FRAME_CURSOR_Y (selected_frame
)))
1270 do_pending_window_change ();
1275 /* If highlighting the region, or if the cursor is in the echo area,
1276 then we can't just move the cursor. */
1277 else if (! (!NILP (Vtransient_mark_mode
)
1278 && !NILP (current_buffer
->mark_active
))
1279 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1280 || highlight_nonselected_windows
)
1281 && NILP (w
->region_showing
)
1282 && !cursor_in_echo_area
)
1284 pos
= *compute_motion (tlbufpos
, 0,
1285 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1287 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
1288 window_internal_width (w
) - 1,
1290 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
),
1294 int width
= window_internal_width (w
) - 1;
1295 FRAME_CURSOR_X (selected_frame
)
1296 = WINDOW_LEFT_MARGIN (w
) + minmax (0, pos
.hpos
, width
);
1297 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1304 /* Text changed drastically or point moved off of line */
1305 cancel_line (this_line_vpos
, selected_frame
);
1308 this_line_bufpos
= 0;
1309 all_windows
|= buffer_shared
> 1;
1311 clear_face_cache_count
++;
1315 Lisp_Object tail
, frame
;
1318 /* Clear the face cache, only when we do a full redisplay
1319 and not too often either. */
1320 if (clear_face_cache_count
> 1000)
1322 clear_face_cache ();
1323 clear_face_cache_count
= 0;
1327 /* Recompute # windows showing selected buffer.
1328 This will be incremented each time such a window is displayed. */
1331 FOR_EACH_FRAME (tail
, frame
)
1333 FRAME_PTR f
= XFRAME (frame
);
1334 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
1337 /* Mark all the scroll bars to be removed; we'll redeem the ones
1338 we want when we redisplay their windows. */
1339 if (condemn_scroll_bars_hook
)
1340 (*condemn_scroll_bars_hook
) (f
);
1342 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1343 redisplay_windows (FRAME_ROOT_WINDOW (f
), preserve_echo_area
);
1345 /* Any scroll bars which redisplay_windows should have nuked
1346 should now go away. */
1347 if (judge_scroll_bars_hook
)
1348 (*judge_scroll_bars_hook
) (f
);
1352 else if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1354 redisplay_window (selected_window
, 1, preserve_echo_area
);
1355 if (!WINDOW_FULL_WIDTH_P (w
))
1356 preserve_other_columns (w
);
1360 /* Prevent various kinds of signals during display update.
1361 stdio is not robust about handling signals,
1362 which can cause an apparent I/O error. */
1363 if (interrupt_input
)
1373 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1377 if (!FRAMEP (XCONS (tail
)->car
))
1380 f
= XFRAME (XCONS (tail
)->car
);
1382 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
1383 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1385 pause
|= update_frame (f
, 0, 0);
1388 mark_window_display_accurate (f
->root_window
, 1);
1389 if (frame_up_to_date_hook
!= 0)
1390 (*frame_up_to_date_hook
) (f
);
1397 if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1398 pause
= update_frame (selected_frame
, 0, 0);
1402 /* We may have called echo_area_display at the top of this
1403 function. If the echo area is on another frame, that may
1404 have put text on a frame other than the selected one, so the
1405 above call to update_frame would not have caught it. Catch
1408 Lisp_Object mini_window
;
1409 FRAME_PTR mini_frame
;
1411 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1412 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1414 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
1415 pause
|= update_frame (mini_frame
, 0, 0);
1419 /* If frame does not match, prevent doing single-line-update next time.
1420 Also, don't forget to check every line to update the arrow. */
1423 this_line_bufpos
= 0;
1424 if (!NILP (last_arrow_position
))
1426 last_arrow_position
= Qt
;
1427 last_arrow_string
= Qt
;
1429 /* If we pause after scrolling, some lines in current_frame
1430 may be null, so preserve_other_columns won't be able to
1431 preserve all the vertical-bar separators. So, avoid using it
1433 if (!WINDOW_FULL_WIDTH_P (w
))
1434 update_mode_lines
= 1;
1437 /* Now text on frame agrees with windows, so
1438 put info into the windows for partial redisplay to follow */
1442 register struct buffer
*b
= XBUFFER (w
->buffer
);
1444 blank_end_of_window
= 0;
1445 unchanged_modified
= BUF_MODIFF (b
);
1446 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
1447 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1448 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1450 /* Record the last place cursor was displayed in this window.
1451 But not if cursor is in the echo area, because in that case
1452 FRAME_CURSOR_X and FRAME_CURSOR_Y are in the echo area. */
1453 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (selected_frame
)
1454 && EQ (FRAME_MINIBUF_WINDOW (selected_frame
), minibuf_window
)))
1456 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1457 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1458 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1461 /* Make last_point invalid, since we don't really know
1462 where the cursor would be if it were not in the echo area. */
1463 XSETINT (w
->last_point
, -1);
1466 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1469 b
->clip_changed
= 0;
1470 w
->update_mode_line
= Qnil
;
1471 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1472 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
1474 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1477 /* Record if we are showing a region, so can make sure to
1478 update it fully at next redisplay. */
1479 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1480 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1481 || highlight_nonselected_windows
)
1482 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1483 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1486 w
->window_end_valid
= w
->buffer
;
1487 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1488 last_arrow_string
= Voverlay_arrow_string
;
1489 if (do_verify_charstarts
)
1490 verify_charstarts (w
);
1491 if (frame_up_to_date_hook
!= 0)
1492 (*frame_up_to_date_hook
) (selected_frame
);
1494 update_mode_lines
= 0;
1495 windows_or_buffers_changed
= 0;
1498 /* Start SIGIO interrupts coming again.
1499 Having them off during the code above
1500 makes it less likely one will discard output,
1501 but not impossible, since there might be stuff
1502 in the system buffer here.
1503 But it is much hairier to try to do anything about that. */
1505 if (interrupt_input
)
1509 /* If something has become visible now which was not before,
1510 redisplay again, so that we get them. */
1513 Lisp_Object tail
, frame
;
1516 FOR_EACH_FRAME (tail
, frame
)
1518 int this_is_visible
= 0;
1520 if (XFRAME (frame
)->visible
)
1521 this_is_visible
= 1;
1522 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1523 if (XFRAME (frame
)->visible
)
1524 this_is_visible
= 1;
1526 if (this_is_visible
)
1530 if (new_count
!= number_of_visible_frames
)
1531 windows_or_buffers_changed
++;
1534 /* Change frame size now if a change is pending. */
1535 do_pending_window_change ();
1537 /* If we just did a pending size change, or have additional
1538 visible frames, redisplay again. */
1539 if (windows_or_buffers_changed
&& !pause
)
1543 /* Redisplay, but leave alone any recent echo area message
1544 unless another message has been requested in its place.
1546 This is useful in situations where you need to redisplay but no
1547 user action has occurred, making it inappropriate for the message
1548 area to be cleared. See tracking_off and
1549 wait_reading_process_input for examples of these situations. */
1552 redisplay_preserve_echo_area ()
1554 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1556 echo_area_glyphs
= previous_echo_glyphs
;
1557 redisplay_internal (1);
1558 echo_area_glyphs
= 0;
1561 redisplay_internal (1);
1565 mark_window_display_accurate (window
, flag
)
1569 register struct window
*w
;
1571 for (;!NILP (window
); window
= w
->next
)
1573 if (!WINDOWP (window
)) abort ();
1574 w
= XWINDOW (window
);
1576 if (!NILP (w
->buffer
))
1578 XSETFASTINT (w
->last_modified
,
1579 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1580 XSETFASTINT (w
->last_overlay_modified
,
1581 !flag
? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)));
1583 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1586 /* Record if we are showing a region, so can make sure to
1587 update it fully at next redisplay. */
1588 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1589 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1590 || highlight_nonselected_windows
)
1591 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1592 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1596 w
->window_end_valid
= w
->buffer
;
1597 w
->update_mode_line
= Qnil
;
1598 if (!NILP (w
->buffer
) && flag
)
1599 XBUFFER (w
->buffer
)->clip_changed
= 0;
1601 if (!NILP (w
->vchild
))
1602 mark_window_display_accurate (w
->vchild
, flag
);
1603 if (!NILP (w
->hchild
))
1604 mark_window_display_accurate (w
->hchild
, flag
);
1609 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1610 last_arrow_string
= Voverlay_arrow_string
;
1614 /* t is unequal to any useful value of Voverlay_arrow_... */
1615 last_arrow_position
= Qt
;
1616 last_arrow_string
= Qt
;
1620 /* Update the menu bar item list for frame F.
1621 This has to be done before we start to fill in any display lines,
1622 because it can call eval.
1624 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1627 update_menu_bar (f
, save_match_data
)
1629 int save_match_data
;
1631 struct buffer
*old
= current_buffer
;
1633 register struct window
*w
;
1635 window
= FRAME_SELECTED_WINDOW (f
);
1636 w
= XWINDOW (window
);
1638 if (update_mode_lines
)
1639 w
->update_mode_line
= Qt
;
1641 if (FRAME_WINDOW_P (f
)
1643 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1644 FRAME_EXTERNAL_MENU_BAR (f
)
1646 FRAME_MENU_BAR_LINES (f
) > 0
1648 : FRAME_MENU_BAR_LINES (f
) > 0)
1650 /* If the user has switched buffers or windows, we need to
1651 recompute to reflect the new bindings. But we'll
1652 recompute when update_mode_lines is set too; that means
1653 that people can use force-mode-line-update to request
1654 that the menu bar be recomputed. The adverse effect on
1655 the rest of the redisplay algorithm is about the same as
1656 windows_or_buffers_changed anyway. */
1657 if (windows_or_buffers_changed
1658 || !NILP (w
->update_mode_line
)
1659 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1660 < BUF_MODIFF (XBUFFER (w
->buffer
)))
1661 != !NILP (w
->last_had_star
))
1662 || ((!NILP (Vtransient_mark_mode
)
1663 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1664 != !NILP (w
->region_showing
)))
1666 struct buffer
*prev
= current_buffer
;
1667 int count
= specpdl_ptr
- specpdl
;
1669 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1670 if (save_match_data
)
1671 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1672 if (NILP (Voverriding_local_map_menu_flag
))
1674 specbind (Qoverriding_terminal_local_map
, Qnil
);
1675 specbind (Qoverriding_local_map
, Qnil
);
1678 /* Run the Lucid hook. */
1679 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1680 /* If it has changed current-menubar from previous value,
1681 really recompute the menubar from the value. */
1682 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1683 call0 (Qrecompute_lucid_menubar
);
1684 safe_run_hooks (Qmenu_bar_update_hook
);
1685 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1686 /* Redisplay the menu bar in case we changed it. */
1687 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1688 if (FRAME_WINDOW_P (f
))
1689 set_frame_menubar (f
, 0, 0);
1691 /* On a terminal screen, the menu bar is an ordinary screen
1692 line, and this makes it get updated. */
1693 w
->update_mode_line
= Qt
;
1694 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1695 /* In the non-toolkit version, the menu bar is an ordinary screen
1696 line, and this makes it get updated. */
1697 w
->update_mode_line
= Qt
;
1698 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1700 unbind_to (count
, Qnil
);
1701 set_buffer_internal_1 (prev
);
1708 /* Redisplay WINDOW and its subwindows and siblings. */
1711 redisplay_windows (window
, preserve_echo_area
)
1713 int preserve_echo_area
;
1715 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1716 redisplay_window (window
, 0, preserve_echo_area
);
1719 /* Return value in display table DP (Lisp_Char_Table *) for character
1720 C. Since a display table doesn't have any parent, we don't have to
1721 follow parent. Do not call this function directly but use the
1722 macro DISP_CHAR_VECTOR. */
1724 disp_char_vector (dp
, c
)
1725 struct Lisp_Char_Table
*dp
;
1731 if (SINGLE_BYTE_CHAR_P (c
)) return (dp
->contents
[c
]);
1733 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
1734 if (code
[0] != CHARSET_COMPOSITION
)
1736 if (code
[1] < 32) code
[1] = -1;
1737 else if (code
[2] < 32) code
[2] = -1;
1739 /* Here, the possible range of CODE[0] (== charset ID) is
1740 128..MAX_CHARSET. Since the top level char table contains data
1741 for multibyte characters after 256th element, we must increment
1742 CODE[0] by 128 to get a correct index. */
1744 code
[3] = -1; /* anchor */
1746 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
1748 val
= dp
->contents
[code
[i
]];
1749 if (!SUB_CHAR_TABLE_P (val
))
1750 return (NILP (val
) ? dp
->defalt
: val
);
1752 /* Here, VAL is a sub char table. We return the default value of it. */
1753 return (dp
->defalt
);
1756 /* Redisplay window WINDOW and its subwindows. */
1759 redisplay_window (window
, just_this_one
, preserve_echo_area
)
1761 int just_this_one
, preserve_echo_area
;
1763 register struct window
*w
= XWINDOW (window
);
1764 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1767 int lpoint_byte
= PT_BYTE
;
1768 struct buffer
*old
= current_buffer
;
1769 register int width
= window_internal_width (w
) - 1;
1770 register int startp
, startp_byte
;
1771 register int hscroll
= XINT (w
->hscroll
);
1772 struct position pos
;
1774 int opoint_byte
= PT_BYTE
;
1776 int update_mode_line
;
1777 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1778 int really_switched_buffer
= 0;
1779 int count
= specpdl_ptr
- specpdl
;
1781 if (Z
== Z_BYTE
&& lpoint
!= lpoint_byte
)
1783 if (lpoint_byte
< lpoint
)
1786 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1788 /* If this is a combination window, do its children; that's all. */
1790 if (!NILP (w
->vchild
))
1792 redisplay_windows (w
->vchild
, preserve_echo_area
);
1795 if (!NILP (w
->hchild
))
1797 redisplay_windows (w
->hchild
, preserve_echo_area
);
1800 if (NILP (w
->buffer
))
1803 specbind (Qinhibit_point_motion_hooks
, Qt
);
1805 height
= window_internal_height (w
);
1806 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1807 if (XBUFFER (w
->buffer
)->clip_changed
)
1808 update_mode_line
= 1;
1810 if (MINI_WINDOW_P (w
))
1812 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1813 /* We've already displayed the echo area glyphs in this window. */
1814 goto finish_scroll_bars
;
1815 else if (w
!= XWINDOW (minibuf_window
))
1817 /* This is a minibuffer, but it's not the currently active one,
1819 int vpos
= XFASTINT (w
->top
);
1822 for (i
= 0; i
< height
; i
++)
1824 get_display_line (f
, vpos
+ i
, 0);
1825 display_string (w
, vpos
+ i
, "", 0,
1826 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
1830 goto finish_scroll_bars
;
1834 /* Otherwise set up data on this window; select its buffer and point value */
1836 if (update_mode_line
)
1837 /* Really select the buffer, for the sake of buffer-local variables. */
1839 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1840 really_switched_buffer
= 1;
1843 set_buffer_temp (XBUFFER (w
->buffer
));
1846 opoint_byte
= PT_BYTE
;
1848 if (Z
== Z_BYTE
&& opoint
!= opoint_byte
)
1850 if (opoint_byte
< opoint
)
1853 /* If %c is in mode line, update it if needed. */
1854 if (!NILP (w
->column_number_displayed
)
1855 /* This alternative quickly identifies a common case
1856 where no change is needed. */
1857 && !(PT
== XFASTINT (w
->last_point
)
1858 && XFASTINT (w
->last_modified
) >= MODIFF
1859 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1860 && XFASTINT (w
->column_number_displayed
) != current_column ())
1861 update_mode_line
= 1;
1863 /* Count number of windows showing the selected buffer.
1864 An indirect buffer counts as its base buffer. */
1868 struct buffer
*current_base
, *window_base
;
1869 current_base
= current_buffer
;
1870 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1871 if (current_base
->base_buffer
)
1872 current_base
= current_base
->base_buffer
;
1873 if (window_base
->base_buffer
)
1874 window_base
= window_base
->base_buffer
;
1875 if (current_base
== window_base
)
1879 /* POINT refers normally to the selected window.
1880 For any other window, set up appropriate value. */
1882 if (!EQ (window
, selected_window
))
1884 int new_pt
= XMARKER (w
->pointm
)->charpos
;
1885 int new_pt_byte
= marker_byte_position (w
->pointm
);
1889 new_pt_byte
= BEGV_BYTE
;
1890 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
1892 else if (new_pt
> (ZV
- 1))
1895 new_pt_byte
= ZV_BYTE
;
1896 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
1898 /* We don't use SET_PT so that the point-motion hooks don't run. */
1899 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
1902 /* If any of the character widths specified in the display table
1903 have changed, invalidate the width run cache. It's true that this
1904 may be a bit late to catch such changes, but the rest of
1905 redisplay goes (non-fatally) haywire when the display table is
1906 changed, so why should we worry about doing any better? */
1907 if (current_buffer
->width_run_cache
)
1909 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1911 if (! disptab_matches_widthtab (disptab
,
1912 XVECTOR (current_buffer
->width_table
)))
1914 invalidate_region_cache (current_buffer
,
1915 current_buffer
->width_run_cache
,
1917 recompute_width_table (current_buffer
, disptab
);
1921 /* If window-start is screwed up, choose a new one. */
1922 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1925 startp
= marker_position (w
->start
);
1926 startp_byte
= marker_byte_position (w
->start
);
1928 /* If someone specified a new starting point but did not insist,
1929 check whether it can be used. */
1930 if (!NILP (w
->optional_new_start
)
1931 && startp
>= BEGV
&& startp
<= ZV
)
1933 w
->optional_new_start
= Qnil
;
1934 /* Check whether this start pos is usable given where point is. */
1936 pos
= *compute_motion (startp
, 0,
1937 (((EQ (window
, minibuf_window
)
1939 ? minibuf_prompt_width
: 0)
1940 + (hscroll
? 1 - hscroll
: 0)),
1943 /* BUG FIX: See the comment of
1944 Fpos_visible_in_window_p (window.c). */
1945 - (1 << (BITS_PER_SHORT
- 1)),
1947 pos_tab_offset (w
, startp
, startp_byte
), w
);
1948 /* If PT does fit on the screen, we will use this start pos,
1949 so do so by setting force_start. */
1950 if (pos
.bufpos
== PT
)
1951 w
->force_start
= Qt
;
1954 /* Handle case where place to start displaying has been specified,
1955 unless the specified location is outside the accessible range. */
1956 if (!NILP (w
->force_start
))
1958 w
->force_start
= Qnil
;
1959 /* Forget any recorded base line for line number display. */
1960 w
->base_line_number
= Qnil
;
1961 /* The old bottom-of-screen position is no longer valid. */
1962 w
->window_end_valid
= Qnil
;
1963 /* Redisplay the mode line. Select the buffer properly for that.
1964 Also, run the hook window-scroll-functions
1965 because we have scrolled. */
1966 /* Note, we do this after clearing force_start because
1967 if there's an error, it is better to forget about force_start
1968 than to get into an infinite loop calling the hook functions
1969 and having them get more errors. */
1970 if (!update_mode_line
1971 || ! NILP (Vwindow_scroll_functions
))
1973 Lisp_Object temp
[3];
1975 if (!really_switched_buffer
)
1977 set_buffer_temp (old
);
1978 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1980 really_switched_buffer
= 1;
1981 update_mode_line
= 1;
1982 w
->update_mode_line
= Qt
;
1983 if (! NILP (Vwindow_scroll_functions
))
1985 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1986 make_number (startp
));
1987 startp
= marker_position (w
->start
);
1988 startp_byte
= marker_byte_position (w
->start
);
1991 XSETFASTINT (w
->last_modified
, 0);
1992 XSETFASTINT (w
->last_overlay_modified
, 0);
1993 if (startp
< BEGV
) startp
= BEGV
, startp_byte
= BEGV_BYTE
;
1994 if (startp
> ZV
) startp
= ZV
, startp
= ZV_BYTE
;
1995 try_window (window
, startp
);
1996 if (cursor_vpos
< 0)
1998 /* If point does not appear, move point so it does appear */
1999 pos
= *compute_motion (startp
, 0,
2000 (((EQ (window
, minibuf_window
)
2002 ? minibuf_prompt_width
: 0)
2003 + (hscroll
? 1 - hscroll
: 0)),
2006 - (1 << (BITS_PER_SHORT
- 1)),
2008 pos_tab_offset (w
, startp
, startp_byte
),
2010 TEMP_SET_PT_BOTH (pos
.bufpos
, pos
.bytepos
);
2011 if (w
!= XWINDOW (selected_window
))
2012 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
2015 if (current_buffer
== old
)
2018 lpoint_byte
= PT_BYTE
;
2020 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2021 + minmax (0, pos
.hpos
, width
));
2022 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2024 /* If we are highlighting the region,
2025 then we just changed the region, so redisplay to show it. */
2026 if (!NILP (Vtransient_mark_mode
)
2027 && !NILP (current_buffer
->mark_active
))
2029 cancel_my_columns (XWINDOW (window
));
2030 try_window (window
, startp
);
2036 /* Handle case where text has not changed, only point,
2037 and it has not moved off the frame. */
2039 /* This code is not used for minibuffer for the sake of
2040 the case of redisplaying to replace an echo area message;
2041 since in that case the minibuffer contents per se are usually unchanged.
2042 This code is of no real use in the minibuffer since
2043 the handling of this_line_bufpos, etc.,
2044 in redisplay handles the same cases. */
2046 if (XFASTINT (w
->last_modified
) >= MODIFF
2047 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
2048 && PT
>= startp
&& !current_buffer
->clip_changed
2049 && (just_this_one
|| WINDOW_FULL_WIDTH_P (w
))
2050 /* If force-mode-line-update was called, really redisplay;
2051 that's how redisplay is forced after e.g. changing
2052 buffer-invisibility-spec. */
2053 && NILP (w
->update_mode_line
)
2054 /* Can't use this case if highlighting a region. */
2055 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
2056 && NILP (w
->region_showing
)
2057 /* If end pos is out of date, scroll bar and percentage will be wrong */
2058 && INTEGERP (w
->window_end_vpos
)
2059 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
2060 && !EQ (window
, minibuf_window
)
2061 && (!MARKERP (Voverlay_arrow_position
)
2062 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
2064 /* All positions in this clause are relative to the window edge. */
2066 int this_scroll_margin
= scroll_margin
;
2067 int last_point_y
= XFASTINT (w
->last_point_y
) - XINT (w
->top
);
2068 int last_point_x
= (XFASTINT (w
->last_point_x
) - WINDOW_LEFT_MARGIN (w
));
2070 /* Find where PT is located now on the frame. */
2071 /* Check just_this_one as a way of verifying that the
2072 window edges have not changed. */
2073 if (PT
== XFASTINT (w
->last_point
) && just_this_one
2074 /* If CURSOR_IN_ECHO_AREA, last_point_x and last_point_y
2075 refer to the echo area and are not related to this window. */
2076 && ! cursor_in_echo_area
)
2078 pos
.hpos
= last_point_x
;
2079 pos
.vpos
= last_point_y
;
2082 else if (PT
> XFASTINT (w
->last_point
)
2083 && ! cursor_in_echo_area
2084 && XFASTINT (w
->last_point
) > startp
&& just_this_one
2085 /* We can't use this if point is in the left margin of a
2086 hscrolled window, because w->last_point_x has been
2087 clipped to the window edges. */
2088 && !(last_point_x
<= 0 && hscroll
))
2090 int last_point
= XFASTINT (w
->last_point
);
2091 int last_point_byte
= CHAR_TO_BYTE (last_point
);
2092 int tab_offset
= (pos_tab_offset (w
, last_point
, last_point_byte
)
2093 - (last_point_x
+ hscroll
- !! hscroll
));
2095 pos
= *compute_motion (last_point
, last_point_y
, last_point_x
, 1,
2097 /* BUG FIX: See the comment of
2098 Fpos_visible_in_window_p (window.c). */
2099 - (1 << (BITS_PER_SHORT
- 1)),
2106 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
2108 /* BUG FIX: See the comment of
2109 Fpos_visible_in_window_p (window.c). */
2110 - (1 << (BITS_PER_SHORT
- 1)),
2112 pos_tab_offset (w
, startp
, startp_byte
),
2116 /* Don't use a scroll margin that is negative or too large. */
2117 if (this_scroll_margin
< 0)
2118 this_scroll_margin
= 0;
2120 if (XINT (w
->height
) < 4 * scroll_margin
)
2121 this_scroll_margin
= XINT (w
->height
) / 4;
2123 /* If point fits on the screen, and not within the scroll margin,
2125 if (pos
.vpos
< height
- this_scroll_margin
2126 && (pos
.vpos
>= this_scroll_margin
|| startp
== BEGV
))
2128 /* Ok, point is still on frame */
2129 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
2131 /* These variables are supposed to be origin 1 */
2132 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2133 + minmax (0, pos
.hpos
, width
));
2134 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2136 /* This doesn't do the trick, because if a window to the right of
2137 this one must be redisplayed, this does nothing because there
2138 is nothing in DesiredFrame yet, and then the other window is
2139 redisplayed, making likes that are empty in this window's columns.
2140 if (WINDOW_FULL_WIDTH_P (w))
2141 preserve_my_columns (w);
2143 if (current_buffer
->clip_changed
2144 && ! NILP (Vwindow_scroll_functions
))
2145 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2146 make_number (marker_position (w
->start
)));
2150 /* Don't bother trying redisplay with same start;
2151 we already know it will lose. */
2153 /* If current starting point was originally the beginning of a line
2154 but no longer is, find a new starting point. */
2155 else if (!NILP (w
->start_at_line_beg
)
2157 || FETCH_BYTE (startp_byte
- 1) == '\n'))
2161 else if (just_this_one
&& !MINI_WINDOW_P (w
)
2163 && XFASTINT (w
->last_modified
)
2164 /* or else vmotion on first line won't work. */
2165 && ! NILP (w
->start_at_line_beg
)
2166 && ! EQ (w
->window_end_valid
, Qnil
)
2167 && do_id
&& !current_buffer
->clip_changed
2168 && !blank_end_of_window
2169 && WINDOW_FULL_WIDTH_P (w
)
2170 /* Can't use this case if highlighting a region. */
2171 && !(!NILP (Vtransient_mark_mode
)
2172 && !NILP (current_buffer
->mark_active
))
2173 /* Don't use try_window_id if newline
2174 doesn't display as the end of a line. */
2175 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
2176 && NILP (w
->region_showing
)
2177 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
2178 && EQ (last_arrow_string
, Voverlay_arrow_string
)
2179 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
2182 /* tem > 0 means success. tem == -1 means choose new start.
2183 tem == -2 means try again with same start,
2184 and nothing but whitespace follows the changed stuff.
2185 tem == 0 means try again with same start. */
2189 else if (startp
>= BEGV
&& startp
<= ZV
2191 /* Avoid starting at end of buffer. */
2192 #if 0 /* This change causes trouble for M-! finger & RET.
2193 It will have to be considered later. */
2194 || ! EQ (window
, selected_window
)
2195 /* Don't do the recentering if redisplay
2196 is not for no user action. */
2197 || preserve_echo_area
2200 || (XFASTINT (w
->last_modified
) >= MODIFF
2201 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
2203 /* Try to redisplay starting at same place as before */
2204 /* If point has not moved off frame, accept the results */
2205 try_window (window
, startp
);
2206 if (cursor_vpos
>= 0)
2208 if (!just_this_one
|| current_buffer
->clip_changed
2209 || beg_unchanged
< startp
)
2210 /* Forget any recorded base line for line number display. */
2211 w
->base_line_number
= Qnil
;
2213 if (current_buffer
->clip_changed
2214 && ! NILP (Vwindow_scroll_functions
))
2215 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2216 make_number (marker_position (w
->start
)));
2221 cancel_my_columns (w
);
2224 XSETFASTINT (w
->last_modified
, 0);
2225 XSETFASTINT (w
->last_overlay_modified
, 0);
2226 /* Redisplay the mode line. Select the buffer properly for that. */
2227 if (!update_mode_line
)
2229 if (!really_switched_buffer
)
2231 set_buffer_temp (old
);
2232 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2234 update_mode_line
= 1;
2235 w
->update_mode_line
= Qt
;
2238 /* Try to scroll by specified few lines */
2240 if ((scroll_conservatively
|| scroll_step
)
2241 && !current_buffer
->clip_changed
2242 && startp
>= BEGV
&& startp
<= ZV
)
2244 int this_scroll_margin
= scroll_margin
;
2245 int scroll_margin_pos
, scroll_margin_bytepos
;
2246 int scroll_max
= scroll_step
;
2249 if (scroll_conservatively
)
2250 scroll_max
= scroll_conservatively
;
2252 /* Don't use a scroll margin that is negative or too large. */
2253 if (this_scroll_margin
< 0)
2254 this_scroll_margin
= 0;
2256 if (XINT (w
->height
) < 4 * this_scroll_margin
)
2257 this_scroll_margin
= XINT (w
->height
) / 4;
2259 ltemp
= Fwindow_end (window
, Qt
);
2260 scroll_margin_pos
= XINT (ltemp
);
2262 if (this_scroll_margin
)
2264 pos
= *vmotion (scroll_margin_pos
, -this_scroll_margin
, w
);
2265 scroll_margin_pos
= pos
.bufpos
;
2266 scroll_margin_bytepos
= pos
.bytepos
;
2269 scroll_margin_bytepos
= CHAR_TO_BYTE (scroll_margin_pos
);
2271 if (PT
>= scroll_margin_pos
)
2273 struct position pos
;
2274 pos
= *compute_motion (scroll_margin_pos
, 0, 0, 0,
2275 PT
, XFASTINT (w
->height
), 0,
2276 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2277 pos_tab_offset (w
, scroll_margin_pos
,
2278 scroll_margin_bytepos
),
2280 if (pos
.vpos
>= scroll_max
)
2283 pos
= *vmotion (startp
,
2284 scroll_conservatively
? pos
.vpos
+ 1 : scroll_step
,
2287 /* The old bottom-of-screen position is no longer valid. */
2288 w
->window_end_valid
= Qnil
;
2289 if (! NILP (Vwindow_scroll_functions
))
2291 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2292 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2293 make_number (pos
.bufpos
));
2294 pos
.bufpos
= marker_position (w
->start
);
2296 try_window (window
, pos
.bufpos
);
2297 if (cursor_vpos
>= 0)
2299 if (!just_this_one
|| current_buffer
->clip_changed
2300 || beg_unchanged
< startp
)
2301 /* Forget any recorded base line for line number display. */
2302 w
->base_line_number
= Qnil
;
2306 cancel_my_columns (w
);
2309 scroll_margin_pos
= startp
;
2310 if (this_scroll_margin
)
2312 pos
= *vmotion (scroll_margin_pos
, this_scroll_margin
, w
);
2313 scroll_margin_pos
= pos
.bufpos
;
2315 if (PT
< scroll_margin_pos
)
2317 struct position pos
;
2318 pos
= *compute_motion (PT
, 0, 0, 0,
2319 scroll_margin_pos
, XFASTINT (w
->height
), 0,
2320 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2321 pos_tab_offset (w
, PT
, PT_BYTE
),
2323 if (pos
.vpos
> scroll_max
)
2326 pos
= *vmotion (startp
,
2327 scroll_conservatively
? -pos
.vpos
: - scroll_step
,
2330 /* The old bottom-of-screen position is no longer valid. */
2331 w
->window_end_valid
= Qnil
;
2332 if (! NILP (Vwindow_scroll_functions
))
2334 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2335 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2336 make_number (pos
.bufpos
));
2337 pos
.bufpos
= marker_position (w
->start
);
2339 try_window (window
, pos
.bufpos
);
2340 if (cursor_vpos
>= 0)
2342 if (!just_this_one
|| current_buffer
->clip_changed
2343 || beg_unchanged
< startp
)
2344 /* Forget any recorded base line for line number display. */
2345 w
->base_line_number
= Qnil
;
2349 cancel_my_columns (w
);
2355 if (scroll_step
&& ! scroll_margin
&& !current_buffer
->clip_changed
2356 && startp
>= BEGV
&& startp
<= ZV
)
2358 if (margin_call
== 0)
2359 margin_call
= (PT
> startp
? 1 : -1);
2360 if (margin_call
> 0)
2362 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
2363 if (pos
.vpos
>= height
)
2367 pos
= *vmotion (startp
, (margin_call
< 0 ? - scroll_step
: scroll_step
),
2370 if (PT
>= pos
.bufpos
)
2372 /* The old bottom-of-screen position is no longer valid. */
2373 w
->window_end_valid
= Qnil
;
2375 if (! NILP (Vwindow_scroll_functions
))
2377 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2378 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2379 make_number (pos
.bufpos
));
2380 pos
.bufpos
= marker_position (w
->start
);
2382 try_window (window
, pos
.bufpos
);
2383 if (cursor_vpos
>= 0)
2385 if (!just_this_one
|| current_buffer
->clip_changed
2386 || beg_unchanged
< startp
)
2387 /* Forget any recorded base line for line number display. */
2388 w
->base_line_number
= Qnil
;
2392 cancel_my_columns (w
);
2398 /* Finally, just choose place to start which centers point */
2401 /* Forget any previously recorded base line for line number display. */
2402 w
->base_line_number
= Qnil
;
2404 pos
= *vmotion (PT
, - (height
/ 2), w
);
2406 /* The minibuffer is often just one line. Ordinary scrolling
2407 gives little overlap and looks bad. So show 20 chars before point. */
2409 && (pos
.bufpos
>= PT
- minibuffer_scroll_overlap
2410 /* If we scrolled less than 1/2 line forward, we will
2411 get too much overlap, so change to the usual amount. */
2412 || pos
.bufpos
< startp
+ width
/ 2)
2413 && PT
> BEGV
+ minibuffer_scroll_overlap
2414 /* If we scrolled to an actual line boundary,
2415 that's different; don't ignore line boundaries. */
2416 && FETCH_BYTE (pos
.bytepos
- 1) != '\n')
2418 pos
.bufpos
= PT
- minibuffer_scroll_overlap
;
2419 pos
.bytepos
= CHAR_TO_BYTE (pos
.bufpos
);
2422 /* Set startp here explicitly in case that helps avoid an infinite loop
2423 in case the window-scroll-functions functions get errors. */
2424 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2426 /* The old bottom-of-screen position is no longer valid. */
2427 w
->window_end_valid
= Qnil
;
2428 if (! NILP (Vwindow_scroll_functions
))
2430 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2431 make_number (pos
.bufpos
));
2432 pos
.bufpos
= marker_position (w
->start
);
2433 pos
.bytepos
= marker_byte_position (w
->start
);
2435 try_window (window
, pos
.bufpos
);
2437 startp
= marker_position (w
->start
);
2438 startp_byte
= marker_byte_position (w
->start
);
2439 w
->start_at_line_beg
2440 = (startp
== BEGV
|| FETCH_BYTE (startp_byte
- 1) == '\n') ? Qt
: Qnil
;
2443 if ((update_mode_line
2444 /* If window not full width, must redo its mode line
2445 if the window to its side is being redone */
2446 || (!just_this_one
&& !WINDOW_FULL_WIDTH_P (w
))
2447 || INTEGERP (w
->base_line_pos
)
2448 || (!NILP (w
->column_number_displayed
)
2449 && XFASTINT (w
->column_number_displayed
) != current_column ()))
2450 && height
!= XFASTINT (w
->height
))
2452 FRAME_PTR oframe
= selected_frame
;
2453 if (!really_switched_buffer
)
2455 set_buffer_temp (old
);
2456 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2457 really_switched_buffer
= 1;
2460 display_mode_line (w
);
2461 selected_frame
= oframe
;
2463 if (! line_number_displayed
2464 && ! BUFFERP (w
->base_line_pos
))
2466 w
->base_line_pos
= Qnil
;
2467 w
->base_line_number
= Qnil
;
2470 /* When we reach a frame's selected window, redo the frame's menu bar. */
2471 if (update_mode_line
2472 && (FRAME_WINDOW_P (f
)
2474 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2475 FRAME_EXTERNAL_MENU_BAR (f
)
2477 FRAME_MENU_BAR_LINES (f
) > 0
2479 : FRAME_MENU_BAR_LINES (f
) > 0)
2480 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
2481 display_menu_bar (w
);
2484 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2486 int start
, end
, whole
;
2488 /* Calculate the start and end positions for the current window.
2489 At some point, it would be nice to choose between scrollbars
2490 which reflect the whole buffer size, with special markers
2491 indicating narrowing, and scrollbars which reflect only the
2494 Note that minibuffers sometimes aren't displaying any text. */
2495 if (! MINI_WINDOW_P (w
)
2496 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
2499 start
= marker_position (w
->start
) - BEGV
;
2500 /* I don't think this is guaranteed to be right. For the
2501 moment, we'll pretend it is. */
2502 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
2504 if (end
< start
) end
= start
;
2505 if (whole
< (end
- start
)) whole
= end
- start
;
2508 start
= end
= whole
= 0;
2510 /* Indicate what this scroll bar ought to be displaying now. */
2511 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
2513 /* Note that we actually used the scroll bar attached to this window,
2514 so it shouldn't be deleted at the end of redisplay. */
2515 (*redeem_scroll_bar_hook
) (w
);
2518 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
2519 if (really_switched_buffer
)
2520 set_buffer_internal_1 (old
);
2522 set_buffer_temp (old
);
2523 TEMP_SET_PT_BOTH (lpoint
, lpoint_byte
);
2525 unbind_to (count
, Qnil
);
2528 /* Do full redisplay on one window, starting at position `pos'. */
2531 try_window (window
, pos
)
2535 register struct window
*w
= XWINDOW (window
);
2536 register int height
= window_internal_height (w
);
2537 register int vpos
= XFASTINT (w
->top
);
2538 register int last_text_vpos
= vpos
;
2539 FRAME_PTR f
= XFRAME (w
->frame
);
2540 int width
= window_internal_width (w
) - 1;
2541 struct position val
;
2543 /* POS should never be out of range! */
2544 if (pos
< XBUFFER (w
->buffer
)->begv
2545 || pos
> XBUFFER (w
->buffer
)->zv
)
2548 if (XMARKER (w
->start
)->charpos
!= pos
)
2549 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2552 overlay_arrow_seen
= 0;
2553 zv_strings_seen
= 0;
2554 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2555 val
.ovstring_chars_done
= 0;
2556 val
.bytepos
= marker_byte_position (w
->start
);
2557 val
.tab_offset
= pos_tab_offset (w
, pos
, val
.bytepos
);
2559 while (--height
>= 0)
2561 val
= *display_text_line (w
, pos
, val
.bytepos
, vpos
,
2562 val
.hpos
, val
.tab_offset
,
2563 val
.ovstring_chars_done
);
2564 /* The following code is omitted because we maintain tab_offset
2567 tab_offset
+= width
;
2568 if (val
.vpos
) tab_offset
= 0;
2571 if (pos
!= val
.bufpos
)
2574 #ifdef USE_TEXT_PROPERTIES
2575 Lisp_Object invis_prop
;
2576 invis_prop
= Fget_char_property (make_number (val
.bufpos
- 1),
2577 Qinvisible
, window
);
2578 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
2582 /* Next line, unless prev line ended in end of buffer with no cr */
2584 && (FETCH_BYTE (val
.bytepos
- 1) != '\n' || invis
));
2589 /* If last line is continued in middle of character,
2590 include the split character in the text considered on the frame */
2591 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2594 /* If bottom just moved off end of frame, change mode line percentage. */
2595 if (XFASTINT (w
->window_end_pos
) == 0
2597 w
->update_mode_line
= Qt
;
2599 /* Say where last char on frame will be, once redisplay is finished. */
2600 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
2601 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
2602 /* But that is not valid info until redisplay finishes. */
2603 w
->window_end_valid
= Qnil
;
2606 /* Try to redisplay when buffer is modified locally,
2607 computing insert/delete line to preserve text outside
2608 the bounds of the changes.
2609 Return 1 if successful, 0 if if cannot tell what to do,
2610 or -1 to tell caller to find a new window start,
2611 or -2 to tell caller to do normal redisplay with same window start. */
2614 try_window_id (window
)
2618 int opoint
, opoint_byte
;
2619 register struct window
*w
= XWINDOW (window
);
2620 register int height
= window_internal_height (w
);
2621 FRAME_PTR f
= XFRAME (w
->frame
);
2622 int top
= XFASTINT (w
->top
);
2623 int start
= marker_position (w
->start
);
2624 int width
= window_internal_width (w
) - 1;
2625 int hscroll
= XINT (w
->hscroll
);
2626 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
2629 register int i
, tem
;
2630 int last_text_vpos
= 0;
2632 int selective
= (INTEGERP (current_buffer
->selective_display
)
2633 ? XINT (current_buffer
->selective_display
)
2634 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2635 struct position val
, bp
, ep
, xp
, pp
;
2636 int scroll_amount
= 0;
2640 int start_byte
= marker_byte_position (w
->start
);
2642 if (GPT
- BEG
< beg_unchanged
)
2643 beg_unchanged
= GPT
- BEG
;
2644 if (Z
- GPT
< end_unchanged
)
2645 end_unchanged
= Z
- GPT
;
2647 if (beg_unchanged
+ BEG
< start
)
2648 return 0; /* Give up if changes go above top of window */
2650 /* Find position before which nothing is changed. */
2651 bp
= *compute_motion (start
, 0, lmargin
, 0,
2652 min (ZV
, beg_unchanged
+ BEG
), height
,
2653 /* BUG FIX: See the comment of
2654 Fpos_visible_in_window_p (window.c). */
2655 - (1 << (BITS_PER_SHORT
- 1)),
2657 pos_tab_offset (w
, start
, start_byte
),
2659 if (bp
.vpos
>= height
)
2663 /* All changes are beyond the window end, and point is on the screen.
2664 We don't need to change the text at all.
2665 But we need to update window_end_pos to account for
2666 any change in buffer size. */
2667 bp
= *compute_motion (start
, 0, lmargin
, 0,
2669 /* BUG FIX: See the comment of
2670 Fpos_visible_in_window_p() (window.c). */
2671 - (1 << (BITS_PER_SHORT
- 1)),
2673 pos_tab_offset (w
, start
, start_byte
), w
);
2674 XSETFASTINT (w
->window_end_vpos
, height
);
2675 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
2683 /* Find beginning of that frame line. Must display from there. */
2684 bp
= *vmotion (bp
.bufpos
, 0, w
);
2687 pos_byte
= bp
.bytepos
;
2693 /* If about to start displaying at the beginning of a continuation line,
2694 really start with previous frame line, in case it was not
2695 continued when last redisplayed */
2696 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
2698 /* Likewise if we have to worry about selective display. */
2699 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
2701 bp
= *vmotion (bp
.bufpos
, -1, w
);
2704 pos_byte
= bp
.bytepos
;
2706 val
.tab_offset
= bp
.tab_offset
; /* Update tab offset. */
2708 if (bp
.contin
&& bp
.hpos
!= lmargin
)
2710 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
2711 val
.tab_offset
= bp
.tab_offset
+ bp
.prevhpos
- width
;
2713 DEC_BOTH (pos
, pos_byte
);
2718 /* Find first visible newline after which no more is changed. */
2719 opoint
= PT
, opoint_byte
= PT_BYTE
;
2720 TEMP_SET_PT (Z
- max (end_unchanged
, Z
- ZV
));
2721 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2723 while (PT
< ZV
- 1 && indented_beyond_p (PT
, PT_BYTE
, selective
))
2724 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2726 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
2728 /* Compute the cursor position after that newline. */
2729 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
2730 height
, - (1 << (BITS_PER_SHORT
- 1)),
2732 /* We have tab offset in VAL, use it. */
2735 /* If changes reach past the text available on the frame,
2736 just display rest of frame. */
2737 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
2740 stop_vpos
= ep
.vpos
;
2742 /* If no newline before ep, the line ep is on includes some changes
2743 that must be displayed. Make sure we don't stop before it. */
2744 /* Also, if changes reach all the way until ep.bufpos,
2745 it is possible that something was deleted after the
2746 newline before it, so the following line must be redrawn. */
2747 if (stop_vpos
== ep
.vpos
2748 && (ep
.bufpos
== BEGV
2749 || FETCH_BYTE (ep
.bytepos
- 1) != '\n'
2750 || ep
.bufpos
== Z
- end_unchanged
))
2751 stop_vpos
= ep
.vpos
+ 1;
2754 overlay_arrow_seen
= 0;
2755 zv_strings_seen
= 0;
2757 /* If changes do not reach to bottom of window,
2758 figure out how much to scroll the rest of the window */
2759 if (stop_vpos
< height
)
2761 /* Now determine how far up or down the rest of the window has moved */
2762 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2763 Z
- XFASTINT (w
->window_end_pos
),
2764 /* Don't care for VPOS... */
2765 1 << (BITS_PER_SHORT
- 1),
2767 1 << (BITS_PER_SHORT
- 1),
2768 width
, hscroll
, ep
.tab_offset
, w
);
2769 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2771 /* Is everything on frame below the changes whitespace?
2772 If so, no scrolling is really necessary. */
2773 for (i
= ep
.bytepos
; i
< xp
.bytepos
; i
++)
2775 tem
= FETCH_BYTE (i
);
2776 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2779 if (i
== xp
.bytepos
)
2782 XSETFASTINT (w
->window_end_vpos
,
2783 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2785 /* Before doing any scrolling, verify that point will be on frame. */
2786 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.vpos
< height
))
2788 if (PT
<= xp
.bufpos
)
2790 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2791 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2793 /* We have tab offset in EP, use it. */
2798 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2799 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2801 /* We have tab offset in XP, use it. */
2804 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2806 cursor_vpos
= pp
.vpos
+ top
;
2807 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, pp
.hpos
, width
);
2810 if (stop_vpos
- scroll_amount
>= height
2811 || ep
.bufpos
== xp
.bufpos
)
2813 if (scroll_amount
< 0)
2814 stop_vpos
-= scroll_amount
;
2816 /* In this path, we have altered window_end_vpos
2817 and not left it negative.
2818 We must make sure that, in case display is preempted
2819 before the frame changes to reflect what we do here,
2820 further updates will not come to try_window_id
2821 and assume the frame and window_end_vpos match. */
2822 blank_end_of_window
= 1;
2824 else if (!scroll_amount
)
2826 /* Even if we don't need to scroll, we must adjust the
2827 charstarts of subsequent lines (that we won't redisplay)
2828 according to the amount of text inserted or deleted. */
2829 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2830 int adjust
= ep
.bufpos
- oldpos
;
2831 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2833 else if (bp
.bufpos
== Z
- end_unchanged
)
2835 /* If reprinting everything is nearly as fast as scrolling,
2836 don't bother scrolling. Can happen if lines are short. */
2837 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2838 top
+ height
- max (0, scroll_amount
),
2840 > xp
.bufpos
- bp
.bufpos
- 20)
2841 /* Return "try normal display with same window-start."
2842 Too bad we can't prevent further scroll-thinking. */
2844 /* If pure deletion, scroll up as many lines as possible.
2845 In common case of killing a line, this can save the
2846 following line from being overwritten by scrolling
2847 and therefore having to be redrawn. */
2848 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2849 top
+ height
- max (0, scroll_amount
),
2850 scroll_amount
, bp
.bufpos
);
2855 /* scroll_frame_lines did not properly adjust subsequent
2856 lines' charstarts in the case where the text of the
2857 screen line at bp.vpos has changed.
2858 (This can happen in a deletion that ends in mid-line.)
2859 To adjust properly, we need to make things consistent
2861 So do a second adjust to make that happen.
2862 Note that stop_vpos >= ep.vpos, so it is sufficient
2863 to update the charstarts for lines at ep.vpos and below. */
2865 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2866 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2867 ep
.bufpos
- oldstart
);
2870 else if (scroll_amount
)
2872 /* If reprinting everything is nearly as fast as scrolling,
2873 don't bother scrolling. Can happen if lines are short. */
2874 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2875 overestimate of cost of reprinting, since xp.bufpos
2876 would end up below the bottom of the window. */
2877 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2878 top
+ height
- max (0, scroll_amount
),
2880 > xp
.bufpos
- ep
.bufpos
- 20)
2881 /* Return "try normal display with same window-start."
2882 Too bad we can't prevent further scroll-thinking. */
2884 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2885 top
+ height
- max (0, scroll_amount
),
2886 scroll_amount
, ep
.bufpos
);
2887 if (!tem
) stop_vpos
= height
;
2891 /* In any case, do not display past bottom of window */
2892 if (stop_vpos
>= height
)
2898 /* Handle case where pos is before w->start --
2899 can happen if part of line had been clipped and is not clipped now */
2900 if (vpos
== 0 && pos
< marker_position (w
->start
))
2901 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2903 val
.bytepos
= pos_byte
;
2904 val
.ovstring_chars_done
= 0;
2906 /* Redisplay the lines where the text was changed */
2907 last_text_vpos
= vpos
;
2908 /* The following code is omitted because we maintain tab offset in
2911 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2912 /* If we are starting display in mid-character, correct tab_offset
2913 to account for passing the line that that character really starts in. */
2914 if (val
.hpos
< lmargin
)
2915 tab_offset
+= width
;
2918 while (vpos
< stop_vpos
)
2920 val
= *display_text_line (w
, pos
, val
.bytepos
, top
+ vpos
++,
2921 val
.hpos
, val
.tab_offset
,
2922 val
.ovstring_chars_done
);
2923 /* If display_text_line ran a hook and changed some text,
2924 redisplay all the way to bottom of buffer
2925 So that we show the changes. */
2926 if (old_tick
!= MODIFF
)
2928 /* The following code is omitted because we maintain tab offset
2929 in val.tab_offset. */
2931 tab_offset
+= width
;
2932 if (val
.vpos
) tab_offset
= 0;
2934 if (pos
!= val
.bufpos
)
2936 /* Next line, unless prev line ended in end of buffer with no cr */
2937 = vpos
- (val
.vpos
&& FETCH_BYTE (val
.bytepos
- 1) != '\n');
2941 /* There are two cases:
2942 1) we have displayed down to the bottom of the window
2943 2) we have scrolled lines below stop_vpos by scroll_amount */
2947 /* If last line is continued in middle of character,
2948 include the split character in the text considered on the frame */
2949 if (val
.hpos
< lmargin
)
2951 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2952 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2955 /* If scrolling made blank lines at window bottom,
2956 redisplay to fill those lines */
2957 if (scroll_amount
< 0)
2959 /* Don't consider these lines for general-purpose scrolling.
2960 That will save time in the scrolling computation. */
2961 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2964 pos_byte
= xp
.bytepos
;
2966 val
.tab_offset
= xp
.tab_offset
;
2968 { /* Display from next line */
2969 vpos
= height
+ scroll_amount
;
2973 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2975 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2976 val
.tab_offset
= xp
.tab_offset
+ bp
.prevhpos
- width
;
2977 DEC_BOTH (pos
, pos_byte
);
2980 blank_end_of_window
= 1;
2981 /* The following code is omitted because we maintain tab offset
2982 in val.tab_offset. */
2984 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2985 /* If we are starting display in mid-character, correct tab_offset
2986 to account for passing the line that that character starts in. */
2987 if (val
.hpos
< lmargin
)
2988 tab_offset
+= width
;
2990 val
.bytepos
= pos_byte
;
2991 while (vpos
< height
)
2993 val
= *display_text_line (w
, pos
, val
.bytepos
,
2994 top
+ vpos
++, val
.hpos
,
2995 val
.tab_offset
, val
.ovstring_chars_done
);
2996 /* The following code is omitted because we maintain tab
2997 offset in val.tab_offset. */
2999 tab_offset
+= width
;
3000 if (val
.vpos
) tab_offset
= 0;
3005 /* Here is a case where display_text_line sets cursor_vpos wrong.
3006 Make it be fixed up, below. */
3012 /* If bottom just moved off end of frame, change mode line percentage. */
3013 if (XFASTINT (w
->window_end_pos
) == 0
3015 w
->update_mode_line
= Qt
;
3017 /* Attempt to adjust end-of-text positions to new bottom line */
3020 delta
= height
- xp
.vpos
;
3022 || (delta
> 0 && xp
.bufpos
<= ZV
)
3023 || (delta
== 0 && xp
.hpos
))
3025 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
3026 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
3027 XSETFASTINT (w
->window_end_vpos
,
3028 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
3032 w
->window_end_valid
= Qnil
;
3034 /* If point was not in a line that was displayed, find it */
3035 if (cursor_vpos
< 0)
3038 val
= *compute_motion (start
, 0, lmargin
, 0, PT
,
3039 /* Don't care for VPOS... */
3040 1 << (BITS_PER_SHORT
- 1),
3042 1 << (BITS_PER_SHORT
- 1),
3044 pos_tab_offset (w
, start
, start_byte
),
3046 /* Admit failure if point is off frame now */
3047 if (val
.vpos
>= height
)
3049 for (vpos
= 0; vpos
< height
; vpos
++)
3050 cancel_line (vpos
+ top
, f
);
3053 cursor_vpos
= val
.vpos
+ top
;
3054 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, val
.hpos
, width
);
3057 FRAME_CURSOR_X (f
) = cursor_hpos
;
3058 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3062 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
3063 height
, - (1 << (BITS_PER_SHORT
- 1)),
3065 pos_tab_offset (w
, start
, start_byte
),
3067 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
3069 if (XFASTINT (w
->window_end_pos
)
3077 /* Copy LEN glyphs starting address FROM to the rope TO.
3078 But don't actually copy the parts that would come in before S.
3079 Value is TO, advanced past the copied data.
3080 F is the frame we are displaying in. */
3083 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
3085 register GLYPH
*to
; /* Copy to here. */
3086 register GLYPH
*s
; /* Starting point. */
3087 Lisp_Object
*from
; /* Data to copy. */
3089 int face
; /* Face to apply to glyphs which don't specify one. */
3092 register Lisp_Object
*fp
= from
;
3093 /* These cache the results of the last call to compute_glyph_face. */
3095 int last_merged
= 0;
3098 if (! FRAME_TERMCAP_P (f
))
3101 GLYPH glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3103 unsigned int c
= FAST_GLYPH_CHAR (glyph
);
3106 /* For an invalid character code, use space. */
3109 if (FAST_GLYPH_FACE (glyph
) == 0)
3110 /* If GLYPH has no face code, use FACE. */
3112 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
3113 /* If it's same as previous glyph, use same result. */
3114 facecode
= last_merged
;
3117 /* Merge this glyph's face and remember the result. */
3118 last_code
= FAST_GLYPH_FACE (glyph
);
3119 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
3123 *to
= FAST_MAKE_GLYPH (c
, facecode
);
3131 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3138 /* Correct a glyph by replacing its specified user-level face code
3139 with a displayable computed face code. */
3142 fix_glyph (f
, glyph
, cface
)
3148 if (! FRAME_TERMCAP_P (f
))
3150 if (FAST_GLYPH_FACE (glyph
) != 0)
3151 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
3152 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
3158 /* Return the column of position POS / POS_BYTE in window W's buffer.
3159 When used on the character at the beginning of a line,
3160 starting at column 0, this says how much to subtract from
3161 the column position of any character in the line
3162 to get its horizontal position on the screen. */
3165 pos_tab_offset (w
, pos
, pos_byte
)
3167 register int pos
, pos_byte
;
3170 int opoint_byte
= PT_BYTE
;
3172 int width
= window_internal_width (w
) - 1;
3175 return MINI_WINDOW_P (w
) ? -minibuf_prompt_width
: 0;
3177 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3180 TEMP_SET_PT_BOTH (pos
, pos_byte
);
3181 col
= current_column ();
3182 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3187 /* Display one line of window W, starting at char position START in W's buffer.
3188 START_BYTE is the corresponding byte position.
3190 Display starting at horizontal position HPOS, expressed relative to
3191 W's left edge. In situations where the text at START shouldn't
3192 start at the left margin (i.e. when the window is hscrolled, or
3193 we're continuing a line which left off in the midst of a
3194 multi-column character), HPOS should be negative; we throw away
3195 characters up 'til hpos = 0. So, HPOS must take hscrolling into
3198 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
3200 OVSTR_DONE is the number of chars of overlay before/after strings
3201 at this position which have already been processed.
3203 Display on position VPOS on the frame. It is origin 0, relative to
3204 the top of the frame, not W.
3206 Returns a STRUCT POSITION giving character to start next line with
3207 and where to display it, including a zero or negative hpos.
3208 The vpos field is not really a vpos; it is 1 unless the line is continued */
3210 struct position val_display_text_line
;
3212 static struct position
*
3213 display_text_line (w
, start
, start_byte
, vpos
, hpos
, taboffset
, ovstr_done
)
3221 register int pos
= start
;
3222 int pos_byte
= start_byte
;
3225 int pause
, limit_byte
;
3226 register unsigned char *p
;
3228 register GLYPH
*leftmargin
;
3229 register GLYPH
*p1prev
;
3230 register GLYPH
*p1start
;
3231 GLYPH
*p1_wide_column_end
= (GLYPH
*) 0;
3232 int prevpos
, prevpos_byte
;
3234 FRAME_PTR f
= XFRAME (w
->frame
);
3235 int tab_width
= XINT (current_buffer
->tab_width
);
3236 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
3237 int width
= window_internal_width (w
) - 1;
3238 struct position val
;
3239 int lastpos
, lastpos_byte
;
3241 int last_invis_skip
= 0;
3242 Lisp_Object last_invis_prop
;
3243 int hscroll
= XINT (w
->hscroll
);
3244 int truncate
= (hscroll
3245 || (truncate_partial_width_windows
3246 && !WINDOW_FULL_WIDTH_P (w
))
3247 || !NILP (current_buffer
->truncate_lines
));
3249 /* 1 if this buffer has a region to highlight. */
3250 int highlight_region
3251 = (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
)
3252 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
3253 int region_beg
, region_end
;
3255 int selective
= (INTEGERP (current_buffer
->selective_display
)
3256 ? XINT (current_buffer
->selective_display
)
3257 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
3258 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
3259 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
3261 Lisp_Object default_invis_vector
[3];
3262 /* Number of characters of ellipsis to display after an invisible line
3263 if it calls for an ellipsis.
3264 Note that this value can be nonzero regardless of whether
3265 selective display is enabled--you must check that separately. */
3267 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3268 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
3269 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
3270 /* This is the sequence of Lisp objects to display
3271 when there are invisible lines. */
3272 Lisp_Object
*invis_vector_contents
3273 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3274 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
3275 : default_invis_vector
);
3277 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
3278 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp
)))
3279 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
3280 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
3281 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp
)))
3282 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
3284 /* If 1, we must handle multibyte characters. */
3285 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
3286 /* Length of multibyte form of each character. */
3288 /* Glyphs generated should be set this bit mask if text must be
3289 displayed from right to left. */
3290 GLYPH rev_dir_bit
= (NILP (current_buffer
->direction_reversed
)
3291 ? 0 : GLYPH_MASK_REV_DIR
);
3293 /* The next buffer location at which the face should change, due
3294 to overlays or text property changes. */
3295 int next_face_change
;
3297 /* The next location where the `invisible' property changes, or an
3298 overlay starts or ends. */
3301 /* The face we're currently using. */
3302 int current_face
= 0;
3305 XSETFASTINT (default_invis_vector
[2], '.');
3306 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
3308 get_display_line (f
, vpos
, WINDOW_LEFT_MARGIN (w
));
3309 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
3311 /* Show where to highlight the region. */
3312 if (highlight_region
3313 /* Maybe highlight only in selected window. */
3314 && (highlight_nonselected_windows
3315 || w
== XWINDOW (selected_window
)
3316 || (MINI_WINDOW_P (XWINDOW (selected_window
))
3317 && w
== XWINDOW (Vminibuf_scroll_window
))))
3319 region_beg
= marker_position (current_buffer
->mark
);
3320 if (PT
< region_beg
)
3322 region_end
= region_beg
;
3327 w
->region_showing
= Qt
;
3331 region_beg
= region_end
= -1;
3332 w
->region_showing
= Qnil
;
3335 if (MINI_WINDOW_P (w
)
3337 && vpos
== XFASTINT (w
->top
))
3339 if (! NILP (minibuf_prompt
))
3341 int old_width
= minibuf_prompt_width
;
3343 minibuf_prompt_width
3344 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
3345 STRING_BYTES (XSTRING (minibuf_prompt
)),
3346 hpos
+ WINDOW_LEFT_MARGIN (w
),
3347 /* Display a space if we truncate. */
3350 /* Truncate the prompt a little before the
3351 margin, so user input can at least start
3352 on the first line. */
3353 (XFASTINT (w
->width
) > 10
3354 ? XFASTINT (w
->width
) - 4 : -1),
3355 STRING_MULTIBYTE (minibuf_prompt
))
3356 - hpos
- WINDOW_LEFT_MARGIN (w
));
3357 hpos
+= minibuf_prompt_width
;
3358 taboffset
-= minibuf_prompt_width
- old_width
;
3361 minibuf_prompt_width
= 0;
3364 /* If we're hscrolled at all, use compute_motion to skip over any
3365 text off the left edge of the window. compute_motion may know
3366 tricks to do this faster than we can. */
3369 struct position
*left_edge
3370 = compute_motion (pos
, vpos
, hpos
, 0,
3372 width
, hscroll
, taboffset
, w
);
3374 /* Retrieve the buffer position and column provided by
3375 compute_motion. We can't assume that the column will be
3376 zero, because you may have multi-column characters crossing
3379 compute_motion may have moved us past the screen position we
3380 requested, if we hit a multi-column character, or the end of
3381 the line. If so, back up. */
3382 if ((left_edge
->vpos
> vpos
3383 || left_edge
->hpos
> 0)
3384 && left_edge
->bufpos
> pos
)
3386 pos
= left_edge
->bufpos
;
3387 pos_byte
= left_edge
->bytepos
;
3388 DEC_BOTH (pos
, pos_byte
);
3389 hpos
= left_edge
->prevhpos
;
3393 pos
= left_edge
->bufpos
;
3394 pos_byte
= left_edge
->bytepos
;
3395 hpos
= left_edge
->hpos
;
3399 hpos
+= WINDOW_LEFT_MARGIN (w
);
3401 desired_glyphs
->bufp
[vpos
] = start
;
3402 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
3404 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
3405 /* In case we don't ever write anything into it... */
3406 desired_glyphs
->charstarts
[vpos
][WINDOW_LEFT_MARGIN (w
)] = -1;
3407 leftmargin
= desired_glyphs
->glyphs
[vpos
] + WINDOW_LEFT_MARGIN (w
);
3408 endp
= leftmargin
+ width
;
3410 /* Arrange the overlays nicely for our purposes. Usually, we call
3411 display_text_line on only one line at a time, in which case this
3412 can't really hurt too much, or we call it on lines which appear
3413 one after another in the buffer, in which case all calls to
3414 recenter_overlay_lists but the first will be pretty cheap. */
3415 recenter_overlay_lists (current_buffer
, pos
);
3417 /* Loop generating characters.
3418 Stop at end of buffer, before newline,
3419 if reach or pass continuation column,
3420 or at face change. */
3422 limit_byte
= pos_byte
;
3423 next_face_change
= pos
;
3424 next_boundary
= pos
;
3427 prevpos_byte
= pos_byte
;
3429 /* If the window is hscrolled and point is in the invisible part of the
3430 current line beyond the left margin we can record the cursor location
3432 if (hscroll
&& start
<= PT
&& PT
< pos
&& cursor_vpos
< 0)
3435 cursor_hpos
= p1
- leftmargin
;
3444 while (pos
== next_boundary
)
3446 Lisp_Object position
, limit
, prop
, ww
;
3448 /* Display the overlay strings here, unless we're at ZV
3449 and have already displayed the appropriate strings
3450 on an earlier line. */
3451 if (pos
< ZV
|| !zv_strings_seen
++)
3454 unsigned char *ovstr
;
3455 ovlen
= overlay_strings (pos
, w
, &ovstr
);
3459 /* Skip the ones we did in a previous line. */
3460 ovstr
+= ovstr_done
;
3461 ovlen
-= ovstr_done
;
3463 while (ovlen
> 0 && p1
< endp
)
3470 c
= STRING_CHAR_AND_LENGTH (ovstr
, ovlen
, len
);
3471 ovstr
+= len
, ovlen
-= len
, ovstr_done
+= len
;
3472 charset
= CHAR_CHARSET (c
);
3473 cols
= (charset
== CHARSET_COMPOSITION
3474 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3475 : CHARSET_WIDTH (charset
));
3479 c
= *ovstr
++, ovlen
--, ovstr_done
++;
3482 g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3485 if (p1
>= leftmargin
&& p1
< endp
)
3486 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3490 /* If we did all the overlay strings
3491 and we have room for text, clear ovstr_done
3492 just for neatness' sake. */
3493 if (ovlen
== 0 && p1
< endp
)
3498 /* Did we reach point? Record the cursor location. */
3499 if (pos
== PT
&& cursor_vpos
< 0)
3502 cursor_hpos
= p1
- leftmargin
;
3508 XSETFASTINT (position
, pos
);
3509 limit
= Fnext_overlay_change (position
);
3510 #ifdef USE_TEXT_PROPERTIES
3511 /* This is just an estimate to give reasonable
3512 performance; nothing should go wrong if it is too small. */
3513 if (XFASTINT (limit
) > pos
+ 50)
3515 int limitpos
= pos
+ 50;
3516 XSETFASTINT (limit
, limitpos
);
3518 limit
= Fnext_single_property_change (position
, Qinvisible
,
3519 Fcurrent_buffer (), limit
);
3521 next_boundary
= XFASTINT (limit
);
3522 /* if the `invisible' property is set, we can skip to
3523 the next property change. */
3525 prop
= Fget_char_property (position
, Qinvisible
, ww
);
3526 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3528 if (pos
< PT
&& next_boundary
>= PT
)
3531 cursor_hpos
= p1
- leftmargin
;
3533 pos
= next_boundary
;
3534 pos_byte
= CHAR_TO_BYTE (pos
);
3535 last_invis_skip
= pos
;
3536 last_invis_prop
= prop
;
3540 /* Did we reach point? Record the cursor location. */
3541 if (pos
== PT
&& cursor_vpos
< 0)
3544 cursor_hpos
= p1
- leftmargin
;
3547 /* Did we hit the end of the visible region of the buffer?
3551 /* Update charstarts for the end of this line. */
3552 /* Do nothing if off the left edge or at the right edge. */
3553 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
3555 int *p2x
= &charstart
[(p1
< leftmargin
3563 /* Figure out where (if at all) the
3564 redisplay_end_trigger-hook should run. */
3565 if (MARKERP (w
->redisplay_end_trigger
)
3566 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
3567 e_t_h
= marker_position (w
->redisplay_end_trigger
);
3568 else if (INTEGERP (w
->redisplay_end_trigger
))
3569 e_t_h
= XINT (w
->redisplay_end_trigger
);
3573 /* If we've gone past the place to run a hook,
3575 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
3577 Lisp_Object args
[3];
3579 args
[0] = Qredisplay_end_trigger_functions
;
3580 XSETWINDOW (args
[1], w
);
3581 XSETINT (args
[2], e_t_h
);
3583 /* Since we are *trying* to run these functions,
3584 don't try to run them again, even if they get an error. */
3585 w
->redisplay_end_trigger
= Qnil
;
3586 Frun_hook_with_args (3, args
);
3589 /* Notice if it changed the face of this character. */
3590 next_face_change
= pos
;
3594 /* Did we hit a face change? Figure out what face we should
3595 use now. We also hit this the first time through the
3596 loop, to see what face we should start with. */
3597 if (pos
>= next_face_change
3598 && (FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
)))
3600 int limit
= pos
+ 50;
3602 current_face
= compute_char_face (f
, w
, pos
,
3603 region_beg
, region_end
,
3604 &next_face_change
, limit
, 0);
3608 /* Compute the next place we need to stop
3609 and do something special; set PAUSE. */
3613 if (pos
< next_boundary
&& next_boundary
< pause
)
3614 pause
= next_boundary
;
3615 if (pos
< next_face_change
&& next_face_change
< pause
)
3616 pause
= next_face_change
;
3621 /* Wouldn't you hate to read the next line to someone over
3623 if (pos
< PT
&& PT
< pause
)
3625 if (pos
< GPT
&& GPT
< pause
)
3628 /* LIMIT_BYTE is not the same place in the buffer as PAUSE.
3629 It is a limit on valid characters.
3630 We use it to bound STRING_CHAR_AND_LENGTH. */
3631 limit_byte
= ZV_BYTE
;
3632 if (pos
< GPT
&& GPT_BYTE
< limit_byte
)
3633 limit_byte
= GPT_BYTE
;
3636 int temp
= CHAR_TO_BYTE (pos
);
3637 p
= BYTE_POS_ADDR (temp
);
3645 p1_wide_column_end
= (GLYPH
*) 0;
3648 c
= STRING_CHAR_AND_LENGTH (p
, limit_byte
- pos_byte
, len
), p
+= len
;
3651 /* Let a display table override all standard display methods. */
3652 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3654 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
3655 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3656 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3657 current_face
, rev_dir_bit
);
3659 else if (c
>= 040 && c
< 0177)
3661 if (p1
>= leftmargin
)
3662 *p1
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3668 /* Same as p1prev, but after the invis_vector_contents text
3669 (if we have that on this line). */
3670 GLYPH
*p1prev_modified
;
3674 if (last_invis_skip
== pos
3675 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
3679 && indented_beyond_p (pos
+ 1, pos_byte
+ 1, selective
))
3681 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3684 INC_BOTH (pos
, pos_byte
);
3685 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3686 pos
= PT
, pos_byte
= PT_BYTE
;
3687 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3692 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3694 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
3699 cs
= charstart
+ (p1
- p1start
);
3702 p1
+= selective_rlen
;
3703 if (p1
- leftmargin
> width
)
3706 #if 0 /* This needs more work; charstarts needs to record
3707 both whether a position ho;ds an ellipsis character
3708 and what buffer position it corresponds to. */
3709 csend
= charstart
+ (p1
- p1start
);
3712 /* The idea is to use p1prev_modified instead of p1prev
3713 in the loop below over p2x. */
3714 p1prev_modified
= p1
;
3717 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3718 (p1
- p1prev
), current_face
, rev_dir_bit
);
3721 /* Update charstarts for the newline that ended this line. */
3722 /* Do nothing here for a char that's entirely off the left edge
3723 or if it starts at the right edge. */
3724 if (p1
>= leftmargin
&& p1prev
!= endp
)
3726 /* Store the newline's position into charstarts
3727 for the column where the newline starts.
3728 Store -1 for the rest of the glyphs it occupies. */
3729 int *p2x
= &charstart
[(p1prev
< leftmargin
3730 ? leftmargin
: p1prev
)
3732 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3739 /* Draw the face of the newline character as extending all the
3740 way to the end of the frame line. */
3743 if (p1
< leftmargin
)
3746 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3756 if (p1
>= leftmargin
&& p1
< endp
)
3757 *p1
= MAKE_GLYPH (f
, ' ', current_face
) | rev_dir_bit
;
3760 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
3763 else if (c
== Ctl ('M') && selective
== -1)
3765 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3766 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3767 pos
= PT
, pos_byte
= PT_BYTE
;
3768 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3770 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3772 if (selective_rlen
> 0)
3774 p1
+= selective_rlen
;
3775 if (p1
- leftmargin
> width
)
3777 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3778 (p1
- p1prev
), current_face
, rev_dir_bit
);
3781 /* Draw the face of the newline character as extending all the
3782 way to the end of the frame line. */
3785 if (p1
< leftmargin
)
3788 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3792 /* Update charstarts for the ^M that ended this line. */
3793 /* Do nothing here for a char that's entirely off the left edge
3794 or if it starts at the right edge. */
3795 if (p1
>= leftmargin
&& p1prev
!= endp
)
3797 /* Store the newline's position into charstarts
3798 for the column where the newline starts.
3799 Store -1 for the rest of the glyphs it occupies. */
3800 int *p2x
= &charstart
[(p1prev
< leftmargin
3801 ? leftmargin
: p1prev
)
3803 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3811 else if (c
< 0200 && ctl_arrow
)
3813 if (p1
>= leftmargin
)
3815 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3816 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
3817 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3821 if (p1
>= leftmargin
&& p1
< endp
)
3822 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
) | rev_dir_bit
;
3827 /* C is a multibyte character or a character to be displayed
3829 int remaining_bytes
= len
;
3831 if (unibyte_display_via_language_environment
3832 && SINGLE_BYTE_CHAR_P (c
)
3834 || (c
>= 0200 && !NILP (Vnonascii_translation_table
))))
3835 c
= unibyte_char_to_multibyte (c
);
3837 if (c
>= 0400 && CHAR_VALID_P (c
, 0))
3839 /* C is a multibyte character. */
3840 int charset
= CHAR_CHARSET (c
);
3841 int columns
= (charset
== CHARSET_COMPOSITION
3842 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3843 : CHARSET_WIDTH (charset
));
3844 GLYPH g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3848 if (p1
>= leftmargin
&& p1
< endp
)
3849 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3852 p1_wide_column_end
= p1
;
3853 remaining_bytes
-= CHARSET_BYTES (charset
);
3856 while (remaining_bytes
> 0)
3858 c
= *(p
- remaining_bytes
--);
3860 if (p1
>= leftmargin
&& p1
< endp
)
3863 (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3864 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
3865 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3869 if (p1
>= leftmargin
&& p1
< endp
)
3870 *p1
= (MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
)
3873 if (p1
>= leftmargin
&& p1
< endp
)
3874 *p1
= (MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
)
3877 if (p1
>= leftmargin
&& p1
< endp
)
3878 *p1
= (MAKE_GLYPH (f
, (7 & c
) + '0', current_face
)
3885 prevpos_byte
= pos_byte
;
3889 /* Update charstarts for the character just output. */
3891 /* Do nothing here for a char that's entirely off the left edge. */
3892 if (p1
>= leftmargin
)
3894 /* Store the char's position into charstarts
3895 for the first glyph occupied by this char.
3896 Store -1 for the rest of the glyphs it occupies. */
3899 int *p2x
= &charstart
[(p1prev
< leftmargin
3900 ? leftmargin
: p1prev
)
3902 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3912 val
.hpos
= - XINT (w
->hscroll
);
3919 lastpos_byte
= pos_byte
;
3921 /* Store 0 in this charstart line for the positions where
3922 there is no character. But do leave what was recorded
3923 for the character that ended the line. */
3924 /* Add 1 in the endtest to compensate for the fact that ENDP was
3925 made from WIDTH, which is 1 less than the window's actual
3927 i
= p1
- p1start
+ 1;
3928 if (p1
< leftmargin
)
3929 i
+= leftmargin
- p1
;
3930 for (; i
< endp
- p1start
+ 1; i
++)
3933 /* Handle continuation in middle of a character */
3934 /* by backing up over it */
3937 /* Don't back up if we never actually displayed any text.
3938 This occurs when the minibuffer prompt takes up the whole line. */
3941 /* Start the next line with that same character whose
3942 character code is C and the length of multi-byte form is
3945 pos_byte
= prevpos_byte
;
3947 if (p1_wide_column_end
< endp
)
3948 /* As ENDP is not in the middle of wide-column character,
3949 we can break the line at ENDP and start from the middle
3950 column in the next line. So, adjust VAL.HPOS to skip
3951 the columns output on this line. */
3952 val
.hpos
+= p1prev
- endp
;
3955 /* We displayed a wide-column character at around ENDP.
3956 Since we can't broke it in the middle, the whole
3957 character should be driven into the next line. */
3958 /* As the result, the actual columns occupied by the
3959 text on this line is less than WIDTH. VAL.TAB_OFFSET
3960 must be adjusted. */
3961 taboffset
= taboffset
+ (p1prev
- endp
);
3962 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3964 GLYPH g
= fix_glyph (f
, truncate
? truncator
: continuer
, 0);
3965 while (p1prev
< endp
)
3968 /* If POINT is at POS, cursor should not on this line. */
3970 lastpos_byte
= pos_byte
;
3976 /* Keep in this line everything up to the continuation column. */
3980 /* Finish deciding which character to start the next line on,
3981 and what hpos to start it at.
3982 Also set `lastpos' to the last position which counts as "on this line"
3983 for cursor-positioning. */
3987 if (FETCH_BYTE (pos_byte
) == '\n')
3989 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3991 /* If stopped due to a newline, start next line after it */
3992 TEMP_SET_PT_BOTH (pos
+ 1, pos_byte
+ 1);
3995 /* Check again for hidden lines, in case the newline occurred exactly
3996 at the right margin. */
3997 while (PT
< ZV
&& selective
> 0
3998 && indented_beyond_p (PT
, PT_BYTE
, selective
))
3999 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
4001 pos
= PT
, pos_byte
= PT_BYTE
;
4002 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
4005 /* Stopped due to right margin of window */
4009 int opoint
= PT
, opoint_byte
= PT_BYTE
;
4011 TEMP_SET_PT_BOTH (pos
, pos_byte
);
4012 *p1
++ = fix_glyph (f
, truncator
, 0);
4013 /* Truncating => start next line after next newline,
4014 and point is on this line if it is before the newline,
4015 and skip none of first char of next line */
4017 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
4018 while (PT
< ZV
&& selective
> 0
4019 && indented_beyond_p (PT
, PT_BYTE
, selective
));
4020 pos
= PT
, pos_byte
= PT_BYTE
;
4021 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
4022 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
4024 lastpos
= pos
- (FETCH_BYTE (pos_byte
- 1) == '\n');
4025 lastpos_byte
= CHAR_TO_BYTE (lastpos
);
4030 *p1
++ = fix_glyph (f
, continuer
, 0);
4032 DEC_BOTH (lastpos
, lastpos_byte
);
4033 val
.tab_offset
= taboffset
+ width
;
4040 /* If point is at eol or in invisible text at eol,
4041 record its frame location now. */
4043 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
4046 cursor_hpos
= p1
- leftmargin
;
4049 if (cursor_vpos
== vpos
)
4051 if (cursor_hpos
< 0) cursor_hpos
= 0;
4052 if (cursor_hpos
> width
) cursor_hpos
= width
;
4053 cursor_hpos
+= WINDOW_LEFT_MARGIN (w
);
4054 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
4056 this_line_bufpos
= 0;
4058 /* If this frame's cursor will be in its echo area,
4059 don't record a cursor from the window text,
4060 and turn off the optimization for cursor-motion-only case. */
4061 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
4062 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
4064 FRAME_CURSOR_Y (f
) = cursor_vpos
;
4065 FRAME_CURSOR_X (f
) = cursor_hpos
;
4067 if (w
== XWINDOW (selected_window
))
4069 /* Line is not continued and did not start
4070 in middle of character */
4071 if ((hpos
- WINDOW_LEFT_MARGIN (w
)
4072 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
4075 this_line_bufpos
= start
;
4076 this_line_buffer
= current_buffer
;
4077 this_line_vpos
= cursor_vpos
;
4078 this_line_start_hpos
= hpos
- WINDOW_LEFT_MARGIN (w
);
4079 this_line_endpos
= Z
- lastpos
;
4086 /* If hscroll and line not empty, insert truncation-at-left marker */
4087 if (hscroll
&& lastpos
!= start
)
4089 GLYPH g
= fix_glyph (f
, truncator
, 0);
4091 if (p1
<= leftmargin
)
4092 p1
= leftmargin
+ 1;
4093 else /* MULE: it may be a wide-column character */
4095 p1prev
= leftmargin
+ 1;
4096 while (p1prev
< p1
&& *p1prev
& GLYPH_MASK_PADDING
)
4101 if (!WINDOW_RIGHTMOST_P (w
))
4104 if (p1
< leftmargin
) p1
= leftmargin
;
4105 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
4107 /* Don't draw vertical bars if we're using scroll bars. They're
4108 covered up by the scroll bars, and it's distracting to see
4109 them when the scroll bar windows are flickering around to be
4111 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4114 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4117 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4118 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
4119 ? XINT (DISP_BORDER_GLYPH (dp
))
4122 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
4123 p1
- desired_glyphs
->glyphs
[vpos
]);
4124 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
4126 /* If the start of this line is the overlay arrow-position,
4127 then put the arrow string into the display-line. */
4129 if (MARKERP (Voverlay_arrow_position
)
4130 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
4131 && start
== marker_position (Voverlay_arrow_position
)
4132 && STRINGP (Voverlay_arrow_string
)
4133 && ! overlay_arrow_seen
)
4136 int len
= XSTRING (Voverlay_arrow_string
)->size
;
4142 /* If the arrow string has text props, obey them when displaying. */
4143 for (i
= 0, i_byte
= 0; i
< len
; )
4146 Lisp_Object face
, ilisp
;
4150 if (STRING_MULTIBYTE (Voverlay_arrow_string
))
4151 FETCH_STRING_CHAR_ADVANCE (c
, Voverlay_arrow_string
, i
, i_byte
);
4153 c
= XSTRING (Voverlay_arrow_string
)->data
[i
++];
4155 XSETFASTINT (ilisp
, i
);
4157 if (FRAME_WINDOW_P (f
))
4159 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
4160 newface
= compute_glyph_face_1 (f
, face
, 0);
4161 c
= FAST_MAKE_GLYPH (c
, newface
);
4163 #endif /* HAVE_FACES */
4164 leftmargin
[idx
] = c
;
4167 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
4168 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
4169 if (desired_glyphs
->used
[vpos
] < arrow_end
)
4170 desired_glyphs
->used
[vpos
] = arrow_end
;
4172 overlay_arrow_seen
= 1;
4176 val
.bytepos
= pos_byte
;
4177 val
.ovstring_chars_done
= ovstr_done
;
4178 val_display_text_line
= val
;
4179 return &val_display_text_line
;
4182 /* Redisplay the menu bar in the frame for window W. */
4185 display_menu_bar (w
)
4188 Lisp_Object items
, tail
;
4189 register int vpos
= 0;
4190 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4191 int maxendcol
= FRAME_WIDTH (f
);
4196 if (!NILP (Vwindow_system
))
4200 #ifdef USE_X_TOOLKIT
4203 #endif /* USE_X_TOOLKIT */
4205 get_display_line (f
, vpos
, 0);
4207 items
= FRAME_MENU_BAR_ITEMS (f
);
4208 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4210 Lisp_Object pos
, string
;
4211 string
= XVECTOR (items
)->contents
[i
+ 1];
4215 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], hpos
);
4217 if (hpos
< maxendcol
)
4218 hpos
= display_string (w
, vpos
,
4219 XSTRING (string
)->data
,
4220 STRING_BYTES (XSTRING (string
)),
4221 hpos
, 0, 0, hpos
, maxendcol
,
4222 STRING_MULTIBYTE (string
));
4223 /* Put a space between items. */
4224 if (hpos
< maxendcol
)
4226 int hpos1
= hpos
+ 1;
4227 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
4228 min (hpos1
, maxendcol
), maxendcol
, 0);
4232 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4233 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4235 /* Fill out the line with spaces. */
4236 if (maxendcol
> hpos
)
4237 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
, 0);
4239 /* Clear the rest of the lines allocated to the menu bar. */
4241 while (vpos
< FRAME_MENU_BAR_LINES (f
))
4242 get_display_line (f
, vpos
++, 0);
4245 /* Display the mode line for window w */
4248 display_mode_line (w
)
4251 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
4252 register int left
= WINDOW_LEFT_MARGIN (w
);
4253 register int right
= WINDOW_RIGHT_MARGIN (w
);
4254 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4256 line_number_displayed
= 0;
4257 w
->column_number_displayed
= Qnil
;
4259 get_display_line (f
, vpos
, left
);
4261 /* Temporarily make frame F's kboard the current kboard
4262 so that kboard-local variables in the mode_line_format
4263 will get the right values. */
4264 push_frame_kboard (f
);
4266 display_mode_element (w
, vpos
, left
, 0, right
, right
,
4267 current_buffer
->mode_line_format
);
4269 pop_frame_kboard ();
4271 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4273 /* Put the mode line in inverse video.
4274 Use faces if possible, since that lets us handle
4275 partial-width windows and avoid inverting the scroll bar columns. */
4277 if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
4279 /* For a partial width window, explicitly set face of each glyph. */
4281 unsigned int padding
;
4282 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
4283 for (i
= left
; i
< right
; ++i
)
4285 padding
= ptr
[i
] & GLYPH_MASK_PADDING
;
4286 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1) | padding
;
4292 /* Make the mode line inverse video if the entire line
4293 is made of mode lines.
4294 I.e. if this window is full width,
4295 or if it is the child of a full width window
4296 (which implies that that window is split side-by-side
4297 and the rest of this line is mode lines of the sibling windows). */
4298 if (WINDOW_FULL_WIDTH_P (w
)
4299 || WINDOW_FULL_WIDTH_P (XWINDOW (w
->parent
)))
4300 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4303 /* Contribute ELT to the mode line for window W.
4304 How it translates into text depends on its data type.
4306 VPOS is the position of the mode line being displayed.
4308 HPOS is the position (absolute on frame) where this element's text
4309 should start. The output is truncated automatically at the right
4312 DEPTH is the depth in recursion. It is used to prevent
4313 infinite recursion here.
4315 MINENDCOL is the hpos before which the element may not end.
4316 The element is padded at the right with spaces if nec
4317 to reach this column.
4319 MAXENDCOL is the hpos past which this element may not extend.
4320 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
4321 (This is necessary to make nested padding and truncation work.)
4323 Returns the hpos of the end of the text generated by ELT.
4324 The next element will receive that value as its HPOS arg,
4325 so as to concatenate the elements. */
4328 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
4330 register int vpos
, hpos
;
4333 register int maxendcol
;
4334 register Lisp_Object elt
;
4342 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
4346 /* A string: output it and check for %-constructs within it. */
4347 register unsigned char c
;
4348 register unsigned char *this = XSTRING (elt
)->data
;
4350 while (hpos
< maxendcol
&& *this)
4352 unsigned char *last
= this;
4353 while ((c
= *this++) != '\0' && c
!= '%')
4355 if (this - 1 != last
)
4357 register int lim
= --this - last
+ hpos
;
4358 if (frame_title_ptr
)
4359 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
4361 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
4362 hpos
, min (lim
, maxendcol
),
4363 STRING_MULTIBYTE (elt
));
4367 register int minendcol
;
4368 register int spec_width
= 0;
4370 /* We can't allow -ve args due to the "%-" construct */
4371 /* Argument specifies minwidth but not maxwidth
4372 (maxwidth can be specified by
4373 (<negative-number> . <stuff>) mode-line elements) */
4375 while ((c
= *this++) >= '0' && c
<= '9')
4377 spec_width
= spec_width
* 10 + (c
- '0');
4380 minendcol
= hpos
+ spec_width
;
4381 if (minendcol
> maxendcol
)
4383 spec_width
= maxendcol
- hpos
;
4384 minendcol
= maxendcol
;
4388 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4389 spec_width
, maxendcol
,
4390 Vglobal_mode_string
);
4393 char *spec
= decode_mode_spec (w
, c
, spec_width
,
4395 if (frame_title_ptr
)
4396 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
4398 hpos
= display_string (w
, vpos
, spec
, -1,
4400 minendcol
, maxendcol
, -1);
4408 /* A symbol: process the value of the symbol recursively
4409 as if it appeared here directly. Avoid error if symbol void.
4410 Special case: if value of symbol is a string, output the string
4413 register Lisp_Object tem
;
4414 tem
= Fboundp (elt
);
4417 tem
= Fsymbol_value (elt
);
4418 /* If value is a string, output that string literally:
4419 don't check for % within it. */
4422 if (frame_title_ptr
)
4423 hpos
= store_frame_title (XSTRING (tem
)->data
,
4424 minendcol
, maxendcol
);
4426 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
4427 STRING_BYTES (XSTRING (tem
)),
4428 hpos
, 0, 1, minendcol
, maxendcol
,
4429 STRING_MULTIBYTE (tem
));
4431 /* Give up right away for nil or t. */
4432 else if (!EQ (tem
, elt
))
4433 { elt
= tem
; goto tail_recurse
; }
4440 register Lisp_Object car
, tem
;
4442 /* A cons cell: three distinct cases.
4443 If first element is a string or a cons, process all the elements
4444 and effectively concatenate them.
4445 If first element is a negative number, truncate displaying cdr to
4446 at most that many characters. If positive, pad (with spaces)
4447 to at least that many characters.
4448 If first element is a symbol, process the cadr or caddr recursively
4449 according to whether the symbol's value is non-nil or nil. */
4450 car
= XCONS (elt
)->car
;
4453 tem
= Fboundp (car
);
4454 elt
= XCONS (elt
)->cdr
;
4457 /* elt is now the cdr, and we know it is a cons cell.
4458 Use its car if CAR has a non-nil value. */
4461 tem
= Fsymbol_value (car
);
4463 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
4465 /* Symbol's value is nil (or symbol is unbound)
4466 Get the cddr of the original list
4467 and if possible find the caddr and use that. */
4468 elt
= XCONS (elt
)->cdr
;
4471 else if (!CONSP (elt
))
4473 elt
= XCONS (elt
)->car
;
4476 else if (INTEGERP (car
))
4478 register int lim
= XINT (car
);
4479 elt
= XCONS (elt
)->cdr
;
4481 /* Negative int means reduce maximum width.
4482 DO NOT change MINENDCOL here!
4483 (20 -10 . foo) should truncate foo to 10 col
4484 and then pad to 20. */
4485 maxendcol
= min (maxendcol
, hpos
- lim
);
4488 /* Padding specified. Don't let it be more than
4491 if (lim
> maxendcol
)
4493 /* If that's more padding than already wanted, queue it.
4494 But don't reduce padding already specified even if
4495 that is beyond the current truncation point. */
4496 if (lim
> minendcol
)
4501 else if (STRINGP (car
) || CONSP (car
))
4503 register int limit
= 50;
4504 /* LIMIT is to protect against circular lists. */
4505 while (CONSP (elt
) && --limit
> 0
4506 && hpos
< maxendcol
)
4508 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4511 elt
= XCONS (elt
)->cdr
;
4519 if (frame_title_ptr
)
4520 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
4522 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
4523 minendcol
, maxendcol
, 0);
4527 if (minendcol
> hpos
)
4528 if (frame_title_ptr
)
4529 hpos
= store_frame_title ("", minendcol
, maxendcol
);
4531 hpos
= display_string (w
, vpos
, "", 0, hpos
,
4532 0, 1, minendcol
, maxendcol
, 0);
4536 /* Write a null-terminated, right justified decimal representation of
4537 the positive integer D to BUF using a minimal field width WIDTH. */
4540 pint2str (buf
, width
, d
)
4545 register char *p
= buf
;
4552 *p
++ = d
% 10 + '0';
4555 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
4565 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4566 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4567 type of CODING_SYSTEM. Return updated pointer into BUF. */
4569 static char invalid_eol_type
[] = "(*invalid*)";
4572 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
4573 Lisp_Object coding_system
;
4578 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
4579 unsigned char *eol_str
;
4581 /* The EOL conversion we are using. */
4582 Lisp_Object eoltype
;
4584 val
= coding_system
;
4586 if (NILP (val
)) /* Not yet decided. */
4591 eoltype
= eol_mnemonic_undecided
;
4592 /* Don't mention EOL conversion if it isn't decided. */
4596 Lisp_Object eolvalue
;
4598 eolvalue
= Fget (coding_system
, Qeol_type
);
4600 while (!NILP (val
) && SYMBOLP (val
))
4602 val
= Fget (val
, Qcoding_system
);
4603 if (NILP (eolvalue
))
4604 eolvalue
= Fget (val
, Qeol_type
);
4608 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
4612 /* The EOL conversion that is normal on this system. */
4614 if (NILP (eolvalue
)) /* Not yet decided. */
4615 eoltype
= eol_mnemonic_undecided
;
4616 else if (VECTORP (eolvalue
)) /* Not yet decided. */
4617 eoltype
= eol_mnemonic_undecided
;
4618 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4619 eoltype
= (XFASTINT (eolvalue
) == 0
4621 : (XFASTINT (eolvalue
) == 1
4622 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
4628 /* Mention the EOL conversion if it is not the usual one. */
4629 if (STRINGP (eoltype
))
4631 eol_str
= XSTRING (eoltype
)->data
;
4632 eol_str_len
= XSTRING (eoltype
)->size
;
4634 else if (INTEGERP (eoltype
)
4635 && CHAR_VALID_P (XINT (eoltype
), 0))
4637 int c
= XINT (eoltype
);
4638 unsigned char work
[4];
4640 eol_str_len
= CHAR_STRING (XINT (eoltype
), work
, eol_str
);
4644 eol_str
= invalid_eol_type
;
4645 eol_str_len
= sizeof (invalid_eol_type
) - 1;
4647 bcopy (eol_str
, buf
, eol_str_len
);
4654 /* Return a string for the output of a mode line %-spec for window W,
4655 generated by character C. SPEC_WIDTH is the field width when
4656 padding to the left (%c, %l). The value returned from this
4657 function will later be truncated to width MAXWIDTH. */
4659 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4662 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
4665 register int spec_width
;
4666 register int maxwidth
;
4669 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4670 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
4671 struct buffer
*b
= XBUFFER (w
->buffer
);
4674 if (maxwidth
> FRAME_WIDTH (f
))
4675 maxwidth
= FRAME_WIDTH (f
);
4680 if (!NILP (b
->read_only
))
4682 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4687 /* This differs from %* only for a modified read-only buffer. */
4688 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4690 if (!NILP (b
->read_only
))
4695 /* This differs from %* in ignoring read-only-ness. */
4696 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4708 if (command_loop_level
> 5)
4710 p
= decode_mode_spec_buf
;
4711 for (i
= 0; i
< command_loop_level
; i
++)
4714 return decode_mode_spec_buf
;
4722 if (command_loop_level
> 5)
4724 p
= decode_mode_spec_buf
;
4725 for (i
= 0; i
< command_loop_level
; i
++)
4728 return decode_mode_spec_buf
;
4736 if (maxwidth
< sizeof (lots_of_dashes
))
4737 return lots_of_dashes
;
4740 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
4744 return decode_mode_spec_buf
;
4750 if (maxwidth
>= 3 && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4752 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
4753 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
4754 decode_mode_spec_buf
[maxwidth
] = '\0';
4755 return decode_mode_spec_buf
;
4762 int col
= current_column ();
4763 XSETFASTINT (w
->column_number_displayed
, col
);
4764 pint2str (decode_mode_spec_buf
, spec_width
, col
);
4765 return decode_mode_spec_buf
;
4769 /* %F displays the frame name. */
4770 /* Systems that can only display a single frame at a time should
4771 NOT replace the frame name with the (constant) frame title,
4772 since then they won't be able to tell which frame is that. */
4773 if (FRAME_WINDOW_P (f
) && !NILP (f
->title
))
4774 return (char *) XSTRING (f
->title
)->data
;
4775 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
4776 return (char *) XSTRING (f
->name
)->data
;
4784 else if (STRINGP (obj
) && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4786 bcopy ("...", decode_mode_spec_buf
, 3);
4787 bcopy (XSTRING (obj
)->data
+ STRING_BYTES (XSTRING (obj
)) - maxwidth
+ 3,
4788 decode_mode_spec_buf
+ 3, maxwidth
- 3);
4789 return decode_mode_spec_buf
;
4796 int startpos
= XMARKER (w
->start
)->charpos
;
4797 int startpos_byte
= marker_byte_position (w
->start
);
4798 int line
, linepos
, linepos_byte
, topline
;
4801 int height
= XFASTINT (w
->height
);
4803 /* If we decided that this buffer isn't suitable for line numbers,
4804 don't forget that too fast. */
4805 if (EQ (w
->base_line_pos
, w
->buffer
))
4807 /* But do forget it, if the window shows a different buffer now. */
4808 else if (BUFFERP (w
->base_line_pos
))
4809 w
->base_line_pos
= Qnil
;
4811 /* If the buffer is very big, don't waste time. */
4812 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
4814 w
->base_line_pos
= Qnil
;
4815 w
->base_line_number
= Qnil
;
4819 if (!NILP (w
->base_line_number
)
4820 && !NILP (w
->base_line_pos
)
4821 && XFASTINT (w
->base_line_pos
) <= startpos
)
4823 line
= XFASTINT (w
->base_line_number
);
4824 linepos
= XFASTINT (w
->base_line_pos
);
4825 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
4830 linepos
= BUF_BEGV (b
);
4831 linepos_byte
= BUF_BEGV_BYTE (b
);
4834 /* Count lines from base line to window start position. */
4835 nlines
= display_count_lines (linepos
, linepos_byte
,
4839 topline
= nlines
+ line
;
4841 /* Determine a new base line, if the old one is too close
4842 or too far away, or if we did not have one.
4843 "Too close" means it's plausible a scroll-down would
4845 if (startpos
== BUF_BEGV (b
))
4847 XSETFASTINT (w
->base_line_number
, topline
);
4848 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
4850 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
4851 || linepos
== BUF_BEGV (b
))
4853 int limit
= BUF_BEGV (b
);
4854 int limit_byte
= BUF_BEGV_BYTE (b
);
4856 int distance
= (height
* 2 + 30) * 200;
4858 if (startpos
- distance
> limit
)
4860 limit
= startpos
- distance
;
4861 limit_byte
= CHAR_TO_BYTE (limit
);
4864 nlines
= display_count_lines (startpos
, startpos_byte
,
4866 - (height
* 2 + 30),
4868 /* If we couldn't find the lines we wanted within
4870 give up on line numbers for this window. */
4871 if (position
== limit_byte
&& limit
== startpos
- distance
)
4873 w
->base_line_pos
= w
->buffer
;
4874 w
->base_line_number
= Qnil
;
4878 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
4879 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
4882 /* Now count lines from the start pos to point. */
4883 nlines
= display_count_lines (startpos
, startpos_byte
,
4884 PT_BYTE
, PT
, &junk
);
4886 /* Record that we did display the line number. */
4887 line_number_displayed
= 1;
4889 /* Make the string to show. */
4890 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
4891 return decode_mode_spec_buf
;
4894 char* p
= decode_mode_spec_buf
;
4895 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
4897 return decode_mode_spec_buf
;
4907 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
4913 int pos
= marker_position (w
->start
);
4914 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4916 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
4918 if (pos
<= BUF_BEGV (b
))
4923 else if (pos
<= BUF_BEGV (b
))
4927 if (total
> 1000000)
4928 /* Do it differently for a large value, to avoid overflow. */
4929 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4931 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4932 /* We can't normally display a 3-digit number,
4933 so get us a 2-digit number that is close. */
4936 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4937 return decode_mode_spec_buf
;
4941 /* Display percentage of size above the bottom of the screen. */
4944 int toppos
= marker_position (w
->start
);
4945 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
4946 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4948 if (botpos
>= BUF_ZV (b
))
4950 if (toppos
<= BUF_BEGV (b
))
4957 if (total
> 1000000)
4958 /* Do it differently for a large value, to avoid overflow. */
4959 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4961 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4962 /* We can't normally display a 3-digit number,
4963 so get us a 2-digit number that is close. */
4966 if (toppos
<= BUF_BEGV (b
))
4967 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
4969 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4970 return decode_mode_spec_buf
;
4975 /* status of process */
4976 obj
= Fget_buffer_process (w
->buffer
);
4978 return "no process";
4980 obj
= Fsymbol_name (Fprocess_status (obj
));
4984 case 't': /* indicate TEXT or BINARY */
4985 #ifdef MODE_LINE_BINARY_TEXT
4986 return MODE_LINE_BINARY_TEXT (b
);
4992 /* coding-system (not including end-of-line format) */
4994 /* coding-system (including end-of-line type) */
4996 int eol_flag
= (c
== 'Z');
4997 char *p
= decode_mode_spec_buf
;
4999 if (! FRAME_WINDOW_P (f
))
5001 /* No need to mention EOL here--the terminal never needs
5002 to do EOL conversion. */
5003 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
5004 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
5006 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
5009 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
5011 obj
= Fget_buffer_process (Fcurrent_buffer ());
5014 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
5016 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
5019 #endif /* subprocesses */
5022 return decode_mode_spec_buf
;
5027 return (char *) XSTRING (obj
)->data
;
5032 /* Count up to COUNT lines starting from START / START_BYTE.
5033 But don't go beyond LIMIT_BYTE.
5034 Return the number of lines thus found (always nonnegative).
5036 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
5039 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
5040 int start
, start_byte
, limit_byte
, count
;
5043 register unsigned char *cursor
;
5044 unsigned char *base
;
5046 register int ceiling
;
5047 register unsigned char *ceiling_addr
;
5048 int orig_count
= count
;
5050 /* If we are not in selective display mode,
5051 check only for newlines. */
5052 int selective_display
= (!NILP (current_buffer
->selective_display
)
5053 && !INTEGERP (current_buffer
->selective_display
));
5057 while (start_byte
< limit_byte
)
5059 ceiling
= BUFFER_CEILING_OF (start_byte
);
5060 ceiling
= min (limit_byte
- 1, ceiling
);
5061 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
5062 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
5065 if (selective_display
)
5066 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
5069 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
5072 if (cursor
!= ceiling_addr
)
5076 start_byte
+= cursor
- base
+ 1;
5077 *byte_pos_ptr
= start_byte
;
5081 if (++cursor
== ceiling_addr
)
5087 start_byte
+= cursor
- base
;
5092 while (start_byte
> limit_byte
)
5094 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
5095 ceiling
= max (limit_byte
, ceiling
);
5096 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
5097 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
5100 if (selective_display
)
5101 while (--cursor
!= ceiling_addr
5102 && *cursor
!= '\n' && *cursor
!= 015)
5105 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
5108 if (cursor
!= ceiling_addr
)
5112 start_byte
+= cursor
- base
+ 1;
5113 *byte_pos_ptr
= start_byte
;
5114 /* When scanning backwards, we should
5115 not count the newline posterior to which we stop. */
5116 return - orig_count
- 1;
5122 /* Here we add 1 to compensate for the last decrement
5123 of CURSOR, which took it past the valid range. */
5124 start_byte
+= cursor
- base
+ 1;
5128 *byte_pos_ptr
= limit_byte
;
5131 return - orig_count
+ count
;
5132 return orig_count
- count
;
5136 /* Display STRING on one line of window W, starting at HPOS.
5137 Display at position VPOS. Caller should have done get_display_line.
5138 If VPOS == -1, display it as the current frame's title.
5139 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
5141 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
5143 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
5144 MAXCOL is the last column ok to end at. Truncate here.
5145 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
5146 Both count from the left edge of the frame, as does HPOS.
5147 The right edge of W is an implicit maximum.
5148 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
5150 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
5151 at the place where the current window ends in this line
5152 and not display anything beyond there. Otherwise, only MAXCOL
5153 controls where to stop output.
5155 MULTIBYTE can be 0 meaning do not display multibyte chars,
5156 1 meaning do display them, or -1 meaning obey the current buffer's
5157 value of enable_multibyte_characters.
5159 Returns ending hpos. */
5162 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
5163 obey_window_width
, mincol
, maxcol
, multibyte
)
5165 unsigned char *string
;
5169 int obey_window_width
;
5176 int hscroll
= XINT (w
->hscroll
);
5177 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
5178 register GLYPH
*start
;
5179 register GLYPH
*end
;
5180 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
5181 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
5182 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
5183 int window_width
= XFASTINT (w
->width
);
5185 /* Use the standard display table, not the window's display table.
5186 We don't want the mode line in rot13. */
5187 register struct Lisp_Char_Table
*dp
= 0;
5190 if (multibyte
== -1)
5191 multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
5192 /* Now multibyte is 1 if we should display multibyte characters. */
5194 if (DISP_TABLE_P (Vstandard_display_table
))
5195 dp
= XCHAR_TABLE (Vstandard_display_table
);
5197 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
5200 start
= desired_glyphs
->glyphs
[vpos
];
5202 if (obey_window_width
)
5204 start
+= XFASTINT (w
->left
);
5205 end
= start
+ window_width
- (truncate
!= 0);
5207 if (!WINDOW_RIGHTMOST_P (w
))
5209 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5213 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
5216 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5221 if (! obey_window_width
5222 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
5223 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
5225 /* Store 0 in charstart for these columns. */
5226 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
5227 desired_glyphs
->charstarts
[vpos
][i
] = 0;
5229 if (maxcol
>= 0 && mincol
> maxcol
)
5233 /* We need this value for multibyte characters. */
5234 length
= strlen (string
);
5236 /* We set truncated to 1 if we get stopped by trying to pass END
5237 (that is, trying to pass MAXCOL.) */
5246 c
= STRING_CHAR_AND_LENGTH (string
, length
, len
);
5248 c
= *string
, len
= 1;
5250 string
+= len
, length
-= len
;
5258 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
5260 p1
= copy_part_of_rope (f
, p1
, start
,
5261 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
5262 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
5265 else if (c
>= 040 && c
< 0177)
5275 if (p1
>= start
&& p1
< end
)
5279 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
5281 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
5285 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
5286 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
5287 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
5290 if (p1
>= start
&& p1
< end
)
5296 /* C is a multibyte character, control character or a binary
5298 int remaining_bytes
= len
;
5300 if (c
>= 0400 && CHAR_VALID_P (c
, 0))
5302 /* C is a multibyte character. */
5303 int charset
= CHAR_CHARSET (c
);
5304 int columns
= (charset
== CHARSET_COMPOSITION
5305 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
5306 : CHARSET_WIDTH (charset
));
5308 remaining_bytes
-= CHARSET_BYTES (charset
);
5311 /* Since we can't show the left part of C, fill all
5312 columns with spaces. */
5313 columns
-= start
- p1
;
5322 else if (p1
+ columns
> end
)
5324 /* Since we can't show the right part of C, fill all
5325 columns with TRUNCATE if TRUNCATE is specified. */
5329 *p1
++ = fix_glyph (f
, truncate
, 0);
5330 /* And tell the line is truncated. */
5337 /* We can show the whole glyph of C. */
5340 *p1
++ = c
| GLYPH_MASK_PADDING
;
5344 while (remaining_bytes
> 0)
5346 c
= *(string
- remaining_bytes
--);
5350 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
5351 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
5352 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
5355 if (p1
>= start
&& p1
< end
)
5356 *p1
= (c
>> 6) + '0';
5358 if (p1
>= start
&& p1
< end
)
5359 *p1
= (7 & (c
>> 3)) + '0';
5361 if (p1
>= start
&& p1
< end
)
5362 *p1
= (7 & c
) + '0';
5371 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
5373 else if (mincol
>= 0)
5375 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
5381 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
5383 if (len
> desired_glyphs
->used
[vpos
])
5384 desired_glyphs
->used
[vpos
] = len
;
5385 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
5391 /* This is like a combination of memq and assq.
5392 Return 1 if PROPVAL appears as an element of LIST
5393 or as the car of an element of LIST.
5394 If PROPVAL is a list, compare each element against LIST
5395 in that way, and return 1 if any element of PROPVAL is found in LIST.
5397 This function cannot quit. */
5400 invisible_p (propval
, list
)
5401 register Lisp_Object propval
;
5404 register Lisp_Object tail
, proptail
;
5405 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5407 register Lisp_Object tem
;
5408 tem
= XCONS (tail
)->car
;
5409 if (EQ (propval
, tem
))
5411 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5414 if (CONSP (propval
))
5415 for (proptail
= propval
; CONSP (proptail
);
5416 proptail
= XCONS (proptail
)->cdr
)
5418 Lisp_Object propelt
;
5419 propelt
= XCONS (proptail
)->car
;
5420 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5422 register Lisp_Object tem
;
5423 tem
= XCONS (tail
)->car
;
5424 if (EQ (propelt
, tem
))
5426 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5433 /* Return 1 if PROPVAL appears as the car of an element of LIST
5434 and the cdr of that element is non-nil.
5435 If PROPVAL is a list, check each element of PROPVAL in that way,
5436 and the first time some element is found,
5437 return 1 if the cdr of that element is non-nil.
5439 This function cannot quit. */
5442 invisible_ellipsis_p (propval
, list
)
5443 register Lisp_Object propval
;
5446 register Lisp_Object tail
, proptail
;
5447 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5449 register Lisp_Object tem
;
5450 tem
= XCONS (tail
)->car
;
5451 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5452 return ! NILP (XCONS (tem
)->cdr
);
5454 if (CONSP (propval
))
5455 for (proptail
= propval
; CONSP (proptail
);
5456 proptail
= XCONS (proptail
)->cdr
)
5458 Lisp_Object propelt
;
5459 propelt
= XCONS (proptail
)->car
;
5460 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5462 register Lisp_Object tem
;
5463 tem
= XCONS (tail
)->car
;
5464 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5465 return ! NILP (XCONS (tem
)->cdr
);
5474 staticpro (&Qinhibit_redisplay
);
5475 Qinhibit_redisplay
= intern ("inhibit-redisplay");
5477 staticpro (&Qmenu_bar_update_hook
);
5478 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
5480 staticpro (&Qoverriding_terminal_local_map
);
5481 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
5483 staticpro (&Qoverriding_local_map
);
5484 Qoverriding_local_map
= intern ("overriding-local-map");
5486 staticpro (&Qwindow_scroll_functions
);
5487 Qwindow_scroll_functions
= intern ("window-scroll-functions");
5489 staticpro (&Qredisplay_end_trigger_functions
);
5490 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
5492 staticpro (&Qinhibit_point_motion_hooks
);
5493 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
5495 staticpro (&last_arrow_position
);
5496 staticpro (&last_arrow_string
);
5497 last_arrow_position
= Qnil
;
5498 last_arrow_string
= Qnil
;
5500 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
5501 "Non-nil means don't actually do any redisplay.\n\
5502 This is used for internal purposes.");
5503 Vinhibit_redisplay
= Qnil
;
5505 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
5506 "String (or mode line construct) included (normally) in `mode-line-format'.");
5507 Vglobal_mode_string
= Qnil
;
5509 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
5510 "Marker for where to display an arrow on top of the buffer text.\n\
5511 This must be the beginning of a line in order to work.\n\
5512 See also `overlay-arrow-string'.");
5513 Voverlay_arrow_position
= Qnil
;
5515 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
5516 "String to display as an arrow. See also `overlay-arrow-position'.");
5517 Voverlay_arrow_string
= Qnil
;
5519 DEFVAR_INT ("scroll-step", &scroll_step
,
5520 "*The number of lines to try scrolling a window by when point moves out.\n\
5521 If that fails to bring point back on frame, point is centered instead.\n\
5522 If this is zero, point is always centered after it moves off frame.");
5524 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
5525 "*Scroll up to this many lines, to bring point back on screen.");
5526 scroll_conservatively
= 0;
5528 DEFVAR_INT ("scroll-margin", &scroll_margin
,
5529 "*Number of lines of margin at the top and bottom of a window.\n\
5530 Recenter the window whenever point gets within this many lines\n\
5531 of the top or bottom of the window.");
5534 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
5536 DEFVAR_BOOL ("truncate-partial-width-windows",
5537 &truncate_partial_width_windows
,
5538 "*Non-nil means truncate lines in all windows less than full frame wide.");
5539 truncate_partial_width_windows
= 1;
5541 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
5542 "*Non-nil means use inverse video for the mode line.");
5543 mode_line_inverse_video
= 1;
5545 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
5546 "*Maximum buffer size (in characters) for line number display\n\
5547 If the buffer is bigger than this, the line number does not appear\n\
5548 in the mode line..");
5549 line_number_display_limit
= 1000000;
5551 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
5552 "*Non-nil means highlight region even in nonselected windows.");
5553 highlight_nonselected_windows
= 0;
5555 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
5556 "Non-nil if more than one frame is visible on this display.\n\
5557 Minibuffer-only frames don't count, but iconified frames do.\n\
5558 This variable is not guaranteed to be accurate except while processing\n\
5559 `frame-title-format' and `icon-title-format'.");
5561 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
5562 "Template for displaying the titlebar of visible frames.\n\
5563 \(Assuming the window manager supports this feature.)\n\
5564 This variable has the same structure as `mode-line-format' (which see),\n\
5565 and is used only on frames for which no explicit name has been set\n\
5566 \(see `modify-frame-parameters').");
5567 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
5568 "Template for displaying the titlebar of an iconified frame.\n\
5569 \(Assuming the window manager supports this feature.)\n\
5570 This variable has the same structure as `mode-line-format' (which see),\n\
5571 and is used only on frames for which no explicit name has been set\n\
5572 \(see `modify-frame-parameters').");
5574 = Vframe_title_format
5575 = Fcons (intern ("multiple-frames"),
5576 Fcons (build_string ("%b"),
5577 Fcons (Fcons (build_string (""),
5578 Fcons (intern ("invocation-name"),
5579 Fcons (build_string ("@"),
5580 Fcons (intern ("system-name"),
5584 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
5585 "Maximum number of lines to keep in the message log buffer.\n\
5586 If nil, disable message logging. If t, log messages but don't truncate\n\
5587 the buffer when it becomes large.");
5588 XSETFASTINT (Vmessage_log_max
, 50);
5590 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
5591 "Functions called before redisplay, if window sizes have changed.\n\
5592 The value should be a list of functions that take one argument.\n\
5593 Just before redisplay, for each frame, if any of its windows have changed\n\
5594 size since the last redisplay, or have been split or deleted,\n\
5595 all the functions in the list are called, with the frame as argument.");
5596 Vwindow_size_change_functions
= Qnil
;
5598 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
5599 "List of functions to call before redisplaying a window with scrolling.\n\
5600 Each function is called with two arguments, the window\n\
5601 and its new display-start position. Note that the value of `window-end'\n\
5602 is not valid when these functions are called.");
5603 Vwindow_scroll_functions
= Qnil
;
5605 DEFVAR_INT ("minibuffer-scroll-overlap", &minibuffer_scroll_overlap
,
5606 "*Number of characters of overlap when scrolling a one-line window.\n\
5607 This commonly affects the minibuffer window, hence the name of the variable.");
5608 minibuffer_scroll_overlap
= 20;
5610 DEFVAR_BOOL ("unibyte-display-via-language-environment",
5611 &unibyte_display_via_language_environment
,
5612 "*Non-nil means display unibyte text according to language environment.\n\
5613 Specifically this means that unibyte non-ASCII characters\n\
5614 are displayed by converting them to the equivalent multibyte characters\n\
5615 according to the current language environment. As a result, they are\n\
5616 displayed according to the current fontset.");
5617 unibyte_display_via_language_environment
= 0;
5620 /* initialize the window system */
5624 Lisp_Object root_window
;
5625 #ifndef COMPILER_REGISTER_BUG
5627 #endif /* COMPILER_REGISTER_BUG */
5628 struct window
*mini_w
;
5630 this_line_bufpos
= 0;
5632 mini_w
= XWINDOW (minibuf_window
);
5633 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
5635 echo_area_glyphs
= 0;
5636 previous_echo_glyphs
= 0;
5638 if (!noninteractive
)
5640 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
5641 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_MENU_BAR_LINES (f
));
5642 set_window_height (root_window
,
5643 FRAME_HEIGHT (f
) - 1 - FRAME_MENU_BAR_LINES (f
),
5645 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
5646 set_window_height (minibuf_window
, 1, 0);
5648 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
5649 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));