1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 /*#include <ctype.h>*/
31 #include "dispextern.h"
38 #include "termhooks.h"
39 #include "intervals.h"
43 #include "region-cache.h"
49 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
50 extern void set_frame_menubar ();
51 extern int pending_menu_activation
;
54 extern int interrupt_input
;
55 extern int command_loop_level
;
57 extern int minibuffer_auto_raise
;
59 extern Lisp_Object Qface
;
61 extern Lisp_Object Voverriding_local_map
;
62 extern Lisp_Object Voverriding_local_map_menu_flag
;
64 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
65 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
66 Lisp_Object Qredisplay_end_trigger_functions
;
67 Lisp_Object Qinhibit_point_motion_hooks
;
69 /* Non-nil means don't actually do any redisplay. */
71 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
73 /* Nonzero means print newline to stdout before next minibuffer message. */
75 int noninteractive_need_newline
;
77 /* Nonzero means print newline to message log before next message. */
79 static int message_log_need_newline
;
81 #define min(a, b) ((a) < (b) ? (a) : (b))
82 #define max(a, b) ((a) > (b) ? (a) : (b))
83 #define minmax(floor, val, ceil) \
84 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
86 /* The buffer position of the first character appearing
87 entirely or partially on the current frame line.
88 Or zero, which disables the optimization for the current frame line. */
89 static int this_line_bufpos
;
91 /* Number of characters past the end of this line,
92 including the terminating newline */
93 static int this_line_endpos
;
95 /* The vertical position of this frame line. */
96 static int this_line_vpos
;
98 /* Hpos value for start of display on this frame line.
99 Usually zero, but negative if first character really began
101 static int this_line_start_hpos
;
103 /* Buffer that this_line variables are describing. */
104 static struct buffer
*this_line_buffer
;
106 /* Value of echo_area_glyphs when it was last acted on.
107 If this is nonzero, there is a message on the frame
108 in the minibuffer and it should be erased as soon
109 as it is no longer requested to appear. */
110 char *previous_echo_glyphs
;
112 /* Nonzero means truncate lines in all windows less wide than the frame */
113 int truncate_partial_width_windows
;
115 /* Nonzero means we have more than one non-minibuffer-only frame.
116 Not guaranteed to be accurate except while parsing frame-title-format. */
119 Lisp_Object Vglobal_mode_string
;
121 /* Marker for where to display an arrow on top of the buffer text. */
122 Lisp_Object Voverlay_arrow_position
;
124 /* String to display for the arrow. */
125 Lisp_Object Voverlay_arrow_string
;
127 /* Values of those variables at last redisplay.
128 However, if Voverlay_arrow_position is a marker,
129 last_arrow_position is its numerical position. */
130 static Lisp_Object last_arrow_position
, last_arrow_string
;
132 /* Like mode-line-format, but for the titlebar on a visible frame. */
133 Lisp_Object Vframe_title_format
;
135 /* Like mode-line-format, but for the titlebar on an iconified frame. */
136 Lisp_Object Vicon_title_format
;
138 /* List of functions to call when a window's size changes. These
139 functions get one arg, a frame on which one or more windows' sizes
141 static Lisp_Object Vwindow_size_change_functions
;
143 Lisp_Object Qmenu_bar_update_hook
;
145 /* Nonzero if overlay arrow has been displayed once in this window. */
146 static int overlay_arrow_seen
;
148 /* Nonzero if visible end of buffer has already been displayed once
149 in this window. (We need this variable in case there are overlay
150 strings that get displayed there.) */
151 static int zv_strings_seen
;
153 /* Nonzero means highlight the region even in nonselected windows. */
154 static int highlight_nonselected_windows
;
156 /* If cursor motion alone moves point off frame,
157 Try scrolling this many lines up or down if that will bring it back. */
158 static int scroll_step
;
160 /* Non-0 means scroll just far enough to bring point back on the screen,
162 static int scroll_conservatively
;
164 /* Recenter the window whenever point gets within this many lines
165 of the top or bottom of the window. */
168 /* Number of characters of overlap to show,
169 when scrolling a one-line window such as a minibuffer. */
170 static int minibuffer_scroll_overlap
;
172 /* Nonzero if try_window_id has made blank lines at window bottom
173 since the last redisplay that paused */
174 static int blank_end_of_window
;
176 /* Number of windows showing the buffer of the selected window
177 (or another buffer with the same base buffer).
178 keyboard.c refers to this. */
181 /* display_text_line sets these to the frame position (origin 0) of point,
182 whether the window is selected or not.
183 Set one to -1 first to determine whether point was found afterwards. */
185 static int cursor_vpos
;
186 static int cursor_hpos
;
188 static int debug_end_pos
;
190 /* Nonzero means display mode line highlighted */
191 int mode_line_inverse_video
;
193 static void redisplay_internal ();
194 static int message_log_check_duplicate ();
195 static void echo_area_display ();
196 void mark_window_display_accurate ();
197 static void redisplay_windows ();
198 static void redisplay_window ();
199 static void update_menu_bar ();
200 static void try_window ();
201 static int try_window_id ();
202 static struct position
*display_text_line ();
203 static void display_mode_line ();
204 static int display_mode_element ();
205 static char *decode_mode_spec ();
206 static int display_string ();
207 static void display_menu_bar ();
208 static int display_count_lines ();
210 /* Prompt to display in front of the minibuffer contents */
211 Lisp_Object minibuf_prompt
;
213 /* Width in columns of current minibuffer prompt. */
214 int minibuf_prompt_width
;
216 /* Message to display instead of minibuffer contents
217 This is what the functions error and message make,
218 and command echoing uses it as well.
219 It overrides the minibuf_prompt as well as the buffer. */
220 char *echo_area_glyphs
;
222 /* This is the length of the message in echo_area_glyphs. */
223 int echo_area_glyphs_length
;
225 /* This is the window where the echo area message was displayed.
226 It is always a minibuffer window, but it may not be the
227 same window currently active as a minibuffer. */
228 Lisp_Object echo_area_window
;
230 /* Nonzero means multibyte characters were enabled when the echo area
231 message was specified. */
232 int message_enable_multibyte
;
234 /* true iff we should redraw the mode lines on the next redisplay */
235 int update_mode_lines
;
237 /* Smallest number of characters before the gap
238 at any time since last redisplay that finished.
239 Valid for current buffer when try_window_id can be called. */
242 /* Smallest number of characters after the gap
243 at any time since last redisplay that finished.
244 Valid for current buffer when try_window_id can be called. */
247 /* MODIFF as of last redisplay that finished;
248 if it matches MODIFF, and overlay_unchanged_modified
249 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
250 contain no useful information */
251 int unchanged_modified
;
253 /* OVERLAY_MODIFF as of last redisplay that finished. */
254 int overlay_unchanged_modified
;
256 /* Nonzero if window sizes or contents have changed
257 since last redisplay that finished */
258 int windows_or_buffers_changed
;
260 /* Nonzero after display_mode_line if %l was used
261 and it displayed a line number. */
262 int line_number_displayed
;
264 /* Maximum buffer size for which to display line numbers. */
265 static int line_number_display_limit
;
267 /* Number of lines to keep in the message log buffer.
268 t means infinite. nil means don't log at all. */
269 Lisp_Object Vmessage_log_max
;
271 #define COERCE_MARKER(X) \
272 (MARKERP ((X)) ? Fmarker_position (X) : (X))
274 static int pos_tab_offset
P_ ((struct window
*, int, int));
276 /* Output a newline in the *Messages* buffer if "needs" one. */
279 message_log_maybe_newline ()
281 if (message_log_need_newline
)
282 message_dolog ("", 0, 1, 0);
286 /* Add a string to the message log, optionally terminated with a newline.
287 This function calls low-level routines in order to bypass text property
288 hooks, etc. which might not be safe to run.
289 MULTIBYTE, if nonzero, means interpret the contents of M as multibyte. */
292 message_dolog (m
, len
, nlflag
, multibyte
)
294 int len
, nlflag
, multibyte
;
296 if (!NILP (Vmessage_log_max
))
298 struct buffer
*oldbuf
;
299 Lisp_Object oldpoint
, oldbegv
, oldzv
;
300 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
301 int point_at_end
= 0;
303 Lisp_Object old_deactivate_mark
, tem
;
304 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
306 old_deactivate_mark
= Vdeactivate_mark
;
307 oldbuf
= current_buffer
;
308 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
309 current_buffer
->undo_list
= Qt
;
311 oldpoint
= Fpoint_marker ();
312 oldbegv
= Fpoint_min_marker ();
313 oldzv
= Fpoint_max_marker ();
314 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
322 BEGV_BYTE
= BEG_BYTE
;
325 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
327 /* Insert the string--maybe converting multibyte to single byte
328 or vice versa, so that all the text fits the buffer. */
330 && NILP (current_buffer
->enable_multibyte_characters
))
333 unsigned char work
[1];
334 /* Convert a multibyte string to single-byte
335 for the *Message* buffer. */
336 for (i
= 0; i
< len
; i
+= nbytes
)
338 c
= STRING_CHAR_AND_LENGTH (m
+ i
, len
- i
, nbytes
);
339 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
341 : multibyte_char_to_unibyte (c
, Qnil
));
342 insert_1_both (work
, 1, 1, 1, 0, 0);
346 && ! NILP (current_buffer
->enable_multibyte_characters
))
349 unsigned char *msg
= (unsigned char *) m
;
350 unsigned char *str
, work
[4];
351 /* Convert a single-byte string to multibyte
352 for the *Message* buffer. */
353 for (i
= 0; i
< len
; i
++)
355 c
= unibyte_char_to_multibyte (msg
[i
]);
356 nbytes
= CHAR_STRING (c
, work
, str
);
357 insert_1_both (work
, 1, nbytes
, 1, 0, 0);
361 insert_1 (m
, len
, 1, 0, 0);
365 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
366 insert_1 ("\n", 1, 1, 0, 0);
368 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
370 this_bol_byte
= PT_BYTE
;
374 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
376 prev_bol_byte
= PT_BYTE
;
378 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
379 this_bol
, this_bol_byte
);
382 del_range_both (prev_bol
, prev_bol_byte
,
383 this_bol
, this_bol_byte
, 0);
389 /* If you change this format, don't forget to also
390 change message_log_check_duplicate. */
391 sprintf (dupstr
, " [%d times]", dup
);
392 duplen
= strlen (dupstr
);
393 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
394 insert_1 (dupstr
, duplen
, 1, 0, 1);
399 if (NATNUMP (Vmessage_log_max
))
401 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
402 -XFASTINT (Vmessage_log_max
) - 1, 0);
403 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
406 BEGV
= XMARKER (oldbegv
)->charpos
;
407 BEGV_BYTE
= marker_byte_position (oldbegv
);
416 ZV
= XMARKER (oldzv
)->charpos
;
417 ZV_BYTE
= marker_byte_position (oldzv
);
421 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
423 /* We can't do Fgoto_char (oldpoint) because it will run some
425 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
426 XMARKER (oldpoint
)->bytepos
);
429 free_marker (oldpoint
);
430 free_marker (oldbegv
);
433 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
434 set_buffer_internal (oldbuf
);
436 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
437 message_log_need_newline
= !nlflag
;
438 Vdeactivate_mark
= old_deactivate_mark
;
442 /* We are at the end of the buffer after just having inserted a newline.
443 (Note: We depend on the fact we won't be crossing the gap.)
444 Check to see if the most recent message looks a lot like the previous one.
445 Return 0 if different, 1 if the new one should just replace it, or a
446 value N > 1 if we should also append " [N times]". */
449 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
450 int prev_bol
, this_bol
;
451 int prev_bol_byte
, this_bol_byte
;
454 int len
= Z_BYTE
- 1 - this_bol_byte
;
456 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
457 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
459 for (i
= 0; i
< len
; i
++)
461 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
470 if (*p1
++ == ' ' && *p1
++ == '[')
473 while (*p1
>= '0' && *p1
<= '9')
474 n
= n
* 10 + *p1
++ - '0';
475 if (strncmp (p1
, " times]\n", 8) == 0)
481 /* Display an echo area message M with a specified length of LEN chars.
482 The string may include null characters. If M is 0, clear out any
483 existing message, and let the minibuffer text show through.
485 The buffer M must continue to exist until after the echo area
486 gets cleared or some other message gets displayed there.
488 Do not pass text that is stored in a Lisp string.
489 Do not pass text in a buffer that was alloca'd. */
492 message2 (m
, len
, multibyte
)
497 /* First flush out any partial line written with print. */
498 message_log_maybe_newline ();
500 message_dolog (m
, len
, 1, multibyte
);
501 message2_nolog (m
, len
, multibyte
);
505 /* The non-logging counterpart of message2. */
508 message2_nolog (m
, len
, multibyte
)
512 message_enable_multibyte
= multibyte
;
516 if (noninteractive_need_newline
)
518 noninteractive_need_newline
= 0;
520 fwrite (m
, len
, 1, stderr
);
521 if (cursor_in_echo_area
== 0)
522 fprintf (stderr
, "\n");
525 /* A null message buffer means that the frame hasn't really been
526 initialized yet. Error messages get reported properly by
527 cmd_error, so this must be just an informative message; toss it. */
528 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
530 Lisp_Object mini_window
;
533 /* Get the frame containing the minibuffer
534 that the selected frame is using. */
535 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
536 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
538 FRAME_SAMPLE_VISIBILITY (f
);
539 if (FRAME_VISIBLE_P (selected_frame
)
540 && ! FRAME_VISIBLE_P (f
))
541 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
545 echo_area_glyphs
= m
;
546 echo_area_glyphs_length
= len
;
548 if (minibuffer_auto_raise
)
549 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
552 echo_area_glyphs
= previous_echo_glyphs
= 0;
554 do_pending_window_change ();
555 echo_area_display ();
556 update_frame (f
, 1, 1);
557 do_pending_window_change ();
558 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
559 (*frame_up_to_date_hook
) (f
);
563 /* Display in echo area the null-terminated ASCII-only string M.
564 If M is 0, clear out any existing message,
565 and let the minibuffer text show through.
567 The string M must continue to exist until after the echo area
568 gets cleared or some other message gets displayed there.
570 Do not pass text that is stored in a Lisp string.
571 Do not pass text in a buffer that was alloca'd. */
577 message2 (m
, (m
? strlen (m
) : 0), 0);
584 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
587 /* Display a message M which contains a single %s
588 which gets replaced with STRING. */
591 message_with_string (m
, string
, log
)
600 if (noninteractive_need_newline
)
602 noninteractive_need_newline
= 0;
603 fprintf (stderr
, m
, XSTRING (string
)->data
);
604 if (cursor_in_echo_area
== 0)
605 fprintf (stderr
, "\n");
609 else if (INTERACTIVE
)
611 /* The frame whose minibuffer we're going to display the message on.
612 It may be larger than the selected frame, so we need
613 to use its buffer, not the selected frame's buffer. */
614 Lisp_Object mini_window
;
617 /* Get the frame containing the minibuffer
618 that the selected frame is using. */
619 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
620 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
622 /* A null message buffer means that the frame hasn't really been
623 initialized yet. Error messages get reported properly by
624 cmd_error, so this must be just an informative message; toss it. */
625 if (FRAME_MESSAGE_BUF (f
))
629 a
[0] = (char *) XSTRING (string
)->data
;
631 len
= doprnt (FRAME_MESSAGE_BUF (f
),
632 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
635 message2 (FRAME_MESSAGE_BUF (f
), len
,
636 STRING_MULTIBYTE (string
));
638 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
639 STRING_MULTIBYTE (string
));
641 /* Print should start at the beginning of the message
643 message_buf_print
= 0;
648 /* Truncate what will be displayed in the echo area
649 the next time we display it--but don't redisplay it now. */
652 truncate_echo_area (len
)
655 /* A null message buffer means that the frame hasn't really been
656 initialized yet. Error messages get reported properly by
657 cmd_error, so this must be just an informative message; toss it. */
658 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
659 echo_area_glyphs_length
= len
;
662 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
663 zero if being used by message. */
664 int message_buf_print
;
666 /* Dump an informative message to the minibuf. If M is 0, clear out
667 any existing message, and let the minibuffer text show through. */
671 message (m
, a1
, a2
, a3
)
673 EMACS_INT a1
, a2
, a3
;
679 if (noninteractive_need_newline
)
681 noninteractive_need_newline
= 0;
682 fprintf (stderr
, m
, a1
, a2
, a3
);
683 if (cursor_in_echo_area
== 0)
684 fprintf (stderr
, "\n");
688 else if (INTERACTIVE
)
690 /* The frame whose minibuffer we're going to display the message on.
691 It may be larger than the selected frame, so we need
692 to use its buffer, not the selected frame's buffer. */
693 Lisp_Object mini_window
;
696 /* Get the frame containing the minibuffer
697 that the selected frame is using. */
698 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
699 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
701 /* A null message buffer means that the frame hasn't really been
702 initialized yet. Error messages get reported properly by
703 cmd_error, so this must be just an informative message; toss it. */
704 if (FRAME_MESSAGE_BUF (f
))
715 len
= doprnt (FRAME_MESSAGE_BUF (f
),
716 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
718 len
= doprnt (FRAME_MESSAGE_BUF (f
),
719 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
721 #endif /* NO_ARG_ARRAY */
723 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
728 /* Print should start at the beginning of the message
730 message_buf_print
= 0;
735 /* The non-logging version of message. */
737 message_nolog (m
, a1
, a2
, a3
)
739 EMACS_INT a1
, a2
, a3
;
741 Lisp_Object old_log_max
;
742 old_log_max
= Vmessage_log_max
;
743 Vmessage_log_max
= Qnil
;
744 message (m
, a1
, a2
, a3
);
745 Vmessage_log_max
= old_log_max
;
751 message2 (echo_area_glyphs
, echo_area_glyphs_length
,
752 ! NILP (current_buffer
->enable_multibyte_characters
));
760 Lisp_Object mini_window
;
762 /* Choose the minibuffer window for this display.
763 It is the minibuffer window used by the selected frame. */
764 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
765 /* This is the frame that window is in. */
766 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
768 if (! FRAME_VISIBLE_P (f
))
773 redraw_garbaged_frames ();
777 if (echo_area_glyphs
|| minibuf_level
== 0)
781 echo_area_window
= mini_window
;
783 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
784 get_display_line (f
, vpos
, 0);
786 /* Make sure the columns that overlap a left-hand scroll bar
788 for (i
= 0; i
< FRAME_LEFT_SCROLL_BAR_WIDTH (f
); i
++)
789 f
->desired_glyphs
->glyphs
[vpos
][i
] = SPACEGLYPH
;
791 display_string (XWINDOW (mini_window
), vpos
,
792 echo_area_glyphs
? echo_area_glyphs
: "",
793 echo_area_glyphs
? echo_area_glyphs_length
: -1,
794 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
796 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
797 message_enable_multibyte
);
799 #if 0 /* This just gets in the way. update_frame does the job. */
800 /* If desired cursor location is on this line, put it at end of text */
801 if (cursor_in_echo_area
)
802 FRAME_CURSOR_Y (f
) = vpos
;
803 if (FRAME_CURSOR_Y (f
) == vpos
)
804 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
807 /* Fill the rest of the minibuffer window with blank lines. */
812 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
814 get_display_line (f
, i
, 0);
815 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
816 hpos, because it is good to clear whatever is behind the
817 scroll bar. This does not affect the scroll bar itself. */
818 display_string (XWINDOW (mini_window
), i
,
821 0, FRAME_WIDTH (f
) + FRAME_SCROLL_BAR_WIDTH (f
),
826 else if (!EQ (mini_window
, selected_window
))
827 windows_or_buffers_changed
++;
829 if (EQ (mini_window
, selected_window
))
830 this_line_bufpos
= 0;
832 previous_echo_glyphs
= echo_area_glyphs
;
835 /* Update frame titles. */
837 #ifdef HAVE_WINDOW_SYSTEM
838 static char frame_title_buf
[512];
839 static char *frame_title_ptr
;
842 store_frame_title (str
, mincol
, maxcol
)
847 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
848 maxcol
= sizeof (frame_title_buf
);
849 limit
= &frame_title_buf
[maxcol
];
850 while (*str
!= '\0' && frame_title_ptr
< limit
)
851 *frame_title_ptr
++ = *str
++;
852 while (frame_title_ptr
< &frame_title_buf
[mincol
])
853 *frame_title_ptr
++ = ' ';
854 return frame_title_ptr
- frame_title_buf
;
858 x_consider_frame_title (frame
)
864 FRAME_PTR f
= XFRAME (frame
);
866 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
869 /* Do we have more than one visible frame on this X display? */
873 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
875 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
877 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
878 && !FRAME_MINIBUF_ONLY_P (tf
)
879 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
883 multiple_frames
= CONSP (tail
);
886 obuf
= current_buffer
;
887 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
888 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
889 frame_title_ptr
= frame_title_buf
;
890 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
891 0, sizeof (frame_title_buf
), fmt
);
893 set_buffer_internal (obuf
);
894 /* Set the name only if it's changed. This avoids consing
895 in the common case where it hasn't. (If it turns out that we've
896 already wasted too much time by walking through the list with
897 display_mode_element, then we might need to optimize at a higher
899 if (! STRINGP (f
->name
) || STRING_BYTES (XSTRING (f
->name
)) != len
900 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
901 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
904 #define frame_title_ptr ((char *)0)
905 #define store_frame_title(str, mincol, maxcol) 0
908 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
909 This can call eval. */
914 register struct window
*w
= XWINDOW (selected_window
);
916 struct gcpro gcpro1
, gcpro2
;
918 all_windows
= (update_mode_lines
|| buffer_shared
> 1
919 || windows_or_buffers_changed
);
921 /* Update all frame titles based on their buffer names, etc.
922 We do this before the menu bars so that the buffer-menu
923 will show the up-to-date frame titles.
925 This used to be done after the menu bars, for a reason that
926 was stated as follows but which I do not understand:
927 "We do this after the menu bars so that the frame will first
928 create its menu bar using the name `emacs' if no other name
929 has yet been specified."
930 I think that is no longer a concern. */
931 #ifdef HAVE_WINDOW_SYSTEM
932 if (windows_or_buffers_changed
|| update_mode_lines
)
934 Lisp_Object tail
, frame
;
936 FOR_EACH_FRAME (tail
, frame
)
937 if (FRAME_VISIBLE_P (XFRAME (frame
))
938 || FRAME_ICONIFIED_P (XFRAME (frame
)))
939 x_consider_frame_title (frame
);
943 /* Update the menu bar item lists, if appropriate.
944 This has to be done before any actual redisplay
945 or generation of display lines. */
948 Lisp_Object tail
, frame
;
949 int count
= specpdl_ptr
- specpdl
;
951 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
953 FOR_EACH_FRAME (tail
, frame
)
955 /* If a window on this frame changed size,
956 report that to the user and clear the size-change flag. */
957 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
959 Lisp_Object functions
;
960 /* Clear flag first in case we get error below. */
961 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
962 functions
= Vwindow_size_change_functions
;
963 GCPRO2 (tail
, functions
);
964 while (CONSP (functions
))
966 call1 (XCONS (functions
)->car
, frame
);
967 functions
= XCONS (functions
)->cdr
;
972 update_menu_bar (XFRAME (frame
), 0);
976 unbind_to (count
, Qnil
);
979 update_menu_bar (selected_frame
, 1);
981 /* Motif needs this. See comment in xmenu.c.
982 Turn it off when pending_menu_activation is not defined. */
984 pending_menu_activation
= 0;
988 /* Do a frame update, taking possible shortcuts into account.
989 This is the main external entry point for redisplay.
991 If the last redisplay displayed an echo area message and that
992 message is no longer requested, we clear the echo area
993 or bring back the minibuffer if that is in use.
995 Do not call eval from within this function.
996 Calls to eval after the call to echo_area_display would confuse
997 the display_line mechanism and would cause a crash.
998 Calls to eval before that point will work most of the time,
999 but can still lose, because this function
1000 can be called from signal handlers; with alarms set up;
1001 or with synchronous processes running.
1003 See Fcall_process; if you called it from here, it could be
1004 entered recursively. */
1006 static int do_verify_charstarts
;
1008 /* Counter is used to clear the face cache
1009 no more than once ever 1000 redisplays. */
1010 static int clear_face_cache_count
;
1012 /* Record the previous terminal frame we displayed. */
1013 static FRAME_PTR previous_terminal_frame
;
1018 redisplay_internal (0);
1021 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
1022 is not in response to any user action; therefore, we should
1023 preserve the echo area. (Actually, our caller does that job.)
1024 Perhaps in the future avoid recentering windows
1025 if it is not necessary; currently that causes some problems. */
1028 redisplay_internal (preserve_echo_area
)
1029 int preserve_echo_area
;
1031 register struct window
*w
= XWINDOW (selected_window
);
1033 int must_finish
= 0;
1035 register int tlbufpos
, tlendpos
;
1036 struct position pos
;
1037 int number_of_visible_frames
;
1042 #ifdef USE_X_TOOLKIT
1043 if (popup_activated ())
1047 if (! NILP (Vinhibit_redisplay
))
1052 if (! FRAME_WINDOW_P (selected_frame
)
1053 && previous_terminal_frame
!= selected_frame
)
1055 /* Since frames on an ASCII terminal share the same display area,
1056 displaying a different frame means redisplay the whole thing. */
1057 windows_or_buffers_changed
++;
1058 SET_FRAME_GARBAGED (selected_frame
);
1059 XSETFRAME (Vterminal_frame
, selected_frame
);
1061 previous_terminal_frame
= selected_frame
;
1063 /* Set the visible flags for all frames.
1064 Do this before checking for resized or garbaged frames; they want
1065 to know if their frames are visible.
1066 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
1068 Lisp_Object tail
, frame
;
1070 number_of_visible_frames
= 0;
1072 FOR_EACH_FRAME (tail
, frame
)
1074 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1076 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1077 number_of_visible_frames
++;
1079 /* Clear out all the display lines in which we will generate the
1080 glyphs to display. */
1081 init_desired_glyphs (XFRAME (frame
));
1085 /* Notice any pending interrupt request to change frame size. */
1086 do_pending_window_change ();
1090 redraw_garbaged_frames ();
1094 prepare_menu_bars ();
1096 if (windows_or_buffers_changed
)
1097 update_mode_lines
++;
1099 /* Detect case that we need to write or remove a star in the mode line. */
1100 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
1102 w
->update_mode_line
= Qt
;
1103 if (buffer_shared
> 1)
1104 update_mode_lines
++;
1107 /* If %c is in use, update it if needed. */
1108 if (!NILP (w
->column_number_displayed
)
1109 /* This alternative quickly identifies a common case
1110 where no change is needed. */
1111 && !(PT
== XFASTINT (w
->last_point
)
1112 && XFASTINT (w
->last_modified
) >= MODIFF
1113 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1114 && XFASTINT (w
->column_number_displayed
) != current_column ())
1115 w
->update_mode_line
= Qt
;
1117 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
1119 all_windows
= update_mode_lines
|| buffer_shared
> 1;
1121 /* If specs for an arrow have changed, do thorough redisplay
1122 to ensure we remove any arrow that should no longer exist. */
1123 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
1124 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
1127 /* Normally the message* functions will have already displayed and
1128 updated the echo area, but the frame may have been trashed, or
1129 the update may have been preempted, so display the echo area
1131 if (echo_area_glyphs
|| previous_echo_glyphs
)
1133 echo_area_display ();
1137 /* If showing region, and mark has changed, must redisplay whole window. */
1138 if (((!NILP (Vtransient_mark_mode
)
1139 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1140 != !NILP (w
->region_showing
))
1141 || (!NILP (w
->region_showing
)
1142 && !EQ (w
->region_showing
,
1143 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
1144 this_line_bufpos
= -1;
1146 tlbufpos
= this_line_bufpos
;
1147 tlendpos
= this_line_endpos
;
1148 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
1149 && !current_buffer
->clip_changed
1150 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
1151 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
1152 /* Make sure recorded data applies to current buffer, etc */
1153 && this_line_buffer
== current_buffer
1154 && current_buffer
== XBUFFER (w
->buffer
)
1155 && NILP (w
->force_start
)
1156 /* Point must be on the line that we have info recorded about */
1158 && PT
<= Z
- tlendpos
1159 /* All text outside that line, including its final newline,
1160 must be unchanged */
1161 && ((XFASTINT (w
->last_modified
) >= MODIFF
1162 && (XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
))
1163 || (beg_unchanged
>= tlbufpos
- 1
1165 /* If selective display, can't optimize
1166 if the changes start at the beginning of the line. */
1167 && ((INTEGERP (current_buffer
->selective_display
)
1168 && XINT (current_buffer
->selective_display
) > 0
1169 ? (beg_unchanged
>= tlbufpos
1172 && end_unchanged
>= tlendpos
1173 && Z
- GPT
>= tlendpos
)))
1175 int tlbufpos_byte
= CHAR_TO_BYTE (tlbufpos
);
1176 if (tlbufpos
> BEGV
&& FETCH_BYTE (tlbufpos_byte
- 1) != '\n'
1178 || FETCH_BYTE (tlbufpos_byte
) == '\n'))
1179 /* Former continuation line has disappeared by becoming empty */
1181 else if (XFASTINT (w
->last_modified
) < MODIFF
1182 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
1183 || MINI_WINDOW_P (w
))
1185 /* We have to handle the case of continuation around a
1186 wide-column character (See the comment in indent.c around
1189 For instance, in the following case:
1191 -------- Insert --------
1192 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1193 J_I_ ==> J_I_ `^^' are cursors.
1197 As we have to redraw the line above, we should goto cancel. */
1199 struct position val
;
1201 int opoint
= PT
, opoint_byte
= PT_BYTE
;
1203 scan_newline (tlbufpos
, tlbufpos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
1205 val
= *compute_motion (PT
, 0,
1206 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1209 1 << (BITS_PER_SHORT
- 1),
1210 1 << (BITS_PER_SHORT
- 1),
1211 window_internal_width (w
) - 1,
1212 XINT (w
->hscroll
), 0, w
);
1213 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
1214 if (val
.hpos
!= this_line_start_hpos
)
1218 overlay_arrow_seen
= 0;
1219 zv_strings_seen
= 0;
1220 display_text_line (w
, tlbufpos
, tlbufpos_byte
,
1221 this_line_vpos
, this_line_start_hpos
,
1222 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
), 0);
1223 /* If line contains point, is not continued,
1224 and ends at same distance from eob as before, we win */
1225 if (cursor_vpos
>= 0 && this_line_bufpos
1226 && this_line_endpos
== tlendpos
)
1228 /* If this is not the window's last line,
1229 we must adjust the charstarts of the lines below. */
1230 if (this_line_vpos
+ 1
1231 < XFASTINT (w
->top
) + window_internal_height (w
))
1233 int left
= WINDOW_LEFT_MARGIN (w
);
1234 int *charstart_next_line
1235 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
1238 if (Z
- tlendpos
== ZV
)
1239 /* This line ends at end of (accessible part of) buffer.
1240 There is no newline to count. */
1241 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
1243 /* This line ends in a newline.
1244 Must take account of the newline and the rest of the
1245 text that follows. */
1246 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
1248 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
1251 if (!WINDOW_FULL_WIDTH_P (w
))
1252 preserve_other_columns (w
);
1258 else if (PT
== XFASTINT (w
->last_point
)
1259 /* Make sure the cursor was last displayed
1260 in this window. Otherwise we have to reposition it. */
1261 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
1262 && (XINT (w
->top
) + XINT (w
->height
)
1263 > FRAME_CURSOR_Y (selected_frame
)))
1267 do_pending_window_change ();
1272 /* If highlighting the region, or if the cursor is in the echo area,
1273 then we can't just move the cursor. */
1274 else if (! (!NILP (Vtransient_mark_mode
)
1275 && !NILP (current_buffer
->mark_active
))
1276 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1277 || highlight_nonselected_windows
)
1278 && NILP (w
->region_showing
)
1279 && !cursor_in_echo_area
)
1281 pos
= *compute_motion (tlbufpos
, 0,
1282 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1284 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
1285 window_internal_width (w
) - 1,
1287 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
),
1291 int width
= window_internal_width (w
) - 1;
1292 FRAME_CURSOR_X (selected_frame
)
1293 = WINDOW_LEFT_MARGIN (w
) + minmax (0, pos
.hpos
, width
);
1294 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1301 /* Text changed drastically or point moved off of line */
1302 cancel_line (this_line_vpos
, selected_frame
);
1305 this_line_bufpos
= 0;
1306 all_windows
|= buffer_shared
> 1;
1308 clear_face_cache_count
++;
1312 Lisp_Object tail
, frame
;
1315 /* Clear the face cache, only when we do a full redisplay
1316 and not too often either. */
1317 if (clear_face_cache_count
> 1000)
1319 clear_face_cache ();
1320 clear_face_cache_count
= 0;
1324 /* Recompute # windows showing selected buffer.
1325 This will be incremented each time such a window is displayed. */
1328 FOR_EACH_FRAME (tail
, frame
)
1330 FRAME_PTR f
= XFRAME (frame
);
1331 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
1334 /* Mark all the scroll bars to be removed; we'll redeem the ones
1335 we want when we redisplay their windows. */
1336 if (condemn_scroll_bars_hook
)
1337 (*condemn_scroll_bars_hook
) (f
);
1339 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1340 redisplay_windows (FRAME_ROOT_WINDOW (f
), preserve_echo_area
);
1342 /* Any scroll bars which redisplay_windows should have nuked
1343 should now go away. */
1344 if (judge_scroll_bars_hook
)
1345 (*judge_scroll_bars_hook
) (f
);
1349 else if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1351 redisplay_window (selected_window
, 1, preserve_echo_area
);
1352 if (!WINDOW_FULL_WIDTH_P (w
))
1353 preserve_other_columns (w
);
1357 /* Prevent various kinds of signals during display update.
1358 stdio is not robust about handling signals,
1359 which can cause an apparent I/O error. */
1360 if (interrupt_input
)
1370 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1374 if (!FRAMEP (XCONS (tail
)->car
))
1377 f
= XFRAME (XCONS (tail
)->car
);
1379 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
1380 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1382 pause
|= update_frame (f
, 0, 0);
1385 mark_window_display_accurate (f
->root_window
, 1);
1386 if (frame_up_to_date_hook
!= 0)
1387 (*frame_up_to_date_hook
) (f
);
1394 if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1395 pause
= update_frame (selected_frame
, 0, 0);
1399 /* We may have called echo_area_display at the top of this
1400 function. If the echo area is on another frame, that may
1401 have put text on a frame other than the selected one, so the
1402 above call to update_frame would not have caught it. Catch
1405 Lisp_Object mini_window
;
1406 FRAME_PTR mini_frame
;
1408 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1409 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1411 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
1412 pause
|= update_frame (mini_frame
, 0, 0);
1416 /* If frame does not match, prevent doing single-line-update next time.
1417 Also, don't forget to check every line to update the arrow. */
1420 this_line_bufpos
= 0;
1421 if (!NILP (last_arrow_position
))
1423 last_arrow_position
= Qt
;
1424 last_arrow_string
= Qt
;
1426 /* If we pause after scrolling, some lines in current_frame
1427 may be null, so preserve_other_columns won't be able to
1428 preserve all the vertical-bar separators. So, avoid using it
1430 if (!WINDOW_FULL_WIDTH_P (w
))
1431 update_mode_lines
= 1;
1434 /* Now text on frame agrees with windows, so
1435 put info into the windows for partial redisplay to follow */
1439 register struct buffer
*b
= XBUFFER (w
->buffer
);
1441 blank_end_of_window
= 0;
1442 unchanged_modified
= BUF_MODIFF (b
);
1443 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
1444 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1445 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1447 /* Record the last place cursor was displayed in this window.
1448 But not if cursor is in the echo area, because in that case
1449 FRAME_CURSOR_X and FRAME_CURSOR_Y are in the echo area. */
1450 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (selected_frame
)
1451 && EQ (FRAME_MINIBUF_WINDOW (selected_frame
), minibuf_window
)))
1453 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1454 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1455 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1458 /* Make last_point invalid, since we don't really know
1459 where the cursor would be if it were not in the echo area. */
1460 XSETINT (w
->last_point
, -1);
1463 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1466 b
->clip_changed
= 0;
1467 w
->update_mode_line
= Qnil
;
1468 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1469 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
1471 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1474 /* Record if we are showing a region, so can make sure to
1475 update it fully at next redisplay. */
1476 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1477 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1478 || highlight_nonselected_windows
)
1479 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1480 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1483 w
->window_end_valid
= w
->buffer
;
1484 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1485 last_arrow_string
= Voverlay_arrow_string
;
1486 if (do_verify_charstarts
)
1487 verify_charstarts (w
);
1488 if (frame_up_to_date_hook
!= 0)
1489 (*frame_up_to_date_hook
) (selected_frame
);
1491 update_mode_lines
= 0;
1492 windows_or_buffers_changed
= 0;
1495 /* Start SIGIO interrupts coming again.
1496 Having them off during the code above
1497 makes it less likely one will discard output,
1498 but not impossible, since there might be stuff
1499 in the system buffer here.
1500 But it is much hairier to try to do anything about that. */
1502 if (interrupt_input
)
1506 /* If something has become visible now which was not before,
1507 redisplay again, so that we get them. */
1510 Lisp_Object tail
, frame
;
1513 FOR_EACH_FRAME (tail
, frame
)
1515 int this_is_visible
= 0;
1517 if (XFRAME (frame
)->visible
)
1518 this_is_visible
= 1;
1519 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1520 if (XFRAME (frame
)->visible
)
1521 this_is_visible
= 1;
1523 if (this_is_visible
)
1527 if (new_count
!= number_of_visible_frames
)
1528 windows_or_buffers_changed
++;
1531 /* Change frame size now if a change is pending. */
1532 do_pending_window_change ();
1534 /* If we just did a pending size change, or have additional
1535 visible frames, redisplay again. */
1536 if (windows_or_buffers_changed
&& !pause
)
1540 /* Redisplay, but leave alone any recent echo area message
1541 unless another message has been requested in its place.
1543 This is useful in situations where you need to redisplay but no
1544 user action has occurred, making it inappropriate for the message
1545 area to be cleared. See tracking_off and
1546 wait_reading_process_input for examples of these situations. */
1549 redisplay_preserve_echo_area ()
1551 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1553 echo_area_glyphs
= previous_echo_glyphs
;
1554 redisplay_internal (1);
1555 echo_area_glyphs
= 0;
1558 redisplay_internal (1);
1562 mark_window_display_accurate (window
, flag
)
1566 register struct window
*w
;
1568 for (;!NILP (window
); window
= w
->next
)
1570 if (!WINDOWP (window
)) abort ();
1571 w
= XWINDOW (window
);
1573 if (!NILP (w
->buffer
))
1575 XSETFASTINT (w
->last_modified
,
1576 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1577 XSETFASTINT (w
->last_overlay_modified
,
1578 !flag
? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)));
1580 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1583 /* Record if we are showing a region, so can make sure to
1584 update it fully at next redisplay. */
1585 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1586 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1587 || highlight_nonselected_windows
)
1588 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1589 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1593 w
->window_end_valid
= w
->buffer
;
1594 w
->update_mode_line
= Qnil
;
1595 if (!NILP (w
->buffer
) && flag
)
1596 XBUFFER (w
->buffer
)->clip_changed
= 0;
1598 if (!NILP (w
->vchild
))
1599 mark_window_display_accurate (w
->vchild
, flag
);
1600 if (!NILP (w
->hchild
))
1601 mark_window_display_accurate (w
->hchild
, flag
);
1606 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1607 last_arrow_string
= Voverlay_arrow_string
;
1611 /* t is unequal to any useful value of Voverlay_arrow_... */
1612 last_arrow_position
= Qt
;
1613 last_arrow_string
= Qt
;
1617 /* Update the menu bar item list for frame F.
1618 This has to be done before we start to fill in any display lines,
1619 because it can call eval.
1621 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1624 update_menu_bar (f
, save_match_data
)
1626 int save_match_data
;
1628 struct buffer
*old
= current_buffer
;
1630 register struct window
*w
;
1632 window
= FRAME_SELECTED_WINDOW (f
);
1633 w
= XWINDOW (window
);
1635 if (update_mode_lines
)
1636 w
->update_mode_line
= Qt
;
1638 if (FRAME_WINDOW_P (f
)
1640 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1641 FRAME_EXTERNAL_MENU_BAR (f
)
1643 FRAME_MENU_BAR_LINES (f
) > 0
1645 : FRAME_MENU_BAR_LINES (f
) > 0)
1647 /* If the user has switched buffers or windows, we need to
1648 recompute to reflect the new bindings. But we'll
1649 recompute when update_mode_lines is set too; that means
1650 that people can use force-mode-line-update to request
1651 that the menu bar be recomputed. The adverse effect on
1652 the rest of the redisplay algorithm is about the same as
1653 windows_or_buffers_changed anyway. */
1654 if (windows_or_buffers_changed
1655 || !NILP (w
->update_mode_line
)
1656 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1657 < BUF_MODIFF (XBUFFER (w
->buffer
)))
1658 != !NILP (w
->last_had_star
))
1659 || ((!NILP (Vtransient_mark_mode
)
1660 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1661 != !NILP (w
->region_showing
)))
1663 struct buffer
*prev
= current_buffer
;
1664 int count
= specpdl_ptr
- specpdl
;
1666 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1667 if (save_match_data
)
1668 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1669 if (NILP (Voverriding_local_map_menu_flag
))
1671 specbind (Qoverriding_terminal_local_map
, Qnil
);
1672 specbind (Qoverriding_local_map
, Qnil
);
1675 /* Run the Lucid hook. */
1676 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1677 /* If it has changed current-menubar from previous value,
1678 really recompute the menubar from the value. */
1679 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1680 call0 (Qrecompute_lucid_menubar
);
1681 safe_run_hooks (Qmenu_bar_update_hook
);
1682 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1683 /* Redisplay the menu bar in case we changed it. */
1684 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1685 if (FRAME_WINDOW_P (f
))
1686 set_frame_menubar (f
, 0, 0);
1688 /* On a terminal screen, the menu bar is an ordinary screen
1689 line, and this makes it get updated. */
1690 w
->update_mode_line
= Qt
;
1691 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1692 /* In the non-toolkit version, the menu bar is an ordinary screen
1693 line, and this makes it get updated. */
1694 w
->update_mode_line
= Qt
;
1695 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1697 unbind_to (count
, Qnil
);
1698 set_buffer_internal_1 (prev
);
1705 /* Redisplay WINDOW and its subwindows and siblings. */
1708 redisplay_windows (window
, preserve_echo_area
)
1710 int preserve_echo_area
;
1712 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1713 redisplay_window (window
, 0, preserve_echo_area
);
1716 /* Return value in display table DP (Lisp_Char_Table *) for character
1717 C. Since a display table doesn't have any parent, we don't have to
1718 follow parent. Do not call this function directly but use the
1719 macro DISP_CHAR_VECTOR. */
1721 disp_char_vector (dp
, c
)
1722 struct Lisp_Char_Table
*dp
;
1728 if (SINGLE_BYTE_CHAR_P (c
)) return (dp
->contents
[c
]);
1730 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
1731 if (code
[0] != CHARSET_COMPOSITION
)
1733 if (code
[1] < 32) code
[1] = -1;
1734 else if (code
[2] < 32) code
[2] = -1;
1736 /* Here, the possible range of CODE[0] (== charset ID) is
1737 128..MAX_CHARSET. Since the top level char table contains data
1738 for multibyte characters after 256th element, we must increment
1739 CODE[0] by 128 to get a correct index. */
1741 code
[3] = -1; /* anchor */
1743 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
1745 val
= dp
->contents
[code
[i
]];
1746 if (!SUB_CHAR_TABLE_P (val
))
1747 return (NILP (val
) ? dp
->defalt
: val
);
1749 /* Here, VAL is a sub char table. We return the default value of it. */
1750 return (dp
->defalt
);
1753 /* Redisplay window WINDOW and its subwindows. */
1756 redisplay_window (window
, just_this_one
, preserve_echo_area
)
1758 int just_this_one
, preserve_echo_area
;
1760 register struct window
*w
= XWINDOW (window
);
1761 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1764 int lpoint_byte
= PT_BYTE
;
1765 struct buffer
*old
= current_buffer
;
1766 register int width
= window_internal_width (w
) - 1;
1767 register int startp
, startp_byte
;
1768 register int hscroll
= XINT (w
->hscroll
);
1769 struct position pos
;
1771 int opoint_byte
= PT_BYTE
;
1773 int update_mode_line
;
1774 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1775 int really_switched_buffer
= 0;
1776 int count
= specpdl_ptr
- specpdl
;
1778 if (Z
== Z_BYTE
&& lpoint
!= lpoint_byte
)
1780 if (lpoint_byte
< lpoint
)
1783 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1785 /* If this is a combination window, do its children; that's all. */
1787 if (!NILP (w
->vchild
))
1789 redisplay_windows (w
->vchild
, preserve_echo_area
);
1792 if (!NILP (w
->hchild
))
1794 redisplay_windows (w
->hchild
, preserve_echo_area
);
1797 if (NILP (w
->buffer
))
1800 specbind (Qinhibit_point_motion_hooks
, Qt
);
1802 height
= window_internal_height (w
);
1803 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1804 if (XBUFFER (w
->buffer
)->clip_changed
)
1805 update_mode_line
= 1;
1807 if (MINI_WINDOW_P (w
))
1809 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1810 /* We've already displayed the echo area glyphs in this window. */
1811 goto finish_scroll_bars
;
1812 else if (w
!= XWINDOW (minibuf_window
))
1814 /* This is a minibuffer, but it's not the currently active one,
1816 int vpos
= XFASTINT (w
->top
);
1819 for (i
= 0; i
< height
; i
++)
1821 get_display_line (f
, vpos
+ i
, 0);
1822 display_string (w
, vpos
+ i
, "", 0,
1823 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
1827 goto finish_scroll_bars
;
1831 /* Otherwise set up data on this window; select its buffer and point value */
1833 if (update_mode_line
)
1834 /* Really select the buffer, for the sake of buffer-local variables. */
1836 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1837 really_switched_buffer
= 1;
1840 set_buffer_temp (XBUFFER (w
->buffer
));
1843 opoint_byte
= PT_BYTE
;
1845 if (Z
== Z_BYTE
&& opoint
!= opoint_byte
)
1847 if (opoint_byte
< opoint
)
1850 /* If %c is in mode line, update it if needed. */
1851 if (!NILP (w
->column_number_displayed
)
1852 /* This alternative quickly identifies a common case
1853 where no change is needed. */
1854 && !(PT
== XFASTINT (w
->last_point
)
1855 && XFASTINT (w
->last_modified
) >= MODIFF
1856 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1857 && XFASTINT (w
->column_number_displayed
) != current_column ())
1858 update_mode_line
= 1;
1860 /* Count number of windows showing the selected buffer.
1861 An indirect buffer counts as its base buffer. */
1865 struct buffer
*current_base
, *window_base
;
1866 current_base
= current_buffer
;
1867 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1868 if (current_base
->base_buffer
)
1869 current_base
= current_base
->base_buffer
;
1870 if (window_base
->base_buffer
)
1871 window_base
= window_base
->base_buffer
;
1872 if (current_base
== window_base
)
1876 /* POINT refers normally to the selected window.
1877 For any other window, set up appropriate value. */
1879 if (!EQ (window
, selected_window
))
1881 int new_pt
= XMARKER (w
->pointm
)->charpos
;
1882 int new_pt_byte
= marker_byte_position (w
->pointm
);
1886 new_pt_byte
= BEGV_BYTE
;
1887 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
1889 else if (new_pt
> (ZV
- 1))
1892 new_pt_byte
= ZV_BYTE
;
1893 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
1895 /* We don't use SET_PT so that the point-motion hooks don't run. */
1896 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
1899 /* If any of the character widths specified in the display table
1900 have changed, invalidate the width run cache. It's true that this
1901 may be a bit late to catch such changes, but the rest of
1902 redisplay goes (non-fatally) haywire when the display table is
1903 changed, so why should we worry about doing any better? */
1904 if (current_buffer
->width_run_cache
)
1906 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1908 if (! disptab_matches_widthtab (disptab
,
1909 XVECTOR (current_buffer
->width_table
)))
1911 invalidate_region_cache (current_buffer
,
1912 current_buffer
->width_run_cache
,
1914 recompute_width_table (current_buffer
, disptab
);
1918 /* If window-start is screwed up, choose a new one. */
1919 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1922 startp
= marker_position (w
->start
);
1923 startp_byte
= marker_byte_position (w
->start
);
1925 /* If someone specified a new starting point but did not insist,
1926 check whether it can be used. */
1927 if (!NILP (w
->optional_new_start
)
1928 && startp
>= BEGV
&& startp
<= ZV
)
1930 w
->optional_new_start
= Qnil
;
1931 /* Check whether this start pos is usable given where point is. */
1933 pos
= *compute_motion (startp
, 0,
1934 (((EQ (window
, minibuf_window
)
1936 ? minibuf_prompt_width
: 0)
1937 + (hscroll
? 1 - hscroll
: 0)),
1940 /* BUG FIX: See the comment of
1941 Fpos_visible_in_window_p (window.c). */
1942 - (1 << (BITS_PER_SHORT
- 1)),
1944 pos_tab_offset (w
, startp
, startp_byte
), w
);
1945 /* If PT does fit on the screen, we will use this start pos,
1946 so do so by setting force_start. */
1947 if (pos
.bufpos
== PT
)
1948 w
->force_start
= Qt
;
1951 /* Handle case where place to start displaying has been specified,
1952 unless the specified location is outside the accessible range. */
1953 if (!NILP (w
->force_start
))
1955 w
->force_start
= Qnil
;
1956 /* Forget any recorded base line for line number display. */
1957 w
->base_line_number
= Qnil
;
1958 /* The old bottom-of-screen position is no longer valid. */
1959 w
->window_end_valid
= Qnil
;
1960 /* Redisplay the mode line. Select the buffer properly for that.
1961 Also, run the hook window-scroll-functions
1962 because we have scrolled. */
1963 /* Note, we do this after clearing force_start because
1964 if there's an error, it is better to forget about force_start
1965 than to get into an infinite loop calling the hook functions
1966 and having them get more errors. */
1967 if (!update_mode_line
1968 || ! NILP (Vwindow_scroll_functions
))
1970 Lisp_Object temp
[3];
1972 if (!really_switched_buffer
)
1974 set_buffer_temp (old
);
1975 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1977 really_switched_buffer
= 1;
1978 update_mode_line
= 1;
1979 w
->update_mode_line
= Qt
;
1980 if (! NILP (Vwindow_scroll_functions
))
1982 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1983 make_number (startp
));
1984 startp
= marker_position (w
->start
);
1985 startp_byte
= marker_byte_position (w
->start
);
1988 XSETFASTINT (w
->last_modified
, 0);
1989 XSETFASTINT (w
->last_overlay_modified
, 0);
1990 if (startp
< BEGV
) startp
= BEGV
, startp_byte
= BEGV_BYTE
;
1991 if (startp
> ZV
) startp
= ZV
, startp
= ZV_BYTE
;
1992 try_window (window
, startp
);
1993 if (cursor_vpos
< 0)
1995 /* If point does not appear, move point so it does appear */
1996 pos
= *compute_motion (startp
, 0,
1997 (((EQ (window
, minibuf_window
)
1999 ? minibuf_prompt_width
: 0)
2000 + (hscroll
? 1 - hscroll
: 0)),
2003 - (1 << (BITS_PER_SHORT
- 1)),
2005 pos_tab_offset (w
, startp
, startp_byte
),
2007 TEMP_SET_PT_BOTH (pos
.bufpos
, pos
.bytepos
);
2008 if (w
!= XWINDOW (selected_window
))
2009 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
2012 if (current_buffer
== old
)
2015 lpoint_byte
= PT_BYTE
;
2017 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2018 + minmax (0, pos
.hpos
, width
));
2019 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2021 /* If we are highlighting the region,
2022 then we just changed the region, so redisplay to show it. */
2023 if (!NILP (Vtransient_mark_mode
)
2024 && !NILP (current_buffer
->mark_active
))
2026 cancel_my_columns (XWINDOW (window
));
2027 try_window (window
, startp
);
2033 /* Handle case where text has not changed, only point,
2034 and it has not moved off the frame. */
2036 /* This code is not used for minibuffer for the sake of
2037 the case of redisplaying to replace an echo area message;
2038 since in that case the minibuffer contents per se are usually unchanged.
2039 This code is of no real use in the minibuffer since
2040 the handling of this_line_bufpos, etc.,
2041 in redisplay handles the same cases. */
2043 if (XFASTINT (w
->last_modified
) >= MODIFF
2044 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
2045 && PT
>= startp
&& !current_buffer
->clip_changed
2046 && (just_this_one
|| WINDOW_FULL_WIDTH_P (w
))
2047 /* If force-mode-line-update was called, really redisplay;
2048 that's how redisplay is forced after e.g. changing
2049 buffer-invisibility-spec. */
2050 && NILP (w
->update_mode_line
)
2051 /* Can't use this case if highlighting a region. */
2052 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
2053 && NILP (w
->region_showing
)
2054 /* If end pos is out of date, scroll bar and percentage will be wrong */
2055 && INTEGERP (w
->window_end_vpos
)
2056 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
2057 && !EQ (window
, minibuf_window
)
2058 && (!MARKERP (Voverlay_arrow_position
)
2059 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
2061 /* All positions in this clause are relative to the window edge. */
2063 int this_scroll_margin
= scroll_margin
;
2064 int last_point_y
= XFASTINT (w
->last_point_y
) - XINT (w
->top
);
2065 int last_point_x
= (XFASTINT (w
->last_point_x
) - WINDOW_LEFT_MARGIN (w
));
2067 /* Find where PT is located now on the frame. */
2068 /* Check just_this_one as a way of verifying that the
2069 window edges have not changed. */
2070 if (PT
== XFASTINT (w
->last_point
) && just_this_one
2071 /* If CURSOR_IN_ECHO_AREA, last_point_x and last_point_y
2072 refer to the echo area and are not related to this window. */
2073 && ! cursor_in_echo_area
)
2075 pos
.hpos
= last_point_x
;
2076 pos
.vpos
= last_point_y
;
2079 else if (PT
> XFASTINT (w
->last_point
)
2080 && ! cursor_in_echo_area
2081 && XFASTINT (w
->last_point
) > startp
&& just_this_one
2082 /* We can't use this if point is in the left margin of a
2083 hscrolled window, because w->last_point_x has been
2084 clipped to the window edges. */
2085 && !(last_point_x
<= 0 && hscroll
))
2087 int last_point
= XFASTINT (w
->last_point
);
2088 int last_point_byte
= CHAR_TO_BYTE (last_point
);
2089 int tab_offset
= (pos_tab_offset (w
, last_point
, last_point_byte
)
2090 - (last_point_x
+ hscroll
- !! hscroll
));
2092 pos
= *compute_motion (last_point
, last_point_y
, last_point_x
, 0,
2094 /* BUG FIX: See the comment of
2095 Fpos_visible_in_window_p (window.c). */
2096 - (1 << (BITS_PER_SHORT
- 1)),
2103 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
2105 /* BUG FIX: See the comment of
2106 Fpos_visible_in_window_p (window.c). */
2107 - (1 << (BITS_PER_SHORT
- 1)),
2109 pos_tab_offset (w
, startp
, startp_byte
),
2113 /* Don't use a scroll margin that is negative or too large. */
2114 if (this_scroll_margin
< 0)
2115 this_scroll_margin
= 0;
2117 if (XINT (w
->height
) < 4 * scroll_margin
)
2118 this_scroll_margin
= XINT (w
->height
) / 4;
2120 /* If point fits on the screen, and not within the scroll margin,
2122 if (pos
.vpos
< height
- this_scroll_margin
2123 && (pos
.vpos
>= this_scroll_margin
|| startp
== BEGV
))
2125 /* Ok, point is still on frame */
2126 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
2128 /* These variables are supposed to be origin 1 */
2129 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2130 + minmax (0, pos
.hpos
, width
));
2131 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2133 /* This doesn't do the trick, because if a window to the right of
2134 this one must be redisplayed, this does nothing because there
2135 is nothing in DesiredFrame yet, and then the other window is
2136 redisplayed, making likes that are empty in this window's columns.
2137 if (WINDOW_FULL_WIDTH_P (w))
2138 preserve_my_columns (w);
2140 if (current_buffer
->clip_changed
2141 && ! NILP (Vwindow_scroll_functions
))
2142 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2143 make_number (marker_position (w
->start
)));
2147 /* Don't bother trying redisplay with same start;
2148 we already know it will lose. */
2150 /* If current starting point was originally the beginning of a line
2151 but no longer is, find a new starting point. */
2152 else if (!NILP (w
->start_at_line_beg
)
2154 || FETCH_BYTE (startp_byte
- 1) == '\n'))
2158 else if (just_this_one
&& !MINI_WINDOW_P (w
)
2160 && XFASTINT (w
->last_modified
)
2161 /* or else vmotion on first line won't work. */
2162 && ! NILP (w
->start_at_line_beg
)
2163 && ! EQ (w
->window_end_valid
, Qnil
)
2164 && do_id
&& !current_buffer
->clip_changed
2165 && !blank_end_of_window
2166 && WINDOW_FULL_WIDTH_P (w
)
2167 /* Can't use this case if highlighting a region. */
2168 && !(!NILP (Vtransient_mark_mode
)
2169 && !NILP (current_buffer
->mark_active
))
2170 /* Don't use try_window_id if newline
2171 doesn't display as the end of a line. */
2172 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
2173 && NILP (w
->region_showing
)
2174 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
2175 && EQ (last_arrow_string
, Voverlay_arrow_string
)
2176 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
2179 /* tem > 0 means success. tem == -1 means choose new start.
2180 tem == -2 means try again with same start,
2181 and nothing but whitespace follows the changed stuff.
2182 tem == 0 means try again with same start. */
2186 else if (startp
>= BEGV
&& startp
<= ZV
2188 /* Avoid starting at end of buffer. */
2189 #if 0 /* This change causes trouble for M-! finger & RET.
2190 It will have to be considered later. */
2191 || ! EQ (window
, selected_window
)
2192 /* Don't do the recentering if redisplay
2193 is not for no user action. */
2194 || preserve_echo_area
2197 || (XFASTINT (w
->last_modified
) >= MODIFF
2198 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
2200 /* Try to redisplay starting at same place as before */
2201 /* If point has not moved off frame, accept the results */
2202 try_window (window
, startp
);
2203 if (cursor_vpos
>= 0)
2205 if (!just_this_one
|| current_buffer
->clip_changed
2206 || beg_unchanged
< startp
)
2207 /* Forget any recorded base line for line number display. */
2208 w
->base_line_number
= Qnil
;
2210 if (current_buffer
->clip_changed
2211 && ! NILP (Vwindow_scroll_functions
))
2212 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2213 make_number (marker_position (w
->start
)));
2218 cancel_my_columns (w
);
2221 XSETFASTINT (w
->last_modified
, 0);
2222 XSETFASTINT (w
->last_overlay_modified
, 0);
2223 /* Redisplay the mode line. Select the buffer properly for that. */
2224 if (!update_mode_line
)
2226 if (!really_switched_buffer
)
2228 set_buffer_temp (old
);
2229 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2231 update_mode_line
= 1;
2232 w
->update_mode_line
= Qt
;
2235 /* Try to scroll by specified few lines */
2237 if ((scroll_conservatively
|| scroll_step
)
2238 && !current_buffer
->clip_changed
2239 && startp
>= BEGV
&& startp
<= ZV
)
2241 int this_scroll_margin
= scroll_margin
;
2242 int scroll_margin_pos
, scroll_margin_bytepos
;
2243 int scroll_max
= scroll_step
;
2246 if (scroll_conservatively
)
2247 scroll_max
= scroll_conservatively
;
2249 /* Don't use a scroll margin that is negative or too large. */
2250 if (this_scroll_margin
< 0)
2251 this_scroll_margin
= 0;
2253 if (XINT (w
->height
) < 4 * this_scroll_margin
)
2254 this_scroll_margin
= XINT (w
->height
) / 4;
2256 ltemp
= Fwindow_end (window
, Qt
);
2257 scroll_margin_pos
= XINT (ltemp
);
2259 if (this_scroll_margin
)
2261 pos
= *vmotion (scroll_margin_pos
, -this_scroll_margin
, w
);
2262 scroll_margin_pos
= pos
.bufpos
;
2263 scroll_margin_bytepos
= pos
.bytepos
;
2266 scroll_margin_bytepos
= CHAR_TO_BYTE (scroll_margin_pos
);
2268 if (PT
>= scroll_margin_pos
)
2270 struct position pos
;
2271 pos
= *compute_motion (scroll_margin_pos
, 0, 0, 0,
2272 PT
, XFASTINT (w
->height
), 0,
2273 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2274 pos_tab_offset (w
, scroll_margin_pos
,
2275 scroll_margin_bytepos
),
2277 if (pos
.vpos
>= scroll_max
)
2280 pos
= *vmotion (startp
,
2281 scroll_conservatively
? pos
.vpos
+ 1 : scroll_step
,
2284 /* The old bottom-of-screen position is no longer valid. */
2285 w
->window_end_valid
= Qnil
;
2286 if (! NILP (Vwindow_scroll_functions
))
2288 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2289 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2290 make_number (pos
.bufpos
));
2291 pos
.bufpos
= marker_position (w
->start
);
2293 try_window (window
, pos
.bufpos
);
2294 if (cursor_vpos
>= 0)
2296 if (!just_this_one
|| current_buffer
->clip_changed
2297 || beg_unchanged
< startp
)
2298 /* Forget any recorded base line for line number display. */
2299 w
->base_line_number
= Qnil
;
2303 cancel_my_columns (w
);
2306 scroll_margin_pos
= startp
;
2307 if (this_scroll_margin
)
2309 pos
= *vmotion (scroll_margin_pos
, this_scroll_margin
, w
);
2310 scroll_margin_pos
= pos
.bufpos
;
2312 if (PT
< scroll_margin_pos
)
2314 struct position pos
;
2315 pos
= *compute_motion (PT
, 0, 0, 0,
2316 scroll_margin_pos
, XFASTINT (w
->height
), 0,
2317 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2318 pos_tab_offset (w
, PT
, PT_BYTE
),
2320 if (pos
.vpos
> scroll_max
)
2323 pos
= *vmotion (startp
,
2324 scroll_conservatively
? -pos
.vpos
: - scroll_step
,
2327 /* The old bottom-of-screen position is no longer valid. */
2328 w
->window_end_valid
= Qnil
;
2329 if (! NILP (Vwindow_scroll_functions
))
2331 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2332 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2333 make_number (pos
.bufpos
));
2334 pos
.bufpos
= marker_position (w
->start
);
2336 try_window (window
, pos
.bufpos
);
2337 if (cursor_vpos
>= 0)
2339 if (!just_this_one
|| current_buffer
->clip_changed
2340 || beg_unchanged
< startp
)
2341 /* Forget any recorded base line for line number display. */
2342 w
->base_line_number
= Qnil
;
2346 cancel_my_columns (w
);
2352 if (scroll_step
&& ! scroll_margin
&& !current_buffer
->clip_changed
2353 && startp
>= BEGV
&& startp
<= ZV
)
2355 if (margin_call
== 0)
2356 margin_call
= (PT
> startp
? 1 : -1);
2357 if (margin_call
> 0)
2359 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
2360 if (pos
.vpos
>= height
)
2364 pos
= *vmotion (startp
, (margin_call
< 0 ? - scroll_step
: scroll_step
),
2367 if (PT
>= pos
.bufpos
)
2369 /* The old bottom-of-screen position is no longer valid. */
2370 w
->window_end_valid
= Qnil
;
2372 if (! NILP (Vwindow_scroll_functions
))
2374 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2375 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2376 make_number (pos
.bufpos
));
2377 pos
.bufpos
= marker_position (w
->start
);
2379 try_window (window
, pos
.bufpos
);
2380 if (cursor_vpos
>= 0)
2382 if (!just_this_one
|| current_buffer
->clip_changed
2383 || beg_unchanged
< startp
)
2384 /* Forget any recorded base line for line number display. */
2385 w
->base_line_number
= Qnil
;
2389 cancel_my_columns (w
);
2395 /* Finally, just choose place to start which centers point */
2398 /* Forget any previously recorded base line for line number display. */
2399 w
->base_line_number
= Qnil
;
2401 pos
= *vmotion (PT
, - (height
/ 2), w
);
2403 /* The minibuffer is often just one line. Ordinary scrolling
2404 gives little overlap and looks bad. So show 20 chars before point. */
2406 && (pos
.bufpos
>= PT
- minibuffer_scroll_overlap
2407 /* If we scrolled less than 1/2 line forward, we will
2408 get too much overlap, so change to the usual amount. */
2409 || pos
.bufpos
< startp
+ width
/ 2)
2410 && PT
> BEGV
+ minibuffer_scroll_overlap
2411 /* If we scrolled to an actual line boundary,
2412 that's different; don't ignore line boundaries. */
2413 && FETCH_BYTE (pos
.bytepos
- 1) != '\n')
2415 pos
.bufpos
= PT
- minibuffer_scroll_overlap
;
2416 pos
.bytepos
= CHAR_TO_BYTE (pos
.bufpos
);
2419 /* Set startp here explicitly in case that helps avoid an infinite loop
2420 in case the window-scroll-functions functions get errors. */
2421 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2423 /* The old bottom-of-screen position is no longer valid. */
2424 w
->window_end_valid
= Qnil
;
2425 if (! NILP (Vwindow_scroll_functions
))
2427 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2428 make_number (pos
.bufpos
));
2429 pos
.bufpos
= marker_position (w
->start
);
2430 pos
.bytepos
= marker_byte_position (w
->start
);
2432 try_window (window
, pos
.bufpos
);
2434 startp
= marker_position (w
->start
);
2435 startp_byte
= marker_byte_position (w
->start
);
2436 w
->start_at_line_beg
2437 = (startp
== BEGV
|| FETCH_BYTE (startp_byte
- 1) == '\n') ? Qt
: Qnil
;
2440 if ((update_mode_line
2441 /* If window not full width, must redo its mode line
2442 if the window to its side is being redone */
2443 || (!just_this_one
&& !WINDOW_FULL_WIDTH_P (w
))
2444 || INTEGERP (w
->base_line_pos
)
2445 || (!NILP (w
->column_number_displayed
)
2446 && XFASTINT (w
->column_number_displayed
) != current_column ()))
2447 && height
!= XFASTINT (w
->height
))
2449 FRAME_PTR oframe
= selected_frame
;
2450 if (!really_switched_buffer
)
2452 set_buffer_temp (old
);
2453 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2454 really_switched_buffer
= 1;
2457 display_mode_line (w
);
2458 selected_frame
= oframe
;
2460 if (! line_number_displayed
2461 && ! BUFFERP (w
->base_line_pos
))
2463 w
->base_line_pos
= Qnil
;
2464 w
->base_line_number
= Qnil
;
2467 /* When we reach a frame's selected window, redo the frame's menu bar. */
2468 if (update_mode_line
2469 && (FRAME_WINDOW_P (f
)
2471 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2472 FRAME_EXTERNAL_MENU_BAR (f
)
2474 FRAME_MENU_BAR_LINES (f
) > 0
2476 : FRAME_MENU_BAR_LINES (f
) > 0)
2477 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
2478 display_menu_bar (w
);
2481 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2483 int start
, end
, whole
;
2485 /* Calculate the start and end positions for the current window.
2486 At some point, it would be nice to choose between scrollbars
2487 which reflect the whole buffer size, with special markers
2488 indicating narrowing, and scrollbars which reflect only the
2491 Note that minibuffers sometimes aren't displaying any text. */
2492 if (! MINI_WINDOW_P (w
)
2493 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
2496 start
= marker_position (w
->start
) - BEGV
;
2497 /* I don't think this is guaranteed to be right. For the
2498 moment, we'll pretend it is. */
2499 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
2501 if (end
< start
) end
= start
;
2502 if (whole
< (end
- start
)) whole
= end
- start
;
2505 start
= end
= whole
= 0;
2507 /* Indicate what this scroll bar ought to be displaying now. */
2508 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
2510 /* Note that we actually used the scroll bar attached to this window,
2511 so it shouldn't be deleted at the end of redisplay. */
2512 (*redeem_scroll_bar_hook
) (w
);
2515 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
2516 if (really_switched_buffer
)
2517 set_buffer_internal_1 (old
);
2519 set_buffer_temp (old
);
2520 TEMP_SET_PT_BOTH (lpoint
, lpoint_byte
);
2522 unbind_to (count
, Qnil
);
2525 /* Do full redisplay on one window, starting at position `pos'. */
2528 try_window (window
, pos
)
2532 register struct window
*w
= XWINDOW (window
);
2533 register int height
= window_internal_height (w
);
2534 register int vpos
= XFASTINT (w
->top
);
2535 register int last_text_vpos
= vpos
;
2536 FRAME_PTR f
= XFRAME (w
->frame
);
2537 int width
= window_internal_width (w
) - 1;
2538 struct position val
;
2540 /* POS should never be out of range! */
2541 if (pos
< XBUFFER (w
->buffer
)->begv
2542 || pos
> XBUFFER (w
->buffer
)->zv
)
2545 if (XMARKER (w
->start
)->charpos
!= pos
)
2546 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2549 overlay_arrow_seen
= 0;
2550 zv_strings_seen
= 0;
2551 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2552 val
.ovstring_chars_done
= 0;
2553 val
.bytepos
= marker_byte_position (w
->start
);
2554 val
.tab_offset
= pos_tab_offset (w
, pos
, val
.bytepos
);
2556 while (--height
>= 0)
2558 val
= *display_text_line (w
, pos
, val
.bytepos
, vpos
,
2559 val
.hpos
, val
.tab_offset
,
2560 val
.ovstring_chars_done
);
2561 /* The following code is omitted because we maintain tab_offset
2564 tab_offset
+= width
;
2565 if (val
.vpos
) tab_offset
= 0;
2568 if (pos
!= val
.bufpos
)
2571 #ifdef USE_TEXT_PROPERTIES
2572 Lisp_Object invis_prop
;
2573 invis_prop
= Fget_char_property (make_number (val
.bufpos
- 1),
2574 Qinvisible
, window
);
2575 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
2579 /* Next line, unless prev line ended in end of buffer with no cr */
2581 && (FETCH_BYTE (val
.bytepos
- 1) != '\n' || invis
));
2586 /* If last line is continued in middle of character,
2587 include the split character in the text considered on the frame */
2588 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2591 /* If bottom just moved off end of frame, change mode line percentage. */
2592 if (XFASTINT (w
->window_end_pos
) == 0
2594 w
->update_mode_line
= Qt
;
2596 /* Say where last char on frame will be, once redisplay is finished. */
2597 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
2598 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
2599 /* But that is not valid info until redisplay finishes. */
2600 w
->window_end_valid
= Qnil
;
2603 /* Try to redisplay when buffer is modified locally,
2604 computing insert/delete line to preserve text outside
2605 the bounds of the changes.
2606 Return 1 if successful, 0 if if cannot tell what to do,
2607 or -1 to tell caller to find a new window start,
2608 or -2 to tell caller to do normal redisplay with same window start. */
2611 try_window_id (window
)
2615 int opoint
, opoint_byte
;
2616 register struct window
*w
= XWINDOW (window
);
2617 register int height
= window_internal_height (w
);
2618 FRAME_PTR f
= XFRAME (w
->frame
);
2619 int top
= XFASTINT (w
->top
);
2620 int start
= marker_position (w
->start
);
2621 int width
= window_internal_width (w
) - 1;
2622 int hscroll
= XINT (w
->hscroll
);
2623 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
2626 register int i
, tem
;
2627 int last_text_vpos
= 0;
2629 int selective
= (INTEGERP (current_buffer
->selective_display
)
2630 ? XINT (current_buffer
->selective_display
)
2631 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2632 struct position val
, bp
, ep
, xp
, pp
;
2633 int scroll_amount
= 0;
2637 int start_byte
= marker_byte_position (w
->start
);
2639 if (GPT
- BEG
< beg_unchanged
)
2640 beg_unchanged
= GPT
- BEG
;
2641 if (Z
- GPT
< end_unchanged
)
2642 end_unchanged
= Z
- GPT
;
2644 if (beg_unchanged
+ BEG
< start
)
2645 return 0; /* Give up if changes go above top of window */
2647 /* Find position before which nothing is changed. */
2648 bp
= *compute_motion (start
, 0, lmargin
, 0,
2649 min (ZV
, beg_unchanged
+ BEG
), height
,
2650 /* BUG FIX: See the comment of
2651 Fpos_visible_in_window_p (window.c). */
2652 - (1 << (BITS_PER_SHORT
- 1)),
2654 pos_tab_offset (w
, start
, start_byte
),
2656 if (bp
.vpos
>= height
)
2660 /* All changes are beyond the window end, and point is on the screen.
2661 We don't need to change the text at all.
2662 But we need to update window_end_pos to account for
2663 any change in buffer size. */
2664 bp
= *compute_motion (start
, 0, lmargin
, 0,
2666 /* BUG FIX: See the comment of
2667 Fpos_visible_in_window_p() (window.c). */
2668 - (1 << (BITS_PER_SHORT
- 1)),
2670 pos_tab_offset (w
, start
, start_byte
), w
);
2671 XSETFASTINT (w
->window_end_vpos
, height
);
2672 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
2680 /* Find beginning of that frame line. Must display from there. */
2681 bp
= *vmotion (bp
.bufpos
, 0, w
);
2684 pos_byte
= bp
.bytepos
;
2690 /* If about to start displaying at the beginning of a continuation line,
2691 really start with previous frame line, in case it was not
2692 continued when last redisplayed */
2693 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
2695 /* Likewise if we have to worry about selective display. */
2696 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
2698 bp
= *vmotion (bp
.bufpos
, -1, w
);
2701 pos_byte
= bp
.bytepos
;
2703 val
.tab_offset
= bp
.tab_offset
; /* Update tab offset. */
2705 if (bp
.contin
&& bp
.hpos
!= lmargin
)
2707 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
2708 val
.tab_offset
= bp
.tab_offset
+ bp
.prevhpos
- width
;
2710 DEC_BOTH (pos
, pos_byte
);
2715 /* Find first visible newline after which no more is changed. */
2716 opoint
= PT
, opoint_byte
= PT_BYTE
;
2717 TEMP_SET_PT (Z
- max (end_unchanged
, Z
- ZV
));
2718 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2720 while (PT
< ZV
- 1 && indented_beyond_p (PT
, PT_BYTE
, selective
))
2721 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2723 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
2725 /* Compute the cursor position after that newline. */
2726 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
2727 height
, - (1 << (BITS_PER_SHORT
- 1)),
2729 /* We have tab offset in VAL, use it. */
2732 /* If changes reach past the text available on the frame,
2733 just display rest of frame. */
2734 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
2737 stop_vpos
= ep
.vpos
;
2739 /* If no newline before ep, the line ep is on includes some changes
2740 that must be displayed. Make sure we don't stop before it. */
2741 /* Also, if changes reach all the way until ep.bufpos,
2742 it is possible that something was deleted after the
2743 newline before it, so the following line must be redrawn. */
2744 if (stop_vpos
== ep
.vpos
2745 && (ep
.bufpos
== BEGV
2746 || FETCH_BYTE (ep
.bytepos
- 1) != '\n'
2747 || ep
.bufpos
== Z
- end_unchanged
))
2748 stop_vpos
= ep
.vpos
+ 1;
2751 overlay_arrow_seen
= 0;
2752 zv_strings_seen
= 0;
2754 /* If changes do not reach to bottom of window,
2755 figure out how much to scroll the rest of the window */
2756 if (stop_vpos
< height
)
2758 /* Now determine how far up or down the rest of the window has moved */
2759 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2760 Z
- XFASTINT (w
->window_end_pos
),
2761 /* Don't care for VPOS... */
2762 1 << (BITS_PER_SHORT
- 1),
2764 1 << (BITS_PER_SHORT
- 1),
2765 width
, hscroll
, ep
.tab_offset
, w
);
2766 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2768 /* Is everything on frame below the changes whitespace?
2769 If so, no scrolling is really necessary. */
2770 for (i
= ep
.bytepos
; i
< xp
.bytepos
; i
++)
2772 tem
= FETCH_BYTE (i
);
2773 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2776 if (i
== xp
.bytepos
)
2779 XSETFASTINT (w
->window_end_vpos
,
2780 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2782 /* Before doing any scrolling, verify that point will be on frame. */
2783 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.vpos
< height
))
2785 if (PT
<= xp
.bufpos
)
2787 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2788 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2790 /* We have tab offset in EP, use it. */
2795 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2796 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2798 /* We have tab offset in XP, use it. */
2801 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2803 cursor_vpos
= pp
.vpos
+ top
;
2804 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, pp
.hpos
, width
);
2807 if (stop_vpos
- scroll_amount
>= height
2808 || ep
.bufpos
== xp
.bufpos
)
2810 if (scroll_amount
< 0)
2811 stop_vpos
-= scroll_amount
;
2813 /* In this path, we have altered window_end_vpos
2814 and not left it negative.
2815 We must make sure that, in case display is preempted
2816 before the frame changes to reflect what we do here,
2817 further updates will not come to try_window_id
2818 and assume the frame and window_end_vpos match. */
2819 blank_end_of_window
= 1;
2821 else if (!scroll_amount
)
2823 /* Even if we don't need to scroll, we must adjust the
2824 charstarts of subsequent lines (that we won't redisplay)
2825 according to the amount of text inserted or deleted. */
2826 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2827 int adjust
= ep
.bufpos
- oldpos
;
2828 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2830 else if (bp
.bufpos
== Z
- end_unchanged
)
2832 /* If reprinting everything is nearly as fast as scrolling,
2833 don't bother scrolling. Can happen if lines are short. */
2834 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2835 top
+ height
- max (0, scroll_amount
),
2837 > xp
.bufpos
- bp
.bufpos
- 20)
2838 /* Return "try normal display with same window-start."
2839 Too bad we can't prevent further scroll-thinking. */
2841 /* If pure deletion, scroll up as many lines as possible.
2842 In common case of killing a line, this can save the
2843 following line from being overwritten by scrolling
2844 and therefore having to be redrawn. */
2845 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2846 top
+ height
- max (0, scroll_amount
),
2847 scroll_amount
, bp
.bufpos
);
2852 /* scroll_frame_lines did not properly adjust subsequent
2853 lines' charstarts in the case where the text of the
2854 screen line at bp.vpos has changed.
2855 (This can happen in a deletion that ends in mid-line.)
2856 To adjust properly, we need to make things consistent
2858 So do a second adjust to make that happen.
2859 Note that stop_vpos >= ep.vpos, so it is sufficient
2860 to update the charstarts for lines at ep.vpos and below. */
2862 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2863 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2864 ep
.bufpos
- oldstart
);
2867 else if (scroll_amount
)
2869 /* If reprinting everything is nearly as fast as scrolling,
2870 don't bother scrolling. Can happen if lines are short. */
2871 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2872 overestimate of cost of reprinting, since xp.bufpos
2873 would end up below the bottom of the window. */
2874 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2875 top
+ height
- max (0, scroll_amount
),
2877 > xp
.bufpos
- ep
.bufpos
- 20)
2878 /* Return "try normal display with same window-start."
2879 Too bad we can't prevent further scroll-thinking. */
2881 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2882 top
+ height
- max (0, scroll_amount
),
2883 scroll_amount
, ep
.bufpos
);
2884 if (!tem
) stop_vpos
= height
;
2888 /* In any case, do not display past bottom of window */
2889 if (stop_vpos
>= height
)
2895 /* Handle case where pos is before w->start --
2896 can happen if part of line had been clipped and is not clipped now */
2897 if (vpos
== 0 && pos
< marker_position (w
->start
))
2898 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2900 val
.bytepos
= pos_byte
;
2902 /* Redisplay the lines where the text was changed */
2903 last_text_vpos
= vpos
;
2904 /* The following code is omitted because we maintain tab offset in
2907 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2908 /* If we are starting display in mid-character, correct tab_offset
2909 to account for passing the line that that character really starts in. */
2910 if (val
.hpos
< lmargin
)
2911 tab_offset
+= width
;
2914 while (vpos
< stop_vpos
)
2916 val
= *display_text_line (w
, pos
, val
.bytepos
, top
+ vpos
++,
2917 val
.hpos
, val
.tab_offset
,
2918 val
.ovstring_chars_done
);
2919 /* If display_text_line ran a hook and changed some text,
2920 redisplay all the way to bottom of buffer
2921 So that we show the changes. */
2922 if (old_tick
!= MODIFF
)
2924 /* The following code is omitted because we maintain tab offset
2925 in val.tab_offset. */
2927 tab_offset
+= width
;
2928 if (val
.vpos
) tab_offset
= 0;
2930 if (pos
!= val
.bufpos
)
2932 /* Next line, unless prev line ended in end of buffer with no cr */
2933 = vpos
- (val
.vpos
&& FETCH_BYTE (val
.bytepos
- 1) != '\n');
2937 /* There are two cases:
2938 1) we have displayed down to the bottom of the window
2939 2) we have scrolled lines below stop_vpos by scroll_amount */
2943 /* If last line is continued in middle of character,
2944 include the split character in the text considered on the frame */
2945 if (val
.hpos
< lmargin
)
2947 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2948 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2951 /* If scrolling made blank lines at window bottom,
2952 redisplay to fill those lines */
2953 if (scroll_amount
< 0)
2955 /* Don't consider these lines for general-purpose scrolling.
2956 That will save time in the scrolling computation. */
2957 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2960 pos_byte
= xp
.bytepos
;
2962 val
.tab_offset
= xp
.tab_offset
;
2964 { /* Display from next line */
2965 vpos
= height
+ scroll_amount
;
2969 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2971 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2972 val
.tab_offset
= xp
.tab_offset
+ bp
.prevhpos
- width
;
2973 DEC_BOTH (pos
, pos_byte
);
2976 blank_end_of_window
= 1;
2977 /* The following code is omitted because we maintain tab offset
2978 in val.tab_offset. */
2980 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2981 /* If we are starting display in mid-character, correct tab_offset
2982 to account for passing the line that that character starts in. */
2983 if (val
.hpos
< lmargin
)
2984 tab_offset
+= width
;
2986 val
.bytepos
= pos_byte
;
2987 while (vpos
< height
)
2989 val
= *display_text_line (w
, pos
, val
.bytepos
,
2990 top
+ vpos
++, val
.hpos
,
2991 val
.tab_offset
, val
.ovstring_chars_done
);
2992 /* The following code is omitted because we maintain tab
2993 offset in val.tab_offset. */
2995 tab_offset
+= width
;
2996 if (val
.vpos
) tab_offset
= 0;
3001 /* Here is a case where display_text_line sets cursor_vpos wrong.
3002 Make it be fixed up, below. */
3008 /* If bottom just moved off end of frame, change mode line percentage. */
3009 if (XFASTINT (w
->window_end_pos
) == 0
3011 w
->update_mode_line
= Qt
;
3013 /* Attempt to adjust end-of-text positions to new bottom line */
3016 delta
= height
- xp
.vpos
;
3018 || (delta
> 0 && xp
.bufpos
<= ZV
)
3019 || (delta
== 0 && xp
.hpos
))
3021 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
3022 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
3023 XSETFASTINT (w
->window_end_vpos
,
3024 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
3028 w
->window_end_valid
= Qnil
;
3030 /* If point was not in a line that was displayed, find it */
3031 if (cursor_vpos
< 0)
3034 val
= *compute_motion (start
, 0, lmargin
, 0, PT
,
3035 /* Don't care for VPOS... */
3036 1 << (BITS_PER_SHORT
- 1),
3038 1 << (BITS_PER_SHORT
- 1),
3040 pos_tab_offset (w
, start
, start_byte
),
3042 /* Admit failure if point is off frame now */
3043 if (val
.vpos
>= height
)
3045 for (vpos
= 0; vpos
< height
; vpos
++)
3046 cancel_line (vpos
+ top
, f
);
3049 cursor_vpos
= val
.vpos
+ top
;
3050 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, val
.hpos
, width
);
3053 FRAME_CURSOR_X (f
) = cursor_hpos
;
3054 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3058 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
3059 height
, - (1 << (BITS_PER_SHORT
- 1)),
3061 pos_tab_offset (w
, start
, start_byte
),
3063 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
3065 if (XFASTINT (w
->window_end_pos
)
3073 /* Copy LEN glyphs starting address FROM to the rope TO.
3074 But don't actually copy the parts that would come in before S.
3075 Value is TO, advanced past the copied data.
3076 F is the frame we are displaying in. */
3079 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
3081 register GLYPH
*to
; /* Copy to here. */
3082 register GLYPH
*s
; /* Starting point. */
3083 Lisp_Object
*from
; /* Data to copy. */
3085 int face
; /* Face to apply to glyphs which don't specify one. */
3088 register Lisp_Object
*fp
= from
;
3089 /* These cache the results of the last call to compute_glyph_face. */
3091 int last_merged
= 0;
3094 if (! FRAME_TERMCAP_P (f
))
3097 GLYPH glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3099 unsigned int c
= FAST_GLYPH_CHAR (glyph
);
3102 /* For an invalid character code, use space. */
3105 if (FAST_GLYPH_FACE (glyph
) == 0)
3106 /* If GLYPH has no face code, use FACE. */
3108 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
3109 /* If it's same as previous glyph, use same result. */
3110 facecode
= last_merged
;
3113 /* Merge this glyph's face and remember the result. */
3114 last_code
= FAST_GLYPH_FACE (glyph
);
3115 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
3119 *to
= FAST_MAKE_GLYPH (c
, facecode
);
3127 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3134 /* Correct a glyph by replacing its specified user-level face code
3135 with a displayable computed face code. */
3138 fix_glyph (f
, glyph
, cface
)
3144 if (! FRAME_TERMCAP_P (f
))
3146 if (FAST_GLYPH_FACE (glyph
) != 0)
3147 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
3148 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
3154 /* Return the column of position POS / POS_BYTE in window W's buffer.
3155 When used on the character at the beginning of a line,
3156 starting at column 0, this says how much to subtract from
3157 the column position of any character in the line
3158 to get its horizontal position on the screen. */
3161 pos_tab_offset (w
, pos
, pos_byte
)
3163 register int pos
, pos_byte
;
3166 int opoint_byte
= PT_BYTE
;
3168 int width
= window_internal_width (w
) - 1;
3171 return MINI_WINDOW_P (w
) ? -minibuf_prompt_width
: 0;
3173 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3176 TEMP_SET_PT_BOTH (pos
, pos_byte
);
3177 col
= current_column ();
3178 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3183 /* Display one line of window W, starting at char position START in W's buffer.
3184 START_BYTE is the corresponding byte position.
3186 Display starting at horizontal position HPOS, expressed relative to
3187 W's left edge. In situations where the text at START shouldn't
3188 start at the left margin (i.e. when the window is hscrolled, or
3189 we're continuing a line which left off in the midst of a
3190 multi-column character), HPOS should be negative; we throw away
3191 characters up 'til hpos = 0. So, HPOS must take hscrolling into
3194 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
3196 OVSTR_DONE is the number of chars of overlay before/after strings
3197 at this position which have already been processed.
3199 Display on position VPOS on the frame. It is origin 0, relative to
3200 the top of the frame, not W.
3202 Returns a STRUCT POSITION giving character to start next line with
3203 and where to display it, including a zero or negative hpos.
3204 The vpos field is not really a vpos; it is 1 unless the line is continued */
3206 struct position val_display_text_line
;
3208 static struct position
*
3209 display_text_line (w
, start
, start_byte
, vpos
, hpos
, taboffset
, ovstr_done
)
3217 register int pos
= start
;
3218 int pos_byte
= start_byte
;
3221 int pause
, limit_byte
;
3222 register unsigned char *p
;
3224 register GLYPH
*leftmargin
;
3225 register GLYPH
*p1prev
;
3226 register GLYPH
*p1start
;
3227 GLYPH
*p1_wide_column_end
= (GLYPH
*) 0;
3228 int prevpos
, prevpos_byte
;
3230 FRAME_PTR f
= XFRAME (w
->frame
);
3231 int tab_width
= XINT (current_buffer
->tab_width
);
3232 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
3233 int width
= window_internal_width (w
) - 1;
3234 struct position val
;
3235 int lastpos
, lastpos_byte
;
3237 int last_invis_skip
= 0;
3238 Lisp_Object last_invis_prop
;
3239 int hscroll
= XINT (w
->hscroll
);
3240 int truncate
= (hscroll
3241 || (truncate_partial_width_windows
3242 && !WINDOW_FULL_WIDTH_P (w
))
3243 || !NILP (current_buffer
->truncate_lines
));
3245 /* 1 if this buffer has a region to highlight. */
3246 int highlight_region
3247 = (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
)
3248 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
3249 int region_beg
, region_end
;
3251 int selective
= (INTEGERP (current_buffer
->selective_display
)
3252 ? XINT (current_buffer
->selective_display
)
3253 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
3254 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
3255 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
3257 Lisp_Object default_invis_vector
[3];
3258 /* Number of characters of ellipsis to display after an invisible line
3259 if it calls for an ellipsis.
3260 Note that this value can be nonzero regardless of whether
3261 selective display is enabled--you must check that separately. */
3263 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3264 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
3265 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
3266 /* This is the sequence of Lisp objects to display
3267 when there are invisible lines. */
3268 Lisp_Object
*invis_vector_contents
3269 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3270 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
3271 : default_invis_vector
);
3273 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
3274 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp
)))
3275 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
3276 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
3277 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp
)))
3278 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
3280 /* If 1, we must handle multibyte characters. */
3281 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
3282 /* Length of multibyte form of each character. */
3284 /* Glyphs generated should be set this bit mask if text must be
3285 displayed from right to left. */
3286 GLYPH rev_dir_bit
= (NILP (current_buffer
->direction_reversed
)
3287 ? 0 : GLYPH_MASK_REV_DIR
);
3289 /* The next buffer location at which the face should change, due
3290 to overlays or text property changes. */
3291 int next_face_change
;
3293 /* The next location where the `invisible' property changes, or an
3294 overlay starts or ends. */
3297 /* The face we're currently using. */
3298 int current_face
= 0;
3301 XSETFASTINT (default_invis_vector
[2], '.');
3302 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
3304 get_display_line (f
, vpos
, WINDOW_LEFT_MARGIN (w
));
3305 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
3307 /* Show where to highlight the region. */
3308 if (highlight_region
3309 /* Maybe highlight only in selected window. */
3310 && (highlight_nonselected_windows
3311 || w
== XWINDOW (selected_window
)
3312 || (MINI_WINDOW_P (XWINDOW (selected_window
))
3313 && w
== XWINDOW (Vminibuf_scroll_window
))))
3315 region_beg
= marker_position (current_buffer
->mark
);
3316 if (PT
< region_beg
)
3318 region_end
= region_beg
;
3323 w
->region_showing
= Qt
;
3327 region_beg
= region_end
= -1;
3328 w
->region_showing
= Qnil
;
3331 if (MINI_WINDOW_P (w
)
3333 && vpos
== XFASTINT (w
->top
))
3335 if (! NILP (minibuf_prompt
))
3337 int old_width
= minibuf_prompt_width
;
3339 minibuf_prompt_width
3340 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
3341 STRING_BYTES (XSTRING (minibuf_prompt
)),
3342 hpos
+ WINDOW_LEFT_MARGIN (w
),
3343 /* Display a space if we truncate. */
3346 /* Truncate the prompt a little before the
3347 margin, so user input can at least start
3348 on the first line. */
3349 (XFASTINT (w
->width
) > 10
3350 ? XFASTINT (w
->width
) - 4 : -1),
3351 STRING_MULTIBYTE (minibuf_prompt
))
3352 - hpos
- WINDOW_LEFT_MARGIN (w
));
3353 hpos
+= minibuf_prompt_width
;
3354 taboffset
-= minibuf_prompt_width
- old_width
;
3357 minibuf_prompt_width
= 0;
3360 /* If we're hscrolled at all, use compute_motion to skip over any
3361 text off the left edge of the window. compute_motion may know
3362 tricks to do this faster than we can. */
3365 struct position
*left_edge
3366 = compute_motion (pos
, vpos
, hpos
, 0,
3368 width
, hscroll
, taboffset
, w
);
3370 /* Retrieve the buffer position and column provided by
3371 compute_motion. We can't assume that the column will be
3372 zero, because you may have multi-column characters crossing
3375 compute_motion may have moved us past the screen position we
3376 requested, if we hit a multi-column character, or the end of
3377 the line. If so, back up. */
3378 if ((left_edge
->vpos
> vpos
3379 || left_edge
->hpos
> 0)
3380 && left_edge
->bufpos
> pos
)
3382 pos
= left_edge
->bufpos
;
3383 pos_byte
= left_edge
->bytepos
;
3384 DEC_BOTH (pos
, pos_byte
);
3385 hpos
= left_edge
->prevhpos
;
3389 pos
= left_edge
->bufpos
;
3390 pos_byte
= left_edge
->bytepos
;
3391 hpos
= left_edge
->hpos
;
3395 hpos
+= WINDOW_LEFT_MARGIN (w
);
3397 desired_glyphs
->bufp
[vpos
] = start
;
3398 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
3400 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
3401 /* In case we don't ever write anything into it... */
3402 desired_glyphs
->charstarts
[vpos
][WINDOW_LEFT_MARGIN (w
)] = -1;
3403 leftmargin
= desired_glyphs
->glyphs
[vpos
] + WINDOW_LEFT_MARGIN (w
);
3404 endp
= leftmargin
+ width
;
3406 /* Arrange the overlays nicely for our purposes. Usually, we call
3407 display_text_line on only one line at a time, in which case this
3408 can't really hurt too much, or we call it on lines which appear
3409 one after another in the buffer, in which case all calls to
3410 recenter_overlay_lists but the first will be pretty cheap. */
3411 recenter_overlay_lists (current_buffer
, pos
);
3413 /* Loop generating characters.
3414 Stop at end of buffer, before newline,
3415 if reach or pass continuation column,
3416 or at face change. */
3418 limit_byte
= pos_byte
;
3419 next_face_change
= pos
;
3420 next_boundary
= pos
;
3423 prevpos_byte
= pos_byte
;
3425 /* If the window is hscrolled and point is in the invisible part of the
3426 current line beyond the left margin we can record the cursor location
3428 if (hscroll
&& start
<= PT
&& PT
< pos
&& cursor_vpos
< 0)
3431 cursor_hpos
= p1
- leftmargin
;
3440 while (pos
== next_boundary
)
3442 Lisp_Object position
, limit
, prop
, ww
;
3444 /* Display the overlay strings here, unless we're at ZV
3445 and have already displayed the appropriate strings
3446 on an earlier line. */
3447 if (pos
< ZV
|| !zv_strings_seen
++)
3450 unsigned char *ovstr
;
3451 ovlen
= overlay_strings (pos
, w
, &ovstr
);
3455 /* Skip the ones we did in a previous line. */
3456 ovstr
+= ovstr_done
;
3457 ovlen
-= ovstr_done
;
3466 c
= STRING_CHAR_AND_LENGTH (ovstr
, ovlen
, len
);
3467 ovstr
+= len
, ovlen
-= len
, ovstr_done
+= len
;
3468 charset
= CHAR_CHARSET (c
);
3469 cols
= (charset
== CHARSET_COMPOSITION
3470 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3471 : CHARSET_WIDTH (charset
));
3475 c
= *ovstr
++, ovlen
--, ovstr_done
++;
3478 g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3481 if (p1
>= leftmargin
&& p1
< endp
)
3482 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3486 /* If we did all the overlay strings
3487 and we have room for text, clear ovstr_done
3488 just for neatness' sake. */
3489 if (ovlen
== 0 && p1
< endp
)
3494 /* Did we reach point? Record the cursor location. */
3495 if (pos
== PT
&& cursor_vpos
< 0)
3498 cursor_hpos
= p1
- leftmargin
;
3504 XSETFASTINT (position
, pos
);
3505 limit
= Fnext_overlay_change (position
);
3506 #ifdef USE_TEXT_PROPERTIES
3507 /* This is just an estimate to give reasonable
3508 performance; nothing should go wrong if it is too small. */
3509 if (XFASTINT (limit
) > pos
+ 50)
3511 int limitpos
= pos
+ 50;
3512 XSETFASTINT (limit
, limitpos
);
3514 limit
= Fnext_single_property_change (position
, Qinvisible
,
3515 Fcurrent_buffer (), limit
);
3517 next_boundary
= XFASTINT (limit
);
3518 /* if the `invisible' property is set, we can skip to
3519 the next property change. */
3521 prop
= Fget_char_property (position
, Qinvisible
, ww
);
3522 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3524 if (pos
< PT
&& next_boundary
>= PT
)
3527 cursor_hpos
= p1
- leftmargin
;
3529 pos
= next_boundary
;
3530 pos_byte
= CHAR_TO_BYTE (pos
);
3531 last_invis_skip
= pos
;
3532 last_invis_prop
= prop
;
3536 /* Did we reach point? Record the cursor location. */
3537 if (pos
== PT
&& cursor_vpos
< 0)
3540 cursor_hpos
= p1
- leftmargin
;
3543 /* Did we hit the end of the visible region of the buffer?
3547 /* Update charstarts for the end of this line. */
3548 /* Do nothing if off the left edge or at the right edge. */
3549 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
3551 int *p2x
= &charstart
[(p1
< leftmargin
3559 /* Figure out where (if at all) the
3560 redisplay_end_trigger-hook should run. */
3561 if (MARKERP (w
->redisplay_end_trigger
)
3562 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
3563 e_t_h
= marker_position (w
->redisplay_end_trigger
);
3564 else if (INTEGERP (w
->redisplay_end_trigger
))
3565 e_t_h
= XINT (w
->redisplay_end_trigger
);
3569 /* If we've gone past the place to run a hook,
3571 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
3573 Lisp_Object args
[3];
3575 args
[0] = Qredisplay_end_trigger_functions
;
3576 XSETWINDOW (args
[1], w
);
3577 XSETINT (args
[2], e_t_h
);
3579 /* Since we are *trying* to run these functions,
3580 don't try to run them again, even if they get an error. */
3581 w
->redisplay_end_trigger
= Qnil
;
3582 Frun_hook_with_args (3, args
);
3585 /* Notice if it changed the face of this character. */
3586 next_face_change
= pos
;
3590 /* Did we hit a face change? Figure out what face we should
3591 use now. We also hit this the first time through the
3592 loop, to see what face we should start with. */
3593 if (pos
>= next_face_change
3594 && (FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
)))
3596 int limit
= pos
+ 50;
3598 current_face
= compute_char_face (f
, w
, pos
,
3599 region_beg
, region_end
,
3600 &next_face_change
, limit
, 0);
3604 /* Compute the next place we need to stop
3605 and do something special; set PAUSE. */
3609 if (pos
< next_boundary
&& next_boundary
< pause
)
3610 pause
= next_boundary
;
3611 if (pos
< next_face_change
&& next_face_change
< pause
)
3612 pause
= next_face_change
;
3617 /* Wouldn't you hate to read the next line to someone over
3619 if (pos
< PT
&& PT
< pause
)
3621 if (pos
< GPT
&& GPT
< pause
)
3624 /* LIMIT_BYTE is not the same place in the buffer as PAUSE.
3625 It is a limit on valid characters.
3626 We use it to bound STRING_CHAR_AND_LENGTH. */
3627 limit_byte
= ZV_BYTE
;
3628 if (pos
< GPT
&& GPT_BYTE
< limit_byte
)
3629 limit_byte
= GPT_BYTE
;
3632 int temp
= CHAR_TO_BYTE (pos
);
3633 p
= BYTE_POS_ADDR (temp
);
3641 p1_wide_column_end
= (GLYPH
*) 0;
3644 c
= STRING_CHAR_AND_LENGTH (p
, limit_byte
- pos_byte
, len
), p
+= len
;
3647 /* Let a display table override all standard display methods. */
3648 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3650 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
3651 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3652 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3653 current_face
, rev_dir_bit
);
3655 else if (c
>= 040 && c
< 0177)
3657 if (p1
>= leftmargin
)
3658 *p1
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3664 /* Same as p1prev, but after the invis_vector_contents text
3665 (if we have that on this line). */
3666 GLYPH
*p1prev_modified
;
3670 if (last_invis_skip
== pos
3671 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
3675 && indented_beyond_p (pos
+ 1, pos_byte
+ 1, selective
))
3677 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3680 INC_BOTH (pos
, pos_byte
);
3681 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3682 pos
= PT
, pos_byte
= PT_BYTE
;
3683 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3688 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3690 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
3695 cs
= charstart
+ (p1
- p1start
);
3698 p1
+= selective_rlen
;
3699 if (p1
- leftmargin
> width
)
3702 #if 0 /* This needs more work; charstarts needs to record
3703 both whether a position ho;ds an ellipsis character
3704 and what buffer position it corresponds to. */
3705 csend
= charstart
+ (p1
- p1start
);
3708 /* The idea is to use p1prev_modified instead of p1prev
3709 in the loop below over p2x. */
3710 p1prev_modified
= p1
;
3713 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3714 (p1
- p1prev
), current_face
, rev_dir_bit
);
3717 /* Update charstarts for the newline that ended this line. */
3718 /* Do nothing here for a char that's entirely off the left edge
3719 or if it starts at the right edge. */
3720 if (p1
>= leftmargin
&& p1prev
!= endp
)
3722 /* Store the newline's position into charstarts
3723 for the column where the newline starts.
3724 Store -1 for the rest of the glyphs it occupies. */
3725 int *p2x
= &charstart
[(p1prev
< leftmargin
3726 ? leftmargin
: p1prev
)
3728 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3735 /* Draw the face of the newline character as extending all the
3736 way to the end of the frame line. */
3739 if (p1
< leftmargin
)
3742 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3752 if (p1
>= leftmargin
&& p1
< endp
)
3753 *p1
= MAKE_GLYPH (f
, ' ', current_face
) | rev_dir_bit
;
3756 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
3759 else if (c
== Ctl ('M') && selective
== -1)
3761 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3762 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3763 pos
= PT
, pos_byte
= PT_BYTE
;
3764 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3766 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3768 if (selective_rlen
> 0)
3770 p1
+= selective_rlen
;
3771 if (p1
- leftmargin
> width
)
3773 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3774 (p1
- p1prev
), current_face
, rev_dir_bit
);
3777 /* Draw the face of the newline character as extending all the
3778 way to the end of the frame line. */
3781 if (p1
< leftmargin
)
3784 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3788 /* Update charstarts for the ^M that ended this line. */
3789 /* Do nothing here for a char that's entirely off the left edge
3790 or if it starts at the right edge. */
3791 if (p1
>= leftmargin
&& p1prev
!= endp
)
3793 /* Store the newline's position into charstarts
3794 for the column where the newline starts.
3795 Store -1 for the rest of the glyphs it occupies. */
3796 int *p2x
= &charstart
[(p1prev
< leftmargin
3797 ? leftmargin
: p1prev
)
3799 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3807 else if (c
< 0200 && ctl_arrow
)
3809 if (p1
>= leftmargin
)
3811 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3812 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
3813 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3817 if (p1
>= leftmargin
&& p1
< endp
)
3818 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
) | rev_dir_bit
;
3823 /* C is a multibyte character or a character to be displayed
3825 int remaining_bytes
= len
;
3827 if (c
>= 0400 && CHAR_VALID_P (c
, 0))
3829 /* C is a multibyte character. */
3830 int charset
= CHAR_CHARSET (c
);
3831 int columns
= (charset
== CHARSET_COMPOSITION
3832 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3833 : CHARSET_WIDTH (charset
));
3834 GLYPH g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3838 if (p1
>= leftmargin
&& p1
< endp
)
3839 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3842 p1_wide_column_end
= p1
;
3843 remaining_bytes
-= CHARSET_BYTES (charset
);
3846 while (remaining_bytes
> 0)
3848 c
= *(p
- remaining_bytes
--);
3850 if (p1
>= leftmargin
&& p1
< endp
)
3853 (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3854 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
3855 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3859 if (p1
>= leftmargin
&& p1
< endp
)
3860 *p1
= (MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
)
3863 if (p1
>= leftmargin
&& p1
< endp
)
3864 *p1
= (MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
)
3867 if (p1
>= leftmargin
&& p1
< endp
)
3868 *p1
= (MAKE_GLYPH (f
, (7 & c
) + '0', current_face
)
3875 prevpos_byte
= pos_byte
;
3879 /* Update charstarts for the character just output. */
3881 /* Do nothing here for a char that's entirely off the left edge. */
3882 if (p1
>= leftmargin
)
3884 /* Store the char's position into charstarts
3885 for the first glyph occupied by this char.
3886 Store -1 for the rest of the glyphs it occupies. */
3889 int *p2x
= &charstart
[(p1prev
< leftmargin
3890 ? leftmargin
: p1prev
)
3892 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3902 val
.hpos
= - XINT (w
->hscroll
);
3909 lastpos_byte
= pos_byte
;
3911 /* Store 0 in this charstart line for the positions where
3912 there is no character. But do leave what was recorded
3913 for the character that ended the line. */
3914 /* Add 1 in the endtest to compensate for the fact that ENDP was
3915 made from WIDTH, which is 1 less than the window's actual
3917 i
= p1
- p1start
+ 1;
3918 if (p1
< leftmargin
)
3919 i
+= leftmargin
- p1
;
3920 for (; i
< endp
- p1start
+ 1; i
++)
3923 /* Handle continuation in middle of a character */
3924 /* by backing up over it */
3927 /* Don't back up if we never actually displayed any text.
3928 This occurs when the minibuffer prompt takes up the whole line. */
3931 /* Start the next line with that same character whose
3932 character code is C and the length of multi-byte form is
3935 pos_byte
= prevpos_byte
;
3937 if (p1_wide_column_end
< endp
)
3938 /* As ENDP is not in the middle of wide-column character,
3939 we can break the line at ENDP and start from the middle
3940 column in the next line. So, adjust VAL.HPOS to skip
3941 the columns output on this line. */
3942 val
.hpos
+= p1prev
- endp
;
3945 /* We displayed a wide-column character at around ENDP.
3946 Since we can't broke it in the middle, the whole
3947 character should be driven into the next line. */
3948 /* As the result, the actual columns occupied by the
3949 text on this line is less than WIDTH. VAL.TAB_OFFSET
3950 must be adjusted. */
3951 taboffset
= taboffset
+ (p1prev
- endp
);
3952 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3954 GLYPH g
= fix_glyph (f
, truncate
? truncator
: continuer
, 0);
3955 while (p1prev
< endp
)
3958 /* If POINT is at POS, cursor should not on this line. */
3960 lastpos_byte
= pos_byte
;
3966 /* Keep in this line everything up to the continuation column. */
3970 /* Finish deciding which character to start the next line on,
3971 and what hpos to start it at.
3972 Also set `lastpos' to the last position which counts as "on this line"
3973 for cursor-positioning. */
3977 if (FETCH_BYTE (pos_byte
) == '\n')
3979 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3981 /* If stopped due to a newline, start next line after it */
3982 TEMP_SET_PT_BOTH (pos
+ 1, pos_byte
+ 1);
3985 /* Check again for hidden lines, in case the newline occurred exactly
3986 at the right margin. */
3987 while (PT
< ZV
&& selective
> 0
3988 && indented_beyond_p (PT
, PT_BYTE
, selective
))
3989 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
3991 pos
= PT
, pos_byte
= PT_BYTE
;
3992 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3995 /* Stopped due to right margin of window */
3999 int opoint
= PT
, opoint_byte
= PT_BYTE
;
4001 TEMP_SET_PT_BOTH (pos
, pos_byte
);
4002 *p1
++ = fix_glyph (f
, truncator
, 0);
4003 /* Truncating => start next line after next newline,
4004 and point is on this line if it is before the newline,
4005 and skip none of first char of next line */
4007 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
4008 while (PT
< ZV
&& selective
> 0
4009 && indented_beyond_p (PT
, PT_BYTE
, selective
));
4010 pos
= PT
, pos_byte
= PT_BYTE
;
4011 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
4012 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
4014 lastpos
= pos
- (FETCH_BYTE (pos_byte
- 1) == '\n');
4015 lastpos_byte
= CHAR_TO_BYTE (lastpos
);
4020 *p1
++ = fix_glyph (f
, continuer
, 0);
4022 DEC_BOTH (lastpos
, lastpos_byte
);
4023 val
.tab_offset
= taboffset
+ width
;
4030 /* If point is at eol or in invisible text at eol,
4031 record its frame location now. */
4033 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
4036 cursor_hpos
= p1
- leftmargin
;
4039 if (cursor_vpos
== vpos
)
4041 if (cursor_hpos
< 0) cursor_hpos
= 0;
4042 if (cursor_hpos
> width
) cursor_hpos
= width
;
4043 cursor_hpos
+= WINDOW_LEFT_MARGIN (w
);
4044 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
4046 this_line_bufpos
= 0;
4048 /* If this frame's cursor will be in its echo area,
4049 don't record a cursor from the window text,
4050 and turn off the optimization for cursor-motion-only case. */
4051 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
4052 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
4054 FRAME_CURSOR_Y (f
) = cursor_vpos
;
4055 FRAME_CURSOR_X (f
) = cursor_hpos
;
4057 if (w
== XWINDOW (selected_window
))
4059 /* Line is not continued and did not start
4060 in middle of character */
4061 if ((hpos
- WINDOW_LEFT_MARGIN (w
)
4062 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
4065 this_line_bufpos
= start
;
4066 this_line_buffer
= current_buffer
;
4067 this_line_vpos
= cursor_vpos
;
4068 this_line_start_hpos
= hpos
- WINDOW_LEFT_MARGIN (w
);
4069 this_line_endpos
= Z
- lastpos
;
4076 /* If hscroll and line not empty, insert truncation-at-left marker */
4077 if (hscroll
&& lastpos
!= start
)
4079 GLYPH g
= fix_glyph (f
, truncator
, 0);
4081 if (p1
<= leftmargin
)
4082 p1
= leftmargin
+ 1;
4083 else /* MULE: it may be a wide-column character */
4085 p1prev
= leftmargin
+ 1;
4086 while (p1prev
< p1
&& *p1prev
& GLYPH_MASK_PADDING
)
4091 if (!WINDOW_RIGHTMOST_P (w
))
4094 if (p1
< leftmargin
) p1
= leftmargin
;
4095 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
4097 /* Don't draw vertical bars if we're using scroll bars. They're
4098 covered up by the scroll bars, and it's distracting to see
4099 them when the scroll bar windows are flickering around to be
4101 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4104 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4107 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4108 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
4109 ? XINT (DISP_BORDER_GLYPH (dp
))
4112 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
4113 p1
- desired_glyphs
->glyphs
[vpos
]);
4114 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
4116 /* If the start of this line is the overlay arrow-position,
4117 then put the arrow string into the display-line. */
4119 if (MARKERP (Voverlay_arrow_position
)
4120 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
4121 && start
== marker_position (Voverlay_arrow_position
)
4122 && STRINGP (Voverlay_arrow_string
)
4123 && ! overlay_arrow_seen
)
4126 int len
= XSTRING (Voverlay_arrow_string
)->size
;
4132 /* If the arrow string has text props, obey them when displaying. */
4133 for (i
= 0, i_byte
= 0; i
< len
; )
4136 Lisp_Object face
, ilisp
;
4140 if (STRING_MULTIBYTE (Voverlay_arrow_string
))
4141 FETCH_STRING_CHAR_ADVANCE (c
, Voverlay_arrow_string
, i
, i_byte
);
4143 c
= XSTRING (Voverlay_arrow_string
)->data
[i
++];
4145 XSETFASTINT (ilisp
, i
);
4147 if (FRAME_WINDOW_P (f
))
4149 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
4150 newface
= compute_glyph_face_1 (f
, face
, 0);
4151 c
= FAST_MAKE_GLYPH (c
, newface
);
4153 #endif /* HAVE_FACES */
4154 leftmargin
[idx
] = c
;
4157 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
4158 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
4159 if (desired_glyphs
->used
[vpos
] < arrow_end
)
4160 desired_glyphs
->used
[vpos
] = arrow_end
;
4162 overlay_arrow_seen
= 1;
4166 val
.bytepos
= pos_byte
;
4167 val
.ovstring_chars_done
= ovstr_done
;
4168 val_display_text_line
= val
;
4169 return &val_display_text_line
;
4172 /* Redisplay the menu bar in the frame for window W. */
4175 display_menu_bar (w
)
4178 Lisp_Object items
, tail
;
4179 register int vpos
= 0;
4180 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4181 int maxendcol
= FRAME_WIDTH (f
);
4186 if (!NILP (Vwindow_system
))
4190 #ifdef USE_X_TOOLKIT
4193 #endif /* USE_X_TOOLKIT */
4195 get_display_line (f
, vpos
, 0);
4197 items
= FRAME_MENU_BAR_ITEMS (f
);
4198 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4200 Lisp_Object pos
, string
;
4201 string
= XVECTOR (items
)->contents
[i
+ 1];
4205 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], hpos
);
4207 if (hpos
< maxendcol
)
4208 hpos
= display_string (w
, vpos
,
4209 XSTRING (string
)->data
,
4210 STRING_BYTES (XSTRING (string
)),
4211 hpos
, 0, 0, hpos
, maxendcol
,
4212 STRING_MULTIBYTE (string
));
4213 /* Put a space between items. */
4214 if (hpos
< maxendcol
)
4216 int hpos1
= hpos
+ 1;
4217 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
4218 min (hpos1
, maxendcol
), maxendcol
, 0);
4222 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4223 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4225 /* Fill out the line with spaces. */
4226 if (maxendcol
> hpos
)
4227 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
, 0);
4229 /* Clear the rest of the lines allocated to the menu bar. */
4231 while (vpos
< FRAME_MENU_BAR_LINES (f
))
4232 get_display_line (f
, vpos
++, 0);
4235 /* Display the mode line for window w */
4238 display_mode_line (w
)
4241 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
4242 register int left
= WINDOW_LEFT_MARGIN (w
);
4243 register int right
= WINDOW_RIGHT_MARGIN (w
);
4244 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4246 line_number_displayed
= 0;
4247 w
->column_number_displayed
= Qnil
;
4249 get_display_line (f
, vpos
, left
);
4251 /* Temporarily make frame F's kboard the current kboard
4252 so that kboard-local variables in the mode_line_format
4253 will get the right values. */
4254 push_frame_kboard (f
);
4256 display_mode_element (w
, vpos
, left
, 0, right
, right
,
4257 current_buffer
->mode_line_format
);
4259 pop_frame_kboard ();
4261 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4263 /* Put the mode line in inverse video.
4264 Use faces if possible, since that lets us handle
4265 partial-width windows and avoid inverting the scroll bar columns. */
4267 if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
4269 /* For a partial width window, explicitly set face of each glyph. */
4271 unsigned int padding
;
4272 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
4273 for (i
= left
; i
< right
; ++i
)
4275 padding
= ptr
[i
] & GLYPH_MASK_PADDING
;
4276 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1) | padding
;
4282 /* Make the mode line inverse video if the entire line
4283 is made of mode lines.
4284 I.e. if this window is full width,
4285 or if it is the child of a full width window
4286 (which implies that that window is split side-by-side
4287 and the rest of this line is mode lines of the sibling windows). */
4288 if (WINDOW_FULL_WIDTH_P (w
)
4289 || WINDOW_FULL_WIDTH_P (XWINDOW (w
->parent
)))
4290 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4293 /* Contribute ELT to the mode line for window W.
4294 How it translates into text depends on its data type.
4296 VPOS is the position of the mode line being displayed.
4298 HPOS is the position (absolute on frame) where this element's text
4299 should start. The output is truncated automatically at the right
4302 DEPTH is the depth in recursion. It is used to prevent
4303 infinite recursion here.
4305 MINENDCOL is the hpos before which the element may not end.
4306 The element is padded at the right with spaces if nec
4307 to reach this column.
4309 MAXENDCOL is the hpos past which this element may not extend.
4310 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
4311 (This is necessary to make nested padding and truncation work.)
4313 Returns the hpos of the end of the text generated by ELT.
4314 The next element will receive that value as its HPOS arg,
4315 so as to concatenate the elements. */
4318 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
4320 register int vpos
, hpos
;
4323 register int maxendcol
;
4324 register Lisp_Object elt
;
4332 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
4336 /* A string: output it and check for %-constructs within it. */
4337 register unsigned char c
;
4338 register unsigned char *this = XSTRING (elt
)->data
;
4340 while (hpos
< maxendcol
&& *this)
4342 unsigned char *last
= this;
4343 while ((c
= *this++) != '\0' && c
!= '%')
4345 if (this - 1 != last
)
4347 register int lim
= --this - last
+ hpos
;
4348 if (frame_title_ptr
)
4349 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
4351 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
4352 hpos
, min (lim
, maxendcol
),
4353 STRING_MULTIBYTE (elt
));
4357 register int minendcol
;
4358 register int spec_width
= 0;
4360 /* We can't allow -ve args due to the "%-" construct */
4361 /* Argument specifies minwidth but not maxwidth
4362 (maxwidth can be specified by
4363 (<negative-number> . <stuff>) mode-line elements) */
4365 while ((c
= *this++) >= '0' && c
<= '9')
4367 spec_width
= spec_width
* 10 + (c
- '0');
4370 minendcol
= hpos
+ spec_width
;
4371 if (minendcol
> maxendcol
)
4373 spec_width
= maxendcol
- hpos
;
4374 minendcol
= maxendcol
;
4378 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4379 spec_width
, maxendcol
,
4380 Vglobal_mode_string
);
4383 char *spec
= decode_mode_spec (w
, c
, spec_width
,
4385 if (frame_title_ptr
)
4386 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
4388 hpos
= display_string (w
, vpos
, spec
, -1,
4390 minendcol
, maxendcol
, -1);
4398 /* A symbol: process the value of the symbol recursively
4399 as if it appeared here directly. Avoid error if symbol void.
4400 Special case: if value of symbol is a string, output the string
4403 register Lisp_Object tem
;
4404 tem
= Fboundp (elt
);
4407 tem
= Fsymbol_value (elt
);
4408 /* If value is a string, output that string literally:
4409 don't check for % within it. */
4412 if (frame_title_ptr
)
4413 hpos
= store_frame_title (XSTRING (tem
)->data
,
4414 minendcol
, maxendcol
);
4416 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
4417 STRING_BYTES (XSTRING (tem
)),
4418 hpos
, 0, 1, minendcol
, maxendcol
,
4419 STRING_MULTIBYTE (tem
));
4421 /* Give up right away for nil or t. */
4422 else if (!EQ (tem
, elt
))
4423 { elt
= tem
; goto tail_recurse
; }
4430 register Lisp_Object car
, tem
;
4432 /* A cons cell: three distinct cases.
4433 If first element is a string or a cons, process all the elements
4434 and effectively concatenate them.
4435 If first element is a negative number, truncate displaying cdr to
4436 at most that many characters. If positive, pad (with spaces)
4437 to at least that many characters.
4438 If first element is a symbol, process the cadr or caddr recursively
4439 according to whether the symbol's value is non-nil or nil. */
4440 car
= XCONS (elt
)->car
;
4443 tem
= Fboundp (car
);
4444 elt
= XCONS (elt
)->cdr
;
4447 /* elt is now the cdr, and we know it is a cons cell.
4448 Use its car if CAR has a non-nil value. */
4451 tem
= Fsymbol_value (car
);
4453 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
4455 /* Symbol's value is nil (or symbol is unbound)
4456 Get the cddr of the original list
4457 and if possible find the caddr and use that. */
4458 elt
= XCONS (elt
)->cdr
;
4461 else if (!CONSP (elt
))
4463 elt
= XCONS (elt
)->car
;
4466 else if (INTEGERP (car
))
4468 register int lim
= XINT (car
);
4469 elt
= XCONS (elt
)->cdr
;
4471 /* Negative int means reduce maximum width.
4472 DO NOT change MINENDCOL here!
4473 (20 -10 . foo) should truncate foo to 10 col
4474 and then pad to 20. */
4475 maxendcol
= min (maxendcol
, hpos
- lim
);
4478 /* Padding specified. Don't let it be more than
4481 if (lim
> maxendcol
)
4483 /* If that's more padding than already wanted, queue it.
4484 But don't reduce padding already specified even if
4485 that is beyond the current truncation point. */
4486 if (lim
> minendcol
)
4491 else if (STRINGP (car
) || CONSP (car
))
4493 register int limit
= 50;
4494 /* LIMIT is to protect against circular lists. */
4495 while (CONSP (elt
) && --limit
> 0
4496 && hpos
< maxendcol
)
4498 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4501 elt
= XCONS (elt
)->cdr
;
4509 if (frame_title_ptr
)
4510 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
4512 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
4513 minendcol
, maxendcol
, 0);
4517 if (minendcol
> hpos
)
4518 if (frame_title_ptr
)
4519 hpos
= store_frame_title ("", minendcol
, maxendcol
);
4521 hpos
= display_string (w
, vpos
, "", 0, hpos
,
4522 0, 1, minendcol
, maxendcol
, 0);
4526 /* Write a null-terminated, right justified decimal representation of
4527 the positive integer D to BUF using a minimal field width WIDTH. */
4530 pint2str (buf
, width
, d
)
4535 register char *p
= buf
;
4542 *p
++ = d
% 10 + '0';
4545 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
4555 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4556 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4557 type of CODING_SYSTEM. Return updated pointer into BUF. */
4560 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
4561 Lisp_Object coding_system
;
4566 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
4568 val
= coding_system
;
4570 if (NILP (val
)) /* Not yet decided. */
4575 *buf
++ = eol_mnemonic_undecided
;
4576 /* Don't mention EOL conversion if it isn't decided. */
4580 Lisp_Object eolvalue
;
4582 eolvalue
= Fget (coding_system
, Qeol_type
);
4584 while (!NILP (val
) && SYMBOLP (val
))
4586 val
= Fget (val
, Qcoding_system
);
4587 if (NILP (eolvalue
))
4588 eolvalue
= Fget (val
, Qeol_type
);
4592 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
4596 /* The EOL conversion we are using. */
4598 /* The EOL conversion that is normal on this system. */
4600 if (NILP (eolvalue
)) /* Not yet decided. */
4601 eoltype
= eol_mnemonic_undecided
;
4602 else if (VECTORP (eolvalue
)) /* Not yet decided. */
4603 eoltype
= eol_mnemonic_undecided
;
4604 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4605 eoltype
= (XFASTINT (eolvalue
) == 0
4607 : (XFASTINT (eolvalue
) == 1
4608 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
4610 /* Mention the EOL conversion if it is not the usual one. */
4617 /* Return a string for the output of a mode line %-spec for window W,
4618 generated by character C. SPEC_WIDTH is the field width when
4619 padding to the left (%c, %l). The value returned from this
4620 function will later be truncated to width MAXWIDTH. */
4622 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4625 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
4628 register int spec_width
;
4629 register int maxwidth
;
4632 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4633 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
4634 struct buffer
*b
= XBUFFER (w
->buffer
);
4637 if (maxwidth
> FRAME_WIDTH (f
))
4638 maxwidth
= FRAME_WIDTH (f
);
4643 if (!NILP (b
->read_only
))
4645 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4650 /* This differs from %* only for a modified read-only buffer. */
4651 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4653 if (!NILP (b
->read_only
))
4658 /* This differs from %* in ignoring read-only-ness. */
4659 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4671 if (command_loop_level
> 5)
4673 p
= decode_mode_spec_buf
;
4674 for (i
= 0; i
< command_loop_level
; i
++)
4677 return decode_mode_spec_buf
;
4685 if (command_loop_level
> 5)
4687 p
= decode_mode_spec_buf
;
4688 for (i
= 0; i
< command_loop_level
; i
++)
4691 return decode_mode_spec_buf
;
4699 if (maxwidth
< sizeof (lots_of_dashes
))
4700 return lots_of_dashes
;
4703 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
4707 return decode_mode_spec_buf
;
4713 if (maxwidth
>= 3 && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4715 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
4716 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
4717 decode_mode_spec_buf
[maxwidth
] = '\0';
4718 return decode_mode_spec_buf
;
4725 int col
= current_column ();
4726 XSETFASTINT (w
->column_number_displayed
, col
);
4727 pint2str (decode_mode_spec_buf
, spec_width
, col
);
4728 return decode_mode_spec_buf
;
4732 /* %F displays the frame name. */
4733 /* Systems that can only display a single frame at a time should
4734 NOT replace the frame name with the (constant) frame title,
4735 since then they won't be able to tell which frame is that. */
4736 if (FRAME_WINDOW_P (f
) && !NILP (f
->title
))
4737 return (char *) XSTRING (f
->title
)->data
;
4738 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
4739 return (char *) XSTRING (f
->name
)->data
;
4747 else if (STRINGP (obj
) && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4749 bcopy ("...", decode_mode_spec_buf
, 3);
4750 bcopy (XSTRING (obj
)->data
+ STRING_BYTES (XSTRING (obj
)) - maxwidth
+ 3,
4751 decode_mode_spec_buf
+ 3, maxwidth
- 3);
4752 return decode_mode_spec_buf
;
4759 int startpos
= XMARKER (w
->start
)->charpos
;
4760 int startpos_byte
= marker_byte_position (w
->start
);
4761 int line
, linepos
, linepos_byte
, topline
;
4764 int height
= XFASTINT (w
->height
);
4766 /* If we decided that this buffer isn't suitable for line numbers,
4767 don't forget that too fast. */
4768 if (EQ (w
->base_line_pos
, w
->buffer
))
4770 /* But do forget it, if the window shows a different buffer now. */
4771 else if (BUFFERP (w
->base_line_pos
))
4772 w
->base_line_pos
= Qnil
;
4774 /* If the buffer is very big, don't waste time. */
4775 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
4777 w
->base_line_pos
= Qnil
;
4778 w
->base_line_number
= Qnil
;
4782 if (!NILP (w
->base_line_number
)
4783 && !NILP (w
->base_line_pos
)
4784 && XFASTINT (w
->base_line_pos
) <= startpos
)
4786 line
= XFASTINT (w
->base_line_number
);
4787 linepos
= XFASTINT (w
->base_line_pos
);
4788 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
4793 linepos
= BUF_BEGV (b
);
4794 linepos_byte
= BUF_BEGV_BYTE (b
);
4797 /* Count lines from base line to window start position. */
4798 nlines
= display_count_lines (linepos
, linepos_byte
,
4802 topline
= nlines
+ line
;
4804 /* Determine a new base line, if the old one is too close
4805 or too far away, or if we did not have one.
4806 "Too close" means it's plausible a scroll-down would
4808 if (startpos
== BUF_BEGV (b
))
4810 XSETFASTINT (w
->base_line_number
, topline
);
4811 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
4813 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
4814 || linepos
== BUF_BEGV (b
))
4816 int limit
= BUF_BEGV (b
);
4817 int limit_byte
= BUF_BEGV_BYTE (b
);
4819 int distance
= (height
* 2 + 30) * 200;
4821 if (startpos
- distance
> limit
)
4823 limit
= startpos
- distance
;
4824 limit_byte
= CHAR_TO_BYTE (limit
);
4827 nlines
= display_count_lines (startpos
, startpos_byte
,
4829 - (height
* 2 + 30),
4831 /* If we couldn't find the lines we wanted within
4833 give up on line numbers for this window. */
4834 if (position
== limit_byte
&& limit
== startpos
- distance
)
4836 w
->base_line_pos
= w
->buffer
;
4837 w
->base_line_number
= Qnil
;
4841 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
4842 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
4845 /* Now count lines from the start pos to point. */
4846 nlines
= display_count_lines (startpos
, startpos_byte
,
4847 PT_BYTE
, PT
, &junk
);
4849 /* Record that we did display the line number. */
4850 line_number_displayed
= 1;
4852 /* Make the string to show. */
4853 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
4854 return decode_mode_spec_buf
;
4857 char* p
= decode_mode_spec_buf
;
4858 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
4860 return decode_mode_spec_buf
;
4870 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
4876 int pos
= marker_position (w
->start
);
4877 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4879 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
4881 if (pos
<= BUF_BEGV (b
))
4886 else if (pos
<= BUF_BEGV (b
))
4890 if (total
> 1000000)
4891 /* Do it differently for a large value, to avoid overflow. */
4892 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4894 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4895 /* We can't normally display a 3-digit number,
4896 so get us a 2-digit number that is close. */
4899 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4900 return decode_mode_spec_buf
;
4904 /* Display percentage of size above the bottom of the screen. */
4907 int toppos
= marker_position (w
->start
);
4908 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
4909 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4911 if (botpos
>= BUF_ZV (b
))
4913 if (toppos
<= BUF_BEGV (b
))
4920 if (total
> 1000000)
4921 /* Do it differently for a large value, to avoid overflow. */
4922 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4924 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4925 /* We can't normally display a 3-digit number,
4926 so get us a 2-digit number that is close. */
4929 if (toppos
<= BUF_BEGV (b
))
4930 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
4932 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4933 return decode_mode_spec_buf
;
4938 /* status of process */
4939 obj
= Fget_buffer_process (w
->buffer
);
4941 return "no process";
4943 obj
= Fsymbol_name (Fprocess_status (obj
));
4947 case 't': /* indicate TEXT or BINARY */
4948 #ifdef MODE_LINE_BINARY_TEXT
4949 return MODE_LINE_BINARY_TEXT (b
);
4955 /* coding-system (not including end-of-line format) */
4957 /* coding-system (including end-of-line type) */
4959 int eol_flag
= (c
== 'Z');
4960 char *p
= decode_mode_spec_buf
;
4962 if (! FRAME_WINDOW_P (f
))
4964 /* No need to mention EOL here--the terminal never needs
4965 to do EOL conversion. */
4966 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
4967 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
4969 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
4972 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
4974 obj
= Fget_buffer_process (Fcurrent_buffer ());
4977 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
4979 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
4982 #endif /* subprocesses */
4985 return decode_mode_spec_buf
;
4990 return (char *) XSTRING (obj
)->data
;
4995 /* Count up to COUNT lines starting from START / START_BYTE.
4996 But don't go beyond LIMIT_BYTE.
4997 Return the number of lines thus found (always nonnegative).
4999 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
5002 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
5003 int start
, start_byte
, limit_byte
, count
;
5006 register unsigned char *cursor
;
5007 unsigned char *base
;
5009 register int ceiling
;
5010 register unsigned char *ceiling_addr
;
5011 int orig_count
= count
;
5013 /* If we are not in selective display mode,
5014 check only for newlines. */
5015 int selective_display
= (!NILP (current_buffer
->selective_display
)
5016 && !INTEGERP (current_buffer
->selective_display
));
5020 while (start_byte
< limit_byte
)
5022 ceiling
= BUFFER_CEILING_OF (start_byte
);
5023 ceiling
= min (limit_byte
- 1, ceiling
);
5024 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
5025 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
5028 if (selective_display
)
5029 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
5032 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
5035 if (cursor
!= ceiling_addr
)
5039 start_byte
+= cursor
- base
+ 1;
5040 *byte_pos_ptr
= start_byte
;
5044 if (++cursor
== ceiling_addr
)
5050 start_byte
+= cursor
- base
;
5055 while (start_byte
> limit_byte
)
5057 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
5058 ceiling
= max (limit_byte
, ceiling
);
5059 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
5060 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
5063 if (selective_display
)
5064 while (--cursor
!= ceiling_addr
5065 && *cursor
!= '\n' && *cursor
!= 015)
5068 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
5071 if (cursor
!= ceiling_addr
)
5075 start_byte
+= cursor
- base
+ 1;
5076 *byte_pos_ptr
= start_byte
;
5077 /* When scanning backwards, we should
5078 not count the newline posterior to which we stop. */
5079 return - orig_count
- 1;
5085 /* Here we add 1 to compensate for the last decrement
5086 of CURSOR, which took it past the valid range. */
5087 start_byte
+= cursor
- base
+ 1;
5091 *byte_pos_ptr
= limit_byte
;
5094 return - orig_count
+ count
;
5095 return orig_count
- count
;
5099 /* Display STRING on one line of window W, starting at HPOS.
5100 Display at position VPOS. Caller should have done get_display_line.
5101 If VPOS == -1, display it as the current frame's title.
5102 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
5104 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
5106 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
5107 MAXCOL is the last column ok to end at. Truncate here.
5108 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
5109 Both count from the left edge of the frame, as does HPOS.
5110 The right edge of W is an implicit maximum.
5111 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
5113 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
5114 at the place where the current window ends in this line
5115 and not display anything beyond there. Otherwise, only MAXCOL
5116 controls where to stop output.
5118 MULTIBYTE can be 0 meaning do not display multibyte chars,
5119 1 meaning do display them, or -1 meaning obey the current buffer's
5120 value of enable_multibyte_characters.
5122 Returns ending hpos. */
5125 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
5126 obey_window_width
, mincol
, maxcol
, multibyte
)
5128 unsigned char *string
;
5132 int obey_window_width
;
5139 int hscroll
= XINT (w
->hscroll
);
5140 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
5141 register GLYPH
*start
;
5142 register GLYPH
*end
;
5143 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
5144 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
5145 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
5146 int window_width
= XFASTINT (w
->width
);
5148 /* Use the standard display table, not the window's display table.
5149 We don't want the mode line in rot13. */
5150 register struct Lisp_Char_Table
*dp
= 0;
5153 if (multibyte
== -1)
5154 multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
5155 /* Now multibyte is 1 if we should display multibyte characters. */
5157 if (DISP_TABLE_P (Vstandard_display_table
))
5158 dp
= XCHAR_TABLE (Vstandard_display_table
);
5160 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
5163 start
= desired_glyphs
->glyphs
[vpos
];
5165 if (obey_window_width
)
5167 start
+= XFASTINT (w
->left
);
5168 end
= start
+ window_width
- (truncate
!= 0);
5170 if (!WINDOW_RIGHTMOST_P (w
))
5172 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5176 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
5179 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5184 if (! obey_window_width
5185 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
5186 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
5188 /* Store 0 in charstart for these columns. */
5189 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
5190 desired_glyphs
->charstarts
[vpos
][i
] = 0;
5192 if (maxcol
>= 0 && mincol
> maxcol
)
5196 /* We need this value for multibyte characters. */
5197 length
= strlen (string
);
5199 /* We set truncated to 1 if we get stopped by trying to pass END
5200 (that is, trying to pass MAXCOL.) */
5209 c
= STRING_CHAR_AND_LENGTH (string
, length
, len
);
5211 c
= *string
, len
= 1;
5213 string
+= len
, length
-= len
;
5221 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
5223 p1
= copy_part_of_rope (f
, p1
, start
,
5224 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
5225 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
5228 else if (c
>= 040 && c
< 0177)
5238 if (p1
>= start
&& p1
< end
)
5242 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
5244 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
5248 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
5249 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
5250 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
5253 if (p1
>= start
&& p1
< end
)
5259 /* C is a multibyte character, control character or a binary
5261 int remaining_bytes
= len
;
5263 if (c
>= 0400 && CHAR_VALID_P (c
, 0))
5265 /* C is a multibyte character. */
5266 int charset
= CHAR_CHARSET (c
);
5267 int columns
= (charset
== CHARSET_COMPOSITION
5268 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
5269 : CHARSET_WIDTH (charset
));
5271 remaining_bytes
-= CHARSET_BYTES (charset
);
5274 /* Since we can't show the left part of C, fill all
5275 columns with spaces. */
5276 columns
-= start
- p1
;
5285 else if (p1
+ columns
> end
)
5287 /* Since we can't show the right part of C, fill all
5288 columns with TRUNCATE if TRUNCATE is specified. */
5292 *p1
++ = fix_glyph (f
, truncate
, 0);
5293 /* And tell the line is truncated. */
5300 /* We can show the whole glyph of C. */
5303 *p1
++ = c
| GLYPH_MASK_PADDING
;
5307 while (remaining_bytes
> 0)
5309 c
= *(string
- remaining_bytes
--);
5313 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
5314 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
5315 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
5318 if (p1
>= start
&& p1
< end
)
5319 *p1
= (c
>> 6) + '0';
5321 if (p1
>= start
&& p1
< end
)
5322 *p1
= (7 & (c
>> 3)) + '0';
5324 if (p1
>= start
&& p1
< end
)
5325 *p1
= (7 & c
) + '0';
5334 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
5336 else if (mincol
>= 0)
5338 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
5344 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
5346 if (len
> desired_glyphs
->used
[vpos
])
5347 desired_glyphs
->used
[vpos
] = len
;
5348 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
5354 /* This is like a combination of memq and assq.
5355 Return 1 if PROPVAL appears as an element of LIST
5356 or as the car of an element of LIST.
5357 If PROPVAL is a list, compare each element against LIST
5358 in that way, and return 1 if any element of PROPVAL is found in LIST.
5360 This function cannot quit. */
5363 invisible_p (propval
, list
)
5364 register Lisp_Object propval
;
5367 register Lisp_Object tail
, proptail
;
5368 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5370 register Lisp_Object tem
;
5371 tem
= XCONS (tail
)->car
;
5372 if (EQ (propval
, tem
))
5374 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5377 if (CONSP (propval
))
5378 for (proptail
= propval
; CONSP (proptail
);
5379 proptail
= XCONS (proptail
)->cdr
)
5381 Lisp_Object propelt
;
5382 propelt
= XCONS (proptail
)->car
;
5383 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5385 register Lisp_Object tem
;
5386 tem
= XCONS (tail
)->car
;
5387 if (EQ (propelt
, tem
))
5389 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5396 /* Return 1 if PROPVAL appears as the car of an element of LIST
5397 and the cdr of that element is non-nil.
5398 If PROPVAL is a list, check each element of PROPVAL in that way,
5399 and the first time some element is found,
5400 return 1 if the cdr of that element is non-nil.
5402 This function cannot quit. */
5405 invisible_ellipsis_p (propval
, list
)
5406 register Lisp_Object propval
;
5409 register Lisp_Object tail
, proptail
;
5410 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5412 register Lisp_Object tem
;
5413 tem
= XCONS (tail
)->car
;
5414 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5415 return ! NILP (XCONS (tem
)->cdr
);
5417 if (CONSP (propval
))
5418 for (proptail
= propval
; CONSP (proptail
);
5419 proptail
= XCONS (proptail
)->cdr
)
5421 Lisp_Object propelt
;
5422 propelt
= XCONS (proptail
)->car
;
5423 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5425 register Lisp_Object tem
;
5426 tem
= XCONS (tail
)->car
;
5427 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5428 return ! NILP (XCONS (tem
)->cdr
);
5437 staticpro (&Qinhibit_redisplay
);
5438 Qinhibit_redisplay
= intern ("inhibit-redisplay");
5440 staticpro (&Qmenu_bar_update_hook
);
5441 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
5443 staticpro (&Qoverriding_terminal_local_map
);
5444 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
5446 staticpro (&Qoverriding_local_map
);
5447 Qoverriding_local_map
= intern ("overriding-local-map");
5449 staticpro (&Qwindow_scroll_functions
);
5450 Qwindow_scroll_functions
= intern ("window-scroll-functions");
5452 staticpro (&Qredisplay_end_trigger_functions
);
5453 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
5455 staticpro (&Qinhibit_point_motion_hooks
);
5456 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
5458 staticpro (&last_arrow_position
);
5459 staticpro (&last_arrow_string
);
5460 last_arrow_position
= Qnil
;
5461 last_arrow_string
= Qnil
;
5463 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
5464 "Non-nil means don't actually do any redisplay.\n\
5465 This is used for internal purposes.");
5466 Vinhibit_redisplay
= Qnil
;
5468 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
5469 "String (or mode line construct) included (normally) in `mode-line-format'.");
5470 Vglobal_mode_string
= Qnil
;
5472 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
5473 "Marker for where to display an arrow on top of the buffer text.\n\
5474 This must be the beginning of a line in order to work.\n\
5475 See also `overlay-arrow-string'.");
5476 Voverlay_arrow_position
= Qnil
;
5478 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
5479 "String to display as an arrow. See also `overlay-arrow-position'.");
5480 Voverlay_arrow_string
= Qnil
;
5482 DEFVAR_INT ("scroll-step", &scroll_step
,
5483 "*The number of lines to try scrolling a window by when point moves out.\n\
5484 If that fails to bring point back on frame, point is centered instead.\n\
5485 If this is zero, point is always centered after it moves off frame.");
5487 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
5488 "*Scroll up to this many lines, to bring point back on screen.");
5489 scroll_conservatively
= 0;
5491 DEFVAR_INT ("scroll-margin", &scroll_margin
,
5492 "*Number of lines of margin at the top and bottom of a window.\n\
5493 Recenter the window whenever point gets within this many lines\n\
5494 of the top or bottom of the window.");
5497 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
5499 DEFVAR_BOOL ("truncate-partial-width-windows",
5500 &truncate_partial_width_windows
,
5501 "*Non-nil means truncate lines in all windows less than full frame wide.");
5502 truncate_partial_width_windows
= 1;
5504 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
5505 "*Non-nil means use inverse video for the mode line.");
5506 mode_line_inverse_video
= 1;
5508 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
5509 "*Maximum buffer size (in characters) for line number display\n\
5510 If the buffer is bigger than this, the line number does not appear\n\
5511 in the mode line..");
5512 line_number_display_limit
= 1000000;
5514 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
5515 "*Non-nil means highlight region even in nonselected windows.");
5516 highlight_nonselected_windows
= 0;
5518 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
5519 "Non-nil if more than one frame is visible on this display.\n\
5520 Minibuffer-only frames don't count, but iconified frames do.\n\
5521 This variable is not guaranteed to be accurate except while processing\n\
5522 `frame-title-format' and `icon-title-format'.");
5524 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
5525 "Template for displaying the titlebar of visible frames.\n\
5526 \(Assuming the window manager supports this feature.)\n\
5527 This variable has the same structure as `mode-line-format' (which see),\n\
5528 and is used only on frames for which no explicit name has been set\n\
5529 \(see `modify-frame-parameters').");
5530 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
5531 "Template for displaying the titlebar of an iconified frame.\n\
5532 \(Assuming the window manager supports this feature.)\n\
5533 This variable has the same structure as `mode-line-format' (which see),\n\
5534 and is used only on frames for which no explicit name has been set\n\
5535 \(see `modify-frame-parameters').");
5537 = Vframe_title_format
5538 = Fcons (intern ("multiple-frames"),
5539 Fcons (build_string ("%b"),
5540 Fcons (Fcons (build_string (""),
5541 Fcons (intern ("invocation-name"),
5542 Fcons (build_string ("@"),
5543 Fcons (intern ("system-name"),
5547 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
5548 "Maximum number of lines to keep in the message log buffer.\n\
5549 If nil, disable message logging. If t, log messages but don't truncate\n\
5550 the buffer when it becomes large.");
5551 XSETFASTINT (Vmessage_log_max
, 50);
5553 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
5554 "Functions called before redisplay, if window sizes have changed.\n\
5555 The value should be a list of functions that take one argument.\n\
5556 Just before redisplay, for each frame, if any of its windows have changed\n\
5557 size since the last redisplay, or have been split or deleted,\n\
5558 all the functions in the list are called, with the frame as argument.");
5559 Vwindow_size_change_functions
= Qnil
;
5561 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
5562 "List of functions to call before redisplaying a window with scrolling.\n\
5563 Each function is called with two arguments, the window\n\
5564 and its new display-start position. Note that the value of `window-end'\n\
5565 is not valid when these functions are called.");
5566 Vwindow_scroll_functions
= Qnil
;
5568 DEFVAR_INT ("minibuffer-scroll-overlap", &minibuffer_scroll_overlap
,
5569 "*Number of characters of overlap when scrolling a one-line window.\n\
5570 This commonly affects the minibuffer window, hence the name of the variable.");
5571 minibuffer_scroll_overlap
= 20;
5574 /* initialize the window system */
5578 Lisp_Object root_window
;
5579 #ifndef COMPILER_REGISTER_BUG
5581 #endif /* COMPILER_REGISTER_BUG */
5582 struct window
*mini_w
;
5584 this_line_bufpos
= 0;
5586 mini_w
= XWINDOW (minibuf_window
);
5587 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
5589 echo_area_glyphs
= 0;
5590 previous_echo_glyphs
= 0;
5592 if (!noninteractive
)
5594 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
5595 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_MENU_BAR_LINES (f
));
5596 set_window_height (root_window
,
5597 FRAME_HEIGHT (f
) - 1 - FRAME_MENU_BAR_LINES (f
),
5599 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
5600 set_window_height (minibuf_window
, 1, 0);
5602 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
5603 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));