1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /*#include <ctype.h>*/
29 #include "dispextern.h"
35 #include "termhooks.h"
36 #include "intervals.h"
39 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
40 extern void set_frame_menubar ();
43 extern int interrupt_input
;
44 extern int command_loop_level
;
46 extern Lisp_Object Qface
;
48 extern Lisp_Object Voverriding_local_map
;
49 extern Lisp_Object Voverriding_local_map_menu_flag
;
51 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
52 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
53 Lisp_Object Qredisplay_end_trigger_functions
;
55 /* Nonzero means print newline to stdout before next minibuffer message. */
57 int noninteractive_need_newline
;
59 /* Nonzero means print newline to message log before next message. */
61 static int message_log_need_newline
;
63 #define min(a, b) ((a) < (b) ? (a) : (b))
64 #define max(a, b) ((a) > (b) ? (a) : (b))
65 #define minmax(floor, val, ceil) \
66 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
68 /* The buffer position of the first character appearing
69 entirely or partially on the current frame line.
70 Or zero, which disables the optimization for the current frame line. */
71 static int this_line_bufpos
;
73 /* Number of characters past the end of this line,
74 including the terminating newline */
75 static int this_line_endpos
;
77 /* The vertical position of this frame line. */
78 static int this_line_vpos
;
80 /* Hpos value for start of display on this frame line.
81 Usually zero, but negative if first character really began
83 static int this_line_start_hpos
;
85 /* Buffer that this_line variables are describing. */
86 static struct buffer
*this_line_buffer
;
88 /* Value of echo_area_glyphs when it was last acted on.
89 If this is nonzero, there is a message on the frame
90 in the minibuffer and it should be erased as soon
91 as it is no longer requested to appear. */
92 char *previous_echo_glyphs
;
94 /* Nonzero means truncate lines in all windows less wide than the frame */
95 int truncate_partial_width_windows
;
97 /* Nonzero means we have more than one non-minibuffer-only frame.
98 Not guaranteed to be accurate except while parsing frame-title-format. */
101 Lisp_Object Vglobal_mode_string
;
103 /* Marker for where to display an arrow on top of the buffer text. */
104 Lisp_Object Voverlay_arrow_position
;
106 /* String to display for the arrow. */
107 Lisp_Object Voverlay_arrow_string
;
109 /* Like mode-line-format, but for the titlebar on a visible frame. */
110 Lisp_Object Vframe_title_format
;
112 /* Like mode-line-format, but for the titlebar on an iconified frame. */
113 Lisp_Object Vicon_title_format
;
115 /* List of functions to call when a window's size changes. These
116 functions get one arg, a frame on which one or more windows' sizes
118 static Lisp_Object Vwindow_size_change_functions
;
120 /* Values of those variables at last redisplay. */
121 static Lisp_Object last_arrow_position
, last_arrow_string
;
123 Lisp_Object Qmenu_bar_update_hook
;
125 /* Nonzero if overlay arrow has been displayed once in this window. */
126 static int overlay_arrow_seen
;
128 /* Nonzero if visible end of buffer has already been displayed once
129 in this window. (We need this variable in case there are overlay
130 strings that get displayed there.) */
131 static int zv_strings_seen
;
133 /* Nonzero means highlight the region even in nonselected windows. */
134 static int highlight_nonselected_windows
;
136 /* If cursor motion alone moves point off frame,
137 Try scrolling this many lines up or down if that will bring it back. */
138 static int scroll_step
;
140 /* Nonzero if try_window_id has made blank lines at window bottom
141 since the last redisplay that paused */
142 static int blank_end_of_window
;
144 /* Number of windows showing the buffer of the selected window
145 (or another buffer with the same base buffer).
146 keyboard.c refers to this. */
149 /* display_text_line sets these to the frame position (origin 0) of point,
150 whether the window is selected or not.
151 Set one to -1 first to determine whether point was found afterwards. */
153 static int cursor_vpos
;
154 static int cursor_hpos
;
156 static int debug_end_pos
;
158 /* Nonzero means display mode line highlighted */
159 int mode_line_inverse_video
;
161 static int message_log_check_duplicate ();
162 static void echo_area_display ();
163 void mark_window_display_accurate ();
164 static void redisplay_windows ();
165 static void redisplay_window ();
166 static void update_menu_bar ();
167 static void try_window ();
168 static int try_window_id ();
169 static struct position
*display_text_line ();
170 static void display_mode_line ();
171 static int display_mode_element ();
172 static char *decode_mode_spec ();
173 static int display_string ();
174 static void display_menu_bar ();
175 static int display_count_lines ();
177 /* Prompt to display in front of the minibuffer contents */
178 Lisp_Object minibuf_prompt
;
180 /* Width in columns of current minibuffer prompt. */
181 int minibuf_prompt_width
;
183 /* Message to display instead of minibuffer contents
184 This is what the functions error and message make,
185 and command echoing uses it as well.
186 It overrides the minibuf_prompt as well as the buffer. */
187 char *echo_area_glyphs
;
189 /* This is the length of the message in echo_area_glyphs. */
190 int echo_area_glyphs_length
;
192 /* This is the window where the echo area message was displayed.
193 It is always a minibuffer window, but it may not be the
194 same window currently active as a minibuffer. */
195 Lisp_Object echo_area_window
;
197 /* true iff we should redraw the mode lines on the next redisplay */
198 int update_mode_lines
;
200 /* Smallest number of characters before the gap
201 at any time since last redisplay that finished.
202 Valid for current buffer when try_window_id can be called. */
205 /* Smallest number of characters after the gap
206 at any time since last redisplay that finished.
207 Valid for current buffer when try_window_id can be called. */
210 /* MODIFF as of last redisplay that finished;
211 if it matches MODIFF, beg_unchanged and end_unchanged
212 contain no useful information */
213 int unchanged_modified
;
215 /* Nonzero if window sizes or contents have changed
216 since last redisplay that finished */
217 int windows_or_buffers_changed
;
219 /* Nonzero after display_mode_line if %l was used
220 and it displayed a line number. */
221 int line_number_displayed
;
223 /* Maximum buffer size for which to display line numbers. */
224 static int line_number_display_limit
;
226 /* Number of lines to keep in the message log buffer.
227 t means infinite. nil means don't log at all. */
228 Lisp_Object Vmessage_log_max
;
231 message_log_maybe_newline ()
233 if (message_log_need_newline
)
234 message_dolog ("", 0, 1);
238 /* Add a string to the message log, optionally terminated with a newline.
239 This function calls low-level routines in order to bypass text property
240 hooks, etc. which might not be safe to run. */
243 message_dolog (m
, len
, nlflag
)
247 if (!NILP (Vmessage_log_max
))
249 struct buffer
*oldbuf
;
250 int oldpoint
, oldbegv
, oldzv
;
251 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
253 oldbuf
= current_buffer
;
254 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
255 current_buffer
->undo_list
= Qt
;
262 oldpoint
+= len
+ nlflag
;
264 oldzv
+= len
+ nlflag
;
267 insert_1 (m
, len
, 1, 0);
270 int this_bol
, prev_bol
, dup
;
271 insert_1 ("\n", 1, 1, 0);
273 this_bol
= scan_buffer ('\n', Z
, 0, -2, 0, 0);
276 prev_bol
= scan_buffer ('\n', this_bol
, 0, -2, 0, 0);
277 dup
= message_log_check_duplicate (prev_bol
, this_bol
);
280 if (oldpoint
> prev_bol
)
281 oldpoint
-= min (this_bol
, oldpoint
) - prev_bol
;
282 if (oldbegv
> prev_bol
)
283 oldbegv
-= min (this_bol
, oldbegv
) - prev_bol
;
284 if (oldzv
> prev_bol
)
285 oldzv
-= min (this_bol
, oldzv
) - prev_bol
;
286 del_range_1 (prev_bol
, this_bol
, 0);
292 /* If you change this format, don't forget to also
293 change message_log_check_duplicate. */
294 sprintf (dupstr
, " [%d times]", dup
);
295 duplen
= strlen (dupstr
);
301 insert_1 (dupstr
, duplen
, 1, 0);
306 if (NATNUMP (Vmessage_log_max
))
308 int pos
= scan_buffer ('\n', Z
, 0,
309 -XFASTINT (Vmessage_log_max
) - 1, 0, 0);
310 oldpoint
-= min (pos
, oldpoint
) - BEG
;
311 oldbegv
-= min (pos
, oldbegv
) - BEG
;
312 oldzv
-= min (pos
, oldzv
) - BEG
;
313 del_range_1 (BEG
, pos
, 0);
318 TEMP_SET_PT (oldpoint
);
319 set_buffer_internal (oldbuf
);
320 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
321 message_log_need_newline
= !nlflag
;
326 /* We are at the end of the buffer after just having inserted a newline.
327 (Note: We depend on the fact we won't be crossing the gap.)
328 Check to see if the most recent message looks a lot like the previous one.
329 Return 0 if different, 1 if the new one should just replace it, or a
330 value N > 1 if we should also append " [N times]". */
333 message_log_check_duplicate (prev_bol
, this_bol
)
334 int prev_bol
, this_bol
;
337 int len
= Z
- 1 - this_bol
;
339 unsigned char *p1
= BUF_CHAR_ADDRESS (current_buffer
, prev_bol
);
340 unsigned char *p2
= BUF_CHAR_ADDRESS (current_buffer
, this_bol
);
342 for (i
= 0; i
< len
; i
++)
344 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
353 if (*p1
++ == ' ' && *p1
++ == '[')
356 while (*p1
>= '0' && *p1
<= '9')
357 n
= n
* 10 + *p1
++ - '0';
358 if (strncmp (p1
, " times]\n", 8) == 0)
364 /* Display an echo area message M with a specified length of LEN chars.
365 The string may include null characters. If m is 0, clear out any
366 existing message, and let the minibuffer text show through.
367 Do not pass text that is stored in a Lisp string. */
374 /* First flush out any partial line written with print. */
375 message_log_maybe_newline ();
377 message_dolog (m
, len
, 1);
378 message2_nolog (m
, len
);
382 /* The non-logging part of that function. */
385 message2_nolog (m
, len
)
391 if (noninteractive_need_newline
)
393 noninteractive_need_newline
= 0;
394 fwrite (m
, len
, 1, stderr
);
395 if (cursor_in_echo_area
== 0)
396 fprintf (stderr
, "\n");
399 /* A null message buffer means that the frame hasn't really been
400 initialized yet. Error messages get reported properly by
401 cmd_error, so this must be just an informative message; toss it. */
402 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
404 Lisp_Object mini_window
;
407 /* Get the frame containing the minibuffer
408 that the selected frame is using. */
409 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
410 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
413 FRAME_SAMPLE_VISIBILITY (f
);
414 if (FRAME_VISIBLE_P (selected_frame
)
415 && ! FRAME_VISIBLE_P (f
))
416 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
421 echo_area_glyphs
= m
;
422 echo_area_glyphs_length
= len
;
425 echo_area_glyphs
= previous_echo_glyphs
= 0;
427 do_pending_window_change ();
428 echo_area_display ();
429 update_frame (f
, 1, 1);
430 do_pending_window_change ();
431 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
432 (*frame_up_to_date_hook
) (f
);
440 message2 (m
, (m
? strlen (m
) : 0));
447 message2_nolog (m
, (m
? strlen (m
) : 0));
450 /* Truncate what will be displayed in the echo area
451 the next time we display it--but don't redisplay it now. */
454 truncate_echo_area (len
)
457 /* A null message buffer means that the frame hasn't really been
458 initialized yet. Error messages get reported properly by
459 cmd_error, so this must be just an informative message; toss it. */
460 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
461 echo_area_glyphs_length
= len
;
464 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
465 zero if being used by message. */
466 int message_buf_print
;
468 /* Dump an informative message to the minibuf. If m is 0, clear out
469 any existing message, and let the minibuffer text show through. */
472 message (m
, a1
, a2
, a3
)
474 EMACS_INT a1
, a2
, a3
;
480 if (noninteractive_need_newline
)
482 noninteractive_need_newline
= 0;
483 fprintf (stderr
, m
, a1
, a2
, a3
);
484 if (cursor_in_echo_area
== 0)
485 fprintf (stderr
, "\n");
489 else if (INTERACTIVE
)
491 /* The frame whose minibuffer we're going to display the message on.
492 It may be larger than the selected frame, so we need
493 to use its buffer, not the selected frame's buffer. */
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 /* A null message buffer means that the frame hasn't really been
503 initialized yet. Error messages get reported properly by
504 cmd_error, so this must be just an informative message; toss it. */
505 if (FRAME_MESSAGE_BUF (f
))
516 len
= doprnt (FRAME_MESSAGE_BUF (f
),
517 FRAME_WIDTH (f
), m
, (char *)0, 3, a
);
519 len
= doprnt (FRAME_MESSAGE_BUF (f
),
520 FRAME_WIDTH (f
), m
, (char *)0, 3, &a1
);
521 #endif /* NO_ARG_ARRAY */
523 message2 (FRAME_MESSAGE_BUF (f
), len
);
528 /* Print should start at the beginning of the message
530 message_buf_print
= 0;
535 /* The non-logging version of that function. */
537 message_nolog (m
, a1
, a2
, a3
)
539 EMACS_INT a1
, a2
, a3
;
541 Lisp_Object old_log_max
;
542 old_log_max
= Vmessage_log_max
;
543 Vmessage_log_max
= Qnil
;
544 message (m
, a1
, a2
, a3
);
545 Vmessage_log_max
= old_log_max
;
551 message2 (echo_area_glyphs
, echo_area_glyphs_length
);
559 Lisp_Object mini_window
;
561 /* Choose the minibuffer window for this display.
562 It is the minibuffer window used by the selected frame. */
563 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
564 /* This is the frame that window is in. */
565 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
567 if (! FRAME_VISIBLE_P (f
))
572 redraw_garbaged_frames ();
576 if (echo_area_glyphs
|| minibuf_level
== 0)
578 echo_area_window
= mini_window
;
580 vpos
= XFASTINT (XWINDOW (mini_window
)->top
);
581 get_display_line (f
, vpos
, 0);
582 display_string (XWINDOW (mini_window
), vpos
,
583 echo_area_glyphs
? echo_area_glyphs
: "",
584 echo_area_glyphs
? echo_area_glyphs_length
: -1,
585 0, 0, 0, 0, FRAME_WIDTH (f
));
587 #if 0 /* This just gets in the way. update_frame does the job. */
588 /* If desired cursor location is on this line, put it at end of text */
589 if (cursor_in_echo_area
)
590 FRAME_CURSOR_Y (f
) = vpos
;
591 if (FRAME_CURSOR_Y (f
) == vpos
)
592 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
595 /* Fill the rest of the minibuffer window with blank lines. */
600 i
< vpos
+ XFASTINT (XWINDOW (mini_window
)->height
); i
++)
602 get_display_line (f
, i
, 0);
603 display_string (XWINDOW (mini_window
), vpos
,
604 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f
));
608 else if (!EQ (mini_window
, selected_window
))
609 windows_or_buffers_changed
++;
611 if (EQ (mini_window
, selected_window
))
612 this_line_bufpos
= 0;
614 previous_echo_glyphs
= echo_area_glyphs
;
617 #ifdef HAVE_WINDOW_SYSTEM
618 static char frame_title_buf
[512];
619 static char *frame_title_ptr
;
622 store_frame_title (str
, mincol
, maxcol
)
627 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
628 maxcol
= sizeof (frame_title_buf
);
629 limit
= &frame_title_buf
[maxcol
];
630 while (*str
!= '\0' && frame_title_ptr
< limit
)
631 *frame_title_ptr
++ = *str
++;
632 while (frame_title_ptr
< &frame_title_buf
[mincol
])
633 *frame_title_ptr
++ = ' ';
634 return frame_title_ptr
- frame_title_buf
;
638 x_consider_frame_title (frame
)
644 FRAME_PTR f
= XFRAME (frame
);
646 if (!(FRAME_WINDOW_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
))
649 /* Do we have more than one visible frame on this X display? */
653 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
655 FRAME_PTR tf
= XFRAME (XCONS (tail
)->car
);
657 if (tf
!= f
&& FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
658 && !FRAME_MINIBUF_ONLY_P (tf
)
659 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
663 multiple_frames
= CONSP (tail
);
666 obuf
= current_buffer
;
667 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
668 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
669 frame_title_ptr
= frame_title_buf
;
670 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
671 0, sizeof (frame_title_buf
), fmt
);
673 set_buffer_internal (obuf
);
674 /* Set the name only if it's changed. This avoids consing
675 in the common case where it hasn't. (If it turns out that we've
676 already wasted too much time by walking through the list with
677 display_mode_element, then we might need to optimize at a higher
679 if (! STRINGP (f
->name
) || XSTRING (f
->name
)->size
!= len
680 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
681 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
684 #define frame_title_ptr ((char *)0)
685 #define store_frame_title(str, mincol, maxcol) 0
688 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
689 This can call eval. */
694 register struct window
*w
= XWINDOW (selected_window
);
696 struct gcpro gcpro1
, gcpro2
;
698 all_windows
= (update_mode_lines
|| buffer_shared
> 1
699 || windows_or_buffers_changed
);
701 /* Update all frame titles based on their buffer names, etc.
702 We do this before the menu bars so that the buffer-menu
703 will show the up-to-date frame titles.
705 This used to be done after the menu bars, for a reason that
706 was stated as follows but which I do not understand:
707 "We do this after the menu bars so that the frame will first
708 create its menu bar using the name `emacs' if no other name
709 has yet been specified."
710 I think that is no longer a concern. */
711 #ifdef HAVE_WINDOW_SYSTEM
712 if (windows_or_buffers_changed
|| update_mode_lines
)
714 Lisp_Object tail
, frame
;
716 FOR_EACH_FRAME (tail
, frame
)
717 if (FRAME_VISIBLE_P (XFRAME (frame
))
718 || FRAME_ICONIFIED_P (XFRAME (frame
)))
719 x_consider_frame_title (frame
);
723 /* Update the menu bar item lists, if appropriate.
724 This has to be done before any actual redisplay
725 or generation of display lines. */
728 Lisp_Object tail
, frame
;
729 int count
= specpdl_ptr
- specpdl
;
731 record_unwind_protect (Fstore_match_data
, Fmatch_data ());
733 FOR_EACH_FRAME (tail
, frame
)
735 /* If a window on this frame changed size,
736 report that to the user and clear the size-change flag. */
737 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)))
739 Lisp_Object functions
;
740 /* Clear flag first in case we get error below. */
741 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame
)) = 0;
742 functions
= Vwindow_size_change_functions
;
743 GCPRO2 (tail
, functions
);
744 while (CONSP (functions
))
746 call1 (XCONS (functions
)->car
, frame
);
747 functions
= XCONS (functions
)->cdr
;
752 update_menu_bar (XFRAME (frame
), 0);
756 unbind_to (count
, Qnil
);
759 update_menu_bar (selected_frame
, 1);
762 /* Do a frame update, taking possible shortcuts into account.
763 This is the main external entry point for redisplay.
765 If the last redisplay displayed an echo area message and that
766 message is no longer requested, we clear the echo area
767 or bring back the minibuffer if that is in use.
769 Do not call eval from within this function.
770 Calls to eval after the call to echo_area_display would confuse
771 the display_line mechanism and would cause a crash.
772 Calls to eval before that point will work most of the time,
773 but can still lose, because this function
774 can be called from signal handlers; with alarms set up;
775 or with synchronous processes running.
777 See Fcall_process; if you called it from here, it could be
778 entered recursively. */
780 static int do_verify_charstarts
;
782 /* Counter is used to clear the face cache
783 no more than once ever 1000 redisplays. */
784 static int clear_face_cache_count
;
786 /* Record the previous terminal frame we displayed. */
787 static FRAME_PTR previous_terminal_frame
;
792 register struct window
*w
= XWINDOW (selected_window
);
796 register int tlbufpos
, tlendpos
;
803 if (FRAME_TERMCAP_P (selected_frame
)
804 && previous_terminal_frame
!= selected_frame
)
806 /* Since frames on an ASCII terminal share the same display area,
807 displaying a different frame means redisplay the whole thing. */
808 windows_or_buffers_changed
++;
809 SET_FRAME_GARBAGED (selected_frame
);
810 XSETFRAME (Vterminal_frame
, selected_frame
);
812 previous_terminal_frame
= selected_frame
;
815 /* Set the visible flags for all frames.
816 Do this before checking for resized or garbaged frames; they want
817 to know if their frames are visible.
818 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
820 Lisp_Object tail
, frame
;
822 FOR_EACH_FRAME (tail
, frame
)
824 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
826 /* Clear out all the display lines in which we will generate the
827 glyphs to display. */
828 init_desired_glyphs (XFRAME (frame
));
832 /* Notice any pending interrupt request to change frame size. */
833 do_pending_window_change ();
837 redraw_garbaged_frames ();
841 prepare_menu_bars ();
843 if (windows_or_buffers_changed
)
846 /* Detect case that we need to write a star in the mode line. */
847 if (XFASTINT (w
->last_modified
) < MODIFF
848 && XFASTINT (w
->last_modified
) <= SAVE_MODIFF
)
850 w
->update_mode_line
= Qt
;
851 if (buffer_shared
> 1)
855 /* If %c is in use, update it if needed. */
856 if (!NILP (w
->column_number_displayed
)
857 /* This alternative quickly identifies a common case
858 where no change is needed. */
859 && !(PT
== XFASTINT (w
->last_point
)
860 && XFASTINT (w
->last_modified
) >= MODIFF
)
861 && XFASTINT (w
->column_number_displayed
) != current_column ())
862 w
->update_mode_line
= Qt
;
864 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
866 all_windows
= update_mode_lines
|| buffer_shared
> 1;
868 /* If specs for an arrow have changed, do thorough redisplay
869 to ensure we remove any arrow that should no longer exist. */
870 if (! EQ (Voverlay_arrow_position
, last_arrow_position
)
871 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
874 /* Normally the message* functions will have already displayed and
875 updated the echo area, but the frame may have been trashed, or
876 the update may have been preempted, so display the echo area
878 if (echo_area_glyphs
|| previous_echo_glyphs
)
880 echo_area_display ();
884 /* If showing region, and mark has changed, must redisplay whole window. */
885 if (((!NILP (Vtransient_mark_mode
)
886 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
887 != !NILP (w
->region_showing
))
888 || (!NILP (w
->region_showing
)
889 && !EQ (w
->region_showing
,
890 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
891 this_line_bufpos
= -1;
893 tlbufpos
= this_line_bufpos
;
894 tlendpos
= this_line_endpos
;
895 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
896 && !current_buffer
->clip_changed
897 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
898 /* Make sure recorded data applies to current buffer, etc */
899 && this_line_buffer
== current_buffer
900 && current_buffer
== XBUFFER (w
->buffer
)
901 && NILP (w
->force_start
)
902 /* Point must be on the line that we have info recorded about */
904 && PT
<= Z
- tlendpos
905 /* All text outside that line, including its final newline,
907 && (XFASTINT (w
->last_modified
) >= MODIFF
908 || (beg_unchanged
>= tlbufpos
- 1
910 /* If selective display, can't optimize
911 if the changes start at the beginning of the line. */
912 && ((INTEGERP (current_buffer
->selective_display
)
913 && XINT (current_buffer
->selective_display
) > 0
914 ? (beg_unchanged
>= tlbufpos
917 && end_unchanged
>= tlendpos
918 && Z
- GPT
>= tlendpos
)))
920 if (tlbufpos
> BEGV
&& FETCH_CHAR (tlbufpos
- 1) != '\n'
922 || FETCH_CHAR (tlbufpos
) == '\n'))
923 /* Former continuation line has disappeared by becoming empty */
925 else if (XFASTINT (w
->last_modified
) < MODIFF
926 || MINI_WINDOW_P (w
))
929 overlay_arrow_seen
= 0;
931 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
932 pos_tab_offset (w
, tlbufpos
));
933 /* If line contains point, is not continued,
934 and ends at same distance from eob as before, we win */
935 if (cursor_vpos
>= 0 && this_line_bufpos
936 && this_line_endpos
== tlendpos
)
938 /* If this is not the window's last line,
939 we must adjust the charstarts of the lines below. */
940 if (this_line_vpos
+ 1
941 < XFASTINT (w
->top
) + window_internal_height (w
))
943 int left
= XFASTINT (w
->left
);
944 int *charstart_next_line
945 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
948 if (Z
- tlendpos
== ZV
)
949 /* This line ends at end of (accessible part of) buffer.
950 There is no newline to count. */
951 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
953 /* This line ends in a newline.
954 Must take account of the newline and the rest of the
955 text that follows. */
956 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
958 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
961 if (XFASTINT (w
->width
) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w
))))
962 preserve_other_columns (w
);
968 else if (PT
== XFASTINT (w
->last_point
)
969 /* Make sure the cursor was last displayed
970 in this window. Otherwise we have to reposition it. */
971 && XINT (w
->top
) <= FRAME_CURSOR_Y (selected_frame
)
972 && (XINT (w
->top
) + XINT (w
->height
)
973 > FRAME_CURSOR_Y (selected_frame
)))
977 do_pending_window_change ();
982 /* If highlighting the region, or if the cursor is in the echo area,
983 then we can't just move the cursor. */
984 else if (! (!NILP (Vtransient_mark_mode
)
985 && !NILP (current_buffer
->mark_active
))
986 && NILP (w
->region_showing
)
987 && !cursor_in_echo_area
)
989 pos
= *compute_motion (tlbufpos
, 0,
990 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
992 PT
, 2, - (1 << (BITS_PER_SHORT
- 1)),
993 window_internal_width (w
) - 1,
995 pos_tab_offset (w
, tlbufpos
), w
);
998 int width
= window_internal_width (w
) - 1;
999 FRAME_CURSOR_X (selected_frame
)
1000 = XFASTINT (w
->left
) + minmax (0, pos
.hpos
, width
);
1001 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
1008 /* Text changed drastically or point moved off of line */
1009 cancel_line (this_line_vpos
, selected_frame
);
1012 this_line_bufpos
= 0;
1013 all_windows
|= buffer_shared
> 1;
1015 clear_face_cache_count
++;
1019 Lisp_Object tail
, frame
;
1022 /* Clear the face cache, only when we do a full redisplay
1023 and not too often either. */
1024 if (clear_face_cache_count
> 1000)
1026 clear_face_cache ();
1027 clear_face_cache_count
= 0;
1031 /* Recompute # windows showing selected buffer.
1032 This will be incremented each time such a window is displayed. */
1035 FOR_EACH_FRAME (tail
, frame
)
1037 FRAME_PTR f
= XFRAME (frame
);
1038 if (! FRAME_TERMCAP_P (f
) || f
== selected_frame
)
1041 /* Mark all the scroll bars to be removed; we'll redeem the ones
1042 we want when we redisplay their windows. */
1043 if (condemn_scroll_bars_hook
)
1044 (*condemn_scroll_bars_hook
) (f
);
1046 if (FRAME_VISIBLE_P (f
))
1047 redisplay_windows (FRAME_ROOT_WINDOW (f
));
1049 /* Any scroll bars which redisplay_windows should have nuked
1050 should now go away. */
1051 if (judge_scroll_bars_hook
)
1052 (*judge_scroll_bars_hook
) (f
);
1056 else if (FRAME_VISIBLE_P (selected_frame
))
1058 redisplay_window (selected_window
, 1);
1059 if (XFASTINT (w
->width
) != FRAME_WIDTH (selected_frame
))
1060 preserve_other_columns (w
);
1064 /* Prevent various kinds of signals during display update.
1065 stdio is not robust about handling signals,
1066 which can cause an apparent I/O error. */
1067 if (interrupt_input
)
1078 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1082 if (!FRAMEP (XCONS (tail
)->car
))
1085 f
= XFRAME (XCONS (tail
)->car
);
1087 if ((! FRAME_TERMCAP_P (f
) || f
== selected_frame
)
1088 && FRAME_VISIBLE_P (f
))
1090 pause
|= update_frame (f
, 0, 0);
1093 mark_window_display_accurate (f
->root_window
, 1);
1094 if (frame_up_to_date_hook
!= 0)
1095 (*frame_up_to_date_hook
) (f
);
1101 #endif /* MULTI_FRAME */
1103 if (FRAME_VISIBLE_P (selected_frame
))
1104 pause
= update_frame (selected_frame
, 0, 0);
1108 /* We may have called echo_area_display at the top of this
1109 function. If the echo area is on another frame, that may
1110 have put text on a frame other than the selected one, so the
1111 above call to update_frame would not have caught it. Catch
1114 Lisp_Object mini_window
;
1115 FRAME_PTR mini_frame
;
1117 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
1118 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
1120 if (mini_frame
!= selected_frame
1121 && ! FRAME_TERMCAP_P (mini_frame
))
1122 pause
|= update_frame (mini_frame
, 0, 0);
1126 /* If frame does not match, prevent doing single-line-update next time.
1127 Also, don't forget to check every line to update the arrow. */
1130 this_line_bufpos
= 0;
1131 if (!NILP (last_arrow_position
))
1133 last_arrow_position
= Qt
;
1134 last_arrow_string
= Qt
;
1136 /* If we pause after scrolling, some lines in current_frame
1137 may be null, so preserve_other_columns won't be able to
1138 preserve all the vertical-bar separators. So, avoid using it
1140 if (XFASTINT (w
->width
) != FRAME_WIDTH (selected_frame
))
1141 update_mode_lines
= 1;
1144 /* Now text on frame agrees with windows, so
1145 put info into the windows for partial redisplay to follow */
1149 register struct buffer
*b
= XBUFFER (w
->buffer
);
1151 blank_end_of_window
= 0;
1152 unchanged_modified
= BUF_MODIFF (b
);
1153 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
1154 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
1156 XSETFASTINT (w
->last_point
, BUF_PT (b
));
1157 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
1158 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
1161 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
1164 b
->clip_changed
= 0;
1165 w
->update_mode_line
= Qnil
;
1166 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
1167 w
->window_end_valid
= w
->buffer
;
1168 last_arrow_position
= Voverlay_arrow_position
;
1169 last_arrow_string
= Voverlay_arrow_string
;
1170 if (do_verify_charstarts
)
1171 verify_charstarts (w
);
1172 if (frame_up_to_date_hook
!= 0)
1173 (*frame_up_to_date_hook
) (selected_frame
);
1175 update_mode_lines
= 0;
1176 windows_or_buffers_changed
= 0;
1179 /* Start SIGIO interrupts coming again.
1180 Having them off during the code above
1181 makes it less likely one will discard output,
1182 but not impossible, since there might be stuff
1183 in the system buffer here.
1184 But it is much hairier to try to do anything about that. */
1186 if (interrupt_input
)
1190 /* Change frame size now if a change is pending. */
1191 do_pending_window_change ();
1193 /* If we just did a pending size change, redisplay again
1194 for the new size. */
1195 if (windows_or_buffers_changed
&& !pause
)
1199 /* Redisplay, but leave alone any recent echo area message
1200 unless another message has been requested in its place.
1202 This is useful in situations where you need to redisplay but no
1203 user action has occurred, making it inappropriate for the message
1204 area to be cleared. See tracking_off and
1205 wait_reading_process_input for examples of these situations. */
1207 redisplay_preserve_echo_area ()
1209 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1211 echo_area_glyphs
= previous_echo_glyphs
;
1213 echo_area_glyphs
= 0;
1220 mark_window_display_accurate (window
, flag
)
1224 register struct window
*w
;
1226 for (;!NILP (window
); window
= w
->next
)
1228 if (!WINDOWP (window
)) abort ();
1229 w
= XWINDOW (window
);
1231 if (!NILP (w
->buffer
))
1233 XSETFASTINT (w
->last_modified
,
1234 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1236 /* Record if we are showing a region, so can make sure to
1237 update it fully at next redisplay. */
1238 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1239 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1240 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1244 w
->window_end_valid
= w
->buffer
;
1245 w
->update_mode_line
= Qnil
;
1246 if (!NILP (w
->buffer
))
1247 XBUFFER (w
->buffer
)->clip_changed
= 0;
1249 if (!NILP (w
->vchild
))
1250 mark_window_display_accurate (w
->vchild
, flag
);
1251 if (!NILP (w
->hchild
))
1252 mark_window_display_accurate (w
->hchild
, flag
);
1257 last_arrow_position
= Voverlay_arrow_position
;
1258 last_arrow_string
= Voverlay_arrow_string
;
1262 /* t is unequal to any useful value of Voverlay_arrow_... */
1263 last_arrow_position
= Qt
;
1264 last_arrow_string
= Qt
;
1268 /* Update the menu bar item list for frame F.
1269 This has to be done before we start to fill in any display lines,
1270 because it can call eval.
1272 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1275 update_menu_bar (f
, save_match_data
)
1277 int save_match_data
;
1279 struct buffer
*old
= current_buffer
;
1281 register struct window
*w
;
1283 window
= FRAME_SELECTED_WINDOW (f
);
1284 w
= XWINDOW (window
);
1286 if (update_mode_lines
)
1287 w
->update_mode_line
= Qt
;
1291 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1292 FRAME_EXTERNAL_MENU_BAR (f
)
1294 FRAME_MENU_BAR_LINES (f
) > 0
1296 : FRAME_MENU_BAR_LINES (f
) > 0)
1298 /* If the user has switched buffers or windows, we need to
1299 recompute to reflect the new bindings. But we'll
1300 recompute when update_mode_lines is set too; that means
1301 that people can use force-mode-line-update to request
1302 that the menu bar be recomputed. The adverse effect on
1303 the rest of the redisplay algorithm is about the same as
1304 windows_or_buffers_changed anyway. */
1305 if (windows_or_buffers_changed
1306 || !NILP (w
->update_mode_line
)
1307 || (XFASTINT (w
->last_modified
) < MODIFF
1308 && (XFASTINT (w
->last_modified
)
1309 <= BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))))
1310 || ((!NILP (Vtransient_mark_mode
)
1311 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
1312 != !NILP (w
->region_showing
)))
1314 struct buffer
*prev
= current_buffer
;
1315 int count
= specpdl_ptr
- specpdl
;
1317 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1318 if (save_match_data
)
1319 record_unwind_protect (Fstore_match_data
, Fmatch_data ());
1320 if (NILP (Voverriding_local_map_menu_flag
))
1322 specbind (Qoverriding_terminal_local_map
, Qnil
);
1323 specbind (Qoverriding_local_map
, Qnil
);
1326 /* Run the Lucid hook. */
1327 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1328 /* If it has changed current-menubar from previous value,
1329 really recompute the menubar from the value. */
1330 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1331 call0 (Qrecompute_lucid_menubar
);
1332 call1 (Vrun_hooks
, Qmenu_bar_update_hook
);
1333 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1334 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1336 set_frame_menubar (f
, 0, 0);
1337 #endif /* USE_X_TOOLKIT || HAVE_NTGUI */
1339 unbind_to (count
, Qnil
);
1340 set_buffer_internal_1 (prev
);
1347 /* Redisplay WINDOW and its subwindows and siblings. */
1350 redisplay_windows (window
)
1353 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1354 redisplay_window (window
, 0);
1357 /* Redisplay window WINDOW and its subwindows. */
1360 redisplay_window (window
, just_this_one
)
1364 register struct window
*w
= XWINDOW (window
);
1365 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1367 register int lpoint
= PT
;
1368 struct buffer
*old
= current_buffer
;
1369 register int width
= window_internal_width (w
) - 1;
1370 register int startp
;
1371 register int hscroll
= XINT (w
->hscroll
);
1372 struct position pos
;
1375 int update_mode_line
;
1376 struct Lisp_Char_Table
*dp
= window_display_table (w
);
1378 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1380 /* If this is a combination window, do its children; that's all. */
1382 if (!NILP (w
->vchild
))
1384 redisplay_windows (w
->vchild
);
1387 if (!NILP (w
->hchild
))
1389 redisplay_windows (w
->hchild
);
1392 if (NILP (w
->buffer
))
1395 height
= window_internal_height (w
);
1396 update_mode_line
= (!NILP (w
->update_mode_line
) || update_mode_lines
);
1397 if (XBUFFER (w
->buffer
)->clip_changed
)
1398 update_mode_line
= 1;
1400 if (MINI_WINDOW_P (w
))
1402 if (w
== XWINDOW (echo_area_window
) && echo_area_glyphs
)
1403 /* We've already displayed the echo area glyphs in this window. */
1404 goto finish_scroll_bars
;
1405 else if (w
!= XWINDOW (minibuf_window
))
1407 /* This is a minibuffer, but it's not the currently active one,
1409 int vpos
= XFASTINT (w
->top
);
1412 for (i
= 0; i
< height
; i
++)
1414 get_display_line (f
, vpos
+ i
, 0);
1415 display_string (w
, vpos
+ i
, "", 0, 0, 0, 1, 0, width
);
1418 goto finish_scroll_bars
;
1422 /* Otherwise set up data on this window; select its buffer and point value */
1424 if (update_mode_line
)
1425 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1427 set_buffer_temp (XBUFFER (w
->buffer
));
1431 /* If %c is in mode line, update it if needed. */
1432 if (!NILP (w
->column_number_displayed
)
1433 /* This alternative quickly identifies a common case
1434 where no change is needed. */
1435 && !(PT
== XFASTINT (w
->last_point
)
1436 && XFASTINT (w
->last_modified
) >= MODIFF
)
1437 && XFASTINT (w
->column_number_displayed
) != current_column ())
1438 update_mode_line
= 1;
1440 /* Count number of windows showing the selected buffer.
1441 An indirect buffer counts as its base buffer. */
1445 struct buffer
*current_base
, *window_base
;
1446 current_base
= current_buffer
;
1447 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1448 if (current_base
->base_buffer
)
1449 current_base
= current_base
->base_buffer
;
1450 if (window_base
->base_buffer
)
1451 window_base
= window_base
->base_buffer
;
1452 if (current_base
== window_base
)
1456 /* POINT refers normally to the selected window.
1457 For any other window, set up appropriate value. */
1459 if (!EQ (window
, selected_window
))
1461 int new_pt
= marker_position (w
->pointm
);
1465 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1467 else if (new_pt
> (ZV
- 1))
1470 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1472 /* We don't use SET_PT so that the point-motion hooks don't run. */
1473 BUF_PT (current_buffer
) = new_pt
;
1476 /* If any of the character widths specified in the display table
1477 have changed, invalidate the width run cache. It's true that this
1478 may be a bit late to catch such changes, but the rest of
1479 redisplay goes (non-fatally) haywire when the display table is
1480 changed, so why should we worry about doing any better? */
1481 if (current_buffer
->width_run_cache
)
1483 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
1485 if (! disptab_matches_widthtab (disptab
,
1486 XVECTOR (current_buffer
->width_table
)))
1488 invalidate_region_cache (current_buffer
,
1489 current_buffer
->width_run_cache
,
1491 recompute_width_table (current_buffer
, disptab
);
1495 /* If window-start is screwed up, choose a new one. */
1496 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1499 startp
= marker_position (w
->start
);
1501 /* Handle case where place to start displaying has been specified,
1502 unless the specified location is outside the accessible range. */
1503 if (!NILP (w
->force_start
))
1505 w
->force_start
= Qnil
;
1506 /* Forget any recorded base line for line number display. */
1507 w
->base_line_number
= Qnil
;
1508 /* Redisplay the mode line. Select the buffer properly for that.
1509 Also, run the hook window-scroll-functions
1510 because we have scrolled. */
1511 /* Note, we do this after clearing force_start because
1512 if there's an error, it is better to forget about force_start
1513 than to get into an infinite loop calling the hook functions
1514 and having them get more errors. */
1515 if (!update_mode_line
1516 || ! NILP (Vwindow_scroll_functions
))
1518 Lisp_Object temp
[3];
1520 set_buffer_temp (old
);
1521 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1522 update_mode_line
= 1;
1523 w
->update_mode_line
= Qt
;
1524 if (! NILP (Vwindow_scroll_functions
))
1525 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1526 make_number (startp
));
1528 XSETFASTINT (w
->last_modified
, 0);
1529 if (startp
< BEGV
) startp
= BEGV
;
1530 if (startp
> ZV
) startp
= ZV
;
1531 try_window (window
, startp
);
1532 if (cursor_vpos
< 0)
1534 /* If point does not appear, move point so it does appear */
1535 pos
= *compute_motion (startp
, 0,
1536 (((EQ (window
, minibuf_window
)
1538 ? minibuf_prompt_width
: 0)
1539 + (hscroll
? 1 - hscroll
: 0)),
1542 - (1 << (BITS_PER_SHORT
- 1)),
1543 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1544 BUF_PT (current_buffer
) = pos
.bufpos
;
1545 if (w
!= XWINDOW (selected_window
))
1546 Fset_marker (w
->pointm
, make_number (PT
), Qnil
);
1549 if (current_buffer
== old
)
1551 FRAME_CURSOR_X (f
) = (XFASTINT (w
->left
)
1552 + minmax (0, pos
.hpos
, width
));
1553 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1555 /* If we are highlighting the region,
1556 then we just changed the region, so redisplay to show it. */
1557 if (!NILP (Vtransient_mark_mode
)
1558 && !NILP (current_buffer
->mark_active
))
1560 cancel_my_columns (XWINDOW (window
));
1561 try_window (window
, startp
);
1567 /* Handle case where text has not changed, only point,
1568 and it has not moved off the frame */
1570 /* This code is not used for minibuffer for the sake of
1571 the case of redisplaying to replace an echo area message;
1572 since in that case the minibuffer contents per se are usually unchanged.
1573 This code is of no real use in the minibuffer since
1574 the handling of this_line_bufpos, etc.,
1575 in redisplay handles the same cases. */
1577 if (XFASTINT (w
->last_modified
) >= MODIFF
1578 && PT
>= startp
&& !current_buffer
->clip_changed
1579 && (just_this_one
|| XFASTINT (w
->width
) == FRAME_WIDTH (f
))
1580 /* If force-mode-line-update was called, really redisplay;
1581 that's how redisplay is forced after e.g. changing
1582 buffer-invisibility-spec. */
1583 && NILP (w
->update_mode_line
)
1584 /* Can't use this case if highlighting a region. */
1585 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
1586 && NILP (w
->region_showing
)
1587 /* If end pos is out of date, scroll bar and percentage will be wrong */
1588 && INTEGERP (w
->window_end_vpos
)
1589 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
1590 && !EQ (window
, minibuf_window
))
1592 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0), 0,
1593 PT
, height
, 0, width
, hscroll
,
1594 pos_tab_offset (w
, startp
), w
);
1596 if (pos
.vpos
< height
)
1598 /* Ok, point is still on frame */
1599 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
1601 /* These variables are supposed to be origin 1 */
1602 FRAME_CURSOR_X (f
) = (XFASTINT (w
->left
)
1603 + minmax (0, pos
.hpos
, width
));
1604 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1606 /* This doesn't do the trick, because if a window to the right of
1607 this one must be redisplayed, this does nothing because there
1608 is nothing in DesiredFrame yet, and then the other window is
1609 redisplayed, making likes that are empty in this window's columns.
1610 if (XFASTINT (w->width) != FRAME_WIDTH (f))
1611 preserve_my_columns (w);
1615 /* Don't bother trying redisplay with same start;
1616 we already know it will lose */
1618 /* If current starting point was originally the beginning of a line
1619 but no longer is, find a new starting point. */
1620 else if (!NILP (w
->start_at_line_beg
)
1622 || FETCH_CHAR (startp
- 1) == '\n'))
1626 else if (just_this_one
&& !MINI_WINDOW_P (w
)
1628 && XFASTINT (w
->last_modified
)
1629 /* or else vmotion on first line won't work. */
1630 && ! NILP (w
->start_at_line_beg
)
1631 && ! EQ (w
->window_end_valid
, Qnil
)
1632 && do_id
&& !current_buffer
->clip_changed
1633 && !blank_end_of_window
1634 && XFASTINT (w
->width
) == FRAME_WIDTH (f
)
1635 /* Can't use this case if highlighting a region. */
1636 && !(!NILP (Vtransient_mark_mode
)
1637 && !NILP (current_buffer
->mark_active
))
1638 /* Don't use try_window_id if newline
1639 doesn't display as the end of a line. */
1640 && !(dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, '\n')))
1641 && NILP (w
->region_showing
)
1642 && EQ (last_arrow_position
, Voverlay_arrow_position
)
1643 && EQ (last_arrow_string
, Voverlay_arrow_string
)
1644 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
1647 /* tem > 0 means success. tem == -1 means choose new start.
1648 tem == -2 means try again with same start,
1649 and nothing but whitespace follows the changed stuff.
1650 tem == 0 means try again with same start. */
1654 else if (startp
>= BEGV
&& startp
<= ZV
1655 /* Avoid starting display at end of buffer! */
1656 && (startp
< ZV
|| startp
== BEGV
1657 || (XFASTINT (w
->last_modified
) >= MODIFF
)))
1659 /* Try to redisplay starting at same place as before */
1660 /* If point has not moved off frame, accept the results */
1661 try_window (window
, startp
);
1662 if (cursor_vpos
>= 0)
1664 if (!just_this_one
|| current_buffer
->clip_changed
1665 || beg_unchanged
< startp
)
1666 /* Forget any recorded base line for line number display. */
1667 w
->base_line_number
= Qnil
;
1671 cancel_my_columns (w
);
1674 XSETFASTINT (w
->last_modified
, 0);
1675 /* Redisplay the mode line. Select the buffer properly for that. */
1676 if (!update_mode_line
)
1678 set_buffer_temp (old
);
1679 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1680 update_mode_line
= 1;
1681 w
->update_mode_line
= Qt
;
1684 /* Try to scroll by specified few lines */
1686 if (scroll_step
&& !current_buffer
->clip_changed
1687 && startp
>= BEGV
&& startp
<= ZV
)
1691 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), scroll_step
, w
);
1692 if (pos
.vpos
>= height
)
1696 pos
= *vmotion (startp
, (PT
< startp
? - scroll_step
: scroll_step
), w
);
1698 if (PT
>= pos
.bufpos
)
1700 if (! NILP (Vwindow_scroll_functions
))
1701 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1702 make_number (pos
.bufpos
));
1703 try_window (window
, pos
.bufpos
);
1704 if (cursor_vpos
>= 0)
1706 if (!just_this_one
|| current_buffer
->clip_changed
1707 || beg_unchanged
< startp
)
1708 /* Forget any recorded base line for line number display. */
1709 w
->base_line_number
= Qnil
;
1713 cancel_my_columns (w
);
1718 /* Finally, just choose place to start which centers point */
1721 /* Forget any previously recorded base line for line number display. */
1722 w
->base_line_number
= Qnil
;
1724 pos
= *vmotion (PT
, - (height
/ 2), w
);
1725 /* Set startp here explicitly in case that helps avoid an infinite loop
1726 in case the window-scroll-functions functions get errors. */
1727 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1728 if (! NILP (Vwindow_scroll_functions
))
1729 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1730 make_number (pos
.bufpos
));
1731 try_window (window
, pos
.bufpos
);
1733 startp
= marker_position (w
->start
);
1734 w
->start_at_line_beg
1735 = (startp
== BEGV
|| FETCH_CHAR (startp
- 1) == '\n') ? Qt
: Qnil
;
1738 if ((update_mode_line
1739 /* If window not full width, must redo its mode line
1740 if the window to its side is being redone */
1741 || (!just_this_one
&& width
< FRAME_WIDTH (f
) - 1)
1742 || INTEGERP (w
->base_line_pos
)
1743 || (!NILP (w
->column_number_displayed
)
1744 && XFASTINT (w
->column_number_displayed
) != current_column ()))
1745 && height
!= XFASTINT (w
->height
))
1746 display_mode_line (w
);
1747 if (! line_number_displayed
1748 && ! BUFFERP (w
->base_line_pos
))
1750 w
->base_line_pos
= Qnil
;
1751 w
->base_line_number
= Qnil
;
1754 /* When we reach a frame's selected window, redo the frame's menu bar. */
1755 if (update_mode_line
1758 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1759 FRAME_EXTERNAL_MENU_BAR (f
)
1761 FRAME_MENU_BAR_LINES (f
) > 0
1763 : FRAME_MENU_BAR_LINES (f
) > 0)
1764 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
1765 display_menu_bar (w
);
1768 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
1770 int start
, end
, whole
;
1772 /* Calculate the start and end positions for the current window.
1773 At some point, it would be nice to choose between scrollbars
1774 which reflect the whole buffer size, with special markers
1775 indicating narrowing, and scrollbars which reflect only the
1778 Note that minibuffers sometimes aren't displaying any text. */
1779 if (! MINI_WINDOW_P (w
)
1780 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
1783 start
= marker_position (w
->start
) - BEGV
;
1784 /* I don't think this is guaranteed to be right. For the
1785 moment, we'll pretend it is. */
1786 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
1788 if (end
< start
) end
= start
;
1789 if (whole
< (end
- start
)) whole
= end
- start
;
1792 start
= end
= whole
= 0;
1794 /* Indicate what this scroll bar ought to be displaying now. */
1795 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
1797 /* Note that we actually used the scroll bar attached to this window,
1798 so it shouldn't be deleted at the end of redisplay. */
1799 (*redeem_scroll_bar_hook
) (w
);
1802 BUF_PT (current_buffer
) = opoint
;
1803 if (update_mode_line
)
1804 set_buffer_internal_1 (old
);
1806 set_buffer_temp (old
);
1807 BUF_PT (current_buffer
) = lpoint
;
1810 /* Do full redisplay on one window, starting at position `pos'. */
1813 try_window (window
, pos
)
1817 register struct window
*w
= XWINDOW (window
);
1818 register int height
= window_internal_height (w
);
1819 register int vpos
= XFASTINT (w
->top
);
1820 register int last_text_vpos
= vpos
;
1821 int tab_offset
= pos_tab_offset (w
, pos
);
1822 FRAME_PTR f
= XFRAME (w
->frame
);
1823 int width
= window_internal_width (w
) - 1;
1824 struct position val
;
1826 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1828 overlay_arrow_seen
= 0;
1829 zv_strings_seen
= 0;
1830 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
1832 while (--height
>= 0)
1834 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, tab_offset
);
1835 tab_offset
+= width
;
1836 /* For the first line displayed, display_text_line
1837 subtracts the prompt width from the tab offset.
1838 But it does not affect the value of our variable tab_offset.
1839 So we do the subtraction again,
1840 for the sake of continuation lines of that first line. */
1841 if (MINI_WINDOW_P (w
) && vpos
== XFASTINT (w
->top
))
1842 tab_offset
-= minibuf_prompt_width
;
1844 if (val
.vpos
) tab_offset
= 0;
1846 if (pos
!= val
.bufpos
)
1849 #ifdef USE_TEXT_PROPERTIES
1850 Lisp_Object invis_prop
;
1851 invis_prop
= Fget_char_property (val
.bufpos
-1, Qinvisible
, window
);
1852 invis
= TEXT_PROP_MEANS_INVISIBLE (invis_prop
);
1856 /* Next line, unless prev line ended in end of buffer with no cr */
1858 && (FETCH_CHAR (val
.bufpos
- 1) != '\n' || invis
));
1863 /* If last line is continued in middle of character,
1864 include the split character in the text considered on the frame */
1865 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1868 /* If bottom just moved off end of frame, change mode line percentage. */
1869 if (XFASTINT (w
->window_end_pos
) == 0
1871 w
->update_mode_line
= Qt
;
1873 /* Say where last char on frame will be, once redisplay is finished. */
1874 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
1875 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
1876 /* But that is not valid info until redisplay finishes. */
1877 w
->window_end_valid
= Qnil
;
1880 /* Try to redisplay when buffer is modified locally,
1881 computing insert/delete line to preserve text outside
1882 the bounds of the changes.
1883 Return 1 if successful, 0 if if cannot tell what to do,
1884 or -1 to tell caller to find a new window start,
1885 or -2 to tell caller to do normal redisplay with same window start. */
1888 try_window_id (window
)
1892 register struct window
*w
= XWINDOW (window
);
1893 register int height
= window_internal_height (w
);
1894 FRAME_PTR f
= XFRAME (w
->frame
);
1895 int top
= XFASTINT (w
->top
);
1896 int start
= marker_position (w
->start
);
1897 int width
= window_internal_width (w
) - 1;
1898 int hscroll
= XINT (w
->hscroll
);
1899 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
1902 register int i
, tem
;
1903 int last_text_vpos
= 0;
1905 int selective
= (INTEGERP (current_buffer
->selective_display
)
1906 ? XINT (current_buffer
->selective_display
)
1907 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
1909 struct position val
, bp
, ep
, xp
, pp
;
1910 int scroll_amount
= 0;
1912 int tab_offset
, epto
, old_tick
;
1914 if (GPT
- BEG
< beg_unchanged
)
1915 beg_unchanged
= GPT
- BEG
;
1916 if (Z
- GPT
< end_unchanged
)
1917 end_unchanged
= Z
- GPT
;
1919 if (beg_unchanged
+ BEG
< start
)
1920 return 0; /* Give up if changes go above top of window */
1922 /* Find position before which nothing is changed. */
1923 bp
= *compute_motion (start
, 0, lmargin
, 0,
1924 min (ZV
, beg_unchanged
+ BEG
), height
, 0,
1925 width
, hscroll
, pos_tab_offset (w
, start
), w
);
1926 if (bp
.vpos
>= height
)
1930 /* All changes are beyond the window end, and point is on the screen.
1931 We don't need to change the text at all.
1932 But we need to update window_end_pos to account for
1933 any change in buffer size. */
1934 bp
= *compute_motion (start
, 0, lmargin
, 0,
1936 width
, hscroll
, pos_tab_offset (w
, start
), w
);
1937 XSETFASTINT (w
->window_end_vpos
, height
);
1938 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
1946 /* Find beginning of that frame line. Must display from there. */
1947 bp
= *vmotion (bp
.bufpos
, 0, w
);
1955 /* If about to start displaying at the beginning of a continuation line,
1956 really start with previous frame line, in case it was not
1957 continued when last redisplayed */
1958 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
1960 /* Likewise if we have to worry about selective display. */
1961 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
1963 bp
= *vmotion (bp
.bufpos
, -1, w
);
1968 if (bp
.contin
&& bp
.hpos
!= lmargin
)
1970 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
1977 /* Find first visible newline after which no more is changed. */
1978 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
1980 while (tem
< ZV
- 1 && (indented_beyond_p (tem
, selective
)))
1981 tem
= find_next_newline (tem
, 1);
1983 /* Compute the cursor position after that newline. */
1984 ep
= *compute_motion (pos
, vpos
, val
.hpos
, did_motion
, tem
,
1985 height
, - (1 << (BITS_PER_SHORT
- 1)),
1986 width
, hscroll
, pos_tab_offset (w
, bp
.bufpos
), w
);
1988 /* If changes reach past the text available on the frame,
1989 just display rest of frame. */
1990 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
1993 stop_vpos
= ep
.vpos
;
1995 /* If no newline before ep, the line ep is on includes some changes
1996 that must be displayed. Make sure we don't stop before it. */
1997 /* Also, if changes reach all the way until ep.bufpos,
1998 it is possible that something was deleted after the
1999 newline before it, so the following line must be redrawn. */
2000 if (stop_vpos
== ep
.vpos
2001 && (ep
.bufpos
== BEGV
2002 || FETCH_CHAR (ep
.bufpos
- 1) != '\n'
2003 || ep
.bufpos
== Z
- end_unchanged
))
2004 stop_vpos
= ep
.vpos
+ 1;
2007 overlay_arrow_seen
= 0;
2008 zv_strings_seen
= 0;
2010 /* If changes do not reach to bottom of window,
2011 figure out how much to scroll the rest of the window */
2012 if (stop_vpos
< height
)
2014 /* Now determine how far up or down the rest of the window has moved */
2015 epto
= pos_tab_offset (w
, ep
.bufpos
);
2016 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2017 Z
- XFASTINT (w
->window_end_pos
),
2018 10000, 0, width
, hscroll
, epto
, w
);
2019 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
2021 /* Is everything on frame below the changes whitespace?
2022 If so, no scrolling is really necessary. */
2023 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
2025 tem
= FETCH_CHAR (i
);
2026 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
2032 XSETFASTINT (w
->window_end_vpos
,
2033 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
2035 /* Before doing any scrolling, verify that point will be on frame. */
2036 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.bufpos
< height
))
2038 if (PT
<= xp
.bufpos
)
2040 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
, 1,
2041 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2042 width
, hscroll
, epto
, w
);
2046 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
, 1,
2047 PT
, height
, - (1 << (BITS_PER_SHORT
- 1)),
2049 pos_tab_offset (w
, xp
.bufpos
), w
);
2051 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
2053 cursor_vpos
= pp
.vpos
+ top
;
2054 cursor_hpos
= XFASTINT (w
->left
) + minmax (0, pp
.hpos
, width
);
2057 if (stop_vpos
- scroll_amount
>= height
2058 || ep
.bufpos
== xp
.bufpos
)
2060 if (scroll_amount
< 0)
2061 stop_vpos
-= scroll_amount
;
2063 /* In this path, we have altered window_end_vpos
2064 and not left it negative.
2065 We must make sure that, in case display is preempted
2066 before the frame changes to reflect what we do here,
2067 further updates will not come to try_window_id
2068 and assume the frame and window_end_vpos match. */
2069 blank_end_of_window
= 1;
2071 else if (!scroll_amount
)
2073 /* Even if we don't need to scroll, we must adjust the
2074 charstarts of subsequent lines (that we won't redisplay)
2075 according to the amount of text inserted or deleted. */
2076 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2077 int adjust
= ep
.bufpos
- oldpos
;
2078 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
2080 else if (bp
.bufpos
== Z
- end_unchanged
)
2082 /* If reprinting everything is nearly as fast as scrolling,
2083 don't bother scrolling. Can happen if lines are short. */
2084 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
2085 top
+ height
- max (0, scroll_amount
),
2087 > xp
.bufpos
- bp
.bufpos
- 20)
2088 /* Return "try normal display with same window-start."
2089 Too bad we can't prevent further scroll-thinking. */
2091 /* If pure deletion, scroll up as many lines as possible.
2092 In common case of killing a line, this can save the
2093 following line from being overwritten by scrolling
2094 and therefore having to be redrawn. */
2095 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
2096 top
+ height
- max (0, scroll_amount
),
2097 scroll_amount
, bp
.bufpos
);
2102 /* scroll_frame_lines did not properly adjust subsequent
2103 lines' charstarts in the case where the text of the
2104 screen line at bp.vpos has changed.
2105 (This can happen in a deletion that ends in mid-line.)
2106 To adjust properly, we need to make things consistent
2108 So do a second adjust to make that happen.
2109 Note that stop_vpos >= ep.vpos, so it is sufficient
2110 to update the charstarts for lines at ep.vpos and below. */
2112 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
2113 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
2114 ep
.bufpos
- oldstart
);
2117 else if (scroll_amount
)
2119 /* If reprinting everything is nearly as fast as scrolling,
2120 don't bother scrolling. Can happen if lines are short. */
2121 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2122 overestimate of cost of reprinting, since xp.bufpos
2123 would end up below the bottom of the window. */
2124 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
2125 top
+ height
- max (0, scroll_amount
),
2127 > xp
.bufpos
- ep
.bufpos
- 20)
2128 /* Return "try normal display with same window-start."
2129 Too bad we can't prevent further scroll-thinking. */
2131 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
2132 top
+ height
- max (0, scroll_amount
),
2133 scroll_amount
, ep
.bufpos
);
2134 if (!tem
) stop_vpos
= height
;
2138 /* In any case, do not display past bottom of window */
2139 if (stop_vpos
>= height
)
2145 /* Handle case where pos is before w->start --
2146 can happen if part of line had been clipped and is not clipped now */
2147 if (vpos
== 0 && pos
< marker_position (w
->start
))
2148 Fset_marker (w
->start
, make_number (pos
), Qnil
);
2150 /* Redisplay the lines where the text was changed */
2151 last_text_vpos
= vpos
;
2152 tab_offset
= pos_tab_offset (w
, pos
);
2153 /* If we are starting display in mid-character, correct tab_offset
2154 to account for passing the line that that character really starts in. */
2155 if (val
.hpos
< lmargin
)
2156 tab_offset
+= width
;
2158 while (vpos
< stop_vpos
)
2160 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
2161 /* If display_text_line ran a hook and changed some text,
2162 redisplay all the way to bottom of buffer
2163 So that we show the changes. */
2164 if (old_tick
!= MODIFF
)
2166 tab_offset
+= width
;
2167 if (val
.vpos
) tab_offset
= 0;
2168 if (pos
!= val
.bufpos
)
2170 /* Next line, unless prev line ended in end of buffer with no cr */
2171 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
2175 /* There are two cases:
2176 1) we have displayed down to the bottom of the window
2177 2) we have scrolled lines below stop_vpos by scroll_amount */
2181 /* If last line is continued in middle of character,
2182 include the split character in the text considered on the frame */
2183 if (val
.hpos
< lmargin
)
2185 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
2186 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2189 /* If scrolling made blank lines at window bottom,
2190 redisplay to fill those lines */
2191 if (scroll_amount
< 0)
2193 /* Don't consider these lines for general-purpose scrolling.
2194 That will save time in the scrolling computation. */
2195 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
2200 vpos
= height
+ scroll_amount
;
2201 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
2203 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
2207 blank_end_of_window
= 1;
2208 tab_offset
= pos_tab_offset (w
, pos
);
2209 /* If we are starting display in mid-character, correct tab_offset
2210 to account for passing the line that that character starts in. */
2211 if (val
.hpos
< lmargin
)
2212 tab_offset
+= width
;
2214 while (vpos
< height
)
2216 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
2217 tab_offset
+= width
;
2218 if (val
.vpos
) tab_offset
= 0;
2222 /* Here is a case where display_text_line sets cursor_vpos wrong.
2223 Make it be fixed up, below. */
2229 /* If bottom just moved off end of frame, change mode line percentage. */
2230 if (XFASTINT (w
->window_end_pos
) == 0
2232 w
->update_mode_line
= Qt
;
2234 /* Attempt to adjust end-of-text positions to new bottom line */
2237 delta
= height
- xp
.vpos
;
2239 || (delta
> 0 && xp
.bufpos
<= ZV
)
2240 || (delta
== 0 && xp
.hpos
))
2242 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
), delta
, w
);
2243 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
2244 XSETFASTINT (w
->window_end_vpos
,
2245 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
2249 w
->window_end_valid
= Qnil
;
2251 /* If point was not in a line that was displayed, find it */
2252 if (cursor_vpos
< 0)
2255 val
= *compute_motion (start
, 0, lmargin
, 0, PT
, 10000, 10000,
2256 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2257 /* Admit failure if point is off frame now */
2258 if (val
.vpos
>= height
)
2260 for (vpos
= 0; vpos
< height
; vpos
++)
2261 cancel_line (vpos
+ top
, f
);
2264 cursor_vpos
= val
.vpos
+ top
;
2265 cursor_hpos
= XFASTINT (w
->left
) + minmax (0, val
.hpos
, width
);
2268 FRAME_CURSOR_X (f
) = cursor_hpos
;
2269 FRAME_CURSOR_Y (f
) = cursor_vpos
;
2273 val
= *compute_motion (start
, 0, lmargin
, 0, ZV
,
2274 height
, - (1 << (BITS_PER_SHORT
- 1)),
2275 width
, hscroll
, pos_tab_offset (w
, start
), w
);
2276 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
2278 if (XFASTINT (w
->window_end_pos
)
2286 /* Mark a section of BUF as modified, but only for the sake of redisplay.
2287 This is useful for recording changes to overlays.
2289 We increment the buffer's modification timestamp and set the
2290 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
2291 as if the region of text between START and END had been modified;
2292 the redisplay code will check this against the windows' timestamps,
2293 and redraw the appropriate area of the buffer.
2295 However, if the buffer is unmodified, we bump the last-save
2296 timestamp as well, so that incrementing the timestamp doesn't fool
2297 Emacs into thinking that the buffer's text has been modified.
2299 Tweaking the timestamps shouldn't hurt the first-modification
2300 timestamps recorded in the undo records; those values aren't
2301 written until just before a real text modification is made, so they
2302 will never catch the timestamp value just before this function gets
2306 redisplay_region (buf
, start
, end
)
2316 start
= end
; end
= temp
;
2319 /* If this is a buffer not in the selected window,
2320 we must do other windows. */
2321 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
2322 windows_or_buffers_changed
= 1;
2323 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2324 else if (buf
!= current_buffer
)
2325 windows_or_buffers_changed
= 1;
2326 /* If multiple windows show this buffer, we must do other windows. */
2327 else if (buffer_shared
> 1)
2328 windows_or_buffers_changed
= 1;
2331 if (unchanged_modified
== MODIFF
)
2333 beg_unchanged
= start
- BEG
;
2334 end_unchanged
= Z
- end
;
2338 if (Z
- end
< end_unchanged
)
2339 end_unchanged
= Z
- end
;
2340 if (start
- BEG
< beg_unchanged
)
2341 beg_unchanged
= start
- BEG
;
2345 /* Increment the buffer's time stamp, but also increment the save
2346 and autosave timestamps, so as not to screw up that timekeeping. */
2347 if (BUF_MODIFF (buf
) == BUF_SAVE_MODIFF (buf
))
2348 BUF_SAVE_MODIFF (buf
)++;
2349 if (BUF_MODIFF (buf
) == buf
->auto_save_modified
)
2350 buf
->auto_save_modified
++;
2352 BUF_MODIFF (buf
) ++;
2356 /* Copy LEN glyphs starting address FROM to the rope TO.
2357 But don't actually copy the parts that would come in before S.
2358 Value is TO, advanced past the copied data.
2359 F is the frame we are displaying in. */
2362 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
2364 register GLYPH
*to
; /* Copy to here. */
2365 register GLYPH
*s
; /* Starting point. */
2366 Lisp_Object
*from
; /* Data to copy. */
2368 int face
; /* Face to apply to glyphs which don't specify one. */
2371 register Lisp_Object
*fp
= from
;
2372 /* These cache the results of the last call to compute_glyph_face. */
2374 int last_merged
= 0;
2377 if (! FRAME_TERMCAP_P (f
))
2380 int glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2383 if (FAST_GLYPH_FACE (glyph
) == 0)
2384 /* If GLYPH has no face code, use FACE. */
2386 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
2387 /* If it's same as previous glyph, use same result. */
2388 facecode
= last_merged
;
2391 /* Merge this glyph's face and remember the result. */
2392 last_code
= FAST_GLYPH_FACE (glyph
);
2393 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
2397 *to
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), facecode
);
2405 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2412 /* Correct a glyph by replacing its specified user-level face code
2413 with a displayable computed face code. */
2416 fix_glyph (f
, glyph
, cface
)
2422 if (! FRAME_TERMCAP_P (f
))
2424 if (FAST_GLYPH_FACE (glyph
) != 0)
2425 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
2426 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
2432 /* Display one line of window W, starting at position START in W's buffer.
2434 Display starting at horizontal position HPOS, expressed relative to
2435 W's left edge. In situations where the text at START shouldn't
2436 start at the left margin (i.e. when the window is hscrolled, or
2437 we're continuing a line which left off in the midst of a
2438 multi-column character), HPOS should be negative; we throw away
2439 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2442 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2444 Display on position VPOS on the frame. It is origin 0, relative to
2445 the top of the frame, not W.
2447 Returns a STRUCT POSITION giving character to start next line with
2448 and where to display it, including a zero or negative hpos.
2449 The vpos field is not really a vpos; it is 1 unless the line is continued */
2451 struct position val_display_text_line
;
2453 static struct position
*
2454 display_text_line (w
, start
, vpos
, hpos
, taboffset
)
2461 register int pos
= start
;
2465 register unsigned char *p
;
2467 register GLYPH
*leftmargin
;
2468 register GLYPH
*p1prev
;
2469 register GLYPH
*p1start
;
2472 FRAME_PTR f
= XFRAME (w
->frame
);
2473 int tab_width
= XINT (current_buffer
->tab_width
);
2474 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
2475 int width
= window_internal_width (w
) - 1;
2476 struct position val
;
2479 int last_invis_skip
= 0;
2480 Lisp_Object last_invis_prop
;
2481 int hscroll
= XINT (w
->hscroll
);
2482 int truncate
= (hscroll
2483 || (truncate_partial_width_windows
2484 && XFASTINT (w
->width
) < FRAME_WIDTH (f
))
2485 || !NILP (current_buffer
->truncate_lines
));
2487 /* 1 if we should highlight the region. */
2488 int highlight_region
2489 = !NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
);
2490 int region_beg
, region_end
;
2492 int selective
= (INTEGERP (current_buffer
->selective_display
)
2493 ? XINT (current_buffer
->selective_display
)
2494 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2495 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
2496 register struct Lisp_Char_Table
*dp
= window_display_table (w
);
2498 Lisp_Object default_invis_vector
[3];
2499 /* Number of characters of ellipsis to display after an invisible line
2500 if it calls for an ellipsis.
2501 Note that this value can be nonzero regardless of whether
2502 selective display is enabled--you must check that separately. */
2504 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2505 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
2506 : !NILP (current_buffer
->selective_display_ellipses
) ? 3 : 0);
2507 /* This is the sequence of Lisp objects to display
2508 when there are invisible lines. */
2509 Lisp_Object
*invis_vector_contents
2510 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2511 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
2512 : default_invis_vector
);
2514 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
2515 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
2516 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
2517 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
2519 /* The next buffer location at which the face should change, due
2520 to overlays or text property changes. */
2521 int next_face_change
;
2523 /* The next location where the `invisible' property changes, or an
2524 overlay starts or ends. */
2527 /* The face we're currently using. */
2528 int current_face
= 0;
2531 XSETFASTINT (default_invis_vector
[2], '.');
2532 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
2534 hpos
+= XFASTINT (w
->left
);
2535 get_display_line (f
, vpos
, XFASTINT (w
->left
));
2536 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
2538 /* Show where to highlight the region. */
2539 if (highlight_region
&& XMARKER (current_buffer
->mark
)->buffer
!= 0
2540 /* Maybe highlight only in selected window. */
2541 && (highlight_nonselected_windows
2542 || w
== XWINDOW (selected_window
)))
2544 region_beg
= marker_position (current_buffer
->mark
);
2545 if (PT
< region_beg
)
2547 region_end
= region_beg
;
2552 w
->region_showing
= Qt
;
2555 region_beg
= region_end
= -1;
2557 if (MINI_WINDOW_P (w
)
2559 && vpos
== XFASTINT (w
->top
))
2561 if (! NILP (minibuf_prompt
))
2563 minibuf_prompt_width
2564 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
2565 XSTRING (minibuf_prompt
)->size
, hpos
,
2566 /* Display a space if we truncate. */
2569 /* Truncate the prompt a little before the
2570 margin, so user input can at least start
2571 on the first line. */
2572 w
->width
> 10 ? w
->width
- 4 : -1)
2574 hpos
+= minibuf_prompt_width
;
2575 taboffset
-= minibuf_prompt_width
;
2578 minibuf_prompt_width
= 0;
2581 /* If we're hscrolled at all, use compute_motion to skip over any
2582 text off the left edge of the window. compute_motion may know
2583 tricks to do this faster than we can. */
2586 struct position
*left_edge
2587 = compute_motion (pos
, vpos
, hpos
, 0,
2589 width
, hscroll
, taboffset
, w
);
2591 /* Retrieve the buffer position and column provided by
2592 compute_motion. We can't assume that the column will be
2593 zero, because you may have multi-column characters crossing
2596 compute_motion may have moved us past the screen position we
2597 requested, if we hit a multi-column character, or the end of
2598 the line. If so, back up. */
2599 if (left_edge
->vpos
> vpos
2600 || left_edge
->hpos
> 0)
2602 pos
= left_edge
->bufpos
- 1;
2603 hpos
= left_edge
->prevhpos
;
2607 pos
= left_edge
->bufpos
;
2608 hpos
= left_edge
->hpos
;
2612 desired_glyphs
->bufp
[vpos
] = start
;
2613 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2615 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
2616 /* In case we don't ever write anything into it... */
2617 desired_glyphs
->charstarts
[vpos
][XFASTINT (w
->left
)] = -1;
2618 leftmargin
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
2619 endp
= leftmargin
+ width
;
2621 /* Arrange the overlays nicely for our purposes. Usually, we call
2622 display_text_line on only one line at a time, in which case this
2623 can't really hurt too much, or we call it on lines which appear
2624 one after another in the buffer, in which case all calls to
2625 recenter_overlay_lists but the first will be pretty cheap. */
2626 recenter_overlay_lists (current_buffer
, pos
);
2628 /* Loop generating characters.
2629 Stop at end of buffer, before newline,
2630 if reach or pass continuation column,
2631 or at face change. */
2633 next_face_change
= pos
;
2634 next_boundary
= pos
;
2643 while (pos
== next_boundary
)
2645 Lisp_Object position
, limit
, prop
, ww
;
2647 /* Display the overlay strings here, unless we're at ZV
2648 and have already displayed the appropriate strings
2649 on an earlier line. */
2650 if (pos
< ZV
|| !zv_strings_seen
++)
2654 ovlen
= overlay_strings (pos
, w
, &ovstr
);
2655 for (; ovlen
; ovlen
--, ovstr
++)
2657 if (p1
>= leftmargin
&& p1
< endp
)
2658 *p1
= MAKE_GLYPH (f
, *ovstr
, current_face
);
2663 /* Did we reach point? Record the cursor location. */
2664 if (pos
== PT
&& cursor_vpos
< 0)
2667 cursor_hpos
= p1
- leftmargin
;
2673 XSETFASTINT (position
, pos
);
2674 limit
= Fnext_overlay_change (position
);
2675 #ifdef USE_TEXT_PROPERTIES
2676 /* This is just an estimate to give reasonable
2677 performance; nothing should go wrong if it is too small. */
2678 if (XFASTINT (limit
) > pos
+ 50)
2679 XSETFASTINT (limit
, pos
+ 50);
2680 limit
= Fnext_single_property_change (position
, Qinvisible
,
2681 Fcurrent_buffer (), limit
);
2683 next_boundary
= XFASTINT (limit
);
2684 /* if the `invisible' property is set, we can skip to
2685 the next property change. */
2687 prop
= Fget_char_property (position
, Qinvisible
, ww
);
2688 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2690 if (pos
< PT
&& next_boundary
>= PT
)
2693 cursor_hpos
= p1
- leftmargin
;
2695 pos
= next_boundary
;
2696 last_invis_skip
= pos
;
2697 last_invis_prop
= prop
;
2701 /* Did we reach point? Record the cursor location. */
2702 if (pos
== PT
&& cursor_vpos
< 0)
2705 cursor_hpos
= p1
- leftmargin
;
2708 /* Did we hit the end of the visible region of the buffer?
2712 /* Update charstarts for the end of this line. */
2713 /* Do nothing if off the left edge or at the right edge. */
2714 if (p1
>= leftmargin
&& p1
+ 1 != endp
)
2716 int *p2x
= &charstart
[(p1
< leftmargin
2724 /* Figure out where (if at all) the
2725 redisplay_end_trigger-hook should run. */
2726 if (MARKERP (w
->redisplay_end_trigger
)
2727 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2728 e_t_h
= marker_position (w
->redisplay_end_trigger
);
2729 else if (INTEGERP (w
->redisplay_end_trigger
))
2730 e_t_h
= XINT (w
->redisplay_end_trigger
);
2734 /* If we've gone past the place to run a hook,
2736 if (pos
>= e_t_h
&& e_t_h
!= ZV
)
2738 Lisp_Object args
[3];
2740 args
[0] = Qredisplay_end_trigger_functions
;
2741 XSETWINDOW (args
[1], w
);
2742 XSETINT (args
[2], e_t_h
);
2743 Frun_hook_with_args (3, args
);
2745 w
->redisplay_end_trigger
= Qnil
;
2747 /* Notice if it changed the face of this character. */
2748 next_face_change
= pos
;
2752 /* Did we hit a face change? Figure out what face we should
2753 use now. We also hit this the first time through the
2754 loop, to see what face we should start with. */
2755 if (pos
>= next_face_change
&& (FRAME_WINDOW_P (f
)))
2756 current_face
= compute_char_face (f
, w
, pos
,
2757 region_beg
, region_end
,
2758 &next_face_change
, pos
+ 50, 0);
2761 /* Compute the next place we need to stop
2762 and do something special; set PAUSE. */
2766 if (pos
< next_boundary
&& next_boundary
< pause
)
2767 pause
= next_boundary
;
2768 if (pos
< next_face_change
&& next_face_change
< pause
)
2769 pause
= next_face_change
;
2774 /* Wouldn't you hate to read the next line to someone over
2776 if (pos
< PT
&& PT
< pause
)
2778 if (pos
< GPT
&& GPT
< pause
)
2781 p
= &FETCH_CHAR (pos
);
2790 /* Let a display table override all standard display methods. */
2791 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
2793 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
2794 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
2795 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
2798 else if (c
>= 040 && c
< 0177)
2800 if (p1
>= leftmargin
)
2801 *p1
= MAKE_GLYPH (f
, c
, current_face
);
2807 if (last_invis_skip
== pos
2808 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop
))
2812 && indented_beyond_p (pos
+ 1, selective
))
2815 pos
= find_next_newline (pos
+ 1, 1);
2816 if (FETCH_CHAR (pos
- 1) == '\n')
2819 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
2821 p1
+= selective_rlen
;
2822 if (p1
- leftmargin
> width
)
2824 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
2825 (p1
- p1prev
), current_face
);
2828 /* Draw the face of the newline character as extending all the
2829 way to the end of the frame line. */
2832 if (p1
< leftmargin
)
2835 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
);
2839 /* Update charstarts for the newline that ended this line. */
2840 /* Do nothing here for a char that's entirely off the left edge
2841 or if it starts at the right edge. */
2842 if (p1
>= leftmargin
&& p1prev
!= endp
)
2844 /* Store the newline's position into charstarts
2845 for the column where the newline starts.
2846 Store -1 for the rest of the glyphs it occupies. */
2847 int *p2x
= &charstart
[(p1prev
< leftmargin
2848 ? leftmargin
: p1prev
)
2850 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
2863 if (p1
>= leftmargin
&& p1
< endp
)
2864 *p1
= MAKE_GLYPH (f
, ' ', current_face
);
2867 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
2870 else if (c
== Ctl ('M') && selective
== -1)
2872 pos
= find_next_newline (pos
, 1);
2873 if (FETCH_CHAR (pos
- 1) == '\n')
2875 if (selective_rlen
> 0)
2877 p1
+= selective_rlen
;
2878 if (p1
- leftmargin
> width
)
2880 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
2881 (p1
- p1prev
), current_face
);
2884 /* Draw the face of the newline character as extending all the
2885 way to the end of the frame line. */
2888 if (p1
< leftmargin
)
2891 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
);
2895 /* Update charstarts for the ^M that ended this line. */
2896 /* Do nothing here for a char that's entirely off the left edge
2897 or if it starts at the right edge. */
2898 if (p1
>= leftmargin
&& p1prev
!= endp
)
2900 /* Store the newline's position into charstarts
2901 for the column where the newline starts.
2902 Store -1 for the rest of the glyphs it occupies. */
2903 int *p2x
= &charstart
[(p1prev
< leftmargin
2904 ? leftmargin
: p1prev
)
2906 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
2914 else if (c
< 0200 && ctl_arrow
)
2916 if (p1
>= leftmargin
)
2917 *p1
= fix_glyph (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
2918 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
2921 if (p1
>= leftmargin
&& p1
< endp
)
2922 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
);
2927 if (p1
>= leftmargin
)
2928 *p1
= fix_glyph (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
2929 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
2932 if (p1
>= leftmargin
&& p1
< endp
)
2933 *p1
= MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
);
2935 if (p1
>= leftmargin
&& p1
< endp
)
2936 *p1
= MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
);
2938 if (p1
>= leftmargin
&& p1
< endp
)
2939 *p1
= MAKE_GLYPH (f
, (7 & c
) + '0', current_face
);
2946 /* Update charstarts for the character just output. */
2948 /* Do nothing here for a char that's entirely off the left edge. */
2949 if (p1
>= leftmargin
)
2951 /* Store the char's position into charstarts
2952 for the first glyph occupied by this char.
2953 Store -1 for the rest of the glyphs it occupies. */
2956 int *p2x
= &charstart
[(p1prev
< leftmargin
2957 ? leftmargin
: p1prev
)
2959 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
2969 val
.hpos
= - XINT (w
->hscroll
);
2977 /* Store 0 in this charstart line for the positions where
2978 there is no character. But do leave what was recorded
2979 for the character that ended the line. */
2980 /* Add 1 in the endtest to compensate for the fact that ENDP was
2981 made from WIDTH, which is 1 less than the window's actual
2983 i
= p1
- p1start
+ 1;
2984 if (p1
< leftmargin
)
2985 i
+= leftmargin
- p1
;
2986 for (; i
< endp
- p1start
+ 1; i
++)
2989 /* Handle continuation in middle of a character */
2990 /* by backing up over it */
2993 /* Don't back up if we never actually displayed any text.
2994 This occurs when the minibuffer prompt takes up the whole line. */
2997 /* Start the next line with that same character */
2999 /* but at negative hpos, to skip the columns output on this line. */
3000 val
.hpos
+= p1prev
- endp
;
3003 /* Keep in this line everything up to the continuation column. */
3007 /* Finish deciding which character to start the next line on,
3008 and what hpos to start it at.
3009 Also set `lastpos' to the last position which counts as "on this line"
3010 for cursor-positioning. */
3014 if (FETCH_CHAR (pos
) == '\n')
3016 /* If stopped due to a newline, start next line after it */
3018 /* Check again for hidden lines, in case the newline occurred exactly
3019 at the right margin. */
3020 while (pos
< ZV
&& selective
> 0
3021 && indented_beyond_p (pos
, selective
))
3022 pos
= find_next_newline (pos
, 1);
3025 /* Stopped due to right margin of window */
3029 *p1
++ = fix_glyph (f
, truncator
, 0);
3030 /* Truncating => start next line after next newline,
3031 and point is on this line if it is before the newline,
3032 and skip none of first char of next line */
3034 pos
= find_next_newline (pos
, 1);
3035 while (pos
< ZV
&& selective
> 0
3036 && indented_beyond_p (pos
, selective
));
3037 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
3039 lastpos
= pos
- (FETCH_CHAR (pos
- 1) == '\n');
3043 *p1
++ = fix_glyph (f
, continuer
, 0);
3050 /* If point is at eol or in invisible text at eol,
3051 record its frame location now. */
3053 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
3056 cursor_hpos
= p1
- leftmargin
;
3059 if (cursor_vpos
== vpos
)
3061 if (cursor_hpos
< 0) cursor_hpos
= 0;
3062 if (cursor_hpos
> width
) cursor_hpos
= width
;
3063 cursor_hpos
+= XFASTINT (w
->left
);
3064 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
3066 if (!(cursor_in_echo_area
&& FRAME_HAS_MINIBUF_P (f
)
3067 && EQ (FRAME_MINIBUF_WINDOW (f
), minibuf_window
)))
3069 FRAME_CURSOR_Y (f
) = cursor_vpos
;
3070 FRAME_CURSOR_X (f
) = cursor_hpos
;
3073 if (w
== XWINDOW (selected_window
))
3075 /* Line is not continued and did not start
3076 in middle of character */
3077 if ((hpos
- XFASTINT (w
->left
)
3078 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
3081 this_line_bufpos
= start
;
3082 this_line_buffer
= current_buffer
;
3083 this_line_vpos
= cursor_vpos
;
3084 this_line_start_hpos
= hpos
;
3085 this_line_endpos
= Z
- lastpos
;
3088 this_line_bufpos
= 0;
3093 /* If hscroll and line not empty, insert truncation-at-left marker */
3094 if (hscroll
&& lastpos
!= start
)
3096 *leftmargin
= fix_glyph (f
, truncator
, 0);
3097 if (p1
<= leftmargin
)
3098 p1
= leftmargin
+ 1;
3101 if (XFASTINT (w
->width
) + XFASTINT (w
->left
) != FRAME_WIDTH (f
))
3104 if (p1
< leftmargin
) p1
= leftmargin
;
3105 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
3107 /* Don't draw vertical bars if we're using scroll bars. They're
3108 covered up by the scroll bars, and it's distracting to see
3109 them when the scroll bar windows are flickering around to be
3111 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3114 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
3118 *p1
++ = (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
3119 ? DISP_BORDER_GLYPH (dp
)
3122 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
3123 p1
- desired_glyphs
->glyphs
[vpos
]);
3124 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
3126 /* If the start of this line is the overlay arrow-position,
3127 then put the arrow string into the display-line. */
3129 if (MARKERP (Voverlay_arrow_position
)
3130 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
3131 && start
== marker_position (Voverlay_arrow_position
)
3132 && STRINGP (Voverlay_arrow_string
)
3133 && ! overlay_arrow_seen
)
3135 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
3137 int len
= XSTRING (Voverlay_arrow_string
)->size
;
3143 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string
)->intervals
))
3145 /* If the arrow string has text props, obey them when displaying. */
3146 for (i
= 0; i
< len
; i
++)
3149 Lisp_Object face
, ilisp
;
3152 XSETFASTINT (ilisp
, i
);
3153 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
3154 newface
= compute_glyph_face_1 (f
, face
, 0);
3155 leftmargin
[i
] = FAST_MAKE_GLYPH (c
, newface
);
3159 #endif /* HAVE_FACES */
3161 for (i
= 0; i
< len
; i
++)
3162 leftmargin
[i
] = p
[i
];
3165 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3166 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
3167 if (desired_glyphs
->used
[vpos
] < arrow_end
)
3168 desired_glyphs
->used
[vpos
] = arrow_end
;
3170 overlay_arrow_seen
= 1;
3174 val_display_text_line
= val
;
3175 return &val_display_text_line
;
3178 /* Redisplay the menu bar in the frame for window W. */
3181 display_menu_bar (w
)
3184 Lisp_Object items
, tail
;
3185 register int vpos
= 0;
3186 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3187 int maxendcol
= FRAME_WIDTH (f
);
3195 #ifdef USE_X_TOOLKIT
3198 #endif /* USE_X_TOOLKIT */
3200 get_display_line (f
, vpos
, 0);
3202 items
= FRAME_MENU_BAR_ITEMS (f
);
3203 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
3205 Lisp_Object pos
, string
;
3206 string
= XVECTOR (items
)->contents
[i
+ 1];
3210 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 2], hpos
);
3212 if (hpos
< maxendcol
)
3213 hpos
= display_string (XWINDOW (FRAME_ROOT_WINDOW (f
)), vpos
,
3214 XSTRING (string
)->data
,
3215 XSTRING (string
)->size
,
3216 hpos
, 0, 0, hpos
, maxendcol
);
3217 /* Put a space between items. */
3218 if (hpos
< maxendcol
)
3220 int hpos1
= hpos
+ 1;
3221 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
3222 min (hpos1
, maxendcol
), maxendcol
);
3226 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3227 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3229 /* Fill out the line with spaces. */
3230 if (maxendcol
> hpos
)
3231 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
);
3233 /* Clear the rest of the lines allocated to the menu bar. */
3235 while (vpos
< FRAME_MENU_BAR_LINES (f
))
3236 get_display_line (f
, vpos
++, 0);
3239 /* Display the mode line for window w */
3242 display_mode_line (w
)
3245 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
3246 register int left
= XFASTINT (w
->left
);
3247 register int right
= XFASTINT (w
->width
) + left
;
3248 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3250 line_number_displayed
= 0;
3251 w
->column_number_displayed
= Qnil
;
3253 get_display_line (f
, vpos
, left
);
3255 /* Temporarily make frame F's kboard the current kboard
3256 so that kboard-local variables in the mode_line_format
3257 will get the right values. */
3258 push_frame_kboard (f
);
3260 display_mode_element (w
, vpos
, left
, 0, right
, right
,
3261 current_buffer
->mode_line_format
);
3263 pop_frame_kboard ();
3265 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
3267 /* Make the mode line inverse video if the entire line
3268 is made of mode lines.
3269 I.e. if this window is full width,
3270 or if it is the child of a full width window
3271 (which implies that that window is split side-by-side
3272 and the rest of this line is mode lines of the sibling windows). */
3273 if (XFASTINT (w
->width
) == FRAME_WIDTH (f
)
3274 || XFASTINT (XWINDOW (w
->parent
)->width
) == FRAME_WIDTH (f
))
3275 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
3277 else if (! FRAME_TERMCAP_P (f
) && mode_line_inverse_video
)
3279 /* For a partial width window, explicitly set face of each glyph. */
3281 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
3282 for (i
= left
; i
< right
; ++i
)
3283 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1);
3288 /* Contribute ELT to the mode line for window W.
3289 How it translates into text depends on its data type.
3291 VPOS is the position of the mode line being displayed.
3293 HPOS is the position (absolute on frame) where this element's text
3294 should start. The output is truncated automatically at the right
3297 DEPTH is the depth in recursion. It is used to prevent
3298 infinite recursion here.
3300 MINENDCOL is the hpos before which the element may not end.
3301 The element is padded at the right with spaces if nec
3302 to reach this column.
3304 MAXENDCOL is the hpos past which this element may not extend.
3305 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3306 (This is necessary to make nested padding and truncation work.)
3308 Returns the hpos of the end of the text generated by ELT.
3309 The next element will receive that value as its HPOS arg,
3310 so as to concatenate the elements. */
3313 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
3315 register int vpos
, hpos
;
3318 register int maxendcol
;
3319 register Lisp_Object elt
;
3327 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
3331 /* A string: output it and check for %-constructs within it. */
3332 register unsigned char c
;
3333 register unsigned char *this = XSTRING (elt
)->data
;
3335 while (hpos
< maxendcol
&& *this)
3337 unsigned char *last
= this;
3338 while ((c
= *this++) != '\0' && c
!= '%')
3340 if (this - 1 != last
)
3342 register int lim
= --this - last
+ hpos
;
3343 if (frame_title_ptr
)
3344 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
3346 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
3347 hpos
, min (lim
, maxendcol
));
3351 register int minendcol
;
3352 register int spec_width
= 0;
3354 /* We can't allow -ve args due to the "%-" construct */
3355 /* Argument specifies minwidth but not maxwidth
3356 (maxwidth can be specified by
3357 (<negative-number> . <stuff>) mode-line elements) */
3359 while ((c
= *this++) >= '0' && c
<= '9')
3361 spec_width
= spec_width
* 10 + (c
- '0');
3364 minendcol
= hpos
+ spec_width
;
3365 if (minendcol
> maxendcol
)
3367 spec_width
= maxendcol
- hpos
;
3368 minendcol
= maxendcol
;
3372 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
3373 spec_width
, maxendcol
,
3374 Vglobal_mode_string
);
3377 char *spec
= decode_mode_spec (w
, c
, spec_width
,
3379 if (frame_title_ptr
)
3380 hpos
= store_frame_title (spec
, minendcol
, maxendcol
);
3382 hpos
= display_string (w
, vpos
, spec
, -1,
3384 minendcol
, maxendcol
);
3392 /* A symbol: process the value of the symbol recursively
3393 as if it appeared here directly. Avoid error if symbol void.
3394 Special case: if value of symbol is a string, output the string
3397 register Lisp_Object tem
;
3398 tem
= Fboundp (elt
);
3401 tem
= Fsymbol_value (elt
);
3402 /* If value is a string, output that string literally:
3403 don't check for % within it. */
3406 if (frame_title_ptr
)
3407 hpos
= store_frame_title (XSTRING (tem
)->data
,
3408 minendcol
, maxendcol
);
3410 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
3411 XSTRING (tem
)->size
,
3412 hpos
, 0, 1, minendcol
, maxendcol
);
3414 /* Give up right away for nil or t. */
3415 else if (!EQ (tem
, elt
))
3416 { elt
= tem
; goto tail_recurse
; }
3423 register Lisp_Object car
, tem
;
3425 /* A cons cell: three distinct cases.
3426 If first element is a string or a cons, process all the elements
3427 and effectively concatenate them.
3428 If first element is a negative number, truncate displaying cdr to
3429 at most that many characters. If positive, pad (with spaces)
3430 to at least that many characters.
3431 If first element is a symbol, process the cadr or caddr recursively
3432 according to whether the symbol's value is non-nil or nil. */
3433 car
= XCONS (elt
)->car
;
3436 tem
= Fboundp (car
);
3437 elt
= XCONS (elt
)->cdr
;
3440 /* elt is now the cdr, and we know it is a cons cell.
3441 Use its car if CAR has a non-nil value. */
3444 tem
= Fsymbol_value (car
);
3446 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
3448 /* Symbol's value is nil (or symbol is unbound)
3449 Get the cddr of the original list
3450 and if possible find the caddr and use that. */
3451 elt
= XCONS (elt
)->cdr
;
3454 else if (!CONSP (elt
))
3456 elt
= XCONS (elt
)->car
;
3459 else if (INTEGERP (car
))
3461 register int lim
= XINT (car
);
3462 elt
= XCONS (elt
)->cdr
;
3464 /* Negative int means reduce maximum width.
3465 DO NOT change MINENDCOL here!
3466 (20 -10 . foo) should truncate foo to 10 col
3467 and then pad to 20. */
3468 maxendcol
= min (maxendcol
, hpos
- lim
);
3471 /* Padding specified. Don't let it be more than
3474 if (lim
> maxendcol
)
3476 /* If that's more padding than already wanted, queue it.
3477 But don't reduce padding already specified even if
3478 that is beyond the current truncation point. */
3479 if (lim
> minendcol
)
3484 else if (STRINGP (car
) || CONSP (car
))
3486 register int limit
= 50;
3487 /* LIMIT is to protect against circular lists. */
3488 while (CONSP (elt
) && --limit
> 0
3489 && hpos
< maxendcol
)
3491 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
3494 elt
= XCONS (elt
)->cdr
;
3502 if (frame_title_ptr
)
3503 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
3505 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
3506 minendcol
, maxendcol
);
3510 if (minendcol
> hpos
)
3511 if (frame_title_ptr
)
3512 hpos
= store_frame_title ("", minendcol
, maxendcol
);
3514 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 1, minendcol
, maxendcol
);
3518 /* Write a null-terminated, right justified decimal representation of
3519 the positive integer D to BUF using a minimal field width WIDTH. */
3522 pint2str (buf
, width
, d
)
3527 register char *p
= buf
;
3534 *p
++ = d
% 10 + '0';
3537 for (width
-= (int) (p
- buf
); width
> 0; --width
) *p
++ = ' ';
3547 /* Return a string for the output of a mode line %-spec for window W,
3548 generated by character C. SPEC_WIDTH is the field width when
3549 padding to the left (%c, %l). The value returned from this
3550 function will later be truncated to width MAXWIDTH. */
3552 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3555 decode_mode_spec (w
, c
, spec_width
, maxwidth
)
3558 register int spec_width
;
3559 register int maxwidth
;
3562 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3563 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
3564 struct buffer
*b
= XBUFFER (w
->buffer
);
3567 if (maxwidth
> FRAME_WIDTH (f
))
3568 maxwidth
= FRAME_WIDTH (f
);
3573 if (!NILP (b
->read_only
))
3575 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
3580 /* This differs from %* only for a modified read-only buffer. */
3581 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
3583 if (!NILP (b
->read_only
))
3588 /* This differs from %* in ignoring read-only-ness. */
3589 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
3601 if (command_loop_level
> 5)
3603 p
= decode_mode_spec_buf
;
3604 for (i
= 0; i
< command_loop_level
; i
++)
3607 return decode_mode_spec_buf
;
3615 if (command_loop_level
> 5)
3617 p
= decode_mode_spec_buf
;
3618 for (i
= 0; i
< command_loop_level
; i
++)
3621 return decode_mode_spec_buf
;
3629 if (maxwidth
< sizeof (lots_of_dashes
))
3630 return lots_of_dashes
;
3633 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
3637 return decode_mode_spec_buf
;
3643 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
3645 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
3646 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
3647 decode_mode_spec_buf
[maxwidth
] = '\0';
3648 return decode_mode_spec_buf
;
3655 int col
= current_column ();
3656 XSETFASTINT (w
->column_number_displayed
, col
);
3657 pint2str (decode_mode_spec_buf
, spec_width
, col
);
3658 return decode_mode_spec_buf
;
3662 /* %F displays the frame name. */
3664 return (char *) XSTRING (selected_frame
->name
)->data
;
3674 else if (STRINGP (obj
) && XSTRING (obj
)->size
> maxwidth
)
3676 bcopy ("...", decode_mode_spec_buf
, 3);
3677 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
3678 decode_mode_spec_buf
+ 3, maxwidth
- 3);
3679 return decode_mode_spec_buf
;
3686 int startpos
= marker_position (w
->start
);
3687 int line
, linepos
, topline
;
3690 int height
= XFASTINT (w
->height
);
3692 /* If we decided that this buffer isn't suitable for line numbers,
3693 don't forget that too fast. */
3694 if (EQ (w
->base_line_pos
, w
->buffer
))
3697 /* If the buffer is very big, don't waste time. */
3698 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
3700 w
->base_line_pos
= Qnil
;
3701 w
->base_line_number
= Qnil
;
3705 if (!NILP (w
->base_line_number
)
3706 && !NILP (w
->base_line_pos
)
3707 && XFASTINT (w
->base_line_pos
) <= marker_position (w
->start
))
3709 line
= XFASTINT (w
->base_line_number
);
3710 linepos
= XFASTINT (w
->base_line_pos
);
3715 linepos
= BUF_BEGV (b
);
3718 /* Count lines from base line to window start position. */
3719 nlines
= display_count_lines (linepos
, startpos
, startpos
, &junk
);
3721 topline
= nlines
+ line
;
3723 /* Determine a new base line, if the old one is too close
3724 or too far away, or if we did not have one.
3725 "Too close" means it's plausible a scroll-down would
3727 if (startpos
== BUF_BEGV (b
))
3729 XSETFASTINT (w
->base_line_number
, topline
);
3730 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
3732 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
3733 || linepos
== BUF_BEGV (b
))
3735 int limit
= BUF_BEGV (b
);
3737 int distance
= (height
* 2 + 30) * 200;
3739 if (startpos
- distance
> limit
)
3740 limit
= startpos
- distance
;
3742 nlines
= display_count_lines (startpos
, limit
,
3745 /* If we couldn't find the lines we wanted within
3747 give up on line numbers for this window. */
3748 if (position
== startpos
- distance
)
3750 w
->base_line_pos
= w
->buffer
;
3751 w
->base_line_number
= Qnil
;
3755 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
3756 XSETFASTINT (w
->base_line_pos
, position
);
3759 /* Now count lines from the start pos to point. */
3760 nlines
= display_count_lines (startpos
, PT
, PT
, &junk
);
3762 /* Record that we did display the line number. */
3763 line_number_displayed
= 1;
3765 /* Make the string to show. */
3766 pint2str (decode_mode_spec_buf
, spec_width
, topline
+ nlines
);
3767 return decode_mode_spec_buf
;
3770 char* p
= decode_mode_spec_buf
;
3771 for (spec_width
-= 2; spec_width
> 0; --spec_width
) *p
++ = ' ';
3773 return decode_mode_spec_buf
;
3783 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
3789 int pos
= marker_position (w
->start
);
3790 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
3792 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
3794 if (pos
<= BUF_BEGV (b
))
3799 else if (pos
<= BUF_BEGV (b
))
3803 if (total
> 1000000)
3804 /* Do it differently for a large value, to avoid overflow. */
3805 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
3807 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
3808 /* We can't normally display a 3-digit number,
3809 so get us a 2-digit number that is close. */
3812 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
3813 return decode_mode_spec_buf
;
3817 /* Display percentage of size above the bottom of the screen. */
3820 int toppos
= marker_position (w
->start
);
3821 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
3822 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
3824 if (botpos
>= BUF_ZV (b
))
3826 if (toppos
<= BUF_BEGV (b
))
3833 if (total
> 1000000)
3834 /* Do it differently for a large value, to avoid overflow. */
3835 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
3837 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
3838 /* We can't normally display a 3-digit number,
3839 so get us a 2-digit number that is close. */
3842 if (toppos
<= BUF_BEGV (b
))
3843 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
3845 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
3846 return decode_mode_spec_buf
;
3851 /* status of process */
3852 obj
= Fget_buffer_process (w
->buffer
);
3854 return "no process";
3856 obj
= Fsymbol_name (Fprocess_status (obj
));
3860 case 't': /* indicate TEXT or BINARY */
3861 #ifdef MODE_LINE_BINARY_TEXT
3862 return MODE_LINE_BINARY_TEXT (b
);
3869 return (char *) XSTRING (obj
)->data
;
3874 /* Search for COUNT instances of a line boundary, which means either a
3875 newline or (if selective display enabled) a carriage return.
3876 Start at START. If COUNT is negative, search backwards.
3878 If we find COUNT instances, set *SHORTAGE to zero, and return the
3879 position after the COUNTth match. Note that for reverse motion
3880 this is not the same as the usual convention for Emacs motion commands.
3882 If we don't find COUNT instances before reaching the end of the
3883 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3884 the number of line boundaries left unfound, and return the end of the
3885 buffer we bumped up against. */
3888 display_scan_buffer (start
, count
, shortage
)
3889 int *shortage
, start
;
3892 int limit
= ((count
> 0) ? ZV
- 1 : BEGV
);
3893 int direction
= ((count
> 0) ? 1 : -1);
3895 register unsigned char *cursor
;
3896 unsigned char *base
;
3898 register int ceiling
;
3899 register unsigned char *ceiling_addr
;
3901 /* If we are not in selective display mode,
3902 check only for newlines. */
3903 if (! (!NILP (current_buffer
->selective_display
)
3904 && !INTEGERP (current_buffer
->selective_display
)))
3905 return scan_buffer ('\n', start
, 0, count
, shortage
, 0);
3907 /* The code that follows is like scan_buffer
3908 but checks for either newline or carriage return. */
3914 while (start
!= limit
+ 1)
3916 ceiling
= BUFFER_CEILING_OF (start
);
3917 ceiling
= min (limit
, ceiling
);
3918 ceiling_addr
= &FETCH_CHAR (ceiling
) + 1;
3919 base
= (cursor
= &FETCH_CHAR (start
));
3922 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
3924 if (cursor
!= ceiling_addr
)
3929 return (start
+ cursor
- base
+ 1);
3932 if (++cursor
== ceiling_addr
)
3938 start
+= cursor
- base
;
3942 start
--; /* first character we scan */
3943 while (start
> limit
- 1)
3944 { /* we WILL scan under start */
3945 ceiling
= BUFFER_FLOOR_OF (start
);
3946 ceiling
= max (limit
, ceiling
);
3947 ceiling_addr
= &FETCH_CHAR (ceiling
) - 1;
3948 base
= (cursor
= &FETCH_CHAR (start
));
3952 while (--cursor
!= ceiling_addr
3953 && *cursor
!= '\n' && *cursor
!= 015)
3955 if (cursor
!= ceiling_addr
)
3960 return (start
+ cursor
- base
+ 1);
3966 start
+= cursor
- base
;
3971 *shortage
= count
* direction
;
3972 return (start
+ ((direction
== 1 ? 0 : 1)));
3975 /* Count up to N lines starting from FROM.
3976 But don't go beyond LIMIT.
3977 Return the number of lines thus found (always positive).
3978 Store the position after what was found into *POS_PTR. */
3981 display_count_lines (from
, limit
, n
, pos_ptr
)
3994 *pos_ptr
= display_scan_buffer (from
, n
, &shortage
);
4000 /* When scanning backwards, scan_buffer stops *after* the last newline
4001 it finds, but does count it. Compensate for that. */
4002 return - n
- shortage
- (*pos_ptr
!= limit
);
4003 return n
- shortage
;
4006 /* Display STRING on one line of window W, starting at HPOS.
4007 Display at position VPOS. Caller should have done get_display_line.
4008 If VPOS == -1, display it as the current frame's title.
4009 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4011 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4013 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4014 MAXCOL is the last column ok to end at. Truncate here.
4015 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4016 Both count from the left edge of the frame, as does HPOS.
4017 The right edge of W is an implicit maximum.
4018 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4020 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4021 at the place where the current window ends in this line
4022 and not display anything beyond there. Otherwise, only MAXCOL
4023 controls where to stop output.
4025 Returns ending hpos. */
4028 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
4029 obey_window_width
, mincol
, maxcol
)
4031 unsigned char *string
;
4035 int obey_window_width
;
4041 int hscroll
= XINT (w
->hscroll
);
4042 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
4043 register GLYPH
*start
;
4044 register GLYPH
*end
;
4045 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
4046 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
4047 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
4048 int window_width
= XFASTINT (w
->width
);
4050 /* Use the standard display table, not the window's display table.
4051 We don't want the mode line in rot13. */
4052 register struct Lisp_Char_Table
*dp
= 0;
4055 if (DISP_TABLE_P (Vstandard_display_table
))
4056 dp
= XCHAR_TABLE (Vstandard_display_table
);
4058 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
4061 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
4063 if (obey_window_width
)
4065 end
= start
+ window_width
- (truncate
!= 0);
4067 if ((window_width
+ XFASTINT (w
->left
)) != FRAME_WIDTH (f
))
4069 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4073 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
4081 if (! obey_window_width
4082 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
4083 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
4085 /* Store 0 in charstart for these columns. */
4086 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
4087 desired_glyphs
->charstarts
[vpos
][i
] = 0;
4089 if (maxcol
>= 0 && mincol
> maxcol
)
4092 /* We set truncated to 1 if we get stopped by trying to pass END
4093 (that is, trying to pass MAXCOL.) */
4100 /* Specified length. */
4103 /* Unspecified length (null-terminated string). */
4113 if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
4115 p1
= copy_part_of_rope (f
, p1
, start
,
4116 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
4117 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
4120 else if (c
>= 040 && c
< 0177)
4130 if (p1
>= start
&& p1
< end
)
4134 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
4136 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
4139 *p1
= fix_glyph (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
4140 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
4143 if (p1
>= start
&& p1
< end
)
4150 *p1
= fix_glyph (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
4151 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
4154 if (p1
>= start
&& p1
< end
)
4155 *p1
= (c
>> 6) + '0';
4157 if (p1
>= start
&& p1
< end
)
4158 *p1
= (7 & (c
>> 3)) + '0';
4160 if (p1
>= start
&& p1
< end
)
4161 *p1
= (7 & c
) + '0';
4169 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
4171 else if (mincol
>= 0)
4173 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
4179 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
4181 if (len
> desired_glyphs
->used
[vpos
])
4182 desired_glyphs
->used
[vpos
] = len
;
4183 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
4189 /* This is like a combination of memq and assq.
4190 Return 1 if PROPVAL appears as an element of LIST
4191 or as the car of an element of LIST.
4192 If PROPVAL is a list, compare each element against LIST
4193 in that way, and return 1 if any element of PROPVAL is found in LIST.
4195 This function cannot quit. */
4198 invisible_p (propval
, list
)
4199 register Lisp_Object propval
;
4202 register Lisp_Object tail
, proptail
;
4203 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4205 register Lisp_Object tem
;
4206 tem
= XCONS (tail
)->car
;
4207 if (EQ (propval
, tem
))
4209 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
4212 if (CONSP (propval
))
4213 for (proptail
= propval
; CONSP (proptail
);
4214 proptail
= XCONS (proptail
)->cdr
)
4216 Lisp_Object propelt
;
4217 propelt
= XCONS (proptail
)->car
;
4218 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4220 register Lisp_Object tem
;
4221 tem
= XCONS (tail
)->car
;
4222 if (EQ (propelt
, tem
))
4224 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
4231 /* Return 1 if PROPVAL appears as the car of an element of LIST
4232 and the cdr of that element is non-nil.
4233 If PROPVAL is a list, check each element of PROPVAL in that way,
4234 and the first time some element is found,
4235 return 1 if the cdr of that element is non-nil.
4237 This function cannot quit. */
4240 invisible_ellipsis_p (propval
, list
)
4241 register Lisp_Object propval
;
4244 register Lisp_Object tail
, proptail
;
4245 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4247 register Lisp_Object tem
;
4248 tem
= XCONS (tail
)->car
;
4249 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
4250 return ! NILP (XCONS (tem
)->cdr
);
4252 if (CONSP (propval
))
4253 for (proptail
= propval
; CONSP (proptail
);
4254 proptail
= XCONS (proptail
)->cdr
)
4256 Lisp_Object propelt
;
4257 propelt
= XCONS (proptail
)->car
;
4258 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4260 register Lisp_Object tem
;
4261 tem
= XCONS (tail
)->car
;
4262 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
4263 return ! NILP (XCONS (tem
)->cdr
);
4272 staticpro (&Qmenu_bar_update_hook
);
4273 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
4275 staticpro (&Qoverriding_terminal_local_map
);
4276 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
4278 staticpro (&Qoverriding_local_map
);
4279 Qoverriding_local_map
= intern ("overriding-local-map");
4281 staticpro (&Qwindow_scroll_functions
);
4282 Qwindow_scroll_functions
= intern ("window-scroll-functions");
4284 staticpro (&Qredisplay_end_trigger_functions
);
4285 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
4287 staticpro (&last_arrow_position
);
4288 staticpro (&last_arrow_string
);
4289 last_arrow_position
= Qnil
;
4290 last_arrow_string
= Qnil
;
4292 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
4293 "String (or mode line construct) included (normally) in `mode-line-format'.");
4294 Vglobal_mode_string
= Qnil
;
4296 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
4297 "Marker for where to display an arrow on top of the buffer text.\n\
4298 This must be the beginning of a line in order to work.\n\
4299 See also `overlay-arrow-string'.");
4300 Voverlay_arrow_position
= Qnil
;
4302 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
4303 "String to display as an arrow. See also `overlay-arrow-position'.");
4304 Voverlay_arrow_string
= Qnil
;
4306 DEFVAR_INT ("scroll-step", &scroll_step
,
4307 "*The number of lines to try scrolling a window by when point moves out.\n\
4308 If that fails to bring point back on frame, point is centered instead.\n\
4309 If this is zero, point is always centered after it moves off frame.");
4311 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
4313 DEFVAR_BOOL ("truncate-partial-width-windows",
4314 &truncate_partial_width_windows
,
4315 "*Non-nil means truncate lines in all windows less than full frame wide.");
4316 truncate_partial_width_windows
= 1;
4318 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
4319 "*Non-nil means use inverse video for the mode line.");
4320 mode_line_inverse_video
= 1;
4322 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
4323 "*Maximum buffer size for which line number should be displayed.");
4324 line_number_display_limit
= 1000000;
4326 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
4327 "*Non-nil means highlight region even in nonselected windows.");
4328 highlight_nonselected_windows
= 1;
4330 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
4331 "Non-nil if more than one frame is visible on this display.\n\
4332 Minibuffer-only frames don't count, but iconified frames do.\n\
4333 This variable is not guaranteed to be accurate except while processing\n\
4334 `frame-title-format' and `icon-title-format'.");
4336 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
4337 "Template for displaying the titlebar of visible frames.\n\
4338 \(Assuming the window manager supports this feature.)\n\
4339 This variable has the same structure as `mode-line-format' (which see),\n\
4340 and is used only on frames for which no explicit name has been set\n\
4341 \(see `modify-frame-parameters').");
4342 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
4343 "Template for displaying the titlebar of an iconified frame.\n\
4344 \(Assuming the window manager supports this feature.)\n\
4345 This variable has the same structure as `mode-line-format' (which see),\n\
4346 and is used only on frames for which no explicit name has been set\n\
4347 \(see `modify-frame-parameters').");
4349 = Vframe_title_format
4350 = Fcons (intern ("multiple-frames"),
4351 Fcons (build_string ("%b"),
4352 Fcons (Fcons (build_string (""),
4353 Fcons (intern ("invocation-name"),
4354 Fcons (build_string ("@"),
4355 Fcons (intern ("system-name"),
4359 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
4360 "Maximum number of lines to keep in the message log buffer.\n\
4361 If nil, disable message logging. If t, log messages but don't truncate\n\
4362 the buffer when it becomes large.");
4363 XSETFASTINT (Vmessage_log_max
, 50);
4365 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
4366 "Functions called before redisplay, if window sizes have changed.\n\
4367 The value should be a list of functions that take one argument.\n\
4368 Just before redisplay, for each frame, if any of its windows have changed\n\
4369 size since the last redisplay, or have been split or deleted,\n\
4370 all the functions in the list are called, with the frame as argument.");
4371 Vwindow_size_change_functions
= Qnil
;
4373 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
4374 "List of Functions to call before redisplaying a window with scrolling.\n\
4375 Each function is called with two arguments, the window\n\
4376 and its new display-start position. Note that the value of `window-end'\n\
4377 is not valid when these functions are called.");
4378 Vwindow_scroll_functions
= Qnil
;
4381 /* initialize the window system */
4384 Lisp_Object root_window
;
4385 #ifndef COMPILER_REGISTER_BUG
4387 #endif /* COMPILER_REGISTER_BUG */
4388 struct window
*mini_w
;
4390 this_line_bufpos
= 0;
4392 mini_w
= XWINDOW (minibuf_window
);
4393 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
4395 echo_area_glyphs
= 0;
4396 previous_echo_glyphs
= 0;
4398 if (!noninteractive
)
4400 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
4401 XSETFASTINT (XWINDOW (root_window
)->top
, 0);
4402 set_window_height (root_window
, FRAME_HEIGHT (f
) - 1, 0);
4403 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
4404 set_window_height (minibuf_window
, 1, 0);
4406 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
4407 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));