(fortran-imenu-generic-expression): New variable.
[emacs.git] / src / xdisp.c
blob933cff33848a189fce0ee6054fa2daa1cea88122
1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 1997
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include <config.h>
24 #include <stdio.h>
25 /*#include <ctype.h>*/
26 #undef NULL
27 #include "lisp.h"
28 #include "frame.h"
29 #include "window.h"
30 #include "termchar.h"
31 #include "dispextern.h"
32 #include "buffer.h"
33 #include "charset.h"
34 #include "indent.h"
35 #include "commands.h"
36 #include "macros.h"
37 #include "disptab.h"
38 #include "termhooks.h"
39 #include "intervals.h"
40 #include "keyboard.h"
41 #include "coding.h"
42 #include "process.h"
44 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
45 extern void set_frame_menubar ();
46 extern int pending_menu_activation;
47 #endif
49 extern int interrupt_input;
50 extern int command_loop_level;
52 extern int minibuffer_auto_raise;
54 extern Lisp_Object Qface;
56 extern Lisp_Object Voverriding_local_map;
57 extern Lisp_Object Voverriding_local_map_menu_flag;
59 Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
60 Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
61 Lisp_Object Qredisplay_end_trigger_functions;
63 /* Nonzero means print newline to stdout before next minibuffer message. */
65 int noninteractive_need_newline;
67 /* Nonzero means print newline to message log before next message. */
69 static int message_log_need_newline;
71 #define min(a, b) ((a) < (b) ? (a) : (b))
72 #define max(a, b) ((a) > (b) ? (a) : (b))
73 #define minmax(floor, val, ceil) \
74 ((val) < (floor) ? (floor) : (val) > (ceil) ? (ceil) : (val))
76 /* The buffer position of the first character appearing
77 entirely or partially on the current frame line.
78 Or zero, which disables the optimization for the current frame line. */
79 static int this_line_bufpos;
81 /* Number of characters past the end of this line,
82 including the terminating newline */
83 static int this_line_endpos;
85 /* The vertical position of this frame line. */
86 static int this_line_vpos;
88 /* Hpos value for start of display on this frame line.
89 Usually zero, but negative if first character really began
90 on previous line */
91 static int this_line_start_hpos;
93 /* Buffer that this_line variables are describing. */
94 static struct buffer *this_line_buffer;
96 /* Value of echo_area_glyphs when it was last acted on.
97 If this is nonzero, there is a message on the frame
98 in the minibuffer and it should be erased as soon
99 as it is no longer requested to appear. */
100 char *previous_echo_glyphs;
102 /* Nonzero means truncate lines in all windows less wide than the frame */
103 int truncate_partial_width_windows;
105 /* Nonzero means we have more than one non-minibuffer-only frame.
106 Not guaranteed to be accurate except while parsing frame-title-format. */
107 int multiple_frames;
109 Lisp_Object Vglobal_mode_string;
111 /* Marker for where to display an arrow on top of the buffer text. */
112 Lisp_Object Voverlay_arrow_position;
114 /* String to display for the arrow. */
115 Lisp_Object Voverlay_arrow_string;
117 /* Values of those variables at last redisplay.
118 However, if Voverlay_arrow_position is a marker,
119 last_arrow_position is its numerical position. */
120 static Lisp_Object last_arrow_position, last_arrow_string;
122 /* Like mode-line-format, but for the titlebar on a visible frame. */
123 Lisp_Object Vframe_title_format;
125 /* Like mode-line-format, but for the titlebar on an iconified frame. */
126 Lisp_Object Vicon_title_format;
128 /* List of functions to call when a window's size changes. These
129 functions get one arg, a frame on which one or more windows' sizes
130 have changed. */
131 static Lisp_Object Vwindow_size_change_functions;
133 Lisp_Object Qmenu_bar_update_hook;
135 /* Nonzero if overlay arrow has been displayed once in this window. */
136 static int overlay_arrow_seen;
138 /* Nonzero if visible end of buffer has already been displayed once
139 in this window. (We need this variable in case there are overlay
140 strings that get displayed there.) */
141 static int zv_strings_seen;
143 /* Nonzero means highlight the region even in nonselected windows. */
144 static int highlight_nonselected_windows;
146 /* If cursor motion alone moves point off frame,
147 Try scrolling this many lines up or down if that will bring it back. */
148 static int scroll_step;
150 /* Non-0 means scroll just far enough to bring point back on the screen,
151 when appropriate. */
152 static int scroll_conservatively;
154 /* Recenter the window whenever point gets within this many lines
155 of the top or bottom of the window. */
156 int scroll_margin;
158 /* Nonzero if try_window_id has made blank lines at window bottom
159 since the last redisplay that paused */
160 static int blank_end_of_window;
162 /* Number of windows showing the buffer of the selected window
163 (or another buffer with the same base buffer).
164 keyboard.c refers to this. */
165 int buffer_shared;
167 /* display_text_line sets these to the frame position (origin 0) of point,
168 whether the window is selected or not.
169 Set one to -1 first to determine whether point was found afterwards. */
171 static int cursor_vpos;
172 static int cursor_hpos;
174 static int debug_end_pos;
176 /* Nonzero means display mode line highlighted */
177 int mode_line_inverse_video;
179 static void redisplay_internal ();
180 static int message_log_check_duplicate ();
181 static void echo_area_display ();
182 void mark_window_display_accurate ();
183 static void redisplay_windows ();
184 static void redisplay_window ();
185 static void update_menu_bar ();
186 static void try_window ();
187 static int try_window_id ();
188 static struct position *display_text_line ();
189 static void display_mode_line ();
190 static int display_mode_element ();
191 static char *decode_mode_spec ();
192 static int display_string ();
193 static void display_menu_bar ();
194 static int display_count_lines ();
196 /* Prompt to display in front of the minibuffer contents */
197 Lisp_Object minibuf_prompt;
199 /* Width in columns of current minibuffer prompt. */
200 int minibuf_prompt_width;
202 /* Message to display instead of minibuffer contents
203 This is what the functions error and message make,
204 and command echoing uses it as well.
205 It overrides the minibuf_prompt as well as the buffer. */
206 char *echo_area_glyphs;
208 /* This is the length of the message in echo_area_glyphs. */
209 int echo_area_glyphs_length;
211 /* This is the window where the echo area message was displayed.
212 It is always a minibuffer window, but it may not be the
213 same window currently active as a minibuffer. */
214 Lisp_Object echo_area_window;
216 /* Nonzero means multibyte characters were enabled when the echo area
217 message was specified. */
218 int message_enable_multibyte;
220 /* true iff we should redraw the mode lines on the next redisplay */
221 int update_mode_lines;
223 /* Smallest number of characters before the gap
224 at any time since last redisplay that finished.
225 Valid for current buffer when try_window_id can be called. */
226 int beg_unchanged;
228 /* Smallest number of characters after the gap
229 at any time since last redisplay that finished.
230 Valid for current buffer when try_window_id can be called. */
231 int end_unchanged;
233 /* MODIFF as of last redisplay that finished;
234 if it matches MODIFF, and overlay_unchanged_modified
235 matches OVERLAY_MODIFF, that means beg_unchanged and end_unchanged
236 contain no useful information */
237 int unchanged_modified;
239 /* OVERLAY_MODIFF as of last redisplay that finished. */
240 int overlay_unchanged_modified;
242 /* Nonzero if window sizes or contents have changed
243 since last redisplay that finished */
244 int windows_or_buffers_changed;
246 /* Nonzero after display_mode_line if %l was used
247 and it displayed a line number. */
248 int line_number_displayed;
250 /* Maximum buffer size for which to display line numbers. */
251 static int line_number_display_limit;
253 /* Number of lines to keep in the message log buffer.
254 t means infinite. nil means don't log at all. */
255 Lisp_Object Vmessage_log_max;
257 #define COERCE_MARKER(X) \
258 (MARKERP ((X)) ? Fmarker_position (X) : (X))
260 /* Output a newline in the *Messages* buffer if "needs" one. */
262 void
263 message_log_maybe_newline ()
265 if (message_log_need_newline)
266 message_dolog ("", 0, 1);
270 /* Add a string to the message log, optionally terminated with a newline.
271 This function calls low-level routines in order to bypass text property
272 hooks, etc. which might not be safe to run. */
274 void
275 message_dolog (m, len, nlflag)
276 char *m;
277 int len, nlflag;
279 if (!NILP (Vmessage_log_max))
281 struct buffer *oldbuf;
282 int oldpoint, oldbegv, oldzv;
283 int old_windows_or_buffers_changed = windows_or_buffers_changed;
285 oldbuf = current_buffer;
286 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
287 current_buffer->undo_list = Qt;
288 oldpoint = PT;
289 oldbegv = BEGV;
290 oldzv = ZV;
291 BEGV = BEG;
292 ZV = Z;
293 if (oldpoint == Z)
294 oldpoint += len + nlflag;
295 if (oldzv == Z)
296 oldzv += len + nlflag;
297 TEMP_SET_PT (Z);
298 if (len)
299 insert_1 (m, len, 1, 0);
300 if (nlflag)
302 int this_bol, prev_bol, dup;
303 insert_1 ("\n", 1, 1, 0);
305 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
306 if (this_bol > BEG)
308 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
309 dup = message_log_check_duplicate (prev_bol, this_bol);
310 if (dup)
312 if (oldpoint > prev_bol)
313 oldpoint -= min (this_bol, oldpoint) - prev_bol;
314 if (oldbegv > prev_bol)
315 oldbegv -= min (this_bol, oldbegv) - prev_bol;
316 if (oldzv > prev_bol)
317 oldzv -= min (this_bol, oldzv) - prev_bol;
318 del_range_1 (prev_bol, this_bol, 0);
319 if (dup > 1)
321 char dupstr[40];
322 int duplen;
324 /* If you change this format, don't forget to also
325 change message_log_check_duplicate. */
326 sprintf (dupstr, " [%d times]", dup);
327 duplen = strlen (dupstr);
328 TEMP_SET_PT (Z-1);
329 if (oldpoint == Z)
330 oldpoint += duplen;
331 if (oldzv == Z)
332 oldzv += duplen;
333 insert_1 (dupstr, duplen, 1, 0);
338 if (NATNUMP (Vmessage_log_max))
340 int pos = scan_buffer ('\n', Z, 0,
341 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
342 oldpoint -= min (pos, oldpoint) - BEG;
343 oldbegv -= min (pos, oldbegv) - BEG;
344 oldzv -= min (pos, oldzv) - BEG;
345 del_range_1 (BEG, pos, 0);
348 BEGV = oldbegv;
349 ZV = oldzv;
350 TEMP_SET_PT (oldpoint);
351 set_buffer_internal (oldbuf);
352 windows_or_buffers_changed = old_windows_or_buffers_changed;
353 message_log_need_newline = !nlflag;
357 /* We are at the end of the buffer after just having inserted a newline.
358 (Note: We depend on the fact we won't be crossing the gap.)
359 Check to see if the most recent message looks a lot like the previous one.
360 Return 0 if different, 1 if the new one should just replace it, or a
361 value N > 1 if we should also append " [N times]". */
363 static int
364 message_log_check_duplicate (prev_bol, this_bol)
365 int prev_bol, this_bol;
367 int i;
368 int len = Z - 1 - this_bol;
369 int seen_dots = 0;
370 unsigned char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
371 unsigned char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
373 for (i = 0; i < len; i++)
375 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
376 && p1[i] != '\n')
377 seen_dots = 1;
378 if (p1[i] != p2[i])
379 return seen_dots;
381 p1 += len;
382 if (*p1 == '\n')
383 return 2;
384 if (*p1++ == ' ' && *p1++ == '[')
386 int n = 0;
387 while (*p1 >= '0' && *p1 <= '9')
388 n = n * 10 + *p1++ - '0';
389 if (strncmp (p1, " times]\n", 8) == 0)
390 return n+1;
392 return 0;
395 /* Display an echo area message M with a specified length of LEN chars.
396 The string may include null characters. If M is 0, clear out any
397 existing message, and let the minibuffer text show through.
399 The buffer M must continue to exist until after the echo area
400 gets cleared or some other message gets displayed there.
402 Do not pass text that is stored in a Lisp string.
403 Do not pass text in a buffer that was alloca'd. */
405 void
406 message2 (m, len)
407 char *m;
408 int len;
410 /* First flush out any partial line written with print. */
411 message_log_maybe_newline ();
412 if (m)
413 message_dolog (m, len, 1);
414 message2_nolog (m, len);
418 /* The non-logging counterpart of message2. */
420 void
421 message2_nolog (m, len)
422 char *m;
423 int len;
425 message_enable_multibyte
426 = ! NILP (current_buffer->enable_multibyte_characters);
428 if (noninteractive)
430 if (noninteractive_need_newline)
431 putc ('\n', stderr);
432 noninteractive_need_newline = 0;
433 if (m)
434 fwrite (m, len, 1, stderr);
435 if (cursor_in_echo_area == 0)
436 fprintf (stderr, "\n");
437 fflush (stderr);
439 /* A null message buffer means that the frame hasn't really been
440 initialized yet. Error messages get reported properly by
441 cmd_error, so this must be just an informative message; toss it. */
442 else if (INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
444 Lisp_Object mini_window;
445 FRAME_PTR f;
447 /* Get the frame containing the minibuffer
448 that the selected frame is using. */
449 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
450 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
452 FRAME_SAMPLE_VISIBILITY (f);
453 if (FRAME_VISIBLE_P (selected_frame)
454 && ! FRAME_VISIBLE_P (f))
455 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window)));
457 if (m)
459 echo_area_glyphs = m;
460 echo_area_glyphs_length = len;
462 if (minibuffer_auto_raise)
463 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window)));
465 else
466 echo_area_glyphs = previous_echo_glyphs = 0;
468 do_pending_window_change ();
469 echo_area_display ();
470 update_frame (f, 1, 1);
471 do_pending_window_change ();
472 if (frame_up_to_date_hook != 0 && ! gc_in_progress)
473 (*frame_up_to_date_hook) (f);
477 /* Display a null-terminated echo area message M. If M is 0, clear out any
478 existing message, and let the minibuffer text show through.
480 The buffer M must continue to exist until after the echo area
481 gets cleared or some other message gets displayed there.
483 Do not pass text that is stored in a Lisp string.
484 Do not pass text in a buffer that was alloca'd. */
486 void
487 message1 (m)
488 char *m;
490 message2 (m, (m ? strlen (m) : 0));
493 void
494 message1_nolog (m)
495 char *m;
497 message2_nolog (m, (m ? strlen (m) : 0));
500 /* Truncate what will be displayed in the echo area
501 the next time we display it--but don't redisplay it now. */
503 void
504 truncate_echo_area (len)
505 int len;
507 /* A null message buffer means that the frame hasn't really been
508 initialized yet. Error messages get reported properly by
509 cmd_error, so this must be just an informative message; toss it. */
510 if (!noninteractive && INTERACTIVE && FRAME_MESSAGE_BUF (selected_frame))
511 echo_area_glyphs_length = len;
514 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by print;
515 zero if being used by message. */
516 int message_buf_print;
518 /* Dump an informative message to the minibuf. If M is 0, clear out
519 any existing message, and let the minibuffer text show through. */
521 /* VARARGS 1 */
522 void
523 message (m, a1, a2, a3)
524 char *m;
525 EMACS_INT a1, a2, a3;
527 if (noninteractive)
529 if (m)
531 if (noninteractive_need_newline)
532 putc ('\n', stderr);
533 noninteractive_need_newline = 0;
534 fprintf (stderr, m, a1, a2, a3);
535 if (cursor_in_echo_area == 0)
536 fprintf (stderr, "\n");
537 fflush (stderr);
540 else if (INTERACTIVE)
542 /* The frame whose minibuffer we're going to display the message on.
543 It may be larger than the selected frame, so we need
544 to use its buffer, not the selected frame's buffer. */
545 Lisp_Object mini_window;
546 FRAME_PTR f;
548 /* Get the frame containing the minibuffer
549 that the selected frame is using. */
550 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
551 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
553 /* A null message buffer means that the frame hasn't really been
554 initialized yet. Error messages get reported properly by
555 cmd_error, so this must be just an informative message; toss it. */
556 if (FRAME_MESSAGE_BUF (f))
558 if (m)
560 int len;
561 #ifdef NO_ARG_ARRAY
562 EMACS_INT a[3];
563 a[0] = a1;
564 a[1] = a2;
565 a[2] = a3;
567 len = doprnt (FRAME_MESSAGE_BUF (f),
568 FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, a);
569 #else
570 len = doprnt (FRAME_MESSAGE_BUF (f),
571 FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, &a1);
572 #endif /* NO_ARG_ARRAY */
574 message2 (FRAME_MESSAGE_BUF (f), len);
576 else
577 message1 (0);
579 /* Print should start at the beginning of the message
580 buffer next time. */
581 message_buf_print = 0;
586 /* The non-logging version of message. */
587 void
588 message_nolog (m, a1, a2, a3)
589 char *m;
590 EMACS_INT a1, a2, a3;
592 Lisp_Object old_log_max;
593 old_log_max = Vmessage_log_max;
594 Vmessage_log_max = Qnil;
595 message (m, a1, a2, a3);
596 Vmessage_log_max = old_log_max;
599 void
600 update_echo_area ()
602 message2 (echo_area_glyphs, echo_area_glyphs_length);
605 static void
606 echo_area_display ()
608 register int vpos;
609 FRAME_PTR f;
610 Lisp_Object mini_window;
612 /* Choose the minibuffer window for this display.
613 It is the minibuffer window used by the selected frame. */
614 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
615 /* This is the frame that window is in. */
616 f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
618 if (! FRAME_VISIBLE_P (f))
619 return;
621 if (frame_garbaged)
623 redraw_garbaged_frames ();
624 frame_garbaged = 0;
627 if (echo_area_glyphs || minibuf_level == 0)
629 int i;
631 echo_area_window = mini_window;
633 vpos = XFASTINT (XWINDOW (mini_window)->top);
634 get_display_line (f, vpos, 0);
636 /* Make sure the columns that overlap a left-hand scroll bar
637 are always clear. */
638 for (i = 0; i < FRAME_LEFT_SCROLL_BAR_WIDTH (f); i++)
639 f->desired_glyphs->glyphs[vpos][i] = SPACEGLYPH;
641 display_string (XWINDOW (mini_window), vpos,
642 echo_area_glyphs ? echo_area_glyphs : "",
643 echo_area_glyphs ? echo_area_glyphs_length : -1,
644 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
645 0, 0, 0,
646 FRAME_WIDTH (f) + FRAME_LEFT_SCROLL_BAR_WIDTH (f),
647 message_enable_multibyte);
649 #if 0 /* This just gets in the way. update_frame does the job. */
650 /* If desired cursor location is on this line, put it at end of text */
651 if (cursor_in_echo_area)
652 FRAME_CURSOR_Y (f) = vpos;
653 if (FRAME_CURSOR_Y (f) == vpos)
654 FRAME_CURSOR_X (f) = FRAME_DESIRED_GLYPHS (f)->used[vpos];
655 #endif
657 /* Fill the rest of the minibuffer window with blank lines. */
659 int i;
661 for (i = vpos + 1;
662 i < vpos + XFASTINT (XWINDOW (mini_window)->height); i++)
664 get_display_line (f, i, 0);
665 /* We don't use FRAME_SCROLL_BAR_WIDTH (f) as the starting
666 hpos, because it is good to clear whatever is behind the
667 scroll bar. This does not affect the scroll bar itself. */
668 display_string (XWINDOW (mini_window), i,
669 "", 0,
670 0, 0, 0,
671 0, FRAME_WIDTH (f) + FRAME_SCROLL_BAR_WIDTH (f),
676 else if (!EQ (mini_window, selected_window))
677 windows_or_buffers_changed++;
679 if (EQ (mini_window, selected_window))
680 this_line_bufpos = 0;
682 previous_echo_glyphs = echo_area_glyphs;
685 /* Update frame titles. */
687 #ifdef HAVE_WINDOW_SYSTEM
688 static char frame_title_buf[512];
689 static char *frame_title_ptr;
691 static int
692 store_frame_title (str, mincol, maxcol)
693 char *str;
694 int mincol, maxcol;
696 char *limit;
697 if (maxcol < 0 || maxcol >= sizeof(frame_title_buf))
698 maxcol = sizeof (frame_title_buf);
699 limit = &frame_title_buf[maxcol];
700 while (*str != '\0' && frame_title_ptr < limit)
701 *frame_title_ptr++ = *str++;
702 while (frame_title_ptr < &frame_title_buf[mincol])
703 *frame_title_ptr++ = ' ';
704 return frame_title_ptr - frame_title_buf;
707 static void
708 x_consider_frame_title (frame)
709 Lisp_Object frame;
711 Lisp_Object fmt;
712 struct buffer *obuf;
713 int len;
714 FRAME_PTR f = XFRAME (frame);
716 if (!(FRAME_WINDOW_P (f) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name))
717 return;
719 /* Do we have more than one visible frame on this X display? */
721 Lisp_Object tail;
723 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
725 FRAME_PTR tf = XFRAME (XCONS (tail)->car);
727 if (tf != f && FRAME_KBOARD (tf) == FRAME_KBOARD (f)
728 && !FRAME_MINIBUF_ONLY_P (tf)
729 && (FRAME_VISIBLE_P (tf) || FRAME_ICONIFIED_P (tf)))
730 break;
733 multiple_frames = CONSP (tail);
736 obuf = current_buffer;
737 Fset_buffer (XWINDOW (f->selected_window)->buffer);
738 fmt = (FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format);
739 frame_title_ptr = frame_title_buf;
740 len = display_mode_element (XWINDOW (f->selected_window), 0, 0, 0,
741 0, sizeof (frame_title_buf), fmt);
742 frame_title_ptr = 0;
743 set_buffer_internal (obuf);
744 /* Set the name only if it's changed. This avoids consing
745 in the common case where it hasn't. (If it turns out that we've
746 already wasted too much time by walking through the list with
747 display_mode_element, then we might need to optimize at a higher
748 level than this.) */
749 if (! STRINGP (f->name) || XSTRING (f->name)->size != len
750 || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
751 x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
753 #else
754 #define frame_title_ptr ((char *)0)
755 #define store_frame_title(str, mincol, maxcol) 0
756 #endif
758 /* Prepare for redisplay by updating menu-bar item lists when appropriate.
759 This can call eval. */
761 void
762 prepare_menu_bars ()
764 register struct window *w = XWINDOW (selected_window);
765 int all_windows;
766 struct gcpro gcpro1, gcpro2;
768 all_windows = (update_mode_lines || buffer_shared > 1
769 || windows_or_buffers_changed);
771 /* Update all frame titles based on their buffer names, etc.
772 We do this before the menu bars so that the buffer-menu
773 will show the up-to-date frame titles.
775 This used to be done after the menu bars, for a reason that
776 was stated as follows but which I do not understand:
777 "We do this after the menu bars so that the frame will first
778 create its menu bar using the name `emacs' if no other name
779 has yet been specified."
780 I think that is no longer a concern. */
781 #ifdef HAVE_WINDOW_SYSTEM
782 if (windows_or_buffers_changed || update_mode_lines)
784 Lisp_Object tail, frame;
786 FOR_EACH_FRAME (tail, frame)
787 if (FRAME_VISIBLE_P (XFRAME (frame))
788 || FRAME_ICONIFIED_P (XFRAME (frame)))
789 x_consider_frame_title (frame);
791 #endif
793 /* Update the menu bar item lists, if appropriate.
794 This has to be done before any actual redisplay
795 or generation of display lines. */
796 if (all_windows)
798 Lisp_Object tail, frame;
799 int count = specpdl_ptr - specpdl;
801 record_unwind_protect (Fstore_match_data, Fmatch_data (Qnil, Qnil));
803 FOR_EACH_FRAME (tail, frame)
805 /* If a window on this frame changed size,
806 report that to the user and clear the size-change flag. */
807 if (FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)))
809 Lisp_Object functions;
810 /* Clear flag first in case we get error below. */
811 FRAME_WINDOW_SIZES_CHANGED (XFRAME (frame)) = 0;
812 functions = Vwindow_size_change_functions;
813 GCPRO2 (tail, functions);
814 while (CONSP (functions))
816 call1 (XCONS (functions)->car, frame);
817 functions = XCONS (functions)->cdr;
819 UNGCPRO;
821 GCPRO1 (tail);
822 update_menu_bar (XFRAME (frame), 0);
823 UNGCPRO;
826 unbind_to (count, Qnil);
828 else
829 update_menu_bar (selected_frame, 1);
831 /* Motif needs this. See comment in xmenu.c.
832 Turn it off when pending_menu_activation is not defined. */
833 #ifdef USE_X_TOOLKIT
834 pending_menu_activation = 0;
835 #endif
838 /* Do a frame update, taking possible shortcuts into account.
839 This is the main external entry point for redisplay.
841 If the last redisplay displayed an echo area message and that
842 message is no longer requested, we clear the echo area
843 or bring back the minibuffer if that is in use.
845 Do not call eval from within this function.
846 Calls to eval after the call to echo_area_display would confuse
847 the display_line mechanism and would cause a crash.
848 Calls to eval before that point will work most of the time,
849 but can still lose, because this function
850 can be called from signal handlers; with alarms set up;
851 or with synchronous processes running.
853 See Fcall_process; if you called it from here, it could be
854 entered recursively. */
856 static int do_verify_charstarts;
858 /* Counter is used to clear the face cache
859 no more than once ever 1000 redisplays. */
860 static int clear_face_cache_count;
862 /* Record the previous terminal frame we displayed. */
863 static FRAME_PTR previous_terminal_frame;
865 void
866 redisplay ()
868 redisplay_internal (0);
871 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay
872 is not in response to any user action; therefore, we should
873 preserve the echo area. (Actually, our caller does that job.)
874 Perhaps in the future avoid recentering windows
875 if it is not necessary; currently that causes some problems. */
877 static void
878 redisplay_internal (preserve_echo_area)
879 int preserve_echo_area;
881 register struct window *w = XWINDOW (selected_window);
882 register int pause;
883 int must_finish = 0;
884 int all_windows;
885 register int tlbufpos, tlendpos;
886 struct position pos;
887 int number_of_visible_frames;
889 if (noninteractive)
890 return;
892 #ifdef USE_X_TOOLKIT
893 if (popup_activated ())
894 return;
895 #endif
897 retry:
899 if (! FRAME_WINDOW_P (selected_frame)
900 && previous_terminal_frame != selected_frame)
902 /* Since frames on an ASCII terminal share the same display area,
903 displaying a different frame means redisplay the whole thing. */
904 windows_or_buffers_changed++;
905 SET_FRAME_GARBAGED (selected_frame);
906 XSETFRAME (Vterminal_frame, selected_frame);
908 previous_terminal_frame = selected_frame;
910 /* Set the visible flags for all frames.
911 Do this before checking for resized or garbaged frames; they want
912 to know if their frames are visible.
913 See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
915 Lisp_Object tail, frame;
917 number_of_visible_frames = 0;
919 FOR_EACH_FRAME (tail, frame)
921 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
923 if (FRAME_VISIBLE_P (XFRAME (frame)))
924 number_of_visible_frames++;
926 /* Clear out all the display lines in which we will generate the
927 glyphs to display. */
928 init_desired_glyphs (XFRAME (frame));
932 /* Notice any pending interrupt request to change frame size. */
933 do_pending_window_change ();
935 if (frame_garbaged)
937 redraw_garbaged_frames ();
938 frame_garbaged = 0;
941 prepare_menu_bars ();
943 if (windows_or_buffers_changed)
944 update_mode_lines++;
946 /* Detect case that we need to write or remove a star in the mode line. */
947 if ((SAVE_MODIFF < MODIFF) != !NILP (w->last_had_star))
949 w->update_mode_line = Qt;
950 if (buffer_shared > 1)
951 update_mode_lines++;
954 /* If %c is in use, update it if needed. */
955 if (!NILP (w->column_number_displayed)
956 /* This alternative quickly identifies a common case
957 where no change is needed. */
958 && !(PT == XFASTINT (w->last_point)
959 && XFASTINT (w->last_modified) >= MODIFF
960 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)
961 && XFASTINT (w->column_number_displayed) != current_column ())
962 w->update_mode_line = Qt;
964 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
966 all_windows = update_mode_lines || buffer_shared > 1;
968 /* If specs for an arrow have changed, do thorough redisplay
969 to ensure we remove any arrow that should no longer exist. */
970 if (! EQ (COERCE_MARKER (Voverlay_arrow_position), last_arrow_position)
971 || ! EQ (Voverlay_arrow_string, last_arrow_string))
972 all_windows = 1;
974 /* Normally the message* functions will have already displayed and
975 updated the echo area, but the frame may have been trashed, or
976 the update may have been preempted, so display the echo area
977 again here. */
978 if (echo_area_glyphs || previous_echo_glyphs)
980 echo_area_display ();
981 must_finish = 1;
984 /* If showing region, and mark has changed, must redisplay whole window. */
985 if (((!NILP (Vtransient_mark_mode)
986 && !NILP (XBUFFER (w->buffer)->mark_active))
987 != !NILP (w->region_showing))
988 || (!NILP (w->region_showing)
989 && !EQ (w->region_showing,
990 Fmarker_position (XBUFFER (w->buffer)->mark))))
991 this_line_bufpos = -1;
993 tlbufpos = this_line_bufpos;
994 tlendpos = this_line_endpos;
995 if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line)
996 && !current_buffer->clip_changed
997 && FRAME_VISIBLE_P (XFRAME (w->frame))
998 && !FRAME_OBSCURED_P (XFRAME (w->frame))
999 /* Make sure recorded data applies to current buffer, etc */
1000 && this_line_buffer == current_buffer
1001 && current_buffer == XBUFFER (w->buffer)
1002 && NILP (w->force_start)
1003 /* Point must be on the line that we have info recorded about */
1004 && PT >= tlbufpos
1005 && PT <= Z - tlendpos
1006 /* All text outside that line, including its final newline,
1007 must be unchanged */
1008 && ((XFASTINT (w->last_modified) >= MODIFF
1009 && (XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF))
1010 || (beg_unchanged >= tlbufpos - 1
1011 && GPT >= tlbufpos
1012 /* If selective display, can't optimize
1013 if the changes start at the beginning of the line. */
1014 && ((INTEGERP (current_buffer->selective_display)
1015 && XINT (current_buffer->selective_display) > 0
1016 ? (beg_unchanged >= tlbufpos
1017 && GPT > tlbufpos)
1018 : 1))
1019 && end_unchanged >= tlendpos
1020 && Z - GPT >= tlendpos)))
1022 if (tlbufpos > BEGV && FETCH_BYTE (tlbufpos - 1) != '\n'
1023 && (tlbufpos == ZV
1024 || FETCH_BYTE (tlbufpos) == '\n'))
1025 /* Former continuation line has disappeared by becoming empty */
1026 goto cancel;
1027 else if (XFASTINT (w->last_modified) < MODIFF
1028 || XFASTINT (w->last_overlay_modified) < OVERLAY_MODIFF
1029 || MINI_WINDOW_P (w))
1031 /* We have to handle the case of continuation around a
1032 wide-column character (See the comment in indent.c around
1033 line 885).
1035 For instance, in the following case:
1037 -------- Insert --------
1038 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
1039 J_I_ ==> J_I_ `^^' are cursors.
1040 ^^ ^^
1041 -------- --------
1043 As we have to redraw the line above, we should goto cancel. */
1045 struct position val;
1046 int prevline;
1048 prevline = find_next_newline (tlbufpos, -1);
1049 val = *compute_motion (prevline, 0,
1050 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1052 tlbufpos,
1053 1 << (BITS_PER_SHORT - 1),
1054 1 << (BITS_PER_SHORT - 1),
1055 window_internal_width (w) - 1,
1056 XINT (w->hscroll), 0, w);
1057 if (val.hpos != this_line_start_hpos)
1058 goto cancel;
1060 cursor_vpos = -1;
1061 overlay_arrow_seen = 0;
1062 zv_strings_seen = 0;
1063 display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
1064 pos_tab_offset (w, tlbufpos), 0);
1065 /* If line contains point, is not continued,
1066 and ends at same distance from eob as before, we win */
1067 if (cursor_vpos >= 0 && this_line_bufpos
1068 && this_line_endpos == tlendpos)
1070 /* If this is not the window's last line,
1071 we must adjust the charstarts of the lines below. */
1072 if (this_line_vpos + 1
1073 < XFASTINT (w->top) + window_internal_height (w))
1075 int left = WINDOW_LEFT_MARGIN (w);
1076 int *charstart_next_line
1077 = FRAME_CURRENT_GLYPHS (XFRAME (WINDOW_FRAME (w)))->charstarts[this_line_vpos + 1];
1078 int adjust;
1080 if (Z - tlendpos == ZV)
1081 /* This line ends at end of (accessible part of) buffer.
1082 There is no newline to count. */
1083 adjust = Z - tlendpos - charstart_next_line[left];
1084 else
1085 /* This line ends in a newline.
1086 Must take account of the newline and the rest of the
1087 text that follows. */
1088 adjust = Z - tlendpos + 1 - charstart_next_line[left];
1090 adjust_window_charstarts (w, this_line_vpos, adjust);
1093 if (!WINDOW_FULL_WIDTH_P (w))
1094 preserve_other_columns (w);
1095 goto update;
1097 else
1098 goto cancel;
1100 else if (PT == XFASTINT (w->last_point)
1101 /* Make sure the cursor was last displayed
1102 in this window. Otherwise we have to reposition it. */
1103 && XINT (w->top) <= FRAME_CURSOR_Y (selected_frame)
1104 && (XINT (w->top) + XINT (w->height)
1105 > FRAME_CURSOR_Y (selected_frame)))
1107 if (!must_finish)
1109 do_pending_window_change ();
1110 return;
1112 goto update;
1114 /* If highlighting the region, or if the cursor is in the echo area,
1115 then we can't just move the cursor. */
1116 else if (! (!NILP (Vtransient_mark_mode)
1117 && !NILP (current_buffer->mark_active))
1118 && (w == XWINDOW (current_buffer->last_selected_window)
1119 || highlight_nonselected_windows)
1120 && NILP (w->region_showing)
1121 && !cursor_in_echo_area)
1123 pos = *compute_motion (tlbufpos, 0,
1124 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
1126 PT, 2, - (1 << (BITS_PER_SHORT - 1)),
1127 window_internal_width (w) - 1,
1128 XINT (w->hscroll),
1129 pos_tab_offset (w, tlbufpos), w);
1130 if (pos.vpos < 1)
1132 int width = window_internal_width (w) - 1;
1133 FRAME_CURSOR_X (selected_frame)
1134 = WINDOW_LEFT_MARGIN (w) + minmax (0, pos.hpos, width);
1135 FRAME_CURSOR_Y (selected_frame) = this_line_vpos;
1136 goto update;
1138 else
1139 goto cancel;
1141 cancel:
1142 /* Text changed drastically or point moved off of line */
1143 cancel_line (this_line_vpos, selected_frame);
1146 this_line_bufpos = 0;
1147 all_windows |= buffer_shared > 1;
1149 clear_face_cache_count++;
1151 if (all_windows)
1153 Lisp_Object tail, frame;
1155 #ifdef HAVE_FACES
1156 /* Clear the face cache, only when we do a full redisplay
1157 and not too often either. */
1158 if (clear_face_cache_count > 1000)
1160 clear_face_cache ();
1161 clear_face_cache_count = 0;
1163 #endif
1165 /* Recompute # windows showing selected buffer.
1166 This will be incremented each time such a window is displayed. */
1167 buffer_shared = 0;
1169 FOR_EACH_FRAME (tail, frame)
1171 FRAME_PTR f = XFRAME (frame);
1172 if (FRAME_WINDOW_P (f) || f == selected_frame)
1175 /* Mark all the scroll bars to be removed; we'll redeem the ones
1176 we want when we redisplay their windows. */
1177 if (condemn_scroll_bars_hook)
1178 (*condemn_scroll_bars_hook) (f);
1180 if (FRAME_VISIBLE_P (f) && !FRAME_OBSCURED_P (f))
1181 redisplay_windows (FRAME_ROOT_WINDOW (f), preserve_echo_area);
1183 /* Any scroll bars which redisplay_windows should have nuked
1184 should now go away. */
1185 if (judge_scroll_bars_hook)
1186 (*judge_scroll_bars_hook) (f);
1190 else if (FRAME_VISIBLE_P (selected_frame) && !FRAME_OBSCURED_P (selected_frame))
1192 redisplay_window (selected_window, 1, preserve_echo_area);
1193 if (!WINDOW_FULL_WIDTH_P (w))
1194 preserve_other_columns (w);
1197 update:
1198 /* Prevent various kinds of signals during display update.
1199 stdio is not robust about handling signals,
1200 which can cause an apparent I/O error. */
1201 if (interrupt_input)
1202 unrequest_sigio ();
1203 stop_polling ();
1205 if (all_windows)
1207 Lisp_Object tail;
1209 pause = 0;
1211 for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
1213 FRAME_PTR f;
1215 if (!FRAMEP (XCONS (tail)->car))
1216 continue;
1218 f = XFRAME (XCONS (tail)->car);
1220 if ((FRAME_WINDOW_P (f) || f == selected_frame)
1221 && FRAME_VISIBLE_P (f) && !FRAME_OBSCURED_P (f))
1223 pause |= update_frame (f, 0, 0);
1224 if (!pause)
1226 mark_window_display_accurate (f->root_window, 1);
1227 if (frame_up_to_date_hook != 0)
1228 (*frame_up_to_date_hook) (f);
1233 else
1235 if (FRAME_VISIBLE_P (selected_frame) && !FRAME_OBSCURED_P (selected_frame))
1236 pause = update_frame (selected_frame, 0, 0);
1237 else
1238 pause = 0;
1240 /* We may have called echo_area_display at the top of this
1241 function. If the echo area is on another frame, that may
1242 have put text on a frame other than the selected one, so the
1243 above call to update_frame would not have caught it. Catch
1244 it here. */
1246 Lisp_Object mini_window;
1247 FRAME_PTR mini_frame;
1249 mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
1250 mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
1252 if (mini_frame != selected_frame && FRAME_WINDOW_P (mini_frame))
1253 pause |= update_frame (mini_frame, 0, 0);
1257 /* If frame does not match, prevent doing single-line-update next time.
1258 Also, don't forget to check every line to update the arrow. */
1259 if (pause)
1261 this_line_bufpos = 0;
1262 if (!NILP (last_arrow_position))
1264 last_arrow_position = Qt;
1265 last_arrow_string = Qt;
1267 /* If we pause after scrolling, some lines in current_frame
1268 may be null, so preserve_other_columns won't be able to
1269 preserve all the vertical-bar separators. So, avoid using it
1270 in that case. */
1271 if (!WINDOW_FULL_WIDTH_P (w))
1272 update_mode_lines = 1;
1275 /* Now text on frame agrees with windows, so
1276 put info into the windows for partial redisplay to follow */
1278 if (!pause)
1280 register struct buffer *b = XBUFFER (w->buffer);
1282 blank_end_of_window = 0;
1283 unchanged_modified = BUF_MODIFF (b);
1284 overlay_unchanged_modified = BUF_OVERLAY_MODIFF (b);
1285 beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
1286 end_unchanged = BUF_Z (b) - BUF_GPT (b);
1288 XSETFASTINT (w->last_point, BUF_PT (b));
1289 XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame));
1290 XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame));
1292 if (all_windows)
1293 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1);
1294 else
1296 b->clip_changed = 0;
1297 w->update_mode_line = Qnil;
1298 XSETFASTINT (w->last_modified, BUF_MODIFF (b));
1299 XSETFASTINT (w->last_overlay_modified, BUF_OVERLAY_MODIFF (b));
1300 w->last_had_star
1301 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1302 ? Qt : Qnil);
1304 /* Record if we are showing a region, so can make sure to
1305 update it fully at next redisplay. */
1306 w->region_showing = (!NILP (Vtransient_mark_mode)
1307 && (w == XWINDOW (current_buffer->last_selected_window)
1308 || highlight_nonselected_windows)
1309 && !NILP (XBUFFER (w->buffer)->mark_active)
1310 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1311 : Qnil);
1313 w->window_end_valid = w->buffer;
1314 last_arrow_position = COERCE_MARKER (Voverlay_arrow_position);
1315 last_arrow_string = Voverlay_arrow_string;
1316 if (do_verify_charstarts)
1317 verify_charstarts (w);
1318 if (frame_up_to_date_hook != 0)
1319 (*frame_up_to_date_hook) (selected_frame);
1321 update_mode_lines = 0;
1322 windows_or_buffers_changed = 0;
1325 /* Start SIGIO interrupts coming again.
1326 Having them off during the code above
1327 makes it less likely one will discard output,
1328 but not impossible, since there might be stuff
1329 in the system buffer here.
1330 But it is much hairier to try to do anything about that. */
1332 if (interrupt_input)
1333 request_sigio ();
1334 start_polling ();
1336 /* If something has become visible now which was not before,
1337 redisplay again, so that we get them. */
1338 if (!pause)
1340 Lisp_Object tail, frame;
1341 int new_count = 0;
1343 FOR_EACH_FRAME (tail, frame)
1345 int this_is_visible = 0;
1347 if (XFRAME (frame)->visible)
1348 this_is_visible = 1;
1349 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1350 if (XFRAME (frame)->visible)
1351 this_is_visible = 1;
1353 if (this_is_visible)
1354 new_count++;
1357 if (new_count != number_of_visible_frames)
1358 windows_or_buffers_changed++;
1361 /* Change frame size now if a change is pending. */
1362 do_pending_window_change ();
1364 /* If we just did a pending size change, or have additional
1365 visible frames, redisplay again. */
1366 if (windows_or_buffers_changed && !pause)
1367 goto retry;
1370 /* Redisplay, but leave alone any recent echo area message
1371 unless another message has been requested in its place.
1373 This is useful in situations where you need to redisplay but no
1374 user action has occurred, making it inappropriate for the message
1375 area to be cleared. See tracking_off and
1376 wait_reading_process_input for examples of these situations. */
1378 redisplay_preserve_echo_area ()
1380 if (echo_area_glyphs == 0 && previous_echo_glyphs != 0)
1382 echo_area_glyphs = previous_echo_glyphs;
1383 redisplay_internal (1);
1384 echo_area_glyphs = 0;
1386 else
1387 redisplay_internal (1);
1390 void
1391 mark_window_display_accurate (window, flag)
1392 Lisp_Object window;
1393 int flag;
1395 register struct window *w;
1397 for (;!NILP (window); window = w->next)
1399 if (!WINDOWP (window)) abort ();
1400 w = XWINDOW (window);
1402 if (!NILP (w->buffer))
1404 XSETFASTINT (w->last_modified,
1405 !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer)));
1406 XSETFASTINT (w->last_overlay_modified,
1407 !flag ? 0 : BUF_OVERLAY_MODIFF (XBUFFER (w->buffer)));
1408 w->last_had_star
1409 = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1410 ? Qt : Qnil);
1412 /* Record if we are showing a region, so can make sure to
1413 update it fully at next redisplay. */
1414 w->region_showing = (!NILP (Vtransient_mark_mode)
1415 && (w == XWINDOW (current_buffer->last_selected_window)
1416 || highlight_nonselected_windows)
1417 && !NILP (XBUFFER (w->buffer)->mark_active)
1418 ? Fmarker_position (XBUFFER (w->buffer)->mark)
1419 : Qnil);
1422 w->window_end_valid = w->buffer;
1423 w->update_mode_line = Qnil;
1424 if (!NILP (w->buffer) && flag)
1425 XBUFFER (w->buffer)->clip_changed = 0;
1427 if (!NILP (w->vchild))
1428 mark_window_display_accurate (w->vchild, flag);
1429 if (!NILP (w->hchild))
1430 mark_window_display_accurate (w->hchild, flag);
1433 if (flag)
1435 last_arrow_position = COERCE_MARKER (Voverlay_arrow_position);
1436 last_arrow_string = Voverlay_arrow_string;
1438 else
1440 /* t is unequal to any useful value of Voverlay_arrow_... */
1441 last_arrow_position = Qt;
1442 last_arrow_string = Qt;
1446 /* Update the menu bar item list for frame F.
1447 This has to be done before we start to fill in any display lines,
1448 because it can call eval.
1450 If SAVE_MATCH_DATA is 1, we must save and restore it here. */
1452 static void
1453 update_menu_bar (f, save_match_data)
1454 FRAME_PTR f;
1455 int save_match_data;
1457 struct buffer *old = current_buffer;
1458 Lisp_Object window;
1459 register struct window *w;
1461 window = FRAME_SELECTED_WINDOW (f);
1462 w = XWINDOW (window);
1464 if (update_mode_lines)
1465 w->update_mode_line = Qt;
1467 if (FRAME_WINDOW_P (f)
1469 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1470 FRAME_EXTERNAL_MENU_BAR (f)
1471 #else
1472 FRAME_MENU_BAR_LINES (f) > 0
1473 #endif
1474 : FRAME_MENU_BAR_LINES (f) > 0)
1476 /* If the user has switched buffers or windows, we need to
1477 recompute to reflect the new bindings. But we'll
1478 recompute when update_mode_lines is set too; that means
1479 that people can use force-mode-line-update to request
1480 that the menu bar be recomputed. The adverse effect on
1481 the rest of the redisplay algorithm is about the same as
1482 windows_or_buffers_changed anyway. */
1483 if (windows_or_buffers_changed
1484 || !NILP (w->update_mode_line)
1485 || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer))
1486 < BUF_MODIFF (XBUFFER (w->buffer)))
1487 != !NILP (w->last_had_star))
1488 || ((!NILP (Vtransient_mark_mode)
1489 && !NILP (XBUFFER (w->buffer)->mark_active))
1490 != !NILP (w->region_showing)))
1492 struct buffer *prev = current_buffer;
1493 int count = specpdl_ptr - specpdl;
1495 set_buffer_internal_1 (XBUFFER (w->buffer));
1496 if (save_match_data)
1497 record_unwind_protect (Fstore_match_data, Fmatch_data (Qnil, Qnil));
1498 if (NILP (Voverriding_local_map_menu_flag))
1500 specbind (Qoverriding_terminal_local_map, Qnil);
1501 specbind (Qoverriding_local_map, Qnil);
1504 /* Run the Lucid hook. */
1505 call1 (Vrun_hooks, Qactivate_menubar_hook);
1506 /* If it has changed current-menubar from previous value,
1507 really recompute the menubar from the value. */
1508 if (! NILP (Vlucid_menu_bar_dirty_flag))
1509 call0 (Qrecompute_lucid_menubar);
1510 safe_run_hooks (Qmenu_bar_update_hook);
1511 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1512 /* Redisplay the menu bar in case we changed it. */
1513 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1514 if (FRAME_WINDOW_P (f))
1515 set_frame_menubar (f, 0, 0);
1516 else
1517 /* On a terminal screen, the menu bar is an ordinary screen
1518 line, and this makes it get updated. */
1519 w->update_mode_line = Qt;
1520 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1521 /* In the non-toolkit version, the menu bar is an ordinary screen
1522 line, and this makes it get updated. */
1523 w->update_mode_line = Qt;
1524 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
1526 unbind_to (count, Qnil);
1527 set_buffer_internal_1 (prev);
1532 int do_id = 1;
1534 /* Redisplay WINDOW and its subwindows and siblings. */
1536 static void
1537 redisplay_windows (window, preserve_echo_area)
1538 Lisp_Object window;
1539 int preserve_echo_area;
1541 for (; !NILP (window); window = XWINDOW (window)->next)
1542 redisplay_window (window, 0, preserve_echo_area);
1545 /* Return value in display table DP (Lisp_Char_Table *) for character
1546 C. Since a display table doesn't have any parent, we don't have to
1547 follow parent. Do not call this function directly but use the
1548 macro DISP_CHAR_VECTOR. */
1549 Lisp_Object
1550 disp_char_vector (dp, c)
1551 struct Lisp_Char_Table *dp;
1552 int c;
1554 int code[4], i;
1555 Lisp_Object val;
1557 if (SINGLE_BYTE_CHAR_P (c)) return (dp->contents[c]);
1559 SPLIT_NON_ASCII_CHAR (c, code[0], code[1], code[2]);
1560 if (code[0] != CHARSET_COMPOSITION)
1562 if (code[1] < 32) code[1] = -1;
1563 else if (code[2] < 32) code[2] = -1;
1565 /* Here, the possible range of CODE[0] (== charset ID) is
1566 128..MAX_CHARSET. Since the top level char table contains data
1567 for multibyte characters after 256th element, we must increment
1568 CODE[0] by 128 to get a correct index. */
1569 code[0] += 128;
1570 code[3] = -1; /* anchor */
1572 for (i = 0; code[i] >= 0; i++, dp = XCHAR_TABLE (val))
1574 val = dp->contents[code[i]];
1575 if (!SUB_CHAR_TABLE_P (val))
1576 return (NILP (val) ? dp->defalt : val);
1578 /* Here, VAL is a sub char table. We return the default value of it. */
1579 return (dp->defalt);
1582 /* Redisplay window WINDOW and its subwindows. */
1584 static void
1585 redisplay_window (window, just_this_one, preserve_echo_area)
1586 Lisp_Object window;
1587 int just_this_one, preserve_echo_area;
1589 register struct window *w = XWINDOW (window);
1590 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
1591 int height;
1592 register int lpoint = PT;
1593 struct buffer *old = current_buffer;
1594 register int width = window_internal_width (w) - 1;
1595 register int startp;
1596 register int hscroll = XINT (w->hscroll);
1597 struct position pos;
1598 int opoint = PT;
1599 int tem;
1600 int update_mode_line;
1601 struct Lisp_Char_Table *dp = window_display_table (w);
1603 if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */
1605 /* If this is a combination window, do its children; that's all. */
1607 if (!NILP (w->vchild))
1609 redisplay_windows (w->vchild, preserve_echo_area);
1610 return;
1612 if (!NILP (w->hchild))
1614 redisplay_windows (w->hchild, preserve_echo_area);
1615 return;
1617 if (NILP (w->buffer))
1618 abort ();
1620 height = window_internal_height (w);
1621 update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines);
1622 if (XBUFFER (w->buffer)->clip_changed)
1623 update_mode_line = 1;
1625 if (MINI_WINDOW_P (w))
1627 if (w == XWINDOW (echo_area_window) && echo_area_glyphs)
1628 /* We've already displayed the echo area glyphs in this window. */
1629 goto finish_scroll_bars;
1630 else if (w != XWINDOW (minibuf_window))
1632 /* This is a minibuffer, but it's not the currently active one,
1633 so clear it. */
1634 int vpos = XFASTINT (w->top);
1635 int i;
1637 for (i = 0; i < height; i++)
1639 get_display_line (f, vpos + i, 0);
1640 display_string (w, vpos + i, "", 0,
1641 FRAME_LEFT_SCROLL_BAR_WIDTH (f),
1642 0, 1, 0, width, 0);
1645 goto finish_scroll_bars;
1649 /* Otherwise set up data on this window; select its buffer and point value */
1651 if (update_mode_line)
1652 set_buffer_internal_1 (XBUFFER (w->buffer));
1653 else
1654 set_buffer_temp (XBUFFER (w->buffer));
1656 opoint = PT;
1658 /* If %c is in mode line, update it if needed. */
1659 if (!NILP (w->column_number_displayed)
1660 /* This alternative quickly identifies a common case
1661 where no change is needed. */
1662 && !(PT == XFASTINT (w->last_point)
1663 && XFASTINT (w->last_modified) >= MODIFF
1664 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)
1665 && XFASTINT (w->column_number_displayed) != current_column ())
1666 update_mode_line = 1;
1668 /* Count number of windows showing the selected buffer.
1669 An indirect buffer counts as its base buffer. */
1671 if (!just_this_one)
1673 struct buffer *current_base, *window_base;
1674 current_base = current_buffer;
1675 window_base = XBUFFER (XWINDOW (selected_window)->buffer);
1676 if (current_base->base_buffer)
1677 current_base = current_base->base_buffer;
1678 if (window_base->base_buffer)
1679 window_base = window_base->base_buffer;
1680 if (current_base == window_base)
1681 buffer_shared++;
1684 /* POINT refers normally to the selected window.
1685 For any other window, set up appropriate value. */
1687 if (!EQ (window, selected_window))
1689 int new_pt = marker_position (w->pointm);
1690 if (new_pt < BEGV)
1692 new_pt = BEGV;
1693 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1695 else if (new_pt > (ZV - 1))
1697 new_pt = ZV;
1698 Fset_marker (w->pointm, make_number (new_pt), Qnil);
1700 /* We don't use SET_PT so that the point-motion hooks don't run. */
1701 BUF_PT (current_buffer) = new_pt;
1704 /* If any of the character widths specified in the display table
1705 have changed, invalidate the width run cache. It's true that this
1706 may be a bit late to catch such changes, but the rest of
1707 redisplay goes (non-fatally) haywire when the display table is
1708 changed, so why should we worry about doing any better? */
1709 if (current_buffer->width_run_cache)
1711 struct Lisp_Char_Table *disptab = buffer_display_table ();
1713 if (! disptab_matches_widthtab (disptab,
1714 XVECTOR (current_buffer->width_table)))
1716 invalidate_region_cache (current_buffer,
1717 current_buffer->width_run_cache,
1718 BEG, Z);
1719 recompute_width_table (current_buffer, disptab);
1723 /* If window-start is screwed up, choose a new one. */
1724 if (XMARKER (w->start)->buffer != current_buffer)
1725 goto recenter;
1727 startp = marker_position (w->start);
1729 /* If someone specified a new starting point but did not insist,
1730 check whether it can be used. */
1731 if (!NILP (w->optional_new_start))
1733 w->optional_new_start = Qnil;
1734 /* Check whether this start pos is usable given where point is. */
1736 pos = *compute_motion (startp, 0,
1737 (((EQ (window, minibuf_window)
1738 && startp == BEG)
1739 ? minibuf_prompt_width : 0)
1740 + (hscroll ? 1 - hscroll : 0)),
1742 PT, height,
1743 /* BUG FIX: See the comment of
1744 Fpos_visible_in_window_p (window.c). */
1745 - (1 << (BITS_PER_SHORT - 1)),
1746 width, hscroll, pos_tab_offset (w, startp), w);
1747 /* If PT does fit on the screen, we will use this start pos,
1748 so do so by setting force_start. */
1749 if (pos.bufpos == PT)
1750 w->force_start = Qt;
1753 /* Handle case where place to start displaying has been specified,
1754 unless the specified location is outside the accessible range. */
1755 if (!NILP (w->force_start))
1757 w->force_start = Qnil;
1758 /* Forget any recorded base line for line number display. */
1759 w->base_line_number = Qnil;
1760 /* Redisplay the mode line. Select the buffer properly for that.
1761 Also, run the hook window-scroll-functions
1762 because we have scrolled. */
1763 /* Note, we do this after clearing force_start because
1764 if there's an error, it is better to forget about force_start
1765 than to get into an infinite loop calling the hook functions
1766 and having them get more errors. */
1767 if (!update_mode_line
1768 || ! NILP (Vwindow_scroll_functions))
1770 Lisp_Object temp[3];
1772 set_buffer_temp (old);
1773 set_buffer_internal_1 (XBUFFER (w->buffer));
1774 update_mode_line = 1;
1775 w->update_mode_line = Qt;
1776 if (! NILP (Vwindow_scroll_functions))
1778 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1779 make_number (startp));
1780 startp = marker_position (w->start);
1783 XSETFASTINT (w->last_modified, 0);
1784 XSETFASTINT (w->last_overlay_modified, 0);
1785 if (startp < BEGV) startp = BEGV;
1786 if (startp > ZV) startp = ZV;
1787 try_window (window, startp);
1788 if (cursor_vpos < 0)
1790 /* If point does not appear, move point so it does appear */
1791 pos = *compute_motion (startp, 0,
1792 (((EQ (window, minibuf_window)
1793 && startp == BEG)
1794 ? minibuf_prompt_width : 0)
1795 + (hscroll ? 1 - hscroll : 0)),
1797 ZV, height / 2,
1798 - (1 << (BITS_PER_SHORT - 1)),
1799 width, hscroll, pos_tab_offset (w, startp), w);
1800 BUF_PT (current_buffer) = pos.bufpos;
1801 if (w != XWINDOW (selected_window))
1802 Fset_marker (w->pointm, make_number (PT), Qnil);
1803 else
1805 if (current_buffer == old)
1806 lpoint = PT;
1807 FRAME_CURSOR_X (f) = (WINDOW_LEFT_MARGIN (w)
1808 + minmax (0, pos.hpos, width));
1809 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1811 /* If we are highlighting the region,
1812 then we just changed the region, so redisplay to show it. */
1813 if (!NILP (Vtransient_mark_mode)
1814 && !NILP (current_buffer->mark_active))
1816 cancel_my_columns (XWINDOW (window));
1817 try_window (window, startp);
1820 goto done;
1823 /* Handle case where text has not changed, only point,
1824 and it has not moved off the frame. */
1826 /* This code is not used for minibuffer for the sake of
1827 the case of redisplaying to replace an echo area message;
1828 since in that case the minibuffer contents per se are usually unchanged.
1829 This code is of no real use in the minibuffer since
1830 the handling of this_line_bufpos, etc.,
1831 in redisplay handles the same cases. */
1833 if (XFASTINT (w->last_modified) >= MODIFF
1834 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF
1835 && PT >= startp && !current_buffer->clip_changed
1836 && (just_this_one || WINDOW_FULL_WIDTH_P (w))
1837 /* If force-mode-line-update was called, really redisplay;
1838 that's how redisplay is forced after e.g. changing
1839 buffer-invisibility-spec. */
1840 && NILP (w->update_mode_line)
1841 /* Can't use this case if highlighting a region. */
1842 && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
1843 && NILP (w->region_showing)
1844 /* If end pos is out of date, scroll bar and percentage will be wrong */
1845 && INTEGERP (w->window_end_vpos)
1846 && XFASTINT (w->window_end_vpos) < XFASTINT (w->height)
1847 && !EQ (window, minibuf_window)
1848 && (!MARKERP (Voverlay_arrow_position)
1849 || current_buffer != XMARKER (Voverlay_arrow_position)->buffer))
1851 /* All positions in this clause are relative to the window edge. */
1853 int this_scroll_margin = scroll_margin;
1854 int last_point_y = XFASTINT (w->last_point_y) - XINT (w->top);
1855 int last_point_x = (XFASTINT (w->last_point_x) - WINDOW_LEFT_MARGIN (w));
1857 /* Find where PT is located now on the frame. */
1858 /* Check just_this_one as a way of verifying that the
1859 window edges have not changed. */
1860 if (PT == XFASTINT (w->last_point) && just_this_one)
1862 pos.hpos = last_point_x;
1863 pos.vpos = last_point_y;
1864 pos.bufpos = PT;
1866 else if (PT > XFASTINT (w->last_point)
1867 && XFASTINT (w->last_point) > startp && just_this_one
1868 /* We can't use this if point is in the left margin of a
1869 hscrolled window, because w->last_point_x has been
1870 clipped to the window edges. */
1871 && !(last_point_x <= 0 && hscroll))
1873 pos = *compute_motion (XFASTINT (w->last_point),
1874 last_point_y, last_point_x, 0,
1875 PT, height,
1876 /* BUG FIX: See the comment of
1877 Fpos_visible_in_window_p (window.c). */
1878 - (1 << (BITS_PER_SHORT - 1)),
1879 width, hscroll,
1880 pos_tab_offset (w, startp), w);
1882 else
1884 pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0,
1885 PT, height,
1886 /* BUG FIX: See the comment of
1887 Fpos_visible_in_window_p (window.c). */
1888 - (1 << (BITS_PER_SHORT - 1)),
1889 width, hscroll,
1890 pos_tab_offset (w, startp), w);
1893 /* Don't use a scroll margin that is negative or too large. */
1894 if (this_scroll_margin < 0)
1895 this_scroll_margin = 0;
1897 if (XINT (w->height) < 4 * scroll_margin)
1898 this_scroll_margin = XINT (w->height) / 4;
1900 /* If point fits on the screen, and not within the scroll margin,
1901 we are ok. */
1902 if (pos.vpos < height - this_scroll_margin
1903 && (pos.vpos >= this_scroll_margin || startp == BEGV))
1905 /* Ok, point is still on frame */
1906 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
1908 /* These variables are supposed to be origin 1 */
1909 FRAME_CURSOR_X (f) = (WINDOW_LEFT_MARGIN (w)
1910 + minmax (0, pos.hpos, width));
1911 FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top);
1913 /* This doesn't do the trick, because if a window to the right of
1914 this one must be redisplayed, this does nothing because there
1915 is nothing in DesiredFrame yet, and then the other window is
1916 redisplayed, making likes that are empty in this window's columns.
1917 if (WINDOW_FULL_WIDTH_P (w))
1918 preserve_my_columns (w);
1920 if (current_buffer->clip_changed
1921 && ! NILP (Vwindow_scroll_functions))
1922 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1923 make_number (marker_position (w->start)));
1925 goto done;
1927 /* Don't bother trying redisplay with same start;
1928 we already know it will lose */
1930 /* If current starting point was originally the beginning of a line
1931 but no longer is, find a new starting point. */
1932 else if (!NILP (w->start_at_line_beg)
1933 && !(startp <= BEGV
1934 || FETCH_BYTE (startp - 1) == '\n'))
1936 goto recenter;
1938 else if (just_this_one && !MINI_WINDOW_P (w)
1939 && PT >= startp
1940 && XFASTINT (w->last_modified)
1941 /* or else vmotion on first line won't work. */
1942 && ! NILP (w->start_at_line_beg)
1943 && ! EQ (w->window_end_valid, Qnil)
1944 && do_id && !current_buffer->clip_changed
1945 && !blank_end_of_window
1946 && WINDOW_FULL_WIDTH_P (w)
1947 /* Can't use this case if highlighting a region. */
1948 && !(!NILP (Vtransient_mark_mode)
1949 && !NILP (current_buffer->mark_active))
1950 /* Don't use try_window_id if newline
1951 doesn't display as the end of a line. */
1952 && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n')))
1953 && NILP (w->region_showing)
1954 && EQ (last_arrow_position, COERCE_MARKER (Voverlay_arrow_position))
1955 && EQ (last_arrow_string, Voverlay_arrow_string)
1956 && (tem = try_window_id (FRAME_SELECTED_WINDOW (f)))
1957 && tem != -2)
1959 /* tem > 0 means success. tem == -1 means choose new start.
1960 tem == -2 means try again with same start,
1961 and nothing but whitespace follows the changed stuff.
1962 tem == 0 means try again with same start. */
1963 if (tem > 0)
1964 goto done;
1966 else if (startp >= BEGV && startp <= ZV
1967 && (startp < ZV
1968 /* Avoid starting at end of buffer. */
1969 #if 0 /* This change causes trouble for M-! finger & RET.
1970 It will have to be considered later. */
1971 || ! EQ (window, selected_window)
1972 /* Don't do the recentering if redisplay
1973 is not for no user action. */
1974 || preserve_echo_area
1975 #endif
1976 || startp == BEGV
1977 || (XFASTINT (w->last_modified) >= MODIFF
1978 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)))
1980 /* Try to redisplay starting at same place as before */
1981 /* If point has not moved off frame, accept the results */
1982 try_window (window, startp);
1983 if (cursor_vpos >= 0)
1985 if (!just_this_one || current_buffer->clip_changed
1986 || beg_unchanged < startp)
1987 /* Forget any recorded base line for line number display. */
1988 w->base_line_number = Qnil;
1990 if (current_buffer->clip_changed
1991 && ! NILP (Vwindow_scroll_functions))
1992 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1993 make_number (marker_position (w->start)));
1995 goto done;
1997 else
1998 cancel_my_columns (w);
2001 XSETFASTINT (w->last_modified, 0);
2002 XSETFASTINT (w->last_overlay_modified, 0);
2003 /* Redisplay the mode line. Select the buffer properly for that. */
2004 if (!update_mode_line)
2006 set_buffer_temp (old);
2007 set_buffer_internal_1 (XBUFFER (w->buffer));
2008 update_mode_line = 1;
2009 w->update_mode_line = Qt;
2012 /* Try to scroll by specified few lines */
2014 if (scroll_conservatively && !current_buffer->clip_changed
2015 && startp >= BEGV && startp <= ZV)
2017 int this_scroll_margin = scroll_margin;
2018 int scroll_margin_pos;
2020 /* Don't use a scroll margin that is negative or too large. */
2021 if (this_scroll_margin < 0)
2022 this_scroll_margin = 0;
2024 if (XINT (w->height) < 4 * this_scroll_margin)
2025 this_scroll_margin = XINT (w->height) / 4;
2027 scroll_margin_pos = Z - XFASTINT (w->window_end_pos);
2028 if (this_scroll_margin)
2030 pos = *vmotion (scroll_margin_pos, -this_scroll_margin, w);
2031 scroll_margin_pos = pos.bufpos;
2033 if (PT >= scroll_margin_pos)
2035 struct position pos;
2036 pos = *compute_motion (scroll_margin_pos, 0, 0, 0,
2037 PT, XFASTINT (w->height), 0,
2038 XFASTINT (w->width), XFASTINT (w->hscroll),
2039 pos_tab_offset (w, startp), w);
2040 if (pos.vpos > scroll_conservatively)
2041 goto scroll_fail_1;
2043 pos = *vmotion (startp, pos.vpos + 1, w);
2045 if (! NILP (Vwindow_scroll_functions))
2047 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
2048 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2049 make_number (pos.bufpos));
2050 pos.bufpos = marker_position (w->start);
2052 try_window (window, pos.bufpos);
2053 if (cursor_vpos >= 0)
2055 if (!just_this_one || current_buffer->clip_changed
2056 || beg_unchanged < startp)
2057 /* Forget any recorded base line for line number display. */
2058 w->base_line_number = Qnil;
2059 goto done;
2061 else
2062 cancel_my_columns (w);
2065 scroll_margin_pos = startp;
2066 if (this_scroll_margin)
2068 pos = *vmotion (scroll_margin_pos, this_scroll_margin, w);
2069 scroll_margin_pos = pos.bufpos;
2071 if (PT < scroll_margin_pos)
2073 struct position pos;
2074 pos = *compute_motion (PT, 0, 0, 0,
2075 scroll_margin_pos, XFASTINT (w->height), 0,
2076 XFASTINT (w->width), XFASTINT (w->hscroll),
2077 pos_tab_offset (w, startp), w);
2078 if (pos.vpos > scroll_conservatively)
2079 goto scroll_fail_1;
2081 pos = *vmotion (startp, -pos.vpos, w);
2083 if (! NILP (Vwindow_scroll_functions))
2085 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
2086 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2087 make_number (pos.bufpos));
2088 pos.bufpos = marker_position (w->start);
2090 try_window (window, pos.bufpos);
2091 if (cursor_vpos >= 0)
2093 if (!just_this_one || current_buffer->clip_changed
2094 || beg_unchanged < startp)
2095 /* Forget any recorded base line for line number display. */
2096 w->base_line_number = Qnil;
2097 goto done;
2099 else
2100 cancel_my_columns (w);
2102 scroll_fail_1: ;
2105 if (scroll_step && !current_buffer->clip_changed
2106 && startp >= BEGV && startp <= ZV)
2108 if (PT > startp)
2110 pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w);
2111 if (pos.vpos >= height)
2112 goto scroll_fail;
2115 pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w);
2117 if (PT >= pos.bufpos)
2119 if (! NILP (Vwindow_scroll_functions))
2121 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
2122 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2123 make_number (pos.bufpos));
2124 pos.bufpos = marker_position (w->start);
2126 try_window (window, pos.bufpos);
2127 if (cursor_vpos >= 0)
2129 if (!just_this_one || current_buffer->clip_changed
2130 || beg_unchanged < startp)
2131 /* Forget any recorded base line for line number display. */
2132 w->base_line_number = Qnil;
2133 goto done;
2135 else
2136 cancel_my_columns (w);
2138 scroll_fail: ;
2141 /* Finally, just choose place to start which centers point */
2143 recenter:
2144 /* Forget any previously recorded base line for line number display. */
2145 w->base_line_number = Qnil;
2147 pos = *vmotion (PT, - (height / 2), w);
2148 /* Set startp here explicitly in case that helps avoid an infinite loop
2149 in case the window-scroll-functions functions get errors. */
2150 Fset_marker (w->start, make_number (pos.bufpos), Qnil);
2151 if (! NILP (Vwindow_scroll_functions))
2153 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2154 make_number (pos.bufpos));
2155 pos.bufpos = marker_position (w->start);
2157 try_window (window, pos.bufpos);
2159 startp = marker_position (w->start);
2160 w->start_at_line_beg
2161 = (startp == BEGV || FETCH_BYTE (startp - 1) == '\n') ? Qt : Qnil;
2163 done:
2164 if ((update_mode_line
2165 /* If window not full width, must redo its mode line
2166 if the window to its side is being redone */
2167 || (!just_this_one && !WINDOW_FULL_WIDTH_P (w))
2168 || INTEGERP (w->base_line_pos)
2169 || (!NILP (w->column_number_displayed)
2170 && XFASTINT (w->column_number_displayed) != current_column ()))
2171 && height != XFASTINT (w->height))
2172 display_mode_line (w);
2173 if (! line_number_displayed
2174 && ! BUFFERP (w->base_line_pos))
2176 w->base_line_pos = Qnil;
2177 w->base_line_number = Qnil;
2180 /* When we reach a frame's selected window, redo the frame's menu bar. */
2181 if (update_mode_line
2182 && (FRAME_WINDOW_P (f)
2184 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2185 FRAME_EXTERNAL_MENU_BAR (f)
2186 #else
2187 FRAME_MENU_BAR_LINES (f) > 0
2188 #endif
2189 : FRAME_MENU_BAR_LINES (f) > 0)
2190 && EQ (FRAME_SELECTED_WINDOW (f), window))
2191 display_menu_bar (w);
2193 finish_scroll_bars:
2194 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
2196 int start, end, whole;
2198 /* Calculate the start and end positions for the current window.
2199 At some point, it would be nice to choose between scrollbars
2200 which reflect the whole buffer size, with special markers
2201 indicating narrowing, and scrollbars which reflect only the
2202 visible region.
2204 Note that minibuffers sometimes aren't displaying any text. */
2205 if (! MINI_WINDOW_P (w)
2206 || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs))
2208 whole = ZV - BEGV;
2209 start = marker_position (w->start) - BEGV;
2210 /* I don't think this is guaranteed to be right. For the
2211 moment, we'll pretend it is. */
2212 end = (Z - XINT (w->window_end_pos)) - BEGV;
2214 if (end < start) end = start;
2215 if (whole < (end - start)) whole = end - start;
2217 else
2218 start = end = whole = 0;
2220 /* Indicate what this scroll bar ought to be displaying now. */
2221 (*set_vertical_scroll_bar_hook) (w, end - start, whole, start);
2223 /* Note that we actually used the scroll bar attached to this window,
2224 so it shouldn't be deleted at the end of redisplay. */
2225 (*redeem_scroll_bar_hook) (w);
2228 BUF_PT (current_buffer) = opoint;
2229 if (update_mode_line)
2230 set_buffer_internal_1 (old);
2231 else
2232 set_buffer_temp (old);
2233 BUF_PT (current_buffer) = lpoint;
2236 /* Do full redisplay on one window, starting at position `pos'. */
2238 static void
2239 try_window (window, pos)
2240 Lisp_Object window;
2241 register int pos;
2243 register struct window *w = XWINDOW (window);
2244 register int height = window_internal_height (w);
2245 register int vpos = XFASTINT (w->top);
2246 register int last_text_vpos = vpos;
2247 FRAME_PTR f = XFRAME (w->frame);
2248 int width = window_internal_width (w) - 1;
2249 struct position val;
2251 /* POS should never be out of range! */
2252 if (pos < XBUFFER (w->buffer)->begv
2253 || pos > XBUFFER (w->buffer)->zv)
2254 abort ();
2256 Fset_marker (w->start, make_number (pos), Qnil);
2257 cursor_vpos = -1;
2258 overlay_arrow_seen = 0;
2259 zv_strings_seen = 0;
2260 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
2261 val.ovstring_chars_done = 0;
2262 val.tab_offset = pos_tab_offset (w, pos);
2264 while (--height >= 0)
2266 val = *display_text_line (w, pos, vpos, val.hpos, val.tab_offset,
2267 val.ovstring_chars_done);
2268 /* The following code is omitted because we maintain tab_offset
2269 in VAL. */
2270 #if 0
2271 tab_offset += width;
2272 if (val.vpos) tab_offset = 0;
2273 #endif /* 0 */
2274 vpos++;
2275 if (pos != val.bufpos)
2277 int invis = 0;
2278 #ifdef USE_TEXT_PROPERTIES
2279 Lisp_Object invis_prop;
2280 invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window);
2281 invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop);
2282 #endif
2284 last_text_vpos
2285 /* Next line, unless prev line ended in end of buffer with no cr */
2286 = vpos - (val.vpos
2287 && (FETCH_BYTE (val.bufpos - 1) != '\n' || invis));
2289 pos = val.bufpos;
2292 /* If last line is continued in middle of character,
2293 include the split character in the text considered on the frame */
2294 if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
2295 pos++;
2297 /* If bottom just moved off end of frame, change mode line percentage. */
2298 if (XFASTINT (w->window_end_pos) == 0
2299 && Z != pos)
2300 w->update_mode_line = Qt;
2302 /* Say where last char on frame will be, once redisplay is finished. */
2303 XSETFASTINT (w->window_end_pos, Z - pos);
2304 XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top));
2305 /* But that is not valid info until redisplay finishes. */
2306 w->window_end_valid = Qnil;
2309 /* Try to redisplay when buffer is modified locally,
2310 computing insert/delete line to preserve text outside
2311 the bounds of the changes.
2312 Return 1 if successful, 0 if if cannot tell what to do,
2313 or -1 to tell caller to find a new window start,
2314 or -2 to tell caller to do normal redisplay with same window start. */
2316 static int
2317 try_window_id (window)
2318 Lisp_Object window;
2320 int pos;
2321 register struct window *w = XWINDOW (window);
2322 register int height = window_internal_height (w);
2323 FRAME_PTR f = XFRAME (w->frame);
2324 int top = XFASTINT (w->top);
2325 int start = marker_position (w->start);
2326 int width = window_internal_width (w) - 1;
2327 int hscroll = XINT (w->hscroll);
2328 int lmargin = hscroll > 0 ? 1 - hscroll : 0;
2329 int did_motion;
2330 register int vpos;
2331 register int i, tem;
2332 int last_text_vpos = 0;
2333 int stop_vpos;
2334 int selective = (INTEGERP (current_buffer->selective_display)
2335 ? XINT (current_buffer->selective_display)
2336 : !NILP (current_buffer->selective_display) ? -1 : 0);
2338 struct position val, bp, ep, xp, pp;
2339 int scroll_amount = 0;
2340 int delta;
2341 int epto, old_tick;
2343 if (GPT - BEG < beg_unchanged)
2344 beg_unchanged = GPT - BEG;
2345 if (Z - GPT < end_unchanged)
2346 end_unchanged = Z - GPT;
2348 if (beg_unchanged + BEG < start)
2349 return 0; /* Give up if changes go above top of window */
2351 /* Find position before which nothing is changed. */
2352 bp = *compute_motion (start, 0, lmargin, 0,
2353 min (ZV, beg_unchanged + BEG), height,
2354 /* BUG FIX: See the comment of
2355 Fpos_visible_in_window_p() (window.c). */
2356 - (1 << (BITS_PER_SHORT - 1)),
2357 width, hscroll, pos_tab_offset (w, start), w);
2358 if (bp.vpos >= height)
2360 if (PT < bp.bufpos)
2362 /* All changes are beyond the window end, and point is on the screen.
2363 We don't need to change the text at all.
2364 But we need to update window_end_pos to account for
2365 any change in buffer size. */
2366 bp = *compute_motion (start, 0, lmargin, 0,
2367 ZV, height,
2368 /* BUG FIX: See the comment of
2369 Fpos_visible_in_window_p() (window.c). */
2370 - (1 << (BITS_PER_SHORT - 1)),
2371 width, hscroll, pos_tab_offset (w, start), w);
2372 XSETFASTINT (w->window_end_vpos, height);
2373 XSETFASTINT (w->window_end_pos, Z - bp.bufpos);
2374 goto findpoint;
2376 return 0;
2379 vpos = bp.vpos;
2381 /* Find beginning of that frame line. Must display from there. */
2382 bp = *vmotion (bp.bufpos, 0, w);
2384 pos = bp.bufpos;
2385 val.hpos = lmargin;
2386 if (pos < start)
2387 return -1;
2389 did_motion = 0;
2390 /* If about to start displaying at the beginning of a continuation line,
2391 really start with previous frame line, in case it was not
2392 continued when last redisplayed */
2393 if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
2395 /* Likewise if we have to worry about selective display. */
2396 (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0))
2398 bp = *vmotion (bp.bufpos, -1, w);
2399 --vpos;
2400 pos = bp.bufpos;
2402 val.tab_offset = bp.tab_offset; /* Update tab offset. */
2404 if (bp.contin && bp.hpos != lmargin)
2406 val.hpos = bp.prevhpos - width + lmargin;
2407 val.tab_offset = bp.tab_offset + bp.prevhpos - width;
2408 did_motion = 1;
2409 DEC_POS (pos);
2412 bp.vpos = vpos;
2414 /* Find first visible newline after which no more is changed. */
2415 tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1);
2416 if (selective > 0)
2417 while (tem < ZV - 1 && (indented_beyond_p (tem, selective)))
2418 tem = find_next_newline (tem, 1);
2420 /* Compute the cursor position after that newline. */
2421 ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem,
2422 height, - (1 << (BITS_PER_SHORT - 1)),
2423 width, hscroll,
2424 /* We have tab offset in VAL, use it. */
2425 val.tab_offset, w);
2427 /* If changes reach past the text available on the frame,
2428 just display rest of frame. */
2429 if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
2430 stop_vpos = height;
2431 else
2432 stop_vpos = ep.vpos;
2434 /* If no newline before ep, the line ep is on includes some changes
2435 that must be displayed. Make sure we don't stop before it. */
2436 /* Also, if changes reach all the way until ep.bufpos,
2437 it is possible that something was deleted after the
2438 newline before it, so the following line must be redrawn. */
2439 if (stop_vpos == ep.vpos
2440 && (ep.bufpos == BEGV
2441 || FETCH_BYTE (ep.bufpos - 1) != '\n'
2442 || ep.bufpos == Z - end_unchanged))
2443 stop_vpos = ep.vpos + 1;
2445 cursor_vpos = -1;
2446 overlay_arrow_seen = 0;
2447 zv_strings_seen = 0;
2449 /* If changes do not reach to bottom of window,
2450 figure out how much to scroll the rest of the window */
2451 if (stop_vpos < height)
2453 /* Now determine how far up or down the rest of the window has moved */
2454 xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2455 Z - XFASTINT (w->window_end_pos),
2456 /* Don't care for VPOS... */
2457 1 << (BITS_PER_SHORT - 1),
2458 /* ... nor HPOS. */
2459 1 << (BITS_PER_SHORT - 1),
2460 width, hscroll, ep.tab_offset, w);
2461 scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
2463 /* Is everything on frame below the changes whitespace?
2464 If so, no scrolling is really necessary. */
2465 for (i = ep.bufpos; i < xp.bufpos; i++)
2467 tem = FETCH_BYTE (i);
2468 if (tem != ' ' && tem != '\n' && tem != '\t')
2469 break;
2471 if (i == xp.bufpos)
2472 return -2;
2474 XSETFASTINT (w->window_end_vpos,
2475 XFASTINT (w->window_end_vpos) + scroll_amount);
2477 /* Before doing any scrolling, verify that point will be on frame. */
2478 if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.vpos < height))
2480 if (PT <= xp.bufpos)
2482 pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1,
2483 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2484 width, hscroll,
2485 /* We have tab offset in EP, use it. */
2486 ep.tab_offset, w);
2488 else
2490 pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1,
2491 PT, height, - (1 << (BITS_PER_SHORT - 1)),
2492 width, hscroll,
2493 /* We have tab offset in XP, use it. */
2494 xp.tab_offset, w);
2496 if (pp.bufpos < PT || pp.vpos == height)
2497 return 0;
2498 cursor_vpos = pp.vpos + top;
2499 cursor_hpos = WINDOW_LEFT_MARGIN (w) + minmax (0, pp.hpos, width);
2502 if (stop_vpos - scroll_amount >= height
2503 || ep.bufpos == xp.bufpos)
2505 if (scroll_amount < 0)
2506 stop_vpos -= scroll_amount;
2507 scroll_amount = 0;
2508 /* In this path, we have altered window_end_vpos
2509 and not left it negative.
2510 We must make sure that, in case display is preempted
2511 before the frame changes to reflect what we do here,
2512 further updates will not come to try_window_id
2513 and assume the frame and window_end_vpos match. */
2514 blank_end_of_window = 1;
2516 else if (!scroll_amount)
2518 /* Even if we don't need to scroll, we must adjust the
2519 charstarts of subsequent lines (that we won't redisplay)
2520 according to the amount of text inserted or deleted. */
2521 int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2522 int adjust = ep.bufpos - oldpos;
2523 adjust_window_charstarts (w, ep.vpos + top - 1, adjust);
2525 else if (bp.bufpos == Z - end_unchanged)
2527 /* If reprinting everything is nearly as fast as scrolling,
2528 don't bother scrolling. Can happen if lines are short. */
2529 if (scroll_cost (f, bp.vpos + top - scroll_amount,
2530 top + height - max (0, scroll_amount),
2531 scroll_amount)
2532 > xp.bufpos - bp.bufpos - 20)
2533 /* Return "try normal display with same window-start."
2534 Too bad we can't prevent further scroll-thinking. */
2535 return -2;
2536 /* If pure deletion, scroll up as many lines as possible.
2537 In common case of killing a line, this can save the
2538 following line from being overwritten by scrolling
2539 and therefore having to be redrawn. */
2540 tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount,
2541 top + height - max (0, scroll_amount),
2542 scroll_amount, bp.bufpos);
2543 if (!tem)
2544 stop_vpos = height;
2545 else
2547 /* scroll_frame_lines did not properly adjust subsequent
2548 lines' charstarts in the case where the text of the
2549 screen line at bp.vpos has changed.
2550 (This can happen in a deletion that ends in mid-line.)
2551 To adjust properly, we need to make things consistent
2552 at the position ep.
2553 So do a second adjust to make that happen.
2554 Note that stop_vpos >= ep.vpos, so it is sufficient
2555 to update the charstarts for lines at ep.vpos and below. */
2556 int oldstart
2557 = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0];
2558 adjust_window_charstarts (w, ep.vpos + top - 1,
2559 ep.bufpos - oldstart);
2562 else if (scroll_amount)
2564 /* If reprinting everything is nearly as fast as scrolling,
2565 don't bother scrolling. Can happen if lines are short. */
2566 /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
2567 overestimate of cost of reprinting, since xp.bufpos
2568 would end up below the bottom of the window. */
2569 if (scroll_cost (f, ep.vpos + top - scroll_amount,
2570 top + height - max (0, scroll_amount),
2571 scroll_amount)
2572 > xp.bufpos - ep.bufpos - 20)
2573 /* Return "try normal display with same window-start."
2574 Too bad we can't prevent further scroll-thinking. */
2575 return -2;
2576 tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount,
2577 top + height - max (0, scroll_amount),
2578 scroll_amount, ep.bufpos);
2579 if (!tem) stop_vpos = height;
2583 /* In any case, do not display past bottom of window */
2584 if (stop_vpos >= height)
2586 stop_vpos = height;
2587 scroll_amount = 0;
2590 /* Handle case where pos is before w->start --
2591 can happen if part of line had been clipped and is not clipped now */
2592 if (vpos == 0 && pos < marker_position (w->start))
2593 Fset_marker (w->start, make_number (pos), Qnil);
2595 /* Redisplay the lines where the text was changed */
2596 last_text_vpos = vpos;
2597 /* The following code is omitted because we maintain tab offset in
2598 val.tab_offset. */
2599 #if 0
2600 tab_offset = pos_tab_offset (w, pos);
2601 /* If we are starting display in mid-character, correct tab_offset
2602 to account for passing the line that that character really starts in. */
2603 if (val.hpos < lmargin)
2604 tab_offset += width;
2605 #endif /* 0 */
2606 old_tick = MODIFF;
2607 while (vpos < stop_vpos)
2609 val = *display_text_line (w, pos, top + vpos++, val.hpos, val.tab_offset,
2610 val.ovstring_chars_done);
2611 /* If display_text_line ran a hook and changed some text,
2612 redisplay all the way to bottom of buffer
2613 So that we show the changes. */
2614 if (old_tick != MODIFF)
2615 stop_vpos = height;
2616 /* The following code is omitted because we maintain tab offset
2617 in val.tab_offset. */
2618 #if 0
2619 tab_offset += width;
2620 if (val.vpos) tab_offset = 0;
2621 #endif
2622 if (pos != val.bufpos)
2623 last_text_vpos
2624 /* Next line, unless prev line ended in end of buffer with no cr */
2625 = vpos - (val.vpos && FETCH_BYTE (val.bufpos - 1) != '\n');
2626 pos = val.bufpos;
2629 /* There are two cases:
2630 1) we have displayed down to the bottom of the window
2631 2) we have scrolled lines below stop_vpos by scroll_amount */
2633 if (vpos == height)
2635 /* If last line is continued in middle of character,
2636 include the split character in the text considered on the frame */
2637 if (val.hpos < lmargin)
2638 val.bufpos++;
2639 XSETFASTINT (w->window_end_vpos, last_text_vpos);
2640 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2643 /* If scrolling made blank lines at window bottom,
2644 redisplay to fill those lines */
2645 if (scroll_amount < 0)
2647 /* Don't consider these lines for general-purpose scrolling.
2648 That will save time in the scrolling computation. */
2649 FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos;
2650 vpos = xp.vpos;
2651 pos = xp.bufpos;
2652 val.hpos = xp.hpos;
2653 val.tab_offset = xp.tab_offset;
2654 if (pos == ZV)
2655 { /* Display from next line */
2656 vpos = height + scroll_amount;
2657 val.hpos = lmargin;
2658 val.tab_offset = 0;
2660 else if (xp.contin && xp.hpos != lmargin)
2662 val.hpos = xp.prevhpos - width + lmargin;
2663 val.tab_offset = xp.tab_offset + bp.prevhpos - width;
2664 DEC_POS (pos);
2667 blank_end_of_window = 1;
2668 /* The following code is omitted because we maintain tab offset
2669 in val.tab_offset. */
2670 #if 0
2671 tab_offset = pos_tab_offset (w, pos);
2672 /* If we are starting display in mid-character, correct tab_offset
2673 to account for passing the line that that character starts in. */
2674 if (val.hpos < lmargin)
2675 tab_offset += width;
2676 #endif
2677 while (vpos < height)
2679 val = *display_text_line (w, pos, top + vpos++, val.hpos,
2680 val.tab_offset, val.ovstring_chars_done);
2681 /* The following code is omitted because we maintain tab
2682 offset in val.tab_offset. */
2683 #if 0
2684 tab_offset += width;
2685 if (val.vpos) tab_offset = 0;
2686 #endif /* 0 */
2687 pos = val.bufpos;
2690 /* Here is a case where display_text_line sets cursor_vpos wrong.
2691 Make it be fixed up, below. */
2692 if (xp.bufpos == ZV
2693 && xp.bufpos == PT)
2694 cursor_vpos = -1;
2697 /* If bottom just moved off end of frame, change mode line percentage. */
2698 if (XFASTINT (w->window_end_pos) == 0
2699 && Z != val.bufpos)
2700 w->update_mode_line = Qt;
2702 /* Attempt to adjust end-of-text positions to new bottom line */
2703 if (scroll_amount)
2705 delta = height - xp.vpos;
2706 if (delta < 0
2707 || (delta > 0 && xp.bufpos <= ZV)
2708 || (delta == 0 && xp.hpos))
2710 val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w);
2711 XSETFASTINT (w->window_end_pos, Z - val.bufpos);
2712 XSETFASTINT (w->window_end_vpos,
2713 XFASTINT (w->window_end_vpos) + val.vpos);
2717 w->window_end_valid = Qnil;
2719 /* If point was not in a line that was displayed, find it */
2720 if (cursor_vpos < 0)
2722 findpoint:
2723 val = *compute_motion (start, 0, lmargin, 0, PT,
2724 /* Don't care for VPOS... */
2725 1 << (BITS_PER_SHORT - 1),
2726 /* ... nor HPOS. */
2727 1 << (BITS_PER_SHORT - 1),
2728 width, hscroll, pos_tab_offset (w, start), w);
2729 /* Admit failure if point is off frame now */
2730 if (val.vpos >= height)
2732 for (vpos = 0; vpos < height; vpos++)
2733 cancel_line (vpos + top, f);
2734 return 0;
2736 cursor_vpos = val.vpos + top;
2737 cursor_hpos = WINDOW_LEFT_MARGIN (w) + minmax (0, val.hpos, width);
2740 FRAME_CURSOR_X (f) = cursor_hpos;
2741 FRAME_CURSOR_Y (f) = cursor_vpos;
2743 if (debug_end_pos)
2745 val = *compute_motion (start, 0, lmargin, 0, ZV,
2746 height, - (1 << (BITS_PER_SHORT - 1)),
2747 width, hscroll, pos_tab_offset (w, start), w);
2748 if (val.vpos != XFASTINT (w->window_end_vpos))
2749 abort ();
2750 if (XFASTINT (w->window_end_pos)
2751 != Z - val.bufpos)
2752 abort ();
2755 return 1;
2758 /* Copy LEN glyphs starting address FROM to the rope TO.
2759 But don't actually copy the parts that would come in before S.
2760 Value is TO, advanced past the copied data.
2761 F is the frame we are displaying in. */
2763 static GLYPH *
2764 copy_part_of_rope (f, to, s, from, len, face)
2765 FRAME_PTR f;
2766 register GLYPH *to; /* Copy to here. */
2767 register GLYPH *s; /* Starting point. */
2768 Lisp_Object *from; /* Data to copy. */
2769 int len;
2770 int face; /* Face to apply to glyphs which don't specify one. */
2772 int n = len;
2773 register Lisp_Object *fp = from;
2774 /* These cache the results of the last call to compute_glyph_face. */
2775 int last_code = -1;
2776 int last_merged = 0;
2778 #ifdef HAVE_FACES
2779 if (! FRAME_TERMCAP_P (f))
2780 while (n--)
2782 GLYPH glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2783 int facecode;
2784 unsigned int c = FAST_GLYPH_CHAR (glyph);
2786 if (c > MAX_CHAR)
2787 /* For an invalid character code, use space. */
2788 c = ' ';
2790 if (FAST_GLYPH_FACE (glyph) == 0)
2791 /* If GLYPH has no face code, use FACE. */
2792 facecode = face;
2793 else if (FAST_GLYPH_FACE (glyph) == last_code)
2794 /* If it's same as previous glyph, use same result. */
2795 facecode = last_merged;
2796 else
2798 /* Merge this glyph's face and remember the result. */
2799 last_code = FAST_GLYPH_FACE (glyph);
2800 last_merged = facecode = compute_glyph_face (f, last_code, face);
2803 if (to >= s)
2804 *to = FAST_MAKE_GLYPH (c, facecode);
2805 ++to;
2806 ++fp;
2808 else
2809 #endif
2810 while (n--)
2812 if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0);
2813 ++to;
2814 ++fp;
2816 return to;
2819 /* Correct a glyph by replacing its specified user-level face code
2820 with a displayable computed face code. */
2822 static GLYPH
2823 fix_glyph (f, glyph, cface)
2824 FRAME_PTR f;
2825 GLYPH glyph;
2826 int cface;
2828 #ifdef HAVE_FACES
2829 if (! FRAME_TERMCAP_P (f))
2831 if (FAST_GLYPH_FACE (glyph) != 0)
2832 cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface);
2833 glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface);
2835 #endif
2836 return glyph;
2839 /* Display one line of window W, starting at position START in W's buffer.
2841 Display starting at horizontal position HPOS, expressed relative to
2842 W's left edge. In situations where the text at START shouldn't
2843 start at the left margin (i.e. when the window is hscrolled, or
2844 we're continuing a line which left off in the midst of a
2845 multi-column character), HPOS should be negative; we throw away
2846 characters up 'til hpos = 0. So, HPOS must take hscrolling into
2847 account.
2849 TABOFFSET is an offset for ostensible hpos, used in tab stop calculations.
2851 OVSTR_DONE is the number of chars of overlay before/after strings
2852 at this position which have already been processed.
2854 Display on position VPOS on the frame. It is origin 0, relative to
2855 the top of the frame, not W.
2857 Returns a STRUCT POSITION giving character to start next line with
2858 and where to display it, including a zero or negative hpos.
2859 The vpos field is not really a vpos; it is 1 unless the line is continued */
2861 struct position val_display_text_line;
2863 static struct position *
2864 display_text_line (w, start, vpos, hpos, taboffset, ovstr_done)
2865 struct window *w;
2866 int start;
2867 int vpos;
2868 int hpos;
2869 int taboffset;
2870 int ovstr_done;
2872 register int pos = start;
2873 register int c;
2874 register GLYPH *p1;
2875 register int pause;
2876 register unsigned char *p;
2877 GLYPH *endp;
2878 register GLYPH *leftmargin;
2879 register GLYPH *p1prev;
2880 register GLYPH *p1start;
2881 int prevpos;
2882 int *charstart;
2883 FRAME_PTR f = XFRAME (w->frame);
2884 int tab_width = XINT (current_buffer->tab_width);
2885 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
2886 int width = window_internal_width (w) - 1;
2887 struct position val;
2888 int lastpos;
2889 int invis;
2890 int last_invis_skip = 0;
2891 Lisp_Object last_invis_prop;
2892 int hscroll = XINT (w->hscroll);
2893 int truncate = (hscroll
2894 || (truncate_partial_width_windows
2895 && !WINDOW_FULL_WIDTH_P (w))
2896 || !NILP (current_buffer->truncate_lines));
2898 /* 1 if we should highlight the region. */
2899 int highlight_region
2900 = (!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active)
2901 && (XWINDOW (current_buffer->last_selected_window) == w
2902 || highlight_nonselected_windows));
2903 int region_beg, region_end;
2905 int selective = (INTEGERP (current_buffer->selective_display)
2906 ? XINT (current_buffer->selective_display)
2907 : !NILP (current_buffer->selective_display) ? -1 : 0);
2908 register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
2909 register struct Lisp_Char_Table *dp = window_display_table (w);
2911 Lisp_Object default_invis_vector[3];
2912 /* Number of characters of ellipsis to display after an invisible line
2913 if it calls for an ellipsis.
2914 Note that this value can be nonzero regardless of whether
2915 selective display is enabled--you must check that separately. */
2916 int selective_rlen
2917 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2918 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size
2919 : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0);
2920 /* This is the sequence of Lisp objects to display
2921 when there are invisible lines. */
2922 Lisp_Object *invis_vector_contents
2923 = (dp && VECTORP (DISP_INVIS_VECTOR (dp))
2924 ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents
2925 : default_invis_vector);
2927 GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp))
2928 || !GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (dp)))
2929 ? '$' : XINT (DISP_TRUNC_GLYPH (dp)));
2930 GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp))
2931 || !GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (dp)))
2932 ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp)));
2934 /* If 1, we must handle multibyte characters. */
2935 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
2936 /* Length of multibyte form of each character. */
2937 int len;
2938 /* Glyphs generated should be set this bit mask if text must be
2939 displayed from right to left. */
2940 GLYPH rev_dir_bit = (NILP (current_buffer->direction_reversed)
2941 ? 0 : GLYPH_MASK_REV_DIR);
2943 /* The next buffer location at which the face should change, due
2944 to overlays or text property changes. */
2945 int next_face_change;
2947 /* The next location where the `invisible' property changes, or an
2948 overlay starts or ends. */
2949 int next_boundary;
2951 /* The face we're currently using. */
2952 int current_face = 0;
2953 int i;
2955 XSETFASTINT (default_invis_vector[2], '.');
2956 default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2];
2958 get_display_line (f, vpos, WINDOW_LEFT_MARGIN (w));
2959 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
2961 /* Show where to highlight the region. */
2962 if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0
2963 /* Maybe highlight only in selected window. */
2964 && (highlight_nonselected_windows
2965 || w == XWINDOW (selected_window)))
2967 region_beg = marker_position (current_buffer->mark);
2968 if (PT < region_beg)
2970 region_end = region_beg;
2971 region_beg = PT;
2973 else
2974 region_end = PT;
2975 w->region_showing = Qt;
2977 else
2979 region_beg = region_end = -1;
2980 w->region_showing = Qnil;
2983 if (MINI_WINDOW_P (w)
2984 && start == BEG
2985 && vpos == XFASTINT (w->top))
2987 if (! NILP (minibuf_prompt))
2989 int old_width = minibuf_prompt_width;
2991 minibuf_prompt_width
2992 = (display_string (w, vpos, XSTRING (minibuf_prompt)->data,
2993 XSTRING (minibuf_prompt)->size,
2994 hpos + WINDOW_LEFT_MARGIN (w),
2995 /* Display a space if we truncate. */
2996 ' ',
2997 1, -1,
2998 /* Truncate the prompt a little before the
2999 margin, so user input can at least start
3000 on the first line. */
3001 (XFASTINT (w->width) > 10
3002 ? XFASTINT (w->width) - 4 : -1),
3004 - hpos - WINDOW_LEFT_MARGIN (w));
3005 hpos += minibuf_prompt_width;
3006 taboffset -= minibuf_prompt_width - old_width;
3008 else
3009 minibuf_prompt_width = 0;
3012 /* If we're hscrolled at all, use compute_motion to skip over any
3013 text off the left edge of the window. compute_motion may know
3014 tricks to do this faster than we can. */
3015 if (hpos < 0)
3017 struct position *left_edge
3018 = compute_motion (pos, vpos, hpos, 0,
3019 ZV, vpos, 0,
3020 width, hscroll, taboffset, w);
3022 /* Retrieve the buffer position and column provided by
3023 compute_motion. We can't assume that the column will be
3024 zero, because you may have multi-column characters crossing
3025 the left margin.
3027 compute_motion may have moved us past the screen position we
3028 requested, if we hit a multi-column character, or the end of
3029 the line. If so, back up. */
3030 if (left_edge->vpos > vpos
3031 || left_edge->hpos > 0)
3033 pos = left_edge->bufpos;
3034 /* Since this should not be a valid multibyte character, we
3035 can decrease POS by 1. */
3036 pos--;
3037 hpos = left_edge->prevhpos;
3039 else
3041 pos = left_edge->bufpos;
3042 hpos = left_edge->hpos;
3046 hpos += WINDOW_LEFT_MARGIN (w);
3048 desired_glyphs->bufp[vpos] = start;
3049 p1 = desired_glyphs->glyphs[vpos] + hpos;
3050 p1start = p1;
3051 charstart = desired_glyphs->charstarts[vpos] + hpos;
3052 /* In case we don't ever write anything into it... */
3053 desired_glyphs->charstarts[vpos][WINDOW_LEFT_MARGIN (w)] = -1;
3054 leftmargin = desired_glyphs->glyphs[vpos] + WINDOW_LEFT_MARGIN (w);
3055 endp = leftmargin + width;
3057 /* Arrange the overlays nicely for our purposes. Usually, we call
3058 display_text_line on only one line at a time, in which case this
3059 can't really hurt too much, or we call it on lines which appear
3060 one after another in the buffer, in which case all calls to
3061 recenter_overlay_lists but the first will be pretty cheap. */
3062 recenter_overlay_lists (current_buffer, pos);
3064 /* Loop generating characters.
3065 Stop at end of buffer, before newline,
3066 if reach or pass continuation column,
3067 or at face change. */
3068 pause = pos;
3069 next_face_change = pos;
3070 next_boundary = pos;
3071 p1prev = p1;
3072 prevpos = pos;
3074 /* If the window is hscrolled and point is in the invisible part of the
3075 current line beyond the left margin we can record the cursor location
3076 right away. */
3077 if (hscroll && start <= PT && PT < pos && cursor_vpos < 0)
3079 cursor_vpos = vpos;
3080 cursor_hpos = p1 - leftmargin;
3083 while (p1 < endp)
3085 if (pos >= pause)
3087 int e_t_h;
3089 while (pos == next_boundary)
3091 Lisp_Object position, limit, prop, ww;
3093 /* Display the overlay strings here, unless we're at ZV
3094 and have already displayed the appropriate strings
3095 on an earlier line. */
3096 if (pos < ZV || !zv_strings_seen++)
3098 int ovlen;
3099 unsigned char *ovstr;
3100 ovlen = overlay_strings (pos, w, &ovstr);
3102 if (ovlen > 0)
3104 /* Skip the ones we did in a previous line. */
3105 ovstr += ovstr_done;
3106 ovlen -= ovstr_done;
3108 while (ovlen > 0)
3110 int charset, cols;
3111 GLYPH g;
3113 if (multibyte)
3115 c = STRING_CHAR_AND_LENGTH (ovstr, ovlen, len);
3116 ovstr += len, ovlen -= len, ovstr_done += len;
3117 charset = CHAR_CHARSET (c);
3118 cols = (charset == CHARSET_COMPOSITION
3119 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
3120 : CHARSET_WIDTH (charset));
3122 else
3124 c = *ovstr++, ovlen--, ovstr_done++;
3125 cols = 1;
3127 g = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3128 while (cols-- > 0)
3130 if (p1 >= leftmargin && p1 < endp)
3131 *p1 = g, g |= GLYPH_MASK_PADDING;
3132 p1++;
3135 /* If we did all the overlay strings
3136 and we have room for text, clear ovstr_done
3137 just for neatness' sake. */
3138 if (ovlen == 0 && p1 < endp)
3139 ovstr_done = 0;
3143 /* Did we reach point? Record the cursor location. */
3144 if (pos == PT && cursor_vpos < 0)
3146 cursor_vpos = vpos;
3147 cursor_hpos = p1 - leftmargin;
3150 if (pos >= ZV)
3151 break;
3153 XSETFASTINT (position, pos);
3154 limit = Fnext_overlay_change (position);
3155 #ifdef USE_TEXT_PROPERTIES
3156 /* This is just an estimate to give reasonable
3157 performance; nothing should go wrong if it is too small. */
3158 if (XFASTINT (limit) > pos + 50)
3160 int limitpos = pos + 50;
3161 if (limitpos < Z)
3162 INC_POS (limitpos); /* Adjust to character boundary. */
3163 XSETFASTINT (limit, limitpos);
3165 limit = Fnext_single_property_change (position, Qinvisible,
3166 Fcurrent_buffer (), limit);
3167 #endif
3168 next_boundary = XFASTINT (limit);
3169 /* if the `invisible' property is set, we can skip to
3170 the next property change. */
3171 XSETWINDOW (ww, w);
3172 prop = Fget_char_property (position, Qinvisible, ww);
3173 if (TEXT_PROP_MEANS_INVISIBLE (prop))
3175 if (pos < PT && next_boundary >= PT)
3177 cursor_vpos = vpos;
3178 cursor_hpos = p1 - leftmargin;
3180 pos = next_boundary;
3181 last_invis_skip = pos;
3182 last_invis_prop = prop;
3186 /* Did we reach point? Record the cursor location. */
3187 if (pos == PT && cursor_vpos < 0)
3189 cursor_vpos = vpos;
3190 cursor_hpos = p1 - leftmargin;
3193 /* Did we hit the end of the visible region of the buffer?
3194 Stop here. */
3195 if (pos >= ZV)
3197 /* Update charstarts for the end of this line. */
3198 /* Do nothing if off the left edge or at the right edge. */
3199 if (p1 >= leftmargin && p1 + 1 != endp)
3201 int *p2x = &charstart[(p1 < leftmargin
3202 ? leftmargin : p1)
3203 - p1start];
3204 *p2x++ = pos;
3206 break;
3209 /* Figure out where (if at all) the
3210 redisplay_end_trigger-hook should run. */
3211 if (MARKERP (w->redisplay_end_trigger)
3212 && XMARKER (w->redisplay_end_trigger)->buffer != 0)
3213 e_t_h = marker_position (w->redisplay_end_trigger);
3214 else if (INTEGERP (w->redisplay_end_trigger))
3215 e_t_h = XINT (w->redisplay_end_trigger);
3216 else
3217 e_t_h = ZV;
3219 /* If we've gone past the place to run a hook,
3220 run the hook. */
3221 if (pos >= e_t_h && e_t_h != ZV)
3223 Lisp_Object args[3];
3225 args[0] = Qredisplay_end_trigger_functions;
3226 XSETWINDOW (args[1], w);
3227 XSETINT (args[2], e_t_h);
3229 /* Since we are *trying* to run these functions,
3230 don't try to run them again, even if they get an error. */
3231 w->redisplay_end_trigger = Qnil;
3232 Frun_hook_with_args (3, args);
3234 e_t_h = ZV;
3235 /* Notice if it changed the face of this character. */
3236 next_face_change = pos;
3239 #ifdef HAVE_FACES
3240 /* Did we hit a face change? Figure out what face we should
3241 use now. We also hit this the first time through the
3242 loop, to see what face we should start with. */
3243 if (pos >= next_face_change
3244 && (FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f)))
3246 int limit = pos + 50;
3248 if (limit < Z && !CHAR_HEAD_P (POS_ADDR (limit)))
3249 INC_POS (limit); /* Adjust to character boundary. */
3250 current_face = compute_char_face (f, w, pos,
3251 region_beg, region_end,
3252 &next_face_change, limit, 0);
3254 #endif
3256 /* Compute the next place we need to stop
3257 and do something special; set PAUSE. */
3259 pause = ZV;
3261 if (pos < next_boundary && next_boundary < pause)
3262 pause = next_boundary;
3263 if (pos < next_face_change && next_face_change < pause)
3264 pause = next_face_change;
3266 if (e_t_h < pause)
3267 pause = e_t_h;
3269 /* Wouldn't you hate to read the next line to someone over
3270 the phone? */
3271 if (pos < PT && PT < pause)
3272 pause = PT;
3273 if (pos < GPT && GPT < pause)
3274 pause = GPT;
3276 p = POS_ADDR (pos);
3279 if (p1 >= endp)
3280 break;
3282 p1prev = p1;
3284 if (multibyte)
3285 /* PAUSE is surely at character boundary. */
3286 c = STRING_CHAR_AND_LENGTH (p, pause - pos, len), p += len;
3287 else
3288 c = *p++, len = 1;
3289 /* Let a display table override all standard display methods. */
3290 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
3292 p1 = copy_part_of_rope (f, p1, leftmargin,
3293 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
3294 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
3295 current_face, rev_dir_bit);
3297 else if (c >= 040 && c < 0177)
3299 if (p1 >= leftmargin)
3300 *p1 = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3301 p1++;
3303 else if (c == '\n')
3305 #if 0
3306 /* Same as p1prev, but after the invis_vector_contents text
3307 (if we have that on this line). */
3308 GLYPH *p1prev_modified;
3309 #endif
3311 invis = 0;
3312 if (last_invis_skip == pos
3313 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop))
3314 invis = 1;
3315 while (pos + 1 < ZV
3316 && selective > 0
3317 && indented_beyond_p (pos + 1, selective))
3319 invis = 1;
3320 pos = find_next_newline (pos + 1, 1);
3321 if (FETCH_BYTE (pos - 1) == '\n')
3322 pos--;
3324 if (invis && selective_rlen > 0 && p1 >= leftmargin)
3326 #if 0
3327 GLYPH *cs, *csend;
3329 cs = charstart + (p1 - p1start);
3330 #endif
3332 p1 += selective_rlen;
3333 if (p1 - leftmargin > width)
3334 p1 = endp;
3336 #if 0 /* This needs more work; charstarts needs to record
3337 both whether a position ho;ds an ellipsis character
3338 and what buffer position it corresponds to. */
3339 csend = charstart + (p1 - p1start);
3340 while (cs != csend)
3341 *cs++ = -2;
3342 /* The idea is to use p1prev_modified instead of p1prev
3343 in the loop below over p2x. */
3344 p1prev_modified = p1;
3345 #endif
3347 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
3348 (p1 - p1prev), current_face, rev_dir_bit);
3351 /* Update charstarts for the newline that ended this line. */
3352 /* Do nothing here for a char that's entirely off the left edge
3353 or if it starts at the right edge. */
3354 if (p1 >= leftmargin && p1prev != endp)
3356 /* Store the newline's position into charstarts
3357 for the column where the newline starts.
3358 Store -1 for the rest of the glyphs it occupies. */
3359 int *p2x = &charstart[(p1prev < leftmargin
3360 ? leftmargin : p1prev)
3361 - p1start];
3362 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3364 *p2x++ = pos;
3365 while (p2x < p2)
3366 *p2x++ = -1;
3368 #ifdef HAVE_FACES
3369 /* Draw the face of the newline character as extending all the
3370 way to the end of the frame line. */
3371 if (current_face)
3373 if (p1 < leftmargin)
3374 p1 = leftmargin;
3375 while (p1 < endp)
3376 *p1++ = FAST_MAKE_GLYPH (' ', current_face) | rev_dir_bit;
3378 #endif
3380 break;
3382 else if (c == '\t')
3386 if (p1 >= leftmargin && p1 < endp)
3387 *p1 = MAKE_GLYPH (f, ' ', current_face) | rev_dir_bit;
3388 p1++;
3390 while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0))
3391 % tab_width);
3393 else if (c == Ctl ('M') && selective == -1)
3395 pos = find_next_newline (pos, 1);
3396 if (FETCH_BYTE (pos - 1) == '\n')
3397 pos--;
3398 if (selective_rlen > 0)
3400 p1 += selective_rlen;
3401 if (p1 - leftmargin > width)
3402 p1 = endp;
3403 copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents,
3404 (p1 - p1prev), current_face, rev_dir_bit);
3406 #ifdef HAVE_FACES
3407 /* Draw the face of the newline character as extending all the
3408 way to the end of the frame line. */
3409 if (current_face)
3411 if (p1 < leftmargin)
3412 p1 = leftmargin;
3413 while (p1 < endp)
3414 *p1++ = FAST_MAKE_GLYPH (' ', current_face) | rev_dir_bit;
3416 #endif
3418 /* Update charstarts for the ^M that ended this line. */
3419 /* Do nothing here for a char that's entirely off the left edge
3420 or if it starts at the right edge. */
3421 if (p1 >= leftmargin && p1prev != endp)
3423 /* Store the newline's position into charstarts
3424 for the column where the newline starts.
3425 Store -1 for the rest of the glyphs it occupies. */
3426 int *p2x = &charstart[(p1prev < leftmargin
3427 ? leftmargin : p1prev)
3428 - p1start];
3429 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3431 *p2x++ = pos;
3432 while (p2x < p2)
3433 *p2x++ = -1;
3435 break;
3437 else if (c < 0200 && ctl_arrow)
3439 if (p1 >= leftmargin)
3440 *p1 = (fix_glyph
3441 (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
3442 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp)))
3443 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
3444 current_face)
3445 | rev_dir_bit);
3446 p1++;
3447 if (p1 >= leftmargin && p1 < endp)
3448 *p1 = MAKE_GLYPH (f, c ^ 0100, current_face) | rev_dir_bit;
3449 p1++;
3451 else if (len == 1)
3453 /* C is not a multibyte character. */
3454 if (p1 >= leftmargin)
3455 *p1 = (fix_glyph
3456 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
3457 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
3458 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
3459 current_face)
3460 | rev_dir_bit);
3461 p1++;
3462 if (p1 >= leftmargin && p1 < endp)
3463 *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face) | rev_dir_bit;
3464 p1++;
3465 if (p1 >= leftmargin && p1 < endp)
3466 *p1 = (MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face)
3467 | rev_dir_bit);
3468 p1++;
3469 if (p1 >= leftmargin && p1 < endp)
3470 *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face) | rev_dir_bit;
3471 p1++;
3473 else
3475 /* C is a multibyte character. */
3476 int charset = CHAR_CHARSET (c);
3477 int columns = (charset == CHARSET_COMPOSITION
3478 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
3479 : CHARSET_WIDTH (charset));
3480 GLYPH g = MAKE_GLYPH (f, c, current_face) | rev_dir_bit;
3482 while (columns--)
3484 if (p1 >= leftmargin && p1 < endp)
3485 *p1 = g, g |= GLYPH_MASK_PADDING;
3486 p1++;
3490 prevpos = pos;
3491 pos += len;
3493 /* Update charstarts for the character just output. */
3495 /* Do nothing here for a char that's entirely off the left edge. */
3496 if (p1 >= leftmargin)
3498 /* Store the char's position into charstarts
3499 for the first glyph occupied by this char.
3500 Store -1 for the rest of the glyphs it occupies. */
3501 if (p1 != p1prev)
3503 int *p2x = &charstart[(p1prev < leftmargin
3504 ? leftmargin : p1prev)
3505 - p1start];
3506 int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start];
3508 if (p2x < p2)
3509 *p2x++ = prevpos;
3510 while (p2x < p2)
3511 *p2x++ = -1;
3516 val.hpos = - XINT (w->hscroll);
3517 if (val.hpos)
3518 val.hpos++;
3520 val.vpos = 1;
3522 lastpos = pos;
3524 /* Store 0 in this charstart line for the positions where
3525 there is no character. But do leave what was recorded
3526 for the character that ended the line. */
3527 /* Add 1 in the endtest to compensate for the fact that ENDP was
3528 made from WIDTH, which is 1 less than the window's actual
3529 internal width. */
3530 i = p1 - p1start + 1;
3531 if (p1 < leftmargin)
3532 i += leftmargin - p1;
3533 for (; i < endp - p1start + 1; i++)
3534 charstart[i] = 0;
3536 /* Handle continuation in middle of a character */
3537 /* by backing up over it */
3538 if (p1 > endp)
3540 /* Don't back up if we never actually displayed any text.
3541 This occurs when the minibuffer prompt takes up the whole line. */
3542 if (p1prev)
3544 /* Start the next line with that same character whose
3545 character code is C and the length of multi-byte form is
3546 LEN. */
3547 pos = prevpos;
3549 if (len == 1)
3550 /* C is not a multi-byte character. We can break it and
3551 start from the middle column in the next line. So,
3552 adjust VAL.HPOS to skip the columns output on this
3553 line. */
3554 val.hpos += p1prev - endp;
3555 else
3557 /* C is a multibyte character. Since we can't broke it
3558 in the middle, the whole character should be driven
3559 into the next line. */
3560 /* As the result, the actual columns occupied by the
3561 text on this line is less than WIDTH. VAL.TAB_OFFSET
3562 must be adjusted. */
3563 taboffset = taboffset + (p1prev - endp);
3564 /* Let's fill unused columns with TRUNCATOR or CONTINUER. */
3566 GLYPH g = fix_glyph (f, truncate ? truncator : continuer, 0);
3567 while (p1prev < endp)
3568 *p1prev++ = g;
3570 /* If POINT is at POS, cursor should not on this line. */
3571 lastpos = pos;
3572 if (PT == pos)
3573 cursor_vpos = -1;
3577 /* Keep in this line everything up to the continuation column. */
3578 p1 = endp;
3581 /* Finish deciding which character to start the next line on,
3582 and what hpos to start it at.
3583 Also set `lastpos' to the last position which counts as "on this line"
3584 for cursor-positioning. */
3586 if (pos < ZV)
3588 if (FETCH_BYTE (pos) == '\n')
3590 /* If stopped due to a newline, start next line after it */
3591 pos++;
3592 val.tab_offset = 0;
3593 /* Check again for hidden lines, in case the newline occurred exactly
3594 at the right margin. */
3595 while (pos < ZV && selective > 0
3596 && indented_beyond_p (pos, selective))
3597 pos = find_next_newline (pos, 1);
3599 else
3600 /* Stopped due to right margin of window */
3602 if (truncate)
3604 *p1++ = fix_glyph (f, truncator, 0);
3605 /* Truncating => start next line after next newline,
3606 and point is on this line if it is before the newline,
3607 and skip none of first char of next line */
3609 pos = find_next_newline (pos, 1);
3610 while (pos < ZV && selective > 0
3611 && indented_beyond_p (pos, selective));
3612 val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
3614 lastpos = pos - (FETCH_BYTE (pos - 1) == '\n');
3615 val.tab_offset = 0;
3617 else
3619 *p1++ = fix_glyph (f, continuer, 0);
3620 val.vpos = 0;
3621 lastpos--;
3622 val.tab_offset = taboffset + width;
3626 else
3627 val.tab_offset = 0;
3629 /* If point is at eol or in invisible text at eol,
3630 record its frame location now. */
3632 if (start <= PT && PT <= lastpos && cursor_vpos < 0)
3634 cursor_vpos = vpos;
3635 cursor_hpos = p1 - leftmargin;
3638 if (cursor_vpos == vpos)
3640 if (cursor_hpos < 0) cursor_hpos = 0;
3641 if (cursor_hpos > width) cursor_hpos = width;
3642 cursor_hpos += WINDOW_LEFT_MARGIN (w);
3643 if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)))
3645 if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f)
3646 && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window)))
3648 FRAME_CURSOR_Y (f) = cursor_vpos;
3649 FRAME_CURSOR_X (f) = cursor_hpos;
3652 if (w == XWINDOW (selected_window))
3654 /* Line is not continued and did not start
3655 in middle of character */
3656 if ((hpos - WINDOW_LEFT_MARGIN (w)
3657 == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
3658 && val.vpos)
3660 this_line_bufpos = start;
3661 this_line_buffer = current_buffer;
3662 this_line_vpos = cursor_vpos;
3663 this_line_start_hpos = hpos - WINDOW_LEFT_MARGIN (w);
3664 this_line_endpos = Z - lastpos;
3666 else
3667 this_line_bufpos = 0;
3672 /* If hscroll and line not empty, insert truncation-at-left marker */
3673 if (hscroll && lastpos != start)
3675 GLYPH g = fix_glyph (f, truncator, 0);
3676 *leftmargin = g;
3677 if (p1 <= leftmargin)
3678 p1 = leftmargin + 1;
3679 else /* MULE: it may be a wide-column character */
3681 p1prev = leftmargin + 1;
3682 while (p1prev < p1 && *p1prev & GLYPH_MASK_PADDING)
3683 *p1prev++ = g;
3687 if (!WINDOW_RIGHTMOST_P (w))
3689 endp++;
3690 if (p1 < leftmargin) p1 = leftmargin;
3691 while (p1 < endp) *p1++ = SPACEGLYPH;
3693 /* Don't draw vertical bars if we're using scroll bars. They're
3694 covered up by the scroll bars, and it's distracting to see
3695 them when the scroll bar windows are flickering around to be
3696 reconfigured. */
3697 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3699 int i;
3700 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
3701 *p1++ = SPACEGLYPH;
3703 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3704 *p1++ = (dp && INTEGERP (DISP_BORDER_GLYPH (dp))
3705 ? XINT (DISP_BORDER_GLYPH (dp))
3706 : '|');
3708 desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos],
3709 p1 - desired_glyphs->glyphs[vpos]);
3710 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
3712 /* If the start of this line is the overlay arrow-position,
3713 then put the arrow string into the display-line. */
3715 if (MARKERP (Voverlay_arrow_position)
3716 && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
3717 && start == marker_position (Voverlay_arrow_position)
3718 && STRINGP (Voverlay_arrow_string)
3719 && ! overlay_arrow_seen)
3721 unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
3722 int i;
3723 int len = XSTRING (Voverlay_arrow_string)->size;
3724 int arrow_end;
3726 if (len > width)
3727 len = width;
3728 #ifdef HAVE_FACES
3729 if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals))
3731 /* If the arrow string has text props, obey them when displaying. */
3732 for (i = 0; i < len; i++)
3734 int c = p[i];
3735 Lisp_Object face, ilisp;
3736 int newface;
3738 XSETFASTINT (ilisp, i);
3739 face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string);
3740 newface = compute_glyph_face_1 (f, face, 0);
3741 leftmargin[i] = FAST_MAKE_GLYPH (c, newface);
3744 else
3745 #endif /* HAVE_FACES */
3747 for (i = 0; i < len; i++)
3748 leftmargin[i] = p[i];
3751 /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */
3752 arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len;
3753 if (desired_glyphs->used[vpos] < arrow_end)
3754 desired_glyphs->used[vpos] = arrow_end;
3756 overlay_arrow_seen = 1;
3759 val.bufpos = pos;
3760 val.ovstring_chars_done = ovstr_done;
3761 val_display_text_line = val;
3762 return &val_display_text_line;
3765 /* Redisplay the menu bar in the frame for window W. */
3767 static void
3768 display_menu_bar (w)
3769 struct window *w;
3771 Lisp_Object items, tail;
3772 register int vpos = 0;
3773 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3774 int maxendcol = FRAME_WIDTH (f) + WINDOW_LEFT_MARGIN (w);
3775 int hpos = 0;
3776 int i;
3778 #ifdef HAVE_NTGUI
3779 if (!NILP (Vwindow_system))
3780 return;
3781 #endif
3783 #ifdef USE_X_TOOLKIT
3784 if (FRAME_X_P (f))
3785 return;
3786 #endif /* USE_X_TOOLKIT */
3788 get_display_line (f, vpos, 0);
3790 items = FRAME_MENU_BAR_ITEMS (f);
3791 for (i = 0; i < XVECTOR (items)->size; i += 4)
3793 Lisp_Object pos, string;
3794 string = XVECTOR (items)->contents[i + 1];
3795 if (NILP (string))
3796 break;
3798 XSETFASTINT (XVECTOR (items)->contents[i + 3], hpos);
3800 if (hpos < maxendcol)
3801 hpos = display_string (w, vpos,
3802 XSTRING (string)->data,
3803 XSTRING (string)->size,
3804 hpos, 0, 0, hpos, maxendcol, -1);
3805 /* Put a space between items. */
3806 if (hpos < maxendcol)
3808 int hpos1 = hpos + 1;
3809 hpos = display_string (w, vpos, "", 0, hpos, 0, 0,
3810 min (hpos1, maxendcol), maxendcol, 0);
3814 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3815 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3817 /* Fill out the line with spaces. */
3818 if (maxendcol > hpos)
3819 hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol, 0);
3821 /* Clear the rest of the lines allocated to the menu bar. */
3822 vpos++;
3823 while (vpos < FRAME_MENU_BAR_LINES (f))
3824 get_display_line (f, vpos++, 0);
3827 /* Display the mode line for window w */
3829 static void
3830 display_mode_line (w)
3831 struct window *w;
3833 register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
3834 register int left = WINDOW_LEFT_MARGIN (w);
3835 register int right = WINDOW_RIGHT_MARGIN (w);
3836 register FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
3838 line_number_displayed = 0;
3839 w->column_number_displayed = Qnil;
3841 get_display_line (f, vpos, left);
3843 /* Temporarily make frame F's kboard the current kboard
3844 so that kboard-local variables in the mode_line_format
3845 will get the right values. */
3846 push_frame_kboard (f);
3848 display_mode_element (w, vpos, left, 0, right, right,
3849 current_buffer->mode_line_format);
3851 pop_frame_kboard ();
3853 FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0;
3855 /* Put the mode line in inverse video.
3856 Use faces if possible, since that lets us handle
3857 partial-width windows and avoid inverting the scroll bar columns. */
3858 #ifdef HAVE_FACES
3859 if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video)
3861 /* For a partial width window, explicitly set face of each glyph. */
3862 int i;
3863 unsigned int padding;
3864 GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos];
3865 for (i = left; i < right; ++i)
3867 padding = ptr[i] & GLYPH_MASK_PADDING;
3868 ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1) | padding;
3871 else
3872 #endif
3874 /* Make the mode line inverse video if the entire line
3875 is made of mode lines.
3876 I.e. if this window is full width,
3877 or if it is the child of a full width window
3878 (which implies that that window is split side-by-side
3879 and the rest of this line is mode lines of the sibling windows). */
3880 if (WINDOW_FULL_WIDTH_P (w)
3881 || WINDOW_FULL_WIDTH_P (XWINDOW (w->parent)))
3882 FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video;
3885 /* Contribute ELT to the mode line for window W.
3886 How it translates into text depends on its data type.
3888 VPOS is the position of the mode line being displayed.
3890 HPOS is the position (absolute on frame) where this element's text
3891 should start. The output is truncated automatically at the right
3892 edge of window W.
3894 DEPTH is the depth in recursion. It is used to prevent
3895 infinite recursion here.
3897 MINENDCOL is the hpos before which the element may not end.
3898 The element is padded at the right with spaces if nec
3899 to reach this column.
3901 MAXENDCOL is the hpos past which this element may not extend.
3902 If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
3903 (This is necessary to make nested padding and truncation work.)
3905 Returns the hpos of the end of the text generated by ELT.
3906 The next element will receive that value as its HPOS arg,
3907 so as to concatenate the elements. */
3909 static int
3910 display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
3911 struct window *w;
3912 register int vpos, hpos;
3913 int depth;
3914 int minendcol;
3915 register int maxendcol;
3916 register Lisp_Object elt;
3918 tail_recurse:
3919 if (depth > 10)
3920 goto invalid;
3922 depth++;
3924 switch (SWITCH_ENUM_CAST (XTYPE (elt)))
3926 case Lisp_String:
3928 /* A string: output it and check for %-constructs within it. */
3929 register unsigned char c;
3930 register unsigned char *this = XSTRING (elt)->data;
3932 while (hpos < maxendcol && *this)
3934 unsigned char *last = this;
3935 while ((c = *this++) != '\0' && c != '%')
3937 if (this - 1 != last)
3939 register int lim = --this - last + hpos;
3940 if (frame_title_ptr)
3941 hpos = store_frame_title (last, hpos, min (lim, maxendcol));
3942 else
3943 hpos = display_string (w, vpos, last, -1, hpos, 0, 1,
3944 hpos, min (lim, maxendcol), -1);
3946 else /* c == '%' */
3948 register int minendcol;
3949 register int spec_width = 0;
3951 /* We can't allow -ve args due to the "%-" construct */
3952 /* Argument specifies minwidth but not maxwidth
3953 (maxwidth can be specified by
3954 (<negative-number> . <stuff>) mode-line elements) */
3956 while ((c = *this++) >= '0' && c <= '9')
3958 spec_width = spec_width * 10 + (c - '0');
3961 minendcol = hpos + spec_width;
3962 if (minendcol > maxendcol)
3964 spec_width = maxendcol - hpos;
3965 minendcol = maxendcol;
3968 if (c == 'M')
3969 hpos = display_mode_element (w, vpos, hpos, depth,
3970 spec_width, maxendcol,
3971 Vglobal_mode_string);
3972 else if (c != 0)
3974 char *spec = decode_mode_spec (w, c, spec_width,
3975 maxendcol - hpos);
3976 if (frame_title_ptr)
3977 hpos = store_frame_title (spec, minendcol, maxendcol);
3978 else
3979 hpos = display_string (w, vpos, spec, -1,
3980 hpos, 0, 1,
3981 minendcol, maxendcol, -1);
3986 break;
3988 case Lisp_Symbol:
3989 /* A symbol: process the value of the symbol recursively
3990 as if it appeared here directly. Avoid error if symbol void.
3991 Special case: if value of symbol is a string, output the string
3992 literally. */
3994 register Lisp_Object tem;
3995 tem = Fboundp (elt);
3996 if (!NILP (tem))
3998 tem = Fsymbol_value (elt);
3999 /* If value is a string, output that string literally:
4000 don't check for % within it. */
4001 if (STRINGP (tem))
4003 if (frame_title_ptr)
4004 hpos = store_frame_title (XSTRING (tem)->data,
4005 minendcol, maxendcol);
4006 else
4007 hpos = display_string (w, vpos, XSTRING (tem)->data,
4008 XSTRING (tem)->size,
4009 hpos, 0, 1, minendcol, maxendcol, -1);
4011 /* Give up right away for nil or t. */
4012 else if (!EQ (tem, elt))
4013 { elt = tem; goto tail_recurse; }
4016 break;
4018 case Lisp_Cons:
4020 register Lisp_Object car, tem;
4022 /* A cons cell: three distinct cases.
4023 If first element is a string or a cons, process all the elements
4024 and effectively concatenate them.
4025 If first element is a negative number, truncate displaying cdr to
4026 at most that many characters. If positive, pad (with spaces)
4027 to at least that many characters.
4028 If first element is a symbol, process the cadr or caddr recursively
4029 according to whether the symbol's value is non-nil or nil. */
4030 car = XCONS (elt)->car;
4031 if (SYMBOLP (car))
4033 tem = Fboundp (car);
4034 elt = XCONS (elt)->cdr;
4035 if (!CONSP (elt))
4036 goto invalid;
4037 /* elt is now the cdr, and we know it is a cons cell.
4038 Use its car if CAR has a non-nil value. */
4039 if (!NILP (tem))
4041 tem = Fsymbol_value (car);
4042 if (!NILP (tem))
4043 { elt = XCONS (elt)->car; goto tail_recurse; }
4045 /* Symbol's value is nil (or symbol is unbound)
4046 Get the cddr of the original list
4047 and if possible find the caddr and use that. */
4048 elt = XCONS (elt)->cdr;
4049 if (NILP (elt))
4050 break;
4051 else if (!CONSP (elt))
4052 goto invalid;
4053 elt = XCONS (elt)->car;
4054 goto tail_recurse;
4056 else if (INTEGERP (car))
4058 register int lim = XINT (car);
4059 elt = XCONS (elt)->cdr;
4060 if (lim < 0)
4061 /* Negative int means reduce maximum width.
4062 DO NOT change MINENDCOL here!
4063 (20 -10 . foo) should truncate foo to 10 col
4064 and then pad to 20. */
4065 maxendcol = min (maxendcol, hpos - lim);
4066 else if (lim > 0)
4068 /* Padding specified. Don't let it be more than
4069 current maximum. */
4070 lim += hpos;
4071 if (lim > maxendcol)
4072 lim = maxendcol;
4073 /* If that's more padding than already wanted, queue it.
4074 But don't reduce padding already specified even if
4075 that is beyond the current truncation point. */
4076 if (lim > minendcol)
4077 minendcol = lim;
4079 goto tail_recurse;
4081 else if (STRINGP (car) || CONSP (car))
4083 register int limit = 50;
4084 /* LIMIT is to protect against circular lists. */
4085 while (CONSP (elt) && --limit > 0
4086 && hpos < maxendcol)
4088 hpos = display_mode_element (w, vpos, hpos, depth,
4089 hpos, maxendcol,
4090 XCONS (elt)->car);
4091 elt = XCONS (elt)->cdr;
4095 break;
4097 default:
4098 invalid:
4099 if (frame_title_ptr)
4100 hpos = store_frame_title ("*invalid*", minendcol, maxendcol);
4101 else
4102 hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1,
4103 minendcol, maxendcol, 0);
4104 return hpos;
4107 if (minendcol > hpos)
4108 if (frame_title_ptr)
4109 hpos = store_frame_title ("", minendcol, maxendcol);
4110 else
4111 hpos = display_string (w, vpos, "", 0, hpos,
4112 0, 1, minendcol, maxendcol, 0);
4113 return hpos;
4116 /* Write a null-terminated, right justified decimal representation of
4117 the positive integer D to BUF using a minimal field width WIDTH. */
4119 static void
4120 pint2str (buf, width, d)
4121 register char *buf;
4122 register int width;
4123 register int d;
4125 register char *p = buf;
4127 if (d <= 0)
4128 *p++ = '0';
4129 else
4130 while (d > 0)
4132 *p++ = d % 10 + '0';
4133 d /= 10;
4135 for (width -= (int) (p - buf); width > 0; --width) *p++ = ' ';
4136 *p-- = '\0';
4137 while (p > buf)
4139 d = *buf;
4140 *buf++ = *p;
4141 *p-- = d;
4145 /* Set a mnemonic character for CODING_SYSTEM (Lisp symbol) in BUF.
4146 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
4147 type of CODING_SYSTEM. Return updated pointer into BUF. */
4149 static char *
4150 decode_mode_spec_coding (coding_system, buf, eol_flag)
4151 Lisp_Object coding_system;
4152 register char *buf;
4153 int eol_flag;
4155 Lisp_Object val;
4156 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
4158 val = coding_system;
4160 if (NILP (val)) /* Not yet decided. */
4162 if (multibyte)
4163 *buf++ = '-';
4164 if (eol_flag)
4165 *buf++ = eol_mnemonic_undecided;
4166 /* Don't mention EOL conversion if it isn't decided. */
4168 else
4170 Lisp_Object eolvalue;
4172 eolvalue = Fget (coding_system, Qeol_type);
4174 while (!NILP (val) && SYMBOLP (val))
4176 val = Fget (val, Qcoding_system);
4177 if (NILP (eolvalue))
4178 eolvalue = Fget (val, Qeol_type);
4181 if (multibyte)
4182 *buf++ = XFASTINT (XVECTOR (val)->contents[1]);
4184 if (eol_flag)
4186 /* The EOL conversion we are using. */
4187 int eoltype;
4188 /* The EOL conversion that is normal on this system. */
4190 if (NILP (eolvalue)) /* Not yet decided. */
4191 eoltype = eol_mnemonic_undecided;
4192 else if (VECTORP (eolvalue)) /* Not yet decided. */
4193 eoltype = eol_mnemonic_undecided;
4194 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
4195 eoltype = (XFASTINT (eolvalue) == 0
4196 ? eol_mnemonic_unix
4197 : (XFASTINT (eolvalue) == 1
4198 ? eol_mnemonic_dos : eol_mnemonic_mac));
4200 /* Mention the EOL conversion if it is not the usual one. */
4201 *buf++ = eoltype;
4204 return buf;
4207 /* Return a string for the output of a mode line %-spec for window W,
4208 generated by character C. SPEC_WIDTH is the field width when
4209 padding to the left (%c, %l). The value returned from this
4210 function will later be truncated to width MAXWIDTH. */
4212 static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
4214 static char *
4215 decode_mode_spec (w, c, spec_width, maxwidth)
4216 struct window *w;
4217 register char c;
4218 register int spec_width;
4219 register int maxwidth;
4221 Lisp_Object obj;
4222 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4223 char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents;
4224 struct buffer *b = XBUFFER (w->buffer);
4226 obj = Qnil;
4227 if (maxwidth > FRAME_WIDTH (f))
4228 maxwidth = FRAME_WIDTH (f);
4230 switch (c)
4232 case '*':
4233 if (!NILP (b->read_only))
4234 return "%";
4235 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4236 return "*";
4237 return "-";
4239 case '+':
4240 /* This differs from %* only for a modified read-only buffer. */
4241 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4242 return "*";
4243 if (!NILP (b->read_only))
4244 return "%";
4245 return "-";
4247 case '&':
4248 /* This differs from %* in ignoring read-only-ness. */
4249 if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
4250 return "*";
4251 return "-";
4253 case '%':
4254 return "%";
4256 case '[':
4258 int i;
4259 char *p;
4261 if (command_loop_level > 5)
4262 return "[[[... ";
4263 p = decode_mode_spec_buf;
4264 for (i = 0; i < command_loop_level; i++)
4265 *p++ = '[';
4266 *p = 0;
4267 return decode_mode_spec_buf;
4270 case ']':
4272 int i;
4273 char *p;
4275 if (command_loop_level > 5)
4276 return " ...]]]";
4277 p = decode_mode_spec_buf;
4278 for (i = 0; i < command_loop_level; i++)
4279 *p++ = ']';
4280 *p = 0;
4281 return decode_mode_spec_buf;
4284 case '-':
4286 register char *p;
4287 register int i;
4289 if (maxwidth < sizeof (lots_of_dashes))
4290 return lots_of_dashes;
4291 else
4293 for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--)
4294 *p++ = '-';
4295 *p = '\0';
4297 return decode_mode_spec_buf;
4300 case 'b':
4301 obj = b->name;
4302 #if 0
4303 if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
4305 bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
4306 decode_mode_spec_buf[maxwidth - 1] = '\\';
4307 decode_mode_spec_buf[maxwidth] = '\0';
4308 return decode_mode_spec_buf;
4310 #endif
4311 break;
4313 case 'c':
4315 int col = current_column ();
4316 XSETFASTINT (w->column_number_displayed, col);
4317 pint2str (decode_mode_spec_buf, spec_width, col);
4318 return decode_mode_spec_buf;
4321 case 'F':
4322 /* %F displays the frame name. */
4323 /* Systems that can only display a single frame at a time should
4324 NOT replace the frame name with the (constant) frame title,
4325 since then they won't be able to tell which frame is that. */
4326 if (FRAME_WINDOW_P (f) && !NILP (f->title))
4327 return (char *) XSTRING (f->title)->data;
4328 if (f->explicit_name || ! FRAME_WINDOW_P (f))
4329 return (char *) XSTRING (f->name)->data;
4330 return "Emacs";
4332 case 'f':
4333 obj = b->filename;
4334 #if 0
4335 if (NILP (obj))
4336 return "[none]";
4337 else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth)
4339 bcopy ("...", decode_mode_spec_buf, 3);
4340 bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
4341 decode_mode_spec_buf + 3, maxwidth - 3);
4342 return decode_mode_spec_buf;
4344 #endif
4345 break;
4347 case 'l':
4349 int startpos = marker_position (w->start);
4350 int line, linepos, topline;
4351 int nlines, junk;
4352 Lisp_Object tem;
4353 int height = XFASTINT (w->height);
4355 /* If we decided that this buffer isn't suitable for line numbers,
4356 don't forget that too fast. */
4357 if (EQ (w->base_line_pos, w->buffer))
4358 goto no_value;
4359 /* But do forget it, if the window shows a different buffer now. */
4360 else if (BUFFERP (w->base_line_pos))
4361 w->base_line_pos = Qnil;
4363 /* If the buffer is very big, don't waste time. */
4364 if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit)
4366 w->base_line_pos = Qnil;
4367 w->base_line_number = Qnil;
4368 goto no_value;
4371 if (!NILP (w->base_line_number)
4372 && !NILP (w->base_line_pos)
4373 && XFASTINT (w->base_line_pos) <= marker_position (w->start))
4375 line = XFASTINT (w->base_line_number);
4376 linepos = XFASTINT (w->base_line_pos);
4378 else
4380 line = 1;
4381 linepos = BUF_BEGV (b);
4384 /* Count lines from base line to window start position. */
4385 nlines = display_count_lines (linepos, startpos, startpos, &junk);
4387 topline = nlines + line;
4389 /* Determine a new base line, if the old one is too close
4390 or too far away, or if we did not have one.
4391 "Too close" means it's plausible a scroll-down would
4392 go back past it. */
4393 if (startpos == BUF_BEGV (b))
4395 XSETFASTINT (w->base_line_number, topline);
4396 XSETFASTINT (w->base_line_pos, BUF_BEGV (b));
4398 else if (nlines < height + 25 || nlines > height * 3 + 50
4399 || linepos == BUF_BEGV (b))
4401 int limit = BUF_BEGV (b);
4402 int position;
4403 int distance = (height * 2 + 30) * 200;
4405 if (startpos - distance > limit)
4406 limit = startpos - distance;
4408 nlines = display_count_lines (startpos, limit,
4409 -(height * 2 + 30),
4410 &position);
4411 /* If we couldn't find the lines we wanted within
4412 200 chars per line,
4413 give up on line numbers for this window. */
4414 if (position == startpos - distance)
4416 w->base_line_pos = w->buffer;
4417 w->base_line_number = Qnil;
4418 goto no_value;
4421 XSETFASTINT (w->base_line_number, topline - nlines);
4422 XSETFASTINT (w->base_line_pos, position);
4425 /* Now count lines from the start pos to point. */
4426 nlines = display_count_lines (startpos, PT, PT, &junk);
4428 /* Record that we did display the line number. */
4429 line_number_displayed = 1;
4431 /* Make the string to show. */
4432 pint2str (decode_mode_spec_buf, spec_width, topline + nlines);
4433 return decode_mode_spec_buf;
4434 no_value:
4436 char* p = decode_mode_spec_buf;
4437 for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' ';
4438 strcpy (p, "??");
4439 return decode_mode_spec_buf;
4442 break;
4444 case 'm':
4445 obj = b->mode_name;
4446 break;
4448 case 'n':
4449 if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b))
4450 return " Narrow";
4451 break;
4453 case 'p':
4455 int pos = marker_position (w->start);
4456 int total = BUF_ZV (b) - BUF_BEGV (b);
4458 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
4460 if (pos <= BUF_BEGV (b))
4461 return "All";
4462 else
4463 return "Bottom";
4465 else if (pos <= BUF_BEGV (b))
4466 return "Top";
4467 else
4469 if (total > 1000000)
4470 /* Do it differently for a large value, to avoid overflow. */
4471 total = ((pos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
4472 else
4473 total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
4474 /* We can't normally display a 3-digit number,
4475 so get us a 2-digit number that is close. */
4476 if (total == 100)
4477 total = 99;
4478 sprintf (decode_mode_spec_buf, "%2d%%", total);
4479 return decode_mode_spec_buf;
4483 /* Display percentage of size above the bottom of the screen. */
4484 case 'P':
4486 int toppos = marker_position (w->start);
4487 int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
4488 int total = BUF_ZV (b) - BUF_BEGV (b);
4490 if (botpos >= BUF_ZV (b))
4492 if (toppos <= BUF_BEGV (b))
4493 return "All";
4494 else
4495 return "Bottom";
4497 else
4499 if (total > 1000000)
4500 /* Do it differently for a large value, to avoid overflow. */
4501 total = ((botpos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
4502 else
4503 total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
4504 /* We can't normally display a 3-digit number,
4505 so get us a 2-digit number that is close. */
4506 if (total == 100)
4507 total = 99;
4508 if (toppos <= BUF_BEGV (b))
4509 sprintf (decode_mode_spec_buf, "Top%2d%%", total);
4510 else
4511 sprintf (decode_mode_spec_buf, "%2d%%", total);
4512 return decode_mode_spec_buf;
4516 case 's':
4517 /* status of process */
4518 obj = Fget_buffer_process (w->buffer);
4519 if (NILP (obj))
4520 return "no process";
4521 #ifdef subprocesses
4522 obj = Fsymbol_name (Fprocess_status (obj));
4523 #endif
4524 break;
4526 case 't': /* indicate TEXT or BINARY */
4527 #ifdef MODE_LINE_BINARY_TEXT
4528 return MODE_LINE_BINARY_TEXT (b);
4529 #else
4530 return "T";
4531 #endif
4533 case 'z':
4534 /* coding-system (not including end-of-line format) */
4535 case 'Z':
4536 /* coding-system (including end-of-line type) */
4538 int eol_flag = (c == 'Z');
4539 char *p = decode_mode_spec_buf;
4541 if (! FRAME_WINDOW_P (f))
4543 /* No need to mention EOL here--the terminal never needs
4544 to do EOL conversion. */
4545 p = decode_mode_spec_coding (keyboard_coding.symbol, p, 0);
4546 p = decode_mode_spec_coding (terminal_coding.symbol, p, 0);
4548 p = decode_mode_spec_coding (b->buffer_file_coding_system,
4549 p, eol_flag);
4551 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
4552 #ifdef subprocesses
4553 obj = Fget_buffer_process (Fcurrent_buffer ());
4554 if (PROCESSP (obj))
4556 p = decode_mode_spec_coding (XPROCESS (obj)->decode_coding_system,
4557 p, eol_flag);
4558 p = decode_mode_spec_coding (XPROCESS (obj)->encode_coding_system,
4559 p, eol_flag);
4561 #endif /* subprocesses */
4562 #endif /* 0 */
4563 *p = 0;
4564 return decode_mode_spec_buf;
4568 if (STRINGP (obj))
4569 return (char *) XSTRING (obj)->data;
4570 else
4571 return "";
4574 /* Search for COUNT instances of a line boundary, which means either a
4575 newline or (if selective display enabled) a carriage return.
4576 Start at START. If COUNT is negative, search backwards.
4578 If we find COUNT instances, set *SHORTAGE to zero, and return the
4579 position after the COUNTth match. Note that for reverse motion
4580 this is not the same as the usual convention for Emacs motion commands.
4582 If we don't find COUNT instances before reaching the end of the
4583 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
4584 the number of line boundaries left unfound, and return the end of the
4585 buffer we bumped up against. */
4587 static int
4588 display_scan_buffer (start, count, shortage)
4589 int *shortage, start;
4590 register int count;
4592 int limit = ((count > 0) ? ZV - 1 : BEGV);
4593 int direction = ((count > 0) ? 1 : -1);
4595 register unsigned char *cursor;
4596 unsigned char *base;
4598 register int ceiling;
4599 register unsigned char *ceiling_addr;
4601 /* If we are not in selective display mode,
4602 check only for newlines. */
4603 if (! (!NILP (current_buffer->selective_display)
4604 && !INTEGERP (current_buffer->selective_display)))
4605 return scan_buffer ('\n', start, 0, count, shortage, 0);
4607 /* The code that follows is like scan_buffer
4608 but checks for either newline or carriage return. */
4610 if (shortage != 0)
4611 *shortage = 0;
4613 if (count > 0)
4614 while (start != limit + 1)
4616 ceiling = BUFFER_CEILING_OF (start);
4617 ceiling = min (limit, ceiling);
4618 ceiling_addr = POS_ADDR (ceiling) + 1;
4619 base = (cursor = POS_ADDR (start));
4620 while (1)
4622 while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr)
4624 if (cursor != ceiling_addr)
4626 if (--count == 0)
4628 immediate_quit = 0;
4629 return (start + cursor - base + 1);
4631 else
4632 if (++cursor == ceiling_addr)
4633 break;
4635 else
4636 break;
4638 start += cursor - base;
4640 else
4642 start--; /* first character we scan */
4643 while (start > limit - 1)
4644 { /* we WILL scan under start */
4645 ceiling = BUFFER_FLOOR_OF (start);
4646 ceiling = max (limit, ceiling);
4647 ceiling_addr = POS_ADDR (ceiling) - 1;
4648 base = (cursor = POS_ADDR (start));
4649 cursor++;
4650 while (1)
4652 while (--cursor != ceiling_addr
4653 && *cursor != '\n' && *cursor != 015)
4655 if (cursor != ceiling_addr)
4657 if (++count == 0)
4659 immediate_quit = 0;
4660 return (start + cursor - base + 1);
4663 else
4664 break;
4666 start += cursor - base;
4670 if (shortage != 0)
4671 *shortage = count * direction;
4672 return (start + ((direction == 1 ? 0 : 1)));
4675 /* Count up to N lines starting from FROM.
4676 But don't go beyond LIMIT.
4677 Return the number of lines thus found (always positive).
4678 Store the position after what was found into *POS_PTR. */
4680 static int
4681 display_count_lines (from, limit, n, pos_ptr)
4682 int from, limit, n;
4683 int *pos_ptr;
4685 int oldbegv = BEGV;
4686 int oldzv = ZV;
4687 int shortage = 0;
4689 if (limit < from)
4690 BEGV = limit;
4691 else
4692 ZV = limit;
4694 *pos_ptr = display_scan_buffer (from, n, &shortage);
4696 ZV = oldzv;
4697 BEGV = oldbegv;
4699 if (n < 0)
4700 /* When scanning backwards, scan_buffer stops *after* the last newline
4701 it finds, but does count it. Compensate for that. */
4702 return - n - shortage - (*pos_ptr != limit);
4703 return n - shortage;
4706 /* Display STRING on one line of window W, starting at HPOS.
4707 Display at position VPOS. Caller should have done get_display_line.
4708 If VPOS == -1, display it as the current frame's title.
4709 LENGTH is the length of STRING, or -1 meaning STRING is null-terminated.
4711 TRUNCATE is GLYPH to display at end if truncated. Zero for none.
4713 MINCOL is the first column ok to end at. (Pad with spaces to this col.)
4714 MAXCOL is the last column ok to end at. Truncate here.
4715 -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
4716 Both count from the left edge of the frame, as does HPOS.
4717 The right edge of W is an implicit maximum.
4718 If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
4720 OBEY_WINDOW_WIDTH says to put spaces or vertical bars
4721 at the place where the current window ends in this line
4722 and not display anything beyond there. Otherwise, only MAXCOL
4723 controls where to stop output.
4725 MULTIBYTE can be 0 meaning do not display multibyte chars,
4726 1 meaning do display them, or -1 meaning obey the current buffer's
4727 value of enable_multibyte_characters.
4729 Returns ending hpos. */
4731 static int
4732 display_string (w, vpos, string, length, hpos, truncate,
4733 obey_window_width, mincol, maxcol, multibyte)
4734 struct window *w;
4735 unsigned char *string;
4736 int length;
4737 int vpos, hpos;
4738 GLYPH truncate;
4739 int obey_window_width;
4740 int mincol, maxcol;
4741 int multibyte;
4743 register int c;
4744 int truncated;
4745 register GLYPH *p1;
4746 int hscroll = XINT (w->hscroll);
4747 int tab_width = XINT (XBUFFER (w->buffer)->tab_width);
4748 register GLYPH *start;
4749 register GLYPH *end;
4750 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
4751 struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f);
4752 GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos;
4753 int window_width = XFASTINT (w->width);
4755 /* Use the standard display table, not the window's display table.
4756 We don't want the mode line in rot13. */
4757 register struct Lisp_Char_Table *dp = 0;
4758 int i;
4760 if (multibyte == -1)
4761 multibyte = !NILP (current_buffer->enable_multibyte_characters);
4762 /* Now multibyte is 1 if we should display multibyte characters. */
4764 if (DISP_TABLE_P (Vstandard_display_table))
4765 dp = XCHAR_TABLE (Vstandard_display_table);
4767 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
4769 p1 = p1start;
4770 start = desired_glyphs->glyphs[vpos];
4772 if (obey_window_width)
4774 start += XFASTINT (w->left);
4775 end = start + window_width - (truncate != 0);
4777 if (!WINDOW_RIGHTMOST_P (w))
4779 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
4781 int i;
4783 for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++)
4784 *end-- = ' ';
4786 else if (!FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4787 *end-- = '|';
4791 if (! obey_window_width
4792 || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol))
4793 end = desired_glyphs->glyphs[vpos] + maxcol;
4795 /* Store 0 in charstart for these columns. */
4796 for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++)
4797 desired_glyphs->charstarts[vpos][i] = 0;
4799 if (maxcol >= 0 && mincol > maxcol)
4800 mincol = maxcol;
4802 if (length < 0)
4803 /* We need this value for multibyte characters. */
4804 length = strlen (string);
4806 /* We set truncated to 1 if we get stopped by trying to pass END
4807 (that is, trying to pass MAXCOL.) */
4808 truncated = 0;
4809 while (1)
4811 int len;
4813 if (length <= 0)
4814 break;
4815 if (multibyte)
4816 c = STRING_CHAR_AND_LENGTH (string, length, len);
4817 else
4818 c = *string, len = 1;
4820 string += len, length -= len;
4822 if (p1 >= end)
4824 truncated = 1;
4825 break;
4828 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
4830 p1 = copy_part_of_rope (f, p1, start,
4831 XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents,
4832 XVECTOR (DISP_CHAR_VECTOR (dp, c))->size,
4835 else if (c >= 040 && c < 0177)
4837 if (p1 >= start)
4838 *p1 = c;
4839 p1++;
4841 else if (c == '\t')
4845 if (p1 >= start && p1 < end)
4846 *p1 = SPACEGLYPH;
4847 p1++;
4849 while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
4851 else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow))
4853 if (p1 >= start)
4854 *p1 = (fix_glyph
4855 (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp))
4856 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (dp)))
4857 ? XINT (DISP_CTRL_GLYPH (dp)) : '^'),
4858 0));
4859 p1++;
4860 if (p1 >= start && p1 < end)
4861 *p1 = c ^ 0100;
4862 p1++;
4864 else if (len == 1)
4866 /* C is a control character or a binary byte data. */
4867 if (p1 >= start)
4868 *p1 = (fix_glyph
4869 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
4870 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
4871 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
4872 0));
4873 p1++;
4874 if (p1 >= start && p1 < end)
4875 *p1 = (c >> 6) + '0';
4876 p1++;
4877 if (p1 >= start && p1 < end)
4878 *p1 = (7 & (c >> 3)) + '0';
4879 p1++;
4880 if (p1 >= start && p1 < end)
4881 *p1 = (7 & c) + '0';
4882 p1++;
4884 else
4886 /* C is a multibyte character. */
4887 int charset = CHAR_CHARSET (c);
4888 int columns = (charset == CHARSET_COMPOSITION
4889 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
4890 : CHARSET_WIDTH (charset));
4892 if (p1 < start)
4894 /* Since we can't show the left part of C, fill all
4895 columns with spaces. */
4896 columns -= start - p1;
4897 p1 = start;
4898 while (columns--)
4900 if (p1 < end)
4901 *p1 = SPACEGLYPH;
4902 p1++;
4905 else if (p1 + columns > end)
4907 /* Since we can't show the right part of C, fill all
4908 columns with TRUNCATE if TRUNCATE is specified. */
4909 if (truncate)
4911 while (p1 < end)
4912 *p1++ = fix_glyph (f, truncate, 0);
4913 /* And tell the line is truncated. */
4914 truncated = 1;
4916 break;
4918 else
4920 /* We can show the whole glyph of C. */
4921 *p1++ = c;
4922 while (--columns)
4923 *p1++ = c | GLYPH_MASK_PADDING;
4928 if (truncated)
4930 p1 = end;
4931 if (truncate) *p1++ = fix_glyph (f, truncate, 0);
4933 else if (mincol >= 0)
4935 end = desired_glyphs->glyphs[vpos] + mincol;
4936 while (p1 < end)
4937 *p1++ = SPACEGLYPH;
4941 register int len = p1 - desired_glyphs->glyphs[vpos];
4943 if (len > desired_glyphs->used[vpos])
4944 desired_glyphs->used[vpos] = len;
4945 desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0;
4947 return len;
4951 /* This is like a combination of memq and assq.
4952 Return 1 if PROPVAL appears as an element of LIST
4953 or as the car of an element of LIST.
4954 If PROPVAL is a list, compare each element against LIST
4955 in that way, and return 1 if any element of PROPVAL is found in LIST.
4956 Otherwise return 0.
4957 This function cannot quit. */
4960 invisible_p (propval, list)
4961 register Lisp_Object propval;
4962 Lisp_Object list;
4964 register Lisp_Object tail, proptail;
4965 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4967 register Lisp_Object tem;
4968 tem = XCONS (tail)->car;
4969 if (EQ (propval, tem))
4970 return 1;
4971 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
4972 return 1;
4974 if (CONSP (propval))
4975 for (proptail = propval; CONSP (proptail);
4976 proptail = XCONS (proptail)->cdr)
4978 Lisp_Object propelt;
4979 propelt = XCONS (proptail)->car;
4980 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
4982 register Lisp_Object tem;
4983 tem = XCONS (tail)->car;
4984 if (EQ (propelt, tem))
4985 return 1;
4986 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
4987 return 1;
4990 return 0;
4993 /* Return 1 if PROPVAL appears as the car of an element of LIST
4994 and the cdr of that element is non-nil.
4995 If PROPVAL is a list, check each element of PROPVAL in that way,
4996 and the first time some element is found,
4997 return 1 if the cdr of that element is non-nil.
4998 Otherwise return 0.
4999 This function cannot quit. */
5002 invisible_ellipsis_p (propval, list)
5003 register Lisp_Object propval;
5004 Lisp_Object list;
5006 register Lisp_Object tail, proptail;
5007 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
5009 register Lisp_Object tem;
5010 tem = XCONS (tail)->car;
5011 if (CONSP (tem) && EQ (propval, XCONS (tem)->car))
5012 return ! NILP (XCONS (tem)->cdr);
5014 if (CONSP (propval))
5015 for (proptail = propval; CONSP (proptail);
5016 proptail = XCONS (proptail)->cdr)
5018 Lisp_Object propelt;
5019 propelt = XCONS (proptail)->car;
5020 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
5022 register Lisp_Object tem;
5023 tem = XCONS (tail)->car;
5024 if (CONSP (tem) && EQ (propelt, XCONS (tem)->car))
5025 return ! NILP (XCONS (tem)->cdr);
5028 return 0;
5031 void
5032 syms_of_xdisp ()
5034 staticpro (&Qmenu_bar_update_hook);
5035 Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
5037 staticpro (&Qoverriding_terminal_local_map);
5038 Qoverriding_terminal_local_map = intern ("overriding-terminal-local-map");
5040 staticpro (&Qoverriding_local_map);
5041 Qoverriding_local_map = intern ("overriding-local-map");
5043 staticpro (&Qwindow_scroll_functions);
5044 Qwindow_scroll_functions = intern ("window-scroll-functions");
5046 staticpro (&Qredisplay_end_trigger_functions);
5047 Qredisplay_end_trigger_functions = intern ("redisplay-end-trigger-functions");
5049 staticpro (&last_arrow_position);
5050 staticpro (&last_arrow_string);
5051 last_arrow_position = Qnil;
5052 last_arrow_string = Qnil;
5054 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
5055 "String (or mode line construct) included (normally) in `mode-line-format'.");
5056 Vglobal_mode_string = Qnil;
5058 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
5059 "Marker for where to display an arrow on top of the buffer text.\n\
5060 This must be the beginning of a line in order to work.\n\
5061 See also `overlay-arrow-string'.");
5062 Voverlay_arrow_position = Qnil;
5064 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
5065 "String to display as an arrow. See also `overlay-arrow-position'.");
5066 Voverlay_arrow_string = Qnil;
5068 DEFVAR_INT ("scroll-step", &scroll_step,
5069 "*The number of lines to try scrolling a window by when point moves out.\n\
5070 If that fails to bring point back on frame, point is centered instead.\n\
5071 If this is zero, point is always centered after it moves off frame.");
5073 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively,
5074 "*Scroll up to this many lines, to bring point back on screen.");
5075 scroll_conservatively = 0;
5077 DEFVAR_INT ("scroll-margin", &scroll_margin,
5078 "*Number of lines of margin at the top and bottom of a window.\n\
5079 Recenter the window whenever point gets within this many lines\n\
5080 of the top or bottom of the window.");
5081 scroll_margin = 0;
5083 DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
5085 DEFVAR_BOOL ("truncate-partial-width-windows",
5086 &truncate_partial_width_windows,
5087 "*Non-nil means truncate lines in all windows less than full frame wide.");
5088 truncate_partial_width_windows = 1;
5090 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
5091 "*Non-nil means use inverse video for the mode line.");
5092 mode_line_inverse_video = 1;
5094 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit,
5095 "*Maximum buffer size for which line number should be displayed.");
5096 line_number_display_limit = 1000000;
5098 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows,
5099 "*Non-nil means highlight region even in nonselected windows.");
5100 highlight_nonselected_windows = 0;
5102 DEFVAR_BOOL ("multiple-frames", &multiple_frames,
5103 "Non-nil if more than one frame is visible on this display.\n\
5104 Minibuffer-only frames don't count, but iconified frames do.\n\
5105 This variable is not guaranteed to be accurate except while processing\n\
5106 `frame-title-format' and `icon-title-format'.");
5108 DEFVAR_LISP ("frame-title-format", &Vframe_title_format,
5109 "Template for displaying the titlebar of visible frames.\n\
5110 \(Assuming the window manager supports this feature.)\n\
5111 This variable has the same structure as `mode-line-format' (which see),\n\
5112 and is used only on frames for which no explicit name has been set\n\
5113 \(see `modify-frame-parameters').");
5114 DEFVAR_LISP ("icon-title-format", &Vicon_title_format,
5115 "Template for displaying the titlebar of an iconified frame.\n\
5116 \(Assuming the window manager supports this feature.)\n\
5117 This variable has the same structure as `mode-line-format' (which see),\n\
5118 and is used only on frames for which no explicit name has been set\n\
5119 \(see `modify-frame-parameters').");
5120 Vicon_title_format
5121 = Vframe_title_format
5122 = Fcons (intern ("multiple-frames"),
5123 Fcons (build_string ("%b"),
5124 Fcons (Fcons (build_string (""),
5125 Fcons (intern ("invocation-name"),
5126 Fcons (build_string ("@"),
5127 Fcons (intern ("system-name"),
5128 Qnil)))),
5129 Qnil)));
5131 DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
5132 "Maximum number of lines to keep in the message log buffer.\n\
5133 If nil, disable message logging. If t, log messages but don't truncate\n\
5134 the buffer when it becomes large.");
5135 XSETFASTINT (Vmessage_log_max, 50);
5137 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions,
5138 "Functions called before redisplay, if window sizes have changed.\n\
5139 The value should be a list of functions that take one argument.\n\
5140 Just before redisplay, for each frame, if any of its windows have changed\n\
5141 size since the last redisplay, or have been split or deleted,\n\
5142 all the functions in the list are called, with the frame as argument.");
5143 Vwindow_size_change_functions = Qnil;
5145 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions,
5146 "List of Functions to call before redisplaying a window with scrolling.\n\
5147 Each function is called with two arguments, the window\n\
5148 and its new display-start position. Note that the value of `window-end'\n\
5149 is not valid when these functions are called.");
5150 Vwindow_scroll_functions = Qnil;
5153 /* initialize the window system */
5154 init_xdisp ()
5156 Lisp_Object root_window;
5157 #ifndef COMPILER_REGISTER_BUG
5158 register
5159 #endif /* COMPILER_REGISTER_BUG */
5160 struct window *mini_w;
5162 this_line_bufpos = 0;
5164 mini_w = XWINDOW (minibuf_window);
5165 root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w)));
5167 echo_area_glyphs = 0;
5168 previous_echo_glyphs = 0;
5170 if (!noninteractive)
5172 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window)));
5173 XSETFASTINT (XWINDOW (root_window)->top, FRAME_MENU_BAR_LINES (f));
5174 set_window_height (root_window,
5175 FRAME_HEIGHT (f) - 1 - FRAME_MENU_BAR_LINES (f),
5177 XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1);
5178 set_window_height (minibuf_window, 1, 0);
5180 XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f));
5181 XSETFASTINT (mini_w->width, FRAME_WIDTH (f));