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
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? 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 a 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)
204 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
205 extern int pending_menu_activation
;
208 extern int interrupt_input
;
209 extern int command_loop_level
;
211 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Qface
;
214 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
216 extern Lisp_Object Voverriding_local_map
;
217 extern Lisp_Object Voverriding_local_map_menu_flag
;
218 extern Lisp_Object Qmenu_item
;
220 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
221 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
222 Lisp_Object Qredisplay_end_trigger_functions
;
223 Lisp_Object Qinhibit_point_motion_hooks
;
224 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
, QCpropertize
;
225 Lisp_Object Qfontified
;
226 Lisp_Object Qgrow_only
;
227 Lisp_Object Qinhibit_eval_during_redisplay
;
228 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
230 Lisp_Object Qrisky_local_variable
;
232 /* Holds the list (error). */
233 Lisp_Object list_of_error
;
235 /* Functions called to fontify regions of text. */
237 Lisp_Object Vfontification_functions
;
238 Lisp_Object Qfontification_functions
;
240 /* Non-zero means draw tool bar buttons raised when the mouse moves
243 int auto_raise_tool_bar_buttons_p
;
245 /* Margin around tool bar buttons in pixels. */
247 Lisp_Object Vtool_bar_button_margin
;
249 /* Thickness of shadow to draw around tool bar buttons. */
251 EMACS_INT tool_bar_button_relief
;
253 /* Non-zero means automatically resize tool-bars so that all tool-bar
254 items are visible, and no blank lines remain. */
256 int auto_resize_tool_bars_p
;
258 /* Non-nil means don't actually do any redisplay. */
260 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
262 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
264 int inhibit_eval_during_redisplay
;
266 /* Names of text properties relevant for redisplay. */
268 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
269 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
271 /* Symbols used in text property values. */
273 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
274 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
276 extern Lisp_Object Qheight
;
278 /* Non-nil means highlight trailing whitespace. */
280 Lisp_Object Vshow_trailing_whitespace
;
282 /* Name of the face used to highlight trailing whitespace. */
284 Lisp_Object Qtrailing_whitespace
;
286 /* The symbol `image' which is the car of the lists used to represent
291 /* Non-zero means print newline to stdout before next mini-buffer
294 int noninteractive_need_newline
;
296 /* Non-zero means print newline to message log before next message. */
298 static int message_log_need_newline
;
300 /* Three markers that message_dolog uses.
301 It could allocate them itself, but that causes trouble
302 in handling memory-full errors. */
303 static Lisp_Object message_dolog_marker1
;
304 static Lisp_Object message_dolog_marker2
;
305 static Lisp_Object message_dolog_marker3
;
307 /* The buffer position of the first character appearing entirely or
308 partially on the line of the selected window which contains the
309 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
310 redisplay optimization in redisplay_internal. */
312 static struct text_pos this_line_start_pos
;
314 /* Number of characters past the end of the line above, including the
315 terminating newline. */
317 static struct text_pos this_line_end_pos
;
319 /* The vertical positions and the height of this line. */
321 static int this_line_vpos
;
322 static int this_line_y
;
323 static int this_line_pixel_height
;
325 /* X position at which this display line starts. Usually zero;
326 negative if first character is partially visible. */
328 static int this_line_start_x
;
330 /* Buffer that this_line_.* variables are referring to. */
332 static struct buffer
*this_line_buffer
;
334 /* Nonzero means truncate lines in all windows less wide than the
337 int truncate_partial_width_windows
;
339 /* A flag to control how to display unibyte 8-bit character. */
341 int unibyte_display_via_language_environment
;
343 /* Nonzero means we have more than one non-mini-buffer-only frame.
344 Not guaranteed to be accurate except while parsing
345 frame-title-format. */
349 Lisp_Object Vglobal_mode_string
;
351 /* Marker for where to display an arrow on top of the buffer text. */
353 Lisp_Object Voverlay_arrow_position
;
355 /* String to display for the arrow. Only used on terminal frames. */
357 Lisp_Object Voverlay_arrow_string
;
359 /* Values of those variables at last redisplay. However, if
360 Voverlay_arrow_position is a marker, last_arrow_position is its
361 numerical position. */
363 static Lisp_Object last_arrow_position
, last_arrow_string
;
365 /* Like mode-line-format, but for the title bar on a visible frame. */
367 Lisp_Object Vframe_title_format
;
369 /* Like mode-line-format, but for the title bar on an iconified frame. */
371 Lisp_Object Vicon_title_format
;
373 /* List of functions to call when a window's size changes. These
374 functions get one arg, a frame on which one or more windows' sizes
377 static Lisp_Object Vwindow_size_change_functions
;
379 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
381 /* Nonzero if overlay arrow has been displayed once in this window. */
383 static int overlay_arrow_seen
;
385 /* Nonzero means highlight the region even in nonselected windows. */
387 int highlight_nonselected_windows
;
389 /* If cursor motion alone moves point off frame, try scrolling this
390 many lines up or down if that will bring it back. */
392 static EMACS_INT scroll_step
;
394 /* Nonzero means scroll just far enough to bring point back on the
395 screen, when appropriate. */
397 static EMACS_INT scroll_conservatively
;
399 /* Recenter the window whenever point gets within this many lines of
400 the top or bottom of the window. This value is translated into a
401 pixel value by multiplying it with CANON_Y_UNIT, which means that
402 there is really a fixed pixel height scroll margin. */
404 EMACS_INT scroll_margin
;
406 /* Number of windows showing the buffer of the selected window (or
407 another buffer with the same base buffer). keyboard.c refers to
412 /* Vector containing glyphs for an ellipsis `...'. */
414 static Lisp_Object default_invis_vector
[3];
416 /* Zero means display the mode-line/header-line/menu-bar in the default face
417 (this slightly odd definition is for compatibility with previous versions
418 of emacs), non-zero means display them using their respective faces.
420 This variable is deprecated. */
422 int mode_line_inverse_video
;
424 /* Prompt to display in front of the mini-buffer contents. */
426 Lisp_Object minibuf_prompt
;
428 /* Width of current mini-buffer prompt. Only set after display_line
429 of the line that contains the prompt. */
431 int minibuf_prompt_width
;
433 /* This is the window where the echo area message was displayed. It
434 is always a mini-buffer window, but it may not be the same window
435 currently active as a mini-buffer. */
437 Lisp_Object echo_area_window
;
439 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
440 pushes the current message and the value of
441 message_enable_multibyte on the stack, the function restore_message
442 pops the stack and displays MESSAGE again. */
444 Lisp_Object Vmessage_stack
;
446 /* Nonzero means multibyte characters were enabled when the echo area
447 message was specified. */
449 int message_enable_multibyte
;
451 /* Nonzero if we should redraw the mode lines on the next redisplay. */
453 int update_mode_lines
;
455 /* Nonzero if window sizes or contents have changed since last
456 redisplay that finished. */
458 int windows_or_buffers_changed
;
460 /* Nonzero means a frame's cursor type has been changed. */
462 int cursor_type_changed
;
464 /* Nonzero after display_mode_line if %l was used and it displayed a
467 int line_number_displayed
;
469 /* Maximum buffer size for which to display line numbers. */
471 Lisp_Object Vline_number_display_limit
;
473 /* Line width to consider when repositioning for line number display. */
475 static EMACS_INT line_number_display_limit_width
;
477 /* Number of lines to keep in the message log buffer. t means
478 infinite. nil means don't log at all. */
480 Lisp_Object Vmessage_log_max
;
482 /* The name of the *Messages* buffer, a string. */
484 static Lisp_Object Vmessages_buffer_name
;
486 /* Current, index 0, and last displayed echo area message. Either
487 buffers from echo_buffers, or nil to indicate no message. */
489 Lisp_Object echo_area_buffer
[2];
491 /* The buffers referenced from echo_area_buffer. */
493 static Lisp_Object echo_buffer
[2];
495 /* A vector saved used in with_area_buffer to reduce consing. */
497 static Lisp_Object Vwith_echo_area_save_vector
;
499 /* Non-zero means display_echo_area should display the last echo area
500 message again. Set by redisplay_preserve_echo_area. */
502 static int display_last_displayed_message_p
;
504 /* Nonzero if echo area is being used by print; zero if being used by
507 int message_buf_print
;
509 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
511 Lisp_Object Qinhibit_menubar_update
;
512 int inhibit_menubar_update
;
514 /* Maximum height for resizing mini-windows. Either a float
515 specifying a fraction of the available height, or an integer
516 specifying a number of lines. */
518 Lisp_Object Vmax_mini_window_height
;
520 /* Non-zero means messages should be displayed with truncated
521 lines instead of being continued. */
523 int message_truncate_lines
;
524 Lisp_Object Qmessage_truncate_lines
;
526 /* Set to 1 in clear_message to make redisplay_internal aware
527 of an emptied echo area. */
529 static int message_cleared_p
;
531 /* Non-zero means we want a hollow cursor in windows that are not
532 selected. Zero means there's no cursor in such windows. */
534 int cursor_in_non_selected_windows
;
535 Lisp_Object Qcursor_in_non_selected_windows
;
537 /* A scratch glyph row with contents used for generating truncation
538 glyphs. Also used in direct_output_for_insert. */
540 #define MAX_SCRATCH_GLYPHS 100
541 struct glyph_row scratch_glyph_row
;
542 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
544 /* Ascent and height of the last line processed by move_it_to. */
546 static int last_max_ascent
, last_height
;
548 /* Non-zero if there's a help-echo in the echo area. */
550 int help_echo_showing_p
;
552 /* If >= 0, computed, exact values of mode-line and header-line height
553 to use in the macros CURRENT_MODE_LINE_HEIGHT and
554 CURRENT_HEADER_LINE_HEIGHT. */
556 int current_mode_line_height
, current_header_line_height
;
558 /* The maximum distance to look ahead for text properties. Values
559 that are too small let us call compute_char_face and similar
560 functions too often which is expensive. Values that are too large
561 let us call compute_char_face and alike too often because we
562 might not be interested in text properties that far away. */
564 #define TEXT_PROP_DISTANCE_LIMIT 100
568 /* Variables to turn off display optimizations from Lisp. */
570 int inhibit_try_window_id
, inhibit_try_window_reusing
;
571 int inhibit_try_cursor_movement
;
573 /* Non-zero means print traces of redisplay if compiled with
576 int trace_redisplay_p
;
578 #endif /* GLYPH_DEBUG */
580 #ifdef DEBUG_TRACE_MOVE
581 /* Non-zero means trace with TRACE_MOVE to stderr. */
584 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
586 #define TRACE_MOVE(x) (void) 0
589 /* Non-zero means automatically scroll windows horizontally to make
592 int automatic_hscrolling_p
;
594 /* How close to the margin can point get before the window is scrolled
596 EMACS_INT hscroll_margin
;
598 /* How much to scroll horizontally when point is inside the above margin. */
599 Lisp_Object Vhscroll_step
;
601 /* A list of symbols, one for each supported image type. */
603 Lisp_Object Vimage_types
;
605 /* The variable `resize-mini-windows'. If nil, don't resize
606 mini-windows. If t, always resize them to fit the text they
607 display. If `grow-only', let mini-windows grow only until they
610 Lisp_Object Vresize_mini_windows
;
612 /* Buffer being redisplayed -- for redisplay_window_error. */
614 struct buffer
*displayed_buffer
;
616 /* Value returned from text property handlers (see below). */
621 HANDLED_RECOMPUTE_PROPS
,
622 HANDLED_OVERLAY_STRING_CONSUMED
,
626 /* A description of text properties that redisplay is interested
631 /* The name of the property. */
634 /* A unique index for the property. */
637 /* A handler function called to set up iterator IT from the property
638 at IT's current position. Value is used to steer handle_stop. */
639 enum prop_handled (*handler
) P_ ((struct it
*it
));
642 static enum prop_handled handle_face_prop
P_ ((struct it
*));
643 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
644 static enum prop_handled handle_display_prop
P_ ((struct it
*));
645 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
646 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
647 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
649 /* Properties handled by iterators. */
651 static struct props it_props
[] =
653 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
654 /* Handle `face' before `display' because some sub-properties of
655 `display' need to know the face. */
656 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
657 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
658 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
659 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
663 /* Value is the position described by X. If X is a marker, value is
664 the marker_position of X. Otherwise, value is X. */
666 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
668 /* Enumeration returned by some move_it_.* functions internally. */
672 /* Not used. Undefined value. */
675 /* Move ended at the requested buffer position or ZV. */
676 MOVE_POS_MATCH_OR_ZV
,
678 /* Move ended at the requested X pixel position. */
681 /* Move within a line ended at the end of a line that must be
685 /* Move within a line ended at the end of a line that would
686 be displayed truncated. */
689 /* Move within a line ended at a line end. */
695 /* Function prototypes. */
697 static void setup_for_ellipsis
P_ ((struct it
*));
698 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
699 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
700 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
701 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
702 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
703 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
706 static int invisible_text_between_p
P_ ((struct it
*, int, int));
709 static int next_element_from_ellipsis
P_ ((struct it
*));
710 static void pint2str
P_ ((char *, int, int));
711 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
713 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
714 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
715 static void store_frame_title_char
P_ ((char));
716 static int store_frame_title
P_ ((unsigned char *, int, int));
717 static void x_consider_frame_title
P_ ((Lisp_Object
));
718 static void handle_stop
P_ ((struct it
*));
719 static int tool_bar_lines_needed
P_ ((struct frame
*));
720 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
721 static void ensure_echo_area_buffers
P_ ((void));
722 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
723 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
724 static int with_echo_area_buffer
P_ ((struct window
*, int,
725 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
726 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
727 static void clear_garbaged_frames
P_ ((void));
728 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
729 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
730 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
731 static int display_echo_area
P_ ((struct window
*));
732 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
733 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
734 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
735 static int string_char_and_length
P_ ((unsigned char *, int, int *));
736 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
738 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
739 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
740 static void insert_left_trunc_glyphs
P_ ((struct it
*));
741 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
742 static void extend_face_to_end_of_line
P_ ((struct it
*));
743 static int append_space
P_ ((struct it
*, int));
744 static int make_cursor_line_fully_visible
P_ ((struct window
*));
745 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int));
746 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
747 static int trailing_whitespace_p
P_ ((int));
748 static int message_log_check_duplicate
P_ ((int, int, int, int));
749 static void push_it
P_ ((struct it
*));
750 static void pop_it
P_ ((struct it
*));
751 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
752 static void redisplay_internal
P_ ((int));
753 static int echo_area_display
P_ ((int));
754 static void redisplay_windows
P_ ((Lisp_Object
));
755 static void redisplay_window
P_ ((Lisp_Object
, int));
756 static Lisp_Object
redisplay_window_error ();
757 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
758 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
759 static void update_menu_bar
P_ ((struct frame
*, int));
760 static int try_window_reusing_current_matrix
P_ ((struct window
*));
761 static int try_window_id
P_ ((struct window
*));
762 static int display_line
P_ ((struct it
*));
763 static int display_mode_lines
P_ ((struct window
*));
764 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
765 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
766 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
767 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
768 static void display_menu_bar
P_ ((struct window
*));
769 static int display_count_lines
P_ ((int, int, int, int, int *));
770 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
771 int, int, struct it
*, int, int, int, int));
772 static void compute_line_metrics
P_ ((struct it
*));
773 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
774 static int get_overlay_strings
P_ ((struct it
*, int));
775 static void next_overlay_string
P_ ((struct it
*));
776 static void reseat
P_ ((struct it
*, struct text_pos
, int));
777 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
778 static void back_to_previous_visible_line_start
P_ ((struct it
*));
779 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
780 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
781 static int next_element_from_display_vector
P_ ((struct it
*));
782 static int next_element_from_string
P_ ((struct it
*));
783 static int next_element_from_c_string
P_ ((struct it
*));
784 static int next_element_from_buffer
P_ ((struct it
*));
785 static int next_element_from_composition
P_ ((struct it
*));
786 static int next_element_from_image
P_ ((struct it
*));
787 static int next_element_from_stretch
P_ ((struct it
*));
788 static void load_overlay_strings
P_ ((struct it
*, int));
789 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
790 struct display_pos
*));
791 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
792 Lisp_Object
, int, int, int, int));
793 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
795 void move_it_vertically_backward
P_ ((struct it
*, int));
796 static void init_to_row_start
P_ ((struct it
*, struct window
*,
797 struct glyph_row
*));
798 static int init_to_row_end
P_ ((struct it
*, struct window
*,
799 struct glyph_row
*));
800 static void back_to_previous_line_start
P_ ((struct it
*));
801 static int forward_to_next_line_start
P_ ((struct it
*, int *));
802 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
804 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
805 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
806 static int number_of_chars
P_ ((unsigned char *, int));
807 static void compute_stop_pos
P_ ((struct it
*));
808 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
810 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
811 static int next_overlay_change
P_ ((int));
812 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
813 Lisp_Object
, struct text_pos
*,
815 static int underlying_face_id
P_ ((struct it
*));
816 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
819 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
820 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
822 #ifdef HAVE_WINDOW_SYSTEM
824 static void update_tool_bar
P_ ((struct frame
*, int));
825 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
826 static int redisplay_tool_bar
P_ ((struct frame
*));
827 static void display_tool_bar_line
P_ ((struct it
*));
829 #endif /* HAVE_WINDOW_SYSTEM */
832 /***********************************************************************
833 Window display dimensions
834 ***********************************************************************/
836 /* Return the window-relative maximum y + 1 for glyph rows displaying
837 text in window W. This is the height of W minus the height of a
838 mode line, if any. */
841 window_text_bottom_y (w
)
844 struct frame
*f
= XFRAME (w
->frame
);
845 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
847 if (WINDOW_WANTS_MODELINE_P (w
))
848 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
853 /* Return the pixel width of display area AREA of window W. AREA < 0
854 means return the total width of W, not including fringes to
855 the left and right of the window. */
858 window_box_width (w
, area
)
862 struct frame
*f
= XFRAME (w
->frame
);
863 int width
= XFASTINT (w
->width
);
865 if (!w
->pseudo_window_p
)
867 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
869 if (area
== TEXT_AREA
)
871 if (INTEGERP (w
->left_margin_width
))
872 width
-= XFASTINT (w
->left_margin_width
);
873 if (INTEGERP (w
->right_margin_width
))
874 width
-= XFASTINT (w
->right_margin_width
);
876 else if (area
== LEFT_MARGIN_AREA
)
877 width
= (INTEGERP (w
->left_margin_width
)
878 ? XFASTINT (w
->left_margin_width
) : 0);
879 else if (area
== RIGHT_MARGIN_AREA
)
880 width
= (INTEGERP (w
->right_margin_width
)
881 ? XFASTINT (w
->right_margin_width
) : 0);
884 return width
* CANON_X_UNIT (f
);
888 /* Return the pixel height of the display area of window W, not
889 including mode lines of W, if any. */
892 window_box_height (w
)
895 struct frame
*f
= XFRAME (w
->frame
);
896 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
898 xassert (height
>= 0);
900 /* Note: the code below that determines the mode-line/header-line
901 height is essentially the same as that contained in the macro
902 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
903 the appropriate glyph row has its `mode_line_p' flag set,
904 and if it doesn't, uses estimate_mode_line_height instead. */
906 if (WINDOW_WANTS_MODELINE_P (w
))
908 struct glyph_row
*ml_row
909 = (w
->current_matrix
&& w
->current_matrix
->rows
910 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
912 if (ml_row
&& ml_row
->mode_line_p
)
913 height
-= ml_row
->height
;
915 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
918 if (WINDOW_WANTS_HEADER_LINE_P (w
))
920 struct glyph_row
*hl_row
921 = (w
->current_matrix
&& w
->current_matrix
->rows
922 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
924 if (hl_row
&& hl_row
->mode_line_p
)
925 height
-= hl_row
->height
;
927 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
930 /* With a very small font and a mode-line that's taller than
931 default, we might end up with a negative height. */
932 return max (0, height
);
936 /* Return the frame-relative coordinate of the left edge of display
937 area AREA of window W. AREA < 0 means return the left edge of the
938 whole window, to the right of the left fringe of W. */
941 window_box_left (w
, area
)
945 struct frame
*f
= XFRAME (w
->frame
);
946 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
948 if (!w
->pseudo_window_p
)
950 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
951 + FRAME_LEFT_FRINGE_WIDTH (f
));
953 if (area
== TEXT_AREA
)
954 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
955 else if (area
== RIGHT_MARGIN_AREA
)
956 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
957 + window_box_width (w
, TEXT_AREA
));
964 /* Return the frame-relative coordinate of the right edge of display
965 area AREA of window W. AREA < 0 means return the left edge of the
966 whole window, to the left of the right fringe of W. */
969 window_box_right (w
, area
)
973 return window_box_left (w
, area
) + window_box_width (w
, area
);
977 /* Get the bounding box of the display area AREA of window W, without
978 mode lines, in frame-relative coordinates. AREA < 0 means the
979 whole window, not including the left and right fringes of
980 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
981 coordinates of the upper-left corner of the box. Return in
982 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
985 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
988 int *box_x
, *box_y
, *box_width
, *box_height
;
990 struct frame
*f
= XFRAME (w
->frame
);
992 *box_width
= window_box_width (w
, area
);
993 *box_height
= window_box_height (w
);
994 *box_x
= window_box_left (w
, area
);
995 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
996 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
997 if (WINDOW_WANTS_HEADER_LINE_P (w
))
998 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1002 /* Get the bounding box of the display area AREA of window W, without
1003 mode lines. AREA < 0 means the whole window, not including the
1004 left and right fringe of the window. Return in *TOP_LEFT_X
1005 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1006 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1007 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1011 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1012 bottom_right_x
, bottom_right_y
)
1015 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1017 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1019 *bottom_right_x
+= *top_left_x
;
1020 *bottom_right_y
+= *top_left_y
;
1025 /***********************************************************************
1027 ***********************************************************************/
1029 /* Return the bottom y-position of the line the iterator IT is in.
1030 This can modify IT's settings. */
1036 int line_height
= it
->max_ascent
+ it
->max_descent
;
1037 int line_top_y
= it
->current_y
;
1039 if (line_height
== 0)
1042 line_height
= last_height
;
1043 else if (IT_CHARPOS (*it
) < ZV
)
1045 move_it_by_lines (it
, 1, 1);
1046 line_height
= (it
->max_ascent
|| it
->max_descent
1047 ? it
->max_ascent
+ it
->max_descent
1052 struct glyph_row
*row
= it
->glyph_row
;
1054 /* Use the default character height. */
1055 it
->glyph_row
= NULL
;
1056 it
->what
= IT_CHARACTER
;
1059 PRODUCE_GLYPHS (it
);
1060 line_height
= it
->ascent
+ it
->descent
;
1061 it
->glyph_row
= row
;
1065 return line_top_y
+ line_height
;
1069 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1070 1 if POS is visible and the line containing POS is fully visible.
1071 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1072 and header-lines heights. */
1075 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1077 int charpos
, *fully
, exact_mode_line_heights_p
;
1080 struct text_pos top
;
1082 struct buffer
*old_buffer
= NULL
;
1084 if (XBUFFER (w
->buffer
) != current_buffer
)
1086 old_buffer
= current_buffer
;
1087 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1090 *fully
= visible_p
= 0;
1091 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1093 /* Compute exact mode line heights, if requested. */
1094 if (exact_mode_line_heights_p
)
1096 if (WINDOW_WANTS_MODELINE_P (w
))
1097 current_mode_line_height
1098 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1099 current_buffer
->mode_line_format
);
1101 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1102 current_header_line_height
1103 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1104 current_buffer
->header_line_format
);
1107 start_display (&it
, w
, top
);
1108 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1109 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1111 /* Note that we may overshoot because of invisible text. */
1112 if (IT_CHARPOS (it
) >= charpos
)
1114 int top_y
= it
.current_y
;
1115 int bottom_y
= line_bottom_y (&it
);
1116 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1118 if (top_y
< window_top_y
)
1119 visible_p
= bottom_y
> window_top_y
;
1120 else if (top_y
< it
.last_visible_y
)
1123 *fully
= bottom_y
<= it
.last_visible_y
;
1126 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1128 move_it_by_lines (&it
, 1, 0);
1129 if (charpos
< IT_CHARPOS (it
))
1137 set_buffer_internal_1 (old_buffer
);
1139 current_header_line_height
= current_mode_line_height
= -1;
1144 /* Return the next character from STR which is MAXLEN bytes long.
1145 Return in *LEN the length of the character. This is like
1146 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1147 we find one, we return a `?', but with the length of the invalid
1151 string_char_and_length (str
, maxlen
, len
)
1157 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1158 if (!CHAR_VALID_P (c
, 1))
1159 /* We may not change the length here because other places in Emacs
1160 don't use this function, i.e. they silently accept invalid
1169 /* Given a position POS containing a valid character and byte position
1170 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1172 static struct text_pos
1173 string_pos_nchars_ahead (pos
, string
, nchars
)
1174 struct text_pos pos
;
1178 xassert (STRINGP (string
) && nchars
>= 0);
1180 if (STRING_MULTIBYTE (string
))
1182 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1183 unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1188 string_char_and_length (p
, rest
, &len
);
1189 p
+= len
, rest
-= len
;
1190 xassert (rest
>= 0);
1192 BYTEPOS (pos
) += len
;
1196 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1202 /* Value is the text position, i.e. character and byte position,
1203 for character position CHARPOS in STRING. */
1205 static INLINE
struct text_pos
1206 string_pos (charpos
, string
)
1210 struct text_pos pos
;
1211 xassert (STRINGP (string
));
1212 xassert (charpos
>= 0);
1213 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1218 /* Value is a text position, i.e. character and byte position, for
1219 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1220 means recognize multibyte characters. */
1222 static struct text_pos
1223 c_string_pos (charpos
, s
, multibyte_p
)
1228 struct text_pos pos
;
1230 xassert (s
!= NULL
);
1231 xassert (charpos
>= 0);
1235 int rest
= strlen (s
), len
;
1237 SET_TEXT_POS (pos
, 0, 0);
1240 string_char_and_length (s
, rest
, &len
);
1241 s
+= len
, rest
-= len
;
1242 xassert (rest
>= 0);
1244 BYTEPOS (pos
) += len
;
1248 SET_TEXT_POS (pos
, charpos
, charpos
);
1254 /* Value is the number of characters in C string S. MULTIBYTE_P
1255 non-zero means recognize multibyte characters. */
1258 number_of_chars (s
, multibyte_p
)
1266 int rest
= strlen (s
), len
;
1267 unsigned char *p
= (unsigned char *) s
;
1269 for (nchars
= 0; rest
> 0; ++nchars
)
1271 string_char_and_length (p
, rest
, &len
);
1272 rest
-= len
, p
+= len
;
1276 nchars
= strlen (s
);
1282 /* Compute byte position NEWPOS->bytepos corresponding to
1283 NEWPOS->charpos. POS is a known position in string STRING.
1284 NEWPOS->charpos must be >= POS.charpos. */
1287 compute_string_pos (newpos
, pos
, string
)
1288 struct text_pos
*newpos
, pos
;
1291 xassert (STRINGP (string
));
1292 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1294 if (STRING_MULTIBYTE (string
))
1295 *newpos
= string_pos_nchars_ahead (pos
, string
,
1296 CHARPOS (*newpos
) - CHARPOS (pos
));
1298 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1303 /***********************************************************************
1304 Lisp form evaluation
1305 ***********************************************************************/
1307 /* Error handler for safe_eval and safe_call. */
1310 safe_eval_handler (arg
)
1313 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1318 /* Evaluate SEXPR and return the result, or nil if something went
1319 wrong. Prevent redisplay during the evaluation. */
1327 if (inhibit_eval_during_redisplay
)
1331 int count
= BINDING_STACK_SIZE ();
1332 struct gcpro gcpro1
;
1335 specbind (Qinhibit_redisplay
, Qt
);
1336 /* Use Qt to ensure debugger does not run,
1337 so there is no possibility of wanting to redisplay. */
1338 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1341 val
= unbind_to (count
, val
);
1348 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1349 Return the result, or nil if something went wrong. Prevent
1350 redisplay during the evaluation. */
1353 safe_call (nargs
, args
)
1359 if (inhibit_eval_during_redisplay
)
1363 int count
= BINDING_STACK_SIZE ();
1364 struct gcpro gcpro1
;
1367 gcpro1
.nvars
= nargs
;
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_2 (Ffuncall
, nargs
, args
, Qt
,
1374 val
= unbind_to (count
, val
);
1381 /* Call function FN with one argument ARG.
1382 Return the result, or nil if something went wrong. */
1385 safe_call1 (fn
, arg
)
1386 Lisp_Object fn
, arg
;
1388 Lisp_Object args
[2];
1391 return safe_call (2, args
);
1396 /***********************************************************************
1398 ***********************************************************************/
1402 /* Define CHECK_IT to perform sanity checks on iterators.
1403 This is for debugging. It is too slow to do unconditionally. */
1409 if (it
->method
== next_element_from_string
)
1411 xassert (STRINGP (it
->string
));
1412 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1414 else if (it
->method
== next_element_from_buffer
)
1416 /* Check that character and byte positions agree. */
1417 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1421 xassert (it
->current
.dpvec_index
>= 0);
1423 xassert (it
->current
.dpvec_index
< 0);
1426 #define CHECK_IT(IT) check_it ((IT))
1430 #define CHECK_IT(IT) (void) 0
1437 /* Check that the window end of window W is what we expect it
1438 to be---the last row in the current matrix displaying text. */
1441 check_window_end (w
)
1444 if (!MINI_WINDOW_P (w
)
1445 && !NILP (w
->window_end_valid
))
1447 struct glyph_row
*row
;
1448 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1449 XFASTINT (w
->window_end_vpos
)),
1451 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1452 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1456 #define CHECK_WINDOW_END(W) check_window_end ((W))
1458 #else /* not GLYPH_DEBUG */
1460 #define CHECK_WINDOW_END(W) (void) 0
1462 #endif /* not GLYPH_DEBUG */
1466 /***********************************************************************
1467 Iterator initialization
1468 ***********************************************************************/
1470 /* Initialize IT for displaying current_buffer in window W, starting
1471 at character position CHARPOS. CHARPOS < 0 means that no buffer
1472 position is specified which is useful when the iterator is assigned
1473 a position later. BYTEPOS is the byte position corresponding to
1474 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1476 If ROW is not null, calls to produce_glyphs with IT as parameter
1477 will produce glyphs in that row.
1479 BASE_FACE_ID is the id of a base face to use. It must be one of
1480 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1481 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1482 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1484 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1485 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1486 will be initialized to use the corresponding mode line glyph row of
1487 the desired matrix of W. */
1490 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1493 int charpos
, bytepos
;
1494 struct glyph_row
*row
;
1495 enum face_id base_face_id
;
1497 int highlight_region_p
;
1499 /* Some precondition checks. */
1500 xassert (w
!= NULL
&& it
!= NULL
);
1501 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1504 /* If face attributes have been changed since the last redisplay,
1505 free realized faces now because they depend on face definitions
1506 that might have changed. */
1507 if (face_change_count
)
1509 face_change_count
= 0;
1510 free_all_realized_faces (Qnil
);
1513 /* Use one of the mode line rows of W's desired matrix if
1517 if (base_face_id
== MODE_LINE_FACE_ID
1518 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1519 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1520 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1521 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1525 bzero (it
, sizeof *it
);
1526 it
->current
.overlay_string_index
= -1;
1527 it
->current
.dpvec_index
= -1;
1528 it
->base_face_id
= base_face_id
;
1530 /* The window in which we iterate over current_buffer: */
1531 XSETWINDOW (it
->window
, w
);
1533 it
->f
= XFRAME (w
->frame
);
1535 /* Extra space between lines (on window systems only). */
1536 if (base_face_id
== DEFAULT_FACE_ID
1537 && FRAME_WINDOW_P (it
->f
))
1539 if (NATNUMP (current_buffer
->extra_line_spacing
))
1540 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1541 else if (it
->f
->extra_line_spacing
> 0)
1542 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1545 /* If realized faces have been removed, e.g. because of face
1546 attribute changes of named faces, recompute them. When running
1547 in batch mode, the face cache of Vterminal_frame is null. If
1548 we happen to get called, make a dummy face cache. */
1553 FRAME_FACE_CACHE (it
->f
) == NULL
)
1554 init_frame_faces (it
->f
);
1555 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1556 recompute_basic_faces (it
->f
);
1558 /* Current value of the `space-width', and 'height' properties. */
1559 it
->space_width
= Qnil
;
1560 it
->font_height
= Qnil
;
1562 /* Are control characters displayed as `^C'? */
1563 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1565 /* -1 means everything between a CR and the following line end
1566 is invisible. >0 means lines indented more than this value are
1568 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1569 ? XFASTINT (current_buffer
->selective_display
)
1570 : (!NILP (current_buffer
->selective_display
)
1572 it
->selective_display_ellipsis_p
1573 = !NILP (current_buffer
->selective_display_ellipses
);
1575 /* Display table to use. */
1576 it
->dp
= window_display_table (w
);
1578 /* Are multibyte characters enabled in current_buffer? */
1579 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1581 /* Non-zero if we should highlight the region. */
1583 = (!NILP (Vtransient_mark_mode
)
1584 && !NILP (current_buffer
->mark_active
)
1585 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1587 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1588 start and end of a visible region in window IT->w. Set both to
1589 -1 to indicate no region. */
1590 if (highlight_region_p
1591 /* Maybe highlight only in selected window. */
1592 && (/* Either show region everywhere. */
1593 highlight_nonselected_windows
1594 /* Or show region in the selected window. */
1595 || w
== XWINDOW (selected_window
)
1596 /* Or show the region if we are in the mini-buffer and W is
1597 the window the mini-buffer refers to. */
1598 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1599 && WINDOWP (minibuf_selected_window
)
1600 && w
== XWINDOW (minibuf_selected_window
))))
1602 int charpos
= marker_position (current_buffer
->mark
);
1603 it
->region_beg_charpos
= min (PT
, charpos
);
1604 it
->region_end_charpos
= max (PT
, charpos
);
1607 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1609 /* Get the position at which the redisplay_end_trigger hook should
1610 be run, if it is to be run at all. */
1611 if (MARKERP (w
->redisplay_end_trigger
)
1612 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1613 it
->redisplay_end_trigger_charpos
1614 = marker_position (w
->redisplay_end_trigger
);
1615 else if (INTEGERP (w
->redisplay_end_trigger
))
1616 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1618 /* Correct bogus values of tab_width. */
1619 it
->tab_width
= XINT (current_buffer
->tab_width
);
1620 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1623 /* Are lines in the display truncated? */
1624 it
->truncate_lines_p
1625 = (base_face_id
!= DEFAULT_FACE_ID
1626 || XINT (it
->w
->hscroll
)
1627 || (truncate_partial_width_windows
1628 && !WINDOW_FULL_WIDTH_P (it
->w
))
1629 || !NILP (current_buffer
->truncate_lines
));
1631 /* Get dimensions of truncation and continuation glyphs. These are
1632 displayed as fringe bitmaps under X, so we don't need them for such
1634 if (!FRAME_WINDOW_P (it
->f
))
1636 if (it
->truncate_lines_p
)
1638 /* We will need the truncation glyph. */
1639 xassert (it
->glyph_row
== NULL
);
1640 produce_special_glyphs (it
, IT_TRUNCATION
);
1641 it
->truncation_pixel_width
= it
->pixel_width
;
1645 /* We will need the continuation glyph. */
1646 xassert (it
->glyph_row
== NULL
);
1647 produce_special_glyphs (it
, IT_CONTINUATION
);
1648 it
->continuation_pixel_width
= it
->pixel_width
;
1651 /* Reset these values to zero because the produce_special_glyphs
1652 above has changed them. */
1653 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1654 it
->phys_ascent
= it
->phys_descent
= 0;
1657 /* Set this after getting the dimensions of truncation and
1658 continuation glyphs, so that we don't produce glyphs when calling
1659 produce_special_glyphs, above. */
1660 it
->glyph_row
= row
;
1661 it
->area
= TEXT_AREA
;
1663 /* Get the dimensions of the display area. The display area
1664 consists of the visible window area plus a horizontally scrolled
1665 part to the left of the window. All x-values are relative to the
1666 start of this total display area. */
1667 if (base_face_id
!= DEFAULT_FACE_ID
)
1669 /* Mode lines, menu bar in terminal frames. */
1670 it
->first_visible_x
= 0;
1671 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1676 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1677 it
->last_visible_x
= (it
->first_visible_x
1678 + window_box_width (w
, TEXT_AREA
));
1680 /* If we truncate lines, leave room for the truncator glyph(s) at
1681 the right margin. Otherwise, leave room for the continuation
1682 glyph(s). Truncation and continuation glyphs are not inserted
1683 for window-based redisplay. */
1684 if (!FRAME_WINDOW_P (it
->f
))
1686 if (it
->truncate_lines_p
)
1687 it
->last_visible_x
-= it
->truncation_pixel_width
;
1689 it
->last_visible_x
-= it
->continuation_pixel_width
;
1692 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1693 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1696 /* Leave room for a border glyph. */
1697 if (!FRAME_WINDOW_P (it
->f
)
1698 && !WINDOW_RIGHTMOST_P (it
->w
))
1699 it
->last_visible_x
-= 1;
1701 it
->last_visible_y
= window_text_bottom_y (w
);
1703 /* For mode lines and alike, arrange for the first glyph having a
1704 left box line if the face specifies a box. */
1705 if (base_face_id
!= DEFAULT_FACE_ID
)
1709 it
->face_id
= base_face_id
;
1711 /* If we have a boxed mode line, make the first character appear
1712 with a left box line. */
1713 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1714 if (face
->box
!= FACE_NO_BOX
)
1715 it
->start_of_box_run_p
= 1;
1718 /* If a buffer position was specified, set the iterator there,
1719 getting overlays and face properties from that position. */
1720 if (charpos
>= BUF_BEG (current_buffer
))
1722 it
->end_charpos
= ZV
;
1724 IT_CHARPOS (*it
) = charpos
;
1726 /* Compute byte position if not specified. */
1727 if (bytepos
< charpos
)
1728 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1730 IT_BYTEPOS (*it
) = bytepos
;
1732 /* Compute faces etc. */
1733 reseat (it
, it
->current
.pos
, 1);
1740 /* Initialize IT for the display of window W with window start POS. */
1743 start_display (it
, w
, pos
)
1746 struct text_pos pos
;
1748 struct glyph_row
*row
;
1749 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1751 row
= w
->desired_matrix
->rows
+ first_vpos
;
1752 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1754 if (!it
->truncate_lines_p
)
1756 int start_at_line_beg_p
;
1757 int first_y
= it
->current_y
;
1759 /* If window start is not at a line start, skip forward to POS to
1760 get the correct continuation lines width. */
1761 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1762 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1763 if (!start_at_line_beg_p
)
1765 reseat_at_previous_visible_line_start (it
);
1766 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1768 /* If lines are continued, this line may end in the middle
1769 of a multi-glyph character (e.g. a control character
1770 displayed as \003, or in the middle of an overlay
1771 string). In this case move_it_to above will not have
1772 taken us to the start of the continuation line but to the
1773 end of the continued line. */
1774 if (it
->current_x
> 0)
1776 if (it
->current
.dpvec_index
>= 0
1777 || it
->current
.overlay_string_index
>= 0)
1779 set_iterator_to_next (it
, 1);
1780 move_it_in_display_line_to (it
, -1, -1, 0);
1783 it
->continuation_lines_width
+= it
->current_x
;
1786 /* We're starting a new display line, not affected by the
1787 height of the continued line, so clear the appropriate
1788 fields in the iterator structure. */
1789 it
->max_ascent
= it
->max_descent
= 0;
1790 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1792 it
->current_y
= first_y
;
1794 it
->current_x
= it
->hpos
= 0;
1798 #if 0 /* Don't assert the following because start_display is sometimes
1799 called intentionally with a window start that is not at a
1800 line start. Please leave this code in as a comment. */
1802 /* Window start should be on a line start, now. */
1803 xassert (it
->continuation_lines_width
1804 || IT_CHARPOS (it
) == BEGV
1805 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1810 /* Return 1 if POS is a position in ellipses displayed for invisible
1811 text. W is the window we display, for text property lookup. */
1814 in_ellipses_for_invisible_text_p (pos
, w
)
1815 struct display_pos
*pos
;
1818 Lisp_Object prop
, window
;
1820 int charpos
= CHARPOS (pos
->pos
);
1822 /* If POS specifies a position in a display vector, this might
1823 be for an ellipsis displayed for invisible text. We won't
1824 get the iterator set up for delivering that ellipsis unless
1825 we make sure that it gets aware of the invisible text. */
1826 if (pos
->dpvec_index
>= 0
1827 && pos
->overlay_string_index
< 0
1828 && CHARPOS (pos
->string_pos
) < 0
1830 && (XSETWINDOW (window
, w
),
1831 prop
= Fget_char_property (make_number (charpos
),
1832 Qinvisible
, window
),
1833 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1835 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1837 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1844 /* Initialize IT for stepping through current_buffer in window W,
1845 starting at position POS that includes overlay string and display
1846 vector/ control character translation position information. Value
1847 is zero if there are overlay strings with newlines at POS. */
1850 init_from_display_pos (it
, w
, pos
)
1853 struct display_pos
*pos
;
1855 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1856 int i
, overlay_strings_with_newlines
= 0;
1858 /* If POS specifies a position in a display vector, this might
1859 be for an ellipsis displayed for invisible text. We won't
1860 get the iterator set up for delivering that ellipsis unless
1861 we make sure that it gets aware of the invisible text. */
1862 if (in_ellipses_for_invisible_text_p (pos
, w
))
1868 /* Keep in mind: the call to reseat in init_iterator skips invisible
1869 text, so we might end up at a position different from POS. This
1870 is only a problem when POS is a row start after a newline and an
1871 overlay starts there with an after-string, and the overlay has an
1872 invisible property. Since we don't skip invisible text in
1873 display_line and elsewhere immediately after consuming the
1874 newline before the row start, such a POS will not be in a string,
1875 but the call to init_iterator below will move us to the
1877 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1879 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1881 char *s
= SDATA (it
->overlay_strings
[i
]);
1882 char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
1884 while (s
< e
&& *s
!= '\n')
1889 overlay_strings_with_newlines
= 1;
1894 /* If position is within an overlay string, set up IT to the right
1896 if (pos
->overlay_string_index
>= 0)
1900 /* If the first overlay string happens to have a `display'
1901 property for an image, the iterator will be set up for that
1902 image, and we have to undo that setup first before we can
1903 correct the overlay string index. */
1904 if (it
->method
== next_element_from_image
)
1907 /* We already have the first chunk of overlay strings in
1908 IT->overlay_strings. Load more until the one for
1909 pos->overlay_string_index is in IT->overlay_strings. */
1910 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1912 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1913 it
->current
.overlay_string_index
= 0;
1916 load_overlay_strings (it
, 0);
1917 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1921 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1922 relative_index
= (it
->current
.overlay_string_index
1923 % OVERLAY_STRING_CHUNK_SIZE
);
1924 it
->string
= it
->overlay_strings
[relative_index
];
1925 xassert (STRINGP (it
->string
));
1926 it
->current
.string_pos
= pos
->string_pos
;
1927 it
->method
= next_element_from_string
;
1930 #if 0 /* This is bogus because POS not having an overlay string
1931 position does not mean it's after the string. Example: A
1932 line starting with a before-string and initialization of IT
1933 to the previous row's end position. */
1934 else if (it
->current
.overlay_string_index
>= 0)
1936 /* If POS says we're already after an overlay string ending at
1937 POS, make sure to pop the iterator because it will be in
1938 front of that overlay string. When POS is ZV, we've thereby
1939 also ``processed'' overlay strings at ZV. */
1942 it
->current
.overlay_string_index
= -1;
1943 it
->method
= next_element_from_buffer
;
1944 if (CHARPOS (pos
->pos
) == ZV
)
1945 it
->overlay_strings_at_end_processed_p
= 1;
1949 if (CHARPOS (pos
->string_pos
) >= 0)
1951 /* Recorded position is not in an overlay string, but in another
1952 string. This can only be a string from a `display' property.
1953 IT should already be filled with that string. */
1954 it
->current
.string_pos
= pos
->string_pos
;
1955 xassert (STRINGP (it
->string
));
1958 /* Restore position in display vector translations, control
1959 character translations or ellipses. */
1960 if (pos
->dpvec_index
>= 0)
1962 if (it
->dpvec
== NULL
)
1963 get_next_display_element (it
);
1964 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1965 it
->current
.dpvec_index
= pos
->dpvec_index
;
1969 return !overlay_strings_with_newlines
;
1973 /* Initialize IT for stepping through current_buffer in window W
1974 starting at ROW->start. */
1977 init_to_row_start (it
, w
, row
)
1980 struct glyph_row
*row
;
1982 init_from_display_pos (it
, w
, &row
->start
);
1983 it
->continuation_lines_width
= row
->continuation_lines_width
;
1988 /* Initialize IT for stepping through current_buffer in window W
1989 starting in the line following ROW, i.e. starting at ROW->end.
1990 Value is zero if there are overlay strings with newlines at ROW's
1994 init_to_row_end (it
, w
, row
)
1997 struct glyph_row
*row
;
2001 if (init_from_display_pos (it
, w
, &row
->end
))
2003 if (row
->continued_p
)
2004 it
->continuation_lines_width
2005 = row
->continuation_lines_width
+ row
->pixel_width
;
2016 /***********************************************************************
2018 ***********************************************************************/
2020 /* Called when IT reaches IT->stop_charpos. Handle text property and
2021 overlay changes. Set IT->stop_charpos to the next position where
2028 enum prop_handled handled
;
2029 int handle_overlay_change_p
= 1;
2033 it
->current
.dpvec_index
= -1;
2037 handled
= HANDLED_NORMALLY
;
2039 /* Call text property handlers. */
2040 for (p
= it_props
; p
->handler
; ++p
)
2042 handled
= p
->handler (it
);
2044 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2046 else if (handled
== HANDLED_RETURN
)
2048 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2049 handle_overlay_change_p
= 0;
2052 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2054 /* Don't check for overlay strings below when set to deliver
2055 characters from a display vector. */
2056 if (it
->method
== next_element_from_display_vector
)
2057 handle_overlay_change_p
= 0;
2059 /* Handle overlay changes. */
2060 if (handle_overlay_change_p
)
2061 handled
= handle_overlay_change (it
);
2063 /* Determine where to stop next. */
2064 if (handled
== HANDLED_NORMALLY
)
2065 compute_stop_pos (it
);
2068 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2072 /* Compute IT->stop_charpos from text property and overlay change
2073 information for IT's current position. */
2076 compute_stop_pos (it
)
2079 register INTERVAL iv
, next_iv
;
2080 Lisp_Object object
, limit
, position
;
2082 /* If nowhere else, stop at the end. */
2083 it
->stop_charpos
= it
->end_charpos
;
2085 if (STRINGP (it
->string
))
2087 /* Strings are usually short, so don't limit the search for
2089 object
= it
->string
;
2091 position
= make_number (IT_STRING_CHARPOS (*it
));
2097 /* If next overlay change is in front of the current stop pos
2098 (which is IT->end_charpos), stop there. Note: value of
2099 next_overlay_change is point-max if no overlay change
2101 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2102 if (charpos
< it
->stop_charpos
)
2103 it
->stop_charpos
= charpos
;
2105 /* If showing the region, we have to stop at the region
2106 start or end because the face might change there. */
2107 if (it
->region_beg_charpos
> 0)
2109 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2110 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2111 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2112 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2115 /* Set up variables for computing the stop position from text
2116 property changes. */
2117 XSETBUFFER (object
, current_buffer
);
2118 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2119 position
= make_number (IT_CHARPOS (*it
));
2123 /* Get the interval containing IT's position. Value is a null
2124 interval if there isn't such an interval. */
2125 iv
= validate_interval_range (object
, &position
, &position
, 0);
2126 if (!NULL_INTERVAL_P (iv
))
2128 Lisp_Object values_here
[LAST_PROP_IDX
];
2131 /* Get properties here. */
2132 for (p
= it_props
; p
->handler
; ++p
)
2133 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2135 /* Look for an interval following iv that has different
2137 for (next_iv
= next_interval (iv
);
2138 (!NULL_INTERVAL_P (next_iv
)
2140 || XFASTINT (limit
) > next_iv
->position
));
2141 next_iv
= next_interval (next_iv
))
2143 for (p
= it_props
; p
->handler
; ++p
)
2145 Lisp_Object new_value
;
2147 new_value
= textget (next_iv
->plist
, *p
->name
);
2148 if (!EQ (values_here
[p
->idx
], new_value
))
2156 if (!NULL_INTERVAL_P (next_iv
))
2158 if (INTEGERP (limit
)
2159 && next_iv
->position
>= XFASTINT (limit
))
2160 /* No text property change up to limit. */
2161 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2163 /* Text properties change in next_iv. */
2164 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2168 xassert (STRINGP (it
->string
)
2169 || (it
->stop_charpos
>= BEGV
2170 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2174 /* Return the position of the next overlay change after POS in
2175 current_buffer. Value is point-max if no overlay change
2176 follows. This is like `next-overlay-change' but doesn't use
2180 next_overlay_change (pos
)
2185 Lisp_Object
*overlays
;
2189 /* Get all overlays at the given position. */
2191 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2192 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2193 if (noverlays
> len
)
2196 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2197 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2200 /* If any of these overlays ends before endpos,
2201 use its ending point instead. */
2202 for (i
= 0; i
< noverlays
; ++i
)
2207 oend
= OVERLAY_END (overlays
[i
]);
2208 oendpos
= OVERLAY_POSITION (oend
);
2209 endpos
= min (endpos
, oendpos
);
2217 /***********************************************************************
2219 ***********************************************************************/
2221 /* Handle changes in the `fontified' property of the current buffer by
2222 calling hook functions from Qfontification_functions to fontify
2225 static enum prop_handled
2226 handle_fontified_prop (it
)
2229 Lisp_Object prop
, pos
;
2230 enum prop_handled handled
= HANDLED_NORMALLY
;
2232 /* Get the value of the `fontified' property at IT's current buffer
2233 position. (The `fontified' property doesn't have a special
2234 meaning in strings.) If the value is nil, call functions from
2235 Qfontification_functions. */
2236 if (!STRINGP (it
->string
)
2238 && !NILP (Vfontification_functions
)
2239 && !NILP (Vrun_hooks
)
2240 && (pos
= make_number (IT_CHARPOS (*it
)),
2241 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2244 int count
= BINDING_STACK_SIZE ();
2247 val
= Vfontification_functions
;
2248 specbind (Qfontification_functions
, Qnil
);
2250 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2251 safe_call1 (val
, pos
);
2254 Lisp_Object globals
, fn
;
2255 struct gcpro gcpro1
, gcpro2
;
2258 GCPRO2 (val
, globals
);
2260 for (; CONSP (val
); val
= XCDR (val
))
2266 /* A value of t indicates this hook has a local
2267 binding; it means to run the global binding too.
2268 In a global value, t should not occur. If it
2269 does, we must ignore it to avoid an endless
2271 for (globals
= Fdefault_value (Qfontification_functions
);
2273 globals
= XCDR (globals
))
2275 fn
= XCAR (globals
);
2277 safe_call1 (fn
, pos
);
2281 safe_call1 (fn
, pos
);
2287 unbind_to (count
, Qnil
);
2289 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2290 something. This avoids an endless loop if they failed to
2291 fontify the text for which reason ever. */
2292 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2293 handled
= HANDLED_RECOMPUTE_PROPS
;
2301 /***********************************************************************
2303 ***********************************************************************/
2305 /* Set up iterator IT from face properties at its current position.
2306 Called from handle_stop. */
2308 static enum prop_handled
2309 handle_face_prop (it
)
2312 int new_face_id
, next_stop
;
2314 if (!STRINGP (it
->string
))
2317 = face_at_buffer_position (it
->w
,
2319 it
->region_beg_charpos
,
2320 it
->region_end_charpos
,
2323 + TEXT_PROP_DISTANCE_LIMIT
),
2326 /* Is this a start of a run of characters with box face?
2327 Caveat: this can be called for a freshly initialized
2328 iterator; face_id is -1 in this case. We know that the new
2329 face will not change until limit, i.e. if the new face has a
2330 box, all characters up to limit will have one. But, as
2331 usual, we don't know whether limit is really the end. */
2332 if (new_face_id
!= it
->face_id
)
2334 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2336 /* If new face has a box but old face has not, this is
2337 the start of a run of characters with box, i.e. it has
2338 a shadow on the left side. The value of face_id of the
2339 iterator will be -1 if this is the initial call that gets
2340 the face. In this case, we have to look in front of IT's
2341 position and see whether there is a face != new_face_id. */
2342 it
->start_of_box_run_p
2343 = (new_face
->box
!= FACE_NO_BOX
2344 && (it
->face_id
>= 0
2345 || IT_CHARPOS (*it
) == BEG
2346 || new_face_id
!= face_before_it_pos (it
)));
2347 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2352 int base_face_id
, bufpos
;
2354 if (it
->current
.overlay_string_index
>= 0)
2355 bufpos
= IT_CHARPOS (*it
);
2359 /* For strings from a buffer, i.e. overlay strings or strings
2360 from a `display' property, use the face at IT's current
2361 buffer position as the base face to merge with, so that
2362 overlay strings appear in the same face as surrounding
2363 text, unless they specify their own faces. */
2364 base_face_id
= underlying_face_id (it
);
2366 new_face_id
= face_at_string_position (it
->w
,
2368 IT_STRING_CHARPOS (*it
),
2370 it
->region_beg_charpos
,
2371 it
->region_end_charpos
,
2375 #if 0 /* This shouldn't be neccessary. Let's check it. */
2376 /* If IT is used to display a mode line we would really like to
2377 use the mode line face instead of the frame's default face. */
2378 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2379 && new_face_id
== DEFAULT_FACE_ID
)
2380 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2383 /* Is this a start of a run of characters with box? Caveat:
2384 this can be called for a freshly allocated iterator; face_id
2385 is -1 is this case. We know that the new face will not
2386 change until the next check pos, i.e. if the new face has a
2387 box, all characters up to that position will have a
2388 box. But, as usual, we don't know whether that position
2389 is really the end. */
2390 if (new_face_id
!= it
->face_id
)
2392 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2393 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2395 /* If new face has a box but old face hasn't, this is the
2396 start of a run of characters with box, i.e. it has a
2397 shadow on the left side. */
2398 it
->start_of_box_run_p
2399 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2400 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2404 it
->face_id
= new_face_id
;
2405 return HANDLED_NORMALLY
;
2409 /* Return the ID of the face ``underlying'' IT's current position,
2410 which is in a string. If the iterator is associated with a
2411 buffer, return the face at IT's current buffer position.
2412 Otherwise, use the iterator's base_face_id. */
2415 underlying_face_id (it
)
2418 int face_id
= it
->base_face_id
, i
;
2420 xassert (STRINGP (it
->string
));
2422 for (i
= it
->sp
- 1; i
>= 0; --i
)
2423 if (NILP (it
->stack
[i
].string
))
2424 face_id
= it
->stack
[i
].face_id
;
2430 /* Compute the face one character before or after the current position
2431 of IT. BEFORE_P non-zero means get the face in front of IT's
2432 position. Value is the id of the face. */
2435 face_before_or_after_it_pos (it
, before_p
)
2440 int next_check_charpos
;
2441 struct text_pos pos
;
2443 xassert (it
->s
== NULL
);
2445 if (STRINGP (it
->string
))
2447 int bufpos
, base_face_id
;
2449 /* No face change past the end of the string (for the case
2450 we are padding with spaces). No face change before the
2452 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2453 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2456 /* Set pos to the position before or after IT's current position. */
2458 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2460 /* For composition, we must check the character after the
2462 pos
= (it
->what
== IT_COMPOSITION
2463 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2464 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2466 if (it
->current
.overlay_string_index
>= 0)
2467 bufpos
= IT_CHARPOS (*it
);
2471 base_face_id
= underlying_face_id (it
);
2473 /* Get the face for ASCII, or unibyte. */
2474 face_id
= face_at_string_position (it
->w
,
2478 it
->region_beg_charpos
,
2479 it
->region_end_charpos
,
2480 &next_check_charpos
,
2483 /* Correct the face for charsets different from ASCII. Do it
2484 for the multibyte case only. The face returned above is
2485 suitable for unibyte text if IT->string is unibyte. */
2486 if (STRING_MULTIBYTE (it
->string
))
2488 unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2489 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2491 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2493 c
= string_char_and_length (p
, rest
, &len
);
2494 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2499 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2500 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2503 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2504 pos
= it
->current
.pos
;
2507 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2510 if (it
->what
== IT_COMPOSITION
)
2511 /* For composition, we must check the position after the
2513 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2515 INC_TEXT_POS (pos
, it
->multibyte_p
);
2518 /* Determine face for CHARSET_ASCII, or unibyte. */
2519 face_id
= face_at_buffer_position (it
->w
,
2521 it
->region_beg_charpos
,
2522 it
->region_end_charpos
,
2523 &next_check_charpos
,
2526 /* Correct the face for charsets different from ASCII. Do it
2527 for the multibyte case only. The face returned above is
2528 suitable for unibyte text if current_buffer is unibyte. */
2529 if (it
->multibyte_p
)
2531 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2532 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2533 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2542 /***********************************************************************
2544 ***********************************************************************/
2546 /* Set up iterator IT from invisible properties at its current
2547 position. Called from handle_stop. */
2549 static enum prop_handled
2550 handle_invisible_prop (it
)
2553 enum prop_handled handled
= HANDLED_NORMALLY
;
2555 if (STRINGP (it
->string
))
2557 extern Lisp_Object Qinvisible
;
2558 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2560 /* Get the value of the invisible text property at the
2561 current position. Value will be nil if there is no such
2563 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2564 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2567 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2569 handled
= HANDLED_RECOMPUTE_PROPS
;
2571 /* Get the position at which the next change of the
2572 invisible text property can be found in IT->string.
2573 Value will be nil if the property value is the same for
2574 all the rest of IT->string. */
2575 XSETINT (limit
, SCHARS (it
->string
));
2576 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2579 /* Text at current position is invisible. The next
2580 change in the property is at position end_charpos.
2581 Move IT's current position to that position. */
2582 if (INTEGERP (end_charpos
)
2583 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2585 struct text_pos old
;
2586 old
= it
->current
.string_pos
;
2587 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2588 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2592 /* The rest of the string is invisible. If this is an
2593 overlay string, proceed with the next overlay string
2594 or whatever comes and return a character from there. */
2595 if (it
->current
.overlay_string_index
>= 0)
2597 next_overlay_string (it
);
2598 /* Don't check for overlay strings when we just
2599 finished processing them. */
2600 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2604 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
2605 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
2612 int invis_p
, newpos
, next_stop
, start_charpos
;
2613 Lisp_Object pos
, prop
, overlay
;
2615 /* First of all, is there invisible text at this position? */
2616 start_charpos
= IT_CHARPOS (*it
);
2617 pos
= make_number (IT_CHARPOS (*it
));
2618 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2620 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2622 /* If we are on invisible text, skip over it. */
2623 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2625 /* Record whether we have to display an ellipsis for the
2627 int display_ellipsis_p
= invis_p
== 2;
2629 handled
= HANDLED_RECOMPUTE_PROPS
;
2631 /* Loop skipping over invisible text. The loop is left at
2632 ZV or with IT on the first char being visible again. */
2635 /* Try to skip some invisible text. Return value is the
2636 position reached which can be equal to IT's position
2637 if there is nothing invisible here. This skips both
2638 over invisible text properties and overlays with
2639 invisible property. */
2640 newpos
= skip_invisible (IT_CHARPOS (*it
),
2641 &next_stop
, ZV
, it
->window
);
2643 /* If we skipped nothing at all we weren't at invisible
2644 text in the first place. If everything to the end of
2645 the buffer was skipped, end the loop. */
2646 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2650 /* We skipped some characters but not necessarily
2651 all there are. Check if we ended up on visible
2652 text. Fget_char_property returns the property of
2653 the char before the given position, i.e. if we
2654 get invis_p = 0, this means that the char at
2655 newpos is visible. */
2656 pos
= make_number (newpos
);
2657 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2658 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2661 /* If we ended up on invisible text, proceed to
2662 skip starting with next_stop. */
2664 IT_CHARPOS (*it
) = next_stop
;
2668 /* The position newpos is now either ZV or on visible text. */
2669 IT_CHARPOS (*it
) = newpos
;
2670 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2672 /* If there are before-strings at the start of invisible
2673 text, and the text is invisible because of a text
2674 property, arrange to show before-strings because 20.x did
2675 it that way. (If the text is invisible because of an
2676 overlay property instead of a text property, this is
2677 already handled in the overlay code.) */
2679 && get_overlay_strings (it
, start_charpos
))
2681 handled
= HANDLED_RECOMPUTE_PROPS
;
2682 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2684 else if (display_ellipsis_p
)
2685 setup_for_ellipsis (it
);
2693 /* Make iterator IT return `...' next. */
2696 setup_for_ellipsis (it
)
2700 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2702 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2703 it
->dpvec
= v
->contents
;
2704 it
->dpend
= v
->contents
+ v
->size
;
2708 /* Default `...'. */
2709 it
->dpvec
= default_invis_vector
;
2710 it
->dpend
= default_invis_vector
+ 3;
2713 /* The ellipsis display does not replace the display of the
2714 character at the new position. Indicate this by setting
2715 IT->dpvec_char_len to zero. */
2716 it
->dpvec_char_len
= 0;
2718 it
->current
.dpvec_index
= 0;
2719 it
->method
= next_element_from_display_vector
;
2724 /***********************************************************************
2726 ***********************************************************************/
2728 /* Set up iterator IT from `display' property at its current position.
2729 Called from handle_stop. */
2731 static enum prop_handled
2732 handle_display_prop (it
)
2735 Lisp_Object prop
, object
;
2736 struct text_pos
*position
;
2737 int display_replaced_p
= 0;
2739 if (STRINGP (it
->string
))
2741 object
= it
->string
;
2742 position
= &it
->current
.string_pos
;
2746 object
= it
->w
->buffer
;
2747 position
= &it
->current
.pos
;
2750 /* Reset those iterator values set from display property values. */
2751 it
->font_height
= Qnil
;
2752 it
->space_width
= Qnil
;
2755 /* We don't support recursive `display' properties, i.e. string
2756 values that have a string `display' property, that have a string
2757 `display' property etc. */
2758 if (!it
->string_from_display_prop_p
)
2759 it
->area
= TEXT_AREA
;
2761 prop
= Fget_char_property (make_number (position
->charpos
),
2764 return HANDLED_NORMALLY
;
2767 /* Simple properties. */
2768 && !EQ (XCAR (prop
), Qimage
)
2769 && !EQ (XCAR (prop
), Qspace
)
2770 && !EQ (XCAR (prop
), Qwhen
)
2771 && !EQ (XCAR (prop
), Qspace_width
)
2772 && !EQ (XCAR (prop
), Qheight
)
2773 && !EQ (XCAR (prop
), Qraise
)
2774 /* Marginal area specifications. */
2775 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2776 && !NILP (XCAR (prop
)))
2778 for (; CONSP (prop
); prop
= XCDR (prop
))
2780 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2781 position
, display_replaced_p
))
2782 display_replaced_p
= 1;
2785 else if (VECTORP (prop
))
2788 for (i
= 0; i
< ASIZE (prop
); ++i
)
2789 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2790 position
, display_replaced_p
))
2791 display_replaced_p
= 1;
2795 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2796 display_replaced_p
= 1;
2799 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2803 /* Value is the position of the end of the `display' property starting
2804 at START_POS in OBJECT. */
2806 static struct text_pos
2807 display_prop_end (it
, object
, start_pos
)
2810 struct text_pos start_pos
;
2813 struct text_pos end_pos
;
2815 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2816 Qdisplay
, object
, Qnil
);
2817 CHARPOS (end_pos
) = XFASTINT (end
);
2818 if (STRINGP (object
))
2819 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2821 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2827 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2828 is the object in which the `display' property was found. *POSITION
2829 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2830 means that we previously saw a display sub-property which already
2831 replaced text display with something else, for example an image;
2832 ignore such properties after the first one has been processed.
2834 If PROP is a `space' or `image' sub-property, set *POSITION to the
2835 end position of the `display' property.
2837 Value is non-zero if something was found which replaces the display
2838 of buffer or string text. */
2841 handle_single_display_prop (it
, prop
, object
, position
,
2842 display_replaced_before_p
)
2846 struct text_pos
*position
;
2847 int display_replaced_before_p
;
2850 int replaces_text_display_p
= 0;
2853 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2854 evaluated. If the result is nil, VALUE is ignored. */
2856 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2865 if (!NILP (form
) && !EQ (form
, Qt
))
2867 int count
= BINDING_STACK_SIZE ();
2868 struct gcpro gcpro1
;
2870 /* Bind `object' to the object having the `display' property, a
2871 buffer or string. Bind `position' to the position in the
2872 object where the property was found, and `buffer-position'
2873 to the current position in the buffer. */
2874 specbind (Qobject
, object
);
2875 specbind (Qposition
, make_number (CHARPOS (*position
)));
2876 specbind (Qbuffer_position
,
2877 make_number (STRINGP (object
)
2878 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2880 form
= safe_eval (form
);
2882 unbind_to (count
, Qnil
);
2889 && EQ (XCAR (prop
), Qheight
)
2890 && CONSP (XCDR (prop
)))
2892 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2895 /* `(height HEIGHT)'. */
2896 it
->font_height
= XCAR (XCDR (prop
));
2897 if (!NILP (it
->font_height
))
2899 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2900 int new_height
= -1;
2902 if (CONSP (it
->font_height
)
2903 && (EQ (XCAR (it
->font_height
), Qplus
)
2904 || EQ (XCAR (it
->font_height
), Qminus
))
2905 && CONSP (XCDR (it
->font_height
))
2906 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2908 /* `(+ N)' or `(- N)' where N is an integer. */
2909 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2910 if (EQ (XCAR (it
->font_height
), Qplus
))
2912 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2914 else if (FUNCTIONP (it
->font_height
))
2916 /* Call function with current height as argument.
2917 Value is the new height. */
2919 height
= safe_call1 (it
->font_height
,
2920 face
->lface
[LFACE_HEIGHT_INDEX
]);
2921 if (NUMBERP (height
))
2922 new_height
= XFLOATINT (height
);
2924 else if (NUMBERP (it
->font_height
))
2926 /* Value is a multiple of the canonical char height. */
2929 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2930 new_height
= (XFLOATINT (it
->font_height
)
2931 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2935 /* Evaluate IT->font_height with `height' bound to the
2936 current specified height to get the new height. */
2938 int count
= BINDING_STACK_SIZE ();
2940 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2941 value
= safe_eval (it
->font_height
);
2942 unbind_to (count
, Qnil
);
2944 if (NUMBERP (value
))
2945 new_height
= XFLOATINT (value
);
2949 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2952 else if (CONSP (prop
)
2953 && EQ (XCAR (prop
), Qspace_width
)
2954 && CONSP (XCDR (prop
)))
2956 /* `(space_width WIDTH)'. */
2957 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2960 value
= XCAR (XCDR (prop
));
2961 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2962 it
->space_width
= value
;
2964 else if (CONSP (prop
)
2965 && EQ (XCAR (prop
), Qraise
)
2966 && CONSP (XCDR (prop
)))
2968 /* `(raise FACTOR)'. */
2969 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2972 #ifdef HAVE_WINDOW_SYSTEM
2973 value
= XCAR (XCDR (prop
));
2974 if (NUMBERP (value
))
2976 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2977 it
->voffset
= - (XFLOATINT (value
)
2978 * (FONT_HEIGHT (face
->font
)));
2980 #endif /* HAVE_WINDOW_SYSTEM */
2982 else if (!it
->string_from_display_prop_p
)
2984 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2985 VALUE) or `((margin nil) VALUE)' or VALUE. */
2986 Lisp_Object location
, value
;
2987 struct text_pos start_pos
;
2990 /* Characters having this form of property are not displayed, so
2991 we have to find the end of the property. */
2992 start_pos
= *position
;
2993 *position
= display_prop_end (it
, object
, start_pos
);
2996 /* Let's stop at the new position and assume that all
2997 text properties change there. */
2998 it
->stop_charpos
= position
->charpos
;
3000 location
= Qunbound
;
3001 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3005 value
= XCDR (prop
);
3007 value
= XCAR (value
);
3010 if (EQ (XCAR (tem
), Qmargin
)
3011 && (tem
= XCDR (tem
),
3012 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3014 || EQ (tem
, Qleft_margin
)
3015 || EQ (tem
, Qright_margin
))))
3019 if (EQ (location
, Qunbound
))
3025 #ifdef HAVE_WINDOW_SYSTEM
3026 if (FRAME_TERMCAP_P (it
->f
))
3027 valid_p
= STRINGP (value
);
3029 valid_p
= (STRINGP (value
)
3030 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3031 || valid_image_p (value
));
3032 #else /* not HAVE_WINDOW_SYSTEM */
3033 valid_p
= STRINGP (value
);
3034 #endif /* not HAVE_WINDOW_SYSTEM */
3036 if ((EQ (location
, Qleft_margin
)
3037 || EQ (location
, Qright_margin
)
3040 && !display_replaced_before_p
)
3042 replaces_text_display_p
= 1;
3044 /* Save current settings of IT so that we can restore them
3045 when we are finished with the glyph property value. */
3048 if (NILP (location
))
3049 it
->area
= TEXT_AREA
;
3050 else if (EQ (location
, Qleft_margin
))
3051 it
->area
= LEFT_MARGIN_AREA
;
3053 it
->area
= RIGHT_MARGIN_AREA
;
3055 if (STRINGP (value
))
3058 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3059 it
->current
.overlay_string_index
= -1;
3060 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3061 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3062 it
->method
= next_element_from_string
;
3063 it
->stop_charpos
= 0;
3064 it
->string_from_display_prop_p
= 1;
3065 /* Say that we haven't consumed the characters with
3066 `display' property yet. The call to pop_it in
3067 set_iterator_to_next will clean this up. */
3068 *position
= start_pos
;
3070 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3072 it
->method
= next_element_from_stretch
;
3074 it
->current
.pos
= it
->position
= start_pos
;
3076 #ifdef HAVE_WINDOW_SYSTEM
3079 it
->what
= IT_IMAGE
;
3080 it
->image_id
= lookup_image (it
->f
, value
);
3081 it
->position
= start_pos
;
3082 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3083 it
->method
= next_element_from_image
;
3085 /* Say that we haven't consumed the characters with
3086 `display' property yet. The call to pop_it in
3087 set_iterator_to_next will clean this up. */
3088 *position
= start_pos
;
3090 #endif /* HAVE_WINDOW_SYSTEM */
3093 /* Invalid property or property not supported. Restore
3094 the position to what it was before. */
3095 *position
= start_pos
;
3098 return replaces_text_display_p
;
3102 /* Check if PROP is a display sub-property value whose text should be
3103 treated as intangible. */
3106 single_display_prop_intangible_p (prop
)
3109 /* Skip over `when FORM'. */
3110 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3121 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3122 we don't need to treat text as intangible. */
3123 if (EQ (XCAR (prop
), Qmargin
))
3131 || EQ (XCAR (prop
), Qleft_margin
)
3132 || EQ (XCAR (prop
), Qright_margin
))
3136 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3140 /* Check if PROP is a display property value whose text should be
3141 treated as intangible. */
3144 display_prop_intangible_p (prop
)
3148 && CONSP (XCAR (prop
))
3149 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3151 /* A list of sub-properties. */
3152 while (CONSP (prop
))
3154 if (single_display_prop_intangible_p (XCAR (prop
)))
3159 else if (VECTORP (prop
))
3161 /* A vector of sub-properties. */
3163 for (i
= 0; i
< ASIZE (prop
); ++i
)
3164 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3168 return single_display_prop_intangible_p (prop
);
3174 /* Return 1 if PROP is a display sub-property value containing STRING. */
3177 single_display_prop_string_p (prop
, string
)
3178 Lisp_Object prop
, string
;
3180 if (EQ (string
, prop
))
3183 /* Skip over `when FORM'. */
3184 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3193 /* Skip over `margin LOCATION'. */
3194 if (EQ (XCAR (prop
), Qmargin
))
3205 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3209 /* Return 1 if STRING appears in the `display' property PROP. */
3212 display_prop_string_p (prop
, string
)
3213 Lisp_Object prop
, string
;
3216 && CONSP (XCAR (prop
))
3217 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3219 /* A list of sub-properties. */
3220 while (CONSP (prop
))
3222 if (single_display_prop_string_p (XCAR (prop
), string
))
3227 else if (VECTORP (prop
))
3229 /* A vector of sub-properties. */
3231 for (i
= 0; i
< ASIZE (prop
); ++i
)
3232 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3236 return single_display_prop_string_p (prop
, string
);
3242 /* Determine from which buffer position in W's buffer STRING comes
3243 from. AROUND_CHARPOS is an approximate position where it could
3244 be from. Value is the buffer position or 0 if it couldn't be
3247 W's buffer must be current.
3249 This function is necessary because we don't record buffer positions
3250 in glyphs generated from strings (to keep struct glyph small).
3251 This function may only use code that doesn't eval because it is
3252 called asynchronously from note_mouse_highlight. */
3255 string_buffer_position (w
, string
, around_charpos
)
3260 Lisp_Object limit
, prop
, pos
;
3261 const int MAX_DISTANCE
= 1000;
3264 pos
= make_number (around_charpos
);
3265 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3266 while (!found
&& !EQ (pos
, limit
))
3268 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3269 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3272 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3277 pos
= make_number (around_charpos
);
3278 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3279 while (!found
&& !EQ (pos
, limit
))
3281 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3282 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3285 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3290 return found
? XINT (pos
) : 0;
3295 /***********************************************************************
3296 `composition' property
3297 ***********************************************************************/
3299 /* Set up iterator IT from `composition' property at its current
3300 position. Called from handle_stop. */
3302 static enum prop_handled
3303 handle_composition_prop (it
)
3306 Lisp_Object prop
, string
;
3307 int pos
, pos_byte
, end
;
3308 enum prop_handled handled
= HANDLED_NORMALLY
;
3310 if (STRINGP (it
->string
))
3312 pos
= IT_STRING_CHARPOS (*it
);
3313 pos_byte
= IT_STRING_BYTEPOS (*it
);
3314 string
= it
->string
;
3318 pos
= IT_CHARPOS (*it
);
3319 pos_byte
= IT_BYTEPOS (*it
);
3323 /* If there's a valid composition and point is not inside of the
3324 composition (in the case that the composition is from the current
3325 buffer), draw a glyph composed from the composition components. */
3326 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3327 && COMPOSITION_VALID_P (pos
, end
, prop
)
3328 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3330 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3334 it
->method
= next_element_from_composition
;
3336 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3337 /* For a terminal, draw only the first character of the
3339 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3340 it
->len
= (STRINGP (it
->string
)
3341 ? string_char_to_byte (it
->string
, end
)
3342 : CHAR_TO_BYTE (end
)) - pos_byte
;
3343 it
->stop_charpos
= end
;
3344 handled
= HANDLED_RETURN
;
3353 /***********************************************************************
3355 ***********************************************************************/
3357 /* The following structure is used to record overlay strings for
3358 later sorting in load_overlay_strings. */
3360 struct overlay_entry
3362 Lisp_Object overlay
;
3369 /* Set up iterator IT from overlay strings at its current position.
3370 Called from handle_stop. */
3372 static enum prop_handled
3373 handle_overlay_change (it
)
3376 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3377 return HANDLED_RECOMPUTE_PROPS
;
3379 return HANDLED_NORMALLY
;
3383 /* Set up the next overlay string for delivery by IT, if there is an
3384 overlay string to deliver. Called by set_iterator_to_next when the
3385 end of the current overlay string is reached. If there are more
3386 overlay strings to display, IT->string and
3387 IT->current.overlay_string_index are set appropriately here.
3388 Otherwise IT->string is set to nil. */
3391 next_overlay_string (it
)
3394 ++it
->current
.overlay_string_index
;
3395 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3397 /* No more overlay strings. Restore IT's settings to what
3398 they were before overlay strings were processed, and
3399 continue to deliver from current_buffer. */
3400 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3403 xassert (it
->stop_charpos
>= BEGV
3404 && it
->stop_charpos
<= it
->end_charpos
);
3406 it
->current
.overlay_string_index
= -1;
3407 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3408 it
->n_overlay_strings
= 0;
3409 it
->method
= next_element_from_buffer
;
3411 /* If we're at the end of the buffer, record that we have
3412 processed the overlay strings there already, so that
3413 next_element_from_buffer doesn't try it again. */
3414 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3415 it
->overlay_strings_at_end_processed_p
= 1;
3417 /* If we have to display `...' for invisible text, set
3418 the iterator up for that. */
3419 if (display_ellipsis_p
)
3420 setup_for_ellipsis (it
);
3424 /* There are more overlay strings to process. If
3425 IT->current.overlay_string_index has advanced to a position
3426 where we must load IT->overlay_strings with more strings, do
3428 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3430 if (it
->current
.overlay_string_index
&& i
== 0)
3431 load_overlay_strings (it
, 0);
3433 /* Initialize IT to deliver display elements from the overlay
3435 it
->string
= it
->overlay_strings
[i
];
3436 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3437 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3438 it
->method
= next_element_from_string
;
3439 it
->stop_charpos
= 0;
3446 /* Compare two overlay_entry structures E1 and E2. Used as a
3447 comparison function for qsort in load_overlay_strings. Overlay
3448 strings for the same position are sorted so that
3450 1. All after-strings come in front of before-strings, except
3451 when they come from the same overlay.
3453 2. Within after-strings, strings are sorted so that overlay strings
3454 from overlays with higher priorities come first.
3456 2. Within before-strings, strings are sorted so that overlay
3457 strings from overlays with higher priorities come last.
3459 Value is analogous to strcmp. */
3463 compare_overlay_entries (e1
, e2
)
3466 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3467 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3470 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3472 /* Let after-strings appear in front of before-strings if
3473 they come from different overlays. */
3474 if (EQ (entry1
->overlay
, entry2
->overlay
))
3475 result
= entry1
->after_string_p
? 1 : -1;
3477 result
= entry1
->after_string_p
? -1 : 1;
3479 else if (entry1
->after_string_p
)
3480 /* After-strings sorted in order of decreasing priority. */
3481 result
= entry2
->priority
- entry1
->priority
;
3483 /* Before-strings sorted in order of increasing priority. */
3484 result
= entry1
->priority
- entry2
->priority
;
3490 /* Load the vector IT->overlay_strings with overlay strings from IT's
3491 current buffer position, or from CHARPOS if that is > 0. Set
3492 IT->n_overlays to the total number of overlay strings found.
3494 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3495 a time. On entry into load_overlay_strings,
3496 IT->current.overlay_string_index gives the number of overlay
3497 strings that have already been loaded by previous calls to this
3500 IT->add_overlay_start contains an additional overlay start
3501 position to consider for taking overlay strings from, if non-zero.
3502 This position comes into play when the overlay has an `invisible'
3503 property, and both before and after-strings. When we've skipped to
3504 the end of the overlay, because of its `invisible' property, we
3505 nevertheless want its before-string to appear.
3506 IT->add_overlay_start will contain the overlay start position
3509 Overlay strings are sorted so that after-string strings come in
3510 front of before-string strings. Within before and after-strings,
3511 strings are sorted by overlay priority. See also function
3512 compare_overlay_entries. */
3515 load_overlay_strings (it
, charpos
)
3519 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3520 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3523 int n
= 0, i
, j
, invis_p
;
3524 struct overlay_entry
*entries
3525 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3528 charpos
= IT_CHARPOS (*it
);
3530 /* Append the overlay string STRING of overlay OVERLAY to vector
3531 `entries' which has size `size' and currently contains `n'
3532 elements. AFTER_P non-zero means STRING is an after-string of
3534 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3537 Lisp_Object priority; \
3541 int new_size = 2 * size; \
3542 struct overlay_entry *old = entries; \
3544 (struct overlay_entry *) alloca (new_size \
3545 * sizeof *entries); \
3546 bcopy (old, entries, size * sizeof *entries); \
3550 entries[n].string = (STRING); \
3551 entries[n].overlay = (OVERLAY); \
3552 priority = Foverlay_get ((OVERLAY), Qpriority); \
3553 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3554 entries[n].after_string_p = (AFTER_P); \
3559 /* Process overlay before the overlay center. */
3560 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3562 overlay
= XCAR (ov
);
3563 xassert (OVERLAYP (overlay
));
3564 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3565 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3570 /* Skip this overlay if it doesn't start or end at IT's current
3572 if (end
!= charpos
&& start
!= charpos
)
3575 /* Skip this overlay if it doesn't apply to IT->w. */
3576 window
= Foverlay_get (overlay
, Qwindow
);
3577 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3580 /* If the text ``under'' the overlay is invisible, both before-
3581 and after-strings from this overlay are visible; start and
3582 end position are indistinguishable. */
3583 invisible
= Foverlay_get (overlay
, Qinvisible
);
3584 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3586 /* If overlay has a non-empty before-string, record it. */
3587 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3588 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3590 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3592 /* If overlay has a non-empty after-string, record it. */
3593 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3594 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3596 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3599 /* Process overlays after the overlay center. */
3600 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3602 overlay
= XCAR (ov
);
3603 xassert (OVERLAYP (overlay
));
3604 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3605 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3607 if (start
> charpos
)
3610 /* Skip this overlay if it doesn't start or end at IT's current
3612 if (end
!= charpos
&& start
!= charpos
)
3615 /* Skip this overlay if it doesn't apply to IT->w. */
3616 window
= Foverlay_get (overlay
, Qwindow
);
3617 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3620 /* If the text ``under'' the overlay is invisible, it has a zero
3621 dimension, and both before- and after-strings apply. */
3622 invisible
= Foverlay_get (overlay
, Qinvisible
);
3623 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3625 /* If overlay has a non-empty before-string, record it. */
3626 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3627 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3629 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3631 /* If overlay has a non-empty after-string, record it. */
3632 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3633 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3635 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3638 #undef RECORD_OVERLAY_STRING
3642 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3644 /* Record the total number of strings to process. */
3645 it
->n_overlay_strings
= n
;
3647 /* IT->current.overlay_string_index is the number of overlay strings
3648 that have already been consumed by IT. Copy some of the
3649 remaining overlay strings to IT->overlay_strings. */
3651 j
= it
->current
.overlay_string_index
;
3652 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3653 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3659 /* Get the first chunk of overlay strings at IT's current buffer
3660 position, or at CHARPOS if that is > 0. Value is non-zero if at
3661 least one overlay string was found. */
3664 get_overlay_strings (it
, charpos
)
3668 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3669 process. This fills IT->overlay_strings with strings, and sets
3670 IT->n_overlay_strings to the total number of strings to process.
3671 IT->pos.overlay_string_index has to be set temporarily to zero
3672 because load_overlay_strings needs this; it must be set to -1
3673 when no overlay strings are found because a zero value would
3674 indicate a position in the first overlay string. */
3675 it
->current
.overlay_string_index
= 0;
3676 load_overlay_strings (it
, charpos
);
3678 /* If we found overlay strings, set up IT to deliver display
3679 elements from the first one. Otherwise set up IT to deliver
3680 from current_buffer. */
3681 if (it
->n_overlay_strings
)
3683 /* Make sure we know settings in current_buffer, so that we can
3684 restore meaningful values when we're done with the overlay
3686 compute_stop_pos (it
);
3687 xassert (it
->face_id
>= 0);
3689 /* Save IT's settings. They are restored after all overlay
3690 strings have been processed. */
3691 xassert (it
->sp
== 0);
3694 /* Set up IT to deliver display elements from the first overlay
3696 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3697 it
->string
= it
->overlay_strings
[0];
3698 it
->stop_charpos
= 0;
3699 xassert (STRINGP (it
->string
));
3700 it
->end_charpos
= SCHARS (it
->string
);
3701 it
->multibyte_p
= SMBP (it
->string
);
3702 it
->method
= next_element_from_string
;
3707 it
->current
.overlay_string_index
= -1;
3708 it
->method
= next_element_from_buffer
;
3713 /* Value is non-zero if we found at least one overlay string. */
3714 return STRINGP (it
->string
);
3719 /***********************************************************************
3720 Saving and restoring state
3721 ***********************************************************************/
3723 /* Save current settings of IT on IT->stack. Called, for example,
3724 before setting up IT for an overlay string, to be able to restore
3725 IT's settings to what they were after the overlay string has been
3732 struct iterator_stack_entry
*p
;
3734 xassert (it
->sp
< 2);
3735 p
= it
->stack
+ it
->sp
;
3737 p
->stop_charpos
= it
->stop_charpos
;
3738 xassert (it
->face_id
>= 0);
3739 p
->face_id
= it
->face_id
;
3740 p
->string
= it
->string
;
3741 p
->pos
= it
->current
;
3742 p
->end_charpos
= it
->end_charpos
;
3743 p
->string_nchars
= it
->string_nchars
;
3745 p
->multibyte_p
= it
->multibyte_p
;
3746 p
->space_width
= it
->space_width
;
3747 p
->font_height
= it
->font_height
;
3748 p
->voffset
= it
->voffset
;
3749 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3750 p
->display_ellipsis_p
= 0;
3755 /* Restore IT's settings from IT->stack. Called, for example, when no
3756 more overlay strings must be processed, and we return to delivering
3757 display elements from a buffer, or when the end of a string from a
3758 `display' property is reached and we return to delivering display
3759 elements from an overlay string, or from a buffer. */
3765 struct iterator_stack_entry
*p
;
3767 xassert (it
->sp
> 0);
3769 p
= it
->stack
+ it
->sp
;
3770 it
->stop_charpos
= p
->stop_charpos
;
3771 it
->face_id
= p
->face_id
;
3772 it
->string
= p
->string
;
3773 it
->current
= p
->pos
;
3774 it
->end_charpos
= p
->end_charpos
;
3775 it
->string_nchars
= p
->string_nchars
;
3777 it
->multibyte_p
= p
->multibyte_p
;
3778 it
->space_width
= p
->space_width
;
3779 it
->font_height
= p
->font_height
;
3780 it
->voffset
= p
->voffset
;
3781 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3786 /***********************************************************************
3788 ***********************************************************************/
3790 /* Set IT's current position to the previous line start. */
3793 back_to_previous_line_start (it
)
3796 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3797 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3801 /* Move IT to the next line start.
3803 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3804 we skipped over part of the text (as opposed to moving the iterator
3805 continuously over the text). Otherwise, don't change the value
3808 Newlines may come from buffer text, overlay strings, or strings
3809 displayed via the `display' property. That's the reason we can't
3810 simply use find_next_newline_no_quit.
3812 Note that this function may not skip over invisible text that is so
3813 because of text properties and immediately follows a newline. If
3814 it would, function reseat_at_next_visible_line_start, when called
3815 from set_iterator_to_next, would effectively make invisible
3816 characters following a newline part of the wrong glyph row, which
3817 leads to wrong cursor motion. */
3820 forward_to_next_line_start (it
, skipped_p
)
3824 int old_selective
, newline_found_p
, n
;
3825 const int MAX_NEWLINE_DISTANCE
= 500;
3827 /* If already on a newline, just consume it to avoid unintended
3828 skipping over invisible text below. */
3829 if (it
->what
== IT_CHARACTER
3831 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3833 set_iterator_to_next (it
, 0);
3838 /* Don't handle selective display in the following. It's (a)
3839 unnecessary because it's done by the caller, and (b) leads to an
3840 infinite recursion because next_element_from_ellipsis indirectly
3841 calls this function. */
3842 old_selective
= it
->selective
;
3845 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3846 from buffer text. */
3847 for (n
= newline_found_p
= 0;
3848 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3849 n
+= STRINGP (it
->string
) ? 0 : 1)
3851 if (!get_next_display_element (it
))
3853 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3854 set_iterator_to_next (it
, 0);
3857 /* If we didn't find a newline near enough, see if we can use a
3859 if (n
== MAX_NEWLINE_DISTANCE
)
3861 int start
= IT_CHARPOS (*it
);
3862 int limit
= find_next_newline_no_quit (start
, 1);
3865 xassert (!STRINGP (it
->string
));
3867 /* If there isn't any `display' property in sight, and no
3868 overlays, we can just use the position of the newline in
3870 if (it
->stop_charpos
>= limit
3871 || ((pos
= Fnext_single_property_change (make_number (start
),
3873 Qnil
, make_number (limit
)),
3875 && next_overlay_change (start
) == ZV
))
3877 IT_CHARPOS (*it
) = limit
;
3878 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3879 *skipped_p
= newline_found_p
= 1;
3883 while (get_next_display_element (it
)
3884 && !newline_found_p
)
3886 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3887 set_iterator_to_next (it
, 0);
3892 it
->selective
= old_selective
;
3893 return newline_found_p
;
3897 /* Set IT's current position to the previous visible line start. Skip
3898 invisible text that is so either due to text properties or due to
3899 selective display. Caution: this does not change IT->current_x and
3903 back_to_previous_visible_line_start (it
)
3908 /* Go back one newline if not on BEGV already. */
3909 if (IT_CHARPOS (*it
) > BEGV
)
3910 back_to_previous_line_start (it
);
3912 /* Move over lines that are invisible because of selective display
3913 or text properties. */
3914 while (IT_CHARPOS (*it
) > BEGV
3919 /* If selective > 0, then lines indented more than that values
3921 if (it
->selective
> 0
3922 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3923 (float) it
->selective
)) /* iftc */
3929 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3930 Qinvisible
, it
->window
);
3931 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3935 /* Back one more newline if the current one is invisible. */
3937 back_to_previous_line_start (it
);
3940 xassert (IT_CHARPOS (*it
) >= BEGV
);
3941 xassert (IT_CHARPOS (*it
) == BEGV
3942 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3947 /* Reseat iterator IT at the previous visible line start. Skip
3948 invisible text that is so either due to text properties or due to
3949 selective display. At the end, update IT's overlay information,
3950 face information etc. */
3953 reseat_at_previous_visible_line_start (it
)
3956 back_to_previous_visible_line_start (it
);
3957 reseat (it
, it
->current
.pos
, 1);
3962 /* Reseat iterator IT on the next visible line start in the current
3963 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3964 preceding the line start. Skip over invisible text that is so
3965 because of selective display. Compute faces, overlays etc at the
3966 new position. Note that this function does not skip over text that
3967 is invisible because of text properties. */
3970 reseat_at_next_visible_line_start (it
, on_newline_p
)
3974 int newline_found_p
, skipped_p
= 0;
3976 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3978 /* Skip over lines that are invisible because they are indented
3979 more than the value of IT->selective. */
3980 if (it
->selective
> 0)
3981 while (IT_CHARPOS (*it
) < ZV
3982 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3983 (float) it
->selective
)) /* iftc */
3985 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3986 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3989 /* Position on the newline if that's what's requested. */
3990 if (on_newline_p
&& newline_found_p
)
3992 if (STRINGP (it
->string
))
3994 if (IT_STRING_CHARPOS (*it
) > 0)
3996 --IT_STRING_CHARPOS (*it
);
3997 --IT_STRING_BYTEPOS (*it
);
4000 else if (IT_CHARPOS (*it
) > BEGV
)
4004 reseat (it
, it
->current
.pos
, 0);
4008 reseat (it
, it
->current
.pos
, 0);
4015 /***********************************************************************
4016 Changing an iterator's position
4017 ***********************************************************************/
4019 /* Change IT's current position to POS in current_buffer. If FORCE_P
4020 is non-zero, always check for text properties at the new position.
4021 Otherwise, text properties are only looked up if POS >=
4022 IT->check_charpos of a property. */
4025 reseat (it
, pos
, force_p
)
4027 struct text_pos pos
;
4030 int original_pos
= IT_CHARPOS (*it
);
4032 reseat_1 (it
, pos
, 0);
4034 /* Determine where to check text properties. Avoid doing it
4035 where possible because text property lookup is very expensive. */
4037 || CHARPOS (pos
) > it
->stop_charpos
4038 || CHARPOS (pos
) < original_pos
)
4045 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4046 IT->stop_pos to POS, also. */
4049 reseat_1 (it
, pos
, set_stop_p
)
4051 struct text_pos pos
;
4054 /* Don't call this function when scanning a C string. */
4055 xassert (it
->s
== NULL
);
4057 /* POS must be a reasonable value. */
4058 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4060 it
->current
.pos
= it
->position
= pos
;
4061 XSETBUFFER (it
->object
, current_buffer
);
4062 it
->end_charpos
= ZV
;
4064 it
->current
.dpvec_index
= -1;
4065 it
->current
.overlay_string_index
= -1;
4066 IT_STRING_CHARPOS (*it
) = -1;
4067 IT_STRING_BYTEPOS (*it
) = -1;
4069 it
->method
= next_element_from_buffer
;
4070 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4072 it
->face_before_selective_p
= 0;
4075 it
->stop_charpos
= CHARPOS (pos
);
4079 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4080 If S is non-null, it is a C string to iterate over. Otherwise,
4081 STRING gives a Lisp string to iterate over.
4083 If PRECISION > 0, don't return more then PRECISION number of
4084 characters from the string.
4086 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4087 characters have been returned. FIELD_WIDTH < 0 means an infinite
4090 MULTIBYTE = 0 means disable processing of multibyte characters,
4091 MULTIBYTE > 0 means enable it,
4092 MULTIBYTE < 0 means use IT->multibyte_p.
4094 IT must be initialized via a prior call to init_iterator before
4095 calling this function. */
4098 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4103 int precision
, field_width
, multibyte
;
4105 /* No region in strings. */
4106 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4108 /* No text property checks performed by default, but see below. */
4109 it
->stop_charpos
= -1;
4111 /* Set iterator position and end position. */
4112 bzero (&it
->current
, sizeof it
->current
);
4113 it
->current
.overlay_string_index
= -1;
4114 it
->current
.dpvec_index
= -1;
4115 xassert (charpos
>= 0);
4117 /* If STRING is specified, use its multibyteness, otherwise use the
4118 setting of MULTIBYTE, if specified. */
4120 it
->multibyte_p
= multibyte
> 0;
4124 xassert (STRINGP (string
));
4125 it
->string
= string
;
4127 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4128 it
->method
= next_element_from_string
;
4129 it
->current
.string_pos
= string_pos (charpos
, string
);
4136 /* Note that we use IT->current.pos, not it->current.string_pos,
4137 for displaying C strings. */
4138 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4139 if (it
->multibyte_p
)
4141 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4142 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4146 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4147 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4150 it
->method
= next_element_from_c_string
;
4153 /* PRECISION > 0 means don't return more than PRECISION characters
4155 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4156 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4158 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4159 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4160 FIELD_WIDTH < 0 means infinite field width. This is useful for
4161 padding with `-' at the end of a mode line. */
4162 if (field_width
< 0)
4163 field_width
= INFINITY
;
4164 if (field_width
> it
->end_charpos
- charpos
)
4165 it
->end_charpos
= charpos
+ field_width
;
4167 /* Use the standard display table for displaying strings. */
4168 if (DISP_TABLE_P (Vstandard_display_table
))
4169 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4171 it
->stop_charpos
= charpos
;
4177 /***********************************************************************
4179 ***********************************************************************/
4181 /* Load IT's display element fields with information about the next
4182 display element from the current position of IT. Value is zero if
4183 end of buffer (or C string) is reached. */
4186 get_next_display_element (it
)
4189 /* Non-zero means that we found an display element. Zero means that
4190 we hit the end of what we iterate over. Performance note: the
4191 function pointer `method' used here turns out to be faster than
4192 using a sequence of if-statements. */
4193 int success_p
= (*it
->method
) (it
);
4195 if (it
->what
== IT_CHARACTER
)
4197 /* Map via display table or translate control characters.
4198 IT->c, IT->len etc. have been set to the next character by
4199 the function call above. If we have a display table, and it
4200 contains an entry for IT->c, translate it. Don't do this if
4201 IT->c itself comes from a display table, otherwise we could
4202 end up in an infinite recursion. (An alternative could be to
4203 count the recursion depth of this function and signal an
4204 error when a certain maximum depth is reached.) Is it worth
4206 if (success_p
&& it
->dpvec
== NULL
)
4211 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4214 struct Lisp_Vector
*v
= XVECTOR (dv
);
4216 /* Return the first character from the display table
4217 entry, if not empty. If empty, don't display the
4218 current character. */
4221 it
->dpvec_char_len
= it
->len
;
4222 it
->dpvec
= v
->contents
;
4223 it
->dpend
= v
->contents
+ v
->size
;
4224 it
->current
.dpvec_index
= 0;
4225 it
->method
= next_element_from_display_vector
;
4226 success_p
= get_next_display_element (it
);
4230 set_iterator_to_next (it
, 0);
4231 success_p
= get_next_display_element (it
);
4235 /* Translate control characters into `\003' or `^C' form.
4236 Control characters coming from a display table entry are
4237 currently not translated because we use IT->dpvec to hold
4238 the translation. This could easily be changed but I
4239 don't believe that it is worth doing.
4241 Non-printable multibyte characters are also translated
4243 else if ((it
->c
< ' '
4244 && (it
->area
!= TEXT_AREA
4245 || (it
->c
!= '\n' && it
->c
!= '\t')))
4248 || !CHAR_PRINTABLE_P (it
->c
))
4250 /* IT->c is a control character which must be displayed
4251 either as '\003' or as `^C' where the '\\' and '^'
4252 can be defined in the display table. Fill
4253 IT->ctl_chars with glyphs for what we have to
4254 display. Then, set IT->dpvec to these glyphs. */
4257 if (it
->c
< 128 && it
->ctl_arrow_p
)
4259 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4261 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4262 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4263 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4265 g
= FAST_MAKE_GLYPH ('^', 0);
4266 XSETINT (it
->ctl_chars
[0], g
);
4268 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4269 XSETINT (it
->ctl_chars
[1], g
);
4271 /* Set up IT->dpvec and return first character from it. */
4272 it
->dpvec_char_len
= it
->len
;
4273 it
->dpvec
= it
->ctl_chars
;
4274 it
->dpend
= it
->dpvec
+ 2;
4275 it
->current
.dpvec_index
= 0;
4276 it
->method
= next_element_from_display_vector
;
4277 get_next_display_element (it
);
4281 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4286 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4288 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4289 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4290 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4292 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4294 if (SINGLE_BYTE_CHAR_P (it
->c
))
4295 str
[0] = it
->c
, len
= 1;
4298 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4301 /* It's an invalid character, which
4302 shouldn't happen actually, but due to
4303 bugs it may happen. Let's print the char
4304 as is, there's not much meaningful we can
4307 str
[1] = it
->c
>> 8;
4308 str
[2] = it
->c
>> 16;
4309 str
[3] = it
->c
>> 24;
4314 for (i
= 0; i
< len
; i
++)
4316 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4317 /* Insert three more glyphs into IT->ctl_chars for
4318 the octal display of the character. */
4319 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4320 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4321 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4322 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4323 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4324 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4327 /* Set up IT->dpvec and return the first character
4329 it
->dpvec_char_len
= it
->len
;
4330 it
->dpvec
= it
->ctl_chars
;
4331 it
->dpend
= it
->dpvec
+ len
* 4;
4332 it
->current
.dpvec_index
= 0;
4333 it
->method
= next_element_from_display_vector
;
4334 get_next_display_element (it
);
4339 /* Adjust face id for a multibyte character. There are no
4340 multibyte character in unibyte text. */
4343 && FRAME_WINDOW_P (it
->f
))
4345 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4346 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4350 /* Is this character the last one of a run of characters with
4351 box? If yes, set IT->end_of_box_run_p to 1. */
4358 it
->end_of_box_run_p
4359 = ((face_id
= face_after_it_pos (it
),
4360 face_id
!= it
->face_id
)
4361 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4362 face
->box
== FACE_NO_BOX
));
4365 /* Value is 0 if end of buffer or string reached. */
4370 /* Move IT to the next display element.
4372 RESEAT_P non-zero means if called on a newline in buffer text,
4373 skip to the next visible line start.
4375 Functions get_next_display_element and set_iterator_to_next are
4376 separate because I find this arrangement easier to handle than a
4377 get_next_display_element function that also increments IT's
4378 position. The way it is we can first look at an iterator's current
4379 display element, decide whether it fits on a line, and if it does,
4380 increment the iterator position. The other way around we probably
4381 would either need a flag indicating whether the iterator has to be
4382 incremented the next time, or we would have to implement a
4383 decrement position function which would not be easy to write. */
4386 set_iterator_to_next (it
, reseat_p
)
4390 /* Reset flags indicating start and end of a sequence of characters
4391 with box. Reset them at the start of this function because
4392 moving the iterator to a new position might set them. */
4393 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4395 if (it
->method
== next_element_from_buffer
)
4397 /* The current display element of IT is a character from
4398 current_buffer. Advance in the buffer, and maybe skip over
4399 invisible lines that are so because of selective display. */
4400 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4401 reseat_at_next_visible_line_start (it
, 0);
4404 xassert (it
->len
!= 0);
4405 IT_BYTEPOS (*it
) += it
->len
;
4406 IT_CHARPOS (*it
) += 1;
4407 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4410 else if (it
->method
== next_element_from_composition
)
4412 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4413 if (STRINGP (it
->string
))
4415 IT_STRING_BYTEPOS (*it
) += it
->len
;
4416 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4417 it
->method
= next_element_from_string
;
4418 goto consider_string_end
;
4422 IT_BYTEPOS (*it
) += it
->len
;
4423 IT_CHARPOS (*it
) += it
->cmp_len
;
4424 it
->method
= next_element_from_buffer
;
4427 else if (it
->method
== next_element_from_c_string
)
4429 /* Current display element of IT is from a C string. */
4430 IT_BYTEPOS (*it
) += it
->len
;
4431 IT_CHARPOS (*it
) += 1;
4433 else if (it
->method
== next_element_from_display_vector
)
4435 /* Current display element of IT is from a display table entry.
4436 Advance in the display table definition. Reset it to null if
4437 end reached, and continue with characters from buffers/
4439 ++it
->current
.dpvec_index
;
4441 /* Restore face of the iterator to what they were before the
4442 display vector entry (these entries may contain faces). */
4443 it
->face_id
= it
->saved_face_id
;
4445 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4448 it
->method
= next_element_from_c_string
;
4449 else if (STRINGP (it
->string
))
4450 it
->method
= next_element_from_string
;
4452 it
->method
= next_element_from_buffer
;
4455 it
->current
.dpvec_index
= -1;
4457 /* Skip over characters which were displayed via IT->dpvec. */
4458 if (it
->dpvec_char_len
< 0)
4459 reseat_at_next_visible_line_start (it
, 1);
4460 else if (it
->dpvec_char_len
> 0)
4462 it
->len
= it
->dpvec_char_len
;
4463 set_iterator_to_next (it
, reseat_p
);
4467 else if (it
->method
== next_element_from_string
)
4469 /* Current display element is a character from a Lisp string. */
4470 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4471 IT_STRING_BYTEPOS (*it
) += it
->len
;
4472 IT_STRING_CHARPOS (*it
) += 1;
4474 consider_string_end
:
4476 if (it
->current
.overlay_string_index
>= 0)
4478 /* IT->string is an overlay string. Advance to the
4479 next, if there is one. */
4480 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4481 next_overlay_string (it
);
4485 /* IT->string is not an overlay string. If we reached
4486 its end, and there is something on IT->stack, proceed
4487 with what is on the stack. This can be either another
4488 string, this time an overlay string, or a buffer. */
4489 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4493 if (!STRINGP (it
->string
))
4494 it
->method
= next_element_from_buffer
;
4496 goto consider_string_end
;
4500 else if (it
->method
== next_element_from_image
4501 || it
->method
== next_element_from_stretch
)
4503 /* The position etc with which we have to proceed are on
4504 the stack. The position may be at the end of a string,
4505 if the `display' property takes up the whole string. */
4508 if (STRINGP (it
->string
))
4510 it
->method
= next_element_from_string
;
4511 goto consider_string_end
;
4514 it
->method
= next_element_from_buffer
;
4517 /* There are no other methods defined, so this should be a bug. */
4520 xassert (it
->method
!= next_element_from_string
4521 || (STRINGP (it
->string
)
4522 && IT_STRING_CHARPOS (*it
) >= 0));
4526 /* Load IT's display element fields with information about the next
4527 display element which comes from a display table entry or from the
4528 result of translating a control character to one of the forms `^C'
4529 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4532 next_element_from_display_vector (it
)
4536 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4538 /* Remember the current face id in case glyphs specify faces.
4539 IT's face is restored in set_iterator_to_next. */
4540 it
->saved_face_id
= it
->face_id
;
4542 if (INTEGERP (*it
->dpvec
)
4543 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4548 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4549 it
->c
= FAST_GLYPH_CHAR (g
);
4550 it
->len
= CHAR_BYTES (it
->c
);
4552 /* The entry may contain a face id to use. Such a face id is
4553 the id of a Lisp face, not a realized face. A face id of
4554 zero means no face is specified. */
4555 lface_id
= FAST_GLYPH_FACE (g
);
4558 /* The function returns -1 if lface_id is invalid. */
4559 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4561 it
->face_id
= face_id
;
4565 /* Display table entry is invalid. Return a space. */
4566 it
->c
= ' ', it
->len
= 1;
4568 /* Don't change position and object of the iterator here. They are
4569 still the values of the character that had this display table
4570 entry or was translated, and that's what we want. */
4571 it
->what
= IT_CHARACTER
;
4576 /* Load IT with the next display element from Lisp string IT->string.
4577 IT->current.string_pos is the current position within the string.
4578 If IT->current.overlay_string_index >= 0, the Lisp string is an
4582 next_element_from_string (it
)
4585 struct text_pos position
;
4587 xassert (STRINGP (it
->string
));
4588 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4589 position
= it
->current
.string_pos
;
4591 /* Time to check for invisible text? */
4592 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4593 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4597 /* Since a handler may have changed IT->method, we must
4599 return get_next_display_element (it
);
4602 if (it
->current
.overlay_string_index
>= 0)
4604 /* Get the next character from an overlay string. In overlay
4605 strings, There is no field width or padding with spaces to
4607 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4612 else if (STRING_MULTIBYTE (it
->string
))
4614 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4615 unsigned char *s
= SDATA (it
->string
) + IT_STRING_BYTEPOS (*it
);
4616 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4620 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4626 /* Get the next character from a Lisp string that is not an
4627 overlay string. Such strings come from the mode line, for
4628 example. We may have to pad with spaces, or truncate the
4629 string. See also next_element_from_c_string. */
4630 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4635 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4637 /* Pad with spaces. */
4638 it
->c
= ' ', it
->len
= 1;
4639 CHARPOS (position
) = BYTEPOS (position
) = -1;
4641 else if (STRING_MULTIBYTE (it
->string
))
4643 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4644 unsigned char *s
= SDATA (it
->string
) + IT_STRING_BYTEPOS (*it
);
4645 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4649 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4654 /* Record what we have and where it came from. Note that we store a
4655 buffer position in IT->position although it could arguably be a
4657 it
->what
= IT_CHARACTER
;
4658 it
->object
= it
->string
;
4659 it
->position
= position
;
4664 /* Load IT with next display element from C string IT->s.
4665 IT->string_nchars is the maximum number of characters to return
4666 from the string. IT->end_charpos may be greater than
4667 IT->string_nchars when this function is called, in which case we
4668 may have to return padding spaces. Value is zero if end of string
4669 reached, including padding spaces. */
4672 next_element_from_c_string (it
)
4678 it
->what
= IT_CHARACTER
;
4679 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4682 /* IT's position can be greater IT->string_nchars in case a field
4683 width or precision has been specified when the iterator was
4685 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4687 /* End of the game. */
4691 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4693 /* Pad with spaces. */
4694 it
->c
= ' ', it
->len
= 1;
4695 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4697 else if (it
->multibyte_p
)
4699 /* Implementation note: The calls to strlen apparently aren't a
4700 performance problem because there is no noticeable performance
4701 difference between Emacs running in unibyte or multibyte mode. */
4702 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4703 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4707 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4713 /* Set up IT to return characters from an ellipsis, if appropriate.
4714 The definition of the ellipsis glyphs may come from a display table
4715 entry. This function Fills IT with the first glyph from the
4716 ellipsis if an ellipsis is to be displayed. */
4719 next_element_from_ellipsis (it
)
4722 if (it
->selective_display_ellipsis_p
)
4724 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4726 /* Use the display table definition for `...'. Invalid glyphs
4727 will be handled by the method returning elements from dpvec. */
4728 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4729 it
->dpvec_char_len
= it
->len
;
4730 it
->dpvec
= v
->contents
;
4731 it
->dpend
= v
->contents
+ v
->size
;
4732 it
->current
.dpvec_index
= 0;
4733 it
->method
= next_element_from_display_vector
;
4737 /* Use default `...' which is stored in default_invis_vector. */
4738 it
->dpvec_char_len
= it
->len
;
4739 it
->dpvec
= default_invis_vector
;
4740 it
->dpend
= default_invis_vector
+ 3;
4741 it
->current
.dpvec_index
= 0;
4742 it
->method
= next_element_from_display_vector
;
4747 /* The face at the current position may be different from the
4748 face we find after the invisible text. Remember what it
4749 was in IT->saved_face_id, and signal that it's there by
4750 setting face_before_selective_p. */
4751 it
->saved_face_id
= it
->face_id
;
4752 it
->method
= next_element_from_buffer
;
4753 reseat_at_next_visible_line_start (it
, 1);
4754 it
->face_before_selective_p
= 1;
4757 return get_next_display_element (it
);
4761 /* Deliver an image display element. The iterator IT is already
4762 filled with image information (done in handle_display_prop). Value
4767 next_element_from_image (it
)
4770 it
->what
= IT_IMAGE
;
4775 /* Fill iterator IT with next display element from a stretch glyph
4776 property. IT->object is the value of the text property. Value is
4780 next_element_from_stretch (it
)
4783 it
->what
= IT_STRETCH
;
4788 /* Load IT with the next display element from current_buffer. Value
4789 is zero if end of buffer reached. IT->stop_charpos is the next
4790 position at which to stop and check for text properties or buffer
4794 next_element_from_buffer (it
)
4799 /* Check this assumption, otherwise, we would never enter the
4800 if-statement, below. */
4801 xassert (IT_CHARPOS (*it
) >= BEGV
4802 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4804 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4806 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4808 int overlay_strings_follow_p
;
4810 /* End of the game, except when overlay strings follow that
4811 haven't been returned yet. */
4812 if (it
->overlay_strings_at_end_processed_p
)
4813 overlay_strings_follow_p
= 0;
4816 it
->overlay_strings_at_end_processed_p
= 1;
4817 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4820 if (overlay_strings_follow_p
)
4821 success_p
= get_next_display_element (it
);
4825 it
->position
= it
->current
.pos
;
4832 return get_next_display_element (it
);
4837 /* No face changes, overlays etc. in sight, so just return a
4838 character from current_buffer. */
4841 /* Maybe run the redisplay end trigger hook. Performance note:
4842 This doesn't seem to cost measurable time. */
4843 if (it
->redisplay_end_trigger_charpos
4845 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4846 run_redisplay_end_trigger_hook (it
);
4848 /* Get the next character, maybe multibyte. */
4849 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4850 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4852 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4853 - IT_BYTEPOS (*it
));
4854 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4857 it
->c
= *p
, it
->len
= 1;
4859 /* Record what we have and where it came from. */
4860 it
->what
= IT_CHARACTER
;;
4861 it
->object
= it
->w
->buffer
;
4862 it
->position
= it
->current
.pos
;
4864 /* Normally we return the character found above, except when we
4865 really want to return an ellipsis for selective display. */
4870 /* A value of selective > 0 means hide lines indented more
4871 than that number of columns. */
4872 if (it
->selective
> 0
4873 && IT_CHARPOS (*it
) + 1 < ZV
4874 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4875 IT_BYTEPOS (*it
) + 1,
4876 (float) it
->selective
)) /* iftc */
4878 success_p
= next_element_from_ellipsis (it
);
4879 it
->dpvec_char_len
= -1;
4882 else if (it
->c
== '\r' && it
->selective
== -1)
4884 /* A value of selective == -1 means that everything from the
4885 CR to the end of the line is invisible, with maybe an
4886 ellipsis displayed for it. */
4887 success_p
= next_element_from_ellipsis (it
);
4888 it
->dpvec_char_len
= -1;
4893 /* Value is zero if end of buffer reached. */
4894 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4899 /* Run the redisplay end trigger hook for IT. */
4902 run_redisplay_end_trigger_hook (it
)
4905 Lisp_Object args
[3];
4907 /* IT->glyph_row should be non-null, i.e. we should be actually
4908 displaying something, or otherwise we should not run the hook. */
4909 xassert (it
->glyph_row
);
4911 /* Set up hook arguments. */
4912 args
[0] = Qredisplay_end_trigger_functions
;
4913 args
[1] = it
->window
;
4914 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4915 it
->redisplay_end_trigger_charpos
= 0;
4917 /* Since we are *trying* to run these functions, don't try to run
4918 them again, even if they get an error. */
4919 it
->w
->redisplay_end_trigger
= Qnil
;
4920 Frun_hook_with_args (3, args
);
4922 /* Notice if it changed the face of the character we are on. */
4923 handle_face_prop (it
);
4927 /* Deliver a composition display element. The iterator IT is already
4928 filled with composition information (done in
4929 handle_composition_prop). Value is always 1. */
4932 next_element_from_composition (it
)
4935 it
->what
= IT_COMPOSITION
;
4936 it
->position
= (STRINGP (it
->string
)
4937 ? it
->current
.string_pos
4944 /***********************************************************************
4945 Moving an iterator without producing glyphs
4946 ***********************************************************************/
4948 /* Move iterator IT to a specified buffer or X position within one
4949 line on the display without producing glyphs.
4951 OP should be a bit mask including some or all of these bits:
4952 MOVE_TO_X: Stop on reaching x-position TO_X.
4953 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
4954 Regardless of OP's value, stop in reaching the end of the display line.
4956 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
4957 This means, in particular, that TO_X includes window's horizontal
4960 The return value has several possible values that
4961 say what condition caused the scan to stop:
4963 MOVE_POS_MATCH_OR_ZV
4964 - when TO_POS or ZV was reached.
4967 -when TO_X was reached before TO_POS or ZV were reached.
4970 - when we reached the end of the display area and the line must
4974 - when we reached the end of the display area and the line is
4978 - when we stopped at a line end, i.e. a newline or a CR and selective
4981 static enum move_it_result
4982 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4984 int to_charpos
, to_x
, op
;
4986 enum move_it_result result
= MOVE_UNDEFINED
;
4987 struct glyph_row
*saved_glyph_row
;
4989 /* Don't produce glyphs in produce_glyphs. */
4990 saved_glyph_row
= it
->glyph_row
;
4991 it
->glyph_row
= NULL
;
4995 int x
, i
, ascent
= 0, descent
= 0;
4997 /* Stop when ZV or TO_CHARPOS reached. */
4998 if (!get_next_display_element (it
)
4999 || ((op
& MOVE_TO_POS
) != 0
5000 && BUFFERP (it
->object
)
5001 && IT_CHARPOS (*it
) >= to_charpos
))
5003 result
= MOVE_POS_MATCH_OR_ZV
;
5007 /* The call to produce_glyphs will get the metrics of the
5008 display element IT is loaded with. We record in x the
5009 x-position before this display element in case it does not
5013 /* Remember the line height so far in case the next element doesn't
5015 if (!it
->truncate_lines_p
)
5017 ascent
= it
->max_ascent
;
5018 descent
= it
->max_descent
;
5021 PRODUCE_GLYPHS (it
);
5023 if (it
->area
!= TEXT_AREA
)
5025 set_iterator_to_next (it
, 1);
5029 /* The number of glyphs we get back in IT->nglyphs will normally
5030 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5031 character on a terminal frame, or (iii) a line end. For the
5032 second case, IT->nglyphs - 1 padding glyphs will be present
5033 (on X frames, there is only one glyph produced for a
5034 composite character.
5036 The behavior implemented below means, for continuation lines,
5037 that as many spaces of a TAB as fit on the current line are
5038 displayed there. For terminal frames, as many glyphs of a
5039 multi-glyph character are displayed in the current line, too.
5040 This is what the old redisplay code did, and we keep it that
5041 way. Under X, the whole shape of a complex character must
5042 fit on the line or it will be completely displayed in the
5045 Note that both for tabs and padding glyphs, all glyphs have
5049 /* More than one glyph or glyph doesn't fit on line. All
5050 glyphs have the same width. */
5051 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5054 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5056 new_x
= x
+ single_glyph_width
;
5058 /* We want to leave anything reaching TO_X to the caller. */
5059 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5062 result
= MOVE_X_REACHED
;
5065 else if (/* Lines are continued. */
5066 !it
->truncate_lines_p
5067 && (/* And glyph doesn't fit on the line. */
5068 new_x
> it
->last_visible_x
5069 /* Or it fits exactly and we're on a window
5071 || (new_x
== it
->last_visible_x
5072 && FRAME_WINDOW_P (it
->f
))))
5074 if (/* IT->hpos == 0 means the very first glyph
5075 doesn't fit on the line, e.g. a wide image. */
5077 || (new_x
== it
->last_visible_x
5078 && FRAME_WINDOW_P (it
->f
)))
5081 it
->current_x
= new_x
;
5082 if (i
== it
->nglyphs
- 1)
5083 set_iterator_to_next (it
, 1);
5088 it
->max_ascent
= ascent
;
5089 it
->max_descent
= descent
;
5092 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5094 result
= MOVE_LINE_CONTINUED
;
5097 else if (new_x
> it
->first_visible_x
)
5099 /* Glyph is visible. Increment number of glyphs that
5100 would be displayed. */
5105 /* Glyph is completely off the left margin of the display
5106 area. Nothing to do. */
5110 if (result
!= MOVE_UNDEFINED
)
5113 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5115 /* Stop when TO_X specified and reached. This check is
5116 necessary here because of lines consisting of a line end,
5117 only. The line end will not produce any glyphs and we
5118 would never get MOVE_X_REACHED. */
5119 xassert (it
->nglyphs
== 0);
5120 result
= MOVE_X_REACHED
;
5124 /* Is this a line end? If yes, we're done. */
5125 if (ITERATOR_AT_END_OF_LINE_P (it
))
5127 result
= MOVE_NEWLINE_OR_CR
;
5131 /* The current display element has been consumed. Advance
5133 set_iterator_to_next (it
, 1);
5135 /* Stop if lines are truncated and IT's current x-position is
5136 past the right edge of the window now. */
5137 if (it
->truncate_lines_p
5138 && it
->current_x
>= it
->last_visible_x
)
5140 result
= MOVE_LINE_TRUNCATED
;
5145 /* Restore the iterator settings altered at the beginning of this
5147 it
->glyph_row
= saved_glyph_row
;
5152 /* Move IT forward until it satisfies one or more of the criteria in
5153 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5155 OP is a bit-mask that specifies where to stop, and in particular,
5156 which of those four position arguments makes a difference. See the
5157 description of enum move_operation_enum.
5159 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5160 screen line, this function will set IT to the next position >
5164 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5166 int to_charpos
, to_x
, to_y
, to_vpos
;
5169 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5175 if (op
& MOVE_TO_VPOS
)
5177 /* If no TO_CHARPOS and no TO_X specified, stop at the
5178 start of the line TO_VPOS. */
5179 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5181 if (it
->vpos
== to_vpos
)
5187 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5191 /* TO_VPOS >= 0 means stop at TO_X in the line at
5192 TO_VPOS, or at TO_POS, whichever comes first. */
5193 if (it
->vpos
== to_vpos
)
5199 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5201 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5206 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5208 /* We have reached TO_X but not in the line we want. */
5209 skip
= move_it_in_display_line_to (it
, to_charpos
,
5211 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5219 else if (op
& MOVE_TO_Y
)
5221 struct it it_backup
;
5223 /* TO_Y specified means stop at TO_X in the line containing
5224 TO_Y---or at TO_CHARPOS if this is reached first. The
5225 problem is that we can't really tell whether the line
5226 contains TO_Y before we have completely scanned it, and
5227 this may skip past TO_X. What we do is to first scan to
5230 If TO_X is not specified, use a TO_X of zero. The reason
5231 is to make the outcome of this function more predictable.
5232 If we didn't use TO_X == 0, we would stop at the end of
5233 the line which is probably not what a caller would expect
5235 skip
= move_it_in_display_line_to (it
, to_charpos
,
5239 | (op
& MOVE_TO_POS
)));
5241 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5242 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5248 /* If TO_X was reached, we would like to know whether TO_Y
5249 is in the line. This can only be said if we know the
5250 total line height which requires us to scan the rest of
5252 if (skip
== MOVE_X_REACHED
)
5255 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5256 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5258 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5261 /* Now, decide whether TO_Y is in this line. */
5262 line_height
= it
->max_ascent
+ it
->max_descent
;
5263 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5265 if (to_y
>= it
->current_y
5266 && to_y
< it
->current_y
+ line_height
)
5268 if (skip
== MOVE_X_REACHED
)
5269 /* If TO_Y is in this line and TO_X was reached above,
5270 we scanned too far. We have to restore IT's settings
5271 to the ones before skipping. */
5275 else if (skip
== MOVE_X_REACHED
)
5278 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5286 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5290 case MOVE_POS_MATCH_OR_ZV
:
5294 case MOVE_NEWLINE_OR_CR
:
5295 set_iterator_to_next (it
, 1);
5296 it
->continuation_lines_width
= 0;
5299 case MOVE_LINE_TRUNCATED
:
5300 it
->continuation_lines_width
= 0;
5301 reseat_at_next_visible_line_start (it
, 0);
5302 if ((op
& MOVE_TO_POS
) != 0
5303 && IT_CHARPOS (*it
) > to_charpos
)
5310 case MOVE_LINE_CONTINUED
:
5311 it
->continuation_lines_width
+= it
->current_x
;
5318 /* Reset/increment for the next run. */
5319 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5320 it
->current_x
= it
->hpos
= 0;
5321 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5323 last_height
= it
->max_ascent
+ it
->max_descent
;
5324 last_max_ascent
= it
->max_ascent
;
5325 it
->max_ascent
= it
->max_descent
= 0;
5330 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5334 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5336 If DY > 0, move IT backward at least that many pixels. DY = 0
5337 means move IT backward to the preceding line start or BEGV. This
5338 function may move over more than DY pixels if IT->current_y - DY
5339 ends up in the middle of a line; in this case IT->current_y will be
5340 set to the top of the line moved to. */
5343 move_it_vertically_backward (it
, dy
)
5349 int start_pos
= IT_CHARPOS (*it
);
5353 /* Estimate how many newlines we must move back. */
5354 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5356 /* Set the iterator's position that many lines back. */
5357 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5358 back_to_previous_visible_line_start (it
);
5360 /* Reseat the iterator here. When moving backward, we don't want
5361 reseat to skip forward over invisible text, set up the iterator
5362 to deliver from overlay strings at the new position etc. So,
5363 use reseat_1 here. */
5364 reseat_1 (it
, it
->current
.pos
, 1);
5366 /* We are now surely at a line start. */
5367 it
->current_x
= it
->hpos
= 0;
5369 /* Move forward and see what y-distance we moved. First move to the
5370 start of the next line so that we get its height. We need this
5371 height to be able to tell whether we reached the specified
5374 it2
.max_ascent
= it2
.max_descent
= 0;
5375 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5376 MOVE_TO_POS
| MOVE_TO_VPOS
);
5377 xassert (IT_CHARPOS (*it
) >= BEGV
);
5380 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5381 xassert (IT_CHARPOS (*it
) >= BEGV
);
5382 h
= it2
.current_y
- it
->current_y
;
5383 nlines
= it2
.vpos
- it
->vpos
;
5385 /* Correct IT's y and vpos position. */
5391 /* DY == 0 means move to the start of the screen line. The
5392 value of nlines is > 0 if continuation lines were involved. */
5394 move_it_by_lines (it
, nlines
, 1);
5395 xassert (IT_CHARPOS (*it
) <= start_pos
);
5399 /* The y-position we try to reach. Note that h has been
5400 subtracted in front of the if-statement. */
5401 int target_y
= it
->current_y
+ h
- dy
;
5402 int y0
= it3
.current_y
;
5403 int y1
= line_bottom_y (&it3
);
5404 int line_height
= y1
- y0
;
5406 /* If we did not reach target_y, try to move further backward if
5407 we can. If we moved too far backward, try to move forward. */
5408 if (target_y
< it
->current_y
5409 /* This is heuristic. In a window that's 3 lines high, with
5410 a line height of 13 pixels each, recentering with point
5411 on the bottom line will try to move -39/2 = 19 pixels
5412 backward. Try to avoid moving into the first line. */
5413 && it
->current_y
- target_y
> line_height
/ 3 * 2
5414 && IT_CHARPOS (*it
) > BEGV
)
5416 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5417 target_y
- it
->current_y
));
5418 move_it_vertically (it
, target_y
- it
->current_y
);
5419 xassert (IT_CHARPOS (*it
) >= BEGV
);
5421 else if (target_y
>= it
->current_y
+ line_height
5422 && IT_CHARPOS (*it
) < ZV
)
5424 /* Should move forward by at least one line, maybe more.
5426 Note: Calling move_it_by_lines can be expensive on
5427 terminal frames, where compute_motion is used (via
5428 vmotion) to do the job, when there are very long lines
5429 and truncate-lines is nil. That's the reason for
5430 treating terminal frames specially here. */
5432 if (!FRAME_WINDOW_P (it
->f
))
5433 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5438 move_it_by_lines (it
, 1, 1);
5440 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5443 xassert (IT_CHARPOS (*it
) >= BEGV
);
5449 /* Move IT by a specified amount of pixel lines DY. DY negative means
5450 move backwards. DY = 0 means move to start of screen line. At the
5451 end, IT will be on the start of a screen line. */
5454 move_it_vertically (it
, dy
)
5459 move_it_vertically_backward (it
, -dy
);
5462 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5463 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5464 MOVE_TO_POS
| MOVE_TO_Y
);
5465 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5467 /* If buffer ends in ZV without a newline, move to the start of
5468 the line to satisfy the post-condition. */
5469 if (IT_CHARPOS (*it
) == ZV
5470 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5471 move_it_by_lines (it
, 0, 0);
5476 /* Move iterator IT past the end of the text line it is in. */
5479 move_it_past_eol (it
)
5482 enum move_it_result rc
;
5484 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5485 if (rc
== MOVE_NEWLINE_OR_CR
)
5486 set_iterator_to_next (it
, 0);
5490 #if 0 /* Currently not used. */
5492 /* Return non-zero if some text between buffer positions START_CHARPOS
5493 and END_CHARPOS is invisible. IT->window is the window for text
5497 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5499 int start_charpos
, end_charpos
;
5501 Lisp_Object prop
, limit
;
5502 int invisible_found_p
;
5504 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5506 /* Is text at START invisible? */
5507 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5509 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5510 invisible_found_p
= 1;
5513 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5515 make_number (end_charpos
));
5516 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5519 return invisible_found_p
;
5525 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5526 negative means move up. DVPOS == 0 means move to the start of the
5527 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5528 NEED_Y_P is zero, IT->current_y will be left unchanged.
5530 Further optimization ideas: If we would know that IT->f doesn't use
5531 a face with proportional font, we could be faster for
5532 truncate-lines nil. */
5535 move_it_by_lines (it
, dvpos
, need_y_p
)
5537 int dvpos
, need_y_p
;
5539 struct position pos
;
5541 if (!FRAME_WINDOW_P (it
->f
))
5543 struct text_pos textpos
;
5545 /* We can use vmotion on frames without proportional fonts. */
5546 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5547 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5548 reseat (it
, textpos
, 1);
5549 it
->vpos
+= pos
.vpos
;
5550 it
->current_y
+= pos
.vpos
;
5552 else if (dvpos
== 0)
5554 /* DVPOS == 0 means move to the start of the screen line. */
5555 move_it_vertically_backward (it
, 0);
5556 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5559 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5563 int start_charpos
, i
;
5565 /* Start at the beginning of the screen line containing IT's
5567 move_it_vertically_backward (it
, 0);
5569 /* Go back -DVPOS visible lines and reseat the iterator there. */
5570 start_charpos
= IT_CHARPOS (*it
);
5571 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5572 back_to_previous_visible_line_start (it
);
5573 reseat (it
, it
->current
.pos
, 1);
5574 it
->current_x
= it
->hpos
= 0;
5576 /* Above call may have moved too far if continuation lines
5577 are involved. Scan forward and see if it did. */
5579 it2
.vpos
= it2
.current_y
= 0;
5580 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5581 it
->vpos
-= it2
.vpos
;
5582 it
->current_y
-= it2
.current_y
;
5583 it
->current_x
= it
->hpos
= 0;
5585 /* If we moved too far, move IT some lines forward. */
5586 if (it2
.vpos
> -dvpos
)
5588 int delta
= it2
.vpos
+ dvpos
;
5589 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5596 /***********************************************************************
5598 ***********************************************************************/
5601 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5605 add_to_log (format
, arg1
, arg2
)
5607 Lisp_Object arg1
, arg2
;
5609 Lisp_Object args
[3];
5610 Lisp_Object msg
, fmt
;
5613 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5615 /* Do nothing if called asynchronously. Inserting text into
5616 a buffer may call after-change-functions and alike and
5617 that would means running Lisp asynchronously. */
5618 if (handling_signal
)
5622 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5624 args
[0] = fmt
= build_string (format
);
5627 msg
= Fformat (3, args
);
5629 len
= SBYTES (msg
) + 1;
5630 buffer
= (char *) alloca (len
);
5631 bcopy (SDATA (msg
), buffer
, len
);
5633 message_dolog (buffer
, len
- 1, 1, 0);
5638 /* Output a newline in the *Messages* buffer if "needs" one. */
5641 message_log_maybe_newline ()
5643 if (message_log_need_newline
)
5644 message_dolog ("", 0, 1, 0);
5648 /* Add a string M of length NBYTES to the message log, optionally
5649 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5650 nonzero, means interpret the contents of M as multibyte. This
5651 function calls low-level routines in order to bypass text property
5652 hooks, etc. which might not be safe to run. */
5655 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5657 int nbytes
, nlflag
, multibyte
;
5659 if (!NILP (Vmessage_log_max
))
5661 struct buffer
*oldbuf
;
5662 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5663 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5664 int point_at_end
= 0;
5666 Lisp_Object old_deactivate_mark
, tem
;
5667 struct gcpro gcpro1
;
5669 old_deactivate_mark
= Vdeactivate_mark
;
5670 oldbuf
= current_buffer
;
5671 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5672 current_buffer
->undo_list
= Qt
;
5674 oldpoint
= message_dolog_marker1
;
5675 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5676 oldbegv
= message_dolog_marker2
;
5677 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5678 oldzv
= message_dolog_marker3
;
5679 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5680 GCPRO1 (old_deactivate_mark
);
5688 BEGV_BYTE
= BEG_BYTE
;
5691 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5693 /* Insert the string--maybe converting multibyte to single byte
5694 or vice versa, so that all the text fits the buffer. */
5696 && NILP (current_buffer
->enable_multibyte_characters
))
5698 int i
, c
, char_bytes
;
5699 unsigned char work
[1];
5701 /* Convert a multibyte string to single-byte
5702 for the *Message* buffer. */
5703 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5705 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5706 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5708 : multibyte_char_to_unibyte (c
, Qnil
));
5709 insert_1_both (work
, 1, 1, 1, 0, 0);
5712 else if (! multibyte
5713 && ! NILP (current_buffer
->enable_multibyte_characters
))
5715 int i
, c
, char_bytes
;
5716 unsigned char *msg
= (unsigned char *) m
;
5717 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5718 /* Convert a single-byte string to multibyte
5719 for the *Message* buffer. */
5720 for (i
= 0; i
< nbytes
; i
++)
5722 c
= unibyte_char_to_multibyte (msg
[i
]);
5723 char_bytes
= CHAR_STRING (c
, str
);
5724 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5728 insert_1 (m
, nbytes
, 1, 0, 0);
5732 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5733 insert_1 ("\n", 1, 1, 0, 0);
5735 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5737 this_bol_byte
= PT_BYTE
;
5739 /* See if this line duplicates the previous one.
5740 If so, combine duplicates. */
5743 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5745 prev_bol_byte
= PT_BYTE
;
5747 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5748 this_bol
, this_bol_byte
);
5751 del_range_both (prev_bol
, prev_bol_byte
,
5752 this_bol
, this_bol_byte
, 0);
5758 /* If you change this format, don't forget to also
5759 change message_log_check_duplicate. */
5760 sprintf (dupstr
, " [%d times]", dup
);
5761 duplen
= strlen (dupstr
);
5762 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5763 insert_1 (dupstr
, duplen
, 1, 0, 1);
5768 /* If we have more than the desired maximum number of lines
5769 in the *Messages* buffer now, delete the oldest ones.
5770 This is safe because we don't have undo in this buffer. */
5772 if (NATNUMP (Vmessage_log_max
))
5774 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5775 -XFASTINT (Vmessage_log_max
) - 1, 0);
5776 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5779 BEGV
= XMARKER (oldbegv
)->charpos
;
5780 BEGV_BYTE
= marker_byte_position (oldbegv
);
5789 ZV
= XMARKER (oldzv
)->charpos
;
5790 ZV_BYTE
= marker_byte_position (oldzv
);
5794 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5796 /* We can't do Fgoto_char (oldpoint) because it will run some
5798 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5799 XMARKER (oldpoint
)->bytepos
);
5802 unchain_marker (oldpoint
);
5803 unchain_marker (oldbegv
);
5804 unchain_marker (oldzv
);
5806 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5807 set_buffer_internal (oldbuf
);
5809 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5810 message_log_need_newline
= !nlflag
;
5811 Vdeactivate_mark
= old_deactivate_mark
;
5816 /* We are at the end of the buffer after just having inserted a newline.
5817 (Note: We depend on the fact we won't be crossing the gap.)
5818 Check to see if the most recent message looks a lot like the previous one.
5819 Return 0 if different, 1 if the new one should just replace it, or a
5820 value N > 1 if we should also append " [N times]". */
5823 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5824 int prev_bol
, this_bol
;
5825 int prev_bol_byte
, this_bol_byte
;
5828 int len
= Z_BYTE
- 1 - this_bol_byte
;
5830 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5831 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5833 for (i
= 0; i
< len
; i
++)
5835 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5843 if (*p1
++ == ' ' && *p1
++ == '[')
5846 while (*p1
>= '0' && *p1
<= '9')
5847 n
= n
* 10 + *p1
++ - '0';
5848 if (strncmp (p1
, " times]\n", 8) == 0)
5855 /* Display an echo area message M with a specified length of NBYTES
5856 bytes. The string may include null characters. If M is 0, clear
5857 out any existing message, and let the mini-buffer text show
5860 The buffer M must continue to exist until after the echo area gets
5861 cleared or some other message gets displayed there. This means do
5862 not pass text that is stored in a Lisp string; do not pass text in
5863 a buffer that was alloca'd. */
5866 message2 (m
, nbytes
, multibyte
)
5871 /* First flush out any partial line written with print. */
5872 message_log_maybe_newline ();
5874 message_dolog (m
, nbytes
, 1, multibyte
);
5875 message2_nolog (m
, nbytes
, multibyte
);
5879 /* The non-logging counterpart of message2. */
5882 message2_nolog (m
, nbytes
, multibyte
)
5886 struct frame
*sf
= SELECTED_FRAME ();
5887 message_enable_multibyte
= multibyte
;
5891 if (noninteractive_need_newline
)
5892 putc ('\n', stderr
);
5893 noninteractive_need_newline
= 0;
5895 fwrite (m
, nbytes
, 1, stderr
);
5896 if (cursor_in_echo_area
== 0)
5897 fprintf (stderr
, "\n");
5900 /* A null message buffer means that the frame hasn't really been
5901 initialized yet. Error messages get reported properly by
5902 cmd_error, so this must be just an informative message; toss it. */
5903 else if (INTERACTIVE
5904 && sf
->glyphs_initialized_p
5905 && FRAME_MESSAGE_BUF (sf
))
5907 Lisp_Object mini_window
;
5910 /* Get the frame containing the mini-buffer
5911 that the selected frame is using. */
5912 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5913 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5915 FRAME_SAMPLE_VISIBILITY (f
);
5916 if (FRAME_VISIBLE_P (sf
)
5917 && ! FRAME_VISIBLE_P (f
))
5918 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5922 set_message (m
, Qnil
, nbytes
, multibyte
);
5923 if (minibuffer_auto_raise
)
5924 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5927 clear_message (1, 1);
5929 do_pending_window_change (0);
5930 echo_area_display (1);
5931 do_pending_window_change (0);
5932 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5933 (*frame_up_to_date_hook
) (f
);
5938 /* Display an echo area message M with a specified length of NBYTES
5939 bytes. The string may include null characters. If M is not a
5940 string, clear out any existing message, and let the mini-buffer
5941 text show through. */
5944 message3 (m
, nbytes
, multibyte
)
5949 struct gcpro gcpro1
;
5953 /* First flush out any partial line written with print. */
5954 message_log_maybe_newline ();
5956 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
5957 message3_nolog (m
, nbytes
, multibyte
);
5963 /* The non-logging version of message3. */
5966 message3_nolog (m
, nbytes
, multibyte
)
5968 int nbytes
, multibyte
;
5970 struct frame
*sf
= SELECTED_FRAME ();
5971 message_enable_multibyte
= multibyte
;
5975 if (noninteractive_need_newline
)
5976 putc ('\n', stderr
);
5977 noninteractive_need_newline
= 0;
5979 fwrite (SDATA (m
), nbytes
, 1, stderr
);
5980 if (cursor_in_echo_area
== 0)
5981 fprintf (stderr
, "\n");
5984 /* A null message buffer means that the frame hasn't really been
5985 initialized yet. Error messages get reported properly by
5986 cmd_error, so this must be just an informative message; toss it. */
5987 else if (INTERACTIVE
5988 && sf
->glyphs_initialized_p
5989 && FRAME_MESSAGE_BUF (sf
))
5991 Lisp_Object mini_window
;
5995 /* Get the frame containing the mini-buffer
5996 that the selected frame is using. */
5997 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5998 frame
= XWINDOW (mini_window
)->frame
;
6001 FRAME_SAMPLE_VISIBILITY (f
);
6002 if (FRAME_VISIBLE_P (sf
)
6003 && !FRAME_VISIBLE_P (f
))
6004 Fmake_frame_visible (frame
);
6006 if (STRINGP (m
) && SCHARS (m
) > 0)
6008 set_message (NULL
, m
, nbytes
, multibyte
);
6009 if (minibuffer_auto_raise
)
6010 Fraise_frame (frame
);
6013 clear_message (1, 1);
6015 do_pending_window_change (0);
6016 echo_area_display (1);
6017 do_pending_window_change (0);
6018 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6019 (*frame_up_to_date_hook
) (f
);
6024 /* Display a null-terminated echo area message M. If M is 0, clear
6025 out any existing message, and let the mini-buffer text show through.
6027 The buffer M must continue to exist until after the echo area gets
6028 cleared or some other message gets displayed there. Do not pass
6029 text that is stored in a Lisp string. Do not pass text in a buffer
6030 that was alloca'd. */
6036 message2 (m
, (m
? strlen (m
) : 0), 0);
6040 /* The non-logging counterpart of message1. */
6046 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6049 /* Display a message M which contains a single %s
6050 which gets replaced with STRING. */
6053 message_with_string (m
, string
, log
)
6058 CHECK_STRING (string
);
6064 if (noninteractive_need_newline
)
6065 putc ('\n', stderr
);
6066 noninteractive_need_newline
= 0;
6067 fprintf (stderr
, m
, SDATA (string
));
6068 if (cursor_in_echo_area
== 0)
6069 fprintf (stderr
, "\n");
6073 else if (INTERACTIVE
)
6075 /* The frame whose minibuffer we're going to display the message on.
6076 It may be larger than the selected frame, so we need
6077 to use its buffer, not the selected frame's buffer. */
6078 Lisp_Object mini_window
;
6079 struct frame
*f
, *sf
= SELECTED_FRAME ();
6081 /* Get the frame containing the minibuffer
6082 that the selected frame is using. */
6083 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6084 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6086 /* A null message buffer means that the frame hasn't really been
6087 initialized yet. Error messages get reported properly by
6088 cmd_error, so this must be just an informative message; toss it. */
6089 if (FRAME_MESSAGE_BUF (f
))
6091 Lisp_Object args
[2], message
;
6092 struct gcpro gcpro1
, gcpro2
;
6094 args
[0] = build_string (m
);
6095 args
[1] = message
= string
;
6096 GCPRO2 (args
[0], message
);
6099 message
= Fformat (2, args
);
6102 message3 (message
, SBYTES (message
), SMBP (message
));
6104 message3_nolog (message
, SBYTES (message
), SMBP (message
));
6108 /* Print should start at the beginning of the message
6109 buffer next time. */
6110 message_buf_print
= 0;
6116 /* Dump an informative message to the minibuf. If M is 0, clear out
6117 any existing message, and let the mini-buffer text show through. */
6121 message (m
, a1
, a2
, a3
)
6123 EMACS_INT a1
, a2
, a3
;
6129 if (noninteractive_need_newline
)
6130 putc ('\n', stderr
);
6131 noninteractive_need_newline
= 0;
6132 fprintf (stderr
, m
, a1
, a2
, a3
);
6133 if (cursor_in_echo_area
== 0)
6134 fprintf (stderr
, "\n");
6138 else if (INTERACTIVE
)
6140 /* The frame whose mini-buffer we're going to display the message
6141 on. It may be larger than the selected frame, so we need to
6142 use its buffer, not the selected frame's buffer. */
6143 Lisp_Object mini_window
;
6144 struct frame
*f
, *sf
= SELECTED_FRAME ();
6146 /* Get the frame containing the mini-buffer
6147 that the selected frame is using. */
6148 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6149 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6151 /* A null message buffer means that the frame hasn't really been
6152 initialized yet. Error messages get reported properly by
6153 cmd_error, so this must be just an informative message; toss
6155 if (FRAME_MESSAGE_BUF (f
))
6166 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6167 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6169 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6170 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6172 #endif /* NO_ARG_ARRAY */
6174 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6179 /* Print should start at the beginning of the message
6180 buffer next time. */
6181 message_buf_print
= 0;
6187 /* The non-logging version of message. */
6190 message_nolog (m
, a1
, a2
, a3
)
6192 EMACS_INT a1
, a2
, a3
;
6194 Lisp_Object old_log_max
;
6195 old_log_max
= Vmessage_log_max
;
6196 Vmessage_log_max
= Qnil
;
6197 message (m
, a1
, a2
, a3
);
6198 Vmessage_log_max
= old_log_max
;
6202 /* Display the current message in the current mini-buffer. This is
6203 only called from error handlers in process.c, and is not time
6209 if (!NILP (echo_area_buffer
[0]))
6212 string
= Fcurrent_message ();
6213 message3 (string
, SBYTES (string
),
6214 !NILP (current_buffer
->enable_multibyte_characters
));
6219 /* Make sure echo area buffers in echo_buffers[] are life. If they
6220 aren't, make new ones. */
6223 ensure_echo_area_buffers ()
6227 for (i
= 0; i
< 2; ++i
)
6228 if (!BUFFERP (echo_buffer
[i
])
6229 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6232 Lisp_Object old_buffer
;
6235 old_buffer
= echo_buffer
[i
];
6236 sprintf (name
, " *Echo Area %d*", i
);
6237 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6238 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6240 for (j
= 0; j
< 2; ++j
)
6241 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6242 echo_area_buffer
[j
] = echo_buffer
[i
];
6247 /* Call FN with args A1..A4 with either the current or last displayed
6248 echo_area_buffer as current buffer.
6250 WHICH zero means use the current message buffer
6251 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6252 from echo_buffer[] and clear it.
6254 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6255 suitable buffer from echo_buffer[] and clear it.
6257 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6258 that the current message becomes the last displayed one, make
6259 choose a suitable buffer for echo_area_buffer[0], and clear it.
6261 Value is what FN returns. */
6264 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6267 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6273 int this_one
, the_other
, clear_buffer_p
, rc
;
6274 int count
= BINDING_STACK_SIZE ();
6276 /* If buffers aren't live, make new ones. */
6277 ensure_echo_area_buffers ();
6282 this_one
= 0, the_other
= 1;
6284 this_one
= 1, the_other
= 0;
6287 this_one
= 0, the_other
= 1;
6290 /* We need a fresh one in case the current echo buffer equals
6291 the one containing the last displayed echo area message. */
6292 if (!NILP (echo_area_buffer
[this_one
])
6293 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6294 echo_area_buffer
[this_one
] = Qnil
;
6297 /* Choose a suitable buffer from echo_buffer[] is we don't
6299 if (NILP (echo_area_buffer
[this_one
]))
6301 echo_area_buffer
[this_one
]
6302 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6303 ? echo_buffer
[the_other
]
6304 : echo_buffer
[this_one
]);
6308 buffer
= echo_area_buffer
[this_one
];
6310 /* Don't get confused by reusing the buffer used for echoing
6311 for a different purpose. */
6312 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6315 record_unwind_protect (unwind_with_echo_area_buffer
,
6316 with_echo_area_buffer_unwind_data (w
));
6318 /* Make the echo area buffer current. Note that for display
6319 purposes, it is not necessary that the displayed window's buffer
6320 == current_buffer, except for text property lookup. So, let's
6321 only set that buffer temporarily here without doing a full
6322 Fset_window_buffer. We must also change w->pointm, though,
6323 because otherwise an assertions in unshow_buffer fails, and Emacs
6325 set_buffer_internal_1 (XBUFFER (buffer
));
6329 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6332 current_buffer
->undo_list
= Qt
;
6333 current_buffer
->read_only
= Qnil
;
6334 specbind (Qinhibit_read_only
, Qt
);
6335 specbind (Qinhibit_modification_hooks
, Qt
);
6337 if (clear_buffer_p
&& Z
> BEG
)
6340 xassert (BEGV
>= BEG
);
6341 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6343 rc
= fn (a1
, a2
, a3
, a4
);
6345 xassert (BEGV
>= BEG
);
6346 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6348 unbind_to (count
, Qnil
);
6353 /* Save state that should be preserved around the call to the function
6354 FN called in with_echo_area_buffer. */
6357 with_echo_area_buffer_unwind_data (w
)
6363 /* Reduce consing by keeping one vector in
6364 Vwith_echo_area_save_vector. */
6365 vector
= Vwith_echo_area_save_vector
;
6366 Vwith_echo_area_save_vector
= Qnil
;
6369 vector
= Fmake_vector (make_number (7), Qnil
);
6371 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6372 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6373 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6377 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6378 AREF (vector
, i
) = w
->buffer
; ++i
;
6379 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6380 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6385 for (; i
< end
; ++i
)
6386 AREF (vector
, i
) = Qnil
;
6389 xassert (i
== ASIZE (vector
));
6394 /* Restore global state from VECTOR which was created by
6395 with_echo_area_buffer_unwind_data. */
6398 unwind_with_echo_area_buffer (vector
)
6401 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6402 Vdeactivate_mark
= AREF (vector
, 1);
6403 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6405 if (WINDOWP (AREF (vector
, 3)))
6408 Lisp_Object buffer
, charpos
, bytepos
;
6410 w
= XWINDOW (AREF (vector
, 3));
6411 buffer
= AREF (vector
, 4);
6412 charpos
= AREF (vector
, 5);
6413 bytepos
= AREF (vector
, 6);
6416 set_marker_both (w
->pointm
, buffer
,
6417 XFASTINT (charpos
), XFASTINT (bytepos
));
6420 Vwith_echo_area_save_vector
= vector
;
6425 /* Set up the echo area for use by print functions. MULTIBYTE_P
6426 non-zero means we will print multibyte. */
6429 setup_echo_area_for_printing (multibyte_p
)
6432 ensure_echo_area_buffers ();
6434 if (!message_buf_print
)
6436 /* A message has been output since the last time we printed.
6437 Choose a fresh echo area buffer. */
6438 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6439 echo_area_buffer
[0] = echo_buffer
[1];
6441 echo_area_buffer
[0] = echo_buffer
[0];
6443 /* Switch to that buffer and clear it. */
6444 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6445 current_buffer
->truncate_lines
= Qnil
;
6449 int count
= BINDING_STACK_SIZE ();
6450 specbind (Qinhibit_read_only
, Qt
);
6452 unbind_to (count
, Qnil
);
6454 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6456 /* Set up the buffer for the multibyteness we need. */
6458 != !NILP (current_buffer
->enable_multibyte_characters
))
6459 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6461 /* Raise the frame containing the echo area. */
6462 if (minibuffer_auto_raise
)
6464 struct frame
*sf
= SELECTED_FRAME ();
6465 Lisp_Object mini_window
;
6466 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6467 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6470 message_log_maybe_newline ();
6471 message_buf_print
= 1;
6475 if (NILP (echo_area_buffer
[0]))
6477 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6478 echo_area_buffer
[0] = echo_buffer
[1];
6480 echo_area_buffer
[0] = echo_buffer
[0];
6483 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6485 /* Someone switched buffers between print requests. */
6486 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6487 current_buffer
->truncate_lines
= Qnil
;
6493 /* Display an echo area message in window W. Value is non-zero if W's
6494 height is changed. If display_last_displayed_message_p is
6495 non-zero, display the message that was last displayed, otherwise
6496 display the current message. */
6499 display_echo_area (w
)
6502 int i
, no_message_p
, window_height_changed_p
, count
;
6504 /* Temporarily disable garbage collections while displaying the echo
6505 area. This is done because a GC can print a message itself.
6506 That message would modify the echo area buffer's contents while a
6507 redisplay of the buffer is going on, and seriously confuse
6509 count
= inhibit_garbage_collection ();
6511 /* If there is no message, we must call display_echo_area_1
6512 nevertheless because it resizes the window. But we will have to
6513 reset the echo_area_buffer in question to nil at the end because
6514 with_echo_area_buffer will sets it to an empty buffer. */
6515 i
= display_last_displayed_message_p
? 1 : 0;
6516 no_message_p
= NILP (echo_area_buffer
[i
]);
6518 window_height_changed_p
6519 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6520 display_echo_area_1
,
6521 (EMACS_INT
) w
, Qnil
, 0, 0);
6524 echo_area_buffer
[i
] = Qnil
;
6526 unbind_to (count
, Qnil
);
6527 return window_height_changed_p
;
6531 /* Helper for display_echo_area. Display the current buffer which
6532 contains the current echo area message in window W, a mini-window,
6533 a pointer to which is passed in A1. A2..A4 are currently not used.
6534 Change the height of W so that all of the message is displayed.
6535 Value is non-zero if height of W was changed. */
6538 display_echo_area_1 (a1
, a2
, a3
, a4
)
6543 struct window
*w
= (struct window
*) a1
;
6545 struct text_pos start
;
6546 int window_height_changed_p
= 0;
6548 /* Do this before displaying, so that we have a large enough glyph
6549 matrix for the display. */
6550 window_height_changed_p
= resize_mini_window (w
, 0);
6553 clear_glyph_matrix (w
->desired_matrix
);
6554 XSETWINDOW (window
, w
);
6555 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6556 try_window (window
, start
);
6558 return window_height_changed_p
;
6562 /* Resize the echo area window to exactly the size needed for the
6563 currently displayed message, if there is one. If a mini-buffer
6564 is active, don't shrink it. */
6567 resize_echo_area_exactly ()
6569 if (BUFFERP (echo_area_buffer
[0])
6570 && WINDOWP (echo_area_window
))
6572 struct window
*w
= XWINDOW (echo_area_window
);
6574 Lisp_Object resize_exactly
;
6576 if (minibuf_level
== 0)
6577 resize_exactly
= Qt
;
6579 resize_exactly
= Qnil
;
6581 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6582 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6585 ++windows_or_buffers_changed
;
6586 ++update_mode_lines
;
6587 redisplay_internal (0);
6593 /* Callback function for with_echo_area_buffer, when used from
6594 resize_echo_area_exactly. A1 contains a pointer to the window to
6595 resize, EXACTLY non-nil means resize the mini-window exactly to the
6596 size of the text displayed. A3 and A4 are not used. Value is what
6597 resize_mini_window returns. */
6600 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6602 Lisp_Object exactly
;
6605 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6609 /* Resize mini-window W to fit the size of its contents. EXACT:P
6610 means size the window exactly to the size needed. Otherwise, it's
6611 only enlarged until W's buffer is empty. Value is non-zero if
6612 the window height has been changed. */
6615 resize_mini_window (w
, exact_p
)
6619 struct frame
*f
= XFRAME (w
->frame
);
6620 int window_height_changed_p
= 0;
6622 xassert (MINI_WINDOW_P (w
));
6624 /* Don't resize windows while redisplaying a window; it would
6625 confuse redisplay functions when the size of the window they are
6626 displaying changes from under them. Such a resizing can happen,
6627 for instance, when which-func prints a long message while
6628 we are running fontification-functions. We're running these
6629 functions with safe_call which binds inhibit-redisplay to t. */
6630 if (!NILP (Vinhibit_redisplay
))
6633 /* Nil means don't try to resize. */
6634 if (NILP (Vresize_mini_windows
)
6635 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6638 if (!FRAME_MINIBUF_ONLY_P (f
))
6641 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6642 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6643 int height
, max_height
;
6644 int unit
= CANON_Y_UNIT (f
);
6645 struct text_pos start
;
6646 struct buffer
*old_current_buffer
= NULL
;
6648 if (current_buffer
!= XBUFFER (w
->buffer
))
6650 old_current_buffer
= current_buffer
;
6651 set_buffer_internal (XBUFFER (w
->buffer
));
6654 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6656 /* Compute the max. number of lines specified by the user. */
6657 if (FLOATP (Vmax_mini_window_height
))
6658 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6659 else if (INTEGERP (Vmax_mini_window_height
))
6660 max_height
= XINT (Vmax_mini_window_height
);
6662 max_height
= total_height
/ 4;
6664 /* Correct that max. height if it's bogus. */
6665 max_height
= max (1, max_height
);
6666 max_height
= min (total_height
, max_height
);
6668 /* Find out the height of the text in the window. */
6669 if (it
.truncate_lines_p
)
6674 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6675 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6676 height
= it
.current_y
+ last_height
;
6678 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6679 height
-= it
.extra_line_spacing
;
6680 height
= (height
+ unit
- 1) / unit
;
6683 /* Compute a suitable window start. */
6684 if (height
> max_height
)
6686 height
= max_height
;
6687 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6688 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6689 start
= it
.current
.pos
;
6692 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6693 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6695 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6697 /* Let it grow only, until we display an empty message, in which
6698 case the window shrinks again. */
6699 if (height
> XFASTINT (w
->height
))
6701 int old_height
= XFASTINT (w
->height
);
6702 freeze_window_starts (f
, 1);
6703 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6704 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6706 else if (height
< XFASTINT (w
->height
)
6707 && (exact_p
|| BEGV
== ZV
))
6709 int old_height
= XFASTINT (w
->height
);
6710 freeze_window_starts (f
, 0);
6711 shrink_mini_window (w
);
6712 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6717 /* Always resize to exact size needed. */
6718 if (height
> XFASTINT (w
->height
))
6720 int old_height
= XFASTINT (w
->height
);
6721 freeze_window_starts (f
, 1);
6722 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6723 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6725 else if (height
< XFASTINT (w
->height
))
6727 int old_height
= XFASTINT (w
->height
);
6728 freeze_window_starts (f
, 0);
6729 shrink_mini_window (w
);
6733 freeze_window_starts (f
, 1);
6734 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6737 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6741 if (old_current_buffer
)
6742 set_buffer_internal (old_current_buffer
);
6745 return window_height_changed_p
;
6749 /* Value is the current message, a string, or nil if there is no
6757 if (NILP (echo_area_buffer
[0]))
6761 with_echo_area_buffer (0, 0, current_message_1
,
6762 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6764 echo_area_buffer
[0] = Qnil
;
6772 current_message_1 (a1
, a2
, a3
, a4
)
6777 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6780 *msg
= make_buffer_string (BEG
, Z
, 1);
6787 /* Push the current message on Vmessage_stack for later restauration
6788 by restore_message. Value is non-zero if the current message isn't
6789 empty. This is a relatively infrequent operation, so it's not
6790 worth optimizing. */
6796 msg
= current_message ();
6797 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6798 return STRINGP (msg
);
6802 /* Handler for record_unwind_protect calling pop_message. */
6805 push_message_unwind (dummy
)
6813 /* Restore message display from the top of Vmessage_stack. */
6820 xassert (CONSP (Vmessage_stack
));
6821 msg
= XCAR (Vmessage_stack
);
6823 message3_nolog (msg
, SBYTES (msg
), SMBP (msg
));
6825 message3_nolog (msg
, 0, 0);
6829 /* Pop the top-most entry off Vmessage_stack. */
6834 xassert (CONSP (Vmessage_stack
));
6835 Vmessage_stack
= XCDR (Vmessage_stack
);
6839 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6840 exits. If the stack is not empty, we have a missing pop_message
6844 check_message_stack ()
6846 if (!NILP (Vmessage_stack
))
6851 /* Truncate to NCHARS what will be displayed in the echo area the next
6852 time we display it---but don't redisplay it now. */
6855 truncate_echo_area (nchars
)
6859 echo_area_buffer
[0] = Qnil
;
6860 /* A null message buffer means that the frame hasn't really been
6861 initialized yet. Error messages get reported properly by
6862 cmd_error, so this must be just an informative message; toss it. */
6863 else if (!noninteractive
6865 && !NILP (echo_area_buffer
[0]))
6867 struct frame
*sf
= SELECTED_FRAME ();
6868 if (FRAME_MESSAGE_BUF (sf
))
6869 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6874 /* Helper function for truncate_echo_area. Truncate the current
6875 message to at most NCHARS characters. */
6878 truncate_message_1 (nchars
, a2
, a3
, a4
)
6883 if (BEG
+ nchars
< Z
)
6884 del_range (BEG
+ nchars
, Z
);
6886 echo_area_buffer
[0] = Qnil
;
6891 /* Set the current message to a substring of S or STRING.
6893 If STRING is a Lisp string, set the message to the first NBYTES
6894 bytes from STRING. NBYTES zero means use the whole string. If
6895 STRING is multibyte, the message will be displayed multibyte.
6897 If S is not null, set the message to the first LEN bytes of S. LEN
6898 zero means use the whole string. MULTIBYTE_P non-zero means S is
6899 multibyte. Display the message multibyte in that case. */
6902 set_message (s
, string
, nbytes
, multibyte_p
)
6907 message_enable_multibyte
6908 = ((s
&& multibyte_p
)
6909 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6911 with_echo_area_buffer (0, -1, set_message_1
,
6912 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6913 message_buf_print
= 0;
6914 help_echo_showing_p
= 0;
6918 /* Helper function for set_message. Arguments have the same meaning
6919 as there, with A1 corresponding to S and A2 corresponding to STRING
6920 This function is called with the echo area buffer being
6924 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6927 EMACS_INT nbytes
, multibyte_p
;
6929 char *s
= (char *) a1
;
6930 Lisp_Object string
= a2
;
6934 /* Change multibyteness of the echo buffer appropriately. */
6935 if (message_enable_multibyte
6936 != !NILP (current_buffer
->enable_multibyte_characters
))
6937 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6939 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6941 /* Insert new message at BEG. */
6942 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6944 if (STRINGP (string
))
6949 nbytes
= SBYTES (string
);
6950 nchars
= string_byte_to_char (string
, nbytes
);
6952 /* This function takes care of single/multibyte conversion. We
6953 just have to ensure that the echo area buffer has the right
6954 setting of enable_multibyte_characters. */
6955 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6960 nbytes
= strlen (s
);
6962 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6964 /* Convert from multi-byte to single-byte. */
6966 unsigned char work
[1];
6968 /* Convert a multibyte string to single-byte. */
6969 for (i
= 0; i
< nbytes
; i
+= n
)
6971 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6972 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6974 : multibyte_char_to_unibyte (c
, Qnil
));
6975 insert_1_both (work
, 1, 1, 1, 0, 0);
6978 else if (!multibyte_p
6979 && !NILP (current_buffer
->enable_multibyte_characters
))
6981 /* Convert from single-byte to multi-byte. */
6983 unsigned char *msg
= (unsigned char *) s
;
6984 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6986 /* Convert a single-byte string to multibyte. */
6987 for (i
= 0; i
< nbytes
; i
++)
6989 c
= unibyte_char_to_multibyte (msg
[i
]);
6990 n
= CHAR_STRING (c
, str
);
6991 insert_1_both (str
, 1, n
, 1, 0, 0);
6995 insert_1 (s
, nbytes
, 1, 0, 0);
7002 /* Clear messages. CURRENT_P non-zero means clear the current
7003 message. LAST_DISPLAYED_P non-zero means clear the message
7007 clear_message (current_p
, last_displayed_p
)
7008 int current_p
, last_displayed_p
;
7012 echo_area_buffer
[0] = Qnil
;
7013 message_cleared_p
= 1;
7016 if (last_displayed_p
)
7017 echo_area_buffer
[1] = Qnil
;
7019 message_buf_print
= 0;
7022 /* Clear garbaged frames.
7024 This function is used where the old redisplay called
7025 redraw_garbaged_frames which in turn called redraw_frame which in
7026 turn called clear_frame. The call to clear_frame was a source of
7027 flickering. I believe a clear_frame is not necessary. It should
7028 suffice in the new redisplay to invalidate all current matrices,
7029 and ensure a complete redisplay of all windows. */
7032 clear_garbaged_frames ()
7036 Lisp_Object tail
, frame
;
7037 int changed_count
= 0;
7039 FOR_EACH_FRAME (tail
, frame
)
7041 struct frame
*f
= XFRAME (frame
);
7043 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7046 Fredraw_frame (frame
);
7047 clear_current_matrices (f
);
7056 ++windows_or_buffers_changed
;
7061 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7062 is non-zero update selected_frame. Value is non-zero if the
7063 mini-windows height has been changed. */
7066 echo_area_display (update_frame_p
)
7069 Lisp_Object mini_window
;
7072 int window_height_changed_p
= 0;
7073 struct frame
*sf
= SELECTED_FRAME ();
7075 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7076 w
= XWINDOW (mini_window
);
7077 f
= XFRAME (WINDOW_FRAME (w
));
7079 /* Don't display if frame is invisible or not yet initialized. */
7080 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7083 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7085 #ifdef HAVE_WINDOW_SYSTEM
7086 /* When Emacs starts, selected_frame may be a visible terminal
7087 frame, even if we run under a window system. If we let this
7088 through, a message would be displayed on the terminal. */
7089 if (EQ (selected_frame
, Vterminal_frame
)
7090 && !NILP (Vwindow_system
))
7092 #endif /* HAVE_WINDOW_SYSTEM */
7095 /* Redraw garbaged frames. */
7097 clear_garbaged_frames ();
7099 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7101 echo_area_window
= mini_window
;
7102 window_height_changed_p
= display_echo_area (w
);
7103 w
->must_be_updated_p
= 1;
7105 /* Update the display, unless called from redisplay_internal.
7106 Also don't update the screen during redisplay itself. The
7107 update will happen at the end of redisplay, and an update
7108 here could cause confusion. */
7109 if (update_frame_p
&& !redisplaying_p
)
7113 /* If the display update has been interrupted by pending
7114 input, update mode lines in the frame. Due to the
7115 pending input, it might have been that redisplay hasn't
7116 been called, so that mode lines above the echo area are
7117 garbaged. This looks odd, so we prevent it here. */
7118 if (!display_completed
)
7119 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7121 if (window_height_changed_p
7122 /* Don't do this if Emacs is shutting down. Redisplay
7123 needs to run hooks. */
7124 && !NILP (Vrun_hooks
))
7126 /* Must update other windows. Likewise as in other
7127 cases, don't let this update be interrupted by
7129 int count
= BINDING_STACK_SIZE ();
7130 specbind (Qredisplay_dont_pause
, Qt
);
7131 windows_or_buffers_changed
= 1;
7132 redisplay_internal (0);
7133 unbind_to (count
, Qnil
);
7135 else if (FRAME_WINDOW_P (f
) && n
== 0)
7137 /* Window configuration is the same as before.
7138 Can do with a display update of the echo area,
7139 unless we displayed some mode lines. */
7140 update_single_window (w
, 1);
7141 rif
->flush_display (f
);
7144 update_frame (f
, 1, 1);
7146 /* If cursor is in the echo area, make sure that the next
7147 redisplay displays the minibuffer, so that the cursor will
7148 be replaced with what the minibuffer wants. */
7149 if (cursor_in_echo_area
)
7150 ++windows_or_buffers_changed
;
7153 else if (!EQ (mini_window
, selected_window
))
7154 windows_or_buffers_changed
++;
7156 /* Last displayed message is now the current message. */
7157 echo_area_buffer
[1] = echo_area_buffer
[0];
7159 /* Prevent redisplay optimization in redisplay_internal by resetting
7160 this_line_start_pos. This is done because the mini-buffer now
7161 displays the message instead of its buffer text. */
7162 if (EQ (mini_window
, selected_window
))
7163 CHARPOS (this_line_start_pos
) = 0;
7165 return window_height_changed_p
;
7170 /***********************************************************************
7172 ***********************************************************************/
7175 /* The frame title buffering code is also used by Fformat_mode_line.
7176 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7178 /* A buffer for constructing frame titles in it; allocated from the
7179 heap in init_xdisp and resized as needed in store_frame_title_char. */
7181 static char *frame_title_buf
;
7183 /* The buffer's end, and a current output position in it. */
7185 static char *frame_title_buf_end
;
7186 static char *frame_title_ptr
;
7189 /* Store a single character C for the frame title in frame_title_buf.
7190 Re-allocate frame_title_buf if necessary. */
7193 store_frame_title_char (c
)
7196 /* If output position has reached the end of the allocated buffer,
7197 double the buffer's size. */
7198 if (frame_title_ptr
== frame_title_buf_end
)
7200 int len
= frame_title_ptr
- frame_title_buf
;
7201 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7202 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7203 frame_title_buf_end
= frame_title_buf
+ new_size
;
7204 frame_title_ptr
= frame_title_buf
+ len
;
7207 *frame_title_ptr
++ = c
;
7211 /* Store part of a frame title in frame_title_buf, beginning at
7212 frame_title_ptr. STR is the string to store. Do not copy
7213 characters that yield more columns than PRECISION; PRECISION <= 0
7214 means copy the whole string. Pad with spaces until FIELD_WIDTH
7215 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7216 pad. Called from display_mode_element when it is used to build a
7220 store_frame_title (str
, field_width
, precision
)
7222 int field_width
, precision
;
7227 /* Copy at most PRECISION chars from STR. */
7228 nbytes
= strlen (str
);
7229 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7231 store_frame_title_char (*str
++);
7233 /* Fill up with spaces until FIELD_WIDTH reached. */
7234 while (field_width
> 0
7237 store_frame_title_char (' ');
7244 #ifdef HAVE_WINDOW_SYSTEM
7246 /* Set the title of FRAME, if it has changed. The title format is
7247 Vicon_title_format if FRAME is iconified, otherwise it is
7248 frame_title_format. */
7251 x_consider_frame_title (frame
)
7254 struct frame
*f
= XFRAME (frame
);
7256 if (FRAME_WINDOW_P (f
)
7257 || FRAME_MINIBUF_ONLY_P (f
)
7258 || f
->explicit_name
)
7260 /* Do we have more than one visible frame on this X display? */
7263 struct buffer
*obuf
;
7267 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7269 Lisp_Object other_frame
= XCAR (tail
);
7270 struct frame
*tf
= XFRAME (other_frame
);
7273 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7274 && !FRAME_MINIBUF_ONLY_P (tf
)
7275 && !EQ (other_frame
, tip_frame
)
7276 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7280 /* Set global variable indicating that multiple frames exist. */
7281 multiple_frames
= CONSP (tail
);
7283 /* Switch to the buffer of selected window of the frame. Set up
7284 frame_title_ptr so that display_mode_element will output into it;
7285 then display the title. */
7286 obuf
= current_buffer
;
7287 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7288 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7289 frame_title_ptr
= frame_title_buf
;
7290 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7291 NULL
, DEFAULT_FACE_ID
);
7292 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7293 len
= frame_title_ptr
- frame_title_buf
;
7294 frame_title_ptr
= NULL
;
7295 set_buffer_internal_1 (obuf
);
7297 /* Set the title only if it's changed. This avoids consing in
7298 the common case where it hasn't. (If it turns out that we've
7299 already wasted too much time by walking through the list with
7300 display_mode_element, then we might need to optimize at a
7301 higher level than this.) */
7302 if (! STRINGP (f
->name
)
7303 || SBYTES (f
->name
) != len
7304 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7305 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7309 #endif /* not HAVE_WINDOW_SYSTEM */
7314 /***********************************************************************
7316 ***********************************************************************/
7319 /* Prepare for redisplay by updating menu-bar item lists when
7320 appropriate. This can call eval. */
7323 prepare_menu_bars ()
7326 struct gcpro gcpro1
, gcpro2
;
7328 Lisp_Object tooltip_frame
;
7330 #ifdef HAVE_WINDOW_SYSTEM
7331 tooltip_frame
= tip_frame
;
7333 tooltip_frame
= Qnil
;
7336 /* Update all frame titles based on their buffer names, etc. We do
7337 this before the menu bars so that the buffer-menu will show the
7338 up-to-date frame titles. */
7339 #ifdef HAVE_WINDOW_SYSTEM
7340 if (windows_or_buffers_changed
|| update_mode_lines
)
7342 Lisp_Object tail
, frame
;
7344 FOR_EACH_FRAME (tail
, frame
)
7347 if (!EQ (frame
, tooltip_frame
)
7348 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7349 x_consider_frame_title (frame
);
7352 #endif /* HAVE_WINDOW_SYSTEM */
7354 /* Update the menu bar item lists, if appropriate. This has to be
7355 done before any actual redisplay or generation of display lines. */
7356 all_windows
= (update_mode_lines
7357 || buffer_shared
> 1
7358 || windows_or_buffers_changed
);
7361 Lisp_Object tail
, frame
;
7362 int count
= BINDING_STACK_SIZE ();
7364 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7366 FOR_EACH_FRAME (tail
, frame
)
7370 /* Ignore tooltip frame. */
7371 if (EQ (frame
, tooltip_frame
))
7374 /* If a window on this frame changed size, report that to
7375 the user and clear the size-change flag. */
7376 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7378 Lisp_Object functions
;
7380 /* Clear flag first in case we get an error below. */
7381 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7382 functions
= Vwindow_size_change_functions
;
7383 GCPRO2 (tail
, functions
);
7385 while (CONSP (functions
))
7387 call1 (XCAR (functions
), frame
);
7388 functions
= XCDR (functions
);
7394 update_menu_bar (f
, 0);
7395 #ifdef HAVE_WINDOW_SYSTEM
7396 update_tool_bar (f
, 0);
7401 unbind_to (count
, Qnil
);
7405 struct frame
*sf
= SELECTED_FRAME ();
7406 update_menu_bar (sf
, 1);
7407 #ifdef HAVE_WINDOW_SYSTEM
7408 update_tool_bar (sf
, 1);
7412 /* Motif needs this. See comment in xmenu.c. Turn it off when
7413 pending_menu_activation is not defined. */
7414 #ifdef USE_X_TOOLKIT
7415 pending_menu_activation
= 0;
7420 /* Update the menu bar item list for frame F. This has to be done
7421 before we start to fill in any display lines, because it can call
7424 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7427 update_menu_bar (f
, save_match_data
)
7429 int save_match_data
;
7432 register struct window
*w
;
7434 /* If called recursively during a menu update, do nothing. This can
7435 happen when, for instance, an activate-menubar-hook causes a
7437 if (inhibit_menubar_update
)
7440 window
= FRAME_SELECTED_WINDOW (f
);
7441 w
= XWINDOW (window
);
7443 #if 0 /* The if statement below this if statement used to include the
7444 condition !NILP (w->update_mode_line), rather than using
7445 update_mode_lines directly, and this if statement may have
7446 been added to make that condition work. Now the if
7447 statement below matches its comment, this isn't needed. */
7448 if (update_mode_lines
)
7449 w
->update_mode_line
= Qt
;
7452 if (FRAME_WINDOW_P (f
)
7454 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
7455 FRAME_EXTERNAL_MENU_BAR (f
)
7457 FRAME_MENU_BAR_LINES (f
) > 0
7459 : FRAME_MENU_BAR_LINES (f
) > 0)
7461 /* If the user has switched buffers or windows, we need to
7462 recompute to reflect the new bindings. But we'll
7463 recompute when update_mode_lines is set too; that means
7464 that people can use force-mode-line-update to request
7465 that the menu bar be recomputed. The adverse effect on
7466 the rest of the redisplay algorithm is about the same as
7467 windows_or_buffers_changed anyway. */
7468 if (windows_or_buffers_changed
7469 /* This used to test w->update_mode_line, but we believe
7470 there is no need to recompute the menu in that case. */
7471 || update_mode_lines
7472 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7473 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7474 != !NILP (w
->last_had_star
))
7475 || ((!NILP (Vtransient_mark_mode
)
7476 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7477 != !NILP (w
->region_showing
)))
7479 struct buffer
*prev
= current_buffer
;
7480 int count
= BINDING_STACK_SIZE ();
7482 specbind (Qinhibit_menubar_update
, Qt
);
7484 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7485 if (save_match_data
)
7486 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7487 if (NILP (Voverriding_local_map_menu_flag
))
7489 specbind (Qoverriding_terminal_local_map
, Qnil
);
7490 specbind (Qoverriding_local_map
, Qnil
);
7493 /* Run the Lucid hook. */
7494 safe_run_hooks (Qactivate_menubar_hook
);
7496 /* If it has changed current-menubar from previous value,
7497 really recompute the menu-bar from the value. */
7498 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7499 call0 (Qrecompute_lucid_menubar
);
7501 safe_run_hooks (Qmenu_bar_update_hook
);
7502 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7504 /* Redisplay the menu bar in case we changed it. */
7505 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
7506 if (FRAME_WINDOW_P (f
)
7507 #if defined (MAC_OS)
7508 /* All frames on Mac OS share the same menubar. So only the
7509 selected frame should be allowed to set it. */
7510 && f
== SELECTED_FRAME ()
7513 set_frame_menubar (f
, 0, 0);
7515 /* On a terminal screen, the menu bar is an ordinary screen
7516 line, and this makes it get updated. */
7517 w
->update_mode_line
= Qt
;
7518 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7519 /* In the non-toolkit version, the menu bar is an ordinary screen
7520 line, and this makes it get updated. */
7521 w
->update_mode_line
= Qt
;
7522 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7524 unbind_to (count
, Qnil
);
7525 set_buffer_internal_1 (prev
);
7532 /***********************************************************************
7534 ***********************************************************************/
7536 #ifdef HAVE_WINDOW_SYSTEM
7538 /* Update the tool-bar item list for frame F. This has to be done
7539 before we start to fill in any display lines. Called from
7540 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7541 and restore it here. */
7544 update_tool_bar (f
, save_match_data
)
7546 int save_match_data
;
7548 if (WINDOWP (f
->tool_bar_window
)
7549 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7554 window
= FRAME_SELECTED_WINDOW (f
);
7555 w
= XWINDOW (window
);
7557 /* If the user has switched buffers or windows, we need to
7558 recompute to reflect the new bindings. But we'll
7559 recompute when update_mode_lines is set too; that means
7560 that people can use force-mode-line-update to request
7561 that the menu bar be recomputed. The adverse effect on
7562 the rest of the redisplay algorithm is about the same as
7563 windows_or_buffers_changed anyway. */
7564 if (windows_or_buffers_changed
7565 || !NILP (w
->update_mode_line
)
7566 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7567 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7568 != !NILP (w
->last_had_star
))
7569 || ((!NILP (Vtransient_mark_mode
)
7570 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7571 != !NILP (w
->region_showing
)))
7573 struct buffer
*prev
= current_buffer
;
7574 int count
= BINDING_STACK_SIZE ();
7576 /* Set current_buffer to the buffer of the selected
7577 window of the frame, so that we get the right local
7579 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7581 /* Save match data, if we must. */
7582 if (save_match_data
)
7583 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7585 /* Make sure that we don't accidentally use bogus keymaps. */
7586 if (NILP (Voverriding_local_map_menu_flag
))
7588 specbind (Qoverriding_terminal_local_map
, Qnil
);
7589 specbind (Qoverriding_local_map
, Qnil
);
7592 /* Build desired tool-bar items from keymaps. */
7594 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7596 /* Redisplay the tool-bar in case we changed it. */
7597 w
->update_mode_line
= Qt
;
7599 unbind_to (count
, Qnil
);
7600 set_buffer_internal_1 (prev
);
7606 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7607 F's desired tool-bar contents. F->tool_bar_items must have
7608 been set up previously by calling prepare_menu_bars. */
7611 build_desired_tool_bar_string (f
)
7614 int i
, size
, size_needed
;
7615 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7616 Lisp_Object image
, plist
, props
;
7618 image
= plist
= props
= Qnil
;
7619 GCPRO3 (image
, plist
, props
);
7621 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7622 Otherwise, make a new string. */
7624 /* The size of the string we might be able to reuse. */
7625 size
= (STRINGP (f
->desired_tool_bar_string
)
7626 ? SCHARS (f
->desired_tool_bar_string
)
7629 /* We need one space in the string for each image. */
7630 size_needed
= f
->n_tool_bar_items
;
7632 /* Reuse f->desired_tool_bar_string, if possible. */
7633 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7634 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7638 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7639 Fremove_text_properties (make_number (0), make_number (size
),
7640 props
, f
->desired_tool_bar_string
);
7643 /* Put a `display' property on the string for the images to display,
7644 put a `menu_item' property on tool-bar items with a value that
7645 is the index of the item in F's tool-bar item vector. */
7646 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7648 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7650 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7651 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7652 int hmargin
, vmargin
, relief
, idx
, end
;
7653 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7655 /* If image is a vector, choose the image according to the
7657 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7658 if (VECTORP (image
))
7662 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7663 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7666 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7667 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7669 xassert (ASIZE (image
) >= idx
);
7670 image
= AREF (image
, idx
);
7675 /* Ignore invalid image specifications. */
7676 if (!valid_image_p (image
))
7679 /* Display the tool-bar button pressed, or depressed. */
7680 plist
= Fcopy_sequence (XCDR (image
));
7682 /* Compute margin and relief to draw. */
7683 relief
= (tool_bar_button_relief
>= 0
7684 ? tool_bar_button_relief
7685 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7686 hmargin
= vmargin
= relief
;
7688 if (INTEGERP (Vtool_bar_button_margin
)
7689 && XINT (Vtool_bar_button_margin
) > 0)
7691 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7692 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7694 else if (CONSP (Vtool_bar_button_margin
))
7696 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7697 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7698 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7700 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7701 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7702 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7705 if (auto_raise_tool_bar_buttons_p
)
7707 /* Add a `:relief' property to the image spec if the item is
7711 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7718 /* If image is selected, display it pressed, i.e. with a
7719 negative relief. If it's not selected, display it with a
7721 plist
= Fplist_put (plist
, QCrelief
,
7723 ? make_number (-relief
)
7724 : make_number (relief
)));
7729 /* Put a margin around the image. */
7730 if (hmargin
|| vmargin
)
7732 if (hmargin
== vmargin
)
7733 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7735 plist
= Fplist_put (plist
, QCmargin
,
7736 Fcons (make_number (hmargin
),
7737 make_number (vmargin
)));
7740 /* If button is not enabled, and we don't have special images
7741 for the disabled state, make the image appear disabled by
7742 applying an appropriate algorithm to it. */
7743 if (!enabled_p
&& idx
< 0)
7744 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7746 /* Put a `display' text property on the string for the image to
7747 display. Put a `menu-item' property on the string that gives
7748 the start of this item's properties in the tool-bar items
7750 image
= Fcons (Qimage
, plist
);
7751 props
= list4 (Qdisplay
, image
,
7752 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7754 /* Let the last image hide all remaining spaces in the tool bar
7755 string. The string can be longer than needed when we reuse a
7757 if (i
+ 1 == f
->n_tool_bar_items
)
7758 end
= SCHARS (f
->desired_tool_bar_string
);
7761 Fadd_text_properties (make_number (i
), make_number (end
),
7762 props
, f
->desired_tool_bar_string
);
7770 /* Display one line of the tool-bar of frame IT->f. */
7773 display_tool_bar_line (it
)
7776 struct glyph_row
*row
= it
->glyph_row
;
7777 int max_x
= it
->last_visible_x
;
7780 prepare_desired_row (row
);
7781 row
->y
= it
->current_y
;
7783 /* Note that this isn't made use of if the face hasn't a box,
7784 so there's no need to check the face here. */
7785 it
->start_of_box_run_p
= 1;
7787 while (it
->current_x
< max_x
)
7789 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7791 /* Get the next display element. */
7792 if (!get_next_display_element (it
))
7795 /* Produce glyphs. */
7796 x_before
= it
->current_x
;
7797 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7798 PRODUCE_GLYPHS (it
);
7800 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7805 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7807 if (x
+ glyph
->pixel_width
> max_x
)
7809 /* Glyph doesn't fit on line. */
7810 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7816 x
+= glyph
->pixel_width
;
7820 /* Stop at line ends. */
7821 if (ITERATOR_AT_END_OF_LINE_P (it
))
7824 set_iterator_to_next (it
, 1);
7829 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7830 extend_face_to_end_of_line (it
);
7831 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7832 last
->right_box_line_p
= 1;
7833 if (last
== row
->glyphs
[TEXT_AREA
])
7834 last
->left_box_line_p
= 1;
7835 compute_line_metrics (it
);
7837 /* If line is empty, make it occupy the rest of the tool-bar. */
7838 if (!row
->displays_text_p
)
7840 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7841 row
->ascent
= row
->phys_ascent
= 0;
7844 row
->full_width_p
= 1;
7845 row
->continued_p
= 0;
7846 row
->truncated_on_left_p
= 0;
7847 row
->truncated_on_right_p
= 0;
7849 it
->current_x
= it
->hpos
= 0;
7850 it
->current_y
+= row
->height
;
7856 /* Value is the number of screen lines needed to make all tool-bar
7857 items of frame F visible. */
7860 tool_bar_lines_needed (f
)
7863 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7866 /* Initialize an iterator for iteration over
7867 F->desired_tool_bar_string in the tool-bar window of frame F. */
7868 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7869 it
.first_visible_x
= 0;
7870 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7871 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7873 while (!ITERATOR_AT_END_P (&it
))
7875 it
.glyph_row
= w
->desired_matrix
->rows
;
7876 clear_glyph_row (it
.glyph_row
);
7877 display_tool_bar_line (&it
);
7880 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7884 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7886 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7895 frame
= selected_frame
;
7897 CHECK_FRAME (frame
);
7900 if (WINDOWP (f
->tool_bar_window
)
7901 || (w
= XWINDOW (f
->tool_bar_window
),
7902 XFASTINT (w
->height
) > 0))
7904 update_tool_bar (f
, 1);
7905 if (f
->n_tool_bar_items
)
7907 build_desired_tool_bar_string (f
);
7908 nlines
= tool_bar_lines_needed (f
);
7912 return make_number (nlines
);
7916 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7917 height should be changed. */
7920 redisplay_tool_bar (f
)
7925 struct glyph_row
*row
;
7926 int change_height_p
= 0;
7928 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7929 do anything. This means you must start with tool-bar-lines
7930 non-zero to get the auto-sizing effect. Or in other words, you
7931 can turn off tool-bars by specifying tool-bar-lines zero. */
7932 if (!WINDOWP (f
->tool_bar_window
)
7933 || (w
= XWINDOW (f
->tool_bar_window
),
7934 XFASTINT (w
->height
) == 0))
7937 /* Set up an iterator for the tool-bar window. */
7938 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7939 it
.first_visible_x
= 0;
7940 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7943 /* Build a string that represents the contents of the tool-bar. */
7944 build_desired_tool_bar_string (f
);
7945 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7947 /* Display as many lines as needed to display all tool-bar items. */
7948 while (it
.current_y
< it
.last_visible_y
)
7949 display_tool_bar_line (&it
);
7951 /* It doesn't make much sense to try scrolling in the tool-bar
7952 window, so don't do it. */
7953 w
->desired_matrix
->no_scrolling_p
= 1;
7954 w
->must_be_updated_p
= 1;
7956 if (auto_resize_tool_bars_p
)
7960 /* If we couldn't display everything, change the tool-bar's
7962 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7963 change_height_p
= 1;
7965 /* If there are blank lines at the end, except for a partially
7966 visible blank line at the end that is smaller than
7967 CANON_Y_UNIT, change the tool-bar's height. */
7968 row
= it
.glyph_row
- 1;
7969 if (!row
->displays_text_p
7970 && row
->height
>= CANON_Y_UNIT (f
))
7971 change_height_p
= 1;
7973 /* If row displays tool-bar items, but is partially visible,
7974 change the tool-bar's height. */
7975 if (row
->displays_text_p
7976 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7977 change_height_p
= 1;
7979 /* Resize windows as needed by changing the `tool-bar-lines'
7982 && (nlines
= tool_bar_lines_needed (f
),
7983 nlines
!= XFASTINT (w
->height
)))
7985 extern Lisp_Object Qtool_bar_lines
;
7987 int old_height
= XFASTINT (w
->height
);
7989 XSETFRAME (frame
, f
);
7990 clear_glyph_matrix (w
->desired_matrix
);
7991 Fmodify_frame_parameters (frame
,
7992 Fcons (Fcons (Qtool_bar_lines
,
7993 make_number (nlines
)),
7995 if (XFASTINT (w
->height
) != old_height
)
7996 fonts_changed_p
= 1;
8000 return change_height_p
;
8004 /* Get information about the tool-bar item which is displayed in GLYPH
8005 on frame F. Return in *PROP_IDX the index where tool-bar item
8006 properties start in F->tool_bar_items. Value is zero if
8007 GLYPH doesn't display a tool-bar item. */
8010 tool_bar_item_info (f
, glyph
, prop_idx
)
8012 struct glyph
*glyph
;
8019 /* This function can be called asynchronously, which means we must
8020 exclude any possibility that Fget_text_property signals an
8022 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8023 charpos
= max (0, charpos
);
8025 /* Get the text property `menu-item' at pos. The value of that
8026 property is the start index of this item's properties in
8027 F->tool_bar_items. */
8028 prop
= Fget_text_property (make_number (charpos
),
8029 Qmenu_item
, f
->current_tool_bar_string
);
8030 if (INTEGERP (prop
))
8032 *prop_idx
= XINT (prop
);
8041 #endif /* HAVE_WINDOW_SYSTEM */
8045 /************************************************************************
8046 Horizontal scrolling
8047 ************************************************************************/
8049 static int hscroll_window_tree
P_ ((Lisp_Object
));
8050 static int hscroll_windows
P_ ((Lisp_Object
));
8052 /* For all leaf windows in the window tree rooted at WINDOW, set their
8053 hscroll value so that PT is (i) visible in the window, and (ii) so
8054 that it is not within a certain margin at the window's left and
8055 right border. Value is non-zero if any window's hscroll has been
8059 hscroll_window_tree (window
)
8062 int hscrolled_p
= 0;
8063 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
8064 int hscroll_step_abs
= 0;
8065 double hscroll_step_rel
= 0;
8067 if (hscroll_relative_p
)
8069 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
8070 if (hscroll_step_rel
< 0)
8072 hscroll_relative_p
= 0;
8073 hscroll_step_abs
= 0;
8076 else if (INTEGERP (Vhscroll_step
))
8078 hscroll_step_abs
= XINT (Vhscroll_step
);
8079 if (hscroll_step_abs
< 0)
8080 hscroll_step_abs
= 0;
8083 hscroll_step_abs
= 0;
8085 while (WINDOWP (window
))
8087 struct window
*w
= XWINDOW (window
);
8089 if (WINDOWP (w
->hchild
))
8090 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8091 else if (WINDOWP (w
->vchild
))
8092 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8093 else if (w
->cursor
.vpos
>= 0)
8095 int h_margin
, text_area_x
, text_area_y
;
8096 int text_area_width
, text_area_height
;
8097 struct glyph_row
*current_cursor_row
8098 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8099 struct glyph_row
*desired_cursor_row
8100 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8101 struct glyph_row
*cursor_row
8102 = (desired_cursor_row
->enabled_p
8103 ? desired_cursor_row
8104 : current_cursor_row
);
8106 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8107 &text_area_width
, &text_area_height
);
8109 /* Scroll when cursor is inside this scroll margin. */
8110 h_margin
= hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8112 if ((XFASTINT (w
->hscroll
)
8113 && w
->cursor
.x
<= h_margin
)
8114 || (cursor_row
->enabled_p
8115 && cursor_row
->truncated_on_right_p
8116 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
8120 struct buffer
*saved_current_buffer
;
8124 /* Find point in a display of infinite width. */
8125 saved_current_buffer
= current_buffer
;
8126 current_buffer
= XBUFFER (w
->buffer
);
8128 if (w
== XWINDOW (selected_window
))
8129 pt
= BUF_PT (current_buffer
);
8132 pt
= marker_position (w
->pointm
);
8133 pt
= max (BEGV
, pt
);
8137 /* Move iterator to pt starting at cursor_row->start in
8138 a line with infinite width. */
8139 init_to_row_start (&it
, w
, cursor_row
);
8140 it
.last_visible_x
= INFINITY
;
8141 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8142 current_buffer
= saved_current_buffer
;
8144 /* Position cursor in window. */
8145 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8146 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8147 / CANON_X_UNIT (it
.f
);
8148 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
8150 if (hscroll_relative_p
)
8151 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8154 wanted_x
= text_area_width
8155 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8158 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8162 if (hscroll_relative_p
)
8163 wanted_x
= text_area_width
* hscroll_step_rel
8166 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8169 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8171 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8173 /* Don't call Fset_window_hscroll if value hasn't
8174 changed because it will prevent redisplay
8176 if (XFASTINT (w
->hscroll
) != hscroll
)
8178 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8179 w
->hscroll
= make_number (hscroll
);
8188 /* Value is non-zero if hscroll of any leaf window has been changed. */
8193 /* Set hscroll so that cursor is visible and not inside horizontal
8194 scroll margins for all windows in the tree rooted at WINDOW. See
8195 also hscroll_window_tree above. Value is non-zero if any window's
8196 hscroll has been changed. If it has, desired matrices on the frame
8197 of WINDOW are cleared. */
8200 hscroll_windows (window
)
8205 if (automatic_hscrolling_p
)
8207 hscrolled_p
= hscroll_window_tree (window
);
8209 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8218 /************************************************************************
8220 ************************************************************************/
8222 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8223 to a non-zero value. This is sometimes handy to have in a debugger
8228 /* First and last unchanged row for try_window_id. */
8230 int debug_first_unchanged_at_end_vpos
;
8231 int debug_last_unchanged_at_beg_vpos
;
8233 /* Delta vpos and y. */
8235 int debug_dvpos
, debug_dy
;
8237 /* Delta in characters and bytes for try_window_id. */
8239 int debug_delta
, debug_delta_bytes
;
8241 /* Values of window_end_pos and window_end_vpos at the end of
8244 EMACS_INT debug_end_pos
, debug_end_vpos
;
8246 /* Append a string to W->desired_matrix->method. FMT is a printf
8247 format string. A1...A9 are a supplement for a variable-length
8248 argument list. If trace_redisplay_p is non-zero also printf the
8249 resulting string to stderr. */
8252 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8255 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8258 char *method
= w
->desired_matrix
->method
;
8259 int len
= strlen (method
);
8260 int size
= sizeof w
->desired_matrix
->method
;
8261 int remaining
= size
- len
- 1;
8263 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8264 if (len
&& remaining
)
8270 strncpy (method
+ len
, buffer
, remaining
);
8272 if (trace_redisplay_p
)
8273 fprintf (stderr
, "%p (%s): %s\n",
8275 ((BUFFERP (w
->buffer
)
8276 && STRINGP (XBUFFER (w
->buffer
)->name
))
8277 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
8282 #endif /* GLYPH_DEBUG */
8285 /* This counter is used to clear the face cache every once in a while
8286 in redisplay_internal. It is incremented for each redisplay.
8287 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8290 #define CLEAR_FACE_CACHE_COUNT 500
8291 static int clear_face_cache_count
;
8293 /* Record the previous terminal frame we displayed. */
8295 static struct frame
*previous_terminal_frame
;
8297 /* Non-zero while redisplay_internal is in progress. */
8302 /* Value is non-zero if all changes in window W, which displays
8303 current_buffer, are in the text between START and END. START is a
8304 buffer position, END is given as a distance from Z. Used in
8305 redisplay_internal for display optimization. */
8308 text_outside_line_unchanged_p (w
, start
, end
)
8312 int unchanged_p
= 1;
8314 /* If text or overlays have changed, see where. */
8315 if (XFASTINT (w
->last_modified
) < MODIFF
8316 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8318 /* Gap in the line? */
8319 if (GPT
< start
|| Z
- GPT
< end
)
8322 /* Changes start in front of the line, or end after it? */
8324 && (BEG_UNCHANGED
< start
- 1
8325 || END_UNCHANGED
< end
))
8328 /* If selective display, can't optimize if changes start at the
8329 beginning of the line. */
8331 && INTEGERP (current_buffer
->selective_display
)
8332 && XINT (current_buffer
->selective_display
) > 0
8333 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8336 /* If there are overlays at the start or end of the line, these
8337 may have overlay strings with newlines in them. A change at
8338 START, for instance, may actually concern the display of such
8339 overlay strings as well, and they are displayed on different
8340 lines. So, quickly rule out this case. (For the future, it
8341 might be desirable to implement something more telling than
8342 just BEG/END_UNCHANGED.) */
8345 if (BEG
+ BEG_UNCHANGED
== start
8346 && overlay_touches_p (start
))
8348 if (END_UNCHANGED
== end
8349 && overlay_touches_p (Z
- end
))
8358 /* Do a frame update, taking possible shortcuts into account. This is
8359 the main external entry point for redisplay.
8361 If the last redisplay displayed an echo area message and that message
8362 is no longer requested, we clear the echo area or bring back the
8363 mini-buffer if that is in use. */
8368 redisplay_internal (0);
8372 /* Return 1 if point moved out of or into a composition. Otherwise
8373 return 0. PREV_BUF and PREV_PT are the last point buffer and
8374 position. BUF and PT are the current point buffer and position. */
8377 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8378 struct buffer
*prev_buf
, *buf
;
8385 XSETBUFFER (buffer
, buf
);
8386 /* Check a composition at the last point if point moved within the
8388 if (prev_buf
== buf
)
8391 /* Point didn't move. */
8394 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8395 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8396 && COMPOSITION_VALID_P (start
, end
, prop
)
8397 && start
< prev_pt
&& end
> prev_pt
)
8398 /* The last point was within the composition. Return 1 iff
8399 point moved out of the composition. */
8400 return (pt
<= start
|| pt
>= end
);
8403 /* Check a composition at the current point. */
8404 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8405 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8406 && COMPOSITION_VALID_P (start
, end
, prop
)
8407 && start
< pt
&& end
> pt
);
8411 /* Reconsider the setting of B->clip_changed which is displayed
8415 reconsider_clip_changes (w
, b
)
8419 if (b
->prevent_redisplay_optimizations_p
)
8420 b
->clip_changed
= 1;
8421 else if (b
->clip_changed
8422 && !NILP (w
->window_end_valid
)
8423 && w
->current_matrix
->buffer
== b
8424 && w
->current_matrix
->zv
== BUF_ZV (b
)
8425 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8426 b
->clip_changed
= 0;
8428 /* If display wasn't paused, and W is not a tool bar window, see if
8429 point has been moved into or out of a composition. In that case,
8430 we set b->clip_changed to 1 to force updating the screen. If
8431 b->clip_changed has already been set to 1, we can skip this
8433 if (!b
->clip_changed
8434 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8438 if (w
== XWINDOW (selected_window
))
8439 pt
= BUF_PT (current_buffer
);
8441 pt
= marker_position (w
->pointm
);
8443 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8444 || pt
!= XINT (w
->last_point
))
8445 && check_point_in_composition (w
->current_matrix
->buffer
,
8446 XINT (w
->last_point
),
8447 XBUFFER (w
->buffer
), pt
))
8448 b
->clip_changed
= 1;
8453 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8454 response to any user action; therefore, we should preserve the echo
8455 area. (Actually, our caller does that job.) Perhaps in the future
8456 avoid recentering windows if it is not necessary; currently that
8457 causes some problems. */
8460 redisplay_internal (preserve_echo_area
)
8461 int preserve_echo_area
;
8463 struct window
*w
= XWINDOW (selected_window
);
8464 struct frame
*f
= XFRAME (w
->frame
);
8466 int must_finish
= 0;
8467 struct text_pos tlbufpos
, tlendpos
;
8468 int number_of_visible_frames
;
8470 struct frame
*sf
= SELECTED_FRAME ();
8472 /* Non-zero means redisplay has to consider all windows on all
8473 frames. Zero means, only selected_window is considered. */
8474 int consider_all_windows_p
;
8476 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8478 /* No redisplay if running in batch mode or frame is not yet fully
8479 initialized, or redisplay is explicitly turned off by setting
8480 Vinhibit_redisplay. */
8482 || !NILP (Vinhibit_redisplay
)
8483 || !f
->glyphs_initialized_p
)
8486 /* The flag redisplay_performed_directly_p is set by
8487 direct_output_for_insert when it already did the whole screen
8488 update necessary. */
8489 if (redisplay_performed_directly_p
)
8491 redisplay_performed_directly_p
= 0;
8492 if (!hscroll_windows (selected_window
))
8496 #ifdef USE_X_TOOLKIT
8497 if (popup_activated ())
8501 /* I don't think this happens but let's be paranoid. */
8505 /* Record a function that resets redisplaying_p to its old value
8506 when we leave this function. */
8507 count
= BINDING_STACK_SIZE ();
8508 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8513 reconsider_clip_changes (w
, current_buffer
);
8515 /* If new fonts have been loaded that make a glyph matrix adjustment
8516 necessary, do it. */
8517 if (fonts_changed_p
)
8519 adjust_glyphs (NULL
);
8520 ++windows_or_buffers_changed
;
8521 fonts_changed_p
= 0;
8524 /* If face_change_count is non-zero, init_iterator will free all
8525 realized faces, which includes the faces referenced from current
8526 matrices. So, we can't reuse current matrices in this case. */
8527 if (face_change_count
)
8528 ++windows_or_buffers_changed
;
8530 if (! FRAME_WINDOW_P (sf
)
8531 && previous_terminal_frame
!= sf
)
8533 /* Since frames on an ASCII terminal share the same display
8534 area, displaying a different frame means redisplay the whole
8536 windows_or_buffers_changed
++;
8537 SET_FRAME_GARBAGED (sf
);
8538 XSETFRAME (Vterminal_frame
, sf
);
8540 previous_terminal_frame
= sf
;
8542 /* Set the visible flags for all frames. Do this before checking
8543 for resized or garbaged frames; they want to know if their frames
8544 are visible. See the comment in frame.h for
8545 FRAME_SAMPLE_VISIBILITY. */
8547 Lisp_Object tail
, frame
;
8549 number_of_visible_frames
= 0;
8551 FOR_EACH_FRAME (tail
, frame
)
8553 struct frame
*f
= XFRAME (frame
);
8555 FRAME_SAMPLE_VISIBILITY (f
);
8556 if (FRAME_VISIBLE_P (f
))
8557 ++number_of_visible_frames
;
8558 clear_desired_matrices (f
);
8562 /* Notice any pending interrupt request to change frame size. */
8563 do_pending_window_change (1);
8565 /* Clear frames marked as garbaged. */
8567 clear_garbaged_frames ();
8569 /* Build menubar and tool-bar items. */
8570 prepare_menu_bars ();
8572 if (windows_or_buffers_changed
)
8573 update_mode_lines
++;
8575 /* Detect case that we need to write or remove a star in the mode line. */
8576 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8578 w
->update_mode_line
= Qt
;
8579 if (buffer_shared
> 1)
8580 update_mode_lines
++;
8583 /* If %c is in the mode line, update it if needed. */
8584 if (!NILP (w
->column_number_displayed
)
8585 /* This alternative quickly identifies a common case
8586 where no change is needed. */
8587 && !(PT
== XFASTINT (w
->last_point
)
8588 && XFASTINT (w
->last_modified
) >= MODIFF
8589 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8590 && (XFASTINT (w
->column_number_displayed
)
8591 != (int) current_column ())) /* iftc */
8592 w
->update_mode_line
= Qt
;
8594 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8596 /* The variable buffer_shared is set in redisplay_window and
8597 indicates that we redisplay a buffer in different windows. See
8599 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
8600 || cursor_type_changed
);
8602 /* If specs for an arrow have changed, do thorough redisplay
8603 to ensure we remove any arrow that should no longer exist. */
8604 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8605 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8606 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8608 /* Normally the message* functions will have already displayed and
8609 updated the echo area, but the frame may have been trashed, or
8610 the update may have been preempted, so display the echo area
8611 again here. Checking message_cleared_p captures the case that
8612 the echo area should be cleared. */
8613 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8614 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8615 || (message_cleared_p
8616 && minibuf_level
== 0
8617 /* If the mini-window is currently selected, this means the
8618 echo-area doesn't show through. */
8619 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8621 int window_height_changed_p
= echo_area_display (0);
8624 /* If we don't display the current message, don't clear the
8625 message_cleared_p flag, because, if we did, we wouldn't clear
8626 the echo area in the next redisplay which doesn't preserve
8628 if (!display_last_displayed_message_p
)
8629 message_cleared_p
= 0;
8631 if (fonts_changed_p
)
8633 else if (window_height_changed_p
)
8635 consider_all_windows_p
= 1;
8636 ++update_mode_lines
;
8637 ++windows_or_buffers_changed
;
8639 /* If window configuration was changed, frames may have been
8640 marked garbaged. Clear them or we will experience
8641 surprises wrt scrolling. */
8643 clear_garbaged_frames ();
8646 else if (EQ (selected_window
, minibuf_window
)
8647 && (current_buffer
->clip_changed
8648 || XFASTINT (w
->last_modified
) < MODIFF
8649 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8650 && resize_mini_window (w
, 0))
8652 /* Resized active mini-window to fit the size of what it is
8653 showing if its contents might have changed. */
8655 consider_all_windows_p
= 1;
8656 ++windows_or_buffers_changed
;
8657 ++update_mode_lines
;
8659 /* If window configuration was changed, frames may have been
8660 marked garbaged. Clear them or we will experience
8661 surprises wrt scrolling. */
8663 clear_garbaged_frames ();
8667 /* If showing the region, and mark has changed, we must redisplay
8668 the whole window. The assignment to this_line_start_pos prevents
8669 the optimization directly below this if-statement. */
8670 if (((!NILP (Vtransient_mark_mode
)
8671 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8672 != !NILP (w
->region_showing
))
8673 || (!NILP (w
->region_showing
)
8674 && !EQ (w
->region_showing
,
8675 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8676 CHARPOS (this_line_start_pos
) = 0;
8678 /* Optimize the case that only the line containing the cursor in the
8679 selected window has changed. Variables starting with this_ are
8680 set in display_line and record information about the line
8681 containing the cursor. */
8682 tlbufpos
= this_line_start_pos
;
8683 tlendpos
= this_line_end_pos
;
8684 if (!consider_all_windows_p
8685 && CHARPOS (tlbufpos
) > 0
8686 && NILP (w
->update_mode_line
)
8687 && !current_buffer
->clip_changed
8688 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8689 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8690 /* Make sure recorded data applies to current buffer, etc. */
8691 && this_line_buffer
== current_buffer
8692 && current_buffer
== XBUFFER (w
->buffer
)
8693 && NILP (w
->force_start
)
8694 && NILP (w
->optional_new_start
)
8695 /* Point must be on the line that we have info recorded about. */
8696 && PT
>= CHARPOS (tlbufpos
)
8697 && PT
<= Z
- CHARPOS (tlendpos
)
8698 /* All text outside that line, including its final newline,
8699 must be unchanged */
8700 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8701 CHARPOS (tlendpos
)))
8703 if (CHARPOS (tlbufpos
) > BEGV
8704 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8705 && (CHARPOS (tlbufpos
) == ZV
8706 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8707 /* Former continuation line has disappeared by becoming empty */
8709 else if (XFASTINT (w
->last_modified
) < MODIFF
8710 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8711 || MINI_WINDOW_P (w
))
8713 /* We have to handle the case of continuation around a
8714 wide-column character (See the comment in indent.c around
8717 For instance, in the following case:
8719 -------- Insert --------
8720 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8721 J_I_ ==> J_I_ `^^' are cursors.
8725 As we have to redraw the line above, we should goto cancel. */
8728 int line_height_before
= this_line_pixel_height
;
8730 /* Note that start_display will handle the case that the
8731 line starting at tlbufpos is a continuation lines. */
8732 start_display (&it
, w
, tlbufpos
);
8734 /* Implementation note: It this still necessary? */
8735 if (it
.current_x
!= this_line_start_x
)
8738 TRACE ((stderr
, "trying display optimization 1\n"));
8739 w
->cursor
.vpos
= -1;
8740 overlay_arrow_seen
= 0;
8741 it
.vpos
= this_line_vpos
;
8742 it
.current_y
= this_line_y
;
8743 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8746 /* If line contains point, is not continued,
8747 and ends at same distance from eob as before, we win */
8748 if (w
->cursor
.vpos
>= 0
8749 /* Line is not continued, otherwise this_line_start_pos
8750 would have been set to 0 in display_line. */
8751 && CHARPOS (this_line_start_pos
)
8752 /* Line ends as before. */
8753 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8754 /* Line has same height as before. Otherwise other lines
8755 would have to be shifted up or down. */
8756 && this_line_pixel_height
== line_height_before
)
8758 /* If this is not the window's last line, we must adjust
8759 the charstarts of the lines below. */
8760 if (it
.current_y
< it
.last_visible_y
)
8762 struct glyph_row
*row
8763 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8764 int delta
, delta_bytes
;
8766 if (Z
- CHARPOS (tlendpos
) == ZV
)
8768 /* This line ends at end of (accessible part of)
8769 buffer. There is no newline to count. */
8771 - CHARPOS (tlendpos
)
8772 - MATRIX_ROW_START_CHARPOS (row
));
8773 delta_bytes
= (Z_BYTE
8774 - BYTEPOS (tlendpos
)
8775 - MATRIX_ROW_START_BYTEPOS (row
));
8779 /* This line ends in a newline. Must take
8780 account of the newline and the rest of the
8781 text that follows. */
8783 - CHARPOS (tlendpos
)
8784 - MATRIX_ROW_START_CHARPOS (row
));
8785 delta_bytes
= (Z_BYTE
8786 - BYTEPOS (tlendpos
)
8787 - MATRIX_ROW_START_BYTEPOS (row
));
8790 increment_matrix_positions (w
->current_matrix
,
8792 w
->current_matrix
->nrows
,
8793 delta
, delta_bytes
);
8796 /* If this row displays text now but previously didn't,
8797 or vice versa, w->window_end_vpos may have to be
8799 if ((it
.glyph_row
- 1)->displays_text_p
)
8801 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8802 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8804 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8805 && this_line_vpos
> 0)
8806 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8807 w
->window_end_valid
= Qnil
;
8809 /* Update hint: No need to try to scroll in update_window. */
8810 w
->desired_matrix
->no_scrolling_p
= 1;
8813 *w
->desired_matrix
->method
= 0;
8814 debug_method_add (w
, "optimization 1");
8821 else if (/* Cursor position hasn't changed. */
8822 PT
== XFASTINT (w
->last_point
)
8823 /* Make sure the cursor was last displayed
8824 in this window. Otherwise we have to reposition it. */
8825 && 0 <= w
->cursor
.vpos
8826 && XINT (w
->height
) > w
->cursor
.vpos
)
8830 do_pending_window_change (1);
8832 /* We used to always goto end_of_redisplay here, but this
8833 isn't enough if we have a blinking cursor. */
8834 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8835 goto end_of_redisplay
;
8839 /* If highlighting the region, or if the cursor is in the echo area,
8840 then we can't just move the cursor. */
8841 else if (! (!NILP (Vtransient_mark_mode
)
8842 && !NILP (current_buffer
->mark_active
))
8843 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8844 || highlight_nonselected_windows
)
8845 && NILP (w
->region_showing
)
8846 && NILP (Vshow_trailing_whitespace
)
8847 && !cursor_in_echo_area
)
8850 struct glyph_row
*row
;
8852 /* Skip from tlbufpos to PT and see where it is. Note that
8853 PT may be in invisible text. If so, we will end at the
8854 next visible position. */
8855 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8856 NULL
, DEFAULT_FACE_ID
);
8857 it
.current_x
= this_line_start_x
;
8858 it
.current_y
= this_line_y
;
8859 it
.vpos
= this_line_vpos
;
8861 /* The call to move_it_to stops in front of PT, but
8862 moves over before-strings. */
8863 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8865 if (it
.vpos
== this_line_vpos
8866 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8869 xassert (this_line_vpos
== it
.vpos
);
8870 xassert (this_line_y
== it
.current_y
);
8871 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8873 *w
->desired_matrix
->method
= 0;
8874 debug_method_add (w
, "optimization 3");
8883 /* Text changed drastically or point moved off of line. */
8884 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8887 CHARPOS (this_line_start_pos
) = 0;
8888 consider_all_windows_p
|= buffer_shared
> 1;
8889 ++clear_face_cache_count
;
8892 /* Build desired matrices, and update the display. If
8893 consider_all_windows_p is non-zero, do it for all windows on all
8894 frames. Otherwise do it for selected_window, only. */
8896 if (consider_all_windows_p
)
8898 Lisp_Object tail
, frame
;
8899 int i
, n
= 0, size
= 50;
8900 struct frame
**updated
8901 = (struct frame
**) alloca (size
* sizeof *updated
);
8903 /* Clear the face cache eventually. */
8904 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8906 clear_face_cache (0);
8907 clear_face_cache_count
= 0;
8910 /* Recompute # windows showing selected buffer. This will be
8911 incremented each time such a window is displayed. */
8914 FOR_EACH_FRAME (tail
, frame
)
8916 struct frame
*f
= XFRAME (frame
);
8918 if (FRAME_WINDOW_P (f
) || f
== sf
)
8920 #ifdef HAVE_WINDOW_SYSTEM
8921 if (clear_face_cache_count
% 50 == 0
8922 && FRAME_WINDOW_P (f
))
8923 clear_image_cache (f
, 0);
8924 #endif /* HAVE_WINDOW_SYSTEM */
8926 /* Mark all the scroll bars to be removed; we'll redeem
8927 the ones we want when we redisplay their windows. */
8928 if (condemn_scroll_bars_hook
)
8929 condemn_scroll_bars_hook (f
);
8931 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8932 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8934 /* Any scroll bars which redisplay_windows should have
8935 nuked should now go away. */
8936 if (judge_scroll_bars_hook
)
8937 judge_scroll_bars_hook (f
);
8939 /* If fonts changed, display again. */
8940 if (fonts_changed_p
)
8943 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8945 /* See if we have to hscroll. */
8946 if (hscroll_windows (f
->root_window
))
8949 /* Prevent various kinds of signals during display
8950 update. stdio is not robust about handling
8951 signals, which can cause an apparent I/O
8953 if (interrupt_input
)
8957 /* Update the display. */
8958 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8959 pause
|= update_frame (f
, 0, 0);
8965 int nbytes
= size
* sizeof *updated
;
8966 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8967 bcopy (updated
, p
, nbytes
);
8976 /* Do the mark_window_display_accurate after all windows have
8977 been redisplayed because this call resets flags in buffers
8978 which are needed for proper redisplay. */
8979 for (i
= 0; i
< n
; ++i
)
8981 struct frame
*f
= updated
[i
];
8982 mark_window_display_accurate (f
->root_window
, 1);
8983 if (frame_up_to_date_hook
)
8984 frame_up_to_date_hook (f
);
8987 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8989 Lisp_Object mini_window
;
8990 struct frame
*mini_frame
;
8992 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8993 /* Use list_of_error, not Qerror, so that
8994 we catch only errors and don't run the debugger. */
8995 internal_condition_case_1 (redisplay_window_1
, selected_window
,
8997 redisplay_window_error
);
8999 /* Compare desired and current matrices, perform output. */
9002 /* If fonts changed, display again. */
9003 if (fonts_changed_p
)
9006 /* Prevent various kinds of signals during display update.
9007 stdio is not robust about handling signals,
9008 which can cause an apparent I/O error. */
9009 if (interrupt_input
)
9013 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9015 if (hscroll_windows (selected_window
))
9018 XWINDOW (selected_window
)->must_be_updated_p
= 1;
9019 pause
= update_frame (sf
, 0, 0);
9022 /* We may have called echo_area_display at the top of this
9023 function. If the echo area is on another frame, that may
9024 have put text on a frame other than the selected one, so the
9025 above call to update_frame would not have caught it. Catch
9027 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9028 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9030 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
9032 XWINDOW (mini_window
)->must_be_updated_p
= 1;
9033 pause
|= update_frame (mini_frame
, 0, 0);
9034 if (!pause
&& hscroll_windows (mini_window
))
9039 /* If display was paused because of pending input, make sure we do a
9040 thorough update the next time. */
9043 /* Prevent the optimization at the beginning of
9044 redisplay_internal that tries a single-line update of the
9045 line containing the cursor in the selected window. */
9046 CHARPOS (this_line_start_pos
) = 0;
9048 /* Let the overlay arrow be updated the next time. */
9049 if (!NILP (last_arrow_position
))
9051 last_arrow_position
= Qt
;
9052 last_arrow_string
= Qt
;
9055 /* If we pause after scrolling, some rows in the current
9056 matrices of some windows are not valid. */
9057 if (!WINDOW_FULL_WIDTH_P (w
)
9058 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9059 update_mode_lines
= 1;
9063 if (!consider_all_windows_p
)
9065 /* This has already been done above if
9066 consider_all_windows_p is set. */
9067 mark_window_display_accurate_1 (w
, 1);
9069 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9070 last_arrow_string
= Voverlay_arrow_string
;
9072 if (frame_up_to_date_hook
!= 0)
9073 frame_up_to_date_hook (sf
);
9076 update_mode_lines
= 0;
9077 windows_or_buffers_changed
= 0;
9078 cursor_type_changed
= 0;
9081 /* Start SIGIO interrupts coming again. Having them off during the
9082 code above makes it less likely one will discard output, but not
9083 impossible, since there might be stuff in the system buffer here.
9084 But it is much hairier to try to do anything about that. */
9085 if (interrupt_input
)
9089 /* If a frame has become visible which was not before, redisplay
9090 again, so that we display it. Expose events for such a frame
9091 (which it gets when becoming visible) don't call the parts of
9092 redisplay constructing glyphs, so simply exposing a frame won't
9093 display anything in this case. So, we have to display these
9094 frames here explicitly. */
9097 Lisp_Object tail
, frame
;
9100 FOR_EACH_FRAME (tail
, frame
)
9102 int this_is_visible
= 0;
9104 if (XFRAME (frame
)->visible
)
9105 this_is_visible
= 1;
9106 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9107 if (XFRAME (frame
)->visible
)
9108 this_is_visible
= 1;
9110 if (this_is_visible
)
9114 if (new_count
!= number_of_visible_frames
)
9115 windows_or_buffers_changed
++;
9118 /* Change frame size now if a change is pending. */
9119 do_pending_window_change (1);
9121 /* If we just did a pending size change, or have additional
9122 visible frames, redisplay again. */
9123 if (windows_or_buffers_changed
&& !pause
)
9128 unbind_to (count
, Qnil
);
9132 /* Redisplay, but leave alone any recent echo area message unless
9133 another message has been requested in its place.
9135 This is useful in situations where you need to redisplay but no
9136 user action has occurred, making it inappropriate for the message
9137 area to be cleared. See tracking_off and
9138 wait_reading_process_input for examples of these situations.
9140 FROM_WHERE is an integer saying from where this function was
9141 called. This is useful for debugging. */
9144 redisplay_preserve_echo_area (from_where
)
9147 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9149 if (!NILP (echo_area_buffer
[1]))
9151 /* We have a previously displayed message, but no current
9152 message. Redisplay the previous message. */
9153 display_last_displayed_message_p
= 1;
9154 redisplay_internal (1);
9155 display_last_displayed_message_p
= 0;
9158 redisplay_internal (1);
9162 /* Function registered with record_unwind_protect in
9163 redisplay_internal. Clears the flag indicating that a redisplay is
9167 unwind_redisplay (old_redisplaying_p
)
9168 Lisp_Object old_redisplaying_p
;
9170 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9175 /* Mark the display of window W as accurate or inaccurate. If
9176 ACCURATE_P is non-zero mark display of W as accurate. If
9177 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9178 redisplay_internal is called. */
9181 mark_window_display_accurate_1 (w
, accurate_p
)
9185 if (BUFFERP (w
->buffer
))
9187 struct buffer
*b
= XBUFFER (w
->buffer
);
9190 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9191 w
->last_overlay_modified
9192 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9194 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9198 b
->clip_changed
= 0;
9199 b
->prevent_redisplay_optimizations_p
= 0;
9201 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9202 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9203 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9204 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9206 w
->current_matrix
->buffer
= b
;
9207 w
->current_matrix
->begv
= BUF_BEGV (b
);
9208 w
->current_matrix
->zv
= BUF_ZV (b
);
9210 w
->last_cursor
= w
->cursor
;
9211 w
->last_cursor_off_p
= w
->cursor_off_p
;
9213 if (w
== XWINDOW (selected_window
))
9214 w
->last_point
= make_number (BUF_PT (b
));
9216 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9222 w
->window_end_valid
= w
->buffer
;
9223 #if 0 /* This is incorrect with variable-height lines. */
9224 xassert (XINT (w
->window_end_vpos
)
9226 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9228 w
->update_mode_line
= Qnil
;
9233 /* Mark the display of windows in the window tree rooted at WINDOW as
9234 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9235 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9236 be redisplayed the next time redisplay_internal is called. */
9239 mark_window_display_accurate (window
, accurate_p
)
9245 for (; !NILP (window
); window
= w
->next
)
9247 w
= XWINDOW (window
);
9248 mark_window_display_accurate_1 (w
, accurate_p
);
9250 if (!NILP (w
->vchild
))
9251 mark_window_display_accurate (w
->vchild
, accurate_p
);
9252 if (!NILP (w
->hchild
))
9253 mark_window_display_accurate (w
->hchild
, accurate_p
);
9258 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9259 last_arrow_string
= Voverlay_arrow_string
;
9263 /* Force a thorough redisplay the next time by setting
9264 last_arrow_position and last_arrow_string to t, which is
9265 unequal to any useful value of Voverlay_arrow_... */
9266 last_arrow_position
= Qt
;
9267 last_arrow_string
= Qt
;
9272 /* Return value in display table DP (Lisp_Char_Table *) for character
9273 C. Since a display table doesn't have any parent, we don't have to
9274 follow parent. Do not call this function directly but use the
9275 macro DISP_CHAR_VECTOR. */
9278 disp_char_vector (dp
, c
)
9279 struct Lisp_Char_Table
*dp
;
9285 if (SINGLE_BYTE_CHAR_P (c
))
9286 return (dp
->contents
[c
]);
9288 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9291 else if (code
[2] < 32)
9294 /* Here, the possible range of code[0] (== charset ID) is
9295 128..max_charset. Since the top level char table contains data
9296 for multibyte characters after 256th element, we must increment
9297 code[0] by 128 to get a correct index. */
9299 code
[3] = -1; /* anchor */
9301 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9303 val
= dp
->contents
[code
[i
]];
9304 if (!SUB_CHAR_TABLE_P (val
))
9305 return (NILP (val
) ? dp
->defalt
: val
);
9308 /* Here, val is a sub char table. We return the default value of
9310 return (dp
->defalt
);
9315 /***********************************************************************
9317 ***********************************************************************/
9319 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9322 redisplay_windows (window
)
9325 while (!NILP (window
))
9327 struct window
*w
= XWINDOW (window
);
9329 if (!NILP (w
->hchild
))
9330 redisplay_windows (w
->hchild
);
9331 else if (!NILP (w
->vchild
))
9332 redisplay_windows (w
->vchild
);
9335 displayed_buffer
= XBUFFER (w
->buffer
);
9336 /* Use list_of_error, not Qerror, so that
9337 we catch only errors and don't run the debugger. */
9338 internal_condition_case_1 (redisplay_window_0
, window
,
9340 redisplay_window_error
);
9348 redisplay_window_error ()
9350 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9355 redisplay_window_0 (window
)
9358 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9359 redisplay_window (window
, 0);
9364 redisplay_window_1 (window
)
9367 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9368 redisplay_window (window
, 1);
9372 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9373 DELTA is the number of bytes by which positions recorded in ROW
9374 differ from current buffer positions. */
9377 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9379 struct glyph_row
*row
;
9380 struct glyph_matrix
*matrix
;
9381 int delta
, delta_bytes
, dy
, dvpos
;
9383 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9384 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9386 int pt_old
= PT
- delta
;
9388 /* Skip over glyphs not having an object at the start of the row.
9389 These are special glyphs like truncation marks on terminal
9391 if (row
->displays_text_p
)
9393 && INTEGERP (glyph
->object
)
9394 && glyph
->charpos
< 0)
9396 x
+= glyph
->pixel_width
;
9401 && !INTEGERP (glyph
->object
)
9402 && (!BUFFERP (glyph
->object
)
9403 || glyph
->charpos
< pt_old
))
9405 x
+= glyph
->pixel_width
;
9409 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9411 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9412 w
->cursor
.y
= row
->y
+ dy
;
9414 if (w
== XWINDOW (selected_window
))
9416 if (!row
->continued_p
9417 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9420 this_line_buffer
= XBUFFER (w
->buffer
);
9422 CHARPOS (this_line_start_pos
)
9423 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9424 BYTEPOS (this_line_start_pos
)
9425 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9427 CHARPOS (this_line_end_pos
)
9428 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9429 BYTEPOS (this_line_end_pos
)
9430 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9432 this_line_y
= w
->cursor
.y
;
9433 this_line_pixel_height
= row
->height
;
9434 this_line_vpos
= w
->cursor
.vpos
;
9435 this_line_start_x
= row
->x
;
9438 CHARPOS (this_line_start_pos
) = 0;
9443 /* Run window scroll functions, if any, for WINDOW with new window
9444 start STARTP. Sets the window start of WINDOW to that position.
9446 We assume that the window's buffer is really current. */
9448 static INLINE
struct text_pos
9449 run_window_scroll_functions (window
, startp
)
9451 struct text_pos startp
;
9453 struct window
*w
= XWINDOW (window
);
9454 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9456 if (current_buffer
!= XBUFFER (w
->buffer
))
9459 if (!NILP (Vwindow_scroll_functions
))
9461 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9462 make_number (CHARPOS (startp
)));
9463 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9464 /* In case the hook functions switch buffers. */
9465 if (current_buffer
!= XBUFFER (w
->buffer
))
9466 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9473 /* Modify the desired matrix of window W and W->vscroll so that the
9474 line containing the cursor is fully visible.
9475 A value of 1 means there is nothing to be done or we did it.
9476 A value of 0 causes redisplay. */
9479 make_cursor_line_fully_visible (w
)
9482 struct glyph_matrix
*matrix
;
9483 struct glyph_row
*row
;
9486 /* It's not always possible to find the cursor, e.g, when a window
9487 is full of overlay strings. Don't do anything in that case. */
9488 if (w
->cursor
.vpos
< 0)
9491 matrix
= w
->desired_matrix
;
9492 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9494 /* If the cursor row is not partially visible, there's nothing to do. */
9495 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9498 /* If the row the cursor is in is taller than the window's height,
9499 it's not clear what to do, so do nothing. */
9500 window_height
= window_box_height (w
);
9501 if (row
->height
>= window_height
)
9504 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9506 int dy
= row
->height
- row
->visible_height
;
9509 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9511 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9513 int dy
= - (row
->height
- row
->visible_height
);
9516 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9519 /* When we change the cursor y-position of the selected window,
9520 change this_line_y as well so that the display optimization for
9521 the cursor line of the selected window in redisplay_internal uses
9522 the correct y-position. */
9523 if (w
== XWINDOW (selected_window
))
9524 this_line_y
= w
->cursor
.y
;
9526 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9527 redisplay with larger matrices. */
9528 if (matrix
->nrows
< required_matrix_height (w
))
9530 fonts_changed_p
= 1;
9538 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9539 non-zero means only WINDOW is redisplayed in redisplay_internal.
9540 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9541 in redisplay_window to bring a partially visible line into view in
9542 the case that only the cursor has moved.
9546 1 if scrolling succeeded
9548 0 if scrolling didn't find point.
9550 -1 if new fonts have been loaded so that we must interrupt
9551 redisplay, adjust glyph matrices, and try again. */
9557 SCROLLING_NEED_LARGER_MATRICES
9561 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9562 scroll_step
, temp_scroll_step
)
9564 int just_this_one_p
;
9565 EMACS_INT scroll_conservatively
, scroll_step
;
9566 int temp_scroll_step
;
9568 struct window
*w
= XWINDOW (window
);
9569 struct frame
*f
= XFRAME (w
->frame
);
9570 struct text_pos scroll_margin_pos
;
9571 struct text_pos pos
;
9572 struct text_pos startp
;
9574 Lisp_Object window_end
;
9575 int this_scroll_margin
;
9579 int amount_to_scroll
= 0;
9580 Lisp_Object aggressive
;
9584 debug_method_add (w
, "try_scrolling");
9587 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9589 /* Compute scroll margin height in pixels. We scroll when point is
9590 within this distance from the top or bottom of the window. */
9591 if (scroll_margin
> 0)
9593 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9594 this_scroll_margin
*= CANON_Y_UNIT (f
);
9597 this_scroll_margin
= 0;
9599 /* Compute how much we should try to scroll maximally to bring point
9601 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9602 scroll_max
= max (scroll_step
,
9603 max (scroll_conservatively
, temp_scroll_step
));
9604 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9605 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9606 /* We're trying to scroll because of aggressive scrolling
9607 but no scroll_step is set. Choose an arbitrary one. Maybe
9608 there should be a variable for this. */
9612 scroll_max
*= CANON_Y_UNIT (f
);
9614 /* Decide whether we have to scroll down. Start at the window end
9615 and move this_scroll_margin up to find the position of the scroll
9617 window_end
= Fwindow_end (window
, Qt
);
9618 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9619 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9620 if (this_scroll_margin
)
9622 start_display (&it
, w
, scroll_margin_pos
);
9623 move_it_vertically (&it
, - this_scroll_margin
);
9624 scroll_margin_pos
= it
.current
.pos
;
9627 if (PT
>= CHARPOS (scroll_margin_pos
))
9631 /* Point is in the scroll margin at the bottom of the window, or
9632 below. Compute a new window start that makes point visible. */
9634 /* Compute the distance from the scroll margin to PT.
9635 Give up if the distance is greater than scroll_max. */
9636 start_display (&it
, w
, scroll_margin_pos
);
9638 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9639 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9641 /* To make point visible, we have to move the window start
9642 down so that the line the cursor is in is visible, which
9643 means we have to add in the height of the cursor line. */
9644 dy
= line_bottom_y (&it
) - y0
;
9646 if (dy
> scroll_max
)
9647 return SCROLLING_FAILED
;
9649 /* Move the window start down. If scrolling conservatively,
9650 move it just enough down to make point visible. If
9651 scroll_step is set, move it down by scroll_step. */
9652 start_display (&it
, w
, startp
);
9654 if (scroll_conservatively
)
9656 = max (max (dy
, CANON_Y_UNIT (f
)),
9657 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9658 else if (scroll_step
|| temp_scroll_step
)
9659 amount_to_scroll
= scroll_max
;
9662 aggressive
= current_buffer
->scroll_up_aggressively
;
9663 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9664 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9665 if (NUMBERP (aggressive
))
9666 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9669 if (amount_to_scroll
<= 0)
9670 return SCROLLING_FAILED
;
9672 move_it_vertically (&it
, amount_to_scroll
);
9673 startp
= it
.current
.pos
;
9677 /* See if point is inside the scroll margin at the top of the
9679 scroll_margin_pos
= startp
;
9680 if (this_scroll_margin
)
9682 start_display (&it
, w
, startp
);
9683 move_it_vertically (&it
, this_scroll_margin
);
9684 scroll_margin_pos
= it
.current
.pos
;
9687 if (PT
< CHARPOS (scroll_margin_pos
))
9689 /* Point is in the scroll margin at the top of the window or
9690 above what is displayed in the window. */
9693 /* Compute the vertical distance from PT to the scroll
9694 margin position. Give up if distance is greater than
9696 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9697 start_display (&it
, w
, pos
);
9699 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9700 it
.last_visible_y
, -1,
9701 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9702 dy
= it
.current_y
- y0
;
9703 if (dy
> scroll_max
)
9704 return SCROLLING_FAILED
;
9706 /* Compute new window start. */
9707 start_display (&it
, w
, startp
);
9709 if (scroll_conservatively
)
9711 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9712 else if (scroll_step
|| temp_scroll_step
)
9713 amount_to_scroll
= scroll_max
;
9716 aggressive
= current_buffer
->scroll_down_aggressively
;
9717 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9718 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9719 if (NUMBERP (aggressive
))
9720 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9723 if (amount_to_scroll
<= 0)
9724 return SCROLLING_FAILED
;
9726 move_it_vertically (&it
, - amount_to_scroll
);
9727 startp
= it
.current
.pos
;
9731 /* Run window scroll functions. */
9732 startp
= run_window_scroll_functions (window
, startp
);
9734 /* Display the window. Give up if new fonts are loaded, or if point
9736 if (!try_window (window
, startp
))
9737 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9738 else if (w
->cursor
.vpos
< 0)
9740 clear_glyph_matrix (w
->desired_matrix
);
9741 rc
= SCROLLING_FAILED
;
9745 /* Maybe forget recorded base line for line number display. */
9746 if (!just_this_one_p
9747 || current_buffer
->clip_changed
9748 || BEG_UNCHANGED
< CHARPOS (startp
))
9749 w
->base_line_number
= Qnil
;
9751 /* If cursor ends up on a partially visible line, shift display
9752 lines up or down. If that fails because we need larger
9753 matrices, give up. */
9754 if (!make_cursor_line_fully_visible (w
))
9755 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9757 rc
= SCROLLING_SUCCESS
;
9764 /* Compute a suitable window start for window W if display of W starts
9765 on a continuation line. Value is non-zero if a new window start
9768 The new window start will be computed, based on W's width, starting
9769 from the start of the continued line. It is the start of the
9770 screen line with the minimum distance from the old start W->start. */
9773 compute_window_start_on_continuation_line (w
)
9776 struct text_pos pos
, start_pos
;
9777 int window_start_changed_p
= 0;
9779 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9781 /* If window start is on a continuation line... Window start may be
9782 < BEGV in case there's invisible text at the start of the
9783 buffer (M-x rmail, for example). */
9784 if (CHARPOS (start_pos
) > BEGV
9785 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9788 struct glyph_row
*row
;
9790 /* Handle the case that the window start is out of range. */
9791 if (CHARPOS (start_pos
) < BEGV
)
9792 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9793 else if (CHARPOS (start_pos
) > ZV
)
9794 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9796 /* Find the start of the continued line. This should be fast
9797 because scan_buffer is fast (newline cache). */
9798 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9799 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9800 row
, DEFAULT_FACE_ID
);
9801 reseat_at_previous_visible_line_start (&it
);
9803 /* If the line start is "too far" away from the window start,
9804 say it takes too much time to compute a new window start. */
9805 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9806 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9808 int min_distance
, distance
;
9810 /* Move forward by display lines to find the new window
9811 start. If window width was enlarged, the new start can
9812 be expected to be > the old start. If window width was
9813 decreased, the new window start will be < the old start.
9814 So, we're looking for the display line start with the
9815 minimum distance from the old window start. */
9816 pos
= it
.current
.pos
;
9817 min_distance
= INFINITY
;
9818 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9819 distance
< min_distance
)
9821 min_distance
= distance
;
9822 pos
= it
.current
.pos
;
9823 move_it_by_lines (&it
, 1, 0);
9826 /* Set the window start there. */
9827 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9828 window_start_changed_p
= 1;
9832 return window_start_changed_p
;
9836 /* Try cursor movement in case text has not changed in window WINDOW,
9837 with window start STARTP. Value is
9839 CURSOR_MOVEMENT_SUCCESS if successful
9841 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9843 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9844 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9845 we want to scroll as if scroll-step were set to 1. See the code.
9847 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9848 which case we have to abort this redisplay, and adjust matrices
9853 CURSOR_MOVEMENT_SUCCESS
,
9854 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9855 CURSOR_MOVEMENT_MUST_SCROLL
,
9856 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9860 try_cursor_movement (window
, startp
, scroll_step
)
9862 struct text_pos startp
;
9865 struct window
*w
= XWINDOW (window
);
9866 struct frame
*f
= XFRAME (w
->frame
);
9867 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9870 if (inhibit_try_cursor_movement
)
9874 /* Handle case where text has not changed, only point, and it has
9875 not moved off the frame. */
9876 if (/* Point may be in this window. */
9877 PT
>= CHARPOS (startp
)
9878 /* Selective display hasn't changed. */
9879 && !current_buffer
->clip_changed
9880 /* Function force-mode-line-update is used to force a thorough
9881 redisplay. It sets either windows_or_buffers_changed or
9882 update_mode_lines. So don't take a shortcut here for these
9884 && !update_mode_lines
9885 && !windows_or_buffers_changed
9886 && !cursor_type_changed
9887 /* Can't use this case if highlighting a region. When a
9888 region exists, cursor movement has to do more than just
9890 && !(!NILP (Vtransient_mark_mode
)
9891 && !NILP (current_buffer
->mark_active
))
9892 && NILP (w
->region_showing
)
9893 && NILP (Vshow_trailing_whitespace
)
9894 /* Right after splitting windows, last_point may be nil. */
9895 && INTEGERP (w
->last_point
)
9896 /* This code is not used for mini-buffer for the sake of the case
9897 of redisplaying to replace an echo area message; since in
9898 that case the mini-buffer contents per se are usually
9899 unchanged. This code is of no real use in the mini-buffer
9900 since the handling of this_line_start_pos, etc., in redisplay
9901 handles the same cases. */
9902 && !EQ (window
, minibuf_window
)
9903 /* When splitting windows or for new windows, it happens that
9904 redisplay is called with a nil window_end_vpos or one being
9905 larger than the window. This should really be fixed in
9906 window.c. I don't have this on my list, now, so we do
9907 approximately the same as the old redisplay code. --gerd. */
9908 && INTEGERP (w
->window_end_vpos
)
9909 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9910 && (FRAME_WINDOW_P (f
)
9911 || !MARKERP (Voverlay_arrow_position
)
9912 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9914 int this_scroll_margin
;
9915 struct glyph_row
*row
= NULL
;
9918 debug_method_add (w
, "cursor movement");
9921 /* Scroll if point within this distance from the top or bottom
9922 of the window. This is a pixel value. */
9923 this_scroll_margin
= max (0, scroll_margin
);
9924 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9925 this_scroll_margin
*= CANON_Y_UNIT (f
);
9927 /* Start with the row the cursor was displayed during the last
9928 not paused redisplay. Give up if that row is not valid. */
9929 if (w
->last_cursor
.vpos
< 0
9930 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9931 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9934 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9935 if (row
->mode_line_p
)
9937 if (!row
->enabled_p
)
9938 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9941 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
9944 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9946 if (PT
> XFASTINT (w
->last_point
))
9948 /* Point has moved forward. */
9949 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9950 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9952 xassert (row
->enabled_p
);
9956 /* The end position of a row equals the start position
9957 of the next row. If PT is there, we would rather
9958 display it in the next line. */
9959 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9960 && MATRIX_ROW_END_CHARPOS (row
) == PT
9961 && !cursor_row_p (w
, row
))
9964 /* If within the scroll margin, scroll. Note that
9965 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9966 the next line would be drawn, and that
9967 this_scroll_margin can be zero. */
9968 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9969 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9970 /* Line is completely visible last line in window
9971 and PT is to be set in the next line. */
9972 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9973 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9974 && !row
->ends_at_zv_p
9975 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9978 else if (PT
< XFASTINT (w
->last_point
))
9980 /* Cursor has to be moved backward. Note that PT >=
9981 CHARPOS (startp) because of the outer
9983 while (!row
->mode_line_p
9984 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9985 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9986 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9987 && (row
->y
> this_scroll_margin
9988 || CHARPOS (startp
) == BEGV
))
9990 xassert (row
->enabled_p
);
9994 /* Consider the following case: Window starts at BEGV,
9995 there is invisible, intangible text at BEGV, so that
9996 display starts at some point START > BEGV. It can
9997 happen that we are called with PT somewhere between
9998 BEGV and START. Try to handle that case. */
9999 if (row
< w
->current_matrix
->rows
10000 || row
->mode_line_p
)
10002 row
= w
->current_matrix
->rows
;
10003 if (row
->mode_line_p
)
10007 /* Due to newlines in overlay strings, we may have to
10008 skip forward over overlay strings. */
10009 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10010 && MATRIX_ROW_END_CHARPOS (row
) == PT
10011 && !cursor_row_p (w
, row
))
10014 /* If within the scroll margin, scroll. */
10015 if (row
->y
< this_scroll_margin
10016 && CHARPOS (startp
) != BEGV
)
10020 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
10021 || PT
> MATRIX_ROW_END_CHARPOS (row
))
10023 /* if PT is not in the glyph row, give up. */
10024 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10026 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10028 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
10029 && !row
->ends_at_zv_p
10030 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
10031 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10032 else if (row
->height
> window_box_height (w
))
10034 /* If we end up in a partially visible line, let's
10035 make it fully visible, except when it's taller
10036 than the window, in which case we can't do much
10039 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10043 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10044 try_window (window
, startp
);
10045 if (!make_cursor_line_fully_visible (w
))
10046 rc
= CURSOR_MOVEMENT_NEED_LARGER_MATRICES
;
10048 rc
= CURSOR_MOVEMENT_SUCCESS
;
10052 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10055 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10056 rc
= CURSOR_MOVEMENT_SUCCESS
;
10065 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10066 selected_window is redisplayed. */
10069 redisplay_window (window
, just_this_one_p
)
10070 Lisp_Object window
;
10071 int just_this_one_p
;
10073 struct window
*w
= XWINDOW (window
);
10074 struct frame
*f
= XFRAME (w
->frame
);
10075 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10076 struct buffer
*old
= current_buffer
;
10077 struct text_pos lpoint
, opoint
, startp
;
10078 int update_mode_line
;
10081 /* Record it now because it's overwritten. */
10082 int current_matrix_up_to_date_p
= 0;
10083 int temp_scroll_step
= 0;
10084 int count
= BINDING_STACK_SIZE ();
10087 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10090 /* W must be a leaf window here. */
10091 xassert (!NILP (w
->buffer
));
10093 *w
->desired_matrix
->method
= 0;
10096 specbind (Qinhibit_point_motion_hooks
, Qt
);
10098 reconsider_clip_changes (w
, buffer
);
10100 /* Has the mode line to be updated? */
10101 update_mode_line
= (!NILP (w
->update_mode_line
)
10102 || update_mode_lines
10103 || buffer
->clip_changed
);
10105 if (MINI_WINDOW_P (w
))
10107 if (w
== XWINDOW (echo_area_window
)
10108 && !NILP (echo_area_buffer
[0]))
10110 if (update_mode_line
)
10111 /* We may have to update a tty frame's menu bar or a
10112 tool-bar. Example `M-x C-h C-h C-g'. */
10113 goto finish_menu_bars
;
10115 /* We've already displayed the echo area glyphs in this window. */
10116 goto finish_scroll_bars
;
10118 else if (w
!= XWINDOW (minibuf_window
))
10120 /* W is a mini-buffer window, but it's not the currently
10121 active one, so clear it. */
10122 int yb
= window_text_bottom_y (w
);
10123 struct glyph_row
*row
;
10126 for (y
= 0, row
= w
->desired_matrix
->rows
;
10128 y
+= row
->height
, ++row
)
10129 blank_row (w
, row
, y
);
10130 goto finish_scroll_bars
;
10133 clear_glyph_matrix (w
->desired_matrix
);
10136 /* Otherwise set up data on this window; select its buffer and point
10138 /* Really select the buffer, for the sake of buffer-local
10140 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10141 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10143 current_matrix_up_to_date_p
10144 = (!NILP (w
->window_end_valid
)
10145 && !current_buffer
->clip_changed
10146 && XFASTINT (w
->last_modified
) >= MODIFF
10147 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10149 /* When windows_or_buffers_changed is non-zero, we can't rely on
10150 the window end being valid, so set it to nil there. */
10151 if (windows_or_buffers_changed
)
10153 /* If window starts on a continuation line, maybe adjust the
10154 window start in case the window's width changed. */
10155 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10156 compute_window_start_on_continuation_line (w
);
10158 w
->window_end_valid
= Qnil
;
10161 /* Some sanity checks. */
10162 CHECK_WINDOW_END (w
);
10163 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10165 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10168 /* If %c is in mode line, update it if needed. */
10169 if (!NILP (w
->column_number_displayed
)
10170 /* This alternative quickly identifies a common case
10171 where no change is needed. */
10172 && !(PT
== XFASTINT (w
->last_point
)
10173 && XFASTINT (w
->last_modified
) >= MODIFF
10174 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10175 && (XFASTINT (w
->column_number_displayed
)
10176 != (int) current_column ())) /* iftc */
10177 update_mode_line
= 1;
10179 /* Count number of windows showing the selected buffer. An indirect
10180 buffer counts as its base buffer. */
10181 if (!just_this_one_p
)
10183 struct buffer
*current_base
, *window_base
;
10184 current_base
= current_buffer
;
10185 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10186 if (current_base
->base_buffer
)
10187 current_base
= current_base
->base_buffer
;
10188 if (window_base
->base_buffer
)
10189 window_base
= window_base
->base_buffer
;
10190 if (current_base
== window_base
)
10194 /* Point refers normally to the selected window. For any other
10195 window, set up appropriate value. */
10196 if (!EQ (window
, selected_window
))
10198 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10199 int new_pt_byte
= marker_byte_position (w
->pointm
);
10203 new_pt_byte
= BEGV_BYTE
;
10204 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10206 else if (new_pt
> (ZV
- 1))
10209 new_pt_byte
= ZV_BYTE
;
10210 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10213 /* We don't use SET_PT so that the point-motion hooks don't run. */
10214 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10217 /* If any of the character widths specified in the display table
10218 have changed, invalidate the width run cache. It's true that
10219 this may be a bit late to catch such changes, but the rest of
10220 redisplay goes (non-fatally) haywire when the display table is
10221 changed, so why should we worry about doing any better? */
10222 if (current_buffer
->width_run_cache
)
10224 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10226 if (! disptab_matches_widthtab (disptab
,
10227 XVECTOR (current_buffer
->width_table
)))
10229 invalidate_region_cache (current_buffer
,
10230 current_buffer
->width_run_cache
,
10232 recompute_width_table (current_buffer
, disptab
);
10236 /* If window-start is screwed up, choose a new one. */
10237 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10240 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10242 /* If someone specified a new starting point but did not insist,
10243 check whether it can be used. */
10244 if (!NILP (w
->optional_new_start
)
10245 && CHARPOS (startp
) >= BEGV
10246 && CHARPOS (startp
) <= ZV
)
10248 w
->optional_new_start
= Qnil
;
10249 start_display (&it
, w
, startp
);
10250 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10251 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10252 if (IT_CHARPOS (it
) == PT
)
10253 w
->force_start
= Qt
;
10256 /* Handle case where place to start displaying has been specified,
10257 unless the specified location is outside the accessible range. */
10258 if (!NILP (w
->force_start
)
10259 || w
->frozen_window_start_p
)
10261 w
->force_start
= Qnil
;
10263 w
->window_end_valid
= Qnil
;
10265 /* Forget any recorded base line for line number display. */
10266 if (!current_matrix_up_to_date_p
10267 || current_buffer
->clip_changed
)
10268 w
->base_line_number
= Qnil
;
10270 /* Redisplay the mode line. Select the buffer properly for that.
10271 Also, run the hook window-scroll-functions
10272 because we have scrolled. */
10273 /* Note, we do this after clearing force_start because
10274 if there's an error, it is better to forget about force_start
10275 than to get into an infinite loop calling the hook functions
10276 and having them get more errors. */
10277 if (!update_mode_line
10278 || ! NILP (Vwindow_scroll_functions
))
10280 update_mode_line
= 1;
10281 w
->update_mode_line
= Qt
;
10282 startp
= run_window_scroll_functions (window
, startp
);
10285 w
->last_modified
= make_number (0);
10286 w
->last_overlay_modified
= make_number (0);
10287 if (CHARPOS (startp
) < BEGV
)
10288 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10289 else if (CHARPOS (startp
) > ZV
)
10290 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10292 /* Redisplay, then check if cursor has been set during the
10293 redisplay. Give up if new fonts were loaded. */
10294 if (!try_window (window
, startp
))
10296 w
->force_start
= Qt
;
10297 clear_glyph_matrix (w
->desired_matrix
);
10298 goto finish_scroll_bars
;
10301 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10303 /* If point does not appear, try to move point so it does
10304 appear. The desired matrix has been built above, so we
10305 can use it here. */
10307 struct glyph_row
*row
;
10309 window_height
= window_box_height (w
) / 2;
10310 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10311 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10314 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10315 MATRIX_ROW_START_BYTEPOS (row
));
10317 if (w
!= XWINDOW (selected_window
))
10318 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10319 else if (current_buffer
== old
)
10320 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10322 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10324 /* If we are highlighting the region, then we just changed
10325 the region, so redisplay to show it. */
10326 if (!NILP (Vtransient_mark_mode
)
10327 && !NILP (current_buffer
->mark_active
))
10329 clear_glyph_matrix (w
->desired_matrix
);
10330 if (!try_window (window
, startp
))
10331 goto need_larger_matrices
;
10335 if (!make_cursor_line_fully_visible (w
))
10336 goto need_larger_matrices
;
10338 debug_method_add (w
, "forced window start");
10343 /* Handle case where text has not changed, only point, and it has
10344 not moved off the frame. */
10345 if (current_matrix_up_to_date_p
10346 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10347 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10351 case CURSOR_MOVEMENT_SUCCESS
:
10354 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10355 goto need_larger_matrices
;
10357 case CURSOR_MOVEMENT_MUST_SCROLL
:
10358 goto try_to_scroll
;
10364 /* If current starting point was originally the beginning of a line
10365 but no longer is, find a new starting point. */
10366 else if (!NILP (w
->start_at_line_beg
)
10367 && !(CHARPOS (startp
) <= BEGV
10368 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10371 debug_method_add (w
, "recenter 1");
10376 /* Try scrolling with try_window_id. Value is > 0 if update has
10377 been done, it is -1 if we know that the same window start will
10378 not work. It is 0 if unsuccessful for some other reason. */
10379 else if ((tem
= try_window_id (w
)) != 0)
10382 debug_method_add (w
, "try_window_id %d", tem
);
10385 if (fonts_changed_p
)
10386 goto need_larger_matrices
;
10390 /* Otherwise try_window_id has returned -1 which means that we
10391 don't want the alternative below this comment to execute. */
10393 else if (CHARPOS (startp
) >= BEGV
10394 && CHARPOS (startp
) <= ZV
10395 && PT
>= CHARPOS (startp
)
10396 && (CHARPOS (startp
) < ZV
10397 /* Avoid starting at end of buffer. */
10398 || CHARPOS (startp
) == BEGV
10399 || (XFASTINT (w
->last_modified
) >= MODIFF
10400 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10403 debug_method_add (w
, "same window start");
10406 /* Try to redisplay starting at same place as before.
10407 If point has not moved off frame, accept the results. */
10408 if (!current_matrix_up_to_date_p
10409 /* Don't use try_window_reusing_current_matrix in this case
10410 because a window scroll function can have changed the
10412 || !NILP (Vwindow_scroll_functions
)
10413 || MINI_WINDOW_P (w
)
10414 || !try_window_reusing_current_matrix (w
))
10416 IF_DEBUG (debug_method_add (w
, "1"));
10417 try_window (window
, startp
);
10420 if (fonts_changed_p
)
10421 goto need_larger_matrices
;
10423 if (w
->cursor
.vpos
>= 0)
10425 if (!just_this_one_p
10426 || current_buffer
->clip_changed
10427 || BEG_UNCHANGED
< CHARPOS (startp
))
10428 /* Forget any recorded base line for line number display. */
10429 w
->base_line_number
= Qnil
;
10431 if (!make_cursor_line_fully_visible (w
))
10432 goto need_larger_matrices
;
10436 clear_glyph_matrix (w
->desired_matrix
);
10441 w
->last_modified
= make_number (0);
10442 w
->last_overlay_modified
= make_number (0);
10444 /* Redisplay the mode line. Select the buffer properly for that. */
10445 if (!update_mode_line
)
10447 update_mode_line
= 1;
10448 w
->update_mode_line
= Qt
;
10451 /* Try to scroll by specified few lines. */
10452 if ((scroll_conservatively
10454 || temp_scroll_step
10455 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10456 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10457 && !current_buffer
->clip_changed
10458 && CHARPOS (startp
) >= BEGV
10459 && CHARPOS (startp
) <= ZV
)
10461 /* The function returns -1 if new fonts were loaded, 1 if
10462 successful, 0 if not successful. */
10463 int rc
= try_scrolling (window
, just_this_one_p
,
10464 scroll_conservatively
,
10469 case SCROLLING_SUCCESS
:
10472 case SCROLLING_NEED_LARGER_MATRICES
:
10473 goto need_larger_matrices
;
10475 case SCROLLING_FAILED
:
10483 /* Finally, just choose place to start which centers point */
10488 debug_method_add (w
, "recenter");
10491 /* w->vscroll = 0; */
10493 /* Forget any previously recorded base line for line number display. */
10494 if (!current_matrix_up_to_date_p
10495 || current_buffer
->clip_changed
)
10496 w
->base_line_number
= Qnil
;
10498 /* Move backward half the height of the window. */
10499 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10500 it
.current_y
= it
.last_visible_y
;
10501 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10502 xassert (IT_CHARPOS (it
) >= BEGV
);
10504 /* The function move_it_vertically_backward may move over more
10505 than the specified y-distance. If it->w is small, e.g. a
10506 mini-buffer window, we may end up in front of the window's
10507 display area. Start displaying at the start of the line
10508 containing PT in this case. */
10509 if (it
.current_y
<= 0)
10511 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10512 move_it_vertically (&it
, 0);
10513 xassert (IT_CHARPOS (it
) <= PT
);
10517 it
.current_x
= it
.hpos
= 0;
10519 /* Set startp here explicitly in case that helps avoid an infinite loop
10520 in case the window-scroll-functions functions get errors. */
10521 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10523 /* Run scroll hooks. */
10524 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10526 /* Redisplay the window. */
10527 if (!current_matrix_up_to_date_p
10528 || windows_or_buffers_changed
10529 || cursor_type_changed
10530 /* Don't use try_window_reusing_current_matrix in this case
10531 because it can have changed the buffer. */
10532 || !NILP (Vwindow_scroll_functions
)
10533 || !just_this_one_p
10534 || MINI_WINDOW_P (w
)
10535 || !try_window_reusing_current_matrix (w
))
10536 try_window (window
, startp
);
10538 /* If new fonts have been loaded (due to fontsets), give up. We
10539 have to start a new redisplay since we need to re-adjust glyph
10541 if (fonts_changed_p
)
10542 goto need_larger_matrices
;
10544 /* If cursor did not appear assume that the middle of the window is
10545 in the first line of the window. Do it again with the next line.
10546 (Imagine a window of height 100, displaying two lines of height
10547 60. Moving back 50 from it->last_visible_y will end in the first
10549 if (w
->cursor
.vpos
< 0)
10551 if (!NILP (w
->window_end_valid
)
10552 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10554 clear_glyph_matrix (w
->desired_matrix
);
10555 move_it_by_lines (&it
, 1, 0);
10556 try_window (window
, it
.current
.pos
);
10558 else if (PT
< IT_CHARPOS (it
))
10560 clear_glyph_matrix (w
->desired_matrix
);
10561 move_it_by_lines (&it
, -1, 0);
10562 try_window (window
, it
.current
.pos
);
10566 /* Not much we can do about it. */
10570 /* Consider the following case: Window starts at BEGV, there is
10571 invisible, intangible text at BEGV, so that display starts at
10572 some point START > BEGV. It can happen that we are called with
10573 PT somewhere between BEGV and START. Try to handle that case. */
10574 if (w
->cursor
.vpos
< 0)
10576 struct glyph_row
*row
= w
->current_matrix
->rows
;
10577 if (row
->mode_line_p
)
10579 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10582 if (!make_cursor_line_fully_visible (w
))
10583 goto need_larger_matrices
;
10587 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10588 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10589 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10592 /* Display the mode line, if we must. */
10593 if ((update_mode_line
10594 /* If window not full width, must redo its mode line
10595 if (a) the window to its side is being redone and
10596 (b) we do a frame-based redisplay. This is a consequence
10597 of how inverted lines are drawn in frame-based redisplay. */
10598 || (!just_this_one_p
10599 && !FRAME_WINDOW_P (f
)
10600 && !WINDOW_FULL_WIDTH_P (w
))
10601 /* Line number to display. */
10602 || INTEGERP (w
->base_line_pos
)
10603 /* Column number is displayed and different from the one displayed. */
10604 || (!NILP (w
->column_number_displayed
)
10605 && (XFASTINT (w
->column_number_displayed
)
10606 != (int) current_column ()))) /* iftc */
10607 /* This means that the window has a mode line. */
10608 && (WINDOW_WANTS_MODELINE_P (w
)
10609 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10611 display_mode_lines (w
);
10613 /* If mode line height has changed, arrange for a thorough
10614 immediate redisplay using the correct mode line height. */
10615 if (WINDOW_WANTS_MODELINE_P (w
)
10616 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10618 fonts_changed_p
= 1;
10619 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10620 = DESIRED_MODE_LINE_HEIGHT (w
);
10623 /* If top line height has changed, arrange for a thorough
10624 immediate redisplay using the correct mode line height. */
10625 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10626 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10628 fonts_changed_p
= 1;
10629 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10630 = DESIRED_HEADER_LINE_HEIGHT (w
);
10633 if (fonts_changed_p
)
10634 goto need_larger_matrices
;
10637 if (!line_number_displayed
10638 && !BUFFERP (w
->base_line_pos
))
10640 w
->base_line_pos
= Qnil
;
10641 w
->base_line_number
= Qnil
;
10646 /* When we reach a frame's selected window, redo the frame's menu bar. */
10647 if (update_mode_line
10648 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10650 int redisplay_menu_p
= 0;
10652 if (FRAME_WINDOW_P (f
))
10654 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
10655 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10657 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10661 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10663 if (redisplay_menu_p
)
10664 display_menu_bar (w
);
10666 #ifdef HAVE_WINDOW_SYSTEM
10667 if (WINDOWP (f
->tool_bar_window
)
10668 && (FRAME_TOOL_BAR_LINES (f
) > 0
10669 || auto_resize_tool_bars_p
))
10670 redisplay_tool_bar (f
);
10674 need_larger_matrices
:
10676 finish_scroll_bars
:
10678 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10680 int start
, end
, whole
;
10682 /* Calculate the start and end positions for the current window.
10683 At some point, it would be nice to choose between scrollbars
10684 which reflect the whole buffer size, with special markers
10685 indicating narrowing, and scrollbars which reflect only the
10688 Note that mini-buffers sometimes aren't displaying any text. */
10689 if (!MINI_WINDOW_P (w
)
10690 || (w
== XWINDOW (minibuf_window
)
10691 && NILP (echo_area_buffer
[0])))
10694 start
= marker_position (w
->start
) - BEGV
;
10695 /* I don't think this is guaranteed to be right. For the
10696 moment, we'll pretend it is. */
10697 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10701 if (whole
< (end
- start
))
10702 whole
= end
- start
;
10705 start
= end
= whole
= 0;
10707 /* Indicate what this scroll bar ought to be displaying now. */
10708 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10710 /* Note that we actually used the scroll bar attached to this
10711 window, so it shouldn't be deleted at the end of redisplay. */
10712 redeem_scroll_bar_hook (w
);
10715 /* Restore current_buffer and value of point in it. */
10716 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10717 set_buffer_internal_1 (old
);
10718 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10720 unbind_to (count
, Qnil
);
10724 /* Build the complete desired matrix of WINDOW with a window start
10725 buffer position POS. Value is non-zero if successful. It is zero
10726 if fonts were loaded during redisplay which makes re-adjusting
10727 glyph matrices necessary. */
10730 try_window (window
, pos
)
10731 Lisp_Object window
;
10732 struct text_pos pos
;
10734 struct window
*w
= XWINDOW (window
);
10736 struct glyph_row
*last_text_row
= NULL
;
10738 /* Make POS the new window start. */
10739 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10741 /* Mark cursor position as unknown. No overlay arrow seen. */
10742 w
->cursor
.vpos
= -1;
10743 overlay_arrow_seen
= 0;
10745 /* Initialize iterator and info to start at POS. */
10746 start_display (&it
, w
, pos
);
10748 /* Display all lines of W. */
10749 while (it
.current_y
< it
.last_visible_y
)
10751 if (display_line (&it
))
10752 last_text_row
= it
.glyph_row
- 1;
10753 if (fonts_changed_p
)
10757 /* If bottom moved off end of frame, change mode line percentage. */
10758 if (XFASTINT (w
->window_end_pos
) <= 0
10759 && Z
!= IT_CHARPOS (it
))
10760 w
->update_mode_line
= Qt
;
10762 /* Set window_end_pos to the offset of the last character displayed
10763 on the window from the end of current_buffer. Set
10764 window_end_vpos to its row number. */
10767 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10768 w
->window_end_bytepos
10769 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10771 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10773 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10774 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10775 ->displays_text_p
);
10779 w
->window_end_bytepos
= 0;
10780 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10783 /* But that is not valid info until redisplay finishes. */
10784 w
->window_end_valid
= Qnil
;
10790 /************************************************************************
10791 Window redisplay reusing current matrix when buffer has not changed
10792 ************************************************************************/
10794 /* Try redisplay of window W showing an unchanged buffer with a
10795 different window start than the last time it was displayed by
10796 reusing its current matrix. Value is non-zero if successful.
10797 W->start is the new window start. */
10800 try_window_reusing_current_matrix (w
)
10803 struct frame
*f
= XFRAME (w
->frame
);
10804 struct glyph_row
*row
, *bottom_row
;
10807 struct text_pos start
, new_start
;
10808 int nrows_scrolled
, i
;
10809 struct glyph_row
*last_text_row
;
10810 struct glyph_row
*last_reused_text_row
;
10811 struct glyph_row
*start_row
;
10812 int start_vpos
, min_y
, max_y
;
10815 if (inhibit_try_window_reusing
)
10819 if (/* This function doesn't handle terminal frames. */
10820 !FRAME_WINDOW_P (f
)
10821 /* Don't try to reuse the display if windows have been split
10823 || windows_or_buffers_changed
10824 || cursor_type_changed
)
10827 /* Can't do this if region may have changed. */
10828 if ((!NILP (Vtransient_mark_mode
)
10829 && !NILP (current_buffer
->mark_active
))
10830 || !NILP (w
->region_showing
)
10831 || !NILP (Vshow_trailing_whitespace
))
10834 /* If top-line visibility has changed, give up. */
10835 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10836 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10839 /* Give up if old or new display is scrolled vertically. We could
10840 make this function handle this, but right now it doesn't. */
10841 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10842 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10845 /* The variable new_start now holds the new window start. The old
10846 start `start' can be determined from the current matrix. */
10847 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10848 start
= start_row
->start
.pos
;
10849 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10851 /* Clear the desired matrix for the display below. */
10852 clear_glyph_matrix (w
->desired_matrix
);
10854 if (CHARPOS (new_start
) <= CHARPOS (start
))
10858 /* Don't use this method if the display starts with an ellipsis
10859 displayed for invisible text. It's not easy to handle that case
10860 below, and it's certainly not worth the effort since this is
10861 not a frequent case. */
10862 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10865 IF_DEBUG (debug_method_add (w
, "twu1"));
10867 /* Display up to a row that can be reused. The variable
10868 last_text_row is set to the last row displayed that displays
10869 text. Note that it.vpos == 0 if or if not there is a
10870 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10871 start_display (&it
, w
, new_start
);
10872 first_row_y
= it
.current_y
;
10873 w
->cursor
.vpos
= -1;
10874 last_text_row
= last_reused_text_row
= NULL
;
10876 while (it
.current_y
< it
.last_visible_y
10877 && IT_CHARPOS (it
) < CHARPOS (start
)
10878 && !fonts_changed_p
)
10879 if (display_line (&it
))
10880 last_text_row
= it
.glyph_row
- 1;
10882 /* A value of current_y < last_visible_y means that we stopped
10883 at the previous window start, which in turn means that we
10884 have at least one reusable row. */
10885 if (it
.current_y
< it
.last_visible_y
)
10887 /* IT.vpos always starts from 0; it counts text lines. */
10888 nrows_scrolled
= it
.vpos
;
10890 /* Find PT if not already found in the lines displayed. */
10891 if (w
->cursor
.vpos
< 0)
10893 int dy
= it
.current_y
- first_row_y
;
10895 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10896 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
10898 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10899 dy
, nrows_scrolled
);
10902 clear_glyph_matrix (w
->desired_matrix
);
10907 /* Scroll the display. Do it before the current matrix is
10908 changed. The problem here is that update has not yet
10909 run, i.e. part of the current matrix is not up to date.
10910 scroll_run_hook will clear the cursor, and use the
10911 current matrix to get the height of the row the cursor is
10913 run
.current_y
= first_row_y
;
10914 run
.desired_y
= it
.current_y
;
10915 run
.height
= it
.last_visible_y
- it
.current_y
;
10917 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10920 rif
->update_window_begin_hook (w
);
10921 rif
->clear_mouse_face (w
);
10922 rif
->scroll_run_hook (w
, &run
);
10923 rif
->update_window_end_hook (w
, 0, 0);
10927 /* Shift current matrix down by nrows_scrolled lines. */
10928 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10929 rotate_matrix (w
->current_matrix
,
10931 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10934 /* Disable lines that must be updated. */
10935 for (i
= 0; i
< it
.vpos
; ++i
)
10936 (start_row
+ i
)->enabled_p
= 0;
10938 /* Re-compute Y positions. */
10939 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10940 max_y
= it
.last_visible_y
;
10941 for (row
= start_row
+ nrows_scrolled
;
10945 row
->y
= it
.current_y
;
10946 row
->visible_height
= row
->height
;
10948 if (row
->y
< min_y
)
10949 row
->visible_height
-= min_y
- row
->y
;
10950 if (row
->y
+ row
->height
> max_y
)
10951 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10953 it
.current_y
+= row
->height
;
10955 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10956 last_reused_text_row
= row
;
10957 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10961 /* Disable lines in the current matrix which are now
10962 below the window. */
10963 for (++row
; row
< bottom_row
; ++row
)
10964 row
->enabled_p
= 0;
10967 /* Update window_end_pos etc.; last_reused_text_row is the last
10968 reused row from the current matrix containing text, if any.
10969 The value of last_text_row is the last displayed line
10970 containing text. */
10971 if (last_reused_text_row
)
10973 w
->window_end_bytepos
10974 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10976 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10978 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10979 w
->current_matrix
));
10981 else if (last_text_row
)
10983 w
->window_end_bytepos
10984 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10986 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10988 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10992 /* This window must be completely empty. */
10993 w
->window_end_bytepos
= 0;
10994 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10996 w
->window_end_valid
= Qnil
;
10998 /* Update hint: don't try scrolling again in update_window. */
10999 w
->desired_matrix
->no_scrolling_p
= 1;
11002 debug_method_add (w
, "try_window_reusing_current_matrix 1");
11006 else if (CHARPOS (new_start
) > CHARPOS (start
))
11008 struct glyph_row
*pt_row
, *row
;
11009 struct glyph_row
*first_reusable_row
;
11010 struct glyph_row
*first_row_to_display
;
11012 int yb
= window_text_bottom_y (w
);
11014 /* Find the row starting at new_start, if there is one. Don't
11015 reuse a partially visible line at the end. */
11016 first_reusable_row
= start_row
;
11017 while (first_reusable_row
->enabled_p
11018 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
11019 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11020 < CHARPOS (new_start
)))
11021 ++first_reusable_row
;
11023 /* Give up if there is no row to reuse. */
11024 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
11025 || !first_reusable_row
->enabled_p
11026 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11027 != CHARPOS (new_start
)))
11030 /* We can reuse fully visible rows beginning with
11031 first_reusable_row to the end of the window. Set
11032 first_row_to_display to the first row that cannot be reused.
11033 Set pt_row to the row containing point, if there is any. */
11035 for (first_row_to_display
= first_reusable_row
;
11036 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
11037 ++first_row_to_display
)
11039 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
11040 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
11041 pt_row
= first_row_to_display
;
11044 /* Start displaying at the start of first_row_to_display. */
11045 xassert (first_row_to_display
->y
< yb
);
11046 init_to_row_start (&it
, w
, first_row_to_display
);
11048 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
11050 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
11052 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11053 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11055 /* Display lines beginning with first_row_to_display in the
11056 desired matrix. Set last_text_row to the last row displayed
11057 that displays text. */
11058 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11059 if (pt_row
== NULL
)
11060 w
->cursor
.vpos
= -1;
11061 last_text_row
= NULL
;
11062 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11063 if (display_line (&it
))
11064 last_text_row
= it
.glyph_row
- 1;
11066 /* Give up If point isn't in a row displayed or reused. */
11067 if (w
->cursor
.vpos
< 0)
11069 clear_glyph_matrix (w
->desired_matrix
);
11073 /* If point is in a reused row, adjust y and vpos of the cursor
11077 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11078 w
->current_matrix
);
11079 w
->cursor
.y
-= first_reusable_row
->y
;
11082 /* Scroll the display. */
11083 run
.current_y
= first_reusable_row
->y
;
11084 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11085 run
.height
= it
.last_visible_y
- run
.current_y
;
11086 dy
= run
.current_y
- run
.desired_y
;
11090 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11092 rif
->update_window_begin_hook (w
);
11093 rif
->clear_mouse_face (w
);
11094 rif
->scroll_run_hook (w
, &run
);
11095 rif
->update_window_end_hook (w
, 0, 0);
11099 /* Adjust Y positions of reused rows. */
11100 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11101 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11102 max_y
= it
.last_visible_y
;
11103 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11106 row
->visible_height
= row
->height
;
11107 if (row
->y
< min_y
)
11108 row
->visible_height
-= min_y
- row
->y
;
11109 if (row
->y
+ row
->height
> max_y
)
11110 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11113 /* Scroll the current matrix. */
11114 xassert (nrows_scrolled
> 0);
11115 rotate_matrix (w
->current_matrix
,
11117 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11120 /* Disable rows not reused. */
11121 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11122 row
->enabled_p
= 0;
11124 /* Adjust window end. A null value of last_text_row means that
11125 the window end is in reused rows which in turn means that
11126 only its vpos can have changed. */
11129 w
->window_end_bytepos
11130 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11132 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11134 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11139 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11142 w
->window_end_valid
= Qnil
;
11143 w
->desired_matrix
->no_scrolling_p
= 1;
11146 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11156 /************************************************************************
11157 Window redisplay reusing current matrix when buffer has changed
11158 ************************************************************************/
11160 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11161 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11163 static struct glyph_row
*
11164 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11165 struct glyph_row
*));
11168 /* Return the last row in MATRIX displaying text. If row START is
11169 non-null, start searching with that row. IT gives the dimensions
11170 of the display. Value is null if matrix is empty; otherwise it is
11171 a pointer to the row found. */
11173 static struct glyph_row
*
11174 find_last_row_displaying_text (matrix
, it
, start
)
11175 struct glyph_matrix
*matrix
;
11177 struct glyph_row
*start
;
11179 struct glyph_row
*row
, *row_found
;
11181 /* Set row_found to the last row in IT->w's current matrix
11182 displaying text. The loop looks funny but think of partially
11185 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11186 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11188 xassert (row
->enabled_p
);
11190 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11199 /* Return the last row in the current matrix of W that is not affected
11200 by changes at the start of current_buffer that occurred since W's
11201 current matrix was built. Value is null if no such row exists.
11203 BEG_UNCHANGED us the number of characters unchanged at the start of
11204 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11205 first changed character in current_buffer. Characters at positions <
11206 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11207 when the current matrix was built. */
11209 static struct glyph_row
*
11210 find_last_unchanged_at_beg_row (w
)
11213 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11214 struct glyph_row
*row
;
11215 struct glyph_row
*row_found
= NULL
;
11216 int yb
= window_text_bottom_y (w
);
11218 /* Find the last row displaying unchanged text. */
11219 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11220 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11221 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11223 if (/* If row ends before first_changed_pos, it is unchanged,
11224 except in some case. */
11225 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11226 /* When row ends in ZV and we write at ZV it is not
11228 && !row
->ends_at_zv_p
11229 /* When first_changed_pos is the end of a continued line,
11230 row is not unchanged because it may be no longer
11232 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11233 && row
->continued_p
))
11236 /* Stop if last visible row. */
11237 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11247 /* Find the first glyph row in the current matrix of W that is not
11248 affected by changes at the end of current_buffer since the
11249 time W's current matrix was built.
11251 Return in *DELTA the number of chars by which buffer positions in
11252 unchanged text at the end of current_buffer must be adjusted.
11254 Return in *DELTA_BYTES the corresponding number of bytes.
11256 Value is null if no such row exists, i.e. all rows are affected by
11259 static struct glyph_row
*
11260 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11262 int *delta
, *delta_bytes
;
11264 struct glyph_row
*row
;
11265 struct glyph_row
*row_found
= NULL
;
11267 *delta
= *delta_bytes
= 0;
11269 /* Display must not have been paused, otherwise the current matrix
11270 is not up to date. */
11271 if (NILP (w
->window_end_valid
))
11274 /* A value of window_end_pos >= END_UNCHANGED means that the window
11275 end is in the range of changed text. If so, there is no
11276 unchanged row at the end of W's current matrix. */
11277 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11280 /* Set row to the last row in W's current matrix displaying text. */
11281 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11283 /* If matrix is entirely empty, no unchanged row exists. */
11284 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11286 /* The value of row is the last glyph row in the matrix having a
11287 meaningful buffer position in it. The end position of row
11288 corresponds to window_end_pos. This allows us to translate
11289 buffer positions in the current matrix to current buffer
11290 positions for characters not in changed text. */
11291 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11292 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11293 int last_unchanged_pos
, last_unchanged_pos_old
;
11294 struct glyph_row
*first_text_row
11295 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11297 *delta
= Z
- Z_old
;
11298 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11300 /* Set last_unchanged_pos to the buffer position of the last
11301 character in the buffer that has not been changed. Z is the
11302 index + 1 of the last character in current_buffer, i.e. by
11303 subtracting END_UNCHANGED we get the index of the last
11304 unchanged character, and we have to add BEG to get its buffer
11306 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11307 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11309 /* Search backward from ROW for a row displaying a line that
11310 starts at a minimum position >= last_unchanged_pos_old. */
11311 for (; row
> first_text_row
; --row
)
11313 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11316 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11321 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11328 /* Make sure that glyph rows in the current matrix of window W
11329 reference the same glyph memory as corresponding rows in the
11330 frame's frame matrix. This function is called after scrolling W's
11331 current matrix on a terminal frame in try_window_id and
11332 try_window_reusing_current_matrix. */
11335 sync_frame_with_window_matrix_rows (w
)
11338 struct frame
*f
= XFRAME (w
->frame
);
11339 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11341 /* Preconditions: W must be a leaf window and full-width. Its frame
11342 must have a frame matrix. */
11343 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11344 xassert (WINDOW_FULL_WIDTH_P (w
));
11345 xassert (!FRAME_WINDOW_P (f
));
11347 /* If W is a full-width window, glyph pointers in W's current matrix
11348 have, by definition, to be the same as glyph pointers in the
11349 corresponding frame matrix. Note that frame matrices have no
11350 marginal areas (see build_frame_matrix). */
11351 window_row
= w
->current_matrix
->rows
;
11352 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11353 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11354 while (window_row
< window_row_end
)
11356 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
11357 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
11359 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
11360 frame_row
->glyphs
[TEXT_AREA
] = start
;
11361 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
11362 frame_row
->glyphs
[LAST_AREA
] = end
;
11364 /* Disable frame rows whose corresponding window rows have
11365 been disabled in try_window_id. */
11366 if (!window_row
->enabled_p
)
11367 frame_row
->enabled_p
= 0;
11369 ++window_row
, ++frame_row
;
11374 /* Find the glyph row in window W containing CHARPOS. Consider all
11375 rows between START and END (not inclusive). END null means search
11376 all rows to the end of the display area of W. Value is the row
11377 containing CHARPOS or null. */
11380 row_containing_pos (w
, charpos
, start
, end
, dy
)
11383 struct glyph_row
*start
, *end
;
11386 struct glyph_row
*row
= start
;
11389 /* If we happen to start on a header-line, skip that. */
11390 if (row
->mode_line_p
)
11393 if ((end
&& row
>= end
) || !row
->enabled_p
)
11396 last_y
= window_text_bottom_y (w
) - dy
;
11398 while ((end
== NULL
|| row
< end
)
11399 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
11400 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11401 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11402 /* The end position of a row equals the start
11403 position of the next row. If CHARPOS is there, we
11404 would rather display it in the next line, except
11405 when this line ends in ZV. */
11406 && !row
->ends_at_zv_p
11407 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))
11410 /* Give up if CHARPOS not found. */
11411 if ((end
&& row
>= end
)
11412 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11413 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11420 /* Try to redisplay window W by reusing its existing display. W's
11421 current matrix must be up to date when this function is called,
11422 i.e. window_end_valid must not be nil.
11426 1 if display has been updated
11427 0 if otherwise unsuccessful
11428 -1 if redisplay with same window start is known not to succeed
11430 The following steps are performed:
11432 1. Find the last row in the current matrix of W that is not
11433 affected by changes at the start of current_buffer. If no such row
11436 2. Find the first row in W's current matrix that is not affected by
11437 changes at the end of current_buffer. Maybe there is no such row.
11439 3. Display lines beginning with the row + 1 found in step 1 to the
11440 row found in step 2 or, if step 2 didn't find a row, to the end of
11443 4. If cursor is not known to appear on the window, give up.
11445 5. If display stopped at the row found in step 2, scroll the
11446 display and current matrix as needed.
11448 6. Maybe display some lines at the end of W, if we must. This can
11449 happen under various circumstances, like a partially visible line
11450 becoming fully visible, or because newly displayed lines are displayed
11451 in smaller font sizes.
11453 7. Update W's window end information. */
11459 struct frame
*f
= XFRAME (w
->frame
);
11460 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11461 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11462 struct glyph_row
*last_unchanged_at_beg_row
;
11463 struct glyph_row
*first_unchanged_at_end_row
;
11464 struct glyph_row
*row
;
11465 struct glyph_row
*bottom_row
;
11468 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11469 struct text_pos start_pos
;
11471 int first_unchanged_at_end_vpos
= 0;
11472 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11473 struct text_pos start
;
11474 int first_changed_charpos
, last_changed_charpos
;
11477 if (inhibit_try_window_id
)
11481 /* This is handy for debugging. */
11483 #define GIVE_UP(X) \
11485 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11489 #define GIVE_UP(X) return 0
11492 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11494 /* Don't use this for mini-windows because these can show
11495 messages and mini-buffers, and we don't handle that here. */
11496 if (MINI_WINDOW_P (w
))
11499 /* This flag is used to prevent redisplay optimizations. */
11500 if (windows_or_buffers_changed
|| cursor_type_changed
)
11503 /* Verify that narrowing has not changed. This flag is also set to prevent
11504 redisplay optimizations. It would be nice to further
11505 reduce the number of cases where this prevents try_window_id. */
11506 if (current_buffer
->clip_changed
)
11509 /* Window must either use window-based redisplay or be full width. */
11510 if (!FRAME_WINDOW_P (f
)
11511 && (!line_ins_del_ok
11512 || !WINDOW_FULL_WIDTH_P (w
)))
11515 /* Give up if point is not known NOT to appear in W. */
11516 if (PT
< CHARPOS (start
))
11519 /* Another way to prevent redisplay optimizations. */
11520 if (XFASTINT (w
->last_modified
) == 0)
11523 /* Verify that window is not hscrolled. */
11524 if (XFASTINT (w
->hscroll
) != 0)
11527 /* Verify that display wasn't paused. */
11528 if (NILP (w
->window_end_valid
))
11531 /* Can't use this if highlighting a region because a cursor movement
11532 will do more than just set the cursor. */
11533 if (!NILP (Vtransient_mark_mode
)
11534 && !NILP (current_buffer
->mark_active
))
11537 /* Likewise if highlighting trailing whitespace. */
11538 if (!NILP (Vshow_trailing_whitespace
))
11541 /* Likewise if showing a region. */
11542 if (!NILP (w
->region_showing
))
11545 /* Can use this if overlay arrow position and or string have changed. */
11546 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11547 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11551 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11552 only if buffer has really changed. The reason is that the gap is
11553 initially at Z for freshly visited files. The code below would
11554 set end_unchanged to 0 in that case. */
11555 if (MODIFF
> SAVE_MODIFF
11556 /* This seems to happen sometimes after saving a buffer. */
11557 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11559 if (GPT
- BEG
< BEG_UNCHANGED
)
11560 BEG_UNCHANGED
= GPT
- BEG
;
11561 if (Z
- GPT
< END_UNCHANGED
)
11562 END_UNCHANGED
= Z
- GPT
;
11565 /* The position of the first and last character that has been changed. */
11566 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11567 last_changed_charpos
= Z
- END_UNCHANGED
;
11569 /* If window starts after a line end, and the last change is in
11570 front of that newline, then changes don't affect the display.
11571 This case happens with stealth-fontification. Note that although
11572 the display is unchanged, glyph positions in the matrix have to
11573 be adjusted, of course. */
11574 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11575 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11576 && ((last_changed_charpos
< CHARPOS (start
)
11577 && CHARPOS (start
) == BEGV
)
11578 || (last_changed_charpos
< CHARPOS (start
) - 1
11579 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11581 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11582 struct glyph_row
*r0
;
11584 /* Compute how many chars/bytes have been added to or removed
11585 from the buffer. */
11586 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11587 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11589 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11591 /* Give up if PT is not in the window. Note that it already has
11592 been checked at the start of try_window_id that PT is not in
11593 front of the window start. */
11594 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11597 /* If window start is unchanged, we can reuse the whole matrix
11598 as is, after adjusting glyph positions. No need to compute
11599 the window end again, since its offset from Z hasn't changed. */
11600 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11601 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11602 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11604 /* Adjust positions in the glyph matrix. */
11605 if (delta
|| delta_bytes
)
11607 struct glyph_row
*r1
11608 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11609 increment_matrix_positions (w
->current_matrix
,
11610 MATRIX_ROW_VPOS (r0
, current_matrix
),
11611 MATRIX_ROW_VPOS (r1
, current_matrix
),
11612 delta
, delta_bytes
);
11615 /* Set the cursor. */
11616 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11617 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11622 /* Handle the case that changes are all below what is displayed in
11623 the window, and that PT is in the window. This shortcut cannot
11624 be taken if ZV is visible in the window, and text has been added
11625 there that is visible in the window. */
11626 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11627 /* ZV is not visible in the window, or there are no
11628 changes at ZV, actually. */
11629 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11630 || first_changed_charpos
== last_changed_charpos
))
11632 struct glyph_row
*r0
;
11634 /* Give up if PT is not in the window. Note that it already has
11635 been checked at the start of try_window_id that PT is not in
11636 front of the window start. */
11637 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11640 /* If window start is unchanged, we can reuse the whole matrix
11641 as is, without changing glyph positions since no text has
11642 been added/removed in front of the window end. */
11643 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11644 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11646 /* We have to compute the window end anew since text
11647 can have been added/removed after it. */
11649 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11650 w
->window_end_bytepos
11651 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11653 /* Set the cursor. */
11654 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11655 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11660 /* Give up if window start is in the changed area.
11662 The condition used to read
11664 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11666 but why that was tested escapes me at the moment. */
11667 if (CHARPOS (start
) >= first_changed_charpos
11668 && CHARPOS (start
) <= last_changed_charpos
)
11671 /* Check that window start agrees with the start of the first glyph
11672 row in its current matrix. Check this after we know the window
11673 start is not in changed text, otherwise positions would not be
11675 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11676 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11679 /* Give up if the window ends in strings. Overlay strings
11680 at the end are difficult to handle, so don't try. */
11681 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11682 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11685 /* Compute the position at which we have to start displaying new
11686 lines. Some of the lines at the top of the window might be
11687 reusable because they are not displaying changed text. Find the
11688 last row in W's current matrix not affected by changes at the
11689 start of current_buffer. Value is null if changes start in the
11690 first line of window. */
11691 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11692 if (last_unchanged_at_beg_row
)
11694 /* Avoid starting to display in the moddle of a character, a TAB
11695 for instance. This is easier than to set up the iterator
11696 exactly, and it's not a frequent case, so the additional
11697 effort wouldn't really pay off. */
11698 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11699 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11700 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11701 --last_unchanged_at_beg_row
;
11703 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11706 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11708 start_pos
= it
.current
.pos
;
11710 /* Start displaying new lines in the desired matrix at the same
11711 vpos we would use in the current matrix, i.e. below
11712 last_unchanged_at_beg_row. */
11713 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11715 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11716 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11718 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11722 /* There are no reusable lines at the start of the window.
11723 Start displaying in the first line. */
11724 start_display (&it
, w
, start
);
11725 start_pos
= it
.current
.pos
;
11728 /* Find the first row that is not affected by changes at the end of
11729 the buffer. Value will be null if there is no unchanged row, in
11730 which case we must redisplay to the end of the window. delta
11731 will be set to the value by which buffer positions beginning with
11732 first_unchanged_at_end_row have to be adjusted due to text
11734 first_unchanged_at_end_row
11735 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11736 IF_DEBUG (debug_delta
= delta
);
11737 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11739 /* Set stop_pos to the buffer position up to which we will have to
11740 display new lines. If first_unchanged_at_end_row != NULL, this
11741 is the buffer position of the start of the line displayed in that
11742 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11743 that we don't stop at a buffer position. */
11745 if (first_unchanged_at_end_row
)
11747 xassert (last_unchanged_at_beg_row
== NULL
11748 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11750 /* If this is a continuation line, move forward to the next one
11751 that isn't. Changes in lines above affect this line.
11752 Caution: this may move first_unchanged_at_end_row to a row
11753 not displaying text. */
11754 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11755 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11756 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11757 < it
.last_visible_y
))
11758 ++first_unchanged_at_end_row
;
11760 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11761 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11762 >= it
.last_visible_y
))
11763 first_unchanged_at_end_row
= NULL
;
11766 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11768 first_unchanged_at_end_vpos
11769 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11770 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11773 else if (last_unchanged_at_beg_row
== NULL
)
11779 /* Either there is no unchanged row at the end, or the one we have
11780 now displays text. This is a necessary condition for the window
11781 end pos calculation at the end of this function. */
11782 xassert (first_unchanged_at_end_row
== NULL
11783 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11785 debug_last_unchanged_at_beg_vpos
11786 = (last_unchanged_at_beg_row
11787 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11789 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11791 #endif /* GLYPH_DEBUG != 0 */
11794 /* Display new lines. Set last_text_row to the last new line
11795 displayed which has text on it, i.e. might end up as being the
11796 line where the window_end_vpos is. */
11797 w
->cursor
.vpos
= -1;
11798 last_text_row
= NULL
;
11799 overlay_arrow_seen
= 0;
11800 while (it
.current_y
< it
.last_visible_y
11801 && !fonts_changed_p
11802 && (first_unchanged_at_end_row
== NULL
11803 || IT_CHARPOS (it
) < stop_pos
))
11805 if (display_line (&it
))
11806 last_text_row
= it
.glyph_row
- 1;
11809 if (fonts_changed_p
)
11813 /* Compute differences in buffer positions, y-positions etc. for
11814 lines reused at the bottom of the window. Compute what we can
11816 if (first_unchanged_at_end_row
11817 /* No lines reused because we displayed everything up to the
11818 bottom of the window. */
11819 && it
.current_y
< it
.last_visible_y
)
11822 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11824 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11825 run
.current_y
= first_unchanged_at_end_row
->y
;
11826 run
.desired_y
= run
.current_y
+ dy
;
11827 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11831 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11832 first_unchanged_at_end_row
= NULL
;
11834 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11837 /* Find the cursor if not already found. We have to decide whether
11838 PT will appear on this window (it sometimes doesn't, but this is
11839 not a very frequent case.) This decision has to be made before
11840 the current matrix is altered. A value of cursor.vpos < 0 means
11841 that PT is either in one of the lines beginning at
11842 first_unchanged_at_end_row or below the window. Don't care for
11843 lines that might be displayed later at the window end; as
11844 mentioned, this is not a frequent case. */
11845 if (w
->cursor
.vpos
< 0)
11847 /* Cursor in unchanged rows at the top? */
11848 if (PT
< CHARPOS (start_pos
)
11849 && last_unchanged_at_beg_row
)
11851 row
= row_containing_pos (w
, PT
,
11852 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11853 last_unchanged_at_beg_row
+ 1, 0);
11855 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11858 /* Start from first_unchanged_at_end_row looking for PT. */
11859 else if (first_unchanged_at_end_row
)
11861 row
= row_containing_pos (w
, PT
- delta
,
11862 first_unchanged_at_end_row
, NULL
, 0);
11864 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11865 delta_bytes
, dy
, dvpos
);
11868 /* Give up if cursor was not found. */
11869 if (w
->cursor
.vpos
< 0)
11871 clear_glyph_matrix (w
->desired_matrix
);
11876 /* Don't let the cursor end in the scroll margins. */
11878 int this_scroll_margin
, cursor_height
;
11880 this_scroll_margin
= max (0, scroll_margin
);
11881 this_scroll_margin
= min (this_scroll_margin
,
11882 XFASTINT (w
->height
) / 4);
11883 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11884 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11886 if ((w
->cursor
.y
< this_scroll_margin
11887 && CHARPOS (start
) > BEGV
)
11888 /* Don't take scroll margin into account at the bottom because
11889 old redisplay didn't do it either. */
11890 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11892 w
->cursor
.vpos
= -1;
11893 clear_glyph_matrix (w
->desired_matrix
);
11898 /* Scroll the display. Do it before changing the current matrix so
11899 that xterm.c doesn't get confused about where the cursor glyph is
11901 if (dy
&& run
.height
)
11905 if (FRAME_WINDOW_P (f
))
11907 rif
->update_window_begin_hook (w
);
11908 rif
->clear_mouse_face (w
);
11909 rif
->scroll_run_hook (w
, &run
);
11910 rif
->update_window_end_hook (w
, 0, 0);
11914 /* Terminal frame. In this case, dvpos gives the number of
11915 lines to scroll by; dvpos < 0 means scroll up. */
11916 int first_unchanged_at_end_vpos
11917 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11918 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11919 int end
= (XFASTINT (w
->top
)
11920 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11921 + window_internal_height (w
));
11923 /* Perform the operation on the screen. */
11926 /* Scroll last_unchanged_at_beg_row to the end of the
11927 window down dvpos lines. */
11928 set_terminal_window (end
);
11930 /* On dumb terminals delete dvpos lines at the end
11931 before inserting dvpos empty lines. */
11932 if (!scroll_region_ok
)
11933 ins_del_lines (end
- dvpos
, -dvpos
);
11935 /* Insert dvpos empty lines in front of
11936 last_unchanged_at_beg_row. */
11937 ins_del_lines (from
, dvpos
);
11939 else if (dvpos
< 0)
11941 /* Scroll up last_unchanged_at_beg_vpos to the end of
11942 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11943 set_terminal_window (end
);
11945 /* Delete dvpos lines in front of
11946 last_unchanged_at_beg_vpos. ins_del_lines will set
11947 the cursor to the given vpos and emit |dvpos| delete
11949 ins_del_lines (from
+ dvpos
, dvpos
);
11951 /* On a dumb terminal insert dvpos empty lines at the
11953 if (!scroll_region_ok
)
11954 ins_del_lines (end
+ dvpos
, -dvpos
);
11957 set_terminal_window (0);
11963 /* Shift reused rows of the current matrix to the right position.
11964 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11966 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11967 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11970 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11971 bottom_vpos
, dvpos
);
11972 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11975 else if (dvpos
> 0)
11977 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11978 bottom_vpos
, dvpos
);
11979 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11980 first_unchanged_at_end_vpos
+ dvpos
, 0);
11983 /* For frame-based redisplay, make sure that current frame and window
11984 matrix are in sync with respect to glyph memory. */
11985 if (!FRAME_WINDOW_P (f
))
11986 sync_frame_with_window_matrix_rows (w
);
11988 /* Adjust buffer positions in reused rows. */
11990 increment_matrix_positions (current_matrix
,
11991 first_unchanged_at_end_vpos
+ dvpos
,
11992 bottom_vpos
, delta
, delta_bytes
);
11994 /* Adjust Y positions. */
11996 shift_glyph_matrix (w
, current_matrix
,
11997 first_unchanged_at_end_vpos
+ dvpos
,
12000 if (first_unchanged_at_end_row
)
12001 first_unchanged_at_end_row
+= dvpos
;
12003 /* If scrolling up, there may be some lines to display at the end of
12005 last_text_row_at_end
= NULL
;
12008 /* Scrolling up can leave for example a partially visible line
12009 at the end of the window to be redisplayed. */
12010 /* Set last_row to the glyph row in the current matrix where the
12011 window end line is found. It has been moved up or down in
12012 the matrix by dvpos. */
12013 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
12014 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
12016 /* If last_row is the window end line, it should display text. */
12017 xassert (last_row
->displays_text_p
);
12019 /* If window end line was partially visible before, begin
12020 displaying at that line. Otherwise begin displaying with the
12021 line following it. */
12022 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
12024 init_to_row_start (&it
, w
, last_row
);
12025 it
.vpos
= last_vpos
;
12026 it
.current_y
= last_row
->y
;
12030 init_to_row_end (&it
, w
, last_row
);
12031 it
.vpos
= 1 + last_vpos
;
12032 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
12036 /* We may start in a continuation line. If so, we have to
12037 get the right continuation_lines_width and current_x. */
12038 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
12039 it
.hpos
= it
.current_x
= 0;
12041 /* Display the rest of the lines at the window end. */
12042 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12043 while (it
.current_y
< it
.last_visible_y
12044 && !fonts_changed_p
)
12046 /* Is it always sure that the display agrees with lines in
12047 the current matrix? I don't think so, so we mark rows
12048 displayed invalid in the current matrix by setting their
12049 enabled_p flag to zero. */
12050 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
12051 if (display_line (&it
))
12052 last_text_row_at_end
= it
.glyph_row
- 1;
12056 /* Update window_end_pos and window_end_vpos. */
12057 if (first_unchanged_at_end_row
12058 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12059 && !last_text_row_at_end
)
12061 /* Window end line if one of the preserved rows from the current
12062 matrix. Set row to the last row displaying text in current
12063 matrix starting at first_unchanged_at_end_row, after
12065 xassert (first_unchanged_at_end_row
->displays_text_p
);
12066 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12067 first_unchanged_at_end_row
);
12068 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12070 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12071 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12073 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12074 xassert (w
->window_end_bytepos
>= 0);
12075 IF_DEBUG (debug_method_add (w
, "A"));
12077 else if (last_text_row_at_end
)
12080 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12081 w
->window_end_bytepos
12082 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12084 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12085 xassert (w
->window_end_bytepos
>= 0);
12086 IF_DEBUG (debug_method_add (w
, "B"));
12088 else if (last_text_row
)
12090 /* We have displayed either to the end of the window or at the
12091 end of the window, i.e. the last row with text is to be found
12092 in the desired matrix. */
12094 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12095 w
->window_end_bytepos
12096 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12098 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12099 xassert (w
->window_end_bytepos
>= 0);
12101 else if (first_unchanged_at_end_row
== NULL
12102 && last_text_row
== NULL
12103 && last_text_row_at_end
== NULL
)
12105 /* Displayed to end of window, but no line containing text was
12106 displayed. Lines were deleted at the end of the window. */
12107 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12108 int vpos
= XFASTINT (w
->window_end_vpos
);
12109 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12110 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12113 row
== NULL
&& vpos
>= first_vpos
;
12114 --vpos
, --current_row
, --desired_row
)
12116 if (desired_row
->enabled_p
)
12118 if (desired_row
->displays_text_p
)
12121 else if (current_row
->displays_text_p
)
12125 xassert (row
!= NULL
);
12126 w
->window_end_vpos
= make_number (vpos
+ 1);
12127 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12128 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12129 xassert (w
->window_end_bytepos
>= 0);
12130 IF_DEBUG (debug_method_add (w
, "C"));
12135 #if 0 /* This leads to problems, for instance when the cursor is
12136 at ZV, and the cursor line displays no text. */
12137 /* Disable rows below what's displayed in the window. This makes
12138 debugging easier. */
12139 enable_glyph_matrix_rows (current_matrix
,
12140 XFASTINT (w
->window_end_vpos
) + 1,
12144 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12145 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12147 /* Record that display has not been completed. */
12148 w
->window_end_valid
= Qnil
;
12149 w
->desired_matrix
->no_scrolling_p
= 1;
12157 /***********************************************************************
12158 More debugging support
12159 ***********************************************************************/
12163 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12164 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12165 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12168 /* Dump the contents of glyph matrix MATRIX on stderr.
12170 GLYPHS 0 means don't show glyph contents.
12171 GLYPHS 1 means show glyphs in short form
12172 GLYPHS > 1 means show glyphs in long form. */
12175 dump_glyph_matrix (matrix
, glyphs
)
12176 struct glyph_matrix
*matrix
;
12180 for (i
= 0; i
< matrix
->nrows
; ++i
)
12181 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12185 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12186 the glyph row and area where the glyph comes from. */
12189 dump_glyph (row
, glyph
, area
)
12190 struct glyph_row
*row
;
12191 struct glyph
*glyph
;
12194 if (glyph
->type
== CHAR_GLYPH
)
12197 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12198 glyph
- row
->glyphs
[TEXT_AREA
],
12201 (BUFFERP (glyph
->object
)
12203 : (STRINGP (glyph
->object
)
12206 glyph
->pixel_width
,
12208 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12212 glyph
->left_box_line_p
,
12213 glyph
->right_box_line_p
);
12215 else if (glyph
->type
== STRETCH_GLYPH
)
12218 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12219 glyph
- row
->glyphs
[TEXT_AREA
],
12222 (BUFFERP (glyph
->object
)
12224 : (STRINGP (glyph
->object
)
12227 glyph
->pixel_width
,
12231 glyph
->left_box_line_p
,
12232 glyph
->right_box_line_p
);
12234 else if (glyph
->type
== IMAGE_GLYPH
)
12237 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12238 glyph
- row
->glyphs
[TEXT_AREA
],
12241 (BUFFERP (glyph
->object
)
12243 : (STRINGP (glyph
->object
)
12246 glyph
->pixel_width
,
12250 glyph
->left_box_line_p
,
12251 glyph
->right_box_line_p
);
12256 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12257 GLYPHS 0 means don't show glyph contents.
12258 GLYPHS 1 means show glyphs in short form
12259 GLYPHS > 1 means show glyphs in long form. */
12262 dump_glyph_row (row
, vpos
, glyphs
)
12263 struct glyph_row
*row
;
12268 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12269 fprintf (stderr
, "=======================================================================\n");
12271 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12272 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12274 MATRIX_ROW_START_CHARPOS (row
),
12275 MATRIX_ROW_END_CHARPOS (row
),
12276 row
->used
[TEXT_AREA
],
12277 row
->contains_overlapping_glyphs_p
,
12279 row
->truncated_on_left_p
,
12280 row
->truncated_on_right_p
,
12281 row
->overlay_arrow_p
,
12283 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12284 row
->displays_text_p
,
12287 row
->ends_in_middle_of_char_p
,
12288 row
->starts_in_middle_of_char_p
,
12294 row
->visible_height
,
12297 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12298 row
->end
.overlay_string_index
,
12299 row
->continuation_lines_width
);
12300 fprintf (stderr
, "%9d %5d\n",
12301 CHARPOS (row
->start
.string_pos
),
12302 CHARPOS (row
->end
.string_pos
));
12303 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12304 row
->end
.dpvec_index
);
12311 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12313 struct glyph
*glyph
= row
->glyphs
[area
];
12314 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12316 /* Glyph for a line end in text. */
12317 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12320 if (glyph
< glyph_end
)
12321 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12323 for (; glyph
< glyph_end
; ++glyph
)
12324 dump_glyph (row
, glyph
, area
);
12327 else if (glyphs
== 1)
12331 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12333 char *s
= (char *) alloca (row
->used
[area
] + 1);
12336 for (i
= 0; i
< row
->used
[area
]; ++i
)
12338 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12339 if (glyph
->type
== CHAR_GLYPH
12340 && glyph
->u
.ch
< 0x80
12341 && glyph
->u
.ch
>= ' ')
12342 s
[i
] = glyph
->u
.ch
;
12348 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12354 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12355 Sdump_glyph_matrix
, 0, 1, "p",
12356 doc
: /* Dump the current matrix of the selected window to stderr.
12357 Shows contents of glyph row structures. With non-nil
12358 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12359 glyphs in short form, otherwise show glyphs in long form. */)
12361 Lisp_Object glyphs
;
12363 struct window
*w
= XWINDOW (selected_window
);
12364 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12366 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12367 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12368 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12369 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12370 fprintf (stderr
, "=============================================\n");
12371 dump_glyph_matrix (w
->current_matrix
,
12372 NILP (glyphs
) ? 0 : XINT (glyphs
));
12377 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
12378 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
12381 struct frame
*f
= XFRAME (selected_frame
);
12382 dump_glyph_matrix (f
->current_matrix
, 1);
12387 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12388 doc
: /* Dump glyph row ROW to stderr.
12389 GLYPH 0 means don't dump glyphs.
12390 GLYPH 1 means dump glyphs in short form.
12391 GLYPH > 1 or omitted means dump glyphs in long form. */)
12393 Lisp_Object row
, glyphs
;
12395 struct glyph_matrix
*matrix
;
12398 CHECK_NUMBER (row
);
12399 matrix
= XWINDOW (selected_window
)->current_matrix
;
12401 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12402 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12404 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12409 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12410 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12411 GLYPH 0 means don't dump glyphs.
12412 GLYPH 1 means dump glyphs in short form.
12413 GLYPH > 1 or omitted means dump glyphs in long form. */)
12415 Lisp_Object row
, glyphs
;
12417 struct frame
*sf
= SELECTED_FRAME ();
12418 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12421 CHECK_NUMBER (row
);
12423 if (vpos
>= 0 && vpos
< m
->nrows
)
12424 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12425 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12430 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12431 doc
: /* Toggle tracing of redisplay.
12432 With ARG, turn tracing on if and only if ARG is positive. */)
12437 trace_redisplay_p
= !trace_redisplay_p
;
12440 arg
= Fprefix_numeric_value (arg
);
12441 trace_redisplay_p
= XINT (arg
) > 0;
12448 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12449 doc
: /* Like `format', but print result to stderr. */)
12454 Lisp_Object s
= Fformat (nargs
, args
);
12455 fprintf (stderr
, "%s", SDATA (s
));
12459 #endif /* GLYPH_DEBUG */
12463 /***********************************************************************
12464 Building Desired Matrix Rows
12465 ***********************************************************************/
12467 /* Return a temporary glyph row holding the glyphs of an overlay
12468 arrow. Only used for non-window-redisplay windows. */
12470 static struct glyph_row
*
12471 get_overlay_arrow_glyph_row (w
)
12474 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12475 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12476 struct buffer
*old
= current_buffer
;
12477 unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
12478 int arrow_len
= SCHARS (Voverlay_arrow_string
);
12479 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12483 int n_glyphs_before
;
12485 set_buffer_temp (buffer
);
12486 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12487 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12488 SET_TEXT_POS (it
.position
, 0, 0);
12490 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12492 while (p
< arrow_end
)
12494 Lisp_Object face
, ilisp
;
12496 /* Get the next character. */
12498 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12500 it
.c
= *p
, it
.len
= 1;
12503 /* Get its face. */
12504 ilisp
= make_number (p
- arrow_string
);
12505 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12506 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12508 /* Compute its width, get its glyphs. */
12509 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12510 SET_TEXT_POS (it
.position
, -1, -1);
12511 PRODUCE_GLYPHS (&it
);
12513 /* If this character doesn't fit any more in the line, we have
12514 to remove some glyphs. */
12515 if (it
.current_x
> it
.last_visible_x
)
12517 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12522 set_buffer_temp (old
);
12523 return it
.glyph_row
;
12527 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12528 glyphs are only inserted for terminal frames since we can't really
12529 win with truncation glyphs when partially visible glyphs are
12530 involved. Which glyphs to insert is determined by
12531 produce_special_glyphs. */
12534 insert_left_trunc_glyphs (it
)
12537 struct it truncate_it
;
12538 struct glyph
*from
, *end
, *to
, *toend
;
12540 xassert (!FRAME_WINDOW_P (it
->f
));
12542 /* Get the truncation glyphs. */
12544 truncate_it
.current_x
= 0;
12545 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12546 truncate_it
.glyph_row
= &scratch_glyph_row
;
12547 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12548 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12549 truncate_it
.object
= make_number (0);
12550 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12552 /* Overwrite glyphs from IT with truncation glyphs. */
12553 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12554 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12555 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12556 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12561 /* There may be padding glyphs left over. Overwrite them too. */
12562 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12564 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12570 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12574 /* Compute the pixel height and width of IT->glyph_row.
12576 Most of the time, ascent and height of a display line will be equal
12577 to the max_ascent and max_height values of the display iterator
12578 structure. This is not the case if
12580 1. We hit ZV without displaying anything. In this case, max_ascent
12581 and max_height will be zero.
12583 2. We have some glyphs that don't contribute to the line height.
12584 (The glyph row flag contributes_to_line_height_p is for future
12585 pixmap extensions).
12587 The first case is easily covered by using default values because in
12588 these cases, the line height does not really matter, except that it
12589 must not be zero. */
12592 compute_line_metrics (it
)
12595 struct glyph_row
*row
= it
->glyph_row
;
12598 if (FRAME_WINDOW_P (it
->f
))
12600 int i
, min_y
, max_y
;
12602 /* The line may consist of one space only, that was added to
12603 place the cursor on it. If so, the row's height hasn't been
12605 if (row
->height
== 0)
12607 if (it
->max_ascent
+ it
->max_descent
== 0)
12608 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12609 row
->ascent
= it
->max_ascent
;
12610 row
->height
= it
->max_ascent
+ it
->max_descent
;
12611 row
->phys_ascent
= it
->max_phys_ascent
;
12612 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12615 /* Compute the width of this line. */
12616 row
->pixel_width
= row
->x
;
12617 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12618 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12620 xassert (row
->pixel_width
>= 0);
12621 xassert (row
->ascent
>= 0 && row
->height
> 0);
12623 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12624 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12626 /* If first line's physical ascent is larger than its logical
12627 ascent, use the physical ascent, and make the row taller.
12628 This makes accented characters fully visible. */
12629 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12630 && row
->phys_ascent
> row
->ascent
)
12632 row
->height
+= row
->phys_ascent
- row
->ascent
;
12633 row
->ascent
= row
->phys_ascent
;
12636 /* Compute how much of the line is visible. */
12637 row
->visible_height
= row
->height
;
12639 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12640 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12642 if (row
->y
< min_y
)
12643 row
->visible_height
-= min_y
- row
->y
;
12644 if (row
->y
+ row
->height
> max_y
)
12645 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12649 row
->pixel_width
= row
->used
[TEXT_AREA
];
12650 if (row
->continued_p
)
12651 row
->pixel_width
-= it
->continuation_pixel_width
;
12652 else if (row
->truncated_on_right_p
)
12653 row
->pixel_width
-= it
->truncation_pixel_width
;
12654 row
->ascent
= row
->phys_ascent
= 0;
12655 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12658 /* Compute a hash code for this row. */
12660 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12661 for (i
= 0; i
< row
->used
[area
]; ++i
)
12662 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12663 + row
->glyphs
[area
][i
].u
.val
12664 + row
->glyphs
[area
][i
].face_id
12665 + row
->glyphs
[area
][i
].padding_p
12666 + (row
->glyphs
[area
][i
].type
<< 2));
12668 it
->max_ascent
= it
->max_descent
= 0;
12669 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12673 /* Append one space to the glyph row of iterator IT if doing a
12674 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12675 space have the default face, otherwise let it have the same face as
12676 IT->face_id. Value is non-zero if a space was added.
12678 This function is called to make sure that there is always one glyph
12679 at the end of a glyph row that the cursor can be set on under
12680 window-systems. (If there weren't such a glyph we would not know
12681 how wide and tall a box cursor should be displayed).
12683 At the same time this space let's a nicely handle clearing to the
12684 end of the line if the row ends in italic text. */
12687 append_space (it
, default_face_p
)
12689 int default_face_p
;
12691 if (FRAME_WINDOW_P (it
->f
))
12693 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12695 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12696 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12698 /* Save some values that must not be changed.
12699 Must save IT->c and IT->len because otherwise
12700 ITERATOR_AT_END_P wouldn't work anymore after
12701 append_space has been called. */
12702 enum display_element_type saved_what
= it
->what
;
12703 int saved_c
= it
->c
, saved_len
= it
->len
;
12704 int saved_x
= it
->current_x
;
12705 int saved_face_id
= it
->face_id
;
12706 struct text_pos saved_pos
;
12707 Lisp_Object saved_object
;
12710 saved_object
= it
->object
;
12711 saved_pos
= it
->position
;
12713 it
->what
= IT_CHARACTER
;
12714 bzero (&it
->position
, sizeof it
->position
);
12715 it
->object
= make_number (0);
12719 if (default_face_p
)
12720 it
->face_id
= DEFAULT_FACE_ID
;
12721 else if (it
->face_before_selective_p
)
12722 it
->face_id
= it
->saved_face_id
;
12723 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12724 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12726 PRODUCE_GLYPHS (it
);
12728 it
->current_x
= saved_x
;
12729 it
->object
= saved_object
;
12730 it
->position
= saved_pos
;
12731 it
->what
= saved_what
;
12732 it
->face_id
= saved_face_id
;
12733 it
->len
= saved_len
;
12743 /* Extend the face of the last glyph in the text area of IT->glyph_row
12744 to the end of the display line. Called from display_line.
12745 If the glyph row is empty, add a space glyph to it so that we
12746 know the face to draw. Set the glyph row flag fill_line_p. */
12749 extend_face_to_end_of_line (it
)
12753 struct frame
*f
= it
->f
;
12755 /* If line is already filled, do nothing. */
12756 if (it
->current_x
>= it
->last_visible_x
)
12759 /* Face extension extends the background and box of IT->face_id
12760 to the end of the line. If the background equals the background
12761 of the frame, we don't have to do anything. */
12762 if (it
->face_before_selective_p
)
12763 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12765 face
= FACE_FROM_ID (f
, it
->face_id
);
12767 if (FRAME_WINDOW_P (f
)
12768 && face
->box
== FACE_NO_BOX
12769 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12773 /* Set the glyph row flag indicating that the face of the last glyph
12774 in the text area has to be drawn to the end of the text area. */
12775 it
->glyph_row
->fill_line_p
= 1;
12777 /* If current character of IT is not ASCII, make sure we have the
12778 ASCII face. This will be automatically undone the next time
12779 get_next_display_element returns a multibyte character. Note
12780 that the character will always be single byte in unibyte text. */
12781 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12783 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12786 if (FRAME_WINDOW_P (f
))
12788 /* If the row is empty, add a space with the current face of IT,
12789 so that we know which face to draw. */
12790 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12792 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12793 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12794 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12799 /* Save some values that must not be changed. */
12800 int saved_x
= it
->current_x
;
12801 struct text_pos saved_pos
;
12802 Lisp_Object saved_object
;
12803 enum display_element_type saved_what
= it
->what
;
12804 int saved_face_id
= it
->face_id
;
12806 saved_object
= it
->object
;
12807 saved_pos
= it
->position
;
12809 it
->what
= IT_CHARACTER
;
12810 bzero (&it
->position
, sizeof it
->position
);
12811 it
->object
= make_number (0);
12814 it
->face_id
= face
->id
;
12816 PRODUCE_GLYPHS (it
);
12818 while (it
->current_x
<= it
->last_visible_x
)
12819 PRODUCE_GLYPHS (it
);
12821 /* Don't count these blanks really. It would let us insert a left
12822 truncation glyph below and make us set the cursor on them, maybe. */
12823 it
->current_x
= saved_x
;
12824 it
->object
= saved_object
;
12825 it
->position
= saved_pos
;
12826 it
->what
= saved_what
;
12827 it
->face_id
= saved_face_id
;
12832 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12833 trailing whitespace. */
12836 trailing_whitespace_p (charpos
)
12839 int bytepos
= CHAR_TO_BYTE (charpos
);
12842 while (bytepos
< ZV_BYTE
12843 && (c
= FETCH_CHAR (bytepos
),
12844 c
== ' ' || c
== '\t'))
12847 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12849 if (bytepos
!= PT_BYTE
)
12856 /* Highlight trailing whitespace, if any, in ROW. */
12859 highlight_trailing_whitespace (f
, row
)
12861 struct glyph_row
*row
;
12863 int used
= row
->used
[TEXT_AREA
];
12867 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12868 struct glyph
*glyph
= start
+ used
- 1;
12870 /* Skip over glyphs inserted to display the cursor at the
12871 end of a line, for extending the face of the last glyph
12872 to the end of the line on terminals, and for truncation
12873 and continuation glyphs. */
12874 while (glyph
>= start
12875 && glyph
->type
== CHAR_GLYPH
12876 && INTEGERP (glyph
->object
))
12879 /* If last glyph is a space or stretch, and it's trailing
12880 whitespace, set the face of all trailing whitespace glyphs in
12881 IT->glyph_row to `trailing-whitespace'. */
12883 && BUFFERP (glyph
->object
)
12884 && (glyph
->type
== STRETCH_GLYPH
12885 || (glyph
->type
== CHAR_GLYPH
12886 && glyph
->u
.ch
== ' '))
12887 && trailing_whitespace_p (glyph
->charpos
))
12889 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12891 while (glyph
>= start
12892 && BUFFERP (glyph
->object
)
12893 && (glyph
->type
== STRETCH_GLYPH
12894 || (glyph
->type
== CHAR_GLYPH
12895 && glyph
->u
.ch
== ' ')))
12896 (glyph
--)->face_id
= face_id
;
12902 /* Value is non-zero if glyph row ROW in window W should be
12903 used to hold the cursor. */
12906 cursor_row_p (w
, row
)
12908 struct glyph_row
*row
;
12910 int cursor_row_p
= 1;
12912 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12914 /* If the row ends with a newline from a string, we don't want
12915 the cursor there (if the row is continued it doesn't end in a
12917 if (CHARPOS (row
->end
.string_pos
) >= 0
12918 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12919 cursor_row_p
= row
->continued_p
;
12921 /* If the row ends at ZV, display the cursor at the end of that
12922 row instead of at the start of the row below. */
12923 else if (row
->ends_at_zv_p
)
12929 return cursor_row_p
;
12933 /* Construct the glyph row IT->glyph_row in the desired matrix of
12934 IT->w from text at the current position of IT. See dispextern.h
12935 for an overview of struct it. Value is non-zero if
12936 IT->glyph_row displays text, as opposed to a line displaying ZV
12943 struct glyph_row
*row
= it
->glyph_row
;
12945 /* We always start displaying at hpos zero even if hscrolled. */
12946 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12948 /* We must not display in a row that's not a text row. */
12949 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12950 < it
->w
->desired_matrix
->nrows
);
12952 /* Is IT->w showing the region? */
12953 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12955 /* Clear the result glyph row and enable it. */
12956 prepare_desired_row (row
);
12958 row
->y
= it
->current_y
;
12959 row
->start
= it
->current
;
12960 row
->continuation_lines_width
= it
->continuation_lines_width
;
12961 row
->displays_text_p
= 1;
12962 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12963 it
->starts_in_middle_of_char_p
= 0;
12965 /* Arrange the overlays nicely for our purposes. Usually, we call
12966 display_line on only one line at a time, in which case this
12967 can't really hurt too much, or we call it on lines which appear
12968 one after another in the buffer, in which case all calls to
12969 recenter_overlay_lists but the first will be pretty cheap. */
12970 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12972 /* Move over display elements that are not visible because we are
12973 hscrolled. This may stop at an x-position < IT->first_visible_x
12974 if the first glyph is partially visible or if we hit a line end. */
12975 if (it
->current_x
< it
->first_visible_x
)
12976 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12977 MOVE_TO_POS
| MOVE_TO_X
);
12979 /* Get the initial row height. This is either the height of the
12980 text hscrolled, if there is any, or zero. */
12981 row
->ascent
= it
->max_ascent
;
12982 row
->height
= it
->max_ascent
+ it
->max_descent
;
12983 row
->phys_ascent
= it
->max_phys_ascent
;
12984 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12986 /* Loop generating characters. The loop is left with IT on the next
12987 character to display. */
12990 int n_glyphs_before
, hpos_before
, x_before
;
12992 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12994 /* Retrieve the next thing to display. Value is zero if end of
12996 if (!get_next_display_element (it
))
12998 /* Maybe add a space at the end of this line that is used to
12999 display the cursor there under X. Set the charpos of the
13000 first glyph of blank lines not corresponding to any text
13002 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
13003 || row
->used
[TEXT_AREA
] == 0)
13005 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
13006 row
->displays_text_p
= 0;
13008 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
13009 && (!MINI_WINDOW_P (it
->w
)
13010 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
13011 row
->indicate_empty_line_p
= 1;
13014 it
->continuation_lines_width
= 0;
13015 row
->ends_at_zv_p
= 1;
13019 /* Now, get the metrics of what we want to display. This also
13020 generates glyphs in `row' (which is IT->glyph_row). */
13021 n_glyphs_before
= row
->used
[TEXT_AREA
];
13024 /* Remember the line height so far in case the next element doesn't
13025 fit on the line. */
13026 if (!it
->truncate_lines_p
)
13028 ascent
= it
->max_ascent
;
13029 descent
= it
->max_descent
;
13030 phys_ascent
= it
->max_phys_ascent
;
13031 phys_descent
= it
->max_phys_descent
;
13034 PRODUCE_GLYPHS (it
);
13036 /* If this display element was in marginal areas, continue with
13038 if (it
->area
!= TEXT_AREA
)
13040 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13041 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13042 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13043 row
->phys_height
= max (row
->phys_height
,
13044 it
->max_phys_ascent
+ it
->max_phys_descent
);
13045 set_iterator_to_next (it
, 1);
13049 /* Does the display element fit on the line? If we truncate
13050 lines, we should draw past the right edge of the window. If
13051 we don't truncate, we want to stop so that we can display the
13052 continuation glyph before the right margin. If lines are
13053 continued, there are two possible strategies for characters
13054 resulting in more than 1 glyph (e.g. tabs): Display as many
13055 glyphs as possible in this line and leave the rest for the
13056 continuation line, or display the whole element in the next
13057 line. Original redisplay did the former, so we do it also. */
13058 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
13059 hpos_before
= it
->hpos
;
13062 if (/* Not a newline. */
13064 /* Glyphs produced fit entirely in the line. */
13065 && it
->current_x
< it
->last_visible_x
)
13067 it
->hpos
+= nglyphs
;
13068 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13069 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13070 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13071 row
->phys_height
= max (row
->phys_height
,
13072 it
->max_phys_ascent
+ it
->max_phys_descent
);
13073 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13074 row
->x
= x
- it
->first_visible_x
;
13079 struct glyph
*glyph
;
13081 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13083 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13084 new_x
= x
+ glyph
->pixel_width
;
13086 if (/* Lines are continued. */
13087 !it
->truncate_lines_p
13088 && (/* Glyph doesn't fit on the line. */
13089 new_x
> it
->last_visible_x
13090 /* Or it fits exactly on a window system frame. */
13091 || (new_x
== it
->last_visible_x
13092 && FRAME_WINDOW_P (it
->f
))))
13094 /* End of a continued line. */
13097 || (new_x
== it
->last_visible_x
13098 && FRAME_WINDOW_P (it
->f
)))
13100 /* Current glyph is the only one on the line or
13101 fits exactly on the line. We must continue
13102 the line because we can't draw the cursor
13103 after the glyph. */
13104 row
->continued_p
= 1;
13105 it
->current_x
= new_x
;
13106 it
->continuation_lines_width
+= new_x
;
13108 if (i
== nglyphs
- 1)
13109 set_iterator_to_next (it
, 1);
13111 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13112 && !FRAME_WINDOW_P (it
->f
))
13114 /* A padding glyph that doesn't fit on this line.
13115 This means the whole character doesn't fit
13117 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13119 /* Fill the rest of the row with continuation
13120 glyphs like in 20.x. */
13121 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13122 < row
->glyphs
[1 + TEXT_AREA
])
13123 produce_special_glyphs (it
, IT_CONTINUATION
);
13125 row
->continued_p
= 1;
13126 it
->current_x
= x_before
;
13127 it
->continuation_lines_width
+= x_before
;
13129 /* Restore the height to what it was before the
13130 element not fitting on the line. */
13131 it
->max_ascent
= ascent
;
13132 it
->max_descent
= descent
;
13133 it
->max_phys_ascent
= phys_ascent
;
13134 it
->max_phys_descent
= phys_descent
;
13136 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13138 /* A TAB that extends past the right edge of the
13139 window. This produces a single glyph on
13140 window system frames. We leave the glyph in
13141 this row and let it fill the row, but don't
13142 consume the TAB. */
13143 it
->continuation_lines_width
+= it
->last_visible_x
;
13144 row
->ends_in_middle_of_char_p
= 1;
13145 row
->continued_p
= 1;
13146 glyph
->pixel_width
= it
->last_visible_x
- x
;
13147 it
->starts_in_middle_of_char_p
= 1;
13151 /* Something other than a TAB that draws past
13152 the right edge of the window. Restore
13153 positions to values before the element. */
13154 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13156 /* Display continuation glyphs. */
13157 if (!FRAME_WINDOW_P (it
->f
))
13158 produce_special_glyphs (it
, IT_CONTINUATION
);
13159 row
->continued_p
= 1;
13161 it
->continuation_lines_width
+= x
;
13163 if (nglyphs
> 1 && i
> 0)
13165 row
->ends_in_middle_of_char_p
= 1;
13166 it
->starts_in_middle_of_char_p
= 1;
13169 /* Restore the height to what it was before the
13170 element not fitting on the line. */
13171 it
->max_ascent
= ascent
;
13172 it
->max_descent
= descent
;
13173 it
->max_phys_ascent
= phys_ascent
;
13174 it
->max_phys_descent
= phys_descent
;
13179 else if (new_x
> it
->first_visible_x
)
13181 /* Increment number of glyphs actually displayed. */
13184 if (x
< it
->first_visible_x
)
13185 /* Glyph is partially visible, i.e. row starts at
13186 negative X position. */
13187 row
->x
= x
- it
->first_visible_x
;
13191 /* Glyph is completely off the left margin of the
13192 window. This should not happen because of the
13193 move_it_in_display_line at the start of
13199 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13200 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13201 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13202 row
->phys_height
= max (row
->phys_height
,
13203 it
->max_phys_ascent
+ it
->max_phys_descent
);
13205 /* End of this display line if row is continued. */
13206 if (row
->continued_p
)
13210 /* Is this a line end? If yes, we're also done, after making
13211 sure that a non-default face is extended up to the right
13212 margin of the window. */
13213 if (ITERATOR_AT_END_OF_LINE_P (it
))
13215 int used_before
= row
->used
[TEXT_AREA
];
13217 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13219 /* Add a space at the end of the line that is used to
13220 display the cursor there. */
13221 append_space (it
, 0);
13223 /* Extend the face to the end of the line. */
13224 extend_face_to_end_of_line (it
);
13226 /* Make sure we have the position. */
13227 if (used_before
== 0)
13228 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13230 /* Consume the line end. This skips over invisible lines. */
13231 set_iterator_to_next (it
, 1);
13232 it
->continuation_lines_width
= 0;
13236 /* Proceed with next display element. Note that this skips
13237 over lines invisible because of selective display. */
13238 set_iterator_to_next (it
, 1);
13240 /* If we truncate lines, we are done when the last displayed
13241 glyphs reach past the right margin of the window. */
13242 if (it
->truncate_lines_p
13243 && (FRAME_WINDOW_P (it
->f
)
13244 ? (it
->current_x
>= it
->last_visible_x
)
13245 : (it
->current_x
> it
->last_visible_x
)))
13247 /* Maybe add truncation glyphs. */
13248 if (!FRAME_WINDOW_P (it
->f
))
13252 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13253 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13256 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13258 row
->used
[TEXT_AREA
] = i
;
13259 produce_special_glyphs (it
, IT_TRUNCATION
);
13263 row
->truncated_on_right_p
= 1;
13264 it
->continuation_lines_width
= 0;
13265 reseat_at_next_visible_line_start (it
, 0);
13266 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13267 it
->hpos
= hpos_before
;
13268 it
->current_x
= x_before
;
13273 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13274 at the left window margin. */
13275 if (it
->first_visible_x
13276 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13278 if (!FRAME_WINDOW_P (it
->f
))
13279 insert_left_trunc_glyphs (it
);
13280 row
->truncated_on_left_p
= 1;
13283 /* If the start of this line is the overlay arrow-position, then
13284 mark this glyph row as the one containing the overlay arrow.
13285 This is clearly a mess with variable size fonts. It would be
13286 better to let it be displayed like cursors under X. */
13287 if (MARKERP (Voverlay_arrow_position
)
13288 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13289 && (MATRIX_ROW_START_CHARPOS (row
)
13290 == marker_position (Voverlay_arrow_position
))
13291 && STRINGP (Voverlay_arrow_string
)
13292 && ! overlay_arrow_seen
)
13294 /* Overlay arrow in window redisplay is a fringe bitmap. */
13295 if (!FRAME_WINDOW_P (it
->f
))
13297 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13298 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13299 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13300 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13301 struct glyph
*p2
, *end
;
13303 /* Copy the arrow glyphs. */
13304 while (glyph
< arrow_end
)
13307 /* Throw away padding glyphs. */
13309 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13310 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13316 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13320 overlay_arrow_seen
= 1;
13321 row
->overlay_arrow_p
= 1;
13324 /* Compute pixel dimensions of this line. */
13325 compute_line_metrics (it
);
13327 /* Remember the position at which this line ends. */
13328 row
->end
= it
->current
;
13330 /* Maybe set the cursor. */
13331 if (it
->w
->cursor
.vpos
< 0
13332 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13333 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13334 && cursor_row_p (it
->w
, row
))
13335 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13337 /* Highlight trailing whitespace. */
13338 if (!NILP (Vshow_trailing_whitespace
))
13339 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13341 /* Prepare for the next line. This line starts horizontally at (X
13342 HPOS) = (0 0). Vertical positions are incremented. As a
13343 convenience for the caller, IT->glyph_row is set to the next
13345 it
->current_x
= it
->hpos
= 0;
13346 it
->current_y
+= row
->height
;
13349 return row
->displays_text_p
;
13354 /***********************************************************************
13356 ***********************************************************************/
13358 /* Redisplay the menu bar in the frame for window W.
13360 The menu bar of X frames that don't have X toolkit support is
13361 displayed in a special window W->frame->menu_bar_window.
13363 The menu bar of terminal frames is treated specially as far as
13364 glyph matrices are concerned. Menu bar lines are not part of
13365 windows, so the update is done directly on the frame matrix rows
13366 for the menu bar. */
13369 display_menu_bar (w
)
13372 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13377 /* Don't do all this for graphical frames. */
13379 if (!NILP (Vwindow_system
))
13382 #ifdef USE_X_TOOLKIT
13387 if (FRAME_MAC_P (f
))
13391 #ifdef USE_X_TOOLKIT
13392 xassert (!FRAME_WINDOW_P (f
));
13393 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13394 it
.first_visible_x
= 0;
13395 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13396 #else /* not USE_X_TOOLKIT */
13397 if (FRAME_WINDOW_P (f
))
13399 /* Menu bar lines are displayed in the desired matrix of the
13400 dummy window menu_bar_window. */
13401 struct window
*menu_w
;
13402 xassert (WINDOWP (f
->menu_bar_window
));
13403 menu_w
= XWINDOW (f
->menu_bar_window
);
13404 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13406 it
.first_visible_x
= 0;
13407 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13411 /* This is a TTY frame, i.e. character hpos/vpos are used as
13413 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13415 it
.first_visible_x
= 0;
13416 it
.last_visible_x
= FRAME_WIDTH (f
);
13418 #endif /* not USE_X_TOOLKIT */
13420 if (! mode_line_inverse_video
)
13421 /* Force the menu-bar to be displayed in the default face. */
13422 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13424 /* Clear all rows of the menu bar. */
13425 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13427 struct glyph_row
*row
= it
.glyph_row
+ i
;
13428 clear_glyph_row (row
);
13429 row
->enabled_p
= 1;
13430 row
->full_width_p
= 1;
13433 /* Display all items of the menu bar. */
13434 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13435 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13437 Lisp_Object string
;
13439 /* Stop at nil string. */
13440 string
= AREF (items
, i
+ 1);
13444 /* Remember where item was displayed. */
13445 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13447 /* Display the item, pad with one space. */
13448 if (it
.current_x
< it
.last_visible_x
)
13449 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13450 SCHARS (string
) + 1, 0, 0, -1);
13453 /* Fill out the line with spaces. */
13454 if (it
.current_x
< it
.last_visible_x
)
13455 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13457 /* Compute the total height of the lines. */
13458 compute_line_metrics (&it
);
13463 /***********************************************************************
13465 ***********************************************************************/
13467 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13468 FORCE is non-zero, redisplay mode lines unconditionally.
13469 Otherwise, redisplay only mode lines that are garbaged. Value is
13470 the number of windows whose mode lines were redisplayed. */
13473 redisplay_mode_lines (window
, force
)
13474 Lisp_Object window
;
13479 while (!NILP (window
))
13481 struct window
*w
= XWINDOW (window
);
13483 if (WINDOWP (w
->hchild
))
13484 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13485 else if (WINDOWP (w
->vchild
))
13486 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13488 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13489 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13491 struct text_pos lpoint
;
13492 struct buffer
*old
= current_buffer
;
13494 /* Set the window's buffer for the mode line display. */
13495 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13496 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13498 /* Point refers normally to the selected window. For any
13499 other window, set up appropriate value. */
13500 if (!EQ (window
, selected_window
))
13502 struct text_pos pt
;
13504 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13505 if (CHARPOS (pt
) < BEGV
)
13506 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13507 else if (CHARPOS (pt
) > (ZV
- 1))
13508 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13510 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13513 /* Display mode lines. */
13514 clear_glyph_matrix (w
->desired_matrix
);
13515 if (display_mode_lines (w
))
13518 w
->must_be_updated_p
= 1;
13521 /* Restore old settings. */
13522 set_buffer_internal_1 (old
);
13523 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13533 /* Display the mode and/or top line of window W. Value is the number
13534 of mode lines displayed. */
13537 display_mode_lines (w
)
13540 Lisp_Object old_selected_window
, old_selected_frame
;
13543 old_selected_frame
= selected_frame
;
13544 selected_frame
= w
->frame
;
13545 old_selected_window
= selected_window
;
13546 XSETWINDOW (selected_window
, w
);
13548 /* These will be set while the mode line specs are processed. */
13549 line_number_displayed
= 0;
13550 w
->column_number_displayed
= Qnil
;
13552 if (WINDOW_WANTS_MODELINE_P (w
))
13554 struct window
*sel_w
= XWINDOW (old_selected_window
);
13556 /* Select mode line face based on the real selected window. */
13557 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
13558 current_buffer
->mode_line_format
);
13562 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13564 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13565 current_buffer
->header_line_format
);
13569 selected_frame
= old_selected_frame
;
13570 selected_window
= old_selected_window
;
13575 /* Display mode or top line of window W. FACE_ID specifies which line
13576 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13577 FORMAT is the mode line format to display. Value is the pixel
13578 height of the mode line displayed. */
13581 display_mode_line (w
, face_id
, format
)
13583 enum face_id face_id
;
13584 Lisp_Object format
;
13589 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13590 prepare_desired_row (it
.glyph_row
);
13592 if (! mode_line_inverse_video
)
13593 /* Force the mode-line to be displayed in the default face. */
13594 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13596 /* Temporarily make frame's keyboard the current kboard so that
13597 kboard-local variables in the mode_line_format will get the right
13599 push_frame_kboard (it
.f
);
13600 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
13601 pop_frame_kboard ();
13603 /* Fill up with spaces. */
13604 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13606 compute_line_metrics (&it
);
13607 it
.glyph_row
->full_width_p
= 1;
13608 it
.glyph_row
->mode_line_p
= 1;
13609 it
.glyph_row
->continued_p
= 0;
13610 it
.glyph_row
->truncated_on_left_p
= 0;
13611 it
.glyph_row
->truncated_on_right_p
= 0;
13613 /* Make a 3D mode-line have a shadow at its right end. */
13614 face
= FACE_FROM_ID (it
.f
, face_id
);
13615 extend_face_to_end_of_line (&it
);
13616 if (face
->box
!= FACE_NO_BOX
)
13618 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13619 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13620 last
->right_box_line_p
= 1;
13623 return it
.glyph_row
->height
;
13626 /* Alist that caches the results of :propertize.
13627 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
13628 Lisp_Object mode_line_proptrans_alist
;
13630 /* List of strings making up the mode-line. */
13631 Lisp_Object mode_line_string_list
;
13633 /* Base face property when building propertized mode line string. */
13634 static Lisp_Object mode_line_string_face
;
13635 static Lisp_Object mode_line_string_face_prop
;
13638 /* Contribute ELT to the mode line for window IT->w. How it
13639 translates into text depends on its data type.
13641 IT describes the display environment in which we display, as usual.
13643 DEPTH is the depth in recursion. It is used to prevent
13644 infinite recursion here.
13646 FIELD_WIDTH is the number of characters the display of ELT should
13647 occupy in the mode line, and PRECISION is the maximum number of
13648 characters to display from ELT's representation. See
13649 display_string for details.
13651 Returns the hpos of the end of the text generated by ELT.
13653 PROPS is a property list to add to any string we encounter.
13655 If RISKY is nonzero, remove (disregard) any properties in any string
13656 we encounter, and ignore :eval and :propertize.
13658 If the global variable `frame_title_ptr' is non-NULL, then the output
13659 is passed to `store_frame_title' instead of `display_string'. */
13662 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
13665 int field_width
, precision
;
13666 Lisp_Object elt
, props
;
13669 int n
= 0, field
, prec
;
13678 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13682 /* A string: output it and check for %-constructs within it. */
13684 unsigned char *this, *lisp_string
;
13686 if (!NILP (props
) || risky
)
13688 Lisp_Object oprops
, aelt
;
13689 oprops
= Ftext_properties_at (make_number (0), elt
);
13691 if (NILP (Fequal (props
, oprops
)) || risky
)
13693 /* If the starting string has properties,
13694 merge the specified ones onto the existing ones. */
13695 if (! NILP (oprops
) && !risky
)
13699 oprops
= Fcopy_sequence (oprops
);
13701 while (CONSP (tem
))
13703 oprops
= Fplist_put (oprops
, XCAR (tem
),
13704 XCAR (XCDR (tem
)));
13705 tem
= XCDR (XCDR (tem
));
13710 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
13711 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
13713 mode_line_proptrans_alist
13714 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
13721 elt
= Fcopy_sequence (elt
);
13722 Fset_text_properties (make_number (0), Flength (elt
),
13724 /* Add this item to mode_line_proptrans_alist. */
13725 mode_line_proptrans_alist
13726 = Fcons (Fcons (elt
, props
),
13727 mode_line_proptrans_alist
);
13728 /* Truncate mode_line_proptrans_alist
13729 to at most 50 elements. */
13730 tem
= Fnthcdr (make_number (50),
13731 mode_line_proptrans_alist
);
13733 XSETCDR (tem
, Qnil
);
13738 this = SDATA (elt
);
13739 lisp_string
= this;
13743 prec
= precision
- n
;
13744 if (frame_title_ptr
)
13745 n
+= store_frame_title (SDATA (elt
), -1, prec
);
13746 else if (!NILP (mode_line_string_list
))
13747 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
13749 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
13750 0, prec
, 0, STRING_MULTIBYTE (elt
));
13755 while ((precision
<= 0 || n
< precision
)
13757 && (frame_title_ptr
13758 || !NILP (mode_line_string_list
)
13759 || it
->current_x
< it
->last_visible_x
))
13761 unsigned char *last
= this;
13763 /* Advance to end of string or next format specifier. */
13764 while ((c
= *this++) != '\0' && c
!= '%')
13767 if (this - 1 != last
)
13769 /* Output to end of string or up to '%'. Field width
13770 is length of string. Don't output more than
13771 PRECISION allows us. */
13774 prec
= chars_in_text (last
, this - last
);
13775 if (precision
> 0 && prec
> precision
- n
)
13776 prec
= precision
- n
;
13778 if (frame_title_ptr
)
13779 n
+= store_frame_title (last
, 0, prec
);
13780 else if (!NILP (mode_line_string_list
))
13782 int bytepos
= last
- lisp_string
;
13783 int charpos
= string_byte_to_char (elt
, bytepos
);
13784 n
+= store_mode_line_string (NULL
,
13785 Fsubstring (elt
, make_number (charpos
),
13786 make_number (charpos
+ prec
)),
13791 int bytepos
= last
- lisp_string
;
13792 int charpos
= string_byte_to_char (elt
, bytepos
);
13793 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13795 STRING_MULTIBYTE (elt
));
13798 else /* c == '%' */
13800 unsigned char *percent_position
= this;
13802 /* Get the specified minimum width. Zero means
13805 while ((c
= *this++) >= '0' && c
<= '9')
13806 field
= field
* 10 + c
- '0';
13808 /* Don't pad beyond the total padding allowed. */
13809 if (field_width
- n
> 0 && field
> field_width
- n
)
13810 field
= field_width
- n
;
13812 /* Note that either PRECISION <= 0 or N < PRECISION. */
13813 prec
= precision
- n
;
13816 n
+= display_mode_element (it
, depth
, field
, prec
,
13817 Vglobal_mode_string
, props
,
13822 int bytepos
, charpos
;
13823 unsigned char *spec
;
13825 bytepos
= percent_position
- lisp_string
;
13826 charpos
= (STRING_MULTIBYTE (elt
)
13827 ? string_byte_to_char (elt
, bytepos
)
13831 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13833 if (frame_title_ptr
)
13834 n
+= store_frame_title (spec
, field
, prec
);
13835 else if (!NILP (mode_line_string_list
))
13837 int len
= strlen (spec
);
13838 Lisp_Object tem
= make_string (spec
, len
);
13839 props
= Ftext_properties_at (make_number (charpos
), elt
);
13840 /* Should only keep face property in props */
13841 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
13845 int nglyphs_before
, nwritten
;
13847 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13848 nwritten
= display_string (spec
, Qnil
, elt
,
13853 /* Assign to the glyphs written above the
13854 string where the `%x' came from, position
13858 struct glyph
*glyph
13859 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13863 for (i
= 0; i
< nwritten
; ++i
)
13865 glyph
[i
].object
= elt
;
13866 glyph
[i
].charpos
= charpos
;
13881 /* A symbol: process the value of the symbol recursively
13882 as if it appeared here directly. Avoid error if symbol void.
13883 Special case: if value of symbol is a string, output the string
13886 register Lisp_Object tem
;
13888 /* If the variable is not marked as risky to set
13889 then its contents are risky to use. */
13890 if (NILP (Fget (elt
, Qrisky_local_variable
)))
13893 tem
= Fboundp (elt
);
13896 tem
= Fsymbol_value (elt
);
13897 /* If value is a string, output that string literally:
13898 don't check for % within it. */
13902 if (!EQ (tem
, elt
))
13904 /* Give up right away for nil or t. */
13914 register Lisp_Object car
, tem
;
13916 /* A cons cell: five distinct cases.
13917 If first element is :eval or :propertize, do something special.
13918 If first element is a string or a cons, process all the elements
13919 and effectively concatenate them.
13920 If first element is a negative number, truncate displaying cdr to
13921 at most that many characters. If positive, pad (with spaces)
13922 to at least that many characters.
13923 If first element is a symbol, process the cadr or caddr recursively
13924 according to whether the symbol's value is non-nil or nil. */
13926 if (EQ (car
, QCeval
))
13928 /* An element of the form (:eval FORM) means evaluate FORM
13929 and use the result as mode line elements. */
13934 if (CONSP (XCDR (elt
)))
13937 spec
= safe_eval (XCAR (XCDR (elt
)));
13938 n
+= display_mode_element (it
, depth
, field_width
- n
,
13939 precision
- n
, spec
, props
,
13943 else if (EQ (car
, QCpropertize
))
13945 /* An element of the form (:propertize ELT PROPS...)
13946 means display ELT but applying properties PROPS. */
13951 if (CONSP (XCDR (elt
)))
13952 n
+= display_mode_element (it
, depth
, field_width
- n
,
13953 precision
- n
, XCAR (XCDR (elt
)),
13954 XCDR (XCDR (elt
)), risky
);
13956 else if (SYMBOLP (car
))
13958 tem
= Fboundp (car
);
13962 /* elt is now the cdr, and we know it is a cons cell.
13963 Use its car if CAR has a non-nil value. */
13966 tem
= Fsymbol_value (car
);
13973 /* Symbol's value is nil (or symbol is unbound)
13974 Get the cddr of the original list
13975 and if possible find the caddr and use that. */
13979 else if (!CONSP (elt
))
13984 else if (INTEGERP (car
))
13986 register int lim
= XINT (car
);
13990 /* Negative int means reduce maximum width. */
13991 if (precision
<= 0)
13994 precision
= min (precision
, -lim
);
13998 /* Padding specified. Don't let it be more than
13999 current maximum. */
14001 lim
= min (precision
, lim
);
14003 /* If that's more padding than already wanted, queue it.
14004 But don't reduce padding already specified even if
14005 that is beyond the current truncation point. */
14006 field_width
= max (lim
, field_width
);
14010 else if (STRINGP (car
) || CONSP (car
))
14012 register int limit
= 50;
14013 /* Limit is to protect against circular lists. */
14016 && (precision
<= 0 || n
< precision
))
14018 n
+= display_mode_element (it
, depth
, field_width
- n
,
14019 precision
- n
, XCAR (elt
),
14029 if (frame_title_ptr
)
14030 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
14031 else if (!NILP (mode_line_string_list
))
14032 n
+= store_mode_line_string ("*invalid*", Qnil
, 0, 0, precision
- n
, Qnil
);
14034 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
14035 precision
- n
, 0, 0);
14039 /* Pad to FIELD_WIDTH. */
14040 if (field_width
> 0 && n
< field_width
)
14042 if (frame_title_ptr
)
14043 n
+= store_frame_title ("", field_width
- n
, 0);
14044 else if (!NILP (mode_line_string_list
))
14045 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
14047 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
14054 /* Store a mode-line string element in mode_line_string_list.
14056 If STRING is non-null, display that C string. Otherwise, the Lisp
14057 string LISP_STRING is displayed.
14059 FIELD_WIDTH is the minimum number of output glyphs to produce.
14060 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14061 with spaces. FIELD_WIDTH <= 0 means don't pad.
14063 PRECISION is the maximum number of characters to output from
14064 STRING. PRECISION <= 0 means don't truncate the string.
14066 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
14067 properties to the string.
14069 PROPS are the properties to add to the string.
14070 The mode_line_string_face face property is always added to the string.
14073 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
14075 Lisp_Object lisp_string
;
14084 if (string
!= NULL
)
14086 len
= strlen (string
);
14087 if (precision
> 0 && len
> precision
)
14089 lisp_string
= make_string (string
, len
);
14091 props
= mode_line_string_face_prop
;
14092 else if (!NILP (mode_line_string_face
))
14094 Lisp_Object face
= Fplist_get (props
, Qface
);
14095 props
= Fcopy_sequence (props
);
14097 face
= mode_line_string_face
;
14099 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14100 props
= Fplist_put (props
, Qface
, face
);
14102 Fadd_text_properties (make_number (0), make_number (len
),
14103 props
, lisp_string
);
14107 len
= XFASTINT (Flength (lisp_string
));
14108 if (precision
> 0 && len
> precision
)
14111 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
14114 if (!NILP (mode_line_string_face
))
14118 props
= Ftext_properties_at (make_number (0), lisp_string
);
14119 face
= Fplist_get (props
, Qface
);
14121 face
= mode_line_string_face
;
14123 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14124 props
= Fcons (Qface
, Fcons (face
, Qnil
));
14126 lisp_string
= Fcopy_sequence (lisp_string
);
14129 Fadd_text_properties (make_number (0), make_number (len
),
14130 props
, lisp_string
);
14135 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14139 if (field_width
> len
)
14141 field_width
-= len
;
14142 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
14144 Fadd_text_properties (make_number (0), make_number (field_width
),
14145 props
, lisp_string
);
14146 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14154 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
14156 doc
: /* Return the mode-line of selected window as a string.
14157 First optional arg FORMAT specifies a different format string (see
14158 `mode-line-format' for details) to use. If FORMAT is t, return
14159 the buffer's header-line. Second optional arg WINDOW specifies a
14160 different window to use as the context for the formatting.
14161 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
14162 (format
, window
, no_props
)
14163 Lisp_Object format
, window
, no_props
;
14169 struct buffer
*old_buffer
= NULL
;
14170 enum face_id face_id
= DEFAULT_FACE_ID
;
14173 window
= selected_window
;
14174 CHECK_WINDOW (window
);
14175 w
= XWINDOW (window
);
14176 CHECK_BUFFER (w
->buffer
);
14178 if (XBUFFER (w
->buffer
) != current_buffer
)
14180 old_buffer
= current_buffer
;
14181 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14184 if (NILP (format
) || EQ (format
, Qt
))
14186 face_id
= NILP (format
)
14187 ? CURRENT_MODE_LINE_FACE_ID (w
) :
14188 HEADER_LINE_FACE_ID
;
14189 format
= NILP (format
)
14190 ? current_buffer
->mode_line_format
14191 : current_buffer
->header_line_format
;
14194 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14196 if (NILP (no_props
))
14198 mode_line_string_face
=
14199 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
14200 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
14201 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
14203 mode_line_string_face_prop
=
14204 NILP (mode_line_string_face
) ? Qnil
:
14205 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
14207 /* We need a dummy last element in mode_line_string_list to
14208 indicate we are building the propertized mode-line string.
14209 Using mode_line_string_face_prop here GC protects it. */
14210 mode_line_string_list
=
14211 Fcons (mode_line_string_face_prop
, Qnil
);
14212 frame_title_ptr
= NULL
;
14216 mode_line_string_face_prop
= Qnil
;
14217 mode_line_string_list
= Qnil
;
14218 frame_title_ptr
= frame_title_buf
;
14221 push_frame_kboard (it
.f
);
14222 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14223 pop_frame_kboard ();
14226 set_buffer_internal_1 (old_buffer
);
14228 if (NILP (no_props
))
14231 mode_line_string_list
= Fnreverse (mode_line_string_list
);
14232 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
14233 make_string ("", 0));
14234 mode_line_string_face_prop
= Qnil
;
14235 mode_line_string_list
= Qnil
;
14239 len
= frame_title_ptr
- frame_title_buf
;
14240 if (len
> 0 && frame_title_ptr
[-1] == '-')
14242 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
14243 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
14245 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
14246 if (len
> frame_title_ptr
- frame_title_buf
)
14247 len
= frame_title_ptr
- frame_title_buf
;
14250 frame_title_ptr
= NULL
;
14251 return make_string (frame_title_buf
, len
);
14254 /* Write a null-terminated, right justified decimal representation of
14255 the positive integer D to BUF using a minimal field width WIDTH. */
14258 pint2str (buf
, width
, d
)
14259 register char *buf
;
14260 register int width
;
14263 register char *p
= buf
;
14271 *p
++ = d
% 10 + '0';
14276 for (width
-= (int) (p
- buf
); width
> 0; --width
)
14287 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
14288 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
14289 type of CODING_SYSTEM. Return updated pointer into BUF. */
14291 static unsigned char invalid_eol_type
[] = "(*invalid*)";
14294 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
14295 Lisp_Object coding_system
;
14296 register char *buf
;
14300 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
14301 unsigned char *eol_str
;
14303 /* The EOL conversion we are using. */
14304 Lisp_Object eoltype
;
14306 val
= Fget (coding_system
, Qcoding_system
);
14309 if (!VECTORP (val
)) /* Not yet decided. */
14314 eoltype
= eol_mnemonic_undecided
;
14315 /* Don't mention EOL conversion if it isn't decided. */
14319 Lisp_Object eolvalue
;
14321 eolvalue
= Fget (coding_system
, Qeol_type
);
14324 *buf
++ = XFASTINT (AREF (val
, 1));
14328 /* The EOL conversion that is normal on this system. */
14330 if (NILP (eolvalue
)) /* Not yet decided. */
14331 eoltype
= eol_mnemonic_undecided
;
14332 else if (VECTORP (eolvalue
)) /* Not yet decided. */
14333 eoltype
= eol_mnemonic_undecided
;
14334 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
14335 eoltype
= (XFASTINT (eolvalue
) == 0
14336 ? eol_mnemonic_unix
14337 : (XFASTINT (eolvalue
) == 1
14338 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
14344 /* Mention the EOL conversion if it is not the usual one. */
14345 if (STRINGP (eoltype
))
14347 eol_str
= SDATA (eoltype
);
14348 eol_str_len
= SBYTES (eoltype
);
14350 else if (INTEGERP (eoltype
)
14351 && CHAR_VALID_P (XINT (eoltype
), 0))
14353 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
14354 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
14358 eol_str
= invalid_eol_type
;
14359 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14361 bcopy (eol_str
, buf
, eol_str_len
);
14362 buf
+= eol_str_len
;
14368 /* Return a string for the output of a mode line %-spec for window W,
14369 generated by character C. PRECISION >= 0 means don't return a
14370 string longer than that value. FIELD_WIDTH > 0 means pad the
14371 string returned with spaces to that value. Return 1 in *MULTIBYTE
14372 if the result is multibyte text. */
14374 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14377 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14380 int field_width
, precision
;
14384 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14385 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14386 struct buffer
*b
= XBUFFER (w
->buffer
);
14394 if (!NILP (b
->read_only
))
14396 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14401 /* This differs from %* only for a modified read-only buffer. */
14402 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14404 if (!NILP (b
->read_only
))
14409 /* This differs from %* in ignoring read-only-ness. */
14410 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14422 if (command_loop_level
> 5)
14424 p
= decode_mode_spec_buf
;
14425 for (i
= 0; i
< command_loop_level
; i
++)
14428 return decode_mode_spec_buf
;
14436 if (command_loop_level
> 5)
14438 p
= decode_mode_spec_buf
;
14439 for (i
= 0; i
< command_loop_level
; i
++)
14442 return decode_mode_spec_buf
;
14449 /* Let lots_of_dashes be a string of infinite length. */
14450 if (!NILP (mode_line_string_list
))
14452 if (field_width
<= 0
14453 || field_width
> sizeof (lots_of_dashes
))
14455 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
14456 decode_mode_spec_buf
[i
] = '-';
14457 decode_mode_spec_buf
[i
] = '\0';
14458 return decode_mode_spec_buf
;
14461 return lots_of_dashes
;
14470 int col
= (int) current_column (); /* iftc */
14471 w
->column_number_displayed
= make_number (col
);
14472 pint2str (decode_mode_spec_buf
, field_width
, col
);
14473 return decode_mode_spec_buf
;
14477 /* %F displays the frame name. */
14478 if (!NILP (f
->title
))
14479 return (char *) SDATA (f
->title
);
14480 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14481 return (char *) SDATA (f
->name
);
14490 int startpos
= XMARKER (w
->start
)->charpos
;
14491 int startpos_byte
= marker_byte_position (w
->start
);
14492 int line
, linepos
, linepos_byte
, topline
;
14494 int height
= XFASTINT (w
->height
);
14496 /* If we decided that this buffer isn't suitable for line numbers,
14497 don't forget that too fast. */
14498 if (EQ (w
->base_line_pos
, w
->buffer
))
14500 /* But do forget it, if the window shows a different buffer now. */
14501 else if (BUFFERP (w
->base_line_pos
))
14502 w
->base_line_pos
= Qnil
;
14504 /* If the buffer is very big, don't waste time. */
14505 if (INTEGERP (Vline_number_display_limit
)
14506 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14508 w
->base_line_pos
= Qnil
;
14509 w
->base_line_number
= Qnil
;
14513 if (!NILP (w
->base_line_number
)
14514 && !NILP (w
->base_line_pos
)
14515 && XFASTINT (w
->base_line_pos
) <= startpos
)
14517 line
= XFASTINT (w
->base_line_number
);
14518 linepos
= XFASTINT (w
->base_line_pos
);
14519 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14524 linepos
= BUF_BEGV (b
);
14525 linepos_byte
= BUF_BEGV_BYTE (b
);
14528 /* Count lines from base line to window start position. */
14529 nlines
= display_count_lines (linepos
, linepos_byte
,
14533 topline
= nlines
+ line
;
14535 /* Determine a new base line, if the old one is too close
14536 or too far away, or if we did not have one.
14537 "Too close" means it's plausible a scroll-down would
14538 go back past it. */
14539 if (startpos
== BUF_BEGV (b
))
14541 w
->base_line_number
= make_number (topline
);
14542 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14544 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14545 || linepos
== BUF_BEGV (b
))
14547 int limit
= BUF_BEGV (b
);
14548 int limit_byte
= BUF_BEGV_BYTE (b
);
14550 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14552 if (startpos
- distance
> limit
)
14554 limit
= startpos
- distance
;
14555 limit_byte
= CHAR_TO_BYTE (limit
);
14558 nlines
= display_count_lines (startpos
, startpos_byte
,
14560 - (height
* 2 + 30),
14562 /* If we couldn't find the lines we wanted within
14563 line_number_display_limit_width chars per line,
14564 give up on line numbers for this window. */
14565 if (position
== limit_byte
&& limit
== startpos
- distance
)
14567 w
->base_line_pos
= w
->buffer
;
14568 w
->base_line_number
= Qnil
;
14572 w
->base_line_number
= make_number (topline
- nlines
);
14573 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14576 /* Now count lines from the start pos to point. */
14577 nlines
= display_count_lines (startpos
, startpos_byte
,
14578 PT_BYTE
, PT
, &junk
);
14580 /* Record that we did display the line number. */
14581 line_number_displayed
= 1;
14583 /* Make the string to show. */
14584 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14585 return decode_mode_spec_buf
;
14588 char* p
= decode_mode_spec_buf
;
14589 int pad
= field_width
- 2;
14595 return decode_mode_spec_buf
;
14601 obj
= b
->mode_name
;
14605 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14611 int pos
= marker_position (w
->start
);
14612 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14614 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14616 if (pos
<= BUF_BEGV (b
))
14621 else if (pos
<= BUF_BEGV (b
))
14625 if (total
> 1000000)
14626 /* Do it differently for a large value, to avoid overflow. */
14627 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14629 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14630 /* We can't normally display a 3-digit number,
14631 so get us a 2-digit number that is close. */
14634 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14635 return decode_mode_spec_buf
;
14639 /* Display percentage of size above the bottom of the screen. */
14642 int toppos
= marker_position (w
->start
);
14643 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14644 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14646 if (botpos
>= BUF_ZV (b
))
14648 if (toppos
<= BUF_BEGV (b
))
14655 if (total
> 1000000)
14656 /* Do it differently for a large value, to avoid overflow. */
14657 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14659 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14660 /* We can't normally display a 3-digit number,
14661 so get us a 2-digit number that is close. */
14664 if (toppos
<= BUF_BEGV (b
))
14665 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14667 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14668 return decode_mode_spec_buf
;
14673 /* status of process */
14674 obj
= Fget_buffer_process (w
->buffer
);
14676 return "no process";
14677 #ifdef subprocesses
14678 obj
= Fsymbol_name (Fprocess_status (obj
));
14682 case 't': /* indicate TEXT or BINARY */
14683 #ifdef MODE_LINE_BINARY_TEXT
14684 return MODE_LINE_BINARY_TEXT (b
);
14690 /* coding-system (not including end-of-line format) */
14692 /* coding-system (including end-of-line type) */
14694 int eol_flag
= (c
== 'Z');
14695 char *p
= decode_mode_spec_buf
;
14697 if (! FRAME_WINDOW_P (f
))
14699 /* No need to mention EOL here--the terminal never needs
14700 to do EOL conversion. */
14701 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14702 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14704 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14707 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14708 #ifdef subprocesses
14709 obj
= Fget_buffer_process (Fcurrent_buffer ());
14710 if (PROCESSP (obj
))
14712 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14714 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14717 #endif /* subprocesses */
14720 return decode_mode_spec_buf
;
14726 *multibyte
= STRING_MULTIBYTE (obj
);
14727 return (char *) SDATA (obj
);
14734 /* Count up to COUNT lines starting from START / START_BYTE.
14735 But don't go beyond LIMIT_BYTE.
14736 Return the number of lines thus found (always nonnegative).
14738 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14741 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14742 int start
, start_byte
, limit_byte
, count
;
14745 register unsigned char *cursor
;
14746 unsigned char *base
;
14748 register int ceiling
;
14749 register unsigned char *ceiling_addr
;
14750 int orig_count
= count
;
14752 /* If we are not in selective display mode,
14753 check only for newlines. */
14754 int selective_display
= (!NILP (current_buffer
->selective_display
)
14755 && !INTEGERP (current_buffer
->selective_display
));
14759 while (start_byte
< limit_byte
)
14761 ceiling
= BUFFER_CEILING_OF (start_byte
);
14762 ceiling
= min (limit_byte
- 1, ceiling
);
14763 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14764 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14767 if (selective_display
)
14768 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14771 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14774 if (cursor
!= ceiling_addr
)
14778 start_byte
+= cursor
- base
+ 1;
14779 *byte_pos_ptr
= start_byte
;
14783 if (++cursor
== ceiling_addr
)
14789 start_byte
+= cursor
- base
;
14794 while (start_byte
> limit_byte
)
14796 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14797 ceiling
= max (limit_byte
, ceiling
);
14798 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14799 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14802 if (selective_display
)
14803 while (--cursor
!= ceiling_addr
14804 && *cursor
!= '\n' && *cursor
!= 015)
14807 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14810 if (cursor
!= ceiling_addr
)
14814 start_byte
+= cursor
- base
+ 1;
14815 *byte_pos_ptr
= start_byte
;
14816 /* When scanning backwards, we should
14817 not count the newline posterior to which we stop. */
14818 return - orig_count
- 1;
14824 /* Here we add 1 to compensate for the last decrement
14825 of CURSOR, which took it past the valid range. */
14826 start_byte
+= cursor
- base
+ 1;
14830 *byte_pos_ptr
= limit_byte
;
14833 return - orig_count
+ count
;
14834 return orig_count
- count
;
14840 /***********************************************************************
14842 ***********************************************************************/
14844 /* Display a NUL-terminated string, starting with index START.
14846 If STRING is non-null, display that C string. Otherwise, the Lisp
14847 string LISP_STRING is displayed.
14849 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14850 FACE_STRING. Display STRING or LISP_STRING with the face at
14851 FACE_STRING_POS in FACE_STRING:
14853 Display the string in the environment given by IT, but use the
14854 standard display table, temporarily.
14856 FIELD_WIDTH is the minimum number of output glyphs to produce.
14857 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14858 with spaces. If STRING has more characters, more than FIELD_WIDTH
14859 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14861 PRECISION is the maximum number of characters to output from
14862 STRING. PRECISION < 0 means don't truncate the string.
14864 This is roughly equivalent to printf format specifiers:
14866 FIELD_WIDTH PRECISION PRINTF
14867 ----------------------------------------
14873 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14874 display them, and < 0 means obey the current buffer's value of
14875 enable_multibyte_characters.
14877 Value is the number of glyphs produced. */
14880 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14881 start
, it
, field_width
, precision
, max_x
, multibyte
)
14882 unsigned char *string
;
14883 Lisp_Object lisp_string
;
14884 Lisp_Object face_string
;
14885 int face_string_pos
;
14888 int field_width
, precision
, max_x
;
14891 int hpos_at_start
= it
->hpos
;
14892 int saved_face_id
= it
->face_id
;
14893 struct glyph_row
*row
= it
->glyph_row
;
14895 /* Initialize the iterator IT for iteration over STRING beginning
14896 with index START. */
14897 reseat_to_string (it
, string
, lisp_string
, start
,
14898 precision
, field_width
, multibyte
);
14900 /* If displaying STRING, set up the face of the iterator
14901 from LISP_STRING, if that's given. */
14902 if (STRINGP (face_string
))
14908 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14909 0, it
->region_beg_charpos
,
14910 it
->region_end_charpos
,
14911 &endptr
, it
->base_face_id
, 0);
14912 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14913 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14916 /* Set max_x to the maximum allowed X position. Don't let it go
14917 beyond the right edge of the window. */
14919 max_x
= it
->last_visible_x
;
14921 max_x
= min (max_x
, it
->last_visible_x
);
14923 /* Skip over display elements that are not visible. because IT->w is
14925 if (it
->current_x
< it
->first_visible_x
)
14926 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14927 MOVE_TO_POS
| MOVE_TO_X
);
14929 row
->ascent
= it
->max_ascent
;
14930 row
->height
= it
->max_ascent
+ it
->max_descent
;
14931 row
->phys_ascent
= it
->max_phys_ascent
;
14932 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14934 /* This condition is for the case that we are called with current_x
14935 past last_visible_x. */
14936 while (it
->current_x
< max_x
)
14938 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14940 /* Get the next display element. */
14941 if (!get_next_display_element (it
))
14944 /* Produce glyphs. */
14945 x_before
= it
->current_x
;
14946 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14947 PRODUCE_GLYPHS (it
);
14949 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14952 while (i
< nglyphs
)
14954 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14956 if (!it
->truncate_lines_p
14957 && x
+ glyph
->pixel_width
> max_x
)
14959 /* End of continued line or max_x reached. */
14960 if (CHAR_GLYPH_PADDING_P (*glyph
))
14962 /* A wide character is unbreakable. */
14963 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14964 it
->current_x
= x_before
;
14968 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14973 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14975 /* Glyph is at least partially visible. */
14977 if (x
< it
->first_visible_x
)
14978 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14982 /* Glyph is off the left margin of the display area.
14983 Should not happen. */
14987 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14988 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14989 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14990 row
->phys_height
= max (row
->phys_height
,
14991 it
->max_phys_ascent
+ it
->max_phys_descent
);
14992 x
+= glyph
->pixel_width
;
14996 /* Stop if max_x reached. */
15000 /* Stop at line ends. */
15001 if (ITERATOR_AT_END_OF_LINE_P (it
))
15003 it
->continuation_lines_width
= 0;
15007 set_iterator_to_next (it
, 1);
15009 /* Stop if truncating at the right edge. */
15010 if (it
->truncate_lines_p
15011 && it
->current_x
>= it
->last_visible_x
)
15013 /* Add truncation mark, but don't do it if the line is
15014 truncated at a padding space. */
15015 if (IT_CHARPOS (*it
) < it
->string_nchars
)
15017 if (!FRAME_WINDOW_P (it
->f
))
15021 if (it
->current_x
> it
->last_visible_x
)
15023 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15024 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15026 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15028 row
->used
[TEXT_AREA
] = i
;
15029 produce_special_glyphs (it
, IT_TRUNCATION
);
15032 produce_special_glyphs (it
, IT_TRUNCATION
);
15034 it
->glyph_row
->truncated_on_right_p
= 1;
15040 /* Maybe insert a truncation at the left. */
15041 if (it
->first_visible_x
15042 && IT_CHARPOS (*it
) > 0)
15044 if (!FRAME_WINDOW_P (it
->f
))
15045 insert_left_trunc_glyphs (it
);
15046 it
->glyph_row
->truncated_on_left_p
= 1;
15049 it
->face_id
= saved_face_id
;
15051 /* Value is number of columns displayed. */
15052 return it
->hpos
- hpos_at_start
;
15057 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
15058 appears as an element of LIST or as the car of an element of LIST.
15059 If PROPVAL is a list, compare each element against LIST in that
15060 way, and return 1/2 if any element of PROPVAL is found in LIST.
15061 Otherwise return 0. This function cannot quit.
15062 The return value is 2 if the text is invisible but with an ellipsis
15063 and 1 if it's invisible and without an ellipsis. */
15066 invisible_p (propval
, list
)
15067 register Lisp_Object propval
;
15070 register Lisp_Object tail
, proptail
;
15072 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15074 register Lisp_Object tem
;
15076 if (EQ (propval
, tem
))
15078 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
15079 return NILP (XCDR (tem
)) ? 1 : 2;
15082 if (CONSP (propval
))
15084 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
15086 Lisp_Object propelt
;
15087 propelt
= XCAR (proptail
);
15088 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15090 register Lisp_Object tem
;
15092 if (EQ (propelt
, tem
))
15094 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
15095 return NILP (XCDR (tem
)) ? 1 : 2;
15104 /***********************************************************************
15106 ***********************************************************************/
15111 Vwith_echo_area_save_vector
= Qnil
;
15112 staticpro (&Vwith_echo_area_save_vector
);
15114 Vmessage_stack
= Qnil
;
15115 staticpro (&Vmessage_stack
);
15117 Qinhibit_redisplay
= intern ("inhibit-redisplay");
15118 staticpro (&Qinhibit_redisplay
);
15120 message_dolog_marker1
= Fmake_marker ();
15121 staticpro (&message_dolog_marker1
);
15122 message_dolog_marker2
= Fmake_marker ();
15123 staticpro (&message_dolog_marker2
);
15124 message_dolog_marker3
= Fmake_marker ();
15125 staticpro (&message_dolog_marker3
);
15128 defsubr (&Sdump_frame_glyph_matrix
);
15129 defsubr (&Sdump_glyph_matrix
);
15130 defsubr (&Sdump_glyph_row
);
15131 defsubr (&Sdump_tool_bar_row
);
15132 defsubr (&Strace_redisplay
);
15133 defsubr (&Strace_to_stderr
);
15135 #ifdef HAVE_WINDOW_SYSTEM
15136 defsubr (&Stool_bar_lines_needed
);
15138 defsubr (&Sformat_mode_line
);
15140 staticpro (&Qmenu_bar_update_hook
);
15141 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
15143 staticpro (&Qoverriding_terminal_local_map
);
15144 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
15146 staticpro (&Qoverriding_local_map
);
15147 Qoverriding_local_map
= intern ("overriding-local-map");
15149 staticpro (&Qwindow_scroll_functions
);
15150 Qwindow_scroll_functions
= intern ("window-scroll-functions");
15152 staticpro (&Qredisplay_end_trigger_functions
);
15153 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
15155 staticpro (&Qinhibit_point_motion_hooks
);
15156 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
15158 QCdata
= intern (":data");
15159 staticpro (&QCdata
);
15160 Qdisplay
= intern ("display");
15161 staticpro (&Qdisplay
);
15162 Qspace_width
= intern ("space-width");
15163 staticpro (&Qspace_width
);
15164 Qraise
= intern ("raise");
15165 staticpro (&Qraise
);
15166 Qspace
= intern ("space");
15167 staticpro (&Qspace
);
15168 Qmargin
= intern ("margin");
15169 staticpro (&Qmargin
);
15170 Qleft_margin
= intern ("left-margin");
15171 staticpro (&Qleft_margin
);
15172 Qright_margin
= intern ("right-margin");
15173 staticpro (&Qright_margin
);
15174 Qalign_to
= intern ("align-to");
15175 staticpro (&Qalign_to
);
15176 QCalign_to
= intern (":align-to");
15177 staticpro (&QCalign_to
);
15178 Qrelative_width
= intern ("relative-width");
15179 staticpro (&Qrelative_width
);
15180 QCrelative_width
= intern (":relative-width");
15181 staticpro (&QCrelative_width
);
15182 QCrelative_height
= intern (":relative-height");
15183 staticpro (&QCrelative_height
);
15184 QCeval
= intern (":eval");
15185 staticpro (&QCeval
);
15186 QCpropertize
= intern (":propertize");
15187 staticpro (&QCpropertize
);
15188 Qwhen
= intern ("when");
15189 staticpro (&Qwhen
);
15190 QCfile
= intern (":file");
15191 staticpro (&QCfile
);
15192 Qfontified
= intern ("fontified");
15193 staticpro (&Qfontified
);
15194 Qfontification_functions
= intern ("fontification-functions");
15195 staticpro (&Qfontification_functions
);
15196 Qtrailing_whitespace
= intern ("trailing-whitespace");
15197 staticpro (&Qtrailing_whitespace
);
15198 Qimage
= intern ("image");
15199 staticpro (&Qimage
);
15200 Qmessage_truncate_lines
= intern ("message-truncate-lines");
15201 staticpro (&Qmessage_truncate_lines
);
15202 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
15203 staticpro (&Qcursor_in_non_selected_windows
);
15204 Qgrow_only
= intern ("grow-only");
15205 staticpro (&Qgrow_only
);
15206 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
15207 staticpro (&Qinhibit_menubar_update
);
15208 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
15209 staticpro (&Qinhibit_eval_during_redisplay
);
15210 Qposition
= intern ("position");
15211 staticpro (&Qposition
);
15212 Qbuffer_position
= intern ("buffer-position");
15213 staticpro (&Qbuffer_position
);
15214 Qobject
= intern ("object");
15215 staticpro (&Qobject
);
15216 Qrisky_local_variable
= intern ("risky-local-variable");
15217 staticpro (&Qrisky_local_variable
);
15219 list_of_error
= Fcons (intern ("error"), Qnil
);
15220 staticpro (&list_of_error
);
15222 last_arrow_position
= Qnil
;
15223 last_arrow_string
= Qnil
;
15224 staticpro (&last_arrow_position
);
15225 staticpro (&last_arrow_string
);
15227 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
15228 staticpro (&echo_buffer
[0]);
15229 staticpro (&echo_buffer
[1]);
15231 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
15232 staticpro (&echo_area_buffer
[0]);
15233 staticpro (&echo_area_buffer
[1]);
15235 Vmessages_buffer_name
= build_string ("*Messages*");
15236 staticpro (&Vmessages_buffer_name
);
15238 mode_line_proptrans_alist
= Qnil
;
15239 staticpro (&mode_line_proptrans_alist
);
15241 mode_line_string_list
= Qnil
;
15242 staticpro (&mode_line_string_list
);
15244 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
15245 doc
: /* Non-nil means highlight trailing whitespace.
15246 The face used for trailing whitespace is `trailing-whitespace'. */);
15247 Vshow_trailing_whitespace
= Qnil
;
15249 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
15250 doc
: /* Non-nil means don't actually do any redisplay.
15251 This is used for internal purposes. */);
15252 Vinhibit_redisplay
= Qnil
;
15254 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
15255 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
15256 Vglobal_mode_string
= Qnil
;
15258 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
15259 doc
: /* Marker for where to display an arrow on top of the buffer text.
15260 This must be the beginning of a line in order to work.
15261 See also `overlay-arrow-string'. */);
15262 Voverlay_arrow_position
= Qnil
;
15264 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
15265 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
15266 Voverlay_arrow_string
= Qnil
;
15268 DEFVAR_INT ("scroll-step", &scroll_step
,
15269 doc
: /* *The number of lines to try scrolling a window by when point moves out.
15270 If that fails to bring point back on frame, point is centered instead.
15271 If this is zero, point is always centered after it moves off frame.
15272 If you want scrolling to always be a line at a time, you should set
15273 `scroll-conservatively' to a large value rather than set this to 1. */);
15275 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
15276 doc
: /* *Scroll up to this many lines, to bring point back on screen.
15277 A value of zero means to scroll the text to center point vertically
15278 in the window. */);
15279 scroll_conservatively
= 0;
15281 DEFVAR_INT ("scroll-margin", &scroll_margin
,
15282 doc
: /* *Number of lines of margin at the top and bottom of a window.
15283 Recenter the window whenever point gets within this many lines
15284 of the top or bottom of the window. */);
15288 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
15291 DEFVAR_BOOL ("truncate-partial-width-windows",
15292 &truncate_partial_width_windows
,
15293 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
15294 truncate_partial_width_windows
= 1;
15296 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
15297 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
15298 Any other value means to use the appropriate face, `mode-line',
15299 `header-line', or `menu' respectively.
15301 This variable is deprecated; please change the above faces instead. */);
15302 mode_line_inverse_video
= 1;
15304 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
15305 doc
: /* *Maximum buffer size for which line number should be displayed.
15306 If the buffer is bigger than this, the line number does not appear
15307 in the mode line. A value of nil means no limit. */);
15308 Vline_number_display_limit
= Qnil
;
15310 DEFVAR_INT ("line-number-display-limit-width",
15311 &line_number_display_limit_width
,
15312 doc
: /* *Maximum line width (in characters) for line number display.
15313 If the average length of the lines near point is bigger than this, then the
15314 line number may be omitted from the mode line. */);
15315 line_number_display_limit_width
= 200;
15317 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
15318 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
15319 highlight_nonselected_windows
= 0;
15321 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
15322 doc
: /* Non-nil if more than one frame is visible on this display.
15323 Minibuffer-only frames don't count, but iconified frames do.
15324 This variable is not guaranteed to be accurate except while processing
15325 `frame-title-format' and `icon-title-format'. */);
15327 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
15328 doc
: /* Template for displaying the title bar of visible frames.
15329 \(Assuming the window manager supports this feature.)
15330 This variable has the same structure as `mode-line-format' (which see),
15331 and is used only on frames for which no explicit name has been set
15332 \(see `modify-frame-parameters'). */);
15333 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
15334 doc
: /* Template for displaying the title bar of an iconified frame.
15335 \(Assuming the window manager supports this feature.)
15336 This variable has the same structure as `mode-line-format' (which see),
15337 and is used only on frames for which no explicit name has been set
15338 \(see `modify-frame-parameters'). */);
15340 = Vframe_title_format
15341 = Fcons (intern ("multiple-frames"),
15342 Fcons (build_string ("%b"),
15343 Fcons (Fcons (empty_string
,
15344 Fcons (intern ("invocation-name"),
15345 Fcons (build_string ("@"),
15346 Fcons (intern ("system-name"),
15350 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
15351 doc
: /* Maximum number of lines to keep in the message log buffer.
15352 If nil, disable message logging. If t, log messages but don't truncate
15353 the buffer when it becomes large. */);
15354 Vmessage_log_max
= make_number (50);
15356 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
15357 doc
: /* Functions called before redisplay, if window sizes have changed.
15358 The value should be a list of functions that take one argument.
15359 Just before redisplay, for each frame, if any of its windows have changed
15360 size since the last redisplay, or have been split or deleted,
15361 all the functions in the list are called, with the frame as argument. */);
15362 Vwindow_size_change_functions
= Qnil
;
15364 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
15365 doc
: /* List of Functions to call before redisplaying a window with scrolling.
15366 Each function is called with two arguments, the window
15367 and its new display-start position. Note that the value of `window-end'
15368 is not valid when these functions are called. */);
15369 Vwindow_scroll_functions
= Qnil
;
15371 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
15372 doc
: /* *Non-nil means automatically resize tool-bars.
15373 This increases a tool-bar's height if not all tool-bar items are visible.
15374 It decreases a tool-bar's height when it would display blank lines
15376 auto_resize_tool_bars_p
= 1;
15378 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
15379 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
15380 auto_raise_tool_bar_buttons_p
= 1;
15382 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
15383 doc
: /* *Margin around tool-bar buttons in pixels.
15384 If an integer, use that for both horizontal and vertical margins.
15385 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
15386 HORZ specifying the horizontal margin, and VERT specifying the
15387 vertical margin. */);
15388 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
15390 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
15391 doc
: /* *Relief thickness of tool-bar buttons. */);
15392 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
15394 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
15395 doc
: /* List of functions to call to fontify regions of text.
15396 Each function is called with one argument POS. Functions must
15397 fontify a region starting at POS in the current buffer, and give
15398 fontified regions the property `fontified'. */);
15399 Vfontification_functions
= Qnil
;
15400 Fmake_variable_buffer_local (Qfontification_functions
);
15402 DEFVAR_BOOL ("unibyte-display-via-language-environment",
15403 &unibyte_display_via_language_environment
,
15404 doc
: /* *Non-nil means display unibyte text according to language environment.
15405 Specifically this means that unibyte non-ASCII characters
15406 are displayed by converting them to the equivalent multibyte characters
15407 according to the current language environment. As a result, they are
15408 displayed according to the current fontset. */);
15409 unibyte_display_via_language_environment
= 0;
15411 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
15412 doc
: /* *Maximum height for resizing mini-windows.
15413 If a float, it specifies a fraction of the mini-window frame's height.
15414 If an integer, it specifies a number of lines. */);
15415 Vmax_mini_window_height
= make_float (0.25);
15417 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
15418 doc
: /* *How to resize mini-windows.
15419 A value of nil means don't automatically resize mini-windows.
15420 A value of t means resize them to fit the text displayed in them.
15421 A value of `grow-only', the default, means let mini-windows grow
15422 only, until their display becomes empty, at which point the windows
15423 go back to their normal size. */);
15424 Vresize_mini_windows
= Qgrow_only
;
15426 DEFVAR_BOOL ("cursor-in-non-selected-windows",
15427 &cursor_in_non_selected_windows
,
15428 doc
: /* *Non-nil means display a hollow cursor in non-selected windows.
15429 nil means don't display a cursor there. */);
15430 cursor_in_non_selected_windows
= 1;
15432 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
15433 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
15434 automatic_hscrolling_p
= 1;
15436 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
15437 doc
: /* *How many columns away from the window edge point is allowed to get
15438 before automatic hscrolling will horizontally scroll the window. */);
15439 hscroll_margin
= 5;
15441 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
15442 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
15443 When point is less than `automatic-hscroll-margin' columns from the window
15444 edge, automatic hscrolling will scroll the window by the amount of columns
15445 determined by this variable. If its value is a positive integer, scroll that
15446 many columns. If it's a positive floating-point number, it specifies the
15447 fraction of the window's width to scroll. If it's nil or zero, point will be
15448 centered horizontally after the scroll. Any other value, including negative
15449 numbers, are treated as if the value were zero.
15451 Automatic hscrolling always moves point outside the scroll margin, so if
15452 point was more than scroll step columns inside the margin, the window will
15453 scroll more than the value given by the scroll step.
15455 Note that the lower bound for automatic hscrolling specified by `scroll-left'
15456 and `scroll-right' overrides this variable's effect. */);
15457 Vhscroll_step
= make_number (0);
15459 DEFVAR_LISP ("image-types", &Vimage_types
,
15460 doc
: /* List of supported image types.
15461 Each element of the list is a symbol for a supported image type. */);
15462 Vimage_types
= Qnil
;
15464 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
15465 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
15466 Bind this around calls to `message' to let it take effect. */);
15467 message_truncate_lines
= 0;
15469 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
15470 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
15471 Can be used to update submenus whose contents should vary. */);
15472 Vmenu_bar_update_hook
= Qnil
;
15474 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
15475 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
15476 inhibit_menubar_update
= 0;
15478 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
15479 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
15480 inhibit_eval_during_redisplay
= 0;
15483 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
15484 doc
: /* Inhibit try_window_id display optimization. */);
15485 inhibit_try_window_id
= 0;
15487 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
15488 doc
: /* Inhibit try_window_reusing display optimization. */);
15489 inhibit_try_window_reusing
= 0;
15491 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
15492 doc
: /* Inhibit try_cursor_movement display optimization. */);
15493 inhibit_try_cursor_movement
= 0;
15494 #endif /* GLYPH_DEBUG */
15498 /* Initialize this module when Emacs starts. */
15503 Lisp_Object root_window
;
15504 struct window
*mini_w
;
15506 current_header_line_height
= current_mode_line_height
= -1;
15508 CHARPOS (this_line_start_pos
) = 0;
15510 mini_w
= XWINDOW (minibuf_window
);
15511 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
15513 if (!noninteractive
)
15515 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
15518 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
15519 set_window_height (root_window
,
15520 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
15522 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
15523 set_window_height (minibuf_window
, 1, 0);
15525 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
15526 mini_w
->width
= make_number (FRAME_WIDTH (f
));
15528 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
15529 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
15530 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
15532 /* The default ellipsis glyphs `...'. */
15533 for (i
= 0; i
< 3; ++i
)
15534 default_invis_vector
[i
] = make_number ('.');
15538 /* Allocate the buffer for frame titles.
15539 Also used for `format-mode-line'. */
15541 frame_title_buf
= (char *) xmalloc (size
);
15542 frame_title_buf_end
= frame_title_buf
+ size
;
15543 frame_title_ptr
= NULL
;
15546 help_echo_showing_p
= 0;