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
))
332 int c
, i
= 0, nbytes
;
333 /* Convert a multibyte string to single-byte
334 for the *Message* buffer. */
337 c
= STRING_CHAR (m
+ i
, len
- i
);
339 /* Truncate the character to its last byte--we can only hope
340 the user is happy with the character he gets,
341 since if it isn't right, there is no way to do it right. */
347 && ! NILP (current_buffer
->enable_multibyte_characters
))
350 unsigned char *msg
= (unsigned char *) m
;
351 /* Convert a single-byte string to multibyte
352 for the *Message* buffer. */
355 int c
= unibyte_char_to_multibyte (msg
[i
++]);
360 insert_1 (m
, len
, 1, 0, 0);
364 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
365 insert_1 ("\n", 1, 1, 0, 0);
367 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
369 this_bol_byte
= PT_BYTE
;
373 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
375 prev_bol_byte
= PT_BYTE
;
377 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
378 this_bol
, this_bol_byte
);
381 del_range_both (prev_bol
, prev_bol_byte
,
382 this_bol
, this_bol_byte
, 0);
388 /* If you change this format, don't forget to also
389 change message_log_check_duplicate. */
390 sprintf (dupstr
, " [%d times]", dup
);
391 duplen
= strlen (dupstr
);
392 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
393 insert_1 (dupstr
, duplen
, 1, 0, 1);
398 if (NATNUMP (Vmessage_log_max
))
400 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
401 -XFASTINT (Vmessage_log_max
) - 1, 0);
402 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
405 BEGV
= XMARKER (oldbegv
)->charpos
;
406 BEGV_BYTE
= marker_byte_position (oldbegv
);
415 ZV
= XMARKER (oldzv
)->charpos
;
416 ZV_BYTE
= marker_byte_position (oldzv
);
420 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
422 Fgoto_char (oldpoint
);
425 free_marker (oldpoint
);
426 free_marker (oldbegv
);
429 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
430 set_buffer_internal (oldbuf
);
432 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
433 message_log_need_newline
= !nlflag
;
434 Vdeactivate_mark
= old_deactivate_mark
;
438 /* We are at the end of the buffer after just having inserted a newline.
439 (Note: We depend on the fact we won't be crossing the gap.)
440 Check to see if the most recent message looks a lot like the previous one.
441 Return 0 if different, 1 if the new one should just replace it, or a
442 value N > 1 if we should also append " [N times]". */
445 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
446 int prev_bol
, this_bol
;
447 int prev_bol_byte
, this_bol_byte
;
450 int len
= Z_BYTE
- 1 - this_bol_byte
;
452 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
453 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
455 for (i
= 0; i
< len
; i
++)
457 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
466 if (*p1
++ == ' ' && *p1
++ == '[')
469 while (*p1
>= '0' && *p1
<= '9')
470 n
= n
* 10 + *p1
++ - '0';
471 if (strncmp (p1
, " times]\n", 8) == 0)
477 /* Display an echo area message M with a specified length of LEN chars.
478 The string may include null characters. If M is 0, clear out any
479 existing message, and let the minibuffer text show through.
481 The buffer M must continue to exist until after the echo area
482 gets cleared or some other message gets displayed there.
484 Do not pass text that is stored in a Lisp string.
485 Do not pass text in a buffer that was alloca'd. */
488 message2 (m
, len
, multibyte
)
493 /* First flush out any partial line written with print. */
494 message_log_maybe_newline ();
496 message_dolog (m
, len
, 1, multibyte
);
497 message2_nolog (m
, len
, multibyte
);
501 /* The non-logging counterpart of message2. */
504 message2_nolog (m
, len
, multibyte
)
508 message_enable_multibyte
= multibyte
;
512 if (noninteractive_need_newline
)
514 noninteractive_need_newline
= 0;
516 fwrite (m
, len
, 1, stderr
);
517 if (cursor_in_echo_area
== 0)
518 fprintf (stderr
, "\n");
521 /* A null message buffer means that the frame hasn't really been
522 initialized yet. Error messages get reported properly by
523 cmd_error, so this must be just an informative message; toss it. */
524 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
526 Lisp_Object mini_window
;
529 /* Get the frame containing the minibuffer
530 that the selected frame is using. */
531 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
532 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
534 FRAME_SAMPLE_VISIBILITY (f
);
535 if (FRAME_VISIBLE_P (selected_frame
)
536 && ! FRAME_VISIBLE_P (f
))
537 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
541 echo_area_glyphs
= m
;
542 echo_area_glyphs_length
= len
;
544 if (minibuffer_auto_raise
)
545 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
548 echo_area_glyphs
= previous_echo_glyphs
= 0;
550 do_pending_window_change ();
551 echo_area_display ();
552 update_frame (f
, 1, 1);
553 do_pending_window_change ();
554 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
555 (*frame_up_to_date_hook
) (f
);
559 /* Display in echo area the null-terminated ASCII-only string M.
560 If M is 0, clear out any existing message,
561 and let the minibuffer text show through.
563 The string M must continue to exist until after the echo area
564 gets cleared or some other message gets displayed there.
566 Do not pass text that is stored in a Lisp string.
567 Do not pass text in a buffer that was alloca'd. */
573 message2 (m
, (m
? strlen (m
) : 0), 0);
580 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
583 /* Display a message M which contains a single %s
584 which gets replaced with STRING. */
587 message_with_string (m
, string
, log
)
596 if (noninteractive_need_newline
)
598 noninteractive_need_newline
= 0;
599 fprintf (stderr
, m
, XSTRING (string
)->data
);
600 if (cursor_in_echo_area
== 0)
601 fprintf (stderr
, "\n");
605 else if (INTERACTIVE
)
607 /* The frame whose minibuffer we're going to display the message on.
608 It may be larger than the selected frame, so we need
609 to use its buffer, not the selected frame's buffer. */
610 Lisp_Object mini_window
;
613 /* Get the frame containing the minibuffer
614 that the selected frame is using. */
615 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
616 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
618 /* A null message buffer means that the frame hasn't really been
619 initialized yet. Error messages get reported properly by
620 cmd_error, so this must be just an informative message; toss it. */
621 if (FRAME_MESSAGE_BUF (f
))
625 a
[0] = (char *) XSTRING (string
)->data
;
627 len
= doprnt (FRAME_MESSAGE_BUF (f
),
628 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
631 message2 (FRAME_MESSAGE_BUF (f
), len
,
632 STRING_MULTIBYTE (string
));
634 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
635 STRING_MULTIBYTE (string
));
637 /* Print should start at the beginning of the message
639 message_buf_print
= 0;
644 /* Truncate what will be displayed in the echo area
645 the next time we display it--but don't redisplay it now. */
648 truncate_echo_area (len
)
651 /* A null message buffer means that the frame hasn't really been
652 initialized yet. Error messages get reported properly by
653 cmd_error, so this must be just an informative message; toss it. */
654 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
655 echo_area_glyphs_length
= len
;
658 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
659 zero if being used by message. */
660 int message_buf_print
;
662 /* Dump an informative message to the minibuf. If M is 0, clear out
663 any existing message, and let the minibuffer text show through. */
667 message (m
, a1
, a2
, a3
)
669 EMACS_INT a1
, a2
, a3
;
675 if (noninteractive_need_newline
)
677 noninteractive_need_newline
= 0;
678 fprintf (stderr
, m
, a1
, a2
, a3
);
679 if (cursor_in_echo_area
== 0)
680 fprintf (stderr
, "\n");
684 else if (INTERACTIVE
)
686 /* The frame whose minibuffer we're going to display the message on.
687 It may be larger than the selected frame, so we need
688 to use its buffer, not the selected frame's buffer. */
689 Lisp_Object mini_window
;
692 /* Get the frame containing the minibuffer
693 that the selected frame is using. */
694 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
695 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
697 /* A null message buffer means that the frame hasn't really been
698 initialized yet. Error messages get reported properly by
699 cmd_error, so this must be just an informative message; toss it. */
700 if (FRAME_MESSAGE_BUF (f
))
711 len
= doprnt (FRAME_MESSAGE_BUF (f
),
712 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
714 len
= doprnt (FRAME_MESSAGE_BUF (f
),
715 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
717 #endif /* NO_ARG_ARRAY */
719 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
724 /* Print should start at the beginning of the message
726 message_buf_print
= 0;
731 /* The non-logging version of message. */
733 message_nolog (m
, a1
, a2
, a3
)
735 EMACS_INT a1
, a2
, a3
;
737 Lisp_Object old_log_max
;
738 old_log_max
= Vmessage_log_max
;
739 Vmessage_log_max
= Qnil
;
740 message (m
, a1
, a2
, a3
);
741 Vmessage_log_max
= old_log_max
;
747 message2 (echo_area_glyphs
, echo_area_glyphs_length
,
748 ! NILP (current_buffer
->enable_multibyte_characters
));
756 Lisp_Object mini_window
;
758 /* Choose the minibuffer window for this display.
759 It is the minibuffer window used by the selected frame. */
760 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
761 /* This is the frame that window is in. */
762 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
764 if (! FRAME_VISIBLE_P (f
))
769 redraw_garbaged_frames ();
773 if (echo_area_glyphs
|| minibuf_level
== 0)
777 echo_area_window
= mini_window
;
779 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
780 get_display_line (f
, vpos
, 0);
782 /* Make sure the columns that overlap a left-hand scroll bar
784 for (i
= 0; i
< FRAME_LEFT_SCROLL_BAR_WIDTH (f
); i
++)
785 f
->desired_glyphs
->glyphs
[vpos
][i
] = SPACEGLYPH
;
787 display_string (XWINDOW (mini_window
), vpos
,
788 echo_area_glyphs
? echo_area_glyphs
: "",
789 echo_area_glyphs
? echo_area_glyphs_length
: -1,
790 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
792 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
793 message_enable_multibyte
);
795 #if 0 /* This just gets in the way. update_frame does the job. */
796 /* If desired cursor location is on this line, put it at end of text */
797 if (cursor_in_echo_area
)
798 FRAME_CURSOR_Y (f
) = vpos
;
799 if (FRAME_CURSOR_Y (f
) == vpos
)
800 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
803 /* Fill the rest of the minibuffer window with blank lines. */
808 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
810 get_display_line (f
, i
, 0);
811 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
812 hpos, because it is good to clear whatever is behind the
813 scroll bar. This does not affect the scroll bar itself. */
814 display_string (XWINDOW (mini_window
), i
,
817 0, FRAME_WIDTH (f
) + FRAME_SCROLL_BAR_WIDTH (f
),
822 else if (!EQ (mini_window
, selected_window
))
823 windows_or_buffers_changed
++;
825 if (EQ (mini_window
, selected_window
))
826 this_line_bufpos
= 0;
828 previous_echo_glyphs
= echo_area_glyphs
;
831 /* Update frame titles. */
833 #ifdef HAVE_WINDOW_SYSTEM
834 static char frame_title_buf
[512];
835 static char *frame_title_ptr
;
838 store_frame_title (str
, mincol
, maxcol
)
843 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
844 maxcol
= sizeof (frame_title_buf
);
845 limit
= &frame_title_buf
[maxcol
];
846 while (*str
!= '\0' && frame_title_ptr
< limit
)
847 *frame_title_ptr
++ = *str
++;
848 while (frame_title_ptr
< &frame_title_buf
[mincol
])
849 *frame_title_ptr
++ = ' ';
850 return frame_title_ptr
- frame_title_buf
;
854 x_consider_frame_title (frame
)
860 FRAME_PTR f
= XFRAME (frame
);
862 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
865 /* Do we have more than one visible frame on this X display? */
869 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
871 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
873 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
874 && !FRAME_MINIBUF_ONLY_P (tf
)
875 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
879 multiple_frames
= CONSP (tail
);
882 obuf
= current_buffer
;
883 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
884 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
885 frame_title_ptr
= frame_title_buf
;
886 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
887 0, sizeof (frame_title_buf
), fmt
);
889 set_buffer_internal (obuf
);
890 /* Set the name only if it's changed. This avoids consing
891 in the common case where it hasn't. (If it turns out that we've
892 already wasted too much time by walking through the list with
893 display_mode_element, then we might need to optimize at a higher
895 if (! STRINGP (f
->name
) || STRING_BYTES (XSTRING (f
->name
)) != len
896 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
897 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
900 #define frame_title_ptr ((char *)0)
901 #define store_frame_title(str, mincol, maxcol) 0
904 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
905 This can call eval. */
910 register struct window
*w
= XWINDOW (selected_window
);
912 struct gcpro gcpro1
, gcpro2
;
914 all_windows
= (update_mode_lines
|| buffer_shared
> 1
915 || windows_or_buffers_changed
);
917 /* Update all frame titles based on their buffer names, etc.
918 We do this before the menu bars so that the buffer-menu
919 will show the up-to-date frame titles.
921 This used to be done after the menu bars, for a reason that
922 was stated as follows but which I do not understand:
923 "We do this after the menu bars so that the frame will first
924 create its menu bar using the name `emacs' if no other name
925 has yet been specified."
926 I think that is no longer a concern. */
927 #ifdef HAVE_WINDOW_SYSTEM
928 if (windows_or_buffers_changed
|| update_mode_lines
)
930 Lisp_Object tail
, frame
;
932 FOR_EACH_FRAME (tail
, frame
)
933 if (FRAME_VISIBLE_P (XFRAME (frame
))
934 || FRAME_ICONIFIED_P (XFRAME (frame
)))
935 x_consider_frame_title (frame
);
939 /* Update the menu bar item lists, if appropriate.
940 This has to be done before any actual redisplay
941 or generation of display lines. */
944 Lisp_Object tail
, frame
;
945 int count
= specpdl_ptr
- specpdl
;
947 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
949 FOR_EACH_FRAME (tail
, frame
)
951 /* If a window on this frame changed size,
952 report that to the user and clear the size-change flag. */
953 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
955 Lisp_Object functions
;
956 /* Clear flag first in case we get error below. */
957 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
958 functions
= Vwindow_size_change_functions
;
959 GCPRO2 (tail
, functions
);
960 while (CONSP (functions
))
962 call1 (XCONS (functions
)->car
, frame
);
963 functions
= XCONS (functions
)->cdr
;
968 update_menu_bar (XFRAME (frame
), 0);
972 unbind_to (count
, Qnil
);
975 update_menu_bar (selected_frame
, 1);
977 /* Motif needs this. See comment in xmenu.c.
978 Turn it off when pending_menu_activation is not defined. */
980 pending_menu_activation
= 0;
984 /* Do a frame update, taking possible shortcuts into account.
985 This is the main external entry point for redisplay.
987 If the last redisplay displayed an echo area message and that
988 message is no longer requested, we clear the echo area
989 or bring back the minibuffer if that is in use.
991 Do not call eval from within this function.
992 Calls to eval after the call to echo_area_display would confuse
993 the display_line mechanism and would cause a crash.
994 Calls to eval before that point will work most of the time,
995 but can still lose, because this function
996 can be called from signal handlers; with alarms set up;
997 or with synchronous processes running.
999 See Fcall_process; if you called it from here, it could be
1000 entered recursively. */
1002 static int do_verify_charstarts
;
1004 /* Counter is used to clear the face cache
1005 no more than once ever 1000 redisplays. */
1006 static int clear_face_cache_count
;
1008 /* Record the previous terminal frame we displayed. */
1009 static FRAME_PTR previous_terminal_frame
;
1014 redisplay_internal (0);
1017 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
1018 is not in response to any user action; therefore, we should
1019 preserve the echo area. (Actually, our caller does that job.)
1020 Perhaps in the future avoid recentering windows
1021 if it is not necessary; currently that causes some problems. */
1024 redisplay_internal (preserve_echo_area
)
1025 int preserve_echo_area
;
1027 register struct window
*w
= XWINDOW (selected_window
);
1029 int must_finish
= 0;
1031 register int tlbufpos
, tlendpos
;
1032 struct position pos
;
1033 int number_of_visible_frames
;
1038 #ifdef USE_X_TOOLKIT
1039 if (popup_activated ())
1043 if (! NILP (Vinhibit_redisplay
))
1048 if (! FRAME_WINDOW_P (selected_frame
)
1049 && previous_terminal_frame
!= selected_frame
)
1051 /* Since frames on an ASCII terminal share the same display area,
1052 displaying a different frame means redisplay the whole thing. */
1053 windows_or_buffers_changed
++;
1054 SET_FRAME_GARBAGED (selected_frame
);
1055 XSETFRAME (Vterminal_frame
, selected_frame
);
1057 previous_terminal_frame
= selected_frame
;
1059 /* Set the visible flags for all frames.
1060 Do this before checking for resized or garbaged frames; they want
1061 to know if their frames are visible.
1062 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
1064 Lisp_Object tail
, frame
;
1066 number_of_visible_frames
= 0;
1068 FOR_EACH_FRAME (tail
, frame
)
1070 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1072 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1073 number_of_visible_frames
++;
1075 /* Clear out all the display lines in which we will generate the
1076 glyphs to display. */
1077 init_desired_glyphs (XFRAME (frame
));
1081 /* Notice any pending interrupt request to change frame size. */
1082 do_pending_window_change ();
1086 redraw_garbaged_frames ();
1090 prepare_menu_bars ();
1092 if (windows_or_buffers_changed
)
1093 update_mode_lines
++;
1095 /* Detect case that we need to write or remove a star in the mode line. */
1096 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
1098 w
->update_mode_line
= Qt
;
1099 if (buffer_shared
> 1)
1100 update_mode_lines
++;
1103 /* If %c is in use, update it if needed. */
1104 if (!NILP (w
->column_number_displayed
)
1105 /* This alternative quickly identifies a common case
1106 where no change is needed. */
1107 && !(PT
== XFASTINT (w
->last_point
)
1108 && XFASTINT (w
->last_modified
) >= MODIFF
1109 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1110 && XFASTINT (w
->column_number_displayed
) != current_column ())
1111 w
->update_mode_line
= Qt
;
1113 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
1115 all_windows
= update_mode_lines
|| buffer_shared
> 1;
1117 /* If specs for an arrow have changed, do thorough redisplay
1118 to ensure we remove any arrow that should no longer exist. */
1119 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
1120 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
1123 /* Normally the message* functions will have already displayed and
1124 updated the echo area, but the frame may have been trashed, or
1125 the update may have been preempted, so display the echo area
1127 if (echo_area_glyphs
|| previous_echo_glyphs
)
1129 echo_area_display ();
1133 /* If showing region, and mark has changed, must redisplay whole window. */
1134 if (((!NILP (Vtransient_mark_mode
)
1135 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1136 != !NILP (w
->region_showing
))
1137 || (!NILP (w
->region_showing
)
1138 && !EQ (w
->region_showing
,
1139 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
1140 this_line_bufpos
= -1;
1142 tlbufpos
= this_line_bufpos
;
1143 tlendpos
= this_line_endpos
;
1144 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
1145 && !current_buffer
->clip_changed
1146 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
1147 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
1148 /* Make sure recorded data applies to current buffer, etc */
1149 && this_line_buffer
== current_buffer
1150 && current_buffer
== XBUFFER (w
->buffer
)
1151 && NILP (w
->force_start
)
1152 /* Point must be on the line that we have info recorded about */
1154 && PT
<= Z
- tlendpos
1155 /* All text outside that line, including its final newline,
1156 must be unchanged */
1157 && ((XFASTINT (w
->last_modified
) >= MODIFF
1158 && (XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
))
1159 || (beg_unchanged
>= tlbufpos
- 1
1161 /* If selective display, can't optimize
1162 if the changes start at the beginning of the line. */
1163 && ((INTEGERP (current_buffer
->selective_display
)
1164 && XINT (current_buffer
->selective_display
) > 0
1165 ? (beg_unchanged
>= tlbufpos
1168 && end_unchanged
>= tlendpos
1169 && Z
- GPT
>= tlendpos
)))
1171 int tlbufpos_byte
= CHAR_TO_BYTE (tlbufpos
);
1172 if (tlbufpos
> BEGV
&& FETCH_BYTE (tlbufpos_byte
- 1) != '\n'
1174 || FETCH_BYTE (tlbufpos_byte
) == '\n'))
1175 /* Former continuation line has disappeared by becoming empty */
1177 else if (XFASTINT (w
->last_modified
) < MODIFF
1178 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
1179 || MINI_WINDOW_P (w
))
1181 /* We have to handle the case of continuation around a
1182 wide-column character (See the comment in indent.c around
1185 For instance, in the following case:
1187 -------- Insert --------
1188 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1189 J_I_ ==> J_I_ `^^' are cursors.
1193 As we have to redraw the line above, we should goto cancel. */
1195 struct position val
;
1197 int opoint
= PT
, opoint_byte
= PT_BYTE
;
1199 scan_newline (tlbufpos
, tlbufpos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
1201 val
= *compute_motion (PT
, 0,
1202 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1205 1 << (BITS_PER_SHORT
- 1),
1206 1 << (BITS_PER_SHORT
- 1),
1207 window_internal_width (w
) - 1,
1208 XINT (w
->hscroll
), 0, w
);
1209 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
1210 if (val
.hpos
!= this_line_start_hpos
)
1214 overlay_arrow_seen
= 0;
1215 zv_strings_seen
= 0;
1216 display_text_line (w
, tlbufpos
, tlbufpos_byte
,
1217 this_line_vpos
, this_line_start_hpos
,
1218 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
), 0);
1219 /* If line contains point, is not continued,
1220 and ends at same distance from eob as before, we win */
1221 if (cursor_vpos
>= 0 && this_line_bufpos
1222 && this_line_endpos
== tlendpos
)
1224 /* If this is not the window's last line,
1225 we must adjust the charstarts of the lines below. */
1226 if (this_line_vpos
+ 1
1227 < XFASTINT (w
->top
) + window_internal_height (w
))
1229 int left
= WINDOW_LEFT_MARGIN (w
);
1230 int *charstart_next_line
1231 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
1234 if (Z
- tlendpos
== ZV
)
1235 /* This line ends at end of (accessible part of) buffer.
1236 There is no newline to count. */
1237 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
1239 /* This line ends in a newline.
1240 Must take account of the newline and the rest of the
1241 text that follows. */
1242 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
1244 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
1247 if (!WINDOW_FULL_WIDTH_P (w
))
1248 preserve_other_columns (w
);
1254 else if (PT
== XFASTINT (w
->last_point
)
1255 /* Make sure the cursor was last displayed
1256 in this window. Otherwise we have to reposition it. */
1257 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
1258 && (XINT (w
->top
) + XINT (w
->height
)
1259 > FRAME_CURSOR_Y (selected_frame
)))
1263 do_pending_window_change ();
1268 /* If highlighting the region, or if the cursor is in the echo area,
1269 then we can't just move the cursor. */
1270 else if (! (!NILP (Vtransient_mark_mode
)
1271 && !NILP (current_buffer
->mark_active
))
1272 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1273 || highlight_nonselected_windows
)
1274 && NILP (w
->region_showing
)
1275 && !cursor_in_echo_area
)
1277 pos
= *compute_motion (tlbufpos
, 0,
1278 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1280 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
1281 window_internal_width (w
) - 1,
1283 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
),
1287 int width
= window_internal_width (w
) - 1;
1288 FRAME_CURSOR_X (selected_frame
)
1289 = WINDOW_LEFT_MARGIN (w
) + minmax (0, pos
.hpos
, width
);
1290 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1297 /* Text changed drastically or point moved off of line */
1298 cancel_line (this_line_vpos
, selected_frame
);
1301 this_line_bufpos
= 0;
1302 all_windows
|= buffer_shared
> 1;
1304 clear_face_cache_count
++;
1308 Lisp_Object tail
, frame
;
1311 /* Clear the face cache, only when we do a full redisplay
1312 and not too often either. */
1313 if (clear_face_cache_count
> 1000)
1315 clear_face_cache ();
1316 clear_face_cache_count
= 0;
1320 /* Recompute # windows showing selected buffer.
1321 This will be incremented each time such a window is displayed. */
1324 FOR_EACH_FRAME (tail
, frame
)
1326 FRAME_PTR f
= XFRAME (frame
);
1327 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
1330 /* Mark all the scroll bars to be removed; we'll redeem the ones
1331 we want when we redisplay their windows. */
1332 if (condemn_scroll_bars_hook
)
1333 (*condemn_scroll_bars_hook
) (f
);
1335 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1336 redisplay_windows (FRAME_ROOT_WINDOW (f
), preserve_echo_area
);
1338 /* Any scroll bars which redisplay_windows should have nuked
1339 should now go away. */
1340 if (judge_scroll_bars_hook
)
1341 (*judge_scroll_bars_hook
) (f
);
1345 else if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1347 redisplay_window (selected_window
, 1, preserve_echo_area
);
1348 if (!WINDOW_FULL_WIDTH_P (w
))
1349 preserve_other_columns (w
);
1353 /* Prevent various kinds of signals during display update.
1354 stdio is not robust about handling signals,
1355 which can cause an apparent I/O error. */
1356 if (interrupt_input
)
1366 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1370 if (!FRAMEP (XCONS (tail
)->car
))
1373 f
= XFRAME (XCONS (tail
)->car
);
1375 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
1376 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1378 pause
|= update_frame (f
, 0, 0);
1381 mark_window_display_accurate (f
->root_window
, 1);
1382 if (frame_up_to_date_hook
!= 0)
1383 (*frame_up_to_date_hook
) (f
);
1390 if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1391 pause
= update_frame (selected_frame
, 0, 0);
1395 /* We may have called echo_area_display at the top of this
1396 function. If the echo area is on another frame, that may
1397 have put text on a frame other than the selected one, so the
1398 above call to update_frame would not have caught it. Catch
1401 Lisp_Object mini_window
;
1402 FRAME_PTR mini_frame
;
1404 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1405 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1407 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
1408 pause
|= update_frame (mini_frame
, 0, 0);
1412 /* If frame does not match, prevent doing single-line-update next time.
1413 Also, don't forget to check every line to update the arrow. */
1416 this_line_bufpos
= 0;
1417 if (!NILP (last_arrow_position
))
1419 last_arrow_position
= Qt
;
1420 last_arrow_string
= Qt
;
1422 /* If we pause after scrolling, some lines in current_frame
1423 may be null, so preserve_other_columns won't be able to
1424 preserve all the vertical-bar separators. So, avoid using it
1426 if (!WINDOW_FULL_WIDTH_P (w
))
1427 update_mode_lines
= 1;
1430 /* Now text on frame agrees with windows, so
1431 put info into the windows for partial redisplay to follow */
1435 register struct buffer
*b
= XBUFFER (w
->buffer
);
1437 blank_end_of_window
= 0;
1438 unchanged_modified
= BUF_MODIFF (b
);
1439 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
1440 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1441 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1443 /* Record the last place cursor was displayed in this window.
1444 But not if cursor is in the echo area, because in that case
1445 FRAME_CURSOR_X and FRAME_CURSOR_Y are in the echo area. */
1446 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (selected_frame
)
1447 && EQ (FRAME_MINIBUF_WINDOW (selected_frame
), minibuf_window
)))
1449 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1450 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1451 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1454 /* Make last_point invalid, since we don't really know
1455 where the cursor would be if it were not in the echo area. */
1456 XSETINT (w
->last_point
, -1);
1459 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1462 b
->clip_changed
= 0;
1463 w
->update_mode_line
= Qnil
;
1464 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1465 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
1467 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1470 /* Record if we are showing a region, so can make sure to
1471 update it fully at next redisplay. */
1472 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1473 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1474 || highlight_nonselected_windows
)
1475 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1476 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1479 w
->window_end_valid
= w
->buffer
;
1480 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1481 last_arrow_string
= Voverlay_arrow_string
;
1482 if (do_verify_charstarts
)
1483 verify_charstarts (w
);
1484 if (frame_up_to_date_hook
!= 0)
1485 (*frame_up_to_date_hook
) (selected_frame
);
1487 update_mode_lines
= 0;
1488 windows_or_buffers_changed
= 0;
1491 /* Start SIGIO interrupts coming again.
1492 Having them off during the code above
1493 makes it less likely one will discard output,
1494 but not impossible, since there might be stuff
1495 in the system buffer here.
1496 But it is much hairier to try to do anything about that. */
1498 if (interrupt_input
)
1502 /* If something has become visible now which was not before,
1503 redisplay again, so that we get them. */
1506 Lisp_Object tail
, frame
;
1509 FOR_EACH_FRAME (tail
, frame
)
1511 int this_is_visible
= 0;
1513 if (XFRAME (frame
)->visible
)
1514 this_is_visible
= 1;
1515 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1516 if (XFRAME (frame
)->visible
)
1517 this_is_visible
= 1;
1519 if (this_is_visible
)
1523 if (new_count
!= number_of_visible_frames
)
1524 windows_or_buffers_changed
++;
1527 /* Change frame size now if a change is pending. */
1528 do_pending_window_change ();
1530 /* If we just did a pending size change, or have additional
1531 visible frames, redisplay again. */
1532 if (windows_or_buffers_changed
&& !pause
)
1536 /* Redisplay, but leave alone any recent echo area message
1537 unless another message has been requested in its place.
1539 This is useful in situations where you need to redisplay but no
1540 user action has occurred, making it inappropriate for the message
1541 area to be cleared. See tracking_off and
1542 wait_reading_process_input for examples of these situations. */
1545 redisplay_preserve_echo_area ()
1547 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1549 echo_area_glyphs
= previous_echo_glyphs
;
1550 redisplay_internal (1);
1551 echo_area_glyphs
= 0;
1554 redisplay_internal (1);
1558 mark_window_display_accurate (window
, flag
)
1562 register struct window
*w
;
1564 for (;!NILP (window
); window
= w
->next
)
1566 if (!WINDOWP (window
)) abort ();
1567 w
= XWINDOW (window
);
1569 if (!NILP (w
->buffer
))
1571 XSETFASTINT (w
->last_modified
,
1572 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1573 XSETFASTINT (w
->last_overlay_modified
,
1574 !flag
? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)));
1576 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1579 /* Record if we are showing a region, so can make sure to
1580 update it fully at next redisplay. */
1581 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1582 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1583 || highlight_nonselected_windows
)
1584 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1585 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1589 w
->window_end_valid
= w
->buffer
;
1590 w
->update_mode_line
= Qnil
;
1591 if (!NILP (w
->buffer
) && flag
)
1592 XBUFFER (w
->buffer
)->clip_changed
= 0;
1594 if (!NILP (w
->vchild
))
1595 mark_window_display_accurate (w
->vchild
, flag
);
1596 if (!NILP (w
->hchild
))
1597 mark_window_display_accurate (w
->hchild
, flag
);
1602 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1603 last_arrow_string
= Voverlay_arrow_string
;
1607 /* t is unequal to any useful value of Voverlay_arrow_... */
1608 last_arrow_position
= Qt
;
1609 last_arrow_string
= Qt
;
1613 /* Update the menu bar item list for frame F.
1614 This has to be done before we start to fill in any display lines,
1615 because it can call eval.
1617 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1620 update_menu_bar (f
, save_match_data
)
1622 int save_match_data
;
1624 struct buffer
*old
= current_buffer
;
1626 register struct window
*w
;
1628 window
= FRAME_SELECTED_WINDOW (f
);
1629 w
= XWINDOW (window
);
1631 if (update_mode_lines
)
1632 w
->update_mode_line
= Qt
;
1634 if (FRAME_WINDOW_P (f
)
1636 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1637 FRAME_EXTERNAL_MENU_BAR (f
)
1639 FRAME_MENU_BAR_LINES (f
) > 0
1641 : FRAME_MENU_BAR_LINES (f
) > 0)
1643 /* If the user has switched buffers or windows, we need to
1644 recompute to reflect the new bindings. But we'll
1645 recompute when update_mode_lines is set too; that means
1646 that people can use force-mode-line-update to request
1647 that the menu bar be recomputed. The adverse effect on
1648 the rest of the redisplay algorithm is about the same as
1649 windows_or_buffers_changed anyway. */
1650 if (windows_or_buffers_changed
1651 || !NILP (w
->update_mode_line
)
1652 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1653 < BUF_MODIFF (XBUFFER (w
->buffer
)))
1654 != !NILP (w
->last_had_star
))
1655 || ((!NILP (Vtransient_mark_mode
)
1656 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1657 != !NILP (w
->region_showing
)))
1659 struct buffer
*prev
= current_buffer
;
1660 int count
= specpdl_ptr
- specpdl
;
1662 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1663 if (save_match_data
)
1664 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1665 if (NILP (Voverriding_local_map_menu_flag
))
1667 specbind (Qoverriding_terminal_local_map
, Qnil
);
1668 specbind (Qoverriding_local_map
, Qnil
);
1671 /* Run the Lucid hook. */
1672 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1673 /* If it has changed current-menubar from previous value,
1674 really recompute the menubar from the value. */
1675 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1676 call0 (Qrecompute_lucid_menubar
);
1677 safe_run_hooks (Qmenu_bar_update_hook
);
1678 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1679 /* Redisplay the menu bar in case we changed it. */
1680 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1681 if (FRAME_WINDOW_P (f
))
1682 set_frame_menubar (f
, 0, 0);
1684 /* On a terminal screen, the menu bar is an ordinary screen
1685 line, and this makes it get updated. */
1686 w
->update_mode_line
= Qt
;
1687 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1688 /* In the non-toolkit version, the menu bar is an ordinary screen
1689 line, and this makes it get updated. */
1690 w
->update_mode_line
= Qt
;
1691 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1693 unbind_to (count
, Qnil
);
1694 set_buffer_internal_1 (prev
);
1701 /* Redisplay WINDOW and its subwindows and siblings. */
1704 redisplay_windows (window
, preserve_echo_area
)
1706 int preserve_echo_area
;
1708 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1709 redisplay_window (window
, 0, preserve_echo_area
);
1712 /* Return value in display table DP (Lisp_Char_Table *) for character
1713 C. Since a display table doesn't have any parent, we don't have to
1714 follow parent. Do not call this function directly but use the
1715 macro DISP_CHAR_VECTOR. */
1717 disp_char_vector (dp
, c
)
1718 struct Lisp_Char_Table
*dp
;
1724 if (SINGLE_BYTE_CHAR_P (c
)) return (dp
->contents
[c
]);
1726 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
1727 if (code
[0] != CHARSET_COMPOSITION
)
1729 if (code
[1] < 32) code
[1] = -1;
1730 else if (code
[2] < 32) code
[2] = -1;
1732 /* Here, the possible range of CODE[0] (== charset ID) is
1733 128..MAX_CHARSET. Since the top level char table contains data
1734 for multibyte characters after 256th element, we must increment
1735 CODE[0] by 128 to get a correct index. */
1737 code
[3] = -1; /* anchor */
1739 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
1741 val
= dp
->contents
[code
[i
]];
1742 if (!SUB_CHAR_TABLE_P (val
))
1743 return (NILP (val
) ? dp
->defalt
: val
);
1745 /* Here, VAL is a sub char table. We return the default value of it. */
1746 return (dp
->defalt
);
1749 /* Redisplay window WINDOW and its subwindows. */
1752 redisplay_window (window
, just_this_one
, preserve_echo_area
)
1754 int just_this_one
, preserve_echo_area
;
1756 register struct window
*w
= XWINDOW (window
);
1757 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1760 int lpoint_byte
= PT_BYTE
;
1761 struct buffer
*old
= current_buffer
;
1762 register int width
= window_internal_width (w
) - 1;
1763 register int startp
, startp_byte
;
1764 register int hscroll
= XINT (w
->hscroll
);
1765 struct position pos
;
1767 int opoint_byte
= PT_BYTE
;
1769 int update_mode_line
;
1770 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1771 int really_switched_buffer
= 0;
1772 int count
= specpdl_ptr
- specpdl
;
1774 if (Z
== Z_BYTE
&& lpoint
!= lpoint_byte
)
1776 if (lpoint_byte
< lpoint
)
1779 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1781 /* If this is a combination window, do its children; that's all. */
1783 if (!NILP (w
->vchild
))
1785 redisplay_windows (w
->vchild
, preserve_echo_area
);
1788 if (!NILP (w
->hchild
))
1790 redisplay_windows (w
->hchild
, preserve_echo_area
);
1793 if (NILP (w
->buffer
))
1796 specbind (Qinhibit_point_motion_hooks
, Qt
);
1798 height
= window_internal_height (w
);
1799 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1800 if (XBUFFER (w
->buffer
)->clip_changed
)
1801 update_mode_line
= 1;
1803 if (MINI_WINDOW_P (w
))
1805 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1806 /* We've already displayed the echo area glyphs in this window. */
1807 goto finish_scroll_bars
;
1808 else if (w
!= XWINDOW (minibuf_window
))
1810 /* This is a minibuffer, but it's not the currently active one,
1812 int vpos
= XFASTINT (w
->top
);
1815 for (i
= 0; i
< height
; i
++)
1817 get_display_line (f
, vpos
+ i
, 0);
1818 display_string (w
, vpos
+ i
, "", 0,
1819 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
1823 goto finish_scroll_bars
;
1827 /* Otherwise set up data on this window; select its buffer and point value */
1829 if (update_mode_line
)
1830 /* Really select the buffer, for the sake of buffer-local variables. */
1832 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1833 really_switched_buffer
= 1;
1836 set_buffer_temp (XBUFFER (w
->buffer
));
1839 opoint_byte
= PT_BYTE
;
1841 if (Z
== Z_BYTE
&& opoint
!= opoint_byte
)
1843 if (opoint_byte
< opoint
)
1846 /* If %c is in mode line, update it if needed. */
1847 if (!NILP (w
->column_number_displayed
)
1848 /* This alternative quickly identifies a common case
1849 where no change is needed. */
1850 && !(PT
== XFASTINT (w
->last_point
)
1851 && XFASTINT (w
->last_modified
) >= MODIFF
1852 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1853 && XFASTINT (w
->column_number_displayed
) != current_column ())
1854 update_mode_line
= 1;
1856 /* Count number of windows showing the selected buffer.
1857 An indirect buffer counts as its base buffer. */
1861 struct buffer
*current_base
, *window_base
;
1862 current_base
= current_buffer
;
1863 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1864 if (current_base
->base_buffer
)
1865 current_base
= current_base
->base_buffer
;
1866 if (window_base
->base_buffer
)
1867 window_base
= window_base
->base_buffer
;
1868 if (current_base
== window_base
)
1872 /* POINT refers normally to the selected window.
1873 For any other window, set up appropriate value. */
1875 if (!EQ (window
, selected_window
))
1877 int new_pt
= XMARKER (w
->pointm
)->charpos
;
1878 int new_pt_byte
= marker_byte_position (w
->pointm
);
1882 new_pt_byte
= BEGV_BYTE
;
1883 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
1885 else if (new_pt
> (ZV
- 1))
1888 new_pt_byte
= ZV_BYTE
;
1889 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
1891 /* We don't use SET_PT so that the point-motion hooks don't run. */
1892 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
1895 /* If any of the character widths specified in the display table
1896 have changed, invalidate the width run cache. It's true that this
1897 may be a bit late to catch such changes, but the rest of
1898 redisplay goes (non-fatally) haywire when the display table is
1899 changed, so why should we worry about doing any better? */
1900 if (current_buffer
->width_run_cache
)
1902 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1904 if (! disptab_matches_widthtab (disptab
,
1905 XVECTOR (current_buffer
->width_table
)))
1907 invalidate_region_cache (current_buffer
,
1908 current_buffer
->width_run_cache
,
1910 recompute_width_table (current_buffer
, disptab
);
1914 /* If window-start is screwed up, choose a new one. */
1915 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1918 startp
= marker_position (w
->start
);
1919 startp_byte
= marker_byte_position (w
->start
);
1921 /* If someone specified a new starting point but did not insist,
1922 check whether it can be used. */
1923 if (!NILP (w
->optional_new_start
)
1924 && startp
>= BEGV
&& startp
<= ZV
)
1926 w
->optional_new_start
= Qnil
;
1927 /* Check whether this start pos is usable given where point is. */
1929 pos
= *compute_motion (startp
, 0,
1930 (((EQ (window
, minibuf_window
)
1932 ? minibuf_prompt_width
: 0)
1933 + (hscroll
? 1 - hscroll
: 0)),
1936 /* BUG FIX: See the comment of
1937 Fpos_visible_in_window_p (window.c). */
1938 - (1 << (BITS_PER_SHORT
- 1)),
1940 pos_tab_offset (w
, startp
, startp_byte
), w
);
1941 /* If PT does fit on the screen, we will use this start pos,
1942 so do so by setting force_start. */
1943 if (pos
.bufpos
== PT
)
1944 w
->force_start
= Qt
;
1947 /* Handle case where place to start displaying has been specified,
1948 unless the specified location is outside the accessible range. */
1949 if (!NILP (w
->force_start
))
1951 w
->force_start
= Qnil
;
1952 /* Forget any recorded base line for line number display. */
1953 w
->base_line_number
= Qnil
;
1954 /* The old bottom-of-screen position is no longer valid. */
1955 w
->window_end_valid
= Qnil
;
1956 /* Redisplay the mode line. Select the buffer properly for that.
1957 Also, run the hook window-scroll-functions
1958 because we have scrolled. */
1959 /* Note, we do this after clearing force_start because
1960 if there's an error, it is better to forget about force_start
1961 than to get into an infinite loop calling the hook functions
1962 and having them get more errors. */
1963 if (!update_mode_line
1964 || ! NILP (Vwindow_scroll_functions
))
1966 Lisp_Object temp
[3];
1968 if (!really_switched_buffer
)
1970 set_buffer_temp (old
);
1971 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1973 really_switched_buffer
= 1;
1974 update_mode_line
= 1;
1975 w
->update_mode_line
= Qt
;
1976 if (! NILP (Vwindow_scroll_functions
))
1978 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1979 make_number (startp
));
1980 startp
= marker_position (w
->start
);
1981 startp_byte
= marker_byte_position (w
->start
);
1984 XSETFASTINT (w
->last_modified
, 0);
1985 XSETFASTINT (w
->last_overlay_modified
, 0);
1986 if (startp
< BEGV
) startp
= BEGV
, startp_byte
= BEGV_BYTE
;
1987 if (startp
> ZV
) startp
= ZV
, startp
= ZV_BYTE
;
1988 try_window (window
, startp
);
1989 if (cursor_vpos
< 0)
1991 /* If point does not appear, move point so it does appear */
1992 pos
= *compute_motion (startp
, 0,
1993 (((EQ (window
, minibuf_window
)
1995 ? minibuf_prompt_width
: 0)
1996 + (hscroll
? 1 - hscroll
: 0)),
1999 - (1 << (BITS_PER_SHORT
- 1)),
2001 pos_tab_offset (w
, startp
, startp_byte
),
2003 TEMP_SET_PT_BOTH (pos
.bufpos
, pos
.bytepos
);
2004 if (w
!= XWINDOW (selected_window
))
2005 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
2008 if (current_buffer
== old
)
2011 lpoint_byte
= PT_BYTE
;
2013 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2014 + minmax (0, pos
.hpos
, width
));
2015 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2017 /* If we are highlighting the region,
2018 then we just changed the region, so redisplay to show it. */
2019 if (!NILP (Vtransient_mark_mode
)
2020 && !NILP (current_buffer
->mark_active
))
2022 cancel_my_columns (XWINDOW (window
));
2023 try_window (window
, startp
);
2029 /* Handle case where text has not changed, only point,
2030 and it has not moved off the frame. */
2032 /* This code is not used for minibuffer for the sake of
2033 the case of redisplaying to replace an echo area message;
2034 since in that case the minibuffer contents per se are usually unchanged.
2035 This code is of no real use in the minibuffer since
2036 the handling of this_line_bufpos, etc.,
2037 in redisplay handles the same cases. */
2039 if (XFASTINT (w
->last_modified
) >= MODIFF
2040 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
2041 && PT
>= startp
&& !current_buffer
->clip_changed
2042 && (just_this_one
|| WINDOW_FULL_WIDTH_P (w
))
2043 /* If force-mode-line-update was called, really redisplay;
2044 that's how redisplay is forced after e.g. changing
2045 buffer-invisibility-spec. */
2046 && NILP (w
->update_mode_line
)
2047 /* Can't use this case if highlighting a region. */
2048 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
2049 && NILP (w
->region_showing
)
2050 /* If end pos is out of date, scroll bar and percentage will be wrong */
2051 && INTEGERP (w
->window_end_vpos
)
2052 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
2053 && !EQ (window
, minibuf_window
)
2054 && (!MARKERP (Voverlay_arrow_position
)
2055 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
2057 /* All positions in this clause are relative to the window edge. */
2059 int this_scroll_margin
= scroll_margin
;
2060 int last_point_y
= XFASTINT (w
->last_point_y
) - XINT (w
->top
);
2061 int last_point_x
= (XFASTINT (w
->last_point_x
) - WINDOW_LEFT_MARGIN (w
));
2063 /* Find where PT is located now on the frame. */
2064 /* Check just_this_one as a way of verifying that the
2065 window edges have not changed. */
2066 if (PT
== XFASTINT (w
->last_point
) && just_this_one
2067 /* If CURSOR_IN_ECHO_AREA, last_point_x and last_point_y
2068 refer to the echo area and are not related to this window. */
2069 && ! cursor_in_echo_area
)
2071 pos
.hpos
= last_point_x
;
2072 pos
.vpos
= last_point_y
;
2075 else if (PT
> XFASTINT (w
->last_point
)
2076 && ! cursor_in_echo_area
2077 && XFASTINT (w
->last_point
) > startp
&& just_this_one
2078 /* We can't use this if point is in the left margin of a
2079 hscrolled window, because w->last_point_x has been
2080 clipped to the window edges. */
2081 && !(last_point_x
<= 0 && hscroll
))
2083 int last_point
= XFASTINT (w
->last_point
);
2084 int last_point_byte
= CHAR_TO_BYTE (last_point
);
2085 int tab_offset
= (pos_tab_offset (w
, last_point
, last_point_byte
)
2086 - (last_point_x
+ hscroll
- !! hscroll
));
2088 pos
= *compute_motion (last_point
, last_point_y
, last_point_x
, 0,
2090 /* BUG FIX: See the comment of
2091 Fpos_visible_in_window_p (window.c). */
2092 - (1 << (BITS_PER_SHORT
- 1)),
2099 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
2101 /* BUG FIX: See the comment of
2102 Fpos_visible_in_window_p (window.c). */
2103 - (1 << (BITS_PER_SHORT
- 1)),
2105 pos_tab_offset (w
, startp
, startp_byte
),
2109 /* Don't use a scroll margin that is negative or too large. */
2110 if (this_scroll_margin
< 0)
2111 this_scroll_margin
= 0;
2113 if (XINT (w
->height
) < 4 * scroll_margin
)
2114 this_scroll_margin
= XINT (w
->height
) / 4;
2116 /* If point fits on the screen, and not within the scroll margin,
2118 if (pos
.vpos
< height
- this_scroll_margin
2119 && (pos
.vpos
>= this_scroll_margin
|| startp
== BEGV
))
2121 /* Ok, point is still on frame */
2122 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
2124 /* These variables are supposed to be origin 1 */
2125 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2126 + minmax (0, pos
.hpos
, width
));
2127 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2129 /* This doesn't do the trick, because if a window to the right of
2130 this one must be redisplayed, this does nothing because there
2131 is nothing in DesiredFrame yet, and then the other window is
2132 redisplayed, making likes that are empty in this window's columns.
2133 if (WINDOW_FULL_WIDTH_P (w))
2134 preserve_my_columns (w);
2136 if (current_buffer
->clip_changed
2137 && ! NILP (Vwindow_scroll_functions
))
2138 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2139 make_number (marker_position (w
->start
)));
2143 /* Don't bother trying redisplay with same start;
2144 we already know it will lose. */
2146 /* If current starting point was originally the beginning of a line
2147 but no longer is, find a new starting point. */
2148 else if (!NILP (w
->start_at_line_beg
)
2150 || FETCH_BYTE (startp_byte
- 1) == '\n'))
2154 else if (just_this_one
&& !MINI_WINDOW_P (w
)
2156 && XFASTINT (w
->last_modified
)
2157 /* or else vmotion on first line won't work. */
2158 && ! NILP (w
->start_at_line_beg
)
2159 && ! EQ (w
->window_end_valid
, Qnil
)
2160 && do_id
&& !current_buffer
->clip_changed
2161 && !blank_end_of_window
2162 && WINDOW_FULL_WIDTH_P (w
)
2163 /* Can't use this case if highlighting a region. */
2164 && !(!NILP (Vtransient_mark_mode
)
2165 && !NILP (current_buffer
->mark_active
))
2166 /* Don't use try_window_id if newline
2167 doesn't display as the end of a line. */
2168 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
2169 && NILP (w
->region_showing
)
2170 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
2171 && EQ (last_arrow_string
, Voverlay_arrow_string
)
2172 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
2175 /* tem > 0 means success. tem == -1 means choose new start.
2176 tem == -2 means try again with same start,
2177 and nothing but whitespace follows the changed stuff.
2178 tem == 0 means try again with same start. */
2182 else if (startp
>= BEGV
&& startp
<= ZV
2184 /* Avoid starting at end of buffer. */
2185 #if 0 /* This change causes trouble for M-! finger & RET.
2186 It will have to be considered later. */
2187 || ! EQ (window
, selected_window
)
2188 /* Don't do the recentering if redisplay
2189 is not for no user action. */
2190 || preserve_echo_area
2193 || (XFASTINT (w
->last_modified
) >= MODIFF
2194 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
2196 /* Try to redisplay starting at same place as before */
2197 /* If point has not moved off frame, accept the results */
2198 try_window (window
, startp
);
2199 if (cursor_vpos
>= 0)
2201 if (!just_this_one
|| current_buffer
->clip_changed
2202 || beg_unchanged
< startp
)
2203 /* Forget any recorded base line for line number display. */
2204 w
->base_line_number
= Qnil
;
2206 if (current_buffer
->clip_changed
2207 && ! NILP (Vwindow_scroll_functions
))
2208 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2209 make_number (marker_position (w
->start
)));
2214 cancel_my_columns (w
);
2217 XSETFASTINT (w
->last_modified
, 0);
2218 XSETFASTINT (w
->last_overlay_modified
, 0);
2219 /* Redisplay the mode line. Select the buffer properly for that. */
2220 if (!update_mode_line
)
2222 if (!really_switched_buffer
)
2224 set_buffer_temp (old
);
2225 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2227 update_mode_line
= 1;
2228 w
->update_mode_line
= Qt
;
2231 /* Try to scroll by specified few lines */
2233 if ((scroll_conservatively
|| scroll_step
)
2234 && !current_buffer
->clip_changed
2235 && startp
>= BEGV
&& startp
<= ZV
)
2237 int this_scroll_margin
= scroll_margin
;
2238 int scroll_margin_pos
, scroll_margin_bytepos
;
2239 int scroll_max
= scroll_step
;
2242 if (scroll_conservatively
)
2243 scroll_max
= scroll_conservatively
;
2245 /* Don't use a scroll margin that is negative or too large. */
2246 if (this_scroll_margin
< 0)
2247 this_scroll_margin
= 0;
2249 if (XINT (w
->height
) < 4 * this_scroll_margin
)
2250 this_scroll_margin
= XINT (w
->height
) / 4;
2252 ltemp
= Fwindow_end (window
, Qt
);
2253 scroll_margin_pos
= XINT (ltemp
);
2255 if (this_scroll_margin
)
2257 pos
= *vmotion (scroll_margin_pos
, -this_scroll_margin
, w
);
2258 scroll_margin_pos
= pos
.bufpos
;
2259 scroll_margin_bytepos
= pos
.bytepos
;
2262 scroll_margin_bytepos
= CHAR_TO_BYTE (scroll_margin_pos
);
2264 if (PT
>= scroll_margin_pos
)
2266 struct position pos
;
2267 pos
= *compute_motion (scroll_margin_pos
, 0, 0, 0,
2268 PT
, XFASTINT (w
->height
), 0,
2269 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2270 pos_tab_offset (w
, scroll_margin_pos
,
2271 scroll_margin_bytepos
),
2273 if (pos
.vpos
>= scroll_max
)
2276 pos
= *vmotion (startp
,
2277 scroll_conservatively
? pos
.vpos
+ 1 : scroll_step
,
2280 /* The old bottom-of-screen position is no longer valid. */
2281 w
->window_end_valid
= Qnil
;
2282 if (! NILP (Vwindow_scroll_functions
))
2284 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2285 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2286 make_number (pos
.bufpos
));
2287 pos
.bufpos
= marker_position (w
->start
);
2289 try_window (window
, pos
.bufpos
);
2290 if (cursor_vpos
>= 0)
2292 if (!just_this_one
|| current_buffer
->clip_changed
2293 || beg_unchanged
< startp
)
2294 /* Forget any recorded base line for line number display. */
2295 w
->base_line_number
= Qnil
;
2299 cancel_my_columns (w
);
2302 scroll_margin_pos
= startp
;
2303 if (this_scroll_margin
)
2305 pos
= *vmotion (scroll_margin_pos
, this_scroll_margin
, w
);
2306 scroll_margin_pos
= pos
.bufpos
;
2308 if (PT
< scroll_margin_pos
)
2310 struct position pos
;
2311 pos
= *compute_motion (PT
, 0, 0, 0,
2312 scroll_margin_pos
, XFASTINT (w
->height
), 0,
2313 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2314 pos_tab_offset (w
, PT
, PT_BYTE
),
2316 if (pos
.vpos
> scroll_max
)
2319 pos
= *vmotion (startp
,
2320 scroll_conservatively
? -pos
.vpos
: - scroll_step
,
2323 /* The old bottom-of-screen position is no longer valid. */
2324 w
->window_end_valid
= Qnil
;
2325 if (! NILP (Vwindow_scroll_functions
))
2327 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2328 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2329 make_number (pos
.bufpos
));
2330 pos
.bufpos
= marker_position (w
->start
);
2332 try_window (window
, pos
.bufpos
);
2333 if (cursor_vpos
>= 0)
2335 if (!just_this_one
|| current_buffer
->clip_changed
2336 || beg_unchanged
< startp
)
2337 /* Forget any recorded base line for line number display. */
2338 w
->base_line_number
= Qnil
;
2342 cancel_my_columns (w
);
2348 if (scroll_step
&& ! scroll_margin
&& !current_buffer
->clip_changed
2349 && startp
>= BEGV
&& startp
<= ZV
)
2351 if (margin_call
== 0)
2352 margin_call
= (PT
> startp
? 1 : -1);
2353 if (margin_call
> 0)
2355 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
2356 if (pos
.vpos
>= height
)
2360 pos
= *vmotion (startp
, (margin_call
< 0 ? - scroll_step
: scroll_step
),
2363 if (PT
>= pos
.bufpos
)
2365 /* The old bottom-of-screen position is no longer valid. */
2366 w
->window_end_valid
= Qnil
;
2368 if (! NILP (Vwindow_scroll_functions
))
2370 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2371 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2372 make_number (pos
.bufpos
));
2373 pos
.bufpos
= marker_position (w
->start
);
2375 try_window (window
, pos
.bufpos
);
2376 if (cursor_vpos
>= 0)
2378 if (!just_this_one
|| current_buffer
->clip_changed
2379 || beg_unchanged
< startp
)
2380 /* Forget any recorded base line for line number display. */
2381 w
->base_line_number
= Qnil
;
2385 cancel_my_columns (w
);
2391 /* Finally, just choose place to start which centers point */
2394 /* Forget any previously recorded base line for line number display. */
2395 w
->base_line_number
= Qnil
;
2397 pos
= *vmotion (PT
, - (height
/ 2), w
);
2399 /* The minibuffer is often just one line. Ordinary scrolling
2400 gives little overlap and looks bad. So show 20 chars before point. */
2402 && (pos
.bufpos
>= PT
- minibuffer_scroll_overlap
2403 /* If we scrolled less than 1/2 line forward, we will
2404 get too much overlap, so change to the usual amount. */
2405 || pos
.bufpos
< startp
+ width
/ 2)
2406 && PT
> BEGV
+ minibuffer_scroll_overlap
2407 /* If we scrolled to an actual line boundary,
2408 that's different; don't ignore line boundaries. */
2409 && FETCH_BYTE (pos
.bytepos
- 1) != '\n')
2411 pos
.bufpos
= PT
- minibuffer_scroll_overlap
;
2412 pos
.bytepos
= CHAR_TO_BYTE (pos
.bufpos
);
2415 /* Set startp here explicitly in case that helps avoid an infinite loop
2416 in case the window-scroll-functions functions get errors. */
2417 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2419 /* The old bottom-of-screen position is no longer valid. */
2420 w
->window_end_valid
= Qnil
;
2421 if (! NILP (Vwindow_scroll_functions
))
2423 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2424 make_number (pos
.bufpos
));
2425 pos
.bufpos
= marker_position (w
->start
);
2426 pos
.bytepos
= marker_byte_position (w
->start
);
2428 try_window (window
, pos
.bufpos
);
2430 startp
= marker_position (w
->start
);
2431 startp_byte
= marker_byte_position (w
->start
);
2432 w
->start_at_line_beg
2433 = (startp
== BEGV
|| FETCH_BYTE (startp_byte
- 1) == '\n') ? Qt
: Qnil
;
2436 if ((update_mode_line
2437 /* If window not full width, must redo its mode line
2438 if the window to its side is being redone */
2439 || (!just_this_one
&& !WINDOW_FULL_WIDTH_P (w
))
2440 || INTEGERP (w
->base_line_pos
)
2441 || (!NILP (w
->column_number_displayed
)
2442 && XFASTINT (w
->column_number_displayed
) != current_column ()))
2443 && height
!= XFASTINT (w
->height
))
2445 FRAME_PTR oframe
= selected_frame
;
2446 if (!really_switched_buffer
)
2448 set_buffer_temp (old
);
2449 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2450 really_switched_buffer
= 1;
2453 display_mode_line (w
);
2454 selected_frame
= oframe
;
2456 if (! line_number_displayed
2457 && ! BUFFERP (w
->base_line_pos
))
2459 w
->base_line_pos
= Qnil
;
2460 w
->base_line_number
= Qnil
;
2463 /* When we reach a frame's selected window, redo the frame's menu bar. */
2464 if (update_mode_line
2465 && (FRAME_WINDOW_P (f
)
2467 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2468 FRAME_EXTERNAL_MENU_BAR (f
)
2470 FRAME_MENU_BAR_LINES (f
) > 0
2472 : FRAME_MENU_BAR_LINES (f
) > 0)
2473 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
2474 display_menu_bar (w
);
2477 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2479 int start
, end
, whole
;
2481 /* Calculate the start and end positions for the current window.
2482 At some point, it would be nice to choose between scrollbars
2483 which reflect the whole buffer size, with special markers
2484 indicating narrowing, and scrollbars which reflect only the
2487 Note that minibuffers sometimes aren't displaying any text. */
2488 if (! MINI_WINDOW_P (w
)
2489 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
2492 start
= marker_position (w
->start
) - BEGV
;
2493 /* I don't think this is guaranteed to be right. For the
2494 moment, we'll pretend it is. */
2495 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
2497 if (end
< start
) end
= start
;
2498 if (whole
< (end
- start
)) whole
= end
- start
;
2501 start
= end
= whole
= 0;
2503 /* Indicate what this scroll bar ought to be displaying now. */
2504 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
2506 /* Note that we actually used the scroll bar attached to this window,
2507 so it shouldn't be deleted at the end of redisplay. */
2508 (*redeem_scroll_bar_hook
) (w
);
2511 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
2512 if (really_switched_buffer
)
2513 set_buffer_internal_1 (old
);
2515 set_buffer_temp (old
);
2516 TEMP_SET_PT_BOTH (lpoint
, lpoint_byte
);
2518 unbind_to (count
, Qnil
);
2521 /* Do full redisplay on one window, starting at position `pos'. */
2524 try_window (window
, pos
)
2528 register struct window
*w
= XWINDOW (window
);
2529 register int height
= window_internal_height (w
);
2530 register int vpos
= XFASTINT (w
->top
);
2531 register int last_text_vpos
= vpos
;
2532 FRAME_PTR f
= XFRAME (w
->frame
);
2533 int width
= window_internal_width (w
) - 1;
2534 struct position val
;
2536 /* POS should never be out of range! */
2537 if (pos
< XBUFFER (w
->buffer
)->begv
2538 || pos
> XBUFFER (w
->buffer
)->zv
)
2541 if (XMARKER (w
->start
)->charpos
!= pos
)
2542 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2545 overlay_arrow_seen
= 0;
2546 zv_strings_seen
= 0;
2547 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2548 val
.ovstring_chars_done
= 0;
2549 val
.bytepos
= marker_byte_position (w
->start
);
2550 val
.tab_offset
= pos_tab_offset (w
, pos
, val
.bytepos
);
2552 while (--height
>= 0)
2554 val
= *display_text_line (w
, pos
, val
.bytepos
, vpos
,
2555 val
.hpos
, val
.tab_offset
,
2556 val
.ovstring_chars_done
);
2557 /* The following code is omitted because we maintain tab_offset
2560 tab_offset
+= width
;
2561 if (val
.vpos
) tab_offset
= 0;
2564 if (pos
!= val
.bufpos
)
2567 #ifdef USE_TEXT_PROPERTIES
2568 Lisp_Object invis_prop
;
2569 invis_prop
= Fget_char_property (make_number (val
.bufpos
- 1),
2570 Qinvisible
, window
);
2571 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
2575 /* Next line, unless prev line ended in end of buffer with no cr */
2577 && (FETCH_BYTE (val
.bytepos
- 1) != '\n' || invis
));
2582 /* If last line is continued in middle of character,
2583 include the split character in the text considered on the frame */
2584 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2587 /* If bottom just moved off end of frame, change mode line percentage. */
2588 if (XFASTINT (w
->window_end_pos
) == 0
2590 w
->update_mode_line
= Qt
;
2592 /* Say where last char on frame will be, once redisplay is finished. */
2593 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
2594 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
2595 /* But that is not valid info until redisplay finishes. */
2596 w
->window_end_valid
= Qnil
;
2599 /* Try to redisplay when buffer is modified locally,
2600 computing insert/delete line to preserve text outside
2601 the bounds of the changes.
2602 Return 1 if successful, 0 if if cannot tell what to do,
2603 or -1 to tell caller to find a new window start,
2604 or -2 to tell caller to do normal redisplay with same window start. */
2607 try_window_id (window
)
2611 int opoint
, opoint_byte
;
2612 register struct window
*w
= XWINDOW (window
);
2613 register int height
= window_internal_height (w
);
2614 FRAME_PTR f
= XFRAME (w
->frame
);
2615 int top
= XFASTINT (w
->top
);
2616 int start
= marker_position (w
->start
);
2617 int width
= window_internal_width (w
) - 1;
2618 int hscroll
= XINT (w
->hscroll
);
2619 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
2622 register int i
, tem
;
2623 int last_text_vpos
= 0;
2625 int selective
= (INTEGERP (current_buffer
->selective_display
)
2626 ? XINT (current_buffer
->selective_display
)
2627 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2628 struct position val
, bp
, ep
, xp
, pp
;
2629 int scroll_amount
= 0;
2633 int start_byte
= marker_byte_position (w
->start
);
2635 if (GPT
- BEG
< beg_unchanged
)
2636 beg_unchanged
= GPT
- BEG
;
2637 if (Z
- GPT
< end_unchanged
)
2638 end_unchanged
= Z
- GPT
;
2640 if (beg_unchanged
+ BEG
< start
)
2641 return 0; /* Give up if changes go above top of window */
2643 /* Find position before which nothing is changed. */
2644 bp
= *compute_motion (start
, 0, lmargin
, 0,
2645 min (ZV
, beg_unchanged
+ BEG
), height
,
2646 /* BUG FIX: See the comment of
2647 Fpos_visible_in_window_p (window.c). */
2648 - (1 << (BITS_PER_SHORT
- 1)),
2650 pos_tab_offset (w
, start
, start_byte
),
2652 if (bp
.vpos
>= height
)
2656 /* All changes are beyond the window end, and point is on the screen.
2657 We don't need to change the text at all.
2658 But we need to update window_end_pos to account for
2659 any change in buffer size. */
2660 bp
= *compute_motion (start
, 0, lmargin
, 0,
2662 /* BUG FIX: See the comment of
2663 Fpos_visible_in_window_p() (window.c). */
2664 - (1 << (BITS_PER_SHORT
- 1)),
2666 pos_tab_offset (w
, start
, start_byte
), w
);
2667 XSETFASTINT (w
->window_end_vpos
, height
);
2668 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
2676 /* Find beginning of that frame line. Must display from there. */
2677 bp
= *vmotion (bp
.bufpos
, 0, w
);
2680 pos_byte
= bp
.bytepos
;
2686 /* If about to start displaying at the beginning of a continuation line,
2687 really start with previous frame line, in case it was not
2688 continued when last redisplayed */
2689 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
2691 /* Likewise if we have to worry about selective display. */
2692 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
2694 bp
= *vmotion (bp
.bufpos
, -1, w
);
2697 pos_byte
= bp
.bytepos
;
2699 val
.tab_offset
= bp
.tab_offset
; /* Update tab offset. */
2701 if (bp
.contin
&& bp
.hpos
!= lmargin
)
2703 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
2704 val
.tab_offset
= bp
.tab_offset
+ bp
.prevhpos
- width
;
2706 DEC_BOTH (pos
, pos_byte
);
2711 /* Find first visible newline after which no more is changed. */
2712 opoint
= PT
, opoint_byte
= PT_BYTE
;
2713 TEMP_SET_PT (Z
- max (end_unchanged
, Z
- ZV
));
2714 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2716 while (PT
< ZV
- 1 && indented_beyond_p (PT
, PT_BYTE
, selective
))
2717 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2719 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
2721 /* Compute the cursor position after that newline. */
2722 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
2723 height
, - (1 << (BITS_PER_SHORT
- 1)),
2725 /* We have tab offset in VAL, use it. */
2728 /* If changes reach past the text available on the frame,
2729 just display rest of frame. */
2730 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
2733 stop_vpos
= ep
.vpos
;
2735 /* If no newline before ep, the line ep is on includes some changes
2736 that must be displayed. Make sure we don't stop before it. */
2737 /* Also, if changes reach all the way until ep.bufpos,
2738 it is possible that something was deleted after the
2739 newline before it, so the following line must be redrawn. */
2740 if (stop_vpos
== ep
.vpos
2741 && (ep
.bufpos
== BEGV
2742 || FETCH_BYTE (ep
.bytepos
- 1) != '\n'
2743 || ep
.bufpos
== Z
- end_unchanged
))
2744 stop_vpos
= ep
.vpos
+ 1;
2747 overlay_arrow_seen
= 0;
2748 zv_strings_seen
= 0;
2750 /* If changes do not reach to bottom of window,
2751 figure out how much to scroll the rest of the window */
2752 if (stop_vpos
< height
)
2754 /* Now determine how far up or down the rest of the window has moved */
2755 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2756 Z
- XFASTINT (w
->window_end_pos
),
2757 /* Don't care for VPOS... */
2758 1 << (BITS_PER_SHORT
- 1),
2760 1 << (BITS_PER_SHORT
- 1),
2761 width
, hscroll
, ep
.tab_offset
, w
);
2762 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2764 /* Is everything on frame below the changes whitespace?
2765 If so, no scrolling is really necessary. */
2766 for (i
= ep
.bytepos
; i
< xp
.bytepos
; i
++)
2768 tem
= FETCH_BYTE (i
);
2769 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2772 if (i
== xp
.bytepos
)
2775 XSETFASTINT (w
->window_end_vpos
,
2776 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2778 /* Before doing any scrolling, verify that point will be on frame. */
2779 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.vpos
< height
))
2781 if (PT
<= xp
.bufpos
)
2783 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2784 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2786 /* We have tab offset in EP, use it. */
2791 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2792 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2794 /* We have tab offset in XP, use it. */
2797 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2799 cursor_vpos
= pp
.vpos
+ top
;
2800 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, pp
.hpos
, width
);
2803 if (stop_vpos
- scroll_amount
>= height
2804 || ep
.bufpos
== xp
.bufpos
)
2806 if (scroll_amount
< 0)
2807 stop_vpos
-= scroll_amount
;
2809 /* In this path, we have altered window_end_vpos
2810 and not left it negative.
2811 We must make sure that, in case display is preempted
2812 before the frame changes to reflect what we do here,
2813 further updates will not come to try_window_id
2814 and assume the frame and window_end_vpos match. */
2815 blank_end_of_window
= 1;
2817 else if (!scroll_amount
)
2819 /* Even if we don't need to scroll, we must adjust the
2820 charstarts of subsequent lines (that we won't redisplay)
2821 according to the amount of text inserted or deleted. */
2822 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2823 int adjust
= ep
.bufpos
- oldpos
;
2824 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2826 else if (bp
.bufpos
== Z
- end_unchanged
)
2828 /* If reprinting everything is nearly as fast as scrolling,
2829 don't bother scrolling. Can happen if lines are short. */
2830 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2831 top
+ height
- max (0, scroll_amount
),
2833 > xp
.bufpos
- bp
.bufpos
- 20)
2834 /* Return "try normal display with same window-start."
2835 Too bad we can't prevent further scroll-thinking. */
2837 /* If pure deletion, scroll up as many lines as possible.
2838 In common case of killing a line, this can save the
2839 following line from being overwritten by scrolling
2840 and therefore having to be redrawn. */
2841 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2842 top
+ height
- max (0, scroll_amount
),
2843 scroll_amount
, bp
.bufpos
);
2848 /* scroll_frame_lines did not properly adjust subsequent
2849 lines' charstarts in the case where the text of the
2850 screen line at bp.vpos has changed.
2851 (This can happen in a deletion that ends in mid-line.)
2852 To adjust properly, we need to make things consistent
2854 So do a second adjust to make that happen.
2855 Note that stop_vpos >= ep.vpos, so it is sufficient
2856 to update the charstarts for lines at ep.vpos and below. */
2858 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2859 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2860 ep
.bufpos
- oldstart
);
2863 else if (scroll_amount
)
2865 /* If reprinting everything is nearly as fast as scrolling,
2866 don't bother scrolling. Can happen if lines are short. */
2867 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2868 overestimate of cost of reprinting, since xp.bufpos
2869 would end up below the bottom of the window. */
2870 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2871 top
+ height
- max (0, scroll_amount
),
2873 > xp
.bufpos
- ep
.bufpos
- 20)
2874 /* Return "try normal display with same window-start."
2875 Too bad we can't prevent further scroll-thinking. */
2877 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2878 top
+ height
- max (0, scroll_amount
),
2879 scroll_amount
, ep
.bufpos
);
2880 if (!tem
) stop_vpos
= height
;
2884 /* In any case, do not display past bottom of window */
2885 if (stop_vpos
>= height
)
2891 /* Handle case where pos is before w->start --
2892 can happen if part of line had been clipped and is not clipped now */
2893 if (vpos
== 0 && pos
< marker_position (w
->start
))
2894 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2896 val
.bytepos
= pos_byte
;
2898 /* Redisplay the lines where the text was changed */
2899 last_text_vpos
= vpos
;
2900 /* The following code is omitted because we maintain tab offset in
2903 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2904 /* If we are starting display in mid-character, correct tab_offset
2905 to account for passing the line that that character really starts in. */
2906 if (val
.hpos
< lmargin
)
2907 tab_offset
+= width
;
2910 while (vpos
< stop_vpos
)
2912 val
= *display_text_line (w
, pos
, val
.bytepos
, top
+ vpos
++,
2913 val
.hpos
, val
.tab_offset
,
2914 val
.ovstring_chars_done
);
2915 /* If display_text_line ran a hook and changed some text,
2916 redisplay all the way to bottom of buffer
2917 So that we show the changes. */
2918 if (old_tick
!= MODIFF
)
2920 /* The following code is omitted because we maintain tab offset
2921 in val.tab_offset. */
2923 tab_offset
+= width
;
2924 if (val
.vpos
) tab_offset
= 0;
2926 if (pos
!= val
.bufpos
)
2928 /* Next line, unless prev line ended in end of buffer with no cr */
2929 = vpos
- (val
.vpos
&& FETCH_BYTE (val
.bytepos
- 1) != '\n');
2933 /* There are two cases:
2934 1) we have displayed down to the bottom of the window
2935 2) we have scrolled lines below stop_vpos by scroll_amount */
2939 /* If last line is continued in middle of character,
2940 include the split character in the text considered on the frame */
2941 if (val
.hpos
< lmargin
)
2943 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2944 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2947 /* If scrolling made blank lines at window bottom,
2948 redisplay to fill those lines */
2949 if (scroll_amount
< 0)
2951 /* Don't consider these lines for general-purpose scrolling.
2952 That will save time in the scrolling computation. */
2953 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2956 pos_byte
= xp
.bytepos
;
2958 val
.tab_offset
= xp
.tab_offset
;
2960 { /* Display from next line */
2961 vpos
= height
+ scroll_amount
;
2965 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2967 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2968 val
.tab_offset
= xp
.tab_offset
+ bp
.prevhpos
- width
;
2969 DEC_BOTH (pos
, pos_byte
);
2972 blank_end_of_window
= 1;
2973 /* The following code is omitted because we maintain tab offset
2974 in val.tab_offset. */
2976 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2977 /* If we are starting display in mid-character, correct tab_offset
2978 to account for passing the line that that character starts in. */
2979 if (val
.hpos
< lmargin
)
2980 tab_offset
+= width
;
2982 val
.bytepos
= pos_byte
;
2983 while (vpos
< height
)
2985 val
= *display_text_line (w
, pos
, val
.bytepos
,
2986 top
+ vpos
++, val
.hpos
,
2987 val
.tab_offset
, val
.ovstring_chars_done
);
2988 /* The following code is omitted because we maintain tab
2989 offset in val.tab_offset. */
2991 tab_offset
+= width
;
2992 if (val
.vpos
) tab_offset
= 0;
2997 /* Here is a case where display_text_line sets cursor_vpos wrong.
2998 Make it be fixed up, below. */
3004 /* If bottom just moved off end of frame, change mode line percentage. */
3005 if (XFASTINT (w
->window_end_pos
) == 0
3007 w
->update_mode_line
= Qt
;
3009 /* Attempt to adjust end-of-text positions to new bottom line */
3012 delta
= height
- xp
.vpos
;
3014 || (delta
> 0 && xp
.bufpos
<= ZV
)
3015 || (delta
== 0 && xp
.hpos
))
3017 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
3018 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
3019 XSETFASTINT (w
->window_end_vpos
,
3020 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
3024 w
->window_end_valid
= Qnil
;
3026 /* If point was not in a line that was displayed, find it */
3027 if (cursor_vpos
< 0)
3030 val
= *compute_motion (start
, 0, lmargin
, 0, PT
,
3031 /* Don't care for VPOS... */
3032 1 << (BITS_PER_SHORT
- 1),
3034 1 << (BITS_PER_SHORT
- 1),
3036 pos_tab_offset (w
, start
, start_byte
),
3038 /* Admit failure if point is off frame now */
3039 if (val
.vpos
>= height
)
3041 for (vpos
= 0; vpos
< height
; vpos
++)
3042 cancel_line (vpos
+ top
, f
);
3045 cursor_vpos
= val
.vpos
+ top
;
3046 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, val
.hpos
, width
);
3049 FRAME_CURSOR_X (f
) = cursor_hpos
;
3050 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3054 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
3055 height
, - (1 << (BITS_PER_SHORT
- 1)),
3057 pos_tab_offset (w
, start
, start_byte
),
3059 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
3061 if (XFASTINT (w
->window_end_pos
)
3069 /* Copy LEN glyphs starting address FROM to the rope TO.
3070 But don't actually copy the parts that would come in before S.
3071 Value is TO, advanced past the copied data.
3072 F is the frame we are displaying in. */
3075 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
3077 register GLYPH
*to
; /* Copy to here. */
3078 register GLYPH
*s
; /* Starting point. */
3079 Lisp_Object
*from
; /* Data to copy. */
3081 int face
; /* Face to apply to glyphs which don't specify one. */
3084 register Lisp_Object
*fp
= from
;
3085 /* These cache the results of the last call to compute_glyph_face. */
3087 int last_merged
= 0;
3090 if (! FRAME_TERMCAP_P (f
))
3093 GLYPH glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3095 unsigned int c
= FAST_GLYPH_CHAR (glyph
);
3098 /* For an invalid character code, use space. */
3101 if (FAST_GLYPH_FACE (glyph
) == 0)
3102 /* If GLYPH has no face code, use FACE. */
3104 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
3105 /* If it's same as previous glyph, use same result. */
3106 facecode
= last_merged
;
3109 /* Merge this glyph's face and remember the result. */
3110 last_code
= FAST_GLYPH_FACE (glyph
);
3111 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
3115 *to
= FAST_MAKE_GLYPH (c
, facecode
);
3123 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3130 /* Correct a glyph by replacing its specified user-level face code
3131 with a displayable computed face code. */
3134 fix_glyph (f
, glyph
, cface
)
3140 if (! FRAME_TERMCAP_P (f
))
3142 if (FAST_GLYPH_FACE (glyph
) != 0)
3143 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
3144 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
3150 /* Return the column of position POS / POS_BYTE in window W's buffer.
3151 When used on the character at the beginning of a line,
3152 starting at column 0, this says how much to subtract from
3153 the column position of any character in the line
3154 to get its horizontal position on the screen. */
3157 pos_tab_offset (w
, pos
, pos_byte
)
3159 register int pos
, pos_byte
;
3162 int opoint_byte
= PT_BYTE
;
3164 int width
= window_internal_width (w
) - 1;
3167 return MINI_WINDOW_P (w
) ? -minibuf_prompt_width
: 0;
3169 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3172 TEMP_SET_PT_BOTH (pos
, pos_byte
);
3173 col
= current_column ();
3174 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3179 /* Display one line of window W, starting at char position START in W's buffer.
3180 START_BYTE is the corresponding byte position.
3182 Display starting at horizontal position HPOS, expressed relative to
3183 W's left edge. In situations where the text at START shouldn't
3184 start at the left margin (i.e. when the window is hscrolled, or
3185 we're continuing a line which left off in the midst of a
3186 multi-column character), HPOS should be negative; we throw away
3187 characters up 'til hpos = 0. So, HPOS must take hscrolling into
3190 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
3192 OVSTR_DONE is the number of chars of overlay before/after strings
3193 at this position which have already been processed.
3195 Display on position VPOS on the frame. It is origin 0, relative to
3196 the top of the frame, not W.
3198 Returns a STRUCT POSITION giving character to start next line with
3199 and where to display it, including a zero or negative hpos.
3200 The vpos field is not really a vpos; it is 1 unless the line is continued */
3202 struct position val_display_text_line
;
3204 static struct position
*
3205 display_text_line (w
, start
, start_byte
, vpos
, hpos
, taboffset
, ovstr_done
)
3213 register int pos
= start
;
3214 int pos_byte
= start_byte
;
3217 int pause
, limit_byte
;
3218 register unsigned char *p
;
3220 register GLYPH
*leftmargin
;
3221 register GLYPH
*p1prev
;
3222 register GLYPH
*p1start
;
3223 GLYPH
*p1_wide_column_end
= (GLYPH
*) 0;
3224 int prevpos
, prevpos_byte
;
3226 FRAME_PTR f
= XFRAME (w
->frame
);
3227 int tab_width
= XINT (current_buffer
->tab_width
);
3228 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
3229 int width
= window_internal_width (w
) - 1;
3230 struct position val
;
3231 int lastpos
, lastpos_byte
;
3233 int last_invis_skip
= 0;
3234 Lisp_Object last_invis_prop
;
3235 int hscroll
= XINT (w
->hscroll
);
3236 int truncate
= (hscroll
3237 || (truncate_partial_width_windows
3238 && !WINDOW_FULL_WIDTH_P (w
))
3239 || !NILP (current_buffer
->truncate_lines
));
3241 /* 1 if this buffer has a region to highlight. */
3242 int highlight_region
3243 = (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
)
3244 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
3245 int region_beg
, region_end
;
3247 int selective
= (INTEGERP (current_buffer
->selective_display
)
3248 ? XINT (current_buffer
->selective_display
)
3249 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
3250 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
3251 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
3253 Lisp_Object default_invis_vector
[3];
3254 /* Number of characters of ellipsis to display after an invisible line
3255 if it calls for an ellipsis.
3256 Note that this value can be nonzero regardless of whether
3257 selective display is enabled--you must check that separately. */
3259 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3260 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
3261 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
3262 /* This is the sequence of Lisp objects to display
3263 when there are invisible lines. */
3264 Lisp_Object
*invis_vector_contents
3265 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3266 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
3267 : default_invis_vector
);
3269 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
3270 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp
)))
3271 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
3272 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
3273 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp
)))
3274 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
3276 /* If 1, we must handle multibyte characters. */
3277 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
3278 /* Length of multibyte form of each character. */
3280 /* Glyphs generated should be set this bit mask if text must be
3281 displayed from right to left. */
3282 GLYPH rev_dir_bit
= (NILP (current_buffer
->direction_reversed
)
3283 ? 0 : GLYPH_MASK_REV_DIR
);
3285 /* The next buffer location at which the face should change, due
3286 to overlays or text property changes. */
3287 int next_face_change
;
3289 /* The next location where the `invisible' property changes, or an
3290 overlay starts or ends. */
3293 /* The face we're currently using. */
3294 int current_face
= 0;
3297 XSETFASTINT (default_invis_vector
[2], '.');
3298 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
3300 get_display_line (f
, vpos
, WINDOW_LEFT_MARGIN (w
));
3301 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
3303 /* Show where to highlight the region. */
3304 if (highlight_region
3305 /* Maybe highlight only in selected window. */
3306 && (highlight_nonselected_windows
3307 || w
== XWINDOW (selected_window
)
3308 || (MINI_WINDOW_P (XWINDOW (selected_window
))
3309 && w
== XWINDOW (Vminibuf_scroll_window
))))
3311 region_beg
= marker_position (current_buffer
->mark
);
3312 if (PT
< region_beg
)
3314 region_end
= region_beg
;
3319 w
->region_showing
= Qt
;
3323 region_beg
= region_end
= -1;
3324 w
->region_showing
= Qnil
;
3327 if (MINI_WINDOW_P (w
)
3329 && vpos
== XFASTINT (w
->top
))
3331 if (! NILP (minibuf_prompt
))
3333 int old_width
= minibuf_prompt_width
;
3335 minibuf_prompt_width
3336 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
3337 STRING_BYTES (XSTRING (minibuf_prompt
)),
3338 hpos
+ WINDOW_LEFT_MARGIN (w
),
3339 /* Display a space if we truncate. */
3342 /* Truncate the prompt a little before the
3343 margin, so user input can at least start
3344 on the first line. */
3345 (XFASTINT (w
->width
) > 10
3346 ? XFASTINT (w
->width
) - 4 : -1),
3347 STRING_MULTIBYTE (minibuf_prompt
))
3348 - hpos
- WINDOW_LEFT_MARGIN (w
));
3349 hpos
+= minibuf_prompt_width
;
3350 taboffset
-= minibuf_prompt_width
- old_width
;
3353 minibuf_prompt_width
= 0;
3356 /* If we're hscrolled at all, use compute_motion to skip over any
3357 text off the left edge of the window. compute_motion may know
3358 tricks to do this faster than we can. */
3361 struct position
*left_edge
3362 = compute_motion (pos
, vpos
, hpos
, 0,
3364 width
, hscroll
, taboffset
, w
);
3366 /* Retrieve the buffer position and column provided by
3367 compute_motion. We can't assume that the column will be
3368 zero, because you may have multi-column characters crossing
3371 compute_motion may have moved us past the screen position we
3372 requested, if we hit a multi-column character, or the end of
3373 the line. If so, back up. */
3374 if ((left_edge
->vpos
> vpos
3375 || left_edge
->hpos
> 0)
3376 && left_edge
->bufpos
> pos
)
3378 pos
= left_edge
->bufpos
;
3379 pos_byte
= left_edge
->bytepos
;
3380 DEC_BOTH (pos
, pos_byte
);
3381 hpos
= left_edge
->prevhpos
;
3385 pos
= left_edge
->bufpos
;
3386 pos_byte
= left_edge
->bytepos
;
3387 hpos
= left_edge
->hpos
;
3391 hpos
+= WINDOW_LEFT_MARGIN (w
);
3393 desired_glyphs
->bufp
[vpos
] = start
;
3394 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
3396 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
3397 /* In case we don't ever write anything into it... */
3398 desired_glyphs
->charstarts
[vpos
][WINDOW_LEFT_MARGIN (w
)] = -1;
3399 leftmargin
= desired_glyphs
->glyphs
[vpos
] + WINDOW_LEFT_MARGIN (w
);
3400 endp
= leftmargin
+ width
;
3402 /* Arrange the overlays nicely for our purposes. Usually, we call
3403 display_text_line on only one line at a time, in which case this
3404 can't really hurt too much, or we call it on lines which appear
3405 one after another in the buffer, in which case all calls to
3406 recenter_overlay_lists but the first will be pretty cheap. */
3407 recenter_overlay_lists (current_buffer
, pos
);
3409 /* Loop generating characters.
3410 Stop at end of buffer, before newline,
3411 if reach or pass continuation column,
3412 or at face change. */
3414 limit_byte
= pos_byte
;
3415 next_face_change
= pos
;
3416 next_boundary
= pos
;
3419 prevpos_byte
= pos_byte
;
3421 /* If the window is hscrolled and point is in the invisible part of the
3422 current line beyond the left margin we can record the cursor location
3424 if (hscroll
&& start
<= PT
&& PT
< pos
&& cursor_vpos
< 0)
3427 cursor_hpos
= p1
- leftmargin
;
3436 while (pos
== next_boundary
)
3438 Lisp_Object position
, limit
, prop
, ww
;
3440 /* Display the overlay strings here, unless we're at ZV
3441 and have already displayed the appropriate strings
3442 on an earlier line. */
3443 if (pos
< ZV
|| !zv_strings_seen
++)
3446 unsigned char *ovstr
;
3447 ovlen
= overlay_strings (pos
, w
, &ovstr
);
3451 /* Skip the ones we did in a previous line. */
3452 ovstr
+= ovstr_done
;
3453 ovlen
-= ovstr_done
;
3462 c
= STRING_CHAR_AND_LENGTH (ovstr
, ovlen
, len
);
3463 ovstr
+= len
, ovlen
-= len
, ovstr_done
+= len
;
3464 charset
= CHAR_CHARSET (c
);
3465 cols
= (charset
== CHARSET_COMPOSITION
3466 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3467 : CHARSET_WIDTH (charset
));
3471 c
= *ovstr
++, ovlen
--, ovstr_done
++;
3474 g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3477 if (p1
>= leftmargin
&& p1
< endp
)
3478 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3482 /* If we did all the overlay strings
3483 and we have room for text, clear ovstr_done
3484 just for neatness' sake. */
3485 if (ovlen
== 0 && p1
< endp
)
3490 /* Did we reach point? Record the cursor location. */
3491 if (pos
== PT
&& cursor_vpos
< 0)
3494 cursor_hpos
= p1
- leftmargin
;
3500 XSETFASTINT (position
, pos
);
3501 limit
= Fnext_overlay_change (position
);
3502 #ifdef USE_TEXT_PROPERTIES
3503 /* This is just an estimate to give reasonable
3504 performance; nothing should go wrong if it is too small. */
3505 if (XFASTINT (limit
) > pos
+ 50)
3507 int limitpos
= pos
+ 50;
3508 XSETFASTINT (limit
, limitpos
);
3510 limit
= Fnext_single_property_change (position
, Qinvisible
,
3511 Fcurrent_buffer (), limit
);
3513 next_boundary
= XFASTINT (limit
);
3514 /* if the `invisible' property is set, we can skip to
3515 the next property change. */
3517 prop
= Fget_char_property (position
, Qinvisible
, ww
);
3518 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3520 if (pos
< PT
&& next_boundary
>= PT
)
3523 cursor_hpos
= p1
- leftmargin
;
3525 pos
= next_boundary
;
3526 pos_byte
= CHAR_TO_BYTE (pos
);
3527 last_invis_skip
= pos
;
3528 last_invis_prop
= prop
;
3532 /* Did we reach point? Record the cursor location. */
3533 if (pos
== PT
&& cursor_vpos
< 0)
3536 cursor_hpos
= p1
- leftmargin
;
3539 /* Did we hit the end of the visible region of the buffer?
3543 /* Update charstarts for the end of this line. */
3544 /* Do nothing if off the left edge or at the right edge. */
3545 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
3547 int *p2x
= &charstart
[(p1
< leftmargin
3555 /* Figure out where (if at all) the
3556 redisplay_end_trigger-hook should run. */
3557 if (MARKERP (w
->redisplay_end_trigger
)
3558 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
3559 e_t_h
= marker_position (w
->redisplay_end_trigger
);
3560 else if (INTEGERP (w
->redisplay_end_trigger
))
3561 e_t_h
= XINT (w
->redisplay_end_trigger
);
3565 /* If we've gone past the place to run a hook,
3567 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
3569 Lisp_Object args
[3];
3571 args
[0] = Qredisplay_end_trigger_functions
;
3572 XSETWINDOW (args
[1], w
);
3573 XSETINT (args
[2], e_t_h
);
3575 /* Since we are *trying* to run these functions,
3576 don't try to run them again, even if they get an error. */
3577 w
->redisplay_end_trigger
= Qnil
;
3578 Frun_hook_with_args (3, args
);
3581 /* Notice if it changed the face of this character. */
3582 next_face_change
= pos
;
3586 /* Did we hit a face change? Figure out what face we should
3587 use now. We also hit this the first time through the
3588 loop, to see what face we should start with. */
3589 if (pos
>= next_face_change
3590 && (FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
)))
3592 int limit
= pos
+ 50;
3594 current_face
= compute_char_face (f
, w
, pos
,
3595 region_beg
, region_end
,
3596 &next_face_change
, limit
, 0);
3600 /* Compute the next place we need to stop
3601 and do something special; set PAUSE. */
3605 if (pos
< next_boundary
&& next_boundary
< pause
)
3606 pause
= next_boundary
;
3607 if (pos
< next_face_change
&& next_face_change
< pause
)
3608 pause
= next_face_change
;
3613 /* Wouldn't you hate to read the next line to someone over
3615 if (pos
< PT
&& PT
< pause
)
3617 if (pos
< GPT
&& GPT
< pause
)
3620 /* LIMIT_BYTE is not the same place in the buffer as PAUSE.
3621 It is a limit on valid characters.
3622 We use it to bound STRING_CHAR_AND_LENGTH. */
3623 limit_byte
= ZV_BYTE
;
3624 if (pos
< GPT
&& GPT_BYTE
< limit_byte
)
3625 limit_byte
= GPT_BYTE
;
3628 int temp
= CHAR_TO_BYTE (pos
);
3629 p
= BYTE_POS_ADDR (temp
);
3637 p1_wide_column_end
= (GLYPH
*) 0;
3640 c
= STRING_CHAR_AND_LENGTH (p
, limit_byte
- pos_byte
, len
), p
+= len
;
3643 /* Let a display table override all standard display methods. */
3644 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3646 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
3647 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3648 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3649 current_face
, rev_dir_bit
);
3651 else if (c
>= 040 && c
< 0177)
3653 if (p1
>= leftmargin
)
3654 *p1
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3660 /* Same as p1prev, but after the invis_vector_contents text
3661 (if we have that on this line). */
3662 GLYPH
*p1prev_modified
;
3666 if (last_invis_skip
== pos
3667 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
3671 && indented_beyond_p (pos
+ 1, pos_byte
+ 1, selective
))
3673 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3676 INC_BOTH (pos
, pos_byte
);
3677 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3678 pos
= PT
, pos_byte
= PT_BYTE
;
3679 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3684 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3686 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
3691 cs
= charstart
+ (p1
- p1start
);
3694 p1
+= selective_rlen
;
3695 if (p1
- leftmargin
> width
)
3698 #if 0 /* This needs more work; charstarts needs to record
3699 both whether a position ho;ds an ellipsis character
3700 and what buffer position it corresponds to. */
3701 csend
= charstart
+ (p1
- p1start
);
3704 /* The idea is to use p1prev_modified instead of p1prev
3705 in the loop below over p2x. */
3706 p1prev_modified
= p1
;
3709 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3710 (p1
- p1prev
), current_face
, rev_dir_bit
);
3713 /* Update charstarts for the newline that ended this line. */
3714 /* Do nothing here for a char that's entirely off the left edge
3715 or if it starts at the right edge. */
3716 if (p1
>= leftmargin
&& p1prev
!= endp
)
3718 /* Store the newline's position into charstarts
3719 for the column where the newline starts.
3720 Store -1 for the rest of the glyphs it occupies. */
3721 int *p2x
= &charstart
[(p1prev
< leftmargin
3722 ? leftmargin
: p1prev
)
3724 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3731 /* Draw the face of the newline character as extending all the
3732 way to the end of the frame line. */
3735 if (p1
< leftmargin
)
3738 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3748 if (p1
>= leftmargin
&& p1
< endp
)
3749 *p1
= MAKE_GLYPH (f
, ' ', current_face
) | rev_dir_bit
;
3752 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
3755 else if (c
== Ctl ('M') && selective
== -1)
3757 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3758 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3759 pos
= PT
, pos_byte
= PT_BYTE
;
3760 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3762 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3764 if (selective_rlen
> 0)
3766 p1
+= selective_rlen
;
3767 if (p1
- leftmargin
> width
)
3769 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3770 (p1
- p1prev
), current_face
, rev_dir_bit
);
3773 /* Draw the face of the newline character as extending all the
3774 way to the end of the frame line. */
3777 if (p1
< leftmargin
)
3780 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3784 /* Update charstarts for the ^M that ended this line. */
3785 /* Do nothing here for a char that's entirely off the left edge
3786 or if it starts at the right edge. */
3787 if (p1
>= leftmargin
&& p1prev
!= endp
)
3789 /* Store the newline's position into charstarts
3790 for the column where the newline starts.
3791 Store -1 for the rest of the glyphs it occupies. */
3792 int *p2x
= &charstart
[(p1prev
< leftmargin
3793 ? leftmargin
: p1prev
)
3795 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3803 else if (c
< 0200 && ctl_arrow
)
3805 if (p1
>= leftmargin
)
3807 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3808 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
3809 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3813 if (p1
>= leftmargin
&& p1
< endp
)
3814 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
) | rev_dir_bit
;
3819 /* C is a multibyte character or a character to be displayed
3821 int remaining_bytes
= len
;
3823 if (c
>= 0400 && CHAR_VALID_P (c
, 0))
3825 /* C is a multibyte character. */
3826 int charset
= CHAR_CHARSET (c
);
3827 int columns
= (charset
== CHARSET_COMPOSITION
3828 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3829 : CHARSET_WIDTH (charset
));
3830 GLYPH g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3834 if (p1
>= leftmargin
&& p1
< endp
)
3835 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3838 p1_wide_column_end
= p1
;
3839 remaining_bytes
-= CHARSET_BYTES (charset
);
3842 while (remaining_bytes
> 0)
3844 c
= *(p
- remaining_bytes
--);
3846 if (p1
>= leftmargin
&& p1
< endp
)
3849 (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3850 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
3851 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3855 if (p1
>= leftmargin
&& p1
< endp
)
3856 *p1
= (MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
)
3859 if (p1
>= leftmargin
&& p1
< endp
)
3860 *p1
= (MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
)
3863 if (p1
>= leftmargin
&& p1
< endp
)
3864 *p1
= (MAKE_GLYPH (f
, (7 & c
) + '0', current_face
)
3871 prevpos_byte
= pos_byte
;
3875 /* Update charstarts for the character just output. */
3877 /* Do nothing here for a char that's entirely off the left edge. */
3878 if (p1
>= leftmargin
)
3880 /* Store the char's position into charstarts
3881 for the first glyph occupied by this char.
3882 Store -1 for the rest of the glyphs it occupies. */
3885 int *p2x
= &charstart
[(p1prev
< leftmargin
3886 ? leftmargin
: p1prev
)
3888 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3898 val
.hpos
= - XINT (w
->hscroll
);
3905 lastpos_byte
= pos_byte
;
3907 /* Store 0 in this charstart line for the positions where
3908 there is no character. But do leave what was recorded
3909 for the character that ended the line. */
3910 /* Add 1 in the endtest to compensate for the fact that ENDP was
3911 made from WIDTH, which is 1 less than the window's actual
3913 i
= p1
- p1start
+ 1;
3914 if (p1
< leftmargin
)
3915 i
+= leftmargin
- p1
;
3916 for (; i
< endp
- p1start
+ 1; i
++)
3919 /* Handle continuation in middle of a character */
3920 /* by backing up over it */
3923 /* Don't back up if we never actually displayed any text.
3924 This occurs when the minibuffer prompt takes up the whole line. */
3927 /* Start the next line with that same character whose
3928 character code is C and the length of multi-byte form is
3931 pos_byte
= prevpos_byte
;
3933 if (p1_wide_column_end
< endp
)
3934 /* As ENDP is not in the middle of wide-column character,
3935 we can break the line at ENDP and start from the middle
3936 column in the next line. So, adjust VAL.HPOS to skip
3937 the columns output on this line. */
3938 val
.hpos
+= p1prev
- endp
;
3941 /* We displayed a wide-column character at around ENDP.
3942 Since we can't broke it in the middle, the whole
3943 character should be driven into the next line. */
3944 /* As the result, the actual columns occupied by the
3945 text on this line is less than WIDTH. VAL.TAB_OFFSET
3946 must be adjusted. */
3947 taboffset
= taboffset
+ (p1prev
- endp
);
3948 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3950 GLYPH g
= fix_glyph (f
, truncate
? truncator
: continuer
, 0);
3951 while (p1prev
< endp
)
3954 /* If POINT is at POS, cursor should not on this line. */
3956 lastpos_byte
= pos_byte
;
3962 /* Keep in this line everything up to the continuation column. */
3966 /* Finish deciding which character to start the next line on,
3967 and what hpos to start it at.
3968 Also set `lastpos' to the last position which counts as "on this line"
3969 for cursor-positioning. */
3973 if (FETCH_BYTE (pos_byte
) == '\n')
3975 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3977 /* If stopped due to a newline, start next line after it */
3978 TEMP_SET_PT_BOTH (pos
+ 1, pos_byte
+ 1);
3981 /* Check again for hidden lines, in case the newline occurred exactly
3982 at the right margin. */
3983 while (PT
< ZV
&& selective
> 0
3984 && indented_beyond_p (PT
, PT_BYTE
, selective
))
3985 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
3987 pos
= PT
, pos_byte
= PT_BYTE
;
3988 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3991 /* Stopped due to right margin of window */
3995 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3997 TEMP_SET_PT_BOTH (pos
, pos_byte
);
3998 *p1
++ = fix_glyph (f
, truncator
, 0);
3999 /* Truncating => start next line after next newline,
4000 and point is on this line if it is before the newline,
4001 and skip none of first char of next line */
4003 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
4004 while (PT
< ZV
&& selective
> 0
4005 && indented_beyond_p (PT
, PT_BYTE
, selective
));
4006 pos
= PT
, pos_byte
= PT_BYTE
;
4007 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
4008 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
4010 lastpos
= pos
- (FETCH_BYTE (pos_byte
- 1) == '\n');
4011 lastpos_byte
= CHAR_TO_BYTE (lastpos
);
4016 *p1
++ = fix_glyph (f
, continuer
, 0);
4018 DEC_BOTH (lastpos
, lastpos_byte
);
4019 val
.tab_offset
= taboffset
+ width
;
4026 /* If point is at eol or in invisible text at eol,
4027 record its frame location now. */
4029 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
4032 cursor_hpos
= p1
- leftmargin
;
4035 if (cursor_vpos
== vpos
)
4037 if (cursor_hpos
< 0) cursor_hpos
= 0;
4038 if (cursor_hpos
> width
) cursor_hpos
= width
;
4039 cursor_hpos
+= WINDOW_LEFT_MARGIN (w
);
4040 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
4042 this_line_bufpos
= 0;
4044 /* If this frame's cursor will be in its echo area,
4045 don't record a cursor from the window text,
4046 and turn off the optimization for cursor-motion-only case. */
4047 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
4048 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
4050 FRAME_CURSOR_Y (f
) = cursor_vpos
;
4051 FRAME_CURSOR_X (f
) = cursor_hpos
;
4053 if (w
== XWINDOW (selected_window
))
4055 /* Line is not continued and did not start
4056 in middle of character */
4057 if ((hpos
- WINDOW_LEFT_MARGIN (w
)
4058 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
4061 this_line_bufpos
= start
;
4062 this_line_buffer
= current_buffer
;
4063 this_line_vpos
= cursor_vpos
;
4064 this_line_start_hpos
= hpos
- WINDOW_LEFT_MARGIN (w
);
4065 this_line_endpos
= Z
- lastpos
;
4072 /* If hscroll and line not empty, insert truncation-at-left marker */
4073 if (hscroll
&& lastpos
!= start
)
4075 GLYPH g
= fix_glyph (f
, truncator
, 0);
4077 if (p1
<= leftmargin
)
4078 p1
= leftmargin
+ 1;
4079 else /* MULE: it may be a wide-column character */
4081 p1prev
= leftmargin
+ 1;
4082 while (p1prev
< p1
&& *p1prev
& GLYPH_MASK_PADDING
)
4087 if (!WINDOW_RIGHTMOST_P (w
))
4090 if (p1
< leftmargin
) p1
= leftmargin
;
4091 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
4093 /* Don't draw vertical bars if we're using scroll bars. They're
4094 covered up by the scroll bars, and it's distracting to see
4095 them when the scroll bar windows are flickering around to be
4097 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4100 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4103 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4104 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
4105 ? XINT (DISP_BORDER_GLYPH (dp
))
4108 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
4109 p1
- desired_glyphs
->glyphs
[vpos
]);
4110 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
4112 /* If the start of this line is the overlay arrow-position,
4113 then put the arrow string into the display-line. */
4115 if (MARKERP (Voverlay_arrow_position
)
4116 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
4117 && start
== marker_position (Voverlay_arrow_position
)
4118 && STRINGP (Voverlay_arrow_string
)
4119 && ! overlay_arrow_seen
)
4122 int len
= XSTRING (Voverlay_arrow_string
)->size
;
4128 /* If the arrow string has text props, obey them when displaying. */
4129 for (i
= 0, i_byte
= 0; i
< len
; )
4132 Lisp_Object face
, ilisp
;
4136 if (STRING_MULTIBYTE (Voverlay_arrow_string
))
4137 FETCH_STRING_CHAR_ADVANCE (c
, Voverlay_arrow_string
, i
, i_byte
);
4139 c
= XSTRING (Voverlay_arrow_string
)->data
[i
++];
4141 XSETFASTINT (ilisp
, i
);
4143 if (FRAME_WINDOW_P (f
))
4145 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
4146 newface
= compute_glyph_face_1 (f
, face
, 0);
4147 c
= FAST_MAKE_GLYPH (c
, newface
);
4149 #endif /* HAVE_FACES */
4150 leftmargin
[idx
] = c
;
4153 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
4154 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
4155 if (desired_glyphs
->used
[vpos
] < arrow_end
)
4156 desired_glyphs
->used
[vpos
] = arrow_end
;
4158 overlay_arrow_seen
= 1;
4162 val
.bytepos
= pos_byte
;
4163 val
.ovstring_chars_done
= ovstr_done
;
4164 val_display_text_line
= val
;
4165 return &val_display_text_line
;
4168 /* Redisplay the menu bar in the frame for window W. */
4171 display_menu_bar (w
)
4174 Lisp_Object items
, tail
;
4175 register int vpos
= 0;
4176 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4177 int maxendcol
= FRAME_WIDTH (f
);
4182 if (!NILP (Vwindow_system
))
4186 #ifdef USE_X_TOOLKIT
4189 #endif /* USE_X_TOOLKIT */
4191 get_display_line (f
, vpos
, 0);
4193 items
= FRAME_MENU_BAR_ITEMS (f
);
4194 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4196 Lisp_Object pos
, string
;
4197 string
= XVECTOR (items
)->contents
[i
+ 1];
4201 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], hpos
);
4203 if (hpos
< maxendcol
)
4204 hpos
= display_string (w
, vpos
,
4205 XSTRING (string
)->data
,
4206 STRING_BYTES (XSTRING (string
)),
4207 hpos
, 0, 0, hpos
, maxendcol
,
4208 STRING_MULTIBYTE (string
));
4209 /* Put a space between items. */
4210 if (hpos
< maxendcol
)
4212 int hpos1
= hpos
+ 1;
4213 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
4214 min (hpos1
, maxendcol
), maxendcol
, 0);
4218 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4219 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4221 /* Fill out the line with spaces. */
4222 if (maxendcol
> hpos
)
4223 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
, 0);
4225 /* Clear the rest of the lines allocated to the menu bar. */
4227 while (vpos
< FRAME_MENU_BAR_LINES (f
))
4228 get_display_line (f
, vpos
++, 0);
4231 /* Display the mode line for window w */
4234 display_mode_line (w
)
4237 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
4238 register int left
= WINDOW_LEFT_MARGIN (w
);
4239 register int right
= WINDOW_RIGHT_MARGIN (w
);
4240 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4242 line_number_displayed
= 0;
4243 w
->column_number_displayed
= Qnil
;
4245 get_display_line (f
, vpos
, left
);
4247 /* Temporarily make frame F's kboard the current kboard
4248 so that kboard-local variables in the mode_line_format
4249 will get the right values. */
4250 push_frame_kboard (f
);
4252 display_mode_element (w
, vpos
, left
, 0, right
, right
,
4253 current_buffer
->mode_line_format
);
4255 pop_frame_kboard ();
4257 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4259 /* Put the mode line in inverse video.
4260 Use faces if possible, since that lets us handle
4261 partial-width windows and avoid inverting the scroll bar columns. */
4263 if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
4265 /* For a partial width window, explicitly set face of each glyph. */
4267 unsigned int padding
;
4268 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
4269 for (i
= left
; i
< right
; ++i
)
4271 padding
= ptr
[i
] & GLYPH_MASK_PADDING
;
4272 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1) | padding
;
4278 /* Make the mode line inverse video if the entire line
4279 is made of mode lines.
4280 I.e. if this window is full width,
4281 or if it is the child of a full width window
4282 (which implies that that window is split side-by-side
4283 and the rest of this line is mode lines of the sibling windows). */
4284 if (WINDOW_FULL_WIDTH_P (w
)
4285 || WINDOW_FULL_WIDTH_P (XWINDOW (w
->parent
)))
4286 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4289 /* Contribute ELT to the mode line for window W.
4290 How it translates into text depends on its data type.
4292 VPOS is the position of the mode line being displayed.
4294 HPOS is the position (absolute on frame) where this element's text
4295 should start. The output is truncated automatically at the right
4298 DEPTH is the depth in recursion. It is used to prevent
4299 infinite recursion here.
4301 MINENDCOL is the hpos before which the element may not end.
4302 The element is padded at the right with spaces if nec
4303 to reach this column.
4305 MAXENDCOL is the hpos past which this element may not extend.
4306 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
4307 (This is necessary to make nested padding and truncation work.)
4309 Returns the hpos of the end of the text generated by ELT.
4310 The next element will receive that value as its HPOS arg,
4311 so as to concatenate the elements. */
4314 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
4316 register int vpos
, hpos
;
4319 register int maxendcol
;
4320 register Lisp_Object elt
;
4328 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
4332 /* A string: output it and check for %-constructs within it. */
4333 register unsigned char c
;
4334 register unsigned char *this = XSTRING (elt
)->data
;
4336 while (hpos
< maxendcol
&& *this)
4338 unsigned char *last
= this;
4339 while ((c
= *this++) != '\0' && c
!= '%')
4341 if (this - 1 != last
)
4343 register int lim
= --this - last
+ hpos
;
4344 if (frame_title_ptr
)
4345 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
4347 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
4348 hpos
, min (lim
, maxendcol
),
4349 STRING_MULTIBYTE (elt
));
4353 register int minendcol
;
4354 register int spec_width
= 0;
4356 /* We can't allow -ve args due to the "%-" construct */
4357 /* Argument specifies minwidth but not maxwidth
4358 (maxwidth can be specified by
4359 (<negative-number> . <stuff>) mode-line elements) */
4361 while ((c
= *this++) >= '0' && c
<= '9')
4363 spec_width
= spec_width
* 10 + (c
- '0');
4366 minendcol
= hpos
+ spec_width
;
4367 if (minendcol
> maxendcol
)
4369 spec_width
= maxendcol
- hpos
;
4370 minendcol
= maxendcol
;
4374 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4375 spec_width
, maxendcol
,
4376 Vglobal_mode_string
);
4379 char *spec
= decode_mode_spec (w
, c
, spec_width
,
4381 if (frame_title_ptr
)
4382 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
4384 hpos
= display_string (w
, vpos
, spec
, -1,
4386 minendcol
, maxendcol
, -1);
4394 /* A symbol: process the value of the symbol recursively
4395 as if it appeared here directly. Avoid error if symbol void.
4396 Special case: if value of symbol is a string, output the string
4399 register Lisp_Object tem
;
4400 tem
= Fboundp (elt
);
4403 tem
= Fsymbol_value (elt
);
4404 /* If value is a string, output that string literally:
4405 don't check for % within it. */
4408 if (frame_title_ptr
)
4409 hpos
= store_frame_title (XSTRING (tem
)->data
,
4410 minendcol
, maxendcol
);
4412 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
4413 STRING_BYTES (XSTRING (tem
)),
4414 hpos
, 0, 1, minendcol
, maxendcol
,
4415 STRING_MULTIBYTE (tem
));
4417 /* Give up right away for nil or t. */
4418 else if (!EQ (tem
, elt
))
4419 { elt
= tem
; goto tail_recurse
; }
4426 register Lisp_Object car
, tem
;
4428 /* A cons cell: three distinct cases.
4429 If first element is a string or a cons, process all the elements
4430 and effectively concatenate them.
4431 If first element is a negative number, truncate displaying cdr to
4432 at most that many characters. If positive, pad (with spaces)
4433 to at least that many characters.
4434 If first element is a symbol, process the cadr or caddr recursively
4435 according to whether the symbol's value is non-nil or nil. */
4436 car
= XCONS (elt
)->car
;
4439 tem
= Fboundp (car
);
4440 elt
= XCONS (elt
)->cdr
;
4443 /* elt is now the cdr, and we know it is a cons cell.
4444 Use its car if CAR has a non-nil value. */
4447 tem
= Fsymbol_value (car
);
4449 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
4451 /* Symbol's value is nil (or symbol is unbound)
4452 Get the cddr of the original list
4453 and if possible find the caddr and use that. */
4454 elt
= XCONS (elt
)->cdr
;
4457 else if (!CONSP (elt
))
4459 elt
= XCONS (elt
)->car
;
4462 else if (INTEGERP (car
))
4464 register int lim
= XINT (car
);
4465 elt
= XCONS (elt
)->cdr
;
4467 /* Negative int means reduce maximum width.
4468 DO NOT change MINENDCOL here!
4469 (20 -10 . foo) should truncate foo to 10 col
4470 and then pad to 20. */
4471 maxendcol
= min (maxendcol
, hpos
- lim
);
4474 /* Padding specified. Don't let it be more than
4477 if (lim
> maxendcol
)
4479 /* If that's more padding than already wanted, queue it.
4480 But don't reduce padding already specified even if
4481 that is beyond the current truncation point. */
4482 if (lim
> minendcol
)
4487 else if (STRINGP (car
) || CONSP (car
))
4489 register int limit
= 50;
4490 /* LIMIT is to protect against circular lists. */
4491 while (CONSP (elt
) && --limit
> 0
4492 && hpos
< maxendcol
)
4494 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4497 elt
= XCONS (elt
)->cdr
;
4505 if (frame_title_ptr
)
4506 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
4508 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
4509 minendcol
, maxendcol
, 0);
4513 if (minendcol
> hpos
)
4514 if (frame_title_ptr
)
4515 hpos
= store_frame_title ("", minendcol
, maxendcol
);
4517 hpos
= display_string (w
, vpos
, "", 0, hpos
,
4518 0, 1, minendcol
, maxendcol
, 0);
4522 /* Write a null-terminated, right justified decimal representation of
4523 the positive integer D to BUF using a minimal field width WIDTH. */
4526 pint2str (buf
, width
, d
)
4531 register char *p
= buf
;
4538 *p
++ = d
% 10 + '0';
4541 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
4551 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4552 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4553 type of CODING_SYSTEM. Return updated pointer into BUF. */
4556 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
4557 Lisp_Object coding_system
;
4562 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
4564 val
= coding_system
;
4566 if (NILP (val
)) /* Not yet decided. */
4571 *buf
++ = eol_mnemonic_undecided
;
4572 /* Don't mention EOL conversion if it isn't decided. */
4576 Lisp_Object eolvalue
;
4578 eolvalue
= Fget (coding_system
, Qeol_type
);
4580 while (!NILP (val
) && SYMBOLP (val
))
4582 val
= Fget (val
, Qcoding_system
);
4583 if (NILP (eolvalue
))
4584 eolvalue
= Fget (val
, Qeol_type
);
4588 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
4592 /* The EOL conversion we are using. */
4594 /* The EOL conversion that is normal on this system. */
4596 if (NILP (eolvalue
)) /* Not yet decided. */
4597 eoltype
= eol_mnemonic_undecided
;
4598 else if (VECTORP (eolvalue
)) /* Not yet decided. */
4599 eoltype
= eol_mnemonic_undecided
;
4600 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4601 eoltype
= (XFASTINT (eolvalue
) == 0
4603 : (XFASTINT (eolvalue
) == 1
4604 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
4606 /* Mention the EOL conversion if it is not the usual one. */
4613 /* Return a string for the output of a mode line %-spec for window W,
4614 generated by character C. SPEC_WIDTH is the field width when
4615 padding to the left (%c, %l). The value returned from this
4616 function will later be truncated to width MAXWIDTH. */
4618 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4621 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
4624 register int spec_width
;
4625 register int maxwidth
;
4628 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4629 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
4630 struct buffer
*b
= XBUFFER (w
->buffer
);
4633 if (maxwidth
> FRAME_WIDTH (f
))
4634 maxwidth
= FRAME_WIDTH (f
);
4639 if (!NILP (b
->read_only
))
4641 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4646 /* This differs from %* only for a modified read-only buffer. */
4647 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4649 if (!NILP (b
->read_only
))
4654 /* This differs from %* in ignoring read-only-ness. */
4655 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4667 if (command_loop_level
> 5)
4669 p
= decode_mode_spec_buf
;
4670 for (i
= 0; i
< command_loop_level
; i
++)
4673 return decode_mode_spec_buf
;
4681 if (command_loop_level
> 5)
4683 p
= decode_mode_spec_buf
;
4684 for (i
= 0; i
< command_loop_level
; i
++)
4687 return decode_mode_spec_buf
;
4695 if (maxwidth
< sizeof (lots_of_dashes
))
4696 return lots_of_dashes
;
4699 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
4703 return decode_mode_spec_buf
;
4709 if (maxwidth
>= 3 && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4711 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
4712 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
4713 decode_mode_spec_buf
[maxwidth
] = '\0';
4714 return decode_mode_spec_buf
;
4721 int col
= current_column ();
4722 XSETFASTINT (w
->column_number_displayed
, col
);
4723 pint2str (decode_mode_spec_buf
, spec_width
, col
);
4724 return decode_mode_spec_buf
;
4728 /* %F displays the frame name. */
4729 /* Systems that can only display a single frame at a time should
4730 NOT replace the frame name with the (constant) frame title,
4731 since then they won't be able to tell which frame is that. */
4732 if (FRAME_WINDOW_P (f
) && !NILP (f
->title
))
4733 return (char *) XSTRING (f
->title
)->data
;
4734 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
4735 return (char *) XSTRING (f
->name
)->data
;
4743 else if (STRINGP (obj
) && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4745 bcopy ("...", decode_mode_spec_buf
, 3);
4746 bcopy (XSTRING (obj
)->data
+ STRING_BYTES (XSTRING (obj
)) - maxwidth
+ 3,
4747 decode_mode_spec_buf
+ 3, maxwidth
- 3);
4748 return decode_mode_spec_buf
;
4755 int startpos
= XMARKER (w
->start
)->charpos
;
4756 int startpos_byte
= marker_byte_position (w
->start
);
4757 int line
, linepos
, linepos_byte
, topline
;
4760 int height
= XFASTINT (w
->height
);
4762 /* If we decided that this buffer isn't suitable for line numbers,
4763 don't forget that too fast. */
4764 if (EQ (w
->base_line_pos
, w
->buffer
))
4766 /* But do forget it, if the window shows a different buffer now. */
4767 else if (BUFFERP (w
->base_line_pos
))
4768 w
->base_line_pos
= Qnil
;
4770 /* If the buffer is very big, don't waste time. */
4771 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
4773 w
->base_line_pos
= Qnil
;
4774 w
->base_line_number
= Qnil
;
4778 if (!NILP (w
->base_line_number
)
4779 && !NILP (w
->base_line_pos
)
4780 && XFASTINT (w
->base_line_pos
) <= startpos
)
4782 line
= XFASTINT (w
->base_line_number
);
4783 linepos
= XFASTINT (w
->base_line_pos
);
4784 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
4789 linepos
= BUF_BEGV (b
);
4790 linepos_byte
= BUF_BEGV_BYTE (b
);
4793 /* Count lines from base line to window start position. */
4794 nlines
= display_count_lines (linepos
, linepos_byte
,
4798 topline
= nlines
+ line
;
4800 /* Determine a new base line, if the old one is too close
4801 or too far away, or if we did not have one.
4802 "Too close" means it's plausible a scroll-down would
4804 if (startpos
== BUF_BEGV (b
))
4806 XSETFASTINT (w
->base_line_number
, topline
);
4807 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
4809 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
4810 || linepos
== BUF_BEGV (b
))
4812 int limit
= BUF_BEGV (b
);
4813 int limit_byte
= BUF_BEGV_BYTE (b
);
4815 int distance
= (height
* 2 + 30) * 200;
4817 if (startpos
- distance
> limit
)
4819 limit
= startpos
- distance
;
4820 limit_byte
= CHAR_TO_BYTE (limit
);
4823 nlines
= display_count_lines (startpos
, startpos_byte
,
4825 - (height
* 2 + 30),
4827 /* If we couldn't find the lines we wanted within
4829 give up on line numbers for this window. */
4830 if (position
== limit_byte
&& limit
== startpos
- distance
)
4832 w
->base_line_pos
= w
->buffer
;
4833 w
->base_line_number
= Qnil
;
4837 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
4838 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
4841 /* Now count lines from the start pos to point. */
4842 nlines
= display_count_lines (startpos
, startpos_byte
,
4843 PT_BYTE
, PT
, &junk
);
4845 /* Record that we did display the line number. */
4846 line_number_displayed
= 1;
4848 /* Make the string to show. */
4849 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
4850 return decode_mode_spec_buf
;
4853 char* p
= decode_mode_spec_buf
;
4854 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
4856 return decode_mode_spec_buf
;
4866 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
4872 int pos
= marker_position (w
->start
);
4873 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4875 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
4877 if (pos
<= BUF_BEGV (b
))
4882 else if (pos
<= BUF_BEGV (b
))
4886 if (total
> 1000000)
4887 /* Do it differently for a large value, to avoid overflow. */
4888 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4890 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4891 /* We can't normally display a 3-digit number,
4892 so get us a 2-digit number that is close. */
4895 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4896 return decode_mode_spec_buf
;
4900 /* Display percentage of size above the bottom of the screen. */
4903 int toppos
= marker_position (w
->start
);
4904 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
4905 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4907 if (botpos
>= BUF_ZV (b
))
4909 if (toppos
<= BUF_BEGV (b
))
4916 if (total
> 1000000)
4917 /* Do it differently for a large value, to avoid overflow. */
4918 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4920 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4921 /* We can't normally display a 3-digit number,
4922 so get us a 2-digit number that is close. */
4925 if (toppos
<= BUF_BEGV (b
))
4926 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
4928 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4929 return decode_mode_spec_buf
;
4934 /* status of process */
4935 obj
= Fget_buffer_process (w
->buffer
);
4937 return "no process";
4939 obj
= Fsymbol_name (Fprocess_status (obj
));
4943 case 't': /* indicate TEXT or BINARY */
4944 #ifdef MODE_LINE_BINARY_TEXT
4945 return MODE_LINE_BINARY_TEXT (b
);
4951 /* coding-system (not including end-of-line format) */
4953 /* coding-system (including end-of-line type) */
4955 int eol_flag
= (c
== 'Z');
4956 char *p
= decode_mode_spec_buf
;
4958 if (! FRAME_WINDOW_P (f
))
4960 /* No need to mention EOL here--the terminal never needs
4961 to do EOL conversion. */
4962 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
4963 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
4965 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
4968 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
4970 obj
= Fget_buffer_process (Fcurrent_buffer ());
4973 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
4975 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
4978 #endif /* subprocesses */
4981 return decode_mode_spec_buf
;
4986 return (char *) XSTRING (obj
)->data
;
4991 /* Count up to COUNT lines starting from START / START_BYTE.
4992 But don't go beyond LIMIT_BYTE.
4993 Return the number of lines thus found (always nonnegative).
4995 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
4998 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
4999 int start
, start_byte
, limit_byte
, count
;
5002 register unsigned char *cursor
;
5003 unsigned char *base
;
5005 register int ceiling
;
5006 register unsigned char *ceiling_addr
;
5007 int orig_count
= count
;
5009 /* If we are not in selective display mode,
5010 check only for newlines. */
5011 int selective_display
= (!NILP (current_buffer
->selective_display
)
5012 && !INTEGERP (current_buffer
->selective_display
));
5016 while (start_byte
< limit_byte
)
5018 ceiling
= BUFFER_CEILING_OF (start_byte
);
5019 ceiling
= min (limit_byte
- 1, ceiling
);
5020 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
5021 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
5024 if (selective_display
)
5025 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
5028 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
5031 if (cursor
!= ceiling_addr
)
5035 start_byte
+= cursor
- base
+ 1;
5036 *byte_pos_ptr
= start_byte
;
5040 if (++cursor
== ceiling_addr
)
5046 start_byte
+= cursor
- base
;
5051 while (start_byte
> limit_byte
)
5053 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
5054 ceiling
= max (limit_byte
, ceiling
);
5055 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
5056 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
5059 if (selective_display
)
5060 while (--cursor
!= ceiling_addr
5061 && *cursor
!= '\n' && *cursor
!= 015)
5064 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
5067 if (cursor
!= ceiling_addr
)
5071 start_byte
+= cursor
- base
+ 1;
5072 *byte_pos_ptr
= start_byte
;
5073 /* When scanning backwards, we should
5074 not count the newline posterior to which we stop. */
5075 return - orig_count
- 1;
5081 /* Here we add 1 to compensate for the last decrement
5082 of CURSOR, which took it past the valid range. */
5083 start_byte
+= cursor
- base
+ 1;
5087 *byte_pos_ptr
= limit_byte
;
5090 return - orig_count
+ count
;
5091 return orig_count
- count
;
5095 /* Display STRING on one line of window W, starting at HPOS.
5096 Display at position VPOS. Caller should have done get_display_line.
5097 If VPOS == -1, display it as the current frame's title.
5098 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
5100 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
5102 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
5103 MAXCOL is the last column ok to end at. Truncate here.
5104 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
5105 Both count from the left edge of the frame, as does HPOS.
5106 The right edge of W is an implicit maximum.
5107 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
5109 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
5110 at the place where the current window ends in this line
5111 and not display anything beyond there. Otherwise, only MAXCOL
5112 controls where to stop output.
5114 MULTIBYTE can be 0 meaning do not display multibyte chars,
5115 1 meaning do display them, or -1 meaning obey the current buffer's
5116 value of enable_multibyte_characters.
5118 Returns ending hpos. */
5121 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
5122 obey_window_width
, mincol
, maxcol
, multibyte
)
5124 unsigned char *string
;
5128 int obey_window_width
;
5135 int hscroll
= XINT (w
->hscroll
);
5136 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
5137 register GLYPH
*start
;
5138 register GLYPH
*end
;
5139 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
5140 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
5141 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
5142 int window_width
= XFASTINT (w
->width
);
5144 /* Use the standard display table, not the window's display table.
5145 We don't want the mode line in rot13. */
5146 register struct Lisp_Char_Table
*dp
= 0;
5149 if (multibyte
== -1)
5150 multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
5151 /* Now multibyte is 1 if we should display multibyte characters. */
5153 if (DISP_TABLE_P (Vstandard_display_table
))
5154 dp
= XCHAR_TABLE (Vstandard_display_table
);
5156 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
5159 start
= desired_glyphs
->glyphs
[vpos
];
5161 if (obey_window_width
)
5163 start
+= XFASTINT (w
->left
);
5164 end
= start
+ window_width
- (truncate
!= 0);
5166 if (!WINDOW_RIGHTMOST_P (w
))
5168 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5172 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
5175 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5180 if (! obey_window_width
5181 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
5182 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
5184 /* Store 0 in charstart for these columns. */
5185 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
5186 desired_glyphs
->charstarts
[vpos
][i
] = 0;
5188 if (maxcol
>= 0 && mincol
> maxcol
)
5192 /* We need this value for multibyte characters. */
5193 length
= strlen (string
);
5195 /* We set truncated to 1 if we get stopped by trying to pass END
5196 (that is, trying to pass MAXCOL.) */
5205 c
= STRING_CHAR_AND_LENGTH (string
, length
, len
);
5207 c
= *string
, len
= 1;
5209 string
+= len
, length
-= len
;
5217 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
5219 p1
= copy_part_of_rope (f
, p1
, start
,
5220 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
5221 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
5224 else if (c
>= 040 && c
< 0177)
5234 if (p1
>= start
&& p1
< end
)
5238 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
5240 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
5244 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
5245 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
5246 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
5249 if (p1
>= start
&& p1
< end
)
5255 /* C is a multibyte character, control character or a binary
5257 int remaining_bytes
= len
;
5259 if (c
>= 0400 && CHAR_VALID_P (c
, 0))
5261 /* C is a multibyte character. */
5262 int charset
= CHAR_CHARSET (c
);
5263 int columns
= (charset
== CHARSET_COMPOSITION
5264 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
5265 : CHARSET_WIDTH (charset
));
5267 remaining_bytes
-= CHARSET_BYTES (charset
);
5270 /* Since we can't show the left part of C, fill all
5271 columns with spaces. */
5272 columns
-= start
- p1
;
5281 else if (p1
+ columns
> end
)
5283 /* Since we can't show the right part of C, fill all
5284 columns with TRUNCATE if TRUNCATE is specified. */
5288 *p1
++ = fix_glyph (f
, truncate
, 0);
5289 /* And tell the line is truncated. */
5296 /* We can show the whole glyph of C. */
5299 *p1
++ = c
| GLYPH_MASK_PADDING
;
5303 while (remaining_bytes
> 0)
5305 c
= *(string
- remaining_bytes
--);
5309 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
5310 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
5311 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
5314 if (p1
>= start
&& p1
< end
)
5315 *p1
= (c
>> 6) + '0';
5317 if (p1
>= start
&& p1
< end
)
5318 *p1
= (7 & (c
>> 3)) + '0';
5320 if (p1
>= start
&& p1
< end
)
5321 *p1
= (7 & c
) + '0';
5330 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
5332 else if (mincol
>= 0)
5334 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
5340 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
5342 if (len
> desired_glyphs
->used
[vpos
])
5343 desired_glyphs
->used
[vpos
] = len
;
5344 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
5350 /* This is like a combination of memq and assq.
5351 Return 1 if PROPVAL appears as an element of LIST
5352 or as the car of an element of LIST.
5353 If PROPVAL is a list, compare each element against LIST
5354 in that way, and return 1 if any element of PROPVAL is found in LIST.
5356 This function cannot quit. */
5359 invisible_p (propval
, list
)
5360 register Lisp_Object propval
;
5363 register Lisp_Object tail
, proptail
;
5364 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5366 register Lisp_Object tem
;
5367 tem
= XCONS (tail
)->car
;
5368 if (EQ (propval
, tem
))
5370 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5373 if (CONSP (propval
))
5374 for (proptail
= propval
; CONSP (proptail
);
5375 proptail
= XCONS (proptail
)->cdr
)
5377 Lisp_Object propelt
;
5378 propelt
= XCONS (proptail
)->car
;
5379 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5381 register Lisp_Object tem
;
5382 tem
= XCONS (tail
)->car
;
5383 if (EQ (propelt
, tem
))
5385 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5392 /* Return 1 if PROPVAL appears as the car of an element of LIST
5393 and the cdr of that element is non-nil.
5394 If PROPVAL is a list, check each element of PROPVAL in that way,
5395 and the first time some element is found,
5396 return 1 if the cdr of that element is non-nil.
5398 This function cannot quit. */
5401 invisible_ellipsis_p (propval
, list
)
5402 register Lisp_Object propval
;
5405 register Lisp_Object tail
, proptail
;
5406 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5408 register Lisp_Object tem
;
5409 tem
= XCONS (tail
)->car
;
5410 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5411 return ! NILP (XCONS (tem
)->cdr
);
5413 if (CONSP (propval
))
5414 for (proptail
= propval
; CONSP (proptail
);
5415 proptail
= XCONS (proptail
)->cdr
)
5417 Lisp_Object propelt
;
5418 propelt
= XCONS (proptail
)->car
;
5419 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5421 register Lisp_Object tem
;
5422 tem
= XCONS (tail
)->car
;
5423 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5424 return ! NILP (XCONS (tem
)->cdr
);
5433 staticpro (&Qinhibit_redisplay
);
5434 Qinhibit_redisplay
= intern ("inhibit-redisplay");
5436 staticpro (&Qmenu_bar_update_hook
);
5437 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
5439 staticpro (&Qoverriding_terminal_local_map
);
5440 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
5442 staticpro (&Qoverriding_local_map
);
5443 Qoverriding_local_map
= intern ("overriding-local-map");
5445 staticpro (&Qwindow_scroll_functions
);
5446 Qwindow_scroll_functions
= intern ("window-scroll-functions");
5448 staticpro (&Qredisplay_end_trigger_functions
);
5449 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
5451 staticpro (&Qinhibit_point_motion_hooks
);
5452 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
5454 staticpro (&last_arrow_position
);
5455 staticpro (&last_arrow_string
);
5456 last_arrow_position
= Qnil
;
5457 last_arrow_string
= Qnil
;
5459 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
5460 "Non-nil means don't actually do any redisplay.\n\
5461 This is used for internal purposes.");
5462 Vinhibit_redisplay
= Qnil
;
5464 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
5465 "String (or mode line construct) included (normally) in `mode-line-format'.");
5466 Vglobal_mode_string
= Qnil
;
5468 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
5469 "Marker for where to display an arrow on top of the buffer text.\n\
5470 This must be the beginning of a line in order to work.\n\
5471 See also `overlay-arrow-string'.");
5472 Voverlay_arrow_position
= Qnil
;
5474 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
5475 "String to display as an arrow. See also `overlay-arrow-position'.");
5476 Voverlay_arrow_string
= Qnil
;
5478 DEFVAR_INT ("scroll-step", &scroll_step
,
5479 "*The number of lines to try scrolling a window by when point moves out.\n\
5480 If that fails to bring point back on frame, point is centered instead.\n\
5481 If this is zero, point is always centered after it moves off frame.");
5483 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
5484 "*Scroll up to this many lines, to bring point back on screen.");
5485 scroll_conservatively
= 0;
5487 DEFVAR_INT ("scroll-margin", &scroll_margin
,
5488 "*Number of lines of margin at the top and bottom of a window.\n\
5489 Recenter the window whenever point gets within this many lines\n\
5490 of the top or bottom of the window.");
5493 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
5495 DEFVAR_BOOL ("truncate-partial-width-windows",
5496 &truncate_partial_width_windows
,
5497 "*Non-nil means truncate lines in all windows less than full frame wide.");
5498 truncate_partial_width_windows
= 1;
5500 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
5501 "*Non-nil means use inverse video for the mode line.");
5502 mode_line_inverse_video
= 1;
5504 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
5505 "*Maximum buffer size (in characters) for line number display\n\
5506 If the buffer is bigger than this, the line number does not appear\n\
5507 in the mode line..");
5508 line_number_display_limit
= 1000000;
5510 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
5511 "*Non-nil means highlight region even in nonselected windows.");
5512 highlight_nonselected_windows
= 0;
5514 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
5515 "Non-nil if more than one frame is visible on this display.\n\
5516 Minibuffer-only frames don't count, but iconified frames do.\n\
5517 This variable is not guaranteed to be accurate except while processing\n\
5518 `frame-title-format' and `icon-title-format'.");
5520 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
5521 "Template for displaying the titlebar of visible frames.\n\
5522 \(Assuming the window manager supports this feature.)\n\
5523 This variable has the same structure as `mode-line-format' (which see),\n\
5524 and is used only on frames for which no explicit name has been set\n\
5525 \(see `modify-frame-parameters').");
5526 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
5527 "Template for displaying the titlebar of an iconified frame.\n\
5528 \(Assuming the window manager supports this feature.)\n\
5529 This variable has the same structure as `mode-line-format' (which see),\n\
5530 and is used only on frames for which no explicit name has been set\n\
5531 \(see `modify-frame-parameters').");
5533 = Vframe_title_format
5534 = Fcons (intern ("multiple-frames"),
5535 Fcons (build_string ("%b"),
5536 Fcons (Fcons (build_string (""),
5537 Fcons (intern ("invocation-name"),
5538 Fcons (build_string ("@"),
5539 Fcons (intern ("system-name"),
5543 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
5544 "Maximum number of lines to keep in the message log buffer.\n\
5545 If nil, disable message logging. If t, log messages but don't truncate\n\
5546 the buffer when it becomes large.");
5547 XSETFASTINT (Vmessage_log_max
, 50);
5549 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
5550 "Functions called before redisplay, if window sizes have changed.\n\
5551 The value should be a list of functions that take one argument.\n\
5552 Just before redisplay, for each frame, if any of its windows have changed\n\
5553 size since the last redisplay, or have been split or deleted,\n\
5554 all the functions in the list are called, with the frame as argument.");
5555 Vwindow_size_change_functions
= Qnil
;
5557 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
5558 "List of functions to call before redisplaying a window with scrolling.\n\
5559 Each function is called with two arguments, the window\n\
5560 and its new display-start position. Note that the value of `window-end'\n\
5561 is not valid when these functions are called.");
5562 Vwindow_scroll_functions
= Qnil
;
5564 DEFVAR_INT ("minibuffer-scroll-overlap", &minibuffer_scroll_overlap
,
5565 "*Number of characters of overlap when scrolling a one-line window.\n\
5566 This commonly affects the minibuffer window, hence the name of the variable.");
5567 minibuffer_scroll_overlap
= 20;
5570 /* initialize the window system */
5574 Lisp_Object root_window
;
5575 #ifndef COMPILER_REGISTER_BUG
5577 #endif /* COMPILER_REGISTER_BUG */
5578 struct window
*mini_w
;
5580 this_line_bufpos
= 0;
5582 mini_w
= XWINDOW (minibuf_window
);
5583 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
5585 echo_area_glyphs
= 0;
5586 previous_echo_glyphs
= 0;
5588 if (!noninteractive
)
5590 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
5591 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_MENU_BAR_LINES (f
));
5592 set_window_height (root_window
,
5593 FRAME_HEIGHT (f
) - 1 - FRAME_MENU_BAR_LINES (f
),
5595 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
5596 set_window_height (minibuf_window
, 1, 0);
5598 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
5599 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));