1 /* Updating of data structures for redisplay.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #define DOC_STRINGS_IN_COMMENTS
36 #include "termhooks.h"
37 /* cm.h must come after dispextern.h on Windows. */
38 #include "dispextern.h"
48 #include "intervals.h"
49 #include "blockinput.h"
52 /* I don't know why DEC Alpha OSF1 fail to compile this file if we
53 include the following file. */
54 /* #include "systty.h" */
55 #include "syssignal.h"
59 #endif /* HAVE_X_WINDOWS */
63 #endif /* HAVE_NTGUI */
67 #endif /* macintosh */
69 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
74 /* To get the prototype for `sleep'. */
80 /* Get number of chars of output now in the buffer of a stdio stream.
81 This ought to be built in in stdio, but it isn't. Some s- files
82 override this because their stdio internals differ. */
84 #ifdef __GNU_LIBRARY__
86 /* The s- file might have overridden the definition with one that
87 works for the system's C library. But we are using the GNU C
88 library, so this is the right definition for every system. */
90 #ifdef GNU_LIBRARY_PENDING_OUTPUT_COUNT
91 #define PENDING_OUTPUT_COUNT GNU_LIBRARY_PENDING_OUTPUT_COUNT
93 #undef PENDING_OUTPUT_COUNT
94 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
96 #else /* not __GNU_LIBRARY__ */
97 #if !defined (PENDING_OUTPUT_COUNT) && HAVE_STDIO_EXT_H && HAVE___FPENDING
98 #include <stdio_ext.h>
99 #define PENDING_OUTPUT_COUNT(FILE) __fpending (FILE)
101 #ifndef PENDING_OUTPUT_COUNT
102 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
104 #endif /* not __GNU_LIBRARY__ */
106 #if defined(HAVE_TERM_H) && defined (LINUX) && defined (HAVE_LIBNCURSES)
107 #include <term.h> /* for tgetent */
110 /* Structure to pass dimensions around. Used for character bounding
111 boxes, glyph matrix dimensions and alike. */
120 /* Function prototypes. */
122 static struct glyph_matrix
*save_current_matrix
P_ ((struct frame
*));
123 static void restore_current_matrix
P_ ((struct frame
*, struct glyph_matrix
*));
124 static void fake_current_matrices
P_ ((Lisp_Object
));
125 static void redraw_overlapping_rows
P_ ((struct window
*, int));
126 static void redraw_overlapped_rows
P_ ((struct window
*, int));
127 static int count_blanks
P_ ((struct glyph
*, int));
128 static int count_match
P_ ((struct glyph
*, struct glyph
*,
129 struct glyph
*, struct glyph
*));
130 static unsigned line_draw_cost
P_ ((struct glyph_matrix
*, int));
131 static void update_frame_line
P_ ((struct frame
*, int));
132 static struct dim allocate_matrices_for_frame_redisplay
133 P_ ((Lisp_Object
, int, int, int, int *));
134 static void allocate_matrices_for_window_redisplay
P_ ((struct window
*));
135 static int realloc_glyph_pool
P_ ((struct glyph_pool
*, struct dim
));
136 static void adjust_frame_glyphs
P_ ((struct frame
*));
137 struct glyph_matrix
*new_glyph_matrix
P_ ((struct glyph_pool
*));
138 static void free_glyph_matrix
P_ ((struct glyph_matrix
*));
139 static void adjust_glyph_matrix
P_ ((struct window
*, struct glyph_matrix
*,
140 int, int, struct dim
));
141 static void change_frame_size_1
P_ ((struct frame
*, int, int, int, int, int));
142 static void swap_glyph_pointers
P_ ((struct glyph_row
*, struct glyph_row
*));
144 static int glyph_row_slice_p
P_ ((struct glyph_row
*, struct glyph_row
*));
146 static void fill_up_frame_row_with_spaces
P_ ((struct glyph_row
*, int));
147 static void build_frame_matrix_from_window_tree
P_ ((struct glyph_matrix
*,
149 static void build_frame_matrix_from_leaf_window
P_ ((struct glyph_matrix
*,
151 static struct glyph_pool
*new_glyph_pool
P_ ((void));
152 static void free_glyph_pool
P_ ((struct glyph_pool
*));
153 static void adjust_frame_glyphs_initially
P_ ((void));
154 static void adjust_frame_message_buffer
P_ ((struct frame
*));
155 static void adjust_decode_mode_spec_buffer
P_ ((struct frame
*));
156 static void fill_up_glyph_row_with_spaces
P_ ((struct glyph_row
*));
157 static void build_frame_matrix
P_ ((struct frame
*));
158 void clear_current_matrices
P_ ((struct frame
*));
159 void scroll_glyph_matrix_range
P_ ((struct glyph_matrix
*, int, int,
161 static void clear_window_matrices
P_ ((struct window
*, int));
162 static void fill_up_glyph_row_area_with_spaces
P_ ((struct glyph_row
*, int));
163 static int scrolling_window
P_ ((struct window
*, int));
164 static int update_window_line
P_ ((struct window
*, int, int *));
165 static void update_marginal_area
P_ ((struct window
*, int, int));
166 static int update_text_area
P_ ((struct window
*, int));
167 static void make_current
P_ ((struct glyph_matrix
*, struct glyph_matrix
*,
169 static void mirror_make_current
P_ ((struct window
*, int));
170 void check_window_matrix_pointers
P_ ((struct window
*));
172 static void check_matrix_pointers
P_ ((struct glyph_matrix
*,
173 struct glyph_matrix
*));
175 static void mirror_line_dance
P_ ((struct window
*, int, int, int *, char *));
176 static int update_window_tree
P_ ((struct window
*, int));
177 static int update_window
P_ ((struct window
*, int));
178 static int update_frame_1
P_ ((struct frame
*, int, int));
179 static void set_window_cursor_after_update
P_ ((struct window
*));
180 static int row_equal_p
P_ ((struct window
*, struct glyph_row
*,
181 struct glyph_row
*, int));
182 static void adjust_frame_glyphs_for_window_redisplay
P_ ((struct frame
*));
183 static void adjust_frame_glyphs_for_frame_redisplay
P_ ((struct frame
*));
184 static void reverse_rows
P_ ((struct glyph_matrix
*, int, int));
185 static int margin_glyphs_to_reserve
P_ ((struct window
*, int, Lisp_Object
));
186 static void sync_window_with_frame_matrix_rows
P_ ((struct window
*));
187 struct window
*frame_row_to_window
P_ ((struct window
*, int));
190 /* Non-zero means don't pause redisplay for pending input. (This is
191 for debugging and for a future implementation of EDT-like
194 int redisplay_dont_pause
;
196 /* Nonzero upon entry to redisplay means do not assume anything about
197 current contents of actual terminal frame; clear and redraw it. */
201 /* Nonzero means last display completed. Zero means it was preempted. */
203 int display_completed
;
205 /* Lisp variable visible-bell; enables use of screen-flash instead of
210 /* Invert the color of the whole frame, at a low level. */
214 /* Line speed of the terminal. */
218 /* Either nil or a symbol naming the window system under which Emacs
221 Lisp_Object Vwindow_system
;
223 /* Version number of X windows: 10, 11 or nil. */
225 Lisp_Object Vwindow_system_version
;
227 /* Vector of glyph definitions. Indexed by glyph number, the contents
228 are a string which is how to output the glyph.
230 If Vglyph_table is nil, a glyph is output by using its low 8 bits
233 This is an obsolete feature that is no longer used. The variable
234 is retained for compatibility. */
236 Lisp_Object Vglyph_table
;
238 /* Display table to use for vectors that don't specify their own. */
240 Lisp_Object Vstandard_display_table
;
242 /* Nonzero means reading single-character input with prompt so put
243 cursor on mini-buffer after the prompt. positive means at end of
244 text in echo area; negative means at beginning of line. */
246 int cursor_in_echo_area
;
248 Lisp_Object Qdisplay_table
, Qredisplay_dont_pause
;
251 /* The currently selected frame. In a single-frame version, this
252 variable always equals the_only_frame. */
254 Lisp_Object selected_frame
;
256 /* A frame which is not just a mini-buffer, or 0 if there are no such
257 frames. This is usually the most recent such frame that was
258 selected. In a single-frame version, this variable always holds
259 the address of the_only_frame. */
261 struct frame
*last_nonminibuf_frame
;
263 /* Stdio stream being used for copy of all output. */
267 /* Structure for info on cursor positioning. */
271 /* 1 means SIGWINCH happened when not safe. */
273 int delayed_size_change
;
275 /* 1 means glyph initialization has been completed at startup. */
277 static int glyphs_initialized_initially_p
;
279 /* Updated window if != 0. Set by update_window. */
281 struct window
*updated_window
;
283 /* Glyph row updated in update_window_line, and area that is updated. */
285 struct glyph_row
*updated_row
;
288 /* A glyph for a space. */
290 struct glyph space_glyph
;
292 /* Non-zero means update has been performed directly, so that there's
293 no need for redisplay_internal to do much work. Set by
294 direct_output_for_insert. */
296 int redisplay_performed_directly_p
;
298 /* Counts of allocated structures. These counts serve to diagnose
299 memory leaks and double frees. */
301 int glyph_matrix_count
;
302 int glyph_pool_count
;
304 /* If non-null, the frame whose frame matrices are manipulated. If
305 null, window matrices are worked on. */
307 static struct frame
*frame_matrix_frame
;
309 /* Current interface for window-based redisplay. Set from init_xterm.
310 A null value means we are not using window-based redisplay. */
312 struct redisplay_interface
*rif
;
314 /* Non-zero means that fonts have been loaded since the last glyph
315 matrix adjustments. Redisplay must stop, and glyph matrices must
316 be adjusted when this flag becomes non-zero during display. The
317 reason fonts can be loaded so late is that fonts of fontsets are
322 /* Convert vpos and hpos from frame to window and vice versa.
323 This may only be used for terminal frames. */
327 static int window_to_frame_vpos
P_ ((struct window
*, int));
328 static int window_to_frame_hpos
P_ ((struct window
*, int));
329 #define WINDOW_TO_FRAME_VPOS(W, VPOS) window_to_frame_vpos ((W), (VPOS))
330 #define WINDOW_TO_FRAME_HPOS(W, HPOS) window_to_frame_hpos ((W), (HPOS))
332 /* One element of the ring buffer containing redisplay history
335 struct redisplay_history
337 char trace
[512 + 100];
340 /* The size of the history buffer. */
342 #define REDISPLAY_HISTORY_SIZE 30
344 /* The redisplay history buffer. */
346 static struct redisplay_history redisplay_history
[REDISPLAY_HISTORY_SIZE
];
348 /* Next free entry in redisplay_history. */
350 static int history_idx
;
352 /* A tick that's incremented each time something is added to the
355 static unsigned history_tick
;
357 static void add_frame_display_history
P_ ((struct frame
*, int));
358 static void add_window_display_history
P_ ((struct window
*, char *, int));
361 /* Add to the redisplay history how window W has been displayed.
362 MSG is a trace containing the information how W's glyph matrix
363 has been contructed. PAUSED_P non-zero means that the update
364 has been interrupted for pending input. */
367 add_window_display_history (w
, msg
, paused_p
)
374 if (history_idx
>= REDISPLAY_HISTORY_SIZE
)
376 buf
= redisplay_history
[history_idx
].trace
;
379 sprintf (buf
, "%d: window %p (`%s')%s\n",
382 ((BUFFERP (w
->buffer
)
383 && STRINGP (XBUFFER (w
->buffer
)->name
))
384 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
386 paused_p
? " ***paused***" : "");
391 /* Add to the redisplay history that frame F has been displayed.
392 PAUSED_P non-zero means that the update has been interrupted for
396 add_frame_display_history (f
, paused_p
)
402 if (history_idx
>= REDISPLAY_HISTORY_SIZE
)
404 buf
= redisplay_history
[history_idx
].trace
;
407 sprintf (buf
, "%d: update frame %p%s",
409 f
, paused_p
? " ***paused***" : "");
413 DEFUN ("dump-redisplay-history", Fdump_redisplay_history
,
414 Sdump_redisplay_history
, 0, 0, "",
415 /* Dump redisplay history to stderr. */
420 for (i
= history_idx
- 1; i
!= history_idx
; --i
)
423 i
= REDISPLAY_HISTORY_SIZE
- 1;
424 fprintf (stderr
, "%s\n", redisplay_history
[i
].trace
);
431 #else /* GLYPH_DEBUG == 0 */
433 #define WINDOW_TO_FRAME_VPOS(W, VPOS) ((VPOS) + XFASTINT ((W)->top))
434 #define WINDOW_TO_FRAME_HPOS(W, HPOS) ((HPOS) + XFASTINT ((W)->left))
436 #endif /* GLYPH_DEBUG == 0 */
439 /* Like bcopy except never gets confused by overlap. Let this be the
440 first function defined in this file, or change emacs.c where the
441 address of this function is used. */
444 safe_bcopy (from
, to
, size
)
448 if (size
<= 0 || from
== to
)
451 /* If the source and destination don't overlap, then bcopy can
452 handle it. If they do overlap, but the destination is lower in
453 memory than the source, we'll assume bcopy can handle that. */
454 if (to
< from
|| from
+ size
<= to
)
455 bcopy (from
, to
, size
);
457 /* Otherwise, we'll copy from the end. */
460 register char *endf
= from
+ size
;
461 register char *endt
= to
+ size
;
463 /* If TO - FROM is large, then we should break the copy into
464 nonoverlapping chunks of TO - FROM bytes each. However, if
465 TO - FROM is small, then the bcopy function call overhead
466 makes this not worth it. The crossover point could be about
467 anywhere. Since I don't think the obvious copy loop is too
468 bad, I'm trying to err in its favor. */
473 while (endf
!= from
);
485 bcopy (endf
, endt
, to
- from
);
488 /* If SIZE wasn't a multiple of TO - FROM, there will be a
489 little left over. The amount left over is (endt + (to -
490 from)) - to, which is endt - from. */
491 bcopy (from
, to
, endt
- from
);
498 /***********************************************************************
500 ***********************************************************************/
502 /* Allocate and return a glyph_matrix structure. POOL is the glyph
503 pool from which memory for the matrix should be allocated, or null
504 for window-based redisplay where no glyph pools are used. The
505 member `pool' of the glyph matrix structure returned is set to
506 POOL, the structure is otherwise zeroed. */
508 struct glyph_matrix
*
509 new_glyph_matrix (pool
)
510 struct glyph_pool
*pool
;
512 struct glyph_matrix
*result
;
514 /* Allocate and clear. */
515 result
= (struct glyph_matrix
*) xmalloc (sizeof *result
);
516 bzero (result
, sizeof *result
);
518 /* Increment number of allocated matrices. This count is used
519 to detect memory leaks. */
520 ++glyph_matrix_count
;
522 /* Set pool and return. */
528 /* Free glyph matrix MATRIX. Passing in a null MATRIX is allowed.
530 The global counter glyph_matrix_count is decremented when a matrix
531 is freed. If the count gets negative, more structures were freed
532 than allocated, i.e. one matrix was freed more than once or a bogus
533 pointer was passed to this function.
535 If MATRIX->pool is null, this means that the matrix manages its own
536 glyph memory---this is done for matrices on X frames. Freeing the
537 matrix also frees the glyph memory in this case. */
540 free_glyph_matrix (matrix
)
541 struct glyph_matrix
*matrix
;
547 /* Detect the case that more matrices are freed than were
549 if (--glyph_matrix_count
< 0)
552 /* Free glyph memory if MATRIX owns it. */
553 if (matrix
->pool
== NULL
)
554 for (i
= 0; i
< matrix
->rows_allocated
; ++i
)
555 xfree (matrix
->rows
[i
].glyphs
[LEFT_MARGIN_AREA
]);
557 /* Free row structures and the matrix itself. */
558 xfree (matrix
->rows
);
564 /* Return the number of glyphs to reserve for a marginal area of
565 window W. TOTAL_GLYPHS is the number of glyphs in a complete
566 display line of window W. MARGIN gives the width of the marginal
567 area in canonical character units. MARGIN should be an integer
571 margin_glyphs_to_reserve (w
, total_glyphs
, margin
)
578 if (NUMBERP (margin
))
580 int width
= XFASTINT (w
->width
);
581 double d
= max (0, XFLOATINT (margin
));
582 d
= min (width
/ 2 - 1, d
);
583 n
= (int) ((double) total_glyphs
/ width
* d
);
592 /* Adjust glyph matrix MATRIX on window W or on a frame to changed
595 W is null if the function is called for a frame glyph matrix.
596 Otherwise it is the window MATRIX is a member of. X and Y are the
597 indices of the first column and row of MATRIX within the frame
598 matrix, if such a matrix exists. They are zero for purely
599 window-based redisplay. DIM is the needed size of the matrix.
601 In window-based redisplay, where no frame matrices exist, glyph
602 matrices manage their own glyph storage. Otherwise, they allocate
603 storage from a common frame glyph pool which can be found in
606 The reason for this memory management strategy is to avoid complete
607 frame redraws if possible. When we allocate from a common pool, a
608 change of the location or size of a sub-matrix within the pool
609 requires a complete redisplay of the frame because we cannot easily
610 make sure that the current matrices of all windows still agree with
611 what is displayed on the screen. While this is usually fast, it
612 leads to screen flickering. */
615 adjust_glyph_matrix (w
, matrix
, x
, y
, dim
)
617 struct glyph_matrix
*matrix
;
623 int marginal_areas_changed_p
= 0;
624 int header_line_changed_p
= 0;
625 int header_line_p
= 0;
626 int left
= -1, right
= -1;
627 int window_x
, window_y
, window_width
= -1, window_height
;
629 /* See if W had a top line that has disappeared now, or vice versa. */
632 header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
633 header_line_changed_p
= header_line_p
!= matrix
->header_line_p
;
635 matrix
->header_line_p
= header_line_p
;
637 /* Do nothing if MATRIX' size, position, vscroll, and marginal areas
638 haven't changed. This optimization is important because preserving
639 the matrix means preventing redisplay. */
640 if (matrix
->pool
== NULL
)
642 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
643 left
= margin_glyphs_to_reserve (w
, dim
.width
, w
->left_margin_width
);
644 right
= margin_glyphs_to_reserve (w
, dim
.width
, w
->right_margin_width
);
645 xassert (left
>= 0 && right
>= 0);
646 marginal_areas_changed_p
= (left
!= matrix
->left_margin_glyphs
647 || right
!= matrix
->right_margin_glyphs
);
649 if (!marginal_areas_changed_p
651 && !header_line_changed_p
652 && matrix
->window_left_x
== XFASTINT (w
->left
)
653 && matrix
->window_top_y
== XFASTINT (w
->top
)
654 && matrix
->window_height
== window_height
655 && matrix
->window_vscroll
== w
->vscroll
656 && matrix
->window_width
== window_width
)
660 /* Enlarge MATRIX->rows if necessary. New rows are cleared. */
661 if (matrix
->rows_allocated
< dim
.height
)
663 int size
= dim
.height
* sizeof (struct glyph_row
);
664 new_rows
= dim
.height
- matrix
->rows_allocated
;
665 matrix
->rows
= (struct glyph_row
*) xrealloc (matrix
->rows
, size
);
666 bzero (matrix
->rows
+ matrix
->rows_allocated
,
667 new_rows
* sizeof *matrix
->rows
);
668 matrix
->rows_allocated
= dim
.height
;
673 /* If POOL is not null, MATRIX is a frame matrix or a window matrix
674 on a frame not using window-based redisplay. Set up pointers for
675 each row into the glyph pool. */
678 xassert (matrix
->pool
->glyphs
);
682 left
= margin_glyphs_to_reserve (w
, dim
.width
,
683 w
->left_margin_width
);
684 right
= margin_glyphs_to_reserve (w
, dim
.width
,
685 w
->right_margin_width
);
690 for (i
= 0; i
< dim
.height
; ++i
)
692 struct glyph_row
*row
= &matrix
->rows
[i
];
694 row
->glyphs
[LEFT_MARGIN_AREA
]
695 = (matrix
->pool
->glyphs
696 + (y
+ i
) * matrix
->pool
->ncolumns
700 || row
== matrix
->rows
+ dim
.height
- 1
701 || (row
== matrix
->rows
&& matrix
->header_line_p
))
703 row
->glyphs
[TEXT_AREA
]
704 = row
->glyphs
[LEFT_MARGIN_AREA
];
705 row
->glyphs
[RIGHT_MARGIN_AREA
]
706 = row
->glyphs
[TEXT_AREA
] + dim
.width
;
707 row
->glyphs
[LAST_AREA
]
708 = row
->glyphs
[RIGHT_MARGIN_AREA
];
712 row
->glyphs
[TEXT_AREA
]
713 = row
->glyphs
[LEFT_MARGIN_AREA
] + left
;
714 row
->glyphs
[RIGHT_MARGIN_AREA
]
715 = row
->glyphs
[TEXT_AREA
] + dim
.width
- left
- right
;
716 row
->glyphs
[LAST_AREA
]
717 = row
->glyphs
[LEFT_MARGIN_AREA
] + dim
.width
;
721 matrix
->left_margin_glyphs
= left
;
722 matrix
->right_margin_glyphs
= right
;
726 /* If MATRIX->pool is null, MATRIX is responsible for managing
727 its own memory. Allocate glyph memory from the heap. */
728 if (dim
.width
> matrix
->matrix_w
730 || header_line_changed_p
731 || marginal_areas_changed_p
)
733 struct glyph_row
*row
= matrix
->rows
;
734 struct glyph_row
*end
= row
+ matrix
->rows_allocated
;
738 row
->glyphs
[LEFT_MARGIN_AREA
]
739 = (struct glyph
*) xrealloc (row
->glyphs
[LEFT_MARGIN_AREA
],
741 * sizeof (struct glyph
)));
743 /* The mode line never has marginal areas. */
744 if (row
== matrix
->rows
+ dim
.height
- 1
745 || (row
== matrix
->rows
&& matrix
->header_line_p
))
747 row
->glyphs
[TEXT_AREA
]
748 = row
->glyphs
[LEFT_MARGIN_AREA
];
749 row
->glyphs
[RIGHT_MARGIN_AREA
]
750 = row
->glyphs
[TEXT_AREA
] + dim
.width
;
751 row
->glyphs
[LAST_AREA
]
752 = row
->glyphs
[RIGHT_MARGIN_AREA
];
756 row
->glyphs
[TEXT_AREA
]
757 = row
->glyphs
[LEFT_MARGIN_AREA
] + left
;
758 row
->glyphs
[RIGHT_MARGIN_AREA
]
759 = row
->glyphs
[TEXT_AREA
] + dim
.width
- left
- right
;
760 row
->glyphs
[LAST_AREA
]
761 = row
->glyphs
[LEFT_MARGIN_AREA
] + dim
.width
;
767 xassert (left
>= 0 && right
>= 0);
768 matrix
->left_margin_glyphs
= left
;
769 matrix
->right_margin_glyphs
= right
;
772 /* Number of rows to be used by MATRIX. */
773 matrix
->nrows
= dim
.height
;
774 xassert (matrix
->nrows
>= 0);
778 if (matrix
== w
->current_matrix
)
780 /* Mark rows in a current matrix of a window as not having
781 valid contents. It's important to not do this for
782 desired matrices. When Emacs starts, it may already be
783 building desired matrices when this function runs. */
784 if (window_width
< 0)
785 window_width
= window_box_width (w
, -1);
787 /* Optimize the case that only the height has changed (C-x 2,
788 upper window). Invalidate all rows that are no longer part
790 if (!marginal_areas_changed_p
791 && !header_line_changed_p
793 && dim
.width
== matrix
->matrix_w
794 && matrix
->window_left_x
== XFASTINT (w
->left
)
795 && matrix
->window_top_y
== XFASTINT (w
->top
)
796 && matrix
->window_width
== window_width
)
798 /* Find the last row in the window. */
799 for (i
= 0; i
< matrix
->nrows
&& matrix
->rows
[i
].enabled_p
; ++i
)
800 if (MATRIX_ROW_BOTTOM_Y (matrix
->rows
+ i
) >= window_height
)
806 /* Window end is invalid, if inside of the rows that
807 are invalidated below. */
808 if (INTEGERP (w
->window_end_vpos
)
809 && XFASTINT (w
->window_end_vpos
) >= i
)
810 w
->window_end_valid
= Qnil
;
812 while (i
< matrix
->nrows
)
813 matrix
->rows
[i
++].enabled_p
= 0;
817 for (i
= 0; i
< matrix
->nrows
; ++i
)
818 matrix
->rows
[i
].enabled_p
= 0;
821 else if (matrix
== w
->desired_matrix
)
823 /* Rows in desired matrices always have to be cleared;
824 redisplay expects this is the case when it runs, so it
825 had better be the case when we adjust matrices between
827 for (i
= 0; i
< matrix
->nrows
; ++i
)
828 matrix
->rows
[i
].enabled_p
= 0;
833 /* Remember last values to be able to optimize frame redraws. */
834 matrix
->matrix_x
= x
;
835 matrix
->matrix_y
= y
;
836 matrix
->matrix_w
= dim
.width
;
837 matrix
->matrix_h
= dim
.height
;
839 /* Record the top y location and height of W at the time the matrix
840 was last adjusted. This is used to optimize redisplay above. */
843 matrix
->window_left_x
= XFASTINT (w
->left
);
844 matrix
->window_top_y
= XFASTINT (w
->top
);
845 matrix
->window_height
= window_height
;
846 matrix
->window_width
= window_width
;
847 matrix
->window_vscroll
= w
->vscroll
;
852 /* Reverse the contents of rows in MATRIX between START and END. The
853 contents of the row at END - 1 end up at START, END - 2 at START +
854 1 etc. This is part of the implementation of rotate_matrix (see
858 reverse_rows (matrix
, start
, end
)
859 struct glyph_matrix
*matrix
;
864 for (i
= start
, j
= end
- 1; i
< j
; ++i
, --j
)
866 /* Non-ISO HP/UX compiler doesn't like auto struct
868 struct glyph_row temp
;
869 temp
= matrix
->rows
[i
];
870 matrix
->rows
[i
] = matrix
->rows
[j
];
871 matrix
->rows
[j
] = temp
;
876 /* Rotate the contents of rows in MATRIX in the range FIRST .. LAST -
877 1 by BY positions. BY < 0 means rotate left, i.e. towards lower
878 indices. (Note: this does not copy glyphs, only glyph pointers in
879 row structures are moved around).
881 The algorithm used for rotating the vector was, I believe, first
882 described by Kernighan. See the vector R as consisting of two
883 sub-vectors AB, where A has length BY for BY >= 0. The result
884 after rotating is then BA. Reverse both sub-vectors to get ArBr
885 and reverse the result to get (ArBr)r which is BA. Similar for
889 rotate_matrix (matrix
, first
, last
, by
)
890 struct glyph_matrix
*matrix
;
895 /* Up (rotate left, i.e. towards lower indices). */
897 reverse_rows (matrix
, first
, first
+ by
);
898 reverse_rows (matrix
, first
+ by
, last
);
899 reverse_rows (matrix
, first
, last
);
903 /* Down (rotate right, i.e. towards higher indices). */
904 reverse_rows (matrix
, last
- by
, last
);
905 reverse_rows (matrix
, first
, last
- by
);
906 reverse_rows (matrix
, first
, last
);
911 /* Increment buffer positions in glyph rows of MATRIX. Do it for rows
912 with indices START <= index < END. Increment positions by DELTA/
916 increment_matrix_positions (matrix
, start
, end
, delta
, delta_bytes
)
917 struct glyph_matrix
*matrix
;
918 int start
, end
, delta
, delta_bytes
;
920 /* Check that START and END are reasonable values. */
921 xassert (start
>= 0 && start
<= matrix
->nrows
);
922 xassert (end
>= 0 && end
<= matrix
->nrows
);
923 xassert (start
<= end
);
925 for (; start
< end
; ++start
)
926 increment_row_positions (matrix
->rows
+ start
, delta
, delta_bytes
);
930 /* Enable a range of rows in glyph matrix MATRIX. START and END are
931 the row indices of the first and last + 1 row to enable. If
932 ENABLED_P is non-zero, enabled_p flags in rows will be set to 1. */
935 enable_glyph_matrix_rows (matrix
, start
, end
, enabled_p
)
936 struct glyph_matrix
*matrix
;
940 xassert (start
<= end
);
941 xassert (start
>= 0 && start
< matrix
->nrows
);
942 xassert (end
>= 0 && end
<= matrix
->nrows
);
944 for (; start
< end
; ++start
)
945 matrix
->rows
[start
].enabled_p
= enabled_p
!= 0;
951 This empties all rows in MATRIX by setting the enabled_p flag for
952 all rows of the matrix to zero. The function prepare_desired_row
953 will eventually really clear a row when it sees one with a zero
956 Resets update hints to defaults value. The only update hint
957 currently present is the flag MATRIX->no_scrolling_p. */
960 clear_glyph_matrix (matrix
)
961 struct glyph_matrix
*matrix
;
965 enable_glyph_matrix_rows (matrix
, 0, matrix
->nrows
, 0);
966 matrix
->no_scrolling_p
= 0;
971 /* Shift part of the glyph matrix MATRIX of window W up or down.
972 Increment y-positions in glyph rows between START and END by DY,
973 and recompute their visible height. */
976 shift_glyph_matrix (w
, matrix
, start
, end
, dy
)
978 struct glyph_matrix
*matrix
;
983 xassert (start
<= end
);
984 xassert (start
>= 0 && start
< matrix
->nrows
);
985 xassert (end
>= 0 && end
<= matrix
->nrows
);
987 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
988 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
);
990 for (; start
< end
; ++start
)
992 struct glyph_row
*row
= &matrix
->rows
[start
];
995 row
->visible_height
= row
->height
;
998 row
->visible_height
-= min_y
- row
->y
;
999 if (row
->y
+ row
->height
> max_y
)
1000 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
1005 /* Mark all rows in current matrices of frame F as invalid. Marking
1006 invalid is done by setting enabled_p to zero for all rows in a
1010 clear_current_matrices (f
)
1011 register struct frame
*f
;
1013 /* Clear frame current matrix, if we have one. */
1014 if (f
->current_matrix
)
1015 clear_glyph_matrix (f
->current_matrix
);
1017 /* Clear the matrix of the menu bar window, if such a window exists.
1018 The menu bar window is currently used to display menus on X when
1019 no toolkit support is compiled in. */
1020 if (WINDOWP (f
->menu_bar_window
))
1021 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1023 /* Clear the matrix of the tool-bar window, if any. */
1024 if (WINDOWP (f
->tool_bar_window
))
1025 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1027 /* Clear current window matrices. */
1028 xassert (WINDOWP (FRAME_ROOT_WINDOW (f
)));
1029 clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)), 0);
1033 /* Clear out all display lines of F for a coming redisplay. */
1036 clear_desired_matrices (f
)
1037 register struct frame
*f
;
1039 if (f
->desired_matrix
)
1040 clear_glyph_matrix (f
->desired_matrix
);
1042 if (WINDOWP (f
->menu_bar_window
))
1043 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->desired_matrix
);
1045 if (WINDOWP (f
->tool_bar_window
))
1046 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->desired_matrix
);
1048 /* Do it for window matrices. */
1049 xassert (WINDOWP (FRAME_ROOT_WINDOW (f
)));
1050 clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)), 1);
1054 /* Clear matrices in window tree rooted in W. If DESIRED_P is
1055 non-zero clear desired matrices, otherwise clear current matrices. */
1058 clear_window_matrices (w
, desired_p
)
1064 if (!NILP (w
->hchild
))
1066 xassert (WINDOWP (w
->hchild
));
1067 clear_window_matrices (XWINDOW (w
->hchild
), desired_p
);
1069 else if (!NILP (w
->vchild
))
1071 xassert (WINDOWP (w
->vchild
));
1072 clear_window_matrices (XWINDOW (w
->vchild
), desired_p
);
1077 clear_glyph_matrix (w
->desired_matrix
);
1080 clear_glyph_matrix (w
->current_matrix
);
1081 w
->window_end_valid
= Qnil
;
1085 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
1091 /***********************************************************************
1094 See dispextern.h for an overall explanation of glyph rows.
1095 ***********************************************************************/
1097 /* Clear glyph row ROW. Do it in a way that makes it robust against
1098 changes in the glyph_row structure, i.e. addition or removal of
1099 structure members. */
1101 static struct glyph_row null_row
;
1104 clear_glyph_row (row
)
1105 struct glyph_row
*row
;
1107 struct glyph
*p
[1 + LAST_AREA
];
1109 /* Save pointers. */
1110 p
[LEFT_MARGIN_AREA
] = row
->glyphs
[LEFT_MARGIN_AREA
];
1111 p
[TEXT_AREA
] = row
->glyphs
[TEXT_AREA
];
1112 p
[RIGHT_MARGIN_AREA
] = row
->glyphs
[RIGHT_MARGIN_AREA
];
1113 p
[LAST_AREA
] = row
->glyphs
[LAST_AREA
];
1118 /* Restore pointers. */
1119 row
->glyphs
[LEFT_MARGIN_AREA
] = p
[LEFT_MARGIN_AREA
];
1120 row
->glyphs
[TEXT_AREA
] = p
[TEXT_AREA
];
1121 row
->glyphs
[RIGHT_MARGIN_AREA
] = p
[RIGHT_MARGIN_AREA
];
1122 row
->glyphs
[LAST_AREA
] = p
[LAST_AREA
];
1124 #if 0 /* At some point, some bit-fields of struct glyph were not set,
1125 which made glyphs unequal when compared with GLYPH_EQUAL_P.
1126 Redisplay outputs such glyphs, and flickering effects were
1127 the result. This also depended on the contents of memory
1128 returned by xmalloc. If flickering happens again, activate
1129 the code below If the flickering is gone with that, chances
1130 are that the flickering has the same reason as here. */
1131 bzero (p
[0], (char *) p
[LAST_AREA
] - (char *) p
[0]);
1136 /* Make ROW an empty, enabled row of canonical character height,
1137 in window W starting at y-position Y. */
1140 blank_row (w
, row
, y
)
1142 struct glyph_row
*row
;
1147 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1148 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
);
1150 clear_glyph_row (row
);
1152 row
->ascent
= row
->phys_ascent
= 0;
1153 row
->height
= row
->phys_height
= CANON_Y_UNIT (XFRAME (w
->frame
));
1154 row
->visible_height
= row
->height
;
1157 row
->visible_height
-= min_y
- row
->y
;
1158 if (row
->y
+ row
->height
> max_y
)
1159 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
1165 /* Increment buffer positions in glyph row ROW. DELTA and DELTA_BYTES
1166 are the amounts by which to change positions. Note that the first
1167 glyph of the text area of a row can have a buffer position even if
1168 the used count of the text area is zero. Such rows display line
1172 increment_row_positions (row
, delta
, delta_bytes
)
1173 struct glyph_row
*row
;
1174 int delta
, delta_bytes
;
1178 /* Increment start and end positions. */
1179 MATRIX_ROW_START_CHARPOS (row
) += delta
;
1180 MATRIX_ROW_START_BYTEPOS (row
) += delta_bytes
;
1181 MATRIX_ROW_END_CHARPOS (row
) += delta
;
1182 MATRIX_ROW_END_BYTEPOS (row
) += delta_bytes
;
1184 /* Increment positions in glyphs. */
1185 for (area
= 0; area
< LAST_AREA
; ++area
)
1186 for (i
= 0; i
< row
->used
[area
]; ++i
)
1187 if (BUFFERP (row
->glyphs
[area
][i
].object
)
1188 && row
->glyphs
[area
][i
].charpos
> 0)
1189 row
->glyphs
[area
][i
].charpos
+= delta
;
1191 /* Capture the case of rows displaying a line end. */
1192 if (row
->used
[TEXT_AREA
] == 0
1193 && MATRIX_ROW_DISPLAYS_TEXT_P (row
))
1194 row
->glyphs
[TEXT_AREA
]->charpos
+= delta
;
1199 /* Swap glyphs between two glyph rows A and B. This exchanges glyph
1200 contents, i.e. glyph structure contents are exchanged between A and
1201 B without changing glyph pointers in A and B. */
1204 swap_glyphs_in_rows (a
, b
)
1205 struct glyph_row
*a
, *b
;
1209 for (area
= 0; area
< LAST_AREA
; ++area
)
1211 /* Number of glyphs to swap. */
1212 int max_used
= max (a
->used
[area
], b
->used
[area
]);
1214 /* Start of glyphs in area of row A. */
1215 struct glyph
*glyph_a
= a
->glyphs
[area
];
1217 /* End + 1 of glyphs in area of row A. */
1218 struct glyph
*glyph_a_end
= a
->glyphs
[max_used
];
1220 /* Start of glyphs in area of row B. */
1221 struct glyph
*glyph_b
= b
->glyphs
[area
];
1223 while (glyph_a
< glyph_a_end
)
1225 /* Non-ISO HP/UX compiler doesn't like auto struct
1229 *glyph_a
= *glyph_b
;
1239 /* Exchange pointers to glyph memory between glyph rows A and B. */
1242 swap_glyph_pointers (a
, b
)
1243 struct glyph_row
*a
, *b
;
1246 for (i
= 0; i
< LAST_AREA
+ 1; ++i
)
1248 struct glyph
*temp
= a
->glyphs
[i
];
1249 a
->glyphs
[i
] = b
->glyphs
[i
];
1250 b
->glyphs
[i
] = temp
;
1255 /* Copy glyph row structure FROM to glyph row structure TO, except
1256 that glyph pointers in the structures are left unchanged. */
1259 copy_row_except_pointers (to
, from
)
1260 struct glyph_row
*to
, *from
;
1262 struct glyph
*pointers
[1 + LAST_AREA
];
1264 /* Save glyph pointers of TO. */
1265 bcopy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
1267 /* Do a structure assignment. */
1270 /* Restore original pointers of TO. */
1271 bcopy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
1275 /* Copy contents of glyph row FROM to glyph row TO. Glyph pointers in
1276 TO and FROM are left unchanged. Glyph contents are copied from the
1277 glyph memory of FROM to the glyph memory of TO. Increment buffer
1278 positions in row TO by DELTA/ DELTA_BYTES. */
1281 copy_glyph_row_contents (to
, from
, delta
, delta_bytes
)
1282 struct glyph_row
*to
, *from
;
1283 int delta
, delta_bytes
;
1287 /* This is like a structure assignment TO = FROM, except that
1288 glyph pointers in the rows are left unchanged. */
1289 copy_row_except_pointers (to
, from
);
1291 /* Copy glyphs from FROM to TO. */
1292 for (area
= 0; area
< LAST_AREA
; ++area
)
1293 if (from
->used
[area
])
1294 bcopy (from
->glyphs
[area
], to
->glyphs
[area
],
1295 from
->used
[area
] * sizeof (struct glyph
));
1297 /* Increment buffer positions in TO by DELTA. */
1298 increment_row_positions (to
, delta
, delta_bytes
);
1302 /* Assign glyph row FROM to glyph row TO. This works like a structure
1303 assignment TO = FROM, except that glyph pointers are not copied but
1304 exchanged between TO and FROM. Pointers must be exchanged to avoid
1308 assign_row (to
, from
)
1309 struct glyph_row
*to
, *from
;
1311 swap_glyph_pointers (to
, from
);
1312 copy_row_except_pointers (to
, from
);
1316 /* Test whether the glyph memory of the glyph row WINDOW_ROW, which is
1317 a row in a window matrix, is a slice of the glyph memory of the
1318 glyph row FRAME_ROW which is a row in a frame glyph matrix. Value
1319 is non-zero if the glyph memory of WINDOW_ROW is part of the glyph
1320 memory of FRAME_ROW. */
1325 glyph_row_slice_p (window_row
, frame_row
)
1326 struct glyph_row
*window_row
, *frame_row
;
1328 struct glyph
*window_glyph_start
= window_row
->glyphs
[0];
1329 struct glyph
*frame_glyph_start
= frame_row
->glyphs
[0];
1330 struct glyph
*frame_glyph_end
= frame_row
->glyphs
[LAST_AREA
];
1332 return (frame_glyph_start
<= window_glyph_start
1333 && window_glyph_start
< frame_glyph_end
);
1336 #endif /* GLYPH_DEBUG */
1340 /* Find the row in the window glyph matrix WINDOW_MATRIX being a slice
1341 of ROW in the frame matrix FRAME_MATRIX. Value is null if no row
1342 in WINDOW_MATRIX is found satisfying the condition. */
1344 static struct glyph_row
*
1345 find_glyph_row_slice (window_matrix
, frame_matrix
, row
)
1346 struct glyph_matrix
*window_matrix
, *frame_matrix
;
1351 xassert (row
>= 0 && row
< frame_matrix
->nrows
);
1353 for (i
= 0; i
< window_matrix
->nrows
; ++i
)
1354 if (glyph_row_slice_p (window_matrix
->rows
+ i
,
1355 frame_matrix
->rows
+ row
))
1358 return i
< window_matrix
->nrows
? window_matrix
->rows
+ i
: 0;
1363 /* Prepare ROW for display. Desired rows are cleared lazily,
1364 i.e. they are only marked as to be cleared by setting their
1365 enabled_p flag to zero. When a row is to be displayed, a prior
1366 call to this function really clears it. */
1369 prepare_desired_row (row
)
1370 struct glyph_row
*row
;
1372 if (!row
->enabled_p
)
1374 clear_glyph_row (row
);
1380 /* Return a hash code for glyph row ROW. */
1383 line_hash_code (row
)
1384 struct glyph_row
*row
;
1392 /* Give all highlighted lines the same hash code
1393 so as to encourage scrolling to leave them in place. */
1398 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1399 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1403 int c
= glyph
->u
.ch
;
1404 int face_id
= glyph
->face_id
;
1405 if (must_write_spaces
)
1407 hash
= (((hash
<< 4) + (hash
>> 24)) & 0x0fffffff) + c
;
1408 hash
= (((hash
<< 4) + (hash
>> 24)) & 0x0fffffff) + face_id
;
1421 /* Return the cost of drawing line VPOS In MATRIX. The cost equals
1422 the number of characters in the line. If must_write_spaces is
1423 zero, leading and trailing spaces are ignored. */
1426 line_draw_cost (matrix
, vpos
)
1427 struct glyph_matrix
*matrix
;
1430 struct glyph_row
*row
= matrix
->rows
+ vpos
;
1431 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
1432 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
];
1434 Lisp_Object
*glyph_table_base
= GLYPH_TABLE_BASE
;
1435 int glyph_table_len
= GLYPH_TABLE_LENGTH
;
1437 /* Ignore trailing and leading spaces if we can. */
1438 if (!must_write_spaces
)
1440 /* Skip from the end over trailing spaces. */
1441 while (end
> beg
&& CHAR_GLYPH_SPACE_P (*(end
- 1)))
1444 /* All blank line. */
1448 /* Skip over leading spaces. */
1449 while (CHAR_GLYPH_SPACE_P (*beg
))
1453 /* If we don't have a glyph-table, each glyph is one character,
1454 so return the number of glyphs. */
1455 if (glyph_table_base
== 0)
1459 /* Otherwise, scan the glyphs and accumulate their total length
1464 GLYPH g
= GLYPH_FROM_CHAR_GLYPH (*beg
);
1467 || GLYPH_SIMPLE_P (glyph_table_base
, glyph_table_len
, g
))
1470 len
+= GLYPH_LENGTH (glyph_table_base
, g
);
1480 /* Test two glyph rows A and B for equality. Value is non-zero if A
1481 and B have equal contents. W is the window to which the glyphs
1482 rows A and B belong. It is needed here to test for partial row
1483 visibility. MOUSE_FACE_P non-zero means compare the mouse_face_p
1484 flags of A and B, too. */
1487 row_equal_p (w
, a
, b
, mouse_face_p
)
1489 struct glyph_row
*a
, *b
;
1494 else if (a
->hash
!= b
->hash
)
1498 struct glyph
*a_glyph
, *b_glyph
, *a_end
;
1501 if (mouse_face_p
&& a
->mouse_face_p
!= b
->mouse_face_p
)
1504 /* Compare glyphs. */
1505 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
1507 if (a
->used
[area
] != b
->used
[area
])
1510 a_glyph
= a
->glyphs
[area
];
1511 a_end
= a_glyph
+ a
->used
[area
];
1512 b_glyph
= b
->glyphs
[area
];
1514 while (a_glyph
< a_end
1515 && GLYPH_EQUAL_P (a_glyph
, b_glyph
))
1516 ++a_glyph
, ++b_glyph
;
1518 if (a_glyph
!= a_end
)
1522 if (a
->truncated_on_left_p
!= b
->truncated_on_left_p
1523 || a
->inverse_p
!= b
->inverse_p
1524 || a
->fill_line_p
!= b
->fill_line_p
1525 || a
->truncated_on_right_p
!= b
->truncated_on_right_p
1526 || a
->overlay_arrow_p
!= b
->overlay_arrow_p
1527 || a
->continued_p
!= b
->continued_p
1528 || a
->indicate_empty_line_p
!= b
->indicate_empty_line_p
1529 || a
->overlapped_p
!= b
->overlapped_p
1530 || (MATRIX_ROW_CONTINUATION_LINE_P (a
)
1531 != MATRIX_ROW_CONTINUATION_LINE_P (b
))
1532 /* Different partially visible characters on left margin. */
1534 /* Different height. */
1535 || a
->ascent
!= b
->ascent
1536 || a
->phys_ascent
!= b
->phys_ascent
1537 || a
->phys_height
!= b
->phys_height
1538 || a
->visible_height
!= b
->visible_height
)
1547 /***********************************************************************
1550 See dispextern.h for an overall explanation of glyph pools.
1551 ***********************************************************************/
1553 /* Allocate a glyph_pool structure. The structure returned is
1554 initialized with zeros. The global variable glyph_pool_count is
1555 incremented for each pool allocated. */
1557 static struct glyph_pool
*
1560 struct glyph_pool
*result
;
1562 /* Allocate a new glyph_pool and clear it. */
1563 result
= (struct glyph_pool
*) xmalloc (sizeof *result
);
1564 bzero (result
, sizeof *result
);
1566 /* For memory leak and double deletion checking. */
1573 /* Free a glyph_pool structure POOL. The function may be called with
1574 a null POOL pointer. The global variable glyph_pool_count is
1575 decremented with every pool structure freed. If this count gets
1576 negative, more structures were freed than allocated, i.e. one
1577 structure must have been freed more than once or a bogus pointer
1578 was passed to free_glyph_pool. */
1581 free_glyph_pool (pool
)
1582 struct glyph_pool
*pool
;
1586 /* More freed than allocated? */
1588 xassert (glyph_pool_count
>= 0);
1590 xfree (pool
->glyphs
);
1596 /* Enlarge a glyph pool POOL. MATRIX_DIM gives the number of rows and
1597 columns we need. This function never shrinks a pool. The only
1598 case in which this would make sense, would be when a frame's size
1599 is changed from a large value to a smaller one. But, if someone
1600 does it once, we can expect that he will do it again.
1602 Value is non-zero if the pool changed in a way which makes
1603 re-adjusting window glyph matrices necessary. */
1606 realloc_glyph_pool (pool
, matrix_dim
)
1607 struct glyph_pool
*pool
;
1608 struct dim matrix_dim
;
1613 changed_p
= (pool
->glyphs
== 0
1614 || matrix_dim
.height
!= pool
->nrows
1615 || matrix_dim
.width
!= pool
->ncolumns
);
1617 /* Enlarge the glyph pool. */
1618 needed
= matrix_dim
.width
* matrix_dim
.height
;
1619 if (needed
> pool
->nglyphs
)
1621 int size
= needed
* sizeof (struct glyph
);
1624 pool
->glyphs
= (struct glyph
*) xrealloc (pool
->glyphs
, size
);
1627 pool
->glyphs
= (struct glyph
*) xmalloc (size
);
1628 bzero (pool
->glyphs
, size
);
1631 pool
->nglyphs
= needed
;
1634 /* Remember the number of rows and columns because (a) we use then
1635 to do sanity checks, and (b) the number of columns determines
1636 where rows in the frame matrix start---this must be available to
1637 determine pointers to rows of window sub-matrices. */
1638 pool
->nrows
= matrix_dim
.height
;
1639 pool
->ncolumns
= matrix_dim
.width
;
1646 /***********************************************************************
1648 ***********************************************************************/
1653 /* Flush standard output. This is sometimes useful to call from
1663 /* Check that no glyph pointers have been lost in MATRIX. If a
1664 pointer has been lost, e.g. by using a structure assignment between
1665 rows, at least one pointer must occur more than once in the rows of
1669 check_matrix_pointer_lossage (matrix
)
1670 struct glyph_matrix
*matrix
;
1674 for (i
= 0; i
< matrix
->nrows
; ++i
)
1675 for (j
= 0; j
< matrix
->nrows
; ++j
)
1677 || (matrix
->rows
[i
].glyphs
[TEXT_AREA
]
1678 != matrix
->rows
[j
].glyphs
[TEXT_AREA
]));
1682 /* Get a pointer to glyph row ROW in MATRIX, with bounds checks. */
1685 matrix_row (matrix
, row
)
1686 struct glyph_matrix
*matrix
;
1689 xassert (matrix
&& matrix
->rows
);
1690 xassert (row
>= 0 && row
< matrix
->nrows
);
1692 /* That's really too slow for normal testing because this function
1693 is called almost everywhere. Although---it's still astonishingly
1694 fast, so it is valuable to have for debugging purposes. */
1696 check_matrix_pointer_lossage (matrix
);
1699 return matrix
->rows
+ row
;
1703 #if 0 /* This function makes invalid assumptions when text is
1704 partially invisible. But it might come handy for debugging
1707 /* Check invariants that must hold for an up to date current matrix of
1711 check_matrix_invariants (w
)
1714 struct glyph_matrix
*matrix
= w
->current_matrix
;
1715 int yb
= window_text_bottom_y (w
);
1716 struct glyph_row
*row
= matrix
->rows
;
1717 struct glyph_row
*last_text_row
= NULL
;
1718 struct buffer
*saved
= current_buffer
;
1719 struct buffer
*buffer
= XBUFFER (w
->buffer
);
1722 /* This can sometimes happen for a fresh window. */
1723 if (matrix
->nrows
< 2)
1726 set_buffer_temp (buffer
);
1728 /* Note: last row is always reserved for the mode line. */
1729 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1730 && MATRIX_ROW_BOTTOM_Y (row
) < yb
)
1732 struct glyph_row
*next
= row
+ 1;
1734 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
1735 last_text_row
= row
;
1737 /* Check that character and byte positions are in sync. */
1738 xassert (MATRIX_ROW_START_BYTEPOS (row
)
1739 == CHAR_TO_BYTE (MATRIX_ROW_START_CHARPOS (row
)));
1741 /* CHAR_TO_BYTE aborts when invoked for a position > Z. We can
1742 have such a position temporarily in case of a minibuffer
1743 displaying something like `[Sole completion]' at its end. */
1744 if (MATRIX_ROW_END_CHARPOS (row
) < BUF_ZV (current_buffer
))
1745 xassert (MATRIX_ROW_END_BYTEPOS (row
)
1746 == CHAR_TO_BYTE (MATRIX_ROW_END_CHARPOS (row
)));
1748 /* Check that end position of `row' is equal to start position
1750 if (next
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (next
))
1752 xassert (MATRIX_ROW_END_CHARPOS (row
)
1753 == MATRIX_ROW_START_CHARPOS (next
));
1754 xassert (MATRIX_ROW_END_BYTEPOS (row
)
1755 == MATRIX_ROW_START_BYTEPOS (next
));
1760 xassert (w
->current_matrix
->nrows
== w
->desired_matrix
->nrows
);
1761 xassert (w
->desired_matrix
->rows
!= NULL
);
1762 set_buffer_temp (saved
);
1767 #endif /* GLYPH_DEBUG != 0 */
1771 /**********************************************************************
1772 Allocating/ Adjusting Glyph Matrices
1773 **********************************************************************/
1775 /* Allocate glyph matrices over a window tree for a frame-based
1778 X and Y are column/row within the frame glyph matrix where
1779 sub-matrices for the window tree rooted at WINDOW must be
1780 allocated. CH_DIM contains the dimensions of the smallest
1781 character that could be used during display. DIM_ONLY_P non-zero
1782 means that the caller of this function is only interested in the
1783 result matrix dimension, and matrix adjustments should not be
1786 The function returns the total width/height of the sub-matrices of
1787 the window tree. If called on a frame root window, the computation
1788 will take the mini-buffer window into account.
1790 *WINDOW_CHANGE_FLAGS is set to a bit mask with bits
1792 NEW_LEAF_MATRIX set if any window in the tree did not have a
1793 glyph matrices yet, and
1795 CHANGED_LEAF_MATRIX set if the dimension or location of a matrix of
1796 any window in the tree will be changed or have been changed (see
1799 *WINDOW_CHANGE_FLAGS must be initialized by the caller of this
1802 Windows are arranged into chains of windows on the same level
1803 through the next fields of window structures. Such a level can be
1804 either a sequence of horizontally adjacent windows from left to
1805 right, or a sequence of vertically adjacent windows from top to
1806 bottom. Each window in a horizontal sequence can be either a leaf
1807 window or a vertical sequence; a window in a vertical sequence can
1808 be either a leaf or a horizontal sequence. All windows in a
1809 horizontal sequence have the same height, and all windows in a
1810 vertical sequence have the same width.
1812 This function uses, for historical reasons, a more general
1813 algorithm to determine glyph matrix dimensions that would be
1816 The matrix height of a horizontal sequence is determined by the
1817 maximum height of any matrix in the sequence. The matrix width of
1818 a horizontal sequence is computed by adding up matrix widths of
1819 windows in the sequence.
1821 |<------- result width ------->|
1822 +---------+----------+---------+ ---
1825 +---------+ | | result height
1830 The matrix width of a vertical sequence is the maximum matrix width
1831 of any window in the sequence. Its height is computed by adding up
1832 matrix heights of windows in the sequence.
1834 |<---- result width -->|
1842 +------------+---------+ |
1845 +------------+---------+ --- */
1847 /* Bit indicating that a new matrix will be allocated or has been
1850 #define NEW_LEAF_MATRIX (1 << 0)
1852 /* Bit indicating that a matrix will or has changed its location or
1855 #define CHANGED_LEAF_MATRIX (1 << 1)
1858 allocate_matrices_for_frame_redisplay (window
, x
, y
, dim_only_p
,
1859 window_change_flags
)
1863 int *window_change_flags
;
1865 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1867 int wmax
= 0, hmax
= 0;
1871 int in_horz_combination_p
;
1873 /* What combination is WINDOW part of? Compute this once since the
1874 result is the same for all windows in the `next' chain. The
1875 special case of a root window (parent equal to nil) is treated
1876 like a vertical combination because a root window's `next'
1877 points to the mini-buffer window, if any, which is arranged
1878 vertically below other windows. */
1879 in_horz_combination_p
1880 = (!NILP (XWINDOW (window
)->parent
)
1881 && !NILP (XWINDOW (XWINDOW (window
)->parent
)->hchild
));
1883 /* For WINDOW and all windows on the same level. */
1886 w
= XWINDOW (window
);
1888 /* Get the dimension of the window sub-matrix for W, depending
1889 on whether this a combination or a leaf window. */
1890 if (!NILP (w
->hchild
))
1891 dim
= allocate_matrices_for_frame_redisplay (w
->hchild
, x
, y
,
1893 window_change_flags
);
1894 else if (!NILP (w
->vchild
))
1895 dim
= allocate_matrices_for_frame_redisplay (w
->vchild
, x
, y
,
1897 window_change_flags
);
1900 /* If not already done, allocate sub-matrix structures. */
1901 if (w
->desired_matrix
== NULL
)
1903 w
->desired_matrix
= new_glyph_matrix (f
->desired_pool
);
1904 w
->current_matrix
= new_glyph_matrix (f
->current_pool
);
1905 *window_change_flags
|= NEW_LEAF_MATRIX
;
1908 /* Width and height MUST be chosen so that there are no
1909 holes in the frame matrix. */
1910 dim
.width
= required_matrix_width (w
);
1911 dim
.height
= required_matrix_height (w
);
1913 /* Will matrix be re-allocated? */
1914 if (x
!= w
->desired_matrix
->matrix_x
1915 || y
!= w
->desired_matrix
->matrix_y
1916 || dim
.width
!= w
->desired_matrix
->matrix_w
1917 || dim
.height
!= w
->desired_matrix
->matrix_h
1918 || (margin_glyphs_to_reserve (w
, dim
.width
,
1919 w
->right_margin_width
)
1920 != w
->desired_matrix
->left_margin_glyphs
)
1921 || (margin_glyphs_to_reserve (w
, dim
.width
,
1922 w
->left_margin_width
)
1923 != w
->desired_matrix
->right_margin_glyphs
))
1924 *window_change_flags
|= CHANGED_LEAF_MATRIX
;
1926 /* Actually change matrices, if allowed. Do not consider
1927 CHANGED_LEAF_MATRIX computed above here because the pool
1928 may have been changed which we don't now here. We trust
1929 that we only will be called with DIM_ONLY_P != 0 when
1933 adjust_glyph_matrix (w
, w
->desired_matrix
, x
, y
, dim
);
1934 adjust_glyph_matrix (w
, w
->current_matrix
, x
, y
, dim
);
1938 /* If we are part of a horizontal combination, advance x for
1939 windows to the right of W; otherwise advance y for windows
1941 if (in_horz_combination_p
)
1946 /* Remember maximum glyph matrix dimensions. */
1947 wmax
= max (wmax
, dim
.width
);
1948 hmax
= max (hmax
, dim
.height
);
1950 /* Next window on same level. */
1953 while (!NILP (window
));
1955 /* Set `total' to the total glyph matrix dimension of this window
1956 level. In a vertical combination, the width is the width of the
1957 widest window; the height is the y we finally reached, corrected
1958 by the y we started with. In a horizontal combination, the total
1959 height is the height of the tallest window, and the width is the
1960 x we finally reached, corrected by the x we started with. */
1961 if (in_horz_combination_p
)
1963 total
.width
= x
- x0
;
1964 total
.height
= hmax
;
1969 total
.height
= y
- y0
;
1976 /* Return the required height of glyph matrices for window W. */
1979 required_matrix_height (w
)
1982 #ifdef HAVE_WINDOW_SYSTEM
1983 struct frame
*f
= XFRAME (w
->frame
);
1985 if (FRAME_WINDOW_P (f
))
1987 int ch_height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
1988 int window_pixel_height
= window_box_height (w
) + abs (w
->vscroll
);
1989 return (((window_pixel_height
+ ch_height
- 1)
1991 /* One partially visible line at the top and
1992 bottom of the window. */
1994 /* 2 for top and mode line. */
1997 #endif /* HAVE_WINDOW_SYSTEM */
1999 return XINT (w
->height
);
2003 /* Return the required width of glyph matrices for window W. */
2006 required_matrix_width (w
)
2009 #ifdef HAVE_WINDOW_SYSTEM
2010 struct frame
*f
= XFRAME (w
->frame
);
2011 if (FRAME_WINDOW_P (f
))
2013 int ch_width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2014 int window_pixel_width
= XFLOATINT (w
->width
) * CANON_X_UNIT (f
);
2016 /* Compute number of glyphs needed in a glyph row. */
2017 return (((window_pixel_width
+ ch_width
- 1)
2019 /* 2 partially visible columns in the text area. */
2021 /* One partially visible column at the right
2022 edge of each marginal area. */
2025 #endif /* HAVE_WINDOW_SYSTEM */
2027 return XINT (w
->width
);
2031 /* Allocate window matrices for window-based redisplay. W is the
2032 window whose matrices must be allocated/reallocated. CH_DIM is the
2033 size of the smallest character that could potentially be used on W. */
2036 allocate_matrices_for_window_redisplay (w
)
2041 if (!NILP (w
->vchild
))
2042 allocate_matrices_for_window_redisplay (XWINDOW (w
->vchild
));
2043 else if (!NILP (w
->hchild
))
2044 allocate_matrices_for_window_redisplay (XWINDOW (w
->hchild
));
2047 /* W is a leaf window. */
2050 /* If matrices are not yet allocated, allocate them now. */
2051 if (w
->desired_matrix
== NULL
)
2053 w
->desired_matrix
= new_glyph_matrix (NULL
);
2054 w
->current_matrix
= new_glyph_matrix (NULL
);
2057 dim
.width
= required_matrix_width (w
);
2058 dim
.height
= required_matrix_height (w
);
2059 adjust_glyph_matrix (w
, w
->desired_matrix
, 0, 0, dim
);
2060 adjust_glyph_matrix (w
, w
->current_matrix
, 0, 0, dim
);
2063 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
2068 /* Re-allocate/ re-compute glyph matrices on frame F. If F is null,
2069 do it for all frames; otherwise do it just for the given frame.
2070 This function must be called when a new frame is created, its size
2071 changes, or its window configuration changes. */
2077 /* Block input so that expose events and other events that access
2078 glyph matrices are not processed while we are changing them. */
2082 adjust_frame_glyphs (f
);
2085 Lisp_Object tail
, lisp_frame
;
2087 FOR_EACH_FRAME (tail
, lisp_frame
)
2088 adjust_frame_glyphs (XFRAME (lisp_frame
));
2095 /* Adjust frame glyphs when Emacs is initialized.
2097 To be called from init_display.
2099 We need a glyph matrix because redraw will happen soon.
2100 Unfortunately, window sizes on selected_frame are not yet set to
2101 meaningful values. I believe we can assume that there are only two
2102 windows on the frame---the mini-buffer and the root window. Frame
2103 height and width seem to be correct so far. So, set the sizes of
2104 windows to estimated values. */
2107 adjust_frame_glyphs_initially ()
2109 struct frame
*sf
= SELECTED_FRAME ();
2110 struct window
*root
= XWINDOW (sf
->root_window
);
2111 struct window
*mini
= XWINDOW (root
->next
);
2112 int frame_height
= FRAME_HEIGHT (sf
);
2113 int frame_width
= FRAME_WIDTH (sf
);
2114 int top_margin
= FRAME_TOP_MARGIN (sf
);
2116 /* Do it for the root window. */
2117 XSETFASTINT (root
->top
, top_margin
);
2118 XSETFASTINT (root
->width
, frame_width
);
2119 set_window_height (sf
->root_window
, frame_height
- 1 - top_margin
, 0);
2121 /* Do it for the mini-buffer window. */
2122 XSETFASTINT (mini
->top
, frame_height
- 1);
2123 XSETFASTINT (mini
->width
, frame_width
);
2124 set_window_height (root
->next
, 1, 0);
2126 adjust_frame_glyphs (sf
);
2127 glyphs_initialized_initially_p
= 1;
2131 /* Allocate/reallocate glyph matrices of a single frame F. */
2134 adjust_frame_glyphs (f
)
2137 if (FRAME_WINDOW_P (f
))
2138 adjust_frame_glyphs_for_window_redisplay (f
);
2140 adjust_frame_glyphs_for_frame_redisplay (f
);
2142 /* Don't forget the message buffer and the buffer for
2143 decode_mode_spec. */
2144 adjust_frame_message_buffer (f
);
2145 adjust_decode_mode_spec_buffer (f
);
2147 f
->glyphs_initialized_p
= 1;
2151 /* In the window tree with root W, build current matrices of leaf
2152 windows from the frame's current matrix. */
2155 fake_current_matrices (window
)
2160 for (; !NILP (window
); window
= w
->next
)
2162 w
= XWINDOW (window
);
2164 if (!NILP (w
->hchild
))
2165 fake_current_matrices (w
->hchild
);
2166 else if (!NILP (w
->vchild
))
2167 fake_current_matrices (w
->vchild
);
2171 struct frame
*f
= XFRAME (w
->frame
);
2172 struct glyph_matrix
*m
= w
->current_matrix
;
2173 struct glyph_matrix
*fm
= f
->current_matrix
;
2175 xassert (m
->matrix_h
== XFASTINT (w
->height
));
2176 xassert (m
->matrix_w
== XFASTINT (w
->width
));
2178 for (i
= 0; i
< m
->matrix_h
; ++i
)
2180 struct glyph_row
*r
= m
->rows
+ i
;
2181 struct glyph_row
*fr
= fm
->rows
+ i
+ XFASTINT (w
->top
);
2183 xassert (r
->glyphs
[TEXT_AREA
] >= fr
->glyphs
[TEXT_AREA
]
2184 && r
->glyphs
[LAST_AREA
] <= fr
->glyphs
[LAST_AREA
]);
2186 r
->enabled_p
= fr
->enabled_p
;
2189 r
->used
[LEFT_MARGIN_AREA
] = m
->left_margin_glyphs
;
2190 r
->used
[RIGHT_MARGIN_AREA
] = m
->right_margin_glyphs
;
2191 r
->used
[TEXT_AREA
] = (m
->matrix_w
2192 - r
->used
[LEFT_MARGIN_AREA
]
2193 - r
->used
[RIGHT_MARGIN_AREA
]);
2195 r
->inverse_p
= fr
->inverse_p
;
2203 /* Save away the contents of frame F's current frame matrix. Value is
2204 a glyph matrix holding the contents of F's current frame matrix. '*/
2206 static struct glyph_matrix
*
2207 save_current_matrix (f
)
2211 struct glyph_matrix
*saved
;
2213 saved
= (struct glyph_matrix
*) xmalloc (sizeof *saved
);
2214 bzero (saved
, sizeof *saved
);
2215 saved
->nrows
= f
->current_matrix
->nrows
;
2216 saved
->rows
= (struct glyph_row
*) xmalloc (saved
->nrows
2217 * sizeof *saved
->rows
);
2218 bzero (saved
->rows
, saved
->nrows
* sizeof *saved
->rows
);
2220 for (i
= 0; i
< saved
->nrows
; ++i
)
2222 struct glyph_row
*from
= f
->current_matrix
->rows
+ i
;
2223 struct glyph_row
*to
= saved
->rows
+ i
;
2224 size_t nbytes
= from
->used
[TEXT_AREA
] * sizeof (struct glyph
);
2225 to
->glyphs
[TEXT_AREA
] = (struct glyph
*) xmalloc (nbytes
);
2226 bcopy (from
->glyphs
[TEXT_AREA
], to
->glyphs
[TEXT_AREA
], nbytes
);
2227 to
->used
[TEXT_AREA
] = from
->used
[TEXT_AREA
];
2234 /* Restore the contents of frame F's current frame matrix from SAVED,
2235 and free memory associated with SAVED. */
2238 restore_current_matrix (f
, saved
)
2240 struct glyph_matrix
*saved
;
2244 for (i
= 0; i
< saved
->nrows
; ++i
)
2246 struct glyph_row
*from
= saved
->rows
+ i
;
2247 struct glyph_row
*to
= f
->current_matrix
->rows
+ i
;
2248 size_t nbytes
= from
->used
[TEXT_AREA
] * sizeof (struct glyph
);
2249 bcopy (from
->glyphs
[TEXT_AREA
], to
->glyphs
[TEXT_AREA
], nbytes
);
2250 to
->used
[TEXT_AREA
] = from
->used
[TEXT_AREA
];
2251 xfree (from
->glyphs
[TEXT_AREA
]);
2254 xfree (saved
->rows
);
2260 /* Allocate/reallocate glyph matrices of a single frame F for
2261 frame-based redisplay. */
2264 adjust_frame_glyphs_for_frame_redisplay (f
)
2268 struct dim matrix_dim
;
2270 int window_change_flags
;
2273 if (!FRAME_LIVE_P (f
))
2276 /* Determine the smallest character in any font for F. On
2277 console windows, all characters have dimension (1, 1). */
2278 ch_dim
.width
= ch_dim
.height
= 1;
2280 top_window_y
= FRAME_TOP_MARGIN (f
);
2282 /* Allocate glyph pool structures if not already done. */
2283 if (f
->desired_pool
== NULL
)
2285 f
->desired_pool
= new_glyph_pool ();
2286 f
->current_pool
= new_glyph_pool ();
2289 /* Allocate frames matrix structures if needed. */
2290 if (f
->desired_matrix
== NULL
)
2292 f
->desired_matrix
= new_glyph_matrix (f
->desired_pool
);
2293 f
->current_matrix
= new_glyph_matrix (f
->current_pool
);
2296 /* Compute window glyph matrices. (This takes the mini-buffer
2297 window into account). The result is the size of the frame glyph
2298 matrix needed. The variable window_change_flags is set to a bit
2299 mask indicating whether new matrices will be allocated or
2300 existing matrices change their size or location within the frame
2302 window_change_flags
= 0;
2304 = allocate_matrices_for_frame_redisplay (FRAME_ROOT_WINDOW (f
),
2307 &window_change_flags
);
2309 /* Add in menu bar lines, if any. */
2310 matrix_dim
.height
+= top_window_y
;
2312 /* Enlarge pools as necessary. */
2313 pool_changed_p
= realloc_glyph_pool (f
->desired_pool
, matrix_dim
);
2314 realloc_glyph_pool (f
->current_pool
, matrix_dim
);
2316 /* Set up glyph pointers within window matrices. Do this only if
2317 absolutely necessary since it requires a frame redraw. */
2318 if (pool_changed_p
|| window_change_flags
)
2320 /* Do it for window matrices. */
2321 allocate_matrices_for_frame_redisplay (FRAME_ROOT_WINDOW (f
),
2323 &window_change_flags
);
2325 /* Size of frame matrices must equal size of frame. Note
2326 that we are called for X frames with window widths NOT equal
2327 to the frame width (from CHANGE_FRAME_SIZE_1). */
2328 xassert (matrix_dim
.width
== FRAME_WIDTH (f
)
2329 && matrix_dim
.height
== FRAME_HEIGHT (f
));
2331 /* Pointers to glyph memory in glyph rows are exchanged during
2332 the update phase of redisplay, which means in general that a
2333 frame's current matrix consists of pointers into both the
2334 desired and current glyph pool of the frame. Adjusting a
2335 matrix sets the frame matrix up so that pointers are all into
2336 the same pool. If we want to preserve glyph contents of the
2337 current matrix over a call to adjust_glyph_matrix, we must
2338 make a copy of the current glyphs, and restore the current
2339 matrix' contents from that copy. */
2340 if (display_completed
2341 && !FRAME_GARBAGED_P (f
)
2342 && matrix_dim
.width
== f
->current_matrix
->matrix_w
2343 && matrix_dim
.height
== f
->current_matrix
->matrix_h
)
2345 struct glyph_matrix
*copy
= save_current_matrix (f
);
2346 adjust_glyph_matrix (NULL
, f
->desired_matrix
, 0, 0, matrix_dim
);
2347 adjust_glyph_matrix (NULL
, f
->current_matrix
, 0, 0, matrix_dim
);
2348 restore_current_matrix (f
, copy
);
2349 fake_current_matrices (FRAME_ROOT_WINDOW (f
));
2353 adjust_glyph_matrix (NULL
, f
->desired_matrix
, 0, 0, matrix_dim
);
2354 adjust_glyph_matrix (NULL
, f
->current_matrix
, 0, 0, matrix_dim
);
2355 SET_FRAME_GARBAGED (f
);
2361 /* Allocate/reallocate glyph matrices of a single frame F for
2362 window-based redisplay. */
2365 adjust_frame_glyphs_for_window_redisplay (f
)
2371 xassert (FRAME_WINDOW_P (f
) && FRAME_LIVE_P (f
));
2373 /* Get minimum sizes. */
2374 #ifdef HAVE_WINDOW_SYSTEM
2375 ch_dim
.width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2376 ch_dim
.height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2378 ch_dim
.width
= ch_dim
.height
= 1;
2381 /* Allocate/reallocate window matrices. */
2382 allocate_matrices_for_window_redisplay (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2384 /* Allocate/ reallocate matrices of the dummy window used to display
2385 the menu bar under X when no X toolkit support is available. */
2386 #ifndef USE_X_TOOLKIT
2388 /* Allocate a dummy window if not already done. */
2389 if (NILP (f
->menu_bar_window
))
2391 f
->menu_bar_window
= make_window ();
2392 w
= XWINDOW (f
->menu_bar_window
);
2393 XSETFRAME (w
->frame
, f
);
2394 w
->pseudo_window_p
= 1;
2397 w
= XWINDOW (f
->menu_bar_window
);
2399 /* Set window dimensions to frame dimensions and allocate or
2400 adjust glyph matrices of W. */
2401 XSETFASTINT (w
->top
, 0);
2402 XSETFASTINT (w
->left
, 0);
2403 XSETFASTINT (w
->height
, FRAME_MENU_BAR_LINES (f
));
2404 XSETFASTINT (w
->width
, FRAME_WINDOW_WIDTH (f
));
2405 allocate_matrices_for_window_redisplay (w
);
2407 #endif /* not USE_X_TOOLKIT */
2409 /* Allocate/ reallocate matrices of the tool bar window. If we
2410 don't have a tool bar window yet, make one. */
2411 if (NILP (f
->tool_bar_window
))
2413 f
->tool_bar_window
= make_window ();
2414 w
= XWINDOW (f
->tool_bar_window
);
2415 XSETFRAME (w
->frame
, f
);
2416 w
->pseudo_window_p
= 1;
2419 w
= XWINDOW (f
->tool_bar_window
);
2421 XSETFASTINT (w
->top
, FRAME_MENU_BAR_LINES (f
));
2422 XSETFASTINT (w
->left
, 0);
2423 XSETFASTINT (w
->height
, FRAME_TOOL_BAR_LINES (f
));
2424 XSETFASTINT (w
->width
, FRAME_WINDOW_WIDTH (f
));
2425 allocate_matrices_for_window_redisplay (w
);
2429 /* Adjust/ allocate message buffer of frame F.
2431 Note that the message buffer is never freed. Since I could not
2432 find a free in 19.34, I assume that freeing it would be
2433 problematic in some way and don't do it either.
2435 (Implementation note: It should be checked if we can free it
2436 eventually without causing trouble). */
2439 adjust_frame_message_buffer (f
)
2442 int size
= FRAME_MESSAGE_BUF_SIZE (f
) + 1;
2444 if (FRAME_MESSAGE_BUF (f
))
2446 char *buffer
= FRAME_MESSAGE_BUF (f
);
2447 char *new_buffer
= (char *) xrealloc (buffer
, size
);
2448 FRAME_MESSAGE_BUF (f
) = new_buffer
;
2451 FRAME_MESSAGE_BUF (f
) = (char *) xmalloc (size
);
2455 /* Re-allocate buffer for decode_mode_spec on frame F. */
2458 adjust_decode_mode_spec_buffer (f
)
2461 f
->decode_mode_spec_buffer
2462 = (char *) xrealloc (f
->decode_mode_spec_buffer
,
2463 FRAME_MESSAGE_BUF_SIZE (f
) + 1);
2468 /**********************************************************************
2469 Freeing Glyph Matrices
2470 **********************************************************************/
2472 /* Free glyph memory for a frame F. F may be null. This function can
2473 be called for the same frame more than once. The root window of
2474 F may be nil when this function is called. This is the case when
2475 the function is called when F is destroyed. */
2481 if (f
&& f
->glyphs_initialized_p
)
2483 /* Block interrupt input so that we don't get surprised by an X
2484 event while we're in an inconsistent state. */
2486 f
->glyphs_initialized_p
= 0;
2488 /* Release window sub-matrices. */
2489 if (!NILP (f
->root_window
))
2490 free_window_matrices (XWINDOW (f
->root_window
));
2492 /* Free the dummy window for menu bars without X toolkit and its
2494 if (!NILP (f
->menu_bar_window
))
2496 struct window
*w
= XWINDOW (f
->menu_bar_window
);
2497 free_glyph_matrix (w
->desired_matrix
);
2498 free_glyph_matrix (w
->current_matrix
);
2499 w
->desired_matrix
= w
->current_matrix
= NULL
;
2500 f
->menu_bar_window
= Qnil
;
2503 /* Free the tool bar window and its glyph matrices. */
2504 if (!NILP (f
->tool_bar_window
))
2506 struct window
*w
= XWINDOW (f
->tool_bar_window
);
2507 free_glyph_matrix (w
->desired_matrix
);
2508 free_glyph_matrix (w
->current_matrix
);
2509 w
->desired_matrix
= w
->current_matrix
= NULL
;
2510 f
->tool_bar_window
= Qnil
;
2513 /* Release frame glyph matrices. Reset fields to zero in
2514 case we are called a second time. */
2515 if (f
->desired_matrix
)
2517 free_glyph_matrix (f
->desired_matrix
);
2518 free_glyph_matrix (f
->current_matrix
);
2519 f
->desired_matrix
= f
->current_matrix
= NULL
;
2522 /* Release glyph pools. */
2523 if (f
->desired_pool
)
2525 free_glyph_pool (f
->desired_pool
);
2526 free_glyph_pool (f
->current_pool
);
2527 f
->desired_pool
= f
->current_pool
= NULL
;
2535 /* Free glyph sub-matrices in the window tree rooted at W. This
2536 function may be called with a null pointer, and it may be called on
2537 the same tree more than once. */
2540 free_window_matrices (w
)
2545 if (!NILP (w
->hchild
))
2546 free_window_matrices (XWINDOW (w
->hchild
));
2547 else if (!NILP (w
->vchild
))
2548 free_window_matrices (XWINDOW (w
->vchild
));
2551 /* This is a leaf window. Free its memory and reset fields
2552 to zero in case this function is called a second time for
2554 free_glyph_matrix (w
->current_matrix
);
2555 free_glyph_matrix (w
->desired_matrix
);
2556 w
->current_matrix
= w
->desired_matrix
= NULL
;
2559 /* Next window on same level. */
2560 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2565 /* Check glyph memory leaks. This function is called from
2566 shut_down_emacs. Note that frames are not destroyed when Emacs
2567 exits. We therefore free all glyph memory for all active frames
2568 explicitly and check that nothing is left allocated. */
2571 check_glyph_memory ()
2573 Lisp_Object tail
, frame
;
2575 /* Free glyph memory for all frames. */
2576 FOR_EACH_FRAME (tail
, frame
)
2577 free_glyphs (XFRAME (frame
));
2579 /* Check that nothing is left allocated. */
2580 if (glyph_matrix_count
)
2582 if (glyph_pool_count
)
2588 /**********************************************************************
2589 Building a Frame Matrix
2590 **********************************************************************/
2592 /* Most of the redisplay code works on glyph matrices attached to
2593 windows. This is a good solution most of the time, but it is not
2594 suitable for terminal code. Terminal output functions cannot rely
2595 on being able to set an arbitrary terminal window. Instead they
2596 must be provided with a view of the whole frame, i.e. the whole
2597 screen. We build such a view by constructing a frame matrix from
2598 window matrices in this section.
2600 Windows that must be updated have their must_be_update_p flag set.
2601 For all such windows, their desired matrix is made part of the
2602 desired frame matrix. For other windows, their current matrix is
2603 made part of the desired frame matrix.
2605 +-----------------+----------------+
2606 | desired | desired |
2608 +-----------------+----------------+
2611 +----------------------------------+
2613 Desired window matrices can be made part of the frame matrix in a
2614 cheap way: We exploit the fact that the desired frame matrix and
2615 desired window matrices share their glyph memory. This is not
2616 possible for current window matrices. Their glyphs are copied to
2617 the desired frame matrix. The latter is equivalent to
2618 preserve_other_columns in the old redisplay.
2620 Used glyphs counters for frame matrix rows are the result of adding
2621 up glyph lengths of the window matrices. A line in the frame
2622 matrix is enabled, if a corresponding line in a window matrix is
2625 After building the desired frame matrix, it will be passed to
2626 terminal code, which will manipulate both the desired and current
2627 frame matrix. Changes applied to the frame's current matrix have
2628 to be visible in current window matrices afterwards, of course.
2630 This problem is solved like this:
2632 1. Window and frame matrices share glyphs. Window matrices are
2633 constructed in a way that their glyph contents ARE the glyph
2634 contents needed in a frame matrix. Thus, any modification of
2635 glyphs done in terminal code will be reflected in window matrices
2638 2. Exchanges of rows in a frame matrix done by terminal code are
2639 intercepted by hook functions so that corresponding row operations
2640 on window matrices can be performed. This is necessary because we
2641 use pointers to glyphs in glyph row structures. To satisfy the
2642 assumption of point 1 above that glyphs are updated implicitly in
2643 window matrices when they are manipulated via the frame matrix,
2644 window and frame matrix must of course agree where to find the
2645 glyphs for their rows. Possible manipulations that must be
2646 mirrored are assignments of rows of the desired frame matrix to the
2647 current frame matrix and scrolling the current frame matrix. */
2649 /* Build frame F's desired matrix from window matrices. Only windows
2650 which have the flag must_be_updated_p set have to be updated. Menu
2651 bar lines of a frame are not covered by window matrices, so make
2652 sure not to touch them in this function. */
2655 build_frame_matrix (f
)
2660 /* F must have a frame matrix when this function is called. */
2661 xassert (!FRAME_WINDOW_P (f
));
2663 /* Clear all rows in the frame matrix covered by window matrices.
2664 Menu bar lines are not covered by windows. */
2665 for (i
= FRAME_TOP_MARGIN (f
); i
< f
->desired_matrix
->nrows
; ++i
)
2666 clear_glyph_row (MATRIX_ROW (f
->desired_matrix
, i
));
2668 /* Build the matrix by walking the window tree. */
2669 build_frame_matrix_from_window_tree (f
->desired_matrix
,
2670 XWINDOW (FRAME_ROOT_WINDOW (f
)));
2674 /* Walk a window tree, building a frame matrix MATRIX from window
2675 matrices. W is the root of a window tree. */
2678 build_frame_matrix_from_window_tree (matrix
, w
)
2679 struct glyph_matrix
*matrix
;
2684 if (!NILP (w
->hchild
))
2685 build_frame_matrix_from_window_tree (matrix
, XWINDOW (w
->hchild
));
2686 else if (!NILP (w
->vchild
))
2687 build_frame_matrix_from_window_tree (matrix
, XWINDOW (w
->vchild
));
2689 build_frame_matrix_from_leaf_window (matrix
, w
);
2691 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2696 /* Add a window's matrix to a frame matrix. FRAME_MATRIX is the
2697 desired frame matrix built. W is a leaf window whose desired or
2698 current matrix is to be added to FRAME_MATRIX. W's flag
2699 must_be_updated_p determines which matrix it contributes to
2700 FRAME_MATRIX. If must_be_updated_p is non-zero, W's desired matrix
2701 is added to FRAME_MATRIX, otherwise W's current matrix is added.
2702 Adding a desired matrix means setting up used counters and such in
2703 frame rows, while adding a current window matrix to FRAME_MATRIX
2704 means copying glyphs. The latter case corresponds to
2705 preserve_other_columns in the old redisplay. */
2708 build_frame_matrix_from_leaf_window (frame_matrix
, w
)
2709 struct glyph_matrix
*frame_matrix
;
2712 struct glyph_matrix
*window_matrix
;
2713 int window_y
, frame_y
;
2714 /* If non-zero, a glyph to insert at the right border of W. */
2715 GLYPH right_border_glyph
= 0;
2717 /* Set window_matrix to the matrix we have to add to FRAME_MATRIX. */
2718 if (w
->must_be_updated_p
)
2720 window_matrix
= w
->desired_matrix
;
2722 /* Decide whether we want to add a vertical border glyph. */
2723 if (!WINDOW_RIGHTMOST_P (w
))
2725 struct Lisp_Char_Table
*dp
= window_display_table (w
);
2726 right_border_glyph
= (dp
&& INTEGERP (DISP_BORDER_GLYPH (dp
))
2727 ? XINT (DISP_BORDER_GLYPH (dp
))
2732 window_matrix
= w
->current_matrix
;
2734 /* For all rows in the window matrix and corresponding rows in the
2737 frame_y
= window_matrix
->matrix_y
;
2738 while (window_y
< window_matrix
->nrows
)
2740 struct glyph_row
*frame_row
= frame_matrix
->rows
+ frame_y
;
2741 struct glyph_row
*window_row
= window_matrix
->rows
+ window_y
;
2742 int current_row_p
= window_matrix
== w
->current_matrix
;
2744 /* Fill up the frame row with spaces up to the left margin of the
2746 fill_up_frame_row_with_spaces (frame_row
, window_matrix
->matrix_x
);
2748 /* Fill up areas in the window matrix row with spaces. */
2749 fill_up_glyph_row_with_spaces (window_row
);
2751 /* If only part of W's desired matrix has been built, and
2752 window_row wasn't displayed, use the corresponding current
2754 if (window_matrix
== w
->desired_matrix
2755 && !window_row
->enabled_p
)
2757 window_row
= w
->current_matrix
->rows
+ window_y
;
2763 /* Copy window row to frame row. */
2764 bcopy (window_row
->glyphs
[0],
2765 frame_row
->glyphs
[TEXT_AREA
] + window_matrix
->matrix_x
,
2766 window_matrix
->matrix_w
* sizeof (struct glyph
));
2770 xassert (window_row
->enabled_p
);
2772 /* Only when a desired row has been displayed, we want
2773 the corresponding frame row to be updated. */
2774 frame_row
->enabled_p
= 1;
2776 /* Maybe insert a vertical border between horizontally adjacent
2778 if (right_border_glyph
)
2780 struct glyph
*border
= window_row
->glyphs
[LAST_AREA
] - 1;
2781 SET_CHAR_GLYPH_FROM_GLYPH (*border
, right_border_glyph
);
2784 /* Window row window_y must be a slice of frame row
2786 xassert (glyph_row_slice_p (window_row
, frame_row
));
2788 /* If rows are in sync, we don't have to copy glyphs because
2789 frame and window share glyphs. */
2792 strcpy (w
->current_matrix
->method
, w
->desired_matrix
->method
);
2793 add_window_display_history (w
, w
->current_matrix
->method
, 0);
2797 /* Set number of used glyphs in the frame matrix. Since we fill
2798 up with spaces, and visit leaf windows from left to right it
2799 can be done simply. */
2800 frame_row
->used
[TEXT_AREA
]
2801 = window_matrix
->matrix_x
+ window_matrix
->matrix_w
;
2803 /* Or in other flags. */
2804 frame_row
->inverse_p
|= window_row
->inverse_p
;
2813 /* Add spaces to a glyph row ROW in a window matrix.
2815 Each row has the form:
2817 +---------+-----------------------------+------------+
2818 | left | text | right |
2819 +---------+-----------------------------+------------+
2821 Left and right marginal areas are optional. This function adds
2822 spaces to areas so that there are no empty holes between areas.
2823 In other words: If the right area is not empty, the text area
2824 is filled up with spaces up to the right area. If the text area
2825 is not empty, the left area is filled up.
2827 To be called for frame-based redisplay, only. */
2830 fill_up_glyph_row_with_spaces (row
)
2831 struct glyph_row
*row
;
2833 fill_up_glyph_row_area_with_spaces (row
, LEFT_MARGIN_AREA
);
2834 fill_up_glyph_row_area_with_spaces (row
, TEXT_AREA
);
2835 fill_up_glyph_row_area_with_spaces (row
, RIGHT_MARGIN_AREA
);
2839 /* Fill area AREA of glyph row ROW with spaces. To be called for
2840 frame-based redisplay only. */
2843 fill_up_glyph_row_area_with_spaces (row
, area
)
2844 struct glyph_row
*row
;
2847 if (row
->glyphs
[area
] < row
->glyphs
[area
+ 1])
2849 struct glyph
*end
= row
->glyphs
[area
+ 1];
2850 struct glyph
*text
= row
->glyphs
[area
] + row
->used
[area
];
2853 *text
++ = space_glyph
;
2854 row
->used
[area
] = text
- row
->glyphs
[area
];
2859 /* Add spaces to the end of ROW in a frame matrix until index UPTO is
2860 reached. In frame matrices only one area, TEXT_AREA, is used. */
2863 fill_up_frame_row_with_spaces (row
, upto
)
2864 struct glyph_row
*row
;
2867 int i
= row
->used
[TEXT_AREA
];
2868 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
2871 glyph
[i
++] = space_glyph
;
2873 row
->used
[TEXT_AREA
] = i
;
2878 /**********************************************************************
2879 Mirroring operations on frame matrices in window matrices
2880 **********************************************************************/
2882 /* Set frame being updated via frame-based redisplay to F. This
2883 function must be called before updates to make explicit that we are
2884 working on frame matrices or not. */
2887 set_frame_matrix_frame (f
)
2890 frame_matrix_frame
= f
;
2894 /* Make sure glyph row ROW in CURRENT_MATRIX is up to date.
2895 DESIRED_MATRIX is the desired matrix corresponding to
2896 CURRENT_MATRIX. The update is done by exchanging glyph pointers
2897 between rows in CURRENT_MATRIX and DESIRED_MATRIX. If
2898 frame_matrix_frame is non-null, this indicates that the exchange is
2899 done in frame matrices, and that we have to perform analogous
2900 operations in window matrices of frame_matrix_frame. */
2903 make_current (desired_matrix
, current_matrix
, row
)
2904 struct glyph_matrix
*desired_matrix
, *current_matrix
;
2907 struct glyph_row
*current_row
= MATRIX_ROW (current_matrix
, row
);
2908 struct glyph_row
*desired_row
= MATRIX_ROW (desired_matrix
, row
);
2909 int mouse_face_p
= current_row
->mouse_face_p
;
2911 /* Do current_row = desired_row. This exchanges glyph pointers
2912 between both rows, and does a structure assignment otherwise. */
2913 assign_row (current_row
, desired_row
);
2915 /* Enable current_row to mark it as valid. */
2916 current_row
->enabled_p
= 1;
2917 current_row
->mouse_face_p
= mouse_face_p
;
2919 /* If we are called on frame matrices, perform analogous operations
2920 for window matrices. */
2921 if (frame_matrix_frame
)
2922 mirror_make_current (XWINDOW (frame_matrix_frame
->root_window
), row
);
2926 /* W is the root of a window tree. FRAME_ROW is the index of a row in
2927 W's frame which has been made current (by swapping pointers between
2928 current and desired matrix). Perform analogous operations in the
2929 matrices of leaf windows in the window tree rooted at W. */
2932 mirror_make_current (w
, frame_row
)
2938 if (!NILP (w
->hchild
))
2939 mirror_make_current (XWINDOW (w
->hchild
), frame_row
);
2940 else if (!NILP (w
->vchild
))
2941 mirror_make_current (XWINDOW (w
->vchild
), frame_row
);
2944 /* Row relative to window W. Don't use FRAME_TO_WINDOW_VPOS
2945 here because the checks performed in debug mode there
2946 will not allow the conversion. */
2947 int row
= frame_row
- w
->desired_matrix
->matrix_y
;
2949 /* If FRAME_ROW is within W, assign the desired row to the
2950 current row (exchanging glyph pointers). */
2951 if (row
>= 0 && row
< w
->desired_matrix
->matrix_h
)
2953 struct glyph_row
*current_row
2954 = MATRIX_ROW (w
->current_matrix
, row
);
2955 struct glyph_row
*desired_row
2956 = MATRIX_ROW (w
->desired_matrix
, row
);
2958 if (desired_row
->enabled_p
)
2959 assign_row (current_row
, desired_row
);
2961 swap_glyph_pointers (desired_row
, current_row
);
2962 current_row
->enabled_p
= 1;
2966 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2971 /* Perform row dance after scrolling. We are working on the range of
2972 lines UNCHANGED_AT_TOP + 1 to UNCHANGED_AT_TOP + NLINES (not
2973 including) in MATRIX. COPY_FROM is a vector containing, for each
2974 row I in the range 0 <= I < NLINES, the index of the original line
2975 to move to I. This index is relative to the row range, i.e. 0 <=
2976 index < NLINES. RETAINED_P is a vector containing zero for each
2977 row 0 <= I < NLINES which is empty.
2979 This function is called from do_scrolling and do_direct_scrolling. */
2982 mirrored_line_dance (matrix
, unchanged_at_top
, nlines
, copy_from
,
2984 struct glyph_matrix
*matrix
;
2985 int unchanged_at_top
, nlines
;
2989 /* A copy of original rows. */
2990 struct glyph_row
*old_rows
;
2992 /* Rows to assign to. */
2993 struct glyph_row
*new_rows
= MATRIX_ROW (matrix
, unchanged_at_top
);
2997 /* Make a copy of the original rows. */
2998 old_rows
= (struct glyph_row
*) alloca (nlines
* sizeof *old_rows
);
2999 bcopy (new_rows
, old_rows
, nlines
* sizeof *old_rows
);
3001 /* Assign new rows, maybe clear lines. */
3002 for (i
= 0; i
< nlines
; ++i
)
3004 int enabled_before_p
= new_rows
[i
].enabled_p
;
3006 xassert (i
+ unchanged_at_top
< matrix
->nrows
);
3007 xassert (unchanged_at_top
+ copy_from
[i
] < matrix
->nrows
);
3008 new_rows
[i
] = old_rows
[copy_from
[i
]];
3009 new_rows
[i
].enabled_p
= enabled_before_p
;
3011 /* RETAINED_P is zero for empty lines. */
3012 if (!retained_p
[copy_from
[i
]])
3013 new_rows
[i
].enabled_p
= 0;
3016 /* Do the same for window matrices, if MATRIX Is a frame matrix. */
3017 if (frame_matrix_frame
)
3018 mirror_line_dance (XWINDOW (frame_matrix_frame
->root_window
),
3019 unchanged_at_top
, nlines
, copy_from
, retained_p
);
3023 /* Synchronize glyph pointers in the current matrix of window W with
3024 the current frame matrix. W must be full-width, and be on a tty
3028 sync_window_with_frame_matrix_rows (w
)
3031 struct frame
*f
= XFRAME (w
->frame
);
3032 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
3034 /* Preconditions: W must be a leaf window and full-width. Its frame
3035 must have a frame matrix. */
3036 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
3037 xassert (WINDOW_FULL_WIDTH_P (w
));
3038 xassert (!FRAME_WINDOW_P (f
));
3040 /* If W is a full-width window, glyph pointers in W's current matrix
3041 have, by definition, to be the same as glyph pointers in the
3042 corresponding frame matrix. */
3043 window_row
= w
->current_matrix
->rows
;
3044 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
3045 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
3046 while (window_row
< window_row_end
)
3050 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
3051 window_row
->glyphs
[area
] = frame_row
->glyphs
[area
];
3053 ++window_row
, ++frame_row
;
3058 /* Return the window in the window tree rooted in W containing frame
3059 row ROW. Value is null if none is found. */
3062 frame_row_to_window (w
, row
)
3066 struct window
*found
= NULL
;
3070 if (!NILP (w
->hchild
))
3071 found
= frame_row_to_window (XWINDOW (w
->hchild
), row
);
3072 else if (!NILP (w
->vchild
))
3073 found
= frame_row_to_window (XWINDOW (w
->vchild
), row
);
3074 else if (row
>= XFASTINT (w
->top
)
3075 && row
< XFASTINT (w
->top
) + XFASTINT (w
->height
))
3078 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3085 /* Perform a line dance in the window tree rooted at W, after
3086 scrolling a frame matrix in mirrored_line_dance.
3088 We are working on the range of lines UNCHANGED_AT_TOP + 1 to
3089 UNCHANGED_AT_TOP + NLINES (not including) in W's frame matrix.
3090 COPY_FROM is a vector containing, for each row I in the range 0 <=
3091 I < NLINES, the index of the original line to move to I. This
3092 index is relative to the row range, i.e. 0 <= index < NLINES.
3093 RETAINED_P is a vector containing zero for each row 0 <= I < NLINES
3097 mirror_line_dance (w
, unchanged_at_top
, nlines
, copy_from
, retained_p
)
3099 int unchanged_at_top
, nlines
;
3105 if (!NILP (w
->hchild
))
3106 mirror_line_dance (XWINDOW (w
->hchild
), unchanged_at_top
,
3107 nlines
, copy_from
, retained_p
);
3108 else if (!NILP (w
->vchild
))
3109 mirror_line_dance (XWINDOW (w
->vchild
), unchanged_at_top
,
3110 nlines
, copy_from
, retained_p
);
3113 /* W is a leaf window, and we are working on its current
3115 struct glyph_matrix
*m
= w
->current_matrix
;
3117 struct glyph_row
*old_rows
;
3119 /* Make a copy of the original rows of matrix m. */
3120 old_rows
= (struct glyph_row
*) alloca (m
->nrows
* sizeof *old_rows
);
3121 bcopy (m
->rows
, old_rows
, m
->nrows
* sizeof *old_rows
);
3123 for (i
= 0; i
< nlines
; ++i
)
3125 /* Frame relative line assigned to. */
3126 int frame_to
= i
+ unchanged_at_top
;
3128 /* Frame relative line assigned. */
3129 int frame_from
= copy_from
[i
] + unchanged_at_top
;
3131 /* Window relative line assigned to. */
3132 int window_to
= frame_to
- m
->matrix_y
;
3134 /* Window relative line assigned. */
3135 int window_from
= frame_from
- m
->matrix_y
;
3137 /* Is assigned line inside window? */
3138 int from_inside_window_p
3139 = window_from
>= 0 && window_from
< m
->matrix_h
;
3141 /* Is assigned to line inside window? */
3142 int to_inside_window_p
3143 = window_to
>= 0 && window_to
< m
->matrix_h
;
3145 if (from_inside_window_p
&& to_inside_window_p
)
3147 /* Enabled setting before assignment. */
3148 int enabled_before_p
;
3150 /* Do the assignment. The enabled_p flag is saved
3151 over the assignment because the old redisplay did
3153 enabled_before_p
= m
->rows
[window_to
].enabled_p
;
3154 m
->rows
[window_to
] = old_rows
[window_from
];
3155 m
->rows
[window_to
].enabled_p
= enabled_before_p
;
3157 /* If frame line is empty, window line is empty, too. */
3158 if (!retained_p
[copy_from
[i
]])
3159 m
->rows
[window_to
].enabled_p
= 0;
3161 else if (to_inside_window_p
)
3163 /* A copy between windows. This is an infrequent
3164 case not worth optimizing. */
3165 struct frame
*f
= XFRAME (w
->frame
);
3166 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3168 struct glyph_matrix
*m2
;
3171 w2
= frame_row_to_window (root
, frame_to
);
3172 m2
= w2
->current_matrix
;
3173 m2_from
= frame_from
- m2
->matrix_y
;
3174 copy_row_except_pointers (m
->rows
+ window_to
,
3175 m2
->rows
+ m2_from
);
3177 /* If frame line is empty, window line is empty, too. */
3178 if (!retained_p
[copy_from
[i
]])
3179 m
->rows
[window_to
].enabled_p
= 0;
3182 else if (from_inside_window_p
)
3186 /* If there was a copy between windows, make sure glyph
3187 pointers are in sync with the frame matrix. */
3189 sync_window_with_frame_matrix_rows (w
);
3191 /* Check that no pointers are lost. */
3195 /* Next window on same level. */
3196 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3203 /* Check that window and frame matrices agree about their
3204 understanding where glyphs of the rows are to find. For each
3205 window in the window tree rooted at W, check that rows in the
3206 matrices of leaf window agree with their frame matrices about
3210 check_window_matrix_pointers (w
)
3215 if (!NILP (w
->hchild
))
3216 check_window_matrix_pointers (XWINDOW (w
->hchild
));
3217 else if (!NILP (w
->vchild
))
3218 check_window_matrix_pointers (XWINDOW (w
->vchild
));
3221 struct frame
*f
= XFRAME (w
->frame
);
3222 check_matrix_pointers (w
->desired_matrix
, f
->desired_matrix
);
3223 check_matrix_pointers (w
->current_matrix
, f
->current_matrix
);
3226 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3231 /* Check that window rows are slices of frame rows. WINDOW_MATRIX is
3232 a window and FRAME_MATRIX is the corresponding frame matrix. For
3233 each row in WINDOW_MATRIX check that it's a slice of the
3234 corresponding frame row. If it isn't, abort. */
3237 check_matrix_pointers (window_matrix
, frame_matrix
)
3238 struct glyph_matrix
*window_matrix
, *frame_matrix
;
3240 /* Row number in WINDOW_MATRIX. */
3243 /* Row number corresponding to I in FRAME_MATRIX. */
3244 int j
= window_matrix
->matrix_y
;
3246 /* For all rows check that the row in the window matrix is a
3247 slice of the row in the frame matrix. If it isn't we didn't
3248 mirror an operation on the frame matrix correctly. */
3249 while (i
< window_matrix
->nrows
)
3251 if (!glyph_row_slice_p (window_matrix
->rows
+ i
,
3252 frame_matrix
->rows
+ j
))
3258 #endif /* GLYPH_DEBUG != 0 */
3262 /**********************************************************************
3263 VPOS and HPOS translations
3264 **********************************************************************/
3268 /* Translate vertical position VPOS which is relative to window W to a
3269 vertical position relative to W's frame. */
3272 window_to_frame_vpos (w
, vpos
)
3276 struct frame
*f
= XFRAME (w
->frame
);
3278 xassert (!FRAME_WINDOW_P (f
));
3279 xassert (vpos
>= 0 && vpos
<= w
->desired_matrix
->nrows
);
3280 vpos
+= XFASTINT (w
->top
);
3281 xassert (vpos
>= 0 && vpos
<= FRAME_HEIGHT (f
));
3286 /* Translate horizontal position HPOS which is relative to window W to
3287 a vertical position relative to W's frame. */
3290 window_to_frame_hpos (w
, hpos
)
3294 struct frame
*f
= XFRAME (w
->frame
);
3296 xassert (!FRAME_WINDOW_P (f
));
3297 hpos
+= XFASTINT (w
->left
);
3301 #endif /* GLYPH_DEBUG */
3305 /**********************************************************************
3307 **********************************************************************/
3309 DEFUN ("redraw-frame", Fredraw_frame
, Sredraw_frame
, 1, 1, 0,
3310 /* Clear frame FRAME and output again what is supposed to appear on it. */
3316 CHECK_LIVE_FRAME (frame
, 0);
3319 /* Ignore redraw requests, if frame has no glyphs yet.
3320 (Implementation note: It still has to be checked why we are
3321 called so early here). */
3322 if (!glyphs_initialized_initially_p
)
3326 if (FRAME_MSDOS_P (f
))
3327 set_terminal_modes ();
3329 clear_current_matrices (f
);
3332 windows_or_buffers_changed
++;
3333 /* Mark all windows as inaccurate, so that every window will have
3334 its redisplay done. */
3335 mark_window_display_accurate (FRAME_ROOT_WINDOW (f
), 0);
3336 set_window_update_flags (XWINDOW (FRAME_ROOT_WINDOW (f
)), 1);
3342 /* Redraw frame F. This is nothing more than a call to the Lisp
3343 function redraw-frame. */
3350 XSETFRAME (frame
, f
);
3351 Fredraw_frame (frame
);
3355 DEFUN ("redraw-display", Fredraw_display
, Sredraw_display
, 0, 0, "",
3356 /* Clear and redisplay all visible frames. */
3359 Lisp_Object tail
, frame
;
3361 FOR_EACH_FRAME (tail
, frame
)
3362 if (FRAME_VISIBLE_P (XFRAME (frame
)))
3363 Fredraw_frame (frame
);
3369 /* This is used when frame_garbaged is set. Call Fredraw_frame on all
3370 visible frames marked as garbaged. */
3373 redraw_garbaged_frames ()
3375 Lisp_Object tail
, frame
;
3377 FOR_EACH_FRAME (tail
, frame
)
3378 if (FRAME_VISIBLE_P (XFRAME (frame
))
3379 && FRAME_GARBAGED_P (XFRAME (frame
)))
3380 Fredraw_frame (frame
);
3385 /***********************************************************************
3387 ***********************************************************************/
3389 /* Try to update display and current glyph matrix directly.
3391 This function is called after a character G has been inserted into
3392 current_buffer. It tries to update the current glyph matrix and
3393 perform appropriate screen output to reflect the insertion. If it
3394 succeeds, the global flag redisplay_performed_directly_p will be
3395 set to 1, and thereby prevent the more costly general redisplay
3396 from running (see redisplay_internal).
3398 This function is not called for `hairy' character insertions.
3399 In particular, it is not called when after or before change
3400 functions exist, like they are used by font-lock. See keyboard.c
3401 for details where this function is called. */
3404 direct_output_for_insert (g
)
3407 register struct frame
*f
= SELECTED_FRAME ();
3408 struct window
*w
= XWINDOW (selected_window
);
3410 struct glyph_row
*glyph_row
;
3411 struct glyph
*glyphs
, *glyph
, *end
;
3413 /* Non-null means that Redisplay of W is based on window matrices. */
3414 int window_redisplay_p
= FRAME_WINDOW_P (f
);
3415 /* Non-null means we are in overwrite mode. */
3416 int overwrite_p
= !NILP (current_buffer
->overwrite_mode
);
3418 struct text_pos pos
;
3419 int delta
, delta_bytes
;
3421 /* Not done directly. */
3422 redisplay_performed_directly_p
= 0;
3424 /* Quickly give up for some common cases. */
3425 if (cursor_in_echo_area
3426 /* Give up if fonts have changed. */
3428 /* Give up if face attributes have been changed. */
3429 || face_change_count
3430 /* Give up if cursor position not really known. */
3431 || !display_completed
3432 /* Give up if buffer appears in two places. */
3433 || buffer_shared
> 1
3434 /* Give up if currently displaying a message instead of the
3435 minibuffer contents. */
3436 || (EQ (selected_window
, minibuf_window
)
3437 && EQ (minibuf_window
, echo_area_window
))
3438 /* Give up for hscrolled mini-buffer because display of the prompt
3439 is handled specially there (see display_line). */
3440 || (MINI_WINDOW_P (w
) && XFASTINT (w
->hscroll
))
3441 /* Give up if overwriting in the middle of a line. */
3444 && FETCH_BYTE (PT
) != '\n')
3445 /* Give up for tabs and line ends. */
3449 /* Give up if unable to display the cursor in the window. */
3450 || w
->cursor
.vpos
< 0
3451 /* Give up if we are showing a message or just cleared the message
3452 because we might need to resize the echo area window. */
3453 || !NILP (echo_area_buffer
[0])
3454 || !NILP (echo_area_buffer
[1])
3455 || (glyph_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
),
3456 /* Can't do it in a continued line because continuation
3457 lines would change. */
3458 (glyph_row
->continued_p
3459 /* Can't use this method if the line overlaps others or is
3460 overlapped by others because these other lines would
3461 have to be redisplayed. */
3462 || glyph_row
->overlapping_p
3463 || glyph_row
->overlapped_p
))
3464 /* Can't do it for partial width windows on terminal frames
3465 because we can't clear to eol in such a window. */
3466 || (!window_redisplay_p
&& !WINDOW_FULL_WIDTH_P (w
)))
3469 /* If we can't insert glyphs, we can use this method only
3470 at the end of a line. */
3471 if (!char_ins_del_ok
)
3472 if (PT
!= ZV
&& FETCH_BYTE (PT_BYTE
) != '\n')
3475 /* Set up a display iterator structure for W. Glyphs will be
3476 produced in scratch_glyph_row. Current position is W's cursor
3478 clear_glyph_row (&scratch_glyph_row
);
3479 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
3480 DEC_TEXT_POS (pos
, !NILP (current_buffer
->enable_multibyte_characters
));
3481 init_iterator (&it
, w
, CHARPOS (pos
), BYTEPOS (pos
), &scratch_glyph_row
,
3484 glyph_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
3485 if (glyph_row
->mouse_face_p
)
3488 /* Give up if highlighting trailing whitespace and we have trailing
3489 whitespace in glyph_row. We would have to remove the trailing
3490 whitespace face in that case. */
3491 if (!NILP (Vshow_trailing_whitespace
)
3492 && glyph_row
->used
[TEXT_AREA
])
3496 last
= glyph_row
->glyphs
[TEXT_AREA
] + glyph_row
->used
[TEXT_AREA
] - 1;
3497 if (last
->type
== STRETCH_GLYPH
3498 || (last
->type
== CHAR_GLYPH
3499 && last
->u
.ch
== ' '))
3503 /* Give up if there are overlay strings at pos. This would fail
3504 if the overlay string has newlines in it. */
3505 if (STRINGP (it
.string
))
3508 it
.hpos
= w
->cursor
.hpos
;
3509 it
.vpos
= w
->cursor
.vpos
;
3510 it
.current_x
= w
->cursor
.x
+ it
.first_visible_x
;
3511 it
.current_y
= w
->cursor
.y
;
3512 it
.end_charpos
= PT
;
3513 it
.stop_charpos
= min (PT
, it
.stop_charpos
);
3514 it
.stop_charpos
= max (IT_CHARPOS (it
), it
.stop_charpos
);
3516 /* More than one display element may be returned for PT - 1 if
3517 (i) it's a control character which is translated into `\003' or
3518 `^C', or (ii) it has a display table entry, or (iii) it's a
3519 combination of both. */
3520 delta
= delta_bytes
= 0;
3521 while (get_next_display_element (&it
))
3523 PRODUCE_GLYPHS (&it
);
3525 /* Give up if glyph doesn't fit completely on the line. */
3526 if (it
.current_x
>= it
.last_visible_x
)
3529 /* Give up if new glyph has different ascent or descent than
3530 the original row, or if it is not a character glyph. */
3531 if (glyph_row
->ascent
!= it
.ascent
3532 || glyph_row
->height
!= it
.ascent
+ it
.descent
3533 || glyph_row
->phys_ascent
!= it
.phys_ascent
3534 || glyph_row
->phys_height
!= it
.phys_ascent
+ it
.phys_descent
3535 || it
.what
!= IT_CHARACTER
)
3539 delta_bytes
+= it
.len
;
3540 set_iterator_to_next (&it
, 1);
3543 /* Give up if we hit the right edge of the window. We would have
3544 to insert truncation or continuation glyphs. */
3545 added_width
= it
.current_x
- (w
->cursor
.x
+ it
.first_visible_x
);
3546 if (glyph_row
->pixel_width
+ added_width
>= it
.last_visible_x
)
3549 /* Give up if there is a \t following in the line. */
3551 it2
.end_charpos
= ZV
;
3552 it2
.stop_charpos
= min (it2
.stop_charpos
, ZV
);
3553 while (get_next_display_element (&it2
)
3554 && !ITERATOR_AT_END_OF_LINE_P (&it2
))
3558 set_iterator_to_next (&it2
, 1);
3561 /* Number of new glyphs produced. */
3562 n
= it
.glyph_row
->used
[TEXT_AREA
];
3564 /* Start and end of glyphs in original row. */
3565 glyphs
= glyph_row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
3566 end
= glyph_row
->glyphs
[1 + TEXT_AREA
];
3568 /* Make room for new glyphs, then insert them. */
3569 xassert (end
- glyphs
- n
>= 0);
3570 safe_bcopy ((char *) glyphs
, (char *) (glyphs
+ n
),
3571 (end
- glyphs
- n
) * sizeof (*end
));
3572 bcopy (it
.glyph_row
->glyphs
[TEXT_AREA
], glyphs
, n
* sizeof *glyphs
);
3573 glyph_row
->used
[TEXT_AREA
] = min (glyph_row
->used
[TEXT_AREA
] + n
,
3574 end
- glyph_row
->glyphs
[TEXT_AREA
]);
3576 /* Compute new line width. */
3577 glyph
= glyph_row
->glyphs
[TEXT_AREA
];
3578 end
= glyph
+ glyph_row
->used
[TEXT_AREA
];
3579 glyph_row
->pixel_width
= glyph_row
->x
;
3582 glyph_row
->pixel_width
+= glyph
->pixel_width
;
3586 /* Increment buffer positions for glyphs following the newly
3588 for (glyph
= glyphs
+ n
; glyph
< end
; ++glyph
)
3589 if (glyph
->charpos
> 0 && BUFFERP (glyph
->object
))
3590 glyph
->charpos
+= delta
;
3592 if (MATRIX_ROW_END_CHARPOS (glyph_row
) > 0)
3594 MATRIX_ROW_END_CHARPOS (glyph_row
) += delta
;
3595 MATRIX_ROW_END_BYTEPOS (glyph_row
) += delta_bytes
;
3598 /* Adjust positions in lines following the one we are in. */
3599 increment_matrix_positions (w
->current_matrix
,
3601 w
->current_matrix
->nrows
,
3602 delta
, delta_bytes
);
3604 glyph_row
->contains_overlapping_glyphs_p
3605 |= it
.glyph_row
->contains_overlapping_glyphs_p
;
3607 glyph_row
->displays_text_p
= 1;
3608 w
->window_end_vpos
= make_number (max (w
->cursor
.vpos
,
3609 XFASTINT (w
->window_end_vpos
)));
3611 if (!NILP (Vshow_trailing_whitespace
))
3612 highlight_trailing_whitespace (it
.f
, glyph_row
);
3614 /* Write glyphs. If at end of row, we can simply call write_glyphs.
3615 In the middle, we have to insert glyphs. Note that this is now
3616 implemented for X frames. The implementation uses updated_window
3618 updated_row
= glyph_row
;
3619 updated_area
= TEXT_AREA
;
3623 rif
->update_window_begin_hook (w
);
3625 if (glyphs
== end
- n
3626 /* In front of a space added by append_space. */
3627 || (glyphs
== end
- n
- 1
3628 && (end
- n
)->charpos
<= 0))
3629 rif
->write_glyphs (glyphs
, n
);
3631 rif
->insert_glyphs (glyphs
, n
);
3635 if (glyphs
== end
- n
)
3636 write_glyphs (glyphs
, n
);
3638 insert_glyphs (glyphs
, n
);
3641 w
->cursor
.hpos
+= n
;
3642 w
->cursor
.x
= it
.current_x
- it
.first_visible_x
;
3643 xassert (w
->cursor
.hpos
>= 0
3644 && w
->cursor
.hpos
< w
->desired_matrix
->matrix_w
);
3646 /* How to set the cursor differs depending on whether we are
3647 using a frame matrix or a window matrix. Note that when
3648 a frame matrix is used, cursor_to expects frame coordinates,
3649 and the X and Y parameters are not used. */
3650 if (window_redisplay_p
)
3651 rif
->cursor_to (w
->cursor
.vpos
, w
->cursor
.hpos
,
3652 w
->cursor
.y
, w
->cursor
.x
);
3656 x
= (WINDOW_TO_FRAME_HPOS (w
, w
->cursor
.hpos
)
3657 + (INTEGERP (w
->left_margin_width
)
3658 ? XFASTINT (w
->left_margin_width
)
3660 y
= WINDOW_TO_FRAME_VPOS (w
, w
->cursor
.vpos
);
3665 rif
->update_window_end_hook (w
, 1, 0);
3670 TRACE ((stderr
, "direct output for insert\n"));
3672 UNCHANGED_MODIFIED
= MODIFF
;
3673 BEG_UNCHANGED
= GPT
- BEG
;
3674 XSETFASTINT (w
->last_point
, PT
);
3675 w
->last_cursor
= w
->cursor
;
3676 XSETFASTINT (w
->last_modified
, MODIFF
);
3677 XSETFASTINT (w
->last_overlay_modified
, OVERLAY_MODIFF
);
3679 redisplay_performed_directly_p
= 1;
3684 /* Perform a direct display update for moving PT by N positions
3685 left or right. N < 0 means a movement backwards. This function
3686 is currently only called for N == 1 or N == -1. */
3689 direct_output_forward_char (n
)
3692 struct frame
*f
= SELECTED_FRAME ();
3693 struct window
*w
= XWINDOW (selected_window
);
3694 struct glyph_row
*row
;
3696 /* Give up if point moved out of or into a composition. */
3697 if (check_point_in_composition (current_buffer
, XINT (w
->last_point
),
3698 current_buffer
, PT
))
3701 /* Give up if face attributes have been changed. */
3702 if (face_change_count
)
3705 /* Give up if current matrix is not up to date or we are
3706 displaying a message. */
3707 if (!display_completed
|| cursor_in_echo_area
)
3710 /* Give up if the buffer's direction is reversed. */
3711 if (!NILP (XBUFFER (w
->buffer
)->direction_reversed
))
3714 /* Can't use direct output if highlighting a region. */
3715 if (!NILP (Vtransient_mark_mode
) && !NILP (current_buffer
->mark_active
))
3718 /* Can't use direct output if highlighting trailing whitespace. */
3719 if (!NILP (Vshow_trailing_whitespace
))
3722 /* Give up if we are showing a message or just cleared the message
3723 because we might need to resize the echo area window. */
3724 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
3727 /* Give up if currently displaying a message instead of the
3728 minibuffer contents. */
3729 if (XWINDOW (minibuf_window
) == w
3730 && EQ (minibuf_window
, echo_area_window
))
3733 /* Give up if we don't know where the cursor is. */
3734 if (w
->cursor
.vpos
< 0)
3737 row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
3739 /* Give up if PT is outside of the last known cursor row. */
3740 if (PT
<= MATRIX_ROW_START_BYTEPOS (row
)
3741 || PT
>= MATRIX_ROW_END_BYTEPOS (row
))
3744 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
3746 w
->last_cursor
= w
->cursor
;
3747 XSETFASTINT (w
->last_point
, PT
);
3749 xassert (w
->cursor
.hpos
>= 0
3750 && w
->cursor
.hpos
< w
->desired_matrix
->matrix_w
);
3752 if (FRAME_WINDOW_P (f
))
3753 rif
->cursor_to (w
->cursor
.vpos
, w
->cursor
.hpos
,
3754 w
->cursor
.y
, w
->cursor
.x
);
3758 x
= (WINDOW_TO_FRAME_HPOS (w
, w
->cursor
.hpos
)
3759 + (INTEGERP (w
->left_margin_width
)
3760 ? XFASTINT (w
->left_margin_width
)
3762 y
= WINDOW_TO_FRAME_VPOS (w
, w
->cursor
.vpos
);
3767 redisplay_performed_directly_p
= 1;
3773 /***********************************************************************
3775 ***********************************************************************/
3777 /* Update frame F based on the data in desired matrices.
3779 If FORCE_P is non-zero, don't let redisplay be stopped by detecting
3780 pending input. If INHIBIT_HAIRY_ID_P is non-zero, don't try
3783 Value is non-zero if redisplay was stopped due to pending input. */
3786 update_frame (f
, force_p
, inhibit_hairy_id_p
)
3789 int inhibit_hairy_id_p
;
3791 /* 1 means display has been paused because of pending input. */
3793 struct window
*root_window
= XWINDOW (f
->root_window
);
3795 if (FRAME_WINDOW_P (f
))
3797 /* We are working on window matrix basis. All windows whose
3798 flag must_be_updated_p is set have to be updated. */
3800 /* Record that we are not working on frame matrices. */
3801 set_frame_matrix_frame (NULL
);
3803 /* Update all windows in the window tree of F, maybe stopping
3804 when pending input is detected. */
3807 /* Update the menu bar on X frames that don't have toolkit
3809 if (WINDOWP (f
->menu_bar_window
))
3810 update_window (XWINDOW (f
->menu_bar_window
), 1);
3812 /* Update the tool-bar window, if present. */
3813 if (WINDOWP (f
->tool_bar_window
))
3816 struct window
*w
= XWINDOW (f
->tool_bar_window
);
3818 /* Update tool-bar window. */
3819 if (w
->must_be_updated_p
)
3821 update_window (w
, 1);
3822 w
->must_be_updated_p
= 0;
3824 /* Swap tool-bar strings. We swap because we want to
3826 tem
= f
->current_tool_bar_string
;
3827 f
->current_tool_bar_string
= f
->desired_tool_bar_string
;
3828 f
->desired_tool_bar_string
= tem
;
3833 /* Update windows. */
3834 paused_p
= update_window_tree (root_window
, force_p
);
3837 #if 0 /* This flush is a performance bottleneck under X,
3838 and it doesn't seem to be necessary anyway. */
3839 rif
->flush_display (f
);
3844 /* We are working on frame matrix basis. Set the frame on whose
3845 frame matrix we operate. */
3846 set_frame_matrix_frame (f
);
3848 /* Build F's desired matrix from window matrices. */
3849 build_frame_matrix (f
);
3851 /* Update the display */
3853 paused_p
= update_frame_1 (f
, force_p
, inhibit_hairy_id_p
);
3857 fflush (termscript
);
3860 /* Check window matrices for lost pointers. */
3862 check_window_matrix_pointers (root_window
);
3863 add_frame_display_history (f
, paused_p
);
3867 /* Reset flags indicating that a window should be updated. */
3868 set_window_update_flags (root_window
, 0);
3870 display_completed
= !paused_p
;
3876 /************************************************************************
3877 Window-based updates
3878 ************************************************************************/
3880 /* Perform updates in window tree rooted at W. FORCE_P non-zero means
3881 don't stop updating when input is pending. */
3884 update_window_tree (w
, force_p
)
3890 while (w
&& !paused_p
)
3892 if (!NILP (w
->hchild
))
3893 paused_p
|= update_window_tree (XWINDOW (w
->hchild
), force_p
);
3894 else if (!NILP (w
->vchild
))
3895 paused_p
|= update_window_tree (XWINDOW (w
->vchild
), force_p
);
3896 else if (w
->must_be_updated_p
)
3897 paused_p
|= update_window (w
, force_p
);
3899 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3906 /* Update window W if its flag must_be_updated_p is non-zero. If
3907 FORCE_P is non-zero, don't stop updating if input is pending. */
3910 update_single_window (w
, force_p
)
3914 if (w
->must_be_updated_p
)
3916 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3918 /* Record that this is not a frame-based redisplay. */
3919 set_frame_matrix_frame (NULL
);
3923 update_window (w
, force_p
);
3926 /* Reset flag in W. */
3927 w
->must_be_updated_p
= 0;
3932 /* Redraw lines from the current matrix of window W that are
3933 overlapped by other rows. YB is bottom-most y-position in W. */
3936 redraw_overlapped_rows (w
, yb
)
3942 /* If rows overlapping others have been changed, the rows being
3943 overlapped have to be redrawn. This won't draw lines that have
3944 already been drawn in update_window_line because overlapped_p in
3945 desired rows is 0, so after row assignment overlapped_p in
3946 current rows is 0. */
3947 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
3949 struct glyph_row
*row
= w
->current_matrix
->rows
+ i
;
3951 if (!row
->enabled_p
)
3953 else if (row
->mode_line_p
)
3956 if (row
->overlapped_p
)
3958 enum glyph_row_area area
;
3960 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
3963 updated_area
= area
;
3964 rif
->cursor_to (i
, 0, row
->y
, area
== TEXT_AREA
? row
->x
: 0);
3965 if (row
->used
[area
])
3966 rif
->write_glyphs (row
->glyphs
[area
], row
->used
[area
]);
3967 rif
->clear_end_of_line (-1);
3970 row
->overlapped_p
= 0;
3973 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
3979 /* Redraw lines from the current matrix of window W that overlap
3980 others. YB is bottom-most y-position in W. */
3983 redraw_overlapping_rows (w
, yb
)
3988 struct glyph_row
*row
;
3990 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
3992 row
= w
->current_matrix
->rows
+ i
;
3994 if (!row
->enabled_p
)
3996 else if (row
->mode_line_p
)
3999 bottom_y
= MATRIX_ROW_BOTTOM_Y (row
);
4001 if (row
->overlapping_p
&& i
> 0 && bottom_y
< yb
)
4003 if (row
->used
[LEFT_MARGIN_AREA
])
4004 rif
->fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
4006 if (row
->used
[TEXT_AREA
])
4007 rif
->fix_overlapping_area (w
, row
, TEXT_AREA
);
4009 if (row
->used
[RIGHT_MARGIN_AREA
])
4010 rif
->fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
4012 /* Record in neighbor rows that ROW overwrites part of their
4014 if (row
->phys_ascent
> row
->ascent
&& i
> 0)
4015 MATRIX_ROW (w
->current_matrix
, i
- 1)->overlapped_p
= 1;
4016 if ((row
->phys_height
- row
->phys_ascent
4017 > row
->height
- row
->ascent
)
4019 MATRIX_ROW (w
->current_matrix
, i
+ 1)->overlapped_p
= 1;
4030 /* Check that no row in the current matrix of window W is enabled
4031 which is below what's displayed in the window. */
4034 check_current_matrix_flags (w
)
4037 int last_seen_p
= 0;
4038 int i
, yb
= window_text_bottom_y (w
);
4040 for (i
= 0; i
< w
->current_matrix
->nrows
- 1; ++i
)
4042 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
4043 if (!last_seen_p
&& MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
4045 else if (last_seen_p
&& row
->enabled_p
)
4050 #endif /* GLYPH_DEBUG */
4053 /* Update display of window W. FORCE_P non-zero means that we should
4054 not stop when detecting pending input. */
4057 update_window (w
, force_p
)
4061 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
4063 int preempt_count
= baud_rate
/ 2400 + 1;
4064 extern int input_pending
;
4065 extern Lisp_Object do_mouse_tracking
;
4067 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4068 extern struct frame
*updating_frame
;
4071 /* Check that W's frame doesn't have glyph matrices. */
4072 xassert (FRAME_WINDOW_P (f
));
4073 xassert (updating_frame
!= NULL
);
4075 /* Check pending input the first time so that we can quickly return. */
4076 if (redisplay_dont_pause
)
4079 detect_input_pending ();
4081 /* If forced to complete the update, or if no input is pending, do
4083 if (force_p
|| !input_pending
|| !NILP (do_mouse_tracking
))
4085 struct glyph_row
*row
, *end
;
4086 struct glyph_row
*mode_line_row
;
4087 struct glyph_row
*header_line_row
;
4088 int yb
, changed_p
= 0, mouse_face_overwritten_p
= 0, n_updated
;
4090 rif
->update_window_begin_hook (w
);
4091 yb
= window_text_bottom_y (w
);
4093 /* If window has a top line, update it before everything else.
4094 Adjust y-positions of other rows by the top line height. */
4095 row
= desired_matrix
->rows
;
4096 end
= row
+ desired_matrix
->nrows
- 1;
4098 if (row
->mode_line_p
)
4100 header_line_row
= row
;
4104 header_line_row
= NULL
;
4106 /* Update the mode line, if necessary. */
4107 mode_line_row
= MATRIX_MODE_LINE_ROW (desired_matrix
);
4108 if (mode_line_row
->mode_line_p
&& mode_line_row
->enabled_p
)
4110 mode_line_row
->y
= yb
;
4111 update_window_line (w
, MATRIX_ROW_VPOS (mode_line_row
,
4113 &mouse_face_overwritten_p
);
4117 /* Find first enabled row. Optimizations in redisplay_internal
4118 may lead to an update with only one row enabled. There may
4119 be also completely empty matrices. */
4120 while (row
< end
&& !row
->enabled_p
)
4123 /* Try reusing part of the display by copying. */
4124 if (row
< end
&& !desired_matrix
->no_scrolling_p
)
4126 int rc
= scrolling_window (w
, header_line_row
!= NULL
);
4129 /* All rows were found to be equal. */
4134 /* We've scrolled the display. */
4139 /* Update the top mode line after scrolling because a new top
4140 line would otherwise overwrite lines at the top of the window
4141 that can be scrolled. */
4142 if (header_line_row
&& header_line_row
->enabled_p
)
4144 header_line_row
->y
= 0;
4145 update_window_line (w
, 0, &mouse_face_overwritten_p
);
4149 /* Update the rest of the lines. */
4150 for (n_updated
= 0; row
< end
&& (force_p
|| !input_pending
); ++row
)
4153 int vpos
= MATRIX_ROW_VPOS (row
, desired_matrix
);
4156 /* We'll Have to play a little bit with when to
4157 detect_input_pending. If it's done too often,
4158 scrolling large windows with repeated scroll-up
4159 commands will too quickly pause redisplay. */
4160 if (!force_p
&& ++n_updated
% preempt_count
== 0)
4161 detect_input_pending ();
4163 changed_p
|= update_window_line (w
, vpos
,
4164 &mouse_face_overwritten_p
);
4166 /* Mark all rows below the last visible one in the current
4167 matrix as invalid. This is necessary because of
4168 variable line heights. Consider the case of three
4169 successive redisplays, where the first displays 5
4170 lines, the second 3 lines, and the third 5 lines again.
4171 If the second redisplay wouldn't mark rows in the
4172 current matrix invalid, the third redisplay might be
4173 tempted to optimize redisplay based on lines displayed
4174 in the first redisplay. */
4175 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
4176 for (i
= vpos
+ 1; i
< w
->current_matrix
->nrows
- 1; ++i
)
4177 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
4180 /* Was display preempted? */
4181 paused_p
= row
< end
;
4185 /* Fix the appearance of overlapping(overlapped rows. */
4186 if (!paused_p
&& !w
->pseudo_window_p
)
4188 if (changed_p
&& rif
->fix_overlapping_area
)
4190 redraw_overlapped_rows (w
, yb
);
4191 redraw_overlapping_rows (w
, yb
);
4194 /* Make cursor visible at cursor position of W. */
4195 set_window_cursor_after_update (w
);
4197 #if 0 /* Check that current matrix invariants are satisfied. This is
4198 for debugging only. See the comment of check_matrix_invariants. */
4199 IF_DEBUG (check_matrix_invariants (w
));
4204 /* Remember the redisplay method used to display the matrix. */
4205 strcpy (w
->current_matrix
->method
, w
->desired_matrix
->method
);
4208 /* End the update of window W. Don't set the cursor if we
4209 paused updating the display because in this case,
4210 set_window_cursor_after_update hasn't been called, and
4211 output_cursor doesn't contain the cursor location. */
4212 rif
->update_window_end_hook (w
, !paused_p
, mouse_face_overwritten_p
);
4218 /* check_current_matrix_flags (w); */
4219 add_window_display_history (w
, w
->current_matrix
->method
, paused_p
);
4222 clear_glyph_matrix (desired_matrix
);
4228 /* Update the display of area AREA in window W, row number VPOS.
4229 AREA can be either LEFT_MARGIN_AREA or RIGHT_MARGIN_AREA. */
4232 update_marginal_area (w
, area
, vpos
)
4236 struct glyph_row
*desired_row
= MATRIX_ROW (w
->desired_matrix
, vpos
);
4238 /* Let functions in xterm.c know what area subsequent X positions
4239 will be relative to. */
4240 updated_area
= area
;
4242 /* Set cursor to start of glyphs, write them, and clear to the end
4243 of the area. I don't think that something more sophisticated is
4244 necessary here, since marginal areas will not be the default. */
4245 rif
->cursor_to (vpos
, 0, desired_row
->y
, 0);
4246 if (desired_row
->used
[area
])
4247 rif
->write_glyphs (desired_row
->glyphs
[area
], desired_row
->used
[area
]);
4248 rif
->clear_end_of_line (-1);
4252 /* Update the display of the text area of row VPOS in window W.
4253 Value is non-zero if display has changed. */
4256 update_text_area (w
, vpos
)
4260 struct glyph_row
*current_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
4261 struct glyph_row
*desired_row
= MATRIX_ROW (w
->desired_matrix
, vpos
);
4264 /* Let functions in xterm.c know what area subsequent X positions
4265 will be relative to. */
4266 updated_area
= TEXT_AREA
;
4268 /* If rows are at different X or Y, or rows have different height,
4269 or the current row is marked invalid, write the entire line. */
4270 if (!current_row
->enabled_p
4271 || desired_row
->y
!= current_row
->y
4272 || desired_row
->ascent
!= current_row
->ascent
4273 || desired_row
->phys_ascent
!= current_row
->phys_ascent
4274 || desired_row
->phys_height
!= current_row
->phys_height
4275 || desired_row
->visible_height
!= current_row
->visible_height
4276 || current_row
->overlapped_p
4277 || current_row
->mouse_face_p
4278 || current_row
->x
!= desired_row
->x
)
4280 rif
->cursor_to (vpos
, 0, desired_row
->y
, desired_row
->x
);
4282 if (desired_row
->used
[TEXT_AREA
])
4283 rif
->write_glyphs (desired_row
->glyphs
[TEXT_AREA
],
4284 desired_row
->used
[TEXT_AREA
]);
4286 /* Clear to end of window. */
4287 rif
->clear_end_of_line (-1);
4293 struct glyph
*current_glyph
= current_row
->glyphs
[TEXT_AREA
];
4294 struct glyph
*desired_glyph
= desired_row
->glyphs
[TEXT_AREA
];
4295 int overlapping_glyphs_p
= current_row
->contains_overlapping_glyphs_p
;
4296 int desired_stop_pos
= desired_row
->used
[TEXT_AREA
];
4298 /* If the desired row extends its face to the text area end,
4299 make sure we write at least one glyph, so that the face
4300 extension actually takes place. */
4301 if (MATRIX_ROW_EXTENDS_FACE_P (desired_row
))
4304 stop
= min (current_row
->used
[TEXT_AREA
], desired_stop_pos
);
4308 /* Loop over glyphs that current and desired row may have
4314 /* Skip over glyphs that both rows have in common. These
4315 don't have to be written. We can't skip if the last
4316 current glyph overlaps the glyph to its right. For
4317 example, consider a current row of `if ' with the `f' in
4318 Courier bold so that it overlaps the ` ' to its right.
4319 If the desired row is ` ', we would skip over the space
4320 after the `if' and there would remain a pixel from the
4321 `f' on the screen. */
4322 if (overlapping_glyphs_p
&& i
> 0)
4324 struct glyph
*glyph
= ¤t_row
->glyphs
[TEXT_AREA
][i
- 1];
4327 rif
->get_glyph_overhangs (glyph
, XFRAME (w
->frame
),
4329 can_skip_p
= right
== 0;
4335 && GLYPH_EQUAL_P (desired_glyph
, current_glyph
))
4337 x
+= desired_glyph
->pixel_width
;
4338 ++desired_glyph
, ++current_glyph
, ++i
;
4341 /* Consider the case that the current row contains "xxx
4342 ppp ggg" in italic Courier font, and the desired row
4343 is "xxx ggg". The character `p' has lbearing, `g'
4344 has not. The loop above will stop in front of the
4345 first `p' in the current row. If we would start
4346 writing glyphs there, we wouldn't erase the lbearing
4347 of the `p'. The rest of the lbearing problem is then
4348 taken care of by x_draw_glyphs. */
4349 if (overlapping_glyphs_p
4351 && i
< current_row
->used
[TEXT_AREA
]
4352 && (current_row
->used
[TEXT_AREA
]
4353 != desired_row
->used
[TEXT_AREA
]))
4357 rif
->get_glyph_overhangs (current_glyph
, XFRAME (w
->frame
),
4359 while (left
> 0 && i
> 0)
4361 --i
, --desired_glyph
, --current_glyph
;
4362 x
-= desired_glyph
->pixel_width
;
4363 left
-= desired_glyph
->pixel_width
;
4368 /* Try to avoid writing the entire rest of the desired row
4369 by looking for a resync point. This mainly prevents
4370 mode line flickering in the case the mode line is in
4371 fixed-pitch font, which it usually will be. */
4372 if (i
< desired_row
->used
[TEXT_AREA
])
4374 int start_x
= x
, start_hpos
= i
;
4375 struct glyph
*start
= desired_glyph
;
4377 int skip_first_p
= !can_skip_p
;
4379 /* Find the next glyph that's equal again. */
4382 || !GLYPH_EQUAL_P (desired_glyph
, current_glyph
))
4385 x
+= desired_glyph
->pixel_width
;
4386 current_x
+= current_glyph
->pixel_width
;
4387 ++desired_glyph
, ++current_glyph
, ++i
;
4391 if (i
== start_hpos
|| x
!= current_x
)
4395 desired_glyph
= start
;
4399 rif
->cursor_to (vpos
, start_hpos
, desired_row
->y
, start_x
);
4400 rif
->write_glyphs (start
, i
- start_hpos
);
4405 /* Write the rest. */
4406 if (i
< desired_row
->used
[TEXT_AREA
])
4408 rif
->cursor_to (vpos
, i
, desired_row
->y
, x
);
4409 rif
->write_glyphs (desired_glyph
, desired_row
->used
[TEXT_AREA
] - i
);
4413 /* Maybe clear to end of line. */
4414 if (MATRIX_ROW_EXTENDS_FACE_P (desired_row
))
4416 /* If new row extends to the end of the text area, nothing
4417 has to be cleared, if and only if we did a write_glyphs
4418 above. This is made sure by setting desired_stop_pos
4419 appropriately above. */
4420 xassert (i
< desired_row
->used
[TEXT_AREA
]);
4422 else if (MATRIX_ROW_EXTENDS_FACE_P (current_row
))
4424 /* If old row extends to the end of the text area, clear. */
4425 if (i
>= desired_row
->used
[TEXT_AREA
])
4426 rif
->cursor_to (vpos
, i
, desired_row
->y
,
4427 desired_row
->x
+ desired_row
->pixel_width
);
4428 rif
->clear_end_of_line (-1);
4431 else if (desired_row
->pixel_width
< current_row
->pixel_width
)
4433 /* Otherwise clear to the end of the old row. Everything
4434 after that position should be clear already. */
4437 if (i
>= desired_row
->used
[TEXT_AREA
])
4438 rif
->cursor_to (vpos
, i
, desired_row
->y
,
4439 desired_row
->x
+ desired_row
->pixel_width
);
4441 /* If cursor is displayed at the end of the line, make sure
4442 it's cleared. Nowadays we don't have a phys_cursor_glyph
4443 with which to erase the cursor (because this method
4444 doesn't work with lbearing/rbearing), so we must do it
4446 if (vpos
== w
->phys_cursor
.vpos
4447 && w
->phys_cursor
.hpos
>= desired_row
->used
[TEXT_AREA
])
4449 w
->phys_cursor_on_p
= 0;
4453 x
= current_row
->x
+ current_row
->pixel_width
;
4454 rif
->clear_end_of_line (x
);
4463 /* Update row VPOS in window W. Value is non-zero if display has been
4467 update_window_line (w
, vpos
, mouse_face_overwritten_p
)
4469 int vpos
, *mouse_face_overwritten_p
;
4471 struct glyph_row
*current_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
4472 struct glyph_row
*desired_row
= MATRIX_ROW (w
->desired_matrix
, vpos
);
4475 /* Set the row being updated. This is important to let xterm.c
4476 know what line height values are in effect. */
4477 updated_row
= desired_row
;
4479 /* A row can be completely invisible in case a desired matrix was
4480 built with a vscroll and then make_cursor_line_fully_visible shifts
4481 the matrix. Make sure to make such rows current anyway, since
4482 we need the correct y-position, for example, in the current matrix. */
4483 if (desired_row
->mode_line_p
4484 || desired_row
->visible_height
> 0)
4486 xassert (desired_row
->enabled_p
);
4488 /* Update display of the left margin area, if there is one. */
4489 if (!desired_row
->full_width_p
4490 && !NILP (w
->left_margin_width
))
4493 update_marginal_area (w
, LEFT_MARGIN_AREA
, vpos
);
4496 /* Update the display of the text area. */
4497 if (update_text_area (w
, vpos
))
4500 if (current_row
->mouse_face_p
)
4501 *mouse_face_overwritten_p
= 1;
4504 /* Update display of the right margin area, if there is one. */
4505 if (!desired_row
->full_width_p
4506 && !NILP (w
->right_margin_width
))
4509 update_marginal_area (w
, RIGHT_MARGIN_AREA
, vpos
);
4512 /* Draw truncation marks etc. */
4513 if (!current_row
->enabled_p
4514 || desired_row
->y
!= current_row
->y
4515 || desired_row
->visible_height
!= current_row
->visible_height
4516 || desired_row
->overlay_arrow_p
!= current_row
->overlay_arrow_p
4517 || desired_row
->truncated_on_left_p
!= current_row
->truncated_on_left_p
4518 || desired_row
->truncated_on_right_p
!= current_row
->truncated_on_right_p
4519 || desired_row
->continued_p
!= current_row
->continued_p
4520 || desired_row
->mode_line_p
!= current_row
->mode_line_p
4521 || (desired_row
->indicate_empty_line_p
4522 != current_row
->indicate_empty_line_p
)
4523 || (MATRIX_ROW_CONTINUATION_LINE_P (desired_row
)
4524 != MATRIX_ROW_CONTINUATION_LINE_P (current_row
)))
4525 rif
->after_update_window_line_hook (desired_row
);
4528 /* Update current_row from desired_row. */
4529 make_current (w
->desired_matrix
, w
->current_matrix
, vpos
);
4535 /* Set the cursor after an update of window W. This function may only
4536 be called from update_window. */
4539 set_window_cursor_after_update (w
)
4542 struct frame
*f
= XFRAME (w
->frame
);
4543 int cx
, cy
, vpos
, hpos
;
4545 /* Not intended for frame matrix updates. */
4546 xassert (FRAME_WINDOW_P (f
));
4548 if (cursor_in_echo_area
4549 && !NILP (echo_area_buffer
[0])
4550 /* If we are showing a message instead of the mini-buffer,
4551 show the cursor for the message instead. */
4552 && XWINDOW (minibuf_window
) == w
4553 && EQ (minibuf_window
, echo_area_window
)
4554 /* These cases apply only to the frame that contains
4555 the active mini-buffer window. */
4556 && FRAME_HAS_MINIBUF_P (f
)
4557 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
4559 cx
= cy
= vpos
= hpos
= 0;
4561 if (cursor_in_echo_area
>= 0)
4563 /* If the mini-buffer is several lines high, find the last
4564 line that has any text on it. Note: either all lines
4565 are enabled or none. Otherwise we wouldn't be able to
4567 struct glyph_row
*row
, *last_row
;
4568 struct glyph
*glyph
;
4569 int yb
= window_text_bottom_y (w
);
4572 row
= w
->current_matrix
->rows
;
4573 while (row
->enabled_p
4574 && (last_row
== NULL
4575 || MATRIX_ROW_BOTTOM_Y (row
) <= yb
))
4577 if (row
->used
[TEXT_AREA
]
4578 && row
->glyphs
[TEXT_AREA
][0].charpos
>= 0)
4585 struct glyph
*start
= last_row
->glyphs
[TEXT_AREA
];
4586 struct glyph
*last
= start
+ last_row
->used
[TEXT_AREA
] - 1;
4588 while (last
> start
&& last
->charpos
< 0)
4591 for (glyph
= start
; glyph
< last
; ++glyph
)
4593 cx
+= glyph
->pixel_width
;
4598 vpos
= MATRIX_ROW_VPOS (last_row
, w
->current_matrix
);
4606 hpos
= w
->cursor
.hpos
;
4607 vpos
= w
->cursor
.vpos
;
4610 /* Window cursor can be out of sync for horizontally split windows. */
4611 hpos
= max (0, hpos
);
4612 hpos
= min (w
->current_matrix
->matrix_w
- 1, hpos
);
4613 vpos
= max (0, vpos
);
4614 vpos
= min (w
->current_matrix
->nrows
- 1, vpos
);
4615 rif
->cursor_to (vpos
, hpos
, cy
, cx
);
4619 /* Set WINDOW->must_be_updated_p to ON_P for all windows in the window
4620 tree rooted at W. */
4623 set_window_update_flags (w
, on_p
)
4629 if (!NILP (w
->hchild
))
4630 set_window_update_flags (XWINDOW (w
->hchild
), on_p
);
4631 else if (!NILP (w
->vchild
))
4632 set_window_update_flags (XWINDOW (w
->vchild
), on_p
);
4634 w
->must_be_updated_p
= on_p
;
4636 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4642 /***********************************************************************
4643 Window-Based Scrolling
4644 ***********************************************************************/
4646 /* Structure describing rows in scrolling_window. */
4650 /* Number of occurrences of this row in desired and current matrix. */
4651 int old_uses
, new_uses
;
4653 /* Vpos of row in new matrix. */
4654 int new_line_number
;
4656 /* Bucket index of this row_entry in the hash table row_table. */
4659 /* The row described by this entry. */
4660 struct glyph_row
*row
;
4662 /* Hash collision chain. */
4663 struct row_entry
*next
;
4666 /* A pool to allocate row_entry structures from, and the size of the
4667 pool. The pool is reallocated in scrolling_window when we find
4668 that we need a larger one. */
4670 static struct row_entry
*row_entry_pool
;
4671 static int row_entry_pool_size
;
4673 /* Index of next free entry in row_entry_pool. */
4675 static int row_entry_idx
;
4677 /* The hash table used during scrolling, and the table's size. This
4678 table is used to quickly identify equal rows in the desired and
4681 static struct row_entry
**row_table
;
4682 static int row_table_size
;
4684 /* Vectors of pointers to row_entry structures belonging to the
4685 current and desired matrix, and the size of the vectors. */
4687 static struct row_entry
**old_lines
, **new_lines
;
4688 static int old_lines_size
, new_lines_size
;
4690 /* A pool to allocate run structures from, and its size. */
4692 static struct run
*run_pool
;
4693 static int runs_size
;
4695 /* A vector of runs of lines found during scrolling. */
4697 static struct run
**runs
;
4699 static struct row_entry
*add_row_entry
P_ ((struct window
*,
4700 struct glyph_row
*));
4703 /* Add glyph row ROW to the scrolling hash table during the scrolling
4706 static INLINE
struct row_entry
*
4707 add_row_entry (w
, row
)
4709 struct glyph_row
*row
;
4711 struct row_entry
*entry
;
4712 int i
= row
->hash
% row_table_size
;
4714 entry
= row_table
[i
];
4715 while (entry
&& !row_equal_p (w
, entry
->row
, row
, 1))
4716 entry
= entry
->next
;
4720 entry
= row_entry_pool
+ row_entry_idx
++;
4722 entry
->old_uses
= entry
->new_uses
= 0;
4723 entry
->new_line_number
= 0;
4725 entry
->next
= row_table
[i
];
4726 row_table
[i
] = entry
;
4733 /* Try to reuse part of the current display of W by scrolling lines.
4734 HEADER_LINE_P non-zero means W has a top mode line.
4736 The algorithm is taken from Communications of the ACM, Apr78 "A
4737 Technique for Isolating Differences Between Files." It should take
4740 A short outline of the steps of the algorithm
4742 1. Skip lines equal at the start and end of both matrices.
4744 2. Enter rows in the current and desired matrix into a symbol
4745 table, counting how often they appear in both matrices.
4747 3. Rows that appear exactly once in both matrices serve as anchors,
4748 i.e. we assume that such lines are likely to have been moved.
4750 4. Starting from anchor lines, extend regions to be scrolled both
4751 forward and backward.
4755 -1 if all rows were found to be equal.
4756 0 to indicate that we did not scroll the display, or
4757 1 if we did scroll. */
4760 scrolling_window (w
, header_line_p
)
4764 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
4765 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
4766 int yb
= window_text_bottom_y (w
);
4767 int i
, j
, first_old
, first_new
, last_old
, last_new
;
4768 int nruns
, nbytes
, n
, run_idx
;
4769 struct row_entry
*entry
;
4771 /* Skip over rows equal at the start. */
4772 for (i
= header_line_p
? 1 : 0; i
< current_matrix
->nrows
- 1; ++i
)
4774 struct glyph_row
*d
= MATRIX_ROW (desired_matrix
, i
);
4775 struct glyph_row
*c
= MATRIX_ROW (current_matrix
, i
);
4780 && MATRIX_ROW_BOTTOM_Y (c
) <= yb
4781 && MATRIX_ROW_BOTTOM_Y (d
) <= yb
4782 && row_equal_p (w
, c
, d
, 1))
4791 /* Give up if some rows in the desired matrix are not enabled. */
4792 if (!MATRIX_ROW (desired_matrix
, i
)->enabled_p
)
4795 first_old
= first_new
= i
;
4797 /* Set last_new to the index + 1 of the last enabled row in the
4800 while (i
< desired_matrix
->nrows
- 1
4801 && MATRIX_ROW (desired_matrix
, i
)->enabled_p
4802 && MATRIX_ROW_BOTTOM_Y (MATRIX_ROW (desired_matrix
, i
)) <= yb
)
4805 if (!MATRIX_ROW (desired_matrix
, i
)->enabled_p
)
4810 /* Set last_old to the index + 1 of the last enabled row in the
4811 current matrix. We don't look at the enabled flag here because
4812 we plan to reuse part of the display even if other parts are
4815 while (i
< current_matrix
->nrows
- 1)
4817 int bottom
= MATRIX_ROW_BOTTOM_Y (MATRIX_ROW (current_matrix
, i
));
4826 /* Skip over rows equal at the bottom. */
4829 while (i
- 1 > first_new
4830 && j
- 1 > first_old
4831 && MATRIX_ROW (current_matrix
, i
- 1)->enabled_p
4832 && (MATRIX_ROW (current_matrix
, i
- 1)->y
4833 == MATRIX_ROW (desired_matrix
, j
- 1)->y
)
4835 MATRIX_ROW (desired_matrix
, i
- 1),
4836 MATRIX_ROW (current_matrix
, j
- 1), 1))
4841 /* Nothing to do if all rows are equal. */
4842 if (last_new
== first_new
)
4845 /* Reallocate vectors, tables etc. if necessary. */
4847 if (current_matrix
->nrows
> old_lines_size
)
4849 old_lines_size
= current_matrix
->nrows
;
4850 nbytes
= old_lines_size
* sizeof *old_lines
;
4851 old_lines
= (struct row_entry
**) xrealloc (old_lines
, nbytes
);
4854 if (desired_matrix
->nrows
> new_lines_size
)
4856 new_lines_size
= desired_matrix
->nrows
;
4857 nbytes
= new_lines_size
* sizeof *new_lines
;
4858 new_lines
= (struct row_entry
**) xrealloc (new_lines
, nbytes
);
4861 n
= desired_matrix
->nrows
+ current_matrix
->nrows
;
4862 if (3 * n
> row_table_size
)
4864 row_table_size
= next_almost_prime (3 * n
);
4865 nbytes
= row_table_size
* sizeof *row_table
;
4866 row_table
= (struct row_entry
**) xrealloc (row_table
, nbytes
);
4867 bzero (row_table
, nbytes
);
4870 if (n
> row_entry_pool_size
)
4872 row_entry_pool_size
= n
;
4873 nbytes
= row_entry_pool_size
* sizeof *row_entry_pool
;
4874 row_entry_pool
= (struct row_entry
*) xrealloc (row_entry_pool
, nbytes
);
4877 if (desired_matrix
->nrows
> runs_size
)
4879 runs_size
= desired_matrix
->nrows
;
4880 nbytes
= runs_size
* sizeof *runs
;
4881 runs
= (struct run
**) xrealloc (runs
, nbytes
);
4882 nbytes
= runs_size
* sizeof *run_pool
;
4883 run_pool
= (struct run
*) xrealloc (run_pool
, nbytes
);
4886 nruns
= run_idx
= 0;
4889 /* Add rows from the current and desired matrix to the hash table
4890 row_hash_table to be able to find equal ones quickly. */
4892 for (i
= first_old
; i
< last_old
; ++i
)
4894 if (MATRIX_ROW (current_matrix
, i
)->enabled_p
)
4896 entry
= add_row_entry (w
, MATRIX_ROW (current_matrix
, i
));
4897 old_lines
[i
] = entry
;
4901 old_lines
[i
] = NULL
;
4904 for (i
= first_new
; i
< last_new
; ++i
)
4906 xassert (MATRIX_ROW_ENABLED_P (desired_matrix
, i
));
4907 entry
= add_row_entry (w
, MATRIX_ROW (desired_matrix
, i
));
4909 entry
->new_line_number
= i
;
4910 new_lines
[i
] = entry
;
4913 /* Identify moves based on lines that are unique and equal
4914 in both matrices. */
4915 for (i
= first_old
; i
< last_old
;)
4917 && old_lines
[i
]->old_uses
== 1
4918 && old_lines
[i
]->new_uses
== 1)
4921 int new_line
= old_lines
[i
]->new_line_number
;
4922 struct run
*run
= run_pool
+ run_idx
++;
4925 run
->current_vpos
= i
;
4926 run
->current_y
= MATRIX_ROW (current_matrix
, i
)->y
;
4927 run
->desired_vpos
= new_line
;
4928 run
->desired_y
= MATRIX_ROW (desired_matrix
, new_line
)->y
;
4930 run
->height
= MATRIX_ROW (current_matrix
, i
)->height
;
4932 /* Extend backward. */
4935 while (j
> first_old
4937 && old_lines
[j
] == new_lines
[k
])
4939 int h
= MATRIX_ROW (current_matrix
, j
)->height
;
4940 --run
->current_vpos
;
4941 --run
->desired_vpos
;
4944 run
->desired_y
-= h
;
4945 run
->current_y
-= h
;
4949 /* Extend forward. */
4954 && old_lines
[j
] == new_lines
[k
])
4956 int h
= MATRIX_ROW (current_matrix
, j
)->height
;
4962 /* Insert run into list of all runs. Order runs by copied
4963 pixel lines. Note that we record runs that don't have to
4964 be copied because they are already in place. This is done
4965 because we can avoid calling update_window_line in this
4967 for (j
= 0; j
< nruns
&& runs
[j
]->height
> run
->height
; ++j
)
4969 for (k
= nruns
; k
> j
; --k
)
4970 runs
[k
] = runs
[k
- 1];
4979 /* Do the moves. Do it in a way that we don't overwrite something
4980 we want to copy later on. This is not solvable in general
4981 because there is only one display and we don't have a way to
4982 exchange areas on this display. Example:
4984 +-----------+ +-----------+
4986 +-----------+ --> +-----------+
4988 +-----------+ +-----------+
4990 Instead, prefer bigger moves, and invalidate moves that would
4991 copy from where we copied to. */
4993 for (i
= 0; i
< nruns
; ++i
)
4994 if (runs
[i
]->nrows
> 0)
4996 struct run
*r
= runs
[i
];
4998 /* Copy on the display. */
4999 if (r
->current_y
!= r
->desired_y
)
5001 rif
->scroll_run_hook (w
, r
);
5003 /* Invalidate runs that copy from where we copied to. */
5004 for (j
= i
+ 1; j
< nruns
; ++j
)
5006 struct run
*p
= runs
[j
];
5008 if ((p
->current_y
>= r
->desired_y
5009 && p
->current_y
< r
->desired_y
+ r
->height
)
5010 || (p
->current_y
+ p
->height
>= r
->desired_y
5011 && (p
->current_y
+ p
->height
5012 < r
->desired_y
+ r
->height
)))
5017 /* Assign matrix rows. */
5018 for (j
= 0; j
< r
->nrows
; ++j
)
5020 struct glyph_row
*from
, *to
;
5021 int to_overlapped_p
;
5023 to
= MATRIX_ROW (current_matrix
, r
->desired_vpos
+ j
);
5024 from
= MATRIX_ROW (desired_matrix
, r
->desired_vpos
+ j
);
5025 to_overlapped_p
= to
->overlapped_p
;
5026 assign_row (to
, from
);
5027 to
->enabled_p
= 1, from
->enabled_p
= 0;
5028 to
->overlapped_p
= to_overlapped_p
;
5032 /* Clear the hash table, for the next time. */
5033 for (i
= 0; i
< row_entry_idx
; ++i
)
5034 row_table
[row_entry_pool
[i
].bucket
] = NULL
;
5036 /* Value is non-zero to indicate that we scrolled the display. */
5042 /************************************************************************
5044 ************************************************************************/
5046 /* Update the desired frame matrix of frame F.
5048 FORCE_P non-zero means that the update should not be stopped by
5049 pending input. INHIBIT_HAIRY_ID_P non-zero means that scrolling
5050 should not be tried.
5052 Value is non-zero if update was stopped due to pending input. */
5055 update_frame_1 (f
, force_p
, inhibit_id_p
)
5060 /* Frame matrices to work on. */
5061 struct glyph_matrix
*current_matrix
= f
->current_matrix
;
5062 struct glyph_matrix
*desired_matrix
= f
->desired_matrix
;
5065 int preempt_count
= baud_rate
/ 2400 + 1;
5066 extern int input_pending
;
5068 xassert (current_matrix
&& desired_matrix
);
5070 if (baud_rate
!= FRAME_COST_BAUD_RATE (f
))
5071 calculate_costs (f
);
5073 if (preempt_count
<= 0)
5076 if (redisplay_dont_pause
)
5078 else if (!force_p
&& detect_input_pending ())
5084 /* If we cannot insert/delete lines, it's no use trying it. */
5085 if (!line_ins_del_ok
)
5088 /* See if any of the desired lines are enabled; don't compute for
5089 i/d line if just want cursor motion. */
5090 for (i
= 0; i
< desired_matrix
->nrows
; i
++)
5091 if (MATRIX_ROW_ENABLED_P (desired_matrix
, i
))
5094 /* Try doing i/d line, if not yet inhibited. */
5095 if (!inhibit_id_p
&& i
< desired_matrix
->nrows
)
5096 force_p
|= scrolling (f
);
5098 /* Update the individual lines as needed. Do bottom line first. */
5099 if (MATRIX_ROW_ENABLED_P (desired_matrix
, desired_matrix
->nrows
- 1))
5100 update_frame_line (f
, desired_matrix
->nrows
- 1);
5102 /* Now update the rest of the lines. */
5103 for (i
= 0; i
< desired_matrix
->nrows
- 1 && (force_p
|| !input_pending
); i
++)
5105 if (MATRIX_ROW_ENABLED_P (desired_matrix
, i
))
5107 if (FRAME_TERMCAP_P (f
))
5109 /* Flush out every so many lines.
5110 Also flush out if likely to have more than 1k buffered
5111 otherwise. I'm told that some telnet connections get
5112 really screwed by more than 1k output at once. */
5113 int outq
= PENDING_OUTPUT_COUNT (stdout
);
5115 || (outq
> 20 && ((i
- 1) % preempt_count
== 0)))
5118 if (preempt_count
== 1)
5120 #ifdef EMACS_OUTQSIZE
5121 if (EMACS_OUTQSIZE (0, &outq
) < 0)
5122 /* Probably not a tty. Ignore the error and reset
5123 * the outq count. */
5124 outq
= PENDING_OUTPUT_COUNT (stdout
);
5127 if (baud_rate
<= outq
&& baud_rate
> 0)
5128 sleep (outq
/ baud_rate
);
5133 if ((i
- 1) % preempt_count
== 0)
5134 detect_input_pending ();
5136 update_frame_line (f
, i
);
5140 pause
= (i
< FRAME_HEIGHT (f
) - 1) ? i
: 0;
5142 /* Now just clean up termcap drivers and set cursor, etc. */
5145 if ((cursor_in_echo_area
5146 /* If we are showing a message instead of the mini-buffer,
5147 show the cursor for the message instead of for the
5148 (now hidden) mini-buffer contents. */
5149 || (EQ (minibuf_window
, selected_window
)
5150 && EQ (minibuf_window
, echo_area_window
)
5151 && !NILP (echo_area_buffer
[0])))
5152 /* These cases apply only to the frame that contains
5153 the active mini-buffer window. */
5154 && FRAME_HAS_MINIBUF_P (f
)
5155 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
5157 int top
= XINT (XWINDOW (FRAME_MINIBUF_WINDOW (f
))->top
);
5160 if (cursor_in_echo_area
< 0)
5162 /* Negative value of cursor_in_echo_area means put
5163 cursor at beginning of line. */
5169 /* Positive value of cursor_in_echo_area means put
5170 cursor at the end of the prompt. If the mini-buffer
5171 is several lines high, find the last line that has
5173 row
= FRAME_HEIGHT (f
);
5179 if (MATRIX_ROW_ENABLED_P (current_matrix
, row
))
5181 /* Frame rows are filled up with spaces that
5182 must be ignored here. */
5183 struct glyph_row
*r
= MATRIX_ROW (current_matrix
,
5185 struct glyph
*start
= r
->glyphs
[TEXT_AREA
];
5186 struct glyph
*last
= start
+ r
->used
[TEXT_AREA
];
5189 && (last
- 1)->charpos
< 0)
5195 while (row
> top
&& col
== 0);
5197 /* Make sure COL is not out of range. */
5198 if (col
>= FRAME_CURSOR_X_LIMIT (f
))
5200 /* If we have another row, advance cursor into it. */
5201 if (row
< FRAME_HEIGHT (f
) - 1)
5203 col
= FRAME_LEFT_SCROLL_BAR_WIDTH (f
);
5206 /* Otherwise move it back in range. */
5208 col
= FRAME_CURSOR_X_LIMIT (f
) - 1;
5212 cursor_to (row
, col
);
5216 /* We have only one cursor on terminal frames. Use it to
5217 display the cursor of the selected window. */
5218 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
5219 if (w
->cursor
.vpos
>= 0
5220 /* The cursor vpos may be temporarily out of bounds
5221 in the following situation: There is one window,
5222 with the cursor in the lower half of it. The window
5223 is split, and a message causes a redisplay before
5224 a new cursor position has been computed. */
5225 && w
->cursor
.vpos
< XFASTINT (w
->height
))
5227 int x
= WINDOW_TO_FRAME_HPOS (w
, w
->cursor
.hpos
);
5228 int y
= WINDOW_TO_FRAME_VPOS (w
, w
->cursor
.vpos
);
5230 if (INTEGERP (w
->left_margin_width
))
5231 x
+= XFASTINT (w
->left_margin_width
);
5233 /* x = max (min (x, FRAME_WINDOW_WIDTH (f) - 1), 0); */
5241 clear_desired_matrices (f
);
5246 /* Do line insertions/deletions on frame F for frame-based redisplay. */
5250 struct frame
*frame
;
5252 int unchanged_at_top
, unchanged_at_bottom
;
5255 int *old_hash
= (int *) alloca (FRAME_HEIGHT (frame
) * sizeof (int));
5256 int *new_hash
= (int *) alloca (FRAME_HEIGHT (frame
) * sizeof (int));
5257 int *draw_cost
= (int *) alloca (FRAME_HEIGHT (frame
) * sizeof (int));
5258 int *old_draw_cost
= (int *) alloca (FRAME_HEIGHT (frame
) * sizeof (int));
5260 int free_at_end_vpos
= FRAME_HEIGHT (frame
);
5261 struct glyph_matrix
*current_matrix
= frame
->current_matrix
;
5262 struct glyph_matrix
*desired_matrix
= frame
->desired_matrix
;
5264 if (!current_matrix
)
5267 /* Compute hash codes of all the lines. Also calculate number of
5268 changed lines, number of unchanged lines at the beginning, and
5269 number of unchanged lines at the end. */
5271 unchanged_at_top
= 0;
5272 unchanged_at_bottom
= FRAME_HEIGHT (frame
);
5273 for (i
= 0; i
< FRAME_HEIGHT (frame
); i
++)
5275 /* Give up on this scrolling if some old lines are not enabled. */
5276 if (!MATRIX_ROW_ENABLED_P (current_matrix
, i
))
5278 old_hash
[i
] = line_hash_code (MATRIX_ROW (current_matrix
, i
));
5279 if (! MATRIX_ROW_ENABLED_P (desired_matrix
, i
))
5281 /* This line cannot be redrawn, so don't let scrolling mess it. */
5282 new_hash
[i
] = old_hash
[i
];
5283 #define INFINITY 1000000 /* Taken from scroll.c */
5284 draw_cost
[i
] = INFINITY
;
5288 new_hash
[i
] = line_hash_code (MATRIX_ROW (desired_matrix
, i
));
5289 draw_cost
[i
] = line_draw_cost (desired_matrix
, i
);
5292 if (old_hash
[i
] != new_hash
[i
])
5295 unchanged_at_bottom
= FRAME_HEIGHT (frame
) - i
- 1;
5297 else if (i
== unchanged_at_top
)
5299 old_draw_cost
[i
] = line_draw_cost (current_matrix
, i
);
5302 /* If changed lines are few, don't allow preemption, don't scroll. */
5303 if ((!scroll_region_ok
&& changed_lines
< baud_rate
/ 2400)
5304 || unchanged_at_bottom
== FRAME_HEIGHT (frame
))
5307 window_size
= (FRAME_HEIGHT (frame
) - unchanged_at_top
5308 - unchanged_at_bottom
);
5310 if (scroll_region_ok
)
5311 free_at_end_vpos
-= unchanged_at_bottom
;
5312 else if (memory_below_frame
)
5313 free_at_end_vpos
= -1;
5315 /* If large window, fast terminal and few lines in common between
5316 current frame and desired frame, don't bother with i/d calc. */
5317 if (!scroll_region_ok
&& window_size
>= 18 && baud_rate
> 2400
5319 10 * scrolling_max_lines_saved (unchanged_at_top
,
5320 FRAME_HEIGHT (frame
) - unchanged_at_bottom
,
5321 old_hash
, new_hash
, draw_cost
)))
5324 if (window_size
< 2)
5327 scrolling_1 (frame
, window_size
, unchanged_at_top
, unchanged_at_bottom
,
5328 draw_cost
+ unchanged_at_top
- 1,
5329 old_draw_cost
+ unchanged_at_top
- 1,
5330 old_hash
+ unchanged_at_top
- 1,
5331 new_hash
+ unchanged_at_top
- 1,
5332 free_at_end_vpos
- unchanged_at_top
);
5338 /* Count the number of blanks at the start of the vector of glyphs R
5339 which is LEN glyphs long. */
5342 count_blanks (r
, len
)
5348 for (i
= 0; i
< len
; ++i
)
5349 if (!CHAR_GLYPH_SPACE_P (r
[i
]))
5356 /* Count the number of glyphs in common at the start of the glyph
5357 vectors STR1 and STR2. END1 is the end of STR1 and END2 is the end
5358 of STR2. Value is the number of equal glyphs equal at the start. */
5361 count_match (str1
, end1
, str2
, end2
)
5362 struct glyph
*str1
, *end1
, *str2
, *end2
;
5364 struct glyph
*p1
= str1
;
5365 struct glyph
*p2
= str2
;
5369 && GLYPH_CHAR_AND_FACE_EQUAL_P (p1
, p2
))
5376 /* Char insertion/deletion cost vector, from term.c */
5378 extern int *char_ins_del_vector
;
5379 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_WINDOW_WIDTH((f))])
5382 /* Perform a frame-based update on line VPOS in frame FRAME. */
5385 update_frame_line (f
, vpos
)
5389 struct glyph
*obody
, *nbody
, *op1
, *op2
, *np1
, *nend
;
5391 int osp
, nsp
, begmatch
, endmatch
, olen
, nlen
;
5392 struct glyph_matrix
*current_matrix
= f
->current_matrix
;
5393 struct glyph_matrix
*desired_matrix
= f
->desired_matrix
;
5394 struct glyph_row
*current_row
= MATRIX_ROW (current_matrix
, vpos
);
5395 struct glyph_row
*desired_row
= MATRIX_ROW (desired_matrix
, vpos
);
5396 int must_write_whole_line_p
;
5397 int write_spaces_p
= must_write_spaces
;
5398 int colored_spaces_p
= (FACE_FROM_ID (f
, DEFAULT_FACE_ID
)->background
5399 != FACE_TTY_DEFAULT_BG_COLOR
);
5401 if (colored_spaces_p
)
5404 if (desired_row
->inverse_p
5405 != (current_row
->enabled_p
&& current_row
->inverse_p
))
5407 int n
= current_row
->enabled_p
? current_row
->used
[TEXT_AREA
] : 0;
5408 change_line_highlight (desired_row
->inverse_p
, vpos
, vpos
, n
);
5409 current_row
->enabled_p
= 0;
5412 reassert_line_highlight (desired_row
->inverse_p
, vpos
);
5414 /* Current row not enabled means it has unknown contents. We must
5415 write the whole desired line in that case. */
5416 must_write_whole_line_p
= !current_row
->enabled_p
;
5417 if (must_write_whole_line_p
)
5424 obody
= MATRIX_ROW_GLYPH_START (current_matrix
, vpos
);
5425 olen
= current_row
->used
[TEXT_AREA
];
5427 if (!current_row
->inverse_p
)
5429 /* Ignore trailing spaces, if we can. */
5430 if (!write_spaces_p
)
5431 while (olen
> 0 && CHAR_GLYPH_SPACE_P (obody
[olen
-1]))
5436 /* For an inverse-video line, make sure it's filled with
5437 spaces all the way to the frame edge so that the reverse
5438 video extends all the way across. */
5439 while (olen
< FRAME_WIDTH (f
) - 1)
5440 obody
[olen
++] = space_glyph
;
5444 current_row
->enabled_p
= 1;
5445 current_row
->used
[TEXT_AREA
] = desired_row
->used
[TEXT_AREA
];
5446 current_row
->inverse_p
= desired_row
->inverse_p
;
5448 /* If desired line is empty, just clear the line. */
5449 if (!desired_row
->enabled_p
)
5455 nbody
= desired_row
->glyphs
[TEXT_AREA
];
5456 nlen
= desired_row
->used
[TEXT_AREA
];
5457 nend
= nbody
+ nlen
;
5459 /* If display line has unknown contents, write the whole line. */
5460 if (must_write_whole_line_p
)
5462 /* Ignore spaces at the end, if we can. */
5463 if (!write_spaces_p
)
5464 while (nlen
> 0 && CHAR_GLYPH_SPACE_P (nbody
[nlen
- 1]))
5467 /* Write the contents of the desired line. */
5470 cursor_to (vpos
, 0);
5471 write_glyphs (nbody
, nlen
);
5474 /* Don't call clear_end_of_line if we already wrote the whole
5475 line. The cursor will not be at the right margin in that
5476 case but in the line below. */
5477 if (nlen
< FRAME_WINDOW_WIDTH (f
))
5479 cursor_to (vpos
, nlen
);
5480 clear_end_of_line (FRAME_WINDOW_WIDTH (f
));
5483 /* Make sure we are in the right row, otherwise cursor movement
5484 with cmgoto might use `ch' in the wrong row. */
5485 cursor_to (vpos
, 0);
5487 make_current (desired_matrix
, current_matrix
, vpos
);
5491 /* Pretend trailing spaces are not there at all,
5492 unless for one reason or another we must write all spaces. */
5493 if (!desired_row
->inverse_p
)
5495 if (!write_spaces_p
)
5496 while (nlen
> 0 && CHAR_GLYPH_SPACE_P (nbody
[nlen
- 1]))
5501 /* For an inverse-video line, give it extra trailing spaces all
5502 the way to the frame edge so that the reverse video extends
5503 all the way across. */
5504 while (nlen
< FRAME_WIDTH (f
) - 1)
5505 nbody
[nlen
++] = space_glyph
;
5508 /* If there's no i/d char, quickly do the best we can without it. */
5509 if (!char_ins_del_ok
)
5513 /* Find the first glyph in desired row that doesn't agree with
5514 a glyph in the current row, and write the rest from there on. */
5515 for (i
= 0; i
< nlen
; i
++)
5517 if (i
>= olen
|| !GLYPH_EQUAL_P (nbody
+ i
, obody
+ i
))
5519 /* Find the end of the run of different glyphs. */
5523 || !GLYPH_EQUAL_P (nbody
+ j
, obody
+ j
)
5524 || CHAR_GLYPH_PADDING_P (nbody
[j
])))
5527 /* Output this run of non-matching chars. */
5528 cursor_to (vpos
, i
);
5529 write_glyphs (nbody
+ i
, j
- i
);
5532 /* Now find the next non-match. */
5536 /* Clear the rest of the line, or the non-clear part of it. */
5539 cursor_to (vpos
, nlen
);
5540 clear_end_of_line (olen
);
5543 /* Make current row = desired row. */
5544 make_current (desired_matrix
, current_matrix
, vpos
);
5548 /* Here when CHAR_INS_DEL_OK != 0, i.e. we can insert or delete
5549 characters in a row. */
5553 /* If current line is blank, skip over initial spaces, if
5554 possible, and write the rest. */
5555 if (write_spaces_p
|| desired_row
->inverse_p
)
5558 nsp
= count_blanks (nbody
, nlen
);
5562 cursor_to (vpos
, nsp
);
5563 write_glyphs (nbody
+ nsp
, nlen
- nsp
);
5566 /* Exchange contents between current_frame and new_frame. */
5567 make_current (desired_matrix
, current_matrix
, vpos
);
5571 /* Compute number of leading blanks in old and new contents. */
5572 osp
= count_blanks (obody
, olen
);
5573 nsp
= (desired_row
->inverse_p
|| colored_spaces_p
5575 : count_blanks (nbody
, nlen
));
5577 /* Compute number of matching chars starting with first non-blank. */
5578 begmatch
= count_match (obody
+ osp
, obody
+ olen
,
5579 nbody
+ nsp
, nbody
+ nlen
);
5581 /* Spaces in new match implicit space past the end of old. */
5582 /* A bug causing this to be a no-op was fixed in 18.29. */
5583 if (!write_spaces_p
&& osp
+ begmatch
== olen
)
5586 while (np1
+ begmatch
< nend
&& CHAR_GLYPH_SPACE_P (np1
[begmatch
]))
5590 /* Avoid doing insert/delete char
5591 just cause number of leading spaces differs
5592 when the following text does not match. */
5593 if (begmatch
== 0 && osp
!= nsp
)
5594 osp
= nsp
= min (osp
, nsp
);
5596 /* Find matching characters at end of line */
5599 op2
= op1
+ begmatch
- min (olen
- osp
, nlen
- nsp
);
5601 && GLYPH_EQUAL_P (op1
- 1, np1
- 1))
5606 endmatch
= obody
+ olen
- op1
;
5608 /* tem gets the distance to insert or delete.
5609 endmatch is how many characters we save by doing so.
5612 tem
= (nlen
- nsp
) - (olen
- osp
);
5614 && (!char_ins_del_ok
|| endmatch
<= char_ins_del_cost (f
)[tem
]))
5617 /* nsp - osp is the distance to insert or delete.
5618 If that is nonzero, begmatch is known to be nonzero also.
5619 begmatch + endmatch is how much we save by doing the ins/del.
5623 && (!char_ins_del_ok
5624 || begmatch
+ endmatch
<= char_ins_del_cost (f
)[nsp
- osp
]))
5628 osp
= nsp
= min (osp
, nsp
);
5631 /* Now go through the line, inserting, writing and
5632 deleting as appropriate. */
5636 cursor_to (vpos
, nsp
);
5637 delete_glyphs (osp
- nsp
);
5641 /* If going to delete chars later in line
5642 and insert earlier in the line,
5643 must delete first to avoid losing data in the insert */
5644 if (endmatch
&& nlen
< olen
+ nsp
- osp
)
5646 cursor_to (vpos
, nlen
- endmatch
+ osp
- nsp
);
5647 delete_glyphs (olen
+ nsp
- osp
- nlen
);
5648 olen
= nlen
- (nsp
- osp
);
5650 cursor_to (vpos
, osp
);
5651 insert_glyphs (0, nsp
- osp
);
5655 tem
= nsp
+ begmatch
+ endmatch
;
5656 if (nlen
!= tem
|| olen
!= tem
)
5658 if (!endmatch
|| nlen
== olen
)
5660 /* If new text being written reaches right margin, there is
5661 no need to do clear-to-eol at the end of this function
5662 (and it would not be safe, since cursor is not going to
5663 be "at the margin" after the text is done). */
5664 if (nlen
== FRAME_WINDOW_WIDTH (f
))
5667 /* Function write_glyphs is prepared to do nothing
5668 if passed a length <= 0. Check it here to avoid
5669 unnecessary cursor movement. */
5672 cursor_to (vpos
, nsp
+ begmatch
);
5673 write_glyphs (nbody
+ nsp
+ begmatch
, nlen
- tem
);
5676 else if (nlen
> olen
)
5678 /* Here, we used to have the following simple code:
5679 ----------------------------------------
5680 write_glyphs (nbody + nsp + begmatch, olen - tem);
5681 insert_glyphs (nbody + nsp + begmatch + olen - tem, nlen - olen);
5682 ----------------------------------------
5683 but it doesn't work if nbody[nsp + begmatch + olen - tem]
5684 is a padding glyph. */
5685 int out
= olen
- tem
; /* Columns to be overwritten originally. */
5688 cursor_to (vpos
, nsp
+ begmatch
);
5690 /* Calculate columns we can actually overwrite. */
5691 while (CHAR_GLYPH_PADDING_P (nbody
[nsp
+ begmatch
+ out
]))
5693 write_glyphs (nbody
+ nsp
+ begmatch
, out
);
5695 /* If we left columns to be overwritten, we must delete them. */
5696 del
= olen
- tem
- out
;
5698 delete_glyphs (del
);
5700 /* At last, we insert columns not yet written out. */
5701 insert_glyphs (nbody
+ nsp
+ begmatch
+ out
, nlen
- olen
+ del
);
5704 else if (olen
> nlen
)
5706 cursor_to (vpos
, nsp
+ begmatch
);
5707 write_glyphs (nbody
+ nsp
+ begmatch
, nlen
- tem
);
5708 delete_glyphs (olen
- nlen
);
5714 /* If any unerased characters remain after the new line, erase them. */
5717 cursor_to (vpos
, nlen
);
5718 clear_end_of_line (olen
);
5721 /* Exchange contents between current_frame and new_frame. */
5722 make_current (desired_matrix
, current_matrix
, vpos
);
5727 /***********************************************************************
5728 X/Y Position -> Buffer Position
5729 ***********************************************************************/
5731 /* Determine what's under window-relative pixel position (*X, *Y).
5732 Return in *OBJECT the object (string or buffer) that's there.
5733 Return in *POS the position in that object. Adjust *X and *Y
5734 to character boundaries. */
5737 buffer_posn_from_coords (w
, x
, y
, object
, pos
)
5740 Lisp_Object
*object
;
5741 struct display_pos
*pos
;
5744 struct buffer
*old_current_buffer
= current_buffer
;
5745 struct text_pos startp
;
5746 int left_area_width
;
5748 current_buffer
= XBUFFER (w
->buffer
);
5749 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
5750 CHARPOS (startp
) = min (ZV
, max (BEGV
, CHARPOS (startp
)));
5751 BYTEPOS (startp
) = min (ZV_BYTE
, max (BEGV_BYTE
, BYTEPOS (startp
)));
5752 start_display (&it
, w
, startp
);
5754 left_area_width
= WINDOW_DISPLAY_LEFT_AREA_PIXEL_WIDTH (w
);
5755 move_it_to (&it
, -1, *x
+ it
.first_visible_x
- left_area_width
, *y
, -1,
5756 MOVE_TO_X
| MOVE_TO_Y
);
5758 *x
= it
.current_x
- it
.first_visible_x
+ left_area_width
;
5760 current_buffer
= old_current_buffer
;
5762 *object
= STRINGP (it
.string
) ? it
.string
: w
->buffer
;
5767 /* Value is the string under window-relative coordinates X/Y in the
5768 mode or top line of window W, or nil if none. MODE_LINE_P non-zero
5769 means look at the mode line. *CHARPOS is set to the position in
5770 the string returned. */
5773 mode_line_string (w
, x
, y
, mode_line_p
, charpos
)
5775 int x
, y
, mode_line_p
;
5778 struct glyph_row
*row
;
5779 struct glyph
*glyph
, *end
;
5780 struct frame
*f
= XFRAME (w
->frame
);
5782 Lisp_Object string
= Qnil
;
5785 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
5787 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
5789 if (row
->mode_line_p
&& row
->enabled_p
)
5791 /* The mode lines are displayed over scroll bars and bitmap
5792 areas, and X is window-relative. Correct X by the scroll bar
5793 and bitmap area width. */
5794 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
5795 x
+= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
5796 x
+= FRAME_LEFT_FLAGS_AREA_WIDTH (f
);
5798 /* Find the glyph under X. If we find one with a string object,
5799 it's the one we were looking for. */
5800 glyph
= row
->glyphs
[TEXT_AREA
];
5801 end
= glyph
+ row
->used
[TEXT_AREA
];
5802 for (x0
= 0; glyph
< end
; x0
+= glyph
->pixel_width
, ++glyph
)
5803 if (x
>= x0
&& x
< x0
+ glyph
->pixel_width
)
5805 string
= glyph
->object
;
5806 *charpos
= glyph
->charpos
;
5815 /***********************************************************************
5816 Changing Frame Sizes
5817 ***********************************************************************/
5822 window_change_signal (signalnum
) /* If we don't have an argument, */
5823 int signalnum
; /* some compilers complain in signal calls. */
5829 int old_errno
= errno
;
5831 get_frame_size (&width
, &height
);
5833 /* The frame size change obviously applies to a termcap-controlled
5834 frame. Find such a frame in the list, and assume it's the only
5835 one (since the redisplay code always writes to stdout, not a
5836 FILE * specified in the frame structure). Record the new size,
5837 but don't reallocate the data structures now. Let that be done
5838 later outside of the signal handler. */
5841 Lisp_Object tail
, frame
;
5843 FOR_EACH_FRAME (tail
, frame
)
5845 if (FRAME_TERMCAP_P (XFRAME (frame
)))
5847 change_frame_size (XFRAME (frame
), height
, width
, 0, 1, 0);
5853 signal (SIGWINCH
, window_change_signal
);
5856 #endif /* SIGWINCH */
5859 /* Do any change in frame size that was requested by a signal. SAFE
5860 non-zero means this function is called from a place where it is
5861 safe to change frame sizes while a redisplay is in progress. */
5864 do_pending_window_change (safe
)
5867 /* If window_change_signal should have run before, run it now. */
5868 if (redisplaying_p
&& !safe
)
5871 while (delayed_size_change
)
5873 Lisp_Object tail
, frame
;
5875 delayed_size_change
= 0;
5877 FOR_EACH_FRAME (tail
, frame
)
5879 struct frame
*f
= XFRAME (frame
);
5881 int height
= FRAME_NEW_HEIGHT (f
);
5882 int width
= FRAME_NEW_WIDTH (f
);
5884 if (height
!= 0 || width
!= 0)
5885 change_frame_size (f
, height
, width
, 0, 0, safe
);
5891 /* Change the frame height and/or width. Values may be given as zero to
5892 indicate no change is to take place.
5894 If DELAY is non-zero, then assume we're being called from a signal
5895 handler, and queue the change for later - perhaps the next
5896 redisplay. Since this tries to resize windows, we can't call it
5897 from a signal handler.
5899 SAFE non-zero means this function is called from a place where it's
5900 safe to change frame sizes while a redisplay is in progress. */
5903 change_frame_size (f
, newheight
, newwidth
, pretend
, delay
, safe
)
5904 register struct frame
*f
;
5905 int newheight
, newwidth
, pretend
, delay
, safe
;
5907 Lisp_Object tail
, frame
;
5909 if (! FRAME_WINDOW_P (f
))
5911 /* When using termcap, or on MS-DOS, all frames use
5912 the same screen, so a change in size affects all frames. */
5913 FOR_EACH_FRAME (tail
, frame
)
5914 if (! FRAME_WINDOW_P (XFRAME (frame
)))
5915 change_frame_size_1 (XFRAME (frame
), newheight
, newwidth
,
5916 pretend
, delay
, safe
);
5919 change_frame_size_1 (f
, newheight
, newwidth
, pretend
, delay
, safe
);
5923 change_frame_size_1 (f
, newheight
, newwidth
, pretend
, delay
, safe
)
5924 register struct frame
*f
;
5925 int newheight
, newwidth
, pretend
, delay
, safe
;
5927 int new_frame_window_width
;
5928 int count
= specpdl_ptr
- specpdl
;
5930 /* If we can't deal with the change now, queue it for later. */
5931 if (delay
|| (redisplaying_p
&& !safe
))
5933 FRAME_NEW_HEIGHT (f
) = newheight
;
5934 FRAME_NEW_WIDTH (f
) = newwidth
;
5935 delayed_size_change
= 1;
5939 /* This size-change overrides any pending one for this frame. */
5940 FRAME_NEW_HEIGHT (f
) = 0;
5941 FRAME_NEW_WIDTH (f
) = 0;
5943 /* If an argument is zero, set it to the current value. */
5945 newheight
= FRAME_HEIGHT (f
);
5947 newwidth
= FRAME_WIDTH (f
);
5949 /* Compute width of windows in F.
5950 This is the width of the frame without vertical scroll bars. */
5951 new_frame_window_width
= FRAME_WINDOW_WIDTH_ARG (f
, newwidth
);
5953 /* Round up to the smallest acceptable size. */
5954 check_frame_size (f
, &newheight
, &newwidth
);
5956 /* If we're not changing the frame size, quit now. */
5957 if (newheight
== FRAME_HEIGHT (f
)
5958 && new_frame_window_width
== FRAME_WINDOW_WIDTH (f
))
5964 /* We only can set screen dimensions to certain values supported
5965 by our video hardware. Try to find the smallest size greater
5966 or equal to the requested dimensions. */
5967 dos_set_window_size (&newheight
, &newwidth
);
5970 if (newheight
!= FRAME_HEIGHT (f
))
5972 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
5974 /* Frame has both root and mini-buffer. */
5975 XSETFASTINT (XWINDOW (FRAME_ROOT_WINDOW (f
))->top
,
5976 FRAME_TOP_MARGIN (f
));
5977 set_window_height (FRAME_ROOT_WINDOW (f
),
5980 - FRAME_TOP_MARGIN (f
)),
5982 XSETFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f
))->top
,
5984 set_window_height (FRAME_MINIBUF_WINDOW (f
), 1, 0);
5987 /* Frame has just one top-level window. */
5988 set_window_height (FRAME_ROOT_WINDOW (f
),
5989 newheight
- FRAME_TOP_MARGIN (f
), 0);
5991 if (FRAME_TERMCAP_P (f
) && !pretend
)
5992 FrameRows
= newheight
;
5995 if (new_frame_window_width
!= FRAME_WINDOW_WIDTH (f
))
5997 set_window_width (FRAME_ROOT_WINDOW (f
), new_frame_window_width
, 0);
5998 if (FRAME_HAS_MINIBUF_P (f
))
5999 set_window_width (FRAME_MINIBUF_WINDOW (f
), new_frame_window_width
, 0);
6001 if (FRAME_TERMCAP_P (f
) && !pretend
)
6002 FrameCols
= newwidth
;
6004 if (WINDOWP (f
->tool_bar_window
))
6005 XSETFASTINT (XWINDOW (f
->tool_bar_window
)->width
, newwidth
);
6008 FRAME_HEIGHT (f
) = newheight
;
6009 SET_FRAME_WIDTH (f
, newwidth
);
6012 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
6013 int text_area_x
, text_area_y
, text_area_width
, text_area_height
;
6015 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
, &text_area_width
,
6017 if (w
->cursor
.x
>= text_area_x
+ text_area_width
)
6018 w
->cursor
.hpos
= w
->cursor
.x
= 0;
6019 if (w
->cursor
.y
>= text_area_y
+ text_area_height
)
6020 w
->cursor
.vpos
= w
->cursor
.y
= 0;
6024 SET_FRAME_GARBAGED (f
);
6025 calculate_costs (f
);
6029 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
6031 /* This isn't quite a no-op: it runs window-configuration-change-hook. */
6032 Fset_window_buffer (FRAME_SELECTED_WINDOW (f
),
6033 XWINDOW (FRAME_SELECTED_WINDOW (f
))->buffer
);
6035 unbind_to (count
, Qnil
);
6040 /***********************************************************************
6041 Terminal Related Lisp Functions
6042 ***********************************************************************/
6044 DEFUN ("open-termscript", Fopen_termscript
, Sopen_termscript
,
6045 1, 1, "FOpen termscript file: ",
6046 /* Start writing all terminal output to FILE as well as the terminal.
6047 FILE = nil means just close any termscript file currently open. */
6051 if (termscript
!= 0) fclose (termscript
);
6056 file
= Fexpand_file_name (file
, Qnil
);
6057 termscript
= fopen (XSTRING (file
)->data
, "w");
6058 if (termscript
== 0)
6059 report_file_error ("Opening termscript", Fcons (file
, Qnil
));
6065 DEFUN ("send-string-to-terminal", Fsend_string_to_terminal
,
6066 Ssend_string_to_terminal
, 1, 1, 0,
6067 /* Send STRING to the terminal without alteration.
6068 Control characters in STRING will have terminal-dependent effects. */
6072 /* ??? Perhaps we should do something special for multibyte strings here. */
6073 CHECK_STRING (string
, 0);
6074 fwrite (XSTRING (string
)->data
, 1, STRING_BYTES (XSTRING (string
)), stdout
);
6078 fwrite (XSTRING (string
)->data
, 1, STRING_BYTES (XSTRING (string
)),
6080 fflush (termscript
);
6086 DEFUN ("ding", Fding
, Sding
, 0, 1, 0,
6087 /* Beep, or flash the screen.
6088 Also, unless an argument is given,
6089 terminate any keyboard macro currently executing. */
6112 else if (!INTERACTIVE
) /* Stop executing a keyboard macro. */
6113 error ("Keyboard macro terminated by a command ringing the bell");
6121 /***********************************************************************
6123 ***********************************************************************/
6125 DEFUN ("sleep-for", Fsleep_for
, Ssleep_for
, 1, 2, 0,
6126 /* Pause, without updating display, for SECONDS seconds.
6127 SECONDS may be a floating-point value, meaning that you can wait for a
6128 fraction of a second. Optional second arg MILLISECONDS specifies an
6129 additional wait period, in milliseconds; this may be useful if your
6130 Emacs was built without floating point support.
6131 \(Not all operating systems support waiting for a fraction of a second.) */
6132 (seconds
, milliseconds
))
6133 Lisp_Object seconds
, milliseconds
;
6137 if (NILP (milliseconds
))
6138 XSETINT (milliseconds
, 0);
6140 CHECK_NUMBER (milliseconds
, 1);
6141 usec
= XINT (milliseconds
) * 1000;
6144 double duration
= extract_float (seconds
);
6145 sec
= (int) duration
;
6146 usec
+= (duration
- sec
) * 1000000;
6149 #ifndef EMACS_HAS_USECS
6150 if (sec
== 0 && usec
!= 0)
6151 error ("millisecond `sleep-for' not supported on %s", SYSTEM_TYPE
);
6154 /* Assure that 0 <= usec < 1000000. */
6157 /* We can't rely on the rounding being correct if user is negative. */
6158 if (-1000000 < usec
)
6159 sec
--, usec
+= 1000000;
6161 sec
-= -usec
/ 1000000, usec
= 1000000 - (-usec
% 1000000);
6164 sec
+= usec
/ 1000000, usec
%= 1000000;
6166 if (sec
< 0 || (sec
== 0 && usec
== 0))
6172 XSETFASTINT (zero
, 0);
6173 wait_reading_process_input (sec
, usec
, zero
, 0);
6176 /* We should always have wait_reading_process_input; we have a dummy
6177 implementation for systems which don't support subprocesses. */
6179 /* No wait_reading_process_input */
6186 /* The reason this is done this way
6187 (rather than defined (H_S) && defined (H_T))
6188 is because the VMS preprocessor doesn't grok `defined' */
6190 EMACS_GET_TIME (end_time
);
6191 EMACS_SET_SECS_USECS (timeout
, sec
, usec
);
6192 EMACS_ADD_TIME (end_time
, end_time
, timeout
);
6196 EMACS_GET_TIME (timeout
);
6197 EMACS_SUB_TIME (timeout
, end_time
, timeout
);
6198 if (EMACS_TIME_NEG_P (timeout
)
6199 || !select (1, 0, 0, 0, &timeout
))
6202 #else /* not HAVE_SELECT */
6204 #endif /* HAVE_SELECT */
6205 #endif /* not VMS */
6208 #endif /* no subprocesses */
6214 /* This is just like wait_reading_process_input, except that
6215 it does the redisplay.
6217 It's also much like Fsit_for, except that it can be used for
6218 waiting for input as well. */
6221 sit_for (sec
, usec
, reading
, display
, initial_display
)
6222 int sec
, usec
, reading
, display
, initial_display
;
6224 Lisp_Object read_kbd
;
6226 swallow_events (display
);
6228 if (detect_input_pending_run_timers (display
))
6231 if (initial_display
)
6232 redisplay_preserve_echo_area (2);
6234 if (sec
== 0 && usec
== 0)
6241 XSETINT (read_kbd
, reading
? -1 : 1);
6242 wait_reading_process_input (sec
, usec
, read_kbd
, display
);
6244 return detect_input_pending () ? Qnil
: Qt
;
6248 DEFUN ("sit-for", Fsit_for
, Ssit_for
, 1, 3, 0,
6249 /* Perform redisplay, then wait for SECONDS seconds or until input is available.
6250 SECONDS may be a floating-point value, meaning that you can wait for a
6251 fraction of a second. Optional second arg MILLISECONDS specifies an
6252 additional wait period, in milliseconds; this may be useful if your
6253 Emacs was built without floating point support.
6254 \(Not all operating systems support waiting for a fraction of a second.)
6255 Optional third arg NODISP non-nil means don't redisplay, just wait for input.
6256 Redisplay is preempted as always if input arrives, and does not happen
6257 if input is available before it starts.
6258 Value is t if waited the full time with no input arriving. */
6259 (seconds
, milliseconds
, nodisp
))
6260 Lisp_Object seconds
, milliseconds
, nodisp
;
6264 if (NILP (milliseconds
))
6265 XSETINT (milliseconds
, 0);
6267 CHECK_NUMBER (milliseconds
, 1);
6268 usec
= XINT (milliseconds
) * 1000;
6271 double duration
= extract_float (seconds
);
6272 sec
= (int) duration
;
6273 usec
+= (duration
- sec
) * 1000000;
6276 #ifndef EMACS_HAS_USECS
6277 if (usec
!= 0 && sec
== 0)
6278 error ("millisecond `sit-for' not supported on %s", SYSTEM_TYPE
);
6281 return sit_for (sec
, usec
, 0, NILP (nodisp
), NILP (nodisp
));
6286 /***********************************************************************
6287 Other Lisp Functions
6288 ***********************************************************************/
6290 /* A vector of size >= 2 * NFRAMES + 3 * NBUFFERS + 1, containing the
6291 session's frames, frame names, buffers, buffer-read-only flags, and
6292 buffer-modified-flags, and a trailing sentinel (so we don't need to
6293 add length checks). */
6295 static Lisp_Object frame_and_buffer_state
;
6298 DEFUN ("frame-or-buffer-changed-p", Fframe_or_buffer_changed_p
,
6299 Sframe_or_buffer_changed_p
, 0, 0, 0,
6300 /* Return non-nil if the frame and buffer state appears to have changed.
6301 The state variable is an internal vector containing all frames and buffers,
6302 aside from buffers whose names start with space,
6303 along with the buffers' read-only and modified flags, which allows a fast
6304 check to see whether the menu bars might need to be recomputed.
6305 If this function returns non-nil, it updates the internal vector to reflect
6306 the current state. */
6309 Lisp_Object tail
, frame
, buf
;
6313 vecp
= XVECTOR (frame_and_buffer_state
)->contents
;
6314 FOR_EACH_FRAME (tail
, frame
)
6316 if (!EQ (*vecp
++, frame
))
6318 if (!EQ (*vecp
++, XFRAME (frame
)->name
))
6321 /* Check that the buffer info matches.
6322 No need to test for the end of the vector
6323 because the last element of the vector is lambda
6324 and that will always cause a mismatch. */
6325 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
6327 buf
= XCDR (XCAR (tail
));
6328 /* Ignore buffers that aren't included in buffer lists. */
6329 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
6331 if (!EQ (*vecp
++, buf
))
6333 if (!EQ (*vecp
++, XBUFFER (buf
)->read_only
))
6335 if (!EQ (*vecp
++, Fbuffer_modified_p (buf
)))
6338 /* Detect deletion of a buffer at the end of the list. */
6339 if (EQ (*vecp
, Qlambda
))
6342 /* Start with 1 so there is room for at least one lambda at the end. */
6344 FOR_EACH_FRAME (tail
, frame
)
6346 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
6348 /* Reallocate the vector if it's grown, or if it's shrunk a lot. */
6349 if (n
> XVECTOR (frame_and_buffer_state
)->size
6350 || n
+ 20 < XVECTOR (frame_and_buffer_state
)->size
/ 2)
6351 /* Add 20 extra so we grow it less often. */
6352 frame_and_buffer_state
= Fmake_vector (make_number (n
+ 20), Qlambda
);
6353 vecp
= XVECTOR (frame_and_buffer_state
)->contents
;
6354 FOR_EACH_FRAME (tail
, frame
)
6357 *vecp
++ = XFRAME (frame
)->name
;
6359 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
6361 buf
= XCDR (XCAR (tail
));
6362 /* Ignore buffers that aren't included in buffer lists. */
6363 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
6366 *vecp
++ = XBUFFER (buf
)->read_only
;
6367 *vecp
++ = Fbuffer_modified_p (buf
);
6369 /* Fill up the vector with lambdas (always at least one). */
6371 while (vecp
- XVECTOR (frame_and_buffer_state
)->contents
6372 < XVECTOR (frame_and_buffer_state
)->size
)
6374 /* Make sure we didn't overflow the vector. */
6375 if (vecp
- XVECTOR (frame_and_buffer_state
)->contents
6376 > XVECTOR (frame_and_buffer_state
)->size
)
6383 /***********************************************************************
6385 ***********************************************************************/
6387 char *terminal_type
;
6389 /* Initialization done when Emacs fork is started, before doing stty.
6390 Determine terminal type and set terminal_driver. Then invoke its
6391 decoding routine to set up variables in the terminal package. */
6396 #ifdef HAVE_X_WINDOWS
6397 extern int display_arg
;
6400 /* Construct the space glyph. */
6401 space_glyph
.type
= CHAR_GLYPH
;
6402 SET_CHAR_GLYPH_FROM_GLYPH (space_glyph
, ' ');
6403 space_glyph
.charpos
= -1;
6407 cursor_in_echo_area
= 0;
6408 terminal_type
= (char *) 0;
6410 /* Now is the time to initialize this; it's used by init_sys_modes
6412 Vwindow_system
= Qnil
;
6414 /* If the user wants to use a window system, we shouldn't bother
6415 initializing the terminal. This is especially important when the
6416 terminal is so dumb that emacs gives up before and doesn't bother
6417 using the window system.
6419 If the DISPLAY environment variable is set and nonempty,
6420 try to use X, and die with an error message if that doesn't work. */
6422 #ifdef HAVE_X_WINDOWS
6427 display
= getenv ("DECW$DISPLAY");
6429 display
= getenv ("DISPLAY");
6432 display_arg
= (display
!= 0 && *display
!= 0);
6435 if (!inhibit_window_system
&& display_arg
6441 Vwindow_system
= intern ("x");
6443 Vwindow_system_version
= make_number (11);
6445 Vwindow_system_version
= make_number (10);
6447 #if defined (LINUX) && defined (HAVE_LIBNCURSES)
6448 /* In some versions of ncurses,
6449 tputs crashes if we have not called tgetent.
6451 { char b
[2044]; tgetent (b
, "xterm");}
6453 adjust_frame_glyphs_initially ();
6456 #endif /* HAVE_X_WINDOWS */
6459 if (!inhibit_window_system
)
6461 Vwindow_system
= intern ("w32");
6462 Vwindow_system_version
= make_number (1);
6463 adjust_frame_glyphs_initially ();
6466 #endif /* HAVE_NTGUI */
6469 if (!inhibit_window_system
)
6471 Vwindow_system
= intern ("mac");
6472 Vwindow_system_version
= make_number (1);
6473 adjust_frame_glyphs_initially ();
6476 #endif /* macintosh */
6478 /* If no window system has been specified, try to use the terminal. */
6481 fatal ("standard input is not a tty");
6485 /* Look at the TERM variable */
6486 terminal_type
= (char *) getenv ("TERM");
6490 fprintf (stderr
, "Please specify your terminal type.\n\
6491 For types defined in VMS, use set term /device=TYPE.\n\
6492 For types not defined in VMS, use define emacs_term \"TYPE\".\n\
6493 \(The quotation marks are necessary since terminal types are lower case.)\n");
6495 fprintf (stderr
, "Please set the environment variable TERM; see tset(1).\n");
6501 /* VMS DCL tends to up-case things, so down-case term type.
6502 Hardly any uppercase letters in terminal types; should be none. */
6504 char *new = (char *) xmalloc (strlen (terminal_type
) + 1);
6507 strcpy (new, terminal_type
);
6509 for (p
= new; *p
; p
++)
6513 terminal_type
= new;
6517 term_init (terminal_type
);
6520 struct frame
*sf
= SELECTED_FRAME ();
6521 int width
= FRAME_WINDOW_WIDTH (sf
);
6522 int height
= FRAME_HEIGHT (sf
);
6524 unsigned int total_glyphs
= height
* (width
+ 2) * sizeof (struct glyph
);
6526 /* If these sizes are so big they cause overflow, just ignore the
6527 change. It's not clear what better we could do. */
6528 if (total_glyphs
/ sizeof (struct glyph
) / height
!= width
+ 2)
6529 fatal ("screen size %dx%d too big", width
, height
);
6532 adjust_frame_glyphs_initially ();
6533 calculate_costs (XFRAME (selected_frame
));
6538 #endif /* CANNOT_DUMP */
6539 signal (SIGWINCH
, window_change_signal
);
6540 #endif /* SIGWINCH */
6542 /* Set up faces of the initial terminal frame of a dumped Emacs. */
6546 /* The MSDOS terminal turns on its ``window system'' relatively
6547 late into the startup, so we cannot do the frame faces'
6548 initialization just yet. It will be done later by pc-win.el
6549 and internal_terminal_init. */
6550 && (strcmp (terminal_type
, "internal") != 0 || inhibit_window_system
)
6552 && NILP (Vwindow_system
))
6554 /* For the initial frame, we don't have any way of knowing what
6555 are the foreground and background colors of the terminal. */
6556 struct frame
*sf
= SELECTED_FRAME();
6558 FRAME_FOREGROUND_PIXEL (sf
) = FACE_TTY_DEFAULT_FG_COLOR
;
6559 FRAME_BACKGROUND_PIXEL (sf
) = FACE_TTY_DEFAULT_BG_COLOR
;
6560 call0 (intern ("tty-set-up-initial-frame-faces"));
6566 /***********************************************************************
6568 ***********************************************************************/
6570 DEFUN ("internal-show-cursor", Finternal_show_cursor
,
6571 Sinternal_show_cursor
, 2, 2, 0,
6572 /* Set the cursor-visibility flag of WINDOW to SHOW.
6573 WINDOW nil means use the selected window. SHOW non-nil means
6574 show a cursor in WINDOW in the next redisplay. SHOW nil means
6575 don't show a cursor. */
6577 Lisp_Object window
, show
;
6579 /* Don't change cursor state while redisplaying. This could confuse
6581 if (!redisplaying_p
)
6584 window
= selected_window
;
6586 CHECK_WINDOW (window
, 2);
6588 XWINDOW (window
)->cursor_off_p
= NILP (show
);
6595 DEFUN ("internal-show-cursor-p", Finternal_show_cursor_p
,
6596 Sinternal_show_cursor_p
, 0, 1, 0,
6597 /* Value is non-nil if next redisplay will display a cursor in WINDOW.
6598 WINDOW nil or omitted means report on the selected window. */
6605 window
= selected_window
;
6607 CHECK_WINDOW (window
, 2);
6609 w
= XWINDOW (window
);
6610 return w
->cursor_off_p
? Qnil
: Qt
;
6614 /***********************************************************************
6616 ***********************************************************************/
6621 defsubr (&Sredraw_frame
);
6622 defsubr (&Sredraw_display
);
6623 defsubr (&Sframe_or_buffer_changed_p
);
6624 defsubr (&Sopen_termscript
);
6626 defsubr (&Ssit_for
);
6627 defsubr (&Ssleep_for
);
6628 defsubr (&Ssend_string_to_terminal
);
6629 defsubr (&Sinternal_show_cursor
);
6630 defsubr (&Sinternal_show_cursor_p
);
6633 defsubr (&Sdump_redisplay_history
);
6636 frame_and_buffer_state
= Fmake_vector (make_number (20), Qlambda
);
6637 staticpro (&frame_and_buffer_state
);
6639 Qdisplay_table
= intern ("display-table");
6640 staticpro (&Qdisplay_table
);
6641 Qredisplay_dont_pause
= intern ("redisplay-dont-pause");
6642 staticpro (&Qredisplay_dont_pause
);
6644 DEFVAR_INT ("baud-rate", &baud_rate
6645 /* *The output baud rate of the terminal.
6646 On most systems, changing this value will affect the amount of padding
6647 and the other strategic decisions made during redisplay. */);
6649 DEFVAR_BOOL ("inverse-video", &inverse_video
6650 /* *Non-nil means invert the entire frame display.
6651 This means everything is in inverse video which otherwise would not be. */);
6653 DEFVAR_BOOL ("visible-bell", &visible_bell
6654 /* *Non-nil means try to flash the frame to represent a bell. */);
6656 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter
6657 /* *Non-nil means no need to redraw entire frame after suspending.
6658 A non-nil value is useful if the terminal can automatically preserve
6659 Emacs's frame display when you reenter Emacs.
6660 It is up to you to set this variable if your terminal can do that. */);
6662 DEFVAR_LISP ("window-system", &Vwindow_system
6663 /* A symbol naming the window-system under which Emacs is running
6664 \(such as `x'), or nil if emacs is running on an ordinary terminal. */);
6666 DEFVAR_LISP ("window-system-version", &Vwindow_system_version
6667 /* The version number of the window system in use.
6668 For X windows, this is 10 or 11. */);
6670 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area
6671 /* Non-nil means put cursor in minibuffer, at end of any message there. */);
6673 DEFVAR_LISP ("glyph-table", &Vglyph_table
6674 /* Table defining how to output a glyph code to the frame.
6675 If not nil, this is a vector indexed by glyph code to define the glyph.
6676 Each element can be:
6677 integer: a glyph code which this glyph is an alias for.
6678 string: output this glyph using that string (not impl. in X windows).
6679 nil: this glyph mod 524288 is the code of a character to output,
6680 and this glyph / 524288 is the face number (see `face-id') to use
6681 while outputting it. */);
6682 Vglyph_table
= Qnil
;
6684 DEFVAR_LISP ("standard-display-table", &Vstandard_display_table
6685 /* Display table to use for buffers that specify none.
6686 See `buffer-display-table' for more information. */);
6687 Vstandard_display_table
= Qnil
;
6689 DEFVAR_BOOL ("redisplay-dont-pause", &redisplay_dont_pause
6690 /* *Non-nil means update isn't paused when input is detected. */);
6691 redisplay_dont_pause
= 0;
6693 /* Initialize `window-system', unless init_display already decided it. */
6698 Vwindow_system
= Qnil
;
6699 Vwindow_system_version
= Qnil
;