]> code.delx.au - gnu-emacs/blob - src/xdisp.c
(Fcombine_after_change_execute): Fix Lisp_Object/integer confusion.
[gnu-emacs] / src / xdisp.c
1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21
22 #include <config.h>
23 #include <stdio.h>
24 /*#include <ctype.h>*/
25 #undef NULL
26 #include "lisp.h"
27 #include "frame.h"
28 #include "window.h"
29 #include "termchar.h"
30 #include "dispextern.h"
31 #include "buffer.h"
32 #include "charset.h"
33 #include "indent.h"
34 #include "commands.h"
35 #include "macros.h"
36 #include "disptab.h"
37 #include "termhooks.h"
38 #include "intervals.h"
39 #include "keyboard.h"
40 #include "coding.h"
41 #include "process.h"
42
43 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
44 extern void set_frame_menubar ();
45 extern int pending_menu_activation;
46 #endif
47
48 extern int interrupt_input;
49 extern int command_loop_level;
50
51 extern int minibuffer_auto_raise;
52
53 extern Lisp_Object Qface;
54
55 extern Lisp_Object Voverriding_local_map;
56 extern Lisp_Object Voverriding_local_map_menu_flag;
57
58 Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
59 Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
60 Lisp_Object Qredisplay_end_trigger_functions;
61
62 /* Nonzero means print newline to stdout before next minibuffer message. */
63
64 int noninteractive_need_newline;
65
66 /* Nonzero means print newline to message log before next message. */
67
68 static int message_log_need_newline;
69
70 #define min(a, b) ((a) < (b) ? (a) : (b))
71 #define max(a, b) ((a) > (b) ? (a) : (b))
72 #define minmax(floor, val, ceil) \
73 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
74
75 /* The buffer position of the first character appearing
76 entirely or partially on the current frame line.
77 Or zero, which disables the optimization for the current frame line. */
78 static int this_line_bufpos;
79
80 /* Number of characters past the end of this line,
81 including the terminating newline */
82 static int this_line_endpos;
83
84 /* The vertical position of this frame line. */
85 static int this_line_vpos;
86
87 /* Hpos value for start of display on this frame line.
88 Usually zero, but negative if first character really began
89 on previous line */
90 static int this_line_start_hpos;
91
92 /* Buffer that this_line variables are describing. */
93 static struct buffer *this_line_buffer;
94
95 /* Value of echo_area_glyphs when it was last acted on.
96 If this is nonzero, there is a message on the frame
97 in the minibuffer and it should be erased as soon
98 as it is no longer requested to appear. */
99 char *previous_echo_glyphs;
100
101 /* Nonzero means truncate lines in all windows less wide than the frame */
102 int truncate_partial_width_windows;
103
104 /* Nonzero means we have more than one non-minibuffer-only frame.
105 Not guaranteed to be accurate except while parsing frame-title-format. */
106 int multiple_frames;
107
108 Lisp_Object Vglobal_mode_string;
109
110 /* Marker for where to display an arrow on top of the buffer text. */
111 Lisp_Object Voverlay_arrow_position;
112
113 /* String to display for the arrow. */
114 Lisp_Object Voverlay_arrow_string;
115
116 /* Like mode-line-format, but for the titlebar on a visible frame. */
117 Lisp_Object Vframe_title_format;
118
119 /* Like mode-line-format, but for the titlebar on an iconified frame. */
120 Lisp_Object Vicon_title_format;
121
122 /* List of functions to call when a window's size changes. These
123 functions get one arg, a frame on which one or more windows' sizes
124 have changed. */
125 static Lisp_Object Vwindow_size_change_functions;
126
127 /* Values of those variables at last redisplay. */
128 static Lisp_Object last_arrow_position, last_arrow_string;
129
130 Lisp_Object Qmenu_bar_update_hook;
131
132 /* Nonzero if overlay arrow has been displayed once in this window. */
133 static int overlay_arrow_seen;
134
135 /* Nonzero if visible end of buffer has already been displayed once
136 in this window. (We need this variable in case there are overlay
137 strings that get displayed there.) */
138 static int zv_strings_seen;
139
140 /* Nonzero means highlight the region even in nonselected windows. */
141 static int highlight_nonselected_windows;
142
143 /* If cursor motion alone moves point off frame,
144 Try scrolling this many lines up or down if that will bring it back. */
145 static int scroll_step;
146
147 /* Non-0 means scroll just far enough to bring point back on the screen,
148 when appropriate. */
149 static int scroll_conservatively;
150
151 /* Recenter the window whenever point gets within this many lines
152 of the top or bottom of the window. */
153 int scroll_margin;
154
155 /* Nonzero if try_window_id has made blank lines at window bottom
156 since the last redisplay that paused */
157 static int blank_end_of_window;
158
159 /* Number of windows showing the buffer of the selected window
160 (or another buffer with the same base buffer).
161 keyboard.c refers to this. */
162 int buffer_shared;
163
164 /* display_text_line sets these to the frame position (origin 0) of point,
165 whether the window is selected or not.
166 Set one to -1 first to determine whether point was found afterwards. */
167
168 static int cursor_vpos;
169 static int cursor_hpos;
170
171 static int debug_end_pos;
172
173 /* Nonzero means display mode line highlighted */
174 int mode_line_inverse_video;
175
176 static void redisplay_internal ();
177 static int message_log_check_duplicate ();
178 static void echo_area_display ();
179 void mark_window_display_accurate ();
180 static void redisplay_windows ();
181 static void redisplay_window ();
182 static void update_menu_bar ();
183 static void try_window ();
184 static int try_window_id ();
185 static struct position *display_text_line ();
186 static void display_mode_line ();
187 static int display_mode_element ();
188 static char *decode_mode_spec ();
189 static int display_string ();
190 static void display_menu_bar ();
191 static int display_count_lines ();
192
193 /* Prompt to display in front of the minibuffer contents */
194 Lisp_Object minibuf_prompt;
195
196 /* Width in columns of current minibuffer prompt. */
197 int minibuf_prompt_width;
198
199 /* Message to display instead of minibuffer contents
200 This is what the functions error and message make,
201 and command echoing uses it as well.
202 It overrides the minibuf_prompt as well as the buffer. */
203 char *echo_area_glyphs;
204
205 /* This is the length of the message in echo_area_glyphs. */
206 int echo_area_glyphs_length;
207
208 /* This is the window where the echo area message was displayed.
209 It is always a minibuffer window, but it may not be the
210 same window currently active as a minibuffer. */
211 Lisp_Object echo_area_window;
212
213 /* true iff we should redraw the mode lines on the next redisplay */
214 int update_mode_lines;
215
216 /* Smallest number of characters before the gap
217 at any time since last redisplay that finished.
218 Valid for current buffer when try_window_id can be called. */
219 int beg_unchanged;
220
221 /* Smallest number of characters after the gap
222 at any time since last redisplay that finished.
223 Valid for current buffer when try_window_id can be called. */
224 int end_unchanged;
225
226 /* MODIFF as of last redisplay that finished;
227 if it matches MODIFF, and overlay_unchanged_modified
228 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
229 contain no useful information */
230 int unchanged_modified;
231
232 /* OVERLAY_MODIFF as of last redisplay that finished. */
233 int overlay_unchanged_modified;
234
235 /* Nonzero if window sizes or contents have changed
236 since last redisplay that finished */
237 int windows_or_buffers_changed;
238
239 /* Nonzero after display_mode_line if %l was used
240 and it displayed a line number. */
241 int line_number_displayed;
242
243 /* Maximum buffer size for which to display line numbers. */
244 static int line_number_display_limit;
245
246 /* Number of lines to keep in the message log buffer.
247 t means infinite. nil means don't log at all. */
248 Lisp_Object Vmessage_log_max;
249 \f
250 /* Output a newline in the *Messages* buffer if "needs" one. */
251
252 void
253 message_log_maybe_newline ()
254 {
255 if (message_log_need_newline)
256 message_dolog ("", 0, 1);
257 }
258
259
260 /* Add a string to the message log, optionally terminated with a newline.
261 This function calls low-level routines in order to bypass text property
262 hooks, etc. which might not be safe to run. */
263
264 void
265 message_dolog (m, len, nlflag)
266 char *m;
267 int len, nlflag;
268 {
269 if (!NILP (Vmessage_log_max))
270 {
271 struct buffer *oldbuf;
272 int oldpoint, oldbegv, oldzv;
273 int old_windows_or_buffers_changed = windows_or_buffers_changed;
274
275 oldbuf = current_buffer;
276 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
277 current_buffer->undo_list = Qt;
278 oldpoint = PT;
279 oldbegv = BEGV;
280 oldzv = ZV;
281 BEGV = BEG;
282 ZV = Z;
283 if (oldpoint == Z)
284 oldpoint += len + nlflag;
285 if (oldzv == Z)
286 oldzv += len + nlflag;
287 TEMP_SET_PT (Z);
288 if (len)
289 insert_1 (m, len, 1, 0);
290 if (nlflag)
291 {
292 int this_bol, prev_bol, dup;
293 insert_1 ("\n", 1, 1, 0);
294
295 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
296 if (this_bol > BEG)
297 {
298 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
299 dup = message_log_check_duplicate (prev_bol, this_bol);
300 if (dup)
301 {
302 if (oldpoint > prev_bol)
303 oldpoint -= min (this_bol, oldpoint) - prev_bol;
304 if (oldbegv > prev_bol)
305 oldbegv -= min (this_bol, oldbegv) - prev_bol;
306 if (oldzv > prev_bol)
307 oldzv -= min (this_bol, oldzv) - prev_bol;
308 del_range_1 (prev_bol, this_bol, 0);
309 if (dup > 1)
310 {
311 char dupstr[40];
312 int duplen;
313
314 /* If you change this format, don't forget to also
315 change message_log_check_duplicate. */
316 sprintf (dupstr, " [%d times]", dup);
317 duplen = strlen (dupstr);
318 TEMP_SET_PT (Z-1);
319 if (oldpoint == Z)
320 oldpoint += duplen;
321 if (oldzv == Z)
322 oldzv += duplen;
323 insert_1 (dupstr, duplen, 1, 0);
324 }
325 }
326 }
327
328 if (NATNUMP (Vmessage_log_max))
329 {
330 int pos = scan_buffer ('\n', Z, 0,
331 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
332 oldpoint -= min (pos, oldpoint) - BEG;
333 oldbegv -= min (pos, oldbegv) - BEG;
334 oldzv -= min (pos, oldzv) - BEG;
335 del_range_1 (BEG, pos, 0);
336 }
337 }
338 BEGV = oldbegv;
339 ZV = oldzv;
340 TEMP_SET_PT (oldpoint);
341 set_buffer_internal (oldbuf);
342 windows_or_buffers_changed = old_windows_or_buffers_changed;
343 message_log_need_newline = !nlflag;
344 }
345 }
346
347 /* We are at the end of the buffer after just having inserted a newline.
348 (Note: We depend on the fact we won't be crossing the gap.)
349 Check to see if the most recent message looks a lot like the previous one.
350 Return 0 if different, 1 if the new one should just replace it, or a
351 value N > 1 if we should also append " [N times]". */
352
353 static int
354 message_log_check_duplicate (prev_bol, this_bol)
355 int prev_bol, this_bol;
356 {
357 int i;
358 int len = Z - 1 - this_bol;
359 int seen_dots = 0;
360 unsigned char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
361 unsigned char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
362
363 for (i = 0; i < len; i++)
364 {
365 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
366 && p1[i] != '\n')
367 seen_dots = 1;
368 if (p1[i] != p2[i])
369 return seen_dots;
370 }
371 p1 += len;
372 if (*p1 == '\n')
373 return 2;
374 if (*p1++ == ' ' && *p1++ == '[')
375 {
376 int n = 0;
377 while (*p1 >= '0' && *p1 <= '9')
378 n = n * 10 + *p1++ - '0';
379 if (strncmp (p1, " times]\n", 8) == 0)
380 return n+1;
381 }
382 return 0;
383 }
384 \f
385 /* Display an echo area message M with a specified length of LEN chars.
386 The string may include null characters. If M is 0, clear out any
387 existing message, and let the minibuffer text show through.
388
389 The buffer M must continue to exist until after the echo area
390 gets cleared or some other message gets displayed there.
391
392 Do not pass text that is stored in a Lisp string.
393 Do not pass text in a buffer that was alloca'd. */
394
395 void
396 message2 (m, len)
397 char *m;
398 int len;
399 {
400 /* First flush out any partial line written with print. */
401 message_log_maybe_newline ();
402 if (m)
403 message_dolog (m, len, 1);
404 message2_nolog (m, len);
405 }
406
407
408 /* The non-logging counterpart of message2. */
409
410 void
411 message2_nolog (m, len)
412 char *m;
413 int len;
414 {
415 if (noninteractive)
416 {
417 if (noninteractive_need_newline)
418 putc ('\n', stderr);
419 noninteractive_need_newline = 0;
420 fwrite (m, len, 1, stderr);
421 if (cursor_in_echo_area == 0)
422 fprintf (stderr, "\n");
423 fflush (stderr);
424 }
425 /* A null message buffer means that the frame hasn't really been
426 initialized yet. Error messages get reported properly by
427 cmd_error, so this must be just an informative message; toss it. */
428 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
429 {
430 Lisp_Object mini_window;
431 FRAME_PTR f;
432
433 /* Get the frame containing the minibuffer
434 that the selected frame is using. */
435 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
436 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
437
438 FRAME_SAMPLE_VISIBILITY (f);
439 if (FRAME_VISIBLE_P (selected_frame)
440 && ! FRAME_VISIBLE_P (f))
441 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window)));
442
443 if (m)
444 {
445 echo_area_glyphs = m;
446 echo_area_glyphs_length = len;
447
448 if (minibuffer_auto_raise)
449 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window)));
450 }
451 else
452 echo_area_glyphs = previous_echo_glyphs = 0;
453
454 do_pending_window_change ();
455 echo_area_display ();
456 update_frame (f, 1, 1);
457 do_pending_window_change ();
458 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
459 (*frame_up_to_date_hook) (f);
460 }
461 }
462 \f
463 /* Display a null-terminated echo area message M. If M is 0, clear out any
464 existing message, and let the minibuffer text show through.
465
466 The buffer M must continue to exist until after the echo area
467 gets cleared or some other message gets displayed there.
468
469 Do not pass text that is stored in a Lisp string.
470 Do not pass text in a buffer that was alloca'd. */
471
472 void
473 message1 (m)
474 char *m;
475 {
476 message2 (m, (m ? strlen (m) : 0));
477 }
478
479 void
480 message1_nolog (m)
481 char *m;
482 {
483 message2_nolog (m, (m ? strlen (m) : 0));
484 }
485
486 /* Truncate what will be displayed in the echo area
487 the next time we display it--but don't redisplay it now. */
488
489 void
490 truncate_echo_area (len)
491 int len;
492 {
493 /* A null message buffer means that the frame hasn't really been
494 initialized yet. Error messages get reported properly by
495 cmd_error, so this must be just an informative message; toss it. */
496 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
497 echo_area_glyphs_length = len;
498 }
499
500 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
501 zero if being used by message. */
502 int message_buf_print;
503
504 /* Dump an informative message to the minibuf. If M is 0, clear out
505 any existing message, and let the minibuffer text show through. */
506
507 /* VARARGS 1 */
508 void
509 message (m, a1, a2, a3)
510 char *m;
511 EMACS_INT a1, a2, a3;
512 {
513 if (noninteractive)
514 {
515 if (m)
516 {
517 if (noninteractive_need_newline)
518 putc ('\n', stderr);
519 noninteractive_need_newline = 0;
520 fprintf (stderr, m, a1, a2, a3);
521 if (cursor_in_echo_area == 0)
522 fprintf (stderr, "\n");
523 fflush (stderr);
524 }
525 }
526 else if (INTERACTIVE)
527 {
528 /* The frame whose minibuffer we're going to display the message on.
529 It may be larger than the selected frame, so we need
530 to use its buffer, not the selected frame's buffer. */
531 Lisp_Object mini_window;
532 FRAME_PTR f;
533
534 /* Get the frame containing the minibuffer
535 that the selected frame is using. */
536 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
537 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
538
539 /* A null message buffer means that the frame hasn't really been
540 initialized yet. Error messages get reported properly by
541 cmd_error, so this must be just an informative message; toss it. */
542 if (FRAME_MESSAGE_BUF (f))
543 {
544 if (m)
545 {
546 int len;
547 #ifdef NO_ARG_ARRAY
548 EMACS_INT a[3];
549 a[0] = a1;
550 a[1] = a2;
551 a[2] = a3;
552
553 len = doprnt (FRAME_MESSAGE_BUF (f),
554 FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, a);
555 #else
556 len = doprnt (FRAME_MESSAGE_BUF (f),
557 FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, &a1);
558 #endif /* NO_ARG_ARRAY */
559
560 message2 (FRAME_MESSAGE_BUF (f), len);
561 }
562 else
563 message1 (0);
564
565 /* Print should start at the beginning of the message
566 buffer next time. */
567 message_buf_print = 0;
568 }
569 }
570 }
571
572 /* The non-logging version of message. */
573 void
574 message_nolog (m, a1, a2, a3)
575 char *m;
576 EMACS_INT a1, a2, a3;
577 {
578 Lisp_Object old_log_max;
579 old_log_max = Vmessage_log_max;
580 Vmessage_log_max = Qnil;
581 message (m, a1, a2, a3);
582 Vmessage_log_max = old_log_max;
583 }
584
585 void
586 update_echo_area ()
587 {
588 message2 (echo_area_glyphs, echo_area_glyphs_length);
589 }
590 \f
591 static void
592 echo_area_display ()
593 {
594 register int vpos;
595 FRAME_PTR f;
596 Lisp_Object mini_window;
597
598 /* Choose the minibuffer window for this display.
599 It is the minibuffer window used by the selected frame. */
600 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
601 /* This is the frame that window is in. */
602 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
603
604 if (! FRAME_VISIBLE_P (f))
605 return;
606
607 if (frame_garbaged)
608 {
609 redraw_garbaged_frames ();
610 frame_garbaged = 0;
611 }
612
613 if (echo_area_glyphs || minibuf_level == 0)
614 {
615 int i;
616
617 echo_area_window = mini_window;
618
619 vpos = XFASTINT (XWINDOW (mini_window)->top);
620 get_display_line (f, vpos, 0);
621
622 /* Make sure the columns that overlap a left-hand scroll bar
623 are always clear. */
624 for (i = 0; i < FRAME_LEFT_SCROLL_BAR_WIDTH (f); i++)
625 f->desired_glyphs->glyphs[vpos][i] = SPACEGLYPH;
626
627 display_string (XWINDOW (mini_window), vpos,
628 echo_area_glyphs ? echo_area_glyphs : "",
629 echo_area_glyphs ? echo_area_glyphs_length : -1,
630 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
631 0, 0, 0, FRAME_WIDTH (f));
632
633 #if 0 /* This just gets in the way. update_frame does the job. */
634 /* If desired cursor location is on this line, put it at end of text */
635 if (cursor_in_echo_area)
636 FRAME_CURSOR_Y (f) = vpos;
637 if (FRAME_CURSOR_Y (f) == vpos)
638 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
639 #endif
640
641 /* Fill the rest of the minibuffer window with blank lines. */
642 {
643 int i;
644
645 for (i = vpos + 1;
646 i < vpos + XFASTINT (XWINDOW (mini_window)->height); i++)
647 {
648 get_display_line (f, i, 0);
649 display_string (XWINDOW (mini_window), vpos,
650 "", 0,
651 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
652 0, 0, 0, FRAME_WIDTH (f));
653 }
654 }
655 }
656 else if (!EQ (mini_window, selected_window))
657 windows_or_buffers_changed++;
658
659 if (EQ (mini_window, selected_window))
660 this_line_bufpos = 0;
661
662 previous_echo_glyphs = echo_area_glyphs;
663 }
664 \f
665 /* Update frame titles. */
666
667 #ifdef HAVE_WINDOW_SYSTEM
668 static char frame_title_buf[512];
669 static char *frame_title_ptr;
670
671 static int
672 store_frame_title (str, mincol, maxcol)
673 char *str;
674 int mincol, maxcol;
675 {
676 char *limit;
677 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
678 maxcol = sizeof (frame_title_buf);
679 limit = &frame_title_buf[maxcol];
680 while (*str != '\0' && frame_title_ptr < limit)
681 *frame_title_ptr++ = *str++;
682 while (frame_title_ptr < &frame_title_buf[mincol])
683 *frame_title_ptr++ = ' ';
684 return frame_title_ptr - frame_title_buf;
685 }
686
687 static void
688 x_consider_frame_title (frame)
689 Lisp_Object frame;
690 {
691 Lisp_Object fmt;
692 struct buffer *obuf;
693 int len;
694 FRAME_PTR f = XFRAME (frame);
695
696 if (!(FRAME_WINDOW_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name))
697 return;
698
699 /* Do we have more than one visible frame on this X display? */
700 {
701 Lisp_Object tail;
702
703 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
704 {
705 FRAME_PTR tf = XFRAME (XCONS (tail)->car);
706
707 if (tf != f && FRAME_KBOARD (tf) == FRAME_KBOARD (f)
708 && !FRAME_MINIBUF_ONLY_P (tf)
709 && (FRAME_VISIBLE_P (tf) || FRAME_ICONIFIED_P (tf)))
710 break;
711 }
712
713 multiple_frames = CONSP (tail);
714 }
715
716 obuf = current_buffer;
717 Fset_buffer (XWINDOW (f->selected_window)->buffer);
718 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
719 frame_title_ptr = frame_title_buf;
720 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
721 0, sizeof (frame_title_buf), fmt);
722 frame_title_ptr = 0;
723 set_buffer_internal (obuf);
724 /* Set the name only if it's changed. This avoids consing
725 in the common case where it hasn't. (If it turns out that we've
726 already wasted too much time by walking through the list with
727 display_mode_element, then we might need to optimize at a higher
728 level than this.) */
729 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
730 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
731 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
732 }
733 #else
734 #define frame_title_ptr ((char *)0)
735 #define store_frame_title(str, mincol, maxcol) 0
736 #endif
737 \f
738 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
739 This can call eval. */
740
741 void
742 prepare_menu_bars ()
743 {
744 register struct window *w = XWINDOW (selected_window);
745 int all_windows;
746 struct gcpro gcpro1, gcpro2;
747
748 all_windows = (update_mode_lines || buffer_shared > 1
749 || windows_or_buffers_changed);
750
751 /* Update all frame titles based on their buffer names, etc.
752 We do this before the menu bars so that the buffer-menu
753 will show the up-to-date frame titles.
754
755 This used to be done after the menu bars, for a reason that
756 was stated as follows but which I do not understand:
757 "We do this after the menu bars so that the frame will first
758 create its menu bar using the name `emacs' if no other name
759 has yet been specified."
760 I think that is no longer a concern. */
761 #ifdef HAVE_WINDOW_SYSTEM
762 if (windows_or_buffers_changed || update_mode_lines)
763 {
764 Lisp_Object tail, frame;
765
766 FOR_EACH_FRAME (tail, frame)
767 if (FRAME_VISIBLE_P (XFRAME (frame))
768 || FRAME_ICONIFIED_P (XFRAME (frame)))
769 x_consider_frame_title (frame);
770 }
771 #endif
772
773 /* Update the menu bar item lists, if appropriate.
774 This has to be done before any actual redisplay
775 or generation of display lines. */
776 if (all_windows)
777 {
778 Lisp_Object tail, frame;
779 int count = specpdl_ptr - specpdl;
780
781 record_unwind_protect (Fstore_match_data, Fmatch_data (Qnil, Qnil));
782
783 FOR_EACH_FRAME (tail, frame)
784 {
785 /* If a window on this frame changed size,
786 report that to the user and clear the size-change flag. */
787 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
788 {
789 Lisp_Object functions;
790 /* Clear flag first in case we get error below. */
791 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
792 functions = Vwindow_size_change_functions;
793 GCPRO2 (tail, functions);
794 while (CONSP (functions))
795 {
796 call1 (XCONS (functions)->car, frame);
797 functions = XCONS (functions)->cdr;
798 }
799 UNGCPRO;
800 }
801 GCPRO1 (tail);
802 update_menu_bar (XFRAME (frame), 0);
803 UNGCPRO;
804 }
805
806 unbind_to (count, Qnil);
807 }
808 else
809 update_menu_bar (selected_frame, 1);
810
811 /* Motif needs this. See comment in xmenu.c.
812 Turn it off when pending_menu_activation is not defined. */
813 #ifdef USE_X_TOOLKIT
814 pending_menu_activation = 0;
815 #endif
816 }
817 \f
818 /* Do a frame update, taking possible shortcuts into account.
819 This is the main external entry point for redisplay.
820
821 If the last redisplay displayed an echo area message and that
822 message is no longer requested, we clear the echo area
823 or bring back the minibuffer if that is in use.
824
825 Do not call eval from within this function.
826 Calls to eval after the call to echo_area_display would confuse
827 the display_line mechanism and would cause a crash.
828 Calls to eval before that point will work most of the time,
829 but can still lose, because this function
830 can be called from signal handlers; with alarms set up;
831 or with synchronous processes running.
832
833 See Fcall_process; if you called it from here, it could be
834 entered recursively. */
835
836 static int do_verify_charstarts;
837
838 /* Counter is used to clear the face cache
839 no more than once ever 1000 redisplays. */
840 static int clear_face_cache_count;
841
842 /* Record the previous terminal frame we displayed. */
843 static FRAME_PTR previous_terminal_frame;
844
845 void
846 redisplay ()
847 {
848 redisplay_internal (0);
849 }
850
851 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
852 is not in response to any user action; therefore, we should
853 preserve the echo area. (Actually, our caller does that job.)
854 Perhaps in the future avoid recentering windows
855 if it is not necessary; currently that causes some problems. */
856
857 static void
858 redisplay_internal (preserve_echo_area)
859 int preserve_echo_area;
860 {
861 register struct window *w = XWINDOW (selected_window);
862 register int pause;
863 int must_finish = 0;
864 int all_windows;
865 register int tlbufpos, tlendpos;
866 struct position pos;
867
868 if (noninteractive)
869 return;
870
871 #ifdef USE_X_TOOLKIT
872 if (popup_activated ())
873 return;
874 #endif
875
876 if (! FRAME_WINDOW_P (selected_frame)
877 && previous_terminal_frame != selected_frame)
878 {
879 /* Since frames on an ASCII terminal share the same display area,
880 displaying a different frame means redisplay the whole thing. */
881 windows_or_buffers_changed++;
882 SET_FRAME_GARBAGED (selected_frame);
883 XSETFRAME (Vterminal_frame, selected_frame);
884 }
885 previous_terminal_frame = selected_frame;
886
887 /* Set the visible flags for all frames.
888 Do this before checking for resized or garbaged frames; they want
889 to know if their frames are visible.
890 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
891 {
892 Lisp_Object tail, frame;
893
894 FOR_EACH_FRAME (tail, frame)
895 {
896 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
897
898 /* Clear out all the display lines in which we will generate the
899 glyphs to display. */
900 init_desired_glyphs (XFRAME (frame));
901 }
902 }
903
904 /* Notice any pending interrupt request to change frame size. */
905 do_pending_window_change ();
906
907 if (frame_garbaged)
908 {
909 redraw_garbaged_frames ();
910 frame_garbaged = 0;
911 }
912
913 prepare_menu_bars ();
914
915 if (windows_or_buffers_changed)
916 update_mode_lines++;
917
918 /* Detect case that we need to write or remove a star in the mode line. */
919 if ((SAVE_MODIFF < MODIFF) != !NILP (w->last_had_star))
920 {
921 w->update_mode_line = Qt;
922 if (buffer_shared > 1)
923 update_mode_lines++;
924 }
925
926 /* If %c is in use, update it if needed. */
927 if (!NILP (w->column_number_displayed)
928 /* This alternative quickly identifies a common case
929 where no change is needed. */
930 && !(PT == XFASTINT (w->last_point)
931 && XFASTINT (w->last_modified) >= MODIFF
932 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)
933 && XFASTINT (w->column_number_displayed) != current_column ())
934 w->update_mode_line = Qt;
935
936 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
937
938 all_windows = update_mode_lines || buffer_shared > 1;
939
940 /* If specs for an arrow have changed, do thorough redisplay
941 to ensure we remove any arrow that should no longer exist. */
942 if (! EQ (Voverlay_arrow_position, last_arrow_position)
943 || ! EQ (Voverlay_arrow_string, last_arrow_string))
944 all_windows = 1;
945
946 /* Normally the message* functions will have already displayed and
947 updated the echo area, but the frame may have been trashed, or
948 the update may have been preempted, so display the echo area
949 again here. */
950 if (echo_area_glyphs || previous_echo_glyphs)
951 {
952 echo_area_display ();
953 must_finish = 1;
954 }
955
956 /* If showing region, and mark has changed, must redisplay whole window. */
957 if (((!NILP (Vtransient_mark_mode)
958 && !NILP (XBUFFER (w->buffer)->mark_active))
959 != !NILP (w->region_showing))
960 || (!NILP (w->region_showing)
961 && !EQ (w->region_showing,
962 Fmarker_position (XBUFFER (w->buffer)->mark))))
963 this_line_bufpos = -1;
964
965 tlbufpos = this_line_bufpos;
966 tlendpos = this_line_endpos;
967 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
968 && !current_buffer->clip_changed
969 && FRAME_VISIBLE_P (XFRAME (w->frame))
970 /* Make sure recorded data applies to current buffer, etc */
971 && this_line_buffer == current_buffer
972 && current_buffer == XBUFFER (w->buffer)
973 && NILP (w->force_start)
974 /* Point must be on the line that we have info recorded about */
975 && PT >= tlbufpos
976 && PT <= Z - tlendpos
977 /* All text outside that line, including its final newline,
978 must be unchanged */
979 && ((XFASTINT (w->last_modified) >= MODIFF
980 && (XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF))
981 || (beg_unchanged >= tlbufpos - 1
982 && GPT >= tlbufpos
983 /* If selective display, can't optimize
984 if the changes start at the beginning of the line. */
985 && ((INTEGERP (current_buffer->selective_display)
986 && XINT (current_buffer->selective_display) > 0
987 ? (beg_unchanged >= tlbufpos
988 && GPT > tlbufpos)
989 : 1))
990 && end_unchanged >= tlendpos
991 && Z - GPT >= tlendpos)))
992 {
993 if (tlbufpos > BEGV && FETCH_BYTE (tlbufpos - 1) != '\n'
994 && (tlbufpos == ZV
995 || FETCH_BYTE (tlbufpos) == '\n'))
996 /* Former continuation line has disappeared by becoming empty */
997 goto cancel;
998 else if (XFASTINT (w->last_modified) < MODIFF
999 || XFASTINT (w->last_overlay_modified) < OVERLAY_MODIFF
1000 || MINI_WINDOW_P (w))
1001 {
1002 /* We have to handle the case of continuation around a
1003 wide-column character (See the comment in indent.c around
1004 line 885).
1005
1006 For instance, in the following case:
1007
1008 -------- Insert --------
1009 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1010 J_I_ ==> J_I_ `^^' are cursors.
1011 ^^ ^^
1012 -------- --------
1013
1014 As we have to redraw the line above, we should goto cancel. */
1015
1016 struct position val;
1017 int prevline;
1018
1019 prevline = find_next_newline (tlbufpos, -1);
1020 val = *compute_motion (prevline, 0,
1021 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1022 0,
1023 tlbufpos,
1024 1 << (BITS_PER_SHORT - 1),
1025 1 << (BITS_PER_SHORT - 1),
1026 window_internal_width (w) - 1,
1027 XINT (w->hscroll), 0, w);
1028 if (val.hpos != this_line_start_hpos)
1029 goto cancel;
1030
1031 cursor_vpos = -1;
1032 overlay_arrow_seen = 0;
1033 zv_strings_seen = 0;
1034 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
1035 pos_tab_offset (w, tlbufpos), 0);
1036 /* If line contains point, is not continued,
1037 and ends at same distance from eob as before, we win */
1038 if (cursor_vpos >= 0 && this_line_bufpos
1039 && this_line_endpos == tlendpos)
1040 {
1041 /* If this is not the window's last line,
1042 we must adjust the charstarts of the lines below. */
1043 if (this_line_vpos + 1
1044 < XFASTINT (w->top) + window_internal_height (w))
1045 {
1046 int left = WINDOW_LEFT_MARGIN (w);
1047 int *charstart_next_line
1048 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
1049 int adjust;
1050
1051 if (Z - tlendpos == ZV)
1052 /* This line ends at end of (accessible part of) buffer.
1053 There is no newline to count. */
1054 adjust = Z - tlendpos - charstart_next_line[left];
1055 else
1056 /* This line ends in a newline.
1057 Must take account of the newline and the rest of the
1058 text that follows. */
1059 adjust = Z - tlendpos + 1 - charstart_next_line[left];
1060
1061 adjust_window_charstarts (w, this_line_vpos, adjust);
1062 }
1063
1064 if (!WINDOW_FULL_WIDTH_P (w))
1065 preserve_other_columns (w);
1066 goto update;
1067 }
1068 else
1069 goto cancel;
1070 }
1071 else if (PT == XFASTINT (w->last_point)
1072 /* Make sure the cursor was last displayed
1073 in this window. Otherwise we have to reposition it. */
1074 && XINT (w->top) <= FRAME_CURSOR_Y (selected_frame)
1075 && (XINT (w->top) + XINT (w->height)
1076 > FRAME_CURSOR_Y (selected_frame)))
1077 {
1078 if (!must_finish)
1079 {
1080 do_pending_window_change ();
1081 return;
1082 }
1083 goto update;
1084 }
1085 /* If highlighting the region, or if the cursor is in the echo area,
1086 then we can't just move the cursor. */
1087 else if (! (!NILP (Vtransient_mark_mode)
1088 && !NILP (current_buffer->mark_active))
1089 && w == XWINDOW (current_buffer->last_selected_window)
1090 && NILP (w->region_showing)
1091 && !cursor_in_echo_area)
1092 {
1093 pos = *compute_motion (tlbufpos, 0,
1094 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1095 0,
1096 PT, 2, - (1 << (BITS_PER_SHORT - 1)),
1097 window_internal_width (w) - 1,
1098 XINT (w->hscroll),
1099 pos_tab_offset (w, tlbufpos), w);
1100 if (pos.vpos < 1)
1101 {
1102 int width = window_internal_width (w) - 1;
1103 FRAME_CURSOR_X (selected_frame)
1104 = WINDOW_LEFT_MARGIN (w) + minmax (0, pos.hpos, width);
1105 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
1106 goto update;
1107 }
1108 else
1109 goto cancel;
1110 }
1111 cancel:
1112 /* Text changed drastically or point moved off of line */
1113 cancel_line (this_line_vpos, selected_frame);
1114 }
1115
1116 this_line_bufpos = 0;
1117 all_windows |= buffer_shared > 1;
1118
1119 clear_face_cache_count++;
1120
1121 if (all_windows)
1122 {
1123 Lisp_Object tail, frame;
1124
1125 #ifdef HAVE_FACES
1126 /* Clear the face cache, only when we do a full redisplay
1127 and not too often either. */
1128 if (clear_face_cache_count > 1000)
1129 {
1130 clear_face_cache ();
1131 clear_face_cache_count = 0;
1132 }
1133 #endif
1134
1135 /* Recompute # windows showing selected buffer.
1136 This will be incremented each time such a window is displayed. */
1137 buffer_shared = 0;
1138
1139 FOR_EACH_FRAME (tail, frame)
1140 {
1141 FRAME_PTR f = XFRAME (frame);
1142 if (FRAME_WINDOW_P (f) || f == selected_frame)
1143 {
1144
1145 /* Mark all the scroll bars to be removed; we'll redeem the ones
1146 we want when we redisplay their windows. */
1147 if (condemn_scroll_bars_hook)
1148 (*condemn_scroll_bars_hook) (f);
1149
1150 if (FRAME_VISIBLE_P (f))
1151 redisplay_windows (FRAME_ROOT_WINDOW (f), preserve_echo_area);
1152
1153 /* Any scroll bars which redisplay_windows should have nuked
1154 should now go away. */
1155 if (judge_scroll_bars_hook)
1156 (*judge_scroll_bars_hook) (f);
1157 }
1158 }
1159 }
1160 else if (FRAME_VISIBLE_P (selected_frame))
1161 {
1162 redisplay_window (selected_window, 1, preserve_echo_area);
1163 if (!WINDOW_FULL_WIDTH_P (w))
1164 preserve_other_columns (w);
1165 }
1166
1167 update:
1168 /* Prevent various kinds of signals during display update.
1169 stdio is not robust about handling signals,
1170 which can cause an apparent I/O error. */
1171 if (interrupt_input)
1172 unrequest_sigio ();
1173 stop_polling ();
1174
1175 if (all_windows)
1176 {
1177 Lisp_Object tail;
1178
1179 pause = 0;
1180
1181 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
1182 {
1183 FRAME_PTR f;
1184
1185 if (!FRAMEP (XCONS (tail)->car))
1186 continue;
1187
1188 f = XFRAME (XCONS (tail)->car);
1189
1190 if ((FRAME_WINDOW_P (f) || f == selected_frame)
1191 && FRAME_VISIBLE_P (f))
1192 {
1193 pause |= update_frame (f, 0, 0);
1194 if (!pause)
1195 {
1196 mark_window_display_accurate (f->root_window, 1);
1197 if (frame_up_to_date_hook != 0)
1198 (*frame_up_to_date_hook) (f);
1199 }
1200 }
1201 }
1202 }
1203 else
1204 {
1205 if (FRAME_VISIBLE_P (selected_frame))
1206 pause = update_frame (selected_frame, 0, 0);
1207 else
1208 pause = 0;
1209
1210 /* We may have called echo_area_display at the top of this
1211 function. If the echo area is on another frame, that may
1212 have put text on a frame other than the selected one, so the
1213 above call to update_frame would not have caught it. Catch
1214 it here. */
1215 {
1216 Lisp_Object mini_window;
1217 FRAME_PTR mini_frame;
1218
1219 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
1220 mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
1221
1222 if (mini_frame != selected_frame && FRAME_WINDOW_P (mini_frame))
1223 pause |= update_frame (mini_frame, 0, 0);
1224 }
1225 }
1226
1227 /* If frame does not match, prevent doing single-line-update next time.
1228 Also, don't forget to check every line to update the arrow. */
1229 if (pause)
1230 {
1231 this_line_bufpos = 0;
1232 if (!NILP (last_arrow_position))
1233 {
1234 last_arrow_position = Qt;
1235 last_arrow_string = Qt;
1236 }
1237 /* If we pause after scrolling, some lines in current_frame
1238 may be null, so preserve_other_columns won't be able to
1239 preserve all the vertical-bar separators. So, avoid using it
1240 in that case. */
1241 if (!WINDOW_FULL_WIDTH_P (w))
1242 update_mode_lines = 1;
1243 }
1244
1245 /* Now text on frame agrees with windows, so
1246 put info into the windows for partial redisplay to follow */
1247
1248 if (!pause)
1249 {
1250 register struct buffer *b = XBUFFER (w->buffer);
1251
1252 blank_end_of_window = 0;
1253 unchanged_modified = BUF_MODIFF (b);
1254 overlay_unchanged_modified = BUF_OVERLAY_MODIFF (b);
1255 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1256 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1257
1258 XSETFASTINT (w->last_point, BUF_PT (b));
1259 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1260 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1261
1262 if (all_windows)
1263 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1264 else
1265 {
1266 b->clip_changed = 0;
1267 w->update_mode_line = Qnil;
1268 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1269 XSETFASTINT (w->last_overlay_modified, BUF_OVERLAY_MODIFF (b));
1270 w->last_had_star
1271 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1272 ? Qt : Qnil);
1273 w->window_end_valid = w->buffer;
1274 last_arrow_position = Voverlay_arrow_position;
1275 last_arrow_string = Voverlay_arrow_string;
1276 if (do_verify_charstarts)
1277 verify_charstarts (w);
1278 if (frame_up_to_date_hook != 0)
1279 (*frame_up_to_date_hook) (selected_frame);
1280 }
1281 update_mode_lines = 0;
1282 windows_or_buffers_changed = 0;
1283 }
1284
1285 /* Start SIGIO interrupts coming again.
1286 Having them off during the code above
1287 makes it less likely one will discard output,
1288 but not impossible, since there might be stuff
1289 in the system buffer here.
1290 But it is much hairier to try to do anything about that. */
1291
1292 if (interrupt_input)
1293 request_sigio ();
1294 start_polling ();
1295
1296 /* Change frame size now if a change is pending. */
1297 do_pending_window_change ();
1298
1299 /* If we just did a pending size change, redisplay again
1300 for the new size. */
1301 if (windows_or_buffers_changed && !pause)
1302 redisplay ();
1303 }
1304
1305 /* Redisplay, but leave alone any recent echo area message
1306 unless another message has been requested in its place.
1307
1308 This is useful in situations where you need to redisplay but no
1309 user action has occurred, making it inappropriate for the message
1310 area to be cleared. See tracking_off and
1311 wait_reading_process_input for examples of these situations. */
1312
1313 redisplay_preserve_echo_area ()
1314 {
1315 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1316 {
1317 echo_area_glyphs = previous_echo_glyphs;
1318 redisplay_internal (1);
1319 echo_area_glyphs = 0;
1320 }
1321 else
1322 redisplay_internal (1);
1323 }
1324
1325 void
1326 mark_window_display_accurate (window, flag)
1327 Lisp_Object window;
1328 int flag;
1329 {
1330 register struct window *w;
1331
1332 for (;!NILP (window); window = w->next)
1333 {
1334 if (!WINDOWP (window)) abort ();
1335 w = XWINDOW (window);
1336
1337 if (!NILP (w->buffer))
1338 {
1339 XSETFASTINT (w->last_modified,
1340 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1341 XSETFASTINT (w->last_overlay_modified,
1342 !flag ? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w->buffer)));
1343 w->last_had_star
1344 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1345 ? Qt : Qnil);
1346
1347 /* Record if we are showing a region, so can make sure to
1348 update it fully at next redisplay. */
1349 w->region_showing = (!NILP (Vtransient_mark_mode)
1350 && w == XWINDOW (current_buffer->last_selected_window)
1351 && !NILP (XBUFFER (w->buffer)->mark_active)
1352 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1353 : Qnil);
1354 }
1355
1356 w->window_end_valid = w->buffer;
1357 w->update_mode_line = Qnil;
1358 if (!NILP (w->buffer) && flag)
1359 XBUFFER (w->buffer)->clip_changed = 0;
1360
1361 if (!NILP (w->vchild))
1362 mark_window_display_accurate (w->vchild, flag);
1363 if (!NILP (w->hchild))
1364 mark_window_display_accurate (w->hchild, flag);
1365 }
1366
1367 if (flag)
1368 {
1369 last_arrow_position = Voverlay_arrow_position;
1370 last_arrow_string = Voverlay_arrow_string;
1371 }
1372 else
1373 {
1374 /* t is unequal to any useful value of Voverlay_arrow_... */
1375 last_arrow_position = Qt;
1376 last_arrow_string = Qt;
1377 }
1378 }
1379 \f
1380 /* Update the menu bar item list for frame F.
1381 This has to be done before we start to fill in any display lines,
1382 because it can call eval.
1383
1384 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1385
1386 static void
1387 update_menu_bar (f, save_match_data)
1388 FRAME_PTR f;
1389 int save_match_data;
1390 {
1391 struct buffer *old = current_buffer;
1392 Lisp_Object window;
1393 register struct window *w;
1394
1395 window = FRAME_SELECTED_WINDOW (f);
1396 w = XWINDOW (window);
1397
1398 if (update_mode_lines)
1399 w->update_mode_line = Qt;
1400
1401 if (FRAME_WINDOW_P (f)
1402 ?
1403 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1404 FRAME_EXTERNAL_MENU_BAR (f)
1405 #else
1406 FRAME_MENU_BAR_LINES (f) > 0
1407 #endif
1408 : FRAME_MENU_BAR_LINES (f) > 0)
1409 {
1410 /* If the user has switched buffers or windows, we need to
1411 recompute to reflect the new bindings. But we'll
1412 recompute when update_mode_lines is set too; that means
1413 that people can use force-mode-line-update to request
1414 that the menu bar be recomputed. The adverse effect on
1415 the rest of the redisplay algorithm is about the same as
1416 windows_or_buffers_changed anyway. */
1417 if (windows_or_buffers_changed
1418 || !NILP (w->update_mode_line)
1419 || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1420 < BUF_MODIFF (XBUFFER (w->buffer)))
1421 != !NILP (w->last_had_star))
1422 || ((!NILP (Vtransient_mark_mode)
1423 && !NILP (XBUFFER (w->buffer)->mark_active))
1424 != !NILP (w->region_showing)))
1425 {
1426 struct buffer *prev = current_buffer;
1427 int count = specpdl_ptr - specpdl;
1428
1429 set_buffer_internal_1 (XBUFFER (w->buffer));
1430 if (save_match_data)
1431 record_unwind_protect (Fstore_match_data, Fmatch_data (Qnil, Qnil));
1432 if (NILP (Voverriding_local_map_menu_flag))
1433 {
1434 specbind (Qoverriding_terminal_local_map, Qnil);
1435 specbind (Qoverriding_local_map, Qnil);
1436 }
1437
1438 /* Run the Lucid hook. */
1439 call1 (Vrun_hooks, Qactivate_menubar_hook);
1440 /* If it has changed current-menubar from previous value,
1441 really recompute the menubar from the value. */
1442 if (! NILP (Vlucid_menu_bar_dirty_flag))
1443 call0 (Qrecompute_lucid_menubar);
1444 safe_run_hooks (Qmenu_bar_update_hook);
1445 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1446 /* Redisplay the menu bar in case we changed it. */
1447 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1448 if (FRAME_WINDOW_P (f))
1449 set_frame_menubar (f, 0, 0);
1450 else
1451 /* On a terminal screen, the menu bar is an ordinary screen
1452 line, and this makes it get updated. */
1453 w->update_mode_line = Qt;
1454 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1455 /* In the non-toolkit version, the menu bar is an ordinary screen
1456 line, and this makes it get updated. */
1457 w->update_mode_line = Qt;
1458 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1459
1460 unbind_to (count, Qnil);
1461 set_buffer_internal_1 (prev);
1462 }
1463 }
1464 }
1465 \f
1466 int do_id = 1;
1467
1468 /* Redisplay WINDOW and its subwindows and siblings. */
1469
1470 static void
1471 redisplay_windows (window, preserve_echo_area)
1472 Lisp_Object window;
1473 int preserve_echo_area;
1474 {
1475 for (; !NILP (window); window = XWINDOW (window)->next)
1476 redisplay_window (window, 0, preserve_echo_area);
1477 }
1478
1479 /* Return value in display table DP (Lisp_Char_Table *) for character
1480 C. Since a display table doesn't have any parent, we don't have to
1481 follow parent. Do not call this function directly but use the
1482 macro DISP_CHAR_VECTOR. */
1483 Lisp_Object
1484 disp_char_vector (dp, c)
1485 struct Lisp_Char_Table *dp;
1486 int c;
1487 {
1488 int code[4], i;
1489 Lisp_Object val;
1490
1491 if (SINGLE_BYTE_CHAR_P (c)) return (dp->contents[c]);
1492
1493 SPLIT_NON_ASCII_CHAR (c, code[0], code[1], code[2]);
1494 if (code[0] != CHARSET_COMPOSITION)
1495 {
1496 if (code[1] < 32) code[1] = -1;
1497 else if (code[2] < 32) code[2] = -1;
1498 }
1499 /* Here, the possible range of CODE[0] (== charset ID) is
1500 128..MAX_CHARSET. Since the top level char table contains data
1501 for multibyte characters after 256th element, we must increment
1502 CODE[0] by 128 to get a correct index. */
1503 code[0] += 128;
1504 code[3] = -1; /* anchor */
1505
1506 for (i = 0; code[i] >= 0; i++, dp = XCHAR_TABLE (val))
1507 {
1508 val = dp->contents[code[i]];
1509 if (!SUB_CHAR_TABLE_P (val))
1510 return (NILP (val) ? dp->defalt : val);
1511 }
1512 /* Here, VAL is a sub char table. We return the default value of it. */
1513 return (dp->defalt);
1514 }
1515
1516 /* Redisplay window WINDOW and its subwindows. */
1517
1518 static void
1519 redisplay_window (window, just_this_one, preserve_echo_area)
1520 Lisp_Object window;
1521 int just_this_one, preserve_echo_area;
1522 {
1523 register struct window *w = XWINDOW (window);
1524 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1525 int height;
1526 register int lpoint = PT;
1527 struct buffer *old = current_buffer;
1528 register int width = window_internal_width (w) - 1;
1529 register int startp;
1530 register int hscroll = XINT (w->hscroll);
1531 struct position pos;
1532 int opoint = PT;
1533 int tem;
1534 int update_mode_line;
1535 struct Lisp_Char_Table *dp = window_display_table (w);
1536
1537 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1538
1539 /* If this is a combination window, do its children; that's all. */
1540
1541 if (!NILP (w->vchild))
1542 {
1543 redisplay_windows (w->vchild, preserve_echo_area);
1544 return;
1545 }
1546 if (!NILP (w->hchild))
1547 {
1548 redisplay_windows (w->hchild, preserve_echo_area);
1549 return;
1550 }
1551 if (NILP (w->buffer))
1552 abort ();
1553
1554 height = window_internal_height (w);
1555 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1556 if (XBUFFER (w->buffer)->clip_changed)
1557 update_mode_line = 1;
1558
1559 if (MINI_WINDOW_P (w))
1560 {
1561 if (w == XWINDOW (echo_area_window) && echo_area_glyphs)
1562 /* We've already displayed the echo area glyphs in this window. */
1563 goto finish_scroll_bars;
1564 else if (w != XWINDOW (minibuf_window))
1565 {
1566 /* This is a minibuffer, but it's not the currently active one,
1567 so clear it. */
1568 int vpos = XFASTINT (w->top);
1569 int i;
1570
1571 for (i = 0; i < height; i++)
1572 {
1573 get_display_line (f, vpos + i, 0);
1574 display_string (w, vpos + i, "", 0,
1575 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
1576 0, 1, 0, width);
1577 }
1578
1579 goto finish_scroll_bars;
1580 }
1581 }
1582
1583 /* Otherwise set up data on this window; select its buffer and point value */
1584
1585 if (update_mode_line)
1586 set_buffer_internal_1 (XBUFFER (w->buffer));
1587 else
1588 set_buffer_temp (XBUFFER (w->buffer));
1589
1590 opoint = PT;
1591
1592 /* If %c is in mode line, update it if needed. */
1593 if (!NILP (w->column_number_displayed)
1594 /* This alternative quickly identifies a common case
1595 where no change is needed. */
1596 && !(PT == XFASTINT (w->last_point)
1597 && XFASTINT (w->last_modified) >= MODIFF
1598 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)
1599 && XFASTINT (w->column_number_displayed) != current_column ())
1600 update_mode_line = 1;
1601
1602 /* Count number of windows showing the selected buffer.
1603 An indirect buffer counts as its base buffer. */
1604
1605 if (!just_this_one)
1606 {
1607 struct buffer *current_base, *window_base;
1608 current_base = current_buffer;
1609 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1610 if (current_base->base_buffer)
1611 current_base = current_base->base_buffer;
1612 if (window_base->base_buffer)
1613 window_base = window_base->base_buffer;
1614 if (current_base == window_base)
1615 buffer_shared++;
1616 }
1617
1618 /* POINT refers normally to the selected window.
1619 For any other window, set up appropriate value. */
1620
1621 if (!EQ (window, selected_window))
1622 {
1623 int new_pt = marker_position (w->pointm);
1624 if (new_pt < BEGV)
1625 {
1626 new_pt = BEGV;
1627 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1628 }
1629 else if (new_pt > (ZV - 1))
1630 {
1631 new_pt = ZV;
1632 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1633 }
1634 /* We don't use SET_PT so that the point-motion hooks don't run. */
1635 BUF_PT (current_buffer) = new_pt;
1636 }
1637
1638 /* If any of the character widths specified in the display table
1639 have changed, invalidate the width run cache. It's true that this
1640 may be a bit late to catch such changes, but the rest of
1641 redisplay goes (non-fatally) haywire when the display table is
1642 changed, so why should we worry about doing any better? */
1643 if (current_buffer->width_run_cache)
1644 {
1645 struct Lisp_Char_Table *disptab = buffer_display_table ();
1646
1647 if (! disptab_matches_widthtab (disptab,
1648 XVECTOR (current_buffer->width_table)))
1649 {
1650 invalidate_region_cache (current_buffer,
1651 current_buffer->width_run_cache,
1652 BEG, Z);
1653 recompute_width_table (current_buffer, disptab);
1654 }
1655 }
1656
1657 /* If window-start is screwed up, choose a new one. */
1658 if (XMARKER (w->start)->buffer != current_buffer)
1659 goto recenter;
1660
1661 startp = marker_position (w->start);
1662
1663 /* If someone specified a new starting point but did not insist,
1664 check whether it can be used. */
1665 if (!NILP (w->optional_new_start))
1666 {
1667 w->optional_new_start = Qnil;
1668 /* Check whether this start pos is usable given where point is. */
1669
1670 pos = *compute_motion (startp, 0,
1671 (((EQ (window, minibuf_window)
1672 && startp == BEG)
1673 ? minibuf_prompt_width : 0)
1674 + (hscroll ? 1 - hscroll : 0)),
1675 0,
1676 PT, height,
1677 /* BUG FIX: See the comment of
1678 Fpos_visible_in_window_p (window.c). */
1679 - (1 << (BITS_PER_SHORT - 1)),
1680 width, hscroll, pos_tab_offset (w, startp), w);
1681 /* If PT does fit on the screen, we will use this start pos,
1682 so do so by setting force_start. */
1683 if (pos.bufpos == PT)
1684 w->force_start = Qt;
1685 }
1686
1687 /* Handle case where place to start displaying has been specified,
1688 unless the specified location is outside the accessible range. */
1689 if (!NILP (w->force_start))
1690 {
1691 w->force_start = Qnil;
1692 /* Forget any recorded base line for line number display. */
1693 w->base_line_number = Qnil;
1694 /* Redisplay the mode line. Select the buffer properly for that.
1695 Also, run the hook window-scroll-functions
1696 because we have scrolled. */
1697 /* Note, we do this after clearing force_start because
1698 if there's an error, it is better to forget about force_start
1699 than to get into an infinite loop calling the hook functions
1700 and having them get more errors. */
1701 if (!update_mode_line
1702 || ! NILP (Vwindow_scroll_functions))
1703 {
1704 Lisp_Object temp[3];
1705
1706 set_buffer_temp (old);
1707 set_buffer_internal_1 (XBUFFER (w->buffer));
1708 update_mode_line = 1;
1709 w->update_mode_line = Qt;
1710 if (! NILP (Vwindow_scroll_functions))
1711 {
1712 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1713 make_number (startp));
1714 startp = marker_position (w->start);
1715 }
1716 }
1717 XSETFASTINT (w->last_modified, 0);
1718 XSETFASTINT (w->last_overlay_modified, 0);
1719 if (startp < BEGV) startp = BEGV;
1720 if (startp > ZV) startp = ZV;
1721 try_window (window, startp);
1722 if (cursor_vpos < 0)
1723 {
1724 /* If point does not appear, move point so it does appear */
1725 pos = *compute_motion (startp, 0,
1726 (((EQ (window, minibuf_window)
1727 && startp == BEG)
1728 ? minibuf_prompt_width : 0)
1729 + (hscroll ? 1 - hscroll : 0)),
1730 0,
1731 ZV, height / 2,
1732 - (1 << (BITS_PER_SHORT - 1)),
1733 width, hscroll, pos_tab_offset (w, startp), w);
1734 BUF_PT (current_buffer) = pos.bufpos;
1735 if (w != XWINDOW (selected_window))
1736 Fset_marker (w->pointm, make_number (PT), Qnil);
1737 else
1738 {
1739 if (current_buffer == old)
1740 lpoint = PT;
1741 FRAME_CURSOR_X (f) = (WINDOW_LEFT_MARGIN (w)
1742 + minmax (0, pos.hpos, width));
1743 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1744 }
1745 /* If we are highlighting the region,
1746 then we just changed the region, so redisplay to show it. */
1747 if (!NILP (Vtransient_mark_mode)
1748 && !NILP (current_buffer->mark_active))
1749 {
1750 cancel_my_columns (XWINDOW (window));
1751 try_window (window, startp);
1752 }
1753 }
1754 goto done;
1755 }
1756
1757 /* Handle case where text has not changed, only point,
1758 and it has not moved off the frame. */
1759
1760 /* This code is not used for minibuffer for the sake of
1761 the case of redisplaying to replace an echo area message;
1762 since in that case the minibuffer contents per se are usually unchanged.
1763 This code is of no real use in the minibuffer since
1764 the handling of this_line_bufpos, etc.,
1765 in redisplay handles the same cases. */
1766
1767 if (XFASTINT (w->last_modified) >= MODIFF
1768 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF
1769 && PT >= startp && !current_buffer->clip_changed
1770 && (just_this_one || WINDOW_FULL_WIDTH_P (w))
1771 /* If force-mode-line-update was called, really redisplay;
1772 that's how redisplay is forced after e.g. changing
1773 buffer-invisibility-spec. */
1774 && NILP (w->update_mode_line)
1775 /* Can't use this case if highlighting a region. */
1776 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1777 && NILP (w->region_showing)
1778 /* If end pos is out of date, scroll bar and percentage will be wrong */
1779 && INTEGERP (w->window_end_vpos)
1780 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1781 && !EQ (window, minibuf_window))
1782 {
1783 int this_scroll_margin = scroll_margin;
1784
1785 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0,
1786 PT, height,
1787 /* BUG FIX: See the comment of
1788 Fpos_visible_in_window_p (window.c). */
1789 - (1 << (BITS_PER_SHORT - 1)),
1790 width, hscroll,
1791 pos_tab_offset (w, startp), w);
1792
1793 /* Don't use a scroll margin that is negative or too large. */
1794 if (this_scroll_margin < 0)
1795 this_scroll_margin = 0;
1796
1797 if (XINT (w->height) < 4 * scroll_margin)
1798 this_scroll_margin = XINT (w->height) / 4;
1799
1800 /* If point fits on the screen, and not within the scroll margin,
1801 we are ok. */
1802 if (pos.vpos < height - this_scroll_margin
1803 && (pos.vpos >= this_scroll_margin || startp == BEGV))
1804 {
1805 /* Ok, point is still on frame */
1806 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1807 {
1808 /* These variables are supposed to be origin 1 */
1809 FRAME_CURSOR_X (f) = (WINDOW_LEFT_MARGIN (w)
1810 + minmax (0, pos.hpos, width));
1811 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1812 }
1813 /* This doesn't do the trick, because if a window to the right of
1814 this one must be redisplayed, this does nothing because there
1815 is nothing in DesiredFrame yet, and then the other window is
1816 redisplayed, making likes that are empty in this window's columns.
1817 if (WINDOW_FULL_WIDTH_P (w))
1818 preserve_my_columns (w);
1819 */
1820 goto done;
1821 }
1822 /* Don't bother trying redisplay with same start;
1823 we already know it will lose */
1824 }
1825 /* If current starting point was originally the beginning of a line
1826 but no longer is, find a new starting point. */
1827 else if (!NILP (w->start_at_line_beg)
1828 && !(startp <= BEGV
1829 || FETCH_BYTE (startp - 1) == '\n'))
1830 {
1831 goto recenter;
1832 }
1833 else if (just_this_one && !MINI_WINDOW_P (w)
1834 && PT >= startp
1835 && XFASTINT (w->last_modified)
1836 /* or else vmotion on first line won't work. */
1837 && ! NILP (w->start_at_line_beg)
1838 && ! EQ (w->window_end_valid, Qnil)
1839 && do_id && !current_buffer->clip_changed
1840 && !blank_end_of_window
1841 && WINDOW_FULL_WIDTH_P (w)
1842 /* Can't use this case if highlighting a region. */
1843 && !(!NILP (Vtransient_mark_mode)
1844 && !NILP (current_buffer->mark_active))
1845 /* Don't use try_window_id if newline
1846 doesn't display as the end of a line. */
1847 && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n')))
1848 && NILP (w->region_showing)
1849 && EQ (last_arrow_position, Voverlay_arrow_position)
1850 && EQ (last_arrow_string, Voverlay_arrow_string)
1851 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1852 && tem != -2)
1853 {
1854 /* tem > 0 means success. tem == -1 means choose new start.
1855 tem == -2 means try again with same start,
1856 and nothing but whitespace follows the changed stuff.
1857 tem == 0 means try again with same start. */
1858 if (tem > 0)
1859 goto done;
1860 }
1861 else if (startp >= BEGV && startp <= ZV
1862 && (startp < ZV
1863 /* Avoid starting at end of buffer. */
1864 #if 0 /* This change causes trouble for M-! finger & RET.
1865 It will have to be considered later. */
1866 || ! EQ (window, selected_window)
1867 /* Don't do the recentering if redisplay
1868 is not for no user action. */
1869 || preserve_echo_area
1870 #endif
1871 || startp == BEGV
1872 || (XFASTINT (w->last_modified) >= MODIFF
1873 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)))
1874 {
1875 /* Try to redisplay starting at same place as before */
1876 /* If point has not moved off frame, accept the results */
1877 try_window (window, startp);
1878 if (cursor_vpos >= 0)
1879 {
1880 if (!just_this_one || current_buffer->clip_changed
1881 || beg_unchanged < startp)
1882 /* Forget any recorded base line for line number display. */
1883 w->base_line_number = Qnil;
1884 goto done;
1885 }
1886 else
1887 cancel_my_columns (w);
1888 }
1889
1890 XSETFASTINT (w->last_modified, 0);
1891 XSETFASTINT (w->last_overlay_modified, 0);
1892 /* Redisplay the mode line. Select the buffer properly for that. */
1893 if (!update_mode_line)
1894 {
1895 set_buffer_temp (old);
1896 set_buffer_internal_1 (XBUFFER (w->buffer));
1897 update_mode_line = 1;
1898 w->update_mode_line = Qt;
1899 }
1900
1901 /* Try to scroll by specified few lines */
1902
1903 if (scroll_conservatively && !current_buffer->clip_changed
1904 && startp >= BEGV && startp <= ZV)
1905 {
1906 int this_scroll_margin = scroll_margin;
1907
1908 /* Don't use a scroll margin that is negative or too large. */
1909 if (this_scroll_margin < 0)
1910 this_scroll_margin = 0;
1911
1912 if (XINT (w->height) < 4 * scroll_margin)
1913 this_scroll_margin = XINT (w->height) / 4;
1914
1915 if (PT >= Z - XFASTINT (w->window_end_pos))
1916 {
1917 struct position pos;
1918 pos = *compute_motion (Z - XFASTINT (w->window_end_pos), 0, 0, 0,
1919 PT, XFASTINT (w->height), 0,
1920 XFASTINT (w->width), XFASTINT (w->hscroll),
1921 pos_tab_offset (w, startp), w);
1922 if (pos.vpos > scroll_conservatively)
1923 goto scroll_fail_1;
1924
1925 pos = *vmotion (startp, pos.vpos + 1 + this_scroll_margin, w);
1926
1927 if (! NILP (Vwindow_scroll_functions))
1928 {
1929 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
1930 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1931 make_number (pos.bufpos));
1932 pos.bufpos = marker_position (w->start);
1933 }
1934 try_window (window, pos.bufpos);
1935 if (cursor_vpos >= 0)
1936 {
1937 if (!just_this_one || current_buffer->clip_changed
1938 || beg_unchanged < startp)
1939 /* Forget any recorded base line for line number display. */
1940 w->base_line_number = Qnil;
1941 goto done;
1942 }
1943 else
1944 cancel_my_columns (w);
1945 }
1946 if (PT < startp)
1947 {
1948 struct position pos;
1949 pos = *compute_motion (PT, 0, 0, 0,
1950 startp, XFASTINT (w->height), 0,
1951 XFASTINT (w->width), XFASTINT (w->hscroll),
1952 pos_tab_offset (w, startp), w);
1953 if (pos.vpos >= scroll_conservatively)
1954 goto scroll_fail_1;
1955
1956 pos = *vmotion (startp, - pos.vpos - this_scroll_margin, w);
1957
1958 if (! NILP (Vwindow_scroll_functions))
1959 {
1960 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
1961 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1962 make_number (pos.bufpos));
1963 pos.bufpos = marker_position (w->start);
1964 }
1965 try_window (window, pos.bufpos);
1966 if (cursor_vpos >= 0)
1967 {
1968 if (!just_this_one || current_buffer->clip_changed
1969 || beg_unchanged < startp)
1970 /* Forget any recorded base line for line number display. */
1971 w->base_line_number = Qnil;
1972 goto done;
1973 }
1974 else
1975 cancel_my_columns (w);
1976 }
1977 scroll_fail_1: ;
1978 }
1979
1980 if (scroll_step && !current_buffer->clip_changed
1981 && startp >= BEGV && startp <= ZV)
1982 {
1983 if (PT > startp)
1984 {
1985 pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w);
1986 if (pos.vpos >= height)
1987 goto scroll_fail;
1988 }
1989
1990 pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w);
1991
1992 if (PT >= pos.bufpos)
1993 {
1994 if (! NILP (Vwindow_scroll_functions))
1995 {
1996 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
1997 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1998 make_number (pos.bufpos));
1999 pos.bufpos = marker_position (w->start);
2000 }
2001 try_window (window, pos.bufpos);
2002 if (cursor_vpos >= 0)
2003 {
2004 if (!just_this_one || current_buffer->clip_changed
2005 || beg_unchanged < startp)
2006 /* Forget any recorded base line for line number display. */
2007 w->base_line_number = Qnil;
2008 goto done;
2009 }
2010 else
2011 cancel_my_columns (w);
2012 }
2013 scroll_fail: ;
2014 }
2015
2016 /* Finally, just choose place to start which centers point */
2017
2018 recenter:
2019 /* Forget any previously recorded base line for line number display. */
2020 w->base_line_number = Qnil;
2021
2022 pos = *vmotion (PT, - (height / 2), w);
2023 /* Set startp here explicitly in case that helps avoid an infinite loop
2024 in case the window-scroll-functions functions get errors. */
2025 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
2026 if (! NILP (Vwindow_scroll_functions))
2027 {
2028 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2029 make_number (pos.bufpos));
2030 pos.bufpos = marker_position (w->start);
2031 }
2032 try_window (window, pos.bufpos);
2033
2034 startp = marker_position (w->start);
2035 w->start_at_line_beg
2036 = (startp == BEGV || FETCH_BYTE (startp - 1) == '\n') ? Qt : Qnil;
2037
2038 done:
2039 if ((update_mode_line
2040 /* If window not full width, must redo its mode line
2041 if the window to its side is being redone */
2042 || (!just_this_one && !WINDOW_FULL_WIDTH_P (w))
2043 || INTEGERP (w->base_line_pos)
2044 || (!NILP (w->column_number_displayed)
2045 && XFASTINT (w->column_number_displayed) != current_column ()))
2046 && height != XFASTINT (w->height))
2047 display_mode_line (w);
2048 if (! line_number_displayed
2049 && ! BUFFERP (w->base_line_pos))
2050 {
2051 w->base_line_pos = Qnil;
2052 w->base_line_number = Qnil;
2053 }
2054
2055 /* When we reach a frame's selected window, redo the frame's menu bar. */
2056 if (update_mode_line
2057 && (FRAME_WINDOW_P (f)
2058 ?
2059 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2060 FRAME_EXTERNAL_MENU_BAR (f)
2061 #else
2062 FRAME_MENU_BAR_LINES (f) > 0
2063 #endif
2064 : FRAME_MENU_BAR_LINES (f) > 0)
2065 && EQ (FRAME_SELECTED_WINDOW (f), window))
2066 display_menu_bar (w);
2067
2068 finish_scroll_bars:
2069 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
2070 {
2071 int start, end, whole;
2072
2073 /* Calculate the start and end positions for the current window.
2074 At some point, it would be nice to choose between scrollbars
2075 which reflect the whole buffer size, with special markers
2076 indicating narrowing, and scrollbars which reflect only the
2077 visible region.
2078
2079 Note that minibuffers sometimes aren't displaying any text. */
2080 if (! MINI_WINDOW_P (w)
2081 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
2082 {
2083 whole = ZV - BEGV;
2084 start = marker_position (w->start) - BEGV;
2085 /* I don't think this is guaranteed to be right. For the
2086 moment, we'll pretend it is. */
2087 end = (Z - XINT (w->window_end_pos)) - BEGV;
2088
2089 if (end < start) end = start;
2090 if (whole < (end - start)) whole = end - start;
2091 }
2092 else
2093 start = end = whole = 0;
2094
2095 /* Indicate what this scroll bar ought to be displaying now. */
2096 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
2097
2098 /* Note that we actually used the scroll bar attached to this window,
2099 so it shouldn't be deleted at the end of redisplay. */
2100 (*redeem_scroll_bar_hook) (w);
2101 }
2102
2103 BUF_PT (current_buffer) = opoint;
2104 if (update_mode_line)
2105 set_buffer_internal_1 (old);
2106 else
2107 set_buffer_temp (old);
2108 BUF_PT (current_buffer) = lpoint;
2109 }
2110 \f
2111 /* Do full redisplay on one window, starting at position `pos'. */
2112
2113 static void
2114 try_window (window, pos)
2115 Lisp_Object window;
2116 register int pos;
2117 {
2118 register struct window *w = XWINDOW (window);
2119 register int height = window_internal_height (w);
2120 register int vpos = XFASTINT (w->top);
2121 register int last_text_vpos = vpos;
2122 FRAME_PTR f = XFRAME (w->frame);
2123 int width = window_internal_width (w) - 1;
2124 struct position val;
2125
2126 /* POS should never be out of range! */
2127 if (pos < XBUFFER (w->buffer)->begv
2128 || pos > XBUFFER (w->buffer)->zv)
2129 abort ();
2130
2131 Fset_marker (w->start, make_number (pos), Qnil);
2132 cursor_vpos = -1;
2133 overlay_arrow_seen = 0;
2134 zv_strings_seen = 0;
2135 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2136 val.ovstring_chars_done = 0;
2137 val.tab_offset = pos_tab_offset (w, pos);
2138
2139 while (--height >= 0)
2140 {
2141 val = *display_text_line (w, pos, vpos, val.hpos, val.tab_offset,
2142 val.ovstring_chars_done);
2143 /* The following code is omitted because we maintain tab_offset
2144 in VAL. */
2145 #if 0
2146 tab_offset += width;
2147 if (val.vpos) tab_offset = 0;
2148 #endif /* 0 */
2149 vpos++;
2150 if (pos != val.bufpos)
2151 {
2152 int invis = 0;
2153 #ifdef USE_TEXT_PROPERTIES
2154 Lisp_Object invis_prop;
2155 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
2156 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
2157 #endif
2158
2159 last_text_vpos
2160 /* Next line, unless prev line ended in end of buffer with no cr */
2161 = vpos - (val.vpos
2162 && (FETCH_BYTE (val.bufpos - 1) != '\n' || invis));
2163 }
2164 pos = val.bufpos;
2165 }
2166
2167 /* If last line is continued in middle of character,
2168 include the split character in the text considered on the frame */
2169 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2170 pos++;
2171
2172 /* If bottom just moved off end of frame, change mode line percentage. */
2173 if (XFASTINT (w->window_end_pos) == 0
2174 && Z != pos)
2175 w->update_mode_line = Qt;
2176
2177 /* Say where last char on frame will be, once redisplay is finished. */
2178 XSETFASTINT (w->window_end_pos, Z - pos);
2179 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
2180 /* But that is not valid info until redisplay finishes. */
2181 w->window_end_valid = Qnil;
2182 }
2183 \f
2184 /* Try to redisplay when buffer is modified locally,
2185 computing insert/delete line to preserve text outside
2186 the bounds of the changes.
2187 Return 1 if successful, 0 if if cannot tell what to do,
2188 or -1 to tell caller to find a new window start,
2189 or -2 to tell caller to do normal redisplay with same window start. */
2190
2191 static int
2192 try_window_id (window)
2193 Lisp_Object window;
2194 {
2195 int pos;
2196 register struct window *w = XWINDOW (window);
2197 register int height = window_internal_height (w);
2198 FRAME_PTR f = XFRAME (w->frame);
2199 int top = XFASTINT (w->top);
2200 int start = marker_position (w->start);
2201 int width = window_internal_width (w) - 1;
2202 int hscroll = XINT (w->hscroll);
2203 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
2204 int did_motion;
2205 register int vpos;
2206 register int i, tem;
2207 int last_text_vpos = 0;
2208 int stop_vpos;
2209 int selective = (INTEGERP (current_buffer->selective_display)
2210 ? XINT (current_buffer->selective_display)
2211 : !NILP (current_buffer->selective_display) ? -1 : 0);
2212
2213 struct position val, bp, ep, xp, pp;
2214 int scroll_amount = 0;
2215 int delta;
2216 int epto, old_tick;
2217
2218 if (GPT - BEG < beg_unchanged)
2219 beg_unchanged = GPT - BEG;
2220 if (Z - GPT < end_unchanged)
2221 end_unchanged = Z - GPT;
2222
2223 if (beg_unchanged + BEG < start)
2224 return 0; /* Give up if changes go above top of window */
2225
2226 /* Find position before which nothing is changed. */
2227 bp = *compute_motion (start, 0, lmargin, 0,
2228 min (ZV, beg_unchanged + BEG), height,
2229 /* BUG FIX: See the comment of
2230 Fpos_visible_in_window_p() (window.c). */
2231 - (1 << (BITS_PER_SHORT - 1)),
2232 width, hscroll, pos_tab_offset (w, start), w);
2233 if (bp.vpos >= height)
2234 {
2235 if (PT < bp.bufpos)
2236 {
2237 /* All changes are beyond the window end, and point is on the screen.
2238 We don't need to change the text at all.
2239 But we need to update window_end_pos to account for
2240 any change in buffer size. */
2241 bp = *compute_motion (start, 0, lmargin, 0,
2242 ZV, height,
2243 /* BUG FIX: See the comment of
2244 Fpos_visible_in_window_p() (window.c). */
2245 - (1 << (BITS_PER_SHORT - 1)),
2246 width, hscroll, pos_tab_offset (w, start), w);
2247 XSETFASTINT (w->window_end_vpos, height);
2248 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
2249 goto findpoint;
2250 }
2251 return 0;
2252 }
2253
2254 vpos = bp.vpos;
2255
2256 /* Find beginning of that frame line. Must display from there. */
2257 bp = *vmotion (bp.bufpos, 0, w);
2258
2259 pos = bp.bufpos;
2260 val.hpos = lmargin;
2261 if (pos < start)
2262 return -1;
2263
2264 did_motion = 0;
2265 /* If about to start displaying at the beginning of a continuation line,
2266 really start with previous frame line, in case it was not
2267 continued when last redisplayed */
2268 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
2269 ||
2270 /* Likewise if we have to worry about selective display. */
2271 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
2272 {
2273 bp = *vmotion (bp.bufpos, -1, w);
2274 --vpos;
2275 pos = bp.bufpos;
2276 }
2277 val.tab_offset = bp.tab_offset; /* Update tab offset. */
2278
2279 if (bp.contin && bp.hpos != lmargin)
2280 {
2281 val.hpos = bp.prevhpos - width + lmargin;
2282 val.tab_offset = bp.tab_offset + bp.prevhpos - width;
2283 did_motion = 1;
2284 DEC_POS (pos);
2285 }
2286
2287 bp.vpos = vpos;
2288
2289 /* Find first visible newline after which no more is changed. */
2290 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
2291 if (selective > 0)
2292 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
2293 tem = find_next_newline (tem, 1);
2294
2295 /* Compute the cursor position after that newline. */
2296 ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem,
2297 height, - (1 << (BITS_PER_SHORT - 1)),
2298 width, hscroll,
2299 /* We have tab offset in VAL, use it. */
2300 val.tab_offset, w);
2301
2302 /* If changes reach past the text available on the frame,
2303 just display rest of frame. */
2304 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
2305 stop_vpos = height;
2306 else
2307 stop_vpos = ep.vpos;
2308
2309 /* If no newline before ep, the line ep is on includes some changes
2310 that must be displayed. Make sure we don't stop before it. */
2311 /* Also, if changes reach all the way until ep.bufpos,
2312 it is possible that something was deleted after the
2313 newline before it, so the following line must be redrawn. */
2314 if (stop_vpos == ep.vpos
2315 && (ep.bufpos == BEGV
2316 || FETCH_BYTE (ep.bufpos - 1) != '\n'
2317 || ep.bufpos == Z - end_unchanged))
2318 stop_vpos = ep.vpos + 1;
2319
2320 cursor_vpos = -1;
2321 overlay_arrow_seen = 0;
2322 zv_strings_seen = 0;
2323
2324 /* If changes do not reach to bottom of window,
2325 figure out how much to scroll the rest of the window */
2326 if (stop_vpos < height)
2327 {
2328 /* Now determine how far up or down the rest of the window has moved */
2329 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2330 Z - XFASTINT (w->window_end_pos),
2331 /* Don't care for VPOS... */
2332 1 << (BITS_PER_SHORT - 1),
2333 /* ... nor HPOS. */
2334 1 << (BITS_PER_SHORT - 1),
2335 width, hscroll, ep.tab_offset, w);
2336 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
2337
2338 /* Is everything on frame below the changes whitespace?
2339 If so, no scrolling is really necessary. */
2340 for (i = ep.bufpos; i < xp.bufpos; i++)
2341 {
2342 tem = FETCH_BYTE (i);
2343 if (tem != ' ' && tem != '\n' && tem != '\t')
2344 break;
2345 }
2346 if (i == xp.bufpos)
2347 return -2;
2348
2349 XSETFASTINT (w->window_end_vpos,
2350 XFASTINT (w->window_end_vpos) + scroll_amount);
2351
2352 /* Before doing any scrolling, verify that point will be on frame. */
2353 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.vpos < height))
2354 {
2355 if (PT <= xp.bufpos)
2356 {
2357 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2358 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2359 width, hscroll,
2360 /* We have tab offset in EP, use it. */
2361 ep.tab_offset, w);
2362 }
2363 else
2364 {
2365 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1,
2366 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2367 width, hscroll,
2368 /* We have tab offset in XP, use it. */
2369 xp.tab_offset, w);
2370 }
2371 if (pp.bufpos < PT || pp.vpos == height)
2372 return 0;
2373 cursor_vpos = pp.vpos + top;
2374 cursor_hpos = WINDOW_LEFT_MARGIN (w) + minmax (0, pp.hpos, width);
2375 }
2376
2377 if (stop_vpos - scroll_amount >= height
2378 || ep.bufpos == xp.bufpos)
2379 {
2380 if (scroll_amount < 0)
2381 stop_vpos -= scroll_amount;
2382 scroll_amount = 0;
2383 /* In this path, we have altered window_end_vpos
2384 and not left it negative.
2385 We must make sure that, in case display is preempted
2386 before the frame changes to reflect what we do here,
2387 further updates will not come to try_window_id
2388 and assume the frame and window_end_vpos match. */
2389 blank_end_of_window = 1;
2390 }
2391 else if (!scroll_amount)
2392 {
2393 /* Even if we don't need to scroll, we must adjust the
2394 charstarts of subsequent lines (that we won't redisplay)
2395 according to the amount of text inserted or deleted. */
2396 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2397 int adjust = ep.bufpos - oldpos;
2398 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
2399 }
2400 else if (bp.bufpos == Z - end_unchanged)
2401 {
2402 /* If reprinting everything is nearly as fast as scrolling,
2403 don't bother scrolling. Can happen if lines are short. */
2404 if (scroll_cost (f, bp.vpos + top - scroll_amount,
2405 top + height - max (0, scroll_amount),
2406 scroll_amount)
2407 > xp.bufpos - bp.bufpos - 20)
2408 /* Return "try normal display with same window-start."
2409 Too bad we can't prevent further scroll-thinking. */
2410 return -2;
2411 /* If pure deletion, scroll up as many lines as possible.
2412 In common case of killing a line, this can save the
2413 following line from being overwritten by scrolling
2414 and therefore having to be redrawn. */
2415 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
2416 top + height - max (0, scroll_amount),
2417 scroll_amount, bp.bufpos);
2418 if (!tem)
2419 stop_vpos = height;
2420 else
2421 {
2422 /* scroll_frame_lines did not properly adjust subsequent
2423 lines' charstarts in the case where the text of the
2424 screen line at bp.vpos has changed.
2425 (This can happen in a deletion that ends in mid-line.)
2426 To adjust properly, we need to make things consistent
2427 at the position ep.
2428 So do a second adjust to make that happen.
2429 Note that stop_vpos >= ep.vpos, so it is sufficient
2430 to update the charstarts for lines at ep.vpos and below. */
2431 int oldstart
2432 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2433 adjust_window_charstarts (w, ep.vpos + top - 1,
2434 ep.bufpos - oldstart);
2435 }
2436 }
2437 else if (scroll_amount)
2438 {
2439 /* If reprinting everything is nearly as fast as scrolling,
2440 don't bother scrolling. Can happen if lines are short. */
2441 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2442 overestimate of cost of reprinting, since xp.bufpos
2443 would end up below the bottom of the window. */
2444 if (scroll_cost (f, ep.vpos + top - scroll_amount,
2445 top + height - max (0, scroll_amount),
2446 scroll_amount)
2447 > xp.bufpos - ep.bufpos - 20)
2448 /* Return "try normal display with same window-start."
2449 Too bad we can't prevent further scroll-thinking. */
2450 return -2;
2451 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
2452 top + height - max (0, scroll_amount),
2453 scroll_amount, ep.bufpos);
2454 if (!tem) stop_vpos = height;
2455 }
2456 }
2457
2458 /* In any case, do not display past bottom of window */
2459 if (stop_vpos >= height)
2460 {
2461 stop_vpos = height;
2462 scroll_amount = 0;
2463 }
2464
2465 /* Handle case where pos is before w->start --
2466 can happen if part of line had been clipped and is not clipped now */
2467 if (vpos == 0 && pos < marker_position (w->start))
2468 Fset_marker (w->start, make_number (pos), Qnil);
2469
2470 /* Redisplay the lines where the text was changed */
2471 last_text_vpos = vpos;
2472 /* The following code is omitted because we maintain tab offset in
2473 val.tab_offset. */
2474 #if 0
2475 tab_offset = pos_tab_offset (w, pos);
2476 /* If we are starting display in mid-character, correct tab_offset
2477 to account for passing the line that that character really starts in. */
2478 if (val.hpos < lmargin)
2479 tab_offset += width;
2480 #endif /* 0 */
2481 old_tick = MODIFF;
2482 while (vpos < stop_vpos)
2483 {
2484 val = *display_text_line (w, pos, top + vpos++, val.hpos, val.tab_offset,
2485 val.ovstring_chars_done);
2486 /* If display_text_line ran a hook and changed some text,
2487 redisplay all the way to bottom of buffer
2488 So that we show the changes. */
2489 if (old_tick != MODIFF)
2490 stop_vpos = height;
2491 /* The following code is omitted because we maintain tab offset
2492 in val.tab_offset. */
2493 #if 0
2494 tab_offset += width;
2495 if (val.vpos) tab_offset = 0;
2496 #endif
2497 if (pos != val.bufpos)
2498 last_text_vpos
2499 /* Next line, unless prev line ended in end of buffer with no cr */
2500 = vpos - (val.vpos && FETCH_BYTE (val.bufpos - 1) != '\n');
2501 pos = val.bufpos;
2502 }
2503
2504 /* There are two cases:
2505 1) we have displayed down to the bottom of the window
2506 2) we have scrolled lines below stop_vpos by scroll_amount */
2507
2508 if (vpos == height)
2509 {
2510 /* If last line is continued in middle of character,
2511 include the split character in the text considered on the frame */
2512 if (val.hpos < lmargin)
2513 val.bufpos++;
2514 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2515 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2516 }
2517
2518 /* If scrolling made blank lines at window bottom,
2519 redisplay to fill those lines */
2520 if (scroll_amount < 0)
2521 {
2522 /* Don't consider these lines for general-purpose scrolling.
2523 That will save time in the scrolling computation. */
2524 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2525 vpos = xp.vpos;
2526 pos = xp.bufpos;
2527 val.hpos = xp.hpos;
2528 val.tab_offset = xp.tab_offset;
2529 if (pos == ZV)
2530 { /* Display from next line */
2531 vpos = height + scroll_amount;
2532 val.hpos = lmargin;
2533 val.tab_offset = 0;
2534 }
2535 else if (xp.contin && xp.hpos != lmargin)
2536 {
2537 val.hpos = xp.prevhpos - width + lmargin;
2538 val.tab_offset = xp.tab_offset + bp.prevhpos - width;
2539 DEC_POS (pos);
2540 }
2541
2542 blank_end_of_window = 1;
2543 /* The following code is omitted because we maintain tab offset
2544 in val.tab_offset. */
2545 #if 0
2546 tab_offset = pos_tab_offset (w, pos);
2547 /* If we are starting display in mid-character, correct tab_offset
2548 to account for passing the line that that character starts in. */
2549 if (val.hpos < lmargin)
2550 tab_offset += width;
2551 #endif
2552 while (vpos < height)
2553 {
2554 val = *display_text_line (w, pos, top + vpos++, val.hpos,
2555 val.tab_offset, val.ovstring_chars_done);
2556 /* The following code is omitted because we maintain tab
2557 offset in val.tab_offset. */
2558 #if 0
2559 tab_offset += width;
2560 if (val.vpos) tab_offset = 0;
2561 #endif /* 0 */
2562 pos = val.bufpos;
2563 }
2564
2565 /* Here is a case where display_text_line sets cursor_vpos wrong.
2566 Make it be fixed up, below. */
2567 if (xp.bufpos == ZV
2568 && xp.bufpos == PT)
2569 cursor_vpos = -1;
2570 }
2571
2572 /* If bottom just moved off end of frame, change mode line percentage. */
2573 if (XFASTINT (w->window_end_pos) == 0
2574 && Z != val.bufpos)
2575 w->update_mode_line = Qt;
2576
2577 /* Attempt to adjust end-of-text positions to new bottom line */
2578 if (scroll_amount)
2579 {
2580 delta = height - xp.vpos;
2581 if (delta < 0
2582 || (delta > 0 && xp.bufpos <= ZV)
2583 || (delta == 0 && xp.hpos))
2584 {
2585 val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w);
2586 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2587 XSETFASTINT (w->window_end_vpos,
2588 XFASTINT (w->window_end_vpos) + val.vpos);
2589 }
2590 }
2591
2592 w->window_end_valid = Qnil;
2593
2594 /* If point was not in a line that was displayed, find it */
2595 if (cursor_vpos < 0)
2596 {
2597 findpoint:
2598 val = *compute_motion (start, 0, lmargin, 0, PT,
2599 /* Don't care for VPOS... */
2600 1 << (BITS_PER_SHORT - 1),
2601 /* ... nor HPOS. */
2602 1 << (BITS_PER_SHORT - 1),
2603 width, hscroll, pos_tab_offset (w, start), w);
2604 /* Admit failure if point is off frame now */
2605 if (val.vpos >= height)
2606 {
2607 for (vpos = 0; vpos < height; vpos++)
2608 cancel_line (vpos + top, f);
2609 return 0;
2610 }
2611 cursor_vpos = val.vpos + top;
2612 cursor_hpos = WINDOW_LEFT_MARGIN (w) + minmax (0, val.hpos, width);
2613 }
2614
2615 FRAME_CURSOR_X (f) = cursor_hpos;
2616 FRAME_CURSOR_Y (f) = cursor_vpos;
2617
2618 if (debug_end_pos)
2619 {
2620 val = *compute_motion (start, 0, lmargin, 0, ZV,
2621 height, - (1 << (BITS_PER_SHORT - 1)),
2622 width, hscroll, pos_tab_offset (w, start), w);
2623 if (val.vpos != XFASTINT (w->window_end_vpos))
2624 abort ();
2625 if (XFASTINT (w->window_end_pos)
2626 != Z - val.bufpos)
2627 abort ();
2628 }
2629
2630 return 1;
2631 }
2632 \f
2633 /* Copy LEN glyphs starting address FROM to the rope TO.
2634 But don't actually copy the parts that would come in before S.
2635 Value is TO, advanced past the copied data.
2636 F is the frame we are displaying in. */
2637
2638 static GLYPH *
2639 copy_part_of_rope (f, to, s, from, len, face)
2640 FRAME_PTR f;
2641 register GLYPH *to; /* Copy to here. */
2642 register GLYPH *s; /* Starting point. */
2643 Lisp_Object *from; /* Data to copy. */
2644 int len;
2645 int face; /* Face to apply to glyphs which don't specify one. */
2646 {
2647 int n = len;
2648 register Lisp_Object *fp = from;
2649 /* These cache the results of the last call to compute_glyph_face. */
2650 int last_code = -1;
2651 int last_merged = 0;
2652
2653 #ifdef HAVE_FACES
2654 if (! FRAME_TERMCAP_P (f))
2655 while (n--)
2656 {
2657 GLYPH glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2658 int facecode;
2659 unsigned int c = FAST_GLYPH_CHAR (glyph);
2660
2661 if (c > MAX_CHAR)
2662 /* For an invalid character code, use space. */
2663 c = ' ';
2664
2665 if (FAST_GLYPH_FACE (glyph) == 0)
2666 /* If GLYPH has no face code, use FACE. */
2667 facecode = face;
2668 else if (FAST_GLYPH_FACE (glyph) == last_code)
2669 /* If it's same as previous glyph, use same result. */
2670 facecode = last_merged;
2671 else
2672 {
2673 /* Merge this glyph's face and remember the result. */
2674 last_code = FAST_GLYPH_FACE (glyph);
2675 last_merged = facecode = compute_glyph_face (f, last_code, face);
2676 }
2677
2678 if (to >= s)
2679 *to = FAST_MAKE_GLYPH (c, facecode);
2680 ++to;
2681 ++fp;
2682 }
2683 else
2684 #endif
2685 while (n--)
2686 {
2687 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2688 ++to;
2689 ++fp;
2690 }
2691 return to;
2692 }
2693
2694 /* Correct a glyph by replacing its specified user-level face code
2695 with a displayable computed face code. */
2696
2697 static GLYPH
2698 fix_glyph (f, glyph, cface)
2699 FRAME_PTR f;
2700 GLYPH glyph;
2701 int cface;
2702 {
2703 #ifdef HAVE_FACES
2704 if (! FRAME_TERMCAP_P (f))
2705 {
2706 if (FAST_GLYPH_FACE (glyph) != 0)
2707 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2708 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2709 }
2710 #endif
2711 return glyph;
2712 }
2713 \f
2714 /* Display one line of window W, starting at position START in W's buffer.
2715
2716 Display starting at horizontal position HPOS, expressed relative to
2717 W's left edge. In situations where the text at START shouldn't
2718 start at the left margin (i.e. when the window is hscrolled, or
2719 we're continuing a line which left off in the midst of a
2720 multi-column character), HPOS should be negative; we throw away
2721 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2722 account.
2723
2724 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2725
2726 OVSTR_DONE is the number of chars of overlay before/after strings
2727 at this position which have already been processed.
2728
2729 Display on position VPOS on the frame. It is origin 0, relative to
2730 the top of the frame, not W.
2731
2732 Returns a STRUCT POSITION giving character to start next line with
2733 and where to display it, including a zero or negative hpos.
2734 The vpos field is not really a vpos; it is 1 unless the line is continued */
2735
2736 struct position val_display_text_line;
2737
2738 static struct position *
2739 display_text_line (w, start, vpos, hpos, taboffset, ovstr_done)
2740 struct window *w;
2741 int start;
2742 int vpos;
2743 int hpos;
2744 int taboffset;
2745 int ovstr_done;
2746 {
2747 register int pos = start;
2748 register int c;
2749 register GLYPH *p1;
2750 register int pause;
2751 register unsigned char *p;
2752 GLYPH *endp;
2753 register GLYPH *leftmargin;
2754 register GLYPH *p1prev;
2755 register GLYPH *p1start;
2756 int prevpos;
2757 int *charstart;
2758 FRAME_PTR f = XFRAME (w->frame);
2759 int tab_width = XINT (current_buffer->tab_width);
2760 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2761 int width = window_internal_width (w) - 1;
2762 struct position val;
2763 int lastpos;
2764 int invis;
2765 int last_invis_skip = 0;
2766 Lisp_Object last_invis_prop;
2767 int hscroll = XINT (w->hscroll);
2768 int truncate = (hscroll
2769 || (truncate_partial_width_windows
2770 && !WINDOW_FULL_WIDTH_P (w))
2771 || !NILP (current_buffer->truncate_lines));
2772
2773 /* 1 if we should highlight the region. */
2774 int highlight_region
2775 = (!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active)
2776 && XWINDOW (current_buffer->last_selected_window) == w);
2777 int region_beg, region_end;
2778
2779 int selective = (INTEGERP (current_buffer->selective_display)
2780 ? XINT (current_buffer->selective_display)
2781 : !NILP (current_buffer->selective_display) ? -1 : 0);
2782 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2783 register struct Lisp_Char_Table *dp = window_display_table (w);
2784
2785 Lisp_Object default_invis_vector[3];
2786 /* Number of characters of ellipsis to display after an invisible line
2787 if it calls for an ellipsis.
2788 Note that this value can be nonzero regardless of whether
2789 selective display is enabled--you must check that separately. */
2790 int selective_rlen
2791 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2792 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2793 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
2794 /* This is the sequence of Lisp objects to display
2795 when there are invisible lines. */
2796 Lisp_Object *invis_vector_contents
2797 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2798 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2799 : default_invis_vector);
2800
2801 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2802 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp)))
2803 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2804 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2805 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp)))
2806 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2807
2808 /* If 1, we must handle multibyte characters. */
2809 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
2810 /* Length of multibyte form of each character. */
2811 int len;
2812 /* Glyphs generated should be set this bit mask if text must be
2813 displayed from right to left. */
2814 GLYPH rev_dir_bit = (NILP (current_buffer->direction_reversed)
2815 ? 0 : GLYPH_MASK_REV_DIR);
2816
2817 /* The next buffer location at which the face should change, due
2818 to overlays or text property changes. */
2819 int next_face_change;
2820
2821 /* The next location where the `invisible' property changes, or an
2822 overlay starts or ends. */
2823 int next_boundary;
2824
2825 /* The face we're currently using. */
2826 int current_face = 0;
2827 int i;
2828
2829 XSETFASTINT (default_invis_vector[2], '.');
2830 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2831
2832 hpos += WINDOW_LEFT_MARGIN (w);
2833 get_display_line (f, vpos, WINDOW_LEFT_MARGIN (w));
2834 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2835
2836 /* Show where to highlight the region. */
2837 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2838 /* Maybe highlight only in selected window. */
2839 && (highlight_nonselected_windows
2840 || w == XWINDOW (selected_window)))
2841 {
2842 region_beg = marker_position (current_buffer->mark);
2843 if (PT < region_beg)
2844 {
2845 region_end = region_beg;
2846 region_beg = PT;
2847 }
2848 else
2849 region_end = PT;
2850 w->region_showing = Qt;
2851 }
2852 else
2853 region_beg = region_end = -1;
2854
2855 if (MINI_WINDOW_P (w)
2856 && start == BEG
2857 && vpos == XFASTINT (w->top))
2858 {
2859 if (! NILP (minibuf_prompt))
2860 {
2861 minibuf_prompt_width
2862 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2863 XSTRING (minibuf_prompt)->size, hpos,
2864 /* Display a space if we truncate. */
2865 ' ',
2866 1, -1,
2867 /* Truncate the prompt a little before the
2868 margin, so user input can at least start
2869 on the first line. */
2870 (XFASTINT (w->width) > 10
2871 ? XFASTINT (w->width) - 4 : -1))
2872 - hpos);
2873 hpos += minibuf_prompt_width;
2874 taboffset -= minibuf_prompt_width;
2875 }
2876 else
2877 minibuf_prompt_width = 0;
2878 }
2879
2880 /* If we're hscrolled at all, use compute_motion to skip over any
2881 text off the left edge of the window. compute_motion may know
2882 tricks to do this faster than we can. */
2883 if (hpos < 0)
2884 {
2885 struct position *left_edge
2886 = compute_motion (pos, vpos, hpos, 0,
2887 ZV, vpos, 0,
2888 width, hscroll, taboffset, w);
2889
2890 /* Retrieve the buffer position and column provided by
2891 compute_motion. We can't assume that the column will be
2892 zero, because you may have multi-column characters crossing
2893 the left margin.
2894
2895 compute_motion may have moved us past the screen position we
2896 requested, if we hit a multi-column character, or the end of
2897 the line. If so, back up. */
2898 if (left_edge->vpos > vpos
2899 || left_edge->hpos > 0)
2900 {
2901 pos = left_edge->bufpos;
2902 /* Since this should not be a valid multibyte character, we
2903 can decrease POS by 1. */
2904 pos--;
2905 hpos = left_edge->prevhpos;
2906 }
2907 else
2908 {
2909 pos = left_edge->bufpos;
2910 hpos = left_edge->hpos;
2911 }
2912 }
2913
2914 desired_glyphs->bufp[vpos] = start;
2915 p1 = desired_glyphs->glyphs[vpos] + hpos;
2916 p1start = p1;
2917 charstart = desired_glyphs->charstarts[vpos] + hpos;
2918 /* In case we don't ever write anything into it... */
2919 desired_glyphs->charstarts[vpos][WINDOW_LEFT_MARGIN (w)] = -1;
2920 leftmargin = desired_glyphs->glyphs[vpos] + WINDOW_LEFT_MARGIN (w);
2921 endp = leftmargin + width;
2922
2923 /* Arrange the overlays nicely for our purposes. Usually, we call
2924 display_text_line on only one line at a time, in which case this
2925 can't really hurt too much, or we call it on lines which appear
2926 one after another in the buffer, in which case all calls to
2927 recenter_overlay_lists but the first will be pretty cheap. */
2928 recenter_overlay_lists (current_buffer, pos);
2929
2930 /* Loop generating characters.
2931 Stop at end of buffer, before newline,
2932 if reach or pass continuation column,
2933 or at face change. */
2934 pause = pos;
2935 next_face_change = pos;
2936 next_boundary = pos;
2937 p1prev = p1;
2938 prevpos = pos;
2939 while (1)
2940 {
2941 if (pos >= pause)
2942 {
2943 int e_t_h;
2944
2945 while (pos == next_boundary)
2946 {
2947 Lisp_Object position, limit, prop, ww;
2948
2949 /* Display the overlay strings here, unless we're at ZV
2950 and have already displayed the appropriate strings
2951 on an earlier line. */
2952 if (pos < ZV || !zv_strings_seen++)
2953 {
2954 int ovlen;
2955 unsigned char *ovstr;
2956 ovlen = overlay_strings (pos, w, &ovstr);
2957
2958 if (ovlen > 0)
2959 {
2960 /* Skip the ones we did in a previous line. */
2961 ovstr += ovstr_done;
2962 ovlen -= ovstr_done;
2963
2964 while (ovlen > 0)
2965 {
2966 int charset, cols;
2967 GLYPH g;
2968
2969 if (multibyte)
2970 {
2971 c = STRING_CHAR_AND_LENGTH (ovstr, ovlen, len);
2972 ovstr += len, ovlen -= len, ovstr_done += len;
2973 charset = CHAR_CHARSET (c);
2974 cols = (charset == CHARSET_COMPOSITION
2975 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
2976 : CHARSET_WIDTH (charset));
2977 }
2978 else
2979 {
2980 c = *ovstr++, ovlen--, ovstr_done++;
2981 cols = 1;
2982 }
2983 g = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
2984 while (cols-- > 0)
2985 {
2986 if (p1 >= leftmargin && p1 < endp)
2987 *p1 = g, g |= GLYPH_MASK_PADDING;
2988 p1++;
2989 }
2990 }
2991 /* If we did all the overlay strings
2992 and we have room for text, clear ovstr_done
2993 just for neatness' sake. */
2994 if (ovlen == 0 && p1 < endp)
2995 ovstr_done = 0;
2996 }
2997 }
2998
2999 /* Did we reach point? Record the cursor location. */
3000 if (pos == PT && cursor_vpos < 0)
3001 {
3002 cursor_vpos = vpos;
3003 cursor_hpos = p1 - leftmargin;
3004 }
3005
3006 if (pos >= ZV)
3007 break;
3008
3009 XSETFASTINT (position, pos);
3010 limit = Fnext_overlay_change (position);
3011 #ifdef USE_TEXT_PROPERTIES
3012 /* This is just an estimate to give reasonable
3013 performance; nothing should go wrong if it is too small. */
3014 if (XFASTINT (limit) > pos + 50)
3015 {
3016 int limitpos = pos + 50;
3017 if (limitpos < Z)
3018 INC_POS (limitpos); /* Adjust to character boundary. */
3019 XSETFASTINT (limit, limitpos);
3020 }
3021 limit = Fnext_single_property_change (position, Qinvisible,
3022 Fcurrent_buffer (), limit);
3023 #endif
3024 next_boundary = XFASTINT (limit);
3025 /* if the `invisible' property is set, we can skip to
3026 the next property change. */
3027 XSETWINDOW (ww, w);
3028 prop = Fget_char_property (position, Qinvisible, ww);
3029 if (TEXT_PROP_MEANS_INVISIBLE (prop))
3030 {
3031 if (pos < PT && next_boundary >= PT)
3032 {
3033 cursor_vpos = vpos;
3034 cursor_hpos = p1 - leftmargin;
3035 }
3036 pos = next_boundary;
3037 last_invis_skip = pos;
3038 last_invis_prop = prop;
3039 }
3040 }
3041
3042 /* Did we reach point? Record the cursor location. */
3043 if (pos == PT && cursor_vpos < 0)
3044 {
3045 cursor_vpos = vpos;
3046 cursor_hpos = p1 - leftmargin;
3047 }
3048
3049 /* Did we hit the end of the visible region of the buffer?
3050 Stop here. */
3051 if (pos >= ZV)
3052 {
3053 /* Update charstarts for the end of this line. */
3054 /* Do nothing if off the left edge or at the right edge. */
3055 if (p1 >= leftmargin && p1 + 1 != endp)
3056 {
3057 int *p2x = &charstart[(p1 < leftmargin
3058 ? leftmargin : p1)
3059 - p1start];
3060 *p2x++ = pos;
3061 }
3062 break;
3063 }
3064
3065 /* Figure out where (if at all) the
3066 redisplay_end_trigger-hook should run. */
3067 if (MARKERP (w->redisplay_end_trigger)
3068 && XMARKER (w->redisplay_end_trigger)->buffer != 0)
3069 e_t_h = marker_position (w->redisplay_end_trigger);
3070 else if (INTEGERP (w->redisplay_end_trigger))
3071 e_t_h = XINT (w->redisplay_end_trigger);
3072 else
3073 e_t_h = ZV;
3074
3075 /* If we've gone past the place to run a hook,
3076 run the hook. */
3077 if (pos >= e_t_h && e_t_h != ZV)
3078 {
3079 Lisp_Object args[3];
3080
3081 args[0] = Qredisplay_end_trigger_functions;
3082 XSETWINDOW (args[1], w);
3083 XSETINT (args[2], e_t_h);
3084
3085 /* Since we are *trying* to run these functions,
3086 don't try to run them again, even if they get an error. */
3087 w->redisplay_end_trigger = Qnil;
3088 Frun_hook_with_args (3, args);
3089
3090 e_t_h = ZV;
3091 /* Notice if it changed the face of this character. */
3092 next_face_change = pos;
3093 }
3094
3095 #ifdef HAVE_FACES
3096 /* Did we hit a face change? Figure out what face we should
3097 use now. We also hit this the first time through the
3098 loop, to see what face we should start with. */
3099 if (pos >= next_face_change
3100 && (FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f)))
3101 {
3102 int limit = pos + 50;
3103
3104 if (limit < Z && !CHAR_HEAD_P (POS_ADDR (limit)))
3105 INC_POS (limit); /* Adjust to character boundary. */
3106 current_face = compute_char_face (f, w, pos,
3107 region_beg, region_end,
3108 &next_face_change, limit, 0);
3109 }
3110 #endif
3111
3112 /* Compute the next place we need to stop
3113 and do something special; set PAUSE. */
3114
3115 pause = ZV;
3116
3117 if (pos < next_boundary && next_boundary < pause)
3118 pause = next_boundary;
3119 if (pos < next_face_change && next_face_change < pause)
3120 pause = next_face_change;
3121
3122 if (e_t_h < pause)
3123 pause = e_t_h;
3124
3125 /* Wouldn't you hate to read the next line to someone over
3126 the phone? */
3127 if (pos < PT && PT < pause)
3128 pause = PT;
3129 if (pos < GPT && GPT < pause)
3130 pause = GPT;
3131
3132 p = POS_ADDR (pos);
3133 }
3134
3135 if (p1 >= endp)
3136 break;
3137
3138 p1prev = p1;
3139
3140 if (multibyte)
3141 /* PAUSE is surely at character boundary. */
3142 c = STRING_CHAR_AND_LENGTH (p, pause - pos, len), p += len;
3143 else
3144 c = *p++, len = 1;
3145 /* Let a display table override all standard display methods. */
3146 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3147 {
3148 p1 = copy_part_of_rope (f, p1, leftmargin,
3149 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3150 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3151 current_face, rev_dir_bit);
3152 }
3153 else if (c >= 040 && c < 0177)
3154 {
3155 if (p1 >= leftmargin)
3156 *p1 = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3157 p1++;
3158 }
3159 else if (c == '\n')
3160 {
3161 invis = 0;
3162 if (last_invis_skip == pos
3163 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
3164 invis = 1;
3165 while (pos + 1 < ZV
3166 && selective > 0
3167 && indented_beyond_p (pos + 1, selective))
3168 {
3169 invis = 1;
3170 pos = find_next_newline (pos + 1, 1);
3171 if (FETCH_BYTE (pos - 1) == '\n')
3172 pos--;
3173 }
3174 if (invis && selective_rlen > 0 && p1 >= leftmargin)
3175 {
3176 p1 += selective_rlen;
3177 if (p1 - leftmargin > width)
3178 p1 = endp;
3179 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
3180 (p1 - p1prev), current_face, rev_dir_bit);
3181 }
3182 #ifdef HAVE_FACES
3183 /* Draw the face of the newline character as extending all the
3184 way to the end of the frame line. */
3185 if (current_face)
3186 {
3187 if (p1 < leftmargin)
3188 p1 = leftmargin;
3189 while (p1 < endp)
3190 *p1++ = FAST_MAKE_GLYPH (' ', current_face) | rev_dir_bit;
3191 }
3192 #endif
3193
3194 /* Update charstarts for the newline that ended this line. */
3195 /* Do nothing here for a char that's entirely off the left edge
3196 or if it starts at the right edge. */
3197 if (p1 >= leftmargin && p1prev != endp)
3198 {
3199 /* Store the newline's position into charstarts
3200 for the column where the newline starts.
3201 Store -1 for the rest of the glyphs it occupies. */
3202 int *p2x = &charstart[(p1prev < leftmargin
3203 ? leftmargin : p1prev)
3204 - p1start];
3205 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3206
3207 *p2x++ = pos;
3208 while (p2x < p2)
3209 *p2x++ = -1;
3210 }
3211
3212 break;
3213 }
3214 else if (c == '\t')
3215 {
3216 do
3217 {
3218 if (p1 >= leftmargin && p1 < endp)
3219 *p1 = MAKE_GLYPH (f, ' ', current_face) | rev_dir_bit;
3220 p1++;
3221 }
3222 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
3223 % tab_width);
3224 }
3225 else if (c == Ctl ('M') && selective == -1)
3226 {
3227 pos = find_next_newline (pos, 1);
3228 if (FETCH_BYTE (pos - 1) == '\n')
3229 pos--;
3230 if (selective_rlen > 0)
3231 {
3232 p1 += selective_rlen;
3233 if (p1 - leftmargin > width)
3234 p1 = endp;
3235 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
3236 (p1 - p1prev), current_face, rev_dir_bit);
3237 }
3238 #ifdef HAVE_FACES
3239 /* Draw the face of the newline character as extending all the
3240 way to the end of the frame line. */
3241 if (current_face)
3242 {
3243 if (p1 < leftmargin)
3244 p1 = leftmargin;
3245 while (p1 < endp)
3246 *p1++ = FAST_MAKE_GLYPH (' ', current_face) | rev_dir_bit;
3247 }
3248 #endif
3249
3250 /* Update charstarts for the ^M that ended this line. */
3251 /* Do nothing here for a char that's entirely off the left edge
3252 or if it starts at the right edge. */
3253 if (p1 >= leftmargin && p1prev != endp)
3254 {
3255 /* Store the newline's position into charstarts
3256 for the column where the newline starts.
3257 Store -1 for the rest of the glyphs it occupies. */
3258 int *p2x = &charstart[(p1prev < leftmargin
3259 ? leftmargin : p1prev)
3260 - p1start];
3261 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3262
3263 *p2x++ = pos;
3264 while (p2x < p2)
3265 *p2x++ = -1;
3266 }
3267 break;
3268 }
3269 else if (c < 0200 && ctl_arrow)
3270 {
3271 if (p1 >= leftmargin)
3272 *p1 = (fix_glyph
3273 (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
3274 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp)))
3275 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3276 current_face)
3277 | rev_dir_bit);
3278 p1++;
3279 if (p1 >= leftmargin && p1 < endp)
3280 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face) | rev_dir_bit;
3281 p1++;
3282 }
3283 else if (len == 1)
3284 {
3285 /* C is not a multibyte character. */
3286 if (p1 >= leftmargin)
3287 *p1 = (fix_glyph
3288 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
3289 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
3290 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3291 current_face)
3292 | rev_dir_bit);
3293 p1++;
3294 if (p1 >= leftmargin && p1 < endp)
3295 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face) | rev_dir_bit;
3296 p1++;
3297 if (p1 >= leftmargin && p1 < endp)
3298 *p1 = (MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face)
3299 | rev_dir_bit);
3300 p1++;
3301 if (p1 >= leftmargin && p1 < endp)
3302 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face) | rev_dir_bit;
3303 p1++;
3304 }
3305 else
3306 {
3307 /* C is a multibyte character. */
3308 int charset = CHAR_CHARSET (c);
3309 int columns = (charset == CHARSET_COMPOSITION
3310 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
3311 : CHARSET_WIDTH (charset));
3312 GLYPH g = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3313
3314 while (columns--)
3315 {
3316 if (p1 >= leftmargin && p1 < endp)
3317 *p1 = g, g |= GLYPH_MASK_PADDING;
3318 p1++;
3319 }
3320 }
3321
3322 prevpos = pos;
3323 pos += len;
3324
3325 /* Update charstarts for the character just output. */
3326
3327 /* Do nothing here for a char that's entirely off the left edge. */
3328 if (p1 >= leftmargin)
3329 {
3330 /* Store the char's position into charstarts
3331 for the first glyph occupied by this char.
3332 Store -1 for the rest of the glyphs it occupies. */
3333 if (p1 != p1prev)
3334 {
3335 int *p2x = &charstart[(p1prev < leftmargin
3336 ? leftmargin : p1prev)
3337 - p1start];
3338 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3339
3340 if (p2x < p2)
3341 *p2x++ = prevpos;
3342 while (p2x < p2)
3343 *p2x++ = -1;
3344 }
3345 }
3346 }
3347
3348 val.hpos = - XINT (w->hscroll);
3349 if (val.hpos)
3350 val.hpos++;
3351
3352 val.vpos = 1;
3353
3354 lastpos = pos;
3355
3356 /* Store 0 in this charstart line for the positions where
3357 there is no character. But do leave what was recorded
3358 for the character that ended the line. */
3359 /* Add 1 in the endtest to compensate for the fact that ENDP was
3360 made from WIDTH, which is 1 less than the window's actual
3361 internal width. */
3362 i = p1 - p1start + 1;
3363 if (p1 < leftmargin)
3364 i += leftmargin - p1;
3365 for (; i < endp - p1start + 1; i++)
3366 charstart[i] = 0;
3367
3368 /* Handle continuation in middle of a character */
3369 /* by backing up over it */
3370 if (p1 > endp)
3371 {
3372 /* Don't back up if we never actually displayed any text.
3373 This occurs when the minibuffer prompt takes up the whole line. */
3374 if (p1prev)
3375 {
3376 /* Start the next line with that same character whose
3377 character code is C and the length of multi-byte form is
3378 LEN. */
3379 pos = prevpos;
3380
3381 if (len == 1)
3382 /* C is not a multi-byte character. We can break it and
3383 start from the middle column in the next line. So,
3384 adjust VAL.HPOS to skip the columns output on this
3385 line. */
3386 val.hpos += p1prev - endp;
3387 else
3388 {
3389 /* C is a multibyte character. Since we can't broke it
3390 in the middle, the whole character should be driven
3391 into the next line. */
3392 /* As the result, the actual columns occupied by the
3393 text on this line is less than WIDTH. VAL.TAB_OFFSET
3394 must be adjusted. */
3395 taboffset = taboffset + (p1prev - endp);
3396 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3397 {
3398 GLYPH g = fix_glyph (f, truncate ? truncator : continuer, 0);
3399 while (p1prev < endp)
3400 *p1prev++ = g;
3401 }
3402 /* If POINT is at POS, cursor should not on this line. */
3403 lastpos = pos;
3404 if (PT == pos)
3405 cursor_vpos = -1;
3406 }
3407 }
3408
3409 /* Keep in this line everything up to the continuation column. */
3410 p1 = endp;
3411 }
3412
3413 /* Finish deciding which character to start the next line on,
3414 and what hpos to start it at.
3415 Also set `lastpos' to the last position which counts as "on this line"
3416 for cursor-positioning. */
3417
3418 if (pos < ZV)
3419 {
3420 if (FETCH_BYTE (pos) == '\n')
3421 {
3422 /* If stopped due to a newline, start next line after it */
3423 pos++;
3424 val.tab_offset = 0;
3425 /* Check again for hidden lines, in case the newline occurred exactly
3426 at the right margin. */
3427 while (pos < ZV && selective > 0
3428 && indented_beyond_p (pos, selective))
3429 pos = find_next_newline (pos, 1);
3430 }
3431 else
3432 /* Stopped due to right margin of window */
3433 {
3434 if (truncate)
3435 {
3436 *p1++ = fix_glyph (f, truncator, 0);
3437 /* Truncating => start next line after next newline,
3438 and point is on this line if it is before the newline,
3439 and skip none of first char of next line */
3440 do
3441 pos = find_next_newline (pos, 1);
3442 while (pos < ZV && selective > 0
3443 && indented_beyond_p (pos, selective));
3444 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
3445
3446 lastpos = pos - (FETCH_BYTE (pos - 1) == '\n');
3447 val.tab_offset = 0;
3448 }
3449 else
3450 {
3451 *p1++ = fix_glyph (f, continuer, 0);
3452 val.vpos = 0;
3453 lastpos--;
3454 val.tab_offset = taboffset + width;
3455 }
3456 }
3457 }
3458 else
3459 val.tab_offset = 0;
3460
3461 /* If point is at eol or in invisible text at eol,
3462 record its frame location now. */
3463
3464 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
3465 {
3466 cursor_vpos = vpos;
3467 cursor_hpos = p1 - leftmargin;
3468 }
3469
3470 if (cursor_vpos == vpos)
3471 {
3472 if (cursor_hpos < 0) cursor_hpos = 0;
3473 if (cursor_hpos > width) cursor_hpos = width;
3474 cursor_hpos += WINDOW_LEFT_MARGIN (w);
3475 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
3476 {
3477 if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f)
3478 && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window)))
3479 {
3480 FRAME_CURSOR_Y (f) = cursor_vpos;
3481 FRAME_CURSOR_X (f) = cursor_hpos;
3482 }
3483
3484 if (w == XWINDOW (selected_window))
3485 {
3486 /* Line is not continued and did not start
3487 in middle of character */
3488 if ((hpos - WINDOW_LEFT_MARGIN (w)
3489 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
3490 && val.vpos)
3491 {
3492 this_line_bufpos = start;
3493 this_line_buffer = current_buffer;
3494 this_line_vpos = cursor_vpos;
3495 this_line_start_hpos = hpos;
3496 this_line_endpos = Z - lastpos;
3497 }
3498 else
3499 this_line_bufpos = 0;
3500 }
3501 }
3502 }
3503
3504 /* If hscroll and line not empty, insert truncation-at-left marker */
3505 if (hscroll && lastpos != start)
3506 {
3507 GLYPH g = fix_glyph (f, truncator, 0);
3508 *leftmargin = g;
3509 if (p1 <= leftmargin)
3510 p1 = leftmargin + 1;
3511 else /* MULE: it may be a wide-column character */
3512 {
3513 p1prev = leftmargin + 1;
3514 while (p1prev < p1 && *p1prev & GLYPH_MASK_PADDING)
3515 *p1prev++ = g;
3516 }
3517 }
3518
3519 if (!WINDOW_RIGHTMOST_P (w))
3520 {
3521 endp++;
3522 if (p1 < leftmargin) p1 = leftmargin;
3523 while (p1 < endp) *p1++ = SPACEGLYPH;
3524
3525 /* Don't draw vertical bars if we're using scroll bars. They're
3526 covered up by the scroll bars, and it's distracting to see
3527 them when the scroll bar windows are flickering around to be
3528 reconfigured. */
3529 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3530 {
3531 int i;
3532 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3533 *p1++ = SPACEGLYPH;
3534 }
3535 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3536 *p1++ = (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
3537 ? XINT (DISP_BORDER_GLYPH (dp))
3538 : '|');
3539 }
3540 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
3541 p1 - desired_glyphs->glyphs[vpos]);
3542 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3543
3544 /* If the start of this line is the overlay arrow-position,
3545 then put the arrow string into the display-line. */
3546
3547 if (MARKERP (Voverlay_arrow_position)
3548 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
3549 && start == marker_position (Voverlay_arrow_position)
3550 && STRINGP (Voverlay_arrow_string)
3551 && ! overlay_arrow_seen)
3552 {
3553 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
3554 int i;
3555 int len = XSTRING (Voverlay_arrow_string)->size;
3556 int arrow_end;
3557
3558 if (len > width)
3559 len = width;
3560 #ifdef HAVE_FACES
3561 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
3562 {
3563 /* If the arrow string has text props, obey them when displaying. */
3564 for (i = 0; i < len; i++)
3565 {
3566 int c = p[i];
3567 Lisp_Object face, ilisp;
3568 int newface;
3569
3570 XSETFASTINT (ilisp, i);
3571 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
3572 newface = compute_glyph_face_1 (f, face, 0);
3573 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
3574 }
3575 }
3576 else
3577 #endif /* HAVE_FACES */
3578 {
3579 for (i = 0; i < len; i++)
3580 leftmargin[i] = p[i];
3581 }
3582
3583 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3584 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
3585 if (desired_glyphs->used[vpos] < arrow_end)
3586 desired_glyphs->used[vpos] = arrow_end;
3587
3588 overlay_arrow_seen = 1;
3589 }
3590
3591 val.bufpos = pos;
3592 val.ovstring_chars_done = ovstr_done;
3593 val_display_text_line = val;
3594 return &val_display_text_line;
3595 }
3596 \f
3597 /* Redisplay the menu bar in the frame for window W. */
3598
3599 static void
3600 display_menu_bar (w)
3601 struct window *w;
3602 {
3603 Lisp_Object items, tail;
3604 register int vpos = 0;
3605 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3606 int maxendcol = FRAME_WIDTH (f);
3607 int hpos = 0;
3608 int i;
3609
3610 #ifdef HAVE_NTGUI
3611 if (!NILP (Vwindow_system))
3612 return;
3613 #endif
3614
3615 #ifdef USE_X_TOOLKIT
3616 if (FRAME_X_P (f))
3617 return;
3618 #endif /* USE_X_TOOLKIT */
3619
3620 get_display_line (f, vpos, 0);
3621
3622 items = FRAME_MENU_BAR_ITEMS (f);
3623 for (i = 0; i < XVECTOR (items)->size; i += 4)
3624 {
3625 Lisp_Object pos, string;
3626 string = XVECTOR (items)->contents[i + 1];
3627 if (NILP (string))
3628 break;
3629
3630 XSETFASTINT (XVECTOR (items)->contents[i + 3], hpos);
3631
3632 if (hpos < maxendcol)
3633 hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos,
3634 XSTRING (string)->data,
3635 XSTRING (string)->size,
3636 hpos, 0, 0, hpos, maxendcol);
3637 /* Put a space between items. */
3638 if (hpos < maxendcol)
3639 {
3640 int hpos1 = hpos + 1;
3641 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
3642 min (hpos1, maxendcol), maxendcol);
3643 }
3644 }
3645
3646 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3647 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3648
3649 /* Fill out the line with spaces. */
3650 if (maxendcol > hpos)
3651 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol);
3652
3653 /* Clear the rest of the lines allocated to the menu bar. */
3654 vpos++;
3655 while (vpos < FRAME_MENU_BAR_LINES (f))
3656 get_display_line (f, vpos++, 0);
3657 }
3658 \f
3659 /* Display the mode line for window w */
3660
3661 static void
3662 display_mode_line (w)
3663 struct window *w;
3664 {
3665 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
3666 register int left = WINDOW_LEFT_MARGIN (w);
3667 register int right = WINDOW_RIGHT_MARGIN (w);
3668 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3669
3670 line_number_displayed = 0;
3671 w->column_number_displayed = Qnil;
3672
3673 get_display_line (f, vpos, left);
3674
3675 /* Temporarily make frame F's kboard the current kboard
3676 so that kboard-local variables in the mode_line_format
3677 will get the right values. */
3678 push_frame_kboard (f);
3679
3680 display_mode_element (w, vpos, left, 0, right, right,
3681 current_buffer->mode_line_format);
3682
3683 pop_frame_kboard ();
3684
3685 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3686
3687 /* Put the mode line in inverse video.
3688 Use faces if possible, since that lets us handle
3689 partial-width windows and avoid inverting the scroll bar columns. */
3690 #ifdef HAVE_FACES
3691 if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video)
3692 {
3693 /* For a partial width window, explicitly set face of each glyph. */
3694 int i;
3695 unsigned int padding;
3696 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3697 for (i = left; i < right; ++i)
3698 {
3699 padding = ptr[i] & GLYPH_MASK_PADDING;
3700 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1) | padding;
3701 }
3702 }
3703 else
3704 #endif
3705
3706 /* Make the mode line inverse video if the entire line
3707 is made of mode lines.
3708 I.e. if this window is full width,
3709 or if it is the child of a full width window
3710 (which implies that that window is split side-by-side
3711 and the rest of this line is mode lines of the sibling windows). */
3712 if (WINDOW_FULL_WIDTH_P (w)
3713 || WINDOW_FULL_WIDTH_P (XWINDOW (w->parent)))
3714 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3715 }
3716
3717 /* Contribute ELT to the mode line for window W.
3718 How it translates into text depends on its data type.
3719
3720 VPOS is the position of the mode line being displayed.
3721
3722 HPOS is the position (absolute on frame) where this element's text
3723 should start. The output is truncated automatically at the right
3724 edge of window W.
3725
3726 DEPTH is the depth in recursion. It is used to prevent
3727 infinite recursion here.
3728
3729 MINENDCOL is the hpos before which the element may not end.
3730 The element is padded at the right with spaces if nec
3731 to reach this column.
3732
3733 MAXENDCOL is the hpos past which this element may not extend.
3734 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3735 (This is necessary to make nested padding and truncation work.)
3736
3737 Returns the hpos of the end of the text generated by ELT.
3738 The next element will receive that value as its HPOS arg,
3739 so as to concatenate the elements. */
3740
3741 static int
3742 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3743 struct window *w;
3744 register int vpos, hpos;
3745 int depth;
3746 int minendcol;
3747 register int maxendcol;
3748 register Lisp_Object elt;
3749 {
3750 tail_recurse:
3751 if (depth > 10)
3752 goto invalid;
3753
3754 depth++;
3755
3756 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3757 {
3758 case Lisp_String:
3759 {
3760 /* A string: output it and check for %-constructs within it. */
3761 register unsigned char c;
3762 register unsigned char *this = XSTRING (elt)->data;
3763
3764 while (hpos < maxendcol && *this)
3765 {
3766 unsigned char *last = this;
3767 while ((c = *this++) != '\0' && c != '%')
3768 ;
3769 if (this - 1 != last)
3770 {
3771 register int lim = --this - last + hpos;
3772 if (frame_title_ptr)
3773 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3774 else
3775 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3776 hpos, min (lim, maxendcol));
3777 }
3778 else /* c == '%' */
3779 {
3780 register int minendcol;
3781 register int spec_width = 0;
3782
3783 /* We can't allow -ve args due to the "%-" construct */
3784 /* Argument specifies minwidth but not maxwidth
3785 (maxwidth can be specified by
3786 (<negative-number> . <stuff>) mode-line elements) */
3787
3788 while ((c = *this++) >= '0' && c <= '9')
3789 {
3790 spec_width = spec_width * 10 + (c - '0');
3791 }
3792
3793 minendcol = hpos + spec_width;
3794 if (minendcol > maxendcol)
3795 {
3796 spec_width = maxendcol - hpos;
3797 minendcol = maxendcol;
3798 }
3799
3800 if (c == 'M')
3801 hpos = display_mode_element (w, vpos, hpos, depth,
3802 spec_width, maxendcol,
3803 Vglobal_mode_string);
3804 else if (c != 0)
3805 {
3806 char *spec = decode_mode_spec (w, c, spec_width,
3807 maxendcol - hpos);
3808 if (frame_title_ptr)
3809 hpos = store_frame_title (spec, minendcol, maxendcol);
3810 else
3811 hpos = display_string (w, vpos, spec, -1,
3812 hpos, 0, 1,
3813 minendcol, maxendcol);
3814 }
3815 }
3816 }
3817 }
3818 break;
3819
3820 case Lisp_Symbol:
3821 /* A symbol: process the value of the symbol recursively
3822 as if it appeared here directly. Avoid error if symbol void.
3823 Special case: if value of symbol is a string, output the string
3824 literally. */
3825 {
3826 register Lisp_Object tem;
3827 tem = Fboundp (elt);
3828 if (!NILP (tem))
3829 {
3830 tem = Fsymbol_value (elt);
3831 /* If value is a string, output that string literally:
3832 don't check for % within it. */
3833 if (STRINGP (tem))
3834 {
3835 if (frame_title_ptr)
3836 hpos = store_frame_title (XSTRING (tem)->data,
3837 minendcol, maxendcol);
3838 else
3839 hpos = display_string (w, vpos, XSTRING (tem)->data,
3840 XSTRING (tem)->size,
3841 hpos, 0, 1, minendcol, maxendcol);
3842 }
3843 /* Give up right away for nil or t. */
3844 else if (!EQ (tem, elt))
3845 { elt = tem; goto tail_recurse; }
3846 }
3847 }
3848 break;
3849
3850 case Lisp_Cons:
3851 {
3852 register Lisp_Object car, tem;
3853
3854 /* A cons cell: three distinct cases.
3855 If first element is a string or a cons, process all the elements
3856 and effectively concatenate them.
3857 If first element is a negative number, truncate displaying cdr to
3858 at most that many characters. If positive, pad (with spaces)
3859 to at least that many characters.
3860 If first element is a symbol, process the cadr or caddr recursively
3861 according to whether the symbol's value is non-nil or nil. */
3862 car = XCONS (elt)->car;
3863 if (SYMBOLP (car))
3864 {
3865 tem = Fboundp (car);
3866 elt = XCONS (elt)->cdr;
3867 if (!CONSP (elt))
3868 goto invalid;
3869 /* elt is now the cdr, and we know it is a cons cell.
3870 Use its car if CAR has a non-nil value. */
3871 if (!NILP (tem))
3872 {
3873 tem = Fsymbol_value (car);
3874 if (!NILP (tem))
3875 { elt = XCONS (elt)->car; goto tail_recurse; }
3876 }
3877 /* Symbol's value is nil (or symbol is unbound)
3878 Get the cddr of the original list
3879 and if possible find the caddr and use that. */
3880 elt = XCONS (elt)->cdr;
3881 if (NILP (elt))
3882 break;
3883 else if (!CONSP (elt))
3884 goto invalid;
3885 elt = XCONS (elt)->car;
3886 goto tail_recurse;
3887 }
3888 else if (INTEGERP (car))
3889 {
3890 register int lim = XINT (car);
3891 elt = XCONS (elt)->cdr;
3892 if (lim < 0)
3893 /* Negative int means reduce maximum width.
3894 DO NOT change MINENDCOL here!
3895 (20 -10 . foo) should truncate foo to 10 col
3896 and then pad to 20. */
3897 maxendcol = min (maxendcol, hpos - lim);
3898 else if (lim > 0)
3899 {
3900 /* Padding specified. Don't let it be more than
3901 current maximum. */
3902 lim += hpos;
3903 if (lim > maxendcol)
3904 lim = maxendcol;
3905 /* If that's more padding than already wanted, queue it.
3906 But don't reduce padding already specified even if
3907 that is beyond the current truncation point. */
3908 if (lim > minendcol)
3909 minendcol = lim;
3910 }
3911 goto tail_recurse;
3912 }
3913 else if (STRINGP (car) || CONSP (car))
3914 {
3915 register int limit = 50;
3916 /* LIMIT is to protect against circular lists. */
3917 while (CONSP (elt) && --limit > 0
3918 && hpos < maxendcol)
3919 {
3920 hpos = display_mode_element (w, vpos, hpos, depth,
3921 hpos, maxendcol,
3922 XCONS (elt)->car);
3923 elt = XCONS (elt)->cdr;
3924 }
3925 }
3926 }
3927 break;
3928
3929 default:
3930 invalid:
3931 if (frame_title_ptr)
3932 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
3933 else
3934 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
3935 minendcol, maxendcol);
3936 return hpos;
3937 }
3938
3939 if (minendcol > hpos)
3940 if (frame_title_ptr)
3941 hpos = store_frame_title ("", minendcol, maxendcol);
3942 else
3943 hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol);
3944 return hpos;
3945 }
3946 \f
3947 /* Write a null-terminated, right justified decimal representation of
3948 the positive integer D to BUF using a minimal field width WIDTH. */
3949
3950 static void
3951 pint2str (buf, width, d)
3952 register char *buf;
3953 register int width;
3954 register int d;
3955 {
3956 register char *p = buf;
3957
3958 if (d <= 0)
3959 *p++ = '0';
3960 else
3961 while (d > 0)
3962 {
3963 *p++ = d % 10 + '0';
3964 d /= 10;
3965 }
3966 for (width -= (int) (p - buf); width > 0; --width) *p++ = ' ';
3967 *p-- = '\0';
3968 while (p > buf)
3969 {
3970 d = *buf;
3971 *buf++ = *p;
3972 *p-- = d;
3973 }
3974 }
3975
3976 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
3977 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
3978 type of CODING_SYSTEM. Return updated pointer into BUF. */
3979
3980 static char *
3981 decode_mode_spec_coding (coding_system, buf, eol_flag)
3982 Lisp_Object coding_system;
3983 register char *buf;
3984 int eol_flag;
3985 {
3986 register Lisp_Object val = coding_system;
3987
3988 if (NILP (val)) /* Not yet decided. */
3989 {
3990 *buf++ = '-';
3991 if (eol_flag) *buf++ = eol_mnemonic_undecided;
3992 }
3993 else
3994 {
3995 while (!NILP (val) && SYMBOLP (val))
3996 val = Fget (val, Qcoding_system);
3997 *buf++ = XFASTINT (XVECTOR (val)->contents[1]);
3998 if (eol_flag)
3999 {
4000 val = Fget (coding_system, Qeol_type);
4001
4002 if (NILP (val)) /* Not yet decided. */
4003 *buf++ = eol_mnemonic_undecided;
4004 else if (VECTORP (val)) /* Not yet decided. */
4005 *buf++ = eol_mnemonic_undecided;
4006 else /* INTEGERP (val) -- 1:LF, 2:CRLF, 3:CR */
4007 *buf++ = (XFASTINT (val) == 1
4008 ? eol_mnemonic_unix
4009 : (XFASTINT (val) == 2
4010 ? eol_mnemonic_dos : eol_mnemonic_mac));
4011 }
4012 }
4013 return buf;
4014 }
4015
4016 /* Return a string for the output of a mode line %-spec for window W,
4017 generated by character C. SPEC_WIDTH is the field width when
4018 padding to the left (%c, %l). The value returned from this
4019 function will later be truncated to width MAXWIDTH. */
4020
4021 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4022
4023 static char *
4024 decode_mode_spec (w, c, spec_width, maxwidth)
4025 struct window *w;
4026 register char c;
4027 register int spec_width;
4028 register int maxwidth;
4029 {
4030 Lisp_Object obj;
4031 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4032 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
4033 struct buffer *b = XBUFFER (w->buffer);
4034
4035 obj = Qnil;
4036 if (maxwidth > FRAME_WIDTH (f))
4037 maxwidth = FRAME_WIDTH (f);
4038
4039 switch (c)
4040 {
4041 case '*':
4042 if (!NILP (b->read_only))
4043 return "%";
4044 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4045 return "*";
4046 return "-";
4047
4048 case '+':
4049 /* This differs from %* only for a modified read-only buffer. */
4050 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4051 return "*";
4052 if (!NILP (b->read_only))
4053 return "%";
4054 return "-";
4055
4056 case '&':
4057 /* This differs from %* in ignoring read-only-ness. */
4058 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4059 return "*";
4060 return "-";
4061
4062 case '%':
4063 return "%";
4064
4065 case '[':
4066 {
4067 int i;
4068 char *p;
4069
4070 if (command_loop_level > 5)
4071 return "[[[... ";
4072 p = decode_mode_spec_buf;
4073 for (i = 0; i < command_loop_level; i++)
4074 *p++ = '[';
4075 *p = 0;
4076 return decode_mode_spec_buf;
4077 }
4078
4079 case ']':
4080 {
4081 int i;
4082 char *p;
4083
4084 if (command_loop_level > 5)
4085 return " ...]]]";
4086 p = decode_mode_spec_buf;
4087 for (i = 0; i < command_loop_level; i++)
4088 *p++ = ']';
4089 *p = 0;
4090 return decode_mode_spec_buf;
4091 }
4092
4093 case '-':
4094 {
4095 register char *p;
4096 register int i;
4097
4098 if (maxwidth < sizeof (lots_of_dashes))
4099 return lots_of_dashes;
4100 else
4101 {
4102 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
4103 *p++ = '-';
4104 *p = '\0';
4105 }
4106 return decode_mode_spec_buf;
4107 }
4108
4109 case 'b':
4110 obj = b->name;
4111 #if 0
4112 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
4113 {
4114 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
4115 decode_mode_spec_buf[maxwidth - 1] = '\\';
4116 decode_mode_spec_buf[maxwidth] = '\0';
4117 return decode_mode_spec_buf;
4118 }
4119 #endif
4120 break;
4121
4122 case 'c':
4123 {
4124 int col = current_column ();
4125 XSETFASTINT (w->column_number_displayed, col);
4126 pint2str (decode_mode_spec_buf, spec_width, col);
4127 return decode_mode_spec_buf;
4128 }
4129
4130 case 'F':
4131 /* %F displays the frame name. */
4132 if (!NILP (f->title))
4133 return (char *) XSTRING (f->title)->data;
4134 if (f->explicit_name || ! FRAME_WINDOW_P (f))
4135 return (char *) XSTRING (f->name)->data;
4136 return "Emacs";
4137
4138 case 'f':
4139 obj = b->filename;
4140 #if 0
4141 if (NILP (obj))
4142 return "[none]";
4143 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
4144 {
4145 bcopy ("...", decode_mode_spec_buf, 3);
4146 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
4147 decode_mode_spec_buf + 3, maxwidth - 3);
4148 return decode_mode_spec_buf;
4149 }
4150 #endif
4151 break;
4152
4153 case 'l':
4154 {
4155 int startpos = marker_position (w->start);
4156 int line, linepos, topline;
4157 int nlines, junk;
4158 Lisp_Object tem;
4159 int height = XFASTINT (w->height);
4160
4161 /* If we decided that this buffer isn't suitable for line numbers,
4162 don't forget that too fast. */
4163 if (EQ (w->base_line_pos, w->buffer))
4164 goto no_value;
4165 /* But do forget it, if the window shows a different buffer now. */
4166 else if (BUFFERP (w->base_line_pos))
4167 w->base_line_pos = Qnil;
4168
4169 /* If the buffer is very big, don't waste time. */
4170 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
4171 {
4172 w->base_line_pos = Qnil;
4173 w->base_line_number = Qnil;
4174 goto no_value;
4175 }
4176
4177 if (!NILP (w->base_line_number)
4178 && !NILP (w->base_line_pos)
4179 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
4180 {
4181 line = XFASTINT (w->base_line_number);
4182 linepos = XFASTINT (w->base_line_pos);
4183 }
4184 else
4185 {
4186 line = 1;
4187 linepos = BUF_BEGV (b);
4188 }
4189
4190 /* Count lines from base line to window start position. */
4191 nlines = display_count_lines (linepos, startpos, startpos, &junk);
4192
4193 topline = nlines + line;
4194
4195 /* Determine a new base line, if the old one is too close
4196 or too far away, or if we did not have one.
4197 "Too close" means it's plausible a scroll-down would
4198 go back past it. */
4199 if (startpos == BUF_BEGV (b))
4200 {
4201 XSETFASTINT (w->base_line_number, topline);
4202 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
4203 }
4204 else if (nlines < height + 25 || nlines > height * 3 + 50
4205 || linepos == BUF_BEGV (b))
4206 {
4207 int limit = BUF_BEGV (b);
4208 int position;
4209 int distance = (height * 2 + 30) * 200;
4210
4211 if (startpos - distance > limit)
4212 limit = startpos - distance;
4213
4214 nlines = display_count_lines (startpos, limit,
4215 -(height * 2 + 30),
4216 &position);
4217 /* If we couldn't find the lines we wanted within
4218 200 chars per line,
4219 give up on line numbers for this window. */
4220 if (position == startpos - distance)
4221 {
4222 w->base_line_pos = w->buffer;
4223 w->base_line_number = Qnil;
4224 goto no_value;
4225 }
4226
4227 XSETFASTINT (w->base_line_number, topline - nlines);
4228 XSETFASTINT (w->base_line_pos, position);
4229 }
4230
4231 /* Now count lines from the start pos to point. */
4232 nlines = display_count_lines (startpos, PT, PT, &junk);
4233
4234 /* Record that we did display the line number. */
4235 line_number_displayed = 1;
4236
4237 /* Make the string to show. */
4238 pint2str (decode_mode_spec_buf, spec_width, topline + nlines);
4239 return decode_mode_spec_buf;
4240 no_value:
4241 {
4242 char* p = decode_mode_spec_buf;
4243 for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' ';
4244 strcpy (p, "??");
4245 return decode_mode_spec_buf;
4246 }
4247 }
4248 break;
4249
4250 case 'm':
4251 obj = b->mode_name;
4252 break;
4253
4254 case 'n':
4255 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
4256 return " Narrow";
4257 break;
4258
4259 case 'p':
4260 {
4261 int pos = marker_position (w->start);
4262 int total = BUF_ZV (b) - BUF_BEGV (b);
4263
4264 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
4265 {
4266 if (pos <= BUF_BEGV (b))
4267 return "All";
4268 else
4269 return "Bottom";
4270 }
4271 else if (pos <= BUF_BEGV (b))
4272 return "Top";
4273 else
4274 {
4275 if (total > 1000000)
4276 /* Do it differently for a large value, to avoid overflow. */
4277 total = ((pos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
4278 else
4279 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
4280 /* We can't normally display a 3-digit number,
4281 so get us a 2-digit number that is close. */
4282 if (total == 100)
4283 total = 99;
4284 sprintf (decode_mode_spec_buf, "%2d%%", total);
4285 return decode_mode_spec_buf;
4286 }
4287 }
4288
4289 /* Display percentage of size above the bottom of the screen. */
4290 case 'P':
4291 {
4292 int toppos = marker_position (w->start);
4293 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
4294 int total = BUF_ZV (b) - BUF_BEGV (b);
4295
4296 if (botpos >= BUF_ZV (b))
4297 {
4298 if (toppos <= BUF_BEGV (b))
4299 return "All";
4300 else
4301 return "Bottom";
4302 }
4303 else
4304 {
4305 if (total > 1000000)
4306 /* Do it differently for a large value, to avoid overflow. */
4307 total = ((botpos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
4308 else
4309 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
4310 /* We can't normally display a 3-digit number,
4311 so get us a 2-digit number that is close. */
4312 if (total == 100)
4313 total = 99;
4314 if (toppos <= BUF_BEGV (b))
4315 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
4316 else
4317 sprintf (decode_mode_spec_buf, "%2d%%", total);
4318 return decode_mode_spec_buf;
4319 }
4320 }
4321
4322 case 's':
4323 /* status of process */
4324 obj = Fget_buffer_process (w->buffer);
4325 if (NILP (obj))
4326 return "no process";
4327 #ifdef subprocesses
4328 obj = Fsymbol_name (Fprocess_status (obj));
4329 #endif
4330 break;
4331
4332 case 't': /* indicate TEXT or BINARY */
4333 #ifdef MODE_LINE_BINARY_TEXT
4334 return MODE_LINE_BINARY_TEXT (b);
4335 #else
4336 return "T";
4337 #endif
4338
4339 case 'z':
4340 /* coding-system (not including end-of-line format) */
4341 case 'Z':
4342 /* coding-system (including end-of-line type) */
4343 {
4344 int eol_flag = (c == 'Z');
4345 char *p;
4346
4347 p = decode_mode_spec_coding
4348 (find_symbol_value (Qbuffer_file_coding_system),
4349 decode_mode_spec_buf, eol_flag);
4350 if (FRAME_TERMCAP_P (f))
4351 {
4352 p = decode_mode_spec_coding (keyboard_coding.symbol, p, eol_flag);
4353 p = decode_mode_spec_coding (terminal_coding.symbol, p, eol_flag);
4354 }
4355 #ifdef subprocesses
4356 obj = Fget_buffer_process (Fcurrent_buffer ());
4357 if (PROCESSP (obj))
4358 {
4359 p = decode_mode_spec_coding (XPROCESS (obj)->decode_coding_system,
4360 p, eol_flag);
4361 p = decode_mode_spec_coding (XPROCESS (obj)->encode_coding_system,
4362 p, eol_flag);
4363 }
4364 #endif /* subprocesses */
4365 *p = 0;
4366 return decode_mode_spec_buf;
4367 }
4368 }
4369
4370 if (STRINGP (obj))
4371 return (char *) XSTRING (obj)->data;
4372 else
4373 return "";
4374 }
4375 \f
4376 /* Search for COUNT instances of a line boundary, which means either a
4377 newline or (if selective display enabled) a carriage return.
4378 Start at START. If COUNT is negative, search backwards.
4379
4380 If we find COUNT instances, set *SHORTAGE to zero, and return the
4381 position after the COUNTth match. Note that for reverse motion
4382 this is not the same as the usual convention for Emacs motion commands.
4383
4384 If we don't find COUNT instances before reaching the end of the
4385 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
4386 the number of line boundaries left unfound, and return the end of the
4387 buffer we bumped up against. */
4388
4389 static int
4390 display_scan_buffer (start, count, shortage)
4391 int *shortage, start;
4392 register int count;
4393 {
4394 int limit = ((count > 0) ? ZV - 1 : BEGV);
4395 int direction = ((count > 0) ? 1 : -1);
4396
4397 register unsigned char *cursor;
4398 unsigned char *base;
4399
4400 register int ceiling;
4401 register unsigned char *ceiling_addr;
4402
4403 /* If we are not in selective display mode,
4404 check only for newlines. */
4405 if (! (!NILP (current_buffer->selective_display)
4406 && !INTEGERP (current_buffer->selective_display)))
4407 return scan_buffer ('\n', start, 0, count, shortage, 0);
4408
4409 /* The code that follows is like scan_buffer
4410 but checks for either newline or carriage return. */
4411
4412 if (shortage != 0)
4413 *shortage = 0;
4414
4415 if (count > 0)
4416 while (start != limit + 1)
4417 {
4418 ceiling = BUFFER_CEILING_OF (start);
4419 ceiling = min (limit, ceiling);
4420 ceiling_addr = POS_ADDR (ceiling) + 1;
4421 base = (cursor = POS_ADDR (start));
4422 while (1)
4423 {
4424 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
4425 ;
4426 if (cursor != ceiling_addr)
4427 {
4428 if (--count == 0)
4429 {
4430 immediate_quit = 0;
4431 return (start + cursor - base + 1);
4432 }
4433 else
4434 if (++cursor == ceiling_addr)
4435 break;
4436 }
4437 else
4438 break;
4439 }
4440 start += cursor - base;
4441 }
4442 else
4443 {
4444 start--; /* first character we scan */
4445 while (start > limit - 1)
4446 { /* we WILL scan under start */
4447 ceiling = BUFFER_FLOOR_OF (start);
4448 ceiling = max (limit, ceiling);
4449 ceiling_addr = POS_ADDR (ceiling) - 1;
4450 base = (cursor = POS_ADDR (start));
4451 cursor++;
4452 while (1)
4453 {
4454 while (--cursor != ceiling_addr
4455 && *cursor != '\n' && *cursor != 015)
4456 ;
4457 if (cursor != ceiling_addr)
4458 {
4459 if (++count == 0)
4460 {
4461 immediate_quit = 0;
4462 return (start + cursor - base + 1);
4463 }
4464 }
4465 else
4466 break;
4467 }
4468 start += cursor - base;
4469 }
4470 }
4471
4472 if (shortage != 0)
4473 *shortage = count * direction;
4474 return (start + ((direction == 1 ? 0 : 1)));
4475 }
4476
4477 /* Count up to N lines starting from FROM.
4478 But don't go beyond LIMIT.
4479 Return the number of lines thus found (always positive).
4480 Store the position after what was found into *POS_PTR. */
4481
4482 static int
4483 display_count_lines (from, limit, n, pos_ptr)
4484 int from, limit, n;
4485 int *pos_ptr;
4486 {
4487 int oldbegv = BEGV;
4488 int oldzv = ZV;
4489 int shortage = 0;
4490
4491 if (limit < from)
4492 BEGV = limit;
4493 else
4494 ZV = limit;
4495
4496 *pos_ptr = display_scan_buffer (from, n, &shortage);
4497
4498 ZV = oldzv;
4499 BEGV = oldbegv;
4500
4501 if (n < 0)
4502 /* When scanning backwards, scan_buffer stops *after* the last newline
4503 it finds, but does count it. Compensate for that. */
4504 return - n - shortage - (*pos_ptr != limit);
4505 return n - shortage;
4506 }
4507 \f
4508 /* Display STRING on one line of window W, starting at HPOS.
4509 Display at position VPOS. Caller should have done get_display_line.
4510 If VPOS == -1, display it as the current frame's title.
4511 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4512
4513 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4514
4515 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4516 MAXCOL is the last column ok to end at. Truncate here.
4517 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4518 Both count from the left edge of the frame, as does HPOS.
4519 The right edge of W is an implicit maximum.
4520 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4521
4522 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4523 at the place where the current window ends in this line
4524 and not display anything beyond there. Otherwise, only MAXCOL
4525 controls where to stop output.
4526
4527 Returns ending hpos. */
4528
4529 static int
4530 display_string (w, vpos, string, length, hpos, truncate,
4531 obey_window_width, mincol, maxcol)
4532 struct window *w;
4533 unsigned char *string;
4534 int length;
4535 int vpos, hpos;
4536 GLYPH truncate;
4537 int obey_window_width;
4538 int mincol, maxcol;
4539 {
4540 register int c;
4541 int truncated;
4542 register GLYPH *p1;
4543 int hscroll = XINT (w->hscroll);
4544 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
4545 register GLYPH *start;
4546 register GLYPH *end;
4547 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4548 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
4549 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
4550 int window_width = XFASTINT (w->width);
4551 /* If 1, we must display multibyte characters. */
4552 int multibyte = !NILP (XBUFFER (w->buffer)->enable_multibyte_characters);
4553
4554 /* Use the standard display table, not the window's display table.
4555 We don't want the mode line in rot13. */
4556 register struct Lisp_Char_Table *dp = 0;
4557 int i;
4558
4559 if (DISP_TABLE_P (Vstandard_display_table))
4560 dp = XCHAR_TABLE (Vstandard_display_table);
4561
4562 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
4563
4564 p1 = p1start;
4565 start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left);
4566
4567 if (obey_window_width)
4568 {
4569 end = start + window_width - (truncate != 0);
4570
4571 if (!WINDOW_RIGHTMOST_P (w))
4572 {
4573 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
4574 {
4575 int i;
4576
4577 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
4578 *end-- = ' ';
4579 }
4580 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4581 *end-- = '|';
4582 }
4583 }
4584
4585 if (! obey_window_width
4586 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
4587 end = desired_glyphs->glyphs[vpos] + maxcol;
4588
4589 /* Store 0 in charstart for these columns. */
4590 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
4591 desired_glyphs->charstarts[vpos][i] = 0;
4592
4593 if (maxcol >= 0 && mincol > maxcol)
4594 mincol = maxcol;
4595
4596 if (length < 0)
4597 /* We need this value for multibyte characters. */
4598 length = strlen (string);
4599
4600 /* We set truncated to 1 if we get stopped by trying to pass END
4601 (that is, trying to pass MAXCOL.) */
4602 truncated = 0;
4603 while (1)
4604 {
4605 int len;
4606
4607 if (length <= 0)
4608 break;
4609 if (multibyte)
4610 c = STRING_CHAR_AND_LENGTH (string, length, len);
4611 else
4612 c = *string, len = 1;
4613
4614 string += len, length -= len;
4615
4616 if (p1 >= end)
4617 {
4618 truncated = 1;
4619 break;
4620 }
4621
4622 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
4623 {
4624 p1 = copy_part_of_rope (f, p1, start,
4625 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
4626 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
4627 0);
4628 }
4629 else if (c >= 040 && c < 0177)
4630 {
4631 if (p1 >= start)
4632 *p1 = c;
4633 p1++;
4634 }
4635 else if (c == '\t')
4636 {
4637 do
4638 {
4639 if (p1 >= start && p1 < end)
4640 *p1 = SPACEGLYPH;
4641 p1++;
4642 }
4643 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
4644 }
4645 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
4646 {
4647 if (p1 >= start)
4648 *p1 = (fix_glyph
4649 (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
4650 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp)))
4651 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
4652 0));
4653 p1++;
4654 if (p1 >= start && p1 < end)
4655 *p1 = c ^ 0100;
4656 p1++;
4657 }
4658 else if (len == 1)
4659 {
4660 /* C is a control character or a binary byte data. */
4661 if (p1 >= start)
4662 *p1 = (fix_glyph
4663 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
4664 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
4665 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
4666 0));
4667 p1++;
4668 if (p1 >= start && p1 < end)
4669 *p1 = (c >> 6) + '0';
4670 p1++;
4671 if (p1 >= start && p1 < end)
4672 *p1 = (7 & (c >> 3)) + '0';
4673 p1++;
4674 if (p1 >= start && p1 < end)
4675 *p1 = (7 & c) + '0';
4676 p1++;
4677 }
4678 else
4679 {
4680 /* C is a multibyte character. */
4681 int charset = CHAR_CHARSET (c);
4682 int columns = (charset == CHARSET_COMPOSITION
4683 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
4684 : CHARSET_WIDTH (charset));
4685
4686 if (p1 < start)
4687 {
4688 /* Since we can't show the left part of C, fill all
4689 columns with spaces. */
4690 columns -= start - p1;
4691 p1 = start;
4692 while (columns--)
4693 {
4694 if (p1 < end)
4695 *p1 = SPACEGLYPH;
4696 p1++;
4697 }
4698 }
4699 else if (p1 + columns > end)
4700 {
4701 /* Since we can't show the right part of C, fill all
4702 columns with TRUNCATE if TRUNCATE is specified. */
4703 if (truncate)
4704 {
4705 while (p1 < end)
4706 *p1++ = fix_glyph (f, truncate, 0);
4707 /* And tell the line is truncated. */
4708 truncated = 1;
4709 }
4710 break;
4711 }
4712 else
4713 {
4714 /* We can show the whole glyph of C. */
4715 *p1++ = c;
4716 while (--columns)
4717 *p1++ = c | GLYPH_MASK_PADDING;
4718 }
4719 }
4720 }
4721
4722 if (truncated)
4723 {
4724 p1 = end;
4725 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
4726 }
4727 else if (mincol >= 0)
4728 {
4729 end = desired_glyphs->glyphs[vpos] + mincol;
4730 while (p1 < end)
4731 *p1++ = SPACEGLYPH;
4732 }
4733
4734 {
4735 register int len = p1 - desired_glyphs->glyphs[vpos];
4736
4737 if (len > desired_glyphs->used[vpos])
4738 desired_glyphs->used[vpos] = len;
4739 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
4740
4741 return len;
4742 }
4743 }
4744 \f
4745 /* This is like a combination of memq and assq.
4746 Return 1 if PROPVAL appears as an element of LIST
4747 or as the car of an element of LIST.
4748 If PROPVAL is a list, compare each element against LIST
4749 in that way, and return 1 if any element of PROPVAL is found in LIST.
4750 Otherwise return 0.
4751 This function cannot quit. */
4752
4753 int
4754 invisible_p (propval, list)
4755 register Lisp_Object propval;
4756 Lisp_Object list;
4757 {
4758 register Lisp_Object tail, proptail;
4759 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4760 {
4761 register Lisp_Object tem;
4762 tem = XCONS (tail)->car;
4763 if (EQ (propval, tem))
4764 return 1;
4765 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4766 return 1;
4767 }
4768 if (CONSP (propval))
4769 for (proptail = propval; CONSP (proptail);
4770 proptail = XCONS (proptail)->cdr)
4771 {
4772 Lisp_Object propelt;
4773 propelt = XCONS (proptail)->car;
4774 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4775 {
4776 register Lisp_Object tem;
4777 tem = XCONS (tail)->car;
4778 if (EQ (propelt, tem))
4779 return 1;
4780 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4781 return 1;
4782 }
4783 }
4784 return 0;
4785 }
4786
4787 /* Return 1 if PROPVAL appears as the car of an element of LIST
4788 and the cdr of that element is non-nil.
4789 If PROPVAL is a list, check each element of PROPVAL in that way,
4790 and the first time some element is found,
4791 return 1 if the cdr of that element is non-nil.
4792 Otherwise return 0.
4793 This function cannot quit. */
4794
4795 int
4796 invisible_ellipsis_p (propval, list)
4797 register Lisp_Object propval;
4798 Lisp_Object list;
4799 {
4800 register Lisp_Object tail, proptail;
4801 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4802 {
4803 register Lisp_Object tem;
4804 tem = XCONS (tail)->car;
4805 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4806 return ! NILP (XCONS (tem)->cdr);
4807 }
4808 if (CONSP (propval))
4809 for (proptail = propval; CONSP (proptail);
4810 proptail = XCONS (proptail)->cdr)
4811 {
4812 Lisp_Object propelt;
4813 propelt = XCONS (proptail)->car;
4814 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4815 {
4816 register Lisp_Object tem;
4817 tem = XCONS (tail)->car;
4818 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4819 return ! NILP (XCONS (tem)->cdr);
4820 }
4821 }
4822 return 0;
4823 }
4824 \f
4825 void
4826 syms_of_xdisp ()
4827 {
4828 staticpro (&Qmenu_bar_update_hook);
4829 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
4830
4831 staticpro (&Qoverriding_terminal_local_map);
4832 Qoverriding_terminal_local_map = intern ("overriding-terminal-local-map");
4833
4834 staticpro (&Qoverriding_local_map);
4835 Qoverriding_local_map = intern ("overriding-local-map");
4836
4837 staticpro (&Qwindow_scroll_functions);
4838 Qwindow_scroll_functions = intern ("window-scroll-functions");
4839
4840 staticpro (&Qredisplay_end_trigger_functions);
4841 Qredisplay_end_trigger_functions = intern ("redisplay-end-trigger-functions");
4842
4843 staticpro (&last_arrow_position);
4844 staticpro (&last_arrow_string);
4845 last_arrow_position = Qnil;
4846 last_arrow_string = Qnil;
4847
4848 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
4849 "String (or mode line construct) included (normally) in `mode-line-format'.");
4850 Vglobal_mode_string = Qnil;
4851
4852 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
4853 "Marker for where to display an arrow on top of the buffer text.\n\
4854 This must be the beginning of a line in order to work.\n\
4855 See also `overlay-arrow-string'.");
4856 Voverlay_arrow_position = Qnil;
4857
4858 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
4859 "String to display as an arrow. See also `overlay-arrow-position'.");
4860 Voverlay_arrow_string = Qnil;
4861
4862 DEFVAR_INT ("scroll-step", &scroll_step,
4863 "*The number of lines to try scrolling a window by when point moves out.\n\
4864 If that fails to bring point back on frame, point is centered instead.\n\
4865 If this is zero, point is always centered after it moves off frame.");
4866
4867 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively,
4868 "*Scroll up to this many lines, to bring point back on screen.");
4869 scroll_conservatively = 0;
4870
4871 DEFVAR_INT ("scroll-margin", &scroll_margin,
4872 "*Number of lines of margin at the top and bottom of a window.\n\
4873 Recenter the window whenever point gets within this many lines\n\
4874 of the top or bottom of the window.");
4875 scroll_margin = 0;
4876
4877 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
4878
4879 DEFVAR_BOOL ("truncate-partial-width-windows",
4880 &truncate_partial_width_windows,
4881 "*Non-nil means truncate lines in all windows less than full frame wide.");
4882 truncate_partial_width_windows = 1;
4883
4884 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
4885 "*Non-nil means use inverse video for the mode line.");
4886 mode_line_inverse_video = 1;
4887
4888 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
4889 "*Maximum buffer size for which line number should be displayed.");
4890 line_number_display_limit = 1000000;
4891
4892 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
4893 "*Non-nil means highlight region even in nonselected windows.");
4894 highlight_nonselected_windows = 1;
4895
4896 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
4897 "Non-nil if more than one frame is visible on this display.\n\
4898 Minibuffer-only frames don't count, but iconified frames do.\n\
4899 This variable is not guaranteed to be accurate except while processing\n\
4900 `frame-title-format' and `icon-title-format'.");
4901
4902 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
4903 "Template for displaying the titlebar of visible frames.\n\
4904 \(Assuming the window manager supports this feature.)\n\
4905 This variable has the same structure as `mode-line-format' (which see),\n\
4906 and is used only on frames for which no explicit name has been set\n\
4907 \(see `modify-frame-parameters').");
4908 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
4909 "Template for displaying the titlebar of an iconified frame.\n\
4910 \(Assuming the window manager supports this feature.)\n\
4911 This variable has the same structure as `mode-line-format' (which see),\n\
4912 and is used only on frames for which no explicit name has been set\n\
4913 \(see `modify-frame-parameters').");
4914 Vicon_title_format
4915 = Vframe_title_format
4916 = Fcons (intern ("multiple-frames"),
4917 Fcons (build_string ("%b"),
4918 Fcons (Fcons (build_string (""),
4919 Fcons (intern ("invocation-name"),
4920 Fcons (build_string ("@"),
4921 Fcons (intern ("system-name"),
4922 Qnil)))),
4923 Qnil)));
4924
4925 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
4926 "Maximum number of lines to keep in the message log buffer.\n\
4927 If nil, disable message logging. If t, log messages but don't truncate\n\
4928 the buffer when it becomes large.");
4929 XSETFASTINT (Vmessage_log_max, 50);
4930
4931 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
4932 "Functions called before redisplay, if window sizes have changed.\n\
4933 The value should be a list of functions that take one argument.\n\
4934 Just before redisplay, for each frame, if any of its windows have changed\n\
4935 size since the last redisplay, or have been split or deleted,\n\
4936 all the functions in the list are called, with the frame as argument.");
4937 Vwindow_size_change_functions = Qnil;
4938
4939 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions,
4940 "List of Functions to call before redisplaying a window with scrolling.\n\
4941 Each function is called with two arguments, the window\n\
4942 and its new display-start position. Note that the value of `window-end'\n\
4943 is not valid when these functions are called.");
4944 Vwindow_scroll_functions = Qnil;
4945 }
4946
4947 /* initialize the window system */
4948 init_xdisp ()
4949 {
4950 Lisp_Object root_window;
4951 #ifndef COMPILER_REGISTER_BUG
4952 register
4953 #endif /* COMPILER_REGISTER_BUG */
4954 struct window *mini_w;
4955
4956 this_line_bufpos = 0;
4957
4958 mini_w = XWINDOW (minibuf_window);
4959 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
4960
4961 echo_area_glyphs = 0;
4962 previous_echo_glyphs = 0;
4963
4964 if (!noninteractive)
4965 {
4966 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
4967 XSETFASTINT (XWINDOW (root_window)->top, 0);
4968 set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0);
4969 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
4970 set_window_height (minibuf_window, 1, 0);
4971
4972 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
4973 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));
4974 }
4975 }