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 | |
817 | preserve the echo area. Perhaps in the future avoid recentering windows | |
818 | if it is not necessary; currently that causes some problems. */ | |
819 | ||
820 | static void | |
821 | redisplay_internal (preserve_echo_area) | |
822 | int preserve_echo_area; | |
a2889657 JB |
823 | { |
824 | register struct window *w = XWINDOW (selected_window); | |
825 | register int pause; | |
826 | int must_finish = 0; | |
827 | int all_windows; | |
828 | register int tlbufpos, tlendpos; | |
829 | struct position pos; | |
a2889657 JB |
830 | |
831 | if (noninteractive) | |
832 | return; | |
833 | ||
15f0cf78 RS |
834 | #ifdef USE_X_TOOLKIT |
835 | if (popup_activated ()) | |
836 | return; | |
837 | #endif | |
838 | ||
20de20dc RS |
839 | #ifdef MULTI_FRAME |
840 | if (FRAME_TERMCAP_P (selected_frame) | |
841 | && previous_terminal_frame != selected_frame) | |
842 | { | |
843 | /* Since frames on an ASCII terminal share the same display area, | |
844 | displaying a different frame means redisplay the whole thing. */ | |
845 | windows_or_buffers_changed++; | |
846 | SET_FRAME_GARBAGED (selected_frame); | |
847 | XSETFRAME (Vterminal_frame, selected_frame); | |
848 | } | |
849 | previous_terminal_frame = selected_frame; | |
850 | #endif | |
851 | ||
d724d989 JB |
852 | /* Set the visible flags for all frames. |
853 | Do this before checking for resized or garbaged frames; they want | |
854 | to know if their frames are visible. | |
855 | See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */ | |
856 | { | |
35f56f96 | 857 | Lisp_Object tail, frame; |
d724d989 | 858 | |
35f56f96 | 859 | FOR_EACH_FRAME (tail, frame) |
f82aff7c RS |
860 | { |
861 | FRAME_SAMPLE_VISIBILITY (XFRAME (frame)); | |
862 | ||
863 | /* Clear out all the display lines in which we will generate the | |
864 | glyphs to display. */ | |
865 | init_desired_glyphs (XFRAME (frame)); | |
866 | } | |
d724d989 JB |
867 | } |
868 | ||
44fa5b1e | 869 | /* Notice any pending interrupt request to change frame size. */ |
a2889657 JB |
870 | do_pending_window_change (); |
871 | ||
44fa5b1e | 872 | if (frame_garbaged) |
a2889657 | 873 | { |
02a9b6e4 | 874 | redraw_garbaged_frames (); |
44fa5b1e | 875 | frame_garbaged = 0; |
a2889657 JB |
876 | } |
877 | ||
f82aff7c RS |
878 | prepare_menu_bars (); |
879 | ||
28995e67 | 880 | if (windows_or_buffers_changed) |
a2889657 JB |
881 | update_mode_lines++; |
882 | ||
883 | /* Detect case that we need to write a star in the mode line. */ | |
884 | if (XFASTINT (w->last_modified) < MODIFF | |
42640f83 | 885 | && XFASTINT (w->last_modified) <= SAVE_MODIFF) |
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); |
9769686d RS |
1075 | if (! FRAME_TERMCAP_P (f) || f == selected_frame) |
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 RS |
1123 | |
1124 | if ((! FRAME_TERMCAP_P (f) || f == selected_frame) | |
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 | |
20de20dc RS |
1157 | if (mini_frame != selected_frame |
1158 | && ! FRAME_TERMCAP_P (mini_frame)) | |
44fa5b1e | 1159 | pause |= update_frame (mini_frame, 0, 0); |
8de2d90b | 1160 | } |
6e8290aa | 1161 | } |
a2889657 | 1162 | |
44fa5b1e | 1163 | /* If frame does not match, prevent doing single-line-update next time. |
a2889657 JB |
1164 | Also, don't forget to check every line to update the arrow. */ |
1165 | if (pause) | |
1166 | { | |
1167 | this_line_bufpos = 0; | |
265a9e55 | 1168 | if (!NILP (last_arrow_position)) |
a2889657 JB |
1169 | { |
1170 | last_arrow_position = Qt; | |
1171 | last_arrow_string = Qt; | |
1172 | } | |
44fa5b1e | 1173 | /* If we pause after scrolling, some lines in current_frame |
a2889657 JB |
1174 | may be null, so preserve_other_columns won't be able to |
1175 | preserve all the vertical-bar separators. So, avoid using it | |
1176 | in that case. */ | |
44fa5b1e | 1177 | if (XFASTINT (w->width) != FRAME_WIDTH (selected_frame)) |
a2889657 JB |
1178 | update_mode_lines = 1; |
1179 | } | |
1180 | ||
44fa5b1e | 1181 | /* Now text on frame agrees with windows, so |
a2889657 JB |
1182 | put info into the windows for partial redisplay to follow */ |
1183 | ||
1184 | if (!pause) | |
1185 | { | |
1186 | register struct buffer *b = XBUFFER (w->buffer); | |
1187 | ||
1188 | blank_end_of_window = 0; | |
a2889657 JB |
1189 | unchanged_modified = BUF_MODIFF (b); |
1190 | beg_unchanged = BUF_GPT (b) - BUF_BEG (b); | |
1191 | end_unchanged = BUF_Z (b) - BUF_GPT (b); | |
1192 | ||
c2213350 KH |
1193 | XSETFASTINT (w->last_point, BUF_PT (b)); |
1194 | XSETFASTINT (w->last_point_x, FRAME_CURSOR_X (selected_frame)); | |
1195 | XSETFASTINT (w->last_point_y, FRAME_CURSOR_Y (selected_frame)); | |
a2889657 JB |
1196 | |
1197 | if (all_windows) | |
11e82b76 | 1198 | mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame), 1); |
a2889657 JB |
1199 | else |
1200 | { | |
28995e67 | 1201 | b->clip_changed = 0; |
a2889657 | 1202 | w->update_mode_line = Qnil; |
c2213350 | 1203 | XSETFASTINT (w->last_modified, BUF_MODIFF (b)); |
d2f84654 | 1204 | w->window_end_valid = w->buffer; |
a2889657 JB |
1205 | last_arrow_position = Voverlay_arrow_position; |
1206 | last_arrow_string = Voverlay_arrow_string; | |
0d231165 RS |
1207 | if (do_verify_charstarts) |
1208 | verify_charstarts (w); | |
efc63ef0 RS |
1209 | if (frame_up_to_date_hook != 0) |
1210 | (*frame_up_to_date_hook) (selected_frame); | |
a2889657 JB |
1211 | } |
1212 | update_mode_lines = 0; | |
1213 | windows_or_buffers_changed = 0; | |
1214 | } | |
1215 | ||
1216 | /* Start SIGIO interrupts coming again. | |
1217 | Having them off during the code above | |
1218 | makes it less likely one will discard output, | |
1219 | but not impossible, since there might be stuff | |
1220 | in the system buffer here. | |
1221 | But it is much hairier to try to do anything about that. */ | |
1222 | ||
1223 | if (interrupt_input) | |
1224 | request_sigio (); | |
1225 | start_polling (); | |
1226 | ||
44fa5b1e | 1227 | /* Change frame size now if a change is pending. */ |
a2889657 | 1228 | do_pending_window_change (); |
d8e242fd RS |
1229 | |
1230 | /* If we just did a pending size change, redisplay again | |
1231 | for the new size. */ | |
3c8c72e0 | 1232 | if (windows_or_buffers_changed && !pause) |
d8e242fd | 1233 | redisplay (); |
a2889657 JB |
1234 | } |
1235 | ||
1236 | /* Redisplay, but leave alone any recent echo area message | |
1237 | unless another message has been requested in its place. | |
1238 | ||
1239 | This is useful in situations where you need to redisplay but no | |
1240 | user action has occurred, making it inappropriate for the message | |
1241 | area to be cleared. See tracking_off and | |
1242 | wait_reading_process_input for examples of these situations. */ | |
1243 | ||
1244 | redisplay_preserve_echo_area () | |
1245 | { | |
1246 | if (echo_area_glyphs == 0 && previous_echo_glyphs != 0) | |
1247 | { | |
1248 | echo_area_glyphs = previous_echo_glyphs; | |
e9874cee | 1249 | redisplay_internal (1); |
a2889657 JB |
1250 | echo_area_glyphs = 0; |
1251 | } | |
1252 | else | |
e9874cee | 1253 | redisplay_internal (1); |
a2889657 JB |
1254 | } |
1255 | ||
1256 | void | |
1257 | mark_window_display_accurate (window, flag) | |
1258 | Lisp_Object window; | |
1259 | int flag; | |
1260 | { | |
1261 | register struct window *w; | |
1262 | ||
265a9e55 | 1263 | for (;!NILP (window); window = w->next) |
a2889657 | 1264 | { |
e24c997d | 1265 | if (!WINDOWP (window)) abort (); |
a2889657 JB |
1266 | w = XWINDOW (window); |
1267 | ||
265a9e55 | 1268 | if (!NILP (w->buffer)) |
bd66d1ba | 1269 | { |
c2213350 KH |
1270 | XSETFASTINT (w->last_modified, |
1271 | !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer))); | |
bd66d1ba RS |
1272 | |
1273 | /* Record if we are showing a region, so can make sure to | |
1274 | update it fully at next redisplay. */ | |
1275 | w->region_showing = (!NILP (Vtransient_mark_mode) | |
1276 | && !NILP (XBUFFER (w->buffer)->mark_active) | |
1277 | ? Fmarker_position (XBUFFER (w->buffer)->mark) | |
1278 | : Qnil); | |
1279 | } | |
1280 | ||
d2f84654 | 1281 | w->window_end_valid = w->buffer; |
a2889657 | 1282 | w->update_mode_line = Qnil; |
051e7076 | 1283 | if (!NILP (w->buffer) && flag) |
28995e67 | 1284 | XBUFFER (w->buffer)->clip_changed = 0; |
a2889657 | 1285 | |
265a9e55 | 1286 | if (!NILP (w->vchild)) |
a2889657 | 1287 | mark_window_display_accurate (w->vchild, flag); |
265a9e55 | 1288 | if (!NILP (w->hchild)) |
a2889657 JB |
1289 | mark_window_display_accurate (w->hchild, flag); |
1290 | } | |
1291 | ||
1292 | if (flag) | |
1293 | { | |
1294 | last_arrow_position = Voverlay_arrow_position; | |
1295 | last_arrow_string = Voverlay_arrow_string; | |
1296 | } | |
1297 | else | |
1298 | { | |
1299 | /* t is unequal to any useful value of Voverlay_arrow_... */ | |
1300 | last_arrow_position = Qt; | |
1301 | last_arrow_string = Qt; | |
1302 | } | |
1303 | } | |
1304 | \f | |
ecf7de9b | 1305 | /* Update the menu bar item list for frame F. |
90adcf20 | 1306 | This has to be done before we start to fill in any display lines, |
a2725ab2 RS |
1307 | because it can call eval. |
1308 | ||
1309 | If SAVE_MATCH_DATA is 1, we must save and restore it here. */ | |
90adcf20 RS |
1310 | |
1311 | static void | |
a2725ab2 | 1312 | update_menu_bar (f, save_match_data) |
ecf7de9b | 1313 | FRAME_PTR f; |
a2725ab2 | 1314 | int save_match_data; |
90adcf20 | 1315 | { |
90adcf20 | 1316 | struct buffer *old = current_buffer; |
ecf7de9b RS |
1317 | Lisp_Object window; |
1318 | register struct window *w; | |
a2725ab2 | 1319 | |
ecf7de9b RS |
1320 | window = FRAME_SELECTED_WINDOW (f); |
1321 | w = XWINDOW (window); | |
90adcf20 RS |
1322 | |
1323 | if (update_mode_lines) | |
1324 | w->update_mode_line = Qt; | |
1325 | ||
d1e74921 | 1326 | if (FRAME_WINDOW_P (f) |
d3413a53 | 1327 | ? |
dc937613 | 1328 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
cf074754 | 1329 | FRAME_EXTERNAL_MENU_BAR (f) |
78614721 | 1330 | #else |
cf074754 | 1331 | FRAME_MENU_BAR_LINES (f) > 0 |
78614721 | 1332 | #endif |
d3413a53 | 1333 | : FRAME_MENU_BAR_LINES (f) > 0) |
90adcf20 RS |
1334 | { |
1335 | /* If the user has switched buffers or windows, we need to | |
1336 | recompute to reflect the new bindings. But we'll | |
1337 | recompute when update_mode_lines is set too; that means | |
1338 | that people can use force-mode-line-update to request | |
1339 | that the menu bar be recomputed. The adverse effect on | |
1340 | the rest of the redisplay algorithm is about the same as | |
1341 | windows_or_buffers_changed anyway. */ | |
1342 | if (windows_or_buffers_changed | |
cf074754 | 1343 | || !NILP (w->update_mode_line) |
90adcf20 RS |
1344 | || (XFASTINT (w->last_modified) < MODIFF |
1345 | && (XFASTINT (w->last_modified) | |
94bb7f9b KH |
1346 | <= BUF_SAVE_MODIFF (XBUFFER (w->buffer)))) |
1347 | || ((!NILP (Vtransient_mark_mode) | |
1348 | && !NILP (XBUFFER (w->buffer)->mark_active)) | |
1349 | != !NILP (w->region_showing))) | |
90adcf20 RS |
1350 | { |
1351 | struct buffer *prev = current_buffer; | |
a2725ab2 RS |
1352 | int count = specpdl_ptr - specpdl; |
1353 | ||
399164b4 | 1354 | set_buffer_internal_1 (XBUFFER (w->buffer)); |
eac4251c | 1355 | if (save_match_data) |
a2725ab2 | 1356 | record_unwind_protect (Fstore_match_data, Fmatch_data ()); |
399164b4 | 1357 | if (NILP (Voverriding_local_map_menu_flag)) |
d46fb96a KH |
1358 | { |
1359 | specbind (Qoverriding_terminal_local_map, Qnil); | |
1360 | specbind (Qoverriding_local_map, Qnil); | |
1361 | } | |
a2725ab2 | 1362 | |
34acc8e6 KH |
1363 | /* Run the Lucid hook. */ |
1364 | call1 (Vrun_hooks, Qactivate_menubar_hook); | |
1365 | /* If it has changed current-menubar from previous value, | |
1366 | really recompute the menubar from the value. */ | |
1367 | if (! NILP (Vlucid_menu_bar_dirty_flag)) | |
1368 | call0 (Qrecompute_lucid_menubar); | |
e02500d4 | 1369 | safe_run_hooks (Qmenu_bar_update_hook); |
8351baf2 | 1370 | FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f)); |
8f3343d0 | 1371 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
d1e74921 | 1372 | if (FRAME_WINDOW_P (f)) |
d3413a53 | 1373 | set_frame_menubar (f, 0, 0); |
8f3343d0 | 1374 | #endif /* USE_X_TOOLKIT || HAVE_NTGUI */ |
a2725ab2 RS |
1375 | |
1376 | unbind_to (count, Qnil); | |
399164b4 | 1377 | set_buffer_internal_1 (prev); |
90adcf20 RS |
1378 | } |
1379 | } | |
1380 | } | |
1381 | \f | |
a2889657 JB |
1382 | int do_id = 1; |
1383 | ||
90adcf20 RS |
1384 | /* Redisplay WINDOW and its subwindows and siblings. */ |
1385 | ||
a2889657 | 1386 | static void |
e9874cee | 1387 | redisplay_windows (window, preserve_echo_area) |
a2889657 | 1388 | Lisp_Object window; |
e9874cee | 1389 | int preserve_echo_area; |
a2889657 | 1390 | { |
265a9e55 | 1391 | for (; !NILP (window); window = XWINDOW (window)->next) |
e9874cee | 1392 | redisplay_window (window, 0, preserve_echo_area); |
a2889657 JB |
1393 | } |
1394 | ||
90adcf20 RS |
1395 | /* Redisplay window WINDOW and its subwindows. */ |
1396 | ||
a2889657 | 1397 | static void |
e9874cee | 1398 | redisplay_window (window, just_this_one, preserve_echo_area) |
a2889657 | 1399 | Lisp_Object window; |
e9874cee | 1400 | int just_this_one, preserve_echo_area; |
a2889657 JB |
1401 | { |
1402 | register struct window *w = XWINDOW (window); | |
30c566e4 | 1403 | FRAME_PTR f = XFRAME (WINDOW_FRAME (w)); |
a2889657 | 1404 | int height; |
ae3b1442 | 1405 | register int lpoint = PT; |
a2889657 | 1406 | struct buffer *old = current_buffer; |
b1d1124b | 1407 | register int width = window_internal_width (w) - 1; |
a2889657 JB |
1408 | register int startp; |
1409 | register int hscroll = XINT (w->hscroll); | |
1410 | struct position pos; | |
ae3b1442 | 1411 | int opoint = PT; |
a2889657 | 1412 | int tem; |
e481f960 | 1413 | int update_mode_line; |
f908610f | 1414 | struct Lisp_Char_Table *dp = window_display_table (w); |
a2889657 | 1415 | |
44fa5b1e | 1416 | if (FRAME_HEIGHT (f) == 0) abort (); /* Some bug zeros some core */ |
a2889657 JB |
1417 | |
1418 | /* If this is a combination window, do its children; that's all. */ | |
1419 | ||
265a9e55 | 1420 | if (!NILP (w->vchild)) |
a2889657 JB |
1421 | { |
1422 | redisplay_windows (w->vchild); | |
1423 | return; | |
1424 | } | |
265a9e55 | 1425 | if (!NILP (w->hchild)) |
a2889657 JB |
1426 | { |
1427 | redisplay_windows (w->hchild); | |
1428 | return; | |
1429 | } | |
265a9e55 | 1430 | if (NILP (w->buffer)) |
a2889657 | 1431 | abort (); |
8de2d90b JB |
1432 | |
1433 | height = window_internal_height (w); | |
4d641a15 | 1434 | update_mode_line = (!NILP (w->update_mode_line) || update_mode_lines); |
73af359d RS |
1435 | if (XBUFFER (w->buffer)->clip_changed) |
1436 | update_mode_line = 1; | |
8de2d90b JB |
1437 | |
1438 | if (MINI_WINDOW_P (w)) | |
1439 | { | |
73af359d RS |
1440 | if (w == XWINDOW (echo_area_window) && echo_area_glyphs) |
1441 | /* We've already displayed the echo area glyphs in this window. */ | |
1442 | goto finish_scroll_bars; | |
1443 | else if (w != XWINDOW (minibuf_window)) | |
8de2d90b | 1444 | { |
73af359d RS |
1445 | /* This is a minibuffer, but it's not the currently active one, |
1446 | so clear it. */ | |
1447 | int vpos = XFASTINT (w->top); | |
8de2d90b JB |
1448 | int i; |
1449 | ||
1450 | for (i = 0; i < height; i++) | |
1451 | { | |
44fa5b1e | 1452 | get_display_line (f, vpos + i, 0); |
278feba9 | 1453 | display_string (w, vpos + i, "", 0, 0, 0, 1, 0, width); |
8de2d90b JB |
1454 | } |
1455 | ||
88f22aff | 1456 | goto finish_scroll_bars; |
8de2d90b JB |
1457 | } |
1458 | } | |
a2889657 | 1459 | |
a2889657 JB |
1460 | /* Otherwise set up data on this window; select its buffer and point value */ |
1461 | ||
e481f960 | 1462 | if (update_mode_line) |
f72df6ac | 1463 | set_buffer_internal_1 (XBUFFER (w->buffer)); |
e481f960 RS |
1464 | else |
1465 | set_buffer_temp (XBUFFER (w->buffer)); | |
1466 | ||
ae3b1442 | 1467 | opoint = PT; |
a2889657 | 1468 | |
28995e67 RS |
1469 | /* If %c is in mode line, update it if needed. */ |
1470 | if (!NILP (w->column_number_displayed) | |
1471 | /* This alternative quickly identifies a common case | |
1472 | where no change is needed. */ | |
1473 | && !(PT == XFASTINT (w->last_point) | |
1474 | && XFASTINT (w->last_modified) >= MODIFF) | |
1475 | && XFASTINT (w->column_number_displayed) != current_column ()) | |
1476 | update_mode_line = 1; | |
1477 | ||
42640f83 RS |
1478 | /* Count number of windows showing the selected buffer. |
1479 | An indirect buffer counts as its base buffer. */ | |
a2889657 | 1480 | |
42640f83 RS |
1481 | if (!just_this_one) |
1482 | { | |
1483 | struct buffer *current_base, *window_base; | |
1484 | current_base = current_buffer; | |
1485 | window_base = XBUFFER (XWINDOW (selected_window)->buffer); | |
1486 | if (current_base->base_buffer) | |
1487 | current_base = current_base->base_buffer; | |
1488 | if (window_base->base_buffer) | |
1489 | window_base = window_base->base_buffer; | |
1490 | if (current_base == window_base) | |
1491 | buffer_shared++; | |
1492 | } | |
a2889657 JB |
1493 | |
1494 | /* POINT refers normally to the selected window. | |
1495 | For any other window, set up appropriate value. */ | |
1496 | ||
1497 | if (!EQ (window, selected_window)) | |
1498 | { | |
f67a0f51 RS |
1499 | int new_pt = marker_position (w->pointm); |
1500 | if (new_pt < BEGV) | |
a2889657 | 1501 | { |
f67a0f51 RS |
1502 | new_pt = BEGV; |
1503 | Fset_marker (w->pointm, make_number (new_pt), Qnil); | |
a2889657 | 1504 | } |
f67a0f51 | 1505 | else if (new_pt > (ZV - 1)) |
a2889657 | 1506 | { |
f67a0f51 RS |
1507 | new_pt = ZV; |
1508 | Fset_marker (w->pointm, make_number (new_pt), Qnil); | |
a2889657 | 1509 | } |
f67a0f51 RS |
1510 | /* We don't use SET_PT so that the point-motion hooks don't run. */ |
1511 | BUF_PT (current_buffer) = new_pt; | |
a2889657 JB |
1512 | } |
1513 | ||
f4faa47c JB |
1514 | /* If any of the character widths specified in the display table |
1515 | have changed, invalidate the width run cache. It's true that this | |
1516 | may be a bit late to catch such changes, but the rest of | |
1517 | redisplay goes (non-fatally) haywire when the display table is | |
1518 | changed, so why should we worry about doing any better? */ | |
1519 | if (current_buffer->width_run_cache) | |
1520 | { | |
f908610f | 1521 | struct Lisp_Char_Table *disptab = buffer_display_table (); |
f4faa47c JB |
1522 | |
1523 | if (! disptab_matches_widthtab (disptab, | |
1524 | XVECTOR (current_buffer->width_table))) | |
1525 | { | |
1526 | invalidate_region_cache (current_buffer, | |
1527 | current_buffer->width_run_cache, | |
1528 | BEG, Z); | |
1529 | recompute_width_table (current_buffer, disptab); | |
1530 | } | |
1531 | } | |
1532 | ||
a2889657 | 1533 | /* If window-start is screwed up, choose a new one. */ |
a2889657 JB |
1534 | if (XMARKER (w->start)->buffer != current_buffer) |
1535 | goto recenter; | |
1536 | ||
1537 | startp = marker_position (w->start); | |
1538 | ||
8de2d90b | 1539 | /* Handle case where place to start displaying has been specified, |
aa6d10fa | 1540 | unless the specified location is outside the accessible range. */ |
265a9e55 | 1541 | if (!NILP (w->force_start)) |
a2889657 | 1542 | { |
e63574d7 | 1543 | w->force_start = Qnil; |
aa6d10fa RS |
1544 | /* Forget any recorded base line for line number display. */ |
1545 | w->base_line_number = Qnil; | |
75c43375 RS |
1546 | /* Redisplay the mode line. Select the buffer properly for that. |
1547 | Also, run the hook window-scroll-functions | |
1548 | because we have scrolled. */ | |
e63574d7 RS |
1549 | /* Note, we do this after clearing force_start because |
1550 | if there's an error, it is better to forget about force_start | |
1551 | than to get into an infinite loop calling the hook functions | |
1552 | and having them get more errors. */ | |
75c43375 RS |
1553 | if (!update_mode_line |
1554 | || ! NILP (Vwindow_scroll_functions)) | |
e481f960 | 1555 | { |
75c43375 RS |
1556 | Lisp_Object temp[3]; |
1557 | ||
e481f960 | 1558 | set_buffer_temp (old); |
f72df6ac | 1559 | set_buffer_internal_1 (XBUFFER (w->buffer)); |
e481f960 RS |
1560 | update_mode_line = 1; |
1561 | w->update_mode_line = Qt; | |
75c43375 | 1562 | if (! NILP (Vwindow_scroll_functions)) |
3dcd07e3 KH |
1563 | { |
1564 | run_hook_with_args_2 (Qwindow_scroll_functions, window, | |
1565 | make_number (startp)); | |
1566 | startp = marker_position (w->start); | |
1567 | } | |
e481f960 | 1568 | } |
c2213350 | 1569 | XSETFASTINT (w->last_modified, 0); |
8de2d90b JB |
1570 | if (startp < BEGV) startp = BEGV; |
1571 | if (startp > ZV) startp = ZV; | |
a2889657 JB |
1572 | try_window (window, startp); |
1573 | if (cursor_vpos < 0) | |
1574 | { | |
1575 | /* If point does not appear, move point so it does appear */ | |
1576 | pos = *compute_motion (startp, 0, | |
ca26e1c8 KH |
1577 | (((EQ (window, minibuf_window) |
1578 | && startp == BEG) | |
1579 | ? minibuf_prompt_width : 0) | |
1580 | + (hscroll ? 1 - hscroll : 0)), | |
1581 | 0, | |
1582 | ZV, height / 2, | |
68be917d | 1583 | - (1 << (BITS_PER_SHORT - 1)), |
ca26e1c8 | 1584 | width, hscroll, pos_tab_offset (w, startp), w); |
f67a0f51 | 1585 | BUF_PT (current_buffer) = pos.bufpos; |
90adcf20 | 1586 | if (w != XWINDOW (selected_window)) |
ae3b1442 | 1587 | Fset_marker (w->pointm, make_number (PT), Qnil); |
a2889657 JB |
1588 | else |
1589 | { | |
9d6a6bb9 | 1590 | if (current_buffer == old) |
ae3b1442 | 1591 | lpoint = PT; |
210e752f KH |
1592 | FRAME_CURSOR_X (f) = (XFASTINT (w->left) |
1593 | + minmax (0, pos.hpos, width)); | |
44fa5b1e | 1594 | FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top); |
a2889657 | 1595 | } |
df0b5ea1 RS |
1596 | /* If we are highlighting the region, |
1597 | then we just changed the region, so redisplay to show it. */ | |
df0b5ea1 RS |
1598 | if (!NILP (Vtransient_mark_mode) |
1599 | && !NILP (current_buffer->mark_active)) | |
6f27fa9b RS |
1600 | { |
1601 | cancel_my_columns (XWINDOW (window)); | |
1602 | try_window (window, startp); | |
1603 | } | |
a2889657 JB |
1604 | } |
1605 | goto done; | |
1606 | } | |
1607 | ||
1608 | /* Handle case where text has not changed, only point, | |
208aee63 | 1609 | and it has not moved off the frame. */ |
a2889657 JB |
1610 | |
1611 | /* This code is not used for minibuffer for the sake of | |
1612 | the case of redisplaying to replace an echo area message; | |
1613 | since in that case the minibuffer contents per se are usually unchanged. | |
1614 | This code is of no real use in the minibuffer since | |
1615 | the handling of this_line_bufpos, etc., | |
1616 | in redisplay handles the same cases. */ | |
1617 | ||
1618 | if (XFASTINT (w->last_modified) >= MODIFF | |
86bee31c | 1619 | && PT >= startp && !current_buffer->clip_changed |
44fa5b1e | 1620 | && (just_this_one || XFASTINT (w->width) == FRAME_WIDTH (f)) |
b1aa6cb3 RS |
1621 | /* If force-mode-line-update was called, really redisplay; |
1622 | that's how redisplay is forced after e.g. changing | |
1623 | buffer-invisibility-spec. */ | |
632ab665 | 1624 | && NILP (w->update_mode_line) |
bd66d1ba RS |
1625 | /* Can't use this case if highlighting a region. */ |
1626 | && !(!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active)) | |
1627 | && NILP (w->region_showing) | |
15495c73 KH |
1628 | /* If end pos is out of date, scroll bar and percentage will be wrong */ |
1629 | && INTEGERP (w->window_end_vpos) | |
1630 | && XFASTINT (w->window_end_vpos) < XFASTINT (w->height) | |
a2889657 JB |
1631 | && !EQ (window, minibuf_window)) |
1632 | { | |
ca26e1c8 | 1633 | pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), 0, |
632ab665 | 1634 | PT, height, 0, width, hscroll, |
e37f06d7 | 1635 | pos_tab_offset (w, startp), w); |
a2889657 JB |
1636 | |
1637 | if (pos.vpos < height) | |
1638 | { | |
44fa5b1e JB |
1639 | /* Ok, point is still on frame */ |
1640 | if (w == XWINDOW (FRAME_SELECTED_WINDOW (f))) | |
a2889657 JB |
1641 | { |
1642 | /* These variables are supposed to be origin 1 */ | |
210e752f KH |
1643 | FRAME_CURSOR_X (f) = (XFASTINT (w->left) |
1644 | + minmax (0, pos.hpos, width)); | |
44fa5b1e | 1645 | FRAME_CURSOR_Y (f) = pos.vpos + XFASTINT (w->top); |
a2889657 JB |
1646 | } |
1647 | /* This doesn't do the trick, because if a window to the right of | |
1648 | this one must be redisplayed, this does nothing because there | |
44fa5b1e | 1649 | is nothing in DesiredFrame yet, and then the other window is |
a2889657 | 1650 | redisplayed, making likes that are empty in this window's columns. |
44fa5b1e | 1651 | if (XFASTINT (w->width) != FRAME_WIDTH (f)) |
a2889657 JB |
1652 | preserve_my_columns (w); |
1653 | */ | |
1654 | goto done; | |
1655 | } | |
1656 | /* Don't bother trying redisplay with same start; | |
1657 | we already know it will lose */ | |
1658 | } | |
1659 | /* If current starting point was originally the beginning of a line | |
1660 | but no longer is, find a new starting point. */ | |
265a9e55 | 1661 | else if (!NILP (w->start_at_line_beg) |
b16234d8 | 1662 | && !(startp <= BEGV |
a2889657 JB |
1663 | || FETCH_CHAR (startp - 1) == '\n')) |
1664 | { | |
1665 | goto recenter; | |
1666 | } | |
1667 | else if (just_this_one && !MINI_WINDOW_P (w) | |
ae3b1442 | 1668 | && PT >= startp |
a2889657 | 1669 | && XFASTINT (w->last_modified) |
14709f21 JB |
1670 | /* or else vmotion on first line won't work. */ |
1671 | && ! NILP (w->start_at_line_beg) | |
a2889657 | 1672 | && ! EQ (w->window_end_valid, Qnil) |
86bee31c | 1673 | && do_id && !current_buffer->clip_changed |
a2889657 | 1674 | && !blank_end_of_window |
44fa5b1e | 1675 | && XFASTINT (w->width) == FRAME_WIDTH (f) |
bd66d1ba RS |
1676 | /* Can't use this case if highlighting a region. */ |
1677 | && !(!NILP (Vtransient_mark_mode) | |
1678 | && !NILP (current_buffer->mark_active)) | |
23c852cb KH |
1679 | /* Don't use try_window_id if newline |
1680 | doesn't display as the end of a line. */ | |
1681 | && !(dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, '\n'))) | |
bd66d1ba | 1682 | && NILP (w->region_showing) |
a2889657 JB |
1683 | && EQ (last_arrow_position, Voverlay_arrow_position) |
1684 | && EQ (last_arrow_string, Voverlay_arrow_string) | |
44fa5b1e | 1685 | && (tem = try_window_id (FRAME_SELECTED_WINDOW (f))) |
a2889657 JB |
1686 | && tem != -2) |
1687 | { | |
1688 | /* tem > 0 means success. tem == -1 means choose new start. | |
1689 | tem == -2 means try again with same start, | |
1690 | and nothing but whitespace follows the changed stuff. | |
1691 | tem == 0 means try again with same start. */ | |
1692 | if (tem > 0) | |
1693 | goto done; | |
1694 | } | |
1695 | else if (startp >= BEGV && startp <= ZV | |
e9874cee RS |
1696 | && (startp < ZV |
1697 | /* Avoid starting at end of buffer. */ | |
1698 | #if 0 /* This change causes trouble for M-! finger & RET. | |
1699 | It will have to be considered later. */ | |
1700 | || ! EQ (window, selected_window) | |
1701 | /* Don't do the recentering if redisplay | |
1702 | is not for no user action. */ | |
1703 | || preserve_echo_area | |
1704 | #endif | |
1705 | || startp == BEGV | |
a2889657 JB |
1706 | || (XFASTINT (w->last_modified) >= MODIFF))) |
1707 | { | |
1708 | /* Try to redisplay starting at same place as before */ | |
44fa5b1e | 1709 | /* If point has not moved off frame, accept the results */ |
a2889657 JB |
1710 | try_window (window, startp); |
1711 | if (cursor_vpos >= 0) | |
aa6d10fa | 1712 | { |
28995e67 RS |
1713 | if (!just_this_one || current_buffer->clip_changed |
1714 | || beg_unchanged < startp) | |
aa6d10fa RS |
1715 | /* Forget any recorded base line for line number display. */ |
1716 | w->base_line_number = Qnil; | |
1717 | goto done; | |
1718 | } | |
a2889657 JB |
1719 | else |
1720 | cancel_my_columns (w); | |
1721 | } | |
1722 | ||
c2213350 | 1723 | XSETFASTINT (w->last_modified, 0); |
e481f960 RS |
1724 | /* Redisplay the mode line. Select the buffer properly for that. */ |
1725 | if (!update_mode_line) | |
1726 | { | |
1727 | set_buffer_temp (old); | |
f72df6ac | 1728 | set_buffer_internal_1 (XBUFFER (w->buffer)); |
e481f960 RS |
1729 | update_mode_line = 1; |
1730 | w->update_mode_line = Qt; | |
1731 | } | |
a2889657 JB |
1732 | |
1733 | /* Try to scroll by specified few lines */ | |
1734 | ||
2c081c2d KH |
1735 | if (scroll_step && !current_buffer->clip_changed |
1736 | && startp >= BEGV && startp <= ZV) | |
a2889657 | 1737 | { |
ae3b1442 | 1738 | if (PT > startp) |
a2889657 | 1739 | { |
210e752f | 1740 | pos = *vmotion (Z - XFASTINT (w->window_end_pos), scroll_step, w); |
a2889657 JB |
1741 | if (pos.vpos >= height) |
1742 | goto scroll_fail; | |
1743 | } | |
1744 | ||
210e752f | 1745 | pos = *vmotion (startp, (PT < startp ? - scroll_step : scroll_step), w); |
a2889657 | 1746 | |
ae3b1442 | 1747 | if (PT >= pos.bufpos) |
a2889657 | 1748 | { |
75c43375 | 1749 | if (! NILP (Vwindow_scroll_functions)) |
3dcd07e3 KH |
1750 | { |
1751 | run_hook_with_args_2 (Qwindow_scroll_functions, window, | |
1752 | make_number (pos.bufpos)); | |
1753 | pos.bufpos = marker_position (w->start); | |
1754 | } | |
a2889657 JB |
1755 | try_window (window, pos.bufpos); |
1756 | if (cursor_vpos >= 0) | |
aa6d10fa | 1757 | { |
28995e67 RS |
1758 | if (!just_this_one || current_buffer->clip_changed |
1759 | || beg_unchanged < startp) | |
aa6d10fa RS |
1760 | /* Forget any recorded base line for line number display. */ |
1761 | w->base_line_number = Qnil; | |
1762 | goto done; | |
1763 | } | |
a2889657 JB |
1764 | else |
1765 | cancel_my_columns (w); | |
1766 | } | |
1767 | scroll_fail: ; | |
1768 | } | |
1769 | ||
1770 | /* Finally, just choose place to start which centers point */ | |
1771 | ||
1772 | recenter: | |
aa6d10fa RS |
1773 | /* Forget any previously recorded base line for line number display. */ |
1774 | w->base_line_number = Qnil; | |
1775 | ||
210e752f | 1776 | pos = *vmotion (PT, - (height / 2), w); |
e63574d7 RS |
1777 | /* Set startp here explicitly in case that helps avoid an infinite loop |
1778 | in case the window-scroll-functions functions get errors. */ | |
208aee63 | 1779 | Fset_marker (w->start, make_number (pos.bufpos), Qnil); |
75c43375 | 1780 | if (! NILP (Vwindow_scroll_functions)) |
3dcd07e3 KH |
1781 | { |
1782 | run_hook_with_args_2 (Qwindow_scroll_functions, window, | |
1783 | make_number (pos.bufpos)); | |
1784 | pos.bufpos = marker_position (w->start); | |
1785 | } | |
a2889657 JB |
1786 | try_window (window, pos.bufpos); |
1787 | ||
1788 | startp = marker_position (w->start); | |
ca26e1c8 | 1789 | w->start_at_line_beg |
b16234d8 | 1790 | = (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil; |
a2889657 JB |
1791 | |
1792 | done: | |
e481f960 | 1793 | if ((update_mode_line |
aa6d10fa RS |
1794 | /* If window not full width, must redo its mode line |
1795 | if the window to its side is being redone */ | |
1796 | || (!just_this_one && width < FRAME_WIDTH (f) - 1) | |
155ef550 KH |
1797 | || INTEGERP (w->base_line_pos) |
1798 | || (!NILP (w->column_number_displayed) | |
1799 | && XFASTINT (w->column_number_displayed) != current_column ())) | |
a2889657 JB |
1800 | && height != XFASTINT (w->height)) |
1801 | display_mode_line (w); | |
aa6d10fa RS |
1802 | if (! line_number_displayed |
1803 | && ! BUFFERP (w->base_line_pos)) | |
1804 | { | |
1805 | w->base_line_pos = Qnil; | |
1806 | w->base_line_number = Qnil; | |
1807 | } | |
a2889657 | 1808 | |
7ce2c095 | 1809 | /* When we reach a frame's selected window, redo the frame's menu bar. */ |
e481f960 | 1810 | if (update_mode_line |
d1e74921 | 1811 | && (FRAME_WINDOW_P (f) |
d3413a53 | 1812 | ? |
dc937613 | 1813 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
d3413a53 | 1814 | FRAME_EXTERNAL_MENU_BAR (f) |
76412d64 | 1815 | #else |
d3413a53 | 1816 | FRAME_MENU_BAR_LINES (f) > 0 |
76412d64 | 1817 | #endif |
d3413a53 | 1818 | : FRAME_MENU_BAR_LINES (f) > 0) |
7ce2c095 RS |
1819 | && EQ (FRAME_SELECTED_WINDOW (f), window)) |
1820 | display_menu_bar (w); | |
1821 | ||
88f22aff JB |
1822 | finish_scroll_bars: |
1823 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
30c566e4 | 1824 | { |
b1d1124b | 1825 | int start, end, whole; |
30c566e4 | 1826 | |
b1d1124b | 1827 | /* Calculate the start and end positions for the current window. |
3505ea70 JB |
1828 | At some point, it would be nice to choose between scrollbars |
1829 | which reflect the whole buffer size, with special markers | |
1830 | indicating narrowing, and scrollbars which reflect only the | |
1831 | visible region. | |
1832 | ||
b1d1124b JB |
1833 | Note that minibuffers sometimes aren't displaying any text. */ |
1834 | if (! MINI_WINDOW_P (w) | |
1835 | || (w == XWINDOW (minibuf_window) && ! echo_area_glyphs)) | |
1836 | { | |
8a9311d7 | 1837 | whole = ZV - BEGV; |
4d641a15 | 1838 | start = marker_position (w->start) - BEGV; |
b1d1124b JB |
1839 | /* I don't think this is guaranteed to be right. For the |
1840 | moment, we'll pretend it is. */ | |
85f26be9 | 1841 | end = (Z - XINT (w->window_end_pos)) - BEGV; |
3505ea70 JB |
1842 | |
1843 | if (end < start) end = start; | |
8a9311d7 | 1844 | if (whole < (end - start)) whole = end - start; |
b1d1124b JB |
1845 | } |
1846 | else | |
1847 | start = end = whole = 0; | |
30c566e4 | 1848 | |
88f22aff | 1849 | /* Indicate what this scroll bar ought to be displaying now. */ |
7eb9ba41 | 1850 | (*set_vertical_scroll_bar_hook) (w, end - start, whole, start); |
30c566e4 | 1851 | |
88f22aff | 1852 | /* Note that we actually used the scroll bar attached to this window, |
30c566e4 | 1853 | so it shouldn't be deleted at the end of redisplay. */ |
88f22aff | 1854 | (*redeem_scroll_bar_hook) (w); |
30c566e4 | 1855 | } |
b1d1124b | 1856 | |
f67a0f51 | 1857 | BUF_PT (current_buffer) = opoint; |
e481f960 | 1858 | if (update_mode_line) |
f72df6ac | 1859 | set_buffer_internal_1 (old); |
e481f960 RS |
1860 | else |
1861 | set_buffer_temp (old); | |
f67a0f51 | 1862 | BUF_PT (current_buffer) = lpoint; |
a2889657 JB |
1863 | } |
1864 | \f | |
1865 | /* Do full redisplay on one window, starting at position `pos'. */ | |
1866 | ||
1867 | static void | |
1868 | try_window (window, pos) | |
1869 | Lisp_Object window; | |
1870 | register int pos; | |
1871 | { | |
1872 | register struct window *w = XWINDOW (window); | |
1873 | register int height = window_internal_height (w); | |
1874 | register int vpos = XFASTINT (w->top); | |
1875 | register int last_text_vpos = vpos; | |
1876 | int tab_offset = pos_tab_offset (w, pos); | |
44fa5b1e | 1877 | FRAME_PTR f = XFRAME (w->frame); |
b1d1124b | 1878 | int width = window_internal_width (w) - 1; |
a2889657 JB |
1879 | struct position val; |
1880 | ||
1881 | Fset_marker (w->start, make_number (pos), Qnil); | |
1882 | cursor_vpos = -1; | |
1883 | overlay_arrow_seen = 0; | |
ca26e1c8 | 1884 | zv_strings_seen = 0; |
a2889657 JB |
1885 | val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0; |
1886 | ||
1887 | while (--height >= 0) | |
1888 | { | |
1889 | val = *display_text_line (w, pos, vpos, val.hpos, tab_offset); | |
1890 | tab_offset += width; | |
2b050fec RS |
1891 | /* For the first line displayed, display_text_line |
1892 | subtracts the prompt width from the tab offset. | |
1893 | But it does not affect the value of our variable tab_offset. | |
1894 | So we do the subtraction again, | |
1895 | for the sake of continuation lines of that first line. */ | |
1896 | if (MINI_WINDOW_P (w) && vpos == XFASTINT (w->top)) | |
1897 | tab_offset -= minibuf_prompt_width; | |
1898 | ||
a2889657 JB |
1899 | if (val.vpos) tab_offset = 0; |
1900 | vpos++; | |
1901 | if (pos != val.bufpos) | |
642eefc6 RS |
1902 | { |
1903 | int invis = 0; | |
e885523c | 1904 | #ifdef USE_TEXT_PROPERTIES |
642eefc6 RS |
1905 | Lisp_Object invis_prop; |
1906 | invis_prop = Fget_char_property (val.bufpos-1, Qinvisible, window); | |
1907 | invis = TEXT_PROP_MEANS_INVISIBLE (invis_prop); | |
e885523c | 1908 | #endif |
642eefc6 RS |
1909 | |
1910 | last_text_vpos | |
1911 | /* Next line, unless prev line ended in end of buffer with no cr */ | |
1912 | = vpos - (val.vpos | |
1913 | && (FETCH_CHAR (val.bufpos - 1) != '\n' || invis)); | |
1914 | } | |
a2889657 JB |
1915 | pos = val.bufpos; |
1916 | } | |
1917 | ||
1918 | /* If last line is continued in middle of character, | |
44fa5b1e | 1919 | include the split character in the text considered on the frame */ |
a2889657 JB |
1920 | if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0)) |
1921 | pos++; | |
1922 | ||
44fa5b1e | 1923 | /* If bottom just moved off end of frame, change mode line percentage. */ |
a2889657 JB |
1924 | if (XFASTINT (w->window_end_pos) == 0 |
1925 | && Z != pos) | |
1926 | w->update_mode_line = Qt; | |
1927 | ||
44fa5b1e | 1928 | /* Say where last char on frame will be, once redisplay is finished. */ |
c2213350 KH |
1929 | XSETFASTINT (w->window_end_pos, Z - pos); |
1930 | XSETFASTINT (w->window_end_vpos, last_text_vpos - XFASTINT (w->top)); | |
a2889657 JB |
1931 | /* But that is not valid info until redisplay finishes. */ |
1932 | w->window_end_valid = Qnil; | |
1933 | } | |
1934 | \f | |
1935 | /* Try to redisplay when buffer is modified locally, | |
1936 | computing insert/delete line to preserve text outside | |
1937 | the bounds of the changes. | |
1938 | Return 1 if successful, 0 if if cannot tell what to do, | |
1939 | or -1 to tell caller to find a new window start, | |
1940 | or -2 to tell caller to do normal redisplay with same window start. */ | |
1941 | ||
1942 | static int | |
1943 | try_window_id (window) | |
1944 | Lisp_Object window; | |
1945 | { | |
1946 | int pos; | |
1947 | register struct window *w = XWINDOW (window); | |
1948 | register int height = window_internal_height (w); | |
44fa5b1e | 1949 | FRAME_PTR f = XFRAME (w->frame); |
a2889657 JB |
1950 | int top = XFASTINT (w->top); |
1951 | int start = marker_position (w->start); | |
b1d1124b | 1952 | int width = window_internal_width (w) - 1; |
a2889657 JB |
1953 | int hscroll = XINT (w->hscroll); |
1954 | int lmargin = hscroll > 0 ? 1 - hscroll : 0; | |
ca26e1c8 | 1955 | int did_motion; |
a2889657 JB |
1956 | register int vpos; |
1957 | register int i, tem; | |
1958 | int last_text_vpos = 0; | |
1959 | int stop_vpos; | |
e24c997d KH |
1960 | int selective = (INTEGERP (current_buffer->selective_display) |
1961 | ? XINT (current_buffer->selective_display) | |
1962 | : !NILP (current_buffer->selective_display) ? -1 : 0); | |
a2889657 JB |
1963 | |
1964 | struct position val, bp, ep, xp, pp; | |
1965 | int scroll_amount = 0; | |
1966 | int delta; | |
d3413a53 | 1967 | int tab_offset, epto, old_tick; |
a2889657 JB |
1968 | |
1969 | if (GPT - BEG < beg_unchanged) | |
1970 | beg_unchanged = GPT - BEG; | |
1971 | if (Z - GPT < end_unchanged) | |
1972 | end_unchanged = Z - GPT; | |
1973 | ||
6a1dc7ac | 1974 | if (beg_unchanged + BEG < start) |
a2889657 JB |
1975 | return 0; /* Give up if changes go above top of window */ |
1976 | ||
1977 | /* Find position before which nothing is changed. */ | |
ca26e1c8 | 1978 | bp = *compute_motion (start, 0, lmargin, 0, |
632ab665 | 1979 | min (ZV, beg_unchanged + BEG), height, 0, |
e37f06d7 | 1980 | width, hscroll, pos_tab_offset (w, start), w); |
a2889657 | 1981 | if (bp.vpos >= height) |
6e8290aa | 1982 | { |
632ab665 | 1983 | if (PT < bp.bufpos) |
6e8290aa | 1984 | { |
67481ae5 RS |
1985 | /* All changes are beyond the window end, and point is on the screen. |
1986 | We don't need to change the text at all. | |
6e8290aa JB |
1987 | But we need to update window_end_pos to account for |
1988 | any change in buffer size. */ | |
ca26e1c8 | 1989 | bp = *compute_motion (start, 0, lmargin, 0, |
67481ae5 | 1990 | ZV, height, 0, |
e37f06d7 | 1991 | width, hscroll, pos_tab_offset (w, start), w); |
c2213350 KH |
1992 | XSETFASTINT (w->window_end_vpos, height); |
1993 | XSETFASTINT (w->window_end_pos, Z - bp.bufpos); | |
4d641a15 | 1994 | goto findpoint; |
6e8290aa JB |
1995 | } |
1996 | return 0; | |
1997 | } | |
a2889657 JB |
1998 | |
1999 | vpos = bp.vpos; | |
2000 | ||
44fa5b1e | 2001 | /* Find beginning of that frame line. Must display from there. */ |
210e752f | 2002 | bp = *vmotion (bp.bufpos, 0, w); |
a2889657 JB |
2003 | |
2004 | pos = bp.bufpos; | |
2005 | val.hpos = lmargin; | |
2006 | if (pos < start) | |
2007 | return -1; | |
2008 | ||
ca26e1c8 | 2009 | did_motion = 0; |
a2889657 | 2010 | /* If about to start displaying at the beginning of a continuation line, |
44fa5b1e | 2011 | really start with previous frame line, in case it was not |
a2889657 | 2012 | continued when last redisplayed */ |
05ba02eb JB |
2013 | if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0) |
2014 | || | |
2015 | /* Likewise if we have to worry about selective display. */ | |
9f412332 | 2016 | (selective > 0 && bp.bufpos - 1 == beg_unchanged && vpos > 0)) |
a2889657 | 2017 | { |
210e752f | 2018 | bp = *vmotion (bp.bufpos, -1, w); |
a2889657 JB |
2019 | --vpos; |
2020 | pos = bp.bufpos; | |
2021 | } | |
2022 | ||
2023 | if (bp.contin && bp.hpos != lmargin) | |
2024 | { | |
2025 | val.hpos = bp.prevhpos - width + lmargin; | |
ca26e1c8 | 2026 | did_motion = 1; |
a2889657 JB |
2027 | pos--; |
2028 | } | |
2029 | ||
2030 | bp.vpos = vpos; | |
2031 | ||
2032 | /* Find first visible newline after which no more is changed. */ | |
2033 | tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1); | |
9f412332 KH |
2034 | if (selective > 0) |
2035 | while (tem < ZV - 1 && (indented_beyond_p (tem, selective))) | |
a2889657 JB |
2036 | tem = find_next_newline (tem, 1); |
2037 | ||
2038 | /* Compute the cursor position after that newline. */ | |
ca26e1c8 | 2039 | ep = *compute_motion (pos, vpos, val.hpos, did_motion, tem, |
68be917d | 2040 | height, - (1 << (BITS_PER_SHORT - 1)), |
e37f06d7 | 2041 | width, hscroll, pos_tab_offset (w, bp.bufpos), w); |
a2889657 | 2042 | |
44fa5b1e JB |
2043 | /* If changes reach past the text available on the frame, |
2044 | just display rest of frame. */ | |
a2889657 JB |
2045 | if (ep.bufpos > Z - XFASTINT (w->window_end_pos)) |
2046 | stop_vpos = height; | |
2047 | else | |
2048 | stop_vpos = ep.vpos; | |
2049 | ||
2050 | /* If no newline before ep, the line ep is on includes some changes | |
2051 | that must be displayed. Make sure we don't stop before it. */ | |
2052 | /* Also, if changes reach all the way until ep.bufpos, | |
2053 | it is possible that something was deleted after the | |
2054 | newline before it, so the following line must be redrawn. */ | |
2055 | if (stop_vpos == ep.vpos | |
2056 | && (ep.bufpos == BEGV | |
2057 | || FETCH_CHAR (ep.bufpos - 1) != '\n' | |
2058 | || ep.bufpos == Z - end_unchanged)) | |
2059 | stop_vpos = ep.vpos + 1; | |
2060 | ||
2061 | cursor_vpos = -1; | |
2062 | overlay_arrow_seen = 0; | |
ca26e1c8 | 2063 | zv_strings_seen = 0; |
a2889657 JB |
2064 | |
2065 | /* If changes do not reach to bottom of window, | |
2066 | figure out how much to scroll the rest of the window */ | |
2067 | if (stop_vpos < height) | |
2068 | { | |
2069 | /* Now determine how far up or down the rest of the window has moved */ | |
2070 | epto = pos_tab_offset (w, ep.bufpos); | |
ca26e1c8 | 2071 | xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1, |
a2889657 | 2072 | Z - XFASTINT (w->window_end_pos), |
e37f06d7 | 2073 | 10000, 0, width, hscroll, epto, w); |
a2889657 JB |
2074 | scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos); |
2075 | ||
44fa5b1e | 2076 | /* Is everything on frame below the changes whitespace? |
a2889657 JB |
2077 | If so, no scrolling is really necessary. */ |
2078 | for (i = ep.bufpos; i < xp.bufpos; i++) | |
2079 | { | |
2080 | tem = FETCH_CHAR (i); | |
2081 | if (tem != ' ' && tem != '\n' && tem != '\t') | |
2082 | break; | |
2083 | } | |
2084 | if (i == xp.bufpos) | |
2085 | return -2; | |
2086 | ||
e8e536a9 KH |
2087 | XSETFASTINT (w->window_end_vpos, |
2088 | XFASTINT (w->window_end_vpos) + scroll_amount); | |
a2889657 | 2089 | |
44fa5b1e | 2090 | /* Before doing any scrolling, verify that point will be on frame. */ |
ae3b1442 | 2091 | if (PT > ep.bufpos && !(PT <= xp.bufpos && xp.bufpos < height)) |
a2889657 | 2092 | { |
ae3b1442 | 2093 | if (PT <= xp.bufpos) |
a2889657 | 2094 | { |
ca26e1c8 | 2095 | pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, 1, |
68be917d | 2096 | PT, height, - (1 << (BITS_PER_SHORT - 1)), |
e37f06d7 | 2097 | width, hscroll, epto, w); |
a2889657 JB |
2098 | } |
2099 | else | |
2100 | { | |
ca26e1c8 | 2101 | pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, 1, |
68be917d | 2102 | PT, height, - (1 << (BITS_PER_SHORT - 1)), |
e37f06d7 KH |
2103 | width, hscroll, |
2104 | pos_tab_offset (w, xp.bufpos), w); | |
a2889657 | 2105 | } |
ae3b1442 | 2106 | if (pp.bufpos < PT || pp.vpos == height) |
a2889657 JB |
2107 | return 0; |
2108 | cursor_vpos = pp.vpos + top; | |
210e752f | 2109 | cursor_hpos = XFASTINT (w->left) + minmax (0, pp.hpos, width); |
a2889657 JB |
2110 | } |
2111 | ||
2112 | if (stop_vpos - scroll_amount >= height | |
2113 | || ep.bufpos == xp.bufpos) | |
2114 | { | |
2115 | if (scroll_amount < 0) | |
2116 | stop_vpos -= scroll_amount; | |
2117 | scroll_amount = 0; | |
2118 | /* In this path, we have altered window_end_vpos | |
2119 | and not left it negative. | |
2120 | We must make sure that, in case display is preempted | |
44fa5b1e | 2121 | before the frame changes to reflect what we do here, |
a2889657 | 2122 | further updates will not come to try_window_id |
44fa5b1e | 2123 | and assume the frame and window_end_vpos match. */ |
a2889657 JB |
2124 | blank_end_of_window = 1; |
2125 | } | |
2126 | else if (!scroll_amount) | |
0d231165 RS |
2127 | { |
2128 | /* Even if we don't need to scroll, we must adjust the | |
2129 | charstarts of subsequent lines (that we won't redisplay) | |
2130 | according to the amount of text inserted or deleted. */ | |
2131 | int oldpos = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0]; | |
2132 | int adjust = ep.bufpos - oldpos; | |
2133 | adjust_window_charstarts (w, ep.vpos + top - 1, adjust); | |
2134 | } | |
a2889657 JB |
2135 | else if (bp.bufpos == Z - end_unchanged) |
2136 | { | |
2137 | /* If reprinting everything is nearly as fast as scrolling, | |
2138 | don't bother scrolling. Can happen if lines are short. */ | |
44fa5b1e | 2139 | if (scroll_cost (f, bp.vpos + top - scroll_amount, |
a2889657 JB |
2140 | top + height - max (0, scroll_amount), |
2141 | scroll_amount) | |
2142 | > xp.bufpos - bp.bufpos - 20) | |
2143 | /* Return "try normal display with same window-start." | |
2144 | Too bad we can't prevent further scroll-thinking. */ | |
2145 | return -2; | |
2146 | /* If pure deletion, scroll up as many lines as possible. | |
2147 | In common case of killing a line, this can save the | |
2148 | following line from being overwritten by scrolling | |
2149 | and therefore having to be redrawn. */ | |
44fa5b1e | 2150 | tem = scroll_frame_lines (f, bp.vpos + top - scroll_amount, |
d1cb44a4 RS |
2151 | top + height - max (0, scroll_amount), |
2152 | scroll_amount, bp.bufpos); | |
d2f84654 RS |
2153 | if (!tem) |
2154 | stop_vpos = height; | |
2155 | else | |
2156 | { | |
2157 | /* scroll_frame_lines did not properly adjust subsequent | |
2158 | lines' charstarts in the case where the text of the | |
2159 | screen line at bp.vpos has changed. | |
2160 | (This can happen in a deletion that ends in mid-line.) | |
8e6208c5 KH |
2161 | To adjust properly, we need to make things consistent |
2162 | at the position ep. | |
d2f84654 RS |
2163 | So do a second adjust to make that happen. |
2164 | Note that stop_vpos >= ep.vpos, so it is sufficient | |
2165 | to update the charstarts for lines at ep.vpos and below. */ | |
2166 | int oldstart | |
2167 | = FRAME_CURRENT_GLYPHS (f)->charstarts[ep.vpos + top][0]; | |
2168 | adjust_window_charstarts (w, ep.vpos + top - 1, | |
2169 | ep.bufpos - oldstart); | |
2170 | } | |
a2889657 JB |
2171 | } |
2172 | else if (scroll_amount) | |
2173 | { | |
2174 | /* If reprinting everything is nearly as fast as scrolling, | |
2175 | don't bother scrolling. Can happen if lines are short. */ | |
2176 | /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an | |
2177 | overestimate of cost of reprinting, since xp.bufpos | |
2178 | would end up below the bottom of the window. */ | |
44fa5b1e | 2179 | if (scroll_cost (f, ep.vpos + top - scroll_amount, |
a2889657 JB |
2180 | top + height - max (0, scroll_amount), |
2181 | scroll_amount) | |
2182 | > xp.bufpos - ep.bufpos - 20) | |
2183 | /* Return "try normal display with same window-start." | |
2184 | Too bad we can't prevent further scroll-thinking. */ | |
2185 | return -2; | |
44fa5b1e | 2186 | tem = scroll_frame_lines (f, ep.vpos + top - scroll_amount, |
a2889657 | 2187 | top + height - max (0, scroll_amount), |
d1cb44a4 | 2188 | scroll_amount, ep.bufpos); |
a2889657 JB |
2189 | if (!tem) stop_vpos = height; |
2190 | } | |
2191 | } | |
2192 | ||
2193 | /* In any case, do not display past bottom of window */ | |
2194 | if (stop_vpos >= height) | |
2195 | { | |
2196 | stop_vpos = height; | |
2197 | scroll_amount = 0; | |
2198 | } | |
2199 | ||
2200 | /* Handle case where pos is before w->start -- | |
2201 | can happen if part of line had been clipped and is not clipped now */ | |
2202 | if (vpos == 0 && pos < marker_position (w->start)) | |
2203 | Fset_marker (w->start, make_number (pos), Qnil); | |
2204 | ||
2205 | /* Redisplay the lines where the text was changed */ | |
2206 | last_text_vpos = vpos; | |
2207 | tab_offset = pos_tab_offset (w, pos); | |
2208 | /* If we are starting display in mid-character, correct tab_offset | |
2209 | to account for passing the line that that character really starts in. */ | |
2210 | if (val.hpos < lmargin) | |
2211 | tab_offset += width; | |
d3413a53 | 2212 | old_tick = MODIFF; |
a2889657 JB |
2213 | while (vpos < stop_vpos) |
2214 | { | |
2215 | val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset); | |
d3413a53 RS |
2216 | /* If display_text_line ran a hook and changed some text, |
2217 | redisplay all the way to bottom of buffer | |
2218 | So that we show the changes. */ | |
2219 | if (old_tick != MODIFF) | |
2220 | stop_vpos = height; | |
a2889657 JB |
2221 | tab_offset += width; |
2222 | if (val.vpos) tab_offset = 0; | |
2223 | if (pos != val.bufpos) | |
2224 | last_text_vpos | |
2225 | /* Next line, unless prev line ended in end of buffer with no cr */ | |
2226 | = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n'); | |
2227 | pos = val.bufpos; | |
2228 | } | |
2229 | ||
2230 | /* There are two cases: | |
2231 | 1) we have displayed down to the bottom of the window | |
2232 | 2) we have scrolled lines below stop_vpos by scroll_amount */ | |
2233 | ||
2234 | if (vpos == height) | |
2235 | { | |
2236 | /* If last line is continued in middle of character, | |
44fa5b1e | 2237 | include the split character in the text considered on the frame */ |
a2889657 JB |
2238 | if (val.hpos < lmargin) |
2239 | val.bufpos++; | |
c2213350 KH |
2240 | XSETFASTINT (w->window_end_vpos, last_text_vpos); |
2241 | XSETFASTINT (w->window_end_pos, Z - val.bufpos); | |
a2889657 JB |
2242 | } |
2243 | ||
2244 | /* If scrolling made blank lines at window bottom, | |
2245 | redisplay to fill those lines */ | |
2246 | if (scroll_amount < 0) | |
2247 | { | |
2248 | /* Don't consider these lines for general-purpose scrolling. | |
2249 | That will save time in the scrolling computation. */ | |
44fa5b1e | 2250 | FRAME_SCROLL_BOTTOM_VPOS (f) = xp.vpos; |
a2889657 JB |
2251 | vpos = xp.vpos; |
2252 | pos = xp.bufpos; | |
2253 | val.hpos = lmargin; | |
2254 | if (pos == ZV) | |
2255 | vpos = height + scroll_amount; | |
2256 | else if (xp.contin && xp.hpos != lmargin) | |
2257 | { | |
2258 | val.hpos = xp.prevhpos - width + lmargin; | |
2259 | pos--; | |
2260 | } | |
2261 | ||
2262 | blank_end_of_window = 1; | |
2263 | tab_offset = pos_tab_offset (w, pos); | |
2264 | /* If we are starting display in mid-character, correct tab_offset | |
2265 | to account for passing the line that that character starts in. */ | |
2266 | if (val.hpos < lmargin) | |
2267 | tab_offset += width; | |
2268 | ||
2269 | while (vpos < height) | |
2270 | { | |
2271 | val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset); | |
2272 | tab_offset += width; | |
2273 | if (val.vpos) tab_offset = 0; | |
2274 | pos = val.bufpos; | |
2275 | } | |
2276 | ||
2277 | /* Here is a case where display_text_line sets cursor_vpos wrong. | |
2278 | Make it be fixed up, below. */ | |
2279 | if (xp.bufpos == ZV | |
ae3b1442 | 2280 | && xp.bufpos == PT) |
a2889657 JB |
2281 | cursor_vpos = -1; |
2282 | } | |
2283 | ||
44fa5b1e | 2284 | /* If bottom just moved off end of frame, change mode line percentage. */ |
a2889657 JB |
2285 | if (XFASTINT (w->window_end_pos) == 0 |
2286 | && Z != val.bufpos) | |
2287 | w->update_mode_line = Qt; | |
2288 | ||
2289 | /* Attempt to adjust end-of-text positions to new bottom line */ | |
2290 | if (scroll_amount) | |
2291 | { | |
2292 | delta = height - xp.vpos; | |
2293 | if (delta < 0 | |
2294 | || (delta > 0 && xp.bufpos <= ZV) | |
2295 | || (delta == 0 && xp.hpos)) | |
2296 | { | |
210e752f | 2297 | val = *vmotion (Z - XFASTINT (w->window_end_pos), delta, w); |
c2213350 | 2298 | XSETFASTINT (w->window_end_pos, Z - val.bufpos); |
e8e536a9 KH |
2299 | XSETFASTINT (w->window_end_vpos, |
2300 | XFASTINT (w->window_end_vpos) + val.vpos); | |
a2889657 JB |
2301 | } |
2302 | } | |
2303 | ||
2304 | w->window_end_valid = Qnil; | |
2305 | ||
2306 | /* If point was not in a line that was displayed, find it */ | |
2307 | if (cursor_vpos < 0) | |
2308 | { | |
4d641a15 | 2309 | findpoint: |
ca26e1c8 | 2310 | val = *compute_motion (start, 0, lmargin, 0, PT, 10000, 10000, |
e37f06d7 | 2311 | width, hscroll, pos_tab_offset (w, start), w); |
44fa5b1e | 2312 | /* Admit failure if point is off frame now */ |
a2889657 JB |
2313 | if (val.vpos >= height) |
2314 | { | |
2315 | for (vpos = 0; vpos < height; vpos++) | |
44fa5b1e | 2316 | cancel_line (vpos + top, f); |
a2889657 JB |
2317 | return 0; |
2318 | } | |
2319 | cursor_vpos = val.vpos + top; | |
210e752f | 2320 | cursor_hpos = XFASTINT (w->left) + minmax (0, val.hpos, width); |
a2889657 JB |
2321 | } |
2322 | ||
210e752f | 2323 | FRAME_CURSOR_X (f) = cursor_hpos; |
44fa5b1e | 2324 | FRAME_CURSOR_Y (f) = cursor_vpos; |
a2889657 JB |
2325 | |
2326 | if (debug_end_pos) | |
2327 | { | |
ca26e1c8 | 2328 | val = *compute_motion (start, 0, lmargin, 0, ZV, |
68be917d | 2329 | height, - (1 << (BITS_PER_SHORT - 1)), |
e37f06d7 | 2330 | width, hscroll, pos_tab_offset (w, start), w); |
a2889657 JB |
2331 | if (val.vpos != XFASTINT (w->window_end_vpos)) |
2332 | abort (); | |
2333 | if (XFASTINT (w->window_end_pos) | |
2334 | != Z - val.bufpos) | |
2335 | abort (); | |
2336 | } | |
2337 | ||
2338 | return 1; | |
2339 | } | |
2340 | \f | |
31b24551 JB |
2341 | /* Mark a section of BUF as modified, but only for the sake of redisplay. |
2342 | This is useful for recording changes to overlays. | |
2343 | ||
2344 | We increment the buffer's modification timestamp and set the | |
2345 | redisplay caches (windows_or_buffers_changed, beg_unchanged, etc) | |
2346 | as if the region of text between START and END had been modified; | |
2347 | the redisplay code will check this against the windows' timestamps, | |
2348 | and redraw the appropriate area of the buffer. | |
2349 | ||
2350 | However, if the buffer is unmodified, we bump the last-save | |
2351 | timestamp as well, so that incrementing the timestamp doesn't fool | |
2352 | Emacs into thinking that the buffer's text has been modified. | |
2353 | ||
2354 | Tweaking the timestamps shouldn't hurt the first-modification | |
2355 | timestamps recorded in the undo records; those values aren't | |
2356 | written until just before a real text modification is made, so they | |
2357 | will never catch the timestamp value just before this function gets | |
2358 | called. */ | |
2359 | ||
2360 | void | |
2361 | redisplay_region (buf, start, end) | |
2362 | struct buffer *buf; | |
2363 | int start, end; | |
2364 | { | |
2365 | if (start == end) | |
2366 | return; | |
2367 | ||
2368 | if (start > end) | |
2369 | { | |
2370 | int temp = start; | |
2371 | start = end; end = temp; | |
2372 | } | |
2373 | ||
70bcb498 RS |
2374 | /* If this is a buffer not in the selected window, |
2375 | we must do other windows. */ | |
2376 | if (buf != XBUFFER (XWINDOW (selected_window)->buffer)) | |
2377 | windows_or_buffers_changed = 1; | |
99b9e975 RS |
2378 | /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */ |
2379 | else if (buf != current_buffer) | |
2380 | windows_or_buffers_changed = 1; | |
70bcb498 RS |
2381 | /* If multiple windows show this buffer, we must do other windows. */ |
2382 | else if (buffer_shared > 1) | |
31b24551 JB |
2383 | windows_or_buffers_changed = 1; |
2384 | else | |
2385 | { | |
2386 | if (unchanged_modified == MODIFF) | |
2387 | { | |
2388 | beg_unchanged = start - BEG; | |
2389 | end_unchanged = Z - end; | |
2390 | } | |
2391 | else | |
2392 | { | |
2393 | if (Z - end < end_unchanged) | |
2394 | end_unchanged = Z - end; | |
2395 | if (start - BEG < beg_unchanged) | |
2396 | beg_unchanged = start - BEG; | |
2397 | } | |
2398 | } | |
2399 | ||
2400 | /* Increment the buffer's time stamp, but also increment the save | |
42640f83 RS |
2401 | and autosave timestamps, so as not to screw up that timekeeping. */ |
2402 | if (BUF_MODIFF (buf) == BUF_SAVE_MODIFF (buf)) | |
2403 | BUF_SAVE_MODIFF (buf)++; | |
31b24551 JB |
2404 | if (BUF_MODIFF (buf) == buf->auto_save_modified) |
2405 | buf->auto_save_modified++; | |
2406 | ||
2407 | BUF_MODIFF (buf) ++; | |
2408 | } | |
2409 | ||
2410 | \f | |
278feba9 | 2411 | /* Copy LEN glyphs starting address FROM to the rope TO. |
f7430cb6 | 2412 | But don't actually copy the parts that would come in before S. |
278feba9 RS |
2413 | Value is TO, advanced past the copied data. |
2414 | F is the frame we are displaying in. */ | |
a2889657 | 2415 | |
278feba9 RS |
2416 | static GLYPH * |
2417 | copy_part_of_rope (f, to, s, from, len, face) | |
2418 | FRAME_PTR f; | |
2419 | register GLYPH *to; /* Copy to here. */ | |
a2889657 | 2420 | register GLYPH *s; /* Starting point. */ |
278feba9 RS |
2421 | Lisp_Object *from; /* Data to copy. */ |
2422 | int len; | |
1c2250c2 | 2423 | int face; /* Face to apply to glyphs which don't specify one. */ |
a2889657 | 2424 | { |
278feba9 RS |
2425 | int n = len; |
2426 | register Lisp_Object *fp = from; | |
2427 | /* These cache the results of the last call to compute_glyph_face. */ | |
2428 | int last_code = -1; | |
2429 | int last_merged = 0; | |
c581d710 | 2430 | |
87485d6f | 2431 | #ifdef HAVE_FACES |
4cdc65eb KH |
2432 | if (! FRAME_TERMCAP_P (f)) |
2433 | while (n--) | |
2434 | { | |
dedd1182 | 2435 | int glyph = (INTEGERP (*fp) ? XFASTINT (*fp) : 0); |
4cdc65eb KH |
2436 | int facecode; |
2437 | ||
2438 | if (FAST_GLYPH_FACE (glyph) == 0) | |
2439 | /* If GLYPH has no face code, use FACE. */ | |
2440 | facecode = face; | |
2441 | else if (FAST_GLYPH_FACE (glyph) == last_code) | |
2442 | /* If it's same as previous glyph, use same result. */ | |
2443 | facecode = last_merged; | |
2444 | else | |
2445 | { | |
2446 | /* Merge this glyph's face and remember the result. */ | |
2447 | last_code = FAST_GLYPH_FACE (glyph); | |
2448 | last_merged = facecode = compute_glyph_face (f, last_code, face); | |
2449 | } | |
b2a76982 | 2450 | |
4cdc65eb KH |
2451 | if (to >= s) |
2452 | *to = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), facecode); | |
2453 | ++to; | |
2454 | ++fp; | |
2455 | } | |
2456 | else | |
2457 | #endif | |
2458 | while (n--) | |
2459 | { | |
dedd1182 | 2460 | if (to >= s) *to = (INTEGERP (*fp) ? XFASTINT (*fp) : 0); |
4cdc65eb KH |
2461 | ++to; |
2462 | ++fp; | |
2463 | } | |
278feba9 | 2464 | return to; |
c581d710 RS |
2465 | } |
2466 | ||
278feba9 RS |
2467 | /* Correct a glyph by replacing its specified user-level face code |
2468 | with a displayable computed face code. */ | |
c581d710 | 2469 | |
278feba9 | 2470 | static GLYPH |
659a218f | 2471 | fix_glyph (f, glyph, cface) |
278feba9 RS |
2472 | FRAME_PTR f; |
2473 | GLYPH glyph; | |
659a218f | 2474 | int cface; |
c581d710 | 2475 | { |
87485d6f | 2476 | #ifdef HAVE_FACES |
659a218f KH |
2477 | if (! FRAME_TERMCAP_P (f)) |
2478 | { | |
2479 | if (FAST_GLYPH_FACE (glyph) != 0) | |
2480 | cface = compute_glyph_face (f, FAST_GLYPH_FACE (glyph), cface); | |
2481 | glyph = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), cface); | |
2482 | } | |
4cdc65eb KH |
2483 | #endif |
2484 | return glyph; | |
a2889657 JB |
2485 | } |
2486 | \f | |
f4faa47c JB |
2487 | /* Display one line of window W, starting at position START in W's buffer. |
2488 | ||
2489 | Display starting at horizontal position HPOS, expressed relative to | |
2490 | W's left edge. In situations where the text at START shouldn't | |
2491 | start at the left margin (i.e. when the window is hscrolled, or | |
2492 | we're continuing a line which left off in the midst of a | |
2493 | multi-column character), HPOS should be negative; we throw away | |
2494 | characters up 'til hpos = 0. So, HPOS must take hscrolling into | |
2495 | account. | |
a2889657 JB |
2496 | |
2497 | TABOFFSET is an offset for ostensible hpos, used in tab stop calculations. | |
2498 | ||
f4faa47c JB |
2499 | Display on position VPOS on the frame. It is origin 0, relative to |
2500 | the top of the frame, not W. | |
a2889657 JB |
2501 | |
2502 | Returns a STRUCT POSITION giving character to start next line with | |
2503 | and where to display it, including a zero or negative hpos. | |
2504 | The vpos field is not really a vpos; it is 1 unless the line is continued */ | |
2505 | ||
2506 | struct position val_display_text_line; | |
2507 | ||
2508 | static struct position * | |
2509 | display_text_line (w, start, vpos, hpos, taboffset) | |
2510 | struct window *w; | |
2511 | int start; | |
2512 | int vpos; | |
2513 | int hpos; | |
2514 | int taboffset; | |
2515 | { | |
2516 | register int pos = start; | |
2517 | register int c; | |
2518 | register GLYPH *p1; | |
a2889657 JB |
2519 | register int pause; |
2520 | register unsigned char *p; | |
2521 | GLYPH *endp; | |
d2f84654 | 2522 | register GLYPH *leftmargin; |
ca26e1c8 | 2523 | register GLYPH *p1prev; |
efc63ef0 | 2524 | register GLYPH *p1start; |
ca26e1c8 | 2525 | int prevpos; |
efc63ef0 | 2526 | int *charstart; |
44fa5b1e | 2527 | FRAME_PTR f = XFRAME (w->frame); |
a2889657 | 2528 | int tab_width = XINT (current_buffer->tab_width); |
265a9e55 | 2529 | int ctl_arrow = !NILP (current_buffer->ctl_arrow); |
b1d1124b | 2530 | int width = window_internal_width (w) - 1; |
a2889657 JB |
2531 | struct position val; |
2532 | int lastpos; | |
2533 | int invis; | |
642eefc6 RS |
2534 | int last_invis_skip = 0; |
2535 | Lisp_Object last_invis_prop; | |
a2889657 | 2536 | int hscroll = XINT (w->hscroll); |
d2f84654 RS |
2537 | int truncate = (hscroll |
2538 | || (truncate_partial_width_windows | |
2539 | && XFASTINT (w->width) < FRAME_WIDTH (f)) | |
2540 | || !NILP (current_buffer->truncate_lines)); | |
bd66d1ba RS |
2541 | |
2542 | /* 1 if we should highlight the region. */ | |
2543 | int highlight_region | |
2544 | = !NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active); | |
2545 | int region_beg, region_end; | |
2546 | ||
e24c997d KH |
2547 | int selective = (INTEGERP (current_buffer->selective_display) |
2548 | ? XINT (current_buffer->selective_display) | |
2549 | : !NILP (current_buffer->selective_display) ? -1 : 0); | |
44fa5b1e | 2550 | register struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f); |
f908610f | 2551 | register struct Lisp_Char_Table *dp = window_display_table (w); |
68a37fa8 RS |
2552 | |
2553 | Lisp_Object default_invis_vector[3]; | |
642eefc6 RS |
2554 | /* Number of characters of ellipsis to display after an invisible line |
2555 | if it calls for an ellipsis. | |
2556 | Note that this value can be nonzero regardless of whether | |
2557 | selective display is enabled--you must check that separately. */ | |
a2889657 | 2558 | int selective_rlen |
642eefc6 | 2559 | = (dp && VECTORP (DISP_INVIS_VECTOR (dp)) |
68a37fa8 | 2560 | ? XVECTOR (DISP_INVIS_VECTOR (dp))->size |
642eefc6 | 2561 | : !NILP (current_buffer->selective_display_ellipses) ? 3 : 0); |
68a37fa8 RS |
2562 | /* This is the sequence of Lisp objects to display |
2563 | when there are invisible lines. */ | |
2564 | Lisp_Object *invis_vector_contents | |
e24c997d | 2565 | = (dp && VECTORP (DISP_INVIS_VECTOR (dp)) |
68a37fa8 RS |
2566 | ? XVECTOR (DISP_INVIS_VECTOR (dp))->contents |
2567 | : default_invis_vector); | |
2568 | ||
e24c997d | 2569 | GLYPH truncator = (dp == 0 || !INTEGERP (DISP_TRUNC_GLYPH (dp)) |
278feba9 | 2570 | ? '$' : XINT (DISP_TRUNC_GLYPH (dp))); |
e24c997d | 2571 | GLYPH continuer = (dp == 0 || !INTEGERP (DISP_CONTINUE_GLYPH (dp)) |
278feba9 | 2572 | ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp))); |
a2889657 | 2573 | |
31b24551 JB |
2574 | /* The next buffer location at which the face should change, due |
2575 | to overlays or text property changes. */ | |
2576 | int next_face_change; | |
2577 | ||
ca26e1c8 KH |
2578 | /* The next location where the `invisible' property changes, or an |
2579 | overlay starts or ends. */ | |
2580 | int next_boundary; | |
2581 | ||
31b24551 | 2582 | /* The face we're currently using. */ |
1c2250c2 | 2583 | int current_face = 0; |
efc63ef0 | 2584 | int i; |
31b24551 | 2585 | |
c2213350 | 2586 | XSETFASTINT (default_invis_vector[2], '.'); |
68a37fa8 RS |
2587 | default_invis_vector[0] = default_invis_vector[1] = default_invis_vector[2]; |
2588 | ||
a2889657 | 2589 | hpos += XFASTINT (w->left); |
44fa5b1e | 2590 | get_display_line (f, vpos, XFASTINT (w->left)); |
54ff581a | 2591 | if (tab_width <= 0 || tab_width > 1000) tab_width = 8; |
a2889657 | 2592 | |
bd66d1ba | 2593 | /* Show where to highlight the region. */ |
1613b757 | 2594 | if (highlight_region && XMARKER (current_buffer->mark)->buffer != 0 |
fba9ce76 RS |
2595 | /* Maybe highlight only in selected window. */ |
2596 | && (highlight_nonselected_windows | |
6f139a45 | 2597 | || w == XWINDOW (selected_window))) |
bd66d1ba RS |
2598 | { |
2599 | region_beg = marker_position (current_buffer->mark); | |
2600 | if (PT < region_beg) | |
2601 | { | |
2602 | region_end = region_beg; | |
2603 | region_beg = PT; | |
2604 | } | |
2605 | else | |
2606 | region_end = PT; | |
2607 | w->region_showing = Qt; | |
2608 | } | |
2609 | else | |
2610 | region_beg = region_end = -1; | |
2611 | ||
f4faa47c | 2612 | if (MINI_WINDOW_P (w) |
ca26e1c8 | 2613 | && start == BEG |
a2889657 JB |
2614 | && vpos == XFASTINT (w->top)) |
2615 | { | |
8c5b6a0a | 2616 | if (! NILP (minibuf_prompt)) |
f7b4b63a KH |
2617 | { |
2618 | minibuf_prompt_width | |
8c5b6a0a KH |
2619 | = (display_string (w, vpos, XSTRING (minibuf_prompt)->data, |
2620 | XSTRING (minibuf_prompt)->size, hpos, | |
ce006f69 RS |
2621 | /* Display a space if we truncate. */ |
2622 | ' ', | |
2623 | 1, -1, | |
2624 | /* Truncate the prompt a little before the | |
2625 | margin, so user input can at least start | |
2626 | on the first line. */ | |
2627 | w->width > 10 ? w->width - 4 : -1) | |
f7b4b63a KH |
2628 | - hpos); |
2629 | hpos += minibuf_prompt_width; | |
2b050fec | 2630 | taboffset -= minibuf_prompt_width; |
f7b4b63a KH |
2631 | } |
2632 | else | |
2633 | minibuf_prompt_width = 0; | |
a2889657 JB |
2634 | } |
2635 | ||
f4faa47c JB |
2636 | /* If we're hscrolled at all, use compute_motion to skip over any |
2637 | text off the left edge of the window. compute_motion may know | |
2638 | tricks to do this faster than we can. */ | |
2639 | if (hpos < 0) | |
2640 | { | |
2641 | struct position *left_edge | |
ca26e1c8 KH |
2642 | = compute_motion (pos, vpos, hpos, 0, |
2643 | ZV, vpos, 0, | |
f4faa47c JB |
2644 | width, hscroll, taboffset, w); |
2645 | ||
2646 | /* Retrieve the buffer position and column provided by | |
2647 | compute_motion. We can't assume that the column will be | |
2648 | zero, because you may have multi-column characters crossing | |
2649 | the left margin. | |
2650 | ||
2651 | compute_motion may have moved us past the screen position we | |
2652 | requested, if we hit a multi-column character, or the end of | |
2653 | the line. If so, back up. */ | |
2654 | if (left_edge->vpos > vpos | |
2655 | || left_edge->hpos > 0) | |
2656 | { | |
2657 | pos = left_edge->bufpos - 1; | |
2658 | hpos = left_edge->prevhpos; | |
2659 | } | |
2660 | else | |
2661 | { | |
2662 | pos = left_edge->bufpos; | |
2663 | hpos = left_edge->hpos; | |
2664 | } | |
2665 | } | |
2666 | ||
2667 | desired_glyphs->bufp[vpos] = start; | |
a2889657 | 2668 | p1 = desired_glyphs->glyphs[vpos] + hpos; |
efc63ef0 RS |
2669 | p1start = p1; |
2670 | charstart = desired_glyphs->charstarts[vpos] + hpos; | |
2671 | /* In case we don't ever write anything into it... */ | |
a007eef6 | 2672 | desired_glyphs->charstarts[vpos][XFASTINT (w->left)] = -1; |
d2f84654 RS |
2673 | leftmargin = desired_glyphs->glyphs[vpos] + XFASTINT (w->left); |
2674 | endp = leftmargin + width; | |
a2889657 | 2675 | |
1c2250c2 JB |
2676 | /* Arrange the overlays nicely for our purposes. Usually, we call |
2677 | display_text_line on only one line at a time, in which case this | |
2678 | can't really hurt too much, or we call it on lines which appear | |
2679 | one after another in the buffer, in which case all calls to | |
2680 | recenter_overlay_lists but the first will be pretty cheap. */ | |
2681 | recenter_overlay_lists (current_buffer, pos); | |
2682 | ||
a2889657 JB |
2683 | /* Loop generating characters. |
2684 | Stop at end of buffer, before newline, | |
31b24551 JB |
2685 | if reach or pass continuation column, |
2686 | or at face change. */ | |
a2889657 | 2687 | pause = pos; |
31b24551 | 2688 | next_face_change = pos; |
ca26e1c8 KH |
2689 | next_boundary = pos; |
2690 | p1prev = p1; | |
2691 | prevpos = pos; | |
85bcef6c | 2692 | while (1) |
a2889657 | 2693 | { |
31b24551 | 2694 | if (pos >= pause) |
a2889657 | 2695 | { |
67481ae5 RS |
2696 | int e_t_h; |
2697 | ||
ca26e1c8 | 2698 | while (pos == next_boundary) |
a2889657 | 2699 | { |
ca26e1c8 KH |
2700 | Lisp_Object position, limit, prop, ww; |
2701 | ||
2702 | /* Display the overlay strings here, unless we're at ZV | |
2703 | and have already displayed the appropriate strings | |
2704 | on an earlier line. */ | |
2705 | if (pos < ZV || !zv_strings_seen++) | |
2706 | { | |
2707 | int ovlen; | |
2708 | char *ovstr; | |
2709 | ovlen = overlay_strings (pos, w, &ovstr); | |
2710 | for (; ovlen; ovlen--, ovstr++) | |
2711 | { | |
2712 | if (p1 >= leftmargin && p1 < endp) | |
2713 | *p1 = MAKE_GLYPH (f, *ovstr, current_face); | |
2714 | p1++; | |
2715 | } | |
2716 | } | |
2717 | ||
2718 | /* Did we reach point? Record the cursor location. */ | |
2719 | if (pos == PT && cursor_vpos < 0) | |
2720 | { | |
2721 | cursor_vpos = vpos; | |
2722 | cursor_hpos = p1 - leftmargin; | |
2723 | } | |
2724 | ||
2725 | if (pos >= ZV) | |
2726 | break; | |
a2889657 | 2727 | |
c2213350 | 2728 | XSETFASTINT (position, pos); |
ca26e1c8 KH |
2729 | limit = Fnext_overlay_change (position); |
2730 | #ifdef USE_TEXT_PROPERTIES | |
dfabd9a0 RS |
2731 | /* This is just an estimate to give reasonable |
2732 | performance; nothing should go wrong if it is too small. */ | |
fe3d6921 | 2733 | if (XFASTINT (limit) > pos + 50) |
c2213350 | 2734 | XSETFASTINT (limit, pos + 50); |
ca26e1c8 KH |
2735 | limit = Fnext_single_property_change (position, Qinvisible, |
2736 | Fcurrent_buffer (), limit); | |
2737 | #endif | |
2738 | next_boundary = XFASTINT (limit); | |
2739 | /* if the `invisible' property is set, we can skip to | |
2740 | the next property change. */ | |
2741 | XSETWINDOW (ww, w); | |
2742 | prop = Fget_char_property (position, Qinvisible, ww); | |
642eefc6 | 2743 | if (TEXT_PROP_MEANS_INVISIBLE (prop)) |
dfabd9a0 | 2744 | { |
ca26e1c8 | 2745 | if (pos < PT && next_boundary >= PT) |
dfabd9a0 RS |
2746 | { |
2747 | cursor_vpos = vpos; | |
d2f84654 | 2748 | cursor_hpos = p1 - leftmargin; |
dfabd9a0 | 2749 | } |
ca26e1c8 | 2750 | pos = next_boundary; |
642eefc6 RS |
2751 | last_invis_skip = pos; |
2752 | last_invis_prop = prop; | |
dfabd9a0 | 2753 | } |
b0a0fbda | 2754 | } |
ca26e1c8 KH |
2755 | |
2756 | /* Did we reach point? Record the cursor location. */ | |
2757 | if (pos == PT && cursor_vpos < 0) | |
2758 | { | |
2759 | cursor_vpos = vpos; | |
2760 | cursor_hpos = p1 - leftmargin; | |
2761 | } | |
2762 | ||
2763 | /* Did we hit the end of the visible region of the buffer? | |
2764 | Stop here. */ | |
2765 | if (pos >= ZV) | |
eff87c2c RS |
2766 | { |
2767 | /* Update charstarts for the end of this line. */ | |
2768 | /* Do nothing if off the left edge or at the right edge. */ | |
2769 | if (p1 >= leftmargin && p1 + 1 != endp) | |
2770 | { | |
2771 | int *p2x = &charstart[(p1 < leftmargin | |
2772 | ? leftmargin : p1) | |
2773 | - p1start]; | |
2774 | *p2x++ = pos; | |
2775 | } | |
2776 | break; | |
2777 | } | |
b0a0fbda | 2778 | |
67481ae5 RS |
2779 | /* Figure out where (if at all) the |
2780 | redisplay_end_trigger-hook should run. */ | |
f6fd109b RS |
2781 | if (MARKERP (w->redisplay_end_trigger) |
2782 | && XMARKER (w->redisplay_end_trigger)->buffer != 0) | |
d3413a53 RS |
2783 | e_t_h = marker_position (w->redisplay_end_trigger); |
2784 | else if (INTEGERP (w->redisplay_end_trigger)) | |
2785 | e_t_h = XINT (w->redisplay_end_trigger); | |
67481ae5 RS |
2786 | else |
2787 | e_t_h = ZV; | |
2788 | ||
2789 | /* If we've gone past the place to run a hook, | |
2790 | run the hook. */ | |
2791 | if (pos >= e_t_h && e_t_h != ZV) | |
2792 | { | |
e0bfbde6 RS |
2793 | Lisp_Object args[3]; |
2794 | ||
2795 | args[0] = Qredisplay_end_trigger_functions; | |
2796 | XSETWINDOW (args[1], w); | |
2797 | XSETINT (args[2], e_t_h); | |
e0bfbde6 | 2798 | |
9c49d3d7 KH |
2799 | /* Since we are *trying* to run these functions, |
2800 | don't try to run them again, even if they get an error. */ | |
d3413a53 | 2801 | w->redisplay_end_trigger = Qnil; |
9c49d3d7 KH |
2802 | Frun_hook_with_args (3, args); |
2803 | ||
67481ae5 | 2804 | e_t_h = ZV; |
f6fd109b RS |
2805 | /* Notice if it changed the face of this character. */ |
2806 | next_face_change = pos; | |
67481ae5 RS |
2807 | } |
2808 | ||
f6fd109b RS |
2809 | #ifdef HAVE_FACES |
2810 | /* Did we hit a face change? Figure out what face we should | |
2811 | use now. We also hit this the first time through the | |
2812 | loop, to see what face we should start with. */ | |
2813 | if (pos >= next_face_change && (FRAME_WINDOW_P (f))) | |
2814 | current_face = compute_char_face (f, w, pos, | |
2815 | region_beg, region_end, | |
2816 | &next_face_change, pos + 50, 0); | |
2817 | #endif | |
2818 | ||
67481ae5 RS |
2819 | /* Compute the next place we need to stop |
2820 | and do something special; set PAUSE. */ | |
2821 | ||
ca26e1c8 | 2822 | pause = ZV; |
1c2250c2 | 2823 | |
ca26e1c8 KH |
2824 | if (pos < next_boundary && next_boundary < pause) |
2825 | pause = next_boundary; | |
1c2250c2 JB |
2826 | if (pos < next_face_change && next_face_change < pause) |
2827 | pause = next_face_change; | |
2828 | ||
67481ae5 RS |
2829 | if (e_t_h < pause) |
2830 | pause = e_t_h; | |
2831 | ||
31b24551 JB |
2832 | /* Wouldn't you hate to read the next line to someone over |
2833 | the phone? */ | |
ae3b1442 KH |
2834 | if (pos < PT && PT < pause) |
2835 | pause = PT; | |
a2889657 JB |
2836 | if (pos < GPT && GPT < pause) |
2837 | pause = GPT; | |
2838 | ||
2839 | p = &FETCH_CHAR (pos); | |
2840 | } | |
ca26e1c8 | 2841 | |
ca26e1c8 KH |
2842 | if (p1 >= endp) |
2843 | break; | |
2844 | ||
2845 | p1prev = p1; | |
2846 | ||
a2889657 | 2847 | c = *p++; |
376b0e59 RS |
2848 | /* Let a display table override all standard display methods. */ |
2849 | if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c))) | |
2850 | { | |
2851 | p1 = copy_part_of_rope (f, p1, leftmargin, | |
2852 | XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents, | |
2853 | XVECTOR (DISP_CHAR_VECTOR (dp, c))->size, | |
2854 | current_face); | |
2855 | } | |
2856 | else if (c >= 040 && c < 0177) | |
a2889657 | 2857 | { |
d2f84654 | 2858 | if (p1 >= leftmargin) |
4cdc65eb | 2859 | *p1 = MAKE_GLYPH (f, c, current_face); |
a2889657 JB |
2860 | p1++; |
2861 | } | |
2862 | else if (c == '\n') | |
2863 | { | |
2864 | invis = 0; | |
642eefc6 RS |
2865 | if (last_invis_skip == pos |
2866 | && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (last_invis_prop)) | |
2867 | invis = 1; | |
ca26e1c8 | 2868 | while (pos + 1 < ZV |
a2889657 | 2869 | && selective > 0 |
9f412332 | 2870 | && indented_beyond_p (pos + 1, selective)) |
a2889657 JB |
2871 | { |
2872 | invis = 1; | |
2873 | pos = find_next_newline (pos + 1, 1); | |
2874 | if (FETCH_CHAR (pos - 1) == '\n') | |
2875 | pos--; | |
2876 | } | |
d2f84654 | 2877 | if (invis && selective_rlen > 0 && p1 >= leftmargin) |
a2889657 JB |
2878 | { |
2879 | p1 += selective_rlen; | |
d2f84654 | 2880 | if (p1 - leftmargin > width) |
a2889657 | 2881 | p1 = endp; |
278feba9 | 2882 | copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents, |
1c2250c2 | 2883 | (p1 - p1prev), current_face); |
a2889657 | 2884 | } |
87485d6f | 2885 | #ifdef HAVE_FACES |
3c5c35c5 JB |
2886 | /* Draw the face of the newline character as extending all the |
2887 | way to the end of the frame line. */ | |
2888 | if (current_face) | |
1105ff20 KH |
2889 | { |
2890 | if (p1 < leftmargin) | |
2891 | p1 = leftmargin; | |
2892 | while (p1 < endp) | |
2893 | *p1++ = FAST_MAKE_GLYPH (' ', current_face); | |
2894 | } | |
3c5c35c5 | 2895 | #endif |
545e04f6 KH |
2896 | |
2897 | /* Update charstarts for the newline that ended this line. */ | |
2898 | /* Do nothing here for a char that's entirely off the left edge | |
2899 | or if it starts at the right edge. */ | |
2900 | if (p1 >= leftmargin && p1prev != endp) | |
2901 | { | |
2902 | /* Store the newline's position into charstarts | |
2903 | for the column where the newline starts. | |
2904 | Store -1 for the rest of the glyphs it occupies. */ | |
2905 | int *p2x = &charstart[(p1prev < leftmargin | |
2906 | ? leftmargin : p1prev) | |
2907 | - p1start]; | |
2908 | int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start]; | |
2909 | ||
2910 | *p2x++ = pos; | |
2911 | while (p2x < p2) | |
2912 | *p2x++ = -1; | |
2913 | } | |
2914 | ||
68a37fa8 | 2915 | break; |
a2889657 JB |
2916 | } |
2917 | else if (c == '\t') | |
2918 | { | |
2919 | do | |
2920 | { | |
d2f84654 | 2921 | if (p1 >= leftmargin && p1 < endp) |
4cdc65eb | 2922 | *p1 = MAKE_GLYPH (f, ' ', current_face); |
a2889657 JB |
2923 | p1++; |
2924 | } | |
d2f84654 | 2925 | while ((p1 - leftmargin + taboffset + hscroll - (hscroll > 0)) |
a2889657 JB |
2926 | % tab_width); |
2927 | } | |
6e8290aa | 2928 | else if (c == Ctl ('M') && selective == -1) |
a2889657 JB |
2929 | { |
2930 | pos = find_next_newline (pos, 1); | |
2931 | if (FETCH_CHAR (pos - 1) == '\n') | |
2932 | pos--; | |
2933 | if (selective_rlen > 0) | |
2934 | { | |
2935 | p1 += selective_rlen; | |
d2f84654 | 2936 | if (p1 - leftmargin > width) |
a2889657 | 2937 | p1 = endp; |
278feba9 | 2938 | copy_part_of_rope (f, p1prev, p1prev, invis_vector_contents, |
1c2250c2 | 2939 | (p1 - p1prev), current_face); |
a2889657 | 2940 | } |
87485d6f | 2941 | #ifdef HAVE_FACES |
3c5c35c5 JB |
2942 | /* Draw the face of the newline character as extending all the |
2943 | way to the end of the frame line. */ | |
2944 | if (current_face) | |
1105ff20 KH |
2945 | { |
2946 | if (p1 < leftmargin) | |
2947 | p1 = leftmargin; | |
2948 | while (p1 < endp) | |
2949 | *p1++ = FAST_MAKE_GLYPH (' ', current_face); | |
2950 | } | |
3c5c35c5 | 2951 | #endif |
545e04f6 KH |
2952 | |
2953 | /* Update charstarts for the ^M that ended this line. */ | |
2954 | /* Do nothing here for a char that's entirely off the left edge | |
2955 | or if it starts at the right edge. */ | |
2956 | if (p1 >= leftmargin && p1prev != endp) | |
2957 | { | |
2958 | /* Store the newline's position into charstarts | |
2959 | for the column where the newline starts. | |
2960 | Store -1 for the rest of the glyphs it occupies. */ | |
2961 | int *p2x = &charstart[(p1prev < leftmargin | |
2962 | ? leftmargin : p1prev) | |
2963 | - p1start]; | |
2964 | int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start]; | |
2965 | ||
2966 | *p2x++ = pos; | |
2967 | while (p2x < p2) | |
2968 | *p2x++ = -1; | |
2969 | } | |
68a37fa8 | 2970 | break; |
a2889657 | 2971 | } |
a2889657 JB |
2972 | else if (c < 0200 && ctl_arrow) |
2973 | { | |
d2f84654 | 2974 | if (p1 >= leftmargin) |
e24c997d | 2975 | *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp)) |
278feba9 RS |
2976 | ? XINT (DISP_CTRL_GLYPH (dp)) : '^'), |
2977 | current_face); | |
a2889657 | 2978 | p1++; |
d2f84654 | 2979 | if (p1 >= leftmargin && p1 < endp) |
4cdc65eb | 2980 | *p1 = MAKE_GLYPH (f, c ^ 0100, current_face); |
a2889657 JB |
2981 | p1++; |
2982 | } | |
2983 | else | |
2984 | { | |
d2f84654 | 2985 | if (p1 >= leftmargin) |
e24c997d | 2986 | *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp)) |
278feba9 RS |
2987 | ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'), |
2988 | current_face); | |
a2889657 | 2989 | p1++; |
d2f84654 | 2990 | if (p1 >= leftmargin && p1 < endp) |
4cdc65eb | 2991 | *p1 = MAKE_GLYPH (f, (c >> 6) + '0', current_face); |
a2889657 | 2992 | p1++; |
d2f84654 | 2993 | if (p1 >= leftmargin && p1 < endp) |
4cdc65eb | 2994 | *p1 = MAKE_GLYPH (f, (7 & (c >> 3)) + '0', current_face); |
a2889657 | 2995 | p1++; |
d2f84654 | 2996 | if (p1 >= leftmargin && p1 < endp) |
4cdc65eb | 2997 | *p1 = MAKE_GLYPH (f, (7 & c) + '0', current_face); |
a2889657 JB |
2998 | p1++; |
2999 | } | |
31b24551 | 3000 | |
ca26e1c8 | 3001 | prevpos = pos; |
a2889657 | 3002 | pos++; |
545e04f6 KH |
3003 | |
3004 | /* Update charstarts for the character just output. */ | |
3005 | ||
3006 | /* Do nothing here for a char that's entirely off the left edge. */ | |
3007 | if (p1 >= leftmargin) | |
3008 | { | |
3009 | /* Store the char's position into charstarts | |
3010 | for the first glyph occupied by this char. | |
3011 | Store -1 for the rest of the glyphs it occupies. */ | |
3012 | if (p1 != p1prev) | |
3013 | { | |
3014 | int *p2x = &charstart[(p1prev < leftmargin | |
3015 | ? leftmargin : p1prev) | |
3016 | - p1start]; | |
3017 | int *p2 = &charstart[(p1 < endp ? p1 : endp) - p1start]; | |
3018 | ||
3019 | if (p2x < p2) | |
3020 | *p2x++ = prevpos; | |
3021 | while (p2x < p2) | |
3022 | *p2x++ = -1; | |
3023 | } | |
3024 | } | |
a2889657 JB |
3025 | } |
3026 | ||
3027 | val.hpos = - XINT (w->hscroll); | |
3028 | if (val.hpos) | |
3029 | val.hpos++; | |
3030 | ||
3031 | val.vpos = 1; | |
3032 | ||
3033 | lastpos = pos; | |
3034 | ||
efc63ef0 RS |
3035 | /* Store 0 in this charstart line for the positions where |
3036 | there is no character. But do leave what was recorded | |
3037 | for the character that ended the line. */ | |
85bcef6c RS |
3038 | /* Add 1 in the endtest to compensate for the fact that ENDP was |
3039 | made from WIDTH, which is 1 less than the window's actual | |
3040 | internal width. */ | |
a007eef6 RS |
3041 | i = p1 - p1start + 1; |
3042 | if (p1 < leftmargin) | |
3043 | i += leftmargin - p1; | |
3044 | for (; i < endp - p1start + 1; i++) | |
efc63ef0 RS |
3045 | charstart[i] = 0; |
3046 | ||
a2889657 JB |
3047 | /* Handle continuation in middle of a character */ |
3048 | /* by backing up over it */ | |
3049 | if (p1 > endp) | |
3050 | { | |
5fcbb24d JB |
3051 | /* Don't back up if we never actually displayed any text. |
3052 | This occurs when the minibuffer prompt takes up the whole line. */ | |
3053 | if (p1prev) | |
3054 | { | |
3055 | /* Start the next line with that same character */ | |
3056 | pos--; | |
3057 | /* but at negative hpos, to skip the columns output on this line. */ | |
3058 | val.hpos += p1prev - endp; | |
3059 | } | |
3060 | ||
a2889657 JB |
3061 | /* Keep in this line everything up to the continuation column. */ |
3062 | p1 = endp; | |
3063 | } | |
3064 | ||
3065 | /* Finish deciding which character to start the next line on, | |
3066 | and what hpos to start it at. | |
3067 | Also set `lastpos' to the last position which counts as "on this line" | |
3068 | for cursor-positioning. */ | |
3069 | ||
3070 | if (pos < ZV) | |
3071 | { | |
3072 | if (FETCH_CHAR (pos) == '\n') | |
dd5f6267 KH |
3073 | { |
3074 | /* If stopped due to a newline, start next line after it */ | |
3075 | pos++; | |
3076 | /* Check again for hidden lines, in case the newline occurred exactly | |
3077 | at the right margin. */ | |
3078 | while (pos < ZV && selective > 0 | |
3079 | && indented_beyond_p (pos, selective)) | |
3080 | pos = find_next_newline (pos, 1); | |
3081 | } | |
a2889657 JB |
3082 | else |
3083 | /* Stopped due to right margin of window */ | |
3084 | { | |
3085 | if (truncate) | |
3086 | { | |
278feba9 | 3087 | *p1++ = fix_glyph (f, truncator, 0); |
a2889657 JB |
3088 | /* Truncating => start next line after next newline, |
3089 | and point is on this line if it is before the newline, | |
3090 | and skip none of first char of next line */ | |
dd5f6267 KH |
3091 | do |
3092 | pos = find_next_newline (pos, 1); | |
3093 | while (pos < ZV && selective > 0 | |
3094 | && indented_beyond_p (pos, selective)); | |
a2889657 JB |
3095 | val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0; |
3096 | ||
3097 | lastpos = pos - (FETCH_CHAR (pos - 1) == '\n'); | |
3098 | } | |
3099 | else | |
3100 | { | |
278feba9 | 3101 | *p1++ = fix_glyph (f, continuer, 0); |
a2889657 JB |
3102 | val.vpos = 0; |
3103 | lastpos--; | |
3104 | } | |
3105 | } | |
3106 | } | |
3107 | ||
3108 | /* If point is at eol or in invisible text at eol, | |
44fa5b1e | 3109 | record its frame location now. */ |
a2889657 | 3110 | |
ae3b1442 | 3111 | if (start <= PT && PT <= lastpos && cursor_vpos < 0) |
a2889657 JB |
3112 | { |
3113 | cursor_vpos = vpos; | |
d2f84654 | 3114 | cursor_hpos = p1 - leftmargin; |
a2889657 JB |
3115 | } |
3116 | ||
3117 | if (cursor_vpos == vpos) | |
3118 | { | |
3119 | if (cursor_hpos < 0) cursor_hpos = 0; | |
3120 | if (cursor_hpos > width) cursor_hpos = width; | |
3121 | cursor_hpos += XFASTINT (w->left); | |
44fa5b1e | 3122 | if (w == XWINDOW (FRAME_SELECTED_WINDOW (f))) |
a2889657 | 3123 | { |
b5bbc9a5 KH |
3124 | if (!(cursor_in_echo_area && FRAME_HAS_MINIBUF_P (f) |
3125 | && EQ (FRAME_MINIBUF_WINDOW (f), minibuf_window))) | |
3126 | { | |
3127 | FRAME_CURSOR_Y (f) = cursor_vpos; | |
3128 | FRAME_CURSOR_X (f) = cursor_hpos; | |
3129 | } | |
a2889657 JB |
3130 | |
3131 | if (w == XWINDOW (selected_window)) | |
3132 | { | |
3133 | /* Line is not continued and did not start | |
3134 | in middle of character */ | |
3135 | if ((hpos - XFASTINT (w->left) | |
3136 | == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0)) | |
3137 | && val.vpos) | |
3138 | { | |
3139 | this_line_bufpos = start; | |
3140 | this_line_buffer = current_buffer; | |
3141 | this_line_vpos = cursor_vpos; | |
3142 | this_line_start_hpos = hpos; | |
3143 | this_line_endpos = Z - lastpos; | |
3144 | } | |
3145 | else | |
3146 | this_line_bufpos = 0; | |
3147 | } | |
3148 | } | |
3149 | } | |
3150 | ||
3151 | /* If hscroll and line not empty, insert truncation-at-left marker */ | |
3152 | if (hscroll && lastpos != start) | |
3153 | { | |
d2f84654 RS |
3154 | *leftmargin = fix_glyph (f, truncator, 0); |
3155 | if (p1 <= leftmargin) | |
3156 | p1 = leftmargin + 1; | |
a2889657 JB |
3157 | } |
3158 | ||
44fa5b1e | 3159 | if (XFASTINT (w->width) + XFASTINT (w->left) != FRAME_WIDTH (f)) |
a2889657 JB |
3160 | { |
3161 | endp++; | |
d2f84654 | 3162 | if (p1 < leftmargin) p1 = leftmargin; |
a2889657 | 3163 | while (p1 < endp) *p1++ = SPACEGLYPH; |
b1d1124b | 3164 | |
88f22aff JB |
3165 | /* Don't draw vertical bars if we're using scroll bars. They're |
3166 | covered up by the scroll bars, and it's distracting to see | |
3167 | them when the scroll bar windows are flickering around to be | |
b1d1124b | 3168 | reconfigured. */ |
75d13c64 KH |
3169 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
3170 | { | |
3171 | int i; | |
3172 | for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++) | |
3173 | *p1++ = SPACEGLYPH; | |
3174 | } | |
3175 | else | |
3176 | *p1++ = (dp && INTEGERP (DISP_BORDER_GLYPH (dp)) | |
3177 | ? DISP_BORDER_GLYPH (dp) | |
3178 | : '|'); | |
a2889657 JB |
3179 | } |
3180 | desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos], | |
3181 | p1 - desired_glyphs->glyphs[vpos]); | |
3182 | desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0; | |
3183 | ||
3184 | /* If the start of this line is the overlay arrow-position, | |
3185 | then put the arrow string into the display-line. */ | |
3186 | ||
e24c997d | 3187 | if (MARKERP (Voverlay_arrow_position) |
a2889657 JB |
3188 | && current_buffer == XMARKER (Voverlay_arrow_position)->buffer |
3189 | && start == marker_position (Voverlay_arrow_position) | |
e24c997d | 3190 | && STRINGP (Voverlay_arrow_string) |
a2889657 JB |
3191 | && ! overlay_arrow_seen) |
3192 | { | |
3193 | unsigned char *p = XSTRING (Voverlay_arrow_string)->data; | |
3194 | int i; | |
3195 | int len = XSTRING (Voverlay_arrow_string)->size; | |
142be3dd | 3196 | int arrow_end; |
a2889657 | 3197 | |
b1d1124b JB |
3198 | if (len > width) |
3199 | len = width; | |
87485d6f | 3200 | #ifdef HAVE_FACES |
c4628384 RS |
3201 | if (!NULL_INTERVAL_P (XSTRING (Voverlay_arrow_string)->intervals)) |
3202 | { | |
3203 | /* If the arrow string has text props, obey them when displaying. */ | |
3204 | for (i = 0; i < len; i++) | |
3205 | { | |
3206 | int c = p[i]; | |
3207 | Lisp_Object face, ilisp; | |
3208 | int newface; | |
3209 | ||
c2213350 | 3210 | XSETFASTINT (ilisp, i); |
c4628384 RS |
3211 | face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string); |
3212 | newface = compute_glyph_face_1 (f, face, 0); | |
3213 | leftmargin[i] = FAST_MAKE_GLYPH (c, newface); | |
3214 | } | |
3215 | } | |
3216 | else | |
87485d6f | 3217 | #endif /* HAVE_FACES */ |
c4628384 RS |
3218 | { |
3219 | for (i = 0; i < len; i++) | |
3220 | leftmargin[i] = p[i]; | |
3221 | } | |
142be3dd JB |
3222 | |
3223 | /* Bug in SunOS 4.1.1 compiler requires this intermediate variable. */ | |
d2f84654 | 3224 | arrow_end = (leftmargin - desired_glyphs->glyphs[vpos]) + len; |
142be3dd JB |
3225 | if (desired_glyphs->used[vpos] < arrow_end) |
3226 | desired_glyphs->used[vpos] = arrow_end; | |
a2889657 JB |
3227 | |
3228 | overlay_arrow_seen = 1; | |
3229 | } | |
3230 | ||
3231 | val.bufpos = pos; | |
3232 | val_display_text_line = val; | |
3233 | return &val_display_text_line; | |
3234 | } | |
3235 | \f | |
7ce2c095 RS |
3236 | /* Redisplay the menu bar in the frame for window W. */ |
3237 | ||
3238 | static void | |
3239 | display_menu_bar (w) | |
3240 | struct window *w; | |
3241 | { | |
3242 | Lisp_Object items, tail; | |
3243 | register int vpos = 0; | |
3244 | register FRAME_PTR f = XFRAME (WINDOW_FRAME (w)); | |
3245 | int maxendcol = FRAME_WIDTH (f); | |
3246 | int hpos = 0; | |
8351baf2 | 3247 | int i; |
7ce2c095 | 3248 | |
dc937613 RS |
3249 | #ifdef HAVE_NTGUI |
3250 | return; | |
3251 | #endif | |
3252 | ||
3253 | #ifdef USE_X_TOOLKIT | |
d3413a53 | 3254 | if (FRAME_X_P (f)) |
7ce2c095 | 3255 | return; |
dc937613 | 3256 | #endif /* USE_X_TOOLKIT */ |
7ce2c095 RS |
3257 | |
3258 | get_display_line (f, vpos, 0); | |
3259 | ||
8351baf2 RS |
3260 | items = FRAME_MENU_BAR_ITEMS (f); |
3261 | for (i = 0; i < XVECTOR (items)->size; i += 3) | |
7ce2c095 | 3262 | { |
8351baf2 RS |
3263 | Lisp_Object pos, string; |
3264 | string = XVECTOR (items)->contents[i + 1]; | |
3265 | if (NILP (string)) | |
3266 | break; | |
2d66ad19 | 3267 | |
c2213350 | 3268 | XSETFASTINT (XVECTOR (items)->contents[i + 2], hpos); |
7ce2c095 RS |
3269 | |
3270 | if (hpos < maxendcol) | |
3271 | hpos = display_string (XWINDOW (FRAME_ROOT_WINDOW (f)), vpos, | |
3272 | XSTRING (string)->data, | |
90adcf20 | 3273 | XSTRING (string)->size, |
278feba9 | 3274 | hpos, 0, 0, hpos, maxendcol); |
6b1bbc46 | 3275 | /* Put a space between items. */ |
2d66ad19 RS |
3276 | if (hpos < maxendcol) |
3277 | { | |
6b1bbc46 | 3278 | int hpos1 = hpos + 1; |
278feba9 | 3279 | hpos = display_string (w, vpos, "", 0, hpos, 0, 0, |
2d66ad19 RS |
3280 | min (hpos1, maxendcol), maxendcol); |
3281 | } | |
7ce2c095 RS |
3282 | } |
3283 | ||
3284 | FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0; | |
3285 | FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video; | |
2d66ad19 RS |
3286 | |
3287 | /* Fill out the line with spaces. */ | |
3288 | if (maxendcol > hpos) | |
278feba9 | 3289 | hpos = display_string (w, vpos, "", 0, hpos, 0, 0, maxendcol, maxendcol); |
db6f348c JB |
3290 | |
3291 | /* Clear the rest of the lines allocated to the menu bar. */ | |
3292 | vpos++; | |
3293 | while (vpos < FRAME_MENU_BAR_LINES (f)) | |
3294 | get_display_line (f, vpos++, 0); | |
7ce2c095 RS |
3295 | } |
3296 | \f | |
a2889657 JB |
3297 | /* Display the mode line for window w */ |
3298 | ||
3299 | static void | |
3300 | display_mode_line (w) | |
3301 | struct window *w; | |
3302 | { | |
3303 | register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1; | |
3304 | register int left = XFASTINT (w->left); | |
3305 | register int right = XFASTINT (w->width) + left; | |
44fa5b1e | 3306 | register FRAME_PTR f = XFRAME (WINDOW_FRAME (w)); |
a2889657 | 3307 | |
aa6d10fa | 3308 | line_number_displayed = 0; |
155ef550 | 3309 | w->column_number_displayed = Qnil; |
aa6d10fa | 3310 | |
44fa5b1e | 3311 | get_display_line (f, vpos, left); |
03b294dc RS |
3312 | |
3313 | /* Temporarily make frame F's kboard the current kboard | |
3314 | so that kboard-local variables in the mode_line_format | |
3315 | will get the right values. */ | |
3316 | push_frame_kboard (f); | |
3317 | ||
3318 | display_mode_element (w, vpos, left, 0, right, right, | |
3319 | current_buffer->mode_line_format); | |
3320 | ||
3321 | pop_frame_kboard (); | |
3322 | ||
44fa5b1e | 3323 | FRAME_DESIRED_GLYPHS (f)->bufp[vpos] = 0; |
a2889657 JB |
3324 | |
3325 | /* Make the mode line inverse video if the entire line | |
3326 | is made of mode lines. | |
3327 | I.e. if this window is full width, | |
3328 | or if it is the child of a full width window | |
3329 | (which implies that that window is split side-by-side | |
3330 | and the rest of this line is mode lines of the sibling windows). */ | |
44fa5b1e JB |
3331 | if (XFASTINT (w->width) == FRAME_WIDTH (f) |
3332 | || XFASTINT (XWINDOW (w->parent)->width) == FRAME_WIDTH (f)) | |
3333 | FRAME_DESIRED_GLYPHS (f)->highlight[vpos] = mode_line_inverse_video; | |
87485d6f | 3334 | #ifdef HAVE_FACES |
03b294dc | 3335 | else if (! FRAME_TERMCAP_P (f) && mode_line_inverse_video) |
d7eb09a0 RS |
3336 | { |
3337 | /* For a partial width window, explicitly set face of each glyph. */ | |
3338 | int i; | |
3339 | GLYPH *ptr = FRAME_DESIRED_GLYPHS (f)->glyphs[vpos]; | |
3340 | for (i = left; i < right; ++i) | |
4cdc65eb | 3341 | ptr[i] = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (ptr[i]), 1); |
d7eb09a0 | 3342 | } |
4cdc65eb | 3343 | #endif |
a2889657 JB |
3344 | } |
3345 | ||
3346 | /* Contribute ELT to the mode line for window W. | |
3347 | How it translates into text depends on its data type. | |
3348 | ||
3349 | VPOS is the position of the mode line being displayed. | |
3350 | ||
44fa5b1e | 3351 | HPOS is the position (absolute on frame) where this element's text |
a2889657 JB |
3352 | should start. The output is truncated automatically at the right |
3353 | edge of window W. | |
3354 | ||
3355 | DEPTH is the depth in recursion. It is used to prevent | |
3356 | infinite recursion here. | |
3357 | ||
3358 | MINENDCOL is the hpos before which the element may not end. | |
3359 | The element is padded at the right with spaces if nec | |
3360 | to reach this column. | |
3361 | ||
3362 | MAXENDCOL is the hpos past which this element may not extend. | |
3363 | If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority. | |
3364 | (This is necessary to make nested padding and truncation work.) | |
3365 | ||
3366 | Returns the hpos of the end of the text generated by ELT. | |
3367 | The next element will receive that value as its HPOS arg, | |
3368 | so as to concatenate the elements. */ | |
3369 | ||
3370 | static int | |
3371 | display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt) | |
3372 | struct window *w; | |
3373 | register int vpos, hpos; | |
3374 | int depth; | |
3375 | int minendcol; | |
3376 | register int maxendcol; | |
3377 | register Lisp_Object elt; | |
3378 | { | |
3379 | tail_recurse: | |
3380 | if (depth > 10) | |
3381 | goto invalid; | |
3382 | ||
3383 | depth++; | |
3384 | ||
0220c518 | 3385 | switch (SWITCH_ENUM_CAST (XTYPE (elt))) |
a2889657 JB |
3386 | { |
3387 | case Lisp_String: | |
3388 | { | |
3389 | /* A string: output it and check for %-constructs within it. */ | |
3390 | register unsigned char c; | |
3391 | register unsigned char *this = XSTRING (elt)->data; | |
3392 | ||
3393 | while (hpos < maxendcol && *this) | |
3394 | { | |
3395 | unsigned char *last = this; | |
3396 | while ((c = *this++) != '\0' && c != '%') | |
3397 | ; | |
3398 | if (this - 1 != last) | |
3399 | { | |
3400 | register int lim = --this - last + hpos; | |
d39b6696 KH |
3401 | if (frame_title_ptr) |
3402 | hpos = store_frame_title (last, hpos, min (lim, maxendcol)); | |
3403 | else | |
3404 | hpos = display_string (w, vpos, last, -1, hpos, 0, 1, | |
3405 | hpos, min (lim, maxendcol)); | |
a2889657 JB |
3406 | } |
3407 | else /* c == '%' */ | |
3408 | { | |
766525bc | 3409 | register int minendcol; |
a2889657 JB |
3410 | register int spec_width = 0; |
3411 | ||
3412 | /* We can't allow -ve args due to the "%-" construct */ | |
3413 | /* Argument specifies minwidth but not maxwidth | |
3414 | (maxwidth can be specified by | |
3415 | (<negative-number> . <stuff>) mode-line elements) */ | |
3416 | ||
3417 | while ((c = *this++) >= '0' && c <= '9') | |
3418 | { | |
3419 | spec_width = spec_width * 10 + (c - '0'); | |
3420 | } | |
3421 | ||
766525bc RS |
3422 | minendcol = hpos + spec_width; |
3423 | if (minendcol > maxendcol) | |
3424 | { | |
3425 | spec_width = maxendcol - hpos; | |
3426 | minendcol = maxendcol; | |
3427 | } | |
a2889657 JB |
3428 | |
3429 | if (c == 'M') | |
3430 | hpos = display_mode_element (w, vpos, hpos, depth, | |
3431 | spec_width, maxendcol, | |
3432 | Vglobal_mode_string); | |
3433 | else if (c != 0) | |
d39b6696 | 3434 | { |
766525bc RS |
3435 | char *spec = decode_mode_spec (w, c, spec_width, |
3436 | maxendcol - hpos); | |
d39b6696 | 3437 | if (frame_title_ptr) |
766525bc | 3438 | hpos = store_frame_title (spec, minendcol, maxendcol); |
d39b6696 KH |
3439 | else |
3440 | hpos = display_string (w, vpos, spec, -1, | |
3441 | hpos, 0, 1, | |
766525bc | 3442 | minendcol, maxendcol); |
d39b6696 | 3443 | } |
a2889657 JB |
3444 | } |
3445 | } | |
3446 | } | |
3447 | break; | |
3448 | ||
3449 | case Lisp_Symbol: | |
3450 | /* A symbol: process the value of the symbol recursively | |
3451 | as if it appeared here directly. Avoid error if symbol void. | |
3452 | Special case: if value of symbol is a string, output the string | |
3453 | literally. */ | |
3454 | { | |
3455 | register Lisp_Object tem; | |
3456 | tem = Fboundp (elt); | |
265a9e55 | 3457 | if (!NILP (tem)) |
a2889657 JB |
3458 | { |
3459 | tem = Fsymbol_value (elt); | |
3460 | /* If value is a string, output that string literally: | |
3461 | don't check for % within it. */ | |
e24c997d | 3462 | if (STRINGP (tem)) |
d39b6696 KH |
3463 | { |
3464 | if (frame_title_ptr) | |
3465 | hpos = store_frame_title (XSTRING (tem)->data, | |
3466 | minendcol, maxendcol); | |
3467 | else | |
3468 | hpos = display_string (w, vpos, XSTRING (tem)->data, | |
3469 | XSTRING (tem)->size, | |
3470 | hpos, 0, 1, minendcol, maxendcol); | |
3471 | } | |
a2889657 JB |
3472 | /* Give up right away for nil or t. */ |
3473 | else if (!EQ (tem, elt)) | |
3474 | { elt = tem; goto tail_recurse; } | |
3475 | } | |
3476 | } | |
3477 | break; | |
3478 | ||
3479 | case Lisp_Cons: | |
3480 | { | |
3481 | register Lisp_Object car, tem; | |
3482 | ||
3483 | /* A cons cell: three distinct cases. | |
3484 | If first element is a string or a cons, process all the elements | |
3485 | and effectively concatenate them. | |
3486 | If first element is a negative number, truncate displaying cdr to | |
3487 | at most that many characters. If positive, pad (with spaces) | |
3488 | to at least that many characters. | |
3489 | If first element is a symbol, process the cadr or caddr recursively | |
3490 | according to whether the symbol's value is non-nil or nil. */ | |
3491 | car = XCONS (elt)->car; | |
e24c997d | 3492 | if (SYMBOLP (car)) |
a2889657 JB |
3493 | { |
3494 | tem = Fboundp (car); | |
3495 | elt = XCONS (elt)->cdr; | |
e24c997d | 3496 | if (!CONSP (elt)) |
a2889657 JB |
3497 | goto invalid; |
3498 | /* elt is now the cdr, and we know it is a cons cell. | |
3499 | Use its car if CAR has a non-nil value. */ | |
265a9e55 | 3500 | if (!NILP (tem)) |
a2889657 JB |
3501 | { |
3502 | tem = Fsymbol_value (car); | |
265a9e55 | 3503 | if (!NILP (tem)) |
a2889657 JB |
3504 | { elt = XCONS (elt)->car; goto tail_recurse; } |
3505 | } | |
3506 | /* Symbol's value is nil (or symbol is unbound) | |
3507 | Get the cddr of the original list | |
3508 | and if possible find the caddr and use that. */ | |
3509 | elt = XCONS (elt)->cdr; | |
265a9e55 | 3510 | if (NILP (elt)) |
a2889657 | 3511 | break; |
e24c997d | 3512 | else if (!CONSP (elt)) |
a2889657 JB |
3513 | goto invalid; |
3514 | elt = XCONS (elt)->car; | |
3515 | goto tail_recurse; | |
3516 | } | |
e24c997d | 3517 | else if (INTEGERP (car)) |
a2889657 JB |
3518 | { |
3519 | register int lim = XINT (car); | |
3520 | elt = XCONS (elt)->cdr; | |
3521 | if (lim < 0) | |
3522 | /* Negative int means reduce maximum width. | |
3523 | DO NOT change MINENDCOL here! | |
3524 | (20 -10 . foo) should truncate foo to 10 col | |
3525 | and then pad to 20. */ | |
3526 | maxendcol = min (maxendcol, hpos - lim); | |
3527 | else if (lim > 0) | |
3528 | { | |
3529 | /* Padding specified. Don't let it be more than | |
3530 | current maximum. */ | |
3531 | lim += hpos; | |
3532 | if (lim > maxendcol) | |
3533 | lim = maxendcol; | |
3534 | /* If that's more padding than already wanted, queue it. | |
3535 | But don't reduce padding already specified even if | |
3536 | that is beyond the current truncation point. */ | |
3537 | if (lim > minendcol) | |
3538 | minendcol = lim; | |
3539 | } | |
3540 | goto tail_recurse; | |
3541 | } | |
e24c997d | 3542 | else if (STRINGP (car) || CONSP (car)) |
a2889657 JB |
3543 | { |
3544 | register int limit = 50; | |
3545 | /* LIMIT is to protect against circular lists. */ | |
e24c997d | 3546 | while (CONSP (elt) && --limit > 0 |
a2889657 JB |
3547 | && hpos < maxendcol) |
3548 | { | |
3549 | hpos = display_mode_element (w, vpos, hpos, depth, | |
3550 | hpos, maxendcol, | |
3551 | XCONS (elt)->car); | |
3552 | elt = XCONS (elt)->cdr; | |
3553 | } | |
3554 | } | |
3555 | } | |
3556 | break; | |
3557 | ||
3558 | default: | |
3559 | invalid: | |
d39b6696 KH |
3560 | if (frame_title_ptr) |
3561 | hpos = store_frame_title ("*invalid*", minendcol, maxendcol); | |
3562 | else | |
3563 | hpos = display_string (w, vpos, "*invalid*", -1, hpos, 0, 1, | |
3564 | minendcol, maxendcol); | |
3565 | return hpos; | |
a2889657 JB |
3566 | } |
3567 | ||
a2889657 | 3568 | if (minendcol > hpos) |
d39b6696 KH |
3569 | if (frame_title_ptr) |
3570 | hpos = store_frame_title ("", minendcol, maxendcol); | |
3571 | else | |
3572 | hpos = display_string (w, vpos, "", 0, hpos, 0, 1, minendcol, maxendcol); | |
a2889657 JB |
3573 | return hpos; |
3574 | } | |
3575 | \f | |
766525bc RS |
3576 | /* Write a null-terminated, right justified decimal representation of |
3577 | the positive integer D to BUF using a minimal field width WIDTH. */ | |
3578 | ||
3579 | static void | |
3580 | pint2str (buf, width, d) | |
3581 | register char *buf; | |
3582 | register int width; | |
3583 | register int d; | |
3584 | { | |
3585 | register char *p = buf; | |
3586 | ||
3587 | if (d <= 0) | |
3588 | *p++ = '0'; | |
3589 | else | |
3590 | while (d > 0) | |
3591 | { | |
3592 | *p++ = d % 10 + '0'; | |
3593 | d /= 10; | |
3594 | } | |
3595 | for (width -= (int) (p - buf); width > 0; --width) *p++ = ' '; | |
3596 | *p-- = '\0'; | |
3597 | while (p > buf) | |
3598 | { | |
3599 | d = *buf; | |
3600 | *buf++ = *p; | |
3601 | *p-- = d; | |
3602 | } | |
3603 | } | |
3604 | ||
a2889657 | 3605 | /* Return a string for the output of a mode line %-spec for window W, |
766525bc RS |
3606 | generated by character C. SPEC_WIDTH is the field width when |
3607 | padding to the left (%c, %l). The value returned from this | |
3608 | function will later be truncated to width MAXWIDTH. */ | |
a2889657 | 3609 | |
11e82b76 JB |
3610 | static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------"; |
3611 | ||
a2889657 | 3612 | static char * |
766525bc | 3613 | decode_mode_spec (w, c, spec_width, maxwidth) |
a2889657 JB |
3614 | struct window *w; |
3615 | register char c; | |
766525bc | 3616 | register int spec_width; |
a2889657 JB |
3617 | register int maxwidth; |
3618 | { | |
0b67772d | 3619 | Lisp_Object obj; |
44fa5b1e JB |
3620 | FRAME_PTR f = XFRAME (WINDOW_FRAME (w)); |
3621 | char *decode_mode_spec_buf = (char *) FRAME_TEMP_GLYPHS (f)->total_contents; | |
d39b6696 | 3622 | struct buffer *b = XBUFFER (w->buffer); |
a2889657 | 3623 | |
0b67772d | 3624 | obj = Qnil; |
44fa5b1e JB |
3625 | if (maxwidth > FRAME_WIDTH (f)) |
3626 | maxwidth = FRAME_WIDTH (f); | |
a2889657 JB |
3627 | |
3628 | switch (c) | |
3629 | { | |
1af9f229 RS |
3630 | case '*': |
3631 | if (!NILP (b->read_only)) | |
3632 | return "%"; | |
3633 | if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
3634 | return "*"; | |
3635 | return "-"; | |
3636 | ||
3637 | case '+': | |
3638 | /* This differs from %* only for a modified read-only buffer. */ | |
3639 | if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
3640 | return "*"; | |
3641 | if (!NILP (b->read_only)) | |
3642 | return "%"; | |
3643 | return "-"; | |
3644 | ||
3645 | case '&': | |
3646 | /* This differs from %* in ignoring read-only-ness. */ | |
3647 | if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
3648 | return "*"; | |
3649 | return "-"; | |
3650 | ||
3651 | case '%': | |
3652 | return "%"; | |
3653 | ||
3654 | case '[': | |
3655 | { | |
3656 | int i; | |
3657 | char *p; | |
3658 | ||
3659 | if (command_loop_level > 5) | |
3660 | return "[[[... "; | |
3661 | p = decode_mode_spec_buf; | |
3662 | for (i = 0; i < command_loop_level; i++) | |
3663 | *p++ = '['; | |
3664 | *p = 0; | |
3665 | return decode_mode_spec_buf; | |
3666 | } | |
3667 | ||
3668 | case ']': | |
3669 | { | |
3670 | int i; | |
3671 | char *p; | |
3672 | ||
3673 | if (command_loop_level > 5) | |
3674 | return " ...]]]"; | |
3675 | p = decode_mode_spec_buf; | |
3676 | for (i = 0; i < command_loop_level; i++) | |
3677 | *p++ = ']'; | |
3678 | *p = 0; | |
3679 | return decode_mode_spec_buf; | |
3680 | } | |
3681 | ||
3682 | case '-': | |
3683 | { | |
3684 | register char *p; | |
3685 | register int i; | |
3686 | ||
3687 | if (maxwidth < sizeof (lots_of_dashes)) | |
3688 | return lots_of_dashes; | |
3689 | else | |
3690 | { | |
3691 | for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--) | |
3692 | *p++ = '-'; | |
3693 | *p = '\0'; | |
3694 | } | |
3695 | return decode_mode_spec_buf; | |
3696 | } | |
3697 | ||
a2889657 | 3698 | case 'b': |
d39b6696 | 3699 | obj = b->name; |
a2889657 JB |
3700 | #if 0 |
3701 | if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth) | |
3702 | { | |
3703 | bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1); | |
3704 | decode_mode_spec_buf[maxwidth - 1] = '\\'; | |
3705 | decode_mode_spec_buf[maxwidth] = '\0'; | |
3706 | return decode_mode_spec_buf; | |
3707 | } | |
3708 | #endif | |
3709 | break; | |
3710 | ||
1af9f229 RS |
3711 | case 'c': |
3712 | { | |
3713 | int col = current_column (); | |
3714 | XSETFASTINT (w->column_number_displayed, col); | |
766525bc | 3715 | pint2str (decode_mode_spec_buf, spec_width, col); |
1af9f229 RS |
3716 | return decode_mode_spec_buf; |
3717 | } | |
3718 | ||
3719 | case 'F': | |
3720 | /* %F displays the frame name. */ | |
9cb61f8d | 3721 | #ifdef MULTI_FRAME |
22dabbb2 RS |
3722 | if (!NILP (selected_frame->title)) |
3723 | return (char *) XSTRING (selected_frame->title)->data; | |
1af9f229 | 3724 | return (char *) XSTRING (selected_frame->name)->data; |
9cb61f8d RS |
3725 | #else |
3726 | return "Emacs"; | |
3727 | #endif | |
1af9f229 | 3728 | |
a2889657 | 3729 | case 'f': |
d39b6696 | 3730 | obj = b->filename; |
a2889657 | 3731 | #if 0 |
265a9e55 | 3732 | if (NILP (obj)) |
a2889657 | 3733 | return "[none]"; |
e24c997d | 3734 | else if (STRINGP (obj) && XSTRING (obj)->size > maxwidth) |
a2889657 JB |
3735 | { |
3736 | bcopy ("...", decode_mode_spec_buf, 3); | |
3737 | bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3, | |
3738 | decode_mode_spec_buf + 3, maxwidth - 3); | |
3739 | return decode_mode_spec_buf; | |
3740 | } | |
3741 | #endif | |
3742 | break; | |
3743 | ||
aa6d10fa RS |
3744 | case 'l': |
3745 | { | |
3746 | int startpos = marker_position (w->start); | |
3747 | int line, linepos, topline; | |
3748 | int nlines, junk; | |
3749 | Lisp_Object tem; | |
3750 | int height = XFASTINT (w->height); | |
3751 | ||
3752 | /* If we decided that this buffer isn't suitable for line numbers, | |
3753 | don't forget that too fast. */ | |
3754 | if (EQ (w->base_line_pos, w->buffer)) | |
766525bc | 3755 | goto no_value; |
aa6d10fa RS |
3756 | |
3757 | /* If the buffer is very big, don't waste time. */ | |
d39b6696 | 3758 | if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit) |
aa6d10fa RS |
3759 | { |
3760 | w->base_line_pos = Qnil; | |
3761 | w->base_line_number = Qnil; | |
766525bc | 3762 | goto no_value; |
aa6d10fa RS |
3763 | } |
3764 | ||
3765 | if (!NILP (w->base_line_number) | |
3766 | && !NILP (w->base_line_pos) | |
3767 | && XFASTINT (w->base_line_pos) <= marker_position (w->start)) | |
3768 | { | |
3769 | line = XFASTINT (w->base_line_number); | |
3770 | linepos = XFASTINT (w->base_line_pos); | |
3771 | } | |
3772 | else | |
3773 | { | |
3774 | line = 1; | |
d39b6696 | 3775 | linepos = BUF_BEGV (b); |
aa6d10fa RS |
3776 | } |
3777 | ||
3778 | /* Count lines from base line to window start position. */ | |
3779 | nlines = display_count_lines (linepos, startpos, startpos, &junk); | |
3780 | ||
3781 | topline = nlines + line; | |
3782 | ||
3783 | /* Determine a new base line, if the old one is too close | |
3784 | or too far away, or if we did not have one. | |
3785 | "Too close" means it's plausible a scroll-down would | |
3786 | go back past it. */ | |
d39b6696 | 3787 | if (startpos == BUF_BEGV (b)) |
aa6d10fa | 3788 | { |
c2213350 KH |
3789 | XSETFASTINT (w->base_line_number, topline); |
3790 | XSETFASTINT (w->base_line_pos, BUF_BEGV (b)); | |
aa6d10fa RS |
3791 | } |
3792 | else if (nlines < height + 25 || nlines > height * 3 + 50 | |
d39b6696 | 3793 | || linepos == BUF_BEGV (b)) |
aa6d10fa | 3794 | { |
d39b6696 | 3795 | int limit = BUF_BEGV (b); |
aa6d10fa RS |
3796 | int position; |
3797 | int distance = (height * 2 + 30) * 200; | |
3798 | ||
3799 | if (startpos - distance > limit) | |
3800 | limit = startpos - distance; | |
3801 | ||
3802 | nlines = display_count_lines (startpos, limit, | |
3803 | -(height * 2 + 30), | |
3804 | &position); | |
3805 | /* If we couldn't find the lines we wanted within | |
3806 | 200 chars per line, | |
3807 | give up on line numbers for this window. */ | |
3808 | if (position == startpos - distance) | |
3809 | { | |
3810 | w->base_line_pos = w->buffer; | |
3811 | w->base_line_number = Qnil; | |
766525bc | 3812 | goto no_value; |
aa6d10fa RS |
3813 | } |
3814 | ||
c2213350 KH |
3815 | XSETFASTINT (w->base_line_number, topline - nlines); |
3816 | XSETFASTINT (w->base_line_pos, position); | |
aa6d10fa RS |
3817 | } |
3818 | ||
3819 | /* Now count lines from the start pos to point. */ | |
3820 | nlines = display_count_lines (startpos, PT, PT, &junk); | |
3821 | ||
3822 | /* Record that we did display the line number. */ | |
3823 | line_number_displayed = 1; | |
3824 | ||
3825 | /* Make the string to show. */ | |
766525bc | 3826 | pint2str (decode_mode_spec_buf, spec_width, topline + nlines); |
aa6d10fa | 3827 | return decode_mode_spec_buf; |
766525bc RS |
3828 | no_value: |
3829 | { | |
3830 | char* p = decode_mode_spec_buf; | |
3831 | for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' '; | |
3832 | strcpy (p, "??"); | |
3833 | return decode_mode_spec_buf; | |
3834 | } | |
aa6d10fa RS |
3835 | } |
3836 | break; | |
3837 | ||
a2889657 | 3838 | case 'm': |
d39b6696 | 3839 | obj = b->mode_name; |
a2889657 JB |
3840 | break; |
3841 | ||
3842 | case 'n': | |
d39b6696 | 3843 | if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b)) |
a2889657 JB |
3844 | return " Narrow"; |
3845 | break; | |
3846 | ||
a2889657 JB |
3847 | case 'p': |
3848 | { | |
3849 | int pos = marker_position (w->start); | |
d39b6696 | 3850 | int total = BUF_ZV (b) - BUF_BEGV (b); |
a2889657 | 3851 | |
d39b6696 | 3852 | if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b)) |
a2889657 | 3853 | { |
d39b6696 | 3854 | if (pos <= BUF_BEGV (b)) |
a2889657 JB |
3855 | return "All"; |
3856 | else | |
3857 | return "Bottom"; | |
3858 | } | |
d39b6696 | 3859 | else if (pos <= BUF_BEGV (b)) |
a2889657 JB |
3860 | return "Top"; |
3861 | else | |
3862 | { | |
3c7d31b9 RS |
3863 | if (total > 1000000) |
3864 | /* Do it differently for a large value, to avoid overflow. */ | |
3865 | total = ((pos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100); | |
3866 | else | |
3867 | total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total; | |
a2889657 JB |
3868 | /* We can't normally display a 3-digit number, |
3869 | so get us a 2-digit number that is close. */ | |
3870 | if (total == 100) | |
3871 | total = 99; | |
3872 | sprintf (decode_mode_spec_buf, "%2d%%", total); | |
3873 | return decode_mode_spec_buf; | |
3874 | } | |
3875 | } | |
3876 | ||
8ffcb79f RS |
3877 | /* Display percentage of size above the bottom of the screen. */ |
3878 | case 'P': | |
3879 | { | |
3880 | int toppos = marker_position (w->start); | |
d39b6696 KH |
3881 | int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos); |
3882 | int total = BUF_ZV (b) - BUF_BEGV (b); | |
8ffcb79f | 3883 | |
d39b6696 | 3884 | if (botpos >= BUF_ZV (b)) |
8ffcb79f | 3885 | { |
d39b6696 | 3886 | if (toppos <= BUF_BEGV (b)) |
8ffcb79f RS |
3887 | return "All"; |
3888 | else | |
3889 | return "Bottom"; | |
3890 | } | |
3891 | else | |
3892 | { | |
3c7d31b9 RS |
3893 | if (total > 1000000) |
3894 | /* Do it differently for a large value, to avoid overflow. */ | |
3895 | total = ((botpos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100); | |
3896 | else | |
3897 | total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total; | |
8ffcb79f RS |
3898 | /* We can't normally display a 3-digit number, |
3899 | so get us a 2-digit number that is close. */ | |
3900 | if (total == 100) | |
3901 | total = 99; | |
d39b6696 | 3902 | if (toppos <= BUF_BEGV (b)) |
8ffcb79f RS |
3903 | sprintf (decode_mode_spec_buf, "Top%2d%%", total); |
3904 | else | |
3905 | sprintf (decode_mode_spec_buf, "%2d%%", total); | |
3906 | return decode_mode_spec_buf; | |
3907 | } | |
3908 | } | |
3909 | ||
1af9f229 RS |
3910 | case 's': |
3911 | /* status of process */ | |
3912 | obj = Fget_buffer_process (w->buffer); | |
3913 | if (NILP (obj)) | |
3914 | return "no process"; | |
3915 | #ifdef subprocesses | |
3916 | obj = Fsymbol_name (Fprocess_status (obj)); | |
3917 | #endif | |
3918 | break; | |
d39b6696 | 3919 | |
1af9f229 RS |
3920 | case 't': /* indicate TEXT or BINARY */ |
3921 | #ifdef MODE_LINE_BINARY_TEXT | |
3922 | return MODE_LINE_BINARY_TEXT (b); | |
3923 | #else | |
3924 | return "T"; | |
3925 | #endif | |
a2889657 | 3926 | } |
d39b6696 | 3927 | |
e24c997d | 3928 | if (STRINGP (obj)) |
a2889657 JB |
3929 | return (char *) XSTRING (obj)->data; |
3930 | else | |
3931 | return ""; | |
3932 | } | |
59b49f63 RS |
3933 | \f |
3934 | /* Search for COUNT instances of a line boundary, which means either a | |
3935 | newline or (if selective display enabled) a carriage return. | |
3936 | Start at START. If COUNT is negative, search backwards. | |
3937 | ||
3938 | If we find COUNT instances, set *SHORTAGE to zero, and return the | |
3939 | position after the COUNTth match. Note that for reverse motion | |
3940 | this is not the same as the usual convention for Emacs motion commands. | |
3941 | ||
3942 | If we don't find COUNT instances before reaching the end of the | |
3943 | buffer (or the beginning, if scanning backwards), set *SHORTAGE to | |
3944 | the number of line boundaries left unfound, and return the end of the | |
3945 | buffer we bumped up against. */ | |
3946 | ||
3947 | static int | |
3948 | display_scan_buffer (start, count, shortage) | |
3949 | int *shortage, start; | |
3950 | register int count; | |
3951 | { | |
3952 | int limit = ((count > 0) ? ZV - 1 : BEGV); | |
3953 | int direction = ((count > 0) ? 1 : -1); | |
3954 | ||
3955 | register unsigned char *cursor; | |
3956 | unsigned char *base; | |
3957 | ||
3958 | register int ceiling; | |
3959 | register unsigned char *ceiling_addr; | |
3960 | ||
3961 | /* If we are not in selective display mode, | |
3962 | check only for newlines. */ | |
3963 | if (! (!NILP (current_buffer->selective_display) | |
3964 | && !INTEGERP (current_buffer->selective_display))) | |
ae474ea9 | 3965 | return scan_buffer ('\n', start, 0, count, shortage, 0); |
59b49f63 RS |
3966 | |
3967 | /* The code that follows is like scan_buffer | |
3968 | but checks for either newline or carriage return. */ | |
3969 | ||
3970 | if (shortage != 0) | |
3971 | *shortage = 0; | |
3972 | ||
3973 | if (count > 0) | |
3974 | while (start != limit + 1) | |
3975 | { | |
3976 | ceiling = BUFFER_CEILING_OF (start); | |
3977 | ceiling = min (limit, ceiling); | |
3978 | ceiling_addr = &FETCH_CHAR (ceiling) + 1; | |
3979 | base = (cursor = &FETCH_CHAR (start)); | |
3980 | while (1) | |
3981 | { | |
3982 | while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr) | |
3983 | ; | |
3984 | if (cursor != ceiling_addr) | |
3985 | { | |
3986 | if (--count == 0) | |
3987 | { | |
3988 | immediate_quit = 0; | |
3989 | return (start + cursor - base + 1); | |
3990 | } | |
3991 | else | |
3992 | if (++cursor == ceiling_addr) | |
3993 | break; | |
3994 | } | |
3995 | else | |
3996 | break; | |
3997 | } | |
3998 | start += cursor - base; | |
3999 | } | |
4000 | else | |
4001 | { | |
4002 | start--; /* first character we scan */ | |
4003 | while (start > limit - 1) | |
4004 | { /* we WILL scan under start */ | |
4005 | ceiling = BUFFER_FLOOR_OF (start); | |
4006 | ceiling = max (limit, ceiling); | |
4007 | ceiling_addr = &FETCH_CHAR (ceiling) - 1; | |
4008 | base = (cursor = &FETCH_CHAR (start)); | |
4009 | cursor++; | |
4010 | while (1) | |
4011 | { | |
4012 | while (--cursor != ceiling_addr | |
4013 | && *cursor != '\n' && *cursor != 015) | |
4014 | ; | |
4015 | if (cursor != ceiling_addr) | |
4016 | { | |
4017 | if (++count == 0) | |
4018 | { | |
4019 | immediate_quit = 0; | |
4020 | return (start + cursor - base + 1); | |
4021 | } | |
4022 | } | |
4023 | else | |
4024 | break; | |
4025 | } | |
4026 | start += cursor - base; | |
4027 | } | |
4028 | } | |
4029 | ||
4030 | if (shortage != 0) | |
4031 | *shortage = count * direction; | |
4032 | return (start + ((direction == 1 ? 0 : 1))); | |
4033 | } | |
aa6d10fa RS |
4034 | |
4035 | /* Count up to N lines starting from FROM. | |
4036 | But don't go beyond LIMIT. | |
4037 | Return the number of lines thus found (always positive). | |
4038 | Store the position after what was found into *POS_PTR. */ | |
4039 | ||
4040 | static int | |
4041 | display_count_lines (from, limit, n, pos_ptr) | |
4042 | int from, limit, n; | |
4043 | int *pos_ptr; | |
4044 | { | |
4045 | int oldbegv = BEGV; | |
4046 | int oldzv = ZV; | |
4047 | int shortage = 0; | |
4048 | ||
4049 | if (limit < from) | |
4050 | BEGV = limit; | |
4051 | else | |
4052 | ZV = limit; | |
4053 | ||
59b49f63 | 4054 | *pos_ptr = display_scan_buffer (from, n, &shortage); |
aa6d10fa RS |
4055 | |
4056 | ZV = oldzv; | |
4057 | BEGV = oldbegv; | |
4058 | ||
4059 | if (n < 0) | |
4060 | /* When scanning backwards, scan_buffer stops *after* the last newline | |
4061 | it finds, but does count it. Compensate for that. */ | |
4062 | return - n - shortage - (*pos_ptr != limit); | |
4063 | return n - shortage; | |
4064 | } | |
a2889657 JB |
4065 | \f |
4066 | /* Display STRING on one line of window W, starting at HPOS. | |
4067 | Display at position VPOS. Caller should have done get_display_line. | |
11e82b76 | 4068 | If VPOS == -1, display it as the current frame's title. |
90adcf20 | 4069 | LENGTH is the length of STRING, or -1 meaning STRING is null-terminated. |
a2889657 JB |
4070 | |
4071 | TRUNCATE is GLYPH to display at end if truncated. Zero for none. | |
4072 | ||
4073 | MINCOL is the first column ok to end at. (Pad with spaces to this col.) | |
4074 | MAXCOL is the last column ok to end at. Truncate here. | |
4075 | -1 for MINCOL or MAXCOL means no explicit minimum or maximum. | |
44fa5b1e | 4076 | Both count from the left edge of the frame, as does HPOS. |
a2889657 JB |
4077 | The right edge of W is an implicit maximum. |
4078 | If TRUNCATE is nonzero, the implicit maximum is one column before the edge. | |
4079 | ||
278feba9 RS |
4080 | OBEY_WINDOW_WIDTH says to put spaces or vertical bars |
4081 | at the place where the current window ends in this line | |
4082 | and not display anything beyond there. Otherwise, only MAXCOL | |
4083 | controls where to stop output. | |
4084 | ||
4085 | Returns ending hpos. */ | |
a2889657 JB |
4086 | |
4087 | static int | |
278feba9 RS |
4088 | display_string (w, vpos, string, length, hpos, truncate, |
4089 | obey_window_width, mincol, maxcol) | |
a2889657 JB |
4090 | struct window *w; |
4091 | unsigned char *string; | |
90adcf20 | 4092 | int length; |
a2889657 JB |
4093 | int vpos, hpos; |
4094 | GLYPH truncate; | |
278feba9 | 4095 | int obey_window_width; |
a2889657 JB |
4096 | int mincol, maxcol; |
4097 | { | |
4098 | register int c; | |
d3413a53 | 4099 | int truncated; |
a2889657 JB |
4100 | register GLYPH *p1; |
4101 | int hscroll = XINT (w->hscroll); | |
253c7d2f | 4102 | int tab_width = XINT (XBUFFER (w->buffer)->tab_width); |
a2889657 JB |
4103 | register GLYPH *start; |
4104 | register GLYPH *end; | |
b1d1124b JB |
4105 | FRAME_PTR f = XFRAME (WINDOW_FRAME (w)); |
4106 | struct frame_glyphs *desired_glyphs = FRAME_DESIRED_GLYPHS (f); | |
a2889657 JB |
4107 | GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos; |
4108 | int window_width = XFASTINT (w->width); | |
4109 | ||
4110 | /* Use the standard display table, not the window's display table. | |
4111 | We don't want the mode line in rot13. */ | |
f908610f | 4112 | register struct Lisp_Char_Table *dp = 0; |
efc63ef0 | 4113 | int i; |
a2889657 | 4114 | |
f908610f RS |
4115 | if (DISP_TABLE_P (Vstandard_display_table)) |
4116 | dp = XCHAR_TABLE (Vstandard_display_table); | |
a2889657 | 4117 | |
54ff581a | 4118 | if (tab_width <= 0 || tab_width > 1000) tab_width = 8; |
a2889657 JB |
4119 | |
4120 | p1 = p1start; | |
4121 | start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left); | |
a2889657 | 4122 | |
278feba9 | 4123 | if (obey_window_width) |
b1d1124b | 4124 | { |
278feba9 RS |
4125 | end = start + window_width - (truncate != 0); |
4126 | ||
4127 | if ((window_width + XFASTINT (w->left)) != FRAME_WIDTH (f)) | |
b1d1124b | 4128 | { |
278feba9 RS |
4129 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
4130 | { | |
4131 | int i; | |
b1d1124b | 4132 | |
5802e919 | 4133 | for (i = 0; i < FRAME_SCROLL_BAR_COLS (f); i++) |
278feba9 RS |
4134 | *end-- = ' '; |
4135 | } | |
4136 | else | |
4137 | *end-- = '|'; | |
b1d1124b | 4138 | } |
b1d1124b | 4139 | } |
a2889657 | 4140 | |
278feba9 RS |
4141 | if (! obey_window_width |
4142 | || (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol)) | |
a2889657 | 4143 | end = desired_glyphs->glyphs[vpos] + maxcol; |
278feba9 | 4144 | |
efc63ef0 | 4145 | /* Store 0 in charstart for these columns. */ |
bd5dec8e | 4146 | for (i = (hpos >= 0 ? hpos : 0); i < end - p1start + hpos; i++) |
efc63ef0 RS |
4147 | desired_glyphs->charstarts[vpos][i] = 0; |
4148 | ||
a2889657 JB |
4149 | if (maxcol >= 0 && mincol > maxcol) |
4150 | mincol = maxcol; | |
4151 | ||
d3413a53 RS |
4152 | /* We set truncated to 1 if we get stopped by trying to pass END |
4153 | (that is, trying to pass MAXCOL.) */ | |
4154 | truncated = 0; | |
4155 | while (1) | |
a2889657 | 4156 | { |
90adcf20 RS |
4157 | if (length == 0) |
4158 | break; | |
a2889657 | 4159 | c = *string++; |
90adcf20 RS |
4160 | /* Specified length. */ |
4161 | if (length >= 0) | |
4162 | length--; | |
4163 | /* Unspecified length (null-terminated string). */ | |
4164 | else if (c == 0) | |
4165 | break; | |
4166 | ||
d3413a53 RS |
4167 | if (p1 >= end) |
4168 | { | |
4169 | truncated = 1; | |
4170 | break; | |
4171 | } | |
4172 | ||
376b0e59 RS |
4173 | if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c))) |
4174 | { | |
4175 | p1 = copy_part_of_rope (f, p1, start, | |
4176 | XVECTOR (DISP_CHAR_VECTOR (dp, c))->contents, | |
4177 | XVECTOR (DISP_CHAR_VECTOR (dp, c))->size, | |
4178 | 0); | |
4179 | } | |
4180 | else if (c >= 040 && c < 0177) | |
a2889657 JB |
4181 | { |
4182 | if (p1 >= start) | |
4183 | *p1 = c; | |
4184 | p1++; | |
4185 | } | |
4186 | else if (c == '\t') | |
4187 | { | |
4188 | do | |
4189 | { | |
4190 | if (p1 >= start && p1 < end) | |
4191 | *p1 = SPACEGLYPH; | |
4192 | p1++; | |
4193 | } | |
4194 | while ((p1 - start + hscroll - (hscroll > 0)) % tab_width); | |
4195 | } | |
ded34426 | 4196 | else if (c < 0200 && ! NILP (buffer_defaults.ctl_arrow)) |
a2889657 JB |
4197 | { |
4198 | if (p1 >= start) | |
e24c997d | 4199 | *p1 = fix_glyph (f, (dp && INTEGERP (DISP_CTRL_GLYPH (dp)) |
278feba9 RS |
4200 | ? XINT (DISP_CTRL_GLYPH (dp)) : '^'), |
4201 | 0); | |
a2889657 | 4202 | p1++; |
6e8290aa | 4203 | if (p1 >= start && p1 < end) |
a2889657 JB |
4204 | *p1 = c ^ 0100; |
4205 | p1++; | |
4206 | } | |
4207 | else | |
4208 | { | |
4209 | if (p1 >= start) | |
e24c997d | 4210 | *p1 = fix_glyph (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp)) |
278feba9 RS |
4211 | ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'), |
4212 | 0); | |
a2889657 | 4213 | p1++; |
6e8290aa | 4214 | if (p1 >= start && p1 < end) |
a2889657 JB |
4215 | *p1 = (c >> 6) + '0'; |
4216 | p1++; | |
6e8290aa | 4217 | if (p1 >= start && p1 < end) |
a2889657 JB |
4218 | *p1 = (7 & (c >> 3)) + '0'; |
4219 | p1++; | |
6e8290aa | 4220 | if (p1 >= start && p1 < end) |
a2889657 JB |
4221 | *p1 = (7 & c) + '0'; |
4222 | p1++; | |
4223 | } | |
4224 | } | |
4225 | ||
d3413a53 | 4226 | if (truncated) |
a2889657 JB |
4227 | { |
4228 | p1 = end; | |
278feba9 | 4229 | if (truncate) *p1++ = fix_glyph (f, truncate, 0); |
a2889657 JB |
4230 | } |
4231 | else if (mincol >= 0) | |
4232 | { | |
4233 | end = desired_glyphs->glyphs[vpos] + mincol; | |
4234 | while (p1 < end) | |
4235 | *p1++ = SPACEGLYPH; | |
4236 | } | |
4237 | ||
4238 | { | |
4239 | register int len = p1 - desired_glyphs->glyphs[vpos]; | |
4240 | ||
4241 | if (len > desired_glyphs->used[vpos]) | |
4242 | desired_glyphs->used[vpos] = len; | |
4243 | desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0; | |
4244 | ||
4245 | return len; | |
4246 | } | |
4247 | } | |
4248 | \f | |
642eefc6 RS |
4249 | /* This is like a combination of memq and assq. |
4250 | Return 1 if PROPVAL appears as an element of LIST | |
4251 | or as the car of an element of LIST. | |
af460d46 RS |
4252 | If PROPVAL is a list, compare each element against LIST |
4253 | in that way, and return 1 if any element of PROPVAL is found in LIST. | |
642eefc6 RS |
4254 | Otherwise return 0. |
4255 | This function cannot quit. */ | |
4256 | ||
4257 | int | |
4258 | invisible_p (propval, list) | |
4259 | register Lisp_Object propval; | |
4260 | Lisp_Object list; | |
4261 | { | |
af460d46 RS |
4262 | register Lisp_Object tail, proptail; |
4263 | for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr) | |
642eefc6 RS |
4264 | { |
4265 | register Lisp_Object tem; | |
af460d46 | 4266 | tem = XCONS (tail)->car; |
642eefc6 RS |
4267 | if (EQ (propval, tem)) |
4268 | return 1; | |
4269 | if (CONSP (tem) && EQ (propval, XCONS (tem)->car)) | |
4270 | return 1; | |
4271 | } | |
af460d46 RS |
4272 | if (CONSP (propval)) |
4273 | for (proptail = propval; CONSP (proptail); | |
4274 | proptail = XCONS (proptail)->cdr) | |
4275 | { | |
4276 | Lisp_Object propelt; | |
4277 | propelt = XCONS (proptail)->car; | |
4278 | for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr) | |
4279 | { | |
4280 | register Lisp_Object tem; | |
4281 | tem = XCONS (tail)->car; | |
4282 | if (EQ (propelt, tem)) | |
4283 | return 1; | |
4284 | if (CONSP (tem) && EQ (propelt, XCONS (tem)->car)) | |
4285 | return 1; | |
4286 | } | |
4287 | } | |
642eefc6 RS |
4288 | return 0; |
4289 | } | |
4290 | ||
4291 | /* Return 1 if PROPVAL appears as the car of an element of LIST | |
4292 | and the cdr of that element is non-nil. | |
af460d46 RS |
4293 | If PROPVAL is a list, check each element of PROPVAL in that way, |
4294 | and the first time some element is found, | |
4295 | return 1 if the cdr of that element is non-nil. | |
642eefc6 RS |
4296 | Otherwise return 0. |
4297 | This function cannot quit. */ | |
4298 | ||
4299 | int | |
4300 | invisible_ellipsis_p (propval, list) | |
4301 | register Lisp_Object propval; | |
4302 | Lisp_Object list; | |
4303 | { | |
af460d46 RS |
4304 | register Lisp_Object tail, proptail; |
4305 | for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr) | |
642eefc6 RS |
4306 | { |
4307 | register Lisp_Object tem; | |
af460d46 | 4308 | tem = XCONS (tail)->car; |
642eefc6 RS |
4309 | if (CONSP (tem) && EQ (propval, XCONS (tem)->car)) |
4310 | return ! NILP (XCONS (tem)->cdr); | |
4311 | } | |
af460d46 RS |
4312 | if (CONSP (propval)) |
4313 | for (proptail = propval; CONSP (proptail); | |
4314 | proptail = XCONS (proptail)->cdr) | |
4315 | { | |
4316 | Lisp_Object propelt; | |
4317 | propelt = XCONS (proptail)->car; | |
4318 | for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr) | |
4319 | { | |
4320 | register Lisp_Object tem; | |
4321 | tem = XCONS (tail)->car; | |
4322 | if (CONSP (tem) && EQ (propelt, XCONS (tem)->car)) | |
4323 | return ! NILP (XCONS (tem)->cdr); | |
4324 | } | |
4325 | } | |
642eefc6 RS |
4326 | return 0; |
4327 | } | |
4328 | \f | |
a2889657 JB |
4329 | void |
4330 | syms_of_xdisp () | |
4331 | { | |
cf074754 RS |
4332 | staticpro (&Qmenu_bar_update_hook); |
4333 | Qmenu_bar_update_hook = intern ("menu-bar-update-hook"); | |
4334 | ||
d46fb96a | 4335 | staticpro (&Qoverriding_terminal_local_map); |
7079aefa | 4336 | Qoverriding_terminal_local_map = intern ("overriding-terminal-local-map"); |
d46fb96a | 4337 | |
399164b4 KH |
4338 | staticpro (&Qoverriding_local_map); |
4339 | Qoverriding_local_map = intern ("overriding-local-map"); | |
4340 | ||
75c43375 RS |
4341 | staticpro (&Qwindow_scroll_functions); |
4342 | Qwindow_scroll_functions = intern ("window-scroll-functions"); | |
4343 | ||
e0bfbde6 RS |
4344 | staticpro (&Qredisplay_end_trigger_functions); |
4345 | Qredisplay_end_trigger_functions = intern ("redisplay-end-trigger-functions"); | |
67481ae5 | 4346 | |
a2889657 JB |
4347 | staticpro (&last_arrow_position); |
4348 | staticpro (&last_arrow_string); | |
4349 | last_arrow_position = Qnil; | |
4350 | last_arrow_string = Qnil; | |
4351 | ||
4352 | DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string, | |
8c45d522 | 4353 | "String (or mode line construct) included (normally) in `mode-line-format'."); |
a2889657 JB |
4354 | Vglobal_mode_string = Qnil; |
4355 | ||
4356 | DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position, | |
4357 | "Marker for where to display an arrow on top of the buffer text.\n\ | |
4358 | This must be the beginning of a line in order to work.\n\ | |
4359 | See also `overlay-arrow-string'."); | |
4360 | Voverlay_arrow_position = Qnil; | |
4361 | ||
4362 | DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string, | |
4363 | "String to display as an arrow. See also `overlay-arrow-position'."); | |
4364 | Voverlay_arrow_string = Qnil; | |
4365 | ||
4366 | DEFVAR_INT ("scroll-step", &scroll_step, | |
4367 | "*The number of lines to try scrolling a window by when point moves out.\n\ | |
44fa5b1e JB |
4368 | If that fails to bring point back on frame, point is centered instead.\n\ |
4369 | If this is zero, point is always centered after it moves off frame."); | |
a2889657 JB |
4370 | |
4371 | DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask"); | |
4372 | ||
4373 | DEFVAR_BOOL ("truncate-partial-width-windows", | |
4374 | &truncate_partial_width_windows, | |
44fa5b1e | 4375 | "*Non-nil means truncate lines in all windows less than full frame wide."); |
a2889657 JB |
4376 | truncate_partial_width_windows = 1; |
4377 | ||
4378 | DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video, | |
4379 | "*Non-nil means use inverse video for the mode line."); | |
4380 | mode_line_inverse_video = 1; | |
aa6d10fa RS |
4381 | |
4382 | DEFVAR_INT ("line-number-display-limit", &line_number_display_limit, | |
4383 | "*Maximum buffer size for which line number should be displayed."); | |
4384 | line_number_display_limit = 1000000; | |
fba9ce76 RS |
4385 | |
4386 | DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows, | |
4387 | "*Non-nil means highlight region even in nonselected windows."); | |
4388 | highlight_nonselected_windows = 1; | |
d39b6696 KH |
4389 | |
4390 | DEFVAR_BOOL ("multiple-frames", &multiple_frames, | |
3450d04c KH |
4391 | "Non-nil if more than one frame is visible on this display.\n\ |
4392 | Minibuffer-only frames don't count, but iconified frames do.\n\ | |
4c2eb242 RS |
4393 | This variable is not guaranteed to be accurate except while processing\n\ |
4394 | `frame-title-format' and `icon-title-format'."); | |
d39b6696 KH |
4395 | |
4396 | DEFVAR_LISP ("frame-title-format", &Vframe_title_format, | |
4397 | "Template for displaying the titlebar of visible frames.\n\ | |
4398 | \(Assuming the window manager supports this feature.)\n\ | |
4399 | This variable has the same structure as `mode-line-format' (which see),\n\ | |
4400 | and is used only on frames for which no explicit name has been set\n\ | |
4401 | \(see `modify-frame-parameters')."); | |
4402 | DEFVAR_LISP ("icon-title-format", &Vicon_title_format, | |
4403 | "Template for displaying the titlebar of an iconified frame.\n\ | |
4404 | \(Assuming the window manager supports this feature.)\n\ | |
4405 | This variable has the same structure as `mode-line-format' (which see),\n\ | |
4406 | and is used only on frames for which no explicit name has been set\n\ | |
4407 | \(see `modify-frame-parameters')."); | |
4408 | Vicon_title_format | |
4409 | = Vframe_title_format | |
4410 | = Fcons (intern ("multiple-frames"), | |
4411 | Fcons (build_string ("%b"), | |
4412 | Fcons (Fcons (build_string (""), | |
4413 | Fcons (intern ("invocation-name"), | |
4414 | Fcons (build_string ("@"), | |
4415 | Fcons (intern ("system-name"), | |
4416 | Qnil)))), | |
4417 | Qnil))); | |
5992c4f7 KH |
4418 | |
4419 | DEFVAR_LISP ("message-log-max", &Vmessage_log_max, | |
4420 | "Maximum number of lines to keep in the message log buffer.\n\ | |
4421 | If nil, disable message logging. If t, log messages but don't truncate\n\ | |
4422 | the buffer when it becomes large."); | |
4423 | XSETFASTINT (Vmessage_log_max, 50); | |
08b610e4 RS |
4424 | |
4425 | DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions, | |
4426 | "Functions called before redisplay, if window sizes have changed.\n\ | |
4427 | The value should be a list of functions that take one argument.\n\ | |
4428 | Just before redisplay, for each frame, if any of its windows have changed\n\ | |
4429 | size since the last redisplay, or have been split or deleted,\n\ | |
4430 | all the functions in the list are called, with the frame as argument."); | |
4431 | Vwindow_size_change_functions = Qnil; | |
75c43375 RS |
4432 | |
4433 | DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions, | |
f908610f | 4434 | "List of Functions to call before redisplaying a window with scrolling.\n\ |
75c43375 | 4435 | Each function is called with two arguments, the window\n\ |
8d9583b0 RS |
4436 | and its new display-start position. Note that the value of `window-end'\n\ |
4437 | is not valid when these functions are called."); | |
75c43375 | 4438 | Vwindow_scroll_functions = Qnil; |
a2889657 JB |
4439 | } |
4440 | ||
4441 | /* initialize the window system */ | |
4442 | init_xdisp () | |
4443 | { | |
4444 | Lisp_Object root_window; | |
4445 | #ifndef COMPILER_REGISTER_BUG | |
4446 | register | |
4447 | #endif /* COMPILER_REGISTER_BUG */ | |
4448 | struct window *mini_w; | |
4449 | ||
4450 | this_line_bufpos = 0; | |
4451 | ||
4452 | mini_w = XWINDOW (minibuf_window); | |
11e82b76 | 4453 | root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w))); |
a2889657 JB |
4454 | |
4455 | echo_area_glyphs = 0; | |
4456 | previous_echo_glyphs = 0; | |
4457 | ||
4458 | if (!noninteractive) | |
4459 | { | |
44fa5b1e | 4460 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (root_window))); |
c2213350 | 4461 | XSETFASTINT (XWINDOW (root_window)->top, 0); |
44fa5b1e | 4462 | set_window_height (root_window, FRAME_HEIGHT (f) - 1, 0); |
c2213350 | 4463 | XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1); |
a2889657 JB |
4464 | set_window_height (minibuf_window, 1, 0); |
4465 | ||
c2213350 KH |
4466 | XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f)); |
4467 | XSETFASTINT (mini_w->width, FRAME_WIDTH (f)); | |
a2889657 JB |
4468 | } |
4469 | } |