Doc fixes.
[bpt/emacs.git] / src / xdisp.c
CommitLineData
a2889657 1/* Display generation from window structure and buffer text.
76412d64 2 Copyright (C) 1985, 86, 87, 88, 93, 94 Free Software Foundation, Inc.
a2889657
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
b1d1124b 8the Free Software Foundation; either version 2, or (at your option)
a2889657
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
18160b98 21#include <config.h>
a2889657
JB
22#include <stdio.h>
23/*#include <ctype.h>*/
24#undef NULL
25#include "lisp.h"
44fa5b1e 26#include "frame.h"
a2889657
JB
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"
30c566e4 35#include "termhooks.h"
b0a0fbda 36#include "intervals.h"
a2889657 37
76412d64
RS
38#ifdef USE_X_TOOLKIT
39extern void set_frame_menubar ();
40#endif
41
a2889657
JB
42extern int interrupt_input;
43extern int command_loop_level;
44
45/* Nonzero means print newline before next minibuffer message. */
46
47int noninteractive_need_newline;
48
49#define min(a, b) ((a) < (b) ? (a) : (b))
50#define max(a, b) ((a) > (b) ? (a) : (b))
51
52/* The buffer position of the first character appearing
44fa5b1e
JB
53 entirely or partially on the current frame line.
54 Or zero, which disables the optimization for the current frame line. */
a2889657
JB
55static int this_line_bufpos;
56
57/* Number of characters past the end of this line,
58 including the terminating newline */
59static int this_line_endpos;
60
44fa5b1e 61/* The vertical position of this frame line. */
a2889657
JB
62static int this_line_vpos;
63
44fa5b1e 64/* Hpos value for start of display on this frame line.
a2889657
JB
65 Usually zero, but negative if first character really began
66 on previous line */
67static int this_line_start_hpos;
68
69/* Buffer that this_line variables are describing. */
70static struct buffer *this_line_buffer;
71
72/* Set by try_window_id to the vpos of first of any lines
44fa5b1e 73 scrolled on to the bottom of the frame. These lines should
a2889657
JB
74 not be included in any general scroll computation. */
75static int scroll_bottom_vpos;
76
77/* Value of echo_area_glyphs when it was last acted on.
44fa5b1e 78 If this is nonzero, there is a message on the frame
a2889657
JB
79 in the minibuffer and it should be erased as soon
80 as it is no longer requested to appear. */
81char *previous_echo_glyphs;
82
44fa5b1e 83/* Nonzero means truncate lines in all windows less wide than the frame */
a2889657
JB
84int truncate_partial_width_windows;
85
86Lisp_Object Vglobal_mode_string;
87
88/* Marker for where to display an arrow on top of the buffer text. */
89Lisp_Object Voverlay_arrow_position;
90
91/* String to display for the arrow. */
92Lisp_Object Voverlay_arrow_string;
93
94/* Values of those variables at last redisplay. */
ded34426 95static Lisp_Object last_arrow_position, last_arrow_string;
a2889657
JB
96
97/* Nonzero if overlay arrow has been displayed once in this window. */
98static int overlay_arrow_seen;
99
fba9ce76
RS
100/* Nonzero means highlight the region even in nonselected windows. */
101static int highlight_nonselected_windows;
102
44fa5b1e 103/* If cursor motion alone moves point off frame,
a2889657
JB
104 Try scrolling this many lines up or down if that will bring it back. */
105int scroll_step;
106
107/* Nonzero if try_window_id has made blank lines at window bottom
108 since the last redisplay that paused */
109static int blank_end_of_window;
110
111/* Number of windows showing the buffer of the selected window.
112 keyboard.c refers to this. */
113int buffer_shared;
114
44fa5b1e 115/* display_text_line sets these to the frame position (origin 0) of point,
a2889657
JB
116 whether the window is selected or not.
117 Set one to -1 first to determine whether point was found afterwards. */
118
119static int cursor_vpos;
120static int cursor_hpos;
121
122int debug_end_pos;
123
124/* Nonzero means display mode line highlighted */
125int mode_line_inverse_video;
126
127static void echo_area_display ();
128void mark_window_display_accurate ();
129static void redisplay_windows ();
130static void redisplay_window ();
90adcf20
RS
131static void update_menu_bars ();
132static void update_menu_bar ();
a2889657
JB
133static void try_window ();
134static int try_window_id ();
135static struct position *display_text_line ();
136static void display_mode_line ();
137static int display_mode_element ();
138static char *fmodetrunc ();
139static char *decode_mode_spec ();
140static int display_string ();
7ce2c095 141static void display_menu_bar ();
aa6d10fa 142static int display_count_lines ();
a2889657
JB
143
144/* Prompt to display in front of the minibuffer contents */
145char *minibuf_prompt;
146
147/* Width in columns of current minibuffer prompt. */
148int minibuf_prompt_width;
149
150/* Message to display instead of minibuffer contents
151 This is what the functions error and message make,
152 and command echoing uses it as well.
153 It overrides the minibuf_prompt as well as the buffer. */
154char *echo_area_glyphs;
155
90adcf20
RS
156/* This is the length of the message in echo_area_glyphs. */
157int echo_area_glyphs_length;
158
a2889657
JB
159/* true iff we should redraw the mode lines on the next redisplay */
160int update_mode_lines;
161
162/* Smallest number of characters before the gap
163 at any time since last redisplay that finished.
164 Valid for current buffer when try_window_id can be called. */
165int beg_unchanged;
166
167/* Smallest number of characters after the gap
168 at any time since last redisplay that finished.
169 Valid for current buffer when try_window_id can be called. */
170int end_unchanged;
171
172/* MODIFF as of last redisplay that finished;
173 if it matches MODIFF, beg_unchanged and end_unchanged
174 contain no useful information */
175int unchanged_modified;
176
177/* Nonzero if head_clip or tail_clip of current buffer has changed
178 since last redisplay that finished */
179int clip_changed;
180
181/* Nonzero if window sizes or contents have changed
182 since last redisplay that finished */
183int windows_or_buffers_changed;
184
aa6d10fa
RS
185/* Nonzero after display_mode_line if %l was used
186 and it displayed a line number. */
187int line_number_displayed;
188
189/* Maximum buffer size for which to display line numbers. */
190int line_number_display_limit;
a2889657 191\f
90adcf20 192/* Display an echo area message M with a specified length of LEN chars.
48ae5f0a
KH
193 The string may include null characters. If m is 0, clear out any
194 existing message, and let the minibuffer text show through.
195 Do not pass text that is stored in a Lisp string. */
90adcf20
RS
196
197void
198message2 (m, len)
199 char *m;
200 int len;
201{
202 if (noninteractive)
203 {
204 if (noninteractive_need_newline)
205 putc ('\n', stderr);
206 noninteractive_need_newline = 0;
207 fwrite (m, len, 1, stderr);
208 if (cursor_in_echo_area == 0)
209 fprintf (stderr, "\n");
210 fflush (stderr);
211 }
212 /* A null message buffer means that the frame hasn't really been
213 initialized yet. Error messages get reported properly by
214 cmd_error, so this must be just an informative message; toss it. */
215 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
216 {
217#ifdef MULTI_FRAME
218 Lisp_Object minibuf_frame;
219
220 choose_minibuf_frame ();
221 minibuf_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
222 FRAME_SAMPLE_VISIBILITY (XFRAME (minibuf_frame));
223 if (FRAME_VISIBLE_P (selected_frame)
224 && ! FRAME_VISIBLE_P (XFRAME (minibuf_frame)))
225 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (minibuf_window)));
226#endif
227
228 if (m)
229 {
230 echo_area_glyphs = m;
231 echo_area_glyphs_length = len;
232 }
ded34426
JB
233 else
234 echo_area_glyphs = previous_echo_glyphs = 0;
235
236 do_pending_window_change ();
237 echo_area_display ();
238 update_frame (XFRAME (XWINDOW (minibuf_window)->frame), 1, 1);
239 do_pending_window_change ();
240 }
241}
242
48ae5f0a
KH
243void
244message1 (m)
245 char *m;
246{
247 message2 (m, (m ? strlen (m) : 0));
248}
249
76412d64
RS
250/* Truncate what will be displayed in the echo area
251 the next time we display it--but don't redisplay it now. */
252
253void
254truncate_echo_area (len)
255 int len;
256{
257 /* A null message buffer means that the frame hasn't really been
258 initialized yet. Error messages get reported properly by
259 cmd_error, so this must be just an informative message; toss it. */
260 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
261 echo_area_glyphs_length = len;
262}
263
44fa5b1e 264/* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
9c74a0dd
JB
265 zero if being used by message. */
266int message_buf_print;
267
81d478f3
JB
268/* Dump an informative message to the minibuf. If m is 0, clear out
269 any existing message, and let the minibuffer text show through. */
a2889657 270/* VARARGS 1 */
a2889657
JB
271void
272message (m, a1, a2, a3)
273 char *m;
274{
275 if (noninteractive)
276 {
81d478f3
JB
277 if (m)
278 {
279 if (noninteractive_need_newline)
280 putc ('\n', stderr);
281 noninteractive_need_newline = 0;
282 fprintf (stderr, m, a1, a2, a3);
c4f14ccb
RS
283 if (cursor_in_echo_area == 0)
284 fprintf (stderr, "\n");
81d478f3
JB
285 fflush (stderr);
286 }
a2889657 287 }
1f40cad2 288 else if (INTERACTIVE)
a2889657 289 {
1f40cad2
JB
290 /* The frame whose minibuffer we're going to display the message on.
291 It may be larger than the selected frame, so we need
292 to use its buffer, not the selected frame's buffer. */
293 FRAME_PTR echo_frame;
294#ifdef MULTI_FRAME
295 choose_minibuf_frame ();
296 echo_frame = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
297#else
298 echo_frame = selected_frame;
299#endif
300
301 /* A null message buffer means that the frame hasn't really been
302 initialized yet. Error messages get reported properly by
303 cmd_error, so this must be just an informative message; toss it. */
304 if (FRAME_MESSAGE_BUF (echo_frame))
81d478f3 305 {
1f40cad2
JB
306 if (m)
307 {
90adcf20 308 int len;
a2889657 309#ifdef NO_ARG_ARRAY
90adcf20
RS
310 int a[3];
311 a[0] = a1;
312 a[1] = a2;
313 a[2] = a3;
a2889657 314
90adcf20
RS
315 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
316 FRAME_WIDTH (echo_frame), m, 0, 3, a);
a2889657 317#else
90adcf20
RS
318 len = doprnt (FRAME_MESSAGE_BUF (echo_frame),
319 FRAME_WIDTH (echo_frame), m, 0, 3, &a1);
1f40cad2 320#endif /* NO_ARG_ARRAY */
1f40cad2 321
90adcf20 322 message2 (FRAME_MESSAGE_BUF (echo_frame), len);
1f40cad2
JB
323 }
324 else
325 message1 (0);
326
327 /* Print should start at the beginning of the message
328 buffer next time. */
329 message_buf_print = 0;
81d478f3 330 }
a2889657
JB
331 }
332}
333
334static void
335echo_area_display ()
336{
337 register int vpos;
44fa5b1e 338 FRAME_PTR f;
a2889657 339
44fa5b1e
JB
340#ifdef MULTI_FRAME
341 choose_minibuf_frame ();
b1d1124b
JB
342#endif
343
44fa5b1e 344 f = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
a2889657 345
44fa5b1e 346 if (! FRAME_VISIBLE_P (f))
a2889657 347 return;
a2889657 348
44fa5b1e 349 if (frame_garbaged)
a2889657 350 {
02a9b6e4 351 redraw_garbaged_frames ();
44fa5b1e 352 frame_garbaged = 0;
a2889657
JB
353 }
354
355 if (echo_area_glyphs || minibuf_level == 0)
356 {
357 vpos = XFASTINT (XWINDOW (minibuf_window)->top);
44fa5b1e 358 get_display_line (f, vpos, 0);
a2889657
JB
359 display_string (XWINDOW (minibuf_window), vpos,
360 echo_area_glyphs ? echo_area_glyphs : "",
90adcf20 361 echo_area_glyphs ? echo_area_glyphs_length : -1,
278feba9 362 0, 0, 0, 0, FRAME_WIDTH (f));
a2889657
JB
363
364 /* If desired cursor location is on this line, put it at end of text */
44fa5b1e
JB
365 if (FRAME_CURSOR_Y (f) == vpos)
366 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
daa37602
JB
367
368 /* Fill the rest of the minibuffer window with blank lines. */
369 {
370 int i;
371
b2a76982
RS
372 for (i = vpos + 1;
373 i < vpos + XFASTINT (XWINDOW (minibuf_window)->height); i++)
daa37602 374 {
44fa5b1e 375 get_display_line (f, i, 0);
daa37602 376 display_string (XWINDOW (minibuf_window), vpos,
278feba9 377 "", 0, 0, 0, 0, 0, FRAME_WIDTH (f));
daa37602
JB
378 }
379 }
a2889657
JB
380 }
381 else if (!EQ (minibuf_window, selected_window))
382 windows_or_buffers_changed++;
383
384 if (EQ (minibuf_window, selected_window))
385 this_line_bufpos = 0;
386
387 previous_echo_glyphs = echo_area_glyphs;
388}
96a410bc
KH
389
390#ifdef HAVE_X_WINDOWS
391/* I'm trying this out because I saw Unimpress use it, but it's
392 possible that this may mess adversely with some window managers. -jla
393
394 Wouldn't it be nice to use something like mode-line-format to
395 describe frame titles? -JimB */
396
397/* Change the title of the frame to the name of the buffer displayed
398 in the currently selected window. Don't do this for minibuffer frames,
399 and don't do it when there's only one non-minibuffer frame. */
400static void
401x_consider_frame_title (frame)
402 Lisp_Object frame;
403{
404 FRAME_PTR f = XFRAME (frame);
405
406 if (FRAME_X_P (f) && ! FRAME_MINIBUF_ONLY_P (f))
407 {
0b67772d 408 Lisp_Object title;
96a410bc 409
0b67772d 410 title = Qnil;
96a410bc
KH
411 if (! EQ (Fnext_frame (frame, Qnil), frame))
412 title = XBUFFER (XWINDOW (f->selected_window)->buffer)->name;
413
414 x_implicitly_set_name (f, title, Qnil);
415 }
416}
417#endif
a2889657 418\f
90adcf20
RS
419/* Prepare for redisplay by updating menu-bar item lists when appropriate.
420 This can't be done in `redisplay' itself because it can call eval. */
421
422void
423prepare_menu_bars ()
424{
425 register struct window *w = XWINDOW (selected_window);
426 int all_windows;
427
428 if (noninteractive)
429 return;
430
431 /* Set the visible flags for all frames.
432 Do this before checking for resized or garbaged frames; they want
433 to know if their frames are visible.
434 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
435 {
436 Lisp_Object tail, frame;
437
438 FOR_EACH_FRAME (tail, frame)
439 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
440 }
441
442 /* Notice any pending interrupt request to change frame size. */
443 do_pending_window_change ();
444
445 if (frame_garbaged)
446 {
447 redraw_garbaged_frames ();
448 frame_garbaged = 0;
449 }
450
451 if (clip_changed || windows_or_buffers_changed)
452 update_mode_lines++;
453
454 /* Detect case that we need to write a star in the mode line. */
455 if (XFASTINT (w->last_modified) < MODIFF
456 && XFASTINT (w->last_modified) <= current_buffer->save_modified)
457 {
458 w->update_mode_line = Qt;
459 if (buffer_shared > 1)
460 update_mode_lines++;
461 }
462
463 all_windows = update_mode_lines || buffer_shared > 1;
464
465 /* If specs for an arrow have changed, do thorough redisplay
466 to ensure we remove any arrow that should no longer exist. */
467 if (! EQ (Voverlay_arrow_position, last_arrow_position)
468 || ! EQ (Voverlay_arrow_string, last_arrow_string))
469 all_windows = 1, clip_changed = 1;
470
471 /* Update the menu bar item lists, if appropriate.
472 This has to be done before any actual redisplay
473 or generation of display lines. */
474 if (all_windows)
475 {
476 Lisp_Object tail, frame;
477
478 FOR_EACH_FRAME (tail, frame)
479 {
480 FRAME_PTR f = XFRAME (frame);
481
482 if (FRAME_VISIBLE_P (f))
483 update_menu_bars (FRAME_ROOT_WINDOW (f));
484 }
485 }
486 else if (FRAME_VISIBLE_P (selected_frame))
487 update_menu_bar (selected_window);
488}
489\f
44fa5b1e 490/* Do a frame update, taking possible shortcuts into account.
a2889657
JB
491 This is the main external entry point for redisplay.
492
493 If the last redisplay displayed an echo area message and that
494 message is no longer requested, we clear the echo area
495 or bring back the minibuffer if that is in use.
496
90adcf20
RS
497 Do not call eval from within this function.
498 Calls to eval after the call to echo_area_display would confuse
499 the display_line mechanism and would cause a crash.
500 Calls to eval before that point will work most of the time,
501 but can still lose, because this function
502 can be called from signal handlers; with alarms set up;
a2889657 503 or with synchronous processes running.
90adcf20 504
a2889657
JB
505 See Fcall_process; if you called it from here, it could be
506 entered recursively. */
507
508void
509redisplay ()
510{
511 register struct window *w = XWINDOW (selected_window);
512 register int pause;
513 int must_finish = 0;
514 int all_windows;
515 register int tlbufpos, tlendpos;
516 struct position pos;
517 extern int input_pending;
518
519 if (noninteractive)
520 return;
521
d724d989
JB
522 /* Set the visible flags for all frames.
523 Do this before checking for resized or garbaged frames; they want
524 to know if their frames are visible.
525 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
526 {
35f56f96 527 Lisp_Object tail, frame;
d724d989 528
35f56f96
JB
529 FOR_EACH_FRAME (tail, frame)
530 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
d724d989
JB
531 }
532
44fa5b1e 533 /* Notice any pending interrupt request to change frame size. */
a2889657
JB
534 do_pending_window_change ();
535
44fa5b1e 536 if (frame_garbaged)
a2889657 537 {
02a9b6e4 538 redraw_garbaged_frames ();
44fa5b1e 539 frame_garbaged = 0;
a2889657
JB
540 }
541
a2889657
JB
542 if (clip_changed || windows_or_buffers_changed)
543 update_mode_lines++;
544
545 /* Detect case that we need to write a star in the mode line. */
546 if (XFASTINT (w->last_modified) < MODIFF
547 && XFASTINT (w->last_modified) <= current_buffer->save_modified)
548 {
549 w->update_mode_line = Qt;
550 if (buffer_shared > 1)
551 update_mode_lines++;
552 }
553
44fa5b1e 554 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
a2889657
JB
555
556 all_windows = update_mode_lines || buffer_shared > 1;
a2889657
JB
557
558 /* If specs for an arrow have changed, do thorough redisplay
559 to ensure we remove any arrow that should no longer exist. */
ded34426
JB
560 if (! EQ (Voverlay_arrow_position, last_arrow_position)
561 || ! EQ (Voverlay_arrow_string, last_arrow_string))
a2889657
JB
562 all_windows = 1, clip_changed = 1;
563
90adcf20
RS
564 /* Normally the message* functions will have already displayed and
565 updated the echo area, but the frame may have been trashed, or
566 the update may have been preempted, so display the echo area
567 again here. */
568 if (echo_area_glyphs || previous_echo_glyphs)
569 {
570 echo_area_display ();
571 must_finish = 1;
572 }
573
bd66d1ba
RS
574 /* If showing region, and mark has changed, must redisplay whole window. */
575 if (((!NILP (Vtransient_mark_mode)
576 && !NILP (XBUFFER (w->buffer)->mark_active))
577 != !NILP (w->region_showing))
82d04750
JB
578 || (!NILP (w->region_showing)
579 && !EQ (w->region_showing,
580 Fmarker_position (XBUFFER (w->buffer)->mark))))
bd66d1ba
RS
581 this_line_bufpos = -1;
582
a2889657
JB
583 tlbufpos = this_line_bufpos;
584 tlendpos = this_line_endpos;
265a9e55 585 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
44fa5b1e 586 && FRAME_VISIBLE_P (XFRAME (w->frame))
a2889657
JB
587 /* Make sure recorded data applies to current buffer, etc */
588 && this_line_buffer == current_buffer
589 && current_buffer == XBUFFER (w->buffer)
265a9e55 590 && NILP (w->force_start)
a2889657
JB
591 /* Point must be on the line that we have info recorded about */
592 && point >= tlbufpos
593 && point <= Z - tlendpos
594 /* All text outside that line, including its final newline,
595 must be unchanged */
596 && (XFASTINT (w->last_modified) >= MODIFF
597 || (beg_unchanged >= tlbufpos - 1
598 && GPT >= tlbufpos
05ba02eb
JB
599 /* If selective display, can't optimize
600 if the changes start at the beginning of the line. */
601 && ((XTYPE (current_buffer->selective_display) == Lisp_Int
602 && XINT (current_buffer->selective_display) > 0
603 ? (beg_unchanged >= tlbufpos
604 && GPT > tlbufpos)
605 : 1))
a2889657
JB
606 && end_unchanged >= tlendpos
607 && Z - GPT >= tlendpos)))
608 {
609 if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
610 && (tlbufpos == ZV
611 || FETCH_CHAR (tlbufpos) == '\n'))
612 /* Former continuation line has disappeared by becoming empty */
613 goto cancel;
614 else if (XFASTINT (w->last_modified) < MODIFF
615 || MINI_WINDOW_P (w))
616 {
617 cursor_vpos = -1;
618 overlay_arrow_seen = 0;
619 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
620 pos_tab_offset (w, tlbufpos));
621 /* If line contains point, is not continued,
622 and ends at same distance from eob as before, we win */
623 if (cursor_vpos >= 0 && this_line_bufpos
624 && this_line_endpos == tlendpos)
625 {
44fa5b1e 626 if (XFASTINT (w->width) != FRAME_WIDTH (XFRAME (WINDOW_FRAME (w))))
a2889657
JB
627 preserve_other_columns (w);
628 goto update;
629 }
630 else
631 goto cancel;
632 }
633 else if (point == XFASTINT (w->last_point))
634 {
635 if (!must_finish)
636 {
637 do_pending_window_change ();
638 return;
639 }
640 goto update;
641 }
bd66d1ba
RS
642 /* If highlighting the region, we can't just move the cursor. */
643 else if (! (!NILP (Vtransient_mark_mode)
644 && !NILP (current_buffer->mark_active))
645 && NILP (w->region_showing))
a2889657
JB
646 {
647 pos = *compute_motion (tlbufpos, 0,
648 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
649 point, 2, - (1 << (SHORTBITS - 1)),
b1d1124b 650 window_internal_width (w) - 1,
de3e8b15
JB
651 XINT (w->hscroll),
652 pos_tab_offset (w, tlbufpos));
a2889657
JB
653 if (pos.vpos < 1)
654 {
44fa5b1e 655 FRAME_CURSOR_X (selected_frame)
a2889657 656 = XFASTINT (w->left) + max (pos.hpos, 0);
44fa5b1e 657 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
a2889657
JB
658 goto update;
659 }
660 else
661 goto cancel;
662 }
663 cancel:
664 /* Text changed drastically or point moved off of line */
44fa5b1e 665 cancel_line (this_line_vpos, selected_frame);
a2889657
JB
666 }
667
668 this_line_bufpos = 0;
669 all_windows |= buffer_shared > 1;
670
671 if (all_windows)
672 {
35f56f96 673 Lisp_Object tail, frame;
a2889657 674
31b24551
JB
675#ifdef HAVE_X_WINDOWS
676 /* Since we're doing a thorough redisplay, we might as well
677 recompute all our display faces. */
678 clear_face_vector ();
679#endif
680
a2889657 681 /* Recompute # windows showing selected buffer.
8de2d90b 682 This will be incremented each time such a window is displayed. */
a2889657
JB
683 buffer_shared = 0;
684
35f56f96 685 FOR_EACH_FRAME (tail, frame)
30c566e4 686 {
35f56f96
JB
687 FRAME_PTR f = XFRAME (frame);
688
88f22aff 689 /* Mark all the scroll bars to be removed; we'll redeem the ones
30c566e4 690 we want when we redisplay their windows. */
88f22aff
JB
691 if (condemn_scroll_bars_hook)
692 (*condemn_scroll_bars_hook) (f);
30c566e4
JB
693
694 if (FRAME_VISIBLE_P (f))
695 redisplay_windows (FRAME_ROOT_WINDOW (f));
96a410bc 696#ifdef HAVE_X_WINDOWS
98bc00f0
KH
697 else if (FRAME_ICONIFIED_P (f)
698 && ! MINI_WINDOW_P (XWINDOW (f->selected_window)))
96a410bc
KH
699 x_consider_frame_title (frame);
700#endif
30c566e4 701
88f22aff 702 /* Any scroll bars which redisplay_windows should have nuked
30c566e4 703 should now go away. */
88f22aff
JB
704 if (judge_scroll_bars_hook)
705 (*judge_scroll_bars_hook) (f);
30c566e4 706 }
a2889657 707 }
44fa5b1e 708 else if (FRAME_VISIBLE_P (selected_frame))
a2889657
JB
709 {
710 redisplay_window (selected_window, 1);
44fa5b1e 711 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
a2889657
JB
712 preserve_other_columns (w);
713 }
714
715update:
716 /* Prevent various kinds of signals during display update.
717 stdio is not robust about handling signals,
718 which can cause an apparent I/O error. */
719 if (interrupt_input)
720 unrequest_sigio ();
721 stop_polling ();
722
44fa5b1e 723#ifdef MULTI_FRAME
a2889657
JB
724 if (all_windows)
725 {
726 Lisp_Object tail;
727
728 pause = 0;
729
44fa5b1e 730 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
a2889657 731 {
44fa5b1e 732 FRAME_PTR f;
a2889657 733
44fa5b1e 734 if (XTYPE (XCONS (tail)->car) != Lisp_Frame)
a2889657
JB
735 continue;
736
44fa5b1e 737 f = XFRAME (XCONS (tail)->car);
30c566e4 738 if (FRAME_VISIBLE_P (f))
a2889657 739 {
44fa5b1e 740 pause |= update_frame (f, 0, 0);
a2889657 741 if (!pause)
efc63ef0
RS
742 {
743 mark_window_display_accurate (f->root_window, 1);
744 if (frame_up_to_date_hook != 0)
745 (*frame_up_to_date_hook) (f);
746 }
a2889657
JB
747 }
748 }
749 }
750 else
44fa5b1e 751#endif /* MULTI_FRAME */
6e8290aa 752 {
44fa5b1e
JB
753 if (FRAME_VISIBLE_P (selected_frame))
754 pause = update_frame (selected_frame, 0, 0);
d724d989 755
8de2d90b 756 /* We may have called echo_area_display at the top of this
44fa5b1e
JB
757 function. If the echo area is on another frame, that may
758 have put text on a frame other than the selected one, so the
759 above call to update_frame would not have caught it. Catch
8de2d90b
JB
760 it here. */
761 {
efc63ef0
RS
762 FRAME_PTR mini_frame
763 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
8de2d90b 764
44fa5b1e
JB
765 if (mini_frame != selected_frame)
766 pause |= update_frame (mini_frame, 0, 0);
8de2d90b 767 }
6e8290aa 768 }
a2889657 769
44fa5b1e 770 /* If frame does not match, prevent doing single-line-update next time.
a2889657
JB
771 Also, don't forget to check every line to update the arrow. */
772 if (pause)
773 {
774 this_line_bufpos = 0;
265a9e55 775 if (!NILP (last_arrow_position))
a2889657
JB
776 {
777 last_arrow_position = Qt;
778 last_arrow_string = Qt;
779 }
44fa5b1e 780 /* If we pause after scrolling, some lines in current_frame
a2889657
JB
781 may be null, so preserve_other_columns won't be able to
782 preserve all the vertical-bar separators. So, avoid using it
783 in that case. */
44fa5b1e 784 if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame))
a2889657
JB
785 update_mode_lines = 1;
786 }
787
44fa5b1e 788 /* Now text on frame agrees with windows, so
a2889657
JB
789 put info into the windows for partial redisplay to follow */
790
791 if (!pause)
792 {
793 register struct buffer *b = XBUFFER (w->buffer);
794
795 blank_end_of_window = 0;
796 clip_changed = 0;
797 unchanged_modified = BUF_MODIFF (b);
798 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
799 end_unchanged = BUF_Z (b) - BUF_GPT (b);
800
801 XFASTINT (w->last_point) = BUF_PT (b);
44fa5b1e
JB
802 XFASTINT (w->last_point_x) = FRAME_CURSOR_X (selected_frame);
803 XFASTINT (w->last_point_y) = FRAME_CURSOR_Y (selected_frame);
a2889657
JB
804
805 if (all_windows)
11e82b76 806 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
a2889657
JB
807 else
808 {
809 w->update_mode_line = Qnil;
810 XFASTINT (w->last_modified) = BUF_MODIFF (b);
811 w->window_end_valid = Qt;
812 last_arrow_position = Voverlay_arrow_position;
813 last_arrow_string = Voverlay_arrow_string;
efc63ef0
RS
814 if (frame_up_to_date_hook != 0)
815 (*frame_up_to_date_hook) (selected_frame);
a2889657
JB
816 }
817 update_mode_lines = 0;
818 windows_or_buffers_changed = 0;
819 }
820
821 /* Start SIGIO interrupts coming again.
822 Having them off during the code above
823 makes it less likely one will discard output,
824 but not impossible, since there might be stuff
825 in the system buffer here.
826 But it is much hairier to try to do anything about that. */
827
828 if (interrupt_input)
829 request_sigio ();
830 start_polling ();
831
44fa5b1e 832 /* Change frame size now if a change is pending. */
a2889657
JB
833 do_pending_window_change ();
834}
835
836/* Redisplay, but leave alone any recent echo area message
837 unless another message has been requested in its place.
838
839 This is useful in situations where you need to redisplay but no
840 user action has occurred, making it inappropriate for the message
841 area to be cleared. See tracking_off and
842 wait_reading_process_input for examples of these situations. */
843
844redisplay_preserve_echo_area ()
845{
846 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
847 {
848 echo_area_glyphs = previous_echo_glyphs;
849 redisplay ();
850 echo_area_glyphs = 0;
851 }
852 else
853 redisplay ();
854}
855
856void
857mark_window_display_accurate (window, flag)
858 Lisp_Object window;
859 int flag;
860{
861 register struct window *w;
862
265a9e55 863 for (;!NILP (window); window = w->next)
a2889657 864 {
ded34426 865 if (XTYPE (window) != Lisp_Window) abort ();
a2889657
JB
866 w = XWINDOW (window);
867
265a9e55 868 if (!NILP (w->buffer))
bd66d1ba
RS
869 {
870 XFASTINT (w->last_modified)
871 = !flag ? 0
872 : XBUFFER (w->buffer) == current_buffer
873 ? MODIFF : BUF_MODIFF (XBUFFER (w->buffer));
874
875 /* Record if we are showing a region, so can make sure to
876 update it fully at next redisplay. */
877 w->region_showing = (!NILP (Vtransient_mark_mode)
878 && !NILP (XBUFFER (w->buffer)->mark_active)
879 ? Fmarker_position (XBUFFER (w->buffer)->mark)
880 : Qnil);
881 }
882
a2889657
JB
883 w->window_end_valid = Qt;
884 w->update_mode_line = Qnil;
885
265a9e55 886 if (!NILP (w->vchild))
a2889657 887 mark_window_display_accurate (w->vchild, flag);
265a9e55 888 if (!NILP (w->hchild))
a2889657
JB
889 mark_window_display_accurate (w->hchild, flag);
890 }
891
892 if (flag)
893 {
894 last_arrow_position = Voverlay_arrow_position;
895 last_arrow_string = Voverlay_arrow_string;
896 }
897 else
898 {
899 /* t is unequal to any useful value of Voverlay_arrow_... */
900 last_arrow_position = Qt;
901 last_arrow_string = Qt;
902 }
903}
904\f
90adcf20
RS
905/* Update the menu bar item lists for WINDOW
906 and its subwindows and siblings.
907 This has to be done before we start to fill in any display lines,
908 because it can call eval. */
909
910static void
911update_menu_bars (window)
912 Lisp_Object window;
913{
914 for (; !NILP (window); window = XWINDOW (window)->next)
0cc7bdb8 915 update_menu_bar (window);
90adcf20
RS
916}
917
918/* Update the menu bar item list for window WINDOW and its subwindows. */
919
920static void
0cc7bdb8 921update_menu_bar (window)
90adcf20 922 Lisp_Object window;
90adcf20
RS
923{
924 register struct window *w = XWINDOW (window);
925 struct buffer *old = current_buffer;
926 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
927
928 /* If this is a combination window, do its children; that's all. */
929
930 if (!NILP (w->vchild))
931 {
932 update_menu_bars (w->vchild);
933 return;
934 }
935 if (!NILP (w->hchild))
936 {
937 update_menu_bars (w->hchild);
938 return;
939 }
940 if (NILP (w->buffer))
941 abort ();
942
943 if (update_mode_lines)
944 w->update_mode_line = Qt;
945
946 /* When we reach a frame's selected window, redo the frame's menu bar. */
947 if (!NILP (w->update_mode_line)
78614721
FP
948#ifdef USE_X_TOOLKIT
949 && FRAME_EXTERNAL_MENU_BAR (f)
950#else
90adcf20 951 && FRAME_MENU_BAR_LINES (f) > 0
78614721 952#endif
90adcf20
RS
953 && EQ (FRAME_SELECTED_WINDOW (f), window))
954 {
955 /* If the user has switched buffers or windows, we need to
956 recompute to reflect the new bindings. But we'll
957 recompute when update_mode_lines is set too; that means
958 that people can use force-mode-line-update to request
959 that the menu bar be recomputed. The adverse effect on
960 the rest of the redisplay algorithm is about the same as
961 windows_or_buffers_changed anyway. */
962 if (windows_or_buffers_changed
963 || update_mode_lines
964 || (XFASTINT (w->last_modified) < MODIFF
965 && (XFASTINT (w->last_modified)
966 <= XBUFFER (w->buffer)->save_modified)))
967 {
968 struct buffer *prev = current_buffer;
969 current_buffer = XBUFFER (w->buffer);
8351baf2 970 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
90adcf20 971 current_buffer = prev;
76412d64
RS
972#ifdef USE_X_TOOLKIT
973 set_frame_menubar (f);
974#endif /* USE_X_TOOLKIT */
90adcf20
RS
975 }
976 }
977}
978\f
a2889657
JB
979int do_id = 1;
980
90adcf20
RS
981/* Redisplay WINDOW and its subwindows and siblings. */
982
a2889657
JB
983static void
984redisplay_windows (window)
985 Lisp_Object window;
986{
265a9e55 987 for (; !NILP (window); window = XWINDOW (window)->next)
a2889657
JB
988 redisplay_window (window, 0);
989}
990
90adcf20
RS
991/* Redisplay window WINDOW and its subwindows. */
992
a2889657
JB
993static void
994redisplay_window (window, just_this_one)
995 Lisp_Object window;
996 int just_this_one;
997{
998 register struct window *w = XWINDOW (window);
30c566e4 999 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
a2889657
JB
1000 int height;
1001 register int lpoint = point;
1002 struct buffer *old = current_buffer;
b1d1124b 1003 register int width = window_internal_width (w) - 1;
a2889657
JB
1004 register int startp;
1005 register int hscroll = XINT (w->hscroll);
1006 struct position pos;
b1d1124b 1007 int opoint = point;
a2889657
JB
1008 int tem;
1009 int window_needs_modeline;
1010
44fa5b1e 1011 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
a2889657
JB
1012
1013 /* If this is a combination window, do its children; that's all. */
1014
265a9e55 1015 if (!NILP (w->vchild))
a2889657
JB
1016 {
1017 redisplay_windows (w->vchild);
1018 return;
1019 }
265a9e55 1020 if (!NILP (w->hchild))
a2889657
JB
1021 {
1022 redisplay_windows (w->hchild);
1023 return;
1024 }
265a9e55 1025 if (NILP (w->buffer))
a2889657 1026 abort ();
8de2d90b
JB
1027
1028 height = window_internal_height (w);
1029
1030 if (MINI_WINDOW_P (w))
1031 {
1032 if (w == XWINDOW (minibuf_window))
1033 {
1034 if (echo_area_glyphs)
1035 /* We've already displayed the echo area glyphs, if any. */
88f22aff 1036 goto finish_scroll_bars;
8de2d90b
JB
1037 }
1038 else
1039 {
1040 /* This is a minibuffer, but it's not the currently active one, so
1041 clear it. */
44fa5b1e 1042 int vpos = XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top);
8de2d90b
JB
1043 int i;
1044
1045 for (i = 0; i < height; i++)
1046 {
44fa5b1e 1047 get_display_line (f, vpos + i, 0);
278feba9 1048 display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width);
8de2d90b
JB
1049 }
1050
88f22aff 1051 goto finish_scroll_bars;
8de2d90b
JB
1052 }
1053 }
a2889657
JB
1054
1055 if (update_mode_lines)
1056 w->update_mode_line = Qt;
1057
1058 /* Otherwise set up data on this window; select its buffer and point value */
1059
a2889657
JB
1060 current_buffer = XBUFFER (w->buffer);
1061 opoint = point;
1062
1063 /* Count number of windows showing the selected buffer. */
1064
1065 if (!just_this_one
1066 && current_buffer == XBUFFER (XWINDOW (selected_window)->buffer))
1067 buffer_shared++;
1068
1069 /* POINT refers normally to the selected window.
1070 For any other window, set up appropriate value. */
1071
1072 if (!EQ (window, selected_window))
1073 {
1074 SET_PT (marker_position (w->pointm));
1075 if (point < BEGV)
1076 {
265a9e55 1077 SET_PT (BEGV);
a2889657
JB
1078 Fset_marker (w->pointm, make_number (point), Qnil);
1079 }
1080 else if (point > (ZV - 1))
1081 {
265a9e55 1082 SET_PT (ZV);
a2889657
JB
1083 Fset_marker (w->pointm, make_number (point), Qnil);
1084 }
1085 }
1086
1087 /* If window-start is screwed up, choose a new one. */
a2889657
JB
1088 if (XMARKER (w->start)->buffer != current_buffer)
1089 goto recenter;
1090
1091 startp = marker_position (w->start);
1092
8de2d90b 1093 /* Handle case where place to start displaying has been specified,
aa6d10fa 1094 unless the specified location is outside the accessible range. */
265a9e55 1095 if (!NILP (w->force_start))
a2889657 1096 {
aa6d10fa
RS
1097 /* Forget any recorded base line for line number display. */
1098 w->base_line_number = Qnil;
a2889657
JB
1099 w->update_mode_line = Qt;
1100 w->force_start = Qnil;
1101 XFASTINT (w->last_modified) = 0;
8de2d90b
JB
1102 if (startp < BEGV) startp = BEGV;
1103 if (startp > ZV) startp = ZV;
a2889657
JB
1104 try_window (window, startp);
1105 if (cursor_vpos < 0)
1106 {
bd66d1ba 1107 /* ??? What should happen here if highlighting a region? */
a2889657
JB
1108 /* If point does not appear, move point so it does appear */
1109 pos = *compute_motion (startp, 0,
1110 ((EQ (window, minibuf_window) && startp == 1)
1111 ? minibuf_prompt_width : 0)
1112 +
1113 (hscroll ? 1 - hscroll : 0),
1114 ZV, height / 2,
1115 - (1 << (SHORTBITS - 1)),
1116 width, hscroll, pos_tab_offset (w, startp));
1117 SET_PT (pos.bufpos);
90adcf20 1118 if (w != XWINDOW (selected_window))
a2889657
JB
1119 Fset_marker (w->pointm, make_number (point), Qnil);
1120 else
1121 {
9d6a6bb9
RS
1122 if (current_buffer == old)
1123 lpoint = point;
44fa5b1e
JB
1124 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1125 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
a2889657
JB
1126 }
1127 }
1128 goto done;
1129 }
1130
1131 /* Handle case where text has not changed, only point,
44fa5b1e 1132 and it has not moved off the frame */
a2889657
JB
1133
1134 /* This code is not used for minibuffer for the sake of
1135 the case of redisplaying to replace an echo area message;
1136 since in that case the minibuffer contents per se are usually unchanged.
1137 This code is of no real use in the minibuffer since
1138 the handling of this_line_bufpos, etc.,
1139 in redisplay handles the same cases. */
1140
1141 if (XFASTINT (w->last_modified) >= MODIFF
1142 && point >= startp && !clip_changed
44fa5b1e 1143 && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f))
bd66d1ba
RS
1144 /* Can't use this case if highlighting a region. */
1145 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1146 && NILP (w->region_showing)
a2889657
JB
1147 && !EQ (window, minibuf_window))
1148 {
1149 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0),
1150 point, height + 1, 10000, width, hscroll,
1151 pos_tab_offset (w, startp));
1152
1153 if (pos.vpos < height)
1154 {
44fa5b1e
JB
1155 /* Ok, point is still on frame */
1156 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
a2889657
JB
1157 {
1158 /* These variables are supposed to be origin 1 */
44fa5b1e
JB
1159 FRAME_CURSOR_X (f) = max (0, pos.hpos) + XFASTINT (w->left);
1160 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
a2889657
JB
1161 }
1162 /* This doesn't do the trick, because if a window to the right of
1163 this one must be redisplayed, this does nothing because there
44fa5b1e 1164 is nothing in DesiredFrame yet, and then the other window is
a2889657 1165 redisplayed, making likes that are empty in this window's columns.
44fa5b1e 1166 if (XFASTINT (w->width) != FRAME_WIDTH (f))
a2889657
JB
1167 preserve_my_columns (w);
1168 */
1169 goto done;
1170 }
1171 /* Don't bother trying redisplay with same start;
1172 we already know it will lose */
1173 }
1174 /* If current starting point was originally the beginning of a line
1175 but no longer is, find a new starting point. */
265a9e55 1176 else if (!NILP (w->start_at_line_beg)
a2889657
JB
1177 && !(startp == BEGV
1178 || FETCH_CHAR (startp - 1) == '\n'))
1179 {
1180 goto recenter;
1181 }
1182 else if (just_this_one && !MINI_WINDOW_P (w)
1183 && point >= startp
1184 && XFASTINT (w->last_modified)
14709f21
JB
1185 /* or else vmotion on first line won't work. */
1186 && ! NILP (w->start_at_line_beg)
a2889657
JB
1187 && ! EQ (w->window_end_valid, Qnil)
1188 && do_id && !clip_changed
1189 && !blank_end_of_window
44fa5b1e 1190 && XFASTINT (w->width) == FRAME_WIDTH (f)
bd66d1ba
RS
1191 /* Can't use this case if highlighting a region. */
1192 && !(!NILP (Vtransient_mark_mode)
1193 && !NILP (current_buffer->mark_active))
1194 && NILP (w->region_showing)
a2889657
JB
1195 && EQ (last_arrow_position, Voverlay_arrow_position)
1196 && EQ (last_arrow_string, Voverlay_arrow_string)
44fa5b1e 1197 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
a2889657
JB
1198 && tem != -2)
1199 {
1200 /* tem > 0 means success. tem == -1 means choose new start.
1201 tem == -2 means try again with same start,
1202 and nothing but whitespace follows the changed stuff.
1203 tem == 0 means try again with same start. */
1204 if (tem > 0)
1205 goto done;
1206 }
1207 else if (startp >= BEGV && startp <= ZV
1208 /* Avoid starting display at end of buffer! */
8de2d90b 1209 && (startp < ZV || startp == BEGV
a2889657
JB
1210 || (XFASTINT (w->last_modified) >= MODIFF)))
1211 {
1212 /* Try to redisplay starting at same place as before */
44fa5b1e 1213 /* If point has not moved off frame, accept the results */
a2889657
JB
1214 try_window (window, startp);
1215 if (cursor_vpos >= 0)
aa6d10fa
RS
1216 {
1217 if (!just_this_one || clip_changed || beg_unchanged < startp)
1218 /* Forget any recorded base line for line number display. */
1219 w->base_line_number = Qnil;
1220 goto done;
1221 }
a2889657
JB
1222 else
1223 cancel_my_columns (w);
1224 }
1225
1226 XFASTINT (w->last_modified) = 0;
1227 w->update_mode_line = Qt;
1228
1229 /* Try to scroll by specified few lines */
1230
1231 if (scroll_step && !clip_changed)
1232 {
1233 if (point > startp)
1234 {
1235 pos = *vmotion (Z - XFASTINT (w->window_end_pos),
1236 scroll_step, width, hscroll, window);
1237 if (pos.vpos >= height)
1238 goto scroll_fail;
1239 }
1240
1241 pos = *vmotion (startp, point < startp ? - scroll_step : scroll_step,
1242 width, hscroll, window);
1243
1244 if (point >= pos.bufpos)
1245 {
1246 try_window (window, pos.bufpos);
1247 if (cursor_vpos >= 0)
aa6d10fa
RS
1248 {
1249 if (!just_this_one || clip_changed || beg_unchanged < startp)
1250 /* Forget any recorded base line for line number display. */
1251 w->base_line_number = Qnil;
1252 goto done;
1253 }
a2889657
JB
1254 else
1255 cancel_my_columns (w);
1256 }
1257 scroll_fail: ;
1258 }
1259
1260 /* Finally, just choose place to start which centers point */
1261
1262recenter:
aa6d10fa
RS
1263 /* Forget any previously recorded base line for line number display. */
1264 w->base_line_number = Qnil;
1265
484ab76a 1266 pos = *vmotion (point, - (height / 2), width, hscroll, window);
a2889657
JB
1267 try_window (window, pos.bufpos);
1268
1269 startp = marker_position (w->start);
1270 w->start_at_line_beg =
1271 (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
1272
1273done:
265a9e55 1274 if ((!NILP (w->update_mode_line)
aa6d10fa
RS
1275 /* If window not full width, must redo its mode line
1276 if the window to its side is being redone */
1277 || (!just_this_one && width < FRAME_WIDTH (f) - 1)
1278 || INTEGERP (w->base_line_pos))
a2889657
JB
1279 && height != XFASTINT (w->height))
1280 display_mode_line (w);
aa6d10fa
RS
1281 if (! line_number_displayed
1282 && ! BUFFERP (w->base_line_pos))
1283 {
1284 w->base_line_pos = Qnil;
1285 w->base_line_number = Qnil;
1286 }
a2889657 1287
7ce2c095
RS
1288 /* When we reach a frame's selected window, redo the frame's menu bar. */
1289 if (!NILP (w->update_mode_line)
76412d64
RS
1290#ifdef USE_X_TOOLKIT
1291 && FRAME_EXTERNAL_MENU_BAR (f)
1292#else
7ce2c095 1293 && FRAME_MENU_BAR_LINES (f) > 0
76412d64 1294#endif
7ce2c095
RS
1295 && EQ (FRAME_SELECTED_WINDOW (f), window))
1296 display_menu_bar (w);
1297
88f22aff
JB
1298 finish_scroll_bars:
1299 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
30c566e4 1300 {
b1d1124b 1301 int start, end, whole;
30c566e4 1302
b1d1124b 1303 /* Calculate the start and end positions for the current window.
3505ea70
JB
1304 At some point, it would be nice to choose between scrollbars
1305 which reflect the whole buffer size, with special markers
1306 indicating narrowing, and scrollbars which reflect only the
1307 visible region.
1308
b1d1124b
JB
1309 Note that minibuffers sometimes aren't displaying any text. */
1310 if (! MINI_WINDOW_P (w)
1311 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
1312 {
8a9311d7 1313 whole = ZV - BEGV;
6887f623 1314 start = startp - BEGV;
b1d1124b
JB
1315 /* I don't think this is guaranteed to be right. For the
1316 moment, we'll pretend it is. */
85f26be9 1317 end = (Z - XINT (w->window_end_pos)) - BEGV;
3505ea70
JB
1318
1319 if (end < start) end = start;
8a9311d7 1320 if (whole < (end - start)) whole = end - start;
b1d1124b
JB
1321 }
1322 else
1323 start = end = whole = 0;
30c566e4 1324
88f22aff 1325 /* Indicate what this scroll bar ought to be displaying now. */
7eb9ba41 1326 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
30c566e4 1327
88f22aff 1328 /* Note that we actually used the scroll bar attached to this window,
30c566e4 1329 so it shouldn't be deleted at the end of redisplay. */
88f22aff 1330 (*redeem_scroll_bar_hook) (w);
30c566e4 1331 }
b1d1124b
JB
1332
1333 SET_PT (opoint);
1334 current_buffer = old;
1335 SET_PT (lpoint);
a2889657
JB
1336}
1337\f
1338/* Do full redisplay on one window, starting at position `pos'. */
1339
1340static void
1341try_window (window, pos)
1342 Lisp_Object window;
1343 register int pos;
1344{
1345 register struct window *w = XWINDOW (window);
1346 register int height = window_internal_height (w);
1347 register int vpos = XFASTINT (w->top);
1348 register int last_text_vpos = vpos;
1349 int tab_offset = pos_tab_offset (w, pos);
44fa5b1e 1350 FRAME_PTR f = XFRAME (w->frame);
b1d1124b 1351 int width = window_internal_width (w) - 1;
a2889657
JB
1352 struct position val;
1353
1354 Fset_marker (w->start, make_number (pos), Qnil);
1355 cursor_vpos = -1;
1356 overlay_arrow_seen = 0;
1357 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
1358
1359 while (--height >= 0)
1360 {
1361 val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
1362 tab_offset += width;
1363 if (val.vpos) tab_offset = 0;
1364 vpos++;
1365 if (pos != val.bufpos)
1366 last_text_vpos
1367 /* Next line, unless prev line ended in end of buffer with no cr */
b0a0fbda 1368 = vpos - (val.vpos && (FETCH_CHAR (val.bufpos - 1) != '\n'
e885523c 1369#ifdef USE_TEXT_PROPERTIES
3ae8ced7 1370 || ! NILP (Fget_char_property (val.bufpos-1,
b0a0fbda 1371 Qinvisible,
3ae8ced7 1372 window))
e885523c
KH
1373#endif
1374 ));
a2889657
JB
1375 pos = val.bufpos;
1376 }
1377
1378 /* If last line is continued in middle of character,
44fa5b1e 1379 include the split character in the text considered on the frame */
a2889657
JB
1380 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
1381 pos++;
1382
44fa5b1e 1383 /* If bottom just moved off end of frame, change mode line percentage. */
a2889657
JB
1384 if (XFASTINT (w->window_end_pos) == 0
1385 && Z != pos)
1386 w->update_mode_line = Qt;
1387
44fa5b1e 1388 /* Say where last char on frame will be, once redisplay is finished. */
a2889657
JB
1389 XFASTINT (w->window_end_pos) = Z - pos;
1390 XFASTINT (w->window_end_vpos) = last_text_vpos - XFASTINT (w->top);
1391 /* But that is not valid info until redisplay finishes. */
1392 w->window_end_valid = Qnil;
1393}
1394\f
1395/* Try to redisplay when buffer is modified locally,
1396 computing insert/delete line to preserve text outside
1397 the bounds of the changes.
1398 Return 1 if successful, 0 if if cannot tell what to do,
1399 or -1 to tell caller to find a new window start,
1400 or -2 to tell caller to do normal redisplay with same window start. */
1401
1402static int
1403try_window_id (window)
1404 Lisp_Object window;
1405{
1406 int pos;
1407 register struct window *w = XWINDOW (window);
1408 register int height = window_internal_height (w);
44fa5b1e 1409 FRAME_PTR f = XFRAME (w->frame);
a2889657
JB
1410 int top = XFASTINT (w->top);
1411 int start = marker_position (w->start);
b1d1124b 1412 int width = window_internal_width (w) - 1;
a2889657
JB
1413 int hscroll = XINT (w->hscroll);
1414 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
1415 register int vpos;
1416 register int i, tem;
1417 int last_text_vpos = 0;
1418 int stop_vpos;
9f412332
KH
1419 int selective
1420 = XTYPE (current_buffer->selective_display) == Lisp_Int
1421 ? XINT (current_buffer->selective_display)
1422 : !NILP (current_buffer->selective_display) ? -1 : 0;
a2889657
JB
1423
1424 struct position val, bp, ep, xp, pp;
1425 int scroll_amount = 0;
1426 int delta;
1427 int tab_offset, epto;
1428
1429 if (GPT - BEG < beg_unchanged)
1430 beg_unchanged = GPT - BEG;
1431 if (Z - GPT < end_unchanged)
1432 end_unchanged = Z - GPT;
1433
6a1dc7ac 1434 if (beg_unchanged + BEG < start)
a2889657
JB
1435 return 0; /* Give up if changes go above top of window */
1436
1437 /* Find position before which nothing is changed. */
1438 bp = *compute_motion (start, 0, lmargin,
6a1dc7ac
KH
1439 min (ZV, beg_unchanged + BEG), height + 1, 0,
1440 width, hscroll, pos_tab_offset (w, start));
a2889657 1441 if (bp.vpos >= height)
6e8290aa
JB
1442 {
1443 if (point < bp.bufpos && !bp.contin)
1444 {
44fa5b1e
JB
1445 /* All changes are below the frame, and point is on the frame.
1446 We don't need to change the frame at all.
6e8290aa
JB
1447 But we need to update window_end_pos to account for
1448 any change in buffer size. */
f7be7f78
JB
1449 bp = *compute_motion (start, 0, lmargin,
1450 Z, height, 0,
1451 width, hscroll, pos_tab_offset (w, start));
6e8290aa
JB
1452 XFASTINT (w->window_end_vpos) = height;
1453 XFASTINT (w->window_end_pos) = Z - bp.bufpos;
1454 return 1;
1455 }
1456 return 0;
1457 }
a2889657
JB
1458
1459 vpos = bp.vpos;
1460
44fa5b1e 1461 /* Find beginning of that frame line. Must display from there. */
a2889657
JB
1462 bp = *vmotion (bp.bufpos, 0, width, hscroll, window);
1463
1464 pos = bp.bufpos;
1465 val.hpos = lmargin;
1466 if (pos < start)
1467 return -1;
1468
1469 /* If about to start displaying at the beginning of a continuation line,
44fa5b1e 1470 really start with previous frame line, in case it was not
a2889657 1471 continued when last redisplayed */
05ba02eb
JB
1472 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
1473 ||
1474 /* Likewise if we have to worry about selective display. */
9f412332 1475 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
a2889657
JB
1476 {
1477 bp = *vmotion (bp.bufpos, -1, width, hscroll, window);
1478 --vpos;
1479 pos = bp.bufpos;
1480 }
1481
1482 if (bp.contin && bp.hpos != lmargin)
1483 {
1484 val.hpos = bp.prevhpos - width + lmargin;
1485 pos--;
1486 }
1487
1488 bp.vpos = vpos;
1489
1490 /* Find first visible newline after which no more is changed. */
1491 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
9f412332
KH
1492 if (selective > 0)
1493 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
a2889657
JB
1494 tem = find_next_newline (tem, 1);
1495
1496 /* Compute the cursor position after that newline. */
1497 ep = *compute_motion (pos, vpos, val.hpos, tem,
1498 height, - (1 << (SHORTBITS - 1)),
1499 width, hscroll, pos_tab_offset (w, bp.bufpos));
1500
44fa5b1e
JB
1501 /* If changes reach past the text available on the frame,
1502 just display rest of frame. */
a2889657
JB
1503 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
1504 stop_vpos = height;
1505 else
1506 stop_vpos = ep.vpos;
1507
1508 /* If no newline before ep, the line ep is on includes some changes
1509 that must be displayed. Make sure we don't stop before it. */
1510 /* Also, if changes reach all the way until ep.bufpos,
1511 it is possible that something was deleted after the
1512 newline before it, so the following line must be redrawn. */
1513 if (stop_vpos == ep.vpos
1514 && (ep.bufpos == BEGV
1515 || FETCH_CHAR (ep.bufpos - 1) != '\n'
1516 || ep.bufpos == Z - end_unchanged))
1517 stop_vpos = ep.vpos + 1;
1518
1519 cursor_vpos = -1;
1520 overlay_arrow_seen = 0;
1521
1522 /* If changes do not reach to bottom of window,
1523 figure out how much to scroll the rest of the window */
1524 if (stop_vpos < height)
1525 {
1526 /* Now determine how far up or down the rest of the window has moved */
1527 epto = pos_tab_offset (w, ep.bufpos);
1528 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1529 Z - XFASTINT (w->window_end_pos),
1530 10000, 0, width, hscroll, epto);
1531 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
1532
44fa5b1e 1533 /* Is everything on frame below the changes whitespace?
a2889657
JB
1534 If so, no scrolling is really necessary. */
1535 for (i = ep.bufpos; i < xp.bufpos; i++)
1536 {
1537 tem = FETCH_CHAR (i);
1538 if (tem != ' ' && tem != '\n' && tem != '\t')
1539 break;
1540 }
1541 if (i == xp.bufpos)
1542 return -2;
1543
1544 XFASTINT (w->window_end_vpos) += scroll_amount;
1545
44fa5b1e 1546 /* Before doing any scrolling, verify that point will be on frame. */
a2889657
JB
1547 if (point > ep.bufpos && !(point <= xp.bufpos && xp.bufpos < height))
1548 {
1549 if (point <= xp.bufpos)
1550 {
1551 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
1552 point, height, - (1 << (SHORTBITS - 1)),
1553 width, hscroll, epto);
1554 }
1555 else
1556 {
1557 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos,
1558 point, height, - (1 << (SHORTBITS - 1)),
1559 width, hscroll, pos_tab_offset (w, xp.bufpos));
1560 }
1561 if (pp.bufpos < point || pp.vpos == height)
1562 return 0;
1563 cursor_vpos = pp.vpos + top;
1564 cursor_hpos = pp.hpos + XFASTINT (w->left);
1565 }
1566
1567 if (stop_vpos - scroll_amount >= height
1568 || ep.bufpos == xp.bufpos)
1569 {
1570 if (scroll_amount < 0)
1571 stop_vpos -= scroll_amount;
1572 scroll_amount = 0;
1573 /* In this path, we have altered window_end_vpos
1574 and not left it negative.
1575 We must make sure that, in case display is preempted
44fa5b1e 1576 before the frame changes to reflect what we do here,
a2889657 1577 further updates will not come to try_window_id
44fa5b1e 1578 and assume the frame and window_end_vpos match. */
a2889657
JB
1579 blank_end_of_window = 1;
1580 }
1581 else if (!scroll_amount)
1582 {}
1583 else if (bp.bufpos == Z - end_unchanged)
1584 {
1585 /* If reprinting everything is nearly as fast as scrolling,
1586 don't bother scrolling. Can happen if lines are short. */
44fa5b1e 1587 if (scroll_cost (f, bp.vpos + top - scroll_amount,
a2889657
JB
1588 top + height - max (0, scroll_amount),
1589 scroll_amount)
1590 > xp.bufpos - bp.bufpos - 20)
1591 /* Return "try normal display with same window-start."
1592 Too bad we can't prevent further scroll-thinking. */
1593 return -2;
1594 /* If pure deletion, scroll up as many lines as possible.
1595 In common case of killing a line, this can save the
1596 following line from being overwritten by scrolling
1597 and therefore having to be redrawn. */
44fa5b1e 1598 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
a2889657
JB
1599 top + height - max (0, scroll_amount),
1600 scroll_amount);
1601 if (!tem) stop_vpos = height;
1602 }
1603 else if (scroll_amount)
1604 {
1605 /* If reprinting everything is nearly as fast as scrolling,
1606 don't bother scrolling. Can happen if lines are short. */
1607 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
1608 overestimate of cost of reprinting, since xp.bufpos
1609 would end up below the bottom of the window. */
44fa5b1e 1610 if (scroll_cost (f, ep.vpos + top - scroll_amount,
a2889657
JB
1611 top + height - max (0, scroll_amount),
1612 scroll_amount)
1613 > xp.bufpos - ep.bufpos - 20)
1614 /* Return "try normal display with same window-start."
1615 Too bad we can't prevent further scroll-thinking. */
1616 return -2;
44fa5b1e 1617 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
a2889657
JB
1618 top + height - max (0, scroll_amount),
1619 scroll_amount);
1620 if (!tem) stop_vpos = height;
1621 }
1622 }
1623
1624 /* In any case, do not display past bottom of window */
1625 if (stop_vpos >= height)
1626 {
1627 stop_vpos = height;
1628 scroll_amount = 0;
1629 }
1630
1631 /* Handle case where pos is before w->start --
1632 can happen if part of line had been clipped and is not clipped now */
1633 if (vpos == 0 && pos < marker_position (w->start))
1634 Fset_marker (w->start, make_number (pos), Qnil);
1635
1636 /* Redisplay the lines where the text was changed */
1637 last_text_vpos = vpos;
1638 tab_offset = pos_tab_offset (w, pos);
1639 /* If we are starting display in mid-character, correct tab_offset
1640 to account for passing the line that that character really starts in. */
1641 if (val.hpos < lmargin)
1642 tab_offset += width;
1643 while (vpos < stop_vpos)
1644 {
1645 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
1646 tab_offset += width;
1647 if (val.vpos) tab_offset = 0;
1648 if (pos != val.bufpos)
1649 last_text_vpos
1650 /* Next line, unless prev line ended in end of buffer with no cr */
1651 = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
1652 pos = val.bufpos;
1653 }
1654
1655 /* There are two cases:
1656 1) we have displayed down to the bottom of the window
1657 2) we have scrolled lines below stop_vpos by scroll_amount */
1658
1659 if (vpos == height)
1660 {
1661 /* If last line is continued in middle of character,
44fa5b1e 1662 include the split character in the text considered on the frame */
a2889657
JB
1663 if (val.hpos < lmargin)
1664 val.bufpos++;
1665 XFASTINT (w->window_end_vpos) = last_text_vpos;
1666 XFASTINT (w->window_end_pos) = Z - val.bufpos;
1667 }
1668
1669 /* If scrolling made blank lines at window bottom,
1670 redisplay to fill those lines */
1671 if (scroll_amount < 0)
1672 {
1673 /* Don't consider these lines for general-purpose scrolling.
1674 That will save time in the scrolling computation. */
44fa5b1e 1675 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
a2889657
JB
1676 vpos = xp.vpos;
1677 pos = xp.bufpos;
1678 val.hpos = lmargin;
1679 if (pos == ZV)
1680 vpos = height + scroll_amount;
1681 else if (xp.contin && xp.hpos != lmargin)
1682 {
1683 val.hpos = xp.prevhpos - width + lmargin;
1684 pos--;
1685 }
1686
1687 blank_end_of_window = 1;
1688 tab_offset = pos_tab_offset (w, pos);
1689 /* If we are starting display in mid-character, correct tab_offset
1690 to account for passing the line that that character starts in. */
1691 if (val.hpos < lmargin)
1692 tab_offset += width;
1693
1694 while (vpos < height)
1695 {
1696 val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
1697 tab_offset += width;
1698 if (val.vpos) tab_offset = 0;
1699 pos = val.bufpos;
1700 }
1701
1702 /* Here is a case where display_text_line sets cursor_vpos wrong.
1703 Make it be fixed up, below. */
1704 if (xp.bufpos == ZV
1705 && xp.bufpos == point)
1706 cursor_vpos = -1;
1707 }
1708
44fa5b1e 1709 /* If bottom just moved off end of frame, change mode line percentage. */
a2889657
JB
1710 if (XFASTINT (w->window_end_pos) == 0
1711 && Z != val.bufpos)
1712 w->update_mode_line = Qt;
1713
1714 /* Attempt to adjust end-of-text positions to new bottom line */
1715 if (scroll_amount)
1716 {
1717 delta = height - xp.vpos;
1718 if (delta < 0
1719 || (delta > 0 && xp.bufpos <= ZV)
1720 || (delta == 0 && xp.hpos))
1721 {
1722 val = *vmotion (Z - XFASTINT (w->window_end_pos),
1723 delta, width, hscroll, window);
1724 XFASTINT (w->window_end_pos) = Z - val.bufpos;
1725 XFASTINT (w->window_end_vpos) += val.vpos;
1726 }
1727 }
1728
1729 w->window_end_valid = Qnil;
1730
1731 /* If point was not in a line that was displayed, find it */
1732 if (cursor_vpos < 0)
1733 {
1734 val = *compute_motion (start, 0, lmargin, point, 10000, 10000,
1735 width, hscroll, pos_tab_offset (w, start));
44fa5b1e 1736 /* Admit failure if point is off frame now */
a2889657
JB
1737 if (val.vpos >= height)
1738 {
1739 for (vpos = 0; vpos < height; vpos++)
44fa5b1e 1740 cancel_line (vpos + top, f);
a2889657
JB
1741 return 0;
1742 }
1743 cursor_vpos = val.vpos + top;
1744 cursor_hpos = val.hpos + XFASTINT (w->left);
1745 }
1746
44fa5b1e
JB
1747 FRAME_CURSOR_X (f) = max (0, cursor_hpos);
1748 FRAME_CURSOR_Y (f) = cursor_vpos;
a2889657
JB
1749
1750 if (debug_end_pos)
1751 {
1752 val = *compute_motion (start, 0, lmargin, ZV,
1753 height, - (1 << (SHORTBITS - 1)),
1754 width, hscroll, pos_tab_offset (w, start));
1755 if (val.vpos != XFASTINT (w->window_end_vpos))
1756 abort ();
1757 if (XFASTINT (w->window_end_pos)
1758 != Z - val.bufpos)
1759 abort ();
1760 }
1761
1762 return 1;
1763}
1764\f
31b24551
JB
1765/* Mark a section of BUF as modified, but only for the sake of redisplay.
1766 This is useful for recording changes to overlays.
1767
1768 We increment the buffer's modification timestamp and set the
1769 redisplay caches (windows_or_buffers_changed, beg_unchanged, etc)
1770 as if the region of text between START and END had been modified;
1771 the redisplay code will check this against the windows' timestamps,
1772 and redraw the appropriate area of the buffer.
1773
1774 However, if the buffer is unmodified, we bump the last-save
1775 timestamp as well, so that incrementing the timestamp doesn't fool
1776 Emacs into thinking that the buffer's text has been modified.
1777
1778 Tweaking the timestamps shouldn't hurt the first-modification
1779 timestamps recorded in the undo records; those values aren't
1780 written until just before a real text modification is made, so they
1781 will never catch the timestamp value just before this function gets
1782 called. */
1783
1784void
1785redisplay_region (buf, start, end)
1786 struct buffer *buf;
1787 int start, end;
1788{
1789 if (start == end)
1790 return;
1791
1792 if (start > end)
1793 {
1794 int temp = start;
1795 start = end; end = temp;
1796 }
1797
1798 if (buf != current_buffer)
1799 windows_or_buffers_changed = 1;
1800 else
1801 {
1802 if (unchanged_modified == MODIFF)
1803 {
1804 beg_unchanged = start - BEG;
1805 end_unchanged = Z - end;
1806 }
1807 else
1808 {
1809 if (Z - end < end_unchanged)
1810 end_unchanged = Z - end;
1811 if (start - BEG < beg_unchanged)
1812 beg_unchanged = start - BEG;
1813 }
1814 }
1815
1816 /* Increment the buffer's time stamp, but also increment the save
1817 and autosave timestamps, so as not to screw up that timekeeping. */
1818 if (BUF_MODIFF (buf) == buf->save_modified)
1819 buf->save_modified++;
1820 if (BUF_MODIFF (buf) == buf->auto_save_modified)
1821 buf->auto_save_modified++;
1822
1823 BUF_MODIFF (buf) ++;
1824}
1825
1826\f
278feba9 1827/* Copy LEN glyphs starting address FROM to the rope TO.
f7430cb6 1828 But don't actually copy the parts that would come in before S.
278feba9
RS
1829 Value is TO, advanced past the copied data.
1830 F is the frame we are displaying in. */
a2889657 1831
278feba9
RS
1832static GLYPH *
1833copy_part_of_rope (f, to, s, from, len, face)
1834 FRAME_PTR f;
1835 register GLYPH *to; /* Copy to here. */
a2889657 1836 register GLYPH *s; /* Starting point. */
278feba9
RS
1837 Lisp_Object *from; /* Data to copy. */
1838 int len;
1c2250c2 1839 int face; /* Face to apply to glyphs which don't specify one. */
a2889657 1840{
278feba9
RS
1841 int n = len;
1842 register Lisp_Object *fp = from;
1843 /* These cache the results of the last call to compute_glyph_face. */
1844 int last_code = -1;
1845 int last_merged = 0;
c581d710 1846
4cdc65eb
KH
1847#ifdef HAVE_X_WINDOWS
1848 if (! FRAME_TERMCAP_P (f))
1849 while (n--)
1850 {
1851 int glyph = XFASTINT (*fp);
1852 int facecode;
1853
1854 if (FAST_GLYPH_FACE (glyph) == 0)
1855 /* If GLYPH has no face code, use FACE. */
1856 facecode = face;
1857 else if (FAST_GLYPH_FACE (glyph) == last_code)
1858 /* If it's same as previous glyph, use same result. */
1859 facecode = last_merged;
1860 else
1861 {
1862 /* Merge this glyph's face and remember the result. */
1863 last_code = FAST_GLYPH_FACE (glyph);
1864 last_merged = facecode = compute_glyph_face (f, last_code, face);
1865 }
b2a76982 1866
4cdc65eb
KH
1867 if (to >= s)
1868 *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode);
1869 ++to;
1870 ++fp;
1871 }
1872 else
1873#endif
1874 while (n--)
1875 {
1876 if (to >= s) *to = XFASTINT (*fp);
1877 ++to;
1878 ++fp;
1879 }
278feba9 1880 return to;
c581d710
RS
1881}
1882
278feba9
RS
1883/* Correct a glyph by replacing its specified user-level face code
1884 with a displayable computed face code. */
c581d710 1885
278feba9
RS
1886static GLYPH
1887fix_glyph (f, glyph, current_face)
1888 FRAME_PTR f;
1889 GLYPH glyph;
1890 int current_face;
c581d710 1891{
4cdc65eb
KH
1892#ifdef HAVE_X_WINDOWS
1893 if (! FRAME_TERMCAP_P (f) && FAST_GLYPH_FACE (glyph) != 0)
1894 return FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph),
1895 compute_glyph_face (f, FAST_GLYPH_FACE (glyph),
1896 current_face));
1897#endif
1898 return glyph;
a2889657
JB
1899}
1900\f
1901/* Display one line of window w, starting at position START in W's buffer.
1902 Display starting at horizontal position HPOS, which is normally zero
1903 or negative. A negative value causes output up to hpos = 0 to be discarded.
1904 This is done for negative hscroll, or when this is a continuation line
1905 and the continuation occurred in the middle of a multi-column character.
1906
1907 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
1908
44fa5b1e 1909 Display on position VPOS on the frame. (origin 0).
a2889657
JB
1910
1911 Returns a STRUCT POSITION giving character to start next line with
1912 and where to display it, including a zero or negative hpos.
1913 The vpos field is not really a vpos; it is 1 unless the line is continued */
1914
1915struct position val_display_text_line;
1916
1917static struct position *
1918display_text_line (w, start, vpos, hpos, taboffset)
1919 struct window *w;
1920 int start;
1921 int vpos;
1922 int hpos;
1923 int taboffset;
1924{
1925 register int pos = start;
1926 register int c;
1927 register GLYPH *p1;
1928 int end;
1929 register int pause;
1930 register unsigned char *p;
1931 GLYPH *endp;
1932 register GLYPH *startp;
5fcbb24d 1933 register GLYPH *p1prev = 0;
efc63ef0
RS
1934 register GLYPH *p1start;
1935 int *charstart;
44fa5b1e 1936 FRAME_PTR f = XFRAME (w->frame);
a2889657 1937 int tab_width = XINT (current_buffer->tab_width);
265a9e55 1938 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
b1d1124b 1939 int width = window_internal_width (w) - 1;
a2889657
JB
1940 struct position val;
1941 int lastpos;
1942 int invis;
1943 int hscroll = XINT (w->hscroll);
1944 int truncate = hscroll
1945 || (truncate_partial_width_windows
44fa5b1e 1946 && XFASTINT (w->width) < FRAME_WIDTH (f))
265a9e55 1947 || !NILP (current_buffer->truncate_lines);
bd66d1ba
RS
1948
1949 /* 1 if we should highlight the region. */
1950 int highlight_region
1951 = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active);
1952 int region_beg, region_end;
1953
a2889657
JB
1954 int selective
1955 = XTYPE (current_buffer->selective_display) == Lisp_Int
1956 ? XINT (current_buffer->selective_display)
265a9e55 1957 : !NILP (current_buffer->selective_display) ? -1 : 0;
44fa5b1e 1958 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
a2889657 1959 register struct Lisp_Vector *dp = window_display_table (w);
68a37fa8
RS
1960
1961 Lisp_Object default_invis_vector[3];
1962 /* Nonzero means display something where there are invisible lines.
1963 The precise value is the number of glyphs to display. */
a2889657 1964 int selective_rlen
c581d710 1965 = (selective && dp && XTYPE (DISP_INVIS_VECTOR (dp)) == Lisp_Vector
68a37fa8
RS
1966 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
1967 : selective && !NILP (current_buffer->selective_display_ellipses)
1968 ? 3 : 0);
1969 /* This is the sequence of Lisp objects to display
1970 when there are invisible lines. */
1971 Lisp_Object *invis_vector_contents
1972 = (dp && XTYPE (DISP_INVIS_VECTOR (dp)) == Lisp_Vector
1973 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
1974 : default_invis_vector);
1975
a2889657 1976 GLYPH truncator = (dp == 0 || XTYPE (DISP_TRUNC_GLYPH (dp)) != Lisp_Int
278feba9 1977 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
a2889657 1978 GLYPH continuer = (dp == 0 || XTYPE (DISP_CONTINUE_GLYPH (dp)) != Lisp_Int
278feba9 1979 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
a2889657 1980
31b24551
JB
1981 /* The next buffer location at which the face should change, due
1982 to overlays or text property changes. */
1983 int next_face_change;
1984
b0a0fbda
RS
1985#ifdef USE_TEXT_PROPERTIES
1986 /* The next location where the `invisible' property changes */
1987 int next_invisible;
b0a0fbda
RS
1988#endif
1989
31b24551 1990 /* The face we're currently using. */
1c2250c2 1991 int current_face = 0;
efc63ef0 1992 int i;
31b24551 1993
68a37fa8
RS
1994 XFASTINT (default_invis_vector[2]) = '.';
1995 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
1996
a2889657 1997 hpos += XFASTINT (w->left);
44fa5b1e 1998 get_display_line (f, vpos, XFASTINT (w->left));
54ff581a 1999 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
a2889657 2000
bd66d1ba 2001 /* Show where to highlight the region. */
1613b757 2002 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
fba9ce76
RS
2003 /* Maybe highlight only in selected window. */
2004 && (highlight_nonselected_windows
6f139a45 2005 || w == XWINDOW (selected_window)))
bd66d1ba
RS
2006 {
2007 region_beg = marker_position (current_buffer->mark);
2008 if (PT < region_beg)
2009 {
2010 region_end = region_beg;
2011 region_beg = PT;
2012 }
2013 else
2014 region_end = PT;
2015 w->region_showing = Qt;
2016 }
2017 else
2018 region_beg = region_end = -1;
2019
a2889657
JB
2020 if (MINI_WINDOW_P (w) && start == 1
2021 && vpos == XFASTINT (w->top))
2022 {
2023 if (minibuf_prompt)
90adcf20 2024 hpos = display_string (w, vpos, minibuf_prompt, -1, hpos,
a2889657 2025 (!truncate ? continuer : truncator),
278feba9 2026 1, -1, -1);
a2889657
JB
2027 minibuf_prompt_width = hpos;
2028 }
2029
2030 desired_glyphs->bufp[vpos] = pos;
2031 p1 = desired_glyphs->glyphs[vpos] + hpos;
efc63ef0
RS
2032 p1start = p1;
2033 charstart = desired_glyphs->charstarts[vpos] + hpos;
2034 /* In case we don't ever write anything into it... */
2035 *charstart = -1;
a2889657
JB
2036 end = ZV;
2037 startp = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
2038 endp = startp + width;
2039
1c2250c2
JB
2040 /* Arrange the overlays nicely for our purposes. Usually, we call
2041 display_text_line on only one line at a time, in which case this
2042 can't really hurt too much, or we call it on lines which appear
2043 one after another in the buffer, in which case all calls to
2044 recenter_overlay_lists but the first will be pretty cheap. */
2045 recenter_overlay_lists (current_buffer, pos);
2046
a2889657
JB
2047 /* Loop generating characters.
2048 Stop at end of buffer, before newline,
31b24551
JB
2049 if reach or pass continuation column,
2050 or at face change. */
a2889657 2051 pause = pos;
31b24551 2052 next_face_change = pos;
b0a0fbda
RS
2053#ifdef USE_TEXT_PROPERTIES
2054 next_invisible = pos;
2055#endif
a2889657
JB
2056 while (p1 < endp)
2057 {
efc63ef0
RS
2058 /* Record which glyph starts a character,
2059 and the character position of that character. */
2060 charstart[p1 - p1start] = pos;
2061
a2889657 2062 p1prev = p1;
31b24551 2063 if (pos >= pause)
a2889657 2064 {
31b24551
JB
2065 /* Did we hit the end of the visible region of the buffer?
2066 Stop here. */
2067 if (pos >= end)
a2889657 2068 break;
31b24551
JB
2069
2070 /* Did we reach point? Record the cursor location. */
a2889657
JB
2071 if (pos == point && cursor_vpos < 0)
2072 {
2073 cursor_vpos = vpos;
2074 cursor_hpos = p1 - startp;
2075 }
2076
b0a0fbda
RS
2077#ifdef USE_TEXT_PROPERTIES
2078 /* if the `invisible' property is set to t, we can skip to
2079 the next property change */
2080 while (pos == next_invisible && pos < end)
b0a0fbda 2081 {
3ae8ced7 2082 Lisp_Object position, limit, endpos, prop, ww;
dfabd9a0 2083 XFASTINT (position) = pos;
3ae8ced7
KH
2084 XSET (ww, Lisp_Window, w);
2085 prop = Fget_char_property (position, Qinvisible, ww);
dfabd9a0
RS
2086 /* This is just an estimate to give reasonable
2087 performance; nothing should go wrong if it is too small. */
fe3d6921
KH
2088 limit = Fnext_overlay_change (position);
2089 if (XFASTINT (limit) > pos + 50)
2090 XFASTINT (limit) = pos + 50;
2091 endpos = Fnext_single_property_change (position, Qinvisible,
dfabd9a0
RS
2092 Fcurrent_buffer (), limit);
2093 if (INTEGERP (endpos))
2094 next_invisible = XINT (endpos);
2095 else
2096 next_invisible = end;
2097 if (! NILP (prop))
2098 {
2099 if (pos < point && next_invisible >= point)
2100 {
2101 cursor_vpos = vpos;
2102 cursor_hpos = p1 - startp;
2103 }
2104 pos = next_invisible;
2105 }
b0a0fbda 2106 }
b0a0fbda
RS
2107 if (pos >= end)
2108 break;
2109#endif
2110
9dbd4b48 2111#ifdef HAVE_X_WINDOWS
31b24551
JB
2112 /* Did we hit a face change? Figure out what face we should
2113 use now. We also hit this the first time through the
2114 loop, to see what face we should start with. */
b0a0fbda 2115 if (pos >= next_face_change && FRAME_X_P (f))
bd66d1ba
RS
2116 current_face = compute_char_face (f, w, pos,
2117 region_beg, region_end,
efc63ef0 2118 &next_face_change, pos + 50, 0);
9dbd4b48 2119#endif
31b24551 2120
1c2250c2
JB
2121 pause = end;
2122
b0a0fbda
RS
2123#ifdef USE_TEXT_PROPERTIES
2124 if (pos < next_invisible && next_invisible < pause)
2125 pause = next_invisible;
2126#endif
1c2250c2
JB
2127 if (pos < next_face_change && next_face_change < pause)
2128 pause = next_face_change;
2129
31b24551
JB
2130 /* Wouldn't you hate to read the next line to someone over
2131 the phone? */
a2889657
JB
2132 if (pos < point && point < pause)
2133 pause = point;
2134 if (pos < GPT && GPT < pause)
2135 pause = GPT;
2136
2137 p = &FETCH_CHAR (pos);
2138 }
2139 c = *p++;
2140 if (c >= 040 && c < 0177
c581d710 2141 && (dp == 0 || XTYPE (DISP_CHAR_VECTOR (dp, c)) != Lisp_Vector))
a2889657
JB
2142 {
2143 if (p1 >= startp)
4cdc65eb 2144 *p1 = MAKE_GLYPH (f, c, current_face);
a2889657
JB
2145 p1++;
2146 }
2147 else if (c == '\n')
2148 {
2149 invis = 0;
2150 while (pos < end
2151 && selective > 0
9f412332 2152 && indented_beyond_p (pos + 1, selective))
a2889657
JB
2153 {
2154 invis = 1;
2155 pos = find_next_newline (pos + 1, 1);
2156 if (FETCH_CHAR (pos - 1) == '\n')
2157 pos--;
2158 }
2159 if (invis && selective_rlen > 0 && p1 >= startp)
2160 {
2161 p1 += selective_rlen;
2162 if (p1 - startp > width)
2163 p1 = endp;
278feba9 2164 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
1c2250c2 2165 (p1 - p1prev), current_face);
a2889657 2166 }
4cdc65eb 2167#ifdef HAVE_X_WINDOWS
3c5c35c5
JB
2168 /* Draw the face of the newline character as extending all the
2169 way to the end of the frame line. */
2170 if (current_face)
2171 while (p1 < endp)
4cdc65eb 2172 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
3c5c35c5 2173#endif
68a37fa8 2174 break;
a2889657
JB
2175 }
2176 else if (c == '\t')
2177 {
2178 do
2179 {
2180 if (p1 >= startp && p1 < endp)
4cdc65eb 2181 *p1 = MAKE_GLYPH (f, ' ', current_face);
a2889657
JB
2182 p1++;
2183 }
2184 while ((p1 - startp + taboffset + hscroll - (hscroll > 0))
2185 % tab_width);
2186 }
6e8290aa 2187 else if (c == Ctl ('M') && selective == -1)
a2889657
JB
2188 {
2189 pos = find_next_newline (pos, 1);
2190 if (FETCH_CHAR (pos - 1) == '\n')
2191 pos--;
2192 if (selective_rlen > 0)
2193 {
2194 p1 += selective_rlen;
2195 if (p1 - startp > width)
2196 p1 = endp;
278feba9 2197 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
1c2250c2 2198 (p1 - p1prev), current_face);
a2889657 2199 }
4cdc65eb 2200#ifdef HAVE_X_WINDOWS
3c5c35c5
JB
2201 /* Draw the face of the newline character as extending all the
2202 way to the end of the frame line. */
2203 if (current_face)
2204 while (p1 < endp)
4cdc65eb 2205 *p1++ = FAST_MAKE_GLYPH (' ', current_face);
3c5c35c5 2206#endif
68a37fa8 2207 break;
a2889657 2208 }
c581d710 2209 else if (dp != 0 && XTYPE (DISP_CHAR_VECTOR (dp, c)) == Lisp_Vector)
a2889657 2210 {
278feba9
RS
2211 p1 = copy_part_of_rope (f, p1, startp,
2212 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
2213 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
2214 current_face);
a2889657
JB
2215 }
2216 else if (c < 0200 && ctl_arrow)
2217 {
2218 if (p1 >= startp)
278feba9
RS
2219 *p1 = fix_glyph (f, (dp && XTYPE (DISP_CTRL_GLYPH (dp)) == Lisp_Int
2220 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
2221 current_face);
a2889657 2222 p1++;
6e8290aa 2223 if (p1 >= startp && p1 < endp)
4cdc65eb 2224 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face);
a2889657
JB
2225 p1++;
2226 }
2227 else
2228 {
2229 if (p1 >= startp)
278feba9
RS
2230 *p1 = fix_glyph (f, (dp && XTYPE (DISP_ESCAPE_GLYPH (dp)) == Lisp_Int
2231 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
2232 current_face);
a2889657 2233 p1++;
6e8290aa 2234 if (p1 >= startp && p1 < endp)
4cdc65eb 2235 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face);
a2889657 2236 p1++;
6e8290aa 2237 if (p1 >= startp && p1 < endp)
4cdc65eb 2238 *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face);
a2889657 2239 p1++;
6e8290aa 2240 if (p1 >= startp && p1 < endp)
4cdc65eb 2241 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face);
a2889657
JB
2242 p1++;
2243 }
31b24551 2244
efc63ef0
RS
2245 /* For all the glyphs occupied by this character, except for the
2246 first, store -1 in charstarts. */
2247 if (p1 != p1prev)
2248 {
2249 int *p2x = &charstart[p1prev - p1start] + 1;
2250 int *p2 = &charstart[p1 - p1start];
2251 while (p2x != p2)
2252 *p2x++ = -1;
2253 }
2254 else
2255 /* If this character took up no space,
2256 erase all mention of it from charstart. */
2257 charstart[p1 - p1start] = 0;
a2889657
JB
2258 pos++;
2259 }
2260
2261 val.hpos = - XINT (w->hscroll);
2262 if (val.hpos)
2263 val.hpos++;
2264
2265 val.vpos = 1;
2266
2267 lastpos = pos;
2268
efc63ef0
RS
2269 /* Store 0 in this charstart line for the positions where
2270 there is no character. But do leave what was recorded
2271 for the character that ended the line. */
2272 for (i = p1 - p1start + 1; i < endp - p1start; i++)
2273 charstart[i] = 0;
2274
a2889657
JB
2275 /* Handle continuation in middle of a character */
2276 /* by backing up over it */
2277 if (p1 > endp)
2278 {
5fcbb24d
JB
2279 /* Don't back up if we never actually displayed any text.
2280 This occurs when the minibuffer prompt takes up the whole line. */
2281 if (p1prev)
2282 {
2283 /* Start the next line with that same character */
2284 pos--;
2285 /* but at negative hpos, to skip the columns output on this line. */
2286 val.hpos += p1prev - endp;
2287 }
2288
a2889657
JB
2289 /* Keep in this line everything up to the continuation column. */
2290 p1 = endp;
2291 }
2292
2293 /* Finish deciding which character to start the next line on,
2294 and what hpos to start it at.
2295 Also set `lastpos' to the last position which counts as "on this line"
2296 for cursor-positioning. */
2297
2298 if (pos < ZV)
2299 {
2300 if (FETCH_CHAR (pos) == '\n')
dd5f6267
KH
2301 {
2302 /* If stopped due to a newline, start next line after it */
2303 pos++;
2304 /* Check again for hidden lines, in case the newline occurred exactly
2305 at the right margin. */
2306 while (pos < ZV && selective > 0
2307 && indented_beyond_p (pos, selective))
2308 pos = find_next_newline (pos, 1);
2309 }
a2889657
JB
2310 else
2311 /* Stopped due to right margin of window */
2312 {
2313 if (truncate)
2314 {
278feba9 2315 *p1++ = fix_glyph (f, truncator, 0);
a2889657
JB
2316 /* Truncating => start next line after next newline,
2317 and point is on this line if it is before the newline,
2318 and skip none of first char of next line */
dd5f6267
KH
2319 do
2320 pos = find_next_newline (pos, 1);
2321 while (pos < ZV && selective > 0
2322 && indented_beyond_p (pos, selective));
a2889657
JB
2323 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2324
2325 lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
2326 }
2327 else
2328 {
278feba9 2329 *p1++ = fix_glyph (f, continuer, 0);
a2889657
JB
2330 val.vpos = 0;
2331 lastpos--;
2332 }
2333 }
2334 }
2335
2336 /* If point is at eol or in invisible text at eol,
44fa5b1e 2337 record its frame location now. */
a2889657
JB
2338
2339 if (start <= point && point <= lastpos && cursor_vpos < 0)
2340 {
2341 cursor_vpos = vpos;
2342 cursor_hpos = p1 - startp;
2343 }
2344
2345 if (cursor_vpos == vpos)
2346 {
2347 if (cursor_hpos < 0) cursor_hpos = 0;
2348 if (cursor_hpos > width) cursor_hpos = width;
2349 cursor_hpos += XFASTINT (w->left);
44fa5b1e 2350 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
a2889657 2351 {
44fa5b1e
JB
2352 FRAME_CURSOR_Y (f) = cursor_vpos;
2353 FRAME_CURSOR_X (f) = cursor_hpos;
a2889657
JB
2354
2355 if (w == XWINDOW (selected_window))
2356 {
2357 /* Line is not continued and did not start
2358 in middle of character */
2359 if ((hpos - XFASTINT (w->left)
2360 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2361 && val.vpos)
2362 {
2363 this_line_bufpos = start;
2364 this_line_buffer = current_buffer;
2365 this_line_vpos = cursor_vpos;
2366 this_line_start_hpos = hpos;
2367 this_line_endpos = Z - lastpos;
2368 }
2369 else
2370 this_line_bufpos = 0;
2371 }
2372 }
2373 }
2374
2375 /* If hscroll and line not empty, insert truncation-at-left marker */
2376 if (hscroll && lastpos != start)
2377 {
278feba9 2378 *startp = fix_glyph (f, truncator, 0);
a2889657
JB
2379 if (p1 <= startp)
2380 p1 = startp + 1;
2381 }
2382
44fa5b1e 2383 if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f))
a2889657
JB
2384 {
2385 endp++;
2386 if (p1 < startp) p1 = startp;
2387 while (p1 < endp) *p1++ = SPACEGLYPH;
b1d1124b 2388
88f22aff
JB
2389 /* Don't draw vertical bars if we're using scroll bars. They're
2390 covered up by the scroll bars, and it's distracting to see
2391 them when the scroll bar windows are flickering around to be
b1d1124b 2392 reconfigured. */
88f22aff 2393 *p1++ = (FRAME_HAS_VERTICAL_SCROLL_BARS (f)
b1d1124b 2394 ? ' ' : '|');
a2889657
JB
2395 }
2396 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
2397 p1 - desired_glyphs->glyphs[vpos]);
2398 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
2399
2400 /* If the start of this line is the overlay arrow-position,
2401 then put the arrow string into the display-line. */
2402
2403 if (XTYPE (Voverlay_arrow_position) == Lisp_Marker
2404 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
2405 && start == marker_position (Voverlay_arrow_position)
2406 && XTYPE (Voverlay_arrow_string) == Lisp_String
2407 && ! overlay_arrow_seen)
2408 {
2409 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
2410 int i;
2411 int len = XSTRING (Voverlay_arrow_string)->size;
142be3dd 2412 int arrow_end;
a2889657 2413
b1d1124b
JB
2414 if (len > width)
2415 len = width;
a2889657
JB
2416 for (i = 0; i < len; i++)
2417 startp[i] = p[i];
142be3dd
JB
2418
2419 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
2420 arrow_end = (startp - desired_glyphs->glyphs[vpos]) + len;
2421 if (desired_glyphs->used[vpos] < arrow_end)
2422 desired_glyphs->used[vpos] = arrow_end;
a2889657
JB
2423
2424 overlay_arrow_seen = 1;
2425 }
2426
2427 val.bufpos = pos;
2428 val_display_text_line = val;
2429 return &val_display_text_line;
2430}
2431\f
7ce2c095
RS
2432/* Redisplay the menu bar in the frame for window W. */
2433
2434static void
2435display_menu_bar (w)
2436 struct window *w;
2437{
2438 Lisp_Object items, tail;
2439 register int vpos = 0;
2440 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2441 int maxendcol = FRAME_WIDTH (f);
2442 int hpos = 0;
8351baf2 2443 int i;
7ce2c095 2444
76412d64 2445#ifndef USE_X_TOOLKIT
7ce2c095
RS
2446 if (FRAME_MENU_BAR_LINES (f) <= 0)
2447 return;
2448
2449 get_display_line (f, vpos, 0);
2450
8351baf2
RS
2451 items = FRAME_MENU_BAR_ITEMS (f);
2452 for (i = 0; i < XVECTOR (items)->size; i += 3)
7ce2c095 2453 {
8351baf2
RS
2454 Lisp_Object pos, string;
2455 string = XVECTOR (items)->contents[i + 1];
2456 if (NILP (string))
2457 break;
2d66ad19 2458
8351baf2 2459 XFASTINT (XVECTOR (items)->contents[i + 2]) = hpos;
7ce2c095
RS
2460
2461 if (hpos < maxendcol)
2462 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
2463 XSTRING (string)->data,
90adcf20 2464 XSTRING (string)->size,
278feba9 2465 hpos, 0, 0, hpos, maxendcol);
2d66ad19
RS
2466 /* Put a gap of 3 spaces between items. */
2467 if (hpos < maxendcol)
2468 {
2469 int hpos1 = hpos + 3;
278feba9 2470 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
2d66ad19
RS
2471 min (hpos1, maxendcol), maxendcol);
2472 }
7ce2c095
RS
2473 }
2474
2475 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
2476 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
2d66ad19
RS
2477
2478 /* Fill out the line with spaces. */
2479 if (maxendcol > hpos)
278feba9 2480 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
db6f348c
JB
2481
2482 /* Clear the rest of the lines allocated to the menu bar. */
2483 vpos++;
2484 while (vpos < FRAME_MENU_BAR_LINES (f))
2485 get_display_line (f, vpos++, 0);
76412d64 2486#endif /* not USE_X_TOOLKIT */
7ce2c095
RS
2487}
2488\f
a2889657
JB
2489/* Display the mode line for window w */
2490
2491static void
2492display_mode_line (w)
2493 struct window *w;
2494{
2495 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
2496 register int left = XFASTINT (w->left);
2497 register int right = XFASTINT (w->width) + left;
44fa5b1e 2498 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
a2889657 2499
aa6d10fa
RS
2500 line_number_displayed = 0;
2501
44fa5b1e 2502 get_display_line (f, vpos, left);
a2889657
JB
2503 display_mode_element (w, vpos, left, 0, right, right,
2504 current_buffer->mode_line_format);
44fa5b1e 2505 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
a2889657
JB
2506
2507 /* Make the mode line inverse video if the entire line
2508 is made of mode lines.
2509 I.e. if this window is full width,
2510 or if it is the child of a full width window
2511 (which implies that that window is split side-by-side
2512 and the rest of this line is mode lines of the sibling windows). */
44fa5b1e
JB
2513 if (XFASTINT (w->width) == FRAME_WIDTH (f)
2514 || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f))
2515 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
4cdc65eb 2516#ifdef HAVE_X_WINDOWS
d7eb09a0
RS
2517 else if (! FRAME_TERMCAP_P (f))
2518 {
2519 /* For a partial width window, explicitly set face of each glyph. */
2520 int i;
2521 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
2522 for (i = left; i < right; ++i)
4cdc65eb 2523 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1);
d7eb09a0 2524 }
4cdc65eb 2525#endif
a2889657
JB
2526
2527#ifdef HAVE_X_WINDOWS
96a410bc
KH
2528 if (w == XWINDOW (f->selected_window))
2529 x_consider_frame_title (WINDOW_FRAME (w));
a2889657
JB
2530#endif
2531}
2532
2533/* Contribute ELT to the mode line for window W.
2534 How it translates into text depends on its data type.
2535
2536 VPOS is the position of the mode line being displayed.
2537
44fa5b1e 2538 HPOS is the position (absolute on frame) where this element's text
a2889657
JB
2539 should start. The output is truncated automatically at the right
2540 edge of window W.
2541
2542 DEPTH is the depth in recursion. It is used to prevent
2543 infinite recursion here.
2544
2545 MINENDCOL is the hpos before which the element may not end.
2546 The element is padded at the right with spaces if nec
2547 to reach this column.
2548
2549 MAXENDCOL is the hpos past which this element may not extend.
2550 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
2551 (This is necessary to make nested padding and truncation work.)
2552
2553 Returns the hpos of the end of the text generated by ELT.
2554 The next element will receive that value as its HPOS arg,
2555 so as to concatenate the elements. */
2556
2557static int
2558display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
2559 struct window *w;
2560 register int vpos, hpos;
2561 int depth;
2562 int minendcol;
2563 register int maxendcol;
2564 register Lisp_Object elt;
2565{
2566 tail_recurse:
2567 if (depth > 10)
2568 goto invalid;
2569
2570 depth++;
2571
2572#ifdef SWITCH_ENUM_BUG
2573 switch ((int) XTYPE (elt))
2574#else
2575 switch (XTYPE (elt))
2576#endif
2577 {
2578 case Lisp_String:
2579 {
2580 /* A string: output it and check for %-constructs within it. */
2581 register unsigned char c;
2582 register unsigned char *this = XSTRING (elt)->data;
2583
2584 while (hpos < maxendcol && *this)
2585 {
2586 unsigned char *last = this;
2587 while ((c = *this++) != '\0' && c != '%')
2588 ;
2589 if (this - 1 != last)
2590 {
2591 register int lim = --this - last + hpos;
278feba9
RS
2592 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
2593 hpos, min (lim, maxendcol));
a2889657
JB
2594 }
2595 else /* c == '%' */
2596 {
2597 register int spec_width = 0;
2598
2599 /* We can't allow -ve args due to the "%-" construct */
2600 /* Argument specifies minwidth but not maxwidth
2601 (maxwidth can be specified by
2602 (<negative-number> . <stuff>) mode-line elements) */
2603
2604 while ((c = *this++) >= '0' && c <= '9')
2605 {
2606 spec_width = spec_width * 10 + (c - '0');
2607 }
2608
2609 spec_width += hpos;
2610 if (spec_width > maxendcol)
2611 spec_width = maxendcol;
2612
2613 if (c == 'M')
2614 hpos = display_mode_element (w, vpos, hpos, depth,
2615 spec_width, maxendcol,
2616 Vglobal_mode_string);
2617 else if (c != 0)
2618 hpos = display_string (w, vpos,
2619 decode_mode_spec (w, c,
2620 maxendcol - hpos),
90adcf20 2621 -1,
278feba9 2622 hpos, 0, 1, spec_width, maxendcol);
a2889657
JB
2623 }
2624 }
2625 }
2626 break;
2627
2628 case Lisp_Symbol:
2629 /* A symbol: process the value of the symbol recursively
2630 as if it appeared here directly. Avoid error if symbol void.
2631 Special case: if value of symbol is a string, output the string
2632 literally. */
2633 {
2634 register Lisp_Object tem;
2635 tem = Fboundp (elt);
265a9e55 2636 if (!NILP (tem))
a2889657
JB
2637 {
2638 tem = Fsymbol_value (elt);
2639 /* If value is a string, output that string literally:
2640 don't check for % within it. */
2641 if (XTYPE (tem) == Lisp_String)
2642 hpos = display_string (w, vpos, XSTRING (tem)->data,
90adcf20 2643 XSTRING (tem)->size,
278feba9 2644 hpos, 0, 1, minendcol, maxendcol);
a2889657
JB
2645 /* Give up right away for nil or t. */
2646 else if (!EQ (tem, elt))
2647 { elt = tem; goto tail_recurse; }
2648 }
2649 }
2650 break;
2651
2652 case Lisp_Cons:
2653 {
2654 register Lisp_Object car, tem;
2655
2656 /* A cons cell: three distinct cases.
2657 If first element is a string or a cons, process all the elements
2658 and effectively concatenate them.
2659 If first element is a negative number, truncate displaying cdr to
2660 at most that many characters. If positive, pad (with spaces)
2661 to at least that many characters.
2662 If first element is a symbol, process the cadr or caddr recursively
2663 according to whether the symbol's value is non-nil or nil. */
2664 car = XCONS (elt)->car;
2665 if (XTYPE (car) == Lisp_Symbol)
2666 {
2667 tem = Fboundp (car);
2668 elt = XCONS (elt)->cdr;
2669 if (XTYPE (elt) != Lisp_Cons)
2670 goto invalid;
2671 /* elt is now the cdr, and we know it is a cons cell.
2672 Use its car if CAR has a non-nil value. */
265a9e55 2673 if (!NILP (tem))
a2889657
JB
2674 {
2675 tem = Fsymbol_value (car);
265a9e55 2676 if (!NILP (tem))
a2889657
JB
2677 { elt = XCONS (elt)->car; goto tail_recurse; }
2678 }
2679 /* Symbol's value is nil (or symbol is unbound)
2680 Get the cddr of the original list
2681 and if possible find the caddr and use that. */
2682 elt = XCONS (elt)->cdr;
265a9e55 2683 if (NILP (elt))
a2889657
JB
2684 break;
2685 else if (XTYPE (elt) != Lisp_Cons)
2686 goto invalid;
2687 elt = XCONS (elt)->car;
2688 goto tail_recurse;
2689 }
2690 else if (XTYPE (car) == Lisp_Int)
2691 {
2692 register int lim = XINT (car);
2693 elt = XCONS (elt)->cdr;
2694 if (lim < 0)
2695 /* Negative int means reduce maximum width.
2696 DO NOT change MINENDCOL here!
2697 (20 -10 . foo) should truncate foo to 10 col
2698 and then pad to 20. */
2699 maxendcol = min (maxendcol, hpos - lim);
2700 else if (lim > 0)
2701 {
2702 /* Padding specified. Don't let it be more than
2703 current maximum. */
2704 lim += hpos;
2705 if (lim > maxendcol)
2706 lim = maxendcol;
2707 /* If that's more padding than already wanted, queue it.
2708 But don't reduce padding already specified even if
2709 that is beyond the current truncation point. */
2710 if (lim > minendcol)
2711 minendcol = lim;
2712 }
2713 goto tail_recurse;
2714 }
2715 else if (XTYPE (car) == Lisp_String || XTYPE (car) == Lisp_Cons)
2716 {
2717 register int limit = 50;
2718 /* LIMIT is to protect against circular lists. */
2719 while (XTYPE (elt) == Lisp_Cons && --limit > 0
2720 && hpos < maxendcol)
2721 {
2722 hpos = display_mode_element (w, vpos, hpos, depth,
2723 hpos, maxendcol,
2724 XCONS (elt)->car);
2725 elt = XCONS (elt)->cdr;
2726 }
2727 }
2728 }
2729 break;
2730
2731 default:
2732 invalid:
278feba9 2733 return (display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
a2889657
JB
2734 minendcol, maxendcol));
2735 }
2736
2737 end:
2738 if (minendcol > hpos)
278feba9 2739 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
a2889657
JB
2740 return hpos;
2741}
2742\f
2743/* Return a string for the output of a mode line %-spec for window W,
2744 generated by character C and width MAXWIDTH. */
2745
11e82b76
JB
2746static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
2747
a2889657
JB
2748static char *
2749decode_mode_spec (w, c, maxwidth)
2750 struct window *w;
2751 register char c;
2752 register int maxwidth;
2753{
0b67772d 2754 Lisp_Object obj;
44fa5b1e
JB
2755 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2756 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
a2889657 2757
0b67772d 2758 obj = Qnil;
44fa5b1e
JB
2759 if (maxwidth > FRAME_WIDTH (f))
2760 maxwidth = FRAME_WIDTH (f);
a2889657
JB
2761
2762 switch (c)
2763 {
2764 case 'b':
2765 obj = current_buffer->name;
2766#if 0
2767 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
2768 {
2769 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
2770 decode_mode_spec_buf[maxwidth - 1] = '\\';
2771 decode_mode_spec_buf[maxwidth] = '\0';
2772 return decode_mode_spec_buf;
2773 }
2774#endif
2775 break;
2776
2777 case 'f':
2778 obj = current_buffer->filename;
2779#if 0
265a9e55 2780 if (NILP (obj))
a2889657
JB
2781 return "[none]";
2782 else if (XTYPE (obj) == Lisp_String && XSTRING (obj)->size > maxwidth)
2783 {
2784 bcopy ("...", decode_mode_spec_buf, 3);
2785 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
2786 decode_mode_spec_buf + 3, maxwidth - 3);
2787 return decode_mode_spec_buf;
2788 }
2789#endif
2790 break;
2791
aa6d10fa
RS
2792 case 'l':
2793 {
2794 int startpos = marker_position (w->start);
2795 int line, linepos, topline;
2796 int nlines, junk;
2797 Lisp_Object tem;
2798 int height = XFASTINT (w->height);
2799
2800 /* If we decided that this buffer isn't suitable for line numbers,
2801 don't forget that too fast. */
2802 if (EQ (w->base_line_pos, w->buffer))
2803 return "??";
2804
2805 /* If the buffer is very big, don't waste time. */
2806 if (ZV - BEGV > line_number_display_limit)
2807 {
2808 w->base_line_pos = Qnil;
2809 w->base_line_number = Qnil;
2810 return "??";
2811 }
2812
2813 if (!NILP (w->base_line_number)
2814 && !NILP (w->base_line_pos)
2815 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
2816 {
2817 line = XFASTINT (w->base_line_number);
2818 linepos = XFASTINT (w->base_line_pos);
2819 }
2820 else
2821 {
2822 line = 1;
2823 linepos = BEGV;
2824 }
2825
2826 /* Count lines from base line to window start position. */
2827 nlines = display_count_lines (linepos, startpos, startpos, &junk);
2828
2829 topline = nlines + line;
2830
2831 /* Determine a new base line, if the old one is too close
2832 or too far away, or if we did not have one.
2833 "Too close" means it's plausible a scroll-down would
2834 go back past it. */
2835 if (startpos == BEGV)
2836 {
2837 XFASTINT (w->base_line_number) = topline;
2838 XFASTINT (w->base_line_pos) = BEGV;
2839 }
2840 else if (nlines < height + 25 || nlines > height * 3 + 50
2841 || linepos == BEGV)
2842 {
2843 int limit = BEGV;
2844 int position;
2845 int distance = (height * 2 + 30) * 200;
2846
2847 if (startpos - distance > limit)
2848 limit = startpos - distance;
2849
2850 nlines = display_count_lines (startpos, limit,
2851 -(height * 2 + 30),
2852 &position);
2853 /* If we couldn't find the lines we wanted within
2854 200 chars per line,
2855 give up on line numbers for this window. */
2856 if (position == startpos - distance)
2857 {
2858 w->base_line_pos = w->buffer;
2859 w->base_line_number = Qnil;
2860 return "??";
2861 }
2862
2863 XFASTINT (w->base_line_number) = topline - nlines;
2864 XFASTINT (w->base_line_pos) = position;
2865 }
2866
2867 /* Now count lines from the start pos to point. */
2868 nlines = display_count_lines (startpos, PT, PT, &junk);
2869
2870 /* Record that we did display the line number. */
2871 line_number_displayed = 1;
2872
2873 /* Make the string to show. */
2874 sprintf (decode_mode_spec_buf, "%d", topline + nlines);
2875 return decode_mode_spec_buf;
2876 }
2877 break;
2878
a2889657
JB
2879 case 'm':
2880 obj = current_buffer->mode_name;
2881 break;
2882
2883 case 'n':
2884 if (BEGV > BEG || ZV < Z)
2885 return " Narrow";
2886 break;
2887
2888 case '*':
265a9e55 2889 if (!NILP (current_buffer->read_only))
a2889657
JB
2890 return "%";
2891 if (MODIFF > current_buffer->save_modified)
2892 return "*";
2893 return "-";
2894
5cc9f80d
RS
2895 case '+':
2896 if (MODIFF > current_buffer->save_modified)
2897 return "*";
2898 return "-";
2899
a2889657
JB
2900 case 's':
2901 /* status of process */
a2889657 2902 obj = Fget_buffer_process (Fcurrent_buffer ());
265a9e55 2903 if (NILP (obj))
a2889657 2904 return "no process";
76412d64 2905#ifdef subprocesses
a2889657 2906 obj = Fsymbol_name (Fprocess_status (obj));
76412d64 2907#endif
a2889657 2908 break;
a2889657 2909
76412d64
RS
2910 case 't': /* indicate TEXT or BINARY */
2911#ifdef MSDOS
2912 decode_mode_spec_buf[0]
2913 = NILP (current_buffer->buffer_file_type) ? "T" : "B";
2914 decode_mode_spec_buf[1] = 0;
2915 return decode_mode_spec_buf;
2916#else /* not MSDOS */
2917 return "T";
2918#endif /* not MSDOS */
2919
a2889657
JB
2920 case 'p':
2921 {
2922 int pos = marker_position (w->start);
2923 int total = ZV - BEGV;
2924
2925 if (XFASTINT (w->window_end_pos) <= Z - ZV)
2926 {
2927 if (pos <= BEGV)
2928 return "All";
2929 else
2930 return "Bottom";
2931 }
2932 else if (pos <= BEGV)
2933 return "Top";
2934 else
2935 {
2936 total = ((pos - BEGV) * 100 + total - 1) / total;
2937 /* We can't normally display a 3-digit number,
2938 so get us a 2-digit number that is close. */
2939 if (total == 100)
2940 total = 99;
2941 sprintf (decode_mode_spec_buf, "%2d%%", total);
2942 return decode_mode_spec_buf;
2943 }
2944 }
2945
8ffcb79f
RS
2946 /* Display percentage of size above the bottom of the screen. */
2947 case 'P':
2948 {
2949 int toppos = marker_position (w->start);
2950 int botpos = Z - XFASTINT (w->window_end_pos);
2951 int total = ZV - BEGV;
2952
2953 if (botpos >= ZV)
2954 {
2955 if (toppos <= BEGV)
2956 return "All";
2957 else
2958 return "Bottom";
2959 }
2960 else
2961 {
2962 total = ((botpos - BEGV) * 100 + total - 1) / total;
2963 /* We can't normally display a 3-digit number,
2964 so get us a 2-digit number that is close. */
2965 if (total == 100)
2966 total = 99;
2967 if (toppos <= BEGV)
2968 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
2969 else
2970 sprintf (decode_mode_spec_buf, "%2d%%", total);
2971 return decode_mode_spec_buf;
2972 }
2973 }
2974
a2889657
JB
2975 case '%':
2976 return "%";
2977
2978 case '[':
2979 {
2980 int i;
2981 char *p;
2982
2983 if (command_loop_level > 5)
2984 return "[[[... ";
2985 p = decode_mode_spec_buf;
2986 for (i = 0; i < command_loop_level; i++)
2987 *p++ = '[';
2988 *p = 0;
2989 return decode_mode_spec_buf;
2990 }
2991
2992 case ']':
2993 {
2994 int i;
2995 char *p;
2996
2997 if (command_loop_level > 5)
2998 return " ...]]]";
2999 p = decode_mode_spec_buf;
3000 for (i = 0; i < command_loop_level; i++)
3001 *p++ = ']';
3002 *p = 0;
3003 return decode_mode_spec_buf;
3004 }
3005
3006 case '-':
3007 {
a2889657
JB
3008 register char *p;
3009 register int i;
3010
3011 if (maxwidth < sizeof (lots_of_dashes))
3012 return lots_of_dashes;
3013 else
3014 {
3015 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
3016 *p++ = '-';
3017 *p = '\0';
3018 }
3019 return decode_mode_spec_buf;
3020 }
3021 }
3022
3023 if (XTYPE (obj) == Lisp_String)
3024 return (char *) XSTRING (obj)->data;
3025 else
3026 return "";
3027}
aa6d10fa
RS
3028
3029/* Count up to N lines starting from FROM.
3030 But don't go beyond LIMIT.
3031 Return the number of lines thus found (always positive).
3032 Store the position after what was found into *POS_PTR. */
3033
3034static int
3035display_count_lines (from, limit, n, pos_ptr)
3036 int from, limit, n;
3037 int *pos_ptr;
3038{
3039 int oldbegv = BEGV;
3040 int oldzv = ZV;
3041 int shortage = 0;
3042
3043 if (limit < from)
3044 BEGV = limit;
3045 else
3046 ZV = limit;
3047
278feba9 3048 *pos_ptr = scan_buffer ('\n', from, n, &shortage, 0);
aa6d10fa
RS
3049
3050 ZV = oldzv;
3051 BEGV = oldbegv;
3052
3053 if (n < 0)
3054 /* When scanning backwards, scan_buffer stops *after* the last newline
3055 it finds, but does count it. Compensate for that. */
3056 return - n - shortage - (*pos_ptr != limit);
3057 return n - shortage;
3058}
a2889657
JB
3059\f
3060/* Display STRING on one line of window W, starting at HPOS.
3061 Display at position VPOS. Caller should have done get_display_line.
11e82b76 3062 If VPOS == -1, display it as the current frame's title.
90adcf20 3063 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
a2889657
JB
3064
3065 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
3066
3067 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
3068 MAXCOL is the last column ok to end at. Truncate here.
3069 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
44fa5b1e 3070 Both count from the left edge of the frame, as does HPOS.
a2889657
JB
3071 The right edge of W is an implicit maximum.
3072 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
3073
278feba9
RS
3074 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
3075 at the place where the current window ends in this line
3076 and not display anything beyond there. Otherwise, only MAXCOL
3077 controls where to stop output.
3078
3079 Returns ending hpos. */
a2889657
JB
3080
3081static int
278feba9
RS
3082display_string (w, vpos, string, length, hpos, truncate,
3083 obey_window_width, mincol, maxcol)
a2889657
JB
3084 struct window *w;
3085 unsigned char *string;
90adcf20 3086 int length;
a2889657
JB
3087 int vpos, hpos;
3088 GLYPH truncate;
278feba9 3089 int obey_window_width;
a2889657
JB
3090 int mincol, maxcol;
3091{
3092 register int c;
3093 register GLYPH *p1;
3094 int hscroll = XINT (w->hscroll);
253c7d2f 3095 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
a2889657
JB
3096 register GLYPH *start;
3097 register GLYPH *end;
b1d1124b
JB
3098 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3099 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
a2889657
JB
3100 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
3101 int window_width = XFASTINT (w->width);
3102
3103 /* Use the standard display table, not the window's display table.
3104 We don't want the mode line in rot13. */
3105 register struct Lisp_Vector *dp = 0;
efc63ef0 3106 int i;
a2889657
JB
3107
3108 if (XTYPE (Vstandard_display_table) == Lisp_Vector
3109 && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE)
3110 dp = XVECTOR (Vstandard_display_table);
3111
54ff581a 3112 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
a2889657
JB
3113
3114 p1 = p1start;
3115 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
a2889657 3116
278feba9 3117 if (obey_window_width)
b1d1124b 3118 {
278feba9
RS
3119 end = start + window_width - (truncate != 0);
3120
3121 if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f))
b1d1124b 3122 {
278feba9
RS
3123 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3124 {
3125 int i;
b1d1124b 3126
278feba9
RS
3127 for (i = 0; i < VERTICAL_SCROLL_BAR_WIDTH; i++)
3128 *end-- = ' ';
3129 }
3130 else
3131 *end-- = '|';
b1d1124b 3132 }
b1d1124b 3133 }
a2889657 3134
278feba9
RS
3135 if (! obey_window_width
3136 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
a2889657 3137 end = desired_glyphs->glyphs[vpos] + maxcol;
278feba9 3138
efc63ef0
RS
3139 /* Store 0 in charstart for these columns. */
3140 for (i = hpos; i < end - p1start + hpos; i++)
3141 desired_glyphs->charstarts[vpos][i] = 0;
3142
a2889657
JB
3143 if (maxcol >= 0 && mincol > maxcol)
3144 mincol = maxcol;
3145
3146 while (p1 < end)
3147 {
90adcf20
RS
3148 if (length == 0)
3149 break;
a2889657 3150 c = *string++;
90adcf20
RS
3151 /* Specified length. */
3152 if (length >= 0)
3153 length--;
3154 /* Unspecified length (null-terminated string). */
3155 else if (c == 0)
3156 break;
3157
a2889657 3158 if (c >= 040 && c < 0177
c581d710 3159 && (dp == 0 || XTYPE (DISP_CHAR_VECTOR (dp, c)) != Lisp_Vector))
a2889657
JB
3160 {
3161 if (p1 >= start)
3162 *p1 = c;
3163 p1++;
3164 }
3165 else if (c == '\t')
3166 {
3167 do
3168 {
3169 if (p1 >= start && p1 < end)
3170 *p1 = SPACEGLYPH;
3171 p1++;
3172 }
3173 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
3174 }
c581d710 3175 else if (dp != 0 && XTYPE (DISP_CHAR_VECTOR (dp, c)) == Lisp_Vector)
278feba9
RS
3176 {
3177 p1 = copy_part_of_rope (f, p1, start,
3178 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3179 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3180 0);
3181 }
ded34426 3182 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
a2889657
JB
3183 {
3184 if (p1 >= start)
278feba9
RS
3185 *p1 = fix_glyph (f, (dp && XTYPE (DISP_CTRL_GLYPH (dp)) == Lisp_Int
3186 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3187 0);
a2889657 3188 p1++;
6e8290aa 3189 if (p1 >= start && p1 < end)
a2889657
JB
3190 *p1 = c ^ 0100;
3191 p1++;
3192 }
3193 else
3194 {
3195 if (p1 >= start)
278feba9
RS
3196 *p1 = fix_glyph (f, (dp && XTYPE (DISP_ESCAPE_GLYPH (dp)) == Lisp_Int
3197 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3198 0);
a2889657 3199 p1++;
6e8290aa 3200 if (p1 >= start && p1 < end)
a2889657
JB
3201 *p1 = (c >> 6) + '0';
3202 p1++;
6e8290aa 3203 if (p1 >= start && p1 < end)
a2889657
JB
3204 *p1 = (7 & (c >> 3)) + '0';
3205 p1++;
6e8290aa 3206 if (p1 >= start && p1 < end)
a2889657
JB
3207 *p1 = (7 & c) + '0';
3208 p1++;
3209 }
3210 }
3211
90adcf20 3212 if (c && length > 0)
a2889657
JB
3213 {
3214 p1 = end;
278feba9 3215 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
a2889657
JB
3216 }
3217 else if (mincol >= 0)
3218 {
3219 end = desired_glyphs->glyphs[vpos] + mincol;
3220 while (p1 < end)
3221 *p1++ = SPACEGLYPH;
3222 }
3223
3224 {
3225 register int len = p1 - desired_glyphs->glyphs[vpos];
3226
3227 if (len > desired_glyphs->used[vpos])
3228 desired_glyphs->used[vpos] = len;
3229 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3230
3231 return len;
3232 }
3233}
3234\f
3235void
3236syms_of_xdisp ()
3237{
3238 staticpro (&last_arrow_position);
3239 staticpro (&last_arrow_string);
3240 last_arrow_position = Qnil;
3241 last_arrow_string = Qnil;
3242
3243 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
8c45d522 3244 "String (or mode line construct) included (normally) in `mode-line-format'.");
a2889657
JB
3245 Vglobal_mode_string = Qnil;
3246
3247 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
3248 "Marker for where to display an arrow on top of the buffer text.\n\
3249This must be the beginning of a line in order to work.\n\
3250See also `overlay-arrow-string'.");
3251 Voverlay_arrow_position = Qnil;
3252
3253 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
3254 "String to display as an arrow. See also `overlay-arrow-position'.");
3255 Voverlay_arrow_string = Qnil;
3256
3257 DEFVAR_INT ("scroll-step", &scroll_step,
3258 "*The number of lines to try scrolling a window by when point moves out.\n\
44fa5b1e
JB
3259If that fails to bring point back on frame, point is centered instead.\n\
3260If this is zero, point is always centered after it moves off frame.");
a2889657
JB
3261
3262 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
3263
3264 DEFVAR_BOOL ("truncate-partial-width-windows",
3265 &truncate_partial_width_windows,
44fa5b1e 3266 "*Non-nil means truncate lines in all windows less than full frame wide.");
a2889657
JB
3267 truncate_partial_width_windows = 1;
3268
3269 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
3270 "*Non-nil means use inverse video for the mode line.");
3271 mode_line_inverse_video = 1;
aa6d10fa
RS
3272
3273 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
3274 "*Maximum buffer size for which line number should be displayed.");
3275 line_number_display_limit = 1000000;
fba9ce76
RS
3276
3277 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
3278 "*Non-nil means highlight region even in nonselected windows.");
3279 highlight_nonselected_windows = 1;
a2889657
JB
3280}
3281
3282/* initialize the window system */
3283init_xdisp ()
3284{
3285 Lisp_Object root_window;
3286#ifndef COMPILER_REGISTER_BUG
3287 register
3288#endif /* COMPILER_REGISTER_BUG */
3289 struct window *mini_w;
3290
3291 this_line_bufpos = 0;
3292
3293 mini_w = XWINDOW (minibuf_window);
11e82b76 3294 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
a2889657
JB
3295
3296 echo_area_glyphs = 0;
3297 previous_echo_glyphs = 0;
3298
3299 if (!noninteractive)
3300 {
44fa5b1e 3301 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
a2889657 3302 XFASTINT (XWINDOW (root_window)->top) = 0;
44fa5b1e
JB
3303 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
3304 XFASTINT (mini_w->top) = FRAME_HEIGHT (f) - 1;
a2889657
JB
3305 set_window_height (minibuf_window, 1, 0);
3306
44fa5b1e
JB
3307 XFASTINT (XWINDOW (root_window)->width) = FRAME_WIDTH (f);
3308 XFASTINT (mini_w->width) = FRAME_WIDTH (f);
a2889657
JB
3309 }
3310}