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 trapped by the condition-case
216 in command-line, so this must be just an informative message; toss it. */
217 else if (INTERACTIVE
&& SCREEN_MESSAGE_BUF (selected_screen
))
225 doprnt (SCREEN_MESSAGE_BUF (selected_screen
),
226 SCREEN_WIDTH (selected_screen
), m
, 0, 3, a
);
228 doprnt (SCREEN_MESSAGE_BUF (selected_screen
),
229 SCREEN_WIDTH (selected_screen
), m
, 0, 3, &a1
);
230 #endif /* NO_ARG_ARRAY */
232 echo_area_glyphs
= SCREEN_MESSAGE_BUF (selected_screen
);
234 /* Print should start at the beginning of the message
236 message_buf_print
= 0;
238 do_pending_window_change ();
239 echo_area_display ();
240 update_screen (XSCREEN (XWINDOW (minibuf_window
)->screen
), 1, 1);
241 do_pending_window_change ();
245 /* Specify m, a string, as a message in the minibuf. */
250 /* A null message buffer means that the screen hasn't really been
251 initialized yet; write the error message on the standard error
252 as if we were non-interactive. */
255 if (noninteractive_need_newline
)
257 noninteractive_need_newline
= 0;
258 fprintf (stderr
, "%s\n", m
);
261 /* A null message buffer means that the screen hasn't really been
262 initialized yet. Error messages get trapped by the condition-case
263 in command-line, so this must be just an informative message; toss it. */
264 else if (INTERACTIVE
&& SCREEN_MESSAGE_BUF (selected_screen
))
266 echo_area_glyphs
= m
;
267 do_pending_window_change ();
268 echo_area_display ();
269 update_screen (XSCREEN (XWINDOW (minibuf_window
)->screen
), 1, 1);
270 do_pending_window_change ();
281 choose_minibuf_screen ();
282 s
= XSCREEN (XWINDOW (minibuf_window
)->screen
);
294 if (echo_area_glyphs
|| minibuf_level
== 0)
296 vpos
= XFASTINT (XWINDOW (minibuf_window
)->top
);
297 get_display_line (s
, vpos
, 0);
298 display_string (XWINDOW (minibuf_window
), vpos
,
299 echo_area_glyphs
? echo_area_glyphs
: "",
300 0, 0, 0, SCREEN_WIDTH (s
));
302 /* If desired cursor location is on this line, put it at end of text */
303 if (SCREEN_CURSOR_Y (s
) == vpos
)
304 SCREEN_CURSOR_X (s
) = s
->desired_glyphs
->used
[vpos
];
306 else if (!EQ (minibuf_window
, selected_window
))
307 windows_or_buffers_changed
++;
309 if (EQ (minibuf_window
, selected_window
))
310 this_line_bufpos
= 0;
312 previous_echo_glyphs
= echo_area_glyphs
;
315 /* Do a screen update, taking possible shortcuts into account.
316 This is the main external entry point for redisplay.
318 If the last redisplay displayed an echo area message and that
319 message is no longer requested, we clear the echo area
320 or bring back the minibuffer if that is in use.
322 Everyone would like to have a hook here to call eval,
323 but that cannot be done safely without a lot of changes elsewhere.
324 This can be called from signal handlers; with alarms set up;
325 or with synchronous processes running.
326 See the function `echo' in keyboard.c.
327 See Fcall_process; if you called it from here, it could be
328 entered recursively. */
333 register struct window
*w
= XWINDOW (selected_window
);
337 register int tlbufpos
, tlendpos
;
339 extern int input_pending
;
344 /* Notice any pending interrupt request to change screen size. */
345 do_pending_window_change ();
353 /* Normally the message* functions will have already displayed and
354 updated the echo area, but the screen may have been trashed, or
355 the update may have been preempted, so display the echo area
357 if (echo_area_glyphs
|| previous_echo_glyphs
)
359 echo_area_display ();
363 if (clip_changed
|| windows_or_buffers_changed
)
366 /* Detect case that we need to write a star in the mode line. */
367 if (XFASTINT (w
->last_modified
) < MODIFF
368 && XFASTINT (w
->last_modified
) <= current_buffer
->save_modified
)
370 w
->update_mode_line
= Qt
;
371 if (buffer_shared
> 1)
375 SCREEN_SCROLL_BOTTOM_VPOS (XSCREEN (w
->screen
)) = -1;
377 all_windows
= update_mode_lines
|| buffer_shared
> 1;
379 /* If specs for an arrow have changed, do thorough redisplay
380 to ensure we remove any arrow that should no longer exist. */
381 if (Voverlay_arrow_position
!= last_arrow_position
382 || Voverlay_arrow_string
!= last_arrow_string
)
383 all_windows
= 1, clip_changed
= 1;
385 tlbufpos
= this_line_bufpos
;
386 tlendpos
= this_line_endpos
;
387 if (!all_windows
&& tlbufpos
> 0 && NULL (w
->update_mode_line
)
388 && SCREEN_VISIBLE_P (XSCREEN (w
->screen
))
389 /* Make sure recorded data applies to current buffer, etc */
390 && this_line_buffer
== current_buffer
391 && current_buffer
== XBUFFER (w
->buffer
)
392 && NULL (w
->force_start
)
393 /* Point must be on the line that we have info recorded about */
395 && point
<= Z
- tlendpos
396 /* All text outside that line, including its final newline,
398 && (XFASTINT (w
->last_modified
) >= MODIFF
399 || (beg_unchanged
>= tlbufpos
- 1
401 && end_unchanged
>= tlendpos
402 && Z
- GPT
>= tlendpos
)))
404 if (tlbufpos
> BEGV
&& FETCH_CHAR (tlbufpos
- 1) != '\n'
406 || FETCH_CHAR (tlbufpos
) == '\n'))
407 /* Former continuation line has disappeared by becoming empty */
409 else if (XFASTINT (w
->last_modified
) < MODIFF
410 || MINI_WINDOW_P (w
))
413 overlay_arrow_seen
= 0;
414 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
415 pos_tab_offset (w
, tlbufpos
));
416 /* If line contains point, is not continued,
417 and ends at same distance from eob as before, we win */
418 if (cursor_vpos
>= 0 && this_line_bufpos
419 && this_line_endpos
== tlendpos
)
421 if (XFASTINT (w
->width
) != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
422 preserve_other_columns (w
);
428 else if (point
== XFASTINT (w
->last_point
))
432 do_pending_window_change ();
439 pos
= *compute_motion (tlbufpos
, 0,
440 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
441 point
, 2, - (1 << (SHORTBITS
- 1)),
442 XFASTINT (w
->width
) - 1
443 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
444 != SCREEN_WIDTH (selected_screen
)),
445 XINT (w
->hscroll
), 0);
448 SCREEN_CURSOR_X (selected_screen
)
449 = XFASTINT (w
->left
) + max (pos
.hpos
, 0);
450 SCREEN_CURSOR_Y (selected_screen
) = this_line_vpos
;
457 /* Text changed drastically or point moved off of line */
458 cancel_line (this_line_vpos
, selected_screen
);
461 this_line_bufpos
= 0;
462 all_windows
|= buffer_shared
> 1;
469 /* Recompute # windows showing selected buffer.
470 This will be increment each time such a window is displayed. */
473 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
477 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
480 s
= XSCREEN (XCONS (tail
)->car
);
484 /* Clear the echo area on screens where the minibuffer isn't. */
485 if (s
!= XSCREEN (XWINDOW (minibuf_window
)->screen
)
486 /* But only screens that have minibuffers. */
487 && s
->has_minibuffer
)
489 int vpos
= XFASTINT (XWINDOW (s
->minibuffer_window
)->top
);
490 register struct screen_glyphs
*line
;
492 get_display_line (s
, vpos
, 0);
493 display_string (XWINDOW (s
->minibuffer_window
), vpos
, "",
497 /* Redraw its windows. */
498 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
502 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
503 #endif /* not MULTI_SCREEN */
505 else if (SCREEN_VISIBLE_P (selected_screen
))
507 redisplay_window (selected_window
, 1);
508 if (XFASTINT (w
->width
) != SCREEN_WIDTH (selected_screen
))
509 preserve_other_columns (w
);
513 /* Prevent various kinds of signals during display update.
514 stdio is not robust about handling signals,
515 which can cause an apparent I/O error. */
527 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
531 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
534 s
= XSCREEN (XCONS (tail
)->car
);
537 pause
|= update_screen (s
, 0, 0, SCREEN_SCROLL_BOTTOM_VPOS (s
));
539 mark_window_display_accurate (s
->root_window
, 1);
544 #endif /* MULTI_SCREEN */
546 if (SCREEN_VISIBLE_P (selected_screen
))
547 pause
= update_screen (selected_screen
, 0, 0);
550 /* We called echo_area_display at the top of this function. If
551 the echo area is on another screen, that may have put text on
552 a screen other than the selected one, so the above call to
553 update_screen would not have caught it. Catch it here. */
554 if (echo_area_glyphs
|| previous_echo_glyphs
)
556 SCREEN_PTR mini_screen
=
557 XSCREEN (WINDOW_SCREEN (XWINDOW (minibuf_window
)));
559 if (mini_screen
!= selected_screen
)
560 pause
|= update_screen (mini_screen
, 0, 0);
565 /* If screen does not match, prevent doing single-line-update next time.
566 Also, don't forget to check every line to update the arrow. */
569 this_line_bufpos
= 0;
570 if (!NULL (last_arrow_position
))
572 last_arrow_position
= Qt
;
573 last_arrow_string
= Qt
;
575 /* If we pause after scrolling, some lines in current_screen
576 may be null, so preserve_other_columns won't be able to
577 preserve all the vertical-bar separators. So, avoid using it
579 if (XFASTINT (w
->width
) != SCREEN_WIDTH (selected_screen
))
580 update_mode_lines
= 1;
583 /* Now text on screen agrees with windows, so
584 put info into the windows for partial redisplay to follow */
588 register struct buffer
*b
= XBUFFER (w
->buffer
);
590 blank_end_of_window
= 0;
592 unchanged_modified
= BUF_MODIFF (b
);
593 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
594 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
596 XFASTINT (w
->last_point
) = BUF_PT (b
);
597 XFASTINT (w
->last_point_x
) = SCREEN_CURSOR_X (selected_screen
);
598 XFASTINT (w
->last_point_y
) = SCREEN_CURSOR_Y (selected_screen
);
601 mark_window_display_accurate (XWINDOW (minibuf_window
)->prev
, 1);
604 w
->update_mode_line
= Qnil
;
605 XFASTINT (w
->last_modified
) = BUF_MODIFF (b
);
606 w
->window_end_valid
= Qt
;
607 last_arrow_position
= Voverlay_arrow_position
;
608 last_arrow_string
= Voverlay_arrow_string
;
610 update_mode_lines
= 0;
611 windows_or_buffers_changed
= 0;
614 /* Start SIGIO interrupts coming again.
615 Having them off during the code above
616 makes it less likely one will discard output,
617 but not impossible, since there might be stuff
618 in the system buffer here.
619 But it is much hairier to try to do anything about that. */
625 /* Change screen size now if a change is pending. */
626 do_pending_window_change ();
629 /* Redisplay, but leave alone any recent echo area message
630 unless another message has been requested in its place.
632 This is useful in situations where you need to redisplay but no
633 user action has occurred, making it inappropriate for the message
634 area to be cleared. See tracking_off and
635 wait_reading_process_input for examples of these situations. */
637 redisplay_preserve_echo_area ()
639 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
641 echo_area_glyphs
= previous_echo_glyphs
;
643 echo_area_glyphs
= 0;
650 mark_window_display_accurate (window
, flag
)
654 register struct window
*w
;
656 for (;!NULL (window
); window
= w
->next
)
658 w
= XWINDOW (window
);
660 if (!NULL (w
->buffer
))
661 XFASTINT (w
->last_modified
)
663 : XBUFFER (w
->buffer
) == current_buffer
664 ? MODIFF
: BUF_MODIFF (XBUFFER (w
->buffer
));
665 w
->window_end_valid
= Qt
;
666 w
->update_mode_line
= Qnil
;
668 if (!NULL (w
->vchild
))
669 mark_window_display_accurate (w
->vchild
, flag
);
670 if (!NULL (w
->hchild
))
671 mark_window_display_accurate (w
->hchild
, flag
);
676 last_arrow_position
= Voverlay_arrow_position
;
677 last_arrow_string
= Voverlay_arrow_string
;
681 /* t is unequal to any useful value of Voverlay_arrow_... */
682 last_arrow_position
= Qt
;
683 last_arrow_string
= Qt
;
690 redisplay_windows (window
)
693 for (; !NULL (window
); window
= XWINDOW (window
)->next
)
694 redisplay_window (window
, 0);
698 redisplay_window (window
, just_this_one
)
702 register struct window
*w
= XWINDOW (window
);
703 SCREEN_PTR s
= XSCREEN (w
->screen
);
705 register int lpoint
= point
;
706 struct buffer
*old
= current_buffer
;
707 register int width
= XFASTINT (w
->width
) - 1
708 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
709 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))));
711 register int hscroll
= XINT (w
->hscroll
);
715 int window_needs_modeline
;
717 if (SCREEN_HEIGHT (s
) == 0) abort (); /* Some bug zeros some core */
719 /* If this is a combination window, do its children; that's all. */
721 if (!NULL (w
->vchild
))
723 redisplay_windows (w
->vchild
);
726 if (!NULL (w
->hchild
))
728 redisplay_windows (w
->hchild
);
731 if (NULL (w
->buffer
))
734 if (update_mode_lines
)
735 w
->update_mode_line
= Qt
;
737 /* Otherwise set up data on this window; select its buffer and point value */
739 height
= window_internal_height (w
);
741 if (MINI_WINDOW_P (w
)
743 /* Don't display minibuffers except minibuf_window. */
744 || w
!= XWINDOW (minibuf_window
)))
747 current_buffer
= XBUFFER (w
->buffer
);
750 /* Count number of windows showing the selected buffer. */
753 && current_buffer
== XBUFFER (XWINDOW (selected_window
)->buffer
))
756 /* POINT refers normally to the selected window.
757 For any other window, set up appropriate value. */
759 if (!EQ (window
, selected_window
))
761 SET_PT (marker_position (w
->pointm
));
765 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
767 else if (point
> (ZV
- 1))
770 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
774 /* If window-start is screwed up, choose a new one. */
776 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
779 startp
= marker_position (w
->start
);
781 /* Handle case where place to start displaying has been specified */
783 if (!NULL (w
->force_start
))
785 w
->update_mode_line
= Qt
;
786 w
->force_start
= Qnil
;
787 XFASTINT (w
->last_modified
) = 0;
788 try_window (window
, startp
);
791 /* If point does not appear, move point so it does appear */
792 pos
= *compute_motion (startp
, 0,
793 ((EQ (window
, minibuf_window
) && startp
== 1)
794 ? minibuf_prompt_width
: 0)
796 (hscroll
? 1 - hscroll
: 0),
798 - (1 << (SHORTBITS
- 1)),
799 width
, hscroll
, pos_tab_offset (w
, startp
));
801 if (w
!= XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
802 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
806 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
807 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
813 /* Handle case where text has not changed, only point,
814 and it has not moved off the screen */
816 /* This code is not used for minibuffer for the sake of
817 the case of redisplaying to replace an echo area message;
818 since in that case the minibuffer contents per se are usually unchanged.
819 This code is of no real use in the minibuffer since
820 the handling of this_line_bufpos, etc.,
821 in redisplay handles the same cases. */
823 if (XFASTINT (w
->last_modified
) >= MODIFF
824 && point
>= startp
&& !clip_changed
825 && (just_this_one
|| XFASTINT (w
->width
) == SCREEN_WIDTH (s
))
826 && !EQ (window
, minibuf_window
))
828 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0),
829 point
, height
+ 1, 10000, width
, hscroll
,
830 pos_tab_offset (w
, startp
));
832 if (pos
.vpos
< height
)
834 /* Ok, point is still on screen */
835 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
837 /* These variables are supposed to be origin 1 */
838 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
839 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
841 /* This doesn't do the trick, because if a window to the right of
842 this one must be redisplayed, this does nothing because there
843 is nothing in DesiredScreen yet, and then the other window is
844 redisplayed, making likes that are empty in this window's columns.
845 if (XFASTINT (w->width) != SCREEN_WIDTH (s))
846 preserve_my_columns (w);
850 /* Don't bother trying redisplay with same start;
851 we already know it will lose */
853 /* If current starting point was originally the beginning of a line
854 but no longer is, find a new starting point. */
855 else if (!NULL (w
->start_at_line_beg
)
857 || FETCH_CHAR (startp
- 1) == '\n'))
861 else if (just_this_one
&& !MINI_WINDOW_P (w
)
863 && XFASTINT (w
->last_modified
)
864 && ! EQ (w
->window_end_valid
, Qnil
)
865 && do_id
&& !clip_changed
866 && !blank_end_of_window
867 && XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
868 && EQ (last_arrow_position
, Voverlay_arrow_position
)
869 && EQ (last_arrow_string
, Voverlay_arrow_string
)
870 && (tem
= try_window_id (SCREEN_SELECTED_WINDOW (s
)))
873 /* tem > 0 means success. tem == -1 means choose new start.
874 tem == -2 means try again with same start,
875 and nothing but whitespace follows the changed stuff.
876 tem == 0 means try again with same start. */
880 else if (startp
>= BEGV
&& startp
<= ZV
881 /* Avoid starting display at end of buffer! */
882 && (startp
<= ZV
|| startp
== BEGV
883 || (XFASTINT (w
->last_modified
) >= MODIFF
)))
885 /* Try to redisplay starting at same place as before */
886 /* If point has not moved off screen, accept the results */
887 try_window (window
, startp
);
888 if (cursor_vpos
>= 0)
891 cancel_my_columns (w
);
894 XFASTINT (w
->last_modified
) = 0;
895 w
->update_mode_line
= Qt
;
897 /* Try to scroll by specified few lines */
899 if (scroll_step
&& !clip_changed
)
903 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
904 scroll_step
, width
, hscroll
, window
);
905 if (pos
.vpos
>= height
)
909 pos
= *vmotion (startp
, point
< startp
? - scroll_step
: scroll_step
,
910 width
, hscroll
, window
);
912 if (point
>= pos
.bufpos
)
914 try_window (window
, pos
.bufpos
);
915 if (cursor_vpos
>= 0)
918 cancel_my_columns (w
);
923 /* Finally, just choose place to start which centers point */
926 pos
= *vmotion (point
, - height
/ 2, width
, hscroll
, window
);
927 try_window (window
, pos
.bufpos
);
929 startp
= marker_position (w
->start
);
930 w
->start_at_line_beg
=
931 (startp
== BEGV
|| FETCH_CHAR (startp
- 1) == '\n') ? Qt
: Qnil
;
934 /* If window not full width, must redo its mode line
935 if the window to its side is being redone */
936 if ((!NULL (w
->update_mode_line
)
937 || (!just_this_one
&& width
< SCREEN_WIDTH (s
) - 1))
938 && height
!= XFASTINT (w
->height
))
939 display_mode_line (w
);
942 current_buffer
= old
;
946 /* Do full redisplay on one window, starting at position `pos'. */
949 try_window (window
, pos
)
953 register struct window
*w
= XWINDOW (window
);
954 register int height
= window_internal_height (w
);
955 register int vpos
= XFASTINT (w
->top
);
956 register int last_text_vpos
= vpos
;
957 int tab_offset
= pos_tab_offset (w
, pos
);
958 SCREEN_PTR s
= XSCREEN (w
->screen
);
959 int width
= XFASTINT (w
->width
) - 1
960 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
963 Fset_marker (w
->start
, make_number (pos
), Qnil
);
965 overlay_arrow_seen
= 0;
966 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
968 while (--height
>= 0)
970 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, tab_offset
);
972 if (val
.vpos
) tab_offset
= 0;
974 if (pos
!= val
.bufpos
)
976 /* Next line, unless prev line ended in end of buffer with no cr */
977 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
981 /* If last line is continued in middle of character,
982 include the split character in the text considered on the screen */
983 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
986 /* If bottom just moved off end of screen, change mode line percentage. */
987 if (XFASTINT (w
->window_end_pos
) == 0
989 w
->update_mode_line
= Qt
;
991 /* Say where last char on screen will be, once redisplay is finished. */
992 XFASTINT (w
->window_end_pos
) = Z
- pos
;
993 XFASTINT (w
->window_end_vpos
) = last_text_vpos
- XFASTINT (w
->top
);
994 /* But that is not valid info until redisplay finishes. */
995 w
->window_end_valid
= Qnil
;
998 /* Try to redisplay when buffer is modified locally,
999 computing insert/delete line to preserve text outside
1000 the bounds of the changes.
1001 Return 1 if successful, 0 if if cannot tell what to do,
1002 or -1 to tell caller to find a new window start,
1003 or -2 to tell caller to do normal redisplay with same window start. */
1006 try_window_id (window
)
1010 register struct window
*w
= XWINDOW (window
);
1011 register int height
= window_internal_height (w
);
1012 SCREEN_PTR s
= XSCREEN (w
->screen
);
1013 int top
= XFASTINT (w
->top
);
1014 int start
= marker_position (w
->start
);
1015 int width
= XFASTINT (w
->width
) - 1
1016 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
1017 int hscroll
= XINT (w
->hscroll
);
1018 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
1020 register int i
, tem
;
1021 int last_text_vpos
= 0;
1024 struct position val
, bp
, ep
, xp
, pp
;
1025 int scroll_amount
= 0;
1027 int tab_offset
, epto
;
1029 if (GPT
- BEG
< beg_unchanged
)
1030 beg_unchanged
= GPT
- BEG
;
1031 if (Z
- GPT
< end_unchanged
)
1032 end_unchanged
= Z
- GPT
;
1034 if (beg_unchanged
+ 1 < start
)
1035 return 0; /* Give up if changes go above top of window */
1037 /* Find position before which nothing is changed. */
1038 bp
= *compute_motion (start
, 0, lmargin
,
1039 beg_unchanged
+ 1, height
+ 1, 0, width
, hscroll
,
1040 pos_tab_offset (w
, start
));
1041 if (bp
.vpos
>= height
)
1043 if (point
< bp
.bufpos
&& !bp
.contin
)
1045 /* All changes are below the screen, and point is on the screen.
1046 We don't need to change the screen at all.
1047 But we need to update window_end_pos to account for
1048 any change in buffer size. */
1049 bp
= *compute_motion (start
, 0, lmargin
,
1051 width
, hscroll
, pos_tab_offset (w
, start
));
1052 XFASTINT (w
->window_end_vpos
) = height
;
1053 XFASTINT (w
->window_end_pos
) = Z
- bp
.bufpos
;
1061 /* Find beginning of that screen line. Must display from there. */
1062 bp
= *vmotion (bp
.bufpos
, 0, width
, hscroll
, window
);
1069 /* If about to start displaying at the beginning of a continuation line,
1070 really start with previous screen line, in case it was not
1071 continued when last redisplayed */
1072 if (bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
1074 bp
= *vmotion (bp
.bufpos
, -1, width
, hscroll
, window
);
1079 if (bp
.contin
&& bp
.hpos
!= lmargin
)
1081 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
1087 /* Find first visible newline after which no more is changed. */
1088 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
1089 if (XTYPE (current_buffer
->selective_display
) == Lisp_Int
1090 && XINT (current_buffer
->selective_display
) > 0)
1092 && (position_indentation (tem
)
1093 >= XINT (current_buffer
->selective_display
)))
1094 tem
= find_next_newline (tem
, 1);
1096 /* Compute the cursor position after that newline. */
1097 ep
= *compute_motion (pos
, vpos
, val
.hpos
, tem
,
1098 height
, - (1 << (SHORTBITS
- 1)),
1099 width
, hscroll
, pos_tab_offset (w
, bp
.bufpos
));
1101 /* If changes reach past the text available on the screen,
1102 just display rest of screen. */
1103 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
1106 stop_vpos
= ep
.vpos
;
1108 /* If no newline before ep, the line ep is on includes some changes
1109 that must be displayed. Make sure we don't stop before it. */
1110 /* Also, if changes reach all the way until ep.bufpos,
1111 it is possible that something was deleted after the
1112 newline before it, so the following line must be redrawn. */
1113 if (stop_vpos
== ep
.vpos
1114 && (ep
.bufpos
== BEGV
1115 || FETCH_CHAR (ep
.bufpos
- 1) != '\n'
1116 || ep
.bufpos
== Z
- end_unchanged
))
1117 stop_vpos
= ep
.vpos
+ 1;
1120 overlay_arrow_seen
= 0;
1122 /* If changes do not reach to bottom of window,
1123 figure out how much to scroll the rest of the window */
1124 if (stop_vpos
< height
)
1126 /* Now determine how far up or down the rest of the window has moved */
1127 epto
= pos_tab_offset (w
, ep
.bufpos
);
1128 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1129 Z
- XFASTINT (w
->window_end_pos
),
1130 10000, 0, width
, hscroll
, epto
);
1131 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
1133 /* Is everything on screen below the changes whitespace?
1134 If so, no scrolling is really necessary. */
1135 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
1137 tem
= FETCH_CHAR (i
);
1138 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
1144 XFASTINT (w
->window_end_vpos
) += scroll_amount
;
1146 /* Before doing any scrolling, verify that point will be on screen. */
1147 if (point
> ep
.bufpos
&& !(point
<= xp
.bufpos
&& xp
.bufpos
< height
))
1149 if (point
<= xp
.bufpos
)
1151 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1152 point
, height
, - (1 << (SHORTBITS
- 1)),
1153 width
, hscroll
, epto
);
1157 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
,
1158 point
, height
, - (1 << (SHORTBITS
- 1)),
1159 width
, hscroll
, pos_tab_offset (w
, xp
.bufpos
));
1161 if (pp
.bufpos
< point
|| pp
.vpos
== height
)
1163 cursor_vpos
= pp
.vpos
+ top
;
1164 cursor_hpos
= pp
.hpos
+ XFASTINT (w
->left
);
1167 if (stop_vpos
- scroll_amount
>= height
1168 || ep
.bufpos
== xp
.bufpos
)
1170 if (scroll_amount
< 0)
1171 stop_vpos
-= scroll_amount
;
1173 /* In this path, we have altered window_end_vpos
1174 and not left it negative.
1175 We must make sure that, in case display is preempted
1176 before the screen changes to reflect what we do here,
1177 further updates will not come to try_window_id
1178 and assume the screen and window_end_vpos match. */
1179 blank_end_of_window
= 1;
1181 else if (!scroll_amount
)
1183 else if (bp
.bufpos
== Z
- end_unchanged
)
1185 /* If reprinting everything is nearly as fast as scrolling,
1186 don't bother scrolling. Can happen if lines are short. */
1187 if (scroll_cost (s
, bp
.vpos
+ top
- scroll_amount
,
1188 top
+ height
- max (0, scroll_amount
),
1190 > xp
.bufpos
- bp
.bufpos
- 20)
1191 /* Return "try normal display with same window-start."
1192 Too bad we can't prevent further scroll-thinking. */
1194 /* If pure deletion, scroll up as many lines as possible.
1195 In common case of killing a line, this can save the
1196 following line from being overwritten by scrolling
1197 and therefore having to be redrawn. */
1198 tem
= scroll_screen_lines (s
, bp
.vpos
+ top
- scroll_amount
,
1199 top
+ height
- max (0, scroll_amount
),
1201 if (!tem
) stop_vpos
= height
;
1203 else if (scroll_amount
)
1205 /* If reprinting everything is nearly as fast as scrolling,
1206 don't bother scrolling. Can happen if lines are short. */
1207 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1208 overestimate of cost of reprinting, since xp.bufpos
1209 would end up below the bottom of the window. */
1210 if (scroll_cost (s
, ep
.vpos
+ top
- scroll_amount
,
1211 top
+ height
- max (0, scroll_amount
),
1213 > xp
.bufpos
- ep
.bufpos
- 20)
1214 /* Return "try normal display with same window-start."
1215 Too bad we can't prevent further scroll-thinking. */
1217 tem
= scroll_screen_lines (s
, ep
.vpos
+ top
- scroll_amount
,
1218 top
+ height
- max (0, scroll_amount
),
1220 if (!tem
) stop_vpos
= height
;
1224 /* In any case, do not display past bottom of window */
1225 if (stop_vpos
>= height
)
1231 /* Handle case where pos is before w->start --
1232 can happen if part of line had been clipped and is not clipped now */
1233 if (vpos
== 0 && pos
< marker_position (w
->start
))
1234 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1236 /* Redisplay the lines where the text was changed */
1237 last_text_vpos
= vpos
;
1238 tab_offset
= pos_tab_offset (w
, pos
);
1239 /* If we are starting display in mid-character, correct tab_offset
1240 to account for passing the line that that character really starts in. */
1241 if (val
.hpos
< lmargin
)
1242 tab_offset
+= width
;
1243 while (vpos
< stop_vpos
)
1245 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1246 tab_offset
+= width
;
1247 if (val
.vpos
) tab_offset
= 0;
1248 if (pos
!= val
.bufpos
)
1250 /* Next line, unless prev line ended in end of buffer with no cr */
1251 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
1255 /* There are two cases:
1256 1) we have displayed down to the bottom of the window
1257 2) we have scrolled lines below stop_vpos by scroll_amount */
1261 /* If last line is continued in middle of character,
1262 include the split character in the text considered on the screen */
1263 if (val
.hpos
< lmargin
)
1265 XFASTINT (w
->window_end_vpos
) = last_text_vpos
;
1266 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1269 /* If scrolling made blank lines at window bottom,
1270 redisplay to fill those lines */
1271 if (scroll_amount
< 0)
1273 /* Don't consider these lines for general-purpose scrolling.
1274 That will save time in the scrolling computation. */
1275 SCREEN_SCROLL_BOTTOM_VPOS (s
) = xp
.vpos
;
1280 vpos
= height
+ scroll_amount
;
1281 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
1283 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
1287 blank_end_of_window
= 1;
1288 tab_offset
= pos_tab_offset (w
, pos
);
1289 /* If we are starting display in mid-character, correct tab_offset
1290 to account for passing the line that that character starts in. */
1291 if (val
.hpos
< lmargin
)
1292 tab_offset
+= width
;
1294 while (vpos
< height
)
1296 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1297 tab_offset
+= width
;
1298 if (val
.vpos
) tab_offset
= 0;
1302 /* Here is a case where display_text_line sets cursor_vpos wrong.
1303 Make it be fixed up, below. */
1305 && xp
.bufpos
== point
)
1309 /* If bottom just moved off end of screen, change mode line percentage. */
1310 if (XFASTINT (w
->window_end_pos
) == 0
1312 w
->update_mode_line
= Qt
;
1314 /* Attempt to adjust end-of-text positions to new bottom line */
1317 delta
= height
- xp
.vpos
;
1319 || (delta
> 0 && xp
.bufpos
<= ZV
)
1320 || (delta
== 0 && xp
.hpos
))
1322 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
1323 delta
, width
, hscroll
, window
);
1324 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1325 XFASTINT (w
->window_end_vpos
) += val
.vpos
;
1329 w
->window_end_valid
= Qnil
;
1331 /* If point was not in a line that was displayed, find it */
1332 if (cursor_vpos
< 0)
1334 val
= *compute_motion (start
, 0, lmargin
, point
, 10000, 10000,
1335 width
, hscroll
, pos_tab_offset (w
, start
));
1336 /* Admit failure if point is off screen now */
1337 if (val
.vpos
>= height
)
1339 for (vpos
= 0; vpos
< height
; vpos
++)
1340 cancel_line (vpos
+ top
, s
);
1343 cursor_vpos
= val
.vpos
+ top
;
1344 cursor_hpos
= val
.hpos
+ XFASTINT (w
->left
);
1347 SCREEN_CURSOR_X (s
) = max (0, cursor_hpos
);
1348 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1352 val
= *compute_motion (start
, 0, lmargin
, ZV
,
1353 height
, - (1 << (SHORTBITS
- 1)),
1354 width
, hscroll
, pos_tab_offset (w
, start
));
1355 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
1357 if (XFASTINT (w
->window_end_pos
)
1365 /* Copy glyphs from the rope FROM to T.
1366 But don't actually copy the parts that would come in before S.
1367 Value is T, advanced past the copied data.
1369 Characters in FROM are grouped into units of `sizeof GLYPH' chars;
1370 any extra chars at the end of FROM are ignored. */
1373 copy_rope (t
, s
, from
)
1374 register GLYPH
*t
; /* Copy to here. */
1375 register GLYPH
*s
; /* Starting point. */
1376 Lisp_Object from
; /* Data to copy; known to be a string. */
1378 register int n
= XSTRING (from
)->size
/ sizeof (GLYPH
);
1379 register GLYPH
*f
= (GLYPH
*) XSTRING (from
)->data
;
1383 if (t
>= s
) *t
= *f
;
1390 /* Display one line of window w, starting at position START in W's buffer.
1391 Display starting at horizontal position HPOS, which is normally zero
1392 or negative. A negative value causes output up to hpos = 0 to be discarded.
1393 This is done for negative hscroll, or when this is a continuation line
1394 and the continuation occurred in the middle of a multi-column character.
1396 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
1398 Display on position VPOS on the screen. (origin 0).
1400 Returns a STRUCT POSITION giving character to start next line with
1401 and where to display it, including a zero or negative hpos.
1402 The vpos field is not really a vpos; it is 1 unless the line is continued */
1404 struct position val_display_text_line
;
1406 static struct position
*
1407 display_text_line (w
, start
, vpos
, hpos
, taboffset
)
1414 register int pos
= start
;
1419 register unsigned char *p
;
1421 register GLYPH
*startp
;
1422 register GLYPH
*p1prev
;
1423 SCREEN_PTR s
= XSCREEN (w
->screen
);
1424 int tab_width
= XINT (current_buffer
->tab_width
);
1425 int ctl_arrow
= !NULL (current_buffer
->ctl_arrow
);
1426 int width
= XFASTINT (w
->width
) - 1
1427 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
1428 struct position val
;
1431 int hscroll
= XINT (w
->hscroll
);
1432 int truncate
= hscroll
1433 || (truncate_partial_width_windows
1434 && XFASTINT (w
->width
) < SCREEN_WIDTH (s
))
1435 || !NULL (current_buffer
->truncate_lines
);
1437 = XTYPE (current_buffer
->selective_display
) == Lisp_Int
1438 ? XINT (current_buffer
->selective_display
)
1439 : !NULL (current_buffer
->selective_display
) ? -1 : 0;
1441 int selective_e
= selective
&& !NULL (current_buffer
->selective_display_ellipses
);
1443 register struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (s
);
1444 register struct Lisp_Vector
*dp
= window_display_table (w
);
1446 = (selective
&& dp
&& XTYPE (DISP_INVIS_ROPE (dp
)) == Lisp_String
1447 ? XSTRING (DISP_INVIS_ROPE (dp
))->size
/ sizeof (GLYPH
) : 0);
1448 GLYPH truncator
= (dp
== 0 || XTYPE (DISP_TRUNC_GLYPH (dp
)) != Lisp_Int
1449 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
1450 GLYPH continuer
= (dp
== 0 || XTYPE (DISP_CONTINUE_GLYPH (dp
)) != Lisp_Int
1451 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
1453 hpos
+= XFASTINT (w
->left
);
1454 get_display_line (s
, vpos
, XFASTINT (w
->left
));
1455 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
1457 if (MINI_WINDOW_P (w
) && start
== 1
1458 && vpos
== XFASTINT (w
->top
))
1461 hpos
= display_string (w
, vpos
, minibuf_prompt
, hpos
,
1462 (!truncate
? continuer
: truncator
),
1464 minibuf_prompt_width
= hpos
;
1467 desired_glyphs
->bufp
[vpos
] = pos
;
1468 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
1470 startp
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
1471 endp
= startp
+ width
;
1473 /* Loop generating characters.
1474 Stop at end of buffer, before newline,
1475 or if reach or pass continuation column. */
1485 if (pos
== point
&& cursor_vpos
< 0)
1488 cursor_hpos
= p1
- startp
;
1492 if (pos
< point
&& point
< pause
)
1494 if (pos
< GPT
&& GPT
< pause
)
1497 p
= &FETCH_CHAR (pos
);
1500 if (c
>= 040 && c
< 0177
1501 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
1512 && position_indentation (pos
+ 1) >= selective
)
1515 pos
= find_next_newline (pos
+ 1, 1);
1516 if (FETCH_CHAR (pos
- 1) == '\n')
1519 if (invis
&& selective_rlen
> 0 && p1
>= startp
)
1521 p1
+= selective_rlen
;
1522 if (p1
- startp
> width
)
1524 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1525 (p1
- p1prev
) * sizeof (GLYPH
));
1533 if (p1
>= startp
&& p1
< endp
)
1537 while ((p1
- startp
+ taboffset
+ hscroll
- (hscroll
> 0))
1540 else if (c
== Ctl ('M') && selective
== -1)
1542 pos
= find_next_newline (pos
, 1);
1543 if (FETCH_CHAR (pos
- 1) == '\n')
1545 if (selective_rlen
> 0)
1547 p1
+= selective_rlen
;
1548 if (p1
- startp
> width
)
1550 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1551 (p1
- p1prev
) * sizeof (GLYPH
));
1555 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
1557 p1
= copy_rope (p1
, startp
, DISP_CHAR_ROPE (dp
, c
));
1559 else if (c
< 0200 && ctl_arrow
)
1562 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
1563 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
1565 if (p1
>= startp
&& p1
< endp
)
1572 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
1573 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
1575 if (p1
>= startp
&& p1
< endp
)
1576 *p1
= (c
>> 6) + '0';
1578 if (p1
>= startp
&& p1
< endp
)
1579 *p1
= (7 & (c
>> 3)) + '0';
1581 if (p1
>= startp
&& p1
< endp
)
1582 *p1
= (7 & c
) + '0';
1588 val
.hpos
= - XINT (w
->hscroll
);
1596 /* Handle continuation in middle of a character */
1597 /* by backing up over it */
1600 /* Start the next line with that same character */
1602 /* but at a negative hpos, to skip the columns output on this line. */
1603 val
.hpos
+= p1prev
- endp
;
1604 /* Keep in this line everything up to the continuation column. */
1608 /* Finish deciding which character to start the next line on,
1609 and what hpos to start it at.
1610 Also set `lastpos' to the last position which counts as "on this line"
1611 for cursor-positioning. */
1615 if (FETCH_CHAR (pos
) == '\n')
1616 /* If stopped due to a newline, start next line after it */
1619 /* Stopped due to right margin of window */
1624 /* Truncating => start next line after next newline,
1625 and point is on this line if it is before the newline,
1626 and skip none of first char of next line */
1627 pos
= find_next_newline (pos
, 1);
1628 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
1630 lastpos
= pos
- (FETCH_CHAR (pos
- 1) == '\n');
1641 /* If point is at eol or in invisible text at eol,
1642 record its screen location now. */
1644 if (start
<= point
&& point
<= lastpos
&& cursor_vpos
< 0)
1647 cursor_hpos
= p1
- startp
;
1650 if (cursor_vpos
== vpos
)
1652 if (cursor_hpos
< 0) cursor_hpos
= 0;
1653 if (cursor_hpos
> width
) cursor_hpos
= width
;
1654 cursor_hpos
+= XFASTINT (w
->left
);
1655 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
1657 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1658 SCREEN_CURSOR_X (s
) = cursor_hpos
;
1660 if (w
== XWINDOW (selected_window
))
1662 /* Line is not continued and did not start
1663 in middle of character */
1664 if ((hpos
- XFASTINT (w
->left
)
1665 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1668 this_line_bufpos
= start
;
1669 this_line_buffer
= current_buffer
;
1670 this_line_vpos
= cursor_vpos
;
1671 this_line_start_hpos
= hpos
;
1672 this_line_endpos
= Z
- lastpos
;
1675 this_line_bufpos
= 0;
1680 /* If hscroll and line not empty, insert truncation-at-left marker */
1681 if (hscroll
&& lastpos
!= start
)
1683 *startp
= truncator
;
1688 if (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
))
1691 if (p1
< startp
) p1
= startp
;
1692 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
1695 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
1696 p1
- desired_glyphs
->glyphs
[vpos
]);
1697 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
1699 /* If the start of this line is the overlay arrow-position,
1700 then put the arrow string into the display-line. */
1702 if (XTYPE (Voverlay_arrow_position
) == Lisp_Marker
1703 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
1704 && start
== marker_position (Voverlay_arrow_position
)
1705 && XTYPE (Voverlay_arrow_string
) == Lisp_String
1706 && ! overlay_arrow_seen
)
1708 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
1710 int len
= XSTRING (Voverlay_arrow_string
)->size
;
1712 if (len
> XFASTINT (w
->width
) - 1)
1713 len
= XFASTINT (w
->width
) - 1;
1714 for (i
= 0; i
< len
; i
++)
1716 if (desired_glyphs
->used
[vpos
] <
1717 (len
+ startp
- desired_glyphs
->glyphs
[vpos
]))
1718 desired_glyphs
->used
[vpos
] = len
+ startp
- desired_glyphs
->glyphs
[vpos
];
1720 overlay_arrow_seen
= 1;
1724 val_display_text_line
= val
;
1725 return &val_display_text_line
;
1728 /* Display the mode line for window w */
1731 display_mode_line (w
)
1734 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
1735 register int left
= XFASTINT (w
->left
);
1736 register int right
= XFASTINT (w
->width
) + left
;
1737 register SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (w
));
1739 get_display_line (s
, vpos
, left
);
1740 display_mode_element (w
, vpos
, left
, 0, right
, right
,
1741 current_buffer
->mode_line_format
);
1742 SCREEN_DESIRED_GLYPHS (s
)->bufp
[vpos
] = 0;
1744 /* Make the mode line inverse video if the entire line
1745 is made of mode lines.
1746 I.e. if this window is full width,
1747 or if it is the child of a full width window
1748 (which implies that that window is split side-by-side
1749 and the rest of this line is mode lines of the sibling windows). */
1750 if (XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
1751 || XFASTINT (XWINDOW (w
->parent
)->width
) == SCREEN_WIDTH (s
))
1752 s
->desired_glyphs
->highlight
[vpos
] = mode_line_inverse_video
;
1754 #ifdef HAVE_X_WINDOWS
1755 /* I'm trying this out because I saw Unimpress use it, but it's
1756 possible that this may fuck adversely with some window managers. jla */
1759 && (XTYPE (Vglobal_minibuffer_screen
) != Lisp_Screen
1760 || s
!= XSCREEN (Vglobal_minibuffer_screen
))
1761 && w
== XWINDOW (s
->selected_window
)
1762 && (NULL (Fstring_equal (XBUFFER (w
->buffer
)->name
, s
->name
))))
1763 x_set_name (s
, XBUFFER (w
->buffer
)->name
, Qnil
);
1767 /* Contribute ELT to the mode line for window W.
1768 How it translates into text depends on its data type.
1770 VPOS is the position of the mode line being displayed.
1772 HPOS is the position (absolute on screen) where this element's text
1773 should start. The output is truncated automatically at the right
1776 DEPTH is the depth in recursion. It is used to prevent
1777 infinite recursion here.
1779 MINENDCOL is the hpos before which the element may not end.
1780 The element is padded at the right with spaces if nec
1781 to reach this column.
1783 MAXENDCOL is the hpos past which this element may not extend.
1784 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
1785 (This is necessary to make nested padding and truncation work.)
1787 Returns the hpos of the end of the text generated by ELT.
1788 The next element will receive that value as its HPOS arg,
1789 so as to concatenate the elements. */
1792 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
1794 register int vpos
, hpos
;
1797 register int maxendcol
;
1798 register Lisp_Object elt
;
1806 #ifdef SWITCH_ENUM_BUG
1807 switch ((int) XTYPE (elt
))
1809 switch (XTYPE (elt
))
1814 /* A string: output it and check for %-constructs within it. */
1815 register unsigned char c
;
1816 register unsigned char *this = XSTRING (elt
)->data
;
1818 while (hpos
< maxendcol
&& *this)
1820 unsigned char *last
= this;
1821 while ((c
= *this++) != '\0' && c
!= '%')
1823 if (this - 1 != last
)
1825 register int lim
= --this - last
+ hpos
;
1826 hpos
= display_string (w
, vpos
, last
, hpos
, 0, hpos
,
1827 min (lim
, maxendcol
));
1831 register int spec_width
= 0;
1833 /* We can't allow -ve args due to the "%-" construct */
1834 /* Argument specifies minwidth but not maxwidth
1835 (maxwidth can be specified by
1836 (<negative-number> . <stuff>) mode-line elements) */
1838 while ((c
= *this++) >= '0' && c
<= '9')
1840 spec_width
= spec_width
* 10 + (c
- '0');
1844 if (spec_width
> maxendcol
)
1845 spec_width
= maxendcol
;
1848 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1849 spec_width
, maxendcol
,
1850 Vglobal_mode_string
);
1852 hpos
= display_string (w
, vpos
,
1853 decode_mode_spec (w
, c
,
1855 hpos
, 0, spec_width
, maxendcol
);
1862 /* A symbol: process the value of the symbol recursively
1863 as if it appeared here directly. Avoid error if symbol void.
1864 Special case: if value of symbol is a string, output the string
1867 register Lisp_Object tem
;
1868 tem
= Fboundp (elt
);
1871 tem
= Fsymbol_value (elt
);
1872 /* If value is a string, output that string literally:
1873 don't check for % within it. */
1874 if (XTYPE (tem
) == Lisp_String
)
1875 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
1876 hpos
, 0, minendcol
, maxendcol
);
1877 /* Give up right away for nil or t. */
1878 else if (!EQ (tem
, elt
))
1879 { elt
= tem
; goto tail_recurse
; }
1886 register Lisp_Object car
, tem
;
1888 /* A cons cell: three distinct cases.
1889 If first element is a string or a cons, process all the elements
1890 and effectively concatenate them.
1891 If first element is a negative number, truncate displaying cdr to
1892 at most that many characters. If positive, pad (with spaces)
1893 to at least that many characters.
1894 If first element is a symbol, process the cadr or caddr recursively
1895 according to whether the symbol's value is non-nil or nil. */
1896 car
= XCONS (elt
)->car
;
1897 if (XTYPE (car
) == Lisp_Symbol
)
1899 tem
= Fboundp (car
);
1900 elt
= XCONS (elt
)->cdr
;
1901 if (XTYPE (elt
) != Lisp_Cons
)
1903 /* elt is now the cdr, and we know it is a cons cell.
1904 Use its car if CAR has a non-nil value. */
1907 tem
= Fsymbol_value (car
);
1909 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
1911 /* Symbol's value is nil (or symbol is unbound)
1912 Get the cddr of the original list
1913 and if possible find the caddr and use that. */
1914 elt
= XCONS (elt
)->cdr
;
1917 else if (XTYPE (elt
) != Lisp_Cons
)
1919 elt
= XCONS (elt
)->car
;
1922 else if (XTYPE (car
) == Lisp_Int
)
1924 register int lim
= XINT (car
);
1925 elt
= XCONS (elt
)->cdr
;
1927 /* Negative int means reduce maximum width.
1928 DO NOT change MINENDCOL here!
1929 (20 -10 . foo) should truncate foo to 10 col
1930 and then pad to 20. */
1931 maxendcol
= min (maxendcol
, hpos
- lim
);
1934 /* Padding specified. Don't let it be more than
1937 if (lim
> maxendcol
)
1939 /* If that's more padding than already wanted, queue it.
1940 But don't reduce padding already specified even if
1941 that is beyond the current truncation point. */
1942 if (lim
> minendcol
)
1947 else if (XTYPE (car
) == Lisp_String
|| XTYPE (car
) == Lisp_Cons
)
1949 register int limit
= 50;
1950 /* LIMIT is to protect against circular lists. */
1951 while (XTYPE (elt
) == Lisp_Cons
&& --limit
> 0
1952 && hpos
< maxendcol
)
1954 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1957 elt
= XCONS (elt
)->cdr
;
1965 return (display_string (w
, vpos
, "*invalid*", hpos
, 0,
1966 minendcol
, maxendcol
));
1970 if (minendcol
> hpos
)
1971 hpos
= display_string (w
, vpos
, "", hpos
, 0, minendcol
, -1);
1975 /* Return a string for the output of a mode line %-spec for window W,
1976 generated by character C and width MAXWIDTH. */
1979 decode_mode_spec (w
, c
, maxwidth
)
1982 register int maxwidth
;
1984 Lisp_Object obj
= Qnil
;
1985 SCREEN_PTR scr
= XSCREEN (WINDOW_SCREEN (w
));
1986 char *decode_mode_spec_buf
= (char *) SCREEN_TEMP_GLYPHS (scr
)->total_contents
;
1988 if (maxwidth
> SCREEN_WIDTH (scr
))
1989 maxwidth
= SCREEN_WIDTH (scr
);
1994 obj
= current_buffer
->name
;
1996 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
1998 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
1999 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
2000 decode_mode_spec_buf
[maxwidth
] = '\0';
2001 return decode_mode_spec_buf
;
2007 obj
= current_buffer
->filename
;
2011 else if (XTYPE (obj
) == Lisp_String
&& XSTRING (obj
)->size
> maxwidth
)
2013 bcopy ("...", decode_mode_spec_buf
, 3);
2014 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
2015 decode_mode_spec_buf
+ 3, maxwidth
- 3);
2016 return decode_mode_spec_buf
;
2022 obj
= current_buffer
->mode_name
;
2026 if (BEGV
> BEG
|| ZV
< Z
)
2031 if (!NULL (current_buffer
->read_only
))
2033 if (MODIFF
> current_buffer
->save_modified
)
2038 /* status of process */
2040 obj
= Fget_buffer_process (Fcurrent_buffer ());
2042 return "no process";
2043 obj
= Fsymbol_name (Fprocess_status (obj
));
2046 return "no processes";
2047 #endif /* subprocesses */
2051 int pos
= marker_position (w
->start
);
2052 int total
= ZV
- BEGV
;
2054 if (XFASTINT (w
->window_end_pos
) <= Z
- ZV
)
2061 else if (pos
<= BEGV
)
2065 total
= ((pos
- BEGV
) * 100 + total
- 1) / total
;
2066 /* We can't normally display a 3-digit number,
2067 so get us a 2-digit number that is close. */
2070 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
2071 return decode_mode_spec_buf
;
2083 if (command_loop_level
> 5)
2085 p
= decode_mode_spec_buf
;
2086 for (i
= 0; i
< command_loop_level
; i
++)
2089 return decode_mode_spec_buf
;
2097 if (command_loop_level
> 5)
2099 p
= decode_mode_spec_buf
;
2100 for (i
= 0; i
< command_loop_level
; i
++)
2103 return decode_mode_spec_buf
;
2108 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
2112 if (maxwidth
< sizeof (lots_of_dashes
))
2113 return lots_of_dashes
;
2116 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
2120 return decode_mode_spec_buf
;
2124 if (XTYPE (obj
) == Lisp_String
)
2125 return (char *) XSTRING (obj
)->data
;
2130 /* Display STRING on one line of window W, starting at HPOS.
2131 Display at position VPOS. Caller should have done get_display_line.
2133 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
2135 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
2136 MAXCOL is the last column ok to end at. Truncate here.
2137 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
2138 Both count from the left edge of the screen, as does HPOS.
2139 The right edge of W is an implicit maximum.
2140 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
2142 Returns ending hpos */
2145 display_string (w
, vpos
, string
, hpos
, truncate
, mincol
, maxcol
)
2147 unsigned char *string
;
2154 int hscroll
= XINT (w
->hscroll
);
2155 int tab_width
= XINT (current_buffer
->tab_width
);
2156 register GLYPH
*start
;
2157 register GLYPH
*end
;
2158 struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (XSCREEN (w
->screen
));
2159 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2160 int window_width
= XFASTINT (w
->width
);
2162 /* Use the standard display table, not the window's display table.
2163 We don't want the mode line in rot13. */
2164 register struct Lisp_Vector
*dp
= 0;
2166 if (XTYPE (Vstandard_display_table
) == Lisp_Vector
2167 && XVECTOR (Vstandard_display_table
)->size
== DISP_TABLE_SIZE
)
2168 dp
= XVECTOR (Vstandard_display_table
);
2170 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
2173 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
2174 end
= start
+ window_width
- (truncate
!= 0);
2176 if ((window_width
+ XFASTINT (w
->left
))
2177 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
2180 if (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
)
2181 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
2182 if (maxcol
>= 0 && mincol
> maxcol
)
2189 if (c
>= 040 && c
< 0177
2190 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
2200 if (p1
>= start
&& p1
< end
)
2204 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
2206 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
2207 p1
= copy_rope (p1
, start
, DISP_CHAR_ROPE (dp
, c
));
2208 else if (c
< 0200 && buffer_defaults
.ctl_arrow
)
2211 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
2212 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
2214 if (p1
>= start
&& p1
< end
)
2221 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
2222 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
2224 if (p1
>= start
&& p1
< end
)
2225 *p1
= (c
>> 6) + '0';
2227 if (p1
>= start
&& p1
< end
)
2228 *p1
= (7 & (c
>> 3)) + '0';
2230 if (p1
>= start
&& p1
< end
)
2231 *p1
= (7 & c
) + '0';
2239 if (truncate
) *p1
++ = truncate
;
2241 else if (mincol
>= 0)
2243 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
2249 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
2251 if (len
> desired_glyphs
->used
[vpos
])
2252 desired_glyphs
->used
[vpos
] = len
;
2253 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
2262 staticpro (&last_arrow_position
);
2263 staticpro (&last_arrow_string
);
2264 last_arrow_position
= Qnil
;
2265 last_arrow_string
= Qnil
;
2267 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
2268 "String displayed by mode-line-format's \"%m\" specifiation.");
2269 Vglobal_mode_string
= Qnil
;
2271 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
2272 "Marker for where to display an arrow on top of the buffer text.\n\
2273 This must be the beginning of a line in order to work.\n\
2274 See also `overlay-arrow-string'.");
2275 Voverlay_arrow_position
= Qnil
;
2277 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
2278 "String to display as an arrow. See also `overlay-arrow-position'.");
2279 Voverlay_arrow_string
= Qnil
;
2281 DEFVAR_INT ("scroll-step", &scroll_step
,
2282 "*The number of lines to try scrolling a window by when point moves out.\n\
2283 If that fails to bring point back on screen, point is centered instead.\n\
2284 If this is zero, point is always centered after it moves off screen.");
2286 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
2288 DEFVAR_BOOL ("truncate-partial-width-windows",
2289 &truncate_partial_width_windows
,
2290 "*Non-nil means truncate lines in all windows less than full screen wide.");
2291 truncate_partial_width_windows
= 1;
2293 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
2294 "*Non-nil means use inverse video for the mode line.");
2295 mode_line_inverse_video
= 1;
2297 #ifndef MULTI_SCREEN
2298 defsubr (&Sredraw_display
);
2299 #endif /* MULTI_SCREEN */
2302 /* initialize the window system */
2305 Lisp_Object root_window
;
2306 #ifndef COMPILER_REGISTER_BUG
2308 #endif /* COMPILER_REGISTER_BUG */
2309 struct window
*mini_w
;
2311 this_line_bufpos
= 0;
2313 mini_w
= XWINDOW (minibuf_window
);
2314 root_window
= mini_w
->prev
;
2316 echo_area_glyphs
= 0;
2317 previous_echo_glyphs
= 0;
2319 if (!noninteractive
)
2321 SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (XWINDOW (root_window
)));
2322 XFASTINT (XWINDOW (root_window
)->top
) = 0;
2323 set_window_height (root_window
, SCREEN_HEIGHT (s
) - 1, 0);
2324 XFASTINT (mini_w
->top
) = SCREEN_HEIGHT (s
) - 1;
2325 set_window_height (minibuf_window
, 1, 0);
2327 XFASTINT (XWINDOW (root_window
)->width
) = SCREEN_WIDTH (s
);
2328 XFASTINT (mini_w
->width
) = SCREEN_WIDTH (s
);