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