1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988 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 1, 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"
36 extern int interrupt_input
;
37 extern int command_loop_level
;
39 /* Nonzero means print newline before next minibuffer message. */
41 int noninteractive_need_newline
;
43 #define min(a, b) ((a) < (b) ? (a) : (b))
44 #define max(a, b) ((a) > (b) ? (a) : (b))
46 /* The buffer position of the first character appearing
47 entirely or partially on the current screen line.
48 Or zero, which disables the optimization for the current screen line. */
49 static int this_line_bufpos
;
51 /* Number of characters past the end of this line,
52 including the terminating newline */
53 static int this_line_endpos
;
55 /* The vertical position of this screen line. */
56 static int this_line_vpos
;
58 /* Hpos value for start of display on this screen line.
59 Usually zero, but negative if first character really began
61 static int this_line_start_hpos
;
63 /* Buffer that this_line variables are describing. */
64 static struct buffer
*this_line_buffer
;
66 /* Set by try_window_id to the vpos of first of any lines
67 scrolled on to the bottom of the screen. These lines should
68 not be included in any general scroll computation. */
69 static int scroll_bottom_vpos
;
71 /* Value of echo_area_glyphs when it was last acted on.
72 If this is nonzero, there is a message on the screen
73 in the minibuffer and it should be erased as soon
74 as it is no longer requested to appear. */
75 char *previous_echo_glyphs
;
77 /* Nonzero means truncate lines in all windows less wide than the screen */
78 int truncate_partial_width_windows
;
80 Lisp_Object Vglobal_mode_string
;
82 /* Marker for where to display an arrow on top of the buffer text. */
83 Lisp_Object Voverlay_arrow_position
;
85 /* String to display for the arrow. */
86 Lisp_Object Voverlay_arrow_string
;
88 /* Values of those variables at last redisplay. */
89 Lisp_Object last_arrow_position
, last_arrow_string
;
91 /* Nonzero if overlay arrow has been displayed once in this window. */
92 static int overlay_arrow_seen
;
94 /* If cursor motion alone moves point off screen,
95 Try scrolling this many lines up or down if that will bring it back. */
98 /* Nonzero if try_window_id has made blank lines at window bottom
99 since the last redisplay that paused */
100 static int blank_end_of_window
;
102 /* Number of windows showing the buffer of the selected window.
103 keyboard.c refers to this. */
106 /* display_text_line sets these to the screen position (origin 0) of point,
107 whether the window is selected or not.
108 Set one to -1 first to determine whether point was found afterwards. */
110 static int cursor_vpos
;
111 static int cursor_hpos
;
115 /* Nonzero means display mode line highlighted */
116 int mode_line_inverse_video
;
118 static void echo_area_display ();
119 void mark_window_display_accurate ();
120 static void redisplay_windows ();
121 static void redisplay_window ();
122 static void try_window ();
123 static int try_window_id ();
124 static struct position
*display_text_line ();
125 static void display_mode_line ();
126 static int display_mode_element ();
127 static char *fmodetrunc ();
128 static char *decode_mode_spec ();
129 static int display_string ();
131 /* Prompt to display in front of the minibuffer contents */
132 char *minibuf_prompt
;
134 /* Width in columns of current minibuffer prompt. */
135 int minibuf_prompt_width
;
137 /* Message to display instead of minibuffer contents
138 This is what the functions error and message make,
139 and command echoing uses it as well.
140 It overrides the minibuf_prompt as well as the buffer. */
141 char *echo_area_glyphs
;
143 /* true iff we should redraw the mode lines on the next redisplay */
144 int update_mode_lines
;
146 /* Smallest number of characters before the gap
147 at any time since last redisplay that finished.
148 Valid for current buffer when try_window_id can be called. */
151 /* Smallest number of characters after the gap
152 at any time since last redisplay that finished.
153 Valid for current buffer when try_window_id can be called. */
156 /* MODIFF as of last redisplay that finished;
157 if it matches MODIFF, beg_unchanged and end_unchanged
158 contain no useful information */
159 int unchanged_modified
;
161 /* Nonzero if head_clip or tail_clip of current buffer has changed
162 since last redisplay that finished */
165 /* Nonzero if window sizes or contents have changed
166 since last redisplay that finished */
167 int windows_or_buffers_changed
;
172 DEFUN ("redraw-display", Fredraw_display
, Sredraw_display
, 0, 0, "",
173 "Clear the screen and output again what is supposed to appear on it.")
176 if (screen_height
== 0) abort (); /* Some bug zeros some core */
179 clear_screen_records ();
180 if (screen_height
== 0) abort (); /* Some bug zeros some core */
181 windows_or_buffers_changed
++;
182 /* Mark all windows as INaccurate,
183 so that every window will have its redisplay done. */
184 mark_window_display_accurate (XWINDOW (minibuf_window
)->prev
, 0);
185 if (screen_height
== 0) abort (); /* Some bug zeros some core */
189 #endif /* not MULTI_SCREEN */
191 /* Buffer used for messages formatted by `message'. */
194 /* Nonzero if message_buf is being used by print;
195 zero if being used by message. */
196 int message_buf_print
;
198 /* dump an informative message to the minibuf */
202 message (m
, a1
, a2
, a3
)
207 if (noninteractive_need_newline
)
209 noninteractive_need_newline
= 0;
210 fprintf (stderr
, m
, a1
, a2
, a3
);
211 fprintf (stderr
, "\n");
214 /* A null message buffer means that the screen hasn't really been
215 initialized yet. Error messages get reported properly by
216 cmd_error, so this must be just an informative message; toss it. */
217 else if (INTERACTIVE
&& SCREEN_MESSAGE_BUF (selected_screen
))
220 choose_minibuf_screen ();
221 Fmake_screen_visible (WINDOW_SCREEN (XWINDOW (minibuf_window
)));
231 doprnt (SCREEN_MESSAGE_BUF (selected_screen
),
232 SCREEN_WIDTH (selected_screen
), m
, 0, 3, a
);
234 doprnt (SCREEN_MESSAGE_BUF (selected_screen
),
235 SCREEN_WIDTH (selected_screen
), m
, 0, 3, &a1
);
236 #endif /* NO_ARG_ARRAY */
239 echo_area_glyphs
= SCREEN_MESSAGE_BUF (selected_screen
);
241 /* Print should start at the beginning of the message
243 message_buf_print
= 0;
245 do_pending_window_change ();
246 echo_area_display ();
247 update_screen (XSCREEN (XWINDOW (minibuf_window
)->screen
), 1, 1);
248 do_pending_window_change ();
252 /* Specify m, a string, as a message in the minibuf. */
259 if (noninteractive_need_newline
)
261 noninteractive_need_newline
= 0;
262 fprintf (stderr
, "%s\n", m
);
265 /* A null message buffer means that the screen hasn't really been
266 initialized yet. Error messages get reported properly by
267 cmd_error, so this must be just an informative message; toss it. */
268 else if (INTERACTIVE
&& SCREEN_MESSAGE_BUF (selected_screen
))
271 choose_minibuf_screen ();
272 Fmake_screen_visible (WINDOW_SCREEN (XWINDOW (minibuf_window
)));
275 echo_area_glyphs
= m
;
276 do_pending_window_change ();
277 echo_area_display ();
278 update_screen (XSCREEN (XWINDOW (minibuf_window
)->screen
), 1, 1);
279 do_pending_window_change ();
290 choose_minibuf_screen ();
291 s
= XSCREEN (WINDOW_SCREEN (XWINDOW (minibuf_window
)));
293 if (! SCREEN_VISIBLE_P (s
))
303 if (echo_area_glyphs
|| minibuf_level
== 0)
305 vpos
= XFASTINT (XWINDOW (minibuf_window
)->top
);
306 get_display_line (s
, vpos
, 0);
307 display_string (XWINDOW (minibuf_window
), vpos
,
308 echo_area_glyphs
? echo_area_glyphs
: "",
309 0, 0, 0, SCREEN_WIDTH (s
));
311 /* If desired cursor location is on this line, put it at end of text */
312 if (SCREEN_CURSOR_Y (s
) == vpos
)
313 SCREEN_CURSOR_X (s
) = s
->desired_glyphs
->used
[vpos
];
315 else if (!EQ (minibuf_window
, selected_window
))
316 windows_or_buffers_changed
++;
318 if (EQ (minibuf_window
, selected_window
))
319 this_line_bufpos
= 0;
321 previous_echo_glyphs
= echo_area_glyphs
;
324 /* Do a screen update, taking possible shortcuts into account.
325 This is the main external entry point for redisplay.
327 If the last redisplay displayed an echo area message and that
328 message is no longer requested, we clear the echo area
329 or bring back the minibuffer if that is in use.
331 Everyone would like to have a hook here to call eval,
332 but that cannot be done safely without a lot of changes elsewhere.
333 This can be called from signal handlers; with alarms set up;
334 or with synchronous processes running.
335 See the function `echo' in keyboard.c.
336 See Fcall_process; if you called it from here, it could be
337 entered recursively. */
342 register struct window
*w
= XWINDOW (selected_window
);
346 register int tlbufpos
, tlendpos
;
348 extern int input_pending
;
353 /* Notice any pending interrupt request to change screen size. */
354 do_pending_window_change ();
362 /* Normally the message* functions will have already displayed and
363 updated the echo area, but the screen may have been trashed, or
364 the update may have been preempted, so display the echo area
366 if (echo_area_glyphs
|| previous_echo_glyphs
)
368 echo_area_display ();
372 if (clip_changed
|| windows_or_buffers_changed
)
375 /* Detect case that we need to write a star in the mode line. */
376 if (XFASTINT (w
->last_modified
) < MODIFF
377 && XFASTINT (w
->last_modified
) <= current_buffer
->save_modified
)
379 w
->update_mode_line
= Qt
;
380 if (buffer_shared
> 1)
384 SCREEN_SCROLL_BOTTOM_VPOS (XSCREEN (w
->screen
)) = -1;
386 all_windows
= update_mode_lines
|| buffer_shared
> 1;
388 /* If specs for an arrow have changed, do thorough redisplay
389 to ensure we remove any arrow that should no longer exist. */
390 if (Voverlay_arrow_position
!= last_arrow_position
391 || Voverlay_arrow_string
!= last_arrow_string
)
392 all_windows
= 1, clip_changed
= 1;
394 tlbufpos
= this_line_bufpos
;
395 tlendpos
= this_line_endpos
;
396 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
397 && SCREEN_VISIBLE_P (XSCREEN (w
->screen
))
398 /* Make sure recorded data applies to current buffer, etc */
399 && this_line_buffer
== current_buffer
400 && current_buffer
== XBUFFER (w
->buffer
)
401 && NILP (w
->force_start
)
402 /* Point must be on the line that we have info recorded about */
404 && point
<= Z
- tlendpos
405 /* All text outside that line, including its final newline,
407 && (XFASTINT (w
->last_modified
) >= MODIFF
408 || (beg_unchanged
>= tlbufpos
- 1
410 && end_unchanged
>= tlendpos
411 && Z
- GPT
>= tlendpos
)))
413 if (tlbufpos
> BEGV
&& FETCH_CHAR (tlbufpos
- 1) != '\n'
415 || FETCH_CHAR (tlbufpos
) == '\n'))
416 /* Former continuation line has disappeared by becoming empty */
418 else if (XFASTINT (w
->last_modified
) < MODIFF
419 || MINI_WINDOW_P (w
))
422 overlay_arrow_seen
= 0;
423 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
424 pos_tab_offset (w
, tlbufpos
));
425 /* If line contains point, is not continued,
426 and ends at same distance from eob as before, we win */
427 if (cursor_vpos
>= 0 && this_line_bufpos
428 && this_line_endpos
== tlendpos
)
430 if (XFASTINT (w
->width
) != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
431 preserve_other_columns (w
);
437 else if (point
== XFASTINT (w
->last_point
))
441 do_pending_window_change ();
448 pos
= *compute_motion (tlbufpos
, 0,
449 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
450 point
, 2, - (1 << (SHORTBITS
- 1)),
451 XFASTINT (w
->width
) - 1
452 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
453 != SCREEN_WIDTH (selected_screen
)),
454 XINT (w
->hscroll
), 0);
457 SCREEN_CURSOR_X (selected_screen
)
458 = XFASTINT (w
->left
) + max (pos
.hpos
, 0);
459 SCREEN_CURSOR_Y (selected_screen
) = this_line_vpos
;
466 /* Text changed drastically or point moved off of line */
467 cancel_line (this_line_vpos
, selected_screen
);
470 this_line_bufpos
= 0;
471 all_windows
|= buffer_shared
> 1;
478 /* Recompute # windows showing selected buffer.
479 This will be incremented each time such a window is displayed. */
482 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
486 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
489 s
= XSCREEN (XCONS (tail
)->car
);
491 /* Redraw its windows. */
492 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
495 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
496 #endif /* not MULTI_SCREEN */
498 else if (SCREEN_VISIBLE_P (selected_screen
))
500 redisplay_window (selected_window
, 1);
501 if (XFASTINT (w
->width
) != SCREEN_WIDTH (selected_screen
))
502 preserve_other_columns (w
);
506 /* Prevent various kinds of signals during display update.
507 stdio is not robust about handling signals,
508 which can cause an apparent I/O error. */
520 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
524 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
527 s
= XSCREEN (XCONS (tail
)->car
);
530 pause
|= update_screen (s
, 0, 0);
532 mark_window_display_accurate (s
->root_window
, 1);
537 #endif /* MULTI_SCREEN */
539 if (SCREEN_VISIBLE_P (selected_screen
))
540 pause
= update_screen (selected_screen
, 0, 0);
542 /* We may have called echo_area_display at the top of this
543 function. If the echo area is on another screen, that may
544 have put text on a screen other than the selected one, so the
545 above call to update_screen would not have caught it. Catch
548 SCREEN_PTR mini_screen
=
549 XSCREEN (WINDOW_SCREEN (XWINDOW (minibuf_window
)));
551 if (mini_screen
!= selected_screen
)
552 pause
|= update_screen (mini_screen
, 0, 0);
557 /* If screen does not match, prevent doing single-line-update next time.
558 Also, don't forget to check every line to update the arrow. */
561 this_line_bufpos
= 0;
562 if (!NILP (last_arrow_position
))
564 last_arrow_position
= Qt
;
565 last_arrow_string
= Qt
;
567 /* If we pause after scrolling, some lines in current_screen
568 may be null, so preserve_other_columns won't be able to
569 preserve all the vertical-bar separators. So, avoid using it
571 if (XFASTINT (w
->width
) != SCREEN_WIDTH (selected_screen
))
572 update_mode_lines
= 1;
575 /* Now text on screen agrees with windows, so
576 put info into the windows for partial redisplay to follow */
580 register struct buffer
*b
= XBUFFER (w
->buffer
);
582 blank_end_of_window
= 0;
584 unchanged_modified
= BUF_MODIFF (b
);
585 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
586 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
588 XFASTINT (w
->last_point
) = BUF_PT (b
);
589 XFASTINT (w
->last_point_x
) = SCREEN_CURSOR_X (selected_screen
);
590 XFASTINT (w
->last_point_y
) = SCREEN_CURSOR_Y (selected_screen
);
593 mark_window_display_accurate (XWINDOW (minibuf_window
)->prev
, 1);
596 w
->update_mode_line
= Qnil
;
597 XFASTINT (w
->last_modified
) = BUF_MODIFF (b
);
598 w
->window_end_valid
= Qt
;
599 last_arrow_position
= Voverlay_arrow_position
;
600 last_arrow_string
= Voverlay_arrow_string
;
602 update_mode_lines
= 0;
603 windows_or_buffers_changed
= 0;
606 /* Start SIGIO interrupts coming again.
607 Having them off during the code above
608 makes it less likely one will discard output,
609 but not impossible, since there might be stuff
610 in the system buffer here.
611 But it is much hairier to try to do anything about that. */
617 /* Change screen size now if a change is pending. */
618 do_pending_window_change ();
621 /* Redisplay, but leave alone any recent echo area message
622 unless another message has been requested in its place.
624 This is useful in situations where you need to redisplay but no
625 user action has occurred, making it inappropriate for the message
626 area to be cleared. See tracking_off and
627 wait_reading_process_input for examples of these situations. */
629 redisplay_preserve_echo_area ()
631 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
633 echo_area_glyphs
= previous_echo_glyphs
;
635 echo_area_glyphs
= 0;
642 mark_window_display_accurate (window
, flag
)
646 register struct window
*w
;
648 for (;!NILP (window
); window
= w
->next
)
650 w
= XWINDOW (window
);
652 if (!NILP (w
->buffer
))
653 XFASTINT (w
->last_modified
)
655 : XBUFFER (w
->buffer
) == current_buffer
656 ? MODIFF
: BUF_MODIFF (XBUFFER (w
->buffer
));
657 w
->window_end_valid
= Qt
;
658 w
->update_mode_line
= Qnil
;
660 if (!NILP (w
->vchild
))
661 mark_window_display_accurate (w
->vchild
, flag
);
662 if (!NILP (w
->hchild
))
663 mark_window_display_accurate (w
->hchild
, flag
);
668 last_arrow_position
= Voverlay_arrow_position
;
669 last_arrow_string
= Voverlay_arrow_string
;
673 /* t is unequal to any useful value of Voverlay_arrow_... */
674 last_arrow_position
= Qt
;
675 last_arrow_string
= Qt
;
682 redisplay_windows (window
)
685 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
686 redisplay_window (window
, 0);
690 redisplay_window (window
, just_this_one
)
694 register struct window
*w
= XWINDOW (window
);
695 SCREEN_PTR s
= XSCREEN (w
->screen
);
697 register int lpoint
= point
;
698 struct buffer
*old
= current_buffer
;
699 register int width
= XFASTINT (w
->width
) - 1
700 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
701 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))));
703 register int hscroll
= XINT (w
->hscroll
);
707 int window_needs_modeline
;
709 if (SCREEN_HEIGHT (s
) == 0) abort (); /* Some bug zeros some core */
711 /* If this is a combination window, do its children; that's all. */
713 if (!NILP (w
->vchild
))
715 redisplay_windows (w
->vchild
);
718 if (!NILP (w
->hchild
))
720 redisplay_windows (w
->hchild
);
723 if (NILP (w
->buffer
))
726 height
= window_internal_height (w
);
728 if (MINI_WINDOW_P (w
))
730 if (w
== XWINDOW (minibuf_window
))
732 if (echo_area_glyphs
)
733 /* We've already displayed the echo area glyphs, if any. */
738 /* This is a minibuffer, but it's not the currently active one, so
740 int vpos
= XFASTINT (XWINDOW (SCREEN_MINIBUF_WINDOW (s
))->top
);
743 for (i
= 0; i
< height
; i
++)
745 get_display_line (s
, vpos
+ i
, 0);
746 display_string (w
, vpos
+ i
, "", 0, 0, 0, width
);
753 if (update_mode_lines
)
754 w
->update_mode_line
= Qt
;
756 /* Otherwise set up data on this window; select its buffer and point value */
758 current_buffer
= XBUFFER (w
->buffer
);
761 /* Count number of windows showing the selected buffer. */
764 && current_buffer
== XBUFFER (XWINDOW (selected_window
)->buffer
))
767 /* POINT refers normally to the selected window.
768 For any other window, set up appropriate value. */
770 if (!EQ (window
, selected_window
))
772 SET_PT (marker_position (w
->pointm
));
776 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
778 else if (point
> (ZV
- 1))
781 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
785 /* If window-start is screwed up, choose a new one. */
786 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
789 startp
= marker_position (w
->start
);
791 /* Handle case where place to start displaying has been specified,
792 unless the specified location is outside the visible range. */
793 if (!NILP (w
->force_start
))
795 w
->update_mode_line
= Qt
;
796 w
->force_start
= Qnil
;
797 XFASTINT (w
->last_modified
) = 0;
798 if (startp
< BEGV
) startp
= BEGV
;
799 if (startp
> ZV
) startp
= ZV
;
800 try_window (window
, startp
);
803 /* If point does not appear, move point so it does appear */
804 pos
= *compute_motion (startp
, 0,
805 ((EQ (window
, minibuf_window
) && startp
== 1)
806 ? minibuf_prompt_width
: 0)
808 (hscroll
? 1 - hscroll
: 0),
810 - (1 << (SHORTBITS
- 1)),
811 width
, hscroll
, pos_tab_offset (w
, startp
));
813 if (w
!= XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
814 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
818 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
819 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
825 /* Handle case where text has not changed, only point,
826 and it has not moved off the screen */
828 /* This code is not used for minibuffer for the sake of
829 the case of redisplaying to replace an echo area message;
830 since in that case the minibuffer contents per se are usually unchanged.
831 This code is of no real use in the minibuffer since
832 the handling of this_line_bufpos, etc.,
833 in redisplay handles the same cases. */
835 if (XFASTINT (w
->last_modified
) >= MODIFF
836 && point
>= startp
&& !clip_changed
837 && (just_this_one
|| XFASTINT (w
->width
) == SCREEN_WIDTH (s
))
838 && !EQ (window
, minibuf_window
))
840 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0),
841 point
, height
+ 1, 10000, width
, hscroll
,
842 pos_tab_offset (w
, startp
));
844 if (pos
.vpos
< height
)
846 /* Ok, point is still on screen */
847 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
849 /* These variables are supposed to be origin 1 */
850 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
851 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
853 /* This doesn't do the trick, because if a window to the right of
854 this one must be redisplayed, this does nothing because there
855 is nothing in DesiredScreen yet, and then the other window is
856 redisplayed, making likes that are empty in this window's columns.
857 if (XFASTINT (w->width) != SCREEN_WIDTH (s))
858 preserve_my_columns (w);
862 /* Don't bother trying redisplay with same start;
863 we already know it will lose */
865 /* If current starting point was originally the beginning of a line
866 but no longer is, find a new starting point. */
867 else if (!NILP (w
->start_at_line_beg
)
869 || FETCH_CHAR (startp
- 1) == '\n'))
873 else if (just_this_one
&& !MINI_WINDOW_P (w
)
875 && XFASTINT (w
->last_modified
)
876 && ! EQ (w
->window_end_valid
, Qnil
)
877 && do_id
&& !clip_changed
878 && !blank_end_of_window
879 && XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
880 && EQ (last_arrow_position
, Voverlay_arrow_position
)
881 && EQ (last_arrow_string
, Voverlay_arrow_string
)
882 && (tem
= try_window_id (SCREEN_SELECTED_WINDOW (s
)))
885 /* tem > 0 means success. tem == -1 means choose new start.
886 tem == -2 means try again with same start,
887 and nothing but whitespace follows the changed stuff.
888 tem == 0 means try again with same start. */
892 else if (startp
>= BEGV
&& startp
<= ZV
893 /* Avoid starting display at end of buffer! */
894 && (startp
< ZV
|| startp
== BEGV
895 || (XFASTINT (w
->last_modified
) >= MODIFF
)))
897 /* Try to redisplay starting at same place as before */
898 /* If point has not moved off screen, accept the results */
899 try_window (window
, startp
);
900 if (cursor_vpos
>= 0)
903 cancel_my_columns (w
);
906 XFASTINT (w
->last_modified
) = 0;
907 w
->update_mode_line
= Qt
;
909 /* Try to scroll by specified few lines */
911 if (scroll_step
&& !clip_changed
)
915 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
916 scroll_step
, width
, hscroll
, window
);
917 if (pos
.vpos
>= height
)
921 pos
= *vmotion (startp
, point
< startp
? - scroll_step
: scroll_step
,
922 width
, hscroll
, window
);
924 if (point
>= pos
.bufpos
)
926 try_window (window
, pos
.bufpos
);
927 if (cursor_vpos
>= 0)
930 cancel_my_columns (w
);
935 /* Finally, just choose place to start which centers point */
938 pos
= *vmotion (point
, - height
/ 2, width
, hscroll
, window
);
939 try_window (window
, pos
.bufpos
);
941 startp
= marker_position (w
->start
);
942 w
->start_at_line_beg
=
943 (startp
== BEGV
|| FETCH_CHAR (startp
- 1) == '\n') ? Qt
: Qnil
;
946 /* If window not full width, must redo its mode line
947 if the window to its side is being redone */
948 if ((!NILP (w
->update_mode_line
)
949 || (!just_this_one
&& width
< SCREEN_WIDTH (s
) - 1))
950 && height
!= XFASTINT (w
->height
))
951 display_mode_line (w
);
954 current_buffer
= old
;
958 /* Do full redisplay on one window, starting at position `pos'. */
961 try_window (window
, pos
)
965 register struct window
*w
= XWINDOW (window
);
966 register int height
= window_internal_height (w
);
967 register int vpos
= XFASTINT (w
->top
);
968 register int last_text_vpos
= vpos
;
969 int tab_offset
= pos_tab_offset (w
, pos
);
970 SCREEN_PTR s
= XSCREEN (w
->screen
);
971 int width
= XFASTINT (w
->width
) - 1
972 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
975 Fset_marker (w
->start
, make_number (pos
), Qnil
);
977 overlay_arrow_seen
= 0;
978 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
980 while (--height
>= 0)
982 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, tab_offset
);
984 if (val
.vpos
) tab_offset
= 0;
986 if (pos
!= val
.bufpos
)
988 /* Next line, unless prev line ended in end of buffer with no cr */
989 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
993 /* If last line is continued in middle of character,
994 include the split character in the text considered on the screen */
995 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
998 /* If bottom just moved off end of screen, change mode line percentage. */
999 if (XFASTINT (w
->window_end_pos
) == 0
1001 w
->update_mode_line
= Qt
;
1003 /* Say where last char on screen will be, once redisplay is finished. */
1004 XFASTINT (w
->window_end_pos
) = Z
- pos
;
1005 XFASTINT (w
->window_end_vpos
) = last_text_vpos
- XFASTINT (w
->top
);
1006 /* But that is not valid info until redisplay finishes. */
1007 w
->window_end_valid
= Qnil
;
1010 /* Try to redisplay when buffer is modified locally,
1011 computing insert/delete line to preserve text outside
1012 the bounds of the changes.
1013 Return 1 if successful, 0 if if cannot tell what to do,
1014 or -1 to tell caller to find a new window start,
1015 or -2 to tell caller to do normal redisplay with same window start. */
1018 try_window_id (window
)
1022 register struct window
*w
= XWINDOW (window
);
1023 register int height
= window_internal_height (w
);
1024 SCREEN_PTR s
= XSCREEN (w
->screen
);
1025 int top
= XFASTINT (w
->top
);
1026 int start
= marker_position (w
->start
);
1027 int width
= XFASTINT (w
->width
) - 1
1028 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
1029 int hscroll
= XINT (w
->hscroll
);
1030 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
1032 register int i
, tem
;
1033 int last_text_vpos
= 0;
1036 struct position val
, bp
, ep
, xp
, pp
;
1037 int scroll_amount
= 0;
1039 int tab_offset
, epto
;
1041 if (GPT
- BEG
< beg_unchanged
)
1042 beg_unchanged
= GPT
- BEG
;
1043 if (Z
- GPT
< end_unchanged
)
1044 end_unchanged
= Z
- GPT
;
1046 if (beg_unchanged
+ 1 < start
)
1047 return 0; /* Give up if changes go above top of window */
1049 /* Find position before which nothing is changed. */
1050 bp
= *compute_motion (start
, 0, lmargin
,
1051 beg_unchanged
+ 1, height
+ 1, 0, width
, hscroll
,
1052 pos_tab_offset (w
, start
));
1053 if (bp
.vpos
>= height
)
1055 if (point
< bp
.bufpos
&& !bp
.contin
)
1057 /* All changes are below the screen, and point is on the screen.
1058 We don't need to change the screen at all.
1059 But we need to update window_end_pos to account for
1060 any change in buffer size. */
1061 bp
= *compute_motion (start
, 0, lmargin
,
1063 width
, hscroll
, pos_tab_offset (w
, start
));
1064 XFASTINT (w
->window_end_vpos
) = height
;
1065 XFASTINT (w
->window_end_pos
) = Z
- bp
.bufpos
;
1073 /* Find beginning of that screen line. Must display from there. */
1074 bp
= *vmotion (bp
.bufpos
, 0, width
, hscroll
, window
);
1081 /* If about to start displaying at the beginning of a continuation line,
1082 really start with previous screen line, in case it was not
1083 continued when last redisplayed */
1084 if (bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
1086 bp
= *vmotion (bp
.bufpos
, -1, width
, hscroll
, window
);
1091 if (bp
.contin
&& bp
.hpos
!= lmargin
)
1093 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
1099 /* Find first visible newline after which no more is changed. */
1100 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
1101 if (XTYPE (current_buffer
->selective_display
) == Lisp_Int
1102 && XINT (current_buffer
->selective_display
) > 0)
1104 && (position_indentation (tem
)
1105 >= XINT (current_buffer
->selective_display
)))
1106 tem
= find_next_newline (tem
, 1);
1108 /* Compute the cursor position after that newline. */
1109 ep
= *compute_motion (pos
, vpos
, val
.hpos
, tem
,
1110 height
, - (1 << (SHORTBITS
- 1)),
1111 width
, hscroll
, pos_tab_offset (w
, bp
.bufpos
));
1113 /* If changes reach past the text available on the screen,
1114 just display rest of screen. */
1115 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
1118 stop_vpos
= ep
.vpos
;
1120 /* If no newline before ep, the line ep is on includes some changes
1121 that must be displayed. Make sure we don't stop before it. */
1122 /* Also, if changes reach all the way until ep.bufpos,
1123 it is possible that something was deleted after the
1124 newline before it, so the following line must be redrawn. */
1125 if (stop_vpos
== ep
.vpos
1126 && (ep
.bufpos
== BEGV
1127 || FETCH_CHAR (ep
.bufpos
- 1) != '\n'
1128 || ep
.bufpos
== Z
- end_unchanged
))
1129 stop_vpos
= ep
.vpos
+ 1;
1132 overlay_arrow_seen
= 0;
1134 /* If changes do not reach to bottom of window,
1135 figure out how much to scroll the rest of the window */
1136 if (stop_vpos
< height
)
1138 /* Now determine how far up or down the rest of the window has moved */
1139 epto
= pos_tab_offset (w
, ep
.bufpos
);
1140 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1141 Z
- XFASTINT (w
->window_end_pos
),
1142 10000, 0, width
, hscroll
, epto
);
1143 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
1145 /* Is everything on screen below the changes whitespace?
1146 If so, no scrolling is really necessary. */
1147 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
1149 tem
= FETCH_CHAR (i
);
1150 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
1156 XFASTINT (w
->window_end_vpos
) += scroll_amount
;
1158 /* Before doing any scrolling, verify that point will be on screen. */
1159 if (point
> ep
.bufpos
&& !(point
<= xp
.bufpos
&& xp
.bufpos
< height
))
1161 if (point
<= xp
.bufpos
)
1163 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1164 point
, height
, - (1 << (SHORTBITS
- 1)),
1165 width
, hscroll
, epto
);
1169 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
,
1170 point
, height
, - (1 << (SHORTBITS
- 1)),
1171 width
, hscroll
, pos_tab_offset (w
, xp
.bufpos
));
1173 if (pp
.bufpos
< point
|| pp
.vpos
== height
)
1175 cursor_vpos
= pp
.vpos
+ top
;
1176 cursor_hpos
= pp
.hpos
+ XFASTINT (w
->left
);
1179 if (stop_vpos
- scroll_amount
>= height
1180 || ep
.bufpos
== xp
.bufpos
)
1182 if (scroll_amount
< 0)
1183 stop_vpos
-= scroll_amount
;
1185 /* In this path, we have altered window_end_vpos
1186 and not left it negative.
1187 We must make sure that, in case display is preempted
1188 before the screen changes to reflect what we do here,
1189 further updates will not come to try_window_id
1190 and assume the screen and window_end_vpos match. */
1191 blank_end_of_window
= 1;
1193 else if (!scroll_amount
)
1195 else if (bp
.bufpos
== Z
- end_unchanged
)
1197 /* If reprinting everything is nearly as fast as scrolling,
1198 don't bother scrolling. Can happen if lines are short. */
1199 if (scroll_cost (s
, bp
.vpos
+ top
- scroll_amount
,
1200 top
+ height
- max (0, scroll_amount
),
1202 > xp
.bufpos
- bp
.bufpos
- 20)
1203 /* Return "try normal display with same window-start."
1204 Too bad we can't prevent further scroll-thinking. */
1206 /* If pure deletion, scroll up as many lines as possible.
1207 In common case of killing a line, this can save the
1208 following line from being overwritten by scrolling
1209 and therefore having to be redrawn. */
1210 tem
= scroll_screen_lines (s
, bp
.vpos
+ top
- scroll_amount
,
1211 top
+ height
- max (0, scroll_amount
),
1213 if (!tem
) stop_vpos
= height
;
1215 else if (scroll_amount
)
1217 /* If reprinting everything is nearly as fast as scrolling,
1218 don't bother scrolling. Can happen if lines are short. */
1219 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1220 overestimate of cost of reprinting, since xp.bufpos
1221 would end up below the bottom of the window. */
1222 if (scroll_cost (s
, ep
.vpos
+ top
- scroll_amount
,
1223 top
+ height
- max (0, scroll_amount
),
1225 > xp
.bufpos
- ep
.bufpos
- 20)
1226 /* Return "try normal display with same window-start."
1227 Too bad we can't prevent further scroll-thinking. */
1229 tem
= scroll_screen_lines (s
, ep
.vpos
+ top
- scroll_amount
,
1230 top
+ height
- max (0, scroll_amount
),
1232 if (!tem
) stop_vpos
= height
;
1236 /* In any case, do not display past bottom of window */
1237 if (stop_vpos
>= height
)
1243 /* Handle case where pos is before w->start --
1244 can happen if part of line had been clipped and is not clipped now */
1245 if (vpos
== 0 && pos
< marker_position (w
->start
))
1246 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1248 /* Redisplay the lines where the text was changed */
1249 last_text_vpos
= vpos
;
1250 tab_offset
= pos_tab_offset (w
, pos
);
1251 /* If we are starting display in mid-character, correct tab_offset
1252 to account for passing the line that that character really starts in. */
1253 if (val
.hpos
< lmargin
)
1254 tab_offset
+= width
;
1255 while (vpos
< stop_vpos
)
1257 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1258 tab_offset
+= width
;
1259 if (val
.vpos
) tab_offset
= 0;
1260 if (pos
!= val
.bufpos
)
1262 /* Next line, unless prev line ended in end of buffer with no cr */
1263 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
1267 /* There are two cases:
1268 1) we have displayed down to the bottom of the window
1269 2) we have scrolled lines below stop_vpos by scroll_amount */
1273 /* If last line is continued in middle of character,
1274 include the split character in the text considered on the screen */
1275 if (val
.hpos
< lmargin
)
1277 XFASTINT (w
->window_end_vpos
) = last_text_vpos
;
1278 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1281 /* If scrolling made blank lines at window bottom,
1282 redisplay to fill those lines */
1283 if (scroll_amount
< 0)
1285 /* Don't consider these lines for general-purpose scrolling.
1286 That will save time in the scrolling computation. */
1287 SCREEN_SCROLL_BOTTOM_VPOS (s
) = xp
.vpos
;
1292 vpos
= height
+ scroll_amount
;
1293 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
1295 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
1299 blank_end_of_window
= 1;
1300 tab_offset
= pos_tab_offset (w
, pos
);
1301 /* If we are starting display in mid-character, correct tab_offset
1302 to account for passing the line that that character starts in. */
1303 if (val
.hpos
< lmargin
)
1304 tab_offset
+= width
;
1306 while (vpos
< height
)
1308 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1309 tab_offset
+= width
;
1310 if (val
.vpos
) tab_offset
= 0;
1314 /* Here is a case where display_text_line sets cursor_vpos wrong.
1315 Make it be fixed up, below. */
1317 && xp
.bufpos
== point
)
1321 /* If bottom just moved off end of screen, change mode line percentage. */
1322 if (XFASTINT (w
->window_end_pos
) == 0
1324 w
->update_mode_line
= Qt
;
1326 /* Attempt to adjust end-of-text positions to new bottom line */
1329 delta
= height
- xp
.vpos
;
1331 || (delta
> 0 && xp
.bufpos
<= ZV
)
1332 || (delta
== 0 && xp
.hpos
))
1334 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
1335 delta
, width
, hscroll
, window
);
1336 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1337 XFASTINT (w
->window_end_vpos
) += val
.vpos
;
1341 w
->window_end_valid
= Qnil
;
1343 /* If point was not in a line that was displayed, find it */
1344 if (cursor_vpos
< 0)
1346 val
= *compute_motion (start
, 0, lmargin
, point
, 10000, 10000,
1347 width
, hscroll
, pos_tab_offset (w
, start
));
1348 /* Admit failure if point is off screen now */
1349 if (val
.vpos
>= height
)
1351 for (vpos
= 0; vpos
< height
; vpos
++)
1352 cancel_line (vpos
+ top
, s
);
1355 cursor_vpos
= val
.vpos
+ top
;
1356 cursor_hpos
= val
.hpos
+ XFASTINT (w
->left
);
1359 SCREEN_CURSOR_X (s
) = max (0, cursor_hpos
);
1360 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1364 val
= *compute_motion (start
, 0, lmargin
, ZV
,
1365 height
, - (1 << (SHORTBITS
- 1)),
1366 width
, hscroll
, pos_tab_offset (w
, start
));
1367 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
1369 if (XFASTINT (w
->window_end_pos
)
1377 /* Copy glyphs from the rope FROM to T.
1378 But don't actually copy the parts that would come in before S.
1379 Value is T, advanced past the copied data.
1381 Characters in FROM are grouped into units of `sizeof GLYPH' chars;
1382 any extra chars at the end of FROM are ignored. */
1385 copy_rope (t
, s
, from
)
1386 register GLYPH
*t
; /* Copy to here. */
1387 register GLYPH
*s
; /* Starting point. */
1388 Lisp_Object from
; /* Data to copy; known to be a string. */
1390 register int n
= XSTRING (from
)->size
/ sizeof (GLYPH
);
1391 register GLYPH
*f
= (GLYPH
*) XSTRING (from
)->data
;
1395 if (t
>= s
) *t
= *f
;
1402 /* Display one line of window w, starting at position START in W's buffer.
1403 Display starting at horizontal position HPOS, which is normally zero
1404 or negative. A negative value causes output up to hpos = 0 to be discarded.
1405 This is done for negative hscroll, or when this is a continuation line
1406 and the continuation occurred in the middle of a multi-column character.
1408 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
1410 Display on position VPOS on the screen. (origin 0).
1412 Returns a STRUCT POSITION giving character to start next line with
1413 and where to display it, including a zero or negative hpos.
1414 The vpos field is not really a vpos; it is 1 unless the line is continued */
1416 struct position val_display_text_line
;
1418 static struct position
*
1419 display_text_line (w
, start
, vpos
, hpos
, taboffset
)
1426 register int pos
= start
;
1431 register unsigned char *p
;
1433 register GLYPH
*startp
;
1434 register GLYPH
*p1prev
;
1435 SCREEN_PTR s
= XSCREEN (w
->screen
);
1436 int tab_width
= XINT (current_buffer
->tab_width
);
1437 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
1438 int width
= XFASTINT (w
->width
) - 1
1439 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
1440 struct position val
;
1443 int hscroll
= XINT (w
->hscroll
);
1444 int truncate
= hscroll
1445 || (truncate_partial_width_windows
1446 && XFASTINT (w
->width
) < SCREEN_WIDTH (s
))
1447 || !NILP (current_buffer
->truncate_lines
);
1449 = XTYPE (current_buffer
->selective_display
) == Lisp_Int
1450 ? XINT (current_buffer
->selective_display
)
1451 : !NILP (current_buffer
->selective_display
) ? -1 : 0;
1453 int selective_e
= selective
&& !NILP (current_buffer
->selective_display_ellipses
);
1455 register struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (s
);
1456 register struct Lisp_Vector
*dp
= window_display_table (w
);
1458 = (selective
&& dp
&& XTYPE (DISP_INVIS_ROPE (dp
)) == Lisp_String
1459 ? XSTRING (DISP_INVIS_ROPE (dp
))->size
/ sizeof (GLYPH
) : 0);
1460 GLYPH truncator
= (dp
== 0 || XTYPE (DISP_TRUNC_GLYPH (dp
)) != Lisp_Int
1461 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
1462 GLYPH continuer
= (dp
== 0 || XTYPE (DISP_CONTINUE_GLYPH (dp
)) != Lisp_Int
1463 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
1465 hpos
+= XFASTINT (w
->left
);
1466 get_display_line (s
, vpos
, XFASTINT (w
->left
));
1467 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
1469 if (MINI_WINDOW_P (w
) && start
== 1
1470 && vpos
== XFASTINT (w
->top
))
1473 hpos
= display_string (w
, vpos
, minibuf_prompt
, hpos
,
1474 (!truncate
? continuer
: truncator
),
1476 minibuf_prompt_width
= hpos
;
1479 desired_glyphs
->bufp
[vpos
] = pos
;
1480 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
1482 startp
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
1483 endp
= startp
+ width
;
1485 /* Loop generating characters.
1486 Stop at end of buffer, before newline,
1487 or if reach or pass continuation column. */
1497 if (pos
== point
&& cursor_vpos
< 0)
1500 cursor_hpos
= p1
- startp
;
1504 if (pos
< point
&& point
< pause
)
1506 if (pos
< GPT
&& GPT
< pause
)
1509 p
= &FETCH_CHAR (pos
);
1512 if (c
>= 040 && c
< 0177
1513 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
1524 && position_indentation (pos
+ 1) >= selective
)
1527 pos
= find_next_newline (pos
+ 1, 1);
1528 if (FETCH_CHAR (pos
- 1) == '\n')
1531 if (invis
&& selective_rlen
> 0 && p1
>= startp
)
1533 p1
+= selective_rlen
;
1534 if (p1
- startp
> width
)
1536 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1537 (p1
- p1prev
) * sizeof (GLYPH
));
1545 if (p1
>= startp
&& p1
< endp
)
1549 while ((p1
- startp
+ taboffset
+ hscroll
- (hscroll
> 0))
1552 else if (c
== Ctl ('M') && selective
== -1)
1554 pos
= find_next_newline (pos
, 1);
1555 if (FETCH_CHAR (pos
- 1) == '\n')
1557 if (selective_rlen
> 0)
1559 p1
+= selective_rlen
;
1560 if (p1
- startp
> width
)
1562 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1563 (p1
- p1prev
) * sizeof (GLYPH
));
1567 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
1569 p1
= copy_rope (p1
, startp
, DISP_CHAR_ROPE (dp
, c
));
1571 else if (c
< 0200 && ctl_arrow
)
1574 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
1575 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
1577 if (p1
>= startp
&& p1
< endp
)
1584 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
1585 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
1587 if (p1
>= startp
&& p1
< endp
)
1588 *p1
= (c
>> 6) + '0';
1590 if (p1
>= startp
&& p1
< endp
)
1591 *p1
= (7 & (c
>> 3)) + '0';
1593 if (p1
>= startp
&& p1
< endp
)
1594 *p1
= (7 & c
) + '0';
1600 val
.hpos
= - XINT (w
->hscroll
);
1608 /* Handle continuation in middle of a character */
1609 /* by backing up over it */
1612 /* Start the next line with that same character */
1614 /* but at a negative hpos, to skip the columns output on this line. */
1615 val
.hpos
+= p1prev
- endp
;
1616 /* Keep in this line everything up to the continuation column. */
1620 /* Finish deciding which character to start the next line on,
1621 and what hpos to start it at.
1622 Also set `lastpos' to the last position which counts as "on this line"
1623 for cursor-positioning. */
1627 if (FETCH_CHAR (pos
) == '\n')
1628 /* If stopped due to a newline, start next line after it */
1631 /* Stopped due to right margin of window */
1636 /* Truncating => start next line after next newline,
1637 and point is on this line if it is before the newline,
1638 and skip none of first char of next line */
1639 pos
= find_next_newline (pos
, 1);
1640 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
1642 lastpos
= pos
- (FETCH_CHAR (pos
- 1) == '\n');
1653 /* If point is at eol or in invisible text at eol,
1654 record its screen location now. */
1656 if (start
<= point
&& point
<= lastpos
&& cursor_vpos
< 0)
1659 cursor_hpos
= p1
- startp
;
1662 if (cursor_vpos
== vpos
)
1664 if (cursor_hpos
< 0) cursor_hpos
= 0;
1665 if (cursor_hpos
> width
) cursor_hpos
= width
;
1666 cursor_hpos
+= XFASTINT (w
->left
);
1667 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
1669 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1670 SCREEN_CURSOR_X (s
) = cursor_hpos
;
1672 if (w
== XWINDOW (selected_window
))
1674 /* Line is not continued and did not start
1675 in middle of character */
1676 if ((hpos
- XFASTINT (w
->left
)
1677 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1680 this_line_bufpos
= start
;
1681 this_line_buffer
= current_buffer
;
1682 this_line_vpos
= cursor_vpos
;
1683 this_line_start_hpos
= hpos
;
1684 this_line_endpos
= Z
- lastpos
;
1687 this_line_bufpos
= 0;
1692 /* If hscroll and line not empty, insert truncation-at-left marker */
1693 if (hscroll
&& lastpos
!= start
)
1695 *startp
= truncator
;
1700 if (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
))
1703 if (p1
< startp
) p1
= startp
;
1704 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
1707 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
1708 p1
- desired_glyphs
->glyphs
[vpos
]);
1709 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
1711 /* If the start of this line is the overlay arrow-position,
1712 then put the arrow string into the display-line. */
1714 if (XTYPE (Voverlay_arrow_position
) == Lisp_Marker
1715 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
1716 && start
== marker_position (Voverlay_arrow_position
)
1717 && XTYPE (Voverlay_arrow_string
) == Lisp_String
1718 && ! overlay_arrow_seen
)
1720 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
1722 int len
= XSTRING (Voverlay_arrow_string
)->size
;
1724 if (len
> XFASTINT (w
->width
) - 1)
1725 len
= XFASTINT (w
->width
) - 1;
1726 for (i
= 0; i
< len
; i
++)
1728 if (desired_glyphs
->used
[vpos
] <
1729 (len
+ startp
- desired_glyphs
->glyphs
[vpos
]))
1730 desired_glyphs
->used
[vpos
] = len
+ startp
- desired_glyphs
->glyphs
[vpos
];
1732 overlay_arrow_seen
= 1;
1736 val_display_text_line
= val
;
1737 return &val_display_text_line
;
1740 /* Display the mode line for window w */
1743 display_mode_line (w
)
1746 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
1747 register int left
= XFASTINT (w
->left
);
1748 register int right
= XFASTINT (w
->width
) + left
;
1749 register SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (w
));
1751 get_display_line (s
, vpos
, left
);
1752 display_mode_element (w
, vpos
, left
, 0, right
, right
,
1753 current_buffer
->mode_line_format
);
1754 SCREEN_DESIRED_GLYPHS (s
)->bufp
[vpos
] = 0;
1756 /* Make the mode line inverse video if the entire line
1757 is made of mode lines.
1758 I.e. if this window is full width,
1759 or if it is the child of a full width window
1760 (which implies that that window is split side-by-side
1761 and the rest of this line is mode lines of the sibling windows). */
1762 if (XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
1763 || XFASTINT (XWINDOW (w
->parent
)->width
) == SCREEN_WIDTH (s
))
1764 s
->desired_glyphs
->highlight
[vpos
] = mode_line_inverse_video
;
1766 #ifdef HAVE_X_WINDOWS
1767 /* I'm trying this out because I saw Unimpress use it, but it's
1768 possible that this may mess adversely with some window managers. jla */
1771 && ! SCREEN_MINIBUF_ONLY_P (s
)
1772 && w
== XWINDOW (s
->selected_window
)
1773 && (NILP (Fstring_equal (XBUFFER (w
->buffer
)->name
, s
->name
))))
1774 x_set_name (s
, XBUFFER (w
->buffer
)->name
, Qnil
);
1778 /* Contribute ELT to the mode line for window W.
1779 How it translates into text depends on its data type.
1781 VPOS is the position of the mode line being displayed.
1783 HPOS is the position (absolute on screen) where this element's text
1784 should start. The output is truncated automatically at the right
1787 DEPTH is the depth in recursion. It is used to prevent
1788 infinite recursion here.
1790 MINENDCOL is the hpos before which the element may not end.
1791 The element is padded at the right with spaces if nec
1792 to reach this column.
1794 MAXENDCOL is the hpos past which this element may not extend.
1795 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
1796 (This is necessary to make nested padding and truncation work.)
1798 Returns the hpos of the end of the text generated by ELT.
1799 The next element will receive that value as its HPOS arg,
1800 so as to concatenate the elements. */
1803 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
1805 register int vpos
, hpos
;
1808 register int maxendcol
;
1809 register Lisp_Object elt
;
1817 #ifdef SWITCH_ENUM_BUG
1818 switch ((int) XTYPE (elt
))
1820 switch (XTYPE (elt
))
1825 /* A string: output it and check for %-constructs within it. */
1826 register unsigned char c
;
1827 register unsigned char *this = XSTRING (elt
)->data
;
1829 while (hpos
< maxendcol
&& *this)
1831 unsigned char *last
= this;
1832 while ((c
= *this++) != '\0' && c
!= '%')
1834 if (this - 1 != last
)
1836 register int lim
= --this - last
+ hpos
;
1837 hpos
= display_string (w
, vpos
, last
, hpos
, 0, hpos
,
1838 min (lim
, maxendcol
));
1842 register int spec_width
= 0;
1844 /* We can't allow -ve args due to the "%-" construct */
1845 /* Argument specifies minwidth but not maxwidth
1846 (maxwidth can be specified by
1847 (<negative-number> . <stuff>) mode-line elements) */
1849 while ((c
= *this++) >= '0' && c
<= '9')
1851 spec_width
= spec_width
* 10 + (c
- '0');
1855 if (spec_width
> maxendcol
)
1856 spec_width
= maxendcol
;
1859 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1860 spec_width
, maxendcol
,
1861 Vglobal_mode_string
);
1863 hpos
= display_string (w
, vpos
,
1864 decode_mode_spec (w
, c
,
1866 hpos
, 0, spec_width
, maxendcol
);
1873 /* A symbol: process the value of the symbol recursively
1874 as if it appeared here directly. Avoid error if symbol void.
1875 Special case: if value of symbol is a string, output the string
1878 register Lisp_Object tem
;
1879 tem
= Fboundp (elt
);
1882 tem
= Fsymbol_value (elt
);
1883 /* If value is a string, output that string literally:
1884 don't check for % within it. */
1885 if (XTYPE (tem
) == Lisp_String
)
1886 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
1887 hpos
, 0, minendcol
, maxendcol
);
1888 /* Give up right away for nil or t. */
1889 else if (!EQ (tem
, elt
))
1890 { elt
= tem
; goto tail_recurse
; }
1897 register Lisp_Object car
, tem
;
1899 /* A cons cell: three distinct cases.
1900 If first element is a string or a cons, process all the elements
1901 and effectively concatenate them.
1902 If first element is a negative number, truncate displaying cdr to
1903 at most that many characters. If positive, pad (with spaces)
1904 to at least that many characters.
1905 If first element is a symbol, process the cadr or caddr recursively
1906 according to whether the symbol's value is non-nil or nil. */
1907 car
= XCONS (elt
)->car
;
1908 if (XTYPE (car
) == Lisp_Symbol
)
1910 tem
= Fboundp (car
);
1911 elt
= XCONS (elt
)->cdr
;
1912 if (XTYPE (elt
) != Lisp_Cons
)
1914 /* elt is now the cdr, and we know it is a cons cell.
1915 Use its car if CAR has a non-nil value. */
1918 tem
= Fsymbol_value (car
);
1920 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
1922 /* Symbol's value is nil (or symbol is unbound)
1923 Get the cddr of the original list
1924 and if possible find the caddr and use that. */
1925 elt
= XCONS (elt
)->cdr
;
1928 else if (XTYPE (elt
) != Lisp_Cons
)
1930 elt
= XCONS (elt
)->car
;
1933 else if (XTYPE (car
) == Lisp_Int
)
1935 register int lim
= XINT (car
);
1936 elt
= XCONS (elt
)->cdr
;
1938 /* Negative int means reduce maximum width.
1939 DO NOT change MINENDCOL here!
1940 (20 -10 . foo) should truncate foo to 10 col
1941 and then pad to 20. */
1942 maxendcol
= min (maxendcol
, hpos
- lim
);
1945 /* Padding specified. Don't let it be more than
1948 if (lim
> maxendcol
)
1950 /* If that's more padding than already wanted, queue it.
1951 But don't reduce padding already specified even if
1952 that is beyond the current truncation point. */
1953 if (lim
> minendcol
)
1958 else if (XTYPE (car
) == Lisp_String
|| XTYPE (car
) == Lisp_Cons
)
1960 register int limit
= 50;
1961 /* LIMIT is to protect against circular lists. */
1962 while (XTYPE (elt
) == Lisp_Cons
&& --limit
> 0
1963 && hpos
< maxendcol
)
1965 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1968 elt
= XCONS (elt
)->cdr
;
1976 return (display_string (w
, vpos
, "*invalid*", hpos
, 0,
1977 minendcol
, maxendcol
));
1981 if (minendcol
> hpos
)
1982 hpos
= display_string (w
, vpos
, "", hpos
, 0, minendcol
, -1);
1986 /* Return a string for the output of a mode line %-spec for window W,
1987 generated by character C and width MAXWIDTH. */
1990 decode_mode_spec (w
, c
, maxwidth
)
1993 register int maxwidth
;
1995 Lisp_Object obj
= Qnil
;
1996 SCREEN_PTR scr
= XSCREEN (WINDOW_SCREEN (w
));
1997 char *decode_mode_spec_buf
= (char *) SCREEN_TEMP_GLYPHS (scr
)->total_contents
;
1999 if (maxwidth
> SCREEN_WIDTH (scr
))
2000 maxwidth
= SCREEN_WIDTH (scr
);
2005 obj
= current_buffer
->name
;
2007 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
2009 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
2010 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
2011 decode_mode_spec_buf
[maxwidth
] = '\0';
2012 return decode_mode_spec_buf
;
2018 obj
= current_buffer
->filename
;
2022 else if (XTYPE (obj
) == Lisp_String
&& XSTRING (obj
)->size
> maxwidth
)
2024 bcopy ("...", decode_mode_spec_buf
, 3);
2025 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
2026 decode_mode_spec_buf
+ 3, maxwidth
- 3);
2027 return decode_mode_spec_buf
;
2033 obj
= current_buffer
->mode_name
;
2037 if (BEGV
> BEG
|| ZV
< Z
)
2042 if (!NILP (current_buffer
->read_only
))
2044 if (MODIFF
> current_buffer
->save_modified
)
2049 /* status of process */
2051 obj
= Fget_buffer_process (Fcurrent_buffer ());
2053 return "no process";
2054 obj
= Fsymbol_name (Fprocess_status (obj
));
2057 return "no processes";
2058 #endif /* subprocesses */
2062 int pos
= marker_position (w
->start
);
2063 int total
= ZV
- BEGV
;
2065 if (XFASTINT (w
->window_end_pos
) <= Z
- ZV
)
2072 else if (pos
<= BEGV
)
2076 total
= ((pos
- BEGV
) * 100 + total
- 1) / total
;
2077 /* We can't normally display a 3-digit number,
2078 so get us a 2-digit number that is close. */
2081 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
2082 return decode_mode_spec_buf
;
2094 if (command_loop_level
> 5)
2096 p
= decode_mode_spec_buf
;
2097 for (i
= 0; i
< command_loop_level
; i
++)
2100 return decode_mode_spec_buf
;
2108 if (command_loop_level
> 5)
2110 p
= decode_mode_spec_buf
;
2111 for (i
= 0; i
< command_loop_level
; i
++)
2114 return decode_mode_spec_buf
;
2119 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
2123 if (maxwidth
< sizeof (lots_of_dashes
))
2124 return lots_of_dashes
;
2127 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
2131 return decode_mode_spec_buf
;
2135 if (XTYPE (obj
) == Lisp_String
)
2136 return (char *) XSTRING (obj
)->data
;
2141 /* Display STRING on one line of window W, starting at HPOS.
2142 Display at position VPOS. Caller should have done get_display_line.
2144 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
2146 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
2147 MAXCOL is the last column ok to end at. Truncate here.
2148 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
2149 Both count from the left edge of the screen, as does HPOS.
2150 The right edge of W is an implicit maximum.
2151 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
2153 Returns ending hpos */
2156 display_string (w
, vpos
, string
, hpos
, truncate
, mincol
, maxcol
)
2158 unsigned char *string
;
2165 int hscroll
= XINT (w
->hscroll
);
2166 int tab_width
= XINT (current_buffer
->tab_width
);
2167 register GLYPH
*start
;
2168 register GLYPH
*end
;
2169 struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (XSCREEN (w
->screen
));
2170 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2171 int window_width
= XFASTINT (w
->width
);
2173 /* Use the standard display table, not the window's display table.
2174 We don't want the mode line in rot13. */
2175 register struct Lisp_Vector
*dp
= 0;
2177 if (XTYPE (Vstandard_display_table
) == Lisp_Vector
2178 && XVECTOR (Vstandard_display_table
)->size
== DISP_TABLE_SIZE
)
2179 dp
= XVECTOR (Vstandard_display_table
);
2181 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
2184 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
2185 end
= start
+ window_width
- (truncate
!= 0);
2187 if ((window_width
+ XFASTINT (w
->left
))
2188 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
2191 if (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
)
2192 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
2193 if (maxcol
>= 0 && mincol
> maxcol
)
2200 if (c
>= 040 && c
< 0177
2201 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
2211 if (p1
>= start
&& p1
< end
)
2215 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
2217 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
2218 p1
= copy_rope (p1
, start
, DISP_CHAR_ROPE (dp
, c
));
2219 else if (c
< 0200 && buffer_defaults
.ctl_arrow
)
2222 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
2223 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
2225 if (p1
>= start
&& p1
< end
)
2232 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
2233 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
2235 if (p1
>= start
&& p1
< end
)
2236 *p1
= (c
>> 6) + '0';
2238 if (p1
>= start
&& p1
< end
)
2239 *p1
= (7 & (c
>> 3)) + '0';
2241 if (p1
>= start
&& p1
< end
)
2242 *p1
= (7 & c
) + '0';
2250 if (truncate
) *p1
++ = truncate
;
2252 else if (mincol
>= 0)
2254 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
2260 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
2262 if (len
> desired_glyphs
->used
[vpos
])
2263 desired_glyphs
->used
[vpos
] = len
;
2264 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
2273 staticpro (&last_arrow_position
);
2274 staticpro (&last_arrow_string
);
2275 last_arrow_position
= Qnil
;
2276 last_arrow_string
= Qnil
;
2278 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
2279 "String displayed by mode-line-format's \"%m\" specifiation.");
2280 Vglobal_mode_string
= Qnil
;
2282 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
2283 "Marker for where to display an arrow on top of the buffer text.\n\
2284 This must be the beginning of a line in order to work.\n\
2285 See also `overlay-arrow-string'.");
2286 Voverlay_arrow_position
= Qnil
;
2288 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
2289 "String to display as an arrow. See also `overlay-arrow-position'.");
2290 Voverlay_arrow_string
= Qnil
;
2292 DEFVAR_INT ("scroll-step", &scroll_step
,
2293 "*The number of lines to try scrolling a window by when point moves out.\n\
2294 If that fails to bring point back on screen, point is centered instead.\n\
2295 If this is zero, point is always centered after it moves off screen.");
2297 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
2299 DEFVAR_BOOL ("truncate-partial-width-windows",
2300 &truncate_partial_width_windows
,
2301 "*Non-nil means truncate lines in all windows less than full screen wide.");
2302 truncate_partial_width_windows
= 1;
2304 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
2305 "*Non-nil means use inverse video for the mode line.");
2306 mode_line_inverse_video
= 1;
2308 #ifndef MULTI_SCREEN
2309 defsubr (&Sredraw_display
);
2310 #endif /* MULTI_SCREEN */
2313 /* initialize the window system */
2316 Lisp_Object root_window
;
2317 #ifndef COMPILER_REGISTER_BUG
2319 #endif /* COMPILER_REGISTER_BUG */
2320 struct window
*mini_w
;
2322 this_line_bufpos
= 0;
2324 mini_w
= XWINDOW (minibuf_window
);
2325 root_window
= mini_w
->prev
;
2327 echo_area_glyphs
= 0;
2328 previous_echo_glyphs
= 0;
2330 if (!noninteractive
)
2332 SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (XWINDOW (root_window
)));
2333 XFASTINT (XWINDOW (root_window
)->top
) = 0;
2334 set_window_height (root_window
, SCREEN_HEIGHT (s
) - 1, 0);
2335 XFASTINT (mini_w
->top
) = SCREEN_HEIGHT (s
) - 1;
2336 set_window_height (minibuf_window
, 1, 0);
2338 XFASTINT (XWINDOW (root_window
)->width
) = SCREEN_WIDTH (s
);
2339 XFASTINT (mini_w
->width
) = SCREEN_WIDTH (s
);