1 /* Updating of data structures for redisplay.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
34 /* cm.h must come after dispextern.h on Windows. */
35 #include "dispextern.h"
38 #include "character.h"
41 #include "termhooks.h"
46 #include "intervals.h"
47 #include "blockinput.h"
50 #include "syssignal.h"
54 #endif /* HAVE_X_WINDOWS */
58 #endif /* HAVE_NTGUI */
64 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
69 /* Get number of chars of output now in the buffer of a stdio stream.
70 This ought to be built in in stdio, but it isn't. Some s- files
71 override this because their stdio internals differ. */
73 #ifdef __GNU_LIBRARY__
75 /* The s- file might have overridden the definition with one that
76 works for the system's C library. But we are using the GNU C
77 library, so this is the right definition for every system. */
79 #ifdef GNU_LIBRARY_PENDING_OUTPUT_COUNT
80 #define PENDING_OUTPUT_COUNT GNU_LIBRARY_PENDING_OUTPUT_COUNT
82 #undef PENDING_OUTPUT_COUNT
83 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
85 #else /* not __GNU_LIBRARY__ */
86 #if !defined (PENDING_OUTPUT_COUNT) && HAVE_STDIO_EXT_H && HAVE___FPENDING
87 #include <stdio_ext.h>
88 #define PENDING_OUTPUT_COUNT(FILE) __fpending (FILE)
90 #ifndef PENDING_OUTPUT_COUNT
91 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
93 #endif /* not __GNU_LIBRARY__ */
95 #if defined(HAVE_TERM_H) && defined (GNU_LINUX) && defined (HAVE_LIBNCURSES)
96 #include <term.h> /* for tgetent */
99 /* Structure to pass dimensions around. Used for character bounding
100 boxes, glyph matrix dimensions and alike. */
109 /* Function prototypes. */
111 static struct glyph_matrix
*save_current_matrix (struct frame
*);
112 static void restore_current_matrix (struct frame
*, struct glyph_matrix
*);
113 static int showing_window_margins_p (struct window
*);
114 static void fake_current_matrices (Lisp_Object
);
115 static void redraw_overlapping_rows (struct window
*, int);
116 static void redraw_overlapped_rows (struct window
*, int);
117 static int count_blanks (struct glyph
*, int);
118 static int count_match (struct glyph
*, struct glyph
*,
119 struct glyph
*, struct glyph
*);
120 static unsigned line_draw_cost (struct glyph_matrix
*, int);
121 static void update_frame_line (struct frame
*, int);
122 static struct dim allocate_matrices_for_frame_redisplay
123 (Lisp_Object
, int, int, int, int *);
124 static void allocate_matrices_for_window_redisplay (struct window
*);
125 static int realloc_glyph_pool (struct glyph_pool
*, struct dim
);
126 static void adjust_frame_glyphs (struct frame
*);
127 struct glyph_matrix
*new_glyph_matrix (struct glyph_pool
*);
128 static void free_glyph_matrix (struct glyph_matrix
*);
129 static void adjust_glyph_matrix (struct window
*, struct glyph_matrix
*,
130 int, int, struct dim
);
131 static void change_frame_size_1 (struct frame
*, int, int, int, int, int);
132 static void swap_glyph_pointers (struct glyph_row
*, struct glyph_row
*);
134 static int glyph_row_slice_p (struct glyph_row
*, struct glyph_row
*);
136 static void fill_up_frame_row_with_spaces (struct glyph_row
*, int);
137 static void build_frame_matrix_from_window_tree (struct glyph_matrix
*,
139 static void build_frame_matrix_from_leaf_window (struct glyph_matrix
*,
141 static struct glyph_pool
*new_glyph_pool (void);
142 static void free_glyph_pool (struct glyph_pool
*);
143 static void adjust_frame_glyphs_initially (void);
144 static void adjust_frame_message_buffer (struct frame
*);
145 static void adjust_decode_mode_spec_buffer (struct frame
*);
146 static void fill_up_glyph_row_with_spaces (struct glyph_row
*);
147 static void build_frame_matrix (struct frame
*);
148 void clear_current_matrices (struct frame
*);
149 void scroll_glyph_matrix_range (struct glyph_matrix
*, int, int,
151 static void clear_window_matrices (struct window
*, int);
152 static void fill_up_glyph_row_area_with_spaces (struct glyph_row
*, int);
153 static int scrolling_window (struct window
*, int);
154 static int update_window_line (struct window
*, int, int *);
155 static void update_marginal_area (struct window
*, int, int);
156 static int update_text_area (struct window
*, int);
157 static void make_current (struct glyph_matrix
*, struct glyph_matrix
*,
159 static void mirror_make_current (struct window
*, int);
160 void check_window_matrix_pointers (struct window
*);
162 static void check_matrix_pointers (struct glyph_matrix
*,
163 struct glyph_matrix
*);
165 static void mirror_line_dance (struct window
*, int, int, int *, char *);
166 static int update_window_tree (struct window
*, int);
167 static int update_window (struct window
*, int);
168 static int update_frame_1 (struct frame
*, int, int);
169 static void set_window_cursor_after_update (struct window
*);
170 static int row_equal_p (struct window
*, struct glyph_row
*,
171 struct glyph_row
*, int);
172 static void adjust_frame_glyphs_for_window_redisplay (struct frame
*);
173 static void adjust_frame_glyphs_for_frame_redisplay (struct frame
*);
174 static void reverse_rows (struct glyph_matrix
*, int, int);
175 static int margin_glyphs_to_reserve (struct window
*, int, Lisp_Object
);
176 static void sync_window_with_frame_matrix_rows (struct window
*);
177 struct window
*frame_row_to_window (struct window
*, int);
180 /* Non-zero means don't pause redisplay for pending input. (This is
181 for debugging and for a future implementation of EDT-like
184 int redisplay_dont_pause
;
186 /* Define PERIODIC_PREEMPTION_CHECKING to 1, if micro-second timers
187 are supported, so we can check for input during redisplay at
188 regular intervals. */
189 #ifdef EMACS_HAS_USECS
190 #define PERIODIC_PREEMPTION_CHECKING 1
192 #define PERIODIC_PREEMPTION_CHECKING 0
195 #if PERIODIC_PREEMPTION_CHECKING
197 /* If a number (float), check for user input every N seconds. */
199 Lisp_Object Vredisplay_preemption_period
;
201 /* Redisplay preemption timers. */
203 static EMACS_TIME preemption_period
;
204 static EMACS_TIME preemption_next_check
;
208 /* Nonzero upon entry to redisplay means do not assume anything about
209 current contents of actual terminal frame; clear and redraw it. */
213 /* Nonzero means last display completed. Zero means it was preempted. */
215 int display_completed
;
217 /* Lisp variable visible-bell; enables use of screen-flash instead of
222 /* Invert the color of the whole frame, at a low level. */
226 /* Line speed of the terminal. */
230 /* Either nil or a symbol naming the window system under which Emacs
231 creates the first frame. */
233 Lisp_Object Vinitial_window_system
;
235 /* Version number of X windows: 10, 11 or nil. */
237 Lisp_Object Vwindow_system_version
;
239 /* Vector of glyph definitions. Indexed by glyph number, the contents
240 are a string which is how to output the glyph.
242 If Vglyph_table is nil, a glyph is output by using its low 8 bits
245 This is an obsolete feature that is no longer used. The variable
246 is retained for compatibility. */
248 Lisp_Object Vglyph_table
;
250 /* Display table to use for vectors that don't specify their own. */
252 Lisp_Object Vstandard_display_table
;
254 /* Nonzero means reading single-character input with prompt so put
255 cursor on mini-buffer after the prompt. Positive means at end of
256 text in echo area; negative means at beginning of line. */
258 int cursor_in_echo_area
;
260 Lisp_Object Qdisplay_table
, Qredisplay_dont_pause
;
263 /* The currently selected frame. In a single-frame version, this
264 variable always equals the_only_frame. */
266 Lisp_Object selected_frame
;
268 /* A frame which is not just a mini-buffer, or 0 if there are no such
269 frames. This is usually the most recent such frame that was
270 selected. In a single-frame version, this variable always holds
271 the address of the_only_frame. */
273 struct frame
*last_nonminibuf_frame
;
275 /* 1 means SIGWINCH happened when not safe. */
277 int delayed_size_change
;
279 /* 1 means glyph initialization has been completed at startup. */
281 static int glyphs_initialized_initially_p
;
283 /* Updated window if != 0. Set by update_window. */
285 struct window
*updated_window
;
287 /* Glyph row updated in update_window_line, and area that is updated. */
289 struct glyph_row
*updated_row
;
292 /* A glyph for a space. */
294 struct glyph space_glyph
;
296 /* Counts of allocated structures. These counts serve to diagnose
297 memory leaks and double frees. */
299 int glyph_matrix_count
;
300 int glyph_pool_count
;
302 /* If non-null, the frame whose frame matrices are manipulated. If
303 null, window matrices are worked on. */
305 static struct frame
*frame_matrix_frame
;
307 /* Non-zero means that fonts have been loaded since the last glyph
308 matrix adjustments. Redisplay must stop, and glyph matrices must
309 be adjusted when this flag becomes non-zero during display. The
310 reason fonts can be loaded so late is that fonts of fontsets are
311 loaded on demand. Another reason is that a line contains many
312 characters displayed by zero width or very narrow glyphs of
313 variable-width fonts. */
317 /* Convert vpos and hpos from frame to window and vice versa.
318 This may only be used for terminal frames. */
322 static int window_to_frame_vpos (struct window
*, int);
323 static int window_to_frame_hpos (struct window
*, int);
324 #define WINDOW_TO_FRAME_VPOS(W, VPOS) window_to_frame_vpos ((W), (VPOS))
325 #define WINDOW_TO_FRAME_HPOS(W, HPOS) window_to_frame_hpos ((W), (HPOS))
327 /* One element of the ring buffer containing redisplay history
330 struct redisplay_history
332 char trace
[512 + 100];
335 /* The size of the history buffer. */
337 #define REDISPLAY_HISTORY_SIZE 30
339 /* The redisplay history buffer. */
341 static struct redisplay_history redisplay_history
[REDISPLAY_HISTORY_SIZE
];
343 /* Next free entry in redisplay_history. */
345 static int history_idx
;
347 /* A tick that's incremented each time something is added to the
350 static unsigned history_tick
;
352 static void add_frame_display_history (struct frame
*, int);
353 static void add_window_display_history (struct window
*, char *, int);
355 /* Add to the redisplay history how window W has been displayed.
356 MSG is a trace containing the information how W's glyph matrix
357 has been constructed. PAUSED_P non-zero means that the update
358 has been interrupted for pending input. */
361 add_window_display_history (struct window
*w
, char *msg
, int paused_p
)
365 if (history_idx
>= REDISPLAY_HISTORY_SIZE
)
367 buf
= redisplay_history
[history_idx
].trace
;
370 sprintf (buf
, "%d: window %p (`%s')%s\n",
373 ((BUFFERP (w
->buffer
)
374 && STRINGP (XBUFFER (w
->buffer
)->name
))
375 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
377 paused_p
? " ***paused***" : "");
382 /* Add to the redisplay history that frame F has been displayed.
383 PAUSED_P non-zero means that the update has been interrupted for
387 add_frame_display_history (struct frame
*f
, int paused_p
)
391 if (history_idx
>= REDISPLAY_HISTORY_SIZE
)
393 buf
= redisplay_history
[history_idx
].trace
;
396 sprintf (buf
, "%d: update frame %p%s",
398 f
, paused_p
? " ***paused***" : "");
402 DEFUN ("dump-redisplay-history", Fdump_redisplay_history
,
403 Sdump_redisplay_history
, 0, 0, "",
404 doc
: /* Dump redisplay history to stderr. */)
409 for (i
= history_idx
- 1; i
!= history_idx
; --i
)
412 i
= REDISPLAY_HISTORY_SIZE
- 1;
413 fprintf (stderr
, "%s\n", redisplay_history
[i
].trace
);
420 #else /* GLYPH_DEBUG == 0 */
422 #define WINDOW_TO_FRAME_VPOS(W, VPOS) ((VPOS) + WINDOW_TOP_EDGE_LINE (W))
423 #define WINDOW_TO_FRAME_HPOS(W, HPOS) ((HPOS) + WINDOW_LEFT_EDGE_COL (W))
425 #endif /* GLYPH_DEBUG == 0 */
428 #if defined PROFILING && !HAVE___EXECUTABLE_START
429 /* FIXME: only used to find text start for profiling. */
432 safe_bcopy (const char *from
, char *to
, int size
)
438 /***********************************************************************
440 ***********************************************************************/
442 /* Allocate and return a glyph_matrix structure. POOL is the glyph
443 pool from which memory for the matrix should be allocated, or null
444 for window-based redisplay where no glyph pools are used. The
445 member `pool' of the glyph matrix structure returned is set to
446 POOL, the structure is otherwise zeroed. */
448 struct glyph_matrix
*
449 new_glyph_matrix (struct glyph_pool
*pool
)
451 struct glyph_matrix
*result
;
453 /* Allocate and clear. */
454 result
= (struct glyph_matrix
*) xmalloc (sizeof *result
);
455 memset (result
, 0, sizeof *result
);
457 /* Increment number of allocated matrices. This count is used
458 to detect memory leaks. */
459 ++glyph_matrix_count
;
461 /* Set pool and return. */
467 /* Free glyph matrix MATRIX. Passing in a null MATRIX is allowed.
469 The global counter glyph_matrix_count is decremented when a matrix
470 is freed. If the count gets negative, more structures were freed
471 than allocated, i.e. one matrix was freed more than once or a bogus
472 pointer was passed to this function.
474 If MATRIX->pool is null, this means that the matrix manages its own
475 glyph memory---this is done for matrices on X frames. Freeing the
476 matrix also frees the glyph memory in this case. */
479 free_glyph_matrix (struct glyph_matrix
*matrix
)
485 /* Detect the case that more matrices are freed than were
487 if (--glyph_matrix_count
< 0)
490 /* Free glyph memory if MATRIX owns it. */
491 if (matrix
->pool
== NULL
)
492 for (i
= 0; i
< matrix
->rows_allocated
; ++i
)
493 xfree (matrix
->rows
[i
].glyphs
[LEFT_MARGIN_AREA
]);
495 /* Free row structures and the matrix itself. */
496 xfree (matrix
->rows
);
502 /* Return the number of glyphs to reserve for a marginal area of
503 window W. TOTAL_GLYPHS is the number of glyphs in a complete
504 display line of window W. MARGIN gives the width of the marginal
505 area in canonical character units. MARGIN should be an integer
509 margin_glyphs_to_reserve (struct window
*w
, int total_glyphs
, Lisp_Object margin
)
513 if (NUMBERP (margin
))
515 int width
= XFASTINT (w
->total_cols
);
516 double d
= max (0, XFLOATINT (margin
));
517 d
= min (width
/ 2 - 1, d
);
518 n
= (int) ((double) total_glyphs
/ width
* d
);
527 /* Adjust glyph matrix MATRIX on window W or on a frame to changed
530 W is null if the function is called for a frame glyph matrix.
531 Otherwise it is the window MATRIX is a member of. X and Y are the
532 indices of the first column and row of MATRIX within the frame
533 matrix, if such a matrix exists. They are zero for purely
534 window-based redisplay. DIM is the needed size of the matrix.
536 In window-based redisplay, where no frame matrices exist, glyph
537 matrices manage their own glyph storage. Otherwise, they allocate
538 storage from a common frame glyph pool which can be found in
541 The reason for this memory management strategy is to avoid complete
542 frame redraws if possible. When we allocate from a common pool, a
543 change of the location or size of a sub-matrix within the pool
544 requires a complete redisplay of the frame because we cannot easily
545 make sure that the current matrices of all windows still agree with
546 what is displayed on the screen. While this is usually fast, it
547 leads to screen flickering. */
550 adjust_glyph_matrix (struct window
*w
, struct glyph_matrix
*matrix
, int x
, int y
, struct dim dim
)
554 int marginal_areas_changed_p
= 0;
555 int header_line_changed_p
= 0;
556 int header_line_p
= 0;
557 int left
= -1, right
= -1;
558 int window_width
= -1, window_height
= -1;
560 /* See if W had a header line that has disappeared now, or vice versa.
564 window_box (w
, -1, 0, 0, &window_width
, &window_height
);
566 header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
567 header_line_changed_p
= header_line_p
!= matrix
->header_line_p
;
569 matrix
->header_line_p
= header_line_p
;
571 /* If POOL is null, MATRIX is a window matrix for window-based redisplay.
572 Do nothing if MATRIX' size, position, vscroll, and marginal areas
573 haven't changed. This optimization is important because preserving
574 the matrix means preventing redisplay. */
575 if (matrix
->pool
== NULL
)
577 left
= margin_glyphs_to_reserve (w
, dim
.width
, w
->left_margin_cols
);
578 right
= margin_glyphs_to_reserve (w
, dim
.width
, w
->right_margin_cols
);
579 xassert (left
>= 0 && right
>= 0);
580 marginal_areas_changed_p
= (left
!= matrix
->left_margin_glyphs
581 || right
!= matrix
->right_margin_glyphs
);
583 if (!marginal_areas_changed_p
585 && !header_line_changed_p
586 && matrix
->window_left_col
== WINDOW_LEFT_EDGE_COL (w
)
587 && matrix
->window_top_line
== WINDOW_TOP_EDGE_LINE (w
)
588 && matrix
->window_height
== window_height
589 && matrix
->window_vscroll
== w
->vscroll
590 && matrix
->window_width
== window_width
)
594 /* Enlarge MATRIX->rows if necessary. New rows are cleared. */
595 if (matrix
->rows_allocated
< dim
.height
)
597 int size
= dim
.height
* sizeof (struct glyph_row
);
598 new_rows
= dim
.height
- matrix
->rows_allocated
;
599 matrix
->rows
= (struct glyph_row
*) xrealloc (matrix
->rows
, size
);
600 memset (matrix
->rows
+ matrix
->rows_allocated
, 0,
601 new_rows
* sizeof *matrix
->rows
);
602 matrix
->rows_allocated
= dim
.height
;
607 /* If POOL is not null, MATRIX is a frame matrix or a window matrix
608 on a frame not using window-based redisplay. Set up pointers for
609 each row into the glyph pool. */
612 xassert (matrix
->pool
->glyphs
);
616 left
= margin_glyphs_to_reserve (w
, dim
.width
,
617 w
->left_margin_cols
);
618 right
= margin_glyphs_to_reserve (w
, dim
.width
,
619 w
->right_margin_cols
);
624 for (i
= 0; i
< dim
.height
; ++i
)
626 struct glyph_row
*row
= &matrix
->rows
[i
];
628 row
->glyphs
[LEFT_MARGIN_AREA
]
629 = (matrix
->pool
->glyphs
630 + (y
+ i
) * matrix
->pool
->ncolumns
634 || row
== matrix
->rows
+ dim
.height
- 1
635 || (row
== matrix
->rows
&& matrix
->header_line_p
))
637 row
->glyphs
[TEXT_AREA
]
638 = row
->glyphs
[LEFT_MARGIN_AREA
];
639 row
->glyphs
[RIGHT_MARGIN_AREA
]
640 = row
->glyphs
[TEXT_AREA
] + dim
.width
;
641 row
->glyphs
[LAST_AREA
]
642 = row
->glyphs
[RIGHT_MARGIN_AREA
];
646 row
->glyphs
[TEXT_AREA
]
647 = row
->glyphs
[LEFT_MARGIN_AREA
] + left
;
648 row
->glyphs
[RIGHT_MARGIN_AREA
]
649 = row
->glyphs
[TEXT_AREA
] + dim
.width
- left
- right
;
650 row
->glyphs
[LAST_AREA
]
651 = row
->glyphs
[LEFT_MARGIN_AREA
] + dim
.width
;
655 matrix
->left_margin_glyphs
= left
;
656 matrix
->right_margin_glyphs
= right
;
660 /* If MATRIX->pool is null, MATRIX is responsible for managing
661 its own memory. It is a window matrix for window-based redisplay.
662 Allocate glyph memory from the heap. */
663 if (dim
.width
> matrix
->matrix_w
665 || header_line_changed_p
666 || marginal_areas_changed_p
)
668 struct glyph_row
*row
= matrix
->rows
;
669 struct glyph_row
*end
= row
+ matrix
->rows_allocated
;
673 row
->glyphs
[LEFT_MARGIN_AREA
]
674 = (struct glyph
*) xrealloc (row
->glyphs
[LEFT_MARGIN_AREA
],
676 * sizeof (struct glyph
)));
678 /* The mode line never has marginal areas. */
679 if (row
== matrix
->rows
+ dim
.height
- 1
680 || (row
== matrix
->rows
&& matrix
->header_line_p
))
682 row
->glyphs
[TEXT_AREA
]
683 = row
->glyphs
[LEFT_MARGIN_AREA
];
684 row
->glyphs
[RIGHT_MARGIN_AREA
]
685 = row
->glyphs
[TEXT_AREA
] + dim
.width
;
686 row
->glyphs
[LAST_AREA
]
687 = row
->glyphs
[RIGHT_MARGIN_AREA
];
691 row
->glyphs
[TEXT_AREA
]
692 = row
->glyphs
[LEFT_MARGIN_AREA
] + left
;
693 row
->glyphs
[RIGHT_MARGIN_AREA
]
694 = row
->glyphs
[TEXT_AREA
] + dim
.width
- left
- right
;
695 row
->glyphs
[LAST_AREA
]
696 = row
->glyphs
[LEFT_MARGIN_AREA
] + dim
.width
;
702 xassert (left
>= 0 && right
>= 0);
703 matrix
->left_margin_glyphs
= left
;
704 matrix
->right_margin_glyphs
= right
;
707 /* Number of rows to be used by MATRIX. */
708 matrix
->nrows
= dim
.height
;
709 xassert (matrix
->nrows
>= 0);
713 if (matrix
== w
->current_matrix
)
715 /* Mark rows in a current matrix of a window as not having
716 valid contents. It's important to not do this for
717 desired matrices. When Emacs starts, it may already be
718 building desired matrices when this function runs. */
719 if (window_width
< 0)
720 window_width
= window_box_width (w
, -1);
722 /* Optimize the case that only the height has changed (C-x 2,
723 upper window). Invalidate all rows that are no longer part
725 if (!marginal_areas_changed_p
726 && !header_line_changed_p
728 && dim
.width
== matrix
->matrix_w
729 && matrix
->window_left_col
== WINDOW_LEFT_EDGE_COL (w
)
730 && matrix
->window_top_line
== WINDOW_TOP_EDGE_LINE (w
)
731 && matrix
->window_width
== window_width
)
733 /* Find the last row in the window. */
734 for (i
= 0; i
< matrix
->nrows
&& matrix
->rows
[i
].enabled_p
; ++i
)
735 if (MATRIX_ROW_BOTTOM_Y (matrix
->rows
+ i
) >= window_height
)
741 /* Window end is invalid, if inside of the rows that
742 are invalidated below. */
743 if (INTEGERP (w
->window_end_vpos
)
744 && XFASTINT (w
->window_end_vpos
) >= i
)
745 w
->window_end_valid
= Qnil
;
747 while (i
< matrix
->nrows
)
748 matrix
->rows
[i
++].enabled_p
= 0;
752 for (i
= 0; i
< matrix
->nrows
; ++i
)
753 matrix
->rows
[i
].enabled_p
= 0;
756 else if (matrix
== w
->desired_matrix
)
758 /* Rows in desired matrices always have to be cleared;
759 redisplay expects this is the case when it runs, so it
760 had better be the case when we adjust matrices between
762 for (i
= 0; i
< matrix
->nrows
; ++i
)
763 matrix
->rows
[i
].enabled_p
= 0;
768 /* Remember last values to be able to optimize frame redraws. */
769 matrix
->matrix_x
= x
;
770 matrix
->matrix_y
= y
;
771 matrix
->matrix_w
= dim
.width
;
772 matrix
->matrix_h
= dim
.height
;
774 /* Record the top y location and height of W at the time the matrix
775 was last adjusted. This is used to optimize redisplay above. */
778 matrix
->window_left_col
= WINDOW_LEFT_EDGE_COL (w
);
779 matrix
->window_top_line
= WINDOW_TOP_EDGE_LINE (w
);
780 matrix
->window_height
= window_height
;
781 matrix
->window_width
= window_width
;
782 matrix
->window_vscroll
= w
->vscroll
;
787 /* Reverse the contents of rows in MATRIX between START and END. The
788 contents of the row at END - 1 end up at START, END - 2 at START +
789 1 etc. This is part of the implementation of rotate_matrix (see
793 reverse_rows (struct glyph_matrix
*matrix
, int start
, int end
)
797 for (i
= start
, j
= end
- 1; i
< j
; ++i
, --j
)
799 /* Non-ISO HP/UX compiler doesn't like auto struct
801 struct glyph_row temp
;
802 temp
= matrix
->rows
[i
];
803 matrix
->rows
[i
] = matrix
->rows
[j
];
804 matrix
->rows
[j
] = temp
;
809 /* Rotate the contents of rows in MATRIX in the range FIRST .. LAST -
810 1 by BY positions. BY < 0 means rotate left, i.e. towards lower
811 indices. (Note: this does not copy glyphs, only glyph pointers in
812 row structures are moved around).
814 The algorithm used for rotating the vector was, I believe, first
815 described by Kernighan. See the vector R as consisting of two
816 sub-vectors AB, where A has length BY for BY >= 0. The result
817 after rotating is then BA. Reverse both sub-vectors to get ArBr
818 and reverse the result to get (ArBr)r which is BA. Similar for
822 rotate_matrix (struct glyph_matrix
*matrix
, int first
, int last
, int by
)
826 /* Up (rotate left, i.e. towards lower indices). */
828 reverse_rows (matrix
, first
, first
+ by
);
829 reverse_rows (matrix
, first
+ by
, last
);
830 reverse_rows (matrix
, first
, last
);
834 /* Down (rotate right, i.e. towards higher indices). */
835 reverse_rows (matrix
, last
- by
, last
);
836 reverse_rows (matrix
, first
, last
- by
);
837 reverse_rows (matrix
, first
, last
);
842 /* Increment buffer positions in glyph rows of MATRIX. Do it for rows
843 with indices START <= index < END. Increment positions by DELTA/
847 increment_matrix_positions (struct glyph_matrix
*matrix
, int start
, int end
,
848 EMACS_INT delta
, EMACS_INT delta_bytes
)
850 /* Check that START and END are reasonable values. */
851 xassert (start
>= 0 && start
<= matrix
->nrows
);
852 xassert (end
>= 0 && end
<= matrix
->nrows
);
853 xassert (start
<= end
);
855 for (; start
< end
; ++start
)
856 increment_row_positions (matrix
->rows
+ start
, delta
, delta_bytes
);
860 /* Enable a range of rows in glyph matrix MATRIX. START and END are
861 the row indices of the first and last + 1 row to enable. If
862 ENABLED_P is non-zero, enabled_p flags in rows will be set to 1. */
865 enable_glyph_matrix_rows (struct glyph_matrix
*matrix
, int start
, int end
, int enabled_p
)
867 xassert (start
<= end
);
868 xassert (start
>= 0 && start
< matrix
->nrows
);
869 xassert (end
>= 0 && end
<= matrix
->nrows
);
871 for (; start
< end
; ++start
)
872 matrix
->rows
[start
].enabled_p
= enabled_p
!= 0;
878 This empties all rows in MATRIX by setting the enabled_p flag for
879 all rows of the matrix to zero. The function prepare_desired_row
880 will eventually really clear a row when it sees one with a zero
883 Resets update hints to defaults value. The only update hint
884 currently present is the flag MATRIX->no_scrolling_p. */
887 clear_glyph_matrix (struct glyph_matrix
*matrix
)
891 enable_glyph_matrix_rows (matrix
, 0, matrix
->nrows
, 0);
892 matrix
->no_scrolling_p
= 0;
897 /* Shift part of the glyph matrix MATRIX of window W up or down.
898 Increment y-positions in glyph rows between START and END by DY,
899 and recompute their visible height. */
902 shift_glyph_matrix (struct window
*w
, struct glyph_matrix
*matrix
, int start
, int end
, int dy
)
906 xassert (start
<= end
);
907 xassert (start
>= 0 && start
< matrix
->nrows
);
908 xassert (end
>= 0 && end
<= matrix
->nrows
);
910 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
911 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
);
913 for (; start
< end
; ++start
)
915 struct glyph_row
*row
= &matrix
->rows
[start
];
918 row
->visible_height
= row
->height
;
921 row
->visible_height
-= min_y
- row
->y
;
922 if (row
->y
+ row
->height
> max_y
)
923 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
928 /* Mark all rows in current matrices of frame F as invalid. Marking
929 invalid is done by setting enabled_p to zero for all rows in a
933 clear_current_matrices (register struct frame
*f
)
935 /* Clear frame current matrix, if we have one. */
936 if (f
->current_matrix
)
937 clear_glyph_matrix (f
->current_matrix
);
939 /* Clear the matrix of the menu bar window, if such a window exists.
940 The menu bar window is currently used to display menus on X when
941 no toolkit support is compiled in. */
942 if (WINDOWP (f
->menu_bar_window
))
943 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
945 /* Clear the matrix of the tool-bar window, if any. */
946 if (WINDOWP (f
->tool_bar_window
))
947 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
949 /* Clear current window matrices. */
950 xassert (WINDOWP (FRAME_ROOT_WINDOW (f
)));
951 clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)), 0);
955 /* Clear out all display lines of F for a coming redisplay. */
958 clear_desired_matrices (register struct frame
*f
)
960 if (f
->desired_matrix
)
961 clear_glyph_matrix (f
->desired_matrix
);
963 if (WINDOWP (f
->menu_bar_window
))
964 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->desired_matrix
);
966 if (WINDOWP (f
->tool_bar_window
))
967 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->desired_matrix
);
969 /* Do it for window matrices. */
970 xassert (WINDOWP (FRAME_ROOT_WINDOW (f
)));
971 clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)), 1);
975 /* Clear matrices in window tree rooted in W. If DESIRED_P is
976 non-zero clear desired matrices, otherwise clear current matrices. */
979 clear_window_matrices (struct window
*w
, int desired_p
)
983 if (!NILP (w
->hchild
))
985 xassert (WINDOWP (w
->hchild
));
986 clear_window_matrices (XWINDOW (w
->hchild
), desired_p
);
988 else if (!NILP (w
->vchild
))
990 xassert (WINDOWP (w
->vchild
));
991 clear_window_matrices (XWINDOW (w
->vchild
), desired_p
);
996 clear_glyph_matrix (w
->desired_matrix
);
999 clear_glyph_matrix (w
->current_matrix
);
1000 w
->window_end_valid
= Qnil
;
1004 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
1010 /***********************************************************************
1013 See dispextern.h for an overall explanation of glyph rows.
1014 ***********************************************************************/
1016 /* Clear glyph row ROW. Do it in a way that makes it robust against
1017 changes in the glyph_row structure, i.e. addition or removal of
1018 structure members. */
1020 static struct glyph_row null_row
;
1023 clear_glyph_row (struct glyph_row
*row
)
1025 struct glyph
*p
[1 + LAST_AREA
];
1027 /* Save pointers. */
1028 p
[LEFT_MARGIN_AREA
] = row
->glyphs
[LEFT_MARGIN_AREA
];
1029 p
[TEXT_AREA
] = row
->glyphs
[TEXT_AREA
];
1030 p
[RIGHT_MARGIN_AREA
] = row
->glyphs
[RIGHT_MARGIN_AREA
];
1031 p
[LAST_AREA
] = row
->glyphs
[LAST_AREA
];
1036 /* Restore pointers. */
1037 row
->glyphs
[LEFT_MARGIN_AREA
] = p
[LEFT_MARGIN_AREA
];
1038 row
->glyphs
[TEXT_AREA
] = p
[TEXT_AREA
];
1039 row
->glyphs
[RIGHT_MARGIN_AREA
] = p
[RIGHT_MARGIN_AREA
];
1040 row
->glyphs
[LAST_AREA
] = p
[LAST_AREA
];
1042 #if 0 /* At some point, some bit-fields of struct glyph were not set,
1043 which made glyphs unequal when compared with GLYPH_EQUAL_P.
1044 Redisplay outputs such glyphs, and flickering effects were
1045 the result. This also depended on the contents of memory
1046 returned by xmalloc. If flickering happens again, activate
1047 the code below. If the flickering is gone with that, chances
1048 are that the flickering has the same reason as here. */
1049 memset (p
[0], 0, (char *) p
[LAST_AREA
] - (char *) p
[0]);
1054 /* Make ROW an empty, enabled row of canonical character height,
1055 in window W starting at y-position Y. */
1058 blank_row (struct window
*w
, struct glyph_row
*row
, int y
)
1062 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1063 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
);
1065 clear_glyph_row (row
);
1067 row
->ascent
= row
->phys_ascent
= 0;
1068 row
->height
= row
->phys_height
= FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
1069 row
->visible_height
= row
->height
;
1072 row
->visible_height
-= min_y
- row
->y
;
1073 if (row
->y
+ row
->height
> max_y
)
1074 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
1080 /* Increment buffer positions in glyph row ROW. DELTA and DELTA_BYTES
1081 are the amounts by which to change positions. Note that the first
1082 glyph of the text area of a row can have a buffer position even if
1083 the used count of the text area is zero. Such rows display line
1087 increment_row_positions (struct glyph_row
*row
,
1088 EMACS_INT delta
, EMACS_INT delta_bytes
)
1092 /* Increment start and end positions. */
1093 MATRIX_ROW_START_CHARPOS (row
) += delta
;
1094 MATRIX_ROW_START_BYTEPOS (row
) += delta_bytes
;
1095 MATRIX_ROW_END_CHARPOS (row
) += delta
;
1096 MATRIX_ROW_END_BYTEPOS (row
) += delta_bytes
;
1097 CHARPOS (row
->start
.pos
) += delta
;
1098 BYTEPOS (row
->start
.pos
) += delta_bytes
;
1099 CHARPOS (row
->end
.pos
) += delta
;
1100 BYTEPOS (row
->end
.pos
) += delta_bytes
;
1102 if (!row
->enabled_p
)
1105 /* Increment positions in glyphs. */
1106 for (area
= 0; area
< LAST_AREA
; ++area
)
1107 for (i
= 0; i
< row
->used
[area
]; ++i
)
1108 if (BUFFERP (row
->glyphs
[area
][i
].object
)
1109 && row
->glyphs
[area
][i
].charpos
> 0)
1110 row
->glyphs
[area
][i
].charpos
+= delta
;
1112 /* Capture the case of rows displaying a line end. */
1113 if (row
->used
[TEXT_AREA
] == 0
1114 && MATRIX_ROW_DISPLAYS_TEXT_P (row
))
1115 row
->glyphs
[TEXT_AREA
]->charpos
+= delta
;
1120 /* Swap glyphs between two glyph rows A and B. This exchanges glyph
1121 contents, i.e. glyph structure contents are exchanged between A and
1122 B without changing glyph pointers in A and B. */
1125 swap_glyphs_in_rows (a
, b
)
1126 struct glyph_row
*a
, *b
;
1130 for (area
= 0; area
< LAST_AREA
; ++area
)
1132 /* Number of glyphs to swap. */
1133 int max_used
= max (a
->used
[area
], b
->used
[area
]);
1135 /* Start of glyphs in area of row A. */
1136 struct glyph
*glyph_a
= a
->glyphs
[area
];
1138 /* End + 1 of glyphs in area of row A. */
1139 struct glyph
*glyph_a_end
= a
->glyphs
[max_used
];
1141 /* Start of glyphs in area of row B. */
1142 struct glyph
*glyph_b
= b
->glyphs
[area
];
1144 while (glyph_a
< glyph_a_end
)
1146 /* Non-ISO HP/UX compiler doesn't like auto struct
1150 *glyph_a
= *glyph_b
;
1160 /* Exchange pointers to glyph memory between glyph rows A and B. */
1163 swap_glyph_pointers (struct glyph_row
*a
, struct glyph_row
*b
)
1166 for (i
= 0; i
< LAST_AREA
+ 1; ++i
)
1168 struct glyph
*temp
= a
->glyphs
[i
];
1169 a
->glyphs
[i
] = b
->glyphs
[i
];
1170 b
->glyphs
[i
] = temp
;
1175 /* Copy glyph row structure FROM to glyph row structure TO, except
1176 that glyph pointers in the structures are left unchanged. */
1179 copy_row_except_pointers (struct glyph_row
*to
, struct glyph_row
*from
)
1181 struct glyph
*pointers
[1 + LAST_AREA
];
1183 /* Save glyph pointers of TO. */
1184 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
1186 /* Do a structure assignment. */
1189 /* Restore original pointers of TO. */
1190 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
1194 /* Copy contents of glyph row FROM to glyph row TO. Glyph pointers in
1195 TO and FROM are left unchanged. Glyph contents are copied from the
1196 glyph memory of FROM to the glyph memory of TO. Increment buffer
1197 positions in row TO by DELTA/ DELTA_BYTES. */
1200 copy_glyph_row_contents (struct glyph_row
*to
, struct glyph_row
*from
,
1201 EMACS_INT delta
, EMACS_INT delta_bytes
)
1205 /* This is like a structure assignment TO = FROM, except that
1206 glyph pointers in the rows are left unchanged. */
1207 copy_row_except_pointers (to
, from
);
1209 /* Copy glyphs from FROM to TO. */
1210 for (area
= 0; area
< LAST_AREA
; ++area
)
1211 if (from
->used
[area
])
1212 memcpy (to
->glyphs
[area
], from
->glyphs
[area
],
1213 from
->used
[area
] * sizeof (struct glyph
));
1215 /* Increment buffer positions in TO by DELTA. */
1216 increment_row_positions (to
, delta
, delta_bytes
);
1220 /* Assign glyph row FROM to glyph row TO. This works like a structure
1221 assignment TO = FROM, except that glyph pointers are not copied but
1222 exchanged between TO and FROM. Pointers must be exchanged to avoid
1226 assign_row (struct glyph_row
*to
, struct glyph_row
*from
)
1228 swap_glyph_pointers (to
, from
);
1229 copy_row_except_pointers (to
, from
);
1233 /* Test whether the glyph memory of the glyph row WINDOW_ROW, which is
1234 a row in a window matrix, is a slice of the glyph memory of the
1235 glyph row FRAME_ROW which is a row in a frame glyph matrix. Value
1236 is non-zero if the glyph memory of WINDOW_ROW is part of the glyph
1237 memory of FRAME_ROW. */
1242 glyph_row_slice_p (struct glyph_row
*window_row
, struct glyph_row
*frame_row
)
1244 struct glyph
*window_glyph_start
= window_row
->glyphs
[0];
1245 struct glyph
*frame_glyph_start
= frame_row
->glyphs
[0];
1246 struct glyph
*frame_glyph_end
= frame_row
->glyphs
[LAST_AREA
];
1248 return (frame_glyph_start
<= window_glyph_start
1249 && window_glyph_start
< frame_glyph_end
);
1252 #endif /* GLYPH_DEBUG */
1256 /* Find the row in the window glyph matrix WINDOW_MATRIX being a slice
1257 of ROW in the frame matrix FRAME_MATRIX. Value is null if no row
1258 in WINDOW_MATRIX is found satisfying the condition. */
1260 static struct glyph_row
*
1261 find_glyph_row_slice (struct glyph_matrix
*window_matrix
,
1262 struct glyph_matrix
*frame_matrix
, int row
)
1266 xassert (row
>= 0 && row
< frame_matrix
->nrows
);
1268 for (i
= 0; i
< window_matrix
->nrows
; ++i
)
1269 if (glyph_row_slice_p (window_matrix
->rows
+ i
,
1270 frame_matrix
->rows
+ row
))
1273 return i
< window_matrix
->nrows
? window_matrix
->rows
+ i
: 0;
1278 /* Prepare ROW for display. Desired rows are cleared lazily,
1279 i.e. they are only marked as to be cleared by setting their
1280 enabled_p flag to zero. When a row is to be displayed, a prior
1281 call to this function really clears it. */
1284 prepare_desired_row (struct glyph_row
*row
)
1286 if (!row
->enabled_p
)
1288 unsigned rp
= row
->reversed_p
;
1290 clear_glyph_row (row
);
1292 row
->reversed_p
= rp
;
1297 /* Return a hash code for glyph row ROW. */
1300 line_hash_code (struct glyph_row
*row
)
1306 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1307 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1311 int c
= glyph
->u
.ch
;
1312 int face_id
= glyph
->face_id
;
1313 if (FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ())) /* XXX Is SELECTED_FRAME OK here? */
1315 hash
= (((hash
<< 4) + (hash
>> 24)) & 0x0fffffff) + c
;
1316 hash
= (((hash
<< 4) + (hash
>> 24)) & 0x0fffffff) + face_id
;
1328 /* Return the cost of drawing line VPOS in MATRIX. The cost equals
1329 the number of characters in the line. If must_write_spaces is
1330 zero, leading and trailing spaces are ignored. */
1333 line_draw_cost (struct glyph_matrix
*matrix
, int vpos
)
1335 struct glyph_row
*row
= matrix
->rows
+ vpos
;
1336 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
1337 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
];
1339 Lisp_Object
*glyph_table_base
= GLYPH_TABLE_BASE
;
1340 int glyph_table_len
= GLYPH_TABLE_LENGTH
;
1342 /* Ignore trailing and leading spaces if we can. */
1343 if (!FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ())) /* XXX Is SELECTED_FRAME OK here? */
1345 /* Skip from the end over trailing spaces. */
1346 while (end
> beg
&& CHAR_GLYPH_SPACE_P (*(end
- 1)))
1349 /* All blank line. */
1353 /* Skip over leading spaces. */
1354 while (CHAR_GLYPH_SPACE_P (*beg
))
1358 /* If we don't have a glyph-table, each glyph is one character,
1359 so return the number of glyphs. */
1360 if (glyph_table_base
== 0)
1364 /* Otherwise, scan the glyphs and accumulate their total length
1371 SET_GLYPH_FROM_CHAR_GLYPH (g
, *beg
);
1373 if (GLYPH_INVALID_P (g
)
1374 || GLYPH_SIMPLE_P (glyph_table_base
, glyph_table_len
, g
))
1377 len
+= GLYPH_LENGTH (glyph_table_base
, g
);
1387 /* Test two glyph rows A and B for equality. Value is non-zero if A
1388 and B have equal contents. W is the window to which the glyphs
1389 rows A and B belong. It is needed here to test for partial row
1390 visibility. MOUSE_FACE_P non-zero means compare the mouse_face_p
1391 flags of A and B, too. */
1394 row_equal_p (struct window
*w
, struct glyph_row
*a
, struct glyph_row
*b
, int mouse_face_p
)
1398 else if (a
->hash
!= b
->hash
)
1402 struct glyph
*a_glyph
, *b_glyph
, *a_end
;
1405 if (mouse_face_p
&& a
->mouse_face_p
!= b
->mouse_face_p
)
1408 /* Compare glyphs. */
1409 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
1411 if (a
->used
[area
] != b
->used
[area
])
1414 a_glyph
= a
->glyphs
[area
];
1415 a_end
= a_glyph
+ a
->used
[area
];
1416 b_glyph
= b
->glyphs
[area
];
1418 while (a_glyph
< a_end
1419 && GLYPH_EQUAL_P (a_glyph
, b_glyph
))
1420 ++a_glyph
, ++b_glyph
;
1422 if (a_glyph
!= a_end
)
1426 if (a
->fill_line_p
!= b
->fill_line_p
1427 || a
->cursor_in_fringe_p
!= b
->cursor_in_fringe_p
1428 || a
->left_fringe_bitmap
!= b
->left_fringe_bitmap
1429 || a
->left_fringe_face_id
!= b
->left_fringe_face_id
1430 || a
->right_fringe_bitmap
!= b
->right_fringe_bitmap
1431 || a
->right_fringe_face_id
!= b
->right_fringe_face_id
1432 || a
->overlay_arrow_bitmap
!= b
->overlay_arrow_bitmap
1433 || a
->exact_window_width_line_p
!= b
->exact_window_width_line_p
1434 || a
->overlapped_p
!= b
->overlapped_p
1435 || (MATRIX_ROW_CONTINUATION_LINE_P (a
)
1436 != MATRIX_ROW_CONTINUATION_LINE_P (b
))
1437 || a
->reversed_p
!= b
->reversed_p
1438 /* Different partially visible characters on left margin. */
1440 /* Different height. */
1441 || a
->ascent
!= b
->ascent
1442 || a
->phys_ascent
!= b
->phys_ascent
1443 || a
->phys_height
!= b
->phys_height
1444 || a
->visible_height
!= b
->visible_height
)
1453 /***********************************************************************
1456 See dispextern.h for an overall explanation of glyph pools.
1457 ***********************************************************************/
1459 /* Allocate a glyph_pool structure. The structure returned is
1460 initialized with zeros. The global variable glyph_pool_count is
1461 incremented for each pool allocated. */
1463 static struct glyph_pool
*
1464 new_glyph_pool (void)
1466 struct glyph_pool
*result
;
1468 /* Allocate a new glyph_pool and clear it. */
1469 result
= (struct glyph_pool
*) xmalloc (sizeof *result
);
1470 memset (result
, 0, sizeof *result
);
1472 /* For memory leak and double deletion checking. */
1479 /* Free a glyph_pool structure POOL. The function may be called with
1480 a null POOL pointer. The global variable glyph_pool_count is
1481 decremented with every pool structure freed. If this count gets
1482 negative, more structures were freed than allocated, i.e. one
1483 structure must have been freed more than once or a bogus pointer
1484 was passed to free_glyph_pool. */
1487 free_glyph_pool (struct glyph_pool
*pool
)
1491 /* More freed than allocated? */
1493 xassert (glyph_pool_count
>= 0);
1495 xfree (pool
->glyphs
);
1501 /* Enlarge a glyph pool POOL. MATRIX_DIM gives the number of rows and
1502 columns we need. This function never shrinks a pool. The only
1503 case in which this would make sense, would be when a frame's size
1504 is changed from a large value to a smaller one. But, if someone
1505 does it once, we can expect that he will do it again.
1507 Value is non-zero if the pool changed in a way which makes
1508 re-adjusting window glyph matrices necessary. */
1511 realloc_glyph_pool (struct glyph_pool
*pool
, struct dim matrix_dim
)
1516 changed_p
= (pool
->glyphs
== 0
1517 || matrix_dim
.height
!= pool
->nrows
1518 || matrix_dim
.width
!= pool
->ncolumns
);
1520 /* Enlarge the glyph pool. */
1521 needed
= matrix_dim
.width
* matrix_dim
.height
;
1522 if (needed
> pool
->nglyphs
)
1524 int size
= needed
* sizeof (struct glyph
);
1528 pool
->glyphs
= (struct glyph
*) xrealloc (pool
->glyphs
, size
);
1529 memset (pool
->glyphs
+ pool
->nglyphs
, 0,
1530 size
- pool
->nglyphs
* sizeof (struct glyph
));
1534 pool
->glyphs
= (struct glyph
*) xmalloc (size
);
1535 memset (pool
->glyphs
, 0, size
);
1538 pool
->nglyphs
= needed
;
1541 /* Remember the number of rows and columns because (a) we use them
1542 to do sanity checks, and (b) the number of columns determines
1543 where rows in the frame matrix start---this must be available to
1544 determine pointers to rows of window sub-matrices. */
1545 pool
->nrows
= matrix_dim
.height
;
1546 pool
->ncolumns
= matrix_dim
.width
;
1553 /***********************************************************************
1555 ***********************************************************************/
1560 /* Flush standard output. This is sometimes useful to call from the debugger.
1561 XXX Maybe this should be changed to flush the current terminal instead of
1572 /* Check that no glyph pointers have been lost in MATRIX. If a
1573 pointer has been lost, e.g. by using a structure assignment between
1574 rows, at least one pointer must occur more than once in the rows of
1578 check_matrix_pointer_lossage (struct glyph_matrix
*matrix
)
1582 for (i
= 0; i
< matrix
->nrows
; ++i
)
1583 for (j
= 0; j
< matrix
->nrows
; ++j
)
1585 || (matrix
->rows
[i
].glyphs
[TEXT_AREA
]
1586 != matrix
->rows
[j
].glyphs
[TEXT_AREA
]));
1590 /* Get a pointer to glyph row ROW in MATRIX, with bounds checks. */
1593 matrix_row (struct glyph_matrix
*matrix
, int row
)
1595 xassert (matrix
&& matrix
->rows
);
1596 xassert (row
>= 0 && row
< matrix
->nrows
);
1598 /* That's really too slow for normal testing because this function
1599 is called almost everywhere. Although---it's still astonishingly
1600 fast, so it is valuable to have for debugging purposes. */
1602 check_matrix_pointer_lossage (matrix
);
1605 return matrix
->rows
+ row
;
1609 #if 0 /* This function makes invalid assumptions when text is
1610 partially invisible. But it might come handy for debugging
1613 /* Check invariants that must hold for an up to date current matrix of
1617 check_matrix_invariants (struct window
*w
)
1619 struct glyph_matrix
*matrix
= w
->current_matrix
;
1620 int yb
= window_text_bottom_y (w
);
1621 struct glyph_row
*row
= matrix
->rows
;
1622 struct glyph_row
*last_text_row
= NULL
;
1623 struct buffer
*saved
= current_buffer
;
1624 struct buffer
*buffer
= XBUFFER (w
->buffer
);
1627 /* This can sometimes happen for a fresh window. */
1628 if (matrix
->nrows
< 2)
1631 set_buffer_temp (buffer
);
1633 /* Note: last row is always reserved for the mode line. */
1634 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1635 && MATRIX_ROW_BOTTOM_Y (row
) < yb
)
1637 struct glyph_row
*next
= row
+ 1;
1639 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
1640 last_text_row
= row
;
1642 /* Check that character and byte positions are in sync. */
1643 xassert (MATRIX_ROW_START_BYTEPOS (row
)
1644 == CHAR_TO_BYTE (MATRIX_ROW_START_CHARPOS (row
)));
1645 xassert (BYTEPOS (row
->start
.pos
)
1646 == CHAR_TO_BYTE (CHARPOS (row
->start
.pos
)));
1648 /* CHAR_TO_BYTE aborts when invoked for a position > Z. We can
1649 have such a position temporarily in case of a minibuffer
1650 displaying something like `[Sole completion]' at its end. */
1651 if (MATRIX_ROW_END_CHARPOS (row
) < BUF_ZV (current_buffer
))
1653 xassert (MATRIX_ROW_END_BYTEPOS (row
)
1654 == CHAR_TO_BYTE (MATRIX_ROW_END_CHARPOS (row
)));
1655 xassert (BYTEPOS (row
->end
.pos
)
1656 == CHAR_TO_BYTE (CHARPOS (row
->end
.pos
)));
1659 /* Check that end position of `row' is equal to start position
1661 if (next
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (next
))
1663 xassert (MATRIX_ROW_END_CHARPOS (row
)
1664 == MATRIX_ROW_START_CHARPOS (next
));
1665 xassert (MATRIX_ROW_END_BYTEPOS (row
)
1666 == MATRIX_ROW_START_BYTEPOS (next
));
1667 xassert (CHARPOS (row
->end
.pos
) == CHARPOS (next
->start
.pos
));
1668 xassert (BYTEPOS (row
->end
.pos
) == BYTEPOS (next
->start
.pos
));
1673 xassert (w
->current_matrix
->nrows
== w
->desired_matrix
->nrows
);
1674 xassert (w
->desired_matrix
->rows
!= NULL
);
1675 set_buffer_temp (saved
);
1680 #endif /* GLYPH_DEBUG != 0 */
1684 /**********************************************************************
1685 Allocating/ Adjusting Glyph Matrices
1686 **********************************************************************/
1688 /* Allocate glyph matrices over a window tree for a frame-based
1691 X and Y are column/row within the frame glyph matrix where
1692 sub-matrices for the window tree rooted at WINDOW must be
1693 allocated. DIM_ONLY_P non-zero means that the caller of this
1694 function is only interested in the result matrix dimension, and
1695 matrix adjustments should not be performed.
1697 The function returns the total width/height of the sub-matrices of
1698 the window tree. If called on a frame root window, the computation
1699 will take the mini-buffer window into account.
1701 *WINDOW_CHANGE_FLAGS is set to a bit mask with bits
1703 NEW_LEAF_MATRIX set if any window in the tree did not have a
1704 glyph matrices yet, and
1706 CHANGED_LEAF_MATRIX set if the dimension or location of a matrix of
1707 any window in the tree will be changed or have been changed (see
1710 *WINDOW_CHANGE_FLAGS must be initialized by the caller of this
1713 Windows are arranged into chains of windows on the same level
1714 through the next fields of window structures. Such a level can be
1715 either a sequence of horizontally adjacent windows from left to
1716 right, or a sequence of vertically adjacent windows from top to
1717 bottom. Each window in a horizontal sequence can be either a leaf
1718 window or a vertical sequence; a window in a vertical sequence can
1719 be either a leaf or a horizontal sequence. All windows in a
1720 horizontal sequence have the same height, and all windows in a
1721 vertical sequence have the same width.
1723 This function uses, for historical reasons, a more general
1724 algorithm to determine glyph matrix dimensions that would be
1727 The matrix height of a horizontal sequence is determined by the
1728 maximum height of any matrix in the sequence. The matrix width of
1729 a horizontal sequence is computed by adding up matrix widths of
1730 windows in the sequence.
1732 |<------- result width ------->|
1733 +---------+----------+---------+ ---
1736 +---------+ | | result height
1741 The matrix width of a vertical sequence is the maximum matrix width
1742 of any window in the sequence. Its height is computed by adding up
1743 matrix heights of windows in the sequence.
1745 |<---- result width -->|
1753 +------------+---------+ |
1756 +------------+---------+ --- */
1758 /* Bit indicating that a new matrix will be allocated or has been
1761 #define NEW_LEAF_MATRIX (1 << 0)
1763 /* Bit indicating that a matrix will or has changed its location or
1766 #define CHANGED_LEAF_MATRIX (1 << 1)
1769 allocate_matrices_for_frame_redisplay (Lisp_Object window
, int x
, int y
,
1770 int dim_only_p
, int *window_change_flags
)
1772 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1774 int wmax
= 0, hmax
= 0;
1778 int in_horz_combination_p
;
1780 /* What combination is WINDOW part of? Compute this once since the
1781 result is the same for all windows in the `next' chain. The
1782 special case of a root window (parent equal to nil) is treated
1783 like a vertical combination because a root window's `next'
1784 points to the mini-buffer window, if any, which is arranged
1785 vertically below other windows. */
1786 in_horz_combination_p
1787 = (!NILP (XWINDOW (window
)->parent
)
1788 && !NILP (XWINDOW (XWINDOW (window
)->parent
)->hchild
));
1790 /* For WINDOW and all windows on the same level. */
1793 w
= XWINDOW (window
);
1795 /* Get the dimension of the window sub-matrix for W, depending
1796 on whether this is a combination or a leaf window. */
1797 if (!NILP (w
->hchild
))
1798 dim
= allocate_matrices_for_frame_redisplay (w
->hchild
, x
, y
,
1800 window_change_flags
);
1801 else if (!NILP (w
->vchild
))
1802 dim
= allocate_matrices_for_frame_redisplay (w
->vchild
, x
, y
,
1804 window_change_flags
);
1807 /* If not already done, allocate sub-matrix structures. */
1808 if (w
->desired_matrix
== NULL
)
1810 w
->desired_matrix
= new_glyph_matrix (f
->desired_pool
);
1811 w
->current_matrix
= new_glyph_matrix (f
->current_pool
);
1812 *window_change_flags
|= NEW_LEAF_MATRIX
;
1815 /* Width and height MUST be chosen so that there are no
1816 holes in the frame matrix. */
1817 dim
.width
= required_matrix_width (w
);
1818 dim
.height
= required_matrix_height (w
);
1820 /* Will matrix be re-allocated? */
1821 if (x
!= w
->desired_matrix
->matrix_x
1822 || y
!= w
->desired_matrix
->matrix_y
1823 || dim
.width
!= w
->desired_matrix
->matrix_w
1824 || dim
.height
!= w
->desired_matrix
->matrix_h
1825 || (margin_glyphs_to_reserve (w
, dim
.width
,
1826 w
->left_margin_cols
)
1827 != w
->desired_matrix
->left_margin_glyphs
)
1828 || (margin_glyphs_to_reserve (w
, dim
.width
,
1829 w
->right_margin_cols
)
1830 != w
->desired_matrix
->right_margin_glyphs
))
1831 *window_change_flags
|= CHANGED_LEAF_MATRIX
;
1833 /* Actually change matrices, if allowed. Do not consider
1834 CHANGED_LEAF_MATRIX computed above here because the pool
1835 may have been changed which we don't now here. We trust
1836 that we only will be called with DIM_ONLY_P != 0 when
1840 adjust_glyph_matrix (w
, w
->desired_matrix
, x
, y
, dim
);
1841 adjust_glyph_matrix (w
, w
->current_matrix
, x
, y
, dim
);
1845 /* If we are part of a horizontal combination, advance x for
1846 windows to the right of W; otherwise advance y for windows
1848 if (in_horz_combination_p
)
1853 /* Remember maximum glyph matrix dimensions. */
1854 wmax
= max (wmax
, dim
.width
);
1855 hmax
= max (hmax
, dim
.height
);
1857 /* Next window on same level. */
1860 while (!NILP (window
));
1862 /* Set `total' to the total glyph matrix dimension of this window
1863 level. In a vertical combination, the width is the width of the
1864 widest window; the height is the y we finally reached, corrected
1865 by the y we started with. In a horizontal combination, the total
1866 height is the height of the tallest window, and the width is the
1867 x we finally reached, corrected by the x we started with. */
1868 if (in_horz_combination_p
)
1870 total
.width
= x
- x0
;
1871 total
.height
= hmax
;
1876 total
.height
= y
- y0
;
1883 /* Return the required height of glyph matrices for window W. */
1886 required_matrix_height (struct window
*w
)
1888 #ifdef HAVE_WINDOW_SYSTEM
1889 struct frame
*f
= XFRAME (w
->frame
);
1891 if (FRAME_WINDOW_P (f
))
1893 int ch_height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
1894 int window_pixel_height
= window_box_height (w
) + eabs (w
->vscroll
);
1895 return (((window_pixel_height
+ ch_height
- 1)
1896 / ch_height
) * w
->nrows_scale_factor
1897 /* One partially visible line at the top and
1898 bottom of the window. */
1900 /* 2 for header and mode line. */
1903 #endif /* HAVE_WINDOW_SYSTEM */
1905 return WINDOW_TOTAL_LINES (w
);
1909 /* Return the required width of glyph matrices for window W. */
1912 required_matrix_width (struct window
*w
)
1914 #ifdef HAVE_WINDOW_SYSTEM
1915 struct frame
*f
= XFRAME (w
->frame
);
1916 if (FRAME_WINDOW_P (f
))
1918 int ch_width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
1919 int window_pixel_width
= WINDOW_TOTAL_WIDTH (w
);
1921 /* Compute number of glyphs needed in a glyph row. */
1922 return (((window_pixel_width
+ ch_width
- 1)
1923 / ch_width
) * w
->ncols_scale_factor
1924 /* 2 partially visible columns in the text area. */
1926 /* One partially visible column at the right
1927 edge of each marginal area. */
1930 #endif /* HAVE_WINDOW_SYSTEM */
1932 return XINT (w
->total_cols
);
1936 /* Allocate window matrices for window-based redisplay. W is the
1937 window whose matrices must be allocated/reallocated. */
1940 allocate_matrices_for_window_redisplay (struct window
*w
)
1944 if (!NILP (w
->vchild
))
1945 allocate_matrices_for_window_redisplay (XWINDOW (w
->vchild
));
1946 else if (!NILP (w
->hchild
))
1947 allocate_matrices_for_window_redisplay (XWINDOW (w
->hchild
));
1950 /* W is a leaf window. */
1953 /* If matrices are not yet allocated, allocate them now. */
1954 if (w
->desired_matrix
== NULL
)
1956 w
->desired_matrix
= new_glyph_matrix (NULL
);
1957 w
->current_matrix
= new_glyph_matrix (NULL
);
1960 dim
.width
= required_matrix_width (w
);
1961 dim
.height
= required_matrix_height (w
);
1962 adjust_glyph_matrix (w
, w
->desired_matrix
, 0, 0, dim
);
1963 adjust_glyph_matrix (w
, w
->current_matrix
, 0, 0, dim
);
1966 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
1971 /* Re-allocate/ re-compute glyph matrices on frame F. If F is null,
1972 do it for all frames; otherwise do it just for the given frame.
1973 This function must be called when a new frame is created, its size
1974 changes, or its window configuration changes. */
1977 adjust_glyphs (struct frame
*f
)
1979 /* Block input so that expose events and other events that access
1980 glyph matrices are not processed while we are changing them. */
1984 adjust_frame_glyphs (f
);
1987 Lisp_Object tail
, lisp_frame
;
1989 FOR_EACH_FRAME (tail
, lisp_frame
)
1990 adjust_frame_glyphs (XFRAME (lisp_frame
));
1997 /* Adjust frame glyphs when Emacs is initialized.
1999 To be called from init_display.
2001 We need a glyph matrix because redraw will happen soon.
2002 Unfortunately, window sizes on selected_frame are not yet set to
2003 meaningful values. I believe we can assume that there are only two
2004 windows on the frame---the mini-buffer and the root window. Frame
2005 height and width seem to be correct so far. So, set the sizes of
2006 windows to estimated values. */
2009 adjust_frame_glyphs_initially (void)
2011 struct frame
*sf
= SELECTED_FRAME ();
2012 struct window
*root
= XWINDOW (sf
->root_window
);
2013 struct window
*mini
= XWINDOW (root
->next
);
2014 int frame_lines
= FRAME_LINES (sf
);
2015 int frame_cols
= FRAME_COLS (sf
);
2016 int top_margin
= FRAME_TOP_MARGIN (sf
);
2018 /* Do it for the root window. */
2019 XSETFASTINT (root
->top_line
, top_margin
);
2020 XSETFASTINT (root
->total_cols
, frame_cols
);
2021 set_window_height (sf
->root_window
, frame_lines
- 1 - top_margin
, 0);
2023 /* Do it for the mini-buffer window. */
2024 XSETFASTINT (mini
->top_line
, frame_lines
- 1);
2025 XSETFASTINT (mini
->total_cols
, frame_cols
);
2026 set_window_height (root
->next
, 1, 0);
2028 adjust_frame_glyphs (sf
);
2029 glyphs_initialized_initially_p
= 1;
2033 /* Allocate/reallocate glyph matrices of a single frame F. */
2036 adjust_frame_glyphs (struct frame
*f
)
2038 if (FRAME_WINDOW_P (f
))
2039 adjust_frame_glyphs_for_window_redisplay (f
);
2041 adjust_frame_glyphs_for_frame_redisplay (f
);
2043 /* Don't forget the message buffer and the buffer for
2044 decode_mode_spec. */
2045 adjust_frame_message_buffer (f
);
2046 adjust_decode_mode_spec_buffer (f
);
2048 f
->glyphs_initialized_p
= 1;
2051 /* Return 1 if any window in the tree has nonzero window margins. See
2052 the hack at the end of adjust_frame_glyphs_for_frame_redisplay. */
2054 showing_window_margins_p (struct window
*w
)
2058 if (!NILP (w
->hchild
))
2060 if (showing_window_margins_p (XWINDOW (w
->hchild
)))
2063 else if (!NILP (w
->vchild
))
2065 if (showing_window_margins_p (XWINDOW (w
->vchild
)))
2068 else if (!NILP (w
->left_margin_cols
)
2069 || !NILP (w
->right_margin_cols
))
2072 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2078 /* In the window tree with root W, build current matrices of leaf
2079 windows from the frame's current matrix. */
2082 fake_current_matrices (Lisp_Object window
)
2086 for (; !NILP (window
); window
= w
->next
)
2088 w
= XWINDOW (window
);
2090 if (!NILP (w
->hchild
))
2091 fake_current_matrices (w
->hchild
);
2092 else if (!NILP (w
->vchild
))
2093 fake_current_matrices (w
->vchild
);
2097 struct frame
*f
= XFRAME (w
->frame
);
2098 struct glyph_matrix
*m
= w
->current_matrix
;
2099 struct glyph_matrix
*fm
= f
->current_matrix
;
2101 xassert (m
->matrix_h
== WINDOW_TOTAL_LINES (w
));
2102 xassert (m
->matrix_w
== WINDOW_TOTAL_COLS (w
));
2104 for (i
= 0; i
< m
->matrix_h
; ++i
)
2106 struct glyph_row
*r
= m
->rows
+ i
;
2107 struct glyph_row
*fr
= fm
->rows
+ i
+ WINDOW_TOP_EDGE_LINE (w
);
2109 xassert (r
->glyphs
[TEXT_AREA
] >= fr
->glyphs
[TEXT_AREA
]
2110 && r
->glyphs
[LAST_AREA
] <= fr
->glyphs
[LAST_AREA
]);
2112 r
->enabled_p
= fr
->enabled_p
;
2115 r
->used
[LEFT_MARGIN_AREA
] = m
->left_margin_glyphs
;
2116 r
->used
[RIGHT_MARGIN_AREA
] = m
->right_margin_glyphs
;
2117 r
->used
[TEXT_AREA
] = (m
->matrix_w
2118 - r
->used
[LEFT_MARGIN_AREA
]
2119 - r
->used
[RIGHT_MARGIN_AREA
]);
2128 /* Save away the contents of frame F's current frame matrix. Value is
2129 a glyph matrix holding the contents of F's current frame matrix. */
2131 static struct glyph_matrix
*
2132 save_current_matrix (struct frame
*f
)
2135 struct glyph_matrix
*saved
;
2137 saved
= (struct glyph_matrix
*) xmalloc (sizeof *saved
);
2138 memset (saved
, 0, sizeof *saved
);
2139 saved
->nrows
= f
->current_matrix
->nrows
;
2140 saved
->rows
= (struct glyph_row
*) xmalloc (saved
->nrows
2141 * sizeof *saved
->rows
);
2142 memset (saved
->rows
, 0, saved
->nrows
* sizeof *saved
->rows
);
2144 for (i
= 0; i
< saved
->nrows
; ++i
)
2146 struct glyph_row
*from
= f
->current_matrix
->rows
+ i
;
2147 struct glyph_row
*to
= saved
->rows
+ i
;
2148 size_t nbytes
= from
->used
[TEXT_AREA
] * sizeof (struct glyph
);
2149 to
->glyphs
[TEXT_AREA
] = (struct glyph
*) xmalloc (nbytes
);
2150 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
], nbytes
);
2151 to
->used
[TEXT_AREA
] = from
->used
[TEXT_AREA
];
2158 /* Restore the contents of frame F's current frame matrix from SAVED,
2159 and free memory associated with SAVED. */
2162 restore_current_matrix (struct frame
*f
, struct glyph_matrix
*saved
)
2166 for (i
= 0; i
< saved
->nrows
; ++i
)
2168 struct glyph_row
*from
= saved
->rows
+ i
;
2169 struct glyph_row
*to
= f
->current_matrix
->rows
+ i
;
2170 size_t nbytes
= from
->used
[TEXT_AREA
] * sizeof (struct glyph
);
2171 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
], nbytes
);
2172 to
->used
[TEXT_AREA
] = from
->used
[TEXT_AREA
];
2173 xfree (from
->glyphs
[TEXT_AREA
]);
2176 xfree (saved
->rows
);
2182 /* Allocate/reallocate glyph matrices of a single frame F for
2183 frame-based redisplay. */
2186 adjust_frame_glyphs_for_frame_redisplay (struct frame
*f
)
2188 struct dim matrix_dim
;
2190 int window_change_flags
;
2193 if (!FRAME_LIVE_P (f
))
2196 top_window_y
= FRAME_TOP_MARGIN (f
);
2198 /* Allocate glyph pool structures if not already done. */
2199 if (f
->desired_pool
== NULL
)
2201 f
->desired_pool
= new_glyph_pool ();
2202 f
->current_pool
= new_glyph_pool ();
2205 /* Allocate frames matrix structures if needed. */
2206 if (f
->desired_matrix
== NULL
)
2208 f
->desired_matrix
= new_glyph_matrix (f
->desired_pool
);
2209 f
->current_matrix
= new_glyph_matrix (f
->current_pool
);
2212 /* Compute window glyph matrices. (This takes the mini-buffer
2213 window into account). The result is the size of the frame glyph
2214 matrix needed. The variable window_change_flags is set to a bit
2215 mask indicating whether new matrices will be allocated or
2216 existing matrices change their size or location within the frame
2218 window_change_flags
= 0;
2220 = allocate_matrices_for_frame_redisplay (FRAME_ROOT_WINDOW (f
),
2223 &window_change_flags
);
2225 /* Add in menu bar lines, if any. */
2226 matrix_dim
.height
+= top_window_y
;
2228 /* Enlarge pools as necessary. */
2229 pool_changed_p
= realloc_glyph_pool (f
->desired_pool
, matrix_dim
);
2230 realloc_glyph_pool (f
->current_pool
, matrix_dim
);
2232 /* Set up glyph pointers within window matrices. Do this only if
2233 absolutely necessary since it requires a frame redraw. */
2234 if (pool_changed_p
|| window_change_flags
)
2236 /* Do it for window matrices. */
2237 allocate_matrices_for_frame_redisplay (FRAME_ROOT_WINDOW (f
),
2239 &window_change_flags
);
2241 /* Size of frame matrices must equal size of frame. Note
2242 that we are called for X frames with window widths NOT equal
2243 to the frame width (from CHANGE_FRAME_SIZE_1). */
2244 xassert (matrix_dim
.width
== FRAME_COLS (f
)
2245 && matrix_dim
.height
== FRAME_LINES (f
));
2247 /* Pointers to glyph memory in glyph rows are exchanged during
2248 the update phase of redisplay, which means in general that a
2249 frame's current matrix consists of pointers into both the
2250 desired and current glyph pool of the frame. Adjusting a
2251 matrix sets the frame matrix up so that pointers are all into
2252 the same pool. If we want to preserve glyph contents of the
2253 current matrix over a call to adjust_glyph_matrix, we must
2254 make a copy of the current glyphs, and restore the current
2255 matrix' contents from that copy. */
2256 if (display_completed
2257 && !FRAME_GARBAGED_P (f
)
2258 && matrix_dim
.width
== f
->current_matrix
->matrix_w
2259 && matrix_dim
.height
== f
->current_matrix
->matrix_h
2260 /* For some reason, the frame glyph matrix gets corrupted if
2261 any of the windows contain margins. I haven't been able
2262 to hunt down the reason, but for the moment this prevents
2263 the problem from manifesting. -- cyd */
2264 && !showing_window_margins_p (XWINDOW (FRAME_ROOT_WINDOW (f
))))
2266 struct glyph_matrix
*copy
= save_current_matrix (f
);
2267 adjust_glyph_matrix (NULL
, f
->desired_matrix
, 0, 0, matrix_dim
);
2268 adjust_glyph_matrix (NULL
, f
->current_matrix
, 0, 0, matrix_dim
);
2269 restore_current_matrix (f
, copy
);
2270 fake_current_matrices (FRAME_ROOT_WINDOW (f
));
2274 adjust_glyph_matrix (NULL
, f
->desired_matrix
, 0, 0, matrix_dim
);
2275 adjust_glyph_matrix (NULL
, f
->current_matrix
, 0, 0, matrix_dim
);
2276 SET_FRAME_GARBAGED (f
);
2282 /* Allocate/reallocate glyph matrices of a single frame F for
2283 window-based redisplay. */
2286 adjust_frame_glyphs_for_window_redisplay (struct frame
*f
)
2290 xassert (FRAME_WINDOW_P (f
) && FRAME_LIVE_P (f
));
2292 /* Allocate/reallocate window matrices. */
2293 allocate_matrices_for_window_redisplay (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2295 #ifdef HAVE_X_WINDOWS
2296 /* Allocate/ reallocate matrices of the dummy window used to display
2297 the menu bar under X when no X toolkit support is available. */
2298 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
2300 /* Allocate a dummy window if not already done. */
2301 if (NILP (f
->menu_bar_window
))
2303 f
->menu_bar_window
= make_window ();
2304 w
= XWINDOW (f
->menu_bar_window
);
2305 XSETFRAME (w
->frame
, f
);
2306 w
->pseudo_window_p
= 1;
2309 w
= XWINDOW (f
->menu_bar_window
);
2311 /* Set window dimensions to frame dimensions and allocate or
2312 adjust glyph matrices of W. */
2313 XSETFASTINT (w
->top_line
, 0);
2314 XSETFASTINT (w
->left_col
, 0);
2315 XSETFASTINT (w
->total_lines
, FRAME_MENU_BAR_LINES (f
));
2316 XSETFASTINT (w
->total_cols
, FRAME_TOTAL_COLS (f
));
2317 allocate_matrices_for_window_redisplay (w
);
2319 #endif /* not USE_X_TOOLKIT && not USE_GTK */
2320 #endif /* HAVE_X_WINDOWS */
2323 /* Allocate/ reallocate matrices of the tool bar window. If we
2324 don't have a tool bar window yet, make one. */
2325 if (NILP (f
->tool_bar_window
))
2327 f
->tool_bar_window
= make_window ();
2328 w
= XWINDOW (f
->tool_bar_window
);
2329 XSETFRAME (w
->frame
, f
);
2330 w
->pseudo_window_p
= 1;
2333 w
= XWINDOW (f
->tool_bar_window
);
2335 XSETFASTINT (w
->top_line
, FRAME_MENU_BAR_LINES (f
));
2336 XSETFASTINT (w
->left_col
, 0);
2337 XSETFASTINT (w
->total_lines
, FRAME_TOOL_BAR_LINES (f
));
2338 XSETFASTINT (w
->total_cols
, FRAME_TOTAL_COLS (f
));
2339 allocate_matrices_for_window_redisplay (w
);
2344 /* Adjust/ allocate message buffer of frame F.
2346 Note that the message buffer is never freed. Since I could not
2347 find a free in 19.34, I assume that freeing it would be
2348 problematic in some way and don't do it either.
2350 (Implementation note: It should be checked if we can free it
2351 eventually without causing trouble). */
2354 adjust_frame_message_buffer (struct frame
*f
)
2356 int size
= FRAME_MESSAGE_BUF_SIZE (f
) + 1;
2358 if (FRAME_MESSAGE_BUF (f
))
2360 char *buffer
= FRAME_MESSAGE_BUF (f
);
2361 char *new_buffer
= (char *) xrealloc (buffer
, size
);
2362 FRAME_MESSAGE_BUF (f
) = new_buffer
;
2365 FRAME_MESSAGE_BUF (f
) = (char *) xmalloc (size
);
2369 /* Re-allocate buffer for decode_mode_spec on frame F. */
2372 adjust_decode_mode_spec_buffer (struct frame
*f
)
2374 f
->decode_mode_spec_buffer
2375 = (char *) xrealloc (f
->decode_mode_spec_buffer
,
2376 FRAME_MESSAGE_BUF_SIZE (f
) + 1);
2381 /**********************************************************************
2382 Freeing Glyph Matrices
2383 **********************************************************************/
2385 /* Free glyph memory for a frame F. F may be null. This function can
2386 be called for the same frame more than once. The root window of
2387 F may be nil when this function is called. This is the case when
2388 the function is called when F is destroyed. */
2391 free_glyphs (struct frame
*f
)
2393 if (f
&& f
->glyphs_initialized_p
)
2395 /* Block interrupt input so that we don't get surprised by an X
2396 event while we're in an inconsistent state. */
2398 f
->glyphs_initialized_p
= 0;
2400 /* Release window sub-matrices. */
2401 if (!NILP (f
->root_window
))
2402 free_window_matrices (XWINDOW (f
->root_window
));
2404 /* Free the dummy window for menu bars without X toolkit and its
2406 if (!NILP (f
->menu_bar_window
))
2408 struct window
*w
= XWINDOW (f
->menu_bar_window
);
2409 free_glyph_matrix (w
->desired_matrix
);
2410 free_glyph_matrix (w
->current_matrix
);
2411 w
->desired_matrix
= w
->current_matrix
= NULL
;
2412 f
->menu_bar_window
= Qnil
;
2415 /* Free the tool bar window and its glyph matrices. */
2416 if (!NILP (f
->tool_bar_window
))
2418 struct window
*w
= XWINDOW (f
->tool_bar_window
);
2419 free_glyph_matrix (w
->desired_matrix
);
2420 free_glyph_matrix (w
->current_matrix
);
2421 w
->desired_matrix
= w
->current_matrix
= NULL
;
2422 f
->tool_bar_window
= Qnil
;
2425 /* Release frame glyph matrices. Reset fields to zero in
2426 case we are called a second time. */
2427 if (f
->desired_matrix
)
2429 free_glyph_matrix (f
->desired_matrix
);
2430 free_glyph_matrix (f
->current_matrix
);
2431 f
->desired_matrix
= f
->current_matrix
= NULL
;
2434 /* Release glyph pools. */
2435 if (f
->desired_pool
)
2437 free_glyph_pool (f
->desired_pool
);
2438 free_glyph_pool (f
->current_pool
);
2439 f
->desired_pool
= f
->current_pool
= NULL
;
2447 /* Free glyph sub-matrices in the window tree rooted at W. This
2448 function may be called with a null pointer, and it may be called on
2449 the same tree more than once. */
2452 free_window_matrices (struct window
*w
)
2456 if (!NILP (w
->hchild
))
2457 free_window_matrices (XWINDOW (w
->hchild
));
2458 else if (!NILP (w
->vchild
))
2459 free_window_matrices (XWINDOW (w
->vchild
));
2462 /* This is a leaf window. Free its memory and reset fields
2463 to zero in case this function is called a second time for
2465 free_glyph_matrix (w
->current_matrix
);
2466 free_glyph_matrix (w
->desired_matrix
);
2467 w
->current_matrix
= w
->desired_matrix
= NULL
;
2470 /* Next window on same level. */
2471 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2476 /* Check glyph memory leaks. This function is called from
2477 shut_down_emacs. Note that frames are not destroyed when Emacs
2478 exits. We therefore free all glyph memory for all active frames
2479 explicitly and check that nothing is left allocated. */
2482 check_glyph_memory (void)
2484 Lisp_Object tail
, frame
;
2486 /* Free glyph memory for all frames. */
2487 FOR_EACH_FRAME (tail
, frame
)
2488 free_glyphs (XFRAME (frame
));
2490 /* Check that nothing is left allocated. */
2491 if (glyph_matrix_count
)
2493 if (glyph_pool_count
)
2499 /**********************************************************************
2500 Building a Frame Matrix
2501 **********************************************************************/
2503 /* Most of the redisplay code works on glyph matrices attached to
2504 windows. This is a good solution most of the time, but it is not
2505 suitable for terminal code. Terminal output functions cannot rely
2506 on being able to set an arbitrary terminal window. Instead they
2507 must be provided with a view of the whole frame, i.e. the whole
2508 screen. We build such a view by constructing a frame matrix from
2509 window matrices in this section.
2511 Windows that must be updated have their must_be_update_p flag set.
2512 For all such windows, their desired matrix is made part of the
2513 desired frame matrix. For other windows, their current matrix is
2514 made part of the desired frame matrix.
2516 +-----------------+----------------+
2517 | desired | desired |
2519 +-----------------+----------------+
2522 +----------------------------------+
2524 Desired window matrices can be made part of the frame matrix in a
2525 cheap way: We exploit the fact that the desired frame matrix and
2526 desired window matrices share their glyph memory. This is not
2527 possible for current window matrices. Their glyphs are copied to
2528 the desired frame matrix. The latter is equivalent to
2529 preserve_other_columns in the old redisplay.
2531 Used glyphs counters for frame matrix rows are the result of adding
2532 up glyph lengths of the window matrices. A line in the frame
2533 matrix is enabled, if a corresponding line in a window matrix is
2536 After building the desired frame matrix, it will be passed to
2537 terminal code, which will manipulate both the desired and current
2538 frame matrix. Changes applied to the frame's current matrix have
2539 to be visible in current window matrices afterwards, of course.
2541 This problem is solved like this:
2543 1. Window and frame matrices share glyphs. Window matrices are
2544 constructed in a way that their glyph contents ARE the glyph
2545 contents needed in a frame matrix. Thus, any modification of
2546 glyphs done in terminal code will be reflected in window matrices
2549 2. Exchanges of rows in a frame matrix done by terminal code are
2550 intercepted by hook functions so that corresponding row operations
2551 on window matrices can be performed. This is necessary because we
2552 use pointers to glyphs in glyph row structures. To satisfy the
2553 assumption of point 1 above that glyphs are updated implicitly in
2554 window matrices when they are manipulated via the frame matrix,
2555 window and frame matrix must of course agree where to find the
2556 glyphs for their rows. Possible manipulations that must be
2557 mirrored are assignments of rows of the desired frame matrix to the
2558 current frame matrix and scrolling the current frame matrix. */
2560 /* Build frame F's desired matrix from window matrices. Only windows
2561 which have the flag must_be_updated_p set have to be updated. Menu
2562 bar lines of a frame are not covered by window matrices, so make
2563 sure not to touch them in this function. */
2566 build_frame_matrix (struct frame
*f
)
2570 /* F must have a frame matrix when this function is called. */
2571 xassert (!FRAME_WINDOW_P (f
));
2573 /* Clear all rows in the frame matrix covered by window matrices.
2574 Menu bar lines are not covered by windows. */
2575 for (i
= FRAME_TOP_MARGIN (f
); i
< f
->desired_matrix
->nrows
; ++i
)
2576 clear_glyph_row (MATRIX_ROW (f
->desired_matrix
, i
));
2578 /* Build the matrix by walking the window tree. */
2579 build_frame_matrix_from_window_tree (f
->desired_matrix
,
2580 XWINDOW (FRAME_ROOT_WINDOW (f
)));
2584 /* Walk a window tree, building a frame matrix MATRIX from window
2585 matrices. W is the root of a window tree. */
2588 build_frame_matrix_from_window_tree (struct glyph_matrix
*matrix
, struct window
*w
)
2592 if (!NILP (w
->hchild
))
2593 build_frame_matrix_from_window_tree (matrix
, XWINDOW (w
->hchild
));
2594 else if (!NILP (w
->vchild
))
2595 build_frame_matrix_from_window_tree (matrix
, XWINDOW (w
->vchild
));
2597 build_frame_matrix_from_leaf_window (matrix
, w
);
2599 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2604 /* Add a window's matrix to a frame matrix. FRAME_MATRIX is the
2605 desired frame matrix built. W is a leaf window whose desired or
2606 current matrix is to be added to FRAME_MATRIX. W's flag
2607 must_be_updated_p determines which matrix it contributes to
2608 FRAME_MATRIX. If must_be_updated_p is non-zero, W's desired matrix
2609 is added to FRAME_MATRIX, otherwise W's current matrix is added.
2610 Adding a desired matrix means setting up used counters and such in
2611 frame rows, while adding a current window matrix to FRAME_MATRIX
2612 means copying glyphs. The latter case corresponds to
2613 preserve_other_columns in the old redisplay. */
2616 build_frame_matrix_from_leaf_window (struct glyph_matrix
*frame_matrix
, struct window
*w
)
2618 struct glyph_matrix
*window_matrix
;
2619 int window_y
, frame_y
;
2620 /* If non-zero, a glyph to insert at the right border of W. */
2621 GLYPH right_border_glyph
;
2623 SET_GLYPH_FROM_CHAR (right_border_glyph
, 0);
2625 /* Set window_matrix to the matrix we have to add to FRAME_MATRIX. */
2626 if (w
->must_be_updated_p
)
2628 window_matrix
= w
->desired_matrix
;
2630 /* Decide whether we want to add a vertical border glyph. */
2631 if (!WINDOW_RIGHTMOST_P (w
))
2633 struct Lisp_Char_Table
*dp
= window_display_table (w
);
2636 SET_GLYPH_FROM_CHAR (right_border_glyph
, '|');
2638 && (gc
= DISP_BORDER_GLYPH (dp
), GLYPH_CODE_P (gc
))
2639 && GLYPH_CODE_CHAR_VALID_P (gc
))
2641 SET_GLYPH_FROM_GLYPH_CODE (right_border_glyph
, gc
);
2642 spec_glyph_lookup_face (w
, &right_border_glyph
);
2645 if (GLYPH_FACE (right_border_glyph
) <= 0)
2646 SET_GLYPH_FACE (right_border_glyph
, VERTICAL_BORDER_FACE_ID
);
2650 window_matrix
= w
->current_matrix
;
2652 /* For all rows in the window matrix and corresponding rows in the
2655 frame_y
= window_matrix
->matrix_y
;
2656 while (window_y
< window_matrix
->nrows
)
2658 struct glyph_row
*frame_row
= frame_matrix
->rows
+ frame_y
;
2659 struct glyph_row
*window_row
= window_matrix
->rows
+ window_y
;
2660 int current_row_p
= window_matrix
== w
->current_matrix
;
2662 /* Fill up the frame row with spaces up to the left margin of the
2664 fill_up_frame_row_with_spaces (frame_row
, window_matrix
->matrix_x
);
2666 /* Fill up areas in the window matrix row with spaces. */
2667 fill_up_glyph_row_with_spaces (window_row
);
2669 /* If only part of W's desired matrix has been built, and
2670 window_row wasn't displayed, use the corresponding current
2672 if (window_matrix
== w
->desired_matrix
2673 && !window_row
->enabled_p
)
2675 window_row
= w
->current_matrix
->rows
+ window_y
;
2681 /* Copy window row to frame row. */
2682 memcpy (frame_row
->glyphs
[TEXT_AREA
] + window_matrix
->matrix_x
,
2683 window_row
->glyphs
[0],
2684 window_matrix
->matrix_w
* sizeof (struct glyph
));
2688 xassert (window_row
->enabled_p
);
2690 /* Only when a desired row has been displayed, we want
2691 the corresponding frame row to be updated. */
2692 frame_row
->enabled_p
= 1;
2694 /* Maybe insert a vertical border between horizontally adjacent
2696 if (GLYPH_CHAR (right_border_glyph
) != 0)
2698 struct glyph
*border
= window_row
->glyphs
[LAST_AREA
] - 1;
2699 SET_CHAR_GLYPH_FROM_GLYPH (*border
, right_border_glyph
);
2703 /* Window row window_y must be a slice of frame row
2705 xassert (glyph_row_slice_p (window_row
, frame_row
));
2707 /* If rows are in sync, we don't have to copy glyphs because
2708 frame and window share glyphs. */
2710 strcpy (w
->current_matrix
->method
, w
->desired_matrix
->method
);
2711 add_window_display_history (w
, w
->current_matrix
->method
, 0);
2715 /* Set number of used glyphs in the frame matrix. Since we fill
2716 up with spaces, and visit leaf windows from left to right it
2717 can be done simply. */
2718 frame_row
->used
[TEXT_AREA
]
2719 = window_matrix
->matrix_x
+ window_matrix
->matrix_w
;
2727 /* Given a user-specified glyph, possibly including a Lisp-level face
2728 ID, return a glyph that has a realized face ID.
2729 This is used for glyphs displayed specially and not part of the text;
2730 for instance, vertical separators, truncation markers, etc. */
2733 spec_glyph_lookup_face (struct window
*w
, GLYPH
*glyph
)
2735 int lface_id
= GLYPH_FACE (*glyph
);
2736 /* Convert the glyph's specified face to a realized (cache) face. */
2739 int face_id
= merge_faces (XFRAME (w
->frame
),
2740 Qt
, lface_id
, DEFAULT_FACE_ID
);
2741 SET_GLYPH_FACE (*glyph
, face_id
);
2745 /* Add spaces to a glyph row ROW in a window matrix.
2747 Each row has the form:
2749 +---------+-----------------------------+------------+
2750 | left | text | right |
2751 +---------+-----------------------------+------------+
2753 Left and right marginal areas are optional. This function adds
2754 spaces to areas so that there are no empty holes between areas.
2755 In other words: If the right area is not empty, the text area
2756 is filled up with spaces up to the right area. If the text area
2757 is not empty, the left area is filled up.
2759 To be called for frame-based redisplay, only. */
2762 fill_up_glyph_row_with_spaces (struct glyph_row
*row
)
2764 fill_up_glyph_row_area_with_spaces (row
, LEFT_MARGIN_AREA
);
2765 fill_up_glyph_row_area_with_spaces (row
, TEXT_AREA
);
2766 fill_up_glyph_row_area_with_spaces (row
, RIGHT_MARGIN_AREA
);
2770 /* Fill area AREA of glyph row ROW with spaces. To be called for
2771 frame-based redisplay only. */
2774 fill_up_glyph_row_area_with_spaces (struct glyph_row
*row
, int area
)
2776 if (row
->glyphs
[area
] < row
->glyphs
[area
+ 1])
2778 struct glyph
*end
= row
->glyphs
[area
+ 1];
2779 struct glyph
*text
= row
->glyphs
[area
] + row
->used
[area
];
2782 *text
++ = space_glyph
;
2783 row
->used
[area
] = text
- row
->glyphs
[area
];
2788 /* Add spaces to the end of ROW in a frame matrix until index UPTO is
2789 reached. In frame matrices only one area, TEXT_AREA, is used. */
2792 fill_up_frame_row_with_spaces (struct glyph_row
*row
, int upto
)
2794 int i
= row
->used
[TEXT_AREA
];
2795 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
2798 glyph
[i
++] = space_glyph
;
2800 row
->used
[TEXT_AREA
] = i
;
2805 /**********************************************************************
2806 Mirroring operations on frame matrices in window matrices
2807 **********************************************************************/
2809 /* Set frame being updated via frame-based redisplay to F. This
2810 function must be called before updates to make explicit that we are
2811 working on frame matrices or not. */
2814 set_frame_matrix_frame (struct frame
*f
)
2816 frame_matrix_frame
= f
;
2820 /* Make sure glyph row ROW in CURRENT_MATRIX is up to date.
2821 DESIRED_MATRIX is the desired matrix corresponding to
2822 CURRENT_MATRIX. The update is done by exchanging glyph pointers
2823 between rows in CURRENT_MATRIX and DESIRED_MATRIX. If
2824 frame_matrix_frame is non-null, this indicates that the exchange is
2825 done in frame matrices, and that we have to perform analogous
2826 operations in window matrices of frame_matrix_frame. */
2829 make_current (struct glyph_matrix
*desired_matrix
, struct glyph_matrix
*current_matrix
, int row
)
2831 struct glyph_row
*current_row
= MATRIX_ROW (current_matrix
, row
);
2832 struct glyph_row
*desired_row
= MATRIX_ROW (desired_matrix
, row
);
2833 int mouse_face_p
= current_row
->mouse_face_p
;
2835 /* Do current_row = desired_row. This exchanges glyph pointers
2836 between both rows, and does a structure assignment otherwise. */
2837 assign_row (current_row
, desired_row
);
2839 /* Enable current_row to mark it as valid. */
2840 current_row
->enabled_p
= 1;
2841 current_row
->mouse_face_p
= mouse_face_p
;
2843 /* If we are called on frame matrices, perform analogous operations
2844 for window matrices. */
2845 if (frame_matrix_frame
)
2846 mirror_make_current (XWINDOW (frame_matrix_frame
->root_window
), row
);
2850 /* W is the root of a window tree. FRAME_ROW is the index of a row in
2851 W's frame which has been made current (by swapping pointers between
2852 current and desired matrix). Perform analogous operations in the
2853 matrices of leaf windows in the window tree rooted at W. */
2856 mirror_make_current (struct window
*w
, int frame_row
)
2860 if (!NILP (w
->hchild
))
2861 mirror_make_current (XWINDOW (w
->hchild
), frame_row
);
2862 else if (!NILP (w
->vchild
))
2863 mirror_make_current (XWINDOW (w
->vchild
), frame_row
);
2866 /* Row relative to window W. Don't use FRAME_TO_WINDOW_VPOS
2867 here because the checks performed in debug mode there
2868 will not allow the conversion. */
2869 int row
= frame_row
- w
->desired_matrix
->matrix_y
;
2871 /* If FRAME_ROW is within W, assign the desired row to the
2872 current row (exchanging glyph pointers). */
2873 if (row
>= 0 && row
< w
->desired_matrix
->matrix_h
)
2875 struct glyph_row
*current_row
2876 = MATRIX_ROW (w
->current_matrix
, row
);
2877 struct glyph_row
*desired_row
2878 = MATRIX_ROW (w
->desired_matrix
, row
);
2880 if (desired_row
->enabled_p
)
2881 assign_row (current_row
, desired_row
);
2883 swap_glyph_pointers (desired_row
, current_row
);
2884 current_row
->enabled_p
= 1;
2886 /* Set the Y coordinate of the mode/header line's row.
2887 It is needed in draw_row_with_mouse_face to find the
2888 screen coordinates. (Window-based redisplay sets
2889 this in update_window, but no one seems to do that
2890 for frame-based redisplay.) */
2891 if (current_row
->mode_line_p
)
2892 current_row
->y
= row
;
2896 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2901 /* Perform row dance after scrolling. We are working on the range of
2902 lines UNCHANGED_AT_TOP + 1 to UNCHANGED_AT_TOP + NLINES (not
2903 including) in MATRIX. COPY_FROM is a vector containing, for each
2904 row I in the range 0 <= I < NLINES, the index of the original line
2905 to move to I. This index is relative to the row range, i.e. 0 <=
2906 index < NLINES. RETAINED_P is a vector containing zero for each
2907 row 0 <= I < NLINES which is empty.
2909 This function is called from do_scrolling and do_direct_scrolling. */
2912 mirrored_line_dance (struct glyph_matrix
*matrix
, int unchanged_at_top
, int nlines
,
2913 int *copy_from
, char *retained_p
)
2915 /* A copy of original rows. */
2916 struct glyph_row
*old_rows
;
2918 /* Rows to assign to. */
2919 struct glyph_row
*new_rows
= MATRIX_ROW (matrix
, unchanged_at_top
);
2923 /* Make a copy of the original rows. */
2924 old_rows
= (struct glyph_row
*) alloca (nlines
* sizeof *old_rows
);
2925 memcpy (old_rows
, new_rows
, nlines
* sizeof *old_rows
);
2927 /* Assign new rows, maybe clear lines. */
2928 for (i
= 0; i
< nlines
; ++i
)
2930 int enabled_before_p
= new_rows
[i
].enabled_p
;
2932 xassert (i
+ unchanged_at_top
< matrix
->nrows
);
2933 xassert (unchanged_at_top
+ copy_from
[i
] < matrix
->nrows
);
2934 new_rows
[i
] = old_rows
[copy_from
[i
]];
2935 new_rows
[i
].enabled_p
= enabled_before_p
;
2937 /* RETAINED_P is zero for empty lines. */
2938 if (!retained_p
[copy_from
[i
]])
2939 new_rows
[i
].enabled_p
= 0;
2942 /* Do the same for window matrices, if MATRIX is a frame matrix. */
2943 if (frame_matrix_frame
)
2944 mirror_line_dance (XWINDOW (frame_matrix_frame
->root_window
),
2945 unchanged_at_top
, nlines
, copy_from
, retained_p
);
2949 /* Synchronize glyph pointers in the current matrix of window W with
2950 the current frame matrix. */
2953 sync_window_with_frame_matrix_rows (struct window
*w
)
2955 struct frame
*f
= XFRAME (w
->frame
);
2956 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
2957 int left
, right
, x
, width
;
2959 /* Preconditions: W must be a leaf window on a tty frame. */
2960 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
2961 xassert (!FRAME_WINDOW_P (f
));
2963 left
= margin_glyphs_to_reserve (w
, 1, w
->left_margin_cols
);
2964 right
= margin_glyphs_to_reserve (w
, 1, w
->right_margin_cols
);
2965 x
= w
->current_matrix
->matrix_x
;
2966 width
= w
->current_matrix
->matrix_w
;
2968 window_row
= w
->current_matrix
->rows
;
2969 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
2970 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
2972 for (; window_row
< window_row_end
; ++window_row
, ++frame_row
)
2974 window_row
->glyphs
[LEFT_MARGIN_AREA
]
2975 = frame_row
->glyphs
[0] + x
;
2976 window_row
->glyphs
[TEXT_AREA
]
2977 = window_row
->glyphs
[LEFT_MARGIN_AREA
] + left
;
2978 window_row
->glyphs
[LAST_AREA
]
2979 = window_row
->glyphs
[LEFT_MARGIN_AREA
] + width
;
2980 window_row
->glyphs
[RIGHT_MARGIN_AREA
]
2981 = window_row
->glyphs
[LAST_AREA
] - right
;
2986 /* Return the window in the window tree rooted in W containing frame
2987 row ROW. Value is null if none is found. */
2990 frame_row_to_window (struct window
*w
, int row
)
2992 struct window
*found
= NULL
;
2996 if (!NILP (w
->hchild
))
2997 found
= frame_row_to_window (XWINDOW (w
->hchild
), row
);
2998 else if (!NILP (w
->vchild
))
2999 found
= frame_row_to_window (XWINDOW (w
->vchild
), row
);
3000 else if (row
>= WINDOW_TOP_EDGE_LINE (w
)
3001 && row
< WINDOW_BOTTOM_EDGE_LINE (w
))
3004 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3011 /* Perform a line dance in the window tree rooted at W, after
3012 scrolling a frame matrix in mirrored_line_dance.
3014 We are working on the range of lines UNCHANGED_AT_TOP + 1 to
3015 UNCHANGED_AT_TOP + NLINES (not including) in W's frame matrix.
3016 COPY_FROM is a vector containing, for each row I in the range 0 <=
3017 I < NLINES, the index of the original line to move to I. This
3018 index is relative to the row range, i.e. 0 <= index < NLINES.
3019 RETAINED_P is a vector containing zero for each row 0 <= I < NLINES
3023 mirror_line_dance (struct window
*w
, int unchanged_at_top
, int nlines
, int *copy_from
, char *retained_p
)
3027 if (!NILP (w
->hchild
))
3028 mirror_line_dance (XWINDOW (w
->hchild
), unchanged_at_top
,
3029 nlines
, copy_from
, retained_p
);
3030 else if (!NILP (w
->vchild
))
3031 mirror_line_dance (XWINDOW (w
->vchild
), unchanged_at_top
,
3032 nlines
, copy_from
, retained_p
);
3035 /* W is a leaf window, and we are working on its current
3037 struct glyph_matrix
*m
= w
->current_matrix
;
3039 struct glyph_row
*old_rows
;
3041 /* Make a copy of the original rows of matrix m. */
3042 old_rows
= (struct glyph_row
*) alloca (m
->nrows
* sizeof *old_rows
);
3043 memcpy (old_rows
, m
->rows
, m
->nrows
* sizeof *old_rows
);
3045 for (i
= 0; i
< nlines
; ++i
)
3047 /* Frame relative line assigned to. */
3048 int frame_to
= i
+ unchanged_at_top
;
3050 /* Frame relative line assigned. */
3051 int frame_from
= copy_from
[i
] + unchanged_at_top
;
3053 /* Window relative line assigned to. */
3054 int window_to
= frame_to
- m
->matrix_y
;
3056 /* Window relative line assigned. */
3057 int window_from
= frame_from
- m
->matrix_y
;
3059 /* Is assigned line inside window? */
3060 int from_inside_window_p
3061 = window_from
>= 0 && window_from
< m
->matrix_h
;
3063 /* Is assigned to line inside window? */
3064 int to_inside_window_p
3065 = window_to
>= 0 && window_to
< m
->matrix_h
;
3067 if (from_inside_window_p
&& to_inside_window_p
)
3069 /* Enabled setting before assignment. */
3070 int enabled_before_p
;
3072 /* Do the assignment. The enabled_p flag is saved
3073 over the assignment because the old redisplay did
3075 enabled_before_p
= m
->rows
[window_to
].enabled_p
;
3076 m
->rows
[window_to
] = old_rows
[window_from
];
3077 m
->rows
[window_to
].enabled_p
= enabled_before_p
;
3079 /* If frame line is empty, window line is empty, too. */
3080 if (!retained_p
[copy_from
[i
]])
3081 m
->rows
[window_to
].enabled_p
= 0;
3083 else if (to_inside_window_p
)
3085 /* A copy between windows. This is an infrequent
3086 case not worth optimizing. */
3087 struct frame
*f
= XFRAME (w
->frame
);
3088 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3090 struct glyph_matrix
*m2
;
3093 w2
= frame_row_to_window (root
, frame_from
);
3094 /* ttn@surf.glug.org: when enabling menu bar using `emacs
3095 -nw', FROM_FRAME sometimes has no associated window.
3096 This check avoids a segfault if W2 is null. */
3099 m2
= w2
->current_matrix
;
3100 m2_from
= frame_from
- m2
->matrix_y
;
3101 copy_row_except_pointers (m
->rows
+ window_to
,
3102 m2
->rows
+ m2_from
);
3104 /* If frame line is empty, window line is empty, too. */
3105 if (!retained_p
[copy_from
[i
]])
3106 m
->rows
[window_to
].enabled_p
= 0;
3110 else if (from_inside_window_p
)
3114 /* If there was a copy between windows, make sure glyph
3115 pointers are in sync with the frame matrix. */
3117 sync_window_with_frame_matrix_rows (w
);
3119 /* Check that no pointers are lost. */
3123 /* Next window on same level. */
3124 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3131 /* Check that window and frame matrices agree about their
3132 understanding where glyphs of the rows are to find. For each
3133 window in the window tree rooted at W, check that rows in the
3134 matrices of leaf window agree with their frame matrices about
3138 check_window_matrix_pointers (struct window
*w
)
3142 if (!NILP (w
->hchild
))
3143 check_window_matrix_pointers (XWINDOW (w
->hchild
));
3144 else if (!NILP (w
->vchild
))
3145 check_window_matrix_pointers (XWINDOW (w
->vchild
));
3148 struct frame
*f
= XFRAME (w
->frame
);
3149 check_matrix_pointers (w
->desired_matrix
, f
->desired_matrix
);
3150 check_matrix_pointers (w
->current_matrix
, f
->current_matrix
);
3153 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3158 /* Check that window rows are slices of frame rows. WINDOW_MATRIX is
3159 a window and FRAME_MATRIX is the corresponding frame matrix. For
3160 each row in WINDOW_MATRIX check that it's a slice of the
3161 corresponding frame row. If it isn't, abort. */
3164 check_matrix_pointers (struct glyph_matrix
*window_matrix
,
3165 struct glyph_matrix
*frame_matrix
)
3167 /* Row number in WINDOW_MATRIX. */
3170 /* Row number corresponding to I in FRAME_MATRIX. */
3171 int j
= window_matrix
->matrix_y
;
3173 /* For all rows check that the row in the window matrix is a
3174 slice of the row in the frame matrix. If it isn't we didn't
3175 mirror an operation on the frame matrix correctly. */
3176 while (i
< window_matrix
->nrows
)
3178 if (!glyph_row_slice_p (window_matrix
->rows
+ i
,
3179 frame_matrix
->rows
+ j
))
3185 #endif /* GLYPH_DEBUG != 0 */
3189 /**********************************************************************
3190 VPOS and HPOS translations
3191 **********************************************************************/
3195 /* Translate vertical position VPOS which is relative to window W to a
3196 vertical position relative to W's frame. */
3199 window_to_frame_vpos (struct window
*w
, int vpos
)
3201 struct frame
*f
= XFRAME (w
->frame
);
3203 xassert (!FRAME_WINDOW_P (f
));
3204 xassert (vpos
>= 0 && vpos
<= w
->desired_matrix
->nrows
);
3205 vpos
+= WINDOW_TOP_EDGE_LINE (w
);
3206 xassert (vpos
>= 0 && vpos
<= FRAME_LINES (f
));
3211 /* Translate horizontal position HPOS which is relative to window W to
3212 a horizontal position relative to W's frame. */
3215 window_to_frame_hpos (struct window
*w
, int hpos
)
3217 xassert (!FRAME_WINDOW_P (XFRAME (w
->frame
)));
3218 hpos
+= WINDOW_LEFT_EDGE_COL (w
);
3222 #endif /* GLYPH_DEBUG */
3226 /**********************************************************************
3228 **********************************************************************/
3230 DEFUN ("redraw-frame", Fredraw_frame
, Sredraw_frame
, 1, 1, 0,
3231 doc
: /* Clear frame FRAME and output again what is supposed to appear on it. */)
3236 CHECK_LIVE_FRAME (frame
);
3239 /* Ignore redraw requests, if frame has no glyphs yet.
3240 (Implementation note: It still has to be checked why we are
3241 called so early here). */
3242 if (!glyphs_initialized_initially_p
)
3247 if (FRAME_MSDOS_P (f
))
3248 FRAME_TERMINAL (f
)->set_terminal_modes_hook (FRAME_TERMINAL (f
));
3251 clear_current_matrices (f
);
3253 if (FRAME_TERMCAP_P (f
))
3254 fflush (FRAME_TTY (f
)->output
);
3255 windows_or_buffers_changed
++;
3256 /* Mark all windows as inaccurate, so that every window will have
3257 its redisplay done. */
3258 mark_window_display_accurate (FRAME_ROOT_WINDOW (f
), 0);
3259 set_window_update_flags (XWINDOW (FRAME_ROOT_WINDOW (f
)), 1);
3265 /* Redraw frame F. This is nothing more than a call to the Lisp
3266 function redraw-frame. */
3269 redraw_frame (struct frame
*f
)
3272 XSETFRAME (frame
, f
);
3273 Fredraw_frame (frame
);
3277 DEFUN ("redraw-display", Fredraw_display
, Sredraw_display
, 0, 0, "",
3278 doc
: /* Clear and redisplay all visible frames. */)
3281 Lisp_Object tail
, frame
;
3283 FOR_EACH_FRAME (tail
, frame
)
3284 if (FRAME_VISIBLE_P (XFRAME (frame
)))
3285 Fredraw_frame (frame
);
3291 /* This is used when frame_garbaged is set. Call Fredraw_frame on all
3292 visible frames marked as garbaged. */
3295 redraw_garbaged_frames (void)
3297 Lisp_Object tail
, frame
;
3299 FOR_EACH_FRAME (tail
, frame
)
3300 if (FRAME_VISIBLE_P (XFRAME (frame
))
3301 && FRAME_GARBAGED_P (XFRAME (frame
)))
3302 Fredraw_frame (frame
);
3307 /***********************************************************************
3309 ***********************************************************************/
3311 /* Update frame F based on the data in desired matrices.
3313 If FORCE_P is non-zero, don't let redisplay be stopped by detecting
3314 pending input. If INHIBIT_HAIRY_ID_P is non-zero, don't try
3317 Value is non-zero if redisplay was stopped due to pending input. */
3320 update_frame (struct frame
*f
, int force_p
, int inhibit_hairy_id_p
)
3322 /* 1 means display has been paused because of pending input. */
3324 struct window
*root_window
= XWINDOW (f
->root_window
);
3326 if (redisplay_dont_pause
)
3328 #if PERIODIC_PREEMPTION_CHECKING
3329 else if (NILP (Vredisplay_preemption_period
))
3331 else if (!force_p
&& NUMBERP (Vredisplay_preemption_period
))
3334 double p
= XFLOATINT (Vredisplay_preemption_period
);
3337 if (detect_input_pending_ignore_squeezables ())
3344 usec
= (p
- sec
) * 1000000;
3346 EMACS_GET_TIME (tm
);
3347 EMACS_SET_SECS_USECS (preemption_period
, sec
, usec
);
3348 EMACS_ADD_TIME (preemption_next_check
, tm
, preemption_period
);
3352 if (FRAME_WINDOW_P (f
))
3354 /* We are working on window matrix basis. All windows whose
3355 flag must_be_updated_p is set have to be updated. */
3357 /* Record that we are not working on frame matrices. */
3358 set_frame_matrix_frame (NULL
);
3360 /* Update all windows in the window tree of F, maybe stopping
3361 when pending input is detected. */
3364 /* Update the menu bar on X frames that don't have toolkit
3366 if (WINDOWP (f
->menu_bar_window
))
3367 update_window (XWINDOW (f
->menu_bar_window
), 1);
3369 /* Update the tool-bar window, if present. */
3370 if (WINDOWP (f
->tool_bar_window
))
3372 struct window
*w
= XWINDOW (f
->tool_bar_window
);
3374 /* Update tool-bar window. */
3375 if (w
->must_be_updated_p
)
3379 update_window (w
, 1);
3380 w
->must_be_updated_p
= 0;
3382 /* Swap tool-bar strings. We swap because we want to
3384 tem
= f
->current_tool_bar_string
;
3385 f
->current_tool_bar_string
= f
->desired_tool_bar_string
;
3386 f
->desired_tool_bar_string
= tem
;
3391 /* Update windows. */
3392 paused_p
= update_window_tree (root_window
, force_p
);
3395 /* This flush is a performance bottleneck under X,
3396 and it doesn't seem to be necessary anyway (in general).
3397 It is necessary when resizing the window with the mouse, or
3398 at least the fringes are not redrawn in a timely manner. ++kfs */
3399 if (f
->force_flush_display_p
)
3401 FRAME_RIF (f
)->flush_display (f
);
3402 f
->force_flush_display_p
= 0;
3407 /* We are working on frame matrix basis. Set the frame on whose
3408 frame matrix we operate. */
3409 set_frame_matrix_frame (f
);
3411 /* Build F's desired matrix from window matrices. */
3412 build_frame_matrix (f
);
3414 /* Update the display */
3416 paused_p
= update_frame_1 (f
, force_p
, inhibit_hairy_id_p
);
3419 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
3421 if (FRAME_TTY (f
)->termscript
)
3422 fflush (FRAME_TTY (f
)->termscript
);
3423 if (FRAME_TERMCAP_P (f
))
3424 fflush (FRAME_TTY (f
)->output
);
3427 /* Check window matrices for lost pointers. */
3429 check_window_matrix_pointers (root_window
);
3430 add_frame_display_history (f
, paused_p
);
3434 #if PERIODIC_PREEMPTION_CHECKING
3437 /* Reset flags indicating that a window should be updated. */
3438 set_window_update_flags (root_window
, 0);
3440 display_completed
= !paused_p
;
3446 /************************************************************************
3447 Window-based updates
3448 ************************************************************************/
3450 /* Perform updates in window tree rooted at W. FORCE_P non-zero means
3451 don't stop updating when input is pending. */
3454 update_window_tree (struct window
*w
, int force_p
)
3458 while (w
&& !paused_p
)
3460 if (!NILP (w
->hchild
))
3461 paused_p
|= update_window_tree (XWINDOW (w
->hchild
), force_p
);
3462 else if (!NILP (w
->vchild
))
3463 paused_p
|= update_window_tree (XWINDOW (w
->vchild
), force_p
);
3464 else if (w
->must_be_updated_p
)
3465 paused_p
|= update_window (w
, force_p
);
3467 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3474 /* Update window W if its flag must_be_updated_p is non-zero. If
3475 FORCE_P is non-zero, don't stop updating if input is pending. */
3478 update_single_window (struct window
*w
, int force_p
)
3480 if (w
->must_be_updated_p
)
3482 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3484 /* Record that this is not a frame-based redisplay. */
3485 set_frame_matrix_frame (NULL
);
3487 if (redisplay_dont_pause
)
3489 #if PERIODIC_PREEMPTION_CHECKING
3490 else if (NILP (Vredisplay_preemption_period
))
3492 else if (!force_p
&& NUMBERP (Vredisplay_preemption_period
))
3495 double p
= XFLOATINT (Vredisplay_preemption_period
);
3499 usec
= (p
- sec
) * 1000000;
3501 EMACS_GET_TIME (tm
);
3502 EMACS_SET_SECS_USECS (preemption_period
, sec
, usec
);
3503 EMACS_ADD_TIME (preemption_next_check
, tm
, preemption_period
);
3509 update_window (w
, force_p
);
3512 /* Reset flag in W. */
3513 w
->must_be_updated_p
= 0;
3517 #ifdef HAVE_WINDOW_SYSTEM
3519 /* Redraw lines from the current matrix of window W that are
3520 overlapped by other rows. YB is bottom-most y-position in W. */
3523 redraw_overlapped_rows (struct window
*w
, int yb
)
3526 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3528 /* If rows overlapping others have been changed, the rows being
3529 overlapped have to be redrawn. This won't draw lines that have
3530 already been drawn in update_window_line because overlapped_p in
3531 desired rows is 0, so after row assignment overlapped_p in
3532 current rows is 0. */
3533 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
3535 struct glyph_row
*row
= w
->current_matrix
->rows
+ i
;
3537 if (!row
->enabled_p
)
3539 else if (row
->mode_line_p
)
3542 if (row
->overlapped_p
)
3544 enum glyph_row_area area
;
3546 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
3549 updated_area
= area
;
3550 FRAME_RIF (f
)->cursor_to (i
, 0, row
->y
,
3551 area
== TEXT_AREA
? row
->x
: 0);
3552 if (row
->used
[area
])
3553 FRAME_RIF (f
)->write_glyphs (row
->glyphs
[area
],
3555 FRAME_RIF (f
)->clear_end_of_line (-1);
3558 row
->overlapped_p
= 0;
3561 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
3567 /* Redraw lines from the current matrix of window W that overlap
3568 others. YB is bottom-most y-position in W. */
3571 redraw_overlapping_rows (struct window
*w
, int yb
)
3574 struct glyph_row
*row
;
3575 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
3577 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
3579 row
= w
->current_matrix
->rows
+ i
;
3581 if (!row
->enabled_p
)
3583 else if (row
->mode_line_p
)
3586 bottom_y
= MATRIX_ROW_BOTTOM_Y (row
);
3588 if (row
->overlapping_p
)
3592 if (MATRIX_ROW_OVERLAPS_PRED_P (row
) && i
> 0
3593 && !MATRIX_ROW (w
->current_matrix
, i
- 1)->overlapped_p
)
3594 overlaps
|= OVERLAPS_PRED
;
3595 if (MATRIX_ROW_OVERLAPS_SUCC_P (row
) && bottom_y
< yb
3596 && !MATRIX_ROW (w
->current_matrix
, i
+ 1)->overlapped_p
)
3597 overlaps
|= OVERLAPS_SUCC
;
3601 if (row
->used
[LEFT_MARGIN_AREA
])
3602 rif
->fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, overlaps
);
3604 if (row
->used
[TEXT_AREA
])
3605 rif
->fix_overlapping_area (w
, row
, TEXT_AREA
, overlaps
);
3607 if (row
->used
[RIGHT_MARGIN_AREA
])
3608 rif
->fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, overlaps
);
3610 /* Record in neighbour rows that ROW overwrites part of
3612 if (overlaps
& OVERLAPS_PRED
)
3613 MATRIX_ROW (w
->current_matrix
, i
- 1)->overlapped_p
= 1;
3614 if (overlaps
& OVERLAPS_SUCC
)
3615 MATRIX_ROW (w
->current_matrix
, i
+ 1)->overlapped_p
= 1;
3624 #endif /* HAVE_WINDOW_SYSTEM */
3629 /* Check that no row in the current matrix of window W is enabled
3630 which is below what's displayed in the window. */
3633 check_current_matrix_flags (struct window
*w
)
3635 int last_seen_p
= 0;
3636 int i
, yb
= window_text_bottom_y (w
);
3638 for (i
= 0; i
< w
->current_matrix
->nrows
- 1; ++i
)
3640 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
3641 if (!last_seen_p
&& MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
3643 else if (last_seen_p
&& row
->enabled_p
)
3648 #endif /* GLYPH_DEBUG */
3651 /* Update display of window W. FORCE_P non-zero means that we should
3652 not stop when detecting pending input. */
3655 update_window (struct window
*w
, int force_p
)
3657 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
3659 #if !PERIODIC_PREEMPTION_CHECKING
3660 int preempt_count
= baud_rate
/ 2400 + 1;
3662 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
3664 /* Check that W's frame doesn't have glyph matrices. */
3665 xassert (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))));
3668 /* Check pending input the first time so that we can quickly return. */
3669 #if !PERIODIC_PREEMPTION_CHECKING
3671 detect_input_pending_ignore_squeezables ();
3674 /* If forced to complete the update, or if no input is pending, do
3676 if (force_p
|| !input_pending
|| !NILP (do_mouse_tracking
))
3678 struct glyph_row
*row
, *end
;
3679 struct glyph_row
*mode_line_row
;
3680 struct glyph_row
*header_line_row
;
3681 int yb
, changed_p
= 0, mouse_face_overwritten_p
= 0, n_updated
;
3683 rif
->update_window_begin_hook (w
);
3684 yb
= window_text_bottom_y (w
);
3686 /* If window has a header line, update it before everything else.
3687 Adjust y-positions of other rows by the header line height. */
3688 row
= desired_matrix
->rows
;
3689 end
= row
+ desired_matrix
->nrows
- 1;
3691 if (row
->mode_line_p
)
3693 header_line_row
= row
;
3697 header_line_row
= NULL
;
3699 /* Update the mode line, if necessary. */
3700 mode_line_row
= MATRIX_MODE_LINE_ROW (desired_matrix
);
3701 if (mode_line_row
->mode_line_p
&& mode_line_row
->enabled_p
)
3703 mode_line_row
->y
= yb
;
3704 update_window_line (w
, MATRIX_ROW_VPOS (mode_line_row
,
3706 &mouse_face_overwritten_p
);
3709 /* Find first enabled row. Optimizations in redisplay_internal
3710 may lead to an update with only one row enabled. There may
3711 be also completely empty matrices. */
3712 while (row
< end
&& !row
->enabled_p
)
3715 /* Try reusing part of the display by copying. */
3716 if (row
< end
&& !desired_matrix
->no_scrolling_p
)
3718 int rc
= scrolling_window (w
, header_line_row
!= NULL
);
3721 /* All rows were found to be equal. */
3727 /* We've scrolled the display. */
3733 /* Update the rest of the lines. */
3734 for (n_updated
= 0; row
< end
&& (force_p
|| !input_pending
); ++row
)
3737 int vpos
= MATRIX_ROW_VPOS (row
, desired_matrix
);
3740 /* We'll have to play a little bit with when to
3741 detect_input_pending. If it's done too often,
3742 scrolling large windows with repeated scroll-up
3743 commands will too quickly pause redisplay. */
3744 #if PERIODIC_PREEMPTION_CHECKING
3748 EMACS_GET_TIME (tm
);
3749 EMACS_SUB_TIME (dif
, preemption_next_check
, tm
);
3750 if (EMACS_TIME_NEG_P (dif
))
3752 EMACS_ADD_TIME (preemption_next_check
, tm
, preemption_period
);
3753 if (detect_input_pending_ignore_squeezables ())
3758 if (!force_p
&& ++n_updated
% preempt_count
== 0)
3759 detect_input_pending_ignore_squeezables ();
3761 changed_p
|= update_window_line (w
, vpos
,
3762 &mouse_face_overwritten_p
);
3764 /* Mark all rows below the last visible one in the current
3765 matrix as invalid. This is necessary because of
3766 variable line heights. Consider the case of three
3767 successive redisplays, where the first displays 5
3768 lines, the second 3 lines, and the third 5 lines again.
3769 If the second redisplay wouldn't mark rows in the
3770 current matrix invalid, the third redisplay might be
3771 tempted to optimize redisplay based on lines displayed
3772 in the first redisplay. */
3773 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
3774 for (i
= vpos
+ 1; i
< w
->current_matrix
->nrows
- 1; ++i
)
3775 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
3778 /* Was display preempted? */
3779 paused_p
= row
< end
;
3783 /* Update the header line after scrolling because a new header
3784 line would otherwise overwrite lines at the top of the window
3785 that can be scrolled. */
3786 if (header_line_row
&& header_line_row
->enabled_p
)
3788 header_line_row
->y
= 0;
3789 update_window_line (w
, 0, &mouse_face_overwritten_p
);
3792 /* Fix the appearance of overlapping/overlapped rows. */
3793 if (!paused_p
&& !w
->pseudo_window_p
)
3795 #ifdef HAVE_WINDOW_SYSTEM
3796 if (changed_p
&& rif
->fix_overlapping_area
)
3798 redraw_overlapped_rows (w
, yb
);
3799 redraw_overlapping_rows (w
, yb
);
3803 /* Make cursor visible at cursor position of W. */
3804 set_window_cursor_after_update (w
);
3806 #if 0 /* Check that current matrix invariants are satisfied. This is
3807 for debugging only. See the comment of check_matrix_invariants. */
3808 IF_DEBUG (check_matrix_invariants (w
));
3813 /* Remember the redisplay method used to display the matrix. */
3814 strcpy (w
->current_matrix
->method
, w
->desired_matrix
->method
);
3817 #ifdef HAVE_WINDOW_SYSTEM
3818 update_window_fringes (w
, 0);
3821 /* End the update of window W. Don't set the cursor if we
3822 paused updating the display because in this case,
3823 set_window_cursor_after_update hasn't been called, and
3824 output_cursor doesn't contain the cursor location. */
3825 rif
->update_window_end_hook (w
, !paused_p
, mouse_face_overwritten_p
);
3831 /* check_current_matrix_flags (w); */
3832 add_window_display_history (w
, w
->current_matrix
->method
, paused_p
);
3835 clear_glyph_matrix (desired_matrix
);
3841 /* Update the display of area AREA in window W, row number VPOS.
3842 AREA can be either LEFT_MARGIN_AREA or RIGHT_MARGIN_AREA. */
3845 update_marginal_area (struct window
*w
, int area
, int vpos
)
3847 struct glyph_row
*desired_row
= MATRIX_ROW (w
->desired_matrix
, vpos
);
3848 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
3850 /* Let functions in xterm.c know what area subsequent X positions
3851 will be relative to. */
3852 updated_area
= area
;
3854 /* Set cursor to start of glyphs, write them, and clear to the end
3855 of the area. I don't think that something more sophisticated is
3856 necessary here, since marginal areas will not be the default. */
3857 rif
->cursor_to (vpos
, 0, desired_row
->y
, 0);
3858 if (desired_row
->used
[area
])
3859 rif
->write_glyphs (desired_row
->glyphs
[area
], desired_row
->used
[area
]);
3860 rif
->clear_end_of_line (-1);
3864 /* Update the display of the text area of row VPOS in window W.
3865 Value is non-zero if display has changed. */
3868 update_text_area (struct window
*w
, int vpos
)
3870 struct glyph_row
*current_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
3871 struct glyph_row
*desired_row
= MATRIX_ROW (w
->desired_matrix
, vpos
);
3872 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
3875 /* Let functions in xterm.c know what area subsequent X positions
3876 will be relative to. */
3877 updated_area
= TEXT_AREA
;
3879 /* If rows are at different X or Y, or rows have different height,
3880 or the current row is marked invalid, write the entire line. */
3881 if (!current_row
->enabled_p
3882 || desired_row
->y
!= current_row
->y
3883 || desired_row
->ascent
!= current_row
->ascent
3884 || desired_row
->phys_ascent
!= current_row
->phys_ascent
3885 || desired_row
->phys_height
!= current_row
->phys_height
3886 || desired_row
->visible_height
!= current_row
->visible_height
3887 || current_row
->overlapped_p
3888 /* This next line is necessary for correctly redrawing
3889 mouse-face areas after scrolling and other operations.
3890 However, it causes excessive flickering when mouse is moved
3891 across the mode line. Luckily, turning it off for the mode
3892 line doesn't seem to hurt anything. -- cyd.
3893 But it is still needed for the header line. -- kfs. */
3894 || (current_row
->mouse_face_p
3895 && !(current_row
->mode_line_p
&& vpos
> 0))
3896 || current_row
->x
!= desired_row
->x
)
3898 rif
->cursor_to (vpos
, 0, desired_row
->y
, desired_row
->x
);
3900 if (desired_row
->used
[TEXT_AREA
])
3901 rif
->write_glyphs (desired_row
->glyphs
[TEXT_AREA
],
3902 desired_row
->used
[TEXT_AREA
]);
3904 /* Clear to end of window. */
3905 rif
->clear_end_of_line (-1);
3908 /* This erases the cursor. We do this here because
3909 notice_overwritten_cursor cannot easily check this, which
3910 might indicate that the whole functionality of
3911 notice_overwritten_cursor would better be implemented here.
3912 On the other hand, we need notice_overwritten_cursor as long
3913 as mouse highlighting is done asynchronously outside of
3915 if (vpos
== w
->phys_cursor
.vpos
)
3916 w
->phys_cursor_on_p
= 0;
3921 struct glyph
*current_glyph
= current_row
->glyphs
[TEXT_AREA
];
3922 struct glyph
*desired_glyph
= desired_row
->glyphs
[TEXT_AREA
];
3923 int overlapping_glyphs_p
= current_row
->contains_overlapping_glyphs_p
;
3924 int desired_stop_pos
= desired_row
->used
[TEXT_AREA
];
3925 int abort_skipping
= 0;
3927 /* If the desired row extends its face to the text area end, and
3928 unless the current row also does so at the same position,
3929 make sure we write at least one glyph, so that the face
3930 extension actually takes place. */
3931 if (MATRIX_ROW_EXTENDS_FACE_P (desired_row
)
3932 && (desired_stop_pos
< current_row
->used
[TEXT_AREA
]
3933 || (desired_stop_pos
== current_row
->used
[TEXT_AREA
]
3934 && !MATRIX_ROW_EXTENDS_FACE_P (current_row
))))
3937 stop
= min (current_row
->used
[TEXT_AREA
], desired_stop_pos
);
3941 /* Loop over glyphs that current and desired row may have
3945 int can_skip_p
= !abort_skipping
;
3947 /* Skip over glyphs that both rows have in common. These
3948 don't have to be written. We can't skip if the last
3949 current glyph overlaps the glyph to its right. For
3950 example, consider a current row of `if ' with the `f' in
3951 Courier bold so that it overlaps the ` ' to its right.
3952 If the desired row is ` ', we would skip over the space
3953 after the `if' and there would remain a pixel from the
3954 `f' on the screen. */
3955 if (overlapping_glyphs_p
&& i
> 0)
3957 struct glyph
*glyph
= ¤t_row
->glyphs
[TEXT_AREA
][i
- 1];
3960 rif
->get_glyph_overhangs (glyph
, XFRAME (w
->frame
),
3962 can_skip_p
= (right
== 0 && !abort_skipping
);
3970 && GLYPH_EQUAL_P (desired_glyph
, current_glyph
))
3972 x
+= desired_glyph
->pixel_width
;
3973 ++desired_glyph
, ++current_glyph
, ++i
;
3976 /* Consider the case that the current row contains "xxx
3977 ppp ggg" in italic Courier font, and the desired row
3978 is "xxx ggg". The character `p' has lbearing, `g'
3979 has not. The loop above will stop in front of the
3980 first `p' in the current row. If we would start
3981 writing glyphs there, we wouldn't erase the lbearing
3982 of the `p'. The rest of the lbearing problem is then
3983 taken care of by draw_glyphs. */
3984 if (overlapping_glyphs_p
3986 && i
< current_row
->used
[TEXT_AREA
]
3987 && (current_row
->used
[TEXT_AREA
]
3988 != desired_row
->used
[TEXT_AREA
]))
3992 rif
->get_glyph_overhangs (current_glyph
, XFRAME (w
->frame
),
3994 while (left
> 0 && i
> 0)
3996 --i
, --desired_glyph
, --current_glyph
;
3997 x
-= desired_glyph
->pixel_width
;
3998 left
-= desired_glyph
->pixel_width
;
4001 /* Abort the skipping algorithm if we end up before
4002 our starting point, to avoid looping (bug#1070).
4003 This can happen when the lbearing is larger than
4005 abort_skipping
= (i
< start_hpos
);
4009 /* Try to avoid writing the entire rest of the desired row
4010 by looking for a resync point. This mainly prevents
4011 mode line flickering in the case the mode line is in
4012 fixed-pitch font, which it usually will be. */
4013 if (i
< desired_row
->used
[TEXT_AREA
])
4015 int start_x
= x
, start_hpos
= i
;
4016 struct glyph
*start
= desired_glyph
;
4018 int skip_first_p
= !can_skip_p
;
4020 /* Find the next glyph that's equal again. */
4023 || !GLYPH_EQUAL_P (desired_glyph
, current_glyph
))
4026 x
+= desired_glyph
->pixel_width
;
4027 current_x
+= current_glyph
->pixel_width
;
4028 ++desired_glyph
, ++current_glyph
, ++i
;
4032 if (i
== start_hpos
|| x
!= current_x
)
4036 desired_glyph
= start
;
4040 rif
->cursor_to (vpos
, start_hpos
, desired_row
->y
, start_x
);
4041 rif
->write_glyphs (start
, i
- start_hpos
);
4046 /* Write the rest. */
4047 if (i
< desired_row
->used
[TEXT_AREA
])
4049 rif
->cursor_to (vpos
, i
, desired_row
->y
, x
);
4050 rif
->write_glyphs (desired_glyph
, desired_row
->used
[TEXT_AREA
] - i
);
4054 /* Maybe clear to end of line. */
4055 if (MATRIX_ROW_EXTENDS_FACE_P (desired_row
))
4057 /* If new row extends to the end of the text area, nothing
4058 has to be cleared, if and only if we did a write_glyphs
4059 above. This is made sure by setting desired_stop_pos
4060 appropriately above. */
4061 xassert (i
< desired_row
->used
[TEXT_AREA
]
4062 || ((desired_row
->used
[TEXT_AREA
]
4063 == current_row
->used
[TEXT_AREA
])
4064 && MATRIX_ROW_EXTENDS_FACE_P (current_row
)));
4066 else if (MATRIX_ROW_EXTENDS_FACE_P (current_row
))
4068 /* If old row extends to the end of the text area, clear. */
4069 if (i
>= desired_row
->used
[TEXT_AREA
])
4070 rif
->cursor_to (vpos
, i
, desired_row
->y
,
4071 desired_row
->pixel_width
);
4072 rif
->clear_end_of_line (-1);
4075 else if (desired_row
->pixel_width
< current_row
->pixel_width
)
4077 /* Otherwise clear to the end of the old row. Everything
4078 after that position should be clear already. */
4081 if (i
>= desired_row
->used
[TEXT_AREA
])
4082 rif
->cursor_to (vpos
, i
, desired_row
->y
,
4083 desired_row
->pixel_width
);
4085 /* If cursor is displayed at the end of the line, make sure
4086 it's cleared. Nowadays we don't have a phys_cursor_glyph
4087 with which to erase the cursor (because this method
4088 doesn't work with lbearing/rbearing), so we must do it
4090 if (vpos
== w
->phys_cursor
.vpos
4091 && (desired_row
->reversed_p
4092 ? (w
->phys_cursor
.hpos
< 0)
4093 : (w
->phys_cursor
.hpos
>= desired_row
->used
[TEXT_AREA
])))
4095 w
->phys_cursor_on_p
= 0;
4099 x
= current_row
->pixel_width
;
4100 rif
->clear_end_of_line (x
);
4109 /* Update row VPOS in window W. Value is non-zero if display has been
4113 update_window_line (struct window
*w
, int vpos
, int *mouse_face_overwritten_p
)
4115 struct glyph_row
*current_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
4116 struct glyph_row
*desired_row
= MATRIX_ROW (w
->desired_matrix
, vpos
);
4117 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
4120 /* Set the row being updated. This is important to let xterm.c
4121 know what line height values are in effect. */
4122 updated_row
= desired_row
;
4124 /* A row can be completely invisible in case a desired matrix was
4125 built with a vscroll and then make_cursor_line_fully_visible shifts
4126 the matrix. Make sure to make such rows current anyway, since
4127 we need the correct y-position, for example, in the current matrix. */
4128 if (desired_row
->mode_line_p
4129 || desired_row
->visible_height
> 0)
4131 xassert (desired_row
->enabled_p
);
4133 /* Update display of the left margin area, if there is one. */
4134 if (!desired_row
->full_width_p
4135 && !NILP (w
->left_margin_cols
))
4138 update_marginal_area (w
, LEFT_MARGIN_AREA
, vpos
);
4141 /* Update the display of the text area. */
4142 if (update_text_area (w
, vpos
))
4145 if (current_row
->mouse_face_p
)
4146 *mouse_face_overwritten_p
= 1;
4149 /* Update display of the right margin area, if there is one. */
4150 if (!desired_row
->full_width_p
4151 && !NILP (w
->right_margin_cols
))
4154 update_marginal_area (w
, RIGHT_MARGIN_AREA
, vpos
);
4157 /* Draw truncation marks etc. */
4158 if (!current_row
->enabled_p
4159 || desired_row
->y
!= current_row
->y
4160 || desired_row
->visible_height
!= current_row
->visible_height
4161 || desired_row
->cursor_in_fringe_p
!= current_row
->cursor_in_fringe_p
4162 || desired_row
->overlay_arrow_bitmap
!= current_row
->overlay_arrow_bitmap
4163 || current_row
->redraw_fringe_bitmaps_p
4164 || desired_row
->mode_line_p
!= current_row
->mode_line_p
4165 || desired_row
->exact_window_width_line_p
!= current_row
->exact_window_width_line_p
4166 || (MATRIX_ROW_CONTINUATION_LINE_P (desired_row
)
4167 != MATRIX_ROW_CONTINUATION_LINE_P (current_row
)))
4168 rif
->after_update_window_line_hook (desired_row
);
4171 /* Update current_row from desired_row. */
4172 make_current (w
->desired_matrix
, w
->current_matrix
, vpos
);
4178 /* Set the cursor after an update of window W. This function may only
4179 be called from update_window. */
4182 set_window_cursor_after_update (struct window
*w
)
4184 struct frame
*f
= XFRAME (w
->frame
);
4185 struct redisplay_interface
*rif
= FRAME_RIF (f
);
4186 int cx
, cy
, vpos
, hpos
;
4188 /* Not intended for frame matrix updates. */
4189 xassert (FRAME_WINDOW_P (f
));
4191 if (cursor_in_echo_area
4192 && !NILP (echo_area_buffer
[0])
4193 /* If we are showing a message instead of the mini-buffer,
4194 show the cursor for the message instead. */
4195 && XWINDOW (minibuf_window
) == w
4196 && EQ (minibuf_window
, echo_area_window
)
4197 /* These cases apply only to the frame that contains
4198 the active mini-buffer window. */
4199 && FRAME_HAS_MINIBUF_P (f
)
4200 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
4202 cx
= cy
= vpos
= hpos
= 0;
4204 if (cursor_in_echo_area
>= 0)
4206 /* If the mini-buffer is several lines high, find the last
4207 line that has any text on it. Note: either all lines
4208 are enabled or none. Otherwise we wouldn't be able to
4210 struct glyph_row
*row
, *last_row
;
4211 struct glyph
*glyph
;
4212 int yb
= window_text_bottom_y (w
);
4215 row
= w
->current_matrix
->rows
;
4216 while (row
->enabled_p
4217 && (last_row
== NULL
4218 || MATRIX_ROW_BOTTOM_Y (row
) <= yb
))
4220 if (row
->used
[TEXT_AREA
]
4221 && row
->glyphs
[TEXT_AREA
][0].charpos
>= 0)
4228 struct glyph
*start
= last_row
->glyphs
[TEXT_AREA
];
4229 struct glyph
*last
= start
+ last_row
->used
[TEXT_AREA
] - 1;
4231 while (last
> start
&& last
->charpos
< 0)
4234 for (glyph
= start
; glyph
< last
; ++glyph
)
4236 cx
+= glyph
->pixel_width
;
4241 vpos
= MATRIX_ROW_VPOS (last_row
, w
->current_matrix
);
4249 hpos
= w
->cursor
.hpos
;
4250 vpos
= w
->cursor
.vpos
;
4253 /* Window cursor can be out of sync for horizontally split windows. */
4254 hpos
= max (-1, hpos
); /* -1 is for when cursor is on the left fringe */
4255 hpos
= min (w
->current_matrix
->matrix_w
- 1, hpos
);
4256 vpos
= max (0, vpos
);
4257 vpos
= min (w
->current_matrix
->nrows
- 1, vpos
);
4258 rif
->cursor_to (vpos
, hpos
, cy
, cx
);
4262 /* Set WINDOW->must_be_updated_p to ON_P for all windows in the window
4263 tree rooted at W. */
4266 set_window_update_flags (struct window
*w
, int on_p
)
4270 if (!NILP (w
->hchild
))
4271 set_window_update_flags (XWINDOW (w
->hchild
), on_p
);
4272 else if (!NILP (w
->vchild
))
4273 set_window_update_flags (XWINDOW (w
->vchild
), on_p
);
4275 w
->must_be_updated_p
= on_p
;
4277 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4283 /***********************************************************************
4284 Window-Based Scrolling
4285 ***********************************************************************/
4287 /* Structure describing rows in scrolling_window. */
4291 /* Number of occurrences of this row in desired and current matrix. */
4292 int old_uses
, new_uses
;
4294 /* Vpos of row in new matrix. */
4295 int new_line_number
;
4297 /* Bucket index of this row_entry in the hash table row_table. */
4300 /* The row described by this entry. */
4301 struct glyph_row
*row
;
4303 /* Hash collision chain. */
4304 struct row_entry
*next
;
4307 /* A pool to allocate row_entry structures from, and the size of the
4308 pool. The pool is reallocated in scrolling_window when we find
4309 that we need a larger one. */
4311 static struct row_entry
*row_entry_pool
;
4312 static int row_entry_pool_size
;
4314 /* Index of next free entry in row_entry_pool. */
4316 static int row_entry_idx
;
4318 /* The hash table used during scrolling, and the table's size. This
4319 table is used to quickly identify equal rows in the desired and
4322 static struct row_entry
**row_table
;
4323 static int row_table_size
;
4325 /* Vectors of pointers to row_entry structures belonging to the
4326 current and desired matrix, and the size of the vectors. */
4328 static struct row_entry
**old_lines
, **new_lines
;
4329 static int old_lines_size
, new_lines_size
;
4331 /* A pool to allocate run structures from, and its size. */
4333 static struct run
*run_pool
;
4334 static int runs_size
;
4336 /* A vector of runs of lines found during scrolling. */
4338 static struct run
**runs
;
4340 /* Add glyph row ROW to the scrolling hash table during the scrolling
4343 static INLINE
struct row_entry
*
4344 add_row_entry (struct window
*w
, struct glyph_row
*row
)
4346 struct row_entry
*entry
;
4347 int i
= row
->hash
% row_table_size
;
4349 entry
= row_table
[i
];
4350 while (entry
&& !row_equal_p (w
, entry
->row
, row
, 1))
4351 entry
= entry
->next
;
4355 entry
= row_entry_pool
+ row_entry_idx
++;
4357 entry
->old_uses
= entry
->new_uses
= 0;
4358 entry
->new_line_number
= 0;
4360 entry
->next
= row_table
[i
];
4361 row_table
[i
] = entry
;
4368 /* Try to reuse part of the current display of W by scrolling lines.
4369 HEADER_LINE_P non-zero means W has a header line.
4371 The algorithm is taken from Communications of the ACM, Apr78 "A
4372 Technique for Isolating Differences Between Files." It should take
4375 A short outline of the steps of the algorithm
4377 1. Skip lines equal at the start and end of both matrices.
4379 2. Enter rows in the current and desired matrix into a symbol
4380 table, counting how often they appear in both matrices.
4382 3. Rows that appear exactly once in both matrices serve as anchors,
4383 i.e. we assume that such lines are likely to have been moved.
4385 4. Starting from anchor lines, extend regions to be scrolled both
4386 forward and backward.
4390 -1 if all rows were found to be equal.
4391 0 to indicate that we did not scroll the display, or
4392 1 if we did scroll. */
4395 scrolling_window (struct window
*w
, int header_line_p
)
4397 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
4398 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
4399 int yb
= window_text_bottom_y (w
);
4400 int i
, j
, first_old
, first_new
, last_old
, last_new
;
4401 int nruns
, nbytes
, n
, run_idx
;
4402 struct row_entry
*entry
;
4403 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
4405 /* Skip over rows equal at the start. */
4406 for (i
= header_line_p
? 1 : 0; i
< current_matrix
->nrows
- 1; ++i
)
4408 struct glyph_row
*d
= MATRIX_ROW (desired_matrix
, i
);
4409 struct glyph_row
*c
= MATRIX_ROW (current_matrix
, i
);
4413 && !d
->redraw_fringe_bitmaps_p
4415 && MATRIX_ROW_BOTTOM_Y (c
) <= yb
4416 && MATRIX_ROW_BOTTOM_Y (d
) <= yb
4417 && row_equal_p (w
, c
, d
, 1))
4426 /* Give up if some rows in the desired matrix are not enabled. */
4427 if (!MATRIX_ROW (desired_matrix
, i
)->enabled_p
)
4430 first_old
= first_new
= i
;
4432 /* Set last_new to the index + 1 of the last enabled row in the
4435 while (i
< desired_matrix
->nrows
- 1
4436 && MATRIX_ROW (desired_matrix
, i
)->enabled_p
4437 && MATRIX_ROW_BOTTOM_Y (MATRIX_ROW (desired_matrix
, i
)) <= yb
)
4440 if (!MATRIX_ROW (desired_matrix
, i
)->enabled_p
)
4445 /* Set last_old to the index + 1 of the last enabled row in the
4446 current matrix. We don't look at the enabled flag here because
4447 we plan to reuse part of the display even if other parts are
4450 while (i
< current_matrix
->nrows
- 1)
4452 int bottom
= MATRIX_ROW_BOTTOM_Y (MATRIX_ROW (current_matrix
, i
));
4461 /* Skip over rows equal at the bottom. */
4464 while (i
- 1 > first_new
4465 && j
- 1 > first_old
4466 && MATRIX_ROW (current_matrix
, i
- 1)->enabled_p
4467 && (MATRIX_ROW (current_matrix
, i
- 1)->y
4468 == MATRIX_ROW (desired_matrix
, j
- 1)->y
)
4469 && !MATRIX_ROW (desired_matrix
, j
- 1)->redraw_fringe_bitmaps_p
4471 MATRIX_ROW (desired_matrix
, i
- 1),
4472 MATRIX_ROW (current_matrix
, j
- 1), 1))
4477 /* Nothing to do if all rows are equal. */
4478 if (last_new
== first_new
)
4481 /* Reallocate vectors, tables etc. if necessary. */
4483 if (current_matrix
->nrows
> old_lines_size
)
4485 old_lines_size
= current_matrix
->nrows
;
4486 nbytes
= old_lines_size
* sizeof *old_lines
;
4487 old_lines
= (struct row_entry
**) xrealloc (old_lines
, nbytes
);
4490 if (desired_matrix
->nrows
> new_lines_size
)
4492 new_lines_size
= desired_matrix
->nrows
;
4493 nbytes
= new_lines_size
* sizeof *new_lines
;
4494 new_lines
= (struct row_entry
**) xrealloc (new_lines
, nbytes
);
4497 n
= desired_matrix
->nrows
+ current_matrix
->nrows
;
4498 if (3 * n
> row_table_size
)
4500 row_table_size
= next_almost_prime (3 * n
);
4501 nbytes
= row_table_size
* sizeof *row_table
;
4502 row_table
= (struct row_entry
**) xrealloc (row_table
, nbytes
);
4503 memset (row_table
, 0, nbytes
);
4506 if (n
> row_entry_pool_size
)
4508 row_entry_pool_size
= n
;
4509 nbytes
= row_entry_pool_size
* sizeof *row_entry_pool
;
4510 row_entry_pool
= (struct row_entry
*) xrealloc (row_entry_pool
, nbytes
);
4513 if (desired_matrix
->nrows
> runs_size
)
4515 runs_size
= desired_matrix
->nrows
;
4516 nbytes
= runs_size
* sizeof *runs
;
4517 runs
= (struct run
**) xrealloc (runs
, nbytes
);
4518 nbytes
= runs_size
* sizeof *run_pool
;
4519 run_pool
= (struct run
*) xrealloc (run_pool
, nbytes
);
4522 nruns
= run_idx
= 0;
4525 /* Add rows from the current and desired matrix to the hash table
4526 row_hash_table to be able to find equal ones quickly. */
4528 for (i
= first_old
; i
< last_old
; ++i
)
4530 if (MATRIX_ROW (current_matrix
, i
)->enabled_p
)
4532 entry
= add_row_entry (w
, MATRIX_ROW (current_matrix
, i
));
4533 old_lines
[i
] = entry
;
4537 old_lines
[i
] = NULL
;
4540 for (i
= first_new
; i
< last_new
; ++i
)
4542 xassert (MATRIX_ROW_ENABLED_P (desired_matrix
, i
));
4543 entry
= add_row_entry (w
, MATRIX_ROW (desired_matrix
, i
));
4545 entry
->new_line_number
= i
;
4546 new_lines
[i
] = entry
;
4549 /* Identify moves based on lines that are unique and equal
4550 in both matrices. */
4551 for (i
= first_old
; i
< last_old
;)
4553 && old_lines
[i
]->old_uses
== 1
4554 && old_lines
[i
]->new_uses
== 1)
4557 int new_line
= old_lines
[i
]->new_line_number
;
4558 struct run
*run
= run_pool
+ run_idx
++;
4561 run
->current_vpos
= i
;
4562 run
->current_y
= MATRIX_ROW (current_matrix
, i
)->y
;
4563 run
->desired_vpos
= new_line
;
4564 run
->desired_y
= MATRIX_ROW (desired_matrix
, new_line
)->y
;
4566 run
->height
= MATRIX_ROW (current_matrix
, i
)->height
;
4568 /* Extend backward. */
4571 while (j
> first_old
4573 && old_lines
[j
] == new_lines
[k
])
4575 int h
= MATRIX_ROW (current_matrix
, j
)->height
;
4576 --run
->current_vpos
;
4577 --run
->desired_vpos
;
4580 run
->desired_y
-= h
;
4581 run
->current_y
-= h
;
4585 /* Extend forward. */
4590 && old_lines
[j
] == new_lines
[k
])
4592 int h
= MATRIX_ROW (current_matrix
, j
)->height
;
4598 /* Insert run into list of all runs. Order runs by copied
4599 pixel lines. Note that we record runs that don't have to
4600 be copied because they are already in place. This is done
4601 because we can avoid calling update_window_line in this
4603 for (j
= 0; j
< nruns
&& runs
[j
]->height
> run
->height
; ++j
)
4605 for (k
= nruns
; k
> j
; --k
)
4606 runs
[k
] = runs
[k
- 1];
4615 /* Do the moves. Do it in a way that we don't overwrite something
4616 we want to copy later on. This is not solvable in general
4617 because there is only one display and we don't have a way to
4618 exchange areas on this display. Example:
4620 +-----------+ +-----------+
4622 +-----------+ --> +-----------+
4624 +-----------+ +-----------+
4626 Instead, prefer bigger moves, and invalidate moves that would
4627 copy from where we copied to. */
4629 for (i
= 0; i
< nruns
; ++i
)
4630 if (runs
[i
]->nrows
> 0)
4632 struct run
*r
= runs
[i
];
4634 /* Copy on the display. */
4635 if (r
->current_y
!= r
->desired_y
)
4637 rif
->scroll_run_hook (w
, r
);
4639 /* Invalidate runs that copy from where we copied to. */
4640 for (j
= i
+ 1; j
< nruns
; ++j
)
4642 struct run
*p
= runs
[j
];
4644 if ((p
->current_y
>= r
->desired_y
4645 && p
->current_y
< r
->desired_y
+ r
->height
)
4646 || (p
->current_y
+ p
->height
>= r
->desired_y
4647 && (p
->current_y
+ p
->height
4648 < r
->desired_y
+ r
->height
)))
4653 /* Assign matrix rows. */
4654 for (j
= 0; j
< r
->nrows
; ++j
)
4656 struct glyph_row
*from
, *to
;
4657 int to_overlapped_p
;
4659 to
= MATRIX_ROW (current_matrix
, r
->desired_vpos
+ j
);
4660 from
= MATRIX_ROW (desired_matrix
, r
->desired_vpos
+ j
);
4661 to_overlapped_p
= to
->overlapped_p
;
4662 if (!from
->mode_line_p
&& !w
->pseudo_window_p
4663 && (to
->left_fringe_bitmap
!= from
->left_fringe_bitmap
4664 || to
->right_fringe_bitmap
!= from
->right_fringe_bitmap
4665 || to
->left_fringe_face_id
!= from
->left_fringe_face_id
4666 || to
->right_fringe_face_id
!= from
->right_fringe_face_id
4667 || to
->overlay_arrow_bitmap
!= from
->overlay_arrow_bitmap
))
4668 from
->redraw_fringe_bitmaps_p
= 1;
4669 assign_row (to
, from
);
4670 to
->enabled_p
= 1, from
->enabled_p
= 0;
4671 to
->overlapped_p
= to_overlapped_p
;
4675 /* Clear the hash table, for the next time. */
4676 for (i
= 0; i
< row_entry_idx
; ++i
)
4677 row_table
[row_entry_pool
[i
].bucket
] = NULL
;
4679 /* Value is > 0 to indicate that we scrolled the display. */
4685 /************************************************************************
4687 ************************************************************************/
4689 /* Update the desired frame matrix of frame F.
4691 FORCE_P non-zero means that the update should not be stopped by
4692 pending input. INHIBIT_HAIRY_ID_P non-zero means that scrolling
4693 should not be tried.
4695 Value is non-zero if update was stopped due to pending input. */
4698 update_frame_1 (struct frame
*f
, int force_p
, int inhibit_id_p
)
4700 /* Frame matrices to work on. */
4701 struct glyph_matrix
*current_matrix
= f
->current_matrix
;
4702 struct glyph_matrix
*desired_matrix
= f
->desired_matrix
;
4705 int preempt_count
= baud_rate
/ 2400 + 1;
4707 xassert (current_matrix
&& desired_matrix
);
4709 if (baud_rate
!= FRAME_COST_BAUD_RATE (f
))
4710 calculate_costs (f
);
4712 if (preempt_count
<= 0)
4715 #if !PERIODIC_PREEMPTION_CHECKING
4716 if (!force_p
&& detect_input_pending_ignore_squeezables ())
4723 /* If we cannot insert/delete lines, it's no use trying it. */
4724 if (!FRAME_LINE_INS_DEL_OK (f
))
4727 /* See if any of the desired lines are enabled; don't compute for
4728 i/d line if just want cursor motion. */
4729 for (i
= 0; i
< desired_matrix
->nrows
; i
++)
4730 if (MATRIX_ROW_ENABLED_P (desired_matrix
, i
))
4733 /* Try doing i/d line, if not yet inhibited. */
4734 if (!inhibit_id_p
&& i
< desired_matrix
->nrows
)
4735 force_p
|= scrolling (f
);
4737 /* Update the individual lines as needed. Do bottom line first. */
4738 if (MATRIX_ROW_ENABLED_P (desired_matrix
, desired_matrix
->nrows
- 1))
4739 update_frame_line (f
, desired_matrix
->nrows
- 1);
4741 /* Now update the rest of the lines. */
4742 for (i
= 0; i
< desired_matrix
->nrows
- 1 && (force_p
|| !input_pending
); i
++)
4744 if (MATRIX_ROW_ENABLED_P (desired_matrix
, i
))
4746 if (FRAME_TERMCAP_P (f
))
4748 /* Flush out every so many lines.
4749 Also flush out if likely to have more than 1k buffered
4750 otherwise. I'm told that some telnet connections get
4751 really screwed by more than 1k output at once. */
4752 FILE *display_output
= FRAME_TTY (f
)->output
;
4755 int outq
= PENDING_OUTPUT_COUNT (display_output
);
4757 || (outq
> 20 && ((i
- 1) % preempt_count
== 0)))
4759 fflush (display_output
);
4760 if (preempt_count
== 1)
4762 #ifdef EMACS_OUTQSIZE
4763 if (EMACS_OUTQSIZE (0, &outq
) < 0)
4764 /* Probably not a tty. Ignore the error and reset
4766 outq
= PENDING_OUTPUT_COUNT (FRAME_TTY (f
->output
));
4769 if (baud_rate
<= outq
&& baud_rate
> 0)
4770 sleep (outq
/ baud_rate
);
4776 #if PERIODIC_PREEMPTION_CHECKING
4780 EMACS_GET_TIME (tm
);
4781 EMACS_SUB_TIME (dif
, preemption_next_check
, tm
);
4782 if (EMACS_TIME_NEG_P (dif
))
4784 EMACS_ADD_TIME (preemption_next_check
, tm
, preemption_period
);
4785 if (detect_input_pending_ignore_squeezables ())
4790 if (!force_p
&& (i
- 1) % preempt_count
== 0)
4791 detect_input_pending_ignore_squeezables ();
4794 update_frame_line (f
, i
);
4798 pause
= (i
< FRAME_LINES (f
) - 1) ? i
: 0;
4800 /* Now just clean up termcap drivers and set cursor, etc. */
4803 if ((cursor_in_echo_area
4804 /* If we are showing a message instead of the mini-buffer,
4805 show the cursor for the message instead of for the
4806 (now hidden) mini-buffer contents. */
4807 || (EQ (minibuf_window
, selected_window
)
4808 && EQ (minibuf_window
, echo_area_window
)
4809 && !NILP (echo_area_buffer
[0])))
4810 /* These cases apply only to the frame that contains
4811 the active mini-buffer window. */
4812 && FRAME_HAS_MINIBUF_P (f
)
4813 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
4815 int top
= WINDOW_TOP_EDGE_LINE (XWINDOW (FRAME_MINIBUF_WINDOW (f
)));
4818 if (cursor_in_echo_area
< 0)
4820 /* Negative value of cursor_in_echo_area means put
4821 cursor at beginning of line. */
4827 /* Positive value of cursor_in_echo_area means put
4828 cursor at the end of the prompt. If the mini-buffer
4829 is several lines high, find the last line that has
4831 row
= FRAME_LINES (f
);
4837 if (MATRIX_ROW_ENABLED_P (current_matrix
, row
))
4839 /* Frame rows are filled up with spaces that
4840 must be ignored here. */
4841 struct glyph_row
*r
= MATRIX_ROW (current_matrix
,
4843 struct glyph
*start
= r
->glyphs
[TEXT_AREA
];
4844 struct glyph
*last
= start
+ r
->used
[TEXT_AREA
];
4847 && (last
- 1)->charpos
< 0)
4853 while (row
> top
&& col
== 0);
4855 /* Make sure COL is not out of range. */
4856 if (col
>= FRAME_CURSOR_X_LIMIT (f
))
4858 /* If we have another row, advance cursor into it. */
4859 if (row
< FRAME_LINES (f
) - 1)
4861 col
= FRAME_LEFT_SCROLL_BAR_COLS (f
);
4864 /* Otherwise move it back in range. */
4866 col
= FRAME_CURSOR_X_LIMIT (f
) - 1;
4870 cursor_to (f
, row
, col
);
4874 /* We have only one cursor on terminal frames. Use it to
4875 display the cursor of the selected window. */
4876 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
4877 if (w
->cursor
.vpos
>= 0
4878 /* The cursor vpos may be temporarily out of bounds
4879 in the following situation: There is one window,
4880 with the cursor in the lower half of it. The window
4881 is split, and a message causes a redisplay before
4882 a new cursor position has been computed. */
4883 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
4885 int x
= WINDOW_TO_FRAME_HPOS (w
, w
->cursor
.hpos
);
4886 int y
= WINDOW_TO_FRAME_VPOS (w
, w
->cursor
.vpos
);
4888 if (INTEGERP (w
->left_margin_cols
))
4889 x
+= XFASTINT (w
->left_margin_cols
);
4891 /* x = max (min (x, FRAME_TOTAL_COLS (f) - 1), 0); */
4892 cursor_to (f
, y
, x
);
4897 #if !PERIODIC_PREEMPTION_CHECKING
4901 clear_desired_matrices (f
);
4906 /* Do line insertions/deletions on frame F for frame-based redisplay. */
4909 scrolling (struct frame
*frame
)
4911 int unchanged_at_top
, unchanged_at_bottom
;
4914 int *old_hash
= (int *) alloca (FRAME_LINES (frame
) * sizeof (int));
4915 int *new_hash
= (int *) alloca (FRAME_LINES (frame
) * sizeof (int));
4916 int *draw_cost
= (int *) alloca (FRAME_LINES (frame
) * sizeof (int));
4917 int *old_draw_cost
= (int *) alloca (FRAME_LINES (frame
) * sizeof (int));
4919 int free_at_end_vpos
= FRAME_LINES (frame
);
4920 struct glyph_matrix
*current_matrix
= frame
->current_matrix
;
4921 struct glyph_matrix
*desired_matrix
= frame
->desired_matrix
;
4923 if (!current_matrix
)
4926 /* Compute hash codes of all the lines. Also calculate number of
4927 changed lines, number of unchanged lines at the beginning, and
4928 number of unchanged lines at the end. */
4930 unchanged_at_top
= 0;
4931 unchanged_at_bottom
= FRAME_LINES (frame
);
4932 for (i
= 0; i
< FRAME_LINES (frame
); i
++)
4934 /* Give up on this scrolling if some old lines are not enabled. */
4935 if (!MATRIX_ROW_ENABLED_P (current_matrix
, i
))
4937 old_hash
[i
] = line_hash_code (MATRIX_ROW (current_matrix
, i
));
4938 if (! MATRIX_ROW_ENABLED_P (desired_matrix
, i
))
4940 /* This line cannot be redrawn, so don't let scrolling mess it. */
4941 new_hash
[i
] = old_hash
[i
];
4942 #define INFINITY 1000000 /* Taken from scroll.c */
4943 draw_cost
[i
] = INFINITY
;
4947 new_hash
[i
] = line_hash_code (MATRIX_ROW (desired_matrix
, i
));
4948 draw_cost
[i
] = line_draw_cost (desired_matrix
, i
);
4951 if (old_hash
[i
] != new_hash
[i
])
4954 unchanged_at_bottom
= FRAME_LINES (frame
) - i
- 1;
4956 else if (i
== unchanged_at_top
)
4958 old_draw_cost
[i
] = line_draw_cost (current_matrix
, i
);
4961 /* If changed lines are few, don't allow preemption, don't scroll. */
4962 if ((!FRAME_SCROLL_REGION_OK (frame
)
4963 && changed_lines
< baud_rate
/ 2400)
4964 || unchanged_at_bottom
== FRAME_LINES (frame
))
4967 window_size
= (FRAME_LINES (frame
) - unchanged_at_top
4968 - unchanged_at_bottom
);
4970 if (FRAME_SCROLL_REGION_OK (frame
))
4971 free_at_end_vpos
-= unchanged_at_bottom
;
4972 else if (FRAME_MEMORY_BELOW_FRAME (frame
))
4973 free_at_end_vpos
= -1;
4975 /* If large window, fast terminal and few lines in common between
4976 current frame and desired frame, don't bother with i/d calc. */
4977 if (!FRAME_SCROLL_REGION_OK (frame
)
4978 && window_size
>= 18 && baud_rate
> 2400
4980 10 * scrolling_max_lines_saved (unchanged_at_top
,
4981 FRAME_LINES (frame
) - unchanged_at_bottom
,
4982 old_hash
, new_hash
, draw_cost
)))
4985 if (window_size
< 2)
4988 scrolling_1 (frame
, window_size
, unchanged_at_top
, unchanged_at_bottom
,
4989 draw_cost
+ unchanged_at_top
- 1,
4990 old_draw_cost
+ unchanged_at_top
- 1,
4991 old_hash
+ unchanged_at_top
- 1,
4992 new_hash
+ unchanged_at_top
- 1,
4993 free_at_end_vpos
- unchanged_at_top
);
4999 /* Count the number of blanks at the start of the vector of glyphs R
5000 which is LEN glyphs long. */
5003 count_blanks (struct glyph
*r
, int len
)
5007 for (i
= 0; i
< len
; ++i
)
5008 if (!CHAR_GLYPH_SPACE_P (r
[i
]))
5015 /* Count the number of glyphs in common at the start of the glyph
5016 vectors STR1 and STR2. END1 is the end of STR1 and END2 is the end
5017 of STR2. Value is the number of equal glyphs equal at the start. */
5020 count_match (struct glyph
*str1
, struct glyph
*end1
, struct glyph
*str2
, struct glyph
*end2
)
5022 struct glyph
*p1
= str1
;
5023 struct glyph
*p2
= str2
;
5027 && GLYPH_CHAR_AND_FACE_EQUAL_P (p1
, p2
))
5034 /* Char insertion/deletion cost vector, from term.c */
5036 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_TOTAL_COLS((f))])
5039 /* Perform a frame-based update on line VPOS in frame FRAME. */
5042 update_frame_line (struct frame
*f
, int vpos
)
5044 struct glyph
*obody
, *nbody
, *op1
, *op2
, *np1
, *nend
;
5046 int osp
, nsp
, begmatch
, endmatch
, olen
, nlen
;
5047 struct glyph_matrix
*current_matrix
= f
->current_matrix
;
5048 struct glyph_matrix
*desired_matrix
= f
->desired_matrix
;
5049 struct glyph_row
*current_row
= MATRIX_ROW (current_matrix
, vpos
);
5050 struct glyph_row
*desired_row
= MATRIX_ROW (desired_matrix
, vpos
);
5051 int must_write_whole_line_p
;
5052 int write_spaces_p
= FRAME_MUST_WRITE_SPACES (f
);
5053 int colored_spaces_p
= (FACE_FROM_ID (f
, DEFAULT_FACE_ID
)->background
5054 != FACE_TTY_DEFAULT_BG_COLOR
);
5056 if (colored_spaces_p
)
5059 /* Current row not enabled means it has unknown contents. We must
5060 write the whole desired line in that case. */
5061 must_write_whole_line_p
= !current_row
->enabled_p
;
5062 if (must_write_whole_line_p
)
5069 obody
= MATRIX_ROW_GLYPH_START (current_matrix
, vpos
);
5070 olen
= current_row
->used
[TEXT_AREA
];
5072 /* Ignore trailing spaces, if we can. */
5073 if (!write_spaces_p
)
5074 while (olen
> 0 && CHAR_GLYPH_SPACE_P (obody
[olen
-1]))
5078 current_row
->enabled_p
= 1;
5079 current_row
->used
[TEXT_AREA
] = desired_row
->used
[TEXT_AREA
];
5081 /* If desired line is empty, just clear the line. */
5082 if (!desired_row
->enabled_p
)
5088 nbody
= desired_row
->glyphs
[TEXT_AREA
];
5089 nlen
= desired_row
->used
[TEXT_AREA
];
5090 nend
= nbody
+ nlen
;
5092 /* If display line has unknown contents, write the whole line. */
5093 if (must_write_whole_line_p
)
5095 /* Ignore spaces at the end, if we can. */
5096 if (!write_spaces_p
)
5097 while (nlen
> 0 && CHAR_GLYPH_SPACE_P (nbody
[nlen
- 1]))
5100 /* Write the contents of the desired line. */
5103 cursor_to (f
, vpos
, 0);
5104 write_glyphs (f
, nbody
, nlen
);
5107 /* Don't call clear_end_of_line if we already wrote the whole
5108 line. The cursor will not be at the right margin in that
5109 case but in the line below. */
5110 if (nlen
< FRAME_TOTAL_COLS (f
))
5112 cursor_to (f
, vpos
, nlen
);
5113 clear_end_of_line (f
, FRAME_TOTAL_COLS (f
));
5116 /* Make sure we are in the right row, otherwise cursor movement
5117 with cmgoto might use `ch' in the wrong row. */
5118 cursor_to (f
, vpos
, 0);
5120 make_current (desired_matrix
, current_matrix
, vpos
);
5124 /* Pretend trailing spaces are not there at all,
5125 unless for one reason or another we must write all spaces. */
5126 if (!write_spaces_p
)
5127 while (nlen
> 0 && CHAR_GLYPH_SPACE_P (nbody
[nlen
- 1]))
5130 /* If there's no i/d char, quickly do the best we can without it. */
5131 if (!FRAME_CHAR_INS_DEL_OK (f
))
5135 /* Find the first glyph in desired row that doesn't agree with
5136 a glyph in the current row, and write the rest from there on. */
5137 for (i
= 0; i
< nlen
; i
++)
5139 if (i
>= olen
|| !GLYPH_EQUAL_P (nbody
+ i
, obody
+ i
))
5141 /* Find the end of the run of different glyphs. */
5145 || !GLYPH_EQUAL_P (nbody
+ j
, obody
+ j
)
5146 || CHAR_GLYPH_PADDING_P (nbody
[j
])))
5149 /* Output this run of non-matching chars. */
5150 cursor_to (f
, vpos
, i
);
5151 write_glyphs (f
, nbody
+ i
, j
- i
);
5154 /* Now find the next non-match. */
5158 /* Clear the rest of the line, or the non-clear part of it. */
5161 cursor_to (f
, vpos
, nlen
);
5162 clear_end_of_line (f
, olen
);
5165 /* Make current row = desired row. */
5166 make_current (desired_matrix
, current_matrix
, vpos
);
5170 /* Here when CHAR_INS_DEL_OK != 0, i.e. we can insert or delete
5171 characters in a row. */
5175 /* If current line is blank, skip over initial spaces, if
5176 possible, and write the rest. */
5180 nsp
= count_blanks (nbody
, nlen
);
5184 cursor_to (f
, vpos
, nsp
);
5185 write_glyphs (f
, nbody
+ nsp
, nlen
- nsp
);
5188 /* Exchange contents between current_frame and new_frame. */
5189 make_current (desired_matrix
, current_matrix
, vpos
);
5193 /* Compute number of leading blanks in old and new contents. */
5194 osp
= count_blanks (obody
, olen
);
5195 nsp
= (colored_spaces_p
? 0 : count_blanks (nbody
, nlen
));
5197 /* Compute number of matching chars starting with first non-blank. */
5198 begmatch
= count_match (obody
+ osp
, obody
+ olen
,
5199 nbody
+ nsp
, nbody
+ nlen
);
5201 /* Spaces in new match implicit space past the end of old. */
5202 /* A bug causing this to be a no-op was fixed in 18.29. */
5203 if (!write_spaces_p
&& osp
+ begmatch
== olen
)
5206 while (np1
+ begmatch
< nend
&& CHAR_GLYPH_SPACE_P (np1
[begmatch
]))
5210 /* Avoid doing insert/delete char
5211 just cause number of leading spaces differs
5212 when the following text does not match. */
5213 if (begmatch
== 0 && osp
!= nsp
)
5214 osp
= nsp
= min (osp
, nsp
);
5216 /* Find matching characters at end of line */
5219 op2
= op1
+ begmatch
- min (olen
- osp
, nlen
- nsp
);
5221 && GLYPH_EQUAL_P (op1
- 1, np1
- 1))
5226 endmatch
= obody
+ olen
- op1
;
5228 /* tem gets the distance to insert or delete.
5229 endmatch is how many characters we save by doing so.
5232 tem
= (nlen
- nsp
) - (olen
- osp
);
5234 && (!FRAME_CHAR_INS_DEL_OK (f
)
5235 || endmatch
<= char_ins_del_cost (f
)[tem
]))
5238 /* nsp - osp is the distance to insert or delete.
5239 If that is nonzero, begmatch is known to be nonzero also.
5240 begmatch + endmatch is how much we save by doing the ins/del.
5244 && (!FRAME_CHAR_INS_DEL_OK (f
)
5245 || begmatch
+ endmatch
<= char_ins_del_cost (f
)[nsp
- osp
]))
5249 osp
= nsp
= min (osp
, nsp
);
5252 /* Now go through the line, inserting, writing and
5253 deleting as appropriate. */
5257 cursor_to (f
, vpos
, nsp
);
5258 delete_glyphs (f
, osp
- nsp
);
5262 /* If going to delete chars later in line
5263 and insert earlier in the line,
5264 must delete first to avoid losing data in the insert */
5265 if (endmatch
&& nlen
< olen
+ nsp
- osp
)
5267 cursor_to (f
, vpos
, nlen
- endmatch
+ osp
- nsp
);
5268 delete_glyphs (f
, olen
+ nsp
- osp
- nlen
);
5269 olen
= nlen
- (nsp
- osp
);
5271 cursor_to (f
, vpos
, osp
);
5272 insert_glyphs (f
, 0, nsp
- osp
);
5276 tem
= nsp
+ begmatch
+ endmatch
;
5277 if (nlen
!= tem
|| olen
!= tem
)
5279 if (!endmatch
|| nlen
== olen
)
5281 /* If new text being written reaches right margin, there is
5282 no need to do clear-to-eol at the end of this function
5283 (and it would not be safe, since cursor is not going to
5284 be "at the margin" after the text is done). */
5285 if (nlen
== FRAME_TOTAL_COLS (f
))
5288 /* Function write_glyphs is prepared to do nothing
5289 if passed a length <= 0. Check it here to avoid
5290 unnecessary cursor movement. */
5293 cursor_to (f
, vpos
, nsp
+ begmatch
);
5294 write_glyphs (f
, nbody
+ nsp
+ begmatch
, nlen
- tem
);
5297 else if (nlen
> olen
)
5299 /* Here, we used to have the following simple code:
5300 ----------------------------------------
5301 write_glyphs (nbody + nsp + begmatch, olen - tem);
5302 insert_glyphs (nbody + nsp + begmatch + olen - tem, nlen - olen);
5303 ----------------------------------------
5304 but it doesn't work if nbody[nsp + begmatch + olen - tem]
5305 is a padding glyph. */
5306 int out
= olen
- tem
; /* Columns to be overwritten originally. */
5309 cursor_to (f
, vpos
, nsp
+ begmatch
);
5311 /* Calculate columns we can actually overwrite. */
5312 while (CHAR_GLYPH_PADDING_P (nbody
[nsp
+ begmatch
+ out
]))
5314 write_glyphs (f
, nbody
+ nsp
+ begmatch
, out
);
5316 /* If we left columns to be overwritten, we must delete them. */
5317 del
= olen
- tem
- out
;
5319 delete_glyphs (f
, del
);
5321 /* At last, we insert columns not yet written out. */
5322 insert_glyphs (f
, nbody
+ nsp
+ begmatch
+ out
, nlen
- olen
+ del
);
5325 else if (olen
> nlen
)
5327 cursor_to (f
, vpos
, nsp
+ begmatch
);
5328 write_glyphs (f
, nbody
+ nsp
+ begmatch
, nlen
- tem
);
5329 delete_glyphs (f
, olen
- nlen
);
5335 /* If any unerased characters remain after the new line, erase them. */
5338 cursor_to (f
, vpos
, nlen
);
5339 clear_end_of_line (f
, olen
);
5342 /* Exchange contents between current_frame and new_frame. */
5343 make_current (desired_matrix
, current_matrix
, vpos
);
5348 /***********************************************************************
5349 X/Y Position -> Buffer Position
5350 ***********************************************************************/
5352 /* Determine what's under window-relative pixel position (*X, *Y).
5353 Return the OBJECT (string or buffer) that's there.
5354 Return in *POS the position in that object.
5355 Adjust *X and *Y to character positions.
5356 Return in *DX and *DY the pixel coordinates of the click,
5357 relative to the top left corner of OBJECT, or relative to
5358 the top left corner of the character glyph at (*X, *Y)
5360 Return WIDTH and HEIGHT of the object at (*X, *Y), or zero
5361 if the coordinates point to an empty area of the display. */
5364 buffer_posn_from_coords (struct window
*w
, int *x
, int *y
, struct display_pos
*pos
, Lisp_Object
*object
, int *dx
, int *dy
, int *width
, int *height
)
5367 Lisp_Object old_current_buffer
= Fcurrent_buffer ();
5368 struct text_pos startp
;
5370 struct glyph_row
*row
;
5371 #ifdef HAVE_WINDOW_SYSTEM
5372 struct image
*img
= 0;
5376 /* We used to set current_buffer directly here, but that does the
5377 wrong thing with `face-remapping-alist' (bug#2044). */
5378 Fset_buffer (w
->buffer
);
5379 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
5380 CHARPOS (startp
) = min (ZV
, max (BEGV
, CHARPOS (startp
)));
5381 BYTEPOS (startp
) = min (ZV_BYTE
, max (BEGV_BYTE
, BYTEPOS (startp
)));
5382 start_display (&it
, w
, startp
);
5386 /* First, move to the beginning of the row corresponding to *Y. We
5387 need to be in that row to get the correct value of base paragraph
5388 direction for the text at (*X, *Y). */
5389 move_it_to (&it
, -1, 0, *y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
5391 /* TO_X is the pixel position that the iterator will compute for the
5392 glyph at *X. We add it.first_visible_x because iterator
5393 positions include the hscroll. */
5394 to_x
= x0
+ it
.first_visible_x
;
5395 if (it
.bidi_it
.paragraph_dir
== R2L
)
5396 /* For lines in an R2L paragraph, we need to mirror TO_X wrt the
5397 text area. This is because the iterator, even in R2L
5398 paragraphs, delivers glyphs as if they started at the left
5399 margin of the window. (When we actually produce glyphs for
5400 display, we reverse their order in PRODUCE_GLYPHS, but the
5401 iterator doesn't know about that.) The following line adjusts
5402 the pixel position to the iterator geometry, which is what
5403 move_it_* routines use. (The -1 is because in a window whose
5404 text-area width is W, the rightmost pixel position is W-1, and
5405 it should be mirrored into zero pixel position.) */
5406 to_x
= window_box_width (w
, TEXT_AREA
) - to_x
- 1;
5408 /* Now move horizontally in the row to the glyph under *X. Second
5409 argument is ZV to prevent move_it_in_display_line from matching
5410 based on buffer positions. */
5411 move_it_in_display_line (&it
, ZV
, to_x
, MOVE_TO_X
);
5413 Fset_buffer (old_current_buffer
);
5415 *dx
= x0
+ it
.first_visible_x
- it
.current_x
;
5416 *dy
= *y
- it
.current_y
;
5419 if (STRINGP (it
.string
))
5422 if (it
.what
== IT_COMPOSITION
5423 && it
.cmp_it
.nchars
> 1
5424 && it
.cmp_it
.reversed_p
)
5426 /* The current display element is a grapheme cluster in a
5427 composition. In that case, we need the position of the first
5428 character of the cluster. But, as it.cmp_it.reversed_p is 1,
5429 it.current points to the last character of the cluster, thus
5430 we must move back to the first character of the same
5432 CHARPOS (pos
->pos
) -= it
.cmp_it
.nchars
- 1;
5433 if (STRINGP (it
.string
))
5434 BYTEPOS (pos
->pos
) = string_char_to_byte (string
, CHARPOS (pos
->pos
));
5436 BYTEPOS (pos
->pos
) = CHAR_TO_BYTE (CHARPOS (pos
->pos
));
5439 #ifdef HAVE_WINDOW_SYSTEM
5440 if (it
.what
== IT_IMAGE
)
5442 if ((img
= IMAGE_FROM_ID (it
.f
, it
.image_id
)) != NULL
5443 && !NILP (img
->spec
))
5444 *object
= img
->spec
;
5448 if (it
.vpos
< w
->current_matrix
->nrows
5449 && (row
= MATRIX_ROW (w
->current_matrix
, it
.vpos
),
5452 if (it
.hpos
< row
->used
[TEXT_AREA
])
5454 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + it
.hpos
;
5455 #ifdef HAVE_WINDOW_SYSTEM
5458 *dy
-= row
->ascent
- glyph
->ascent
;
5459 *dx
+= glyph
->slice
.img
.x
;
5460 *dy
+= glyph
->slice
.img
.y
;
5461 /* Image slices positions are still relative to the entire image */
5462 *width
= img
->width
;
5463 *height
= img
->height
;
5468 *width
= glyph
->pixel_width
;
5469 *height
= glyph
->ascent
+ glyph
->descent
;
5475 *height
= row
->height
;
5480 *width
= *height
= 0;
5483 /* Add extra (default width) columns if clicked after EOL. */
5484 x1
= max(0, it
.current_x
+ it
.pixel_width
- it
.first_visible_x
);
5486 it
.hpos
+= (x0
- x1
) / WINDOW_FRAME_COLUMN_WIDTH (w
);
5495 /* Value is the string under window-relative coordinates X/Y in the
5496 mode line or header line (PART says which) of window W, or nil if none.
5497 *CHARPOS is set to the position in the string returned. */
5500 mode_line_string (struct window
*w
, enum window_part part
,
5501 int *x
, int *y
, EMACS_INT
*charpos
, Lisp_Object
*object
,
5502 int *dx
, int *dy
, int *width
, int *height
)
5504 struct glyph_row
*row
;
5505 struct glyph
*glyph
, *end
;
5507 Lisp_Object string
= Qnil
;
5509 if (part
== ON_MODE_LINE
)
5510 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
5512 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
5514 *y
= row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
5516 if (row
->mode_line_p
&& row
->enabled_p
)
5518 /* Find the glyph under X. If we find one with a string object,
5519 it's the one we were looking for. */
5520 glyph
= row
->glyphs
[TEXT_AREA
];
5521 end
= glyph
+ row
->used
[TEXT_AREA
];
5522 for (x0
= *x
; glyph
< end
&& x0
>= glyph
->pixel_width
; ++glyph
)
5523 x0
-= glyph
->pixel_width
;
5524 *x
= glyph
- row
->glyphs
[TEXT_AREA
];
5527 string
= glyph
->object
;
5528 *charpos
= glyph
->charpos
;
5529 *width
= glyph
->pixel_width
;
5530 *height
= glyph
->ascent
+ glyph
->descent
;
5531 #ifdef HAVE_WINDOW_SYSTEM
5532 if (glyph
->type
== IMAGE_GLYPH
)
5535 img
= IMAGE_FROM_ID (WINDOW_XFRAME (w
), glyph
->u
.img_id
);
5537 *object
= img
->spec
;
5538 y0
-= row
->ascent
- glyph
->ascent
;
5544 /* Add extra (default width) columns if clicked after EOL. */
5545 *x
+= x0
/ WINDOW_FRAME_COLUMN_WIDTH (w
);
5547 *height
= row
->height
;
5554 *width
= *height
= 0;
5564 /* Value is the string under window-relative coordinates X/Y in either
5565 marginal area, or nil if none. *CHARPOS is set to the position in
5566 the string returned. */
5569 marginal_area_string (struct window
*w
, enum window_part part
,
5570 int *x
, int *y
, EMACS_INT
*charpos
, Lisp_Object
*object
,
5571 int *dx
, int *dy
, int *width
, int *height
)
5573 struct glyph_row
*row
= w
->current_matrix
->rows
;
5574 struct glyph
*glyph
, *end
;
5575 int x0
, y0
, i
, wy
= *y
;
5577 Lisp_Object string
= Qnil
;
5579 if (part
== ON_LEFT_MARGIN
)
5580 area
= LEFT_MARGIN_AREA
;
5581 else if (part
== ON_RIGHT_MARGIN
)
5582 area
= RIGHT_MARGIN_AREA
;
5586 for (i
= 0; row
->enabled_p
&& i
< w
->current_matrix
->nrows
; ++i
, ++row
)
5587 if (wy
>= row
->y
&& wy
< MATRIX_ROW_BOTTOM_Y (row
))
5590 *y
= row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
5594 /* Find the glyph under X. If we find one with a string object,
5595 it's the one we were looking for. */
5596 if (area
== RIGHT_MARGIN_AREA
)
5597 x0
= ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5598 ? WINDOW_LEFT_FRINGE_WIDTH (w
)
5599 : WINDOW_TOTAL_FRINGE_WIDTH (w
))
5600 + window_box_width (w
, LEFT_MARGIN_AREA
)
5601 + window_box_width (w
, TEXT_AREA
));
5603 x0
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5604 ? WINDOW_LEFT_FRINGE_WIDTH (w
)
5607 glyph
= row
->glyphs
[area
];
5608 end
= glyph
+ row
->used
[area
];
5609 for (x0
= *x
- x0
; glyph
< end
&& x0
>= glyph
->pixel_width
; ++glyph
)
5610 x0
-= glyph
->pixel_width
;
5611 *x
= glyph
- row
->glyphs
[area
];
5614 string
= glyph
->object
;
5615 *charpos
= glyph
->charpos
;
5616 *width
= glyph
->pixel_width
;
5617 *height
= glyph
->ascent
+ glyph
->descent
;
5618 #ifdef HAVE_WINDOW_SYSTEM
5619 if (glyph
->type
== IMAGE_GLYPH
)
5622 img
= IMAGE_FROM_ID (WINDOW_XFRAME (w
), glyph
->u
.img_id
);
5624 *object
= img
->spec
;
5625 y0
-= row
->ascent
- glyph
->ascent
;
5626 x0
+= glyph
->slice
.img
.x
;
5627 y0
+= glyph
->slice
.img
.y
;
5633 /* Add extra (default width) columns if clicked after EOL. */
5634 *x
+= x0
/ WINDOW_FRAME_COLUMN_WIDTH (w
);
5636 *height
= row
->height
;
5643 *width
= *height
= 0;
5653 /***********************************************************************
5654 Changing Frame Sizes
5655 ***********************************************************************/
5660 window_change_signal (int signalnum
) /* If we don't have an argument, */
5661 /* some compilers complain in signal calls. */
5664 int old_errno
= errno
;
5666 struct tty_display_info
*tty
;
5668 signal (SIGWINCH
, window_change_signal
);
5669 SIGNAL_THREAD_CHECK (signalnum
);
5671 /* The frame size change obviously applies to a single
5672 termcap-controlled terminal, but we can't decide which.
5673 Therefore, we resize the frames corresponding to each tty.
5675 for (tty
= tty_list
; tty
; tty
= tty
->next
) {
5677 if (! tty
->term_initted
)
5680 /* Suspended tty frames have tty->input == NULL avoid trying to
5685 get_tty_size (fileno (tty
->input
), &width
, &height
);
5687 if (width
> 5 && height
> 2) {
5688 Lisp_Object tail
, frame
;
5690 FOR_EACH_FRAME (tail
, frame
)
5691 if (FRAME_TERMCAP_P (XFRAME (frame
)) && FRAME_TTY (XFRAME (frame
)) == tty
)
5692 /* Record the new sizes, but don't reallocate the data
5693 structures now. Let that be done later outside of the
5695 change_frame_size (XFRAME (frame
), height
, width
, 0, 1, 0);
5701 #endif /* SIGWINCH */
5704 /* Do any change in frame size that was requested by a signal. SAFE
5705 non-zero means this function is called from a place where it is
5706 safe to change frame sizes while a redisplay is in progress. */
5709 do_pending_window_change (int safe
)
5711 /* If window_change_signal should have run before, run it now. */
5712 if (redisplaying_p
&& !safe
)
5715 while (delayed_size_change
)
5717 Lisp_Object tail
, frame
;
5719 delayed_size_change
= 0;
5721 FOR_EACH_FRAME (tail
, frame
)
5723 struct frame
*f
= XFRAME (frame
);
5725 if (f
->new_text_lines
!= 0 || f
->new_text_cols
!= 0)
5726 change_frame_size (f
, f
->new_text_lines
, f
->new_text_cols
,
5733 /* Change the frame height and/or width. Values may be given as zero to
5734 indicate no change is to take place.
5736 If DELAY is non-zero, then assume we're being called from a signal
5737 handler, and queue the change for later - perhaps the next
5738 redisplay. Since this tries to resize windows, we can't call it
5739 from a signal handler.
5741 SAFE non-zero means this function is called from a place where it's
5742 safe to change frame sizes while a redisplay is in progress. */
5745 change_frame_size (register struct frame
*f
, int newheight
, int newwidth
, int pretend
, int delay
, int safe
)
5747 Lisp_Object tail
, frame
;
5749 if (FRAME_MSDOS_P (f
))
5751 /* On MS-DOS, all frames use the same screen, so a change in
5752 size affects all frames. Termcap now supports multiple
5754 FOR_EACH_FRAME (tail
, frame
)
5755 if (! FRAME_WINDOW_P (XFRAME (frame
)))
5756 change_frame_size_1 (XFRAME (frame
), newheight
, newwidth
,
5757 pretend
, delay
, safe
);
5760 change_frame_size_1 (f
, newheight
, newwidth
, pretend
, delay
, safe
);
5764 change_frame_size_1 (register struct frame
*f
, int newheight
, int newwidth
, int pretend
, int delay
, int safe
)
5766 int new_frame_total_cols
;
5767 int count
= SPECPDL_INDEX ();
5769 /* If we can't deal with the change now, queue it for later. */
5770 if (delay
|| (redisplaying_p
&& !safe
))
5772 f
->new_text_lines
= newheight
;
5773 f
->new_text_cols
= newwidth
;
5774 delayed_size_change
= 1;
5778 /* This size-change overrides any pending one for this frame. */
5779 f
->new_text_lines
= 0;
5780 f
->new_text_cols
= 0;
5782 /* If an argument is zero, set it to the current value. */
5784 newheight
= FRAME_LINES (f
);
5786 newwidth
= FRAME_COLS (f
);
5788 /* Compute width of windows in F.
5789 This is the width of the frame without vertical scroll bars. */
5790 new_frame_total_cols
= FRAME_TOTAL_COLS_ARG (f
, newwidth
);
5792 /* Round up to the smallest acceptable size. */
5793 check_frame_size (f
, &newheight
, &newwidth
);
5795 /* If we're not changing the frame size, quit now. */
5796 /* Frame width may be unchanged but the text portion may change, for example,
5797 fullscreen and remove/add scroll bar. */
5798 if (newheight
== FRAME_LINES (f
)
5799 && newwidth
== FRAME_COLS (f
) // text portion unchanged
5800 && new_frame_total_cols
== FRAME_TOTAL_COLS (f
)) // frame width unchanged
5806 /* We only can set screen dimensions to certain values supported
5807 by our video hardware. Try to find the smallest size greater
5808 or equal to the requested dimensions. */
5809 dos_set_window_size (&newheight
, &newwidth
);
5812 if (newheight
!= FRAME_LINES (f
))
5814 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
5816 /* Frame has both root and mini-buffer. */
5817 XSETFASTINT (XWINDOW (FRAME_ROOT_WINDOW (f
))->top_line
,
5818 FRAME_TOP_MARGIN (f
));
5819 set_window_height (FRAME_ROOT_WINDOW (f
),
5822 - FRAME_TOP_MARGIN (f
)),
5824 XSETFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f
))->top_line
,
5826 set_window_height (FRAME_MINIBUF_WINDOW (f
), 1, 0);
5829 /* Frame has just one top-level window. */
5830 set_window_height (FRAME_ROOT_WINDOW (f
),
5831 newheight
- FRAME_TOP_MARGIN (f
), 2);
5833 /* MSDOS frames cannot PRETEND, as they change frame size by
5834 manipulating video hardware. */
5835 if ((FRAME_TERMCAP_P (f
) && !pretend
) || FRAME_MSDOS_P (f
))
5836 FrameRows (FRAME_TTY (f
)) = newheight
;
5839 if (new_frame_total_cols
!= FRAME_TOTAL_COLS (f
))
5841 set_window_width (FRAME_ROOT_WINDOW (f
), new_frame_total_cols
, 2);
5842 if (FRAME_HAS_MINIBUF_P (f
))
5843 set_window_width (FRAME_MINIBUF_WINDOW (f
), new_frame_total_cols
, 0);
5845 /* MSDOS frames cannot PRETEND, as they change frame size by
5846 manipulating video hardware. */
5847 if ((FRAME_TERMCAP_P (f
) && !pretend
) || FRAME_MSDOS_P (f
))
5848 FrameCols (FRAME_TTY (f
)) = newwidth
;
5850 if (WINDOWP (f
->tool_bar_window
))
5851 XSETFASTINT (XWINDOW (f
->tool_bar_window
)->total_cols
, newwidth
);
5854 FRAME_LINES (f
) = newheight
;
5855 SET_FRAME_COLS (f
, newwidth
);
5858 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
5859 int text_area_x
, text_area_y
, text_area_width
, text_area_height
;
5861 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
, &text_area_width
,
5863 if (w
->cursor
.x
>= text_area_x
+ text_area_width
)
5864 w
->cursor
.hpos
= w
->cursor
.x
= 0;
5865 if (w
->cursor
.y
>= text_area_y
+ text_area_height
)
5866 w
->cursor
.vpos
= w
->cursor
.y
= 0;
5870 calculate_costs (f
);
5871 SET_FRAME_GARBAGED (f
);
5876 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5878 run_window_configuration_change_hook (f
);
5880 unbind_to (count
, Qnil
);
5885 /***********************************************************************
5886 Terminal Related Lisp Functions
5887 ***********************************************************************/
5889 DEFUN ("open-termscript", Fopen_termscript
, Sopen_termscript
,
5890 1, 1, "FOpen termscript file: ",
5891 doc
: /* Start writing all terminal output to FILE as well as the terminal.
5892 FILE = nil means just close any termscript file currently open. */)
5895 struct tty_display_info
*tty
;
5897 if (! FRAME_TERMCAP_P (SELECTED_FRAME ())
5898 && ! FRAME_MSDOS_P (SELECTED_FRAME ()))
5899 error ("Current frame is not on a tty device");
5903 if (tty
->termscript
!= 0)
5906 fclose (tty
->termscript
);
5909 tty
->termscript
= 0;
5913 file
= Fexpand_file_name (file
, Qnil
);
5914 tty
->termscript
= fopen (SDATA (file
), "w");
5915 if (tty
->termscript
== 0)
5916 report_file_error ("Opening termscript", Fcons (file
, Qnil
));
5922 DEFUN ("send-string-to-terminal", Fsend_string_to_terminal
,
5923 Ssend_string_to_terminal
, 1, 2, 0,
5924 doc
: /* Send STRING to the terminal without alteration.
5925 Control characters in STRING will have terminal-dependent effects.
5927 Optional parameter TERMINAL specifies the tty terminal device to use.
5928 It may be a terminal object, a frame, or nil for the terminal used by
5929 the currently selected frame. In batch mode, STRING is sent to stdout
5930 when TERMINAL is nil. */)
5931 (Lisp_Object string
, Lisp_Object terminal
)
5933 struct terminal
*t
= get_terminal (terminal
, 1);
5936 /* ??? Perhaps we should do something special for multibyte strings here. */
5937 CHECK_STRING (string
);
5941 error ("Unknown terminal device");
5943 if (t
->type
== output_initial
)
5945 else if (t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
5946 error ("Device %d is not a termcap terminal device", t
->id
);
5949 struct tty_display_info
*tty
= t
->display_info
.tty
;
5952 error ("Terminal is currently suspended");
5954 if (tty
->termscript
)
5956 fwrite (SDATA (string
), 1, SBYTES (string
), tty
->termscript
);
5957 fflush (tty
->termscript
);
5961 fwrite (SDATA (string
), 1, SBYTES (string
), out
);
5968 DEFUN ("ding", Fding
, Sding
, 0, 1, 0,
5969 doc
: /* Beep, or flash the screen.
5970 Also, unless an argument is given,
5971 terminate any keyboard macro currently executing. */)
5979 ring_bell (XFRAME (selected_frame
));
5988 bitch_at_user (void)
5992 else if (!INTERACTIVE
) /* Stop executing a keyboard macro. */
5993 error ("Keyboard macro terminated by a command ringing the bell");
5995 ring_bell (XFRAME (selected_frame
));
6000 /***********************************************************************
6002 ***********************************************************************/
6004 DEFUN ("sleep-for", Fsleep_for
, Ssleep_for
, 1, 2, 0,
6005 doc
: /* Pause, without updating display, for SECONDS seconds.
6006 SECONDS may be a floating-point value, meaning that you can wait for a
6007 fraction of a second. Optional second arg MILLISECONDS specifies an
6008 additional wait period, in milliseconds; this may be useful if your
6009 Emacs was built without floating point support.
6010 \(Not all operating systems support waiting for a fraction of a second.) */)
6011 (Lisp_Object seconds
, Lisp_Object milliseconds
)
6015 if (NILP (milliseconds
))
6016 XSETINT (milliseconds
, 0);
6018 CHECK_NUMBER (milliseconds
);
6019 usec
= XINT (milliseconds
) * 1000;
6022 double duration
= extract_float (seconds
);
6023 sec
= (int) duration
;
6024 usec
+= (duration
- sec
) * 1000000;
6027 #ifndef EMACS_HAS_USECS
6028 if (sec
== 0 && usec
!= 0)
6029 error ("Millisecond `sleep-for' not supported on %s", SYSTEM_TYPE
);
6032 /* Assure that 0 <= usec < 1000000. */
6035 /* We can't rely on the rounding being correct if usec is negative. */
6036 if (-1000000 < usec
)
6037 sec
--, usec
+= 1000000;
6039 sec
-= -usec
/ 1000000, usec
= 1000000 - (-usec
% 1000000);
6042 sec
+= usec
/ 1000000, usec
%= 1000000;
6044 if (sec
< 0 || (sec
== 0 && usec
== 0))
6047 wait_reading_process_output (sec
, usec
, 0, 0, Qnil
, NULL
, 0);
6053 /* This is just like wait_reading_process_output, except that
6056 TIMEOUT is number of seconds to wait (float or integer),
6057 or t to wait forever.
6058 READING is 1 if reading input.
6059 If DO_DISPLAY is >0 display process output while waiting.
6060 If DO_DISPLAY is >1 perform an initial redisplay before waiting.
6064 sit_for (Lisp_Object timeout
, int reading
, int do_display
)
6068 swallow_events (do_display
);
6070 if ((detect_input_pending_run_timers (do_display
))
6071 || !NILP (Vexecuting_kbd_macro
))
6074 if (do_display
>= 2)
6075 redisplay_preserve_echo_area (2);
6077 if (INTEGERP (timeout
))
6079 sec
= XINT (timeout
);
6082 else if (FLOATP (timeout
))
6084 double seconds
= XFLOAT_DATA (timeout
);
6085 sec
= (int) seconds
;
6086 usec
= (int) ((seconds
- sec
) * 1000000);
6088 else if (EQ (timeout
, Qt
))
6094 wrong_type_argument (Qnumberp
, timeout
);
6096 if (sec
== 0 && usec
== 0 && !EQ (timeout
, Qt
))
6103 wait_reading_process_output (sec
, usec
, reading
? -1 : 1, do_display
,
6106 return detect_input_pending () ? Qnil
: Qt
;
6110 DEFUN ("redisplay", Fredisplay
, Sredisplay
, 0, 1, 0,
6111 doc
: /* Perform redisplay if no input is available.
6112 If optional arg FORCE is non-nil or `redisplay-dont-pause' is non-nil,
6113 perform a full redisplay even if input is available.
6114 Return t if redisplay was performed, nil otherwise. */)
6120 if ((detect_input_pending_run_timers (1)
6121 && NILP (force
) && !redisplay_dont_pause
)
6122 || !NILP (Vexecuting_kbd_macro
))
6125 count
= SPECPDL_INDEX ();
6126 if (!NILP (force
) && !redisplay_dont_pause
)
6127 specbind (Qredisplay_dont_pause
, Qt
);
6128 redisplay_preserve_echo_area (2);
6129 unbind_to (count
, Qnil
);
6135 /***********************************************************************
6136 Other Lisp Functions
6137 ***********************************************************************/
6139 /* A vector of size >= 2 * NFRAMES + 3 * NBUFFERS + 1, containing the
6140 session's frames, frame names, buffers, buffer-read-only flags, and
6141 buffer-modified-flags. */
6143 static Lisp_Object frame_and_buffer_state
;
6146 DEFUN ("frame-or-buffer-changed-p", Fframe_or_buffer_changed_p
,
6147 Sframe_or_buffer_changed_p
, 0, 1, 0,
6148 doc
: /* Return non-nil if the frame and buffer state appears to have changed.
6149 VARIABLE is a variable name whose value is either nil or a state vector
6150 that will be updated to contain all frames and buffers,
6151 aside from buffers whose names start with space,
6152 along with the buffers' read-only and modified flags. This allows a fast
6153 check to see whether buffer menus might need to be recomputed.
6154 If this function returns non-nil, it updates the internal vector to reflect
6157 If VARIABLE is nil, an internal variable is used. Users should not
6158 pass nil for VARIABLE. */)
6159 (Lisp_Object variable
)
6161 Lisp_Object state
, tail
, frame
, buf
;
6162 Lisp_Object
*vecp
, *end
;
6165 if (! NILP (variable
))
6167 CHECK_SYMBOL (variable
);
6168 state
= Fsymbol_value (variable
);
6169 if (! VECTORP (state
))
6173 state
= frame_and_buffer_state
;
6175 vecp
= XVECTOR (state
)->contents
;
6176 end
= vecp
+ XVECTOR (state
)->size
;
6178 FOR_EACH_FRAME (tail
, frame
)
6182 if (!EQ (*vecp
++, frame
))
6186 if (!EQ (*vecp
++, XFRAME (frame
)->name
))
6189 /* Check that the buffer info matches. */
6190 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
6192 buf
= XCDR (XCAR (tail
));
6193 /* Ignore buffers that aren't included in buffer lists. */
6194 if (SREF (XBUFFER (buf
)->name
, 0) == ' ')
6198 if (!EQ (*vecp
++, buf
))
6202 if (!EQ (*vecp
++, XBUFFER (buf
)->read_only
))
6206 if (!EQ (*vecp
++, Fbuffer_modified_p (buf
)))
6211 /* Detect deletion of a buffer at the end of the list. */
6212 if (EQ (*vecp
, Qlambda
))
6215 /* Come here if we decide the data has changed. */
6217 /* Count the size we will need.
6218 Start with 1 so there is room for at least one lambda at the end. */
6220 FOR_EACH_FRAME (tail
, frame
)
6222 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
6224 /* Reallocate the vector if data has grown to need it,
6225 or if it has shrunk a lot. */
6226 if (! VECTORP (state
)
6227 || n
> XVECTOR (state
)->size
6228 || n
+ 20 < XVECTOR (state
)->size
/ 2)
6229 /* Add 20 extra so we grow it less often. */
6231 state
= Fmake_vector (make_number (n
+ 20), Qlambda
);
6232 if (! NILP (variable
))
6233 Fset (variable
, state
);
6235 frame_and_buffer_state
= state
;
6238 /* Record the new data in the (possibly reallocated) vector. */
6239 vecp
= XVECTOR (state
)->contents
;
6240 FOR_EACH_FRAME (tail
, frame
)
6243 *vecp
++ = XFRAME (frame
)->name
;
6245 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
6247 buf
= XCDR (XCAR (tail
));
6248 /* Ignore buffers that aren't included in buffer lists. */
6249 if (SREF (XBUFFER (buf
)->name
, 0) == ' ')
6252 *vecp
++ = XBUFFER (buf
)->read_only
;
6253 *vecp
++ = Fbuffer_modified_p (buf
);
6255 /* Fill up the vector with lambdas (always at least one). */
6257 while (vecp
- XVECTOR (state
)->contents
6258 < XVECTOR (state
)->size
)
6260 /* Make sure we didn't overflow the vector. */
6261 if (vecp
- XVECTOR (state
)->contents
6262 > XVECTOR (state
)->size
)
6269 /***********************************************************************
6271 ***********************************************************************/
6273 /* Initialization done when Emacs fork is started, before doing stty.
6274 Determine terminal type and set terminal_driver. Then invoke its
6275 decoding routine to set up variables in the terminal package. */
6280 char *terminal_type
;
6282 /* Construct the space glyph. */
6283 space_glyph
.type
= CHAR_GLYPH
;
6284 SET_CHAR_GLYPH (space_glyph
, ' ', DEFAULT_FACE_ID
, 0);
6285 space_glyph
.charpos
= -1;
6288 cursor_in_echo_area
= 0;
6289 terminal_type
= (char *) 0;
6291 /* Now is the time to initialize this; it's used by init_sys_modes
6293 Vinitial_window_system
= Qnil
;
6295 /* SIGWINCH needs to be handled no matter what display we start
6296 with. Otherwise newly opened tty frames will not resize
6301 #endif /* CANNOT_DUMP */
6302 signal (SIGWINCH
, window_change_signal
);
6303 #endif /* SIGWINCH */
6305 /* If running as a daemon, no need to initialize any frames/terminal. */
6309 /* If the user wants to use a window system, we shouldn't bother
6310 initializing the terminal. This is especially important when the
6311 terminal is so dumb that emacs gives up before and doesn't bother
6312 using the window system.
6314 If the DISPLAY environment variable is set and nonempty,
6315 try to use X, and die with an error message if that doesn't work. */
6317 #ifdef HAVE_X_WINDOWS
6318 if (! inhibit_window_system
&& ! display_arg
)
6321 display
= getenv ("DISPLAY");
6322 display_arg
= (display
!= 0 && *display
!= 0);
6324 if (display_arg
&& !x_display_ok (display
))
6326 fprintf (stderr
, "Display %s unavailable, simulating -nw\n",
6328 inhibit_window_system
= 1;
6332 if (!inhibit_window_system
&& display_arg
6338 Vinitial_window_system
= Qx
;
6340 Vwindow_system_version
= make_number (11);
6342 #if defined (GNU_LINUX) && defined (HAVE_LIBNCURSES)
6343 /* In some versions of ncurses,
6344 tputs crashes if we have not called tgetent.
6346 { char b
[2044]; tgetent (b
, "xterm");}
6348 adjust_frame_glyphs_initially ();
6351 #endif /* HAVE_X_WINDOWS */
6354 if (!inhibit_window_system
)
6356 Vinitial_window_system
= Qw32
;
6357 Vwindow_system_version
= make_number (1);
6358 adjust_frame_glyphs_initially ();
6361 #endif /* HAVE_NTGUI */
6364 if (!inhibit_window_system
6370 Vinitial_window_system
= Qns
;
6371 Vwindow_system_version
= make_number(10);
6372 adjust_frame_glyphs_initially ();
6377 /* If no window system has been specified, try to use the terminal. */
6380 fatal ("standard input is not a tty");
6385 terminal_type
= "w32console";
6387 /* Look at the TERM variable. */
6388 terminal_type
= (char *) getenv ("TERM");
6392 #ifdef HAVE_WINDOW_SYSTEM
6393 if (! inhibit_window_system
)
6394 fprintf (stderr
, "Please set the environment variable DISPLAY or TERM (see `tset').\n");
6396 #endif /* HAVE_WINDOW_SYSTEM */
6397 fprintf (stderr
, "Please set the environment variable TERM; see `tset'.\n");
6403 struct frame
*f
= XFRAME (selected_frame
);
6405 /* Open a display on the controlling tty. */
6406 t
= init_tty (0, terminal_type
, 1); /* Errors are fatal. */
6408 /* Convert the initial frame to use the new display. */
6409 if (f
->output_method
!= output_initial
)
6411 f
->output_method
= t
->type
;
6414 t
->reference_count
++;
6416 f
->output_data
.tty
->display_info
= &the_only_display_info
;
6418 if (f
->output_method
== output_termcap
)
6419 create_tty_output (f
);
6421 t
->display_info
.tty
->top_frame
= selected_frame
;
6422 change_frame_size (XFRAME (selected_frame
),
6423 FrameRows (t
->display_info
.tty
),
6424 FrameCols (t
->display_info
.tty
), 0, 0, 1);
6426 /* Delete the initial terminal. */
6427 if (--initial_terminal
->reference_count
== 0
6428 && initial_terminal
->delete_terminal_hook
)
6429 (*initial_terminal
->delete_terminal_hook
) (initial_terminal
);
6431 /* Update frame parameters to reflect the new type. */
6432 Fmodify_frame_parameters
6433 (selected_frame
, Fcons (Fcons (Qtty_type
,
6434 Ftty_type (selected_frame
)), Qnil
));
6435 if (t
->display_info
.tty
->name
)
6436 Fmodify_frame_parameters (selected_frame
,
6437 Fcons (Fcons (Qtty
, build_string (t
->display_info
.tty
->name
)),
6440 Fmodify_frame_parameters (selected_frame
, Fcons (Fcons (Qtty
, Qnil
),
6445 struct frame
*sf
= SELECTED_FRAME ();
6446 int width
= FRAME_TOTAL_COLS (sf
);
6447 int height
= FRAME_LINES (sf
);
6449 unsigned int total_glyphs
= height
* (width
+ 2) * sizeof (struct glyph
);
6451 /* If these sizes are so big they cause overflow, just ignore the
6452 change. It's not clear what better we could do. */
6453 if (total_glyphs
/ sizeof (struct glyph
) / height
!= width
+ 2)
6454 fatal ("screen size %dx%d too big", width
, height
);
6457 adjust_frame_glyphs_initially ();
6458 calculate_costs (XFRAME (selected_frame
));
6460 /* Set up faces of the initial terminal frame of a dumped Emacs. */
6463 && NILP (Vinitial_window_system
))
6465 /* For the initial frame, we don't have any way of knowing what
6466 are the foreground and background colors of the terminal. */
6467 struct frame
*sf
= SELECTED_FRAME();
6469 FRAME_FOREGROUND_PIXEL (sf
) = FACE_TTY_DEFAULT_FG_COLOR
;
6470 FRAME_BACKGROUND_PIXEL (sf
) = FACE_TTY_DEFAULT_BG_COLOR
;
6471 call0 (intern ("tty-set-up-initial-frame-faces"));
6477 /***********************************************************************
6479 ***********************************************************************/
6481 DEFUN ("internal-show-cursor", Finternal_show_cursor
,
6482 Sinternal_show_cursor
, 2, 2, 0,
6483 doc
: /* Set the cursor-visibility flag of WINDOW to SHOW.
6484 WINDOW nil means use the selected window. SHOW non-nil means
6485 show a cursor in WINDOW in the next redisplay. SHOW nil means
6486 don't show a cursor. */)
6487 (Lisp_Object window
, Lisp_Object show
)
6489 /* Don't change cursor state while redisplaying. This could confuse
6491 if (!redisplaying_p
)
6494 window
= selected_window
;
6496 CHECK_WINDOW (window
);
6498 XWINDOW (window
)->cursor_off_p
= NILP (show
);
6505 DEFUN ("internal-show-cursor-p", Finternal_show_cursor_p
,
6506 Sinternal_show_cursor_p
, 0, 1, 0,
6507 doc
: /* Value is non-nil if next redisplay will display a cursor in WINDOW.
6508 WINDOW nil or omitted means report on the selected window. */)
6509 (Lisp_Object window
)
6514 window
= selected_window
;
6516 CHECK_WINDOW (window
);
6518 w
= XWINDOW (window
);
6519 return w
->cursor_off_p
? Qnil
: Qt
;
6522 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame
,
6523 Slast_nonminibuf_frame
, 0, 0, 0,
6524 doc
: /* Value is last nonminibuffer frame. */)
6527 Lisp_Object frame
= Qnil
;
6529 if (last_nonminibuf_frame
)
6530 XSETFRAME (frame
, last_nonminibuf_frame
);
6535 /***********************************************************************
6537 ***********************************************************************/
6540 syms_of_display (void)
6542 defsubr (&Sredraw_frame
);
6543 defsubr (&Sredraw_display
);
6544 defsubr (&Sframe_or_buffer_changed_p
);
6545 defsubr (&Sopen_termscript
);
6547 defsubr (&Sredisplay
);
6548 defsubr (&Ssleep_for
);
6549 defsubr (&Ssend_string_to_terminal
);
6550 defsubr (&Sinternal_show_cursor
);
6551 defsubr (&Sinternal_show_cursor_p
);
6552 defsubr (&Slast_nonminibuf_frame
);
6555 defsubr (&Sdump_redisplay_history
);
6558 frame_and_buffer_state
= Fmake_vector (make_number (20), Qlambda
);
6559 staticpro (&frame_and_buffer_state
);
6561 Qdisplay_table
= intern_c_string ("display-table");
6562 staticpro (&Qdisplay_table
);
6563 Qredisplay_dont_pause
= intern_c_string ("redisplay-dont-pause");
6564 staticpro (&Qredisplay_dont_pause
);
6566 DEFVAR_INT ("baud-rate", &baud_rate
,
6567 doc
: /* *The output baud rate of the terminal.
6568 On most systems, changing this value will affect the amount of padding
6569 and the other strategic decisions made during redisplay. */);
6571 DEFVAR_BOOL ("inverse-video", &inverse_video
,
6572 doc
: /* *Non-nil means invert the entire frame display.
6573 This means everything is in inverse video which otherwise would not be. */);
6575 DEFVAR_BOOL ("visible-bell", &visible_bell
,
6576 doc
: /* *Non-nil means try to flash the frame to represent a bell.
6578 See also `ring-bell-function'. */);
6580 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter
,
6581 doc
: /* *Non-nil means no need to redraw entire frame after suspending.
6582 A non-nil value is useful if the terminal can automatically preserve
6583 Emacs's frame display when you reenter Emacs.
6584 It is up to you to set this variable if your terminal can do that. */);
6586 DEFVAR_LISP ("initial-window-system", &Vinitial_window_system
,
6587 doc
: /* Name of the window system that Emacs uses for the first frame.
6588 The value is a symbol:
6589 nil for a termcap frame (a character-only terminal),
6590 'x' for an Emacs frame that is really an X window,
6591 'w32' for an Emacs frame that is a window on MS-Windows display,
6592 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
6593 'pc' for a direct-write MS-DOS frame.
6595 Use of this variable as a boolean is deprecated. Instead,
6596 use `display-graphic-p' or any of the other `display-*-p'
6597 predicates which report frame's specific UI-related capabilities. */);
6599 DEFVAR_KBOARD ("window-system", Vwindow_system
,
6600 doc
: /* Name of window system through which the selected frame is displayed.
6601 The value is a symbol:
6602 nil for a termcap frame (a character-only terminal),
6603 'x' for an Emacs frame that is really an X window,
6604 'w32' for an Emacs frame that is a window on MS-Windows display,
6605 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
6606 'pc' for a direct-write MS-DOS frame.
6608 Use of this variable as a boolean is deprecated. Instead,
6609 use `display-graphic-p' or any of the other `display-*-p'
6610 predicates which report frame's specific UI-related capabilities. */);
6612 DEFVAR_LISP ("window-system-version", &Vwindow_system_version
,
6613 doc
: /* The version number of the window system in use.
6614 For X windows, this is 11. */);
6616 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area
,
6617 doc
: /* Non-nil means put cursor in minibuffer, at end of any message there. */);
6619 DEFVAR_LISP ("glyph-table", &Vglyph_table
,
6620 doc
: /* Table defining how to output a glyph code to the frame.
6621 If not nil, this is a vector indexed by glyph code to define the glyph.
6622 Each element can be:
6623 integer: a glyph code which this glyph is an alias for.
6624 string: output this glyph using that string (not impl. in X windows).
6625 nil: this glyph mod 524288 is the code of a character to output,
6626 and this glyph / 524288 is the face number (see `face-id') to use
6627 while outputting it. */);
6628 Vglyph_table
= Qnil
;
6630 DEFVAR_LISP ("standard-display-table", &Vstandard_display_table
,
6631 doc
: /* Display table to use for buffers that specify none.
6632 See `buffer-display-table' for more information. */);
6633 Vstandard_display_table
= Qnil
;
6635 DEFVAR_BOOL ("redisplay-dont-pause", &redisplay_dont_pause
,
6636 doc
: /* *Non-nil means update isn't paused when input is detected. */);
6637 redisplay_dont_pause
= 0;
6639 #if PERIODIC_PREEMPTION_CHECKING
6640 DEFVAR_LISP ("redisplay-preemption-period", &Vredisplay_preemption_period
,
6641 doc
: /* *The period in seconds between checking for input during redisplay.
6642 If input is detected, redisplay is pre-empted, and the input is processed.
6643 If nil, never pre-empt redisplay. */);
6644 Vredisplay_preemption_period
= make_float (0.10);
6651 Vinitial_window_system
= Qnil
;
6652 Vwindow_system_version
= Qnil
;
6656 /* arch-tag: 8d812b1f-04a2-4195-a9c4-381f8457a413
6657 (do not change this comment) */