1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
205 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
206 extern int pending_menu_activation
;
209 extern int interrupt_input
;
210 extern int command_loop_level
;
212 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Vminibuffer_list
;
215 extern Lisp_Object Qface
;
216 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
218 extern Lisp_Object Voverriding_local_map
;
219 extern Lisp_Object Voverriding_local_map_menu_flag
;
220 extern Lisp_Object Qmenu_item
;
221 extern Lisp_Object Qwhen
;
223 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
224 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
225 Lisp_Object Qredisplay_end_trigger_functions
;
226 Lisp_Object Qinhibit_point_motion_hooks
;
227 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
228 Lisp_Object Qfontified
;
229 Lisp_Object Qgrow_only
;
230 Lisp_Object Qinhibit_eval_during_redisplay
;
231 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
234 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
236 Lisp_Object Qrisky_local_variable
;
238 /* Holds the list (error). */
239 Lisp_Object list_of_error
;
241 /* Functions called to fontify regions of text. */
243 Lisp_Object Vfontification_functions
;
244 Lisp_Object Qfontification_functions
;
246 /* Non-zero means draw tool bar buttons raised when the mouse moves
249 int auto_raise_tool_bar_buttons_p
;
251 /* Margin around tool bar buttons in pixels. */
253 Lisp_Object Vtool_bar_button_margin
;
255 /* Thickness of shadow to draw around tool bar buttons. */
257 EMACS_INT tool_bar_button_relief
;
259 /* Non-zero means automatically resize tool-bars so that all tool-bar
260 items are visible, and no blank lines remain. */
262 int auto_resize_tool_bars_p
;
264 /* Non-nil means don't actually do any redisplay. */
266 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
268 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
270 int inhibit_eval_during_redisplay
;
272 /* Names of text properties relevant for redisplay. */
274 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
275 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
277 /* Symbols used in text property values. */
279 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
280 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
282 extern Lisp_Object Qheight
;
284 /* Non-nil means highlight trailing whitespace. */
286 Lisp_Object Vshow_trailing_whitespace
;
288 /* Name of the face used to highlight trailing whitespace. */
290 Lisp_Object Qtrailing_whitespace
;
292 /* The symbol `image' which is the car of the lists used to represent
297 /* Non-zero means print newline to stdout before next mini-buffer
300 int noninteractive_need_newline
;
302 /* Non-zero means print newline to message log before next message. */
304 static int message_log_need_newline
;
306 /* Three markers that message_dolog uses.
307 It could allocate them itself, but that causes trouble
308 in handling memory-full errors. */
309 static Lisp_Object message_dolog_marker1
;
310 static Lisp_Object message_dolog_marker2
;
311 static Lisp_Object message_dolog_marker3
;
313 /* The buffer position of the first character appearing entirely or
314 partially on the line of the selected window which contains the
315 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
316 redisplay optimization in redisplay_internal. */
318 static struct text_pos this_line_start_pos
;
320 /* Number of characters past the end of the line above, including the
321 terminating newline. */
323 static struct text_pos this_line_end_pos
;
325 /* The vertical positions and the height of this line. */
327 static int this_line_vpos
;
328 static int this_line_y
;
329 static int this_line_pixel_height
;
331 /* X position at which this display line starts. Usually zero;
332 negative if first character is partially visible. */
334 static int this_line_start_x
;
336 /* Buffer that this_line_.* variables are referring to. */
338 static struct buffer
*this_line_buffer
;
340 /* Nonzero means truncate lines in all windows less wide than the
343 int truncate_partial_width_windows
;
345 /* A flag to control how to display unibyte 8-bit character. */
347 int unibyte_display_via_language_environment
;
349 /* Nonzero means we have more than one non-mini-buffer-only frame.
350 Not guaranteed to be accurate except while parsing
351 frame-title-format. */
355 Lisp_Object Vglobal_mode_string
;
357 /* Marker for where to display an arrow on top of the buffer text. */
359 Lisp_Object Voverlay_arrow_position
;
361 /* String to display for the arrow. Only used on terminal frames. */
363 Lisp_Object Voverlay_arrow_string
;
365 /* Values of those variables at last redisplay. However, if
366 Voverlay_arrow_position is a marker, last_arrow_position is its
367 numerical position. */
369 static Lisp_Object last_arrow_position
, last_arrow_string
;
371 /* Like mode-line-format, but for the title bar on a visible frame. */
373 Lisp_Object Vframe_title_format
;
375 /* Like mode-line-format, but for the title bar on an iconified frame. */
377 Lisp_Object Vicon_title_format
;
379 /* List of functions to call when a window's size changes. These
380 functions get one arg, a frame on which one or more windows' sizes
383 static Lisp_Object Vwindow_size_change_functions
;
385 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
387 /* Nonzero if overlay arrow has been displayed once in this window. */
389 static int overlay_arrow_seen
;
391 /* Nonzero means highlight the region even in nonselected windows. */
393 int highlight_nonselected_windows
;
395 /* If cursor motion alone moves point off frame, try scrolling this
396 many lines up or down if that will bring it back. */
398 static EMACS_INT scroll_step
;
400 /* Nonzero means scroll just far enough to bring point back on the
401 screen, when appropriate. */
403 static EMACS_INT scroll_conservatively
;
405 /* Recenter the window whenever point gets within this many lines of
406 the top or bottom of the window. This value is translated into a
407 pixel value by multiplying it with CANON_Y_UNIT, which means that
408 there is really a fixed pixel height scroll margin. */
410 EMACS_INT scroll_margin
;
412 /* Number of windows showing the buffer of the selected window (or
413 another buffer with the same base buffer). keyboard.c refers to
418 /* Vector containing glyphs for an ellipsis `...'. */
420 static Lisp_Object default_invis_vector
[3];
422 /* Zero means display the mode-line/header-line/menu-bar in the default face
423 (this slightly odd definition is for compatibility with previous versions
424 of emacs), non-zero means display them using their respective faces.
426 This variable is deprecated. */
428 int mode_line_inverse_video
;
430 /* Prompt to display in front of the mini-buffer contents. */
432 Lisp_Object minibuf_prompt
;
434 /* Width of current mini-buffer prompt. Only set after display_line
435 of the line that contains the prompt. */
437 int minibuf_prompt_width
;
439 /* This is the window where the echo area message was displayed. It
440 is always a mini-buffer window, but it may not be the same window
441 currently active as a mini-buffer. */
443 Lisp_Object echo_area_window
;
445 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
446 pushes the current message and the value of
447 message_enable_multibyte on the stack, the function restore_message
448 pops the stack and displays MESSAGE again. */
450 Lisp_Object Vmessage_stack
;
452 /* Nonzero means multibyte characters were enabled when the echo area
453 message was specified. */
455 int message_enable_multibyte
;
457 /* Nonzero if we should redraw the mode lines on the next redisplay. */
459 int update_mode_lines
;
461 /* Nonzero if window sizes or contents have changed since last
462 redisplay that finished. */
464 int windows_or_buffers_changed
;
466 /* Nonzero means a frame's cursor type has been changed. */
468 int cursor_type_changed
;
470 /* Nonzero after display_mode_line if %l was used and it displayed a
473 int line_number_displayed
;
475 /* Maximum buffer size for which to display line numbers. */
477 Lisp_Object Vline_number_display_limit
;
479 /* Line width to consider when repositioning for line number display. */
481 static EMACS_INT line_number_display_limit_width
;
483 /* Number of lines to keep in the message log buffer. t means
484 infinite. nil means don't log at all. */
486 Lisp_Object Vmessage_log_max
;
488 /* The name of the *Messages* buffer, a string. */
490 static Lisp_Object Vmessages_buffer_name
;
492 /* Current, index 0, and last displayed echo area message. Either
493 buffers from echo_buffers, or nil to indicate no message. */
495 Lisp_Object echo_area_buffer
[2];
497 /* The buffers referenced from echo_area_buffer. */
499 static Lisp_Object echo_buffer
[2];
501 /* A vector saved used in with_area_buffer to reduce consing. */
503 static Lisp_Object Vwith_echo_area_save_vector
;
505 /* Non-zero means display_echo_area should display the last echo area
506 message again. Set by redisplay_preserve_echo_area. */
508 static int display_last_displayed_message_p
;
510 /* Nonzero if echo area is being used by print; zero if being used by
513 int message_buf_print
;
515 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
517 Lisp_Object Qinhibit_menubar_update
;
518 int inhibit_menubar_update
;
520 /* Maximum height for resizing mini-windows. Either a float
521 specifying a fraction of the available height, or an integer
522 specifying a number of lines. */
524 Lisp_Object Vmax_mini_window_height
;
526 /* Non-zero means messages should be displayed with truncated
527 lines instead of being continued. */
529 int message_truncate_lines
;
530 Lisp_Object Qmessage_truncate_lines
;
532 /* Set to 1 in clear_message to make redisplay_internal aware
533 of an emptied echo area. */
535 static int message_cleared_p
;
537 /* Non-zero means we want a hollow cursor in windows that are not
538 selected. Zero means there's no cursor in such windows. */
540 Lisp_Object Vcursor_in_non_selected_windows
;
541 Lisp_Object Qcursor_in_non_selected_windows
;
543 /* How to blink the default frame cursor off. */
544 Lisp_Object Vblink_cursor_alist
;
546 /* A scratch glyph row with contents used for generating truncation
547 glyphs. Also used in direct_output_for_insert. */
549 #define MAX_SCRATCH_GLYPHS 100
550 struct glyph_row scratch_glyph_row
;
551 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
553 /* Ascent and height of the last line processed by move_it_to. */
555 static int last_max_ascent
, last_height
;
557 /* Non-zero if there's a help-echo in the echo area. */
559 int help_echo_showing_p
;
561 /* If >= 0, computed, exact values of mode-line and header-line height
562 to use in the macros CURRENT_MODE_LINE_HEIGHT and
563 CURRENT_HEADER_LINE_HEIGHT. */
565 int current_mode_line_height
, current_header_line_height
;
567 /* The maximum distance to look ahead for text properties. Values
568 that are too small let us call compute_char_face and similar
569 functions too often which is expensive. Values that are too large
570 let us call compute_char_face and alike too often because we
571 might not be interested in text properties that far away. */
573 #define TEXT_PROP_DISTANCE_LIMIT 100
577 /* Variables to turn off display optimizations from Lisp. */
579 int inhibit_try_window_id
, inhibit_try_window_reusing
;
580 int inhibit_try_cursor_movement
;
582 /* Non-zero means print traces of redisplay if compiled with
585 int trace_redisplay_p
;
587 #endif /* GLYPH_DEBUG */
589 #ifdef DEBUG_TRACE_MOVE
590 /* Non-zero means trace with TRACE_MOVE to stderr. */
593 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
595 #define TRACE_MOVE(x) (void) 0
598 /* Non-zero means automatically scroll windows horizontally to make
601 int automatic_hscrolling_p
;
603 /* How close to the margin can point get before the window is scrolled
605 EMACS_INT hscroll_margin
;
607 /* How much to scroll horizontally when point is inside the above margin. */
608 Lisp_Object Vhscroll_step
;
610 /* A list of symbols, one for each supported image type. */
612 Lisp_Object Vimage_types
;
614 /* The variable `resize-mini-windows'. If nil, don't resize
615 mini-windows. If t, always resize them to fit the text they
616 display. If `grow-only', let mini-windows grow only until they
619 Lisp_Object Vresize_mini_windows
;
621 /* Buffer being redisplayed -- for redisplay_window_error. */
623 struct buffer
*displayed_buffer
;
625 /* Value returned from text property handlers (see below). */
630 HANDLED_RECOMPUTE_PROPS
,
631 HANDLED_OVERLAY_STRING_CONSUMED
,
635 /* A description of text properties that redisplay is interested
640 /* The name of the property. */
643 /* A unique index for the property. */
646 /* A handler function called to set up iterator IT from the property
647 at IT's current position. Value is used to steer handle_stop. */
648 enum prop_handled (*handler
) P_ ((struct it
*it
));
651 static enum prop_handled handle_face_prop
P_ ((struct it
*));
652 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
653 static enum prop_handled handle_display_prop
P_ ((struct it
*));
654 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
655 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
656 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
658 /* Properties handled by iterators. */
660 static struct props it_props
[] =
662 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
663 /* Handle `face' before `display' because some sub-properties of
664 `display' need to know the face. */
665 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
666 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
667 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
668 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
672 /* Value is the position described by X. If X is a marker, value is
673 the marker_position of X. Otherwise, value is X. */
675 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
677 /* Enumeration returned by some move_it_.* functions internally. */
681 /* Not used. Undefined value. */
684 /* Move ended at the requested buffer position or ZV. */
685 MOVE_POS_MATCH_OR_ZV
,
687 /* Move ended at the requested X pixel position. */
690 /* Move within a line ended at the end of a line that must be
694 /* Move within a line ended at the end of a line that would
695 be displayed truncated. */
698 /* Move within a line ended at a line end. */
702 /* This counter is used to clear the face cache every once in a while
703 in redisplay_internal. It is incremented for each redisplay.
704 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
707 #define CLEAR_FACE_CACHE_COUNT 500
708 static int clear_face_cache_count
;
710 /* Record the previous terminal frame we displayed. */
712 static struct frame
*previous_terminal_frame
;
714 /* Non-zero while redisplay_internal is in progress. */
718 /* Non-zero means don't free realized faces. Bound while freeing
719 realized faces is dangerous because glyph matrices might still
722 int inhibit_free_realized_faces
;
723 Lisp_Object Qinhibit_free_realized_faces
;
726 /* Function prototypes. */
728 static void setup_for_ellipsis
P_ ((struct it
*));
729 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
730 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
731 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
732 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
733 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
734 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
737 static int invisible_text_between_p
P_ ((struct it
*, int, int));
740 static int next_element_from_ellipsis
P_ ((struct it
*));
741 static void pint2str
P_ ((char *, int, int));
742 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
744 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
745 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
746 static void store_frame_title_char
P_ ((char));
747 static int store_frame_title
P_ ((const unsigned char *, int, int));
748 static void x_consider_frame_title
P_ ((Lisp_Object
));
749 static void handle_stop
P_ ((struct it
*));
750 static int tool_bar_lines_needed
P_ ((struct frame
*));
751 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
752 static void ensure_echo_area_buffers
P_ ((void));
753 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
754 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
755 static int with_echo_area_buffer
P_ ((struct window
*, int,
756 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
757 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
758 static void clear_garbaged_frames
P_ ((void));
759 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
760 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
761 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
762 static int display_echo_area
P_ ((struct window
*));
763 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
764 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
765 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
766 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
767 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
769 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
770 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
771 static void insert_left_trunc_glyphs
P_ ((struct it
*));
772 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
773 static void extend_face_to_end_of_line
P_ ((struct it
*));
774 static int append_space
P_ ((struct it
*, int));
775 static int make_cursor_line_fully_visible
P_ ((struct window
*));
776 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
777 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
778 static int trailing_whitespace_p
P_ ((int));
779 static int message_log_check_duplicate
P_ ((int, int, int, int));
780 static void push_it
P_ ((struct it
*));
781 static void pop_it
P_ ((struct it
*));
782 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
783 static void redisplay_internal
P_ ((int));
784 static int echo_area_display
P_ ((int));
785 static void redisplay_windows
P_ ((Lisp_Object
));
786 static void redisplay_window
P_ ((Lisp_Object
, int));
787 static Lisp_Object
redisplay_window_error ();
788 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
789 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
790 static void update_menu_bar
P_ ((struct frame
*, int));
791 static int try_window_reusing_current_matrix
P_ ((struct window
*));
792 static int try_window_id
P_ ((struct window
*));
793 static int display_line
P_ ((struct it
*));
794 static int display_mode_lines
P_ ((struct window
*));
795 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
796 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
797 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
798 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
799 static void display_menu_bar
P_ ((struct window
*));
800 static int display_count_lines
P_ ((int, int, int, int, int *));
801 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
802 int, int, struct it
*, int, int, int, int));
803 static void compute_line_metrics
P_ ((struct it
*));
804 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
805 static int get_overlay_strings
P_ ((struct it
*, int));
806 static void next_overlay_string
P_ ((struct it
*));
807 static void reseat
P_ ((struct it
*, struct text_pos
, int));
808 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
809 static void back_to_previous_visible_line_start
P_ ((struct it
*));
810 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
811 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
812 static int next_element_from_display_vector
P_ ((struct it
*));
813 static int next_element_from_string
P_ ((struct it
*));
814 static int next_element_from_c_string
P_ ((struct it
*));
815 static int next_element_from_buffer
P_ ((struct it
*));
816 static int next_element_from_composition
P_ ((struct it
*));
817 static int next_element_from_image
P_ ((struct it
*));
818 static int next_element_from_stretch
P_ ((struct it
*));
819 static void load_overlay_strings
P_ ((struct it
*, int));
820 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
821 struct display_pos
*));
822 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
823 Lisp_Object
, int, int, int, int));
824 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
826 void move_it_vertically_backward
P_ ((struct it
*, int));
827 static void init_to_row_start
P_ ((struct it
*, struct window
*,
828 struct glyph_row
*));
829 static int init_to_row_end
P_ ((struct it
*, struct window
*,
830 struct glyph_row
*));
831 static void back_to_previous_line_start
P_ ((struct it
*));
832 static int forward_to_next_line_start
P_ ((struct it
*, int *));
833 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
835 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
836 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
837 static int number_of_chars
P_ ((unsigned char *, int));
838 static void compute_stop_pos
P_ ((struct it
*));
839 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
841 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
842 static int next_overlay_change
P_ ((int));
843 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
844 Lisp_Object
, struct text_pos
*,
846 static int underlying_face_id
P_ ((struct it
*));
847 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
850 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
851 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
853 #ifdef HAVE_WINDOW_SYSTEM
855 static void update_tool_bar
P_ ((struct frame
*, int));
856 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
857 static int redisplay_tool_bar
P_ ((struct frame
*));
858 static void display_tool_bar_line
P_ ((struct it
*));
860 #endif /* HAVE_WINDOW_SYSTEM */
863 /***********************************************************************
864 Window display dimensions
865 ***********************************************************************/
867 /* Return the bottom boundary y-position for text lines in window W.
868 This is the first y position at which a line cannot start.
869 It is relative to the top of the window.
871 This is the height of W minus the height of a mode line, if any. */
874 window_text_bottom_y (w
)
877 struct frame
*f
= XFRAME (w
->frame
);
878 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
880 if (WINDOW_WANTS_MODELINE_P (w
))
881 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
886 /* Return the pixel width of display area AREA of window W. AREA < 0
887 means return the total width of W, not including fringes to
888 the left and right of the window. */
891 window_box_width (w
, area
)
895 struct frame
*f
= XFRAME (w
->frame
);
896 int width
= XFASTINT (w
->width
);
898 if (!w
->pseudo_window_p
)
900 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
902 if (area
== TEXT_AREA
)
904 if (INTEGERP (w
->left_margin_width
))
905 width
-= XFASTINT (w
->left_margin_width
);
906 if (INTEGERP (w
->right_margin_width
))
907 width
-= XFASTINT (w
->right_margin_width
);
909 else if (area
== LEFT_MARGIN_AREA
)
910 width
= (INTEGERP (w
->left_margin_width
)
911 ? XFASTINT (w
->left_margin_width
) : 0);
912 else if (area
== RIGHT_MARGIN_AREA
)
913 width
= (INTEGERP (w
->right_margin_width
)
914 ? XFASTINT (w
->right_margin_width
) : 0);
917 return width
* CANON_X_UNIT (f
);
921 /* Return the pixel height of the display area of window W, not
922 including mode lines of W, if any. */
925 window_box_height (w
)
928 struct frame
*f
= XFRAME (w
->frame
);
929 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
931 xassert (height
>= 0);
933 /* Note: the code below that determines the mode-line/header-line
934 height is essentially the same as that contained in the macro
935 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
936 the appropriate glyph row has its `mode_line_p' flag set,
937 and if it doesn't, uses estimate_mode_line_height instead. */
939 if (WINDOW_WANTS_MODELINE_P (w
))
941 struct glyph_row
*ml_row
942 = (w
->current_matrix
&& w
->current_matrix
->rows
943 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
945 if (ml_row
&& ml_row
->mode_line_p
)
946 height
-= ml_row
->height
;
948 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
951 if (WINDOW_WANTS_HEADER_LINE_P (w
))
953 struct glyph_row
*hl_row
954 = (w
->current_matrix
&& w
->current_matrix
->rows
955 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
957 if (hl_row
&& hl_row
->mode_line_p
)
958 height
-= hl_row
->height
;
960 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
963 /* With a very small font and a mode-line that's taller than
964 default, we might end up with a negative height. */
965 return max (0, height
);
969 /* Return the frame-relative coordinate of the left edge of display
970 area AREA of window W. AREA < 0 means return the left edge of the
971 whole window, to the right of the left fringe of W. */
974 window_box_left (w
, area
)
978 struct frame
*f
= XFRAME (w
->frame
);
979 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
981 if (!w
->pseudo_window_p
)
983 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
984 + FRAME_LEFT_FRINGE_WIDTH (f
));
986 if (area
== TEXT_AREA
)
987 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
988 else if (area
== RIGHT_MARGIN_AREA
)
989 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
990 + window_box_width (w
, TEXT_AREA
));
997 /* Return the frame-relative coordinate of the right edge of display
998 area AREA of window W. AREA < 0 means return the left edge of the
999 whole window, to the left of the right fringe of W. */
1002 window_box_right (w
, area
)
1006 return window_box_left (w
, area
) + window_box_width (w
, area
);
1010 /* Get the bounding box of the display area AREA of window W, without
1011 mode lines, in frame-relative coordinates. AREA < 0 means the
1012 whole window, not including the left and right fringes of
1013 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1014 coordinates of the upper-left corner of the box. Return in
1015 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1018 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1021 int *box_x
, *box_y
, *box_width
, *box_height
;
1023 struct frame
*f
= XFRAME (w
->frame
);
1025 *box_width
= window_box_width (w
, area
);
1026 *box_height
= window_box_height (w
);
1027 *box_x
= window_box_left (w
, area
);
1028 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
1029 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
1030 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1031 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1035 /* Get the bounding box of the display area AREA of window W, without
1036 mode lines. AREA < 0 means the whole window, not including the
1037 left and right fringe of the window. Return in *TOP_LEFT_X
1038 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1039 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1040 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1044 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1045 bottom_right_x
, bottom_right_y
)
1048 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1050 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1052 *bottom_right_x
+= *top_left_x
;
1053 *bottom_right_y
+= *top_left_y
;
1058 /***********************************************************************
1060 ***********************************************************************/
1062 /* Return the bottom y-position of the line the iterator IT is in.
1063 This can modify IT's settings. */
1069 int line_height
= it
->max_ascent
+ it
->max_descent
;
1070 int line_top_y
= it
->current_y
;
1072 if (line_height
== 0)
1075 line_height
= last_height
;
1076 else if (IT_CHARPOS (*it
) < ZV
)
1078 move_it_by_lines (it
, 1, 1);
1079 line_height
= (it
->max_ascent
|| it
->max_descent
1080 ? it
->max_ascent
+ it
->max_descent
1085 struct glyph_row
*row
= it
->glyph_row
;
1087 /* Use the default character height. */
1088 it
->glyph_row
= NULL
;
1089 it
->what
= IT_CHARACTER
;
1092 PRODUCE_GLYPHS (it
);
1093 line_height
= it
->ascent
+ it
->descent
;
1094 it
->glyph_row
= row
;
1098 return line_top_y
+ line_height
;
1102 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1103 1 if POS is visible and the line containing POS is fully visible.
1104 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1105 and header-lines heights. */
1108 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1110 int charpos
, *fully
, exact_mode_line_heights_p
;
1113 struct text_pos top
;
1115 struct buffer
*old_buffer
= NULL
;
1117 if (XBUFFER (w
->buffer
) != current_buffer
)
1119 old_buffer
= current_buffer
;
1120 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1123 *fully
= visible_p
= 0;
1124 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1126 /* Compute exact mode line heights, if requested. */
1127 if (exact_mode_line_heights_p
)
1129 if (WINDOW_WANTS_MODELINE_P (w
))
1130 current_mode_line_height
1131 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1132 current_buffer
->mode_line_format
);
1134 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1135 current_header_line_height
1136 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1137 current_buffer
->header_line_format
);
1140 start_display (&it
, w
, top
);
1141 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1142 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1144 /* Note that we may overshoot because of invisible text. */
1145 if (IT_CHARPOS (it
) >= charpos
)
1147 int top_y
= it
.current_y
;
1148 int bottom_y
= line_bottom_y (&it
);
1149 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1151 if (top_y
< window_top_y
)
1152 visible_p
= bottom_y
> window_top_y
;
1153 else if (top_y
< it
.last_visible_y
)
1156 *fully
= bottom_y
<= it
.last_visible_y
;
1159 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1161 move_it_by_lines (&it
, 1, 0);
1162 if (charpos
< IT_CHARPOS (it
))
1170 set_buffer_internal_1 (old_buffer
);
1172 current_header_line_height
= current_mode_line_height
= -1;
1177 /* Return the next character from STR which is MAXLEN bytes long.
1178 Return in *LEN the length of the character. This is like
1179 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1180 we find one, we return a `?', but with the length of the invalid
1184 string_char_and_length (str
, maxlen
, len
)
1185 const unsigned char *str
;
1190 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1191 if (!CHAR_VALID_P (c
, 1))
1192 /* We may not change the length here because other places in Emacs
1193 don't use this function, i.e. they silently accept invalid
1202 /* Given a position POS containing a valid character and byte position
1203 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1205 static struct text_pos
1206 string_pos_nchars_ahead (pos
, string
, nchars
)
1207 struct text_pos pos
;
1211 xassert (STRINGP (string
) && nchars
>= 0);
1213 if (STRING_MULTIBYTE (string
))
1215 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1216 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1221 string_char_and_length (p
, rest
, &len
);
1222 p
+= len
, rest
-= len
;
1223 xassert (rest
>= 0);
1225 BYTEPOS (pos
) += len
;
1229 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1235 /* Value is the text position, i.e. character and byte position,
1236 for character position CHARPOS in STRING. */
1238 static INLINE
struct text_pos
1239 string_pos (charpos
, string
)
1243 struct text_pos pos
;
1244 xassert (STRINGP (string
));
1245 xassert (charpos
>= 0);
1246 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1251 /* Value is a text position, i.e. character and byte position, for
1252 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1253 means recognize multibyte characters. */
1255 static struct text_pos
1256 c_string_pos (charpos
, s
, multibyte_p
)
1261 struct text_pos pos
;
1263 xassert (s
!= NULL
);
1264 xassert (charpos
>= 0);
1268 int rest
= strlen (s
), len
;
1270 SET_TEXT_POS (pos
, 0, 0);
1273 string_char_and_length (s
, rest
, &len
);
1274 s
+= len
, rest
-= len
;
1275 xassert (rest
>= 0);
1277 BYTEPOS (pos
) += len
;
1281 SET_TEXT_POS (pos
, charpos
, charpos
);
1287 /* Value is the number of characters in C string S. MULTIBYTE_P
1288 non-zero means recognize multibyte characters. */
1291 number_of_chars (s
, multibyte_p
)
1299 int rest
= strlen (s
), len
;
1300 unsigned char *p
= (unsigned char *) s
;
1302 for (nchars
= 0; rest
> 0; ++nchars
)
1304 string_char_and_length (p
, rest
, &len
);
1305 rest
-= len
, p
+= len
;
1309 nchars
= strlen (s
);
1315 /* Compute byte position NEWPOS->bytepos corresponding to
1316 NEWPOS->charpos. POS is a known position in string STRING.
1317 NEWPOS->charpos must be >= POS.charpos. */
1320 compute_string_pos (newpos
, pos
, string
)
1321 struct text_pos
*newpos
, pos
;
1324 xassert (STRINGP (string
));
1325 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1327 if (STRING_MULTIBYTE (string
))
1328 *newpos
= string_pos_nchars_ahead (pos
, string
,
1329 CHARPOS (*newpos
) - CHARPOS (pos
));
1331 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1336 /***********************************************************************
1337 Lisp form evaluation
1338 ***********************************************************************/
1340 /* Error handler for safe_eval and safe_call. */
1343 safe_eval_handler (arg
)
1346 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1351 /* Evaluate SEXPR and return the result, or nil if something went
1352 wrong. Prevent redisplay during the evaluation. */
1360 if (inhibit_eval_during_redisplay
)
1364 int count
= SPECPDL_INDEX ();
1365 struct gcpro gcpro1
;
1368 specbind (Qinhibit_redisplay
, Qt
);
1369 /* Use Qt to ensure debugger does not run,
1370 so there is no possibility of wanting to redisplay. */
1371 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1374 val
= unbind_to (count
, val
);
1381 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1382 Return the result, or nil if something went wrong. Prevent
1383 redisplay during the evaluation. */
1386 safe_call (nargs
, args
)
1392 if (inhibit_eval_during_redisplay
)
1396 int count
= SPECPDL_INDEX ();
1397 struct gcpro gcpro1
;
1400 gcpro1
.nvars
= nargs
;
1401 specbind (Qinhibit_redisplay
, Qt
);
1402 /* Use Qt to ensure debugger does not run,
1403 so there is no possibility of wanting to redisplay. */
1404 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1407 val
= unbind_to (count
, val
);
1414 /* Call function FN with one argument ARG.
1415 Return the result, or nil if something went wrong. */
1418 safe_call1 (fn
, arg
)
1419 Lisp_Object fn
, arg
;
1421 Lisp_Object args
[2];
1424 return safe_call (2, args
);
1429 /***********************************************************************
1431 ***********************************************************************/
1435 /* Define CHECK_IT to perform sanity checks on iterators.
1436 This is for debugging. It is too slow to do unconditionally. */
1442 if (it
->method
== next_element_from_string
)
1444 xassert (STRINGP (it
->string
));
1445 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1447 else if (it
->method
== next_element_from_buffer
)
1449 /* Check that character and byte positions agree. */
1450 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1454 xassert (it
->current
.dpvec_index
>= 0);
1456 xassert (it
->current
.dpvec_index
< 0);
1459 #define CHECK_IT(IT) check_it ((IT))
1463 #define CHECK_IT(IT) (void) 0
1470 /* Check that the window end of window W is what we expect it
1471 to be---the last row in the current matrix displaying text. */
1474 check_window_end (w
)
1477 if (!MINI_WINDOW_P (w
)
1478 && !NILP (w
->window_end_valid
))
1480 struct glyph_row
*row
;
1481 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1482 XFASTINT (w
->window_end_vpos
)),
1484 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1485 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1489 #define CHECK_WINDOW_END(W) check_window_end ((W))
1491 #else /* not GLYPH_DEBUG */
1493 #define CHECK_WINDOW_END(W) (void) 0
1495 #endif /* not GLYPH_DEBUG */
1499 /***********************************************************************
1500 Iterator initialization
1501 ***********************************************************************/
1503 /* Initialize IT for displaying current_buffer in window W, starting
1504 at character position CHARPOS. CHARPOS < 0 means that no buffer
1505 position is specified which is useful when the iterator is assigned
1506 a position later. BYTEPOS is the byte position corresponding to
1507 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1509 If ROW is not null, calls to produce_glyphs with IT as parameter
1510 will produce glyphs in that row.
1512 BASE_FACE_ID is the id of a base face to use. It must be one of
1513 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1514 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1515 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1517 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1518 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1519 will be initialized to use the corresponding mode line glyph row of
1520 the desired matrix of W. */
1523 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1526 int charpos
, bytepos
;
1527 struct glyph_row
*row
;
1528 enum face_id base_face_id
;
1530 int highlight_region_p
;
1532 /* Some precondition checks. */
1533 xassert (w
!= NULL
&& it
!= NULL
);
1534 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1537 /* If face attributes have been changed since the last redisplay,
1538 free realized faces now because they depend on face definitions
1539 that might have changed. Don't free faces while there might be
1540 desired matrices pending which reference these faces. */
1541 if (face_change_count
&& !inhibit_free_realized_faces
)
1543 face_change_count
= 0;
1544 free_all_realized_faces (Qnil
);
1547 /* Use one of the mode line rows of W's desired matrix if
1551 if (base_face_id
== MODE_LINE_FACE_ID
1552 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1553 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1554 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1555 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1559 bzero (it
, sizeof *it
);
1560 it
->current
.overlay_string_index
= -1;
1561 it
->current
.dpvec_index
= -1;
1562 it
->base_face_id
= base_face_id
;
1564 /* The window in which we iterate over current_buffer: */
1565 XSETWINDOW (it
->window
, w
);
1567 it
->f
= XFRAME (w
->frame
);
1569 /* Extra space between lines (on window systems only). */
1570 if (base_face_id
== DEFAULT_FACE_ID
1571 && FRAME_WINDOW_P (it
->f
))
1573 if (NATNUMP (current_buffer
->extra_line_spacing
))
1574 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1575 else if (it
->f
->extra_line_spacing
> 0)
1576 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1579 /* If realized faces have been removed, e.g. because of face
1580 attribute changes of named faces, recompute them. When running
1581 in batch mode, the face cache of Vterminal_frame is null. If
1582 we happen to get called, make a dummy face cache. */
1587 FRAME_FACE_CACHE (it
->f
) == NULL
)
1588 init_frame_faces (it
->f
);
1589 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1590 recompute_basic_faces (it
->f
);
1592 /* Current value of the `space-width', and 'height' properties. */
1593 it
->space_width
= Qnil
;
1594 it
->font_height
= Qnil
;
1596 /* Are control characters displayed as `^C'? */
1597 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1599 /* -1 means everything between a CR and the following line end
1600 is invisible. >0 means lines indented more than this value are
1602 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1603 ? XFASTINT (current_buffer
->selective_display
)
1604 : (!NILP (current_buffer
->selective_display
)
1606 it
->selective_display_ellipsis_p
1607 = !NILP (current_buffer
->selective_display_ellipses
);
1609 /* Display table to use. */
1610 it
->dp
= window_display_table (w
);
1612 /* Are multibyte characters enabled in current_buffer? */
1613 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1615 /* Non-zero if we should highlight the region. */
1617 = (!NILP (Vtransient_mark_mode
)
1618 && !NILP (current_buffer
->mark_active
)
1619 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1621 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1622 start and end of a visible region in window IT->w. Set both to
1623 -1 to indicate no region. */
1624 if (highlight_region_p
1625 /* Maybe highlight only in selected window. */
1626 && (/* Either show region everywhere. */
1627 highlight_nonselected_windows
1628 /* Or show region in the selected window. */
1629 || w
== XWINDOW (selected_window
)
1630 /* Or show the region if we are in the mini-buffer and W is
1631 the window the mini-buffer refers to. */
1632 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1633 && WINDOWP (minibuf_selected_window
)
1634 && w
== XWINDOW (minibuf_selected_window
))))
1636 int charpos
= marker_position (current_buffer
->mark
);
1637 it
->region_beg_charpos
= min (PT
, charpos
);
1638 it
->region_end_charpos
= max (PT
, charpos
);
1641 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1643 /* Get the position at which the redisplay_end_trigger hook should
1644 be run, if it is to be run at all. */
1645 if (MARKERP (w
->redisplay_end_trigger
)
1646 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1647 it
->redisplay_end_trigger_charpos
1648 = marker_position (w
->redisplay_end_trigger
);
1649 else if (INTEGERP (w
->redisplay_end_trigger
))
1650 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1652 /* Correct bogus values of tab_width. */
1653 it
->tab_width
= XINT (current_buffer
->tab_width
);
1654 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1657 /* Are lines in the display truncated? */
1658 it
->truncate_lines_p
1659 = (base_face_id
!= DEFAULT_FACE_ID
1660 || XINT (it
->w
->hscroll
)
1661 || (truncate_partial_width_windows
1662 && !WINDOW_FULL_WIDTH_P (it
->w
))
1663 || !NILP (current_buffer
->truncate_lines
));
1665 /* Get dimensions of truncation and continuation glyphs. These are
1666 displayed as fringe bitmaps under X, so we don't need them for such
1668 if (!FRAME_WINDOW_P (it
->f
))
1670 if (it
->truncate_lines_p
)
1672 /* We will need the truncation glyph. */
1673 xassert (it
->glyph_row
== NULL
);
1674 produce_special_glyphs (it
, IT_TRUNCATION
);
1675 it
->truncation_pixel_width
= it
->pixel_width
;
1679 /* We will need the continuation glyph. */
1680 xassert (it
->glyph_row
== NULL
);
1681 produce_special_glyphs (it
, IT_CONTINUATION
);
1682 it
->continuation_pixel_width
= it
->pixel_width
;
1685 /* Reset these values to zero because the produce_special_glyphs
1686 above has changed them. */
1687 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1688 it
->phys_ascent
= it
->phys_descent
= 0;
1691 /* Set this after getting the dimensions of truncation and
1692 continuation glyphs, so that we don't produce glyphs when calling
1693 produce_special_glyphs, above. */
1694 it
->glyph_row
= row
;
1695 it
->area
= TEXT_AREA
;
1697 /* Get the dimensions of the display area. The display area
1698 consists of the visible window area plus a horizontally scrolled
1699 part to the left of the window. All x-values are relative to the
1700 start of this total display area. */
1701 if (base_face_id
!= DEFAULT_FACE_ID
)
1703 /* Mode lines, menu bar in terminal frames. */
1704 it
->first_visible_x
= 0;
1705 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1710 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1711 it
->last_visible_x
= (it
->first_visible_x
1712 + window_box_width (w
, TEXT_AREA
));
1714 /* If we truncate lines, leave room for the truncator glyph(s) at
1715 the right margin. Otherwise, leave room for the continuation
1716 glyph(s). Truncation and continuation glyphs are not inserted
1717 for window-based redisplay. */
1718 if (!FRAME_WINDOW_P (it
->f
))
1720 if (it
->truncate_lines_p
)
1721 it
->last_visible_x
-= it
->truncation_pixel_width
;
1723 it
->last_visible_x
-= it
->continuation_pixel_width
;
1726 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1727 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1730 /* Leave room for a border glyph. */
1731 if (!FRAME_WINDOW_P (it
->f
)
1732 && !WINDOW_RIGHTMOST_P (it
->w
))
1733 it
->last_visible_x
-= 1;
1735 it
->last_visible_y
= window_text_bottom_y (w
);
1737 /* For mode lines and alike, arrange for the first glyph having a
1738 left box line if the face specifies a box. */
1739 if (base_face_id
!= DEFAULT_FACE_ID
)
1743 it
->face_id
= base_face_id
;
1745 /* If we have a boxed mode line, make the first character appear
1746 with a left box line. */
1747 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1748 if (face
->box
!= FACE_NO_BOX
)
1749 it
->start_of_box_run_p
= 1;
1752 /* If a buffer position was specified, set the iterator there,
1753 getting overlays and face properties from that position. */
1754 if (charpos
>= BUF_BEG (current_buffer
))
1756 it
->end_charpos
= ZV
;
1758 IT_CHARPOS (*it
) = charpos
;
1760 /* Compute byte position if not specified. */
1761 if (bytepos
< charpos
)
1762 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1764 IT_BYTEPOS (*it
) = bytepos
;
1766 /* Compute faces etc. */
1767 reseat (it
, it
->current
.pos
, 1);
1774 /* Initialize IT for the display of window W with window start POS. */
1777 start_display (it
, w
, pos
)
1780 struct text_pos pos
;
1782 struct glyph_row
*row
;
1783 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1785 row
= w
->desired_matrix
->rows
+ first_vpos
;
1786 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1788 if (!it
->truncate_lines_p
)
1790 int start_at_line_beg_p
;
1791 int first_y
= it
->current_y
;
1793 /* If window start is not at a line start, skip forward to POS to
1794 get the correct continuation lines width. */
1795 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1796 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1797 if (!start_at_line_beg_p
)
1801 reseat_at_previous_visible_line_start (it
);
1802 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1804 new_x
= it
->current_x
+ it
->pixel_width
;
1806 /* If lines are continued, this line may end in the middle
1807 of a multi-glyph character (e.g. a control character
1808 displayed as \003, or in the middle of an overlay
1809 string). In this case move_it_to above will not have
1810 taken us to the start of the continuation line but to the
1811 end of the continued line. */
1812 if (it
->current_x
> 0
1813 && !it
->truncate_lines_p
/* Lines are continued. */
1814 && (/* And glyph doesn't fit on the line. */
1815 new_x
> it
->last_visible_x
1816 /* Or it fits exactly and we're on a window
1818 || (new_x
== it
->last_visible_x
1819 && FRAME_WINDOW_P (it
->f
))))
1821 if (it
->current
.dpvec_index
>= 0
1822 || it
->current
.overlay_string_index
>= 0)
1824 set_iterator_to_next (it
, 1);
1825 move_it_in_display_line_to (it
, -1, -1, 0);
1828 it
->continuation_lines_width
+= it
->current_x
;
1831 /* We're starting a new display line, not affected by the
1832 height of the continued line, so clear the appropriate
1833 fields in the iterator structure. */
1834 it
->max_ascent
= it
->max_descent
= 0;
1835 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1837 it
->current_y
= first_y
;
1839 it
->current_x
= it
->hpos
= 0;
1843 #if 0 /* Don't assert the following because start_display is sometimes
1844 called intentionally with a window start that is not at a
1845 line start. Please leave this code in as a comment. */
1847 /* Window start should be on a line start, now. */
1848 xassert (it
->continuation_lines_width
1849 || IT_CHARPOS (it
) == BEGV
1850 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1855 /* Return 1 if POS is a position in ellipses displayed for invisible
1856 text. W is the window we display, for text property lookup. */
1859 in_ellipses_for_invisible_text_p (pos
, w
)
1860 struct display_pos
*pos
;
1863 Lisp_Object prop
, window
;
1865 int charpos
= CHARPOS (pos
->pos
);
1867 /* If POS specifies a position in a display vector, this might
1868 be for an ellipsis displayed for invisible text. We won't
1869 get the iterator set up for delivering that ellipsis unless
1870 we make sure that it gets aware of the invisible text. */
1871 if (pos
->dpvec_index
>= 0
1872 && pos
->overlay_string_index
< 0
1873 && CHARPOS (pos
->string_pos
) < 0
1875 && (XSETWINDOW (window
, w
),
1876 prop
= Fget_char_property (make_number (charpos
),
1877 Qinvisible
, window
),
1878 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1880 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1882 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1889 /* Initialize IT for stepping through current_buffer in window W,
1890 starting at position POS that includes overlay string and display
1891 vector/ control character translation position information. Value
1892 is zero if there are overlay strings with newlines at POS. */
1895 init_from_display_pos (it
, w
, pos
)
1898 struct display_pos
*pos
;
1900 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1901 int i
, overlay_strings_with_newlines
= 0;
1903 /* If POS specifies a position in a display vector, this might
1904 be for an ellipsis displayed for invisible text. We won't
1905 get the iterator set up for delivering that ellipsis unless
1906 we make sure that it gets aware of the invisible text. */
1907 if (in_ellipses_for_invisible_text_p (pos
, w
))
1913 /* Keep in mind: the call to reseat in init_iterator skips invisible
1914 text, so we might end up at a position different from POS. This
1915 is only a problem when POS is a row start after a newline and an
1916 overlay starts there with an after-string, and the overlay has an
1917 invisible property. Since we don't skip invisible text in
1918 display_line and elsewhere immediately after consuming the
1919 newline before the row start, such a POS will not be in a string,
1920 but the call to init_iterator below will move us to the
1922 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1924 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1926 const char *s
= SDATA (it
->overlay_strings
[i
]);
1927 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
1929 while (s
< e
&& *s
!= '\n')
1934 overlay_strings_with_newlines
= 1;
1939 /* If position is within an overlay string, set up IT to the right
1941 if (pos
->overlay_string_index
>= 0)
1945 /* If the first overlay string happens to have a `display'
1946 property for an image, the iterator will be set up for that
1947 image, and we have to undo that setup first before we can
1948 correct the overlay string index. */
1949 if (it
->method
== next_element_from_image
)
1952 /* We already have the first chunk of overlay strings in
1953 IT->overlay_strings. Load more until the one for
1954 pos->overlay_string_index is in IT->overlay_strings. */
1955 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1957 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1958 it
->current
.overlay_string_index
= 0;
1961 load_overlay_strings (it
, 0);
1962 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1966 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1967 relative_index
= (it
->current
.overlay_string_index
1968 % OVERLAY_STRING_CHUNK_SIZE
);
1969 it
->string
= it
->overlay_strings
[relative_index
];
1970 xassert (STRINGP (it
->string
));
1971 it
->current
.string_pos
= pos
->string_pos
;
1972 it
->method
= next_element_from_string
;
1975 #if 0 /* This is bogus because POS not having an overlay string
1976 position does not mean it's after the string. Example: A
1977 line starting with a before-string and initialization of IT
1978 to the previous row's end position. */
1979 else if (it
->current
.overlay_string_index
>= 0)
1981 /* If POS says we're already after an overlay string ending at
1982 POS, make sure to pop the iterator because it will be in
1983 front of that overlay string. When POS is ZV, we've thereby
1984 also ``processed'' overlay strings at ZV. */
1987 it
->current
.overlay_string_index
= -1;
1988 it
->method
= next_element_from_buffer
;
1989 if (CHARPOS (pos
->pos
) == ZV
)
1990 it
->overlay_strings_at_end_processed_p
= 1;
1994 if (CHARPOS (pos
->string_pos
) >= 0)
1996 /* Recorded position is not in an overlay string, but in another
1997 string. This can only be a string from a `display' property.
1998 IT should already be filled with that string. */
1999 it
->current
.string_pos
= pos
->string_pos
;
2000 xassert (STRINGP (it
->string
));
2003 /* Restore position in display vector translations, control
2004 character translations or ellipses. */
2005 if (pos
->dpvec_index
>= 0)
2007 if (it
->dpvec
== NULL
)
2008 get_next_display_element (it
);
2009 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2010 it
->current
.dpvec_index
= pos
->dpvec_index
;
2014 return !overlay_strings_with_newlines
;
2018 /* Initialize IT for stepping through current_buffer in window W
2019 starting at ROW->start. */
2022 init_to_row_start (it
, w
, row
)
2025 struct glyph_row
*row
;
2027 init_from_display_pos (it
, w
, &row
->start
);
2028 it
->continuation_lines_width
= row
->continuation_lines_width
;
2033 /* Initialize IT for stepping through current_buffer in window W
2034 starting in the line following ROW, i.e. starting at ROW->end.
2035 Value is zero if there are overlay strings with newlines at ROW's
2039 init_to_row_end (it
, w
, row
)
2042 struct glyph_row
*row
;
2046 if (init_from_display_pos (it
, w
, &row
->end
))
2048 if (row
->continued_p
)
2049 it
->continuation_lines_width
2050 = row
->continuation_lines_width
+ row
->pixel_width
;
2061 /***********************************************************************
2063 ***********************************************************************/
2065 /* Called when IT reaches IT->stop_charpos. Handle text property and
2066 overlay changes. Set IT->stop_charpos to the next position where
2073 enum prop_handled handled
;
2074 int handle_overlay_change_p
= 1;
2078 it
->current
.dpvec_index
= -1;
2082 handled
= HANDLED_NORMALLY
;
2084 /* Call text property handlers. */
2085 for (p
= it_props
; p
->handler
; ++p
)
2087 handled
= p
->handler (it
);
2089 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2091 else if (handled
== HANDLED_RETURN
)
2093 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2094 handle_overlay_change_p
= 0;
2097 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2099 /* Don't check for overlay strings below when set to deliver
2100 characters from a display vector. */
2101 if (it
->method
== next_element_from_display_vector
)
2102 handle_overlay_change_p
= 0;
2104 /* Handle overlay changes. */
2105 if (handle_overlay_change_p
)
2106 handled
= handle_overlay_change (it
);
2108 /* Determine where to stop next. */
2109 if (handled
== HANDLED_NORMALLY
)
2110 compute_stop_pos (it
);
2113 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2117 /* Compute IT->stop_charpos from text property and overlay change
2118 information for IT's current position. */
2121 compute_stop_pos (it
)
2124 register INTERVAL iv
, next_iv
;
2125 Lisp_Object object
, limit
, position
;
2127 /* If nowhere else, stop at the end. */
2128 it
->stop_charpos
= it
->end_charpos
;
2130 if (STRINGP (it
->string
))
2132 /* Strings are usually short, so don't limit the search for
2134 object
= it
->string
;
2136 position
= make_number (IT_STRING_CHARPOS (*it
));
2142 /* If next overlay change is in front of the current stop pos
2143 (which is IT->end_charpos), stop there. Note: value of
2144 next_overlay_change is point-max if no overlay change
2146 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2147 if (charpos
< it
->stop_charpos
)
2148 it
->stop_charpos
= charpos
;
2150 /* If showing the region, we have to stop at the region
2151 start or end because the face might change there. */
2152 if (it
->region_beg_charpos
> 0)
2154 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2155 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2156 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2157 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2160 /* Set up variables for computing the stop position from text
2161 property changes. */
2162 XSETBUFFER (object
, current_buffer
);
2163 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2164 position
= make_number (IT_CHARPOS (*it
));
2168 /* Get the interval containing IT's position. Value is a null
2169 interval if there isn't such an interval. */
2170 iv
= validate_interval_range (object
, &position
, &position
, 0);
2171 if (!NULL_INTERVAL_P (iv
))
2173 Lisp_Object values_here
[LAST_PROP_IDX
];
2176 /* Get properties here. */
2177 for (p
= it_props
; p
->handler
; ++p
)
2178 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2180 /* Look for an interval following iv that has different
2182 for (next_iv
= next_interval (iv
);
2183 (!NULL_INTERVAL_P (next_iv
)
2185 || XFASTINT (limit
) > next_iv
->position
));
2186 next_iv
= next_interval (next_iv
))
2188 for (p
= it_props
; p
->handler
; ++p
)
2190 Lisp_Object new_value
;
2192 new_value
= textget (next_iv
->plist
, *p
->name
);
2193 if (!EQ (values_here
[p
->idx
], new_value
))
2201 if (!NULL_INTERVAL_P (next_iv
))
2203 if (INTEGERP (limit
)
2204 && next_iv
->position
>= XFASTINT (limit
))
2205 /* No text property change up to limit. */
2206 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2208 /* Text properties change in next_iv. */
2209 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2213 xassert (STRINGP (it
->string
)
2214 || (it
->stop_charpos
>= BEGV
2215 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2219 /* Return the position of the next overlay change after POS in
2220 current_buffer. Value is point-max if no overlay change
2221 follows. This is like `next-overlay-change' but doesn't use
2225 next_overlay_change (pos
)
2230 Lisp_Object
*overlays
;
2234 /* Get all overlays at the given position. */
2236 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2237 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2238 if (noverlays
> len
)
2241 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2242 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2245 /* If any of these overlays ends before endpos,
2246 use its ending point instead. */
2247 for (i
= 0; i
< noverlays
; ++i
)
2252 oend
= OVERLAY_END (overlays
[i
]);
2253 oendpos
= OVERLAY_POSITION (oend
);
2254 endpos
= min (endpos
, oendpos
);
2262 /***********************************************************************
2264 ***********************************************************************/
2266 /* Handle changes in the `fontified' property of the current buffer by
2267 calling hook functions from Qfontification_functions to fontify
2270 static enum prop_handled
2271 handle_fontified_prop (it
)
2274 Lisp_Object prop
, pos
;
2275 enum prop_handled handled
= HANDLED_NORMALLY
;
2277 /* Get the value of the `fontified' property at IT's current buffer
2278 position. (The `fontified' property doesn't have a special
2279 meaning in strings.) If the value is nil, call functions from
2280 Qfontification_functions. */
2281 if (!STRINGP (it
->string
)
2283 && !NILP (Vfontification_functions
)
2284 && !NILP (Vrun_hooks
)
2285 && (pos
= make_number (IT_CHARPOS (*it
)),
2286 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2289 int count
= SPECPDL_INDEX ();
2292 val
= Vfontification_functions
;
2293 specbind (Qfontification_functions
, Qnil
);
2295 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2296 safe_call1 (val
, pos
);
2299 Lisp_Object globals
, fn
;
2300 struct gcpro gcpro1
, gcpro2
;
2303 GCPRO2 (val
, globals
);
2305 for (; CONSP (val
); val
= XCDR (val
))
2311 /* A value of t indicates this hook has a local
2312 binding; it means to run the global binding too.
2313 In a global value, t should not occur. If it
2314 does, we must ignore it to avoid an endless
2316 for (globals
= Fdefault_value (Qfontification_functions
);
2318 globals
= XCDR (globals
))
2320 fn
= XCAR (globals
);
2322 safe_call1 (fn
, pos
);
2326 safe_call1 (fn
, pos
);
2332 unbind_to (count
, Qnil
);
2334 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2335 something. This avoids an endless loop if they failed to
2336 fontify the text for which reason ever. */
2337 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2338 handled
= HANDLED_RECOMPUTE_PROPS
;
2346 /***********************************************************************
2348 ***********************************************************************/
2350 /* Set up iterator IT from face properties at its current position.
2351 Called from handle_stop. */
2353 static enum prop_handled
2354 handle_face_prop (it
)
2357 int new_face_id
, next_stop
;
2359 if (!STRINGP (it
->string
))
2362 = face_at_buffer_position (it
->w
,
2364 it
->region_beg_charpos
,
2365 it
->region_end_charpos
,
2368 + TEXT_PROP_DISTANCE_LIMIT
),
2371 /* Is this a start of a run of characters with box face?
2372 Caveat: this can be called for a freshly initialized
2373 iterator; face_id is -1 in this case. We know that the new
2374 face will not change until limit, i.e. if the new face has a
2375 box, all characters up to limit will have one. But, as
2376 usual, we don't know whether limit is really the end. */
2377 if (new_face_id
!= it
->face_id
)
2379 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2381 /* If new face has a box but old face has not, this is
2382 the start of a run of characters with box, i.e. it has
2383 a shadow on the left side. The value of face_id of the
2384 iterator will be -1 if this is the initial call that gets
2385 the face. In this case, we have to look in front of IT's
2386 position and see whether there is a face != new_face_id. */
2387 it
->start_of_box_run_p
2388 = (new_face
->box
!= FACE_NO_BOX
2389 && (it
->face_id
>= 0
2390 || IT_CHARPOS (*it
) == BEG
2391 || new_face_id
!= face_before_it_pos (it
)));
2392 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2397 int base_face_id
, bufpos
;
2399 if (it
->current
.overlay_string_index
>= 0)
2400 bufpos
= IT_CHARPOS (*it
);
2404 /* For strings from a buffer, i.e. overlay strings or strings
2405 from a `display' property, use the face at IT's current
2406 buffer position as the base face to merge with, so that
2407 overlay strings appear in the same face as surrounding
2408 text, unless they specify their own faces. */
2409 base_face_id
= underlying_face_id (it
);
2411 new_face_id
= face_at_string_position (it
->w
,
2413 IT_STRING_CHARPOS (*it
),
2415 it
->region_beg_charpos
,
2416 it
->region_end_charpos
,
2420 #if 0 /* This shouldn't be neccessary. Let's check it. */
2421 /* If IT is used to display a mode line we would really like to
2422 use the mode line face instead of the frame's default face. */
2423 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2424 && new_face_id
== DEFAULT_FACE_ID
)
2425 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2428 /* Is this a start of a run of characters with box? Caveat:
2429 this can be called for a freshly allocated iterator; face_id
2430 is -1 is this case. We know that the new face will not
2431 change until the next check pos, i.e. if the new face has a
2432 box, all characters up to that position will have a
2433 box. But, as usual, we don't know whether that position
2434 is really the end. */
2435 if (new_face_id
!= it
->face_id
)
2437 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2438 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2440 /* If new face has a box but old face hasn't, this is the
2441 start of a run of characters with box, i.e. it has a
2442 shadow on the left side. */
2443 it
->start_of_box_run_p
2444 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2445 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2449 it
->face_id
= new_face_id
;
2450 return HANDLED_NORMALLY
;
2454 /* Return the ID of the face ``underlying'' IT's current position,
2455 which is in a string. If the iterator is associated with a
2456 buffer, return the face at IT's current buffer position.
2457 Otherwise, use the iterator's base_face_id. */
2460 underlying_face_id (it
)
2463 int face_id
= it
->base_face_id
, i
;
2465 xassert (STRINGP (it
->string
));
2467 for (i
= it
->sp
- 1; i
>= 0; --i
)
2468 if (NILP (it
->stack
[i
].string
))
2469 face_id
= it
->stack
[i
].face_id
;
2475 /* Compute the face one character before or after the current position
2476 of IT. BEFORE_P non-zero means get the face in front of IT's
2477 position. Value is the id of the face. */
2480 face_before_or_after_it_pos (it
, before_p
)
2485 int next_check_charpos
;
2486 struct text_pos pos
;
2488 xassert (it
->s
== NULL
);
2490 if (STRINGP (it
->string
))
2492 int bufpos
, base_face_id
;
2494 /* No face change past the end of the string (for the case
2495 we are padding with spaces). No face change before the
2497 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2498 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2501 /* Set pos to the position before or after IT's current position. */
2503 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2505 /* For composition, we must check the character after the
2507 pos
= (it
->what
== IT_COMPOSITION
2508 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2509 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2511 if (it
->current
.overlay_string_index
>= 0)
2512 bufpos
= IT_CHARPOS (*it
);
2516 base_face_id
= underlying_face_id (it
);
2518 /* Get the face for ASCII, or unibyte. */
2519 face_id
= face_at_string_position (it
->w
,
2523 it
->region_beg_charpos
,
2524 it
->region_end_charpos
,
2525 &next_check_charpos
,
2528 /* Correct the face for charsets different from ASCII. Do it
2529 for the multibyte case only. The face returned above is
2530 suitable for unibyte text if IT->string is unibyte. */
2531 if (STRING_MULTIBYTE (it
->string
))
2533 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2534 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2536 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2538 c
= string_char_and_length (p
, rest
, &len
);
2539 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2544 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2545 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2548 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2549 pos
= it
->current
.pos
;
2552 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2555 if (it
->what
== IT_COMPOSITION
)
2556 /* For composition, we must check the position after the
2558 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2560 INC_TEXT_POS (pos
, it
->multibyte_p
);
2563 /* Determine face for CHARSET_ASCII, or unibyte. */
2564 face_id
= face_at_buffer_position (it
->w
,
2566 it
->region_beg_charpos
,
2567 it
->region_end_charpos
,
2568 &next_check_charpos
,
2571 /* Correct the face for charsets different from ASCII. Do it
2572 for the multibyte case only. The face returned above is
2573 suitable for unibyte text if current_buffer is unibyte. */
2574 if (it
->multibyte_p
)
2576 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
2577 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2578 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2587 /***********************************************************************
2589 ***********************************************************************/
2591 /* Set up iterator IT from invisible properties at its current
2592 position. Called from handle_stop. */
2594 static enum prop_handled
2595 handle_invisible_prop (it
)
2598 enum prop_handled handled
= HANDLED_NORMALLY
;
2600 if (STRINGP (it
->string
))
2602 extern Lisp_Object Qinvisible
;
2603 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2605 /* Get the value of the invisible text property at the
2606 current position. Value will be nil if there is no such
2608 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2609 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2612 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2614 handled
= HANDLED_RECOMPUTE_PROPS
;
2616 /* Get the position at which the next change of the
2617 invisible text property can be found in IT->string.
2618 Value will be nil if the property value is the same for
2619 all the rest of IT->string. */
2620 XSETINT (limit
, SCHARS (it
->string
));
2621 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2624 /* Text at current position is invisible. The next
2625 change in the property is at position end_charpos.
2626 Move IT's current position to that position. */
2627 if (INTEGERP (end_charpos
)
2628 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2630 struct text_pos old
;
2631 old
= it
->current
.string_pos
;
2632 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2633 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2637 /* The rest of the string is invisible. If this is an
2638 overlay string, proceed with the next overlay string
2639 or whatever comes and return a character from there. */
2640 if (it
->current
.overlay_string_index
>= 0)
2642 next_overlay_string (it
);
2643 /* Don't check for overlay strings when we just
2644 finished processing them. */
2645 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2649 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
2650 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
2657 int invis_p
, newpos
, next_stop
, start_charpos
;
2658 Lisp_Object pos
, prop
, overlay
;
2660 /* First of all, is there invisible text at this position? */
2661 start_charpos
= IT_CHARPOS (*it
);
2662 pos
= make_number (IT_CHARPOS (*it
));
2663 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2665 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2667 /* If we are on invisible text, skip over it. */
2668 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2670 /* Record whether we have to display an ellipsis for the
2672 int display_ellipsis_p
= invis_p
== 2;
2674 handled
= HANDLED_RECOMPUTE_PROPS
;
2676 /* Loop skipping over invisible text. The loop is left at
2677 ZV or with IT on the first char being visible again. */
2680 /* Try to skip some invisible text. Return value is the
2681 position reached which can be equal to IT's position
2682 if there is nothing invisible here. This skips both
2683 over invisible text properties and overlays with
2684 invisible property. */
2685 newpos
= skip_invisible (IT_CHARPOS (*it
),
2686 &next_stop
, ZV
, it
->window
);
2688 /* If we skipped nothing at all we weren't at invisible
2689 text in the first place. If everything to the end of
2690 the buffer was skipped, end the loop. */
2691 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2695 /* We skipped some characters but not necessarily
2696 all there are. Check if we ended up on visible
2697 text. Fget_char_property returns the property of
2698 the char before the given position, i.e. if we
2699 get invis_p = 0, this means that the char at
2700 newpos is visible. */
2701 pos
= make_number (newpos
);
2702 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2703 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2706 /* If we ended up on invisible text, proceed to
2707 skip starting with next_stop. */
2709 IT_CHARPOS (*it
) = next_stop
;
2713 /* The position newpos is now either ZV or on visible text. */
2714 IT_CHARPOS (*it
) = newpos
;
2715 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2717 /* If there are before-strings at the start of invisible
2718 text, and the text is invisible because of a text
2719 property, arrange to show before-strings because 20.x did
2720 it that way. (If the text is invisible because of an
2721 overlay property instead of a text property, this is
2722 already handled in the overlay code.) */
2724 && get_overlay_strings (it
, start_charpos
))
2726 handled
= HANDLED_RECOMPUTE_PROPS
;
2727 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2729 else if (display_ellipsis_p
)
2730 setup_for_ellipsis (it
);
2738 /* Make iterator IT return `...' next. */
2741 setup_for_ellipsis (it
)
2745 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2747 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2748 it
->dpvec
= v
->contents
;
2749 it
->dpend
= v
->contents
+ v
->size
;
2753 /* Default `...'. */
2754 it
->dpvec
= default_invis_vector
;
2755 it
->dpend
= default_invis_vector
+ 3;
2758 /* The ellipsis display does not replace the display of the
2759 character at the new position. Indicate this by setting
2760 IT->dpvec_char_len to zero. */
2761 it
->dpvec_char_len
= 0;
2763 it
->current
.dpvec_index
= 0;
2764 it
->method
= next_element_from_display_vector
;
2769 /***********************************************************************
2771 ***********************************************************************/
2773 /* Set up iterator IT from `display' property at its current position.
2774 Called from handle_stop. */
2776 static enum prop_handled
2777 handle_display_prop (it
)
2780 Lisp_Object prop
, object
;
2781 struct text_pos
*position
;
2782 int display_replaced_p
= 0;
2784 if (STRINGP (it
->string
))
2786 object
= it
->string
;
2787 position
= &it
->current
.string_pos
;
2791 object
= it
->w
->buffer
;
2792 position
= &it
->current
.pos
;
2795 /* Reset those iterator values set from display property values. */
2796 it
->font_height
= Qnil
;
2797 it
->space_width
= Qnil
;
2800 /* We don't support recursive `display' properties, i.e. string
2801 values that have a string `display' property, that have a string
2802 `display' property etc. */
2803 if (!it
->string_from_display_prop_p
)
2804 it
->area
= TEXT_AREA
;
2806 prop
= Fget_char_property (make_number (position
->charpos
),
2809 return HANDLED_NORMALLY
;
2812 /* Simple properties. */
2813 && !EQ (XCAR (prop
), Qimage
)
2814 && !EQ (XCAR (prop
), Qspace
)
2815 && !EQ (XCAR (prop
), Qwhen
)
2816 && !EQ (XCAR (prop
), Qspace_width
)
2817 && !EQ (XCAR (prop
), Qheight
)
2818 && !EQ (XCAR (prop
), Qraise
)
2819 /* Marginal area specifications. */
2820 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2821 && !NILP (XCAR (prop
)))
2823 for (; CONSP (prop
); prop
= XCDR (prop
))
2825 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2826 position
, display_replaced_p
))
2827 display_replaced_p
= 1;
2830 else if (VECTORP (prop
))
2833 for (i
= 0; i
< ASIZE (prop
); ++i
)
2834 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2835 position
, display_replaced_p
))
2836 display_replaced_p
= 1;
2840 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2841 display_replaced_p
= 1;
2844 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2848 /* Value is the position of the end of the `display' property starting
2849 at START_POS in OBJECT. */
2851 static struct text_pos
2852 display_prop_end (it
, object
, start_pos
)
2855 struct text_pos start_pos
;
2858 struct text_pos end_pos
;
2860 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2861 Qdisplay
, object
, Qnil
);
2862 CHARPOS (end_pos
) = XFASTINT (end
);
2863 if (STRINGP (object
))
2864 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2866 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2872 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2873 is the object in which the `display' property was found. *POSITION
2874 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2875 means that we previously saw a display sub-property which already
2876 replaced text display with something else, for example an image;
2877 ignore such properties after the first one has been processed.
2879 If PROP is a `space' or `image' sub-property, set *POSITION to the
2880 end position of the `display' property.
2882 Value is non-zero if something was found which replaces the display
2883 of buffer or string text. */
2886 handle_single_display_prop (it
, prop
, object
, position
,
2887 display_replaced_before_p
)
2891 struct text_pos
*position
;
2892 int display_replaced_before_p
;
2895 int replaces_text_display_p
= 0;
2898 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2899 evaluated. If the result is nil, VALUE is ignored. */
2901 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2910 if (!NILP (form
) && !EQ (form
, Qt
))
2912 int count
= SPECPDL_INDEX ();
2913 struct gcpro gcpro1
;
2915 /* Bind `object' to the object having the `display' property, a
2916 buffer or string. Bind `position' to the position in the
2917 object where the property was found, and `buffer-position'
2918 to the current position in the buffer. */
2919 specbind (Qobject
, object
);
2920 specbind (Qposition
, make_number (CHARPOS (*position
)));
2921 specbind (Qbuffer_position
,
2922 make_number (STRINGP (object
)
2923 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2925 form
= safe_eval (form
);
2927 unbind_to (count
, Qnil
);
2934 && EQ (XCAR (prop
), Qheight
)
2935 && CONSP (XCDR (prop
)))
2937 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2940 /* `(height HEIGHT)'. */
2941 it
->font_height
= XCAR (XCDR (prop
));
2942 if (!NILP (it
->font_height
))
2944 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2945 int new_height
= -1;
2947 if (CONSP (it
->font_height
)
2948 && (EQ (XCAR (it
->font_height
), Qplus
)
2949 || EQ (XCAR (it
->font_height
), Qminus
))
2950 && CONSP (XCDR (it
->font_height
))
2951 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2953 /* `(+ N)' or `(- N)' where N is an integer. */
2954 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2955 if (EQ (XCAR (it
->font_height
), Qplus
))
2957 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2959 else if (FUNCTIONP (it
->font_height
))
2961 /* Call function with current height as argument.
2962 Value is the new height. */
2964 height
= safe_call1 (it
->font_height
,
2965 face
->lface
[LFACE_HEIGHT_INDEX
]);
2966 if (NUMBERP (height
))
2967 new_height
= XFLOATINT (height
);
2969 else if (NUMBERP (it
->font_height
))
2971 /* Value is a multiple of the canonical char height. */
2974 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2975 new_height
= (XFLOATINT (it
->font_height
)
2976 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2980 /* Evaluate IT->font_height with `height' bound to the
2981 current specified height to get the new height. */
2983 int count
= SPECPDL_INDEX ();
2985 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2986 value
= safe_eval (it
->font_height
);
2987 unbind_to (count
, Qnil
);
2989 if (NUMBERP (value
))
2990 new_height
= XFLOATINT (value
);
2994 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2997 else if (CONSP (prop
)
2998 && EQ (XCAR (prop
), Qspace_width
)
2999 && CONSP (XCDR (prop
)))
3001 /* `(space_width WIDTH)'. */
3002 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3005 value
= XCAR (XCDR (prop
));
3006 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3007 it
->space_width
= value
;
3009 else if (CONSP (prop
)
3010 && EQ (XCAR (prop
), Qraise
)
3011 && CONSP (XCDR (prop
)))
3013 /* `(raise FACTOR)'. */
3014 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3017 #ifdef HAVE_WINDOW_SYSTEM
3018 value
= XCAR (XCDR (prop
));
3019 if (NUMBERP (value
))
3021 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3022 it
->voffset
= - (XFLOATINT (value
)
3023 * (FONT_HEIGHT (face
->font
)));
3025 #endif /* HAVE_WINDOW_SYSTEM */
3027 else if (!it
->string_from_display_prop_p
)
3029 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3030 VALUE) or `((margin nil) VALUE)' or VALUE. */
3031 Lisp_Object location
, value
;
3032 struct text_pos start_pos
;
3035 /* Characters having this form of property are not displayed, so
3036 we have to find the end of the property. */
3037 start_pos
= *position
;
3038 *position
= display_prop_end (it
, object
, start_pos
);
3041 /* Let's stop at the new position and assume that all
3042 text properties change there. */
3043 it
->stop_charpos
= position
->charpos
;
3045 location
= Qunbound
;
3046 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3050 value
= XCDR (prop
);
3052 value
= XCAR (value
);
3055 if (EQ (XCAR (tem
), Qmargin
)
3056 && (tem
= XCDR (tem
),
3057 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3059 || EQ (tem
, Qleft_margin
)
3060 || EQ (tem
, Qright_margin
))))
3064 if (EQ (location
, Qunbound
))
3070 #ifdef HAVE_WINDOW_SYSTEM
3071 if (FRAME_TERMCAP_P (it
->f
))
3072 valid_p
= STRINGP (value
);
3074 valid_p
= (STRINGP (value
)
3075 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3076 || valid_image_p (value
));
3077 #else /* not HAVE_WINDOW_SYSTEM */
3078 valid_p
= STRINGP (value
);
3079 #endif /* not HAVE_WINDOW_SYSTEM */
3081 if ((EQ (location
, Qleft_margin
)
3082 || EQ (location
, Qright_margin
)
3085 && !display_replaced_before_p
)
3087 replaces_text_display_p
= 1;
3089 /* Save current settings of IT so that we can restore them
3090 when we are finished with the glyph property value. */
3093 if (NILP (location
))
3094 it
->area
= TEXT_AREA
;
3095 else if (EQ (location
, Qleft_margin
))
3096 it
->area
= LEFT_MARGIN_AREA
;
3098 it
->area
= RIGHT_MARGIN_AREA
;
3100 if (STRINGP (value
))
3103 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3104 it
->current
.overlay_string_index
= -1;
3105 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3106 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3107 it
->method
= next_element_from_string
;
3108 it
->stop_charpos
= 0;
3109 it
->string_from_display_prop_p
= 1;
3110 /* Say that we haven't consumed the characters with
3111 `display' property yet. The call to pop_it in
3112 set_iterator_to_next will clean this up. */
3113 *position
= start_pos
;
3115 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3117 it
->method
= next_element_from_stretch
;
3119 it
->current
.pos
= it
->position
= start_pos
;
3121 #ifdef HAVE_WINDOW_SYSTEM
3124 it
->what
= IT_IMAGE
;
3125 it
->image_id
= lookup_image (it
->f
, value
);
3126 it
->position
= start_pos
;
3127 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3128 it
->method
= next_element_from_image
;
3130 /* Say that we haven't consumed the characters with
3131 `display' property yet. The call to pop_it in
3132 set_iterator_to_next will clean this up. */
3133 *position
= start_pos
;
3135 #endif /* HAVE_WINDOW_SYSTEM */
3138 /* Invalid property or property not supported. Restore
3139 the position to what it was before. */
3140 *position
= start_pos
;
3143 return replaces_text_display_p
;
3147 /* Check if PROP is a display sub-property value whose text should be
3148 treated as intangible. */
3151 single_display_prop_intangible_p (prop
)
3154 /* Skip over `when FORM'. */
3155 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3169 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3170 we don't need to treat text as intangible. */
3171 if (EQ (XCAR (prop
), Qmargin
))
3179 || EQ (XCAR (prop
), Qleft_margin
)
3180 || EQ (XCAR (prop
), Qright_margin
))
3184 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3188 /* Check if PROP is a display property value whose text should be
3189 treated as intangible. */
3192 display_prop_intangible_p (prop
)
3196 && CONSP (XCAR (prop
))
3197 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3199 /* A list of sub-properties. */
3200 while (CONSP (prop
))
3202 if (single_display_prop_intangible_p (XCAR (prop
)))
3207 else if (VECTORP (prop
))
3209 /* A vector of sub-properties. */
3211 for (i
= 0; i
< ASIZE (prop
); ++i
)
3212 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3216 return single_display_prop_intangible_p (prop
);
3222 /* Return 1 if PROP is a display sub-property value containing STRING. */
3225 single_display_prop_string_p (prop
, string
)
3226 Lisp_Object prop
, string
;
3228 if (EQ (string
, prop
))
3231 /* Skip over `when FORM'. */
3232 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3241 /* Skip over `margin LOCATION'. */
3242 if (EQ (XCAR (prop
), Qmargin
))
3253 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3257 /* Return 1 if STRING appears in the `display' property PROP. */
3260 display_prop_string_p (prop
, string
)
3261 Lisp_Object prop
, string
;
3264 && CONSP (XCAR (prop
))
3265 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3267 /* A list of sub-properties. */
3268 while (CONSP (prop
))
3270 if (single_display_prop_string_p (XCAR (prop
), string
))
3275 else if (VECTORP (prop
))
3277 /* A vector of sub-properties. */
3279 for (i
= 0; i
< ASIZE (prop
); ++i
)
3280 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3284 return single_display_prop_string_p (prop
, string
);
3290 /* Determine from which buffer position in W's buffer STRING comes
3291 from. AROUND_CHARPOS is an approximate position where it could
3292 be from. Value is the buffer position or 0 if it couldn't be
3295 W's buffer must be current.
3297 This function is necessary because we don't record buffer positions
3298 in glyphs generated from strings (to keep struct glyph small).
3299 This function may only use code that doesn't eval because it is
3300 called asynchronously from note_mouse_highlight. */
3303 string_buffer_position (w
, string
, around_charpos
)
3308 Lisp_Object limit
, prop
, pos
;
3309 const int MAX_DISTANCE
= 1000;
3312 pos
= make_number (around_charpos
);
3313 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3314 while (!found
&& !EQ (pos
, limit
))
3316 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3317 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3320 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3325 pos
= make_number (around_charpos
);
3326 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3327 while (!found
&& !EQ (pos
, limit
))
3329 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3330 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3333 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3338 return found
? XINT (pos
) : 0;
3343 /***********************************************************************
3344 `composition' property
3345 ***********************************************************************/
3347 /* Set up iterator IT from `composition' property at its current
3348 position. Called from handle_stop. */
3350 static enum prop_handled
3351 handle_composition_prop (it
)
3354 Lisp_Object prop
, string
;
3355 int pos
, pos_byte
, end
;
3356 enum prop_handled handled
= HANDLED_NORMALLY
;
3358 if (STRINGP (it
->string
))
3360 pos
= IT_STRING_CHARPOS (*it
);
3361 pos_byte
= IT_STRING_BYTEPOS (*it
);
3362 string
= it
->string
;
3366 pos
= IT_CHARPOS (*it
);
3367 pos_byte
= IT_BYTEPOS (*it
);
3371 /* If there's a valid composition and point is not inside of the
3372 composition (in the case that the composition is from the current
3373 buffer), draw a glyph composed from the composition components. */
3374 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3375 && COMPOSITION_VALID_P (pos
, end
, prop
)
3376 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3378 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3382 it
->method
= next_element_from_composition
;
3384 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3385 /* For a terminal, draw only the first character of the
3387 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3388 it
->len
= (STRINGP (it
->string
)
3389 ? string_char_to_byte (it
->string
, end
)
3390 : CHAR_TO_BYTE (end
)) - pos_byte
;
3391 it
->stop_charpos
= end
;
3392 handled
= HANDLED_RETURN
;
3401 /***********************************************************************
3403 ***********************************************************************/
3405 /* The following structure is used to record overlay strings for
3406 later sorting in load_overlay_strings. */
3408 struct overlay_entry
3410 Lisp_Object overlay
;
3417 /* Set up iterator IT from overlay strings at its current position.
3418 Called from handle_stop. */
3420 static enum prop_handled
3421 handle_overlay_change (it
)
3424 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3425 return HANDLED_RECOMPUTE_PROPS
;
3427 return HANDLED_NORMALLY
;
3431 /* Set up the next overlay string for delivery by IT, if there is an
3432 overlay string to deliver. Called by set_iterator_to_next when the
3433 end of the current overlay string is reached. If there are more
3434 overlay strings to display, IT->string and
3435 IT->current.overlay_string_index are set appropriately here.
3436 Otherwise IT->string is set to nil. */
3439 next_overlay_string (it
)
3442 ++it
->current
.overlay_string_index
;
3443 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3445 /* No more overlay strings. Restore IT's settings to what
3446 they were before overlay strings were processed, and
3447 continue to deliver from current_buffer. */
3448 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3451 xassert (it
->stop_charpos
>= BEGV
3452 && it
->stop_charpos
<= it
->end_charpos
);
3454 it
->current
.overlay_string_index
= -1;
3455 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3456 it
->n_overlay_strings
= 0;
3457 it
->method
= next_element_from_buffer
;
3459 /* If we're at the end of the buffer, record that we have
3460 processed the overlay strings there already, so that
3461 next_element_from_buffer doesn't try it again. */
3462 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3463 it
->overlay_strings_at_end_processed_p
= 1;
3465 /* If we have to display `...' for invisible text, set
3466 the iterator up for that. */
3467 if (display_ellipsis_p
)
3468 setup_for_ellipsis (it
);
3472 /* There are more overlay strings to process. If
3473 IT->current.overlay_string_index has advanced to a position
3474 where we must load IT->overlay_strings with more strings, do
3476 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3478 if (it
->current
.overlay_string_index
&& i
== 0)
3479 load_overlay_strings (it
, 0);
3481 /* Initialize IT to deliver display elements from the overlay
3483 it
->string
= it
->overlay_strings
[i
];
3484 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3485 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3486 it
->method
= next_element_from_string
;
3487 it
->stop_charpos
= 0;
3494 /* Compare two overlay_entry structures E1 and E2. Used as a
3495 comparison function for qsort in load_overlay_strings. Overlay
3496 strings for the same position are sorted so that
3498 1. All after-strings come in front of before-strings, except
3499 when they come from the same overlay.
3501 2. Within after-strings, strings are sorted so that overlay strings
3502 from overlays with higher priorities come first.
3504 2. Within before-strings, strings are sorted so that overlay
3505 strings from overlays with higher priorities come last.
3507 Value is analogous to strcmp. */
3511 compare_overlay_entries (e1
, e2
)
3514 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3515 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3518 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3520 /* Let after-strings appear in front of before-strings if
3521 they come from different overlays. */
3522 if (EQ (entry1
->overlay
, entry2
->overlay
))
3523 result
= entry1
->after_string_p
? 1 : -1;
3525 result
= entry1
->after_string_p
? -1 : 1;
3527 else if (entry1
->after_string_p
)
3528 /* After-strings sorted in order of decreasing priority. */
3529 result
= entry2
->priority
- entry1
->priority
;
3531 /* Before-strings sorted in order of increasing priority. */
3532 result
= entry1
->priority
- entry2
->priority
;
3538 /* Load the vector IT->overlay_strings with overlay strings from IT's
3539 current buffer position, or from CHARPOS if that is > 0. Set
3540 IT->n_overlays to the total number of overlay strings found.
3542 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3543 a time. On entry into load_overlay_strings,
3544 IT->current.overlay_string_index gives the number of overlay
3545 strings that have already been loaded by previous calls to this
3548 IT->add_overlay_start contains an additional overlay start
3549 position to consider for taking overlay strings from, if non-zero.
3550 This position comes into play when the overlay has an `invisible'
3551 property, and both before and after-strings. When we've skipped to
3552 the end of the overlay, because of its `invisible' property, we
3553 nevertheless want its before-string to appear.
3554 IT->add_overlay_start will contain the overlay start position
3557 Overlay strings are sorted so that after-string strings come in
3558 front of before-string strings. Within before and after-strings,
3559 strings are sorted by overlay priority. See also function
3560 compare_overlay_entries. */
3563 load_overlay_strings (it
, charpos
)
3567 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3568 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3571 int n
= 0, i
, j
, invis_p
;
3572 struct overlay_entry
*entries
3573 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3576 charpos
= IT_CHARPOS (*it
);
3578 /* Append the overlay string STRING of overlay OVERLAY to vector
3579 `entries' which has size `size' and currently contains `n'
3580 elements. AFTER_P non-zero means STRING is an after-string of
3582 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3585 Lisp_Object priority; \
3589 int new_size = 2 * size; \
3590 struct overlay_entry *old = entries; \
3592 (struct overlay_entry *) alloca (new_size \
3593 * sizeof *entries); \
3594 bcopy (old, entries, size * sizeof *entries); \
3598 entries[n].string = (STRING); \
3599 entries[n].overlay = (OVERLAY); \
3600 priority = Foverlay_get ((OVERLAY), Qpriority); \
3601 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3602 entries[n].after_string_p = (AFTER_P); \
3607 /* Process overlay before the overlay center. */
3608 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3610 overlay
= XCAR (ov
);
3611 xassert (OVERLAYP (overlay
));
3612 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3613 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3618 /* Skip this overlay if it doesn't start or end at IT's current
3620 if (end
!= charpos
&& start
!= charpos
)
3623 /* Skip this overlay if it doesn't apply to IT->w. */
3624 window
= Foverlay_get (overlay
, Qwindow
);
3625 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3628 /* If the text ``under'' the overlay is invisible, both before-
3629 and after-strings from this overlay are visible; start and
3630 end position are indistinguishable. */
3631 invisible
= Foverlay_get (overlay
, Qinvisible
);
3632 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3634 /* If overlay has a non-empty before-string, record it. */
3635 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3636 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3638 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3640 /* If overlay has a non-empty after-string, record it. */
3641 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3642 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3644 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3647 /* Process overlays after the overlay center. */
3648 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3650 overlay
= XCAR (ov
);
3651 xassert (OVERLAYP (overlay
));
3652 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3653 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3655 if (start
> charpos
)
3658 /* Skip this overlay if it doesn't start or end at IT's current
3660 if (end
!= charpos
&& start
!= charpos
)
3663 /* Skip this overlay if it doesn't apply to IT->w. */
3664 window
= Foverlay_get (overlay
, Qwindow
);
3665 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3668 /* If the text ``under'' the overlay is invisible, it has a zero
3669 dimension, and both before- and after-strings apply. */
3670 invisible
= Foverlay_get (overlay
, Qinvisible
);
3671 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3673 /* If overlay has a non-empty before-string, record it. */
3674 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3675 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3677 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3679 /* If overlay has a non-empty after-string, record it. */
3680 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3681 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3683 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3686 #undef RECORD_OVERLAY_STRING
3690 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3692 /* Record the total number of strings to process. */
3693 it
->n_overlay_strings
= n
;
3695 /* IT->current.overlay_string_index is the number of overlay strings
3696 that have already been consumed by IT. Copy some of the
3697 remaining overlay strings to IT->overlay_strings. */
3699 j
= it
->current
.overlay_string_index
;
3700 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3701 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3707 /* Get the first chunk of overlay strings at IT's current buffer
3708 position, or at CHARPOS if that is > 0. Value is non-zero if at
3709 least one overlay string was found. */
3712 get_overlay_strings (it
, charpos
)
3716 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3717 process. This fills IT->overlay_strings with strings, and sets
3718 IT->n_overlay_strings to the total number of strings to process.
3719 IT->pos.overlay_string_index has to be set temporarily to zero
3720 because load_overlay_strings needs this; it must be set to -1
3721 when no overlay strings are found because a zero value would
3722 indicate a position in the first overlay string. */
3723 it
->current
.overlay_string_index
= 0;
3724 load_overlay_strings (it
, charpos
);
3726 /* If we found overlay strings, set up IT to deliver display
3727 elements from the first one. Otherwise set up IT to deliver
3728 from current_buffer. */
3729 if (it
->n_overlay_strings
)
3731 /* Make sure we know settings in current_buffer, so that we can
3732 restore meaningful values when we're done with the overlay
3734 compute_stop_pos (it
);
3735 xassert (it
->face_id
>= 0);
3737 /* Save IT's settings. They are restored after all overlay
3738 strings have been processed. */
3739 xassert (it
->sp
== 0);
3742 /* Set up IT to deliver display elements from the first overlay
3744 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3745 it
->string
= it
->overlay_strings
[0];
3746 it
->stop_charpos
= 0;
3747 xassert (STRINGP (it
->string
));
3748 it
->end_charpos
= SCHARS (it
->string
);
3749 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3750 it
->method
= next_element_from_string
;
3755 it
->current
.overlay_string_index
= -1;
3756 it
->method
= next_element_from_buffer
;
3761 /* Value is non-zero if we found at least one overlay string. */
3762 return STRINGP (it
->string
);
3767 /***********************************************************************
3768 Saving and restoring state
3769 ***********************************************************************/
3771 /* Save current settings of IT on IT->stack. Called, for example,
3772 before setting up IT for an overlay string, to be able to restore
3773 IT's settings to what they were after the overlay string has been
3780 struct iterator_stack_entry
*p
;
3782 xassert (it
->sp
< 2);
3783 p
= it
->stack
+ it
->sp
;
3785 p
->stop_charpos
= it
->stop_charpos
;
3786 xassert (it
->face_id
>= 0);
3787 p
->face_id
= it
->face_id
;
3788 p
->string
= it
->string
;
3789 p
->pos
= it
->current
;
3790 p
->end_charpos
= it
->end_charpos
;
3791 p
->string_nchars
= it
->string_nchars
;
3793 p
->multibyte_p
= it
->multibyte_p
;
3794 p
->space_width
= it
->space_width
;
3795 p
->font_height
= it
->font_height
;
3796 p
->voffset
= it
->voffset
;
3797 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3798 p
->display_ellipsis_p
= 0;
3803 /* Restore IT's settings from IT->stack. Called, for example, when no
3804 more overlay strings must be processed, and we return to delivering
3805 display elements from a buffer, or when the end of a string from a
3806 `display' property is reached and we return to delivering display
3807 elements from an overlay string, or from a buffer. */
3813 struct iterator_stack_entry
*p
;
3815 xassert (it
->sp
> 0);
3817 p
= it
->stack
+ it
->sp
;
3818 it
->stop_charpos
= p
->stop_charpos
;
3819 it
->face_id
= p
->face_id
;
3820 it
->string
= p
->string
;
3821 it
->current
= p
->pos
;
3822 it
->end_charpos
= p
->end_charpos
;
3823 it
->string_nchars
= p
->string_nchars
;
3825 it
->multibyte_p
= p
->multibyte_p
;
3826 it
->space_width
= p
->space_width
;
3827 it
->font_height
= p
->font_height
;
3828 it
->voffset
= p
->voffset
;
3829 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3834 /***********************************************************************
3836 ***********************************************************************/
3838 /* Set IT's current position to the previous line start. */
3841 back_to_previous_line_start (it
)
3844 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3845 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3849 /* Move IT to the next line start.
3851 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3852 we skipped over part of the text (as opposed to moving the iterator
3853 continuously over the text). Otherwise, don't change the value
3856 Newlines may come from buffer text, overlay strings, or strings
3857 displayed via the `display' property. That's the reason we can't
3858 simply use find_next_newline_no_quit.
3860 Note that this function may not skip over invisible text that is so
3861 because of text properties and immediately follows a newline. If
3862 it would, function reseat_at_next_visible_line_start, when called
3863 from set_iterator_to_next, would effectively make invisible
3864 characters following a newline part of the wrong glyph row, which
3865 leads to wrong cursor motion. */
3868 forward_to_next_line_start (it
, skipped_p
)
3872 int old_selective
, newline_found_p
, n
;
3873 const int MAX_NEWLINE_DISTANCE
= 500;
3875 /* If already on a newline, just consume it to avoid unintended
3876 skipping over invisible text below. */
3877 if (it
->what
== IT_CHARACTER
3879 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3881 set_iterator_to_next (it
, 0);
3886 /* Don't handle selective display in the following. It's (a)
3887 unnecessary because it's done by the caller, and (b) leads to an
3888 infinite recursion because next_element_from_ellipsis indirectly
3889 calls this function. */
3890 old_selective
= it
->selective
;
3893 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3894 from buffer text. */
3895 for (n
= newline_found_p
= 0;
3896 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3897 n
+= STRINGP (it
->string
) ? 0 : 1)
3899 if (!get_next_display_element (it
))
3901 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3902 set_iterator_to_next (it
, 0);
3905 /* If we didn't find a newline near enough, see if we can use a
3907 if (!newline_found_p
)
3909 int start
= IT_CHARPOS (*it
);
3910 int limit
= find_next_newline_no_quit (start
, 1);
3913 xassert (!STRINGP (it
->string
));
3915 /* If there isn't any `display' property in sight, and no
3916 overlays, we can just use the position of the newline in
3918 if (it
->stop_charpos
>= limit
3919 || ((pos
= Fnext_single_property_change (make_number (start
),
3921 Qnil
, make_number (limit
)),
3923 && next_overlay_change (start
) == ZV
))
3925 IT_CHARPOS (*it
) = limit
;
3926 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3927 *skipped_p
= newline_found_p
= 1;
3931 while (get_next_display_element (it
)
3932 && !newline_found_p
)
3934 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3935 set_iterator_to_next (it
, 0);
3940 it
->selective
= old_selective
;
3941 return newline_found_p
;
3945 /* Set IT's current position to the previous visible line start. Skip
3946 invisible text that is so either due to text properties or due to
3947 selective display. Caution: this does not change IT->current_x and
3951 back_to_previous_visible_line_start (it
)
3956 /* Go back one newline if not on BEGV already. */
3957 if (IT_CHARPOS (*it
) > BEGV
)
3958 back_to_previous_line_start (it
);
3960 /* Move over lines that are invisible because of selective display
3961 or text properties. */
3962 while (IT_CHARPOS (*it
) > BEGV
3967 /* If selective > 0, then lines indented more than that values
3969 if (it
->selective
> 0
3970 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3971 (double) it
->selective
)) /* iftc */
3977 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3978 Qinvisible
, it
->window
);
3979 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3983 /* Back one more newline if the current one is invisible. */
3985 back_to_previous_line_start (it
);
3988 xassert (IT_CHARPOS (*it
) >= BEGV
);
3989 xassert (IT_CHARPOS (*it
) == BEGV
3990 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3995 /* Reseat iterator IT at the previous visible line start. Skip
3996 invisible text that is so either due to text properties or due to
3997 selective display. At the end, update IT's overlay information,
3998 face information etc. */
4001 reseat_at_previous_visible_line_start (it
)
4004 back_to_previous_visible_line_start (it
);
4005 reseat (it
, it
->current
.pos
, 1);
4010 /* Reseat iterator IT on the next visible line start in the current
4011 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4012 preceding the line start. Skip over invisible text that is so
4013 because of selective display. Compute faces, overlays etc at the
4014 new position. Note that this function does not skip over text that
4015 is invisible because of text properties. */
4018 reseat_at_next_visible_line_start (it
, on_newline_p
)
4022 int newline_found_p
, skipped_p
= 0;
4024 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4026 /* Skip over lines that are invisible because they are indented
4027 more than the value of IT->selective. */
4028 if (it
->selective
> 0)
4029 while (IT_CHARPOS (*it
) < ZV
4030 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4031 (double) it
->selective
)) /* iftc */
4033 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4034 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4037 /* Position on the newline if that's what's requested. */
4038 if (on_newline_p
&& newline_found_p
)
4040 if (STRINGP (it
->string
))
4042 if (IT_STRING_CHARPOS (*it
) > 0)
4044 --IT_STRING_CHARPOS (*it
);
4045 --IT_STRING_BYTEPOS (*it
);
4048 else if (IT_CHARPOS (*it
) > BEGV
)
4052 reseat (it
, it
->current
.pos
, 0);
4056 reseat (it
, it
->current
.pos
, 0);
4063 /***********************************************************************
4064 Changing an iterator's position
4065 ***********************************************************************/
4067 /* Change IT's current position to POS in current_buffer. If FORCE_P
4068 is non-zero, always check for text properties at the new position.
4069 Otherwise, text properties are only looked up if POS >=
4070 IT->check_charpos of a property. */
4073 reseat (it
, pos
, force_p
)
4075 struct text_pos pos
;
4078 int original_pos
= IT_CHARPOS (*it
);
4080 reseat_1 (it
, pos
, 0);
4082 /* Determine where to check text properties. Avoid doing it
4083 where possible because text property lookup is very expensive. */
4085 || CHARPOS (pos
) > it
->stop_charpos
4086 || CHARPOS (pos
) < original_pos
)
4093 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4094 IT->stop_pos to POS, also. */
4097 reseat_1 (it
, pos
, set_stop_p
)
4099 struct text_pos pos
;
4102 /* Don't call this function when scanning a C string. */
4103 xassert (it
->s
== NULL
);
4105 /* POS must be a reasonable value. */
4106 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4108 it
->current
.pos
= it
->position
= pos
;
4109 XSETBUFFER (it
->object
, current_buffer
);
4110 it
->end_charpos
= ZV
;
4112 it
->current
.dpvec_index
= -1;
4113 it
->current
.overlay_string_index
= -1;
4114 IT_STRING_CHARPOS (*it
) = -1;
4115 IT_STRING_BYTEPOS (*it
) = -1;
4117 it
->method
= next_element_from_buffer
;
4118 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4120 it
->face_before_selective_p
= 0;
4123 it
->stop_charpos
= CHARPOS (pos
);
4127 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4128 If S is non-null, it is a C string to iterate over. Otherwise,
4129 STRING gives a Lisp string to iterate over.
4131 If PRECISION > 0, don't return more then PRECISION number of
4132 characters from the string.
4134 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4135 characters have been returned. FIELD_WIDTH < 0 means an infinite
4138 MULTIBYTE = 0 means disable processing of multibyte characters,
4139 MULTIBYTE > 0 means enable it,
4140 MULTIBYTE < 0 means use IT->multibyte_p.
4142 IT must be initialized via a prior call to init_iterator before
4143 calling this function. */
4146 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4151 int precision
, field_width
, multibyte
;
4153 /* No region in strings. */
4154 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4156 /* No text property checks performed by default, but see below. */
4157 it
->stop_charpos
= -1;
4159 /* Set iterator position and end position. */
4160 bzero (&it
->current
, sizeof it
->current
);
4161 it
->current
.overlay_string_index
= -1;
4162 it
->current
.dpvec_index
= -1;
4163 xassert (charpos
>= 0);
4165 /* If STRING is specified, use its multibyteness, otherwise use the
4166 setting of MULTIBYTE, if specified. */
4168 it
->multibyte_p
= multibyte
> 0;
4172 xassert (STRINGP (string
));
4173 it
->string
= string
;
4175 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4176 it
->method
= next_element_from_string
;
4177 it
->current
.string_pos
= string_pos (charpos
, string
);
4184 /* Note that we use IT->current.pos, not it->current.string_pos,
4185 for displaying C strings. */
4186 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4187 if (it
->multibyte_p
)
4189 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4190 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4194 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4195 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4198 it
->method
= next_element_from_c_string
;
4201 /* PRECISION > 0 means don't return more than PRECISION characters
4203 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4204 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4206 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4207 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4208 FIELD_WIDTH < 0 means infinite field width. This is useful for
4209 padding with `-' at the end of a mode line. */
4210 if (field_width
< 0)
4211 field_width
= INFINITY
;
4212 if (field_width
> it
->end_charpos
- charpos
)
4213 it
->end_charpos
= charpos
+ field_width
;
4215 /* Use the standard display table for displaying strings. */
4216 if (DISP_TABLE_P (Vstandard_display_table
))
4217 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4219 it
->stop_charpos
= charpos
;
4225 /***********************************************************************
4227 ***********************************************************************/
4229 /* Load IT's display element fields with information about the next
4230 display element from the current position of IT. Value is zero if
4231 end of buffer (or C string) is reached. */
4234 get_next_display_element (it
)
4237 /* Non-zero means that we found a display element. Zero means that
4238 we hit the end of what we iterate over. Performance note: the
4239 function pointer `method' used here turns out to be faster than
4240 using a sequence of if-statements. */
4241 int success_p
= (*it
->method
) (it
);
4243 if (it
->what
== IT_CHARACTER
)
4245 /* Map via display table or translate control characters.
4246 IT->c, IT->len etc. have been set to the next character by
4247 the function call above. If we have a display table, and it
4248 contains an entry for IT->c, translate it. Don't do this if
4249 IT->c itself comes from a display table, otherwise we could
4250 end up in an infinite recursion. (An alternative could be to
4251 count the recursion depth of this function and signal an
4252 error when a certain maximum depth is reached.) Is it worth
4254 if (success_p
&& it
->dpvec
== NULL
)
4259 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4262 struct Lisp_Vector
*v
= XVECTOR (dv
);
4264 /* Return the first character from the display table
4265 entry, if not empty. If empty, don't display the
4266 current character. */
4269 it
->dpvec_char_len
= it
->len
;
4270 it
->dpvec
= v
->contents
;
4271 it
->dpend
= v
->contents
+ v
->size
;
4272 it
->current
.dpvec_index
= 0;
4273 it
->method
= next_element_from_display_vector
;
4274 success_p
= get_next_display_element (it
);
4278 set_iterator_to_next (it
, 0);
4279 success_p
= get_next_display_element (it
);
4283 /* Translate control characters into `\003' or `^C' form.
4284 Control characters coming from a display table entry are
4285 currently not translated because we use IT->dpvec to hold
4286 the translation. This could easily be changed but I
4287 don't believe that it is worth doing.
4289 If it->multibyte_p is nonzero, eight-bit characters and
4290 non-printable multibyte characters are also translated to
4293 If it->multibyte_p is zero, eight-bit characters that
4294 don't have corresponding multibyte char code are also
4295 translated to octal form. */
4296 else if ((it
->c
< ' '
4297 && (it
->area
!= TEXT_AREA
4298 || (it
->c
!= '\n' && it
->c
!= '\t')))
4302 || !CHAR_PRINTABLE_P (it
->c
))
4304 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4306 /* IT->c is a control character which must be displayed
4307 either as '\003' or as `^C' where the '\\' and '^'
4308 can be defined in the display table. Fill
4309 IT->ctl_chars with glyphs for what we have to
4310 display. Then, set IT->dpvec to these glyphs. */
4313 if (it
->c
< 128 && it
->ctl_arrow_p
)
4315 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4317 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4318 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4319 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4321 g
= FAST_MAKE_GLYPH ('^', 0);
4322 XSETINT (it
->ctl_chars
[0], g
);
4324 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4325 XSETINT (it
->ctl_chars
[1], g
);
4327 /* Set up IT->dpvec and return first character from it. */
4328 it
->dpvec_char_len
= it
->len
;
4329 it
->dpvec
= it
->ctl_chars
;
4330 it
->dpend
= it
->dpvec
+ 2;
4331 it
->current
.dpvec_index
= 0;
4332 it
->method
= next_element_from_display_vector
;
4333 get_next_display_element (it
);
4337 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4342 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4344 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4345 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4346 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4348 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4350 if (SINGLE_BYTE_CHAR_P (it
->c
))
4351 str
[0] = it
->c
, len
= 1;
4354 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4357 /* It's an invalid character, which
4358 shouldn't happen actually, but due to
4359 bugs it may happen. Let's print the char
4360 as is, there's not much meaningful we can
4363 str
[1] = it
->c
>> 8;
4364 str
[2] = it
->c
>> 16;
4365 str
[3] = it
->c
>> 24;
4370 for (i
= 0; i
< len
; i
++)
4372 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4373 /* Insert three more glyphs into IT->ctl_chars for
4374 the octal display of the character. */
4375 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4376 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4377 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4378 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4379 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4380 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4383 /* Set up IT->dpvec and return the first character
4385 it
->dpvec_char_len
= it
->len
;
4386 it
->dpvec
= it
->ctl_chars
;
4387 it
->dpend
= it
->dpvec
+ len
* 4;
4388 it
->current
.dpvec_index
= 0;
4389 it
->method
= next_element_from_display_vector
;
4390 get_next_display_element (it
);
4395 /* Adjust face id for a multibyte character. There are no
4396 multibyte character in unibyte text. */
4399 && FRAME_WINDOW_P (it
->f
))
4401 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4402 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4406 /* Is this character the last one of a run of characters with
4407 box? If yes, set IT->end_of_box_run_p to 1. */
4414 it
->end_of_box_run_p
4415 = ((face_id
= face_after_it_pos (it
),
4416 face_id
!= it
->face_id
)
4417 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4418 face
->box
== FACE_NO_BOX
));
4421 /* Value is 0 if end of buffer or string reached. */
4426 /* Move IT to the next display element.
4428 RESEAT_P non-zero means if called on a newline in buffer text,
4429 skip to the next visible line start.
4431 Functions get_next_display_element and set_iterator_to_next are
4432 separate because I find this arrangement easier to handle than a
4433 get_next_display_element function that also increments IT's
4434 position. The way it is we can first look at an iterator's current
4435 display element, decide whether it fits on a line, and if it does,
4436 increment the iterator position. The other way around we probably
4437 would either need a flag indicating whether the iterator has to be
4438 incremented the next time, or we would have to implement a
4439 decrement position function which would not be easy to write. */
4442 set_iterator_to_next (it
, reseat_p
)
4446 /* Reset flags indicating start and end of a sequence of characters
4447 with box. Reset them at the start of this function because
4448 moving the iterator to a new position might set them. */
4449 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4451 if (it
->method
== next_element_from_buffer
)
4453 /* The current display element of IT is a character from
4454 current_buffer. Advance in the buffer, and maybe skip over
4455 invisible lines that are so because of selective display. */
4456 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4457 reseat_at_next_visible_line_start (it
, 0);
4460 xassert (it
->len
!= 0);
4461 IT_BYTEPOS (*it
) += it
->len
;
4462 IT_CHARPOS (*it
) += 1;
4463 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4466 else if (it
->method
== next_element_from_composition
)
4468 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4469 if (STRINGP (it
->string
))
4471 IT_STRING_BYTEPOS (*it
) += it
->len
;
4472 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4473 it
->method
= next_element_from_string
;
4474 goto consider_string_end
;
4478 IT_BYTEPOS (*it
) += it
->len
;
4479 IT_CHARPOS (*it
) += it
->cmp_len
;
4480 it
->method
= next_element_from_buffer
;
4483 else if (it
->method
== next_element_from_c_string
)
4485 /* Current display element of IT is from a C string. */
4486 IT_BYTEPOS (*it
) += it
->len
;
4487 IT_CHARPOS (*it
) += 1;
4489 else if (it
->method
== next_element_from_display_vector
)
4491 /* Current display element of IT is from a display table entry.
4492 Advance in the display table definition. Reset it to null if
4493 end reached, and continue with characters from buffers/
4495 ++it
->current
.dpvec_index
;
4497 /* Restore face of the iterator to what they were before the
4498 display vector entry (these entries may contain faces). */
4499 it
->face_id
= it
->saved_face_id
;
4501 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4504 it
->method
= next_element_from_c_string
;
4505 else if (STRINGP (it
->string
))
4506 it
->method
= next_element_from_string
;
4508 it
->method
= next_element_from_buffer
;
4511 it
->current
.dpvec_index
= -1;
4513 /* Skip over characters which were displayed via IT->dpvec. */
4514 if (it
->dpvec_char_len
< 0)
4515 reseat_at_next_visible_line_start (it
, 1);
4516 else if (it
->dpvec_char_len
> 0)
4518 it
->len
= it
->dpvec_char_len
;
4519 set_iterator_to_next (it
, reseat_p
);
4523 else if (it
->method
== next_element_from_string
)
4525 /* Current display element is a character from a Lisp string. */
4526 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4527 IT_STRING_BYTEPOS (*it
) += it
->len
;
4528 IT_STRING_CHARPOS (*it
) += 1;
4530 consider_string_end
:
4532 if (it
->current
.overlay_string_index
>= 0)
4534 /* IT->string is an overlay string. Advance to the
4535 next, if there is one. */
4536 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4537 next_overlay_string (it
);
4541 /* IT->string is not an overlay string. If we reached
4542 its end, and there is something on IT->stack, proceed
4543 with what is on the stack. This can be either another
4544 string, this time an overlay string, or a buffer. */
4545 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4549 if (!STRINGP (it
->string
))
4550 it
->method
= next_element_from_buffer
;
4552 goto consider_string_end
;
4556 else if (it
->method
== next_element_from_image
4557 || it
->method
== next_element_from_stretch
)
4559 /* The position etc with which we have to proceed are on
4560 the stack. The position may be at the end of a string,
4561 if the `display' property takes up the whole string. */
4564 if (STRINGP (it
->string
))
4566 it
->method
= next_element_from_string
;
4567 goto consider_string_end
;
4570 it
->method
= next_element_from_buffer
;
4573 /* There are no other methods defined, so this should be a bug. */
4576 xassert (it
->method
!= next_element_from_string
4577 || (STRINGP (it
->string
)
4578 && IT_STRING_CHARPOS (*it
) >= 0));
4582 /* Load IT's display element fields with information about the next
4583 display element which comes from a display table entry or from the
4584 result of translating a control character to one of the forms `^C'
4585 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4588 next_element_from_display_vector (it
)
4592 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4594 /* Remember the current face id in case glyphs specify faces.
4595 IT's face is restored in set_iterator_to_next. */
4596 it
->saved_face_id
= it
->face_id
;
4598 if (INTEGERP (*it
->dpvec
)
4599 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4604 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4605 it
->c
= FAST_GLYPH_CHAR (g
);
4606 it
->len
= CHAR_BYTES (it
->c
);
4608 /* The entry may contain a face id to use. Such a face id is
4609 the id of a Lisp face, not a realized face. A face id of
4610 zero means no face is specified. */
4611 lface_id
= FAST_GLYPH_FACE (g
);
4614 /* The function returns -1 if lface_id is invalid. */
4615 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4617 it
->face_id
= face_id
;
4621 /* Display table entry is invalid. Return a space. */
4622 it
->c
= ' ', it
->len
= 1;
4624 /* Don't change position and object of the iterator here. They are
4625 still the values of the character that had this display table
4626 entry or was translated, and that's what we want. */
4627 it
->what
= IT_CHARACTER
;
4632 /* Load IT with the next display element from Lisp string IT->string.
4633 IT->current.string_pos is the current position within the string.
4634 If IT->current.overlay_string_index >= 0, the Lisp string is an
4638 next_element_from_string (it
)
4641 struct text_pos position
;
4643 xassert (STRINGP (it
->string
));
4644 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4645 position
= it
->current
.string_pos
;
4647 /* Time to check for invisible text? */
4648 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4649 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4653 /* Since a handler may have changed IT->method, we must
4655 return get_next_display_element (it
);
4658 if (it
->current
.overlay_string_index
>= 0)
4660 /* Get the next character from an overlay string. In overlay
4661 strings, There is no field width or padding with spaces to
4663 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4668 else if (STRING_MULTIBYTE (it
->string
))
4670 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4671 const unsigned char *s
= (SDATA (it
->string
)
4672 + IT_STRING_BYTEPOS (*it
));
4673 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4677 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4683 /* Get the next character from a Lisp string that is not an
4684 overlay string. Such strings come from the mode line, for
4685 example. We may have to pad with spaces, or truncate the
4686 string. See also next_element_from_c_string. */
4687 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4692 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4694 /* Pad with spaces. */
4695 it
->c
= ' ', it
->len
= 1;
4696 CHARPOS (position
) = BYTEPOS (position
) = -1;
4698 else if (STRING_MULTIBYTE (it
->string
))
4700 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4701 const unsigned char *s
= (SDATA (it
->string
)
4702 + IT_STRING_BYTEPOS (*it
));
4703 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4707 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4712 /* Record what we have and where it came from. Note that we store a
4713 buffer position in IT->position although it could arguably be a
4715 it
->what
= IT_CHARACTER
;
4716 it
->object
= it
->string
;
4717 it
->position
= position
;
4722 /* Load IT with next display element from C string IT->s.
4723 IT->string_nchars is the maximum number of characters to return
4724 from the string. IT->end_charpos may be greater than
4725 IT->string_nchars when this function is called, in which case we
4726 may have to return padding spaces. Value is zero if end of string
4727 reached, including padding spaces. */
4730 next_element_from_c_string (it
)
4736 it
->what
= IT_CHARACTER
;
4737 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4740 /* IT's position can be greater IT->string_nchars in case a field
4741 width or precision has been specified when the iterator was
4743 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4745 /* End of the game. */
4749 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4751 /* Pad with spaces. */
4752 it
->c
= ' ', it
->len
= 1;
4753 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4755 else if (it
->multibyte_p
)
4757 /* Implementation note: The calls to strlen apparently aren't a
4758 performance problem because there is no noticeable performance
4759 difference between Emacs running in unibyte or multibyte mode. */
4760 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4761 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4765 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4771 /* Set up IT to return characters from an ellipsis, if appropriate.
4772 The definition of the ellipsis glyphs may come from a display table
4773 entry. This function Fills IT with the first glyph from the
4774 ellipsis if an ellipsis is to be displayed. */
4777 next_element_from_ellipsis (it
)
4780 if (it
->selective_display_ellipsis_p
)
4782 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4784 /* Use the display table definition for `...'. Invalid glyphs
4785 will be handled by the method returning elements from dpvec. */
4786 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4787 it
->dpvec_char_len
= it
->len
;
4788 it
->dpvec
= v
->contents
;
4789 it
->dpend
= v
->contents
+ v
->size
;
4790 it
->current
.dpvec_index
= 0;
4791 it
->method
= next_element_from_display_vector
;
4795 /* Use default `...' which is stored in default_invis_vector. */
4796 it
->dpvec_char_len
= it
->len
;
4797 it
->dpvec
= default_invis_vector
;
4798 it
->dpend
= default_invis_vector
+ 3;
4799 it
->current
.dpvec_index
= 0;
4800 it
->method
= next_element_from_display_vector
;
4805 /* The face at the current position may be different from the
4806 face we find after the invisible text. Remember what it
4807 was in IT->saved_face_id, and signal that it's there by
4808 setting face_before_selective_p. */
4809 it
->saved_face_id
= it
->face_id
;
4810 it
->method
= next_element_from_buffer
;
4811 reseat_at_next_visible_line_start (it
, 1);
4812 it
->face_before_selective_p
= 1;
4815 return get_next_display_element (it
);
4819 /* Deliver an image display element. The iterator IT is already
4820 filled with image information (done in handle_display_prop). Value
4825 next_element_from_image (it
)
4828 it
->what
= IT_IMAGE
;
4833 /* Fill iterator IT with next display element from a stretch glyph
4834 property. IT->object is the value of the text property. Value is
4838 next_element_from_stretch (it
)
4841 it
->what
= IT_STRETCH
;
4846 /* Load IT with the next display element from current_buffer. Value
4847 is zero if end of buffer reached. IT->stop_charpos is the next
4848 position at which to stop and check for text properties or buffer
4852 next_element_from_buffer (it
)
4857 /* Check this assumption, otherwise, we would never enter the
4858 if-statement, below. */
4859 xassert (IT_CHARPOS (*it
) >= BEGV
4860 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4862 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4864 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4866 int overlay_strings_follow_p
;
4868 /* End of the game, except when overlay strings follow that
4869 haven't been returned yet. */
4870 if (it
->overlay_strings_at_end_processed_p
)
4871 overlay_strings_follow_p
= 0;
4874 it
->overlay_strings_at_end_processed_p
= 1;
4875 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4878 if (overlay_strings_follow_p
)
4879 success_p
= get_next_display_element (it
);
4883 it
->position
= it
->current
.pos
;
4890 return get_next_display_element (it
);
4895 /* No face changes, overlays etc. in sight, so just return a
4896 character from current_buffer. */
4899 /* Maybe run the redisplay end trigger hook. Performance note:
4900 This doesn't seem to cost measurable time. */
4901 if (it
->redisplay_end_trigger_charpos
4903 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4904 run_redisplay_end_trigger_hook (it
);
4906 /* Get the next character, maybe multibyte. */
4907 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4908 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4910 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4911 - IT_BYTEPOS (*it
));
4912 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4915 it
->c
= *p
, it
->len
= 1;
4917 /* Record what we have and where it came from. */
4918 it
->what
= IT_CHARACTER
;;
4919 it
->object
= it
->w
->buffer
;
4920 it
->position
= it
->current
.pos
;
4922 /* Normally we return the character found above, except when we
4923 really want to return an ellipsis for selective display. */
4928 /* A value of selective > 0 means hide lines indented more
4929 than that number of columns. */
4930 if (it
->selective
> 0
4931 && IT_CHARPOS (*it
) + 1 < ZV
4932 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4933 IT_BYTEPOS (*it
) + 1,
4934 (double) it
->selective
)) /* iftc */
4936 success_p
= next_element_from_ellipsis (it
);
4937 it
->dpvec_char_len
= -1;
4940 else if (it
->c
== '\r' && it
->selective
== -1)
4942 /* A value of selective == -1 means that everything from the
4943 CR to the end of the line is invisible, with maybe an
4944 ellipsis displayed for it. */
4945 success_p
= next_element_from_ellipsis (it
);
4946 it
->dpvec_char_len
= -1;
4951 /* Value is zero if end of buffer reached. */
4952 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4957 /* Run the redisplay end trigger hook for IT. */
4960 run_redisplay_end_trigger_hook (it
)
4963 Lisp_Object args
[3];
4965 /* IT->glyph_row should be non-null, i.e. we should be actually
4966 displaying something, or otherwise we should not run the hook. */
4967 xassert (it
->glyph_row
);
4969 /* Set up hook arguments. */
4970 args
[0] = Qredisplay_end_trigger_functions
;
4971 args
[1] = it
->window
;
4972 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4973 it
->redisplay_end_trigger_charpos
= 0;
4975 /* Since we are *trying* to run these functions, don't try to run
4976 them again, even if they get an error. */
4977 it
->w
->redisplay_end_trigger
= Qnil
;
4978 Frun_hook_with_args (3, args
);
4980 /* Notice if it changed the face of the character we are on. */
4981 handle_face_prop (it
);
4985 /* Deliver a composition display element. The iterator IT is already
4986 filled with composition information (done in
4987 handle_composition_prop). Value is always 1. */
4990 next_element_from_composition (it
)
4993 it
->what
= IT_COMPOSITION
;
4994 it
->position
= (STRINGP (it
->string
)
4995 ? it
->current
.string_pos
5002 /***********************************************************************
5003 Moving an iterator without producing glyphs
5004 ***********************************************************************/
5006 /* Move iterator IT to a specified buffer or X position within one
5007 line on the display without producing glyphs.
5009 OP should be a bit mask including some or all of these bits:
5010 MOVE_TO_X: Stop on reaching x-position TO_X.
5011 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5012 Regardless of OP's value, stop in reaching the end of the display line.
5014 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5015 This means, in particular, that TO_X includes window's horizontal
5018 The return value has several possible values that
5019 say what condition caused the scan to stop:
5021 MOVE_POS_MATCH_OR_ZV
5022 - when TO_POS or ZV was reached.
5025 -when TO_X was reached before TO_POS or ZV were reached.
5028 - when we reached the end of the display area and the line must
5032 - when we reached the end of the display area and the line is
5036 - when we stopped at a line end, i.e. a newline or a CR and selective
5039 static enum move_it_result
5040 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5042 int to_charpos
, to_x
, op
;
5044 enum move_it_result result
= MOVE_UNDEFINED
;
5045 struct glyph_row
*saved_glyph_row
;
5047 /* Don't produce glyphs in produce_glyphs. */
5048 saved_glyph_row
= it
->glyph_row
;
5049 it
->glyph_row
= NULL
;
5053 int x
, i
, ascent
= 0, descent
= 0;
5055 /* Stop when ZV or TO_CHARPOS reached. */
5056 if (!get_next_display_element (it
)
5057 || ((op
& MOVE_TO_POS
) != 0
5058 && BUFFERP (it
->object
)
5059 && IT_CHARPOS (*it
) >= to_charpos
))
5061 result
= MOVE_POS_MATCH_OR_ZV
;
5065 /* The call to produce_glyphs will get the metrics of the
5066 display element IT is loaded with. We record in x the
5067 x-position before this display element in case it does not
5071 /* Remember the line height so far in case the next element doesn't
5073 if (!it
->truncate_lines_p
)
5075 ascent
= it
->max_ascent
;
5076 descent
= it
->max_descent
;
5079 PRODUCE_GLYPHS (it
);
5081 if (it
->area
!= TEXT_AREA
)
5083 set_iterator_to_next (it
, 1);
5087 /* The number of glyphs we get back in IT->nglyphs will normally
5088 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5089 character on a terminal frame, or (iii) a line end. For the
5090 second case, IT->nglyphs - 1 padding glyphs will be present
5091 (on X frames, there is only one glyph produced for a
5092 composite character.
5094 The behavior implemented below means, for continuation lines,
5095 that as many spaces of a TAB as fit on the current line are
5096 displayed there. For terminal frames, as many glyphs of a
5097 multi-glyph character are displayed in the current line, too.
5098 This is what the old redisplay code did, and we keep it that
5099 way. Under X, the whole shape of a complex character must
5100 fit on the line or it will be completely displayed in the
5103 Note that both for tabs and padding glyphs, all glyphs have
5107 /* More than one glyph or glyph doesn't fit on line. All
5108 glyphs have the same width. */
5109 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5112 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5114 new_x
= x
+ single_glyph_width
;
5116 /* We want to leave anything reaching TO_X to the caller. */
5117 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5120 result
= MOVE_X_REACHED
;
5123 else if (/* Lines are continued. */
5124 !it
->truncate_lines_p
5125 && (/* And glyph doesn't fit on the line. */
5126 new_x
> it
->last_visible_x
5127 /* Or it fits exactly and we're on a window
5129 || (new_x
== it
->last_visible_x
5130 && FRAME_WINDOW_P (it
->f
))))
5132 if (/* IT->hpos == 0 means the very first glyph
5133 doesn't fit on the line, e.g. a wide image. */
5135 || (new_x
== it
->last_visible_x
5136 && FRAME_WINDOW_P (it
->f
)))
5139 it
->current_x
= new_x
;
5140 if (i
== it
->nglyphs
- 1)
5141 set_iterator_to_next (it
, 1);
5146 it
->max_ascent
= ascent
;
5147 it
->max_descent
= descent
;
5150 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5152 result
= MOVE_LINE_CONTINUED
;
5155 else if (new_x
> it
->first_visible_x
)
5157 /* Glyph is visible. Increment number of glyphs that
5158 would be displayed. */
5163 /* Glyph is completely off the left margin of the display
5164 area. Nothing to do. */
5168 if (result
!= MOVE_UNDEFINED
)
5171 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5173 /* Stop when TO_X specified and reached. This check is
5174 necessary here because of lines consisting of a line end,
5175 only. The line end will not produce any glyphs and we
5176 would never get MOVE_X_REACHED. */
5177 xassert (it
->nglyphs
== 0);
5178 result
= MOVE_X_REACHED
;
5182 /* Is this a line end? If yes, we're done. */
5183 if (ITERATOR_AT_END_OF_LINE_P (it
))
5185 result
= MOVE_NEWLINE_OR_CR
;
5189 /* The current display element has been consumed. Advance
5191 set_iterator_to_next (it
, 1);
5193 /* Stop if lines are truncated and IT's current x-position is
5194 past the right edge of the window now. */
5195 if (it
->truncate_lines_p
5196 && it
->current_x
>= it
->last_visible_x
)
5198 result
= MOVE_LINE_TRUNCATED
;
5203 /* Restore the iterator settings altered at the beginning of this
5205 it
->glyph_row
= saved_glyph_row
;
5210 /* Move IT forward until it satisfies one or more of the criteria in
5211 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5213 OP is a bit-mask that specifies where to stop, and in particular,
5214 which of those four position arguments makes a difference. See the
5215 description of enum move_operation_enum.
5217 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5218 screen line, this function will set IT to the next position >
5222 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5224 int to_charpos
, to_x
, to_y
, to_vpos
;
5227 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5233 if (op
& MOVE_TO_VPOS
)
5235 /* If no TO_CHARPOS and no TO_X specified, stop at the
5236 start of the line TO_VPOS. */
5237 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5239 if (it
->vpos
== to_vpos
)
5245 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5249 /* TO_VPOS >= 0 means stop at TO_X in the line at
5250 TO_VPOS, or at TO_POS, whichever comes first. */
5251 if (it
->vpos
== to_vpos
)
5257 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5259 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5264 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5266 /* We have reached TO_X but not in the line we want. */
5267 skip
= move_it_in_display_line_to (it
, to_charpos
,
5269 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5277 else if (op
& MOVE_TO_Y
)
5279 struct it it_backup
;
5281 /* TO_Y specified means stop at TO_X in the line containing
5282 TO_Y---or at TO_CHARPOS if this is reached first. The
5283 problem is that we can't really tell whether the line
5284 contains TO_Y before we have completely scanned it, and
5285 this may skip past TO_X. What we do is to first scan to
5288 If TO_X is not specified, use a TO_X of zero. The reason
5289 is to make the outcome of this function more predictable.
5290 If we didn't use TO_X == 0, we would stop at the end of
5291 the line which is probably not what a caller would expect
5293 skip
= move_it_in_display_line_to (it
, to_charpos
,
5297 | (op
& MOVE_TO_POS
)));
5299 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5300 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5306 /* If TO_X was reached, we would like to know whether TO_Y
5307 is in the line. This can only be said if we know the
5308 total line height which requires us to scan the rest of
5310 if (skip
== MOVE_X_REACHED
)
5313 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5314 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5316 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5319 /* Now, decide whether TO_Y is in this line. */
5320 line_height
= it
->max_ascent
+ it
->max_descent
;
5321 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5323 if (to_y
>= it
->current_y
5324 && to_y
< it
->current_y
+ line_height
)
5326 if (skip
== MOVE_X_REACHED
)
5327 /* If TO_Y is in this line and TO_X was reached above,
5328 we scanned too far. We have to restore IT's settings
5329 to the ones before skipping. */
5333 else if (skip
== MOVE_X_REACHED
)
5336 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5344 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5348 case MOVE_POS_MATCH_OR_ZV
:
5352 case MOVE_NEWLINE_OR_CR
:
5353 set_iterator_to_next (it
, 1);
5354 it
->continuation_lines_width
= 0;
5357 case MOVE_LINE_TRUNCATED
:
5358 it
->continuation_lines_width
= 0;
5359 reseat_at_next_visible_line_start (it
, 0);
5360 if ((op
& MOVE_TO_POS
) != 0
5361 && IT_CHARPOS (*it
) > to_charpos
)
5368 case MOVE_LINE_CONTINUED
:
5369 it
->continuation_lines_width
+= it
->current_x
;
5376 /* Reset/increment for the next run. */
5377 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5378 it
->current_x
= it
->hpos
= 0;
5379 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5381 last_height
= it
->max_ascent
+ it
->max_descent
;
5382 last_max_ascent
= it
->max_ascent
;
5383 it
->max_ascent
= it
->max_descent
= 0;
5388 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5392 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5394 If DY > 0, move IT backward at least that many pixels. DY = 0
5395 means move IT backward to the preceding line start or BEGV. This
5396 function may move over more than DY pixels if IT->current_y - DY
5397 ends up in the middle of a line; in this case IT->current_y will be
5398 set to the top of the line moved to. */
5401 move_it_vertically_backward (it
, dy
)
5407 int start_pos
= IT_CHARPOS (*it
);
5411 /* Estimate how many newlines we must move back. */
5412 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5414 /* Set the iterator's position that many lines back. */
5415 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5416 back_to_previous_visible_line_start (it
);
5418 /* Reseat the iterator here. When moving backward, we don't want
5419 reseat to skip forward over invisible text, set up the iterator
5420 to deliver from overlay strings at the new position etc. So,
5421 use reseat_1 here. */
5422 reseat_1 (it
, it
->current
.pos
, 1);
5424 /* We are now surely at a line start. */
5425 it
->current_x
= it
->hpos
= 0;
5426 it
->continuation_lines_width
= 0;
5428 /* Move forward and see what y-distance we moved. First move to the
5429 start of the next line so that we get its height. We need this
5430 height to be able to tell whether we reached the specified
5433 it2
.max_ascent
= it2
.max_descent
= 0;
5434 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5435 MOVE_TO_POS
| MOVE_TO_VPOS
);
5436 xassert (IT_CHARPOS (*it
) >= BEGV
);
5439 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5440 xassert (IT_CHARPOS (*it
) >= BEGV
);
5441 h
= it2
.current_y
- it
->current_y
;
5442 nlines
= it2
.vpos
- it
->vpos
;
5444 /* Correct IT's y and vpos position. */
5450 /* DY == 0 means move to the start of the screen line. The
5451 value of nlines is > 0 if continuation lines were involved. */
5453 move_it_by_lines (it
, nlines
, 1);
5454 xassert (IT_CHARPOS (*it
) <= start_pos
);
5458 /* The y-position we try to reach. Note that h has been
5459 subtracted in front of the if-statement. */
5460 int target_y
= it
->current_y
+ h
- dy
;
5461 int y0
= it3
.current_y
;
5462 int y1
= line_bottom_y (&it3
);
5463 int line_height
= y1
- y0
;
5465 /* If we did not reach target_y, try to move further backward if
5466 we can. If we moved too far backward, try to move forward. */
5467 if (target_y
< it
->current_y
5468 /* This is heuristic. In a window that's 3 lines high, with
5469 a line height of 13 pixels each, recentering with point
5470 on the bottom line will try to move -39/2 = 19 pixels
5471 backward. Try to avoid moving into the first line. */
5472 && it
->current_y
- target_y
> line_height
/ 3 * 2
5473 && IT_CHARPOS (*it
) > BEGV
)
5475 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5476 target_y
- it
->current_y
));
5477 move_it_vertically (it
, target_y
- it
->current_y
);
5478 xassert (IT_CHARPOS (*it
) >= BEGV
);
5480 else if (target_y
>= it
->current_y
+ line_height
5481 && IT_CHARPOS (*it
) < ZV
)
5483 /* Should move forward by at least one line, maybe more.
5485 Note: Calling move_it_by_lines can be expensive on
5486 terminal frames, where compute_motion is used (via
5487 vmotion) to do the job, when there are very long lines
5488 and truncate-lines is nil. That's the reason for
5489 treating terminal frames specially here. */
5491 if (!FRAME_WINDOW_P (it
->f
))
5492 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5497 move_it_by_lines (it
, 1, 1);
5499 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5502 xassert (IT_CHARPOS (*it
) >= BEGV
);
5508 /* Move IT by a specified amount of pixel lines DY. DY negative means
5509 move backwards. DY = 0 means move to start of screen line. At the
5510 end, IT will be on the start of a screen line. */
5513 move_it_vertically (it
, dy
)
5518 move_it_vertically_backward (it
, -dy
);
5521 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5522 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5523 MOVE_TO_POS
| MOVE_TO_Y
);
5524 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5526 /* If buffer ends in ZV without a newline, move to the start of
5527 the line to satisfy the post-condition. */
5528 if (IT_CHARPOS (*it
) == ZV
5529 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5530 move_it_by_lines (it
, 0, 0);
5535 /* Move iterator IT past the end of the text line it is in. */
5538 move_it_past_eol (it
)
5541 enum move_it_result rc
;
5543 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5544 if (rc
== MOVE_NEWLINE_OR_CR
)
5545 set_iterator_to_next (it
, 0);
5549 #if 0 /* Currently not used. */
5551 /* Return non-zero if some text between buffer positions START_CHARPOS
5552 and END_CHARPOS is invisible. IT->window is the window for text
5556 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5558 int start_charpos
, end_charpos
;
5560 Lisp_Object prop
, limit
;
5561 int invisible_found_p
;
5563 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5565 /* Is text at START invisible? */
5566 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5568 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5569 invisible_found_p
= 1;
5572 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5574 make_number (end_charpos
));
5575 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5578 return invisible_found_p
;
5584 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5585 negative means move up. DVPOS == 0 means move to the start of the
5586 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5587 NEED_Y_P is zero, IT->current_y will be left unchanged.
5589 Further optimization ideas: If we would know that IT->f doesn't use
5590 a face with proportional font, we could be faster for
5591 truncate-lines nil. */
5594 move_it_by_lines (it
, dvpos
, need_y_p
)
5596 int dvpos
, need_y_p
;
5598 struct position pos
;
5600 if (!FRAME_WINDOW_P (it
->f
))
5602 struct text_pos textpos
;
5604 /* We can use vmotion on frames without proportional fonts. */
5605 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5606 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5607 reseat (it
, textpos
, 1);
5608 it
->vpos
+= pos
.vpos
;
5609 it
->current_y
+= pos
.vpos
;
5611 else if (dvpos
== 0)
5613 /* DVPOS == 0 means move to the start of the screen line. */
5614 move_it_vertically_backward (it
, 0);
5615 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5618 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5622 int start_charpos
, i
;
5624 /* Start at the beginning of the screen line containing IT's
5626 move_it_vertically_backward (it
, 0);
5628 /* Go back -DVPOS visible lines and reseat the iterator there. */
5629 start_charpos
= IT_CHARPOS (*it
);
5630 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5631 back_to_previous_visible_line_start (it
);
5632 reseat (it
, it
->current
.pos
, 1);
5633 it
->current_x
= it
->hpos
= 0;
5635 /* Above call may have moved too far if continuation lines
5636 are involved. Scan forward and see if it did. */
5638 it2
.vpos
= it2
.current_y
= 0;
5639 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5640 it
->vpos
-= it2
.vpos
;
5641 it
->current_y
-= it2
.current_y
;
5642 it
->current_x
= it
->hpos
= 0;
5644 /* If we moved too far, move IT some lines forward. */
5645 if (it2
.vpos
> -dvpos
)
5647 int delta
= it2
.vpos
+ dvpos
;
5648 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5653 /* Return 1 if IT points into the middle of a display vector. */
5656 in_display_vector_p (it
)
5659 return (it
->method
== next_element_from_display_vector
5660 && it
->current
.dpvec_index
> 0
5661 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
5665 /***********************************************************************
5667 ***********************************************************************/
5670 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5674 add_to_log (format
, arg1
, arg2
)
5676 Lisp_Object arg1
, arg2
;
5678 Lisp_Object args
[3];
5679 Lisp_Object msg
, fmt
;
5682 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5684 /* Do nothing if called asynchronously. Inserting text into
5685 a buffer may call after-change-functions and alike and
5686 that would means running Lisp asynchronously. */
5687 if (handling_signal
)
5691 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5693 args
[0] = fmt
= build_string (format
);
5696 msg
= Fformat (3, args
);
5698 len
= SBYTES (msg
) + 1;
5699 buffer
= (char *) alloca (len
);
5700 bcopy (SDATA (msg
), buffer
, len
);
5702 message_dolog (buffer
, len
- 1, 1, 0);
5707 /* Output a newline in the *Messages* buffer if "needs" one. */
5710 message_log_maybe_newline ()
5712 if (message_log_need_newline
)
5713 message_dolog ("", 0, 1, 0);
5717 /* Add a string M of length NBYTES to the message log, optionally
5718 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5719 nonzero, means interpret the contents of M as multibyte. This
5720 function calls low-level routines in order to bypass text property
5721 hooks, etc. which might not be safe to run. */
5724 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5726 int nbytes
, nlflag
, multibyte
;
5728 if (!NILP (Vmemory_full
))
5731 if (!NILP (Vmessage_log_max
))
5733 struct buffer
*oldbuf
;
5734 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5735 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5736 int point_at_end
= 0;
5738 Lisp_Object old_deactivate_mark
, tem
;
5739 struct gcpro gcpro1
;
5741 old_deactivate_mark
= Vdeactivate_mark
;
5742 oldbuf
= current_buffer
;
5743 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5744 current_buffer
->undo_list
= Qt
;
5746 oldpoint
= message_dolog_marker1
;
5747 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5748 oldbegv
= message_dolog_marker2
;
5749 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5750 oldzv
= message_dolog_marker3
;
5751 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5752 GCPRO1 (old_deactivate_mark
);
5760 BEGV_BYTE
= BEG_BYTE
;
5763 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5765 /* Insert the string--maybe converting multibyte to single byte
5766 or vice versa, so that all the text fits the buffer. */
5768 && NILP (current_buffer
->enable_multibyte_characters
))
5770 int i
, c
, char_bytes
;
5771 unsigned char work
[1];
5773 /* Convert a multibyte string to single-byte
5774 for the *Message* buffer. */
5775 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
5777 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5778 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5780 : multibyte_char_to_unibyte (c
, Qnil
));
5781 insert_1_both (work
, 1, 1, 1, 0, 0);
5784 else if (! multibyte
5785 && ! NILP (current_buffer
->enable_multibyte_characters
))
5787 int i
, c
, char_bytes
;
5788 unsigned char *msg
= (unsigned char *) m
;
5789 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5790 /* Convert a single-byte string to multibyte
5791 for the *Message* buffer. */
5792 for (i
= 0; i
< nbytes
; i
++)
5794 c
= unibyte_char_to_multibyte (msg
[i
]);
5795 char_bytes
= CHAR_STRING (c
, str
);
5796 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5800 insert_1 (m
, nbytes
, 1, 0, 0);
5804 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5805 insert_1 ("\n", 1, 1, 0, 0);
5807 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5809 this_bol_byte
= PT_BYTE
;
5811 /* See if this line duplicates the previous one.
5812 If so, combine duplicates. */
5815 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5817 prev_bol_byte
= PT_BYTE
;
5819 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5820 this_bol
, this_bol_byte
);
5823 del_range_both (prev_bol
, prev_bol_byte
,
5824 this_bol
, this_bol_byte
, 0);
5830 /* If you change this format, don't forget to also
5831 change message_log_check_duplicate. */
5832 sprintf (dupstr
, " [%d times]", dup
);
5833 duplen
= strlen (dupstr
);
5834 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5835 insert_1 (dupstr
, duplen
, 1, 0, 1);
5840 /* If we have more than the desired maximum number of lines
5841 in the *Messages* buffer now, delete the oldest ones.
5842 This is safe because we don't have undo in this buffer. */
5844 if (NATNUMP (Vmessage_log_max
))
5846 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5847 -XFASTINT (Vmessage_log_max
) - 1, 0);
5848 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5851 BEGV
= XMARKER (oldbegv
)->charpos
;
5852 BEGV_BYTE
= marker_byte_position (oldbegv
);
5861 ZV
= XMARKER (oldzv
)->charpos
;
5862 ZV_BYTE
= marker_byte_position (oldzv
);
5866 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5868 /* We can't do Fgoto_char (oldpoint) because it will run some
5870 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5871 XMARKER (oldpoint
)->bytepos
);
5874 unchain_marker (oldpoint
);
5875 unchain_marker (oldbegv
);
5876 unchain_marker (oldzv
);
5878 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5879 set_buffer_internal (oldbuf
);
5881 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5882 message_log_need_newline
= !nlflag
;
5883 Vdeactivate_mark
= old_deactivate_mark
;
5888 /* We are at the end of the buffer after just having inserted a newline.
5889 (Note: We depend on the fact we won't be crossing the gap.)
5890 Check to see if the most recent message looks a lot like the previous one.
5891 Return 0 if different, 1 if the new one should just replace it, or a
5892 value N > 1 if we should also append " [N times]". */
5895 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5896 int prev_bol
, this_bol
;
5897 int prev_bol_byte
, this_bol_byte
;
5900 int len
= Z_BYTE
- 1 - this_bol_byte
;
5902 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5903 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5905 for (i
= 0; i
< len
; i
++)
5907 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5915 if (*p1
++ == ' ' && *p1
++ == '[')
5918 while (*p1
>= '0' && *p1
<= '9')
5919 n
= n
* 10 + *p1
++ - '0';
5920 if (strncmp (p1
, " times]\n", 8) == 0)
5927 /* Display an echo area message M with a specified length of NBYTES
5928 bytes. The string may include null characters. If M is 0, clear
5929 out any existing message, and let the mini-buffer text show
5932 The buffer M must continue to exist until after the echo area gets
5933 cleared or some other message gets displayed there. This means do
5934 not pass text that is stored in a Lisp string; do not pass text in
5935 a buffer that was alloca'd. */
5938 message2 (m
, nbytes
, multibyte
)
5943 /* First flush out any partial line written with print. */
5944 message_log_maybe_newline ();
5946 message_dolog (m
, nbytes
, 1, multibyte
);
5947 message2_nolog (m
, nbytes
, multibyte
);
5951 /* The non-logging counterpart of message2. */
5954 message2_nolog (m
, nbytes
, multibyte
)
5956 int nbytes
, multibyte
;
5958 struct frame
*sf
= SELECTED_FRAME ();
5959 message_enable_multibyte
= multibyte
;
5963 if (noninteractive_need_newline
)
5964 putc ('\n', stderr
);
5965 noninteractive_need_newline
= 0;
5967 fwrite (m
, nbytes
, 1, stderr
);
5968 if (cursor_in_echo_area
== 0)
5969 fprintf (stderr
, "\n");
5972 /* A null message buffer means that the frame hasn't really been
5973 initialized yet. Error messages get reported properly by
5974 cmd_error, so this must be just an informative message; toss it. */
5975 else if (INTERACTIVE
5976 && sf
->glyphs_initialized_p
5977 && FRAME_MESSAGE_BUF (sf
))
5979 Lisp_Object mini_window
;
5982 /* Get the frame containing the mini-buffer
5983 that the selected frame is using. */
5984 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5985 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5987 FRAME_SAMPLE_VISIBILITY (f
);
5988 if (FRAME_VISIBLE_P (sf
)
5989 && ! FRAME_VISIBLE_P (f
))
5990 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5994 set_message (m
, Qnil
, nbytes
, multibyte
);
5995 if (minibuffer_auto_raise
)
5996 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5999 clear_message (1, 1);
6001 do_pending_window_change (0);
6002 echo_area_display (1);
6003 do_pending_window_change (0);
6004 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6005 (*frame_up_to_date_hook
) (f
);
6010 /* Display an echo area message M with a specified length of NBYTES
6011 bytes. The string may include null characters. If M is not a
6012 string, clear out any existing message, and let the mini-buffer
6013 text show through. */
6016 message3 (m
, nbytes
, multibyte
)
6021 struct gcpro gcpro1
;
6025 /* First flush out any partial line written with print. */
6026 message_log_maybe_newline ();
6028 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6029 message3_nolog (m
, nbytes
, multibyte
);
6035 /* The non-logging version of message3. */
6038 message3_nolog (m
, nbytes
, multibyte
)
6040 int nbytes
, multibyte
;
6042 struct frame
*sf
= SELECTED_FRAME ();
6043 message_enable_multibyte
= multibyte
;
6047 if (noninteractive_need_newline
)
6048 putc ('\n', stderr
);
6049 noninteractive_need_newline
= 0;
6051 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6052 if (cursor_in_echo_area
== 0)
6053 fprintf (stderr
, "\n");
6056 /* A null message buffer means that the frame hasn't really been
6057 initialized yet. Error messages get reported properly by
6058 cmd_error, so this must be just an informative message; toss it. */
6059 else if (INTERACTIVE
6060 && sf
->glyphs_initialized_p
6061 && FRAME_MESSAGE_BUF (sf
))
6063 Lisp_Object mini_window
;
6067 /* Get the frame containing the mini-buffer
6068 that the selected frame is using. */
6069 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6070 frame
= XWINDOW (mini_window
)->frame
;
6073 FRAME_SAMPLE_VISIBILITY (f
);
6074 if (FRAME_VISIBLE_P (sf
)
6075 && !FRAME_VISIBLE_P (f
))
6076 Fmake_frame_visible (frame
);
6078 if (STRINGP (m
) && SCHARS (m
) > 0)
6080 set_message (NULL
, m
, nbytes
, multibyte
);
6081 if (minibuffer_auto_raise
)
6082 Fraise_frame (frame
);
6085 clear_message (1, 1);
6087 do_pending_window_change (0);
6088 echo_area_display (1);
6089 do_pending_window_change (0);
6090 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6091 (*frame_up_to_date_hook
) (f
);
6096 /* Display a null-terminated echo area message M. If M is 0, clear
6097 out any existing message, and let the mini-buffer text show through.
6099 The buffer M must continue to exist until after the echo area gets
6100 cleared or some other message gets displayed there. Do not pass
6101 text that is stored in a Lisp string. Do not pass text in a buffer
6102 that was alloca'd. */
6108 message2 (m
, (m
? strlen (m
) : 0), 0);
6112 /* The non-logging counterpart of message1. */
6118 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6121 /* Display a message M which contains a single %s
6122 which gets replaced with STRING. */
6125 message_with_string (m
, string
, log
)
6130 CHECK_STRING (string
);
6136 if (noninteractive_need_newline
)
6137 putc ('\n', stderr
);
6138 noninteractive_need_newline
= 0;
6139 fprintf (stderr
, m
, SDATA (string
));
6140 if (cursor_in_echo_area
== 0)
6141 fprintf (stderr
, "\n");
6145 else if (INTERACTIVE
)
6147 /* The frame whose minibuffer we're going to display the message on.
6148 It may be larger than the selected frame, so we need
6149 to use its buffer, not the selected frame's buffer. */
6150 Lisp_Object mini_window
;
6151 struct frame
*f
, *sf
= SELECTED_FRAME ();
6153 /* Get the frame containing the minibuffer
6154 that the selected frame is using. */
6155 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6156 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6158 /* A null message buffer means that the frame hasn't really been
6159 initialized yet. Error messages get reported properly by
6160 cmd_error, so this must be just an informative message; toss it. */
6161 if (FRAME_MESSAGE_BUF (f
))
6163 Lisp_Object args
[2], message
;
6164 struct gcpro gcpro1
, gcpro2
;
6166 args
[0] = build_string (m
);
6167 args
[1] = message
= string
;
6168 GCPRO2 (args
[0], message
);
6171 message
= Fformat (2, args
);
6174 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6176 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6180 /* Print should start at the beginning of the message
6181 buffer next time. */
6182 message_buf_print
= 0;
6188 /* Dump an informative message to the minibuf. If M is 0, clear out
6189 any existing message, and let the mini-buffer text show through. */
6193 message (m
, a1
, a2
, a3
)
6195 EMACS_INT a1
, a2
, a3
;
6201 if (noninteractive_need_newline
)
6202 putc ('\n', stderr
);
6203 noninteractive_need_newline
= 0;
6204 fprintf (stderr
, m
, a1
, a2
, a3
);
6205 if (cursor_in_echo_area
== 0)
6206 fprintf (stderr
, "\n");
6210 else if (INTERACTIVE
)
6212 /* The frame whose mini-buffer we're going to display the message
6213 on. It may be larger than the selected frame, so we need to
6214 use its buffer, not the selected frame's buffer. */
6215 Lisp_Object mini_window
;
6216 struct frame
*f
, *sf
= SELECTED_FRAME ();
6218 /* Get the frame containing the mini-buffer
6219 that the selected frame is using. */
6220 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6221 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6223 /* A null message buffer means that the frame hasn't really been
6224 initialized yet. Error messages get reported properly by
6225 cmd_error, so this must be just an informative message; toss
6227 if (FRAME_MESSAGE_BUF (f
))
6238 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6239 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6241 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6242 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6244 #endif /* NO_ARG_ARRAY */
6246 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6251 /* Print should start at the beginning of the message
6252 buffer next time. */
6253 message_buf_print
= 0;
6259 /* The non-logging version of message. */
6262 message_nolog (m
, a1
, a2
, a3
)
6264 EMACS_INT a1
, a2
, a3
;
6266 Lisp_Object old_log_max
;
6267 old_log_max
= Vmessage_log_max
;
6268 Vmessage_log_max
= Qnil
;
6269 message (m
, a1
, a2
, a3
);
6270 Vmessage_log_max
= old_log_max
;
6274 /* Display the current message in the current mini-buffer. This is
6275 only called from error handlers in process.c, and is not time
6281 if (!NILP (echo_area_buffer
[0]))
6284 string
= Fcurrent_message ();
6285 message3 (string
, SBYTES (string
),
6286 !NILP (current_buffer
->enable_multibyte_characters
));
6291 /* Make sure echo area buffers in `echo_buffers' are live.
6292 If they aren't, make new ones. */
6295 ensure_echo_area_buffers ()
6299 for (i
= 0; i
< 2; ++i
)
6300 if (!BUFFERP (echo_buffer
[i
])
6301 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6304 Lisp_Object old_buffer
;
6307 old_buffer
= echo_buffer
[i
];
6308 sprintf (name
, " *Echo Area %d*", i
);
6309 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6310 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6312 for (j
= 0; j
< 2; ++j
)
6313 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6314 echo_area_buffer
[j
] = echo_buffer
[i
];
6319 /* Call FN with args A1..A4 with either the current or last displayed
6320 echo_area_buffer as current buffer.
6322 WHICH zero means use the current message buffer
6323 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6324 from echo_buffer[] and clear it.
6326 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6327 suitable buffer from echo_buffer[] and clear it.
6329 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6330 that the current message becomes the last displayed one, make
6331 choose a suitable buffer for echo_area_buffer[0], and clear it.
6333 Value is what FN returns. */
6336 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6339 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6345 int this_one
, the_other
, clear_buffer_p
, rc
;
6346 int count
= SPECPDL_INDEX ();
6348 /* If buffers aren't live, make new ones. */
6349 ensure_echo_area_buffers ();
6354 this_one
= 0, the_other
= 1;
6356 this_one
= 1, the_other
= 0;
6359 this_one
= 0, the_other
= 1;
6362 /* We need a fresh one in case the current echo buffer equals
6363 the one containing the last displayed echo area message. */
6364 if (!NILP (echo_area_buffer
[this_one
])
6365 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6366 echo_area_buffer
[this_one
] = Qnil
;
6369 /* Choose a suitable buffer from echo_buffer[] is we don't
6371 if (NILP (echo_area_buffer
[this_one
]))
6373 echo_area_buffer
[this_one
]
6374 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6375 ? echo_buffer
[the_other
]
6376 : echo_buffer
[this_one
]);
6380 buffer
= echo_area_buffer
[this_one
];
6382 /* Don't get confused by reusing the buffer used for echoing
6383 for a different purpose. */
6384 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6387 record_unwind_protect (unwind_with_echo_area_buffer
,
6388 with_echo_area_buffer_unwind_data (w
));
6390 /* Make the echo area buffer current. Note that for display
6391 purposes, it is not necessary that the displayed window's buffer
6392 == current_buffer, except for text property lookup. So, let's
6393 only set that buffer temporarily here without doing a full
6394 Fset_window_buffer. We must also change w->pointm, though,
6395 because otherwise an assertions in unshow_buffer fails, and Emacs
6397 set_buffer_internal_1 (XBUFFER (buffer
));
6401 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6404 current_buffer
->undo_list
= Qt
;
6405 current_buffer
->read_only
= Qnil
;
6406 specbind (Qinhibit_read_only
, Qt
);
6407 specbind (Qinhibit_modification_hooks
, Qt
);
6409 if (clear_buffer_p
&& Z
> BEG
)
6412 xassert (BEGV
>= BEG
);
6413 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6415 rc
= fn (a1
, a2
, a3
, a4
);
6417 xassert (BEGV
>= BEG
);
6418 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6420 unbind_to (count
, Qnil
);
6425 /* Save state that should be preserved around the call to the function
6426 FN called in with_echo_area_buffer. */
6429 with_echo_area_buffer_unwind_data (w
)
6435 /* Reduce consing by keeping one vector in
6436 Vwith_echo_area_save_vector. */
6437 vector
= Vwith_echo_area_save_vector
;
6438 Vwith_echo_area_save_vector
= Qnil
;
6441 vector
= Fmake_vector (make_number (7), Qnil
);
6443 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6444 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6445 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6449 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6450 AREF (vector
, i
) = w
->buffer
; ++i
;
6451 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6452 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6457 for (; i
< end
; ++i
)
6458 AREF (vector
, i
) = Qnil
;
6461 xassert (i
== ASIZE (vector
));
6466 /* Restore global state from VECTOR which was created by
6467 with_echo_area_buffer_unwind_data. */
6470 unwind_with_echo_area_buffer (vector
)
6473 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6474 Vdeactivate_mark
= AREF (vector
, 1);
6475 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6477 if (WINDOWP (AREF (vector
, 3)))
6480 Lisp_Object buffer
, charpos
, bytepos
;
6482 w
= XWINDOW (AREF (vector
, 3));
6483 buffer
= AREF (vector
, 4);
6484 charpos
= AREF (vector
, 5);
6485 bytepos
= AREF (vector
, 6);
6488 set_marker_both (w
->pointm
, buffer
,
6489 XFASTINT (charpos
), XFASTINT (bytepos
));
6492 Vwith_echo_area_save_vector
= vector
;
6497 /* Set up the echo area for use by print functions. MULTIBYTE_P
6498 non-zero means we will print multibyte. */
6501 setup_echo_area_for_printing (multibyte_p
)
6504 /* If we can't find an echo area any more, exit. */
6505 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
6508 ensure_echo_area_buffers ();
6510 if (!message_buf_print
)
6512 /* A message has been output since the last time we printed.
6513 Choose a fresh echo area buffer. */
6514 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6515 echo_area_buffer
[0] = echo_buffer
[1];
6517 echo_area_buffer
[0] = echo_buffer
[0];
6519 /* Switch to that buffer and clear it. */
6520 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6521 current_buffer
->truncate_lines
= Qnil
;
6525 int count
= SPECPDL_INDEX ();
6526 specbind (Qinhibit_read_only
, Qt
);
6527 /* Note that undo recording is always disabled. */
6529 unbind_to (count
, Qnil
);
6531 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6533 /* Set up the buffer for the multibyteness we need. */
6535 != !NILP (current_buffer
->enable_multibyte_characters
))
6536 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6538 /* Raise the frame containing the echo area. */
6539 if (minibuffer_auto_raise
)
6541 struct frame
*sf
= SELECTED_FRAME ();
6542 Lisp_Object mini_window
;
6543 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6544 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6547 message_log_maybe_newline ();
6548 message_buf_print
= 1;
6552 if (NILP (echo_area_buffer
[0]))
6554 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6555 echo_area_buffer
[0] = echo_buffer
[1];
6557 echo_area_buffer
[0] = echo_buffer
[0];
6560 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6562 /* Someone switched buffers between print requests. */
6563 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6564 current_buffer
->truncate_lines
= Qnil
;
6570 /* Display an echo area message in window W. Value is non-zero if W's
6571 height is changed. If display_last_displayed_message_p is
6572 non-zero, display the message that was last displayed, otherwise
6573 display the current message. */
6576 display_echo_area (w
)
6579 int i
, no_message_p
, window_height_changed_p
, count
;
6581 /* Temporarily disable garbage collections while displaying the echo
6582 area. This is done because a GC can print a message itself.
6583 That message would modify the echo area buffer's contents while a
6584 redisplay of the buffer is going on, and seriously confuse
6586 count
= inhibit_garbage_collection ();
6588 /* If there is no message, we must call display_echo_area_1
6589 nevertheless because it resizes the window. But we will have to
6590 reset the echo_area_buffer in question to nil at the end because
6591 with_echo_area_buffer will sets it to an empty buffer. */
6592 i
= display_last_displayed_message_p
? 1 : 0;
6593 no_message_p
= NILP (echo_area_buffer
[i
]);
6595 window_height_changed_p
6596 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6597 display_echo_area_1
,
6598 (EMACS_INT
) w
, Qnil
, 0, 0);
6601 echo_area_buffer
[i
] = Qnil
;
6603 unbind_to (count
, Qnil
);
6604 return window_height_changed_p
;
6608 /* Helper for display_echo_area. Display the current buffer which
6609 contains the current echo area message in window W, a mini-window,
6610 a pointer to which is passed in A1. A2..A4 are currently not used.
6611 Change the height of W so that all of the message is displayed.
6612 Value is non-zero if height of W was changed. */
6615 display_echo_area_1 (a1
, a2
, a3
, a4
)
6620 struct window
*w
= (struct window
*) a1
;
6622 struct text_pos start
;
6623 int window_height_changed_p
= 0;
6625 /* Do this before displaying, so that we have a large enough glyph
6626 matrix for the display. */
6627 window_height_changed_p
= resize_mini_window (w
, 0);
6630 clear_glyph_matrix (w
->desired_matrix
);
6631 XSETWINDOW (window
, w
);
6632 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6633 try_window (window
, start
);
6635 return window_height_changed_p
;
6639 /* Resize the echo area window to exactly the size needed for the
6640 currently displayed message, if there is one. If a mini-buffer
6641 is active, don't shrink it. */
6644 resize_echo_area_exactly ()
6646 if (BUFFERP (echo_area_buffer
[0])
6647 && WINDOWP (echo_area_window
))
6649 struct window
*w
= XWINDOW (echo_area_window
);
6651 Lisp_Object resize_exactly
;
6653 if (minibuf_level
== 0)
6654 resize_exactly
= Qt
;
6656 resize_exactly
= Qnil
;
6658 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6659 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6662 ++windows_or_buffers_changed
;
6663 ++update_mode_lines
;
6664 redisplay_internal (0);
6670 /* Callback function for with_echo_area_buffer, when used from
6671 resize_echo_area_exactly. A1 contains a pointer to the window to
6672 resize, EXACTLY non-nil means resize the mini-window exactly to the
6673 size of the text displayed. A3 and A4 are not used. Value is what
6674 resize_mini_window returns. */
6677 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6679 Lisp_Object exactly
;
6682 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6686 /* Resize mini-window W to fit the size of its contents. EXACT:P
6687 means size the window exactly to the size needed. Otherwise, it's
6688 only enlarged until W's buffer is empty. Value is non-zero if
6689 the window height has been changed. */
6692 resize_mini_window (w
, exact_p
)
6696 struct frame
*f
= XFRAME (w
->frame
);
6697 int window_height_changed_p
= 0;
6699 xassert (MINI_WINDOW_P (w
));
6701 /* Don't resize windows while redisplaying a window; it would
6702 confuse redisplay functions when the size of the window they are
6703 displaying changes from under them. Such a resizing can happen,
6704 for instance, when which-func prints a long message while
6705 we are running fontification-functions. We're running these
6706 functions with safe_call which binds inhibit-redisplay to t. */
6707 if (!NILP (Vinhibit_redisplay
))
6710 /* Nil means don't try to resize. */
6711 if (NILP (Vresize_mini_windows
)
6712 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6715 if (!FRAME_MINIBUF_ONLY_P (f
))
6718 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6719 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6720 int height
, max_height
;
6721 int unit
= CANON_Y_UNIT (f
);
6722 struct text_pos start
;
6723 struct buffer
*old_current_buffer
= NULL
;
6725 if (current_buffer
!= XBUFFER (w
->buffer
))
6727 old_current_buffer
= current_buffer
;
6728 set_buffer_internal (XBUFFER (w
->buffer
));
6731 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6733 /* Compute the max. number of lines specified by the user. */
6734 if (FLOATP (Vmax_mini_window_height
))
6735 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6736 else if (INTEGERP (Vmax_mini_window_height
))
6737 max_height
= XINT (Vmax_mini_window_height
);
6739 max_height
= total_height
/ 4;
6741 /* Correct that max. height if it's bogus. */
6742 max_height
= max (1, max_height
);
6743 max_height
= min (total_height
, max_height
);
6745 /* Find out the height of the text in the window. */
6746 if (it
.truncate_lines_p
)
6751 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6752 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6753 height
= it
.current_y
+ last_height
;
6755 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6756 height
-= it
.extra_line_spacing
;
6757 height
= (height
+ unit
- 1) / unit
;
6760 /* Compute a suitable window start. */
6761 if (height
> max_height
)
6763 height
= max_height
;
6764 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6765 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6766 start
= it
.current
.pos
;
6769 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6770 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6772 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6774 /* Let it grow only, until we display an empty message, in which
6775 case the window shrinks again. */
6776 if (height
> XFASTINT (w
->height
))
6778 int old_height
= XFASTINT (w
->height
);
6779 freeze_window_starts (f
, 1);
6780 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6781 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6783 else if (height
< XFASTINT (w
->height
)
6784 && (exact_p
|| BEGV
== ZV
))
6786 int old_height
= XFASTINT (w
->height
);
6787 freeze_window_starts (f
, 0);
6788 shrink_mini_window (w
);
6789 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6794 /* Always resize to exact size needed. */
6795 if (height
> XFASTINT (w
->height
))
6797 int old_height
= XFASTINT (w
->height
);
6798 freeze_window_starts (f
, 1);
6799 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6800 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6802 else if (height
< XFASTINT (w
->height
))
6804 int old_height
= XFASTINT (w
->height
);
6805 freeze_window_starts (f
, 0);
6806 shrink_mini_window (w
);
6810 freeze_window_starts (f
, 1);
6811 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6814 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6818 if (old_current_buffer
)
6819 set_buffer_internal (old_current_buffer
);
6822 return window_height_changed_p
;
6826 /* Value is the current message, a string, or nil if there is no
6834 if (NILP (echo_area_buffer
[0]))
6838 with_echo_area_buffer (0, 0, current_message_1
,
6839 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6841 echo_area_buffer
[0] = Qnil
;
6849 current_message_1 (a1
, a2
, a3
, a4
)
6854 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6857 *msg
= make_buffer_string (BEG
, Z
, 1);
6864 /* Push the current message on Vmessage_stack for later restauration
6865 by restore_message. Value is non-zero if the current message isn't
6866 empty. This is a relatively infrequent operation, so it's not
6867 worth optimizing. */
6873 msg
= current_message ();
6874 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6875 return STRINGP (msg
);
6879 /* Restore message display from the top of Vmessage_stack. */
6886 xassert (CONSP (Vmessage_stack
));
6887 msg
= XCAR (Vmessage_stack
);
6889 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
6891 message3_nolog (msg
, 0, 0);
6895 /* Handler for record_unwind_protect calling pop_message. */
6898 pop_message_unwind (dummy
)
6905 /* Pop the top-most entry off Vmessage_stack. */
6910 xassert (CONSP (Vmessage_stack
));
6911 Vmessage_stack
= XCDR (Vmessage_stack
);
6915 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6916 exits. If the stack is not empty, we have a missing pop_message
6920 check_message_stack ()
6922 if (!NILP (Vmessage_stack
))
6927 /* Truncate to NCHARS what will be displayed in the echo area the next
6928 time we display it---but don't redisplay it now. */
6931 truncate_echo_area (nchars
)
6935 echo_area_buffer
[0] = Qnil
;
6936 /* A null message buffer means that the frame hasn't really been
6937 initialized yet. Error messages get reported properly by
6938 cmd_error, so this must be just an informative message; toss it. */
6939 else if (!noninteractive
6941 && !NILP (echo_area_buffer
[0]))
6943 struct frame
*sf
= SELECTED_FRAME ();
6944 if (FRAME_MESSAGE_BUF (sf
))
6945 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6950 /* Helper function for truncate_echo_area. Truncate the current
6951 message to at most NCHARS characters. */
6954 truncate_message_1 (nchars
, a2
, a3
, a4
)
6959 if (BEG
+ nchars
< Z
)
6960 del_range (BEG
+ nchars
, Z
);
6962 echo_area_buffer
[0] = Qnil
;
6967 /* Set the current message to a substring of S or STRING.
6969 If STRING is a Lisp string, set the message to the first NBYTES
6970 bytes from STRING. NBYTES zero means use the whole string. If
6971 STRING is multibyte, the message will be displayed multibyte.
6973 If S is not null, set the message to the first LEN bytes of S. LEN
6974 zero means use the whole string. MULTIBYTE_P non-zero means S is
6975 multibyte. Display the message multibyte in that case. */
6978 set_message (s
, string
, nbytes
, multibyte_p
)
6981 int nbytes
, multibyte_p
;
6983 message_enable_multibyte
6984 = ((s
&& multibyte_p
)
6985 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6987 with_echo_area_buffer (0, -1, set_message_1
,
6988 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6989 message_buf_print
= 0;
6990 help_echo_showing_p
= 0;
6994 /* Helper function for set_message. Arguments have the same meaning
6995 as there, with A1 corresponding to S and A2 corresponding to STRING
6996 This function is called with the echo area buffer being
7000 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7003 EMACS_INT nbytes
, multibyte_p
;
7005 const char *s
= (const char *) a1
;
7006 Lisp_Object string
= a2
;
7010 /* Change multibyteness of the echo buffer appropriately. */
7011 if (message_enable_multibyte
7012 != !NILP (current_buffer
->enable_multibyte_characters
))
7013 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7015 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7017 /* Insert new message at BEG. */
7018 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7020 if (STRINGP (string
))
7025 nbytes
= SBYTES (string
);
7026 nchars
= string_byte_to_char (string
, nbytes
);
7028 /* This function takes care of single/multibyte conversion. We
7029 just have to ensure that the echo area buffer has the right
7030 setting of enable_multibyte_characters. */
7031 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7036 nbytes
= strlen (s
);
7038 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7040 /* Convert from multi-byte to single-byte. */
7042 unsigned char work
[1];
7044 /* Convert a multibyte string to single-byte. */
7045 for (i
= 0; i
< nbytes
; i
+= n
)
7047 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7048 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7050 : multibyte_char_to_unibyte (c
, Qnil
));
7051 insert_1_both (work
, 1, 1, 1, 0, 0);
7054 else if (!multibyte_p
7055 && !NILP (current_buffer
->enable_multibyte_characters
))
7057 /* Convert from single-byte to multi-byte. */
7059 const unsigned char *msg
= (const unsigned char *) s
;
7060 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7062 /* Convert a single-byte string to multibyte. */
7063 for (i
= 0; i
< nbytes
; i
++)
7065 c
= unibyte_char_to_multibyte (msg
[i
]);
7066 n
= CHAR_STRING (c
, str
);
7067 insert_1_both (str
, 1, n
, 1, 0, 0);
7071 insert_1 (s
, nbytes
, 1, 0, 0);
7078 /* Clear messages. CURRENT_P non-zero means clear the current
7079 message. LAST_DISPLAYED_P non-zero means clear the message
7083 clear_message (current_p
, last_displayed_p
)
7084 int current_p
, last_displayed_p
;
7088 echo_area_buffer
[0] = Qnil
;
7089 message_cleared_p
= 1;
7092 if (last_displayed_p
)
7093 echo_area_buffer
[1] = Qnil
;
7095 message_buf_print
= 0;
7098 /* Clear garbaged frames.
7100 This function is used where the old redisplay called
7101 redraw_garbaged_frames which in turn called redraw_frame which in
7102 turn called clear_frame. The call to clear_frame was a source of
7103 flickering. I believe a clear_frame is not necessary. It should
7104 suffice in the new redisplay to invalidate all current matrices,
7105 and ensure a complete redisplay of all windows. */
7108 clear_garbaged_frames ()
7112 Lisp_Object tail
, frame
;
7113 int changed_count
= 0;
7115 FOR_EACH_FRAME (tail
, frame
)
7117 struct frame
*f
= XFRAME (frame
);
7119 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7122 Fredraw_frame (frame
);
7123 clear_current_matrices (f
);
7132 ++windows_or_buffers_changed
;
7137 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7138 is non-zero update selected_frame. Value is non-zero if the
7139 mini-windows height has been changed. */
7142 echo_area_display (update_frame_p
)
7145 Lisp_Object mini_window
;
7148 int window_height_changed_p
= 0;
7149 struct frame
*sf
= SELECTED_FRAME ();
7151 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7152 w
= XWINDOW (mini_window
);
7153 f
= XFRAME (WINDOW_FRAME (w
));
7155 /* Don't display if frame is invisible or not yet initialized. */
7156 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7159 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7161 #ifdef HAVE_WINDOW_SYSTEM
7162 /* When Emacs starts, selected_frame may be a visible terminal
7163 frame, even if we run under a window system. If we let this
7164 through, a message would be displayed on the terminal. */
7165 if (EQ (selected_frame
, Vterminal_frame
)
7166 && !NILP (Vwindow_system
))
7168 #endif /* HAVE_WINDOW_SYSTEM */
7171 /* Redraw garbaged frames. */
7173 clear_garbaged_frames ();
7175 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7177 echo_area_window
= mini_window
;
7178 window_height_changed_p
= display_echo_area (w
);
7179 w
->must_be_updated_p
= 1;
7181 /* Update the display, unless called from redisplay_internal.
7182 Also don't update the screen during redisplay itself. The
7183 update will happen at the end of redisplay, and an update
7184 here could cause confusion. */
7185 if (update_frame_p
&& !redisplaying_p
)
7189 /* If the display update has been interrupted by pending
7190 input, update mode lines in the frame. Due to the
7191 pending input, it might have been that redisplay hasn't
7192 been called, so that mode lines above the echo area are
7193 garbaged. This looks odd, so we prevent it here. */
7194 if (!display_completed
)
7195 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7197 if (window_height_changed_p
7198 /* Don't do this if Emacs is shutting down. Redisplay
7199 needs to run hooks. */
7200 && !NILP (Vrun_hooks
))
7202 /* Must update other windows. Likewise as in other
7203 cases, don't let this update be interrupted by
7205 int count
= SPECPDL_INDEX ();
7206 specbind (Qredisplay_dont_pause
, Qt
);
7207 windows_or_buffers_changed
= 1;
7208 redisplay_internal (0);
7209 unbind_to (count
, Qnil
);
7211 else if (FRAME_WINDOW_P (f
) && n
== 0)
7213 /* Window configuration is the same as before.
7214 Can do with a display update of the echo area,
7215 unless we displayed some mode lines. */
7216 update_single_window (w
, 1);
7217 rif
->flush_display (f
);
7220 update_frame (f
, 1, 1);
7222 /* If cursor is in the echo area, make sure that the next
7223 redisplay displays the minibuffer, so that the cursor will
7224 be replaced with what the minibuffer wants. */
7225 if (cursor_in_echo_area
)
7226 ++windows_or_buffers_changed
;
7229 else if (!EQ (mini_window
, selected_window
))
7230 windows_or_buffers_changed
++;
7232 /* Last displayed message is now the current message. */
7233 echo_area_buffer
[1] = echo_area_buffer
[0];
7235 /* Prevent redisplay optimization in redisplay_internal by resetting
7236 this_line_start_pos. This is done because the mini-buffer now
7237 displays the message instead of its buffer text. */
7238 if (EQ (mini_window
, selected_window
))
7239 CHARPOS (this_line_start_pos
) = 0;
7241 return window_height_changed_p
;
7246 /***********************************************************************
7248 ***********************************************************************/
7251 /* The frame title buffering code is also used by Fformat_mode_line.
7252 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7254 /* A buffer for constructing frame titles in it; allocated from the
7255 heap in init_xdisp and resized as needed in store_frame_title_char. */
7257 static char *frame_title_buf
;
7259 /* The buffer's end, and a current output position in it. */
7261 static char *frame_title_buf_end
;
7262 static char *frame_title_ptr
;
7265 /* Store a single character C for the frame title in frame_title_buf.
7266 Re-allocate frame_title_buf if necessary. */
7270 store_frame_title_char (char c
)
7272 store_frame_title_char (c
)
7276 /* If output position has reached the end of the allocated buffer,
7277 double the buffer's size. */
7278 if (frame_title_ptr
== frame_title_buf_end
)
7280 int len
= frame_title_ptr
- frame_title_buf
;
7281 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7282 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7283 frame_title_buf_end
= frame_title_buf
+ new_size
;
7284 frame_title_ptr
= frame_title_buf
+ len
;
7287 *frame_title_ptr
++ = c
;
7291 /* Store part of a frame title in frame_title_buf, beginning at
7292 frame_title_ptr. STR is the string to store. Do not copy
7293 characters that yield more columns than PRECISION; PRECISION <= 0
7294 means copy the whole string. Pad with spaces until FIELD_WIDTH
7295 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7296 pad. Called from display_mode_element when it is used to build a
7300 store_frame_title (str
, field_width
, precision
)
7301 const unsigned char *str
;
7302 int field_width
, precision
;
7307 /* Copy at most PRECISION chars from STR. */
7308 nbytes
= strlen (str
);
7309 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7311 store_frame_title_char (*str
++);
7313 /* Fill up with spaces until FIELD_WIDTH reached. */
7314 while (field_width
> 0
7317 store_frame_title_char (' ');
7324 #ifdef HAVE_WINDOW_SYSTEM
7326 /* Set the title of FRAME, if it has changed. The title format is
7327 Vicon_title_format if FRAME is iconified, otherwise it is
7328 frame_title_format. */
7331 x_consider_frame_title (frame
)
7334 struct frame
*f
= XFRAME (frame
);
7336 if (FRAME_WINDOW_P (f
)
7337 || FRAME_MINIBUF_ONLY_P (f
)
7338 || f
->explicit_name
)
7340 /* Do we have more than one visible frame on this X display? */
7343 struct buffer
*obuf
;
7347 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7349 Lisp_Object other_frame
= XCAR (tail
);
7350 struct frame
*tf
= XFRAME (other_frame
);
7353 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7354 && !FRAME_MINIBUF_ONLY_P (tf
)
7355 && !EQ (other_frame
, tip_frame
)
7356 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7360 /* Set global variable indicating that multiple frames exist. */
7361 multiple_frames
= CONSP (tail
);
7363 /* Switch to the buffer of selected window of the frame. Set up
7364 frame_title_ptr so that display_mode_element will output into it;
7365 then display the title. */
7366 obuf
= current_buffer
;
7367 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7368 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7369 frame_title_ptr
= frame_title_buf
;
7370 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7371 NULL
, DEFAULT_FACE_ID
);
7372 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7373 len
= frame_title_ptr
- frame_title_buf
;
7374 frame_title_ptr
= NULL
;
7375 set_buffer_internal_1 (obuf
);
7377 /* Set the title only if it's changed. This avoids consing in
7378 the common case where it hasn't. (If it turns out that we've
7379 already wasted too much time by walking through the list with
7380 display_mode_element, then we might need to optimize at a
7381 higher level than this.) */
7382 if (! STRINGP (f
->name
)
7383 || SBYTES (f
->name
) != len
7384 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7385 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7389 #endif /* not HAVE_WINDOW_SYSTEM */
7394 /***********************************************************************
7396 ***********************************************************************/
7399 /* Prepare for redisplay by updating menu-bar item lists when
7400 appropriate. This can call eval. */
7403 prepare_menu_bars ()
7406 struct gcpro gcpro1
, gcpro2
;
7408 Lisp_Object tooltip_frame
;
7410 #ifdef HAVE_WINDOW_SYSTEM
7411 tooltip_frame
= tip_frame
;
7413 tooltip_frame
= Qnil
;
7416 /* Update all frame titles based on their buffer names, etc. We do
7417 this before the menu bars so that the buffer-menu will show the
7418 up-to-date frame titles. */
7419 #ifdef HAVE_WINDOW_SYSTEM
7420 if (windows_or_buffers_changed
|| update_mode_lines
)
7422 Lisp_Object tail
, frame
;
7424 FOR_EACH_FRAME (tail
, frame
)
7427 if (!EQ (frame
, tooltip_frame
)
7428 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7429 x_consider_frame_title (frame
);
7432 #endif /* HAVE_WINDOW_SYSTEM */
7434 /* Update the menu bar item lists, if appropriate. This has to be
7435 done before any actual redisplay or generation of display lines. */
7436 all_windows
= (update_mode_lines
7437 || buffer_shared
> 1
7438 || windows_or_buffers_changed
);
7441 Lisp_Object tail
, frame
;
7442 int count
= SPECPDL_INDEX ();
7444 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7446 FOR_EACH_FRAME (tail
, frame
)
7450 /* Ignore tooltip frame. */
7451 if (EQ (frame
, tooltip_frame
))
7454 /* If a window on this frame changed size, report that to
7455 the user and clear the size-change flag. */
7456 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7458 Lisp_Object functions
;
7460 /* Clear flag first in case we get an error below. */
7461 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7462 functions
= Vwindow_size_change_functions
;
7463 GCPRO2 (tail
, functions
);
7465 while (CONSP (functions
))
7467 call1 (XCAR (functions
), frame
);
7468 functions
= XCDR (functions
);
7474 update_menu_bar (f
, 0);
7475 #ifdef HAVE_WINDOW_SYSTEM
7476 update_tool_bar (f
, 0);
7481 unbind_to (count
, Qnil
);
7485 struct frame
*sf
= SELECTED_FRAME ();
7486 update_menu_bar (sf
, 1);
7487 #ifdef HAVE_WINDOW_SYSTEM
7488 update_tool_bar (sf
, 1);
7492 /* Motif needs this. See comment in xmenu.c. Turn it off when
7493 pending_menu_activation is not defined. */
7494 #ifdef USE_X_TOOLKIT
7495 pending_menu_activation
= 0;
7500 /* Update the menu bar item list for frame F. This has to be done
7501 before we start to fill in any display lines, because it can call
7504 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7507 update_menu_bar (f
, save_match_data
)
7509 int save_match_data
;
7512 register struct window
*w
;
7514 /* If called recursively during a menu update, do nothing. This can
7515 happen when, for instance, an activate-menubar-hook causes a
7517 if (inhibit_menubar_update
)
7520 window
= FRAME_SELECTED_WINDOW (f
);
7521 w
= XWINDOW (window
);
7523 #if 0 /* The if statement below this if statement used to include the
7524 condition !NILP (w->update_mode_line), rather than using
7525 update_mode_lines directly, and this if statement may have
7526 been added to make that condition work. Now the if
7527 statement below matches its comment, this isn't needed. */
7528 if (update_mode_lines
)
7529 w
->update_mode_line
= Qt
;
7532 if (FRAME_WINDOW_P (f
)
7534 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7535 || defined (USE_GTK)
7536 FRAME_EXTERNAL_MENU_BAR (f
)
7538 FRAME_MENU_BAR_LINES (f
) > 0
7540 : FRAME_MENU_BAR_LINES (f
) > 0)
7542 /* If the user has switched buffers or windows, we need to
7543 recompute to reflect the new bindings. But we'll
7544 recompute when update_mode_lines is set too; that means
7545 that people can use force-mode-line-update to request
7546 that the menu bar be recomputed. The adverse effect on
7547 the rest of the redisplay algorithm is about the same as
7548 windows_or_buffers_changed anyway. */
7549 if (windows_or_buffers_changed
7550 /* This used to test w->update_mode_line, but we believe
7551 there is no need to recompute the menu in that case. */
7552 || update_mode_lines
7553 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7554 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7555 != !NILP (w
->last_had_star
))
7556 || ((!NILP (Vtransient_mark_mode
)
7557 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7558 != !NILP (w
->region_showing
)))
7560 struct buffer
*prev
= current_buffer
;
7561 int count
= SPECPDL_INDEX ();
7563 specbind (Qinhibit_menubar_update
, Qt
);
7565 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7566 if (save_match_data
)
7567 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7568 if (NILP (Voverriding_local_map_menu_flag
))
7570 specbind (Qoverriding_terminal_local_map
, Qnil
);
7571 specbind (Qoverriding_local_map
, Qnil
);
7574 /* Run the Lucid hook. */
7575 safe_run_hooks (Qactivate_menubar_hook
);
7577 /* If it has changed current-menubar from previous value,
7578 really recompute the menu-bar from the value. */
7579 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7580 call0 (Qrecompute_lucid_menubar
);
7582 safe_run_hooks (Qmenu_bar_update_hook
);
7583 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7585 /* Redisplay the menu bar in case we changed it. */
7586 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7587 || defined (USE_GTK)
7588 if (FRAME_WINDOW_P (f
)
7589 #if defined (MAC_OS)
7590 /* All frames on Mac OS share the same menubar. So only the
7591 selected frame should be allowed to set it. */
7592 && f
== SELECTED_FRAME ()
7595 set_frame_menubar (f
, 0, 0);
7597 /* On a terminal screen, the menu bar is an ordinary screen
7598 line, and this makes it get updated. */
7599 w
->update_mode_line
= Qt
;
7600 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
7601 /* In the non-toolkit version, the menu bar is an ordinary screen
7602 line, and this makes it get updated. */
7603 w
->update_mode_line
= Qt
;
7604 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
7606 unbind_to (count
, Qnil
);
7607 set_buffer_internal_1 (prev
);
7614 /***********************************************************************
7616 ***********************************************************************/
7618 #ifdef HAVE_WINDOW_SYSTEM
7620 /* Update the tool-bar item list for frame F. This has to be done
7621 before we start to fill in any display lines. Called from
7622 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7623 and restore it here. */
7626 update_tool_bar (f
, save_match_data
)
7628 int save_match_data
;
7631 int do_update
= FRAME_EXTERNAL_TOOL_BAR(f
);
7633 int do_update
= WINDOWP (f
->tool_bar_window
)
7634 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0;
7642 window
= FRAME_SELECTED_WINDOW (f
);
7643 w
= XWINDOW (window
);
7645 /* If the user has switched buffers or windows, we need to
7646 recompute to reflect the new bindings. But we'll
7647 recompute when update_mode_lines is set too; that means
7648 that people can use force-mode-line-update to request
7649 that the menu bar be recomputed. The adverse effect on
7650 the rest of the redisplay algorithm is about the same as
7651 windows_or_buffers_changed anyway. */
7652 if (windows_or_buffers_changed
7653 || !NILP (w
->update_mode_line
)
7654 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7655 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7656 != !NILP (w
->last_had_star
))
7657 || ((!NILP (Vtransient_mark_mode
)
7658 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7659 != !NILP (w
->region_showing
)))
7661 struct buffer
*prev
= current_buffer
;
7662 int count
= SPECPDL_INDEX ();
7664 /* Set current_buffer to the buffer of the selected
7665 window of the frame, so that we get the right local
7667 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7669 /* Save match data, if we must. */
7670 if (save_match_data
)
7671 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7673 /* Make sure that we don't accidentally use bogus keymaps. */
7674 if (NILP (Voverriding_local_map_menu_flag
))
7676 specbind (Qoverriding_terminal_local_map
, Qnil
);
7677 specbind (Qoverriding_local_map
, Qnil
);
7680 /* Build desired tool-bar items from keymaps. */
7682 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7684 /* Redisplay the tool-bar in case we changed it. */
7685 w
->update_mode_line
= Qt
;
7687 unbind_to (count
, Qnil
);
7688 set_buffer_internal_1 (prev
);
7694 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7695 F's desired tool-bar contents. F->tool_bar_items must have
7696 been set up previously by calling prepare_menu_bars. */
7699 build_desired_tool_bar_string (f
)
7702 int i
, size
, size_needed
;
7703 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7704 Lisp_Object image
, plist
, props
;
7706 image
= plist
= props
= Qnil
;
7707 GCPRO3 (image
, plist
, props
);
7709 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7710 Otherwise, make a new string. */
7712 /* The size of the string we might be able to reuse. */
7713 size
= (STRINGP (f
->desired_tool_bar_string
)
7714 ? SCHARS (f
->desired_tool_bar_string
)
7717 /* We need one space in the string for each image. */
7718 size_needed
= f
->n_tool_bar_items
;
7720 /* Reuse f->desired_tool_bar_string, if possible. */
7721 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7722 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7726 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7727 Fremove_text_properties (make_number (0), make_number (size
),
7728 props
, f
->desired_tool_bar_string
);
7731 /* Put a `display' property on the string for the images to display,
7732 put a `menu_item' property on tool-bar items with a value that
7733 is the index of the item in F's tool-bar item vector. */
7734 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7736 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7738 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7739 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7740 int hmargin
, vmargin
, relief
, idx
, end
;
7741 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7743 /* If image is a vector, choose the image according to the
7745 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7746 if (VECTORP (image
))
7750 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7751 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7754 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7755 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7757 xassert (ASIZE (image
) >= idx
);
7758 image
= AREF (image
, idx
);
7763 /* Ignore invalid image specifications. */
7764 if (!valid_image_p (image
))
7767 /* Display the tool-bar button pressed, or depressed. */
7768 plist
= Fcopy_sequence (XCDR (image
));
7770 /* Compute margin and relief to draw. */
7771 relief
= (tool_bar_button_relief
>= 0
7772 ? tool_bar_button_relief
7773 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7774 hmargin
= vmargin
= relief
;
7776 if (INTEGERP (Vtool_bar_button_margin
)
7777 && XINT (Vtool_bar_button_margin
) > 0)
7779 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7780 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7782 else if (CONSP (Vtool_bar_button_margin
))
7784 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7785 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7786 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7788 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7789 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7790 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7793 if (auto_raise_tool_bar_buttons_p
)
7795 /* Add a `:relief' property to the image spec if the item is
7799 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7806 /* If image is selected, display it pressed, i.e. with a
7807 negative relief. If it's not selected, display it with a
7809 plist
= Fplist_put (plist
, QCrelief
,
7811 ? make_number (-relief
)
7812 : make_number (relief
)));
7817 /* Put a margin around the image. */
7818 if (hmargin
|| vmargin
)
7820 if (hmargin
== vmargin
)
7821 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7823 plist
= Fplist_put (plist
, QCmargin
,
7824 Fcons (make_number (hmargin
),
7825 make_number (vmargin
)));
7828 /* If button is not enabled, and we don't have special images
7829 for the disabled state, make the image appear disabled by
7830 applying an appropriate algorithm to it. */
7831 if (!enabled_p
&& idx
< 0)
7832 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7834 /* Put a `display' text property on the string for the image to
7835 display. Put a `menu-item' property on the string that gives
7836 the start of this item's properties in the tool-bar items
7838 image
= Fcons (Qimage
, plist
);
7839 props
= list4 (Qdisplay
, image
,
7840 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7842 /* Let the last image hide all remaining spaces in the tool bar
7843 string. The string can be longer than needed when we reuse a
7845 if (i
+ 1 == f
->n_tool_bar_items
)
7846 end
= SCHARS (f
->desired_tool_bar_string
);
7849 Fadd_text_properties (make_number (i
), make_number (end
),
7850 props
, f
->desired_tool_bar_string
);
7858 /* Display one line of the tool-bar of frame IT->f. */
7861 display_tool_bar_line (it
)
7864 struct glyph_row
*row
= it
->glyph_row
;
7865 int max_x
= it
->last_visible_x
;
7868 prepare_desired_row (row
);
7869 row
->y
= it
->current_y
;
7871 /* Note that this isn't made use of if the face hasn't a box,
7872 so there's no need to check the face here. */
7873 it
->start_of_box_run_p
= 1;
7875 while (it
->current_x
< max_x
)
7877 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7879 /* Get the next display element. */
7880 if (!get_next_display_element (it
))
7883 /* Produce glyphs. */
7884 x_before
= it
->current_x
;
7885 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7886 PRODUCE_GLYPHS (it
);
7888 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7893 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7895 if (x
+ glyph
->pixel_width
> max_x
)
7897 /* Glyph doesn't fit on line. */
7898 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7904 x
+= glyph
->pixel_width
;
7908 /* Stop at line ends. */
7909 if (ITERATOR_AT_END_OF_LINE_P (it
))
7912 set_iterator_to_next (it
, 1);
7917 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7918 extend_face_to_end_of_line (it
);
7919 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7920 last
->right_box_line_p
= 1;
7921 if (last
== row
->glyphs
[TEXT_AREA
])
7922 last
->left_box_line_p
= 1;
7923 compute_line_metrics (it
);
7925 /* If line is empty, make it occupy the rest of the tool-bar. */
7926 if (!row
->displays_text_p
)
7928 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7929 row
->ascent
= row
->phys_ascent
= 0;
7932 row
->full_width_p
= 1;
7933 row
->continued_p
= 0;
7934 row
->truncated_on_left_p
= 0;
7935 row
->truncated_on_right_p
= 0;
7937 it
->current_x
= it
->hpos
= 0;
7938 it
->current_y
+= row
->height
;
7944 /* Value is the number of screen lines needed to make all tool-bar
7945 items of frame F visible. */
7948 tool_bar_lines_needed (f
)
7951 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7954 /* Initialize an iterator for iteration over
7955 F->desired_tool_bar_string in the tool-bar window of frame F. */
7956 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7957 it
.first_visible_x
= 0;
7958 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7959 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7961 while (!ITERATOR_AT_END_P (&it
))
7963 it
.glyph_row
= w
->desired_matrix
->rows
;
7964 clear_glyph_row (it
.glyph_row
);
7965 display_tool_bar_line (&it
);
7968 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7972 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7974 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7983 frame
= selected_frame
;
7985 CHECK_FRAME (frame
);
7988 if (WINDOWP (f
->tool_bar_window
)
7989 || (w
= XWINDOW (f
->tool_bar_window
),
7990 XFASTINT (w
->height
) > 0))
7992 update_tool_bar (f
, 1);
7993 if (f
->n_tool_bar_items
)
7995 build_desired_tool_bar_string (f
);
7996 nlines
= tool_bar_lines_needed (f
);
8000 return make_number (nlines
);
8004 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8005 height should be changed. */
8008 redisplay_tool_bar (f
)
8013 struct glyph_row
*row
;
8014 int change_height_p
= 0;
8017 if (FRAME_EXTERNAL_TOOL_BAR(f
))
8018 update_frame_tool_bar (f
);
8022 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8023 do anything. This means you must start with tool-bar-lines
8024 non-zero to get the auto-sizing effect. Or in other words, you
8025 can turn off tool-bars by specifying tool-bar-lines zero. */
8026 if (!WINDOWP (f
->tool_bar_window
)
8027 || (w
= XWINDOW (f
->tool_bar_window
),
8028 XFASTINT (w
->height
) == 0))
8031 /* Set up an iterator for the tool-bar window. */
8032 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8033 it
.first_visible_x
= 0;
8034 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
8037 /* Build a string that represents the contents of the tool-bar. */
8038 build_desired_tool_bar_string (f
);
8039 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8041 /* Display as many lines as needed to display all tool-bar items. */
8042 while (it
.current_y
< it
.last_visible_y
)
8043 display_tool_bar_line (&it
);
8045 /* It doesn't make much sense to try scrolling in the tool-bar
8046 window, so don't do it. */
8047 w
->desired_matrix
->no_scrolling_p
= 1;
8048 w
->must_be_updated_p
= 1;
8050 if (auto_resize_tool_bars_p
)
8054 /* If we couldn't display everything, change the tool-bar's
8056 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8057 change_height_p
= 1;
8059 /* If there are blank lines at the end, except for a partially
8060 visible blank line at the end that is smaller than
8061 CANON_Y_UNIT, change the tool-bar's height. */
8062 row
= it
.glyph_row
- 1;
8063 if (!row
->displays_text_p
8064 && row
->height
>= CANON_Y_UNIT (f
))
8065 change_height_p
= 1;
8067 /* If row displays tool-bar items, but is partially visible,
8068 change the tool-bar's height. */
8069 if (row
->displays_text_p
8070 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8071 change_height_p
= 1;
8073 /* Resize windows as needed by changing the `tool-bar-lines'
8076 && (nlines
= tool_bar_lines_needed (f
),
8077 nlines
!= XFASTINT (w
->height
)))
8079 extern Lisp_Object Qtool_bar_lines
;
8081 int old_height
= XFASTINT (w
->height
);
8083 XSETFRAME (frame
, f
);
8084 clear_glyph_matrix (w
->desired_matrix
);
8085 Fmodify_frame_parameters (frame
,
8086 Fcons (Fcons (Qtool_bar_lines
,
8087 make_number (nlines
)),
8089 if (XFASTINT (w
->height
) != old_height
)
8090 fonts_changed_p
= 1;
8094 return change_height_p
;
8098 /* Get information about the tool-bar item which is displayed in GLYPH
8099 on frame F. Return in *PROP_IDX the index where tool-bar item
8100 properties start in F->tool_bar_items. Value is zero if
8101 GLYPH doesn't display a tool-bar item. */
8104 tool_bar_item_info (f
, glyph
, prop_idx
)
8106 struct glyph
*glyph
;
8113 /* This function can be called asynchronously, which means we must
8114 exclude any possibility that Fget_text_property signals an
8116 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8117 charpos
= max (0, charpos
);
8119 /* Get the text property `menu-item' at pos. The value of that
8120 property is the start index of this item's properties in
8121 F->tool_bar_items. */
8122 prop
= Fget_text_property (make_number (charpos
),
8123 Qmenu_item
, f
->current_tool_bar_string
);
8124 if (INTEGERP (prop
))
8126 *prop_idx
= XINT (prop
);
8135 #endif /* HAVE_WINDOW_SYSTEM */
8139 /************************************************************************
8140 Horizontal scrolling
8141 ************************************************************************/
8143 static int hscroll_window_tree
P_ ((Lisp_Object
));
8144 static int hscroll_windows
P_ ((Lisp_Object
));
8146 /* For all leaf windows in the window tree rooted at WINDOW, set their
8147 hscroll value so that PT is (i) visible in the window, and (ii) so
8148 that it is not within a certain margin at the window's left and
8149 right border. Value is non-zero if any window's hscroll has been
8153 hscroll_window_tree (window
)
8156 int hscrolled_p
= 0;
8157 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
8158 int hscroll_step_abs
= 0;
8159 double hscroll_step_rel
= 0;
8161 if (hscroll_relative_p
)
8163 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
8164 if (hscroll_step_rel
< 0)
8166 hscroll_relative_p
= 0;
8167 hscroll_step_abs
= 0;
8170 else if (INTEGERP (Vhscroll_step
))
8172 hscroll_step_abs
= XINT (Vhscroll_step
);
8173 if (hscroll_step_abs
< 0)
8174 hscroll_step_abs
= 0;
8177 hscroll_step_abs
= 0;
8179 while (WINDOWP (window
))
8181 struct window
*w
= XWINDOW (window
);
8183 if (WINDOWP (w
->hchild
))
8184 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8185 else if (WINDOWP (w
->vchild
))
8186 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8187 else if (w
->cursor
.vpos
>= 0)
8189 int h_margin
, text_area_x
, text_area_y
;
8190 int text_area_width
, text_area_height
;
8191 struct glyph_row
*current_cursor_row
8192 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8193 struct glyph_row
*desired_cursor_row
8194 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8195 struct glyph_row
*cursor_row
8196 = (desired_cursor_row
->enabled_p
8197 ? desired_cursor_row
8198 : current_cursor_row
);
8200 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8201 &text_area_width
, &text_area_height
);
8203 /* Scroll when cursor is inside this scroll margin. */
8204 h_margin
= hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8206 if ((XFASTINT (w
->hscroll
)
8207 && w
->cursor
.x
<= h_margin
)
8208 || (cursor_row
->enabled_p
8209 && cursor_row
->truncated_on_right_p
8210 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
8214 struct buffer
*saved_current_buffer
;
8218 /* Find point in a display of infinite width. */
8219 saved_current_buffer
= current_buffer
;
8220 current_buffer
= XBUFFER (w
->buffer
);
8222 if (w
== XWINDOW (selected_window
))
8223 pt
= BUF_PT (current_buffer
);
8226 pt
= marker_position (w
->pointm
);
8227 pt
= max (BEGV
, pt
);
8231 /* Move iterator to pt starting at cursor_row->start in
8232 a line with infinite width. */
8233 init_to_row_start (&it
, w
, cursor_row
);
8234 it
.last_visible_x
= INFINITY
;
8235 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8236 current_buffer
= saved_current_buffer
;
8238 /* Position cursor in window. */
8239 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8240 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8241 / CANON_X_UNIT (it
.f
);
8242 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
8244 if (hscroll_relative_p
)
8245 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8248 wanted_x
= text_area_width
8249 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8252 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8256 if (hscroll_relative_p
)
8257 wanted_x
= text_area_width
* hscroll_step_rel
8260 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8263 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8265 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8267 /* Don't call Fset_window_hscroll if value hasn't
8268 changed because it will prevent redisplay
8270 if (XFASTINT (w
->hscroll
) != hscroll
)
8272 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8273 w
->hscroll
= make_number (hscroll
);
8282 /* Value is non-zero if hscroll of any leaf window has been changed. */
8287 /* Set hscroll so that cursor is visible and not inside horizontal
8288 scroll margins for all windows in the tree rooted at WINDOW. See
8289 also hscroll_window_tree above. Value is non-zero if any window's
8290 hscroll has been changed. If it has, desired matrices on the frame
8291 of WINDOW are cleared. */
8294 hscroll_windows (window
)
8299 if (automatic_hscrolling_p
)
8301 hscrolled_p
= hscroll_window_tree (window
);
8303 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8312 /************************************************************************
8314 ************************************************************************/
8316 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8317 to a non-zero value. This is sometimes handy to have in a debugger
8322 /* First and last unchanged row for try_window_id. */
8324 int debug_first_unchanged_at_end_vpos
;
8325 int debug_last_unchanged_at_beg_vpos
;
8327 /* Delta vpos and y. */
8329 int debug_dvpos
, debug_dy
;
8331 /* Delta in characters and bytes for try_window_id. */
8333 int debug_delta
, debug_delta_bytes
;
8335 /* Values of window_end_pos and window_end_vpos at the end of
8338 EMACS_INT debug_end_pos
, debug_end_vpos
;
8340 /* Append a string to W->desired_matrix->method. FMT is a printf
8341 format string. A1...A9 are a supplement for a variable-length
8342 argument list. If trace_redisplay_p is non-zero also printf the
8343 resulting string to stderr. */
8346 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8349 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8352 char *method
= w
->desired_matrix
->method
;
8353 int len
= strlen (method
);
8354 int size
= sizeof w
->desired_matrix
->method
;
8355 int remaining
= size
- len
- 1;
8357 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8358 if (len
&& remaining
)
8364 strncpy (method
+ len
, buffer
, remaining
);
8366 if (trace_redisplay_p
)
8367 fprintf (stderr
, "%p (%s): %s\n",
8369 ((BUFFERP (w
->buffer
)
8370 && STRINGP (XBUFFER (w
->buffer
)->name
))
8371 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
8376 #endif /* GLYPH_DEBUG */
8379 /* Value is non-zero if all changes in window W, which displays
8380 current_buffer, are in the text between START and END. START is a
8381 buffer position, END is given as a distance from Z. Used in
8382 redisplay_internal for display optimization. */
8385 text_outside_line_unchanged_p (w
, start
, end
)
8389 int unchanged_p
= 1;
8391 /* If text or overlays have changed, see where. */
8392 if (XFASTINT (w
->last_modified
) < MODIFF
8393 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8395 /* Gap in the line? */
8396 if (GPT
< start
|| Z
- GPT
< end
)
8399 /* Changes start in front of the line, or end after it? */
8401 && (BEG_UNCHANGED
< start
- 1
8402 || END_UNCHANGED
< end
))
8405 /* If selective display, can't optimize if changes start at the
8406 beginning of the line. */
8408 && INTEGERP (current_buffer
->selective_display
)
8409 && XINT (current_buffer
->selective_display
) > 0
8410 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8413 /* If there are overlays at the start or end of the line, these
8414 may have overlay strings with newlines in them. A change at
8415 START, for instance, may actually concern the display of such
8416 overlay strings as well, and they are displayed on different
8417 lines. So, quickly rule out this case. (For the future, it
8418 might be desirable to implement something more telling than
8419 just BEG/END_UNCHANGED.) */
8422 if (BEG
+ BEG_UNCHANGED
== start
8423 && overlay_touches_p (start
))
8425 if (END_UNCHANGED
== end
8426 && overlay_touches_p (Z
- end
))
8435 /* Do a frame update, taking possible shortcuts into account. This is
8436 the main external entry point for redisplay.
8438 If the last redisplay displayed an echo area message and that message
8439 is no longer requested, we clear the echo area or bring back the
8440 mini-buffer if that is in use. */
8445 redisplay_internal (0);
8449 /* Return 1 if point moved out of or into a composition. Otherwise
8450 return 0. PREV_BUF and PREV_PT are the last point buffer and
8451 position. BUF and PT are the current point buffer and position. */
8454 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8455 struct buffer
*prev_buf
, *buf
;
8462 XSETBUFFER (buffer
, buf
);
8463 /* Check a composition at the last point if point moved within the
8465 if (prev_buf
== buf
)
8468 /* Point didn't move. */
8471 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8472 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8473 && COMPOSITION_VALID_P (start
, end
, prop
)
8474 && start
< prev_pt
&& end
> prev_pt
)
8475 /* The last point was within the composition. Return 1 iff
8476 point moved out of the composition. */
8477 return (pt
<= start
|| pt
>= end
);
8480 /* Check a composition at the current point. */
8481 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8482 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8483 && COMPOSITION_VALID_P (start
, end
, prop
)
8484 && start
< pt
&& end
> pt
);
8488 /* Reconsider the setting of B->clip_changed which is displayed
8492 reconsider_clip_changes (w
, b
)
8497 && !NILP (w
->window_end_valid
)
8498 && w
->current_matrix
->buffer
== b
8499 && w
->current_matrix
->zv
== BUF_ZV (b
)
8500 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8501 b
->clip_changed
= 0;
8503 /* If display wasn't paused, and W is not a tool bar window, see if
8504 point has been moved into or out of a composition. In that case,
8505 we set b->clip_changed to 1 to force updating the screen. If
8506 b->clip_changed has already been set to 1, we can skip this
8508 if (!b
->clip_changed
8509 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8513 if (w
== XWINDOW (selected_window
))
8514 pt
= BUF_PT (current_buffer
);
8516 pt
= marker_position (w
->pointm
);
8518 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8519 || pt
!= XINT (w
->last_point
))
8520 && check_point_in_composition (w
->current_matrix
->buffer
,
8521 XINT (w
->last_point
),
8522 XBUFFER (w
->buffer
), pt
))
8523 b
->clip_changed
= 1;
8527 #define STOP_POLLING \
8528 do { if (! polling_stopped_here) stop_polling (); \
8529 polling_stopped_here = 1; } while (0)
8531 #define RESUME_POLLING \
8532 do { if (polling_stopped_here) start_polling (); \
8533 polling_stopped_here = 0; } while (0)
8536 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8537 response to any user action; therefore, we should preserve the echo
8538 area. (Actually, our caller does that job.) Perhaps in the future
8539 avoid recentering windows if it is not necessary; currently that
8540 causes some problems. */
8543 redisplay_internal (preserve_echo_area
)
8544 int preserve_echo_area
;
8546 struct window
*w
= XWINDOW (selected_window
);
8547 struct frame
*f
= XFRAME (w
->frame
);
8549 int must_finish
= 0;
8550 struct text_pos tlbufpos
, tlendpos
;
8551 int number_of_visible_frames
;
8553 struct frame
*sf
= SELECTED_FRAME ();
8554 int polling_stopped_here
= 0;
8556 /* Non-zero means redisplay has to consider all windows on all
8557 frames. Zero means, only selected_window is considered. */
8558 int consider_all_windows_p
;
8560 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8562 /* No redisplay if running in batch mode or frame is not yet fully
8563 initialized, or redisplay is explicitly turned off by setting
8564 Vinhibit_redisplay. */
8566 || !NILP (Vinhibit_redisplay
)
8567 || !f
->glyphs_initialized_p
)
8570 /* The flag redisplay_performed_directly_p is set by
8571 direct_output_for_insert when it already did the whole screen
8572 update necessary. */
8573 if (redisplay_performed_directly_p
)
8575 redisplay_performed_directly_p
= 0;
8576 if (!hscroll_windows (selected_window
))
8580 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
8581 if (popup_activated ())
8585 /* I don't think this happens but let's be paranoid. */
8589 /* Record a function that resets redisplaying_p to its old value
8590 when we leave this function. */
8591 count
= SPECPDL_INDEX ();
8592 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8594 specbind (Qinhibit_free_realized_faces
, Qnil
);
8598 reconsider_clip_changes (w
, current_buffer
);
8600 /* If new fonts have been loaded that make a glyph matrix adjustment
8601 necessary, do it. */
8602 if (fonts_changed_p
)
8604 adjust_glyphs (NULL
);
8605 ++windows_or_buffers_changed
;
8606 fonts_changed_p
= 0;
8609 /* If face_change_count is non-zero, init_iterator will free all
8610 realized faces, which includes the faces referenced from current
8611 matrices. So, we can't reuse current matrices in this case. */
8612 if (face_change_count
)
8613 ++windows_or_buffers_changed
;
8615 if (! FRAME_WINDOW_P (sf
)
8616 && previous_terminal_frame
!= sf
)
8618 /* Since frames on an ASCII terminal share the same display
8619 area, displaying a different frame means redisplay the whole
8621 windows_or_buffers_changed
++;
8622 SET_FRAME_GARBAGED (sf
);
8623 XSETFRAME (Vterminal_frame
, sf
);
8625 previous_terminal_frame
= sf
;
8627 /* Set the visible flags for all frames. Do this before checking
8628 for resized or garbaged frames; they want to know if their frames
8629 are visible. See the comment in frame.h for
8630 FRAME_SAMPLE_VISIBILITY. */
8632 Lisp_Object tail
, frame
;
8634 number_of_visible_frames
= 0;
8636 FOR_EACH_FRAME (tail
, frame
)
8638 struct frame
*f
= XFRAME (frame
);
8640 FRAME_SAMPLE_VISIBILITY (f
);
8641 if (FRAME_VISIBLE_P (f
))
8642 ++number_of_visible_frames
;
8643 clear_desired_matrices (f
);
8647 /* Notice any pending interrupt request to change frame size. */
8648 do_pending_window_change (1);
8650 /* Clear frames marked as garbaged. */
8652 clear_garbaged_frames ();
8654 /* Build menubar and tool-bar items. */
8655 prepare_menu_bars ();
8657 if (windows_or_buffers_changed
)
8658 update_mode_lines
++;
8660 /* Detect case that we need to write or remove a star in the mode line. */
8661 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8663 w
->update_mode_line
= Qt
;
8664 if (buffer_shared
> 1)
8665 update_mode_lines
++;
8668 /* If %c is in the mode line, update it if needed. */
8669 if (!NILP (w
->column_number_displayed
)
8670 /* This alternative quickly identifies a common case
8671 where no change is needed. */
8672 && !(PT
== XFASTINT (w
->last_point
)
8673 && XFASTINT (w
->last_modified
) >= MODIFF
8674 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8675 && (XFASTINT (w
->column_number_displayed
)
8676 != (int) current_column ())) /* iftc */
8677 w
->update_mode_line
= Qt
;
8679 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8681 /* The variable buffer_shared is set in redisplay_window and
8682 indicates that we redisplay a buffer in different windows. See
8684 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
8685 || cursor_type_changed
);
8687 /* If specs for an arrow have changed, do thorough redisplay
8688 to ensure we remove any arrow that should no longer exist. */
8689 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8690 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8691 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8693 /* Normally the message* functions will have already displayed and
8694 updated the echo area, but the frame may have been trashed, or
8695 the update may have been preempted, so display the echo area
8696 again here. Checking message_cleared_p captures the case that
8697 the echo area should be cleared. */
8698 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8699 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8700 || (message_cleared_p
8701 && minibuf_level
== 0
8702 /* If the mini-window is currently selected, this means the
8703 echo-area doesn't show through. */
8704 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8706 int window_height_changed_p
= echo_area_display (0);
8709 /* If we don't display the current message, don't clear the
8710 message_cleared_p flag, because, if we did, we wouldn't clear
8711 the echo area in the next redisplay which doesn't preserve
8713 if (!display_last_displayed_message_p
)
8714 message_cleared_p
= 0;
8716 if (fonts_changed_p
)
8718 else if (window_height_changed_p
)
8720 consider_all_windows_p
= 1;
8721 ++update_mode_lines
;
8722 ++windows_or_buffers_changed
;
8724 /* If window configuration was changed, frames may have been
8725 marked garbaged. Clear them or we will experience
8726 surprises wrt scrolling. */
8728 clear_garbaged_frames ();
8731 else if (EQ (selected_window
, minibuf_window
)
8732 && (current_buffer
->clip_changed
8733 || XFASTINT (w
->last_modified
) < MODIFF
8734 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8735 && resize_mini_window (w
, 0))
8737 /* Resized active mini-window to fit the size of what it is
8738 showing if its contents might have changed. */
8740 consider_all_windows_p
= 1;
8741 ++windows_or_buffers_changed
;
8742 ++update_mode_lines
;
8744 /* If window configuration was changed, frames may have been
8745 marked garbaged. Clear them or we will experience
8746 surprises wrt scrolling. */
8748 clear_garbaged_frames ();
8752 /* If showing the region, and mark has changed, we must redisplay
8753 the whole window. The assignment to this_line_start_pos prevents
8754 the optimization directly below this if-statement. */
8755 if (((!NILP (Vtransient_mark_mode
)
8756 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8757 != !NILP (w
->region_showing
))
8758 || (!NILP (w
->region_showing
)
8759 && !EQ (w
->region_showing
,
8760 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8761 CHARPOS (this_line_start_pos
) = 0;
8763 /* Optimize the case that only the line containing the cursor in the
8764 selected window has changed. Variables starting with this_ are
8765 set in display_line and record information about the line
8766 containing the cursor. */
8767 tlbufpos
= this_line_start_pos
;
8768 tlendpos
= this_line_end_pos
;
8769 if (!consider_all_windows_p
8770 && CHARPOS (tlbufpos
) > 0
8771 && NILP (w
->update_mode_line
)
8772 && !current_buffer
->clip_changed
8773 && !current_buffer
->prevent_redisplay_optimizations_p
8774 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8775 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8776 /* Make sure recorded data applies to current buffer, etc. */
8777 && this_line_buffer
== current_buffer
8778 && current_buffer
== XBUFFER (w
->buffer
)
8779 && NILP (w
->force_start
)
8780 && NILP (w
->optional_new_start
)
8781 /* Point must be on the line that we have info recorded about. */
8782 && PT
>= CHARPOS (tlbufpos
)
8783 && PT
<= Z
- CHARPOS (tlendpos
)
8784 /* All text outside that line, including its final newline,
8785 must be unchanged */
8786 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8787 CHARPOS (tlendpos
)))
8789 if (CHARPOS (tlbufpos
) > BEGV
8790 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8791 && (CHARPOS (tlbufpos
) == ZV
8792 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8793 /* Former continuation line has disappeared by becoming empty */
8795 else if (XFASTINT (w
->last_modified
) < MODIFF
8796 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8797 || MINI_WINDOW_P (w
))
8799 /* We have to handle the case of continuation around a
8800 wide-column character (See the comment in indent.c around
8803 For instance, in the following case:
8805 -------- Insert --------
8806 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8807 J_I_ ==> J_I_ `^^' are cursors.
8811 As we have to redraw the line above, we should goto cancel. */
8814 int line_height_before
= this_line_pixel_height
;
8816 /* Note that start_display will handle the case that the
8817 line starting at tlbufpos is a continuation lines. */
8818 start_display (&it
, w
, tlbufpos
);
8820 /* Implementation note: It this still necessary? */
8821 if (it
.current_x
!= this_line_start_x
)
8824 TRACE ((stderr
, "trying display optimization 1\n"));
8825 w
->cursor
.vpos
= -1;
8826 overlay_arrow_seen
= 0;
8827 it
.vpos
= this_line_vpos
;
8828 it
.current_y
= this_line_y
;
8829 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8832 /* If line contains point, is not continued,
8833 and ends at same distance from eob as before, we win */
8834 if (w
->cursor
.vpos
>= 0
8835 /* Line is not continued, otherwise this_line_start_pos
8836 would have been set to 0 in display_line. */
8837 && CHARPOS (this_line_start_pos
)
8838 /* Line ends as before. */
8839 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8840 /* Line has same height as before. Otherwise other lines
8841 would have to be shifted up or down. */
8842 && this_line_pixel_height
== line_height_before
)
8844 /* If this is not the window's last line, we must adjust
8845 the charstarts of the lines below. */
8846 if (it
.current_y
< it
.last_visible_y
)
8848 struct glyph_row
*row
8849 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8850 int delta
, delta_bytes
;
8852 if (Z
- CHARPOS (tlendpos
) == ZV
)
8854 /* This line ends at end of (accessible part of)
8855 buffer. There is no newline to count. */
8857 - CHARPOS (tlendpos
)
8858 - MATRIX_ROW_START_CHARPOS (row
));
8859 delta_bytes
= (Z_BYTE
8860 - BYTEPOS (tlendpos
)
8861 - MATRIX_ROW_START_BYTEPOS (row
));
8865 /* This line ends in a newline. Must take
8866 account of the newline and the rest of the
8867 text that follows. */
8869 - CHARPOS (tlendpos
)
8870 - MATRIX_ROW_START_CHARPOS (row
));
8871 delta_bytes
= (Z_BYTE
8872 - BYTEPOS (tlendpos
)
8873 - MATRIX_ROW_START_BYTEPOS (row
));
8876 increment_matrix_positions (w
->current_matrix
,
8878 w
->current_matrix
->nrows
,
8879 delta
, delta_bytes
);
8882 /* If this row displays text now but previously didn't,
8883 or vice versa, w->window_end_vpos may have to be
8885 if ((it
.glyph_row
- 1)->displays_text_p
)
8887 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8888 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8890 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8891 && this_line_vpos
> 0)
8892 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8893 w
->window_end_valid
= Qnil
;
8895 /* Update hint: No need to try to scroll in update_window. */
8896 w
->desired_matrix
->no_scrolling_p
= 1;
8899 *w
->desired_matrix
->method
= 0;
8900 debug_method_add (w
, "optimization 1");
8907 else if (/* Cursor position hasn't changed. */
8908 PT
== XFASTINT (w
->last_point
)
8909 /* Make sure the cursor was last displayed
8910 in this window. Otherwise we have to reposition it. */
8911 && 0 <= w
->cursor
.vpos
8912 && XINT (w
->height
) > w
->cursor
.vpos
)
8916 do_pending_window_change (1);
8918 /* We used to always goto end_of_redisplay here, but this
8919 isn't enough if we have a blinking cursor. */
8920 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8921 goto end_of_redisplay
;
8925 /* If highlighting the region, or if the cursor is in the echo area,
8926 then we can't just move the cursor. */
8927 else if (! (!NILP (Vtransient_mark_mode
)
8928 && !NILP (current_buffer
->mark_active
))
8929 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8930 || highlight_nonselected_windows
)
8931 && NILP (w
->region_showing
)
8932 && NILP (Vshow_trailing_whitespace
)
8933 && !cursor_in_echo_area
)
8936 struct glyph_row
*row
;
8938 /* Skip from tlbufpos to PT and see where it is. Note that
8939 PT may be in invisible text. If so, we will end at the
8940 next visible position. */
8941 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8942 NULL
, DEFAULT_FACE_ID
);
8943 it
.current_x
= this_line_start_x
;
8944 it
.current_y
= this_line_y
;
8945 it
.vpos
= this_line_vpos
;
8947 /* The call to move_it_to stops in front of PT, but
8948 moves over before-strings. */
8949 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8951 if (it
.vpos
== this_line_vpos
8952 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8955 xassert (this_line_vpos
== it
.vpos
);
8956 xassert (this_line_y
== it
.current_y
);
8957 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8959 *w
->desired_matrix
->method
= 0;
8960 debug_method_add (w
, "optimization 3");
8969 /* Text changed drastically or point moved off of line. */
8970 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8973 CHARPOS (this_line_start_pos
) = 0;
8974 consider_all_windows_p
|= buffer_shared
> 1;
8975 ++clear_face_cache_count
;
8978 /* Build desired matrices, and update the display. If
8979 consider_all_windows_p is non-zero, do it for all windows on all
8980 frames. Otherwise do it for selected_window, only. */
8982 if (consider_all_windows_p
)
8984 Lisp_Object tail
, frame
;
8985 int i
, n
= 0, size
= 50;
8986 struct frame
**updated
8987 = (struct frame
**) alloca (size
* sizeof *updated
);
8989 /* Clear the face cache eventually. */
8990 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8992 clear_face_cache (0);
8993 clear_face_cache_count
= 0;
8996 /* Recompute # windows showing selected buffer. This will be
8997 incremented each time such a window is displayed. */
9000 FOR_EACH_FRAME (tail
, frame
)
9002 struct frame
*f
= XFRAME (frame
);
9004 if (FRAME_WINDOW_P (f
) || f
== sf
)
9006 #ifdef HAVE_WINDOW_SYSTEM
9007 if (clear_face_cache_count
% 50 == 0
9008 && FRAME_WINDOW_P (f
))
9009 clear_image_cache (f
, 0);
9010 #endif /* HAVE_WINDOW_SYSTEM */
9012 /* Mark all the scroll bars to be removed; we'll redeem
9013 the ones we want when we redisplay their windows. */
9014 if (condemn_scroll_bars_hook
)
9015 condemn_scroll_bars_hook (f
);
9017 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
9018 redisplay_windows (FRAME_ROOT_WINDOW (f
));
9020 /* Any scroll bars which redisplay_windows should have
9021 nuked should now go away. */
9022 if (judge_scroll_bars_hook
)
9023 judge_scroll_bars_hook (f
);
9025 /* If fonts changed, display again. */
9026 /* ??? rms: I suspect it is a mistake to jump all the way
9027 back to retry here. It should just retry this frame. */
9028 if (fonts_changed_p
)
9031 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
9033 /* See if we have to hscroll. */
9034 if (hscroll_windows (f
->root_window
))
9037 /* Prevent various kinds of signals during display
9038 update. stdio is not robust about handling
9039 signals, which can cause an apparent I/O
9041 if (interrupt_input
)
9045 /* Update the display. */
9046 set_window_update_flags (XWINDOW (f
->root_window
), 1);
9047 pause
|= update_frame (f
, 0, 0);
9053 int nbytes
= size
* sizeof *updated
;
9054 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
9055 bcopy (updated
, p
, nbytes
);
9064 /* Do the mark_window_display_accurate after all windows have
9065 been redisplayed because this call resets flags in buffers
9066 which are needed for proper redisplay. */
9067 for (i
= 0; i
< n
; ++i
)
9069 struct frame
*f
= updated
[i
];
9070 mark_window_display_accurate (f
->root_window
, 1);
9071 if (frame_up_to_date_hook
)
9072 frame_up_to_date_hook (f
);
9075 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9077 Lisp_Object mini_window
;
9078 struct frame
*mini_frame
;
9080 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9081 /* Use list_of_error, not Qerror, so that
9082 we catch only errors and don't run the debugger. */
9083 internal_condition_case_1 (redisplay_window_1
, selected_window
,
9085 redisplay_window_error
);
9087 /* Compare desired and current matrices, perform output. */
9090 /* If fonts changed, display again. */
9091 if (fonts_changed_p
)
9094 /* Prevent various kinds of signals during display update.
9095 stdio is not robust about handling signals,
9096 which can cause an apparent I/O error. */
9097 if (interrupt_input
)
9101 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9103 if (hscroll_windows (selected_window
))
9106 XWINDOW (selected_window
)->must_be_updated_p
= 1;
9107 pause
= update_frame (sf
, 0, 0);
9110 /* We may have called echo_area_display at the top of this
9111 function. If the echo area is on another frame, that may
9112 have put text on a frame other than the selected one, so the
9113 above call to update_frame would not have caught it. Catch
9115 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9116 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9118 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
9120 XWINDOW (mini_window
)->must_be_updated_p
= 1;
9121 pause
|= update_frame (mini_frame
, 0, 0);
9122 if (!pause
&& hscroll_windows (mini_window
))
9127 /* If display was paused because of pending input, make sure we do a
9128 thorough update the next time. */
9131 /* Prevent the optimization at the beginning of
9132 redisplay_internal that tries a single-line update of the
9133 line containing the cursor in the selected window. */
9134 CHARPOS (this_line_start_pos
) = 0;
9136 /* Let the overlay arrow be updated the next time. */
9137 if (!NILP (last_arrow_position
))
9139 last_arrow_position
= Qt
;
9140 last_arrow_string
= Qt
;
9143 /* If we pause after scrolling, some rows in the current
9144 matrices of some windows are not valid. */
9145 if (!WINDOW_FULL_WIDTH_P (w
)
9146 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9147 update_mode_lines
= 1;
9151 if (!consider_all_windows_p
)
9153 /* This has already been done above if
9154 consider_all_windows_p is set. */
9155 mark_window_display_accurate_1 (w
, 1);
9157 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9158 last_arrow_string
= Voverlay_arrow_string
;
9160 if (frame_up_to_date_hook
!= 0)
9161 frame_up_to_date_hook (sf
);
9164 update_mode_lines
= 0;
9165 windows_or_buffers_changed
= 0;
9166 cursor_type_changed
= 0;
9169 /* Start SIGIO interrupts coming again. Having them off during the
9170 code above makes it less likely one will discard output, but not
9171 impossible, since there might be stuff in the system buffer here.
9172 But it is much hairier to try to do anything about that. */
9173 if (interrupt_input
)
9177 /* If a frame has become visible which was not before, redisplay
9178 again, so that we display it. Expose events for such a frame
9179 (which it gets when becoming visible) don't call the parts of
9180 redisplay constructing glyphs, so simply exposing a frame won't
9181 display anything in this case. So, we have to display these
9182 frames here explicitly. */
9185 Lisp_Object tail
, frame
;
9188 FOR_EACH_FRAME (tail
, frame
)
9190 int this_is_visible
= 0;
9192 if (XFRAME (frame
)->visible
)
9193 this_is_visible
= 1;
9194 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9195 if (XFRAME (frame
)->visible
)
9196 this_is_visible
= 1;
9198 if (this_is_visible
)
9202 if (new_count
!= number_of_visible_frames
)
9203 windows_or_buffers_changed
++;
9206 /* Change frame size now if a change is pending. */
9207 do_pending_window_change (1);
9209 /* If we just did a pending size change, or have additional
9210 visible frames, redisplay again. */
9211 if (windows_or_buffers_changed
&& !pause
)
9215 unbind_to (count
, Qnil
);
9220 /* Redisplay, but leave alone any recent echo area message unless
9221 another message has been requested in its place.
9223 This is useful in situations where you need to redisplay but no
9224 user action has occurred, making it inappropriate for the message
9225 area to be cleared. See tracking_off and
9226 wait_reading_process_input for examples of these situations.
9228 FROM_WHERE is an integer saying from where this function was
9229 called. This is useful for debugging. */
9232 redisplay_preserve_echo_area (from_where
)
9235 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9237 if (!NILP (echo_area_buffer
[1]))
9239 /* We have a previously displayed message, but no current
9240 message. Redisplay the previous message. */
9241 display_last_displayed_message_p
= 1;
9242 redisplay_internal (1);
9243 display_last_displayed_message_p
= 0;
9246 redisplay_internal (1);
9250 /* Function registered with record_unwind_protect in
9251 redisplay_internal. Reset redisplaying_p to the value it had
9252 before redisplay_internal was called, and clear
9253 prevent_freeing_realized_faces_p. */
9256 unwind_redisplay (old_redisplaying_p
)
9257 Lisp_Object old_redisplaying_p
;
9259 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9264 /* Mark the display of window W as accurate or inaccurate. If
9265 ACCURATE_P is non-zero mark display of W as accurate. If
9266 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9267 redisplay_internal is called. */
9270 mark_window_display_accurate_1 (w
, accurate_p
)
9274 if (BUFFERP (w
->buffer
))
9276 struct buffer
*b
= XBUFFER (w
->buffer
);
9279 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9280 w
->last_overlay_modified
9281 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9283 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9287 b
->clip_changed
= 0;
9288 b
->prevent_redisplay_optimizations_p
= 0;
9290 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9291 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9292 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9293 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9295 w
->current_matrix
->buffer
= b
;
9296 w
->current_matrix
->begv
= BUF_BEGV (b
);
9297 w
->current_matrix
->zv
= BUF_ZV (b
);
9299 w
->last_cursor
= w
->cursor
;
9300 w
->last_cursor_off_p
= w
->cursor_off_p
;
9302 if (w
== XWINDOW (selected_window
))
9303 w
->last_point
= make_number (BUF_PT (b
));
9305 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9311 w
->window_end_valid
= w
->buffer
;
9312 #if 0 /* This is incorrect with variable-height lines. */
9313 xassert (XINT (w
->window_end_vpos
)
9315 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9317 w
->update_mode_line
= Qnil
;
9322 /* Mark the display of windows in the window tree rooted at WINDOW as
9323 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9324 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9325 be redisplayed the next time redisplay_internal is called. */
9328 mark_window_display_accurate (window
, accurate_p
)
9334 for (; !NILP (window
); window
= w
->next
)
9336 w
= XWINDOW (window
);
9337 mark_window_display_accurate_1 (w
, accurate_p
);
9339 if (!NILP (w
->vchild
))
9340 mark_window_display_accurate (w
->vchild
, accurate_p
);
9341 if (!NILP (w
->hchild
))
9342 mark_window_display_accurate (w
->hchild
, accurate_p
);
9347 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9348 last_arrow_string
= Voverlay_arrow_string
;
9352 /* Force a thorough redisplay the next time by setting
9353 last_arrow_position and last_arrow_string to t, which is
9354 unequal to any useful value of Voverlay_arrow_... */
9355 last_arrow_position
= Qt
;
9356 last_arrow_string
= Qt
;
9361 /* Return value in display table DP (Lisp_Char_Table *) for character
9362 C. Since a display table doesn't have any parent, we don't have to
9363 follow parent. Do not call this function directly but use the
9364 macro DISP_CHAR_VECTOR. */
9367 disp_char_vector (dp
, c
)
9368 struct Lisp_Char_Table
*dp
;
9374 if (SINGLE_BYTE_CHAR_P (c
))
9375 return (dp
->contents
[c
]);
9377 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9380 else if (code
[2] < 32)
9383 /* Here, the possible range of code[0] (== charset ID) is
9384 128..max_charset. Since the top level char table contains data
9385 for multibyte characters after 256th element, we must increment
9386 code[0] by 128 to get a correct index. */
9388 code
[3] = -1; /* anchor */
9390 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9392 val
= dp
->contents
[code
[i
]];
9393 if (!SUB_CHAR_TABLE_P (val
))
9394 return (NILP (val
) ? dp
->defalt
: val
);
9397 /* Here, val is a sub char table. We return the default value of
9399 return (dp
->defalt
);
9404 /***********************************************************************
9406 ***********************************************************************/
9408 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9411 redisplay_windows (window
)
9414 while (!NILP (window
))
9416 struct window
*w
= XWINDOW (window
);
9418 if (!NILP (w
->hchild
))
9419 redisplay_windows (w
->hchild
);
9420 else if (!NILP (w
->vchild
))
9421 redisplay_windows (w
->vchild
);
9424 displayed_buffer
= XBUFFER (w
->buffer
);
9425 /* Use list_of_error, not Qerror, so that
9426 we catch only errors and don't run the debugger. */
9427 internal_condition_case_1 (redisplay_window_0
, window
,
9429 redisplay_window_error
);
9437 redisplay_window_error ()
9439 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9444 redisplay_window_0 (window
)
9447 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9448 redisplay_window (window
, 0);
9453 redisplay_window_1 (window
)
9456 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9457 redisplay_window (window
, 1);
9462 /* Increment GLYPH until it reaches END or CONDITION fails while
9463 adding (GLYPH)->pixel_width to X. */
9465 #define SKIP_GLYPHS(glyph, end, x, condition) \
9468 (x) += (glyph)->pixel_width; \
9471 while ((glyph) < (end) && (condition))
9474 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9475 DELTA is the number of bytes by which positions recorded in ROW
9476 differ from current buffer positions. */
9479 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9481 struct glyph_row
*row
;
9482 struct glyph_matrix
*matrix
;
9483 int delta
, delta_bytes
, dy
, dvpos
;
9485 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9486 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9487 /* The first glyph that starts a sequence of glyphs from string. */
9488 struct glyph
*string_start
;
9489 /* The X coordinate of string_start. */
9491 /* The last known character position. */
9492 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
9493 /* The last known character position before string_start. */
9494 int string_before_pos
;
9496 int pt_old
= PT
- delta
;
9498 /* Skip over glyphs not having an object at the start of the row.
9499 These are special glyphs like truncation marks on terminal
9501 if (row
->displays_text_p
)
9503 && INTEGERP (glyph
->object
)
9504 && glyph
->charpos
< 0)
9506 x
+= glyph
->pixel_width
;
9510 string_start
= NULL
;
9512 && !INTEGERP (glyph
->object
)
9513 && (!BUFFERP (glyph
->object
)
9514 || (last_pos
= glyph
->charpos
) < pt_old
))
9516 if (! STRINGP (glyph
->object
))
9518 string_start
= NULL
;
9519 x
+= glyph
->pixel_width
;
9524 string_before_pos
= last_pos
;
9525 string_start
= glyph
;
9527 /* Skip all glyphs from string. */
9528 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
9533 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
9535 /* We may have skipped over point because the previous glyphs
9536 are from string. As there's no easy way to know the
9537 character position of the current glyph, find the correct
9538 glyph on point by scanning from string_start again. */
9543 limit
= make_number (pt_old
+ 1);
9545 glyph
= string_start
;
9547 string
= glyph
->object
;
9548 pos
= string_buffer_position (w
, string
, string_before_pos
);
9549 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
9550 because we always put cursor after overlay strings. */
9551 while (pos
== 0 && glyph
< end
)
9553 string
= glyph
->object
;
9554 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
9556 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
9561 pos
= XINT (Fnext_single_char_property_change
9562 (make_number (pos
), Qdisplay
, Qnil
, limit
));
9565 /* Skip glyphs from the same string. */
9566 string
= glyph
->object
;
9567 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
9568 /* Skip glyphs from an overlay. */
9570 && ! string_buffer_position (w
, glyph
->object
, pos
))
9572 string
= glyph
->object
;
9573 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
9578 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9580 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9581 w
->cursor
.y
= row
->y
+ dy
;
9583 if (w
== XWINDOW (selected_window
))
9585 if (!row
->continued_p
9586 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9589 this_line_buffer
= XBUFFER (w
->buffer
);
9591 CHARPOS (this_line_start_pos
)
9592 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9593 BYTEPOS (this_line_start_pos
)
9594 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9596 CHARPOS (this_line_end_pos
)
9597 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9598 BYTEPOS (this_line_end_pos
)
9599 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9601 this_line_y
= w
->cursor
.y
;
9602 this_line_pixel_height
= row
->height
;
9603 this_line_vpos
= w
->cursor
.vpos
;
9604 this_line_start_x
= row
->x
;
9607 CHARPOS (this_line_start_pos
) = 0;
9612 /* Run window scroll functions, if any, for WINDOW with new window
9613 start STARTP. Sets the window start of WINDOW to that position.
9615 We assume that the window's buffer is really current. */
9617 static INLINE
struct text_pos
9618 run_window_scroll_functions (window
, startp
)
9620 struct text_pos startp
;
9622 struct window
*w
= XWINDOW (window
);
9623 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9625 if (current_buffer
!= XBUFFER (w
->buffer
))
9628 if (!NILP (Vwindow_scroll_functions
))
9630 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9631 make_number (CHARPOS (startp
)));
9632 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9633 /* In case the hook functions switch buffers. */
9634 if (current_buffer
!= XBUFFER (w
->buffer
))
9635 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9642 /* Make sure the line containing the cursor is fully visible.
9643 A value of 1 means there is nothing to be done.
9644 (Either the line is fully visible, or it cannot be made so,
9646 A value of 0 means the caller should do scrolling
9647 as if point had gone off the screen. */
9650 make_cursor_line_fully_visible (w
)
9653 struct glyph_matrix
*matrix
;
9654 struct glyph_row
*row
;
9657 /* It's not always possible to find the cursor, e.g, when a window
9658 is full of overlay strings. Don't do anything in that case. */
9659 if (w
->cursor
.vpos
< 0)
9662 matrix
= w
->desired_matrix
;
9663 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9665 /* If the cursor row is not partially visible, there's nothing to do. */
9666 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9669 /* If the row the cursor is in is taller than the window's height,
9670 it's not clear what to do, so do nothing. */
9671 window_height
= window_box_height (w
);
9672 if (row
->height
>= window_height
)
9678 /* This code used to try to scroll the window just enough to make
9679 the line visible. It returned 0 to say that the caller should
9680 allocate larger glyph matrices. */
9682 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9684 int dy
= row
->height
- row
->visible_height
;
9687 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9689 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9691 int dy
= - (row
->height
- row
->visible_height
);
9694 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9697 /* When we change the cursor y-position of the selected window,
9698 change this_line_y as well so that the display optimization for
9699 the cursor line of the selected window in redisplay_internal uses
9700 the correct y-position. */
9701 if (w
== XWINDOW (selected_window
))
9702 this_line_y
= w
->cursor
.y
;
9704 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9705 redisplay with larger matrices. */
9706 if (matrix
->nrows
< required_matrix_height (w
))
9708 fonts_changed_p
= 1;
9717 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9718 non-zero means only WINDOW is redisplayed in redisplay_internal.
9719 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9720 in redisplay_window to bring a partially visible line into view in
9721 the case that only the cursor has moved.
9723 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
9724 last screen line's vertical height extends past the end of the screen.
9728 1 if scrolling succeeded
9730 0 if scrolling didn't find point.
9732 -1 if new fonts have been loaded so that we must interrupt
9733 redisplay, adjust glyph matrices, and try again. */
9739 SCROLLING_NEED_LARGER_MATRICES
9743 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9744 scroll_step
, temp_scroll_step
, last_line_misfit
)
9746 int just_this_one_p
;
9747 EMACS_INT scroll_conservatively
, scroll_step
;
9748 int temp_scroll_step
;
9749 int last_line_misfit
;
9751 struct window
*w
= XWINDOW (window
);
9752 struct frame
*f
= XFRAME (w
->frame
);
9753 struct text_pos scroll_margin_pos
;
9754 struct text_pos pos
;
9755 struct text_pos startp
;
9757 Lisp_Object window_end
;
9758 int this_scroll_margin
;
9762 int amount_to_scroll
= 0;
9763 Lisp_Object aggressive
;
9765 int end_scroll_margin
;
9768 debug_method_add (w
, "try_scrolling");
9771 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9773 /* Compute scroll margin height in pixels. We scroll when point is
9774 within this distance from the top or bottom of the window. */
9775 if (scroll_margin
> 0)
9777 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9778 this_scroll_margin
*= CANON_Y_UNIT (f
);
9781 this_scroll_margin
= 0;
9783 /* Compute how much we should try to scroll maximally to bring point
9785 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9786 scroll_max
= max (scroll_step
,
9787 max (scroll_conservatively
, temp_scroll_step
));
9788 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9789 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9790 /* We're trying to scroll because of aggressive scrolling
9791 but no scroll_step is set. Choose an arbitrary one. Maybe
9792 there should be a variable for this. */
9796 scroll_max
*= CANON_Y_UNIT (f
);
9798 /* Decide whether we have to scroll down. Start at the window end
9799 and move this_scroll_margin up to find the position of the scroll
9801 window_end
= Fwindow_end (window
, Qt
);
9805 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9806 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9808 end_scroll_margin
= this_scroll_margin
+ !!last_line_misfit
;
9809 if (end_scroll_margin
)
9811 start_display (&it
, w
, scroll_margin_pos
);
9812 move_it_vertically (&it
, - end_scroll_margin
);
9813 scroll_margin_pos
= it
.current
.pos
;
9816 if (PT
>= CHARPOS (scroll_margin_pos
))
9820 /* Point is in the scroll margin at the bottom of the window, or
9821 below. Compute a new window start that makes point visible. */
9823 /* Compute the distance from the scroll margin to PT.
9824 Give up if the distance is greater than scroll_max. */
9825 start_display (&it
, w
, scroll_margin_pos
);
9827 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9828 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9830 /* To make point visible, we have to move the window start
9831 down so that the line the cursor is in is visible, which
9832 means we have to add in the height of the cursor line. */
9833 dy
= line_bottom_y (&it
) - y0
;
9835 if (dy
> scroll_max
)
9836 return SCROLLING_FAILED
;
9838 /* Move the window start down. If scrolling conservatively,
9839 move it just enough down to make point visible. If
9840 scroll_step is set, move it down by scroll_step. */
9841 start_display (&it
, w
, startp
);
9843 if (scroll_conservatively
)
9844 /* Set AMOUNT_TO_SCROLL to at least one line,
9845 and at most scroll_conservatively lines. */
9847 = min (max (dy
, CANON_Y_UNIT (f
)),
9848 CANON_Y_UNIT (f
) * scroll_conservatively
);
9849 else if (scroll_step
|| temp_scroll_step
)
9850 amount_to_scroll
= scroll_max
;
9853 aggressive
= current_buffer
->scroll_up_aggressively
;
9854 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9855 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9856 if (NUMBERP (aggressive
))
9857 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9860 if (amount_to_scroll
<= 0)
9861 return SCROLLING_FAILED
;
9863 /* If moving by amount_to_scroll leaves STARTP unchanged,
9864 move it down one screen line. */
9866 move_it_vertically (&it
, amount_to_scroll
);
9867 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
9868 move_it_by_lines (&it
, 1, 1);
9869 startp
= it
.current
.pos
;
9873 /* See if point is inside the scroll margin at the top of the
9875 scroll_margin_pos
= startp
;
9876 if (this_scroll_margin
)
9878 start_display (&it
, w
, startp
);
9879 move_it_vertically (&it
, this_scroll_margin
);
9880 scroll_margin_pos
= it
.current
.pos
;
9883 if (PT
< CHARPOS (scroll_margin_pos
))
9885 /* Point is in the scroll margin at the top of the window or
9886 above what is displayed in the window. */
9889 /* Compute the vertical distance from PT to the scroll
9890 margin position. Give up if distance is greater than
9892 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9893 start_display (&it
, w
, pos
);
9895 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9896 it
.last_visible_y
, -1,
9897 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9898 dy
= it
.current_y
- y0
;
9899 if (dy
> scroll_max
)
9900 return SCROLLING_FAILED
;
9902 /* Compute new window start. */
9903 start_display (&it
, w
, startp
);
9905 if (scroll_conservatively
)
9907 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9908 else if (scroll_step
|| temp_scroll_step
)
9909 amount_to_scroll
= scroll_max
;
9912 aggressive
= current_buffer
->scroll_down_aggressively
;
9913 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9914 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9915 if (NUMBERP (aggressive
))
9916 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9919 if (amount_to_scroll
<= 0)
9920 return SCROLLING_FAILED
;
9922 move_it_vertically (&it
, - amount_to_scroll
);
9923 startp
= it
.current
.pos
;
9927 /* Run window scroll functions. */
9928 startp
= run_window_scroll_functions (window
, startp
);
9930 /* Display the window. Give up if new fonts are loaded, or if point
9932 if (!try_window (window
, startp
))
9933 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9934 else if (w
->cursor
.vpos
< 0)
9936 clear_glyph_matrix (w
->desired_matrix
);
9937 rc
= SCROLLING_FAILED
;
9941 /* Maybe forget recorded base line for line number display. */
9942 if (!just_this_one_p
9943 || current_buffer
->clip_changed
9944 || BEG_UNCHANGED
< CHARPOS (startp
))
9945 w
->base_line_number
= Qnil
;
9947 /* If cursor ends up on a partially visible line,
9948 treat that as being off the bottom of the screen. */
9949 if (! make_cursor_line_fully_visible (w
))
9951 clear_glyph_matrix (w
->desired_matrix
);
9952 last_line_misfit
= 1;
9955 rc
= SCROLLING_SUCCESS
;
9962 /* Compute a suitable window start for window W if display of W starts
9963 on a continuation line. Value is non-zero if a new window start
9966 The new window start will be computed, based on W's width, starting
9967 from the start of the continued line. It is the start of the
9968 screen line with the minimum distance from the old start W->start. */
9971 compute_window_start_on_continuation_line (w
)
9974 struct text_pos pos
, start_pos
;
9975 int window_start_changed_p
= 0;
9977 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9979 /* If window start is on a continuation line... Window start may be
9980 < BEGV in case there's invisible text at the start of the
9981 buffer (M-x rmail, for example). */
9982 if (CHARPOS (start_pos
) > BEGV
9983 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9986 struct glyph_row
*row
;
9988 /* Handle the case that the window start is out of range. */
9989 if (CHARPOS (start_pos
) < BEGV
)
9990 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9991 else if (CHARPOS (start_pos
) > ZV
)
9992 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9994 /* Find the start of the continued line. This should be fast
9995 because scan_buffer is fast (newline cache). */
9996 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9997 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9998 row
, DEFAULT_FACE_ID
);
9999 reseat_at_previous_visible_line_start (&it
);
10001 /* If the line start is "too far" away from the window start,
10002 say it takes too much time to compute a new window start. */
10003 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
10004 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
10006 int min_distance
, distance
;
10008 /* Move forward by display lines to find the new window
10009 start. If window width was enlarged, the new start can
10010 be expected to be > the old start. If window width was
10011 decreased, the new window start will be < the old start.
10012 So, we're looking for the display line start with the
10013 minimum distance from the old window start. */
10014 pos
= it
.current
.pos
;
10015 min_distance
= INFINITY
;
10016 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
10017 distance
< min_distance
)
10019 min_distance
= distance
;
10020 pos
= it
.current
.pos
;
10021 move_it_by_lines (&it
, 1, 0);
10024 /* Set the window start there. */
10025 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
10026 window_start_changed_p
= 1;
10030 return window_start_changed_p
;
10034 /* Try cursor movement in case text has not changed in window WINDOW,
10035 with window start STARTP. Value is
10037 CURSOR_MOVEMENT_SUCCESS if successful
10039 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
10041 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
10042 display. *SCROLL_STEP is set to 1, under certain circumstances, if
10043 we want to scroll as if scroll-step were set to 1. See the code.
10045 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
10046 which case we have to abort this redisplay, and adjust matrices
10051 CURSOR_MOVEMENT_SUCCESS
,
10052 CURSOR_MOVEMENT_CANNOT_BE_USED
,
10053 CURSOR_MOVEMENT_MUST_SCROLL
,
10054 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
10058 try_cursor_movement (window
, startp
, scroll_step
)
10059 Lisp_Object window
;
10060 struct text_pos startp
;
10063 struct window
*w
= XWINDOW (window
);
10064 struct frame
*f
= XFRAME (w
->frame
);
10065 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
10068 if (inhibit_try_cursor_movement
)
10072 /* Handle case where text has not changed, only point, and it has
10073 not moved off the frame. */
10074 if (/* Point may be in this window. */
10075 PT
>= CHARPOS (startp
)
10076 /* Selective display hasn't changed. */
10077 && !current_buffer
->clip_changed
10078 /* Function force-mode-line-update is used to force a thorough
10079 redisplay. It sets either windows_or_buffers_changed or
10080 update_mode_lines. So don't take a shortcut here for these
10082 && !update_mode_lines
10083 && !windows_or_buffers_changed
10084 && !cursor_type_changed
10085 /* Can't use this case if highlighting a region. When a
10086 region exists, cursor movement has to do more than just
10088 && !(!NILP (Vtransient_mark_mode
)
10089 && !NILP (current_buffer
->mark_active
))
10090 && NILP (w
->region_showing
)
10091 && NILP (Vshow_trailing_whitespace
)
10092 /* Right after splitting windows, last_point may be nil. */
10093 && INTEGERP (w
->last_point
)
10094 /* This code is not used for mini-buffer for the sake of the case
10095 of redisplaying to replace an echo area message; since in
10096 that case the mini-buffer contents per se are usually
10097 unchanged. This code is of no real use in the mini-buffer
10098 since the handling of this_line_start_pos, etc., in redisplay
10099 handles the same cases. */
10100 && !EQ (window
, minibuf_window
)
10101 /* When splitting windows or for new windows, it happens that
10102 redisplay is called with a nil window_end_vpos or one being
10103 larger than the window. This should really be fixed in
10104 window.c. I don't have this on my list, now, so we do
10105 approximately the same as the old redisplay code. --gerd. */
10106 && INTEGERP (w
->window_end_vpos
)
10107 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
10108 && (FRAME_WINDOW_P (f
)
10109 || !MARKERP (Voverlay_arrow_position
)
10110 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
10112 int this_scroll_margin
;
10113 struct glyph_row
*row
= NULL
;
10116 debug_method_add (w
, "cursor movement");
10119 /* Scroll if point within this distance from the top or bottom
10120 of the window. This is a pixel value. */
10121 this_scroll_margin
= max (0, scroll_margin
);
10122 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
10123 this_scroll_margin
*= CANON_Y_UNIT (f
);
10125 /* Start with the row the cursor was displayed during the last
10126 not paused redisplay. Give up if that row is not valid. */
10127 if (w
->last_cursor
.vpos
< 0
10128 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
10129 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10132 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
10133 if (row
->mode_line_p
)
10135 if (!row
->enabled_p
)
10136 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10139 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
10142 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
10144 if (PT
> XFASTINT (w
->last_point
))
10146 /* Point has moved forward. */
10147 while (MATRIX_ROW_END_CHARPOS (row
) < PT
10148 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10150 xassert (row
->enabled_p
);
10154 /* The end position of a row equals the start position
10155 of the next row. If PT is there, we would rather
10156 display it in the next line. */
10157 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10158 && MATRIX_ROW_END_CHARPOS (row
) == PT
10159 && !cursor_row_p (w
, row
))
10162 /* If within the scroll margin, scroll. Note that
10163 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
10164 the next line would be drawn, and that
10165 this_scroll_margin can be zero. */
10166 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
10167 || PT
> MATRIX_ROW_END_CHARPOS (row
)
10168 /* Line is completely visible last line in window
10169 and PT is to be set in the next line. */
10170 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
10171 && PT
== MATRIX_ROW_END_CHARPOS (row
)
10172 && !row
->ends_at_zv_p
10173 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
10176 else if (PT
< XFASTINT (w
->last_point
))
10178 /* Cursor has to be moved backward. Note that PT >=
10179 CHARPOS (startp) because of the outer
10181 while (!row
->mode_line_p
10182 && (MATRIX_ROW_START_CHARPOS (row
) > PT
10183 || (MATRIX_ROW_START_CHARPOS (row
) == PT
10184 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
10185 && (row
->y
> this_scroll_margin
10186 || CHARPOS (startp
) == BEGV
))
10188 xassert (row
->enabled_p
);
10192 /* Consider the following case: Window starts at BEGV,
10193 there is invisible, intangible text at BEGV, so that
10194 display starts at some point START > BEGV. It can
10195 happen that we are called with PT somewhere between
10196 BEGV and START. Try to handle that case. */
10197 if (row
< w
->current_matrix
->rows
10198 || row
->mode_line_p
)
10200 row
= w
->current_matrix
->rows
;
10201 if (row
->mode_line_p
)
10205 /* Due to newlines in overlay strings, we may have to
10206 skip forward over overlay strings. */
10207 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10208 && MATRIX_ROW_END_CHARPOS (row
) == PT
10209 && !cursor_row_p (w
, row
))
10212 /* If within the scroll margin, scroll. */
10213 if (row
->y
< this_scroll_margin
10214 && CHARPOS (startp
) != BEGV
)
10218 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
10219 || PT
> MATRIX_ROW_END_CHARPOS (row
))
10221 /* if PT is not in the glyph row, give up. */
10222 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10224 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10226 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
10227 && !row
->ends_at_zv_p
10228 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
10229 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10230 else if (row
->height
> window_box_height (w
))
10232 /* If we end up in a partially visible line, let's
10233 make it fully visible, except when it's taller
10234 than the window, in which case we can't do much
10237 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10241 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10242 if (!make_cursor_line_fully_visible (w
))
10243 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10245 rc
= CURSOR_MOVEMENT_SUCCESS
;
10249 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10252 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10253 rc
= CURSOR_MOVEMENT_SUCCESS
;
10262 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10263 selected_window is redisplayed.
10265 We can return without actually redisplaying the window if
10266 fonts_changed_p is nonzero. In that case, redisplay_internal will
10270 redisplay_window (window
, just_this_one_p
)
10271 Lisp_Object window
;
10272 int just_this_one_p
;
10274 struct window
*w
= XWINDOW (window
);
10275 struct frame
*f
= XFRAME (w
->frame
);
10276 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10277 struct buffer
*old
= current_buffer
;
10278 struct text_pos lpoint
, opoint
, startp
;
10279 int update_mode_line
;
10282 /* Record it now because it's overwritten. */
10283 int current_matrix_up_to_date_p
= 0;
10284 /* This is less strict than current_matrix_up_to_date_p.
10285 It indictes that the buffer contents and narrowing are unchanged. */
10286 int buffer_unchanged_p
= 0;
10287 int temp_scroll_step
= 0;
10288 int count
= SPECPDL_INDEX ();
10290 int centering_position
;
10291 int last_line_misfit
= 0;
10293 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10296 /* W must be a leaf window here. */
10297 xassert (!NILP (w
->buffer
));
10299 *w
->desired_matrix
->method
= 0;
10302 specbind (Qinhibit_point_motion_hooks
, Qt
);
10304 reconsider_clip_changes (w
, buffer
);
10306 /* Has the mode line to be updated? */
10307 update_mode_line
= (!NILP (w
->update_mode_line
)
10308 || update_mode_lines
10309 || buffer
->clip_changed
10310 || buffer
->prevent_redisplay_optimizations_p
);
10312 if (MINI_WINDOW_P (w
))
10314 if (w
== XWINDOW (echo_area_window
)
10315 && !NILP (echo_area_buffer
[0]))
10317 if (update_mode_line
)
10318 /* We may have to update a tty frame's menu bar or a
10319 tool-bar. Example `M-x C-h C-h C-g'. */
10320 goto finish_menu_bars
;
10322 /* We've already displayed the echo area glyphs in this window. */
10323 goto finish_scroll_bars
;
10325 else if ((w
!= XWINDOW (minibuf_window
)
10326 || minibuf_level
== 0)
10327 /* Quail displays non-mini buffers in minibuffer window.
10328 In that case, redisplay the window normally. */
10329 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
10331 /* W is a mini-buffer window, but it's not active, so clear
10333 int yb
= window_text_bottom_y (w
);
10334 struct glyph_row
*row
;
10337 for (y
= 0, row
= w
->desired_matrix
->rows
;
10339 y
+= row
->height
, ++row
)
10340 blank_row (w
, row
, y
);
10341 goto finish_scroll_bars
;
10344 clear_glyph_matrix (w
->desired_matrix
);
10347 /* Otherwise set up data on this window; select its buffer and point
10349 /* Really select the buffer, for the sake of buffer-local
10351 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10352 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10354 current_matrix_up_to_date_p
10355 = (!NILP (w
->window_end_valid
)
10356 && !current_buffer
->clip_changed
10357 && !current_buffer
->prevent_redisplay_optimizations_p
10358 && XFASTINT (w
->last_modified
) >= MODIFF
10359 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10362 = (!NILP (w
->window_end_valid
)
10363 && !current_buffer
->clip_changed
10364 && XFASTINT (w
->last_modified
) >= MODIFF
10365 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10367 /* When windows_or_buffers_changed is non-zero, we can't rely on
10368 the window end being valid, so set it to nil there. */
10369 if (windows_or_buffers_changed
)
10371 /* If window starts on a continuation line, maybe adjust the
10372 window start in case the window's width changed. */
10373 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10374 compute_window_start_on_continuation_line (w
);
10376 w
->window_end_valid
= Qnil
;
10379 /* Some sanity checks. */
10380 CHECK_WINDOW_END (w
);
10381 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10383 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10386 /* If %c is in mode line, update it if needed. */
10387 if (!NILP (w
->column_number_displayed
)
10388 /* This alternative quickly identifies a common case
10389 where no change is needed. */
10390 && !(PT
== XFASTINT (w
->last_point
)
10391 && XFASTINT (w
->last_modified
) >= MODIFF
10392 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10393 && (XFASTINT (w
->column_number_displayed
)
10394 != (int) current_column ())) /* iftc */
10395 update_mode_line
= 1;
10397 /* Count number of windows showing the selected buffer. An indirect
10398 buffer counts as its base buffer. */
10399 if (!just_this_one_p
)
10401 struct buffer
*current_base
, *window_base
;
10402 current_base
= current_buffer
;
10403 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10404 if (current_base
->base_buffer
)
10405 current_base
= current_base
->base_buffer
;
10406 if (window_base
->base_buffer
)
10407 window_base
= window_base
->base_buffer
;
10408 if (current_base
== window_base
)
10412 /* Point refers normally to the selected window. For any other
10413 window, set up appropriate value. */
10414 if (!EQ (window
, selected_window
))
10416 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10417 int new_pt_byte
= marker_byte_position (w
->pointm
);
10421 new_pt_byte
= BEGV_BYTE
;
10422 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10424 else if (new_pt
> (ZV
- 1))
10427 new_pt_byte
= ZV_BYTE
;
10428 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10431 /* We don't use SET_PT so that the point-motion hooks don't run. */
10432 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10435 /* If any of the character widths specified in the display table
10436 have changed, invalidate the width run cache. It's true that
10437 this may be a bit late to catch such changes, but the rest of
10438 redisplay goes (non-fatally) haywire when the display table is
10439 changed, so why should we worry about doing any better? */
10440 if (current_buffer
->width_run_cache
)
10442 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10444 if (! disptab_matches_widthtab (disptab
,
10445 XVECTOR (current_buffer
->width_table
)))
10447 invalidate_region_cache (current_buffer
,
10448 current_buffer
->width_run_cache
,
10450 recompute_width_table (current_buffer
, disptab
);
10454 /* If window-start is screwed up, choose a new one. */
10455 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10458 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10460 /* If someone specified a new starting point but did not insist,
10461 check whether it can be used. */
10462 if (!NILP (w
->optional_new_start
)
10463 && CHARPOS (startp
) >= BEGV
10464 && CHARPOS (startp
) <= ZV
)
10466 w
->optional_new_start
= Qnil
;
10467 start_display (&it
, w
, startp
);
10468 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10469 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10470 if (IT_CHARPOS (it
) == PT
)
10471 w
->force_start
= Qt
;
10474 /* Handle case where place to start displaying has been specified,
10475 unless the specified location is outside the accessible range. */
10476 if (!NILP (w
->force_start
)
10477 || w
->frozen_window_start_p
)
10479 /* We set this later on if we have to adjust point. */
10482 w
->force_start
= Qnil
;
10484 w
->window_end_valid
= Qnil
;
10486 /* Forget any recorded base line for line number display. */
10487 if (!buffer_unchanged_p
)
10488 w
->base_line_number
= Qnil
;
10490 /* Redisplay the mode line. Select the buffer properly for that.
10491 Also, run the hook window-scroll-functions
10492 because we have scrolled. */
10493 /* Note, we do this after clearing force_start because
10494 if there's an error, it is better to forget about force_start
10495 than to get into an infinite loop calling the hook functions
10496 and having them get more errors. */
10497 if (!update_mode_line
10498 || ! NILP (Vwindow_scroll_functions
))
10500 update_mode_line
= 1;
10501 w
->update_mode_line
= Qt
;
10502 startp
= run_window_scroll_functions (window
, startp
);
10505 w
->last_modified
= make_number (0);
10506 w
->last_overlay_modified
= make_number (0);
10507 if (CHARPOS (startp
) < BEGV
)
10508 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10509 else if (CHARPOS (startp
) > ZV
)
10510 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10512 /* Redisplay, then check if cursor has been set during the
10513 redisplay. Give up if new fonts were loaded. */
10514 if (!try_window (window
, startp
))
10516 w
->force_start
= Qt
;
10517 clear_glyph_matrix (w
->desired_matrix
);
10518 goto need_larger_matrices
;
10521 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10523 /* If point does not appear, try to move point so it does
10524 appear. The desired matrix has been built above, so we
10525 can use it here. */
10526 new_vpos
= window_box_height (w
) / 2;
10529 if (!make_cursor_line_fully_visible (w
))
10531 /* Point does appear, but on a line partly visible at end of window.
10532 Move it back to a fully-visible line. */
10533 new_vpos
= window_box_height (w
);
10536 /* If we need to move point for either of the above reasons,
10537 now actually do it. */
10540 struct glyph_row
*row
;
10542 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10543 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
10546 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10547 MATRIX_ROW_START_BYTEPOS (row
));
10549 if (w
!= XWINDOW (selected_window
))
10550 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10551 else if (current_buffer
== old
)
10552 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10554 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10556 /* If we are highlighting the region, then we just changed
10557 the region, so redisplay to show it. */
10558 if (!NILP (Vtransient_mark_mode
)
10559 && !NILP (current_buffer
->mark_active
))
10561 clear_glyph_matrix (w
->desired_matrix
);
10562 if (!try_window (window
, startp
))
10563 goto need_larger_matrices
;
10568 debug_method_add (w
, "forced window start");
10573 /* Handle case where text has not changed, only point, and it has
10574 not moved off the frame, and we are not retrying after hscroll.
10575 (current_matrix_up_to_date_p is nonzero when retrying.) */
10576 if (current_matrix_up_to_date_p
10577 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10578 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10582 case CURSOR_MOVEMENT_SUCCESS
:
10585 #if 0 /* try_cursor_movement never returns this value. */
10586 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10587 goto need_larger_matrices
;
10590 case CURSOR_MOVEMENT_MUST_SCROLL
:
10591 goto try_to_scroll
;
10597 /* If current starting point was originally the beginning of a line
10598 but no longer is, find a new starting point. */
10599 else if (!NILP (w
->start_at_line_beg
)
10600 && !(CHARPOS (startp
) <= BEGV
10601 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10604 debug_method_add (w
, "recenter 1");
10609 /* Try scrolling with try_window_id. Value is > 0 if update has
10610 been done, it is -1 if we know that the same window start will
10611 not work. It is 0 if unsuccessful for some other reason. */
10612 else if ((tem
= try_window_id (w
)) != 0)
10615 debug_method_add (w
, "try_window_id %d", tem
);
10618 if (fonts_changed_p
)
10619 goto need_larger_matrices
;
10623 /* Otherwise try_window_id has returned -1 which means that we
10624 don't want the alternative below this comment to execute. */
10626 else if (CHARPOS (startp
) >= BEGV
10627 && CHARPOS (startp
) <= ZV
10628 && PT
>= CHARPOS (startp
)
10629 && (CHARPOS (startp
) < ZV
10630 /* Avoid starting at end of buffer. */
10631 || CHARPOS (startp
) == BEGV
10632 || (XFASTINT (w
->last_modified
) >= MODIFF
10633 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10636 debug_method_add (w
, "same window start");
10639 /* Try to redisplay starting at same place as before.
10640 If point has not moved off frame, accept the results. */
10641 if (!current_matrix_up_to_date_p
10642 /* Don't use try_window_reusing_current_matrix in this case
10643 because a window scroll function can have changed the
10645 || !NILP (Vwindow_scroll_functions
)
10646 || MINI_WINDOW_P (w
)
10647 || !try_window_reusing_current_matrix (w
))
10649 IF_DEBUG (debug_method_add (w
, "1"));
10650 try_window (window
, startp
);
10653 if (fonts_changed_p
)
10654 goto need_larger_matrices
;
10656 if (w
->cursor
.vpos
>= 0)
10658 if (!just_this_one_p
10659 || current_buffer
->clip_changed
10660 || BEG_UNCHANGED
< CHARPOS (startp
))
10661 /* Forget any recorded base line for line number display. */
10662 w
->base_line_number
= Qnil
;
10664 if (!make_cursor_line_fully_visible (w
))
10666 clear_glyph_matrix (w
->desired_matrix
);
10667 last_line_misfit
= 1;
10669 /* Drop through and scroll. */
10674 clear_glyph_matrix (w
->desired_matrix
);
10679 w
->last_modified
= make_number (0);
10680 w
->last_overlay_modified
= make_number (0);
10682 /* Redisplay the mode line. Select the buffer properly for that. */
10683 if (!update_mode_line
)
10685 update_mode_line
= 1;
10686 w
->update_mode_line
= Qt
;
10689 /* Try to scroll by specified few lines. */
10690 if ((scroll_conservatively
10692 || temp_scroll_step
10693 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10694 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10695 && !current_buffer
->clip_changed
10696 && CHARPOS (startp
) >= BEGV
10697 && CHARPOS (startp
) <= ZV
)
10699 /* The function returns -1 if new fonts were loaded, 1 if
10700 successful, 0 if not successful. */
10701 int rc
= try_scrolling (window
, just_this_one_p
,
10702 scroll_conservatively
,
10704 temp_scroll_step
, last_line_misfit
);
10707 case SCROLLING_SUCCESS
:
10710 case SCROLLING_NEED_LARGER_MATRICES
:
10711 goto need_larger_matrices
;
10713 case SCROLLING_FAILED
:
10721 /* Finally, just choose place to start which centers point */
10724 centering_position
= window_box_height (w
) / 2;
10727 /* Jump here with centering_position already set to 0. */
10730 debug_method_add (w
, "recenter");
10733 /* w->vscroll = 0; */
10735 /* Forget any previously recorded base line for line number display. */
10736 if (!buffer_unchanged_p
)
10737 w
->base_line_number
= Qnil
;
10739 /* Move backward half the height of the window. */
10740 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10741 it
.current_y
= it
.last_visible_y
;
10742 move_it_vertically_backward (&it
, centering_position
);
10743 xassert (IT_CHARPOS (it
) >= BEGV
);
10745 /* The function move_it_vertically_backward may move over more
10746 than the specified y-distance. If it->w is small, e.g. a
10747 mini-buffer window, we may end up in front of the window's
10748 display area. Start displaying at the start of the line
10749 containing PT in this case. */
10750 if (it
.current_y
<= 0)
10752 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10753 move_it_vertically (&it
, 0);
10754 xassert (IT_CHARPOS (it
) <= PT
);
10758 it
.current_x
= it
.hpos
= 0;
10760 /* Set startp here explicitly in case that helps avoid an infinite loop
10761 in case the window-scroll-functions functions get errors. */
10762 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10764 /* Run scroll hooks. */
10765 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10767 /* Redisplay the window. */
10768 if (!current_matrix_up_to_date_p
10769 || windows_or_buffers_changed
10770 || cursor_type_changed
10771 /* Don't use try_window_reusing_current_matrix in this case
10772 because it can have changed the buffer. */
10773 || !NILP (Vwindow_scroll_functions
)
10774 || !just_this_one_p
10775 || MINI_WINDOW_P (w
)
10776 || !try_window_reusing_current_matrix (w
))
10777 try_window (window
, startp
);
10779 /* If new fonts have been loaded (due to fontsets), give up. We
10780 have to start a new redisplay since we need to re-adjust glyph
10782 if (fonts_changed_p
)
10783 goto need_larger_matrices
;
10785 /* If cursor did not appear assume that the middle of the window is
10786 in the first line of the window. Do it again with the next line.
10787 (Imagine a window of height 100, displaying two lines of height
10788 60. Moving back 50 from it->last_visible_y will end in the first
10790 if (w
->cursor
.vpos
< 0)
10792 if (!NILP (w
->window_end_valid
)
10793 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10795 clear_glyph_matrix (w
->desired_matrix
);
10796 move_it_by_lines (&it
, 1, 0);
10797 try_window (window
, it
.current
.pos
);
10799 else if (PT
< IT_CHARPOS (it
))
10801 clear_glyph_matrix (w
->desired_matrix
);
10802 move_it_by_lines (&it
, -1, 0);
10803 try_window (window
, it
.current
.pos
);
10807 /* Not much we can do about it. */
10811 /* Consider the following case: Window starts at BEGV, there is
10812 invisible, intangible text at BEGV, so that display starts at
10813 some point START > BEGV. It can happen that we are called with
10814 PT somewhere between BEGV and START. Try to handle that case. */
10815 if (w
->cursor
.vpos
< 0)
10817 struct glyph_row
*row
= w
->current_matrix
->rows
;
10818 if (row
->mode_line_p
)
10820 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10823 if (!make_cursor_line_fully_visible (w
))
10825 /* If vscroll is enabled, disable it and try again. */
10829 clear_glyph_matrix (w
->desired_matrix
);
10833 /* If centering point failed to make the whole line visible,
10834 put point at the top instead. That has to make the whole line
10835 visible, if it can be done. */
10836 centering_position
= 0;
10842 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10843 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10844 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10847 /* Display the mode line, if we must. */
10848 if ((update_mode_line
10849 /* If window not full width, must redo its mode line
10850 if (a) the window to its side is being redone and
10851 (b) we do a frame-based redisplay. This is a consequence
10852 of how inverted lines are drawn in frame-based redisplay. */
10853 || (!just_this_one_p
10854 && !FRAME_WINDOW_P (f
)
10855 && !WINDOW_FULL_WIDTH_P (w
))
10856 /* Line number to display. */
10857 || INTEGERP (w
->base_line_pos
)
10858 /* Column number is displayed and different from the one displayed. */
10859 || (!NILP (w
->column_number_displayed
)
10860 && (XFASTINT (w
->column_number_displayed
)
10861 != (int) current_column ()))) /* iftc */
10862 /* This means that the window has a mode line. */
10863 && (WINDOW_WANTS_MODELINE_P (w
)
10864 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10866 display_mode_lines (w
);
10868 /* If mode line height has changed, arrange for a thorough
10869 immediate redisplay using the correct mode line height. */
10870 if (WINDOW_WANTS_MODELINE_P (w
)
10871 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10873 fonts_changed_p
= 1;
10874 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10875 = DESIRED_MODE_LINE_HEIGHT (w
);
10878 /* If top line height has changed, arrange for a thorough
10879 immediate redisplay using the correct mode line height. */
10880 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10881 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10883 fonts_changed_p
= 1;
10884 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10885 = DESIRED_HEADER_LINE_HEIGHT (w
);
10888 if (fonts_changed_p
)
10889 goto need_larger_matrices
;
10892 if (!line_number_displayed
10893 && !BUFFERP (w
->base_line_pos
))
10895 w
->base_line_pos
= Qnil
;
10896 w
->base_line_number
= Qnil
;
10901 /* When we reach a frame's selected window, redo the frame's menu bar. */
10902 if (update_mode_line
10903 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10905 int redisplay_menu_p
= 0;
10906 int redisplay_tool_bar_p
= 0;
10908 if (FRAME_WINDOW_P (f
))
10910 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
10911 || defined (USE_GTK)
10912 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10914 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10918 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10920 if (redisplay_menu_p
)
10921 display_menu_bar (w
);
10923 #ifdef HAVE_WINDOW_SYSTEM
10925 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
10927 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
10928 && (FRAME_TOOL_BAR_LINES (f
) > 0
10929 || auto_resize_tool_bars_p
);
10933 if (redisplay_tool_bar_p
)
10934 redisplay_tool_bar (f
);
10938 /* We go to this label, with fonts_changed_p nonzero,
10939 if it is necessary to try again using larger glyph matrices.
10940 We have to redeem the scroll bar even in this case,
10941 because the loop in redisplay_internal expects that. */
10942 need_larger_matrices
:
10944 finish_scroll_bars
:
10946 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10948 int start
, end
, whole
;
10950 /* Calculate the start and end positions for the current window.
10951 At some point, it would be nice to choose between scrollbars
10952 which reflect the whole buffer size, with special markers
10953 indicating narrowing, and scrollbars which reflect only the
10956 Note that mini-buffers sometimes aren't displaying any text. */
10957 if (!MINI_WINDOW_P (w
)
10958 || (w
== XWINDOW (minibuf_window
)
10959 && NILP (echo_area_buffer
[0])))
10962 start
= marker_position (w
->start
) - BEGV
;
10963 /* I don't think this is guaranteed to be right. For the
10964 moment, we'll pretend it is. */
10965 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10969 if (whole
< (end
- start
))
10970 whole
= end
- start
;
10973 start
= end
= whole
= 0;
10975 /* Indicate what this scroll bar ought to be displaying now. */
10976 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10978 /* Note that we actually used the scroll bar attached to this
10979 window, so it shouldn't be deleted at the end of redisplay. */
10980 redeem_scroll_bar_hook (w
);
10983 /* Restore current_buffer and value of point in it. */
10984 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10985 set_buffer_internal_1 (old
);
10986 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10988 unbind_to (count
, Qnil
);
10992 /* Build the complete desired matrix of WINDOW with a window start
10993 buffer position POS. Value is non-zero if successful. It is zero
10994 if fonts were loaded during redisplay which makes re-adjusting
10995 glyph matrices necessary. */
10998 try_window (window
, pos
)
10999 Lisp_Object window
;
11000 struct text_pos pos
;
11002 struct window
*w
= XWINDOW (window
);
11004 struct glyph_row
*last_text_row
= NULL
;
11006 /* Make POS the new window start. */
11007 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
11009 /* Mark cursor position as unknown. No overlay arrow seen. */
11010 w
->cursor
.vpos
= -1;
11011 overlay_arrow_seen
= 0;
11013 /* Initialize iterator and info to start at POS. */
11014 start_display (&it
, w
, pos
);
11016 /* Display all lines of W. */
11017 while (it
.current_y
< it
.last_visible_y
)
11019 if (display_line (&it
))
11020 last_text_row
= it
.glyph_row
- 1;
11021 if (fonts_changed_p
)
11025 /* If bottom moved off end of frame, change mode line percentage. */
11026 if (XFASTINT (w
->window_end_pos
) <= 0
11027 && Z
!= IT_CHARPOS (it
))
11028 w
->update_mode_line
= Qt
;
11030 /* Set window_end_pos to the offset of the last character displayed
11031 on the window from the end of current_buffer. Set
11032 window_end_vpos to its row number. */
11035 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
11036 w
->window_end_bytepos
11037 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11039 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11041 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11042 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
11043 ->displays_text_p
);
11047 w
->window_end_bytepos
= 0;
11048 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
11051 /* But that is not valid info until redisplay finishes. */
11052 w
->window_end_valid
= Qnil
;
11058 /************************************************************************
11059 Window redisplay reusing current matrix when buffer has not changed
11060 ************************************************************************/
11062 /* Try redisplay of window W showing an unchanged buffer with a
11063 different window start than the last time it was displayed by
11064 reusing its current matrix. Value is non-zero if successful.
11065 W->start is the new window start. */
11068 try_window_reusing_current_matrix (w
)
11071 struct frame
*f
= XFRAME (w
->frame
);
11072 struct glyph_row
*row
, *bottom_row
;
11075 struct text_pos start
, new_start
;
11076 int nrows_scrolled
, i
;
11077 struct glyph_row
*last_text_row
;
11078 struct glyph_row
*last_reused_text_row
;
11079 struct glyph_row
*start_row
;
11080 int start_vpos
, min_y
, max_y
;
11083 if (inhibit_try_window_reusing
)
11087 if (/* This function doesn't handle terminal frames. */
11088 !FRAME_WINDOW_P (f
)
11089 /* Don't try to reuse the display if windows have been split
11091 || windows_or_buffers_changed
11092 || cursor_type_changed
)
11095 /* Can't do this if region may have changed. */
11096 if ((!NILP (Vtransient_mark_mode
)
11097 && !NILP (current_buffer
->mark_active
))
11098 || !NILP (w
->region_showing
)
11099 || !NILP (Vshow_trailing_whitespace
))
11102 /* If top-line visibility has changed, give up. */
11103 if (WINDOW_WANTS_HEADER_LINE_P (w
)
11104 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
11107 /* Give up if old or new display is scrolled vertically. We could
11108 make this function handle this, but right now it doesn't. */
11109 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11110 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
11113 /* The variable new_start now holds the new window start. The old
11114 start `start' can be determined from the current matrix. */
11115 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
11116 start
= start_row
->start
.pos
;
11117 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
11119 /* Clear the desired matrix for the display below. */
11120 clear_glyph_matrix (w
->desired_matrix
);
11122 if (CHARPOS (new_start
) <= CHARPOS (start
))
11126 /* Don't use this method if the display starts with an ellipsis
11127 displayed for invisible text. It's not easy to handle that case
11128 below, and it's certainly not worth the effort since this is
11129 not a frequent case. */
11130 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
11133 IF_DEBUG (debug_method_add (w
, "twu1"));
11135 /* Display up to a row that can be reused. The variable
11136 last_text_row is set to the last row displayed that displays
11137 text. Note that it.vpos == 0 if or if not there is a
11138 header-line; it's not the same as the MATRIX_ROW_VPOS! */
11139 start_display (&it
, w
, new_start
);
11140 first_row_y
= it
.current_y
;
11141 w
->cursor
.vpos
= -1;
11142 last_text_row
= last_reused_text_row
= NULL
;
11144 while (it
.current_y
< it
.last_visible_y
11145 && IT_CHARPOS (it
) < CHARPOS (start
)
11146 && !fonts_changed_p
)
11147 if (display_line (&it
))
11148 last_text_row
= it
.glyph_row
- 1;
11150 /* A value of current_y < last_visible_y means that we stopped
11151 at the previous window start, which in turn means that we
11152 have at least one reusable row. */
11153 if (it
.current_y
< it
.last_visible_y
)
11155 /* IT.vpos always starts from 0; it counts text lines. */
11156 nrows_scrolled
= it
.vpos
;
11158 /* Find PT if not already found in the lines displayed. */
11159 if (w
->cursor
.vpos
< 0)
11161 int dy
= it
.current_y
- first_row_y
;
11163 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11164 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
11166 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
11167 dy
, nrows_scrolled
);
11170 clear_glyph_matrix (w
->desired_matrix
);
11175 /* Scroll the display. Do it before the current matrix is
11176 changed. The problem here is that update has not yet
11177 run, i.e. part of the current matrix is not up to date.
11178 scroll_run_hook will clear the cursor, and use the
11179 current matrix to get the height of the row the cursor is
11181 run
.current_y
= first_row_y
;
11182 run
.desired_y
= it
.current_y
;
11183 run
.height
= it
.last_visible_y
- it
.current_y
;
11185 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
11188 rif
->update_window_begin_hook (w
);
11189 rif
->clear_mouse_face (w
);
11190 rif
->scroll_run_hook (w
, &run
);
11191 rif
->update_window_end_hook (w
, 0, 0);
11195 /* Shift current matrix down by nrows_scrolled lines. */
11196 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11197 rotate_matrix (w
->current_matrix
,
11199 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11202 /* Disable lines that must be updated. */
11203 for (i
= 0; i
< it
.vpos
; ++i
)
11204 (start_row
+ i
)->enabled_p
= 0;
11206 /* Re-compute Y positions. */
11207 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11208 max_y
= it
.last_visible_y
;
11209 for (row
= start_row
+ nrows_scrolled
;
11213 row
->y
= it
.current_y
;
11214 row
->visible_height
= row
->height
;
11216 if (row
->y
< min_y
)
11217 row
->visible_height
-= min_y
- row
->y
;
11218 if (row
->y
+ row
->height
> max_y
)
11219 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11221 it
.current_y
+= row
->height
;
11223 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11224 last_reused_text_row
= row
;
11225 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
11229 /* Disable lines in the current matrix which are now
11230 below the window. */
11231 for (++row
; row
< bottom_row
; ++row
)
11232 row
->enabled_p
= 0;
11235 /* Update window_end_pos etc.; last_reused_text_row is the last
11236 reused row from the current matrix containing text, if any.
11237 The value of last_text_row is the last displayed line
11238 containing text. */
11239 if (last_reused_text_row
)
11241 w
->window_end_bytepos
11242 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
11244 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
11246 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
11247 w
->current_matrix
));
11249 else if (last_text_row
)
11251 w
->window_end_bytepos
11252 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11254 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11256 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11260 /* This window must be completely empty. */
11261 w
->window_end_bytepos
= 0;
11262 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
11264 w
->window_end_valid
= Qnil
;
11266 /* Update hint: don't try scrolling again in update_window. */
11267 w
->desired_matrix
->no_scrolling_p
= 1;
11270 debug_method_add (w
, "try_window_reusing_current_matrix 1");
11274 else if (CHARPOS (new_start
) > CHARPOS (start
))
11276 struct glyph_row
*pt_row
, *row
;
11277 struct glyph_row
*first_reusable_row
;
11278 struct glyph_row
*first_row_to_display
;
11280 int yb
= window_text_bottom_y (w
);
11282 /* Find the row starting at new_start, if there is one. Don't
11283 reuse a partially visible line at the end. */
11284 first_reusable_row
= start_row
;
11285 while (first_reusable_row
->enabled_p
11286 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
11287 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11288 < CHARPOS (new_start
)))
11289 ++first_reusable_row
;
11291 /* Give up if there is no row to reuse. */
11292 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
11293 || !first_reusable_row
->enabled_p
11294 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11295 != CHARPOS (new_start
)))
11298 /* We can reuse fully visible rows beginning with
11299 first_reusable_row to the end of the window. Set
11300 first_row_to_display to the first row that cannot be reused.
11301 Set pt_row to the row containing point, if there is any. */
11303 for (first_row_to_display
= first_reusable_row
;
11304 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
11305 ++first_row_to_display
)
11307 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
11308 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
11309 pt_row
= first_row_to_display
;
11312 /* Start displaying at the start of first_row_to_display. */
11313 xassert (first_row_to_display
->y
< yb
);
11314 init_to_row_start (&it
, w
, first_row_to_display
);
11316 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
11318 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
11320 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11321 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11323 /* Display lines beginning with first_row_to_display in the
11324 desired matrix. Set last_text_row to the last row displayed
11325 that displays text. */
11326 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11327 if (pt_row
== NULL
)
11328 w
->cursor
.vpos
= -1;
11329 last_text_row
= NULL
;
11330 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11331 if (display_line (&it
))
11332 last_text_row
= it
.glyph_row
- 1;
11334 /* Give up If point isn't in a row displayed or reused. */
11335 if (w
->cursor
.vpos
< 0)
11337 clear_glyph_matrix (w
->desired_matrix
);
11341 /* If point is in a reused row, adjust y and vpos of the cursor
11345 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11346 w
->current_matrix
);
11347 w
->cursor
.y
-= first_reusable_row
->y
;
11350 /* Scroll the display. */
11351 run
.current_y
= first_reusable_row
->y
;
11352 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11353 run
.height
= it
.last_visible_y
- run
.current_y
;
11354 dy
= run
.current_y
- run
.desired_y
;
11358 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11360 rif
->update_window_begin_hook (w
);
11361 rif
->clear_mouse_face (w
);
11362 rif
->scroll_run_hook (w
, &run
);
11363 rif
->update_window_end_hook (w
, 0, 0);
11367 /* Adjust Y positions of reused rows. */
11368 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11369 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11370 max_y
= it
.last_visible_y
;
11371 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11374 row
->visible_height
= row
->height
;
11375 if (row
->y
< min_y
)
11376 row
->visible_height
-= min_y
- row
->y
;
11377 if (row
->y
+ row
->height
> max_y
)
11378 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11381 /* Scroll the current matrix. */
11382 xassert (nrows_scrolled
> 0);
11383 rotate_matrix (w
->current_matrix
,
11385 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11388 /* Disable rows not reused. */
11389 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11390 row
->enabled_p
= 0;
11392 /* Adjust window end. A null value of last_text_row means that
11393 the window end is in reused rows which in turn means that
11394 only its vpos can have changed. */
11397 w
->window_end_bytepos
11398 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11400 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11402 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11407 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11410 w
->window_end_valid
= Qnil
;
11411 w
->desired_matrix
->no_scrolling_p
= 1;
11414 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11424 /************************************************************************
11425 Window redisplay reusing current matrix when buffer has changed
11426 ************************************************************************/
11428 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11429 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11431 static struct glyph_row
*
11432 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11433 struct glyph_row
*));
11436 /* Return the last row in MATRIX displaying text. If row START is
11437 non-null, start searching with that row. IT gives the dimensions
11438 of the display. Value is null if matrix is empty; otherwise it is
11439 a pointer to the row found. */
11441 static struct glyph_row
*
11442 find_last_row_displaying_text (matrix
, it
, start
)
11443 struct glyph_matrix
*matrix
;
11445 struct glyph_row
*start
;
11447 struct glyph_row
*row
, *row_found
;
11449 /* Set row_found to the last row in IT->w's current matrix
11450 displaying text. The loop looks funny but think of partially
11453 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11454 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11456 xassert (row
->enabled_p
);
11458 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11467 /* Return the last row in the current matrix of W that is not affected
11468 by changes at the start of current_buffer that occurred since W's
11469 current matrix was built. Value is null if no such row exists.
11471 BEG_UNCHANGED us the number of characters unchanged at the start of
11472 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11473 first changed character in current_buffer. Characters at positions <
11474 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11475 when the current matrix was built. */
11477 static struct glyph_row
*
11478 find_last_unchanged_at_beg_row (w
)
11481 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11482 struct glyph_row
*row
;
11483 struct glyph_row
*row_found
= NULL
;
11484 int yb
= window_text_bottom_y (w
);
11486 /* Find the last row displaying unchanged text. */
11487 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11488 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11489 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11491 if (/* If row ends before first_changed_pos, it is unchanged,
11492 except in some case. */
11493 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11494 /* When row ends in ZV and we write at ZV it is not
11496 && !row
->ends_at_zv_p
11497 /* When first_changed_pos is the end of a continued line,
11498 row is not unchanged because it may be no longer
11500 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11501 && row
->continued_p
))
11504 /* Stop if last visible row. */
11505 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11515 /* Find the first glyph row in the current matrix of W that is not
11516 affected by changes at the end of current_buffer since the
11517 time W's current matrix was built.
11519 Return in *DELTA the number of chars by which buffer positions in
11520 unchanged text at the end of current_buffer must be adjusted.
11522 Return in *DELTA_BYTES the corresponding number of bytes.
11524 Value is null if no such row exists, i.e. all rows are affected by
11527 static struct glyph_row
*
11528 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11530 int *delta
, *delta_bytes
;
11532 struct glyph_row
*row
;
11533 struct glyph_row
*row_found
= NULL
;
11535 *delta
= *delta_bytes
= 0;
11537 /* Display must not have been paused, otherwise the current matrix
11538 is not up to date. */
11539 if (NILP (w
->window_end_valid
))
11542 /* A value of window_end_pos >= END_UNCHANGED means that the window
11543 end is in the range of changed text. If so, there is no
11544 unchanged row at the end of W's current matrix. */
11545 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11548 /* Set row to the last row in W's current matrix displaying text. */
11549 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11551 /* If matrix is entirely empty, no unchanged row exists. */
11552 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11554 /* The value of row is the last glyph row in the matrix having a
11555 meaningful buffer position in it. The end position of row
11556 corresponds to window_end_pos. This allows us to translate
11557 buffer positions in the current matrix to current buffer
11558 positions for characters not in changed text. */
11559 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11560 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11561 int last_unchanged_pos
, last_unchanged_pos_old
;
11562 struct glyph_row
*first_text_row
11563 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11565 *delta
= Z
- Z_old
;
11566 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11568 /* Set last_unchanged_pos to the buffer position of the last
11569 character in the buffer that has not been changed. Z is the
11570 index + 1 of the last character in current_buffer, i.e. by
11571 subtracting END_UNCHANGED we get the index of the last
11572 unchanged character, and we have to add BEG to get its buffer
11574 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11575 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11577 /* Search backward from ROW for a row displaying a line that
11578 starts at a minimum position >= last_unchanged_pos_old. */
11579 for (; row
> first_text_row
; --row
)
11581 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11584 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11589 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11596 /* Make sure that glyph rows in the current matrix of window W
11597 reference the same glyph memory as corresponding rows in the
11598 frame's frame matrix. This function is called after scrolling W's
11599 current matrix on a terminal frame in try_window_id and
11600 try_window_reusing_current_matrix. */
11603 sync_frame_with_window_matrix_rows (w
)
11606 struct frame
*f
= XFRAME (w
->frame
);
11607 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11609 /* Preconditions: W must be a leaf window and full-width. Its frame
11610 must have a frame matrix. */
11611 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11612 xassert (WINDOW_FULL_WIDTH_P (w
));
11613 xassert (!FRAME_WINDOW_P (f
));
11615 /* If W is a full-width window, glyph pointers in W's current matrix
11616 have, by definition, to be the same as glyph pointers in the
11617 corresponding frame matrix. Note that frame matrices have no
11618 marginal areas (see build_frame_matrix). */
11619 window_row
= w
->current_matrix
->rows
;
11620 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11621 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11622 while (window_row
< window_row_end
)
11624 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
11625 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
11627 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
11628 frame_row
->glyphs
[TEXT_AREA
] = start
;
11629 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
11630 frame_row
->glyphs
[LAST_AREA
] = end
;
11632 /* Disable frame rows whose corresponding window rows have
11633 been disabled in try_window_id. */
11634 if (!window_row
->enabled_p
)
11635 frame_row
->enabled_p
= 0;
11637 ++window_row
, ++frame_row
;
11642 /* Find the glyph row in window W containing CHARPOS. Consider all
11643 rows between START and END (not inclusive). END null means search
11644 all rows to the end of the display area of W. Value is the row
11645 containing CHARPOS or null. */
11648 row_containing_pos (w
, charpos
, start
, end
, dy
)
11651 struct glyph_row
*start
, *end
;
11654 struct glyph_row
*row
= start
;
11657 /* If we happen to start on a header-line, skip that. */
11658 if (row
->mode_line_p
)
11661 if ((end
&& row
>= end
) || !row
->enabled_p
)
11664 last_y
= window_text_bottom_y (w
) - dy
;
11668 /* Give up if we have gone too far. */
11669 if (end
&& row
>= end
)
11671 /* This formerly returned if they were equal.
11672 I think that both quantities are of a "last plus one" type;
11673 if so, when they are equal, the row is within the screen. -- rms. */
11674 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
11677 /* If it is in this row, return this row. */
11678 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
11679 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11680 /* The end position of a row equals the start
11681 position of the next row. If CHARPOS is there, we
11682 would rather display it in the next line, except
11683 when this line ends in ZV. */
11684 && !row
->ends_at_zv_p
11685 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11686 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
11693 /* Try to redisplay window W by reusing its existing display. W's
11694 current matrix must be up to date when this function is called,
11695 i.e. window_end_valid must not be nil.
11699 1 if display has been updated
11700 0 if otherwise unsuccessful
11701 -1 if redisplay with same window start is known not to succeed
11703 The following steps are performed:
11705 1. Find the last row in the current matrix of W that is not
11706 affected by changes at the start of current_buffer. If no such row
11709 2. Find the first row in W's current matrix that is not affected by
11710 changes at the end of current_buffer. Maybe there is no such row.
11712 3. Display lines beginning with the row + 1 found in step 1 to the
11713 row found in step 2 or, if step 2 didn't find a row, to the end of
11716 4. If cursor is not known to appear on the window, give up.
11718 5. If display stopped at the row found in step 2, scroll the
11719 display and current matrix as needed.
11721 6. Maybe display some lines at the end of W, if we must. This can
11722 happen under various circumstances, like a partially visible line
11723 becoming fully visible, or because newly displayed lines are displayed
11724 in smaller font sizes.
11726 7. Update W's window end information. */
11732 struct frame
*f
= XFRAME (w
->frame
);
11733 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11734 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11735 struct glyph_row
*last_unchanged_at_beg_row
;
11736 struct glyph_row
*first_unchanged_at_end_row
;
11737 struct glyph_row
*row
;
11738 struct glyph_row
*bottom_row
;
11741 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11742 struct text_pos start_pos
;
11744 int first_unchanged_at_end_vpos
= 0;
11745 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11746 struct text_pos start
;
11747 int first_changed_charpos
, last_changed_charpos
;
11750 if (inhibit_try_window_id
)
11754 /* This is handy for debugging. */
11756 #define GIVE_UP(X) \
11758 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11762 #define GIVE_UP(X) return 0
11765 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11767 /* Don't use this for mini-windows because these can show
11768 messages and mini-buffers, and we don't handle that here. */
11769 if (MINI_WINDOW_P (w
))
11772 /* This flag is used to prevent redisplay optimizations. */
11773 if (windows_or_buffers_changed
|| cursor_type_changed
)
11776 /* Verify that narrowing has not changed.
11777 Also verify that we were not told to prevent redisplay optimizations.
11778 It would be nice to further
11779 reduce the number of cases where this prevents try_window_id. */
11780 if (current_buffer
->clip_changed
11781 || current_buffer
->prevent_redisplay_optimizations_p
)
11784 /* Window must either use window-based redisplay or be full width. */
11785 if (!FRAME_WINDOW_P (f
)
11786 && (!line_ins_del_ok
11787 || !WINDOW_FULL_WIDTH_P (w
)))
11790 /* Give up if point is not known NOT to appear in W. */
11791 if (PT
< CHARPOS (start
))
11794 /* Another way to prevent redisplay optimizations. */
11795 if (XFASTINT (w
->last_modified
) == 0)
11798 /* Verify that window is not hscrolled. */
11799 if (XFASTINT (w
->hscroll
) != 0)
11802 /* Verify that display wasn't paused. */
11803 if (NILP (w
->window_end_valid
))
11806 /* Can't use this if highlighting a region because a cursor movement
11807 will do more than just set the cursor. */
11808 if (!NILP (Vtransient_mark_mode
)
11809 && !NILP (current_buffer
->mark_active
))
11812 /* Likewise if highlighting trailing whitespace. */
11813 if (!NILP (Vshow_trailing_whitespace
))
11816 /* Likewise if showing a region. */
11817 if (!NILP (w
->region_showing
))
11820 /* Can use this if overlay arrow position and or string have changed. */
11821 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11822 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11826 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11827 only if buffer has really changed. The reason is that the gap is
11828 initially at Z for freshly visited files. The code below would
11829 set end_unchanged to 0 in that case. */
11830 if (MODIFF
> SAVE_MODIFF
11831 /* This seems to happen sometimes after saving a buffer. */
11832 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11834 if (GPT
- BEG
< BEG_UNCHANGED
)
11835 BEG_UNCHANGED
= GPT
- BEG
;
11836 if (Z
- GPT
< END_UNCHANGED
)
11837 END_UNCHANGED
= Z
- GPT
;
11840 /* The position of the first and last character that has been changed. */
11841 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11842 last_changed_charpos
= Z
- END_UNCHANGED
;
11844 /* If window starts after a line end, and the last change is in
11845 front of that newline, then changes don't affect the display.
11846 This case happens with stealth-fontification. Note that although
11847 the display is unchanged, glyph positions in the matrix have to
11848 be adjusted, of course. */
11849 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11850 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11851 && ((last_changed_charpos
< CHARPOS (start
)
11852 && CHARPOS (start
) == BEGV
)
11853 || (last_changed_charpos
< CHARPOS (start
) - 1
11854 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11856 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11857 struct glyph_row
*r0
;
11859 /* Compute how many chars/bytes have been added to or removed
11860 from the buffer. */
11861 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11862 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11864 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11866 /* Give up if PT is not in the window. Note that it already has
11867 been checked at the start of try_window_id that PT is not in
11868 front of the window start. */
11869 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11872 /* If window start is unchanged, we can reuse the whole matrix
11873 as is, after adjusting glyph positions. No need to compute
11874 the window end again, since its offset from Z hasn't changed. */
11875 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11876 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11877 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11879 /* Adjust positions in the glyph matrix. */
11880 if (delta
|| delta_bytes
)
11882 struct glyph_row
*r1
11883 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11884 increment_matrix_positions (w
->current_matrix
,
11885 MATRIX_ROW_VPOS (r0
, current_matrix
),
11886 MATRIX_ROW_VPOS (r1
, current_matrix
),
11887 delta
, delta_bytes
);
11890 /* Set the cursor. */
11891 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11893 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11900 /* Handle the case that changes are all below what is displayed in
11901 the window, and that PT is in the window. This shortcut cannot
11902 be taken if ZV is visible in the window, and text has been added
11903 there that is visible in the window. */
11904 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11905 /* ZV is not visible in the window, or there are no
11906 changes at ZV, actually. */
11907 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11908 || first_changed_charpos
== last_changed_charpos
))
11910 struct glyph_row
*r0
;
11912 /* Give up if PT is not in the window. Note that it already has
11913 been checked at the start of try_window_id that PT is not in
11914 front of the window start. */
11915 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11918 /* If window start is unchanged, we can reuse the whole matrix
11919 as is, without changing glyph positions since no text has
11920 been added/removed in front of the window end. */
11921 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11922 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11924 /* We have to compute the window end anew since text
11925 can have been added/removed after it. */
11927 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11928 w
->window_end_bytepos
11929 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11931 /* Set the cursor. */
11932 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11934 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11941 /* Give up if window start is in the changed area.
11943 The condition used to read
11945 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11947 but why that was tested escapes me at the moment. */
11948 if (CHARPOS (start
) >= first_changed_charpos
11949 && CHARPOS (start
) <= last_changed_charpos
)
11952 /* Check that window start agrees with the start of the first glyph
11953 row in its current matrix. Check this after we know the window
11954 start is not in changed text, otherwise positions would not be
11956 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11957 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11960 /* Give up if the window ends in strings. Overlay strings
11961 at the end are difficult to handle, so don't try. */
11962 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11963 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11966 /* Compute the position at which we have to start displaying new
11967 lines. Some of the lines at the top of the window might be
11968 reusable because they are not displaying changed text. Find the
11969 last row in W's current matrix not affected by changes at the
11970 start of current_buffer. Value is null if changes start in the
11971 first line of window. */
11972 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11973 if (last_unchanged_at_beg_row
)
11975 /* Avoid starting to display in the moddle of a character, a TAB
11976 for instance. This is easier than to set up the iterator
11977 exactly, and it's not a frequent case, so the additional
11978 effort wouldn't really pay off. */
11979 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11980 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11981 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11982 --last_unchanged_at_beg_row
;
11984 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11987 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11989 start_pos
= it
.current
.pos
;
11991 /* Start displaying new lines in the desired matrix at the same
11992 vpos we would use in the current matrix, i.e. below
11993 last_unchanged_at_beg_row. */
11994 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11996 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11997 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11999 xassert (it
.hpos
== 0 && it
.current_x
== 0);
12003 /* There are no reusable lines at the start of the window.
12004 Start displaying in the first line. */
12005 start_display (&it
, w
, start
);
12006 start_pos
= it
.current
.pos
;
12009 /* Find the first row that is not affected by changes at the end of
12010 the buffer. Value will be null if there is no unchanged row, in
12011 which case we must redisplay to the end of the window. delta
12012 will be set to the value by which buffer positions beginning with
12013 first_unchanged_at_end_row have to be adjusted due to text
12015 first_unchanged_at_end_row
12016 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
12017 IF_DEBUG (debug_delta
= delta
);
12018 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
12020 /* Set stop_pos to the buffer position up to which we will have to
12021 display new lines. If first_unchanged_at_end_row != NULL, this
12022 is the buffer position of the start of the line displayed in that
12023 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
12024 that we don't stop at a buffer position. */
12026 if (first_unchanged_at_end_row
)
12028 xassert (last_unchanged_at_beg_row
== NULL
12029 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
12031 /* If this is a continuation line, move forward to the next one
12032 that isn't. Changes in lines above affect this line.
12033 Caution: this may move first_unchanged_at_end_row to a row
12034 not displaying text. */
12035 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
12036 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
12037 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
12038 < it
.last_visible_y
))
12039 ++first_unchanged_at_end_row
;
12041 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
12042 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
12043 >= it
.last_visible_y
))
12044 first_unchanged_at_end_row
= NULL
;
12047 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
12049 first_unchanged_at_end_vpos
12050 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
12051 xassert (stop_pos
>= Z
- END_UNCHANGED
);
12054 else if (last_unchanged_at_beg_row
== NULL
)
12060 /* Either there is no unchanged row at the end, or the one we have
12061 now displays text. This is a necessary condition for the window
12062 end pos calculation at the end of this function. */
12063 xassert (first_unchanged_at_end_row
== NULL
12064 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
12066 debug_last_unchanged_at_beg_vpos
12067 = (last_unchanged_at_beg_row
12068 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
12070 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
12072 #endif /* GLYPH_DEBUG != 0 */
12075 /* Display new lines. Set last_text_row to the last new line
12076 displayed which has text on it, i.e. might end up as being the
12077 line where the window_end_vpos is. */
12078 w
->cursor
.vpos
= -1;
12079 last_text_row
= NULL
;
12080 overlay_arrow_seen
= 0;
12081 while (it
.current_y
< it
.last_visible_y
12082 && !fonts_changed_p
12083 && (first_unchanged_at_end_row
== NULL
12084 || IT_CHARPOS (it
) < stop_pos
))
12086 if (display_line (&it
))
12087 last_text_row
= it
.glyph_row
- 1;
12090 if (fonts_changed_p
)
12094 /* Compute differences in buffer positions, y-positions etc. for
12095 lines reused at the bottom of the window. Compute what we can
12097 if (first_unchanged_at_end_row
12098 /* No lines reused because we displayed everything up to the
12099 bottom of the window. */
12100 && it
.current_y
< it
.last_visible_y
)
12103 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
12105 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
12106 run
.current_y
= first_unchanged_at_end_row
->y
;
12107 run
.desired_y
= run
.current_y
+ dy
;
12108 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
12112 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
12113 first_unchanged_at_end_row
= NULL
;
12115 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
12118 /* Find the cursor if not already found. We have to decide whether
12119 PT will appear on this window (it sometimes doesn't, but this is
12120 not a very frequent case.) This decision has to be made before
12121 the current matrix is altered. A value of cursor.vpos < 0 means
12122 that PT is either in one of the lines beginning at
12123 first_unchanged_at_end_row or below the window. Don't care for
12124 lines that might be displayed later at the window end; as
12125 mentioned, this is not a frequent case. */
12126 if (w
->cursor
.vpos
< 0)
12128 /* Cursor in unchanged rows at the top? */
12129 if (PT
< CHARPOS (start_pos
)
12130 && last_unchanged_at_beg_row
)
12132 row
= row_containing_pos (w
, PT
,
12133 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
12134 last_unchanged_at_beg_row
+ 1, 0);
12136 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12139 /* Start from first_unchanged_at_end_row looking for PT. */
12140 else if (first_unchanged_at_end_row
)
12142 row
= row_containing_pos (w
, PT
- delta
,
12143 first_unchanged_at_end_row
, NULL
, 0);
12145 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
12146 delta_bytes
, dy
, dvpos
);
12149 /* Give up if cursor was not found. */
12150 if (w
->cursor
.vpos
< 0)
12152 clear_glyph_matrix (w
->desired_matrix
);
12157 /* Don't let the cursor end in the scroll margins. */
12159 int this_scroll_margin
, cursor_height
;
12161 this_scroll_margin
= max (0, scroll_margin
);
12162 this_scroll_margin
= min (this_scroll_margin
,
12163 XFASTINT (w
->height
) / 4);
12164 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
12165 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
12167 if ((w
->cursor
.y
< this_scroll_margin
12168 && CHARPOS (start
) > BEGV
)
12169 /* Don't take scroll margin into account at the bottom because
12170 old redisplay didn't do it either. */
12171 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
12173 w
->cursor
.vpos
= -1;
12174 clear_glyph_matrix (w
->desired_matrix
);
12179 /* Scroll the display. Do it before changing the current matrix so
12180 that xterm.c doesn't get confused about where the cursor glyph is
12182 if (dy
&& run
.height
)
12186 if (FRAME_WINDOW_P (f
))
12188 rif
->update_window_begin_hook (w
);
12189 rif
->clear_mouse_face (w
);
12190 rif
->scroll_run_hook (w
, &run
);
12191 rif
->update_window_end_hook (w
, 0, 0);
12195 /* Terminal frame. In this case, dvpos gives the number of
12196 lines to scroll by; dvpos < 0 means scroll up. */
12197 int first_unchanged_at_end_vpos
12198 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
12199 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
12200 int end
= (XFASTINT (w
->top
)
12201 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
12202 + window_internal_height (w
));
12204 /* Perform the operation on the screen. */
12207 /* Scroll last_unchanged_at_beg_row to the end of the
12208 window down dvpos lines. */
12209 set_terminal_window (end
);
12211 /* On dumb terminals delete dvpos lines at the end
12212 before inserting dvpos empty lines. */
12213 if (!scroll_region_ok
)
12214 ins_del_lines (end
- dvpos
, -dvpos
);
12216 /* Insert dvpos empty lines in front of
12217 last_unchanged_at_beg_row. */
12218 ins_del_lines (from
, dvpos
);
12220 else if (dvpos
< 0)
12222 /* Scroll up last_unchanged_at_beg_vpos to the end of
12223 the window to last_unchanged_at_beg_vpos - |dvpos|. */
12224 set_terminal_window (end
);
12226 /* Delete dvpos lines in front of
12227 last_unchanged_at_beg_vpos. ins_del_lines will set
12228 the cursor to the given vpos and emit |dvpos| delete
12230 ins_del_lines (from
+ dvpos
, dvpos
);
12232 /* On a dumb terminal insert dvpos empty lines at the
12234 if (!scroll_region_ok
)
12235 ins_del_lines (end
+ dvpos
, -dvpos
);
12238 set_terminal_window (0);
12244 /* Shift reused rows of the current matrix to the right position.
12245 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
12247 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
12248 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
12251 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
12252 bottom_vpos
, dvpos
);
12253 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
12256 else if (dvpos
> 0)
12258 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
12259 bottom_vpos
, dvpos
);
12260 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
12261 first_unchanged_at_end_vpos
+ dvpos
, 0);
12264 /* For frame-based redisplay, make sure that current frame and window
12265 matrix are in sync with respect to glyph memory. */
12266 if (!FRAME_WINDOW_P (f
))
12267 sync_frame_with_window_matrix_rows (w
);
12269 /* Adjust buffer positions in reused rows. */
12271 increment_matrix_positions (current_matrix
,
12272 first_unchanged_at_end_vpos
+ dvpos
,
12273 bottom_vpos
, delta
, delta_bytes
);
12275 /* Adjust Y positions. */
12277 shift_glyph_matrix (w
, current_matrix
,
12278 first_unchanged_at_end_vpos
+ dvpos
,
12281 if (first_unchanged_at_end_row
)
12282 first_unchanged_at_end_row
+= dvpos
;
12284 /* If scrolling up, there may be some lines to display at the end of
12286 last_text_row_at_end
= NULL
;
12289 /* Scrolling up can leave for example a partially visible line
12290 at the end of the window to be redisplayed. */
12291 /* Set last_row to the glyph row in the current matrix where the
12292 window end line is found. It has been moved up or down in
12293 the matrix by dvpos. */
12294 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
12295 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
12297 /* If last_row is the window end line, it should display text. */
12298 xassert (last_row
->displays_text_p
);
12300 /* If window end line was partially visible before, begin
12301 displaying at that line. Otherwise begin displaying with the
12302 line following it. */
12303 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
12305 init_to_row_start (&it
, w
, last_row
);
12306 it
.vpos
= last_vpos
;
12307 it
.current_y
= last_row
->y
;
12311 init_to_row_end (&it
, w
, last_row
);
12312 it
.vpos
= 1 + last_vpos
;
12313 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
12317 /* We may start in a continuation line. If so, we have to
12318 get the right continuation_lines_width and current_x. */
12319 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
12320 it
.hpos
= it
.current_x
= 0;
12322 /* Display the rest of the lines at the window end. */
12323 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12324 while (it
.current_y
< it
.last_visible_y
12325 && !fonts_changed_p
)
12327 /* Is it always sure that the display agrees with lines in
12328 the current matrix? I don't think so, so we mark rows
12329 displayed invalid in the current matrix by setting their
12330 enabled_p flag to zero. */
12331 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
12332 if (display_line (&it
))
12333 last_text_row_at_end
= it
.glyph_row
- 1;
12337 /* Update window_end_pos and window_end_vpos. */
12338 if (first_unchanged_at_end_row
12339 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12340 && !last_text_row_at_end
)
12342 /* Window end line if one of the preserved rows from the current
12343 matrix. Set row to the last row displaying text in current
12344 matrix starting at first_unchanged_at_end_row, after
12346 xassert (first_unchanged_at_end_row
->displays_text_p
);
12347 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12348 first_unchanged_at_end_row
);
12349 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12351 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12352 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12354 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12355 xassert (w
->window_end_bytepos
>= 0);
12356 IF_DEBUG (debug_method_add (w
, "A"));
12358 else if (last_text_row_at_end
)
12361 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12362 w
->window_end_bytepos
12363 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12365 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12366 xassert (w
->window_end_bytepos
>= 0);
12367 IF_DEBUG (debug_method_add (w
, "B"));
12369 else if (last_text_row
)
12371 /* We have displayed either to the end of the window or at the
12372 end of the window, i.e. the last row with text is to be found
12373 in the desired matrix. */
12375 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12376 w
->window_end_bytepos
12377 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12379 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12380 xassert (w
->window_end_bytepos
>= 0);
12382 else if (first_unchanged_at_end_row
== NULL
12383 && last_text_row
== NULL
12384 && last_text_row_at_end
== NULL
)
12386 /* Displayed to end of window, but no line containing text was
12387 displayed. Lines were deleted at the end of the window. */
12388 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12389 int vpos
= XFASTINT (w
->window_end_vpos
);
12390 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12391 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12394 row
== NULL
&& vpos
>= first_vpos
;
12395 --vpos
, --current_row
, --desired_row
)
12397 if (desired_row
->enabled_p
)
12399 if (desired_row
->displays_text_p
)
12402 else if (current_row
->displays_text_p
)
12406 xassert (row
!= NULL
);
12407 w
->window_end_vpos
= make_number (vpos
+ 1);
12408 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12409 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12410 xassert (w
->window_end_bytepos
>= 0);
12411 IF_DEBUG (debug_method_add (w
, "C"));
12416 #if 0 /* This leads to problems, for instance when the cursor is
12417 at ZV, and the cursor line displays no text. */
12418 /* Disable rows below what's displayed in the window. This makes
12419 debugging easier. */
12420 enable_glyph_matrix_rows (current_matrix
,
12421 XFASTINT (w
->window_end_vpos
) + 1,
12425 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12426 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12428 /* Record that display has not been completed. */
12429 w
->window_end_valid
= Qnil
;
12430 w
->desired_matrix
->no_scrolling_p
= 1;
12438 /***********************************************************************
12439 More debugging support
12440 ***********************************************************************/
12444 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12445 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12446 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12449 /* Dump the contents of glyph matrix MATRIX on stderr.
12451 GLYPHS 0 means don't show glyph contents.
12452 GLYPHS 1 means show glyphs in short form
12453 GLYPHS > 1 means show glyphs in long form. */
12456 dump_glyph_matrix (matrix
, glyphs
)
12457 struct glyph_matrix
*matrix
;
12461 for (i
= 0; i
< matrix
->nrows
; ++i
)
12462 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12466 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12467 the glyph row and area where the glyph comes from. */
12470 dump_glyph (row
, glyph
, area
)
12471 struct glyph_row
*row
;
12472 struct glyph
*glyph
;
12475 if (glyph
->type
== CHAR_GLYPH
)
12478 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12479 glyph
- row
->glyphs
[TEXT_AREA
],
12482 (BUFFERP (glyph
->object
)
12484 : (STRINGP (glyph
->object
)
12487 glyph
->pixel_width
,
12489 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12493 glyph
->left_box_line_p
,
12494 glyph
->right_box_line_p
);
12496 else if (glyph
->type
== STRETCH_GLYPH
)
12499 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12500 glyph
- row
->glyphs
[TEXT_AREA
],
12503 (BUFFERP (glyph
->object
)
12505 : (STRINGP (glyph
->object
)
12508 glyph
->pixel_width
,
12512 glyph
->left_box_line_p
,
12513 glyph
->right_box_line_p
);
12515 else if (glyph
->type
== IMAGE_GLYPH
)
12518 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12519 glyph
- row
->glyphs
[TEXT_AREA
],
12522 (BUFFERP (glyph
->object
)
12524 : (STRINGP (glyph
->object
)
12527 glyph
->pixel_width
,
12531 glyph
->left_box_line_p
,
12532 glyph
->right_box_line_p
);
12537 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12538 GLYPHS 0 means don't show glyph contents.
12539 GLYPHS 1 means show glyphs in short form
12540 GLYPHS > 1 means show glyphs in long form. */
12543 dump_glyph_row (row
, vpos
, glyphs
)
12544 struct glyph_row
*row
;
12549 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12550 fprintf (stderr
, "=======================================================================\n");
12552 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12553 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12555 MATRIX_ROW_START_CHARPOS (row
),
12556 MATRIX_ROW_END_CHARPOS (row
),
12557 row
->used
[TEXT_AREA
],
12558 row
->contains_overlapping_glyphs_p
,
12560 row
->truncated_on_left_p
,
12561 row
->truncated_on_right_p
,
12562 row
->overlay_arrow_p
,
12564 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12565 row
->displays_text_p
,
12568 row
->ends_in_middle_of_char_p
,
12569 row
->starts_in_middle_of_char_p
,
12575 row
->visible_height
,
12578 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12579 row
->end
.overlay_string_index
,
12580 row
->continuation_lines_width
);
12581 fprintf (stderr
, "%9d %5d\n",
12582 CHARPOS (row
->start
.string_pos
),
12583 CHARPOS (row
->end
.string_pos
));
12584 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12585 row
->end
.dpvec_index
);
12592 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12594 struct glyph
*glyph
= row
->glyphs
[area
];
12595 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12597 /* Glyph for a line end in text. */
12598 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12601 if (glyph
< glyph_end
)
12602 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12604 for (; glyph
< glyph_end
; ++glyph
)
12605 dump_glyph (row
, glyph
, area
);
12608 else if (glyphs
== 1)
12612 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12614 char *s
= (char *) alloca (row
->used
[area
] + 1);
12617 for (i
= 0; i
< row
->used
[area
]; ++i
)
12619 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12620 if (glyph
->type
== CHAR_GLYPH
12621 && glyph
->u
.ch
< 0x80
12622 && glyph
->u
.ch
>= ' ')
12623 s
[i
] = glyph
->u
.ch
;
12629 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12635 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12636 Sdump_glyph_matrix
, 0, 1, "p",
12637 doc
: /* Dump the current matrix of the selected window to stderr.
12638 Shows contents of glyph row structures. With non-nil
12639 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12640 glyphs in short form, otherwise show glyphs in long form. */)
12642 Lisp_Object glyphs
;
12644 struct window
*w
= XWINDOW (selected_window
);
12645 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12647 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12648 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12649 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12650 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12651 fprintf (stderr
, "=============================================\n");
12652 dump_glyph_matrix (w
->current_matrix
,
12653 NILP (glyphs
) ? 0 : XINT (glyphs
));
12658 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
12659 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
12662 struct frame
*f
= XFRAME (selected_frame
);
12663 dump_glyph_matrix (f
->current_matrix
, 1);
12668 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12669 doc
: /* Dump glyph row ROW to stderr.
12670 GLYPH 0 means don't dump glyphs.
12671 GLYPH 1 means dump glyphs in short form.
12672 GLYPH > 1 or omitted means dump glyphs in long form. */)
12674 Lisp_Object row
, glyphs
;
12676 struct glyph_matrix
*matrix
;
12679 CHECK_NUMBER (row
);
12680 matrix
= XWINDOW (selected_window
)->current_matrix
;
12682 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12683 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12685 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12690 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12691 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12692 GLYPH 0 means don't dump glyphs.
12693 GLYPH 1 means dump glyphs in short form.
12694 GLYPH > 1 or omitted means dump glyphs in long form. */)
12696 Lisp_Object row
, glyphs
;
12698 struct frame
*sf
= SELECTED_FRAME ();
12699 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12702 CHECK_NUMBER (row
);
12704 if (vpos
>= 0 && vpos
< m
->nrows
)
12705 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12706 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12711 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12712 doc
: /* Toggle tracing of redisplay.
12713 With ARG, turn tracing on if and only if ARG is positive. */)
12718 trace_redisplay_p
= !trace_redisplay_p
;
12721 arg
= Fprefix_numeric_value (arg
);
12722 trace_redisplay_p
= XINT (arg
) > 0;
12729 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12730 doc
: /* Like `format', but print result to stderr.
12731 usage: (trace-to-stderr STRING &rest OBJECTS) */)
12736 Lisp_Object s
= Fformat (nargs
, args
);
12737 fprintf (stderr
, "%s", SDATA (s
));
12741 #endif /* GLYPH_DEBUG */
12745 /***********************************************************************
12746 Building Desired Matrix Rows
12747 ***********************************************************************/
12749 /* Return a temporary glyph row holding the glyphs of an overlay
12750 arrow. Only used for non-window-redisplay windows. */
12752 static struct glyph_row
*
12753 get_overlay_arrow_glyph_row (w
)
12756 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12757 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12758 struct buffer
*old
= current_buffer
;
12759 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
12760 int arrow_len
= SCHARS (Voverlay_arrow_string
);
12761 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12762 const unsigned char *p
;
12765 int n_glyphs_before
;
12767 set_buffer_temp (buffer
);
12768 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12769 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12770 SET_TEXT_POS (it
.position
, 0, 0);
12772 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12774 while (p
< arrow_end
)
12776 Lisp_Object face
, ilisp
;
12778 /* Get the next character. */
12780 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12782 it
.c
= *p
, it
.len
= 1;
12785 /* Get its face. */
12786 ilisp
= make_number (p
- arrow_string
);
12787 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12788 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12790 /* Compute its width, get its glyphs. */
12791 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12792 SET_TEXT_POS (it
.position
, -1, -1);
12793 PRODUCE_GLYPHS (&it
);
12795 /* If this character doesn't fit any more in the line, we have
12796 to remove some glyphs. */
12797 if (it
.current_x
> it
.last_visible_x
)
12799 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12804 set_buffer_temp (old
);
12805 return it
.glyph_row
;
12809 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12810 glyphs are only inserted for terminal frames since we can't really
12811 win with truncation glyphs when partially visible glyphs are
12812 involved. Which glyphs to insert is determined by
12813 produce_special_glyphs. */
12816 insert_left_trunc_glyphs (it
)
12819 struct it truncate_it
;
12820 struct glyph
*from
, *end
, *to
, *toend
;
12822 xassert (!FRAME_WINDOW_P (it
->f
));
12824 /* Get the truncation glyphs. */
12826 truncate_it
.current_x
= 0;
12827 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12828 truncate_it
.glyph_row
= &scratch_glyph_row
;
12829 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12830 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12831 truncate_it
.object
= make_number (0);
12832 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12834 /* Overwrite glyphs from IT with truncation glyphs. */
12835 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12836 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12837 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12838 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12843 /* There may be padding glyphs left over. Overwrite them too. */
12844 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12846 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12852 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12856 /* Compute the pixel height and width of IT->glyph_row.
12858 Most of the time, ascent and height of a display line will be equal
12859 to the max_ascent and max_height values of the display iterator
12860 structure. This is not the case if
12862 1. We hit ZV without displaying anything. In this case, max_ascent
12863 and max_height will be zero.
12865 2. We have some glyphs that don't contribute to the line height.
12866 (The glyph row flag contributes_to_line_height_p is for future
12867 pixmap extensions).
12869 The first case is easily covered by using default values because in
12870 these cases, the line height does not really matter, except that it
12871 must not be zero. */
12874 compute_line_metrics (it
)
12877 struct glyph_row
*row
= it
->glyph_row
;
12880 if (FRAME_WINDOW_P (it
->f
))
12882 int i
, min_y
, max_y
;
12884 /* The line may consist of one space only, that was added to
12885 place the cursor on it. If so, the row's height hasn't been
12887 if (row
->height
== 0)
12889 if (it
->max_ascent
+ it
->max_descent
== 0)
12890 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12891 row
->ascent
= it
->max_ascent
;
12892 row
->height
= it
->max_ascent
+ it
->max_descent
;
12893 row
->phys_ascent
= it
->max_phys_ascent
;
12894 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12897 /* Compute the width of this line. */
12898 row
->pixel_width
= row
->x
;
12899 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12900 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12902 xassert (row
->pixel_width
>= 0);
12903 xassert (row
->ascent
>= 0 && row
->height
> 0);
12905 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12906 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12908 /* If first line's physical ascent is larger than its logical
12909 ascent, use the physical ascent, and make the row taller.
12910 This makes accented characters fully visible. */
12911 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12912 && row
->phys_ascent
> row
->ascent
)
12914 row
->height
+= row
->phys_ascent
- row
->ascent
;
12915 row
->ascent
= row
->phys_ascent
;
12918 /* Compute how much of the line is visible. */
12919 row
->visible_height
= row
->height
;
12921 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12922 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12924 if (row
->y
< min_y
)
12925 row
->visible_height
-= min_y
- row
->y
;
12926 if (row
->y
+ row
->height
> max_y
)
12927 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12931 row
->pixel_width
= row
->used
[TEXT_AREA
];
12932 if (row
->continued_p
)
12933 row
->pixel_width
-= it
->continuation_pixel_width
;
12934 else if (row
->truncated_on_right_p
)
12935 row
->pixel_width
-= it
->truncation_pixel_width
;
12936 row
->ascent
= row
->phys_ascent
= 0;
12937 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12940 /* Compute a hash code for this row. */
12942 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12943 for (i
= 0; i
< row
->used
[area
]; ++i
)
12944 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12945 + row
->glyphs
[area
][i
].u
.val
12946 + row
->glyphs
[area
][i
].face_id
12947 + row
->glyphs
[area
][i
].padding_p
12948 + (row
->glyphs
[area
][i
].type
<< 2));
12950 it
->max_ascent
= it
->max_descent
= 0;
12951 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12955 /* Append one space to the glyph row of iterator IT if doing a
12956 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12957 space have the default face, otherwise let it have the same face as
12958 IT->face_id. Value is non-zero if a space was added.
12960 This function is called to make sure that there is always one glyph
12961 at the end of a glyph row that the cursor can be set on under
12962 window-systems. (If there weren't such a glyph we would not know
12963 how wide and tall a box cursor should be displayed).
12965 At the same time this space let's a nicely handle clearing to the
12966 end of the line if the row ends in italic text. */
12969 append_space (it
, default_face_p
)
12971 int default_face_p
;
12973 if (FRAME_WINDOW_P (it
->f
))
12975 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12977 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12978 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12980 /* Save some values that must not be changed.
12981 Must save IT->c and IT->len because otherwise
12982 ITERATOR_AT_END_P wouldn't work anymore after
12983 append_space has been called. */
12984 enum display_element_type saved_what
= it
->what
;
12985 int saved_c
= it
->c
, saved_len
= it
->len
;
12986 int saved_x
= it
->current_x
;
12987 int saved_face_id
= it
->face_id
;
12988 struct text_pos saved_pos
;
12989 Lisp_Object saved_object
;
12992 saved_object
= it
->object
;
12993 saved_pos
= it
->position
;
12995 it
->what
= IT_CHARACTER
;
12996 bzero (&it
->position
, sizeof it
->position
);
12997 it
->object
= make_number (0);
13001 if (default_face_p
)
13002 it
->face_id
= DEFAULT_FACE_ID
;
13003 else if (it
->face_before_selective_p
)
13004 it
->face_id
= it
->saved_face_id
;
13005 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13006 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
13008 PRODUCE_GLYPHS (it
);
13010 it
->current_x
= saved_x
;
13011 it
->object
= saved_object
;
13012 it
->position
= saved_pos
;
13013 it
->what
= saved_what
;
13014 it
->face_id
= saved_face_id
;
13015 it
->len
= saved_len
;
13025 /* Extend the face of the last glyph in the text area of IT->glyph_row
13026 to the end of the display line. Called from display_line.
13027 If the glyph row is empty, add a space glyph to it so that we
13028 know the face to draw. Set the glyph row flag fill_line_p. */
13031 extend_face_to_end_of_line (it
)
13035 struct frame
*f
= it
->f
;
13037 /* If line is already filled, do nothing. */
13038 if (it
->current_x
>= it
->last_visible_x
)
13041 /* Face extension extends the background and box of IT->face_id
13042 to the end of the line. If the background equals the background
13043 of the frame, we don't have to do anything. */
13044 if (it
->face_before_selective_p
)
13045 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
13047 face
= FACE_FROM_ID (f
, it
->face_id
);
13049 if (FRAME_WINDOW_P (f
)
13050 && face
->box
== FACE_NO_BOX
13051 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
13055 /* Set the glyph row flag indicating that the face of the last glyph
13056 in the text area has to be drawn to the end of the text area. */
13057 it
->glyph_row
->fill_line_p
= 1;
13059 /* If current character of IT is not ASCII, make sure we have the
13060 ASCII face. This will be automatically undone the next time
13061 get_next_display_element returns a multibyte character. Note
13062 that the character will always be single byte in unibyte text. */
13063 if (!SINGLE_BYTE_CHAR_P (it
->c
))
13065 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
13068 if (FRAME_WINDOW_P (f
))
13070 /* If the row is empty, add a space with the current face of IT,
13071 so that we know which face to draw. */
13072 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
13074 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
13075 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
13076 it
->glyph_row
->used
[TEXT_AREA
] = 1;
13081 /* Save some values that must not be changed. */
13082 int saved_x
= it
->current_x
;
13083 struct text_pos saved_pos
;
13084 Lisp_Object saved_object
;
13085 enum display_element_type saved_what
= it
->what
;
13086 int saved_face_id
= it
->face_id
;
13088 saved_object
= it
->object
;
13089 saved_pos
= it
->position
;
13091 it
->what
= IT_CHARACTER
;
13092 bzero (&it
->position
, sizeof it
->position
);
13093 it
->object
= make_number (0);
13096 it
->face_id
= face
->id
;
13098 PRODUCE_GLYPHS (it
);
13100 while (it
->current_x
<= it
->last_visible_x
)
13101 PRODUCE_GLYPHS (it
);
13103 /* Don't count these blanks really. It would let us insert a left
13104 truncation glyph below and make us set the cursor on them, maybe. */
13105 it
->current_x
= saved_x
;
13106 it
->object
= saved_object
;
13107 it
->position
= saved_pos
;
13108 it
->what
= saved_what
;
13109 it
->face_id
= saved_face_id
;
13114 /* Value is non-zero if text starting at CHARPOS in current_buffer is
13115 trailing whitespace. */
13118 trailing_whitespace_p (charpos
)
13121 int bytepos
= CHAR_TO_BYTE (charpos
);
13124 while (bytepos
< ZV_BYTE
13125 && (c
= FETCH_CHAR (bytepos
),
13126 c
== ' ' || c
== '\t'))
13129 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
13131 if (bytepos
!= PT_BYTE
)
13138 /* Highlight trailing whitespace, if any, in ROW. */
13141 highlight_trailing_whitespace (f
, row
)
13143 struct glyph_row
*row
;
13145 int used
= row
->used
[TEXT_AREA
];
13149 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
13150 struct glyph
*glyph
= start
+ used
- 1;
13152 /* Skip over glyphs inserted to display the cursor at the
13153 end of a line, for extending the face of the last glyph
13154 to the end of the line on terminals, and for truncation
13155 and continuation glyphs. */
13156 while (glyph
>= start
13157 && glyph
->type
== CHAR_GLYPH
13158 && INTEGERP (glyph
->object
))
13161 /* If last glyph is a space or stretch, and it's trailing
13162 whitespace, set the face of all trailing whitespace glyphs in
13163 IT->glyph_row to `trailing-whitespace'. */
13165 && BUFFERP (glyph
->object
)
13166 && (glyph
->type
== STRETCH_GLYPH
13167 || (glyph
->type
== CHAR_GLYPH
13168 && glyph
->u
.ch
== ' '))
13169 && trailing_whitespace_p (glyph
->charpos
))
13171 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
13173 while (glyph
>= start
13174 && BUFFERP (glyph
->object
)
13175 && (glyph
->type
== STRETCH_GLYPH
13176 || (glyph
->type
== CHAR_GLYPH
13177 && glyph
->u
.ch
== ' ')))
13178 (glyph
--)->face_id
= face_id
;
13184 /* Value is non-zero if glyph row ROW in window W should be
13185 used to hold the cursor. */
13188 cursor_row_p (w
, row
)
13190 struct glyph_row
*row
;
13192 int cursor_row_p
= 1;
13194 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
13196 /* If the row ends with a newline from a string, we don't want
13197 the cursor there (if the row is continued it doesn't end in a
13199 if (CHARPOS (row
->end
.string_pos
) >= 0
13200 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13201 cursor_row_p
= row
->continued_p
;
13203 /* If the row ends at ZV, display the cursor at the end of that
13204 row instead of at the start of the row below. */
13205 else if (row
->ends_at_zv_p
)
13211 return cursor_row_p
;
13215 /* Construct the glyph row IT->glyph_row in the desired matrix of
13216 IT->w from text at the current position of IT. See dispextern.h
13217 for an overview of struct it. Value is non-zero if
13218 IT->glyph_row displays text, as opposed to a line displaying ZV
13225 struct glyph_row
*row
= it
->glyph_row
;
13227 /* We always start displaying at hpos zero even if hscrolled. */
13228 xassert (it
->hpos
== 0 && it
->current_x
== 0);
13230 /* We must not display in a row that's not a text row. */
13231 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
13232 < it
->w
->desired_matrix
->nrows
);
13234 /* Is IT->w showing the region? */
13235 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
13237 /* Clear the result glyph row and enable it. */
13238 prepare_desired_row (row
);
13240 row
->y
= it
->current_y
;
13241 row
->start
= it
->current
;
13242 row
->continuation_lines_width
= it
->continuation_lines_width
;
13243 row
->displays_text_p
= 1;
13244 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
13245 it
->starts_in_middle_of_char_p
= 0;
13247 /* Arrange the overlays nicely for our purposes. Usually, we call
13248 display_line on only one line at a time, in which case this
13249 can't really hurt too much, or we call it on lines which appear
13250 one after another in the buffer, in which case all calls to
13251 recenter_overlay_lists but the first will be pretty cheap. */
13252 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
13254 /* Move over display elements that are not visible because we are
13255 hscrolled. This may stop at an x-position < IT->first_visible_x
13256 if the first glyph is partially visible or if we hit a line end. */
13257 if (it
->current_x
< it
->first_visible_x
)
13258 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
13259 MOVE_TO_POS
| MOVE_TO_X
);
13261 /* Get the initial row height. This is either the height of the
13262 text hscrolled, if there is any, or zero. */
13263 row
->ascent
= it
->max_ascent
;
13264 row
->height
= it
->max_ascent
+ it
->max_descent
;
13265 row
->phys_ascent
= it
->max_phys_ascent
;
13266 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13268 /* Loop generating characters. The loop is left with IT on the next
13269 character to display. */
13272 int n_glyphs_before
, hpos_before
, x_before
;
13274 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
13276 /* Retrieve the next thing to display. Value is zero if end of
13278 if (!get_next_display_element (it
))
13280 /* Maybe add a space at the end of this line that is used to
13281 display the cursor there under X. Set the charpos of the
13282 first glyph of blank lines not corresponding to any text
13284 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
13285 || row
->used
[TEXT_AREA
] == 0)
13287 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
13288 row
->displays_text_p
= 0;
13290 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
13291 && (!MINI_WINDOW_P (it
->w
)
13292 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
13293 row
->indicate_empty_line_p
= 1;
13296 it
->continuation_lines_width
= 0;
13297 row
->ends_at_zv_p
= 1;
13301 /* Now, get the metrics of what we want to display. This also
13302 generates glyphs in `row' (which is IT->glyph_row). */
13303 n_glyphs_before
= row
->used
[TEXT_AREA
];
13306 /* Remember the line height so far in case the next element doesn't
13307 fit on the line. */
13308 if (!it
->truncate_lines_p
)
13310 ascent
= it
->max_ascent
;
13311 descent
= it
->max_descent
;
13312 phys_ascent
= it
->max_phys_ascent
;
13313 phys_descent
= it
->max_phys_descent
;
13316 PRODUCE_GLYPHS (it
);
13318 /* If this display element was in marginal areas, continue with
13320 if (it
->area
!= TEXT_AREA
)
13322 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13323 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13324 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13325 row
->phys_height
= max (row
->phys_height
,
13326 it
->max_phys_ascent
+ it
->max_phys_descent
);
13327 set_iterator_to_next (it
, 1);
13331 /* Does the display element fit on the line? If we truncate
13332 lines, we should draw past the right edge of the window. If
13333 we don't truncate, we want to stop so that we can display the
13334 continuation glyph before the right margin. If lines are
13335 continued, there are two possible strategies for characters
13336 resulting in more than 1 glyph (e.g. tabs): Display as many
13337 glyphs as possible in this line and leave the rest for the
13338 continuation line, or display the whole element in the next
13339 line. Original redisplay did the former, so we do it also. */
13340 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
13341 hpos_before
= it
->hpos
;
13344 if (/* Not a newline. */
13346 /* Glyphs produced fit entirely in the line. */
13347 && it
->current_x
< it
->last_visible_x
)
13349 it
->hpos
+= nglyphs
;
13350 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13351 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13352 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13353 row
->phys_height
= max (row
->phys_height
,
13354 it
->max_phys_ascent
+ it
->max_phys_descent
);
13355 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13356 row
->x
= x
- it
->first_visible_x
;
13361 struct glyph
*glyph
;
13363 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13365 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13366 new_x
= x
+ glyph
->pixel_width
;
13368 if (/* Lines are continued. */
13369 !it
->truncate_lines_p
13370 && (/* Glyph doesn't fit on the line. */
13371 new_x
> it
->last_visible_x
13372 /* Or it fits exactly on a window system frame. */
13373 || (new_x
== it
->last_visible_x
13374 && FRAME_WINDOW_P (it
->f
))))
13376 /* End of a continued line. */
13379 || (new_x
== it
->last_visible_x
13380 && FRAME_WINDOW_P (it
->f
)))
13382 /* Current glyph is the only one on the line or
13383 fits exactly on the line. We must continue
13384 the line because we can't draw the cursor
13385 after the glyph. */
13386 row
->continued_p
= 1;
13387 it
->current_x
= new_x
;
13388 it
->continuation_lines_width
+= new_x
;
13390 if (i
== nglyphs
- 1)
13391 set_iterator_to_next (it
, 1);
13393 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13394 && !FRAME_WINDOW_P (it
->f
))
13396 /* A padding glyph that doesn't fit on this line.
13397 This means the whole character doesn't fit
13399 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13401 /* Fill the rest of the row with continuation
13402 glyphs like in 20.x. */
13403 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13404 < row
->glyphs
[1 + TEXT_AREA
])
13405 produce_special_glyphs (it
, IT_CONTINUATION
);
13407 row
->continued_p
= 1;
13408 it
->current_x
= x_before
;
13409 it
->continuation_lines_width
+= x_before
;
13411 /* Restore the height to what it was before the
13412 element not fitting on the line. */
13413 it
->max_ascent
= ascent
;
13414 it
->max_descent
= descent
;
13415 it
->max_phys_ascent
= phys_ascent
;
13416 it
->max_phys_descent
= phys_descent
;
13418 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13420 /* A TAB that extends past the right edge of the
13421 window. This produces a single glyph on
13422 window system frames. We leave the glyph in
13423 this row and let it fill the row, but don't
13424 consume the TAB. */
13425 it
->continuation_lines_width
+= it
->last_visible_x
;
13426 row
->ends_in_middle_of_char_p
= 1;
13427 row
->continued_p
= 1;
13428 glyph
->pixel_width
= it
->last_visible_x
- x
;
13429 it
->starts_in_middle_of_char_p
= 1;
13433 /* Something other than a TAB that draws past
13434 the right edge of the window. Restore
13435 positions to values before the element. */
13436 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13438 /* Display continuation glyphs. */
13439 if (!FRAME_WINDOW_P (it
->f
))
13440 produce_special_glyphs (it
, IT_CONTINUATION
);
13441 row
->continued_p
= 1;
13443 it
->continuation_lines_width
+= x
;
13445 if (nglyphs
> 1 && i
> 0)
13447 row
->ends_in_middle_of_char_p
= 1;
13448 it
->starts_in_middle_of_char_p
= 1;
13451 /* Restore the height to what it was before the
13452 element not fitting on the line. */
13453 it
->max_ascent
= ascent
;
13454 it
->max_descent
= descent
;
13455 it
->max_phys_ascent
= phys_ascent
;
13456 it
->max_phys_descent
= phys_descent
;
13461 else if (new_x
> it
->first_visible_x
)
13463 /* Increment number of glyphs actually displayed. */
13466 if (x
< it
->first_visible_x
)
13467 /* Glyph is partially visible, i.e. row starts at
13468 negative X position. */
13469 row
->x
= x
- it
->first_visible_x
;
13473 /* Glyph is completely off the left margin of the
13474 window. This should not happen because of the
13475 move_it_in_display_line at the start of this
13476 function, unless the text display area of the
13477 window is empty. */
13478 xassert (it
->first_visible_x
<= it
->last_visible_x
);
13482 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13483 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13484 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13485 row
->phys_height
= max (row
->phys_height
,
13486 it
->max_phys_ascent
+ it
->max_phys_descent
);
13488 /* End of this display line if row is continued. */
13489 if (row
->continued_p
)
13493 /* Is this a line end? If yes, we're also done, after making
13494 sure that a non-default face is extended up to the right
13495 margin of the window. */
13496 if (ITERATOR_AT_END_OF_LINE_P (it
))
13498 int used_before
= row
->used
[TEXT_AREA
];
13500 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13502 /* Add a space at the end of the line that is used to
13503 display the cursor there. */
13504 append_space (it
, 0);
13506 /* Extend the face to the end of the line. */
13507 extend_face_to_end_of_line (it
);
13509 /* Make sure we have the position. */
13510 if (used_before
== 0)
13511 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13513 /* Consume the line end. This skips over invisible lines. */
13514 set_iterator_to_next (it
, 1);
13515 it
->continuation_lines_width
= 0;
13519 /* Proceed with next display element. Note that this skips
13520 over lines invisible because of selective display. */
13521 set_iterator_to_next (it
, 1);
13523 /* If we truncate lines, we are done when the last displayed
13524 glyphs reach past the right margin of the window. */
13525 if (it
->truncate_lines_p
13526 && (FRAME_WINDOW_P (it
->f
)
13527 ? (it
->current_x
>= it
->last_visible_x
)
13528 : (it
->current_x
> it
->last_visible_x
)))
13530 /* Maybe add truncation glyphs. */
13531 if (!FRAME_WINDOW_P (it
->f
))
13535 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13536 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13539 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13541 row
->used
[TEXT_AREA
] = i
;
13542 produce_special_glyphs (it
, IT_TRUNCATION
);
13546 row
->truncated_on_right_p
= 1;
13547 it
->continuation_lines_width
= 0;
13548 reseat_at_next_visible_line_start (it
, 0);
13549 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13550 it
->hpos
= hpos_before
;
13551 it
->current_x
= x_before
;
13556 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13557 at the left window margin. */
13558 if (it
->first_visible_x
13559 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13561 if (!FRAME_WINDOW_P (it
->f
))
13562 insert_left_trunc_glyphs (it
);
13563 row
->truncated_on_left_p
= 1;
13566 /* If the start of this line is the overlay arrow-position, then
13567 mark this glyph row as the one containing the overlay arrow.
13568 This is clearly a mess with variable size fonts. It would be
13569 better to let it be displayed like cursors under X. */
13570 if (MARKERP (Voverlay_arrow_position
)
13571 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13572 && (MATRIX_ROW_START_CHARPOS (row
)
13573 == marker_position (Voverlay_arrow_position
))
13574 && STRINGP (Voverlay_arrow_string
)
13575 && ! overlay_arrow_seen
)
13577 /* Overlay arrow in window redisplay is a fringe bitmap. */
13578 if (!FRAME_WINDOW_P (it
->f
))
13580 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13581 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13582 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13583 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13584 struct glyph
*p2
, *end
;
13586 /* Copy the arrow glyphs. */
13587 while (glyph
< arrow_end
)
13590 /* Throw away padding glyphs. */
13592 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13593 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13599 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13603 overlay_arrow_seen
= 1;
13604 row
->overlay_arrow_p
= 1;
13607 /* Compute pixel dimensions of this line. */
13608 compute_line_metrics (it
);
13610 /* Remember the position at which this line ends. */
13611 row
->end
= it
->current
;
13613 /* Maybe set the cursor. */
13614 if (it
->w
->cursor
.vpos
< 0
13615 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13616 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13617 && cursor_row_p (it
->w
, row
))
13618 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13620 /* Highlight trailing whitespace. */
13621 if (!NILP (Vshow_trailing_whitespace
))
13622 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13624 /* Prepare for the next line. This line starts horizontally at (X
13625 HPOS) = (0 0). Vertical positions are incremented. As a
13626 convenience for the caller, IT->glyph_row is set to the next
13628 it
->current_x
= it
->hpos
= 0;
13629 it
->current_y
+= row
->height
;
13632 return row
->displays_text_p
;
13637 /***********************************************************************
13639 ***********************************************************************/
13641 /* Redisplay the menu bar in the frame for window W.
13643 The menu bar of X frames that don't have X toolkit support is
13644 displayed in a special window W->frame->menu_bar_window.
13646 The menu bar of terminal frames is treated specially as far as
13647 glyph matrices are concerned. Menu bar lines are not part of
13648 windows, so the update is done directly on the frame matrix rows
13649 for the menu bar. */
13652 display_menu_bar (w
)
13655 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13660 /* Don't do all this for graphical frames. */
13662 if (!NILP (Vwindow_system
))
13665 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
13670 if (FRAME_MAC_P (f
))
13674 #ifdef USE_X_TOOLKIT
13675 xassert (!FRAME_WINDOW_P (f
));
13676 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13677 it
.first_visible_x
= 0;
13678 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13679 #else /* not USE_X_TOOLKIT */
13680 if (FRAME_WINDOW_P (f
))
13682 /* Menu bar lines are displayed in the desired matrix of the
13683 dummy window menu_bar_window. */
13684 struct window
*menu_w
;
13685 xassert (WINDOWP (f
->menu_bar_window
));
13686 menu_w
= XWINDOW (f
->menu_bar_window
);
13687 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13689 it
.first_visible_x
= 0;
13690 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13694 /* This is a TTY frame, i.e. character hpos/vpos are used as
13696 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13698 it
.first_visible_x
= 0;
13699 it
.last_visible_x
= FRAME_WIDTH (f
);
13701 #endif /* not USE_X_TOOLKIT */
13703 if (! mode_line_inverse_video
)
13704 /* Force the menu-bar to be displayed in the default face. */
13705 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13707 /* Clear all rows of the menu bar. */
13708 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13710 struct glyph_row
*row
= it
.glyph_row
+ i
;
13711 clear_glyph_row (row
);
13712 row
->enabled_p
= 1;
13713 row
->full_width_p
= 1;
13716 /* Display all items of the menu bar. */
13717 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13718 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13720 Lisp_Object string
;
13722 /* Stop at nil string. */
13723 string
= AREF (items
, i
+ 1);
13727 /* Remember where item was displayed. */
13728 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13730 /* Display the item, pad with one space. */
13731 if (it
.current_x
< it
.last_visible_x
)
13732 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13733 SCHARS (string
) + 1, 0, 0, -1);
13736 /* Fill out the line with spaces. */
13737 if (it
.current_x
< it
.last_visible_x
)
13738 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13740 /* Compute the total height of the lines. */
13741 compute_line_metrics (&it
);
13746 /***********************************************************************
13748 ***********************************************************************/
13750 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13751 FORCE is non-zero, redisplay mode lines unconditionally.
13752 Otherwise, redisplay only mode lines that are garbaged. Value is
13753 the number of windows whose mode lines were redisplayed. */
13756 redisplay_mode_lines (window
, force
)
13757 Lisp_Object window
;
13762 while (!NILP (window
))
13764 struct window
*w
= XWINDOW (window
);
13766 if (WINDOWP (w
->hchild
))
13767 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13768 else if (WINDOWP (w
->vchild
))
13769 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13771 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13772 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13774 struct text_pos lpoint
;
13775 struct buffer
*old
= current_buffer
;
13777 /* Set the window's buffer for the mode line display. */
13778 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13779 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13781 /* Point refers normally to the selected window. For any
13782 other window, set up appropriate value. */
13783 if (!EQ (window
, selected_window
))
13785 struct text_pos pt
;
13787 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13788 if (CHARPOS (pt
) < BEGV
)
13789 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13790 else if (CHARPOS (pt
) > (ZV
- 1))
13791 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13793 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13796 /* Display mode lines. */
13797 clear_glyph_matrix (w
->desired_matrix
);
13798 if (display_mode_lines (w
))
13801 w
->must_be_updated_p
= 1;
13804 /* Restore old settings. */
13805 set_buffer_internal_1 (old
);
13806 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13816 /* Display the mode and/or top line of window W. Value is the number
13817 of mode lines displayed. */
13820 display_mode_lines (w
)
13823 Lisp_Object old_selected_window
, old_selected_frame
;
13826 old_selected_frame
= selected_frame
;
13827 selected_frame
= w
->frame
;
13828 old_selected_window
= selected_window
;
13829 XSETWINDOW (selected_window
, w
);
13831 /* These will be set while the mode line specs are processed. */
13832 line_number_displayed
= 0;
13833 w
->column_number_displayed
= Qnil
;
13835 if (WINDOW_WANTS_MODELINE_P (w
))
13837 struct window
*sel_w
= XWINDOW (old_selected_window
);
13839 /* Select mode line face based on the real selected window. */
13840 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
13841 current_buffer
->mode_line_format
);
13845 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13847 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13848 current_buffer
->header_line_format
);
13852 selected_frame
= old_selected_frame
;
13853 selected_window
= old_selected_window
;
13858 /* Display mode or top line of window W. FACE_ID specifies which line
13859 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13860 FORMAT is the mode line format to display. Value is the pixel
13861 height of the mode line displayed. */
13864 display_mode_line (w
, face_id
, format
)
13866 enum face_id face_id
;
13867 Lisp_Object format
;
13872 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13873 prepare_desired_row (it
.glyph_row
);
13875 if (! mode_line_inverse_video
)
13876 /* Force the mode-line to be displayed in the default face. */
13877 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13879 /* Temporarily make frame's keyboard the current kboard so that
13880 kboard-local variables in the mode_line_format will get the right
13882 push_frame_kboard (it
.f
);
13883 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
13884 pop_frame_kboard ();
13886 /* Fill up with spaces. */
13887 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13889 compute_line_metrics (&it
);
13890 it
.glyph_row
->full_width_p
= 1;
13891 it
.glyph_row
->mode_line_p
= 1;
13892 it
.glyph_row
->continued_p
= 0;
13893 it
.glyph_row
->truncated_on_left_p
= 0;
13894 it
.glyph_row
->truncated_on_right_p
= 0;
13896 /* Make a 3D mode-line have a shadow at its right end. */
13897 face
= FACE_FROM_ID (it
.f
, face_id
);
13898 extend_face_to_end_of_line (&it
);
13899 if (face
->box
!= FACE_NO_BOX
)
13901 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13902 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13903 last
->right_box_line_p
= 1;
13906 return it
.glyph_row
->height
;
13909 /* Alist that caches the results of :propertize.
13910 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
13911 Lisp_Object mode_line_proptrans_alist
;
13913 /* List of strings making up the mode-line. */
13914 Lisp_Object mode_line_string_list
;
13916 /* Base face property when building propertized mode line string. */
13917 static Lisp_Object mode_line_string_face
;
13918 static Lisp_Object mode_line_string_face_prop
;
13921 /* Contribute ELT to the mode line for window IT->w. How it
13922 translates into text depends on its data type.
13924 IT describes the display environment in which we display, as usual.
13926 DEPTH is the depth in recursion. It is used to prevent
13927 infinite recursion here.
13929 FIELD_WIDTH is the number of characters the display of ELT should
13930 occupy in the mode line, and PRECISION is the maximum number of
13931 characters to display from ELT's representation. See
13932 display_string for details.
13934 Returns the hpos of the end of the text generated by ELT.
13936 PROPS is a property list to add to any string we encounter.
13938 If RISKY is nonzero, remove (disregard) any properties in any string
13939 we encounter, and ignore :eval and :propertize.
13941 If the global variable `frame_title_ptr' is non-NULL, then the output
13942 is passed to `store_frame_title' instead of `display_string'. */
13945 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
13948 int field_width
, precision
;
13949 Lisp_Object elt
, props
;
13952 int n
= 0, field
, prec
;
13961 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13965 /* A string: output it and check for %-constructs within it. */
13967 const unsigned char *this, *lisp_string
;
13969 if (!NILP (props
) || risky
)
13971 Lisp_Object oprops
, aelt
;
13972 oprops
= Ftext_properties_at (make_number (0), elt
);
13974 if (NILP (Fequal (props
, oprops
)) || risky
)
13976 /* If the starting string has properties,
13977 merge the specified ones onto the existing ones. */
13978 if (! NILP (oprops
) && !risky
)
13982 oprops
= Fcopy_sequence (oprops
);
13984 while (CONSP (tem
))
13986 oprops
= Fplist_put (oprops
, XCAR (tem
),
13987 XCAR (XCDR (tem
)));
13988 tem
= XCDR (XCDR (tem
));
13993 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
13994 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
13996 mode_line_proptrans_alist
13997 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
14004 elt
= Fcopy_sequence (elt
);
14005 Fset_text_properties (make_number (0), Flength (elt
),
14007 /* Add this item to mode_line_proptrans_alist. */
14008 mode_line_proptrans_alist
14009 = Fcons (Fcons (elt
, props
),
14010 mode_line_proptrans_alist
);
14011 /* Truncate mode_line_proptrans_alist
14012 to at most 50 elements. */
14013 tem
= Fnthcdr (make_number (50),
14014 mode_line_proptrans_alist
);
14016 XSETCDR (tem
, Qnil
);
14021 this = SDATA (elt
);
14022 lisp_string
= this;
14026 prec
= precision
- n
;
14027 if (frame_title_ptr
)
14028 n
+= store_frame_title (SDATA (elt
), -1, prec
);
14029 else if (!NILP (mode_line_string_list
))
14030 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
14032 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
14033 0, prec
, 0, STRING_MULTIBYTE (elt
));
14038 while ((precision
<= 0 || n
< precision
)
14040 && (frame_title_ptr
14041 || !NILP (mode_line_string_list
)
14042 || it
->current_x
< it
->last_visible_x
))
14044 const unsigned char *last
= this;
14046 /* Advance to end of string or next format specifier. */
14047 while ((c
= *this++) != '\0' && c
!= '%')
14050 if (this - 1 != last
)
14052 /* Output to end of string or up to '%'. Field width
14053 is length of string. Don't output more than
14054 PRECISION allows us. */
14057 prec
= chars_in_text (last
, this - last
);
14058 if (precision
> 0 && prec
> precision
- n
)
14059 prec
= precision
- n
;
14061 if (frame_title_ptr
)
14062 n
+= store_frame_title (last
, 0, prec
);
14063 else if (!NILP (mode_line_string_list
))
14065 int bytepos
= last
- lisp_string
;
14066 int charpos
= string_byte_to_char (elt
, bytepos
);
14067 n
+= store_mode_line_string (NULL
,
14068 Fsubstring (elt
, make_number (charpos
),
14069 make_number (charpos
+ prec
)),
14074 int bytepos
= last
- lisp_string
;
14075 int charpos
= string_byte_to_char (elt
, bytepos
);
14076 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
14078 STRING_MULTIBYTE (elt
));
14081 else /* c == '%' */
14083 const unsigned char *percent_position
= this;
14085 /* Get the specified minimum width. Zero means
14088 while ((c
= *this++) >= '0' && c
<= '9')
14089 field
= field
* 10 + c
- '0';
14091 /* Don't pad beyond the total padding allowed. */
14092 if (field_width
- n
> 0 && field
> field_width
- n
)
14093 field
= field_width
- n
;
14095 /* Note that either PRECISION <= 0 or N < PRECISION. */
14096 prec
= precision
- n
;
14099 n
+= display_mode_element (it
, depth
, field
, prec
,
14100 Vglobal_mode_string
, props
,
14105 int bytepos
, charpos
;
14106 unsigned char *spec
;
14108 bytepos
= percent_position
- lisp_string
;
14109 charpos
= (STRING_MULTIBYTE (elt
)
14110 ? string_byte_to_char (elt
, bytepos
)
14114 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
14116 if (frame_title_ptr
)
14117 n
+= store_frame_title (spec
, field
, prec
);
14118 else if (!NILP (mode_line_string_list
))
14120 int len
= strlen (spec
);
14121 Lisp_Object tem
= make_string (spec
, len
);
14122 props
= Ftext_properties_at (make_number (charpos
), elt
);
14123 /* Should only keep face property in props */
14124 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
14128 int nglyphs_before
, nwritten
;
14130 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14131 nwritten
= display_string (spec
, Qnil
, elt
,
14136 /* Assign to the glyphs written above the
14137 string where the `%x' came from, position
14141 struct glyph
*glyph
14142 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
14146 for (i
= 0; i
< nwritten
; ++i
)
14148 glyph
[i
].object
= elt
;
14149 glyph
[i
].charpos
= charpos
;
14164 /* A symbol: process the value of the symbol recursively
14165 as if it appeared here directly. Avoid error if symbol void.
14166 Special case: if value of symbol is a string, output the string
14169 register Lisp_Object tem
;
14171 /* If the variable is not marked as risky to set
14172 then its contents are risky to use. */
14173 if (NILP (Fget (elt
, Qrisky_local_variable
)))
14176 tem
= Fboundp (elt
);
14179 tem
= Fsymbol_value (elt
);
14180 /* If value is a string, output that string literally:
14181 don't check for % within it. */
14185 if (!EQ (tem
, elt
))
14187 /* Give up right away for nil or t. */
14197 register Lisp_Object car
, tem
;
14199 /* A cons cell: five distinct cases.
14200 If first element is :eval or :propertize, do something special.
14201 If first element is a string or a cons, process all the elements
14202 and effectively concatenate them.
14203 If first element is a negative number, truncate displaying cdr to
14204 at most that many characters. If positive, pad (with spaces)
14205 to at least that many characters.
14206 If first element is a symbol, process the cadr or caddr recursively
14207 according to whether the symbol's value is non-nil or nil. */
14209 if (EQ (car
, QCeval
))
14211 /* An element of the form (:eval FORM) means evaluate FORM
14212 and use the result as mode line elements. */
14217 if (CONSP (XCDR (elt
)))
14220 spec
= safe_eval (XCAR (XCDR (elt
)));
14221 n
+= display_mode_element (it
, depth
, field_width
- n
,
14222 precision
- n
, spec
, props
,
14226 else if (EQ (car
, QCpropertize
))
14228 /* An element of the form (:propertize ELT PROPS...)
14229 means display ELT but applying properties PROPS. */
14234 if (CONSP (XCDR (elt
)))
14235 n
+= display_mode_element (it
, depth
, field_width
- n
,
14236 precision
- n
, XCAR (XCDR (elt
)),
14237 XCDR (XCDR (elt
)), risky
);
14239 else if (SYMBOLP (car
))
14241 tem
= Fboundp (car
);
14245 /* elt is now the cdr, and we know it is a cons cell.
14246 Use its car if CAR has a non-nil value. */
14249 tem
= Fsymbol_value (car
);
14256 /* Symbol's value is nil (or symbol is unbound)
14257 Get the cddr of the original list
14258 and if possible find the caddr and use that. */
14262 else if (!CONSP (elt
))
14267 else if (INTEGERP (car
))
14269 register int lim
= XINT (car
);
14273 /* Negative int means reduce maximum width. */
14274 if (precision
<= 0)
14277 precision
= min (precision
, -lim
);
14281 /* Padding specified. Don't let it be more than
14282 current maximum. */
14284 lim
= min (precision
, lim
);
14286 /* If that's more padding than already wanted, queue it.
14287 But don't reduce padding already specified even if
14288 that is beyond the current truncation point. */
14289 field_width
= max (lim
, field_width
);
14293 else if (STRINGP (car
) || CONSP (car
))
14295 register int limit
= 50;
14296 /* Limit is to protect against circular lists. */
14299 && (precision
<= 0 || n
< precision
))
14301 n
+= display_mode_element (it
, depth
, field_width
- n
,
14302 precision
- n
, XCAR (elt
),
14312 if (frame_title_ptr
)
14313 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
14314 else if (!NILP (mode_line_string_list
))
14315 n
+= store_mode_line_string ("*invalid*", Qnil
, 0, 0, precision
- n
, Qnil
);
14317 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
14318 precision
- n
, 0, 0);
14322 /* Pad to FIELD_WIDTH. */
14323 if (field_width
> 0 && n
< field_width
)
14325 if (frame_title_ptr
)
14326 n
+= store_frame_title ("", field_width
- n
, 0);
14327 else if (!NILP (mode_line_string_list
))
14328 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
14330 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
14337 /* Store a mode-line string element in mode_line_string_list.
14339 If STRING is non-null, display that C string. Otherwise, the Lisp
14340 string LISP_STRING is displayed.
14342 FIELD_WIDTH is the minimum number of output glyphs to produce.
14343 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14344 with spaces. FIELD_WIDTH <= 0 means don't pad.
14346 PRECISION is the maximum number of characters to output from
14347 STRING. PRECISION <= 0 means don't truncate the string.
14349 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
14350 properties to the string.
14352 PROPS are the properties to add to the string.
14353 The mode_line_string_face face property is always added to the string.
14356 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
14358 Lisp_Object lisp_string
;
14367 if (string
!= NULL
)
14369 len
= strlen (string
);
14370 if (precision
> 0 && len
> precision
)
14372 lisp_string
= make_string (string
, len
);
14374 props
= mode_line_string_face_prop
;
14375 else if (!NILP (mode_line_string_face
))
14377 Lisp_Object face
= Fplist_get (props
, Qface
);
14378 props
= Fcopy_sequence (props
);
14380 face
= mode_line_string_face
;
14382 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14383 props
= Fplist_put (props
, Qface
, face
);
14385 Fadd_text_properties (make_number (0), make_number (len
),
14386 props
, lisp_string
);
14390 len
= XFASTINT (Flength (lisp_string
));
14391 if (precision
> 0 && len
> precision
)
14394 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
14397 if (!NILP (mode_line_string_face
))
14401 props
= Ftext_properties_at (make_number (0), lisp_string
);
14402 face
= Fplist_get (props
, Qface
);
14404 face
= mode_line_string_face
;
14406 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14407 props
= Fcons (Qface
, Fcons (face
, Qnil
));
14409 lisp_string
= Fcopy_sequence (lisp_string
);
14412 Fadd_text_properties (make_number (0), make_number (len
),
14413 props
, lisp_string
);
14418 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14422 if (field_width
> len
)
14424 field_width
-= len
;
14425 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
14427 Fadd_text_properties (make_number (0), make_number (field_width
),
14428 props
, lisp_string
);
14429 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14437 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
14439 doc
: /* Return the mode-line of selected window as a string.
14440 First optional arg FORMAT specifies a different format string (see
14441 `mode-line-format' for details) to use. If FORMAT is t, return
14442 the buffer's header-line. Second optional arg WINDOW specifies a
14443 different window to use as the context for the formatting.
14444 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
14445 (format
, window
, no_props
)
14446 Lisp_Object format
, window
, no_props
;
14451 struct buffer
*old_buffer
= NULL
;
14452 enum face_id face_id
= DEFAULT_FACE_ID
;
14455 window
= selected_window
;
14456 CHECK_WINDOW (window
);
14457 w
= XWINDOW (window
);
14458 CHECK_BUFFER (w
->buffer
);
14460 if (XBUFFER (w
->buffer
) != current_buffer
)
14462 old_buffer
= current_buffer
;
14463 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14466 if (NILP (format
) || EQ (format
, Qt
))
14468 face_id
= NILP (format
)
14469 ? CURRENT_MODE_LINE_FACE_ID (w
) :
14470 HEADER_LINE_FACE_ID
;
14471 format
= NILP (format
)
14472 ? current_buffer
->mode_line_format
14473 : current_buffer
->header_line_format
;
14476 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14478 if (NILP (no_props
))
14480 mode_line_string_face
=
14481 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
14482 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
14483 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
14485 mode_line_string_face_prop
=
14486 NILP (mode_line_string_face
) ? Qnil
:
14487 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
14489 /* We need a dummy last element in mode_line_string_list to
14490 indicate we are building the propertized mode-line string.
14491 Using mode_line_string_face_prop here GC protects it. */
14492 mode_line_string_list
=
14493 Fcons (mode_line_string_face_prop
, Qnil
);
14494 frame_title_ptr
= NULL
;
14498 mode_line_string_face_prop
= Qnil
;
14499 mode_line_string_list
= Qnil
;
14500 frame_title_ptr
= frame_title_buf
;
14503 push_frame_kboard (it
.f
);
14504 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14505 pop_frame_kboard ();
14508 set_buffer_internal_1 (old_buffer
);
14510 if (NILP (no_props
))
14513 mode_line_string_list
= Fnreverse (mode_line_string_list
);
14514 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
14515 make_string ("", 0));
14516 mode_line_string_face_prop
= Qnil
;
14517 mode_line_string_list
= Qnil
;
14521 len
= frame_title_ptr
- frame_title_buf
;
14522 if (len
> 0 && frame_title_ptr
[-1] == '-')
14524 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
14525 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
14527 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
14528 if (len
> frame_title_ptr
- frame_title_buf
)
14529 len
= frame_title_ptr
- frame_title_buf
;
14532 frame_title_ptr
= NULL
;
14533 return make_string (frame_title_buf
, len
);
14536 /* Write a null-terminated, right justified decimal representation of
14537 the positive integer D to BUF using a minimal field width WIDTH. */
14540 pint2str (buf
, width
, d
)
14541 register char *buf
;
14542 register int width
;
14545 register char *p
= buf
;
14553 *p
++ = d
% 10 + '0';
14558 for (width
-= (int) (p
- buf
); width
> 0; --width
)
14569 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
14570 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
14571 type of CODING_SYSTEM. Return updated pointer into BUF. */
14573 static unsigned char invalid_eol_type
[] = "(*invalid*)";
14576 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
14577 Lisp_Object coding_system
;
14578 register char *buf
;
14582 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
14583 const unsigned char *eol_str
;
14585 /* The EOL conversion we are using. */
14586 Lisp_Object eoltype
;
14588 val
= Fget (coding_system
, Qcoding_system
);
14591 if (!VECTORP (val
)) /* Not yet decided. */
14596 eoltype
= eol_mnemonic_undecided
;
14597 /* Don't mention EOL conversion if it isn't decided. */
14601 Lisp_Object eolvalue
;
14603 eolvalue
= Fget (coding_system
, Qeol_type
);
14606 *buf
++ = XFASTINT (AREF (val
, 1));
14610 /* The EOL conversion that is normal on this system. */
14612 if (NILP (eolvalue
)) /* Not yet decided. */
14613 eoltype
= eol_mnemonic_undecided
;
14614 else if (VECTORP (eolvalue
)) /* Not yet decided. */
14615 eoltype
= eol_mnemonic_undecided
;
14616 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
14617 eoltype
= (XFASTINT (eolvalue
) == 0
14618 ? eol_mnemonic_unix
14619 : (XFASTINT (eolvalue
) == 1
14620 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
14626 /* Mention the EOL conversion if it is not the usual one. */
14627 if (STRINGP (eoltype
))
14629 eol_str
= SDATA (eoltype
);
14630 eol_str_len
= SBYTES (eoltype
);
14632 else if (INTEGERP (eoltype
)
14633 && CHAR_VALID_P (XINT (eoltype
), 0))
14635 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
14636 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
14641 eol_str
= invalid_eol_type
;
14642 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14644 bcopy (eol_str
, buf
, eol_str_len
);
14645 buf
+= eol_str_len
;
14651 /* Return a string for the output of a mode line %-spec for window W,
14652 generated by character C. PRECISION >= 0 means don't return a
14653 string longer than that value. FIELD_WIDTH > 0 means pad the
14654 string returned with spaces to that value. Return 1 in *MULTIBYTE
14655 if the result is multibyte text. */
14657 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14660 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14663 int field_width
, precision
;
14667 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14668 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14669 struct buffer
*b
= XBUFFER (w
->buffer
);
14677 if (!NILP (b
->read_only
))
14679 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14684 /* This differs from %* only for a modified read-only buffer. */
14685 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14687 if (!NILP (b
->read_only
))
14692 /* This differs from %* in ignoring read-only-ness. */
14693 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14705 if (command_loop_level
> 5)
14707 p
= decode_mode_spec_buf
;
14708 for (i
= 0; i
< command_loop_level
; i
++)
14711 return decode_mode_spec_buf
;
14719 if (command_loop_level
> 5)
14721 p
= decode_mode_spec_buf
;
14722 for (i
= 0; i
< command_loop_level
; i
++)
14725 return decode_mode_spec_buf
;
14732 /* Let lots_of_dashes be a string of infinite length. */
14733 if (!NILP (mode_line_string_list
))
14735 if (field_width
<= 0
14736 || field_width
> sizeof (lots_of_dashes
))
14738 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
14739 decode_mode_spec_buf
[i
] = '-';
14740 decode_mode_spec_buf
[i
] = '\0';
14741 return decode_mode_spec_buf
;
14744 return lots_of_dashes
;
14753 int col
= (int) current_column (); /* iftc */
14754 w
->column_number_displayed
= make_number (col
);
14755 pint2str (decode_mode_spec_buf
, field_width
, col
);
14756 return decode_mode_spec_buf
;
14760 /* %F displays the frame name. */
14761 if (!NILP (f
->title
))
14762 return (char *) SDATA (f
->title
);
14763 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14764 return (char *) SDATA (f
->name
);
14773 int startpos
= XMARKER (w
->start
)->charpos
;
14774 int startpos_byte
= marker_byte_position (w
->start
);
14775 int line
, linepos
, linepos_byte
, topline
;
14777 int height
= XFASTINT (w
->height
);
14779 /* If we decided that this buffer isn't suitable for line numbers,
14780 don't forget that too fast. */
14781 if (EQ (w
->base_line_pos
, w
->buffer
))
14783 /* But do forget it, if the window shows a different buffer now. */
14784 else if (BUFFERP (w
->base_line_pos
))
14785 w
->base_line_pos
= Qnil
;
14787 /* If the buffer is very big, don't waste time. */
14788 if (INTEGERP (Vline_number_display_limit
)
14789 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14791 w
->base_line_pos
= Qnil
;
14792 w
->base_line_number
= Qnil
;
14796 if (!NILP (w
->base_line_number
)
14797 && !NILP (w
->base_line_pos
)
14798 && XFASTINT (w
->base_line_pos
) <= startpos
)
14800 line
= XFASTINT (w
->base_line_number
);
14801 linepos
= XFASTINT (w
->base_line_pos
);
14802 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14807 linepos
= BUF_BEGV (b
);
14808 linepos_byte
= BUF_BEGV_BYTE (b
);
14811 /* Count lines from base line to window start position. */
14812 nlines
= display_count_lines (linepos
, linepos_byte
,
14816 topline
= nlines
+ line
;
14818 /* Determine a new base line, if the old one is too close
14819 or too far away, or if we did not have one.
14820 "Too close" means it's plausible a scroll-down would
14821 go back past it. */
14822 if (startpos
== BUF_BEGV (b
))
14824 w
->base_line_number
= make_number (topline
);
14825 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14827 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14828 || linepos
== BUF_BEGV (b
))
14830 int limit
= BUF_BEGV (b
);
14831 int limit_byte
= BUF_BEGV_BYTE (b
);
14833 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14835 if (startpos
- distance
> limit
)
14837 limit
= startpos
- distance
;
14838 limit_byte
= CHAR_TO_BYTE (limit
);
14841 nlines
= display_count_lines (startpos
, startpos_byte
,
14843 - (height
* 2 + 30),
14845 /* If we couldn't find the lines we wanted within
14846 line_number_display_limit_width chars per line,
14847 give up on line numbers for this window. */
14848 if (position
== limit_byte
&& limit
== startpos
- distance
)
14850 w
->base_line_pos
= w
->buffer
;
14851 w
->base_line_number
= Qnil
;
14855 w
->base_line_number
= make_number (topline
- nlines
);
14856 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14859 /* Now count lines from the start pos to point. */
14860 nlines
= display_count_lines (startpos
, startpos_byte
,
14861 PT_BYTE
, PT
, &junk
);
14863 /* Record that we did display the line number. */
14864 line_number_displayed
= 1;
14866 /* Make the string to show. */
14867 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14868 return decode_mode_spec_buf
;
14871 char* p
= decode_mode_spec_buf
;
14872 int pad
= field_width
- 2;
14878 return decode_mode_spec_buf
;
14884 obj
= b
->mode_name
;
14888 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14894 int pos
= marker_position (w
->start
);
14895 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14897 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14899 if (pos
<= BUF_BEGV (b
))
14904 else if (pos
<= BUF_BEGV (b
))
14908 if (total
> 1000000)
14909 /* Do it differently for a large value, to avoid overflow. */
14910 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14912 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14913 /* We can't normally display a 3-digit number,
14914 so get us a 2-digit number that is close. */
14917 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14918 return decode_mode_spec_buf
;
14922 /* Display percentage of size above the bottom of the screen. */
14925 int toppos
= marker_position (w
->start
);
14926 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14927 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14929 if (botpos
>= BUF_ZV (b
))
14931 if (toppos
<= BUF_BEGV (b
))
14938 if (total
> 1000000)
14939 /* Do it differently for a large value, to avoid overflow. */
14940 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14942 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14943 /* We can't normally display a 3-digit number,
14944 so get us a 2-digit number that is close. */
14947 if (toppos
<= BUF_BEGV (b
))
14948 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14950 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14951 return decode_mode_spec_buf
;
14956 /* status of process */
14957 obj
= Fget_buffer_process (w
->buffer
);
14959 return "no process";
14960 #ifdef subprocesses
14961 obj
= Fsymbol_name (Fprocess_status (obj
));
14965 case 't': /* indicate TEXT or BINARY */
14966 #ifdef MODE_LINE_BINARY_TEXT
14967 return MODE_LINE_BINARY_TEXT (b
);
14973 /* coding-system (not including end-of-line format) */
14975 /* coding-system (including end-of-line type) */
14977 int eol_flag
= (c
== 'Z');
14978 char *p
= decode_mode_spec_buf
;
14980 if (! FRAME_WINDOW_P (f
))
14982 /* No need to mention EOL here--the terminal never needs
14983 to do EOL conversion. */
14984 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14985 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14987 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14990 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14991 #ifdef subprocesses
14992 obj
= Fget_buffer_process (Fcurrent_buffer ());
14993 if (PROCESSP (obj
))
14995 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14997 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
15000 #endif /* subprocesses */
15003 return decode_mode_spec_buf
;
15009 *multibyte
= STRING_MULTIBYTE (obj
);
15010 return (char *) SDATA (obj
);
15017 /* Count up to COUNT lines starting from START / START_BYTE.
15018 But don't go beyond LIMIT_BYTE.
15019 Return the number of lines thus found (always nonnegative).
15021 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
15024 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
15025 int start
, start_byte
, limit_byte
, count
;
15028 register unsigned char *cursor
;
15029 unsigned char *base
;
15031 register int ceiling
;
15032 register unsigned char *ceiling_addr
;
15033 int orig_count
= count
;
15035 /* If we are not in selective display mode,
15036 check only for newlines. */
15037 int selective_display
= (!NILP (current_buffer
->selective_display
)
15038 && !INTEGERP (current_buffer
->selective_display
));
15042 while (start_byte
< limit_byte
)
15044 ceiling
= BUFFER_CEILING_OF (start_byte
);
15045 ceiling
= min (limit_byte
- 1, ceiling
);
15046 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
15047 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
15050 if (selective_display
)
15051 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
15054 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
15057 if (cursor
!= ceiling_addr
)
15061 start_byte
+= cursor
- base
+ 1;
15062 *byte_pos_ptr
= start_byte
;
15066 if (++cursor
== ceiling_addr
)
15072 start_byte
+= cursor
- base
;
15077 while (start_byte
> limit_byte
)
15079 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
15080 ceiling
= max (limit_byte
, ceiling
);
15081 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
15082 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
15085 if (selective_display
)
15086 while (--cursor
!= ceiling_addr
15087 && *cursor
!= '\n' && *cursor
!= 015)
15090 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
15093 if (cursor
!= ceiling_addr
)
15097 start_byte
+= cursor
- base
+ 1;
15098 *byte_pos_ptr
= start_byte
;
15099 /* When scanning backwards, we should
15100 not count the newline posterior to which we stop. */
15101 return - orig_count
- 1;
15107 /* Here we add 1 to compensate for the last decrement
15108 of CURSOR, which took it past the valid range. */
15109 start_byte
+= cursor
- base
+ 1;
15113 *byte_pos_ptr
= limit_byte
;
15116 return - orig_count
+ count
;
15117 return orig_count
- count
;
15123 /***********************************************************************
15125 ***********************************************************************/
15127 /* Display a NUL-terminated string, starting with index START.
15129 If STRING is non-null, display that C string. Otherwise, the Lisp
15130 string LISP_STRING is displayed.
15132 If FACE_STRING is not nil, FACE_STRING_POS is a position in
15133 FACE_STRING. Display STRING or LISP_STRING with the face at
15134 FACE_STRING_POS in FACE_STRING:
15136 Display the string in the environment given by IT, but use the
15137 standard display table, temporarily.
15139 FIELD_WIDTH is the minimum number of output glyphs to produce.
15140 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15141 with spaces. If STRING has more characters, more than FIELD_WIDTH
15142 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
15144 PRECISION is the maximum number of characters to output from
15145 STRING. PRECISION < 0 means don't truncate the string.
15147 This is roughly equivalent to printf format specifiers:
15149 FIELD_WIDTH PRECISION PRINTF
15150 ----------------------------------------
15156 MULTIBYTE zero means do not display multibyte chars, > 0 means do
15157 display them, and < 0 means obey the current buffer's value of
15158 enable_multibyte_characters.
15160 Value is the number of glyphs produced. */
15163 display_string (string
, lisp_string
, face_string
, face_string_pos
,
15164 start
, it
, field_width
, precision
, max_x
, multibyte
)
15165 unsigned char *string
;
15166 Lisp_Object lisp_string
;
15167 Lisp_Object face_string
;
15168 int face_string_pos
;
15171 int field_width
, precision
, max_x
;
15174 int hpos_at_start
= it
->hpos
;
15175 int saved_face_id
= it
->face_id
;
15176 struct glyph_row
*row
= it
->glyph_row
;
15178 /* Initialize the iterator IT for iteration over STRING beginning
15179 with index START. */
15180 reseat_to_string (it
, string
, lisp_string
, start
,
15181 precision
, field_width
, multibyte
);
15183 /* If displaying STRING, set up the face of the iterator
15184 from LISP_STRING, if that's given. */
15185 if (STRINGP (face_string
))
15191 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
15192 0, it
->region_beg_charpos
,
15193 it
->region_end_charpos
,
15194 &endptr
, it
->base_face_id
, 0);
15195 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15196 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
15199 /* Set max_x to the maximum allowed X position. Don't let it go
15200 beyond the right edge of the window. */
15202 max_x
= it
->last_visible_x
;
15204 max_x
= min (max_x
, it
->last_visible_x
);
15206 /* Skip over display elements that are not visible. because IT->w is
15208 if (it
->current_x
< it
->first_visible_x
)
15209 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
15210 MOVE_TO_POS
| MOVE_TO_X
);
15212 row
->ascent
= it
->max_ascent
;
15213 row
->height
= it
->max_ascent
+ it
->max_descent
;
15214 row
->phys_ascent
= it
->max_phys_ascent
;
15215 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15217 /* This condition is for the case that we are called with current_x
15218 past last_visible_x. */
15219 while (it
->current_x
< max_x
)
15221 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
15223 /* Get the next display element. */
15224 if (!get_next_display_element (it
))
15227 /* Produce glyphs. */
15228 x_before
= it
->current_x
;
15229 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15230 PRODUCE_GLYPHS (it
);
15232 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
15235 while (i
< nglyphs
)
15237 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15239 if (!it
->truncate_lines_p
15240 && x
+ glyph
->pixel_width
> max_x
)
15242 /* End of continued line or max_x reached. */
15243 if (CHAR_GLYPH_PADDING_P (*glyph
))
15245 /* A wide character is unbreakable. */
15246 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15247 it
->current_x
= x_before
;
15251 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15256 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
15258 /* Glyph is at least partially visible. */
15260 if (x
< it
->first_visible_x
)
15261 it
->glyph_row
->x
= x
- it
->first_visible_x
;
15265 /* Glyph is off the left margin of the display area.
15266 Should not happen. */
15270 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15271 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15272 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15273 row
->phys_height
= max (row
->phys_height
,
15274 it
->max_phys_ascent
+ it
->max_phys_descent
);
15275 x
+= glyph
->pixel_width
;
15279 /* Stop if max_x reached. */
15283 /* Stop at line ends. */
15284 if (ITERATOR_AT_END_OF_LINE_P (it
))
15286 it
->continuation_lines_width
= 0;
15290 set_iterator_to_next (it
, 1);
15292 /* Stop if truncating at the right edge. */
15293 if (it
->truncate_lines_p
15294 && it
->current_x
>= it
->last_visible_x
)
15296 /* Add truncation mark, but don't do it if the line is
15297 truncated at a padding space. */
15298 if (IT_CHARPOS (*it
) < it
->string_nchars
)
15300 if (!FRAME_WINDOW_P (it
->f
))
15304 if (it
->current_x
> it
->last_visible_x
)
15306 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15307 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15309 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15311 row
->used
[TEXT_AREA
] = i
;
15312 produce_special_glyphs (it
, IT_TRUNCATION
);
15315 produce_special_glyphs (it
, IT_TRUNCATION
);
15317 it
->glyph_row
->truncated_on_right_p
= 1;
15323 /* Maybe insert a truncation at the left. */
15324 if (it
->first_visible_x
15325 && IT_CHARPOS (*it
) > 0)
15327 if (!FRAME_WINDOW_P (it
->f
))
15328 insert_left_trunc_glyphs (it
);
15329 it
->glyph_row
->truncated_on_left_p
= 1;
15332 it
->face_id
= saved_face_id
;
15334 /* Value is number of columns displayed. */
15335 return it
->hpos
- hpos_at_start
;
15340 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
15341 appears as an element of LIST or as the car of an element of LIST.
15342 If PROPVAL is a list, compare each element against LIST in that
15343 way, and return 1/2 if any element of PROPVAL is found in LIST.
15344 Otherwise return 0. This function cannot quit.
15345 The return value is 2 if the text is invisible but with an ellipsis
15346 and 1 if it's invisible and without an ellipsis. */
15349 invisible_p (propval
, list
)
15350 register Lisp_Object propval
;
15353 register Lisp_Object tail
, proptail
;
15355 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15357 register Lisp_Object tem
;
15359 if (EQ (propval
, tem
))
15361 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
15362 return NILP (XCDR (tem
)) ? 1 : 2;
15365 if (CONSP (propval
))
15367 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
15369 Lisp_Object propelt
;
15370 propelt
= XCAR (proptail
);
15371 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15373 register Lisp_Object tem
;
15375 if (EQ (propelt
, tem
))
15377 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
15378 return NILP (XCDR (tem
)) ? 1 : 2;
15387 /***********************************************************************
15389 ***********************************************************************/
15391 /* Value is the internal representation of the specified cursor type
15392 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
15393 of the bar cursor. */
15395 enum text_cursor_kinds
15396 get_specified_cursor_type (arg
, width
)
15400 enum text_cursor_kinds type
;
15405 if (EQ (arg
, Qbox
))
15406 return FILLED_BOX_CURSOR
;
15408 if (EQ (arg
, Qhollow
))
15409 return HOLLOW_BOX_CURSOR
;
15411 if (EQ (arg
, Qbar
))
15418 && EQ (XCAR (arg
), Qbar
)
15419 && INTEGERP (XCDR (arg
))
15420 && XINT (XCDR (arg
)) >= 0)
15422 *width
= XINT (XCDR (arg
));
15426 if (EQ (arg
, Qhbar
))
15429 return HBAR_CURSOR
;
15433 && EQ (XCAR (arg
), Qhbar
)
15434 && INTEGERP (XCDR (arg
))
15435 && XINT (XCDR (arg
)) >= 0)
15437 *width
= XINT (XCDR (arg
));
15438 return HBAR_CURSOR
;
15441 /* Treat anything unknown as "hollow box cursor".
15442 It was bad to signal an error; people have trouble fixing
15443 .Xdefaults with Emacs, when it has something bad in it. */
15444 type
= HOLLOW_BOX_CURSOR
;
15449 /* Set the default cursor types for specified frame. */
15451 set_frame_cursor_types (f
, arg
)
15458 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
15459 FRAME_CURSOR_WIDTH (f
) = width
;
15461 /* By default, set up the blink-off state depending on the on-state. */
15463 tem
= Fassoc (arg
, Vblink_cursor_alist
);
15466 FRAME_BLINK_OFF_CURSOR (f
)
15467 = get_specified_cursor_type (XCDR (tem
), &width
);
15468 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
15471 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
15475 /* Return the cursor we want to be displayed in window W. Return
15476 width of bar/hbar cursor through WIDTH arg. Return with
15477 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
15478 (i.e. if the `system caret' should track this cursor).
15480 In a mini-buffer window, we want the cursor only to appear if we
15481 are reading input from this window. For the selected window, we
15482 want the cursor type given by the frame parameter or buffer local
15483 setting of cursor-type. If explicitly marked off, draw no cursor.
15484 In all other cases, we want a hollow box cursor. */
15486 enum text_cursor_kinds
15487 get_window_cursor_type (w
, width
, active_cursor
)
15490 int *active_cursor
;
15492 struct frame
*f
= XFRAME (w
->frame
);
15493 struct buffer
*b
= XBUFFER (w
->buffer
);
15494 int cursor_type
= DEFAULT_CURSOR
;
15495 Lisp_Object alt_cursor
;
15496 int non_selected
= 0;
15498 *active_cursor
= 1;
15501 if (cursor_in_echo_area
15502 && FRAME_HAS_MINIBUF_P (f
)
15503 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
15505 if (w
== XWINDOW (echo_area_window
))
15507 *width
= FRAME_CURSOR_WIDTH (f
);
15508 return FRAME_DESIRED_CURSOR (f
);
15511 *active_cursor
= 0;
15515 /* Nonselected window or nonselected frame. */
15516 else if (w
!= XWINDOW (f
->selected_window
)
15517 #ifdef HAVE_WINDOW_SYSTEM
15518 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
15522 *active_cursor
= 0;
15524 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
15530 /* Never display a cursor in a window in which cursor-type is nil. */
15531 if (NILP (b
->cursor_type
))
15534 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
15537 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
15538 return get_specified_cursor_type (alt_cursor
, width
);
15541 /* Get the normal cursor type for this window. */
15542 if (EQ (b
->cursor_type
, Qt
))
15544 cursor_type
= FRAME_DESIRED_CURSOR (f
);
15545 *width
= FRAME_CURSOR_WIDTH (f
);
15548 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
15550 /* Use normal cursor if not blinked off. */
15551 if (!w
->cursor_off_p
)
15552 return cursor_type
;
15554 /* Cursor is blinked off, so determine how to "toggle" it. */
15556 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
15557 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
15558 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
15560 /* Then see if frame has specified a specific blink off cursor type. */
15561 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
15563 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
15564 return FRAME_BLINK_OFF_CURSOR (f
);
15567 /* Finally perform built-in cursor blinking:
15568 filled box <-> hollow box
15569 wide [h]bar <-> narrow [h]bar
15570 narrow [h]bar <-> no cursor
15571 other type <-> no cursor */
15573 if (cursor_type
== FILLED_BOX_CURSOR
)
15574 return HOLLOW_BOX_CURSOR
;
15576 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
15579 return cursor_type
;
15586 /***********************************************************************
15588 ***********************************************************************/
15593 Vwith_echo_area_save_vector
= Qnil
;
15594 staticpro (&Vwith_echo_area_save_vector
);
15596 Vmessage_stack
= Qnil
;
15597 staticpro (&Vmessage_stack
);
15599 Qinhibit_redisplay
= intern ("inhibit-redisplay");
15600 staticpro (&Qinhibit_redisplay
);
15602 message_dolog_marker1
= Fmake_marker ();
15603 staticpro (&message_dolog_marker1
);
15604 message_dolog_marker2
= Fmake_marker ();
15605 staticpro (&message_dolog_marker2
);
15606 message_dolog_marker3
= Fmake_marker ();
15607 staticpro (&message_dolog_marker3
);
15610 defsubr (&Sdump_frame_glyph_matrix
);
15611 defsubr (&Sdump_glyph_matrix
);
15612 defsubr (&Sdump_glyph_row
);
15613 defsubr (&Sdump_tool_bar_row
);
15614 defsubr (&Strace_redisplay
);
15615 defsubr (&Strace_to_stderr
);
15617 #ifdef HAVE_WINDOW_SYSTEM
15618 defsubr (&Stool_bar_lines_needed
);
15620 defsubr (&Sformat_mode_line
);
15622 staticpro (&Qmenu_bar_update_hook
);
15623 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
15625 staticpro (&Qoverriding_terminal_local_map
);
15626 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
15628 staticpro (&Qoverriding_local_map
);
15629 Qoverriding_local_map
= intern ("overriding-local-map");
15631 staticpro (&Qwindow_scroll_functions
);
15632 Qwindow_scroll_functions
= intern ("window-scroll-functions");
15634 staticpro (&Qredisplay_end_trigger_functions
);
15635 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
15637 staticpro (&Qinhibit_point_motion_hooks
);
15638 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
15640 QCdata
= intern (":data");
15641 staticpro (&QCdata
);
15642 Qdisplay
= intern ("display");
15643 staticpro (&Qdisplay
);
15644 Qspace_width
= intern ("space-width");
15645 staticpro (&Qspace_width
);
15646 Qraise
= intern ("raise");
15647 staticpro (&Qraise
);
15648 Qspace
= intern ("space");
15649 staticpro (&Qspace
);
15650 Qmargin
= intern ("margin");
15651 staticpro (&Qmargin
);
15652 Qleft_margin
= intern ("left-margin");
15653 staticpro (&Qleft_margin
);
15654 Qright_margin
= intern ("right-margin");
15655 staticpro (&Qright_margin
);
15656 Qalign_to
= intern ("align-to");
15657 staticpro (&Qalign_to
);
15658 QCalign_to
= intern (":align-to");
15659 staticpro (&QCalign_to
);
15660 Qrelative_width
= intern ("relative-width");
15661 staticpro (&Qrelative_width
);
15662 QCrelative_width
= intern (":relative-width");
15663 staticpro (&QCrelative_width
);
15664 QCrelative_height
= intern (":relative-height");
15665 staticpro (&QCrelative_height
);
15666 QCeval
= intern (":eval");
15667 staticpro (&QCeval
);
15668 QCpropertize
= intern (":propertize");
15669 staticpro (&QCpropertize
);
15670 QCfile
= intern (":file");
15671 staticpro (&QCfile
);
15672 Qfontified
= intern ("fontified");
15673 staticpro (&Qfontified
);
15674 Qfontification_functions
= intern ("fontification-functions");
15675 staticpro (&Qfontification_functions
);
15676 Qtrailing_whitespace
= intern ("trailing-whitespace");
15677 staticpro (&Qtrailing_whitespace
);
15678 Qimage
= intern ("image");
15679 staticpro (&Qimage
);
15680 Qmessage_truncate_lines
= intern ("message-truncate-lines");
15681 staticpro (&Qmessage_truncate_lines
);
15682 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
15683 staticpro (&Qcursor_in_non_selected_windows
);
15684 Qgrow_only
= intern ("grow-only");
15685 staticpro (&Qgrow_only
);
15686 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
15687 staticpro (&Qinhibit_menubar_update
);
15688 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
15689 staticpro (&Qinhibit_eval_during_redisplay
);
15690 Qposition
= intern ("position");
15691 staticpro (&Qposition
);
15692 Qbuffer_position
= intern ("buffer-position");
15693 staticpro (&Qbuffer_position
);
15694 Qobject
= intern ("object");
15695 staticpro (&Qobject
);
15696 Qbar
= intern ("bar");
15698 Qhbar
= intern ("hbar");
15699 staticpro (&Qhbar
);
15700 Qbox
= intern ("box");
15702 Qhollow
= intern ("hollow");
15703 staticpro (&Qhollow
);
15704 Qrisky_local_variable
= intern ("risky-local-variable");
15705 staticpro (&Qrisky_local_variable
);
15706 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
15707 staticpro (&Qinhibit_free_realized_faces
);
15709 list_of_error
= Fcons (intern ("error"), Qnil
);
15710 staticpro (&list_of_error
);
15712 last_arrow_position
= Qnil
;
15713 last_arrow_string
= Qnil
;
15714 staticpro (&last_arrow_position
);
15715 staticpro (&last_arrow_string
);
15717 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
15718 staticpro (&echo_buffer
[0]);
15719 staticpro (&echo_buffer
[1]);
15721 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
15722 staticpro (&echo_area_buffer
[0]);
15723 staticpro (&echo_area_buffer
[1]);
15725 Vmessages_buffer_name
= build_string ("*Messages*");
15726 staticpro (&Vmessages_buffer_name
);
15728 mode_line_proptrans_alist
= Qnil
;
15729 staticpro (&mode_line_proptrans_alist
);
15731 mode_line_string_list
= Qnil
;
15732 staticpro (&mode_line_string_list
);
15734 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
15735 doc
: /* Non-nil means highlight trailing whitespace.
15736 The face used for trailing whitespace is `trailing-whitespace'. */);
15737 Vshow_trailing_whitespace
= Qnil
;
15739 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
15740 doc
: /* Non-nil means don't actually do any redisplay.
15741 This is used for internal purposes. */);
15742 Vinhibit_redisplay
= Qnil
;
15744 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
15745 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
15746 Vglobal_mode_string
= Qnil
;
15748 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
15749 doc
: /* Marker for where to display an arrow on top of the buffer text.
15750 This must be the beginning of a line in order to work.
15751 See also `overlay-arrow-string'. */);
15752 Voverlay_arrow_position
= Qnil
;
15754 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
15755 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
15756 Voverlay_arrow_string
= Qnil
;
15758 DEFVAR_INT ("scroll-step", &scroll_step
,
15759 doc
: /* *The number of lines to try scrolling a window by when point moves out.
15760 If that fails to bring point back on frame, point is centered instead.
15761 If this is zero, point is always centered after it moves off frame.
15762 If you want scrolling to always be a line at a time, you should set
15763 `scroll-conservatively' to a large value rather than set this to 1. */);
15765 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
15766 doc
: /* *Scroll up to this many lines, to bring point back on screen.
15767 A value of zero means to scroll the text to center point vertically
15768 in the window. */);
15769 scroll_conservatively
= 0;
15771 DEFVAR_INT ("scroll-margin", &scroll_margin
,
15772 doc
: /* *Number of lines of margin at the top and bottom of a window.
15773 Recenter the window whenever point gets within this many lines
15774 of the top or bottom of the window. */);
15778 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
15781 DEFVAR_BOOL ("truncate-partial-width-windows",
15782 &truncate_partial_width_windows
,
15783 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
15784 truncate_partial_width_windows
= 1;
15786 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
15787 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
15788 Any other value means to use the appropriate face, `mode-line',
15789 `header-line', or `menu' respectively. */);
15790 mode_line_inverse_video
= 1;
15792 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
15793 doc
: /* *Maximum buffer size for which line number should be displayed.
15794 If the buffer is bigger than this, the line number does not appear
15795 in the mode line. A value of nil means no limit. */);
15796 Vline_number_display_limit
= Qnil
;
15798 DEFVAR_INT ("line-number-display-limit-width",
15799 &line_number_display_limit_width
,
15800 doc
: /* *Maximum line width (in characters) for line number display.
15801 If the average length of the lines near point is bigger than this, then the
15802 line number may be omitted from the mode line. */);
15803 line_number_display_limit_width
= 200;
15805 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
15806 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
15807 highlight_nonselected_windows
= 0;
15809 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
15810 doc
: /* Non-nil if more than one frame is visible on this display.
15811 Minibuffer-only frames don't count, but iconified frames do.
15812 This variable is not guaranteed to be accurate except while processing
15813 `frame-title-format' and `icon-title-format'. */);
15815 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
15816 doc
: /* Template for displaying the title bar of visible frames.
15817 \(Assuming the window manager supports this feature.)
15818 This variable has the same structure as `mode-line-format' (which see),
15819 and is used only on frames for which no explicit name has been set
15820 \(see `modify-frame-parameters'). */);
15821 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
15822 doc
: /* Template for displaying the title bar of an iconified frame.
15823 \(Assuming the window manager supports this feature.)
15824 This variable has the same structure as `mode-line-format' (which see),
15825 and is used only on frames for which no explicit name has been set
15826 \(see `modify-frame-parameters'). */);
15828 = Vframe_title_format
15829 = Fcons (intern ("multiple-frames"),
15830 Fcons (build_string ("%b"),
15831 Fcons (Fcons (empty_string
,
15832 Fcons (intern ("invocation-name"),
15833 Fcons (build_string ("@"),
15834 Fcons (intern ("system-name"),
15838 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
15839 doc
: /* Maximum number of lines to keep in the message log buffer.
15840 If nil, disable message logging. If t, log messages but don't truncate
15841 the buffer when it becomes large. */);
15842 Vmessage_log_max
= make_number (50);
15844 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
15845 doc
: /* Functions called before redisplay, if window sizes have changed.
15846 The value should be a list of functions that take one argument.
15847 Just before redisplay, for each frame, if any of its windows have changed
15848 size since the last redisplay, or have been split or deleted,
15849 all the functions in the list are called, with the frame as argument. */);
15850 Vwindow_size_change_functions
= Qnil
;
15852 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
15853 doc
: /* List of Functions to call before redisplaying a window with scrolling.
15854 Each function is called with two arguments, the window
15855 and its new display-start position. Note that the value of `window-end'
15856 is not valid when these functions are called. */);
15857 Vwindow_scroll_functions
= Qnil
;
15859 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
15860 doc
: /* *Non-nil means automatically resize tool-bars.
15861 This increases a tool-bar's height if not all tool-bar items are visible.
15862 It decreases a tool-bar's height when it would display blank lines
15864 auto_resize_tool_bars_p
= 1;
15866 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
15867 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
15868 auto_raise_tool_bar_buttons_p
= 1;
15870 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
15871 doc
: /* *Margin around tool-bar buttons in pixels.
15872 If an integer, use that for both horizontal and vertical margins.
15873 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
15874 HORZ specifying the horizontal margin, and VERT specifying the
15875 vertical margin. */);
15876 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
15878 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
15879 doc
: /* *Relief thickness of tool-bar buttons. */);
15880 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
15882 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
15883 doc
: /* List of functions to call to fontify regions of text.
15884 Each function is called with one argument POS. Functions must
15885 fontify a region starting at POS in the current buffer, and give
15886 fontified regions the property `fontified'. */);
15887 Vfontification_functions
= Qnil
;
15888 Fmake_variable_buffer_local (Qfontification_functions
);
15890 DEFVAR_BOOL ("unibyte-display-via-language-environment",
15891 &unibyte_display_via_language_environment
,
15892 doc
: /* *Non-nil means display unibyte text according to language environment.
15893 Specifically this means that unibyte non-ASCII characters
15894 are displayed by converting them to the equivalent multibyte characters
15895 according to the current language environment. As a result, they are
15896 displayed according to the current fontset. */);
15897 unibyte_display_via_language_environment
= 0;
15899 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
15900 doc
: /* *Maximum height for resizing mini-windows.
15901 If a float, it specifies a fraction of the mini-window frame's height.
15902 If an integer, it specifies a number of lines. */);
15903 Vmax_mini_window_height
= make_float (0.25);
15905 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
15906 doc
: /* *How to resize mini-windows.
15907 A value of nil means don't automatically resize mini-windows.
15908 A value of t means resize them to fit the text displayed in them.
15909 A value of `grow-only', the default, means let mini-windows grow
15910 only, until their display becomes empty, at which point the windows
15911 go back to their normal size. */);
15912 Vresize_mini_windows
= Qgrow_only
;
15914 DEFVAR_LISP ("cursor-in-non-selected-windows",
15915 &Vcursor_in_non_selected_windows
,
15916 doc
: /* *Cursor type to display in non-selected windows.
15917 t means to use hollow box cursor. See `cursor-type' for other values. */);
15918 Vcursor_in_non_selected_windows
= Qt
;
15920 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
15921 doc
: /* Alist specifying how to blink the cursor off.
15922 Each element has the form (ON-STATE . OFF-STATE). Whenever the
15923 `cursor-type' frame-parameter or variable equals ON-STATE,
15924 comparing using `equal', Emacs uses OFF-STATE to specify
15925 how to blink it off. */);
15926 Vblink_cursor_alist
= Qnil
;
15928 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
15929 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
15930 automatic_hscrolling_p
= 1;
15932 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
15933 doc
: /* *How many columns away from the window edge point is allowed to get
15934 before automatic hscrolling will horizontally scroll the window. */);
15935 hscroll_margin
= 5;
15937 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
15938 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
15939 When point is less than `automatic-hscroll-margin' columns from the window
15940 edge, automatic hscrolling will scroll the window by the amount of columns
15941 determined by this variable. If its value is a positive integer, scroll that
15942 many columns. If it's a positive floating-point number, it specifies the
15943 fraction of the window's width to scroll. If it's nil or zero, point will be
15944 centered horizontally after the scroll. Any other value, including negative
15945 numbers, are treated as if the value were zero.
15947 Automatic hscrolling always moves point outside the scroll margin, so if
15948 point was more than scroll step columns inside the margin, the window will
15949 scroll more than the value given by the scroll step.
15951 Note that the lower bound for automatic hscrolling specified by `scroll-left'
15952 and `scroll-right' overrides this variable's effect. */);
15953 Vhscroll_step
= make_number (0);
15955 DEFVAR_LISP ("image-types", &Vimage_types
,
15956 doc
: /* List of supported image types.
15957 Each element of the list is a symbol for a supported image type. */);
15958 Vimage_types
= Qnil
;
15960 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
15961 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
15962 Bind this around calls to `message' to let it take effect. */);
15963 message_truncate_lines
= 0;
15965 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
15966 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
15967 Can be used to update submenus whose contents should vary. */);
15968 Vmenu_bar_update_hook
= Qnil
;
15970 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
15971 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
15972 inhibit_menubar_update
= 0;
15974 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
15975 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
15976 inhibit_eval_during_redisplay
= 0;
15978 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
15979 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
15980 inhibit_free_realized_faces
= 0;
15983 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
15984 doc
: /* Inhibit try_window_id display optimization. */);
15985 inhibit_try_window_id
= 0;
15987 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
15988 doc
: /* Inhibit try_window_reusing display optimization. */);
15989 inhibit_try_window_reusing
= 0;
15991 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
15992 doc
: /* Inhibit try_cursor_movement display optimization. */);
15993 inhibit_try_cursor_movement
= 0;
15994 #endif /* GLYPH_DEBUG */
15998 /* Initialize this module when Emacs starts. */
16003 Lisp_Object root_window
;
16004 struct window
*mini_w
;
16006 current_header_line_height
= current_mode_line_height
= -1;
16008 CHARPOS (this_line_start_pos
) = 0;
16010 mini_w
= XWINDOW (minibuf_window
);
16011 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
16013 if (!noninteractive
)
16015 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
16018 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
16019 set_window_height (root_window
,
16020 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
16022 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
16023 set_window_height (minibuf_window
, 1, 0);
16025 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
16026 mini_w
->width
= make_number (FRAME_WIDTH (f
));
16028 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
16029 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
16030 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
16032 /* The default ellipsis glyphs `...'. */
16033 for (i
= 0; i
< 3; ++i
)
16034 default_invis_vector
[i
] = make_number ('.');
16038 /* Allocate the buffer for frame titles.
16039 Also used for `format-mode-line'. */
16041 frame_title_buf
= (char *) xmalloc (size
);
16042 frame_title_buf_end
= frame_title_buf
+ size
;
16043 frame_title_ptr
= NULL
;
16046 help_echo_showing_p
= 0;