*** empty log message ***
[bpt/emacs.git] / src / xdisp.c
1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
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.
10
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.
15
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. */
19
20
21 #include "config.h"
22 #include <stdio.h>
23 /*#include <ctype.h>*/
24 #undef NULL
25 #include "lisp.h"
26 #include "screen.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"
35
36 extern int interrupt_input;
37 extern int command_loop_level;
38
39 /* Nonzero means print newline before next minibuffer message. */
40
41 int noninteractive_need_newline;
42
43 #define min(a, b) ((a) < (b) ? (a) : (b))
44 #define max(a, b) ((a) > (b) ? (a) : (b))
45
46 /* The buffer position of the first character appearing
47 entirely or partially on the current screen line.
48 Or zero, which disables the optimization for the current screen line. */
49 static int this_line_bufpos;
50
51 /* Number of characters past the end of this line,
52 including the terminating newline */
53 static int this_line_endpos;
54
55 /* The vertical position of this screen line. */
56 static int this_line_vpos;
57
58 /* Hpos value for start of display on this screen line.
59 Usually zero, but negative if first character really began
60 on previous line */
61 static int this_line_start_hpos;
62
63 /* Buffer that this_line variables are describing. */
64 static struct buffer *this_line_buffer;
65
66 /* Set by try_window_id to the vpos of first of any lines
67 scrolled on to the bottom of the screen. These lines should
68 not be included in any general scroll computation. */
69 static int scroll_bottom_vpos;
70
71 /* Value of echo_area_glyphs when it was last acted on.
72 If this is nonzero, there is a message on the screen
73 in the minibuffer and it should be erased as soon
74 as it is no longer requested to appear. */
75 char *previous_echo_glyphs;
76
77 /* Nonzero means truncate lines in all windows less wide than the screen */
78 int truncate_partial_width_windows;
79
80 Lisp_Object Vglobal_mode_string;
81
82 /* Marker for where to display an arrow on top of the buffer text. */
83 Lisp_Object Voverlay_arrow_position;
84
85 /* String to display for the arrow. */
86 Lisp_Object Voverlay_arrow_string;
87
88 /* Values of those variables at last redisplay. */
89 Lisp_Object last_arrow_position, last_arrow_string;
90
91 /* Nonzero if overlay arrow has been displayed once in this window. */
92 static int overlay_arrow_seen;
93
94 /* If cursor motion alone moves point off screen,
95 Try scrolling this many lines up or down if that will bring it back. */
96 int scroll_step;
97
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;
101
102 /* Number of windows showing the buffer of the selected window.
103 keyboard.c refers to this. */
104 int buffer_shared;
105
106 /* display_text_line sets these to the screen position (origin 0) of point,
107 whether the window is selected or not.
108 Set one to -1 first to determine whether point was found afterwards. */
109
110 static int cursor_vpos;
111 static int cursor_hpos;
112
113 int debug_end_pos;
114
115 /* Nonzero means display mode line highlighted */
116 int mode_line_inverse_video;
117
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 ();
130
131 /* Prompt to display in front of the minibuffer contents */
132 char *minibuf_prompt;
133
134 /* Width in columns of current minibuffer prompt. */
135 int minibuf_prompt_width;
136
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;
142
143 /* true iff we should redraw the mode lines on the next redisplay */
144 int update_mode_lines;
145
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;
150
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;
155
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;
160
161 /* Nonzero if head_clip or tail_clip of current buffer has changed
162 since last redisplay that finished */
163 int clip_changed;
164
165 /* Nonzero if window sizes or contents have changed
166 since last redisplay that finished */
167 int windows_or_buffers_changed;
168
169 \f
170 #ifndef MULTI_SCREEN
171
172 DEFUN ("redraw-display", Fredraw_display, Sredraw_display, 0, 0, "",
173 "Clear the screen and output again what is supposed to appear on it.")
174 ()
175 {
176 if (screen_height == 0) abort (); /* Some bug zeros some core */
177 clear_screen ();
178 fflush (stdout);
179 clear_screen_records ();
180 if (screen_height == 0) abort (); /* Some bug zeros some core */
181 windows_or_buffers_changed++;
182 /* Mark all windows as INaccurate,
183 so that every window will have its redisplay done. */
184 mark_window_display_accurate (XWINDOW (minibuf_window)->prev, 0);
185 if (screen_height == 0) abort (); /* Some bug zeros some core */
186 return Qnil;
187 }
188
189 #endif /* not MULTI_SCREEN */
190 \f
191 /* Buffer used for messages formatted by `message'. */
192 char *message_buf;
193
194 /* Nonzero if message_buf is being used by print;
195 zero if being used by message. */
196 int message_buf_print;
197
198 /* dump an informative message to the minibuf */
199 /* VARARGS 1 */
200
201 void
202 message (m, a1, a2, a3)
203 char *m;
204 {
205 if (noninteractive)
206 {
207 if (noninteractive_need_newline)
208 putc ('\n', stderr);
209 noninteractive_need_newline = 0;
210 fprintf (stderr, m, a1, a2, a3);
211 fprintf (stderr, "\n");
212 fflush (stderr);
213 }
214 /* A null message buffer means that the screen hasn't really been
215 initialized yet. Error messages get reported properly by
216 cmd_error, so this must be just an informative message; toss it. */
217 else if (INTERACTIVE && SCREEN_MESSAGE_BUF (selected_screen))
218 {
219 #ifdef MULTI_SCREEN
220 choose_minibuf_screen ();
221 Fmake_screen_visible (WINDOW_SCREEN (XWINDOW (minibuf_window)));
222 #endif
223
224 {
225 #ifdef NO_ARG_ARRAY
226 int a[3];
227 a[0] = a1;
228 a[1] = a2;
229 a[2] = a3;
230
231 doprnt (SCREEN_MESSAGE_BUF (selected_screen),
232 SCREEN_WIDTH (selected_screen), m, 0, 3, a);
233 #else
234 doprnt (SCREEN_MESSAGE_BUF (selected_screen),
235 SCREEN_WIDTH (selected_screen), m, 0, 3, &a1);
236 #endif /* NO_ARG_ARRAY */
237 }
238
239 echo_area_glyphs = SCREEN_MESSAGE_BUF (selected_screen);
240
241 /* Print should start at the beginning of the message
242 buffer next time. */
243 message_buf_print = 0;
244
245 do_pending_window_change ();
246 echo_area_display ();
247 update_screen (XSCREEN (XWINDOW (minibuf_window)->screen), 1, 1);
248 do_pending_window_change ();
249 }
250 }
251
252 /* Specify m, a string, as a message in the minibuf. */
253 void
254 message1 (m)
255 char *m;
256 {
257 if (noninteractive)
258 {
259 if (noninteractive_need_newline)
260 putc ('\n', stderr);
261 noninteractive_need_newline = 0;
262 fprintf (stderr, "%s\n", m);
263 fflush (stderr);
264 }
265 /* A null message buffer means that the screen hasn't really been
266 initialized yet. Error messages get reported properly by
267 cmd_error, so this must be just an informative message; toss it. */
268 else if (INTERACTIVE && SCREEN_MESSAGE_BUF (selected_screen))
269 {
270 #ifdef MULTI_SCREEN
271 choose_minibuf_screen ();
272 Fmake_screen_visible (WINDOW_SCREEN (XWINDOW (minibuf_window)));
273 #endif
274
275 echo_area_glyphs = m;
276 do_pending_window_change ();
277 echo_area_display ();
278 update_screen (XSCREEN (XWINDOW (minibuf_window)->screen), 1, 1);
279 do_pending_window_change ();
280 }
281 }
282
283 static void
284 echo_area_display ()
285 {
286 register int vpos;
287 SCREEN_PTR s;
288
289 #ifdef MULTI_SCREEN
290 choose_minibuf_screen ();
291 s = XSCREEN (WINDOW_SCREEN (XWINDOW (minibuf_window)));
292
293 if (! SCREEN_VISIBLE_P (s))
294 return;
295 #endif
296
297 if (screen_garbaged)
298 {
299 Fredraw_display ();
300 screen_garbaged = 0;
301 }
302
303 if (echo_area_glyphs || minibuf_level == 0)
304 {
305 vpos = XFASTINT (XWINDOW (minibuf_window)->top);
306 get_display_line (s, vpos, 0);
307 display_string (XWINDOW (minibuf_window), vpos,
308 echo_area_glyphs ? echo_area_glyphs : "",
309 0, 0, 0, SCREEN_WIDTH (s));
310
311 /* If desired cursor location is on this line, put it at end of text */
312 if (SCREEN_CURSOR_Y (s) == vpos)
313 SCREEN_CURSOR_X (s) = s->desired_glyphs->used[vpos];
314 }
315 else if (!EQ (minibuf_window, selected_window))
316 windows_or_buffers_changed++;
317
318 if (EQ (minibuf_window, selected_window))
319 this_line_bufpos = 0;
320
321 previous_echo_glyphs = echo_area_glyphs;
322 }
323 \f
324 /* Do a screen update, taking possible shortcuts into account.
325 This is the main external entry point for redisplay.
326
327 If the last redisplay displayed an echo area message and that
328 message is no longer requested, we clear the echo area
329 or bring back the minibuffer if that is in use.
330
331 Everyone would like to have a hook here to call eval,
332 but that cannot be done safely without a lot of changes elsewhere.
333 This can be called from signal handlers; with alarms set up;
334 or with synchronous processes running.
335 See the function `echo' in keyboard.c.
336 See Fcall_process; if you called it from here, it could be
337 entered recursively. */
338
339 void
340 redisplay ()
341 {
342 register struct window *w = XWINDOW (selected_window);
343 register int pause;
344 int must_finish = 0;
345 int all_windows;
346 register int tlbufpos, tlendpos;
347 struct position pos;
348 extern int input_pending;
349
350 if (noninteractive)
351 return;
352
353 /* Notice any pending interrupt request to change screen size. */
354 do_pending_window_change ();
355
356 if (screen_garbaged)
357 {
358 Fredraw_display ();
359 screen_garbaged = 0;
360 }
361
362 /* Normally the message* functions will have already displayed and
363 updated the echo area, but the screen may have been trashed, or
364 the update may have been preempted, so display the echo area
365 again here. */
366 if (echo_area_glyphs || previous_echo_glyphs)
367 {
368 echo_area_display ();
369 must_finish = 1;
370 }
371
372 if (clip_changed || windows_or_buffers_changed)
373 update_mode_lines++;
374
375 /* Detect case that we need to write a star in the mode line. */
376 if (XFASTINT (w->last_modified) < MODIFF
377 && XFASTINT (w->last_modified) <= current_buffer->save_modified)
378 {
379 w->update_mode_line = Qt;
380 if (buffer_shared > 1)
381 update_mode_lines++;
382 }
383
384 SCREEN_SCROLL_BOTTOM_VPOS (XSCREEN (w->screen)) = -1;
385
386 all_windows = update_mode_lines || buffer_shared > 1;
387
388 /* If specs for an arrow have changed, do thorough redisplay
389 to ensure we remove any arrow that should no longer exist. */
390 if (Voverlay_arrow_position != last_arrow_position
391 || Voverlay_arrow_string != last_arrow_string)
392 all_windows = 1, clip_changed = 1;
393
394 tlbufpos = this_line_bufpos;
395 tlendpos = this_line_endpos;
396 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
397 && SCREEN_VISIBLE_P (XSCREEN (w->screen))
398 /* Make sure recorded data applies to current buffer, etc */
399 && this_line_buffer == current_buffer
400 && current_buffer == XBUFFER (w->buffer)
401 && NILP (w->force_start)
402 /* Point must be on the line that we have info recorded about */
403 && point >= tlbufpos
404 && point <= Z - tlendpos
405 /* All text outside that line, including its final newline,
406 must be unchanged */
407 && (XFASTINT (w->last_modified) >= MODIFF
408 || (beg_unchanged >= tlbufpos - 1
409 && GPT >= tlbufpos
410 && end_unchanged >= tlendpos
411 && Z - GPT >= tlendpos)))
412 {
413 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
414 && (tlbufpos == ZV
415 || FETCH_CHAR (tlbufpos) == '\n'))
416 /* Former continuation line has disappeared by becoming empty */
417 goto cancel;
418 else if (XFASTINT (w->last_modified) < MODIFF
419 || MINI_WINDOW_P (w))
420 {
421 cursor_vpos = -1;
422 overlay_arrow_seen = 0;
423 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
424 pos_tab_offset (w, tlbufpos));
425 /* If line contains point, is not continued,
426 and ends at same distance from eob as before, we win */
427 if (cursor_vpos >= 0 && this_line_bufpos
428 && this_line_endpos == tlendpos)
429 {
430 if (XFASTINT (w->width) != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w))))
431 preserve_other_columns (w);
432 goto update;
433 }
434 else
435 goto cancel;
436 }
437 else if (point == XFASTINT (w->last_point))
438 {
439 if (!must_finish)
440 {
441 do_pending_window_change ();
442 return;
443 }
444 goto update;
445 }
446 else
447 {
448 pos = *compute_motion (tlbufpos, 0,
449 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
450 point, 2, - (1 << (SHORTBITS - 1)),
451 XFASTINT (w->width) - 1
452 - (XFASTINT (w->width) + XFASTINT (w->left)
453 != SCREEN_WIDTH (selected_screen)),
454 XINT (w->hscroll), 0);
455 if (pos.vpos < 1)
456 {
457 SCREEN_CURSOR_X (selected_screen)
458 = XFASTINT (w->left) + max (pos.hpos, 0);
459 SCREEN_CURSOR_Y (selected_screen) = this_line_vpos;
460 goto update;
461 }
462 else
463 goto cancel;
464 }
465 cancel:
466 /* Text changed drastically or point moved off of line */
467 cancel_line (this_line_vpos, selected_screen);
468 }
469
470 this_line_bufpos = 0;
471 all_windows |= buffer_shared > 1;
472
473 if (all_windows)
474 {
475 #ifdef MULTI_SCREEN
476 Lisp_Object tail;
477
478 /* Recompute # windows showing selected buffer.
479 This will be incremented each time such a window is displayed. */
480 buffer_shared = 0;
481
482 for (tail = Vscreen_list; CONSP (tail); tail = XCONS (tail)->cdr)
483 {
484 SCREEN_PTR s;
485
486 if (XTYPE (XCONS (tail)->car) != Lisp_Screen)
487 continue;
488
489 s = XSCREEN (XCONS (tail)->car);
490 if (s->visible)
491 /* Redraw its windows. */
492 redisplay_windows (SCREEN_ROOT_WINDOW (s));
493 }
494 #else
495 redisplay_windows (SCREEN_ROOT_WINDOW (s));
496 #endif /* not MULTI_SCREEN */
497 }
498 else if (SCREEN_VISIBLE_P (selected_screen))
499 {
500 redisplay_window (selected_window, 1);
501 if (XFASTINT (w->width) != SCREEN_WIDTH (selected_screen))
502 preserve_other_columns (w);
503 }
504
505 update:
506 /* Prevent various kinds of signals during display update.
507 stdio is not robust about handling signals,
508 which can cause an apparent I/O error. */
509 if (interrupt_input)
510 unrequest_sigio ();
511 stop_polling ();
512
513 #ifdef MULTI_SCREEN
514 if (all_windows)
515 {
516 Lisp_Object tail;
517
518 pause = 0;
519
520 for (tail = Vscreen_list; CONSP (tail); tail = XCONS (tail)->cdr)
521 {
522 SCREEN_PTR s;
523
524 if (XTYPE (XCONS (tail)->car) != Lisp_Screen)
525 continue;
526
527 s = XSCREEN (XCONS (tail)->car);
528 if (s->visible)
529 {
530 pause |= update_screen (s, 0, 0);
531 if (!pause)
532 mark_window_display_accurate (s->root_window, 1);
533 }
534 }
535 }
536 else
537 #endif /* MULTI_SCREEN */
538 {
539 if (SCREEN_VISIBLE_P (selected_screen))
540 pause = update_screen (selected_screen, 0, 0);
541 #ifdef MULTI_SCREEN
542 /* We may have called echo_area_display at the top of this
543 function. If the echo area is on another screen, that may
544 have put text on a screen other than the selected one, so the
545 above call to update_screen would not have caught it. Catch
546 it here. */
547 {
548 SCREEN_PTR mini_screen =
549 XSCREEN (WINDOW_SCREEN (XWINDOW (minibuf_window)));
550
551 if (mini_screen != selected_screen)
552 pause |= update_screen (mini_screen, 0, 0);
553 }
554 #endif
555 }
556
557 /* If screen does not match, prevent doing single-line-update next time.
558 Also, don't forget to check every line to update the arrow. */
559 if (pause)
560 {
561 this_line_bufpos = 0;
562 if (!NILP (last_arrow_position))
563 {
564 last_arrow_position = Qt;
565 last_arrow_string = Qt;
566 }
567 /* If we pause after scrolling, some lines in current_screen
568 may be null, so preserve_other_columns won't be able to
569 preserve all the vertical-bar separators. So, avoid using it
570 in that case. */
571 if (XFASTINT (w->width) != SCREEN_WIDTH (selected_screen))
572 update_mode_lines = 1;
573 }
574
575 /* Now text on screen agrees with windows, so
576 put info into the windows for partial redisplay to follow */
577
578 if (!pause)
579 {
580 register struct buffer *b = XBUFFER (w->buffer);
581
582 blank_end_of_window = 0;
583 clip_changed = 0;
584 unchanged_modified = BUF_MODIFF (b);
585 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
586 end_unchanged = BUF_Z (b) - BUF_GPT (b);
587
588 XFASTINT (w->last_point) = BUF_PT (b);
589 XFASTINT (w->last_point_x) = SCREEN_CURSOR_X (selected_screen);
590 XFASTINT (w->last_point_y) = SCREEN_CURSOR_Y (selected_screen);
591
592 if (all_windows)
593 mark_window_display_accurate (XWINDOW (minibuf_window)->prev, 1);
594 else
595 {
596 w->update_mode_line = Qnil;
597 XFASTINT (w->last_modified) = BUF_MODIFF (b);
598 w->window_end_valid = Qt;
599 last_arrow_position = Voverlay_arrow_position;
600 last_arrow_string = Voverlay_arrow_string;
601 }
602 update_mode_lines = 0;
603 windows_or_buffers_changed = 0;
604 }
605
606 /* Start SIGIO interrupts coming again.
607 Having them off during the code above
608 makes it less likely one will discard output,
609 but not impossible, since there might be stuff
610 in the system buffer here.
611 But it is much hairier to try to do anything about that. */
612
613 if (interrupt_input)
614 request_sigio ();
615 start_polling ();
616
617 /* Change screen size now if a change is pending. */
618 do_pending_window_change ();
619 }
620
621 /* Redisplay, but leave alone any recent echo area message
622 unless another message has been requested in its place.
623
624 This is useful in situations where you need to redisplay but no
625 user action has occurred, making it inappropriate for the message
626 area to be cleared. See tracking_off and
627 wait_reading_process_input for examples of these situations. */
628
629 redisplay_preserve_echo_area ()
630 {
631 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
632 {
633 echo_area_glyphs = previous_echo_glyphs;
634 redisplay ();
635 echo_area_glyphs = 0;
636 }
637 else
638 redisplay ();
639 }
640
641 void
642 mark_window_display_accurate (window, flag)
643 Lisp_Object window;
644 int flag;
645 {
646 register struct window *w;
647
648 for (;!NILP (window); window = w->next)
649 {
650 w = XWINDOW (window);
651
652 if (!NILP (w->buffer))
653 XFASTINT (w->last_modified)
654 = !flag ? 0
655 : XBUFFER (w->buffer) == current_buffer
656 ? MODIFF : BUF_MODIFF (XBUFFER (w->buffer));
657 w->window_end_valid = Qt;
658 w->update_mode_line = Qnil;
659
660 if (!NILP (w->vchild))
661 mark_window_display_accurate (w->vchild, flag);
662 if (!NILP (w->hchild))
663 mark_window_display_accurate (w->hchild, flag);
664 }
665
666 if (flag)
667 {
668 last_arrow_position = Voverlay_arrow_position;
669 last_arrow_string = Voverlay_arrow_string;
670 }
671 else
672 {
673 /* t is unequal to any useful value of Voverlay_arrow_... */
674 last_arrow_position = Qt;
675 last_arrow_string = Qt;
676 }
677 }
678 \f
679 int do_id = 1;
680
681 static void
682 redisplay_windows (window)
683 Lisp_Object window;
684 {
685 for (; !NILP (window); window = XWINDOW (window)->next)
686 redisplay_window (window, 0);
687 }
688
689 static void
690 redisplay_window (window, just_this_one)
691 Lisp_Object window;
692 int just_this_one;
693 {
694 register struct window *w = XWINDOW (window);
695 SCREEN_PTR s = XSCREEN (w->screen);
696 int height;
697 register int lpoint = point;
698 struct buffer *old = current_buffer;
699 register int width = XFASTINT (w->width) - 1
700 - (XFASTINT (w->width) + XFASTINT (w->left)
701 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w))));
702 register int startp;
703 register int hscroll = XINT (w->hscroll);
704 struct position pos;
705 int opoint;
706 int tem;
707 int window_needs_modeline;
708
709 if (SCREEN_HEIGHT (s) == 0) abort (); /* Some bug zeros some core */
710
711 /* If this is a combination window, do its children; that's all. */
712
713 if (!NILP (w->vchild))
714 {
715 redisplay_windows (w->vchild);
716 return;
717 }
718 if (!NILP (w->hchild))
719 {
720 redisplay_windows (w->hchild);
721 return;
722 }
723 if (NILP (w->buffer))
724 abort ();
725
726 height = window_internal_height (w);
727
728 if (MINI_WINDOW_P (w))
729 {
730 if (w == XWINDOW (minibuf_window))
731 {
732 if (echo_area_glyphs)
733 /* We've already displayed the echo area glyphs, if any. */
734 return;
735 }
736 else
737 {
738 /* This is a minibuffer, but it's not the currently active one, so
739 clear it. */
740 int vpos = XFASTINT (XWINDOW (SCREEN_MINIBUF_WINDOW (s))->top);
741 int i;
742
743 for (i = 0; i < height; i++)
744 {
745 get_display_line (s, vpos + i, 0);
746 display_string (w, vpos + i, "", 0, 0, 0, width);
747 }
748
749 return;
750 }
751 }
752
753 if (update_mode_lines)
754 w->update_mode_line = Qt;
755
756 /* Otherwise set up data on this window; select its buffer and point value */
757
758 current_buffer = XBUFFER (w->buffer);
759 opoint = point;
760
761 /* Count number of windows showing the selected buffer. */
762
763 if (!just_this_one
764 && current_buffer == XBUFFER (XWINDOW (selected_window)->buffer))
765 buffer_shared++;
766
767 /* POINT refers normally to the selected window.
768 For any other window, set up appropriate value. */
769
770 if (!EQ (window, selected_window))
771 {
772 SET_PT (marker_position (w->pointm));
773 if (point < BEGV)
774 {
775 SET_PT (BEGV);
776 Fset_marker (w->pointm, make_number (point), Qnil);
777 }
778 else if (point > (ZV - 1))
779 {
780 SET_PT (ZV);
781 Fset_marker (w->pointm, make_number (point), Qnil);
782 }
783 }
784
785 /* If window-start is screwed up, choose a new one. */
786 if (XMARKER (w->start)->buffer != current_buffer)
787 goto recenter;
788
789 startp = marker_position (w->start);
790
791 /* Handle case where place to start displaying has been specified,
792 unless the specified location is outside the visible range. */
793 if (!NILP (w->force_start))
794 {
795 w->update_mode_line = Qt;
796 w->force_start = Qnil;
797 XFASTINT (w->last_modified) = 0;
798 if (startp < BEGV) startp = BEGV;
799 if (startp > ZV) startp = ZV;
800 try_window (window, startp);
801 if (cursor_vpos < 0)
802 {
803 /* If point does not appear, move point so it does appear */
804 pos = *compute_motion (startp, 0,
805 ((EQ (window, minibuf_window) && startp == 1)
806 ? minibuf_prompt_width : 0)
807 +
808 (hscroll ? 1 - hscroll : 0),
809 ZV, height / 2,
810 - (1 << (SHORTBITS - 1)),
811 width, hscroll, pos_tab_offset (w, startp));
812 SET_PT (pos.bufpos);
813 if (w != XWINDOW (SCREEN_SELECTED_WINDOW (s)))
814 Fset_marker (w->pointm, make_number (point), Qnil);
815 else
816 {
817 lpoint = point;
818 SCREEN_CURSOR_X (s) = max (0, pos.hpos) + XFASTINT (w->left);
819 SCREEN_CURSOR_Y (s) = pos.vpos + XFASTINT (w->top);
820 }
821 }
822 goto done;
823 }
824
825 /* Handle case where text has not changed, only point,
826 and it has not moved off the screen */
827
828 /* This code is not used for minibuffer for the sake of
829 the case of redisplaying to replace an echo area message;
830 since in that case the minibuffer contents per se are usually unchanged.
831 This code is of no real use in the minibuffer since
832 the handling of this_line_bufpos, etc.,
833 in redisplay handles the same cases. */
834
835 if (XFASTINT (w->last_modified) >= MODIFF
836 && point >= startp && !clip_changed
837 && (just_this_one || XFASTINT (w->width) == SCREEN_WIDTH (s))
838 && !EQ (window, minibuf_window))
839 {
840 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0),
841 point, height + 1, 10000, width, hscroll,
842 pos_tab_offset (w, startp));
843
844 if (pos.vpos < height)
845 {
846 /* Ok, point is still on screen */
847 if (w == XWINDOW (SCREEN_SELECTED_WINDOW (s)))
848 {
849 /* These variables are supposed to be origin 1 */
850 SCREEN_CURSOR_X (s) = max (0, pos.hpos) + XFASTINT (w->left);
851 SCREEN_CURSOR_Y (s) = pos.vpos + XFASTINT (w->top);
852 }
853 /* This doesn't do the trick, because if a window to the right of
854 this one must be redisplayed, this does nothing because there
855 is nothing in DesiredScreen yet, and then the other window is
856 redisplayed, making likes that are empty in this window's columns.
857 if (XFASTINT (w->width) != SCREEN_WIDTH (s))
858 preserve_my_columns (w);
859 */
860 goto done;
861 }
862 /* Don't bother trying redisplay with same start;
863 we already know it will lose */
864 }
865 /* If current starting point was originally the beginning of a line
866 but no longer is, find a new starting point. */
867 else if (!NILP (w->start_at_line_beg)
868 && !(startp == BEGV
869 || FETCH_CHAR (startp - 1) == '\n'))
870 {
871 goto recenter;
872 }
873 else if (just_this_one && !MINI_WINDOW_P (w)
874 && point >= startp
875 && XFASTINT (w->last_modified)
876 && ! EQ (w->window_end_valid, Qnil)
877 && do_id && !clip_changed
878 && !blank_end_of_window
879 && XFASTINT (w->width) == SCREEN_WIDTH (s)
880 && EQ (last_arrow_position, Voverlay_arrow_position)
881 && EQ (last_arrow_string, Voverlay_arrow_string)
882 && (tem = try_window_id (SCREEN_SELECTED_WINDOW (s)))
883 && tem != -2)
884 {
885 /* tem > 0 means success. tem == -1 means choose new start.
886 tem == -2 means try again with same start,
887 and nothing but whitespace follows the changed stuff.
888 tem == 0 means try again with same start. */
889 if (tem > 0)
890 goto done;
891 }
892 else if (startp >= BEGV && startp <= ZV
893 /* Avoid starting display at end of buffer! */
894 && (startp < ZV || startp == BEGV
895 || (XFASTINT (w->last_modified) >= MODIFF)))
896 {
897 /* Try to redisplay starting at same place as before */
898 /* If point has not moved off screen, accept the results */
899 try_window (window, startp);
900 if (cursor_vpos >= 0)
901 goto done;
902 else
903 cancel_my_columns (w);
904 }
905
906 XFASTINT (w->last_modified) = 0;
907 w->update_mode_line = Qt;
908
909 /* Try to scroll by specified few lines */
910
911 if (scroll_step && !clip_changed)
912 {
913 if (point > startp)
914 {
915 pos = *vmotion (Z - XFASTINT (w->window_end_pos),
916 scroll_step, width, hscroll, window);
917 if (pos.vpos >= height)
918 goto scroll_fail;
919 }
920
921 pos = *vmotion (startp, point < startp ? - scroll_step : scroll_step,
922 width, hscroll, window);
923
924 if (point >= pos.bufpos)
925 {
926 try_window (window, pos.bufpos);
927 if (cursor_vpos >= 0)
928 goto done;
929 else
930 cancel_my_columns (w);
931 }
932 scroll_fail: ;
933 }
934
935 /* Finally, just choose place to start which centers point */
936
937 recenter:
938 pos = *vmotion (point, - height / 2, width, hscroll, window);
939 try_window (window, pos.bufpos);
940
941 startp = marker_position (w->start);
942 w->start_at_line_beg =
943 (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
944
945 done:
946 /* If window not full width, must redo its mode line
947 if the window to its side is being redone */
948 if ((!NILP (w->update_mode_line)
949 || (!just_this_one && width < SCREEN_WIDTH (s) - 1))
950 && height != XFASTINT (w->height))
951 display_mode_line (w);
952
953 SET_PT (opoint);
954 current_buffer = old;
955 SET_PT (lpoint);
956 }
957 \f
958 /* Do full redisplay on one window, starting at position `pos'. */
959
960 static void
961 try_window (window, pos)
962 Lisp_Object window;
963 register int pos;
964 {
965 register struct window *w = XWINDOW (window);
966 register int height = window_internal_height (w);
967 register int vpos = XFASTINT (w->top);
968 register int last_text_vpos = vpos;
969 int tab_offset = pos_tab_offset (w, pos);
970 SCREEN_PTR s = XSCREEN (w->screen);
971 int width = XFASTINT (w->width) - 1
972 - (XFASTINT (w->width) + XFASTINT (w->left) != SCREEN_WIDTH (s));
973 struct position val;
974
975 Fset_marker (w->start, make_number (pos), Qnil);
976 cursor_vpos = -1;
977 overlay_arrow_seen = 0;
978 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
979
980 while (--height >= 0)
981 {
982 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
983 tab_offset += width;
984 if (val.vpos) tab_offset = 0;
985 vpos++;
986 if (pos != val.bufpos)
987 last_text_vpos
988 /* Next line, unless prev line ended in end of buffer with no cr */
989 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
990 pos = val.bufpos;
991 }
992
993 /* If last line is continued in middle of character,
994 include the split character in the text considered on the screen */
995 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
996 pos++;
997
998 /* If bottom just moved off end of screen, change mode line percentage. */
999 if (XFASTINT (w->window_end_pos) == 0
1000 && Z != pos)
1001 w->update_mode_line = Qt;
1002
1003 /* Say where last char on screen will be, once redisplay is finished. */
1004 XFASTINT (w->window_end_pos) = Z - pos;
1005 XFASTINT (w->window_end_vpos) = last_text_vpos - XFASTINT (w->top);
1006 /* But that is not valid info until redisplay finishes. */
1007 w->window_end_valid = Qnil;
1008 }
1009 \f
1010 /* Try to redisplay when buffer is modified locally,
1011 computing insert/delete line to preserve text outside
1012 the bounds of the changes.
1013 Return 1 if successful, 0 if if cannot tell what to do,
1014 or -1 to tell caller to find a new window start,
1015 or -2 to tell caller to do normal redisplay with same window start. */
1016
1017 static int
1018 try_window_id (window)
1019 Lisp_Object window;
1020 {
1021 int pos;
1022 register struct window *w = XWINDOW (window);
1023 register int height = window_internal_height (w);
1024 SCREEN_PTR s = XSCREEN (w->screen);
1025 int top = XFASTINT (w->top);
1026 int start = marker_position (w->start);
1027 int width = XFASTINT (w->width) - 1
1028 - (XFASTINT (w->width) + XFASTINT (w->left) != SCREEN_WIDTH (s));
1029 int hscroll = XINT (w->hscroll);
1030 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
1031 register int vpos;
1032 register int i, tem;
1033 int last_text_vpos = 0;
1034 int stop_vpos;
1035
1036 struct position val, bp, ep, xp, pp;
1037 int scroll_amount = 0;
1038 int delta;
1039 int tab_offset, epto;
1040
1041 if (GPT - BEG < beg_unchanged)
1042 beg_unchanged = GPT - BEG;
1043 if (Z - GPT < end_unchanged)
1044 end_unchanged = Z - GPT;
1045
1046 if (beg_unchanged + 1 < start)
1047 return 0; /* Give up if changes go above top of window */
1048
1049 /* Find position before which nothing is changed. */
1050 bp = *compute_motion (start, 0, lmargin,
1051 beg_unchanged + 1, height + 1, 0, width, hscroll,
1052 pos_tab_offset (w, start));
1053 if (bp.vpos >= height)
1054 {
1055 if (point < bp.bufpos && !bp.contin)
1056 {
1057 /* All changes are below the screen, and point is on the screen.
1058 We don't need to change the screen at all.
1059 But we need to update window_end_pos to account for
1060 any change in buffer size. */
1061 bp = *compute_motion (start, 0, lmargin,
1062 Z, height, 0,
1063 width, hscroll, pos_tab_offset (w, start));
1064 XFASTINT (w->window_end_vpos) = height;
1065 XFASTINT (w->window_end_pos) = Z - bp.bufpos;
1066 return 1;
1067 }
1068 return 0;
1069 }
1070
1071 vpos = bp.vpos;
1072
1073 /* Find beginning of that screen line. Must display from there. */
1074 bp = *vmotion (bp.bufpos, 0, width, hscroll, window);
1075
1076 pos = bp.bufpos;
1077 val.hpos = lmargin;
1078 if (pos < start)
1079 return -1;
1080
1081 /* If about to start displaying at the beginning of a continuation line,
1082 really start with previous screen line, in case it was not
1083 continued when last redisplayed */
1084 if (bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
1085 {
1086 bp = *vmotion (bp.bufpos, -1, width, hscroll, window);
1087 --vpos;
1088 pos = bp.bufpos;
1089 }
1090
1091 if (bp.contin && bp.hpos != lmargin)
1092 {
1093 val.hpos = bp.prevhpos - width + lmargin;
1094 pos--;
1095 }
1096
1097 bp.vpos = vpos;
1098
1099 /* Find first visible newline after which no more is changed. */
1100 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
1101 if (XTYPE (current_buffer->selective_display) == Lisp_Int
1102 && XINT (current_buffer->selective_display) > 0)
1103 while (tem < ZV - 1
1104 && (position_indentation (tem)
1105 >= XINT (current_buffer->selective_display)))
1106 tem = find_next_newline (tem, 1);
1107
1108 /* Compute the cursor position after that newline. */
1109 ep = *compute_motion (pos, vpos, val.hpos, tem,
1110 height, - (1 << (SHORTBITS - 1)),
1111 width, hscroll, pos_tab_offset (w, bp.bufpos));
1112
1113 /* If changes reach past the text available on the screen,
1114 just display rest of screen. */
1115 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
1116 stop_vpos = height;
1117 else
1118 stop_vpos = ep.vpos;
1119
1120 /* If no newline before ep, the line ep is on includes some changes
1121 that must be displayed. Make sure we don't stop before it. */
1122 /* Also, if changes reach all the way until ep.bufpos,
1123 it is possible that something was deleted after the
1124 newline before it, so the following line must be redrawn. */
1125 if (stop_vpos == ep.vpos
1126 && (ep.bufpos == BEGV
1127 || FETCH_CHAR (ep.bufpos - 1) != '\n'
1128 || ep.bufpos == Z - end_unchanged))
1129 stop_vpos = ep.vpos + 1;
1130
1131 cursor_vpos = -1;
1132 overlay_arrow_seen = 0;
1133
1134 /* If changes do not reach to bottom of window,
1135 figure out how much to scroll the rest of the window */
1136 if (stop_vpos < height)
1137 {
1138 /* Now determine how far up or down the rest of the window has moved */
1139 epto = pos_tab_offset (w, ep.bufpos);
1140 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1141 Z - XFASTINT (w->window_end_pos),
1142 10000, 0, width, hscroll, epto);
1143 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
1144
1145 /* Is everything on screen below the changes whitespace?
1146 If so, no scrolling is really necessary. */
1147 for (i = ep.bufpos; i < xp.bufpos; i++)
1148 {
1149 tem = FETCH_CHAR (i);
1150 if (tem != ' ' && tem != '\n' && tem != '\t')
1151 break;
1152 }
1153 if (i == xp.bufpos)
1154 return -2;
1155
1156 XFASTINT (w->window_end_vpos) += scroll_amount;
1157
1158 /* Before doing any scrolling, verify that point will be on screen. */
1159 if (point > ep.bufpos && !(point <= xp.bufpos && xp.bufpos < height))
1160 {
1161 if (point <= xp.bufpos)
1162 {
1163 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1164 point, height, - (1 << (SHORTBITS - 1)),
1165 width, hscroll, epto);
1166 }
1167 else
1168 {
1169 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos,
1170 point, height, - (1 << (SHORTBITS - 1)),
1171 width, hscroll, pos_tab_offset (w, xp.bufpos));
1172 }
1173 if (pp.bufpos < point || pp.vpos == height)
1174 return 0;
1175 cursor_vpos = pp.vpos + top;
1176 cursor_hpos = pp.hpos + XFASTINT (w->left);
1177 }
1178
1179 if (stop_vpos - scroll_amount >= height
1180 || ep.bufpos == xp.bufpos)
1181 {
1182 if (scroll_amount < 0)
1183 stop_vpos -= scroll_amount;
1184 scroll_amount = 0;
1185 /* In this path, we have altered window_end_vpos
1186 and not left it negative.
1187 We must make sure that, in case display is preempted
1188 before the screen changes to reflect what we do here,
1189 further updates will not come to try_window_id
1190 and assume the screen and window_end_vpos match. */
1191 blank_end_of_window = 1;
1192 }
1193 else if (!scroll_amount)
1194 {}
1195 else if (bp.bufpos == Z - end_unchanged)
1196 {
1197 /* If reprinting everything is nearly as fast as scrolling,
1198 don't bother scrolling. Can happen if lines are short. */
1199 if (scroll_cost (s, bp.vpos + top - scroll_amount,
1200 top + height - max (0, scroll_amount),
1201 scroll_amount)
1202 > xp.bufpos - bp.bufpos - 20)
1203 /* Return "try normal display with same window-start."
1204 Too bad we can't prevent further scroll-thinking. */
1205 return -2;
1206 /* If pure deletion, scroll up as many lines as possible.
1207 In common case of killing a line, this can save the
1208 following line from being overwritten by scrolling
1209 and therefore having to be redrawn. */
1210 tem = scroll_screen_lines (s, bp.vpos + top - scroll_amount,
1211 top + height - max (0, scroll_amount),
1212 scroll_amount);
1213 if (!tem) stop_vpos = height;
1214 }
1215 else if (scroll_amount)
1216 {
1217 /* If reprinting everything is nearly as fast as scrolling,
1218 don't bother scrolling. Can happen if lines are short. */
1219 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1220 overestimate of cost of reprinting, since xp.bufpos
1221 would end up below the bottom of the window. */
1222 if (scroll_cost (s, ep.vpos + top - scroll_amount,
1223 top + height - max (0, scroll_amount),
1224 scroll_amount)
1225 > xp.bufpos - ep.bufpos - 20)
1226 /* Return "try normal display with same window-start."
1227 Too bad we can't prevent further scroll-thinking. */
1228 return -2;
1229 tem = scroll_screen_lines (s, ep.vpos + top - scroll_amount,
1230 top + height - max (0, scroll_amount),
1231 scroll_amount);
1232 if (!tem) stop_vpos = height;
1233 }
1234 }
1235
1236 /* In any case, do not display past bottom of window */
1237 if (stop_vpos >= height)
1238 {
1239 stop_vpos = height;
1240 scroll_amount = 0;
1241 }
1242
1243 /* Handle case where pos is before w->start --
1244 can happen if part of line had been clipped and is not clipped now */
1245 if (vpos == 0 && pos < marker_position (w->start))
1246 Fset_marker (w->start, make_number (pos), Qnil);
1247
1248 /* Redisplay the lines where the text was changed */
1249 last_text_vpos = vpos;
1250 tab_offset = pos_tab_offset (w, pos);
1251 /* If we are starting display in mid-character, correct tab_offset
1252 to account for passing the line that that character really starts in. */
1253 if (val.hpos < lmargin)
1254 tab_offset += width;
1255 while (vpos < stop_vpos)
1256 {
1257 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
1258 tab_offset += width;
1259 if (val.vpos) tab_offset = 0;
1260 if (pos != val.bufpos)
1261 last_text_vpos
1262 /* Next line, unless prev line ended in end of buffer with no cr */
1263 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
1264 pos = val.bufpos;
1265 }
1266
1267 /* There are two cases:
1268 1) we have displayed down to the bottom of the window
1269 2) we have scrolled lines below stop_vpos by scroll_amount */
1270
1271 if (vpos == height)
1272 {
1273 /* If last line is continued in middle of character,
1274 include the split character in the text considered on the screen */
1275 if (val.hpos < lmargin)
1276 val.bufpos++;
1277 XFASTINT (w->window_end_vpos) = last_text_vpos;
1278 XFASTINT (w->window_end_pos) = Z - val.bufpos;
1279 }
1280
1281 /* If scrolling made blank lines at window bottom,
1282 redisplay to fill those lines */
1283 if (scroll_amount < 0)
1284 {
1285 /* Don't consider these lines for general-purpose scrolling.
1286 That will save time in the scrolling computation. */
1287 SCREEN_SCROLL_BOTTOM_VPOS (s) = xp.vpos;
1288 vpos = xp.vpos;
1289 pos = xp.bufpos;
1290 val.hpos = lmargin;
1291 if (pos == ZV)
1292 vpos = height + scroll_amount;
1293 else if (xp.contin && xp.hpos != lmargin)
1294 {
1295 val.hpos = xp.prevhpos - width + lmargin;
1296 pos--;
1297 }
1298
1299 blank_end_of_window = 1;
1300 tab_offset = pos_tab_offset (w, pos);
1301 /* If we are starting display in mid-character, correct tab_offset
1302 to account for passing the line that that character starts in. */
1303 if (val.hpos < lmargin)
1304 tab_offset += width;
1305
1306 while (vpos < height)
1307 {
1308 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
1309 tab_offset += width;
1310 if (val.vpos) tab_offset = 0;
1311 pos = val.bufpos;
1312 }
1313
1314 /* Here is a case where display_text_line sets cursor_vpos wrong.
1315 Make it be fixed up, below. */
1316 if (xp.bufpos == ZV
1317 && xp.bufpos == point)
1318 cursor_vpos = -1;
1319 }
1320
1321 /* If bottom just moved off end of screen, change mode line percentage. */
1322 if (XFASTINT (w->window_end_pos) == 0
1323 && Z != val.bufpos)
1324 w->update_mode_line = Qt;
1325
1326 /* Attempt to adjust end-of-text positions to new bottom line */
1327 if (scroll_amount)
1328 {
1329 delta = height - xp.vpos;
1330 if (delta < 0
1331 || (delta > 0 && xp.bufpos <= ZV)
1332 || (delta == 0 && xp.hpos))
1333 {
1334 val = *vmotion (Z - XFASTINT (w->window_end_pos),
1335 delta, width, hscroll, window);
1336 XFASTINT (w->window_end_pos) = Z - val.bufpos;
1337 XFASTINT (w->window_end_vpos) += val.vpos;
1338 }
1339 }
1340
1341 w->window_end_valid = Qnil;
1342
1343 /* If point was not in a line that was displayed, find it */
1344 if (cursor_vpos < 0)
1345 {
1346 val = *compute_motion (start, 0, lmargin, point, 10000, 10000,
1347 width, hscroll, pos_tab_offset (w, start));
1348 /* Admit failure if point is off screen now */
1349 if (val.vpos >= height)
1350 {
1351 for (vpos = 0; vpos < height; vpos++)
1352 cancel_line (vpos + top, s);
1353 return 0;
1354 }
1355 cursor_vpos = val.vpos + top;
1356 cursor_hpos = val.hpos + XFASTINT (w->left);
1357 }
1358
1359 SCREEN_CURSOR_X (s) = max (0, cursor_hpos);
1360 SCREEN_CURSOR_Y (s) = cursor_vpos;
1361
1362 if (debug_end_pos)
1363 {
1364 val = *compute_motion (start, 0, lmargin, ZV,
1365 height, - (1 << (SHORTBITS - 1)),
1366 width, hscroll, pos_tab_offset (w, start));
1367 if (val.vpos != XFASTINT (w->window_end_vpos))
1368 abort ();
1369 if (XFASTINT (w->window_end_pos)
1370 != Z - val.bufpos)
1371 abort ();
1372 }
1373
1374 return 1;
1375 }
1376 \f
1377 /* Copy glyphs from the rope FROM to T.
1378 But don't actually copy the parts that would come in before S.
1379 Value is T, advanced past the copied data.
1380
1381 Characters in FROM are grouped into units of `sizeof GLYPH' chars;
1382 any extra chars at the end of FROM are ignored. */
1383
1384 GLYPH *
1385 copy_rope (t, s, from)
1386 register GLYPH *t; /* Copy to here. */
1387 register GLYPH *s; /* Starting point. */
1388 Lisp_Object from; /* Data to copy; known to be a string. */
1389 {
1390 register int n = XSTRING (from)->size / sizeof (GLYPH);
1391 register GLYPH *f = (GLYPH *) XSTRING (from)->data;
1392
1393 while (n--)
1394 {
1395 if (t >= s) *t = *f;
1396 ++t;
1397 ++f;
1398 }
1399 return t;
1400 }
1401 \f
1402 /* Display one line of window w, starting at position START in W's buffer.
1403 Display starting at horizontal position HPOS, which is normally zero
1404 or negative. A negative value causes output up to hpos = 0 to be discarded.
1405 This is done for negative hscroll, or when this is a continuation line
1406 and the continuation occurred in the middle of a multi-column character.
1407
1408 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
1409
1410 Display on position VPOS on the screen. (origin 0).
1411
1412 Returns a STRUCT POSITION giving character to start next line with
1413 and where to display it, including a zero or negative hpos.
1414 The vpos field is not really a vpos; it is 1 unless the line is continued */
1415
1416 struct position val_display_text_line;
1417
1418 static struct position *
1419 display_text_line (w, start, vpos, hpos, taboffset)
1420 struct window *w;
1421 int start;
1422 int vpos;
1423 int hpos;
1424 int taboffset;
1425 {
1426 register int pos = start;
1427 register int c;
1428 register GLYPH *p1;
1429 int end;
1430 register int pause;
1431 register unsigned char *p;
1432 GLYPH *endp;
1433 register GLYPH *startp;
1434 register GLYPH *p1prev;
1435 SCREEN_PTR s = XSCREEN (w->screen);
1436 int tab_width = XINT (current_buffer->tab_width);
1437 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
1438 int width = XFASTINT (w->width) - 1
1439 - (XFASTINT (w->width) + XFASTINT (w->left) != SCREEN_WIDTH (s));
1440 struct position val;
1441 int lastpos;
1442 int invis;
1443 int hscroll = XINT (w->hscroll);
1444 int truncate = hscroll
1445 || (truncate_partial_width_windows
1446 && XFASTINT (w->width) < SCREEN_WIDTH (s))
1447 || !NILP (current_buffer->truncate_lines);
1448 int selective
1449 = XTYPE (current_buffer->selective_display) == Lisp_Int
1450 ? XINT (current_buffer->selective_display)
1451 : !NILP (current_buffer->selective_display) ? -1 : 0;
1452 #ifndef old
1453 int selective_e = selective && !NILP (current_buffer->selective_display_ellipses);
1454 #endif
1455 register struct screen_glyphs *desired_glyphs = SCREEN_DESIRED_GLYPHS (s);
1456 register struct Lisp_Vector *dp = window_display_table (w);
1457 int selective_rlen
1458 = (selective && dp && XTYPE (DISP_INVIS_ROPE (dp)) == Lisp_String
1459 ? XSTRING (DISP_INVIS_ROPE (dp))->size / sizeof (GLYPH) : 0);
1460 GLYPH truncator = (dp == 0 || XTYPE (DISP_TRUNC_GLYPH (dp)) != Lisp_Int
1461 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
1462 GLYPH continuer = (dp == 0 || XTYPE (DISP_CONTINUE_GLYPH (dp)) != Lisp_Int
1463 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
1464
1465 hpos += XFASTINT (w->left);
1466 get_display_line (s, vpos, XFASTINT (w->left));
1467 if (tab_width <= 0 || tab_width > 20) tab_width = 8;
1468
1469 if (MINI_WINDOW_P (w) && start == 1
1470 && vpos == XFASTINT (w->top))
1471 {
1472 if (minibuf_prompt)
1473 hpos = display_string (w, vpos, minibuf_prompt, hpos,
1474 (!truncate ? continuer : truncator),
1475 -1, -1);
1476 minibuf_prompt_width = hpos;
1477 }
1478
1479 desired_glyphs->bufp[vpos] = pos;
1480 p1 = desired_glyphs->glyphs[vpos] + hpos;
1481 end = ZV;
1482 startp = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
1483 endp = startp + width;
1484
1485 /* Loop generating characters.
1486 Stop at end of buffer, before newline,
1487 or if reach or pass continuation column. */
1488
1489 pause = pos;
1490 while (p1 < endp)
1491 {
1492 p1prev = p1;
1493 if (pos == pause)
1494 {
1495 if (pos == end)
1496 break;
1497 if (pos == point && cursor_vpos < 0)
1498 {
1499 cursor_vpos = vpos;
1500 cursor_hpos = p1 - startp;
1501 }
1502
1503 pause = end;
1504 if (pos < point && point < pause)
1505 pause = point;
1506 if (pos < GPT && GPT < pause)
1507 pause = GPT;
1508
1509 p = &FETCH_CHAR (pos);
1510 }
1511 c = *p++;
1512 if (c >= 040 && c < 0177
1513 && (dp == 0 || XTYPE (DISP_CHAR_ROPE (dp, c)) != Lisp_String))
1514 {
1515 if (p1 >= startp)
1516 *p1 = c;
1517 p1++;
1518 }
1519 else if (c == '\n')
1520 {
1521 invis = 0;
1522 while (pos < end
1523 && selective > 0
1524 && position_indentation (pos + 1) >= selective)
1525 {
1526 invis = 1;
1527 pos = find_next_newline (pos + 1, 1);
1528 if (FETCH_CHAR (pos - 1) == '\n')
1529 pos--;
1530 }
1531 if (invis && selective_rlen > 0 && p1 >= startp)
1532 {
1533 p1 += selective_rlen;
1534 if (p1 - startp > width)
1535 p1 = endp;
1536 bcopy (XSTRING (DISP_INVIS_ROPE (dp))->data, p1prev,
1537 (p1 - p1prev) * sizeof (GLYPH));
1538 }
1539 break;
1540 }
1541 else if (c == '\t')
1542 {
1543 do
1544 {
1545 if (p1 >= startp && p1 < endp)
1546 *p1 = SPACEGLYPH;
1547 p1++;
1548 }
1549 while ((p1 - startp + taboffset + hscroll - (hscroll > 0))
1550 % tab_width);
1551 }
1552 else if (c == Ctl ('M') && selective == -1)
1553 {
1554 pos = find_next_newline (pos, 1);
1555 if (FETCH_CHAR (pos - 1) == '\n')
1556 pos--;
1557 if (selective_rlen > 0)
1558 {
1559 p1 += selective_rlen;
1560 if (p1 - startp > width)
1561 p1 = endp;
1562 bcopy (XSTRING (DISP_INVIS_ROPE (dp))->data, p1prev,
1563 (p1 - p1prev) * sizeof (GLYPH));
1564 }
1565 break;
1566 }
1567 else if (dp != 0 && XTYPE (DISP_CHAR_ROPE (dp, c)) == Lisp_String)
1568 {
1569 p1 = copy_rope (p1, startp, DISP_CHAR_ROPE (dp, c));
1570 }
1571 else if (c < 0200 && ctl_arrow)
1572 {
1573 if (p1 >= startp)
1574 *p1 = (dp && XTYPE (DISP_CTRL_GLYPH (dp)) == Lisp_Int
1575 ? XINT (DISP_CTRL_GLYPH (dp)) : '^');
1576 p1++;
1577 if (p1 >= startp && p1 < endp)
1578 *p1 = c ^ 0100;
1579 p1++;
1580 }
1581 else
1582 {
1583 if (p1 >= startp)
1584 *p1 = (dp && XTYPE (DISP_ESCAPE_GLYPH (dp)) == Lisp_Int
1585 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\');
1586 p1++;
1587 if (p1 >= startp && p1 < endp)
1588 *p1 = (c >> 6) + '0';
1589 p1++;
1590 if (p1 >= startp && p1 < endp)
1591 *p1 = (7 & (c >> 3)) + '0';
1592 p1++;
1593 if (p1 >= startp && p1 < endp)
1594 *p1 = (7 & c) + '0';
1595 p1++;
1596 }
1597 pos++;
1598 }
1599
1600 val.hpos = - XINT (w->hscroll);
1601 if (val.hpos)
1602 val.hpos++;
1603
1604 val.vpos = 1;
1605
1606 lastpos = pos;
1607
1608 /* Handle continuation in middle of a character */
1609 /* by backing up over it */
1610 if (p1 > endp)
1611 {
1612 /* Start the next line with that same character */
1613 pos--;
1614 /* but at a negative hpos, to skip the columns output on this line. */
1615 val.hpos += p1prev - endp;
1616 /* Keep in this line everything up to the continuation column. */
1617 p1 = endp;
1618 }
1619
1620 /* Finish deciding which character to start the next line on,
1621 and what hpos to start it at.
1622 Also set `lastpos' to the last position which counts as "on this line"
1623 for cursor-positioning. */
1624
1625 if (pos < ZV)
1626 {
1627 if (FETCH_CHAR (pos) == '\n')
1628 /* If stopped due to a newline, start next line after it */
1629 pos++;
1630 else
1631 /* Stopped due to right margin of window */
1632 {
1633 if (truncate)
1634 {
1635 *p1++ = truncator;
1636 /* Truncating => start next line after next newline,
1637 and point is on this line if it is before the newline,
1638 and skip none of first char of next line */
1639 pos = find_next_newline (pos, 1);
1640 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1641
1642 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
1643 }
1644 else
1645 {
1646 *p1++ = continuer;
1647 val.vpos = 0;
1648 lastpos--;
1649 }
1650 }
1651 }
1652
1653 /* If point is at eol or in invisible text at eol,
1654 record its screen location now. */
1655
1656 if (start <= point && point <= lastpos && cursor_vpos < 0)
1657 {
1658 cursor_vpos = vpos;
1659 cursor_hpos = p1 - startp;
1660 }
1661
1662 if (cursor_vpos == vpos)
1663 {
1664 if (cursor_hpos < 0) cursor_hpos = 0;
1665 if (cursor_hpos > width) cursor_hpos = width;
1666 cursor_hpos += XFASTINT (w->left);
1667 if (w == XWINDOW (SCREEN_SELECTED_WINDOW (s)))
1668 {
1669 SCREEN_CURSOR_Y (s) = cursor_vpos;
1670 SCREEN_CURSOR_X (s) = cursor_hpos;
1671
1672 if (w == XWINDOW (selected_window))
1673 {
1674 /* Line is not continued and did not start
1675 in middle of character */
1676 if ((hpos - XFASTINT (w->left)
1677 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1678 && val.vpos)
1679 {
1680 this_line_bufpos = start;
1681 this_line_buffer = current_buffer;
1682 this_line_vpos = cursor_vpos;
1683 this_line_start_hpos = hpos;
1684 this_line_endpos = Z - lastpos;
1685 }
1686 else
1687 this_line_bufpos = 0;
1688 }
1689 }
1690 }
1691
1692 /* If hscroll and line not empty, insert truncation-at-left marker */
1693 if (hscroll && lastpos != start)
1694 {
1695 *startp = truncator;
1696 if (p1 <= startp)
1697 p1 = startp + 1;
1698 }
1699
1700 if (XFASTINT (w->width) + XFASTINT (w->left) != SCREEN_WIDTH (s))
1701 {
1702 endp++;
1703 if (p1 < startp) p1 = startp;
1704 while (p1 < endp) *p1++ = SPACEGLYPH;
1705 *p1++ = '|';
1706 }
1707 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
1708 p1 - desired_glyphs->glyphs[vpos]);
1709 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
1710
1711 /* If the start of this line is the overlay arrow-position,
1712 then put the arrow string into the display-line. */
1713
1714 if (XTYPE (Voverlay_arrow_position) == Lisp_Marker
1715 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
1716 && start == marker_position (Voverlay_arrow_position)
1717 && XTYPE (Voverlay_arrow_string) == Lisp_String
1718 && ! overlay_arrow_seen)
1719 {
1720 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
1721 int i;
1722 int len = XSTRING (Voverlay_arrow_string)->size;
1723
1724 if (len > XFASTINT (w->width) - 1)
1725 len = XFASTINT (w->width) - 1;
1726 for (i = 0; i < len; i++)
1727 startp[i] = p[i];
1728 if (desired_glyphs->used[vpos] <
1729 (len + startp - desired_glyphs->glyphs[vpos]))
1730 desired_glyphs->used[vpos] = len + startp - desired_glyphs->glyphs[vpos];
1731
1732 overlay_arrow_seen = 1;
1733 }
1734
1735 val.bufpos = pos;
1736 val_display_text_line = val;
1737 return &val_display_text_line;
1738 }
1739 \f
1740 /* Display the mode line for window w */
1741
1742 static void
1743 display_mode_line (w)
1744 struct window *w;
1745 {
1746 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
1747 register int left = XFASTINT (w->left);
1748 register int right = XFASTINT (w->width) + left;
1749 register SCREEN_PTR s = XSCREEN (WINDOW_SCREEN (w));
1750
1751 get_display_line (s, vpos, left);
1752 display_mode_element (w, vpos, left, 0, right, right,
1753 current_buffer->mode_line_format);
1754 SCREEN_DESIRED_GLYPHS (s)->bufp[vpos] = 0;
1755
1756 /* Make the mode line inverse video if the entire line
1757 is made of mode lines.
1758 I.e. if this window is full width,
1759 or if it is the child of a full width window
1760 (which implies that that window is split side-by-side
1761 and the rest of this line is mode lines of the sibling windows). */
1762 if (XFASTINT (w->width) == SCREEN_WIDTH (s)
1763 || XFASTINT (XWINDOW (w->parent)->width) == SCREEN_WIDTH (s))
1764 s->desired_glyphs->highlight[vpos] = mode_line_inverse_video;
1765
1766 #ifdef HAVE_X_WINDOWS
1767 /* I'm trying this out because I saw Unimpress use it, but it's
1768 possible that this may mess adversely with some window managers. jla */
1769
1770 if (SCREEN_IS_X (s)
1771 && ! SCREEN_MINIBUF_ONLY_P (s)
1772 && w == XWINDOW (s->selected_window)
1773 && (NILP (Fstring_equal (XBUFFER (w->buffer)->name, s->name))))
1774 x_set_name (s, XBUFFER (w->buffer)->name, Qnil);
1775 #endif
1776 }
1777
1778 /* Contribute ELT to the mode line for window W.
1779 How it translates into text depends on its data type.
1780
1781 VPOS is the position of the mode line being displayed.
1782
1783 HPOS is the position (absolute on screen) where this element's text
1784 should start. The output is truncated automatically at the right
1785 edge of window W.
1786
1787 DEPTH is the depth in recursion. It is used to prevent
1788 infinite recursion here.
1789
1790 MINENDCOL is the hpos before which the element may not end.
1791 The element is padded at the right with spaces if nec
1792 to reach this column.
1793
1794 MAXENDCOL is the hpos past which this element may not extend.
1795 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
1796 (This is necessary to make nested padding and truncation work.)
1797
1798 Returns the hpos of the end of the text generated by ELT.
1799 The next element will receive that value as its HPOS arg,
1800 so as to concatenate the elements. */
1801
1802 static int
1803 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
1804 struct window *w;
1805 register int vpos, hpos;
1806 int depth;
1807 int minendcol;
1808 register int maxendcol;
1809 register Lisp_Object elt;
1810 {
1811 tail_recurse:
1812 if (depth > 10)
1813 goto invalid;
1814
1815 depth++;
1816
1817 #ifdef SWITCH_ENUM_BUG
1818 switch ((int) XTYPE (elt))
1819 #else
1820 switch (XTYPE (elt))
1821 #endif
1822 {
1823 case Lisp_String:
1824 {
1825 /* A string: output it and check for %-constructs within it. */
1826 register unsigned char c;
1827 register unsigned char *this = XSTRING (elt)->data;
1828
1829 while (hpos < maxendcol && *this)
1830 {
1831 unsigned char *last = this;
1832 while ((c = *this++) != '\0' && c != '%')
1833 ;
1834 if (this - 1 != last)
1835 {
1836 register int lim = --this - last + hpos;
1837 hpos = display_string (w, vpos, last, hpos, 0, hpos,
1838 min (lim, maxendcol));
1839 }
1840 else /* c == '%' */
1841 {
1842 register int spec_width = 0;
1843
1844 /* We can't allow -ve args due to the "%-" construct */
1845 /* Argument specifies minwidth but not maxwidth
1846 (maxwidth can be specified by
1847 (<negative-number> . <stuff>) mode-line elements) */
1848
1849 while ((c = *this++) >= '0' && c <= '9')
1850 {
1851 spec_width = spec_width * 10 + (c - '0');
1852 }
1853
1854 spec_width += hpos;
1855 if (spec_width > maxendcol)
1856 spec_width = maxendcol;
1857
1858 if (c == 'M')
1859 hpos = display_mode_element (w, vpos, hpos, depth,
1860 spec_width, maxendcol,
1861 Vglobal_mode_string);
1862 else if (c != 0)
1863 hpos = display_string (w, vpos,
1864 decode_mode_spec (w, c,
1865 maxendcol - hpos),
1866 hpos, 0, spec_width, maxendcol);
1867 }
1868 }
1869 }
1870 break;
1871
1872 case Lisp_Symbol:
1873 /* A symbol: process the value of the symbol recursively
1874 as if it appeared here directly. Avoid error if symbol void.
1875 Special case: if value of symbol is a string, output the string
1876 literally. */
1877 {
1878 register Lisp_Object tem;
1879 tem = Fboundp (elt);
1880 if (!NILP (tem))
1881 {
1882 tem = Fsymbol_value (elt);
1883 /* If value is a string, output that string literally:
1884 don't check for % within it. */
1885 if (XTYPE (tem) == Lisp_String)
1886 hpos = display_string (w, vpos, XSTRING (tem)->data,
1887 hpos, 0, minendcol, maxendcol);
1888 /* Give up right away for nil or t. */
1889 else if (!EQ (tem, elt))
1890 { elt = tem; goto tail_recurse; }
1891 }
1892 }
1893 break;
1894
1895 case Lisp_Cons:
1896 {
1897 register Lisp_Object car, tem;
1898
1899 /* A cons cell: three distinct cases.
1900 If first element is a string or a cons, process all the elements
1901 and effectively concatenate them.
1902 If first element is a negative number, truncate displaying cdr to
1903 at most that many characters. If positive, pad (with spaces)
1904 to at least that many characters.
1905 If first element is a symbol, process the cadr or caddr recursively
1906 according to whether the symbol's value is non-nil or nil. */
1907 car = XCONS (elt)->car;
1908 if (XTYPE (car) == Lisp_Symbol)
1909 {
1910 tem = Fboundp (car);
1911 elt = XCONS (elt)->cdr;
1912 if (XTYPE (elt) != Lisp_Cons)
1913 goto invalid;
1914 /* elt is now the cdr, and we know it is a cons cell.
1915 Use its car if CAR has a non-nil value. */
1916 if (!NILP (tem))
1917 {
1918 tem = Fsymbol_value (car);
1919 if (!NILP (tem))
1920 { elt = XCONS (elt)->car; goto tail_recurse; }
1921 }
1922 /* Symbol's value is nil (or symbol is unbound)
1923 Get the cddr of the original list
1924 and if possible find the caddr and use that. */
1925 elt = XCONS (elt)->cdr;
1926 if (NILP (elt))
1927 break;
1928 else if (XTYPE (elt) != Lisp_Cons)
1929 goto invalid;
1930 elt = XCONS (elt)->car;
1931 goto tail_recurse;
1932 }
1933 else if (XTYPE (car) == Lisp_Int)
1934 {
1935 register int lim = XINT (car);
1936 elt = XCONS (elt)->cdr;
1937 if (lim < 0)
1938 /* Negative int means reduce maximum width.
1939 DO NOT change MINENDCOL here!
1940 (20 -10 . foo) should truncate foo to 10 col
1941 and then pad to 20. */
1942 maxendcol = min (maxendcol, hpos - lim);
1943 else if (lim > 0)
1944 {
1945 /* Padding specified. Don't let it be more than
1946 current maximum. */
1947 lim += hpos;
1948 if (lim > maxendcol)
1949 lim = maxendcol;
1950 /* If that's more padding than already wanted, queue it.
1951 But don't reduce padding already specified even if
1952 that is beyond the current truncation point. */
1953 if (lim > minendcol)
1954 minendcol = lim;
1955 }
1956 goto tail_recurse;
1957 }
1958 else if (XTYPE (car) == Lisp_String || XTYPE (car) == Lisp_Cons)
1959 {
1960 register int limit = 50;
1961 /* LIMIT is to protect against circular lists. */
1962 while (XTYPE (elt) == Lisp_Cons && --limit > 0
1963 && hpos < maxendcol)
1964 {
1965 hpos = display_mode_element (w, vpos, hpos, depth,
1966 hpos, maxendcol,
1967 XCONS (elt)->car);
1968 elt = XCONS (elt)->cdr;
1969 }
1970 }
1971 }
1972 break;
1973
1974 default:
1975 invalid:
1976 return (display_string (w, vpos, "*invalid*", hpos, 0,
1977 minendcol, maxendcol));
1978 }
1979
1980 end:
1981 if (minendcol > hpos)
1982 hpos = display_string (w, vpos, "", hpos, 0, minendcol, -1);
1983 return hpos;
1984 }
1985 \f
1986 /* Return a string for the output of a mode line %-spec for window W,
1987 generated by character C and width MAXWIDTH. */
1988
1989 static char *
1990 decode_mode_spec (w, c, maxwidth)
1991 struct window *w;
1992 register char c;
1993 register int maxwidth;
1994 {
1995 Lisp_Object obj = Qnil;
1996 SCREEN_PTR scr = XSCREEN (WINDOW_SCREEN (w));
1997 char *decode_mode_spec_buf = (char *) SCREEN_TEMP_GLYPHS (scr)->total_contents;
1998
1999 if (maxwidth > SCREEN_WIDTH (scr))
2000 maxwidth = SCREEN_WIDTH (scr);
2001
2002 switch (c)
2003 {
2004 case 'b':
2005 obj = current_buffer->name;
2006 #if 0
2007 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
2008 {
2009 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
2010 decode_mode_spec_buf[maxwidth - 1] = '\\';
2011 decode_mode_spec_buf[maxwidth] = '\0';
2012 return decode_mode_spec_buf;
2013 }
2014 #endif
2015 break;
2016
2017 case 'f':
2018 obj = current_buffer->filename;
2019 #if 0
2020 if (NILP (obj))
2021 return "[none]";
2022 else if (XTYPE (obj) == Lisp_String && XSTRING (obj)->size > maxwidth)
2023 {
2024 bcopy ("...", decode_mode_spec_buf, 3);
2025 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
2026 decode_mode_spec_buf + 3, maxwidth - 3);
2027 return decode_mode_spec_buf;
2028 }
2029 #endif
2030 break;
2031
2032 case 'm':
2033 obj = current_buffer->mode_name;
2034 break;
2035
2036 case 'n':
2037 if (BEGV > BEG || ZV < Z)
2038 return " Narrow";
2039 break;
2040
2041 case '*':
2042 if (!NILP (current_buffer->read_only))
2043 return "%";
2044 if (MODIFF > current_buffer->save_modified)
2045 return "*";
2046 return "-";
2047
2048 case 's':
2049 /* status of process */
2050 #ifdef subprocesses
2051 obj = Fget_buffer_process (Fcurrent_buffer ());
2052 if (NILP (obj))
2053 return "no process";
2054 obj = Fsymbol_name (Fprocess_status (obj));
2055 break;
2056 #else
2057 return "no processes";
2058 #endif /* subprocesses */
2059
2060 case 'p':
2061 {
2062 int pos = marker_position (w->start);
2063 int total = ZV - BEGV;
2064
2065 if (XFASTINT (w->window_end_pos) <= Z - ZV)
2066 {
2067 if (pos <= BEGV)
2068 return "All";
2069 else
2070 return "Bottom";
2071 }
2072 else if (pos <= BEGV)
2073 return "Top";
2074 else
2075 {
2076 total = ((pos - BEGV) * 100 + total - 1) / total;
2077 /* We can't normally display a 3-digit number,
2078 so get us a 2-digit number that is close. */
2079 if (total == 100)
2080 total = 99;
2081 sprintf (decode_mode_spec_buf, "%2d%%", total);
2082 return decode_mode_spec_buf;
2083 }
2084 }
2085
2086 case '%':
2087 return "%";
2088
2089 case '[':
2090 {
2091 int i;
2092 char *p;
2093
2094 if (command_loop_level > 5)
2095 return "[[[... ";
2096 p = decode_mode_spec_buf;
2097 for (i = 0; i < command_loop_level; i++)
2098 *p++ = '[';
2099 *p = 0;
2100 return decode_mode_spec_buf;
2101 }
2102
2103 case ']':
2104 {
2105 int i;
2106 char *p;
2107
2108 if (command_loop_level > 5)
2109 return " ...]]]";
2110 p = decode_mode_spec_buf;
2111 for (i = 0; i < command_loop_level; i++)
2112 *p++ = ']';
2113 *p = 0;
2114 return decode_mode_spec_buf;
2115 }
2116
2117 case '-':
2118 {
2119 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
2120 register char *p;
2121 register int i;
2122
2123 if (maxwidth < sizeof (lots_of_dashes))
2124 return lots_of_dashes;
2125 else
2126 {
2127 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
2128 *p++ = '-';
2129 *p = '\0';
2130 }
2131 return decode_mode_spec_buf;
2132 }
2133 }
2134
2135 if (XTYPE (obj) == Lisp_String)
2136 return (char *) XSTRING (obj)->data;
2137 else
2138 return "";
2139 }
2140 \f
2141 /* Display STRING on one line of window W, starting at HPOS.
2142 Display at position VPOS. Caller should have done get_display_line.
2143
2144 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
2145
2146 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
2147 MAXCOL is the last column ok to end at. Truncate here.
2148 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
2149 Both count from the left edge of the screen, as does HPOS.
2150 The right edge of W is an implicit maximum.
2151 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
2152
2153 Returns ending hpos */
2154
2155 static int
2156 display_string (w, vpos, string, hpos, truncate, mincol, maxcol)
2157 struct window *w;
2158 unsigned char *string;
2159 int vpos, hpos;
2160 GLYPH truncate;
2161 int mincol, maxcol;
2162 {
2163 register int c;
2164 register GLYPH *p1;
2165 int hscroll = XINT (w->hscroll);
2166 int tab_width = XINT (current_buffer->tab_width);
2167 register GLYPH *start;
2168 register GLYPH *end;
2169 struct screen_glyphs *desired_glyphs = SCREEN_DESIRED_GLYPHS (XSCREEN (w->screen));
2170 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
2171 int window_width = XFASTINT (w->width);
2172
2173 /* Use the standard display table, not the window's display table.
2174 We don't want the mode line in rot13. */
2175 register struct Lisp_Vector *dp = 0;
2176
2177 if (XTYPE (Vstandard_display_table) == Lisp_Vector
2178 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
2179 dp = XVECTOR (Vstandard_display_table);
2180
2181 if (tab_width <= 0 || tab_width > 20) tab_width = 8;
2182
2183 p1 = p1start;
2184 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2185 end = start + window_width - (truncate != 0);
2186
2187 if ((window_width + XFASTINT (w->left))
2188 != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w))))
2189 *end-- = '|';
2190
2191 if (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol)
2192 end = desired_glyphs->glyphs[vpos] + maxcol;
2193 if (maxcol >= 0 && mincol > maxcol)
2194 mincol = maxcol;
2195
2196 while (p1 < end)
2197 {
2198 c = *string++;
2199 if (!c) break;
2200 if (c >= 040 && c < 0177
2201 && (dp == 0 || XTYPE (DISP_CHAR_ROPE (dp, c)) != Lisp_String))
2202 {
2203 if (p1 >= start)
2204 *p1 = c;
2205 p1++;
2206 }
2207 else if (c == '\t')
2208 {
2209 do
2210 {
2211 if (p1 >= start && p1 < end)
2212 *p1 = SPACEGLYPH;
2213 p1++;
2214 }
2215 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
2216 }
2217 else if (dp != 0 && XTYPE (DISP_CHAR_ROPE (dp, c)) == Lisp_String)
2218 p1 = copy_rope (p1, start, DISP_CHAR_ROPE (dp, c));
2219 else if (c < 0200 && buffer_defaults.ctl_arrow)
2220 {
2221 if (p1 >= start)
2222 *p1 = (dp && XTYPE (DISP_CTRL_GLYPH (dp)) == Lisp_Int
2223 ? XINT (DISP_CTRL_GLYPH (dp)) : '^');
2224 p1++;
2225 if (p1 >= start && p1 < end)
2226 *p1 = c ^ 0100;
2227 p1++;
2228 }
2229 else
2230 {
2231 if (p1 >= start)
2232 *p1 = (dp && XTYPE (DISP_ESCAPE_GLYPH (dp)) == Lisp_Int
2233 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\');
2234 p1++;
2235 if (p1 >= start && p1 < end)
2236 *p1 = (c >> 6) + '0';
2237 p1++;
2238 if (p1 >= start && p1 < end)
2239 *p1 = (7 & (c >> 3)) + '0';
2240 p1++;
2241 if (p1 >= start && p1 < end)
2242 *p1 = (7 & c) + '0';
2243 p1++;
2244 }
2245 }
2246
2247 if (c)
2248 {
2249 p1 = end;
2250 if (truncate) *p1++ = truncate;
2251 }
2252 else if (mincol >= 0)
2253 {
2254 end = desired_glyphs->glyphs[vpos] + mincol;
2255 while (p1 < end)
2256 *p1++ = SPACEGLYPH;
2257 }
2258
2259 {
2260 register int len = p1 - desired_glyphs->glyphs[vpos];
2261
2262 if (len > desired_glyphs->used[vpos])
2263 desired_glyphs->used[vpos] = len;
2264 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
2265
2266 return len;
2267 }
2268 }
2269 \f
2270 void
2271 syms_of_xdisp ()
2272 {
2273 staticpro (&last_arrow_position);
2274 staticpro (&last_arrow_string);
2275 last_arrow_position = Qnil;
2276 last_arrow_string = Qnil;
2277
2278 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
2279 "String displayed by mode-line-format's \"%m\" specifiation.");
2280 Vglobal_mode_string = Qnil;
2281
2282 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
2283 "Marker for where to display an arrow on top of the buffer text.\n\
2284 This must be the beginning of a line in order to work.\n\
2285 See also `overlay-arrow-string'.");
2286 Voverlay_arrow_position = Qnil;
2287
2288 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
2289 "String to display as an arrow. See also `overlay-arrow-position'.");
2290 Voverlay_arrow_string = Qnil;
2291
2292 DEFVAR_INT ("scroll-step", &scroll_step,
2293 "*The number of lines to try scrolling a window by when point moves out.\n\
2294 If that fails to bring point back on screen, point is centered instead.\n\
2295 If this is zero, point is always centered after it moves off screen.");
2296
2297 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
2298
2299 DEFVAR_BOOL ("truncate-partial-width-windows",
2300 &truncate_partial_width_windows,
2301 "*Non-nil means truncate lines in all windows less than full screen wide.");
2302 truncate_partial_width_windows = 1;
2303
2304 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
2305 "*Non-nil means use inverse video for the mode line.");
2306 mode_line_inverse_video = 1;
2307
2308 #ifndef MULTI_SCREEN
2309 defsubr (&Sredraw_display);
2310 #endif /* MULTI_SCREEN */
2311 }
2312
2313 /* initialize the window system */
2314 init_xdisp ()
2315 {
2316 Lisp_Object root_window;
2317 #ifndef COMPILER_REGISTER_BUG
2318 register
2319 #endif /* COMPILER_REGISTER_BUG */
2320 struct window *mini_w;
2321
2322 this_line_bufpos = 0;
2323
2324 mini_w = XWINDOW (minibuf_window);
2325 root_window = mini_w->prev;
2326
2327 echo_area_glyphs = 0;
2328 previous_echo_glyphs = 0;
2329
2330 if (!noninteractive)
2331 {
2332 SCREEN_PTR s = XSCREEN (WINDOW_SCREEN (XWINDOW (root_window)));
2333 XFASTINT (XWINDOW (root_window)->top) = 0;
2334 set_window_height (root_window, SCREEN_HEIGHT (s) - 1, 0);
2335 XFASTINT (mini_w->top) = SCREEN_HEIGHT (s) - 1;
2336 set_window_height (minibuf_window, 1, 0);
2337
2338 XFASTINT (XWINDOW (root_window)->width) = SCREEN_WIDTH (s);
2339 XFASTINT (mini_w->width) = SCREEN_WIDTH (s);
2340 }
2341 }