1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1992 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 /* Fill the rest of the minibuffer window with blank lines. */
319 for (i
= vpos
+ 1; i
< vpos
+ XWINDOW (minibuf_window
)->height
; i
++)
321 get_display_line (s
, i
, 0);
322 display_string (XWINDOW (minibuf_window
), vpos
,
323 "", 0, 0, 0, SCREEN_WIDTH (s
));
327 else if (!EQ (minibuf_window
, selected_window
))
328 windows_or_buffers_changed
++;
330 if (EQ (minibuf_window
, selected_window
))
331 this_line_bufpos
= 0;
333 previous_echo_glyphs
= echo_area_glyphs
;
336 /* Do a screen update, taking possible shortcuts into account.
337 This is the main external entry point for redisplay.
339 If the last redisplay displayed an echo area message and that
340 message is no longer requested, we clear the echo area
341 or bring back the minibuffer if that is in use.
343 Everyone would like to have a hook here to call eval,
344 but that cannot be done safely without a lot of changes elsewhere.
345 This can be called from signal handlers; with alarms set up;
346 or with synchronous processes running.
347 See the function `echo' in keyboard.c.
348 See Fcall_process; if you called it from here, it could be
349 entered recursively. */
354 register struct window
*w
= XWINDOW (selected_window
);
358 register int tlbufpos
, tlendpos
;
360 extern int input_pending
;
365 /* Notice any pending interrupt request to change screen size. */
366 do_pending_window_change ();
374 /* Normally the message* functions will have already displayed and
375 updated the echo area, but the screen may have been trashed, or
376 the update may have been preempted, so display the echo area
378 if (echo_area_glyphs
|| previous_echo_glyphs
)
380 echo_area_display ();
384 if (clip_changed
|| windows_or_buffers_changed
)
387 /* Detect case that we need to write a star in the mode line. */
388 if (XFASTINT (w
->last_modified
) < MODIFF
389 && XFASTINT (w
->last_modified
) <= current_buffer
->save_modified
)
391 w
->update_mode_line
= Qt
;
392 if (buffer_shared
> 1)
396 SCREEN_SCROLL_BOTTOM_VPOS (XSCREEN (w
->screen
)) = -1;
398 all_windows
= update_mode_lines
|| buffer_shared
> 1;
400 /* If specs for an arrow have changed, do thorough redisplay
401 to ensure we remove any arrow that should no longer exist. */
402 if (Voverlay_arrow_position
!= last_arrow_position
403 || Voverlay_arrow_string
!= last_arrow_string
)
404 all_windows
= 1, clip_changed
= 1;
406 tlbufpos
= this_line_bufpos
;
407 tlendpos
= this_line_endpos
;
408 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
409 && SCREEN_VISIBLE_P (XSCREEN (w
->screen
))
410 /* Make sure recorded data applies to current buffer, etc */
411 && this_line_buffer
== current_buffer
412 && current_buffer
== XBUFFER (w
->buffer
)
413 && NILP (w
->force_start
)
414 /* Point must be on the line that we have info recorded about */
416 && point
<= Z
- tlendpos
417 /* All text outside that line, including its final newline,
419 && (XFASTINT (w
->last_modified
) >= MODIFF
420 || (beg_unchanged
>= tlbufpos
- 1
422 /* If selective display, can't optimize
423 if the changes start at the beginning of the line. */
424 && ((XTYPE (current_buffer
->selective_display
) == Lisp_Int
425 && XINT (current_buffer
->selective_display
) > 0
426 ? (beg_unchanged
>= tlbufpos
429 && end_unchanged
>= tlendpos
430 && Z
- GPT
>= tlendpos
)))
432 if (tlbufpos
> BEGV
&& FETCH_CHAR (tlbufpos
- 1) != '\n'
434 || FETCH_CHAR (tlbufpos
) == '\n'))
435 /* Former continuation line has disappeared by becoming empty */
437 else if (XFASTINT (w
->last_modified
) < MODIFF
438 || MINI_WINDOW_P (w
))
441 overlay_arrow_seen
= 0;
442 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
443 pos_tab_offset (w
, tlbufpos
));
444 /* If line contains point, is not continued,
445 and ends at same distance from eob as before, we win */
446 if (cursor_vpos
>= 0 && this_line_bufpos
447 && this_line_endpos
== tlendpos
)
449 if (XFASTINT (w
->width
) != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
450 preserve_other_columns (w
);
456 else if (point
== XFASTINT (w
->last_point
))
460 do_pending_window_change ();
467 pos
= *compute_motion (tlbufpos
, 0,
468 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
469 point
, 2, - (1 << (SHORTBITS
- 1)),
470 XFASTINT (w
->width
) - 1
471 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
472 != SCREEN_WIDTH (selected_screen
)),
474 pos_tab_offset (w
, tlbufpos
));
477 SCREEN_CURSOR_X (selected_screen
)
478 = XFASTINT (w
->left
) + max (pos
.hpos
, 0);
479 SCREEN_CURSOR_Y (selected_screen
) = this_line_vpos
;
486 /* Text changed drastically or point moved off of line */
487 cancel_line (this_line_vpos
, selected_screen
);
490 this_line_bufpos
= 0;
491 all_windows
|= buffer_shared
> 1;
498 /* Recompute # windows showing selected buffer.
499 This will be incremented each time such a window is displayed. */
502 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
506 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
509 s
= XSCREEN (XCONS (tail
)->car
);
511 /* Redraw its windows. */
512 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
515 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
516 #endif /* not MULTI_SCREEN */
518 else if (SCREEN_VISIBLE_P (selected_screen
))
520 redisplay_window (selected_window
, 1);
521 if (XFASTINT (w
->width
) != SCREEN_WIDTH (selected_screen
))
522 preserve_other_columns (w
);
526 /* Prevent various kinds of signals during display update.
527 stdio is not robust about handling signals,
528 which can cause an apparent I/O error. */
540 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
544 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
547 s
= XSCREEN (XCONS (tail
)->car
);
550 pause
|= update_screen (s
, 0, 0);
552 mark_window_display_accurate (s
->root_window
, 1);
557 #endif /* MULTI_SCREEN */
559 if (SCREEN_VISIBLE_P (selected_screen
))
560 pause
= update_screen (selected_screen
, 0, 0);
562 /* We may have called echo_area_display at the top of this
563 function. If the echo area is on another screen, that may
564 have put text on a screen other than the selected one, so the
565 above call to update_screen would not have caught it. Catch
568 SCREEN_PTR mini_screen
=
569 XSCREEN (WINDOW_SCREEN (XWINDOW (minibuf_window
)));
571 if (mini_screen
!= selected_screen
)
572 pause
|= update_screen (mini_screen
, 0, 0);
577 /* If screen does not match, prevent doing single-line-update next time.
578 Also, don't forget to check every line to update the arrow. */
581 this_line_bufpos
= 0;
582 if (!NILP (last_arrow_position
))
584 last_arrow_position
= Qt
;
585 last_arrow_string
= Qt
;
587 /* If we pause after scrolling, some lines in current_screen
588 may be null, so preserve_other_columns won't be able to
589 preserve all the vertical-bar separators. So, avoid using it
591 if (XFASTINT (w
->width
) != SCREEN_WIDTH (selected_screen
))
592 update_mode_lines
= 1;
595 /* Now text on screen agrees with windows, so
596 put info into the windows for partial redisplay to follow */
600 register struct buffer
*b
= XBUFFER (w
->buffer
);
602 blank_end_of_window
= 0;
604 unchanged_modified
= BUF_MODIFF (b
);
605 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
606 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
608 XFASTINT (w
->last_point
) = BUF_PT (b
);
609 XFASTINT (w
->last_point_x
) = SCREEN_CURSOR_X (selected_screen
);
610 XFASTINT (w
->last_point_y
) = SCREEN_CURSOR_Y (selected_screen
);
613 mark_window_display_accurate (XWINDOW (minibuf_window
)->prev
, 1);
616 w
->update_mode_line
= Qnil
;
617 XFASTINT (w
->last_modified
) = BUF_MODIFF (b
);
618 w
->window_end_valid
= Qt
;
619 last_arrow_position
= Voverlay_arrow_position
;
620 last_arrow_string
= Voverlay_arrow_string
;
622 update_mode_lines
= 0;
623 windows_or_buffers_changed
= 0;
626 /* Start SIGIO interrupts coming again.
627 Having them off during the code above
628 makes it less likely one will discard output,
629 but not impossible, since there might be stuff
630 in the system buffer here.
631 But it is much hairier to try to do anything about that. */
637 /* Change screen size now if a change is pending. */
638 do_pending_window_change ();
641 /* Redisplay, but leave alone any recent echo area message
642 unless another message has been requested in its place.
644 This is useful in situations where you need to redisplay but no
645 user action has occurred, making it inappropriate for the message
646 area to be cleared. See tracking_off and
647 wait_reading_process_input for examples of these situations. */
649 redisplay_preserve_echo_area ()
651 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
653 echo_area_glyphs
= previous_echo_glyphs
;
655 echo_area_glyphs
= 0;
662 mark_window_display_accurate (window
, flag
)
666 register struct window
*w
;
668 for (;!NILP (window
); window
= w
->next
)
670 w
= XWINDOW (window
);
672 if (!NILP (w
->buffer
))
673 XFASTINT (w
->last_modified
)
675 : XBUFFER (w
->buffer
) == current_buffer
676 ? MODIFF
: BUF_MODIFF (XBUFFER (w
->buffer
));
677 w
->window_end_valid
= Qt
;
678 w
->update_mode_line
= Qnil
;
680 if (!NILP (w
->vchild
))
681 mark_window_display_accurate (w
->vchild
, flag
);
682 if (!NILP (w
->hchild
))
683 mark_window_display_accurate (w
->hchild
, flag
);
688 last_arrow_position
= Voverlay_arrow_position
;
689 last_arrow_string
= Voverlay_arrow_string
;
693 /* t is unequal to any useful value of Voverlay_arrow_... */
694 last_arrow_position
= Qt
;
695 last_arrow_string
= Qt
;
702 redisplay_windows (window
)
705 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
706 redisplay_window (window
, 0);
710 redisplay_window (window
, just_this_one
)
714 register struct window
*w
= XWINDOW (window
);
715 SCREEN_PTR s
= XSCREEN (w
->screen
);
717 register int lpoint
= point
;
718 struct buffer
*old
= current_buffer
;
719 register int width
= XFASTINT (w
->width
) - 1
720 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
721 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))));
723 register int hscroll
= XINT (w
->hscroll
);
727 int window_needs_modeline
;
729 if (SCREEN_HEIGHT (s
) == 0) abort (); /* Some bug zeros some core */
731 /* If this is a combination window, do its children; that's all. */
733 if (!NILP (w
->vchild
))
735 redisplay_windows (w
->vchild
);
738 if (!NILP (w
->hchild
))
740 redisplay_windows (w
->hchild
);
743 if (NILP (w
->buffer
))
746 height
= window_internal_height (w
);
748 if (MINI_WINDOW_P (w
))
750 if (w
== XWINDOW (minibuf_window
))
752 if (echo_area_glyphs
)
753 /* We've already displayed the echo area glyphs, if any. */
758 /* This is a minibuffer, but it's not the currently active one, so
760 int vpos
= XFASTINT (XWINDOW (SCREEN_MINIBUF_WINDOW (s
))->top
);
763 for (i
= 0; i
< height
; i
++)
765 get_display_line (s
, vpos
+ i
, 0);
766 display_string (w
, vpos
+ i
, "", 0, 0, 0, width
);
773 if (update_mode_lines
)
774 w
->update_mode_line
= Qt
;
776 /* Otherwise set up data on this window; select its buffer and point value */
778 current_buffer
= XBUFFER (w
->buffer
);
781 /* Count number of windows showing the selected buffer. */
784 && current_buffer
== XBUFFER (XWINDOW (selected_window
)->buffer
))
787 /* POINT refers normally to the selected window.
788 For any other window, set up appropriate value. */
790 if (!EQ (window
, selected_window
))
792 SET_PT (marker_position (w
->pointm
));
796 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
798 else if (point
> (ZV
- 1))
801 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
805 /* If window-start is screwed up, choose a new one. */
806 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
809 startp
= marker_position (w
->start
);
811 /* Handle case where place to start displaying has been specified,
812 unless the specified location is outside the visible range. */
813 if (!NILP (w
->force_start
))
815 w
->update_mode_line
= Qt
;
816 w
->force_start
= Qnil
;
817 XFASTINT (w
->last_modified
) = 0;
818 if (startp
< BEGV
) startp
= BEGV
;
819 if (startp
> ZV
) startp
= ZV
;
820 try_window (window
, startp
);
823 /* If point does not appear, move point so it does appear */
824 pos
= *compute_motion (startp
, 0,
825 ((EQ (window
, minibuf_window
) && startp
== 1)
826 ? minibuf_prompt_width
: 0)
828 (hscroll
? 1 - hscroll
: 0),
830 - (1 << (SHORTBITS
- 1)),
831 width
, hscroll
, pos_tab_offset (w
, startp
));
833 if (w
!= XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
834 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
838 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
839 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
845 /* Handle case where text has not changed, only point,
846 and it has not moved off the screen */
848 /* This code is not used for minibuffer for the sake of
849 the case of redisplaying to replace an echo area message;
850 since in that case the minibuffer contents per se are usually unchanged.
851 This code is of no real use in the minibuffer since
852 the handling of this_line_bufpos, etc.,
853 in redisplay handles the same cases. */
855 if (XFASTINT (w
->last_modified
) >= MODIFF
856 && point
>= startp
&& !clip_changed
857 && (just_this_one
|| XFASTINT (w
->width
) == SCREEN_WIDTH (s
))
858 && !EQ (window
, minibuf_window
))
860 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0),
861 point
, height
+ 1, 10000, width
, hscroll
,
862 pos_tab_offset (w
, startp
));
864 if (pos
.vpos
< height
)
866 /* Ok, point is still on screen */
867 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
869 /* These variables are supposed to be origin 1 */
870 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
871 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
873 /* This doesn't do the trick, because if a window to the right of
874 this one must be redisplayed, this does nothing because there
875 is nothing in DesiredScreen yet, and then the other window is
876 redisplayed, making likes that are empty in this window's columns.
877 if (XFASTINT (w->width) != SCREEN_WIDTH (s))
878 preserve_my_columns (w);
882 /* Don't bother trying redisplay with same start;
883 we already know it will lose */
885 /* If current starting point was originally the beginning of a line
886 but no longer is, find a new starting point. */
887 else if (!NILP (w
->start_at_line_beg
)
889 || FETCH_CHAR (startp
- 1) == '\n'))
893 else if (just_this_one
&& !MINI_WINDOW_P (w
)
895 && XFASTINT (w
->last_modified
)
896 && ! EQ (w
->window_end_valid
, Qnil
)
897 && do_id
&& !clip_changed
898 && !blank_end_of_window
899 && XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
900 && EQ (last_arrow_position
, Voverlay_arrow_position
)
901 && EQ (last_arrow_string
, Voverlay_arrow_string
)
902 && (tem
= try_window_id (SCREEN_SELECTED_WINDOW (s
)))
905 /* tem > 0 means success. tem == -1 means choose new start.
906 tem == -2 means try again with same start,
907 and nothing but whitespace follows the changed stuff.
908 tem == 0 means try again with same start. */
912 else if (startp
>= BEGV
&& startp
<= ZV
913 /* Avoid starting display at end of buffer! */
914 && (startp
< ZV
|| startp
== BEGV
915 || (XFASTINT (w
->last_modified
) >= MODIFF
)))
917 /* Try to redisplay starting at same place as before */
918 /* If point has not moved off screen, accept the results */
919 try_window (window
, startp
);
920 if (cursor_vpos
>= 0)
923 cancel_my_columns (w
);
926 XFASTINT (w
->last_modified
) = 0;
927 w
->update_mode_line
= Qt
;
929 /* Try to scroll by specified few lines */
931 if (scroll_step
&& !clip_changed
)
935 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
936 scroll_step
, width
, hscroll
, window
);
937 if (pos
.vpos
>= height
)
941 pos
= *vmotion (startp
, point
< startp
? - scroll_step
: scroll_step
,
942 width
, hscroll
, window
);
944 if (point
>= pos
.bufpos
)
946 try_window (window
, pos
.bufpos
);
947 if (cursor_vpos
>= 0)
950 cancel_my_columns (w
);
955 /* Finally, just choose place to start which centers point */
958 pos
= *vmotion (point
, - height
/ 2, width
, hscroll
, window
);
959 try_window (window
, pos
.bufpos
);
961 startp
= marker_position (w
->start
);
962 w
->start_at_line_beg
=
963 (startp
== BEGV
|| FETCH_CHAR (startp
- 1) == '\n') ? Qt
: Qnil
;
966 /* If window not full width, must redo its mode line
967 if the window to its side is being redone */
968 if ((!NILP (w
->update_mode_line
)
969 || (!just_this_one
&& width
< SCREEN_WIDTH (s
) - 1))
970 && height
!= XFASTINT (w
->height
))
971 display_mode_line (w
);
974 current_buffer
= old
;
978 /* Do full redisplay on one window, starting at position `pos'. */
981 try_window (window
, pos
)
985 register struct window
*w
= XWINDOW (window
);
986 register int height
= window_internal_height (w
);
987 register int vpos
= XFASTINT (w
->top
);
988 register int last_text_vpos
= vpos
;
989 int tab_offset
= pos_tab_offset (w
, pos
);
990 SCREEN_PTR s
= XSCREEN (w
->screen
);
991 int width
= XFASTINT (w
->width
) - 1
992 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
995 Fset_marker (w
->start
, make_number (pos
), Qnil
);
997 overlay_arrow_seen
= 0;
998 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
1000 while (--height
>= 0)
1002 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, tab_offset
);
1003 tab_offset
+= width
;
1004 if (val
.vpos
) tab_offset
= 0;
1006 if (pos
!= val
.bufpos
)
1008 /* Next line, unless prev line ended in end of buffer with no cr */
1009 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
1013 /* If last line is continued in middle of character,
1014 include the split character in the text considered on the screen */
1015 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1018 /* If bottom just moved off end of screen, change mode line percentage. */
1019 if (XFASTINT (w
->window_end_pos
) == 0
1021 w
->update_mode_line
= Qt
;
1023 /* Say where last char on screen will be, once redisplay is finished. */
1024 XFASTINT (w
->window_end_pos
) = Z
- pos
;
1025 XFASTINT (w
->window_end_vpos
) = last_text_vpos
- XFASTINT (w
->top
);
1026 /* But that is not valid info until redisplay finishes. */
1027 w
->window_end_valid
= Qnil
;
1030 /* Try to redisplay when buffer is modified locally,
1031 computing insert/delete line to preserve text outside
1032 the bounds of the changes.
1033 Return 1 if successful, 0 if if cannot tell what to do,
1034 or -1 to tell caller to find a new window start,
1035 or -2 to tell caller to do normal redisplay with same window start. */
1038 try_window_id (window
)
1042 register struct window
*w
= XWINDOW (window
);
1043 register int height
= window_internal_height (w
);
1044 SCREEN_PTR s
= XSCREEN (w
->screen
);
1045 int top
= XFASTINT (w
->top
);
1046 int start
= marker_position (w
->start
);
1047 int width
= XFASTINT (w
->width
) - 1
1048 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
1049 int hscroll
= XINT (w
->hscroll
);
1050 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
1052 register int i
, tem
;
1053 int last_text_vpos
= 0;
1056 struct position val
, bp
, ep
, xp
, pp
;
1057 int scroll_amount
= 0;
1059 int tab_offset
, epto
;
1061 if (GPT
- BEG
< beg_unchanged
)
1062 beg_unchanged
= GPT
- BEG
;
1063 if (Z
- GPT
< end_unchanged
)
1064 end_unchanged
= Z
- GPT
;
1066 if (beg_unchanged
+ 1 < start
)
1067 return 0; /* Give up if changes go above top of window */
1069 /* Find position before which nothing is changed. */
1070 bp
= *compute_motion (start
, 0, lmargin
,
1071 beg_unchanged
+ 1, height
+ 1, 0, width
, hscroll
,
1072 pos_tab_offset (w
, start
));
1073 if (bp
.vpos
>= height
)
1075 if (point
< bp
.bufpos
&& !bp
.contin
)
1077 /* All changes are below the screen, and point is on the screen.
1078 We don't need to change the screen at all.
1079 But we need to update window_end_pos to account for
1080 any change in buffer size. */
1081 bp
= *compute_motion (start
, 0, lmargin
,
1083 width
, hscroll
, pos_tab_offset (w
, start
));
1084 XFASTINT (w
->window_end_vpos
) = height
;
1085 XFASTINT (w
->window_end_pos
) = Z
- bp
.bufpos
;
1093 /* Find beginning of that screen line. Must display from there. */
1094 bp
= *vmotion (bp
.bufpos
, 0, width
, hscroll
, window
);
1101 /* If about to start displaying at the beginning of a continuation line,
1102 really start with previous screen line, in case it was not
1103 continued when last redisplayed */
1104 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
1106 /* Likewise if we have to worry about selective display. */
1107 (XTYPE (current_buffer
->selective_display
) == Lisp_Int
1108 && XINT (current_buffer
->selective_display
) > 0
1109 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
1111 bp
= *vmotion (bp
.bufpos
, -1, width
, hscroll
, window
);
1116 if (bp
.contin
&& bp
.hpos
!= lmargin
)
1118 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
1124 /* Find first visible newline after which no more is changed. */
1125 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
1126 if (XTYPE (current_buffer
->selective_display
) == Lisp_Int
1127 && XINT (current_buffer
->selective_display
) > 0)
1129 && (position_indentation (tem
)
1130 >= XINT (current_buffer
->selective_display
)))
1131 tem
= find_next_newline (tem
, 1);
1133 /* Compute the cursor position after that newline. */
1134 ep
= *compute_motion (pos
, vpos
, val
.hpos
, tem
,
1135 height
, - (1 << (SHORTBITS
- 1)),
1136 width
, hscroll
, pos_tab_offset (w
, bp
.bufpos
));
1138 /* If changes reach past the text available on the screen,
1139 just display rest of screen. */
1140 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
1143 stop_vpos
= ep
.vpos
;
1145 /* If no newline before ep, the line ep is on includes some changes
1146 that must be displayed. Make sure we don't stop before it. */
1147 /* Also, if changes reach all the way until ep.bufpos,
1148 it is possible that something was deleted after the
1149 newline before it, so the following line must be redrawn. */
1150 if (stop_vpos
== ep
.vpos
1151 && (ep
.bufpos
== BEGV
1152 || FETCH_CHAR (ep
.bufpos
- 1) != '\n'
1153 || ep
.bufpos
== Z
- end_unchanged
))
1154 stop_vpos
= ep
.vpos
+ 1;
1157 overlay_arrow_seen
= 0;
1159 /* If changes do not reach to bottom of window,
1160 figure out how much to scroll the rest of the window */
1161 if (stop_vpos
< height
)
1163 /* Now determine how far up or down the rest of the window has moved */
1164 epto
= pos_tab_offset (w
, ep
.bufpos
);
1165 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1166 Z
- XFASTINT (w
->window_end_pos
),
1167 10000, 0, width
, hscroll
, epto
);
1168 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
1170 /* Is everything on screen below the changes whitespace?
1171 If so, no scrolling is really necessary. */
1172 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
1174 tem
= FETCH_CHAR (i
);
1175 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
1181 XFASTINT (w
->window_end_vpos
) += scroll_amount
;
1183 /* Before doing any scrolling, verify that point will be on screen. */
1184 if (point
> ep
.bufpos
&& !(point
<= xp
.bufpos
&& xp
.bufpos
< height
))
1186 if (point
<= xp
.bufpos
)
1188 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1189 point
, height
, - (1 << (SHORTBITS
- 1)),
1190 width
, hscroll
, epto
);
1194 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
,
1195 point
, height
, - (1 << (SHORTBITS
- 1)),
1196 width
, hscroll
, pos_tab_offset (w
, xp
.bufpos
));
1198 if (pp
.bufpos
< point
|| pp
.vpos
== height
)
1200 cursor_vpos
= pp
.vpos
+ top
;
1201 cursor_hpos
= pp
.hpos
+ XFASTINT (w
->left
);
1204 if (stop_vpos
- scroll_amount
>= height
1205 || ep
.bufpos
== xp
.bufpos
)
1207 if (scroll_amount
< 0)
1208 stop_vpos
-= scroll_amount
;
1210 /* In this path, we have altered window_end_vpos
1211 and not left it negative.
1212 We must make sure that, in case display is preempted
1213 before the screen changes to reflect what we do here,
1214 further updates will not come to try_window_id
1215 and assume the screen and window_end_vpos match. */
1216 blank_end_of_window
= 1;
1218 else if (!scroll_amount
)
1220 else if (bp
.bufpos
== Z
- end_unchanged
)
1222 /* If reprinting everything is nearly as fast as scrolling,
1223 don't bother scrolling. Can happen if lines are short. */
1224 if (scroll_cost (s
, bp
.vpos
+ top
- scroll_amount
,
1225 top
+ height
- max (0, scroll_amount
),
1227 > xp
.bufpos
- bp
.bufpos
- 20)
1228 /* Return "try normal display with same window-start."
1229 Too bad we can't prevent further scroll-thinking. */
1231 /* If pure deletion, scroll up as many lines as possible.
1232 In common case of killing a line, this can save the
1233 following line from being overwritten by scrolling
1234 and therefore having to be redrawn. */
1235 tem
= scroll_screen_lines (s
, bp
.vpos
+ top
- scroll_amount
,
1236 top
+ height
- max (0, scroll_amount
),
1238 if (!tem
) stop_vpos
= height
;
1240 else if (scroll_amount
)
1242 /* If reprinting everything is nearly as fast as scrolling,
1243 don't bother scrolling. Can happen if lines are short. */
1244 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1245 overestimate of cost of reprinting, since xp.bufpos
1246 would end up below the bottom of the window. */
1247 if (scroll_cost (s
, ep
.vpos
+ top
- scroll_amount
,
1248 top
+ height
- max (0, scroll_amount
),
1250 > xp
.bufpos
- ep
.bufpos
- 20)
1251 /* Return "try normal display with same window-start."
1252 Too bad we can't prevent further scroll-thinking. */
1254 tem
= scroll_screen_lines (s
, ep
.vpos
+ top
- scroll_amount
,
1255 top
+ height
- max (0, scroll_amount
),
1257 if (!tem
) stop_vpos
= height
;
1261 /* In any case, do not display past bottom of window */
1262 if (stop_vpos
>= height
)
1268 /* Handle case where pos is before w->start --
1269 can happen if part of line had been clipped and is not clipped now */
1270 if (vpos
== 0 && pos
< marker_position (w
->start
))
1271 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1273 /* Redisplay the lines where the text was changed */
1274 last_text_vpos
= vpos
;
1275 tab_offset
= pos_tab_offset (w
, pos
);
1276 /* If we are starting display in mid-character, correct tab_offset
1277 to account for passing the line that that character really starts in. */
1278 if (val
.hpos
< lmargin
)
1279 tab_offset
+= width
;
1280 while (vpos
< stop_vpos
)
1282 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1283 tab_offset
+= width
;
1284 if (val
.vpos
) tab_offset
= 0;
1285 if (pos
!= val
.bufpos
)
1287 /* Next line, unless prev line ended in end of buffer with no cr */
1288 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
1292 /* There are two cases:
1293 1) we have displayed down to the bottom of the window
1294 2) we have scrolled lines below stop_vpos by scroll_amount */
1298 /* If last line is continued in middle of character,
1299 include the split character in the text considered on the screen */
1300 if (val
.hpos
< lmargin
)
1302 XFASTINT (w
->window_end_vpos
) = last_text_vpos
;
1303 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1306 /* If scrolling made blank lines at window bottom,
1307 redisplay to fill those lines */
1308 if (scroll_amount
< 0)
1310 /* Don't consider these lines for general-purpose scrolling.
1311 That will save time in the scrolling computation. */
1312 SCREEN_SCROLL_BOTTOM_VPOS (s
) = xp
.vpos
;
1317 vpos
= height
+ scroll_amount
;
1318 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
1320 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
1324 blank_end_of_window
= 1;
1325 tab_offset
= pos_tab_offset (w
, pos
);
1326 /* If we are starting display in mid-character, correct tab_offset
1327 to account for passing the line that that character starts in. */
1328 if (val
.hpos
< lmargin
)
1329 tab_offset
+= width
;
1331 while (vpos
< height
)
1333 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1334 tab_offset
+= width
;
1335 if (val
.vpos
) tab_offset
= 0;
1339 /* Here is a case where display_text_line sets cursor_vpos wrong.
1340 Make it be fixed up, below. */
1342 && xp
.bufpos
== point
)
1346 /* If bottom just moved off end of screen, change mode line percentage. */
1347 if (XFASTINT (w
->window_end_pos
) == 0
1349 w
->update_mode_line
= Qt
;
1351 /* Attempt to adjust end-of-text positions to new bottom line */
1354 delta
= height
- xp
.vpos
;
1356 || (delta
> 0 && xp
.bufpos
<= ZV
)
1357 || (delta
== 0 && xp
.hpos
))
1359 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
1360 delta
, width
, hscroll
, window
);
1361 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1362 XFASTINT (w
->window_end_vpos
) += val
.vpos
;
1366 w
->window_end_valid
= Qnil
;
1368 /* If point was not in a line that was displayed, find it */
1369 if (cursor_vpos
< 0)
1371 val
= *compute_motion (start
, 0, lmargin
, point
, 10000, 10000,
1372 width
, hscroll
, pos_tab_offset (w
, start
));
1373 /* Admit failure if point is off screen now */
1374 if (val
.vpos
>= height
)
1376 for (vpos
= 0; vpos
< height
; vpos
++)
1377 cancel_line (vpos
+ top
, s
);
1380 cursor_vpos
= val
.vpos
+ top
;
1381 cursor_hpos
= val
.hpos
+ XFASTINT (w
->left
);
1384 SCREEN_CURSOR_X (s
) = max (0, cursor_hpos
);
1385 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1389 val
= *compute_motion (start
, 0, lmargin
, ZV
,
1390 height
, - (1 << (SHORTBITS
- 1)),
1391 width
, hscroll
, pos_tab_offset (w
, start
));
1392 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
1394 if (XFASTINT (w
->window_end_pos
)
1402 /* Copy glyphs from the rope FROM to T.
1403 But don't actually copy the parts that would come in before S.
1404 Value is T, advanced past the copied data.
1406 Characters in FROM are grouped into units of `sizeof GLYPH' chars;
1407 any extra chars at the end of FROM are ignored. */
1410 copy_rope (t
, s
, from
)
1411 register GLYPH
*t
; /* Copy to here. */
1412 register GLYPH
*s
; /* Starting point. */
1413 Lisp_Object from
; /* Data to copy; known to be a string. */
1415 register int n
= XSTRING (from
)->size
/ sizeof (GLYPH
);
1416 register GLYPH
*f
= (GLYPH
*) XSTRING (from
)->data
;
1420 if (t
>= s
) *t
= *f
;
1427 /* Display one line of window w, starting at position START in W's buffer.
1428 Display starting at horizontal position HPOS, which is normally zero
1429 or negative. A negative value causes output up to hpos = 0 to be discarded.
1430 This is done for negative hscroll, or when this is a continuation line
1431 and the continuation occurred in the middle of a multi-column character.
1433 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
1435 Display on position VPOS on the screen. (origin 0).
1437 Returns a STRUCT POSITION giving character to start next line with
1438 and where to display it, including a zero or negative hpos.
1439 The vpos field is not really a vpos; it is 1 unless the line is continued */
1441 struct position val_display_text_line
;
1443 static struct position
*
1444 display_text_line (w
, start
, vpos
, hpos
, taboffset
)
1451 register int pos
= start
;
1456 register unsigned char *p
;
1458 register GLYPH
*startp
;
1459 register GLYPH
*p1prev
;
1460 SCREEN_PTR s
= XSCREEN (w
->screen
);
1461 int tab_width
= XINT (current_buffer
->tab_width
);
1462 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
1463 int width
= XFASTINT (w
->width
) - 1
1464 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
1465 struct position val
;
1468 int hscroll
= XINT (w
->hscroll
);
1469 int truncate
= hscroll
1470 || (truncate_partial_width_windows
1471 && XFASTINT (w
->width
) < SCREEN_WIDTH (s
))
1472 || !NILP (current_buffer
->truncate_lines
);
1474 = XTYPE (current_buffer
->selective_display
) == Lisp_Int
1475 ? XINT (current_buffer
->selective_display
)
1476 : !NILP (current_buffer
->selective_display
) ? -1 : 0;
1478 int selective_e
= selective
&& !NILP (current_buffer
->selective_display_ellipses
);
1480 register struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (s
);
1481 register struct Lisp_Vector
*dp
= window_display_table (w
);
1483 = (selective
&& dp
&& XTYPE (DISP_INVIS_ROPE (dp
)) == Lisp_String
1484 ? XSTRING (DISP_INVIS_ROPE (dp
))->size
/ sizeof (GLYPH
) : 0);
1485 GLYPH truncator
= (dp
== 0 || XTYPE (DISP_TRUNC_GLYPH (dp
)) != Lisp_Int
1486 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
1487 GLYPH continuer
= (dp
== 0 || XTYPE (DISP_CONTINUE_GLYPH (dp
)) != Lisp_Int
1488 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
1490 hpos
+= XFASTINT (w
->left
);
1491 get_display_line (s
, vpos
, XFASTINT (w
->left
));
1492 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
1494 if (MINI_WINDOW_P (w
) && start
== 1
1495 && vpos
== XFASTINT (w
->top
))
1498 hpos
= display_string (w
, vpos
, minibuf_prompt
, hpos
,
1499 (!truncate
? continuer
: truncator
),
1501 minibuf_prompt_width
= hpos
;
1504 desired_glyphs
->bufp
[vpos
] = pos
;
1505 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
1507 startp
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
1508 endp
= startp
+ width
;
1510 /* Loop generating characters.
1511 Stop at end of buffer, before newline,
1512 or if reach or pass continuation column. */
1522 if (pos
== point
&& cursor_vpos
< 0)
1525 cursor_hpos
= p1
- startp
;
1529 if (pos
< point
&& point
< pause
)
1531 if (pos
< GPT
&& GPT
< pause
)
1534 p
= &FETCH_CHAR (pos
);
1537 if (c
>= 040 && c
< 0177
1538 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
1549 && position_indentation (pos
+ 1) >= selective
)
1552 pos
= find_next_newline (pos
+ 1, 1);
1553 if (FETCH_CHAR (pos
- 1) == '\n')
1556 if (invis
&& selective_rlen
> 0 && p1
>= startp
)
1558 p1
+= selective_rlen
;
1559 if (p1
- startp
> width
)
1561 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1562 (p1
- p1prev
) * sizeof (GLYPH
));
1570 if (p1
>= startp
&& p1
< endp
)
1574 while ((p1
- startp
+ taboffset
+ hscroll
- (hscroll
> 0))
1577 else if (c
== Ctl ('M') && selective
== -1)
1579 pos
= find_next_newline (pos
, 1);
1580 if (FETCH_CHAR (pos
- 1) == '\n')
1582 if (selective_rlen
> 0)
1584 p1
+= selective_rlen
;
1585 if (p1
- startp
> width
)
1587 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1588 (p1
- p1prev
) * sizeof (GLYPH
));
1592 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
1594 p1
= copy_rope (p1
, startp
, DISP_CHAR_ROPE (dp
, c
));
1596 else if (c
< 0200 && ctl_arrow
)
1599 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
1600 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
1602 if (p1
>= startp
&& p1
< endp
)
1609 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
1610 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
1612 if (p1
>= startp
&& p1
< endp
)
1613 *p1
= (c
>> 6) + '0';
1615 if (p1
>= startp
&& p1
< endp
)
1616 *p1
= (7 & (c
>> 3)) + '0';
1618 if (p1
>= startp
&& p1
< endp
)
1619 *p1
= (7 & c
) + '0';
1625 val
.hpos
= - XINT (w
->hscroll
);
1633 /* Handle continuation in middle of a character */
1634 /* by backing up over it */
1637 /* Start the next line with that same character */
1639 /* but at a negative hpos, to skip the columns output on this line. */
1640 val
.hpos
+= p1prev
- endp
;
1641 /* Keep in this line everything up to the continuation column. */
1645 /* Finish deciding which character to start the next line on,
1646 and what hpos to start it at.
1647 Also set `lastpos' to the last position which counts as "on this line"
1648 for cursor-positioning. */
1652 if (FETCH_CHAR (pos
) == '\n')
1653 /* If stopped due to a newline, start next line after it */
1656 /* Stopped due to right margin of window */
1661 /* Truncating => start next line after next newline,
1662 and point is on this line if it is before the newline,
1663 and skip none of first char of next line */
1664 pos
= find_next_newline (pos
, 1);
1665 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
1667 lastpos
= pos
- (FETCH_CHAR (pos
- 1) == '\n');
1678 /* If point is at eol or in invisible text at eol,
1679 record its screen location now. */
1681 if (start
<= point
&& point
<= lastpos
&& cursor_vpos
< 0)
1684 cursor_hpos
= p1
- startp
;
1687 if (cursor_vpos
== vpos
)
1689 if (cursor_hpos
< 0) cursor_hpos
= 0;
1690 if (cursor_hpos
> width
) cursor_hpos
= width
;
1691 cursor_hpos
+= XFASTINT (w
->left
);
1692 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
1694 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1695 SCREEN_CURSOR_X (s
) = cursor_hpos
;
1697 if (w
== XWINDOW (selected_window
))
1699 /* Line is not continued and did not start
1700 in middle of character */
1701 if ((hpos
- XFASTINT (w
->left
)
1702 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1705 this_line_bufpos
= start
;
1706 this_line_buffer
= current_buffer
;
1707 this_line_vpos
= cursor_vpos
;
1708 this_line_start_hpos
= hpos
;
1709 this_line_endpos
= Z
- lastpos
;
1712 this_line_bufpos
= 0;
1717 /* If hscroll and line not empty, insert truncation-at-left marker */
1718 if (hscroll
&& lastpos
!= start
)
1720 *startp
= truncator
;
1725 if (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
))
1728 if (p1
< startp
) p1
= startp
;
1729 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
1732 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
1733 p1
- desired_glyphs
->glyphs
[vpos
]);
1734 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
1736 /* If the start of this line is the overlay arrow-position,
1737 then put the arrow string into the display-line. */
1739 if (XTYPE (Voverlay_arrow_position
) == Lisp_Marker
1740 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
1741 && start
== marker_position (Voverlay_arrow_position
)
1742 && XTYPE (Voverlay_arrow_string
) == Lisp_String
1743 && ! overlay_arrow_seen
)
1745 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
1747 int len
= XSTRING (Voverlay_arrow_string
)->size
;
1749 if (len
> XFASTINT (w
->width
) - 1)
1750 len
= XFASTINT (w
->width
) - 1;
1751 for (i
= 0; i
< len
; i
++)
1753 if (desired_glyphs
->used
[vpos
] <
1754 (len
+ startp
- desired_glyphs
->glyphs
[vpos
]))
1755 desired_glyphs
->used
[vpos
] = len
+ startp
- desired_glyphs
->glyphs
[vpos
];
1757 overlay_arrow_seen
= 1;
1761 val_display_text_line
= val
;
1762 return &val_display_text_line
;
1765 /* Display the mode line for window w */
1768 display_mode_line (w
)
1771 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
1772 register int left
= XFASTINT (w
->left
);
1773 register int right
= XFASTINT (w
->width
) + left
;
1774 register SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (w
));
1776 get_display_line (s
, vpos
, left
);
1777 display_mode_element (w
, vpos
, left
, 0, right
, right
,
1778 current_buffer
->mode_line_format
);
1779 SCREEN_DESIRED_GLYPHS (s
)->bufp
[vpos
] = 0;
1781 /* Make the mode line inverse video if the entire line
1782 is made of mode lines.
1783 I.e. if this window is full width,
1784 or if it is the child of a full width window
1785 (which implies that that window is split side-by-side
1786 and the rest of this line is mode lines of the sibling windows). */
1787 if (XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
1788 || XFASTINT (XWINDOW (w
->parent
)->width
) == SCREEN_WIDTH (s
))
1789 s
->desired_glyphs
->highlight
[vpos
] = mode_line_inverse_video
;
1791 #ifdef HAVE_X_WINDOWS
1792 /* I'm trying this out because I saw Unimpress use it, but it's
1793 possible that this may mess adversely with some window managers. jla */
1796 && ! SCREEN_MINIBUF_ONLY_P (s
)
1797 && w
== XWINDOW (s
->selected_window
)
1798 && (NILP (Fstring_equal (XBUFFER (w
->buffer
)->name
, s
->name
))))
1799 x_set_name (s
, XBUFFER (w
->buffer
)->name
, Qnil
);
1803 /* Contribute ELT to the mode line for window W.
1804 How it translates into text depends on its data type.
1806 VPOS is the position of the mode line being displayed.
1808 HPOS is the position (absolute on screen) where this element's text
1809 should start. The output is truncated automatically at the right
1812 DEPTH is the depth in recursion. It is used to prevent
1813 infinite recursion here.
1815 MINENDCOL is the hpos before which the element may not end.
1816 The element is padded at the right with spaces if nec
1817 to reach this column.
1819 MAXENDCOL is the hpos past which this element may not extend.
1820 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
1821 (This is necessary to make nested padding and truncation work.)
1823 Returns the hpos of the end of the text generated by ELT.
1824 The next element will receive that value as its HPOS arg,
1825 so as to concatenate the elements. */
1828 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
1830 register int vpos
, hpos
;
1833 register int maxendcol
;
1834 register Lisp_Object elt
;
1842 #ifdef SWITCH_ENUM_BUG
1843 switch ((int) XTYPE (elt
))
1845 switch (XTYPE (elt
))
1850 /* A string: output it and check for %-constructs within it. */
1851 register unsigned char c
;
1852 register unsigned char *this = XSTRING (elt
)->data
;
1854 while (hpos
< maxendcol
&& *this)
1856 unsigned char *last
= this;
1857 while ((c
= *this++) != '\0' && c
!= '%')
1859 if (this - 1 != last
)
1861 register int lim
= --this - last
+ hpos
;
1862 hpos
= display_string (w
, vpos
, last
, hpos
, 0, hpos
,
1863 min (lim
, maxendcol
));
1867 register int spec_width
= 0;
1869 /* We can't allow -ve args due to the "%-" construct */
1870 /* Argument specifies minwidth but not maxwidth
1871 (maxwidth can be specified by
1872 (<negative-number> . <stuff>) mode-line elements) */
1874 while ((c
= *this++) >= '0' && c
<= '9')
1876 spec_width
= spec_width
* 10 + (c
- '0');
1880 if (spec_width
> maxendcol
)
1881 spec_width
= maxendcol
;
1884 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1885 spec_width
, maxendcol
,
1886 Vglobal_mode_string
);
1888 hpos
= display_string (w
, vpos
,
1889 decode_mode_spec (w
, c
,
1891 hpos
, 0, spec_width
, maxendcol
);
1898 /* A symbol: process the value of the symbol recursively
1899 as if it appeared here directly. Avoid error if symbol void.
1900 Special case: if value of symbol is a string, output the string
1903 register Lisp_Object tem
;
1904 tem
= Fboundp (elt
);
1907 tem
= Fsymbol_value (elt
);
1908 /* If value is a string, output that string literally:
1909 don't check for % within it. */
1910 if (XTYPE (tem
) == Lisp_String
)
1911 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
1912 hpos
, 0, minendcol
, maxendcol
);
1913 /* Give up right away for nil or t. */
1914 else if (!EQ (tem
, elt
))
1915 { elt
= tem
; goto tail_recurse
; }
1922 register Lisp_Object car
, tem
;
1924 /* A cons cell: three distinct cases.
1925 If first element is a string or a cons, process all the elements
1926 and effectively concatenate them.
1927 If first element is a negative number, truncate displaying cdr to
1928 at most that many characters. If positive, pad (with spaces)
1929 to at least that many characters.
1930 If first element is a symbol, process the cadr or caddr recursively
1931 according to whether the symbol's value is non-nil or nil. */
1932 car
= XCONS (elt
)->car
;
1933 if (XTYPE (car
) == Lisp_Symbol
)
1935 tem
= Fboundp (car
);
1936 elt
= XCONS (elt
)->cdr
;
1937 if (XTYPE (elt
) != Lisp_Cons
)
1939 /* elt is now the cdr, and we know it is a cons cell.
1940 Use its car if CAR has a non-nil value. */
1943 tem
= Fsymbol_value (car
);
1945 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
1947 /* Symbol's value is nil (or symbol is unbound)
1948 Get the cddr of the original list
1949 and if possible find the caddr and use that. */
1950 elt
= XCONS (elt
)->cdr
;
1953 else if (XTYPE (elt
) != Lisp_Cons
)
1955 elt
= XCONS (elt
)->car
;
1958 else if (XTYPE (car
) == Lisp_Int
)
1960 register int lim
= XINT (car
);
1961 elt
= XCONS (elt
)->cdr
;
1963 /* Negative int means reduce maximum width.
1964 DO NOT change MINENDCOL here!
1965 (20 -10 . foo) should truncate foo to 10 col
1966 and then pad to 20. */
1967 maxendcol
= min (maxendcol
, hpos
- lim
);
1970 /* Padding specified. Don't let it be more than
1973 if (lim
> maxendcol
)
1975 /* If that's more padding than already wanted, queue it.
1976 But don't reduce padding already specified even if
1977 that is beyond the current truncation point. */
1978 if (lim
> minendcol
)
1983 else if (XTYPE (car
) == Lisp_String
|| XTYPE (car
) == Lisp_Cons
)
1985 register int limit
= 50;
1986 /* LIMIT is to protect against circular lists. */
1987 while (XTYPE (elt
) == Lisp_Cons
&& --limit
> 0
1988 && hpos
< maxendcol
)
1990 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1993 elt
= XCONS (elt
)->cdr
;
2001 return (display_string (w
, vpos
, "*invalid*", hpos
, 0,
2002 minendcol
, maxendcol
));
2006 if (minendcol
> hpos
)
2007 hpos
= display_string (w
, vpos
, "", hpos
, 0, minendcol
, -1);
2011 /* Return a string for the output of a mode line %-spec for window W,
2012 generated by character C and width MAXWIDTH. */
2015 decode_mode_spec (w
, c
, maxwidth
)
2018 register int maxwidth
;
2020 Lisp_Object obj
= Qnil
;
2021 SCREEN_PTR scr
= XSCREEN (WINDOW_SCREEN (w
));
2022 char *decode_mode_spec_buf
= (char *) SCREEN_TEMP_GLYPHS (scr
)->total_contents
;
2024 if (maxwidth
> SCREEN_WIDTH (scr
))
2025 maxwidth
= SCREEN_WIDTH (scr
);
2030 obj
= current_buffer
->name
;
2032 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
2034 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
2035 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
2036 decode_mode_spec_buf
[maxwidth
] = '\0';
2037 return decode_mode_spec_buf
;
2043 obj
= current_buffer
->filename
;
2047 else if (XTYPE (obj
) == Lisp_String
&& XSTRING (obj
)->size
> maxwidth
)
2049 bcopy ("...", decode_mode_spec_buf
, 3);
2050 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
2051 decode_mode_spec_buf
+ 3, maxwidth
- 3);
2052 return decode_mode_spec_buf
;
2058 obj
= current_buffer
->mode_name
;
2062 if (BEGV
> BEG
|| ZV
< Z
)
2067 if (!NILP (current_buffer
->read_only
))
2069 if (MODIFF
> current_buffer
->save_modified
)
2074 /* status of process */
2075 obj
= Fget_buffer_process (Fcurrent_buffer ());
2077 return "no process";
2078 obj
= Fsymbol_name (Fprocess_status (obj
));
2083 int pos
= marker_position (w
->start
);
2084 int total
= ZV
- BEGV
;
2086 if (XFASTINT (w
->window_end_pos
) <= Z
- ZV
)
2093 else if (pos
<= BEGV
)
2097 total
= ((pos
- BEGV
) * 100 + total
- 1) / total
;
2098 /* We can't normally display a 3-digit number,
2099 so get us a 2-digit number that is close. */
2102 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
2103 return decode_mode_spec_buf
;
2115 if (command_loop_level
> 5)
2117 p
= decode_mode_spec_buf
;
2118 for (i
= 0; i
< command_loop_level
; i
++)
2121 return decode_mode_spec_buf
;
2129 if (command_loop_level
> 5)
2131 p
= decode_mode_spec_buf
;
2132 for (i
= 0; i
< command_loop_level
; i
++)
2135 return decode_mode_spec_buf
;
2140 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
2144 if (maxwidth
< sizeof (lots_of_dashes
))
2145 return lots_of_dashes
;
2148 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
2152 return decode_mode_spec_buf
;
2156 if (XTYPE (obj
) == Lisp_String
)
2157 return (char *) XSTRING (obj
)->data
;
2162 /* Display STRING on one line of window W, starting at HPOS.
2163 Display at position VPOS. Caller should have done get_display_line.
2165 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
2167 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
2168 MAXCOL is the last column ok to end at. Truncate here.
2169 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
2170 Both count from the left edge of the screen, as does HPOS.
2171 The right edge of W is an implicit maximum.
2172 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
2174 Returns ending hpos */
2177 display_string (w
, vpos
, string
, hpos
, truncate
, mincol
, maxcol
)
2179 unsigned char *string
;
2186 int hscroll
= XINT (w
->hscroll
);
2187 int tab_width
= XINT (current_buffer
->tab_width
);
2188 register GLYPH
*start
;
2189 register GLYPH
*end
;
2190 struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (XSCREEN (w
->screen
));
2191 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2192 int window_width
= XFASTINT (w
->width
);
2194 /* Use the standard display table, not the window's display table.
2195 We don't want the mode line in rot13. */
2196 register struct Lisp_Vector
*dp
= 0;
2198 if (XTYPE (Vstandard_display_table
) == Lisp_Vector
2199 && XVECTOR (Vstandard_display_table
)->size
== DISP_TABLE_SIZE
)
2200 dp
= XVECTOR (Vstandard_display_table
);
2202 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
2205 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
2206 end
= start
+ window_width
- (truncate
!= 0);
2208 if ((window_width
+ XFASTINT (w
->left
))
2209 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
2212 if (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
)
2213 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
2214 if (maxcol
>= 0 && mincol
> maxcol
)
2221 if (c
>= 040 && c
< 0177
2222 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
2232 if (p1
>= start
&& p1
< end
)
2236 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
2238 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
2239 p1
= copy_rope (p1
, start
, DISP_CHAR_ROPE (dp
, c
));
2240 else if (c
< 0200 && buffer_defaults
.ctl_arrow
)
2243 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
2244 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
2246 if (p1
>= start
&& p1
< end
)
2253 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
2254 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
2256 if (p1
>= start
&& p1
< end
)
2257 *p1
= (c
>> 6) + '0';
2259 if (p1
>= start
&& p1
< end
)
2260 *p1
= (7 & (c
>> 3)) + '0';
2262 if (p1
>= start
&& p1
< end
)
2263 *p1
= (7 & c
) + '0';
2271 if (truncate
) *p1
++ = truncate
;
2273 else if (mincol
>= 0)
2275 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
2281 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
2283 if (len
> desired_glyphs
->used
[vpos
])
2284 desired_glyphs
->used
[vpos
] = len
;
2285 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
2294 staticpro (&last_arrow_position
);
2295 staticpro (&last_arrow_string
);
2296 last_arrow_position
= Qnil
;
2297 last_arrow_string
= Qnil
;
2299 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
2300 "String displayed by mode-line-format's \"%m\" specifiation.");
2301 Vglobal_mode_string
= Qnil
;
2303 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
2304 "Marker for where to display an arrow on top of the buffer text.\n\
2305 This must be the beginning of a line in order to work.\n\
2306 See also `overlay-arrow-string'.");
2307 Voverlay_arrow_position
= Qnil
;
2309 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
2310 "String to display as an arrow. See also `overlay-arrow-position'.");
2311 Voverlay_arrow_string
= Qnil
;
2313 DEFVAR_INT ("scroll-step", &scroll_step
,
2314 "*The number of lines to try scrolling a window by when point moves out.\n\
2315 If that fails to bring point back on screen, point is centered instead.\n\
2316 If this is zero, point is always centered after it moves off screen.");
2318 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
2320 DEFVAR_BOOL ("truncate-partial-width-windows",
2321 &truncate_partial_width_windows
,
2322 "*Non-nil means truncate lines in all windows less than full screen wide.");
2323 truncate_partial_width_windows
= 1;
2325 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
2326 "*Non-nil means use inverse video for the mode line.");
2327 mode_line_inverse_video
= 1;
2329 #ifndef MULTI_SCREEN
2330 defsubr (&Sredraw_display
);
2331 #endif /* MULTI_SCREEN */
2334 /* initialize the window system */
2337 Lisp_Object root_window
;
2338 #ifndef COMPILER_REGISTER_BUG
2340 #endif /* COMPILER_REGISTER_BUG */
2341 struct window
*mini_w
;
2343 this_line_bufpos
= 0;
2345 mini_w
= XWINDOW (minibuf_window
);
2346 root_window
= mini_w
->prev
;
2348 echo_area_glyphs
= 0;
2349 previous_echo_glyphs
= 0;
2351 if (!noninteractive
)
2353 SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (XWINDOW (root_window
)));
2354 XFASTINT (XWINDOW (root_window
)->top
) = 0;
2355 set_window_height (root_window
, SCREEN_HEIGHT (s
) - 1, 0);
2356 XFASTINT (mini_w
->top
) = SCREEN_HEIGHT (s
) - 1;
2357 set_window_height (minibuf_window
, 1, 0);
2359 XFASTINT (XWINDOW (root_window
)->width
) = SCREEN_WIDTH (s
);
2360 XFASTINT (mini_w
->width
) = SCREEN_WIDTH (s
);