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