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 /* Like mode-line-format, but for the titlebar on a visible frame. */
118 Lisp_Object Vframe_title_format
;
120 /* Like mode-line-format, but for the titlebar on an iconified frame. */
121 Lisp_Object Vicon_title_format
;
123 /* List of functions to call when a window's size changes. These
124 functions get one arg, a frame on which one or more windows' sizes
126 static Lisp_Object Vwindow_size_change_functions
;
128 /* Values of those variables at last redisplay. */
129 static Lisp_Object last_arrow_position
, last_arrow_string
;
131 Lisp_Object Qmenu_bar_update_hook
;
133 /* Nonzero if overlay arrow has been displayed once in this window. */
134 static int overlay_arrow_seen
;
136 /* Nonzero if visible end of buffer has already been displayed once
137 in this window. (We need this variable in case there are overlay
138 strings that get displayed there.) */
139 static int zv_strings_seen
;
141 /* Nonzero means highlight the region even in nonselected windows. */
142 static int highlight_nonselected_windows
;
144 /* If cursor motion alone moves point off frame,
145 Try scrolling this many lines up or down if that will bring it back. */
146 static int scroll_step
;
148 /* Non-0 means scroll just far enough to bring point back on the screen,
150 static int scroll_conservatively
;
152 /* Recenter the window whenever point gets within this many lines
153 of the top or bottom of the window. */
156 /* Nonzero if try_window_id has made blank lines at window bottom
157 since the last redisplay that paused */
158 static int blank_end_of_window
;
160 /* Number of windows showing the buffer of the selected window
161 (or another buffer with the same base buffer).
162 keyboard.c refers to this. */
165 /* display_text_line sets these to the frame position (origin 0) of point,
166 whether the window is selected or not.
167 Set one to -1 first to determine whether point was found afterwards. */
169 static int cursor_vpos
;
170 static int cursor_hpos
;
172 static int debug_end_pos
;
174 /* Nonzero means display mode line highlighted */
175 int mode_line_inverse_video
;
177 static void redisplay_internal ();
178 static int message_log_check_duplicate ();
179 static void echo_area_display ();
180 void mark_window_display_accurate ();
181 static void redisplay_windows ();
182 static void redisplay_window ();
183 static void update_menu_bar ();
184 static void try_window ();
185 static int try_window_id ();
186 static struct position
*display_text_line ();
187 static void display_mode_line ();
188 static int display_mode_element ();
189 static char *decode_mode_spec ();
190 static int display_string ();
191 static void display_menu_bar ();
192 static int display_count_lines ();
194 /* Prompt to display in front of the minibuffer contents */
195 Lisp_Object minibuf_prompt
;
197 /* Width in columns of current minibuffer prompt. */
198 int minibuf_prompt_width
;
200 /* Message to display instead of minibuffer contents
201 This is what the functions error and message make,
202 and command echoing uses it as well.
203 It overrides the minibuf_prompt as well as the buffer. */
204 char *echo_area_glyphs
;
206 /* This is the length of the message in echo_area_glyphs. */
207 int echo_area_glyphs_length
;
209 /* This is the window where the echo area message was displayed.
210 It is always a minibuffer window, but it may not be the
211 same window currently active as a minibuffer. */
212 Lisp_Object echo_area_window
;
214 /* true iff we should redraw the mode lines on the next redisplay */
215 int update_mode_lines
;
217 /* Smallest number of characters before the gap
218 at any time since last redisplay that finished.
219 Valid for current buffer when try_window_id can be called. */
222 /* Smallest number of characters after the gap
223 at any time since last redisplay that finished.
224 Valid for current buffer when try_window_id can be called. */
227 /* MODIFF as of last redisplay that finished;
228 if it matches MODIFF, and overlay_unchanged_modified
229 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
230 contain no useful information */
231 int unchanged_modified
;
233 /* OVERLAY_MODIFF as of last redisplay that finished. */
234 int overlay_unchanged_modified
;
236 /* Nonzero if window sizes or contents have changed
237 since last redisplay that finished */
238 int windows_or_buffers_changed
;
240 /* Nonzero after display_mode_line if %l was used
241 and it displayed a line number. */
242 int line_number_displayed
;
244 /* Maximum buffer size for which to display line numbers. */
245 static int line_number_display_limit
;
247 /* Number of lines to keep in the message log buffer.
248 t means infinite. nil means don't log at all. */
249 Lisp_Object Vmessage_log_max
;
251 /* Output a newline in the *Messages* buffer if "needs" one. */
254 message_log_maybe_newline ()
256 if (message_log_need_newline
)
257 message_dolog ("", 0, 1);
261 /* Add a string to the message log, optionally terminated with a newline.
262 This function calls low-level routines in order to bypass text property
263 hooks, etc. which might not be safe to run. */
266 message_dolog (m
, len
, nlflag
)
270 if (!NILP (Vmessage_log_max
))
272 struct buffer
*oldbuf
;
273 int oldpoint
, oldbegv
, oldzv
;
274 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
276 oldbuf
= current_buffer
;
277 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
278 current_buffer
->undo_list
= Qt
;
285 oldpoint
+= len
+ nlflag
;
287 oldzv
+= len
+ nlflag
;
290 insert_1 (m
, len
, 1, 0);
293 int this_bol
, prev_bol
, dup
;
294 insert_1 ("\n", 1, 1, 0);
296 this_bol
= scan_buffer ('\n', Z
, 0, -2, 0, 0);
299 prev_bol
= scan_buffer ('\n', this_bol
, 0, -2, 0, 0);
300 dup
= message_log_check_duplicate (prev_bol
, this_bol
);
303 if (oldpoint
> prev_bol
)
304 oldpoint
-= min (this_bol
, oldpoint
) - prev_bol
;
305 if (oldbegv
> prev_bol
)
306 oldbegv
-= min (this_bol
, oldbegv
) - prev_bol
;
307 if (oldzv
> prev_bol
)
308 oldzv
-= min (this_bol
, oldzv
) - prev_bol
;
309 del_range_1 (prev_bol
, this_bol
, 0);
315 /* If you change this format, don't forget to also
316 change message_log_check_duplicate. */
317 sprintf (dupstr
, " [%d times]", dup
);
318 duplen
= strlen (dupstr
);
324 insert_1 (dupstr
, duplen
, 1, 0);
329 if (NATNUMP (Vmessage_log_max
))
331 int pos
= scan_buffer ('\n', Z
, 0,
332 -XFASTINT (Vmessage_log_max
) - 1, 0, 0);
333 oldpoint
-= min (pos
, oldpoint
) - BEG
;
334 oldbegv
-= min (pos
, oldbegv
) - BEG
;
335 oldzv
-= min (pos
, oldzv
) - BEG
;
336 del_range_1 (BEG
, pos
, 0);
341 TEMP_SET_PT (oldpoint
);
342 set_buffer_internal (oldbuf
);
343 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
344 message_log_need_newline
= !nlflag
;
348 /* We are at the end of the buffer after just having inserted a newline.
349 (Note: We depend on the fact we won't be crossing the gap.)
350 Check to see if the most recent message looks a lot like the previous one.
351 Return 0 if different, 1 if the new one should just replace it, or a
352 value N > 1 if we should also append " [N times]". */
355 message_log_check_duplicate (prev_bol
, this_bol
)
356 int prev_bol
, this_bol
;
359 int len
= Z
- 1 - this_bol
;
361 unsigned char *p1
= BUF_CHAR_ADDRESS (current_buffer
, prev_bol
);
362 unsigned char *p2
= BUF_CHAR_ADDRESS (current_buffer
, this_bol
);
364 for (i
= 0; i
< len
; i
++)
366 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
375 if (*p1
++ == ' ' && *p1
++ == '[')
378 while (*p1
>= '0' && *p1
<= '9')
379 n
= n
* 10 + *p1
++ - '0';
380 if (strncmp (p1
, " times]\n", 8) == 0)
386 /* Display an echo area message M with a specified length of LEN chars.
387 The string may include null characters. If M is 0, clear out any
388 existing message, and let the minibuffer text show through.
390 The buffer M must continue to exist until after the echo area
391 gets cleared or some other message gets displayed there.
393 Do not pass text that is stored in a Lisp string.
394 Do not pass text in a buffer that was alloca'd. */
401 /* First flush out any partial line written with print. */
402 message_log_maybe_newline ();
404 message_dolog (m
, len
, 1);
405 message2_nolog (m
, len
);
409 /* The non-logging counterpart of message2. */
412 message2_nolog (m
, len
)
418 if (noninteractive_need_newline
)
420 noninteractive_need_newline
= 0;
421 fwrite (m
, len
, 1, stderr
);
422 if (cursor_in_echo_area
== 0)
423 fprintf (stderr
, "\n");
426 /* A null message buffer means that the frame hasn't really been
427 initialized yet. Error messages get reported properly by
428 cmd_error, so this must be just an informative message; toss it. */
429 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
431 Lisp_Object mini_window
;
434 /* Get the frame containing the minibuffer
435 that the selected frame is using. */
436 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
437 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
439 FRAME_SAMPLE_VISIBILITY (f
);
440 if (FRAME_VISIBLE_P (selected_frame
)
441 && ! FRAME_VISIBLE_P (f
))
442 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
446 echo_area_glyphs
= m
;
447 echo_area_glyphs_length
= len
;
449 if (minibuffer_auto_raise
)
450 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
453 echo_area_glyphs
= previous_echo_glyphs
= 0;
455 do_pending_window_change ();
456 echo_area_display ();
457 update_frame (f
, 1, 1);
458 do_pending_window_change ();
459 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
460 (*frame_up_to_date_hook
) (f
);
464 /* Display a null-terminated echo area message M. If M is 0, clear out any
465 existing message, and let the minibuffer text show through.
467 The buffer M must continue to exist until after the echo area
468 gets cleared or some other message gets displayed there.
470 Do not pass text that is stored in a Lisp string.
471 Do not pass text in a buffer that was alloca'd. */
477 message2 (m
, (m
? strlen (m
) : 0));
484 message2_nolog (m
, (m
? strlen (m
) : 0));
487 /* Truncate what will be displayed in the echo area
488 the next time we display it--but don't redisplay it now. */
491 truncate_echo_area (len
)
494 /* A null message buffer means that the frame hasn't really been
495 initialized yet. Error messages get reported properly by
496 cmd_error, so this must be just an informative message; toss it. */
497 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
498 echo_area_glyphs_length
= len
;
501 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
502 zero if being used by message. */
503 int message_buf_print
;
505 /* Dump an informative message to the minibuf. If M is 0, clear out
506 any existing message, and let the minibuffer text show through. */
510 message (m
, a1
, a2
, a3
)
512 EMACS_INT a1
, a2
, a3
;
518 if (noninteractive_need_newline
)
520 noninteractive_need_newline
= 0;
521 fprintf (stderr
, m
, a1
, a2
, a3
);
522 if (cursor_in_echo_area
== 0)
523 fprintf (stderr
, "\n");
527 else if (INTERACTIVE
)
529 /* The frame whose minibuffer we're going to display the message on.
530 It may be larger than the selected frame, so we need
531 to use its buffer, not the selected frame's buffer. */
532 Lisp_Object mini_window
;
535 /* Get the frame containing the minibuffer
536 that the selected frame is using. */
537 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
538 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
540 /* A null message buffer means that the frame hasn't really been
541 initialized yet. Error messages get reported properly by
542 cmd_error, so this must be just an informative message; toss it. */
543 if (FRAME_MESSAGE_BUF (f
))
554 len
= doprnt (FRAME_MESSAGE_BUF (f
),
555 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
557 len
= doprnt (FRAME_MESSAGE_BUF (f
),
558 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, &a1
);
559 #endif /* NO_ARG_ARRAY */
561 message2 (FRAME_MESSAGE_BUF (f
), len
);
566 /* Print should start at the beginning of the message
568 message_buf_print
= 0;
573 /* The non-logging version of message. */
575 message_nolog (m
, a1
, a2
, a3
)
577 EMACS_INT a1
, a2
, a3
;
579 Lisp_Object old_log_max
;
580 old_log_max
= Vmessage_log_max
;
581 Vmessage_log_max
= Qnil
;
582 message (m
, a1
, a2
, a3
);
583 Vmessage_log_max
= old_log_max
;
589 message2 (echo_area_glyphs
, echo_area_glyphs_length
);
597 Lisp_Object mini_window
;
599 /* Choose the minibuffer window for this display.
600 It is the minibuffer window used by the selected frame. */
601 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
602 /* This is the frame that window is in. */
603 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
605 if (! FRAME_VISIBLE_P (f
))
610 redraw_garbaged_frames ();
614 if (echo_area_glyphs
|| minibuf_level
== 0)
618 echo_area_window
= mini_window
;
620 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
621 get_display_line (f
, vpos
, 0);
623 /* Make sure the columns that overlap a left-hand scroll bar
625 for (i
= 0; i
< FRAME_LEFT_SCROLL_BAR_WIDTH (f
); i
++)
626 f
->desired_glyphs
->glyphs
[vpos
][i
] = SPACEGLYPH
;
628 display_string (XWINDOW (mini_window
), vpos
,
629 echo_area_glyphs
? echo_area_glyphs
: "",
630 echo_area_glyphs
? echo_area_glyphs_length
: -1,
631 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
633 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
));
635 #if 0 /* This just gets in the way. update_frame does the job. */
636 /* If desired cursor location is on this line, put it at end of text */
637 if (cursor_in_echo_area
)
638 FRAME_CURSOR_Y (f
) = vpos
;
639 if (FRAME_CURSOR_Y (f
) == vpos
)
640 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
643 /* Fill the rest of the minibuffer window with blank lines. */
648 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
650 get_display_line (f
, i
, 0);
651 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
652 hpos, because it is good to clear whatever is behind the
653 scroll bar. This does not affect the scroll bar itself. */
654 display_string (XWINDOW (mini_window
), i
,
657 0, FRAME_WIDTH (f
) + FRAME_SCROLL_BAR_WIDTH (f
));
661 else if (!EQ (mini_window
, selected_window
))
662 windows_or_buffers_changed
++;
664 if (EQ (mini_window
, selected_window
))
665 this_line_bufpos
= 0;
667 previous_echo_glyphs
= echo_area_glyphs
;
670 /* Update frame titles. */
672 #ifdef HAVE_WINDOW_SYSTEM
673 static char frame_title_buf
[512];
674 static char *frame_title_ptr
;
677 store_frame_title (str
, mincol
, maxcol
)
682 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
683 maxcol
= sizeof (frame_title_buf
);
684 limit
= &frame_title_buf
[maxcol
];
685 while (*str
!= '\0' && frame_title_ptr
< limit
)
686 *frame_title_ptr
++ = *str
++;
687 while (frame_title_ptr
< &frame_title_buf
[mincol
])
688 *frame_title_ptr
++ = ' ';
689 return frame_title_ptr
- frame_title_buf
;
693 x_consider_frame_title (frame
)
699 FRAME_PTR f
= XFRAME (frame
);
701 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
704 /* Do we have more than one visible frame on this X display? */
708 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
710 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
712 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
713 && !FRAME_MINIBUF_ONLY_P (tf
)
714 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
718 multiple_frames
= CONSP (tail
);
721 obuf
= current_buffer
;
722 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
723 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
724 frame_title_ptr
= frame_title_buf
;
725 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
726 0, sizeof (frame_title_buf
), fmt
);
728 set_buffer_internal (obuf
);
729 /* Set the name only if it's changed. This avoids consing
730 in the common case where it hasn't. (If it turns out that we've
731 already wasted too much time by walking through the list with
732 display_mode_element, then we might need to optimize at a higher
734 if (! STRINGP (f
->name
) || XSTRING (f
->name
)->size
!= len
735 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
736 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
739 #define frame_title_ptr ((char *)0)
740 #define store_frame_title(str, mincol, maxcol) 0
743 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
744 This can call eval. */
749 register struct window
*w
= XWINDOW (selected_window
);
751 struct gcpro gcpro1
, gcpro2
;
753 all_windows
= (update_mode_lines
|| buffer_shared
> 1
754 || windows_or_buffers_changed
);
756 /* Update all frame titles based on their buffer names, etc.
757 We do this before the menu bars so that the buffer-menu
758 will show the up-to-date frame titles.
760 This used to be done after the menu bars, for a reason that
761 was stated as follows but which I do not understand:
762 "We do this after the menu bars so that the frame will first
763 create its menu bar using the name `emacs' if no other name
764 has yet been specified."
765 I think that is no longer a concern. */
766 #ifdef HAVE_WINDOW_SYSTEM
767 if (windows_or_buffers_changed
|| update_mode_lines
)
769 Lisp_Object tail
, frame
;
771 FOR_EACH_FRAME (tail
, frame
)
772 if (FRAME_VISIBLE_P (XFRAME (frame
))
773 || FRAME_ICONIFIED_P (XFRAME (frame
)))
774 x_consider_frame_title (frame
);
778 /* Update the menu bar item lists, if appropriate.
779 This has to be done before any actual redisplay
780 or generation of display lines. */
783 Lisp_Object tail
, frame
;
784 int count
= specpdl_ptr
- specpdl
;
786 record_unwind_protect (Fstore_match_data
, Fmatch_data (Qnil
, Qnil
));
788 FOR_EACH_FRAME (tail
, frame
)
790 /* If a window on this frame changed size,
791 report that to the user and clear the size-change flag. */
792 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
794 Lisp_Object functions
;
795 /* Clear flag first in case we get error below. */
796 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
797 functions
= Vwindow_size_change_functions
;
798 GCPRO2 (tail
, functions
);
799 while (CONSP (functions
))
801 call1 (XCONS (functions
)->car
, frame
);
802 functions
= XCONS (functions
)->cdr
;
807 update_menu_bar (XFRAME (frame
), 0);
811 unbind_to (count
, Qnil
);
814 update_menu_bar (selected_frame
, 1);
816 /* Motif needs this. See comment in xmenu.c.
817 Turn it off when pending_menu_activation is not defined. */
819 pending_menu_activation
= 0;
823 /* Do a frame update, taking possible shortcuts into account.
824 This is the main external entry point for redisplay.
826 If the last redisplay displayed an echo area message and that
827 message is no longer requested, we clear the echo area
828 or bring back the minibuffer if that is in use.
830 Do not call eval from within this function.
831 Calls to eval after the call to echo_area_display would confuse
832 the display_line mechanism and would cause a crash.
833 Calls to eval before that point will work most of the time,
834 but can still lose, because this function
835 can be called from signal handlers; with alarms set up;
836 or with synchronous processes running.
838 See Fcall_process; if you called it from here, it could be
839 entered recursively. */
841 static int do_verify_charstarts
;
843 /* Counter is used to clear the face cache
844 no more than once ever 1000 redisplays. */
845 static int clear_face_cache_count
;
847 /* Record the previous terminal frame we displayed. */
848 static FRAME_PTR previous_terminal_frame
;
853 redisplay_internal (0);
856 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
857 is not in response to any user action; therefore, we should
858 preserve the echo area. (Actually, our caller does that job.)
859 Perhaps in the future avoid recentering windows
860 if it is not necessary; currently that causes some problems. */
863 redisplay_internal (preserve_echo_area
)
864 int preserve_echo_area
;
866 register struct window
*w
= XWINDOW (selected_window
);
870 register int tlbufpos
, tlendpos
;
872 int number_of_frames_redisplayed
;
878 if (popup_activated ())
884 if (! FRAME_WINDOW_P (selected_frame
)
885 && previous_terminal_frame
!= selected_frame
)
887 /* Since frames on an ASCII terminal share the same display area,
888 displaying a different frame means redisplay the whole thing. */
889 windows_or_buffers_changed
++;
890 SET_FRAME_GARBAGED (selected_frame
);
891 XSETFRAME (Vterminal_frame
, selected_frame
);
893 previous_terminal_frame
= selected_frame
;
895 /* Set the visible flags for all frames.
896 Do this before checking for resized or garbaged frames; they want
897 to know if their frames are visible.
898 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
900 Lisp_Object tail
, frame
;
902 FOR_EACH_FRAME (tail
, frame
)
904 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
906 /* Clear out all the display lines in which we will generate the
907 glyphs to display. */
908 init_desired_glyphs (XFRAME (frame
));
912 /* Notice any pending interrupt request to change frame size. */
913 do_pending_window_change ();
917 redraw_garbaged_frames ();
921 prepare_menu_bars ();
923 if (windows_or_buffers_changed
)
926 /* Detect case that we need to write or remove a star in the mode line. */
927 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
929 w
->update_mode_line
= Qt
;
930 if (buffer_shared
> 1)
934 /* If %c is in use, update it if needed. */
935 if (!NILP (w
->column_number_displayed
)
936 /* This alternative quickly identifies a common case
937 where no change is needed. */
938 && !(PT
== XFASTINT (w
->last_point
)
939 && XFASTINT (w
->last_modified
) >= MODIFF
940 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
941 && XFASTINT (w
->column_number_displayed
) != current_column ())
942 w
->update_mode_line
= Qt
;
944 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
946 all_windows
= update_mode_lines
|| buffer_shared
> 1;
948 /* If specs for an arrow have changed, do thorough redisplay
949 to ensure we remove any arrow that should no longer exist. */
950 if (! EQ (Voverlay_arrow_position
, last_arrow_position
)
951 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
954 /* Normally the message* functions will have already displayed and
955 updated the echo area, but the frame may have been trashed, or
956 the update may have been preempted, so display the echo area
958 if (echo_area_glyphs
|| previous_echo_glyphs
)
960 echo_area_display ();
964 /* If showing region, and mark has changed, must redisplay whole window. */
965 if (((!NILP (Vtransient_mark_mode
)
966 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
967 != !NILP (w
->region_showing
))
968 || (!NILP (w
->region_showing
)
969 && !EQ (w
->region_showing
,
970 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
971 this_line_bufpos
= -1;
973 /* This is in case we goto update, below. */
974 number_of_frames_redisplayed
= 1;
976 tlbufpos
= this_line_bufpos
;
977 tlendpos
= this_line_endpos
;
978 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
979 && !current_buffer
->clip_changed
980 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
981 /* Make sure recorded data applies to current buffer, etc */
982 && this_line_buffer
== current_buffer
983 && current_buffer
== XBUFFER (w
->buffer
)
984 && NILP (w
->force_start
)
985 /* Point must be on the line that we have info recorded about */
987 && PT
<= Z
- tlendpos
988 /* All text outside that line, including its final newline,
990 && ((XFASTINT (w
->last_modified
) >= MODIFF
991 && (XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
))
992 || (beg_unchanged
>= tlbufpos
- 1
994 /* If selective display, can't optimize
995 if the changes start at the beginning of the line. */
996 && ((INTEGERP (current_buffer
->selective_display
)
997 && XINT (current_buffer
->selective_display
) > 0
998 ? (beg_unchanged
>= tlbufpos
1001 && end_unchanged
>= tlendpos
1002 && Z
- GPT
>= tlendpos
)))
1004 if (tlbufpos
> BEGV
&& FETCH_BYTE (tlbufpos
- 1) != '\n'
1006 || FETCH_BYTE (tlbufpos
) == '\n'))
1007 /* Former continuation line has disappeared by becoming empty */
1009 else if (XFASTINT (w
->last_modified
) < MODIFF
1010 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
1011 || MINI_WINDOW_P (w
))
1013 /* We have to handle the case of continuation around a
1014 wide-column character (See the comment in indent.c around
1017 For instance, in the following case:
1019 -------- Insert --------
1020 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1021 J_I_ ==> J_I_ `^^' are cursors.
1025 As we have to redraw the line above, we should goto cancel. */
1027 struct position val
;
1030 prevline
= find_next_newline (tlbufpos
, -1);
1031 val
= *compute_motion (prevline
, 0,
1032 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1035 1 << (BITS_PER_SHORT
- 1),
1036 1 << (BITS_PER_SHORT
- 1),
1037 window_internal_width (w
) - 1,
1038 XINT (w
->hscroll
), 0, w
);
1039 if (val
.hpos
!= this_line_start_hpos
)
1043 overlay_arrow_seen
= 0;
1044 zv_strings_seen
= 0;
1045 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
1046 pos_tab_offset (w
, tlbufpos
), 0);
1047 /* If line contains point, is not continued,
1048 and ends at same distance from eob as before, we win */
1049 if (cursor_vpos
>= 0 && this_line_bufpos
1050 && this_line_endpos
== tlendpos
)
1052 /* If this is not the window's last line,
1053 we must adjust the charstarts of the lines below. */
1054 if (this_line_vpos
+ 1
1055 < XFASTINT (w
->top
) + window_internal_height (w
))
1057 int left
= WINDOW_LEFT_MARGIN (w
);
1058 int *charstart_next_line
1059 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
1062 if (Z
- tlendpos
== ZV
)
1063 /* This line ends at end of (accessible part of) buffer.
1064 There is no newline to count. */
1065 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
1067 /* This line ends in a newline.
1068 Must take account of the newline and the rest of the
1069 text that follows. */
1070 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
1072 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
1075 if (!WINDOW_FULL_WIDTH_P (w
))
1076 preserve_other_columns (w
);
1082 else if (PT
== XFASTINT (w
->last_point
)
1083 /* Make sure the cursor was last displayed
1084 in this window. Otherwise we have to reposition it. */
1085 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
1086 && (XINT (w
->top
) + XINT (w
->height
)
1087 > FRAME_CURSOR_Y (selected_frame
)))
1091 do_pending_window_change ();
1096 /* If highlighting the region, or if the cursor is in the echo area,
1097 then we can't just move the cursor. */
1098 else if (! (!NILP (Vtransient_mark_mode
)
1099 && !NILP (current_buffer
->mark_active
))
1100 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1101 || highlight_nonselected_windows
)
1102 && NILP (w
->region_showing
)
1103 && !cursor_in_echo_area
)
1105 pos
= *compute_motion (tlbufpos
, 0,
1106 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1108 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
1109 window_internal_width (w
) - 1,
1111 pos_tab_offset (w
, tlbufpos
), w
);
1114 int width
= window_internal_width (w
) - 1;
1115 FRAME_CURSOR_X (selected_frame
)
1116 = WINDOW_LEFT_MARGIN (w
) + minmax (0, pos
.hpos
, width
);
1117 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1124 /* Text changed drastically or point moved off of line */
1125 cancel_line (this_line_vpos
, selected_frame
);
1128 this_line_bufpos
= 0;
1129 all_windows
|= buffer_shared
> 1;
1131 clear_face_cache_count
++;
1135 Lisp_Object tail
, frame
;
1138 /* Clear the face cache, only when we do a full redisplay
1139 and not too often either. */
1140 if (clear_face_cache_count
> 1000)
1142 clear_face_cache ();
1143 clear_face_cache_count
= 0;
1147 /* Recompute # windows showing selected buffer.
1148 This will be incremented each time such a window is displayed. */
1150 number_of_frames_redisplayed
= 0;
1152 FOR_EACH_FRAME (tail
, frame
)
1154 FRAME_PTR f
= XFRAME (frame
);
1155 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
1158 /* Mark all the scroll bars to be removed; we'll redeem the ones
1159 we want when we redisplay their windows. */
1160 if (condemn_scroll_bars_hook
)
1161 (*condemn_scroll_bars_hook
) (f
);
1163 if (FRAME_VISIBLE_P (f
))
1165 redisplay_windows (FRAME_ROOT_WINDOW (f
), preserve_echo_area
);
1166 number_of_frames_redisplayed
++;
1169 /* Any scroll bars which redisplay_windows should have nuked
1170 should now go away. */
1171 if (judge_scroll_bars_hook
)
1172 (*judge_scroll_bars_hook
) (f
);
1176 else if (FRAME_VISIBLE_P (selected_frame
))
1178 redisplay_window (selected_window
, 1, preserve_echo_area
);
1179 if (!WINDOW_FULL_WIDTH_P (w
))
1180 preserve_other_columns (w
);
1181 number_of_frames_redisplayed
= 1;
1185 /* Prevent various kinds of signals during display update.
1186 stdio is not robust about handling signals,
1187 which can cause an apparent I/O error. */
1188 if (interrupt_input
)
1198 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1202 if (!FRAMEP (XCONS (tail
)->car
))
1205 f
= XFRAME (XCONS (tail
)->car
);
1207 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
1208 && FRAME_VISIBLE_P (f
))
1210 pause
|= update_frame (f
, 0, 0);
1213 mark_window_display_accurate (f
->root_window
, 1);
1214 if (frame_up_to_date_hook
!= 0)
1215 (*frame_up_to_date_hook
) (f
);
1222 if (FRAME_VISIBLE_P (selected_frame
))
1223 pause
= update_frame (selected_frame
, 0, 0);
1227 /* We may have called echo_area_display at the top of this
1228 function. If the echo area is on another frame, that may
1229 have put text on a frame other than the selected one, so the
1230 above call to update_frame would not have caught it. Catch
1233 Lisp_Object mini_window
;
1234 FRAME_PTR mini_frame
;
1236 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1237 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1239 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
1240 pause
|= update_frame (mini_frame
, 0, 0);
1244 /* If frame does not match, prevent doing single-line-update next time.
1245 Also, don't forget to check every line to update the arrow. */
1248 this_line_bufpos
= 0;
1249 if (!NILP (last_arrow_position
))
1251 last_arrow_position
= Qt
;
1252 last_arrow_string
= Qt
;
1254 /* If we pause after scrolling, some lines in current_frame
1255 may be null, so preserve_other_columns won't be able to
1256 preserve all the vertical-bar separators. So, avoid using it
1258 if (!WINDOW_FULL_WIDTH_P (w
))
1259 update_mode_lines
= 1;
1262 /* Now text on frame agrees with windows, so
1263 put info into the windows for partial redisplay to follow */
1267 register struct buffer
*b
= XBUFFER (w
->buffer
);
1269 blank_end_of_window
= 0;
1270 unchanged_modified
= BUF_MODIFF (b
);
1271 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
1272 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1273 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1275 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1276 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1277 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1280 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1283 b
->clip_changed
= 0;
1284 w
->update_mode_line
= Qnil
;
1285 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1286 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
1288 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1291 /* Record if we are showing a region, so can make sure to
1292 update it fully at next redisplay. */
1293 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1294 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1295 || highlight_nonselected_windows
)
1296 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1297 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1300 w
->window_end_valid
= w
->buffer
;
1301 last_arrow_position
= Voverlay_arrow_position
;
1302 last_arrow_string
= Voverlay_arrow_string
;
1303 if (do_verify_charstarts
)
1304 verify_charstarts (w
);
1305 if (frame_up_to_date_hook
!= 0)
1306 (*frame_up_to_date_hook
) (selected_frame
);
1308 update_mode_lines
= 0;
1309 windows_or_buffers_changed
= 0;
1312 /* Start SIGIO interrupts coming again.
1313 Having them off during the code above
1314 makes it less likely one will discard output,
1315 but not impossible, since there might be stuff
1316 in the system buffer here.
1317 But it is much hairier to try to do anything about that. */
1319 if (interrupt_input
)
1323 /* If something has become visible now which was not before,
1324 redisplay again, so that we get them. */
1327 Lisp_Object tail
, frame
;
1330 FOR_EACH_FRAME (tail
, frame
)
1332 int this_is_visible
= 0;
1333 if (XFRAME (frame
)->visible
)
1334 this_is_visible
= 1;
1335 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1336 if (XFRAME (frame
)->visible
)
1337 this_is_visible
= 1;
1339 if (this_is_visible
)
1343 if (new_count
!= number_of_frames_redisplayed
)
1344 windows_or_buffers_changed
++;
1347 /* Change frame size now if a change is pending. */
1348 do_pending_window_change ();
1350 /* If we just did a pending size change, or have additional
1351 visible frames, redisplay again. */
1352 if (windows_or_buffers_changed
&& !pause
)
1356 /* Redisplay, but leave alone any recent echo area message
1357 unless another message has been requested in its place.
1359 This is useful in situations where you need to redisplay but no
1360 user action has occurred, making it inappropriate for the message
1361 area to be cleared. See tracking_off and
1362 wait_reading_process_input for examples of these situations. */
1364 redisplay_preserve_echo_area ()
1366 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1368 echo_area_glyphs
= previous_echo_glyphs
;
1369 redisplay_internal (1);
1370 echo_area_glyphs
= 0;
1373 redisplay_internal (1);
1377 mark_window_display_accurate (window
, flag
)
1381 register struct window
*w
;
1383 for (;!NILP (window
); window
= w
->next
)
1385 if (!WINDOWP (window
)) abort ();
1386 w
= XWINDOW (window
);
1388 if (!NILP (w
->buffer
))
1390 XSETFASTINT (w
->last_modified
,
1391 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1392 XSETFASTINT (w
->last_overlay_modified
,
1393 !flag
? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)));
1395 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1398 /* Record if we are showing a region, so can make sure to
1399 update it fully at next redisplay. */
1400 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1401 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1402 || highlight_nonselected_windows
)
1403 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1404 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1408 w
->window_end_valid
= w
->buffer
;
1409 w
->update_mode_line
= Qnil
;
1410 if (!NILP (w
->buffer
) && flag
)
1411 XBUFFER (w
->buffer
)->clip_changed
= 0;
1413 if (!NILP (w
->vchild
))
1414 mark_window_display_accurate (w
->vchild
, flag
);
1415 if (!NILP (w
->hchild
))
1416 mark_window_display_accurate (w
->hchild
, flag
);
1421 last_arrow_position
= Voverlay_arrow_position
;
1422 last_arrow_string
= Voverlay_arrow_string
;
1426 /* t is unequal to any useful value of Voverlay_arrow_... */
1427 last_arrow_position
= Qt
;
1428 last_arrow_string
= Qt
;
1432 /* Update the menu bar item list for frame F.
1433 This has to be done before we start to fill in any display lines,
1434 because it can call eval.
1436 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1439 update_menu_bar (f
, save_match_data
)
1441 int save_match_data
;
1443 struct buffer
*old
= current_buffer
;
1445 register struct window
*w
;
1447 window
= FRAME_SELECTED_WINDOW (f
);
1448 w
= XWINDOW (window
);
1450 if (update_mode_lines
)
1451 w
->update_mode_line
= Qt
;
1453 if (FRAME_WINDOW_P (f
)
1455 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1456 FRAME_EXTERNAL_MENU_BAR (f
)
1458 FRAME_MENU_BAR_LINES (f
) > 0
1460 : FRAME_MENU_BAR_LINES (f
) > 0)
1462 /* If the user has switched buffers or windows, we need to
1463 recompute to reflect the new bindings. But we'll
1464 recompute when update_mode_lines is set too; that means
1465 that people can use force-mode-line-update to request
1466 that the menu bar be recomputed. The adverse effect on
1467 the rest of the redisplay algorithm is about the same as
1468 windows_or_buffers_changed anyway. */
1469 if (windows_or_buffers_changed
1470 || !NILP (w
->update_mode_line
)
1471 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1472 < BUF_MODIFF (XBUFFER (w
->buffer
)))
1473 != !NILP (w
->last_had_star
))
1474 || ((!NILP (Vtransient_mark_mode
)
1475 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1476 != !NILP (w
->region_showing
)))
1478 struct buffer
*prev
= current_buffer
;
1479 int count
= specpdl_ptr
- specpdl
;
1481 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1482 if (save_match_data
)
1483 record_unwind_protect (Fstore_match_data
, Fmatch_data (Qnil
, Qnil
));
1484 if (NILP (Voverriding_local_map_menu_flag
))
1486 specbind (Qoverriding_terminal_local_map
, Qnil
);
1487 specbind (Qoverriding_local_map
, Qnil
);
1490 /* Run the Lucid hook. */
1491 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1492 /* If it has changed current-menubar from previous value,
1493 really recompute the menubar from the value. */
1494 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1495 call0 (Qrecompute_lucid_menubar
);
1496 safe_run_hooks (Qmenu_bar_update_hook
);
1497 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1498 /* Redisplay the menu bar in case we changed it. */
1499 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1500 if (FRAME_WINDOW_P (f
))
1501 set_frame_menubar (f
, 0, 0);
1503 /* On a terminal screen, the menu bar is an ordinary screen
1504 line, and this makes it get updated. */
1505 w
->update_mode_line
= Qt
;
1506 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1507 /* In the non-toolkit version, the menu bar is an ordinary screen
1508 line, and this makes it get updated. */
1509 w
->update_mode_line
= Qt
;
1510 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1512 unbind_to (count
, Qnil
);
1513 set_buffer_internal_1 (prev
);
1520 /* Redisplay WINDOW and its subwindows and siblings. */
1523 redisplay_windows (window
, preserve_echo_area
)
1525 int preserve_echo_area
;
1527 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1528 redisplay_window (window
, 0, preserve_echo_area
);
1531 /* Return value in display table DP (Lisp_Char_Table *) for character
1532 C. Since a display table doesn't have any parent, we don't have to
1533 follow parent. Do not call this function directly but use the
1534 macro DISP_CHAR_VECTOR. */
1536 disp_char_vector (dp
, c
)
1537 struct Lisp_Char_Table
*dp
;
1543 if (SINGLE_BYTE_CHAR_P (c
)) return (dp
->contents
[c
]);
1545 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
1546 if (code
[0] != CHARSET_COMPOSITION
)
1548 if (code
[1] < 32) code
[1] = -1;
1549 else if (code
[2] < 32) code
[2] = -1;
1551 /* Here, the possible range of CODE[0] (== charset ID) is
1552 128..MAX_CHARSET. Since the top level char table contains data
1553 for multibyte characters after 256th element, we must increment
1554 CODE[0] by 128 to get a correct index. */
1556 code
[3] = -1; /* anchor */
1558 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
1560 val
= dp
->contents
[code
[i
]];
1561 if (!SUB_CHAR_TABLE_P (val
))
1562 return (NILP (val
) ? dp
->defalt
: val
);
1564 /* Here, VAL is a sub char table. We return the default value of it. */
1565 return (dp
->defalt
);
1568 /* Redisplay window WINDOW and its subwindows. */
1571 redisplay_window (window
, just_this_one
, preserve_echo_area
)
1573 int just_this_one
, preserve_echo_area
;
1575 register struct window
*w
= XWINDOW (window
);
1576 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1578 register int lpoint
= PT
;
1579 struct buffer
*old
= current_buffer
;
1580 register int width
= window_internal_width (w
) - 1;
1581 register int startp
;
1582 register int hscroll
= XINT (w
->hscroll
);
1583 struct position pos
;
1586 int update_mode_line
;
1587 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1589 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1591 /* If this is a combination window, do its children; that's all. */
1593 if (!NILP (w
->vchild
))
1595 redisplay_windows (w
->vchild
, preserve_echo_area
);
1598 if (!NILP (w
->hchild
))
1600 redisplay_windows (w
->hchild
, preserve_echo_area
);
1603 if (NILP (w
->buffer
))
1606 height
= window_internal_height (w
);
1607 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1608 if (XBUFFER (w
->buffer
)->clip_changed
)
1609 update_mode_line
= 1;
1611 if (MINI_WINDOW_P (w
))
1613 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1614 /* We've already displayed the echo area glyphs in this window. */
1615 goto finish_scroll_bars
;
1616 else if (w
!= XWINDOW (minibuf_window
))
1618 /* This is a minibuffer, but it's not the currently active one,
1620 int vpos
= XFASTINT (w
->top
);
1623 for (i
= 0; i
< height
; i
++)
1625 get_display_line (f
, vpos
+ i
, 0);
1626 display_string (w
, vpos
+ i
, "", 0,
1627 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
1631 goto finish_scroll_bars
;
1635 /* Otherwise set up data on this window; select its buffer and point value */
1637 if (update_mode_line
)
1638 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1640 set_buffer_temp (XBUFFER (w
->buffer
));
1644 /* If %c is in mode line, update it if needed. */
1645 if (!NILP (w
->column_number_displayed
)
1646 /* This alternative quickly identifies a common case
1647 where no change is needed. */
1648 && !(PT
== XFASTINT (w
->last_point
)
1649 && XFASTINT (w
->last_modified
) >= MODIFF
1650 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1651 && XFASTINT (w
->column_number_displayed
) != current_column ())
1652 update_mode_line
= 1;
1654 /* Count number of windows showing the selected buffer.
1655 An indirect buffer counts as its base buffer. */
1659 struct buffer
*current_base
, *window_base
;
1660 current_base
= current_buffer
;
1661 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1662 if (current_base
->base_buffer
)
1663 current_base
= current_base
->base_buffer
;
1664 if (window_base
->base_buffer
)
1665 window_base
= window_base
->base_buffer
;
1666 if (current_base
== window_base
)
1670 /* POINT refers normally to the selected window.
1671 For any other window, set up appropriate value. */
1673 if (!EQ (window
, selected_window
))
1675 int new_pt
= marker_position (w
->pointm
);
1679 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1681 else if (new_pt
> (ZV
- 1))
1684 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1686 /* We don't use SET_PT so that the point-motion hooks don't run. */
1687 BUF_PT (current_buffer
) = new_pt
;
1690 /* If any of the character widths specified in the display table
1691 have changed, invalidate the width run cache. It's true that this
1692 may be a bit late to catch such changes, but the rest of
1693 redisplay goes (non-fatally) haywire when the display table is
1694 changed, so why should we worry about doing any better? */
1695 if (current_buffer
->width_run_cache
)
1697 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1699 if (! disptab_matches_widthtab (disptab
,
1700 XVECTOR (current_buffer
->width_table
)))
1702 invalidate_region_cache (current_buffer
,
1703 current_buffer
->width_run_cache
,
1705 recompute_width_table (current_buffer
, disptab
);
1709 /* If window-start is screwed up, choose a new one. */
1710 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1713 startp
= marker_position (w
->start
);
1715 /* If someone specified a new starting point but did not insist,
1716 check whether it can be used. */
1717 if (!NILP (w
->optional_new_start
))
1719 w
->optional_new_start
= Qnil
;
1720 /* Check whether this start pos is usable given where point is. */
1722 pos
= *compute_motion (startp
, 0,
1723 (((EQ (window
, minibuf_window
)
1725 ? minibuf_prompt_width
: 0)
1726 + (hscroll
? 1 - hscroll
: 0)),
1729 /* BUG FIX: See the comment of
1730 Fpos_visible_in_window_p (window.c). */
1731 - (1 << (BITS_PER_SHORT
- 1)),
1732 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1733 /* If PT does fit on the screen, we will use this start pos,
1734 so do so by setting force_start. */
1735 if (pos
.bufpos
== PT
)
1736 w
->force_start
= Qt
;
1739 /* Handle case where place to start displaying has been specified,
1740 unless the specified location is outside the accessible range. */
1741 if (!NILP (w
->force_start
))
1743 w
->force_start
= Qnil
;
1744 /* Forget any recorded base line for line number display. */
1745 w
->base_line_number
= Qnil
;
1746 /* Redisplay the mode line. Select the buffer properly for that.
1747 Also, run the hook window-scroll-functions
1748 because we have scrolled. */
1749 /* Note, we do this after clearing force_start because
1750 if there's an error, it is better to forget about force_start
1751 than to get into an infinite loop calling the hook functions
1752 and having them get more errors. */
1753 if (!update_mode_line
1754 || ! NILP (Vwindow_scroll_functions
))
1756 Lisp_Object temp
[3];
1758 set_buffer_temp (old
);
1759 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1760 update_mode_line
= 1;
1761 w
->update_mode_line
= Qt
;
1762 if (! NILP (Vwindow_scroll_functions
))
1764 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1765 make_number (startp
));
1766 startp
= marker_position (w
->start
);
1769 XSETFASTINT (w
->last_modified
, 0);
1770 XSETFASTINT (w
->last_overlay_modified
, 0);
1771 if (startp
< BEGV
) startp
= BEGV
;
1772 if (startp
> ZV
) startp
= ZV
;
1773 try_window (window
, startp
);
1774 if (cursor_vpos
< 0)
1776 /* If point does not appear, move point so it does appear */
1777 pos
= *compute_motion (startp
, 0,
1778 (((EQ (window
, minibuf_window
)
1780 ? minibuf_prompt_width
: 0)
1781 + (hscroll
? 1 - hscroll
: 0)),
1784 - (1 << (BITS_PER_SHORT
- 1)),
1785 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1786 BUF_PT (current_buffer
) = pos
.bufpos
;
1787 if (w
!= XWINDOW (selected_window
))
1788 Fset_marker (w
->pointm
, make_number (PT
), Qnil
);
1791 if (current_buffer
== old
)
1793 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
1794 + minmax (0, pos
.hpos
, width
));
1795 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1797 /* If we are highlighting the region,
1798 then we just changed the region, so redisplay to show it. */
1799 if (!NILP (Vtransient_mark_mode
)
1800 && !NILP (current_buffer
->mark_active
))
1802 cancel_my_columns (XWINDOW (window
));
1803 try_window (window
, startp
);
1809 /* Handle case where text has not changed, only point,
1810 and it has not moved off the frame. */
1812 /* This code is not used for minibuffer for the sake of
1813 the case of redisplaying to replace an echo area message;
1814 since in that case the minibuffer contents per se are usually unchanged.
1815 This code is of no real use in the minibuffer since
1816 the handling of this_line_bufpos, etc.,
1817 in redisplay handles the same cases. */
1819 if (XFASTINT (w
->last_modified
) >= MODIFF
1820 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
1821 && PT
>= startp
&& !current_buffer
->clip_changed
1822 && (just_this_one
|| WINDOW_FULL_WIDTH_P (w
))
1823 /* If force-mode-line-update was called, really redisplay;
1824 that's how redisplay is forced after e.g. changing
1825 buffer-invisibility-spec. */
1826 && NILP (w
->update_mode_line
)
1827 /* Can't use this case if highlighting a region. */
1828 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
1829 && NILP (w
->region_showing
)
1830 /* If end pos is out of date, scroll bar and percentage will be wrong */
1831 && INTEGERP (w
->window_end_vpos
)
1832 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
1833 && !EQ (window
, minibuf_window
))
1835 int this_scroll_margin
= scroll_margin
;
1837 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
1839 /* BUG FIX: See the comment of
1840 Fpos_visible_in_window_p (window.c). */
1841 - (1 << (BITS_PER_SHORT
- 1)),
1843 pos_tab_offset (w
, startp
), w
);
1845 /* Don't use a scroll margin that is negative or too large. */
1846 if (this_scroll_margin
< 0)
1847 this_scroll_margin
= 0;
1849 if (XINT (w
->height
) < 4 * scroll_margin
)
1850 this_scroll_margin
= XINT (w
->height
) / 4;
1852 /* If point fits on the screen, and not within the scroll margin,
1854 if (pos
.vpos
< height
- this_scroll_margin
1855 && (pos
.vpos
>= this_scroll_margin
|| startp
== BEGV
))
1857 /* Ok, point is still on frame */
1858 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
1860 /* These variables are supposed to be origin 1 */
1861 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
1862 + minmax (0, pos
.hpos
, width
));
1863 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1865 /* This doesn't do the trick, because if a window to the right of
1866 this one must be redisplayed, this does nothing because there
1867 is nothing in DesiredFrame yet, and then the other window is
1868 redisplayed, making likes that are empty in this window's columns.
1869 if (WINDOW_FULL_WIDTH_P (w))
1870 preserve_my_columns (w);
1874 /* Don't bother trying redisplay with same start;
1875 we already know it will lose */
1877 /* If current starting point was originally the beginning of a line
1878 but no longer is, find a new starting point. */
1879 else if (!NILP (w
->start_at_line_beg
)
1881 || FETCH_BYTE (startp
- 1) == '\n'))
1885 else if (just_this_one
&& !MINI_WINDOW_P (w
)
1887 && XFASTINT (w
->last_modified
)
1888 /* or else vmotion on first line won't work. */
1889 && ! NILP (w
->start_at_line_beg
)
1890 && ! EQ (w
->window_end_valid
, Qnil
)
1891 && do_id
&& !current_buffer
->clip_changed
1892 && !blank_end_of_window
1893 && WINDOW_FULL_WIDTH_P (w
)
1894 /* Can't use this case if highlighting a region. */
1895 && !(!NILP (Vtransient_mark_mode
)
1896 && !NILP (current_buffer
->mark_active
))
1897 /* Don't use try_window_id if newline
1898 doesn't display as the end of a line. */
1899 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
1900 && NILP (w
->region_showing
)
1901 && EQ (last_arrow_position
, Voverlay_arrow_position
)
1902 && EQ (last_arrow_string
, Voverlay_arrow_string
)
1903 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
1906 /* tem > 0 means success. tem == -1 means choose new start.
1907 tem == -2 means try again with same start,
1908 and nothing but whitespace follows the changed stuff.
1909 tem == 0 means try again with same start. */
1913 else if (startp
>= BEGV
&& startp
<= ZV
1915 /* Avoid starting at end of buffer. */
1916 #if 0 /* This change causes trouble for M-! finger & RET.
1917 It will have to be considered later. */
1918 || ! EQ (window
, selected_window
)
1919 /* Don't do the recentering if redisplay
1920 is not for no user action. */
1921 || preserve_echo_area
1924 || (XFASTINT (w
->last_modified
) >= MODIFF
1925 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
1927 /* Try to redisplay starting at same place as before */
1928 /* If point has not moved off frame, accept the results */
1929 try_window (window
, startp
);
1930 if (cursor_vpos
>= 0)
1932 if (!just_this_one
|| current_buffer
->clip_changed
1933 || beg_unchanged
< startp
)
1934 /* Forget any recorded base line for line number display. */
1935 w
->base_line_number
= Qnil
;
1939 cancel_my_columns (w
);
1942 XSETFASTINT (w
->last_modified
, 0);
1943 XSETFASTINT (w
->last_overlay_modified
, 0);
1944 /* Redisplay the mode line. Select the buffer properly for that. */
1945 if (!update_mode_line
)
1947 set_buffer_temp (old
);
1948 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1949 update_mode_line
= 1;
1950 w
->update_mode_line
= Qt
;
1953 /* Try to scroll by specified few lines */
1955 if (scroll_conservatively
&& !current_buffer
->clip_changed
1956 && startp
>= BEGV
&& startp
<= ZV
)
1958 int this_scroll_margin
= scroll_margin
;
1960 /* Don't use a scroll margin that is negative or too large. */
1961 if (this_scroll_margin
< 0)
1962 this_scroll_margin
= 0;
1964 if (XINT (w
->height
) < 4 * scroll_margin
)
1965 this_scroll_margin
= XINT (w
->height
) / 4;
1967 if (PT
>= Z
- XFASTINT (w
->window_end_pos
))
1969 struct position pos
;
1970 pos
= *compute_motion (Z
- XFASTINT (w
->window_end_pos
), 0, 0, 0,
1971 PT
, XFASTINT (w
->height
), 0,
1972 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
1973 pos_tab_offset (w
, startp
), w
);
1974 if (pos
.vpos
> scroll_conservatively
)
1977 pos
= *vmotion (startp
, pos
.vpos
+ 1 + this_scroll_margin
, w
);
1979 if (! NILP (Vwindow_scroll_functions
))
1981 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
1982 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1983 make_number (pos
.bufpos
));
1984 pos
.bufpos
= marker_position (w
->start
);
1986 try_window (window
, pos
.bufpos
);
1987 if (cursor_vpos
>= 0)
1989 if (!just_this_one
|| current_buffer
->clip_changed
1990 || beg_unchanged
< startp
)
1991 /* Forget any recorded base line for line number display. */
1992 w
->base_line_number
= Qnil
;
1996 cancel_my_columns (w
);
2000 struct position pos
;
2001 pos
= *compute_motion (PT
, 0, 0, 0,
2002 startp
, XFASTINT (w
->height
), 0,
2003 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2004 pos_tab_offset (w
, startp
), w
);
2005 if (pos
.vpos
>= scroll_conservatively
)
2008 pos
= *vmotion (startp
, - pos
.vpos
- this_scroll_margin
, w
);
2010 if (! NILP (Vwindow_scroll_functions
))
2012 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2013 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2014 make_number (pos
.bufpos
));
2015 pos
.bufpos
= marker_position (w
->start
);
2017 try_window (window
, pos
.bufpos
);
2018 if (cursor_vpos
>= 0)
2020 if (!just_this_one
|| current_buffer
->clip_changed
2021 || beg_unchanged
< startp
)
2022 /* Forget any recorded base line for line number display. */
2023 w
->base_line_number
= Qnil
;
2027 cancel_my_columns (w
);
2032 if (scroll_step
&& !current_buffer
->clip_changed
2033 && startp
>= BEGV
&& startp
<= ZV
)
2037 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
2038 if (pos
.vpos
>= height
)
2042 pos
= *vmotion (startp
, (PT
< startp
? - scroll_step
: scroll_step
), w
);
2044 if (PT
>= pos
.bufpos
)
2046 if (! NILP (Vwindow_scroll_functions
))
2048 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2049 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2050 make_number (pos
.bufpos
));
2051 pos
.bufpos
= marker_position (w
->start
);
2053 try_window (window
, pos
.bufpos
);
2054 if (cursor_vpos
>= 0)
2056 if (!just_this_one
|| current_buffer
->clip_changed
2057 || beg_unchanged
< startp
)
2058 /* Forget any recorded base line for line number display. */
2059 w
->base_line_number
= Qnil
;
2063 cancel_my_columns (w
);
2068 /* Finally, just choose place to start which centers point */
2071 /* Forget any previously recorded base line for line number display. */
2072 w
->base_line_number
= Qnil
;
2074 pos
= *vmotion (PT
, - (height
/ 2), w
);
2075 /* Set startp here explicitly in case that helps avoid an infinite loop
2076 in case the window-scroll-functions functions get errors. */
2077 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2078 if (! NILP (Vwindow_scroll_functions
))
2080 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2081 make_number (pos
.bufpos
));
2082 pos
.bufpos
= marker_position (w
->start
);
2084 try_window (window
, pos
.bufpos
);
2086 startp
= marker_position (w
->start
);
2087 w
->start_at_line_beg
2088 = (startp
== BEGV
|| FETCH_BYTE (startp
- 1) == '\n') ? Qt
: Qnil
;
2091 if ((update_mode_line
2092 /* If window not full width, must redo its mode line
2093 if the window to its side is being redone */
2094 || (!just_this_one
&& !WINDOW_FULL_WIDTH_P (w
))
2095 || INTEGERP (w
->base_line_pos
)
2096 || (!NILP (w
->column_number_displayed
)
2097 && XFASTINT (w
->column_number_displayed
) != current_column ()))
2098 && height
!= XFASTINT (w
->height
))
2099 display_mode_line (w
);
2100 if (! line_number_displayed
2101 && ! BUFFERP (w
->base_line_pos
))
2103 w
->base_line_pos
= Qnil
;
2104 w
->base_line_number
= Qnil
;
2107 /* When we reach a frame's selected window, redo the frame's menu bar. */
2108 if (update_mode_line
2109 && (FRAME_WINDOW_P (f
)
2111 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2112 FRAME_EXTERNAL_MENU_BAR (f
)
2114 FRAME_MENU_BAR_LINES (f
) > 0
2116 : FRAME_MENU_BAR_LINES (f
) > 0)
2117 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
2118 display_menu_bar (w
);
2121 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2123 int start
, end
, whole
;
2125 /* Calculate the start and end positions for the current window.
2126 At some point, it would be nice to choose between scrollbars
2127 which reflect the whole buffer size, with special markers
2128 indicating narrowing, and scrollbars which reflect only the
2131 Note that minibuffers sometimes aren't displaying any text. */
2132 if (! MINI_WINDOW_P (w
)
2133 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
2136 start
= marker_position (w
->start
) - BEGV
;
2137 /* I don't think this is guaranteed to be right. For the
2138 moment, we'll pretend it is. */
2139 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
2141 if (end
< start
) end
= start
;
2142 if (whole
< (end
- start
)) whole
= end
- start
;
2145 start
= end
= whole
= 0;
2147 /* Indicate what this scroll bar ought to be displaying now. */
2148 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
2150 /* Note that we actually used the scroll bar attached to this window,
2151 so it shouldn't be deleted at the end of redisplay. */
2152 (*redeem_scroll_bar_hook
) (w
);
2155 BUF_PT (current_buffer
) = opoint
;
2156 if (update_mode_line
)
2157 set_buffer_internal_1 (old
);
2159 set_buffer_temp (old
);
2160 BUF_PT (current_buffer
) = lpoint
;
2163 /* Do full redisplay on one window, starting at position `pos'. */
2166 try_window (window
, pos
)
2170 register struct window
*w
= XWINDOW (window
);
2171 register int height
= window_internal_height (w
);
2172 register int vpos
= XFASTINT (w
->top
);
2173 register int last_text_vpos
= vpos
;
2174 FRAME_PTR f
= XFRAME (w
->frame
);
2175 int width
= window_internal_width (w
) - 1;
2176 struct position val
;
2178 /* POS should never be out of range! */
2179 if (pos
< XBUFFER (w
->buffer
)->begv
2180 || pos
> XBUFFER (w
->buffer
)->zv
)
2183 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2185 overlay_arrow_seen
= 0;
2186 zv_strings_seen
= 0;
2187 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2188 val
.ovstring_chars_done
= 0;
2189 val
.tab_offset
= pos_tab_offset (w
, pos
);
2191 while (--height
>= 0)
2193 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, val
.tab_offset
,
2194 val
.ovstring_chars_done
);
2195 /* The following code is omitted because we maintain tab_offset
2198 tab_offset
+= width
;
2199 if (val
.vpos
) tab_offset
= 0;
2202 if (pos
!= val
.bufpos
)
2205 #ifdef USE_TEXT_PROPERTIES
2206 Lisp_Object invis_prop
;
2207 invis_prop
= Fget_char_property (val
.bufpos
-1, Qinvisible
, window
);
2208 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
2212 /* Next line, unless prev line ended in end of buffer with no cr */
2214 && (FETCH_BYTE (val
.bufpos
- 1) != '\n' || invis
));
2219 /* If last line is continued in middle of character,
2220 include the split character in the text considered on the frame */
2221 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2224 /* If bottom just moved off end of frame, change mode line percentage. */
2225 if (XFASTINT (w
->window_end_pos
) == 0
2227 w
->update_mode_line
= Qt
;
2229 /* Say where last char on frame will be, once redisplay is finished. */
2230 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
2231 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
2232 /* But that is not valid info until redisplay finishes. */
2233 w
->window_end_valid
= Qnil
;
2236 /* Try to redisplay when buffer is modified locally,
2237 computing insert/delete line to preserve text outside
2238 the bounds of the changes.
2239 Return 1 if successful, 0 if if cannot tell what to do,
2240 or -1 to tell caller to find a new window start,
2241 or -2 to tell caller to do normal redisplay with same window start. */
2244 try_window_id (window
)
2248 register struct window
*w
= XWINDOW (window
);
2249 register int height
= window_internal_height (w
);
2250 FRAME_PTR f
= XFRAME (w
->frame
);
2251 int top
= XFASTINT (w
->top
);
2252 int start
= marker_position (w
->start
);
2253 int width
= window_internal_width (w
) - 1;
2254 int hscroll
= XINT (w
->hscroll
);
2255 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
2258 register int i
, tem
;
2259 int last_text_vpos
= 0;
2261 int selective
= (INTEGERP (current_buffer
->selective_display
)
2262 ? XINT (current_buffer
->selective_display
)
2263 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2265 struct position val
, bp
, ep
, xp
, pp
;
2266 int scroll_amount
= 0;
2270 if (GPT
- BEG
< beg_unchanged
)
2271 beg_unchanged
= GPT
- BEG
;
2272 if (Z
- GPT
< end_unchanged
)
2273 end_unchanged
= Z
- GPT
;
2275 if (beg_unchanged
+ BEG
< start
)
2276 return 0; /* Give up if changes go above top of window */
2278 /* Find position before which nothing is changed. */
2279 bp
= *compute_motion (start
, 0, lmargin
, 0,
2280 min (ZV
, beg_unchanged
+ BEG
), height
,
2281 /* BUG FIX: See the comment of
2282 Fpos_visible_in_window_p() (window.c). */
2283 - (1 << (BITS_PER_SHORT
- 1)),
2284 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2285 if (bp
.vpos
>= height
)
2289 /* All changes are beyond the window end, and point is on the screen.
2290 We don't need to change the text at all.
2291 But we need to update window_end_pos to account for
2292 any change in buffer size. */
2293 bp
= *compute_motion (start
, 0, lmargin
, 0,
2295 /* BUG FIX: See the comment of
2296 Fpos_visible_in_window_p() (window.c). */
2297 - (1 << (BITS_PER_SHORT
- 1)),
2298 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2299 XSETFASTINT (w
->window_end_vpos
, height
);
2300 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
2308 /* Find beginning of that frame line. Must display from there. */
2309 bp
= *vmotion (bp
.bufpos
, 0, w
);
2317 /* If about to start displaying at the beginning of a continuation line,
2318 really start with previous frame line, in case it was not
2319 continued when last redisplayed */
2320 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
2322 /* Likewise if we have to worry about selective display. */
2323 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
2325 bp
= *vmotion (bp
.bufpos
, -1, w
);
2329 val
.tab_offset
= bp
.tab_offset
; /* Update tab offset. */
2331 if (bp
.contin
&& bp
.hpos
!= lmargin
)
2333 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
2334 val
.tab_offset
= bp
.tab_offset
+ bp
.prevhpos
- width
;
2341 /* Find first visible newline after which no more is changed. */
2342 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
2344 while (tem
< ZV
- 1 && (indented_beyond_p (tem
, selective
)))
2345 tem
= find_next_newline (tem
, 1);
2347 /* Compute the cursor position after that newline. */
2348 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
2349 height
, - (1 << (BITS_PER_SHORT
- 1)),
2351 /* We have tab offset in VAL, use it. */
2354 /* If changes reach past the text available on the frame,
2355 just display rest of frame. */
2356 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
2359 stop_vpos
= ep
.vpos
;
2361 /* If no newline before ep, the line ep is on includes some changes
2362 that must be displayed. Make sure we don't stop before it. */
2363 /* Also, if changes reach all the way until ep.bufpos,
2364 it is possible that something was deleted after the
2365 newline before it, so the following line must be redrawn. */
2366 if (stop_vpos
== ep
.vpos
2367 && (ep
.bufpos
== BEGV
2368 || FETCH_BYTE (ep
.bufpos
- 1) != '\n'
2369 || ep
.bufpos
== Z
- end_unchanged
))
2370 stop_vpos
= ep
.vpos
+ 1;
2373 overlay_arrow_seen
= 0;
2374 zv_strings_seen
= 0;
2376 /* If changes do not reach to bottom of window,
2377 figure out how much to scroll the rest of the window */
2378 if (stop_vpos
< height
)
2380 /* Now determine how far up or down the rest of the window has moved */
2381 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2382 Z
- XFASTINT (w
->window_end_pos
),
2383 /* Don't care for VPOS... */
2384 1 << (BITS_PER_SHORT
- 1),
2386 1 << (BITS_PER_SHORT
- 1),
2387 width
, hscroll
, ep
.tab_offset
, w
);
2388 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2390 /* Is everything on frame below the changes whitespace?
2391 If so, no scrolling is really necessary. */
2392 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
2394 tem
= FETCH_BYTE (i
);
2395 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2401 XSETFASTINT (w
->window_end_vpos
,
2402 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2404 /* Before doing any scrolling, verify that point will be on frame. */
2405 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.vpos
< height
))
2407 if (PT
<= xp
.bufpos
)
2409 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2410 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2412 /* We have tab offset in EP, use it. */
2417 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2418 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2420 /* We have tab offset in XP, use it. */
2423 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2425 cursor_vpos
= pp
.vpos
+ top
;
2426 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, pp
.hpos
, width
);
2429 if (stop_vpos
- scroll_amount
>= height
2430 || ep
.bufpos
== xp
.bufpos
)
2432 if (scroll_amount
< 0)
2433 stop_vpos
-= scroll_amount
;
2435 /* In this path, we have altered window_end_vpos
2436 and not left it negative.
2437 We must make sure that, in case display is preempted
2438 before the frame changes to reflect what we do here,
2439 further updates will not come to try_window_id
2440 and assume the frame and window_end_vpos match. */
2441 blank_end_of_window
= 1;
2443 else if (!scroll_amount
)
2445 /* Even if we don't need to scroll, we must adjust the
2446 charstarts of subsequent lines (that we won't redisplay)
2447 according to the amount of text inserted or deleted. */
2448 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2449 int adjust
= ep
.bufpos
- oldpos
;
2450 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2452 else if (bp
.bufpos
== Z
- end_unchanged
)
2454 /* If reprinting everything is nearly as fast as scrolling,
2455 don't bother scrolling. Can happen if lines are short. */
2456 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2457 top
+ height
- max (0, scroll_amount
),
2459 > xp
.bufpos
- bp
.bufpos
- 20)
2460 /* Return "try normal display with same window-start."
2461 Too bad we can't prevent further scroll-thinking. */
2463 /* If pure deletion, scroll up as many lines as possible.
2464 In common case of killing a line, this can save the
2465 following line from being overwritten by scrolling
2466 and therefore having to be redrawn. */
2467 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2468 top
+ height
- max (0, scroll_amount
),
2469 scroll_amount
, bp
.bufpos
);
2474 /* scroll_frame_lines did not properly adjust subsequent
2475 lines' charstarts in the case where the text of the
2476 screen line at bp.vpos has changed.
2477 (This can happen in a deletion that ends in mid-line.)
2478 To adjust properly, we need to make things consistent
2480 So do a second adjust to make that happen.
2481 Note that stop_vpos >= ep.vpos, so it is sufficient
2482 to update the charstarts for lines at ep.vpos and below. */
2484 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2485 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2486 ep
.bufpos
- oldstart
);
2489 else if (scroll_amount
)
2491 /* If reprinting everything is nearly as fast as scrolling,
2492 don't bother scrolling. Can happen if lines are short. */
2493 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2494 overestimate of cost of reprinting, since xp.bufpos
2495 would end up below the bottom of the window. */
2496 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2497 top
+ height
- max (0, scroll_amount
),
2499 > xp
.bufpos
- ep
.bufpos
- 20)
2500 /* Return "try normal display with same window-start."
2501 Too bad we can't prevent further scroll-thinking. */
2503 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2504 top
+ height
- max (0, scroll_amount
),
2505 scroll_amount
, ep
.bufpos
);
2506 if (!tem
) stop_vpos
= height
;
2510 /* In any case, do not display past bottom of window */
2511 if (stop_vpos
>= height
)
2517 /* Handle case where pos is before w->start --
2518 can happen if part of line had been clipped and is not clipped now */
2519 if (vpos
== 0 && pos
< marker_position (w
->start
))
2520 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2522 /* Redisplay the lines where the text was changed */
2523 last_text_vpos
= vpos
;
2524 /* The following code is omitted because we maintain tab offset in
2527 tab_offset
= pos_tab_offset (w
, pos
);
2528 /* If we are starting display in mid-character, correct tab_offset
2529 to account for passing the line that that character really starts in. */
2530 if (val
.hpos
< lmargin
)
2531 tab_offset
+= width
;
2534 while (vpos
< stop_vpos
)
2536 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, val
.tab_offset
,
2537 val
.ovstring_chars_done
);
2538 /* If display_text_line ran a hook and changed some text,
2539 redisplay all the way to bottom of buffer
2540 So that we show the changes. */
2541 if (old_tick
!= MODIFF
)
2543 /* The following code is omitted because we maintain tab offset
2544 in val.tab_offset. */
2546 tab_offset
+= width
;
2547 if (val
.vpos
) tab_offset
= 0;
2549 if (pos
!= val
.bufpos
)
2551 /* Next line, unless prev line ended in end of buffer with no cr */
2552 = vpos
- (val
.vpos
&& FETCH_BYTE (val
.bufpos
- 1) != '\n');
2556 /* There are two cases:
2557 1) we have displayed down to the bottom of the window
2558 2) we have scrolled lines below stop_vpos by scroll_amount */
2562 /* If last line is continued in middle of character,
2563 include the split character in the text considered on the frame */
2564 if (val
.hpos
< lmargin
)
2566 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2567 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2570 /* If scrolling made blank lines at window bottom,
2571 redisplay to fill those lines */
2572 if (scroll_amount
< 0)
2574 /* Don't consider these lines for general-purpose scrolling.
2575 That will save time in the scrolling computation. */
2576 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2580 val
.tab_offset
= xp
.tab_offset
;
2582 { /* Display from next line */
2583 vpos
= height
+ scroll_amount
;
2587 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2589 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2590 val
.tab_offset
= xp
.tab_offset
+ bp
.prevhpos
- width
;
2594 blank_end_of_window
= 1;
2595 /* The following code is omitted because we maintain tab offset
2596 in val.tab_offset. */
2598 tab_offset
= pos_tab_offset (w
, pos
);
2599 /* If we are starting display in mid-character, correct tab_offset
2600 to account for passing the line that that character starts in. */
2601 if (val
.hpos
< lmargin
)
2602 tab_offset
+= width
;
2604 while (vpos
< height
)
2606 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
,
2607 val
.tab_offset
, val
.ovstring_chars_done
);
2608 /* The following code is omitted because we maintain tab
2609 offset in val.tab_offset. */
2611 tab_offset
+= width
;
2612 if (val
.vpos
) tab_offset
= 0;
2617 /* Here is a case where display_text_line sets cursor_vpos wrong.
2618 Make it be fixed up, below. */
2624 /* If bottom just moved off end of frame, change mode line percentage. */
2625 if (XFASTINT (w
->window_end_pos
) == 0
2627 w
->update_mode_line
= Qt
;
2629 /* Attempt to adjust end-of-text positions to new bottom line */
2632 delta
= height
- xp
.vpos
;
2634 || (delta
> 0 && xp
.bufpos
<= ZV
)
2635 || (delta
== 0 && xp
.hpos
))
2637 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
2638 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2639 XSETFASTINT (w
->window_end_vpos
,
2640 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
2644 w
->window_end_valid
= Qnil
;
2646 /* If point was not in a line that was displayed, find it */
2647 if (cursor_vpos
< 0)
2650 val
= *compute_motion (start
, 0, lmargin
, 0, PT
,
2651 /* Don't care for VPOS... */
2652 1 << (BITS_PER_SHORT
- 1),
2654 1 << (BITS_PER_SHORT
- 1),
2655 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2656 /* Admit failure if point is off frame now */
2657 if (val
.vpos
>= height
)
2659 for (vpos
= 0; vpos
< height
; vpos
++)
2660 cancel_line (vpos
+ top
, f
);
2663 cursor_vpos
= val
.vpos
+ top
;
2664 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, val
.hpos
, width
);
2667 FRAME_CURSOR_X (f
) = cursor_hpos
;
2668 FRAME_CURSOR_Y (f
) = cursor_vpos
;
2672 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
2673 height
, - (1 << (BITS_PER_SHORT
- 1)),
2674 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2675 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
2677 if (XFASTINT (w
->window_end_pos
)
2685 /* Copy LEN glyphs starting address FROM to the rope TO.
2686 But don't actually copy the parts that would come in before S.
2687 Value is TO, advanced past the copied data.
2688 F is the frame we are displaying in. */
2691 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
2693 register GLYPH
*to
; /* Copy to here. */
2694 register GLYPH
*s
; /* Starting point. */
2695 Lisp_Object
*from
; /* Data to copy. */
2697 int face
; /* Face to apply to glyphs which don't specify one. */
2700 register Lisp_Object
*fp
= from
;
2701 /* These cache the results of the last call to compute_glyph_face. */
2703 int last_merged
= 0;
2706 if (! FRAME_TERMCAP_P (f
))
2709 GLYPH glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2711 unsigned int c
= FAST_GLYPH_CHAR (glyph
);
2714 /* For an invalid character code, use space. */
2717 if (FAST_GLYPH_FACE (glyph
) == 0)
2718 /* If GLYPH has no face code, use FACE. */
2720 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
2721 /* If it's same as previous glyph, use same result. */
2722 facecode
= last_merged
;
2725 /* Merge this glyph's face and remember the result. */
2726 last_code
= FAST_GLYPH_FACE (glyph
);
2727 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
2731 *to
= FAST_MAKE_GLYPH (c
, facecode
);
2739 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2746 /* Correct a glyph by replacing its specified user-level face code
2747 with a displayable computed face code. */
2750 fix_glyph (f
, glyph
, cface
)
2756 if (! FRAME_TERMCAP_P (f
))
2758 if (FAST_GLYPH_FACE (glyph
) != 0)
2759 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
2760 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
2766 /* Display one line of window W, starting at position START in W's buffer.
2768 Display starting at horizontal position HPOS, expressed relative to
2769 W's left edge. In situations where the text at START shouldn't
2770 start at the left margin (i.e. when the window is hscrolled, or
2771 we're continuing a line which left off in the midst of a
2772 multi-column character), HPOS should be negative; we throw away
2773 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2776 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2778 OVSTR_DONE is the number of chars of overlay before/after strings
2779 at this position which have already been processed.
2781 Display on position VPOS on the frame. It is origin 0, relative to
2782 the top of the frame, not W.
2784 Returns a STRUCT POSITION giving character to start next line with
2785 and where to display it, including a zero or negative hpos.
2786 The vpos field is not really a vpos; it is 1 unless the line is continued */
2788 struct position val_display_text_line
;
2790 static struct position
*
2791 display_text_line (w
, start
, vpos
, hpos
, taboffset
, ovstr_done
)
2799 register int pos
= start
;
2803 register unsigned char *p
;
2805 register GLYPH
*leftmargin
;
2806 register GLYPH
*p1prev
;
2807 register GLYPH
*p1start
;
2810 FRAME_PTR f
= XFRAME (w
->frame
);
2811 int tab_width
= XINT (current_buffer
->tab_width
);
2812 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
2813 int width
= window_internal_width (w
) - 1;
2814 struct position val
;
2817 int last_invis_skip
= 0;
2818 Lisp_Object last_invis_prop
;
2819 int hscroll
= XINT (w
->hscroll
);
2820 int truncate
= (hscroll
2821 || (truncate_partial_width_windows
2822 && !WINDOW_FULL_WIDTH_P (w
))
2823 || !NILP (current_buffer
->truncate_lines
));
2825 /* 1 if we should highlight the region. */
2826 int highlight_region
2827 = (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
)
2828 && (XWINDOW (current_buffer
->last_selected_window
) == w
2829 || highlight_nonselected_windows
));
2830 int region_beg
, region_end
;
2832 int selective
= (INTEGERP (current_buffer
->selective_display
)
2833 ? XINT (current_buffer
->selective_display
)
2834 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2835 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
2836 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
2838 Lisp_Object default_invis_vector
[3];
2839 /* Number of characters of ellipsis to display after an invisible line
2840 if it calls for an ellipsis.
2841 Note that this value can be nonzero regardless of whether
2842 selective display is enabled--you must check that separately. */
2844 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2845 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
2846 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
2847 /* This is the sequence of Lisp objects to display
2848 when there are invisible lines. */
2849 Lisp_Object
*invis_vector_contents
2850 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2851 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
2852 : default_invis_vector
);
2854 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
2855 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp
)))
2856 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
2857 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
2858 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp
)))
2859 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
2861 /* If 1, we must handle multibyte characters. */
2862 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
2863 /* Length of multibyte form of each character. */
2865 /* Glyphs generated should be set this bit mask if text must be
2866 displayed from right to left. */
2867 GLYPH rev_dir_bit
= (NILP (current_buffer
->direction_reversed
)
2868 ? 0 : GLYPH_MASK_REV_DIR
);
2870 /* The next buffer location at which the face should change, due
2871 to overlays or text property changes. */
2872 int next_face_change
;
2874 /* The next location where the `invisible' property changes, or an
2875 overlay starts or ends. */
2878 /* The face we're currently using. */
2879 int current_face
= 0;
2882 XSETFASTINT (default_invis_vector
[2], '.');
2883 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
2885 hpos
+= WINDOW_LEFT_MARGIN (w
);
2886 get_display_line (f
, vpos
, WINDOW_LEFT_MARGIN (w
));
2887 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
2889 /* Show where to highlight the region. */
2890 if (highlight_region
&& XMARKER (current_buffer
->mark
)->buffer
!= 0
2891 /* Maybe highlight only in selected window. */
2892 && (highlight_nonselected_windows
2893 || w
== XWINDOW (selected_window
)))
2895 region_beg
= marker_position (current_buffer
->mark
);
2896 if (PT
< region_beg
)
2898 region_end
= region_beg
;
2903 w
->region_showing
= Qt
;
2907 region_beg
= region_end
= -1;
2908 w
->region_showing
= Qnil
;
2911 if (MINI_WINDOW_P (w
)
2913 && vpos
== XFASTINT (w
->top
))
2915 if (! NILP (minibuf_prompt
))
2917 minibuf_prompt_width
2918 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
2919 XSTRING (minibuf_prompt
)->size
, hpos
,
2920 /* Display a space if we truncate. */
2923 /* Truncate the prompt a little before the
2924 margin, so user input can at least start
2925 on the first line. */
2926 (XFASTINT (w
->width
) > 10
2927 ? XFASTINT (w
->width
) - 4 : -1))
2929 hpos
+= minibuf_prompt_width
;
2930 taboffset
-= minibuf_prompt_width
;
2933 minibuf_prompt_width
= 0;
2936 /* If we're hscrolled at all, use compute_motion to skip over any
2937 text off the left edge of the window. compute_motion may know
2938 tricks to do this faster than we can. */
2941 struct position
*left_edge
2942 = compute_motion (pos
, vpos
, hpos
, 0,
2944 width
, hscroll
, taboffset
, w
);
2946 /* Retrieve the buffer position and column provided by
2947 compute_motion. We can't assume that the column will be
2948 zero, because you may have multi-column characters crossing
2951 compute_motion may have moved us past the screen position we
2952 requested, if we hit a multi-column character, or the end of
2953 the line. If so, back up. */
2954 if (left_edge
->vpos
> vpos
2955 || left_edge
->hpos
> 0)
2957 pos
= left_edge
->bufpos
;
2958 /* Since this should not be a valid multibyte character, we
2959 can decrease POS by 1. */
2961 hpos
= left_edge
->prevhpos
;
2965 pos
= left_edge
->bufpos
;
2966 hpos
= left_edge
->hpos
;
2970 desired_glyphs
->bufp
[vpos
] = start
;
2971 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2973 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
2974 /* In case we don't ever write anything into it... */
2975 desired_glyphs
->charstarts
[vpos
][WINDOW_LEFT_MARGIN (w
)] = -1;
2976 leftmargin
= desired_glyphs
->glyphs
[vpos
] + WINDOW_LEFT_MARGIN (w
);
2977 endp
= leftmargin
+ width
;
2979 /* Arrange the overlays nicely for our purposes. Usually, we call
2980 display_text_line on only one line at a time, in which case this
2981 can't really hurt too much, or we call it on lines which appear
2982 one after another in the buffer, in which case all calls to
2983 recenter_overlay_lists but the first will be pretty cheap. */
2984 recenter_overlay_lists (current_buffer
, pos
);
2986 /* Loop generating characters.
2987 Stop at end of buffer, before newline,
2988 if reach or pass continuation column,
2989 or at face change. */
2991 next_face_change
= pos
;
2992 next_boundary
= pos
;
3001 while (pos
== next_boundary
)
3003 Lisp_Object position
, limit
, prop
, ww
;
3005 /* Display the overlay strings here, unless we're at ZV
3006 and have already displayed the appropriate strings
3007 on an earlier line. */
3008 if (pos
< ZV
|| !zv_strings_seen
++)
3011 unsigned char *ovstr
;
3012 ovlen
= overlay_strings (pos
, w
, &ovstr
);
3016 /* Skip the ones we did in a previous line. */
3017 ovstr
+= ovstr_done
;
3018 ovlen
-= ovstr_done
;
3027 c
= STRING_CHAR_AND_LENGTH (ovstr
, ovlen
, len
);
3028 ovstr
+= len
, ovlen
-= len
, ovstr_done
+= len
;
3029 charset
= CHAR_CHARSET (c
);
3030 cols
= (charset
== CHARSET_COMPOSITION
3031 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3032 : CHARSET_WIDTH (charset
));
3036 c
= *ovstr
++, ovlen
--, ovstr_done
++;
3039 g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3042 if (p1
>= leftmargin
&& p1
< endp
)
3043 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3047 /* If we did all the overlay strings
3048 and we have room for text, clear ovstr_done
3049 just for neatness' sake. */
3050 if (ovlen
== 0 && p1
< endp
)
3055 /* Did we reach point? Record the cursor location. */
3056 if (pos
== PT
&& cursor_vpos
< 0)
3059 cursor_hpos
= p1
- leftmargin
;
3065 XSETFASTINT (position
, pos
);
3066 limit
= Fnext_overlay_change (position
);
3067 #ifdef USE_TEXT_PROPERTIES
3068 /* This is just an estimate to give reasonable
3069 performance; nothing should go wrong if it is too small. */
3070 if (XFASTINT (limit
) > pos
+ 50)
3072 int limitpos
= pos
+ 50;
3074 INC_POS (limitpos
); /* Adjust to character boundary. */
3075 XSETFASTINT (limit
, limitpos
);
3077 limit
= Fnext_single_property_change (position
, Qinvisible
,
3078 Fcurrent_buffer (), limit
);
3080 next_boundary
= XFASTINT (limit
);
3081 /* if the `invisible' property is set, we can skip to
3082 the next property change. */
3084 prop
= Fget_char_property (position
, Qinvisible
, ww
);
3085 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3087 if (pos
< PT
&& next_boundary
>= PT
)
3090 cursor_hpos
= p1
- leftmargin
;
3092 pos
= next_boundary
;
3093 last_invis_skip
= pos
;
3094 last_invis_prop
= prop
;
3098 /* Did we reach point? Record the cursor location. */
3099 if (pos
== PT
&& cursor_vpos
< 0)
3102 cursor_hpos
= p1
- leftmargin
;
3105 /* Did we hit the end of the visible region of the buffer?
3109 /* Update charstarts for the end of this line. */
3110 /* Do nothing if off the left edge or at the right edge. */
3111 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
3113 int *p2x
= &charstart
[(p1
< leftmargin
3121 /* Figure out where (if at all) the
3122 redisplay_end_trigger-hook should run. */
3123 if (MARKERP (w
->redisplay_end_trigger
)
3124 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
3125 e_t_h
= marker_position (w
->redisplay_end_trigger
);
3126 else if (INTEGERP (w
->redisplay_end_trigger
))
3127 e_t_h
= XINT (w
->redisplay_end_trigger
);
3131 /* If we've gone past the place to run a hook,
3133 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
3135 Lisp_Object args
[3];
3137 args
[0] = Qredisplay_end_trigger_functions
;
3138 XSETWINDOW (args
[1], w
);
3139 XSETINT (args
[2], e_t_h
);
3141 /* Since we are *trying* to run these functions,
3142 don't try to run them again, even if they get an error. */
3143 w
->redisplay_end_trigger
= Qnil
;
3144 Frun_hook_with_args (3, args
);
3147 /* Notice if it changed the face of this character. */
3148 next_face_change
= pos
;
3152 /* Did we hit a face change? Figure out what face we should
3153 use now. We also hit this the first time through the
3154 loop, to see what face we should start with. */
3155 if (pos
>= next_face_change
3156 && (FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
)))
3158 int limit
= pos
+ 50;
3160 if (limit
< Z
&& !CHAR_HEAD_P (POS_ADDR (limit
)))
3161 INC_POS (limit
); /* Adjust to character boundary. */
3162 current_face
= compute_char_face (f
, w
, pos
,
3163 region_beg
, region_end
,
3164 &next_face_change
, limit
, 0);
3168 /* Compute the next place we need to stop
3169 and do something special; set PAUSE. */
3173 if (pos
< next_boundary
&& next_boundary
< pause
)
3174 pause
= next_boundary
;
3175 if (pos
< next_face_change
&& next_face_change
< pause
)
3176 pause
= next_face_change
;
3181 /* Wouldn't you hate to read the next line to someone over
3183 if (pos
< PT
&& PT
< pause
)
3185 if (pos
< GPT
&& GPT
< pause
)
3197 /* PAUSE is surely at character boundary. */
3198 c
= STRING_CHAR_AND_LENGTH (p
, pause
- pos
, len
), p
+= len
;
3201 /* Let a display table override all standard display methods. */
3202 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3204 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
3205 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3206 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3207 current_face
, rev_dir_bit
);
3209 else if (c
>= 040 && c
< 0177)
3211 if (p1
>= leftmargin
)
3212 *p1
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3218 /* Same as p1prev, but after the invis_vector_contents text
3219 (if we have that on this line). */
3220 GLYPH
*p1prev_modified
;
3224 if (last_invis_skip
== pos
3225 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
3229 && indented_beyond_p (pos
+ 1, selective
))
3232 pos
= find_next_newline (pos
+ 1, 1);
3233 if (FETCH_BYTE (pos
- 1) == '\n')
3236 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
3241 cs
= charstart
+ (p1
- p1start
);
3244 p1
+= selective_rlen
;
3245 if (p1
- leftmargin
> width
)
3248 #if 0 /* This needs more work; charstarts needs to record
3249 both whether a position ho;ds an ellipsis character
3250 and what buffer position it corresponds to. */
3251 csend
= charstart
+ (p1
- p1start
);
3254 /* The idea is to use p1prev_modified instead of p1prev
3255 in the loop below over p2x. */
3256 p1prev_modified
= p1
;
3259 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3260 (p1
- p1prev
), current_face
, rev_dir_bit
);
3263 /* Update charstarts for the newline that ended this line. */
3264 /* Do nothing here for a char that's entirely off the left edge
3265 or if it starts at the right edge. */
3266 if (p1
>= leftmargin
&& p1prev
!= endp
)
3268 /* Store the newline's position into charstarts
3269 for the column where the newline starts.
3270 Store -1 for the rest of the glyphs it occupies. */
3271 int *p2x
= &charstart
[(p1prev
< leftmargin
3272 ? leftmargin
: p1prev
)
3274 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3281 /* Draw the face of the newline character as extending all the
3282 way to the end of the frame line. */
3285 if (p1
< leftmargin
)
3288 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3298 if (p1
>= leftmargin
&& p1
< endp
)
3299 *p1
= MAKE_GLYPH (f
, ' ', current_face
) | rev_dir_bit
;
3302 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
3305 else if (c
== Ctl ('M') && selective
== -1)
3307 pos
= find_next_newline (pos
, 1);
3308 if (FETCH_BYTE (pos
- 1) == '\n')
3310 if (selective_rlen
> 0)
3312 p1
+= selective_rlen
;
3313 if (p1
- leftmargin
> width
)
3315 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3316 (p1
- p1prev
), current_face
, rev_dir_bit
);
3319 /* Draw the face of the newline character as extending all the
3320 way to the end of the frame line. */
3323 if (p1
< leftmargin
)
3326 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3330 /* Update charstarts for the ^M that ended this line. */
3331 /* Do nothing here for a char that's entirely off the left edge
3332 or if it starts at the right edge. */
3333 if (p1
>= leftmargin
&& p1prev
!= endp
)
3335 /* Store the newline's position into charstarts
3336 for the column where the newline starts.
3337 Store -1 for the rest of the glyphs it occupies. */
3338 int *p2x
= &charstart
[(p1prev
< leftmargin
3339 ? leftmargin
: p1prev
)
3341 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3349 else if (c
< 0200 && ctl_arrow
)
3351 if (p1
>= leftmargin
)
3353 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3354 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
3355 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3359 if (p1
>= leftmargin
&& p1
< endp
)
3360 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
) | rev_dir_bit
;
3365 /* C is not a multibyte character. */
3366 if (p1
>= leftmargin
)
3368 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3369 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
3370 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3374 if (p1
>= leftmargin
&& p1
< endp
)
3375 *p1
= MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
) | rev_dir_bit
;
3377 if (p1
>= leftmargin
&& p1
< endp
)
3378 *p1
= (MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
)
3381 if (p1
>= leftmargin
&& p1
< endp
)
3382 *p1
= MAKE_GLYPH (f
, (7 & c
) + '0', current_face
) | rev_dir_bit
;
3387 /* C is a multibyte character. */
3388 int charset
= CHAR_CHARSET (c
);
3389 int columns
= (charset
== CHARSET_COMPOSITION
3390 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3391 : CHARSET_WIDTH (charset
));
3392 GLYPH g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3396 if (p1
>= leftmargin
&& p1
< endp
)
3397 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3405 /* Update charstarts for the character just output. */
3407 /* Do nothing here for a char that's entirely off the left edge. */
3408 if (p1
>= leftmargin
)
3410 /* Store the char's position into charstarts
3411 for the first glyph occupied by this char.
3412 Store -1 for the rest of the glyphs it occupies. */
3415 int *p2x
= &charstart
[(p1prev
< leftmargin
3416 ? leftmargin
: p1prev
)
3418 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3428 val
.hpos
= - XINT (w
->hscroll
);
3436 /* Store 0 in this charstart line for the positions where
3437 there is no character. But do leave what was recorded
3438 for the character that ended the line. */
3439 /* Add 1 in the endtest to compensate for the fact that ENDP was
3440 made from WIDTH, which is 1 less than the window's actual
3442 i
= p1
- p1start
+ 1;
3443 if (p1
< leftmargin
)
3444 i
+= leftmargin
- p1
;
3445 for (; i
< endp
- p1start
+ 1; i
++)
3448 /* Handle continuation in middle of a character */
3449 /* by backing up over it */
3452 /* Don't back up if we never actually displayed any text.
3453 This occurs when the minibuffer prompt takes up the whole line. */
3456 /* Start the next line with that same character whose
3457 character code is C and the length of multi-byte form is
3462 /* C is not a multi-byte character. We can break it and
3463 start from the middle column in the next line. So,
3464 adjust VAL.HPOS to skip the columns output on this
3466 val
.hpos
+= p1prev
- endp
;
3469 /* C is a multibyte character. Since we can't broke it
3470 in the middle, the whole character should be driven
3471 into the next line. */
3472 /* As the result, the actual columns occupied by the
3473 text on this line is less than WIDTH. VAL.TAB_OFFSET
3474 must be adjusted. */
3475 taboffset
= taboffset
+ (p1prev
- endp
);
3476 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3478 GLYPH g
= fix_glyph (f
, truncate
? truncator
: continuer
, 0);
3479 while (p1prev
< endp
)
3482 /* If POINT is at POS, cursor should not on this line. */
3489 /* Keep in this line everything up to the continuation column. */
3493 /* Finish deciding which character to start the next line on,
3494 and what hpos to start it at.
3495 Also set `lastpos' to the last position which counts as "on this line"
3496 for cursor-positioning. */
3500 if (FETCH_BYTE (pos
) == '\n')
3502 /* If stopped due to a newline, start next line after it */
3505 /* Check again for hidden lines, in case the newline occurred exactly
3506 at the right margin. */
3507 while (pos
< ZV
&& selective
> 0
3508 && indented_beyond_p (pos
, selective
))
3509 pos
= find_next_newline (pos
, 1);
3512 /* Stopped due to right margin of window */
3516 *p1
++ = fix_glyph (f
, truncator
, 0);
3517 /* Truncating => start next line after next newline,
3518 and point is on this line if it is before the newline,
3519 and skip none of first char of next line */
3521 pos
= find_next_newline (pos
, 1);
3522 while (pos
< ZV
&& selective
> 0
3523 && indented_beyond_p (pos
, selective
));
3524 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
3526 lastpos
= pos
- (FETCH_BYTE (pos
- 1) == '\n');
3531 *p1
++ = fix_glyph (f
, continuer
, 0);
3534 val
.tab_offset
= taboffset
+ width
;
3541 /* If point is at eol or in invisible text at eol,
3542 record its frame location now. */
3544 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
3547 cursor_hpos
= p1
- leftmargin
;
3550 if (cursor_vpos
== vpos
)
3552 if (cursor_hpos
< 0) cursor_hpos
= 0;
3553 if (cursor_hpos
> width
) cursor_hpos
= width
;
3554 cursor_hpos
+= WINDOW_LEFT_MARGIN (w
);
3555 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
3557 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
3558 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
3560 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3561 FRAME_CURSOR_X (f
) = cursor_hpos
;
3564 if (w
== XWINDOW (selected_window
))
3566 /* Line is not continued and did not start
3567 in middle of character */
3568 if ((hpos
- WINDOW_LEFT_MARGIN (w
)
3569 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
3572 this_line_bufpos
= start
;
3573 this_line_buffer
= current_buffer
;
3574 this_line_vpos
= cursor_vpos
;
3575 this_line_start_hpos
= hpos
;
3576 this_line_endpos
= Z
- lastpos
;
3579 this_line_bufpos
= 0;
3584 /* If hscroll and line not empty, insert truncation-at-left marker */
3585 if (hscroll
&& lastpos
!= start
)
3587 GLYPH g
= fix_glyph (f
, truncator
, 0);
3589 if (p1
<= leftmargin
)
3590 p1
= leftmargin
+ 1;
3591 else /* MULE: it may be a wide-column character */
3593 p1prev
= leftmargin
+ 1;
3594 while (p1prev
< p1
&& *p1prev
& GLYPH_MASK_PADDING
)
3599 if (!WINDOW_RIGHTMOST_P (w
))
3602 if (p1
< leftmargin
) p1
= leftmargin
;
3603 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
3605 /* Don't draw vertical bars if we're using scroll bars. They're
3606 covered up by the scroll bars, and it's distracting to see
3607 them when the scroll bar windows are flickering around to be
3609 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
3612 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
3615 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3616 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
3617 ? XINT (DISP_BORDER_GLYPH (dp
))
3620 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
3621 p1
- desired_glyphs
->glyphs
[vpos
]);
3622 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
3624 /* If the start of this line is the overlay arrow-position,
3625 then put the arrow string into the display-line. */
3627 if (MARKERP (Voverlay_arrow_position
)
3628 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
3629 && start
== marker_position (Voverlay_arrow_position
)
3630 && STRINGP (Voverlay_arrow_string
)
3631 && ! overlay_arrow_seen
)
3633 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
3635 int len
= XSTRING (Voverlay_arrow_string
)->size
;
3641 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string
)->intervals
))
3643 /* If the arrow string has text props, obey them when displaying. */
3644 for (i
= 0; i
< len
; i
++)
3647 Lisp_Object face
, ilisp
;
3650 XSETFASTINT (ilisp
, i
);
3651 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
3652 newface
= compute_glyph_face_1 (f
, face
, 0);
3653 leftmargin
[i
] = FAST_MAKE_GLYPH (c
, newface
);
3657 #endif /* HAVE_FACES */
3659 for (i
= 0; i
< len
; i
++)
3660 leftmargin
[i
] = p
[i
];
3663 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3664 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
3665 if (desired_glyphs
->used
[vpos
] < arrow_end
)
3666 desired_glyphs
->used
[vpos
] = arrow_end
;
3668 overlay_arrow_seen
= 1;
3672 val
.ovstring_chars_done
= ovstr_done
;
3673 val_display_text_line
= val
;
3674 return &val_display_text_line
;
3677 /* Redisplay the menu bar in the frame for window W. */
3680 display_menu_bar (w
)
3683 Lisp_Object items
, tail
;
3684 register int vpos
= 0;
3685 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3686 int maxendcol
= FRAME_WIDTH (f
);
3691 if (!NILP (Vwindow_system
))
3695 #ifdef USE_X_TOOLKIT
3698 #endif /* USE_X_TOOLKIT */
3700 get_display_line (f
, vpos
, 0);
3702 items
= FRAME_MENU_BAR_ITEMS (f
);
3703 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
3705 Lisp_Object pos
, string
;
3706 string
= XVECTOR (items
)->contents
[i
+ 1];
3710 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], hpos
);
3712 if (hpos
< maxendcol
)
3713 hpos
= display_string (w
, vpos
,
3714 XSTRING (string
)->data
,
3715 XSTRING (string
)->size
,
3716 hpos
, 0, 0, hpos
, maxendcol
);
3717 /* Put a space between items. */
3718 if (hpos
< maxendcol
)
3720 int hpos1
= hpos
+ 1;
3721 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
3722 min (hpos1
, maxendcol
), maxendcol
);
3726 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3727 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3729 /* Fill out the line with spaces. */
3730 if (maxendcol
> hpos
)
3731 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
);
3733 /* Clear the rest of the lines allocated to the menu bar. */
3735 while (vpos
< FRAME_MENU_BAR_LINES (f
))
3736 get_display_line (f
, vpos
++, 0);
3739 /* Display the mode line for window w */
3742 display_mode_line (w
)
3745 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
3746 register int left
= WINDOW_LEFT_MARGIN (w
);
3747 register int right
= WINDOW_RIGHT_MARGIN (w
);
3748 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3750 line_number_displayed
= 0;
3751 w
->column_number_displayed
= Qnil
;
3753 get_display_line (f
, vpos
, left
);
3755 /* Temporarily make frame F's kboard the current kboard
3756 so that kboard-local variables in the mode_line_format
3757 will get the right values. */
3758 push_frame_kboard (f
);
3760 display_mode_element (w
, vpos
, left
, 0, right
, right
,
3761 current_buffer
->mode_line_format
);
3763 pop_frame_kboard ();
3765 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3767 /* Put the mode line in inverse video.
3768 Use faces if possible, since that lets us handle
3769 partial-width windows and avoid inverting the scroll bar columns. */
3771 if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
3773 /* For a partial width window, explicitly set face of each glyph. */
3775 unsigned int padding
;
3776 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
3777 for (i
= left
; i
< right
; ++i
)
3779 padding
= ptr
[i
] & GLYPH_MASK_PADDING
;
3780 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1) | padding
;
3786 /* Make the mode line inverse video if the entire line
3787 is made of mode lines.
3788 I.e. if this window is full width,
3789 or if it is the child of a full width window
3790 (which implies that that window is split side-by-side
3791 and the rest of this line is mode lines of the sibling windows). */
3792 if (WINDOW_FULL_WIDTH_P (w
)
3793 || WINDOW_FULL_WIDTH_P (XWINDOW (w
->parent
)))
3794 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3797 /* Contribute ELT to the mode line for window W.
3798 How it translates into text depends on its data type.
3800 VPOS is the position of the mode line being displayed.
3802 HPOS is the position (absolute on frame) where this element's text
3803 should start. The output is truncated automatically at the right
3806 DEPTH is the depth in recursion. It is used to prevent
3807 infinite recursion here.
3809 MINENDCOL is the hpos before which the element may not end.
3810 The element is padded at the right with spaces if nec
3811 to reach this column.
3813 MAXENDCOL is the hpos past which this element may not extend.
3814 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3815 (This is necessary to make nested padding and truncation work.)
3817 Returns the hpos of the end of the text generated by ELT.
3818 The next element will receive that value as its HPOS arg,
3819 so as to concatenate the elements. */
3822 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
3824 register int vpos
, hpos
;
3827 register int maxendcol
;
3828 register Lisp_Object elt
;
3836 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
3840 /* A string: output it and check for %-constructs within it. */
3841 register unsigned char c
;
3842 register unsigned char *this = XSTRING (elt
)->data
;
3844 while (hpos
< maxendcol
&& *this)
3846 unsigned char *last
= this;
3847 while ((c
= *this++) != '\0' && c
!= '%')
3849 if (this - 1 != last
)
3851 register int lim
= --this - last
+ hpos
;
3852 if (frame_title_ptr
)
3853 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
3855 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
3856 hpos
, min (lim
, maxendcol
));
3860 register int minendcol
;
3861 register int spec_width
= 0;
3863 /* We can't allow -ve args due to the "%-" construct */
3864 /* Argument specifies minwidth but not maxwidth
3865 (maxwidth can be specified by
3866 (<negative-number> . <stuff>) mode-line elements) */
3868 while ((c
= *this++) >= '0' && c
<= '9')
3870 spec_width
= spec_width
* 10 + (c
- '0');
3873 minendcol
= hpos
+ spec_width
;
3874 if (minendcol
> maxendcol
)
3876 spec_width
= maxendcol
- hpos
;
3877 minendcol
= maxendcol
;
3881 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
3882 spec_width
, maxendcol
,
3883 Vglobal_mode_string
);
3886 char *spec
= decode_mode_spec (w
, c
, spec_width
,
3888 if (frame_title_ptr
)
3889 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
3891 hpos
= display_string (w
, vpos
, spec
, -1,
3893 minendcol
, maxendcol
);
3901 /* A symbol: process the value of the symbol recursively
3902 as if it appeared here directly. Avoid error if symbol void.
3903 Special case: if value of symbol is a string, output the string
3906 register Lisp_Object tem
;
3907 tem
= Fboundp (elt
);
3910 tem
= Fsymbol_value (elt
);
3911 /* If value is a string, output that string literally:
3912 don't check for % within it. */
3915 if (frame_title_ptr
)
3916 hpos
= store_frame_title (XSTRING (tem
)->data
,
3917 minendcol
, maxendcol
);
3919 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
3920 XSTRING (tem
)->size
,
3921 hpos
, 0, 1, minendcol
, maxendcol
);
3923 /* Give up right away for nil or t. */
3924 else if (!EQ (tem
, elt
))
3925 { elt
= tem
; goto tail_recurse
; }
3932 register Lisp_Object car
, tem
;
3934 /* A cons cell: three distinct cases.
3935 If first element is a string or a cons, process all the elements
3936 and effectively concatenate them.
3937 If first element is a negative number, truncate displaying cdr to
3938 at most that many characters. If positive, pad (with spaces)
3939 to at least that many characters.
3940 If first element is a symbol, process the cadr or caddr recursively
3941 according to whether the symbol's value is non-nil or nil. */
3942 car
= XCONS (elt
)->car
;
3945 tem
= Fboundp (car
);
3946 elt
= XCONS (elt
)->cdr
;
3949 /* elt is now the cdr, and we know it is a cons cell.
3950 Use its car if CAR has a non-nil value. */
3953 tem
= Fsymbol_value (car
);
3955 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
3957 /* Symbol's value is nil (or symbol is unbound)
3958 Get the cddr of the original list
3959 and if possible find the caddr and use that. */
3960 elt
= XCONS (elt
)->cdr
;
3963 else if (!CONSP (elt
))
3965 elt
= XCONS (elt
)->car
;
3968 else if (INTEGERP (car
))
3970 register int lim
= XINT (car
);
3971 elt
= XCONS (elt
)->cdr
;
3973 /* Negative int means reduce maximum width.
3974 DO NOT change MINENDCOL here!
3975 (20 -10 . foo) should truncate foo to 10 col
3976 and then pad to 20. */
3977 maxendcol
= min (maxendcol
, hpos
- lim
);
3980 /* Padding specified. Don't let it be more than
3983 if (lim
> maxendcol
)
3985 /* If that's more padding than already wanted, queue it.
3986 But don't reduce padding already specified even if
3987 that is beyond the current truncation point. */
3988 if (lim
> minendcol
)
3993 else if (STRINGP (car
) || CONSP (car
))
3995 register int limit
= 50;
3996 /* LIMIT is to protect against circular lists. */
3997 while (CONSP (elt
) && --limit
> 0
3998 && hpos
< maxendcol
)
4000 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4003 elt
= XCONS (elt
)->cdr
;
4011 if (frame_title_ptr
)
4012 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
4014 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
4015 minendcol
, maxendcol
);
4019 if (minendcol
> hpos
)
4020 if (frame_title_ptr
)
4021 hpos
= store_frame_title ("", minendcol
, maxendcol
);
4023 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 1, minendcol
, maxendcol
);
4027 /* Write a null-terminated, right justified decimal representation of
4028 the positive integer D to BUF using a minimal field width WIDTH. */
4031 pint2str (buf
, width
, d
)
4036 register char *p
= buf
;
4043 *p
++ = d
% 10 + '0';
4046 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
4056 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4057 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4058 type of CODING_SYSTEM. Return updated pointer into BUF. */
4061 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
4062 Lisp_Object coding_system
;
4068 val
= coding_system
;
4070 if (NILP (val
)) /* Not yet decided. */
4074 *buf
++ = eol_mnemonic_undecided
;
4075 /* Don't mention EOL conversion if it isn't decided. */
4079 Lisp_Object eolvalue
;
4081 eolvalue
= Fget (coding_system
, Qeol_type
);
4083 while (!NILP (val
) && SYMBOLP (val
))
4085 val
= Fget (val
, Qcoding_system
);
4086 if (NILP (eolvalue
))
4087 eolvalue
= Fget (coding_system
, Qeol_type
);
4090 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
4093 /* The EOL conversion we are using. */
4095 /* The EOL conversion that is normal on this system. */
4097 if (NILP (eolvalue
)) /* Not yet decided. */
4098 eoltype
= eol_mnemonic_undecided
;
4099 else if (VECTORP (eolvalue
)) /* Not yet decided. */
4100 eoltype
= eol_mnemonic_undecided
;
4101 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4102 eoltype
= (XFASTINT (eolvalue
) == 0
4104 : (XFASTINT (eolvalue
) == 1
4105 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
4107 /* Mention the EOL conversion if it is not the usual one. */
4114 /* Return a string for the output of a mode line %-spec for window W,
4115 generated by character C. SPEC_WIDTH is the field width when
4116 padding to the left (%c, %l). The value returned from this
4117 function will later be truncated to width MAXWIDTH. */
4119 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4122 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
4125 register int spec_width
;
4126 register int maxwidth
;
4129 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4130 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
4131 struct buffer
*b
= XBUFFER (w
->buffer
);
4134 if (maxwidth
> FRAME_WIDTH (f
))
4135 maxwidth
= FRAME_WIDTH (f
);
4140 if (!NILP (b
->read_only
))
4142 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4147 /* This differs from %* only for a modified read-only buffer. */
4148 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4150 if (!NILP (b
->read_only
))
4155 /* This differs from %* in ignoring read-only-ness. */
4156 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4168 if (command_loop_level
> 5)
4170 p
= decode_mode_spec_buf
;
4171 for (i
= 0; i
< command_loop_level
; i
++)
4174 return decode_mode_spec_buf
;
4182 if (command_loop_level
> 5)
4184 p
= decode_mode_spec_buf
;
4185 for (i
= 0; i
< command_loop_level
; i
++)
4188 return decode_mode_spec_buf
;
4196 if (maxwidth
< sizeof (lots_of_dashes
))
4197 return lots_of_dashes
;
4200 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
4204 return decode_mode_spec_buf
;
4210 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
4212 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
4213 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
4214 decode_mode_spec_buf
[maxwidth
] = '\0';
4215 return decode_mode_spec_buf
;
4222 int col
= current_column ();
4223 XSETFASTINT (w
->column_number_displayed
, col
);
4224 pint2str (decode_mode_spec_buf
, spec_width
, col
);
4225 return decode_mode_spec_buf
;
4229 /* %F displays the frame name. */
4230 if (!NILP (f
->title
))
4231 return (char *) XSTRING (f
->title
)->data
;
4232 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
4233 return (char *) XSTRING (f
->name
)->data
;
4241 else if (STRINGP (obj
) && XSTRING (obj
)->size
> maxwidth
)
4243 bcopy ("...", decode_mode_spec_buf
, 3);
4244 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
4245 decode_mode_spec_buf
+ 3, maxwidth
- 3);
4246 return decode_mode_spec_buf
;
4253 int startpos
= marker_position (w
->start
);
4254 int line
, linepos
, topline
;
4257 int height
= XFASTINT (w
->height
);
4259 /* If we decided that this buffer isn't suitable for line numbers,
4260 don't forget that too fast. */
4261 if (EQ (w
->base_line_pos
, w
->buffer
))
4263 /* But do forget it, if the window shows a different buffer now. */
4264 else if (BUFFERP (w
->base_line_pos
))
4265 w
->base_line_pos
= Qnil
;
4267 /* If the buffer is very big, don't waste time. */
4268 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
4270 w
->base_line_pos
= Qnil
;
4271 w
->base_line_number
= Qnil
;
4275 if (!NILP (w
->base_line_number
)
4276 && !NILP (w
->base_line_pos
)
4277 && XFASTINT (w
->base_line_pos
) <= marker_position (w
->start
))
4279 line
= XFASTINT (w
->base_line_number
);
4280 linepos
= XFASTINT (w
->base_line_pos
);
4285 linepos
= BUF_BEGV (b
);
4288 /* Count lines from base line to window start position. */
4289 nlines
= display_count_lines (linepos
, startpos
, startpos
, &junk
);
4291 topline
= nlines
+ line
;
4293 /* Determine a new base line, if the old one is too close
4294 or too far away, or if we did not have one.
4295 "Too close" means it's plausible a scroll-down would
4297 if (startpos
== BUF_BEGV (b
))
4299 XSETFASTINT (w
->base_line_number
, topline
);
4300 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
4302 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
4303 || linepos
== BUF_BEGV (b
))
4305 int limit
= BUF_BEGV (b
);
4307 int distance
= (height
* 2 + 30) * 200;
4309 if (startpos
- distance
> limit
)
4310 limit
= startpos
- distance
;
4312 nlines
= display_count_lines (startpos
, limit
,
4315 /* If we couldn't find the lines we wanted within
4317 give up on line numbers for this window. */
4318 if (position
== startpos
- distance
)
4320 w
->base_line_pos
= w
->buffer
;
4321 w
->base_line_number
= Qnil
;
4325 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
4326 XSETFASTINT (w
->base_line_pos
, position
);
4329 /* Now count lines from the start pos to point. */
4330 nlines
= display_count_lines (startpos
, PT
, PT
, &junk
);
4332 /* Record that we did display the line number. */
4333 line_number_displayed
= 1;
4335 /* Make the string to show. */
4336 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
4337 return decode_mode_spec_buf
;
4340 char* p
= decode_mode_spec_buf
;
4341 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
4343 return decode_mode_spec_buf
;
4353 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
4359 int pos
= marker_position (w
->start
);
4360 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4362 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
4364 if (pos
<= BUF_BEGV (b
))
4369 else if (pos
<= BUF_BEGV (b
))
4373 if (total
> 1000000)
4374 /* Do it differently for a large value, to avoid overflow. */
4375 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4377 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4378 /* We can't normally display a 3-digit number,
4379 so get us a 2-digit number that is close. */
4382 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4383 return decode_mode_spec_buf
;
4387 /* Display percentage of size above the bottom of the screen. */
4390 int toppos
= marker_position (w
->start
);
4391 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
4392 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4394 if (botpos
>= BUF_ZV (b
))
4396 if (toppos
<= BUF_BEGV (b
))
4403 if (total
> 1000000)
4404 /* Do it differently for a large value, to avoid overflow. */
4405 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4407 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4408 /* We can't normally display a 3-digit number,
4409 so get us a 2-digit number that is close. */
4412 if (toppos
<= BUF_BEGV (b
))
4413 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
4415 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4416 return decode_mode_spec_buf
;
4421 /* status of process */
4422 obj
= Fget_buffer_process (w
->buffer
);
4424 return "no process";
4426 obj
= Fsymbol_name (Fprocess_status (obj
));
4430 case 't': /* indicate TEXT or BINARY */
4431 #ifdef MODE_LINE_BINARY_TEXT
4432 return MODE_LINE_BINARY_TEXT (b
);
4438 /* coding-system (not including end-of-line format) */
4440 /* coding-system (including end-of-line type) */
4442 int eol_flag
= (c
== 'Z');
4445 if (FRAME_TERMCAP_P (f
))
4447 /* No need to mention EOL here--the terminal never needs
4448 to do EOL conversion. */
4449 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
4450 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
4452 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
4453 decode_mode_spec_buf
, eol_flag
);
4455 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
4457 obj
= Fget_buffer_process (Fcurrent_buffer ());
4460 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
4462 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
4465 #endif /* subprocesses */
4468 return decode_mode_spec_buf
;
4473 return (char *) XSTRING (obj
)->data
;
4478 /* Search for COUNT instances of a line boundary, which means either a
4479 newline or (if selective display enabled) a carriage return.
4480 Start at START. If COUNT is negative, search backwards.
4482 If we find COUNT instances, set *SHORTAGE to zero, and return the
4483 position after the COUNTth match. Note that for reverse motion
4484 this is not the same as the usual convention for Emacs motion commands.
4486 If we don't find COUNT instances before reaching the end of the
4487 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
4488 the number of line boundaries left unfound, and return the end of the
4489 buffer we bumped up against. */
4492 display_scan_buffer (start
, count
, shortage
)
4493 int *shortage
, start
;
4496 int limit
= ((count
> 0) ? ZV
- 1 : BEGV
);
4497 int direction
= ((count
> 0) ? 1 : -1);
4499 register unsigned char *cursor
;
4500 unsigned char *base
;
4502 register int ceiling
;
4503 register unsigned char *ceiling_addr
;
4505 /* If we are not in selective display mode,
4506 check only for newlines. */
4507 if (! (!NILP (current_buffer
->selective_display
)
4508 && !INTEGERP (current_buffer
->selective_display
)))
4509 return scan_buffer ('\n', start
, 0, count
, shortage
, 0);
4511 /* The code that follows is like scan_buffer
4512 but checks for either newline or carriage return. */
4518 while (start
!= limit
+ 1)
4520 ceiling
= BUFFER_CEILING_OF (start
);
4521 ceiling
= min (limit
, ceiling
);
4522 ceiling_addr
= POS_ADDR (ceiling
) + 1;
4523 base
= (cursor
= POS_ADDR (start
));
4526 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
4528 if (cursor
!= ceiling_addr
)
4533 return (start
+ cursor
- base
+ 1);
4536 if (++cursor
== ceiling_addr
)
4542 start
+= cursor
- base
;
4546 start
--; /* first character we scan */
4547 while (start
> limit
- 1)
4548 { /* we WILL scan under start */
4549 ceiling
= BUFFER_FLOOR_OF (start
);
4550 ceiling
= max (limit
, ceiling
);
4551 ceiling_addr
= POS_ADDR (ceiling
) - 1;
4552 base
= (cursor
= POS_ADDR (start
));
4556 while (--cursor
!= ceiling_addr
4557 && *cursor
!= '\n' && *cursor
!= 015)
4559 if (cursor
!= ceiling_addr
)
4564 return (start
+ cursor
- base
+ 1);
4570 start
+= cursor
- base
;
4575 *shortage
= count
* direction
;
4576 return (start
+ ((direction
== 1 ? 0 : 1)));
4579 /* Count up to N lines starting from FROM.
4580 But don't go beyond LIMIT.
4581 Return the number of lines thus found (always positive).
4582 Store the position after what was found into *POS_PTR. */
4585 display_count_lines (from
, limit
, n
, pos_ptr
)
4598 *pos_ptr
= display_scan_buffer (from
, n
, &shortage
);
4604 /* When scanning backwards, scan_buffer stops *after* the last newline
4605 it finds, but does count it. Compensate for that. */
4606 return - n
- shortage
- (*pos_ptr
!= limit
);
4607 return n
- shortage
;
4610 /* Display STRING on one line of window W, starting at HPOS.
4611 Display at position VPOS. Caller should have done get_display_line.
4612 If VPOS == -1, display it as the current frame's title.
4613 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4615 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4617 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4618 MAXCOL is the last column ok to end at. Truncate here.
4619 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4620 Both count from the left edge of the frame, as does HPOS.
4621 The right edge of W is an implicit maximum.
4622 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4624 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4625 at the place where the current window ends in this line
4626 and not display anything beyond there. Otherwise, only MAXCOL
4627 controls where to stop output.
4629 Returns ending hpos. */
4632 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
4633 obey_window_width
, mincol
, maxcol
)
4635 unsigned char *string
;
4639 int obey_window_width
;
4645 int hscroll
= XINT (w
->hscroll
);
4646 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
4647 register GLYPH
*start
;
4648 register GLYPH
*end
;
4649 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4650 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
4651 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
4652 int window_width
= XFASTINT (w
->width
);
4653 /* If 1, we must display multibyte characters. */
4654 int multibyte
= !NILP (XBUFFER (w
->buffer
)->enable_multibyte_characters
);
4656 /* Use the standard display table, not the window's display table.
4657 We don't want the mode line in rot13. */
4658 register struct Lisp_Char_Table
*dp
= 0;
4661 if (DISP_TABLE_P (Vstandard_display_table
))
4662 dp
= XCHAR_TABLE (Vstandard_display_table
);
4664 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
4667 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
4669 if (obey_window_width
)
4671 end
= start
+ window_width
- (truncate
!= 0);
4673 if (!WINDOW_RIGHTMOST_P (w
))
4675 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4679 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4682 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4687 if (! obey_window_width
4688 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
4689 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
4691 /* Store 0 in charstart for these columns. */
4692 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
4693 desired_glyphs
->charstarts
[vpos
][i
] = 0;
4695 if (maxcol
>= 0 && mincol
> maxcol
)
4699 /* We need this value for multibyte characters. */
4700 length
= strlen (string
);
4702 /* We set truncated to 1 if we get stopped by trying to pass END
4703 (that is, trying to pass MAXCOL.) */
4712 c
= STRING_CHAR_AND_LENGTH (string
, length
, len
);
4714 c
= *string
, len
= 1;
4716 string
+= len
, length
-= len
;
4724 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
4726 p1
= copy_part_of_rope (f
, p1
, start
,
4727 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
4728 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
4731 else if (c
>= 040 && c
< 0177)
4741 if (p1
>= start
&& p1
< end
)
4745 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
4747 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
4751 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
4752 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
4753 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
4756 if (p1
>= start
&& p1
< end
)
4762 /* C is a control character or a binary byte data. */
4765 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
4766 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
4767 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
4770 if (p1
>= start
&& p1
< end
)
4771 *p1
= (c
>> 6) + '0';
4773 if (p1
>= start
&& p1
< end
)
4774 *p1
= (7 & (c
>> 3)) + '0';
4776 if (p1
>= start
&& p1
< end
)
4777 *p1
= (7 & c
) + '0';
4782 /* C is a multibyte character. */
4783 int charset
= CHAR_CHARSET (c
);
4784 int columns
= (charset
== CHARSET_COMPOSITION
4785 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
4786 : CHARSET_WIDTH (charset
));
4790 /* Since we can't show the left part of C, fill all
4791 columns with spaces. */
4792 columns
-= start
- p1
;
4801 else if (p1
+ columns
> end
)
4803 /* Since we can't show the right part of C, fill all
4804 columns with TRUNCATE if TRUNCATE is specified. */
4808 *p1
++ = fix_glyph (f
, truncate
, 0);
4809 /* And tell the line is truncated. */
4816 /* We can show the whole glyph of C. */
4819 *p1
++ = c
| GLYPH_MASK_PADDING
;
4827 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
4829 else if (mincol
>= 0)
4831 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
4837 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
4839 if (len
> desired_glyphs
->used
[vpos
])
4840 desired_glyphs
->used
[vpos
] = len
;
4841 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
4847 /* This is like a combination of memq and assq.
4848 Return 1 if PROPVAL appears as an element of LIST
4849 or as the car of an element of LIST.
4850 If PROPVAL is a list, compare each element against LIST
4851 in that way, and return 1 if any element of PROPVAL is found in LIST.
4853 This function cannot quit. */
4856 invisible_p (propval
, list
)
4857 register Lisp_Object propval
;
4860 register Lisp_Object tail
, proptail
;
4861 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4863 register Lisp_Object tem
;
4864 tem
= XCONS (tail
)->car
;
4865 if (EQ (propval
, tem
))
4867 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
4870 if (CONSP (propval
))
4871 for (proptail
= propval
; CONSP (proptail
);
4872 proptail
= XCONS (proptail
)->cdr
)
4874 Lisp_Object propelt
;
4875 propelt
= XCONS (proptail
)->car
;
4876 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4878 register Lisp_Object tem
;
4879 tem
= XCONS (tail
)->car
;
4880 if (EQ (propelt
, tem
))
4882 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
4889 /* Return 1 if PROPVAL appears as the car of an element of LIST
4890 and the cdr of that element is non-nil.
4891 If PROPVAL is a list, check each element of PROPVAL in that way,
4892 and the first time some element is found,
4893 return 1 if the cdr of that element is non-nil.
4895 This function cannot quit. */
4898 invisible_ellipsis_p (propval
, list
)
4899 register Lisp_Object propval
;
4902 register Lisp_Object tail
, proptail
;
4903 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4905 register Lisp_Object tem
;
4906 tem
= XCONS (tail
)->car
;
4907 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
4908 return ! NILP (XCONS (tem
)->cdr
);
4910 if (CONSP (propval
))
4911 for (proptail
= propval
; CONSP (proptail
);
4912 proptail
= XCONS (proptail
)->cdr
)
4914 Lisp_Object propelt
;
4915 propelt
= XCONS (proptail
)->car
;
4916 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4918 register Lisp_Object tem
;
4919 tem
= XCONS (tail
)->car
;
4920 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
4921 return ! NILP (XCONS (tem
)->cdr
);
4930 staticpro (&Qmenu_bar_update_hook
);
4931 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
4933 staticpro (&Qoverriding_terminal_local_map
);
4934 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
4936 staticpro (&Qoverriding_local_map
);
4937 Qoverriding_local_map
= intern ("overriding-local-map");
4939 staticpro (&Qwindow_scroll_functions
);
4940 Qwindow_scroll_functions
= intern ("window-scroll-functions");
4942 staticpro (&Qredisplay_end_trigger_functions
);
4943 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
4945 staticpro (&last_arrow_position
);
4946 staticpro (&last_arrow_string
);
4947 last_arrow_position
= Qnil
;
4948 last_arrow_string
= Qnil
;
4950 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
4951 "String (or mode line construct) included (normally) in `mode-line-format'.");
4952 Vglobal_mode_string
= Qnil
;
4954 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
4955 "Marker for where to display an arrow on top of the buffer text.\n\
4956 This must be the beginning of a line in order to work.\n\
4957 See also `overlay-arrow-string'.");
4958 Voverlay_arrow_position
= Qnil
;
4960 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
4961 "String to display as an arrow. See also `overlay-arrow-position'.");
4962 Voverlay_arrow_string
= Qnil
;
4964 DEFVAR_INT ("scroll-step", &scroll_step
,
4965 "*The number of lines to try scrolling a window by when point moves out.\n\
4966 If that fails to bring point back on frame, point is centered instead.\n\
4967 If this is zero, point is always centered after it moves off frame.");
4969 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
4970 "*Scroll up to this many lines, to bring point back on screen.");
4971 scroll_conservatively
= 0;
4973 DEFVAR_INT ("scroll-margin", &scroll_margin
,
4974 "*Number of lines of margin at the top and bottom of a window.\n\
4975 Recenter the window whenever point gets within this many lines\n\
4976 of the top or bottom of the window.");
4979 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
4981 DEFVAR_BOOL ("truncate-partial-width-windows",
4982 &truncate_partial_width_windows
,
4983 "*Non-nil means truncate lines in all windows less than full frame wide.");
4984 truncate_partial_width_windows
= 1;
4986 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
4987 "*Non-nil means use inverse video for the mode line.");
4988 mode_line_inverse_video
= 1;
4990 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
4991 "*Maximum buffer size for which line number should be displayed.");
4992 line_number_display_limit
= 1000000;
4994 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
4995 "*Non-nil means highlight region even in nonselected windows.");
4996 highlight_nonselected_windows
= 0;
4998 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
4999 "Non-nil if more than one frame is visible on this display.\n\
5000 Minibuffer-only frames don't count, but iconified frames do.\n\
5001 This variable is not guaranteed to be accurate except while processing\n\
5002 `frame-title-format' and `icon-title-format'.");
5004 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
5005 "Template for displaying the titlebar of visible frames.\n\
5006 \(Assuming the window manager supports this feature.)\n\
5007 This variable has the same structure as `mode-line-format' (which see),\n\
5008 and is used only on frames for which no explicit name has been set\n\
5009 \(see `modify-frame-parameters').");
5010 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
5011 "Template for displaying the titlebar of an iconified frame.\n\
5012 \(Assuming the window manager supports this feature.)\n\
5013 This variable has the same structure as `mode-line-format' (which see),\n\
5014 and is used only on frames for which no explicit name has been set\n\
5015 \(see `modify-frame-parameters').");
5017 = Vframe_title_format
5018 = Fcons (intern ("multiple-frames"),
5019 Fcons (build_string ("%b"),
5020 Fcons (Fcons (build_string (""),
5021 Fcons (intern ("invocation-name"),
5022 Fcons (build_string ("@"),
5023 Fcons (intern ("system-name"),
5027 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
5028 "Maximum number of lines to keep in the message log buffer.\n\
5029 If nil, disable message logging. If t, log messages but don't truncate\n\
5030 the buffer when it becomes large.");
5031 XSETFASTINT (Vmessage_log_max
, 50);
5033 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
5034 "Functions called before redisplay, if window sizes have changed.\n\
5035 The value should be a list of functions that take one argument.\n\
5036 Just before redisplay, for each frame, if any of its windows have changed\n\
5037 size since the last redisplay, or have been split or deleted,\n\
5038 all the functions in the list are called, with the frame as argument.");
5039 Vwindow_size_change_functions
= Qnil
;
5041 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
5042 "List of Functions to call before redisplaying a window with scrolling.\n\
5043 Each function is called with two arguments, the window\n\
5044 and its new display-start position. Note that the value of `window-end'\n\
5045 is not valid when these functions are called.");
5046 Vwindow_scroll_functions
= Qnil
;
5049 /* initialize the window system */
5052 Lisp_Object root_window
;
5053 #ifndef COMPILER_REGISTER_BUG
5055 #endif /* COMPILER_REGISTER_BUG */
5056 struct window
*mini_w
;
5058 this_line_bufpos
= 0;
5060 mini_w
= XWINDOW (minibuf_window
);
5061 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
5063 echo_area_glyphs
= 0;
5064 previous_echo_glyphs
= 0;
5066 if (!noninteractive
)
5068 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
5069 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_MENU_BAR_LINES (f
));
5070 set_window_height (root_window
,
5071 FRAME_HEIGHT (f
) - 1 - FRAME_MENU_BAR_LINES (f
),
5073 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
5074 set_window_height (minibuf_window
, 1, 0);
5076 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
5077 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));