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