1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 1997
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"
44 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
45 extern void set_frame_menubar ();
46 extern int pending_menu_activation
;
49 extern int interrupt_input
;
50 extern int command_loop_level
;
52 extern int minibuffer_auto_raise
;
54 extern Lisp_Object Qface
;
56 extern Lisp_Object Voverriding_local_map
;
57 extern Lisp_Object Voverriding_local_map_menu_flag
;
59 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
60 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
61 Lisp_Object Qredisplay_end_trigger_functions
;
63 /* Nonzero means print newline to stdout before next minibuffer message. */
65 int noninteractive_need_newline
;
67 /* Nonzero means print newline to message log before next message. */
69 static int message_log_need_newline
;
71 #define min(a, b) ((a) < (b) ? (a) : (b))
72 #define max(a, b) ((a) > (b) ? (a) : (b))
73 #define minmax(floor, val, ceil) \
74 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
76 /* The buffer position of the first character appearing
77 entirely or partially on the current frame line.
78 Or zero, which disables the optimization for the current frame line. */
79 static int this_line_bufpos
;
81 /* Number of characters past the end of this line,
82 including the terminating newline */
83 static int this_line_endpos
;
85 /* The vertical position of this frame line. */
86 static int this_line_vpos
;
88 /* Hpos value for start of display on this frame line.
89 Usually zero, but negative if first character really began
91 static int this_line_start_hpos
;
93 /* Buffer that this_line variables are describing. */
94 static struct buffer
*this_line_buffer
;
96 /* Value of echo_area_glyphs when it was last acted on.
97 If this is nonzero, there is a message on the frame
98 in the minibuffer and it should be erased as soon
99 as it is no longer requested to appear. */
100 char *previous_echo_glyphs
;
102 /* Nonzero means truncate lines in all windows less wide than the frame */
103 int truncate_partial_width_windows
;
105 /* Nonzero means we have more than one non-minibuffer-only frame.
106 Not guaranteed to be accurate except while parsing frame-title-format. */
109 Lisp_Object Vglobal_mode_string
;
111 /* Marker for where to display an arrow on top of the buffer text. */
112 Lisp_Object Voverlay_arrow_position
;
114 /* String to display for the arrow. */
115 Lisp_Object Voverlay_arrow_string
;
117 /* Values of those variables at last redisplay.
118 However, if Voverlay_arrow_position is a marker,
119 last_arrow_position is its numerical position. */
120 static Lisp_Object last_arrow_position
, last_arrow_string
;
122 /* Like mode-line-format, but for the titlebar on a visible frame. */
123 Lisp_Object Vframe_title_format
;
125 /* Like mode-line-format, but for the titlebar on an iconified frame. */
126 Lisp_Object Vicon_title_format
;
128 /* List of functions to call when a window's size changes. These
129 functions get one arg, a frame on which one or more windows' sizes
131 static Lisp_Object Vwindow_size_change_functions
;
133 Lisp_Object Qmenu_bar_update_hook
;
135 /* Nonzero if overlay arrow has been displayed once in this window. */
136 static int overlay_arrow_seen
;
138 /* Nonzero if visible end of buffer has already been displayed once
139 in this window. (We need this variable in case there are overlay
140 strings that get displayed there.) */
141 static int zv_strings_seen
;
143 /* Nonzero means highlight the region even in nonselected windows. */
144 static int highlight_nonselected_windows
;
146 /* If cursor motion alone moves point off frame,
147 Try scrolling this many lines up or down if that will bring it back. */
148 static int scroll_step
;
150 /* Non-0 means scroll just far enough to bring point back on the screen,
152 static int scroll_conservatively
;
154 /* Recenter the window whenever point gets within this many lines
155 of the top or bottom of the window. */
158 /* Nonzero if try_window_id has made blank lines at window bottom
159 since the last redisplay that paused */
160 static int blank_end_of_window
;
162 /* Number of windows showing the buffer of the selected window
163 (or another buffer with the same base buffer).
164 keyboard.c refers to this. */
167 /* display_text_line sets these to the frame position (origin 0) of point,
168 whether the window is selected or not.
169 Set one to -1 first to determine whether point was found afterwards. */
171 static int cursor_vpos
;
172 static int cursor_hpos
;
174 static int debug_end_pos
;
176 /* Nonzero means display mode line highlighted */
177 int mode_line_inverse_video
;
179 static void redisplay_internal ();
180 static int message_log_check_duplicate ();
181 static void echo_area_display ();
182 void mark_window_display_accurate ();
183 static void redisplay_windows ();
184 static void redisplay_window ();
185 static void update_menu_bar ();
186 static void try_window ();
187 static int try_window_id ();
188 static struct position
*display_text_line ();
189 static void display_mode_line ();
190 static int display_mode_element ();
191 static char *decode_mode_spec ();
192 static int display_string ();
193 static void display_menu_bar ();
194 static int display_count_lines ();
196 /* Prompt to display in front of the minibuffer contents */
197 Lisp_Object minibuf_prompt
;
199 /* Width in columns of current minibuffer prompt. */
200 int minibuf_prompt_width
;
202 /* Message to display instead of minibuffer contents
203 This is what the functions error and message make,
204 and command echoing uses it as well.
205 It overrides the minibuf_prompt as well as the buffer. */
206 char *echo_area_glyphs
;
208 /* This is the length of the message in echo_area_glyphs. */
209 int echo_area_glyphs_length
;
211 /* This is the window where the echo area message was displayed.
212 It is always a minibuffer window, but it may not be the
213 same window currently active as a minibuffer. */
214 Lisp_Object echo_area_window
;
216 /* true iff we should redraw the mode lines on the next redisplay */
217 int update_mode_lines
;
219 /* Smallest number of characters before the gap
220 at any time since last redisplay that finished.
221 Valid for current buffer when try_window_id can be called. */
224 /* Smallest number of characters after the gap
225 at any time since last redisplay that finished.
226 Valid for current buffer when try_window_id can be called. */
229 /* MODIFF as of last redisplay that finished;
230 if it matches MODIFF, and overlay_unchanged_modified
231 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
232 contain no useful information */
233 int unchanged_modified
;
235 /* OVERLAY_MODIFF as of last redisplay that finished. */
236 int overlay_unchanged_modified
;
238 /* Nonzero if window sizes or contents have changed
239 since last redisplay that finished */
240 int windows_or_buffers_changed
;
242 /* Nonzero after display_mode_line if %l was used
243 and it displayed a line number. */
244 int line_number_displayed
;
246 /* Maximum buffer size for which to display line numbers. */
247 static int line_number_display_limit
;
249 /* Number of lines to keep in the message log buffer.
250 t means infinite. nil means don't log at all. */
251 Lisp_Object Vmessage_log_max
;
253 #define COERCE_MARKER(X) \
254 (MARKERP ((X)) ? Fmarker_position (X) : (X))
256 /* Output a newline in the *Messages* buffer if "needs" one. */
259 message_log_maybe_newline ()
261 if (message_log_need_newline
)
262 message_dolog ("", 0, 1);
266 /* Add a string to the message log, optionally terminated with a newline.
267 This function calls low-level routines in order to bypass text property
268 hooks, etc. which might not be safe to run. */
271 message_dolog (m
, len
, nlflag
)
275 if (!NILP (Vmessage_log_max
))
277 struct buffer
*oldbuf
;
278 int oldpoint
, oldbegv
, oldzv
;
279 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
281 oldbuf
= current_buffer
;
282 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
283 current_buffer
->undo_list
= Qt
;
290 oldpoint
+= len
+ nlflag
;
292 oldzv
+= len
+ nlflag
;
295 insert_1 (m
, len
, 1, 0);
298 int this_bol
, prev_bol
, dup
;
299 insert_1 ("\n", 1, 1, 0);
301 this_bol
= scan_buffer ('\n', Z
, 0, -2, 0, 0);
304 prev_bol
= scan_buffer ('\n', this_bol
, 0, -2, 0, 0);
305 dup
= message_log_check_duplicate (prev_bol
, this_bol
);
308 if (oldpoint
> prev_bol
)
309 oldpoint
-= min (this_bol
, oldpoint
) - prev_bol
;
310 if (oldbegv
> prev_bol
)
311 oldbegv
-= min (this_bol
, oldbegv
) - prev_bol
;
312 if (oldzv
> prev_bol
)
313 oldzv
-= min (this_bol
, oldzv
) - prev_bol
;
314 del_range_1 (prev_bol
, this_bol
, 0);
320 /* If you change this format, don't forget to also
321 change message_log_check_duplicate. */
322 sprintf (dupstr
, " [%d times]", dup
);
323 duplen
= strlen (dupstr
);
329 insert_1 (dupstr
, duplen
, 1, 0);
334 if (NATNUMP (Vmessage_log_max
))
336 int pos
= scan_buffer ('\n', Z
, 0,
337 -XFASTINT (Vmessage_log_max
) - 1, 0, 0);
338 oldpoint
-= min (pos
, oldpoint
) - BEG
;
339 oldbegv
-= min (pos
, oldbegv
) - BEG
;
340 oldzv
-= min (pos
, oldzv
) - BEG
;
341 del_range_1 (BEG
, pos
, 0);
346 TEMP_SET_PT (oldpoint
);
347 set_buffer_internal (oldbuf
);
348 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
349 message_log_need_newline
= !nlflag
;
353 /* We are at the end of the buffer after just having inserted a newline.
354 (Note: We depend on the fact we won't be crossing the gap.)
355 Check to see if the most recent message looks a lot like the previous one.
356 Return 0 if different, 1 if the new one should just replace it, or a
357 value N > 1 if we should also append " [N times]". */
360 message_log_check_duplicate (prev_bol
, this_bol
)
361 int prev_bol
, this_bol
;
364 int len
= Z
- 1 - this_bol
;
366 unsigned char *p1
= BUF_CHAR_ADDRESS (current_buffer
, prev_bol
);
367 unsigned char *p2
= BUF_CHAR_ADDRESS (current_buffer
, this_bol
);
369 for (i
= 0; i
< len
; i
++)
371 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
380 if (*p1
++ == ' ' && *p1
++ == '[')
383 while (*p1
>= '0' && *p1
<= '9')
384 n
= n
* 10 + *p1
++ - '0';
385 if (strncmp (p1
, " times]\n", 8) == 0)
391 /* Display an echo area message M with a specified length of LEN chars.
392 The string may include null characters. If M is 0, clear out any
393 existing message, and let the minibuffer text show through.
395 The buffer M must continue to exist until after the echo area
396 gets cleared or some other message gets displayed there.
398 Do not pass text that is stored in a Lisp string.
399 Do not pass text in a buffer that was alloca'd. */
406 /* First flush out any partial line written with print. */
407 message_log_maybe_newline ();
409 message_dolog (m
, len
, 1);
410 message2_nolog (m
, len
);
414 /* The non-logging counterpart of message2. */
417 message2_nolog (m
, len
)
423 if (noninteractive_need_newline
)
425 noninteractive_need_newline
= 0;
427 fwrite (m
, len
, 1, stderr
);
428 if (cursor_in_echo_area
== 0)
429 fprintf (stderr
, "\n");
432 /* A null message buffer means that the frame hasn't really been
433 initialized yet. Error messages get reported properly by
434 cmd_error, so this must be just an informative message; toss it. */
435 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
437 Lisp_Object mini_window
;
440 /* Get the frame containing the minibuffer
441 that the selected frame is using. */
442 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
443 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
445 FRAME_SAMPLE_VISIBILITY (f
);
446 if (FRAME_VISIBLE_P (selected_frame
)
447 && ! FRAME_VISIBLE_P (f
))
448 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
452 echo_area_glyphs
= m
;
453 echo_area_glyphs_length
= len
;
455 if (minibuffer_auto_raise
)
456 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
459 echo_area_glyphs
= previous_echo_glyphs
= 0;
461 do_pending_window_change ();
462 echo_area_display ();
463 update_frame (f
, 1, 1);
464 do_pending_window_change ();
465 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
466 (*frame_up_to_date_hook
) (f
);
470 /* Display a null-terminated echo area message M. If M is 0, clear out any
471 existing message, and let the minibuffer text show through.
473 The buffer M must continue to exist until after the echo area
474 gets cleared or some other message gets displayed there.
476 Do not pass text that is stored in a Lisp string.
477 Do not pass text in a buffer that was alloca'd. */
483 message2 (m
, (m
? strlen (m
) : 0));
490 message2_nolog (m
, (m
? strlen (m
) : 0));
493 /* Truncate what will be displayed in the echo area
494 the next time we display it--but don't redisplay it now. */
497 truncate_echo_area (len
)
500 /* A null message buffer means that the frame hasn't really been
501 initialized yet. Error messages get reported properly by
502 cmd_error, so this must be just an informative message; toss it. */
503 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
504 echo_area_glyphs_length
= len
;
507 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
508 zero if being used by message. */
509 int message_buf_print
;
511 /* Dump an informative message to the minibuf. If M is 0, clear out
512 any existing message, and let the minibuffer text show through. */
516 message (m
, a1
, a2
, a3
)
518 EMACS_INT a1
, a2
, a3
;
524 if (noninteractive_need_newline
)
526 noninteractive_need_newline
= 0;
527 fprintf (stderr
, m
, a1
, a2
, a3
);
528 if (cursor_in_echo_area
== 0)
529 fprintf (stderr
, "\n");
533 else if (INTERACTIVE
)
535 /* The frame whose minibuffer we're going to display the message on.
536 It may be larger than the selected frame, so we need
537 to use its buffer, not the selected frame's buffer. */
538 Lisp_Object mini_window
;
541 /* Get the frame containing the minibuffer
542 that the selected frame is using. */
543 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
544 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
546 /* A null message buffer means that the frame hasn't really been
547 initialized yet. Error messages get reported properly by
548 cmd_error, so this must be just an informative message; toss it. */
549 if (FRAME_MESSAGE_BUF (f
))
560 len
= doprnt (FRAME_MESSAGE_BUF (f
),
561 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
563 len
= doprnt (FRAME_MESSAGE_BUF (f
),
564 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, &a1
);
565 #endif /* NO_ARG_ARRAY */
567 message2 (FRAME_MESSAGE_BUF (f
), len
);
572 /* Print should start at the beginning of the message
574 message_buf_print
= 0;
579 /* The non-logging version of message. */
581 message_nolog (m
, a1
, a2
, a3
)
583 EMACS_INT a1
, a2
, a3
;
585 Lisp_Object old_log_max
;
586 old_log_max
= Vmessage_log_max
;
587 Vmessage_log_max
= Qnil
;
588 message (m
, a1
, a2
, a3
);
589 Vmessage_log_max
= old_log_max
;
595 message2 (echo_area_glyphs
, echo_area_glyphs_length
);
603 Lisp_Object mini_window
;
605 /* Choose the minibuffer window for this display.
606 It is the minibuffer window used by the selected frame. */
607 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
608 /* This is the frame that window is in. */
609 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
611 if (! FRAME_VISIBLE_P (f
))
616 redraw_garbaged_frames ();
620 if (echo_area_glyphs
|| minibuf_level
== 0)
624 echo_area_window
= mini_window
;
626 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
627 get_display_line (f
, vpos
, 0);
629 /* Make sure the columns that overlap a left-hand scroll bar
631 for (i
= 0; i
< FRAME_LEFT_SCROLL_BAR_WIDTH (f
); i
++)
632 f
->desired_glyphs
->glyphs
[vpos
][i
] = SPACEGLYPH
;
634 display_string (XWINDOW (mini_window
), vpos
,
635 echo_area_glyphs
? echo_area_glyphs
: "",
636 echo_area_glyphs
? echo_area_glyphs_length
: -1,
637 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
639 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
));
641 #if 0 /* This just gets in the way. update_frame does the job. */
642 /* If desired cursor location is on this line, put it at end of text */
643 if (cursor_in_echo_area
)
644 FRAME_CURSOR_Y (f
) = vpos
;
645 if (FRAME_CURSOR_Y (f
) == vpos
)
646 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
649 /* Fill the rest of the minibuffer window with blank lines. */
654 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
656 get_display_line (f
, i
, 0);
657 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
658 hpos, because it is good to clear whatever is behind the
659 scroll bar. This does not affect the scroll bar itself. */
660 display_string (XWINDOW (mini_window
), i
,
663 0, FRAME_WIDTH (f
) + FRAME_SCROLL_BAR_WIDTH (f
));
667 else if (!EQ (mini_window
, selected_window
))
668 windows_or_buffers_changed
++;
670 if (EQ (mini_window
, selected_window
))
671 this_line_bufpos
= 0;
673 previous_echo_glyphs
= echo_area_glyphs
;
676 /* Update frame titles. */
678 #ifdef HAVE_WINDOW_SYSTEM
679 static char frame_title_buf
[512];
680 static char *frame_title_ptr
;
683 store_frame_title (str
, mincol
, maxcol
)
688 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
689 maxcol
= sizeof (frame_title_buf
);
690 limit
= &frame_title_buf
[maxcol
];
691 while (*str
!= '\0' && frame_title_ptr
< limit
)
692 *frame_title_ptr
++ = *str
++;
693 while (frame_title_ptr
< &frame_title_buf
[mincol
])
694 *frame_title_ptr
++ = ' ';
695 return frame_title_ptr
- frame_title_buf
;
699 x_consider_frame_title (frame
)
705 FRAME_PTR f
= XFRAME (frame
);
707 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
710 /* Do we have more than one visible frame on this X display? */
714 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
716 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
718 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
719 && !FRAME_MINIBUF_ONLY_P (tf
)
720 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
724 multiple_frames
= CONSP (tail
);
727 obuf
= current_buffer
;
728 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
729 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
730 frame_title_ptr
= frame_title_buf
;
731 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
732 0, sizeof (frame_title_buf
), fmt
);
734 set_buffer_internal (obuf
);
735 /* Set the name only if it's changed. This avoids consing
736 in the common case where it hasn't. (If it turns out that we've
737 already wasted too much time by walking through the list with
738 display_mode_element, then we might need to optimize at a higher
740 if (! STRINGP (f
->name
) || XSTRING (f
->name
)->size
!= len
741 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
742 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
745 #define frame_title_ptr ((char *)0)
746 #define store_frame_title(str, mincol, maxcol) 0
749 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
750 This can call eval. */
755 register struct window
*w
= XWINDOW (selected_window
);
757 struct gcpro gcpro1
, gcpro2
;
759 all_windows
= (update_mode_lines
|| buffer_shared
> 1
760 || windows_or_buffers_changed
);
762 /* Update all frame titles based on their buffer names, etc.
763 We do this before the menu bars so that the buffer-menu
764 will show the up-to-date frame titles.
766 This used to be done after the menu bars, for a reason that
767 was stated as follows but which I do not understand:
768 "We do this after the menu bars so that the frame will first
769 create its menu bar using the name `emacs' if no other name
770 has yet been specified."
771 I think that is no longer a concern. */
772 #ifdef HAVE_WINDOW_SYSTEM
773 if (windows_or_buffers_changed
|| update_mode_lines
)
775 Lisp_Object tail
, frame
;
777 FOR_EACH_FRAME (tail
, frame
)
778 if (FRAME_VISIBLE_P (XFRAME (frame
))
779 || FRAME_ICONIFIED_P (XFRAME (frame
)))
780 x_consider_frame_title (frame
);
784 /* Update the menu bar item lists, if appropriate.
785 This has to be done before any actual redisplay
786 or generation of display lines. */
789 Lisp_Object tail
, frame
;
790 int count
= specpdl_ptr
- specpdl
;
792 record_unwind_protect (Fstore_match_data
, Fmatch_data (Qnil
, Qnil
));
794 FOR_EACH_FRAME (tail
, frame
)
796 /* If a window on this frame changed size,
797 report that to the user and clear the size-change flag. */
798 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
800 Lisp_Object functions
;
801 /* Clear flag first in case we get error below. */
802 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
803 functions
= Vwindow_size_change_functions
;
804 GCPRO2 (tail
, functions
);
805 while (CONSP (functions
))
807 call1 (XCONS (functions
)->car
, frame
);
808 functions
= XCONS (functions
)->cdr
;
813 update_menu_bar (XFRAME (frame
), 0);
817 unbind_to (count
, Qnil
);
820 update_menu_bar (selected_frame
, 1);
822 /* Motif needs this. See comment in xmenu.c.
823 Turn it off when pending_menu_activation is not defined. */
825 pending_menu_activation
= 0;
829 /* Do a frame update, taking possible shortcuts into account.
830 This is the main external entry point for redisplay.
832 If the last redisplay displayed an echo area message and that
833 message is no longer requested, we clear the echo area
834 or bring back the minibuffer if that is in use.
836 Do not call eval from within this function.
837 Calls to eval after the call to echo_area_display would confuse
838 the display_line mechanism and would cause a crash.
839 Calls to eval before that point will work most of the time,
840 but can still lose, because this function
841 can be called from signal handlers; with alarms set up;
842 or with synchronous processes running.
844 See Fcall_process; if you called it from here, it could be
845 entered recursively. */
847 static int do_verify_charstarts
;
849 /* Counter is used to clear the face cache
850 no more than once ever 1000 redisplays. */
851 static int clear_face_cache_count
;
853 /* Record the previous terminal frame we displayed. */
854 static FRAME_PTR previous_terminal_frame
;
859 redisplay_internal (0);
862 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
863 is not in response to any user action; therefore, we should
864 preserve the echo area. (Actually, our caller does that job.)
865 Perhaps in the future avoid recentering windows
866 if it is not necessary; currently that causes some problems. */
869 redisplay_internal (preserve_echo_area
)
870 int preserve_echo_area
;
872 register struct window
*w
= XWINDOW (selected_window
);
876 register int tlbufpos
, tlendpos
;
878 int number_of_visible_frames
;
884 if (popup_activated ())
890 if (! FRAME_WINDOW_P (selected_frame
)
891 && previous_terminal_frame
!= selected_frame
)
893 /* Since frames on an ASCII terminal share the same display area,
894 displaying a different frame means redisplay the whole thing. */
895 windows_or_buffers_changed
++;
896 SET_FRAME_GARBAGED (selected_frame
);
897 XSETFRAME (Vterminal_frame
, selected_frame
);
899 previous_terminal_frame
= selected_frame
;
901 /* Set the visible flags for all frames.
902 Do this before checking for resized or garbaged frames; they want
903 to know if their frames are visible.
904 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
906 Lisp_Object tail
, frame
;
908 number_of_visible_frames
= 0;
910 FOR_EACH_FRAME (tail
, frame
)
912 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
914 if (FRAME_VISIBLE_P (XFRAME (frame
)))
915 number_of_visible_frames
++;
917 /* Clear out all the display lines in which we will generate the
918 glyphs to display. */
919 init_desired_glyphs (XFRAME (frame
));
923 /* Notice any pending interrupt request to change frame size. */
924 do_pending_window_change ();
928 redraw_garbaged_frames ();
932 prepare_menu_bars ();
934 if (windows_or_buffers_changed
)
937 /* Detect case that we need to write or remove a star in the mode line. */
938 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
940 w
->update_mode_line
= Qt
;
941 if (buffer_shared
> 1)
945 /* If %c is in use, update it if needed. */
946 if (!NILP (w
->column_number_displayed
)
947 /* This alternative quickly identifies a common case
948 where no change is needed. */
949 && !(PT
== XFASTINT (w
->last_point
)
950 && XFASTINT (w
->last_modified
) >= MODIFF
951 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
952 && XFASTINT (w
->column_number_displayed
) != current_column ())
953 w
->update_mode_line
= Qt
;
955 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
957 all_windows
= update_mode_lines
|| buffer_shared
> 1;
959 /* If specs for an arrow have changed, do thorough redisplay
960 to ensure we remove any arrow that should no longer exist. */
961 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
962 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
965 /* Normally the message* functions will have already displayed and
966 updated the echo area, but the frame may have been trashed, or
967 the update may have been preempted, so display the echo area
969 if (echo_area_glyphs
|| previous_echo_glyphs
)
971 echo_area_display ();
975 /* If showing region, and mark has changed, must redisplay whole window. */
976 if (((!NILP (Vtransient_mark_mode
)
977 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
978 != !NILP (w
->region_showing
))
979 || (!NILP (w
->region_showing
)
980 && !EQ (w
->region_showing
,
981 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
982 this_line_bufpos
= -1;
984 tlbufpos
= this_line_bufpos
;
985 tlendpos
= this_line_endpos
;
986 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
987 && !current_buffer
->clip_changed
988 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
989 /* Make sure recorded data applies to current buffer, etc */
990 && this_line_buffer
== current_buffer
991 && current_buffer
== XBUFFER (w
->buffer
)
992 && NILP (w
->force_start
)
993 /* Point must be on the line that we have info recorded about */
995 && PT
<= Z
- tlendpos
996 /* All text outside that line, including its final newline,
998 && ((XFASTINT (w
->last_modified
) >= MODIFF
999 && (XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
))
1000 || (beg_unchanged
>= tlbufpos
- 1
1002 /* If selective display, can't optimize
1003 if the changes start at the beginning of the line. */
1004 && ((INTEGERP (current_buffer
->selective_display
)
1005 && XINT (current_buffer
->selective_display
) > 0
1006 ? (beg_unchanged
>= tlbufpos
1009 && end_unchanged
>= tlendpos
1010 && Z
- GPT
>= tlendpos
)))
1012 if (tlbufpos
> BEGV
&& FETCH_BYTE (tlbufpos
- 1) != '\n'
1014 || FETCH_BYTE (tlbufpos
) == '\n'))
1015 /* Former continuation line has disappeared by becoming empty */
1017 else if (XFASTINT (w
->last_modified
) < MODIFF
1018 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
1019 || MINI_WINDOW_P (w
))
1021 /* We have to handle the case of continuation around a
1022 wide-column character (See the comment in indent.c around
1025 For instance, in the following case:
1027 -------- Insert --------
1028 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1029 J_I_ ==> J_I_ `^^' are cursors.
1033 As we have to redraw the line above, we should goto cancel. */
1035 struct position val
;
1038 prevline
= find_next_newline (tlbufpos
, -1);
1039 val
= *compute_motion (prevline
, 0,
1040 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1043 1 << (BITS_PER_SHORT
- 1),
1044 1 << (BITS_PER_SHORT
- 1),
1045 window_internal_width (w
) - 1,
1046 XINT (w
->hscroll
), 0, w
);
1047 if (val
.hpos
!= this_line_start_hpos
)
1051 overlay_arrow_seen
= 0;
1052 zv_strings_seen
= 0;
1053 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
1054 pos_tab_offset (w
, tlbufpos
), 0);
1055 /* If line contains point, is not continued,
1056 and ends at same distance from eob as before, we win */
1057 if (cursor_vpos
>= 0 && this_line_bufpos
1058 && this_line_endpos
== tlendpos
)
1060 /* If this is not the window's last line,
1061 we must adjust the charstarts of the lines below. */
1062 if (this_line_vpos
+ 1
1063 < XFASTINT (w
->top
) + window_internal_height (w
))
1065 int left
= WINDOW_LEFT_MARGIN (w
);
1066 int *charstart_next_line
1067 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
1070 if (Z
- tlendpos
== ZV
)
1071 /* This line ends at end of (accessible part of) buffer.
1072 There is no newline to count. */
1073 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
1075 /* This line ends in a newline.
1076 Must take account of the newline and the rest of the
1077 text that follows. */
1078 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
1080 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
1083 if (!WINDOW_FULL_WIDTH_P (w
))
1084 preserve_other_columns (w
);
1090 else if (PT
== XFASTINT (w
->last_point
)
1091 /* Make sure the cursor was last displayed
1092 in this window. Otherwise we have to reposition it. */
1093 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
1094 && (XINT (w
->top
) + XINT (w
->height
)
1095 > FRAME_CURSOR_Y (selected_frame
)))
1099 do_pending_window_change ();
1104 /* If highlighting the region, or if the cursor is in the echo area,
1105 then we can't just move the cursor. */
1106 else if (! (!NILP (Vtransient_mark_mode
)
1107 && !NILP (current_buffer
->mark_active
))
1108 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1109 || highlight_nonselected_windows
)
1110 && NILP (w
->region_showing
)
1111 && !cursor_in_echo_area
)
1113 pos
= *compute_motion (tlbufpos
, 0,
1114 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1116 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
1117 window_internal_width (w
) - 1,
1119 pos_tab_offset (w
, tlbufpos
), w
);
1122 int width
= window_internal_width (w
) - 1;
1123 FRAME_CURSOR_X (selected_frame
)
1124 = WINDOW_LEFT_MARGIN (w
) + minmax (0, pos
.hpos
, width
);
1125 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1132 /* Text changed drastically or point moved off of line */
1133 cancel_line (this_line_vpos
, selected_frame
);
1136 this_line_bufpos
= 0;
1137 all_windows
|= buffer_shared
> 1;
1139 clear_face_cache_count
++;
1143 Lisp_Object tail
, frame
;
1146 /* Clear the face cache, only when we do a full redisplay
1147 and not too often either. */
1148 if (clear_face_cache_count
> 1000)
1150 clear_face_cache ();
1151 clear_face_cache_count
= 0;
1155 /* Recompute # windows showing selected buffer.
1156 This will be incremented each time such a window is displayed. */
1159 FOR_EACH_FRAME (tail
, frame
)
1161 FRAME_PTR f
= XFRAME (frame
);
1162 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
1165 /* Mark all the scroll bars to be removed; we'll redeem the ones
1166 we want when we redisplay their windows. */
1167 if (condemn_scroll_bars_hook
)
1168 (*condemn_scroll_bars_hook
) (f
);
1170 if (FRAME_VISIBLE_P (f
))
1171 redisplay_windows (FRAME_ROOT_WINDOW (f
), preserve_echo_area
);
1173 /* Any scroll bars which redisplay_windows should have nuked
1174 should now go away. */
1175 if (judge_scroll_bars_hook
)
1176 (*judge_scroll_bars_hook
) (f
);
1180 else if (FRAME_VISIBLE_P (selected_frame
))
1182 redisplay_window (selected_window
, 1, preserve_echo_area
);
1183 if (!WINDOW_FULL_WIDTH_P (w
))
1184 preserve_other_columns (w
);
1188 /* Prevent various kinds of signals during display update.
1189 stdio is not robust about handling signals,
1190 which can cause an apparent I/O error. */
1191 if (interrupt_input
)
1201 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1205 if (!FRAMEP (XCONS (tail
)->car
))
1208 f
= XFRAME (XCONS (tail
)->car
);
1210 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
1211 && FRAME_VISIBLE_P (f
))
1213 pause
|= update_frame (f
, 0, 0);
1216 mark_window_display_accurate (f
->root_window
, 1);
1217 if (frame_up_to_date_hook
!= 0)
1218 (*frame_up_to_date_hook
) (f
);
1225 if (FRAME_VISIBLE_P (selected_frame
))
1226 pause
= update_frame (selected_frame
, 0, 0);
1230 /* We may have called echo_area_display at the top of this
1231 function. If the echo area is on another frame, that may
1232 have put text on a frame other than the selected one, so the
1233 above call to update_frame would not have caught it. Catch
1236 Lisp_Object mini_window
;
1237 FRAME_PTR mini_frame
;
1239 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1240 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1242 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
1243 pause
|= update_frame (mini_frame
, 0, 0);
1247 /* If frame does not match, prevent doing single-line-update next time.
1248 Also, don't forget to check every line to update the arrow. */
1251 this_line_bufpos
= 0;
1252 if (!NILP (last_arrow_position
))
1254 last_arrow_position
= Qt
;
1255 last_arrow_string
= Qt
;
1257 /* If we pause after scrolling, some lines in current_frame
1258 may be null, so preserve_other_columns won't be able to
1259 preserve all the vertical-bar separators. So, avoid using it
1261 if (!WINDOW_FULL_WIDTH_P (w
))
1262 update_mode_lines
= 1;
1265 /* Now text on frame agrees with windows, so
1266 put info into the windows for partial redisplay to follow */
1270 register struct buffer
*b
= XBUFFER (w
->buffer
);
1272 blank_end_of_window
= 0;
1273 unchanged_modified
= BUF_MODIFF (b
);
1274 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
1275 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1276 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1278 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1279 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1280 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1283 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1286 b
->clip_changed
= 0;
1287 w
->update_mode_line
= Qnil
;
1288 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1289 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
1291 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1294 /* Record if we are showing a region, so can make sure to
1295 update it fully at next redisplay. */
1296 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1297 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1298 || highlight_nonselected_windows
)
1299 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1300 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1303 w
->window_end_valid
= w
->buffer
;
1304 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1305 last_arrow_string
= Voverlay_arrow_string
;
1306 if (do_verify_charstarts
)
1307 verify_charstarts (w
);
1308 if (frame_up_to_date_hook
!= 0)
1309 (*frame_up_to_date_hook
) (selected_frame
);
1311 update_mode_lines
= 0;
1312 windows_or_buffers_changed
= 0;
1315 /* Start SIGIO interrupts coming again.
1316 Having them off during the code above
1317 makes it less likely one will discard output,
1318 but not impossible, since there might be stuff
1319 in the system buffer here.
1320 But it is much hairier to try to do anything about that. */
1322 if (interrupt_input
)
1326 /* If something has become visible now which was not before,
1327 redisplay again, so that we get them. */
1330 Lisp_Object tail
, frame
;
1333 FOR_EACH_FRAME (tail
, frame
)
1335 int this_is_visible
= 0;
1337 if (XFRAME (frame
)->visible
)
1338 this_is_visible
= 1;
1339 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1340 if (XFRAME (frame
)->visible
)
1341 this_is_visible
= 1;
1343 if (this_is_visible
)
1347 if (new_count
!= number_of_visible_frames
)
1348 windows_or_buffers_changed
++;
1351 /* Change frame size now if a change is pending. */
1352 do_pending_window_change ();
1354 /* If we just did a pending size change, or have additional
1355 visible frames, redisplay again. */
1356 if (windows_or_buffers_changed
&& !pause
)
1360 /* Redisplay, but leave alone any recent echo area message
1361 unless another message has been requested in its place.
1363 This is useful in situations where you need to redisplay but no
1364 user action has occurred, making it inappropriate for the message
1365 area to be cleared. See tracking_off and
1366 wait_reading_process_input for examples of these situations. */
1368 redisplay_preserve_echo_area ()
1370 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1372 echo_area_glyphs
= previous_echo_glyphs
;
1373 redisplay_internal (1);
1374 echo_area_glyphs
= 0;
1377 redisplay_internal (1);
1381 mark_window_display_accurate (window
, flag
)
1385 register struct window
*w
;
1387 for (;!NILP (window
); window
= w
->next
)
1389 if (!WINDOWP (window
)) abort ();
1390 w
= XWINDOW (window
);
1392 if (!NILP (w
->buffer
))
1394 XSETFASTINT (w
->last_modified
,
1395 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1396 XSETFASTINT (w
->last_overlay_modified
,
1397 !flag
? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)));
1399 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1402 /* Record if we are showing a region, so can make sure to
1403 update it fully at next redisplay. */
1404 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1405 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1406 || highlight_nonselected_windows
)
1407 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1408 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1412 w
->window_end_valid
= w
->buffer
;
1413 w
->update_mode_line
= Qnil
;
1414 if (!NILP (w
->buffer
) && flag
)
1415 XBUFFER (w
->buffer
)->clip_changed
= 0;
1417 if (!NILP (w
->vchild
))
1418 mark_window_display_accurate (w
->vchild
, flag
);
1419 if (!NILP (w
->hchild
))
1420 mark_window_display_accurate (w
->hchild
, flag
);
1425 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1426 last_arrow_string
= Voverlay_arrow_string
;
1430 /* t is unequal to any useful value of Voverlay_arrow_... */
1431 last_arrow_position
= Qt
;
1432 last_arrow_string
= Qt
;
1436 /* Update the menu bar item list for frame F.
1437 This has to be done before we start to fill in any display lines,
1438 because it can call eval.
1440 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1443 update_menu_bar (f
, save_match_data
)
1445 int save_match_data
;
1447 struct buffer
*old
= current_buffer
;
1449 register struct window
*w
;
1451 window
= FRAME_SELECTED_WINDOW (f
);
1452 w
= XWINDOW (window
);
1454 if (update_mode_lines
)
1455 w
->update_mode_line
= Qt
;
1457 if (FRAME_WINDOW_P (f
)
1459 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1460 FRAME_EXTERNAL_MENU_BAR (f
)
1462 FRAME_MENU_BAR_LINES (f
) > 0
1464 : FRAME_MENU_BAR_LINES (f
) > 0)
1466 /* If the user has switched buffers or windows, we need to
1467 recompute to reflect the new bindings. But we'll
1468 recompute when update_mode_lines is set too; that means
1469 that people can use force-mode-line-update to request
1470 that the menu bar be recomputed. The adverse effect on
1471 the rest of the redisplay algorithm is about the same as
1472 windows_or_buffers_changed anyway. */
1473 if (windows_or_buffers_changed
1474 || !NILP (w
->update_mode_line
)
1475 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1476 < BUF_MODIFF (XBUFFER (w
->buffer
)))
1477 != !NILP (w
->last_had_star
))
1478 || ((!NILP (Vtransient_mark_mode
)
1479 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1480 != !NILP (w
->region_showing
)))
1482 struct buffer
*prev
= current_buffer
;
1483 int count
= specpdl_ptr
- specpdl
;
1485 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1486 if (save_match_data
)
1487 record_unwind_protect (Fstore_match_data
, Fmatch_data (Qnil
, Qnil
));
1488 if (NILP (Voverriding_local_map_menu_flag
))
1490 specbind (Qoverriding_terminal_local_map
, Qnil
);
1491 specbind (Qoverriding_local_map
, Qnil
);
1494 /* Run the Lucid hook. */
1495 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1496 /* If it has changed current-menubar from previous value,
1497 really recompute the menubar from the value. */
1498 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1499 call0 (Qrecompute_lucid_menubar
);
1500 safe_run_hooks (Qmenu_bar_update_hook
);
1501 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1502 /* Redisplay the menu bar in case we changed it. */
1503 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1504 if (FRAME_WINDOW_P (f
))
1505 set_frame_menubar (f
, 0, 0);
1507 /* On a terminal screen, the menu bar is an ordinary screen
1508 line, and this makes it get updated. */
1509 w
->update_mode_line
= Qt
;
1510 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1511 /* In the non-toolkit version, the menu bar is an ordinary screen
1512 line, and this makes it get updated. */
1513 w
->update_mode_line
= Qt
;
1514 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1516 unbind_to (count
, Qnil
);
1517 set_buffer_internal_1 (prev
);
1524 /* Redisplay WINDOW and its subwindows and siblings. */
1527 redisplay_windows (window
, preserve_echo_area
)
1529 int preserve_echo_area
;
1531 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1532 redisplay_window (window
, 0, preserve_echo_area
);
1535 /* Return value in display table DP (Lisp_Char_Table *) for character
1536 C. Since a display table doesn't have any parent, we don't have to
1537 follow parent. Do not call this function directly but use the
1538 macro DISP_CHAR_VECTOR. */
1540 disp_char_vector (dp
, c
)
1541 struct Lisp_Char_Table
*dp
;
1547 if (SINGLE_BYTE_CHAR_P (c
)) return (dp
->contents
[c
]);
1549 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
1550 if (code
[0] != CHARSET_COMPOSITION
)
1552 if (code
[1] < 32) code
[1] = -1;
1553 else if (code
[2] < 32) code
[2] = -1;
1555 /* Here, the possible range of CODE[0] (== charset ID) is
1556 128..MAX_CHARSET. Since the top level char table contains data
1557 for multibyte characters after 256th element, we must increment
1558 CODE[0] by 128 to get a correct index. */
1560 code
[3] = -1; /* anchor */
1562 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
1564 val
= dp
->contents
[code
[i
]];
1565 if (!SUB_CHAR_TABLE_P (val
))
1566 return (NILP (val
) ? dp
->defalt
: val
);
1568 /* Here, VAL is a sub char table. We return the default value of it. */
1569 return (dp
->defalt
);
1572 /* Redisplay window WINDOW and its subwindows. */
1575 redisplay_window (window
, just_this_one
, preserve_echo_area
)
1577 int just_this_one
, preserve_echo_area
;
1579 register struct window
*w
= XWINDOW (window
);
1580 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1582 register int lpoint
= PT
;
1583 struct buffer
*old
= current_buffer
;
1584 register int width
= window_internal_width (w
) - 1;
1585 register int startp
;
1586 register int hscroll
= XINT (w
->hscroll
);
1587 struct position pos
;
1590 int update_mode_line
;
1591 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1593 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1595 /* If this is a combination window, do its children; that's all. */
1597 if (!NILP (w
->vchild
))
1599 redisplay_windows (w
->vchild
, preserve_echo_area
);
1602 if (!NILP (w
->hchild
))
1604 redisplay_windows (w
->hchild
, preserve_echo_area
);
1607 if (NILP (w
->buffer
))
1610 height
= window_internal_height (w
);
1611 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1612 if (XBUFFER (w
->buffer
)->clip_changed
)
1613 update_mode_line
= 1;
1615 if (MINI_WINDOW_P (w
))
1617 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1618 /* We've already displayed the echo area glyphs in this window. */
1619 goto finish_scroll_bars
;
1620 else if (w
!= XWINDOW (minibuf_window
))
1622 /* This is a minibuffer, but it's not the currently active one,
1624 int vpos
= XFASTINT (w
->top
);
1627 for (i
= 0; i
< height
; i
++)
1629 get_display_line (f
, vpos
+ i
, 0);
1630 display_string (w
, vpos
+ i
, "", 0,
1631 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
1635 goto finish_scroll_bars
;
1639 /* Otherwise set up data on this window; select its buffer and point value */
1641 if (update_mode_line
)
1642 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1644 set_buffer_temp (XBUFFER (w
->buffer
));
1648 /* If %c is in mode line, update it if needed. */
1649 if (!NILP (w
->column_number_displayed
)
1650 /* This alternative quickly identifies a common case
1651 where no change is needed. */
1652 && !(PT
== XFASTINT (w
->last_point
)
1653 && XFASTINT (w
->last_modified
) >= MODIFF
1654 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1655 && XFASTINT (w
->column_number_displayed
) != current_column ())
1656 update_mode_line
= 1;
1658 /* Count number of windows showing the selected buffer.
1659 An indirect buffer counts as its base buffer. */
1663 struct buffer
*current_base
, *window_base
;
1664 current_base
= current_buffer
;
1665 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1666 if (current_base
->base_buffer
)
1667 current_base
= current_base
->base_buffer
;
1668 if (window_base
->base_buffer
)
1669 window_base
= window_base
->base_buffer
;
1670 if (current_base
== window_base
)
1674 /* POINT refers normally to the selected window.
1675 For any other window, set up appropriate value. */
1677 if (!EQ (window
, selected_window
))
1679 int new_pt
= marker_position (w
->pointm
);
1683 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1685 else if (new_pt
> (ZV
- 1))
1688 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1690 /* We don't use SET_PT so that the point-motion hooks don't run. */
1691 BUF_PT (current_buffer
) = new_pt
;
1694 /* If any of the character widths specified in the display table
1695 have changed, invalidate the width run cache. It's true that this
1696 may be a bit late to catch such changes, but the rest of
1697 redisplay goes (non-fatally) haywire when the display table is
1698 changed, so why should we worry about doing any better? */
1699 if (current_buffer
->width_run_cache
)
1701 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1703 if (! disptab_matches_widthtab (disptab
,
1704 XVECTOR (current_buffer
->width_table
)))
1706 invalidate_region_cache (current_buffer
,
1707 current_buffer
->width_run_cache
,
1709 recompute_width_table (current_buffer
, disptab
);
1713 /* If window-start is screwed up, choose a new one. */
1714 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1717 startp
= marker_position (w
->start
);
1719 /* If someone specified a new starting point but did not insist,
1720 check whether it can be used. */
1721 if (!NILP (w
->optional_new_start
))
1723 w
->optional_new_start
= Qnil
;
1724 /* Check whether this start pos is usable given where point is. */
1726 pos
= *compute_motion (startp
, 0,
1727 (((EQ (window
, minibuf_window
)
1729 ? minibuf_prompt_width
: 0)
1730 + (hscroll
? 1 - hscroll
: 0)),
1733 /* BUG FIX: See the comment of
1734 Fpos_visible_in_window_p (window.c). */
1735 - (1 << (BITS_PER_SHORT
- 1)),
1736 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1737 /* If PT does fit on the screen, we will use this start pos,
1738 so do so by setting force_start. */
1739 if (pos
.bufpos
== PT
)
1740 w
->force_start
= Qt
;
1743 /* Handle case where place to start displaying has been specified,
1744 unless the specified location is outside the accessible range. */
1745 if (!NILP (w
->force_start
))
1747 w
->force_start
= Qnil
;
1748 /* Forget any recorded base line for line number display. */
1749 w
->base_line_number
= Qnil
;
1750 /* Redisplay the mode line. Select the buffer properly for that.
1751 Also, run the hook window-scroll-functions
1752 because we have scrolled. */
1753 /* Note, we do this after clearing force_start because
1754 if there's an error, it is better to forget about force_start
1755 than to get into an infinite loop calling the hook functions
1756 and having them get more errors. */
1757 if (!update_mode_line
1758 || ! NILP (Vwindow_scroll_functions
))
1760 Lisp_Object temp
[3];
1762 set_buffer_temp (old
);
1763 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1764 update_mode_line
= 1;
1765 w
->update_mode_line
= Qt
;
1766 if (! NILP (Vwindow_scroll_functions
))
1768 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1769 make_number (startp
));
1770 startp
= marker_position (w
->start
);
1773 XSETFASTINT (w
->last_modified
, 0);
1774 XSETFASTINT (w
->last_overlay_modified
, 0);
1775 if (startp
< BEGV
) startp
= BEGV
;
1776 if (startp
> ZV
) startp
= ZV
;
1777 try_window (window
, startp
);
1778 if (cursor_vpos
< 0)
1780 /* If point does not appear, move point so it does appear */
1781 pos
= *compute_motion (startp
, 0,
1782 (((EQ (window
, minibuf_window
)
1784 ? minibuf_prompt_width
: 0)
1785 + (hscroll
? 1 - hscroll
: 0)),
1788 - (1 << (BITS_PER_SHORT
- 1)),
1789 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1790 BUF_PT (current_buffer
) = pos
.bufpos
;
1791 if (w
!= XWINDOW (selected_window
))
1792 Fset_marker (w
->pointm
, make_number (PT
), Qnil
);
1795 if (current_buffer
== old
)
1797 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
1798 + minmax (0, pos
.hpos
, width
));
1799 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1801 /* If we are highlighting the region,
1802 then we just changed the region, so redisplay to show it. */
1803 if (!NILP (Vtransient_mark_mode
)
1804 && !NILP (current_buffer
->mark_active
))
1806 cancel_my_columns (XWINDOW (window
));
1807 try_window (window
, startp
);
1813 /* Handle case where text has not changed, only point,
1814 and it has not moved off the frame. */
1816 /* This code is not used for minibuffer for the sake of
1817 the case of redisplaying to replace an echo area message;
1818 since in that case the minibuffer contents per se are usually unchanged.
1819 This code is of no real use in the minibuffer since
1820 the handling of this_line_bufpos, etc.,
1821 in redisplay handles the same cases. */
1823 if (XFASTINT (w
->last_modified
) >= MODIFF
1824 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
1825 && PT
>= startp
&& !current_buffer
->clip_changed
1826 && (just_this_one
|| WINDOW_FULL_WIDTH_P (w
))
1827 /* If force-mode-line-update was called, really redisplay;
1828 that's how redisplay is forced after e.g. changing
1829 buffer-invisibility-spec. */
1830 && NILP (w
->update_mode_line
)
1831 /* Can't use this case if highlighting a region. */
1832 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
1833 && NILP (w
->region_showing
)
1834 /* If end pos is out of date, scroll bar and percentage will be wrong */
1835 && INTEGERP (w
->window_end_vpos
)
1836 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
1837 && !EQ (window
, minibuf_window
)
1838 && (!MARKERP (Voverlay_arrow_position
)
1839 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
1841 /* All positions in this clause are relative to the window edge. */
1843 int this_scroll_margin
= scroll_margin
;
1844 int last_point_y
= XFASTINT (w
->last_point_y
) - XINT (w
->top
);
1845 int last_point_x
= (XFASTINT (w
->last_point_x
) - WINDOW_LEFT_MARGIN (w
));
1847 /* Find where PT is located now on the frame. */
1848 /* Check just_this_one as a way of verifying that the
1849 window edges have not changed. */
1850 if (PT
== XFASTINT (w
->last_point
) && just_this_one
)
1852 pos
.hpos
= last_point_x
;
1853 pos
.vpos
= last_point_y
;
1856 else if (PT
> XFASTINT (w
->last_point
)
1857 && XFASTINT (w
->last_point
) > startp
&& just_this_one
1858 /* We can't use this if point is in the left margin of a
1859 hscrolled window, because w->last_point_x has been
1860 clipped to the window edges. */
1861 && !(last_point_x
<= 0 && hscroll
))
1863 pos
= *compute_motion (XFASTINT (w
->last_point
),
1864 last_point_y
, last_point_x
, 0,
1866 /* BUG FIX: See the comment of
1867 Fpos_visible_in_window_p (window.c). */
1868 - (1 << (BITS_PER_SHORT
- 1)),
1870 pos_tab_offset (w
, startp
), w
);
1874 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
1876 /* BUG FIX: See the comment of
1877 Fpos_visible_in_window_p (window.c). */
1878 - (1 << (BITS_PER_SHORT
- 1)),
1880 pos_tab_offset (w
, startp
), w
);
1883 /* Don't use a scroll margin that is negative or too large. */
1884 if (this_scroll_margin
< 0)
1885 this_scroll_margin
= 0;
1887 if (XINT (w
->height
) < 4 * scroll_margin
)
1888 this_scroll_margin
= XINT (w
->height
) / 4;
1890 /* If point fits on the screen, and not within the scroll margin,
1892 if (pos
.vpos
< height
- this_scroll_margin
1893 && (pos
.vpos
>= this_scroll_margin
|| startp
== BEGV
))
1895 /* Ok, point is still on frame */
1896 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
1898 /* These variables are supposed to be origin 1 */
1899 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
1900 + minmax (0, pos
.hpos
, width
));
1901 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1903 /* This doesn't do the trick, because if a window to the right of
1904 this one must be redisplayed, this does nothing because there
1905 is nothing in DesiredFrame yet, and then the other window is
1906 redisplayed, making likes that are empty in this window's columns.
1907 if (WINDOW_FULL_WIDTH_P (w))
1908 preserve_my_columns (w);
1912 /* Don't bother trying redisplay with same start;
1913 we already know it will lose */
1915 /* If current starting point was originally the beginning of a line
1916 but no longer is, find a new starting point. */
1917 else if (!NILP (w
->start_at_line_beg
)
1919 || FETCH_BYTE (startp
- 1) == '\n'))
1923 else if (just_this_one
&& !MINI_WINDOW_P (w
)
1925 && XFASTINT (w
->last_modified
)
1926 /* or else vmotion on first line won't work. */
1927 && ! NILP (w
->start_at_line_beg
)
1928 && ! EQ (w
->window_end_valid
, Qnil
)
1929 && do_id
&& !current_buffer
->clip_changed
1930 && !blank_end_of_window
1931 && WINDOW_FULL_WIDTH_P (w
)
1932 /* Can't use this case if highlighting a region. */
1933 && !(!NILP (Vtransient_mark_mode
)
1934 && !NILP (current_buffer
->mark_active
))
1935 /* Don't use try_window_id if newline
1936 doesn't display as the end of a line. */
1937 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
1938 && NILP (w
->region_showing
)
1939 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
1940 && EQ (last_arrow_string
, Voverlay_arrow_string
)
1941 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
1944 /* tem > 0 means success. tem == -1 means choose new start.
1945 tem == -2 means try again with same start,
1946 and nothing but whitespace follows the changed stuff.
1947 tem == 0 means try again with same start. */
1951 else if (startp
>= BEGV
&& startp
<= ZV
1953 /* Avoid starting at end of buffer. */
1954 #if 0 /* This change causes trouble for M-! finger & RET.
1955 It will have to be considered later. */
1956 || ! EQ (window
, selected_window
)
1957 /* Don't do the recentering if redisplay
1958 is not for no user action. */
1959 || preserve_echo_area
1962 || (XFASTINT (w
->last_modified
) >= MODIFF
1963 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
1965 /* Try to redisplay starting at same place as before */
1966 /* If point has not moved off frame, accept the results */
1967 try_window (window
, startp
);
1968 if (cursor_vpos
>= 0)
1970 if (!just_this_one
|| current_buffer
->clip_changed
1971 || beg_unchanged
< startp
)
1972 /* Forget any recorded base line for line number display. */
1973 w
->base_line_number
= Qnil
;
1977 cancel_my_columns (w
);
1980 XSETFASTINT (w
->last_modified
, 0);
1981 XSETFASTINT (w
->last_overlay_modified
, 0);
1982 /* Redisplay the mode line. Select the buffer properly for that. */
1983 if (!update_mode_line
)
1985 set_buffer_temp (old
);
1986 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1987 update_mode_line
= 1;
1988 w
->update_mode_line
= Qt
;
1991 /* Try to scroll by specified few lines */
1993 if (scroll_conservatively
&& !current_buffer
->clip_changed
1994 && startp
>= BEGV
&& startp
<= ZV
)
1996 int this_scroll_margin
= scroll_margin
;
1998 /* Don't use a scroll margin that is negative or too large. */
1999 if (this_scroll_margin
< 0)
2000 this_scroll_margin
= 0;
2002 if (XINT (w
->height
) < 4 * scroll_margin
)
2003 this_scroll_margin
= XINT (w
->height
) / 4;
2005 if (PT
>= Z
- XFASTINT (w
->window_end_pos
))
2007 struct position pos
;
2008 pos
= *compute_motion (Z
- XFASTINT (w
->window_end_pos
), 0, 0, 0,
2009 PT
, XFASTINT (w
->height
), 0,
2010 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2011 pos_tab_offset (w
, startp
), w
);
2012 if (pos
.vpos
> scroll_conservatively
)
2015 pos
= *vmotion (startp
, pos
.vpos
+ 1 + this_scroll_margin
, w
);
2017 if (! NILP (Vwindow_scroll_functions
))
2019 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2020 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2021 make_number (pos
.bufpos
));
2022 pos
.bufpos
= marker_position (w
->start
);
2024 try_window (window
, pos
.bufpos
);
2025 if (cursor_vpos
>= 0)
2027 if (!just_this_one
|| current_buffer
->clip_changed
2028 || beg_unchanged
< startp
)
2029 /* Forget any recorded base line for line number display. */
2030 w
->base_line_number
= Qnil
;
2034 cancel_my_columns (w
);
2038 struct position pos
;
2039 pos
= *compute_motion (PT
, 0, 0, 0,
2040 startp
, XFASTINT (w
->height
), 0,
2041 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2042 pos_tab_offset (w
, startp
), w
);
2043 if (pos
.vpos
> scroll_conservatively
)
2046 pos
= *vmotion (startp
, - pos
.vpos
- this_scroll_margin
, w
);
2048 if (! NILP (Vwindow_scroll_functions
))
2050 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2051 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2052 make_number (pos
.bufpos
));
2053 pos
.bufpos
= marker_position (w
->start
);
2055 try_window (window
, pos
.bufpos
);
2056 if (cursor_vpos
>= 0)
2058 if (!just_this_one
|| current_buffer
->clip_changed
2059 || beg_unchanged
< startp
)
2060 /* Forget any recorded base line for line number display. */
2061 w
->base_line_number
= Qnil
;
2065 cancel_my_columns (w
);
2070 if (scroll_step
&& !current_buffer
->clip_changed
2071 && startp
>= BEGV
&& startp
<= ZV
)
2075 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
2076 if (pos
.vpos
>= height
)
2080 pos
= *vmotion (startp
, (PT
< startp
? - scroll_step
: scroll_step
), w
);
2082 if (PT
>= pos
.bufpos
)
2084 if (! NILP (Vwindow_scroll_functions
))
2086 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2087 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2088 make_number (pos
.bufpos
));
2089 pos
.bufpos
= marker_position (w
->start
);
2091 try_window (window
, pos
.bufpos
);
2092 if (cursor_vpos
>= 0)
2094 if (!just_this_one
|| current_buffer
->clip_changed
2095 || beg_unchanged
< startp
)
2096 /* Forget any recorded base line for line number display. */
2097 w
->base_line_number
= Qnil
;
2101 cancel_my_columns (w
);
2106 /* Finally, just choose place to start which centers point */
2109 /* Forget any previously recorded base line for line number display. */
2110 w
->base_line_number
= Qnil
;
2112 pos
= *vmotion (PT
, - (height
/ 2), w
);
2113 /* Set startp here explicitly in case that helps avoid an infinite loop
2114 in case the window-scroll-functions functions get errors. */
2115 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2116 if (! NILP (Vwindow_scroll_functions
))
2118 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2119 make_number (pos
.bufpos
));
2120 pos
.bufpos
= marker_position (w
->start
);
2122 try_window (window
, pos
.bufpos
);
2124 startp
= marker_position (w
->start
);
2125 w
->start_at_line_beg
2126 = (startp
== BEGV
|| FETCH_BYTE (startp
- 1) == '\n') ? Qt
: Qnil
;
2129 if ((update_mode_line
2130 /* If window not full width, must redo its mode line
2131 if the window to its side is being redone */
2132 || (!just_this_one
&& !WINDOW_FULL_WIDTH_P (w
))
2133 || INTEGERP (w
->base_line_pos
)
2134 || (!NILP (w
->column_number_displayed
)
2135 && XFASTINT (w
->column_number_displayed
) != current_column ()))
2136 && height
!= XFASTINT (w
->height
))
2137 display_mode_line (w
);
2138 if (! line_number_displayed
2139 && ! BUFFERP (w
->base_line_pos
))
2141 w
->base_line_pos
= Qnil
;
2142 w
->base_line_number
= Qnil
;
2145 /* When we reach a frame's selected window, redo the frame's menu bar. */
2146 if (update_mode_line
2147 && (FRAME_WINDOW_P (f
)
2149 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2150 FRAME_EXTERNAL_MENU_BAR (f
)
2152 FRAME_MENU_BAR_LINES (f
) > 0
2154 : FRAME_MENU_BAR_LINES (f
) > 0)
2155 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
2156 display_menu_bar (w
);
2159 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2161 int start
, end
, whole
;
2163 /* Calculate the start and end positions for the current window.
2164 At some point, it would be nice to choose between scrollbars
2165 which reflect the whole buffer size, with special markers
2166 indicating narrowing, and scrollbars which reflect only the
2169 Note that minibuffers sometimes aren't displaying any text. */
2170 if (! MINI_WINDOW_P (w
)
2171 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
2174 start
= marker_position (w
->start
) - BEGV
;
2175 /* I don't think this is guaranteed to be right. For the
2176 moment, we'll pretend it is. */
2177 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
2179 if (end
< start
) end
= start
;
2180 if (whole
< (end
- start
)) whole
= end
- start
;
2183 start
= end
= whole
= 0;
2185 /* Indicate what this scroll bar ought to be displaying now. */
2186 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
2188 /* Note that we actually used the scroll bar attached to this window,
2189 so it shouldn't be deleted at the end of redisplay. */
2190 (*redeem_scroll_bar_hook
) (w
);
2193 BUF_PT (current_buffer
) = opoint
;
2194 if (update_mode_line
)
2195 set_buffer_internal_1 (old
);
2197 set_buffer_temp (old
);
2198 BUF_PT (current_buffer
) = lpoint
;
2201 /* Do full redisplay on one window, starting at position `pos'. */
2204 try_window (window
, pos
)
2208 register struct window
*w
= XWINDOW (window
);
2209 register int height
= window_internal_height (w
);
2210 register int vpos
= XFASTINT (w
->top
);
2211 register int last_text_vpos
= vpos
;
2212 FRAME_PTR f
= XFRAME (w
->frame
);
2213 int width
= window_internal_width (w
) - 1;
2214 struct position val
;
2216 /* POS should never be out of range! */
2217 if (pos
< XBUFFER (w
->buffer
)->begv
2218 || pos
> XBUFFER (w
->buffer
)->zv
)
2221 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2223 overlay_arrow_seen
= 0;
2224 zv_strings_seen
= 0;
2225 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2226 val
.ovstring_chars_done
= 0;
2227 val
.tab_offset
= pos_tab_offset (w
, pos
);
2229 while (--height
>= 0)
2231 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, val
.tab_offset
,
2232 val
.ovstring_chars_done
);
2233 /* The following code is omitted because we maintain tab_offset
2236 tab_offset
+= width
;
2237 if (val
.vpos
) tab_offset
= 0;
2240 if (pos
!= val
.bufpos
)
2243 #ifdef USE_TEXT_PROPERTIES
2244 Lisp_Object invis_prop
;
2245 invis_prop
= Fget_char_property (val
.bufpos
-1, Qinvisible
, window
);
2246 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
2250 /* Next line, unless prev line ended in end of buffer with no cr */
2252 && (FETCH_BYTE (val
.bufpos
- 1) != '\n' || invis
));
2257 /* If last line is continued in middle of character,
2258 include the split character in the text considered on the frame */
2259 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2262 /* If bottom just moved off end of frame, change mode line percentage. */
2263 if (XFASTINT (w
->window_end_pos
) == 0
2265 w
->update_mode_line
= Qt
;
2267 /* Say where last char on frame will be, once redisplay is finished. */
2268 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
2269 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
2270 /* But that is not valid info until redisplay finishes. */
2271 w
->window_end_valid
= Qnil
;
2274 /* Try to redisplay when buffer is modified locally,
2275 computing insert/delete line to preserve text outside
2276 the bounds of the changes.
2277 Return 1 if successful, 0 if if cannot tell what to do,
2278 or -1 to tell caller to find a new window start,
2279 or -2 to tell caller to do normal redisplay with same window start. */
2282 try_window_id (window
)
2286 register struct window
*w
= XWINDOW (window
);
2287 register int height
= window_internal_height (w
);
2288 FRAME_PTR f
= XFRAME (w
->frame
);
2289 int top
= XFASTINT (w
->top
);
2290 int start
= marker_position (w
->start
);
2291 int width
= window_internal_width (w
) - 1;
2292 int hscroll
= XINT (w
->hscroll
);
2293 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
2296 register int i
, tem
;
2297 int last_text_vpos
= 0;
2299 int selective
= (INTEGERP (current_buffer
->selective_display
)
2300 ? XINT (current_buffer
->selective_display
)
2301 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2303 struct position val
, bp
, ep
, xp
, pp
;
2304 int scroll_amount
= 0;
2308 if (GPT
- BEG
< beg_unchanged
)
2309 beg_unchanged
= GPT
- BEG
;
2310 if (Z
- GPT
< end_unchanged
)
2311 end_unchanged
= Z
- GPT
;
2313 if (beg_unchanged
+ BEG
< start
)
2314 return 0; /* Give up if changes go above top of window */
2316 /* Find position before which nothing is changed. */
2317 bp
= *compute_motion (start
, 0, lmargin
, 0,
2318 min (ZV
, beg_unchanged
+ BEG
), height
,
2319 /* BUG FIX: See the comment of
2320 Fpos_visible_in_window_p() (window.c). */
2321 - (1 << (BITS_PER_SHORT
- 1)),
2322 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2323 if (bp
.vpos
>= height
)
2327 /* All changes are beyond the window end, and point is on the screen.
2328 We don't need to change the text at all.
2329 But we need to update window_end_pos to account for
2330 any change in buffer size. */
2331 bp
= *compute_motion (start
, 0, lmargin
, 0,
2333 /* BUG FIX: See the comment of
2334 Fpos_visible_in_window_p() (window.c). */
2335 - (1 << (BITS_PER_SHORT
- 1)),
2336 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2337 XSETFASTINT (w
->window_end_vpos
, height
);
2338 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
2346 /* Find beginning of that frame line. Must display from there. */
2347 bp
= *vmotion (bp
.bufpos
, 0, w
);
2355 /* If about to start displaying at the beginning of a continuation line,
2356 really start with previous frame line, in case it was not
2357 continued when last redisplayed */
2358 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
2360 /* Likewise if we have to worry about selective display. */
2361 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
2363 bp
= *vmotion (bp
.bufpos
, -1, w
);
2367 val
.tab_offset
= bp
.tab_offset
; /* Update tab offset. */
2369 if (bp
.contin
&& bp
.hpos
!= lmargin
)
2371 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
2372 val
.tab_offset
= bp
.tab_offset
+ bp
.prevhpos
- width
;
2379 /* Find first visible newline after which no more is changed. */
2380 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
2382 while (tem
< ZV
- 1 && (indented_beyond_p (tem
, selective
)))
2383 tem
= find_next_newline (tem
, 1);
2385 /* Compute the cursor position after that newline. */
2386 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
2387 height
, - (1 << (BITS_PER_SHORT
- 1)),
2389 /* We have tab offset in VAL, use it. */
2392 /* If changes reach past the text available on the frame,
2393 just display rest of frame. */
2394 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
2397 stop_vpos
= ep
.vpos
;
2399 /* If no newline before ep, the line ep is on includes some changes
2400 that must be displayed. Make sure we don't stop before it. */
2401 /* Also, if changes reach all the way until ep.bufpos,
2402 it is possible that something was deleted after the
2403 newline before it, so the following line must be redrawn. */
2404 if (stop_vpos
== ep
.vpos
2405 && (ep
.bufpos
== BEGV
2406 || FETCH_BYTE (ep
.bufpos
- 1) != '\n'
2407 || ep
.bufpos
== Z
- end_unchanged
))
2408 stop_vpos
= ep
.vpos
+ 1;
2411 overlay_arrow_seen
= 0;
2412 zv_strings_seen
= 0;
2414 /* If changes do not reach to bottom of window,
2415 figure out how much to scroll the rest of the window */
2416 if (stop_vpos
< height
)
2418 /* Now determine how far up or down the rest of the window has moved */
2419 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2420 Z
- XFASTINT (w
->window_end_pos
),
2421 /* Don't care for VPOS... */
2422 1 << (BITS_PER_SHORT
- 1),
2424 1 << (BITS_PER_SHORT
- 1),
2425 width
, hscroll
, ep
.tab_offset
, w
);
2426 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2428 /* Is everything on frame below the changes whitespace?
2429 If so, no scrolling is really necessary. */
2430 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
2432 tem
= FETCH_BYTE (i
);
2433 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2439 XSETFASTINT (w
->window_end_vpos
,
2440 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2442 /* Before doing any scrolling, verify that point will be on frame. */
2443 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.vpos
< height
))
2445 if (PT
<= xp
.bufpos
)
2447 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2448 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2450 /* We have tab offset in EP, use it. */
2455 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2456 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2458 /* We have tab offset in XP, use it. */
2461 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2463 cursor_vpos
= pp
.vpos
+ top
;
2464 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, pp
.hpos
, width
);
2467 if (stop_vpos
- scroll_amount
>= height
2468 || ep
.bufpos
== xp
.bufpos
)
2470 if (scroll_amount
< 0)
2471 stop_vpos
-= scroll_amount
;
2473 /* In this path, we have altered window_end_vpos
2474 and not left it negative.
2475 We must make sure that, in case display is preempted
2476 before the frame changes to reflect what we do here,
2477 further updates will not come to try_window_id
2478 and assume the frame and window_end_vpos match. */
2479 blank_end_of_window
= 1;
2481 else if (!scroll_amount
)
2483 /* Even if we don't need to scroll, we must adjust the
2484 charstarts of subsequent lines (that we won't redisplay)
2485 according to the amount of text inserted or deleted. */
2486 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2487 int adjust
= ep
.bufpos
- oldpos
;
2488 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2490 else if (bp
.bufpos
== Z
- end_unchanged
)
2492 /* If reprinting everything is nearly as fast as scrolling,
2493 don't bother scrolling. Can happen if lines are short. */
2494 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2495 top
+ height
- max (0, scroll_amount
),
2497 > xp
.bufpos
- bp
.bufpos
- 20)
2498 /* Return "try normal display with same window-start."
2499 Too bad we can't prevent further scroll-thinking. */
2501 /* If pure deletion, scroll up as many lines as possible.
2502 In common case of killing a line, this can save the
2503 following line from being overwritten by scrolling
2504 and therefore having to be redrawn. */
2505 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2506 top
+ height
- max (0, scroll_amount
),
2507 scroll_amount
, bp
.bufpos
);
2512 /* scroll_frame_lines did not properly adjust subsequent
2513 lines' charstarts in the case where the text of the
2514 screen line at bp.vpos has changed.
2515 (This can happen in a deletion that ends in mid-line.)
2516 To adjust properly, we need to make things consistent
2518 So do a second adjust to make that happen.
2519 Note that stop_vpos >= ep.vpos, so it is sufficient
2520 to update the charstarts for lines at ep.vpos and below. */
2522 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2523 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2524 ep
.bufpos
- oldstart
);
2527 else if (scroll_amount
)
2529 /* If reprinting everything is nearly as fast as scrolling,
2530 don't bother scrolling. Can happen if lines are short. */
2531 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2532 overestimate of cost of reprinting, since xp.bufpos
2533 would end up below the bottom of the window. */
2534 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2535 top
+ height
- max (0, scroll_amount
),
2537 > xp
.bufpos
- ep
.bufpos
- 20)
2538 /* Return "try normal display with same window-start."
2539 Too bad we can't prevent further scroll-thinking. */
2541 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2542 top
+ height
- max (0, scroll_amount
),
2543 scroll_amount
, ep
.bufpos
);
2544 if (!tem
) stop_vpos
= height
;
2548 /* In any case, do not display past bottom of window */
2549 if (stop_vpos
>= height
)
2555 /* Handle case where pos is before w->start --
2556 can happen if part of line had been clipped and is not clipped now */
2557 if (vpos
== 0 && pos
< marker_position (w
->start
))
2558 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2560 /* Redisplay the lines where the text was changed */
2561 last_text_vpos
= vpos
;
2562 /* The following code is omitted because we maintain tab offset in
2565 tab_offset
= pos_tab_offset (w
, pos
);
2566 /* If we are starting display in mid-character, correct tab_offset
2567 to account for passing the line that that character really starts in. */
2568 if (val
.hpos
< lmargin
)
2569 tab_offset
+= width
;
2572 while (vpos
< stop_vpos
)
2574 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, val
.tab_offset
,
2575 val
.ovstring_chars_done
);
2576 /* If display_text_line ran a hook and changed some text,
2577 redisplay all the way to bottom of buffer
2578 So that we show the changes. */
2579 if (old_tick
!= MODIFF
)
2581 /* The following code is omitted because we maintain tab offset
2582 in val.tab_offset. */
2584 tab_offset
+= width
;
2585 if (val
.vpos
) tab_offset
= 0;
2587 if (pos
!= val
.bufpos
)
2589 /* Next line, unless prev line ended in end of buffer with no cr */
2590 = vpos
- (val
.vpos
&& FETCH_BYTE (val
.bufpos
- 1) != '\n');
2594 /* There are two cases:
2595 1) we have displayed down to the bottom of the window
2596 2) we have scrolled lines below stop_vpos by scroll_amount */
2600 /* If last line is continued in middle of character,
2601 include the split character in the text considered on the frame */
2602 if (val
.hpos
< lmargin
)
2604 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2605 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2608 /* If scrolling made blank lines at window bottom,
2609 redisplay to fill those lines */
2610 if (scroll_amount
< 0)
2612 /* Don't consider these lines for general-purpose scrolling.
2613 That will save time in the scrolling computation. */
2614 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2618 val
.tab_offset
= xp
.tab_offset
;
2620 { /* Display from next line */
2621 vpos
= height
+ scroll_amount
;
2625 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2627 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2628 val
.tab_offset
= xp
.tab_offset
+ bp
.prevhpos
- width
;
2632 blank_end_of_window
= 1;
2633 /* The following code is omitted because we maintain tab offset
2634 in val.tab_offset. */
2636 tab_offset
= pos_tab_offset (w
, pos
);
2637 /* If we are starting display in mid-character, correct tab_offset
2638 to account for passing the line that that character starts in. */
2639 if (val
.hpos
< lmargin
)
2640 tab_offset
+= width
;
2642 while (vpos
< height
)
2644 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
,
2645 val
.tab_offset
, val
.ovstring_chars_done
);
2646 /* The following code is omitted because we maintain tab
2647 offset in val.tab_offset. */
2649 tab_offset
+= width
;
2650 if (val
.vpos
) tab_offset
= 0;
2655 /* Here is a case where display_text_line sets cursor_vpos wrong.
2656 Make it be fixed up, below. */
2662 /* If bottom just moved off end of frame, change mode line percentage. */
2663 if (XFASTINT (w
->window_end_pos
) == 0
2665 w
->update_mode_line
= Qt
;
2667 /* Attempt to adjust end-of-text positions to new bottom line */
2670 delta
= height
- xp
.vpos
;
2672 || (delta
> 0 && xp
.bufpos
<= ZV
)
2673 || (delta
== 0 && xp
.hpos
))
2675 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
2676 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2677 XSETFASTINT (w
->window_end_vpos
,
2678 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
2682 w
->window_end_valid
= Qnil
;
2684 /* If point was not in a line that was displayed, find it */
2685 if (cursor_vpos
< 0)
2688 val
= *compute_motion (start
, 0, lmargin
, 0, PT
,
2689 /* Don't care for VPOS... */
2690 1 << (BITS_PER_SHORT
- 1),
2692 1 << (BITS_PER_SHORT
- 1),
2693 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2694 /* Admit failure if point is off frame now */
2695 if (val
.vpos
>= height
)
2697 for (vpos
= 0; vpos
< height
; vpos
++)
2698 cancel_line (vpos
+ top
, f
);
2701 cursor_vpos
= val
.vpos
+ top
;
2702 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, val
.hpos
, width
);
2705 FRAME_CURSOR_X (f
) = cursor_hpos
;
2706 FRAME_CURSOR_Y (f
) = cursor_vpos
;
2710 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
2711 height
, - (1 << (BITS_PER_SHORT
- 1)),
2712 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2713 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
2715 if (XFASTINT (w
->window_end_pos
)
2723 /* Copy LEN glyphs starting address FROM to the rope TO.
2724 But don't actually copy the parts that would come in before S.
2725 Value is TO, advanced past the copied data.
2726 F is the frame we are displaying in. */
2729 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
2731 register GLYPH
*to
; /* Copy to here. */
2732 register GLYPH
*s
; /* Starting point. */
2733 Lisp_Object
*from
; /* Data to copy. */
2735 int face
; /* Face to apply to glyphs which don't specify one. */
2738 register Lisp_Object
*fp
= from
;
2739 /* These cache the results of the last call to compute_glyph_face. */
2741 int last_merged
= 0;
2744 if (! FRAME_TERMCAP_P (f
))
2747 GLYPH glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2749 unsigned int c
= FAST_GLYPH_CHAR (glyph
);
2752 /* For an invalid character code, use space. */
2755 if (FAST_GLYPH_FACE (glyph
) == 0)
2756 /* If GLYPH has no face code, use FACE. */
2758 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
2759 /* If it's same as previous glyph, use same result. */
2760 facecode
= last_merged
;
2763 /* Merge this glyph's face and remember the result. */
2764 last_code
= FAST_GLYPH_FACE (glyph
);
2765 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
2769 *to
= FAST_MAKE_GLYPH (c
, facecode
);
2777 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2784 /* Correct a glyph by replacing its specified user-level face code
2785 with a displayable computed face code. */
2788 fix_glyph (f
, glyph
, cface
)
2794 if (! FRAME_TERMCAP_P (f
))
2796 if (FAST_GLYPH_FACE (glyph
) != 0)
2797 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
2798 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
2804 /* Display one line of window W, starting at position START in W's buffer.
2806 Display starting at horizontal position HPOS, expressed relative to
2807 W's left edge. In situations where the text at START shouldn't
2808 start at the left margin (i.e. when the window is hscrolled, or
2809 we're continuing a line which left off in the midst of a
2810 multi-column character), HPOS should be negative; we throw away
2811 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2814 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2816 OVSTR_DONE is the number of chars of overlay before/after strings
2817 at this position which have already been processed.
2819 Display on position VPOS on the frame. It is origin 0, relative to
2820 the top of the frame, not W.
2822 Returns a STRUCT POSITION giving character to start next line with
2823 and where to display it, including a zero or negative hpos.
2824 The vpos field is not really a vpos; it is 1 unless the line is continued */
2826 struct position val_display_text_line
;
2828 static struct position
*
2829 display_text_line (w
, start
, vpos
, hpos
, taboffset
, ovstr_done
)
2837 register int pos
= start
;
2841 register unsigned char *p
;
2843 register GLYPH
*leftmargin
;
2844 register GLYPH
*p1prev
;
2845 register GLYPH
*p1start
;
2848 FRAME_PTR f
= XFRAME (w
->frame
);
2849 int tab_width
= XINT (current_buffer
->tab_width
);
2850 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
2851 int width
= window_internal_width (w
) - 1;
2852 struct position val
;
2855 int last_invis_skip
= 0;
2856 Lisp_Object last_invis_prop
;
2857 int hscroll
= XINT (w
->hscroll
);
2858 int truncate
= (hscroll
2859 || (truncate_partial_width_windows
2860 && !WINDOW_FULL_WIDTH_P (w
))
2861 || !NILP (current_buffer
->truncate_lines
));
2863 /* 1 if we should highlight the region. */
2864 int highlight_region
2865 = (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
)
2866 && (XWINDOW (current_buffer
->last_selected_window
) == w
2867 || highlight_nonselected_windows
));
2868 int region_beg
, region_end
;
2870 int selective
= (INTEGERP (current_buffer
->selective_display
)
2871 ? XINT (current_buffer
->selective_display
)
2872 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2873 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
2874 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
2876 Lisp_Object default_invis_vector
[3];
2877 /* Number of characters of ellipsis to display after an invisible line
2878 if it calls for an ellipsis.
2879 Note that this value can be nonzero regardless of whether
2880 selective display is enabled--you must check that separately. */
2882 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2883 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
2884 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
2885 /* This is the sequence of Lisp objects to display
2886 when there are invisible lines. */
2887 Lisp_Object
*invis_vector_contents
2888 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2889 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
2890 : default_invis_vector
);
2892 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
2893 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp
)))
2894 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
2895 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
2896 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp
)))
2897 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
2899 /* If 1, we must handle multibyte characters. */
2900 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
2901 /* Length of multibyte form of each character. */
2903 /* Glyphs generated should be set this bit mask if text must be
2904 displayed from right to left. */
2905 GLYPH rev_dir_bit
= (NILP (current_buffer
->direction_reversed
)
2906 ? 0 : GLYPH_MASK_REV_DIR
);
2908 /* The next buffer location at which the face should change, due
2909 to overlays or text property changes. */
2910 int next_face_change
;
2912 /* The next location where the `invisible' property changes, or an
2913 overlay starts or ends. */
2916 /* The face we're currently using. */
2917 int current_face
= 0;
2920 XSETFASTINT (default_invis_vector
[2], '.');
2921 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
2923 get_display_line (f
, vpos
, WINDOW_LEFT_MARGIN (w
));
2924 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
2926 /* Show where to highlight the region. */
2927 if (highlight_region
&& XMARKER (current_buffer
->mark
)->buffer
!= 0
2928 /* Maybe highlight only in selected window. */
2929 && (highlight_nonselected_windows
2930 || w
== XWINDOW (selected_window
)))
2932 region_beg
= marker_position (current_buffer
->mark
);
2933 if (PT
< region_beg
)
2935 region_end
= region_beg
;
2940 w
->region_showing
= Qt
;
2944 region_beg
= region_end
= -1;
2945 w
->region_showing
= Qnil
;
2948 if (MINI_WINDOW_P (w
)
2950 && vpos
== XFASTINT (w
->top
))
2952 if (! NILP (minibuf_prompt
))
2954 int old_width
= minibuf_prompt_width
;
2956 minibuf_prompt_width
2957 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
2958 XSTRING (minibuf_prompt
)->size
,
2959 hpos
+ WINDOW_LEFT_MARGIN (w
),
2960 /* Display a space if we truncate. */
2963 /* Truncate the prompt a little before the
2964 margin, so user input can at least start
2965 on the first line. */
2966 (XFASTINT (w
->width
) > 10
2967 ? XFASTINT (w
->width
) - 4 : -1))
2968 - hpos
- WINDOW_LEFT_MARGIN (w
));
2969 hpos
+= minibuf_prompt_width
;
2970 taboffset
-= minibuf_prompt_width
- old_width
;
2973 minibuf_prompt_width
= 0;
2976 /* If we're hscrolled at all, use compute_motion to skip over any
2977 text off the left edge of the window. compute_motion may know
2978 tricks to do this faster than we can. */
2981 struct position
*left_edge
2982 = compute_motion (pos
, vpos
, hpos
, 0,
2984 width
, hscroll
, taboffset
, w
);
2986 /* Retrieve the buffer position and column provided by
2987 compute_motion. We can't assume that the column will be
2988 zero, because you may have multi-column characters crossing
2991 compute_motion may have moved us past the screen position we
2992 requested, if we hit a multi-column character, or the end of
2993 the line. If so, back up. */
2994 if (left_edge
->vpos
> vpos
2995 || left_edge
->hpos
> 0)
2997 pos
= left_edge
->bufpos
;
2998 /* Since this should not be a valid multibyte character, we
2999 can decrease POS by 1. */
3001 hpos
= left_edge
->prevhpos
;
3005 pos
= left_edge
->bufpos
;
3006 hpos
= left_edge
->hpos
;
3010 hpos
+= WINDOW_LEFT_MARGIN (w
);
3012 desired_glyphs
->bufp
[vpos
] = start
;
3013 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
3015 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
3016 /* In case we don't ever write anything into it... */
3017 desired_glyphs
->charstarts
[vpos
][WINDOW_LEFT_MARGIN (w
)] = -1;
3018 leftmargin
= desired_glyphs
->glyphs
[vpos
] + WINDOW_LEFT_MARGIN (w
);
3019 endp
= leftmargin
+ width
;
3021 /* Arrange the overlays nicely for our purposes. Usually, we call
3022 display_text_line on only one line at a time, in which case this
3023 can't really hurt too much, or we call it on lines which appear
3024 one after another in the buffer, in which case all calls to
3025 recenter_overlay_lists but the first will be pretty cheap. */
3026 recenter_overlay_lists (current_buffer
, pos
);
3028 /* Loop generating characters.
3029 Stop at end of buffer, before newline,
3030 if reach or pass continuation column,
3031 or at face change. */
3033 next_face_change
= pos
;
3034 next_boundary
= pos
;
3038 /* If the window is hscrolled and point is in the invisible part of the
3039 current line beyond the left margin we can record the cursor location
3041 if (hscroll
&& start
<= PT
&& PT
< pos
&& cursor_vpos
< 0)
3044 cursor_hpos
= p1
- leftmargin
;
3053 while (pos
== next_boundary
)
3055 Lisp_Object position
, limit
, prop
, ww
;
3057 /* Display the overlay strings here, unless we're at ZV
3058 and have already displayed the appropriate strings
3059 on an earlier line. */
3060 if (pos
< ZV
|| !zv_strings_seen
++)
3063 unsigned char *ovstr
;
3064 ovlen
= overlay_strings (pos
, w
, &ovstr
);
3068 /* Skip the ones we did in a previous line. */
3069 ovstr
+= ovstr_done
;
3070 ovlen
-= ovstr_done
;
3079 c
= STRING_CHAR_AND_LENGTH (ovstr
, ovlen
, len
);
3080 ovstr
+= len
, ovlen
-= len
, ovstr_done
+= len
;
3081 charset
= CHAR_CHARSET (c
);
3082 cols
= (charset
== CHARSET_COMPOSITION
3083 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3084 : CHARSET_WIDTH (charset
));
3088 c
= *ovstr
++, ovlen
--, ovstr_done
++;
3091 g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3094 if (p1
>= leftmargin
&& p1
< endp
)
3095 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3099 /* If we did all the overlay strings
3100 and we have room for text, clear ovstr_done
3101 just for neatness' sake. */
3102 if (ovlen
== 0 && p1
< endp
)
3107 /* Did we reach point? Record the cursor location. */
3108 if (pos
== PT
&& cursor_vpos
< 0)
3111 cursor_hpos
= p1
- leftmargin
;
3117 XSETFASTINT (position
, pos
);
3118 limit
= Fnext_overlay_change (position
);
3119 #ifdef USE_TEXT_PROPERTIES
3120 /* This is just an estimate to give reasonable
3121 performance; nothing should go wrong if it is too small. */
3122 if (XFASTINT (limit
) > pos
+ 50)
3124 int limitpos
= pos
+ 50;
3126 INC_POS (limitpos
); /* Adjust to character boundary. */
3127 XSETFASTINT (limit
, limitpos
);
3129 limit
= Fnext_single_property_change (position
, Qinvisible
,
3130 Fcurrent_buffer (), limit
);
3132 next_boundary
= XFASTINT (limit
);
3133 /* if the `invisible' property is set, we can skip to
3134 the next property change. */
3136 prop
= Fget_char_property (position
, Qinvisible
, ww
);
3137 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3139 if (pos
< PT
&& next_boundary
>= PT
)
3142 cursor_hpos
= p1
- leftmargin
;
3144 pos
= next_boundary
;
3145 last_invis_skip
= pos
;
3146 last_invis_prop
= prop
;
3150 /* Did we reach point? Record the cursor location. */
3151 if (pos
== PT
&& cursor_vpos
< 0)
3154 cursor_hpos
= p1
- leftmargin
;
3157 /* Did we hit the end of the visible region of the buffer?
3161 /* Update charstarts for the end of this line. */
3162 /* Do nothing if off the left edge or at the right edge. */
3163 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
3165 int *p2x
= &charstart
[(p1
< leftmargin
3173 /* Figure out where (if at all) the
3174 redisplay_end_trigger-hook should run. */
3175 if (MARKERP (w
->redisplay_end_trigger
)
3176 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
3177 e_t_h
= marker_position (w
->redisplay_end_trigger
);
3178 else if (INTEGERP (w
->redisplay_end_trigger
))
3179 e_t_h
= XINT (w
->redisplay_end_trigger
);
3183 /* If we've gone past the place to run a hook,
3185 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
3187 Lisp_Object args
[3];
3189 args
[0] = Qredisplay_end_trigger_functions
;
3190 XSETWINDOW (args
[1], w
);
3191 XSETINT (args
[2], e_t_h
);
3193 /* Since we are *trying* to run these functions,
3194 don't try to run them again, even if they get an error. */
3195 w
->redisplay_end_trigger
= Qnil
;
3196 Frun_hook_with_args (3, args
);
3199 /* Notice if it changed the face of this character. */
3200 next_face_change
= pos
;
3204 /* Did we hit a face change? Figure out what face we should
3205 use now. We also hit this the first time through the
3206 loop, to see what face we should start with. */
3207 if (pos
>= next_face_change
3208 && (FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
)))
3210 int limit
= pos
+ 50;
3212 if (limit
< Z
&& !CHAR_HEAD_P (POS_ADDR (limit
)))
3213 INC_POS (limit
); /* Adjust to character boundary. */
3214 current_face
= compute_char_face (f
, w
, pos
,
3215 region_beg
, region_end
,
3216 &next_face_change
, limit
, 0);
3220 /* Compute the next place we need to stop
3221 and do something special; set PAUSE. */
3225 if (pos
< next_boundary
&& next_boundary
< pause
)
3226 pause
= next_boundary
;
3227 if (pos
< next_face_change
&& next_face_change
< pause
)
3228 pause
= next_face_change
;
3233 /* Wouldn't you hate to read the next line to someone over
3235 if (pos
< PT
&& PT
< pause
)
3237 if (pos
< GPT
&& GPT
< pause
)
3249 /* PAUSE is surely at character boundary. */
3250 c
= STRING_CHAR_AND_LENGTH (p
, pause
- pos
, len
), p
+= len
;
3253 /* Let a display table override all standard display methods. */
3254 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3256 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
3257 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3258 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3259 current_face
, rev_dir_bit
);
3261 else if (c
>= 040 && c
< 0177)
3263 if (p1
>= leftmargin
)
3264 *p1
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3270 /* Same as p1prev, but after the invis_vector_contents text
3271 (if we have that on this line). */
3272 GLYPH
*p1prev_modified
;
3276 if (last_invis_skip
== pos
3277 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
3281 && indented_beyond_p (pos
+ 1, selective
))
3284 pos
= find_next_newline (pos
+ 1, 1);
3285 if (FETCH_BYTE (pos
- 1) == '\n')
3288 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
3293 cs
= charstart
+ (p1
- p1start
);
3296 p1
+= selective_rlen
;
3297 if (p1
- leftmargin
> width
)
3300 #if 0 /* This needs more work; charstarts needs to record
3301 both whether a position ho;ds an ellipsis character
3302 and what buffer position it corresponds to. */
3303 csend
= charstart
+ (p1
- p1start
);
3306 /* The idea is to use p1prev_modified instead of p1prev
3307 in the loop below over p2x. */
3308 p1prev_modified
= p1
;
3311 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3312 (p1
- p1prev
), current_face
, rev_dir_bit
);
3315 /* Update charstarts for the newline that ended this line. */
3316 /* Do nothing here for a char that's entirely off the left edge
3317 or if it starts at the right edge. */
3318 if (p1
>= leftmargin
&& p1prev
!= endp
)
3320 /* Store the newline's position into charstarts
3321 for the column where the newline starts.
3322 Store -1 for the rest of the glyphs it occupies. */
3323 int *p2x
= &charstart
[(p1prev
< leftmargin
3324 ? leftmargin
: p1prev
)
3326 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3333 /* Draw the face of the newline character as extending all the
3334 way to the end of the frame line. */
3337 if (p1
< leftmargin
)
3340 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3350 if (p1
>= leftmargin
&& p1
< endp
)
3351 *p1
= MAKE_GLYPH (f
, ' ', current_face
) | rev_dir_bit
;
3354 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
3357 else if (c
== Ctl ('M') && selective
== -1)
3359 pos
= find_next_newline (pos
, 1);
3360 if (FETCH_BYTE (pos
- 1) == '\n')
3362 if (selective_rlen
> 0)
3364 p1
+= selective_rlen
;
3365 if (p1
- leftmargin
> width
)
3367 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3368 (p1
- p1prev
), current_face
, rev_dir_bit
);
3371 /* Draw the face of the newline character as extending all the
3372 way to the end of the frame line. */
3375 if (p1
< leftmargin
)
3378 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3382 /* Update charstarts for the ^M that ended this line. */
3383 /* Do nothing here for a char that's entirely off the left edge
3384 or if it starts at the right edge. */
3385 if (p1
>= leftmargin
&& p1prev
!= endp
)
3387 /* Store the newline's position into charstarts
3388 for the column where the newline starts.
3389 Store -1 for the rest of the glyphs it occupies. */
3390 int *p2x
= &charstart
[(p1prev
< leftmargin
3391 ? leftmargin
: p1prev
)
3393 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3401 else if (c
< 0200 && ctl_arrow
)
3403 if (p1
>= leftmargin
)
3405 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3406 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
3407 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3411 if (p1
>= leftmargin
&& p1
< endp
)
3412 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
) | rev_dir_bit
;
3417 /* C is not a multibyte character. */
3418 if (p1
>= leftmargin
)
3420 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3421 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
3422 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3426 if (p1
>= leftmargin
&& p1
< endp
)
3427 *p1
= MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
) | rev_dir_bit
;
3429 if (p1
>= leftmargin
&& p1
< endp
)
3430 *p1
= (MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
)
3433 if (p1
>= leftmargin
&& p1
< endp
)
3434 *p1
= MAKE_GLYPH (f
, (7 & c
) + '0', current_face
) | rev_dir_bit
;
3439 /* C is a multibyte character. */
3440 int charset
= CHAR_CHARSET (c
);
3441 int columns
= (charset
== CHARSET_COMPOSITION
3442 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3443 : CHARSET_WIDTH (charset
));
3444 GLYPH g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3448 if (p1
>= leftmargin
&& p1
< endp
)
3449 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3457 /* Update charstarts for the character just output. */
3459 /* Do nothing here for a char that's entirely off the left edge. */
3460 if (p1
>= leftmargin
)
3462 /* Store the char's position into charstarts
3463 for the first glyph occupied by this char.
3464 Store -1 for the rest of the glyphs it occupies. */
3467 int *p2x
= &charstart
[(p1prev
< leftmargin
3468 ? leftmargin
: p1prev
)
3470 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3480 val
.hpos
= - XINT (w
->hscroll
);
3488 /* Store 0 in this charstart line for the positions where
3489 there is no character. But do leave what was recorded
3490 for the character that ended the line. */
3491 /* Add 1 in the endtest to compensate for the fact that ENDP was
3492 made from WIDTH, which is 1 less than the window's actual
3494 i
= p1
- p1start
+ 1;
3495 if (p1
< leftmargin
)
3496 i
+= leftmargin
- p1
;
3497 for (; i
< endp
- p1start
+ 1; i
++)
3500 /* Handle continuation in middle of a character */
3501 /* by backing up over it */
3504 /* Don't back up if we never actually displayed any text.
3505 This occurs when the minibuffer prompt takes up the whole line. */
3508 /* Start the next line with that same character whose
3509 character code is C and the length of multi-byte form is
3514 /* C is not a multi-byte character. We can break it and
3515 start from the middle column in the next line. So,
3516 adjust VAL.HPOS to skip the columns output on this
3518 val
.hpos
+= p1prev
- endp
;
3521 /* C is a multibyte character. Since we can't broke it
3522 in the middle, the whole character should be driven
3523 into the next line. */
3524 /* As the result, the actual columns occupied by the
3525 text on this line is less than WIDTH. VAL.TAB_OFFSET
3526 must be adjusted. */
3527 taboffset
= taboffset
+ (p1prev
- endp
);
3528 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3530 GLYPH g
= fix_glyph (f
, truncate
? truncator
: continuer
, 0);
3531 while (p1prev
< endp
)
3534 /* If POINT is at POS, cursor should not on this line. */
3541 /* Keep in this line everything up to the continuation column. */
3545 /* Finish deciding which character to start the next line on,
3546 and what hpos to start it at.
3547 Also set `lastpos' to the last position which counts as "on this line"
3548 for cursor-positioning. */
3552 if (FETCH_BYTE (pos
) == '\n')
3554 /* If stopped due to a newline, start next line after it */
3557 /* Check again for hidden lines, in case the newline occurred exactly
3558 at the right margin. */
3559 while (pos
< ZV
&& selective
> 0
3560 && indented_beyond_p (pos
, selective
))
3561 pos
= find_next_newline (pos
, 1);
3564 /* Stopped due to right margin of window */
3568 *p1
++ = fix_glyph (f
, truncator
, 0);
3569 /* Truncating => start next line after next newline,
3570 and point is on this line if it is before the newline,
3571 and skip none of first char of next line */
3573 pos
= find_next_newline (pos
, 1);
3574 while (pos
< ZV
&& selective
> 0
3575 && indented_beyond_p (pos
, selective
));
3576 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
3578 lastpos
= pos
- (FETCH_BYTE (pos
- 1) == '\n');
3583 *p1
++ = fix_glyph (f
, continuer
, 0);
3586 val
.tab_offset
= taboffset
+ width
;
3593 /* If point is at eol or in invisible text at eol,
3594 record its frame location now. */
3596 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
3599 cursor_hpos
= p1
- leftmargin
;
3602 if (cursor_vpos
== vpos
)
3604 if (cursor_hpos
< 0) cursor_hpos
= 0;
3605 if (cursor_hpos
> width
) cursor_hpos
= width
;
3606 cursor_hpos
+= WINDOW_LEFT_MARGIN (w
);
3607 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
3609 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
3610 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
3612 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3613 FRAME_CURSOR_X (f
) = cursor_hpos
;
3616 if (w
== XWINDOW (selected_window
))
3618 /* Line is not continued and did not start
3619 in middle of character */
3620 if ((hpos
- WINDOW_LEFT_MARGIN (w
)
3621 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
3624 this_line_bufpos
= start
;
3625 this_line_buffer
= current_buffer
;
3626 this_line_vpos
= cursor_vpos
;
3627 this_line_start_hpos
= hpos
- WINDOW_LEFT_MARGIN (w
);
3628 this_line_endpos
= Z
- lastpos
;
3631 this_line_bufpos
= 0;
3636 /* If hscroll and line not empty, insert truncation-at-left marker */
3637 if (hscroll
&& lastpos
!= start
)
3639 GLYPH g
= fix_glyph (f
, truncator
, 0);
3641 if (p1
<= leftmargin
)
3642 p1
= leftmargin
+ 1;
3643 else /* MULE: it may be a wide-column character */
3645 p1prev
= leftmargin
+ 1;
3646 while (p1prev
< p1
&& *p1prev
& GLYPH_MASK_PADDING
)
3651 if (!WINDOW_RIGHTMOST_P (w
))
3654 if (p1
< leftmargin
) p1
= leftmargin
;
3655 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
3657 /* Don't draw vertical bars if we're using scroll bars. They're
3658 covered up by the scroll bars, and it's distracting to see
3659 them when the scroll bar windows are flickering around to be
3661 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
3664 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
3667 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3668 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
3669 ? XINT (DISP_BORDER_GLYPH (dp
))
3672 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
3673 p1
- desired_glyphs
->glyphs
[vpos
]);
3674 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
3676 /* If the start of this line is the overlay arrow-position,
3677 then put the arrow string into the display-line. */
3679 if (MARKERP (Voverlay_arrow_position
)
3680 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
3681 && start
== marker_position (Voverlay_arrow_position
)
3682 && STRINGP (Voverlay_arrow_string
)
3683 && ! overlay_arrow_seen
)
3685 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
3687 int len
= XSTRING (Voverlay_arrow_string
)->size
;
3693 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string
)->intervals
))
3695 /* If the arrow string has text props, obey them when displaying. */
3696 for (i
= 0; i
< len
; i
++)
3699 Lisp_Object face
, ilisp
;
3702 XSETFASTINT (ilisp
, i
);
3703 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
3704 newface
= compute_glyph_face_1 (f
, face
, 0);
3705 leftmargin
[i
] = FAST_MAKE_GLYPH (c
, newface
);
3709 #endif /* HAVE_FACES */
3711 for (i
= 0; i
< len
; i
++)
3712 leftmargin
[i
] = p
[i
];
3715 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3716 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
3717 if (desired_glyphs
->used
[vpos
] < arrow_end
)
3718 desired_glyphs
->used
[vpos
] = arrow_end
;
3720 overlay_arrow_seen
= 1;
3724 val
.ovstring_chars_done
= ovstr_done
;
3725 val_display_text_line
= val
;
3726 return &val_display_text_line
;
3729 /* Redisplay the menu bar in the frame for window W. */
3732 display_menu_bar (w
)
3735 Lisp_Object items
, tail
;
3736 register int vpos
= 0;
3737 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3738 int maxendcol
= FRAME_WIDTH (f
);
3743 if (!NILP (Vwindow_system
))
3747 #ifdef USE_X_TOOLKIT
3750 #endif /* USE_X_TOOLKIT */
3752 get_display_line (f
, vpos
, 0);
3754 items
= FRAME_MENU_BAR_ITEMS (f
);
3755 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
3757 Lisp_Object pos
, string
;
3758 string
= XVECTOR (items
)->contents
[i
+ 1];
3762 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], hpos
);
3764 if (hpos
< maxendcol
)
3765 hpos
= display_string (w
, vpos
,
3766 XSTRING (string
)->data
,
3767 XSTRING (string
)->size
,
3768 hpos
, 0, 0, hpos
, maxendcol
);
3769 /* Put a space between items. */
3770 if (hpos
< maxendcol
)
3772 int hpos1
= hpos
+ 1;
3773 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
3774 min (hpos1
, maxendcol
), maxendcol
);
3778 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3779 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3781 /* Fill out the line with spaces. */
3782 if (maxendcol
> hpos
)
3783 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
);
3785 /* Clear the rest of the lines allocated to the menu bar. */
3787 while (vpos
< FRAME_MENU_BAR_LINES (f
))
3788 get_display_line (f
, vpos
++, 0);
3791 /* Display the mode line for window w */
3794 display_mode_line (w
)
3797 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
3798 register int left
= WINDOW_LEFT_MARGIN (w
);
3799 register int right
= WINDOW_RIGHT_MARGIN (w
);
3800 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3802 line_number_displayed
= 0;
3803 w
->column_number_displayed
= Qnil
;
3805 get_display_line (f
, vpos
, left
);
3807 /* Temporarily make frame F's kboard the current kboard
3808 so that kboard-local variables in the mode_line_format
3809 will get the right values. */
3810 push_frame_kboard (f
);
3812 display_mode_element (w
, vpos
, left
, 0, right
, right
,
3813 current_buffer
->mode_line_format
);
3815 pop_frame_kboard ();
3817 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3819 /* Put the mode line in inverse video.
3820 Use faces if possible, since that lets us handle
3821 partial-width windows and avoid inverting the scroll bar columns. */
3823 if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
3825 /* For a partial width window, explicitly set face of each glyph. */
3827 unsigned int padding
;
3828 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
3829 for (i
= left
; i
< right
; ++i
)
3831 padding
= ptr
[i
] & GLYPH_MASK_PADDING
;
3832 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1) | padding
;
3838 /* Make the mode line inverse video if the entire line
3839 is made of mode lines.
3840 I.e. if this window is full width,
3841 or if it is the child of a full width window
3842 (which implies that that window is split side-by-side
3843 and the rest of this line is mode lines of the sibling windows). */
3844 if (WINDOW_FULL_WIDTH_P (w
)
3845 || WINDOW_FULL_WIDTH_P (XWINDOW (w
->parent
)))
3846 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3849 /* Contribute ELT to the mode line for window W.
3850 How it translates into text depends on its data type.
3852 VPOS is the position of the mode line being displayed.
3854 HPOS is the position (absolute on frame) where this element's text
3855 should start. The output is truncated automatically at the right
3858 DEPTH is the depth in recursion. It is used to prevent
3859 infinite recursion here.
3861 MINENDCOL is the hpos before which the element may not end.
3862 The element is padded at the right with spaces if nec
3863 to reach this column.
3865 MAXENDCOL is the hpos past which this element may not extend.
3866 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3867 (This is necessary to make nested padding and truncation work.)
3869 Returns the hpos of the end of the text generated by ELT.
3870 The next element will receive that value as its HPOS arg,
3871 so as to concatenate the elements. */
3874 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
3876 register int vpos
, hpos
;
3879 register int maxendcol
;
3880 register Lisp_Object elt
;
3888 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
3892 /* A string: output it and check for %-constructs within it. */
3893 register unsigned char c
;
3894 register unsigned char *this = XSTRING (elt
)->data
;
3896 while (hpos
< maxendcol
&& *this)
3898 unsigned char *last
= this;
3899 while ((c
= *this++) != '\0' && c
!= '%')
3901 if (this - 1 != last
)
3903 register int lim
= --this - last
+ hpos
;
3904 if (frame_title_ptr
)
3905 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
3907 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
3908 hpos
, min (lim
, maxendcol
));
3912 register int minendcol
;
3913 register int spec_width
= 0;
3915 /* We can't allow -ve args due to the "%-" construct */
3916 /* Argument specifies minwidth but not maxwidth
3917 (maxwidth can be specified by
3918 (<negative-number> . <stuff>) mode-line elements) */
3920 while ((c
= *this++) >= '0' && c
<= '9')
3922 spec_width
= spec_width
* 10 + (c
- '0');
3925 minendcol
= hpos
+ spec_width
;
3926 if (minendcol
> maxendcol
)
3928 spec_width
= maxendcol
- hpos
;
3929 minendcol
= maxendcol
;
3933 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
3934 spec_width
, maxendcol
,
3935 Vglobal_mode_string
);
3938 char *spec
= decode_mode_spec (w
, c
, spec_width
,
3940 if (frame_title_ptr
)
3941 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
3943 hpos
= display_string (w
, vpos
, spec
, -1,
3945 minendcol
, maxendcol
);
3953 /* A symbol: process the value of the symbol recursively
3954 as if it appeared here directly. Avoid error if symbol void.
3955 Special case: if value of symbol is a string, output the string
3958 register Lisp_Object tem
;
3959 tem
= Fboundp (elt
);
3962 tem
= Fsymbol_value (elt
);
3963 /* If value is a string, output that string literally:
3964 don't check for % within it. */
3967 if (frame_title_ptr
)
3968 hpos
= store_frame_title (XSTRING (tem
)->data
,
3969 minendcol
, maxendcol
);
3971 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
3972 XSTRING (tem
)->size
,
3973 hpos
, 0, 1, minendcol
, maxendcol
);
3975 /* Give up right away for nil or t. */
3976 else if (!EQ (tem
, elt
))
3977 { elt
= tem
; goto tail_recurse
; }
3984 register Lisp_Object car
, tem
;
3986 /* A cons cell: three distinct cases.
3987 If first element is a string or a cons, process all the elements
3988 and effectively concatenate them.
3989 If first element is a negative number, truncate displaying cdr to
3990 at most that many characters. If positive, pad (with spaces)
3991 to at least that many characters.
3992 If first element is a symbol, process the cadr or caddr recursively
3993 according to whether the symbol's value is non-nil or nil. */
3994 car
= XCONS (elt
)->car
;
3997 tem
= Fboundp (car
);
3998 elt
= XCONS (elt
)->cdr
;
4001 /* elt is now the cdr, and we know it is a cons cell.
4002 Use its car if CAR has a non-nil value. */
4005 tem
= Fsymbol_value (car
);
4007 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
4009 /* Symbol's value is nil (or symbol is unbound)
4010 Get the cddr of the original list
4011 and if possible find the caddr and use that. */
4012 elt
= XCONS (elt
)->cdr
;
4015 else if (!CONSP (elt
))
4017 elt
= XCONS (elt
)->car
;
4020 else if (INTEGERP (car
))
4022 register int lim
= XINT (car
);
4023 elt
= XCONS (elt
)->cdr
;
4025 /* Negative int means reduce maximum width.
4026 DO NOT change MINENDCOL here!
4027 (20 -10 . foo) should truncate foo to 10 col
4028 and then pad to 20. */
4029 maxendcol
= min (maxendcol
, hpos
- lim
);
4032 /* Padding specified. Don't let it be more than
4035 if (lim
> maxendcol
)
4037 /* If that's more padding than already wanted, queue it.
4038 But don't reduce padding already specified even if
4039 that is beyond the current truncation point. */
4040 if (lim
> minendcol
)
4045 else if (STRINGP (car
) || CONSP (car
))
4047 register int limit
= 50;
4048 /* LIMIT is to protect against circular lists. */
4049 while (CONSP (elt
) && --limit
> 0
4050 && hpos
< maxendcol
)
4052 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4055 elt
= XCONS (elt
)->cdr
;
4063 if (frame_title_ptr
)
4064 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
4066 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
4067 minendcol
, maxendcol
);
4071 if (minendcol
> hpos
)
4072 if (frame_title_ptr
)
4073 hpos
= store_frame_title ("", minendcol
, maxendcol
);
4075 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 1, minendcol
, maxendcol
);
4079 /* Write a null-terminated, right justified decimal representation of
4080 the positive integer D to BUF using a minimal field width WIDTH. */
4083 pint2str (buf
, width
, d
)
4088 register char *p
= buf
;
4095 *p
++ = d
% 10 + '0';
4098 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
4108 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4109 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4110 type of CODING_SYSTEM. Return updated pointer into BUF. */
4113 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
4114 Lisp_Object coding_system
;
4119 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
4121 val
= coding_system
;
4123 if (NILP (val
)) /* Not yet decided. */
4128 *buf
++ = eol_mnemonic_undecided
;
4129 /* Don't mention EOL conversion if it isn't decided. */
4133 Lisp_Object eolvalue
;
4135 eolvalue
= Fget (coding_system
, Qeol_type
);
4137 while (!NILP (val
) && SYMBOLP (val
))
4139 val
= Fget (val
, Qcoding_system
);
4140 if (NILP (eolvalue
))
4141 eolvalue
= Fget (val
, Qeol_type
);
4145 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
4149 /* The EOL conversion we are using. */
4151 /* The EOL conversion that is normal on this system. */
4153 if (NILP (eolvalue
)) /* Not yet decided. */
4154 eoltype
= eol_mnemonic_undecided
;
4155 else if (VECTORP (eolvalue
)) /* Not yet decided. */
4156 eoltype
= eol_mnemonic_undecided
;
4157 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4158 eoltype
= (XFASTINT (eolvalue
) == 0
4160 : (XFASTINT (eolvalue
) == 1
4161 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
4163 /* Mention the EOL conversion if it is not the usual one. */
4170 /* Return a string for the output of a mode line %-spec for window W,
4171 generated by character C. SPEC_WIDTH is the field width when
4172 padding to the left (%c, %l). The value returned from this
4173 function will later be truncated to width MAXWIDTH. */
4175 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4178 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
4181 register int spec_width
;
4182 register int maxwidth
;
4185 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4186 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
4187 struct buffer
*b
= XBUFFER (w
->buffer
);
4190 if (maxwidth
> FRAME_WIDTH (f
))
4191 maxwidth
= FRAME_WIDTH (f
);
4196 if (!NILP (b
->read_only
))
4198 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4203 /* This differs from %* only for a modified read-only buffer. */
4204 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4206 if (!NILP (b
->read_only
))
4211 /* This differs from %* in ignoring read-only-ness. */
4212 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4224 if (command_loop_level
> 5)
4226 p
= decode_mode_spec_buf
;
4227 for (i
= 0; i
< command_loop_level
; i
++)
4230 return decode_mode_spec_buf
;
4238 if (command_loop_level
> 5)
4240 p
= decode_mode_spec_buf
;
4241 for (i
= 0; i
< command_loop_level
; i
++)
4244 return decode_mode_spec_buf
;
4252 if (maxwidth
< sizeof (lots_of_dashes
))
4253 return lots_of_dashes
;
4256 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
4260 return decode_mode_spec_buf
;
4266 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
4268 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
4269 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
4270 decode_mode_spec_buf
[maxwidth
] = '\0';
4271 return decode_mode_spec_buf
;
4278 int col
= current_column ();
4279 XSETFASTINT (w
->column_number_displayed
, col
);
4280 pint2str (decode_mode_spec_buf
, spec_width
, col
);
4281 return decode_mode_spec_buf
;
4285 /* %F displays the frame name. */
4286 if (!NILP (f
->title
))
4287 return (char *) XSTRING (f
->title
)->data
;
4288 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
4289 return (char *) XSTRING (f
->name
)->data
;
4297 else if (STRINGP (obj
) && XSTRING (obj
)->size
> maxwidth
)
4299 bcopy ("...", decode_mode_spec_buf
, 3);
4300 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
4301 decode_mode_spec_buf
+ 3, maxwidth
- 3);
4302 return decode_mode_spec_buf
;
4309 int startpos
= marker_position (w
->start
);
4310 int line
, linepos
, topline
;
4313 int height
= XFASTINT (w
->height
);
4315 /* If we decided that this buffer isn't suitable for line numbers,
4316 don't forget that too fast. */
4317 if (EQ (w
->base_line_pos
, w
->buffer
))
4319 /* But do forget it, if the window shows a different buffer now. */
4320 else if (BUFFERP (w
->base_line_pos
))
4321 w
->base_line_pos
= Qnil
;
4323 /* If the buffer is very big, don't waste time. */
4324 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
4326 w
->base_line_pos
= Qnil
;
4327 w
->base_line_number
= Qnil
;
4331 if (!NILP (w
->base_line_number
)
4332 && !NILP (w
->base_line_pos
)
4333 && XFASTINT (w
->base_line_pos
) <= marker_position (w
->start
))
4335 line
= XFASTINT (w
->base_line_number
);
4336 linepos
= XFASTINT (w
->base_line_pos
);
4341 linepos
= BUF_BEGV (b
);
4344 /* Count lines from base line to window start position. */
4345 nlines
= display_count_lines (linepos
, startpos
, startpos
, &junk
);
4347 topline
= nlines
+ line
;
4349 /* Determine a new base line, if the old one is too close
4350 or too far away, or if we did not have one.
4351 "Too close" means it's plausible a scroll-down would
4353 if (startpos
== BUF_BEGV (b
))
4355 XSETFASTINT (w
->base_line_number
, topline
);
4356 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
4358 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
4359 || linepos
== BUF_BEGV (b
))
4361 int limit
= BUF_BEGV (b
);
4363 int distance
= (height
* 2 + 30) * 200;
4365 if (startpos
- distance
> limit
)
4366 limit
= startpos
- distance
;
4368 nlines
= display_count_lines (startpos
, limit
,
4371 /* If we couldn't find the lines we wanted within
4373 give up on line numbers for this window. */
4374 if (position
== startpos
- distance
)
4376 w
->base_line_pos
= w
->buffer
;
4377 w
->base_line_number
= Qnil
;
4381 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
4382 XSETFASTINT (w
->base_line_pos
, position
);
4385 /* Now count lines from the start pos to point. */
4386 nlines
= display_count_lines (startpos
, PT
, PT
, &junk
);
4388 /* Record that we did display the line number. */
4389 line_number_displayed
= 1;
4391 /* Make the string to show. */
4392 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
4393 return decode_mode_spec_buf
;
4396 char* p
= decode_mode_spec_buf
;
4397 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
4399 return decode_mode_spec_buf
;
4409 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
4415 int pos
= marker_position (w
->start
);
4416 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4418 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
4420 if (pos
<= BUF_BEGV (b
))
4425 else if (pos
<= BUF_BEGV (b
))
4429 if (total
> 1000000)
4430 /* Do it differently for a large value, to avoid overflow. */
4431 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4433 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4434 /* We can't normally display a 3-digit number,
4435 so get us a 2-digit number that is close. */
4438 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4439 return decode_mode_spec_buf
;
4443 /* Display percentage of size above the bottom of the screen. */
4446 int toppos
= marker_position (w
->start
);
4447 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
4448 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4450 if (botpos
>= BUF_ZV (b
))
4452 if (toppos
<= BUF_BEGV (b
))
4459 if (total
> 1000000)
4460 /* Do it differently for a large value, to avoid overflow. */
4461 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4463 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4464 /* We can't normally display a 3-digit number,
4465 so get us a 2-digit number that is close. */
4468 if (toppos
<= BUF_BEGV (b
))
4469 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
4471 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4472 return decode_mode_spec_buf
;
4477 /* status of process */
4478 obj
= Fget_buffer_process (w
->buffer
);
4480 return "no process";
4482 obj
= Fsymbol_name (Fprocess_status (obj
));
4486 case 't': /* indicate TEXT or BINARY */
4487 #ifdef MODE_LINE_BINARY_TEXT
4488 return MODE_LINE_BINARY_TEXT (b
);
4494 /* coding-system (not including end-of-line format) */
4496 /* coding-system (including end-of-line type) */
4498 int eol_flag
= (c
== 'Z');
4499 char *p
= decode_mode_spec_buf
;
4501 if (FRAME_TERMCAP_P (f
))
4503 /* No need to mention EOL here--the terminal never needs
4504 to do EOL conversion. */
4505 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
4506 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
4508 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
4511 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
4513 obj
= Fget_buffer_process (Fcurrent_buffer ());
4516 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
4518 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
4521 #endif /* subprocesses */
4524 return decode_mode_spec_buf
;
4529 return (char *) XSTRING (obj
)->data
;
4534 /* Search for COUNT instances of a line boundary, which means either a
4535 newline or (if selective display enabled) a carriage return.
4536 Start at START. If COUNT is negative, search backwards.
4538 If we find COUNT instances, set *SHORTAGE to zero, and return the
4539 position after the COUNTth match. Note that for reverse motion
4540 this is not the same as the usual convention for Emacs motion commands.
4542 If we don't find COUNT instances before reaching the end of the
4543 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
4544 the number of line boundaries left unfound, and return the end of the
4545 buffer we bumped up against. */
4548 display_scan_buffer (start
, count
, shortage
)
4549 int *shortage
, start
;
4552 int limit
= ((count
> 0) ? ZV
- 1 : BEGV
);
4553 int direction
= ((count
> 0) ? 1 : -1);
4555 register unsigned char *cursor
;
4556 unsigned char *base
;
4558 register int ceiling
;
4559 register unsigned char *ceiling_addr
;
4561 /* If we are not in selective display mode,
4562 check only for newlines. */
4563 if (! (!NILP (current_buffer
->selective_display
)
4564 && !INTEGERP (current_buffer
->selective_display
)))
4565 return scan_buffer ('\n', start
, 0, count
, shortage
, 0);
4567 /* The code that follows is like scan_buffer
4568 but checks for either newline or carriage return. */
4574 while (start
!= limit
+ 1)
4576 ceiling
= BUFFER_CEILING_OF (start
);
4577 ceiling
= min (limit
, ceiling
);
4578 ceiling_addr
= POS_ADDR (ceiling
) + 1;
4579 base
= (cursor
= POS_ADDR (start
));
4582 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
4584 if (cursor
!= ceiling_addr
)
4589 return (start
+ cursor
- base
+ 1);
4592 if (++cursor
== ceiling_addr
)
4598 start
+= cursor
- base
;
4602 start
--; /* first character we scan */
4603 while (start
> limit
- 1)
4604 { /* we WILL scan under start */
4605 ceiling
= BUFFER_FLOOR_OF (start
);
4606 ceiling
= max (limit
, ceiling
);
4607 ceiling_addr
= POS_ADDR (ceiling
) - 1;
4608 base
= (cursor
= POS_ADDR (start
));
4612 while (--cursor
!= ceiling_addr
4613 && *cursor
!= '\n' && *cursor
!= 015)
4615 if (cursor
!= ceiling_addr
)
4620 return (start
+ cursor
- base
+ 1);
4626 start
+= cursor
- base
;
4631 *shortage
= count
* direction
;
4632 return (start
+ ((direction
== 1 ? 0 : 1)));
4635 /* Count up to N lines starting from FROM.
4636 But don't go beyond LIMIT.
4637 Return the number of lines thus found (always positive).
4638 Store the position after what was found into *POS_PTR. */
4641 display_count_lines (from
, limit
, n
, pos_ptr
)
4654 *pos_ptr
= display_scan_buffer (from
, n
, &shortage
);
4660 /* When scanning backwards, scan_buffer stops *after* the last newline
4661 it finds, but does count it. Compensate for that. */
4662 return - n
- shortage
- (*pos_ptr
!= limit
);
4663 return n
- shortage
;
4666 /* Display STRING on one line of window W, starting at HPOS.
4667 Display at position VPOS. Caller should have done get_display_line.
4668 If VPOS == -1, display it as the current frame's title.
4669 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4671 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4673 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4674 MAXCOL is the last column ok to end at. Truncate here.
4675 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4676 Both count from the left edge of the frame, as does HPOS.
4677 The right edge of W is an implicit maximum.
4678 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4680 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4681 at the place where the current window ends in this line
4682 and not display anything beyond there. Otherwise, only MAXCOL
4683 controls where to stop output.
4685 Returns ending hpos. */
4688 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
4689 obey_window_width
, mincol
, maxcol
)
4691 unsigned char *string
;
4695 int obey_window_width
;
4701 int hscroll
= XINT (w
->hscroll
);
4702 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
4703 register GLYPH
*start
;
4704 register GLYPH
*end
;
4705 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4706 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
4707 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
4708 int window_width
= XFASTINT (w
->width
);
4709 /* If 1, we must display multibyte characters. */
4710 int multibyte
= !NILP (XBUFFER (w
->buffer
)->enable_multibyte_characters
);
4712 /* Use the standard display table, not the window's display table.
4713 We don't want the mode line in rot13. */
4714 register struct Lisp_Char_Table
*dp
= 0;
4717 if (DISP_TABLE_P (Vstandard_display_table
))
4718 dp
= XCHAR_TABLE (Vstandard_display_table
);
4720 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
4723 start
= desired_glyphs
->glyphs
[vpos
];
4725 if (obey_window_width
)
4727 start
+= XFASTINT (w
->left
);
4728 end
= start
+ window_width
- (truncate
!= 0);
4730 if (!WINDOW_RIGHTMOST_P (w
))
4732 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4736 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4739 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4744 if (! obey_window_width
4745 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
4746 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
4748 /* Store 0 in charstart for these columns. */
4749 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
4750 desired_glyphs
->charstarts
[vpos
][i
] = 0;
4752 if (maxcol
>= 0 && mincol
> maxcol
)
4756 /* We need this value for multibyte characters. */
4757 length
= strlen (string
);
4759 /* We set truncated to 1 if we get stopped by trying to pass END
4760 (that is, trying to pass MAXCOL.) */
4769 c
= STRING_CHAR_AND_LENGTH (string
, length
, len
);
4771 c
= *string
, len
= 1;
4773 string
+= len
, length
-= len
;
4781 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
4783 p1
= copy_part_of_rope (f
, p1
, start
,
4784 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
4785 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
4788 else if (c
>= 040 && c
< 0177)
4798 if (p1
>= start
&& p1
< end
)
4802 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
4804 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
4808 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
4809 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
4810 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
4813 if (p1
>= start
&& p1
< end
)
4819 /* C is a control character or a binary byte data. */
4822 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
4823 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
4824 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
4827 if (p1
>= start
&& p1
< end
)
4828 *p1
= (c
>> 6) + '0';
4830 if (p1
>= start
&& p1
< end
)
4831 *p1
= (7 & (c
>> 3)) + '0';
4833 if (p1
>= start
&& p1
< end
)
4834 *p1
= (7 & c
) + '0';
4839 /* C is a multibyte character. */
4840 int charset
= CHAR_CHARSET (c
);
4841 int columns
= (charset
== CHARSET_COMPOSITION
4842 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
4843 : CHARSET_WIDTH (charset
));
4847 /* Since we can't show the left part of C, fill all
4848 columns with spaces. */
4849 columns
-= start
- p1
;
4858 else if (p1
+ columns
> end
)
4860 /* Since we can't show the right part of C, fill all
4861 columns with TRUNCATE if TRUNCATE is specified. */
4865 *p1
++ = fix_glyph (f
, truncate
, 0);
4866 /* And tell the line is truncated. */
4873 /* We can show the whole glyph of C. */
4876 *p1
++ = c
| GLYPH_MASK_PADDING
;
4884 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
4886 else if (mincol
>= 0)
4888 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
4894 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
4896 if (len
> desired_glyphs
->used
[vpos
])
4897 desired_glyphs
->used
[vpos
] = len
;
4898 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
4904 /* This is like a combination of memq and assq.
4905 Return 1 if PROPVAL appears as an element of LIST
4906 or as the car of an element of LIST.
4907 If PROPVAL is a list, compare each element against LIST
4908 in that way, and return 1 if any element of PROPVAL is found in LIST.
4910 This function cannot quit. */
4913 invisible_p (propval
, list
)
4914 register Lisp_Object propval
;
4917 register Lisp_Object tail
, proptail
;
4918 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4920 register Lisp_Object tem
;
4921 tem
= XCONS (tail
)->car
;
4922 if (EQ (propval
, tem
))
4924 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
4927 if (CONSP (propval
))
4928 for (proptail
= propval
; CONSP (proptail
);
4929 proptail
= XCONS (proptail
)->cdr
)
4931 Lisp_Object propelt
;
4932 propelt
= XCONS (proptail
)->car
;
4933 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4935 register Lisp_Object tem
;
4936 tem
= XCONS (tail
)->car
;
4937 if (EQ (propelt
, tem
))
4939 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
4946 /* Return 1 if PROPVAL appears as the car of an element of LIST
4947 and the cdr of that element is non-nil.
4948 If PROPVAL is a list, check each element of PROPVAL in that way,
4949 and the first time some element is found,
4950 return 1 if the cdr of that element is non-nil.
4952 This function cannot quit. */
4955 invisible_ellipsis_p (propval
, list
)
4956 register Lisp_Object propval
;
4959 register Lisp_Object tail
, proptail
;
4960 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4962 register Lisp_Object tem
;
4963 tem
= XCONS (tail
)->car
;
4964 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
4965 return ! NILP (XCONS (tem
)->cdr
);
4967 if (CONSP (propval
))
4968 for (proptail
= propval
; CONSP (proptail
);
4969 proptail
= XCONS (proptail
)->cdr
)
4971 Lisp_Object propelt
;
4972 propelt
= XCONS (proptail
)->car
;
4973 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4975 register Lisp_Object tem
;
4976 tem
= XCONS (tail
)->car
;
4977 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
4978 return ! NILP (XCONS (tem
)->cdr
);
4987 staticpro (&Qmenu_bar_update_hook
);
4988 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
4990 staticpro (&Qoverriding_terminal_local_map
);
4991 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
4993 staticpro (&Qoverriding_local_map
);
4994 Qoverriding_local_map
= intern ("overriding-local-map");
4996 staticpro (&Qwindow_scroll_functions
);
4997 Qwindow_scroll_functions
= intern ("window-scroll-functions");
4999 staticpro (&Qredisplay_end_trigger_functions
);
5000 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
5002 staticpro (&last_arrow_position
);
5003 staticpro (&last_arrow_string
);
5004 last_arrow_position
= Qnil
;
5005 last_arrow_string
= Qnil
;
5007 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
5008 "String (or mode line construct) included (normally) in `mode-line-format'.");
5009 Vglobal_mode_string
= Qnil
;
5011 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
5012 "Marker for where to display an arrow on top of the buffer text.\n\
5013 This must be the beginning of a line in order to work.\n\
5014 See also `overlay-arrow-string'.");
5015 Voverlay_arrow_position
= Qnil
;
5017 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
5018 "String to display as an arrow. See also `overlay-arrow-position'.");
5019 Voverlay_arrow_string
= Qnil
;
5021 DEFVAR_INT ("scroll-step", &scroll_step
,
5022 "*The number of lines to try scrolling a window by when point moves out.\n\
5023 If that fails to bring point back on frame, point is centered instead.\n\
5024 If this is zero, point is always centered after it moves off frame.");
5026 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
5027 "*Scroll up to this many lines, to bring point back on screen.");
5028 scroll_conservatively
= 0;
5030 DEFVAR_INT ("scroll-margin", &scroll_margin
,
5031 "*Number of lines of margin at the top and bottom of a window.\n\
5032 Recenter the window whenever point gets within this many lines\n\
5033 of the top or bottom of the window.");
5036 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
5038 DEFVAR_BOOL ("truncate-partial-width-windows",
5039 &truncate_partial_width_windows
,
5040 "*Non-nil means truncate lines in all windows less than full frame wide.");
5041 truncate_partial_width_windows
= 1;
5043 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
5044 "*Non-nil means use inverse video for the mode line.");
5045 mode_line_inverse_video
= 1;
5047 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
5048 "*Maximum buffer size for which line number should be displayed.");
5049 line_number_display_limit
= 1000000;
5051 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
5052 "*Non-nil means highlight region even in nonselected windows.");
5053 highlight_nonselected_windows
= 0;
5055 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
5056 "Non-nil if more than one frame is visible on this display.\n\
5057 Minibuffer-only frames don't count, but iconified frames do.\n\
5058 This variable is not guaranteed to be accurate except while processing\n\
5059 `frame-title-format' and `icon-title-format'.");
5061 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
5062 "Template for displaying the titlebar of visible frames.\n\
5063 \(Assuming the window manager supports this feature.)\n\
5064 This variable has the same structure as `mode-line-format' (which see),\n\
5065 and is used only on frames for which no explicit name has been set\n\
5066 \(see `modify-frame-parameters').");
5067 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
5068 "Template for displaying the titlebar of an iconified frame.\n\
5069 \(Assuming the window manager supports this feature.)\n\
5070 This variable has the same structure as `mode-line-format' (which see),\n\
5071 and is used only on frames for which no explicit name has been set\n\
5072 \(see `modify-frame-parameters').");
5074 = Vframe_title_format
5075 = Fcons (intern ("multiple-frames"),
5076 Fcons (build_string ("%b"),
5077 Fcons (Fcons (build_string (""),
5078 Fcons (intern ("invocation-name"),
5079 Fcons (build_string ("@"),
5080 Fcons (intern ("system-name"),
5084 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
5085 "Maximum number of lines to keep in the message log buffer.\n\
5086 If nil, disable message logging. If t, log messages but don't truncate\n\
5087 the buffer when it becomes large.");
5088 XSETFASTINT (Vmessage_log_max
, 50);
5090 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
5091 "Functions called before redisplay, if window sizes have changed.\n\
5092 The value should be a list of functions that take one argument.\n\
5093 Just before redisplay, for each frame, if any of its windows have changed\n\
5094 size since the last redisplay, or have been split or deleted,\n\
5095 all the functions in the list are called, with the frame as argument.");
5096 Vwindow_size_change_functions
= Qnil
;
5098 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
5099 "List of Functions to call before redisplaying a window with scrolling.\n\
5100 Each function is called with two arguments, the window\n\
5101 and its new display-start position. Note that the value of `window-end'\n\
5102 is not valid when these functions are called.");
5103 Vwindow_scroll_functions
= Qnil
;
5106 /* initialize the window system */
5109 Lisp_Object root_window
;
5110 #ifndef COMPILER_REGISTER_BUG
5112 #endif /* COMPILER_REGISTER_BUG */
5113 struct window
*mini_w
;
5115 this_line_bufpos
= 0;
5117 mini_w
= XWINDOW (minibuf_window
);
5118 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
5120 echo_area_glyphs
= 0;
5121 previous_echo_glyphs
= 0;
5123 if (!noninteractive
)
5125 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
5126 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_MENU_BAR_LINES (f
));
5127 set_window_height (root_window
,
5128 FRAME_HEIGHT (f
) - 1 - FRAME_MENU_BAR_LINES (f
),
5130 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
5131 set_window_height (minibuf_window
, 1, 0);
5133 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
5134 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));