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