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