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 else if (!EQ (minibuf_window
, selected_window
))
316 windows_or_buffers_changed
++;
318 if (EQ (minibuf_window
, selected_window
))
319 this_line_bufpos
= 0;
321 previous_echo_glyphs
= echo_area_glyphs
;
324 /* Do a screen update, taking possible shortcuts into account.
325 This is the main external entry point for redisplay.
327 If the last redisplay displayed an echo area message and that
328 message is no longer requested, we clear the echo area
329 or bring back the minibuffer if that is in use.
331 Everyone would like to have a hook here to call eval,
332 but that cannot be done safely without a lot of changes elsewhere.
333 This can be called from signal handlers; with alarms set up;
334 or with synchronous processes running.
335 See the function `echo' in keyboard.c.
336 See Fcall_process; if you called it from here, it could be
337 entered recursively. */
342 register struct window
*w
= XWINDOW (selected_window
);
346 register int tlbufpos
, tlendpos
;
348 extern int input_pending
;
353 /* Notice any pending interrupt request to change screen size. */
354 do_pending_window_change ();
362 /* Normally the message* functions will have already displayed and
363 updated the echo area, but the screen may have been trashed, or
364 the update may have been preempted, so display the echo area
366 if (echo_area_glyphs
|| previous_echo_glyphs
)
368 echo_area_display ();
372 if (clip_changed
|| windows_or_buffers_changed
)
375 /* Detect case that we need to write a star in the mode line. */
376 if (XFASTINT (w
->last_modified
) < MODIFF
377 && XFASTINT (w
->last_modified
) <= current_buffer
->save_modified
)
379 w
->update_mode_line
= Qt
;
380 if (buffer_shared
> 1)
384 SCREEN_SCROLL_BOTTOM_VPOS (XSCREEN (w
->screen
)) = -1;
386 all_windows
= update_mode_lines
|| buffer_shared
> 1;
388 /* If specs for an arrow have changed, do thorough redisplay
389 to ensure we remove any arrow that should no longer exist. */
390 if (Voverlay_arrow_position
!= last_arrow_position
391 || Voverlay_arrow_string
!= last_arrow_string
)
392 all_windows
= 1, clip_changed
= 1;
394 tlbufpos
= this_line_bufpos
;
395 tlendpos
= this_line_endpos
;
396 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
397 && SCREEN_VISIBLE_P (XSCREEN (w
->screen
))
398 /* Make sure recorded data applies to current buffer, etc */
399 && this_line_buffer
== current_buffer
400 && current_buffer
== XBUFFER (w
->buffer
)
401 && NILP (w
->force_start
)
402 /* Point must be on the line that we have info recorded about */
404 && point
<= Z
- tlendpos
405 /* All text outside that line, including its final newline,
407 && (XFASTINT (w
->last_modified
) >= MODIFF
408 || (beg_unchanged
>= tlbufpos
- 1
410 /* If selective display, can't optimize
411 if the changes start at the beginning of the line. */
412 && ((XTYPE (current_buffer
->selective_display
) == Lisp_Int
413 && XINT (current_buffer
->selective_display
) > 0
414 ? (beg_unchanged
>= tlbufpos
417 && end_unchanged
>= tlendpos
418 && Z
- GPT
>= tlendpos
)))
420 if (tlbufpos
> BEGV
&& FETCH_CHAR (tlbufpos
- 1) != '\n'
422 || FETCH_CHAR (tlbufpos
) == '\n'))
423 /* Former continuation line has disappeared by becoming empty */
425 else if (XFASTINT (w
->last_modified
) < MODIFF
426 || MINI_WINDOW_P (w
))
429 overlay_arrow_seen
= 0;
430 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
431 pos_tab_offset (w
, tlbufpos
));
432 /* If line contains point, is not continued,
433 and ends at same distance from eob as before, we win */
434 if (cursor_vpos
>= 0 && this_line_bufpos
435 && this_line_endpos
== tlendpos
)
437 if (XFASTINT (w
->width
) != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
438 preserve_other_columns (w
);
444 else if (point
== XFASTINT (w
->last_point
))
448 do_pending_window_change ();
455 pos
= *compute_motion (tlbufpos
, 0,
456 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
457 point
, 2, - (1 << (SHORTBITS
- 1)),
458 XFASTINT (w
->width
) - 1
459 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
460 != SCREEN_WIDTH (selected_screen
)),
462 pos_tab_offset (w
, tlbufpos
));
465 SCREEN_CURSOR_X (selected_screen
)
466 = XFASTINT (w
->left
) + max (pos
.hpos
, 0);
467 SCREEN_CURSOR_Y (selected_screen
) = this_line_vpos
;
474 /* Text changed drastically or point moved off of line */
475 cancel_line (this_line_vpos
, selected_screen
);
478 this_line_bufpos
= 0;
479 all_windows
|= buffer_shared
> 1;
486 /* Recompute # windows showing selected buffer.
487 This will be incremented each time such a window is displayed. */
490 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
494 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
497 s
= XSCREEN (XCONS (tail
)->car
);
499 /* Redraw its windows. */
500 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
503 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
504 #endif /* not MULTI_SCREEN */
506 else if (SCREEN_VISIBLE_P (selected_screen
))
508 redisplay_window (selected_window
, 1);
509 if (XFASTINT (w
->width
) != SCREEN_WIDTH (selected_screen
))
510 preserve_other_columns (w
);
514 /* Prevent various kinds of signals during display update.
515 stdio is not robust about handling signals,
516 which can cause an apparent I/O error. */
528 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
532 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
535 s
= XSCREEN (XCONS (tail
)->car
);
538 pause
|= update_screen (s
, 0, 0);
540 mark_window_display_accurate (s
->root_window
, 1);
545 #endif /* MULTI_SCREEN */
547 if (SCREEN_VISIBLE_P (selected_screen
))
548 pause
= update_screen (selected_screen
, 0, 0);
550 /* We may have called echo_area_display at the top of this
551 function. If the echo area is on another screen, that may
552 have put text on a screen other than the selected one, so the
553 above call to update_screen would not have caught it. Catch
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 (!NILP (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 (;!NILP (window
); window
= w
->next
)
658 w
= XWINDOW (window
);
660 if (!NILP (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 (!NILP (w
->vchild
))
669 mark_window_display_accurate (w
->vchild
, flag
);
670 if (!NILP (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 (; !NILP (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 (!NILP (w
->vchild
))
723 redisplay_windows (w
->vchild
);
726 if (!NILP (w
->hchild
))
728 redisplay_windows (w
->hchild
);
731 if (NILP (w
->buffer
))
734 height
= window_internal_height (w
);
736 if (MINI_WINDOW_P (w
))
738 if (w
== XWINDOW (minibuf_window
))
740 if (echo_area_glyphs
)
741 /* We've already displayed the echo area glyphs, if any. */
746 /* This is a minibuffer, but it's not the currently active one, so
748 int vpos
= XFASTINT (XWINDOW (SCREEN_MINIBUF_WINDOW (s
))->top
);
751 for (i
= 0; i
< height
; i
++)
753 get_display_line (s
, vpos
+ i
, 0);
754 display_string (w
, vpos
+ i
, "", 0, 0, 0, width
);
761 if (update_mode_lines
)
762 w
->update_mode_line
= Qt
;
764 /* Otherwise set up data on this window; select its buffer and point value */
766 current_buffer
= XBUFFER (w
->buffer
);
769 /* Count number of windows showing the selected buffer. */
772 && current_buffer
== XBUFFER (XWINDOW (selected_window
)->buffer
))
775 /* POINT refers normally to the selected window.
776 For any other window, set up appropriate value. */
778 if (!EQ (window
, selected_window
))
780 SET_PT (marker_position (w
->pointm
));
784 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
786 else if (point
> (ZV
- 1))
789 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
793 /* If window-start is screwed up, choose a new one. */
794 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
797 startp
= marker_position (w
->start
);
799 /* Handle case where place to start displaying has been specified,
800 unless the specified location is outside the visible range. */
801 if (!NILP (w
->force_start
))
803 w
->update_mode_line
= Qt
;
804 w
->force_start
= Qnil
;
805 XFASTINT (w
->last_modified
) = 0;
806 if (startp
< BEGV
) startp
= BEGV
;
807 if (startp
> ZV
) startp
= ZV
;
808 try_window (window
, startp
);
811 /* If point does not appear, move point so it does appear */
812 pos
= *compute_motion (startp
, 0,
813 ((EQ (window
, minibuf_window
) && startp
== 1)
814 ? minibuf_prompt_width
: 0)
816 (hscroll
? 1 - hscroll
: 0),
818 - (1 << (SHORTBITS
- 1)),
819 width
, hscroll
, pos_tab_offset (w
, startp
));
821 if (w
!= XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
822 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
826 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
827 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
833 /* Handle case where text has not changed, only point,
834 and it has not moved off the screen */
836 /* This code is not used for minibuffer for the sake of
837 the case of redisplaying to replace an echo area message;
838 since in that case the minibuffer contents per se are usually unchanged.
839 This code is of no real use in the minibuffer since
840 the handling of this_line_bufpos, etc.,
841 in redisplay handles the same cases. */
843 if (XFASTINT (w
->last_modified
) >= MODIFF
844 && point
>= startp
&& !clip_changed
845 && (just_this_one
|| XFASTINT (w
->width
) == SCREEN_WIDTH (s
))
846 && !EQ (window
, minibuf_window
))
848 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0),
849 point
, height
+ 1, 10000, width
, hscroll
,
850 pos_tab_offset (w
, startp
));
852 if (pos
.vpos
< height
)
854 /* Ok, point is still on screen */
855 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
857 /* These variables are supposed to be origin 1 */
858 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
859 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
861 /* This doesn't do the trick, because if a window to the right of
862 this one must be redisplayed, this does nothing because there
863 is nothing in DesiredScreen yet, and then the other window is
864 redisplayed, making likes that are empty in this window's columns.
865 if (XFASTINT (w->width) != SCREEN_WIDTH (s))
866 preserve_my_columns (w);
870 /* Don't bother trying redisplay with same start;
871 we already know it will lose */
873 /* If current starting point was originally the beginning of a line
874 but no longer is, find a new starting point. */
875 else if (!NILP (w
->start_at_line_beg
)
877 || FETCH_CHAR (startp
- 1) == '\n'))
881 else if (just_this_one
&& !MINI_WINDOW_P (w
)
883 && XFASTINT (w
->last_modified
)
884 && ! EQ (w
->window_end_valid
, Qnil
)
885 && do_id
&& !clip_changed
886 && !blank_end_of_window
887 && XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
888 && EQ (last_arrow_position
, Voverlay_arrow_position
)
889 && EQ (last_arrow_string
, Voverlay_arrow_string
)
890 && (tem
= try_window_id (SCREEN_SELECTED_WINDOW (s
)))
893 /* tem > 0 means success. tem == -1 means choose new start.
894 tem == -2 means try again with same start,
895 and nothing but whitespace follows the changed stuff.
896 tem == 0 means try again with same start. */
900 else if (startp
>= BEGV
&& startp
<= ZV
901 /* Avoid starting display at end of buffer! */
902 && (startp
< ZV
|| startp
== BEGV
903 || (XFASTINT (w
->last_modified
) >= MODIFF
)))
905 /* Try to redisplay starting at same place as before */
906 /* If point has not moved off screen, accept the results */
907 try_window (window
, startp
);
908 if (cursor_vpos
>= 0)
911 cancel_my_columns (w
);
914 XFASTINT (w
->last_modified
) = 0;
915 w
->update_mode_line
= Qt
;
917 /* Try to scroll by specified few lines */
919 if (scroll_step
&& !clip_changed
)
923 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
924 scroll_step
, width
, hscroll
, window
);
925 if (pos
.vpos
>= height
)
929 pos
= *vmotion (startp
, point
< startp
? - scroll_step
: scroll_step
,
930 width
, hscroll
, window
);
932 if (point
>= pos
.bufpos
)
934 try_window (window
, pos
.bufpos
);
935 if (cursor_vpos
>= 0)
938 cancel_my_columns (w
);
943 /* Finally, just choose place to start which centers point */
946 pos
= *vmotion (point
, - height
/ 2, width
, hscroll
, window
);
947 try_window (window
, pos
.bufpos
);
949 startp
= marker_position (w
->start
);
950 w
->start_at_line_beg
=
951 (startp
== BEGV
|| FETCH_CHAR (startp
- 1) == '\n') ? Qt
: Qnil
;
954 /* If window not full width, must redo its mode line
955 if the window to its side is being redone */
956 if ((!NILP (w
->update_mode_line
)
957 || (!just_this_one
&& width
< SCREEN_WIDTH (s
) - 1))
958 && height
!= XFASTINT (w
->height
))
959 display_mode_line (w
);
962 current_buffer
= old
;
966 /* Do full redisplay on one window, starting at position `pos'. */
969 try_window (window
, pos
)
973 register struct window
*w
= XWINDOW (window
);
974 register int height
= window_internal_height (w
);
975 register int vpos
= XFASTINT (w
->top
);
976 register int last_text_vpos
= vpos
;
977 int tab_offset
= pos_tab_offset (w
, pos
);
978 SCREEN_PTR s
= XSCREEN (w
->screen
);
979 int width
= XFASTINT (w
->width
) - 1
980 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
983 Fset_marker (w
->start
, make_number (pos
), Qnil
);
985 overlay_arrow_seen
= 0;
986 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
988 while (--height
>= 0)
990 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, tab_offset
);
992 if (val
.vpos
) tab_offset
= 0;
994 if (pos
!= val
.bufpos
)
996 /* Next line, unless prev line ended in end of buffer with no cr */
997 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
1001 /* If last line is continued in middle of character,
1002 include the split character in the text considered on the screen */
1003 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1006 /* If bottom just moved off end of screen, change mode line percentage. */
1007 if (XFASTINT (w
->window_end_pos
) == 0
1009 w
->update_mode_line
= Qt
;
1011 /* Say where last char on screen will be, once redisplay is finished. */
1012 XFASTINT (w
->window_end_pos
) = Z
- pos
;
1013 XFASTINT (w
->window_end_vpos
) = last_text_vpos
- XFASTINT (w
->top
);
1014 /* But that is not valid info until redisplay finishes. */
1015 w
->window_end_valid
= Qnil
;
1018 /* Try to redisplay when buffer is modified locally,
1019 computing insert/delete line to preserve text outside
1020 the bounds of the changes.
1021 Return 1 if successful, 0 if if cannot tell what to do,
1022 or -1 to tell caller to find a new window start,
1023 or -2 to tell caller to do normal redisplay with same window start. */
1026 try_window_id (window
)
1030 register struct window
*w
= XWINDOW (window
);
1031 register int height
= window_internal_height (w
);
1032 SCREEN_PTR s
= XSCREEN (w
->screen
);
1033 int top
= XFASTINT (w
->top
);
1034 int start
= marker_position (w
->start
);
1035 int width
= XFASTINT (w
->width
) - 1
1036 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
1037 int hscroll
= XINT (w
->hscroll
);
1038 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
1040 register int i
, tem
;
1041 int last_text_vpos
= 0;
1044 struct position val
, bp
, ep
, xp
, pp
;
1045 int scroll_amount
= 0;
1047 int tab_offset
, epto
;
1049 if (GPT
- BEG
< beg_unchanged
)
1050 beg_unchanged
= GPT
- BEG
;
1051 if (Z
- GPT
< end_unchanged
)
1052 end_unchanged
= Z
- GPT
;
1054 if (beg_unchanged
+ 1 < start
)
1055 return 0; /* Give up if changes go above top of window */
1057 /* Find position before which nothing is changed. */
1058 bp
= *compute_motion (start
, 0, lmargin
,
1059 beg_unchanged
+ 1, height
+ 1, 0, width
, hscroll
,
1060 pos_tab_offset (w
, start
));
1061 if (bp
.vpos
>= height
)
1063 if (point
< bp
.bufpos
&& !bp
.contin
)
1065 /* All changes are below the screen, and point is on the screen.
1066 We don't need to change the screen at all.
1067 But we need to update window_end_pos to account for
1068 any change in buffer size. */
1069 bp
= *compute_motion (start
, 0, lmargin
,
1071 width
, hscroll
, pos_tab_offset (w
, start
));
1072 XFASTINT (w
->window_end_vpos
) = height
;
1073 XFASTINT (w
->window_end_pos
) = Z
- bp
.bufpos
;
1081 /* Find beginning of that screen line. Must display from there. */
1082 bp
= *vmotion (bp
.bufpos
, 0, width
, hscroll
, window
);
1089 /* If about to start displaying at the beginning of a continuation line,
1090 really start with previous screen line, in case it was not
1091 continued when last redisplayed */
1092 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
1094 /* Likewise if we have to worry about selective display. */
1095 (XTYPE (current_buffer
->selective_display
) == Lisp_Int
1096 && XINT (current_buffer
->selective_display
) > 0
1097 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
1099 bp
= *vmotion (bp
.bufpos
, -1, width
, hscroll
, window
);
1104 if (bp
.contin
&& bp
.hpos
!= lmargin
)
1106 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
1112 /* Find first visible newline after which no more is changed. */
1113 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
1114 if (XTYPE (current_buffer
->selective_display
) == Lisp_Int
1115 && XINT (current_buffer
->selective_display
) > 0)
1117 && (position_indentation (tem
)
1118 >= XINT (current_buffer
->selective_display
)))
1119 tem
= find_next_newline (tem
, 1);
1121 /* Compute the cursor position after that newline. */
1122 ep
= *compute_motion (pos
, vpos
, val
.hpos
, tem
,
1123 height
, - (1 << (SHORTBITS
- 1)),
1124 width
, hscroll
, pos_tab_offset (w
, bp
.bufpos
));
1126 /* If changes reach past the text available on the screen,
1127 just display rest of screen. */
1128 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
1131 stop_vpos
= ep
.vpos
;
1133 /* If no newline before ep, the line ep is on includes some changes
1134 that must be displayed. Make sure we don't stop before it. */
1135 /* Also, if changes reach all the way until ep.bufpos,
1136 it is possible that something was deleted after the
1137 newline before it, so the following line must be redrawn. */
1138 if (stop_vpos
== ep
.vpos
1139 && (ep
.bufpos
== BEGV
1140 || FETCH_CHAR (ep
.bufpos
- 1) != '\n'
1141 || ep
.bufpos
== Z
- end_unchanged
))
1142 stop_vpos
= ep
.vpos
+ 1;
1145 overlay_arrow_seen
= 0;
1147 /* If changes do not reach to bottom of window,
1148 figure out how much to scroll the rest of the window */
1149 if (stop_vpos
< height
)
1151 /* Now determine how far up or down the rest of the window has moved */
1152 epto
= pos_tab_offset (w
, ep
.bufpos
);
1153 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1154 Z
- XFASTINT (w
->window_end_pos
),
1155 10000, 0, width
, hscroll
, epto
);
1156 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
1158 /* Is everything on screen below the changes whitespace?
1159 If so, no scrolling is really necessary. */
1160 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
1162 tem
= FETCH_CHAR (i
);
1163 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
1169 XFASTINT (w
->window_end_vpos
) += scroll_amount
;
1171 /* Before doing any scrolling, verify that point will be on screen. */
1172 if (point
> ep
.bufpos
&& !(point
<= xp
.bufpos
&& xp
.bufpos
< height
))
1174 if (point
<= xp
.bufpos
)
1176 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1177 point
, height
, - (1 << (SHORTBITS
- 1)),
1178 width
, hscroll
, epto
);
1182 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
,
1183 point
, height
, - (1 << (SHORTBITS
- 1)),
1184 width
, hscroll
, pos_tab_offset (w
, xp
.bufpos
));
1186 if (pp
.bufpos
< point
|| pp
.vpos
== height
)
1188 cursor_vpos
= pp
.vpos
+ top
;
1189 cursor_hpos
= pp
.hpos
+ XFASTINT (w
->left
);
1192 if (stop_vpos
- scroll_amount
>= height
1193 || ep
.bufpos
== xp
.bufpos
)
1195 if (scroll_amount
< 0)
1196 stop_vpos
-= scroll_amount
;
1198 /* In this path, we have altered window_end_vpos
1199 and not left it negative.
1200 We must make sure that, in case display is preempted
1201 before the screen changes to reflect what we do here,
1202 further updates will not come to try_window_id
1203 and assume the screen and window_end_vpos match. */
1204 blank_end_of_window
= 1;
1206 else if (!scroll_amount
)
1208 else if (bp
.bufpos
== Z
- end_unchanged
)
1210 /* If reprinting everything is nearly as fast as scrolling,
1211 don't bother scrolling. Can happen if lines are short. */
1212 if (scroll_cost (s
, bp
.vpos
+ top
- scroll_amount
,
1213 top
+ height
- max (0, scroll_amount
),
1215 > xp
.bufpos
- bp
.bufpos
- 20)
1216 /* Return "try normal display with same window-start."
1217 Too bad we can't prevent further scroll-thinking. */
1219 /* If pure deletion, scroll up as many lines as possible.
1220 In common case of killing a line, this can save the
1221 following line from being overwritten by scrolling
1222 and therefore having to be redrawn. */
1223 tem
= scroll_screen_lines (s
, bp
.vpos
+ top
- scroll_amount
,
1224 top
+ height
- max (0, scroll_amount
),
1226 if (!tem
) stop_vpos
= height
;
1228 else if (scroll_amount
)
1230 /* If reprinting everything is nearly as fast as scrolling,
1231 don't bother scrolling. Can happen if lines are short. */
1232 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1233 overestimate of cost of reprinting, since xp.bufpos
1234 would end up below the bottom of the window. */
1235 if (scroll_cost (s
, ep
.vpos
+ top
- scroll_amount
,
1236 top
+ height
- max (0, scroll_amount
),
1238 > xp
.bufpos
- ep
.bufpos
- 20)
1239 /* Return "try normal display with same window-start."
1240 Too bad we can't prevent further scroll-thinking. */
1242 tem
= scroll_screen_lines (s
, ep
.vpos
+ top
- scroll_amount
,
1243 top
+ height
- max (0, scroll_amount
),
1245 if (!tem
) stop_vpos
= height
;
1249 /* In any case, do not display past bottom of window */
1250 if (stop_vpos
>= height
)
1256 /* Handle case where pos is before w->start --
1257 can happen if part of line had been clipped and is not clipped now */
1258 if (vpos
== 0 && pos
< marker_position (w
->start
))
1259 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1261 /* Redisplay the lines where the text was changed */
1262 last_text_vpos
= vpos
;
1263 tab_offset
= pos_tab_offset (w
, pos
);
1264 /* If we are starting display in mid-character, correct tab_offset
1265 to account for passing the line that that character really starts in. */
1266 if (val
.hpos
< lmargin
)
1267 tab_offset
+= width
;
1268 while (vpos
< stop_vpos
)
1270 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1271 tab_offset
+= width
;
1272 if (val
.vpos
) tab_offset
= 0;
1273 if (pos
!= val
.bufpos
)
1275 /* Next line, unless prev line ended in end of buffer with no cr */
1276 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
1280 /* There are two cases:
1281 1) we have displayed down to the bottom of the window
1282 2) we have scrolled lines below stop_vpos by scroll_amount */
1286 /* If last line is continued in middle of character,
1287 include the split character in the text considered on the screen */
1288 if (val
.hpos
< lmargin
)
1290 XFASTINT (w
->window_end_vpos
) = last_text_vpos
;
1291 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1294 /* If scrolling made blank lines at window bottom,
1295 redisplay to fill those lines */
1296 if (scroll_amount
< 0)
1298 /* Don't consider these lines for general-purpose scrolling.
1299 That will save time in the scrolling computation. */
1300 SCREEN_SCROLL_BOTTOM_VPOS (s
) = xp
.vpos
;
1305 vpos
= height
+ scroll_amount
;
1306 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
1308 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
1312 blank_end_of_window
= 1;
1313 tab_offset
= pos_tab_offset (w
, pos
);
1314 /* If we are starting display in mid-character, correct tab_offset
1315 to account for passing the line that that character starts in. */
1316 if (val
.hpos
< lmargin
)
1317 tab_offset
+= width
;
1319 while (vpos
< height
)
1321 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1322 tab_offset
+= width
;
1323 if (val
.vpos
) tab_offset
= 0;
1327 /* Here is a case where display_text_line sets cursor_vpos wrong.
1328 Make it be fixed up, below. */
1330 && xp
.bufpos
== point
)
1334 /* If bottom just moved off end of screen, change mode line percentage. */
1335 if (XFASTINT (w
->window_end_pos
) == 0
1337 w
->update_mode_line
= Qt
;
1339 /* Attempt to adjust end-of-text positions to new bottom line */
1342 delta
= height
- xp
.vpos
;
1344 || (delta
> 0 && xp
.bufpos
<= ZV
)
1345 || (delta
== 0 && xp
.hpos
))
1347 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
1348 delta
, width
, hscroll
, window
);
1349 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1350 XFASTINT (w
->window_end_vpos
) += val
.vpos
;
1354 w
->window_end_valid
= Qnil
;
1356 /* If point was not in a line that was displayed, find it */
1357 if (cursor_vpos
< 0)
1359 val
= *compute_motion (start
, 0, lmargin
, point
, 10000, 10000,
1360 width
, hscroll
, pos_tab_offset (w
, start
));
1361 /* Admit failure if point is off screen now */
1362 if (val
.vpos
>= height
)
1364 for (vpos
= 0; vpos
< height
; vpos
++)
1365 cancel_line (vpos
+ top
, s
);
1368 cursor_vpos
= val
.vpos
+ top
;
1369 cursor_hpos
= val
.hpos
+ XFASTINT (w
->left
);
1372 SCREEN_CURSOR_X (s
) = max (0, cursor_hpos
);
1373 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1377 val
= *compute_motion (start
, 0, lmargin
, ZV
,
1378 height
, - (1 << (SHORTBITS
- 1)),
1379 width
, hscroll
, pos_tab_offset (w
, start
));
1380 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
1382 if (XFASTINT (w
->window_end_pos
)
1390 /* Copy glyphs from the rope FROM to T.
1391 But don't actually copy the parts that would come in before S.
1392 Value is T, advanced past the copied data.
1394 Characters in FROM are grouped into units of `sizeof GLYPH' chars;
1395 any extra chars at the end of FROM are ignored. */
1398 copy_rope (t
, s
, from
)
1399 register GLYPH
*t
; /* Copy to here. */
1400 register GLYPH
*s
; /* Starting point. */
1401 Lisp_Object from
; /* Data to copy; known to be a string. */
1403 register int n
= XSTRING (from
)->size
/ sizeof (GLYPH
);
1404 register GLYPH
*f
= (GLYPH
*) XSTRING (from
)->data
;
1408 if (t
>= s
) *t
= *f
;
1415 /* Display one line of window w, starting at position START in W's buffer.
1416 Display starting at horizontal position HPOS, which is normally zero
1417 or negative. A negative value causes output up to hpos = 0 to be discarded.
1418 This is done for negative hscroll, or when this is a continuation line
1419 and the continuation occurred in the middle of a multi-column character.
1421 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
1423 Display on position VPOS on the screen. (origin 0).
1425 Returns a STRUCT POSITION giving character to start next line with
1426 and where to display it, including a zero or negative hpos.
1427 The vpos field is not really a vpos; it is 1 unless the line is continued */
1429 struct position val_display_text_line
;
1431 static struct position
*
1432 display_text_line (w
, start
, vpos
, hpos
, taboffset
)
1439 register int pos
= start
;
1444 register unsigned char *p
;
1446 register GLYPH
*startp
;
1447 register GLYPH
*p1prev
;
1448 SCREEN_PTR s
= XSCREEN (w
->screen
);
1449 int tab_width
= XINT (current_buffer
->tab_width
);
1450 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
1451 int width
= XFASTINT (w
->width
) - 1
1452 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
1453 struct position val
;
1456 int hscroll
= XINT (w
->hscroll
);
1457 int truncate
= hscroll
1458 || (truncate_partial_width_windows
1459 && XFASTINT (w
->width
) < SCREEN_WIDTH (s
))
1460 || !NILP (current_buffer
->truncate_lines
);
1462 = XTYPE (current_buffer
->selective_display
) == Lisp_Int
1463 ? XINT (current_buffer
->selective_display
)
1464 : !NILP (current_buffer
->selective_display
) ? -1 : 0;
1466 int selective_e
= selective
&& !NILP (current_buffer
->selective_display_ellipses
);
1468 register struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (s
);
1469 register struct Lisp_Vector
*dp
= window_display_table (w
);
1471 = (selective
&& dp
&& XTYPE (DISP_INVIS_ROPE (dp
)) == Lisp_String
1472 ? XSTRING (DISP_INVIS_ROPE (dp
))->size
/ sizeof (GLYPH
) : 0);
1473 GLYPH truncator
= (dp
== 0 || XTYPE (DISP_TRUNC_GLYPH (dp
)) != Lisp_Int
1474 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
1475 GLYPH continuer
= (dp
== 0 || XTYPE (DISP_CONTINUE_GLYPH (dp
)) != Lisp_Int
1476 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
1478 hpos
+= XFASTINT (w
->left
);
1479 get_display_line (s
, vpos
, XFASTINT (w
->left
));
1480 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
1482 if (MINI_WINDOW_P (w
) && start
== 1
1483 && vpos
== XFASTINT (w
->top
))
1486 hpos
= display_string (w
, vpos
, minibuf_prompt
, hpos
,
1487 (!truncate
? continuer
: truncator
),
1489 minibuf_prompt_width
= hpos
;
1492 desired_glyphs
->bufp
[vpos
] = pos
;
1493 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
1495 startp
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
1496 endp
= startp
+ width
;
1498 /* Loop generating characters.
1499 Stop at end of buffer, before newline,
1500 or if reach or pass continuation column. */
1510 if (pos
== point
&& cursor_vpos
< 0)
1513 cursor_hpos
= p1
- startp
;
1517 if (pos
< point
&& point
< pause
)
1519 if (pos
< GPT
&& GPT
< pause
)
1522 p
= &FETCH_CHAR (pos
);
1525 if (c
>= 040 && c
< 0177
1526 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
1537 && position_indentation (pos
+ 1) >= selective
)
1540 pos
= find_next_newline (pos
+ 1, 1);
1541 if (FETCH_CHAR (pos
- 1) == '\n')
1544 if (invis
&& selective_rlen
> 0 && p1
>= startp
)
1546 p1
+= selective_rlen
;
1547 if (p1
- startp
> width
)
1549 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1550 (p1
- p1prev
) * sizeof (GLYPH
));
1558 if (p1
>= startp
&& p1
< endp
)
1562 while ((p1
- startp
+ taboffset
+ hscroll
- (hscroll
> 0))
1565 else if (c
== Ctl ('M') && selective
== -1)
1567 pos
= find_next_newline (pos
, 1);
1568 if (FETCH_CHAR (pos
- 1) == '\n')
1570 if (selective_rlen
> 0)
1572 p1
+= selective_rlen
;
1573 if (p1
- startp
> width
)
1575 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1576 (p1
- p1prev
) * sizeof (GLYPH
));
1580 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
1582 p1
= copy_rope (p1
, startp
, DISP_CHAR_ROPE (dp
, c
));
1584 else if (c
< 0200 && ctl_arrow
)
1587 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
1588 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
1590 if (p1
>= startp
&& p1
< endp
)
1597 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
1598 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
1600 if (p1
>= startp
&& p1
< endp
)
1601 *p1
= (c
>> 6) + '0';
1603 if (p1
>= startp
&& p1
< endp
)
1604 *p1
= (7 & (c
>> 3)) + '0';
1606 if (p1
>= startp
&& p1
< endp
)
1607 *p1
= (7 & c
) + '0';
1613 val
.hpos
= - XINT (w
->hscroll
);
1621 /* Handle continuation in middle of a character */
1622 /* by backing up over it */
1625 /* Start the next line with that same character */
1627 /* but at a negative hpos, to skip the columns output on this line. */
1628 val
.hpos
+= p1prev
- endp
;
1629 /* Keep in this line everything up to the continuation column. */
1633 /* Finish deciding which character to start the next line on,
1634 and what hpos to start it at.
1635 Also set `lastpos' to the last position which counts as "on this line"
1636 for cursor-positioning. */
1640 if (FETCH_CHAR (pos
) == '\n')
1641 /* If stopped due to a newline, start next line after it */
1644 /* Stopped due to right margin of window */
1649 /* Truncating => start next line after next newline,
1650 and point is on this line if it is before the newline,
1651 and skip none of first char of next line */
1652 pos
= find_next_newline (pos
, 1);
1653 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
1655 lastpos
= pos
- (FETCH_CHAR (pos
- 1) == '\n');
1666 /* If point is at eol or in invisible text at eol,
1667 record its screen location now. */
1669 if (start
<= point
&& point
<= lastpos
&& cursor_vpos
< 0)
1672 cursor_hpos
= p1
- startp
;
1675 if (cursor_vpos
== vpos
)
1677 if (cursor_hpos
< 0) cursor_hpos
= 0;
1678 if (cursor_hpos
> width
) cursor_hpos
= width
;
1679 cursor_hpos
+= XFASTINT (w
->left
);
1680 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
1682 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1683 SCREEN_CURSOR_X (s
) = cursor_hpos
;
1685 if (w
== XWINDOW (selected_window
))
1687 /* Line is not continued and did not start
1688 in middle of character */
1689 if ((hpos
- XFASTINT (w
->left
)
1690 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1693 this_line_bufpos
= start
;
1694 this_line_buffer
= current_buffer
;
1695 this_line_vpos
= cursor_vpos
;
1696 this_line_start_hpos
= hpos
;
1697 this_line_endpos
= Z
- lastpos
;
1700 this_line_bufpos
= 0;
1705 /* If hscroll and line not empty, insert truncation-at-left marker */
1706 if (hscroll
&& lastpos
!= start
)
1708 *startp
= truncator
;
1713 if (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
))
1716 if (p1
< startp
) p1
= startp
;
1717 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
1720 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
1721 p1
- desired_glyphs
->glyphs
[vpos
]);
1722 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
1724 /* If the start of this line is the overlay arrow-position,
1725 then put the arrow string into the display-line. */
1727 if (XTYPE (Voverlay_arrow_position
) == Lisp_Marker
1728 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
1729 && start
== marker_position (Voverlay_arrow_position
)
1730 && XTYPE (Voverlay_arrow_string
) == Lisp_String
1731 && ! overlay_arrow_seen
)
1733 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
1735 int len
= XSTRING (Voverlay_arrow_string
)->size
;
1737 if (len
> XFASTINT (w
->width
) - 1)
1738 len
= XFASTINT (w
->width
) - 1;
1739 for (i
= 0; i
< len
; i
++)
1741 if (desired_glyphs
->used
[vpos
] <
1742 (len
+ startp
- desired_glyphs
->glyphs
[vpos
]))
1743 desired_glyphs
->used
[vpos
] = len
+ startp
- desired_glyphs
->glyphs
[vpos
];
1745 overlay_arrow_seen
= 1;
1749 val_display_text_line
= val
;
1750 return &val_display_text_line
;
1753 /* Display the mode line for window w */
1756 display_mode_line (w
)
1759 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
1760 register int left
= XFASTINT (w
->left
);
1761 register int right
= XFASTINT (w
->width
) + left
;
1762 register SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (w
));
1764 get_display_line (s
, vpos
, left
);
1765 display_mode_element (w
, vpos
, left
, 0, right
, right
,
1766 current_buffer
->mode_line_format
);
1767 SCREEN_DESIRED_GLYPHS (s
)->bufp
[vpos
] = 0;
1769 /* Make the mode line inverse video if the entire line
1770 is made of mode lines.
1771 I.e. if this window is full width,
1772 or if it is the child of a full width window
1773 (which implies that that window is split side-by-side
1774 and the rest of this line is mode lines of the sibling windows). */
1775 if (XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
1776 || XFASTINT (XWINDOW (w
->parent
)->width
) == SCREEN_WIDTH (s
))
1777 s
->desired_glyphs
->highlight
[vpos
] = mode_line_inverse_video
;
1779 #ifdef HAVE_X_WINDOWS
1780 /* I'm trying this out because I saw Unimpress use it, but it's
1781 possible that this may mess adversely with some window managers. jla */
1784 && ! SCREEN_MINIBUF_ONLY_P (s
)
1785 && w
== XWINDOW (s
->selected_window
)
1786 && (NILP (Fstring_equal (XBUFFER (w
->buffer
)->name
, s
->name
))))
1787 x_set_name (s
, XBUFFER (w
->buffer
)->name
, Qnil
);
1791 /* Contribute ELT to the mode line for window W.
1792 How it translates into text depends on its data type.
1794 VPOS is the position of the mode line being displayed.
1796 HPOS is the position (absolute on screen) where this element's text
1797 should start. The output is truncated automatically at the right
1800 DEPTH is the depth in recursion. It is used to prevent
1801 infinite recursion here.
1803 MINENDCOL is the hpos before which the element may not end.
1804 The element is padded at the right with spaces if nec
1805 to reach this column.
1807 MAXENDCOL is the hpos past which this element may not extend.
1808 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
1809 (This is necessary to make nested padding and truncation work.)
1811 Returns the hpos of the end of the text generated by ELT.
1812 The next element will receive that value as its HPOS arg,
1813 so as to concatenate the elements. */
1816 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
1818 register int vpos
, hpos
;
1821 register int maxendcol
;
1822 register Lisp_Object elt
;
1830 #ifdef SWITCH_ENUM_BUG
1831 switch ((int) XTYPE (elt
))
1833 switch (XTYPE (elt
))
1838 /* A string: output it and check for %-constructs within it. */
1839 register unsigned char c
;
1840 register unsigned char *this = XSTRING (elt
)->data
;
1842 while (hpos
< maxendcol
&& *this)
1844 unsigned char *last
= this;
1845 while ((c
= *this++) != '\0' && c
!= '%')
1847 if (this - 1 != last
)
1849 register int lim
= --this - last
+ hpos
;
1850 hpos
= display_string (w
, vpos
, last
, hpos
, 0, hpos
,
1851 min (lim
, maxendcol
));
1855 register int spec_width
= 0;
1857 /* We can't allow -ve args due to the "%-" construct */
1858 /* Argument specifies minwidth but not maxwidth
1859 (maxwidth can be specified by
1860 (<negative-number> . <stuff>) mode-line elements) */
1862 while ((c
= *this++) >= '0' && c
<= '9')
1864 spec_width
= spec_width
* 10 + (c
- '0');
1868 if (spec_width
> maxendcol
)
1869 spec_width
= maxendcol
;
1872 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1873 spec_width
, maxendcol
,
1874 Vglobal_mode_string
);
1876 hpos
= display_string (w
, vpos
,
1877 decode_mode_spec (w
, c
,
1879 hpos
, 0, spec_width
, maxendcol
);
1886 /* A symbol: process the value of the symbol recursively
1887 as if it appeared here directly. Avoid error if symbol void.
1888 Special case: if value of symbol is a string, output the string
1891 register Lisp_Object tem
;
1892 tem
= Fboundp (elt
);
1895 tem
= Fsymbol_value (elt
);
1896 /* If value is a string, output that string literally:
1897 don't check for % within it. */
1898 if (XTYPE (tem
) == Lisp_String
)
1899 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
1900 hpos
, 0, minendcol
, maxendcol
);
1901 /* Give up right away for nil or t. */
1902 else if (!EQ (tem
, elt
))
1903 { elt
= tem
; goto tail_recurse
; }
1910 register Lisp_Object car
, tem
;
1912 /* A cons cell: three distinct cases.
1913 If first element is a string or a cons, process all the elements
1914 and effectively concatenate them.
1915 If first element is a negative number, truncate displaying cdr to
1916 at most that many characters. If positive, pad (with spaces)
1917 to at least that many characters.
1918 If first element is a symbol, process the cadr or caddr recursively
1919 according to whether the symbol's value is non-nil or nil. */
1920 car
= XCONS (elt
)->car
;
1921 if (XTYPE (car
) == Lisp_Symbol
)
1923 tem
= Fboundp (car
);
1924 elt
= XCONS (elt
)->cdr
;
1925 if (XTYPE (elt
) != Lisp_Cons
)
1927 /* elt is now the cdr, and we know it is a cons cell.
1928 Use its car if CAR has a non-nil value. */
1931 tem
= Fsymbol_value (car
);
1933 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
1935 /* Symbol's value is nil (or symbol is unbound)
1936 Get the cddr of the original list
1937 and if possible find the caddr and use that. */
1938 elt
= XCONS (elt
)->cdr
;
1941 else if (XTYPE (elt
) != Lisp_Cons
)
1943 elt
= XCONS (elt
)->car
;
1946 else if (XTYPE (car
) == Lisp_Int
)
1948 register int lim
= XINT (car
);
1949 elt
= XCONS (elt
)->cdr
;
1951 /* Negative int means reduce maximum width.
1952 DO NOT change MINENDCOL here!
1953 (20 -10 . foo) should truncate foo to 10 col
1954 and then pad to 20. */
1955 maxendcol
= min (maxendcol
, hpos
- lim
);
1958 /* Padding specified. Don't let it be more than
1961 if (lim
> maxendcol
)
1963 /* If that's more padding than already wanted, queue it.
1964 But don't reduce padding already specified even if
1965 that is beyond the current truncation point. */
1966 if (lim
> minendcol
)
1971 else if (XTYPE (car
) == Lisp_String
|| XTYPE (car
) == Lisp_Cons
)
1973 register int limit
= 50;
1974 /* LIMIT is to protect against circular lists. */
1975 while (XTYPE (elt
) == Lisp_Cons
&& --limit
> 0
1976 && hpos
< maxendcol
)
1978 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1981 elt
= XCONS (elt
)->cdr
;
1989 return (display_string (w
, vpos
, "*invalid*", hpos
, 0,
1990 minendcol
, maxendcol
));
1994 if (minendcol
> hpos
)
1995 hpos
= display_string (w
, vpos
, "", hpos
, 0, minendcol
, -1);
1999 /* Return a string for the output of a mode line %-spec for window W,
2000 generated by character C and width MAXWIDTH. */
2003 decode_mode_spec (w
, c
, maxwidth
)
2006 register int maxwidth
;
2008 Lisp_Object obj
= Qnil
;
2009 SCREEN_PTR scr
= XSCREEN (WINDOW_SCREEN (w
));
2010 char *decode_mode_spec_buf
= (char *) SCREEN_TEMP_GLYPHS (scr
)->total_contents
;
2012 if (maxwidth
> SCREEN_WIDTH (scr
))
2013 maxwidth
= SCREEN_WIDTH (scr
);
2018 obj
= current_buffer
->name
;
2020 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
2022 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
2023 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
2024 decode_mode_spec_buf
[maxwidth
] = '\0';
2025 return decode_mode_spec_buf
;
2031 obj
= current_buffer
->filename
;
2035 else if (XTYPE (obj
) == Lisp_String
&& XSTRING (obj
)->size
> maxwidth
)
2037 bcopy ("...", decode_mode_spec_buf
, 3);
2038 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
2039 decode_mode_spec_buf
+ 3, maxwidth
- 3);
2040 return decode_mode_spec_buf
;
2046 obj
= current_buffer
->mode_name
;
2050 if (BEGV
> BEG
|| ZV
< Z
)
2055 if (!NILP (current_buffer
->read_only
))
2057 if (MODIFF
> current_buffer
->save_modified
)
2062 /* status of process */
2063 obj
= Fget_buffer_process (Fcurrent_buffer ());
2065 return "no process";
2066 obj
= Fsymbol_name (Fprocess_status (obj
));
2071 int pos
= marker_position (w
->start
);
2072 int total
= ZV
- BEGV
;
2074 if (XFASTINT (w
->window_end_pos
) <= Z
- ZV
)
2081 else if (pos
<= BEGV
)
2085 total
= ((pos
- BEGV
) * 100 + total
- 1) / total
;
2086 /* We can't normally display a 3-digit number,
2087 so get us a 2-digit number that is close. */
2090 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
2091 return decode_mode_spec_buf
;
2103 if (command_loop_level
> 5)
2105 p
= decode_mode_spec_buf
;
2106 for (i
= 0; i
< command_loop_level
; i
++)
2109 return decode_mode_spec_buf
;
2117 if (command_loop_level
> 5)
2119 p
= decode_mode_spec_buf
;
2120 for (i
= 0; i
< command_loop_level
; i
++)
2123 return decode_mode_spec_buf
;
2128 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
2132 if (maxwidth
< sizeof (lots_of_dashes
))
2133 return lots_of_dashes
;
2136 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
2140 return decode_mode_spec_buf
;
2144 if (XTYPE (obj
) == Lisp_String
)
2145 return (char *) XSTRING (obj
)->data
;
2150 /* Display STRING on one line of window W, starting at HPOS.
2151 Display at position VPOS. Caller should have done get_display_line.
2153 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
2155 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
2156 MAXCOL is the last column ok to end at. Truncate here.
2157 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
2158 Both count from the left edge of the screen, as does HPOS.
2159 The right edge of W is an implicit maximum.
2160 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
2162 Returns ending hpos */
2165 display_string (w
, vpos
, string
, hpos
, truncate
, mincol
, maxcol
)
2167 unsigned char *string
;
2174 int hscroll
= XINT (w
->hscroll
);
2175 int tab_width
= XINT (current_buffer
->tab_width
);
2176 register GLYPH
*start
;
2177 register GLYPH
*end
;
2178 struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (XSCREEN (w
->screen
));
2179 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2180 int window_width
= XFASTINT (w
->width
);
2182 /* Use the standard display table, not the window's display table.
2183 We don't want the mode line in rot13. */
2184 register struct Lisp_Vector
*dp
= 0;
2186 if (XTYPE (Vstandard_display_table
) == Lisp_Vector
2187 && XVECTOR (Vstandard_display_table
)->size
== DISP_TABLE_SIZE
)
2188 dp
= XVECTOR (Vstandard_display_table
);
2190 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
2193 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
2194 end
= start
+ window_width
- (truncate
!= 0);
2196 if ((window_width
+ XFASTINT (w
->left
))
2197 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
2200 if (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
)
2201 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
2202 if (maxcol
>= 0 && mincol
> maxcol
)
2209 if (c
>= 040 && c
< 0177
2210 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
2220 if (p1
>= start
&& p1
< end
)
2224 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
2226 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
2227 p1
= copy_rope (p1
, start
, DISP_CHAR_ROPE (dp
, c
));
2228 else if (c
< 0200 && buffer_defaults
.ctl_arrow
)
2231 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
2232 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
2234 if (p1
>= start
&& p1
< end
)
2241 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
2242 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
2244 if (p1
>= start
&& p1
< end
)
2245 *p1
= (c
>> 6) + '0';
2247 if (p1
>= start
&& p1
< end
)
2248 *p1
= (7 & (c
>> 3)) + '0';
2250 if (p1
>= start
&& p1
< end
)
2251 *p1
= (7 & c
) + '0';
2259 if (truncate
) *p1
++ = truncate
;
2261 else if (mincol
>= 0)
2263 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
2269 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
2271 if (len
> desired_glyphs
->used
[vpos
])
2272 desired_glyphs
->used
[vpos
] = len
;
2273 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
2282 staticpro (&last_arrow_position
);
2283 staticpro (&last_arrow_string
);
2284 last_arrow_position
= Qnil
;
2285 last_arrow_string
= Qnil
;
2287 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
2288 "String displayed by mode-line-format's \"%m\" specifiation.");
2289 Vglobal_mode_string
= Qnil
;
2291 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
2292 "Marker for where to display an arrow on top of the buffer text.\n\
2293 This must be the beginning of a line in order to work.\n\
2294 See also `overlay-arrow-string'.");
2295 Voverlay_arrow_position
= Qnil
;
2297 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
2298 "String to display as an arrow. See also `overlay-arrow-position'.");
2299 Voverlay_arrow_string
= Qnil
;
2301 DEFVAR_INT ("scroll-step", &scroll_step
,
2302 "*The number of lines to try scrolling a window by when point moves out.\n\
2303 If that fails to bring point back on screen, point is centered instead.\n\
2304 If this is zero, point is always centered after it moves off screen.");
2306 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
2308 DEFVAR_BOOL ("truncate-partial-width-windows",
2309 &truncate_partial_width_windows
,
2310 "*Non-nil means truncate lines in all windows less than full screen wide.");
2311 truncate_partial_width_windows
= 1;
2313 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
2314 "*Non-nil means use inverse video for the mode line.");
2315 mode_line_inverse_video
= 1;
2317 #ifndef MULTI_SCREEN
2318 defsubr (&Sredraw_display
);
2319 #endif /* MULTI_SCREEN */
2322 /* initialize the window system */
2325 Lisp_Object root_window
;
2326 #ifndef COMPILER_REGISTER_BUG
2328 #endif /* COMPILER_REGISTER_BUG */
2329 struct window
*mini_w
;
2331 this_line_bufpos
= 0;
2333 mini_w
= XWINDOW (minibuf_window
);
2334 root_window
= mini_w
->prev
;
2336 echo_area_glyphs
= 0;
2337 previous_echo_glyphs
= 0;
2339 if (!noninteractive
)
2341 SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (XWINDOW (root_window
)));
2342 XFASTINT (XWINDOW (root_window
)->top
) = 0;
2343 set_window_height (root_window
, SCREEN_HEIGHT (s
) - 1, 0);
2344 XFASTINT (mini_w
->top
) = SCREEN_HEIGHT (s
) - 1;
2345 set_window_height (minibuf_window
, 1, 0);
2347 XFASTINT (XWINDOW (root_window
)->width
) = SCREEN_WIDTH (s
);
2348 XFASTINT (mini_w
->width
) = SCREEN_WIDTH (s
);