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 extern void set_frame_menubar ();
42 extern int interrupt_input
;
43 extern int command_loop_level
;
45 extern Lisp_Object Qface
;
47 /* Nonzero means print newline to stdout before next minibuffer message. */
49 int noninteractive_need_newline
;
51 /* Nonzero means print newline to message log before next message. */
53 int message_log_need_newline
;
55 #define min(a, b) ((a) < (b) ? (a) : (b))
56 #define max(a, b) ((a) > (b) ? (a) : (b))
58 /* The buffer position of the first character appearing
59 entirely or partially on the current frame line.
60 Or zero, which disables the optimization for the current frame line. */
61 static int this_line_bufpos
;
63 /* Number of characters past the end of this line,
64 including the terminating newline */
65 static int this_line_endpos
;
67 /* The vertical position of this frame line. */
68 static int this_line_vpos
;
70 /* Hpos value for start of display on this frame line.
71 Usually zero, but negative if first character really began
73 static int this_line_start_hpos
;
75 /* Buffer that this_line variables are describing. */
76 static struct buffer
*this_line_buffer
;
78 /* Set by try_window_id to the vpos of first of any lines
79 scrolled on to the bottom of the frame. These lines should
80 not be included in any general scroll computation. */
81 static int scroll_bottom_vpos
;
83 /* Value of echo_area_glyphs when it was last acted on.
84 If this is nonzero, there is a message on the frame
85 in the minibuffer and it should be erased as soon
86 as it is no longer requested to appear. */
87 char *previous_echo_glyphs
;
89 /* Nonzero means truncate lines in all windows less wide than the frame */
90 int truncate_partial_width_windows
;
92 /* Nonzero means we have more than one non-minibuffer-only frame.
93 Not guaranteed to be accurate except while parsing frame-title-format. */
96 Lisp_Object Vglobal_mode_string
;
98 /* Marker for where to display an arrow on top of the buffer text. */
99 Lisp_Object Voverlay_arrow_position
;
101 /* String to display for the arrow. */
102 Lisp_Object Voverlay_arrow_string
;
104 /* Like mode-line-format, but for the titlebar on a visible frame. */
105 Lisp_Object Vframe_title_format
;
107 /* Like mode-line-format, but for the titlebar on an iconified frame. */
108 Lisp_Object Vicon_title_format
;
110 /* Values of those variables at last redisplay. */
111 static Lisp_Object last_arrow_position
, last_arrow_string
;
113 Lisp_Object Qmenu_bar_update_hook
;
115 /* Nonzero if overlay arrow has been displayed once in this window. */
116 static int overlay_arrow_seen
;
118 /* Nonzero means highlight the region even in nonselected windows. */
119 static int highlight_nonselected_windows
;
121 /* If cursor motion alone moves point off frame,
122 Try scrolling this many lines up or down if that will bring it back. */
125 /* Nonzero if try_window_id has made blank lines at window bottom
126 since the last redisplay that paused */
127 static int blank_end_of_window
;
129 /* Number of windows showing the buffer of the selected window
130 (or another buffer with the same base buffer).
131 keyboard.c refers to this. */
134 /* display_text_line sets these to the frame position (origin 0) of point,
135 whether the window is selected or not.
136 Set one to -1 first to determine whether point was found afterwards. */
138 static int cursor_vpos
;
139 static int cursor_hpos
;
143 /* Nonzero means display mode line highlighted */
144 int mode_line_inverse_video
;
146 static void echo_area_display ();
147 void mark_window_display_accurate ();
148 static void redisplay_windows ();
149 static void redisplay_window ();
150 static void update_menu_bars ();
151 static void update_menu_bar ();
152 static void try_window ();
153 static int try_window_id ();
154 static struct position
*display_text_line ();
155 static void display_mode_line ();
156 static int display_mode_element ();
157 static char *fmodetrunc ();
158 static char *decode_mode_spec ();
159 static int display_string ();
160 static void display_menu_bar ();
161 static int display_count_lines ();
163 /* Prompt to display in front of the minibuffer contents */
164 Lisp_Object minibuf_prompt
;
166 /* Width in columns of current minibuffer prompt. */
167 int minibuf_prompt_width
;
169 /* Message to display instead of minibuffer contents
170 This is what the functions error and message make,
171 and command echoing uses it as well.
172 It overrides the minibuf_prompt as well as the buffer. */
173 char *echo_area_glyphs
;
175 /* This is the length of the message in echo_area_glyphs. */
176 int echo_area_glyphs_length
;
178 /* true iff we should redraw the mode lines on the next redisplay */
179 int update_mode_lines
;
181 /* Smallest number of characters before the gap
182 at any time since last redisplay that finished.
183 Valid for current buffer when try_window_id can be called. */
186 /* Smallest number of characters after the gap
187 at any time since last redisplay that finished.
188 Valid for current buffer when try_window_id can be called. */
191 /* MODIFF as of last redisplay that finished;
192 if it matches MODIFF, beg_unchanged and end_unchanged
193 contain no useful information */
194 int unchanged_modified
;
196 /* Nonzero if head_clip or tail_clip of current buffer has changed
197 since last redisplay that finished */
200 /* Nonzero if window sizes or contents have changed
201 since last redisplay that finished */
202 int windows_or_buffers_changed
;
204 /* Nonzero after display_mode_line if %l was used
205 and it displayed a line number. */
206 int line_number_displayed
;
208 /* Maximum buffer size for which to display line numbers. */
209 int line_number_display_limit
;
211 /* Number of lines to keep in the message log buffer.
212 t means infinite. nil means don't log at all. */
213 Lisp_Object Vmessage_log_max
;
215 /* Add a string to the message log, optionally terminated with a newline.
216 This function calls low-level routines in order to bypass text property
217 hooks, etc. which might not be safe to run. */
220 message_dolog (m
, len
, nlflag
)
224 if (!NILP (Vmessage_log_max
))
226 struct buffer
*oldbuf
;
227 int oldpoint
, oldbegv
, oldzv
;
229 oldbuf
= current_buffer
;
230 Fset_buffer (Fget_buffer_create (build_string (" *Messages*")));
237 oldpoint
+= len
+ nlflag
;
239 oldzv
+= len
+ nlflag
;
242 insert_1 (m
, len
, 1, 0);
244 insert_1 ("\n", 1, 1, 0);
245 if (NATNUMP (Vmessage_log_max
))
247 int pos
= scan_buffer ('\n', PT
, 0,
248 -XFASTINT (Vmessage_log_max
) - 1, 0, 1);
249 oldpoint
-= min (pos
, oldpoint
) - BEG
;
250 oldbegv
-= min (pos
, oldbegv
) - BEG
;
251 oldzv
-= min (pos
, oldzv
) - BEG
;
252 del_range_1 (BEG
, pos
, 0);
256 TEMP_SET_PT (oldpoint
);
257 set_buffer_internal (oldbuf
);
262 /* Display an echo area message M with a specified length of LEN chars.
263 The string may include null characters. If m is 0, clear out any
264 existing message, and let the minibuffer text show through.
265 Do not pass text that is stored in a Lisp string. */
272 /* First flush out any partial line written with print. */
273 if (message_log_need_newline
)
274 message_dolog ("", 0, 1);
275 message_log_need_newline
= 0;
277 message_dolog (m
, len
, 1);
278 message2_nolog (m
, len
);
282 /* The non-logging part of that function. */
285 message2_nolog (m
, len
)
291 if (noninteractive_need_newline
)
293 noninteractive_need_newline
= 0;
294 fwrite (m
, len
, 1, stderr
);
295 if (cursor_in_echo_area
== 0)
296 fprintf (stderr
, "\n");
299 /* A null message buffer means that the frame hasn't really been
300 initialized yet. Error messages get reported properly by
301 cmd_error, so this must be just an informative message; toss it. */
302 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
305 Lisp_Object minibuf_frame
;
307 choose_minibuf_frame ();
308 minibuf_frame
= WINDOW_FRAME (XWINDOW (minibuf_window
));
309 FRAME_SAMPLE_VISIBILITY (XFRAME (minibuf_frame
));
310 if (FRAME_VISIBLE_P (selected_frame
)
311 && ! FRAME_VISIBLE_P (XFRAME (minibuf_frame
)))
312 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (minibuf_window
)));
317 echo_area_glyphs
= m
;
318 echo_area_glyphs_length
= len
;
321 echo_area_glyphs
= previous_echo_glyphs
= 0;
323 do_pending_window_change ();
324 echo_area_display ();
325 update_frame (XFRAME (XWINDOW (minibuf_window
)->frame
), 1, 1);
326 do_pending_window_change ();
327 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
328 (*frame_up_to_date_hook
) (XFRAME (XWINDOW (minibuf_window
)->frame
));
336 message2 (m
, (m
? strlen (m
) : 0));
343 message2_nolog (m
, (m
? strlen (m
) : 0));
346 /* Truncate what will be displayed in the echo area
347 the next time we display it--but don't redisplay it now. */
350 truncate_echo_area (len
)
353 /* A null message buffer means that the frame hasn't really been
354 initialized yet. Error messages get reported properly by
355 cmd_error, so this must be just an informative message; toss it. */
356 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
357 echo_area_glyphs_length
= len
;
360 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
361 zero if being used by message. */
362 int message_buf_print
;
364 /* Dump an informative message to the minibuf. If m is 0, clear out
365 any existing message, and let the minibuffer text show through. */
368 message (m
, a1
, a2
, a3
)
370 EMACS_INT a1
, a2
, a3
;
376 if (noninteractive_need_newline
)
378 noninteractive_need_newline
= 0;
379 fprintf (stderr
, m
, a1
, a2
, a3
);
380 if (cursor_in_echo_area
== 0)
381 fprintf (stderr
, "\n");
385 else if (INTERACTIVE
)
387 /* The frame whose minibuffer we're going to display the message on.
388 It may be larger than the selected frame, so we need
389 to use its buffer, not the selected frame's buffer. */
390 FRAME_PTR echo_frame
;
392 choose_minibuf_frame ();
393 echo_frame
= XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)));
395 echo_frame
= selected_frame
;
398 /* A null message buffer means that the frame hasn't really been
399 initialized yet. Error messages get reported properly by
400 cmd_error, so this must be just an informative message; toss it. */
401 if (FRAME_MESSAGE_BUF (echo_frame
))
412 len
= doprnt (FRAME_MESSAGE_BUF (echo_frame
),
413 FRAME_WIDTH (echo_frame
), m
, 0, 3, a
);
415 len
= doprnt (FRAME_MESSAGE_BUF (echo_frame
),
416 FRAME_WIDTH (echo_frame
), m
, 0, 3, &a1
);
417 #endif /* NO_ARG_ARRAY */
419 message2 (FRAME_MESSAGE_BUF (echo_frame
), len
);
424 /* Print should start at the beginning of the message
426 message_buf_print
= 0;
434 message2 (echo_area_glyphs
, echo_area_glyphs_length
);
444 choose_minibuf_frame ();
447 f
= XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)));
449 if (! FRAME_VISIBLE_P (f
))
454 redraw_garbaged_frames ();
458 if (echo_area_glyphs
|| minibuf_level
== 0)
460 vpos
= XFASTINT (XWINDOW (minibuf_window
)->top
);
461 get_display_line (f
, vpos
, 0);
462 display_string (XWINDOW (minibuf_window
), vpos
,
463 echo_area_glyphs
? echo_area_glyphs
: "",
464 echo_area_glyphs
? echo_area_glyphs_length
: -1,
465 0, 0, 0, 0, FRAME_WIDTH (f
));
467 /* If desired cursor location is on this line, put it at end of text */
468 if (FRAME_CURSOR_Y (f
) == vpos
)
469 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
471 /* Fill the rest of the minibuffer window with blank lines. */
476 i
< vpos
+ XFASTINT (XWINDOW (minibuf_window
)->height
); i
++)
478 get_display_line (f
, i
, 0);
479 display_string (XWINDOW (minibuf_window
), vpos
,
480 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f
));
484 else if (!EQ (minibuf_window
, selected_window
))
485 windows_or_buffers_changed
++;
487 if (EQ (minibuf_window
, selected_window
))
488 this_line_bufpos
= 0;
490 previous_echo_glyphs
= echo_area_glyphs
;
493 #ifdef HAVE_X_WINDOWS
494 static char frame_title_buf
[512];
495 static char *frame_title_ptr
;
498 store_frame_title (str
, mincol
, maxcol
)
503 if (maxcol
< 0 || maxcol
>= sizeof(frame_title_buf
))
504 maxcol
= sizeof (frame_title_buf
);
505 limit
= &frame_title_buf
[maxcol
];
506 while (*str
!= '\0' && frame_title_ptr
< limit
)
507 *frame_title_ptr
++ = *str
++;
508 while (frame_title_ptr
< &frame_title_buf
[mincol
])
509 *frame_title_ptr
++ = ' ';
510 return frame_title_ptr
- frame_title_buf
;
514 x_consider_frame_title (frame
)
520 FRAME_PTR f
= XFRAME (frame
);
522 if (!FRAME_X_P (f
) || FRAME_MINIBUF_ONLY_P (f
) || f
->explicit_name
)
524 multiple_frames
= !EQ (Fnext_frame (frame
, Qnil
), frame
);
525 obuf
= current_buffer
;
526 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
527 fmt
= (FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
);
528 frame_title_ptr
= frame_title_buf
;
529 len
= display_mode_element (XWINDOW (f
->selected_window
), 0, 0, 0,
530 0, sizeof (frame_title_buf
), fmt
);
532 set_buffer_internal (obuf
);
533 /* Set the name only if it's changed. This avoids consing
534 in the common case where it hasn't. (If it turns out that we've
535 already wasted too much time by walking through the list with
536 display_mode_element, then we might need to optimize at a higher
538 if (! STRINGP (f
->name
) || XSTRING (f
->name
)->size
!= len
539 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
540 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
543 #define frame_title_ptr ((char *)0)
544 #define store_frame_title(str, mincol, maxcol) 0
547 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
548 This can't be done in `redisplay' itself because it can call eval. */
553 register struct window
*w
= XWINDOW (selected_window
);
559 /* Set the visible flags for all frames.
560 Do this before checking for resized or garbaged frames; they want
561 to know if their frames are visible.
562 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
564 Lisp_Object tail
, frame
;
566 FOR_EACH_FRAME (tail
, frame
)
567 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
570 /* Notice any pending interrupt request to change frame size. */
571 do_pending_window_change ();
575 redraw_garbaged_frames ();
579 all_windows
= (update_mode_lines
|| buffer_shared
> 1
580 || clip_changed
|| windows_or_buffers_changed
);
582 #ifdef HAVE_X_WINDOWS
583 if (windows_or_buffers_changed
)
585 Lisp_Object tail
, frame
;
587 FOR_EACH_FRAME (tail
, frame
)
588 if (FRAME_VISIBLE_P (XFRAME (frame
))
589 || FRAME_ICONIFIED_P (XFRAME (frame
)))
590 x_consider_frame_title (frame
);
594 /* Update the menu bar item lists, if appropriate.
595 This has to be done before any actual redisplay
596 or generation of display lines. */
599 Lisp_Object tail
, frame
;
601 FOR_EACH_FRAME (tail
, frame
)
602 update_menu_bar (XFRAME (frame
));
605 update_menu_bar (selected_frame
);
608 /* Do a frame update, taking possible shortcuts into account.
609 This is the main external entry point for redisplay.
611 If the last redisplay displayed an echo area message and that
612 message is no longer requested, we clear the echo area
613 or bring back the minibuffer if that is in use.
615 Do not call eval from within this function.
616 Calls to eval after the call to echo_area_display would confuse
617 the display_line mechanism and would cause a crash.
618 Calls to eval before that point will work most of the time,
619 but can still lose, because this function
620 can be called from signal handlers; with alarms set up;
621 or with synchronous processes running.
623 See Fcall_process; if you called it from here, it could be
624 entered recursively. */
626 static int do_verify_charstarts
;
628 /* Counter is used to clear the face cache
629 no more than once ever 1000 redisplays. */
630 static int clear_face_cache_count
;
635 register struct window
*w
= XWINDOW (selected_window
);
639 register int tlbufpos
, tlendpos
;
641 extern int input_pending
;
646 /* Set the visible flags for all frames.
647 Do this before checking for resized or garbaged frames; they want
648 to know if their frames are visible.
649 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
651 Lisp_Object tail
, frame
;
653 FOR_EACH_FRAME (tail
, frame
)
654 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
657 /* Notice any pending interrupt request to change frame size. */
658 do_pending_window_change ();
662 redraw_garbaged_frames ();
666 if (clip_changed
|| windows_or_buffers_changed
667 || (!NILP (w
->column_number_displayed
)
668 && XFASTINT (w
->column_number_displayed
) != current_column ()))
671 /* Detect case that we need to write a star in the mode line. */
672 if (XFASTINT (w
->last_modified
) < MODIFF
673 && XFASTINT (w
->last_modified
) <= SAVE_MODIFF
)
675 w
->update_mode_line
= Qt
;
676 if (buffer_shared
> 1)
680 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
682 all_windows
= update_mode_lines
|| buffer_shared
> 1;
684 /* If specs for an arrow have changed, do thorough redisplay
685 to ensure we remove any arrow that should no longer exist. */
686 if (! EQ (Voverlay_arrow_position
, last_arrow_position
)
687 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
688 all_windows
= 1, clip_changed
= 1;
690 /* Normally the message* functions will have already displayed and
691 updated the echo area, but the frame may have been trashed, or
692 the update may have been preempted, so display the echo area
694 if (echo_area_glyphs
|| previous_echo_glyphs
)
696 echo_area_display ();
700 /* If showing region, and mark has changed, must redisplay whole window. */
701 if (((!NILP (Vtransient_mark_mode
)
702 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
703 != !NILP (w
->region_showing
))
704 || (!NILP (w
->region_showing
)
705 && !EQ (w
->region_showing
,
706 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
707 this_line_bufpos
= -1;
709 tlbufpos
= this_line_bufpos
;
710 tlendpos
= this_line_endpos
;
711 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
712 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
713 /* Make sure recorded data applies to current buffer, etc */
714 && this_line_buffer
== current_buffer
715 && current_buffer
== XBUFFER (w
->buffer
)
716 && NILP (w
->force_start
)
717 /* Point must be on the line that we have info recorded about */
719 && PT
<= Z
- tlendpos
720 /* All text outside that line, including its final newline,
722 && (XFASTINT (w
->last_modified
) >= MODIFF
723 || (beg_unchanged
>= tlbufpos
- 1
725 /* If selective display, can't optimize
726 if the changes start at the beginning of the line. */
727 && ((INTEGERP (current_buffer
->selective_display
)
728 && XINT (current_buffer
->selective_display
) > 0
729 ? (beg_unchanged
>= tlbufpos
732 && end_unchanged
>= tlendpos
733 && Z
- GPT
>= tlendpos
)))
735 if (tlbufpos
> BEGV
&& FETCH_CHAR (tlbufpos
- 1) != '\n'
737 || FETCH_CHAR (tlbufpos
) == '\n'))
738 /* Former continuation line has disappeared by becoming empty */
740 else if (XFASTINT (w
->last_modified
) < MODIFF
741 || MINI_WINDOW_P (w
))
744 overlay_arrow_seen
= 0;
745 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
746 pos_tab_offset (w
, tlbufpos
));
747 /* If line contains point, is not continued,
748 and ends at same distance from eob as before, we win */
749 if (cursor_vpos
>= 0 && this_line_bufpos
750 && this_line_endpos
== tlendpos
)
752 /* If this is not the window's last line,
753 we must adjust the charstarts of the lines below. */
754 if (this_line_vpos
+ 1
755 < XFASTINT (w
->top
) + window_internal_height (w
))
757 int left
= XFASTINT (w
->left
);
758 int *charstart_next_line
759 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w
)))->charstarts
[this_line_vpos
+ 1];
763 if (Z
- tlendpos
== ZV
)
764 /* This line ends at end of (accessible part of) buffer.
765 There is no newline to count. */
766 adjust
= Z
- tlendpos
- charstart_next_line
[left
];
768 /* This line ends in a newline.
769 Must take account of the newline and the rest of the
770 text that follows. */
771 adjust
= Z
- tlendpos
+ 1 - charstart_next_line
[left
];
773 adjust_window_charstarts (w
, this_line_vpos
, adjust
);
776 if (XFASTINT (w
->width
) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w
))))
777 preserve_other_columns (w
);
783 else if (PT
== XFASTINT (w
->last_point
))
787 do_pending_window_change ();
792 /* If highlighting the region, we can't just move the cursor. */
793 else if (! (!NILP (Vtransient_mark_mode
)
794 && !NILP (current_buffer
->mark_active
))
795 && NILP (w
->region_showing
))
797 pos
= *compute_motion (tlbufpos
, 0,
798 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
799 PT
, 2, - (1 << (SHORTBITS
- 1)),
800 window_internal_width (w
) - 1,
802 pos_tab_offset (w
, tlbufpos
), w
);
805 FRAME_CURSOR_X (selected_frame
)
806 = XFASTINT (w
->left
) + max (pos
.hpos
, 0);
807 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
814 /* Text changed drastically or point moved off of line */
815 cancel_line (this_line_vpos
, selected_frame
);
818 this_line_bufpos
= 0;
819 all_windows
|= buffer_shared
> 1;
821 clear_face_cache_count
++;
825 Lisp_Object tail
, frame
;
828 /* Clear the face cache, only when we do a full redisplay
829 and not too often either. */
830 if (clear_face_cache_count
> 1000)
833 clear_face_cache_count
= 0;
837 /* Recompute # windows showing selected buffer.
838 This will be incremented each time such a window is displayed. */
841 FOR_EACH_FRAME (tail
, frame
)
843 FRAME_PTR f
= XFRAME (frame
);
845 /* Mark all the scroll bars to be removed; we'll redeem the ones
846 we want when we redisplay their windows. */
847 if (condemn_scroll_bars_hook
)
848 (*condemn_scroll_bars_hook
) (f
);
850 if (FRAME_VISIBLE_P (f
))
851 redisplay_windows (FRAME_ROOT_WINDOW (f
));
853 /* Any scroll bars which redisplay_windows should have nuked
854 should now go away. */
855 if (judge_scroll_bars_hook
)
856 (*judge_scroll_bars_hook
) (f
);
859 else if (FRAME_VISIBLE_P (selected_frame
))
861 redisplay_window (selected_window
, 1);
862 if (XFASTINT (w
->width
) != FRAME_WIDTH (selected_frame
))
863 preserve_other_columns (w
);
867 /* Prevent various kinds of signals during display update.
868 stdio is not robust about handling signals,
869 which can cause an apparent I/O error. */
881 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
885 if (!FRAMEP (XCONS (tail
)->car
))
888 f
= XFRAME (XCONS (tail
)->car
);
889 if (FRAME_VISIBLE_P (f
))
891 pause
|= update_frame (f
, 0, 0);
894 mark_window_display_accurate (f
->root_window
, 1);
895 if (frame_up_to_date_hook
!= 0)
896 (*frame_up_to_date_hook
) (f
);
902 #endif /* MULTI_FRAME */
904 if (FRAME_VISIBLE_P (selected_frame
))
905 pause
= update_frame (selected_frame
, 0, 0);
907 /* We may have called echo_area_display at the top of this
908 function. If the echo area is on another frame, that may
909 have put text on a frame other than the selected one, so the
910 above call to update_frame would not have caught it. Catch
914 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)));
916 if (mini_frame
!= selected_frame
)
917 pause
|= update_frame (mini_frame
, 0, 0);
921 /* If frame does not match, prevent doing single-line-update next time.
922 Also, don't forget to check every line to update the arrow. */
925 this_line_bufpos
= 0;
926 if (!NILP (last_arrow_position
))
928 last_arrow_position
= Qt
;
929 last_arrow_string
= Qt
;
931 /* If we pause after scrolling, some lines in current_frame
932 may be null, so preserve_other_columns won't be able to
933 preserve all the vertical-bar separators. So, avoid using it
935 if (XFASTINT (w
->width
) != FRAME_WIDTH (selected_frame
))
936 update_mode_lines
= 1;
939 /* Now text on frame agrees with windows, so
940 put info into the windows for partial redisplay to follow */
944 register struct buffer
*b
= XBUFFER (w
->buffer
);
946 blank_end_of_window
= 0;
948 unchanged_modified
= BUF_MODIFF (b
);
949 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
950 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
952 XSETFASTINT (w
->last_point
, BUF_PT (b
));
953 XSETFASTINT (w
->last_point_x
, FRAME_CURSOR_X (selected_frame
));
954 XSETFASTINT (w
->last_point_y
, FRAME_CURSOR_Y (selected_frame
));
957 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
960 w
->update_mode_line
= Qnil
;
961 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
962 w
->window_end_valid
= w
->buffer
;
963 last_arrow_position
= Voverlay_arrow_position
;
964 last_arrow_string
= Voverlay_arrow_string
;
965 if (do_verify_charstarts
)
966 verify_charstarts (w
);
967 if (frame_up_to_date_hook
!= 0)
968 (*frame_up_to_date_hook
) (selected_frame
);
970 update_mode_lines
= 0;
971 windows_or_buffers_changed
= 0;
974 /* Start SIGIO interrupts coming again.
975 Having them off during the code above
976 makes it less likely one will discard output,
977 but not impossible, since there might be stuff
978 in the system buffer here.
979 But it is much hairier to try to do anything about that. */
985 /* Change frame size now if a change is pending. */
986 do_pending_window_change ();
988 /* If we just did a pending size change, redisplay again
990 if (windows_or_buffers_changed
&& !pause
)
994 /* Redisplay, but leave alone any recent echo area message
995 unless another message has been requested in its place.
997 This is useful in situations where you need to redisplay but no
998 user action has occurred, making it inappropriate for the message
999 area to be cleared. See tracking_off and
1000 wait_reading_process_input for examples of these situations. */
1002 redisplay_preserve_echo_area ()
1004 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
1006 echo_area_glyphs
= previous_echo_glyphs
;
1008 echo_area_glyphs
= 0;
1015 mark_window_display_accurate (window
, flag
)
1019 register struct window
*w
;
1021 for (;!NILP (window
); window
= w
->next
)
1023 if (!WINDOWP (window
)) abort ();
1024 w
= XWINDOW (window
);
1026 if (!NILP (w
->buffer
))
1028 XSETFASTINT (w
->last_modified
,
1029 !flag
? 0 : BUF_MODIFF (XBUFFER (w
->buffer
)));
1031 /* Record if we are showing a region, so can make sure to
1032 update it fully at next redisplay. */
1033 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
1034 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
1035 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
1039 w
->window_end_valid
= w
->buffer
;
1040 w
->update_mode_line
= Qnil
;
1042 if (!NILP (w
->vchild
))
1043 mark_window_display_accurate (w
->vchild
, flag
);
1044 if (!NILP (w
->hchild
))
1045 mark_window_display_accurate (w
->hchild
, flag
);
1050 last_arrow_position
= Voverlay_arrow_position
;
1051 last_arrow_string
= Voverlay_arrow_string
;
1055 /* t is unequal to any useful value of Voverlay_arrow_... */
1056 last_arrow_position
= Qt
;
1057 last_arrow_string
= Qt
;
1061 /* Update the menu bar item list for frame F.
1062 This has to be done before we start to fill in any display lines,
1063 because it can call eval. */
1069 struct buffer
*old
= current_buffer
;
1071 register struct window
*w
;
1072 window
= FRAME_SELECTED_WINDOW (f
);
1073 w
= XWINDOW (window
);
1075 if (update_mode_lines
)
1076 w
->update_mode_line
= Qt
;
1079 #ifdef USE_X_TOOLKIT
1080 FRAME_EXTERNAL_MENU_BAR (f
)
1082 FRAME_MENU_BAR_LINES (f
) > 0
1086 /* If the user has switched buffers or windows, we need to
1087 recompute to reflect the new bindings. But we'll
1088 recompute when update_mode_lines is set too; that means
1089 that people can use force-mode-line-update to request
1090 that the menu bar be recomputed. The adverse effect on
1091 the rest of the redisplay algorithm is about the same as
1092 windows_or_buffers_changed anyway. */
1093 if (windows_or_buffers_changed
1094 || !NILP (w
->update_mode_line
)
1095 || (XFASTINT (w
->last_modified
) < MODIFF
1096 && (XFASTINT (w
->last_modified
)
1097 <= BUF_SAVE_MODIFF (XBUFFER (w
->buffer
)))))
1099 struct buffer
*prev
= current_buffer
;
1100 call1 (Vrun_hooks
, Qmenu_bar_update_hook
);
1101 current_buffer
= XBUFFER (w
->buffer
);
1102 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1103 current_buffer
= prev
;
1104 #ifdef USE_X_TOOLKIT
1105 set_frame_menubar (f
, 0);
1106 #endif /* USE_X_TOOLKIT */
1113 /* Redisplay WINDOW and its subwindows and siblings. */
1116 redisplay_windows (window
)
1119 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
1120 redisplay_window (window
, 0);
1123 /* Redisplay window WINDOW and its subwindows. */
1126 redisplay_window (window
, just_this_one
)
1130 register struct window
*w
= XWINDOW (window
);
1131 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1133 register int lpoint
= PT
;
1134 struct buffer
*old
= current_buffer
;
1135 register int width
= window_internal_width (w
) - 1;
1136 register int startp
;
1137 register int hscroll
= XINT (w
->hscroll
);
1138 struct position pos
;
1141 int window_needs_modeline
;
1143 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
1145 /* If this is a combination window, do its children; that's all. */
1147 if (!NILP (w
->vchild
))
1149 redisplay_windows (w
->vchild
);
1152 if (!NILP (w
->hchild
))
1154 redisplay_windows (w
->hchild
);
1157 if (NILP (w
->buffer
))
1160 height
= window_internal_height (w
);
1162 if (MINI_WINDOW_P (w
))
1164 if (w
== XWINDOW (minibuf_window
))
1166 if (echo_area_glyphs
)
1167 /* We've already displayed the echo area glyphs, if any. */
1168 goto finish_scroll_bars
;
1172 /* This is a minibuffer, but it's not the currently active one, so
1174 int vpos
= XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f
))->top
);
1177 for (i
= 0; i
< height
; i
++)
1179 get_display_line (f
, vpos
+ i
, 0);
1180 display_string (w
, vpos
+ i
, "", 0, 0, 0, 1, 0, width
);
1183 goto finish_scroll_bars
;
1187 if (update_mode_lines
)
1188 w
->update_mode_line
= Qt
;
1190 /* Otherwise set up data on this window; select its buffer and point value */
1192 set_buffer_temp (XBUFFER (w
->buffer
));
1195 /* Count number of windows showing the selected buffer.
1196 An indirect buffer counts as its base buffer. */
1200 struct buffer
*current_base
, *window_base
;
1201 current_base
= current_buffer
;
1202 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1203 if (current_base
->base_buffer
)
1204 current_base
= current_base
->base_buffer
;
1205 if (window_base
->base_buffer
)
1206 window_base
= window_base
->base_buffer
;
1207 if (current_base
== window_base
)
1211 /* POINT refers normally to the selected window.
1212 For any other window, set up appropriate value. */
1214 if (!EQ (window
, selected_window
))
1216 int new_pt
= marker_position (w
->pointm
);
1220 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1222 else if (new_pt
> (ZV
- 1))
1225 Fset_marker (w
->pointm
, make_number (new_pt
), Qnil
);
1227 /* We don't use SET_PT so that the point-motion hooks don't run. */
1228 BUF_PT (current_buffer
) = new_pt
;
1231 /* If any of the character widths specified in the display table
1232 have changed, invalidate the width run cache. It's true that this
1233 may be a bit late to catch such changes, but the rest of
1234 redisplay goes (non-fatally) haywire when the display table is
1235 changed, so why should we worry about doing any better? */
1236 if (current_buffer
->width_run_cache
)
1238 struct Lisp_Vector
*disptab
= buffer_display_table ();
1240 if (! disptab_matches_widthtab (disptab
,
1241 XVECTOR (current_buffer
->width_table
)))
1243 invalidate_region_cache (current_buffer
,
1244 current_buffer
->width_run_cache
,
1246 recompute_width_table (current_buffer
, disptab
);
1250 /* If window-start is screwed up, choose a new one. */
1251 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
1254 startp
= marker_position (w
->start
);
1256 /* Handle case where place to start displaying has been specified,
1257 unless the specified location is outside the accessible range. */
1258 if (!NILP (w
->force_start
))
1260 /* Forget any recorded base line for line number display. */
1261 w
->base_line_number
= Qnil
;
1262 w
->update_mode_line
= Qt
;
1263 w
->force_start
= Qnil
;
1264 XSETFASTINT (w
->last_modified
, 0);
1265 if (startp
< BEGV
) startp
= BEGV
;
1266 if (startp
> ZV
) startp
= ZV
;
1267 try_window (window
, startp
);
1268 if (cursor_vpos
< 0)
1270 /* If point does not appear, move point so it does appear */
1271 pos
= *compute_motion (startp
, 0,
1272 ((EQ (window
, minibuf_window
) && startp
== 1)
1273 ? minibuf_prompt_width
: 0)
1275 (hscroll
? 1 - hscroll
: 0),
1277 - (1 << (SHORTBITS
- 1)),
1278 width
, hscroll
, pos_tab_offset (w
, startp
), w
);
1279 BUF_PT (current_buffer
) = pos
.bufpos
;
1280 if (w
!= XWINDOW (selected_window
))
1281 Fset_marker (w
->pointm
, make_number (PT
), Qnil
);
1284 if (current_buffer
== old
)
1286 FRAME_CURSOR_X (f
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
1287 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1289 /* If we are highlighting the region,
1290 then we just changed the region, so redisplay to show it. */
1291 if (!NILP (Vtransient_mark_mode
)
1292 && !NILP (current_buffer
->mark_active
))
1294 cancel_my_columns (XWINDOW (window
));
1295 try_window (window
, startp
);
1301 /* Handle case where text has not changed, only point,
1302 and it has not moved off the frame */
1304 /* This code is not used for minibuffer for the sake of
1305 the case of redisplaying to replace an echo area message;
1306 since in that case the minibuffer contents per se are usually unchanged.
1307 This code is of no real use in the minibuffer since
1308 the handling of this_line_bufpos, etc.,
1309 in redisplay handles the same cases. */
1311 if (XFASTINT (w
->last_modified
) >= MODIFF
1312 && PT
>= startp
&& !clip_changed
1313 && (just_this_one
|| XFASTINT (w
->width
) == FRAME_WIDTH (f
))
1314 /* Can't use this case if highlighting a region. */
1315 && !(!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
1316 && NILP (w
->region_showing
)
1317 /* If end pos is out of date, scroll bar and percentage will be wrong */
1318 && INTEGERP (w
->window_end_vpos
)
1319 && XFASTINT (w
->window_end_vpos
) < XFASTINT (w
->height
)
1320 && !EQ (window
, minibuf_window
))
1322 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0),
1323 PT
, height
+ 1, 10000, width
, hscroll
,
1324 pos_tab_offset (w
, startp
), w
);
1326 if (pos
.vpos
< height
)
1328 /* Ok, point is still on frame */
1329 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
1331 /* These variables are supposed to be origin 1 */
1332 FRAME_CURSOR_X (f
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
1333 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
1335 /* This doesn't do the trick, because if a window to the right of
1336 this one must be redisplayed, this does nothing because there
1337 is nothing in DesiredFrame yet, and then the other window is
1338 redisplayed, making likes that are empty in this window's columns.
1339 if (XFASTINT (w->width) != FRAME_WIDTH (f))
1340 preserve_my_columns (w);
1344 /* Don't bother trying redisplay with same start;
1345 we already know it will lose */
1347 /* If current starting point was originally the beginning of a line
1348 but no longer is, find a new starting point. */
1349 else if (!NILP (w
->start_at_line_beg
)
1351 || FETCH_CHAR (startp
- 1) == '\n'))
1355 else if (just_this_one
&& !MINI_WINDOW_P (w
)
1357 && XFASTINT (w
->last_modified
)
1358 /* or else vmotion on first line won't work. */
1359 && ! NILP (w
->start_at_line_beg
)
1360 && ! EQ (w
->window_end_valid
, Qnil
)
1361 && do_id
&& !clip_changed
1362 && !blank_end_of_window
1363 && XFASTINT (w
->width
) == FRAME_WIDTH (f
)
1364 /* Can't use this case if highlighting a region. */
1365 && !(!NILP (Vtransient_mark_mode
)
1366 && !NILP (current_buffer
->mark_active
))
1367 && NILP (w
->region_showing
)
1368 && EQ (last_arrow_position
, Voverlay_arrow_position
)
1369 && EQ (last_arrow_string
, Voverlay_arrow_string
)
1370 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
1373 /* tem > 0 means success. tem == -1 means choose new start.
1374 tem == -2 means try again with same start,
1375 and nothing but whitespace follows the changed stuff.
1376 tem == 0 means try again with same start. */
1380 else if (startp
>= BEGV
&& startp
<= ZV
1381 /* Avoid starting display at end of buffer! */
1382 && (startp
< ZV
|| startp
== BEGV
1383 || (XFASTINT (w
->last_modified
) >= MODIFF
)))
1385 /* Try to redisplay starting at same place as before */
1386 /* If point has not moved off frame, accept the results */
1387 try_window (window
, startp
);
1388 if (cursor_vpos
>= 0)
1390 if (!just_this_one
|| clip_changed
|| beg_unchanged
< startp
)
1391 /* Forget any recorded base line for line number display. */
1392 w
->base_line_number
= Qnil
;
1396 cancel_my_columns (w
);
1399 XSETFASTINT (w
->last_modified
, 0);
1400 w
->update_mode_line
= Qt
;
1402 /* Try to scroll by specified few lines */
1404 if (scroll_step
&& !clip_changed
)
1408 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
1409 scroll_step
, width
, hscroll
, window
);
1410 if (pos
.vpos
>= height
)
1414 pos
= *vmotion (startp
, PT
< startp
? - scroll_step
: scroll_step
,
1415 width
, hscroll
, window
);
1417 if (PT
>= pos
.bufpos
)
1419 try_window (window
, pos
.bufpos
);
1420 if (cursor_vpos
>= 0)
1422 if (!just_this_one
|| clip_changed
|| beg_unchanged
< startp
)
1423 /* Forget any recorded base line for line number display. */
1424 w
->base_line_number
= Qnil
;
1428 cancel_my_columns (w
);
1433 /* Finally, just choose place to start which centers point */
1436 /* Forget any previously recorded base line for line number display. */
1437 w
->base_line_number
= Qnil
;
1439 pos
= *vmotion (PT
, - (height
/ 2), width
, hscroll
, window
);
1440 try_window (window
, pos
.bufpos
);
1442 startp
= marker_position (w
->start
);
1443 w
->start_at_line_beg
1444 = (startp
== BEGV
|| FETCH_CHAR (startp
- 1) == '\n') ? Qt
: Qnil
;
1447 if ((!NILP (w
->update_mode_line
)
1448 /* If window not full width, must redo its mode line
1449 if the window to its side is being redone */
1450 || (!just_this_one
&& width
< FRAME_WIDTH (f
) - 1)
1451 || INTEGERP (w
->base_line_pos
)
1452 || (!NILP (w
->column_number_displayed
)
1453 && XFASTINT (w
->column_number_displayed
) != current_column ()))
1454 && height
!= XFASTINT (w
->height
))
1455 display_mode_line (w
);
1456 if (! line_number_displayed
1457 && ! BUFFERP (w
->base_line_pos
))
1459 w
->base_line_pos
= Qnil
;
1460 w
->base_line_number
= Qnil
;
1463 /* When we reach a frame's selected window, redo the frame's menu bar. */
1464 if (!NILP (w
->update_mode_line
)
1465 #ifdef USE_X_TOOLKIT
1466 && FRAME_EXTERNAL_MENU_BAR (f
)
1468 && FRAME_MENU_BAR_LINES (f
) > 0
1470 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
1471 display_menu_bar (w
);
1474 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
1476 int start
, end
, whole
;
1478 /* Calculate the start and end positions for the current window.
1479 At some point, it would be nice to choose between scrollbars
1480 which reflect the whole buffer size, with special markers
1481 indicating narrowing, and scrollbars which reflect only the
1484 Note that minibuffers sometimes aren't displaying any text. */
1485 if (! MINI_WINDOW_P (w
)
1486 || (w
== XWINDOW (minibuf_window
) && ! echo_area_glyphs
))
1489 start
= startp
- BEGV
;
1490 /* I don't think this is guaranteed to be right. For the
1491 moment, we'll pretend it is. */
1492 end
= (Z
- XINT (w
->window_end_pos
)) - BEGV
;
1494 if (end
< start
) end
= start
;
1495 if (whole
< (end
- start
)) whole
= end
- start
;
1498 start
= end
= whole
= 0;
1500 /* Indicate what this scroll bar ought to be displaying now. */
1501 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
1503 /* Note that we actually used the scroll bar attached to this window,
1504 so it shouldn't be deleted at the end of redisplay. */
1505 (*redeem_scroll_bar_hook
) (w
);
1508 BUF_PT (current_buffer
) = opoint
;
1509 set_buffer_temp (old
);
1510 BUF_PT (current_buffer
) = lpoint
;
1513 /* Do full redisplay on one window, starting at position `pos'. */
1516 try_window (window
, pos
)
1520 register struct window
*w
= XWINDOW (window
);
1521 register int height
= window_internal_height (w
);
1522 register int vpos
= XFASTINT (w
->top
);
1523 register int last_text_vpos
= vpos
;
1524 int tab_offset
= pos_tab_offset (w
, pos
);
1525 FRAME_PTR f
= XFRAME (w
->frame
);
1526 int width
= window_internal_width (w
) - 1;
1527 struct position val
;
1529 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1531 overlay_arrow_seen
= 0;
1532 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
1534 while (--height
>= 0)
1536 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, tab_offset
);
1537 tab_offset
+= width
;
1538 if (val
.vpos
) tab_offset
= 0;
1540 if (pos
!= val
.bufpos
)
1542 /* Next line, unless prev line ended in end of buffer with no cr */
1543 = vpos
- (val
.vpos
&& (FETCH_CHAR (val
.bufpos
- 1) != '\n'
1544 #ifdef USE_TEXT_PROPERTIES
1545 || ! NILP (Fget_char_property (val
.bufpos
-1,
1553 /* If last line is continued in middle of character,
1554 include the split character in the text considered on the frame */
1555 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1558 /* If bottom just moved off end of frame, change mode line percentage. */
1559 if (XFASTINT (w
->window_end_pos
) == 0
1561 w
->update_mode_line
= Qt
;
1563 /* Say where last char on frame will be, once redisplay is finished. */
1564 XSETFASTINT (w
->window_end_pos
, Z
- pos
);
1565 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
- XFASTINT (w
->top
));
1566 /* But that is not valid info until redisplay finishes. */
1567 w
->window_end_valid
= Qnil
;
1570 /* Try to redisplay when buffer is modified locally,
1571 computing insert/delete line to preserve text outside
1572 the bounds of the changes.
1573 Return 1 if successful, 0 if if cannot tell what to do,
1574 or -1 to tell caller to find a new window start,
1575 or -2 to tell caller to do normal redisplay with same window start. */
1578 try_window_id (window
)
1582 register struct window
*w
= XWINDOW (window
);
1583 register int height
= window_internal_height (w
);
1584 FRAME_PTR f
= XFRAME (w
->frame
);
1585 int top
= XFASTINT (w
->top
);
1586 int start
= marker_position (w
->start
);
1587 int width
= window_internal_width (w
) - 1;
1588 int hscroll
= XINT (w
->hscroll
);
1589 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
1591 register int i
, tem
;
1592 int last_text_vpos
= 0;
1594 int selective
= (INTEGERP (current_buffer
->selective_display
)
1595 ? XINT (current_buffer
->selective_display
)
1596 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
1598 struct position val
, bp
, ep
, xp
, pp
;
1599 int scroll_amount
= 0;
1601 int tab_offset
, epto
;
1603 if (GPT
- BEG
< beg_unchanged
)
1604 beg_unchanged
= GPT
- BEG
;
1605 if (Z
- GPT
< end_unchanged
)
1606 end_unchanged
= Z
- GPT
;
1608 if (beg_unchanged
+ BEG
< start
)
1609 return 0; /* Give up if changes go above top of window */
1611 /* Find position before which nothing is changed. */
1612 bp
= *compute_motion (start
, 0, lmargin
,
1613 min (ZV
, beg_unchanged
+ BEG
), height
+ 1, 0,
1614 width
, hscroll
, pos_tab_offset (w
, start
), w
);
1615 if (bp
.vpos
>= height
)
1617 if (PT
< bp
.bufpos
&& !bp
.contin
)
1619 /* All changes are below the frame, and point is on the frame.
1620 We don't need to change the frame at all.
1621 But we need to update window_end_pos to account for
1622 any change in buffer size. */
1623 bp
= *compute_motion (start
, 0, lmargin
,
1625 width
, hscroll
, pos_tab_offset (w
, start
), w
);
1626 XSETFASTINT (w
->window_end_vpos
, height
);
1627 XSETFASTINT (w
->window_end_pos
, Z
- bp
.bufpos
);
1635 /* Find beginning of that frame line. Must display from there. */
1636 bp
= *vmotion (bp
.bufpos
, 0, width
, hscroll
, window
);
1643 /* If about to start displaying at the beginning of a continuation line,
1644 really start with previous frame line, in case it was not
1645 continued when last redisplayed */
1646 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
1648 /* Likewise if we have to worry about selective display. */
1649 (selective
> 0 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
1651 bp
= *vmotion (bp
.bufpos
, -1, width
, hscroll
, window
);
1656 if (bp
.contin
&& bp
.hpos
!= lmargin
)
1658 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
1664 /* Find first visible newline after which no more is changed. */
1665 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
1667 while (tem
< ZV
- 1 && (indented_beyond_p (tem
, selective
)))
1668 tem
= find_next_newline (tem
, 1);
1670 /* Compute the cursor position after that newline. */
1671 ep
= *compute_motion (pos
, vpos
, val
.hpos
, tem
,
1672 height
, - (1 << (SHORTBITS
- 1)),
1673 width
, hscroll
, pos_tab_offset (w
, bp
.bufpos
), w
);
1675 /* If changes reach past the text available on the frame,
1676 just display rest of frame. */
1677 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
1680 stop_vpos
= ep
.vpos
;
1682 /* If no newline before ep, the line ep is on includes some changes
1683 that must be displayed. Make sure we don't stop before it. */
1684 /* Also, if changes reach all the way until ep.bufpos,
1685 it is possible that something was deleted after the
1686 newline before it, so the following line must be redrawn. */
1687 if (stop_vpos
== ep
.vpos
1688 && (ep
.bufpos
== BEGV
1689 || FETCH_CHAR (ep
.bufpos
- 1) != '\n'
1690 || ep
.bufpos
== Z
- end_unchanged
))
1691 stop_vpos
= ep
.vpos
+ 1;
1694 overlay_arrow_seen
= 0;
1696 /* If changes do not reach to bottom of window,
1697 figure out how much to scroll the rest of the window */
1698 if (stop_vpos
< height
)
1700 /* Now determine how far up or down the rest of the window has moved */
1701 epto
= pos_tab_offset (w
, ep
.bufpos
);
1702 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1703 Z
- XFASTINT (w
->window_end_pos
),
1704 10000, 0, width
, hscroll
, epto
, w
);
1705 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
1707 /* Is everything on frame below the changes whitespace?
1708 If so, no scrolling is really necessary. */
1709 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
1711 tem
= FETCH_CHAR (i
);
1712 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
1718 XSETFASTINT (w
->window_end_vpos
,
1719 XFASTINT (w
->window_end_vpos
) + scroll_amount
);
1721 /* Before doing any scrolling, verify that point will be on frame. */
1722 if (PT
> ep
.bufpos
&& !(PT
<= xp
.bufpos
&& xp
.bufpos
< height
))
1724 if (PT
<= xp
.bufpos
)
1726 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1727 PT
, height
, - (1 << (SHORTBITS
- 1)),
1728 width
, hscroll
, epto
, w
);
1732 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
,
1733 PT
, height
, - (1 << (SHORTBITS
- 1)),
1735 pos_tab_offset (w
, xp
.bufpos
), w
);
1737 if (pp
.bufpos
< PT
|| pp
.vpos
== height
)
1739 cursor_vpos
= pp
.vpos
+ top
;
1740 cursor_hpos
= pp
.hpos
+ XFASTINT (w
->left
);
1743 if (stop_vpos
- scroll_amount
>= height
1744 || ep
.bufpos
== xp
.bufpos
)
1746 if (scroll_amount
< 0)
1747 stop_vpos
-= scroll_amount
;
1749 /* In this path, we have altered window_end_vpos
1750 and not left it negative.
1751 We must make sure that, in case display is preempted
1752 before the frame changes to reflect what we do here,
1753 further updates will not come to try_window_id
1754 and assume the frame and window_end_vpos match. */
1755 blank_end_of_window
= 1;
1757 else if (!scroll_amount
)
1759 /* Even if we don't need to scroll, we must adjust the
1760 charstarts of subsequent lines (that we won't redisplay)
1761 according to the amount of text inserted or deleted. */
1762 int oldpos
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
1763 int adjust
= ep
.bufpos
- oldpos
;
1764 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1, adjust
);
1766 else if (bp
.bufpos
== Z
- end_unchanged
)
1768 /* If reprinting everything is nearly as fast as scrolling,
1769 don't bother scrolling. Can happen if lines are short. */
1770 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
1771 top
+ height
- max (0, scroll_amount
),
1773 > xp
.bufpos
- bp
.bufpos
- 20)
1774 /* Return "try normal display with same window-start."
1775 Too bad we can't prevent further scroll-thinking. */
1777 /* If pure deletion, scroll up as many lines as possible.
1778 In common case of killing a line, this can save the
1779 following line from being overwritten by scrolling
1780 and therefore having to be redrawn. */
1781 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
1782 top
+ height
- max (0, scroll_amount
),
1783 scroll_amount
, bp
.bufpos
);
1788 /* scroll_frame_lines did not properly adjust subsequent
1789 lines' charstarts in the case where the text of the
1790 screen line at bp.vpos has changed.
1791 (This can happen in a deletion that ends in mid-line.)
1792 To adjust properly, we need to make things constent at
1794 So do a second adjust to make that happen.
1795 Note that stop_vpos >= ep.vpos, so it is sufficient
1796 to update the charstarts for lines at ep.vpos and below. */
1798 = FRAME_CURRENT_GLYPHS (f
)->charstarts
[ep
.vpos
+ top
][0];
1799 adjust_window_charstarts (w
, ep
.vpos
+ top
- 1,
1800 ep
.bufpos
- oldstart
);
1803 else if (scroll_amount
)
1805 /* If reprinting everything is nearly as fast as scrolling,
1806 don't bother scrolling. Can happen if lines are short. */
1807 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1808 overestimate of cost of reprinting, since xp.bufpos
1809 would end up below the bottom of the window. */
1810 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
1811 top
+ height
- max (0, scroll_amount
),
1813 > xp
.bufpos
- ep
.bufpos
- 20)
1814 /* Return "try normal display with same window-start."
1815 Too bad we can't prevent further scroll-thinking. */
1817 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
1818 top
+ height
- max (0, scroll_amount
),
1819 scroll_amount
, ep
.bufpos
);
1820 if (!tem
) stop_vpos
= height
;
1824 /* In any case, do not display past bottom of window */
1825 if (stop_vpos
>= height
)
1831 /* Handle case where pos is before w->start --
1832 can happen if part of line had been clipped and is not clipped now */
1833 if (vpos
== 0 && pos
< marker_position (w
->start
))
1834 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1836 /* Redisplay the lines where the text was changed */
1837 last_text_vpos
= vpos
;
1838 tab_offset
= pos_tab_offset (w
, pos
);
1839 /* If we are starting display in mid-character, correct tab_offset
1840 to account for passing the line that that character really starts in. */
1841 if (val
.hpos
< lmargin
)
1842 tab_offset
+= width
;
1843 while (vpos
< stop_vpos
)
1845 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1846 tab_offset
+= width
;
1847 if (val
.vpos
) tab_offset
= 0;
1848 if (pos
!= val
.bufpos
)
1850 /* Next line, unless prev line ended in end of buffer with no cr */
1851 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
1855 /* There are two cases:
1856 1) we have displayed down to the bottom of the window
1857 2) we have scrolled lines below stop_vpos by scroll_amount */
1861 /* If last line is continued in middle of character,
1862 include the split character in the text considered on the frame */
1863 if (val
.hpos
< lmargin
)
1865 XSETFASTINT (w
->window_end_vpos
, last_text_vpos
);
1866 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
1869 /* If scrolling made blank lines at window bottom,
1870 redisplay to fill those lines */
1871 if (scroll_amount
< 0)
1873 /* Don't consider these lines for general-purpose scrolling.
1874 That will save time in the scrolling computation. */
1875 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
1880 vpos
= height
+ scroll_amount
;
1881 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
1883 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
1887 blank_end_of_window
= 1;
1888 tab_offset
= pos_tab_offset (w
, pos
);
1889 /* If we are starting display in mid-character, correct tab_offset
1890 to account for passing the line that that character starts in. */
1891 if (val
.hpos
< lmargin
)
1892 tab_offset
+= width
;
1894 while (vpos
< height
)
1896 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1897 tab_offset
+= width
;
1898 if (val
.vpos
) tab_offset
= 0;
1902 /* Here is a case where display_text_line sets cursor_vpos wrong.
1903 Make it be fixed up, below. */
1909 /* If bottom just moved off end of frame, change mode line percentage. */
1910 if (XFASTINT (w
->window_end_pos
) == 0
1912 w
->update_mode_line
= Qt
;
1914 /* Attempt to adjust end-of-text positions to new bottom line */
1917 delta
= height
- xp
.vpos
;
1919 || (delta
> 0 && xp
.bufpos
<= ZV
)
1920 || (delta
== 0 && xp
.hpos
))
1922 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
1923 delta
, width
, hscroll
, window
);
1924 XSETFASTINT (w
->window_end_pos
, Z
- val
.bufpos
);
1925 XSETFASTINT (w
->window_end_vpos
,
1926 XFASTINT (w
->window_end_vpos
) + val
.vpos
);
1930 w
->window_end_valid
= Qnil
;
1932 /* If point was not in a line that was displayed, find it */
1933 if (cursor_vpos
< 0)
1935 val
= *compute_motion (start
, 0, lmargin
, PT
, 10000, 10000,
1936 width
, hscroll
, pos_tab_offset (w
, start
), w
);
1937 /* Admit failure if point is off frame now */
1938 if (val
.vpos
>= height
)
1940 for (vpos
= 0; vpos
< height
; vpos
++)
1941 cancel_line (vpos
+ top
, f
);
1944 cursor_vpos
= val
.vpos
+ top
;
1945 cursor_hpos
= val
.hpos
+ XFASTINT (w
->left
);
1948 FRAME_CURSOR_X (f
) = max (0, cursor_hpos
);
1949 FRAME_CURSOR_Y (f
) = cursor_vpos
;
1953 val
= *compute_motion (start
, 0, lmargin
, ZV
,
1954 height
, - (1 << (SHORTBITS
- 1)),
1955 width
, hscroll
, pos_tab_offset (w
, start
), w
);
1956 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
1958 if (XFASTINT (w
->window_end_pos
)
1966 /* Mark a section of BUF as modified, but only for the sake of redisplay.
1967 This is useful for recording changes to overlays.
1969 We increment the buffer's modification timestamp and set the
1970 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
1971 as if the region of text between START and END had been modified;
1972 the redisplay code will check this against the windows' timestamps,
1973 and redraw the appropriate area of the buffer.
1975 However, if the buffer is unmodified, we bump the last-save
1976 timestamp as well, so that incrementing the timestamp doesn't fool
1977 Emacs into thinking that the buffer's text has been modified.
1979 Tweaking the timestamps shouldn't hurt the first-modification
1980 timestamps recorded in the undo records; those values aren't
1981 written until just before a real text modification is made, so they
1982 will never catch the timestamp value just before this function gets
1986 redisplay_region (buf
, start
, end
)
1996 start
= end
; end
= temp
;
1999 /* If this is a buffer not in the selected window,
2000 we must do other windows. */
2001 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
2002 windows_or_buffers_changed
= 1;
2003 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2004 else if (buf
!= current_buffer
)
2005 windows_or_buffers_changed
= 1;
2006 /* If multiple windows show this buffer, we must do other windows. */
2007 else if (buffer_shared
> 1)
2008 windows_or_buffers_changed
= 1;
2011 if (unchanged_modified
== MODIFF
)
2013 beg_unchanged
= start
- BEG
;
2014 end_unchanged
= Z
- end
;
2018 if (Z
- end
< end_unchanged
)
2019 end_unchanged
= Z
- end
;
2020 if (start
- BEG
< beg_unchanged
)
2021 beg_unchanged
= start
- BEG
;
2025 /* Increment the buffer's time stamp, but also increment the save
2026 and autosave timestamps, so as not to screw up that timekeeping. */
2027 if (BUF_MODIFF (buf
) == BUF_SAVE_MODIFF (buf
))
2028 BUF_SAVE_MODIFF (buf
)++;
2029 if (BUF_MODIFF (buf
) == buf
->auto_save_modified
)
2030 buf
->auto_save_modified
++;
2032 BUF_MODIFF (buf
) ++;
2036 /* Copy LEN glyphs starting address FROM to the rope TO.
2037 But don't actually copy the parts that would come in before S.
2038 Value is TO, advanced past the copied data.
2039 F is the frame we are displaying in. */
2042 copy_part_of_rope (f
, to
, s
, from
, len
, face
)
2044 register GLYPH
*to
; /* Copy to here. */
2045 register GLYPH
*s
; /* Starting point. */
2046 Lisp_Object
*from
; /* Data to copy. */
2048 int face
; /* Face to apply to glyphs which don't specify one. */
2051 register Lisp_Object
*fp
= from
;
2052 /* These cache the results of the last call to compute_glyph_face. */
2054 int last_merged
= 0;
2057 if (! FRAME_TERMCAP_P (f
))
2060 int glyph
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2063 if (FAST_GLYPH_FACE (glyph
) == 0)
2064 /* If GLYPH has no face code, use FACE. */
2066 else if (FAST_GLYPH_FACE (glyph
) == last_code
)
2067 /* If it's same as previous glyph, use same result. */
2068 facecode
= last_merged
;
2071 /* Merge this glyph's face and remember the result. */
2072 last_code
= FAST_GLYPH_FACE (glyph
);
2073 last_merged
= facecode
= compute_glyph_face (f
, last_code
, face
);
2077 *to
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), facecode
);
2085 if (to
>= s
) *to
= (INTEGERP (*fp
) ? XFASTINT (*fp
) : 0);
2092 /* Correct a glyph by replacing its specified user-level face code
2093 with a displayable computed face code. */
2096 fix_glyph (f
, glyph
, cface
)
2102 if (! FRAME_TERMCAP_P (f
))
2104 if (FAST_GLYPH_FACE (glyph
) != 0)
2105 cface
= compute_glyph_face (f
, FAST_GLYPH_FACE (glyph
), cface
);
2106 glyph
= FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph
), cface
);
2112 /* Display one line of window W, starting at position START in W's buffer.
2114 Display starting at horizontal position HPOS, expressed relative to
2115 W's left edge. In situations where the text at START shouldn't
2116 start at the left margin (i.e. when the window is hscrolled, or
2117 we're continuing a line which left off in the midst of a
2118 multi-column character), HPOS should be negative; we throw away
2119 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2122 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2124 Display on position VPOS on the frame. It is origin 0, relative to
2125 the top of the frame, not W.
2127 Returns a STRUCT POSITION giving character to start next line with
2128 and where to display it, including a zero or negative hpos.
2129 The vpos field is not really a vpos; it is 1 unless the line is continued */
2131 struct position val_display_text_line
;
2133 static struct position
*
2134 display_text_line (w
, start
, vpos
, hpos
, taboffset
)
2141 register int pos
= start
;
2146 register unsigned char *p
;
2148 register GLYPH
*leftmargin
;
2149 register GLYPH
*p1prev
= 0;
2150 register GLYPH
*p1start
;
2152 FRAME_PTR f
= XFRAME (w
->frame
);
2153 int tab_width
= XINT (current_buffer
->tab_width
);
2154 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
2155 int width
= window_internal_width (w
) - 1;
2156 struct position val
;
2159 int hscroll
= XINT (w
->hscroll
);
2160 int truncate
= (hscroll
2161 || (truncate_partial_width_windows
2162 && XFASTINT (w
->width
) < FRAME_WIDTH (f
))
2163 || !NILP (current_buffer
->truncate_lines
));
2165 /* 1 if we should highlight the region. */
2166 int highlight_region
2167 = !NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
);
2168 int region_beg
, region_end
;
2170 int selective
= (INTEGERP (current_buffer
->selective_display
)
2171 ? XINT (current_buffer
->selective_display
)
2172 : !NILP (current_buffer
->selective_display
) ? -1 : 0);
2173 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
2174 register struct Lisp_Vector
*dp
= window_display_table (w
);
2176 Lisp_Object default_invis_vector
[3];
2177 /* Nonzero means display something where there are invisible lines.
2178 The precise value is the number of glyphs to display. */
2180 = (selective
&& dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2181 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->size
2182 : selective
&& !NILP (current_buffer
->selective_display_ellipses
)
2184 /* This is the sequence of Lisp objects to display
2185 when there are invisible lines. */
2186 Lisp_Object
*invis_vector_contents
2187 = (dp
&& VECTORP (DISP_INVIS_VECTOR (dp
))
2188 ? XVECTOR (DISP_INVIS_VECTOR (dp
))->contents
2189 : default_invis_vector
);
2191 GLYPH truncator
= (dp
== 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp
))
2192 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
2193 GLYPH continuer
= (dp
== 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp
))
2194 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
2196 /* The next buffer location at which the face should change, due
2197 to overlays or text property changes. */
2198 int next_face_change
;
2200 #ifdef USE_TEXT_PROPERTIES
2201 /* The next location where the `invisible' property changes */
2205 /* The face we're currently using. */
2206 int current_face
= 0;
2209 XSETFASTINT (default_invis_vector
[2], '.');
2210 default_invis_vector
[0] = default_invis_vector
[1] = default_invis_vector
[2];
2212 hpos
+= XFASTINT (w
->left
);
2213 get_display_line (f
, vpos
, XFASTINT (w
->left
));
2214 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
2216 /* Show where to highlight the region. */
2217 if (highlight_region
&& XMARKER (current_buffer
->mark
)->buffer
!= 0
2218 /* Maybe highlight only in selected window. */
2219 && (highlight_nonselected_windows
2220 || w
== XWINDOW (selected_window
)))
2222 region_beg
= marker_position (current_buffer
->mark
);
2223 if (PT
< region_beg
)
2225 region_end
= region_beg
;
2230 w
->region_showing
= Qt
;
2233 region_beg
= region_end
= -1;
2235 if (MINI_WINDOW_P (w
)
2237 && vpos
== XFASTINT (w
->top
))
2239 if (! NILP (minibuf_prompt
))
2241 minibuf_prompt_width
2242 = (display_string (w
, vpos
, XSTRING (minibuf_prompt
)->data
,
2243 XSTRING (minibuf_prompt
)->size
, hpos
,
2244 /* Display a space if we truncate. */
2247 /* Truncate the prompt a little before the
2248 margin, so user input can at least start
2249 on the first line. */
2250 w
->width
> 10 ? w
->width
- 4 : -1)
2252 hpos
+= minibuf_prompt_width
;
2255 minibuf_prompt_width
= 0;
2260 /* If we're hscrolled at all, use compute_motion to skip over any
2261 text off the left edge of the window. compute_motion may know
2262 tricks to do this faster than we can. */
2265 struct position
*left_edge
2266 = compute_motion (pos
, vpos
, hpos
,
2268 width
, hscroll
, taboffset
, w
);
2270 /* Retrieve the buffer position and column provided by
2271 compute_motion. We can't assume that the column will be
2272 zero, because you may have multi-column characters crossing
2275 compute_motion may have moved us past the screen position we
2276 requested, if we hit a multi-column character, or the end of
2277 the line. If so, back up. */
2278 if (left_edge
->vpos
> vpos
2279 || left_edge
->hpos
> 0)
2281 pos
= left_edge
->bufpos
- 1;
2282 hpos
= left_edge
->prevhpos
;
2286 pos
= left_edge
->bufpos
;
2287 hpos
= left_edge
->hpos
;
2291 desired_glyphs
->bufp
[vpos
] = start
;
2292 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2294 charstart
= desired_glyphs
->charstarts
[vpos
] + hpos
;
2295 /* In case we don't ever write anything into it... */
2296 desired_glyphs
->charstarts
[vpos
][XFASTINT (w
->left
)] = -1;
2297 leftmargin
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
2298 endp
= leftmargin
+ width
;
2300 /* Arrange the overlays nicely for our purposes. Usually, we call
2301 display_text_line on only one line at a time, in which case this
2302 can't really hurt too much, or we call it on lines which appear
2303 one after another in the buffer, in which case all calls to
2304 recenter_overlay_lists but the first will be pretty cheap. */
2305 recenter_overlay_lists (current_buffer
, pos
);
2307 /* Loop generating characters.
2308 Stop at end of buffer, before newline,
2309 if reach or pass continuation column,
2310 or at face change. */
2312 next_face_change
= pos
;
2313 #ifdef USE_TEXT_PROPERTIES
2314 next_invisible
= pos
;
2318 /* Record which glyph starts a character,
2319 and the character position of that character. */
2320 if (p1
>= leftmargin
)
2321 charstart
[p1
- p1start
] = pos
;
2329 /* Did we hit the end of the visible region of the buffer?
2334 /* Did we reach point? Record the cursor location. */
2335 if (pos
== PT
&& cursor_vpos
< 0)
2338 cursor_hpos
= p1
- leftmargin
;
2341 #ifdef USE_TEXT_PROPERTIES
2342 /* if the `invisible' property is set to t, we can skip to
2343 the next property change */
2344 while (pos
== next_invisible
&& pos
< end
)
2346 Lisp_Object position
, limit
, endpos
, prop
, ww
;
2347 XSETFASTINT (position
, pos
);
2349 prop
= Fget_char_property (position
, Qinvisible
, ww
);
2350 /* This is just an estimate to give reasonable
2351 performance; nothing should go wrong if it is too small. */
2352 limit
= Fnext_overlay_change (position
);
2353 if (XFASTINT (limit
) > pos
+ 50)
2354 XSETFASTINT (limit
, pos
+ 50);
2355 endpos
= Fnext_single_property_change (position
, Qinvisible
,
2356 Fcurrent_buffer (), limit
);
2357 if (INTEGERP (endpos
))
2358 next_invisible
= XINT (endpos
);
2360 next_invisible
= end
;
2363 if (pos
< PT
&& next_invisible
>= PT
)
2366 cursor_hpos
= p1
- leftmargin
;
2368 pos
= next_invisible
;
2376 /* Did we hit a face change? Figure out what face we should
2377 use now. We also hit this the first time through the
2378 loop, to see what face we should start with. */
2379 if (pos
>= next_face_change
&& FRAME_X_P (f
))
2380 current_face
= compute_char_face (f
, w
, pos
,
2381 region_beg
, region_end
,
2382 &next_face_change
, pos
+ 50, 0);
2387 #ifdef USE_TEXT_PROPERTIES
2388 if (pos
< next_invisible
&& next_invisible
< pause
)
2389 pause
= next_invisible
;
2391 if (pos
< next_face_change
&& next_face_change
< pause
)
2392 pause
= next_face_change
;
2394 /* Wouldn't you hate to read the next line to someone over
2396 if (pos
< PT
&& PT
< pause
)
2398 if (pos
< GPT
&& GPT
< pause
)
2401 p
= &FETCH_CHAR (pos
);
2404 if (c
>= 040 && c
< 0177
2405 && (dp
== 0 || !VECTORP (DISP_CHAR_VECTOR (dp
, c
))))
2407 if (p1
>= leftmargin
)
2408 *p1
= MAKE_GLYPH (f
, c
, current_face
);
2414 while (pos
+ 1 < end
2416 && indented_beyond_p (pos
+ 1, selective
))
2419 pos
= find_next_newline (pos
+ 1, 1);
2420 if (FETCH_CHAR (pos
- 1) == '\n')
2423 if (invis
&& selective_rlen
> 0 && p1
>= leftmargin
)
2425 p1
+= selective_rlen
;
2426 if (p1
- leftmargin
> width
)
2428 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
2429 (p1
- p1prev
), current_face
);
2432 /* Draw the face of the newline character as extending all the
2433 way to the end of the frame line. */
2436 if (p1
< leftmargin
)
2439 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
);
2448 if (p1
>= leftmargin
&& p1
< endp
)
2449 *p1
= MAKE_GLYPH (f
, ' ', current_face
);
2452 while ((p1
- leftmargin
+ taboffset
+ hscroll
- (hscroll
> 0))
2455 else if (c
== Ctl ('M') && selective
== -1)
2457 pos
= find_next_newline (pos
, 1);
2458 if (FETCH_CHAR (pos
- 1) == '\n')
2460 if (selective_rlen
> 0)
2462 p1
+= selective_rlen
;
2463 if (p1
- leftmargin
> width
)
2465 copy_part_of_rope (f
, p1prev
, p1prev
, invis_vector_contents
,
2466 (p1
- p1prev
), current_face
);
2469 /* Draw the face of the newline character as extending all the
2470 way to the end of the frame line. */
2473 if (p1
< leftmargin
)
2476 *p1
++ = FAST_MAKE_GLYPH (' ', current_face
);
2481 else if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
2483 p1
= copy_part_of_rope (f
, p1
, leftmargin
,
2484 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
2485 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
2488 else if (c
< 0200 && ctl_arrow
)
2490 if (p1
>= leftmargin
)
2491 *p1
= fix_glyph (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
2492 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
2495 if (p1
>= leftmargin
&& p1
< endp
)
2496 *p1
= MAKE_GLYPH (f
, c
^ 0100, current_face
);
2501 if (p1
>= leftmargin
)
2502 *p1
= fix_glyph (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
2503 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
2506 if (p1
>= leftmargin
&& p1
< endp
)
2507 *p1
= MAKE_GLYPH (f
, (c
>> 6) + '0', current_face
);
2509 if (p1
>= leftmargin
&& p1
< endp
)
2510 *p1
= MAKE_GLYPH (f
, (7 & (c
>> 3)) + '0', current_face
);
2512 if (p1
>= leftmargin
&& p1
< endp
)
2513 *p1
= MAKE_GLYPH (f
, (7 & c
) + '0', current_face
);
2517 /* Do nothing here for a char that's entirely off the left edge. */
2518 if (p1
>= leftmargin
)
2520 /* For all the glyphs occupied by this character, except for the
2521 first, store -1 in charstarts. */
2524 int *p2x
= &charstart
[p1prev
- p1start
];
2525 int *p2
= &charstart
[(p1
< endp
? p1
: endp
) - p1start
];
2527 /* The window's left column should always
2528 contain a character position.
2529 And don't clobber anything to the left of that. */
2530 if (p1prev
< leftmargin
)
2532 p2x
= charstart
+ (leftmargin
- p1start
);
2536 /* This loop skips over the char p2x initially points to. */
2545 val
.hpos
= - XINT (w
->hscroll
);
2553 /* Store 0 in this charstart line for the positions where
2554 there is no character. But do leave what was recorded
2555 for the character that ended the line. */
2556 /* Add 1 in the endtest to compensate for the fact that ENDP was
2557 made from WIDTH, which is 1 less than the window's actual
2559 i
= p1
- p1start
+ 1;
2560 if (p1
< leftmargin
)
2561 i
+= leftmargin
- p1
;
2562 for (; i
< endp
- p1start
+ 1; i
++)
2565 /* Handle continuation in middle of a character */
2566 /* by backing up over it */
2569 /* Don't back up if we never actually displayed any text.
2570 This occurs when the minibuffer prompt takes up the whole line. */
2573 /* Start the next line with that same character */
2575 /* but at negative hpos, to skip the columns output on this line. */
2576 val
.hpos
+= p1prev
- endp
;
2579 /* Keep in this line everything up to the continuation column. */
2583 /* Finish deciding which character to start the next line on,
2584 and what hpos to start it at.
2585 Also set `lastpos' to the last position which counts as "on this line"
2586 for cursor-positioning. */
2590 if (FETCH_CHAR (pos
) == '\n')
2592 /* If stopped due to a newline, start next line after it */
2594 /* Check again for hidden lines, in case the newline occurred exactly
2595 at the right margin. */
2596 while (pos
< ZV
&& selective
> 0
2597 && indented_beyond_p (pos
, selective
))
2598 pos
= find_next_newline (pos
, 1);
2601 /* Stopped due to right margin of window */
2605 *p1
++ = fix_glyph (f
, truncator
, 0);
2606 /* Truncating => start next line after next newline,
2607 and point is on this line if it is before the newline,
2608 and skip none of first char of next line */
2610 pos
= find_next_newline (pos
, 1);
2611 while (pos
< ZV
&& selective
> 0
2612 && indented_beyond_p (pos
, selective
));
2613 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
2615 lastpos
= pos
- (FETCH_CHAR (pos
- 1) == '\n');
2619 *p1
++ = fix_glyph (f
, continuer
, 0);
2626 /* If point is at eol or in invisible text at eol,
2627 record its frame location now. */
2629 if (start
<= PT
&& PT
<= lastpos
&& cursor_vpos
< 0)
2632 cursor_hpos
= p1
- leftmargin
;
2635 if (cursor_vpos
== vpos
)
2637 if (cursor_hpos
< 0) cursor_hpos
= 0;
2638 if (cursor_hpos
> width
) cursor_hpos
= width
;
2639 cursor_hpos
+= XFASTINT (w
->left
);
2640 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
2642 FRAME_CURSOR_Y (f
) = cursor_vpos
;
2643 FRAME_CURSOR_X (f
) = cursor_hpos
;
2645 if (w
== XWINDOW (selected_window
))
2647 /* Line is not continued and did not start
2648 in middle of character */
2649 if ((hpos
- XFASTINT (w
->left
)
2650 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
2653 this_line_bufpos
= start
;
2654 this_line_buffer
= current_buffer
;
2655 this_line_vpos
= cursor_vpos
;
2656 this_line_start_hpos
= hpos
;
2657 this_line_endpos
= Z
- lastpos
;
2660 this_line_bufpos
= 0;
2665 /* If hscroll and line not empty, insert truncation-at-left marker */
2666 if (hscroll
&& lastpos
!= start
)
2668 *leftmargin
= fix_glyph (f
, truncator
, 0);
2669 if (p1
<= leftmargin
)
2670 p1
= leftmargin
+ 1;
2673 if (XFASTINT (w
->width
) + XFASTINT (w
->left
) != FRAME_WIDTH (f
))
2676 if (p1
< leftmargin
) p1
= leftmargin
;
2677 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
2679 /* Don't draw vertical bars if we're using scroll bars. They're
2680 covered up by the scroll bars, and it's distracting to see
2681 them when the scroll bar windows are flickering around to be
2683 *p1
++ = (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
2685 : (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
2686 ? DISP_BORDER_GLYPH (dp
)
2689 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
2690 p1
- desired_glyphs
->glyphs
[vpos
]);
2691 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
2693 /* If the start of this line is the overlay arrow-position,
2694 then put the arrow string into the display-line. */
2696 if (MARKERP (Voverlay_arrow_position
)
2697 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
2698 && start
== marker_position (Voverlay_arrow_position
)
2699 && STRINGP (Voverlay_arrow_string
)
2700 && ! overlay_arrow_seen
)
2702 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
2704 int len
= XSTRING (Voverlay_arrow_string
)->size
;
2710 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string
)->intervals
))
2712 /* If the arrow string has text props, obey them when displaying. */
2713 for (i
= 0; i
< len
; i
++)
2716 Lisp_Object face
, ilisp
;
2719 XSETFASTINT (ilisp
, i
);
2720 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
2721 newface
= compute_glyph_face_1 (f
, face
, 0);
2722 leftmargin
[i
] = FAST_MAKE_GLYPH (c
, newface
);
2726 #endif /* HAVE_FACES */
2728 for (i
= 0; i
< len
; i
++)
2729 leftmargin
[i
] = p
[i
];
2732 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
2733 arrow_end
= (leftmargin
- desired_glyphs
->glyphs
[vpos
]) + len
;
2734 if (desired_glyphs
->used
[vpos
] < arrow_end
)
2735 desired_glyphs
->used
[vpos
] = arrow_end
;
2737 overlay_arrow_seen
= 1;
2741 val_display_text_line
= val
;
2742 return &val_display_text_line
;
2745 /* Redisplay the menu bar in the frame for window W. */
2748 display_menu_bar (w
)
2751 Lisp_Object items
, tail
;
2752 register int vpos
= 0;
2753 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2754 int maxendcol
= FRAME_WIDTH (f
);
2758 #ifndef USE_X_TOOLKIT
2759 if (FRAME_MENU_BAR_LINES (f
) <= 0)
2762 get_display_line (f
, vpos
, 0);
2764 items
= FRAME_MENU_BAR_ITEMS (f
);
2765 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
2767 Lisp_Object pos
, string
;
2768 string
= XVECTOR (items
)->contents
[i
+ 1];
2772 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 2], hpos
);
2774 if (hpos
< maxendcol
)
2775 hpos
= display_string (XWINDOW (FRAME_ROOT_WINDOW (f
)), vpos
,
2776 XSTRING (string
)->data
,
2777 XSTRING (string
)->size
,
2778 hpos
, 0, 0, hpos
, maxendcol
);
2779 /* Put a gap of 3 spaces between items. */
2780 if (hpos
< maxendcol
)
2782 int hpos1
= hpos
+ 3;
2783 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0,
2784 min (hpos1
, maxendcol
), maxendcol
);
2788 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
2789 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
2791 /* Fill out the line with spaces. */
2792 if (maxendcol
> hpos
)
2793 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 0, maxendcol
, maxendcol
);
2795 /* Clear the rest of the lines allocated to the menu bar. */
2797 while (vpos
< FRAME_MENU_BAR_LINES (f
))
2798 get_display_line (f
, vpos
++, 0);
2799 #endif /* not USE_X_TOOLKIT */
2802 /* Display the mode line for window w */
2805 display_mode_line (w
)
2808 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
2809 register int left
= XFASTINT (w
->left
);
2810 register int right
= XFASTINT (w
->width
) + left
;
2811 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2813 line_number_displayed
= 0;
2814 w
->column_number_displayed
= Qnil
;
2816 get_display_line (f
, vpos
, left
);
2817 display_mode_element (w
, vpos
, left
, 0, right
, right
,
2818 current_buffer
->mode_line_format
);
2819 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
2821 /* Make the mode line inverse video if the entire line
2822 is made of mode lines.
2823 I.e. if this window is full width,
2824 or if it is the child of a full width window
2825 (which implies that that window is split side-by-side
2826 and the rest of this line is mode lines of the sibling windows). */
2827 if (XFASTINT (w
->width
) == FRAME_WIDTH (f
)
2828 || XFASTINT (XWINDOW (w
->parent
)->width
) == FRAME_WIDTH (f
))
2829 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
2831 else if (! FRAME_TERMCAP_P (f
))
2833 /* For a partial width window, explicitly set face of each glyph. */
2835 GLYPH
*ptr
= FRAME_DESIRED_GLYPHS (f
)->glyphs
[vpos
];
2836 for (i
= left
; i
< right
; ++i
)
2837 ptr
[i
] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr
[i
]), 1);
2842 /* Contribute ELT to the mode line for window W.
2843 How it translates into text depends on its data type.
2845 VPOS is the position of the mode line being displayed.
2847 HPOS is the position (absolute on frame) where this element's text
2848 should start. The output is truncated automatically at the right
2851 DEPTH is the depth in recursion. It is used to prevent
2852 infinite recursion here.
2854 MINENDCOL is the hpos before which the element may not end.
2855 The element is padded at the right with spaces if nec
2856 to reach this column.
2858 MAXENDCOL is the hpos past which this element may not extend.
2859 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
2860 (This is necessary to make nested padding and truncation work.)
2862 Returns the hpos of the end of the text generated by ELT.
2863 The next element will receive that value as its HPOS arg,
2864 so as to concatenate the elements. */
2867 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
2869 register int vpos
, hpos
;
2872 register int maxendcol
;
2873 register Lisp_Object elt
;
2881 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
2885 /* A string: output it and check for %-constructs within it. */
2886 register unsigned char c
;
2887 register unsigned char *this = XSTRING (elt
)->data
;
2889 while (hpos
< maxendcol
&& *this)
2891 unsigned char *last
= this;
2892 while ((c
= *this++) != '\0' && c
!= '%')
2894 if (this - 1 != last
)
2896 register int lim
= --this - last
+ hpos
;
2897 if (frame_title_ptr
)
2898 hpos
= store_frame_title (last
, hpos
, min (lim
, maxendcol
));
2900 hpos
= display_string (w
, vpos
, last
, -1, hpos
, 0, 1,
2901 hpos
, min (lim
, maxendcol
));
2905 register int spec_width
= 0;
2907 /* We can't allow -ve args due to the "%-" construct */
2908 /* Argument specifies minwidth but not maxwidth
2909 (maxwidth can be specified by
2910 (<negative-number> . <stuff>) mode-line elements) */
2912 while ((c
= *this++) >= '0' && c
<= '9')
2914 spec_width
= spec_width
* 10 + (c
- '0');
2918 if (spec_width
> maxendcol
)
2919 spec_width
= maxendcol
;
2922 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
2923 spec_width
, maxendcol
,
2924 Vglobal_mode_string
);
2927 char *spec
= decode_mode_spec (w
, c
, maxendcol
- hpos
);
2928 if (frame_title_ptr
)
2929 hpos
= store_frame_title (spec
, spec_width
, maxendcol
);
2931 hpos
= display_string (w
, vpos
, spec
, -1,
2933 spec_width
, maxendcol
);
2941 /* A symbol: process the value of the symbol recursively
2942 as if it appeared here directly. Avoid error if symbol void.
2943 Special case: if value of symbol is a string, output the string
2946 register Lisp_Object tem
;
2947 tem
= Fboundp (elt
);
2950 tem
= Fsymbol_value (elt
);
2951 /* If value is a string, output that string literally:
2952 don't check for % within it. */
2955 if (frame_title_ptr
)
2956 hpos
= store_frame_title (XSTRING (tem
)->data
,
2957 minendcol
, maxendcol
);
2959 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
2960 XSTRING (tem
)->size
,
2961 hpos
, 0, 1, minendcol
, maxendcol
);
2963 /* Give up right away for nil or t. */
2964 else if (!EQ (tem
, elt
))
2965 { elt
= tem
; goto tail_recurse
; }
2972 register Lisp_Object car
, tem
;
2974 /* A cons cell: three distinct cases.
2975 If first element is a string or a cons, process all the elements
2976 and effectively concatenate them.
2977 If first element is a negative number, truncate displaying cdr to
2978 at most that many characters. If positive, pad (with spaces)
2979 to at least that many characters.
2980 If first element is a symbol, process the cadr or caddr recursively
2981 according to whether the symbol's value is non-nil or nil. */
2982 car
= XCONS (elt
)->car
;
2985 tem
= Fboundp (car
);
2986 elt
= XCONS (elt
)->cdr
;
2989 /* elt is now the cdr, and we know it is a cons cell.
2990 Use its car if CAR has a non-nil value. */
2993 tem
= Fsymbol_value (car
);
2995 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
2997 /* Symbol's value is nil (or symbol is unbound)
2998 Get the cddr of the original list
2999 and if possible find the caddr and use that. */
3000 elt
= XCONS (elt
)->cdr
;
3003 else if (!CONSP (elt
))
3005 elt
= XCONS (elt
)->car
;
3008 else if (INTEGERP (car
))
3010 register int lim
= XINT (car
);
3011 elt
= XCONS (elt
)->cdr
;
3013 /* Negative int means reduce maximum width.
3014 DO NOT change MINENDCOL here!
3015 (20 -10 . foo) should truncate foo to 10 col
3016 and then pad to 20. */
3017 maxendcol
= min (maxendcol
, hpos
- lim
);
3020 /* Padding specified. Don't let it be more than
3023 if (lim
> maxendcol
)
3025 /* If that's more padding than already wanted, queue it.
3026 But don't reduce padding already specified even if
3027 that is beyond the current truncation point. */
3028 if (lim
> minendcol
)
3033 else if (STRINGP (car
) || CONSP (car
))
3035 register int limit
= 50;
3036 /* LIMIT is to protect against circular lists. */
3037 while (CONSP (elt
) && --limit
> 0
3038 && hpos
< maxendcol
)
3040 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
3043 elt
= XCONS (elt
)->cdr
;
3051 if (frame_title_ptr
)
3052 hpos
= store_frame_title ("*invalid*", minendcol
, maxendcol
);
3054 hpos
= display_string (w
, vpos
, "*invalid*", -1, hpos
, 0, 1,
3055 minendcol
, maxendcol
);
3059 if (minendcol
> hpos
)
3060 if (frame_title_ptr
)
3061 hpos
= store_frame_title ("", minendcol
, maxendcol
);
3063 hpos
= display_string (w
, vpos
, "", 0, hpos
, 0, 1, minendcol
, maxendcol
);
3067 /* Return a string for the output of a mode line %-spec for window W,
3068 generated by character C and width MAXWIDTH. */
3070 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
3073 decode_mode_spec (w
, c
, maxwidth
)
3076 register int maxwidth
;
3079 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3080 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
3081 struct buffer
*b
= XBUFFER (w
->buffer
);
3084 if (maxwidth
> FRAME_WIDTH (f
))
3085 maxwidth
= FRAME_WIDTH (f
);
3092 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
3094 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
3095 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
3096 decode_mode_spec_buf
[maxwidth
] = '\0';
3097 return decode_mode_spec_buf
;
3107 else if (STRINGP (obj
) && XSTRING (obj
)->size
> maxwidth
)
3109 bcopy ("...", decode_mode_spec_buf
, 3);
3110 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
3111 decode_mode_spec_buf
+ 3, maxwidth
- 3);
3112 return decode_mode_spec_buf
;
3119 int col
= current_column ();
3120 XSETFASTINT (w
->column_number_displayed
, col
);
3121 sprintf (decode_mode_spec_buf
, "%d", col
);
3122 return decode_mode_spec_buf
;
3127 int startpos
= marker_position (w
->start
);
3128 int line
, linepos
, topline
;
3131 int height
= XFASTINT (w
->height
);
3133 /* If we decided that this buffer isn't suitable for line numbers,
3134 don't forget that too fast. */
3135 if (EQ (w
->base_line_pos
, w
->buffer
))
3138 /* If the buffer is very big, don't waste time. */
3139 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
3141 w
->base_line_pos
= Qnil
;
3142 w
->base_line_number
= Qnil
;
3146 if (!NILP (w
->base_line_number
)
3147 && !NILP (w
->base_line_pos
)
3148 && XFASTINT (w
->base_line_pos
) <= marker_position (w
->start
))
3150 line
= XFASTINT (w
->base_line_number
);
3151 linepos
= XFASTINT (w
->base_line_pos
);
3156 linepos
= BUF_BEGV (b
);
3159 /* Count lines from base line to window start position. */
3160 nlines
= display_count_lines (linepos
, startpos
, startpos
, &junk
);
3162 topline
= nlines
+ line
;
3164 /* Determine a new base line, if the old one is too close
3165 or too far away, or if we did not have one.
3166 "Too close" means it's plausible a scroll-down would
3168 if (startpos
== BUF_BEGV (b
))
3170 XSETFASTINT (w
->base_line_number
, topline
);
3171 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
3173 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
3174 || linepos
== BUF_BEGV (b
))
3176 int limit
= BUF_BEGV (b
);
3178 int distance
= (height
* 2 + 30) * 200;
3180 if (startpos
- distance
> limit
)
3181 limit
= startpos
- distance
;
3183 nlines
= display_count_lines (startpos
, limit
,
3186 /* If we couldn't find the lines we wanted within
3188 give up on line numbers for this window. */
3189 if (position
== startpos
- distance
)
3191 w
->base_line_pos
= w
->buffer
;
3192 w
->base_line_number
= Qnil
;
3196 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
3197 XSETFASTINT (w
->base_line_pos
, position
);
3200 /* Now count lines from the start pos to point. */
3201 nlines
= display_count_lines (startpos
, PT
, PT
, &junk
);
3203 /* Record that we did display the line number. */
3204 line_number_displayed
= 1;
3206 /* Make the string to show. */
3207 sprintf (decode_mode_spec_buf
, "%d", topline
+ nlines
);
3208 return decode_mode_spec_buf
;
3217 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
3222 if (!NILP (b
->read_only
))
3224 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
3229 /* This differs from %* only for a modified read-only buffer. */
3230 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
3232 if (!NILP (b
->read_only
))
3237 /* This differs from %* in ignoring read-only-ness. */
3238 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
3243 /* status of process */
3244 obj
= Fget_buffer_process (w
->buffer
);
3246 return "no process";
3248 obj
= Fsymbol_name (Fprocess_status (obj
));
3252 case 't': /* indicate TEXT or BINARY */
3253 #ifdef MODE_LINE_BINARY_TEXT
3254 return MODE_LINE_BINARY_TEXT (b
);
3261 int pos
= marker_position (w
->start
);
3262 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
3264 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
3266 if (pos
<= BUF_BEGV (b
))
3271 else if (pos
<= BUF_BEGV (b
))
3275 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
3276 /* We can't normally display a 3-digit number,
3277 so get us a 2-digit number that is close. */
3280 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
3281 return decode_mode_spec_buf
;
3285 /* Display percentage of size above the bottom of the screen. */
3288 int toppos
= marker_position (w
->start
);
3289 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
3290 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
3292 if (botpos
>= BUF_ZV (b
))
3294 if (toppos
<= BUF_BEGV (b
))
3301 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
3302 /* We can't normally display a 3-digit number,
3303 so get us a 2-digit number that is close. */
3306 if (toppos
<= BUF_BEGV (b
))
3307 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
3309 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
3310 return decode_mode_spec_buf
;
3322 if (command_loop_level
> 5)
3324 p
= decode_mode_spec_buf
;
3325 for (i
= 0; i
< command_loop_level
; i
++)
3328 return decode_mode_spec_buf
;
3336 if (command_loop_level
> 5)
3338 p
= decode_mode_spec_buf
;
3339 for (i
= 0; i
< command_loop_level
; i
++)
3342 return decode_mode_spec_buf
;
3350 if (maxwidth
< sizeof (lots_of_dashes
))
3351 return lots_of_dashes
;
3354 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
3358 return decode_mode_spec_buf
;
3363 return (char *) XSTRING (obj
)->data
;
3368 /* Search for COUNT instances of a line boundary, which means either a
3369 newline or (if selective display enabled) a carriage return.
3370 Start at START. If COUNT is negative, search backwards.
3372 If we find COUNT instances, set *SHORTAGE to zero, and return the
3373 position after the COUNTth match. Note that for reverse motion
3374 this is not the same as the usual convention for Emacs motion commands.
3376 If we don't find COUNT instances before reaching the end of the
3377 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
3378 the number of line boundaries left unfound, and return the end of the
3379 buffer we bumped up against. */
3382 display_scan_buffer (start
, count
, shortage
)
3383 int *shortage
, start
;
3386 int limit
= ((count
> 0) ? ZV
- 1 : BEGV
);
3387 int direction
= ((count
> 0) ? 1 : -1);
3389 register unsigned char *cursor
;
3390 unsigned char *base
;
3392 register int ceiling
;
3393 register unsigned char *ceiling_addr
;
3395 /* If we are not in selective display mode,
3396 check only for newlines. */
3397 if (! (!NILP (current_buffer
->selective_display
)
3398 && !INTEGERP (current_buffer
->selective_display
)))
3399 return scan_buffer ('\n', start
, 0, count
, shortage
, 0);
3401 /* The code that follows is like scan_buffer
3402 but checks for either newline or carriage return. */
3408 while (start
!= limit
+ 1)
3410 ceiling
= BUFFER_CEILING_OF (start
);
3411 ceiling
= min (limit
, ceiling
);
3412 ceiling_addr
= &FETCH_CHAR (ceiling
) + 1;
3413 base
= (cursor
= &FETCH_CHAR (start
));
3416 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
3418 if (cursor
!= ceiling_addr
)
3423 return (start
+ cursor
- base
+ 1);
3426 if (++cursor
== ceiling_addr
)
3432 start
+= cursor
- base
;
3436 start
--; /* first character we scan */
3437 while (start
> limit
- 1)
3438 { /* we WILL scan under start */
3439 ceiling
= BUFFER_FLOOR_OF (start
);
3440 ceiling
= max (limit
, ceiling
);
3441 ceiling_addr
= &FETCH_CHAR (ceiling
) - 1;
3442 base
= (cursor
= &FETCH_CHAR (start
));
3446 while (--cursor
!= ceiling_addr
3447 && *cursor
!= '\n' && *cursor
!= 015)
3449 if (cursor
!= ceiling_addr
)
3454 return (start
+ cursor
- base
+ 1);
3460 start
+= cursor
- base
;
3465 *shortage
= count
* direction
;
3466 return (start
+ ((direction
== 1 ? 0 : 1)));
3469 /* Count up to N lines starting from FROM.
3470 But don't go beyond LIMIT.
3471 Return the number of lines thus found (always positive).
3472 Store the position after what was found into *POS_PTR. */
3475 display_count_lines (from
, limit
, n
, pos_ptr
)
3488 *pos_ptr
= display_scan_buffer (from
, n
, &shortage
);
3494 /* When scanning backwards, scan_buffer stops *after* the last newline
3495 it finds, but does count it. Compensate for that. */
3496 return - n
- shortage
- (*pos_ptr
!= limit
);
3497 return n
- shortage
;
3500 /* Display STRING on one line of window W, starting at HPOS.
3501 Display at position VPOS. Caller should have done get_display_line.
3502 If VPOS == -1, display it as the current frame's title.
3503 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
3505 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
3507 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
3508 MAXCOL is the last column ok to end at. Truncate here.
3509 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
3510 Both count from the left edge of the frame, as does HPOS.
3511 The right edge of W is an implicit maximum.
3512 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
3514 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
3515 at the place where the current window ends in this line
3516 and not display anything beyond there. Otherwise, only MAXCOL
3517 controls where to stop output.
3519 Returns ending hpos. */
3522 display_string (w
, vpos
, string
, length
, hpos
, truncate
,
3523 obey_window_width
, mincol
, maxcol
)
3525 unsigned char *string
;
3529 int obey_window_width
;
3534 int hscroll
= XINT (w
->hscroll
);
3535 int tab_width
= XINT (XBUFFER (w
->buffer
)->tab_width
);
3536 register GLYPH
*start
;
3537 register GLYPH
*end
;
3538 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
3539 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
3540 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
3541 int window_width
= XFASTINT (w
->width
);
3543 /* Use the standard display table, not the window's display table.
3544 We don't want the mode line in rot13. */
3545 register struct Lisp_Vector
*dp
= 0;
3548 if (VECTORP (Vstandard_display_table
)
3549 && XVECTOR (Vstandard_display_table
)->size
== DISP_TABLE_SIZE
)
3550 dp
= XVECTOR (Vstandard_display_table
);
3552 if (tab_width
<= 0 || tab_width
> 1000) tab_width
= 8;
3555 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
3557 if (obey_window_width
)
3559 end
= start
+ window_width
- (truncate
!= 0);
3561 if ((window_width
+ XFASTINT (w
->left
)) != FRAME_WIDTH (f
))
3563 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3567 for (i
= 0; i
< FRAME_SCROLL_BAR_COLS (f
); i
++)
3575 if (! obey_window_width
3576 || (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
))
3577 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
3579 /* Store 0 in charstart for these columns. */
3580 for (i
= (hpos
>= 0 ? hpos
: 0); i
< end
- p1start
+ hpos
; i
++)
3581 desired_glyphs
->charstarts
[vpos
][i
] = 0;
3583 if (maxcol
>= 0 && mincol
> maxcol
)
3591 /* Specified length. */
3594 /* Unspecified length (null-terminated string). */
3598 if (c
>= 040 && c
< 0177
3599 && (dp
== 0 || !VECTORP (DISP_CHAR_VECTOR (dp
, c
))))
3609 if (p1
>= start
&& p1
< end
)
3613 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
3615 else if (dp
!= 0 && VECTORP (DISP_CHAR_VECTOR (dp
, c
)))
3617 p1
= copy_part_of_rope (f
, p1
, start
,
3618 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->contents
,
3619 XVECTOR (DISP_CHAR_VECTOR (dp
, c
))->size
,
3622 else if (c
< 0200 && ! NILP (buffer_defaults
.ctl_arrow
))
3625 *p1
= fix_glyph (f
, (dp
&& INTEGERP (DISP_CTRL_GLYPH (dp
))
3626 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^'),
3629 if (p1
>= start
&& p1
< end
)
3636 *p1
= fix_glyph (f
, (dp
&& INTEGERP (DISP_ESCAPE_GLYPH (dp
))
3637 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\'),
3640 if (p1
>= start
&& p1
< end
)
3641 *p1
= (c
>> 6) + '0';
3643 if (p1
>= start
&& p1
< end
)
3644 *p1
= (7 & (c
>> 3)) + '0';
3646 if (p1
>= start
&& p1
< end
)
3647 *p1
= (7 & c
) + '0';
3652 if (c
&& length
> 0)
3655 if (truncate
) *p1
++ = fix_glyph (f
, truncate
, 0);
3657 else if (mincol
>= 0)
3659 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
3665 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
3667 if (len
> desired_glyphs
->used
[vpos
])
3668 desired_glyphs
->used
[vpos
] = len
;
3669 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
3678 staticpro (&Qmenu_bar_update_hook
);
3679 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
3681 staticpro (&last_arrow_position
);
3682 staticpro (&last_arrow_string
);
3683 last_arrow_position
= Qnil
;
3684 last_arrow_string
= Qnil
;
3686 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
3687 "String (or mode line construct) included (normally) in `mode-line-format'.");
3688 Vglobal_mode_string
= Qnil
;
3690 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
3691 "Marker for where to display an arrow on top of the buffer text.\n\
3692 This must be the beginning of a line in order to work.\n\
3693 See also `overlay-arrow-string'.");
3694 Voverlay_arrow_position
= Qnil
;
3696 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
3697 "String to display as an arrow. See also `overlay-arrow-position'.");
3698 Voverlay_arrow_string
= Qnil
;
3700 DEFVAR_INT ("scroll-step", &scroll_step
,
3701 "*The number of lines to try scrolling a window by when point moves out.\n\
3702 If that fails to bring point back on frame, point is centered instead.\n\
3703 If this is zero, point is always centered after it moves off frame.");
3705 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
3707 DEFVAR_BOOL ("truncate-partial-width-windows",
3708 &truncate_partial_width_windows
,
3709 "*Non-nil means truncate lines in all windows less than full frame wide.");
3710 truncate_partial_width_windows
= 1;
3712 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
3713 "*Non-nil means use inverse video for the mode line.");
3714 mode_line_inverse_video
= 1;
3716 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
3717 "*Maximum buffer size for which line number should be displayed.");
3718 line_number_display_limit
= 1000000;
3720 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
3721 "*Non-nil means highlight region even in nonselected windows.");
3722 highlight_nonselected_windows
= 1;
3724 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
3725 "Non-nil means more than one frame is in use, not counting minibuffer frames.\n\
3726 Not guaranteed to be accurate except while parsing frame-title-format.");
3728 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
3729 "Template for displaying the titlebar of visible frames.\n\
3730 \(Assuming the window manager supports this feature.)\n\
3731 This variable has the same structure as `mode-line-format' (which see),\n\
3732 and is used only on frames for which no explicit name has been set\n\
3733 \(see `modify-frame-parameters').");
3734 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
3735 "Template for displaying the titlebar of an iconified frame.\n\
3736 \(Assuming the window manager supports this feature.)\n\
3737 This variable has the same structure as `mode-line-format' (which see),\n\
3738 and is used only on frames for which no explicit name has been set\n\
3739 \(see `modify-frame-parameters').");
3741 = Vframe_title_format
3742 = Fcons (intern ("multiple-frames"),
3743 Fcons (build_string ("%b"),
3744 Fcons (Fcons (build_string (""),
3745 Fcons (intern ("invocation-name"),
3746 Fcons (build_string ("@"),
3747 Fcons (intern ("system-name"),
3751 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
3752 "Maximum number of lines to keep in the message log buffer.\n\
3753 If nil, disable message logging. If t, log messages but don't truncate\n\
3754 the buffer when it becomes large.");
3755 XSETFASTINT (Vmessage_log_max
, 50);
3758 /* initialize the window system */
3761 Lisp_Object root_window
;
3762 #ifndef COMPILER_REGISTER_BUG
3764 #endif /* COMPILER_REGISTER_BUG */
3765 struct window
*mini_w
;
3767 this_line_bufpos
= 0;
3769 mini_w
= XWINDOW (minibuf_window
);
3770 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
3772 echo_area_glyphs
= 0;
3773 previous_echo_glyphs
= 0;
3775 if (!noninteractive
)
3777 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
3778 XSETFASTINT (XWINDOW (root_window
)->top
, 0);
3779 set_window_height (root_window
, FRAME_HEIGHT (f
) - 1, 0);
3780 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
3781 set_window_height (minibuf_window
, 1, 0);
3783 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
3784 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));