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 frame line.
48 Or zero, which disables the optimization for the current frame 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 frame line. */
56 static int this_line_vpos
;
58 /* Hpos value for start of display on this frame 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 frame. 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 frame
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 frame */
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 frame,
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 frame 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
;
170 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
171 zero if being used by message. */
172 int message_buf_print
;
174 /* dump an informative message to the minibuf */
178 message (m
, a1
, a2
, a3
)
183 if (noninteractive_need_newline
)
185 noninteractive_need_newline
= 0;
186 fprintf (stderr
, m
, a1
, a2
, a3
);
187 fprintf (stderr
, "\n");
190 /* A null message buffer means that the frame hasn't really been
191 initialized yet. Error messages get reported properly by
192 cmd_error, so this must be just an informative message; toss it. */
193 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
196 Lisp_Object minibuf_frame
;
198 choose_minibuf_frame ();
199 minibuf_frame
= WINDOW_FRAME (XWINDOW (minibuf_window
));
200 if (FRAME_VISIBLE_P (selected_frame
)
201 && ! FRAME_VISIBLE_P (XFRAME (minibuf_frame
)))
202 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (minibuf_window
)));
212 doprnt (FRAME_MESSAGE_BUF (selected_frame
),
213 FRAME_WIDTH (selected_frame
), m
, 0, 3, a
);
215 doprnt (FRAME_MESSAGE_BUF (selected_frame
),
216 FRAME_WIDTH (selected_frame
), m
, 0, 3, &a1
);
217 #endif /* NO_ARG_ARRAY */
220 echo_area_glyphs
= FRAME_MESSAGE_BUF (selected_frame
);
222 /* Print should start at the beginning of the message
224 message_buf_print
= 0;
226 do_pending_window_change ();
227 echo_area_display ();
228 update_frame (XFRAME (XWINDOW (minibuf_window
)->frame
), 1, 1);
229 do_pending_window_change ();
233 /* Specify m, a string, as a message in the minibuf. */
240 if (noninteractive_need_newline
)
242 noninteractive_need_newline
= 0;
243 fprintf (stderr
, "%s\n", m
);
246 /* A null message buffer means that the frame hasn't really been
247 initialized yet. Error messages get reported properly by
248 cmd_error, so this must be just an informative message; toss it. */
249 else if (INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
252 Lisp_Object minibuf_frame
;
254 choose_minibuf_frame ();
255 minibuf_frame
= WINDOW_FRAME (XWINDOW (minibuf_window
));
256 if (FRAME_VISIBLE_P (selected_frame
)
257 && ! FRAME_VISIBLE_P (XFRAME (minibuf_frame
)))
258 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (minibuf_window
)));
261 echo_area_glyphs
= m
;
262 do_pending_window_change ();
263 echo_area_display ();
264 update_frame (XFRAME (XWINDOW (minibuf_window
)->frame
), 1, 1);
265 do_pending_window_change ();
276 choose_minibuf_frame ();
277 f
= XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)));
279 if (! FRAME_VISIBLE_P (f
))
289 if (echo_area_glyphs
|| minibuf_level
== 0)
291 vpos
= XFASTINT (XWINDOW (minibuf_window
)->top
);
292 get_display_line (f
, vpos
, 0);
293 display_string (XWINDOW (minibuf_window
), vpos
,
294 echo_area_glyphs
? echo_area_glyphs
: "",
295 0, 0, 0, FRAME_WIDTH (f
));
297 /* If desired cursor location is on this line, put it at end of text */
298 if (FRAME_CURSOR_Y (f
) == vpos
)
299 FRAME_CURSOR_X (f
) = FRAME_DESIRED_GLYPHS (f
)->used
[vpos
];
301 /* Fill the rest of the minibuffer window with blank lines. */
305 for (i
= vpos
+ 1; i
< vpos
+ XWINDOW (minibuf_window
)->height
; i
++)
307 get_display_line (f
, i
, 0);
308 display_string (XWINDOW (minibuf_window
), vpos
,
309 "", 0, 0, 0, FRAME_WIDTH (f
));
313 else if (!EQ (minibuf_window
, selected_window
))
314 windows_or_buffers_changed
++;
316 if (EQ (minibuf_window
, selected_window
))
317 this_line_bufpos
= 0;
319 previous_echo_glyphs
= echo_area_glyphs
;
322 /* Do a frame update, taking possible shortcuts into account.
323 This is the main external entry point for redisplay.
325 If the last redisplay displayed an echo area message and that
326 message is no longer requested, we clear the echo area
327 or bring back the minibuffer if that is in use.
329 Everyone would like to have a hook here to call eval,
330 but that cannot be done safely without a lot of changes elsewhere.
331 This can be called from signal handlers; with alarms set up;
332 or with synchronous processes running.
333 See the function `echo' in keyboard.c.
334 See Fcall_process; if you called it from here, it could be
335 entered recursively. */
340 register struct window
*w
= XWINDOW (selected_window
);
344 register int tlbufpos
, tlendpos
;
346 extern int input_pending
;
351 /* Notice any pending interrupt request to change frame size. */
352 do_pending_window_change ();
360 /* Normally the message* functions will have already displayed and
361 updated the echo area, but the frame may have been trashed, or
362 the update may have been preempted, so display the echo area
364 if (echo_area_glyphs
|| previous_echo_glyphs
)
366 echo_area_display ();
370 if (clip_changed
|| windows_or_buffers_changed
)
373 /* Detect case that we need to write a star in the mode line. */
374 if (XFASTINT (w
->last_modified
) < MODIFF
375 && XFASTINT (w
->last_modified
) <= current_buffer
->save_modified
)
377 w
->update_mode_line
= Qt
;
378 if (buffer_shared
> 1)
382 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
384 all_windows
= update_mode_lines
|| buffer_shared
> 1;
386 /* If specs for an arrow have changed, do thorough redisplay
387 to ensure we remove any arrow that should no longer exist. */
388 if (Voverlay_arrow_position
!= last_arrow_position
389 || Voverlay_arrow_string
!= last_arrow_string
)
390 all_windows
= 1, clip_changed
= 1;
392 tlbufpos
= this_line_bufpos
;
393 tlendpos
= this_line_endpos
;
394 if (!all_windows
&& tlbufpos
> 0 && NILP (w
->update_mode_line
)
395 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
396 /* Make sure recorded data applies to current buffer, etc */
397 && this_line_buffer
== current_buffer
398 && current_buffer
== XBUFFER (w
->buffer
)
399 && NILP (w
->force_start
)
400 /* Point must be on the line that we have info recorded about */
402 && point
<= Z
- tlendpos
403 /* All text outside that line, including its final newline,
405 && (XFASTINT (w
->last_modified
) >= MODIFF
406 || (beg_unchanged
>= tlbufpos
- 1
408 /* If selective display, can't optimize
409 if the changes start at the beginning of the line. */
410 && ((XTYPE (current_buffer
->selective_display
) == Lisp_Int
411 && XINT (current_buffer
->selective_display
) > 0
412 ? (beg_unchanged
>= tlbufpos
415 && end_unchanged
>= tlendpos
416 && Z
- GPT
>= tlendpos
)))
418 if (tlbufpos
> BEGV
&& FETCH_CHAR (tlbufpos
- 1) != '\n'
420 || FETCH_CHAR (tlbufpos
) == '\n'))
421 /* Former continuation line has disappeared by becoming empty */
423 else if (XFASTINT (w
->last_modified
) < MODIFF
424 || MINI_WINDOW_P (w
))
427 overlay_arrow_seen
= 0;
428 display_text_line (w
, tlbufpos
, this_line_vpos
, this_line_start_hpos
,
429 pos_tab_offset (w
, tlbufpos
));
430 /* If line contains point, is not continued,
431 and ends at same distance from eob as before, we win */
432 if (cursor_vpos
>= 0 && this_line_bufpos
433 && this_line_endpos
== tlendpos
)
435 if (XFASTINT (w
->width
) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w
))))
436 preserve_other_columns (w
);
442 else if (point
== XFASTINT (w
->last_point
))
446 do_pending_window_change ();
453 pos
= *compute_motion (tlbufpos
, 0,
454 XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0,
455 point
, 2, - (1 << (SHORTBITS
- 1)),
456 XFASTINT (w
->width
) - 1
457 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
458 != FRAME_WIDTH (selected_frame
)),
460 pos_tab_offset (w
, tlbufpos
));
463 FRAME_CURSOR_X (selected_frame
)
464 = XFASTINT (w
->left
) + max (pos
.hpos
, 0);
465 FRAME_CURSOR_Y (selected_frame
) = this_line_vpos
;
472 /* Text changed drastically or point moved off of line */
473 cancel_line (this_line_vpos
, selected_frame
);
476 this_line_bufpos
= 0;
477 all_windows
|= buffer_shared
> 1;
484 /* Recompute # windows showing selected buffer.
485 This will be incremented each time such a window is displayed. */
488 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
492 if (XTYPE (XCONS (tail
)->car
) != Lisp_Frame
)
495 f
= XFRAME (XCONS (tail
)->car
);
497 /* Redraw its windows. */
498 redisplay_windows (FRAME_ROOT_WINDOW (f
));
501 redisplay_windows (FRAME_ROOT_WINDOW (f
));
502 #endif /* not MULTI_FRAME */
504 else if (FRAME_VISIBLE_P (selected_frame
))
506 redisplay_window (selected_window
, 1);
507 if (XFASTINT (w
->width
) != FRAME_WIDTH (selected_frame
))
508 preserve_other_columns (w
);
512 /* Prevent various kinds of signals during display update.
513 stdio is not robust about handling signals,
514 which can cause an apparent I/O error. */
526 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
530 if (XTYPE (XCONS (tail
)->car
) != Lisp_Frame
)
533 f
= XFRAME (XCONS (tail
)->car
);
536 pause
|= update_frame (f
, 0, 0);
538 mark_window_display_accurate (f
->root_window
, 1);
543 #endif /* MULTI_FRAME */
545 if (FRAME_VISIBLE_P (selected_frame
))
546 pause
= update_frame (selected_frame
, 0, 0);
548 /* We may have called echo_area_display at the top of this
549 function. If the echo area is on another frame, that may
550 have put text on a frame other than the selected one, so the
551 above call to update_frame would not have caught it. Catch
554 FRAME_PTR mini_frame
=
555 XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)));
557 if (mini_frame
!= selected_frame
)
558 pause
|= update_frame (mini_frame
, 0, 0);
563 /* If frame does not match, prevent doing single-line-update next time.
564 Also, don't forget to check every line to update the arrow. */
567 this_line_bufpos
= 0;
568 if (!NILP (last_arrow_position
))
570 last_arrow_position
= Qt
;
571 last_arrow_string
= Qt
;
573 /* If we pause after scrolling, some lines in current_frame
574 may be null, so preserve_other_columns won't be able to
575 preserve all the vertical-bar separators. So, avoid using it
577 if (XFASTINT (w
->width
) != FRAME_WIDTH (selected_frame
))
578 update_mode_lines
= 1;
581 /* Now text on frame agrees with windows, so
582 put info into the windows for partial redisplay to follow */
586 register struct buffer
*b
= XBUFFER (w
->buffer
);
588 blank_end_of_window
= 0;
590 unchanged_modified
= BUF_MODIFF (b
);
591 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
592 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
594 XFASTINT (w
->last_point
) = BUF_PT (b
);
595 XFASTINT (w
->last_point_x
) = FRAME_CURSOR_X (selected_frame
);
596 XFASTINT (w
->last_point_y
) = FRAME_CURSOR_Y (selected_frame
);
599 mark_window_display_accurate (XWINDOW (minibuf_window
)->prev
, 1);
602 w
->update_mode_line
= Qnil
;
603 XFASTINT (w
->last_modified
) = BUF_MODIFF (b
);
604 w
->window_end_valid
= Qt
;
605 last_arrow_position
= Voverlay_arrow_position
;
606 last_arrow_string
= Voverlay_arrow_string
;
608 update_mode_lines
= 0;
609 windows_or_buffers_changed
= 0;
612 /* Start SIGIO interrupts coming again.
613 Having them off during the code above
614 makes it less likely one will discard output,
615 but not impossible, since there might be stuff
616 in the system buffer here.
617 But it is much hairier to try to do anything about that. */
623 /* Change frame size now if a change is pending. */
624 do_pending_window_change ();
627 /* Redisplay, but leave alone any recent echo area message
628 unless another message has been requested in its place.
630 This is useful in situations where you need to redisplay but no
631 user action has occurred, making it inappropriate for the message
632 area to be cleared. See tracking_off and
633 wait_reading_process_input for examples of these situations. */
635 redisplay_preserve_echo_area ()
637 if (echo_area_glyphs
== 0 && previous_echo_glyphs
!= 0)
639 echo_area_glyphs
= previous_echo_glyphs
;
641 echo_area_glyphs
= 0;
648 mark_window_display_accurate (window
, flag
)
652 register struct window
*w
;
654 for (;!NILP (window
); window
= w
->next
)
656 w
= XWINDOW (window
);
658 if (!NILP (w
->buffer
))
659 XFASTINT (w
->last_modified
)
661 : XBUFFER (w
->buffer
) == current_buffer
662 ? MODIFF
: BUF_MODIFF (XBUFFER (w
->buffer
));
663 w
->window_end_valid
= Qt
;
664 w
->update_mode_line
= Qnil
;
666 if (!NILP (w
->vchild
))
667 mark_window_display_accurate (w
->vchild
, flag
);
668 if (!NILP (w
->hchild
))
669 mark_window_display_accurate (w
->hchild
, flag
);
674 last_arrow_position
= Voverlay_arrow_position
;
675 last_arrow_string
= Voverlay_arrow_string
;
679 /* t is unequal to any useful value of Voverlay_arrow_... */
680 last_arrow_position
= Qt
;
681 last_arrow_string
= Qt
;
688 redisplay_windows (window
)
691 for (; !NILP (window
); window
= XWINDOW (window
)->next
)
692 redisplay_window (window
, 0);
696 redisplay_window (window
, just_this_one
)
700 register struct window
*w
= XWINDOW (window
);
701 FRAME_PTR f
= XFRAME (w
->frame
);
703 register int lpoint
= point
;
704 struct buffer
*old
= current_buffer
;
705 register int width
= XFASTINT (w
->width
) - 1
706 - (XFASTINT (w
->width
) + XFASTINT (w
->left
)
707 != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w
))));
709 register int hscroll
= XINT (w
->hscroll
);
713 int window_needs_modeline
;
715 if (FRAME_HEIGHT (f
) == 0) abort (); /* Some bug zeros some core */
717 /* If this is a combination window, do its children; that's all. */
719 if (!NILP (w
->vchild
))
721 redisplay_windows (w
->vchild
);
724 if (!NILP (w
->hchild
))
726 redisplay_windows (w
->hchild
);
729 if (NILP (w
->buffer
))
732 height
= window_internal_height (w
);
734 if (MINI_WINDOW_P (w
))
736 if (w
== XWINDOW (minibuf_window
))
738 if (echo_area_glyphs
)
739 /* We've already displayed the echo area glyphs, if any. */
744 /* This is a minibuffer, but it's not the currently active one, so
746 int vpos
= XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f
))->top
);
749 for (i
= 0; i
< height
; i
++)
751 get_display_line (f
, vpos
+ i
, 0);
752 display_string (w
, vpos
+ i
, "", 0, 0, 0, width
);
759 if (update_mode_lines
)
760 w
->update_mode_line
= Qt
;
762 /* Otherwise set up data on this window; select its buffer and point value */
764 current_buffer
= XBUFFER (w
->buffer
);
767 /* Count number of windows showing the selected buffer. */
770 && current_buffer
== XBUFFER (XWINDOW (selected_window
)->buffer
))
773 /* POINT refers normally to the selected window.
774 For any other window, set up appropriate value. */
776 if (!EQ (window
, selected_window
))
778 SET_PT (marker_position (w
->pointm
));
782 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
784 else if (point
> (ZV
- 1))
787 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
791 /* If window-start is screwed up, choose a new one. */
792 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
795 startp
= marker_position (w
->start
);
797 /* Handle case where place to start displaying has been specified,
798 unless the specified location is outside the visible range. */
799 if (!NILP (w
->force_start
))
801 w
->update_mode_line
= Qt
;
802 w
->force_start
= Qnil
;
803 XFASTINT (w
->last_modified
) = 0;
804 if (startp
< BEGV
) startp
= BEGV
;
805 if (startp
> ZV
) startp
= ZV
;
806 try_window (window
, startp
);
809 /* If point does not appear, move point so it does appear */
810 pos
= *compute_motion (startp
, 0,
811 ((EQ (window
, minibuf_window
) && startp
== 1)
812 ? minibuf_prompt_width
: 0)
814 (hscroll
? 1 - hscroll
: 0),
816 - (1 << (SHORTBITS
- 1)),
817 width
, hscroll
, pos_tab_offset (w
, startp
));
819 if (w
!= XWINDOW (FRAME_SELECTED_WINDOW (f
)))
820 Fset_marker (w
->pointm
, make_number (point
), Qnil
);
824 FRAME_CURSOR_X (f
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
825 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
831 /* Handle case where text has not changed, only point,
832 and it has not moved off the frame */
834 /* This code is not used for minibuffer for the sake of
835 the case of redisplaying to replace an echo area message;
836 since in that case the minibuffer contents per se are usually unchanged.
837 This code is of no real use in the minibuffer since
838 the handling of this_line_bufpos, etc.,
839 in redisplay handles the same cases. */
841 if (XFASTINT (w
->last_modified
) >= MODIFF
842 && point
>= startp
&& !clip_changed
843 && (just_this_one
|| XFASTINT (w
->width
) == FRAME_WIDTH (f
))
844 && !EQ (window
, minibuf_window
))
846 pos
= *compute_motion (startp
, 0, (hscroll
? 1 - hscroll
: 0),
847 point
, height
+ 1, 10000, width
, hscroll
,
848 pos_tab_offset (w
, startp
));
850 if (pos
.vpos
< height
)
852 /* Ok, point is still on frame */
853 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
855 /* These variables are supposed to be origin 1 */
856 FRAME_CURSOR_X (f
) = max (0, pos
.hpos
) + XFASTINT (w
->left
);
857 FRAME_CURSOR_Y (f
) = pos
.vpos
+ XFASTINT (w
->top
);
859 /* This doesn't do the trick, because if a window to the right of
860 this one must be redisplayed, this does nothing because there
861 is nothing in DesiredFrame yet, and then the other window is
862 redisplayed, making likes that are empty in this window's columns.
863 if (XFASTINT (w->width) != FRAME_WIDTH (f))
864 preserve_my_columns (w);
868 /* Don't bother trying redisplay with same start;
869 we already know it will lose */
871 /* If current starting point was originally the beginning of a line
872 but no longer is, find a new starting point. */
873 else if (!NILP (w
->start_at_line_beg
)
875 || FETCH_CHAR (startp
- 1) == '\n'))
879 else if (just_this_one
&& !MINI_WINDOW_P (w
)
881 && XFASTINT (w
->last_modified
)
882 && ! EQ (w
->window_end_valid
, Qnil
)
883 && do_id
&& !clip_changed
884 && !blank_end_of_window
885 && XFASTINT (w
->width
) == FRAME_WIDTH (f
)
886 && EQ (last_arrow_position
, Voverlay_arrow_position
)
887 && EQ (last_arrow_string
, Voverlay_arrow_string
)
888 && (tem
= try_window_id (FRAME_SELECTED_WINDOW (f
)))
891 /* tem > 0 means success. tem == -1 means choose new start.
892 tem == -2 means try again with same start,
893 and nothing but whitespace follows the changed stuff.
894 tem == 0 means try again with same start. */
898 else if (startp
>= BEGV
&& startp
<= ZV
899 /* Avoid starting display at end of buffer! */
900 && (startp
< ZV
|| startp
== BEGV
901 || (XFASTINT (w
->last_modified
) >= MODIFF
)))
903 /* Try to redisplay starting at same place as before */
904 /* If point has not moved off frame, accept the results */
905 try_window (window
, startp
);
906 if (cursor_vpos
>= 0)
909 cancel_my_columns (w
);
912 XFASTINT (w
->last_modified
) = 0;
913 w
->update_mode_line
= Qt
;
915 /* Try to scroll by specified few lines */
917 if (scroll_step
&& !clip_changed
)
921 pos
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
922 scroll_step
, width
, hscroll
, window
);
923 if (pos
.vpos
>= height
)
927 pos
= *vmotion (startp
, point
< startp
? - scroll_step
: scroll_step
,
928 width
, hscroll
, window
);
930 if (point
>= pos
.bufpos
)
932 try_window (window
, pos
.bufpos
);
933 if (cursor_vpos
>= 0)
936 cancel_my_columns (w
);
941 /* Finally, just choose place to start which centers point */
944 pos
= *vmotion (point
, - height
/ 2, width
, hscroll
, window
);
945 try_window (window
, pos
.bufpos
);
947 startp
= marker_position (w
->start
);
948 w
->start_at_line_beg
=
949 (startp
== BEGV
|| FETCH_CHAR (startp
- 1) == '\n') ? Qt
: Qnil
;
952 /* If window not full width, must redo its mode line
953 if the window to its side is being redone */
954 if ((!NILP (w
->update_mode_line
)
955 || (!just_this_one
&& width
< FRAME_WIDTH (f
) - 1))
956 && height
!= XFASTINT (w
->height
))
957 display_mode_line (w
);
960 current_buffer
= old
;
964 /* Do full redisplay on one window, starting at position `pos'. */
967 try_window (window
, pos
)
971 register struct window
*w
= XWINDOW (window
);
972 register int height
= window_internal_height (w
);
973 register int vpos
= XFASTINT (w
->top
);
974 register int last_text_vpos
= vpos
;
975 int tab_offset
= pos_tab_offset (w
, pos
);
976 FRAME_PTR f
= XFRAME (w
->frame
);
977 int width
= XFASTINT (w
->width
) - 1
978 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != FRAME_WIDTH (f
));
981 Fset_marker (w
->start
, make_number (pos
), Qnil
);
983 overlay_arrow_seen
= 0;
984 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
986 while (--height
>= 0)
988 val
= *display_text_line (w
, pos
, vpos
, val
.hpos
, tab_offset
);
990 if (val
.vpos
) tab_offset
= 0;
992 if (pos
!= val
.bufpos
)
994 /* Next line, unless prev line ended in end of buffer with no cr */
995 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
999 /* If last line is continued in middle of character,
1000 include the split character in the text considered on the frame */
1001 if (val
.hpos
< (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1004 /* If bottom just moved off end of frame, change mode line percentage. */
1005 if (XFASTINT (w
->window_end_pos
) == 0
1007 w
->update_mode_line
= Qt
;
1009 /* Say where last char on frame will be, once redisplay is finished. */
1010 XFASTINT (w
->window_end_pos
) = Z
- pos
;
1011 XFASTINT (w
->window_end_vpos
) = last_text_vpos
- XFASTINT (w
->top
);
1012 /* But that is not valid info until redisplay finishes. */
1013 w
->window_end_valid
= Qnil
;
1016 /* Try to redisplay when buffer is modified locally,
1017 computing insert/delete line to preserve text outside
1018 the bounds of the changes.
1019 Return 1 if successful, 0 if if cannot tell what to do,
1020 or -1 to tell caller to find a new window start,
1021 or -2 to tell caller to do normal redisplay with same window start. */
1024 try_window_id (window
)
1028 register struct window
*w
= XWINDOW (window
);
1029 register int height
= window_internal_height (w
);
1030 FRAME_PTR f
= XFRAME (w
->frame
);
1031 int top
= XFASTINT (w
->top
);
1032 int start
= marker_position (w
->start
);
1033 int width
= XFASTINT (w
->width
) - 1
1034 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != FRAME_WIDTH (f
));
1035 int hscroll
= XINT (w
->hscroll
);
1036 int lmargin
= hscroll
> 0 ? 1 - hscroll
: 0;
1038 register int i
, tem
;
1039 int last_text_vpos
= 0;
1042 struct position val
, bp
, ep
, xp
, pp
;
1043 int scroll_amount
= 0;
1045 int tab_offset
, epto
;
1047 if (GPT
- BEG
< beg_unchanged
)
1048 beg_unchanged
= GPT
- BEG
;
1049 if (Z
- GPT
< end_unchanged
)
1050 end_unchanged
= Z
- GPT
;
1052 if (beg_unchanged
+ 1 < start
)
1053 return 0; /* Give up if changes go above top of window */
1055 /* Find position before which nothing is changed. */
1056 bp
= *compute_motion (start
, 0, lmargin
,
1057 beg_unchanged
+ 1, height
+ 1, 0, width
, hscroll
,
1058 pos_tab_offset (w
, start
));
1059 if (bp
.vpos
>= height
)
1061 if (point
< bp
.bufpos
&& !bp
.contin
)
1063 /* All changes are below the frame, and point is on the frame.
1064 We don't need to change the frame at all.
1065 But we need to update window_end_pos to account for
1066 any change in buffer size. */
1067 bp
= *compute_motion (start
, 0, lmargin
,
1069 width
, hscroll
, pos_tab_offset (w
, start
));
1070 XFASTINT (w
->window_end_vpos
) = height
;
1071 XFASTINT (w
->window_end_pos
) = Z
- bp
.bufpos
;
1079 /* Find beginning of that frame line. Must display from there. */
1080 bp
= *vmotion (bp
.bufpos
, 0, width
, hscroll
, window
);
1087 /* If about to start displaying at the beginning of a continuation line,
1088 really start with previous frame line, in case it was not
1089 continued when last redisplayed */
1090 if ((bp
.contin
&& bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0)
1092 /* Likewise if we have to worry about selective display. */
1093 (XTYPE (current_buffer
->selective_display
) == Lisp_Int
1094 && XINT (current_buffer
->selective_display
) > 0
1095 && bp
.bufpos
- 1 == beg_unchanged
&& vpos
> 0))
1097 bp
= *vmotion (bp
.bufpos
, -1, width
, hscroll
, window
);
1102 if (bp
.contin
&& bp
.hpos
!= lmargin
)
1104 val
.hpos
= bp
.prevhpos
- width
+ lmargin
;
1110 /* Find first visible newline after which no more is changed. */
1111 tem
= find_next_newline (Z
- max (end_unchanged
, Z
- ZV
), 1);
1112 if (XTYPE (current_buffer
->selective_display
) == Lisp_Int
1113 && XINT (current_buffer
->selective_display
) > 0)
1115 && (position_indentation (tem
)
1116 >= XINT (current_buffer
->selective_display
)))
1117 tem
= find_next_newline (tem
, 1);
1119 /* Compute the cursor position after that newline. */
1120 ep
= *compute_motion (pos
, vpos
, val
.hpos
, tem
,
1121 height
, - (1 << (SHORTBITS
- 1)),
1122 width
, hscroll
, pos_tab_offset (w
, bp
.bufpos
));
1124 /* If changes reach past the text available on the frame,
1125 just display rest of frame. */
1126 if (ep
.bufpos
> Z
- XFASTINT (w
->window_end_pos
))
1129 stop_vpos
= ep
.vpos
;
1131 /* If no newline before ep, the line ep is on includes some changes
1132 that must be displayed. Make sure we don't stop before it. */
1133 /* Also, if changes reach all the way until ep.bufpos,
1134 it is possible that something was deleted after the
1135 newline before it, so the following line must be redrawn. */
1136 if (stop_vpos
== ep
.vpos
1137 && (ep
.bufpos
== BEGV
1138 || FETCH_CHAR (ep
.bufpos
- 1) != '\n'
1139 || ep
.bufpos
== Z
- end_unchanged
))
1140 stop_vpos
= ep
.vpos
+ 1;
1143 overlay_arrow_seen
= 0;
1145 /* If changes do not reach to bottom of window,
1146 figure out how much to scroll the rest of the window */
1147 if (stop_vpos
< height
)
1149 /* Now determine how far up or down the rest of the window has moved */
1150 epto
= pos_tab_offset (w
, ep
.bufpos
);
1151 xp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1152 Z
- XFASTINT (w
->window_end_pos
),
1153 10000, 0, width
, hscroll
, epto
);
1154 scroll_amount
= xp
.vpos
- XFASTINT (w
->window_end_vpos
);
1156 /* Is everything on frame below the changes whitespace?
1157 If so, no scrolling is really necessary. */
1158 for (i
= ep
.bufpos
; i
< xp
.bufpos
; i
++)
1160 tem
= FETCH_CHAR (i
);
1161 if (tem
!= ' ' && tem
!= '\n' && tem
!= '\t')
1167 XFASTINT (w
->window_end_vpos
) += scroll_amount
;
1169 /* Before doing any scrolling, verify that point will be on frame. */
1170 if (point
> ep
.bufpos
&& !(point
<= xp
.bufpos
&& xp
.bufpos
< height
))
1172 if (point
<= xp
.bufpos
)
1174 pp
= *compute_motion (ep
.bufpos
, ep
.vpos
, ep
.hpos
,
1175 point
, height
, - (1 << (SHORTBITS
- 1)),
1176 width
, hscroll
, epto
);
1180 pp
= *compute_motion (xp
.bufpos
, xp
.vpos
, xp
.hpos
,
1181 point
, height
, - (1 << (SHORTBITS
- 1)),
1182 width
, hscroll
, pos_tab_offset (w
, xp
.bufpos
));
1184 if (pp
.bufpos
< point
|| pp
.vpos
== height
)
1186 cursor_vpos
= pp
.vpos
+ top
;
1187 cursor_hpos
= pp
.hpos
+ XFASTINT (w
->left
);
1190 if (stop_vpos
- scroll_amount
>= height
1191 || ep
.bufpos
== xp
.bufpos
)
1193 if (scroll_amount
< 0)
1194 stop_vpos
-= scroll_amount
;
1196 /* In this path, we have altered window_end_vpos
1197 and not left it negative.
1198 We must make sure that, in case display is preempted
1199 before the frame changes to reflect what we do here,
1200 further updates will not come to try_window_id
1201 and assume the frame and window_end_vpos match. */
1202 blank_end_of_window
= 1;
1204 else if (!scroll_amount
)
1206 else if (bp
.bufpos
== Z
- end_unchanged
)
1208 /* If reprinting everything is nearly as fast as scrolling,
1209 don't bother scrolling. Can happen if lines are short. */
1210 if (scroll_cost (f
, bp
.vpos
+ top
- scroll_amount
,
1211 top
+ height
- max (0, scroll_amount
),
1213 > xp
.bufpos
- bp
.bufpos
- 20)
1214 /* Return "try normal display with same window-start."
1215 Too bad we can't prevent further scroll-thinking. */
1217 /* If pure deletion, scroll up as many lines as possible.
1218 In common case of killing a line, this can save the
1219 following line from being overwritten by scrolling
1220 and therefore having to be redrawn. */
1221 tem
= scroll_frame_lines (f
, bp
.vpos
+ top
- scroll_amount
,
1222 top
+ height
- max (0, scroll_amount
),
1224 if (!tem
) stop_vpos
= height
;
1226 else if (scroll_amount
)
1228 /* If reprinting everything is nearly as fast as scrolling,
1229 don't bother scrolling. Can happen if lines are short. */
1230 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1231 overestimate of cost of reprinting, since xp.bufpos
1232 would end up below the bottom of the window. */
1233 if (scroll_cost (f
, ep
.vpos
+ top
- scroll_amount
,
1234 top
+ height
- max (0, scroll_amount
),
1236 > xp
.bufpos
- ep
.bufpos
- 20)
1237 /* Return "try normal display with same window-start."
1238 Too bad we can't prevent further scroll-thinking. */
1240 tem
= scroll_frame_lines (f
, ep
.vpos
+ top
- scroll_amount
,
1241 top
+ height
- max (0, scroll_amount
),
1243 if (!tem
) stop_vpos
= height
;
1247 /* In any case, do not display past bottom of window */
1248 if (stop_vpos
>= height
)
1254 /* Handle case where pos is before w->start --
1255 can happen if part of line had been clipped and is not clipped now */
1256 if (vpos
== 0 && pos
< marker_position (w
->start
))
1257 Fset_marker (w
->start
, make_number (pos
), Qnil
);
1259 /* Redisplay the lines where the text was changed */
1260 last_text_vpos
= vpos
;
1261 tab_offset
= pos_tab_offset (w
, pos
);
1262 /* If we are starting display in mid-character, correct tab_offset
1263 to account for passing the line that that character really starts in. */
1264 if (val
.hpos
< lmargin
)
1265 tab_offset
+= width
;
1266 while (vpos
< stop_vpos
)
1268 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1269 tab_offset
+= width
;
1270 if (val
.vpos
) tab_offset
= 0;
1271 if (pos
!= val
.bufpos
)
1273 /* Next line, unless prev line ended in end of buffer with no cr */
1274 = vpos
- (val
.vpos
&& FETCH_CHAR (val
.bufpos
- 1) != '\n');
1278 /* There are two cases:
1279 1) we have displayed down to the bottom of the window
1280 2) we have scrolled lines below stop_vpos by scroll_amount */
1284 /* If last line is continued in middle of character,
1285 include the split character in the text considered on the frame */
1286 if (val
.hpos
< lmargin
)
1288 XFASTINT (w
->window_end_vpos
) = last_text_vpos
;
1289 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1292 /* If scrolling made blank lines at window bottom,
1293 redisplay to fill those lines */
1294 if (scroll_amount
< 0)
1296 /* Don't consider these lines for general-purpose scrolling.
1297 That will save time in the scrolling computation. */
1298 FRAME_SCROLL_BOTTOM_VPOS (f
) = xp
.vpos
;
1303 vpos
= height
+ scroll_amount
;
1304 else if (xp
.contin
&& xp
.hpos
!= lmargin
)
1306 val
.hpos
= xp
.prevhpos
- width
+ lmargin
;
1310 blank_end_of_window
= 1;
1311 tab_offset
= pos_tab_offset (w
, pos
);
1312 /* If we are starting display in mid-character, correct tab_offset
1313 to account for passing the line that that character starts in. */
1314 if (val
.hpos
< lmargin
)
1315 tab_offset
+= width
;
1317 while (vpos
< height
)
1319 val
= *display_text_line (w
, pos
, top
+ vpos
++, val
.hpos
, tab_offset
);
1320 tab_offset
+= width
;
1321 if (val
.vpos
) tab_offset
= 0;
1325 /* Here is a case where display_text_line sets cursor_vpos wrong.
1326 Make it be fixed up, below. */
1328 && xp
.bufpos
== point
)
1332 /* If bottom just moved off end of frame, change mode line percentage. */
1333 if (XFASTINT (w
->window_end_pos
) == 0
1335 w
->update_mode_line
= Qt
;
1337 /* Attempt to adjust end-of-text positions to new bottom line */
1340 delta
= height
- xp
.vpos
;
1342 || (delta
> 0 && xp
.bufpos
<= ZV
)
1343 || (delta
== 0 && xp
.hpos
))
1345 val
= *vmotion (Z
- XFASTINT (w
->window_end_pos
),
1346 delta
, width
, hscroll
, window
);
1347 XFASTINT (w
->window_end_pos
) = Z
- val
.bufpos
;
1348 XFASTINT (w
->window_end_vpos
) += val
.vpos
;
1352 w
->window_end_valid
= Qnil
;
1354 /* If point was not in a line that was displayed, find it */
1355 if (cursor_vpos
< 0)
1357 val
= *compute_motion (start
, 0, lmargin
, point
, 10000, 10000,
1358 width
, hscroll
, pos_tab_offset (w
, start
));
1359 /* Admit failure if point is off frame now */
1360 if (val
.vpos
>= height
)
1362 for (vpos
= 0; vpos
< height
; vpos
++)
1363 cancel_line (vpos
+ top
, f
);
1366 cursor_vpos
= val
.vpos
+ top
;
1367 cursor_hpos
= val
.hpos
+ XFASTINT (w
->left
);
1370 FRAME_CURSOR_X (f
) = max (0, cursor_hpos
);
1371 FRAME_CURSOR_Y (f
) = cursor_vpos
;
1375 val
= *compute_motion (start
, 0, lmargin
, ZV
,
1376 height
, - (1 << (SHORTBITS
- 1)),
1377 width
, hscroll
, pos_tab_offset (w
, start
));
1378 if (val
.vpos
!= XFASTINT (w
->window_end_vpos
))
1380 if (XFASTINT (w
->window_end_pos
)
1388 /* Copy glyphs from the rope FROM to T.
1389 But don't actually copy the parts that would come in before S.
1390 Value is T, advanced past the copied data.
1392 Characters in FROM are grouped into units of `sizeof GLYPH' chars;
1393 any extra chars at the end of FROM are ignored. */
1396 copy_rope (t
, s
, from
)
1397 register GLYPH
*t
; /* Copy to here. */
1398 register GLYPH
*s
; /* Starting point. */
1399 Lisp_Object from
; /* Data to copy; known to be a string. */
1401 register int n
= XSTRING (from
)->size
/ sizeof (GLYPH
);
1402 register GLYPH
*f
= (GLYPH
*) XSTRING (from
)->data
;
1406 if (t
>= s
) *t
= *f
;
1413 /* Display one line of window w, starting at position START in W's buffer.
1414 Display starting at horizontal position HPOS, which is normally zero
1415 or negative. A negative value causes output up to hpos = 0 to be discarded.
1416 This is done for negative hscroll, or when this is a continuation line
1417 and the continuation occurred in the middle of a multi-column character.
1419 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
1421 Display on position VPOS on the frame. (origin 0).
1423 Returns a STRUCT POSITION giving character to start next line with
1424 and where to display it, including a zero or negative hpos.
1425 The vpos field is not really a vpos; it is 1 unless the line is continued */
1427 struct position val_display_text_line
;
1429 static struct position
*
1430 display_text_line (w
, start
, vpos
, hpos
, taboffset
)
1437 register int pos
= start
;
1442 register unsigned char *p
;
1444 register GLYPH
*startp
;
1445 register GLYPH
*p1prev
;
1446 FRAME_PTR f
= XFRAME (w
->frame
);
1447 int tab_width
= XINT (current_buffer
->tab_width
);
1448 int ctl_arrow
= !NILP (current_buffer
->ctl_arrow
);
1449 int width
= XFASTINT (w
->width
) - 1
1450 - (XFASTINT (w
->width
) + XFASTINT (w
->left
) != FRAME_WIDTH (f
));
1451 struct position val
;
1454 int hscroll
= XINT (w
->hscroll
);
1455 int truncate
= hscroll
1456 || (truncate_partial_width_windows
1457 && XFASTINT (w
->width
) < FRAME_WIDTH (f
))
1458 || !NILP (current_buffer
->truncate_lines
);
1460 = XTYPE (current_buffer
->selective_display
) == Lisp_Int
1461 ? XINT (current_buffer
->selective_display
)
1462 : !NILP (current_buffer
->selective_display
) ? -1 : 0;
1464 int selective_e
= selective
&& !NILP (current_buffer
->selective_display_ellipses
);
1466 register struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (f
);
1467 register struct Lisp_Vector
*dp
= window_display_table (w
);
1469 = (selective
&& dp
&& XTYPE (DISP_INVIS_ROPE (dp
)) == Lisp_String
1470 ? XSTRING (DISP_INVIS_ROPE (dp
))->size
/ sizeof (GLYPH
) : 0);
1471 GLYPH truncator
= (dp
== 0 || XTYPE (DISP_TRUNC_GLYPH (dp
)) != Lisp_Int
1472 ? '$' : XINT (DISP_TRUNC_GLYPH (dp
)));
1473 GLYPH continuer
= (dp
== 0 || XTYPE (DISP_CONTINUE_GLYPH (dp
)) != Lisp_Int
1474 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp
)));
1476 hpos
+= XFASTINT (w
->left
);
1477 get_display_line (f
, vpos
, XFASTINT (w
->left
));
1478 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
1480 if (MINI_WINDOW_P (w
) && start
== 1
1481 && vpos
== XFASTINT (w
->top
))
1484 hpos
= display_string (w
, vpos
, minibuf_prompt
, hpos
,
1485 (!truncate
? continuer
: truncator
),
1487 minibuf_prompt_width
= hpos
;
1490 desired_glyphs
->bufp
[vpos
] = pos
;
1491 p1
= desired_glyphs
->glyphs
[vpos
] + hpos
;
1493 startp
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
1494 endp
= startp
+ width
;
1496 /* Loop generating characters.
1497 Stop at end of buffer, before newline,
1498 or if reach or pass continuation column. */
1508 if (pos
== point
&& cursor_vpos
< 0)
1511 cursor_hpos
= p1
- startp
;
1515 if (pos
< point
&& point
< pause
)
1517 if (pos
< GPT
&& GPT
< pause
)
1520 p
= &FETCH_CHAR (pos
);
1523 if (c
>= 040 && c
< 0177
1524 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
1535 && position_indentation (pos
+ 1) >= selective
)
1538 pos
= find_next_newline (pos
+ 1, 1);
1539 if (FETCH_CHAR (pos
- 1) == '\n')
1542 if (invis
&& selective_rlen
> 0 && p1
>= startp
)
1544 p1
+= selective_rlen
;
1545 if (p1
- startp
> width
)
1547 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1548 (p1
- p1prev
) * sizeof (GLYPH
));
1556 if (p1
>= startp
&& p1
< endp
)
1560 while ((p1
- startp
+ taboffset
+ hscroll
- (hscroll
> 0))
1563 else if (c
== Ctl ('M') && selective
== -1)
1565 pos
= find_next_newline (pos
, 1);
1566 if (FETCH_CHAR (pos
- 1) == '\n')
1568 if (selective_rlen
> 0)
1570 p1
+= selective_rlen
;
1571 if (p1
- startp
> width
)
1573 bcopy (XSTRING (DISP_INVIS_ROPE (dp
))->data
, p1prev
,
1574 (p1
- p1prev
) * sizeof (GLYPH
));
1578 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
1580 p1
= copy_rope (p1
, startp
, DISP_CHAR_ROPE (dp
, c
));
1582 else if (c
< 0200 && ctl_arrow
)
1585 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
1586 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
1588 if (p1
>= startp
&& p1
< endp
)
1595 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
1596 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
1598 if (p1
>= startp
&& p1
< endp
)
1599 *p1
= (c
>> 6) + '0';
1601 if (p1
>= startp
&& p1
< endp
)
1602 *p1
= (7 & (c
>> 3)) + '0';
1604 if (p1
>= startp
&& p1
< endp
)
1605 *p1
= (7 & c
) + '0';
1611 val
.hpos
= - XINT (w
->hscroll
);
1619 /* Handle continuation in middle of a character */
1620 /* by backing up over it */
1623 /* Start the next line with that same character */
1625 /* but at a negative hpos, to skip the columns output on this line. */
1626 val
.hpos
+= p1prev
- endp
;
1627 /* Keep in this line everything up to the continuation column. */
1631 /* Finish deciding which character to start the next line on,
1632 and what hpos to start it at.
1633 Also set `lastpos' to the last position which counts as "on this line"
1634 for cursor-positioning. */
1638 if (FETCH_CHAR (pos
) == '\n')
1639 /* If stopped due to a newline, start next line after it */
1642 /* Stopped due to right margin of window */
1647 /* Truncating => start next line after next newline,
1648 and point is on this line if it is before the newline,
1649 and skip none of first char of next line */
1650 pos
= find_next_newline (pos
, 1);
1651 val
.hpos
= XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0;
1653 lastpos
= pos
- (FETCH_CHAR (pos
- 1) == '\n');
1664 /* If point is at eol or in invisible text at eol,
1665 record its frame location now. */
1667 if (start
<= point
&& point
<= lastpos
&& cursor_vpos
< 0)
1670 cursor_hpos
= p1
- startp
;
1673 if (cursor_vpos
== vpos
)
1675 if (cursor_hpos
< 0) cursor_hpos
= 0;
1676 if (cursor_hpos
> width
) cursor_hpos
= width
;
1677 cursor_hpos
+= XFASTINT (w
->left
);
1678 if (w
== XWINDOW (FRAME_SELECTED_WINDOW (f
)))
1680 FRAME_CURSOR_Y (f
) = cursor_vpos
;
1681 FRAME_CURSOR_X (f
) = cursor_hpos
;
1683 if (w
== XWINDOW (selected_window
))
1685 /* Line is not continued and did not start
1686 in middle of character */
1687 if ((hpos
- XFASTINT (w
->left
)
1688 == (XINT (w
->hscroll
) ? 1 - XINT (w
->hscroll
) : 0))
1691 this_line_bufpos
= start
;
1692 this_line_buffer
= current_buffer
;
1693 this_line_vpos
= cursor_vpos
;
1694 this_line_start_hpos
= hpos
;
1695 this_line_endpos
= Z
- lastpos
;
1698 this_line_bufpos
= 0;
1703 /* If hscroll and line not empty, insert truncation-at-left marker */
1704 if (hscroll
&& lastpos
!= start
)
1706 *startp
= truncator
;
1711 if (XFASTINT (w
->width
) + XFASTINT (w
->left
) != FRAME_WIDTH (f
))
1714 if (p1
< startp
) p1
= startp
;
1715 while (p1
< endp
) *p1
++ = SPACEGLYPH
;
1718 desired_glyphs
->used
[vpos
] = max (desired_glyphs
->used
[vpos
],
1719 p1
- desired_glyphs
->glyphs
[vpos
]);
1720 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
1722 /* If the start of this line is the overlay arrow-position,
1723 then put the arrow string into the display-line. */
1725 if (XTYPE (Voverlay_arrow_position
) == Lisp_Marker
1726 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
1727 && start
== marker_position (Voverlay_arrow_position
)
1728 && XTYPE (Voverlay_arrow_string
) == Lisp_String
1729 && ! overlay_arrow_seen
)
1731 unsigned char *p
= XSTRING (Voverlay_arrow_string
)->data
;
1733 int len
= XSTRING (Voverlay_arrow_string
)->size
;
1735 if (len
> XFASTINT (w
->width
) - 1)
1736 len
= XFASTINT (w
->width
) - 1;
1737 for (i
= 0; i
< len
; i
++)
1739 if (desired_glyphs
->used
[vpos
] <
1740 (len
+ startp
- desired_glyphs
->glyphs
[vpos
]))
1741 desired_glyphs
->used
[vpos
] = len
+ startp
- desired_glyphs
->glyphs
[vpos
];
1743 overlay_arrow_seen
= 1;
1747 val_display_text_line
= val
;
1748 return &val_display_text_line
;
1751 /* Display the mode line for window w */
1754 display_mode_line (w
)
1757 register int vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
1758 register int left
= XFASTINT (w
->left
);
1759 register int right
= XFASTINT (w
->width
) + left
;
1760 register FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
1762 get_display_line (f
, vpos
, left
);
1763 display_mode_element (w
, vpos
, left
, 0, right
, right
,
1764 current_buffer
->mode_line_format
);
1765 FRAME_DESIRED_GLYPHS (f
)->bufp
[vpos
] = 0;
1767 /* Make the mode line inverse video if the entire line
1768 is made of mode lines.
1769 I.e. if this window is full width,
1770 or if it is the child of a full width window
1771 (which implies that that window is split side-by-side
1772 and the rest of this line is mode lines of the sibling windows). */
1773 if (XFASTINT (w
->width
) == FRAME_WIDTH (f
)
1774 || XFASTINT (XWINDOW (w
->parent
)->width
) == FRAME_WIDTH (f
))
1775 FRAME_DESIRED_GLYPHS (f
)->highlight
[vpos
] = mode_line_inverse_video
;
1777 #ifdef HAVE_X_WINDOWS
1778 /* I'm trying this out because I saw Unimpress use it, but it's
1779 possible that this may mess adversely with some window managers. jla */
1782 && ! FRAME_MINIBUF_ONLY_P (f
)
1783 && w
== XWINDOW (f
->selected_window
)
1784 && XINT (Flength (Vframe_list
)) > 1
1785 && (NILP (Fstring_equal (XBUFFER (w
->buffer
)->name
, f
->name
))))
1786 x_set_name (f
, XBUFFER (w
->buffer
)->name
, Qnil
);
1790 /* Contribute ELT to the mode line for window W.
1791 How it translates into text depends on its data type.
1793 VPOS is the position of the mode line being displayed.
1795 HPOS is the position (absolute on frame) where this element's text
1796 should start. The output is truncated automatically at the right
1799 DEPTH is the depth in recursion. It is used to prevent
1800 infinite recursion here.
1802 MINENDCOL is the hpos before which the element may not end.
1803 The element is padded at the right with spaces if nec
1804 to reach this column.
1806 MAXENDCOL is the hpos past which this element may not extend.
1807 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
1808 (This is necessary to make nested padding and truncation work.)
1810 Returns the hpos of the end of the text generated by ELT.
1811 The next element will receive that value as its HPOS arg,
1812 so as to concatenate the elements. */
1815 display_mode_element (w
, vpos
, hpos
, depth
, minendcol
, maxendcol
, elt
)
1817 register int vpos
, hpos
;
1820 register int maxendcol
;
1821 register Lisp_Object elt
;
1829 #ifdef SWITCH_ENUM_BUG
1830 switch ((int) XTYPE (elt
))
1832 switch (XTYPE (elt
))
1837 /* A string: output it and check for %-constructs within it. */
1838 register unsigned char c
;
1839 register unsigned char *this = XSTRING (elt
)->data
;
1841 while (hpos
< maxendcol
&& *this)
1843 unsigned char *last
= this;
1844 while ((c
= *this++) != '\0' && c
!= '%')
1846 if (this - 1 != last
)
1848 register int lim
= --this - last
+ hpos
;
1849 hpos
= display_string (w
, vpos
, last
, hpos
, 0, hpos
,
1850 min (lim
, maxendcol
));
1854 register int spec_width
= 0;
1856 /* We can't allow -ve args due to the "%-" construct */
1857 /* Argument specifies minwidth but not maxwidth
1858 (maxwidth can be specified by
1859 (<negative-number> . <stuff>) mode-line elements) */
1861 while ((c
= *this++) >= '0' && c
<= '9')
1863 spec_width
= spec_width
* 10 + (c
- '0');
1867 if (spec_width
> maxendcol
)
1868 spec_width
= maxendcol
;
1871 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1872 spec_width
, maxendcol
,
1873 Vglobal_mode_string
);
1875 hpos
= display_string (w
, vpos
,
1876 decode_mode_spec (w
, c
,
1878 hpos
, 0, spec_width
, maxendcol
);
1885 /* A symbol: process the value of the symbol recursively
1886 as if it appeared here directly. Avoid error if symbol void.
1887 Special case: if value of symbol is a string, output the string
1890 register Lisp_Object tem
;
1891 tem
= Fboundp (elt
);
1894 tem
= Fsymbol_value (elt
);
1895 /* If value is a string, output that string literally:
1896 don't check for % within it. */
1897 if (XTYPE (tem
) == Lisp_String
)
1898 hpos
= display_string (w
, vpos
, XSTRING (tem
)->data
,
1899 hpos
, 0, minendcol
, maxendcol
);
1900 /* Give up right away for nil or t. */
1901 else if (!EQ (tem
, elt
))
1902 { elt
= tem
; goto tail_recurse
; }
1909 register Lisp_Object car
, tem
;
1911 /* A cons cell: three distinct cases.
1912 If first element is a string or a cons, process all the elements
1913 and effectively concatenate them.
1914 If first element is a negative number, truncate displaying cdr to
1915 at most that many characters. If positive, pad (with spaces)
1916 to at least that many characters.
1917 If first element is a symbol, process the cadr or caddr recursively
1918 according to whether the symbol's value is non-nil or nil. */
1919 car
= XCONS (elt
)->car
;
1920 if (XTYPE (car
) == Lisp_Symbol
)
1922 tem
= Fboundp (car
);
1923 elt
= XCONS (elt
)->cdr
;
1924 if (XTYPE (elt
) != Lisp_Cons
)
1926 /* elt is now the cdr, and we know it is a cons cell.
1927 Use its car if CAR has a non-nil value. */
1930 tem
= Fsymbol_value (car
);
1932 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
1934 /* Symbol's value is nil (or symbol is unbound)
1935 Get the cddr of the original list
1936 and if possible find the caddr and use that. */
1937 elt
= XCONS (elt
)->cdr
;
1940 else if (XTYPE (elt
) != Lisp_Cons
)
1942 elt
= XCONS (elt
)->car
;
1945 else if (XTYPE (car
) == Lisp_Int
)
1947 register int lim
= XINT (car
);
1948 elt
= XCONS (elt
)->cdr
;
1950 /* Negative int means reduce maximum width.
1951 DO NOT change MINENDCOL here!
1952 (20 -10 . foo) should truncate foo to 10 col
1953 and then pad to 20. */
1954 maxendcol
= min (maxendcol
, hpos
- lim
);
1957 /* Padding specified. Don't let it be more than
1960 if (lim
> maxendcol
)
1962 /* If that's more padding than already wanted, queue it.
1963 But don't reduce padding already specified even if
1964 that is beyond the current truncation point. */
1965 if (lim
> minendcol
)
1970 else if (XTYPE (car
) == Lisp_String
|| XTYPE (car
) == Lisp_Cons
)
1972 register int limit
= 50;
1973 /* LIMIT is to protect against circular lists. */
1974 while (XTYPE (elt
) == Lisp_Cons
&& --limit
> 0
1975 && hpos
< maxendcol
)
1977 hpos
= display_mode_element (w
, vpos
, hpos
, depth
,
1980 elt
= XCONS (elt
)->cdr
;
1988 return (display_string (w
, vpos
, "*invalid*", hpos
, 0,
1989 minendcol
, maxendcol
));
1993 if (minendcol
> hpos
)
1994 hpos
= display_string (w
, vpos
, "", hpos
, 0, minendcol
, -1);
1998 /* Return a string for the output of a mode line %-spec for window W,
1999 generated by character C and width MAXWIDTH. */
2002 decode_mode_spec (w
, c
, maxwidth
)
2005 register int maxwidth
;
2007 Lisp_Object obj
= Qnil
;
2008 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2009 char *decode_mode_spec_buf
= (char *) FRAME_TEMP_GLYPHS (f
)->total_contents
;
2011 if (maxwidth
> FRAME_WIDTH (f
))
2012 maxwidth
= FRAME_WIDTH (f
);
2017 obj
= current_buffer
->name
;
2019 if (maxwidth
>= 3 && XSTRING (obj
)->size
> maxwidth
)
2021 bcopy (XSTRING (obj
)->data
, decode_mode_spec_buf
, maxwidth
- 1);
2022 decode_mode_spec_buf
[maxwidth
- 1] = '\\';
2023 decode_mode_spec_buf
[maxwidth
] = '\0';
2024 return decode_mode_spec_buf
;
2030 obj
= current_buffer
->filename
;
2034 else if (XTYPE (obj
) == Lisp_String
&& XSTRING (obj
)->size
> maxwidth
)
2036 bcopy ("...", decode_mode_spec_buf
, 3);
2037 bcopy (XSTRING (obj
)->data
+ XSTRING (obj
)->size
- maxwidth
+ 3,
2038 decode_mode_spec_buf
+ 3, maxwidth
- 3);
2039 return decode_mode_spec_buf
;
2045 obj
= current_buffer
->mode_name
;
2049 if (BEGV
> BEG
|| ZV
< Z
)
2054 if (!NILP (current_buffer
->read_only
))
2056 if (MODIFF
> current_buffer
->save_modified
)
2061 /* status of process */
2062 obj
= Fget_buffer_process (Fcurrent_buffer ());
2064 return "no process";
2065 obj
= Fsymbol_name (Fprocess_status (obj
));
2070 int pos
= marker_position (w
->start
);
2071 int total
= ZV
- BEGV
;
2073 if (XFASTINT (w
->window_end_pos
) <= Z
- ZV
)
2080 else if (pos
<= BEGV
)
2084 total
= ((pos
- BEGV
) * 100 + total
- 1) / total
;
2085 /* We can't normally display a 3-digit number,
2086 so get us a 2-digit number that is close. */
2089 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
2090 return decode_mode_spec_buf
;
2102 if (command_loop_level
> 5)
2104 p
= decode_mode_spec_buf
;
2105 for (i
= 0; i
< command_loop_level
; i
++)
2108 return decode_mode_spec_buf
;
2116 if (command_loop_level
> 5)
2118 p
= decode_mode_spec_buf
;
2119 for (i
= 0; i
< command_loop_level
; i
++)
2122 return decode_mode_spec_buf
;
2127 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
2131 if (maxwidth
< sizeof (lots_of_dashes
))
2132 return lots_of_dashes
;
2135 for (p
= decode_mode_spec_buf
, i
= maxwidth
; i
> 0; i
--)
2139 return decode_mode_spec_buf
;
2143 if (XTYPE (obj
) == Lisp_String
)
2144 return (char *) XSTRING (obj
)->data
;
2149 /* Display STRING on one line of window W, starting at HPOS.
2150 Display at position VPOS. Caller should have done get_display_line.
2152 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
2154 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
2155 MAXCOL is the last column ok to end at. Truncate here.
2156 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
2157 Both count from the left edge of the frame, as does HPOS.
2158 The right edge of W is an implicit maximum.
2159 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
2161 Returns ending hpos */
2164 display_string (w
, vpos
, string
, hpos
, truncate
, mincol
, maxcol
)
2166 unsigned char *string
;
2173 int hscroll
= XINT (w
->hscroll
);
2174 int tab_width
= XINT (current_buffer
->tab_width
);
2175 register GLYPH
*start
;
2176 register GLYPH
*end
;
2177 struct frame_glyphs
*desired_glyphs
= FRAME_DESIRED_GLYPHS (XFRAME (w
->frame
));
2178 GLYPH
*p1start
= desired_glyphs
->glyphs
[vpos
] + hpos
;
2179 int window_width
= XFASTINT (w
->width
);
2181 /* Use the standard display table, not the window's display table.
2182 We don't want the mode line in rot13. */
2183 register struct Lisp_Vector
*dp
= 0;
2185 if (XTYPE (Vstandard_display_table
) == Lisp_Vector
2186 && XVECTOR (Vstandard_display_table
)->size
== DISP_TABLE_SIZE
)
2187 dp
= XVECTOR (Vstandard_display_table
);
2189 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
2192 start
= desired_glyphs
->glyphs
[vpos
] + XFASTINT (w
->left
);
2193 end
= start
+ window_width
- (truncate
!= 0);
2195 if ((window_width
+ XFASTINT (w
->left
))
2196 != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w
))))
2199 if (maxcol
>= 0 && end
- desired_glyphs
->glyphs
[vpos
] > maxcol
)
2200 end
= desired_glyphs
->glyphs
[vpos
] + maxcol
;
2201 if (maxcol
>= 0 && mincol
> maxcol
)
2208 if (c
>= 040 && c
< 0177
2209 && (dp
== 0 || XTYPE (DISP_CHAR_ROPE (dp
, c
)) != Lisp_String
))
2219 if (p1
>= start
&& p1
< end
)
2223 while ((p1
- start
+ hscroll
- (hscroll
> 0)) % tab_width
);
2225 else if (dp
!= 0 && XTYPE (DISP_CHAR_ROPE (dp
, c
)) == Lisp_String
)
2226 p1
= copy_rope (p1
, start
, DISP_CHAR_ROPE (dp
, c
));
2227 else if (c
< 0200 && buffer_defaults
.ctl_arrow
)
2230 *p1
= (dp
&& XTYPE (DISP_CTRL_GLYPH (dp
)) == Lisp_Int
2231 ? XINT (DISP_CTRL_GLYPH (dp
)) : '^');
2233 if (p1
>= start
&& p1
< end
)
2240 *p1
= (dp
&& XTYPE (DISP_ESCAPE_GLYPH (dp
)) == Lisp_Int
2241 ? XINT (DISP_ESCAPE_GLYPH (dp
)) : '\\');
2243 if (p1
>= start
&& p1
< end
)
2244 *p1
= (c
>> 6) + '0';
2246 if (p1
>= start
&& p1
< end
)
2247 *p1
= (7 & (c
>> 3)) + '0';
2249 if (p1
>= start
&& p1
< end
)
2250 *p1
= (7 & c
) + '0';
2258 if (truncate
) *p1
++ = truncate
;
2260 else if (mincol
>= 0)
2262 end
= desired_glyphs
->glyphs
[vpos
] + mincol
;
2268 register int len
= p1
- desired_glyphs
->glyphs
[vpos
];
2270 if (len
> desired_glyphs
->used
[vpos
])
2271 desired_glyphs
->used
[vpos
] = len
;
2272 desired_glyphs
->glyphs
[vpos
][desired_glyphs
->used
[vpos
]] = 0;
2281 staticpro (&last_arrow_position
);
2282 staticpro (&last_arrow_string
);
2283 last_arrow_position
= Qnil
;
2284 last_arrow_string
= Qnil
;
2286 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
2287 "String (or mode line construct) included (normally) in `mode-line-format'.");
2288 Vglobal_mode_string
= Qnil
;
2290 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
2291 "Marker for where to display an arrow on top of the buffer text.\n\
2292 This must be the beginning of a line in order to work.\n\
2293 See also `overlay-arrow-string'.");
2294 Voverlay_arrow_position
= Qnil
;
2296 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
2297 "String to display as an arrow. See also `overlay-arrow-position'.");
2298 Voverlay_arrow_string
= Qnil
;
2300 DEFVAR_INT ("scroll-step", &scroll_step
,
2301 "*The number of lines to try scrolling a window by when point moves out.\n\
2302 If that fails to bring point back on frame, point is centered instead.\n\
2303 If this is zero, point is always centered after it moves off frame.");
2305 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
2307 DEFVAR_BOOL ("truncate-partial-width-windows",
2308 &truncate_partial_width_windows
,
2309 "*Non-nil means truncate lines in all windows less than full frame wide.");
2310 truncate_partial_width_windows
= 1;
2312 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
2313 "*Non-nil means use inverse video for the mode line.");
2314 mode_line_inverse_video
= 1;
2317 /* initialize the window system */
2320 Lisp_Object root_window
;
2321 #ifndef COMPILER_REGISTER_BUG
2323 #endif /* COMPILER_REGISTER_BUG */
2324 struct window
*mini_w
;
2326 this_line_bufpos
= 0;
2328 mini_w
= XWINDOW (minibuf_window
);
2329 root_window
= mini_w
->prev
;
2331 echo_area_glyphs
= 0;
2332 previous_echo_glyphs
= 0;
2334 if (!noninteractive
)
2336 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
2337 XFASTINT (XWINDOW (root_window
)->top
) = 0;
2338 set_window_height (root_window
, FRAME_HEIGHT (f
) - 1, 0);
2339 XFASTINT (mini_w
->top
) = FRAME_HEIGHT (f
) - 1;
2340 set_window_height (minibuf_window
, 1, 0);
2342 XFASTINT (XWINDOW (root_window
)->width
) = FRAME_WIDTH (f
);
2343 XFASTINT (mini_w
->width
) = FRAME_WIDTH (f
);