*** empty log message ***
[emacs.git] / src / xdisp.c
bloba4e675ac663327e7a5cca41c206817b74c6ce5b7
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)
9 any later version.
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. */
21 #include "config.h"
22 #include <stdio.h>
23 /*#include <ctype.h>*/
24 #undef NULL
25 #include "lisp.h"
26 #include "frame.h"
27 #include "window.h"
28 #include "termchar.h"
29 #include "dispextern.h"
30 #include "buffer.h"
31 #include "indent.h"
32 #include "commands.h"
33 #include "macros.h"
34 #include "disptab.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
60 on previous line */
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. */
96 int scroll_step;
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. */
104 int buffer_shared;
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;
113 int debug_end_pos;
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. */
149 int beg_unchanged;
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. */
154 int end_unchanged;
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 */
163 int clip_changed;
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 */
175 /* VARARGS 1 */
177 void
178 message (m, a1, a2, a3)
179 char *m;
181 if (noninteractive)
183 if (noninteractive_need_newline)
184 putc ('\n', stderr);
185 noninteractive_need_newline = 0;
186 fprintf (stderr, m, a1, a2, a3);
187 fprintf (stderr, "\n");
188 fflush (stderr);
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))
195 #ifdef MULTI_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)));
203 #endif
206 #ifdef NO_ARG_ARRAY
207 int a[3];
208 a[0] = a1;
209 a[1] = a2;
210 a[2] = a3;
212 doprnt (FRAME_MESSAGE_BUF (selected_frame),
213 FRAME_WIDTH (selected_frame), m, 0, 3, a);
214 #else
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
223 buffer next time. */
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. */
234 void
235 message1 (m)
236 char *m;
238 if (noninteractive)
240 if (noninteractive_need_newline)
241 putc ('\n', stderr);
242 noninteractive_need_newline = 0;
243 fprintf (stderr, "%s\n", m);
244 fflush (stderr);
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))
251 #ifdef MULTI_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)));
259 #endif
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 ();
269 static void
270 echo_area_display ()
272 register int vpos;
273 FRAME_PTR f;
275 #ifdef MULTI_FRAME
276 choose_minibuf_frame ();
277 f = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
279 if (! FRAME_VISIBLE_P (f))
280 return;
281 #endif
283 if (frame_garbaged)
285 Fredraw_display ();
286 frame_garbaged = 0;
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. */
303 int i;
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. */
337 void
338 redisplay ()
340 register struct window *w = XWINDOW (selected_window);
341 register int pause;
342 int must_finish = 0;
343 int all_windows;
344 register int tlbufpos, tlendpos;
345 struct position pos;
346 extern int input_pending;
348 if (noninteractive)
349 return;
351 /* Notice any pending interrupt request to change frame size. */
352 do_pending_window_change ();
354 if (frame_garbaged)
356 Fredraw_display ();
357 frame_garbaged = 0;
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
363 again here. */
364 if (echo_area_glyphs || previous_echo_glyphs)
366 echo_area_display ();
367 must_finish = 1;
370 if (clip_changed || windows_or_buffers_changed)
371 update_mode_lines++;
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)
379 update_mode_lines++;
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 */
401 && point >= tlbufpos
402 && point <= Z - tlendpos
403 /* All text outside that line, including its final newline,
404 must be unchanged */
405 && (XFASTINT (w->last_modified) >= MODIFF
406 || (beg_unchanged >= tlbufpos - 1
407 && GPT >= tlbufpos
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
413 && GPT > tlbufpos)
414 : 1))
415 && end_unchanged >= tlendpos
416 && Z - GPT >= tlendpos)))
418 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
419 && (tlbufpos == ZV
420 || FETCH_CHAR (tlbufpos) == '\n'))
421 /* Former continuation line has disappeared by becoming empty */
422 goto cancel;
423 else if (XFASTINT (w->last_modified) < MODIFF
424 || MINI_WINDOW_P (w))
426 cursor_vpos = -1;
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);
437 goto update;
439 else
440 goto cancel;
442 else if (point == XFASTINT (w->last_point))
444 if (!must_finish)
446 do_pending_window_change ();
447 return;
449 goto update;
451 else
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)),
459 XINT (w->hscroll),
460 pos_tab_offset (w, tlbufpos));
461 if (pos.vpos < 1)
463 FRAME_CURSOR_X (selected_frame)
464 = XFASTINT (w->left) + max (pos.hpos, 0);
465 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
466 goto update;
468 else
469 goto cancel;
471 cancel:
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;
479 if (all_windows)
481 #ifdef MULTI_FRAME
482 Lisp_Object tail;
484 /* Recompute # windows showing selected buffer.
485 This will be incremented each time such a window is displayed. */
486 buffer_shared = 0;
488 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
490 FRAME_PTR f;
492 if (XTYPE (XCONS (tail)->car) != Lisp_Frame)
493 continue;
495 f = XFRAME (XCONS (tail)->car);
496 if (f->visible)
497 /* Redraw its windows. */
498 redisplay_windows (FRAME_ROOT_WINDOW (f));
500 #else
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);
511 update:
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. */
515 if (interrupt_input)
516 unrequest_sigio ();
517 stop_polling ();
519 #ifdef MULTI_FRAME
520 if (all_windows)
522 Lisp_Object tail;
524 pause = 0;
526 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
528 FRAME_PTR f;
530 if (XTYPE (XCONS (tail)->car) != Lisp_Frame)
531 continue;
533 f = XFRAME (XCONS (tail)->car);
534 if (f->visible)
536 pause |= update_frame (f, 0, 0);
537 if (!pause)
538 mark_window_display_accurate (f->root_window, 1);
542 else
543 #endif /* MULTI_FRAME */
545 if (FRAME_VISIBLE_P (selected_frame))
546 pause = update_frame (selected_frame, 0, 0);
547 #ifdef MULTI_FRAME
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
552 it here. */
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);
560 #endif
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. */
565 if (pause)
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
576 in that case. */
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 */
584 if (!pause)
586 register struct buffer *b = XBUFFER (w->buffer);
588 blank_end_of_window = 0;
589 clip_changed = 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);
598 if (all_windows)
599 mark_window_display_accurate (XWINDOW (minibuf_window)->prev, 1);
600 else
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. */
619 if (interrupt_input)
620 request_sigio ();
621 start_polling ();
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;
640 redisplay ();
641 echo_area_glyphs = 0;
643 else
644 redisplay ();
647 void
648 mark_window_display_accurate (window, flag)
649 Lisp_Object window;
650 int 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)
660 = !flag ? 0
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);
672 if (flag)
674 last_arrow_position = Voverlay_arrow_position;
675 last_arrow_string = Voverlay_arrow_string;
677 else
679 /* t is unequal to any useful value of Voverlay_arrow_... */
680 last_arrow_position = Qt;
681 last_arrow_string = Qt;
685 int do_id = 1;
687 static void
688 redisplay_windows (window)
689 Lisp_Object window;
691 for (; !NILP (window); window = XWINDOW (window)->next)
692 redisplay_window (window, 0);
695 static void
696 redisplay_window (window, just_this_one)
697 Lisp_Object window;
698 int just_this_one;
700 register struct window *w = XWINDOW (window);
701 FRAME_PTR f = XFRAME (w->frame);
702 int height;
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))));
708 register int startp;
709 register int hscroll = XINT (w->hscroll);
710 struct position pos;
711 int opoint;
712 int tem;
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);
722 return;
724 if (!NILP (w->hchild))
726 redisplay_windows (w->hchild);
727 return;
729 if (NILP (w->buffer))
730 abort ();
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. */
740 return;
742 else
744 /* This is a minibuffer, but it's not the currently active one, so
745 clear it. */
746 int vpos = XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top);
747 int i;
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);
755 return;
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);
765 opoint = point;
767 /* Count number of windows showing the selected buffer. */
769 if (!just_this_one
770 && current_buffer == XBUFFER (XWINDOW (selected_window)->buffer))
771 buffer_shared++;
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));
779 if (point < BEGV)
781 SET_PT (BEGV);
782 Fset_marker (w->pointm, make_number (point), Qnil);
784 else if (point > (ZV - 1))
786 SET_PT (ZV);
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)
793 goto recenter;
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);
807 if (cursor_vpos < 0)
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),
815 ZV, height / 2,
816 - (1 << (SHORTBITS - 1)),
817 width, hscroll, pos_tab_offset (w, startp));
818 SET_PT (pos.bufpos);
819 if (w != XWINDOW (FRAME_SELECTED_WINDOW (f)))
820 Fset_marker (w->pointm, make_number (point), Qnil);
821 else
823 lpoint = point;
824 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
825 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
828 goto done;
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);
866 goto done;
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)
874 && !(startp == BEGV
875 || FETCH_CHAR (startp - 1) == '\n'))
877 goto recenter;
879 else if (just_this_one && !MINI_WINDOW_P (w)
880 && point >= startp
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)))
889 && tem != -2)
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. */
895 if (tem > 0)
896 goto done;
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)
907 goto done;
908 else
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)
919 if (point > startp)
921 pos = *vmotion (Z - XFASTINT (w->window_end_pos),
922 scroll_step, width, hscroll, window);
923 if (pos.vpos >= height)
924 goto scroll_fail;
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)
934 goto done;
935 else
936 cancel_my_columns (w);
938 scroll_fail: ;
941 /* Finally, just choose place to start which centers point */
943 recenter:
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;
951 done:
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);
959 SET_PT (opoint);
960 current_buffer = old;
961 SET_PT (lpoint);
964 /* Do full redisplay on one window, starting at position `pos'. */
966 static void
967 try_window (window, pos)
968 Lisp_Object window;
969 register int 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));
979 struct position val;
981 Fset_marker (w->start, make_number (pos), Qnil);
982 cursor_vpos = -1;
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);
989 tab_offset += width;
990 if (val.vpos) tab_offset = 0;
991 vpos++;
992 if (pos != val.bufpos)
993 last_text_vpos
994 /* Next line, unless prev line ended in end of buffer with no cr */
995 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
996 pos = val.bufpos;
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))
1002 pos++;
1004 /* If bottom just moved off end of frame, change mode line percentage. */
1005 if (XFASTINT (w->window_end_pos) == 0
1006 && Z != pos)
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. */
1023 static int
1024 try_window_id (window)
1025 Lisp_Object window;
1027 int pos;
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;
1037 register int vpos;
1038 register int i, tem;
1039 int last_text_vpos = 0;
1040 int stop_vpos;
1042 struct position val, bp, ep, xp, pp;
1043 int scroll_amount = 0;
1044 int delta;
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,
1068 Z, height, 0,
1069 width, hscroll, pos_tab_offset (w, start));
1070 XFASTINT (w->window_end_vpos) = height;
1071 XFASTINT (w->window_end_pos) = Z - bp.bufpos;
1072 return 1;
1074 return 0;
1077 vpos = bp.vpos;
1079 /* Find beginning of that frame line. Must display from there. */
1080 bp = *vmotion (bp.bufpos, 0, width, hscroll, window);
1082 pos = bp.bufpos;
1083 val.hpos = lmargin;
1084 if (pos < start)
1085 return -1;
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);
1098 --vpos;
1099 pos = bp.bufpos;
1102 if (bp.contin && bp.hpos != lmargin)
1104 val.hpos = bp.prevhpos - width + lmargin;
1105 pos--;
1108 bp.vpos = vpos;
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)
1114 while (tem < ZV - 1
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))
1127 stop_vpos = height;
1128 else
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;
1142 cursor_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')
1162 break;
1164 if (i == xp.bufpos)
1165 return -2;
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);
1178 else
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)
1185 return 0;
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;
1195 scroll_amount = 0;
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),
1212 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. */
1216 return -2;
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),
1223 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),
1235 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. */
1239 return -2;
1240 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
1241 top + height - max (0, scroll_amount),
1242 scroll_amount);
1243 if (!tem) stop_vpos = height;
1247 /* In any case, do not display past bottom of window */
1248 if (stop_vpos >= height)
1250 stop_vpos = height;
1251 scroll_amount = 0;
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)
1272 last_text_vpos
1273 /* Next line, unless prev line ended in end of buffer with no cr */
1274 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
1275 pos = val.bufpos;
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 */
1282 if (vpos == height)
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)
1287 val.bufpos++;
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;
1299 vpos = xp.vpos;
1300 pos = xp.bufpos;
1301 val.hpos = lmargin;
1302 if (pos == ZV)
1303 vpos = height + scroll_amount;
1304 else if (xp.contin && xp.hpos != lmargin)
1306 val.hpos = xp.prevhpos - width + lmargin;
1307 pos--;
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;
1322 pos = val.bufpos;
1325 /* Here is a case where display_text_line sets cursor_vpos wrong.
1326 Make it be fixed up, below. */
1327 if (xp.bufpos == ZV
1328 && xp.bufpos == point)
1329 cursor_vpos = -1;
1332 /* If bottom just moved off end of frame, change mode line percentage. */
1333 if (XFASTINT (w->window_end_pos) == 0
1334 && Z != val.bufpos)
1335 w->update_mode_line = Qt;
1337 /* Attempt to adjust end-of-text positions to new bottom line */
1338 if (scroll_amount)
1340 delta = height - xp.vpos;
1341 if (delta < 0
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);
1364 return 0;
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;
1373 if (debug_end_pos)
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))
1379 abort ();
1380 if (XFASTINT (w->window_end_pos)
1381 != Z - val.bufpos)
1382 abort ();
1385 return 1;
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. */
1395 GLYPH *
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;
1404 while (n--)
1406 if (t >= s) *t = *f;
1407 ++t;
1408 ++f;
1410 return t;
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)
1431 struct window *w;
1432 int start;
1433 int vpos;
1434 int hpos;
1435 int taboffset;
1437 register int pos = start;
1438 register int c;
1439 register GLYPH *p1;
1440 int end;
1441 register int pause;
1442 register unsigned char *p;
1443 GLYPH *endp;
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;
1452 int lastpos;
1453 int invis;
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);
1459 int selective
1460 = XTYPE (current_buffer->selective_display) == Lisp_Int
1461 ? XINT (current_buffer->selective_display)
1462 : !NILP (current_buffer->selective_display) ? -1 : 0;
1463 #ifndef old
1464 int selective_e = selective && !NILP (current_buffer->selective_display_ellipses);
1465 #endif
1466 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
1467 register struct Lisp_Vector *dp = window_display_table (w);
1468 int selective_rlen
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))
1483 if (minibuf_prompt)
1484 hpos = display_string (w, vpos, minibuf_prompt, hpos,
1485 (!truncate ? continuer : truncator),
1486 -1, -1);
1487 minibuf_prompt_width = hpos;
1490 desired_glyphs->bufp[vpos] = pos;
1491 p1 = desired_glyphs->glyphs[vpos] + hpos;
1492 end = ZV;
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. */
1500 pause = pos;
1501 while (p1 < endp)
1503 p1prev = p1;
1504 if (pos == pause)
1506 if (pos == end)
1507 break;
1508 if (pos == point && cursor_vpos < 0)
1510 cursor_vpos = vpos;
1511 cursor_hpos = p1 - startp;
1514 pause = end;
1515 if (pos < point && point < pause)
1516 pause = point;
1517 if (pos < GPT && GPT < pause)
1518 pause = GPT;
1520 p = &FETCH_CHAR (pos);
1522 c = *p++;
1523 if (c >= 040 && c < 0177
1524 && (dp == 0 || XTYPE (DISP_CHAR_ROPE (dp, c)) != Lisp_String))
1526 if (p1 >= startp)
1527 *p1 = c;
1528 p1++;
1530 else if (c == '\n')
1532 invis = 0;
1533 while (pos < end
1534 && selective > 0
1535 && position_indentation (pos + 1) >= selective)
1537 invis = 1;
1538 pos = find_next_newline (pos + 1, 1);
1539 if (FETCH_CHAR (pos - 1) == '\n')
1540 pos--;
1542 if (invis && selective_rlen > 0 && p1 >= startp)
1544 p1 += selective_rlen;
1545 if (p1 - startp > width)
1546 p1 = endp;
1547 bcopy (XSTRING (DISP_INVIS_ROPE (dp))->data, p1prev,
1548 (p1 - p1prev) * sizeof (GLYPH));
1550 break;
1552 else if (c == '\t')
1556 if (p1 >= startp && p1 < endp)
1557 *p1 = SPACEGLYPH;
1558 p1++;
1560 while ((p1 - startp + taboffset + hscroll - (hscroll > 0))
1561 % tab_width);
1563 else if (c == Ctl ('M') && selective == -1)
1565 pos = find_next_newline (pos, 1);
1566 if (FETCH_CHAR (pos - 1) == '\n')
1567 pos--;
1568 if (selective_rlen > 0)
1570 p1 += selective_rlen;
1571 if (p1 - startp > width)
1572 p1 = endp;
1573 bcopy (XSTRING (DISP_INVIS_ROPE (dp))->data, p1prev,
1574 (p1 - p1prev) * sizeof (GLYPH));
1576 break;
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)
1584 if (p1 >= startp)
1585 *p1 = (dp && XTYPE (DISP_CTRL_GLYPH (dp)) == Lisp_Int
1586 ? XINT (DISP_CTRL_GLYPH (dp)) : '^');
1587 p1++;
1588 if (p1 >= startp && p1 < endp)
1589 *p1 = c ^ 0100;
1590 p1++;
1592 else
1594 if (p1 >= startp)
1595 *p1 = (dp && XTYPE (DISP_ESCAPE_GLYPH (dp)) == Lisp_Int
1596 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\');
1597 p1++;
1598 if (p1 >= startp && p1 < endp)
1599 *p1 = (c >> 6) + '0';
1600 p1++;
1601 if (p1 >= startp && p1 < endp)
1602 *p1 = (7 & (c >> 3)) + '0';
1603 p1++;
1604 if (p1 >= startp && p1 < endp)
1605 *p1 = (7 & c) + '0';
1606 p1++;
1608 pos++;
1611 val.hpos = - XINT (w->hscroll);
1612 if (val.hpos)
1613 val.hpos++;
1615 val.vpos = 1;
1617 lastpos = pos;
1619 /* Handle continuation in middle of a character */
1620 /* by backing up over it */
1621 if (p1 > endp)
1623 /* Start the next line with that same character */
1624 pos--;
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. */
1628 p1 = endp;
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. */
1636 if (pos < ZV)
1638 if (FETCH_CHAR (pos) == '\n')
1639 /* If stopped due to a newline, start next line after it */
1640 pos++;
1641 else
1642 /* Stopped due to right margin of window */
1644 if (truncate)
1646 *p1++ = truncator;
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');
1655 else
1657 *p1++ = continuer;
1658 val.vpos = 0;
1659 lastpos--;
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)
1669 cursor_vpos = vpos;
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))
1689 && val.vpos)
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;
1697 else
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;
1707 if (p1 <= startp)
1708 p1 = startp + 1;
1711 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
1713 endp++;
1714 if (p1 < startp) p1 = startp;
1715 while (p1 < endp) *p1++ = SPACEGLYPH;
1716 *p1++ = '|';
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;
1732 int i;
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++)
1738 startp[i] = p[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;
1746 val.bufpos = pos;
1747 val_display_text_line = val;
1748 return &val_display_text_line;
1751 /* Display the mode line for window w */
1753 static void
1754 display_mode_line (w)
1755 struct window *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 */
1781 if (FRAME_IS_X (f)
1782 && ! FRAME_MINIBUF_ONLY_P (f)
1783 && w == XWINDOW (f->selected_window))
1784 x_set_name (f, ((XINT (Flength (Vframe_list)) > 1)
1785 ? XBUFFER (w->buffer)->name
1786 : Qnil),
1787 Qnil);
1788 #endif
1791 /* Contribute ELT to the mode line for window W.
1792 How it translates into text depends on its data type.
1794 VPOS is the position of the mode line being displayed.
1796 HPOS is the position (absolute on frame) where this element's text
1797 should start. The output is truncated automatically at the right
1798 edge of window W.
1800 DEPTH is the depth in recursion. It is used to prevent
1801 infinite recursion here.
1803 MINENDCOL is the hpos before which the element may not end.
1804 The element is padded at the right with spaces if nec
1805 to reach this column.
1807 MAXENDCOL is the hpos past which this element may not extend.
1808 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
1809 (This is necessary to make nested padding and truncation work.)
1811 Returns the hpos of the end of the text generated by ELT.
1812 The next element will receive that value as its HPOS arg,
1813 so as to concatenate the elements. */
1815 static int
1816 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
1817 struct window *w;
1818 register int vpos, hpos;
1819 int depth;
1820 int minendcol;
1821 register int maxendcol;
1822 register Lisp_Object elt;
1824 tail_recurse:
1825 if (depth > 10)
1826 goto invalid;
1828 depth++;
1830 #ifdef SWITCH_ENUM_BUG
1831 switch ((int) XTYPE (elt))
1832 #else
1833 switch (XTYPE (elt))
1834 #endif
1836 case Lisp_String:
1838 /* A string: output it and check for %-constructs within it. */
1839 register unsigned char c;
1840 register unsigned char *this = XSTRING (elt)->data;
1842 while (hpos < maxendcol && *this)
1844 unsigned char *last = this;
1845 while ((c = *this++) != '\0' && c != '%')
1847 if (this - 1 != last)
1849 register int lim = --this - last + hpos;
1850 hpos = display_string (w, vpos, last, hpos, 0, hpos,
1851 min (lim, maxendcol));
1853 else /* c == '%' */
1855 register int spec_width = 0;
1857 /* We can't allow -ve args due to the "%-" construct */
1858 /* Argument specifies minwidth but not maxwidth
1859 (maxwidth can be specified by
1860 (<negative-number> . <stuff>) mode-line elements) */
1862 while ((c = *this++) >= '0' && c <= '9')
1864 spec_width = spec_width * 10 + (c - '0');
1867 spec_width += hpos;
1868 if (spec_width > maxendcol)
1869 spec_width = maxendcol;
1871 if (c == 'M')
1872 hpos = display_mode_element (w, vpos, hpos, depth,
1873 spec_width, maxendcol,
1874 Vglobal_mode_string);
1875 else if (c != 0)
1876 hpos = display_string (w, vpos,
1877 decode_mode_spec (w, c,
1878 maxendcol - hpos),
1879 hpos, 0, spec_width, maxendcol);
1883 break;
1885 case Lisp_Symbol:
1886 /* A symbol: process the value of the symbol recursively
1887 as if it appeared here directly. Avoid error if symbol void.
1888 Special case: if value of symbol is a string, output the string
1889 literally. */
1891 register Lisp_Object tem;
1892 tem = Fboundp (elt);
1893 if (!NILP (tem))
1895 tem = Fsymbol_value (elt);
1896 /* If value is a string, output that string literally:
1897 don't check for % within it. */
1898 if (XTYPE (tem) == Lisp_String)
1899 hpos = display_string (w, vpos, XSTRING (tem)->data,
1900 hpos, 0, minendcol, maxendcol);
1901 /* Give up right away for nil or t. */
1902 else if (!EQ (tem, elt))
1903 { elt = tem; goto tail_recurse; }
1906 break;
1908 case Lisp_Cons:
1910 register Lisp_Object car, tem;
1912 /* A cons cell: three distinct cases.
1913 If first element is a string or a cons, process all the elements
1914 and effectively concatenate them.
1915 If first element is a negative number, truncate displaying cdr to
1916 at most that many characters. If positive, pad (with spaces)
1917 to at least that many characters.
1918 If first element is a symbol, process the cadr or caddr recursively
1919 according to whether the symbol's value is non-nil or nil. */
1920 car = XCONS (elt)->car;
1921 if (XTYPE (car) == Lisp_Symbol)
1923 tem = Fboundp (car);
1924 elt = XCONS (elt)->cdr;
1925 if (XTYPE (elt) != Lisp_Cons)
1926 goto invalid;
1927 /* elt is now the cdr, and we know it is a cons cell.
1928 Use its car if CAR has a non-nil value. */
1929 if (!NILP (tem))
1931 tem = Fsymbol_value (car);
1932 if (!NILP (tem))
1933 { elt = XCONS (elt)->car; goto tail_recurse; }
1935 /* Symbol's value is nil (or symbol is unbound)
1936 Get the cddr of the original list
1937 and if possible find the caddr and use that. */
1938 elt = XCONS (elt)->cdr;
1939 if (NILP (elt))
1940 break;
1941 else if (XTYPE (elt) != Lisp_Cons)
1942 goto invalid;
1943 elt = XCONS (elt)->car;
1944 goto tail_recurse;
1946 else if (XTYPE (car) == Lisp_Int)
1948 register int lim = XINT (car);
1949 elt = XCONS (elt)->cdr;
1950 if (lim < 0)
1951 /* Negative int means reduce maximum width.
1952 DO NOT change MINENDCOL here!
1953 (20 -10 . foo) should truncate foo to 10 col
1954 and then pad to 20. */
1955 maxendcol = min (maxendcol, hpos - lim);
1956 else if (lim > 0)
1958 /* Padding specified. Don't let it be more than
1959 current maximum. */
1960 lim += hpos;
1961 if (lim > maxendcol)
1962 lim = maxendcol;
1963 /* If that's more padding than already wanted, queue it.
1964 But don't reduce padding already specified even if
1965 that is beyond the current truncation point. */
1966 if (lim > minendcol)
1967 minendcol = lim;
1969 goto tail_recurse;
1971 else if (XTYPE (car) == Lisp_String || XTYPE (car) == Lisp_Cons)
1973 register int limit = 50;
1974 /* LIMIT is to protect against circular lists. */
1975 while (XTYPE (elt) == Lisp_Cons && --limit > 0
1976 && hpos < maxendcol)
1978 hpos = display_mode_element (w, vpos, hpos, depth,
1979 hpos, maxendcol,
1980 XCONS (elt)->car);
1981 elt = XCONS (elt)->cdr;
1985 break;
1987 default:
1988 invalid:
1989 return (display_string (w, vpos, "*invalid*", hpos, 0,
1990 minendcol, maxendcol));
1993 end:
1994 if (minendcol > hpos)
1995 hpos = display_string (w, vpos, "", hpos, 0, minendcol, -1);
1996 return hpos;
1999 /* Return a string for the output of a mode line %-spec for window W,
2000 generated by character C and width MAXWIDTH. */
2002 static char *
2003 decode_mode_spec (w, c, maxwidth)
2004 struct window *w;
2005 register char c;
2006 register int maxwidth;
2008 Lisp_Object obj = Qnil;
2009 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2010 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
2012 if (maxwidth > FRAME_WIDTH (f))
2013 maxwidth = FRAME_WIDTH (f);
2015 switch (c)
2017 case 'b':
2018 obj = current_buffer->name;
2019 #if 0
2020 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
2022 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
2023 decode_mode_spec_buf[maxwidth - 1] = '\\';
2024 decode_mode_spec_buf[maxwidth] = '\0';
2025 return decode_mode_spec_buf;
2027 #endif
2028 break;
2030 case 'f':
2031 obj = current_buffer->filename;
2032 #if 0
2033 if (NILP (obj))
2034 return "[none]";
2035 else if (XTYPE (obj) == Lisp_String && XSTRING (obj)->size > maxwidth)
2037 bcopy ("...", decode_mode_spec_buf, 3);
2038 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
2039 decode_mode_spec_buf + 3, maxwidth - 3);
2040 return decode_mode_spec_buf;
2042 #endif
2043 break;
2045 case 'm':
2046 obj = current_buffer->mode_name;
2047 break;
2049 case 'n':
2050 if (BEGV > BEG || ZV < Z)
2051 return " Narrow";
2052 break;
2054 case '*':
2055 if (!NILP (current_buffer->read_only))
2056 return "%";
2057 if (MODIFF > current_buffer->save_modified)
2058 return "*";
2059 return "-";
2061 case 's':
2062 /* status of process */
2063 obj = Fget_buffer_process (Fcurrent_buffer ());
2064 if (NILP (obj))
2065 return "no process";
2066 obj = Fsymbol_name (Fprocess_status (obj));
2067 break;
2069 case 'p':
2071 int pos = marker_position (w->start);
2072 int total = ZV - BEGV;
2074 if (XFASTINT (w->window_end_pos) <= Z - ZV)
2076 if (pos <= BEGV)
2077 return "All";
2078 else
2079 return "Bottom";
2081 else if (pos <= BEGV)
2082 return "Top";
2083 else
2085 total = ((pos - BEGV) * 100 + total - 1) / total;
2086 /* We can't normally display a 3-digit number,
2087 so get us a 2-digit number that is close. */
2088 if (total == 100)
2089 total = 99;
2090 sprintf (decode_mode_spec_buf, "%2d%%", total);
2091 return decode_mode_spec_buf;
2095 case '%':
2096 return "%";
2098 case '[':
2100 int i;
2101 char *p;
2103 if (command_loop_level > 5)
2104 return "[[[... ";
2105 p = decode_mode_spec_buf;
2106 for (i = 0; i < command_loop_level; i++)
2107 *p++ = '[';
2108 *p = 0;
2109 return decode_mode_spec_buf;
2112 case ']':
2114 int i;
2115 char *p;
2117 if (command_loop_level > 5)
2118 return " ...]]]";
2119 p = decode_mode_spec_buf;
2120 for (i = 0; i < command_loop_level; i++)
2121 *p++ = ']';
2122 *p = 0;
2123 return decode_mode_spec_buf;
2126 case '-':
2128 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
2129 register char *p;
2130 register int i;
2132 if (maxwidth < sizeof (lots_of_dashes))
2133 return lots_of_dashes;
2134 else
2136 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
2137 *p++ = '-';
2138 *p = '\0';
2140 return decode_mode_spec_buf;
2144 if (XTYPE (obj) == Lisp_String)
2145 return (char *) XSTRING (obj)->data;
2146 else
2147 return "";
2150 /* Display STRING on one line of window W, starting at HPOS.
2151 Display at position VPOS. Caller should have done get_display_line.
2153 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
2155 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
2156 MAXCOL is the last column ok to end at. Truncate here.
2157 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
2158 Both count from the left edge of the frame, as does HPOS.
2159 The right edge of W is an implicit maximum.
2160 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
2162 Returns ending hpos */
2164 static int
2165 display_string (w, vpos, string, hpos, truncate, mincol, maxcol)
2166 struct window *w;
2167 unsigned char *string;
2168 int vpos, hpos;
2169 GLYPH truncate;
2170 int mincol, maxcol;
2172 register int c;
2173 register GLYPH *p1;
2174 int hscroll = XINT (w->hscroll);
2175 int tab_width = XINT (current_buffer->tab_width);
2176 register GLYPH *start;
2177 register GLYPH *end;
2178 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (XFRAME (w->frame));
2179 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
2180 int window_width = XFASTINT (w->width);
2182 /* Use the standard display table, not the window's display table.
2183 We don't want the mode line in rot13. */
2184 register struct Lisp_Vector *dp = 0;
2186 if (XTYPE (Vstandard_display_table) == Lisp_Vector
2187 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
2188 dp = XVECTOR (Vstandard_display_table);
2190 if (tab_width <= 0 || tab_width > 20) tab_width = 8;
2192 p1 = p1start;
2193 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2194 end = start + window_width - (truncate != 0);
2196 if ((window_width + XFASTINT (w->left))
2197 != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w))))
2198 *end-- = '|';
2200 if (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol)
2201 end = desired_glyphs->glyphs[vpos] + maxcol;
2202 if (maxcol >= 0 && mincol > maxcol)
2203 mincol = maxcol;
2205 while (p1 < end)
2207 c = *string++;
2208 if (!c) break;
2209 if (c >= 040 && c < 0177
2210 && (dp == 0 || XTYPE (DISP_CHAR_ROPE (dp, c)) != Lisp_String))
2212 if (p1 >= start)
2213 *p1 = c;
2214 p1++;
2216 else if (c == '\t')
2220 if (p1 >= start && p1 < end)
2221 *p1 = SPACEGLYPH;
2222 p1++;
2224 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
2226 else if (dp != 0 && XTYPE (DISP_CHAR_ROPE (dp, c)) == Lisp_String)
2227 p1 = copy_rope (p1, start, DISP_CHAR_ROPE (dp, c));
2228 else if (c < 0200 && buffer_defaults.ctl_arrow)
2230 if (p1 >= start)
2231 *p1 = (dp && XTYPE (DISP_CTRL_GLYPH (dp)) == Lisp_Int
2232 ? XINT (DISP_CTRL_GLYPH (dp)) : '^');
2233 p1++;
2234 if (p1 >= start && p1 < end)
2235 *p1 = c ^ 0100;
2236 p1++;
2238 else
2240 if (p1 >= start)
2241 *p1 = (dp && XTYPE (DISP_ESCAPE_GLYPH (dp)) == Lisp_Int
2242 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\');
2243 p1++;
2244 if (p1 >= start && p1 < end)
2245 *p1 = (c >> 6) + '0';
2246 p1++;
2247 if (p1 >= start && p1 < end)
2248 *p1 = (7 & (c >> 3)) + '0';
2249 p1++;
2250 if (p1 >= start && p1 < end)
2251 *p1 = (7 & c) + '0';
2252 p1++;
2256 if (c)
2258 p1 = end;
2259 if (truncate) *p1++ = truncate;
2261 else if (mincol >= 0)
2263 end = desired_glyphs->glyphs[vpos] + mincol;
2264 while (p1 < end)
2265 *p1++ = SPACEGLYPH;
2269 register int len = p1 - desired_glyphs->glyphs[vpos];
2271 if (len > desired_glyphs->used[vpos])
2272 desired_glyphs->used[vpos] = len;
2273 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
2275 return len;
2279 void
2280 syms_of_xdisp ()
2282 staticpro (&last_arrow_position);
2283 staticpro (&last_arrow_string);
2284 last_arrow_position = Qnil;
2285 last_arrow_string = Qnil;
2287 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
2288 "String (or mode line construct) included (normally) in `mode-line-format'.");
2289 Vglobal_mode_string = Qnil;
2291 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
2292 "Marker for where to display an arrow on top of the buffer text.\n\
2293 This must be the beginning of a line in order to work.\n\
2294 See also `overlay-arrow-string'.");
2295 Voverlay_arrow_position = Qnil;
2297 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
2298 "String to display as an arrow. See also `overlay-arrow-position'.");
2299 Voverlay_arrow_string = Qnil;
2301 DEFVAR_INT ("scroll-step", &scroll_step,
2302 "*The number of lines to try scrolling a window by when point moves out.\n\
2303 If that fails to bring point back on frame, point is centered instead.\n\
2304 If this is zero, point is always centered after it moves off frame.");
2306 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
2308 DEFVAR_BOOL ("truncate-partial-width-windows",
2309 &truncate_partial_width_windows,
2310 "*Non-nil means truncate lines in all windows less than full frame wide.");
2311 truncate_partial_width_windows = 1;
2313 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
2314 "*Non-nil means use inverse video for the mode line.");
2315 mode_line_inverse_video = 1;
2318 /* initialize the window system */
2319 init_xdisp ()
2321 Lisp_Object root_window;
2322 #ifndef COMPILER_REGISTER_BUG
2323 register
2324 #endif /* COMPILER_REGISTER_BUG */
2325 struct window *mini_w;
2327 this_line_bufpos = 0;
2329 mini_w = XWINDOW (minibuf_window);
2330 root_window = mini_w->prev;
2332 echo_area_glyphs = 0;
2333 previous_echo_glyphs = 0;
2335 if (!noninteractive)
2337 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
2338 XFASTINT (XWINDOW (root_window)->top) = 0;
2339 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
2340 XFASTINT (mini_w->top) = FRAME_HEIGHT (f) - 1;
2341 set_window_height (minibuf_window, 1, 0);
2343 XFASTINT (XWINDOW (root_window)->width) = FRAME_WIDTH (f);
2344 XFASTINT (mini_w->width) = FRAME_WIDTH (f);