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