1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
24 /*#include <ctype.h>*/
30 #include "dispextern.h"
37 #include "termhooks.h"
38 #include "intervals.h"
43 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
44 extern void set_frame_menubar ();
45 extern int pending_menu_activation
;
48 extern int interrupt_input
;
49 extern int command_loop_level
;
51 extern int minibuffer_auto_raise
;
53 extern Lisp_Object Qface
;
55 extern Lisp_Object Voverriding_local_map
;
56 extern Lisp_Object Voverriding_local_map_menu_flag
;
58 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
59 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
60 Lisp_Object Qredisplay_end_trigger_functions
;
62 /* Nonzero means print newline to stdout before next minibuffer message. */
64 int noninteractive_need_newline
;
66 /* Nonzero means print newline to message log before next message. */
68 static int message_log_need_newline
;
70 #define min(a, b) ((a) < (b) ? (a) : (b))
71 #define max(a, b) ((a) > (b) ? (a) : (b))
72 #define minmax(floor, val, ceil) \
73 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
75 /* The buffer position of the first character appearing
76 entirely or partially on the current frame line.
77 Or zero, which disables the optimization for the current frame line. */
78 static int this_line_bufpos
;
80 /* Number of characters past the end of this line,
81 including the terminating newline */
82 static int this_line_endpos
;
84 /* The vertical position of this frame line. */
85 static int this_line_vpos
;
87 /* Hpos value for start of display on this frame line.
88 Usually zero, but negative if first character really began
90 static int this_line_start_hpos
;
92 /* Buffer that this_line variables are describing. */
93 static struct buffer
*this_line_buffer
;
95 /* Value of echo_area_glyphs when it was last acted on.
96 If this is nonzero, there is a message on the frame
97 in the minibuffer and it should be erased as soon
98 as it is no longer requested to appear. */
99 char *previous_echo_glyphs
;
101 /* Nonzero means truncate lines in all windows less wide than the frame */
102 int truncate_partial_width_windows
;
104 /* Nonzero means we have more than one non-minibuffer-only frame.
105 Not guaranteed to be accurate except while parsing frame-title-format. */
108 Lisp_Object Vglobal_mode_string
;
110 /* Marker for where to display an arrow on top of the buffer text. */
111 Lisp_Object Voverlay_arrow_position
;
113 /* String to display for the arrow. */
114 Lisp_Object Voverlay_arrow_string
;
116 /* Like mode-line-format, but for the titlebar on a visible frame. */
117 Lisp_Object Vframe_title_format
;
119 /* Like mode-line-format, but for the titlebar on an iconified frame. */
120 Lisp_Object Vicon_title_format
;
122 /* List of functions to call when a window's size changes. These
123 functions get one arg, a frame on which one or more windows' sizes
125 static Lisp_Object Vwindow_size_change_functions
;
127 /* Values of those variables at last redisplay. */
128 static Lisp_Object last_arrow_position
, last_arrow_string
;
130 Lisp_Object Qmenu_bar_update_hook
;
132 /* Nonzero if overlay arrow has been displayed once in this window. */
133 static int overlay_arrow_seen
;
135 /* Nonzero if visible end of buffer has already been displayed once
136 in this window. (We need this variable in case there are overlay
137 strings that get displayed there.) */
138 static int zv_strings_seen
;
140 /* Nonzero means highlight the region even in nonselected windows. */
141 static int highlight_nonselected_windows
;
143 /* If cursor motion alone moves point off frame,
144 Try scrolling this many lines up or down if that will bring it back. */
145 static int scroll_step
;
147 /* Non-0 means scroll just far enough to bring point back on the screen,
149 static int scroll_conservatively
;
151 /* Recenter the window whenever point gets within this many lines
152 of the top or bottom of the window. */
155 /* Nonzero if try_window_id has made blank lines at window bottom
156 since the last redisplay that paused */
157 static int blank_end_of_window
;
159 /* Number of windows showing the buffer of the selected window
160 (or another buffer with the same base buffer).
161 keyboard.c refers to this. */
164 /* display_text_line sets these to the frame position (origin 0) of point,
165 whether the window is selected or not.
166 Set one to -1 first to determine whether point was found afterwards. */
168 static int cursor_vpos
;
169 static int cursor_hpos
;
171 static int debug_end_pos
;
173 /* Nonzero means display mode line highlighted */
174 int mode_line_inverse_video
;
176 static void redisplay_internal ();
177 static int message_log_check_duplicate ();
178 static void echo_area_display ();
179 void mark_window_display_accurate ();
180 static void redisplay_windows ();
181 static void redisplay_window ();
182 static void update_menu_bar ();
183 static void try_window ();
184 static int try_window_id ();
185 static struct position
*display_text_line ();
186 static void display_mode_line ();
187 static int display_mode_element ();
188 static char *decode_mode_spec ();
189 static int display_string ();
190 static void display_menu_bar ();
191 static int display_count_lines ();
193 /* Prompt to display in front of the minibuffer contents */
194 Lisp_Object minibuf_prompt
;
196 /* Width in columns of current minibuffer prompt. */
197 int minibuf_prompt_width
;
199 /* Message to display instead of minibuffer contents
200 This is what the functions error and message make,
201 and command echoing uses it as well.
202 It overrides the minibuf_prompt as well as the buffer. */
203 char *echo_area_glyphs
;
205 /* This is the length of the message in echo_area_glyphs. */
206 int echo_area_glyphs_length
;
208 /* This is the window where the echo area message was displayed.
209 It is always a minibuffer window, but it may not be the
210 same window currently active as a minibuffer. */
211 Lisp_Object echo_area_window
;
213 /* true iff we should redraw the mode lines on the next redisplay */
214 int update_mode_lines
;
216 /* Smallest number of characters before the gap
217 at any time since last redisplay that finished.
218 Valid for current buffer when try_window_id can be called. */
221 /* Smallest number of characters after the gap
222 at any time since last redisplay that finished.
223 Valid for current buffer when try_window_id can be called. */
226 /* MODIFF as of last redisplay that finished;
227 if it matches MODIFF, and overlay_unchanged_modified
228 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
229 contain no useful information */
230 int unchanged_modified
;
232 /* OVERLAY_MODIFF as of last redisplay that finished. */
233 int overlay_unchanged_modified
;
235 /* Nonzero if window sizes or contents have changed
236 since last redisplay that finished */
237 int windows_or_buffers_changed
;
239 /* Nonzero after display_mode_line if %l was used
240 and it displayed a line number. */
241 int line_number_displayed
;
243 /* Maximum buffer size for which to display line numbers. */
244 static int line_number_display_limit
;
246 /* Number of lines to keep in the message log buffer.
247 t means infinite. nil means don't log at all. */
248 Lisp_Object Vmessage_log_max
;
250 /* Output a newline in the *Messages* buffer if "needs" one. */
253 message_log_maybe_newline ()
255 if (message_log_need_newline
)
256 message_dolog ("", 0, 1);
260 /* Add a string to the message log, optionally terminated with a newline.
261 This function calls low-level routines in order to bypass text property
262 hooks, etc. which might not be safe to run. */
265 message_dolog (m
, len
, nlflag
)
269 if (!NILP (Vmessage_log_max
))
271 struct buffer
*oldbuf
;
272 int oldpoint
, oldbegv
, oldzv
;
273 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
275 oldbuf
= current_buffer
;
276 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
277 current_buffer
->undo_list
= Qt
;
284 oldpoint
+= len
+ nlflag
;
286 oldzv
+= len
+ nlflag
;
289 insert_1 (m
, len
, 1, 0);
292 int this_bol
, prev_bol
, dup
;
293 insert_1 ("\n", 1, 1, 0);
295 this_bol
= scan_buffer ('\n', Z
, 0, -2, 0, 0);
298 prev_bol
= scan_buffer ('\n', this_bol
, 0, -2, 0, 0);
299 dup
= message_log_check_duplicate (prev_bol
, this_bol
);
302 if (oldpoint
> prev_bol
)
303 oldpoint
-= min (this_bol
, oldpoint
) - prev_bol
;
304 if (oldbegv
> prev_bol
)
305 oldbegv
-= min (this_bol
, oldbegv
) - prev_bol
;
306 if (oldzv
> prev_bol
)
307 oldzv
-= min (this_bol
, oldzv
) - prev_bol
;
308 del_range_1 (prev_bol
, this_bol
, 0);
314 /* If you change this format, don't forget to also
315 change message_log_check_duplicate. */
316 sprintf (dupstr
, " [%d times]", dup
);
317 duplen
= strlen (dupstr
);
323 insert_1 (dupstr
, duplen
, 1, 0);
328 if (NATNUMP (Vmessage_log_max
))
330 int pos
= scan_buffer ('\n', Z
, 0,
331 -XFASTINT (Vmessage_log_max
) - 1, 0, 0);
332 oldpoint
-= min (pos
, oldpoint
) - BEG
;
333 oldbegv
-= min (pos
, oldbegv
) - BEG
;
334 oldzv
-= min (pos
, oldzv
) - BEG
;
335 del_range_1 (BEG
, pos
, 0);
340 TEMP_SET_PT (oldpoint
);
341 set_buffer_internal (oldbuf
);
342 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
343 message_log_need_newline
= !nlflag
;
347 /* We are at the end of the buffer after just having inserted a newline.
348 (Note: We depend on the fact we won't be crossing the gap.)
349 Check to see if the most recent message looks a lot like the previous one.
350 Return 0 if different, 1 if the new one should just replace it, or a
351 value N > 1 if we should also append " [N times]". */
354 message_log_check_duplicate (prev_bol
, this_bol
)
355 int prev_bol
, this_bol
;
358 int len
= Z
- 1 - this_bol
;
360 unsigned char *p1
= BUF_CHAR_ADDRESS (current_buffer
, prev_bol
);
361 unsigned char *p2
= BUF_CHAR_ADDRESS (current_buffer
, this_bol
);
363 for (i
= 0; i
< len
; i
++)
365 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
374 if (*p1
++ == ' ' && *p1
++ == '[')
377 while (*p1
>= '0' && *p1
<= '9')
378 n
= n
* 10 + *p1
++ - '0';
379 if (strncmp (p1
, " times]\n", 8) == 0)
385 /* Display an echo area message M with a specified length of LEN chars.
386 The string may include null characters. If M is 0, clear out any
387 existing message, and let the minibuffer text show through.
389 The buffer M must continue to exist until after the echo area
390 gets cleared or some other message gets displayed there.
392 Do not pass text that is stored in a Lisp string.
393 Do not pass text in a buffer that was alloca'd. */
400 /* First flush out any partial line written with print. */
401 message_log_maybe_newline ();
403 message_dolog (m
, len
, 1);
404 message2_nolog (m
, len
);
408 /* The non-logging counterpart of message2. */
411 message2_nolog (m
, len
)
417 if (noninteractive_need_newline
)
419 noninteractive_need_newline
= 0;
420 fwrite (m
, len
, 1, stderr
);
421 if (cursor_in_echo_area
== 0)
422 fprintf (stderr
, "\n");
425 /* A null message buffer means that the frame hasn't really been
426 initialized yet. Error messages get reported properly by
427 cmd_error, so this must be just an informative message; toss it. */
428 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
430 Lisp_Object mini_window
;
433 /* Get the frame containing the minibuffer
434 that the selected frame is using. */
435 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
436 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
438 FRAME_SAMPLE_VISIBILITY (f
);
439 if (FRAME_VISIBLE_P (selected_frame
)
440 && ! FRAME_VISIBLE_P (f
))
441 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
445 echo_area_glyphs
= m
;
446 echo_area_glyphs_length
= len
;
448 if (minibuffer_auto_raise
)
449 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
452 echo_area_glyphs
= previous_echo_glyphs
= 0;
454 do_pending_window_change ();
455 echo_area_display ();
456 update_frame (f
, 1, 1);
457 do_pending_window_change ();
458 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
459 (*frame_up_to_date_hook
) (f
);
463 /* Display a null-terminated echo area message M. If M is 0, clear out any
464 existing message, and let the minibuffer text show through.
466 The buffer M must continue to exist until after the echo area
467 gets cleared or some other message gets displayed there.
469 Do not pass text that is stored in a Lisp string.
470 Do not pass text in a buffer that was alloca'd. */
476 message2 (m
, (m
? strlen (m
) : 0));
483 message2_nolog (m
, (m
? strlen (m
) : 0));
486 /* Truncate what will be displayed in the echo area
487 the next time we display it--but don't redisplay it now. */
490 truncate_echo_area (len
)
493 /* A null message buffer means that the frame hasn't really been
494 initialized yet. Error messages get reported properly by
495 cmd_error, so this must be just an informative message; toss it. */
496 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
497 echo_area_glyphs_length
= len
;
500 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
501 zero if being used by message. */
502 int message_buf_print
;
504 /* Dump an informative message to the minibuf. If M is 0, clear out
505 any existing message, and let the minibuffer text show through. */
509 message (m
, a1
, a2
, a3
)
511 EMACS_INT a1
, a2
, a3
;
517 if (noninteractive_need_newline
)
519 noninteractive_need_newline
= 0;
520 fprintf (stderr
, m
, a1
, a2
, a3
);
521 if (cursor_in_echo_area
== 0)
522 fprintf (stderr
, "\n");
526 else if (INTERACTIVE
)
528 /* The frame whose minibuffer we're going to display the message on.
529 It may be larger than the selected frame, so we need
530 to use its buffer, not the selected frame's buffer. */
531 Lisp_Object mini_window
;
534 /* Get the frame containing the minibuffer
535 that the selected frame is using. */
536 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
537 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
539 /* A null message buffer means that the frame hasn't really been
540 initialized yet. Error messages get reported properly by
541 cmd_error, so this must be just an informative message; toss it. */
542 if (FRAME_MESSAGE_BUF (f
))
553 len
= doprnt (FRAME_MESSAGE_BUF (f
),
554 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
556 len
= doprnt (FRAME_MESSAGE_BUF (f
),
557 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, &a1
);
558 #endif /* NO_ARG_ARRAY */
560 message2 (FRAME_MESSAGE_BUF (f
), len
);
565 /* Print should start at the beginning of the message
567 message_buf_print
= 0;
572 /* The non-logging version of message. */
574 message_nolog (m
, a1
, a2
, a3
)
576 EMACS_INT a1
, a2
, a3
;
578 Lisp_Object old_log_max
;
579 old_log_max
= Vmessage_log_max
;
580 Vmessage_log_max
= Qnil
;
581 message (m
, a1
, a2
, a3
);
582 Vmessage_log_max
= old_log_max
;
588 message2 (echo_area_glyphs
, echo_area_glyphs_length
);
596 Lisp_Object mini_window
;
598 /* Choose the minibuffer window for this display.
599 It is the minibuffer window used by the selected frame. */
600 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
601 /* This is the frame that window is in. */
602 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
604 if (! FRAME_VISIBLE_P (f
))
609 redraw_garbaged_frames ();
613 if (echo_area_glyphs
|| minibuf_level
== 0)
617 echo_area_window
= mini_window
;
619 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
620 get_display_line (f
, vpos
, 0);
622 /* Make sure the columns that overlap a left-hand scroll bar
624 for (i
= 0; i
< FRAME_LEFT_SCROLL_BAR_WIDTH (f
); i
++)
625 f
->desired_glyphs
->glyphs
[vpos
][i
] = SPACEGLYPH
;
627 display_string (XWINDOW (mini_window
), vpos
,
628 echo_area_glyphs
? echo_area_glyphs
: "",
629 echo_area_glyphs
? echo_area_glyphs_length
: -1,
630 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
632 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
));
634 #if 0 /* This just gets in the way. update_frame does the job. */
635 /* If desired cursor location is on this line, put it at end of text */
636 if (cursor_in_echo_area
)
637 FRAME_CURSOR_Y (f
) = vpos
;
638 if (FRAME_CURSOR_Y (f
) == vpos
)
639 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
642 /* Fill the rest of the minibuffer window with blank lines. */
647 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
649 get_display_line (f
, i
, 0);
650 display_string (XWINDOW (mini_window
), i
,
652 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
654 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
));
658 else if (!EQ (mini_window
, selected_window
))
659 windows_or_buffers_changed
++;
661 if (EQ (mini_window
, selected_window
))
662 this_line_bufpos
= 0;
664 previous_echo_glyphs
= echo_area_glyphs
;
667 /* Update frame titles. */
669 #ifdef HAVE_WINDOW_SYSTEM
670 static char frame_title_buf
[512];
671 static char *frame_title_ptr
;
674 store_frame_title (str
, mincol
, maxcol
)
679 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
680 maxcol
= sizeof (frame_title_buf
);
681 limit
= &frame_title_buf
[maxcol
];
682 while (*str
!= '\0' && frame_title_ptr
< limit
)
683 *frame_title_ptr
++ = *str
++;
684 while (frame_title_ptr
< &frame_title_buf
[mincol
])
685 *frame_title_ptr
++ = ' ';
686 return frame_title_ptr
- frame_title_buf
;
690 x_consider_frame_title (frame
)
696 FRAME_PTR f
= XFRAME (frame
);
698 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
701 /* Do we have more than one visible frame on this X display? */
705 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
707 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
709 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
710 && !FRAME_MINIBUF_ONLY_P (tf
)
711 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
715 multiple_frames
= CONSP (tail
);
718 obuf
= current_buffer
;
719 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
720 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
721 frame_title_ptr
= frame_title_buf
;
722 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
723 0, sizeof (frame_title_buf
), fmt
);
725 set_buffer_internal (obuf
);
726 /* Set the name only if it's changed. This avoids consing
727 in the common case where it hasn't. (If it turns out that we've
728 already wasted too much time by walking through the list with
729 display_mode_element, then we might need to optimize at a higher
731 if (! STRINGP (f
->name
) || XSTRING (f
->name
)->size
!= len
732 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
733 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
736 #define frame_title_ptr ((char *)0)
737 #define store_frame_title(str, mincol, maxcol) 0
740 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
741 This can call eval. */
746 register struct window
*w
= XWINDOW (selected_window
);
748 struct gcpro gcpro1
, gcpro2
;
750 all_windows
= (update_mode_lines
|| buffer_shared
> 1
751 || windows_or_buffers_changed
);
753 /* Update all frame titles based on their buffer names, etc.
754 We do this before the menu bars so that the buffer-menu
755 will show the up-to-date frame titles.
757 This used to be done after the menu bars, for a reason that
758 was stated as follows but which I do not understand:
759 "We do this after the menu bars so that the frame will first
760 create its menu bar using the name `emacs' if no other name
761 has yet been specified."
762 I think that is no longer a concern. */
763 #ifdef HAVE_WINDOW_SYSTEM
764 if (windows_or_buffers_changed
|| update_mode_lines
)
766 Lisp_Object tail
, frame
;
768 FOR_EACH_FRAME (tail
, frame
)
769 if (FRAME_VISIBLE_P (XFRAME (frame
))
770 || FRAME_ICONIFIED_P (XFRAME (frame
)))
771 x_consider_frame_title (frame
);
775 /* Update the menu bar item lists, if appropriate.
776 This has to be done before any actual redisplay
777 or generation of display lines. */
780 Lisp_Object tail
, frame
;
781 int count
= specpdl_ptr
- specpdl
;
783 record_unwind_protect (Fstore_match_data
, Fmatch_data (Qnil
, Qnil
));
785 FOR_EACH_FRAME (tail
, frame
)
787 /* If a window on this frame changed size,
788 report that to the user and clear the size-change flag. */
789 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
791 Lisp_Object functions
;
792 /* Clear flag first in case we get error below. */
793 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
794 functions
= Vwindow_size_change_functions
;
795 GCPRO2 (tail
, functions
);
796 while (CONSP (functions
))
798 call1 (XCONS (functions
)->car
, frame
);
799 functions
= XCONS (functions
)->cdr
;
804 update_menu_bar (XFRAME (frame
), 0);
808 unbind_to (count
, Qnil
);
811 update_menu_bar (selected_frame
, 1);
813 /* Motif needs this. See comment in xmenu.c.
814 Turn it off when pending_menu_activation is not defined. */
816 pending_menu_activation
= 0;
820 /* Do a frame update, taking possible shortcuts into account.
821 This is the main external entry point for redisplay.
823 If the last redisplay displayed an echo area message and that
824 message is no longer requested, we clear the echo area
825 or bring back the minibuffer if that is in use.
827 Do not call eval from within this function.
828 Calls to eval after the call to echo_area_display would confuse
829 the display_line mechanism and would cause a crash.
830 Calls to eval before that point will work most of the time,
831 but can still lose, because this function
832 can be called from signal handlers; with alarms set up;
833 or with synchronous processes running.
835 See Fcall_process; if you called it from here, it could be
836 entered recursively. */
838 static int do_verify_charstarts
;
840 /* Counter is used to clear the face cache
841 no more than once ever 1000 redisplays. */
842 static int clear_face_cache_count
;
844 /* Record the previous terminal frame we displayed. */
845 static FRAME_PTR previous_terminal_frame
;
850 redisplay_internal (0);
853 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
854 is not in response to any user action; therefore, we should
855 preserve the echo area. (Actually, our caller does that job.)
856 Perhaps in the future avoid recentering windows
857 if it is not necessary; currently that causes some problems. */
860 redisplay_internal (preserve_echo_area
)
861 int preserve_echo_area
;
863 register struct window
*w
= XWINDOW (selected_window
);
867 register int tlbufpos
, tlendpos
;
869 int number_of_frames_redisplayed
;
875 if (popup_activated ())
879 if (! FRAME_WINDOW_P (selected_frame
)
880 && previous_terminal_frame
!= selected_frame
)
882 /* Since frames on an ASCII terminal share the same display area,
883 displaying a different frame means redisplay the whole thing. */
884 windows_or_buffers_changed
++;
885 SET_FRAME_GARBAGED (selected_frame
);
886 XSETFRAME (Vterminal_frame
, selected_frame
);
888 previous_terminal_frame
= selected_frame
;
890 /* Set the visible flags for all frames.
891 Do this before checking for resized or garbaged frames; they want
892 to know if their frames are visible.
893 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
894 number_of_frames_redisplayed
= 0;
896 Lisp_Object tail
, frame
;
898 FOR_EACH_FRAME (tail
, frame
)
900 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
901 number_of_frames_redisplayed
++;
903 /* Clear out all the display lines in which we will generate the
904 glyphs to display. */
905 init_desired_glyphs (XFRAME (frame
));
909 /* Notice any pending interrupt request to change frame size. */
910 do_pending_window_change ();
914 redraw_garbaged_frames ();
918 prepare_menu_bars ();
920 if (windows_or_buffers_changed
)
923 /* Detect case that we need to write or remove a star in the mode line. */
924 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
926 w
->update_mode_line
= Qt
;
927 if (buffer_shared
> 1)
931 /* If %c is in use, update it if needed. */
932 if (!NILP (w
->column_number_displayed
)
933 /* This alternative quickly identifies a common case
934 where no change is needed. */
935 && !(PT
== XFASTINT (w
->last_point
)
936 && XFASTINT (w
->last_modified
) >= MODIFF
937 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
938 && XFASTINT (w
->column_number_displayed
) != current_column ())
939 w
->update_mode_line
= Qt
;
941 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
943 all_windows
= update_mode_lines
|| buffer_shared
> 1;
945 /* If specs for an arrow have changed, do thorough redisplay
946 to ensure we remove any arrow that should no longer exist. */
947 if (! EQ (Voverlay_arrow_position
, last_arrow_position
)
948 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
951 /* Normally the message* functions will have already displayed and
952 updated the echo area, but the frame may have been trashed, or
953 the update may have been preempted, so display the echo area
955 if (echo_area_glyphs
|| previous_echo_glyphs
)
957 echo_area_display ();
961 /* If showing region, and mark has changed, must redisplay whole window. */
962 if (((!NILP (Vtransient_mark_mode
)
963 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
964 != !NILP (w
->region_showing
))
965 || (!NILP (w
->region_showing
)
966 && !EQ (w
->region_showing
,
967 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
968 this_line_bufpos
= -1;
970 tlbufpos
= this_line_bufpos
;
971 tlendpos
= this_line_endpos
;
972 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
973 && !current_buffer
->clip_changed
974 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
975 /* Make sure recorded data applies to current buffer, etc */
976 && this_line_buffer
== current_buffer
977 && current_buffer
== XBUFFER (w
->buffer
)
978 && NILP (w
->force_start
)
979 /* Point must be on the line that we have info recorded about */
981 && PT
<= Z
- tlendpos
982 /* All text outside that line, including its final newline,
984 && ((XFASTINT (w
->last_modified
) >= MODIFF
985 && (XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
))
986 || (beg_unchanged
>= tlbufpos
- 1
988 /* If selective display, can't optimize
989 if the changes start at the beginning of the line. */
990 && ((INTEGERP (current_buffer
->selective_display
)
991 && XINT (current_buffer
->selective_display
) > 0
992 ? (beg_unchanged
>= tlbufpos
995 && end_unchanged
>= tlendpos
996 && Z
- GPT
>= tlendpos
)))
998 if (tlbufpos
> BEGV
&& FETCH_BYTE (tlbufpos
- 1) != '\n'
1000 || FETCH_BYTE (tlbufpos
) == '\n'))
1001 /* Former continuation line has disappeared by becoming empty */
1003 else if (XFASTINT (w
->last_modified
) < MODIFF
1004 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
1005 || MINI_WINDOW_P (w
))
1007 /* We have to handle the case of continuation around a
1008 wide-column character (See the comment in indent.c around
1011 For instance, in the following case:
1013 -------- Insert --------
1014 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1015 J_I_ ==> J_I_ `^^' are cursors.
1019 As we have to redraw the line above, we should goto cancel. */
1021 struct position val
;
1024 prevline
= find_next_newline (tlbufpos
, -1);
1025 val
= *compute_motion (prevline
, 0,
1026 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1029 1 << (BITS_PER_SHORT
- 1),
1030 1 << (BITS_PER_SHORT
- 1),
1031 window_internal_width (w
) - 1,
1032 XINT (w
->hscroll
), 0, w
);
1033 if (val
.hpos
!= this_line_start_hpos
)
1037 overlay_arrow_seen
= 0;
1038 zv_strings_seen
= 0;
1039 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
1040 pos_tab_offset (w
, tlbufpos
), 0);
1041 /* If line contains point, is not continued,
1042 and ends at same distance from eob as before, we win */
1043 if (cursor_vpos
>= 0 && this_line_bufpos
1044 && this_line_endpos
== tlendpos
)
1046 /* If this is not the window's last line,
1047 we must adjust the charstarts of the lines below. */
1048 if (this_line_vpos
+ 1
1049 < XFASTINT (w
->top
) + window_internal_height (w
))
1051 int left
= WINDOW_LEFT_MARGIN (w
);
1052 int *charstart_next_line
1053 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
1056 if (Z
- tlendpos
== ZV
)
1057 /* This line ends at end of (accessible part of) buffer.
1058 There is no newline to count. */
1059 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
1061 /* This line ends in a newline.
1062 Must take account of the newline and the rest of the
1063 text that follows. */
1064 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
1066 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
1069 if (!WINDOW_FULL_WIDTH_P (w
))
1070 preserve_other_columns (w
);
1076 else if (PT
== XFASTINT (w
->last_point
)
1077 /* Make sure the cursor was last displayed
1078 in this window. Otherwise we have to reposition it. */
1079 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
1080 && (XINT (w
->top
) + XINT (w
->height
)
1081 > FRAME_CURSOR_Y (selected_frame
)))
1085 do_pending_window_change ();
1090 /* If highlighting the region, or if the cursor is in the echo area,
1091 then we can't just move the cursor. */
1092 else if (! (!NILP (Vtransient_mark_mode
)
1093 && !NILP (current_buffer
->mark_active
))
1094 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1095 || highlight_nonselected_windows
)
1096 && NILP (w
->region_showing
)
1097 && !cursor_in_echo_area
)
1099 pos
= *compute_motion (tlbufpos
, 0,
1100 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1102 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
1103 window_internal_width (w
) - 1,
1105 pos_tab_offset (w
, tlbufpos
), w
);
1108 int width
= window_internal_width (w
) - 1;
1109 FRAME_CURSOR_X (selected_frame
)
1110 = WINDOW_LEFT_MARGIN (w
) + minmax (0, pos
.hpos
, width
);
1111 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1118 /* Text changed drastically or point moved off of line */
1119 cancel_line (this_line_vpos
, selected_frame
);
1122 this_line_bufpos
= 0;
1123 all_windows
|= buffer_shared
> 1;
1125 clear_face_cache_count
++;
1129 Lisp_Object tail
, frame
;
1132 /* Clear the face cache, only when we do a full redisplay
1133 and not too often either. */
1134 if (clear_face_cache_count
> 1000)
1136 clear_face_cache ();
1137 clear_face_cache_count
= 0;
1141 /* Recompute # windows showing selected buffer.
1142 This will be incremented each time such a window is displayed. */
1145 FOR_EACH_FRAME (tail
, frame
)
1147 FRAME_PTR f
= XFRAME (frame
);
1148 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
1151 /* Mark all the scroll bars to be removed; we'll redeem the ones
1152 we want when we redisplay their windows. */
1153 if (condemn_scroll_bars_hook
)
1154 (*condemn_scroll_bars_hook
) (f
);
1156 if (FRAME_VISIBLE_P (f
))
1157 redisplay_windows (FRAME_ROOT_WINDOW (f
), preserve_echo_area
);
1159 /* Any scroll bars which redisplay_windows should have nuked
1160 should now go away. */
1161 if (judge_scroll_bars_hook
)
1162 (*judge_scroll_bars_hook
) (f
);
1166 else if (FRAME_VISIBLE_P (selected_frame
))
1168 redisplay_window (selected_window
, 1, preserve_echo_area
);
1169 if (!WINDOW_FULL_WIDTH_P (w
))
1170 preserve_other_columns (w
);
1174 /* Prevent various kinds of signals during display update.
1175 stdio is not robust about handling signals,
1176 which can cause an apparent I/O error. */
1177 if (interrupt_input
)
1187 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1191 if (!FRAMEP (XCONS (tail
)->car
))
1194 f
= XFRAME (XCONS (tail
)->car
);
1196 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
1197 && FRAME_VISIBLE_P (f
))
1199 pause
|= update_frame (f
, 0, 0);
1202 mark_window_display_accurate (f
->root_window
, 1);
1203 if (frame_up_to_date_hook
!= 0)
1204 (*frame_up_to_date_hook
) (f
);
1211 if (FRAME_VISIBLE_P (selected_frame
))
1212 pause
= update_frame (selected_frame
, 0, 0);
1216 /* We may have called echo_area_display at the top of this
1217 function. If the echo area is on another frame, that may
1218 have put text on a frame other than the selected one, so the
1219 above call to update_frame would not have caught it. Catch
1222 Lisp_Object mini_window
;
1223 FRAME_PTR mini_frame
;
1225 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1226 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1228 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
1229 pause
|= update_frame (mini_frame
, 0, 0);
1233 /* If frame does not match, prevent doing single-line-update next time.
1234 Also, don't forget to check every line to update the arrow. */
1237 this_line_bufpos
= 0;
1238 if (!NILP (last_arrow_position
))
1240 last_arrow_position
= Qt
;
1241 last_arrow_string
= Qt
;
1243 /* If we pause after scrolling, some lines in current_frame
1244 may be null, so preserve_other_columns won't be able to
1245 preserve all the vertical-bar separators. So, avoid using it
1247 if (!WINDOW_FULL_WIDTH_P (w
))
1248 update_mode_lines
= 1;
1251 /* Now text on frame agrees with windows, so
1252 put info into the windows for partial redisplay to follow */
1256 register struct buffer
*b
= XBUFFER (w
->buffer
);
1258 blank_end_of_window
= 0;
1259 unchanged_modified
= BUF_MODIFF (b
);
1260 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
1261 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1262 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1264 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1265 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1266 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1269 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1272 b
->clip_changed
= 0;
1273 w
->update_mode_line
= Qnil
;
1274 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1275 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
1277 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1280 /* Record if we are showing a region, so can make sure to
1281 update it fully at next redisplay. */
1282 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1283 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1284 || highlight_nonselected_windows
)
1285 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1286 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1289 w
->window_end_valid
= w
->buffer
;
1290 last_arrow_position
= Voverlay_arrow_position
;
1291 last_arrow_string
= Voverlay_arrow_string
;
1292 if (do_verify_charstarts
)
1293 verify_charstarts (w
);
1294 if (frame_up_to_date_hook
!= 0)
1295 (*frame_up_to_date_hook
) (selected_frame
);
1297 update_mode_lines
= 0;
1298 windows_or_buffers_changed
= 0;
1301 /* Start SIGIO interrupts coming again.
1302 Having them off during the code above
1303 makes it less likely one will discard output,
1304 but not impossible, since there might be stuff
1305 in the system buffer here.
1306 But it is much hairier to try to do anything about that. */
1308 if (interrupt_input
)
1312 /* If something has become visible now which was not before,
1313 redisplay again, so that we get them. */
1316 Lisp_Object tail
, frame
;
1319 FOR_EACH_FRAME (tail
, frame
)
1321 int this_is_visible
= 0;
1322 if (XFRAME (frame
)->visible
)
1323 this_is_visible
= 1;
1324 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1325 if (XFRAME (frame
)->visible
)
1326 this_is_visible
= 1;
1328 if (this_is_visible
)
1332 if (new_count
!= number_of_frames_redisplayed
)
1333 windows_or_buffers_changed
++;
1336 /* Change frame size now if a change is pending. */
1337 do_pending_window_change ();
1339 /* If we just did a pending size change, redisplay again
1340 for the new size. */
1341 if (windows_or_buffers_changed
&& !pause
)
1345 /* Redisplay, but leave alone any recent echo area message
1346 unless another message has been requested in its place.
1348 This is useful in situations where you need to redisplay but no
1349 user action has occurred, making it inappropriate for the message
1350 area to be cleared. See tracking_off and
1351 wait_reading_process_input for examples of these situations. */
1353 redisplay_preserve_echo_area ()
1355 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1357 echo_area_glyphs
= previous_echo_glyphs
;
1358 redisplay_internal (1);
1359 echo_area_glyphs
= 0;
1362 redisplay_internal (1);
1366 mark_window_display_accurate (window
, flag
)
1370 register struct window
*w
;
1372 for (;!NILP (window
); window
= w
->next
)
1374 if (!WINDOWP (window
)) abort ();
1375 w
= XWINDOW (window
);
1377 if (!NILP (w
->buffer
))
1379 XSETFASTINT (w
->last_modified
,
1380 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1381 XSETFASTINT (w
->last_overlay_modified
,
1382 !flag
? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)));
1384 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1387 /* Record if we are showing a region, so can make sure to
1388 update it fully at next redisplay. */
1389 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1390 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1391 || highlight_nonselected_windows
)
1392 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1393 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1397 w
->window_end_valid
= w
->buffer
;
1398 w
->update_mode_line
= Qnil
;
1399 if (!NILP (w
->buffer
) && flag
)
1400 XBUFFER (w
->buffer
)->clip_changed
= 0;
1402 if (!NILP (w
->vchild
))
1403 mark_window_display_accurate (w
->vchild
, flag
);
1404 if (!NILP (w
->hchild
))
1405 mark_window_display_accurate (w
->hchild
, flag
);
1410 last_arrow_position
= Voverlay_arrow_position
;
1411 last_arrow_string
= Voverlay_arrow_string
;
1415 /* t is unequal to any useful value of Voverlay_arrow_... */
1416 last_arrow_position
= Qt
;
1417 last_arrow_string
= Qt
;
1421 /* Update the menu bar item list for frame F.
1422 This has to be done before we start to fill in any display lines,
1423 because it can call eval.
1425 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1428 update_menu_bar (f
, save_match_data
)
1430 int save_match_data
;
1432 struct buffer
*old
= current_buffer
;
1434 register struct window
*w
;
1436 window
= FRAME_SELECTED_WINDOW (f
);
1437 w
= XWINDOW (window
);
1439 if (update_mode_lines
)
1440 w
->update_mode_line
= Qt
;
1442 if (FRAME_WINDOW_P (f
)
1444 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1445 FRAME_EXTERNAL_MENU_BAR (f
)
1447 FRAME_MENU_BAR_LINES (f
) > 0
1449 : FRAME_MENU_BAR_LINES (f
) > 0)
1451 /* If the user has switched buffers or windows, we need to
1452 recompute to reflect the new bindings. But we'll
1453 recompute when update_mode_lines is set too; that means
1454 that people can use force-mode-line-update to request
1455 that the menu bar be recomputed. The adverse effect on
1456 the rest of the redisplay algorithm is about the same as
1457 windows_or_buffers_changed anyway. */
1458 if (windows_or_buffers_changed
1459 || !NILP (w
->update_mode_line
)
1460 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1461 < BUF_MODIFF (XBUFFER (w
->buffer
)))
1462 != !NILP (w
->last_had_star
))
1463 || ((!NILP (Vtransient_mark_mode
)
1464 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1465 != !NILP (w
->region_showing
)))
1467 struct buffer
*prev
= current_buffer
;
1468 int count
= specpdl_ptr
- specpdl
;
1470 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1471 if (save_match_data
)
1472 record_unwind_protect (Fstore_match_data
, Fmatch_data (Qnil
, Qnil
));
1473 if (NILP (Voverriding_local_map_menu_flag
))
1475 specbind (Qoverriding_terminal_local_map
, Qnil
);
1476 specbind (Qoverriding_local_map
, Qnil
);
1479 /* Run the Lucid hook. */
1480 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1481 /* If it has changed current-menubar from previous value,
1482 really recompute the menubar from the value. */
1483 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1484 call0 (Qrecompute_lucid_menubar
);
1485 safe_run_hooks (Qmenu_bar_update_hook
);
1486 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1487 /* Redisplay the menu bar in case we changed it. */
1488 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1489 if (FRAME_WINDOW_P (f
))
1490 set_frame_menubar (f
, 0, 0);
1492 /* On a terminal screen, the menu bar is an ordinary screen
1493 line, and this makes it get updated. */
1494 w
->update_mode_line
= Qt
;
1495 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1496 /* In the non-toolkit version, the menu bar is an ordinary screen
1497 line, and this makes it get updated. */
1498 w
->update_mode_line
= Qt
;
1499 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1501 unbind_to (count
, Qnil
);
1502 set_buffer_internal_1 (prev
);
1509 /* Redisplay WINDOW and its subwindows and siblings. */
1512 redisplay_windows (window
, preserve_echo_area
)
1514 int preserve_echo_area
;
1516 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1517 redisplay_window (window
, 0, preserve_echo_area
);
1520 /* Return value in display table DP (Lisp_Char_Table *) for character
1521 C. Since a display table doesn't have any parent, we don't have to
1522 follow parent. Do not call this function directly but use the
1523 macro DISP_CHAR_VECTOR. */
1525 disp_char_vector (dp
, c
)
1526 struct Lisp_Char_Table
*dp
;
1532 if (SINGLE_BYTE_CHAR_P (c
)) return (dp
->contents
[c
]);
1534 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
1535 if (code
[0] != CHARSET_COMPOSITION
)
1537 if (code
[1] < 32) code
[1] = -1;
1538 else if (code
[2] < 32) code
[2] = -1;
1540 /* Here, the possible range of CODE[0] (== charset ID) is
1541 128..MAX_CHARSET. Since the top level char table contains data
1542 for multibyte characters after 256th element, we must increment
1543 CODE[0] by 128 to get a correct index. */
1545 code
[3] = -1; /* anchor */
1547 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
1549 val
= dp
->contents
[code
[i
]];
1550 if (!SUB_CHAR_TABLE_P (val
))
1551 return (NILP (val
) ? dp
->defalt
: val
);
1553 /* Here, VAL is a sub char table. We return the default value of it. */
1554 return (dp
->defalt
);
1557 /* Redisplay window WINDOW and its subwindows. */
1560 redisplay_window (window
, just_this_one
, preserve_echo_area
)
1562 int just_this_one
, preserve_echo_area
;
1564 register struct window
*w
= XWINDOW (window
);
1565 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1567 register int lpoint
= PT
;
1568 struct buffer
*old
= current_buffer
;
1569 register int width
= window_internal_width (w
) - 1;
1570 register int startp
;
1571 register int hscroll
= XINT (w
->hscroll
);
1572 struct position pos
;
1575 int update_mode_line
;
1576 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1578 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1580 /* If this is a combination window, do its children; that's all. */
1582 if (!NILP (w
->vchild
))
1584 redisplay_windows (w
->vchild
, preserve_echo_area
);
1587 if (!NILP (w
->hchild
))
1589 redisplay_windows (w
->hchild
, preserve_echo_area
);
1592 if (NILP (w
->buffer
))
1595 height
= window_internal_height (w
);
1596 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1597 if (XBUFFER (w
->buffer
)->clip_changed
)
1598 update_mode_line
= 1;
1600 if (MINI_WINDOW_P (w
))
1602 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1603 /* We've already displayed the echo area glyphs in this window. */
1604 goto finish_scroll_bars
;
1605 else if (w
!= XWINDOW (minibuf_window
))
1607 /* This is a minibuffer, but it's not the currently active one,
1609 int vpos
= XFASTINT (w
->top
);
1612 for (i
= 0; i
< height
; i
++)
1614 get_display_line (f
, vpos
+ i
, 0);
1615 display_string (w
, vpos
+ i
, "", 0,
1616 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
1620 goto finish_scroll_bars
;
1624 /* Otherwise set up data on this window; select its buffer and point value */
1626 if (update_mode_line
)
1627 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1629 set_buffer_temp (XBUFFER (w
->buffer
));
1633 /* If %c is in mode line, update it if needed. */
1634 if (!NILP (w
->column_number_displayed
)
1635 /* This alternative quickly identifies a common case
1636 where no change is needed. */
1637 && !(PT
== XFASTINT (w
->last_point
)
1638 && XFASTINT (w
->last_modified
) >= MODIFF
1639 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1640 && XFASTINT (w
->column_number_displayed
) != current_column ())
1641 update_mode_line
= 1;
1643 /* Count number of windows showing the selected buffer.
1644 An indirect buffer counts as its base buffer. */
1648 struct buffer
*current_base
, *window_base
;
1649 current_base
= current_buffer
;
1650 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1651 if (current_base
->base_buffer
)
1652 current_base
= current_base
->base_buffer
;
1653 if (window_base
->base_buffer
)
1654 window_base
= window_base
->base_buffer
;
1655 if (current_base
== window_base
)
1659 /* POINT refers normally to the selected window.
1660 For any other window, set up appropriate value. */
1662 if (!EQ (window
, selected_window
))
1664 int new_pt
= marker_position (w
->pointm
);
1668 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1670 else if (new_pt
> (ZV
- 1))
1673 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1675 /* We don't use SET_PT so that the point-motion hooks don't run. */
1676 BUF_PT (current_buffer
) = new_pt
;
1679 /* If any of the character widths specified in the display table
1680 have changed, invalidate the width run cache. It's true that this
1681 may be a bit late to catch such changes, but the rest of
1682 redisplay goes (non-fatally) haywire when the display table is
1683 changed, so why should we worry about doing any better? */
1684 if (current_buffer
->width_run_cache
)
1686 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1688 if (! disptab_matches_widthtab (disptab
,
1689 XVECTOR (current_buffer
->width_table
)))
1691 invalidate_region_cache (current_buffer
,
1692 current_buffer
->width_run_cache
,
1694 recompute_width_table (current_buffer
, disptab
);
1698 /* If window-start is screwed up, choose a new one. */
1699 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1702 startp
= marker_position (w
->start
);
1704 /* If someone specified a new starting point but did not insist,
1705 check whether it can be used. */
1706 if (!NILP (w
->optional_new_start
))
1708 w
->optional_new_start
= Qnil
;
1709 /* Check whether this start pos is usable given where point is. */
1711 pos
= *compute_motion (startp
, 0,
1712 (((EQ (window
, minibuf_window
)
1714 ? minibuf_prompt_width
: 0)
1715 + (hscroll
? 1 - hscroll
: 0)),
1718 /* BUG FIX: See the comment of
1719 Fpos_visible_in_window_p (window.c). */
1720 - (1 << (BITS_PER_SHORT
- 1)),
1721 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1722 /* If PT does fit on the screen, we will use this start pos,
1723 so do so by setting force_start. */
1724 if (pos
.bufpos
== PT
)
1725 w
->force_start
= Qt
;
1728 /* Handle case where place to start displaying has been specified,
1729 unless the specified location is outside the accessible range. */
1730 if (!NILP (w
->force_start
))
1732 w
->force_start
= Qnil
;
1733 /* Forget any recorded base line for line number display. */
1734 w
->base_line_number
= Qnil
;
1735 /* Redisplay the mode line. Select the buffer properly for that.
1736 Also, run the hook window-scroll-functions
1737 because we have scrolled. */
1738 /* Note, we do this after clearing force_start because
1739 if there's an error, it is better to forget about force_start
1740 than to get into an infinite loop calling the hook functions
1741 and having them get more errors. */
1742 if (!update_mode_line
1743 || ! NILP (Vwindow_scroll_functions
))
1745 Lisp_Object temp
[3];
1747 set_buffer_temp (old
);
1748 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1749 update_mode_line
= 1;
1750 w
->update_mode_line
= Qt
;
1751 if (! NILP (Vwindow_scroll_functions
))
1753 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1754 make_number (startp
));
1755 startp
= marker_position (w
->start
);
1758 XSETFASTINT (w
->last_modified
, 0);
1759 XSETFASTINT (w
->last_overlay_modified
, 0);
1760 if (startp
< BEGV
) startp
= BEGV
;
1761 if (startp
> ZV
) startp
= ZV
;
1762 try_window (window
, startp
);
1763 if (cursor_vpos
< 0)
1765 /* If point does not appear, move point so it does appear */
1766 pos
= *compute_motion (startp
, 0,
1767 (((EQ (window
, minibuf_window
)
1769 ? minibuf_prompt_width
: 0)
1770 + (hscroll
? 1 - hscroll
: 0)),
1773 - (1 << (BITS_PER_SHORT
- 1)),
1774 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1775 BUF_PT (current_buffer
) = pos
.bufpos
;
1776 if (w
!= XWINDOW (selected_window
))
1777 Fset_marker (w
->pointm
, make_number (PT
), Qnil
);
1780 if (current_buffer
== old
)
1782 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
1783 + minmax (0, pos
.hpos
, width
));
1784 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1786 /* If we are highlighting the region,
1787 then we just changed the region, so redisplay to show it. */
1788 if (!NILP (Vtransient_mark_mode
)
1789 && !NILP (current_buffer
->mark_active
))
1791 cancel_my_columns (XWINDOW (window
));
1792 try_window (window
, startp
);
1798 /* Handle case where text has not changed, only point,
1799 and it has not moved off the frame. */
1801 /* This code is not used for minibuffer for the sake of
1802 the case of redisplaying to replace an echo area message;
1803 since in that case the minibuffer contents per se are usually unchanged.
1804 This code is of no real use in the minibuffer since
1805 the handling of this_line_bufpos, etc.,
1806 in redisplay handles the same cases. */
1808 if (XFASTINT (w
->last_modified
) >= MODIFF
1809 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
1810 && PT
>= startp
&& !current_buffer
->clip_changed
1811 && (just_this_one
|| WINDOW_FULL_WIDTH_P (w
))
1812 /* If force-mode-line-update was called, really redisplay;
1813 that's how redisplay is forced after e.g. changing
1814 buffer-invisibility-spec. */
1815 && NILP (w
->update_mode_line
)
1816 /* Can't use this case if highlighting a region. */
1817 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
1818 && NILP (w
->region_showing
)
1819 /* If end pos is out of date, scroll bar and percentage will be wrong */
1820 && INTEGERP (w
->window_end_vpos
)
1821 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
1822 && !EQ (window
, minibuf_window
))
1824 int this_scroll_margin
= scroll_margin
;
1826 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
1828 /* BUG FIX: See the comment of
1829 Fpos_visible_in_window_p (window.c). */
1830 - (1 << (BITS_PER_SHORT
- 1)),
1832 pos_tab_offset (w
, startp
), w
);
1834 /* Don't use a scroll margin that is negative or too large. */
1835 if (this_scroll_margin
< 0)
1836 this_scroll_margin
= 0;
1838 if (XINT (w
->height
) < 4 * scroll_margin
)
1839 this_scroll_margin
= XINT (w
->height
) / 4;
1841 /* If point fits on the screen, and not within the scroll margin,
1843 if (pos
.vpos
< height
- this_scroll_margin
1844 && (pos
.vpos
>= this_scroll_margin
|| startp
== BEGV
))
1846 /* Ok, point is still on frame */
1847 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
1849 /* These variables are supposed to be origin 1 */
1850 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
1851 + minmax (0, pos
.hpos
, width
));
1852 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1854 /* This doesn't do the trick, because if a window to the right of
1855 this one must be redisplayed, this does nothing because there
1856 is nothing in DesiredFrame yet, and then the other window is
1857 redisplayed, making likes that are empty in this window's columns.
1858 if (WINDOW_FULL_WIDTH_P (w))
1859 preserve_my_columns (w);
1863 /* Don't bother trying redisplay with same start;
1864 we already know it will lose */
1866 /* If current starting point was originally the beginning of a line
1867 but no longer is, find a new starting point. */
1868 else if (!NILP (w
->start_at_line_beg
)
1870 || FETCH_BYTE (startp
- 1) == '\n'))
1874 else if (just_this_one
&& !MINI_WINDOW_P (w
)
1876 && XFASTINT (w
->last_modified
)
1877 /* or else vmotion on first line won't work. */
1878 && ! NILP (w
->start_at_line_beg
)
1879 && ! EQ (w
->window_end_valid
, Qnil
)
1880 && do_id
&& !current_buffer
->clip_changed
1881 && !blank_end_of_window
1882 && WINDOW_FULL_WIDTH_P (w
)
1883 /* Can't use this case if highlighting a region. */
1884 && !(!NILP (Vtransient_mark_mode
)
1885 && !NILP (current_buffer
->mark_active
))
1886 /* Don't use try_window_id if newline
1887 doesn't display as the end of a line. */
1888 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
1889 && NILP (w
->region_showing
)
1890 && EQ (last_arrow_position
, Voverlay_arrow_position
)
1891 && EQ (last_arrow_string
, Voverlay_arrow_string
)
1892 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
1895 /* tem > 0 means success. tem == -1 means choose new start.
1896 tem == -2 means try again with same start,
1897 and nothing but whitespace follows the changed stuff.
1898 tem == 0 means try again with same start. */
1902 else if (startp
>= BEGV
&& startp
<= ZV
1904 /* Avoid starting at end of buffer. */
1905 #if 0 /* This change causes trouble for M-! finger & RET.
1906 It will have to be considered later. */
1907 || ! EQ (window
, selected_window
)
1908 /* Don't do the recentering if redisplay
1909 is not for no user action. */
1910 || preserve_echo_area
1913 || (XFASTINT (w
->last_modified
) >= MODIFF
1914 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
1916 /* Try to redisplay starting at same place as before */
1917 /* If point has not moved off frame, accept the results */
1918 try_window (window
, startp
);
1919 if (cursor_vpos
>= 0)
1921 if (!just_this_one
|| current_buffer
->clip_changed
1922 || beg_unchanged
< startp
)
1923 /* Forget any recorded base line for line number display. */
1924 w
->base_line_number
= Qnil
;
1928 cancel_my_columns (w
);
1931 XSETFASTINT (w
->last_modified
, 0);
1932 XSETFASTINT (w
->last_overlay_modified
, 0);
1933 /* Redisplay the mode line. Select the buffer properly for that. */
1934 if (!update_mode_line
)
1936 set_buffer_temp (old
);
1937 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1938 update_mode_line
= 1;
1939 w
->update_mode_line
= Qt
;
1942 /* Try to scroll by specified few lines */
1944 if (scroll_conservatively
&& !current_buffer
->clip_changed
1945 && startp
>= BEGV
&& startp
<= ZV
)
1947 int this_scroll_margin
= scroll_margin
;
1949 /* Don't use a scroll margin that is negative or too large. */
1950 if (this_scroll_margin
< 0)
1951 this_scroll_margin
= 0;
1953 if (XINT (w
->height
) < 4 * scroll_margin
)
1954 this_scroll_margin
= XINT (w
->height
) / 4;
1956 if (PT
>= Z
- XFASTINT (w
->window_end_pos
))
1958 struct position pos
;
1959 pos
= *compute_motion (Z
- XFASTINT (w
->window_end_pos
), 0, 0, 0,
1960 PT
, XFASTINT (w
->height
), 0,
1961 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
1962 pos_tab_offset (w
, startp
), w
);
1963 if (pos
.vpos
> scroll_conservatively
)
1966 pos
= *vmotion (startp
, pos
.vpos
+ 1 + this_scroll_margin
, w
);
1968 if (! NILP (Vwindow_scroll_functions
))
1970 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
1971 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1972 make_number (pos
.bufpos
));
1973 pos
.bufpos
= marker_position (w
->start
);
1975 try_window (window
, pos
.bufpos
);
1976 if (cursor_vpos
>= 0)
1978 if (!just_this_one
|| current_buffer
->clip_changed
1979 || beg_unchanged
< startp
)
1980 /* Forget any recorded base line for line number display. */
1981 w
->base_line_number
= Qnil
;
1985 cancel_my_columns (w
);
1989 struct position pos
;
1990 pos
= *compute_motion (PT
, 0, 0, 0,
1991 startp
, XFASTINT (w
->height
), 0,
1992 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
1993 pos_tab_offset (w
, startp
), w
);
1994 if (pos
.vpos
>= scroll_conservatively
)
1997 pos
= *vmotion (startp
, - pos
.vpos
- this_scroll_margin
, w
);
1999 if (! NILP (Vwindow_scroll_functions
))
2001 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2002 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2003 make_number (pos
.bufpos
));
2004 pos
.bufpos
= marker_position (w
->start
);
2006 try_window (window
, pos
.bufpos
);
2007 if (cursor_vpos
>= 0)
2009 if (!just_this_one
|| current_buffer
->clip_changed
2010 || beg_unchanged
< startp
)
2011 /* Forget any recorded base line for line number display. */
2012 w
->base_line_number
= Qnil
;
2016 cancel_my_columns (w
);
2021 if (scroll_step
&& !current_buffer
->clip_changed
2022 && startp
>= BEGV
&& startp
<= ZV
)
2026 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
2027 if (pos
.vpos
>= height
)
2031 pos
= *vmotion (startp
, (PT
< startp
? - scroll_step
: scroll_step
), w
);
2033 if (PT
>= pos
.bufpos
)
2035 if (! NILP (Vwindow_scroll_functions
))
2037 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2038 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2039 make_number (pos
.bufpos
));
2040 pos
.bufpos
= marker_position (w
->start
);
2042 try_window (window
, pos
.bufpos
);
2043 if (cursor_vpos
>= 0)
2045 if (!just_this_one
|| current_buffer
->clip_changed
2046 || beg_unchanged
< startp
)
2047 /* Forget any recorded base line for line number display. */
2048 w
->base_line_number
= Qnil
;
2052 cancel_my_columns (w
);
2057 /* Finally, just choose place to start which centers point */
2060 /* Forget any previously recorded base line for line number display. */
2061 w
->base_line_number
= Qnil
;
2063 pos
= *vmotion (PT
, - (height
/ 2), w
);
2064 /* Set startp here explicitly in case that helps avoid an infinite loop
2065 in case the window-scroll-functions functions get errors. */
2066 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2067 if (! NILP (Vwindow_scroll_functions
))
2069 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2070 make_number (pos
.bufpos
));
2071 pos
.bufpos
= marker_position (w
->start
);
2073 try_window (window
, pos
.bufpos
);
2075 startp
= marker_position (w
->start
);
2076 w
->start_at_line_beg
2077 = (startp
== BEGV
|| FETCH_BYTE (startp
- 1) == '\n') ? Qt
: Qnil
;
2080 if ((update_mode_line
2081 /* If window not full width, must redo its mode line
2082 if the window to its side is being redone */
2083 || (!just_this_one
&& !WINDOW_FULL_WIDTH_P (w
))
2084 || INTEGERP (w
->base_line_pos
)
2085 || (!NILP (w
->column_number_displayed
)
2086 && XFASTINT (w
->column_number_displayed
) != current_column ()))
2087 && height
!= XFASTINT (w
->height
))
2088 display_mode_line (w
);
2089 if (! line_number_displayed
2090 && ! BUFFERP (w
->base_line_pos
))
2092 w
->base_line_pos
= Qnil
;
2093 w
->base_line_number
= Qnil
;
2096 /* When we reach a frame's selected window, redo the frame's menu bar. */
2097 if (update_mode_line
2098 && (FRAME_WINDOW_P (f
)
2100 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2101 FRAME_EXTERNAL_MENU_BAR (f
)
2103 FRAME_MENU_BAR_LINES (f
) > 0
2105 : FRAME_MENU_BAR_LINES (f
) > 0)
2106 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
2107 display_menu_bar (w
);
2110 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2112 int start
, end
, whole
;
2114 /* Calculate the start and end positions for the current window.
2115 At some point, it would be nice to choose between scrollbars
2116 which reflect the whole buffer size, with special markers
2117 indicating narrowing, and scrollbars which reflect only the
2120 Note that minibuffers sometimes aren't displaying any text. */
2121 if (! MINI_WINDOW_P (w
)
2122 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
2125 start
= marker_position (w
->start
) - BEGV
;
2126 /* I don't think this is guaranteed to be right. For the
2127 moment, we'll pretend it is. */
2128 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
2130 if (end
< start
) end
= start
;
2131 if (whole
< (end
- start
)) whole
= end
- start
;
2134 start
= end
= whole
= 0;
2136 /* Indicate what this scroll bar ought to be displaying now. */
2137 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
2139 /* Note that we actually used the scroll bar attached to this window,
2140 so it shouldn't be deleted at the end of redisplay. */
2141 (*redeem_scroll_bar_hook
) (w
);
2144 BUF_PT (current_buffer
) = opoint
;
2145 if (update_mode_line
)
2146 set_buffer_internal_1 (old
);
2148 set_buffer_temp (old
);
2149 BUF_PT (current_buffer
) = lpoint
;
2152 /* Do full redisplay on one window, starting at position `pos'. */
2155 try_window (window
, pos
)
2159 register struct window
*w
= XWINDOW (window
);
2160 register int height
= window_internal_height (w
);
2161 register int vpos
= XFASTINT (w
->top
);
2162 register int last_text_vpos
= vpos
;
2163 FRAME_PTR f
= XFRAME (w
->frame
);
2164 int width
= window_internal_width (w
) - 1;
2165 struct position val
;
2167 /* POS should never be out of range! */
2168 if (pos
< XBUFFER (w
->buffer
)->begv
2169 || pos
> XBUFFER (w
->buffer
)->zv
)
2172 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2174 overlay_arrow_seen
= 0;
2175 zv_strings_seen
= 0;
2176 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2177 val
.ovstring_chars_done
= 0;
2178 val
.tab_offset
= pos_tab_offset (w
, pos
);
2180 while (--height
>= 0)
2182 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, val
.tab_offset
,
2183 val
.ovstring_chars_done
);
2184 /* The following code is omitted because we maintain tab_offset
2187 tab_offset
+= width
;
2188 if (val
.vpos
) tab_offset
= 0;
2191 if (pos
!= val
.bufpos
)
2194 #ifdef USE_TEXT_PROPERTIES
2195 Lisp_Object invis_prop
;
2196 invis_prop
= Fget_char_property (val
.bufpos
-1, Qinvisible
, window
);
2197 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
2201 /* Next line, unless prev line ended in end of buffer with no cr */
2203 && (FETCH_BYTE (val
.bufpos
- 1) != '\n' || invis
));
2208 /* If last line is continued in middle of character,
2209 include the split character in the text considered on the frame */
2210 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2213 /* If bottom just moved off end of frame, change mode line percentage. */
2214 if (XFASTINT (w
->window_end_pos
) == 0
2216 w
->update_mode_line
= Qt
;
2218 /* Say where last char on frame will be, once redisplay is finished. */
2219 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
2220 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
2221 /* But that is not valid info until redisplay finishes. */
2222 w
->window_end_valid
= Qnil
;
2225 /* Try to redisplay when buffer is modified locally,
2226 computing insert/delete line to preserve text outside
2227 the bounds of the changes.
2228 Return 1 if successful, 0 if if cannot tell what to do,
2229 or -1 to tell caller to find a new window start,
2230 or -2 to tell caller to do normal redisplay with same window start. */
2233 try_window_id (window
)
2237 register struct window
*w
= XWINDOW (window
);
2238 register int height
= window_internal_height (w
);
2239 FRAME_PTR f
= XFRAME (w
->frame
);
2240 int top
= XFASTINT (w
->top
);
2241 int start
= marker_position (w
->start
);
2242 int width
= window_internal_width (w
) - 1;
2243 int hscroll
= XINT (w
->hscroll
);
2244 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
2247 register int i
, tem
;
2248 int last_text_vpos
= 0;
2250 int selective
= (INTEGERP (current_buffer
->selective_display
)
2251 ? XINT (current_buffer
->selective_display
)
2252 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2254 struct position val
, bp
, ep
, xp
, pp
;
2255 int scroll_amount
= 0;
2259 if (GPT
- BEG
< beg_unchanged
)
2260 beg_unchanged
= GPT
- BEG
;
2261 if (Z
- GPT
< end_unchanged
)
2262 end_unchanged
= Z
- GPT
;
2264 if (beg_unchanged
+ BEG
< start
)
2265 return 0; /* Give up if changes go above top of window */
2267 /* Find position before which nothing is changed. */
2268 bp
= *compute_motion (start
, 0, lmargin
, 0,
2269 min (ZV
, beg_unchanged
+ BEG
), height
,
2270 /* BUG FIX: See the comment of
2271 Fpos_visible_in_window_p() (window.c). */
2272 - (1 << (BITS_PER_SHORT
- 1)),
2273 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2274 if (bp
.vpos
>= height
)
2278 /* All changes are beyond the window end, and point is on the screen.
2279 We don't need to change the text at all.
2280 But we need to update window_end_pos to account for
2281 any change in buffer size. */
2282 bp
= *compute_motion (start
, 0, lmargin
, 0,
2284 /* BUG FIX: See the comment of
2285 Fpos_visible_in_window_p() (window.c). */
2286 - (1 << (BITS_PER_SHORT
- 1)),
2287 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2288 XSETFASTINT (w
->window_end_vpos
, height
);
2289 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
2297 /* Find beginning of that frame line. Must display from there. */
2298 bp
= *vmotion (bp
.bufpos
, 0, w
);
2306 /* If about to start displaying at the beginning of a continuation line,
2307 really start with previous frame line, in case it was not
2308 continued when last redisplayed */
2309 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
2311 /* Likewise if we have to worry about selective display. */
2312 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
2314 bp
= *vmotion (bp
.bufpos
, -1, w
);
2318 val
.tab_offset
= bp
.tab_offset
; /* Update tab offset. */
2320 if (bp
.contin
&& bp
.hpos
!= lmargin
)
2322 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
2323 val
.tab_offset
= bp
.tab_offset
+ bp
.prevhpos
- width
;
2330 /* Find first visible newline after which no more is changed. */
2331 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
2333 while (tem
< ZV
- 1 && (indented_beyond_p (tem
, selective
)))
2334 tem
= find_next_newline (tem
, 1);
2336 /* Compute the cursor position after that newline. */
2337 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
2338 height
, - (1 << (BITS_PER_SHORT
- 1)),
2340 /* We have tab offset in VAL, use it. */
2343 /* If changes reach past the text available on the frame,
2344 just display rest of frame. */
2345 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
2348 stop_vpos
= ep
.vpos
;
2350 /* If no newline before ep, the line ep is on includes some changes
2351 that must be displayed. Make sure we don't stop before it. */
2352 /* Also, if changes reach all the way until ep.bufpos,
2353 it is possible that something was deleted after the
2354 newline before it, so the following line must be redrawn. */
2355 if (stop_vpos
== ep
.vpos
2356 && (ep
.bufpos
== BEGV
2357 || FETCH_BYTE (ep
.bufpos
- 1) != '\n'
2358 || ep
.bufpos
== Z
- end_unchanged
))
2359 stop_vpos
= ep
.vpos
+ 1;
2362 overlay_arrow_seen
= 0;
2363 zv_strings_seen
= 0;
2365 /* If changes do not reach to bottom of window,
2366 figure out how much to scroll the rest of the window */
2367 if (stop_vpos
< height
)
2369 /* Now determine how far up or down the rest of the window has moved */
2370 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2371 Z
- XFASTINT (w
->window_end_pos
),
2372 /* Don't care for VPOS... */
2373 1 << (BITS_PER_SHORT
- 1),
2375 1 << (BITS_PER_SHORT
- 1),
2376 width
, hscroll
, ep
.tab_offset
, w
);
2377 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2379 /* Is everything on frame below the changes whitespace?
2380 If so, no scrolling is really necessary. */
2381 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
2383 tem
= FETCH_BYTE (i
);
2384 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2390 XSETFASTINT (w
->window_end_vpos
,
2391 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2393 /* Before doing any scrolling, verify that point will be on frame. */
2394 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.vpos
< height
))
2396 if (PT
<= xp
.bufpos
)
2398 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2399 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2401 /* We have tab offset in EP, use it. */
2406 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2407 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2409 /* We have tab offset in XP, use it. */
2412 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2414 cursor_vpos
= pp
.vpos
+ top
;
2415 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, pp
.hpos
, width
);
2418 if (stop_vpos
- scroll_amount
>= height
2419 || ep
.bufpos
== xp
.bufpos
)
2421 if (scroll_amount
< 0)
2422 stop_vpos
-= scroll_amount
;
2424 /* In this path, we have altered window_end_vpos
2425 and not left it negative.
2426 We must make sure that, in case display is preempted
2427 before the frame changes to reflect what we do here,
2428 further updates will not come to try_window_id
2429 and assume the frame and window_end_vpos match. */
2430 blank_end_of_window
= 1;
2432 else if (!scroll_amount
)
2434 /* Even if we don't need to scroll, we must adjust the
2435 charstarts of subsequent lines (that we won't redisplay)
2436 according to the amount of text inserted or deleted. */
2437 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2438 int adjust
= ep
.bufpos
- oldpos
;
2439 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2441 else if (bp
.bufpos
== Z
- end_unchanged
)
2443 /* If reprinting everything is nearly as fast as scrolling,
2444 don't bother scrolling. Can happen if lines are short. */
2445 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2446 top
+ height
- max (0, scroll_amount
),
2448 > xp
.bufpos
- bp
.bufpos
- 20)
2449 /* Return "try normal display with same window-start."
2450 Too bad we can't prevent further scroll-thinking. */
2452 /* If pure deletion, scroll up as many lines as possible.
2453 In common case of killing a line, this can save the
2454 following line from being overwritten by scrolling
2455 and therefore having to be redrawn. */
2456 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2457 top
+ height
- max (0, scroll_amount
),
2458 scroll_amount
, bp
.bufpos
);
2463 /* scroll_frame_lines did not properly adjust subsequent
2464 lines' charstarts in the case where the text of the
2465 screen line at bp.vpos has changed.
2466 (This can happen in a deletion that ends in mid-line.)
2467 To adjust properly, we need to make things consistent
2469 So do a second adjust to make that happen.
2470 Note that stop_vpos >= ep.vpos, so it is sufficient
2471 to update the charstarts for lines at ep.vpos and below. */
2473 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2474 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2475 ep
.bufpos
- oldstart
);
2478 else if (scroll_amount
)
2480 /* If reprinting everything is nearly as fast as scrolling,
2481 don't bother scrolling. Can happen if lines are short. */
2482 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2483 overestimate of cost of reprinting, since xp.bufpos
2484 would end up below the bottom of the window. */
2485 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2486 top
+ height
- max (0, scroll_amount
),
2488 > xp
.bufpos
- ep
.bufpos
- 20)
2489 /* Return "try normal display with same window-start."
2490 Too bad we can't prevent further scroll-thinking. */
2492 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2493 top
+ height
- max (0, scroll_amount
),
2494 scroll_amount
, ep
.bufpos
);
2495 if (!tem
) stop_vpos
= height
;
2499 /* In any case, do not display past bottom of window */
2500 if (stop_vpos
>= height
)
2506 /* Handle case where pos is before w->start --
2507 can happen if part of line had been clipped and is not clipped now */
2508 if (vpos
== 0 && pos
< marker_position (w
->start
))
2509 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2511 /* Redisplay the lines where the text was changed */
2512 last_text_vpos
= vpos
;
2513 /* The following code is omitted because we maintain tab offset in
2516 tab_offset
= pos_tab_offset (w
, pos
);
2517 /* If we are starting display in mid-character, correct tab_offset
2518 to account for passing the line that that character really starts in. */
2519 if (val
.hpos
< lmargin
)
2520 tab_offset
+= width
;
2523 while (vpos
< stop_vpos
)
2525 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, val
.tab_offset
,
2526 val
.ovstring_chars_done
);
2527 /* If display_text_line ran a hook and changed some text,
2528 redisplay all the way to bottom of buffer
2529 So that we show the changes. */
2530 if (old_tick
!= MODIFF
)
2532 /* The following code is omitted because we maintain tab offset
2533 in val.tab_offset. */
2535 tab_offset
+= width
;
2536 if (val
.vpos
) tab_offset
= 0;
2538 if (pos
!= val
.bufpos
)
2540 /* Next line, unless prev line ended in end of buffer with no cr */
2541 = vpos
- (val
.vpos
&& FETCH_BYTE (val
.bufpos
- 1) != '\n');
2545 /* There are two cases:
2546 1) we have displayed down to the bottom of the window
2547 2) we have scrolled lines below stop_vpos by scroll_amount */
2551 /* If last line is continued in middle of character,
2552 include the split character in the text considered on the frame */
2553 if (val
.hpos
< lmargin
)
2555 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2556 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2559 /* If scrolling made blank lines at window bottom,
2560 redisplay to fill those lines */
2561 if (scroll_amount
< 0)
2563 /* Don't consider these lines for general-purpose scrolling.
2564 That will save time in the scrolling computation. */
2565 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2569 val
.tab_offset
= xp
.tab_offset
;
2571 { /* Display from next line */
2572 vpos
= height
+ scroll_amount
;
2576 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2578 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2579 val
.tab_offset
= xp
.tab_offset
+ bp
.prevhpos
- width
;
2583 blank_end_of_window
= 1;
2584 /* The following code is omitted because we maintain tab offset
2585 in val.tab_offset. */
2587 tab_offset
= pos_tab_offset (w
, pos
);
2588 /* If we are starting display in mid-character, correct tab_offset
2589 to account for passing the line that that character starts in. */
2590 if (val
.hpos
< lmargin
)
2591 tab_offset
+= width
;
2593 while (vpos
< height
)
2595 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
,
2596 val
.tab_offset
, val
.ovstring_chars_done
);
2597 /* The following code is omitted because we maintain tab
2598 offset in val.tab_offset. */
2600 tab_offset
+= width
;
2601 if (val
.vpos
) tab_offset
= 0;
2606 /* Here is a case where display_text_line sets cursor_vpos wrong.
2607 Make it be fixed up, below. */
2613 /* If bottom just moved off end of frame, change mode line percentage. */
2614 if (XFASTINT (w
->window_end_pos
) == 0
2616 w
->update_mode_line
= Qt
;
2618 /* Attempt to adjust end-of-text positions to new bottom line */
2621 delta
= height
- xp
.vpos
;
2623 || (delta
> 0 && xp
.bufpos
<= ZV
)
2624 || (delta
== 0 && xp
.hpos
))
2626 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
2627 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2628 XSETFASTINT (w
->window_end_vpos
,
2629 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
2633 w
->window_end_valid
= Qnil
;
2635 /* If point was not in a line that was displayed, find it */
2636 if (cursor_vpos
< 0)
2639 val
= *compute_motion (start
, 0, lmargin
, 0, PT
,
2640 /* Don't care for VPOS... */
2641 1 << (BITS_PER_SHORT
- 1),
2643 1 << (BITS_PER_SHORT
- 1),
2644 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2645 /* Admit failure if point is off frame now */
2646 if (val
.vpos
>= height
)
2648 for (vpos
= 0; vpos
< height
; vpos
++)
2649 cancel_line (vpos
+ top
, f
);
2652 cursor_vpos
= val
.vpos
+ top
;
2653 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, val
.hpos
, width
);
2656 FRAME_CURSOR_X (f
) = cursor_hpos
;
2657 FRAME_CURSOR_Y (f
) = cursor_vpos
;
2661 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
2662 height
, - (1 << (BITS_PER_SHORT
- 1)),
2663 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2664 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
2666 if (XFASTINT (w
->window_end_pos
)
2674 /* Copy LEN glyphs starting address FROM to the rope TO.
2675 But don't actually copy the parts that would come in before S.
2676 Value is TO, advanced past the copied data.
2677 F is the frame we are displaying in. */
2680 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
2682 register GLYPH
*to
; /* Copy to here. */
2683 register GLYPH
*s
; /* Starting point. */
2684 Lisp_Object
*from
; /* Data to copy. */
2686 int face
; /* Face to apply to glyphs which don't specify one. */
2689 register Lisp_Object
*fp
= from
;
2690 /* These cache the results of the last call to compute_glyph_face. */
2692 int last_merged
= 0;
2695 if (! FRAME_TERMCAP_P (f
))
2698 GLYPH glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2700 unsigned int c
= FAST_GLYPH_CHAR (glyph
);
2703 /* For an invalid character code, use space. */
2706 if (FAST_GLYPH_FACE (glyph
) == 0)
2707 /* If GLYPH has no face code, use FACE. */
2709 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
2710 /* If it's same as previous glyph, use same result. */
2711 facecode
= last_merged
;
2714 /* Merge this glyph's face and remember the result. */
2715 last_code
= FAST_GLYPH_FACE (glyph
);
2716 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
2720 *to
= FAST_MAKE_GLYPH (c
, facecode
);
2728 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2735 /* Correct a glyph by replacing its specified user-level face code
2736 with a displayable computed face code. */
2739 fix_glyph (f
, glyph
, cface
)
2745 if (! FRAME_TERMCAP_P (f
))
2747 if (FAST_GLYPH_FACE (glyph
) != 0)
2748 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
2749 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
2755 /* Display one line of window W, starting at position START in W's buffer.
2757 Display starting at horizontal position HPOS, expressed relative to
2758 W's left edge. In situations where the text at START shouldn't
2759 start at the left margin (i.e. when the window is hscrolled, or
2760 we're continuing a line which left off in the midst of a
2761 multi-column character), HPOS should be negative; we throw away
2762 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2765 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2767 OVSTR_DONE is the number of chars of overlay before/after strings
2768 at this position which have already been processed.
2770 Display on position VPOS on the frame. It is origin 0, relative to
2771 the top of the frame, not W.
2773 Returns a STRUCT POSITION giving character to start next line with
2774 and where to display it, including a zero or negative hpos.
2775 The vpos field is not really a vpos; it is 1 unless the line is continued */
2777 struct position val_display_text_line
;
2779 static struct position
*
2780 display_text_line (w
, start
, vpos
, hpos
, taboffset
, ovstr_done
)
2788 register int pos
= start
;
2792 register unsigned char *p
;
2794 register GLYPH
*leftmargin
;
2795 register GLYPH
*p1prev
;
2796 register GLYPH
*p1start
;
2799 FRAME_PTR f
= XFRAME (w
->frame
);
2800 int tab_width
= XINT (current_buffer
->tab_width
);
2801 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
2802 int width
= window_internal_width (w
) - 1;
2803 struct position val
;
2806 int last_invis_skip
= 0;
2807 Lisp_Object last_invis_prop
;
2808 int hscroll
= XINT (w
->hscroll
);
2809 int truncate
= (hscroll
2810 || (truncate_partial_width_windows
2811 && !WINDOW_FULL_WIDTH_P (w
))
2812 || !NILP (current_buffer
->truncate_lines
));
2814 /* 1 if we should highlight the region. */
2815 int highlight_region
2816 = (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
)
2817 && (XWINDOW (current_buffer
->last_selected_window
) == w
2818 || highlight_nonselected_windows
));
2819 int region_beg
, region_end
;
2821 int selective
= (INTEGERP (current_buffer
->selective_display
)
2822 ? XINT (current_buffer
->selective_display
)
2823 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2824 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
2825 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
2827 Lisp_Object default_invis_vector
[3];
2828 /* Number of characters of ellipsis to display after an invisible line
2829 if it calls for an ellipsis.
2830 Note that this value can be nonzero regardless of whether
2831 selective display is enabled--you must check that separately. */
2833 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2834 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
2835 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
2836 /* This is the sequence of Lisp objects to display
2837 when there are invisible lines. */
2838 Lisp_Object
*invis_vector_contents
2839 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2840 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
2841 : default_invis_vector
);
2843 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
2844 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp
)))
2845 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
2846 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
2847 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp
)))
2848 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
2850 /* If 1, we must handle multibyte characters. */
2851 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
2852 /* Length of multibyte form of each character. */
2854 /* Glyphs generated should be set this bit mask if text must be
2855 displayed from right to left. */
2856 GLYPH rev_dir_bit
= (NILP (current_buffer
->direction_reversed
)
2857 ? 0 : GLYPH_MASK_REV_DIR
);
2859 /* The next buffer location at which the face should change, due
2860 to overlays or text property changes. */
2861 int next_face_change
;
2863 /* The next location where the `invisible' property changes, or an
2864 overlay starts or ends. */
2867 /* The face we're currently using. */
2868 int current_face
= 0;
2871 XSETFASTINT (default_invis_vector
[2], '.');
2872 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
2874 hpos
+= WINDOW_LEFT_MARGIN (w
);
2875 get_display_line (f
, vpos
, WINDOW_LEFT_MARGIN (w
));
2876 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
2878 /* Show where to highlight the region. */
2879 if (highlight_region
&& XMARKER (current_buffer
->mark
)->buffer
!= 0
2880 /* Maybe highlight only in selected window. */
2881 && (highlight_nonselected_windows
2882 || w
== XWINDOW (selected_window
)))
2884 region_beg
= marker_position (current_buffer
->mark
);
2885 if (PT
< region_beg
)
2887 region_end
= region_beg
;
2892 w
->region_showing
= Qt
;
2896 region_beg
= region_end
= -1;
2897 w
->region_showing
= Qnil
;
2900 if (MINI_WINDOW_P (w
)
2902 && vpos
== XFASTINT (w
->top
))
2904 if (! NILP (minibuf_prompt
))
2906 minibuf_prompt_width
2907 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
2908 XSTRING (minibuf_prompt
)->size
, hpos
,
2909 /* Display a space if we truncate. */
2912 /* Truncate the prompt a little before the
2913 margin, so user input can at least start
2914 on the first line. */
2915 (XFASTINT (w
->width
) > 10
2916 ? XFASTINT (w
->width
) - 4 : -1))
2918 hpos
+= minibuf_prompt_width
;
2919 taboffset
-= minibuf_prompt_width
;
2922 minibuf_prompt_width
= 0;
2925 /* If we're hscrolled at all, use compute_motion to skip over any
2926 text off the left edge of the window. compute_motion may know
2927 tricks to do this faster than we can. */
2930 struct position
*left_edge
2931 = compute_motion (pos
, vpos
, hpos
, 0,
2933 width
, hscroll
, taboffset
, w
);
2935 /* Retrieve the buffer position and column provided by
2936 compute_motion. We can't assume that the column will be
2937 zero, because you may have multi-column characters crossing
2940 compute_motion may have moved us past the screen position we
2941 requested, if we hit a multi-column character, or the end of
2942 the line. If so, back up. */
2943 if (left_edge
->vpos
> vpos
2944 || left_edge
->hpos
> 0)
2946 pos
= left_edge
->bufpos
;
2947 /* Since this should not be a valid multibyte character, we
2948 can decrease POS by 1. */
2950 hpos
= left_edge
->prevhpos
;
2954 pos
= left_edge
->bufpos
;
2955 hpos
= left_edge
->hpos
;
2959 desired_glyphs
->bufp
[vpos
] = start
;
2960 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2962 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
2963 /* In case we don't ever write anything into it... */
2964 desired_glyphs
->charstarts
[vpos
][WINDOW_LEFT_MARGIN (w
)] = -1;
2965 leftmargin
= desired_glyphs
->glyphs
[vpos
] + WINDOW_LEFT_MARGIN (w
);
2966 endp
= leftmargin
+ width
;
2968 /* Arrange the overlays nicely for our purposes. Usually, we call
2969 display_text_line on only one line at a time, in which case this
2970 can't really hurt too much, or we call it on lines which appear
2971 one after another in the buffer, in which case all calls to
2972 recenter_overlay_lists but the first will be pretty cheap. */
2973 recenter_overlay_lists (current_buffer
, pos
);
2975 /* Loop generating characters.
2976 Stop at end of buffer, before newline,
2977 if reach or pass continuation column,
2978 or at face change. */
2980 next_face_change
= pos
;
2981 next_boundary
= pos
;
2990 while (pos
== next_boundary
)
2992 Lisp_Object position
, limit
, prop
, ww
;
2994 /* Display the overlay strings here, unless we're at ZV
2995 and have already displayed the appropriate strings
2996 on an earlier line. */
2997 if (pos
< ZV
|| !zv_strings_seen
++)
3000 unsigned char *ovstr
;
3001 ovlen
= overlay_strings (pos
, w
, &ovstr
);
3005 /* Skip the ones we did in a previous line. */
3006 ovstr
+= ovstr_done
;
3007 ovlen
-= ovstr_done
;
3016 c
= STRING_CHAR_AND_LENGTH (ovstr
, ovlen
, len
);
3017 ovstr
+= len
, ovlen
-= len
, ovstr_done
+= len
;
3018 charset
= CHAR_CHARSET (c
);
3019 cols
= (charset
== CHARSET_COMPOSITION
3020 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3021 : CHARSET_WIDTH (charset
));
3025 c
= *ovstr
++, ovlen
--, ovstr_done
++;
3028 g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3031 if (p1
>= leftmargin
&& p1
< endp
)
3032 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3036 /* If we did all the overlay strings
3037 and we have room for text, clear ovstr_done
3038 just for neatness' sake. */
3039 if (ovlen
== 0 && p1
< endp
)
3044 /* Did we reach point? Record the cursor location. */
3045 if (pos
== PT
&& cursor_vpos
< 0)
3048 cursor_hpos
= p1
- leftmargin
;
3054 XSETFASTINT (position
, pos
);
3055 limit
= Fnext_overlay_change (position
);
3056 #ifdef USE_TEXT_PROPERTIES
3057 /* This is just an estimate to give reasonable
3058 performance; nothing should go wrong if it is too small. */
3059 if (XFASTINT (limit
) > pos
+ 50)
3061 int limitpos
= pos
+ 50;
3063 INC_POS (limitpos
); /* Adjust to character boundary. */
3064 XSETFASTINT (limit
, limitpos
);
3066 limit
= Fnext_single_property_change (position
, Qinvisible
,
3067 Fcurrent_buffer (), limit
);
3069 next_boundary
= XFASTINT (limit
);
3070 /* if the `invisible' property is set, we can skip to
3071 the next property change. */
3073 prop
= Fget_char_property (position
, Qinvisible
, ww
);
3074 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3076 if (pos
< PT
&& next_boundary
>= PT
)
3079 cursor_hpos
= p1
- leftmargin
;
3081 pos
= next_boundary
;
3082 last_invis_skip
= pos
;
3083 last_invis_prop
= prop
;
3087 /* Did we reach point? Record the cursor location. */
3088 if (pos
== PT
&& cursor_vpos
< 0)
3091 cursor_hpos
= p1
- leftmargin
;
3094 /* Did we hit the end of the visible region of the buffer?
3098 /* Update charstarts for the end of this line. */
3099 /* Do nothing if off the left edge or at the right edge. */
3100 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
3102 int *p2x
= &charstart
[(p1
< leftmargin
3110 /* Figure out where (if at all) the
3111 redisplay_end_trigger-hook should run. */
3112 if (MARKERP (w
->redisplay_end_trigger
)
3113 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
3114 e_t_h
= marker_position (w
->redisplay_end_trigger
);
3115 else if (INTEGERP (w
->redisplay_end_trigger
))
3116 e_t_h
= XINT (w
->redisplay_end_trigger
);
3120 /* If we've gone past the place to run a hook,
3122 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
3124 Lisp_Object args
[3];
3126 args
[0] = Qredisplay_end_trigger_functions
;
3127 XSETWINDOW (args
[1], w
);
3128 XSETINT (args
[2], e_t_h
);
3130 /* Since we are *trying* to run these functions,
3131 don't try to run them again, even if they get an error. */
3132 w
->redisplay_end_trigger
= Qnil
;
3133 Frun_hook_with_args (3, args
);
3136 /* Notice if it changed the face of this character. */
3137 next_face_change
= pos
;
3141 /* Did we hit a face change? Figure out what face we should
3142 use now. We also hit this the first time through the
3143 loop, to see what face we should start with. */
3144 if (pos
>= next_face_change
3145 && (FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
)))
3147 int limit
= pos
+ 50;
3149 if (limit
< Z
&& !CHAR_HEAD_P (POS_ADDR (limit
)))
3150 INC_POS (limit
); /* Adjust to character boundary. */
3151 current_face
= compute_char_face (f
, w
, pos
,
3152 region_beg
, region_end
,
3153 &next_face_change
, limit
, 0);
3157 /* Compute the next place we need to stop
3158 and do something special; set PAUSE. */
3162 if (pos
< next_boundary
&& next_boundary
< pause
)
3163 pause
= next_boundary
;
3164 if (pos
< next_face_change
&& next_face_change
< pause
)
3165 pause
= next_face_change
;
3170 /* Wouldn't you hate to read the next line to someone over
3172 if (pos
< PT
&& PT
< pause
)
3174 if (pos
< GPT
&& GPT
< pause
)
3186 /* PAUSE is surely at character boundary. */
3187 c
= STRING_CHAR_AND_LENGTH (p
, pause
- pos
, len
), p
+= len
;
3190 /* Let a display table override all standard display methods. */
3191 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3193 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
3194 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3195 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3196 current_face
, rev_dir_bit
);
3198 else if (c
>= 040 && c
< 0177)
3200 if (p1
>= leftmargin
)
3201 *p1
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3207 /* Same as p1prev, but after the invis_vector_contents text
3208 (if we have that on this line). */
3209 GLYPH
*p1prev_modified
;
3213 if (last_invis_skip
== pos
3214 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
3218 && indented_beyond_p (pos
+ 1, selective
))
3221 pos
= find_next_newline (pos
+ 1, 1);
3222 if (FETCH_BYTE (pos
- 1) == '\n')
3225 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
3230 cs
= charstart
+ (p1
- p1start
);
3233 p1
+= selective_rlen
;
3234 if (p1
- leftmargin
> width
)
3237 #if 0 /* This needs more work; charstarts needs to record
3238 both whether a position ho;ds an ellipsis character
3239 and what buffer position it corresponds to. */
3240 csend
= charstart
+ (p1
- p1start
);
3243 /* The idea is to use p1prev_modified instead of p1prev
3244 in the loop below over p2x. */
3245 p1prev_modified
= p1
;
3248 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3249 (p1
- p1prev
), current_face
, rev_dir_bit
);
3252 /* Update charstarts for the newline that ended this line. */
3253 /* Do nothing here for a char that's entirely off the left edge
3254 or if it starts at the right edge. */
3255 if (p1
>= leftmargin
&& p1prev
!= endp
)
3257 /* Store the newline's position into charstarts
3258 for the column where the newline starts.
3259 Store -1 for the rest of the glyphs it occupies. */
3260 int *p2x
= &charstart
[(p1prev
< leftmargin
3261 ? leftmargin
: p1prev
)
3263 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3270 /* Draw the face of the newline character as extending all the
3271 way to the end of the frame line. */
3274 if (p1
< leftmargin
)
3277 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3287 if (p1
>= leftmargin
&& p1
< endp
)
3288 *p1
= MAKE_GLYPH (f
, ' ', current_face
) | rev_dir_bit
;
3291 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
3294 else if (c
== Ctl ('M') && selective
== -1)
3296 pos
= find_next_newline (pos
, 1);
3297 if (FETCH_BYTE (pos
- 1) == '\n')
3299 if (selective_rlen
> 0)
3301 p1
+= selective_rlen
;
3302 if (p1
- leftmargin
> width
)
3304 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3305 (p1
- p1prev
), current_face
, rev_dir_bit
);
3308 /* Draw the face of the newline character as extending all the
3309 way to the end of the frame line. */
3312 if (p1
< leftmargin
)
3315 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3319 /* Update charstarts for the ^M that ended this line. */
3320 /* Do nothing here for a char that's entirely off the left edge
3321 or if it starts at the right edge. */
3322 if (p1
>= leftmargin
&& p1prev
!= endp
)
3324 /* Store the newline's position into charstarts
3325 for the column where the newline starts.
3326 Store -1 for the rest of the glyphs it occupies. */
3327 int *p2x
= &charstart
[(p1prev
< leftmargin
3328 ? leftmargin
: p1prev
)
3330 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3338 else if (c
< 0200 && ctl_arrow
)
3340 if (p1
>= leftmargin
)
3342 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3343 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
3344 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3348 if (p1
>= leftmargin
&& p1
< endp
)
3349 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
) | rev_dir_bit
;
3354 /* C is not a multibyte character. */
3355 if (p1
>= leftmargin
)
3357 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3358 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
3359 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3363 if (p1
>= leftmargin
&& p1
< endp
)
3364 *p1
= MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
) | rev_dir_bit
;
3366 if (p1
>= leftmargin
&& p1
< endp
)
3367 *p1
= (MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
)
3370 if (p1
>= leftmargin
&& p1
< endp
)
3371 *p1
= MAKE_GLYPH (f
, (7 & c
) + '0', current_face
) | rev_dir_bit
;
3376 /* C is a multibyte character. */
3377 int charset
= CHAR_CHARSET (c
);
3378 int columns
= (charset
== CHARSET_COMPOSITION
3379 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3380 : CHARSET_WIDTH (charset
));
3381 GLYPH g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3385 if (p1
>= leftmargin
&& p1
< endp
)
3386 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3394 /* Update charstarts for the character just output. */
3396 /* Do nothing here for a char that's entirely off the left edge. */
3397 if (p1
>= leftmargin
)
3399 /* Store the char's position into charstarts
3400 for the first glyph occupied by this char.
3401 Store -1 for the rest of the glyphs it occupies. */
3404 int *p2x
= &charstart
[(p1prev
< leftmargin
3405 ? leftmargin
: p1prev
)
3407 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3417 val
.hpos
= - XINT (w
->hscroll
);
3425 /* Store 0 in this charstart line for the positions where
3426 there is no character. But do leave what was recorded
3427 for the character that ended the line. */
3428 /* Add 1 in the endtest to compensate for the fact that ENDP was
3429 made from WIDTH, which is 1 less than the window's actual
3431 i
= p1
- p1start
+ 1;
3432 if (p1
< leftmargin
)
3433 i
+= leftmargin
- p1
;
3434 for (; i
< endp
- p1start
+ 1; i
++)
3437 /* Handle continuation in middle of a character */
3438 /* by backing up over it */
3441 /* Don't back up if we never actually displayed any text.
3442 This occurs when the minibuffer prompt takes up the whole line. */
3445 /* Start the next line with that same character whose
3446 character code is C and the length of multi-byte form is
3451 /* C is not a multi-byte character. We can break it and
3452 start from the middle column in the next line. So,
3453 adjust VAL.HPOS to skip the columns output on this
3455 val
.hpos
+= p1prev
- endp
;
3458 /* C is a multibyte character. Since we can't broke it
3459 in the middle, the whole character should be driven
3460 into the next line. */
3461 /* As the result, the actual columns occupied by the
3462 text on this line is less than WIDTH. VAL.TAB_OFFSET
3463 must be adjusted. */
3464 taboffset
= taboffset
+ (p1prev
- endp
);
3465 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3467 GLYPH g
= fix_glyph (f
, truncate
? truncator
: continuer
, 0);
3468 while (p1prev
< endp
)
3471 /* If POINT is at POS, cursor should not on this line. */
3478 /* Keep in this line everything up to the continuation column. */
3482 /* Finish deciding which character to start the next line on,
3483 and what hpos to start it at.
3484 Also set `lastpos' to the last position which counts as "on this line"
3485 for cursor-positioning. */
3489 if (FETCH_BYTE (pos
) == '\n')
3491 /* If stopped due to a newline, start next line after it */
3494 /* Check again for hidden lines, in case the newline occurred exactly
3495 at the right margin. */
3496 while (pos
< ZV
&& selective
> 0
3497 && indented_beyond_p (pos
, selective
))
3498 pos
= find_next_newline (pos
, 1);
3501 /* Stopped due to right margin of window */
3505 *p1
++ = fix_glyph (f
, truncator
, 0);
3506 /* Truncating => start next line after next newline,
3507 and point is on this line if it is before the newline,
3508 and skip none of first char of next line */
3510 pos
= find_next_newline (pos
, 1);
3511 while (pos
< ZV
&& selective
> 0
3512 && indented_beyond_p (pos
, selective
));
3513 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
3515 lastpos
= pos
- (FETCH_BYTE (pos
- 1) == '\n');
3520 *p1
++ = fix_glyph (f
, continuer
, 0);
3523 val
.tab_offset
= taboffset
+ width
;
3530 /* If point is at eol or in invisible text at eol,
3531 record its frame location now. */
3533 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
3536 cursor_hpos
= p1
- leftmargin
;
3539 if (cursor_vpos
== vpos
)
3541 if (cursor_hpos
< 0) cursor_hpos
= 0;
3542 if (cursor_hpos
> width
) cursor_hpos
= width
;
3543 cursor_hpos
+= WINDOW_LEFT_MARGIN (w
);
3544 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
3546 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
3547 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
3549 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3550 FRAME_CURSOR_X (f
) = cursor_hpos
;
3553 if (w
== XWINDOW (selected_window
))
3555 /* Line is not continued and did not start
3556 in middle of character */
3557 if ((hpos
- WINDOW_LEFT_MARGIN (w
)
3558 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
3561 this_line_bufpos
= start
;
3562 this_line_buffer
= current_buffer
;
3563 this_line_vpos
= cursor_vpos
;
3564 this_line_start_hpos
= hpos
;
3565 this_line_endpos
= Z
- lastpos
;
3568 this_line_bufpos
= 0;
3573 /* If hscroll and line not empty, insert truncation-at-left marker */
3574 if (hscroll
&& lastpos
!= start
)
3576 GLYPH g
= fix_glyph (f
, truncator
, 0);
3578 if (p1
<= leftmargin
)
3579 p1
= leftmargin
+ 1;
3580 else /* MULE: it may be a wide-column character */
3582 p1prev
= leftmargin
+ 1;
3583 while (p1prev
< p1
&& *p1prev
& GLYPH_MASK_PADDING
)
3588 if (!WINDOW_RIGHTMOST_P (w
))
3591 if (p1
< leftmargin
) p1
= leftmargin
;
3592 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
3594 /* Don't draw vertical bars if we're using scroll bars. They're
3595 covered up by the scroll bars, and it's distracting to see
3596 them when the scroll bar windows are flickering around to be
3598 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
3601 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
3604 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3605 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
3606 ? XINT (DISP_BORDER_GLYPH (dp
))
3609 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
3610 p1
- desired_glyphs
->glyphs
[vpos
]);
3611 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
3613 /* If the start of this line is the overlay arrow-position,
3614 then put the arrow string into the display-line. */
3616 if (MARKERP (Voverlay_arrow_position
)
3617 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
3618 && start
== marker_position (Voverlay_arrow_position
)
3619 && STRINGP (Voverlay_arrow_string
)
3620 && ! overlay_arrow_seen
)
3622 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
3624 int len
= XSTRING (Voverlay_arrow_string
)->size
;
3630 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string
)->intervals
))
3632 /* If the arrow string has text props, obey them when displaying. */
3633 for (i
= 0; i
< len
; i
++)
3636 Lisp_Object face
, ilisp
;
3639 XSETFASTINT (ilisp
, i
);
3640 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
3641 newface
= compute_glyph_face_1 (f
, face
, 0);
3642 leftmargin
[i
] = FAST_MAKE_GLYPH (c
, newface
);
3646 #endif /* HAVE_FACES */
3648 for (i
= 0; i
< len
; i
++)
3649 leftmargin
[i
] = p
[i
];
3652 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3653 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
3654 if (desired_glyphs
->used
[vpos
] < arrow_end
)
3655 desired_glyphs
->used
[vpos
] = arrow_end
;
3657 overlay_arrow_seen
= 1;
3661 val
.ovstring_chars_done
= ovstr_done
;
3662 val_display_text_line
= val
;
3663 return &val_display_text_line
;
3666 /* Redisplay the menu bar in the frame for window W. */
3669 display_menu_bar (w
)
3672 Lisp_Object items
, tail
;
3673 register int vpos
= 0;
3674 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3675 int maxendcol
= FRAME_WIDTH (f
);
3680 if (!NILP (Vwindow_system
))
3684 #ifdef USE_X_TOOLKIT
3687 #endif /* USE_X_TOOLKIT */
3689 get_display_line (f
, vpos
, 0);
3691 items
= FRAME_MENU_BAR_ITEMS (f
);
3692 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
3694 Lisp_Object pos
, string
;
3695 string
= XVECTOR (items
)->contents
[i
+ 1];
3699 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], hpos
);
3701 if (hpos
< maxendcol
)
3702 hpos
= display_string (w
, vpos
,
3703 XSTRING (string
)->data
,
3704 XSTRING (string
)->size
,
3705 hpos
, 0, 0, hpos
, maxendcol
);
3706 /* Put a space between items. */
3707 if (hpos
< maxendcol
)
3709 int hpos1
= hpos
+ 1;
3710 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
3711 min (hpos1
, maxendcol
), maxendcol
);
3715 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3716 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3718 /* Fill out the line with spaces. */
3719 if (maxendcol
> hpos
)
3720 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
);
3722 /* Clear the rest of the lines allocated to the menu bar. */
3724 while (vpos
< FRAME_MENU_BAR_LINES (f
))
3725 get_display_line (f
, vpos
++, 0);
3728 /* Display the mode line for window w */
3731 display_mode_line (w
)
3734 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
3735 register int left
= WINDOW_LEFT_MARGIN (w
);
3736 register int right
= WINDOW_RIGHT_MARGIN (w
);
3737 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3739 line_number_displayed
= 0;
3740 w
->column_number_displayed
= Qnil
;
3742 get_display_line (f
, vpos
, left
);
3744 /* Temporarily make frame F's kboard the current kboard
3745 so that kboard-local variables in the mode_line_format
3746 will get the right values. */
3747 push_frame_kboard (f
);
3749 display_mode_element (w
, vpos
, left
, 0, right
, right
,
3750 current_buffer
->mode_line_format
);
3752 pop_frame_kboard ();
3754 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3756 /* Put the mode line in inverse video.
3757 Use faces if possible, since that lets us handle
3758 partial-width windows and avoid inverting the scroll bar columns. */
3760 if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
3762 /* For a partial width window, explicitly set face of each glyph. */
3764 unsigned int padding
;
3765 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
3766 for (i
= left
; i
< right
; ++i
)
3768 padding
= ptr
[i
] & GLYPH_MASK_PADDING
;
3769 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1) | padding
;
3775 /* Make the mode line inverse video if the entire line
3776 is made of mode lines.
3777 I.e. if this window is full width,
3778 or if it is the child of a full width window
3779 (which implies that that window is split side-by-side
3780 and the rest of this line is mode lines of the sibling windows). */
3781 if (WINDOW_FULL_WIDTH_P (w
)
3782 || WINDOW_FULL_WIDTH_P (XWINDOW (w
->parent
)))
3783 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3786 /* Contribute ELT to the mode line for window W.
3787 How it translates into text depends on its data type.
3789 VPOS is the position of the mode line being displayed.
3791 HPOS is the position (absolute on frame) where this element's text
3792 should start. The output is truncated automatically at the right
3795 DEPTH is the depth in recursion. It is used to prevent
3796 infinite recursion here.
3798 MINENDCOL is the hpos before which the element may not end.
3799 The element is padded at the right with spaces if nec
3800 to reach this column.
3802 MAXENDCOL is the hpos past which this element may not extend.
3803 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3804 (This is necessary to make nested padding and truncation work.)
3806 Returns the hpos of the end of the text generated by ELT.
3807 The next element will receive that value as its HPOS arg,
3808 so as to concatenate the elements. */
3811 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
3813 register int vpos
, hpos
;
3816 register int maxendcol
;
3817 register Lisp_Object elt
;
3825 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
3829 /* A string: output it and check for %-constructs within it. */
3830 register unsigned char c
;
3831 register unsigned char *this = XSTRING (elt
)->data
;
3833 while (hpos
< maxendcol
&& *this)
3835 unsigned char *last
= this;
3836 while ((c
= *this++) != '\0' && c
!= '%')
3838 if (this - 1 != last
)
3840 register int lim
= --this - last
+ hpos
;
3841 if (frame_title_ptr
)
3842 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
3844 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
3845 hpos
, min (lim
, maxendcol
));
3849 register int minendcol
;
3850 register int spec_width
= 0;
3852 /* We can't allow -ve args due to the "%-" construct */
3853 /* Argument specifies minwidth but not maxwidth
3854 (maxwidth can be specified by
3855 (<negative-number> . <stuff>) mode-line elements) */
3857 while ((c
= *this++) >= '0' && c
<= '9')
3859 spec_width
= spec_width
* 10 + (c
- '0');
3862 minendcol
= hpos
+ spec_width
;
3863 if (minendcol
> maxendcol
)
3865 spec_width
= maxendcol
- hpos
;
3866 minendcol
= maxendcol
;
3870 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
3871 spec_width
, maxendcol
,
3872 Vglobal_mode_string
);
3875 char *spec
= decode_mode_spec (w
, c
, spec_width
,
3877 if (frame_title_ptr
)
3878 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
3880 hpos
= display_string (w
, vpos
, spec
, -1,
3882 minendcol
, maxendcol
);
3890 /* A symbol: process the value of the symbol recursively
3891 as if it appeared here directly. Avoid error if symbol void.
3892 Special case: if value of symbol is a string, output the string
3895 register Lisp_Object tem
;
3896 tem
= Fboundp (elt
);
3899 tem
= Fsymbol_value (elt
);
3900 /* If value is a string, output that string literally:
3901 don't check for % within it. */
3904 if (frame_title_ptr
)
3905 hpos
= store_frame_title (XSTRING (tem
)->data
,
3906 minendcol
, maxendcol
);
3908 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
3909 XSTRING (tem
)->size
,
3910 hpos
, 0, 1, minendcol
, maxendcol
);
3912 /* Give up right away for nil or t. */
3913 else if (!EQ (tem
, elt
))
3914 { elt
= tem
; goto tail_recurse
; }
3921 register Lisp_Object car
, tem
;
3923 /* A cons cell: three distinct cases.
3924 If first element is a string or a cons, process all the elements
3925 and effectively concatenate them.
3926 If first element is a negative number, truncate displaying cdr to
3927 at most that many characters. If positive, pad (with spaces)
3928 to at least that many characters.
3929 If first element is a symbol, process the cadr or caddr recursively
3930 according to whether the symbol's value is non-nil or nil. */
3931 car
= XCONS (elt
)->car
;
3934 tem
= Fboundp (car
);
3935 elt
= XCONS (elt
)->cdr
;
3938 /* elt is now the cdr, and we know it is a cons cell.
3939 Use its car if CAR has a non-nil value. */
3942 tem
= Fsymbol_value (car
);
3944 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
3946 /* Symbol's value is nil (or symbol is unbound)
3947 Get the cddr of the original list
3948 and if possible find the caddr and use that. */
3949 elt
= XCONS (elt
)->cdr
;
3952 else if (!CONSP (elt
))
3954 elt
= XCONS (elt
)->car
;
3957 else if (INTEGERP (car
))
3959 register int lim
= XINT (car
);
3960 elt
= XCONS (elt
)->cdr
;
3962 /* Negative int means reduce maximum width.
3963 DO NOT change MINENDCOL here!
3964 (20 -10 . foo) should truncate foo to 10 col
3965 and then pad to 20. */
3966 maxendcol
= min (maxendcol
, hpos
- lim
);
3969 /* Padding specified. Don't let it be more than
3972 if (lim
> maxendcol
)
3974 /* If that's more padding than already wanted, queue it.
3975 But don't reduce padding already specified even if
3976 that is beyond the current truncation point. */
3977 if (lim
> minendcol
)
3982 else if (STRINGP (car
) || CONSP (car
))
3984 register int limit
= 50;
3985 /* LIMIT is to protect against circular lists. */
3986 while (CONSP (elt
) && --limit
> 0
3987 && hpos
< maxendcol
)
3989 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
3992 elt
= XCONS (elt
)->cdr
;
4000 if (frame_title_ptr
)
4001 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
4003 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
4004 minendcol
, maxendcol
);
4008 if (minendcol
> hpos
)
4009 if (frame_title_ptr
)
4010 hpos
= store_frame_title ("", minendcol
, maxendcol
);
4012 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 1, minendcol
, maxendcol
);
4016 /* Write a null-terminated, right justified decimal representation of
4017 the positive integer D to BUF using a minimal field width WIDTH. */
4020 pint2str (buf
, width
, d
)
4025 register char *p
= buf
;
4032 *p
++ = d
% 10 + '0';
4035 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
4045 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4046 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4047 type of CODING_SYSTEM. Return updated pointer into BUF. */
4050 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
4051 Lisp_Object coding_system
;
4057 val
= coding_system
;
4059 if (NILP (val
)) /* Not yet decided. */
4063 *buf
++ = eol_mnemonic_undecided
;
4064 /* Don't mention EOL conversion if it isn't decided. */
4068 Lisp_Object eolvalue
;
4070 eolvalue
= Fget (coding_system
, Qeol_type
);
4072 while (!NILP (val
) && SYMBOLP (val
))
4074 val
= Fget (val
, Qcoding_system
);
4075 if (NILP (eolvalue
))
4076 eolvalue
= Fget (coding_system
, Qeol_type
);
4079 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
4082 /* The EOL conversion we are using. */
4084 /* The EOL conversion that is normal on this system. */
4086 if (NILP (eolvalue
)) /* Not yet decided. */
4087 eoltype
= eol_mnemonic_undecided
;
4088 else if (VECTORP (eolvalue
)) /* Not yet decided. */
4089 eoltype
= eol_mnemonic_undecided
;
4090 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4091 eoltype
= (XFASTINT (eolvalue
) == 0
4093 : (XFASTINT (eolvalue
) == 1
4094 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
4096 /* Mention the EOL conversion if it is not the usual one. */
4103 /* Return a string for the output of a mode line %-spec for window W,
4104 generated by character C. SPEC_WIDTH is the field width when
4105 padding to the left (%c, %l). The value returned from this
4106 function will later be truncated to width MAXWIDTH. */
4108 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4111 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
4114 register int spec_width
;
4115 register int maxwidth
;
4118 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4119 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
4120 struct buffer
*b
= XBUFFER (w
->buffer
);
4123 if (maxwidth
> FRAME_WIDTH (f
))
4124 maxwidth
= FRAME_WIDTH (f
);
4129 if (!NILP (b
->read_only
))
4131 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4136 /* This differs from %* only for a modified read-only buffer. */
4137 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4139 if (!NILP (b
->read_only
))
4144 /* This differs from %* in ignoring read-only-ness. */
4145 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4157 if (command_loop_level
> 5)
4159 p
= decode_mode_spec_buf
;
4160 for (i
= 0; i
< command_loop_level
; i
++)
4163 return decode_mode_spec_buf
;
4171 if (command_loop_level
> 5)
4173 p
= decode_mode_spec_buf
;
4174 for (i
= 0; i
< command_loop_level
; i
++)
4177 return decode_mode_spec_buf
;
4185 if (maxwidth
< sizeof (lots_of_dashes
))
4186 return lots_of_dashes
;
4189 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
4193 return decode_mode_spec_buf
;
4199 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
4201 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
4202 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
4203 decode_mode_spec_buf
[maxwidth
] = '\0';
4204 return decode_mode_spec_buf
;
4211 int col
= current_column ();
4212 XSETFASTINT (w
->column_number_displayed
, col
);
4213 pint2str (decode_mode_spec_buf
, spec_width
, col
);
4214 return decode_mode_spec_buf
;
4218 /* %F displays the frame name. */
4219 if (!NILP (f
->title
))
4220 return (char *) XSTRING (f
->title
)->data
;
4221 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
4222 return (char *) XSTRING (f
->name
)->data
;
4230 else if (STRINGP (obj
) && XSTRING (obj
)->size
> maxwidth
)
4232 bcopy ("...", decode_mode_spec_buf
, 3);
4233 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
4234 decode_mode_spec_buf
+ 3, maxwidth
- 3);
4235 return decode_mode_spec_buf
;
4242 int startpos
= marker_position (w
->start
);
4243 int line
, linepos
, topline
;
4246 int height
= XFASTINT (w
->height
);
4248 /* If we decided that this buffer isn't suitable for line numbers,
4249 don't forget that too fast. */
4250 if (EQ (w
->base_line_pos
, w
->buffer
))
4252 /* But do forget it, if the window shows a different buffer now. */
4253 else if (BUFFERP (w
->base_line_pos
))
4254 w
->base_line_pos
= Qnil
;
4256 /* If the buffer is very big, don't waste time. */
4257 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
4259 w
->base_line_pos
= Qnil
;
4260 w
->base_line_number
= Qnil
;
4264 if (!NILP (w
->base_line_number
)
4265 && !NILP (w
->base_line_pos
)
4266 && XFASTINT (w
->base_line_pos
) <= marker_position (w
->start
))
4268 line
= XFASTINT (w
->base_line_number
);
4269 linepos
= XFASTINT (w
->base_line_pos
);
4274 linepos
= BUF_BEGV (b
);
4277 /* Count lines from base line to window start position. */
4278 nlines
= display_count_lines (linepos
, startpos
, startpos
, &junk
);
4280 topline
= nlines
+ line
;
4282 /* Determine a new base line, if the old one is too close
4283 or too far away, or if we did not have one.
4284 "Too close" means it's plausible a scroll-down would
4286 if (startpos
== BUF_BEGV (b
))
4288 XSETFASTINT (w
->base_line_number
, topline
);
4289 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
4291 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
4292 || linepos
== BUF_BEGV (b
))
4294 int limit
= BUF_BEGV (b
);
4296 int distance
= (height
* 2 + 30) * 200;
4298 if (startpos
- distance
> limit
)
4299 limit
= startpos
- distance
;
4301 nlines
= display_count_lines (startpos
, limit
,
4304 /* If we couldn't find the lines we wanted within
4306 give up on line numbers for this window. */
4307 if (position
== startpos
- distance
)
4309 w
->base_line_pos
= w
->buffer
;
4310 w
->base_line_number
= Qnil
;
4314 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
4315 XSETFASTINT (w
->base_line_pos
, position
);
4318 /* Now count lines from the start pos to point. */
4319 nlines
= display_count_lines (startpos
, PT
, PT
, &junk
);
4321 /* Record that we did display the line number. */
4322 line_number_displayed
= 1;
4324 /* Make the string to show. */
4325 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
4326 return decode_mode_spec_buf
;
4329 char* p
= decode_mode_spec_buf
;
4330 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
4332 return decode_mode_spec_buf
;
4342 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
4348 int pos
= marker_position (w
->start
);
4349 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4351 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
4353 if (pos
<= BUF_BEGV (b
))
4358 else if (pos
<= BUF_BEGV (b
))
4362 if (total
> 1000000)
4363 /* Do it differently for a large value, to avoid overflow. */
4364 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4366 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4367 /* We can't normally display a 3-digit number,
4368 so get us a 2-digit number that is close. */
4371 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4372 return decode_mode_spec_buf
;
4376 /* Display percentage of size above the bottom of the screen. */
4379 int toppos
= marker_position (w
->start
);
4380 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
4381 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4383 if (botpos
>= BUF_ZV (b
))
4385 if (toppos
<= BUF_BEGV (b
))
4392 if (total
> 1000000)
4393 /* Do it differently for a large value, to avoid overflow. */
4394 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4396 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4397 /* We can't normally display a 3-digit number,
4398 so get us a 2-digit number that is close. */
4401 if (toppos
<= BUF_BEGV (b
))
4402 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
4404 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4405 return decode_mode_spec_buf
;
4410 /* status of process */
4411 obj
= Fget_buffer_process (w
->buffer
);
4413 return "no process";
4415 obj
= Fsymbol_name (Fprocess_status (obj
));
4419 case 't': /* indicate TEXT or BINARY */
4420 #ifdef MODE_LINE_BINARY_TEXT
4421 return MODE_LINE_BINARY_TEXT (b
);
4427 /* coding-system (not including end-of-line format) */
4429 /* coding-system (including end-of-line type) */
4431 int eol_flag
= (c
== 'Z');
4434 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
4435 decode_mode_spec_buf
, eol_flag
);
4436 if (FRAME_TERMCAP_P (f
))
4438 /* No need to mention EOL here--the terminal never needs
4439 to do EOL conversion. */
4440 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
4441 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
4443 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
4445 obj
= Fget_buffer_process (Fcurrent_buffer ());
4448 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
4450 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
4453 #endif /* subprocesses */
4456 return decode_mode_spec_buf
;
4461 return (char *) XSTRING (obj
)->data
;
4466 /* Search for COUNT instances of a line boundary, which means either a
4467 newline or (if selective display enabled) a carriage return.
4468 Start at START. If COUNT is negative, search backwards.
4470 If we find COUNT instances, set *SHORTAGE to zero, and return the
4471 position after the COUNTth match. Note that for reverse motion
4472 this is not the same as the usual convention for Emacs motion commands.
4474 If we don't find COUNT instances before reaching the end of the
4475 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
4476 the number of line boundaries left unfound, and return the end of the
4477 buffer we bumped up against. */
4480 display_scan_buffer (start
, count
, shortage
)
4481 int *shortage
, start
;
4484 int limit
= ((count
> 0) ? ZV
- 1 : BEGV
);
4485 int direction
= ((count
> 0) ? 1 : -1);
4487 register unsigned char *cursor
;
4488 unsigned char *base
;
4490 register int ceiling
;
4491 register unsigned char *ceiling_addr
;
4493 /* If we are not in selective display mode,
4494 check only for newlines. */
4495 if (! (!NILP (current_buffer
->selective_display
)
4496 && !INTEGERP (current_buffer
->selective_display
)))
4497 return scan_buffer ('\n', start
, 0, count
, shortage
, 0);
4499 /* The code that follows is like scan_buffer
4500 but checks for either newline or carriage return. */
4506 while (start
!= limit
+ 1)
4508 ceiling
= BUFFER_CEILING_OF (start
);
4509 ceiling
= min (limit
, ceiling
);
4510 ceiling_addr
= POS_ADDR (ceiling
) + 1;
4511 base
= (cursor
= POS_ADDR (start
));
4514 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
4516 if (cursor
!= ceiling_addr
)
4521 return (start
+ cursor
- base
+ 1);
4524 if (++cursor
== ceiling_addr
)
4530 start
+= cursor
- base
;
4534 start
--; /* first character we scan */
4535 while (start
> limit
- 1)
4536 { /* we WILL scan under start */
4537 ceiling
= BUFFER_FLOOR_OF (start
);
4538 ceiling
= max (limit
, ceiling
);
4539 ceiling_addr
= POS_ADDR (ceiling
) - 1;
4540 base
= (cursor
= POS_ADDR (start
));
4544 while (--cursor
!= ceiling_addr
4545 && *cursor
!= '\n' && *cursor
!= 015)
4547 if (cursor
!= ceiling_addr
)
4552 return (start
+ cursor
- base
+ 1);
4558 start
+= cursor
- base
;
4563 *shortage
= count
* direction
;
4564 return (start
+ ((direction
== 1 ? 0 : 1)));
4567 /* Count up to N lines starting from FROM.
4568 But don't go beyond LIMIT.
4569 Return the number of lines thus found (always positive).
4570 Store the position after what was found into *POS_PTR. */
4573 display_count_lines (from
, limit
, n
, pos_ptr
)
4586 *pos_ptr
= display_scan_buffer (from
, n
, &shortage
);
4592 /* When scanning backwards, scan_buffer stops *after* the last newline
4593 it finds, but does count it. Compensate for that. */
4594 return - n
- shortage
- (*pos_ptr
!= limit
);
4595 return n
- shortage
;
4598 /* Display STRING on one line of window W, starting at HPOS.
4599 Display at position VPOS. Caller should have done get_display_line.
4600 If VPOS == -1, display it as the current frame's title.
4601 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4603 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4605 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4606 MAXCOL is the last column ok to end at. Truncate here.
4607 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4608 Both count from the left edge of the frame, as does HPOS.
4609 The right edge of W is an implicit maximum.
4610 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4612 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4613 at the place where the current window ends in this line
4614 and not display anything beyond there. Otherwise, only MAXCOL
4615 controls where to stop output.
4617 Returns ending hpos. */
4620 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
4621 obey_window_width
, mincol
, maxcol
)
4623 unsigned char *string
;
4627 int obey_window_width
;
4633 int hscroll
= XINT (w
->hscroll
);
4634 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
4635 register GLYPH
*start
;
4636 register GLYPH
*end
;
4637 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4638 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
4639 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
4640 int window_width
= XFASTINT (w
->width
);
4641 /* If 1, we must display multibyte characters. */
4642 int multibyte
= !NILP (XBUFFER (w
->buffer
)->enable_multibyte_characters
);
4644 /* Use the standard display table, not the window's display table.
4645 We don't want the mode line in rot13. */
4646 register struct Lisp_Char_Table
*dp
= 0;
4649 if (DISP_TABLE_P (Vstandard_display_table
))
4650 dp
= XCHAR_TABLE (Vstandard_display_table
);
4652 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
4655 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
4657 if (obey_window_width
)
4659 end
= start
+ window_width
- (truncate
!= 0);
4661 if (!WINDOW_RIGHTMOST_P (w
))
4663 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4667 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4670 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4675 if (! obey_window_width
4676 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
4677 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
4679 /* Store 0 in charstart for these columns. */
4680 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
4681 desired_glyphs
->charstarts
[vpos
][i
] = 0;
4683 if (maxcol
>= 0 && mincol
> maxcol
)
4687 /* We need this value for multibyte characters. */
4688 length
= strlen (string
);
4690 /* We set truncated to 1 if we get stopped by trying to pass END
4691 (that is, trying to pass MAXCOL.) */
4700 c
= STRING_CHAR_AND_LENGTH (string
, length
, len
);
4702 c
= *string
, len
= 1;
4704 string
+= len
, length
-= len
;
4712 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
4714 p1
= copy_part_of_rope (f
, p1
, start
,
4715 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
4716 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
4719 else if (c
>= 040 && c
< 0177)
4729 if (p1
>= start
&& p1
< end
)
4733 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
4735 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
4739 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
4740 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
4741 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
4744 if (p1
>= start
&& p1
< end
)
4750 /* C is a control character or a binary byte data. */
4753 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
4754 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
4755 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
4758 if (p1
>= start
&& p1
< end
)
4759 *p1
= (c
>> 6) + '0';
4761 if (p1
>= start
&& p1
< end
)
4762 *p1
= (7 & (c
>> 3)) + '0';
4764 if (p1
>= start
&& p1
< end
)
4765 *p1
= (7 & c
) + '0';
4770 /* C is a multibyte character. */
4771 int charset
= CHAR_CHARSET (c
);
4772 int columns
= (charset
== CHARSET_COMPOSITION
4773 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
4774 : CHARSET_WIDTH (charset
));
4778 /* Since we can't show the left part of C, fill all
4779 columns with spaces. */
4780 columns
-= start
- p1
;
4789 else if (p1
+ columns
> end
)
4791 /* Since we can't show the right part of C, fill all
4792 columns with TRUNCATE if TRUNCATE is specified. */
4796 *p1
++ = fix_glyph (f
, truncate
, 0);
4797 /* And tell the line is truncated. */
4804 /* We can show the whole glyph of C. */
4807 *p1
++ = c
| GLYPH_MASK_PADDING
;
4815 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
4817 else if (mincol
>= 0)
4819 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
4825 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
4827 if (len
> desired_glyphs
->used
[vpos
])
4828 desired_glyphs
->used
[vpos
] = len
;
4829 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
4835 /* This is like a combination of memq and assq.
4836 Return 1 if PROPVAL appears as an element of LIST
4837 or as the car of an element of LIST.
4838 If PROPVAL is a list, compare each element against LIST
4839 in that way, and return 1 if any element of PROPVAL is found in LIST.
4841 This function cannot quit. */
4844 invisible_p (propval
, list
)
4845 register Lisp_Object propval
;
4848 register Lisp_Object tail
, proptail
;
4849 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4851 register Lisp_Object tem
;
4852 tem
= XCONS (tail
)->car
;
4853 if (EQ (propval
, tem
))
4855 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
4858 if (CONSP (propval
))
4859 for (proptail
= propval
; CONSP (proptail
);
4860 proptail
= XCONS (proptail
)->cdr
)
4862 Lisp_Object propelt
;
4863 propelt
= XCONS (proptail
)->car
;
4864 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4866 register Lisp_Object tem
;
4867 tem
= XCONS (tail
)->car
;
4868 if (EQ (propelt
, tem
))
4870 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
4877 /* Return 1 if PROPVAL appears as the car of an element of LIST
4878 and the cdr of that element is non-nil.
4879 If PROPVAL is a list, check each element of PROPVAL in that way,
4880 and the first time some element is found,
4881 return 1 if the cdr of that element is non-nil.
4883 This function cannot quit. */
4886 invisible_ellipsis_p (propval
, list
)
4887 register Lisp_Object propval
;
4890 register Lisp_Object tail
, proptail
;
4891 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4893 register Lisp_Object tem
;
4894 tem
= XCONS (tail
)->car
;
4895 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
4896 return ! NILP (XCONS (tem
)->cdr
);
4898 if (CONSP (propval
))
4899 for (proptail
= propval
; CONSP (proptail
);
4900 proptail
= XCONS (proptail
)->cdr
)
4902 Lisp_Object propelt
;
4903 propelt
= XCONS (proptail
)->car
;
4904 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4906 register Lisp_Object tem
;
4907 tem
= XCONS (tail
)->car
;
4908 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
4909 return ! NILP (XCONS (tem
)->cdr
);
4918 staticpro (&Qmenu_bar_update_hook
);
4919 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
4921 staticpro (&Qoverriding_terminal_local_map
);
4922 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
4924 staticpro (&Qoverriding_local_map
);
4925 Qoverriding_local_map
= intern ("overriding-local-map");
4927 staticpro (&Qwindow_scroll_functions
);
4928 Qwindow_scroll_functions
= intern ("window-scroll-functions");
4930 staticpro (&Qredisplay_end_trigger_functions
);
4931 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
4933 staticpro (&last_arrow_position
);
4934 staticpro (&last_arrow_string
);
4935 last_arrow_position
= Qnil
;
4936 last_arrow_string
= Qnil
;
4938 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
4939 "String (or mode line construct) included (normally) in `mode-line-format'.");
4940 Vglobal_mode_string
= Qnil
;
4942 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
4943 "Marker for where to display an arrow on top of the buffer text.\n\
4944 This must be the beginning of a line in order to work.\n\
4945 See also `overlay-arrow-string'.");
4946 Voverlay_arrow_position
= Qnil
;
4948 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
4949 "String to display as an arrow. See also `overlay-arrow-position'.");
4950 Voverlay_arrow_string
= Qnil
;
4952 DEFVAR_INT ("scroll-step", &scroll_step
,
4953 "*The number of lines to try scrolling a window by when point moves out.\n\
4954 If that fails to bring point back on frame, point is centered instead.\n\
4955 If this is zero, point is always centered after it moves off frame.");
4957 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
4958 "*Scroll up to this many lines, to bring point back on screen.");
4959 scroll_conservatively
= 0;
4961 DEFVAR_INT ("scroll-margin", &scroll_margin
,
4962 "*Number of lines of margin at the top and bottom of a window.\n\
4963 Recenter the window whenever point gets within this many lines\n\
4964 of the top or bottom of the window.");
4967 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
4969 DEFVAR_BOOL ("truncate-partial-width-windows",
4970 &truncate_partial_width_windows
,
4971 "*Non-nil means truncate lines in all windows less than full frame wide.");
4972 truncate_partial_width_windows
= 1;
4974 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
4975 "*Non-nil means use inverse video for the mode line.");
4976 mode_line_inverse_video
= 1;
4978 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
4979 "*Maximum buffer size for which line number should be displayed.");
4980 line_number_display_limit
= 1000000;
4982 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
4983 "*Non-nil means highlight region even in nonselected windows.");
4984 highlight_nonselected_windows
= 0;
4986 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
4987 "Non-nil if more than one frame is visible on this display.\n\
4988 Minibuffer-only frames don't count, but iconified frames do.\n\
4989 This variable is not guaranteed to be accurate except while processing\n\
4990 `frame-title-format' and `icon-title-format'.");
4992 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
4993 "Template for displaying the titlebar of visible frames.\n\
4994 \(Assuming the window manager supports this feature.)\n\
4995 This variable has the same structure as `mode-line-format' (which see),\n\
4996 and is used only on frames for which no explicit name has been set\n\
4997 \(see `modify-frame-parameters').");
4998 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
4999 "Template for displaying the titlebar of an iconified frame.\n\
5000 \(Assuming the window manager supports this feature.)\n\
5001 This variable has the same structure as `mode-line-format' (which see),\n\
5002 and is used only on frames for which no explicit name has been set\n\
5003 \(see `modify-frame-parameters').");
5005 = Vframe_title_format
5006 = Fcons (intern ("multiple-frames"),
5007 Fcons (build_string ("%b"),
5008 Fcons (Fcons (build_string (""),
5009 Fcons (intern ("invocation-name"),
5010 Fcons (build_string ("@"),
5011 Fcons (intern ("system-name"),
5015 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
5016 "Maximum number of lines to keep in the message log buffer.\n\
5017 If nil, disable message logging. If t, log messages but don't truncate\n\
5018 the buffer when it becomes large.");
5019 XSETFASTINT (Vmessage_log_max
, 50);
5021 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
5022 "Functions called before redisplay, if window sizes have changed.\n\
5023 The value should be a list of functions that take one argument.\n\
5024 Just before redisplay, for each frame, if any of its windows have changed\n\
5025 size since the last redisplay, or have been split or deleted,\n\
5026 all the functions in the list are called, with the frame as argument.");
5027 Vwindow_size_change_functions
= Qnil
;
5029 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
5030 "List of Functions to call before redisplaying a window with scrolling.\n\
5031 Each function is called with two arguments, the window\n\
5032 and its new display-start position. Note that the value of `window-end'\n\
5033 is not valid when these functions are called.");
5034 Vwindow_scroll_functions
= Qnil
;
5037 /* initialize the window system */
5040 Lisp_Object root_window
;
5041 #ifndef COMPILER_REGISTER_BUG
5043 #endif /* COMPILER_REGISTER_BUG */
5044 struct window
*mini_w
;
5046 this_line_bufpos
= 0;
5048 mini_w
= XWINDOW (minibuf_window
);
5049 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
5051 echo_area_glyphs
= 0;
5052 previous_echo_glyphs
= 0;
5054 if (!noninteractive
)
5056 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
5057 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_MENU_BAR_LINES (f
));
5058 set_window_height (root_window
,
5059 FRAME_HEIGHT (f
) - 1 - FRAME_MENU_BAR_LINES (f
),
5061 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
5062 set_window_height (minibuf_window
, 1, 0);
5064 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
5065 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));