Commit | Line | Data |
---|---|---|
a2889657 | 1 | /* Display generation from window structure and buffer text. |
de3e8b15 | 2 | Copyright (C) 1985, 1986, 1987, 1988, 1992 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 | |
8 | the Free Software Foundation; either version 1, or (at your option) | |
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 | ||
21 | #include "config.h" | |
22 | #include <stdio.h> | |
23 | /*#include <ctype.h>*/ | |
24 | #undef NULL | |
25 | #include "lisp.h" | |
26 | #include "screen.h" | |
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" | |
35 | ||
36 | extern int interrupt_input; | |
37 | extern int command_loop_level; | |
38 | ||
39 | /* Nonzero means print newline before next minibuffer message. */ | |
40 | ||
41 | int noninteractive_need_newline; | |
42 | ||
43 | #define min(a, b) ((a) < (b) ? (a) : (b)) | |
44 | #define max(a, b) ((a) > (b) ? (a) : (b)) | |
45 | ||
46 | /* The buffer position of the first character appearing | |
47 | entirely or partially on the current screen line. | |
48 | Or zero, which disables the optimization for the current screen line. */ | |
49 | static int this_line_bufpos; | |
50 | ||
51 | /* Number of characters past the end of this line, | |
52 | including the terminating newline */ | |
53 | static int this_line_endpos; | |
54 | ||
55 | /* The vertical position of this screen line. */ | |
56 | static int this_line_vpos; | |
57 | ||
58 | /* Hpos value for start of display on this screen line. | |
59 | Usually zero, but negative if first character really began | |
60 | on previous line */ | |
61 | static int this_line_start_hpos; | |
62 | ||
63 | /* Buffer that this_line variables are describing. */ | |
64 | static struct buffer *this_line_buffer; | |
65 | ||
66 | /* Set by try_window_id to the vpos of first of any lines | |
67 | scrolled on to the bottom of the screen. These lines should | |
68 | not be included in any general scroll computation. */ | |
69 | static int scroll_bottom_vpos; | |
70 | ||
71 | /* Value of echo_area_glyphs when it was last acted on. | |
72 | If this is nonzero, there is a message on the screen | |
73 | in the minibuffer and it should be erased as soon | |
74 | as it is no longer requested to appear. */ | |
75 | char *previous_echo_glyphs; | |
76 | ||
77 | /* Nonzero means truncate lines in all windows less wide than the screen */ | |
78 | int truncate_partial_width_windows; | |
79 | ||
80 | Lisp_Object Vglobal_mode_string; | |
81 | ||
82 | /* Marker for where to display an arrow on top of the buffer text. */ | |
83 | Lisp_Object Voverlay_arrow_position; | |
84 | ||
85 | /* String to display for the arrow. */ | |
86 | Lisp_Object Voverlay_arrow_string; | |
87 | ||
88 | /* Values of those variables at last redisplay. */ | |
89 | Lisp_Object last_arrow_position, last_arrow_string; | |
90 | ||
91 | /* Nonzero if overlay arrow has been displayed once in this window. */ | |
92 | static int overlay_arrow_seen; | |
93 | ||
94 | /* If cursor motion alone moves point off screen, | |
95 | Try scrolling this many lines up or down if that will bring it back. */ | |
96 | int scroll_step; | |
97 | ||
98 | /* Nonzero if try_window_id has made blank lines at window bottom | |
99 | since the last redisplay that paused */ | |
100 | static int blank_end_of_window; | |
101 | ||
102 | /* Number of windows showing the buffer of the selected window. | |
103 | keyboard.c refers to this. */ | |
104 | int buffer_shared; | |
105 | ||
106 | /* display_text_line sets these to the screen position (origin 0) of point, | |
107 | whether the window is selected or not. | |
108 | Set one to -1 first to determine whether point was found afterwards. */ | |
109 | ||
110 | static int cursor_vpos; | |
111 | static int cursor_hpos; | |
112 | ||
113 | int debug_end_pos; | |
114 | ||
115 | /* Nonzero means display mode line highlighted */ | |
116 | int mode_line_inverse_video; | |
117 | ||
118 | static void echo_area_display (); | |
119 | void mark_window_display_accurate (); | |
120 | static void redisplay_windows (); | |
121 | static void redisplay_window (); | |
122 | static void try_window (); | |
123 | static int try_window_id (); | |
124 | static struct position *display_text_line (); | |
125 | static void display_mode_line (); | |
126 | static int display_mode_element (); | |
127 | static char *fmodetrunc (); | |
128 | static char *decode_mode_spec (); | |
129 | static int display_string (); | |
130 | ||
131 | /* Prompt to display in front of the minibuffer contents */ | |
132 | char *minibuf_prompt; | |
133 | ||
134 | /* Width in columns of current minibuffer prompt. */ | |
135 | int minibuf_prompt_width; | |
136 | ||
137 | /* Message to display instead of minibuffer contents | |
138 | This is what the functions error and message make, | |
139 | and command echoing uses it as well. | |
140 | It overrides the minibuf_prompt as well as the buffer. */ | |
141 | char *echo_area_glyphs; | |
142 | ||
143 | /* true iff we should redraw the mode lines on the next redisplay */ | |
144 | int update_mode_lines; | |
145 | ||
146 | /* Smallest number of characters before the gap | |
147 | at any time since last redisplay that finished. | |
148 | Valid for current buffer when try_window_id can be called. */ | |
149 | int beg_unchanged; | |
150 | ||
151 | /* Smallest number of characters after the gap | |
152 | at any time since last redisplay that finished. | |
153 | Valid for current buffer when try_window_id can be called. */ | |
154 | int end_unchanged; | |
155 | ||
156 | /* MODIFF as of last redisplay that finished; | |
157 | if it matches MODIFF, beg_unchanged and end_unchanged | |
158 | contain no useful information */ | |
159 | int unchanged_modified; | |
160 | ||
161 | /* Nonzero if head_clip or tail_clip of current buffer has changed | |
162 | since last redisplay that finished */ | |
163 | int clip_changed; | |
164 | ||
165 | /* Nonzero if window sizes or contents have changed | |
166 | since last redisplay that finished */ | |
167 | int windows_or_buffers_changed; | |
168 | ||
169 | \f | |
170 | #ifndef MULTI_SCREEN | |
171 | ||
172 | DEFUN ("redraw-display", Fredraw_display, Sredraw_display, 0, 0, "", | |
173 | "Clear the screen and output again what is supposed to appear on it.") | |
174 | () | |
175 | { | |
176 | if (screen_height == 0) abort (); /* Some bug zeros some core */ | |
177 | clear_screen (); | |
178 | fflush (stdout); | |
179 | clear_screen_records (); | |
180 | if (screen_height == 0) abort (); /* Some bug zeros some core */ | |
181 | windows_or_buffers_changed++; | |
182 | /* Mark all windows as INaccurate, | |
183 | so that every window will have its redisplay done. */ | |
184 | mark_window_display_accurate (XWINDOW (minibuf_window)->prev, 0); | |
185 | if (screen_height == 0) abort (); /* Some bug zeros some core */ | |
186 | return Qnil; | |
187 | } | |
188 | ||
189 | #endif /* not MULTI_SCREEN */ | |
190 | \f | |
9c74a0dd | 191 | /* Buffer used for messages formatted by `message'. */ |
a2889657 JB |
192 | char *message_buf; |
193 | ||
9c74a0dd JB |
194 | /* Nonzero if message_buf is being used by print; |
195 | zero if being used by message. */ | |
196 | int message_buf_print; | |
197 | ||
a2889657 JB |
198 | /* dump an informative message to the minibuf */ |
199 | /* VARARGS 1 */ | |
200 | ||
201 | void | |
202 | message (m, a1, a2, a3) | |
203 | char *m; | |
204 | { | |
205 | if (noninteractive) | |
206 | { | |
207 | if (noninteractive_need_newline) | |
208 | putc ('\n', stderr); | |
209 | noninteractive_need_newline = 0; | |
210 | fprintf (stderr, m, a1, a2, a3); | |
211 | fprintf (stderr, "\n"); | |
212 | fflush (stderr); | |
213 | } | |
6e8290aa | 214 | /* A null message buffer means that the screen hasn't really been |
8de2d90b JB |
215 | initialized yet. Error messages get reported properly by |
216 | cmd_error, so this must be just an informative message; toss it. */ | |
6e8290aa | 217 | else if (INTERACTIVE && SCREEN_MESSAGE_BUF (selected_screen)) |
a2889657 | 218 | { |
8de2d90b JB |
219 | #ifdef MULTI_SCREEN |
220 | choose_minibuf_screen (); | |
221 | Fmake_screen_visible (WINDOW_SCREEN (XWINDOW (minibuf_window))); | |
222 | #endif | |
223 | ||
265a9e55 | 224 | { |
a2889657 | 225 | #ifdef NO_ARG_ARRAY |
265a9e55 JB |
226 | int a[3]; |
227 | a[0] = a1; | |
228 | a[1] = a2; | |
229 | a[2] = a3; | |
a2889657 | 230 | |
265a9e55 JB |
231 | doprnt (SCREEN_MESSAGE_BUF (selected_screen), |
232 | SCREEN_WIDTH (selected_screen), m, 0, 3, a); | |
a2889657 | 233 | #else |
265a9e55 JB |
234 | doprnt (SCREEN_MESSAGE_BUF (selected_screen), |
235 | SCREEN_WIDTH (selected_screen), m, 0, 3, &a1); | |
6e8290aa | 236 | #endif /* NO_ARG_ARRAY */ |
265a9e55 | 237 | } |
a2889657 JB |
238 | |
239 | echo_area_glyphs = SCREEN_MESSAGE_BUF (selected_screen); | |
9c74a0dd JB |
240 | |
241 | /* Print should start at the beginning of the message | |
242 | buffer next time. */ | |
243 | message_buf_print = 0; | |
244 | ||
a2889657 JB |
245 | do_pending_window_change (); |
246 | echo_area_display (); | |
247 | update_screen (XSCREEN (XWINDOW (minibuf_window)->screen), 1, 1); | |
248 | do_pending_window_change (); | |
249 | } | |
250 | } | |
251 | ||
252 | /* Specify m, a string, as a message in the minibuf. */ | |
253 | void | |
254 | message1 (m) | |
255 | char *m; | |
256 | { | |
a2889657 JB |
257 | if (noninteractive) |
258 | { | |
259 | if (noninteractive_need_newline) | |
260 | putc ('\n', stderr); | |
261 | noninteractive_need_newline = 0; | |
262 | fprintf (stderr, "%s\n", m); | |
263 | fflush (stderr); | |
264 | } | |
6e8290aa | 265 | /* A null message buffer means that the screen hasn't really been |
8de2d90b JB |
266 | initialized yet. Error messages get reported properly by |
267 | cmd_error, so this must be just an informative message; toss it. */ | |
6e8290aa | 268 | else if (INTERACTIVE && SCREEN_MESSAGE_BUF (selected_screen)) |
a2889657 | 269 | { |
8de2d90b JB |
270 | #ifdef MULTI_SCREEN |
271 | choose_minibuf_screen (); | |
272 | Fmake_screen_visible (WINDOW_SCREEN (XWINDOW (minibuf_window))); | |
273 | #endif | |
274 | ||
a2889657 JB |
275 | echo_area_glyphs = m; |
276 | do_pending_window_change (); | |
277 | echo_area_display (); | |
278 | update_screen (XSCREEN (XWINDOW (minibuf_window)->screen), 1, 1); | |
279 | do_pending_window_change (); | |
280 | } | |
281 | } | |
282 | ||
283 | static void | |
284 | echo_area_display () | |
285 | { | |
286 | register int vpos; | |
287 | SCREEN_PTR s; | |
288 | ||
289 | #ifdef MULTI_SCREEN | |
290 | choose_minibuf_screen (); | |
8de2d90b | 291 | s = XSCREEN (WINDOW_SCREEN (XWINDOW (minibuf_window))); |
a2889657 | 292 | |
8de2d90b | 293 | if (! SCREEN_VISIBLE_P (s)) |
a2889657 JB |
294 | return; |
295 | #endif | |
296 | ||
297 | if (screen_garbaged) | |
298 | { | |
299 | Fredraw_display (); | |
300 | screen_garbaged = 0; | |
301 | } | |
302 | ||
303 | if (echo_area_glyphs || minibuf_level == 0) | |
304 | { | |
305 | vpos = XFASTINT (XWINDOW (minibuf_window)->top); | |
306 | get_display_line (s, vpos, 0); | |
307 | display_string (XWINDOW (minibuf_window), vpos, | |
308 | echo_area_glyphs ? echo_area_glyphs : "", | |
309 | 0, 0, 0, SCREEN_WIDTH (s)); | |
310 | ||
311 | /* If desired cursor location is on this line, put it at end of text */ | |
312 | if (SCREEN_CURSOR_Y (s) == vpos) | |
313 | SCREEN_CURSOR_X (s) = s->desired_glyphs->used[vpos]; | |
314 | } | |
315 | else if (!EQ (minibuf_window, selected_window)) | |
316 | windows_or_buffers_changed++; | |
317 | ||
318 | if (EQ (minibuf_window, selected_window)) | |
319 | this_line_bufpos = 0; | |
320 | ||
321 | previous_echo_glyphs = echo_area_glyphs; | |
322 | } | |
323 | \f | |
324 | /* Do a screen update, taking possible shortcuts into account. | |
325 | This is the main external entry point for redisplay. | |
326 | ||
327 | If the last redisplay displayed an echo area message and that | |
328 | message is no longer requested, we clear the echo area | |
329 | or bring back the minibuffer if that is in use. | |
330 | ||
331 | Everyone would like to have a hook here to call eval, | |
332 | but that cannot be done safely without a lot of changes elsewhere. | |
333 | This can be called from signal handlers; with alarms set up; | |
334 | or with synchronous processes running. | |
335 | See the function `echo' in keyboard.c. | |
336 | See Fcall_process; if you called it from here, it could be | |
337 | entered recursively. */ | |
338 | ||
339 | void | |
340 | redisplay () | |
341 | { | |
342 | register struct window *w = XWINDOW (selected_window); | |
343 | register int pause; | |
344 | int must_finish = 0; | |
345 | int all_windows; | |
346 | register int tlbufpos, tlendpos; | |
347 | struct position pos; | |
348 | extern int input_pending; | |
349 | ||
350 | if (noninteractive) | |
351 | return; | |
352 | ||
353 | /* Notice any pending interrupt request to change screen size. */ | |
354 | do_pending_window_change (); | |
355 | ||
356 | if (screen_garbaged) | |
357 | { | |
358 | Fredraw_display (); | |
359 | screen_garbaged = 0; | |
360 | } | |
361 | ||
6e8290aa JB |
362 | /* Normally the message* functions will have already displayed and |
363 | updated the echo area, but the screen may have been trashed, or | |
364 | the update may have been preempted, so display the echo area | |
365 | again here. */ | |
a2889657 JB |
366 | if (echo_area_glyphs || previous_echo_glyphs) |
367 | { | |
368 | echo_area_display (); | |
369 | must_finish = 1; | |
370 | } | |
371 | ||
372 | if (clip_changed || windows_or_buffers_changed) | |
373 | update_mode_lines++; | |
374 | ||
375 | /* Detect case that we need to write a star in the mode line. */ | |
376 | if (XFASTINT (w->last_modified) < MODIFF | |
377 | && XFASTINT (w->last_modified) <= current_buffer->save_modified) | |
378 | { | |
379 | w->update_mode_line = Qt; | |
380 | if (buffer_shared > 1) | |
381 | update_mode_lines++; | |
382 | } | |
383 | ||
384 | SCREEN_SCROLL_BOTTOM_VPOS (XSCREEN (w->screen)) = -1; | |
385 | ||
386 | all_windows = update_mode_lines || buffer_shared > 1; | |
a2889657 JB |
387 | |
388 | /* If specs for an arrow have changed, do thorough redisplay | |
389 | to ensure we remove any arrow that should no longer exist. */ | |
390 | if (Voverlay_arrow_position != last_arrow_position | |
391 | || Voverlay_arrow_string != last_arrow_string) | |
392 | all_windows = 1, clip_changed = 1; | |
393 | ||
394 | tlbufpos = this_line_bufpos; | |
395 | tlendpos = this_line_endpos; | |
265a9e55 | 396 | if (!all_windows && tlbufpos > 0 && NILP (w->update_mode_line) |
a2889657 JB |
397 | && SCREEN_VISIBLE_P (XSCREEN (w->screen)) |
398 | /* Make sure recorded data applies to current buffer, etc */ | |
399 | && this_line_buffer == current_buffer | |
400 | && current_buffer == XBUFFER (w->buffer) | |
265a9e55 | 401 | && NILP (w->force_start) |
a2889657 JB |
402 | /* Point must be on the line that we have info recorded about */ |
403 | && point >= tlbufpos | |
404 | && point <= Z - tlendpos | |
405 | /* All text outside that line, including its final newline, | |
406 | must be unchanged */ | |
407 | && (XFASTINT (w->last_modified) >= MODIFF | |
408 | || (beg_unchanged >= tlbufpos - 1 | |
409 | && GPT >= tlbufpos | |
05ba02eb JB |
410 | /* If selective display, can't optimize |
411 | if the changes start at the beginning of the line. */ | |
412 | && ((XTYPE (current_buffer->selective_display) == Lisp_Int | |
413 | && XINT (current_buffer->selective_display) > 0 | |
414 | ? (beg_unchanged >= tlbufpos | |
415 | && GPT > tlbufpos) | |
416 | : 1)) | |
a2889657 JB |
417 | && end_unchanged >= tlendpos |
418 | && Z - GPT >= tlendpos))) | |
419 | { | |
420 | if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n' | |
421 | && (tlbufpos == ZV | |
422 | || FETCH_CHAR (tlbufpos) == '\n')) | |
423 | /* Former continuation line has disappeared by becoming empty */ | |
424 | goto cancel; | |
425 | else if (XFASTINT (w->last_modified) < MODIFF | |
426 | || MINI_WINDOW_P (w)) | |
427 | { | |
428 | cursor_vpos = -1; | |
429 | overlay_arrow_seen = 0; | |
430 | display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos, | |
431 | pos_tab_offset (w, tlbufpos)); | |
432 | /* If line contains point, is not continued, | |
433 | and ends at same distance from eob as before, we win */ | |
434 | if (cursor_vpos >= 0 && this_line_bufpos | |
435 | && this_line_endpos == tlendpos) | |
436 | { | |
437 | if (XFASTINT (w->width) != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w)))) | |
438 | preserve_other_columns (w); | |
439 | goto update; | |
440 | } | |
441 | else | |
442 | goto cancel; | |
443 | } | |
444 | else if (point == XFASTINT (w->last_point)) | |
445 | { | |
446 | if (!must_finish) | |
447 | { | |
448 | do_pending_window_change (); | |
449 | return; | |
450 | } | |
451 | goto update; | |
452 | } | |
453 | else | |
454 | { | |
455 | pos = *compute_motion (tlbufpos, 0, | |
456 | XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0, | |
457 | point, 2, - (1 << (SHORTBITS - 1)), | |
458 | XFASTINT (w->width) - 1 | |
459 | - (XFASTINT (w->width) + XFASTINT (w->left) | |
460 | != SCREEN_WIDTH (selected_screen)), | |
de3e8b15 JB |
461 | XINT (w->hscroll), |
462 | pos_tab_offset (w, tlbufpos)); | |
a2889657 JB |
463 | if (pos.vpos < 1) |
464 | { | |
465 | SCREEN_CURSOR_X (selected_screen) | |
466 | = XFASTINT (w->left) + max (pos.hpos, 0); | |
467 | SCREEN_CURSOR_Y (selected_screen) = this_line_vpos; | |
468 | goto update; | |
469 | } | |
470 | else | |
471 | goto cancel; | |
472 | } | |
473 | cancel: | |
474 | /* Text changed drastically or point moved off of line */ | |
475 | cancel_line (this_line_vpos, selected_screen); | |
476 | } | |
477 | ||
478 | this_line_bufpos = 0; | |
479 | all_windows |= buffer_shared > 1; | |
480 | ||
481 | if (all_windows) | |
482 | { | |
483 | #ifdef MULTI_SCREEN | |
484 | Lisp_Object tail; | |
485 | ||
486 | /* Recompute # windows showing selected buffer. | |
8de2d90b | 487 | This will be incremented each time such a window is displayed. */ |
a2889657 JB |
488 | buffer_shared = 0; |
489 | ||
490 | for (tail = Vscreen_list; CONSP (tail); tail = XCONS (tail)->cdr) | |
491 | { | |
492 | SCREEN_PTR s; | |
493 | ||
494 | if (XTYPE (XCONS (tail)->car) != Lisp_Screen) | |
495 | continue; | |
496 | ||
497 | s = XSCREEN (XCONS (tail)->car); | |
498 | if (s->visible) | |
8de2d90b JB |
499 | /* Redraw its windows. */ |
500 | redisplay_windows (SCREEN_ROOT_WINDOW (s)); | |
a2889657 JB |
501 | } |
502 | #else | |
503 | redisplay_windows (SCREEN_ROOT_WINDOW (s)); | |
504 | #endif /* not MULTI_SCREEN */ | |
505 | } | |
506 | else if (SCREEN_VISIBLE_P (selected_screen)) | |
507 | { | |
508 | redisplay_window (selected_window, 1); | |
509 | if (XFASTINT (w->width) != SCREEN_WIDTH (selected_screen)) | |
510 | preserve_other_columns (w); | |
511 | } | |
512 | ||
513 | update: | |
514 | /* Prevent various kinds of signals during display update. | |
515 | stdio is not robust about handling signals, | |
516 | which can cause an apparent I/O error. */ | |
517 | if (interrupt_input) | |
518 | unrequest_sigio (); | |
519 | stop_polling (); | |
520 | ||
521 | #ifdef MULTI_SCREEN | |
522 | if (all_windows) | |
523 | { | |
524 | Lisp_Object tail; | |
525 | ||
526 | pause = 0; | |
527 | ||
528 | for (tail = Vscreen_list; CONSP (tail); tail = XCONS (tail)->cdr) | |
529 | { | |
530 | SCREEN_PTR s; | |
531 | ||
532 | if (XTYPE (XCONS (tail)->car) != Lisp_Screen) | |
533 | continue; | |
534 | ||
535 | s = XSCREEN (XCONS (tail)->car); | |
536 | if (s->visible) | |
537 | { | |
8de2d90b | 538 | pause |= update_screen (s, 0, 0); |
a2889657 JB |
539 | if (!pause) |
540 | mark_window_display_accurate (s->root_window, 1); | |
541 | } | |
542 | } | |
543 | } | |
544 | else | |
545 | #endif /* MULTI_SCREEN */ | |
6e8290aa JB |
546 | { |
547 | if (SCREEN_VISIBLE_P (selected_screen)) | |
548 | pause = update_screen (selected_screen, 0, 0); | |
549 | #ifdef MULTI_SCREEN | |
8de2d90b JB |
550 | /* We may have called echo_area_display at the top of this |
551 | function. If the echo area is on another screen, that may | |
552 | have put text on a screen other than the selected one, so the | |
553 | above call to update_screen would not have caught it. Catch | |
554 | it here. */ | |
555 | { | |
556 | SCREEN_PTR mini_screen = | |
557 | XSCREEN (WINDOW_SCREEN (XWINDOW (minibuf_window))); | |
558 | ||
559 | if (mini_screen != selected_screen) | |
560 | pause |= update_screen (mini_screen, 0, 0); | |
561 | } | |
6e8290aa JB |
562 | #endif |
563 | } | |
a2889657 JB |
564 | |
565 | /* If screen does not match, prevent doing single-line-update next time. | |
566 | Also, don't forget to check every line to update the arrow. */ | |
567 | if (pause) | |
568 | { | |
569 | this_line_bufpos = 0; | |
265a9e55 | 570 | if (!NILP (last_arrow_position)) |
a2889657 JB |
571 | { |
572 | last_arrow_position = Qt; | |
573 | last_arrow_string = Qt; | |
574 | } | |
575 | /* If we pause after scrolling, some lines in current_screen | |
576 | may be null, so preserve_other_columns won't be able to | |
577 | preserve all the vertical-bar separators. So, avoid using it | |
578 | in that case. */ | |
579 | if (XFASTINT (w->width) != SCREEN_WIDTH (selected_screen)) | |
580 | update_mode_lines = 1; | |
581 | } | |
582 | ||
583 | /* Now text on screen agrees with windows, so | |
584 | put info into the windows for partial redisplay to follow */ | |
585 | ||
586 | if (!pause) | |
587 | { | |
588 | register struct buffer *b = XBUFFER (w->buffer); | |
589 | ||
590 | blank_end_of_window = 0; | |
591 | clip_changed = 0; | |
592 | unchanged_modified = BUF_MODIFF (b); | |
593 | beg_unchanged = BUF_GPT (b) - BUF_BEG (b); | |
594 | end_unchanged = BUF_Z (b) - BUF_GPT (b); | |
595 | ||
596 | XFASTINT (w->last_point) = BUF_PT (b); | |
597 | XFASTINT (w->last_point_x) = SCREEN_CURSOR_X (selected_screen); | |
598 | XFASTINT (w->last_point_y) = SCREEN_CURSOR_Y (selected_screen); | |
599 | ||
600 | if (all_windows) | |
601 | mark_window_display_accurate (XWINDOW (minibuf_window)->prev, 1); | |
602 | else | |
603 | { | |
604 | w->update_mode_line = Qnil; | |
605 | XFASTINT (w->last_modified) = BUF_MODIFF (b); | |
606 | w->window_end_valid = Qt; | |
607 | last_arrow_position = Voverlay_arrow_position; | |
608 | last_arrow_string = Voverlay_arrow_string; | |
609 | } | |
610 | update_mode_lines = 0; | |
611 | windows_or_buffers_changed = 0; | |
612 | } | |
613 | ||
614 | /* Start SIGIO interrupts coming again. | |
615 | Having them off during the code above | |
616 | makes it less likely one will discard output, | |
617 | but not impossible, since there might be stuff | |
618 | in the system buffer here. | |
619 | But it is much hairier to try to do anything about that. */ | |
620 | ||
621 | if (interrupt_input) | |
622 | request_sigio (); | |
623 | start_polling (); | |
624 | ||
625 | /* Change screen size now if a change is pending. */ | |
626 | do_pending_window_change (); | |
627 | } | |
628 | ||
629 | /* Redisplay, but leave alone any recent echo area message | |
630 | unless another message has been requested in its place. | |
631 | ||
632 | This is useful in situations where you need to redisplay but no | |
633 | user action has occurred, making it inappropriate for the message | |
634 | area to be cleared. See tracking_off and | |
635 | wait_reading_process_input for examples of these situations. */ | |
636 | ||
637 | redisplay_preserve_echo_area () | |
638 | { | |
639 | if (echo_area_glyphs == 0 && previous_echo_glyphs != 0) | |
640 | { | |
641 | echo_area_glyphs = previous_echo_glyphs; | |
642 | redisplay (); | |
643 | echo_area_glyphs = 0; | |
644 | } | |
645 | else | |
646 | redisplay (); | |
647 | } | |
648 | ||
649 | void | |
650 | mark_window_display_accurate (window, flag) | |
651 | Lisp_Object window; | |
652 | int flag; | |
653 | { | |
654 | register struct window *w; | |
655 | ||
265a9e55 | 656 | for (;!NILP (window); window = w->next) |
a2889657 JB |
657 | { |
658 | w = XWINDOW (window); | |
659 | ||
265a9e55 | 660 | if (!NILP (w->buffer)) |
a2889657 JB |
661 | XFASTINT (w->last_modified) |
662 | = !flag ? 0 | |
663 | : XBUFFER (w->buffer) == current_buffer | |
664 | ? MODIFF : BUF_MODIFF (XBUFFER (w->buffer)); | |
665 | w->window_end_valid = Qt; | |
666 | w->update_mode_line = Qnil; | |
667 | ||
265a9e55 | 668 | if (!NILP (w->vchild)) |
a2889657 | 669 | mark_window_display_accurate (w->vchild, flag); |
265a9e55 | 670 | if (!NILP (w->hchild)) |
a2889657 JB |
671 | mark_window_display_accurate (w->hchild, flag); |
672 | } | |
673 | ||
674 | if (flag) | |
675 | { | |
676 | last_arrow_position = Voverlay_arrow_position; | |
677 | last_arrow_string = Voverlay_arrow_string; | |
678 | } | |
679 | else | |
680 | { | |
681 | /* t is unequal to any useful value of Voverlay_arrow_... */ | |
682 | last_arrow_position = Qt; | |
683 | last_arrow_string = Qt; | |
684 | } | |
685 | } | |
686 | \f | |
687 | int do_id = 1; | |
688 | ||
689 | static void | |
690 | redisplay_windows (window) | |
691 | Lisp_Object window; | |
692 | { | |
265a9e55 | 693 | for (; !NILP (window); window = XWINDOW (window)->next) |
a2889657 JB |
694 | redisplay_window (window, 0); |
695 | } | |
696 | ||
697 | static void | |
698 | redisplay_window (window, just_this_one) | |
699 | Lisp_Object window; | |
700 | int just_this_one; | |
701 | { | |
702 | register struct window *w = XWINDOW (window); | |
703 | SCREEN_PTR s = XSCREEN (w->screen); | |
704 | int height; | |
705 | register int lpoint = point; | |
706 | struct buffer *old = current_buffer; | |
707 | register int width = XFASTINT (w->width) - 1 | |
708 | - (XFASTINT (w->width) + XFASTINT (w->left) | |
709 | != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w)))); | |
710 | register int startp; | |
711 | register int hscroll = XINT (w->hscroll); | |
712 | struct position pos; | |
713 | int opoint; | |
714 | int tem; | |
715 | int window_needs_modeline; | |
716 | ||
717 | if (SCREEN_HEIGHT (s) == 0) abort (); /* Some bug zeros some core */ | |
718 | ||
719 | /* If this is a combination window, do its children; that's all. */ | |
720 | ||
265a9e55 | 721 | if (!NILP (w->vchild)) |
a2889657 JB |
722 | { |
723 | redisplay_windows (w->vchild); | |
724 | return; | |
725 | } | |
265a9e55 | 726 | if (!NILP (w->hchild)) |
a2889657 JB |
727 | { |
728 | redisplay_windows (w->hchild); | |
729 | return; | |
730 | } | |
265a9e55 | 731 | if (NILP (w->buffer)) |
a2889657 | 732 | abort (); |
8de2d90b JB |
733 | |
734 | height = window_internal_height (w); | |
735 | ||
736 | if (MINI_WINDOW_P (w)) | |
737 | { | |
738 | if (w == XWINDOW (minibuf_window)) | |
739 | { | |
740 | if (echo_area_glyphs) | |
741 | /* We've already displayed the echo area glyphs, if any. */ | |
742 | return; | |
743 | } | |
744 | else | |
745 | { | |
746 | /* This is a minibuffer, but it's not the currently active one, so | |
747 | clear it. */ | |
748 | int vpos = XFASTINT (XWINDOW (SCREEN_MINIBUF_WINDOW (s))->top); | |
749 | int i; | |
750 | ||
751 | for (i = 0; i < height; i++) | |
752 | { | |
753 | get_display_line (s, vpos + i, 0); | |
754 | display_string (w, vpos + i, "", 0, 0, 0, width); | |
755 | } | |
756 | ||
757 | return; | |
758 | } | |
759 | } | |
a2889657 JB |
760 | |
761 | if (update_mode_lines) | |
762 | w->update_mode_line = Qt; | |
763 | ||
764 | /* Otherwise set up data on this window; select its buffer and point value */ | |
765 | ||
a2889657 JB |
766 | current_buffer = XBUFFER (w->buffer); |
767 | opoint = point; | |
768 | ||
769 | /* Count number of windows showing the selected buffer. */ | |
770 | ||
771 | if (!just_this_one | |
772 | && current_buffer == XBUFFER (XWINDOW (selected_window)->buffer)) | |
773 | buffer_shared++; | |
774 | ||
775 | /* POINT refers normally to the selected window. | |
776 | For any other window, set up appropriate value. */ | |
777 | ||
778 | if (!EQ (window, selected_window)) | |
779 | { | |
780 | SET_PT (marker_position (w->pointm)); | |
781 | if (point < BEGV) | |
782 | { | |
265a9e55 | 783 | SET_PT (BEGV); |
a2889657 JB |
784 | Fset_marker (w->pointm, make_number (point), Qnil); |
785 | } | |
786 | else if (point > (ZV - 1)) | |
787 | { | |
265a9e55 | 788 | SET_PT (ZV); |
a2889657 JB |
789 | Fset_marker (w->pointm, make_number (point), Qnil); |
790 | } | |
791 | } | |
792 | ||
793 | /* If window-start is screwed up, choose a new one. */ | |
a2889657 JB |
794 | if (XMARKER (w->start)->buffer != current_buffer) |
795 | goto recenter; | |
796 | ||
797 | startp = marker_position (w->start); | |
798 | ||
8de2d90b JB |
799 | /* Handle case where place to start displaying has been specified, |
800 | unless the specified location is outside the visible range. */ | |
265a9e55 | 801 | if (!NILP (w->force_start)) |
a2889657 JB |
802 | { |
803 | w->update_mode_line = Qt; | |
804 | w->force_start = Qnil; | |
805 | XFASTINT (w->last_modified) = 0; | |
8de2d90b JB |
806 | if (startp < BEGV) startp = BEGV; |
807 | if (startp > ZV) startp = ZV; | |
a2889657 JB |
808 | try_window (window, startp); |
809 | if (cursor_vpos < 0) | |
810 | { | |
811 | /* If point does not appear, move point so it does appear */ | |
812 | pos = *compute_motion (startp, 0, | |
813 | ((EQ (window, minibuf_window) && startp == 1) | |
814 | ? minibuf_prompt_width : 0) | |
815 | + | |
816 | (hscroll ? 1 - hscroll : 0), | |
817 | ZV, height / 2, | |
818 | - (1 << (SHORTBITS - 1)), | |
819 | width, hscroll, pos_tab_offset (w, startp)); | |
820 | SET_PT (pos.bufpos); | |
821 | if (w != XWINDOW (SCREEN_SELECTED_WINDOW (s))) | |
822 | Fset_marker (w->pointm, make_number (point), Qnil); | |
823 | else | |
824 | { | |
825 | lpoint = point; | |
826 | SCREEN_CURSOR_X (s) = max (0, pos.hpos) + XFASTINT (w->left); | |
827 | SCREEN_CURSOR_Y (s) = pos.vpos + XFASTINT (w->top); | |
828 | } | |
829 | } | |
830 | goto done; | |
831 | } | |
832 | ||
833 | /* Handle case where text has not changed, only point, | |
834 | and it has not moved off the screen */ | |
835 | ||
836 | /* This code is not used for minibuffer for the sake of | |
837 | the case of redisplaying to replace an echo area message; | |
838 | since in that case the minibuffer contents per se are usually unchanged. | |
839 | This code is of no real use in the minibuffer since | |
840 | the handling of this_line_bufpos, etc., | |
841 | in redisplay handles the same cases. */ | |
842 | ||
843 | if (XFASTINT (w->last_modified) >= MODIFF | |
844 | && point >= startp && !clip_changed | |
845 | && (just_this_one || XFASTINT (w->width) == SCREEN_WIDTH (s)) | |
846 | && !EQ (window, minibuf_window)) | |
847 | { | |
848 | pos = *compute_motion (startp, 0, (hscroll ? 1 - hscroll : 0), | |
849 | point, height + 1, 10000, width, hscroll, | |
850 | pos_tab_offset (w, startp)); | |
851 | ||
852 | if (pos.vpos < height) | |
853 | { | |
854 | /* Ok, point is still on screen */ | |
855 | if (w == XWINDOW (SCREEN_SELECTED_WINDOW (s))) | |
856 | { | |
857 | /* These variables are supposed to be origin 1 */ | |
858 | SCREEN_CURSOR_X (s) = max (0, pos.hpos) + XFASTINT (w->left); | |
859 | SCREEN_CURSOR_Y (s) = pos.vpos + XFASTINT (w->top); | |
860 | } | |
861 | /* This doesn't do the trick, because if a window to the right of | |
862 | this one must be redisplayed, this does nothing because there | |
863 | is nothing in DesiredScreen yet, and then the other window is | |
864 | redisplayed, making likes that are empty in this window's columns. | |
865 | if (XFASTINT (w->width) != SCREEN_WIDTH (s)) | |
866 | preserve_my_columns (w); | |
867 | */ | |
868 | goto done; | |
869 | } | |
870 | /* Don't bother trying redisplay with same start; | |
871 | we already know it will lose */ | |
872 | } | |
873 | /* If current starting point was originally the beginning of a line | |
874 | but no longer is, find a new starting point. */ | |
265a9e55 | 875 | else if (!NILP (w->start_at_line_beg) |
a2889657 JB |
876 | && !(startp == BEGV |
877 | || FETCH_CHAR (startp - 1) == '\n')) | |
878 | { | |
879 | goto recenter; | |
880 | } | |
881 | else if (just_this_one && !MINI_WINDOW_P (w) | |
882 | && point >= startp | |
883 | && XFASTINT (w->last_modified) | |
884 | && ! EQ (w->window_end_valid, Qnil) | |
885 | && do_id && !clip_changed | |
886 | && !blank_end_of_window | |
887 | && XFASTINT (w->width) == SCREEN_WIDTH (s) | |
888 | && EQ (last_arrow_position, Voverlay_arrow_position) | |
889 | && EQ (last_arrow_string, Voverlay_arrow_string) | |
890 | && (tem = try_window_id (SCREEN_SELECTED_WINDOW (s))) | |
891 | && tem != -2) | |
892 | { | |
893 | /* tem > 0 means success. tem == -1 means choose new start. | |
894 | tem == -2 means try again with same start, | |
895 | and nothing but whitespace follows the changed stuff. | |
896 | tem == 0 means try again with same start. */ | |
897 | if (tem > 0) | |
898 | goto done; | |
899 | } | |
900 | else if (startp >= BEGV && startp <= ZV | |
901 | /* Avoid starting display at end of buffer! */ | |
8de2d90b | 902 | && (startp < ZV || startp == BEGV |
a2889657 JB |
903 | || (XFASTINT (w->last_modified) >= MODIFF))) |
904 | { | |
905 | /* Try to redisplay starting at same place as before */ | |
906 | /* If point has not moved off screen, accept the results */ | |
907 | try_window (window, startp); | |
908 | if (cursor_vpos >= 0) | |
909 | goto done; | |
910 | else | |
911 | cancel_my_columns (w); | |
912 | } | |
913 | ||
914 | XFASTINT (w->last_modified) = 0; | |
915 | w->update_mode_line = Qt; | |
916 | ||
917 | /* Try to scroll by specified few lines */ | |
918 | ||
919 | if (scroll_step && !clip_changed) | |
920 | { | |
921 | if (point > startp) | |
922 | { | |
923 | pos = *vmotion (Z - XFASTINT (w->window_end_pos), | |
924 | scroll_step, width, hscroll, window); | |
925 | if (pos.vpos >= height) | |
926 | goto scroll_fail; | |
927 | } | |
928 | ||
929 | pos = *vmotion (startp, point < startp ? - scroll_step : scroll_step, | |
930 | width, hscroll, window); | |
931 | ||
932 | if (point >= pos.bufpos) | |
933 | { | |
934 | try_window (window, pos.bufpos); | |
935 | if (cursor_vpos >= 0) | |
936 | goto done; | |
937 | else | |
938 | cancel_my_columns (w); | |
939 | } | |
940 | scroll_fail: ; | |
941 | } | |
942 | ||
943 | /* Finally, just choose place to start which centers point */ | |
944 | ||
945 | recenter: | |
946 | pos = *vmotion (point, - height / 2, width, hscroll, window); | |
947 | try_window (window, pos.bufpos); | |
948 | ||
949 | startp = marker_position (w->start); | |
950 | w->start_at_line_beg = | |
951 | (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil; | |
952 | ||
953 | done: | |
954 | /* If window not full width, must redo its mode line | |
955 | if the window to its side is being redone */ | |
265a9e55 | 956 | if ((!NILP (w->update_mode_line) |
a2889657 JB |
957 | || (!just_this_one && width < SCREEN_WIDTH (s) - 1)) |
958 | && height != XFASTINT (w->height)) | |
959 | display_mode_line (w); | |
960 | ||
961 | SET_PT (opoint); | |
962 | current_buffer = old; | |
963 | SET_PT (lpoint); | |
964 | } | |
965 | \f | |
966 | /* Do full redisplay on one window, starting at position `pos'. */ | |
967 | ||
968 | static void | |
969 | try_window (window, pos) | |
970 | Lisp_Object window; | |
971 | register int pos; | |
972 | { | |
973 | register struct window *w = XWINDOW (window); | |
974 | register int height = window_internal_height (w); | |
975 | register int vpos = XFASTINT (w->top); | |
976 | register int last_text_vpos = vpos; | |
977 | int tab_offset = pos_tab_offset (w, pos); | |
978 | SCREEN_PTR s = XSCREEN (w->screen); | |
979 | int width = XFASTINT (w->width) - 1 | |
980 | - (XFASTINT (w->width) + XFASTINT (w->left) != SCREEN_WIDTH (s)); | |
981 | struct position val; | |
982 | ||
983 | Fset_marker (w->start, make_number (pos), Qnil); | |
984 | cursor_vpos = -1; | |
985 | overlay_arrow_seen = 0; | |
986 | val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0; | |
987 | ||
988 | while (--height >= 0) | |
989 | { | |
990 | val = *display_text_line (w, pos, vpos, val.hpos, tab_offset); | |
991 | tab_offset += width; | |
992 | if (val.vpos) tab_offset = 0; | |
993 | vpos++; | |
994 | if (pos != val.bufpos) | |
995 | last_text_vpos | |
996 | /* Next line, unless prev line ended in end of buffer with no cr */ | |
997 | = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n'); | |
998 | pos = val.bufpos; | |
999 | } | |
1000 | ||
1001 | /* If last line is continued in middle of character, | |
1002 | include the split character in the text considered on the screen */ | |
1003 | if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0)) | |
1004 | pos++; | |
1005 | ||
1006 | /* If bottom just moved off end of screen, change mode line percentage. */ | |
1007 | if (XFASTINT (w->window_end_pos) == 0 | |
1008 | && Z != pos) | |
1009 | w->update_mode_line = Qt; | |
1010 | ||
1011 | /* Say where last char on screen will be, once redisplay is finished. */ | |
1012 | XFASTINT (w->window_end_pos) = Z - pos; | |
1013 | XFASTINT (w->window_end_vpos) = last_text_vpos - XFASTINT (w->top); | |
1014 | /* But that is not valid info until redisplay finishes. */ | |
1015 | w->window_end_valid = Qnil; | |
1016 | } | |
1017 | \f | |
1018 | /* Try to redisplay when buffer is modified locally, | |
1019 | computing insert/delete line to preserve text outside | |
1020 | the bounds of the changes. | |
1021 | Return 1 if successful, 0 if if cannot tell what to do, | |
1022 | or -1 to tell caller to find a new window start, | |
1023 | or -2 to tell caller to do normal redisplay with same window start. */ | |
1024 | ||
1025 | static int | |
1026 | try_window_id (window) | |
1027 | Lisp_Object window; | |
1028 | { | |
1029 | int pos; | |
1030 | register struct window *w = XWINDOW (window); | |
1031 | register int height = window_internal_height (w); | |
1032 | SCREEN_PTR s = XSCREEN (w->screen); | |
1033 | int top = XFASTINT (w->top); | |
1034 | int start = marker_position (w->start); | |
1035 | int width = XFASTINT (w->width) - 1 | |
1036 | - (XFASTINT (w->width) + XFASTINT (w->left) != SCREEN_WIDTH (s)); | |
1037 | int hscroll = XINT (w->hscroll); | |
1038 | int lmargin = hscroll > 0 ? 1 - hscroll : 0; | |
1039 | register int vpos; | |
1040 | register int i, tem; | |
1041 | int last_text_vpos = 0; | |
1042 | int stop_vpos; | |
1043 | ||
1044 | struct position val, bp, ep, xp, pp; | |
1045 | int scroll_amount = 0; | |
1046 | int delta; | |
1047 | int tab_offset, epto; | |
1048 | ||
1049 | if (GPT - BEG < beg_unchanged) | |
1050 | beg_unchanged = GPT - BEG; | |
1051 | if (Z - GPT < end_unchanged) | |
1052 | end_unchanged = Z - GPT; | |
1053 | ||
1054 | if (beg_unchanged + 1 < start) | |
1055 | return 0; /* Give up if changes go above top of window */ | |
1056 | ||
1057 | /* Find position before which nothing is changed. */ | |
1058 | bp = *compute_motion (start, 0, lmargin, | |
f7be7f78 | 1059 | beg_unchanged + 1, height + 1, 0, width, hscroll, |
a2889657 JB |
1060 | pos_tab_offset (w, start)); |
1061 | if (bp.vpos >= height) | |
6e8290aa JB |
1062 | { |
1063 | if (point < bp.bufpos && !bp.contin) | |
1064 | { | |
1065 | /* All changes are below the screen, and point is on the screen. | |
1066 | We don't need to change the screen at all. | |
1067 | But we need to update window_end_pos to account for | |
1068 | any change in buffer size. */ | |
f7be7f78 JB |
1069 | bp = *compute_motion (start, 0, lmargin, |
1070 | Z, height, 0, | |
1071 | width, hscroll, pos_tab_offset (w, start)); | |
6e8290aa JB |
1072 | XFASTINT (w->window_end_vpos) = height; |
1073 | XFASTINT (w->window_end_pos) = Z - bp.bufpos; | |
1074 | return 1; | |
1075 | } | |
1076 | return 0; | |
1077 | } | |
a2889657 JB |
1078 | |
1079 | vpos = bp.vpos; | |
1080 | ||
1081 | /* Find beginning of that screen line. Must display from there. */ | |
1082 | bp = *vmotion (bp.bufpos, 0, width, hscroll, window); | |
1083 | ||
1084 | pos = bp.bufpos; | |
1085 | val.hpos = lmargin; | |
1086 | if (pos < start) | |
1087 | return -1; | |
1088 | ||
1089 | /* If about to start displaying at the beginning of a continuation line, | |
1090 | really start with previous screen line, in case it was not | |
1091 | continued when last redisplayed */ | |
05ba02eb JB |
1092 | if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0) |
1093 | || | |
1094 | /* Likewise if we have to worry about selective display. */ | |
1095 | (XTYPE (current_buffer->selective_display) == Lisp_Int | |
1096 | && XINT (current_buffer->selective_display) > 0 | |
1097 | && bp.bufpos - 1 == beg_unchanged && vpos > 0)) | |
a2889657 JB |
1098 | { |
1099 | bp = *vmotion (bp.bufpos, -1, width, hscroll, window); | |
1100 | --vpos; | |
1101 | pos = bp.bufpos; | |
1102 | } | |
1103 | ||
1104 | if (bp.contin && bp.hpos != lmargin) | |
1105 | { | |
1106 | val.hpos = bp.prevhpos - width + lmargin; | |
1107 | pos--; | |
1108 | } | |
1109 | ||
1110 | bp.vpos = vpos; | |
1111 | ||
1112 | /* Find first visible newline after which no more is changed. */ | |
1113 | tem = find_next_newline (Z - max (end_unchanged, Z - ZV), 1); | |
1114 | if (XTYPE (current_buffer->selective_display) == Lisp_Int | |
1115 | && XINT (current_buffer->selective_display) > 0) | |
1116 | while (tem < ZV - 1 | |
1117 | && (position_indentation (tem) | |
1118 | >= XINT (current_buffer->selective_display))) | |
1119 | tem = find_next_newline (tem, 1); | |
1120 | ||
1121 | /* Compute the cursor position after that newline. */ | |
1122 | ep = *compute_motion (pos, vpos, val.hpos, tem, | |
1123 | height, - (1 << (SHORTBITS - 1)), | |
1124 | width, hscroll, pos_tab_offset (w, bp.bufpos)); | |
1125 | ||
1126 | /* If changes reach past the text available on the screen, | |
1127 | just display rest of screen. */ | |
1128 | if (ep.bufpos > Z - XFASTINT (w->window_end_pos)) | |
1129 | stop_vpos = height; | |
1130 | else | |
1131 | stop_vpos = ep.vpos; | |
1132 | ||
1133 | /* If no newline before ep, the line ep is on includes some changes | |
1134 | that must be displayed. Make sure we don't stop before it. */ | |
1135 | /* Also, if changes reach all the way until ep.bufpos, | |
1136 | it is possible that something was deleted after the | |
1137 | newline before it, so the following line must be redrawn. */ | |
1138 | if (stop_vpos == ep.vpos | |
1139 | && (ep.bufpos == BEGV | |
1140 | || FETCH_CHAR (ep.bufpos - 1) != '\n' | |
1141 | || ep.bufpos == Z - end_unchanged)) | |
1142 | stop_vpos = ep.vpos + 1; | |
1143 | ||
1144 | cursor_vpos = -1; | |
1145 | overlay_arrow_seen = 0; | |
1146 | ||
1147 | /* If changes do not reach to bottom of window, | |
1148 | figure out how much to scroll the rest of the window */ | |
1149 | if (stop_vpos < height) | |
1150 | { | |
1151 | /* Now determine how far up or down the rest of the window has moved */ | |
1152 | epto = pos_tab_offset (w, ep.bufpos); | |
1153 | xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, | |
1154 | Z - XFASTINT (w->window_end_pos), | |
1155 | 10000, 0, width, hscroll, epto); | |
1156 | scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos); | |
1157 | ||
1158 | /* Is everything on screen below the changes whitespace? | |
1159 | If so, no scrolling is really necessary. */ | |
1160 | for (i = ep.bufpos; i < xp.bufpos; i++) | |
1161 | { | |
1162 | tem = FETCH_CHAR (i); | |
1163 | if (tem != ' ' && tem != '\n' && tem != '\t') | |
1164 | break; | |
1165 | } | |
1166 | if (i == xp.bufpos) | |
1167 | return -2; | |
1168 | ||
1169 | XFASTINT (w->window_end_vpos) += scroll_amount; | |
1170 | ||
1171 | /* Before doing any scrolling, verify that point will be on screen. */ | |
1172 | if (point > ep.bufpos && !(point <= xp.bufpos && xp.bufpos < height)) | |
1173 | { | |
1174 | if (point <= xp.bufpos) | |
1175 | { | |
1176 | pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos, | |
1177 | point, height, - (1 << (SHORTBITS - 1)), | |
1178 | width, hscroll, epto); | |
1179 | } | |
1180 | else | |
1181 | { | |
1182 | pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos, | |
1183 | point, height, - (1 << (SHORTBITS - 1)), | |
1184 | width, hscroll, pos_tab_offset (w, xp.bufpos)); | |
1185 | } | |
1186 | if (pp.bufpos < point || pp.vpos == height) | |
1187 | return 0; | |
1188 | cursor_vpos = pp.vpos + top; | |
1189 | cursor_hpos = pp.hpos + XFASTINT (w->left); | |
1190 | } | |
1191 | ||
1192 | if (stop_vpos - scroll_amount >= height | |
1193 | || ep.bufpos == xp.bufpos) | |
1194 | { | |
1195 | if (scroll_amount < 0) | |
1196 | stop_vpos -= scroll_amount; | |
1197 | scroll_amount = 0; | |
1198 | /* In this path, we have altered window_end_vpos | |
1199 | and not left it negative. | |
1200 | We must make sure that, in case display is preempted | |
1201 | before the screen changes to reflect what we do here, | |
1202 | further updates will not come to try_window_id | |
1203 | and assume the screen and window_end_vpos match. */ | |
1204 | blank_end_of_window = 1; | |
1205 | } | |
1206 | else if (!scroll_amount) | |
1207 | {} | |
1208 | else if (bp.bufpos == Z - end_unchanged) | |
1209 | { | |
1210 | /* If reprinting everything is nearly as fast as scrolling, | |
1211 | don't bother scrolling. Can happen if lines are short. */ | |
1212 | if (scroll_cost (s, bp.vpos + top - scroll_amount, | |
1213 | top + height - max (0, scroll_amount), | |
1214 | scroll_amount) | |
1215 | > xp.bufpos - bp.bufpos - 20) | |
1216 | /* Return "try normal display with same window-start." | |
1217 | Too bad we can't prevent further scroll-thinking. */ | |
1218 | return -2; | |
1219 | /* If pure deletion, scroll up as many lines as possible. | |
1220 | In common case of killing a line, this can save the | |
1221 | following line from being overwritten by scrolling | |
1222 | and therefore having to be redrawn. */ | |
1223 | tem = scroll_screen_lines (s, bp.vpos + top - scroll_amount, | |
1224 | top + height - max (0, scroll_amount), | |
1225 | scroll_amount); | |
1226 | if (!tem) stop_vpos = height; | |
1227 | } | |
1228 | else if (scroll_amount) | |
1229 | { | |
1230 | /* If reprinting everything is nearly as fast as scrolling, | |
1231 | don't bother scrolling. Can happen if lines are short. */ | |
1232 | /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an | |
1233 | overestimate of cost of reprinting, since xp.bufpos | |
1234 | would end up below the bottom of the window. */ | |
1235 | if (scroll_cost (s, ep.vpos + top - scroll_amount, | |
1236 | top + height - max (0, scroll_amount), | |
1237 | scroll_amount) | |
1238 | > xp.bufpos - ep.bufpos - 20) | |
1239 | /* Return "try normal display with same window-start." | |
1240 | Too bad we can't prevent further scroll-thinking. */ | |
1241 | return -2; | |
1242 | tem = scroll_screen_lines (s, ep.vpos + top - scroll_amount, | |
1243 | top + height - max (0, scroll_amount), | |
1244 | scroll_amount); | |
1245 | if (!tem) stop_vpos = height; | |
1246 | } | |
1247 | } | |
1248 | ||
1249 | /* In any case, do not display past bottom of window */ | |
1250 | if (stop_vpos >= height) | |
1251 | { | |
1252 | stop_vpos = height; | |
1253 | scroll_amount = 0; | |
1254 | } | |
1255 | ||
1256 | /* Handle case where pos is before w->start -- | |
1257 | can happen if part of line had been clipped and is not clipped now */ | |
1258 | if (vpos == 0 && pos < marker_position (w->start)) | |
1259 | Fset_marker (w->start, make_number (pos), Qnil); | |
1260 | ||
1261 | /* Redisplay the lines where the text was changed */ | |
1262 | last_text_vpos = vpos; | |
1263 | tab_offset = pos_tab_offset (w, pos); | |
1264 | /* If we are starting display in mid-character, correct tab_offset | |
1265 | to account for passing the line that that character really starts in. */ | |
1266 | if (val.hpos < lmargin) | |
1267 | tab_offset += width; | |
1268 | while (vpos < stop_vpos) | |
1269 | { | |
1270 | val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset); | |
1271 | tab_offset += width; | |
1272 | if (val.vpos) tab_offset = 0; | |
1273 | if (pos != val.bufpos) | |
1274 | last_text_vpos | |
1275 | /* Next line, unless prev line ended in end of buffer with no cr */ | |
1276 | = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n'); | |
1277 | pos = val.bufpos; | |
1278 | } | |
1279 | ||
1280 | /* There are two cases: | |
1281 | 1) we have displayed down to the bottom of the window | |
1282 | 2) we have scrolled lines below stop_vpos by scroll_amount */ | |
1283 | ||
1284 | if (vpos == height) | |
1285 | { | |
1286 | /* If last line is continued in middle of character, | |
1287 | include the split character in the text considered on the screen */ | |
1288 | if (val.hpos < lmargin) | |
1289 | val.bufpos++; | |
1290 | XFASTINT (w->window_end_vpos) = last_text_vpos; | |
1291 | XFASTINT (w->window_end_pos) = Z - val.bufpos; | |
1292 | } | |
1293 | ||
1294 | /* If scrolling made blank lines at window bottom, | |
1295 | redisplay to fill those lines */ | |
1296 | if (scroll_amount < 0) | |
1297 | { | |
1298 | /* Don't consider these lines for general-purpose scrolling. | |
1299 | That will save time in the scrolling computation. */ | |
1300 | SCREEN_SCROLL_BOTTOM_VPOS (s) = xp.vpos; | |
1301 | vpos = xp.vpos; | |
1302 | pos = xp.bufpos; | |
1303 | val.hpos = lmargin; | |
1304 | if (pos == ZV) | |
1305 | vpos = height + scroll_amount; | |
1306 | else if (xp.contin && xp.hpos != lmargin) | |
1307 | { | |
1308 | val.hpos = xp.prevhpos - width + lmargin; | |
1309 | pos--; | |
1310 | } | |
1311 | ||
1312 | blank_end_of_window = 1; | |
1313 | tab_offset = pos_tab_offset (w, pos); | |
1314 | /* If we are starting display in mid-character, correct tab_offset | |
1315 | to account for passing the line that that character starts in. */ | |
1316 | if (val.hpos < lmargin) | |
1317 | tab_offset += width; | |
1318 | ||
1319 | while (vpos < height) | |
1320 | { | |
1321 | val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset); | |
1322 | tab_offset += width; | |
1323 | if (val.vpos) tab_offset = 0; | |
1324 | pos = val.bufpos; | |
1325 | } | |
1326 | ||
1327 | /* Here is a case where display_text_line sets cursor_vpos wrong. | |
1328 | Make it be fixed up, below. */ | |
1329 | if (xp.bufpos == ZV | |
1330 | && xp.bufpos == point) | |
1331 | cursor_vpos = -1; | |
1332 | } | |
1333 | ||
1334 | /* If bottom just moved off end of screen, change mode line percentage. */ | |
1335 | if (XFASTINT (w->window_end_pos) == 0 | |
1336 | && Z != val.bufpos) | |
1337 | w->update_mode_line = Qt; | |
1338 | ||
1339 | /* Attempt to adjust end-of-text positions to new bottom line */ | |
1340 | if (scroll_amount) | |
1341 | { | |
1342 | delta = height - xp.vpos; | |
1343 | if (delta < 0 | |
1344 | || (delta > 0 && xp.bufpos <= ZV) | |
1345 | || (delta == 0 && xp.hpos)) | |
1346 | { | |
1347 | val = *vmotion (Z - XFASTINT (w->window_end_pos), | |
1348 | delta, width, hscroll, window); | |
1349 | XFASTINT (w->window_end_pos) = Z - val.bufpos; | |
1350 | XFASTINT (w->window_end_vpos) += val.vpos; | |
1351 | } | |
1352 | } | |
1353 | ||
1354 | w->window_end_valid = Qnil; | |
1355 | ||
1356 | /* If point was not in a line that was displayed, find it */ | |
1357 | if (cursor_vpos < 0) | |
1358 | { | |
1359 | val = *compute_motion (start, 0, lmargin, point, 10000, 10000, | |
1360 | width, hscroll, pos_tab_offset (w, start)); | |
1361 | /* Admit failure if point is off screen now */ | |
1362 | if (val.vpos >= height) | |
1363 | { | |
1364 | for (vpos = 0; vpos < height; vpos++) | |
1365 | cancel_line (vpos + top, s); | |
1366 | return 0; | |
1367 | } | |
1368 | cursor_vpos = val.vpos + top; | |
1369 | cursor_hpos = val.hpos + XFASTINT (w->left); | |
1370 | } | |
1371 | ||
1372 | SCREEN_CURSOR_X (s) = max (0, cursor_hpos); | |
1373 | SCREEN_CURSOR_Y (s) = cursor_vpos; | |
1374 | ||
1375 | if (debug_end_pos) | |
1376 | { | |
1377 | val = *compute_motion (start, 0, lmargin, ZV, | |
1378 | height, - (1 << (SHORTBITS - 1)), | |
1379 | width, hscroll, pos_tab_offset (w, start)); | |
1380 | if (val.vpos != XFASTINT (w->window_end_vpos)) | |
1381 | abort (); | |
1382 | if (XFASTINT (w->window_end_pos) | |
1383 | != Z - val.bufpos) | |
1384 | abort (); | |
1385 | } | |
1386 | ||
1387 | return 1; | |
1388 | } | |
1389 | \f | |
f7430cb6 JB |
1390 | /* Copy glyphs from the rope FROM to T. |
1391 | But don't actually copy the parts that would come in before S. | |
a2889657 JB |
1392 | Value is T, advanced past the copied data. |
1393 | ||
1394 | Characters in FROM are grouped into units of `sizeof GLYPH' chars; | |
1395 | any extra chars at the end of FROM are ignored. */ | |
1396 | ||
1397 | GLYPH * | |
1398 | copy_rope (t, s, from) | |
1399 | register GLYPH *t; /* Copy to here. */ | |
1400 | register GLYPH *s; /* Starting point. */ | |
1401 | Lisp_Object from; /* Data to copy; known to be a string. */ | |
1402 | { | |
1403 | register int n = XSTRING (from)->size / sizeof (GLYPH); | |
1404 | register GLYPH *f = (GLYPH *) XSTRING (from)->data; | |
1405 | ||
1406 | while (n--) | |
1407 | { | |
1408 | if (t >= s) *t = *f; | |
1409 | ++t; | |
1410 | ++f; | |
1411 | } | |
1412 | return t; | |
1413 | } | |
1414 | \f | |
1415 | /* Display one line of window w, starting at position START in W's buffer. | |
1416 | Display starting at horizontal position HPOS, which is normally zero | |
1417 | or negative. A negative value causes output up to hpos = 0 to be discarded. | |
1418 | This is done for negative hscroll, or when this is a continuation line | |
1419 | and the continuation occurred in the middle of a multi-column character. | |
1420 | ||
1421 | TABOFFSET is an offset for ostensible hpos, used in tab stop calculations. | |
1422 | ||
1423 | Display on position VPOS on the screen. (origin 0). | |
1424 | ||
1425 | Returns a STRUCT POSITION giving character to start next line with | |
1426 | and where to display it, including a zero or negative hpos. | |
1427 | The vpos field is not really a vpos; it is 1 unless the line is continued */ | |
1428 | ||
1429 | struct position val_display_text_line; | |
1430 | ||
1431 | static struct position * | |
1432 | display_text_line (w, start, vpos, hpos, taboffset) | |
1433 | struct window *w; | |
1434 | int start; | |
1435 | int vpos; | |
1436 | int hpos; | |
1437 | int taboffset; | |
1438 | { | |
1439 | register int pos = start; | |
1440 | register int c; | |
1441 | register GLYPH *p1; | |
1442 | int end; | |
1443 | register int pause; | |
1444 | register unsigned char *p; | |
1445 | GLYPH *endp; | |
1446 | register GLYPH *startp; | |
1447 | register GLYPH *p1prev; | |
1448 | SCREEN_PTR s = XSCREEN (w->screen); | |
1449 | int tab_width = XINT (current_buffer->tab_width); | |
265a9e55 | 1450 | int ctl_arrow = !NILP (current_buffer->ctl_arrow); |
a2889657 JB |
1451 | int width = XFASTINT (w->width) - 1 |
1452 | - (XFASTINT (w->width) + XFASTINT (w->left) != SCREEN_WIDTH (s)); | |
1453 | struct position val; | |
1454 | int lastpos; | |
1455 | int invis; | |
1456 | int hscroll = XINT (w->hscroll); | |
1457 | int truncate = hscroll | |
1458 | || (truncate_partial_width_windows | |
1459 | && XFASTINT (w->width) < SCREEN_WIDTH (s)) | |
265a9e55 | 1460 | || !NILP (current_buffer->truncate_lines); |
a2889657 JB |
1461 | int selective |
1462 | = XTYPE (current_buffer->selective_display) == Lisp_Int | |
1463 | ? XINT (current_buffer->selective_display) | |
265a9e55 | 1464 | : !NILP (current_buffer->selective_display) ? -1 : 0; |
a2889657 | 1465 | #ifndef old |
265a9e55 | 1466 | int selective_e = selective && !NILP (current_buffer->selective_display_ellipses); |
a2889657 JB |
1467 | #endif |
1468 | register struct screen_glyphs *desired_glyphs = SCREEN_DESIRED_GLYPHS (s); | |
1469 | register struct Lisp_Vector *dp = window_display_table (w); | |
1470 | int selective_rlen | |
1471 | = (selective && dp && XTYPE (DISP_INVIS_ROPE (dp)) == Lisp_String | |
1472 | ? XSTRING (DISP_INVIS_ROPE (dp))->size / sizeof (GLYPH) : 0); | |
1473 | GLYPH truncator = (dp == 0 || XTYPE (DISP_TRUNC_GLYPH (dp)) != Lisp_Int | |
1474 | ? '$' : XINT (DISP_TRUNC_GLYPH (dp))); | |
1475 | GLYPH continuer = (dp == 0 || XTYPE (DISP_CONTINUE_GLYPH (dp)) != Lisp_Int | |
1476 | ? '\\' : XINT (DISP_CONTINUE_GLYPH (dp))); | |
1477 | ||
1478 | hpos += XFASTINT (w->left); | |
1479 | get_display_line (s, vpos, XFASTINT (w->left)); | |
1480 | if (tab_width <= 0 || tab_width > 20) tab_width = 8; | |
1481 | ||
1482 | if (MINI_WINDOW_P (w) && start == 1 | |
1483 | && vpos == XFASTINT (w->top)) | |
1484 | { | |
1485 | if (minibuf_prompt) | |
1486 | hpos = display_string (w, vpos, minibuf_prompt, hpos, | |
1487 | (!truncate ? continuer : truncator), | |
1488 | -1, -1); | |
1489 | minibuf_prompt_width = hpos; | |
1490 | } | |
1491 | ||
1492 | desired_glyphs->bufp[vpos] = pos; | |
1493 | p1 = desired_glyphs->glyphs[vpos] + hpos; | |
1494 | end = ZV; | |
1495 | startp = desired_glyphs->glyphs[vpos] + XFASTINT (w->left); | |
1496 | endp = startp + width; | |
1497 | ||
1498 | /* Loop generating characters. | |
1499 | Stop at end of buffer, before newline, | |
1500 | or if reach or pass continuation column. */ | |
1501 | ||
1502 | pause = pos; | |
1503 | while (p1 < endp) | |
1504 | { | |
1505 | p1prev = p1; | |
1506 | if (pos == pause) | |
1507 | { | |
1508 | if (pos == end) | |
1509 | break; | |
1510 | if (pos == point && cursor_vpos < 0) | |
1511 | { | |
1512 | cursor_vpos = vpos; | |
1513 | cursor_hpos = p1 - startp; | |
1514 | } | |
1515 | ||
1516 | pause = end; | |
1517 | if (pos < point && point < pause) | |
1518 | pause = point; | |
1519 | if (pos < GPT && GPT < pause) | |
1520 | pause = GPT; | |
1521 | ||
1522 | p = &FETCH_CHAR (pos); | |
1523 | } | |
1524 | c = *p++; | |
1525 | if (c >= 040 && c < 0177 | |
1526 | && (dp == 0 || XTYPE (DISP_CHAR_ROPE (dp, c)) != Lisp_String)) | |
1527 | { | |
1528 | if (p1 >= startp) | |
1529 | *p1 = c; | |
1530 | p1++; | |
1531 | } | |
1532 | else if (c == '\n') | |
1533 | { | |
1534 | invis = 0; | |
1535 | while (pos < end | |
1536 | && selective > 0 | |
1537 | && position_indentation (pos + 1) >= selective) | |
1538 | { | |
1539 | invis = 1; | |
1540 | pos = find_next_newline (pos + 1, 1); | |
1541 | if (FETCH_CHAR (pos - 1) == '\n') | |
1542 | pos--; | |
1543 | } | |
1544 | if (invis && selective_rlen > 0 && p1 >= startp) | |
1545 | { | |
1546 | p1 += selective_rlen; | |
1547 | if (p1 - startp > width) | |
1548 | p1 = endp; | |
1549 | bcopy (XSTRING (DISP_INVIS_ROPE (dp))->data, p1prev, | |
1550 | (p1 - p1prev) * sizeof (GLYPH)); | |
1551 | } | |
1552 | break; | |
1553 | } | |
1554 | else if (c == '\t') | |
1555 | { | |
1556 | do | |
1557 | { | |
1558 | if (p1 >= startp && p1 < endp) | |
1559 | *p1 = SPACEGLYPH; | |
1560 | p1++; | |
1561 | } | |
1562 | while ((p1 - startp + taboffset + hscroll - (hscroll > 0)) | |
1563 | % tab_width); | |
1564 | } | |
6e8290aa | 1565 | else if (c == Ctl ('M') && selective == -1) |
a2889657 JB |
1566 | { |
1567 | pos = find_next_newline (pos, 1); | |
1568 | if (FETCH_CHAR (pos - 1) == '\n') | |
1569 | pos--; | |
1570 | if (selective_rlen > 0) | |
1571 | { | |
1572 | p1 += selective_rlen; | |
1573 | if (p1 - startp > width) | |
1574 | p1 = endp; | |
1575 | bcopy (XSTRING (DISP_INVIS_ROPE (dp))->data, p1prev, | |
1576 | (p1 - p1prev) * sizeof (GLYPH)); | |
1577 | } | |
1578 | break; | |
1579 | } | |
1580 | else if (dp != 0 && XTYPE (DISP_CHAR_ROPE (dp, c)) == Lisp_String) | |
1581 | { | |
1582 | p1 = copy_rope (p1, startp, DISP_CHAR_ROPE (dp, c)); | |
1583 | } | |
1584 | else if (c < 0200 && ctl_arrow) | |
1585 | { | |
1586 | if (p1 >= startp) | |
1587 | *p1 = (dp && XTYPE (DISP_CTRL_GLYPH (dp)) == Lisp_Int | |
1588 | ? XINT (DISP_CTRL_GLYPH (dp)) : '^'); | |
1589 | p1++; | |
6e8290aa | 1590 | if (p1 >= startp && p1 < endp) |
a2889657 JB |
1591 | *p1 = c ^ 0100; |
1592 | p1++; | |
1593 | } | |
1594 | else | |
1595 | { | |
1596 | if (p1 >= startp) | |
1597 | *p1 = (dp && XTYPE (DISP_ESCAPE_GLYPH (dp)) == Lisp_Int | |
1598 | ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'); | |
1599 | p1++; | |
6e8290aa | 1600 | if (p1 >= startp && p1 < endp) |
a2889657 JB |
1601 | *p1 = (c >> 6) + '0'; |
1602 | p1++; | |
6e8290aa | 1603 | if (p1 >= startp && p1 < endp) |
a2889657 JB |
1604 | *p1 = (7 & (c >> 3)) + '0'; |
1605 | p1++; | |
6e8290aa | 1606 | if (p1 >= startp && p1 < endp) |
a2889657 JB |
1607 | *p1 = (7 & c) + '0'; |
1608 | p1++; | |
1609 | } | |
1610 | pos++; | |
1611 | } | |
1612 | ||
1613 | val.hpos = - XINT (w->hscroll); | |
1614 | if (val.hpos) | |
1615 | val.hpos++; | |
1616 | ||
1617 | val.vpos = 1; | |
1618 | ||
1619 | lastpos = pos; | |
1620 | ||
1621 | /* Handle continuation in middle of a character */ | |
1622 | /* by backing up over it */ | |
1623 | if (p1 > endp) | |
1624 | { | |
1625 | /* Start the next line with that same character */ | |
1626 | pos--; | |
1627 | /* but at a negative hpos, to skip the columns output on this line. */ | |
1628 | val.hpos += p1prev - endp; | |
1629 | /* Keep in this line everything up to the continuation column. */ | |
1630 | p1 = endp; | |
1631 | } | |
1632 | ||
1633 | /* Finish deciding which character to start the next line on, | |
1634 | and what hpos to start it at. | |
1635 | Also set `lastpos' to the last position which counts as "on this line" | |
1636 | for cursor-positioning. */ | |
1637 | ||
1638 | if (pos < ZV) | |
1639 | { | |
1640 | if (FETCH_CHAR (pos) == '\n') | |
1641 | /* If stopped due to a newline, start next line after it */ | |
1642 | pos++; | |
1643 | else | |
1644 | /* Stopped due to right margin of window */ | |
1645 | { | |
1646 | if (truncate) | |
1647 | { | |
1648 | *p1++ = truncator; | |
1649 | /* Truncating => start next line after next newline, | |
1650 | and point is on this line if it is before the newline, | |
1651 | and skip none of first char of next line */ | |
1652 | pos = find_next_newline (pos, 1); | |
1653 | val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0; | |
1654 | ||
1655 | lastpos = pos - (FETCH_CHAR (pos - 1) == '\n'); | |
1656 | } | |
1657 | else | |
1658 | { | |
1659 | *p1++ = continuer; | |
1660 | val.vpos = 0; | |
1661 | lastpos--; | |
1662 | } | |
1663 | } | |
1664 | } | |
1665 | ||
1666 | /* If point is at eol or in invisible text at eol, | |
1667 | record its screen location now. */ | |
1668 | ||
1669 | if (start <= point && point <= lastpos && cursor_vpos < 0) | |
1670 | { | |
1671 | cursor_vpos = vpos; | |
1672 | cursor_hpos = p1 - startp; | |
1673 | } | |
1674 | ||
1675 | if (cursor_vpos == vpos) | |
1676 | { | |
1677 | if (cursor_hpos < 0) cursor_hpos = 0; | |
1678 | if (cursor_hpos > width) cursor_hpos = width; | |
1679 | cursor_hpos += XFASTINT (w->left); | |
1680 | if (w == XWINDOW (SCREEN_SELECTED_WINDOW (s))) | |
1681 | { | |
1682 | SCREEN_CURSOR_Y (s) = cursor_vpos; | |
1683 | SCREEN_CURSOR_X (s) = cursor_hpos; | |
1684 | ||
1685 | if (w == XWINDOW (selected_window)) | |
1686 | { | |
1687 | /* Line is not continued and did not start | |
1688 | in middle of character */ | |
1689 | if ((hpos - XFASTINT (w->left) | |
1690 | == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0)) | |
1691 | && val.vpos) | |
1692 | { | |
1693 | this_line_bufpos = start; | |
1694 | this_line_buffer = current_buffer; | |
1695 | this_line_vpos = cursor_vpos; | |
1696 | this_line_start_hpos = hpos; | |
1697 | this_line_endpos = Z - lastpos; | |
1698 | } | |
1699 | else | |
1700 | this_line_bufpos = 0; | |
1701 | } | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | /* If hscroll and line not empty, insert truncation-at-left marker */ | |
1706 | if (hscroll && lastpos != start) | |
1707 | { | |
1708 | *startp = truncator; | |
1709 | if (p1 <= startp) | |
1710 | p1 = startp + 1; | |
1711 | } | |
1712 | ||
1713 | if (XFASTINT (w->width) + XFASTINT (w->left) != SCREEN_WIDTH (s)) | |
1714 | { | |
1715 | endp++; | |
1716 | if (p1 < startp) p1 = startp; | |
1717 | while (p1 < endp) *p1++ = SPACEGLYPH; | |
1718 | *p1++ = '|'; | |
1719 | } | |
1720 | desired_glyphs->used[vpos] = max (desired_glyphs->used[vpos], | |
1721 | p1 - desired_glyphs->glyphs[vpos]); | |
1722 | desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0; | |
1723 | ||
1724 | /* If the start of this line is the overlay arrow-position, | |
1725 | then put the arrow string into the display-line. */ | |
1726 | ||
1727 | if (XTYPE (Voverlay_arrow_position) == Lisp_Marker | |
1728 | && current_buffer == XMARKER (Voverlay_arrow_position)->buffer | |
1729 | && start == marker_position (Voverlay_arrow_position) | |
1730 | && XTYPE (Voverlay_arrow_string) == Lisp_String | |
1731 | && ! overlay_arrow_seen) | |
1732 | { | |
1733 | unsigned char *p = XSTRING (Voverlay_arrow_string)->data; | |
1734 | int i; | |
1735 | int len = XSTRING (Voverlay_arrow_string)->size; | |
1736 | ||
1737 | if (len > XFASTINT (w->width) - 1) | |
1738 | len = XFASTINT (w->width) - 1; | |
1739 | for (i = 0; i < len; i++) | |
1740 | startp[i] = p[i]; | |
1741 | if (desired_glyphs->used[vpos] < | |
1742 | (len + startp - desired_glyphs->glyphs[vpos])) | |
1743 | desired_glyphs->used[vpos] = len + startp - desired_glyphs->glyphs[vpos]; | |
1744 | ||
1745 | overlay_arrow_seen = 1; | |
1746 | } | |
1747 | ||
1748 | val.bufpos = pos; | |
1749 | val_display_text_line = val; | |
1750 | return &val_display_text_line; | |
1751 | } | |
1752 | \f | |
1753 | /* Display the mode line for window w */ | |
1754 | ||
1755 | static void | |
1756 | display_mode_line (w) | |
1757 | struct window *w; | |
1758 | { | |
1759 | register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1; | |
1760 | register int left = XFASTINT (w->left); | |
1761 | register int right = XFASTINT (w->width) + left; | |
1762 | register SCREEN_PTR s = XSCREEN (WINDOW_SCREEN (w)); | |
1763 | ||
1764 | get_display_line (s, vpos, left); | |
1765 | display_mode_element (w, vpos, left, 0, right, right, | |
1766 | current_buffer->mode_line_format); | |
1767 | SCREEN_DESIRED_GLYPHS (s)->bufp[vpos] = 0; | |
1768 | ||
1769 | /* Make the mode line inverse video if the entire line | |
1770 | is made of mode lines. | |
1771 | I.e. if this window is full width, | |
1772 | or if it is the child of a full width window | |
1773 | (which implies that that window is split side-by-side | |
1774 | and the rest of this line is mode lines of the sibling windows). */ | |
1775 | if (XFASTINT (w->width) == SCREEN_WIDTH (s) | |
1776 | || XFASTINT (XWINDOW (w->parent)->width) == SCREEN_WIDTH (s)) | |
1777 | s->desired_glyphs->highlight[vpos] = mode_line_inverse_video; | |
1778 | ||
1779 | #ifdef HAVE_X_WINDOWS | |
1780 | /* I'm trying this out because I saw Unimpress use it, but it's | |
8de2d90b | 1781 | possible that this may mess adversely with some window managers. jla */ |
a2889657 JB |
1782 | |
1783 | if (SCREEN_IS_X (s) | |
8de2d90b | 1784 | && ! SCREEN_MINIBUF_ONLY_P (s) |
a2889657 | 1785 | && w == XWINDOW (s->selected_window) |
265a9e55 | 1786 | && (NILP (Fstring_equal (XBUFFER (w->buffer)->name, s->name)))) |
a2889657 JB |
1787 | x_set_name (s, XBUFFER (w->buffer)->name, Qnil); |
1788 | #endif | |
1789 | } | |
1790 | ||
1791 | /* Contribute ELT to the mode line for window W. | |
1792 | How it translates into text depends on its data type. | |
1793 | ||
1794 | VPOS is the position of the mode line being displayed. | |
1795 | ||
1796 | HPOS is the position (absolute on screen) where this element's text | |
1797 | should start. The output is truncated automatically at the right | |
1798 | edge of window W. | |
1799 | ||
1800 | DEPTH is the depth in recursion. It is used to prevent | |
1801 | infinite recursion here. | |
1802 | ||
1803 | MINENDCOL is the hpos before which the element may not end. | |
1804 | The element is padded at the right with spaces if nec | |
1805 | to reach this column. | |
1806 | ||
1807 | MAXENDCOL is the hpos past which this element may not extend. | |
1808 | If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority. | |
1809 | (This is necessary to make nested padding and truncation work.) | |
1810 | ||
1811 | Returns the hpos of the end of the text generated by ELT. | |
1812 | The next element will receive that value as its HPOS arg, | |
1813 | so as to concatenate the elements. */ | |
1814 | ||
1815 | static int | |
1816 | display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt) | |
1817 | struct window *w; | |
1818 | register int vpos, hpos; | |
1819 | int depth; | |
1820 | int minendcol; | |
1821 | register int maxendcol; | |
1822 | register Lisp_Object elt; | |
1823 | { | |
1824 | tail_recurse: | |
1825 | if (depth > 10) | |
1826 | goto invalid; | |
1827 | ||
1828 | depth++; | |
1829 | ||
1830 | #ifdef SWITCH_ENUM_BUG | |
1831 | switch ((int) XTYPE (elt)) | |
1832 | #else | |
1833 | switch (XTYPE (elt)) | |
1834 | #endif | |
1835 | { | |
1836 | case Lisp_String: | |
1837 | { | |
1838 | /* A string: output it and check for %-constructs within it. */ | |
1839 | register unsigned char c; | |
1840 | register unsigned char *this = XSTRING (elt)->data; | |
1841 | ||
1842 | while (hpos < maxendcol && *this) | |
1843 | { | |
1844 | unsigned char *last = this; | |
1845 | while ((c = *this++) != '\0' && c != '%') | |
1846 | ; | |
1847 | if (this - 1 != last) | |
1848 | { | |
1849 | register int lim = --this - last + hpos; | |
1850 | hpos = display_string (w, vpos, last, hpos, 0, hpos, | |
1851 | min (lim, maxendcol)); | |
1852 | } | |
1853 | else /* c == '%' */ | |
1854 | { | |
1855 | register int spec_width = 0; | |
1856 | ||
1857 | /* We can't allow -ve args due to the "%-" construct */ | |
1858 | /* Argument specifies minwidth but not maxwidth | |
1859 | (maxwidth can be specified by | |
1860 | (<negative-number> . <stuff>) mode-line elements) */ | |
1861 | ||
1862 | while ((c = *this++) >= '0' && c <= '9') | |
1863 | { | |
1864 | spec_width = spec_width * 10 + (c - '0'); | |
1865 | } | |
1866 | ||
1867 | spec_width += hpos; | |
1868 | if (spec_width > maxendcol) | |
1869 | spec_width = maxendcol; | |
1870 | ||
1871 | if (c == 'M') | |
1872 | hpos = display_mode_element (w, vpos, hpos, depth, | |
1873 | spec_width, maxendcol, | |
1874 | Vglobal_mode_string); | |
1875 | else if (c != 0) | |
1876 | hpos = display_string (w, vpos, | |
1877 | decode_mode_spec (w, c, | |
1878 | maxendcol - hpos), | |
1879 | hpos, 0, spec_width, maxendcol); | |
1880 | } | |
1881 | } | |
1882 | } | |
1883 | break; | |
1884 | ||
1885 | case Lisp_Symbol: | |
1886 | /* A symbol: process the value of the symbol recursively | |
1887 | as if it appeared here directly. Avoid error if symbol void. | |
1888 | Special case: if value of symbol is a string, output the string | |
1889 | literally. */ | |
1890 | { | |
1891 | register Lisp_Object tem; | |
1892 | tem = Fboundp (elt); | |
265a9e55 | 1893 | if (!NILP (tem)) |
a2889657 JB |
1894 | { |
1895 | tem = Fsymbol_value (elt); | |
1896 | /* If value is a string, output that string literally: | |
1897 | don't check for % within it. */ | |
1898 | if (XTYPE (tem) == Lisp_String) | |
1899 | hpos = display_string (w, vpos, XSTRING (tem)->data, | |
1900 | hpos, 0, minendcol, maxendcol); | |
1901 | /* Give up right away for nil or t. */ | |
1902 | else if (!EQ (tem, elt)) | |
1903 | { elt = tem; goto tail_recurse; } | |
1904 | } | |
1905 | } | |
1906 | break; | |
1907 | ||
1908 | case Lisp_Cons: | |
1909 | { | |
1910 | register Lisp_Object car, tem; | |
1911 | ||
1912 | /* A cons cell: three distinct cases. | |
1913 | If first element is a string or a cons, process all the elements | |
1914 | and effectively concatenate them. | |
1915 | If first element is a negative number, truncate displaying cdr to | |
1916 | at most that many characters. If positive, pad (with spaces) | |
1917 | to at least that many characters. | |
1918 | If first element is a symbol, process the cadr or caddr recursively | |
1919 | according to whether the symbol's value is non-nil or nil. */ | |
1920 | car = XCONS (elt)->car; | |
1921 | if (XTYPE (car) == Lisp_Symbol) | |
1922 | { | |
1923 | tem = Fboundp (car); | |
1924 | elt = XCONS (elt)->cdr; | |
1925 | if (XTYPE (elt) != Lisp_Cons) | |
1926 | goto invalid; | |
1927 | /* elt is now the cdr, and we know it is a cons cell. | |
1928 | Use its car if CAR has a non-nil value. */ | |
265a9e55 | 1929 | if (!NILP (tem)) |
a2889657 JB |
1930 | { |
1931 | tem = Fsymbol_value (car); | |
265a9e55 | 1932 | if (!NILP (tem)) |
a2889657 JB |
1933 | { elt = XCONS (elt)->car; goto tail_recurse; } |
1934 | } | |
1935 | /* Symbol's value is nil (or symbol is unbound) | |
1936 | Get the cddr of the original list | |
1937 | and if possible find the caddr and use that. */ | |
1938 | elt = XCONS (elt)->cdr; | |
265a9e55 | 1939 | if (NILP (elt)) |
a2889657 JB |
1940 | break; |
1941 | else if (XTYPE (elt) != Lisp_Cons) | |
1942 | goto invalid; | |
1943 | elt = XCONS (elt)->car; | |
1944 | goto tail_recurse; | |
1945 | } | |
1946 | else if (XTYPE (car) == Lisp_Int) | |
1947 | { | |
1948 | register int lim = XINT (car); | |
1949 | elt = XCONS (elt)->cdr; | |
1950 | if (lim < 0) | |
1951 | /* Negative int means reduce maximum width. | |
1952 | DO NOT change MINENDCOL here! | |
1953 | (20 -10 . foo) should truncate foo to 10 col | |
1954 | and then pad to 20. */ | |
1955 | maxendcol = min (maxendcol, hpos - lim); | |
1956 | else if (lim > 0) | |
1957 | { | |
1958 | /* Padding specified. Don't let it be more than | |
1959 | current maximum. */ | |
1960 | lim += hpos; | |
1961 | if (lim > maxendcol) | |
1962 | lim = maxendcol; | |
1963 | /* If that's more padding than already wanted, queue it. | |
1964 | But don't reduce padding already specified even if | |
1965 | that is beyond the current truncation point. */ | |
1966 | if (lim > minendcol) | |
1967 | minendcol = lim; | |
1968 | } | |
1969 | goto tail_recurse; | |
1970 | } | |
1971 | else if (XTYPE (car) == Lisp_String || XTYPE (car) == Lisp_Cons) | |
1972 | { | |
1973 | register int limit = 50; | |
1974 | /* LIMIT is to protect against circular lists. */ | |
1975 | while (XTYPE (elt) == Lisp_Cons && --limit > 0 | |
1976 | && hpos < maxendcol) | |
1977 | { | |
1978 | hpos = display_mode_element (w, vpos, hpos, depth, | |
1979 | hpos, maxendcol, | |
1980 | XCONS (elt)->car); | |
1981 | elt = XCONS (elt)->cdr; | |
1982 | } | |
1983 | } | |
1984 | } | |
1985 | break; | |
1986 | ||
1987 | default: | |
1988 | invalid: | |
1989 | return (display_string (w, vpos, "*invalid*", hpos, 0, | |
1990 | minendcol, maxendcol)); | |
1991 | } | |
1992 | ||
1993 | end: | |
1994 | if (minendcol > hpos) | |
1995 | hpos = display_string (w, vpos, "", hpos, 0, minendcol, -1); | |
1996 | return hpos; | |
1997 | } | |
1998 | \f | |
1999 | /* Return a string for the output of a mode line %-spec for window W, | |
2000 | generated by character C and width MAXWIDTH. */ | |
2001 | ||
2002 | static char * | |
2003 | decode_mode_spec (w, c, maxwidth) | |
2004 | struct window *w; | |
2005 | register char c; | |
2006 | register int maxwidth; | |
2007 | { | |
2008 | Lisp_Object obj = Qnil; | |
2009 | SCREEN_PTR scr = XSCREEN (WINDOW_SCREEN (w)); | |
2010 | char *decode_mode_spec_buf = (char *) SCREEN_TEMP_GLYPHS (scr)->total_contents; | |
2011 | ||
2012 | if (maxwidth > SCREEN_WIDTH (scr)) | |
2013 | maxwidth = SCREEN_WIDTH (scr); | |
2014 | ||
2015 | switch (c) | |
2016 | { | |
2017 | case 'b': | |
2018 | obj = current_buffer->name; | |
2019 | #if 0 | |
2020 | if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth) | |
2021 | { | |
2022 | bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1); | |
2023 | decode_mode_spec_buf[maxwidth - 1] = '\\'; | |
2024 | decode_mode_spec_buf[maxwidth] = '\0'; | |
2025 | return decode_mode_spec_buf; | |
2026 | } | |
2027 | #endif | |
2028 | break; | |
2029 | ||
2030 | case 'f': | |
2031 | obj = current_buffer->filename; | |
2032 | #if 0 | |
265a9e55 | 2033 | if (NILP (obj)) |
a2889657 JB |
2034 | return "[none]"; |
2035 | else if (XTYPE (obj) == Lisp_String && XSTRING (obj)->size > maxwidth) | |
2036 | { | |
2037 | bcopy ("...", decode_mode_spec_buf, 3); | |
2038 | bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3, | |
2039 | decode_mode_spec_buf + 3, maxwidth - 3); | |
2040 | return decode_mode_spec_buf; | |
2041 | } | |
2042 | #endif | |
2043 | break; | |
2044 | ||
2045 | case 'm': | |
2046 | obj = current_buffer->mode_name; | |
2047 | break; | |
2048 | ||
2049 | case 'n': | |
2050 | if (BEGV > BEG || ZV < Z) | |
2051 | return " Narrow"; | |
2052 | break; | |
2053 | ||
2054 | case '*': | |
265a9e55 | 2055 | if (!NILP (current_buffer->read_only)) |
a2889657 JB |
2056 | return "%"; |
2057 | if (MODIFF > current_buffer->save_modified) | |
2058 | return "*"; | |
2059 | return "-"; | |
2060 | ||
2061 | case 's': | |
2062 | /* status of process */ | |
a2889657 | 2063 | obj = Fget_buffer_process (Fcurrent_buffer ()); |
265a9e55 | 2064 | if (NILP (obj)) |
a2889657 JB |
2065 | return "no process"; |
2066 | obj = Fsymbol_name (Fprocess_status (obj)); | |
2067 | break; | |
a2889657 JB |
2068 | |
2069 | case 'p': | |
2070 | { | |
2071 | int pos = marker_position (w->start); | |
2072 | int total = ZV - BEGV; | |
2073 | ||
2074 | if (XFASTINT (w->window_end_pos) <= Z - ZV) | |
2075 | { | |
2076 | if (pos <= BEGV) | |
2077 | return "All"; | |
2078 | else | |
2079 | return "Bottom"; | |
2080 | } | |
2081 | else if (pos <= BEGV) | |
2082 | return "Top"; | |
2083 | else | |
2084 | { | |
2085 | total = ((pos - BEGV) * 100 + total - 1) / total; | |
2086 | /* We can't normally display a 3-digit number, | |
2087 | so get us a 2-digit number that is close. */ | |
2088 | if (total == 100) | |
2089 | total = 99; | |
2090 | sprintf (decode_mode_spec_buf, "%2d%%", total); | |
2091 | return decode_mode_spec_buf; | |
2092 | } | |
2093 | } | |
2094 | ||
2095 | case '%': | |
2096 | return "%"; | |
2097 | ||
2098 | case '[': | |
2099 | { | |
2100 | int i; | |
2101 | char *p; | |
2102 | ||
2103 | if (command_loop_level > 5) | |
2104 | return "[[[... "; | |
2105 | p = decode_mode_spec_buf; | |
2106 | for (i = 0; i < command_loop_level; i++) | |
2107 | *p++ = '['; | |
2108 | *p = 0; | |
2109 | return decode_mode_spec_buf; | |
2110 | } | |
2111 | ||
2112 | case ']': | |
2113 | { | |
2114 | int i; | |
2115 | char *p; | |
2116 | ||
2117 | if (command_loop_level > 5) | |
2118 | return " ...]]]"; | |
2119 | p = decode_mode_spec_buf; | |
2120 | for (i = 0; i < command_loop_level; i++) | |
2121 | *p++ = ']'; | |
2122 | *p = 0; | |
2123 | return decode_mode_spec_buf; | |
2124 | } | |
2125 | ||
2126 | case '-': | |
2127 | { | |
2128 | static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------"; | |
2129 | register char *p; | |
2130 | register int i; | |
2131 | ||
2132 | if (maxwidth < sizeof (lots_of_dashes)) | |
2133 | return lots_of_dashes; | |
2134 | else | |
2135 | { | |
2136 | for (p = decode_mode_spec_buf, i = maxwidth; i > 0; i--) | |
2137 | *p++ = '-'; | |
2138 | *p = '\0'; | |
2139 | } | |
2140 | return decode_mode_spec_buf; | |
2141 | } | |
2142 | } | |
2143 | ||
2144 | if (XTYPE (obj) == Lisp_String) | |
2145 | return (char *) XSTRING (obj)->data; | |
2146 | else | |
2147 | return ""; | |
2148 | } | |
2149 | \f | |
2150 | /* Display STRING on one line of window W, starting at HPOS. | |
2151 | Display at position VPOS. Caller should have done get_display_line. | |
2152 | ||
2153 | TRUNCATE is GLYPH to display at end if truncated. Zero for none. | |
2154 | ||
2155 | MINCOL is the first column ok to end at. (Pad with spaces to this col.) | |
2156 | MAXCOL is the last column ok to end at. Truncate here. | |
2157 | -1 for MINCOL or MAXCOL means no explicit minimum or maximum. | |
2158 | Both count from the left edge of the screen, as does HPOS. | |
2159 | The right edge of W is an implicit maximum. | |
2160 | If TRUNCATE is nonzero, the implicit maximum is one column before the edge. | |
2161 | ||
2162 | Returns ending hpos */ | |
2163 | ||
2164 | static int | |
2165 | display_string (w, vpos, string, hpos, truncate, mincol, maxcol) | |
2166 | struct window *w; | |
2167 | unsigned char *string; | |
2168 | int vpos, hpos; | |
2169 | GLYPH truncate; | |
2170 | int mincol, maxcol; | |
2171 | { | |
2172 | register int c; | |
2173 | register GLYPH *p1; | |
2174 | int hscroll = XINT (w->hscroll); | |
2175 | int tab_width = XINT (current_buffer->tab_width); | |
2176 | register GLYPH *start; | |
2177 | register GLYPH *end; | |
2178 | struct screen_glyphs *desired_glyphs = SCREEN_DESIRED_GLYPHS (XSCREEN (w->screen)); | |
2179 | GLYPH *p1start = desired_glyphs->glyphs[vpos] + hpos; | |
2180 | int window_width = XFASTINT (w->width); | |
2181 | ||
2182 | /* Use the standard display table, not the window's display table. | |
2183 | We don't want the mode line in rot13. */ | |
2184 | register struct Lisp_Vector *dp = 0; | |
2185 | ||
2186 | if (XTYPE (Vstandard_display_table) == Lisp_Vector | |
2187 | && XVECTOR (Vstandard_display_table)->size == DISP_TABLE_SIZE) | |
2188 | dp = XVECTOR (Vstandard_display_table); | |
2189 | ||
2190 | if (tab_width <= 0 || tab_width > 20) tab_width = 8; | |
2191 | ||
2192 | p1 = p1start; | |
2193 | start = desired_glyphs->glyphs[vpos] + XFASTINT (w->left); | |
2194 | end = start + window_width - (truncate != 0); | |
2195 | ||
2196 | if ((window_width + XFASTINT (w->left)) | |
2197 | != SCREEN_WIDTH (XSCREEN (WINDOW_SCREEN (w)))) | |
2198 | *end-- = '|'; | |
2199 | ||
2200 | if (maxcol >= 0 && end - desired_glyphs->glyphs[vpos] > maxcol) | |
2201 | end = desired_glyphs->glyphs[vpos] + maxcol; | |
2202 | if (maxcol >= 0 && mincol > maxcol) | |
2203 | mincol = maxcol; | |
2204 | ||
2205 | while (p1 < end) | |
2206 | { | |
2207 | c = *string++; | |
2208 | if (!c) break; | |
2209 | if (c >= 040 && c < 0177 | |
2210 | && (dp == 0 || XTYPE (DISP_CHAR_ROPE (dp, c)) != Lisp_String)) | |
2211 | { | |
2212 | if (p1 >= start) | |
2213 | *p1 = c; | |
2214 | p1++; | |
2215 | } | |
2216 | else if (c == '\t') | |
2217 | { | |
2218 | do | |
2219 | { | |
2220 | if (p1 >= start && p1 < end) | |
2221 | *p1 = SPACEGLYPH; | |
2222 | p1++; | |
2223 | } | |
2224 | while ((p1 - start + hscroll - (hscroll > 0)) % tab_width); | |
2225 | } | |
2226 | else if (dp != 0 && XTYPE (DISP_CHAR_ROPE (dp, c)) == Lisp_String) | |
2227 | p1 = copy_rope (p1, start, DISP_CHAR_ROPE (dp, c)); | |
2228 | else if (c < 0200 && buffer_defaults.ctl_arrow) | |
2229 | { | |
2230 | if (p1 >= start) | |
2231 | *p1 = (dp && XTYPE (DISP_CTRL_GLYPH (dp)) == Lisp_Int | |
2232 | ? XINT (DISP_CTRL_GLYPH (dp)) : '^'); | |
2233 | p1++; | |
6e8290aa | 2234 | if (p1 >= start && p1 < end) |
a2889657 JB |
2235 | *p1 = c ^ 0100; |
2236 | p1++; | |
2237 | } | |
2238 | else | |
2239 | { | |
2240 | if (p1 >= start) | |
2241 | *p1 = (dp && XTYPE (DISP_ESCAPE_GLYPH (dp)) == Lisp_Int | |
2242 | ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'); | |
2243 | p1++; | |
6e8290aa | 2244 | if (p1 >= start && p1 < end) |
a2889657 JB |
2245 | *p1 = (c >> 6) + '0'; |
2246 | p1++; | |
6e8290aa | 2247 | if (p1 >= start && p1 < end) |
a2889657 JB |
2248 | *p1 = (7 & (c >> 3)) + '0'; |
2249 | p1++; | |
6e8290aa | 2250 | if (p1 >= start && p1 < end) |
a2889657 JB |
2251 | *p1 = (7 & c) + '0'; |
2252 | p1++; | |
2253 | } | |
2254 | } | |
2255 | ||
2256 | if (c) | |
2257 | { | |
2258 | p1 = end; | |
2259 | if (truncate) *p1++ = truncate; | |
2260 | } | |
2261 | else if (mincol >= 0) | |
2262 | { | |
2263 | end = desired_glyphs->glyphs[vpos] + mincol; | |
2264 | while (p1 < end) | |
2265 | *p1++ = SPACEGLYPH; | |
2266 | } | |
2267 | ||
2268 | { | |
2269 | register int len = p1 - desired_glyphs->glyphs[vpos]; | |
2270 | ||
2271 | if (len > desired_glyphs->used[vpos]) | |
2272 | desired_glyphs->used[vpos] = len; | |
2273 | desired_glyphs->glyphs[vpos][desired_glyphs->used[vpos]] = 0; | |
2274 | ||
2275 | return len; | |
2276 | } | |
2277 | } | |
2278 | \f | |
2279 | void | |
2280 | syms_of_xdisp () | |
2281 | { | |
2282 | staticpro (&last_arrow_position); | |
2283 | staticpro (&last_arrow_string); | |
2284 | last_arrow_position = Qnil; | |
2285 | last_arrow_string = Qnil; | |
2286 | ||
2287 | DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string, | |
2288 | "String displayed by mode-line-format's \"%m\" specifiation."); | |
2289 | Vglobal_mode_string = Qnil; | |
2290 | ||
2291 | DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position, | |
2292 | "Marker for where to display an arrow on top of the buffer text.\n\ | |
2293 | This must be the beginning of a line in order to work.\n\ | |
2294 | See also `overlay-arrow-string'."); | |
2295 | Voverlay_arrow_position = Qnil; | |
2296 | ||
2297 | DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string, | |
2298 | "String to display as an arrow. See also `overlay-arrow-position'."); | |
2299 | Voverlay_arrow_string = Qnil; | |
2300 | ||
2301 | DEFVAR_INT ("scroll-step", &scroll_step, | |
2302 | "*The number of lines to try scrolling a window by when point moves out.\n\ | |
2303 | If that fails to bring point back on screen, point is centered instead.\n\ | |
2304 | If this is zero, point is always centered after it moves off screen."); | |
2305 | ||
2306 | DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask"); | |
2307 | ||
2308 | DEFVAR_BOOL ("truncate-partial-width-windows", | |
2309 | &truncate_partial_width_windows, | |
2310 | "*Non-nil means truncate lines in all windows less than full screen wide."); | |
2311 | truncate_partial_width_windows = 1; | |
2312 | ||
2313 | DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video, | |
2314 | "*Non-nil means use inverse video for the mode line."); | |
2315 | mode_line_inverse_video = 1; | |
2316 | ||
2317 | #ifndef MULTI_SCREEN | |
2318 | defsubr (&Sredraw_display); | |
2319 | #endif /* MULTI_SCREEN */ | |
2320 | } | |
2321 | ||
2322 | /* initialize the window system */ | |
2323 | init_xdisp () | |
2324 | { | |
2325 | Lisp_Object root_window; | |
2326 | #ifndef COMPILER_REGISTER_BUG | |
2327 | register | |
2328 | #endif /* COMPILER_REGISTER_BUG */ | |
2329 | struct window *mini_w; | |
2330 | ||
2331 | this_line_bufpos = 0; | |
2332 | ||
2333 | mini_w = XWINDOW (minibuf_window); | |
2334 | root_window = mini_w->prev; | |
2335 | ||
2336 | echo_area_glyphs = 0; | |
2337 | previous_echo_glyphs = 0; | |
2338 | ||
2339 | if (!noninteractive) | |
2340 | { | |
2341 | SCREEN_PTR s = XSCREEN (WINDOW_SCREEN (XWINDOW (root_window))); | |
2342 | XFASTINT (XWINDOW (root_window)->top) = 0; | |
2343 | set_window_height (root_window, SCREEN_HEIGHT (s) - 1, 0); | |
2344 | XFASTINT (mini_w->top) = SCREEN_HEIGHT (s) - 1; | |
2345 | set_window_height (minibuf_window, 1, 0); | |
2346 | ||
2347 | XFASTINT (XWINDOW (root_window)->width) = SCREEN_WIDTH (s); | |
2348 | XFASTINT (mini_w->width) = SCREEN_WIDTH (s); | |
2349 | } | |
2350 | } |