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 /* Nonzero means print newline to stdout before next minibuffer message. */
71 int noninteractive_need_newline
;
73 /* Nonzero means print newline to message log before next message. */
75 static int message_log_need_newline
;
77 #define min(a, b) ((a) < (b) ? (a) : (b))
78 #define max(a, b) ((a) > (b) ? (a) : (b))
79 #define minmax(floor, val, ceil) \
80 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
82 /* The buffer position of the first character appearing
83 entirely or partially on the current frame line.
84 Or zero, which disables the optimization for the current frame line. */
85 static int this_line_bufpos
;
87 /* Number of characters past the end of this line,
88 including the terminating newline */
89 static int this_line_endpos
;
91 /* The vertical position of this frame line. */
92 static int this_line_vpos
;
94 /* Hpos value for start of display on this frame line.
95 Usually zero, but negative if first character really began
97 static int this_line_start_hpos
;
99 /* Buffer that this_line variables are describing. */
100 static struct buffer
*this_line_buffer
;
102 /* Value of echo_area_glyphs when it was last acted on.
103 If this is nonzero, there is a message on the frame
104 in the minibuffer and it should be erased as soon
105 as it is no longer requested to appear. */
106 char *previous_echo_glyphs
;
108 /* Nonzero means truncate lines in all windows less wide than the frame */
109 int truncate_partial_width_windows
;
111 /* Nonzero means we have more than one non-minibuffer-only frame.
112 Not guaranteed to be accurate except while parsing frame-title-format. */
115 Lisp_Object Vglobal_mode_string
;
117 /* Marker for where to display an arrow on top of the buffer text. */
118 Lisp_Object Voverlay_arrow_position
;
120 /* String to display for the arrow. */
121 Lisp_Object Voverlay_arrow_string
;
123 /* Values of those variables at last redisplay.
124 However, if Voverlay_arrow_position is a marker,
125 last_arrow_position is its numerical position. */
126 static Lisp_Object last_arrow_position
, last_arrow_string
;
128 /* Like mode-line-format, but for the titlebar on a visible frame. */
129 Lisp_Object Vframe_title_format
;
131 /* Like mode-line-format, but for the titlebar on an iconified frame. */
132 Lisp_Object Vicon_title_format
;
134 /* List of functions to call when a window's size changes. These
135 functions get one arg, a frame on which one or more windows' sizes
137 static Lisp_Object Vwindow_size_change_functions
;
139 Lisp_Object Qmenu_bar_update_hook
;
141 /* Nonzero if overlay arrow has been displayed once in this window. */
142 static int overlay_arrow_seen
;
144 /* Nonzero if visible end of buffer has already been displayed once
145 in this window. (We need this variable in case there are overlay
146 strings that get displayed there.) */
147 static int zv_strings_seen
;
149 /* Nonzero means highlight the region even in nonselected windows. */
150 static int highlight_nonselected_windows
;
152 /* If cursor motion alone moves point off frame,
153 Try scrolling this many lines up or down if that will bring it back. */
154 static int scroll_step
;
156 /* Non-0 means scroll just far enough to bring point back on the screen,
158 static int scroll_conservatively
;
160 /* Recenter the window whenever point gets within this many lines
161 of the top or bottom of the window. */
164 /* Number of characters of overlap to show,
165 when scrolling a one-line window such as a minibuffer. */
166 static int minibuffer_scroll_overlap
;
168 /* Nonzero if try_window_id has made blank lines at window bottom
169 since the last redisplay that paused */
170 static int blank_end_of_window
;
172 /* Number of windows showing the buffer of the selected window
173 (or another buffer with the same base buffer).
174 keyboard.c refers to this. */
177 /* display_text_line sets these to the frame position (origin 0) of point,
178 whether the window is selected or not.
179 Set one to -1 first to determine whether point was found afterwards. */
181 static int cursor_vpos
;
182 static int cursor_hpos
;
184 static int debug_end_pos
;
186 /* Nonzero means display mode line highlighted */
187 int mode_line_inverse_video
;
189 static void redisplay_internal ();
190 static int message_log_check_duplicate ();
191 static void echo_area_display ();
192 void mark_window_display_accurate ();
193 static void redisplay_windows ();
194 static void redisplay_window ();
195 static void update_menu_bar ();
196 static void try_window ();
197 static int try_window_id ();
198 static struct position
*display_text_line ();
199 static void display_mode_line ();
200 static int display_mode_element ();
201 static char *decode_mode_spec ();
202 static int display_string ();
203 static void display_menu_bar ();
204 static int display_count_lines ();
206 /* Prompt to display in front of the minibuffer contents */
207 Lisp_Object minibuf_prompt
;
209 /* Width in columns of current minibuffer prompt. */
210 int minibuf_prompt_width
;
212 /* Message to display instead of minibuffer contents
213 This is what the functions error and message make,
214 and command echoing uses it as well.
215 It overrides the minibuf_prompt as well as the buffer. */
216 char *echo_area_glyphs
;
218 /* This is the length of the message in echo_area_glyphs. */
219 int echo_area_glyphs_length
;
221 /* This is the window where the echo area message was displayed.
222 It is always a minibuffer window, but it may not be the
223 same window currently active as a minibuffer. */
224 Lisp_Object echo_area_window
;
226 /* Nonzero means multibyte characters were enabled when the echo area
227 message was specified. */
228 int message_enable_multibyte
;
230 /* true iff we should redraw the mode lines on the next redisplay */
231 int update_mode_lines
;
233 /* Smallest number of characters before the gap
234 at any time since last redisplay that finished.
235 Valid for current buffer when try_window_id can be called. */
238 /* Smallest number of characters after the gap
239 at any time since last redisplay that finished.
240 Valid for current buffer when try_window_id can be called. */
243 /* MODIFF as of last redisplay that finished;
244 if it matches MODIFF, and overlay_unchanged_modified
245 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
246 contain no useful information */
247 int unchanged_modified
;
249 /* OVERLAY_MODIFF as of last redisplay that finished. */
250 int overlay_unchanged_modified
;
252 /* Nonzero if window sizes or contents have changed
253 since last redisplay that finished */
254 int windows_or_buffers_changed
;
256 /* Nonzero after display_mode_line if %l was used
257 and it displayed a line number. */
258 int line_number_displayed
;
260 /* Maximum buffer size for which to display line numbers. */
261 static int line_number_display_limit
;
263 /* Number of lines to keep in the message log buffer.
264 t means infinite. nil means don't log at all. */
265 Lisp_Object Vmessage_log_max
;
267 #define COERCE_MARKER(X) \
268 (MARKERP ((X)) ? Fmarker_position (X) : (X))
270 static int pos_tab_offset
P_ ((struct window
*, int, int));
272 /* Output a newline in the *Messages* buffer if "needs" one. */
275 message_log_maybe_newline ()
277 if (message_log_need_newline
)
278 message_dolog ("", 0, 1, 0);
282 /* Add a string to the message log, optionally terminated with a newline.
283 This function calls low-level routines in order to bypass text property
284 hooks, etc. which might not be safe to run.
285 MULTIBYTE, if nonzero, means interpret the contents of M as multibyte. */
288 message_dolog (m
, len
, nlflag
, multibyte
)
290 int len
, nlflag
, multibyte
;
292 if (!NILP (Vmessage_log_max
))
294 struct buffer
*oldbuf
;
295 Lisp_Object oldpoint
, oldbegv
, oldzv
;
296 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
297 int point_at_end
= 0;
299 Lisp_Object old_deactivate_mark
, tem
;
300 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
302 old_deactivate_mark
= Vdeactivate_mark
;
303 oldbuf
= current_buffer
;
304 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
305 current_buffer
->undo_list
= Qt
;
307 oldpoint
= Fpoint_marker ();
308 oldbegv
= Fpoint_min_marker ();
309 oldzv
= Fpoint_max_marker ();
310 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
318 BEGV_BYTE
= BEG_BYTE
;
321 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
323 /* Insert the string--maybe converting multibyte to single byte
324 or vice versa, so that all the text fits the buffer. */
326 && NILP (current_buffer
->enable_multibyte_characters
))
328 int c
, i
= 0, nbytes
;
329 /* Convert a multibyte string to single-byte
330 for the *Message* buffer. */
333 c
= STRING_CHAR (m
+ i
, len
- i
);
334 i
+= XFASTINT (Fchar_bytes (make_number (c
)));
335 /* Truncate the character to its last byte--we can only hope
336 the user is happy with the character he gets,
337 since if it isn't right, there is no way to do it right. */
343 && ! NILP (current_buffer
->enable_multibyte_characters
))
346 unsigned char *msg
= (unsigned char *) m
;
347 /* Convert a single-byte string to multibyte
348 for the *Message* buffer. */
351 int c
= unibyte_char_to_multibyte (msg
[i
++]);
356 insert_1 (m
, len
, 1, 0, 0);
360 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
361 insert_1 ("\n", 1, 1, 0, 0);
363 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
365 this_bol_byte
= PT_BYTE
;
369 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
371 prev_bol_byte
= PT_BYTE
;
373 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
374 this_bol
, this_bol_byte
);
377 del_range_both (prev_bol
, prev_bol_byte
,
378 this_bol
, this_bol_byte
, 0);
384 /* If you change this format, don't forget to also
385 change message_log_check_duplicate. */
386 sprintf (dupstr
, " [%d times]", dup
);
387 duplen
= strlen (dupstr
);
388 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
389 insert_1 (dupstr
, duplen
, 1, 0, 1);
394 if (NATNUMP (Vmessage_log_max
))
396 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
397 -XFASTINT (Vmessage_log_max
) - 1, 0);
398 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
401 BEGV
= XMARKER (oldbegv
)->charpos
;
402 BEGV_BYTE
= marker_byte_position (oldbegv
);
411 ZV
= XMARKER (oldzv
)->charpos
;
412 ZV_BYTE
= marker_byte_position (oldzv
);
416 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
418 Fgoto_char (oldpoint
);
421 free_marker (oldpoint
);
422 free_marker (oldbegv
);
425 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
426 set_buffer_internal (oldbuf
);
428 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
429 message_log_need_newline
= !nlflag
;
430 Vdeactivate_mark
= old_deactivate_mark
;
434 /* We are at the end of the buffer after just having inserted a newline.
435 (Note: We depend on the fact we won't be crossing the gap.)
436 Check to see if the most recent message looks a lot like the previous one.
437 Return 0 if different, 1 if the new one should just replace it, or a
438 value N > 1 if we should also append " [N times]". */
441 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
442 int prev_bol
, this_bol
;
443 int prev_bol_byte
, this_bol_byte
;
446 int len
= Z
- 1 - this_bol
;
448 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
449 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
451 for (i
= 0; i
< len
; i
++)
453 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
462 if (*p1
++ == ' ' && *p1
++ == '[')
465 while (*p1
>= '0' && *p1
<= '9')
466 n
= n
* 10 + *p1
++ - '0';
467 if (strncmp (p1
, " times]\n", 8) == 0)
473 /* Display an echo area message M with a specified length of LEN chars.
474 The string may include null characters. If M is 0, clear out any
475 existing message, and let the minibuffer text show through.
477 The buffer M must continue to exist until after the echo area
478 gets cleared or some other message gets displayed there.
480 Do not pass text that is stored in a Lisp string.
481 Do not pass text in a buffer that was alloca'd. */
484 message2 (m
, len
, multibyte
)
489 /* First flush out any partial line written with print. */
490 message_log_maybe_newline ();
492 message_dolog (m
, len
, 1, multibyte
);
493 message2_nolog (m
, len
, multibyte
);
497 /* The non-logging counterpart of message2. */
500 message2_nolog (m
, len
, multibyte
)
504 message_enable_multibyte
= multibyte
;
508 if (noninteractive_need_newline
)
510 noninteractive_need_newline
= 0;
512 fwrite (m
, len
, 1, stderr
);
513 if (cursor_in_echo_area
== 0)
514 fprintf (stderr
, "\n");
517 /* A null message buffer means that the frame hasn't really been
518 initialized yet. Error messages get reported properly by
519 cmd_error, so this must be just an informative message; toss it. */
520 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
522 Lisp_Object mini_window
;
525 /* Get the frame containing the minibuffer
526 that the selected frame is using. */
527 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
528 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
530 FRAME_SAMPLE_VISIBILITY (f
);
531 if (FRAME_VISIBLE_P (selected_frame
)
532 && ! FRAME_VISIBLE_P (f
))
533 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
537 echo_area_glyphs
= m
;
538 echo_area_glyphs_length
= len
;
540 if (minibuffer_auto_raise
)
541 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
544 echo_area_glyphs
= previous_echo_glyphs
= 0;
546 do_pending_window_change ();
547 echo_area_display ();
548 update_frame (f
, 1, 1);
549 do_pending_window_change ();
550 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
551 (*frame_up_to_date_hook
) (f
);
555 /* Display in echo area the null-terminated ASCII-only string M.
556 If M is 0, clear out any existing message,
557 and let the minibuffer text show through.
559 The string M must continue to exist until after the echo area
560 gets cleared or some other message gets displayed there.
562 Do not pass text that is stored in a Lisp string.
563 Do not pass text in a buffer that was alloca'd. */
569 message2 (m
, (m
? strlen (m
) : 0), 0);
576 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
579 /* Display a message M which contains a single %s
580 which gets replaced with STRING. */
583 message_with_string (m
, string
, log
)
592 if (noninteractive_need_newline
)
594 noninteractive_need_newline
= 0;
595 fprintf (stderr
, m
, XSTRING (string
)->data
);
596 if (cursor_in_echo_area
== 0)
597 fprintf (stderr
, "\n");
601 else if (INTERACTIVE
)
603 /* The frame whose minibuffer we're going to display the message on.
604 It may be larger than the selected frame, so we need
605 to use its buffer, not the selected frame's buffer. */
606 Lisp_Object mini_window
;
609 /* Get the frame containing the minibuffer
610 that the selected frame is using. */
611 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
612 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
614 /* A null message buffer means that the frame hasn't really been
615 initialized yet. Error messages get reported properly by
616 cmd_error, so this must be just an informative message; toss it. */
617 if (FRAME_MESSAGE_BUF (f
))
621 a
[0] = (char *) XSTRING (string
)->data
;
623 len
= doprnt (FRAME_MESSAGE_BUF (f
),
624 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
627 message2 (FRAME_MESSAGE_BUF (f
), len
,
628 STRING_MULTIBYTE (string
));
630 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
631 STRING_MULTIBYTE (string
));
633 /* Print should start at the beginning of the message
635 message_buf_print
= 0;
640 /* Truncate what will be displayed in the echo area
641 the next time we display it--but don't redisplay it now. */
644 truncate_echo_area (len
)
647 /* A null message buffer means that the frame hasn't really been
648 initialized yet. Error messages get reported properly by
649 cmd_error, so this must be just an informative message; toss it. */
650 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
651 echo_area_glyphs_length
= len
;
654 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
655 zero if being used by message. */
656 int message_buf_print
;
658 /* Dump an informative message to the minibuf. If M is 0, clear out
659 any existing message, and let the minibuffer text show through. */
663 message (m
, a1
, a2
, a3
)
665 EMACS_INT a1
, a2
, a3
;
671 if (noninteractive_need_newline
)
673 noninteractive_need_newline
= 0;
674 fprintf (stderr
, m
, a1
, a2
, a3
);
675 if (cursor_in_echo_area
== 0)
676 fprintf (stderr
, "\n");
680 else if (INTERACTIVE
)
682 /* The frame whose minibuffer we're going to display the message on.
683 It may be larger than the selected frame, so we need
684 to use its buffer, not the selected frame's buffer. */
685 Lisp_Object mini_window
;
688 /* Get the frame containing the minibuffer
689 that the selected frame is using. */
690 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
691 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
693 /* A null message buffer means that the frame hasn't really been
694 initialized yet. Error messages get reported properly by
695 cmd_error, so this must be just an informative message; toss it. */
696 if (FRAME_MESSAGE_BUF (f
))
707 len
= doprnt (FRAME_MESSAGE_BUF (f
),
708 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
710 len
= doprnt (FRAME_MESSAGE_BUF (f
),
711 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
713 #endif /* NO_ARG_ARRAY */
715 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
720 /* Print should start at the beginning of the message
722 message_buf_print
= 0;
727 /* The non-logging version of message. */
729 message_nolog (m
, a1
, a2
, a3
)
731 EMACS_INT a1
, a2
, a3
;
733 Lisp_Object old_log_max
;
734 old_log_max
= Vmessage_log_max
;
735 Vmessage_log_max
= Qnil
;
736 message (m
, a1
, a2
, a3
);
737 Vmessage_log_max
= old_log_max
;
743 message2 (echo_area_glyphs
, echo_area_glyphs_length
,
744 ! NILP (current_buffer
->enable_multibyte_characters
));
752 Lisp_Object mini_window
;
754 /* Choose the minibuffer window for this display.
755 It is the minibuffer window used by the selected frame. */
756 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
757 /* This is the frame that window is in. */
758 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
760 if (! FRAME_VISIBLE_P (f
))
765 redraw_garbaged_frames ();
769 if (echo_area_glyphs
|| minibuf_level
== 0)
773 echo_area_window
= mini_window
;
775 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
776 get_display_line (f
, vpos
, 0);
778 /* Make sure the columns that overlap a left-hand scroll bar
780 for (i
= 0; i
< FRAME_LEFT_SCROLL_BAR_WIDTH (f
); i
++)
781 f
->desired_glyphs
->glyphs
[vpos
][i
] = SPACEGLYPH
;
783 display_string (XWINDOW (mini_window
), vpos
,
784 echo_area_glyphs
? echo_area_glyphs
: "",
785 echo_area_glyphs
? echo_area_glyphs_length
: -1,
786 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
788 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
789 message_enable_multibyte
);
791 #if 0 /* This just gets in the way. update_frame does the job. */
792 /* If desired cursor location is on this line, put it at end of text */
793 if (cursor_in_echo_area
)
794 FRAME_CURSOR_Y (f
) = vpos
;
795 if (FRAME_CURSOR_Y (f
) == vpos
)
796 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
799 /* Fill the rest of the minibuffer window with blank lines. */
804 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
806 get_display_line (f
, i
, 0);
807 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
808 hpos, because it is good to clear whatever is behind the
809 scroll bar. This does not affect the scroll bar itself. */
810 display_string (XWINDOW (mini_window
), i
,
813 0, FRAME_WIDTH (f
) + FRAME_SCROLL_BAR_WIDTH (f
),
818 else if (!EQ (mini_window
, selected_window
))
819 windows_or_buffers_changed
++;
821 if (EQ (mini_window
, selected_window
))
822 this_line_bufpos
= 0;
824 previous_echo_glyphs
= echo_area_glyphs
;
827 /* Update frame titles. */
829 #ifdef HAVE_WINDOW_SYSTEM
830 static char frame_title_buf
[512];
831 static char *frame_title_ptr
;
834 store_frame_title (str
, mincol
, maxcol
)
839 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
840 maxcol
= sizeof (frame_title_buf
);
841 limit
= &frame_title_buf
[maxcol
];
842 while (*str
!= '\0' && frame_title_ptr
< limit
)
843 *frame_title_ptr
++ = *str
++;
844 while (frame_title_ptr
< &frame_title_buf
[mincol
])
845 *frame_title_ptr
++ = ' ';
846 return frame_title_ptr
- frame_title_buf
;
850 x_consider_frame_title (frame
)
856 FRAME_PTR f
= XFRAME (frame
);
858 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
861 /* Do we have more than one visible frame on this X display? */
865 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
867 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
869 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
870 && !FRAME_MINIBUF_ONLY_P (tf
)
871 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
875 multiple_frames
= CONSP (tail
);
878 obuf
= current_buffer
;
879 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
880 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
881 frame_title_ptr
= frame_title_buf
;
882 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
883 0, sizeof (frame_title_buf
), fmt
);
885 set_buffer_internal (obuf
);
886 /* Set the name only if it's changed. This avoids consing
887 in the common case where it hasn't. (If it turns out that we've
888 already wasted too much time by walking through the list with
889 display_mode_element, then we might need to optimize at a higher
891 if (! STRINGP (f
->name
) || STRING_BYTES (XSTRING (f
->name
)) != len
892 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
893 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
896 #define frame_title_ptr ((char *)0)
897 #define store_frame_title(str, mincol, maxcol) 0
900 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
901 This can call eval. */
906 register struct window
*w
= XWINDOW (selected_window
);
908 struct gcpro gcpro1
, gcpro2
;
910 all_windows
= (update_mode_lines
|| buffer_shared
> 1
911 || windows_or_buffers_changed
);
913 /* Update all frame titles based on their buffer names, etc.
914 We do this before the menu bars so that the buffer-menu
915 will show the up-to-date frame titles.
917 This used to be done after the menu bars, for a reason that
918 was stated as follows but which I do not understand:
919 "We do this after the menu bars so that the frame will first
920 create its menu bar using the name `emacs' if no other name
921 has yet been specified."
922 I think that is no longer a concern. */
923 #ifdef HAVE_WINDOW_SYSTEM
924 if (windows_or_buffers_changed
|| update_mode_lines
)
926 Lisp_Object tail
, frame
;
928 FOR_EACH_FRAME (tail
, frame
)
929 if (FRAME_VISIBLE_P (XFRAME (frame
))
930 || FRAME_ICONIFIED_P (XFRAME (frame
)))
931 x_consider_frame_title (frame
);
935 /* Update the menu bar item lists, if appropriate.
936 This has to be done before any actual redisplay
937 or generation of display lines. */
940 Lisp_Object tail
, frame
;
941 int count
= specpdl_ptr
- specpdl
;
943 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
945 FOR_EACH_FRAME (tail
, frame
)
947 /* If a window on this frame changed size,
948 report that to the user and clear the size-change flag. */
949 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
951 Lisp_Object functions
;
952 /* Clear flag first in case we get error below. */
953 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
954 functions
= Vwindow_size_change_functions
;
955 GCPRO2 (tail
, functions
);
956 while (CONSP (functions
))
958 call1 (XCONS (functions
)->car
, frame
);
959 functions
= XCONS (functions
)->cdr
;
964 update_menu_bar (XFRAME (frame
), 0);
968 unbind_to (count
, Qnil
);
971 update_menu_bar (selected_frame
, 1);
973 /* Motif needs this. See comment in xmenu.c.
974 Turn it off when pending_menu_activation is not defined. */
976 pending_menu_activation
= 0;
980 /* Do a frame update, taking possible shortcuts into account.
981 This is the main external entry point for redisplay.
983 If the last redisplay displayed an echo area message and that
984 message is no longer requested, we clear the echo area
985 or bring back the minibuffer if that is in use.
987 Do not call eval from within this function.
988 Calls to eval after the call to echo_area_display would confuse
989 the display_line mechanism and would cause a crash.
990 Calls to eval before that point will work most of the time,
991 but can still lose, because this function
992 can be called from signal handlers; with alarms set up;
993 or with synchronous processes running.
995 See Fcall_process; if you called it from here, it could be
996 entered recursively. */
998 static int do_verify_charstarts
;
1000 /* Counter is used to clear the face cache
1001 no more than once ever 1000 redisplays. */
1002 static int clear_face_cache_count
;
1004 /* Record the previous terminal frame we displayed. */
1005 static FRAME_PTR previous_terminal_frame
;
1010 redisplay_internal (0);
1013 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
1014 is not in response to any user action; therefore, we should
1015 preserve the echo area. (Actually, our caller does that job.)
1016 Perhaps in the future avoid recentering windows
1017 if it is not necessary; currently that causes some problems. */
1020 redisplay_internal (preserve_echo_area
)
1021 int preserve_echo_area
;
1023 register struct window
*w
= XWINDOW (selected_window
);
1025 int must_finish
= 0;
1027 register int tlbufpos
, tlendpos
;
1028 struct position pos
;
1029 int number_of_visible_frames
;
1034 #ifdef USE_X_TOOLKIT
1035 if (popup_activated ())
1041 if (! FRAME_WINDOW_P (selected_frame
)
1042 && previous_terminal_frame
!= selected_frame
)
1044 /* Since frames on an ASCII terminal share the same display area,
1045 displaying a different frame means redisplay the whole thing. */
1046 windows_or_buffers_changed
++;
1047 SET_FRAME_GARBAGED (selected_frame
);
1048 XSETFRAME (Vterminal_frame
, selected_frame
);
1050 previous_terminal_frame
= selected_frame
;
1052 /* Set the visible flags for all frames.
1053 Do this before checking for resized or garbaged frames; they want
1054 to know if their frames are visible.
1055 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
1057 Lisp_Object tail
, frame
;
1059 number_of_visible_frames
= 0;
1061 FOR_EACH_FRAME (tail
, frame
)
1063 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1065 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1066 number_of_visible_frames
++;
1068 /* Clear out all the display lines in which we will generate the
1069 glyphs to display. */
1070 init_desired_glyphs (XFRAME (frame
));
1074 /* Notice any pending interrupt request to change frame size. */
1075 do_pending_window_change ();
1079 redraw_garbaged_frames ();
1083 prepare_menu_bars ();
1085 if (windows_or_buffers_changed
)
1086 update_mode_lines
++;
1088 /* Detect case that we need to write or remove a star in the mode line. */
1089 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
1091 w
->update_mode_line
= Qt
;
1092 if (buffer_shared
> 1)
1093 update_mode_lines
++;
1096 /* If %c is in use, update it if needed. */
1097 if (!NILP (w
->column_number_displayed
)
1098 /* This alternative quickly identifies a common case
1099 where no change is needed. */
1100 && !(PT
== XFASTINT (w
->last_point
)
1101 && XFASTINT (w
->last_modified
) >= MODIFF
1102 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1103 && XFASTINT (w
->column_number_displayed
) != current_column ())
1104 w
->update_mode_line
= Qt
;
1106 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
1108 all_windows
= update_mode_lines
|| buffer_shared
> 1;
1110 /* If specs for an arrow have changed, do thorough redisplay
1111 to ensure we remove any arrow that should no longer exist. */
1112 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
1113 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
1116 /* Normally the message* functions will have already displayed and
1117 updated the echo area, but the frame may have been trashed, or
1118 the update may have been preempted, so display the echo area
1120 if (echo_area_glyphs
|| previous_echo_glyphs
)
1122 echo_area_display ();
1126 /* If showing region, and mark has changed, must redisplay whole window. */
1127 if (((!NILP (Vtransient_mark_mode
)
1128 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1129 != !NILP (w
->region_showing
))
1130 || (!NILP (w
->region_showing
)
1131 && !EQ (w
->region_showing
,
1132 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
1133 this_line_bufpos
= -1;
1135 tlbufpos
= this_line_bufpos
;
1136 tlendpos
= this_line_endpos
;
1137 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
1138 && !current_buffer
->clip_changed
1139 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
1140 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
1141 /* Make sure recorded data applies to current buffer, etc */
1142 && this_line_buffer
== current_buffer
1143 && current_buffer
== XBUFFER (w
->buffer
)
1144 && NILP (w
->force_start
)
1145 /* Point must be on the line that we have info recorded about */
1147 && PT
<= Z
- tlendpos
1148 /* All text outside that line, including its final newline,
1149 must be unchanged */
1150 && ((XFASTINT (w
->last_modified
) >= MODIFF
1151 && (XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
))
1152 || (beg_unchanged
>= tlbufpos
- 1
1154 /* If selective display, can't optimize
1155 if the changes start at the beginning of the line. */
1156 && ((INTEGERP (current_buffer
->selective_display
)
1157 && XINT (current_buffer
->selective_display
) > 0
1158 ? (beg_unchanged
>= tlbufpos
1161 && end_unchanged
>= tlendpos
1162 && Z
- GPT
>= tlendpos
)))
1164 int tlbufpos_byte
= CHAR_TO_BYTE (tlbufpos
);
1165 if (tlbufpos
> BEGV
&& FETCH_BYTE (tlbufpos_byte
- 1) != '\n'
1167 || FETCH_BYTE (tlbufpos_byte
) == '\n'))
1168 /* Former continuation line has disappeared by becoming empty */
1170 else if (XFASTINT (w
->last_modified
) < MODIFF
1171 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
1172 || MINI_WINDOW_P (w
))
1174 /* We have to handle the case of continuation around a
1175 wide-column character (See the comment in indent.c around
1178 For instance, in the following case:
1180 -------- Insert --------
1181 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1182 J_I_ ==> J_I_ `^^' are cursors.
1186 As we have to redraw the line above, we should goto cancel. */
1188 struct position val
;
1190 int opoint
= PT
, opoint_byte
= PT_BYTE
;
1192 scan_newline (tlbufpos
, tlbufpos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
1194 val
= *compute_motion (PT
, 0,
1195 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1198 1 << (BITS_PER_SHORT
- 1),
1199 1 << (BITS_PER_SHORT
- 1),
1200 window_internal_width (w
) - 1,
1201 XINT (w
->hscroll
), 0, w
);
1202 SET_PT_BOTH (opoint
, opoint_byte
);
1203 if (val
.hpos
!= this_line_start_hpos
)
1207 overlay_arrow_seen
= 0;
1208 zv_strings_seen
= 0;
1209 display_text_line (w
, tlbufpos
, tlbufpos_byte
,
1210 this_line_vpos
, this_line_start_hpos
,
1211 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
), 0);
1212 /* If line contains point, is not continued,
1213 and ends at same distance from eob as before, we win */
1214 if (cursor_vpos
>= 0 && this_line_bufpos
1215 && this_line_endpos
== tlendpos
)
1217 /* If this is not the window's last line,
1218 we must adjust the charstarts of the lines below. */
1219 if (this_line_vpos
+ 1
1220 < XFASTINT (w
->top
) + window_internal_height (w
))
1222 int left
= WINDOW_LEFT_MARGIN (w
);
1223 int *charstart_next_line
1224 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
1227 if (Z
- tlendpos
== ZV
)
1228 /* This line ends at end of (accessible part of) buffer.
1229 There is no newline to count. */
1230 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
1232 /* This line ends in a newline.
1233 Must take account of the newline and the rest of the
1234 text that follows. */
1235 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
1237 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
1240 if (!WINDOW_FULL_WIDTH_P (w
))
1241 preserve_other_columns (w
);
1247 else if (PT
== XFASTINT (w
->last_point
)
1248 /* Make sure the cursor was last displayed
1249 in this window. Otherwise we have to reposition it. */
1250 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
1251 && (XINT (w
->top
) + XINT (w
->height
)
1252 > FRAME_CURSOR_Y (selected_frame
)))
1256 do_pending_window_change ();
1261 /* If highlighting the region, or if the cursor is in the echo area,
1262 then we can't just move the cursor. */
1263 else if (! (!NILP (Vtransient_mark_mode
)
1264 && !NILP (current_buffer
->mark_active
))
1265 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1266 || highlight_nonselected_windows
)
1267 && NILP (w
->region_showing
)
1268 && !cursor_in_echo_area
)
1270 pos
= *compute_motion (tlbufpos
, 0,
1271 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1273 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
1274 window_internal_width (w
) - 1,
1276 pos_tab_offset (w
, tlbufpos
, tlbufpos_byte
),
1280 int width
= window_internal_width (w
) - 1;
1281 FRAME_CURSOR_X (selected_frame
)
1282 = WINDOW_LEFT_MARGIN (w
) + minmax (0, pos
.hpos
, width
);
1283 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1290 /* Text changed drastically or point moved off of line */
1291 cancel_line (this_line_vpos
, selected_frame
);
1294 this_line_bufpos
= 0;
1295 all_windows
|= buffer_shared
> 1;
1297 clear_face_cache_count
++;
1301 Lisp_Object tail
, frame
;
1304 /* Clear the face cache, only when we do a full redisplay
1305 and not too often either. */
1306 if (clear_face_cache_count
> 1000)
1308 clear_face_cache ();
1309 clear_face_cache_count
= 0;
1313 /* Recompute # windows showing selected buffer.
1314 This will be incremented each time such a window is displayed. */
1317 FOR_EACH_FRAME (tail
, frame
)
1319 FRAME_PTR f
= XFRAME (frame
);
1320 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
1323 /* Mark all the scroll bars to be removed; we'll redeem the ones
1324 we want when we redisplay their windows. */
1325 if (condemn_scroll_bars_hook
)
1326 (*condemn_scroll_bars_hook
) (f
);
1328 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1329 redisplay_windows (FRAME_ROOT_WINDOW (f
), preserve_echo_area
);
1331 /* Any scroll bars which redisplay_windows should have nuked
1332 should now go away. */
1333 if (judge_scroll_bars_hook
)
1334 (*judge_scroll_bars_hook
) (f
);
1338 else if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1340 redisplay_window (selected_window
, 1, preserve_echo_area
);
1341 if (!WINDOW_FULL_WIDTH_P (w
))
1342 preserve_other_columns (w
);
1346 /* Prevent various kinds of signals during display update.
1347 stdio is not robust about handling signals,
1348 which can cause an apparent I/O error. */
1349 if (interrupt_input
)
1359 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1363 if (!FRAMEP (XCONS (tail
)->car
))
1366 f
= XFRAME (XCONS (tail
)->car
);
1368 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
1369 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1371 pause
|= update_frame (f
, 0, 0);
1374 mark_window_display_accurate (f
->root_window
, 1);
1375 if (frame_up_to_date_hook
!= 0)
1376 (*frame_up_to_date_hook
) (f
);
1383 if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1384 pause
= update_frame (selected_frame
, 0, 0);
1388 /* We may have called echo_area_display at the top of this
1389 function. If the echo area is on another frame, that may
1390 have put text on a frame other than the selected one, so the
1391 above call to update_frame would not have caught it. Catch
1394 Lisp_Object mini_window
;
1395 FRAME_PTR mini_frame
;
1397 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1398 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1400 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
1401 pause
|= update_frame (mini_frame
, 0, 0);
1405 /* If frame does not match, prevent doing single-line-update next time.
1406 Also, don't forget to check every line to update the arrow. */
1409 this_line_bufpos
= 0;
1410 if (!NILP (last_arrow_position
))
1412 last_arrow_position
= Qt
;
1413 last_arrow_string
= Qt
;
1415 /* If we pause after scrolling, some lines in current_frame
1416 may be null, so preserve_other_columns won't be able to
1417 preserve all the vertical-bar separators. So, avoid using it
1419 if (!WINDOW_FULL_WIDTH_P (w
))
1420 update_mode_lines
= 1;
1423 /* Now text on frame agrees with windows, so
1424 put info into the windows for partial redisplay to follow */
1428 register struct buffer
*b
= XBUFFER (w
->buffer
);
1430 blank_end_of_window
= 0;
1431 unchanged_modified
= BUF_MODIFF (b
);
1432 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
1433 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1434 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1436 /* Record the last place cursor was displayed in this window.
1437 But not if cursor is in the echo area, because in that case
1438 FRAME_CURSOR_X and FRAME_CURSOR_Y are in the echo area. */
1439 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (selected_frame
)
1440 && EQ (FRAME_MINIBUF_WINDOW (selected_frame
), minibuf_window
)))
1442 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1443 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1444 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1447 /* Make last_point invalid, since we don't really know
1448 where the cursor would be if it were not in the echo area. */
1449 XSETINT (w
->last_point
, -1);
1452 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1455 b
->clip_changed
= 0;
1456 w
->update_mode_line
= Qnil
;
1457 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1458 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
1460 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1463 /* Record if we are showing a region, so can make sure to
1464 update it fully at next redisplay. */
1465 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1466 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1467 || highlight_nonselected_windows
)
1468 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1469 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1472 w
->window_end_valid
= w
->buffer
;
1473 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1474 last_arrow_string
= Voverlay_arrow_string
;
1475 if (do_verify_charstarts
)
1476 verify_charstarts (w
);
1477 if (frame_up_to_date_hook
!= 0)
1478 (*frame_up_to_date_hook
) (selected_frame
);
1480 update_mode_lines
= 0;
1481 windows_or_buffers_changed
= 0;
1484 /* Start SIGIO interrupts coming again.
1485 Having them off during the code above
1486 makes it less likely one will discard output,
1487 but not impossible, since there might be stuff
1488 in the system buffer here.
1489 But it is much hairier to try to do anything about that. */
1491 if (interrupt_input
)
1495 /* If something has become visible now which was not before,
1496 redisplay again, so that we get them. */
1499 Lisp_Object tail
, frame
;
1502 FOR_EACH_FRAME (tail
, frame
)
1504 int this_is_visible
= 0;
1506 if (XFRAME (frame
)->visible
)
1507 this_is_visible
= 1;
1508 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1509 if (XFRAME (frame
)->visible
)
1510 this_is_visible
= 1;
1512 if (this_is_visible
)
1516 if (new_count
!= number_of_visible_frames
)
1517 windows_or_buffers_changed
++;
1520 /* Change frame size now if a change is pending. */
1521 do_pending_window_change ();
1523 /* If we just did a pending size change, or have additional
1524 visible frames, redisplay again. */
1525 if (windows_or_buffers_changed
&& !pause
)
1529 /* Redisplay, but leave alone any recent echo area message
1530 unless another message has been requested in its place.
1532 This is useful in situations where you need to redisplay but no
1533 user action has occurred, making it inappropriate for the message
1534 area to be cleared. See tracking_off and
1535 wait_reading_process_input for examples of these situations. */
1538 redisplay_preserve_echo_area ()
1540 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1542 echo_area_glyphs
= previous_echo_glyphs
;
1543 redisplay_internal (1);
1544 echo_area_glyphs
= 0;
1547 redisplay_internal (1);
1551 mark_window_display_accurate (window
, flag
)
1555 register struct window
*w
;
1557 for (;!NILP (window
); window
= w
->next
)
1559 if (!WINDOWP (window
)) abort ();
1560 w
= XWINDOW (window
);
1562 if (!NILP (w
->buffer
))
1564 XSETFASTINT (w
->last_modified
,
1565 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1566 XSETFASTINT (w
->last_overlay_modified
,
1567 !flag
? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)));
1569 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1572 /* Record if we are showing a region, so can make sure to
1573 update it fully at next redisplay. */
1574 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1575 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1576 || highlight_nonselected_windows
)
1577 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1578 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1582 w
->window_end_valid
= w
->buffer
;
1583 w
->update_mode_line
= Qnil
;
1584 if (!NILP (w
->buffer
) && flag
)
1585 XBUFFER (w
->buffer
)->clip_changed
= 0;
1587 if (!NILP (w
->vchild
))
1588 mark_window_display_accurate (w
->vchild
, flag
);
1589 if (!NILP (w
->hchild
))
1590 mark_window_display_accurate (w
->hchild
, flag
);
1595 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1596 last_arrow_string
= Voverlay_arrow_string
;
1600 /* t is unequal to any useful value of Voverlay_arrow_... */
1601 last_arrow_position
= Qt
;
1602 last_arrow_string
= Qt
;
1606 /* Update the menu bar item list for frame F.
1607 This has to be done before we start to fill in any display lines,
1608 because it can call eval.
1610 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1613 update_menu_bar (f
, save_match_data
)
1615 int save_match_data
;
1617 struct buffer
*old
= current_buffer
;
1619 register struct window
*w
;
1621 window
= FRAME_SELECTED_WINDOW (f
);
1622 w
= XWINDOW (window
);
1624 if (update_mode_lines
)
1625 w
->update_mode_line
= Qt
;
1627 if (FRAME_WINDOW_P (f
)
1629 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1630 FRAME_EXTERNAL_MENU_BAR (f
)
1632 FRAME_MENU_BAR_LINES (f
) > 0
1634 : FRAME_MENU_BAR_LINES (f
) > 0)
1636 /* If the user has switched buffers or windows, we need to
1637 recompute to reflect the new bindings. But we'll
1638 recompute when update_mode_lines is set too; that means
1639 that people can use force-mode-line-update to request
1640 that the menu bar be recomputed. The adverse effect on
1641 the rest of the redisplay algorithm is about the same as
1642 windows_or_buffers_changed anyway. */
1643 if (windows_or_buffers_changed
1644 || !NILP (w
->update_mode_line
)
1645 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1646 < BUF_MODIFF (XBUFFER (w
->buffer
)))
1647 != !NILP (w
->last_had_star
))
1648 || ((!NILP (Vtransient_mark_mode
)
1649 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1650 != !NILP (w
->region_showing
)))
1652 struct buffer
*prev
= current_buffer
;
1653 int count
= specpdl_ptr
- specpdl
;
1655 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1656 if (save_match_data
)
1657 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1658 if (NILP (Voverriding_local_map_menu_flag
))
1660 specbind (Qoverriding_terminal_local_map
, Qnil
);
1661 specbind (Qoverriding_local_map
, Qnil
);
1664 /* Run the Lucid hook. */
1665 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1666 /* If it has changed current-menubar from previous value,
1667 really recompute the menubar from the value. */
1668 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1669 call0 (Qrecompute_lucid_menubar
);
1670 safe_run_hooks (Qmenu_bar_update_hook
);
1671 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1672 /* Redisplay the menu bar in case we changed it. */
1673 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1674 if (FRAME_WINDOW_P (f
))
1675 set_frame_menubar (f
, 0, 0);
1677 /* On a terminal screen, the menu bar is an ordinary screen
1678 line, and this makes it get updated. */
1679 w
->update_mode_line
= Qt
;
1680 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1681 /* In the non-toolkit version, the menu bar is an ordinary screen
1682 line, and this makes it get updated. */
1683 w
->update_mode_line
= Qt
;
1684 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1686 unbind_to (count
, Qnil
);
1687 set_buffer_internal_1 (prev
);
1694 /* Redisplay WINDOW and its subwindows and siblings. */
1697 redisplay_windows (window
, preserve_echo_area
)
1699 int preserve_echo_area
;
1701 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1702 redisplay_window (window
, 0, preserve_echo_area
);
1705 /* Return value in display table DP (Lisp_Char_Table *) for character
1706 C. Since a display table doesn't have any parent, we don't have to
1707 follow parent. Do not call this function directly but use the
1708 macro DISP_CHAR_VECTOR. */
1710 disp_char_vector (dp
, c
)
1711 struct Lisp_Char_Table
*dp
;
1717 if (SINGLE_BYTE_CHAR_P (c
)) return (dp
->contents
[c
]);
1719 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
1720 if (code
[0] != CHARSET_COMPOSITION
)
1722 if (code
[1] < 32) code
[1] = -1;
1723 else if (code
[2] < 32) code
[2] = -1;
1725 /* Here, the possible range of CODE[0] (== charset ID) is
1726 128..MAX_CHARSET. Since the top level char table contains data
1727 for multibyte characters after 256th element, we must increment
1728 CODE[0] by 128 to get a correct index. */
1730 code
[3] = -1; /* anchor */
1732 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
1734 val
= dp
->contents
[code
[i
]];
1735 if (!SUB_CHAR_TABLE_P (val
))
1736 return (NILP (val
) ? dp
->defalt
: val
);
1738 /* Here, VAL is a sub char table. We return the default value of it. */
1739 return (dp
->defalt
);
1742 /* Redisplay window WINDOW and its subwindows. */
1745 redisplay_window (window
, just_this_one
, preserve_echo_area
)
1747 int just_this_one
, preserve_echo_area
;
1749 register struct window
*w
= XWINDOW (window
);
1750 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1753 int lpoint_byte
= PT_BYTE
;
1754 struct buffer
*old
= current_buffer
;
1755 register int width
= window_internal_width (w
) - 1;
1756 register int startp
, startp_byte
;
1757 register int hscroll
= XINT (w
->hscroll
);
1758 struct position pos
;
1760 int opoint_byte
= PT_BYTE
;
1762 int update_mode_line
;
1763 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1764 int really_switched_buffer
= 0;
1765 int count
= specpdl_ptr
- specpdl
;
1767 if (Z
== Z_BYTE
&& lpoint
!= lpoint_byte
)
1769 if (lpoint_byte
< lpoint
)
1772 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1774 /* If this is a combination window, do its children; that's all. */
1776 if (!NILP (w
->vchild
))
1778 redisplay_windows (w
->vchild
, preserve_echo_area
);
1781 if (!NILP (w
->hchild
))
1783 redisplay_windows (w
->hchild
, preserve_echo_area
);
1786 if (NILP (w
->buffer
))
1789 specbind (Qinhibit_point_motion_hooks
, Qt
);
1791 height
= window_internal_height (w
);
1792 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1793 if (XBUFFER (w
->buffer
)->clip_changed
)
1794 update_mode_line
= 1;
1796 if (MINI_WINDOW_P (w
))
1798 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1799 /* We've already displayed the echo area glyphs in this window. */
1800 goto finish_scroll_bars
;
1801 else if (w
!= XWINDOW (minibuf_window
))
1803 /* This is a minibuffer, but it's not the currently active one,
1805 int vpos
= XFASTINT (w
->top
);
1808 for (i
= 0; i
< height
; i
++)
1810 get_display_line (f
, vpos
+ i
, 0);
1811 display_string (w
, vpos
+ i
, "", 0,
1812 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
1816 goto finish_scroll_bars
;
1820 /* Otherwise set up data on this window; select its buffer and point value */
1822 if (update_mode_line
)
1823 /* Really select the buffer, for the sake of buffer-local variables. */
1825 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1826 really_switched_buffer
= 1;
1829 set_buffer_temp (XBUFFER (w
->buffer
));
1832 opoint_byte
= PT_BYTE
;
1834 if (Z
== Z_BYTE
&& opoint
!= opoint_byte
)
1836 if (opoint_byte
< opoint
)
1839 /* If %c is in mode line, update it if needed. */
1840 if (!NILP (w
->column_number_displayed
)
1841 /* This alternative quickly identifies a common case
1842 where no change is needed. */
1843 && !(PT
== XFASTINT (w
->last_point
)
1844 && XFASTINT (w
->last_modified
) >= MODIFF
1845 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1846 && XFASTINT (w
->column_number_displayed
) != current_column ())
1847 update_mode_line
= 1;
1849 /* Count number of windows showing the selected buffer.
1850 An indirect buffer counts as its base buffer. */
1854 struct buffer
*current_base
, *window_base
;
1855 current_base
= current_buffer
;
1856 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1857 if (current_base
->base_buffer
)
1858 current_base
= current_base
->base_buffer
;
1859 if (window_base
->base_buffer
)
1860 window_base
= window_base
->base_buffer
;
1861 if (current_base
== window_base
)
1865 /* POINT refers normally to the selected window.
1866 For any other window, set up appropriate value. */
1868 if (!EQ (window
, selected_window
))
1870 int new_pt
= XMARKER (w
->pointm
)->charpos
;
1871 int new_pt_byte
= marker_byte_position (w
->pointm
);
1875 new_pt_byte
= BEGV_BYTE
;
1876 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
1878 else if (new_pt
> (ZV
- 1))
1881 new_pt_byte
= ZV_BYTE
;
1882 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
1884 /* We don't use SET_PT so that the point-motion hooks don't run. */
1885 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
1888 /* If any of the character widths specified in the display table
1889 have changed, invalidate the width run cache. It's true that this
1890 may be a bit late to catch such changes, but the rest of
1891 redisplay goes (non-fatally) haywire when the display table is
1892 changed, so why should we worry about doing any better? */
1893 if (current_buffer
->width_run_cache
)
1895 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1897 if (! disptab_matches_widthtab (disptab
,
1898 XVECTOR (current_buffer
->width_table
)))
1900 invalidate_region_cache (current_buffer
,
1901 current_buffer
->width_run_cache
,
1903 recompute_width_table (current_buffer
, disptab
);
1907 /* If window-start is screwed up, choose a new one. */
1908 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1911 startp
= marker_position (w
->start
);
1912 startp_byte
= marker_byte_position (w
->start
);
1914 /* If someone specified a new starting point but did not insist,
1915 check whether it can be used. */
1916 if (!NILP (w
->optional_new_start
)
1917 && startp
>= BEGV
&& startp
<= ZV
)
1919 w
->optional_new_start
= Qnil
;
1920 /* Check whether this start pos is usable given where point is. */
1922 pos
= *compute_motion (startp
, 0,
1923 (((EQ (window
, minibuf_window
)
1925 ? minibuf_prompt_width
: 0)
1926 + (hscroll
? 1 - hscroll
: 0)),
1929 /* BUG FIX: See the comment of
1930 Fpos_visible_in_window_p (window.c). */
1931 - (1 << (BITS_PER_SHORT
- 1)),
1933 pos_tab_offset (w
, startp
, startp_byte
), w
);
1934 /* If PT does fit on the screen, we will use this start pos,
1935 so do so by setting force_start. */
1936 if (pos
.bufpos
== PT
)
1937 w
->force_start
= Qt
;
1940 /* Handle case where place to start displaying has been specified,
1941 unless the specified location is outside the accessible range. */
1942 if (!NILP (w
->force_start
))
1944 w
->force_start
= Qnil
;
1945 /* Forget any recorded base line for line number display. */
1946 w
->base_line_number
= Qnil
;
1947 /* Redisplay the mode line. Select the buffer properly for that.
1948 Also, run the hook window-scroll-functions
1949 because we have scrolled. */
1950 /* Note, we do this after clearing force_start because
1951 if there's an error, it is better to forget about force_start
1952 than to get into an infinite loop calling the hook functions
1953 and having them get more errors. */
1954 if (!update_mode_line
1955 || ! NILP (Vwindow_scroll_functions
))
1957 Lisp_Object temp
[3];
1959 if (!really_switched_buffer
)
1961 set_buffer_temp (old
);
1962 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1964 really_switched_buffer
= 1;
1965 update_mode_line
= 1;
1966 w
->update_mode_line
= Qt
;
1967 if (! NILP (Vwindow_scroll_functions
))
1969 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1970 make_number (startp
));
1971 startp
= marker_position (w
->start
);
1972 startp_byte
= marker_byte_position (w
->start
);
1975 XSETFASTINT (w
->last_modified
, 0);
1976 XSETFASTINT (w
->last_overlay_modified
, 0);
1977 if (startp
< BEGV
) startp
= BEGV
, startp_byte
= BEGV_BYTE
;
1978 if (startp
> ZV
) startp
= ZV
, startp
= ZV_BYTE
;
1979 try_window (window
, startp
);
1980 if (cursor_vpos
< 0)
1982 /* If point does not appear, move point so it does appear */
1983 pos
= *compute_motion (startp
, 0,
1984 (((EQ (window
, minibuf_window
)
1986 ? minibuf_prompt_width
: 0)
1987 + (hscroll
? 1 - hscroll
: 0)),
1990 - (1 << (BITS_PER_SHORT
- 1)),
1992 pos_tab_offset (w
, startp
, startp_byte
),
1994 TEMP_SET_PT_BOTH (pos
.bufpos
, pos
.bytepos
);
1995 if (w
!= XWINDOW (selected_window
))
1996 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
1999 if (current_buffer
== old
)
2002 lpoint_byte
= PT_BYTE
;
2004 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2005 + minmax (0, pos
.hpos
, width
));
2006 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2008 /* If we are highlighting the region,
2009 then we just changed the region, so redisplay to show it. */
2010 if (!NILP (Vtransient_mark_mode
)
2011 && !NILP (current_buffer
->mark_active
))
2013 cancel_my_columns (XWINDOW (window
));
2014 try_window (window
, startp
);
2020 /* Handle case where text has not changed, only point,
2021 and it has not moved off the frame. */
2023 /* This code is not used for minibuffer for the sake of
2024 the case of redisplaying to replace an echo area message;
2025 since in that case the minibuffer contents per se are usually unchanged.
2026 This code is of no real use in the minibuffer since
2027 the handling of this_line_bufpos, etc.,
2028 in redisplay handles the same cases. */
2030 if (XFASTINT (w
->last_modified
) >= MODIFF
2031 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
2032 && PT
>= startp
&& !current_buffer
->clip_changed
2033 && (just_this_one
|| WINDOW_FULL_WIDTH_P (w
))
2034 /* If force-mode-line-update was called, really redisplay;
2035 that's how redisplay is forced after e.g. changing
2036 buffer-invisibility-spec. */
2037 && NILP (w
->update_mode_line
)
2038 /* Can't use this case if highlighting a region. */
2039 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
2040 && NILP (w
->region_showing
)
2041 /* If end pos is out of date, scroll bar and percentage will be wrong */
2042 && INTEGERP (w
->window_end_vpos
)
2043 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
2044 && !EQ (window
, minibuf_window
)
2045 && (!MARKERP (Voverlay_arrow_position
)
2046 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
2048 /* All positions in this clause are relative to the window edge. */
2050 int this_scroll_margin
= scroll_margin
;
2051 int last_point_y
= XFASTINT (w
->last_point_y
) - XINT (w
->top
);
2052 int last_point_x
= (XFASTINT (w
->last_point_x
) - WINDOW_LEFT_MARGIN (w
));
2054 /* Find where PT is located now on the frame. */
2055 /* Check just_this_one as a way of verifying that the
2056 window edges have not changed. */
2057 if (PT
== XFASTINT (w
->last_point
) && just_this_one
2058 /* If CURSOR_IN_ECHO_AREA, last_point_x and last_point_y
2059 refer to the echo area and are not related to this window. */
2060 && ! cursor_in_echo_area
)
2062 pos
.hpos
= last_point_x
;
2063 pos
.vpos
= last_point_y
;
2066 else if (PT
> XFASTINT (w
->last_point
)
2067 && ! cursor_in_echo_area
2068 && XFASTINT (w
->last_point
) > startp
&& just_this_one
2069 /* We can't use this if point is in the left margin of a
2070 hscrolled window, because w->last_point_x has been
2071 clipped to the window edges. */
2072 && !(last_point_x
<= 0 && hscroll
))
2074 int last_point
= XFASTINT (w
->last_point
);
2075 int last_point_byte
= CHAR_TO_BYTE (last_point
);
2076 int tab_offset
= (pos_tab_offset (w
, last_point
, last_point_byte
)
2077 - (last_point_x
+ hscroll
- !! hscroll
));
2079 pos
= *compute_motion (last_point
, last_point_y
, last_point_x
, 0,
2081 /* BUG FIX: See the comment of
2082 Fpos_visible_in_window_p (window.c). */
2083 - (1 << (BITS_PER_SHORT
- 1)),
2090 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
2092 /* BUG FIX: See the comment of
2093 Fpos_visible_in_window_p (window.c). */
2094 - (1 << (BITS_PER_SHORT
- 1)),
2096 pos_tab_offset (w
, startp
, startp_byte
),
2100 /* Don't use a scroll margin that is negative or too large. */
2101 if (this_scroll_margin
< 0)
2102 this_scroll_margin
= 0;
2104 if (XINT (w
->height
) < 4 * scroll_margin
)
2105 this_scroll_margin
= XINT (w
->height
) / 4;
2107 /* If point fits on the screen, and not within the scroll margin,
2109 if (pos
.vpos
< height
- this_scroll_margin
2110 && (pos
.vpos
>= this_scroll_margin
|| startp
== BEGV
))
2112 /* Ok, point is still on frame */
2113 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
2115 /* These variables are supposed to be origin 1 */
2116 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
2117 + minmax (0, pos
.hpos
, width
));
2118 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
2120 /* This doesn't do the trick, because if a window to the right of
2121 this one must be redisplayed, this does nothing because there
2122 is nothing in DesiredFrame yet, and then the other window is
2123 redisplayed, making likes that are empty in this window's columns.
2124 if (WINDOW_FULL_WIDTH_P (w))
2125 preserve_my_columns (w);
2127 if (current_buffer
->clip_changed
2128 && ! NILP (Vwindow_scroll_functions
))
2129 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2130 make_number (marker_position (w
->start
)));
2134 /* Don't bother trying redisplay with same start;
2135 we already know it will lose. */
2137 /* If current starting point was originally the beginning of a line
2138 but no longer is, find a new starting point. */
2139 else if (!NILP (w
->start_at_line_beg
)
2141 || FETCH_BYTE (startp_byte
- 1) == '\n'))
2145 else if (just_this_one
&& !MINI_WINDOW_P (w
)
2147 && XFASTINT (w
->last_modified
)
2148 /* or else vmotion on first line won't work. */
2149 && ! NILP (w
->start_at_line_beg
)
2150 && ! EQ (w
->window_end_valid
, Qnil
)
2151 && do_id
&& !current_buffer
->clip_changed
2152 && !blank_end_of_window
2153 && WINDOW_FULL_WIDTH_P (w
)
2154 /* Can't use this case if highlighting a region. */
2155 && !(!NILP (Vtransient_mark_mode
)
2156 && !NILP (current_buffer
->mark_active
))
2157 /* Don't use try_window_id if newline
2158 doesn't display as the end of a line. */
2159 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
2160 && NILP (w
->region_showing
)
2161 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
2162 && EQ (last_arrow_string
, Voverlay_arrow_string
)
2163 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
2166 /* tem > 0 means success. tem == -1 means choose new start.
2167 tem == -2 means try again with same start,
2168 and nothing but whitespace follows the changed stuff.
2169 tem == 0 means try again with same start. */
2173 else if (startp
>= BEGV
&& startp
<= ZV
2175 /* Avoid starting at end of buffer. */
2176 #if 0 /* This change causes trouble for M-! finger & RET.
2177 It will have to be considered later. */
2178 || ! EQ (window
, selected_window
)
2179 /* Don't do the recentering if redisplay
2180 is not for no user action. */
2181 || preserve_echo_area
2184 || (XFASTINT (w
->last_modified
) >= MODIFF
2185 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
2187 /* Try to redisplay starting at same place as before */
2188 /* If point has not moved off frame, accept the results */
2189 try_window (window
, startp
);
2190 if (cursor_vpos
>= 0)
2192 if (!just_this_one
|| current_buffer
->clip_changed
2193 || beg_unchanged
< startp
)
2194 /* Forget any recorded base line for line number display. */
2195 w
->base_line_number
= Qnil
;
2197 if (current_buffer
->clip_changed
2198 && ! NILP (Vwindow_scroll_functions
))
2199 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2200 make_number (marker_position (w
->start
)));
2205 cancel_my_columns (w
);
2208 XSETFASTINT (w
->last_modified
, 0);
2209 XSETFASTINT (w
->last_overlay_modified
, 0);
2210 /* Redisplay the mode line. Select the buffer properly for that. */
2211 if (!update_mode_line
)
2213 if (!really_switched_buffer
)
2215 set_buffer_temp (old
);
2216 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2218 update_mode_line
= 1;
2219 w
->update_mode_line
= Qt
;
2222 /* Try to scroll by specified few lines */
2224 if ((scroll_conservatively
|| scroll_step
)
2225 && !current_buffer
->clip_changed
2226 && startp
>= BEGV
&& startp
<= ZV
)
2228 int this_scroll_margin
= scroll_margin
;
2229 int scroll_margin_pos
, scroll_margin_bytepos
;
2230 int scroll_max
= scroll_step
;
2233 if (scroll_conservatively
)
2234 scroll_max
= scroll_conservatively
;
2236 /* Don't use a scroll margin that is negative or too large. */
2237 if (this_scroll_margin
< 0)
2238 this_scroll_margin
= 0;
2240 if (XINT (w
->height
) < 4 * this_scroll_margin
)
2241 this_scroll_margin
= XINT (w
->height
) / 4;
2243 ltemp
= Fwindow_end (window
, Qt
);
2244 scroll_margin_pos
= XINT (ltemp
);
2246 if (this_scroll_margin
)
2248 pos
= *vmotion (scroll_margin_pos
, -this_scroll_margin
, w
);
2249 scroll_margin_pos
= pos
.bufpos
;
2250 scroll_margin_bytepos
= pos
.bytepos
;
2253 scroll_margin_bytepos
= CHAR_TO_BYTE (scroll_margin_pos
);
2255 if (PT
>= scroll_margin_pos
)
2257 struct position pos
;
2258 pos
= *compute_motion (scroll_margin_pos
, 0, 0, 0,
2259 PT
, XFASTINT (w
->height
), 0,
2260 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2261 pos_tab_offset (w
, scroll_margin_pos
,
2262 scroll_margin_bytepos
),
2264 if (pos
.vpos
>= scroll_max
)
2267 pos
= *vmotion (startp
,
2268 scroll_conservatively
? pos
.vpos
+ 1 : scroll_step
,
2271 if (! NILP (Vwindow_scroll_functions
))
2273 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2274 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2275 make_number (pos
.bufpos
));
2276 pos
.bufpos
= marker_position (w
->start
);
2278 try_window (window
, pos
.bufpos
);
2279 if (cursor_vpos
>= 0)
2281 if (!just_this_one
|| current_buffer
->clip_changed
2282 || beg_unchanged
< startp
)
2283 /* Forget any recorded base line for line number display. */
2284 w
->base_line_number
= Qnil
;
2288 cancel_my_columns (w
);
2291 scroll_margin_pos
= startp
;
2292 if (this_scroll_margin
)
2294 pos
= *vmotion (scroll_margin_pos
, this_scroll_margin
, w
);
2295 scroll_margin_pos
= pos
.bufpos
;
2297 if (PT
< scroll_margin_pos
)
2299 struct position pos
;
2300 pos
= *compute_motion (PT
, 0, 0, 0,
2301 scroll_margin_pos
, XFASTINT (w
->height
), 0,
2302 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2303 pos_tab_offset (w
, PT
, PT_BYTE
),
2305 if (pos
.vpos
> scroll_max
)
2308 pos
= *vmotion (startp
,
2309 scroll_conservatively
? -pos
.vpos
: - scroll_step
,
2312 if (! NILP (Vwindow_scroll_functions
))
2314 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2315 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2316 make_number (pos
.bufpos
));
2317 pos
.bufpos
= marker_position (w
->start
);
2319 try_window (window
, pos
.bufpos
);
2320 if (cursor_vpos
>= 0)
2322 if (!just_this_one
|| current_buffer
->clip_changed
2323 || beg_unchanged
< startp
)
2324 /* Forget any recorded base line for line number display. */
2325 w
->base_line_number
= Qnil
;
2329 cancel_my_columns (w
);
2335 if (scroll_step
&& ! scroll_margin
&& !current_buffer
->clip_changed
2336 && startp
>= BEGV
&& startp
<= ZV
)
2338 if (margin_call
== 0)
2339 margin_call
= (PT
> startp
? 1 : -1);
2340 if (margin_call
> 0)
2342 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
2343 if (pos
.vpos
>= height
)
2347 pos
= *vmotion (startp
, (margin_call
< 0 ? - scroll_step
: scroll_step
),
2350 if (PT
>= pos
.bufpos
)
2352 if (! NILP (Vwindow_scroll_functions
))
2354 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2355 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2356 make_number (pos
.bufpos
));
2357 pos
.bufpos
= marker_position (w
->start
);
2359 try_window (window
, pos
.bufpos
);
2360 if (cursor_vpos
>= 0)
2362 if (!just_this_one
|| current_buffer
->clip_changed
2363 || beg_unchanged
< startp
)
2364 /* Forget any recorded base line for line number display. */
2365 w
->base_line_number
= Qnil
;
2369 cancel_my_columns (w
);
2375 /* Finally, just choose place to start which centers point */
2378 /* Forget any previously recorded base line for line number display. */
2379 w
->base_line_number
= Qnil
;
2381 pos
= *vmotion (PT
, - (height
/ 2), w
);
2383 /* The minibuffer is often just one line. Ordinary scrolling
2384 gives little overlap and looks bad. So show 20 chars before point. */
2386 && (pos
.bufpos
>= PT
- minibuffer_scroll_overlap
2387 /* If we scrolled less than 1/2 line forward, we will
2388 get too much overlap, so change to the usual amount. */
2389 || pos
.bufpos
< startp
+ width
/ 2)
2390 && PT
> BEGV
+ minibuffer_scroll_overlap
2391 /* If we scrolled to an actual line boundary,
2392 that's different; don't ignore line boundaries. */
2393 && FETCH_BYTE (pos
.bytepos
- 1) != '\n')
2395 pos
.bufpos
= PT
- minibuffer_scroll_overlap
;
2396 pos
.bytepos
= CHAR_TO_BYTE (pos
.bufpos
);
2399 /* Set startp here explicitly in case that helps avoid an infinite loop
2400 in case the window-scroll-functions functions get errors. */
2401 set_marker_both (w
->start
, Qnil
, pos
.bufpos
, pos
.bytepos
);
2402 if (! NILP (Vwindow_scroll_functions
))
2404 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2405 make_number (pos
.bufpos
));
2406 pos
.bufpos
= marker_position (w
->start
);
2407 pos
.bytepos
= marker_byte_position (w
->start
);
2409 try_window (window
, pos
.bufpos
);
2411 startp
= marker_position (w
->start
);
2412 startp_byte
= marker_byte_position (w
->start
);
2413 w
->start_at_line_beg
2414 = (startp
== BEGV
|| FETCH_BYTE (startp_byte
- 1) == '\n') ? Qt
: Qnil
;
2417 if ((update_mode_line
2418 /* If window not full width, must redo its mode line
2419 if the window to its side is being redone */
2420 || (!just_this_one
&& !WINDOW_FULL_WIDTH_P (w
))
2421 || INTEGERP (w
->base_line_pos
)
2422 || (!NILP (w
->column_number_displayed
)
2423 && XFASTINT (w
->column_number_displayed
) != current_column ()))
2424 && height
!= XFASTINT (w
->height
))
2426 FRAME_PTR oframe
= selected_frame
;
2427 if (!really_switched_buffer
)
2429 set_buffer_temp (old
);
2430 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2431 really_switched_buffer
= 1;
2434 display_mode_line (w
);
2435 selected_frame
= oframe
;
2437 if (! line_number_displayed
2438 && ! BUFFERP (w
->base_line_pos
))
2440 w
->base_line_pos
= Qnil
;
2441 w
->base_line_number
= Qnil
;
2444 /* When we reach a frame's selected window, redo the frame's menu bar. */
2445 if (update_mode_line
2446 && (FRAME_WINDOW_P (f
)
2448 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2449 FRAME_EXTERNAL_MENU_BAR (f
)
2451 FRAME_MENU_BAR_LINES (f
) > 0
2453 : FRAME_MENU_BAR_LINES (f
) > 0)
2454 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
2455 display_menu_bar (w
);
2458 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2460 int start
, end
, whole
;
2462 /* Calculate the start and end positions for the current window.
2463 At some point, it would be nice to choose between scrollbars
2464 which reflect the whole buffer size, with special markers
2465 indicating narrowing, and scrollbars which reflect only the
2468 Note that minibuffers sometimes aren't displaying any text. */
2469 if (! MINI_WINDOW_P (w
)
2470 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
2473 start
= marker_position (w
->start
) - BEGV
;
2474 /* I don't think this is guaranteed to be right. For the
2475 moment, we'll pretend it is. */
2476 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
2478 if (end
< start
) end
= start
;
2479 if (whole
< (end
- start
)) whole
= end
- start
;
2482 start
= end
= whole
= 0;
2484 /* Indicate what this scroll bar ought to be displaying now. */
2485 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
2487 /* Note that we actually used the scroll bar attached to this window,
2488 so it shouldn't be deleted at the end of redisplay. */
2489 (*redeem_scroll_bar_hook
) (w
);
2492 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
2493 if (really_switched_buffer
)
2494 set_buffer_internal_1 (old
);
2496 set_buffer_temp (old
);
2497 TEMP_SET_PT_BOTH (lpoint
, lpoint_byte
);
2499 unbind_to (count
, Qnil
);
2502 /* Do full redisplay on one window, starting at position `pos'. */
2505 try_window (window
, pos
)
2509 register struct window
*w
= XWINDOW (window
);
2510 register int height
= window_internal_height (w
);
2511 register int vpos
= XFASTINT (w
->top
);
2512 register int last_text_vpos
= vpos
;
2513 FRAME_PTR f
= XFRAME (w
->frame
);
2514 int width
= window_internal_width (w
) - 1;
2515 struct position val
;
2517 /* POS should never be out of range! */
2518 if (pos
< XBUFFER (w
->buffer
)->begv
2519 || pos
> XBUFFER (w
->buffer
)->zv
)
2522 if (XMARKER (w
->start
)->charpos
!= pos
)
2523 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2526 overlay_arrow_seen
= 0;
2527 zv_strings_seen
= 0;
2528 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2529 val
.ovstring_chars_done
= 0;
2530 val
.bytepos
= marker_byte_position (w
->start
);
2531 val
.tab_offset
= pos_tab_offset (w
, pos
, val
.bytepos
);
2533 while (--height
>= 0)
2535 val
= *display_text_line (w
, pos
, val
.bytepos
, vpos
,
2536 val
.hpos
, val
.tab_offset
,
2537 val
.ovstring_chars_done
);
2538 /* The following code is omitted because we maintain tab_offset
2541 tab_offset
+= width
;
2542 if (val
.vpos
) tab_offset
= 0;
2545 if (pos
!= val
.bufpos
)
2548 #ifdef USE_TEXT_PROPERTIES
2549 Lisp_Object invis_prop
;
2550 invis_prop
= Fget_char_property (make_number (val
.bufpos
- 1),
2551 Qinvisible
, window
);
2552 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
2556 /* Next line, unless prev line ended in end of buffer with no cr */
2558 && (FETCH_BYTE (val
.bytepos
- 1) != '\n' || invis
));
2563 /* If last line is continued in middle of character,
2564 include the split character in the text considered on the frame */
2565 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2568 /* If bottom just moved off end of frame, change mode line percentage. */
2569 if (XFASTINT (w
->window_end_pos
) == 0
2571 w
->update_mode_line
= Qt
;
2573 /* Say where last char on frame will be, once redisplay is finished. */
2574 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
2575 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
2576 /* But that is not valid info until redisplay finishes. */
2577 w
->window_end_valid
= Qnil
;
2580 /* Try to redisplay when buffer is modified locally,
2581 computing insert/delete line to preserve text outside
2582 the bounds of the changes.
2583 Return 1 if successful, 0 if if cannot tell what to do,
2584 or -1 to tell caller to find a new window start,
2585 or -2 to tell caller to do normal redisplay with same window start. */
2588 try_window_id (window
)
2592 int opoint
, opoint_byte
;
2593 register struct window
*w
= XWINDOW (window
);
2594 register int height
= window_internal_height (w
);
2595 FRAME_PTR f
= XFRAME (w
->frame
);
2596 int top
= XFASTINT (w
->top
);
2597 int start
= marker_position (w
->start
);
2598 int width
= window_internal_width (w
) - 1;
2599 int hscroll
= XINT (w
->hscroll
);
2600 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
2603 register int i
, tem
;
2604 int last_text_vpos
= 0;
2606 int selective
= (INTEGERP (current_buffer
->selective_display
)
2607 ? XINT (current_buffer
->selective_display
)
2608 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2609 struct position val
, bp
, ep
, xp
, pp
;
2610 int scroll_amount
= 0;
2614 int start_byte
= marker_byte_position (w
->start
);
2616 if (GPT
- BEG
< beg_unchanged
)
2617 beg_unchanged
= GPT
- BEG
;
2618 if (Z
- GPT
< end_unchanged
)
2619 end_unchanged
= Z
- GPT
;
2621 if (beg_unchanged
+ BEG
< start
)
2622 return 0; /* Give up if changes go above top of window */
2624 /* Find position before which nothing is changed. */
2625 bp
= *compute_motion (start
, 0, lmargin
, 0,
2626 min (ZV
, beg_unchanged
+ BEG
), height
,
2627 /* BUG FIX: See the comment of
2628 Fpos_visible_in_window_p (window.c). */
2629 - (1 << (BITS_PER_SHORT
- 1)),
2631 pos_tab_offset (w
, start
, start_byte
),
2633 if (bp
.vpos
>= height
)
2637 /* All changes are beyond the window end, and point is on the screen.
2638 We don't need to change the text at all.
2639 But we need to update window_end_pos to account for
2640 any change in buffer size. */
2641 bp
= *compute_motion (start
, 0, lmargin
, 0,
2643 /* BUG FIX: See the comment of
2644 Fpos_visible_in_window_p() (window.c). */
2645 - (1 << (BITS_PER_SHORT
- 1)),
2647 pos_tab_offset (w
, start
, start_byte
), w
);
2648 XSETFASTINT (w
->window_end_vpos
, height
);
2649 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
2657 /* Find beginning of that frame line. Must display from there. */
2658 bp
= *vmotion (bp
.bufpos
, 0, w
);
2661 pos_byte
= bp
.bytepos
;
2667 /* If about to start displaying at the beginning of a continuation line,
2668 really start with previous frame line, in case it was not
2669 continued when last redisplayed */
2670 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
2672 /* Likewise if we have to worry about selective display. */
2673 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
2675 bp
= *vmotion (bp
.bufpos
, -1, w
);
2678 pos_byte
= bp
.bytepos
;
2680 val
.tab_offset
= bp
.tab_offset
; /* Update tab offset. */
2682 if (bp
.contin
&& bp
.hpos
!= lmargin
)
2684 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
2685 val
.tab_offset
= bp
.tab_offset
+ bp
.prevhpos
- width
;
2687 DEC_BOTH (pos
, pos_byte
);
2692 /* Find first visible newline after which no more is changed. */
2693 opoint
= PT
, opoint_byte
= PT_BYTE
;
2694 SET_PT (Z
- max (end_unchanged
, Z
- ZV
));
2695 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2697 while (PT
< ZV
- 1 && indented_beyond_p (PT
, PT_BYTE
, selective
))
2698 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
2700 SET_PT_BOTH (opoint
, opoint_byte
);
2702 /* Compute the cursor position after that newline. */
2703 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
2704 height
, - (1 << (BITS_PER_SHORT
- 1)),
2706 /* We have tab offset in VAL, use it. */
2709 /* If changes reach past the text available on the frame,
2710 just display rest of frame. */
2711 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
2714 stop_vpos
= ep
.vpos
;
2716 /* If no newline before ep, the line ep is on includes some changes
2717 that must be displayed. Make sure we don't stop before it. */
2718 /* Also, if changes reach all the way until ep.bufpos,
2719 it is possible that something was deleted after the
2720 newline before it, so the following line must be redrawn. */
2721 if (stop_vpos
== ep
.vpos
2722 && (ep
.bufpos
== BEGV
2723 || FETCH_BYTE (ep
.bytepos
- 1) != '\n'
2724 || ep
.bufpos
== Z
- end_unchanged
))
2725 stop_vpos
= ep
.vpos
+ 1;
2728 overlay_arrow_seen
= 0;
2729 zv_strings_seen
= 0;
2731 /* If changes do not reach to bottom of window,
2732 figure out how much to scroll the rest of the window */
2733 if (stop_vpos
< height
)
2735 /* Now determine how far up or down the rest of the window has moved */
2736 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2737 Z
- XFASTINT (w
->window_end_pos
),
2738 /* Don't care for VPOS... */
2739 1 << (BITS_PER_SHORT
- 1),
2741 1 << (BITS_PER_SHORT
- 1),
2742 width
, hscroll
, ep
.tab_offset
, w
);
2743 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2745 /* Is everything on frame below the changes whitespace?
2746 If so, no scrolling is really necessary. */
2747 for (i
= ep
.bytepos
; i
< xp
.bytepos
; i
++)
2749 tem
= FETCH_BYTE (i
);
2750 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2753 if (i
== xp
.bytepos
)
2756 XSETFASTINT (w
->window_end_vpos
,
2757 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2759 /* Before doing any scrolling, verify that point will be on frame. */
2760 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.vpos
< height
))
2762 if (PT
<= xp
.bufpos
)
2764 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2765 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2767 /* We have tab offset in EP, use it. */
2772 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2773 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2775 /* We have tab offset in XP, use it. */
2778 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2780 cursor_vpos
= pp
.vpos
+ top
;
2781 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, pp
.hpos
, width
);
2784 if (stop_vpos
- scroll_amount
>= height
2785 || ep
.bufpos
== xp
.bufpos
)
2787 if (scroll_amount
< 0)
2788 stop_vpos
-= scroll_amount
;
2790 /* In this path, we have altered window_end_vpos
2791 and not left it negative.
2792 We must make sure that, in case display is preempted
2793 before the frame changes to reflect what we do here,
2794 further updates will not come to try_window_id
2795 and assume the frame and window_end_vpos match. */
2796 blank_end_of_window
= 1;
2798 else if (!scroll_amount
)
2800 /* Even if we don't need to scroll, we must adjust the
2801 charstarts of subsequent lines (that we won't redisplay)
2802 according to the amount of text inserted or deleted. */
2803 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2804 int adjust
= ep
.bufpos
- oldpos
;
2805 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2807 else if (bp
.bufpos
== Z
- end_unchanged
)
2809 /* If reprinting everything is nearly as fast as scrolling,
2810 don't bother scrolling. Can happen if lines are short. */
2811 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2812 top
+ height
- max (0, scroll_amount
),
2814 > xp
.bufpos
- bp
.bufpos
- 20)
2815 /* Return "try normal display with same window-start."
2816 Too bad we can't prevent further scroll-thinking. */
2818 /* If pure deletion, scroll up as many lines as possible.
2819 In common case of killing a line, this can save the
2820 following line from being overwritten by scrolling
2821 and therefore having to be redrawn. */
2822 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2823 top
+ height
- max (0, scroll_amount
),
2824 scroll_amount
, bp
.bufpos
);
2829 /* scroll_frame_lines did not properly adjust subsequent
2830 lines' charstarts in the case where the text of the
2831 screen line at bp.vpos has changed.
2832 (This can happen in a deletion that ends in mid-line.)
2833 To adjust properly, we need to make things consistent
2835 So do a second adjust to make that happen.
2836 Note that stop_vpos >= ep.vpos, so it is sufficient
2837 to update the charstarts for lines at ep.vpos and below. */
2839 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2840 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2841 ep
.bufpos
- oldstart
);
2844 else if (scroll_amount
)
2846 /* If reprinting everything is nearly as fast as scrolling,
2847 don't bother scrolling. Can happen if lines are short. */
2848 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2849 overestimate of cost of reprinting, since xp.bufpos
2850 would end up below the bottom of the window. */
2851 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2852 top
+ height
- max (0, scroll_amount
),
2854 > xp
.bufpos
- ep
.bufpos
- 20)
2855 /* Return "try normal display with same window-start."
2856 Too bad we can't prevent further scroll-thinking. */
2858 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2859 top
+ height
- max (0, scroll_amount
),
2860 scroll_amount
, ep
.bufpos
);
2861 if (!tem
) stop_vpos
= height
;
2865 /* In any case, do not display past bottom of window */
2866 if (stop_vpos
>= height
)
2872 /* Handle case where pos is before w->start --
2873 can happen if part of line had been clipped and is not clipped now */
2874 if (vpos
== 0 && pos
< marker_position (w
->start
))
2875 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2877 val
.bytepos
= pos_byte
;
2879 /* Redisplay the lines where the text was changed */
2880 last_text_vpos
= vpos
;
2881 /* The following code is omitted because we maintain tab offset in
2884 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2885 /* If we are starting display in mid-character, correct tab_offset
2886 to account for passing the line that that character really starts in. */
2887 if (val
.hpos
< lmargin
)
2888 tab_offset
+= width
;
2891 while (vpos
< stop_vpos
)
2893 val
= *display_text_line (w
, pos
, val
.bytepos
, top
+ vpos
++,
2894 val
.hpos
, val
.tab_offset
,
2895 val
.ovstring_chars_done
);
2896 /* If display_text_line ran a hook and changed some text,
2897 redisplay all the way to bottom of buffer
2898 So that we show the changes. */
2899 if (old_tick
!= MODIFF
)
2901 /* The following code is omitted because we maintain tab offset
2902 in val.tab_offset. */
2904 tab_offset
+= width
;
2905 if (val
.vpos
) tab_offset
= 0;
2907 if (pos
!= val
.bufpos
)
2909 /* Next line, unless prev line ended in end of buffer with no cr */
2910 = vpos
- (val
.vpos
&& FETCH_BYTE (val
.bytepos
- 1) != '\n');
2914 /* There are two cases:
2915 1) we have displayed down to the bottom of the window
2916 2) we have scrolled lines below stop_vpos by scroll_amount */
2920 /* If last line is continued in middle of character,
2921 include the split character in the text considered on the frame */
2922 if (val
.hpos
< lmargin
)
2924 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2925 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2928 /* If scrolling made blank lines at window bottom,
2929 redisplay to fill those lines */
2930 if (scroll_amount
< 0)
2932 /* Don't consider these lines for general-purpose scrolling.
2933 That will save time in the scrolling computation. */
2934 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2937 pos_byte
= xp
.bytepos
;
2939 val
.tab_offset
= xp
.tab_offset
;
2941 { /* Display from next line */
2942 vpos
= height
+ scroll_amount
;
2946 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2948 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2949 val
.tab_offset
= xp
.tab_offset
+ bp
.prevhpos
- width
;
2950 DEC_BOTH (pos
, pos_byte
);
2953 blank_end_of_window
= 1;
2954 /* The following code is omitted because we maintain tab offset
2955 in val.tab_offset. */
2957 tab_offset
= pos_tab_offset (w
, pos
, pos_byte
);
2958 /* If we are starting display in mid-character, correct tab_offset
2959 to account for passing the line that that character starts in. */
2960 if (val
.hpos
< lmargin
)
2961 tab_offset
+= width
;
2963 val
.bytepos
= pos_byte
;
2964 while (vpos
< height
)
2966 val
= *display_text_line (w
, pos
, val
.bytepos
,
2967 top
+ vpos
++, val
.hpos
,
2968 val
.tab_offset
, val
.ovstring_chars_done
);
2969 /* The following code is omitted because we maintain tab
2970 offset in val.tab_offset. */
2972 tab_offset
+= width
;
2973 if (val
.vpos
) tab_offset
= 0;
2978 /* Here is a case where display_text_line sets cursor_vpos wrong.
2979 Make it be fixed up, below. */
2985 /* If bottom just moved off end of frame, change mode line percentage. */
2986 if (XFASTINT (w
->window_end_pos
) == 0
2988 w
->update_mode_line
= Qt
;
2990 /* Attempt to adjust end-of-text positions to new bottom line */
2993 delta
= height
- xp
.vpos
;
2995 || (delta
> 0 && xp
.bufpos
<= ZV
)
2996 || (delta
== 0 && xp
.hpos
))
2998 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
2999 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
3000 XSETFASTINT (w
->window_end_vpos
,
3001 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
3005 w
->window_end_valid
= Qnil
;
3007 /* If point was not in a line that was displayed, find it */
3008 if (cursor_vpos
< 0)
3011 val
= *compute_motion (start
, 0, lmargin
, 0, PT
,
3012 /* Don't care for VPOS... */
3013 1 << (BITS_PER_SHORT
- 1),
3015 1 << (BITS_PER_SHORT
- 1),
3017 pos_tab_offset (w
, start
, start_byte
),
3019 /* Admit failure if point is off frame now */
3020 if (val
.vpos
>= height
)
3022 for (vpos
= 0; vpos
< height
; vpos
++)
3023 cancel_line (vpos
+ top
, f
);
3026 cursor_vpos
= val
.vpos
+ top
;
3027 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, val
.hpos
, width
);
3030 FRAME_CURSOR_X (f
) = cursor_hpos
;
3031 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3035 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
3036 height
, - (1 << (BITS_PER_SHORT
- 1)),
3038 pos_tab_offset (w
, start
, start_byte
),
3040 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
3042 if (XFASTINT (w
->window_end_pos
)
3050 /* Copy LEN glyphs starting address FROM to the rope TO.
3051 But don't actually copy the parts that would come in before S.
3052 Value is TO, advanced past the copied data.
3053 F is the frame we are displaying in. */
3056 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
3058 register GLYPH
*to
; /* Copy to here. */
3059 register GLYPH
*s
; /* Starting point. */
3060 Lisp_Object
*from
; /* Data to copy. */
3062 int face
; /* Face to apply to glyphs which don't specify one. */
3065 register Lisp_Object
*fp
= from
;
3066 /* These cache the results of the last call to compute_glyph_face. */
3068 int last_merged
= 0;
3071 if (! FRAME_TERMCAP_P (f
))
3074 GLYPH glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3076 unsigned int c
= FAST_GLYPH_CHAR (glyph
);
3079 /* For an invalid character code, use space. */
3082 if (FAST_GLYPH_FACE (glyph
) == 0)
3083 /* If GLYPH has no face code, use FACE. */
3085 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
3086 /* If it's same as previous glyph, use same result. */
3087 facecode
= last_merged
;
3090 /* Merge this glyph's face and remember the result. */
3091 last_code
= FAST_GLYPH_FACE (glyph
);
3092 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
3096 *to
= FAST_MAKE_GLYPH (c
, facecode
);
3104 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
3111 /* Correct a glyph by replacing its specified user-level face code
3112 with a displayable computed face code. */
3115 fix_glyph (f
, glyph
, cface
)
3121 if (! FRAME_TERMCAP_P (f
))
3123 if (FAST_GLYPH_FACE (glyph
) != 0)
3124 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
3125 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
3131 /* Return the column of position POS / POS_BYTE in window W's buffer.
3132 When used on the character at the beginning of a line,
3133 starting at column 0, this says how much to subtract from
3134 the column position of any character in the line
3135 to get its horizontal position on the screen. */
3138 pos_tab_offset (w
, pos
, pos_byte
)
3140 register int pos
, pos_byte
;
3143 int opoint_byte
= PT_BYTE
;
3145 int width
= window_internal_width (w
) - 1;
3148 return MINI_WINDOW_P (w
) ? -minibuf_prompt_width
: 0;
3150 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3153 TEMP_SET_PT_BOTH (pos
, pos_byte
);
3154 col
= current_column ();
3155 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
3160 /* Display one line of window W, starting at char position START in W's buffer.
3161 START_BYTE is the corresponding byte position.
3163 Display starting at horizontal position HPOS, expressed relative to
3164 W's left edge. In situations where the text at START shouldn't
3165 start at the left margin (i.e. when the window is hscrolled, or
3166 we're continuing a line which left off in the midst of a
3167 multi-column character), HPOS should be negative; we throw away
3168 characters up 'til hpos = 0. So, HPOS must take hscrolling into
3171 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
3173 OVSTR_DONE is the number of chars of overlay before/after strings
3174 at this position which have already been processed.
3176 Display on position VPOS on the frame. It is origin 0, relative to
3177 the top of the frame, not W.
3179 Returns a STRUCT POSITION giving character to start next line with
3180 and where to display it, including a zero or negative hpos.
3181 The vpos field is not really a vpos; it is 1 unless the line is continued */
3183 struct position val_display_text_line
;
3185 static struct position
*
3186 display_text_line (w
, start
, start_byte
, vpos
, hpos
, taboffset
, ovstr_done
)
3194 register int pos
= start
;
3195 int pos_byte
= start_byte
;
3198 int pause
, limit_byte
;
3199 register unsigned char *p
;
3201 register GLYPH
*leftmargin
;
3202 register GLYPH
*p1prev
;
3203 register GLYPH
*p1start
;
3204 GLYPH
*p1_wide_column_end
= (GLYPH
*) 0;
3205 int prevpos
, prevpos_byte
;
3207 FRAME_PTR f
= XFRAME (w
->frame
);
3208 int tab_width
= XINT (current_buffer
->tab_width
);
3209 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
3210 int width
= window_internal_width (w
) - 1;
3211 struct position val
;
3212 int lastpos
, lastpos_byte
;
3214 int last_invis_skip
= 0;
3215 Lisp_Object last_invis_prop
;
3216 int hscroll
= XINT (w
->hscroll
);
3217 int truncate
= (hscroll
3218 || (truncate_partial_width_windows
3219 && !WINDOW_FULL_WIDTH_P (w
))
3220 || !NILP (current_buffer
->truncate_lines
));
3222 /* 1 if this buffer has a region to highlight. */
3223 int highlight_region
3224 = (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
)
3225 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
3226 int region_beg
, region_end
;
3228 int selective
= (INTEGERP (current_buffer
->selective_display
)
3229 ? XINT (current_buffer
->selective_display
)
3230 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
3231 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
3232 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
3234 Lisp_Object default_invis_vector
[3];
3235 /* Number of characters of ellipsis to display after an invisible line
3236 if it calls for an ellipsis.
3237 Note that this value can be nonzero regardless of whether
3238 selective display is enabled--you must check that separately. */
3240 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3241 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
3242 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
3243 /* This is the sequence of Lisp objects to display
3244 when there are invisible lines. */
3245 Lisp_Object
*invis_vector_contents
3246 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
3247 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
3248 : default_invis_vector
);
3250 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
3251 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp
)))
3252 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
3253 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
3254 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp
)))
3255 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
3257 /* If 1, we must handle multibyte characters. */
3258 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
3259 /* Length of multibyte form of each character. */
3261 /* Glyphs generated should be set this bit mask if text must be
3262 displayed from right to left. */
3263 GLYPH rev_dir_bit
= (NILP (current_buffer
->direction_reversed
)
3264 ? 0 : GLYPH_MASK_REV_DIR
);
3266 /* The next buffer location at which the face should change, due
3267 to overlays or text property changes. */
3268 int next_face_change
;
3270 /* The next location where the `invisible' property changes, or an
3271 overlay starts or ends. */
3274 /* The face we're currently using. */
3275 int current_face
= 0;
3278 XSETFASTINT (default_invis_vector
[2], '.');
3279 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
3281 get_display_line (f
, vpos
, WINDOW_LEFT_MARGIN (w
));
3282 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
3284 /* Show where to highlight the region. */
3285 if (highlight_region
3286 /* Maybe highlight only in selected window. */
3287 && (highlight_nonselected_windows
3288 || w
== XWINDOW (selected_window
)
3289 || (MINI_WINDOW_P (XWINDOW (selected_window
))
3290 && w
== XWINDOW (Vminibuf_scroll_window
))))
3292 region_beg
= marker_position (current_buffer
->mark
);
3293 if (PT
< region_beg
)
3295 region_end
= region_beg
;
3300 w
->region_showing
= Qt
;
3304 region_beg
= region_end
= -1;
3305 w
->region_showing
= Qnil
;
3308 if (MINI_WINDOW_P (w
)
3310 && vpos
== XFASTINT (w
->top
))
3312 if (! NILP (minibuf_prompt
))
3314 int old_width
= minibuf_prompt_width
;
3316 minibuf_prompt_width
3317 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
3318 STRING_BYTES (XSTRING (minibuf_prompt
)),
3319 hpos
+ WINDOW_LEFT_MARGIN (w
),
3320 /* Display a space if we truncate. */
3323 /* Truncate the prompt a little before the
3324 margin, so user input can at least start
3325 on the first line. */
3326 (XFASTINT (w
->width
) > 10
3327 ? XFASTINT (w
->width
) - 4 : -1),
3328 STRING_MULTIBYTE (minibuf_prompt
))
3329 - hpos
- WINDOW_LEFT_MARGIN (w
));
3330 hpos
+= minibuf_prompt_width
;
3331 taboffset
-= minibuf_prompt_width
- old_width
;
3334 minibuf_prompt_width
= 0;
3337 /* If we're hscrolled at all, use compute_motion to skip over any
3338 text off the left edge of the window. compute_motion may know
3339 tricks to do this faster than we can. */
3342 struct position
*left_edge
3343 = compute_motion (pos
, vpos
, hpos
, 0,
3345 width
, hscroll
, taboffset
, w
);
3347 /* Retrieve the buffer position and column provided by
3348 compute_motion. We can't assume that the column will be
3349 zero, because you may have multi-column characters crossing
3352 compute_motion may have moved us past the screen position we
3353 requested, if we hit a multi-column character, or the end of
3354 the line. If so, back up. */
3355 if (left_edge
->vpos
> vpos
3356 || left_edge
->hpos
> 0)
3358 pos
= left_edge
->bufpos
;
3359 pos_byte
= left_edge
->bytepos
;
3360 DEC_BOTH (pos
, pos_byte
);
3361 hpos
= left_edge
->prevhpos
;
3365 pos
= left_edge
->bufpos
;
3366 pos_byte
= left_edge
->bytepos
;
3367 hpos
= left_edge
->hpos
;
3371 hpos
+= WINDOW_LEFT_MARGIN (w
);
3373 desired_glyphs
->bufp
[vpos
] = start
;
3374 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
3376 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
3377 /* In case we don't ever write anything into it... */
3378 desired_glyphs
->charstarts
[vpos
][WINDOW_LEFT_MARGIN (w
)] = -1;
3379 leftmargin
= desired_glyphs
->glyphs
[vpos
] + WINDOW_LEFT_MARGIN (w
);
3380 endp
= leftmargin
+ width
;
3382 /* Arrange the overlays nicely for our purposes. Usually, we call
3383 display_text_line on only one line at a time, in which case this
3384 can't really hurt too much, or we call it on lines which appear
3385 one after another in the buffer, in which case all calls to
3386 recenter_overlay_lists but the first will be pretty cheap. */
3387 recenter_overlay_lists (current_buffer
, pos
);
3389 /* Loop generating characters.
3390 Stop at end of buffer, before newline,
3391 if reach or pass continuation column,
3392 or at face change. */
3394 limit_byte
= pos_byte
;
3395 next_face_change
= pos
;
3396 next_boundary
= pos
;
3399 prevpos_byte
= pos_byte
;
3401 /* If the window is hscrolled and point is in the invisible part of the
3402 current line beyond the left margin we can record the cursor location
3404 if (hscroll
&& start
<= PT
&& PT
< pos
&& cursor_vpos
< 0)
3407 cursor_hpos
= p1
- leftmargin
;
3416 while (pos
== next_boundary
)
3418 Lisp_Object position
, limit
, prop
, ww
;
3420 /* Display the overlay strings here, unless we're at ZV
3421 and have already displayed the appropriate strings
3422 on an earlier line. */
3423 if (pos
< ZV
|| !zv_strings_seen
++)
3426 unsigned char *ovstr
;
3427 ovlen
= overlay_strings (pos
, w
, &ovstr
);
3431 /* Skip the ones we did in a previous line. */
3432 ovstr
+= ovstr_done
;
3433 ovlen
-= ovstr_done
;
3442 c
= STRING_CHAR_AND_LENGTH (ovstr
, ovlen
, len
);
3443 ovstr
+= len
, ovlen
-= len
, ovstr_done
+= len
;
3444 charset
= CHAR_CHARSET (c
);
3445 cols
= (charset
== CHARSET_COMPOSITION
3446 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3447 : CHARSET_WIDTH (charset
));
3451 c
= *ovstr
++, ovlen
--, ovstr_done
++;
3454 g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3457 if (p1
>= leftmargin
&& p1
< endp
)
3458 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3462 /* If we did all the overlay strings
3463 and we have room for text, clear ovstr_done
3464 just for neatness' sake. */
3465 if (ovlen
== 0 && p1
< endp
)
3470 /* Did we reach point? Record the cursor location. */
3471 if (pos
== PT
&& cursor_vpos
< 0)
3474 cursor_hpos
= p1
- leftmargin
;
3480 XSETFASTINT (position
, pos
);
3481 limit
= Fnext_overlay_change (position
);
3482 #ifdef USE_TEXT_PROPERTIES
3483 /* This is just an estimate to give reasonable
3484 performance; nothing should go wrong if it is too small. */
3485 if (XFASTINT (limit
) > pos
+ 50)
3487 int limitpos
= pos
+ 50;
3488 XSETFASTINT (limit
, limitpos
);
3490 limit
= Fnext_single_property_change (position
, Qinvisible
,
3491 Fcurrent_buffer (), limit
);
3493 next_boundary
= XFASTINT (limit
);
3494 /* if the `invisible' property is set, we can skip to
3495 the next property change. */
3497 prop
= Fget_char_property (position
, Qinvisible
, ww
);
3498 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3500 if (pos
< PT
&& next_boundary
>= PT
)
3503 cursor_hpos
= p1
- leftmargin
;
3505 pos
= next_boundary
;
3506 pos_byte
= CHAR_TO_BYTE (pos
);
3507 last_invis_skip
= pos
;
3508 last_invis_prop
= prop
;
3512 /* Did we reach point? Record the cursor location. */
3513 if (pos
== PT
&& cursor_vpos
< 0)
3516 cursor_hpos
= p1
- leftmargin
;
3519 /* Did we hit the end of the visible region of the buffer?
3523 /* Update charstarts for the end of this line. */
3524 /* Do nothing if off the left edge or at the right edge. */
3525 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
3527 int *p2x
= &charstart
[(p1
< leftmargin
3535 /* Figure out where (if at all) the
3536 redisplay_end_trigger-hook should run. */
3537 if (MARKERP (w
->redisplay_end_trigger
)
3538 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
3539 e_t_h
= marker_position (w
->redisplay_end_trigger
);
3540 else if (INTEGERP (w
->redisplay_end_trigger
))
3541 e_t_h
= XINT (w
->redisplay_end_trigger
);
3545 /* If we've gone past the place to run a hook,
3547 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
3549 Lisp_Object args
[3];
3551 args
[0] = Qredisplay_end_trigger_functions
;
3552 XSETWINDOW (args
[1], w
);
3553 XSETINT (args
[2], e_t_h
);
3555 /* Since we are *trying* to run these functions,
3556 don't try to run them again, even if they get an error. */
3557 w
->redisplay_end_trigger
= Qnil
;
3558 Frun_hook_with_args (3, args
);
3561 /* Notice if it changed the face of this character. */
3562 next_face_change
= pos
;
3566 /* Did we hit a face change? Figure out what face we should
3567 use now. We also hit this the first time through the
3568 loop, to see what face we should start with. */
3569 if (pos
>= next_face_change
3570 && (FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
)))
3572 int limit
= pos
+ 50;
3574 current_face
= compute_char_face (f
, w
, pos
,
3575 region_beg
, region_end
,
3576 &next_face_change
, limit
, 0);
3580 /* Compute the next place we need to stop
3581 and do something special; set PAUSE. */
3585 if (pos
< next_boundary
&& next_boundary
< pause
)
3586 pause
= next_boundary
;
3587 if (pos
< next_face_change
&& next_face_change
< pause
)
3588 pause
= next_face_change
;
3593 /* Wouldn't you hate to read the next line to someone over
3595 if (pos
< PT
&& PT
< pause
)
3597 if (pos
< GPT
&& GPT
< pause
)
3600 /* LIMIT_BYTE is not the same place in the buffer as PAUSE.
3601 It is a limit on valid characters.
3602 We use it to bound STRING_CHAR_AND_LENGTH. */
3603 limit_byte
= ZV_BYTE
;
3604 if (pos
< GPT
&& GPT_BYTE
< limit_byte
)
3605 limit_byte
= GPT_BYTE
;
3608 int temp
= CHAR_TO_BYTE (pos
);
3609 p
= BYTE_POS_ADDR (temp
);
3617 p1_wide_column_end
= (GLYPH
*) 0;
3620 c
= STRING_CHAR_AND_LENGTH (p
, limit_byte
- pos_byte
, len
), p
+= len
;
3623 /* Let a display table override all standard display methods. */
3624 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3626 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
3627 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3628 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3629 current_face
, rev_dir_bit
);
3631 else if (c
>= 040 && c
< 0177)
3633 if (p1
>= leftmargin
)
3634 *p1
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3640 /* Same as p1prev, but after the invis_vector_contents text
3641 (if we have that on this line). */
3642 GLYPH
*p1prev_modified
;
3646 if (last_invis_skip
== pos
3647 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
3651 && indented_beyond_p (pos
+ 1, pos_byte
+ 1, selective
))
3653 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3656 INC_BOTH (pos
, pos_byte
);
3657 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3658 pos
= PT
, pos_byte
= PT_BYTE
;
3659 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3664 SET_PT_BOTH (opoint
, opoint_byte
);
3666 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
3671 cs
= charstart
+ (p1
- p1start
);
3674 p1
+= selective_rlen
;
3675 if (p1
- leftmargin
> width
)
3678 #if 0 /* This needs more work; charstarts needs to record
3679 both whether a position ho;ds an ellipsis character
3680 and what buffer position it corresponds to. */
3681 csend
= charstart
+ (p1
- p1start
);
3684 /* The idea is to use p1prev_modified instead of p1prev
3685 in the loop below over p2x. */
3686 p1prev_modified
= p1
;
3689 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3690 (p1
- p1prev
), current_face
, rev_dir_bit
);
3693 /* Update charstarts for the newline that ended this line. */
3694 /* Do nothing here for a char that's entirely off the left edge
3695 or if it starts at the right edge. */
3696 if (p1
>= leftmargin
&& p1prev
!= endp
)
3698 /* Store the newline's position into charstarts
3699 for the column where the newline starts.
3700 Store -1 for the rest of the glyphs it occupies. */
3701 int *p2x
= &charstart
[(p1prev
< leftmargin
3702 ? leftmargin
: p1prev
)
3704 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3711 /* Draw the face of the newline character as extending all the
3712 way to the end of the frame line. */
3715 if (p1
< leftmargin
)
3718 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3728 if (p1
>= leftmargin
&& p1
< endp
)
3729 *p1
= MAKE_GLYPH (f
, ' ', current_face
) | rev_dir_bit
;
3732 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
3735 else if (c
== Ctl ('M') && selective
== -1)
3737 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3738 scan_newline (pos
, pos_byte
, ZV
, ZV_BYTE
, 1, 1);
3739 pos
= PT
, pos_byte
= PT_BYTE
;
3740 SET_PT_BOTH (opoint
, opoint_byte
);
3742 if (FETCH_BYTE (pos_byte
- 1) == '\n')
3744 if (selective_rlen
> 0)
3746 p1
+= selective_rlen
;
3747 if (p1
- leftmargin
> width
)
3749 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3750 (p1
- p1prev
), current_face
, rev_dir_bit
);
3753 /* Draw the face of the newline character as extending all the
3754 way to the end of the frame line. */
3757 if (p1
< leftmargin
)
3760 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3764 /* Update charstarts for the ^M that ended this line. */
3765 /* Do nothing here for a char that's entirely off the left edge
3766 or if it starts at the right edge. */
3767 if (p1
>= leftmargin
&& p1prev
!= endp
)
3769 /* Store the newline's position into charstarts
3770 for the column where the newline starts.
3771 Store -1 for the rest of the glyphs it occupies. */
3772 int *p2x
= &charstart
[(p1prev
< leftmargin
3773 ? leftmargin
: p1prev
)
3775 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3783 else if (c
< 0200 && ctl_arrow
)
3785 if (p1
>= leftmargin
)
3787 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3788 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
3789 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3793 if (p1
>= leftmargin
&& p1
< endp
)
3794 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
) | rev_dir_bit
;
3799 /* C is a multibyte character or a character to be displayed
3801 int remaining_bytes
= len
;
3805 /* C is a multibyte character. */
3806 int charset
= CHAR_CHARSET (c
);
3807 int columns
= (charset
== CHARSET_COMPOSITION
3808 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3809 : CHARSET_WIDTH (charset
));
3810 GLYPH g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3814 if (p1
>= leftmargin
&& p1
< endp
)
3815 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3818 p1_wide_column_end
= p1
;
3819 remaining_bytes
-= CHARSET_BYTES (charset
);
3822 while (remaining_bytes
> 0)
3824 c
= *(p
- remaining_bytes
--);
3826 if (p1
>= leftmargin
&& p1
< endp
)
3829 (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3830 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
3831 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3835 if (p1
>= leftmargin
&& p1
< endp
)
3836 *p1
= (MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
)
3839 if (p1
>= leftmargin
&& p1
< endp
)
3840 *p1
= (MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
)
3843 if (p1
>= leftmargin
&& p1
< endp
)
3844 *p1
= (MAKE_GLYPH (f
, (7 & c
) + '0', current_face
)
3851 prevpos_byte
= pos_byte
;
3855 /* Update charstarts for the character just output. */
3857 /* Do nothing here for a char that's entirely off the left edge. */
3858 if (p1
>= leftmargin
)
3860 /* Store the char's position into charstarts
3861 for the first glyph occupied by this char.
3862 Store -1 for the rest of the glyphs it occupies. */
3865 int *p2x
= &charstart
[(p1prev
< leftmargin
3866 ? leftmargin
: p1prev
)
3868 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3878 val
.hpos
= - XINT (w
->hscroll
);
3885 lastpos_byte
= pos_byte
;
3887 /* Store 0 in this charstart line for the positions where
3888 there is no character. But do leave what was recorded
3889 for the character that ended the line. */
3890 /* Add 1 in the endtest to compensate for the fact that ENDP was
3891 made from WIDTH, which is 1 less than the window's actual
3893 i
= p1
- p1start
+ 1;
3894 if (p1
< leftmargin
)
3895 i
+= leftmargin
- p1
;
3896 for (; i
< endp
- p1start
+ 1; i
++)
3899 /* Handle continuation in middle of a character */
3900 /* by backing up over it */
3903 /* Don't back up if we never actually displayed any text.
3904 This occurs when the minibuffer prompt takes up the whole line. */
3907 /* Start the next line with that same character whose
3908 character code is C and the length of multi-byte form is
3911 pos_byte
= prevpos_byte
;
3913 if (p1_wide_column_end
< endp
)
3914 /* As ENDP is not in the middle of wide-column character,
3915 we can break the line at ENDP and start from the middle
3916 column in the next line. So, adjust VAL.HPOS to skip
3917 the columns output on this line. */
3918 val
.hpos
+= p1prev
- endp
;
3921 /* We displayed a wide-column character at around ENDP.
3922 Since we can't broke it in the middle, the whole
3923 character should be driven into the next line. */
3924 /* As the result, the actual columns occupied by the
3925 text on this line is less than WIDTH. VAL.TAB_OFFSET
3926 must be adjusted. */
3927 taboffset
= taboffset
+ (p1prev
- endp
);
3928 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3930 GLYPH g
= fix_glyph (f
, truncate
? truncator
: continuer
, 0);
3931 while (p1prev
< endp
)
3934 /* If POINT is at POS, cursor should not on this line. */
3936 lastpos_byte
= pos_byte
;
3942 /* Keep in this line everything up to the continuation column. */
3946 /* Finish deciding which character to start the next line on,
3947 and what hpos to start it at.
3948 Also set `lastpos' to the last position which counts as "on this line"
3949 for cursor-positioning. */
3953 if (FETCH_BYTE (pos_byte
) == '\n')
3955 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3957 /* If stopped due to a newline, start next line after it */
3958 SET_PT_BOTH (pos
+ 1, pos_byte
+ 1);
3961 /* Check again for hidden lines, in case the newline occurred exactly
3962 at the right margin. */
3963 while (PT
< ZV
&& selective
> 0
3964 && indented_beyond_p (PT
, PT_BYTE
, selective
))
3965 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
3967 pos
= PT
, pos_byte
= PT_BYTE
;
3968 SET_PT_BOTH (opoint
, opoint_byte
);
3971 /* Stopped due to right margin of window */
3975 int opoint
= PT
, opoint_byte
= PT_BYTE
;
3977 SET_PT_BOTH (pos
, pos_byte
);
3978 *p1
++ = fix_glyph (f
, truncator
, 0);
3979 /* Truncating => start next line after next newline,
3980 and point is on this line if it is before the newline,
3981 and skip none of first char of next line */
3983 scan_newline (PT
, PT_BYTE
, ZV
, ZV_BYTE
, 1, 1);
3984 while (PT
< ZV
&& selective
> 0
3985 && indented_beyond_p (PT
, PT_BYTE
, selective
));
3986 pos
= PT
, pos_byte
= PT_BYTE
;
3987 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
3988 SET_PT_BOTH (opoint
, opoint_byte
);
3990 lastpos
= pos
- (FETCH_BYTE (pos_byte
- 1) == '\n');
3991 lastpos_byte
= CHAR_TO_BYTE (lastpos
);
3996 *p1
++ = fix_glyph (f
, continuer
, 0);
3998 DEC_BOTH (lastpos
, lastpos_byte
);
3999 val
.tab_offset
= taboffset
+ width
;
4006 /* If point is at eol or in invisible text at eol,
4007 record its frame location now. */
4009 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
4012 cursor_hpos
= p1
- leftmargin
;
4015 if (cursor_vpos
== vpos
)
4017 if (cursor_hpos
< 0) cursor_hpos
= 0;
4018 if (cursor_hpos
> width
) cursor_hpos
= width
;
4019 cursor_hpos
+= WINDOW_LEFT_MARGIN (w
);
4020 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
4022 this_line_bufpos
= 0;
4024 /* If this frame's cursor will be in its echo area,
4025 don't record a cursor from the window text,
4026 and turn off the optimization for cursor-motion-only case. */
4027 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
4028 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
4030 FRAME_CURSOR_Y (f
) = cursor_vpos
;
4031 FRAME_CURSOR_X (f
) = cursor_hpos
;
4033 if (w
== XWINDOW (selected_window
))
4035 /* Line is not continued and did not start
4036 in middle of character */
4037 if ((hpos
- WINDOW_LEFT_MARGIN (w
)
4038 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
4041 this_line_bufpos
= start
;
4042 this_line_buffer
= current_buffer
;
4043 this_line_vpos
= cursor_vpos
;
4044 this_line_start_hpos
= hpos
- WINDOW_LEFT_MARGIN (w
);
4045 this_line_endpos
= Z
- lastpos
;
4052 /* If hscroll and line not empty, insert truncation-at-left marker */
4053 if (hscroll
&& lastpos
!= start
)
4055 GLYPH g
= fix_glyph (f
, truncator
, 0);
4057 if (p1
<= leftmargin
)
4058 p1
= leftmargin
+ 1;
4059 else /* MULE: it may be a wide-column character */
4061 p1prev
= leftmargin
+ 1;
4062 while (p1prev
< p1
&& *p1prev
& GLYPH_MASK_PADDING
)
4067 if (!WINDOW_RIGHTMOST_P (w
))
4070 if (p1
< leftmargin
) p1
= leftmargin
;
4071 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
4073 /* Don't draw vertical bars if we're using scroll bars. They're
4074 covered up by the scroll bars, and it's distracting to see
4075 them when the scroll bar windows are flickering around to be
4077 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4080 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4083 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4084 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
4085 ? XINT (DISP_BORDER_GLYPH (dp
))
4088 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
4089 p1
- desired_glyphs
->glyphs
[vpos
]);
4090 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
4092 /* If the start of this line is the overlay arrow-position,
4093 then put the arrow string into the display-line. */
4095 if (MARKERP (Voverlay_arrow_position
)
4096 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
4097 && start
== marker_position (Voverlay_arrow_position
)
4098 && STRINGP (Voverlay_arrow_string
)
4099 && ! overlay_arrow_seen
)
4102 int len
= XSTRING (Voverlay_arrow_string
)->size
;
4108 /* If the arrow string has text props, obey them when displaying. */
4109 for (i
= 0, i_byte
= 0; i
< len
; )
4112 Lisp_Object face
, ilisp
;
4116 if (STRING_MULTIBYTE (Voverlay_arrow_string
))
4117 FETCH_STRING_CHAR_ADVANCE (c
, Voverlay_arrow_string
, i
, i_byte
);
4119 c
= XSTRING (Voverlay_arrow_string
)->data
[i
++];
4121 XSETFASTINT (ilisp
, i
);
4123 if (FRAME_WINDOW_P (f
))
4125 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
4126 newface
= compute_glyph_face_1 (f
, face
, 0);
4127 c
= FAST_MAKE_GLYPH (c
, newface
);
4129 #endif /* HAVE_FACES */
4130 leftmargin
[idx
] = c
;
4133 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
4134 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
4135 if (desired_glyphs
->used
[vpos
] < arrow_end
)
4136 desired_glyphs
->used
[vpos
] = arrow_end
;
4138 overlay_arrow_seen
= 1;
4142 val
.bytepos
= pos_byte
;
4143 val
.ovstring_chars_done
= ovstr_done
;
4144 val_display_text_line
= val
;
4145 return &val_display_text_line
;
4148 /* Redisplay the menu bar in the frame for window W. */
4151 display_menu_bar (w
)
4154 Lisp_Object items
, tail
;
4155 register int vpos
= 0;
4156 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4157 int maxendcol
= FRAME_WIDTH (f
);
4162 if (!NILP (Vwindow_system
))
4166 #ifdef USE_X_TOOLKIT
4169 #endif /* USE_X_TOOLKIT */
4171 get_display_line (f
, vpos
, 0);
4173 items
= FRAME_MENU_BAR_ITEMS (f
);
4174 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4176 Lisp_Object pos
, string
;
4177 string
= XVECTOR (items
)->contents
[i
+ 1];
4181 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], hpos
);
4183 if (hpos
< maxendcol
)
4184 hpos
= display_string (w
, vpos
,
4185 XSTRING (string
)->data
,
4186 STRING_BYTES (XSTRING (string
)),
4187 hpos
, 0, 0, hpos
, maxendcol
,
4188 STRING_MULTIBYTE (string
));
4189 /* Put a space between items. */
4190 if (hpos
< maxendcol
)
4192 int hpos1
= hpos
+ 1;
4193 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
4194 min (hpos1
, maxendcol
), maxendcol
, 0);
4198 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4199 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4201 /* Fill out the line with spaces. */
4202 if (maxendcol
> hpos
)
4203 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
, 0);
4205 /* Clear the rest of the lines allocated to the menu bar. */
4207 while (vpos
< FRAME_MENU_BAR_LINES (f
))
4208 get_display_line (f
, vpos
++, 0);
4211 /* Display the mode line for window w */
4214 display_mode_line (w
)
4217 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
4218 register int left
= WINDOW_LEFT_MARGIN (w
);
4219 register int right
= WINDOW_RIGHT_MARGIN (w
);
4220 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4222 line_number_displayed
= 0;
4223 w
->column_number_displayed
= Qnil
;
4225 get_display_line (f
, vpos
, left
);
4227 /* Temporarily make frame F's kboard the current kboard
4228 so that kboard-local variables in the mode_line_format
4229 will get the right values. */
4230 push_frame_kboard (f
);
4232 display_mode_element (w
, vpos
, left
, 0, right
, right
,
4233 current_buffer
->mode_line_format
);
4235 pop_frame_kboard ();
4237 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
4239 /* Put the mode line in inverse video.
4240 Use faces if possible, since that lets us handle
4241 partial-width windows and avoid inverting the scroll bar columns. */
4243 if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
4245 /* For a partial width window, explicitly set face of each glyph. */
4247 unsigned int padding
;
4248 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
4249 for (i
= left
; i
< right
; ++i
)
4251 padding
= ptr
[i
] & GLYPH_MASK_PADDING
;
4252 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1) | padding
;
4258 /* Make the mode line inverse video if the entire line
4259 is made of mode lines.
4260 I.e. if this window is full width,
4261 or if it is the child of a full width window
4262 (which implies that that window is split side-by-side
4263 and the rest of this line is mode lines of the sibling windows). */
4264 if (WINDOW_FULL_WIDTH_P (w
)
4265 || WINDOW_FULL_WIDTH_P (XWINDOW (w
->parent
)))
4266 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
4269 /* Contribute ELT to the mode line for window W.
4270 How it translates into text depends on its data type.
4272 VPOS is the position of the mode line being displayed.
4274 HPOS is the position (absolute on frame) where this element's text
4275 should start. The output is truncated automatically at the right
4278 DEPTH is the depth in recursion. It is used to prevent
4279 infinite recursion here.
4281 MINENDCOL is the hpos before which the element may not end.
4282 The element is padded at the right with spaces if nec
4283 to reach this column.
4285 MAXENDCOL is the hpos past which this element may not extend.
4286 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
4287 (This is necessary to make nested padding and truncation work.)
4289 Returns the hpos of the end of the text generated by ELT.
4290 The next element will receive that value as its HPOS arg,
4291 so as to concatenate the elements. */
4294 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
4296 register int vpos
, hpos
;
4299 register int maxendcol
;
4300 register Lisp_Object elt
;
4308 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
4312 /* A string: output it and check for %-constructs within it. */
4313 register unsigned char c
;
4314 register unsigned char *this = XSTRING (elt
)->data
;
4316 while (hpos
< maxendcol
&& *this)
4318 unsigned char *last
= this;
4319 while ((c
= *this++) != '\0' && c
!= '%')
4321 if (this - 1 != last
)
4323 register int lim
= --this - last
+ hpos
;
4324 if (frame_title_ptr
)
4325 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
4327 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
4328 hpos
, min (lim
, maxendcol
),
4329 STRING_MULTIBYTE (elt
));
4333 register int minendcol
;
4334 register int spec_width
= 0;
4336 /* We can't allow -ve args due to the "%-" construct */
4337 /* Argument specifies minwidth but not maxwidth
4338 (maxwidth can be specified by
4339 (<negative-number> . <stuff>) mode-line elements) */
4341 while ((c
= *this++) >= '0' && c
<= '9')
4343 spec_width
= spec_width
* 10 + (c
- '0');
4346 minendcol
= hpos
+ spec_width
;
4347 if (minendcol
> maxendcol
)
4349 spec_width
= maxendcol
- hpos
;
4350 minendcol
= maxendcol
;
4354 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4355 spec_width
, maxendcol
,
4356 Vglobal_mode_string
);
4359 char *spec
= decode_mode_spec (w
, c
, spec_width
,
4361 if (frame_title_ptr
)
4362 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
4364 hpos
= display_string (w
, vpos
, spec
, -1,
4366 minendcol
, maxendcol
, -1);
4374 /* A symbol: process the value of the symbol recursively
4375 as if it appeared here directly. Avoid error if symbol void.
4376 Special case: if value of symbol is a string, output the string
4379 register Lisp_Object tem
;
4380 tem
= Fboundp (elt
);
4383 tem
= Fsymbol_value (elt
);
4384 /* If value is a string, output that string literally:
4385 don't check for % within it. */
4388 if (frame_title_ptr
)
4389 hpos
= store_frame_title (XSTRING (tem
)->data
,
4390 minendcol
, maxendcol
);
4392 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
4393 STRING_BYTES (XSTRING (tem
)),
4394 hpos
, 0, 1, minendcol
, maxendcol
,
4395 STRING_MULTIBYTE (tem
));
4397 /* Give up right away for nil or t. */
4398 else if (!EQ (tem
, elt
))
4399 { elt
= tem
; goto tail_recurse
; }
4406 register Lisp_Object car
, tem
;
4408 /* A cons cell: three distinct cases.
4409 If first element is a string or a cons, process all the elements
4410 and effectively concatenate them.
4411 If first element is a negative number, truncate displaying cdr to
4412 at most that many characters. If positive, pad (with spaces)
4413 to at least that many characters.
4414 If first element is a symbol, process the cadr or caddr recursively
4415 according to whether the symbol's value is non-nil or nil. */
4416 car
= XCONS (elt
)->car
;
4419 tem
= Fboundp (car
);
4420 elt
= XCONS (elt
)->cdr
;
4423 /* elt is now the cdr, and we know it is a cons cell.
4424 Use its car if CAR has a non-nil value. */
4427 tem
= Fsymbol_value (car
);
4429 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
4431 /* Symbol's value is nil (or symbol is unbound)
4432 Get the cddr of the original list
4433 and if possible find the caddr and use that. */
4434 elt
= XCONS (elt
)->cdr
;
4437 else if (!CONSP (elt
))
4439 elt
= XCONS (elt
)->car
;
4442 else if (INTEGERP (car
))
4444 register int lim
= XINT (car
);
4445 elt
= XCONS (elt
)->cdr
;
4447 /* Negative int means reduce maximum width.
4448 DO NOT change MINENDCOL here!
4449 (20 -10 . foo) should truncate foo to 10 col
4450 and then pad to 20. */
4451 maxendcol
= min (maxendcol
, hpos
- lim
);
4454 /* Padding specified. Don't let it be more than
4457 if (lim
> maxendcol
)
4459 /* If that's more padding than already wanted, queue it.
4460 But don't reduce padding already specified even if
4461 that is beyond the current truncation point. */
4462 if (lim
> minendcol
)
4467 else if (STRINGP (car
) || CONSP (car
))
4469 register int limit
= 50;
4470 /* LIMIT is to protect against circular lists. */
4471 while (CONSP (elt
) && --limit
> 0
4472 && hpos
< maxendcol
)
4474 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4477 elt
= XCONS (elt
)->cdr
;
4485 if (frame_title_ptr
)
4486 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
4488 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
4489 minendcol
, maxendcol
, 0);
4493 if (minendcol
> hpos
)
4494 if (frame_title_ptr
)
4495 hpos
= store_frame_title ("", minendcol
, maxendcol
);
4497 hpos
= display_string (w
, vpos
, "", 0, hpos
,
4498 0, 1, minendcol
, maxendcol
, 0);
4502 /* Write a null-terminated, right justified decimal representation of
4503 the positive integer D to BUF using a minimal field width WIDTH. */
4506 pint2str (buf
, width
, d
)
4511 register char *p
= buf
;
4518 *p
++ = d
% 10 + '0';
4521 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
4531 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4532 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4533 type of CODING_SYSTEM. Return updated pointer into BUF. */
4536 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
4537 Lisp_Object coding_system
;
4542 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
4544 val
= coding_system
;
4546 if (NILP (val
)) /* Not yet decided. */
4551 *buf
++ = eol_mnemonic_undecided
;
4552 /* Don't mention EOL conversion if it isn't decided. */
4556 Lisp_Object eolvalue
;
4558 eolvalue
= Fget (coding_system
, Qeol_type
);
4560 while (!NILP (val
) && SYMBOLP (val
))
4562 val
= Fget (val
, Qcoding_system
);
4563 if (NILP (eolvalue
))
4564 eolvalue
= Fget (val
, Qeol_type
);
4568 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
4572 /* The EOL conversion we are using. */
4574 /* The EOL conversion that is normal on this system. */
4576 if (NILP (eolvalue
)) /* Not yet decided. */
4577 eoltype
= eol_mnemonic_undecided
;
4578 else if (VECTORP (eolvalue
)) /* Not yet decided. */
4579 eoltype
= eol_mnemonic_undecided
;
4580 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4581 eoltype
= (XFASTINT (eolvalue
) == 0
4583 : (XFASTINT (eolvalue
) == 1
4584 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
4586 /* Mention the EOL conversion if it is not the usual one. */
4593 /* Return a string for the output of a mode line %-spec for window W,
4594 generated by character C. SPEC_WIDTH is the field width when
4595 padding to the left (%c, %l). The value returned from this
4596 function will later be truncated to width MAXWIDTH. */
4598 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4601 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
4604 register int spec_width
;
4605 register int maxwidth
;
4608 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4609 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
4610 struct buffer
*b
= XBUFFER (w
->buffer
);
4613 if (maxwidth
> FRAME_WIDTH (f
))
4614 maxwidth
= FRAME_WIDTH (f
);
4619 if (!NILP (b
->read_only
))
4621 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4626 /* This differs from %* only for a modified read-only buffer. */
4627 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4629 if (!NILP (b
->read_only
))
4634 /* This differs from %* in ignoring read-only-ness. */
4635 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4647 if (command_loop_level
> 5)
4649 p
= decode_mode_spec_buf
;
4650 for (i
= 0; i
< command_loop_level
; i
++)
4653 return decode_mode_spec_buf
;
4661 if (command_loop_level
> 5)
4663 p
= decode_mode_spec_buf
;
4664 for (i
= 0; i
< command_loop_level
; i
++)
4667 return decode_mode_spec_buf
;
4675 if (maxwidth
< sizeof (lots_of_dashes
))
4676 return lots_of_dashes
;
4679 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
4683 return decode_mode_spec_buf
;
4689 if (maxwidth
>= 3 && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4691 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
4692 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
4693 decode_mode_spec_buf
[maxwidth
] = '\0';
4694 return decode_mode_spec_buf
;
4701 int col
= current_column ();
4702 XSETFASTINT (w
->column_number_displayed
, col
);
4703 pint2str (decode_mode_spec_buf
, spec_width
, col
);
4704 return decode_mode_spec_buf
;
4708 /* %F displays the frame name. */
4709 /* Systems that can only display a single frame at a time should
4710 NOT replace the frame name with the (constant) frame title,
4711 since then they won't be able to tell which frame is that. */
4712 if (FRAME_WINDOW_P (f
) && !NILP (f
->title
))
4713 return (char *) XSTRING (f
->title
)->data
;
4714 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
4715 return (char *) XSTRING (f
->name
)->data
;
4723 else if (STRINGP (obj
) && STRING_BYTES (XSTRING (obj
)) > maxwidth
)
4725 bcopy ("...", decode_mode_spec_buf
, 3);
4726 bcopy (XSTRING (obj
)->data
+ STRING_BYTES (XSTRING (obj
)) - maxwidth
+ 3,
4727 decode_mode_spec_buf
+ 3, maxwidth
- 3);
4728 return decode_mode_spec_buf
;
4735 int startpos
= XMARKER (w
->start
)->charpos
;
4736 int startpos_byte
= marker_byte_position (w
->start
);
4737 int line
, linepos
, linepos_byte
, topline
;
4740 int height
= XFASTINT (w
->height
);
4742 /* If we decided that this buffer isn't suitable for line numbers,
4743 don't forget that too fast. */
4744 if (EQ (w
->base_line_pos
, w
->buffer
))
4746 /* But do forget it, if the window shows a different buffer now. */
4747 else if (BUFFERP (w
->base_line_pos
))
4748 w
->base_line_pos
= Qnil
;
4750 /* If the buffer is very big, don't waste time. */
4751 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
4753 w
->base_line_pos
= Qnil
;
4754 w
->base_line_number
= Qnil
;
4758 if (!NILP (w
->base_line_number
)
4759 && !NILP (w
->base_line_pos
)
4760 && XFASTINT (w
->base_line_pos
) <= startpos
)
4762 line
= XFASTINT (w
->base_line_number
);
4763 linepos
= XFASTINT (w
->base_line_pos
);
4764 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
4769 linepos
= BUF_BEGV (b
);
4770 linepos_byte
= BUF_BEGV_BYTE (b
);
4773 /* Count lines from base line to window start position. */
4774 nlines
= display_count_lines (linepos
, linepos_byte
,
4778 topline
= nlines
+ line
;
4780 /* Determine a new base line, if the old one is too close
4781 or too far away, or if we did not have one.
4782 "Too close" means it's plausible a scroll-down would
4784 if (startpos
== BUF_BEGV (b
))
4786 XSETFASTINT (w
->base_line_number
, topline
);
4787 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
4789 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
4790 || linepos
== BUF_BEGV (b
))
4792 int limit
= BUF_BEGV (b
);
4793 int limit_byte
= BUF_BEGV_BYTE (b
);
4795 int distance
= (height
* 2 + 30) * 200;
4797 if (startpos
- distance
> limit
)
4799 limit
= startpos
- distance
;
4800 limit_byte
= CHAR_TO_BYTE (limit
);
4803 nlines
= display_count_lines (startpos
, startpos_byte
,
4805 - (height
* 2 + 30),
4807 /* If we couldn't find the lines we wanted within
4809 give up on line numbers for this window. */
4810 if (position
== limit_byte
&& limit
== startpos
- distance
)
4812 w
->base_line_pos
= w
->buffer
;
4813 w
->base_line_number
= Qnil
;
4817 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
4818 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
4821 /* Now count lines from the start pos to point. */
4822 nlines
= display_count_lines (startpos
, startpos_byte
,
4823 PT_BYTE
, PT
, &junk
);
4825 /* Record that we did display the line number. */
4826 line_number_displayed
= 1;
4828 /* Make the string to show. */
4829 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
4830 return decode_mode_spec_buf
;
4833 char* p
= decode_mode_spec_buf
;
4834 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
4836 return decode_mode_spec_buf
;
4846 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
4852 int pos
= marker_position (w
->start
);
4853 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4855 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
4857 if (pos
<= BUF_BEGV (b
))
4862 else if (pos
<= BUF_BEGV (b
))
4866 if (total
> 1000000)
4867 /* Do it differently for a large value, to avoid overflow. */
4868 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4870 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4871 /* We can't normally display a 3-digit number,
4872 so get us a 2-digit number that is close. */
4875 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4876 return decode_mode_spec_buf
;
4880 /* Display percentage of size above the bottom of the screen. */
4883 int toppos
= marker_position (w
->start
);
4884 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
4885 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4887 if (botpos
>= BUF_ZV (b
))
4889 if (toppos
<= BUF_BEGV (b
))
4896 if (total
> 1000000)
4897 /* Do it differently for a large value, to avoid overflow. */
4898 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4900 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4901 /* We can't normally display a 3-digit number,
4902 so get us a 2-digit number that is close. */
4905 if (toppos
<= BUF_BEGV (b
))
4906 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
4908 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4909 return decode_mode_spec_buf
;
4914 /* status of process */
4915 obj
= Fget_buffer_process (w
->buffer
);
4917 return "no process";
4919 obj
= Fsymbol_name (Fprocess_status (obj
));
4923 case 't': /* indicate TEXT or BINARY */
4924 #ifdef MODE_LINE_BINARY_TEXT
4925 return MODE_LINE_BINARY_TEXT (b
);
4931 /* coding-system (not including end-of-line format) */
4933 /* coding-system (including end-of-line type) */
4935 int eol_flag
= (c
== 'Z');
4936 char *p
= decode_mode_spec_buf
;
4938 if (! FRAME_WINDOW_P (f
))
4940 /* No need to mention EOL here--the terminal never needs
4941 to do EOL conversion. */
4942 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
4943 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
4945 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
4948 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
4950 obj
= Fget_buffer_process (Fcurrent_buffer ());
4953 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
4955 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
4958 #endif /* subprocesses */
4961 return decode_mode_spec_buf
;
4966 return (char *) XSTRING (obj
)->data
;
4971 /* Count up to COUNT lines starting from START / START_BYTE.
4972 But don't go beyond LIMIT_BYTE.
4973 Return the number of lines thus found (always nonnegative).
4975 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
4978 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
4979 int start
, start_byte
, limit_byte
, count
;
4982 register unsigned char *cursor
;
4983 unsigned char *base
;
4985 register int ceiling
;
4986 register unsigned char *ceiling_addr
;
4987 int orig_count
= count
;
4989 /* If we are not in selective display mode,
4990 check only for newlines. */
4991 int selective_display
= (!NILP (current_buffer
->selective_display
)
4992 && !INTEGERP (current_buffer
->selective_display
));
4996 while (start_byte
< limit_byte
)
4998 ceiling
= BUFFER_CEILING_OF (start_byte
);
4999 ceiling
= min (limit_byte
- 1, ceiling
);
5000 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
5001 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
5004 if (selective_display
)
5005 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
5008 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
5011 if (cursor
!= ceiling_addr
)
5015 start_byte
+= cursor
- base
+ 1;
5016 *byte_pos_ptr
= start_byte
;
5020 if (++cursor
== ceiling_addr
)
5026 start_byte
+= cursor
- base
;
5031 while (start_byte
> limit_byte
)
5033 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
5034 ceiling
= max (limit_byte
, ceiling
);
5035 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
5036 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
5039 if (selective_display
)
5040 while (--cursor
!= ceiling_addr
5041 && *cursor
!= '\n' && *cursor
!= 015)
5044 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
5047 if (cursor
!= ceiling_addr
)
5051 start_byte
+= cursor
- base
+ 1;
5052 *byte_pos_ptr
= start_byte
;
5053 /* When scanning backwards, we should
5054 not count the newline posterior to which we stop. */
5055 return - orig_count
- 1;
5061 /* Here we add 1 to compensate for the last decrement
5062 of CURSOR, which took it past the valid range. */
5063 start_byte
+= cursor
- base
+ 1;
5067 *byte_pos_ptr
= limit_byte
;
5070 return - orig_count
+ count
;
5071 return orig_count
- count
;
5075 /* Display STRING on one line of window W, starting at HPOS.
5076 Display at position VPOS. Caller should have done get_display_line.
5077 If VPOS == -1, display it as the current frame's title.
5078 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
5080 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
5082 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
5083 MAXCOL is the last column ok to end at. Truncate here.
5084 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
5085 Both count from the left edge of the frame, as does HPOS.
5086 The right edge of W is an implicit maximum.
5087 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
5089 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
5090 at the place where the current window ends in this line
5091 and not display anything beyond there. Otherwise, only MAXCOL
5092 controls where to stop output.
5094 MULTIBYTE can be 0 meaning do not display multibyte chars,
5095 1 meaning do display them, or -1 meaning obey the current buffer's
5096 value of enable_multibyte_characters.
5098 Returns ending hpos. */
5101 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
5102 obey_window_width
, mincol
, maxcol
, multibyte
)
5104 unsigned char *string
;
5108 int obey_window_width
;
5115 int hscroll
= XINT (w
->hscroll
);
5116 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
5117 register GLYPH
*start
;
5118 register GLYPH
*end
;
5119 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
5120 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
5121 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
5122 int window_width
= XFASTINT (w
->width
);
5124 /* Use the standard display table, not the window's display table.
5125 We don't want the mode line in rot13. */
5126 register struct Lisp_Char_Table
*dp
= 0;
5129 if (multibyte
== -1)
5130 multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
5131 /* Now multibyte is 1 if we should display multibyte characters. */
5133 if (DISP_TABLE_P (Vstandard_display_table
))
5134 dp
= XCHAR_TABLE (Vstandard_display_table
);
5136 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
5139 start
= desired_glyphs
->glyphs
[vpos
];
5141 if (obey_window_width
)
5143 start
+= XFASTINT (w
->left
);
5144 end
= start
+ window_width
- (truncate
!= 0);
5146 if (!WINDOW_RIGHTMOST_P (w
))
5148 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5152 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
5155 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5160 if (! obey_window_width
5161 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
5162 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
5164 /* Store 0 in charstart for these columns. */
5165 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
5166 desired_glyphs
->charstarts
[vpos
][i
] = 0;
5168 if (maxcol
>= 0 && mincol
> maxcol
)
5172 /* We need this value for multibyte characters. */
5173 length
= strlen (string
);
5175 /* We set truncated to 1 if we get stopped by trying to pass END
5176 (that is, trying to pass MAXCOL.) */
5185 c
= STRING_CHAR_AND_LENGTH (string
, length
, len
);
5187 c
= *string
, len
= 1;
5189 string
+= len
, length
-= len
;
5197 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
5199 p1
= copy_part_of_rope (f
, p1
, start
,
5200 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
5201 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
5204 else if (c
>= 040 && c
< 0177)
5214 if (p1
>= start
&& p1
< end
)
5218 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
5220 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
5224 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
5225 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
5226 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
5229 if (p1
>= start
&& p1
< end
)
5235 /* C is a control character or a binary byte data. */
5238 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
5239 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
5240 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
5243 if (p1
>= start
&& p1
< end
)
5244 *p1
= (c
>> 6) + '0';
5246 if (p1
>= start
&& p1
< end
)
5247 *p1
= (7 & (c
>> 3)) + '0';
5249 if (p1
>= start
&& p1
< end
)
5250 *p1
= (7 & c
) + '0';
5255 /* C is a multibyte character. */
5256 int charset
= CHAR_CHARSET (c
);
5257 int columns
= (charset
== CHARSET_COMPOSITION
5258 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
5259 : CHARSET_WIDTH (charset
));
5263 /* Since we can't show the left part of C, fill all
5264 columns with spaces. */
5265 columns
-= start
- p1
;
5274 else if (p1
+ columns
> end
)
5276 /* Since we can't show the right part of C, fill all
5277 columns with TRUNCATE if TRUNCATE is specified. */
5281 *p1
++ = fix_glyph (f
, truncate
, 0);
5282 /* And tell the line is truncated. */
5289 /* We can show the whole glyph of C. */
5292 *p1
++ = c
| GLYPH_MASK_PADDING
;
5300 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
5302 else if (mincol
>= 0)
5304 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
5310 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
5312 if (len
> desired_glyphs
->used
[vpos
])
5313 desired_glyphs
->used
[vpos
] = len
;
5314 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
5320 /* This is like a combination of memq and assq.
5321 Return 1 if PROPVAL appears as an element of LIST
5322 or as the car of an element of LIST.
5323 If PROPVAL is a list, compare each element against LIST
5324 in that way, and return 1 if any element of PROPVAL is found in LIST.
5326 This function cannot quit. */
5329 invisible_p (propval
, list
)
5330 register Lisp_Object propval
;
5333 register Lisp_Object tail
, proptail
;
5334 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5336 register Lisp_Object tem
;
5337 tem
= XCONS (tail
)->car
;
5338 if (EQ (propval
, tem
))
5340 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5343 if (CONSP (propval
))
5344 for (proptail
= propval
; CONSP (proptail
);
5345 proptail
= XCONS (proptail
)->cdr
)
5347 Lisp_Object propelt
;
5348 propelt
= XCONS (proptail
)->car
;
5349 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5351 register Lisp_Object tem
;
5352 tem
= XCONS (tail
)->car
;
5353 if (EQ (propelt
, tem
))
5355 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5362 /* Return 1 if PROPVAL appears as the car of an element of LIST
5363 and the cdr of that element is non-nil.
5364 If PROPVAL is a list, check each element of PROPVAL in that way,
5365 and the first time some element is found,
5366 return 1 if the cdr of that element is non-nil.
5368 This function cannot quit. */
5371 invisible_ellipsis_p (propval
, list
)
5372 register Lisp_Object propval
;
5375 register Lisp_Object tail
, proptail
;
5376 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5378 register Lisp_Object tem
;
5379 tem
= XCONS (tail
)->car
;
5380 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5381 return ! NILP (XCONS (tem
)->cdr
);
5383 if (CONSP (propval
))
5384 for (proptail
= propval
; CONSP (proptail
);
5385 proptail
= XCONS (proptail
)->cdr
)
5387 Lisp_Object propelt
;
5388 propelt
= XCONS (proptail
)->car
;
5389 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5391 register Lisp_Object tem
;
5392 tem
= XCONS (tail
)->car
;
5393 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5394 return ! NILP (XCONS (tem
)->cdr
);
5403 staticpro (&Qmenu_bar_update_hook
);
5404 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
5406 staticpro (&Qoverriding_terminal_local_map
);
5407 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
5409 staticpro (&Qoverriding_local_map
);
5410 Qoverriding_local_map
= intern ("overriding-local-map");
5412 staticpro (&Qwindow_scroll_functions
);
5413 Qwindow_scroll_functions
= intern ("window-scroll-functions");
5415 staticpro (&Qredisplay_end_trigger_functions
);
5416 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
5418 staticpro (&Qinhibit_point_motion_hooks
);
5419 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
5421 staticpro (&last_arrow_position
);
5422 staticpro (&last_arrow_string
);
5423 last_arrow_position
= Qnil
;
5424 last_arrow_string
= Qnil
;
5426 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
5427 "String (or mode line construct) included (normally) in `mode-line-format'.");
5428 Vglobal_mode_string
= Qnil
;
5430 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
5431 "Marker for where to display an arrow on top of the buffer text.\n\
5432 This must be the beginning of a line in order to work.\n\
5433 See also `overlay-arrow-string'.");
5434 Voverlay_arrow_position
= Qnil
;
5436 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
5437 "String to display as an arrow. See also `overlay-arrow-position'.");
5438 Voverlay_arrow_string
= Qnil
;
5440 DEFVAR_INT ("scroll-step", &scroll_step
,
5441 "*The number of lines to try scrolling a window by when point moves out.\n\
5442 If that fails to bring point back on frame, point is centered instead.\n\
5443 If this is zero, point is always centered after it moves off frame.");
5445 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
5446 "*Scroll up to this many lines, to bring point back on screen.");
5447 scroll_conservatively
= 0;
5449 DEFVAR_INT ("scroll-margin", &scroll_margin
,
5450 "*Number of lines of margin at the top and bottom of a window.\n\
5451 Recenter the window whenever point gets within this many lines\n\
5452 of the top or bottom of the window.");
5455 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
5457 DEFVAR_BOOL ("truncate-partial-width-windows",
5458 &truncate_partial_width_windows
,
5459 "*Non-nil means truncate lines in all windows less than full frame wide.");
5460 truncate_partial_width_windows
= 1;
5462 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
5463 "*Non-nil means use inverse video for the mode line.");
5464 mode_line_inverse_video
= 1;
5466 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
5467 "*Maximum buffer size (in characters) for line number display\n\
5468 If the buffer is bigger than this, the line number does not appear\n\
5469 in the mode line..");
5470 line_number_display_limit
= 1000000;
5472 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
5473 "*Non-nil means highlight region even in nonselected windows.");
5474 highlight_nonselected_windows
= 0;
5476 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
5477 "Non-nil if more than one frame is visible on this display.\n\
5478 Minibuffer-only frames don't count, but iconified frames do.\n\
5479 This variable is not guaranteed to be accurate except while processing\n\
5480 `frame-title-format' and `icon-title-format'.");
5482 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
5483 "Template for displaying the titlebar of visible frames.\n\
5484 \(Assuming the window manager supports this feature.)\n\
5485 This variable has the same structure as `mode-line-format' (which see),\n\
5486 and is used only on frames for which no explicit name has been set\n\
5487 \(see `modify-frame-parameters').");
5488 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
5489 "Template for displaying the titlebar of an iconified frame.\n\
5490 \(Assuming the window manager supports this feature.)\n\
5491 This variable has the same structure as `mode-line-format' (which see),\n\
5492 and is used only on frames for which no explicit name has been set\n\
5493 \(see `modify-frame-parameters').");
5495 = Vframe_title_format
5496 = Fcons (intern ("multiple-frames"),
5497 Fcons (build_string ("%b"),
5498 Fcons (Fcons (build_string (""),
5499 Fcons (intern ("invocation-name"),
5500 Fcons (build_string ("@"),
5501 Fcons (intern ("system-name"),
5505 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
5506 "Maximum number of lines to keep in the message log buffer.\n\
5507 If nil, disable message logging. If t, log messages but don't truncate\n\
5508 the buffer when it becomes large.");
5509 XSETFASTINT (Vmessage_log_max
, 50);
5511 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
5512 "Functions called before redisplay, if window sizes have changed.\n\
5513 The value should be a list of functions that take one argument.\n\
5514 Just before redisplay, for each frame, if any of its windows have changed\n\
5515 size since the last redisplay, or have been split or deleted,\n\
5516 all the functions in the list are called, with the frame as argument.");
5517 Vwindow_size_change_functions
= Qnil
;
5519 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
5520 "List of functions to call before redisplaying a window with scrolling.\n\
5521 Each function is called with two arguments, the window\n\
5522 and its new display-start position. Note that the value of `window-end'\n\
5523 is not valid when these functions are called.");
5524 Vwindow_scroll_functions
= Qnil
;
5526 DEFVAR_INT ("minibuffer-scroll-overlap", &minibuffer_scroll_overlap
,
5527 "*Number of characters of overlap when scrolling a one-line window.\n\
5528 This commonly affects the minibuffer window, hence the name of the variable.");
5529 minibuffer_scroll_overlap
= 20;
5532 /* initialize the window system */
5536 Lisp_Object root_window
;
5537 #ifndef COMPILER_REGISTER_BUG
5539 #endif /* COMPILER_REGISTER_BUG */
5540 struct window
*mini_w
;
5542 this_line_bufpos
= 0;
5544 mini_w
= XWINDOW (minibuf_window
);
5545 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
5547 echo_area_glyphs
= 0;
5548 previous_echo_glyphs
= 0;
5550 if (!noninteractive
)
5552 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
5553 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_MENU_BAR_LINES (f
));
5554 set_window_height (root_window
,
5555 FRAME_HEIGHT (f
) - 1 - FRAME_MENU_BAR_LINES (f
),
5557 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
5558 set_window_height (minibuf_window
, 1, 0);
5560 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
5561 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));