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 */
193 /* dump an informative message to the minibuf */
197 message (m
, a1
, a2
, a3
)
202 if (noninteractive_need_newline
)
204 noninteractive_need_newline
= 0;
205 fprintf (stderr
, m
, a1
, a2
, a3
);
206 fprintf (stderr
, "\n");
209 else if (INTERACTIVE
)
217 doprnt (SCREEN_MESSAGE_BUF (selected_screen
),
218 SCREEN_WIDTH (selected_screen
), m
, 0, 3, a
);
220 doprnt (SCREEN_MESSAGE_BUF (selected_screen
),
221 SCREEN_WIDTH (selected_screen
), m
, 0, 3, &a1
);
222 #endif /* NO_ARG_ARRAY */
224 echo_area_glyphs
= SCREEN_MESSAGE_BUF (selected_screen
);
225 do_pending_window_change ();
226 echo_area_display ();
227 update_screen (XSCREEN (XWINDOW (minibuf_window
)->screen
), 1, 1);
228 do_pending_window_change ();
232 /* Specify m, a string, as a message in the minibuf. */
237 if (!NULL (Vwindow_system
) && SCREEN_IS_TERMCAP (selected_screen
))
242 if (noninteractive_need_newline
)
244 noninteractive_need_newline
= 0;
245 fprintf (stderr
, "%s\n", m
);
248 else if (INTERACTIVE
)
250 echo_area_glyphs
= m
;
251 do_pending_window_change ();
252 echo_area_display ();
253 update_screen (XSCREEN (XWINDOW (minibuf_window
)->screen
), 1, 1);
254 do_pending_window_change ();
265 choose_minibuf_screen ();
266 s
= XSCREEN (XWINDOW (minibuf_window
)->screen
);
278 if (echo_area_glyphs
|| minibuf_level
== 0)
280 vpos
= XFASTINT (XWINDOW (minibuf_window
)->top
);
281 get_display_line (s
, vpos
, 0);
282 display_string (XWINDOW (minibuf_window
), vpos
,
283 echo_area_glyphs
? echo_area_glyphs
: "",
284 0, 0, 0, SCREEN_WIDTH (s
));
286 /* If desired cursor location is on this line, put it at end of text */
287 if (SCREEN_CURSOR_Y (s
) == vpos
)
288 SCREEN_CURSOR_X (s
) = s
->desired_glyphs
->used
[vpos
];
290 else if (!EQ (minibuf_window
, selected_window
))
291 windows_or_buffers_changed
++;
293 if (EQ (minibuf_window
, selected_window
))
294 this_line_bufpos
= 0;
296 previous_echo_glyphs
= echo_area_glyphs
;
299 /* Do a screen update, taking possible shortcuts into account.
300 This is the main external entry point for redisplay.
302 If the last redisplay displayed an echo area message and that
303 message is no longer requested, we clear the echo area
304 or bring back the minibuffer if that is in use.
306 Everyone would like to have a hook here to call eval,
307 but that cannot be done safely without a lot of changes elsewhere.
308 This can be called from signal handlers; with alarms set up;
309 or with synchronous processes running.
310 See the function `echo' in keyboard.c.
311 See Fcall_process; if you called it from here, it could be
312 entered recursively. */
317 register struct window
*w
= XWINDOW (selected_window
);
321 register int tlbufpos
, tlendpos
;
323 extern int input_pending
;
328 /* Notice any pending interrupt request to change screen size. */
329 do_pending_window_change ();
337 if (echo_area_glyphs
|| previous_echo_glyphs
)
339 echo_area_display ();
343 if (clip_changed
|| windows_or_buffers_changed
)
346 /* Detect case that we need to write a star in the mode line. */
347 if (XFASTINT (w
->last_modified
) < MODIFF
348 && XFASTINT (w
->last_modified
) <= current_buffer
->save_modified
)
350 w
->update_mode_line
= Qt
;
351 if (buffer_shared
> 1)
355 SCREEN_SCROLL_BOTTOM_VPOS (XSCREEN (w
->screen
)) = -1;
357 all_windows
= update_mode_lines
|| buffer_shared
> 1;
359 all_windows
|= (XTYPE (Vglobal_minibuffer_screen
) == Lisp_Screen
360 && selected_screen
!= XSCREEN (Vglobal_minibuffer_screen
));
361 #endif /* MULTI_SCREEN */
363 /* If specs for an arrow have changed, do thorough redisplay
364 to ensure we remove any arrow that should no longer exist. */
365 if (Voverlay_arrow_position
!= last_arrow_position
366 || Voverlay_arrow_string
!= last_arrow_string
)
367 all_windows
= 1, clip_changed
= 1;
369 tlbufpos
= this_line_bufpos
;
370 tlendpos
= this_line_endpos
;
371 if (!all_windows
&& tlbufpos
> 0 && NULL (w
->update_mode_line
)
372 && SCREEN_VISIBLE_P (XSCREEN (w
->screen
))
373 /* Make sure recorded data applies to current buffer, etc */
374 && this_line_buffer
== current_buffer
375 && current_buffer
== XBUFFER (w
->buffer
)
376 && NULL (w
->force_start
)
377 /* Point must be on the line that we have info recorded about */
379 && point
<= Z
- tlendpos
380 /* All text outside that line, including its final newline,
382 && (XFASTINT (w
->last_modified
) >= MODIFF
383 || (beg_unchanged
>= tlbufpos
- 1
385 && end_unchanged
>= tlendpos
386 && Z
- GPT
>= tlendpos
)))
388 if (tlbufpos
> BEGV
&& FETCH_CHAR (tlbufpos
- 1) != '\n'
390 || FETCH_CHAR (tlbufpos
) == '\n'))
391 /* Former continuation line has disappeared by becoming empty */
393 else if (XFASTINT (w
->last_modified
) < MODIFF
394 || MINI_WINDOW_P (w
))
397 overlay_arrow_seen
= 0;
398 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
399 pos_tab_offset (w
, tlbufpos
));
400 /* If line contains point, is not continued,
401 and ends at same distance from eob as before, we win */
402 if (cursor_vpos
>= 0 && this_line_bufpos
403 && this_line_endpos
== tlendpos
)
405 if (XFASTINT (w
->width
) != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
406 preserve_other_columns (w
);
412 else if (point
== XFASTINT (w
->last_point
))
416 do_pending_window_change ();
423 pos
= *compute_motion (tlbufpos
, 0,
424 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
425 point
, 2, - (1 << (SHORTBITS
- 1)),
426 XFASTINT (w
->width
) - 1
427 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
428 != SCREEN_WIDTH (selected_screen
)),
429 XINT (w
->hscroll
), 0);
432 SCREEN_CURSOR_X (selected_screen
)
433 = XFASTINT (w
->left
) + max (pos
.hpos
, 0);
434 SCREEN_CURSOR_Y (selected_screen
) = this_line_vpos
;
441 /* Text changed drastically or point moved off of line */
442 cancel_line (this_line_vpos
, selected_screen
);
445 this_line_bufpos
= 0;
446 all_windows
|= buffer_shared
> 1;
453 /* Recompute # windows showing selected buffer.
454 This will be increment each time such a window is displayed. */
457 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
461 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
464 s
= XSCREEN (XCONS (tail
)->car
);
468 /* Clear the echo area on screens where the minibuffer isn't. */
469 if (s
!= XSCREEN (XWINDOW (minibuf_window
)->screen
)
470 /* But only screens that have minibuffers. */
471 && s
->has_minibuffer
)
473 int vpos
= XFASTINT (XWINDOW (s
->minibuffer_window
)->top
);
474 register struct screen_glyphs
*line
;
476 get_display_line (s
, vpos
, 0);
477 display_string (XWINDOW (s
->minibuffer_window
), vpos
, "",
481 /* Redraw its windows. */
482 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
486 redisplay_windows (SCREEN_ROOT_WINDOW (s
));
487 #endif /* not MULTI_SCREEN */
489 else if (SCREEN_VISIBLE_P (selected_screen
))
491 redisplay_window (selected_window
, 1);
492 if (XFASTINT (w
->width
) != SCREEN_WIDTH (selected_screen
))
493 preserve_other_columns (w
);
497 /* Prevent various kinds of signals during display update.
498 stdio is not robust about handling signals,
499 which can cause an apparent I/O error. */
511 for (tail
= Vscreen_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
515 if (XTYPE (XCONS (tail
)->car
) != Lisp_Screen
)
518 s
= XSCREEN (XCONS (tail
)->car
);
521 pause
|= update_screen (s
, 0, 0, SCREEN_SCROLL_BOTTOM_VPOS (s
));
523 mark_window_display_accurate (s
->root_window
, 1);
528 #endif /* MULTI_SCREEN */
529 if (SCREEN_VISIBLE_P (selected_screen
))
530 pause
= update_screen (selected_screen
, 0, 0);
532 /* If screen does not match, prevent doing single-line-update next time.
533 Also, don't forget to check every line to update the arrow. */
536 this_line_bufpos
= 0;
537 if (!NULL (last_arrow_position
))
539 last_arrow_position
= Qt
;
540 last_arrow_string
= Qt
;
542 /* If we pause after scrolling, some lines in current_screen
543 may be null, so preserve_other_columns won't be able to
544 preserve all the vertical-bar separators. So, avoid using it
546 if (XFASTINT (w
->width
) != SCREEN_WIDTH (selected_screen
))
547 update_mode_lines
= 1;
550 /* Now text on screen agrees with windows, so
551 put info into the windows for partial redisplay to follow */
555 register struct buffer
*b
= XBUFFER (w
->buffer
);
557 blank_end_of_window
= 0;
559 unchanged_modified
= BUF_MODIFF (b
);
560 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
561 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
563 XFASTINT (w
->last_point
) = BUF_PT (b
);
564 XFASTINT (w
->last_point_x
) = SCREEN_CURSOR_X (selected_screen
);
565 XFASTINT (w
->last_point_y
) = SCREEN_CURSOR_Y (selected_screen
);
568 mark_window_display_accurate (XWINDOW (minibuf_window
)->prev
, 1);
571 w
->update_mode_line
= Qnil
;
572 XFASTINT (w
->last_modified
) = BUF_MODIFF (b
);
573 w
->window_end_valid
= Qt
;
574 last_arrow_position
= Voverlay_arrow_position
;
575 last_arrow_string
= Voverlay_arrow_string
;
577 update_mode_lines
= 0;
578 windows_or_buffers_changed
= 0;
581 /* Start SIGIO interrupts coming again.
582 Having them off during the code above
583 makes it less likely one will discard output,
584 but not impossible, since there might be stuff
585 in the system buffer here.
586 But it is much hairier to try to do anything about that. */
592 /* Change screen size now if a change is pending. */
593 do_pending_window_change ();
596 /* Redisplay, but leave alone any recent echo area message
597 unless another message has been requested in its place.
599 This is useful in situations where you need to redisplay but no
600 user action has occurred, making it inappropriate for the message
601 area to be cleared. See tracking_off and
602 wait_reading_process_input for examples of these situations. */
604 redisplay_preserve_echo_area ()
606 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
608 echo_area_glyphs
= previous_echo_glyphs
;
610 echo_area_glyphs
= 0;
617 mark_window_display_accurate (window
, flag
)
621 register struct window
*w
;
623 for (;!NULL (window
); window
= w
->next
)
625 w
= XWINDOW (window
);
627 if (!NULL (w
->buffer
))
628 XFASTINT (w
->last_modified
)
630 : XBUFFER (w
->buffer
) == current_buffer
631 ? MODIFF
: BUF_MODIFF (XBUFFER (w
->buffer
));
632 w
->window_end_valid
= Qt
;
633 w
->update_mode_line
= Qnil
;
635 if (!NULL (w
->vchild
))
636 mark_window_display_accurate (w
->vchild
, flag
);
637 if (!NULL (w
->hchild
))
638 mark_window_display_accurate (w
->hchild
, flag
);
643 last_arrow_position
= Voverlay_arrow_position
;
644 last_arrow_string
= Voverlay_arrow_string
;
648 /* t is unequal to any useful value of Voverlay_arrow_... */
649 last_arrow_position
= Qt
;
650 last_arrow_string
= Qt
;
657 redisplay_windows (window
)
660 for (; !NULL (window
); window
= XWINDOW (window
)->next
)
661 redisplay_window (window
, 0);
665 redisplay_window (window
, just_this_one
)
669 register struct window
*w
= XWINDOW (window
);
670 SCREEN_PTR s
= XSCREEN (w
->screen
);
672 register int lpoint
= point
;
673 struct buffer
*old
= current_buffer
;
674 register int width
= XFASTINT (w
->width
) - 1
675 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
676 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))));
678 register int hscroll
= XINT (w
->hscroll
);
682 int window_needs_modeline
;
684 if (SCREEN_HEIGHT (s
) == 0) abort (); /* Some bug zeros some core */
686 /* If this is a combination window, do its children; that's all. */
688 if (!NULL (w
->vchild
))
690 redisplay_windows (w
->vchild
);
693 if (!NULL (w
->hchild
))
695 redisplay_windows (w
->hchild
);
698 if (NULL (w
->buffer
))
701 if (update_mode_lines
)
702 w
->update_mode_line
= Qt
;
704 /* Otherwise set up data on this window; select its buffer and point value */
706 height
= window_internal_height (w
);
708 if (MINI_WINDOW_P (w
)
710 /* Don't display minibuffers except minibuf_window. */
711 || w
!= XWINDOW (minibuf_window
)))
714 current_buffer
= XBUFFER (w
->buffer
);
717 /* Count number of windows showing the selected buffer. */
720 && current_buffer
== XBUFFER (XWINDOW (selected_window
)->buffer
))
723 /* POINT refers normally to the selected window.
724 For any other window, set up appropriate value. */
726 if (!EQ (window
, selected_window
))
728 SET_PT (marker_position (w
->pointm
));
732 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
734 else if (point
> (ZV
- 1))
737 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
741 /* If window-start is screwed up, choose a new one. */
743 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
746 startp
= marker_position (w
->start
);
748 /* Handle case where place to start displaying has been specified */
750 if (!NULL (w
->force_start
))
752 w
->update_mode_line
= Qt
;
753 w
->force_start
= Qnil
;
754 XFASTINT (w
->last_modified
) = 0;
755 try_window (window
, startp
);
758 /* If point does not appear, move point so it does appear */
759 pos
= *compute_motion (startp
, 0,
760 ((EQ (window
, minibuf_window
) && startp
== 1)
761 ? minibuf_prompt_width
: 0)
763 (hscroll
? 1 - hscroll
: 0),
765 - (1 << (SHORTBITS
- 1)),
766 width
, hscroll
, pos_tab_offset (w
, startp
));
768 if (w
!= XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
769 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
773 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
774 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
780 /* Handle case where text has not changed, only point,
781 and it has not moved off the screen */
783 /* This code is not used for minibuffer for the sake of
784 the case of redisplaying to replace an echo area message;
785 since in that case the minibuffer contents per se are usually unchanged.
786 This code is of no real use in the minibuffer since
787 the handling of this_line_bufpos, etc.,
788 in redisplay handles the same cases. */
790 if (XFASTINT (w
->last_modified
) >= MODIFF
791 && point
>= startp
&& !clip_changed
792 && (just_this_one
|| XFASTINT (w
->width
) == SCREEN_WIDTH (s
))
793 && !EQ (window
, minibuf_window
))
795 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0),
796 point
, height
+ 1, 10000, width
, hscroll
,
797 pos_tab_offset (w
, startp
));
799 if (pos
.vpos
< height
)
801 /* Ok, point is still on screen */
802 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
804 /* These variables are supposed to be origin 1 */
805 SCREEN_CURSOR_X (s
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
806 SCREEN_CURSOR_Y (s
) = pos
.vpos
+ XFASTINT (w
->top
);
808 /* This doesn't do the trick, because if a window to the right of
809 this one must be redisplayed, this does nothing because there
810 is nothing in DesiredScreen yet, and then the other window is
811 redisplayed, making likes that are empty in this window's columns.
812 if (XFASTINT (w->width) != SCREEN_WIDTH (s))
813 preserve_my_columns (w);
817 /* Don't bother trying redisplay with same start;
818 we already know it will lose */
820 /* If current starting point was originally the beginning of a line
821 but no longer is, find a new starting point. */
822 else if (!NULL (w
->start_at_line_beg
)
824 || FETCH_CHAR (startp
- 1) == '\n'))
828 else if (just_this_one
&& !MINI_WINDOW_P (w
)
830 && XFASTINT (w
->last_modified
)
831 && ! EQ (w
->window_end_valid
, Qnil
)
832 && do_id
&& !clip_changed
833 && !blank_end_of_window
834 && XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
835 && EQ (last_arrow_position
, Voverlay_arrow_position
)
836 && EQ (last_arrow_string
, Voverlay_arrow_string
)
837 && (tem
= try_window_id (SCREEN_SELECTED_WINDOW (s
)))
840 /* tem > 0 means success. tem == -1 means choose new start.
841 tem == -2 means try again with same start,
842 and nothing but whitespace follows the changed stuff.
843 tem == 0 means try again with same start. */
847 else if (startp
>= BEGV
&& startp
<= ZV
848 /* Avoid starting display at end of buffer! */
849 && (startp
<= ZV
|| startp
== BEGV
850 || (XFASTINT (w
->last_modified
) >= MODIFF
)))
852 /* Try to redisplay starting at same place as before */
853 /* If point has not moved off screen, accept the results */
854 try_window (window
, startp
);
855 if (cursor_vpos
>= 0)
858 cancel_my_columns (w
);
861 XFASTINT (w
->last_modified
) = 0;
862 w
->update_mode_line
= Qt
;
864 /* Try to scroll by specified few lines */
866 if (scroll_step
&& !clip_changed
)
870 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
871 scroll_step
, width
, hscroll
, window
);
872 if (pos
.vpos
>= height
)
876 pos
= *vmotion (startp
, point
< startp
? - scroll_step
: scroll_step
,
877 width
, hscroll
, window
);
879 if (point
>= pos
.bufpos
)
881 try_window (window
, pos
.bufpos
);
882 if (cursor_vpos
>= 0)
885 cancel_my_columns (w
);
890 /* Finally, just choose place to start which centers point */
893 pos
= *vmotion (point
, - height
/ 2, width
, hscroll
, window
);
894 try_window (window
, pos
.bufpos
);
896 startp
= marker_position (w
->start
);
897 w
->start_at_line_beg
=
898 (startp
== BEGV
|| FETCH_CHAR (startp
- 1) == '\n') ? Qt
: Qnil
;
901 /* If window not full width, must redo its mode line
902 if the window to its side is being redone */
903 if ((!NULL (w
->update_mode_line
)
904 || (!just_this_one
&& width
< SCREEN_WIDTH (s
) - 1))
905 && height
!= XFASTINT (w
->height
))
906 display_mode_line (w
);
909 current_buffer
= old
;
913 /* Do full redisplay on one window, starting at position `pos'. */
916 try_window (window
, pos
)
920 register struct window
*w
= XWINDOW (window
);
921 register int height
= window_internal_height (w
);
922 register int vpos
= XFASTINT (w
->top
);
923 register int last_text_vpos
= vpos
;
924 int tab_offset
= pos_tab_offset (w
, pos
);
925 SCREEN_PTR s
= XSCREEN (w
->screen
);
926 int width
= XFASTINT (w
->width
) - 1
927 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
930 Fset_marker (w
->start
, make_number (pos
), Qnil
);
932 overlay_arrow_seen
= 0;
933 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
935 while (--height
>= 0)
937 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, tab_offset
);
939 if (val
.vpos
) tab_offset
= 0;
941 if (pos
!= val
.bufpos
)
943 /* Next line, unless prev line ended in end of buffer with no cr */
944 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
948 /* If last line is continued in middle of character,
949 include the split character in the text considered on the screen */
950 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
953 /* If bottom just moved off end of screen, change mode line percentage. */
954 if (XFASTINT (w
->window_end_pos
) == 0
956 w
->update_mode_line
= Qt
;
958 /* Say where last char on screen will be, once redisplay is finished. */
959 XFASTINT (w
->window_end_pos
) = Z
- pos
;
960 XFASTINT (w
->window_end_vpos
) = last_text_vpos
- XFASTINT (w
->top
);
961 /* But that is not valid info until redisplay finishes. */
962 w
->window_end_valid
= Qnil
;
965 /* Try to redisplay when buffer is modified locally,
966 computing insert/delete line to preserve text outside
967 the bounds of the changes.
968 Return 1 if successful, 0 if if cannot tell what to do,
969 or -1 to tell caller to find a new window start,
970 or -2 to tell caller to do normal redisplay with same window start. */
973 try_window_id (window
)
977 register struct window
*w
= XWINDOW (window
);
978 register int height
= window_internal_height (w
);
979 SCREEN_PTR s
= XSCREEN (w
->screen
);
980 int top
= XFASTINT (w
->top
);
981 int start
= marker_position (w
->start
);
982 int width
= XFASTINT (w
->width
) - 1
983 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
984 int hscroll
= XINT (w
->hscroll
);
985 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
988 int last_text_vpos
= 0;
991 struct position val
, bp
, ep
, xp
, pp
;
992 int scroll_amount
= 0;
994 int tab_offset
, epto
;
996 if (GPT
- BEG
< beg_unchanged
)
997 beg_unchanged
= GPT
- BEG
;
998 if (Z
- GPT
< end_unchanged
)
999 end_unchanged
= Z
- GPT
;
1001 if (beg_unchanged
+ 1 < start
)
1002 return 0; /* Give up if changes go above top of window */
1004 /* Find position before which nothing is changed. */
1005 bp
= *compute_motion (start
, 0, lmargin
,
1006 beg_unchanged
+ 1, 10000, 10000, width
, hscroll
,
1007 pos_tab_offset (w
, start
));
1008 if (bp
.vpos
>= height
)
1009 return point
< bp
.bufpos
&& !bp
.contin
;
1013 /* Find beginning of that screen line. Must display from there. */
1014 bp
= *vmotion (bp
.bufpos
, 0, width
, hscroll
, window
);
1021 /* If about to start displaying at the beginning of a continuation line,
1022 really start with previous screen line, in case it was not
1023 continued when last redisplayed */
1024 if (bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
1026 bp
= *vmotion (bp
.bufpos
, -1, width
, hscroll
, window
);
1031 if (bp
.contin
&& bp
.hpos
!= lmargin
)
1033 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
1039 /* Find first visible newline after which no more is changed. */
1040 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
1041 if (XTYPE (current_buffer
->selective_display
) == Lisp_Int
1042 && XINT (current_buffer
->selective_display
) > 0)
1044 && (position_indentation (tem
)
1045 >= XINT (current_buffer
->selective_display
)))
1046 tem
= find_next_newline (tem
, 1);
1048 /* Compute the cursor position after that newline. */
1049 ep
= *compute_motion (pos
, vpos
, val
.hpos
, tem
,
1050 height
, - (1 << (SHORTBITS
- 1)),
1051 width
, hscroll
, pos_tab_offset (w
, bp
.bufpos
));
1053 /* If changes reach past the text available on the screen,
1054 just display rest of screen. */
1055 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
1058 stop_vpos
= ep
.vpos
;
1060 /* If no newline before ep, the line ep is on includes some changes
1061 that must be displayed. Make sure we don't stop before it. */
1062 /* Also, if changes reach all the way until ep.bufpos,
1063 it is possible that something was deleted after the
1064 newline before it, so the following line must be redrawn. */
1065 if (stop_vpos
== ep
.vpos
1066 && (ep
.bufpos
== BEGV
1067 || FETCH_CHAR (ep
.bufpos
- 1) != '\n'
1068 || ep
.bufpos
== Z
- end_unchanged
))
1069 stop_vpos
= ep
.vpos
+ 1;
1072 overlay_arrow_seen
= 0;
1074 /* If changes do not reach to bottom of window,
1075 figure out how much to scroll the rest of the window */
1076 if (stop_vpos
< height
)
1078 /* Now determine how far up or down the rest of the window has moved */
1079 epto
= pos_tab_offset (w
, ep
.bufpos
);
1080 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1081 Z
- XFASTINT (w
->window_end_pos
),
1082 10000, 0, width
, hscroll
, epto
);
1083 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
1085 /* Is everything on screen below the changes whitespace?
1086 If so, no scrolling is really necessary. */
1087 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
1089 tem
= FETCH_CHAR (i
);
1090 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
1096 XFASTINT (w
->window_end_vpos
) += scroll_amount
;
1098 /* Before doing any scrolling, verify that point will be on screen. */
1099 if (point
> ep
.bufpos
&& !(point
<= xp
.bufpos
&& xp
.bufpos
< height
))
1101 if (point
<= xp
.bufpos
)
1103 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1104 point
, height
, - (1 << (SHORTBITS
- 1)),
1105 width
, hscroll
, epto
);
1109 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
,
1110 point
, height
, - (1 << (SHORTBITS
- 1)),
1111 width
, hscroll
, pos_tab_offset (w
, xp
.bufpos
));
1113 if (pp
.bufpos
< point
|| pp
.vpos
== height
)
1115 cursor_vpos
= pp
.vpos
+ top
;
1116 cursor_hpos
= pp
.hpos
+ XFASTINT (w
->left
);
1119 if (stop_vpos
- scroll_amount
>= height
1120 || ep
.bufpos
== xp
.bufpos
)
1122 if (scroll_amount
< 0)
1123 stop_vpos
-= scroll_amount
;
1125 /* In this path, we have altered window_end_vpos
1126 and not left it negative.
1127 We must make sure that, in case display is preempted
1128 before the screen changes to reflect what we do here,
1129 further updates will not come to try_window_id
1130 and assume the screen and window_end_vpos match. */
1131 blank_end_of_window
= 1;
1133 else if (!scroll_amount
)
1135 else if (bp
.bufpos
== Z
- end_unchanged
)
1137 /* If reprinting everything is nearly as fast as scrolling,
1138 don't bother scrolling. Can happen if lines are short. */
1139 if (scroll_cost (s
, bp
.vpos
+ top
- scroll_amount
,
1140 top
+ height
- max (0, scroll_amount
),
1142 > xp
.bufpos
- bp
.bufpos
- 20)
1143 /* Return "try normal display with same window-start."
1144 Too bad we can't prevent further scroll-thinking. */
1146 /* If pure deletion, scroll up as many lines as possible.
1147 In common case of killing a line, this can save the
1148 following line from being overwritten by scrolling
1149 and therefore having to be redrawn. */
1150 tem
= scroll_screen_lines (s
, bp
.vpos
+ top
- scroll_amount
,
1151 top
+ height
- max (0, scroll_amount
),
1153 if (!tem
) stop_vpos
= height
;
1155 else if (scroll_amount
)
1157 /* If reprinting everything is nearly as fast as scrolling,
1158 don't bother scrolling. Can happen if lines are short. */
1159 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1160 overestimate of cost of reprinting, since xp.bufpos
1161 would end up below the bottom of the window. */
1162 if (scroll_cost (s
, ep
.vpos
+ top
- scroll_amount
,
1163 top
+ height
- max (0, scroll_amount
),
1165 > xp
.bufpos
- ep
.bufpos
- 20)
1166 /* Return "try normal display with same window-start."
1167 Too bad we can't prevent further scroll-thinking. */
1169 tem
= scroll_screen_lines (s
, ep
.vpos
+ top
- scroll_amount
,
1170 top
+ height
- max (0, scroll_amount
),
1172 if (!tem
) stop_vpos
= height
;
1176 /* In any case, do not display past bottom of window */
1177 if (stop_vpos
>= height
)
1183 /* Handle case where pos is before w->start --
1184 can happen if part of line had been clipped and is not clipped now */
1185 if (vpos
== 0 && pos
< marker_position (w
->start
))
1186 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1188 /* Redisplay the lines where the text was changed */
1189 last_text_vpos
= vpos
;
1190 tab_offset
= pos_tab_offset (w
, pos
);
1191 /* If we are starting display in mid-character, correct tab_offset
1192 to account for passing the line that that character really starts in. */
1193 if (val
.hpos
< lmargin
)
1194 tab_offset
+= width
;
1195 while (vpos
< stop_vpos
)
1197 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1198 tab_offset
+= width
;
1199 if (val
.vpos
) tab_offset
= 0;
1200 if (pos
!= val
.bufpos
)
1202 /* Next line, unless prev line ended in end of buffer with no cr */
1203 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
1207 /* There are two cases:
1208 1) we have displayed down to the bottom of the window
1209 2) we have scrolled lines below stop_vpos by scroll_amount */
1213 /* If last line is continued in middle of character,
1214 include the split character in the text considered on the screen */
1215 if (val
.hpos
< lmargin
)
1217 XFASTINT (w
->window_end_vpos
) = last_text_vpos
;
1218 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1221 /* If scrolling made blank lines at window bottom,
1222 redisplay to fill those lines */
1223 if (scroll_amount
< 0)
1225 /* Don't consider these lines for general-purpose scrolling.
1226 That will save time in the scrolling computation. */
1227 SCREEN_SCROLL_BOTTOM_VPOS (s
) = xp
.vpos
;
1232 vpos
= height
+ scroll_amount
;
1233 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
1235 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
1239 blank_end_of_window
= 1;
1240 tab_offset
= pos_tab_offset (w
, pos
);
1241 /* If we are starting display in mid-character, correct tab_offset
1242 to account for passing the line that that character starts in. */
1243 if (val
.hpos
< lmargin
)
1244 tab_offset
+= width
;
1246 while (vpos
< height
)
1248 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1249 tab_offset
+= width
;
1250 if (val
.vpos
) tab_offset
= 0;
1254 /* Here is a case where display_text_line sets cursor_vpos wrong.
1255 Make it be fixed up, below. */
1257 && xp
.bufpos
== point
)
1261 /* If bottom just moved off end of screen, change mode line percentage. */
1262 if (XFASTINT (w
->window_end_pos
) == 0
1264 w
->update_mode_line
= Qt
;
1266 /* Attempt to adjust end-of-text positions to new bottom line */
1269 delta
= height
- xp
.vpos
;
1271 || (delta
> 0 && xp
.bufpos
<= ZV
)
1272 || (delta
== 0 && xp
.hpos
))
1274 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
1275 delta
, width
, hscroll
, window
);
1276 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1277 XFASTINT (w
->window_end_vpos
) += val
.vpos
;
1281 w
->window_end_valid
= Qnil
;
1283 /* If point was not in a line that was displayed, find it */
1284 if (cursor_vpos
< 0)
1286 val
= *compute_motion (start
, 0, lmargin
, point
, 10000, 10000,
1287 width
, hscroll
, pos_tab_offset (w
, start
));
1288 /* Admit failure if point is off screen now */
1289 if (val
.vpos
>= height
)
1291 for (vpos
= 0; vpos
< height
; vpos
++)
1292 cancel_line (vpos
+ top
, s
);
1295 cursor_vpos
= val
.vpos
+ top
;
1296 cursor_hpos
= val
.hpos
+ XFASTINT (w
->left
);
1299 SCREEN_CURSOR_X (s
) = max (0, cursor_hpos
);
1300 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1304 val
= *compute_motion (start
, 0, lmargin
, ZV
,
1305 height
, - (1 << (SHORTBITS
- 1)),
1306 width
, hscroll
, pos_tab_offset (w
, start
));
1307 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
1309 if (XFASTINT (w
->window_end_pos
)
1317 /* Copy part of the contents of the string FROM into a glyph-vector at S.
1318 But don't actually copy the parts that would come in before T.
1319 Value is T, advanced past the copied data.
1321 Characters in FROM are grouped into units of `sizeof GLYPH' chars;
1322 any extra chars at the end of FROM are ignored. */
1325 copy_rope (t
, s
, from
)
1326 register GLYPH
*t
; /* Copy to here. */
1327 register GLYPH
*s
; /* Starting point. */
1328 Lisp_Object from
; /* Data to copy; known to be a string. */
1330 register int n
= XSTRING (from
)->size
/ sizeof (GLYPH
);
1331 register GLYPH
*f
= (GLYPH
*) XSTRING (from
)->data
;
1335 if (t
>= s
) *t
= *f
;
1342 /* Display one line of window w, starting at position START in W's buffer.
1343 Display starting at horizontal position HPOS, which is normally zero
1344 or negative. A negative value causes output up to hpos = 0 to be discarded.
1345 This is done for negative hscroll, or when this is a continuation line
1346 and the continuation occurred in the middle of a multi-column character.
1348 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
1350 Display on position VPOS on the screen. (origin 0).
1352 Returns a STRUCT POSITION giving character to start next line with
1353 and where to display it, including a zero or negative hpos.
1354 The vpos field is not really a vpos; it is 1 unless the line is continued */
1356 struct position val_display_text_line
;
1358 static struct position
*
1359 display_text_line (w
, start
, vpos
, hpos
, taboffset
)
1366 register int pos
= start
;
1371 register unsigned char *p
;
1373 register GLYPH
*startp
;
1374 register GLYPH
*p1prev
;
1375 SCREEN_PTR s
= XSCREEN (w
->screen
);
1376 int tab_width
= XINT (current_buffer
->tab_width
);
1377 int ctl_arrow
= !NULL (current_buffer
->ctl_arrow
);
1378 int width
= XFASTINT (w
->width
) - 1
1379 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
));
1380 struct position val
;
1383 int hscroll
= XINT (w
->hscroll
);
1384 int truncate
= hscroll
1385 || (truncate_partial_width_windows
1386 && XFASTINT (w
->width
) < SCREEN_WIDTH (s
))
1387 || !NULL (current_buffer
->truncate_lines
);
1389 = XTYPE (current_buffer
->selective_display
) == Lisp_Int
1390 ? XINT (current_buffer
->selective_display
)
1391 : !NULL (current_buffer
->selective_display
) ? -1 : 0;
1393 int selective_e
= selective
&& !NULL (current_buffer
->selective_display_ellipses
);
1395 register struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (s
);
1396 register struct Lisp_Vector
*dp
= window_display_table (w
);
1398 = (selective
&& dp
&& XTYPE (DISP_INVIS_ROPE (dp
)) == Lisp_String
1399 ? XSTRING (DISP_INVIS_ROPE (dp
))->size
/ sizeof (GLYPH
) : 0);
1400 GLYPH truncator
= (dp
== 0 || XTYPE (DISP_TRUNC_GLYPH (dp
)) != Lisp_Int
1401 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
1402 GLYPH continuer
= (dp
== 0 || XTYPE (DISP_CONTINUE_GLYPH (dp
)) != Lisp_Int
1403 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
1405 hpos
+= XFASTINT (w
->left
);
1406 get_display_line (s
, vpos
, XFASTINT (w
->left
));
1407 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
1409 if (MINI_WINDOW_P (w
) && start
== 1
1410 && vpos
== XFASTINT (w
->top
))
1413 hpos
= display_string (w
, vpos
, minibuf_prompt
, hpos
,
1414 (!truncate
? continuer
: truncator
),
1416 minibuf_prompt_width
= hpos
;
1419 desired_glyphs
->bufp
[vpos
] = pos
;
1420 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
1422 startp
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
1423 endp
= startp
+ width
;
1425 /* Loop generating characters.
1426 Stop at end of buffer, before newline,
1427 or if reach or pass continuation column. */
1437 if (pos
== point
&& cursor_vpos
< 0)
1440 cursor_hpos
= p1
- startp
;
1444 if (pos
< point
&& point
< pause
)
1446 if (pos
< GPT
&& GPT
< pause
)
1449 p
= &FETCH_CHAR (pos
);
1452 if (c
>= 040 && c
< 0177
1453 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
1464 && position_indentation (pos
+ 1) >= selective
)
1467 pos
= find_next_newline (pos
+ 1, 1);
1468 if (FETCH_CHAR (pos
- 1) == '\n')
1471 if (invis
&& selective_rlen
> 0 && p1
>= startp
)
1473 p1
+= selective_rlen
;
1474 if (p1
- startp
> width
)
1476 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1477 (p1
- p1prev
) * sizeof (GLYPH
));
1485 if (p1
>= startp
&& p1
< endp
)
1489 while ((p1
- startp
+ taboffset
+ hscroll
- (hscroll
> 0))
1492 else if (c
== Ctl('M') && selective
== -1)
1494 pos
= find_next_newline (pos
, 1);
1495 if (FETCH_CHAR (pos
- 1) == '\n')
1497 if (selective_rlen
> 0)
1499 p1
+= selective_rlen
;
1500 if (p1
- startp
> width
)
1502 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1503 (p1
- p1prev
) * sizeof (GLYPH
));
1507 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
1509 p1
= copy_rope (p1
, startp
, DISP_CHAR_ROPE (dp
, c
));
1511 else if (c
< 0200 && ctl_arrow
)
1514 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
1515 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
1524 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
1525 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
1528 *p1
= (c
>> 6) + '0';
1531 *p1
= (7 & (c
>> 3)) + '0';
1534 *p1
= (7 & c
) + '0';
1540 val
.hpos
= - XINT (w
->hscroll
);
1548 /* Handle continuation in middle of a character */
1549 /* by backing up over it */
1552 /* Start the next line with that same character */
1554 /* but at a negative hpos, to skip the columns output on this line. */
1555 val
.hpos
+= p1prev
- endp
;
1556 /* Keep in this line everything up to the continuation column. */
1560 /* Finish deciding which character to start the next line on,
1561 and what hpos to start it at.
1562 Also set `lastpos' to the last position which counts as "on this line"
1563 for cursor-positioning. */
1567 if (FETCH_CHAR (pos
) == '\n')
1568 /* If stopped due to a newline, start next line after it */
1571 /* Stopped due to right margin of window */
1576 /* Truncating => start next line after next newline,
1577 and point is on this line if it is before the newline,
1578 and skip none of first char of next line */
1579 pos
= find_next_newline (pos
, 1);
1580 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
1582 lastpos
= pos
- (FETCH_CHAR (pos
- 1) == '\n');
1593 /* If point is at eol or in invisible text at eol,
1594 record its screen location now. */
1596 if (start
<= point
&& point
<= lastpos
&& cursor_vpos
< 0)
1599 cursor_hpos
= p1
- startp
;
1602 if (cursor_vpos
== vpos
)
1604 if (cursor_hpos
< 0) cursor_hpos
= 0;
1605 if (cursor_hpos
> width
) cursor_hpos
= width
;
1606 cursor_hpos
+= XFASTINT (w
->left
);
1607 if (w
== XWINDOW (SCREEN_SELECTED_WINDOW (s
)))
1609 SCREEN_CURSOR_Y (s
) = cursor_vpos
;
1610 SCREEN_CURSOR_X (s
) = cursor_hpos
;
1612 if (w
== XWINDOW (selected_window
))
1614 /* Line is not continued and did not start
1615 in middle of character */
1616 if ((hpos
- XFASTINT (w
->left
)
1617 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1620 this_line_bufpos
= start
;
1621 this_line_buffer
= current_buffer
;
1622 this_line_vpos
= cursor_vpos
;
1623 this_line_start_hpos
= hpos
;
1624 this_line_endpos
= Z
- lastpos
;
1627 this_line_bufpos
= 0;
1632 /* If hscroll and line not empty, insert truncation-at-left marker */
1633 if (hscroll
&& lastpos
!= start
)
1635 *startp
= truncator
;
1640 if (XFASTINT (w
->width
) + XFASTINT (w
->left
) != SCREEN_WIDTH (s
))
1643 if (p1
< startp
) p1
= startp
;
1644 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
1647 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
1648 p1
- desired_glyphs
->glyphs
[vpos
]);
1649 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
1651 /* If the start of this line is the overlay arrow-position,
1652 then put the arrow string into the display-line. */
1654 if (XTYPE (Voverlay_arrow_position
) == Lisp_Marker
1655 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
1656 && start
== marker_position (Voverlay_arrow_position
)
1657 && XTYPE (Voverlay_arrow_string
) == Lisp_String
1658 && ! overlay_arrow_seen
)
1660 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
1662 int len
= XSTRING (Voverlay_arrow_string
)->size
;
1664 if (len
> XFASTINT (w
->width
) - 1)
1665 len
= XFASTINT (w
->width
) - 1;
1666 for (i
= 0; i
< len
; i
++)
1668 if (desired_glyphs
->used
[vpos
] <
1669 (len
+ startp
- desired_glyphs
->glyphs
[vpos
]))
1670 desired_glyphs
->used
[vpos
] = len
+ startp
- desired_glyphs
->glyphs
[vpos
];
1672 overlay_arrow_seen
= 1;
1676 val_display_text_line
= val
;
1677 return &val_display_text_line
;
1680 /* Display the mode line for window w */
1683 display_mode_line (w
)
1686 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
1687 register int left
= XFASTINT (w
->left
);
1688 register int right
= XFASTINT (w
->width
) + left
;
1689 register SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (w
));
1691 get_display_line (s
, vpos
, left
);
1692 display_mode_element (w
, vpos
, left
, 0, right
, right
,
1693 current_buffer
->mode_line_format
);
1694 SCREEN_DESIRED_GLYPHS (s
)->bufp
[vpos
] = 0;
1696 /* Make the mode line inverse video if the entire line
1697 is made of mode lines.
1698 I.e. if this window is full width,
1699 or if it is the child of a full width window
1700 (which implies that that window is split side-by-side
1701 and the rest of this line is mode lines of the sibling windows). */
1702 if (XFASTINT (w
->width
) == SCREEN_WIDTH (s
)
1703 || XFASTINT (XWINDOW (w
->parent
)->width
) == SCREEN_WIDTH (s
))
1704 s
->desired_glyphs
->highlight
[vpos
] = mode_line_inverse_video
;
1706 #ifdef HAVE_X_WINDOWS
1707 /* I'm trying this out because I saw Unimpress use it, but it's
1708 possible that this may fuck adversely with some window managers. jla */
1711 && (XTYPE (Vglobal_minibuffer_screen
) != Lisp_Screen
1712 || s
!= XSCREEN (Vglobal_minibuffer_screen
))
1713 && w
== XWINDOW (s
->selected_window
)
1714 && (NULL (Fstring_equal (XBUFFER (w
->buffer
)->name
, s
->name
))))
1715 x_set_name (s
, XBUFFER (w
->buffer
)->name
, Qnil
);
1719 /* Contribute ELT to the mode line for window W.
1720 How it translates into text depends on its data type.
1722 VPOS is the position of the mode line being displayed.
1724 HPOS is the position (absolute on screen) where this element's text
1725 should start. The output is truncated automatically at the right
1728 DEPTH is the depth in recursion. It is used to prevent
1729 infinite recursion here.
1731 MINENDCOL is the hpos before which the element may not end.
1732 The element is padded at the right with spaces if nec
1733 to reach this column.
1735 MAXENDCOL is the hpos past which this element may not extend.
1736 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
1737 (This is necessary to make nested padding and truncation work.)
1739 Returns the hpos of the end of the text generated by ELT.
1740 The next element will receive that value as its HPOS arg,
1741 so as to concatenate the elements. */
1744 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
1746 register int vpos
, hpos
;
1749 register int maxendcol
;
1750 register Lisp_Object elt
;
1758 #ifdef SWITCH_ENUM_BUG
1759 switch ((int) XTYPE (elt
))
1761 switch (XTYPE (elt
))
1766 /* A string: output it and check for %-constructs within it. */
1767 register unsigned char c
;
1768 register unsigned char *this = XSTRING (elt
)->data
;
1770 while (hpos
< maxendcol
&& *this)
1772 unsigned char *last
= this;
1773 while ((c
= *this++) != '\0' && c
!= '%')
1775 if (this - 1 != last
)
1777 register int lim
= --this - last
+ hpos
;
1778 hpos
= display_string (w
, vpos
, last
, hpos
, 0, hpos
,
1779 min (lim
, maxendcol
));
1783 register int spec_width
= 0;
1785 /* We can't allow -ve args due to the "%-" construct */
1786 /* Argument specifies minwidth but not maxwidth
1787 (maxwidth can be specified by
1788 (<negative-number> . <stuff>) mode-line elements) */
1790 while ((c
= *this++) >= '0' && c
<= '9')
1792 spec_width
= spec_width
* 10 + (c
- '0');
1796 if (spec_width
> maxendcol
)
1797 spec_width
= maxendcol
;
1800 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1801 spec_width
, maxendcol
,
1802 Vglobal_mode_string
);
1804 hpos
= display_string (w
, vpos
,
1805 decode_mode_spec (w
, c
,
1807 hpos
, 0, spec_width
, maxendcol
);
1814 /* A symbol: process the value of the symbol recursively
1815 as if it appeared here directly. Avoid error if symbol void.
1816 Special case: if value of symbol is a string, output the string
1819 register Lisp_Object tem
;
1820 tem
= Fboundp (elt
);
1823 tem
= Fsymbol_value (elt
);
1824 /* If value is a string, output that string literally:
1825 don't check for % within it. */
1826 if (XTYPE (tem
) == Lisp_String
)
1827 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
1828 hpos
, 0, minendcol
, maxendcol
);
1829 /* Give up right away for nil or t. */
1830 else if (!EQ (tem
, elt
))
1831 { elt
= tem
; goto tail_recurse
; }
1838 register Lisp_Object car
, tem
;
1840 /* A cons cell: three distinct cases.
1841 If first element is a string or a cons, process all the elements
1842 and effectively concatenate them.
1843 If first element is a negative number, truncate displaying cdr to
1844 at most that many characters. If positive, pad (with spaces)
1845 to at least that many characters.
1846 If first element is a symbol, process the cadr or caddr recursively
1847 according to whether the symbol's value is non-nil or nil. */
1848 car
= XCONS (elt
)->car
;
1849 if (XTYPE (car
) == Lisp_Symbol
)
1851 tem
= Fboundp (car
);
1852 elt
= XCONS (elt
)->cdr
;
1853 if (XTYPE (elt
) != Lisp_Cons
)
1855 /* elt is now the cdr, and we know it is a cons cell.
1856 Use its car if CAR has a non-nil value. */
1859 tem
= Fsymbol_value (car
);
1861 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
1863 /* Symbol's value is nil (or symbol is unbound)
1864 Get the cddr of the original list
1865 and if possible find the caddr and use that. */
1866 elt
= XCONS (elt
)->cdr
;
1869 else if (XTYPE (elt
) != Lisp_Cons
)
1871 elt
= XCONS (elt
)->car
;
1874 else if (XTYPE (car
) == Lisp_Int
)
1876 register int lim
= XINT (car
);
1877 elt
= XCONS (elt
)->cdr
;
1879 /* Negative int means reduce maximum width.
1880 DO NOT change MINENDCOL here!
1881 (20 -10 . foo) should truncate foo to 10 col
1882 and then pad to 20. */
1883 maxendcol
= min (maxendcol
, hpos
- lim
);
1886 /* Padding specified. Don't let it be more than
1889 if (lim
> maxendcol
)
1891 /* If that's more padding than already wanted, queue it.
1892 But don't reduce padding already specified even if
1893 that is beyond the current truncation point. */
1894 if (lim
> minendcol
)
1899 else if (XTYPE (car
) == Lisp_String
|| XTYPE (car
) == Lisp_Cons
)
1901 register int limit
= 50;
1902 /* LIMIT is to protect against circular lists. */
1903 while (XTYPE (elt
) == Lisp_Cons
&& --limit
> 0
1904 && hpos
< maxendcol
)
1906 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1909 elt
= XCONS (elt
)->cdr
;
1917 return (display_string (w
, vpos
, "*invalid*", hpos
, 0,
1918 minendcol
, maxendcol
));
1922 if (minendcol
> hpos
)
1923 hpos
= display_string (w
, vpos
, "", hpos
, 0, minendcol
, -1);
1927 /* Return a string for the output of a mode line %-spec for window W,
1928 generated by character C and width MAXWIDTH. */
1931 decode_mode_spec (w
, c
, maxwidth
)
1934 register int maxwidth
;
1936 Lisp_Object obj
= Qnil
;
1937 SCREEN_PTR scr
= XSCREEN (WINDOW_SCREEN (w
));
1938 char *decode_mode_spec_buf
= (char *) SCREEN_TEMP_GLYPHS (scr
)->total_contents
;
1940 if (maxwidth
> SCREEN_WIDTH (scr
))
1941 maxwidth
= SCREEN_WIDTH (scr
);
1946 obj
= current_buffer
->name
;
1948 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
1950 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
1951 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
1952 decode_mode_spec_buf
[maxwidth
] = '\0';
1953 return decode_mode_spec_buf
;
1959 obj
= current_buffer
->filename
;
1963 else if (XTYPE (obj
) == Lisp_String
&& XSTRING (obj
)->size
> maxwidth
)
1965 bcopy ("...", decode_mode_spec_buf
, 3);
1966 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
1967 decode_mode_spec_buf
+ 3, maxwidth
- 3);
1968 return decode_mode_spec_buf
;
1974 obj
= current_buffer
->mode_name
;
1978 if (BEGV
> BEG
|| ZV
< Z
)
1983 if (!NULL (current_buffer
->read_only
))
1985 if (MODIFF
> current_buffer
->save_modified
)
1990 /* status of process */
1992 obj
= Fget_buffer_process (Fcurrent_buffer ());
1994 return "no process";
1995 obj
= Fsymbol_name (Fprocess_status (obj
));
1998 return "no processes";
1999 #endif /* subprocesses */
2003 int pos
= marker_position (w
->start
);
2004 int total
= ZV
- BEGV
;
2006 if (XFASTINT (w
->window_end_pos
) <= Z
- ZV
)
2013 else if (pos
<= BEGV
)
2017 total
= ((pos
- BEGV
) * 100 + total
- 1) / total
;
2018 /* We can't normally display a 3-digit number,
2019 so get us a 2-digit number that is close. */
2022 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
2023 return decode_mode_spec_buf
;
2035 if (command_loop_level
> 5)
2037 p
= decode_mode_spec_buf
;
2038 for (i
= 0; i
< command_loop_level
; i
++)
2041 return decode_mode_spec_buf
;
2049 if (command_loop_level
> 5)
2051 p
= decode_mode_spec_buf
;
2052 for (i
= 0; i
< command_loop_level
; i
++)
2055 return decode_mode_spec_buf
;
2060 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
2064 if (maxwidth
< sizeof (lots_of_dashes
))
2065 return lots_of_dashes
;
2068 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
2072 return decode_mode_spec_buf
;
2076 if (XTYPE (obj
) == Lisp_String
)
2077 return (char *) XSTRING (obj
)->data
;
2082 /* Display STRING on one line of window W, starting at HPOS.
2083 Display at position VPOS. Caller should have done get_display_line.
2085 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
2087 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
2088 MAXCOL is the last column ok to end at. Truncate here.
2089 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
2090 Both count from the left edge of the screen, as does HPOS.
2091 The right edge of W is an implicit maximum.
2092 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
2094 Returns ending hpos */
2097 display_string (w
, vpos
, string
, hpos
, truncate
, mincol
, maxcol
)
2099 unsigned char *string
;
2106 int hscroll
= XINT (w
->hscroll
);
2107 int tab_width
= XINT (current_buffer
->tab_width
);
2108 register GLYPH
*start
;
2109 register GLYPH
*end
;
2110 struct screen_glyphs
*desired_glyphs
= SCREEN_DESIRED_GLYPHS (XSCREEN (w
->screen
));
2111 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2112 int window_width
= XFASTINT (w
->width
);
2114 /* Use the standard display table, not the window's display table.
2115 We don't want the mode line in rot13. */
2116 register struct Lisp_Vector
*dp
= 0;
2118 if (XTYPE (Vstandard_display_table
) == Lisp_Vector
2119 && XVECTOR (Vstandard_display_table
)->size
== DISP_TABLE_SIZE
)
2120 dp
= XVECTOR (Vstandard_display_table
);
2122 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
2125 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
2126 end
= start
+ window_width
- (truncate
!= 0);
2128 if ((window_width
+ XFASTINT (w
->left
))
2129 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w
))))
2132 if (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
)
2133 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
2134 if (maxcol
>= 0 && mincol
> maxcol
)
2141 if (c
>= 040 && c
< 0177
2142 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
2152 if (p1
>= start
&& p1
< end
)
2156 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
2158 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
2159 p1
= copy_rope (p1
, start
, DISP_CHAR_ROPE (dp
, c
));
2160 else if (c
< 0200 && buffer_defaults
.ctl_arrow
)
2163 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
2164 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
2173 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
2174 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
2177 *p1
= (c
>> 6) + '0';
2180 *p1
= (7 & (c
>> 3)) + '0';
2183 *p1
= (7 & c
) + '0';
2191 if (truncate
) *p1
++ = truncate
;
2193 else if (mincol
>= 0)
2195 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
2201 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
2203 if (len
> desired_glyphs
->used
[vpos
])
2204 desired_glyphs
->used
[vpos
] = len
;
2205 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
2214 staticpro (&last_arrow_position
);
2215 staticpro (&last_arrow_string
);
2216 last_arrow_position
= Qnil
;
2217 last_arrow_string
= Qnil
;
2219 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
2220 "String displayed by mode-line-format's \"%m\" specifiation.");
2221 Vglobal_mode_string
= Qnil
;
2223 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
2224 "Marker for where to display an arrow on top of the buffer text.\n\
2225 This must be the beginning of a line in order to work.\n\
2226 See also `overlay-arrow-string'.");
2227 Voverlay_arrow_position
= Qnil
;
2229 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
2230 "String to display as an arrow. See also `overlay-arrow-position'.");
2231 Voverlay_arrow_string
= Qnil
;
2233 DEFVAR_INT ("scroll-step", &scroll_step
,
2234 "*The number of lines to try scrolling a window by when point moves out.\n\
2235 If that fails to bring point back on screen, point is centered instead.\n\
2236 If this is zero, point is always centered after it moves off screen.");
2238 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
2240 DEFVAR_BOOL ("truncate-partial-width-windows",
2241 &truncate_partial_width_windows
,
2242 "*Non-nil means truncate lines in all windows less than full screen wide.");
2243 truncate_partial_width_windows
= 1;
2245 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
2246 "*Non-nil means use inverse video for the mode line.");
2247 mode_line_inverse_video
= 1;
2249 #ifndef MULTI_SCREEN
2250 defsubr (&Sredraw_display
);
2251 #endif /* MULTI_SCREEN */
2254 /* initialize the window system */
2257 Lisp_Object root_window
;
2258 #ifndef COMPILER_REGISTER_BUG
2260 #endif /* COMPILER_REGISTER_BUG */
2261 struct window
*mini_w
;
2263 this_line_bufpos
= 0;
2265 mini_w
= XWINDOW (minibuf_window
);
2266 root_window
= mini_w
->prev
;
2268 echo_area_glyphs
= 0;
2269 previous_echo_glyphs
= 0;
2271 if (!noninteractive
)
2273 SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (XWINDOW (root_window
)));
2274 XFASTINT (XWINDOW (root_window
)->top
) = 0;
2275 set_window_height (root_window
, SCREEN_HEIGHT (s
) - 1, 0);
2276 XFASTINT (mini_w
->top
) = SCREEN_HEIGHT (s
) - 1;
2277 set_window_height (minibuf_window
, 1, 0);
2279 XFASTINT (XWINDOW (root_window
)->width
) = SCREEN_WIDTH (s
);
2280 XFASTINT (mini_w
->width
) = SCREEN_WIDTH (s
);