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