1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 1997
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 /*#include <ctype.h>*/
31 #include "dispextern.h"
38 #include "termhooks.h"
39 #include "intervals.h"
44 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
45 extern void set_frame_menubar ();
46 extern int pending_menu_activation
;
49 extern int interrupt_input
;
50 extern int command_loop_level
;
52 extern int minibuffer_auto_raise
;
54 extern int nonascii_insert_offset
;
56 extern Lisp_Object Qface
;
58 extern Lisp_Object Voverriding_local_map
;
59 extern Lisp_Object Voverriding_local_map_menu_flag
;
61 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
62 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
63 Lisp_Object Qredisplay_end_trigger_functions
;
65 /* Nonzero means print newline to stdout before next minibuffer message. */
67 int noninteractive_need_newline
;
69 /* Nonzero means print newline to message log before next message. */
71 static int message_log_need_newline
;
73 #define min(a, b) ((a) < (b) ? (a) : (b))
74 #define max(a, b) ((a) > (b) ? (a) : (b))
75 #define minmax(floor, val, ceil) \
76 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
78 /* The buffer position of the first character appearing
79 entirely or partially on the current frame line.
80 Or zero, which disables the optimization for the current frame line. */
81 static int this_line_bufpos
;
83 /* Number of characters past the end of this line,
84 including the terminating newline */
85 static int this_line_endpos
;
87 /* The vertical position of this frame line. */
88 static int this_line_vpos
;
90 /* Hpos value for start of display on this frame line.
91 Usually zero, but negative if first character really began
93 static int this_line_start_hpos
;
95 /* Buffer that this_line variables are describing. */
96 static struct buffer
*this_line_buffer
;
98 /* Value of echo_area_glyphs when it was last acted on.
99 If this is nonzero, there is a message on the frame
100 in the minibuffer and it should be erased as soon
101 as it is no longer requested to appear. */
102 char *previous_echo_glyphs
;
104 /* Nonzero means truncate lines in all windows less wide than the frame */
105 int truncate_partial_width_windows
;
107 /* Nonzero means we have more than one non-minibuffer-only frame.
108 Not guaranteed to be accurate except while parsing frame-title-format. */
111 Lisp_Object Vglobal_mode_string
;
113 /* Marker for where to display an arrow on top of the buffer text. */
114 Lisp_Object Voverlay_arrow_position
;
116 /* String to display for the arrow. */
117 Lisp_Object Voverlay_arrow_string
;
119 /* Values of those variables at last redisplay.
120 However, if Voverlay_arrow_position is a marker,
121 last_arrow_position is its numerical position. */
122 static Lisp_Object last_arrow_position
, last_arrow_string
;
124 /* Like mode-line-format, but for the titlebar on a visible frame. */
125 Lisp_Object Vframe_title_format
;
127 /* Like mode-line-format, but for the titlebar on an iconified frame. */
128 Lisp_Object Vicon_title_format
;
130 /* List of functions to call when a window's size changes. These
131 functions get one arg, a frame on which one or more windows' sizes
133 static Lisp_Object Vwindow_size_change_functions
;
135 Lisp_Object Qmenu_bar_update_hook
;
137 /* Nonzero if overlay arrow has been displayed once in this window. */
138 static int overlay_arrow_seen
;
140 /* Nonzero if visible end of buffer has already been displayed once
141 in this window. (We need this variable in case there are overlay
142 strings that get displayed there.) */
143 static int zv_strings_seen
;
145 /* Nonzero means highlight the region even in nonselected windows. */
146 static int highlight_nonselected_windows
;
148 /* If cursor motion alone moves point off frame,
149 Try scrolling this many lines up or down if that will bring it back. */
150 static int scroll_step
;
152 /* Non-0 means scroll just far enough to bring point back on the screen,
154 static int scroll_conservatively
;
156 /* Recenter the window whenever point gets within this many lines
157 of the top or bottom of the window. */
160 /* Number of characters of overlap to show,
161 when scrolling a one-line window such as a minibuffer. */
162 static int minibuffer_scroll_overlap
;
164 /* Nonzero if try_window_id has made blank lines at window bottom
165 since the last redisplay that paused */
166 static int blank_end_of_window
;
168 /* Number of windows showing the buffer of the selected window
169 (or another buffer with the same base buffer).
170 keyboard.c refers to this. */
173 /* display_text_line sets these to the frame position (origin 0) of point,
174 whether the window is selected or not.
175 Set one to -1 first to determine whether point was found afterwards. */
177 static int cursor_vpos
;
178 static int cursor_hpos
;
180 static int debug_end_pos
;
182 /* Nonzero means display mode line highlighted */
183 int mode_line_inverse_video
;
185 static void redisplay_internal ();
186 static int message_log_check_duplicate ();
187 static void echo_area_display ();
188 void mark_window_display_accurate ();
189 static void redisplay_windows ();
190 static void redisplay_window ();
191 static void update_menu_bar ();
192 static void try_window ();
193 static int try_window_id ();
194 static struct position
*display_text_line ();
195 static void display_mode_line ();
196 static int display_mode_element ();
197 static char *decode_mode_spec ();
198 static int display_string ();
199 static void display_menu_bar ();
200 static int display_count_lines ();
202 /* Prompt to display in front of the minibuffer contents */
203 Lisp_Object minibuf_prompt
;
205 /* Width in columns of current minibuffer prompt. */
206 int minibuf_prompt_width
;
208 /* Message to display instead of minibuffer contents
209 This is what the functions error and message make,
210 and command echoing uses it as well.
211 It overrides the minibuf_prompt as well as the buffer. */
212 char *echo_area_glyphs
;
214 /* This is the length of the message in echo_area_glyphs. */
215 int echo_area_glyphs_length
;
217 /* This is the window where the echo area message was displayed.
218 It is always a minibuffer window, but it may not be the
219 same window currently active as a minibuffer. */
220 Lisp_Object echo_area_window
;
222 /* Nonzero means multibyte characters were enabled when the echo area
223 message was specified. */
224 int message_enable_multibyte
;
226 /* true iff we should redraw the mode lines on the next redisplay */
227 int update_mode_lines
;
229 /* Smallest number of characters before the gap
230 at any time since last redisplay that finished.
231 Valid for current buffer when try_window_id can be called. */
234 /* Smallest number of characters after the gap
235 at any time since last redisplay that finished.
236 Valid for current buffer when try_window_id can be called. */
239 /* MODIFF as of last redisplay that finished;
240 if it matches MODIFF, and overlay_unchanged_modified
241 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
242 contain no useful information */
243 int unchanged_modified
;
245 /* OVERLAY_MODIFF as of last redisplay that finished. */
246 int overlay_unchanged_modified
;
248 /* Nonzero if window sizes or contents have changed
249 since last redisplay that finished */
250 int windows_or_buffers_changed
;
252 /* Nonzero after display_mode_line if %l was used
253 and it displayed a line number. */
254 int line_number_displayed
;
256 /* Maximum buffer size for which to display line numbers. */
257 static int line_number_display_limit
;
259 /* Number of lines to keep in the message log buffer.
260 t means infinite. nil means don't log at all. */
261 Lisp_Object Vmessage_log_max
;
263 #define COERCE_MARKER(X) \
264 (MARKERP ((X)) ? Fmarker_position (X) : (X))
266 /* Output a newline in the *Messages* buffer if "needs" one. */
269 message_log_maybe_newline ()
271 if (message_log_need_newline
)
272 message_dolog ("", 0, 1);
276 /* Add a string to the message log, optionally terminated with a newline.
277 This function calls low-level routines in order to bypass text property
278 hooks, etc. which might not be safe to run. */
281 message_dolog (m
, len
, nlflag
)
285 if (!NILP (Vmessage_log_max
))
287 struct buffer
*oldbuf
;
288 int oldpoint
, oldbegv
, oldzv
;
289 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
290 int point_at_end
= 0;
293 oldbuf
= current_buffer
;
294 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
295 current_buffer
->undo_list
= Qt
;
307 /* Insert the string--maybe converting multibyte to single byte
308 or vice versa, so that all the text fits the buffer. */
309 if (! NILP (oldbuf
->enable_multibyte_characters
)
310 && NILP (current_buffer
->enable_multibyte_characters
))
312 int c
, i
= 0, nbytes
;
313 /* Convert a multibyte string to single-byte
314 for the *Message* buffer. */
317 c
= STRING_CHAR (m
+ i
, len
- i
);
318 i
+= XFASTINT (Fchar_bytes (make_number (c
)));
319 /* Truncate the character to its last byte--we can only hope
320 the user is happy with the character he gets,
321 since if it isn't right, there is no way to do it right. */
326 else if (NILP (oldbuf
->enable_multibyte_characters
)
327 && ! NILP (current_buffer
->enable_multibyte_characters
))
330 /* Convert a single-byte string to multibyte
331 for the *Message* buffer. */
335 /* Convert non-ascii chars as if for self-insert. */
336 if (c
>= 0200 && c
<= 0377)
337 c
+= nonascii_insert_offset
;
342 insert_1 (m
, len
, 1, 0);
346 int this_bol
, prev_bol
, dup
;
347 insert_1 ("\n", 1, 1, 0);
349 this_bol
= scan_buffer ('\n', Z
, 0, -2, 0, 0);
352 prev_bol
= scan_buffer ('\n', this_bol
, 0, -2, 0, 0);
353 dup
= message_log_check_duplicate (prev_bol
, this_bol
);
356 if (oldpoint
> prev_bol
)
357 oldpoint
-= min (this_bol
, oldpoint
) - prev_bol
;
358 if (oldbegv
> prev_bol
)
359 oldbegv
-= min (this_bol
, oldbegv
) - prev_bol
;
360 if (oldzv
> prev_bol
)
361 oldzv
-= min (this_bol
, oldzv
) - prev_bol
;
362 del_range_1 (prev_bol
, this_bol
, 0);
368 /* If you change this format, don't forget to also
369 change message_log_check_duplicate. */
370 sprintf (dupstr
, " [%d times]", dup
);
371 duplen
= strlen (dupstr
);
377 insert_1 (dupstr
, duplen
, 1, 0);
382 if (NATNUMP (Vmessage_log_max
))
384 int pos
= scan_buffer ('\n', Z
, 0,
385 -XFASTINT (Vmessage_log_max
) - 1, 0, 0);
386 oldpoint
-= min (pos
, oldpoint
) - BEG
;
387 oldbegv
-= min (pos
, oldbegv
) - BEG
;
388 oldzv
-= min (pos
, oldzv
) - BEG
;
389 del_range_1 (BEG
, pos
, 0);
400 TEMP_SET_PT (oldpoint
);
401 set_buffer_internal (oldbuf
);
402 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
403 message_log_need_newline
= !nlflag
;
407 /* We are at the end of the buffer after just having inserted a newline.
408 (Note: We depend on the fact we won't be crossing the gap.)
409 Check to see if the most recent message looks a lot like the previous one.
410 Return 0 if different, 1 if the new one should just replace it, or a
411 value N > 1 if we should also append " [N times]". */
414 message_log_check_duplicate (prev_bol
, this_bol
)
415 int prev_bol
, this_bol
;
418 int len
= Z
- 1 - this_bol
;
420 unsigned char *p1
= BUF_CHAR_ADDRESS (current_buffer
, prev_bol
);
421 unsigned char *p2
= BUF_CHAR_ADDRESS (current_buffer
, this_bol
);
423 for (i
= 0; i
< len
; i
++)
425 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
434 if (*p1
++ == ' ' && *p1
++ == '[')
437 while (*p1
>= '0' && *p1
<= '9')
438 n
= n
* 10 + *p1
++ - '0';
439 if (strncmp (p1
, " times]\n", 8) == 0)
445 /* Display an echo area message M with a specified length of LEN chars.
446 The string may include null characters. If M is 0, clear out any
447 existing message, and let the minibuffer text show through.
449 The buffer M must continue to exist until after the echo area
450 gets cleared or some other message gets displayed there.
452 Do not pass text that is stored in a Lisp string.
453 Do not pass text in a buffer that was alloca'd. */
460 /* First flush out any partial line written with print. */
461 message_log_maybe_newline ();
463 message_dolog (m
, len
, 1);
464 message2_nolog (m
, len
,
465 ! NILP (current_buffer
->enable_multibyte_characters
));
469 /* The non-logging counterpart of message2. */
472 message2_nolog (m
, len
, multibyte
)
476 message_enable_multibyte
= multibyte
;
480 if (noninteractive_need_newline
)
482 noninteractive_need_newline
= 0;
484 fwrite (m
, len
, 1, stderr
);
485 if (cursor_in_echo_area
== 0)
486 fprintf (stderr
, "\n");
489 /* A null message buffer means that the frame hasn't really been
490 initialized yet. Error messages get reported properly by
491 cmd_error, so this must be just an informative message; toss it. */
492 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
494 Lisp_Object mini_window
;
497 /* Get the frame containing the minibuffer
498 that the selected frame is using. */
499 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
500 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
502 FRAME_SAMPLE_VISIBILITY (f
);
503 if (FRAME_VISIBLE_P (selected_frame
)
504 && ! FRAME_VISIBLE_P (f
))
505 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
509 echo_area_glyphs
= m
;
510 echo_area_glyphs_length
= len
;
512 if (minibuffer_auto_raise
)
513 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
516 echo_area_glyphs
= previous_echo_glyphs
= 0;
518 do_pending_window_change ();
519 echo_area_display ();
520 update_frame (f
, 1, 1);
521 do_pending_window_change ();
522 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
523 (*frame_up_to_date_hook
) (f
);
527 /* Display a null-terminated echo area message M. If M is 0, clear out any
528 existing message, and let the minibuffer text show through.
530 The buffer M must continue to exist until after the echo area
531 gets cleared or some other message gets displayed there.
533 Do not pass text that is stored in a Lisp string.
534 Do not pass text in a buffer that was alloca'd. */
540 message2 (m
, (m
? strlen (m
) : 0));
547 message2_nolog (m
, (m
? strlen (m
) : 0),
548 ! NILP (current_buffer
->enable_multibyte_characters
));
551 /* Truncate what will be displayed in the echo area
552 the next time we display it--but don't redisplay it now. */
555 truncate_echo_area (len
)
558 /* A null message buffer means that the frame hasn't really been
559 initialized yet. Error messages get reported properly by
560 cmd_error, so this must be just an informative message; toss it. */
561 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
562 echo_area_glyphs_length
= len
;
565 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
566 zero if being used by message. */
567 int message_buf_print
;
569 /* Dump an informative message to the minibuf. If M is 0, clear out
570 any existing message, and let the minibuffer text show through. */
574 message (m
, a1
, a2
, a3
)
576 EMACS_INT a1
, a2
, a3
;
582 if (noninteractive_need_newline
)
584 noninteractive_need_newline
= 0;
585 fprintf (stderr
, m
, a1
, a2
, a3
);
586 if (cursor_in_echo_area
== 0)
587 fprintf (stderr
, "\n");
591 else if (INTERACTIVE
)
593 /* The frame whose minibuffer we're going to display the message on.
594 It may be larger than the selected frame, so we need
595 to use its buffer, not the selected frame's buffer. */
596 Lisp_Object mini_window
;
599 /* Get the frame containing the minibuffer
600 that the selected frame is using. */
601 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
602 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
604 /* A null message buffer means that the frame hasn't really been
605 initialized yet. Error messages get reported properly by
606 cmd_error, so this must be just an informative message; toss it. */
607 if (FRAME_MESSAGE_BUF (f
))
618 len
= doprnt (FRAME_MESSAGE_BUF (f
),
619 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
621 len
= doprnt (FRAME_MESSAGE_BUF (f
),
622 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, &a1
);
623 #endif /* NO_ARG_ARRAY */
625 message2 (FRAME_MESSAGE_BUF (f
), len
);
630 /* Print should start at the beginning of the message
632 message_buf_print
= 0;
637 /* The non-logging version of message. */
639 message_nolog (m
, a1
, a2
, a3
)
641 EMACS_INT a1
, a2
, a3
;
643 Lisp_Object old_log_max
;
644 old_log_max
= Vmessage_log_max
;
645 Vmessage_log_max
= Qnil
;
646 message (m
, a1
, a2
, a3
);
647 Vmessage_log_max
= old_log_max
;
653 message2 (echo_area_glyphs
, echo_area_glyphs_length
);
661 Lisp_Object mini_window
;
663 /* Choose the minibuffer window for this display.
664 It is the minibuffer window used by the selected frame. */
665 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
666 /* This is the frame that window is in. */
667 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
669 if (! FRAME_VISIBLE_P (f
))
674 redraw_garbaged_frames ();
678 if (echo_area_glyphs
|| minibuf_level
== 0)
682 echo_area_window
= mini_window
;
684 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
685 get_display_line (f
, vpos
, 0);
687 /* Make sure the columns that overlap a left-hand scroll bar
689 for (i
= 0; i
< FRAME_LEFT_SCROLL_BAR_WIDTH (f
); i
++)
690 f
->desired_glyphs
->glyphs
[vpos
][i
] = SPACEGLYPH
;
692 display_string (XWINDOW (mini_window
), vpos
,
693 echo_area_glyphs
? echo_area_glyphs
: "",
694 echo_area_glyphs
? echo_area_glyphs_length
: -1,
695 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
697 FRAME_WIDTH (f
) + FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
698 message_enable_multibyte
);
700 #if 0 /* This just gets in the way. update_frame does the job. */
701 /* If desired cursor location is on this line, put it at end of text */
702 if (cursor_in_echo_area
)
703 FRAME_CURSOR_Y (f
) = vpos
;
704 if (FRAME_CURSOR_Y (f
) == vpos
)
705 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
708 /* Fill the rest of the minibuffer window with blank lines. */
713 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
715 get_display_line (f
, i
, 0);
716 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
717 hpos, because it is good to clear whatever is behind the
718 scroll bar. This does not affect the scroll bar itself. */
719 display_string (XWINDOW (mini_window
), i
,
722 0, FRAME_WIDTH (f
) + FRAME_SCROLL_BAR_WIDTH (f
),
727 else if (!EQ (mini_window
, selected_window
))
728 windows_or_buffers_changed
++;
730 if (EQ (mini_window
, selected_window
))
731 this_line_bufpos
= 0;
733 previous_echo_glyphs
= echo_area_glyphs
;
736 /* Update frame titles. */
738 #ifdef HAVE_WINDOW_SYSTEM
739 static char frame_title_buf
[512];
740 static char *frame_title_ptr
;
743 store_frame_title (str
, mincol
, maxcol
)
748 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
749 maxcol
= sizeof (frame_title_buf
);
750 limit
= &frame_title_buf
[maxcol
];
751 while (*str
!= '\0' && frame_title_ptr
< limit
)
752 *frame_title_ptr
++ = *str
++;
753 while (frame_title_ptr
< &frame_title_buf
[mincol
])
754 *frame_title_ptr
++ = ' ';
755 return frame_title_ptr
- frame_title_buf
;
759 x_consider_frame_title (frame
)
765 FRAME_PTR f
= XFRAME (frame
);
767 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
770 /* Do we have more than one visible frame on this X display? */
774 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
776 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
778 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
779 && !FRAME_MINIBUF_ONLY_P (tf
)
780 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
784 multiple_frames
= CONSP (tail
);
787 obuf
= current_buffer
;
788 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
789 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
790 frame_title_ptr
= frame_title_buf
;
791 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
792 0, sizeof (frame_title_buf
), fmt
);
794 set_buffer_internal (obuf
);
795 /* Set the name only if it's changed. This avoids consing
796 in the common case where it hasn't. (If it turns out that we've
797 already wasted too much time by walking through the list with
798 display_mode_element, then we might need to optimize at a higher
800 if (! STRINGP (f
->name
) || XSTRING (f
->name
)->size
!= len
801 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
802 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
805 #define frame_title_ptr ((char *)0)
806 #define store_frame_title(str, mincol, maxcol) 0
809 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
810 This can call eval. */
815 register struct window
*w
= XWINDOW (selected_window
);
817 struct gcpro gcpro1
, gcpro2
;
819 all_windows
= (update_mode_lines
|| buffer_shared
> 1
820 || windows_or_buffers_changed
);
822 /* Update all frame titles based on their buffer names, etc.
823 We do this before the menu bars so that the buffer-menu
824 will show the up-to-date frame titles.
826 This used to be done after the menu bars, for a reason that
827 was stated as follows but which I do not understand:
828 "We do this after the menu bars so that the frame will first
829 create its menu bar using the name `emacs' if no other name
830 has yet been specified."
831 I think that is no longer a concern. */
832 #ifdef HAVE_WINDOW_SYSTEM
833 if (windows_or_buffers_changed
|| update_mode_lines
)
835 Lisp_Object tail
, frame
;
837 FOR_EACH_FRAME (tail
, frame
)
838 if (FRAME_VISIBLE_P (XFRAME (frame
))
839 || FRAME_ICONIFIED_P (XFRAME (frame
)))
840 x_consider_frame_title (frame
);
844 /* Update the menu bar item lists, if appropriate.
845 This has to be done before any actual redisplay
846 or generation of display lines. */
849 Lisp_Object tail
, frame
;
850 int count
= specpdl_ptr
- specpdl
;
852 record_unwind_protect (Fstore_match_data
, Fmatch_data (Qnil
, Qnil
));
854 FOR_EACH_FRAME (tail
, frame
)
856 /* If a window on this frame changed size,
857 report that to the user and clear the size-change flag. */
858 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
860 Lisp_Object functions
;
861 /* Clear flag first in case we get error below. */
862 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
863 functions
= Vwindow_size_change_functions
;
864 GCPRO2 (tail
, functions
);
865 while (CONSP (functions
))
867 call1 (XCONS (functions
)->car
, frame
);
868 functions
= XCONS (functions
)->cdr
;
873 update_menu_bar (XFRAME (frame
), 0);
877 unbind_to (count
, Qnil
);
880 update_menu_bar (selected_frame
, 1);
882 /* Motif needs this. See comment in xmenu.c.
883 Turn it off when pending_menu_activation is not defined. */
885 pending_menu_activation
= 0;
889 /* Do a frame update, taking possible shortcuts into account.
890 This is the main external entry point for redisplay.
892 If the last redisplay displayed an echo area message and that
893 message is no longer requested, we clear the echo area
894 or bring back the minibuffer if that is in use.
896 Do not call eval from within this function.
897 Calls to eval after the call to echo_area_display would confuse
898 the display_line mechanism and would cause a crash.
899 Calls to eval before that point will work most of the time,
900 but can still lose, because this function
901 can be called from signal handlers; with alarms set up;
902 or with synchronous processes running.
904 See Fcall_process; if you called it from here, it could be
905 entered recursively. */
907 static int do_verify_charstarts
;
909 /* Counter is used to clear the face cache
910 no more than once ever 1000 redisplays. */
911 static int clear_face_cache_count
;
913 /* Record the previous terminal frame we displayed. */
914 static FRAME_PTR previous_terminal_frame
;
919 redisplay_internal (0);
922 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
923 is not in response to any user action; therefore, we should
924 preserve the echo area. (Actually, our caller does that job.)
925 Perhaps in the future avoid recentering windows
926 if it is not necessary; currently that causes some problems. */
929 redisplay_internal (preserve_echo_area
)
930 int preserve_echo_area
;
932 register struct window
*w
= XWINDOW (selected_window
);
936 register int tlbufpos
, tlendpos
;
938 int number_of_visible_frames
;
944 if (popup_activated ())
950 if (! FRAME_WINDOW_P (selected_frame
)
951 && previous_terminal_frame
!= selected_frame
)
953 /* Since frames on an ASCII terminal share the same display area,
954 displaying a different frame means redisplay the whole thing. */
955 windows_or_buffers_changed
++;
956 SET_FRAME_GARBAGED (selected_frame
);
957 XSETFRAME (Vterminal_frame
, selected_frame
);
959 previous_terminal_frame
= selected_frame
;
961 /* Set the visible flags for all frames.
962 Do this before checking for resized or garbaged frames; they want
963 to know if their frames are visible.
964 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
966 Lisp_Object tail
, frame
;
968 number_of_visible_frames
= 0;
970 FOR_EACH_FRAME (tail
, frame
)
972 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
974 if (FRAME_VISIBLE_P (XFRAME (frame
)))
975 number_of_visible_frames
++;
977 /* Clear out all the display lines in which we will generate the
978 glyphs to display. */
979 init_desired_glyphs (XFRAME (frame
));
983 /* Notice any pending interrupt request to change frame size. */
984 do_pending_window_change ();
988 redraw_garbaged_frames ();
992 prepare_menu_bars ();
994 if (windows_or_buffers_changed
)
997 /* Detect case that we need to write or remove a star in the mode line. */
998 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
1000 w
->update_mode_line
= Qt
;
1001 if (buffer_shared
> 1)
1002 update_mode_lines
++;
1005 /* If %c is in use, update it if needed. */
1006 if (!NILP (w
->column_number_displayed
)
1007 /* This alternative quickly identifies a common case
1008 where no change is needed. */
1009 && !(PT
== XFASTINT (w
->last_point
)
1010 && XFASTINT (w
->last_modified
) >= MODIFF
1011 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1012 && XFASTINT (w
->column_number_displayed
) != current_column ())
1013 w
->update_mode_line
= Qt
;
1015 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
1017 all_windows
= update_mode_lines
|| buffer_shared
> 1;
1019 /* If specs for an arrow have changed, do thorough redisplay
1020 to ensure we remove any arrow that should no longer exist. */
1021 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
1022 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
1025 /* Normally the message* functions will have already displayed and
1026 updated the echo area, but the frame may have been trashed, or
1027 the update may have been preempted, so display the echo area
1029 if (echo_area_glyphs
|| previous_echo_glyphs
)
1031 echo_area_display ();
1035 /* If showing region, and mark has changed, must redisplay whole window. */
1036 if (((!NILP (Vtransient_mark_mode
)
1037 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1038 != !NILP (w
->region_showing
))
1039 || (!NILP (w
->region_showing
)
1040 && !EQ (w
->region_showing
,
1041 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
1042 this_line_bufpos
= -1;
1044 tlbufpos
= this_line_bufpos
;
1045 tlendpos
= this_line_endpos
;
1046 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
1047 && !current_buffer
->clip_changed
1048 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
1049 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
1050 /* Make sure recorded data applies to current buffer, etc */
1051 && this_line_buffer
== current_buffer
1052 && current_buffer
== XBUFFER (w
->buffer
)
1053 && NILP (w
->force_start
)
1054 /* Point must be on the line that we have info recorded about */
1056 && PT
<= Z
- tlendpos
1057 /* All text outside that line, including its final newline,
1058 must be unchanged */
1059 && ((XFASTINT (w
->last_modified
) >= MODIFF
1060 && (XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
))
1061 || (beg_unchanged
>= tlbufpos
- 1
1063 /* If selective display, can't optimize
1064 if the changes start at the beginning of the line. */
1065 && ((INTEGERP (current_buffer
->selective_display
)
1066 && XINT (current_buffer
->selective_display
) > 0
1067 ? (beg_unchanged
>= tlbufpos
1070 && end_unchanged
>= tlendpos
1071 && Z
- GPT
>= tlendpos
)))
1073 if (tlbufpos
> BEGV
&& FETCH_BYTE (tlbufpos
- 1) != '\n'
1075 || FETCH_BYTE (tlbufpos
) == '\n'))
1076 /* Former continuation line has disappeared by becoming empty */
1078 else if (XFASTINT (w
->last_modified
) < MODIFF
1079 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
1080 || MINI_WINDOW_P (w
))
1082 /* We have to handle the case of continuation around a
1083 wide-column character (See the comment in indent.c around
1086 For instance, in the following case:
1088 -------- Insert --------
1089 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1090 J_I_ ==> J_I_ `^^' are cursors.
1094 As we have to redraw the line above, we should goto cancel. */
1096 struct position val
;
1099 prevline
= find_next_newline (tlbufpos
, -1);
1100 val
= *compute_motion (prevline
, 0,
1101 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1104 1 << (BITS_PER_SHORT
- 1),
1105 1 << (BITS_PER_SHORT
- 1),
1106 window_internal_width (w
) - 1,
1107 XINT (w
->hscroll
), 0, w
);
1108 if (val
.hpos
!= this_line_start_hpos
)
1112 overlay_arrow_seen
= 0;
1113 zv_strings_seen
= 0;
1114 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
1115 pos_tab_offset (w
, tlbufpos
), 0);
1116 /* If line contains point, is not continued,
1117 and ends at same distance from eob as before, we win */
1118 if (cursor_vpos
>= 0 && this_line_bufpos
1119 && this_line_endpos
== tlendpos
)
1121 /* If this is not the window's last line,
1122 we must adjust the charstarts of the lines below. */
1123 if (this_line_vpos
+ 1
1124 < XFASTINT (w
->top
) + window_internal_height (w
))
1126 int left
= WINDOW_LEFT_MARGIN (w
);
1127 int *charstart_next_line
1128 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
1131 if (Z
- tlendpos
== ZV
)
1132 /* This line ends at end of (accessible part of) buffer.
1133 There is no newline to count. */
1134 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
1136 /* This line ends in a newline.
1137 Must take account of the newline and the rest of the
1138 text that follows. */
1139 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
1141 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
1144 if (!WINDOW_FULL_WIDTH_P (w
))
1145 preserve_other_columns (w
);
1151 else if (PT
== XFASTINT (w
->last_point
)
1152 /* Make sure the cursor was last displayed
1153 in this window. Otherwise we have to reposition it. */
1154 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
1155 && (XINT (w
->top
) + XINT (w
->height
)
1156 > FRAME_CURSOR_Y (selected_frame
)))
1160 do_pending_window_change ();
1165 /* If highlighting the region, or if the cursor is in the echo area,
1166 then we can't just move the cursor. */
1167 else if (! (!NILP (Vtransient_mark_mode
)
1168 && !NILP (current_buffer
->mark_active
))
1169 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1170 || highlight_nonselected_windows
)
1171 && NILP (w
->region_showing
)
1172 && !cursor_in_echo_area
)
1174 pos
= *compute_motion (tlbufpos
, 0,
1175 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
1177 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
1178 window_internal_width (w
) - 1,
1180 pos_tab_offset (w
, tlbufpos
), w
);
1183 int width
= window_internal_width (w
) - 1;
1184 FRAME_CURSOR_X (selected_frame
)
1185 = WINDOW_LEFT_MARGIN (w
) + minmax (0, pos
.hpos
, width
);
1186 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1193 /* Text changed drastically or point moved off of line */
1194 cancel_line (this_line_vpos
, selected_frame
);
1197 this_line_bufpos
= 0;
1198 all_windows
|= buffer_shared
> 1;
1200 clear_face_cache_count
++;
1204 Lisp_Object tail
, frame
;
1207 /* Clear the face cache, only when we do a full redisplay
1208 and not too often either. */
1209 if (clear_face_cache_count
> 1000)
1211 clear_face_cache ();
1212 clear_face_cache_count
= 0;
1216 /* Recompute # windows showing selected buffer.
1217 This will be incremented each time such a window is displayed. */
1220 FOR_EACH_FRAME (tail
, frame
)
1222 FRAME_PTR f
= XFRAME (frame
);
1223 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
1226 /* Mark all the scroll bars to be removed; we'll redeem the ones
1227 we want when we redisplay their windows. */
1228 if (condemn_scroll_bars_hook
)
1229 (*condemn_scroll_bars_hook
) (f
);
1231 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1232 redisplay_windows (FRAME_ROOT_WINDOW (f
), preserve_echo_area
);
1234 /* Any scroll bars which redisplay_windows should have nuked
1235 should now go away. */
1236 if (judge_scroll_bars_hook
)
1237 (*judge_scroll_bars_hook
) (f
);
1241 else if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1243 redisplay_window (selected_window
, 1, preserve_echo_area
);
1244 if (!WINDOW_FULL_WIDTH_P (w
))
1245 preserve_other_columns (w
);
1249 /* Prevent various kinds of signals during display update.
1250 stdio is not robust about handling signals,
1251 which can cause an apparent I/O error. */
1252 if (interrupt_input
)
1262 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1266 if (!FRAMEP (XCONS (tail
)->car
))
1269 f
= XFRAME (XCONS (tail
)->car
);
1271 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
1272 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
1274 pause
|= update_frame (f
, 0, 0);
1277 mark_window_display_accurate (f
->root_window
, 1);
1278 if (frame_up_to_date_hook
!= 0)
1279 (*frame_up_to_date_hook
) (f
);
1286 if (FRAME_VISIBLE_P (selected_frame
) && !FRAME_OBSCURED_P (selected_frame
))
1287 pause
= update_frame (selected_frame
, 0, 0);
1291 /* We may have called echo_area_display at the top of this
1292 function. If the echo area is on another frame, that may
1293 have put text on a frame other than the selected one, so the
1294 above call to update_frame would not have caught it. Catch
1297 Lisp_Object mini_window
;
1298 FRAME_PTR mini_frame
;
1300 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1301 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1303 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
1304 pause
|= update_frame (mini_frame
, 0, 0);
1308 /* If frame does not match, prevent doing single-line-update next time.
1309 Also, don't forget to check every line to update the arrow. */
1312 this_line_bufpos
= 0;
1313 if (!NILP (last_arrow_position
))
1315 last_arrow_position
= Qt
;
1316 last_arrow_string
= Qt
;
1318 /* If we pause after scrolling, some lines in current_frame
1319 may be null, so preserve_other_columns won't be able to
1320 preserve all the vertical-bar separators. So, avoid using it
1322 if (!WINDOW_FULL_WIDTH_P (w
))
1323 update_mode_lines
= 1;
1326 /* Now text on frame agrees with windows, so
1327 put info into the windows for partial redisplay to follow */
1331 register struct buffer
*b
= XBUFFER (w
->buffer
);
1333 blank_end_of_window
= 0;
1334 unchanged_modified
= BUF_MODIFF (b
);
1335 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
1336 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1337 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1339 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1340 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1341 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1344 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1347 b
->clip_changed
= 0;
1348 w
->update_mode_line
= Qnil
;
1349 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1350 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
1352 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1355 /* Record if we are showing a region, so can make sure to
1356 update it fully at next redisplay. */
1357 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1358 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1359 || highlight_nonselected_windows
)
1360 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1361 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1364 w
->window_end_valid
= w
->buffer
;
1365 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1366 last_arrow_string
= Voverlay_arrow_string
;
1367 if (do_verify_charstarts
)
1368 verify_charstarts (w
);
1369 if (frame_up_to_date_hook
!= 0)
1370 (*frame_up_to_date_hook
) (selected_frame
);
1372 update_mode_lines
= 0;
1373 windows_or_buffers_changed
= 0;
1376 /* Start SIGIO interrupts coming again.
1377 Having them off during the code above
1378 makes it less likely one will discard output,
1379 but not impossible, since there might be stuff
1380 in the system buffer here.
1381 But it is much hairier to try to do anything about that. */
1383 if (interrupt_input
)
1387 /* If something has become visible now which was not before,
1388 redisplay again, so that we get them. */
1391 Lisp_Object tail
, frame
;
1394 FOR_EACH_FRAME (tail
, frame
)
1396 int this_is_visible
= 0;
1398 if (XFRAME (frame
)->visible
)
1399 this_is_visible
= 1;
1400 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1401 if (XFRAME (frame
)->visible
)
1402 this_is_visible
= 1;
1404 if (this_is_visible
)
1408 if (new_count
!= number_of_visible_frames
)
1409 windows_or_buffers_changed
++;
1412 /* Change frame size now if a change is pending. */
1413 do_pending_window_change ();
1415 /* If we just did a pending size change, or have additional
1416 visible frames, redisplay again. */
1417 if (windows_or_buffers_changed
&& !pause
)
1421 /* Redisplay, but leave alone any recent echo area message
1422 unless another message has been requested in its place.
1424 This is useful in situations where you need to redisplay but no
1425 user action has occurred, making it inappropriate for the message
1426 area to be cleared. See tracking_off and
1427 wait_reading_process_input for examples of these situations. */
1430 redisplay_preserve_echo_area ()
1432 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1434 echo_area_glyphs
= previous_echo_glyphs
;
1435 redisplay_internal (1);
1436 echo_area_glyphs
= 0;
1439 redisplay_internal (1);
1443 mark_window_display_accurate (window
, flag
)
1447 register struct window
*w
;
1449 for (;!NILP (window
); window
= w
->next
)
1451 if (!WINDOWP (window
)) abort ();
1452 w
= XWINDOW (window
);
1454 if (!NILP (w
->buffer
))
1456 XSETFASTINT (w
->last_modified
,
1457 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1458 XSETFASTINT (w
->last_overlay_modified
,
1459 !flag
? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)));
1461 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1464 /* Record if we are showing a region, so can make sure to
1465 update it fully at next redisplay. */
1466 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1467 && (w
== XWINDOW (current_buffer
->last_selected_window
)
1468 || highlight_nonselected_windows
)
1469 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1470 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1474 w
->window_end_valid
= w
->buffer
;
1475 w
->update_mode_line
= Qnil
;
1476 if (!NILP (w
->buffer
) && flag
)
1477 XBUFFER (w
->buffer
)->clip_changed
= 0;
1479 if (!NILP (w
->vchild
))
1480 mark_window_display_accurate (w
->vchild
, flag
);
1481 if (!NILP (w
->hchild
))
1482 mark_window_display_accurate (w
->hchild
, flag
);
1487 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
1488 last_arrow_string
= Voverlay_arrow_string
;
1492 /* t is unequal to any useful value of Voverlay_arrow_... */
1493 last_arrow_position
= Qt
;
1494 last_arrow_string
= Qt
;
1498 /* Update the menu bar item list for frame F.
1499 This has to be done before we start to fill in any display lines,
1500 because it can call eval.
1502 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1505 update_menu_bar (f
, save_match_data
)
1507 int save_match_data
;
1509 struct buffer
*old
= current_buffer
;
1511 register struct window
*w
;
1513 window
= FRAME_SELECTED_WINDOW (f
);
1514 w
= XWINDOW (window
);
1516 if (update_mode_lines
)
1517 w
->update_mode_line
= Qt
;
1519 if (FRAME_WINDOW_P (f
)
1521 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1522 FRAME_EXTERNAL_MENU_BAR (f
)
1524 FRAME_MENU_BAR_LINES (f
) > 0
1526 : FRAME_MENU_BAR_LINES (f
) > 0)
1528 /* If the user has switched buffers or windows, we need to
1529 recompute to reflect the new bindings. But we'll
1530 recompute when update_mode_lines is set too; that means
1531 that people can use force-mode-line-update to request
1532 that the menu bar be recomputed. The adverse effect on
1533 the rest of the redisplay algorithm is about the same as
1534 windows_or_buffers_changed anyway. */
1535 if (windows_or_buffers_changed
1536 || !NILP (w
->update_mode_line
)
1537 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
1538 < BUF_MODIFF (XBUFFER (w
->buffer
)))
1539 != !NILP (w
->last_had_star
))
1540 || ((!NILP (Vtransient_mark_mode
)
1541 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1542 != !NILP (w
->region_showing
)))
1544 struct buffer
*prev
= current_buffer
;
1545 int count
= specpdl_ptr
- specpdl
;
1547 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1548 if (save_match_data
)
1549 record_unwind_protect (Fstore_match_data
, Fmatch_data (Qnil
, Qnil
));
1550 if (NILP (Voverriding_local_map_menu_flag
))
1552 specbind (Qoverriding_terminal_local_map
, Qnil
);
1553 specbind (Qoverriding_local_map
, Qnil
);
1556 /* Run the Lucid hook. */
1557 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1558 /* If it has changed current-menubar from previous value,
1559 really recompute the menubar from the value. */
1560 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1561 call0 (Qrecompute_lucid_menubar
);
1562 safe_run_hooks (Qmenu_bar_update_hook
);
1563 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1564 /* Redisplay the menu bar in case we changed it. */
1565 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1566 if (FRAME_WINDOW_P (f
))
1567 set_frame_menubar (f
, 0, 0);
1569 /* On a terminal screen, the menu bar is an ordinary screen
1570 line, and this makes it get updated. */
1571 w
->update_mode_line
= Qt
;
1572 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1573 /* In the non-toolkit version, the menu bar is an ordinary screen
1574 line, and this makes it get updated. */
1575 w
->update_mode_line
= Qt
;
1576 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1578 unbind_to (count
, Qnil
);
1579 set_buffer_internal_1 (prev
);
1586 /* Redisplay WINDOW and its subwindows and siblings. */
1589 redisplay_windows (window
, preserve_echo_area
)
1591 int preserve_echo_area
;
1593 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1594 redisplay_window (window
, 0, preserve_echo_area
);
1597 /* Return value in display table DP (Lisp_Char_Table *) for character
1598 C. Since a display table doesn't have any parent, we don't have to
1599 follow parent. Do not call this function directly but use the
1600 macro DISP_CHAR_VECTOR. */
1602 disp_char_vector (dp
, c
)
1603 struct Lisp_Char_Table
*dp
;
1609 if (SINGLE_BYTE_CHAR_P (c
)) return (dp
->contents
[c
]);
1611 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
1612 if (code
[0] != CHARSET_COMPOSITION
)
1614 if (code
[1] < 32) code
[1] = -1;
1615 else if (code
[2] < 32) code
[2] = -1;
1617 /* Here, the possible range of CODE[0] (== charset ID) is
1618 128..MAX_CHARSET. Since the top level char table contains data
1619 for multibyte characters after 256th element, we must increment
1620 CODE[0] by 128 to get a correct index. */
1622 code
[3] = -1; /* anchor */
1624 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
1626 val
= dp
->contents
[code
[i
]];
1627 if (!SUB_CHAR_TABLE_P (val
))
1628 return (NILP (val
) ? dp
->defalt
: val
);
1630 /* Here, VAL is a sub char table. We return the default value of it. */
1631 return (dp
->defalt
);
1634 /* Redisplay window WINDOW and its subwindows. */
1637 redisplay_window (window
, just_this_one
, preserve_echo_area
)
1639 int just_this_one
, preserve_echo_area
;
1641 register struct window
*w
= XWINDOW (window
);
1642 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1644 register int lpoint
= PT
;
1645 struct buffer
*old
= current_buffer
;
1646 register int width
= window_internal_width (w
) - 1;
1647 register int startp
;
1648 register int hscroll
= XINT (w
->hscroll
);
1649 struct position pos
;
1652 int update_mode_line
;
1653 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1655 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1657 /* If this is a combination window, do its children; that's all. */
1659 if (!NILP (w
->vchild
))
1661 redisplay_windows (w
->vchild
, preserve_echo_area
);
1664 if (!NILP (w
->hchild
))
1666 redisplay_windows (w
->hchild
, preserve_echo_area
);
1669 if (NILP (w
->buffer
))
1672 height
= window_internal_height (w
);
1673 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1674 if (XBUFFER (w
->buffer
)->clip_changed
)
1675 update_mode_line
= 1;
1677 if (MINI_WINDOW_P (w
))
1679 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1680 /* We've already displayed the echo area glyphs in this window. */
1681 goto finish_scroll_bars
;
1682 else if (w
!= XWINDOW (minibuf_window
))
1684 /* This is a minibuffer, but it's not the currently active one,
1686 int vpos
= XFASTINT (w
->top
);
1689 for (i
= 0; i
< height
; i
++)
1691 get_display_line (f
, vpos
+ i
, 0);
1692 display_string (w
, vpos
+ i
, "", 0,
1693 FRAME_LEFT_SCROLL_BAR_WIDTH (f
),
1697 goto finish_scroll_bars
;
1701 /* Otherwise set up data on this window; select its buffer and point value */
1703 if (update_mode_line
)
1704 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1706 set_buffer_temp (XBUFFER (w
->buffer
));
1710 /* If %c is in mode line, update it if needed. */
1711 if (!NILP (w
->column_number_displayed
)
1712 /* This alternative quickly identifies a common case
1713 where no change is needed. */
1714 && !(PT
== XFASTINT (w
->last_point
)
1715 && XFASTINT (w
->last_modified
) >= MODIFF
1716 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
1717 && XFASTINT (w
->column_number_displayed
) != current_column ())
1718 update_mode_line
= 1;
1720 /* Count number of windows showing the selected buffer.
1721 An indirect buffer counts as its base buffer. */
1725 struct buffer
*current_base
, *window_base
;
1726 current_base
= current_buffer
;
1727 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1728 if (current_base
->base_buffer
)
1729 current_base
= current_base
->base_buffer
;
1730 if (window_base
->base_buffer
)
1731 window_base
= window_base
->base_buffer
;
1732 if (current_base
== window_base
)
1736 /* POINT refers normally to the selected window.
1737 For any other window, set up appropriate value. */
1739 if (!EQ (window
, selected_window
))
1741 int new_pt
= marker_position (w
->pointm
);
1745 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1747 else if (new_pt
> (ZV
- 1))
1750 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1752 /* We don't use SET_PT so that the point-motion hooks don't run. */
1753 BUF_PT (current_buffer
) = new_pt
;
1756 /* If any of the character widths specified in the display table
1757 have changed, invalidate the width run cache. It's true that this
1758 may be a bit late to catch such changes, but the rest of
1759 redisplay goes (non-fatally) haywire when the display table is
1760 changed, so why should we worry about doing any better? */
1761 if (current_buffer
->width_run_cache
)
1763 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1765 if (! disptab_matches_widthtab (disptab
,
1766 XVECTOR (current_buffer
->width_table
)))
1768 invalidate_region_cache (current_buffer
,
1769 current_buffer
->width_run_cache
,
1771 recompute_width_table (current_buffer
, disptab
);
1775 /* If window-start is screwed up, choose a new one. */
1776 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1779 startp
= marker_position (w
->start
);
1781 /* If someone specified a new starting point but did not insist,
1782 check whether it can be used. */
1783 if (!NILP (w
->optional_new_start
))
1785 w
->optional_new_start
= Qnil
;
1786 /* Check whether this start pos is usable given where point is. */
1788 pos
= *compute_motion (startp
, 0,
1789 (((EQ (window
, minibuf_window
)
1791 ? minibuf_prompt_width
: 0)
1792 + (hscroll
? 1 - hscroll
: 0)),
1795 /* BUG FIX: See the comment of
1796 Fpos_visible_in_window_p (window.c). */
1797 - (1 << (BITS_PER_SHORT
- 1)),
1798 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1799 /* If PT does fit on the screen, we will use this start pos,
1800 so do so by setting force_start. */
1801 if (pos
.bufpos
== PT
)
1802 w
->force_start
= Qt
;
1805 /* Handle case where place to start displaying has been specified,
1806 unless the specified location is outside the accessible range. */
1807 if (!NILP (w
->force_start
))
1809 w
->force_start
= Qnil
;
1810 /* Forget any recorded base line for line number display. */
1811 w
->base_line_number
= Qnil
;
1812 /* Redisplay the mode line. Select the buffer properly for that.
1813 Also, run the hook window-scroll-functions
1814 because we have scrolled. */
1815 /* Note, we do this after clearing force_start because
1816 if there's an error, it is better to forget about force_start
1817 than to get into an infinite loop calling the hook functions
1818 and having them get more errors. */
1819 if (!update_mode_line
1820 || ! NILP (Vwindow_scroll_functions
))
1822 Lisp_Object temp
[3];
1824 set_buffer_temp (old
);
1825 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1826 update_mode_line
= 1;
1827 w
->update_mode_line
= Qt
;
1828 if (! NILP (Vwindow_scroll_functions
))
1830 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1831 make_number (startp
));
1832 startp
= marker_position (w
->start
);
1835 XSETFASTINT (w
->last_modified
, 0);
1836 XSETFASTINT (w
->last_overlay_modified
, 0);
1837 if (startp
< BEGV
) startp
= BEGV
;
1838 if (startp
> ZV
) startp
= ZV
;
1839 try_window (window
, startp
);
1840 if (cursor_vpos
< 0)
1842 /* If point does not appear, move point so it does appear */
1843 pos
= *compute_motion (startp
, 0,
1844 (((EQ (window
, minibuf_window
)
1846 ? minibuf_prompt_width
: 0)
1847 + (hscroll
? 1 - hscroll
: 0)),
1850 - (1 << (BITS_PER_SHORT
- 1)),
1851 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1852 BUF_PT (current_buffer
) = pos
.bufpos
;
1853 if (w
!= XWINDOW (selected_window
))
1854 Fset_marker (w
->pointm
, make_number (PT
), Qnil
);
1857 if (current_buffer
== old
)
1859 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
1860 + minmax (0, pos
.hpos
, width
));
1861 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1863 /* If we are highlighting the region,
1864 then we just changed the region, so redisplay to show it. */
1865 if (!NILP (Vtransient_mark_mode
)
1866 && !NILP (current_buffer
->mark_active
))
1868 cancel_my_columns (XWINDOW (window
));
1869 try_window (window
, startp
);
1875 /* Handle case where text has not changed, only point,
1876 and it has not moved off the frame. */
1878 /* This code is not used for minibuffer for the sake of
1879 the case of redisplaying to replace an echo area message;
1880 since in that case the minibuffer contents per se are usually unchanged.
1881 This code is of no real use in the minibuffer since
1882 the handling of this_line_bufpos, etc.,
1883 in redisplay handles the same cases. */
1885 if (XFASTINT (w
->last_modified
) >= MODIFF
1886 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
1887 && PT
>= startp
&& !current_buffer
->clip_changed
1888 && (just_this_one
|| WINDOW_FULL_WIDTH_P (w
))
1889 /* If force-mode-line-update was called, really redisplay;
1890 that's how redisplay is forced after e.g. changing
1891 buffer-invisibility-spec. */
1892 && NILP (w
->update_mode_line
)
1893 /* Can't use this case if highlighting a region. */
1894 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
1895 && NILP (w
->region_showing
)
1896 /* If end pos is out of date, scroll bar and percentage will be wrong */
1897 && INTEGERP (w
->window_end_vpos
)
1898 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
1899 && !EQ (window
, minibuf_window
)
1900 && (!MARKERP (Voverlay_arrow_position
)
1901 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
1903 /* All positions in this clause are relative to the window edge. */
1905 int this_scroll_margin
= scroll_margin
;
1906 int last_point_y
= XFASTINT (w
->last_point_y
) - XINT (w
->top
);
1907 int last_point_x
= (XFASTINT (w
->last_point_x
) - WINDOW_LEFT_MARGIN (w
));
1909 /* Find where PT is located now on the frame. */
1910 /* Check just_this_one as a way of verifying that the
1911 window edges have not changed. */
1912 if (PT
== XFASTINT (w
->last_point
) && just_this_one
)
1914 pos
.hpos
= last_point_x
;
1915 pos
.vpos
= last_point_y
;
1918 else if (PT
> XFASTINT (w
->last_point
)
1919 && XFASTINT (w
->last_point
) > startp
&& just_this_one
1920 /* We can't use this if point is in the left margin of a
1921 hscrolled window, because w->last_point_x has been
1922 clipped to the window edges. */
1923 && !(last_point_x
<= 0 && hscroll
))
1925 pos
= *compute_motion (XFASTINT (w
->last_point
),
1926 last_point_y
, last_point_x
, 0,
1928 /* BUG FIX: See the comment of
1929 Fpos_visible_in_window_p (window.c). */
1930 - (1 << (BITS_PER_SHORT
- 1)),
1932 pos_tab_offset (w
, startp
), w
);
1936 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
1938 /* BUG FIX: See the comment of
1939 Fpos_visible_in_window_p (window.c). */
1940 - (1 << (BITS_PER_SHORT
- 1)),
1942 pos_tab_offset (w
, startp
), w
);
1945 /* Don't use a scroll margin that is negative or too large. */
1946 if (this_scroll_margin
< 0)
1947 this_scroll_margin
= 0;
1949 if (XINT (w
->height
) < 4 * scroll_margin
)
1950 this_scroll_margin
= XINT (w
->height
) / 4;
1952 /* If point fits on the screen, and not within the scroll margin,
1954 if (pos
.vpos
< height
- this_scroll_margin
1955 && (pos
.vpos
>= this_scroll_margin
|| startp
== BEGV
))
1957 /* Ok, point is still on frame */
1958 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
1960 /* These variables are supposed to be origin 1 */
1961 FRAME_CURSOR_X (f
) = (WINDOW_LEFT_MARGIN (w
)
1962 + minmax (0, pos
.hpos
, width
));
1963 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1965 /* This doesn't do the trick, because if a window to the right of
1966 this one must be redisplayed, this does nothing because there
1967 is nothing in DesiredFrame yet, and then the other window is
1968 redisplayed, making likes that are empty in this window's columns.
1969 if (WINDOW_FULL_WIDTH_P (w))
1970 preserve_my_columns (w);
1972 if (current_buffer
->clip_changed
1973 && ! NILP (Vwindow_scroll_functions
))
1974 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1975 make_number (marker_position (w
->start
)));
1979 /* Don't bother trying redisplay with same start;
1980 we already know it will lose */
1982 /* If current starting point was originally the beginning of a line
1983 but no longer is, find a new starting point. */
1984 else if (!NILP (w
->start_at_line_beg
)
1986 || FETCH_BYTE (startp
- 1) == '\n'))
1990 else if (just_this_one
&& !MINI_WINDOW_P (w
)
1992 && XFASTINT (w
->last_modified
)
1993 /* or else vmotion on first line won't work. */
1994 && ! NILP (w
->start_at_line_beg
)
1995 && ! EQ (w
->window_end_valid
, Qnil
)
1996 && do_id
&& !current_buffer
->clip_changed
1997 && !blank_end_of_window
1998 && WINDOW_FULL_WIDTH_P (w
)
1999 /* Can't use this case if highlighting a region. */
2000 && !(!NILP (Vtransient_mark_mode
)
2001 && !NILP (current_buffer
->mark_active
))
2002 /* Don't use try_window_id if newline
2003 doesn't display as the end of a line. */
2004 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
2005 && NILP (w
->region_showing
)
2006 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
2007 && EQ (last_arrow_string
, Voverlay_arrow_string
)
2008 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
2011 /* tem > 0 means success. tem == -1 means choose new start.
2012 tem == -2 means try again with same start,
2013 and nothing but whitespace follows the changed stuff.
2014 tem == 0 means try again with same start. */
2018 else if (startp
>= BEGV
&& startp
<= ZV
2020 /* Avoid starting at end of buffer. */
2021 #if 0 /* This change causes trouble for M-! finger & RET.
2022 It will have to be considered later. */
2023 || ! EQ (window
, selected_window
)
2024 /* Don't do the recentering if redisplay
2025 is not for no user action. */
2026 || preserve_echo_area
2029 || (XFASTINT (w
->last_modified
) >= MODIFF
2030 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
2032 /* Try to redisplay starting at same place as before */
2033 /* If point has not moved off frame, accept the results */
2034 try_window (window
, startp
);
2035 if (cursor_vpos
>= 0)
2037 if (!just_this_one
|| current_buffer
->clip_changed
2038 || beg_unchanged
< startp
)
2039 /* Forget any recorded base line for line number display. */
2040 w
->base_line_number
= Qnil
;
2042 if (current_buffer
->clip_changed
2043 && ! NILP (Vwindow_scroll_functions
))
2044 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2045 make_number (marker_position (w
->start
)));
2050 cancel_my_columns (w
);
2053 XSETFASTINT (w
->last_modified
, 0);
2054 XSETFASTINT (w
->last_overlay_modified
, 0);
2055 /* Redisplay the mode line. Select the buffer properly for that. */
2056 if (!update_mode_line
)
2058 set_buffer_temp (old
);
2059 set_buffer_internal_1 (XBUFFER (w
->buffer
));
2060 update_mode_line
= 1;
2061 w
->update_mode_line
= Qt
;
2064 /* Try to scroll by specified few lines */
2066 if (scroll_conservatively
&& !current_buffer
->clip_changed
2067 && startp
>= BEGV
&& startp
<= ZV
)
2069 int this_scroll_margin
= scroll_margin
;
2070 int scroll_margin_pos
;
2072 /* Don't use a scroll margin that is negative or too large. */
2073 if (this_scroll_margin
< 0)
2074 this_scroll_margin
= 0;
2076 if (XINT (w
->height
) < 4 * this_scroll_margin
)
2077 this_scroll_margin
= XINT (w
->height
) / 4;
2079 scroll_margin_pos
= Z
- XFASTINT (w
->window_end_pos
);
2080 if (this_scroll_margin
)
2082 pos
= *vmotion (scroll_margin_pos
, -this_scroll_margin
, w
);
2083 scroll_margin_pos
= pos
.bufpos
;
2085 if (PT
>= scroll_margin_pos
)
2087 struct position pos
;
2088 pos
= *compute_motion (scroll_margin_pos
, 0, 0, 0,
2089 PT
, XFASTINT (w
->height
), 0,
2090 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2091 pos_tab_offset (w
, startp
), w
);
2092 if (pos
.vpos
> scroll_conservatively
)
2095 pos
= *vmotion (startp
, pos
.vpos
+ 1, w
);
2097 if (! NILP (Vwindow_scroll_functions
))
2099 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2100 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2101 make_number (pos
.bufpos
));
2102 pos
.bufpos
= marker_position (w
->start
);
2104 try_window (window
, pos
.bufpos
);
2105 if (cursor_vpos
>= 0)
2107 if (!just_this_one
|| current_buffer
->clip_changed
2108 || beg_unchanged
< startp
)
2109 /* Forget any recorded base line for line number display. */
2110 w
->base_line_number
= Qnil
;
2114 cancel_my_columns (w
);
2117 scroll_margin_pos
= startp
;
2118 if (this_scroll_margin
)
2120 pos
= *vmotion (scroll_margin_pos
, this_scroll_margin
, w
);
2121 scroll_margin_pos
= pos
.bufpos
;
2123 if (PT
< scroll_margin_pos
)
2125 struct position pos
;
2126 pos
= *compute_motion (PT
, 0, 0, 0,
2127 scroll_margin_pos
, XFASTINT (w
->height
), 0,
2128 XFASTINT (w
->width
), XFASTINT (w
->hscroll
),
2129 pos_tab_offset (w
, startp
), w
);
2130 if (pos
.vpos
> scroll_conservatively
)
2133 pos
= *vmotion (startp
, -pos
.vpos
, w
);
2135 if (! NILP (Vwindow_scroll_functions
))
2137 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2138 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2139 make_number (pos
.bufpos
));
2140 pos
.bufpos
= marker_position (w
->start
);
2142 try_window (window
, pos
.bufpos
);
2143 if (cursor_vpos
>= 0)
2145 if (!just_this_one
|| current_buffer
->clip_changed
2146 || beg_unchanged
< startp
)
2147 /* Forget any recorded base line for line number display. */
2148 w
->base_line_number
= Qnil
;
2152 cancel_my_columns (w
);
2157 if (scroll_step
&& !current_buffer
->clip_changed
2158 && startp
>= BEGV
&& startp
<= ZV
)
2162 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
2163 if (pos
.vpos
>= height
)
2167 pos
= *vmotion (startp
, (PT
< startp
? - scroll_step
: scroll_step
), w
);
2169 if (PT
>= pos
.bufpos
)
2171 if (! NILP (Vwindow_scroll_functions
))
2173 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2174 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2175 make_number (pos
.bufpos
));
2176 pos
.bufpos
= marker_position (w
->start
);
2178 try_window (window
, pos
.bufpos
);
2179 if (cursor_vpos
>= 0)
2181 if (!just_this_one
|| current_buffer
->clip_changed
2182 || beg_unchanged
< startp
)
2183 /* Forget any recorded base line for line number display. */
2184 w
->base_line_number
= Qnil
;
2188 cancel_my_columns (w
);
2193 /* Finally, just choose place to start which centers point */
2196 /* Forget any previously recorded base line for line number display. */
2197 w
->base_line_number
= Qnil
;
2199 pos
= *vmotion (PT
, - (height
/ 2), w
);
2201 /* The minibuffer is often just one line. Ordinary scrolling
2202 gives little overlap and looks bad. So show 20 chars before point. */
2204 && (pos
.bufpos
>= PT
- minibuffer_scroll_overlap
2205 /* If we scrolled less than 1/2 line forward, we will
2206 get too much overlap, so change to the usual amount. */
2207 || pos
.bufpos
< startp
+ width
/ 2)
2208 && PT
> BEGV
+ minibuffer_scroll_overlap
2209 /* If we scrolled to an actual line boundary,
2210 that's different; don't ignore line boundaries. */
2211 && FETCH_CHAR (pos
.bufpos
- 1) != '\n')
2212 pos
.bufpos
= PT
- minibuffer_scroll_overlap
;
2214 /* Set startp here explicitly in case that helps avoid an infinite loop
2215 in case the window-scroll-functions functions get errors. */
2216 Fset_marker (w
->start
, make_number (pos
.bufpos
), Qnil
);
2217 if (! NILP (Vwindow_scroll_functions
))
2219 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2220 make_number (pos
.bufpos
));
2221 pos
.bufpos
= marker_position (w
->start
);
2223 try_window (window
, pos
.bufpos
);
2225 startp
= marker_position (w
->start
);
2226 w
->start_at_line_beg
2227 = (startp
== BEGV
|| FETCH_BYTE (startp
- 1) == '\n') ? Qt
: Qnil
;
2230 if ((update_mode_line
2231 /* If window not full width, must redo its mode line
2232 if the window to its side is being redone */
2233 || (!just_this_one
&& !WINDOW_FULL_WIDTH_P (w
))
2234 || INTEGERP (w
->base_line_pos
)
2235 || (!NILP (w
->column_number_displayed
)
2236 && XFASTINT (w
->column_number_displayed
) != current_column ()))
2237 && height
!= XFASTINT (w
->height
))
2238 display_mode_line (w
);
2239 if (! line_number_displayed
2240 && ! BUFFERP (w
->base_line_pos
))
2242 w
->base_line_pos
= Qnil
;
2243 w
->base_line_number
= Qnil
;
2246 /* When we reach a frame's selected window, redo the frame's menu bar. */
2247 if (update_mode_line
2248 && (FRAME_WINDOW_P (f
)
2250 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2251 FRAME_EXTERNAL_MENU_BAR (f
)
2253 FRAME_MENU_BAR_LINES (f
) > 0
2255 : FRAME_MENU_BAR_LINES (f
) > 0)
2256 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
2257 display_menu_bar (w
);
2260 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2262 int start
, end
, whole
;
2264 /* Calculate the start and end positions for the current window.
2265 At some point, it would be nice to choose between scrollbars
2266 which reflect the whole buffer size, with special markers
2267 indicating narrowing, and scrollbars which reflect only the
2270 Note that minibuffers sometimes aren't displaying any text. */
2271 if (! MINI_WINDOW_P (w
)
2272 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
2275 start
= marker_position (w
->start
) - BEGV
;
2276 /* I don't think this is guaranteed to be right. For the
2277 moment, we'll pretend it is. */
2278 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
2280 if (end
< start
) end
= start
;
2281 if (whole
< (end
- start
)) whole
= end
- start
;
2284 start
= end
= whole
= 0;
2286 /* Indicate what this scroll bar ought to be displaying now. */
2287 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
2289 /* Note that we actually used the scroll bar attached to this window,
2290 so it shouldn't be deleted at the end of redisplay. */
2291 (*redeem_scroll_bar_hook
) (w
);
2294 BUF_PT (current_buffer
) = opoint
;
2295 if (update_mode_line
)
2296 set_buffer_internal_1 (old
);
2298 set_buffer_temp (old
);
2299 BUF_PT (current_buffer
) = lpoint
;
2302 /* Do full redisplay on one window, starting at position `pos'. */
2305 try_window (window
, pos
)
2309 register struct window
*w
= XWINDOW (window
);
2310 register int height
= window_internal_height (w
);
2311 register int vpos
= XFASTINT (w
->top
);
2312 register int last_text_vpos
= vpos
;
2313 FRAME_PTR f
= XFRAME (w
->frame
);
2314 int width
= window_internal_width (w
) - 1;
2315 struct position val
;
2317 /* POS should never be out of range! */
2318 if (pos
< XBUFFER (w
->buffer
)->begv
2319 || pos
> XBUFFER (w
->buffer
)->zv
)
2322 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2324 overlay_arrow_seen
= 0;
2325 zv_strings_seen
= 0;
2326 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2327 val
.ovstring_chars_done
= 0;
2328 val
.tab_offset
= pos_tab_offset (w
, pos
);
2330 while (--height
>= 0)
2332 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, val
.tab_offset
,
2333 val
.ovstring_chars_done
);
2334 /* The following code is omitted because we maintain tab_offset
2337 tab_offset
+= width
;
2338 if (val
.vpos
) tab_offset
= 0;
2341 if (pos
!= val
.bufpos
)
2344 #ifdef USE_TEXT_PROPERTIES
2345 Lisp_Object invis_prop
;
2346 invis_prop
= Fget_char_property (val
.bufpos
-1, Qinvisible
, window
);
2347 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
2351 /* Next line, unless prev line ended in end of buffer with no cr */
2353 && (FETCH_BYTE (val
.bufpos
- 1) != '\n' || invis
));
2358 /* If last line is continued in middle of character,
2359 include the split character in the text considered on the frame */
2360 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2363 /* If bottom just moved off end of frame, change mode line percentage. */
2364 if (XFASTINT (w
->window_end_pos
) == 0
2366 w
->update_mode_line
= Qt
;
2368 /* Say where last char on frame will be, once redisplay is finished. */
2369 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
2370 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
2371 /* But that is not valid info until redisplay finishes. */
2372 w
->window_end_valid
= Qnil
;
2375 /* Try to redisplay when buffer is modified locally,
2376 computing insert/delete line to preserve text outside
2377 the bounds of the changes.
2378 Return 1 if successful, 0 if if cannot tell what to do,
2379 or -1 to tell caller to find a new window start,
2380 or -2 to tell caller to do normal redisplay with same window start. */
2383 try_window_id (window
)
2387 register struct window
*w
= XWINDOW (window
);
2388 register int height
= window_internal_height (w
);
2389 FRAME_PTR f
= XFRAME (w
->frame
);
2390 int top
= XFASTINT (w
->top
);
2391 int start
= marker_position (w
->start
);
2392 int width
= window_internal_width (w
) - 1;
2393 int hscroll
= XINT (w
->hscroll
);
2394 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
2397 register int i
, tem
;
2398 int last_text_vpos
= 0;
2400 int selective
= (INTEGERP (current_buffer
->selective_display
)
2401 ? XINT (current_buffer
->selective_display
)
2402 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2404 struct position val
, bp
, ep
, xp
, pp
;
2405 int scroll_amount
= 0;
2409 if (GPT
- BEG
< beg_unchanged
)
2410 beg_unchanged
= GPT
- BEG
;
2411 if (Z
- GPT
< end_unchanged
)
2412 end_unchanged
= Z
- GPT
;
2414 if (beg_unchanged
+ BEG
< start
)
2415 return 0; /* Give up if changes go above top of window */
2417 /* Find position before which nothing is changed. */
2418 bp
= *compute_motion (start
, 0, lmargin
, 0,
2419 min (ZV
, beg_unchanged
+ BEG
), height
,
2420 /* BUG FIX: See the comment of
2421 Fpos_visible_in_window_p() (window.c). */
2422 - (1 << (BITS_PER_SHORT
- 1)),
2423 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2424 if (bp
.vpos
>= height
)
2428 /* All changes are beyond the window end, and point is on the screen.
2429 We don't need to change the text at all.
2430 But we need to update window_end_pos to account for
2431 any change in buffer size. */
2432 bp
= *compute_motion (start
, 0, lmargin
, 0,
2434 /* BUG FIX: See the comment of
2435 Fpos_visible_in_window_p() (window.c). */
2436 - (1 << (BITS_PER_SHORT
- 1)),
2437 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2438 XSETFASTINT (w
->window_end_vpos
, height
);
2439 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
2447 /* Find beginning of that frame line. Must display from there. */
2448 bp
= *vmotion (bp
.bufpos
, 0, w
);
2456 /* If about to start displaying at the beginning of a continuation line,
2457 really start with previous frame line, in case it was not
2458 continued when last redisplayed */
2459 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
2461 /* Likewise if we have to worry about selective display. */
2462 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
2464 bp
= *vmotion (bp
.bufpos
, -1, w
);
2468 val
.tab_offset
= bp
.tab_offset
; /* Update tab offset. */
2470 if (bp
.contin
&& bp
.hpos
!= lmargin
)
2472 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
2473 val
.tab_offset
= bp
.tab_offset
+ bp
.prevhpos
- width
;
2480 /* Find first visible newline after which no more is changed. */
2481 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
2483 while (tem
< ZV
- 1 && (indented_beyond_p (tem
, selective
)))
2484 tem
= find_next_newline (tem
, 1);
2486 /* Compute the cursor position after that newline. */
2487 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
2488 height
, - (1 << (BITS_PER_SHORT
- 1)),
2490 /* We have tab offset in VAL, use it. */
2493 /* If changes reach past the text available on the frame,
2494 just display rest of frame. */
2495 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
2498 stop_vpos
= ep
.vpos
;
2500 /* If no newline before ep, the line ep is on includes some changes
2501 that must be displayed. Make sure we don't stop before it. */
2502 /* Also, if changes reach all the way until ep.bufpos,
2503 it is possible that something was deleted after the
2504 newline before it, so the following line must be redrawn. */
2505 if (stop_vpos
== ep
.vpos
2506 && (ep
.bufpos
== BEGV
2507 || FETCH_BYTE (ep
.bufpos
- 1) != '\n'
2508 || ep
.bufpos
== Z
- end_unchanged
))
2509 stop_vpos
= ep
.vpos
+ 1;
2512 overlay_arrow_seen
= 0;
2513 zv_strings_seen
= 0;
2515 /* If changes do not reach to bottom of window,
2516 figure out how much to scroll the rest of the window */
2517 if (stop_vpos
< height
)
2519 /* Now determine how far up or down the rest of the window has moved */
2520 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2521 Z
- XFASTINT (w
->window_end_pos
),
2522 /* Don't care for VPOS... */
2523 1 << (BITS_PER_SHORT
- 1),
2525 1 << (BITS_PER_SHORT
- 1),
2526 width
, hscroll
, ep
.tab_offset
, w
);
2527 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2529 /* Is everything on frame below the changes whitespace?
2530 If so, no scrolling is really necessary. */
2531 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
2533 tem
= FETCH_BYTE (i
);
2534 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2540 XSETFASTINT (w
->window_end_vpos
,
2541 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2543 /* Before doing any scrolling, verify that point will be on frame. */
2544 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.vpos
< height
))
2546 if (PT
<= xp
.bufpos
)
2548 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2549 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2551 /* We have tab offset in EP, use it. */
2556 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2557 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2559 /* We have tab offset in XP, use it. */
2562 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2564 cursor_vpos
= pp
.vpos
+ top
;
2565 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, pp
.hpos
, width
);
2568 if (stop_vpos
- scroll_amount
>= height
2569 || ep
.bufpos
== xp
.bufpos
)
2571 if (scroll_amount
< 0)
2572 stop_vpos
-= scroll_amount
;
2574 /* In this path, we have altered window_end_vpos
2575 and not left it negative.
2576 We must make sure that, in case display is preempted
2577 before the frame changes to reflect what we do here,
2578 further updates will not come to try_window_id
2579 and assume the frame and window_end_vpos match. */
2580 blank_end_of_window
= 1;
2582 else if (!scroll_amount
)
2584 /* Even if we don't need to scroll, we must adjust the
2585 charstarts of subsequent lines (that we won't redisplay)
2586 according to the amount of text inserted or deleted. */
2587 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2588 int adjust
= ep
.bufpos
- oldpos
;
2589 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2591 else if (bp
.bufpos
== Z
- end_unchanged
)
2593 /* If reprinting everything is nearly as fast as scrolling,
2594 don't bother scrolling. Can happen if lines are short. */
2595 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2596 top
+ height
- max (0, scroll_amount
),
2598 > xp
.bufpos
- bp
.bufpos
- 20)
2599 /* Return "try normal display with same window-start."
2600 Too bad we can't prevent further scroll-thinking. */
2602 /* If pure deletion, scroll up as many lines as possible.
2603 In common case of killing a line, this can save the
2604 following line from being overwritten by scrolling
2605 and therefore having to be redrawn. */
2606 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2607 top
+ height
- max (0, scroll_amount
),
2608 scroll_amount
, bp
.bufpos
);
2613 /* scroll_frame_lines did not properly adjust subsequent
2614 lines' charstarts in the case where the text of the
2615 screen line at bp.vpos has changed.
2616 (This can happen in a deletion that ends in mid-line.)
2617 To adjust properly, we need to make things consistent
2619 So do a second adjust to make that happen.
2620 Note that stop_vpos >= ep.vpos, so it is sufficient
2621 to update the charstarts for lines at ep.vpos and below. */
2623 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2624 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2625 ep
.bufpos
- oldstart
);
2628 else if (scroll_amount
)
2630 /* If reprinting everything is nearly as fast as scrolling,
2631 don't bother scrolling. Can happen if lines are short. */
2632 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2633 overestimate of cost of reprinting, since xp.bufpos
2634 would end up below the bottom of the window. */
2635 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2636 top
+ height
- max (0, scroll_amount
),
2638 > xp
.bufpos
- ep
.bufpos
- 20)
2639 /* Return "try normal display with same window-start."
2640 Too bad we can't prevent further scroll-thinking. */
2642 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2643 top
+ height
- max (0, scroll_amount
),
2644 scroll_amount
, ep
.bufpos
);
2645 if (!tem
) stop_vpos
= height
;
2649 /* In any case, do not display past bottom of window */
2650 if (stop_vpos
>= height
)
2656 /* Handle case where pos is before w->start --
2657 can happen if part of line had been clipped and is not clipped now */
2658 if (vpos
== 0 && pos
< marker_position (w
->start
))
2659 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2661 /* Redisplay the lines where the text was changed */
2662 last_text_vpos
= vpos
;
2663 /* The following code is omitted because we maintain tab offset in
2666 tab_offset
= pos_tab_offset (w
, pos
);
2667 /* If we are starting display in mid-character, correct tab_offset
2668 to account for passing the line that that character really starts in. */
2669 if (val
.hpos
< lmargin
)
2670 tab_offset
+= width
;
2673 while (vpos
< stop_vpos
)
2675 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, val
.tab_offset
,
2676 val
.ovstring_chars_done
);
2677 /* If display_text_line ran a hook and changed some text,
2678 redisplay all the way to bottom of buffer
2679 So that we show the changes. */
2680 if (old_tick
!= MODIFF
)
2682 /* The following code is omitted because we maintain tab offset
2683 in val.tab_offset. */
2685 tab_offset
+= width
;
2686 if (val
.vpos
) tab_offset
= 0;
2688 if (pos
!= val
.bufpos
)
2690 /* Next line, unless prev line ended in end of buffer with no cr */
2691 = vpos
- (val
.vpos
&& FETCH_BYTE (val
.bufpos
- 1) != '\n');
2695 /* There are two cases:
2696 1) we have displayed down to the bottom of the window
2697 2) we have scrolled lines below stop_vpos by scroll_amount */
2701 /* If last line is continued in middle of character,
2702 include the split character in the text considered on the frame */
2703 if (val
.hpos
< lmargin
)
2705 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2706 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2709 /* If scrolling made blank lines at window bottom,
2710 redisplay to fill those lines */
2711 if (scroll_amount
< 0)
2713 /* Don't consider these lines for general-purpose scrolling.
2714 That will save time in the scrolling computation. */
2715 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2719 val
.tab_offset
= xp
.tab_offset
;
2721 { /* Display from next line */
2722 vpos
= height
+ scroll_amount
;
2726 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2728 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2729 val
.tab_offset
= xp
.tab_offset
+ bp
.prevhpos
- width
;
2733 blank_end_of_window
= 1;
2734 /* The following code is omitted because we maintain tab offset
2735 in val.tab_offset. */
2737 tab_offset
= pos_tab_offset (w
, pos
);
2738 /* If we are starting display in mid-character, correct tab_offset
2739 to account for passing the line that that character starts in. */
2740 if (val
.hpos
< lmargin
)
2741 tab_offset
+= width
;
2743 while (vpos
< height
)
2745 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
,
2746 val
.tab_offset
, val
.ovstring_chars_done
);
2747 /* The following code is omitted because we maintain tab
2748 offset in val.tab_offset. */
2750 tab_offset
+= width
;
2751 if (val
.vpos
) tab_offset
= 0;
2756 /* Here is a case where display_text_line sets cursor_vpos wrong.
2757 Make it be fixed up, below. */
2763 /* If bottom just moved off end of frame, change mode line percentage. */
2764 if (XFASTINT (w
->window_end_pos
) == 0
2766 w
->update_mode_line
= Qt
;
2768 /* Attempt to adjust end-of-text positions to new bottom line */
2771 delta
= height
- xp
.vpos
;
2773 || (delta
> 0 && xp
.bufpos
<= ZV
)
2774 || (delta
== 0 && xp
.hpos
))
2776 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
2777 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2778 XSETFASTINT (w
->window_end_vpos
,
2779 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
2783 w
->window_end_valid
= Qnil
;
2785 /* If point was not in a line that was displayed, find it */
2786 if (cursor_vpos
< 0)
2789 val
= *compute_motion (start
, 0, lmargin
, 0, PT
,
2790 /* Don't care for VPOS... */
2791 1 << (BITS_PER_SHORT
- 1),
2793 1 << (BITS_PER_SHORT
- 1),
2794 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2795 /* Admit failure if point is off frame now */
2796 if (val
.vpos
>= height
)
2798 for (vpos
= 0; vpos
< height
; vpos
++)
2799 cancel_line (vpos
+ top
, f
);
2802 cursor_vpos
= val
.vpos
+ top
;
2803 cursor_hpos
= WINDOW_LEFT_MARGIN (w
) + minmax (0, val
.hpos
, width
);
2806 FRAME_CURSOR_X (f
) = cursor_hpos
;
2807 FRAME_CURSOR_Y (f
) = cursor_vpos
;
2811 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
2812 height
, - (1 << (BITS_PER_SHORT
- 1)),
2813 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2814 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
2816 if (XFASTINT (w
->window_end_pos
)
2824 /* Copy LEN glyphs starting address FROM to the rope TO.
2825 But don't actually copy the parts that would come in before S.
2826 Value is TO, advanced past the copied data.
2827 F is the frame we are displaying in. */
2830 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
2832 register GLYPH
*to
; /* Copy to here. */
2833 register GLYPH
*s
; /* Starting point. */
2834 Lisp_Object
*from
; /* Data to copy. */
2836 int face
; /* Face to apply to glyphs which don't specify one. */
2839 register Lisp_Object
*fp
= from
;
2840 /* These cache the results of the last call to compute_glyph_face. */
2842 int last_merged
= 0;
2845 if (! FRAME_TERMCAP_P (f
))
2848 GLYPH glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2850 unsigned int c
= FAST_GLYPH_CHAR (glyph
);
2853 /* For an invalid character code, use space. */
2856 if (FAST_GLYPH_FACE (glyph
) == 0)
2857 /* If GLYPH has no face code, use FACE. */
2859 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
2860 /* If it's same as previous glyph, use same result. */
2861 facecode
= last_merged
;
2864 /* Merge this glyph's face and remember the result. */
2865 last_code
= FAST_GLYPH_FACE (glyph
);
2866 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
2870 *to
= FAST_MAKE_GLYPH (c
, facecode
);
2878 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2885 /* Correct a glyph by replacing its specified user-level face code
2886 with a displayable computed face code. */
2889 fix_glyph (f
, glyph
, cface
)
2895 if (! FRAME_TERMCAP_P (f
))
2897 if (FAST_GLYPH_FACE (glyph
) != 0)
2898 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
2899 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
2905 /* Display one line of window W, starting at position START in W's buffer.
2907 Display starting at horizontal position HPOS, expressed relative to
2908 W's left edge. In situations where the text at START shouldn't
2909 start at the left margin (i.e. when the window is hscrolled, or
2910 we're continuing a line which left off in the midst of a
2911 multi-column character), HPOS should be negative; we throw away
2912 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2915 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2917 OVSTR_DONE is the number of chars of overlay before/after strings
2918 at this position which have already been processed.
2920 Display on position VPOS on the frame. It is origin 0, relative to
2921 the top of the frame, not W.
2923 Returns a STRUCT POSITION giving character to start next line with
2924 and where to display it, including a zero or negative hpos.
2925 The vpos field is not really a vpos; it is 1 unless the line is continued */
2927 struct position val_display_text_line
;
2929 static struct position
*
2930 display_text_line (w
, start
, vpos
, hpos
, taboffset
, ovstr_done
)
2938 register int pos
= start
;
2942 register unsigned char *p
;
2944 register GLYPH
*leftmargin
;
2945 register GLYPH
*p1prev
;
2946 register GLYPH
*p1start
;
2949 FRAME_PTR f
= XFRAME (w
->frame
);
2950 int tab_width
= XINT (current_buffer
->tab_width
);
2951 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
2952 int width
= window_internal_width (w
) - 1;
2953 struct position val
;
2956 int last_invis_skip
= 0;
2957 Lisp_Object last_invis_prop
;
2958 int hscroll
= XINT (w
->hscroll
);
2959 int truncate
= (hscroll
2960 || (truncate_partial_width_windows
2961 && !WINDOW_FULL_WIDTH_P (w
))
2962 || !NILP (current_buffer
->truncate_lines
));
2964 /* 1 if this buffer has a region to highlight. */
2965 int highlight_region
2966 = (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
)
2967 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2968 int region_beg
, region_end
;
2970 int selective
= (INTEGERP (current_buffer
->selective_display
)
2971 ? XINT (current_buffer
->selective_display
)
2972 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2973 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
2974 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
2976 Lisp_Object default_invis_vector
[3];
2977 /* Number of characters of ellipsis to display after an invisible line
2978 if it calls for an ellipsis.
2979 Note that this value can be nonzero regardless of whether
2980 selective display is enabled--you must check that separately. */
2982 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2983 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
2984 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
2985 /* This is the sequence of Lisp objects to display
2986 when there are invisible lines. */
2987 Lisp_Object
*invis_vector_contents
2988 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2989 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
2990 : default_invis_vector
);
2992 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
2993 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp
)))
2994 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
2995 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
2996 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp
)))
2997 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
2999 /* If 1, we must handle multibyte characters. */
3000 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
3001 /* Length of multibyte form of each character. */
3003 /* Glyphs generated should be set this bit mask if text must be
3004 displayed from right to left. */
3005 GLYPH rev_dir_bit
= (NILP (current_buffer
->direction_reversed
)
3006 ? 0 : GLYPH_MASK_REV_DIR
);
3008 /* The next buffer location at which the face should change, due
3009 to overlays or text property changes. */
3010 int next_face_change
;
3012 /* The next location where the `invisible' property changes, or an
3013 overlay starts or ends. */
3016 /* The face we're currently using. */
3017 int current_face
= 0;
3020 XSETFASTINT (default_invis_vector
[2], '.');
3021 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
3023 get_display_line (f
, vpos
, WINDOW_LEFT_MARGIN (w
));
3024 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
3026 /* Show where to highlight the region. */
3027 if (highlight_region
3028 /* Maybe highlight only in selected window. */
3029 && (highlight_nonselected_windows
3030 || w
== XWINDOW (selected_window
)
3031 || (MINI_WINDOW_P (XWINDOW (selected_window
))
3032 && w
== XWINDOW (Vminibuf_scroll_window
))))
3034 region_beg
= marker_position (current_buffer
->mark
);
3035 if (PT
< region_beg
)
3037 region_end
= region_beg
;
3042 w
->region_showing
= Qt
;
3046 region_beg
= region_end
= -1;
3047 w
->region_showing
= Qnil
;
3050 if (MINI_WINDOW_P (w
)
3052 && vpos
== XFASTINT (w
->top
))
3054 if (! NILP (minibuf_prompt
))
3056 int old_width
= minibuf_prompt_width
;
3058 minibuf_prompt_width
3059 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
3060 XSTRING (minibuf_prompt
)->size
,
3061 hpos
+ WINDOW_LEFT_MARGIN (w
),
3062 /* Display a space if we truncate. */
3065 /* Truncate the prompt a little before the
3066 margin, so user input can at least start
3067 on the first line. */
3068 (XFASTINT (w
->width
) > 10
3069 ? XFASTINT (w
->width
) - 4 : -1),
3071 - hpos
- WINDOW_LEFT_MARGIN (w
));
3072 hpos
+= minibuf_prompt_width
;
3073 taboffset
-= minibuf_prompt_width
- old_width
;
3076 minibuf_prompt_width
= 0;
3079 /* If we're hscrolled at all, use compute_motion to skip over any
3080 text off the left edge of the window. compute_motion may know
3081 tricks to do this faster than we can. */
3084 struct position
*left_edge
3085 = compute_motion (pos
, vpos
, hpos
, 0,
3087 width
, hscroll
, taboffset
, w
);
3089 /* Retrieve the buffer position and column provided by
3090 compute_motion. We can't assume that the column will be
3091 zero, because you may have multi-column characters crossing
3094 compute_motion may have moved us past the screen position we
3095 requested, if we hit a multi-column character, or the end of
3096 the line. If so, back up. */
3097 if (left_edge
->vpos
> vpos
3098 || left_edge
->hpos
> 0)
3100 pos
= left_edge
->bufpos
;
3101 /* Since this should not be a valid multibyte character, we
3102 can decrease POS by 1. */
3104 hpos
= left_edge
->prevhpos
;
3108 pos
= left_edge
->bufpos
;
3109 hpos
= left_edge
->hpos
;
3113 hpos
+= WINDOW_LEFT_MARGIN (w
);
3115 desired_glyphs
->bufp
[vpos
] = start
;
3116 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
3118 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
3119 /* In case we don't ever write anything into it... */
3120 desired_glyphs
->charstarts
[vpos
][WINDOW_LEFT_MARGIN (w
)] = -1;
3121 leftmargin
= desired_glyphs
->glyphs
[vpos
] + WINDOW_LEFT_MARGIN (w
);
3122 endp
= leftmargin
+ width
;
3124 /* Arrange the overlays nicely for our purposes. Usually, we call
3125 display_text_line on only one line at a time, in which case this
3126 can't really hurt too much, or we call it on lines which appear
3127 one after another in the buffer, in which case all calls to
3128 recenter_overlay_lists but the first will be pretty cheap. */
3129 recenter_overlay_lists (current_buffer
, pos
);
3131 /* Loop generating characters.
3132 Stop at end of buffer, before newline,
3133 if reach or pass continuation column,
3134 or at face change. */
3136 next_face_change
= pos
;
3137 next_boundary
= pos
;
3141 /* If the window is hscrolled and point is in the invisible part of the
3142 current line beyond the left margin we can record the cursor location
3144 if (hscroll
&& start
<= PT
&& PT
< pos
&& cursor_vpos
< 0)
3147 cursor_hpos
= p1
- leftmargin
;
3156 while (pos
== next_boundary
)
3158 Lisp_Object position
, limit
, prop
, ww
;
3160 /* Display the overlay strings here, unless we're at ZV
3161 and have already displayed the appropriate strings
3162 on an earlier line. */
3163 if (pos
< ZV
|| !zv_strings_seen
++)
3166 unsigned char *ovstr
;
3167 ovlen
= overlay_strings (pos
, w
, &ovstr
);
3171 /* Skip the ones we did in a previous line. */
3172 ovstr
+= ovstr_done
;
3173 ovlen
-= ovstr_done
;
3182 c
= STRING_CHAR_AND_LENGTH (ovstr
, ovlen
, len
);
3183 ovstr
+= len
, ovlen
-= len
, ovstr_done
+= len
;
3184 charset
= CHAR_CHARSET (c
);
3185 cols
= (charset
== CHARSET_COMPOSITION
3186 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3187 : CHARSET_WIDTH (charset
));
3191 c
= *ovstr
++, ovlen
--, ovstr_done
++;
3194 g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3197 if (p1
>= leftmargin
&& p1
< endp
)
3198 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3202 /* If we did all the overlay strings
3203 and we have room for text, clear ovstr_done
3204 just for neatness' sake. */
3205 if (ovlen
== 0 && p1
< endp
)
3210 /* Did we reach point? Record the cursor location. */
3211 if (pos
== PT
&& cursor_vpos
< 0)
3214 cursor_hpos
= p1
- leftmargin
;
3220 XSETFASTINT (position
, pos
);
3221 limit
= Fnext_overlay_change (position
);
3222 #ifdef USE_TEXT_PROPERTIES
3223 /* This is just an estimate to give reasonable
3224 performance; nothing should go wrong if it is too small. */
3225 if (XFASTINT (limit
) > pos
+ 50)
3227 int limitpos
= pos
+ 50;
3229 INC_POS (limitpos
); /* Adjust to character boundary. */
3230 XSETFASTINT (limit
, limitpos
);
3232 limit
= Fnext_single_property_change (position
, Qinvisible
,
3233 Fcurrent_buffer (), limit
);
3235 next_boundary
= XFASTINT (limit
);
3236 /* if the `invisible' property is set, we can skip to
3237 the next property change. */
3239 prop
= Fget_char_property (position
, Qinvisible
, ww
);
3240 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3242 if (pos
< PT
&& next_boundary
>= PT
)
3245 cursor_hpos
= p1
- leftmargin
;
3247 pos
= next_boundary
;
3248 last_invis_skip
= pos
;
3249 last_invis_prop
= prop
;
3253 /* Did we reach point? Record the cursor location. */
3254 if (pos
== PT
&& cursor_vpos
< 0)
3257 cursor_hpos
= p1
- leftmargin
;
3260 /* Did we hit the end of the visible region of the buffer?
3264 /* Update charstarts for the end of this line. */
3265 /* Do nothing if off the left edge or at the right edge. */
3266 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
3268 int *p2x
= &charstart
[(p1
< leftmargin
3276 /* Figure out where (if at all) the
3277 redisplay_end_trigger-hook should run. */
3278 if (MARKERP (w
->redisplay_end_trigger
)
3279 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
3280 e_t_h
= marker_position (w
->redisplay_end_trigger
);
3281 else if (INTEGERP (w
->redisplay_end_trigger
))
3282 e_t_h
= XINT (w
->redisplay_end_trigger
);
3286 /* If we've gone past the place to run a hook,
3288 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
3290 Lisp_Object args
[3];
3292 args
[0] = Qredisplay_end_trigger_functions
;
3293 XSETWINDOW (args
[1], w
);
3294 XSETINT (args
[2], e_t_h
);
3296 /* Since we are *trying* to run these functions,
3297 don't try to run them again, even if they get an error. */
3298 w
->redisplay_end_trigger
= Qnil
;
3299 Frun_hook_with_args (3, args
);
3302 /* Notice if it changed the face of this character. */
3303 next_face_change
= pos
;
3307 /* Did we hit a face change? Figure out what face we should
3308 use now. We also hit this the first time through the
3309 loop, to see what face we should start with. */
3310 if (pos
>= next_face_change
3311 && (FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
)))
3313 int limit
= pos
+ 50;
3315 if (limit
< Z
&& !CHAR_HEAD_P (POS_ADDR (limit
)))
3316 INC_POS (limit
); /* Adjust to character boundary. */
3317 current_face
= compute_char_face (f
, w
, pos
,
3318 region_beg
, region_end
,
3319 &next_face_change
, limit
, 0);
3323 /* Compute the next place we need to stop
3324 and do something special; set PAUSE. */
3328 if (pos
< next_boundary
&& next_boundary
< pause
)
3329 pause
= next_boundary
;
3330 if (pos
< next_face_change
&& next_face_change
< pause
)
3331 pause
= next_face_change
;
3336 /* Wouldn't you hate to read the next line to someone over
3338 if (pos
< PT
&& PT
< pause
)
3340 if (pos
< GPT
&& GPT
< pause
)
3352 /* PAUSE is surely at character boundary. */
3353 c
= STRING_CHAR_AND_LENGTH (p
, pause
- pos
, len
), p
+= len
;
3356 /* Let a display table override all standard display methods. */
3357 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3359 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
3360 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3361 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3362 current_face
, rev_dir_bit
);
3364 else if (c
>= 040 && c
< 0177)
3366 if (p1
>= leftmargin
)
3367 *p1
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3373 /* Same as p1prev, but after the invis_vector_contents text
3374 (if we have that on this line). */
3375 GLYPH
*p1prev_modified
;
3379 if (last_invis_skip
== pos
3380 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
3384 && indented_beyond_p (pos
+ 1, selective
))
3387 pos
= find_next_newline (pos
+ 1, 1);
3388 if (FETCH_BYTE (pos
- 1) == '\n')
3391 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
3396 cs
= charstart
+ (p1
- p1start
);
3399 p1
+= selective_rlen
;
3400 if (p1
- leftmargin
> width
)
3403 #if 0 /* This needs more work; charstarts needs to record
3404 both whether a position ho;ds an ellipsis character
3405 and what buffer position it corresponds to. */
3406 csend
= charstart
+ (p1
- p1start
);
3409 /* The idea is to use p1prev_modified instead of p1prev
3410 in the loop below over p2x. */
3411 p1prev_modified
= p1
;
3414 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3415 (p1
- p1prev
), current_face
, rev_dir_bit
);
3418 /* Update charstarts for the newline that ended this line. */
3419 /* Do nothing here for a char that's entirely off the left edge
3420 or if it starts at the right edge. */
3421 if (p1
>= leftmargin
&& p1prev
!= endp
)
3423 /* Store the newline's position into charstarts
3424 for the column where the newline starts.
3425 Store -1 for the rest of the glyphs it occupies. */
3426 int *p2x
= &charstart
[(p1prev
< leftmargin
3427 ? leftmargin
: p1prev
)
3429 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3436 /* Draw the face of the newline character as extending all the
3437 way to the end of the frame line. */
3440 if (p1
< leftmargin
)
3443 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3453 if (p1
>= leftmargin
&& p1
< endp
)
3454 *p1
= MAKE_GLYPH (f
, ' ', current_face
) | rev_dir_bit
;
3457 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
3460 else if (c
== Ctl ('M') && selective
== -1)
3462 pos
= find_next_newline (pos
, 1);
3463 if (FETCH_BYTE (pos
- 1) == '\n')
3465 if (selective_rlen
> 0)
3467 p1
+= selective_rlen
;
3468 if (p1
- leftmargin
> width
)
3470 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
3471 (p1
- p1prev
), current_face
, rev_dir_bit
);
3474 /* Draw the face of the newline character as extending all the
3475 way to the end of the frame line. */
3478 if (p1
< leftmargin
)
3481 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
) | rev_dir_bit
;
3485 /* Update charstarts for the ^M that ended this line. */
3486 /* Do nothing here for a char that's entirely off the left edge
3487 or if it starts at the right edge. */
3488 if (p1
>= leftmargin
&& p1prev
!= endp
)
3490 /* Store the newline's position into charstarts
3491 for the column where the newline starts.
3492 Store -1 for the rest of the glyphs it occupies. */
3493 int *p2x
= &charstart
[(p1prev
< leftmargin
3494 ? leftmargin
: p1prev
)
3496 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3504 else if (c
< 0200 && ctl_arrow
)
3506 if (p1
>= leftmargin
)
3508 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3509 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
3510 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3514 if (p1
>= leftmargin
&& p1
< endp
)
3515 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
) | rev_dir_bit
;
3520 /* C is not a multibyte character. */
3521 if (p1
>= leftmargin
)
3523 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3524 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
3525 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3529 if (p1
>= leftmargin
&& p1
< endp
)
3530 *p1
= MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
) | rev_dir_bit
;
3532 if (p1
>= leftmargin
&& p1
< endp
)
3533 *p1
= (MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
)
3536 if (p1
>= leftmargin
&& p1
< endp
)
3537 *p1
= MAKE_GLYPH (f
, (7 & c
) + '0', current_face
) | rev_dir_bit
;
3542 /* C is a multibyte character. */
3543 int charset
= CHAR_CHARSET (c
);
3544 int columns
= (charset
== CHARSET_COMPOSITION
3545 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
3546 : CHARSET_WIDTH (charset
));
3547 GLYPH g
= MAKE_GLYPH (f
, c
, current_face
) | rev_dir_bit
;
3551 if (p1
>= leftmargin
&& p1
< endp
)
3552 *p1
= g
, g
|= GLYPH_MASK_PADDING
;
3560 /* Update charstarts for the character just output. */
3562 /* Do nothing here for a char that's entirely off the left edge. */
3563 if (p1
>= leftmargin
)
3565 /* Store the char's position into charstarts
3566 for the first glyph occupied by this char.
3567 Store -1 for the rest of the glyphs it occupies. */
3570 int *p2x
= &charstart
[(p1prev
< leftmargin
3571 ? leftmargin
: p1prev
)
3573 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
3583 val
.hpos
= - XINT (w
->hscroll
);
3591 /* Store 0 in this charstart line for the positions where
3592 there is no character. But do leave what was recorded
3593 for the character that ended the line. */
3594 /* Add 1 in the endtest to compensate for the fact that ENDP was
3595 made from WIDTH, which is 1 less than the window's actual
3597 i
= p1
- p1start
+ 1;
3598 if (p1
< leftmargin
)
3599 i
+= leftmargin
- p1
;
3600 for (; i
< endp
- p1start
+ 1; i
++)
3603 /* Handle continuation in middle of a character */
3604 /* by backing up over it */
3607 /* Don't back up if we never actually displayed any text.
3608 This occurs when the minibuffer prompt takes up the whole line. */
3611 /* Start the next line with that same character whose
3612 character code is C and the length of multi-byte form is
3617 /* C is not a multi-byte character. We can break it and
3618 start from the middle column in the next line. So,
3619 adjust VAL.HPOS to skip the columns output on this
3621 val
.hpos
+= p1prev
- endp
;
3624 /* C is a multibyte character. Since we can't broke it
3625 in the middle, the whole character should be driven
3626 into the next line. */
3627 /* As the result, the actual columns occupied by the
3628 text on this line is less than WIDTH. VAL.TAB_OFFSET
3629 must be adjusted. */
3630 taboffset
= taboffset
+ (p1prev
- endp
);
3631 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3633 GLYPH g
= fix_glyph (f
, truncate
? truncator
: continuer
, 0);
3634 while (p1prev
< endp
)
3637 /* If POINT is at POS, cursor should not on this line. */
3644 /* Keep in this line everything up to the continuation column. */
3648 /* Finish deciding which character to start the next line on,
3649 and what hpos to start it at.
3650 Also set `lastpos' to the last position which counts as "on this line"
3651 for cursor-positioning. */
3655 if (FETCH_BYTE (pos
) == '\n')
3657 /* If stopped due to a newline, start next line after it */
3660 /* Check again for hidden lines, in case the newline occurred exactly
3661 at the right margin. */
3662 while (pos
< ZV
&& selective
> 0
3663 && indented_beyond_p (pos
, selective
))
3664 pos
= find_next_newline (pos
, 1);
3667 /* Stopped due to right margin of window */
3671 *p1
++ = fix_glyph (f
, truncator
, 0);
3672 /* Truncating => start next line after next newline,
3673 and point is on this line if it is before the newline,
3674 and skip none of first char of next line */
3676 pos
= find_next_newline (pos
, 1);
3677 while (pos
< ZV
&& selective
> 0
3678 && indented_beyond_p (pos
, selective
));
3679 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
3681 lastpos
= pos
- (FETCH_BYTE (pos
- 1) == '\n');
3686 *p1
++ = fix_glyph (f
, continuer
, 0);
3689 val
.tab_offset
= taboffset
+ width
;
3696 /* If point is at eol or in invisible text at eol,
3697 record its frame location now. */
3699 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
3702 cursor_hpos
= p1
- leftmargin
;
3705 if (cursor_vpos
== vpos
)
3707 if (cursor_hpos
< 0) cursor_hpos
= 0;
3708 if (cursor_hpos
> width
) cursor_hpos
= width
;
3709 cursor_hpos
+= WINDOW_LEFT_MARGIN (w
);
3710 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
3712 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
3713 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
3715 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3716 FRAME_CURSOR_X (f
) = cursor_hpos
;
3719 if (w
== XWINDOW (selected_window
))
3721 /* Line is not continued and did not start
3722 in middle of character */
3723 if ((hpos
- WINDOW_LEFT_MARGIN (w
)
3724 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
3727 this_line_bufpos
= start
;
3728 this_line_buffer
= current_buffer
;
3729 this_line_vpos
= cursor_vpos
;
3730 this_line_start_hpos
= hpos
- WINDOW_LEFT_MARGIN (w
);
3731 this_line_endpos
= Z
- lastpos
;
3734 this_line_bufpos
= 0;
3739 /* If hscroll and line not empty, insert truncation-at-left marker */
3740 if (hscroll
&& lastpos
!= start
)
3742 GLYPH g
= fix_glyph (f
, truncator
, 0);
3744 if (p1
<= leftmargin
)
3745 p1
= leftmargin
+ 1;
3746 else /* MULE: it may be a wide-column character */
3748 p1prev
= leftmargin
+ 1;
3749 while (p1prev
< p1
&& *p1prev
& GLYPH_MASK_PADDING
)
3754 if (!WINDOW_RIGHTMOST_P (w
))
3757 if (p1
< leftmargin
) p1
= leftmargin
;
3758 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
3760 /* Don't draw vertical bars if we're using scroll bars. They're
3761 covered up by the scroll bars, and it's distracting to see
3762 them when the scroll bar windows are flickering around to be
3764 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
3767 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
3770 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3771 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
3772 ? XINT (DISP_BORDER_GLYPH (dp
))
3775 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
3776 p1
- desired_glyphs
->glyphs
[vpos
]);
3777 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
3779 /* If the start of this line is the overlay arrow-position,
3780 then put the arrow string into the display-line. */
3782 if (MARKERP (Voverlay_arrow_position
)
3783 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
3784 && start
== marker_position (Voverlay_arrow_position
)
3785 && STRINGP (Voverlay_arrow_string
)
3786 && ! overlay_arrow_seen
)
3788 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
3790 int len
= XSTRING (Voverlay_arrow_string
)->size
;
3796 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string
)->intervals
))
3798 /* If the arrow string has text props, obey them when displaying. */
3799 for (i
= 0; i
< len
; i
++)
3802 Lisp_Object face
, ilisp
;
3805 XSETFASTINT (ilisp
, i
);
3806 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
3807 newface
= compute_glyph_face_1 (f
, face
, 0);
3808 leftmargin
[i
] = FAST_MAKE_GLYPH (c
, newface
);
3812 #endif /* HAVE_FACES */
3814 for (i
= 0; i
< len
; i
++)
3815 leftmargin
[i
] = p
[i
];
3818 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3819 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
3820 if (desired_glyphs
->used
[vpos
] < arrow_end
)
3821 desired_glyphs
->used
[vpos
] = arrow_end
;
3823 overlay_arrow_seen
= 1;
3827 val
.ovstring_chars_done
= ovstr_done
;
3828 val_display_text_line
= val
;
3829 return &val_display_text_line
;
3832 /* Redisplay the menu bar in the frame for window W. */
3835 display_menu_bar (w
)
3838 Lisp_Object items
, tail
;
3839 register int vpos
= 0;
3840 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3841 int maxendcol
= FRAME_WIDTH (f
) + WINDOW_LEFT_MARGIN (w
);
3846 if (!NILP (Vwindow_system
))
3850 #ifdef USE_X_TOOLKIT
3853 #endif /* USE_X_TOOLKIT */
3855 get_display_line (f
, vpos
, 0);
3857 items
= FRAME_MENU_BAR_ITEMS (f
);
3858 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
3860 Lisp_Object pos
, string
;
3861 string
= XVECTOR (items
)->contents
[i
+ 1];
3865 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], hpos
);
3867 if (hpos
< maxendcol
)
3868 hpos
= display_string (w
, vpos
,
3869 XSTRING (string
)->data
,
3870 XSTRING (string
)->size
,
3871 hpos
, 0, 0, hpos
, maxendcol
, -1);
3872 /* Put a space between items. */
3873 if (hpos
< maxendcol
)
3875 int hpos1
= hpos
+ 1;
3876 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
3877 min (hpos1
, maxendcol
), maxendcol
, 0);
3881 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3882 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3884 /* Fill out the line with spaces. */
3885 if (maxendcol
> hpos
)
3886 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
, 0);
3888 /* Clear the rest of the lines allocated to the menu bar. */
3890 while (vpos
< FRAME_MENU_BAR_LINES (f
))
3891 get_display_line (f
, vpos
++, 0);
3894 /* Display the mode line for window w */
3897 display_mode_line (w
)
3900 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
3901 register int left
= WINDOW_LEFT_MARGIN (w
);
3902 register int right
= WINDOW_RIGHT_MARGIN (w
);
3903 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3905 line_number_displayed
= 0;
3906 w
->column_number_displayed
= Qnil
;
3908 get_display_line (f
, vpos
, left
);
3910 /* Temporarily make frame F's kboard the current kboard
3911 so that kboard-local variables in the mode_line_format
3912 will get the right values. */
3913 push_frame_kboard (f
);
3915 display_mode_element (w
, vpos
, left
, 0, right
, right
,
3916 current_buffer
->mode_line_format
);
3918 pop_frame_kboard ();
3920 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3922 /* Put the mode line in inverse video.
3923 Use faces if possible, since that lets us handle
3924 partial-width windows and avoid inverting the scroll bar columns. */
3926 if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
3928 /* For a partial width window, explicitly set face of each glyph. */
3930 unsigned int padding
;
3931 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
3932 for (i
= left
; i
< right
; ++i
)
3934 padding
= ptr
[i
] & GLYPH_MASK_PADDING
;
3935 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1) | padding
;
3941 /* Make the mode line inverse video if the entire line
3942 is made of mode lines.
3943 I.e. if this window is full width,
3944 or if it is the child of a full width window
3945 (which implies that that window is split side-by-side
3946 and the rest of this line is mode lines of the sibling windows). */
3947 if (WINDOW_FULL_WIDTH_P (w
)
3948 || WINDOW_FULL_WIDTH_P (XWINDOW (w
->parent
)))
3949 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3952 /* Contribute ELT to the mode line for window W.
3953 How it translates into text depends on its data type.
3955 VPOS is the position of the mode line being displayed.
3957 HPOS is the position (absolute on frame) where this element's text
3958 should start. The output is truncated automatically at the right
3961 DEPTH is the depth in recursion. It is used to prevent
3962 infinite recursion here.
3964 MINENDCOL is the hpos before which the element may not end.
3965 The element is padded at the right with spaces if nec
3966 to reach this column.
3968 MAXENDCOL is the hpos past which this element may not extend.
3969 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3970 (This is necessary to make nested padding and truncation work.)
3972 Returns the hpos of the end of the text generated by ELT.
3973 The next element will receive that value as its HPOS arg,
3974 so as to concatenate the elements. */
3977 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
3979 register int vpos
, hpos
;
3982 register int maxendcol
;
3983 register Lisp_Object elt
;
3991 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
3995 /* A string: output it and check for %-constructs within it. */
3996 register unsigned char c
;
3997 register unsigned char *this = XSTRING (elt
)->data
;
3999 while (hpos
< maxendcol
&& *this)
4001 unsigned char *last
= this;
4002 while ((c
= *this++) != '\0' && c
!= '%')
4004 if (this - 1 != last
)
4006 register int lim
= --this - last
+ hpos
;
4007 if (frame_title_ptr
)
4008 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
4010 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
4011 hpos
, min (lim
, maxendcol
), -1);
4015 register int minendcol
;
4016 register int spec_width
= 0;
4018 /* We can't allow -ve args due to the "%-" construct */
4019 /* Argument specifies minwidth but not maxwidth
4020 (maxwidth can be specified by
4021 (<negative-number> . <stuff>) mode-line elements) */
4023 while ((c
= *this++) >= '0' && c
<= '9')
4025 spec_width
= spec_width
* 10 + (c
- '0');
4028 minendcol
= hpos
+ spec_width
;
4029 if (minendcol
> maxendcol
)
4031 spec_width
= maxendcol
- hpos
;
4032 minendcol
= maxendcol
;
4036 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4037 spec_width
, maxendcol
,
4038 Vglobal_mode_string
);
4041 char *spec
= decode_mode_spec (w
, c
, spec_width
,
4043 if (frame_title_ptr
)
4044 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
4046 hpos
= display_string (w
, vpos
, spec
, -1,
4048 minendcol
, maxendcol
, -1);
4056 /* A symbol: process the value of the symbol recursively
4057 as if it appeared here directly. Avoid error if symbol void.
4058 Special case: if value of symbol is a string, output the string
4061 register Lisp_Object tem
;
4062 tem
= Fboundp (elt
);
4065 tem
= Fsymbol_value (elt
);
4066 /* If value is a string, output that string literally:
4067 don't check for % within it. */
4070 if (frame_title_ptr
)
4071 hpos
= store_frame_title (XSTRING (tem
)->data
,
4072 minendcol
, maxendcol
);
4074 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
4075 XSTRING (tem
)->size
,
4076 hpos
, 0, 1, minendcol
, maxendcol
, -1);
4078 /* Give up right away for nil or t. */
4079 else if (!EQ (tem
, elt
))
4080 { elt
= tem
; goto tail_recurse
; }
4087 register Lisp_Object car
, tem
;
4089 /* A cons cell: three distinct cases.
4090 If first element is a string or a cons, process all the elements
4091 and effectively concatenate them.
4092 If first element is a negative number, truncate displaying cdr to
4093 at most that many characters. If positive, pad (with spaces)
4094 to at least that many characters.
4095 If first element is a symbol, process the cadr or caddr recursively
4096 according to whether the symbol's value is non-nil or nil. */
4097 car
= XCONS (elt
)->car
;
4100 tem
= Fboundp (car
);
4101 elt
= XCONS (elt
)->cdr
;
4104 /* elt is now the cdr, and we know it is a cons cell.
4105 Use its car if CAR has a non-nil value. */
4108 tem
= Fsymbol_value (car
);
4110 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
4112 /* Symbol's value is nil (or symbol is unbound)
4113 Get the cddr of the original list
4114 and if possible find the caddr and use that. */
4115 elt
= XCONS (elt
)->cdr
;
4118 else if (!CONSP (elt
))
4120 elt
= XCONS (elt
)->car
;
4123 else if (INTEGERP (car
))
4125 register int lim
= XINT (car
);
4126 elt
= XCONS (elt
)->cdr
;
4128 /* Negative int means reduce maximum width.
4129 DO NOT change MINENDCOL here!
4130 (20 -10 . foo) should truncate foo to 10 col
4131 and then pad to 20. */
4132 maxendcol
= min (maxendcol
, hpos
- lim
);
4135 /* Padding specified. Don't let it be more than
4138 if (lim
> maxendcol
)
4140 /* If that's more padding than already wanted, queue it.
4141 But don't reduce padding already specified even if
4142 that is beyond the current truncation point. */
4143 if (lim
> minendcol
)
4148 else if (STRINGP (car
) || CONSP (car
))
4150 register int limit
= 50;
4151 /* LIMIT is to protect against circular lists. */
4152 while (CONSP (elt
) && --limit
> 0
4153 && hpos
< maxendcol
)
4155 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
4158 elt
= XCONS (elt
)->cdr
;
4166 if (frame_title_ptr
)
4167 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
4169 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
4170 minendcol
, maxendcol
, 0);
4174 if (minendcol
> hpos
)
4175 if (frame_title_ptr
)
4176 hpos
= store_frame_title ("", minendcol
, maxendcol
);
4178 hpos
= display_string (w
, vpos
, "", 0, hpos
,
4179 0, 1, minendcol
, maxendcol
, 0);
4183 /* Write a null-terminated, right justified decimal representation of
4184 the positive integer D to BUF using a minimal field width WIDTH. */
4187 pint2str (buf
, width
, d
)
4192 register char *p
= buf
;
4199 *p
++ = d
% 10 + '0';
4202 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
4212 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4213 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4214 type of CODING_SYSTEM. Return updated pointer into BUF. */
4217 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
4218 Lisp_Object coding_system
;
4223 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
4225 val
= coding_system
;
4227 if (NILP (val
)) /* Not yet decided. */
4232 *buf
++ = eol_mnemonic_undecided
;
4233 /* Don't mention EOL conversion if it isn't decided. */
4237 Lisp_Object eolvalue
;
4239 eolvalue
= Fget (coding_system
, Qeol_type
);
4241 while (!NILP (val
) && SYMBOLP (val
))
4243 val
= Fget (val
, Qcoding_system
);
4244 if (NILP (eolvalue
))
4245 eolvalue
= Fget (val
, Qeol_type
);
4249 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
4253 /* The EOL conversion we are using. */
4255 /* The EOL conversion that is normal on this system. */
4257 if (NILP (eolvalue
)) /* Not yet decided. */
4258 eoltype
= eol_mnemonic_undecided
;
4259 else if (VECTORP (eolvalue
)) /* Not yet decided. */
4260 eoltype
= eol_mnemonic_undecided
;
4261 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4262 eoltype
= (XFASTINT (eolvalue
) == 0
4264 : (XFASTINT (eolvalue
) == 1
4265 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
4267 /* Mention the EOL conversion if it is not the usual one. */
4274 /* Return a string for the output of a mode line %-spec for window W,
4275 generated by character C. SPEC_WIDTH is the field width when
4276 padding to the left (%c, %l). The value returned from this
4277 function will later be truncated to width MAXWIDTH. */
4279 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4282 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
4285 register int spec_width
;
4286 register int maxwidth
;
4289 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4290 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
4291 struct buffer
*b
= XBUFFER (w
->buffer
);
4294 if (maxwidth
> FRAME_WIDTH (f
))
4295 maxwidth
= FRAME_WIDTH (f
);
4300 if (!NILP (b
->read_only
))
4302 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4307 /* This differs from %* only for a modified read-only buffer. */
4308 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4310 if (!NILP (b
->read_only
))
4315 /* This differs from %* in ignoring read-only-ness. */
4316 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
4328 if (command_loop_level
> 5)
4330 p
= decode_mode_spec_buf
;
4331 for (i
= 0; i
< command_loop_level
; i
++)
4334 return decode_mode_spec_buf
;
4342 if (command_loop_level
> 5)
4344 p
= decode_mode_spec_buf
;
4345 for (i
= 0; i
< command_loop_level
; i
++)
4348 return decode_mode_spec_buf
;
4356 if (maxwidth
< sizeof (lots_of_dashes
))
4357 return lots_of_dashes
;
4360 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
4364 return decode_mode_spec_buf
;
4370 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
4372 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
4373 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
4374 decode_mode_spec_buf
[maxwidth
] = '\0';
4375 return decode_mode_spec_buf
;
4382 int col
= current_column ();
4383 XSETFASTINT (w
->column_number_displayed
, col
);
4384 pint2str (decode_mode_spec_buf
, spec_width
, col
);
4385 return decode_mode_spec_buf
;
4389 /* %F displays the frame name. */
4390 /* Systems that can only display a single frame at a time should
4391 NOT replace the frame name with the (constant) frame title,
4392 since then they won't be able to tell which frame is that. */
4393 if (FRAME_WINDOW_P (f
) && !NILP (f
->title
))
4394 return (char *) XSTRING (f
->title
)->data
;
4395 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
4396 return (char *) XSTRING (f
->name
)->data
;
4404 else if (STRINGP (obj
) && XSTRING (obj
)->size
> maxwidth
)
4406 bcopy ("...", decode_mode_spec_buf
, 3);
4407 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
4408 decode_mode_spec_buf
+ 3, maxwidth
- 3);
4409 return decode_mode_spec_buf
;
4416 int startpos
= marker_position (w
->start
);
4417 int line
, linepos
, topline
;
4420 int height
= XFASTINT (w
->height
);
4422 /* If we decided that this buffer isn't suitable for line numbers,
4423 don't forget that too fast. */
4424 if (EQ (w
->base_line_pos
, w
->buffer
))
4426 /* But do forget it, if the window shows a different buffer now. */
4427 else if (BUFFERP (w
->base_line_pos
))
4428 w
->base_line_pos
= Qnil
;
4430 /* If the buffer is very big, don't waste time. */
4431 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
4433 w
->base_line_pos
= Qnil
;
4434 w
->base_line_number
= Qnil
;
4438 if (!NILP (w
->base_line_number
)
4439 && !NILP (w
->base_line_pos
)
4440 && XFASTINT (w
->base_line_pos
) <= marker_position (w
->start
))
4442 line
= XFASTINT (w
->base_line_number
);
4443 linepos
= XFASTINT (w
->base_line_pos
);
4448 linepos
= BUF_BEGV (b
);
4451 /* Count lines from base line to window start position. */
4452 nlines
= display_count_lines (linepos
, startpos
, startpos
, &junk
);
4454 topline
= nlines
+ line
;
4456 /* Determine a new base line, if the old one is too close
4457 or too far away, or if we did not have one.
4458 "Too close" means it's plausible a scroll-down would
4460 if (startpos
== BUF_BEGV (b
))
4462 XSETFASTINT (w
->base_line_number
, topline
);
4463 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
4465 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
4466 || linepos
== BUF_BEGV (b
))
4468 int limit
= BUF_BEGV (b
);
4470 int distance
= (height
* 2 + 30) * 200;
4472 if (startpos
- distance
> limit
)
4473 limit
= startpos
- distance
;
4475 nlines
= display_count_lines (startpos
, limit
,
4478 /* If we couldn't find the lines we wanted within
4480 give up on line numbers for this window. */
4481 if (position
== startpos
- distance
)
4483 w
->base_line_pos
= w
->buffer
;
4484 w
->base_line_number
= Qnil
;
4488 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
4489 XSETFASTINT (w
->base_line_pos
, position
);
4492 /* Now count lines from the start pos to point. */
4493 nlines
= display_count_lines (startpos
, PT
, PT
, &junk
);
4495 /* Record that we did display the line number. */
4496 line_number_displayed
= 1;
4498 /* Make the string to show. */
4499 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
4500 return decode_mode_spec_buf
;
4503 char* p
= decode_mode_spec_buf
;
4504 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
4506 return decode_mode_spec_buf
;
4516 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
4522 int pos
= marker_position (w
->start
);
4523 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4525 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
4527 if (pos
<= BUF_BEGV (b
))
4532 else if (pos
<= BUF_BEGV (b
))
4536 if (total
> 1000000)
4537 /* Do it differently for a large value, to avoid overflow. */
4538 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4540 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4541 /* We can't normally display a 3-digit number,
4542 so get us a 2-digit number that is close. */
4545 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4546 return decode_mode_spec_buf
;
4550 /* Display percentage of size above the bottom of the screen. */
4553 int toppos
= marker_position (w
->start
);
4554 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
4555 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
4557 if (botpos
>= BUF_ZV (b
))
4559 if (toppos
<= BUF_BEGV (b
))
4566 if (total
> 1000000)
4567 /* Do it differently for a large value, to avoid overflow. */
4568 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
4570 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
4571 /* We can't normally display a 3-digit number,
4572 so get us a 2-digit number that is close. */
4575 if (toppos
<= BUF_BEGV (b
))
4576 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
4578 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
4579 return decode_mode_spec_buf
;
4584 /* status of process */
4585 obj
= Fget_buffer_process (w
->buffer
);
4587 return "no process";
4589 obj
= Fsymbol_name (Fprocess_status (obj
));
4593 case 't': /* indicate TEXT or BINARY */
4594 #ifdef MODE_LINE_BINARY_TEXT
4595 return MODE_LINE_BINARY_TEXT (b
);
4601 /* coding-system (not including end-of-line format) */
4603 /* coding-system (including end-of-line type) */
4605 int eol_flag
= (c
== 'Z');
4606 char *p
= decode_mode_spec_buf
;
4608 if (! FRAME_WINDOW_P (f
))
4610 /* No need to mention EOL here--the terminal never needs
4611 to do EOL conversion. */
4612 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
4613 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
4615 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
4618 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
4620 obj
= Fget_buffer_process (Fcurrent_buffer ());
4623 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
4625 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
4628 #endif /* subprocesses */
4631 return decode_mode_spec_buf
;
4636 return (char *) XSTRING (obj
)->data
;
4641 /* Search for COUNT instances of a line boundary, which means either a
4642 newline or (if selective display enabled) a carriage return.
4643 Start at START. If COUNT is negative, search backwards.
4645 If we find COUNT instances, set *SHORTAGE to zero, and return the
4646 position after the COUNTth match. Note that for reverse motion
4647 this is not the same as the usual convention for Emacs motion commands.
4649 If we don't find COUNT instances before reaching the end of the
4650 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
4651 the number of line boundaries left unfound, and return the end of the
4652 buffer we bumped up against. */
4655 display_scan_buffer (start
, count
, shortage
)
4656 int *shortage
, start
;
4659 int limit
= ((count
> 0) ? ZV
- 1 : BEGV
);
4660 int direction
= ((count
> 0) ? 1 : -1);
4662 register unsigned char *cursor
;
4663 unsigned char *base
;
4665 register int ceiling
;
4666 register unsigned char *ceiling_addr
;
4668 /* If we are not in selective display mode,
4669 check only for newlines. */
4670 if (! (!NILP (current_buffer
->selective_display
)
4671 && !INTEGERP (current_buffer
->selective_display
)))
4672 return scan_buffer ('\n', start
, 0, count
, shortage
, 0);
4674 /* The code that follows is like scan_buffer
4675 but checks for either newline or carriage return. */
4681 while (start
!= limit
+ 1)
4683 ceiling
= BUFFER_CEILING_OF (start
);
4684 ceiling
= min (limit
, ceiling
);
4685 ceiling_addr
= POS_ADDR (ceiling
) + 1;
4686 base
= (cursor
= POS_ADDR (start
));
4689 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
4691 if (cursor
!= ceiling_addr
)
4696 return (start
+ cursor
- base
+ 1);
4699 if (++cursor
== ceiling_addr
)
4705 start
+= cursor
- base
;
4709 start
--; /* first character we scan */
4710 while (start
> limit
- 1)
4711 { /* we WILL scan under start */
4712 ceiling
= BUFFER_FLOOR_OF (start
);
4713 ceiling
= max (limit
, ceiling
);
4714 ceiling_addr
= POS_ADDR (ceiling
) - 1;
4715 base
= (cursor
= POS_ADDR (start
));
4719 while (--cursor
!= ceiling_addr
4720 && *cursor
!= '\n' && *cursor
!= 015)
4722 if (cursor
!= ceiling_addr
)
4727 return (start
+ cursor
- base
+ 1);
4733 start
+= cursor
- base
;
4738 *shortage
= count
* direction
;
4739 return (start
+ ((direction
== 1 ? 0 : 1)));
4742 /* Count up to N lines starting from FROM.
4743 But don't go beyond LIMIT.
4744 Return the number of lines thus found (always positive).
4745 Store the position after what was found into *POS_PTR. */
4748 display_count_lines (from
, limit
, n
, pos_ptr
)
4761 *pos_ptr
= display_scan_buffer (from
, n
, &shortage
);
4767 /* When scanning backwards, scan_buffer stops *after* the last newline
4768 it finds, but does count it. Compensate for that. */
4769 return - n
- shortage
- (*pos_ptr
!= limit
);
4770 return n
- shortage
;
4773 /* Display STRING on one line of window W, starting at HPOS.
4774 Display at position VPOS. Caller should have done get_display_line.
4775 If VPOS == -1, display it as the current frame's title.
4776 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4778 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4780 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4781 MAXCOL is the last column ok to end at. Truncate here.
4782 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4783 Both count from the left edge of the frame, as does HPOS.
4784 The right edge of W is an implicit maximum.
4785 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4787 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4788 at the place where the current window ends in this line
4789 and not display anything beyond there. Otherwise, only MAXCOL
4790 controls where to stop output.
4792 MULTIBYTE can be 0 meaning do not display multibyte chars,
4793 1 meaning do display them, or -1 meaning obey the current buffer's
4794 value of enable_multibyte_characters.
4796 Returns ending hpos. */
4799 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
4800 obey_window_width
, mincol
, maxcol
, multibyte
)
4802 unsigned char *string
;
4806 int obey_window_width
;
4813 int hscroll
= XINT (w
->hscroll
);
4814 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
4815 register GLYPH
*start
;
4816 register GLYPH
*end
;
4817 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4818 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
4819 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
4820 int window_width
= XFASTINT (w
->width
);
4822 /* Use the standard display table, not the window's display table.
4823 We don't want the mode line in rot13. */
4824 register struct Lisp_Char_Table
*dp
= 0;
4827 if (multibyte
== -1)
4828 multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
4829 /* Now multibyte is 1 if we should display multibyte characters. */
4831 if (DISP_TABLE_P (Vstandard_display_table
))
4832 dp
= XCHAR_TABLE (Vstandard_display_table
);
4834 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
4837 start
= desired_glyphs
->glyphs
[vpos
];
4839 if (obey_window_width
)
4841 start
+= XFASTINT (w
->left
);
4842 end
= start
+ window_width
- (truncate
!= 0);
4844 if (!WINDOW_RIGHTMOST_P (w
))
4846 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4850 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4853 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4858 if (! obey_window_width
4859 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
4860 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
4862 /* Store 0 in charstart for these columns. */
4863 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
4864 desired_glyphs
->charstarts
[vpos
][i
] = 0;
4866 if (maxcol
>= 0 && mincol
> maxcol
)
4870 /* We need this value for multibyte characters. */
4871 length
= strlen (string
);
4873 /* We set truncated to 1 if we get stopped by trying to pass END
4874 (that is, trying to pass MAXCOL.) */
4883 c
= STRING_CHAR_AND_LENGTH (string
, length
, len
);
4885 c
= *string
, len
= 1;
4887 string
+= len
, length
-= len
;
4895 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
4897 p1
= copy_part_of_rope (f
, p1
, start
,
4898 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
4899 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
4902 else if (c
>= 040 && c
< 0177)
4912 if (p1
>= start
&& p1
< end
)
4916 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
4918 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
4922 (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
4923 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp
)))
4924 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
4927 if (p1
>= start
&& p1
< end
)
4933 /* C is a control character or a binary byte data. */
4936 (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
4937 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp
)))
4938 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
4941 if (p1
>= start
&& p1
< end
)
4942 *p1
= (c
>> 6) + '0';
4944 if (p1
>= start
&& p1
< end
)
4945 *p1
= (7 & (c
>> 3)) + '0';
4947 if (p1
>= start
&& p1
< end
)
4948 *p1
= (7 & c
) + '0';
4953 /* C is a multibyte character. */
4954 int charset
= CHAR_CHARSET (c
);
4955 int columns
= (charset
== CHARSET_COMPOSITION
4956 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
4957 : CHARSET_WIDTH (charset
));
4961 /* Since we can't show the left part of C, fill all
4962 columns with spaces. */
4963 columns
-= start
- p1
;
4972 else if (p1
+ columns
> end
)
4974 /* Since we can't show the right part of C, fill all
4975 columns with TRUNCATE if TRUNCATE is specified. */
4979 *p1
++ = fix_glyph (f
, truncate
, 0);
4980 /* And tell the line is truncated. */
4987 /* We can show the whole glyph of C. */
4990 *p1
++ = c
| GLYPH_MASK_PADDING
;
4998 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
5000 else if (mincol
>= 0)
5002 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
5008 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
5010 if (len
> desired_glyphs
->used
[vpos
])
5011 desired_glyphs
->used
[vpos
] = len
;
5012 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
5018 /* This is like a combination of memq and assq.
5019 Return 1 if PROPVAL appears as an element of LIST
5020 or as the car of an element of LIST.
5021 If PROPVAL is a list, compare each element against LIST
5022 in that way, and return 1 if any element of PROPVAL is found in LIST.
5024 This function cannot quit. */
5027 invisible_p (propval
, list
)
5028 register Lisp_Object propval
;
5031 register Lisp_Object tail
, proptail
;
5032 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5034 register Lisp_Object tem
;
5035 tem
= XCONS (tail
)->car
;
5036 if (EQ (propval
, tem
))
5038 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5041 if (CONSP (propval
))
5042 for (proptail
= propval
; CONSP (proptail
);
5043 proptail
= XCONS (proptail
)->cdr
)
5045 Lisp_Object propelt
;
5046 propelt
= XCONS (proptail
)->car
;
5047 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5049 register Lisp_Object tem
;
5050 tem
= XCONS (tail
)->car
;
5051 if (EQ (propelt
, tem
))
5053 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5060 /* Return 1 if PROPVAL appears as the car of an element of LIST
5061 and the cdr of that element is non-nil.
5062 If PROPVAL is a list, check each element of PROPVAL in that way,
5063 and the first time some element is found,
5064 return 1 if the cdr of that element is non-nil.
5066 This function cannot quit. */
5069 invisible_ellipsis_p (propval
, list
)
5070 register Lisp_Object propval
;
5073 register Lisp_Object tail
, proptail
;
5074 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5076 register Lisp_Object tem
;
5077 tem
= XCONS (tail
)->car
;
5078 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
5079 return ! NILP (XCONS (tem
)->cdr
);
5081 if (CONSP (propval
))
5082 for (proptail
= propval
; CONSP (proptail
);
5083 proptail
= XCONS (proptail
)->cdr
)
5085 Lisp_Object propelt
;
5086 propelt
= XCONS (proptail
)->car
;
5087 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5089 register Lisp_Object tem
;
5090 tem
= XCONS (tail
)->car
;
5091 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
5092 return ! NILP (XCONS (tem
)->cdr
);
5101 staticpro (&Qmenu_bar_update_hook
);
5102 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
5104 staticpro (&Qoverriding_terminal_local_map
);
5105 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
5107 staticpro (&Qoverriding_local_map
);
5108 Qoverriding_local_map
= intern ("overriding-local-map");
5110 staticpro (&Qwindow_scroll_functions
);
5111 Qwindow_scroll_functions
= intern ("window-scroll-functions");
5113 staticpro (&Qredisplay_end_trigger_functions
);
5114 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
5116 staticpro (&last_arrow_position
);
5117 staticpro (&last_arrow_string
);
5118 last_arrow_position
= Qnil
;
5119 last_arrow_string
= Qnil
;
5121 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
5122 "String (or mode line construct) included (normally) in `mode-line-format'.");
5123 Vglobal_mode_string
= Qnil
;
5125 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
5126 "Marker for where to display an arrow on top of the buffer text.\n\
5127 This must be the beginning of a line in order to work.\n\
5128 See also `overlay-arrow-string'.");
5129 Voverlay_arrow_position
= Qnil
;
5131 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
5132 "String to display as an arrow. See also `overlay-arrow-position'.");
5133 Voverlay_arrow_string
= Qnil
;
5135 DEFVAR_INT ("scroll-step", &scroll_step
,
5136 "*The number of lines to try scrolling a window by when point moves out.\n\
5137 If that fails to bring point back on frame, point is centered instead.\n\
5138 If this is zero, point is always centered after it moves off frame.");
5140 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
5141 "*Scroll up to this many lines, to bring point back on screen.");
5142 scroll_conservatively
= 0;
5144 DEFVAR_INT ("scroll-margin", &scroll_margin
,
5145 "*Number of lines of margin at the top and bottom of a window.\n\
5146 Recenter the window whenever point gets within this many lines\n\
5147 of the top or bottom of the window.");
5150 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
5152 DEFVAR_BOOL ("truncate-partial-width-windows",
5153 &truncate_partial_width_windows
,
5154 "*Non-nil means truncate lines in all windows less than full frame wide.");
5155 truncate_partial_width_windows
= 1;
5157 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
5158 "*Non-nil means use inverse video for the mode line.");
5159 mode_line_inverse_video
= 1;
5161 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
5162 "*Maximum buffer size for which line number should be displayed.");
5163 line_number_display_limit
= 1000000;
5165 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
5166 "*Non-nil means highlight region even in nonselected windows.");
5167 highlight_nonselected_windows
= 0;
5169 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
5170 "Non-nil if more than one frame is visible on this display.\n\
5171 Minibuffer-only frames don't count, but iconified frames do.\n\
5172 This variable is not guaranteed to be accurate except while processing\n\
5173 `frame-title-format' and `icon-title-format'.");
5175 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
5176 "Template for displaying the titlebar of visible frames.\n\
5177 \(Assuming the window manager supports this feature.)\n\
5178 This variable has the same structure as `mode-line-format' (which see),\n\
5179 and is used only on frames for which no explicit name has been set\n\
5180 \(see `modify-frame-parameters').");
5181 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
5182 "Template for displaying the titlebar of an iconified frame.\n\
5183 \(Assuming the window manager supports this feature.)\n\
5184 This variable has the same structure as `mode-line-format' (which see),\n\
5185 and is used only on frames for which no explicit name has been set\n\
5186 \(see `modify-frame-parameters').");
5188 = Vframe_title_format
5189 = Fcons (intern ("multiple-frames"),
5190 Fcons (build_string ("%b"),
5191 Fcons (Fcons (build_string (""),
5192 Fcons (intern ("invocation-name"),
5193 Fcons (build_string ("@"),
5194 Fcons (intern ("system-name"),
5198 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
5199 "Maximum number of lines to keep in the message log buffer.\n\
5200 If nil, disable message logging. If t, log messages but don't truncate\n\
5201 the buffer when it becomes large.");
5202 XSETFASTINT (Vmessage_log_max
, 50);
5204 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
5205 "Functions called before redisplay, if window sizes have changed.\n\
5206 The value should be a list of functions that take one argument.\n\
5207 Just before redisplay, for each frame, if any of its windows have changed\n\
5208 size since the last redisplay, or have been split or deleted,\n\
5209 all the functions in the list are called, with the frame as argument.");
5210 Vwindow_size_change_functions
= Qnil
;
5212 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
5213 "List of functions to call before redisplaying a window with scrolling.\n\
5214 Each function is called with two arguments, the window\n\
5215 and its new display-start position. Note that the value of `window-end'\n\
5216 is not valid when these functions are called.");
5217 Vwindow_scroll_functions
= Qnil
;
5219 DEFVAR_INT ("minibuffer-scroll-overlap", &minibuffer_scroll_overlap
,
5220 "*Number of characters of overlap when scrolling a one-line window.\n\
5221 This commonly affects the minibuffer window, hence the name of the variable.");
5222 minibuffer_scroll_overlap
= 20;
5225 /* initialize the window system */
5228 Lisp_Object root_window
;
5229 #ifndef COMPILER_REGISTER_BUG
5231 #endif /* COMPILER_REGISTER_BUG */
5232 struct window
*mini_w
;
5234 this_line_bufpos
= 0;
5236 mini_w
= XWINDOW (minibuf_window
);
5237 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
5239 echo_area_glyphs
= 0;
5240 previous_echo_glyphs
= 0;
5242 if (!noninteractive
)
5244 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
5245 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_MENU_BAR_LINES (f
));
5246 set_window_height (root_window
,
5247 FRAME_HEIGHT (f
) - 1 - FRAME_MENU_BAR_LINES (f
),
5249 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
5250 set_window_height (minibuf_window
, 1, 0);
5252 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
5253 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));