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