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