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