1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* 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"
179 #include "character.h"
182 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
192 #ifdef HAVE_X_WINDOWS
202 #define INFINITY 10000000
204 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
205 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
206 extern int pending_menu_activation
;
209 extern int interrupt_input
;
210 extern int command_loop_level
;
212 extern int minibuffer_auto_raise
;
214 extern Lisp_Object Qface
;
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 /* Functions called to fontify regions of text. */
232 Lisp_Object Vfontification_functions
;
233 Lisp_Object Qfontification_functions
;
235 /* Non-zero means draw tool bar buttons raised when the mouse moves
238 int auto_raise_tool_bar_buttons_p
;
240 /* Margin around tool bar buttons in pixels. */
242 Lisp_Object Vtool_bar_button_margin
;
244 /* Thickness of shadow to draw around tool bar buttons. */
246 int tool_bar_button_relief
;
248 /* Non-zero means automatically resize tool-bars so that all tool-bar
249 items are visible, and no blank lines remain. */
251 int auto_resize_tool_bars_p
;
253 /* Non-nil means don't actually do any redisplay. */
255 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
257 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
259 int inhibit_eval_during_redisplay
;
261 /* Names of text properties relevant for redisplay. */
263 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
264 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
266 /* Symbols used in text property values. */
268 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
269 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
271 extern Lisp_Object Qheight
;
273 /* Non-nil means highlight trailing whitespace. */
275 Lisp_Object Vshow_trailing_whitespace
;
277 /* Name of the face used to highlight trailing whitespace. */
279 Lisp_Object Qtrailing_whitespace
;
281 /* The symbol `image' which is the car of the lists used to represent
286 /* Non-zero means print newline to stdout before next mini-buffer
289 int noninteractive_need_newline
;
291 /* Non-zero means print newline to message log before next message. */
293 static int message_log_need_newline
;
295 /* Three markers that message_dolog uses.
296 It could allocate them itself, but that causes trouble
297 in handling memory-full errors. */
298 static Lisp_Object message_dolog_marker1
;
299 static Lisp_Object message_dolog_marker2
;
300 static Lisp_Object message_dolog_marker3
;
302 /* The buffer position of the first character appearing entirely or
303 partially on the line of the selected window which contains the
304 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
305 redisplay optimization in redisplay_internal. */
307 static struct text_pos this_line_start_pos
;
309 /* Number of characters past the end of the line above, including the
310 terminating newline. */
312 static struct text_pos this_line_end_pos
;
314 /* The vertical positions and the height of this line. */
316 static int this_line_vpos
;
317 static int this_line_y
;
318 static int this_line_pixel_height
;
320 /* X position at which this display line starts. Usually zero;
321 negative if first character is partially visible. */
323 static int this_line_start_x
;
325 /* Buffer that this_line_.* variables are referring to. */
327 static struct buffer
*this_line_buffer
;
329 /* Nonzero means truncate lines in all windows less wide than the
332 int truncate_partial_width_windows
;
334 /* A flag to control how to display unibyte 8-bit character. */
336 int unibyte_display_via_language_environment
;
338 /* Nonzero means we have more than one non-mini-buffer-only frame.
339 Not guaranteed to be accurate except while parsing
340 frame-title-format. */
344 Lisp_Object Vglobal_mode_string
;
346 /* Marker for where to display an arrow on top of the buffer text. */
348 Lisp_Object Voverlay_arrow_position
;
350 /* String to display for the arrow. Only used on terminal frames. */
352 Lisp_Object Voverlay_arrow_string
;
354 /* Values of those variables at last redisplay. However, if
355 Voverlay_arrow_position is a marker, last_arrow_position is its
356 numerical position. */
358 static Lisp_Object last_arrow_position
, last_arrow_string
;
360 /* Like mode-line-format, but for the title bar on a visible frame. */
362 Lisp_Object Vframe_title_format
;
364 /* Like mode-line-format, but for the title bar on an iconified frame. */
366 Lisp_Object Vicon_title_format
;
368 /* List of functions to call when a window's size changes. These
369 functions get one arg, a frame on which one or more windows' sizes
372 static Lisp_Object Vwindow_size_change_functions
;
374 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
376 /* Nonzero if overlay arrow has been displayed once in this window. */
378 static int overlay_arrow_seen
;
380 /* Nonzero means highlight the region even in nonselected windows. */
382 int highlight_nonselected_windows
;
384 /* If cursor motion alone moves point off frame, try scrolling this
385 many lines up or down if that will bring it back. */
387 static int scroll_step
;
389 /* Nonzero means scroll just far enough to bring point back on the
390 screen, when appropriate. */
392 static int scroll_conservatively
;
394 /* Recenter the window whenever point gets within this many lines of
395 the top or bottom of the window. This value is translated into a
396 pixel value by multiplying it with CANON_Y_UNIT, which means that
397 there is really a fixed pixel height scroll margin. */
401 /* Number of windows showing the buffer of the selected window (or
402 another buffer with the same base buffer). keyboard.c refers to
407 /* Vector containing glyphs for an ellipsis `...'. */
409 static Lisp_Object default_invis_vector
[3];
411 /* Zero means display the mode-line/header-line/menu-bar in the default face
412 (this slightly odd definition is for compatibility with previous versions
413 of emacs), non-zero means display them using their respective faces.
415 This variable is deprecated. */
417 int mode_line_inverse_video
;
419 /* Prompt to display in front of the mini-buffer contents. */
421 Lisp_Object minibuf_prompt
;
423 /* Width of current mini-buffer prompt. Only set after display_line
424 of the line that contains the prompt. */
426 int minibuf_prompt_width
;
427 int minibuf_prompt_pixel_width
;
429 /* This is the window where the echo area message was displayed. It
430 is always a mini-buffer window, but it may not be the same window
431 currently active as a mini-buffer. */
433 Lisp_Object echo_area_window
;
435 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
436 pushes the current message and the value of
437 message_enable_multibyte on the stack, the function restore_message
438 pops the stack and displays MESSAGE again. */
440 Lisp_Object Vmessage_stack
;
442 /* Nonzero means multibyte characters were enabled when the echo area
443 message was specified. */
445 int message_enable_multibyte
;
447 /* Nonzero if we should redraw the mode lines on the next redisplay. */
449 int update_mode_lines
;
451 /* Nonzero if window sizes or contents have changed since last
452 redisplay that finished. */
454 int windows_or_buffers_changed
;
456 /* Nonzero after display_mode_line if %l was used and it displayed a
459 int line_number_displayed
;
461 /* Maximum buffer size for which to display line numbers. */
463 Lisp_Object Vline_number_display_limit
;
465 /* Line width to consider when repositioning for line number display. */
467 static int line_number_display_limit_width
;
469 /* Number of lines to keep in the message log buffer. t means
470 infinite. nil means don't log at all. */
472 Lisp_Object Vmessage_log_max
;
474 /* The name of the *Messages* buffer, a string. */
476 static Lisp_Object Vmessages_buffer_name
;
478 /* Current, index 0, and last displayed echo area message. Either
479 buffers from echo_buffers, or nil to indicate no message. */
481 Lisp_Object echo_area_buffer
[2];
483 /* The buffers referenced from echo_area_buffer. */
485 static Lisp_Object echo_buffer
[2];
487 /* A vector saved used in with_area_buffer to reduce consing. */
489 static Lisp_Object Vwith_echo_area_save_vector
;
491 /* Non-zero means display_echo_area should display the last echo area
492 message again. Set by redisplay_preserve_echo_area. */
494 static int display_last_displayed_message_p
;
496 /* Nonzero if echo area is being used by print; zero if being used by
499 int message_buf_print
;
501 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
503 Lisp_Object Qinhibit_menubar_update
;
504 int inhibit_menubar_update
;
506 /* Maximum height for resizing mini-windows. Either a float
507 specifying a fraction of the available height, or an integer
508 specifying a number of lines. */
510 Lisp_Object Vmax_mini_window_height
;
512 /* Non-zero means messages should be displayed with truncated
513 lines instead of being continued. */
515 int message_truncate_lines
;
516 Lisp_Object Qmessage_truncate_lines
;
518 /* Set to 1 in clear_message to make redisplay_internal aware
519 of an emptied echo area. */
521 static int message_cleared_p
;
523 /* Non-zero means we want a hollow cursor in windows that are not
524 selected. Zero means there's no cursor in such windows. */
526 int cursor_in_non_selected_windows
;
527 Lisp_Object Qcursor_in_non_selected_windows
;
529 /* A scratch glyph row with contents used for generating truncation
530 glyphs. Also used in direct_output_for_insert. */
532 #define MAX_SCRATCH_GLYPHS 100
533 struct glyph_row scratch_glyph_row
;
534 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
536 /* Ascent and height of the last line processed by move_it_to. */
538 static int last_max_ascent
, last_height
;
540 /* Non-zero if there's a help-echo in the echo area. */
542 int help_echo_showing_p
;
544 /* If >= 0, computed, exact values of mode-line and header-line height
545 to use in the macros CURRENT_MODE_LINE_HEIGHT and
546 CURRENT_HEADER_LINE_HEIGHT. */
548 int current_mode_line_height
, current_header_line_height
;
550 /* The maximum distance to look ahead for text properties. Values
551 that are too small let us call compute_char_face and similar
552 functions too often which is expensive. Values that are too large
553 let us call compute_char_face and alike too often because we
554 might not be interested in text properties that far away. */
556 #define TEXT_PROP_DISTANCE_LIMIT 100
560 /* Variables to turn off display optimizations from Lisp. */
562 int inhibit_try_window_id
, inhibit_try_window_reusing
;
563 int inhibit_try_cursor_movement
;
565 /* Non-zero means print traces of redisplay if compiled with
568 int trace_redisplay_p
;
570 #endif /* GLYPH_DEBUG */
572 #ifdef DEBUG_TRACE_MOVE
573 /* Non-zero means trace with TRACE_MOVE to stderr. */
576 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
578 #define TRACE_MOVE(x) (void) 0
581 /* Non-zero means automatically scroll windows horizontally to make
584 int automatic_hscrolling_p
;
586 /* How close to the margin can point get before the window is scrolled
588 int automatic_hscroll_margin
;
590 /* How much to scroll horizontally when point is inside the above margin. */
591 Lisp_Object Vautomatic_hscroll_step
;
593 /* A list of symbols, one for each supported image type. */
595 Lisp_Object Vimage_types
;
597 /* The variable `resize-mini-windows'. If nil, don't resize
598 mini-windows. If t, always resize them to fit the text they
599 display. If `grow-only', let mini-windows grow only until they
602 Lisp_Object Vresize_mini_windows
;
604 /* Buffer being redisplayed -- for redisplay_window_error. */
606 struct buffer
*displayed_buffer
;
608 /* Value returned from text property handlers (see below). */
613 HANDLED_RECOMPUTE_PROPS
,
614 HANDLED_OVERLAY_STRING_CONSUMED
,
618 /* A description of text properties that redisplay is interested
623 /* The name of the property. */
626 /* A unique index for the property. */
629 /* A handler function called to set up iterator IT from the property
630 at IT's current position. Value is used to steer handle_stop. */
631 enum prop_handled (*handler
) P_ ((struct it
*it
));
634 static enum prop_handled handle_face_prop
P_ ((struct it
*));
635 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
636 static enum prop_handled handle_display_prop
P_ ((struct it
*));
637 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
638 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
639 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
640 static enum prop_handled handle_auto_composed_prop
P_ ((struct it
*));
642 /* Properties handled by iterators. */
644 static struct props it_props
[] =
646 {&Qauto_composed
, AUTO_COMPOSED_PROP_IDX
, handle_auto_composed_prop
},
647 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
648 /* Handle `face' before `display' because some sub-properties of
649 `display' need to know the face. */
650 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
651 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
652 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
653 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
657 /* Value is the position described by X. If X is a marker, value is
658 the marker_position of X. Otherwise, value is X. */
660 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
662 /* Enumeration returned by some move_it_.* functions internally. */
666 /* Not used. Undefined value. */
669 /* Move ended at the requested buffer position or ZV. */
670 MOVE_POS_MATCH_OR_ZV
,
672 /* Move ended at the requested X pixel position. */
675 /* Move within a line ended at the end of a line that must be
679 /* Move within a line ended at the end of a line that would
680 be displayed truncated. */
683 /* Move within a line ended at a line end. */
689 /* Function prototypes. */
691 static void setup_for_ellipsis
P_ ((struct it
*));
692 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
693 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
694 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
695 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
696 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
697 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
700 static int invisible_text_between_p
P_ ((struct it
*, int, int));
703 static int next_element_from_ellipsis
P_ ((struct it
*));
704 static void pint2str
P_ ((char *, int, int));
705 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
707 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
708 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
709 static void store_frame_title_char
P_ ((char));
710 static int store_frame_title
P_ ((unsigned char *, int, int));
711 static void x_consider_frame_title
P_ ((Lisp_Object
));
712 static void handle_stop
P_ ((struct it
*));
713 static int tool_bar_lines_needed
P_ ((struct frame
*));
714 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
715 static void ensure_echo_area_buffers
P_ ((void));
716 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
717 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
718 static int with_echo_area_buffer
P_ ((struct window
*, int,
719 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
720 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
721 static void clear_garbaged_frames
P_ ((void));
722 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
723 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
724 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
725 static int display_echo_area
P_ ((struct window
*));
726 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
727 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
728 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
729 static int string_char_and_length
P_ ((unsigned char *, int, int *));
730 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
732 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
733 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
734 static void insert_left_trunc_glyphs
P_ ((struct it
*));
735 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
736 static void extend_face_to_end_of_line
P_ ((struct it
*));
737 static int append_space
P_ ((struct it
*, int));
738 static int make_cursor_line_fully_visible
P_ ((struct window
*));
739 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
740 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
741 static int trailing_whitespace_p
P_ ((int));
742 static int message_log_check_duplicate
P_ ((int, int, int, int));
743 static void push_it
P_ ((struct it
*));
744 static void pop_it
P_ ((struct it
*));
745 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
746 static void redisplay_internal
P_ ((int));
747 static int echo_area_display
P_ ((int));
748 static void redisplay_windows
P_ ((Lisp_Object
));
749 static void redisplay_window
P_ ((Lisp_Object
, int));
750 static Lisp_Object
redisplay_window_error ();
751 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
752 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
753 static void update_menu_bar
P_ ((struct frame
*, int));
754 static int try_window_reusing_current_matrix
P_ ((struct window
*));
755 static int try_window_id
P_ ((struct window
*));
756 static int display_line
P_ ((struct it
*));
757 static int display_mode_lines
P_ ((struct window
*));
758 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
759 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
));
760 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
761 static void display_menu_bar
P_ ((struct window
*));
762 static int display_count_lines
P_ ((int, int, int, int, int *));
763 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
764 int, int, struct it
*, int, int, int, int));
765 static void compute_line_metrics
P_ ((struct it
*));
766 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
767 static int get_overlay_strings
P_ ((struct it
*, int));
768 static void next_overlay_string
P_ ((struct it
*));
769 static void reseat
P_ ((struct it
*, struct text_pos
, int));
770 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
771 static void back_to_previous_visible_line_start
P_ ((struct it
*));
772 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
773 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
774 static int next_element_from_display_vector
P_ ((struct it
*));
775 static int next_element_from_string
P_ ((struct it
*));
776 static int next_element_from_c_string
P_ ((struct it
*));
777 static int next_element_from_buffer
P_ ((struct it
*));
778 static int next_element_from_composition
P_ ((struct it
*));
779 static int next_element_from_image
P_ ((struct it
*));
780 static int next_element_from_stretch
P_ ((struct it
*));
781 static void load_overlay_strings
P_ ((struct it
*, int));
782 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
783 struct display_pos
*));
784 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
785 Lisp_Object
, int, int, int, int));
786 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
788 void move_it_vertically_backward
P_ ((struct it
*, int));
789 static void init_to_row_start
P_ ((struct it
*, struct window
*,
790 struct glyph_row
*));
791 static int init_to_row_end
P_ ((struct it
*, struct window
*,
792 struct glyph_row
*));
793 static void back_to_previous_line_start
P_ ((struct it
*));
794 static int forward_to_next_line_start
P_ ((struct it
*, int *));
795 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
797 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
798 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
799 static int number_of_chars
P_ ((unsigned char *, int));
800 static void compute_stop_pos
P_ ((struct it
*));
801 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
803 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
804 static int next_overlay_change
P_ ((int));
805 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
806 Lisp_Object
, struct text_pos
*,
808 static int underlying_face_id
P_ ((struct it
*));
809 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
812 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
813 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
815 #ifdef HAVE_WINDOW_SYSTEM
817 static void update_tool_bar
P_ ((struct frame
*, int));
818 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
819 static int redisplay_tool_bar
P_ ((struct frame
*));
820 static void display_tool_bar_line
P_ ((struct it
*));
822 #endif /* HAVE_WINDOW_SYSTEM */
825 /***********************************************************************
826 Window display dimensions
827 ***********************************************************************/
829 /* Return the window-relative maximum y + 1 for glyph rows displaying
830 text in window W. This is the height of W minus the height of a
831 mode line, if any. */
834 window_text_bottom_y (w
)
837 struct frame
*f
= XFRAME (w
->frame
);
838 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
840 if (WINDOW_WANTS_MODELINE_P (w
))
841 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
846 /* Return the pixel width of display area AREA of window W. AREA < 0
847 means return the total width of W, not including fringes to
848 the left and right of the window. */
851 window_box_width (w
, area
)
855 struct frame
*f
= XFRAME (w
->frame
);
856 int width
= XFASTINT (w
->width
);
858 if (!w
->pseudo_window_p
)
860 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
862 if (area
== TEXT_AREA
)
864 if (INTEGERP (w
->left_margin_width
))
865 width
-= XFASTINT (w
->left_margin_width
);
866 if (INTEGERP (w
->right_margin_width
))
867 width
-= XFASTINT (w
->right_margin_width
);
869 else if (area
== LEFT_MARGIN_AREA
)
870 width
= (INTEGERP (w
->left_margin_width
)
871 ? XFASTINT (w
->left_margin_width
) : 0);
872 else if (area
== RIGHT_MARGIN_AREA
)
873 width
= (INTEGERP (w
->right_margin_width
)
874 ? XFASTINT (w
->right_margin_width
) : 0);
877 return width
* CANON_X_UNIT (f
);
881 /* Return the pixel height of the display area of window W, not
882 including mode lines of W, if any. */
885 window_box_height (w
)
888 struct frame
*f
= XFRAME (w
->frame
);
889 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
891 xassert (height
>= 0);
893 /* Note: the code below that determines the mode-line/header-line
894 height is essentially the same as that contained in the macro
895 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
896 the appropriate glyph row has its `mode_line_p' flag set,
897 and if it doesn't, uses estimate_mode_line_height instead. */
899 if (WINDOW_WANTS_MODELINE_P (w
))
901 struct glyph_row
*ml_row
902 = (w
->current_matrix
&& w
->current_matrix
->rows
903 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
905 if (ml_row
&& ml_row
->mode_line_p
)
906 height
-= ml_row
->height
;
908 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
911 if (WINDOW_WANTS_HEADER_LINE_P (w
))
913 struct glyph_row
*hl_row
914 = (w
->current_matrix
&& w
->current_matrix
->rows
915 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
917 if (hl_row
&& hl_row
->mode_line_p
)
918 height
-= hl_row
->height
;
920 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
923 /* With a very small font and a mode-line that's taller than
924 default, we might end up with a negative height. */
925 return max (0, height
);
929 /* Return the frame-relative coordinate of the left edge of display
930 area AREA of window W. AREA < 0 means return the left edge of the
931 whole window, to the right of the left fringe of W. */
934 window_box_left (w
, area
)
938 struct frame
*f
= XFRAME (w
->frame
);
939 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
941 if (!w
->pseudo_window_p
)
943 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
944 + FRAME_LEFT_FRINGE_WIDTH (f
));
946 if (area
== TEXT_AREA
)
947 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
948 else if (area
== RIGHT_MARGIN_AREA
)
949 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
950 + window_box_width (w
, TEXT_AREA
));
957 /* Return the frame-relative coordinate of the right edge of display
958 area AREA of window W. AREA < 0 means return the left edge of the
959 whole window, to the left of the right fringe of W. */
962 window_box_right (w
, area
)
966 return window_box_left (w
, area
) + window_box_width (w
, area
);
970 /* Get the bounding box of the display area AREA of window W, without
971 mode lines, in frame-relative coordinates. AREA < 0 means the
972 whole window, not including the left and right fringes of
973 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
974 coordinates of the upper-left corner of the box. Return in
975 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
978 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
981 int *box_x
, *box_y
, *box_width
, *box_height
;
983 struct frame
*f
= XFRAME (w
->frame
);
985 *box_width
= window_box_width (w
, area
);
986 *box_height
= window_box_height (w
);
987 *box_x
= window_box_left (w
, area
);
988 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
989 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
990 if (WINDOW_WANTS_HEADER_LINE_P (w
))
991 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
995 /* Get the bounding box of the display area AREA of window W, without
996 mode lines. AREA < 0 means the whole window, not including the
997 left and right fringe of the window. Return in *TOP_LEFT_X
998 and TOP_LEFT_Y the frame-relative pixel coordinates of the
999 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1000 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1004 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1005 bottom_right_x
, bottom_right_y
)
1008 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1010 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1012 *bottom_right_x
+= *top_left_x
;
1013 *bottom_right_y
+= *top_left_y
;
1018 /***********************************************************************
1020 ***********************************************************************/
1022 /* Return the bottom y-position of the line the iterator IT is in.
1023 This can modify IT's settings. */
1029 int line_height
= it
->max_ascent
+ it
->max_descent
;
1030 int line_top_y
= it
->current_y
;
1032 if (line_height
== 0)
1035 line_height
= last_height
;
1036 else if (IT_CHARPOS (*it
) < ZV
)
1038 move_it_by_lines (it
, 1, 1);
1039 line_height
= (it
->max_ascent
|| it
->max_descent
1040 ? it
->max_ascent
+ it
->max_descent
1045 struct glyph_row
*row
= it
->glyph_row
;
1047 /* Use the default character height. */
1048 it
->glyph_row
= NULL
;
1049 it
->what
= IT_CHARACTER
;
1052 PRODUCE_GLYPHS (it
);
1053 line_height
= it
->ascent
+ it
->descent
;
1054 it
->glyph_row
= row
;
1058 return line_top_y
+ line_height
;
1062 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1063 1 if POS is visible and the line containing POS is fully visible.
1064 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1065 and header-lines heights. */
1068 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1070 int charpos
, *fully
, exact_mode_line_heights_p
;
1073 struct text_pos top
;
1075 struct buffer
*old_buffer
= NULL
;
1077 if (XBUFFER (w
->buffer
) != current_buffer
)
1079 old_buffer
= current_buffer
;
1080 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1083 *fully
= visible_p
= 0;
1084 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1086 /* Compute exact mode line heights, if requested. */
1087 if (exact_mode_line_heights_p
)
1089 if (WINDOW_WANTS_MODELINE_P (w
))
1090 current_mode_line_height
1091 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1092 current_buffer
->mode_line_format
);
1094 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1095 current_header_line_height
1096 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1097 current_buffer
->header_line_format
);
1100 start_display (&it
, w
, top
);
1101 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1102 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1104 /* Note that we may overshoot because of invisible text. */
1105 if (IT_CHARPOS (it
) >= charpos
)
1107 int top_y
= it
.current_y
;
1108 int bottom_y
= line_bottom_y (&it
);
1109 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1111 if (top_y
< window_top_y
)
1112 visible_p
= bottom_y
> window_top_y
;
1113 else if (top_y
< it
.last_visible_y
)
1116 *fully
= bottom_y
<= it
.last_visible_y
;
1119 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1121 move_it_by_lines (&it
, 1, 0);
1122 if (charpos
< IT_CHARPOS (it
))
1130 set_buffer_internal_1 (old_buffer
);
1132 current_header_line_height
= current_mode_line_height
= -1;
1137 /* Return the next character from STR which is MAXLEN bytes long.
1138 Return in *LEN the length of the character. This is like
1139 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1140 we find one, we return a `?', but with the length of the invalid
1144 string_char_and_length (str
, maxlen
, len
)
1150 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1151 if (!CHAR_VALID_P (c
, 1))
1152 /* We may not change the length here because other places in Emacs
1153 don't use this function, i.e. they silently accept invalid
1162 /* Given a position POS containing a valid character and byte position
1163 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1165 static struct text_pos
1166 string_pos_nchars_ahead (pos
, string
, nchars
)
1167 struct text_pos pos
;
1171 xassert (STRINGP (string
) && nchars
>= 0);
1173 if (STRING_MULTIBYTE (string
))
1175 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1176 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1181 string_char_and_length (p
, rest
, &len
);
1182 p
+= len
, rest
-= len
;
1183 xassert (rest
>= 0);
1185 BYTEPOS (pos
) += len
;
1189 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1195 /* Value is the text position, i.e. character and byte position,
1196 for character position CHARPOS in STRING. */
1198 static INLINE
struct text_pos
1199 string_pos (charpos
, string
)
1203 struct text_pos pos
;
1204 xassert (STRINGP (string
));
1205 xassert (charpos
>= 0);
1206 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1211 /* Value is a text position, i.e. character and byte position, for
1212 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1213 means recognize multibyte characters. */
1215 static struct text_pos
1216 c_string_pos (charpos
, s
, multibyte_p
)
1221 struct text_pos pos
;
1223 xassert (s
!= NULL
);
1224 xassert (charpos
>= 0);
1228 int rest
= strlen (s
), len
;
1230 SET_TEXT_POS (pos
, 0, 0);
1233 string_char_and_length (s
, rest
, &len
);
1234 s
+= len
, rest
-= len
;
1235 xassert (rest
>= 0);
1237 BYTEPOS (pos
) += len
;
1241 SET_TEXT_POS (pos
, charpos
, charpos
);
1247 /* Value is the number of characters in C string S. MULTIBYTE_P
1248 non-zero means recognize multibyte characters. */
1251 number_of_chars (s
, multibyte_p
)
1259 int rest
= strlen (s
), len
;
1260 unsigned char *p
= (unsigned char *) s
;
1262 for (nchars
= 0; rest
> 0; ++nchars
)
1264 string_char_and_length (p
, rest
, &len
);
1265 rest
-= len
, p
+= len
;
1269 nchars
= strlen (s
);
1275 /* Compute byte position NEWPOS->bytepos corresponding to
1276 NEWPOS->charpos. POS is a known position in string STRING.
1277 NEWPOS->charpos must be >= POS.charpos. */
1280 compute_string_pos (newpos
, pos
, string
)
1281 struct text_pos
*newpos
, pos
;
1284 xassert (STRINGP (string
));
1285 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1287 if (STRING_MULTIBYTE (string
))
1288 *newpos
= string_pos_nchars_ahead (pos
, string
,
1289 CHARPOS (*newpos
) - CHARPOS (pos
));
1291 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1296 /***********************************************************************
1297 Lisp form evaluation
1298 ***********************************************************************/
1300 /* Error handler for safe_eval and safe_call. */
1303 safe_eval_handler (arg
)
1306 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1311 /* Evaluate SEXPR and return the result, or nil if something went
1312 wrong. Prevent redisplay during the evaluation. */
1320 if (inhibit_eval_during_redisplay
)
1324 int count
= BINDING_STACK_SIZE ();
1325 struct gcpro gcpro1
;
1328 specbind (Qinhibit_redisplay
, Qt
);
1329 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
1332 val
= unbind_to (count
, val
);
1339 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1340 Return the result, or nil if something went wrong. Prevent
1341 redisplay during the evaluation. */
1344 safe_call (nargs
, args
)
1350 if (inhibit_eval_during_redisplay
)
1354 int count
= BINDING_STACK_SIZE ();
1355 struct gcpro gcpro1
;
1358 gcpro1
.nvars
= nargs
;
1359 specbind (Qinhibit_redisplay
, Qt
);
1360 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1363 val
= unbind_to (count
, val
);
1370 /* Call function FN with one argument ARG.
1371 Return the result, or nil if something went wrong. */
1374 safe_call1 (fn
, arg
)
1375 Lisp_Object fn
, arg
;
1377 Lisp_Object args
[2];
1380 return safe_call (2, args
);
1385 /***********************************************************************
1387 ***********************************************************************/
1391 /* Define CHECK_IT to perform sanity checks on iterators.
1392 This is for debugging. It is too slow to do unconditionally. */
1398 if (it
->method
== next_element_from_string
)
1400 xassert (STRINGP (it
->string
));
1401 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1403 else if (it
->method
== next_element_from_buffer
)
1405 /* Check that character and byte positions agree. */
1406 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1410 xassert (it
->current
.dpvec_index
>= 0);
1412 xassert (it
->current
.dpvec_index
< 0);
1415 #define CHECK_IT(IT) check_it ((IT))
1419 #define CHECK_IT(IT) (void) 0
1426 /* Check that the window end of window W is what we expect it
1427 to be---the last row in the current matrix displaying text. */
1430 check_window_end (w
)
1433 if (!MINI_WINDOW_P (w
)
1434 && !NILP (w
->window_end_valid
))
1436 struct glyph_row
*row
;
1437 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1438 XFASTINT (w
->window_end_vpos
)),
1440 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1441 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1445 #define CHECK_WINDOW_END(W) check_window_end ((W))
1447 #else /* not GLYPH_DEBUG */
1449 #define CHECK_WINDOW_END(W) (void) 0
1451 #endif /* not GLYPH_DEBUG */
1455 /***********************************************************************
1456 Iterator initialization
1457 ***********************************************************************/
1459 /* Initialize IT for displaying current_buffer in window W, starting
1460 at character position CHARPOS. CHARPOS < 0 means that no buffer
1461 position is specified which is useful when the iterator is assigned
1462 a position later. BYTEPOS is the byte position corresponding to
1463 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1465 If ROW is not null, calls to produce_glyphs with IT as parameter
1466 will produce glyphs in that row.
1468 BASE_FACE_ID is the id of a base face to use. It must be one of
1469 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1470 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1471 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1473 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1474 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1475 will be initialized to use the corresponding mode line glyph row of
1476 the desired matrix of W. */
1479 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1482 int charpos
, bytepos
;
1483 struct glyph_row
*row
;
1484 enum face_id base_face_id
;
1486 int highlight_region_p
;
1488 /* Some precondition checks. */
1489 xassert (w
!= NULL
&& it
!= NULL
);
1490 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1493 /* If face attributes have been changed since the last redisplay,
1494 free realized faces now because they depend on face definitions
1495 that might have changed. */
1496 if (face_change_count
)
1498 face_change_count
= 0;
1499 free_all_realized_faces (Qnil
);
1502 /* Use one of the mode line rows of W's desired matrix if
1506 if (base_face_id
== MODE_LINE_FACE_ID
1507 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1508 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1509 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1510 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1514 bzero (it
, sizeof *it
);
1515 it
->current
.overlay_string_index
= -1;
1516 it
->current
.dpvec_index
= -1;
1517 it
->base_face_id
= base_face_id
;
1519 /* The window in which we iterate over current_buffer: */
1520 XSETWINDOW (it
->window
, w
);
1522 it
->f
= XFRAME (w
->frame
);
1524 /* Extra space between lines (on window systems only). */
1525 if (base_face_id
== DEFAULT_FACE_ID
1526 && FRAME_WINDOW_P (it
->f
))
1528 if (NATNUMP (current_buffer
->extra_line_spacing
))
1529 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1530 else if (it
->f
->extra_line_spacing
> 0)
1531 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1534 /* If realized faces have been removed, e.g. because of face
1535 attribute changes of named faces, recompute them. When running
1536 in batch mode, the face cache of Vterminal_frame is null. If
1537 we happen to get called, make a dummy face cache. */
1542 FRAME_FACE_CACHE (it
->f
) == NULL
)
1543 init_frame_faces (it
->f
);
1544 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1545 recompute_basic_faces (it
->f
);
1547 /* Current value of the `space-width', and 'height' properties. */
1548 it
->space_width
= Qnil
;
1549 it
->font_height
= Qnil
;
1551 /* Are control characters displayed as `^C'? */
1552 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1554 /* -1 means everything between a CR and the following line end
1555 is invisible. >0 means lines indented more than this value are
1557 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1558 ? XFASTINT (current_buffer
->selective_display
)
1559 : (!NILP (current_buffer
->selective_display
)
1561 it
->selective_display_ellipsis_p
1562 = !NILP (current_buffer
->selective_display_ellipses
);
1564 /* Display table to use. */
1565 it
->dp
= window_display_table (w
);
1567 /* Are multibyte characters enabled in current_buffer? */
1568 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1570 /* Non-zero if we should highlight the region. */
1572 = (!NILP (Vtransient_mark_mode
)
1573 && !NILP (current_buffer
->mark_active
)
1574 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1576 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1577 start and end of a visible region in window IT->w. Set both to
1578 -1 to indicate no region. */
1579 if (highlight_region_p
1580 /* Maybe highlight only in selected window. */
1581 && (/* Either show region everywhere. */
1582 highlight_nonselected_windows
1583 /* Or show region in the selected window. */
1584 || w
== XWINDOW (selected_window
)
1585 /* Or show the region if we are in the mini-buffer and W is
1586 the window the mini-buffer refers to. */
1587 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1588 && WINDOWP (Vminibuf_selected_window
)
1589 && w
== XWINDOW (Vminibuf_selected_window
))))
1591 int charpos
= marker_position (current_buffer
->mark
);
1592 it
->region_beg_charpos
= min (PT
, charpos
);
1593 it
->region_end_charpos
= max (PT
, charpos
);
1596 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1598 /* Get the position at which the redisplay_end_trigger hook should
1599 be run, if it is to be run at all. */
1600 if (MARKERP (w
->redisplay_end_trigger
)
1601 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1602 it
->redisplay_end_trigger_charpos
1603 = marker_position (w
->redisplay_end_trigger
);
1604 else if (INTEGERP (w
->redisplay_end_trigger
))
1605 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1607 /* Correct bogus values of tab_width. */
1608 it
->tab_width
= XINT (current_buffer
->tab_width
);
1609 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1612 /* Are lines in the display truncated? */
1613 it
->truncate_lines_p
1614 = (base_face_id
!= DEFAULT_FACE_ID
1615 || XINT (it
->w
->hscroll
)
1616 || (truncate_partial_width_windows
1617 && !WINDOW_FULL_WIDTH_P (it
->w
))
1618 || !NILP (current_buffer
->truncate_lines
));
1620 /* Get dimensions of truncation and continuation glyphs. These are
1621 displayed as fringe bitmaps under X, so we don't need them for such
1623 if (!FRAME_WINDOW_P (it
->f
))
1625 if (it
->truncate_lines_p
)
1627 /* We will need the truncation glyph. */
1628 xassert (it
->glyph_row
== NULL
);
1629 produce_special_glyphs (it
, IT_TRUNCATION
);
1630 it
->truncation_pixel_width
= it
->pixel_width
;
1634 /* We will need the continuation glyph. */
1635 xassert (it
->glyph_row
== NULL
);
1636 produce_special_glyphs (it
, IT_CONTINUATION
);
1637 it
->continuation_pixel_width
= it
->pixel_width
;
1640 /* Reset these values to zero because the produce_special_glyphs
1641 above has changed them. */
1642 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1643 it
->phys_ascent
= it
->phys_descent
= 0;
1646 /* Set this after getting the dimensions of truncation and
1647 continuation glyphs, so that we don't produce glyphs when calling
1648 produce_special_glyphs, above. */
1649 it
->glyph_row
= row
;
1650 it
->area
= TEXT_AREA
;
1652 /* Get the dimensions of the display area. The display area
1653 consists of the visible window area plus a horizontally scrolled
1654 part to the left of the window. All x-values are relative to the
1655 start of this total display area. */
1656 if (base_face_id
!= DEFAULT_FACE_ID
)
1658 /* Mode lines, menu bar in terminal frames. */
1659 it
->first_visible_x
= 0;
1660 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1665 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1666 it
->last_visible_x
= (it
->first_visible_x
1667 + window_box_width (w
, TEXT_AREA
));
1669 /* If we truncate lines, leave room for the truncator glyph(s) at
1670 the right margin. Otherwise, leave room for the continuation
1671 glyph(s). Truncation and continuation glyphs are not inserted
1672 for window-based redisplay. */
1673 if (!FRAME_WINDOW_P (it
->f
))
1675 if (it
->truncate_lines_p
)
1676 it
->last_visible_x
-= it
->truncation_pixel_width
;
1678 it
->last_visible_x
-= it
->continuation_pixel_width
;
1681 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1682 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1685 /* Leave room for a border glyph. */
1686 if (!FRAME_WINDOW_P (it
->f
)
1687 && !WINDOW_RIGHTMOST_P (it
->w
))
1688 it
->last_visible_x
-= 1;
1690 it
->last_visible_y
= window_text_bottom_y (w
);
1692 /* For mode lines and alike, arrange for the first glyph having a
1693 left box line if the face specifies a box. */
1694 if (base_face_id
!= DEFAULT_FACE_ID
)
1698 it
->face_id
= base_face_id
;
1700 /* If we have a boxed mode line, make the first character appear
1701 with a left box line. */
1702 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1703 if (face
->box
!= FACE_NO_BOX
)
1704 it
->start_of_box_run_p
= 1;
1707 /* If a buffer position was specified, set the iterator there,
1708 getting overlays and face properties from that position. */
1709 if (charpos
>= BUF_BEG (current_buffer
))
1711 it
->end_charpos
= ZV
;
1713 IT_CHARPOS (*it
) = charpos
;
1715 /* Compute byte position if not specified. */
1716 if (bytepos
< charpos
)
1717 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1719 IT_BYTEPOS (*it
) = bytepos
;
1721 /* Compute faces etc. */
1722 reseat (it
, it
->current
.pos
, 1);
1729 /* Initialize IT for the display of window W with window start POS. */
1732 start_display (it
, w
, pos
)
1735 struct text_pos pos
;
1737 struct glyph_row
*row
;
1738 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1740 row
= w
->desired_matrix
->rows
+ first_vpos
;
1741 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1743 if (!it
->truncate_lines_p
)
1745 int start_at_line_beg_p
;
1746 int first_y
= it
->current_y
;
1748 /* If window start is not at a line start, skip forward to POS to
1749 get the correct continuation lines width. */
1750 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1751 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1752 if (!start_at_line_beg_p
)
1754 reseat_at_previous_visible_line_start (it
);
1755 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1757 /* If lines are continued, this line may end in the middle
1758 of a multi-glyph character (e.g. a control character
1759 displayed as \003, or in the middle of an overlay
1760 string). In this case move_it_to above will not have
1761 taken us to the start of the continuation line but to the
1762 end of the continued line. */
1763 if (it
->current_x
> 0)
1765 if (it
->current
.dpvec_index
>= 0
1766 || it
->current
.overlay_string_index
>= 0)
1768 set_iterator_to_next (it
, 1);
1769 move_it_in_display_line_to (it
, -1, -1, 0);
1772 it
->continuation_lines_width
+= it
->current_x
;
1775 /* We're starting a new display line, not affected by the
1776 height of the continued line, so clear the appropriate
1777 fields in the iterator structure. */
1778 it
->max_ascent
= it
->max_descent
= 0;
1779 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1781 it
->current_y
= first_y
;
1783 it
->current_x
= it
->hpos
= 0;
1787 #if 0 /* Don't assert the following because start_display is sometimes
1788 called intentionally with a window start that is not at a
1789 line start. Please leave this code in as a comment. */
1791 /* Window start should be on a line start, now. */
1792 xassert (it
->continuation_lines_width
1793 || IT_CHARPOS (it
) == BEGV
1794 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1799 /* Return 1 if POS is a position in ellipses displayed for invisible
1800 text. W is the window we display, for text property lookup. */
1803 in_ellipses_for_invisible_text_p (pos
, w
)
1804 struct display_pos
*pos
;
1807 Lisp_Object prop
, window
;
1809 int charpos
= CHARPOS (pos
->pos
);
1811 /* If POS specifies a position in a display vector, this might
1812 be for an ellipsis displayed for invisible text. We won't
1813 get the iterator set up for delivering that ellipsis unless
1814 we make sure that it gets aware of the invisible text. */
1815 if (pos
->dpvec_index
>= 0
1816 && pos
->overlay_string_index
< 0
1817 && CHARPOS (pos
->string_pos
) < 0
1819 && (XSETWINDOW (window
, w
),
1820 prop
= Fget_char_property (make_number (charpos
),
1821 Qinvisible
, window
),
1822 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1824 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1826 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1833 /* Initialize IT for stepping through current_buffer in window W,
1834 starting at position POS that includes overlay string and display
1835 vector/ control character translation position information. Value
1836 is zero if there are overlay strings with newlines at POS. */
1839 init_from_display_pos (it
, w
, pos
)
1842 struct display_pos
*pos
;
1844 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1845 int i
, overlay_strings_with_newlines
= 0;
1847 /* If POS specifies a position in a display vector, this might
1848 be for an ellipsis displayed for invisible text. We won't
1849 get the iterator set up for delivering that ellipsis unless
1850 we make sure that it gets aware of the invisible text. */
1851 if (in_ellipses_for_invisible_text_p (pos
, w
))
1857 /* Keep in mind: the call to reseat in init_iterator skips invisible
1858 text, so we might end up at a position different from POS. This
1859 is only a problem when POS is a row start after a newline and an
1860 overlay starts there with an after-string, and the overlay has an
1861 invisible property. Since we don't skip invisible text in
1862 display_line and elsewhere immediately after consuming the
1863 newline before the row start, such a POS will not be in a string,
1864 but the call to init_iterator below will move us to the
1866 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1868 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1870 char *s
= XSTRING (it
->overlay_strings
[i
])->data
;
1871 char *e
= s
+ STRING_BYTES (XSTRING (it
->overlay_strings
[i
]));
1873 while (s
< e
&& *s
!= '\n')
1878 overlay_strings_with_newlines
= 1;
1883 /* If position is within an overlay string, set up IT to the right
1885 if (pos
->overlay_string_index
>= 0)
1889 /* If the first overlay string happens to have a `display'
1890 property for an image, the iterator will be set up for that
1891 image, and we have to undo that setup first before we can
1892 correct the overlay string index. */
1893 if (it
->method
== next_element_from_image
)
1896 /* We already have the first chunk of overlay strings in
1897 IT->overlay_strings. Load more until the one for
1898 pos->overlay_string_index is in IT->overlay_strings. */
1899 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1901 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1902 it
->current
.overlay_string_index
= 0;
1905 load_overlay_strings (it
, 0);
1906 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1910 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1911 relative_index
= (it
->current
.overlay_string_index
1912 % OVERLAY_STRING_CHUNK_SIZE
);
1913 it
->string
= it
->overlay_strings
[relative_index
];
1914 xassert (STRINGP (it
->string
));
1915 it
->current
.string_pos
= pos
->string_pos
;
1916 it
->method
= next_element_from_string
;
1919 #if 0 /* This is bogus because POS not having an overlay string
1920 position does not mean it's after the string. Example: A
1921 line starting with a before-string and initialization of IT
1922 to the previous row's end position. */
1923 else if (it
->current
.overlay_string_index
>= 0)
1925 /* If POS says we're already after an overlay string ending at
1926 POS, make sure to pop the iterator because it will be in
1927 front of that overlay string. When POS is ZV, we've thereby
1928 also ``processed'' overlay strings at ZV. */
1931 it
->current
.overlay_string_index
= -1;
1932 it
->method
= next_element_from_buffer
;
1933 if (CHARPOS (pos
->pos
) == ZV
)
1934 it
->overlay_strings_at_end_processed_p
= 1;
1938 if (CHARPOS (pos
->string_pos
) >= 0)
1940 /* Recorded position is not in an overlay string, but in another
1941 string. This can only be a string from a `display' property.
1942 IT should already be filled with that string. */
1943 it
->current
.string_pos
= pos
->string_pos
;
1944 xassert (STRINGP (it
->string
));
1947 /* Restore position in display vector translations, control
1948 character translations or ellipses. */
1949 if (pos
->dpvec_index
>= 0)
1951 if (it
->dpvec
== NULL
)
1952 get_next_display_element (it
);
1953 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1954 it
->current
.dpvec_index
= pos
->dpvec_index
;
1958 return !overlay_strings_with_newlines
;
1962 /* Initialize IT for stepping through current_buffer in window W
1963 starting at ROW->start. */
1966 init_to_row_start (it
, w
, row
)
1969 struct glyph_row
*row
;
1971 init_from_display_pos (it
, w
, &row
->start
);
1972 it
->continuation_lines_width
= row
->continuation_lines_width
;
1977 /* Initialize IT for stepping through current_buffer in window W
1978 starting in the line following ROW, i.e. starting at ROW->end.
1979 Value is zero if there are overlay strings with newlines at ROW's
1983 init_to_row_end (it
, w
, row
)
1986 struct glyph_row
*row
;
1990 if (init_from_display_pos (it
, w
, &row
->end
))
1992 if (row
->continued_p
)
1993 it
->continuation_lines_width
1994 = row
->continuation_lines_width
+ row
->pixel_width
;
2005 /***********************************************************************
2007 ***********************************************************************/
2009 /* Called when IT reaches IT->stop_charpos. Handle text property and
2010 overlay changes. Set IT->stop_charpos to the next position where
2017 enum prop_handled handled
;
2018 int handle_overlay_change_p
= 1;
2022 it
->current
.dpvec_index
= -1;
2026 handled
= HANDLED_NORMALLY
;
2028 /* Call text property handlers. */
2029 for (p
= it_props
; p
->handler
; ++p
)
2031 handled
= p
->handler (it
);
2033 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2035 else if (handled
== HANDLED_RETURN
)
2037 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2038 handle_overlay_change_p
= 0;
2041 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2043 /* Don't check for overlay strings below when set to deliver
2044 characters from a display vector. */
2045 if (it
->method
== next_element_from_display_vector
)
2046 handle_overlay_change_p
= 0;
2048 /* Handle overlay changes. */
2049 if (handle_overlay_change_p
)
2050 handled
= handle_overlay_change (it
);
2052 /* Determine where to stop next. */
2053 if (handled
== HANDLED_NORMALLY
)
2054 compute_stop_pos (it
);
2057 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2061 /* Compute IT->stop_charpos from text property and overlay change
2062 information for IT's current position. */
2065 compute_stop_pos (it
)
2068 register INTERVAL iv
, next_iv
;
2069 Lisp_Object object
, limit
, position
;
2071 /* If nowhere else, stop at the end. */
2072 it
->stop_charpos
= it
->end_charpos
;
2074 if (STRINGP (it
->string
))
2076 /* Strings are usually short, so don't limit the search for
2078 object
= it
->string
;
2080 position
= make_number (IT_STRING_CHARPOS (*it
));
2086 /* If next overlay change is in front of the current stop pos
2087 (which is IT->end_charpos), stop there. Note: value of
2088 next_overlay_change is point-max if no overlay change
2090 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2091 if (charpos
< it
->stop_charpos
)
2092 it
->stop_charpos
= charpos
;
2094 /* If showing the region, we have to stop at the region
2095 start or end because the face might change there. */
2096 if (it
->region_beg_charpos
> 0)
2098 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2099 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2100 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2101 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2104 /* Set up variables for computing the stop position from text
2105 property changes. */
2106 XSETBUFFER (object
, current_buffer
);
2107 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2108 position
= make_number (IT_CHARPOS (*it
));
2112 /* Get the interval containing IT's position. Value is a null
2113 interval if there isn't such an interval. */
2114 iv
= validate_interval_range (object
, &position
, &position
, 0);
2115 if (!NULL_INTERVAL_P (iv
))
2117 Lisp_Object values_here
[LAST_PROP_IDX
];
2120 /* Get properties here. */
2121 for (p
= it_props
; p
->handler
; ++p
)
2122 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2124 /* Look for an interval following iv that has different
2126 for (next_iv
= next_interval (iv
);
2127 (!NULL_INTERVAL_P (next_iv
)
2129 || XFASTINT (limit
) > next_iv
->position
));
2130 next_iv
= next_interval (next_iv
))
2132 for (p
= it_props
; p
->handler
; ++p
)
2134 Lisp_Object new_value
;
2136 new_value
= textget (next_iv
->plist
, *p
->name
);
2137 if (!EQ (values_here
[p
->idx
], new_value
))
2145 if (!NULL_INTERVAL_P (next_iv
))
2147 if (INTEGERP (limit
)
2148 && next_iv
->position
>= XFASTINT (limit
))
2149 /* No text property change up to limit. */
2150 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2152 /* Text properties change in next_iv. */
2153 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2157 xassert (STRINGP (it
->string
)
2158 || (it
->stop_charpos
>= BEGV
2159 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2163 /* Return the position of the next overlay change after POS in
2164 current_buffer. Value is point-max if no overlay change
2165 follows. This is like `next-overlay-change' but doesn't use
2169 next_overlay_change (pos
)
2174 Lisp_Object
*overlays
;
2178 /* Get all overlays at the given position. */
2180 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2181 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2182 if (noverlays
> len
)
2185 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2186 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2189 /* If any of these overlays ends before endpos,
2190 use its ending point instead. */
2191 for (i
= 0; i
< noverlays
; ++i
)
2196 oend
= OVERLAY_END (overlays
[i
]);
2197 oendpos
= OVERLAY_POSITION (oend
);
2198 endpos
= min (endpos
, oendpos
);
2206 /***********************************************************************
2208 ***********************************************************************/
2210 /* Handle changes in the `fontified' property of the current buffer by
2211 calling hook functions from Qfontification_functions to fontify
2214 static enum prop_handled
2215 handle_fontified_prop (it
)
2218 Lisp_Object prop
, pos
;
2219 enum prop_handled handled
= HANDLED_NORMALLY
;
2221 /* Get the value of the `fontified' property at IT's current buffer
2222 position. (The `fontified' property doesn't have a special
2223 meaning in strings.) If the value is nil, call functions from
2224 Qfontification_functions. */
2225 if (!STRINGP (it
->string
)
2227 && !NILP (Vfontification_functions
)
2228 && !NILP (Vrun_hooks
)
2229 && (pos
= make_number (IT_CHARPOS (*it
)),
2230 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2233 int count
= BINDING_STACK_SIZE ();
2236 val
= Vfontification_functions
;
2237 specbind (Qfontification_functions
, Qnil
);
2239 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2240 safe_call1 (val
, pos
);
2243 Lisp_Object globals
, fn
;
2244 struct gcpro gcpro1
, gcpro2
;
2247 GCPRO2 (val
, globals
);
2249 for (; CONSP (val
); val
= XCDR (val
))
2255 /* A value of t indicates this hook has a local
2256 binding; it means to run the global binding too.
2257 In a global value, t should not occur. If it
2258 does, we must ignore it to avoid an endless
2260 for (globals
= Fdefault_value (Qfontification_functions
);
2262 globals
= XCDR (globals
))
2264 fn
= XCAR (globals
);
2266 safe_call1 (fn
, pos
);
2270 safe_call1 (fn
, pos
);
2276 unbind_to (count
, Qnil
);
2278 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2279 something. This avoids an endless loop if they failed to
2280 fontify the text for which reason ever. */
2281 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2282 handled
= HANDLED_RECOMPUTE_PROPS
;
2290 /***********************************************************************
2292 ***********************************************************************/
2294 /* Set up iterator IT from face properties at its current position.
2295 Called from handle_stop. */
2297 static enum prop_handled
2298 handle_face_prop (it
)
2301 int new_face_id
, next_stop
;
2303 if (!STRINGP (it
->string
))
2306 = face_at_buffer_position (it
->w
,
2308 it
->region_beg_charpos
,
2309 it
->region_end_charpos
,
2312 + TEXT_PROP_DISTANCE_LIMIT
),
2315 /* Is this a start of a run of characters with box face?
2316 Caveat: this can be called for a freshly initialized
2317 iterator; face_id is -1 in this case. We know that the new
2318 face will not change until limit, i.e. if the new face has a
2319 box, all characters up to limit will have one. But, as
2320 usual, we don't know whether limit is really the end. */
2321 if (new_face_id
!= it
->face_id
)
2323 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2325 /* If new face has a box but old face has not, this is
2326 the start of a run of characters with box, i.e. it has
2327 a shadow on the left side. The value of face_id of the
2328 iterator will be -1 if this is the initial call that gets
2329 the face. In this case, we have to look in front of IT's
2330 position and see whether there is a face != new_face_id. */
2331 it
->start_of_box_run_p
2332 = (new_face
->box
!= FACE_NO_BOX
2333 && (it
->face_id
>= 0
2334 || IT_CHARPOS (*it
) == BEG
2335 || new_face_id
!= face_before_it_pos (it
)));
2336 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2341 int base_face_id
, bufpos
;
2343 if (it
->current
.overlay_string_index
>= 0)
2344 bufpos
= IT_CHARPOS (*it
);
2348 /* For strings from a buffer, i.e. overlay strings or strings
2349 from a `display' property, use the face at IT's current
2350 buffer position as the base face to merge with, so that
2351 overlay strings appear in the same face as surrounding
2352 text, unless they specify their own faces. */
2353 base_face_id
= underlying_face_id (it
);
2355 new_face_id
= face_at_string_position (it
->w
,
2357 IT_STRING_CHARPOS (*it
),
2359 it
->region_beg_charpos
,
2360 it
->region_end_charpos
,
2364 #if 0 /* This shouldn't be neccessary. Let's check it. */
2365 /* If IT is used to display a mode line we would really like to
2366 use the mode line face instead of the frame's default face. */
2367 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2368 && new_face_id
== DEFAULT_FACE_ID
)
2369 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2372 /* Is this a start of a run of characters with box? Caveat:
2373 this can be called for a freshly allocated iterator; face_id
2374 is -1 is this case. We know that the new face will not
2375 change until the next check pos, i.e. if the new face has a
2376 box, all characters up to that position will have a
2377 box. But, as usual, we don't know whether that position
2378 is really the end. */
2379 if (new_face_id
!= it
->face_id
)
2381 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2382 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2384 /* If new face has a box but old face hasn't, this is the
2385 start of a run of characters with box, i.e. it has a
2386 shadow on the left side. */
2387 it
->start_of_box_run_p
2388 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2389 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2393 it
->face_id
= new_face_id
;
2394 return HANDLED_NORMALLY
;
2398 /* Return the ID of the face ``underlying'' IT's current position,
2399 which is in a string. If the iterator is associated with a
2400 buffer, return the face at IT's current buffer position.
2401 Otherwise, use the iterator's base_face_id. */
2404 underlying_face_id (it
)
2407 int face_id
= it
->base_face_id
, i
;
2409 xassert (STRINGP (it
->string
));
2411 for (i
= it
->sp
- 1; i
>= 0; --i
)
2412 if (NILP (it
->stack
[i
].string
))
2413 face_id
= it
->stack
[i
].face_id
;
2419 /* Compute the face one character before or after the current position
2420 of IT. BEFORE_P non-zero means get the face in front of IT's
2421 position. Value is the id of the face. */
2424 face_before_or_after_it_pos (it
, before_p
)
2429 int next_check_charpos
;
2430 struct text_pos pos
;
2432 xassert (it
->s
== NULL
);
2434 if (STRINGP (it
->string
))
2436 int bufpos
, base_face_id
;
2438 /* No face change past the end of the string (for the case
2439 we are padding with spaces). No face change before the
2441 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2442 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2445 /* Set pos to the position before or after IT's current position. */
2447 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2449 /* For composition, we must check the character after the
2451 pos
= (it
->what
== IT_COMPOSITION
2452 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2453 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2455 if (it
->current
.overlay_string_index
>= 0)
2456 bufpos
= IT_CHARPOS (*it
);
2460 base_face_id
= underlying_face_id (it
);
2462 /* Get the face for ASCII, or unibyte. */
2463 face_id
= face_at_string_position (it
->w
,
2467 it
->region_beg_charpos
,
2468 it
->region_end_charpos
,
2469 &next_check_charpos
,
2472 /* Correct the face for charsets different from ASCII. Do it
2473 for the multibyte case only. The face returned above is
2474 suitable for unibyte text if IT->string is unibyte. */
2475 if (STRING_MULTIBYTE (it
->string
))
2477 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2478 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2480 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2482 c
= string_char_and_length (p
, rest
, &len
);
2483 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2488 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2489 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2492 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2493 pos
= it
->current
.pos
;
2496 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2499 if (it
->what
== IT_COMPOSITION
)
2500 /* For composition, we must check the position after the
2502 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2504 INC_TEXT_POS (pos
, it
->multibyte_p
);
2507 /* Determine face for CHARSET_ASCII, or unibyte. */
2508 face_id
= face_at_buffer_position (it
->w
,
2510 it
->region_beg_charpos
,
2511 it
->region_end_charpos
,
2512 &next_check_charpos
,
2515 /* Correct the face for charsets different from ASCII. Do it
2516 for the multibyte case only. The face returned above is
2517 suitable for unibyte text if current_buffer is unibyte. */
2518 if (it
->multibyte_p
)
2520 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
2521 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2522 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2531 /***********************************************************************
2533 ***********************************************************************/
2535 /* Set up iterator IT from invisible properties at its current
2536 position. Called from handle_stop. */
2538 static enum prop_handled
2539 handle_invisible_prop (it
)
2542 enum prop_handled handled
= HANDLED_NORMALLY
;
2544 if (STRINGP (it
->string
))
2546 extern Lisp_Object Qinvisible
;
2547 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2549 /* Get the value of the invisible text property at the
2550 current position. Value will be nil if there is no such
2552 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2553 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2556 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2558 handled
= HANDLED_RECOMPUTE_PROPS
;
2560 /* Get the position at which the next change of the
2561 invisible text property can be found in IT->string.
2562 Value will be nil if the property value is the same for
2563 all the rest of IT->string. */
2564 XSETINT (limit
, XSTRING (it
->string
)->size
);
2565 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2568 /* Text at current position is invisible. The next
2569 change in the property is at position end_charpos.
2570 Move IT's current position to that position. */
2571 if (INTEGERP (end_charpos
)
2572 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2574 struct text_pos old
;
2575 old
= it
->current
.string_pos
;
2576 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2577 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2581 /* The rest of the string is invisible. If this is an
2582 overlay string, proceed with the next overlay string
2583 or whatever comes and return a character from there. */
2584 if (it
->current
.overlay_string_index
>= 0)
2586 next_overlay_string (it
);
2587 /* Don't check for overlay strings when we just
2588 finished processing them. */
2589 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2593 struct Lisp_String
*s
= XSTRING (it
->string
);
2594 IT_STRING_CHARPOS (*it
) = s
->size
;
2595 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2602 int invis_p
, newpos
, next_stop
, start_charpos
;
2603 Lisp_Object pos
, prop
, overlay
;
2605 /* First of all, is there invisible text at this position? */
2606 start_charpos
= IT_CHARPOS (*it
);
2607 pos
= make_number (IT_CHARPOS (*it
));
2608 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2610 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2612 /* If we are on invisible text, skip over it. */
2613 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2615 /* Record whether we have to display an ellipsis for the
2617 int display_ellipsis_p
= invis_p
== 2;
2619 handled
= HANDLED_RECOMPUTE_PROPS
;
2621 /* Loop skipping over invisible text. The loop is left at
2622 ZV or with IT on the first char being visible again. */
2625 /* Try to skip some invisible text. Return value is the
2626 position reached which can be equal to IT's position
2627 if there is nothing invisible here. This skips both
2628 over invisible text properties and overlays with
2629 invisible property. */
2630 newpos
= skip_invisible (IT_CHARPOS (*it
),
2631 &next_stop
, ZV
, it
->window
);
2633 /* If we skipped nothing at all we weren't at invisible
2634 text in the first place. If everything to the end of
2635 the buffer was skipped, end the loop. */
2636 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2640 /* We skipped some characters but not necessarily
2641 all there are. Check if we ended up on visible
2642 text. Fget_char_property returns the property of
2643 the char before the given position, i.e. if we
2644 get invis_p = 0, this means that the char at
2645 newpos is visible. */
2646 pos
= make_number (newpos
);
2647 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2648 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2651 /* If we ended up on invisible text, proceed to
2652 skip starting with next_stop. */
2654 IT_CHARPOS (*it
) = next_stop
;
2658 /* The position newpos is now either ZV or on visible text. */
2659 IT_CHARPOS (*it
) = newpos
;
2660 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2662 /* If there are before-strings at the start of invisible
2663 text, and the text is invisible because of a text
2664 property, arrange to show before-strings because 20.x did
2665 it that way. (If the text is invisible because of an
2666 overlay property instead of a text property, this is
2667 already handled in the overlay code.) */
2669 && get_overlay_strings (it
, start_charpos
))
2671 handled
= HANDLED_RECOMPUTE_PROPS
;
2672 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2674 else if (display_ellipsis_p
)
2675 setup_for_ellipsis (it
);
2683 /* Make iterator IT return `...' next. */
2686 setup_for_ellipsis (it
)
2690 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2692 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2693 it
->dpvec
= v
->contents
;
2694 it
->dpend
= v
->contents
+ v
->size
;
2698 /* Default `...'. */
2699 it
->dpvec
= default_invis_vector
;
2700 it
->dpend
= default_invis_vector
+ 3;
2703 /* The ellipsis display does not replace the display of the
2704 character at the new position. Indicate this by setting
2705 IT->dpvec_char_len to zero. */
2706 it
->dpvec_char_len
= 0;
2708 it
->current
.dpvec_index
= 0;
2709 it
->method
= next_element_from_display_vector
;
2714 /***********************************************************************
2716 ***********************************************************************/
2718 /* Set up iterator IT from `display' property at its current position.
2719 Called from handle_stop. */
2721 static enum prop_handled
2722 handle_display_prop (it
)
2725 Lisp_Object prop
, object
;
2726 struct text_pos
*position
;
2727 int display_replaced_p
= 0;
2729 if (STRINGP (it
->string
))
2731 object
= it
->string
;
2732 position
= &it
->current
.string_pos
;
2736 object
= it
->w
->buffer
;
2737 position
= &it
->current
.pos
;
2740 /* Reset those iterator values set from display property values. */
2741 it
->font_height
= Qnil
;
2742 it
->space_width
= Qnil
;
2745 /* We don't support recursive `display' properties, i.e. string
2746 values that have a string `display' property, that have a string
2747 `display' property etc. */
2748 if (!it
->string_from_display_prop_p
)
2749 it
->area
= TEXT_AREA
;
2751 prop
= Fget_char_property (make_number (position
->charpos
),
2754 return HANDLED_NORMALLY
;
2757 /* Simple properties. */
2758 && !EQ (XCAR (prop
), Qimage
)
2759 && !EQ (XCAR (prop
), Qspace
)
2760 && !EQ (XCAR (prop
), Qwhen
)
2761 && !EQ (XCAR (prop
), Qspace_width
)
2762 && !EQ (XCAR (prop
), Qheight
)
2763 && !EQ (XCAR (prop
), Qraise
)
2764 /* Marginal area specifications. */
2765 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2766 && !NILP (XCAR (prop
)))
2768 for (; CONSP (prop
); prop
= XCDR (prop
))
2770 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2771 position
, display_replaced_p
))
2772 display_replaced_p
= 1;
2775 else if (VECTORP (prop
))
2778 for (i
= 0; i
< ASIZE (prop
); ++i
)
2779 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2780 position
, display_replaced_p
))
2781 display_replaced_p
= 1;
2785 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2786 display_replaced_p
= 1;
2789 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2793 /* Value is the position of the end of the `display' property starting
2794 at START_POS in OBJECT. */
2796 static struct text_pos
2797 display_prop_end (it
, object
, start_pos
)
2800 struct text_pos start_pos
;
2803 struct text_pos end_pos
;
2805 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2806 Qdisplay
, object
, Qnil
);
2807 CHARPOS (end_pos
) = XFASTINT (end
);
2808 if (STRINGP (object
))
2809 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2811 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2817 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2818 is the object in which the `display' property was found. *POSITION
2819 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2820 means that we previously saw a display sub-property which already
2821 replaced text display with something else, for example an image;
2822 ignore such properties after the first one has been processed.
2824 If PROP is a `space' or `image' sub-property, set *POSITION to the
2825 end position of the `display' property.
2827 Value is non-zero if something was found which replaces the display
2828 of buffer or string text. */
2831 handle_single_display_prop (it
, prop
, object
, position
,
2832 display_replaced_before_p
)
2836 struct text_pos
*position
;
2837 int display_replaced_before_p
;
2840 int replaces_text_display_p
= 0;
2843 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2844 evaluated. If the result is nil, VALUE is ignored. */
2846 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2855 if (!NILP (form
) && !EQ (form
, Qt
))
2857 int count
= BINDING_STACK_SIZE ();
2858 struct gcpro gcpro1
;
2860 /* Bind `object' to the object having the `display' property, a
2861 buffer or string. Bind `position' to the position in the
2862 object where the property was found, and `buffer-position'
2863 to the current position in the buffer. */
2864 specbind (Qobject
, object
);
2865 specbind (Qposition
, make_number (CHARPOS (*position
)));
2866 specbind (Qbuffer_position
,
2867 make_number (STRINGP (object
)
2868 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2870 form
= safe_eval (form
);
2872 unbind_to (count
, Qnil
);
2879 && EQ (XCAR (prop
), Qheight
)
2880 && CONSP (XCDR (prop
)))
2882 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2885 /* `(height HEIGHT)'. */
2886 it
->font_height
= XCAR (XCDR (prop
));
2887 if (!NILP (it
->font_height
))
2889 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2890 int new_height
= -1;
2892 if (CONSP (it
->font_height
)
2893 && (EQ (XCAR (it
->font_height
), Qplus
)
2894 || EQ (XCAR (it
->font_height
), Qminus
))
2895 && CONSP (XCDR (it
->font_height
))
2896 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2898 /* `(+ N)' or `(- N)' where N is an integer. */
2899 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2900 if (EQ (XCAR (it
->font_height
), Qplus
))
2902 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2904 else if (FUNCTIONP (it
->font_height
))
2906 /* Call function with current height as argument.
2907 Value is the new height. */
2909 height
= safe_call1 (it
->font_height
,
2910 face
->lface
[LFACE_HEIGHT_INDEX
]);
2911 if (NUMBERP (height
))
2912 new_height
= XFLOATINT (height
);
2914 else if (NUMBERP (it
->font_height
))
2916 /* Value is a multiple of the canonical char height. */
2919 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2920 new_height
= (XFLOATINT (it
->font_height
)
2921 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2925 /* Evaluate IT->font_height with `height' bound to the
2926 current specified height to get the new height. */
2928 int count
= BINDING_STACK_SIZE ();
2930 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2931 value
= safe_eval (it
->font_height
);
2932 unbind_to (count
, Qnil
);
2934 if (NUMBERP (value
))
2935 new_height
= XFLOATINT (value
);
2939 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2942 else if (CONSP (prop
)
2943 && EQ (XCAR (prop
), Qspace_width
)
2944 && CONSP (XCDR (prop
)))
2946 /* `(space_width WIDTH)'. */
2947 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2950 value
= XCAR (XCDR (prop
));
2951 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2952 it
->space_width
= value
;
2954 else if (CONSP (prop
)
2955 && EQ (XCAR (prop
), Qraise
)
2956 && CONSP (XCDR (prop
)))
2958 /* `(raise FACTOR)'. */
2959 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2962 #ifdef HAVE_WINDOW_SYSTEM
2963 value
= XCAR (XCDR (prop
));
2964 if (NUMBERP (value
))
2966 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2967 it
->voffset
= - (XFLOATINT (value
)
2968 * (FONT_HEIGHT (face
->font
)));
2970 #endif /* HAVE_WINDOW_SYSTEM */
2972 else if (!it
->string_from_display_prop_p
)
2974 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2975 VALUE) or `((margin nil) VALUE)' or VALUE. */
2976 Lisp_Object location
, value
;
2977 struct text_pos start_pos
;
2980 /* Characters having this form of property are not displayed, so
2981 we have to find the end of the property. */
2982 start_pos
= *position
;
2983 *position
= display_prop_end (it
, object
, start_pos
);
2986 /* Let's stop at the new position and assume that all
2987 text properties change there. */
2988 it
->stop_charpos
= position
->charpos
;
2990 location
= Qunbound
;
2991 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2995 value
= XCDR (prop
);
2997 value
= XCAR (value
);
3000 if (EQ (XCAR (tem
), Qmargin
)
3001 && (tem
= XCDR (tem
),
3002 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3004 || EQ (tem
, Qleft_margin
)
3005 || EQ (tem
, Qright_margin
))))
3009 if (EQ (location
, Qunbound
))
3015 #ifdef HAVE_WINDOW_SYSTEM
3016 if (FRAME_TERMCAP_P (it
->f
))
3017 valid_p
= STRINGP (value
);
3019 valid_p
= (STRINGP (value
)
3020 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3021 || valid_image_p (value
));
3022 #else /* not HAVE_WINDOW_SYSTEM */
3023 valid_p
= STRINGP (value
);
3024 #endif /* not HAVE_WINDOW_SYSTEM */
3026 if ((EQ (location
, Qleft_margin
)
3027 || EQ (location
, Qright_margin
)
3030 && !display_replaced_before_p
)
3032 replaces_text_display_p
= 1;
3034 /* Save current settings of IT so that we can restore them
3035 when we are finished with the glyph property value. */
3038 if (NILP (location
))
3039 it
->area
= TEXT_AREA
;
3040 else if (EQ (location
, Qleft_margin
))
3041 it
->area
= LEFT_MARGIN_AREA
;
3043 it
->area
= RIGHT_MARGIN_AREA
;
3045 if (STRINGP (value
))
3048 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3049 it
->current
.overlay_string_index
= -1;
3050 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3051 it
->end_charpos
= it
->string_nchars
3052 = XSTRING (it
->string
)->size
;
3053 it
->method
= next_element_from_string
;
3054 it
->stop_charpos
= 0;
3055 it
->string_from_display_prop_p
= 1;
3056 /* Say that we haven't consumed the characters with
3057 `display' property yet. The call to pop_it in
3058 set_iterator_to_next will clean this up. */
3059 *position
= start_pos
;
3061 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3063 it
->method
= next_element_from_stretch
;
3065 it
->current
.pos
= it
->position
= start_pos
;
3067 #ifdef HAVE_WINDOW_SYSTEM
3070 it
->what
= IT_IMAGE
;
3071 it
->image_id
= lookup_image (it
->f
, value
);
3072 it
->position
= start_pos
;
3073 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3074 it
->method
= next_element_from_image
;
3076 /* Say that we haven't consumed the characters with
3077 `display' property yet. The call to pop_it in
3078 set_iterator_to_next will clean this up. */
3079 *position
= start_pos
;
3081 #endif /* HAVE_WINDOW_SYSTEM */
3084 /* Invalid property or property not supported. Restore
3085 the position to what it was before. */
3086 *position
= start_pos
;
3089 return replaces_text_display_p
;
3093 /* Check if PROP is a display sub-property value whose text should be
3094 treated as intangible. */
3097 single_display_prop_intangible_p (prop
)
3100 /* Skip over `when FORM'. */
3101 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3112 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3113 we don't need to treat text as intangible. */
3114 if (EQ (XCAR (prop
), Qmargin
))
3122 || EQ (XCAR (prop
), Qleft_margin
)
3123 || EQ (XCAR (prop
), Qright_margin
))
3127 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3131 /* Check if PROP is a display property value whose text should be
3132 treated as intangible. */
3135 display_prop_intangible_p (prop
)
3139 && CONSP (XCAR (prop
))
3140 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3142 /* A list of sub-properties. */
3143 while (CONSP (prop
))
3145 if (single_display_prop_intangible_p (XCAR (prop
)))
3150 else if (VECTORP (prop
))
3152 /* A vector of sub-properties. */
3154 for (i
= 0; i
< ASIZE (prop
); ++i
)
3155 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3159 return single_display_prop_intangible_p (prop
);
3165 /* Return 1 if PROP is a display sub-property value containing STRING. */
3168 single_display_prop_string_p (prop
, string
)
3169 Lisp_Object prop
, string
;
3171 if (EQ (string
, prop
))
3174 /* Skip over `when FORM'. */
3175 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3184 /* Skip over `margin LOCATION'. */
3185 if (EQ (XCAR (prop
), Qmargin
))
3196 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3200 /* Return 1 if STRING appears in the `display' property PROP. */
3203 display_prop_string_p (prop
, string
)
3204 Lisp_Object prop
, string
;
3207 && CONSP (XCAR (prop
))
3208 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3210 /* A list of sub-properties. */
3211 while (CONSP (prop
))
3213 if (single_display_prop_string_p (XCAR (prop
), string
))
3218 else if (VECTORP (prop
))
3220 /* A vector of sub-properties. */
3222 for (i
= 0; i
< ASIZE (prop
); ++i
)
3223 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3227 return single_display_prop_string_p (prop
, string
);
3233 /* Determine from which buffer position in W's buffer STRING comes
3234 from. AROUND_CHARPOS is an approximate position where it could
3235 be from. Value is the buffer position or 0 if it couldn't be
3238 W's buffer must be current.
3240 This function is necessary because we don't record buffer positions
3241 in glyphs generated from strings (to keep struct glyph small).
3242 This function may only use code that doesn't eval because it is
3243 called asynchronously from note_mouse_highlight. */
3246 string_buffer_position (w
, string
, around_charpos
)
3251 Lisp_Object limit
, prop
, pos
;
3252 const int MAX_DISTANCE
= 1000;
3255 pos
= make_number (around_charpos
);
3256 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3257 while (!found
&& !EQ (pos
, limit
))
3259 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3260 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3263 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3268 pos
= make_number (around_charpos
);
3269 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3270 while (!found
&& !EQ (pos
, limit
))
3272 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3273 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3276 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3281 return found
? XINT (pos
) : 0;
3286 /***********************************************************************
3287 `composition' property
3288 ***********************************************************************/
3290 static enum prop_handled
3291 handle_auto_composed_prop (it
)
3294 enum prop_handled handled
= HANDLED_NORMALLY
;
3296 if (! NILP (Vauto_composition_function
))
3301 if (STRINGP (it
->string
))
3302 pos
= IT_STRING_CHARPOS (*it
);
3304 pos
= IT_CHARPOS (*it
);
3306 val
=Fget_char_property (make_number (pos
), Qauto_composed
, it
->string
);
3309 int count
= BINDING_STACK_SIZE ();
3310 Lisp_Object args
[3];
3312 args
[0] = Vauto_composition_function
;
3313 specbind (Qauto_composition_function
, Qnil
);
3314 args
[1] = make_number (pos
);
3315 args
[2] = it
->string
;
3316 safe_call (3, args
);
3317 unbind_to (count
, Qnil
);
3319 val
= Fget_char_property (args
[1], Qauto_composed
, it
->string
);
3321 handled
= HANDLED_RECOMPUTE_PROPS
;
3328 /* Set up iterator IT from `composition' property at its current
3329 position. Called from handle_stop. */
3331 static enum prop_handled
3332 handle_composition_prop (it
)
3335 Lisp_Object prop
, string
;
3336 int pos
, pos_byte
, end
;
3337 enum prop_handled handled
= HANDLED_NORMALLY
;
3339 if (STRINGP (it
->string
))
3341 pos
= IT_STRING_CHARPOS (*it
);
3342 pos_byte
= IT_STRING_BYTEPOS (*it
);
3343 string
= it
->string
;
3347 pos
= IT_CHARPOS (*it
);
3348 pos_byte
= IT_BYTEPOS (*it
);
3352 /* If there's a valid composition and point is not inside of the
3353 composition (in the case that the composition is from the current
3354 buffer), draw a glyph composed from the composition components. */
3355 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3356 && COMPOSITION_VALID_P (pos
, end
, prop
)
3357 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3359 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3363 it
->method
= next_element_from_composition
;
3365 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3366 /* For a terminal, draw only the first character of the
3368 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3369 it
->len
= (STRINGP (it
->string
)
3370 ? string_char_to_byte (it
->string
, end
)
3371 : CHAR_TO_BYTE (end
)) - pos_byte
;
3372 it
->stop_charpos
= end
;
3373 handled
= HANDLED_RETURN
;
3382 /***********************************************************************
3384 ***********************************************************************/
3386 /* The following structure is used to record overlay strings for
3387 later sorting in load_overlay_strings. */
3389 struct overlay_entry
3391 Lisp_Object overlay
;
3398 /* Set up iterator IT from overlay strings at its current position.
3399 Called from handle_stop. */
3401 static enum prop_handled
3402 handle_overlay_change (it
)
3405 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3406 return HANDLED_RECOMPUTE_PROPS
;
3408 return HANDLED_NORMALLY
;
3412 /* Set up the next overlay string for delivery by IT, if there is an
3413 overlay string to deliver. Called by set_iterator_to_next when the
3414 end of the current overlay string is reached. If there are more
3415 overlay strings to display, IT->string and
3416 IT->current.overlay_string_index are set appropriately here.
3417 Otherwise IT->string is set to nil. */
3420 next_overlay_string (it
)
3423 ++it
->current
.overlay_string_index
;
3424 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3426 /* No more overlay strings. Restore IT's settings to what
3427 they were before overlay strings were processed, and
3428 continue to deliver from current_buffer. */
3429 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3432 xassert (it
->stop_charpos
>= BEGV
3433 && it
->stop_charpos
<= it
->end_charpos
);
3435 it
->current
.overlay_string_index
= -1;
3436 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3437 it
->n_overlay_strings
= 0;
3438 it
->method
= next_element_from_buffer
;
3440 /* If we're at the end of the buffer, record that we have
3441 processed the overlay strings there already, so that
3442 next_element_from_buffer doesn't try it again. */
3443 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3444 it
->overlay_strings_at_end_processed_p
= 1;
3446 /* If we have to display `...' for invisible text, set
3447 the iterator up for that. */
3448 if (display_ellipsis_p
)
3449 setup_for_ellipsis (it
);
3453 /* There are more overlay strings to process. If
3454 IT->current.overlay_string_index has advanced to a position
3455 where we must load IT->overlay_strings with more strings, do
3457 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3459 if (it
->current
.overlay_string_index
&& i
== 0)
3460 load_overlay_strings (it
, 0);
3462 /* Initialize IT to deliver display elements from the overlay
3464 it
->string
= it
->overlay_strings
[i
];
3465 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3466 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3467 it
->method
= next_element_from_string
;
3468 it
->stop_charpos
= 0;
3475 /* Compare two overlay_entry structures E1 and E2. Used as a
3476 comparison function for qsort in load_overlay_strings. Overlay
3477 strings for the same position are sorted so that
3479 1. All after-strings come in front of before-strings, except
3480 when they come from the same overlay.
3482 2. Within after-strings, strings are sorted so that overlay strings
3483 from overlays with higher priorities come first.
3485 2. Within before-strings, strings are sorted so that overlay
3486 strings from overlays with higher priorities come last.
3488 Value is analogous to strcmp. */
3492 compare_overlay_entries (e1
, e2
)
3495 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3496 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3499 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3501 /* Let after-strings appear in front of before-strings if
3502 they come from different overlays. */
3503 if (EQ (entry1
->overlay
, entry2
->overlay
))
3504 result
= entry1
->after_string_p
? 1 : -1;
3506 result
= entry1
->after_string_p
? -1 : 1;
3508 else if (entry1
->after_string_p
)
3509 /* After-strings sorted in order of decreasing priority. */
3510 result
= entry2
->priority
- entry1
->priority
;
3512 /* Before-strings sorted in order of increasing priority. */
3513 result
= entry1
->priority
- entry2
->priority
;
3519 /* Load the vector IT->overlay_strings with overlay strings from IT's
3520 current buffer position, or from CHARPOS if that is > 0. Set
3521 IT->n_overlays to the total number of overlay strings found.
3523 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3524 a time. On entry into load_overlay_strings,
3525 IT->current.overlay_string_index gives the number of overlay
3526 strings that have already been loaded by previous calls to this
3529 IT->add_overlay_start contains an additional overlay start
3530 position to consider for taking overlay strings from, if non-zero.
3531 This position comes into play when the overlay has an `invisible'
3532 property, and both before and after-strings. When we've skipped to
3533 the end of the overlay, because of its `invisible' property, we
3534 nevertheless want its before-string to appear.
3535 IT->add_overlay_start will contain the overlay start position
3538 Overlay strings are sorted so that after-string strings come in
3539 front of before-string strings. Within before and after-strings,
3540 strings are sorted by overlay priority. See also function
3541 compare_overlay_entries. */
3544 load_overlay_strings (it
, charpos
)
3548 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3549 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3552 int n
= 0, i
, j
, invis_p
;
3553 struct overlay_entry
*entries
3554 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3557 charpos
= IT_CHARPOS (*it
);
3559 /* Append the overlay string STRING of overlay OVERLAY to vector
3560 `entries' which has size `size' and currently contains `n'
3561 elements. AFTER_P non-zero means STRING is an after-string of
3563 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3566 Lisp_Object priority; \
3570 int new_size = 2 * size; \
3571 struct overlay_entry *old = entries; \
3573 (struct overlay_entry *) alloca (new_size \
3574 * sizeof *entries); \
3575 bcopy (old, entries, size * sizeof *entries); \
3579 entries[n].string = (STRING); \
3580 entries[n].overlay = (OVERLAY); \
3581 priority = Foverlay_get ((OVERLAY), Qpriority); \
3582 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3583 entries[n].after_string_p = (AFTER_P); \
3588 /* Process overlay before the overlay center. */
3589 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3591 overlay
= XCAR (ov
);
3592 xassert (OVERLAYP (overlay
));
3593 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3594 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3599 /* Skip this overlay if it doesn't start or end at IT's current
3601 if (end
!= charpos
&& start
!= charpos
)
3604 /* Skip this overlay if it doesn't apply to IT->w. */
3605 window
= Foverlay_get (overlay
, Qwindow
);
3606 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3609 /* If the text ``under'' the overlay is invisible, both before-
3610 and after-strings from this overlay are visible; start and
3611 end position are indistinguishable. */
3612 invisible
= Foverlay_get (overlay
, Qinvisible
);
3613 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3615 /* If overlay has a non-empty before-string, record it. */
3616 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3617 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3618 && XSTRING (str
)->size
)
3619 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3621 /* If overlay has a non-empty after-string, record it. */
3622 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3623 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3624 && XSTRING (str
)->size
)
3625 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3628 /* Process overlays after the overlay center. */
3629 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3631 overlay
= XCAR (ov
);
3632 xassert (OVERLAYP (overlay
));
3633 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3634 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3636 if (start
> charpos
)
3639 /* Skip this overlay if it doesn't start or end at IT's current
3641 if (end
!= charpos
&& start
!= charpos
)
3644 /* Skip this overlay if it doesn't apply to IT->w. */
3645 window
= Foverlay_get (overlay
, Qwindow
);
3646 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3649 /* If the text ``under'' the overlay is invisible, it has a zero
3650 dimension, and both before- and after-strings apply. */
3651 invisible
= Foverlay_get (overlay
, Qinvisible
);
3652 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3654 /* If overlay has a non-empty before-string, record it. */
3655 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3656 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3657 && XSTRING (str
)->size
)
3658 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3660 /* If overlay has a non-empty after-string, record it. */
3661 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3662 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3663 && XSTRING (str
)->size
)
3664 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3667 #undef RECORD_OVERLAY_STRING
3671 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3673 /* Record the total number of strings to process. */
3674 it
->n_overlay_strings
= n
;
3676 /* IT->current.overlay_string_index is the number of overlay strings
3677 that have already been consumed by IT. Copy some of the
3678 remaining overlay strings to IT->overlay_strings. */
3680 j
= it
->current
.overlay_string_index
;
3681 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3682 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3688 /* Get the first chunk of overlay strings at IT's current buffer
3689 position, or at CHARPOS if that is > 0. Value is non-zero if at
3690 least one overlay string was found. */
3693 get_overlay_strings (it
, charpos
)
3697 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3698 process. This fills IT->overlay_strings with strings, and sets
3699 IT->n_overlay_strings to the total number of strings to process.
3700 IT->pos.overlay_string_index has to be set temporarily to zero
3701 because load_overlay_strings needs this; it must be set to -1
3702 when no overlay strings are found because a zero value would
3703 indicate a position in the first overlay string. */
3704 it
->current
.overlay_string_index
= 0;
3705 load_overlay_strings (it
, charpos
);
3707 /* If we found overlay strings, set up IT to deliver display
3708 elements from the first one. Otherwise set up IT to deliver
3709 from current_buffer. */
3710 if (it
->n_overlay_strings
)
3712 /* Make sure we know settings in current_buffer, so that we can
3713 restore meaningful values when we're done with the overlay
3715 compute_stop_pos (it
);
3716 xassert (it
->face_id
>= 0);
3718 /* Save IT's settings. They are restored after all overlay
3719 strings have been processed. */
3720 xassert (it
->sp
== 0);
3723 /* Set up IT to deliver display elements from the first overlay
3725 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3726 it
->string
= it
->overlay_strings
[0];
3727 it
->stop_charpos
= 0;
3728 it
->end_charpos
= XSTRING (it
->string
)->size
;
3729 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3730 xassert (STRINGP (it
->string
));
3731 it
->method
= next_element_from_string
;
3736 it
->current
.overlay_string_index
= -1;
3737 it
->method
= next_element_from_buffer
;
3742 /* Value is non-zero if we found at least one overlay string. */
3743 return STRINGP (it
->string
);
3748 /***********************************************************************
3749 Saving and restoring state
3750 ***********************************************************************/
3752 /* Save current settings of IT on IT->stack. Called, for example,
3753 before setting up IT for an overlay string, to be able to restore
3754 IT's settings to what they were after the overlay string has been
3761 struct iterator_stack_entry
*p
;
3763 xassert (it
->sp
< 2);
3764 p
= it
->stack
+ it
->sp
;
3766 p
->stop_charpos
= it
->stop_charpos
;
3767 xassert (it
->face_id
>= 0);
3768 p
->face_id
= it
->face_id
;
3769 p
->string
= it
->string
;
3770 p
->pos
= it
->current
;
3771 p
->end_charpos
= it
->end_charpos
;
3772 p
->string_nchars
= it
->string_nchars
;
3774 p
->multibyte_p
= it
->multibyte_p
;
3775 p
->space_width
= it
->space_width
;
3776 p
->font_height
= it
->font_height
;
3777 p
->voffset
= it
->voffset
;
3778 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3779 p
->display_ellipsis_p
= 0;
3784 /* Restore IT's settings from IT->stack. Called, for example, when no
3785 more overlay strings must be processed, and we return to delivering
3786 display elements from a buffer, or when the end of a string from a
3787 `display' property is reached and we return to delivering display
3788 elements from an overlay string, or from a buffer. */
3794 struct iterator_stack_entry
*p
;
3796 xassert (it
->sp
> 0);
3798 p
= it
->stack
+ it
->sp
;
3799 it
->stop_charpos
= p
->stop_charpos
;
3800 it
->face_id
= p
->face_id
;
3801 it
->string
= p
->string
;
3802 it
->current
= p
->pos
;
3803 it
->end_charpos
= p
->end_charpos
;
3804 it
->string_nchars
= p
->string_nchars
;
3806 it
->multibyte_p
= p
->multibyte_p
;
3807 it
->space_width
= p
->space_width
;
3808 it
->font_height
= p
->font_height
;
3809 it
->voffset
= p
->voffset
;
3810 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3815 /***********************************************************************
3817 ***********************************************************************/
3819 /* Set IT's current position to the previous line start. */
3822 back_to_previous_line_start (it
)
3825 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3826 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3830 /* Move IT to the next line start.
3832 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3833 we skipped over part of the text (as opposed to moving the iterator
3834 continuously over the text). Otherwise, don't change the value
3837 Newlines may come from buffer text, overlay strings, or strings
3838 displayed via the `display' property. That's the reason we can't
3839 simply use find_next_newline_no_quit.
3841 Note that this function may not skip over invisible text that is so
3842 because of text properties and immediately follows a newline. If
3843 it would, function reseat_at_next_visible_line_start, when called
3844 from set_iterator_to_next, would effectively make invisible
3845 characters following a newline part of the wrong glyph row, which
3846 leads to wrong cursor motion. */
3849 forward_to_next_line_start (it
, skipped_p
)
3853 int old_selective
, newline_found_p
, n
;
3854 const int MAX_NEWLINE_DISTANCE
= 500;
3856 /* If already on a newline, just consume it to avoid unintended
3857 skipping over invisible text below. */
3858 if (it
->what
== IT_CHARACTER
3860 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3862 set_iterator_to_next (it
, 0);
3867 /* Don't handle selective display in the following. It's (a)
3868 unnecessary because it's done by the caller, and (b) leads to an
3869 infinite recursion because next_element_from_ellipsis indirectly
3870 calls this function. */
3871 old_selective
= it
->selective
;
3874 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3875 from buffer text. */
3876 for (n
= newline_found_p
= 0;
3877 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3878 n
+= STRINGP (it
->string
) ? 0 : 1)
3880 if (!get_next_display_element (it
))
3882 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3883 set_iterator_to_next (it
, 0);
3886 /* If we didn't find a newline near enough, see if we can use a
3888 if (n
== MAX_NEWLINE_DISTANCE
)
3890 int start
= IT_CHARPOS (*it
);
3891 int limit
= find_next_newline_no_quit (start
, 1);
3894 xassert (!STRINGP (it
->string
));
3896 /* If there isn't any `display' property in sight, and no
3897 overlays, we can just use the position of the newline in
3899 if (it
->stop_charpos
>= limit
3900 || ((pos
= Fnext_single_property_change (make_number (start
),
3902 Qnil
, make_number (limit
)),
3904 && next_overlay_change (start
) == ZV
))
3906 IT_CHARPOS (*it
) = limit
;
3907 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3908 *skipped_p
= newline_found_p
= 1;
3912 while (get_next_display_element (it
)
3913 && !newline_found_p
)
3915 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3916 set_iterator_to_next (it
, 0);
3921 it
->selective
= old_selective
;
3922 return newline_found_p
;
3926 /* Set IT's current position to the previous visible line start. Skip
3927 invisible text that is so either due to text properties or due to
3928 selective display. Caution: this does not change IT->current_x and
3932 back_to_previous_visible_line_start (it
)
3937 /* Go back one newline if not on BEGV already. */
3938 if (IT_CHARPOS (*it
) > BEGV
)
3939 back_to_previous_line_start (it
);
3941 /* Move over lines that are invisible because of selective display
3942 or text properties. */
3943 while (IT_CHARPOS (*it
) > BEGV
3948 /* If selective > 0, then lines indented more than that values
3950 if (it
->selective
> 0
3951 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3958 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3959 Qinvisible
, it
->window
);
3960 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3964 /* Back one more newline if the current one is invisible. */
3966 back_to_previous_line_start (it
);
3969 xassert (IT_CHARPOS (*it
) >= BEGV
);
3970 xassert (IT_CHARPOS (*it
) == BEGV
3971 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3976 /* Reseat iterator IT at the previous visible line start. Skip
3977 invisible text that is so either due to text properties or due to
3978 selective display. At the end, update IT's overlay information,
3979 face information etc. */
3982 reseat_at_previous_visible_line_start (it
)
3985 back_to_previous_visible_line_start (it
);
3986 reseat (it
, it
->current
.pos
, 1);
3991 /* Reseat iterator IT on the next visible line start in the current
3992 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3993 preceding the line start. Skip over invisible text that is so
3994 because of selective display. Compute faces, overlays etc at the
3995 new position. Note that this function does not skip over text that
3996 is invisible because of text properties. */
3999 reseat_at_next_visible_line_start (it
, on_newline_p
)
4003 int newline_found_p
, skipped_p
= 0;
4005 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4007 /* Skip over lines that are invisible because they are indented
4008 more than the value of IT->selective. */
4009 if (it
->selective
> 0)
4010 while (IT_CHARPOS (*it
) < ZV
4011 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4014 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4015 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4018 /* Position on the newline if that's what's requested. */
4019 if (on_newline_p
&& newline_found_p
)
4021 if (STRINGP (it
->string
))
4023 if (IT_STRING_CHARPOS (*it
) > 0)
4025 --IT_STRING_CHARPOS (*it
);
4026 --IT_STRING_BYTEPOS (*it
);
4029 else if (IT_CHARPOS (*it
) > BEGV
)
4033 reseat (it
, it
->current
.pos
, 0);
4037 reseat (it
, it
->current
.pos
, 0);
4044 /***********************************************************************
4045 Changing an iterator's position
4046 ***********************************************************************/
4048 /* Change IT's current position to POS in current_buffer. If FORCE_P
4049 is non-zero, always check for text properties at the new position.
4050 Otherwise, text properties are only looked up if POS >=
4051 IT->check_charpos of a property. */
4054 reseat (it
, pos
, force_p
)
4056 struct text_pos pos
;
4059 int original_pos
= IT_CHARPOS (*it
);
4061 reseat_1 (it
, pos
, 0);
4063 /* Determine where to check text properties. Avoid doing it
4064 where possible because text property lookup is very expensive. */
4066 || CHARPOS (pos
) > it
->stop_charpos
4067 || CHARPOS (pos
) < original_pos
)
4074 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4075 IT->stop_pos to POS, also. */
4078 reseat_1 (it
, pos
, set_stop_p
)
4080 struct text_pos pos
;
4083 /* Don't call this function when scanning a C string. */
4084 xassert (it
->s
== NULL
);
4086 /* POS must be a reasonable value. */
4087 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4089 it
->current
.pos
= it
->position
= pos
;
4090 XSETBUFFER (it
->object
, current_buffer
);
4091 it
->end_charpos
= ZV
;
4093 it
->current
.dpvec_index
= -1;
4094 it
->current
.overlay_string_index
= -1;
4095 IT_STRING_CHARPOS (*it
) = -1;
4096 IT_STRING_BYTEPOS (*it
) = -1;
4098 it
->method
= next_element_from_buffer
;
4099 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4101 it
->face_before_selective_p
= 0;
4104 it
->stop_charpos
= CHARPOS (pos
);
4108 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4109 If S is non-null, it is a C string to iterate over. Otherwise,
4110 STRING gives a Lisp string to iterate over.
4112 If PRECISION > 0, don't return more then PRECISION number of
4113 characters from the string.
4115 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4116 characters have been returned. FIELD_WIDTH < 0 means an infinite
4119 MULTIBYTE = 0 means disable processing of multibyte characters,
4120 MULTIBYTE > 0 means enable it,
4121 MULTIBYTE < 0 means use IT->multibyte_p.
4123 IT must be initialized via a prior call to init_iterator before
4124 calling this function. */
4127 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4132 int precision
, field_width
, multibyte
;
4134 /* No region in strings. */
4135 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4137 /* No text property checks performed by default, but see below. */
4138 it
->stop_charpos
= -1;
4140 /* Set iterator position and end position. */
4141 bzero (&it
->current
, sizeof it
->current
);
4142 it
->current
.overlay_string_index
= -1;
4143 it
->current
.dpvec_index
= -1;
4144 xassert (charpos
>= 0);
4146 /* If STRING is specified, use its multibyteness, otherwise use the
4147 setting of MULTIBYTE, if specified. */
4149 it
->multibyte_p
= multibyte
> 0;
4153 xassert (STRINGP (string
));
4154 it
->string
= string
;
4156 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
4157 it
->method
= next_element_from_string
;
4158 it
->current
.string_pos
= string_pos (charpos
, string
);
4165 /* Note that we use IT->current.pos, not it->current.string_pos,
4166 for displaying C strings. */
4167 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4168 if (it
->multibyte_p
)
4170 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4171 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4175 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4176 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4179 it
->method
= next_element_from_c_string
;
4182 /* PRECISION > 0 means don't return more than PRECISION characters
4184 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4185 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4187 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4188 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4189 FIELD_WIDTH < 0 means infinite field width. This is useful for
4190 padding with `-' at the end of a mode line. */
4191 if (field_width
< 0)
4192 field_width
= INFINITY
;
4193 if (field_width
> it
->end_charpos
- charpos
)
4194 it
->end_charpos
= charpos
+ field_width
;
4196 /* Use the standard display table for displaying strings. */
4197 if (DISP_TABLE_P (Vstandard_display_table
))
4198 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4200 it
->stop_charpos
= charpos
;
4206 /***********************************************************************
4208 ***********************************************************************/
4210 /* Load IT's display element fields with information about the next
4211 display element from the current position of IT. Value is zero if
4212 end of buffer (or C string) is reached. */
4215 get_next_display_element (it
)
4218 /* Non-zero means that we found an display element. Zero means that
4219 we hit the end of what we iterate over. Performance note: the
4220 function pointer `method' used here turns out to be faster than
4221 using a sequence of if-statements. */
4222 int success_p
= (*it
->method
) (it
);
4224 if (it
->what
== IT_CHARACTER
)
4226 /* Map via display table or translate control characters.
4227 IT->c, IT->len etc. have been set to the next character by
4228 the function call above. If we have a display table, and it
4229 contains an entry for IT->c, translate it. Don't do this if
4230 IT->c itself comes from a display table, otherwise we could
4231 end up in an infinite recursion. (An alternative could be to
4232 count the recursion depth of this function and signal an
4233 error when a certain maximum depth is reached.) Is it worth
4235 if (success_p
&& it
->dpvec
== NULL
)
4240 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4243 struct Lisp_Vector
*v
= XVECTOR (dv
);
4245 /* Return the first character from the display table
4246 entry, if not empty. If empty, don't display the
4247 current character. */
4250 it
->dpvec_char_len
= it
->len
;
4251 it
->dpvec
= v
->contents
;
4252 it
->dpend
= v
->contents
+ v
->size
;
4253 it
->current
.dpvec_index
= 0;
4254 it
->method
= next_element_from_display_vector
;
4255 success_p
= get_next_display_element (it
);
4259 set_iterator_to_next (it
, 0);
4260 success_p
= get_next_display_element (it
);
4264 /* Translate control characters into `\003' or `^C' form.
4265 Control characters coming from a display table entry are
4266 currently not translated because we use IT->dpvec to hold
4267 the translation. This could easily be changed but I
4268 don't believe that it is worth doing.
4270 Non-printable multibyte characters are also translated
4272 else if ((it
->c
< ' '
4273 && (it
->area
!= TEXT_AREA
4274 || (it
->c
!= '\n' && it
->c
!= '\t')))
4275 || (it
->c
!= '\n' && it
->c
!= '\t'
4276 && (it
->multibyte_p
? !CHAR_PRINTABLE_P (it
->c
)
4279 /* IT->c is a control character which must be displayed
4280 either as '\003' or as `^C' where the '\\' and '^'
4281 can be defined in the display table. Fill
4282 IT->ctl_chars with glyphs for what we have to
4283 display. Then, set IT->dpvec to these glyphs. */
4286 if (it
->c
< 128 && it
->ctl_arrow_p
)
4288 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4290 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4291 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4292 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4294 g
= FAST_MAKE_GLYPH ('^', 0);
4295 XSETINT (it
->ctl_chars
[0], g
);
4297 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4298 XSETINT (it
->ctl_chars
[1], g
);
4300 /* Set up IT->dpvec and return first character from it. */
4301 it
->dpvec_char_len
= it
->len
;
4302 it
->dpvec
= it
->ctl_chars
;
4303 it
->dpend
= it
->dpvec
+ 2;
4304 it
->current
.dpvec_index
= 0;
4305 it
->method
= next_element_from_display_vector
;
4306 get_next_display_element (it
);
4310 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4315 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4317 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4318 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4319 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4321 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4323 if (CHAR_BYTE8_P (it
->c
))
4325 str
[0] = CHAR_TO_BYTE8 (it
->c
);
4328 else if (it
->c
< 256)
4335 /* It's an invalid character, which
4336 shouldn't happen actually, but due to
4337 bugs it may happen. Let's print the char
4338 as is, there's not much meaningful we can
4341 str
[1] = it
->c
>> 8;
4342 str
[2] = it
->c
>> 16;
4343 str
[3] = it
->c
>> 24;
4347 for (i
= 0; i
< len
; i
++)
4349 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4350 /* Insert three more glyphs into IT->ctl_chars for
4351 the octal display of the character. */
4352 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4353 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4354 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4355 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4356 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4357 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4360 /* Set up IT->dpvec and return the first character
4362 it
->dpvec_char_len
= it
->len
;
4363 it
->dpvec
= it
->ctl_chars
;
4364 it
->dpend
= it
->dpvec
+ len
* 4;
4365 it
->current
.dpvec_index
= 0;
4366 it
->method
= next_element_from_display_vector
;
4367 get_next_display_element (it
);
4372 /* Adjust face id for a multibyte character. There are no
4373 multibyte character in unibyte text. */
4376 && FRAME_WINDOW_P (it
->f
))
4378 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4379 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4383 /* Is this character the last one of a run of characters with
4384 box? If yes, set IT->end_of_box_run_p to 1. */
4391 it
->end_of_box_run_p
4392 = ((face_id
= face_after_it_pos (it
),
4393 face_id
!= it
->face_id
)
4394 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4395 face
->box
== FACE_NO_BOX
));
4398 /* Value is 0 if end of buffer or string reached. */
4403 /* Move IT to the next display element.
4405 RESEAT_P non-zero means if called on a newline in buffer text,
4406 skip to the next visible line start.
4408 Functions get_next_display_element and set_iterator_to_next are
4409 separate because I find this arrangement easier to handle than a
4410 get_next_display_element function that also increments IT's
4411 position. The way it is we can first look at an iterator's current
4412 display element, decide whether it fits on a line, and if it does,
4413 increment the iterator position. The other way around we probably
4414 would either need a flag indicating whether the iterator has to be
4415 incremented the next time, or we would have to implement a
4416 decrement position function which would not be easy to write. */
4419 set_iterator_to_next (it
, reseat_p
)
4423 /* Reset flags indicating start and end of a sequence of characters
4424 with box. Reset them at the start of this function because
4425 moving the iterator to a new position might set them. */
4426 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4428 if (it
->method
== next_element_from_buffer
)
4430 /* The current display element of IT is a character from
4431 current_buffer. Advance in the buffer, and maybe skip over
4432 invisible lines that are so because of selective display. */
4433 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4434 reseat_at_next_visible_line_start (it
, 0);
4437 xassert (it
->len
!= 0);
4438 IT_BYTEPOS (*it
) += it
->len
;
4439 IT_CHARPOS (*it
) += 1;
4440 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4443 else if (it
->method
== next_element_from_composition
)
4445 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4446 if (STRINGP (it
->string
))
4448 IT_STRING_BYTEPOS (*it
) += it
->len
;
4449 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4450 it
->method
= next_element_from_string
;
4451 goto consider_string_end
;
4455 IT_BYTEPOS (*it
) += it
->len
;
4456 IT_CHARPOS (*it
) += it
->cmp_len
;
4457 it
->method
= next_element_from_buffer
;
4460 else if (it
->method
== next_element_from_c_string
)
4462 /* Current display element of IT is from a C string. */
4463 IT_BYTEPOS (*it
) += it
->len
;
4464 IT_CHARPOS (*it
) += 1;
4466 else if (it
->method
== next_element_from_display_vector
)
4468 /* Current display element of IT is from a display table entry.
4469 Advance in the display table definition. Reset it to null if
4470 end reached, and continue with characters from buffers/
4472 ++it
->current
.dpvec_index
;
4474 /* Restore face of the iterator to what they were before the
4475 display vector entry (these entries may contain faces). */
4476 it
->face_id
= it
->saved_face_id
;
4478 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4481 it
->method
= next_element_from_c_string
;
4482 else if (STRINGP (it
->string
))
4483 it
->method
= next_element_from_string
;
4485 it
->method
= next_element_from_buffer
;
4488 it
->current
.dpvec_index
= -1;
4490 /* Skip over characters which were displayed via IT->dpvec. */
4491 if (it
->dpvec_char_len
< 0)
4492 reseat_at_next_visible_line_start (it
, 1);
4493 else if (it
->dpvec_char_len
> 0)
4495 it
->len
= it
->dpvec_char_len
;
4496 set_iterator_to_next (it
, reseat_p
);
4500 else if (it
->method
== next_element_from_string
)
4502 /* Current display element is a character from a Lisp string. */
4503 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4504 IT_STRING_BYTEPOS (*it
) += it
->len
;
4505 IT_STRING_CHARPOS (*it
) += 1;
4507 consider_string_end
:
4509 if (it
->current
.overlay_string_index
>= 0)
4511 /* IT->string is an overlay string. Advance to the
4512 next, if there is one. */
4513 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4514 next_overlay_string (it
);
4518 /* IT->string is not an overlay string. If we reached
4519 its end, and there is something on IT->stack, proceed
4520 with what is on the stack. This can be either another
4521 string, this time an overlay string, or a buffer. */
4522 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4526 if (!STRINGP (it
->string
))
4527 it
->method
= next_element_from_buffer
;
4529 goto consider_string_end
;
4533 else if (it
->method
== next_element_from_image
4534 || it
->method
== next_element_from_stretch
)
4536 /* The position etc with which we have to proceed are on
4537 the stack. The position may be at the end of a string,
4538 if the `display' property takes up the whole string. */
4541 if (STRINGP (it
->string
))
4543 it
->method
= next_element_from_string
;
4544 goto consider_string_end
;
4547 it
->method
= next_element_from_buffer
;
4550 /* There are no other methods defined, so this should be a bug. */
4553 xassert (it
->method
!= next_element_from_string
4554 || (STRINGP (it
->string
)
4555 && IT_STRING_CHARPOS (*it
) >= 0));
4559 /* Load IT's display element fields with information about the next
4560 display element which comes from a display table entry or from the
4561 result of translating a control character to one of the forms `^C'
4562 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4565 next_element_from_display_vector (it
)
4569 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4571 /* Remember the current face id in case glyphs specify faces.
4572 IT's face is restored in set_iterator_to_next. */
4573 it
->saved_face_id
= it
->face_id
;
4575 if (INTEGERP (*it
->dpvec
)
4576 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4581 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4582 it
->c
= FAST_GLYPH_CHAR (g
);
4583 it
->len
= CHAR_BYTES (it
->c
);
4585 /* The entry may contain a face id to use. Such a face id is
4586 the id of a Lisp face, not a realized face. A face id of
4587 zero means no face is specified. */
4588 lface_id
= FAST_GLYPH_FACE (g
);
4591 /* The function returns -1 if lface_id is invalid. */
4592 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4594 it
->face_id
= face_id
;
4598 /* Display table entry is invalid. Return a space. */
4599 it
->c
= ' ', it
->len
= 1;
4601 /* Don't change position and object of the iterator here. They are
4602 still the values of the character that had this display table
4603 entry or was translated, and that's what we want. */
4604 it
->what
= IT_CHARACTER
;
4609 /* Load IT with the next display element from Lisp string IT->string.
4610 IT->current.string_pos is the current position within the string.
4611 If IT->current.overlay_string_index >= 0, the Lisp string is an
4615 next_element_from_string (it
)
4618 struct text_pos position
;
4620 xassert (STRINGP (it
->string
));
4621 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4622 position
= it
->current
.string_pos
;
4624 /* Time to check for invisible text? */
4625 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4626 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4630 /* Since a handler may have changed IT->method, we must
4632 return get_next_display_element (it
);
4635 if (it
->current
.overlay_string_index
>= 0)
4637 /* Get the next character from an overlay string. In overlay
4638 strings, There is no field width or padding with spaces to
4640 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4645 else if (STRING_MULTIBYTE (it
->string
))
4647 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4648 - IT_STRING_BYTEPOS (*it
));
4649 unsigned char *s
= (XSTRING (it
->string
)->data
4650 + IT_STRING_BYTEPOS (*it
));
4651 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4655 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4661 /* Get the next character from a Lisp string that is not an
4662 overlay string. Such strings come from the mode line, for
4663 example. We may have to pad with spaces, or truncate the
4664 string. See also next_element_from_c_string. */
4665 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4670 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4672 /* Pad with spaces. */
4673 it
->c
= ' ', it
->len
= 1;
4674 CHARPOS (position
) = BYTEPOS (position
) = -1;
4676 else if (STRING_MULTIBYTE (it
->string
))
4678 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4679 - IT_STRING_BYTEPOS (*it
));
4680 unsigned char *s
= (XSTRING (it
->string
)->data
4681 + IT_STRING_BYTEPOS (*it
));
4682 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4686 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4691 /* Record what we have and where it came from. Note that we store a
4692 buffer position in IT->position although it could arguably be a
4694 it
->what
= IT_CHARACTER
;
4695 it
->object
= it
->string
;
4696 it
->position
= position
;
4701 /* Load IT with next display element from C string IT->s.
4702 IT->string_nchars is the maximum number of characters to return
4703 from the string. IT->end_charpos may be greater than
4704 IT->string_nchars when this function is called, in which case we
4705 may have to return padding spaces. Value is zero if end of string
4706 reached, including padding spaces. */
4709 next_element_from_c_string (it
)
4715 it
->what
= IT_CHARACTER
;
4716 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4719 /* IT's position can be greater IT->string_nchars in case a field
4720 width or precision has been specified when the iterator was
4722 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4724 /* End of the game. */
4728 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4730 /* Pad with spaces. */
4731 it
->c
= ' ', it
->len
= 1;
4732 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4734 else if (it
->multibyte_p
)
4736 /* Implementation note: The calls to strlen apparently aren't a
4737 performance problem because there is no noticeable performance
4738 difference between Emacs running in unibyte or multibyte mode. */
4739 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4740 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4744 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4750 /* Set up IT to return characters from an ellipsis, if appropriate.
4751 The definition of the ellipsis glyphs may come from a display table
4752 entry. This function Fills IT with the first glyph from the
4753 ellipsis if an ellipsis is to be displayed. */
4756 next_element_from_ellipsis (it
)
4759 if (it
->selective_display_ellipsis_p
)
4761 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4763 /* Use the display table definition for `...'. Invalid glyphs
4764 will be handled by the method returning elements from dpvec. */
4765 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4766 it
->dpvec_char_len
= it
->len
;
4767 it
->dpvec
= v
->contents
;
4768 it
->dpend
= v
->contents
+ v
->size
;
4769 it
->current
.dpvec_index
= 0;
4770 it
->method
= next_element_from_display_vector
;
4774 /* Use default `...' which is stored in default_invis_vector. */
4775 it
->dpvec_char_len
= it
->len
;
4776 it
->dpvec
= default_invis_vector
;
4777 it
->dpend
= default_invis_vector
+ 3;
4778 it
->current
.dpvec_index
= 0;
4779 it
->method
= next_element_from_display_vector
;
4784 /* The face at the current position may be different from the
4785 face we find after the invisible text. Remember what it
4786 was in IT->saved_face_id, and signal that it's there by
4787 setting face_before_selective_p. */
4788 it
->saved_face_id
= it
->face_id
;
4789 it
->method
= next_element_from_buffer
;
4790 reseat_at_next_visible_line_start (it
, 1);
4791 it
->face_before_selective_p
= 1;
4794 return get_next_display_element (it
);
4798 /* Deliver an image display element. The iterator IT is already
4799 filled with image information (done in handle_display_prop). Value
4804 next_element_from_image (it
)
4807 it
->what
= IT_IMAGE
;
4812 /* Fill iterator IT with next display element from a stretch glyph
4813 property. IT->object is the value of the text property. Value is
4817 next_element_from_stretch (it
)
4820 it
->what
= IT_STRETCH
;
4825 /* Load IT with the next display element from current_buffer. Value
4826 is zero if end of buffer reached. IT->stop_charpos is the next
4827 position at which to stop and check for text properties or buffer
4831 next_element_from_buffer (it
)
4836 /* Check this assumption, otherwise, we would never enter the
4837 if-statement, below. */
4838 xassert (IT_CHARPOS (*it
) >= BEGV
4839 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4841 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4843 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4845 int overlay_strings_follow_p
;
4847 /* End of the game, except when overlay strings follow that
4848 haven't been returned yet. */
4849 if (it
->overlay_strings_at_end_processed_p
)
4850 overlay_strings_follow_p
= 0;
4853 it
->overlay_strings_at_end_processed_p
= 1;
4854 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4857 if (overlay_strings_follow_p
)
4858 success_p
= get_next_display_element (it
);
4862 it
->position
= it
->current
.pos
;
4869 return get_next_display_element (it
);
4874 /* No face changes, overlays etc. in sight, so just return a
4875 character from current_buffer. */
4878 /* Maybe run the redisplay end trigger hook. Performance note:
4879 This doesn't seem to cost measurable time. */
4880 if (it
->redisplay_end_trigger_charpos
4882 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4883 run_redisplay_end_trigger_hook (it
);
4885 /* Get the next character, maybe multibyte. */
4886 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4887 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4889 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4890 - IT_BYTEPOS (*it
));
4891 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4894 it
->c
= *p
, it
->len
= 1;
4896 /* Record what we have and where it came from. */
4897 it
->what
= IT_CHARACTER
;;
4898 it
->object
= it
->w
->buffer
;
4899 it
->position
= it
->current
.pos
;
4901 /* Normally we return the character found above, except when we
4902 really want to return an ellipsis for selective display. */
4907 /* A value of selective > 0 means hide lines indented more
4908 than that number of columns. */
4909 if (it
->selective
> 0
4910 && IT_CHARPOS (*it
) + 1 < ZV
4911 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4912 IT_BYTEPOS (*it
) + 1,
4915 success_p
= next_element_from_ellipsis (it
);
4916 it
->dpvec_char_len
= -1;
4919 else if (it
->c
== '\r' && it
->selective
== -1)
4921 /* A value of selective == -1 means that everything from the
4922 CR to the end of the line is invisible, with maybe an
4923 ellipsis displayed for it. */
4924 success_p
= next_element_from_ellipsis (it
);
4925 it
->dpvec_char_len
= -1;
4930 /* Value is zero if end of buffer reached. */
4931 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4936 /* Run the redisplay end trigger hook for IT. */
4939 run_redisplay_end_trigger_hook (it
)
4942 Lisp_Object args
[3];
4944 /* IT->glyph_row should be non-null, i.e. we should be actually
4945 displaying something, or otherwise we should not run the hook. */
4946 xassert (it
->glyph_row
);
4948 /* Set up hook arguments. */
4949 args
[0] = Qredisplay_end_trigger_functions
;
4950 args
[1] = it
->window
;
4951 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4952 it
->redisplay_end_trigger_charpos
= 0;
4954 /* Since we are *trying* to run these functions, don't try to run
4955 them again, even if they get an error. */
4956 it
->w
->redisplay_end_trigger
= Qnil
;
4957 Frun_hook_with_args (3, args
);
4959 /* Notice if it changed the face of the character we are on. */
4960 handle_face_prop (it
);
4964 /* Deliver a composition display element. The iterator IT is already
4965 filled with composition information (done in
4966 handle_composition_prop). Value is always 1. */
4969 next_element_from_composition (it
)
4972 it
->what
= IT_COMPOSITION
;
4973 it
->position
= (STRINGP (it
->string
)
4974 ? it
->current
.string_pos
4981 /***********************************************************************
4982 Moving an iterator without producing glyphs
4983 ***********************************************************************/
4985 /* Move iterator IT to a specified buffer or X position within one
4986 line on the display without producing glyphs.
4988 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4989 whichever is reached first.
4991 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4993 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4994 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4995 TO_X includes the amount by which a window is horizontally
5000 MOVE_POS_MATCH_OR_ZV
5001 - when TO_POS or ZV was reached.
5004 -when TO_X was reached before TO_POS or ZV were reached.
5007 - when we reached the end of the display area and the line must
5011 - when we reached the end of the display area and the line is
5015 - when we stopped at a line end, i.e. a newline or a CR and selective
5018 static enum move_it_result
5019 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5021 int to_charpos
, to_x
, op
;
5023 enum move_it_result result
= MOVE_UNDEFINED
;
5024 struct glyph_row
*saved_glyph_row
;
5026 /* Don't produce glyphs in produce_glyphs. */
5027 saved_glyph_row
= it
->glyph_row
;
5028 it
->glyph_row
= NULL
;
5032 int x
, i
, ascent
= 0, descent
= 0;
5034 /* Stop when ZV or TO_CHARPOS reached. */
5035 if (!get_next_display_element (it
)
5036 || ((op
& MOVE_TO_POS
) != 0
5037 && BUFFERP (it
->object
)
5038 && IT_CHARPOS (*it
) >= to_charpos
))
5040 result
= MOVE_POS_MATCH_OR_ZV
;
5044 /* The call to produce_glyphs will get the metrics of the
5045 display element IT is loaded with. We record in x the
5046 x-position before this display element in case it does not
5050 /* Remember the line height so far in case the next element doesn't
5052 if (!it
->truncate_lines_p
)
5054 ascent
= it
->max_ascent
;
5055 descent
= it
->max_descent
;
5058 PRODUCE_GLYPHS (it
);
5060 if (it
->area
!= TEXT_AREA
)
5062 set_iterator_to_next (it
, 1);
5066 /* The number of glyphs we get back in IT->nglyphs will normally
5067 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5068 character on a terminal frame, or (iii) a line end. For the
5069 second case, IT->nglyphs - 1 padding glyphs will be present
5070 (on X frames, there is only one glyph produced for a
5071 composite character.
5073 The behavior implemented below means, for continuation lines,
5074 that as many spaces of a TAB as fit on the current line are
5075 displayed there. For terminal frames, as many glyphs of a
5076 multi-glyph character are displayed in the current line, too.
5077 This is what the old redisplay code did, and we keep it that
5078 way. Under X, the whole shape of a complex character must
5079 fit on the line or it will be completely displayed in the
5082 Note that both for tabs and padding glyphs, all glyphs have
5086 /* More than one glyph or glyph doesn't fit on line. All
5087 glyphs have the same width. */
5088 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5091 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5093 new_x
= x
+ single_glyph_width
;
5095 /* We want to leave anything reaching TO_X to the caller. */
5096 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5099 result
= MOVE_X_REACHED
;
5102 else if (/* Lines are continued. */
5103 !it
->truncate_lines_p
5104 && (/* And glyph doesn't fit on the line. */
5105 new_x
> it
->last_visible_x
5106 /* Or it fits exactly and we're on a window
5108 || (new_x
== it
->last_visible_x
5109 && FRAME_WINDOW_P (it
->f
))))
5111 if (/* IT->hpos == 0 means the very first glyph
5112 doesn't fit on the line, e.g. a wide image. */
5114 || (new_x
== it
->last_visible_x
5115 && FRAME_WINDOW_P (it
->f
)))
5118 it
->current_x
= new_x
;
5119 if (i
== it
->nglyphs
- 1)
5120 set_iterator_to_next (it
, 1);
5125 it
->max_ascent
= ascent
;
5126 it
->max_descent
= descent
;
5129 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5131 result
= MOVE_LINE_CONTINUED
;
5134 else if (new_x
> it
->first_visible_x
)
5136 /* Glyph is visible. Increment number of glyphs that
5137 would be displayed. */
5142 /* Glyph is completely off the left margin of the display
5143 area. Nothing to do. */
5147 if (result
!= MOVE_UNDEFINED
)
5150 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5152 /* Stop when TO_X specified and reached. This check is
5153 necessary here because of lines consisting of a line end,
5154 only. The line end will not produce any glyphs and we
5155 would never get MOVE_X_REACHED. */
5156 xassert (it
->nglyphs
== 0);
5157 result
= MOVE_X_REACHED
;
5161 /* Is this a line end? If yes, we're done. */
5162 if (ITERATOR_AT_END_OF_LINE_P (it
))
5164 result
= MOVE_NEWLINE_OR_CR
;
5168 /* The current display element has been consumed. Advance
5170 set_iterator_to_next (it
, 1);
5172 /* Stop if lines are truncated and IT's current x-position is
5173 past the right edge of the window now. */
5174 if (it
->truncate_lines_p
5175 && it
->current_x
>= it
->last_visible_x
)
5177 result
= MOVE_LINE_TRUNCATED
;
5182 /* Restore the iterator settings altered at the beginning of this
5184 it
->glyph_row
= saved_glyph_row
;
5189 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5190 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5191 the description of enum move_operation_enum.
5193 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5194 screen line, this function will set IT to the next position >
5198 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5200 int to_charpos
, to_x
, to_y
, to_vpos
;
5203 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5209 if (op
& MOVE_TO_VPOS
)
5211 /* If no TO_CHARPOS and no TO_X specified, stop at the
5212 start of the line TO_VPOS. */
5213 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5215 if (it
->vpos
== to_vpos
)
5221 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5225 /* TO_VPOS >= 0 means stop at TO_X in the line at
5226 TO_VPOS, or at TO_POS, whichever comes first. */
5227 if (it
->vpos
== to_vpos
)
5233 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5235 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5240 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5242 /* We have reached TO_X but not in the line we want. */
5243 skip
= move_it_in_display_line_to (it
, to_charpos
,
5245 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5253 else if (op
& MOVE_TO_Y
)
5255 struct it it_backup
;
5257 /* TO_Y specified means stop at TO_X in the line containing
5258 TO_Y---or at TO_CHARPOS if this is reached first. The
5259 problem is that we can't really tell whether the line
5260 contains TO_Y before we have completely scanned it, and
5261 this may skip past TO_X. What we do is to first scan to
5264 If TO_X is not specified, use a TO_X of zero. The reason
5265 is to make the outcome of this function more predictable.
5266 If we didn't use TO_X == 0, we would stop at the end of
5267 the line which is probably not what a caller would expect
5269 skip
= move_it_in_display_line_to (it
, to_charpos
,
5273 | (op
& MOVE_TO_POS
)));
5275 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5276 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5282 /* If TO_X was reached, we would like to know whether TO_Y
5283 is in the line. This can only be said if we know the
5284 total line height which requires us to scan the rest of
5286 if (skip
== MOVE_X_REACHED
)
5289 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5290 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5292 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5295 /* Now, decide whether TO_Y is in this line. */
5296 line_height
= it
->max_ascent
+ it
->max_descent
;
5297 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5299 if (to_y
>= it
->current_y
5300 && to_y
< it
->current_y
+ line_height
)
5302 if (skip
== MOVE_X_REACHED
)
5303 /* If TO_Y is in this line and TO_X was reached above,
5304 we scanned too far. We have to restore IT's settings
5305 to the ones before skipping. */
5309 else if (skip
== MOVE_X_REACHED
)
5312 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5320 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5324 case MOVE_POS_MATCH_OR_ZV
:
5328 case MOVE_NEWLINE_OR_CR
:
5329 set_iterator_to_next (it
, 1);
5330 it
->continuation_lines_width
= 0;
5333 case MOVE_LINE_TRUNCATED
:
5334 it
->continuation_lines_width
= 0;
5335 reseat_at_next_visible_line_start (it
, 0);
5336 if ((op
& MOVE_TO_POS
) != 0
5337 && IT_CHARPOS (*it
) > to_charpos
)
5344 case MOVE_LINE_CONTINUED
:
5345 it
->continuation_lines_width
+= it
->current_x
;
5352 /* Reset/increment for the next run. */
5353 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5354 it
->current_x
= it
->hpos
= 0;
5355 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5357 last_height
= it
->max_ascent
+ it
->max_descent
;
5358 last_max_ascent
= it
->max_ascent
;
5359 it
->max_ascent
= it
->max_descent
= 0;
5364 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5368 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5370 If DY > 0, move IT backward at least that many pixels. DY = 0
5371 means move IT backward to the preceding line start or BEGV. This
5372 function may move over more than DY pixels if IT->current_y - DY
5373 ends up in the middle of a line; in this case IT->current_y will be
5374 set to the top of the line moved to. */
5377 move_it_vertically_backward (it
, dy
)
5383 int start_pos
= IT_CHARPOS (*it
);
5387 /* Estimate how many newlines we must move back. */
5388 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5390 /* Set the iterator's position that many lines back. */
5391 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5392 back_to_previous_visible_line_start (it
);
5394 /* Reseat the iterator here. When moving backward, we don't want
5395 reseat to skip forward over invisible text, set up the iterator
5396 to deliver from overlay strings at the new position etc. So,
5397 use reseat_1 here. */
5398 reseat_1 (it
, it
->current
.pos
, 1);
5400 /* We are now surely at a line start. */
5401 it
->current_x
= it
->hpos
= 0;
5403 /* Move forward and see what y-distance we moved. First move to the
5404 start of the next line so that we get its height. We need this
5405 height to be able to tell whether we reached the specified
5408 it2
.max_ascent
= it2
.max_descent
= 0;
5409 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5410 MOVE_TO_POS
| MOVE_TO_VPOS
);
5411 xassert (IT_CHARPOS (*it
) >= BEGV
);
5414 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5415 xassert (IT_CHARPOS (*it
) >= BEGV
);
5416 h
= it2
.current_y
- it
->current_y
;
5417 nlines
= it2
.vpos
- it
->vpos
;
5419 /* Correct IT's y and vpos position. */
5425 /* DY == 0 means move to the start of the screen line. The
5426 value of nlines is > 0 if continuation lines were involved. */
5428 move_it_by_lines (it
, nlines
, 1);
5429 xassert (IT_CHARPOS (*it
) <= start_pos
);
5433 /* The y-position we try to reach. Note that h has been
5434 subtracted in front of the if-statement. */
5435 int target_y
= it
->current_y
+ h
- dy
;
5436 int y0
= it3
.current_y
;
5437 int y1
= line_bottom_y (&it3
);
5438 int line_height
= y1
- y0
;
5440 /* If we did not reach target_y, try to move further backward if
5441 we can. If we moved too far backward, try to move forward. */
5442 if (target_y
< it
->current_y
5443 /* This is heuristic. In a window that's 3 lines high, with
5444 a line height of 13 pixels each, recentering with point
5445 on the bottom line will try to move -39/2 = 19 pixels
5446 backward. Try to avoid moving into the first line. */
5447 && it
->current_y
- target_y
> line_height
/ 3 * 2
5448 && IT_CHARPOS (*it
) > BEGV
)
5450 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5451 target_y
- it
->current_y
));
5452 move_it_vertically (it
, target_y
- it
->current_y
);
5453 xassert (IT_CHARPOS (*it
) >= BEGV
);
5455 else if (target_y
>= it
->current_y
+ line_height
5456 && IT_CHARPOS (*it
) < ZV
)
5458 /* Should move forward by at least one line, maybe more. */
5461 move_it_by_lines (it
, 1, 1);
5463 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5465 xassert (IT_CHARPOS (*it
) >= BEGV
);
5471 /* Move IT by a specified amount of pixel lines DY. DY negative means
5472 move backwards. DY = 0 means move to start of screen line. At the
5473 end, IT will be on the start of a screen line. */
5476 move_it_vertically (it
, dy
)
5481 move_it_vertically_backward (it
, -dy
);
5484 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5485 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5486 MOVE_TO_POS
| MOVE_TO_Y
);
5487 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5489 /* If buffer ends in ZV without a newline, move to the start of
5490 the line to satisfy the post-condition. */
5491 if (IT_CHARPOS (*it
) == ZV
5492 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5493 move_it_by_lines (it
, 0, 0);
5498 /* Move iterator IT past the end of the text line it is in. */
5501 move_it_past_eol (it
)
5504 enum move_it_result rc
;
5506 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5507 if (rc
== MOVE_NEWLINE_OR_CR
)
5508 set_iterator_to_next (it
, 0);
5512 #if 0 /* Currently not used. */
5514 /* Return non-zero if some text between buffer positions START_CHARPOS
5515 and END_CHARPOS is invisible. IT->window is the window for text
5519 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5521 int start_charpos
, end_charpos
;
5523 Lisp_Object prop
, limit
;
5524 int invisible_found_p
;
5526 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5528 /* Is text at START invisible? */
5529 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5531 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5532 invisible_found_p
= 1;
5535 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5537 make_number (end_charpos
));
5538 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5541 return invisible_found_p
;
5547 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5548 negative means move up. DVPOS == 0 means move to the start of the
5549 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5550 NEED_Y_P is zero, IT->current_y will be left unchanged.
5552 Further optimization ideas: If we would know that IT->f doesn't use
5553 a face with proportional font, we could be faster for
5554 truncate-lines nil. */
5557 move_it_by_lines (it
, dvpos
, need_y_p
)
5559 int dvpos
, need_y_p
;
5561 struct position pos
;
5563 if (!FRAME_WINDOW_P (it
->f
))
5565 struct text_pos textpos
;
5567 /* We can use vmotion on frames without proportional fonts. */
5568 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5569 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5570 reseat (it
, textpos
, 1);
5571 it
->vpos
+= pos
.vpos
;
5572 it
->current_y
+= pos
.vpos
;
5574 else if (dvpos
== 0)
5576 /* DVPOS == 0 means move to the start of the screen line. */
5577 move_it_vertically_backward (it
, 0);
5578 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5581 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5585 int start_charpos
, i
;
5587 /* Start at the beginning of the screen line containing IT's
5589 move_it_vertically_backward (it
, 0);
5591 /* Go back -DVPOS visible lines and reseat the iterator there. */
5592 start_charpos
= IT_CHARPOS (*it
);
5593 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5594 back_to_previous_visible_line_start (it
);
5595 reseat (it
, it
->current
.pos
, 1);
5596 it
->current_x
= it
->hpos
= 0;
5598 /* Above call may have moved too far if continuation lines
5599 are involved. Scan forward and see if it did. */
5601 it2
.vpos
= it2
.current_y
= 0;
5602 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5603 it
->vpos
-= it2
.vpos
;
5604 it
->current_y
-= it2
.current_y
;
5605 it
->current_x
= it
->hpos
= 0;
5607 /* If we moved too far, move IT some lines forward. */
5608 if (it2
.vpos
> -dvpos
)
5610 int delta
= it2
.vpos
+ dvpos
;
5611 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5618 /***********************************************************************
5620 ***********************************************************************/
5623 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5627 add_to_log (format
, arg1
, arg2
)
5629 Lisp_Object arg1
, arg2
;
5631 Lisp_Object args
[3];
5632 Lisp_Object msg
, fmt
;
5635 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5637 /* Do nothing if called asynchronously. Inserting text into
5638 a buffer may call after-change-functions and alike and
5639 that would means running Lisp asynchronously. */
5640 if (handling_signal
)
5644 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5646 args
[0] = fmt
= build_string (format
);
5649 msg
= Fformat (3, args
);
5651 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5652 buffer
= (char *) alloca (len
);
5653 bcopy (XSTRING (msg
)->data
, buffer
, len
);
5655 message_dolog (buffer
, len
- 1, 1, 0);
5660 /* Output a newline in the *Messages* buffer if "needs" one. */
5663 message_log_maybe_newline ()
5665 if (message_log_need_newline
)
5666 message_dolog ("", 0, 1, 0);
5670 /* Add a string M of length NBYTES to the message log, optionally
5671 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5672 nonzero, means interpret the contents of M as multibyte. This
5673 function calls low-level routines in order to bypass text property
5674 hooks, etc. which might not be safe to run. */
5677 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5679 int nbytes
, nlflag
, multibyte
;
5681 if (!NILP (Vmessage_log_max
))
5683 struct buffer
*oldbuf
;
5684 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5685 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5686 int point_at_end
= 0;
5688 Lisp_Object old_deactivate_mark
, tem
;
5689 struct gcpro gcpro1
;
5691 old_deactivate_mark
= Vdeactivate_mark
;
5692 oldbuf
= current_buffer
;
5693 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5694 current_buffer
->undo_list
= Qt
;
5696 oldpoint
= message_dolog_marker1
;
5697 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5698 oldbegv
= message_dolog_marker2
;
5699 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5700 oldzv
= message_dolog_marker3
;
5701 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5702 GCPRO1 (old_deactivate_mark
);
5710 BEGV_BYTE
= BEG_BYTE
;
5713 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5715 /* Insert the string--maybe converting multibyte to single byte
5716 or vice versa, so that all the text fits the buffer. */
5718 && NILP (current_buffer
->enable_multibyte_characters
))
5720 int i
, c
, char_bytes
;
5721 unsigned char work
[1];
5723 /* Convert a multibyte string to single-byte
5724 for the *Message* buffer. */
5725 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5727 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5728 work
[0] = (ASCII_CHAR_P (c
)
5730 : multibyte_char_to_unibyte (c
, Qnil
));
5731 insert_1_both (work
, 1, 1, 1, 0, 0);
5734 else if (! multibyte
5735 && ! NILP (current_buffer
->enable_multibyte_characters
))
5737 int i
, c
, char_bytes
;
5738 unsigned char *msg
= (unsigned char *) m
;
5739 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5740 /* Convert a single-byte string to multibyte
5741 for the *Message* buffer. */
5742 for (i
= 0; i
< nbytes
; i
++)
5744 c
= unibyte_char_to_multibyte (msg
[i
]);
5745 char_bytes
= CHAR_STRING (c
, str
);
5746 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5750 insert_1 (m
, nbytes
, 1, 0, 0);
5754 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5755 insert_1 ("\n", 1, 1, 0, 0);
5757 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5759 this_bol_byte
= PT_BYTE
;
5761 /* See if this line duplicates the previous one.
5762 If so, combine duplicates. */
5765 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5767 prev_bol_byte
= PT_BYTE
;
5769 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5770 this_bol
, this_bol_byte
);
5773 del_range_both (prev_bol
, prev_bol_byte
,
5774 this_bol
, this_bol_byte
, 0);
5780 /* If you change this format, don't forget to also
5781 change message_log_check_duplicate. */
5782 sprintf (dupstr
, " [%d times]", dup
);
5783 duplen
= strlen (dupstr
);
5784 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5785 insert_1 (dupstr
, duplen
, 1, 0, 1);
5790 /* If we have more than the desired maximum number of lines
5791 in the *Messages* buffer now, delete the oldest ones.
5792 This is safe because we don't have undo in this buffer. */
5794 if (NATNUMP (Vmessage_log_max
))
5796 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5797 -XFASTINT (Vmessage_log_max
) - 1, 0);
5798 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5801 BEGV
= XMARKER (oldbegv
)->charpos
;
5802 BEGV_BYTE
= marker_byte_position (oldbegv
);
5811 ZV
= XMARKER (oldzv
)->charpos
;
5812 ZV_BYTE
= marker_byte_position (oldzv
);
5816 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5818 /* We can't do Fgoto_char (oldpoint) because it will run some
5820 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5821 XMARKER (oldpoint
)->bytepos
);
5824 unchain_marker (oldpoint
);
5825 unchain_marker (oldbegv
);
5826 unchain_marker (oldzv
);
5828 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5829 set_buffer_internal (oldbuf
);
5831 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5832 message_log_need_newline
= !nlflag
;
5833 Vdeactivate_mark
= old_deactivate_mark
;
5838 /* We are at the end of the buffer after just having inserted a newline.
5839 (Note: We depend on the fact we won't be crossing the gap.)
5840 Check to see if the most recent message looks a lot like the previous one.
5841 Return 0 if different, 1 if the new one should just replace it, or a
5842 value N > 1 if we should also append " [N times]". */
5845 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5846 int prev_bol
, this_bol
;
5847 int prev_bol_byte
, this_bol_byte
;
5850 int len
= Z_BYTE
- 1 - this_bol_byte
;
5852 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5853 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5855 for (i
= 0; i
< len
; i
++)
5857 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5865 if (*p1
++ == ' ' && *p1
++ == '[')
5868 while (*p1
>= '0' && *p1
<= '9')
5869 n
= n
* 10 + *p1
++ - '0';
5870 if (strncmp (p1
, " times]\n", 8) == 0)
5877 /* Display an echo area message M with a specified length of NBYTES
5878 bytes. The string may include null characters. If M is 0, clear
5879 out any existing message, and let the mini-buffer text show
5882 The buffer M must continue to exist until after the echo area gets
5883 cleared or some other message gets displayed there. This means do
5884 not pass text that is stored in a Lisp string; do not pass text in
5885 a buffer that was alloca'd. */
5888 message2 (m
, nbytes
, multibyte
)
5893 /* First flush out any partial line written with print. */
5894 message_log_maybe_newline ();
5896 message_dolog (m
, nbytes
, 1, multibyte
);
5897 message2_nolog (m
, nbytes
, multibyte
);
5901 /* The non-logging counterpart of message2. */
5904 message2_nolog (m
, nbytes
, multibyte
)
5906 int nbytes
, multibyte
;
5908 struct frame
*sf
= SELECTED_FRAME ();
5909 message_enable_multibyte
= multibyte
;
5913 if (noninteractive_need_newline
)
5914 putc ('\n', stderr
);
5915 noninteractive_need_newline
= 0;
5917 fwrite (m
, nbytes
, 1, stderr
);
5918 if (cursor_in_echo_area
== 0)
5919 fprintf (stderr
, "\n");
5922 /* A null message buffer means that the frame hasn't really been
5923 initialized yet. Error messages get reported properly by
5924 cmd_error, so this must be just an informative message; toss it. */
5925 else if (INTERACTIVE
5926 && sf
->glyphs_initialized_p
5927 && FRAME_MESSAGE_BUF (sf
))
5929 Lisp_Object mini_window
;
5932 /* Get the frame containing the mini-buffer
5933 that the selected frame is using. */
5934 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5935 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5937 FRAME_SAMPLE_VISIBILITY (f
);
5938 if (FRAME_VISIBLE_P (sf
)
5939 && ! FRAME_VISIBLE_P (f
))
5940 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5944 set_message (m
, Qnil
, nbytes
, multibyte
);
5945 if (minibuffer_auto_raise
)
5946 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5949 clear_message (1, 1);
5951 do_pending_window_change (0);
5952 echo_area_display (1);
5953 do_pending_window_change (0);
5954 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5955 (*frame_up_to_date_hook
) (f
);
5960 /* Display an echo area message M with a specified length of NBYTES
5961 bytes. The string may include null characters. If M is not a
5962 string, clear out any existing message, and let the mini-buffer
5963 text show through. */
5966 message3 (m
, nbytes
, multibyte
)
5971 struct gcpro gcpro1
;
5975 /* First flush out any partial line written with print. */
5976 message_log_maybe_newline ();
5978 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5979 message3_nolog (m
, nbytes
, multibyte
);
5985 /* The non-logging version of message3. */
5988 message3_nolog (m
, nbytes
, multibyte
)
5990 int nbytes
, multibyte
;
5992 struct frame
*sf
= SELECTED_FRAME ();
5993 message_enable_multibyte
= multibyte
;
5997 if (noninteractive_need_newline
)
5998 putc ('\n', stderr
);
5999 noninteractive_need_newline
= 0;
6001 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
6002 if (cursor_in_echo_area
== 0)
6003 fprintf (stderr
, "\n");
6006 /* A null message buffer means that the frame hasn't really been
6007 initialized yet. Error messages get reported properly by
6008 cmd_error, so this must be just an informative message; toss it. */
6009 else if (INTERACTIVE
6010 && sf
->glyphs_initialized_p
6011 && FRAME_MESSAGE_BUF (sf
))
6013 Lisp_Object mini_window
;
6017 /* Get the frame containing the mini-buffer
6018 that the selected frame is using. */
6019 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6020 frame
= XWINDOW (mini_window
)->frame
;
6023 FRAME_SAMPLE_VISIBILITY (f
);
6024 if (FRAME_VISIBLE_P (sf
)
6025 && !FRAME_VISIBLE_P (f
))
6026 Fmake_frame_visible (frame
);
6028 if (STRINGP (m
) && XSTRING (m
)->size
)
6030 set_message (NULL
, m
, nbytes
, multibyte
);
6031 if (minibuffer_auto_raise
)
6032 Fraise_frame (frame
);
6035 clear_message (1, 1);
6037 do_pending_window_change (0);
6038 echo_area_display (1);
6039 do_pending_window_change (0);
6040 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6041 (*frame_up_to_date_hook
) (f
);
6046 /* Display a null-terminated echo area message M. If M is 0, clear
6047 out any existing message, and let the mini-buffer text show through.
6049 The buffer M must continue to exist until after the echo area gets
6050 cleared or some other message gets displayed there. Do not pass
6051 text that is stored in a Lisp string. Do not pass text in a buffer
6052 that was alloca'd. */
6058 message2 (m
, (m
? strlen (m
) : 0), 0);
6062 /* The non-logging counterpart of message1. */
6068 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6071 /* Display a message M which contains a single %s
6072 which gets replaced with STRING. */
6075 message_with_string (m
, string
, log
)
6084 if (noninteractive_need_newline
)
6085 putc ('\n', stderr
);
6086 noninteractive_need_newline
= 0;
6087 fprintf (stderr
, m
, XSTRING (string
)->data
);
6088 if (cursor_in_echo_area
== 0)
6089 fprintf (stderr
, "\n");
6093 else if (INTERACTIVE
)
6095 /* The frame whose minibuffer we're going to display the message on.
6096 It may be larger than the selected frame, so we need
6097 to use its buffer, not the selected frame's buffer. */
6098 Lisp_Object mini_window
;
6099 struct frame
*f
, *sf
= SELECTED_FRAME ();
6101 /* Get the frame containing the minibuffer
6102 that the selected frame is using. */
6103 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6104 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6106 /* A null message buffer means that the frame hasn't really been
6107 initialized yet. Error messages get reported properly by
6108 cmd_error, so this must be just an informative message; toss it. */
6109 if (FRAME_MESSAGE_BUF (f
))
6113 a
[0] = (char *) XSTRING (string
)->data
;
6115 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6116 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6119 message2 (FRAME_MESSAGE_BUF (f
), len
,
6120 STRING_MULTIBYTE (string
));
6122 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
6123 STRING_MULTIBYTE (string
));
6125 /* Print should start at the beginning of the message
6126 buffer next time. */
6127 message_buf_print
= 0;
6133 /* Dump an informative message to the minibuf. If M is 0, clear out
6134 any existing message, and let the mini-buffer text show through. */
6138 message (m
, a1
, a2
, a3
)
6140 EMACS_INT a1
, a2
, a3
;
6146 if (noninteractive_need_newline
)
6147 putc ('\n', stderr
);
6148 noninteractive_need_newline
= 0;
6149 fprintf (stderr
, m
, a1
, a2
, a3
);
6150 if (cursor_in_echo_area
== 0)
6151 fprintf (stderr
, "\n");
6155 else if (INTERACTIVE
)
6157 /* The frame whose mini-buffer we're going to display the message
6158 on. It may be larger than the selected frame, so we need to
6159 use its buffer, not the selected frame's buffer. */
6160 Lisp_Object mini_window
;
6161 struct frame
*f
, *sf
= SELECTED_FRAME ();
6163 /* Get the frame containing the mini-buffer
6164 that the selected frame is using. */
6165 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6166 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6168 /* A null message buffer means that the frame hasn't really been
6169 initialized yet. Error messages get reported properly by
6170 cmd_error, so this must be just an informative message; toss
6172 if (FRAME_MESSAGE_BUF (f
))
6183 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6184 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6186 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6187 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6189 #endif /* NO_ARG_ARRAY */
6191 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6196 /* Print should start at the beginning of the message
6197 buffer next time. */
6198 message_buf_print
= 0;
6204 /* The non-logging version of message. */
6207 message_nolog (m
, a1
, a2
, a3
)
6209 EMACS_INT a1
, a2
, a3
;
6211 Lisp_Object old_log_max
;
6212 old_log_max
= Vmessage_log_max
;
6213 Vmessage_log_max
= Qnil
;
6214 message (m
, a1
, a2
, a3
);
6215 Vmessage_log_max
= old_log_max
;
6219 /* Display the current message in the current mini-buffer. This is
6220 only called from error handlers in process.c, and is not time
6226 if (!NILP (echo_area_buffer
[0]))
6229 string
= Fcurrent_message ();
6230 message3 (string
, XSTRING (string
)->size
,
6231 !NILP (current_buffer
->enable_multibyte_characters
));
6236 /* Make sure echo area buffers in echo_buffers[] are life. If they
6237 aren't, make new ones. */
6240 ensure_echo_area_buffers ()
6244 for (i
= 0; i
< 2; ++i
)
6245 if (!BUFFERP (echo_buffer
[i
])
6246 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6249 Lisp_Object old_buffer
;
6252 old_buffer
= echo_buffer
[i
];
6253 sprintf (name
, " *Echo Area %d*", i
);
6254 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6255 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6257 for (j
= 0; j
< 2; ++j
)
6258 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6259 echo_area_buffer
[j
] = echo_buffer
[i
];
6264 /* Call FN with args A1..A4 with either the current or last displayed
6265 echo_area_buffer as current buffer.
6267 WHICH zero means use the current message buffer
6268 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6269 from echo_buffer[] and clear it.
6271 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6272 suitable buffer from echo_buffer[] and clear it.
6274 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6275 that the current message becomes the last displayed one, make
6276 choose a suitable buffer for echo_area_buffer[0], and clear it.
6278 Value is what FN returns. */
6281 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6284 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6290 int this_one
, the_other
, clear_buffer_p
, rc
;
6291 int count
= BINDING_STACK_SIZE ();
6293 /* If buffers aren't life, make new ones. */
6294 ensure_echo_area_buffers ();
6299 this_one
= 0, the_other
= 1;
6301 this_one
= 1, the_other
= 0;
6304 this_one
= 0, the_other
= 1;
6307 /* We need a fresh one in case the current echo buffer equals
6308 the one containing the last displayed echo area message. */
6309 if (!NILP (echo_area_buffer
[this_one
])
6310 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6311 echo_area_buffer
[this_one
] = Qnil
;
6314 /* Choose a suitable buffer from echo_buffer[] is we don't
6316 if (NILP (echo_area_buffer
[this_one
]))
6318 echo_area_buffer
[this_one
]
6319 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6320 ? echo_buffer
[the_other
]
6321 : echo_buffer
[this_one
]);
6325 buffer
= echo_area_buffer
[this_one
];
6327 /* Don't get confused by reusing the buffer used for echoing
6328 for a different purpose. */
6329 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6332 record_unwind_protect (unwind_with_echo_area_buffer
,
6333 with_echo_area_buffer_unwind_data (w
));
6335 /* Make the echo area buffer current. Note that for display
6336 purposes, it is not necessary that the displayed window's buffer
6337 == current_buffer, except for text property lookup. So, let's
6338 only set that buffer temporarily here without doing a full
6339 Fset_window_buffer. We must also change w->pointm, though,
6340 because otherwise an assertions in unshow_buffer fails, and Emacs
6342 set_buffer_internal_1 (XBUFFER (buffer
));
6346 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6349 current_buffer
->undo_list
= Qt
;
6350 current_buffer
->read_only
= Qnil
;
6351 specbind (Qinhibit_read_only
, Qt
);
6352 specbind (Qinhibit_modification_hooks
, Qt
);
6354 if (clear_buffer_p
&& Z
> BEG
)
6357 xassert (BEGV
>= BEG
);
6358 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6360 rc
= fn (a1
, a2
, a3
, a4
);
6362 xassert (BEGV
>= BEG
);
6363 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6365 unbind_to (count
, Qnil
);
6370 /* Save state that should be preserved around the call to the function
6371 FN called in with_echo_area_buffer. */
6374 with_echo_area_buffer_unwind_data (w
)
6380 /* Reduce consing by keeping one vector in
6381 Vwith_echo_area_save_vector. */
6382 vector
= Vwith_echo_area_save_vector
;
6383 Vwith_echo_area_save_vector
= Qnil
;
6386 vector
= Fmake_vector (make_number (7), Qnil
);
6388 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6389 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6390 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6394 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6395 AREF (vector
, i
) = w
->buffer
; ++i
;
6396 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6397 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6402 for (; i
< end
; ++i
)
6403 AREF (vector
, i
) = Qnil
;
6406 xassert (i
== ASIZE (vector
));
6411 /* Restore global state from VECTOR which was created by
6412 with_echo_area_buffer_unwind_data. */
6415 unwind_with_echo_area_buffer (vector
)
6418 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6419 Vdeactivate_mark
= AREF (vector
, 1);
6420 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6422 if (WINDOWP (AREF (vector
, 3)))
6425 Lisp_Object buffer
, charpos
, bytepos
;
6427 w
= XWINDOW (AREF (vector
, 3));
6428 buffer
= AREF (vector
, 4);
6429 charpos
= AREF (vector
, 5);
6430 bytepos
= AREF (vector
, 6);
6433 set_marker_both (w
->pointm
, buffer
,
6434 XFASTINT (charpos
), XFASTINT (bytepos
));
6437 Vwith_echo_area_save_vector
= vector
;
6442 /* Set up the echo area for use by print functions. MULTIBYTE_P
6443 non-zero means we will print multibyte. */
6446 setup_echo_area_for_printing (multibyte_p
)
6449 ensure_echo_area_buffers ();
6451 if (!message_buf_print
)
6453 /* A message has been output since the last time we printed.
6454 Choose a fresh echo area buffer. */
6455 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6456 echo_area_buffer
[0] = echo_buffer
[1];
6458 echo_area_buffer
[0] = echo_buffer
[0];
6460 /* Switch to that buffer and clear it. */
6461 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6462 current_buffer
->truncate_lines
= Qnil
;
6466 int count
= BINDING_STACK_SIZE ();
6467 specbind (Qinhibit_read_only
, Qt
);
6469 unbind_to (count
, Qnil
);
6471 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6473 /* Set up the buffer for the multibyteness we need. */
6475 != !NILP (current_buffer
->enable_multibyte_characters
))
6476 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
, Qnil
);
6478 /* Raise the frame containing the echo area. */
6479 if (minibuffer_auto_raise
)
6481 struct frame
*sf
= SELECTED_FRAME ();
6482 Lisp_Object mini_window
;
6483 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6484 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6487 message_log_maybe_newline ();
6488 message_buf_print
= 1;
6492 if (NILP (echo_area_buffer
[0]))
6494 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6495 echo_area_buffer
[0] = echo_buffer
[1];
6497 echo_area_buffer
[0] = echo_buffer
[0];
6500 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6502 /* Someone switched buffers between print requests. */
6503 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6504 current_buffer
->truncate_lines
= Qnil
;
6510 /* Display an echo area message in window W. Value is non-zero if W's
6511 height is changed. If display_last_displayed_message_p is
6512 non-zero, display the message that was last displayed, otherwise
6513 display the current message. */
6516 display_echo_area (w
)
6519 int i
, no_message_p
, window_height_changed_p
, count
;
6521 /* Temporarily disable garbage collections while displaying the echo
6522 area. This is done because a GC can print a message itself.
6523 That message would modify the echo area buffer's contents while a
6524 redisplay of the buffer is going on, and seriously confuse
6526 count
= inhibit_garbage_collection ();
6528 /* If there is no message, we must call display_echo_area_1
6529 nevertheless because it resizes the window. But we will have to
6530 reset the echo_area_buffer in question to nil at the end because
6531 with_echo_area_buffer will sets it to an empty buffer. */
6532 i
= display_last_displayed_message_p
? 1 : 0;
6533 no_message_p
= NILP (echo_area_buffer
[i
]);
6535 window_height_changed_p
6536 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6537 display_echo_area_1
,
6538 (EMACS_INT
) w
, Qnil
, 0, 0);
6541 echo_area_buffer
[i
] = Qnil
;
6543 unbind_to (count
, Qnil
);
6544 return window_height_changed_p
;
6548 /* Helper for display_echo_area. Display the current buffer which
6549 contains the current echo area message in window W, a mini-window,
6550 a pointer to which is passed in A1. A2..A4 are currently not used.
6551 Change the height of W so that all of the message is displayed.
6552 Value is non-zero if height of W was changed. */
6555 display_echo_area_1 (a1
, a2
, a3
, a4
)
6560 struct window
*w
= (struct window
*) a1
;
6562 struct text_pos start
;
6563 int window_height_changed_p
= 0;
6565 /* Do this before displaying, so that we have a large enough glyph
6566 matrix for the display. */
6567 window_height_changed_p
= resize_mini_window (w
, 0);
6570 clear_glyph_matrix (w
->desired_matrix
);
6571 XSETWINDOW (window
, w
);
6572 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6573 try_window (window
, start
);
6575 return window_height_changed_p
;
6579 /* Resize the echo area window to exactly the size needed for the
6580 currently displayed message, if there is one. If a mini-buffer
6581 is active, don't shrink it. */
6584 resize_echo_area_exactly ()
6586 if (BUFFERP (echo_area_buffer
[0])
6587 && WINDOWP (echo_area_window
))
6589 struct window
*w
= XWINDOW (echo_area_window
);
6591 Lisp_Object resize_exactly
;
6593 if (minibuf_level
== 0)
6594 resize_exactly
= Qt
;
6596 resize_exactly
= Qnil
;
6598 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6599 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6602 ++windows_or_buffers_changed
;
6603 ++update_mode_lines
;
6604 redisplay_internal (0);
6610 /* Callback function for with_echo_area_buffer, when used from
6611 resize_echo_area_exactly. A1 contains a pointer to the window to
6612 resize, EXACTLY non-nil means resize the mini-window exactly to the
6613 size of the text displayed. A3 and A4 are not used. Value is what
6614 resize_mini_window returns. */
6617 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6619 Lisp_Object exactly
;
6622 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6626 /* Resize mini-window W to fit the size of its contents. EXACT:P
6627 means size the window exactly to the size needed. Otherwise, it's
6628 only enlarged until W's buffer is empty. Value is non-zero if
6629 the window height has been changed. */
6632 resize_mini_window (w
, exact_p
)
6636 struct frame
*f
= XFRAME (w
->frame
);
6637 int window_height_changed_p
= 0;
6639 xassert (MINI_WINDOW_P (w
));
6641 /* Don't resize windows while redisplaying a window; it would
6642 confuse redisplay functions when the size of the window they are
6643 displaying changes from under them. Such a resizing can happen,
6644 for instance, when which-func prints a long message while
6645 we are running fontification-functions. We're running these
6646 functions with safe_call which binds inhibit-redisplay to t. */
6647 if (!NILP (Vinhibit_redisplay
))
6650 /* Nil means don't try to resize. */
6651 if (NILP (Vresize_mini_windows
)
6652 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6655 if (!FRAME_MINIBUF_ONLY_P (f
))
6658 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6659 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6660 int height
, max_height
;
6661 int unit
= CANON_Y_UNIT (f
);
6662 struct text_pos start
;
6663 struct buffer
*old_current_buffer
= NULL
;
6665 if (current_buffer
!= XBUFFER (w
->buffer
))
6667 old_current_buffer
= current_buffer
;
6668 set_buffer_internal (XBUFFER (w
->buffer
));
6671 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6673 /* Compute the max. number of lines specified by the user. */
6674 if (FLOATP (Vmax_mini_window_height
))
6675 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6676 else if (INTEGERP (Vmax_mini_window_height
))
6677 max_height
= XINT (Vmax_mini_window_height
);
6679 max_height
= total_height
/ 4;
6681 /* Correct that max. height if it's bogus. */
6682 max_height
= max (1, max_height
);
6683 max_height
= min (total_height
, max_height
);
6685 /* Find out the height of the text in the window. */
6686 if (it
.truncate_lines_p
)
6691 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6692 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6693 height
= it
.current_y
+ last_height
;
6695 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6696 height
-= it
.extra_line_spacing
;
6697 height
= (height
+ unit
- 1) / unit
;
6700 /* Compute a suitable window start. */
6701 if (height
> max_height
)
6703 height
= max_height
;
6704 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6705 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6706 start
= it
.current
.pos
;
6709 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6710 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6712 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6714 /* Let it grow only, until we display an empty message, in which
6715 case the window shrinks again. */
6716 if (height
> XFASTINT (w
->height
))
6718 int old_height
= XFASTINT (w
->height
);
6719 freeze_window_starts (f
, 1);
6720 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6721 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6723 else if (height
< XFASTINT (w
->height
)
6724 && (exact_p
|| BEGV
== ZV
))
6726 int old_height
= XFASTINT (w
->height
);
6727 freeze_window_starts (f
, 0);
6728 shrink_mini_window (w
);
6729 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6734 /* Always resize to exact size needed. */
6735 if (height
> XFASTINT (w
->height
))
6737 int old_height
= XFASTINT (w
->height
);
6738 freeze_window_starts (f
, 1);
6739 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6740 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6742 else if (height
< XFASTINT (w
->height
))
6744 int old_height
= XFASTINT (w
->height
);
6745 freeze_window_starts (f
, 0);
6746 shrink_mini_window (w
);
6750 freeze_window_starts (f
, 1);
6751 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6754 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6758 if (old_current_buffer
)
6759 set_buffer_internal (old_current_buffer
);
6762 return window_height_changed_p
;
6766 /* Value is the current message, a string, or nil if there is no
6774 if (NILP (echo_area_buffer
[0]))
6778 with_echo_area_buffer (0, 0, current_message_1
,
6779 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6781 echo_area_buffer
[0] = Qnil
;
6789 current_message_1 (a1
, a2
, a3
, a4
)
6794 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6797 *msg
= make_buffer_string (BEG
, Z
, 1);
6804 /* Push the current message on Vmessage_stack for later restauration
6805 by restore_message. Value is non-zero if the current message isn't
6806 empty. This is a relatively infrequent operation, so it's not
6807 worth optimizing. */
6813 msg
= current_message ();
6814 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6815 return STRINGP (msg
);
6819 /* Handler for record_unwind_protect calling pop_message. */
6822 push_message_unwind (dummy
)
6830 /* Restore message display from the top of Vmessage_stack. */
6837 xassert (CONSP (Vmessage_stack
));
6838 msg
= XCAR (Vmessage_stack
);
6840 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6842 message3_nolog (msg
, 0, 0);
6846 /* Pop the top-most entry off Vmessage_stack. */
6851 xassert (CONSP (Vmessage_stack
));
6852 Vmessage_stack
= XCDR (Vmessage_stack
);
6856 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6857 exits. If the stack is not empty, we have a missing pop_message
6861 check_message_stack ()
6863 if (!NILP (Vmessage_stack
))
6868 /* Truncate to NCHARS what will be displayed in the echo area the next
6869 time we display it---but don't redisplay it now. */
6872 truncate_echo_area (nchars
)
6876 echo_area_buffer
[0] = Qnil
;
6877 /* A null message buffer means that the frame hasn't really been
6878 initialized yet. Error messages get reported properly by
6879 cmd_error, so this must be just an informative message; toss it. */
6880 else if (!noninteractive
6882 && !NILP (echo_area_buffer
[0]))
6884 struct frame
*sf
= SELECTED_FRAME ();
6885 if (FRAME_MESSAGE_BUF (sf
))
6886 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6891 /* Helper function for truncate_echo_area. Truncate the current
6892 message to at most NCHARS characters. */
6895 truncate_message_1 (nchars
, a2
, a3
, a4
)
6900 if (BEG
+ nchars
< Z
)
6901 del_range (BEG
+ nchars
, Z
);
6903 echo_area_buffer
[0] = Qnil
;
6908 /* Set the current message to a substring of S or STRING.
6910 If STRING is a Lisp string, set the message to the first NBYTES
6911 bytes from STRING. NBYTES zero means use the whole string. If
6912 STRING is multibyte, the message will be displayed multibyte.
6914 If S is not null, set the message to the first LEN bytes of S. LEN
6915 zero means use the whole string. MULTIBYTE_P non-zero means S is
6916 multibyte. Display the message multibyte in that case. */
6919 set_message (s
, string
, nbytes
, multibyte_p
)
6922 int nbytes
, multibyte_p
;
6924 message_enable_multibyte
6925 = ((s
&& multibyte_p
)
6926 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6928 with_echo_area_buffer (0, -1, set_message_1
,
6929 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6930 message_buf_print
= 0;
6931 help_echo_showing_p
= 0;
6935 /* Helper function for set_message. Arguments have the same meaning
6936 as there, with A1 corresponding to S and A2 corresponding to STRING
6937 This function is called with the echo area buffer being
6941 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6944 EMACS_INT nbytes
, multibyte_p
;
6946 char *s
= (char *) a1
;
6947 Lisp_Object string
= a2
;
6951 /* Change multibyteness of the echo buffer appropriately. */
6952 if (message_enable_multibyte
6953 != !NILP (current_buffer
->enable_multibyte_characters
))
6954 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
, Qnil
);
6956 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6958 /* Insert new message at BEG. */
6959 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6961 if (STRINGP (string
))
6966 nbytes
= XSTRING (string
)->size_byte
;
6967 nchars
= string_byte_to_char (string
, nbytes
);
6969 /* This function takes care of single/multibyte conversion. We
6970 just have to ensure that the echo area buffer has the right
6971 setting of enable_multibyte_characters. */
6972 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6977 nbytes
= strlen (s
);
6979 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6981 /* Convert from multi-byte to single-byte. */
6983 unsigned char work
[1];
6985 /* Convert a multibyte string to single-byte. */
6986 for (i
= 0; i
< nbytes
; i
+= n
)
6988 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6989 work
[0] = (ASCII_CHAR_P (c
)
6991 : multibyte_char_to_unibyte (c
, Qnil
));
6992 insert_1_both (work
, 1, 1, 1, 0, 0);
6995 else if (!multibyte_p
6996 && !NILP (current_buffer
->enable_multibyte_characters
))
6998 /* Convert from single-byte to multi-byte. */
7000 unsigned char *msg
= (unsigned char *) s
;
7001 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7003 /* Convert a single-byte string to multibyte. */
7004 for (i
= 0; i
< nbytes
; i
++)
7006 c
= unibyte_char_to_multibyte (msg
[i
]);
7007 n
= CHAR_STRING (c
, str
);
7008 insert_1_both (str
, 1, n
, 1, 0, 0);
7012 insert_1 (s
, nbytes
, 1, 0, 0);
7019 /* Clear messages. CURRENT_P non-zero means clear the current
7020 message. LAST_DISPLAYED_P non-zero means clear the message
7024 clear_message (current_p
, last_displayed_p
)
7025 int current_p
, last_displayed_p
;
7029 echo_area_buffer
[0] = Qnil
;
7030 message_cleared_p
= 1;
7033 if (last_displayed_p
)
7034 echo_area_buffer
[1] = Qnil
;
7036 message_buf_print
= 0;
7039 /* Clear garbaged frames.
7041 This function is used where the old redisplay called
7042 redraw_garbaged_frames which in turn called redraw_frame which in
7043 turn called clear_frame. The call to clear_frame was a source of
7044 flickering. I believe a clear_frame is not necessary. It should
7045 suffice in the new redisplay to invalidate all current matrices,
7046 and ensure a complete redisplay of all windows. */
7049 clear_garbaged_frames ()
7053 Lisp_Object tail
, frame
;
7055 FOR_EACH_FRAME (tail
, frame
)
7057 struct frame
*f
= XFRAME (frame
);
7059 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7062 Fredraw_frame (frame
);
7063 clear_current_matrices (f
);
7070 ++windows_or_buffers_changed
;
7075 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7076 is non-zero update selected_frame. Value is non-zero if the
7077 mini-windows height has been changed. */
7080 echo_area_display (update_frame_p
)
7083 Lisp_Object mini_window
;
7086 int window_height_changed_p
= 0;
7087 struct frame
*sf
= SELECTED_FRAME ();
7089 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7090 w
= XWINDOW (mini_window
);
7091 f
= XFRAME (WINDOW_FRAME (w
));
7093 /* Don't display if frame is invisible or not yet initialized. */
7094 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7097 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7099 #ifdef HAVE_WINDOW_SYSTEM
7100 /* When Emacs starts, selected_frame may be a visible terminal
7101 frame, even if we run under a window system. If we let this
7102 through, a message would be displayed on the terminal. */
7103 if (EQ (selected_frame
, Vterminal_frame
)
7104 && !NILP (Vwindow_system
))
7106 #endif /* HAVE_WINDOW_SYSTEM */
7109 /* Redraw garbaged frames. */
7111 clear_garbaged_frames ();
7113 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7115 echo_area_window
= mini_window
;
7116 window_height_changed_p
= display_echo_area (w
);
7117 w
->must_be_updated_p
= 1;
7119 /* Update the display, unless called from redisplay_internal.
7120 Also don't update the screen during redisplay itself. The
7121 update will happen at the end of redisplay, and an update
7122 here could cause confusion. */
7123 if (update_frame_p
&& !redisplaying_p
)
7127 /* If the display update has been interrupted by pending
7128 input, update mode lines in the frame. Due to the
7129 pending input, it might have been that redisplay hasn't
7130 been called, so that mode lines above the echo area are
7131 garbaged. This looks odd, so we prevent it here. */
7132 if (!display_completed
)
7133 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7135 if (window_height_changed_p
7136 /* Don't do this if Emacs is shutting down. Redisplay
7137 needs to run hooks. */
7138 && !NILP (Vrun_hooks
))
7140 /* Must update other windows. Likewise as in other
7141 cases, don't let this update be interrupted by
7143 int count
= BINDING_STACK_SIZE ();
7144 specbind (Qredisplay_dont_pause
, Qt
);
7145 windows_or_buffers_changed
= 1;
7146 redisplay_internal (0);
7147 unbind_to (count
, Qnil
);
7149 else if (FRAME_WINDOW_P (f
) && n
== 0)
7151 /* Window configuration is the same as before.
7152 Can do with a display update of the echo area,
7153 unless we displayed some mode lines. */
7154 update_single_window (w
, 1);
7155 rif
->flush_display (f
);
7158 update_frame (f
, 1, 1);
7160 /* If cursor is in the echo area, make sure that the next
7161 redisplay displays the minibuffer, so that the cursor will
7162 be replaced with what the minibuffer wants. */
7163 if (cursor_in_echo_area
)
7164 ++windows_or_buffers_changed
;
7167 else if (!EQ (mini_window
, selected_window
))
7168 windows_or_buffers_changed
++;
7170 /* Last displayed message is now the current message. */
7171 echo_area_buffer
[1] = echo_area_buffer
[0];
7173 /* Prevent redisplay optimization in redisplay_internal by resetting
7174 this_line_start_pos. This is done because the mini-buffer now
7175 displays the message instead of its buffer text. */
7176 if (EQ (mini_window
, selected_window
))
7177 CHARPOS (this_line_start_pos
) = 0;
7179 return window_height_changed_p
;
7184 /***********************************************************************
7186 ***********************************************************************/
7189 #ifdef HAVE_WINDOW_SYSTEM
7191 /* A buffer for constructing frame titles in it; allocated from the
7192 heap in init_xdisp and resized as needed in store_frame_title_char. */
7194 static char *frame_title_buf
;
7196 /* The buffer's end, and a current output position in it. */
7198 static char *frame_title_buf_end
;
7199 static char *frame_title_ptr
;
7202 /* Store a single character C for the frame title in frame_title_buf.
7203 Re-allocate frame_title_buf if necessary. */
7206 store_frame_title_char (c
)
7209 /* If output position has reached the end of the allocated buffer,
7210 double the buffer's size. */
7211 if (frame_title_ptr
== frame_title_buf_end
)
7213 int len
= frame_title_ptr
- frame_title_buf
;
7214 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7215 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7216 frame_title_buf_end
= frame_title_buf
+ new_size
;
7217 frame_title_ptr
= frame_title_buf
+ len
;
7220 *frame_title_ptr
++ = c
;
7224 /* Store part of a frame title in frame_title_buf, beginning at
7225 frame_title_ptr. STR is the string to store. Do not copy
7226 characters that yield more columns than PRECISION; PRECISION <= 0
7227 means copy the whole string. Pad with spaces until FIELD_WIDTH
7228 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7229 pad. Called from display_mode_element when it is used to build a
7233 store_frame_title (str
, field_width
, precision
)
7235 int field_width
, precision
;
7240 /* Copy at most PRECISION chars from STR. */
7241 nbytes
= strlen (str
);
7242 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7244 store_frame_title_char (*str
++);
7246 /* Fill up with spaces until FIELD_WIDTH reached. */
7247 while (field_width
> 0
7250 store_frame_title_char (' ');
7258 /* Set the title of FRAME, if it has changed. The title format is
7259 Vicon_title_format if FRAME is iconified, otherwise it is
7260 frame_title_format. */
7263 x_consider_frame_title (frame
)
7266 struct frame
*f
= XFRAME (frame
);
7268 if (FRAME_WINDOW_P (f
)
7269 || FRAME_MINIBUF_ONLY_P (f
)
7270 || f
->explicit_name
)
7272 /* Do we have more than one visible frame on this X display? */
7275 struct buffer
*obuf
;
7279 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7281 Lisp_Object other_frame
= XCAR (tail
);
7282 struct frame
*tf
= XFRAME (other_frame
);
7285 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7286 && !FRAME_MINIBUF_ONLY_P (tf
)
7287 && !EQ (other_frame
, tip_frame
)
7288 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7292 /* Set global variable indicating that multiple frames exist. */
7293 multiple_frames
= CONSP (tail
);
7295 /* Switch to the buffer of selected window of the frame. Set up
7296 frame_title_ptr so that display_mode_element will output into it;
7297 then display the title. */
7298 obuf
= current_buffer
;
7299 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7300 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7301 frame_title_ptr
= frame_title_buf
;
7302 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7303 NULL
, DEFAULT_FACE_ID
);
7304 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
);
7305 len
= frame_title_ptr
- frame_title_buf
;
7306 frame_title_ptr
= NULL
;
7307 set_buffer_internal_1 (obuf
);
7309 /* Set the title only if it's changed. This avoids consing in
7310 the common case where it hasn't. (If it turns out that we've
7311 already wasted too much time by walking through the list with
7312 display_mode_element, then we might need to optimize at a
7313 higher level than this.) */
7314 if (! STRINGP (f
->name
)
7315 || STRING_BYTES (XSTRING (f
->name
)) != len
7316 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7317 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7321 #else /* not HAVE_WINDOW_SYSTEM */
7323 #define frame_title_ptr ((char *)0)
7324 #define store_frame_title(str, mincol, maxcol) 0
7326 #endif /* not HAVE_WINDOW_SYSTEM */
7331 /***********************************************************************
7333 ***********************************************************************/
7336 /* Prepare for redisplay by updating menu-bar item lists when
7337 appropriate. This can call eval. */
7340 prepare_menu_bars ()
7343 struct gcpro gcpro1
, gcpro2
;
7345 Lisp_Object tooltip_frame
;
7347 #ifdef HAVE_WINDOW_SYSTEM
7348 tooltip_frame
= tip_frame
;
7350 tooltip_frame
= Qnil
;
7353 /* Update all frame titles based on their buffer names, etc. We do
7354 this before the menu bars so that the buffer-menu will show the
7355 up-to-date frame titles. */
7356 #ifdef HAVE_WINDOW_SYSTEM
7357 if (windows_or_buffers_changed
|| update_mode_lines
)
7359 Lisp_Object tail
, frame
;
7361 FOR_EACH_FRAME (tail
, frame
)
7364 if (!EQ (frame
, tooltip_frame
)
7365 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7366 x_consider_frame_title (frame
);
7369 #endif /* HAVE_WINDOW_SYSTEM */
7371 /* Update the menu bar item lists, if appropriate. This has to be
7372 done before any actual redisplay or generation of display lines. */
7373 all_windows
= (update_mode_lines
7374 || buffer_shared
> 1
7375 || windows_or_buffers_changed
);
7378 Lisp_Object tail
, frame
;
7379 int count
= BINDING_STACK_SIZE ();
7381 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7383 FOR_EACH_FRAME (tail
, frame
)
7387 /* Ignore tooltip frame. */
7388 if (EQ (frame
, tooltip_frame
))
7391 /* If a window on this frame changed size, report that to
7392 the user and clear the size-change flag. */
7393 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7395 Lisp_Object functions
;
7397 /* Clear flag first in case we get an error below. */
7398 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7399 functions
= Vwindow_size_change_functions
;
7400 GCPRO2 (tail
, functions
);
7402 while (CONSP (functions
))
7404 call1 (XCAR (functions
), frame
);
7405 functions
= XCDR (functions
);
7411 update_menu_bar (f
, 0);
7412 #ifdef HAVE_WINDOW_SYSTEM
7413 update_tool_bar (f
, 0);
7418 unbind_to (count
, Qnil
);
7422 struct frame
*sf
= SELECTED_FRAME ();
7423 update_menu_bar (sf
, 1);
7424 #ifdef HAVE_WINDOW_SYSTEM
7425 update_tool_bar (sf
, 1);
7429 /* Motif needs this. See comment in xmenu.c. Turn it off when
7430 pending_menu_activation is not defined. */
7431 #ifdef USE_X_TOOLKIT
7432 pending_menu_activation
= 0;
7437 /* Update the menu bar item list for frame F. This has to be done
7438 before we start to fill in any display lines, because it can call
7441 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7444 update_menu_bar (f
, save_match_data
)
7446 int save_match_data
;
7449 register struct window
*w
;
7451 /* If called recursively during a menu update, do nothing. This can
7452 happen when, for instance, an activate-menubar-hook causes a
7454 if (inhibit_menubar_update
)
7457 window
= FRAME_SELECTED_WINDOW (f
);
7458 w
= XWINDOW (window
);
7460 if (update_mode_lines
)
7461 w
->update_mode_line
= Qt
;
7463 if (FRAME_WINDOW_P (f
)
7465 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7466 FRAME_EXTERNAL_MENU_BAR (f
)
7468 FRAME_MENU_BAR_LINES (f
) > 0
7470 : FRAME_MENU_BAR_LINES (f
) > 0)
7472 /* If the user has switched buffers or windows, we need to
7473 recompute to reflect the new bindings. But we'll
7474 recompute when update_mode_lines is set too; that means
7475 that people can use force-mode-line-update to request
7476 that the menu bar be recomputed. The adverse effect on
7477 the rest of the redisplay algorithm is about the same as
7478 windows_or_buffers_changed anyway. */
7479 if (windows_or_buffers_changed
7480 || !NILP (w
->update_mode_line
)
7481 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7482 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7483 != !NILP (w
->last_had_star
))
7484 || ((!NILP (Vtransient_mark_mode
)
7485 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7486 != !NILP (w
->region_showing
)))
7488 struct buffer
*prev
= current_buffer
;
7489 int count
= BINDING_STACK_SIZE ();
7491 specbind (Qinhibit_menubar_update
, Qt
);
7493 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7494 if (save_match_data
)
7495 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7496 if (NILP (Voverriding_local_map_menu_flag
))
7498 specbind (Qoverriding_terminal_local_map
, Qnil
);
7499 specbind (Qoverriding_local_map
, Qnil
);
7502 /* Run the Lucid hook. */
7503 safe_run_hooks (Qactivate_menubar_hook
);
7505 /* If it has changed current-menubar from previous value,
7506 really recompute the menu-bar from the value. */
7507 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7508 call0 (Qrecompute_lucid_menubar
);
7510 safe_run_hooks (Qmenu_bar_update_hook
);
7511 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7513 /* Redisplay the menu bar in case we changed it. */
7514 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7515 if (FRAME_WINDOW_P (f
)
7516 #if defined (macintosh)
7517 /* All frames on Mac OS share the same menubar. So only the
7518 selected frame should be allowed to set it. */
7519 && f
== SELECTED_FRAME ()
7522 set_frame_menubar (f
, 0, 0);
7524 /* On a terminal screen, the menu bar is an ordinary screen
7525 line, and this makes it get updated. */
7526 w
->update_mode_line
= Qt
;
7527 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7528 /* In the non-toolkit version, the menu bar is an ordinary screen
7529 line, and this makes it get updated. */
7530 w
->update_mode_line
= Qt
;
7531 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7533 unbind_to (count
, Qnil
);
7534 set_buffer_internal_1 (prev
);
7541 /***********************************************************************
7543 ***********************************************************************/
7545 #ifdef HAVE_WINDOW_SYSTEM
7547 /* Update the tool-bar item list for frame F. This has to be done
7548 before we start to fill in any display lines. Called from
7549 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7550 and restore it here. */
7553 update_tool_bar (f
, save_match_data
)
7555 int save_match_data
;
7557 if (WINDOWP (f
->tool_bar_window
)
7558 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7563 window
= FRAME_SELECTED_WINDOW (f
);
7564 w
= XWINDOW (window
);
7566 /* If the user has switched buffers or windows, we need to
7567 recompute to reflect the new bindings. But we'll
7568 recompute when update_mode_lines is set too; that means
7569 that people can use force-mode-line-update to request
7570 that the menu bar be recomputed. The adverse effect on
7571 the rest of the redisplay algorithm is about the same as
7572 windows_or_buffers_changed anyway. */
7573 if (windows_or_buffers_changed
7574 || !NILP (w
->update_mode_line
)
7575 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7576 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7577 != !NILP (w
->last_had_star
))
7578 || ((!NILP (Vtransient_mark_mode
)
7579 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7580 != !NILP (w
->region_showing
)))
7582 struct buffer
*prev
= current_buffer
;
7583 int count
= BINDING_STACK_SIZE ();
7585 /* Set current_buffer to the buffer of the selected
7586 window of the frame, so that we get the right local
7588 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7590 /* Save match data, if we must. */
7591 if (save_match_data
)
7592 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7594 /* Make sure that we don't accidentally use bogus keymaps. */
7595 if (NILP (Voverriding_local_map_menu_flag
))
7597 specbind (Qoverriding_terminal_local_map
, Qnil
);
7598 specbind (Qoverriding_local_map
, Qnil
);
7601 /* Build desired tool-bar items from keymaps. */
7603 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7605 /* Redisplay the tool-bar in case we changed it. */
7606 w
->update_mode_line
= Qt
;
7608 unbind_to (count
, Qnil
);
7609 set_buffer_internal_1 (prev
);
7615 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7616 F's desired tool-bar contents. F->tool_bar_items must have
7617 been set up previously by calling prepare_menu_bars. */
7620 build_desired_tool_bar_string (f
)
7623 int i
, size
, size_needed
;
7624 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7625 Lisp_Object image
, plist
, props
;
7627 image
= plist
= props
= Qnil
;
7628 GCPRO3 (image
, plist
, props
);
7630 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7631 Otherwise, make a new string. */
7633 /* The size of the string we might be able to reuse. */
7634 size
= (STRINGP (f
->desired_tool_bar_string
)
7635 ? XSTRING (f
->desired_tool_bar_string
)->size
7638 /* We need one space in the string for each image. */
7639 size_needed
= f
->n_tool_bar_items
;
7641 /* Reuse f->desired_tool_bar_string, if possible. */
7642 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7643 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7647 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7648 Fremove_text_properties (make_number (0), make_number (size
),
7649 props
, f
->desired_tool_bar_string
);
7652 /* Put a `display' property on the string for the images to display,
7653 put a `menu_item' property on tool-bar items with a value that
7654 is the index of the item in F's tool-bar item vector. */
7655 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7657 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7659 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7660 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7661 int hmargin
, vmargin
, relief
, idx
, end
;
7662 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7664 /* If image is a vector, choose the image according to the
7666 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7667 if (VECTORP (image
))
7671 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7672 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7675 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7676 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7678 xassert (ASIZE (image
) >= idx
);
7679 image
= AREF (image
, idx
);
7684 /* Ignore invalid image specifications. */
7685 if (!valid_image_p (image
))
7688 /* Display the tool-bar button pressed, or depressed. */
7689 plist
= Fcopy_sequence (XCDR (image
));
7691 /* Compute margin and relief to draw. */
7692 relief
= (tool_bar_button_relief
>= 0
7693 ? tool_bar_button_relief
7694 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7695 hmargin
= vmargin
= relief
;
7697 if (INTEGERP (Vtool_bar_button_margin
)
7698 && XINT (Vtool_bar_button_margin
) > 0)
7700 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7701 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7703 else if (CONSP (Vtool_bar_button_margin
))
7705 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7706 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7707 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7709 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7710 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7711 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7714 if (auto_raise_tool_bar_buttons_p
)
7716 /* Add a `:relief' property to the image spec if the item is
7720 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7727 /* If image is selected, display it pressed, i.e. with a
7728 negative relief. If it's not selected, display it with a
7730 plist
= Fplist_put (plist
, QCrelief
,
7732 ? make_number (-relief
)
7733 : make_number (relief
)));
7738 /* Put a margin around the image. */
7739 if (hmargin
|| vmargin
)
7741 if (hmargin
== vmargin
)
7742 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7744 plist
= Fplist_put (plist
, QCmargin
,
7745 Fcons (make_number (hmargin
),
7746 make_number (vmargin
)));
7749 /* If button is not enabled, and we don't have special images
7750 for the disabled state, make the image appear disabled by
7751 applying an appropriate algorithm to it. */
7752 if (!enabled_p
&& idx
< 0)
7753 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7755 /* Put a `display' text property on the string for the image to
7756 display. Put a `menu-item' property on the string that gives
7757 the start of this item's properties in the tool-bar items
7759 image
= Fcons (Qimage
, plist
);
7760 props
= list4 (Qdisplay
, image
,
7761 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7763 /* Let the last image hide all remaining spaces in the tool bar
7764 string. The string can be longer than needed when we reuse a
7766 if (i
+ 1 == f
->n_tool_bar_items
)
7767 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7770 Fadd_text_properties (make_number (i
), make_number (end
),
7771 props
, f
->desired_tool_bar_string
);
7779 /* Display one line of the tool-bar of frame IT->f. */
7782 display_tool_bar_line (it
)
7785 struct glyph_row
*row
= it
->glyph_row
;
7786 int max_x
= it
->last_visible_x
;
7789 prepare_desired_row (row
);
7790 row
->y
= it
->current_y
;
7792 /* Note that this isn't made use of if the face hasn't a box,
7793 so there's no need to check the face here. */
7794 it
->start_of_box_run_p
= 1;
7796 while (it
->current_x
< max_x
)
7798 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7800 /* Get the next display element. */
7801 if (!get_next_display_element (it
))
7804 /* Produce glyphs. */
7805 x_before
= it
->current_x
;
7806 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7807 PRODUCE_GLYPHS (it
);
7809 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7814 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7816 if (x
+ glyph
->pixel_width
> max_x
)
7818 /* Glyph doesn't fit on line. */
7819 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7825 x
+= glyph
->pixel_width
;
7829 /* Stop at line ends. */
7830 if (ITERATOR_AT_END_OF_LINE_P (it
))
7833 set_iterator_to_next (it
, 1);
7838 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7839 extend_face_to_end_of_line (it
);
7840 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7841 last
->right_box_line_p
= 1;
7842 if (last
== row
->glyphs
[TEXT_AREA
])
7843 last
->left_box_line_p
= 1;
7844 compute_line_metrics (it
);
7846 /* If line is empty, make it occupy the rest of the tool-bar. */
7847 if (!row
->displays_text_p
)
7849 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7850 row
->ascent
= row
->phys_ascent
= 0;
7853 row
->full_width_p
= 1;
7854 row
->continued_p
= 0;
7855 row
->truncated_on_left_p
= 0;
7856 row
->truncated_on_right_p
= 0;
7858 it
->current_x
= it
->hpos
= 0;
7859 it
->current_y
+= row
->height
;
7865 /* Value is the number of screen lines needed to make all tool-bar
7866 items of frame F visible. */
7869 tool_bar_lines_needed (f
)
7872 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7875 /* Initialize an iterator for iteration over
7876 F->desired_tool_bar_string in the tool-bar window of frame F. */
7877 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7878 it
.first_visible_x
= 0;
7879 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7880 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7882 while (!ITERATOR_AT_END_P (&it
))
7884 it
.glyph_row
= w
->desired_matrix
->rows
;
7885 clear_glyph_row (it
.glyph_row
);
7886 display_tool_bar_line (&it
);
7889 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7893 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7895 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7904 frame
= selected_frame
;
7906 CHECK_FRAME (frame
);
7909 if (WINDOWP (f
->tool_bar_window
)
7910 || (w
= XWINDOW (f
->tool_bar_window
),
7911 XFASTINT (w
->height
) > 0))
7913 update_tool_bar (f
, 1);
7914 if (f
->n_tool_bar_items
)
7916 build_desired_tool_bar_string (f
);
7917 nlines
= tool_bar_lines_needed (f
);
7921 return make_number (nlines
);
7925 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7926 height should be changed. */
7929 redisplay_tool_bar (f
)
7934 struct glyph_row
*row
;
7935 int change_height_p
= 0;
7937 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7938 do anything. This means you must start with tool-bar-lines
7939 non-zero to get the auto-sizing effect. Or in other words, you
7940 can turn off tool-bars by specifying tool-bar-lines zero. */
7941 if (!WINDOWP (f
->tool_bar_window
)
7942 || (w
= XWINDOW (f
->tool_bar_window
),
7943 XFASTINT (w
->height
) == 0))
7946 /* Set up an iterator for the tool-bar window. */
7947 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7948 it
.first_visible_x
= 0;
7949 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7952 /* Build a string that represents the contents of the tool-bar. */
7953 build_desired_tool_bar_string (f
);
7954 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7956 /* Display as many lines as needed to display all tool-bar items. */
7957 while (it
.current_y
< it
.last_visible_y
)
7958 display_tool_bar_line (&it
);
7960 /* It doesn't make much sense to try scrolling in the tool-bar
7961 window, so don't do it. */
7962 w
->desired_matrix
->no_scrolling_p
= 1;
7963 w
->must_be_updated_p
= 1;
7965 if (auto_resize_tool_bars_p
)
7969 /* If we couldn't display everything, change the tool-bar's
7971 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7972 change_height_p
= 1;
7974 /* If there are blank lines at the end, except for a partially
7975 visible blank line at the end that is smaller than
7976 CANON_Y_UNIT, change the tool-bar's height. */
7977 row
= it
.glyph_row
- 1;
7978 if (!row
->displays_text_p
7979 && row
->height
>= CANON_Y_UNIT (f
))
7980 change_height_p
= 1;
7982 /* If row displays tool-bar items, but is partially visible,
7983 change the tool-bar's height. */
7984 if (row
->displays_text_p
7985 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7986 change_height_p
= 1;
7988 /* Resize windows as needed by changing the `tool-bar-lines'
7991 && (nlines
= tool_bar_lines_needed (f
),
7992 nlines
!= XFASTINT (w
->height
)))
7994 extern Lisp_Object Qtool_bar_lines
;
7996 int old_height
= XFASTINT (w
->height
);
7998 XSETFRAME (frame
, f
);
7999 clear_glyph_matrix (w
->desired_matrix
);
8000 Fmodify_frame_parameters (frame
,
8001 Fcons (Fcons (Qtool_bar_lines
,
8002 make_number (nlines
)),
8004 if (XFASTINT (w
->height
) != old_height
)
8005 fonts_changed_p
= 1;
8009 return change_height_p
;
8013 /* Get information about the tool-bar item which is displayed in GLYPH
8014 on frame F. Return in *PROP_IDX the index where tool-bar item
8015 properties start in F->tool_bar_items. Value is zero if
8016 GLYPH doesn't display a tool-bar item. */
8019 tool_bar_item_info (f
, glyph
, prop_idx
)
8021 struct glyph
*glyph
;
8028 /* This function can be called asynchronously, which means we must
8029 exclude any possibility that Fget_text_property signals an
8031 charpos
= min (XSTRING (f
->current_tool_bar_string
)->size
, glyph
->charpos
);
8032 charpos
= max (0, charpos
);
8034 /* Get the text property `menu-item' at pos. The value of that
8035 property is the start index of this item's properties in
8036 F->tool_bar_items. */
8037 prop
= Fget_text_property (make_number (charpos
),
8038 Qmenu_item
, f
->current_tool_bar_string
);
8039 if (INTEGERP (prop
))
8041 *prop_idx
= XINT (prop
);
8050 #endif /* HAVE_WINDOW_SYSTEM */
8054 /************************************************************************
8055 Horizontal scrolling
8056 ************************************************************************/
8058 static int hscroll_window_tree
P_ ((Lisp_Object
));
8059 static int hscroll_windows
P_ ((Lisp_Object
));
8061 /* For all leaf windows in the window tree rooted at WINDOW, set their
8062 hscroll value so that PT is (i) visible in the window, and (ii) so
8063 that it is not within a certain margin at the window's left and
8064 right border. Value is non-zero if any window's hscroll has been
8068 hscroll_window_tree (window
)
8071 int hscrolled_p
= 0;
8072 int hscroll_relative_p
= FLOATP (Vautomatic_hscroll_step
);
8073 int hscroll_step_abs
= 0;
8074 double hscroll_step_rel
= 0;
8076 if (hscroll_relative_p
)
8078 hscroll_step_rel
= XFLOAT_DATA (Vautomatic_hscroll_step
);
8079 if (hscroll_step_rel
< 0)
8081 hscroll_relative_p
= 0;
8082 hscroll_step_abs
= 0;
8085 else if (INTEGERP (Vautomatic_hscroll_step
))
8087 hscroll_step_abs
= XINT (Vautomatic_hscroll_step
);
8088 if (hscroll_step_abs
< 0)
8089 hscroll_step_abs
= 0;
8092 hscroll_step_abs
= 0;
8094 while (WINDOWP (window
))
8096 struct window
*w
= XWINDOW (window
);
8098 if (WINDOWP (w
->hchild
))
8099 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8100 else if (WINDOWP (w
->vchild
))
8101 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8102 else if (w
->cursor
.vpos
>= 0)
8104 int hscroll_margin
, text_area_x
, text_area_y
;
8105 int text_area_width
, text_area_height
;
8106 struct glyph_row
*current_cursor_row
8107 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8108 struct glyph_row
*desired_cursor_row
8109 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8110 struct glyph_row
*cursor_row
8111 = (desired_cursor_row
->enabled_p
8112 ? desired_cursor_row
8113 : current_cursor_row
);
8115 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8116 &text_area_width
, &text_area_height
);
8118 /* Scroll when cursor is inside this scroll margin. */
8120 = automatic_hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8122 if ((XFASTINT (w
->hscroll
)
8123 && w
->cursor
.x
<= hscroll_margin
)
8124 || (cursor_row
->enabled_p
8125 && cursor_row
->truncated_on_right_p
8126 && (w
->cursor
.x
>= text_area_width
- hscroll_margin
)))
8130 struct buffer
*saved_current_buffer
;
8134 /* Find point in a display of infinite width. */
8135 saved_current_buffer
= current_buffer
;
8136 current_buffer
= XBUFFER (w
->buffer
);
8138 if (w
== XWINDOW (selected_window
))
8139 pt
= BUF_PT (current_buffer
);
8142 pt
= marker_position (w
->pointm
);
8143 pt
= max (BEGV
, pt
);
8147 /* Move iterator to pt starting at cursor_row->start in
8148 a line with infinite width. */
8149 init_to_row_start (&it
, w
, cursor_row
);
8150 it
.last_visible_x
= INFINITY
;
8151 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8152 current_buffer
= saved_current_buffer
;
8154 /* Position cursor in window. */
8155 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8156 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8157 / CANON_X_UNIT (it
.f
);
8158 else if (w
->cursor
.x
>= text_area_width
- hscroll_margin
)
8160 if (hscroll_relative_p
)
8161 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8164 wanted_x
= text_area_width
8165 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8168 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8172 if (hscroll_relative_p
)
8173 wanted_x
= text_area_width
* hscroll_step_rel
8176 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8179 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8181 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8183 /* Don't call Fset_window_hscroll if value hasn't
8184 changed because it will prevent redisplay
8186 if (XFASTINT (w
->hscroll
) != hscroll
)
8188 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8189 w
->hscroll
= make_number (hscroll
);
8198 /* Value is non-zero if hscroll of any leaf window has been changed. */
8203 /* Set hscroll so that cursor is visible and not inside horizontal
8204 scroll margins for all windows in the tree rooted at WINDOW. See
8205 also hscroll_window_tree above. Value is non-zero if any window's
8206 hscroll has been changed. If it has, desired matrices on the frame
8207 of WINDOW are cleared. */
8210 hscroll_windows (window
)
8215 if (automatic_hscrolling_p
)
8217 hscrolled_p
= hscroll_window_tree (window
);
8219 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8228 /************************************************************************
8230 ************************************************************************/
8232 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8233 to a non-zero value. This is sometimes handy to have in a debugger
8238 /* First and last unchanged row for try_window_id. */
8240 int debug_first_unchanged_at_end_vpos
;
8241 int debug_last_unchanged_at_beg_vpos
;
8243 /* Delta vpos and y. */
8245 int debug_dvpos
, debug_dy
;
8247 /* Delta in characters and bytes for try_window_id. */
8249 int debug_delta
, debug_delta_bytes
;
8251 /* Values of window_end_pos and window_end_vpos at the end of
8254 int debug_end_pos
, debug_end_vpos
;
8256 /* Append a string to W->desired_matrix->method. FMT is a printf
8257 format string. A1...A9 are a supplement for a variable-length
8258 argument list. If trace_redisplay_p is non-zero also printf the
8259 resulting string to stderr. */
8262 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8265 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8268 char *method
= w
->desired_matrix
->method
;
8269 int len
= strlen (method
);
8270 int size
= sizeof w
->desired_matrix
->method
;
8271 int remaining
= size
- len
- 1;
8273 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8274 if (len
&& remaining
)
8280 strncpy (method
+ len
, buffer
, remaining
);
8282 if (trace_redisplay_p
)
8283 fprintf (stderr
, "%p (%s): %s\n",
8285 ((BUFFERP (w
->buffer
)
8286 && STRINGP (XBUFFER (w
->buffer
)->name
))
8287 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8292 #endif /* GLYPH_DEBUG */
8295 /* This counter is used to clear the face cache every once in a while
8296 in redisplay_internal. It is incremented for each redisplay.
8297 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8300 #define CLEAR_FACE_CACHE_COUNT 500
8301 static int clear_face_cache_count
;
8303 /* Record the previous terminal frame we displayed. */
8305 static struct frame
*previous_terminal_frame
;
8307 /* Non-zero while redisplay_internal is in progress. */
8312 /* Value is non-zero if all changes in window W, which displays
8313 current_buffer, are in the text between START and END. START is a
8314 buffer position, END is given as a distance from Z. Used in
8315 redisplay_internal for display optimization. */
8318 text_outside_line_unchanged_p (w
, start
, end
)
8322 int unchanged_p
= 1;
8324 /* If text or overlays have changed, see where. */
8325 if (XFASTINT (w
->last_modified
) < MODIFF
8326 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8328 /* Gap in the line? */
8329 if (GPT
< start
|| Z
- GPT
< end
)
8332 /* Changes start in front of the line, or end after it? */
8334 && (BEG_UNCHANGED
< start
- 1
8335 || END_UNCHANGED
< end
))
8338 /* If selective display, can't optimize if changes start at the
8339 beginning of the line. */
8341 && INTEGERP (current_buffer
->selective_display
)
8342 && XINT (current_buffer
->selective_display
) > 0
8343 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8346 /* If there are overlays at the start or end of the line, these
8347 may have overlay strings with newlines in them. A change at
8348 START, for instance, may actually concern the display of such
8349 overlay strings as well, and they are displayed on different
8350 lines. So, quickly rule out this case. (For the future, it
8351 might be desirable to implement something more telling than
8352 just BEG/END_UNCHANGED.) */
8355 if (BEG
+ BEG_UNCHANGED
== start
8356 && overlay_touches_p (start
))
8358 if (END_UNCHANGED
== end
8359 && overlay_touches_p (Z
- end
))
8368 /* Do a frame update, taking possible shortcuts into account. This is
8369 the main external entry point for redisplay.
8371 If the last redisplay displayed an echo area message and that message
8372 is no longer requested, we clear the echo area or bring back the
8373 mini-buffer if that is in use. */
8378 redisplay_internal (0);
8382 /* Return 1 if point moved out of or into a composition. Otherwise
8383 return 0. PREV_BUF and PREV_PT are the last point buffer and
8384 position. BUF and PT are the current point buffer and position. */
8387 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8388 struct buffer
*prev_buf
, *buf
;
8395 XSETBUFFER (buffer
, buf
);
8396 /* Check a composition at the last point if point moved within the
8398 if (prev_buf
== buf
)
8401 /* Point didn't move. */
8404 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8405 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8406 && COMPOSITION_VALID_P (start
, end
, prop
)
8407 && start
< prev_pt
&& end
> prev_pt
)
8408 /* The last point was within the composition. Return 1 iff
8409 point moved out of the composition. */
8410 return (pt
<= start
|| pt
>= end
);
8413 /* Check a composition at the current point. */
8414 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8415 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8416 && COMPOSITION_VALID_P (start
, end
, prop
)
8417 && start
< pt
&& end
> pt
);
8421 /* Reconsider the setting of B->clip_changed which is displayed
8425 reconsider_clip_changes (w
, b
)
8429 if (b
->prevent_redisplay_optimizations_p
)
8430 b
->clip_changed
= 1;
8431 else if (b
->clip_changed
8432 && !NILP (w
->window_end_valid
)
8433 && w
->current_matrix
->buffer
== b
8434 && w
->current_matrix
->zv
== BUF_ZV (b
)
8435 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8436 b
->clip_changed
= 0;
8438 /* If display wasn't paused, and W is not a tool bar window, see if
8439 point has been moved into or out of a composition. In that case,
8440 we set b->clip_changed to 1 to force updating the screen. If
8441 b->clip_changed has already been set to 1, we can skip this
8443 if (!b
->clip_changed
8444 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8448 if (w
== XWINDOW (selected_window
))
8449 pt
= BUF_PT (current_buffer
);
8451 pt
= marker_position (w
->pointm
);
8453 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8454 || pt
!= XINT (w
->last_point
))
8455 && check_point_in_composition (w
->current_matrix
->buffer
,
8456 XINT (w
->last_point
),
8457 XBUFFER (w
->buffer
), pt
))
8458 b
->clip_changed
= 1;
8463 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8464 response to any user action; therefore, we should preserve the echo
8465 area. (Actually, our caller does that job.) Perhaps in the future
8466 avoid recentering windows if it is not necessary; currently that
8467 causes some problems. */
8470 redisplay_internal (preserve_echo_area
)
8471 int preserve_echo_area
;
8473 struct window
*w
= XWINDOW (selected_window
);
8474 struct frame
*f
= XFRAME (w
->frame
);
8476 int must_finish
= 0;
8477 struct text_pos tlbufpos
, tlendpos
;
8478 int number_of_visible_frames
;
8480 struct frame
*sf
= SELECTED_FRAME ();
8482 /* Non-zero means redisplay has to consider all windows on all
8483 frames. Zero means, only selected_window is considered. */
8484 int consider_all_windows_p
;
8486 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8488 /* No redisplay if running in batch mode or frame is not yet fully
8489 initialized, or redisplay is explicitly turned off by setting
8490 Vinhibit_redisplay. */
8492 || !NILP (Vinhibit_redisplay
)
8493 || !f
->glyphs_initialized_p
)
8496 /* The flag redisplay_performed_directly_p is set by
8497 direct_output_for_insert when it already did the whole screen
8498 update necessary. */
8499 if (redisplay_performed_directly_p
)
8501 redisplay_performed_directly_p
= 0;
8502 if (!hscroll_windows (selected_window
))
8506 #ifdef USE_X_TOOLKIT
8507 if (popup_activated ())
8511 /* I don't think this happens but let's be paranoid. */
8515 /* Record a function that resets redisplaying_p to its old value
8516 when we leave this function. */
8517 count
= BINDING_STACK_SIZE ();
8518 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8523 reconsider_clip_changes (w
, current_buffer
);
8525 /* If new fonts have been loaded that make a glyph matrix adjustment
8526 necessary, do it. */
8527 if (fonts_changed_p
)
8529 adjust_glyphs (NULL
);
8530 ++windows_or_buffers_changed
;
8531 fonts_changed_p
= 0;
8534 /* If face_change_count is non-zero, init_iterator will free all
8535 realized faces, which includes the faces referenced from current
8536 matrices. So, we can't reuse current matrices in this case. */
8537 if (face_change_count
)
8538 ++windows_or_buffers_changed
;
8540 if (! FRAME_WINDOW_P (sf
)
8541 && previous_terminal_frame
!= sf
)
8543 /* Since frames on an ASCII terminal share the same display
8544 area, displaying a different frame means redisplay the whole
8546 windows_or_buffers_changed
++;
8547 SET_FRAME_GARBAGED (sf
);
8548 XSETFRAME (Vterminal_frame
, sf
);
8550 previous_terminal_frame
= sf
;
8552 /* Set the visible flags for all frames. Do this before checking
8553 for resized or garbaged frames; they want to know if their frames
8554 are visible. See the comment in frame.h for
8555 FRAME_SAMPLE_VISIBILITY. */
8557 Lisp_Object tail
, frame
;
8559 number_of_visible_frames
= 0;
8561 FOR_EACH_FRAME (tail
, frame
)
8563 struct frame
*f
= XFRAME (frame
);
8565 FRAME_SAMPLE_VISIBILITY (f
);
8566 if (FRAME_VISIBLE_P (f
))
8567 ++number_of_visible_frames
;
8568 clear_desired_matrices (f
);
8572 /* Notice any pending interrupt request to change frame size. */
8573 do_pending_window_change (1);
8575 /* Clear frames marked as garbaged. */
8577 clear_garbaged_frames ();
8579 /* Build menubar and tool-bar items. */
8580 prepare_menu_bars ();
8582 if (windows_or_buffers_changed
)
8583 update_mode_lines
++;
8585 /* Detect case that we need to write or remove a star in the mode line. */
8586 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8588 w
->update_mode_line
= Qt
;
8589 if (buffer_shared
> 1)
8590 update_mode_lines
++;
8593 /* If %c is in the mode line, update it if needed. */
8594 if (!NILP (w
->column_number_displayed
)
8595 /* This alternative quickly identifies a common case
8596 where no change is needed. */
8597 && !(PT
== XFASTINT (w
->last_point
)
8598 && XFASTINT (w
->last_modified
) >= MODIFF
8599 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8600 && XFASTINT (w
->column_number_displayed
) != current_column ())
8601 w
->update_mode_line
= Qt
;
8603 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8605 /* The variable buffer_shared is set in redisplay_window and
8606 indicates that we redisplay a buffer in different windows. See
8608 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8610 /* If specs for an arrow have changed, do thorough redisplay
8611 to ensure we remove any arrow that should no longer exist. */
8612 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8613 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8614 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8616 /* Normally the message* functions will have already displayed and
8617 updated the echo area, but the frame may have been trashed, or
8618 the update may have been preempted, so display the echo area
8619 again here. Checking message_cleared_p captures the case that
8620 the echo area should be cleared. */
8621 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8622 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8623 || (message_cleared_p
8624 && minibuf_level
== 0
8625 /* If the mini-window is currently selected, this means the
8626 echo-area doesn't show through. */
8627 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8629 int window_height_changed_p
= echo_area_display (0);
8632 /* If we don't display the current message, don't clear the
8633 message_cleared_p flag, because, if we did, we wouldn't clear
8634 the echo area in the next redisplay which doesn't preserve
8636 if (!display_last_displayed_message_p
)
8637 message_cleared_p
= 0;
8639 if (fonts_changed_p
)
8641 else if (window_height_changed_p
)
8643 consider_all_windows_p
= 1;
8644 ++update_mode_lines
;
8645 ++windows_or_buffers_changed
;
8647 /* If window configuration was changed, frames may have been
8648 marked garbaged. Clear them or we will experience
8649 surprises wrt scrolling. */
8651 clear_garbaged_frames ();
8654 else if (EQ (selected_window
, minibuf_window
)
8655 && (current_buffer
->clip_changed
8656 || XFASTINT (w
->last_modified
) < MODIFF
8657 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8658 && resize_mini_window (w
, 0))
8660 /* Resized active mini-window to fit the size of what it is
8661 showing if its contents might have changed. */
8663 consider_all_windows_p
= 1;
8664 ++windows_or_buffers_changed
;
8665 ++update_mode_lines
;
8667 /* If window configuration was changed, frames may have been
8668 marked garbaged. Clear them or we will experience
8669 surprises wrt scrolling. */
8671 clear_garbaged_frames ();
8675 /* If showing the region, and mark has changed, we must redisplay
8676 the whole window. The assignment to this_line_start_pos prevents
8677 the optimization directly below this if-statement. */
8678 if (((!NILP (Vtransient_mark_mode
)
8679 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8680 != !NILP (w
->region_showing
))
8681 || (!NILP (w
->region_showing
)
8682 && !EQ (w
->region_showing
,
8683 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8684 CHARPOS (this_line_start_pos
) = 0;
8686 /* Optimize the case that only the line containing the cursor in the
8687 selected window has changed. Variables starting with this_ are
8688 set in display_line and record information about the line
8689 containing the cursor. */
8690 tlbufpos
= this_line_start_pos
;
8691 tlendpos
= this_line_end_pos
;
8692 if (!consider_all_windows_p
8693 && CHARPOS (tlbufpos
) > 0
8694 && NILP (w
->update_mode_line
)
8695 && !current_buffer
->clip_changed
8696 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8697 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8698 /* Make sure recorded data applies to current buffer, etc. */
8699 && this_line_buffer
== current_buffer
8700 && current_buffer
== XBUFFER (w
->buffer
)
8701 && NILP (w
->force_start
)
8702 /* Point must be on the line that we have info recorded about. */
8703 && PT
>= CHARPOS (tlbufpos
)
8704 && PT
<= Z
- CHARPOS (tlendpos
)
8705 /* All text outside that line, including its final newline,
8706 must be unchanged */
8707 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8708 CHARPOS (tlendpos
)))
8710 if (CHARPOS (tlbufpos
) > BEGV
8711 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8712 && (CHARPOS (tlbufpos
) == ZV
8713 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8714 /* Former continuation line has disappeared by becoming empty */
8716 else if (XFASTINT (w
->last_modified
) < MODIFF
8717 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8718 || MINI_WINDOW_P (w
))
8720 /* We have to handle the case of continuation around a
8721 wide-column character (See the comment in indent.c around
8724 For instance, in the following case:
8726 -------- Insert --------
8727 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8728 J_I_ ==> J_I_ `^^' are cursors.
8732 As we have to redraw the line above, we should goto cancel. */
8735 int line_height_before
= this_line_pixel_height
;
8737 /* Note that start_display will handle the case that the
8738 line starting at tlbufpos is a continuation lines. */
8739 start_display (&it
, w
, tlbufpos
);
8741 /* Implementation note: It this still necessary? */
8742 if (it
.current_x
!= this_line_start_x
)
8745 TRACE ((stderr
, "trying display optimization 1\n"));
8746 w
->cursor
.vpos
= -1;
8747 overlay_arrow_seen
= 0;
8748 it
.vpos
= this_line_vpos
;
8749 it
.current_y
= this_line_y
;
8750 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8753 /* If line contains point, is not continued,
8754 and ends at same distance from eob as before, we win */
8755 if (w
->cursor
.vpos
>= 0
8756 /* Line is not continued, otherwise this_line_start_pos
8757 would have been set to 0 in display_line. */
8758 && CHARPOS (this_line_start_pos
)
8759 /* Line ends as before. */
8760 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8761 /* Line has same height as before. Otherwise other lines
8762 would have to be shifted up or down. */
8763 && this_line_pixel_height
== line_height_before
)
8765 /* If this is not the window's last line, we must adjust
8766 the charstarts of the lines below. */
8767 if (it
.current_y
< it
.last_visible_y
)
8769 struct glyph_row
*row
8770 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8771 int delta
, delta_bytes
;
8773 if (Z
- CHARPOS (tlendpos
) == ZV
)
8775 /* This line ends at end of (accessible part of)
8776 buffer. There is no newline to count. */
8778 - CHARPOS (tlendpos
)
8779 - MATRIX_ROW_START_CHARPOS (row
));
8780 delta_bytes
= (Z_BYTE
8781 - BYTEPOS (tlendpos
)
8782 - MATRIX_ROW_START_BYTEPOS (row
));
8786 /* This line ends in a newline. Must take
8787 account of the newline and the rest of the
8788 text that follows. */
8790 - CHARPOS (tlendpos
)
8791 - MATRIX_ROW_START_CHARPOS (row
));
8792 delta_bytes
= (Z_BYTE
8793 - BYTEPOS (tlendpos
)
8794 - MATRIX_ROW_START_BYTEPOS (row
));
8797 increment_matrix_positions (w
->current_matrix
,
8799 w
->current_matrix
->nrows
,
8800 delta
, delta_bytes
);
8803 /* If this row displays text now but previously didn't,
8804 or vice versa, w->window_end_vpos may have to be
8806 if ((it
.glyph_row
- 1)->displays_text_p
)
8808 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8809 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8811 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8812 && this_line_vpos
> 0)
8813 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8814 w
->window_end_valid
= Qnil
;
8816 /* Update hint: No need to try to scroll in update_window. */
8817 w
->desired_matrix
->no_scrolling_p
= 1;
8820 *w
->desired_matrix
->method
= 0;
8821 debug_method_add (w
, "optimization 1");
8828 else if (/* Cursor position hasn't changed. */
8829 PT
== XFASTINT (w
->last_point
)
8830 /* Make sure the cursor was last displayed
8831 in this window. Otherwise we have to reposition it. */
8832 && 0 <= w
->cursor
.vpos
8833 && XINT (w
->height
) > w
->cursor
.vpos
)
8837 do_pending_window_change (1);
8839 /* We used to always goto end_of_redisplay here, but this
8840 isn't enough if we have a blinking cursor. */
8841 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8842 goto end_of_redisplay
;
8846 /* If highlighting the region, or if the cursor is in the echo area,
8847 then we can't just move the cursor. */
8848 else if (! (!NILP (Vtransient_mark_mode
)
8849 && !NILP (current_buffer
->mark_active
))
8850 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8851 || highlight_nonselected_windows
)
8852 && NILP (w
->region_showing
)
8853 && NILP (Vshow_trailing_whitespace
)
8854 && !cursor_in_echo_area
)
8857 struct glyph_row
*row
;
8859 /* Skip from tlbufpos to PT and see where it is. Note that
8860 PT may be in invisible text. If so, we will end at the
8861 next visible position. */
8862 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8863 NULL
, DEFAULT_FACE_ID
);
8864 it
.current_x
= this_line_start_x
;
8865 it
.current_y
= this_line_y
;
8866 it
.vpos
= this_line_vpos
;
8868 /* The call to move_it_to stops in front of PT, but
8869 moves over before-strings. */
8870 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8872 if (it
.vpos
== this_line_vpos
8873 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8876 xassert (this_line_vpos
== it
.vpos
);
8877 xassert (this_line_y
== it
.current_y
);
8878 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8880 *w
->desired_matrix
->method
= 0;
8881 debug_method_add (w
, "optimization 3");
8890 /* Text changed drastically or point moved off of line. */
8891 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8894 CHARPOS (this_line_start_pos
) = 0;
8895 consider_all_windows_p
|= buffer_shared
> 1;
8896 ++clear_face_cache_count
;
8899 /* Build desired matrices, and update the display. If
8900 consider_all_windows_p is non-zero, do it for all windows on all
8901 frames. Otherwise do it for selected_window, only. */
8903 if (consider_all_windows_p
)
8905 Lisp_Object tail
, frame
;
8906 int i
, n
= 0, size
= 50;
8907 struct frame
**updated
8908 = (struct frame
**) alloca (size
* sizeof *updated
);
8910 /* Clear the face cache eventually. */
8911 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8913 clear_face_cache (0);
8914 clear_face_cache_count
= 0;
8917 /* Recompute # windows showing selected buffer. This will be
8918 incremented each time such a window is displayed. */
8921 FOR_EACH_FRAME (tail
, frame
)
8923 struct frame
*f
= XFRAME (frame
);
8925 if (FRAME_WINDOW_P (f
) || f
== sf
)
8927 if (clear_face_cache_count
% 50 == 0
8928 && FRAME_WINDOW_P (f
))
8929 clear_image_cache (f
, 0);
8931 /* Mark all the scroll bars to be removed; we'll redeem
8932 the ones we want when we redisplay their windows. */
8933 if (condemn_scroll_bars_hook
)
8934 condemn_scroll_bars_hook (f
);
8936 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8937 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8939 /* Any scroll bars which redisplay_windows should have
8940 nuked should now go away. */
8941 if (judge_scroll_bars_hook
)
8942 judge_scroll_bars_hook (f
);
8944 /* If fonts changed, display again. */
8945 if (fonts_changed_p
)
8948 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8950 /* See if we have to hscroll. */
8951 if (hscroll_windows (f
->root_window
))
8954 /* Prevent various kinds of signals during display
8955 update. stdio is not robust about handling
8956 signals, which can cause an apparent I/O
8958 if (interrupt_input
)
8962 /* Update the display. */
8963 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8964 pause
|= update_frame (f
, 0, 0);
8970 int nbytes
= size
* sizeof *updated
;
8971 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8972 bcopy (updated
, p
, nbytes
);
8981 /* Do the mark_window_display_accurate after all windows have
8982 been redisplayed because this call resets flags in buffers
8983 which are needed for proper redisplay. */
8984 for (i
= 0; i
< n
; ++i
)
8986 struct frame
*f
= updated
[i
];
8987 mark_window_display_accurate (f
->root_window
, 1);
8988 if (frame_up_to_date_hook
)
8989 frame_up_to_date_hook (f
);
8992 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8994 Lisp_Object mini_window
;
8995 struct frame
*mini_frame
;
8997 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8998 internal_condition_case_1 (redisplay_window_1
, selected_window
, Qerror
,
8999 redisplay_window_error
);
9001 /* Compare desired and current matrices, perform output. */
9004 /* If fonts changed, display again. */
9005 if (fonts_changed_p
)
9008 /* Prevent various kinds of signals during display update.
9009 stdio is not robust about handling signals,
9010 which can cause an apparent I/O error. */
9011 if (interrupt_input
)
9015 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9017 if (hscroll_windows (selected_window
))
9020 XWINDOW (selected_window
)->must_be_updated_p
= 1;
9021 pause
= update_frame (sf
, 0, 0);
9024 /* We may have called echo_area_display at the top of this
9025 function. If the echo area is on another frame, that may
9026 have put text on a frame other than the selected one, so the
9027 above call to update_frame would not have caught it. Catch
9029 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9030 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9032 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
9034 XWINDOW (mini_window
)->must_be_updated_p
= 1;
9035 pause
|= update_frame (mini_frame
, 0, 0);
9036 if (!pause
&& hscroll_windows (mini_window
))
9041 /* If display was paused because of pending input, make sure we do a
9042 thorough update the next time. */
9045 /* Prevent the optimization at the beginning of
9046 redisplay_internal that tries a single-line update of the
9047 line containing the cursor in the selected window. */
9048 CHARPOS (this_line_start_pos
) = 0;
9050 /* Let the overlay arrow be updated the next time. */
9051 if (!NILP (last_arrow_position
))
9053 last_arrow_position
= Qt
;
9054 last_arrow_string
= Qt
;
9057 /* If we pause after scrolling, some rows in the current
9058 matrices of some windows are not valid. */
9059 if (!WINDOW_FULL_WIDTH_P (w
)
9060 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9061 update_mode_lines
= 1;
9065 if (!consider_all_windows_p
)
9067 /* This has already been done above if
9068 consider_all_windows_p is set. */
9069 mark_window_display_accurate_1 (w
, 1);
9071 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9072 last_arrow_string
= Voverlay_arrow_string
;
9074 if (frame_up_to_date_hook
!= 0)
9075 frame_up_to_date_hook (sf
);
9078 update_mode_lines
= 0;
9079 windows_or_buffers_changed
= 0;
9082 /* Start SIGIO interrupts coming again. Having them off during the
9083 code above makes it less likely one will discard output, but not
9084 impossible, since there might be stuff in the system buffer here.
9085 But it is much hairier to try to do anything about that. */
9086 if (interrupt_input
)
9090 /* If a frame has become visible which was not before, redisplay
9091 again, so that we display it. Expose events for such a frame
9092 (which it gets when becoming visible) don't call the parts of
9093 redisplay constructing glyphs, so simply exposing a frame won't
9094 display anything in this case. So, we have to display these
9095 frames here explicitly. */
9098 Lisp_Object tail
, frame
;
9101 FOR_EACH_FRAME (tail
, frame
)
9103 int this_is_visible
= 0;
9105 if (XFRAME (frame
)->visible
)
9106 this_is_visible
= 1;
9107 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9108 if (XFRAME (frame
)->visible
)
9109 this_is_visible
= 1;
9111 if (this_is_visible
)
9115 if (new_count
!= number_of_visible_frames
)
9116 windows_or_buffers_changed
++;
9119 /* Change frame size now if a change is pending. */
9120 do_pending_window_change (1);
9122 /* If we just did a pending size change, or have additional
9123 visible frames, redisplay again. */
9124 if (windows_or_buffers_changed
&& !pause
)
9129 unbind_to (count
, Qnil
);
9133 /* Redisplay, but leave alone any recent echo area message unless
9134 another message has been requested in its place.
9136 This is useful in situations where you need to redisplay but no
9137 user action has occurred, making it inappropriate for the message
9138 area to be cleared. See tracking_off and
9139 wait_reading_process_input for examples of these situations.
9141 FROM_WHERE is an integer saying from where this function was
9142 called. This is useful for debugging. */
9145 redisplay_preserve_echo_area (from_where
)
9148 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9150 if (!NILP (echo_area_buffer
[1]))
9152 /* We have a previously displayed message, but no current
9153 message. Redisplay the previous message. */
9154 display_last_displayed_message_p
= 1;
9155 redisplay_internal (1);
9156 display_last_displayed_message_p
= 0;
9159 redisplay_internal (1);
9163 /* Function registered with record_unwind_protect in
9164 redisplay_internal. Clears the flag indicating that a redisplay is
9168 unwind_redisplay (old_redisplaying_p
)
9169 Lisp_Object old_redisplaying_p
;
9171 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9176 /* Mark the display of window W as accurate or inaccurate. If
9177 ACCURATE_P is non-zero mark display of W as accurate. If
9178 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9179 redisplay_internal is called. */
9182 mark_window_display_accurate_1 (w
, accurate_p
)
9186 if (BUFFERP (w
->buffer
))
9188 struct buffer
*b
= XBUFFER (w
->buffer
);
9191 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9192 w
->last_overlay_modified
9193 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9195 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9199 b
->clip_changed
= 0;
9200 b
->prevent_redisplay_optimizations_p
= 0;
9202 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9203 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9204 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9205 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9207 w
->current_matrix
->buffer
= b
;
9208 w
->current_matrix
->begv
= BUF_BEGV (b
);
9209 w
->current_matrix
->zv
= BUF_ZV (b
);
9211 w
->last_cursor
= w
->cursor
;
9212 w
->last_cursor_off_p
= w
->cursor_off_p
;
9214 if (w
== XWINDOW (selected_window
))
9215 w
->last_point
= make_number (BUF_PT (b
));
9217 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9223 w
->window_end_valid
= w
->buffer
;
9224 #if 0 /* This is incorrect with variable-height lines. */
9225 xassert (XINT (w
->window_end_vpos
)
9227 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9229 w
->update_mode_line
= Qnil
;
9234 /* Mark the display of windows in the window tree rooted at WINDOW as
9235 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9236 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9237 be redisplayed the next time redisplay_internal is called. */
9240 mark_window_display_accurate (window
, accurate_p
)
9246 for (; !NILP (window
); window
= w
->next
)
9248 w
= XWINDOW (window
);
9249 mark_window_display_accurate_1 (w
, accurate_p
);
9251 if (!NILP (w
->vchild
))
9252 mark_window_display_accurate (w
->vchild
, accurate_p
);
9253 if (!NILP (w
->hchild
))
9254 mark_window_display_accurate (w
->hchild
, accurate_p
);
9259 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9260 last_arrow_string
= Voverlay_arrow_string
;
9264 /* Force a thorough redisplay the next time by setting
9265 last_arrow_position and last_arrow_string to t, which is
9266 unequal to any useful value of Voverlay_arrow_... */
9267 last_arrow_position
= Qt
;
9268 last_arrow_string
= Qt
;
9273 /* Return value in display table DP (Lisp_Char_Table *) for character
9274 C. Since a display table doesn't have any parent, we don't have to
9275 follow parent. Do not call this function directly but use the
9276 macro DISP_CHAR_VECTOR. */
9279 disp_char_vector (dp
, c
)
9280 struct Lisp_Char_Table
*dp
;
9285 if (ASCII_CHAR_P (c
))
9288 if (SUB_CHAR_TABLE_P (val
))
9289 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
9295 XSETCHAR_TABLE (table
, dp
);
9296 val
= char_table_ref (table
, c
);
9305 /***********************************************************************
9307 ***********************************************************************/
9309 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9312 redisplay_windows (window
)
9315 while (!NILP (window
))
9317 struct window
*w
= XWINDOW (window
);
9319 if (!NILP (w
->hchild
))
9320 redisplay_windows (w
->hchild
);
9321 else if (!NILP (w
->vchild
))
9322 redisplay_windows (w
->vchild
);
9325 displayed_buffer
= XBUFFER (w
->buffer
);
9326 internal_condition_case_1 (redisplay_window_0
, window
, Qerror
,
9327 redisplay_window_error
);
9335 redisplay_window_error ()
9337 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9342 redisplay_window_0 (window
)
9345 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9346 redisplay_window (window
, 0);
9351 redisplay_window_1 (window
)
9354 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9355 redisplay_window (window
, 1);
9359 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9360 DELTA is the number of bytes by which positions recorded in ROW
9361 differ from current buffer positions. */
9364 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9366 struct glyph_row
*row
;
9367 struct glyph_matrix
*matrix
;
9368 int delta
, delta_bytes
, dy
, dvpos
;
9370 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9371 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9373 int pt_old
= PT
- delta
;
9375 /* Skip over glyphs not having an object at the start of the row.
9376 These are special glyphs like truncation marks on terminal
9378 if (row
->displays_text_p
)
9380 && INTEGERP (glyph
->object
)
9381 && glyph
->charpos
< 0)
9383 x
+= glyph
->pixel_width
;
9388 && !INTEGERP (glyph
->object
)
9389 && (!BUFFERP (glyph
->object
)
9390 || glyph
->charpos
< pt_old
))
9392 x
+= glyph
->pixel_width
;
9396 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9398 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9399 w
->cursor
.y
= row
->y
+ dy
;
9401 if (w
== XWINDOW (selected_window
))
9403 if (!row
->continued_p
9404 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9407 this_line_buffer
= XBUFFER (w
->buffer
);
9409 CHARPOS (this_line_start_pos
)
9410 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9411 BYTEPOS (this_line_start_pos
)
9412 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9414 CHARPOS (this_line_end_pos
)
9415 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9416 BYTEPOS (this_line_end_pos
)
9417 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9419 this_line_y
= w
->cursor
.y
;
9420 this_line_pixel_height
= row
->height
;
9421 this_line_vpos
= w
->cursor
.vpos
;
9422 this_line_start_x
= row
->x
;
9425 CHARPOS (this_line_start_pos
) = 0;
9430 /* Run window scroll functions, if any, for WINDOW with new window
9431 start STARTP. Sets the window start of WINDOW to that position.
9433 We assume that the window's buffer is really current. */
9435 static INLINE
struct text_pos
9436 run_window_scroll_functions (window
, startp
)
9438 struct text_pos startp
;
9440 struct window
*w
= XWINDOW (window
);
9441 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9443 if (current_buffer
!= XBUFFER (w
->buffer
))
9446 if (!NILP (Vwindow_scroll_functions
))
9448 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9449 make_number (CHARPOS (startp
)));
9450 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9451 /* In case the hook functions switch buffers. */
9452 if (current_buffer
!= XBUFFER (w
->buffer
))
9453 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9460 /* Modify the desired matrix of window W and W->vscroll so that the
9461 line containing the cursor is fully visible. If this requires
9462 larger matrices than are allocated, set fonts_changed_p and return
9466 make_cursor_line_fully_visible (w
)
9469 struct glyph_matrix
*matrix
;
9470 struct glyph_row
*row
;
9473 /* It's not always possible to find the cursor, e.g, when a window
9474 is full of overlay strings. Don't do anything in that case. */
9475 if (w
->cursor
.vpos
< 0)
9478 matrix
= w
->desired_matrix
;
9479 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9481 /* If the cursor row is not partially visible, there's nothing
9483 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9486 /* If the row the cursor is in is taller than the window's height,
9487 it's not clear what to do, so do nothing. */
9488 window_height
= window_box_height (w
);
9489 if (row
->height
>= window_height
)
9492 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9494 int dy
= row
->height
- row
->visible_height
;
9497 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9499 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9501 int dy
= - (row
->height
- row
->visible_height
);
9504 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9507 /* When we change the cursor y-position of the selected window,
9508 change this_line_y as well so that the display optimization for
9509 the cursor line of the selected window in redisplay_internal uses
9510 the correct y-position. */
9511 if (w
== XWINDOW (selected_window
))
9512 this_line_y
= w
->cursor
.y
;
9514 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9515 redisplay with larger matrices. */
9516 if (matrix
->nrows
< required_matrix_height (w
))
9518 fonts_changed_p
= 1;
9526 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9527 non-zero means only WINDOW is redisplayed in redisplay_internal.
9528 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9529 in redisplay_window to bring a partially visible line into view in
9530 the case that only the cursor has moved.
9534 1 if scrolling succeeded
9536 0 if scrolling didn't find point.
9538 -1 if new fonts have been loaded so that we must interrupt
9539 redisplay, adjust glyph matrices, and try again. */
9545 SCROLLING_NEED_LARGER_MATRICES
9549 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9550 scroll_step
, temp_scroll_step
)
9552 int just_this_one_p
;
9553 int scroll_conservatively
, scroll_step
;
9554 int temp_scroll_step
;
9556 struct window
*w
= XWINDOW (window
);
9557 struct frame
*f
= XFRAME (w
->frame
);
9558 struct text_pos scroll_margin_pos
;
9559 struct text_pos pos
;
9560 struct text_pos startp
;
9562 Lisp_Object window_end
;
9563 int this_scroll_margin
;
9567 int amount_to_scroll
= 0;
9568 Lisp_Object aggressive
;
9572 debug_method_add (w
, "try_scrolling");
9575 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9577 /* Compute scroll margin height in pixels. We scroll when point is
9578 within this distance from the top or bottom of the window. */
9579 if (scroll_margin
> 0)
9581 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9582 this_scroll_margin
*= CANON_Y_UNIT (f
);
9585 this_scroll_margin
= 0;
9587 /* Compute how much we should try to scroll maximally to bring point
9589 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9590 scroll_max
= max (scroll_step
,
9591 max (scroll_conservatively
, temp_scroll_step
));
9592 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9593 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9594 /* We're trying to scroll because of aggressive scrolling
9595 but no scroll_step is set. Choose an arbitrary one. Maybe
9596 there should be a variable for this. */
9600 scroll_max
*= CANON_Y_UNIT (f
);
9602 /* Decide whether we have to scroll down. Start at the window end
9603 and move this_scroll_margin up to find the position of the scroll
9605 window_end
= Fwindow_end (window
, Qt
);
9606 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9607 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9608 if (this_scroll_margin
)
9610 start_display (&it
, w
, scroll_margin_pos
);
9611 move_it_vertically (&it
, - this_scroll_margin
);
9612 scroll_margin_pos
= it
.current
.pos
;
9615 if (PT
>= CHARPOS (scroll_margin_pos
))
9619 /* Point is in the scroll margin at the bottom of the window, or
9620 below. Compute a new window start that makes point visible. */
9622 /* Compute the distance from the scroll margin to PT.
9623 Give up if the distance is greater than scroll_max. */
9624 start_display (&it
, w
, scroll_margin_pos
);
9626 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9627 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9629 /* To make point visible, we have to move the window start
9630 down so that the line the cursor is in is visible, which
9631 means we have to add in the height of the cursor line. */
9632 dy
= line_bottom_y (&it
) - y0
;
9634 if (dy
> scroll_max
)
9635 return SCROLLING_FAILED
;
9637 /* Move the window start down. If scrolling conservatively,
9638 move it just enough down to make point visible. If
9639 scroll_step is set, move it down by scroll_step. */
9640 start_display (&it
, w
, startp
);
9642 if (scroll_conservatively
)
9644 = max (max (dy
, CANON_Y_UNIT (f
)),
9645 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9646 else if (scroll_step
|| temp_scroll_step
)
9647 amount_to_scroll
= scroll_max
;
9650 aggressive
= current_buffer
->scroll_up_aggressively
;
9651 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9652 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9653 if (NUMBERP (aggressive
))
9654 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9657 if (amount_to_scroll
<= 0)
9658 return SCROLLING_FAILED
;
9660 move_it_vertically (&it
, amount_to_scroll
);
9661 startp
= it
.current
.pos
;
9665 /* See if point is inside the scroll margin at the top of the
9667 scroll_margin_pos
= startp
;
9668 if (this_scroll_margin
)
9670 start_display (&it
, w
, startp
);
9671 move_it_vertically (&it
, this_scroll_margin
);
9672 scroll_margin_pos
= it
.current
.pos
;
9675 if (PT
< CHARPOS (scroll_margin_pos
))
9677 /* Point is in the scroll margin at the top of the window or
9678 above what is displayed in the window. */
9681 /* Compute the vertical distance from PT to the scroll
9682 margin position. Give up if distance is greater than
9684 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9685 start_display (&it
, w
, pos
);
9687 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9688 it
.last_visible_y
, -1,
9689 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9690 dy
= it
.current_y
- y0
;
9691 if (dy
> scroll_max
)
9692 return SCROLLING_FAILED
;
9694 /* Compute new window start. */
9695 start_display (&it
, w
, startp
);
9697 if (scroll_conservatively
)
9699 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9700 else if (scroll_step
|| temp_scroll_step
)
9701 amount_to_scroll
= scroll_max
;
9704 aggressive
= current_buffer
->scroll_down_aggressively
;
9705 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9706 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9707 if (NUMBERP (aggressive
))
9708 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9711 if (amount_to_scroll
<= 0)
9712 return SCROLLING_FAILED
;
9714 move_it_vertically (&it
, - amount_to_scroll
);
9715 startp
= it
.current
.pos
;
9719 /* Run window scroll functions. */
9720 startp
= run_window_scroll_functions (window
, startp
);
9722 /* Display the window. Give up if new fonts are loaded, or if point
9724 if (!try_window (window
, startp
))
9725 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9726 else if (w
->cursor
.vpos
< 0)
9728 clear_glyph_matrix (w
->desired_matrix
);
9729 rc
= SCROLLING_FAILED
;
9733 /* Maybe forget recorded base line for line number display. */
9734 if (!just_this_one_p
9735 || current_buffer
->clip_changed
9736 || BEG_UNCHANGED
< CHARPOS (startp
))
9737 w
->base_line_number
= Qnil
;
9739 /* If cursor ends up on a partially visible line, shift display
9740 lines up or down. If that fails because we need larger
9741 matrices, give up. */
9742 if (!make_cursor_line_fully_visible (w
))
9743 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9745 rc
= SCROLLING_SUCCESS
;
9752 /* Compute a suitable window start for window W if display of W starts
9753 on a continuation line. Value is non-zero if a new window start
9756 The new window start will be computed, based on W's width, starting
9757 from the start of the continued line. It is the start of the
9758 screen line with the minimum distance from the old start W->start. */
9761 compute_window_start_on_continuation_line (w
)
9764 struct text_pos pos
, start_pos
;
9765 int window_start_changed_p
= 0;
9767 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9769 /* If window start is on a continuation line... Window start may be
9770 < BEGV in case there's invisible text at the start of the
9771 buffer (M-x rmail, for example). */
9772 if (CHARPOS (start_pos
) > BEGV
9773 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9776 struct glyph_row
*row
;
9778 /* Handle the case that the window start is out of range. */
9779 if (CHARPOS (start_pos
) < BEGV
)
9780 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9781 else if (CHARPOS (start_pos
) > ZV
)
9782 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9784 /* Find the start of the continued line. This should be fast
9785 because scan_buffer is fast (newline cache). */
9786 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9787 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9788 row
, DEFAULT_FACE_ID
);
9789 reseat_at_previous_visible_line_start (&it
);
9791 /* If the line start is "too far" away from the window start,
9792 say it takes too much time to compute a new window start. */
9793 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9794 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9796 int min_distance
, distance
;
9798 /* Move forward by display lines to find the new window
9799 start. If window width was enlarged, the new start can
9800 be expected to be > the old start. If window width was
9801 decreased, the new window start will be < the old start.
9802 So, we're looking for the display line start with the
9803 minimum distance from the old window start. */
9804 pos
= it
.current
.pos
;
9805 min_distance
= INFINITY
;
9806 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9807 distance
< min_distance
)
9809 min_distance
= distance
;
9810 pos
= it
.current
.pos
;
9811 move_it_by_lines (&it
, 1, 0);
9814 /* Set the window start there. */
9815 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9816 window_start_changed_p
= 1;
9820 return window_start_changed_p
;
9824 /* Try cursor movement in case text has not changes in window WINDOW,
9825 with window start STARTP. Value is
9827 CURSOR_MOVEMENT_SUCCESS if successful
9829 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9831 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9832 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9833 we want to scroll as if scroll-step were set to 1. See the code.
9835 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9836 which case we have to abort this redisplay, and adjust matrices
9841 CURSOR_MOVEMENT_SUCCESS
,
9842 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9843 CURSOR_MOVEMENT_MUST_SCROLL
,
9844 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9848 try_cursor_movement (window
, startp
, scroll_step
)
9850 struct text_pos startp
;
9853 struct window
*w
= XWINDOW (window
);
9854 struct frame
*f
= XFRAME (w
->frame
);
9855 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9858 if (inhibit_try_cursor_movement
)
9862 /* Handle case where text has not changed, only point, and it has
9863 not moved off the frame. */
9864 if (/* Point may be in this window. */
9865 PT
>= CHARPOS (startp
)
9866 /* Selective display hasn't changed. */
9867 && !current_buffer
->clip_changed
9868 /* Function force-mode-line-update is used to force a thorough
9869 redisplay. It sets either windows_or_buffers_changed or
9870 update_mode_lines. So don't take a shortcut here for these
9872 && !update_mode_lines
9873 && !windows_or_buffers_changed
9874 /* Can't use this case if highlighting a region. When a
9875 region exists, cursor movement has to do more than just
9877 && !(!NILP (Vtransient_mark_mode
)
9878 && !NILP (current_buffer
->mark_active
))
9879 && NILP (w
->region_showing
)
9880 && NILP (Vshow_trailing_whitespace
)
9881 /* Right after splitting windows, last_point may be nil. */
9882 && INTEGERP (w
->last_point
)
9883 /* This code is not used for mini-buffer for the sake of the case
9884 of redisplaying to replace an echo area message; since in
9885 that case the mini-buffer contents per se are usually
9886 unchanged. This code is of no real use in the mini-buffer
9887 since the handling of this_line_start_pos, etc., in redisplay
9888 handles the same cases. */
9889 && !EQ (window
, minibuf_window
)
9890 /* When splitting windows or for new windows, it happens that
9891 redisplay is called with a nil window_end_vpos or one being
9892 larger than the window. This should really be fixed in
9893 window.c. I don't have this on my list, now, so we do
9894 approximately the same as the old redisplay code. --gerd. */
9895 && INTEGERP (w
->window_end_vpos
)
9896 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9897 && (FRAME_WINDOW_P (f
)
9898 || !MARKERP (Voverlay_arrow_position
)
9899 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9901 int this_scroll_margin
;
9902 struct glyph_row
*row
= NULL
;
9905 debug_method_add (w
, "cursor movement");
9908 /* Scroll if point within this distance from the top or bottom
9909 of the window. This is a pixel value. */
9910 this_scroll_margin
= max (0, scroll_margin
);
9911 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9912 this_scroll_margin
*= CANON_Y_UNIT (f
);
9914 /* Start with the row the cursor was displayed during the last
9915 not paused redisplay. Give up if that row is not valid. */
9916 if (w
->last_cursor
.vpos
< 0
9917 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9918 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9921 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9922 if (row
->mode_line_p
)
9924 if (!row
->enabled_p
)
9925 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9928 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
9931 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9933 if (PT
> XFASTINT (w
->last_point
))
9935 /* Point has moved forward. */
9936 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9937 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9939 xassert (row
->enabled_p
);
9943 /* The end position of a row equals the start position
9944 of the next row. If PT is there, we would rather
9945 display it in the next line. */
9946 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9947 && MATRIX_ROW_END_CHARPOS (row
) == PT
9948 && !cursor_row_p (w
, row
))
9951 /* If within the scroll margin, scroll. Note that
9952 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9953 the next line would be drawn, and that
9954 this_scroll_margin can be zero. */
9955 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9956 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9957 /* Line is completely visible last line in window
9958 and PT is to be set in the next line. */
9959 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9960 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9961 && !row
->ends_at_zv_p
9962 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9965 else if (PT
< XFASTINT (w
->last_point
))
9967 /* Cursor has to be moved backward. Note that PT >=
9968 CHARPOS (startp) because of the outer
9970 while (!row
->mode_line_p
9971 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9972 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9973 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9974 && (row
->y
> this_scroll_margin
9975 || CHARPOS (startp
) == BEGV
))
9977 xassert (row
->enabled_p
);
9981 /* Consider the following case: Window starts at BEGV,
9982 there is invisible, intangible text at BEGV, so that
9983 display starts at some point START > BEGV. It can
9984 happen that we are called with PT somewhere between
9985 BEGV and START. Try to handle that case. */
9986 if (row
< w
->current_matrix
->rows
9987 || row
->mode_line_p
)
9989 row
= w
->current_matrix
->rows
;
9990 if (row
->mode_line_p
)
9994 /* Due to newlines in overlay strings, we may have to
9995 skip forward over overlay strings. */
9996 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9997 && MATRIX_ROW_END_CHARPOS (row
) == PT
9998 && !cursor_row_p (w
, row
))
10001 /* If within the scroll margin, scroll. */
10002 if (row
->y
< this_scroll_margin
10003 && CHARPOS (startp
) != BEGV
)
10007 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
10008 || PT
> MATRIX_ROW_END_CHARPOS (row
))
10010 /* if PT is not in the glyph row, give up. */
10011 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10013 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10015 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
10016 && !row
->ends_at_zv_p
10017 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
10018 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10019 else if (row
->height
> window_box_height (w
))
10021 /* If we end up in a partially visible line, let's
10022 make it fully visible, except when it's taller
10023 than the window, in which case we can't do much
10026 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10030 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10031 try_window (window
, startp
);
10032 if (!make_cursor_line_fully_visible (w
))
10033 rc
= CURSOR_MOVEMENT_NEED_LARGER_MATRICES
;
10035 rc
= CURSOR_MOVEMENT_SUCCESS
;
10039 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10042 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10043 rc
= CURSOR_MOVEMENT_SUCCESS
;
10052 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10053 selected_window is redisplayed. */
10056 redisplay_window (window
, just_this_one_p
)
10057 Lisp_Object window
;
10058 int just_this_one_p
;
10060 struct window
*w
= XWINDOW (window
);
10061 struct frame
*f
= XFRAME (w
->frame
);
10062 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10063 struct buffer
*old
= current_buffer
;
10064 struct text_pos lpoint
, opoint
, startp
;
10065 int update_mode_line
;
10068 /* Record it now because it's overwritten. */
10069 int current_matrix_up_to_date_p
= 0;
10070 int temp_scroll_step
= 0;
10071 int count
= BINDING_STACK_SIZE ();
10074 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10077 /* W must be a leaf window here. */
10078 xassert (!NILP (w
->buffer
));
10080 *w
->desired_matrix
->method
= 0;
10083 specbind (Qinhibit_point_motion_hooks
, Qt
);
10085 reconsider_clip_changes (w
, buffer
);
10087 /* Has the mode line to be updated? */
10088 update_mode_line
= (!NILP (w
->update_mode_line
)
10089 || update_mode_lines
10090 || buffer
->clip_changed
);
10092 if (MINI_WINDOW_P (w
))
10094 if (w
== XWINDOW (echo_area_window
)
10095 && !NILP (echo_area_buffer
[0]))
10097 if (update_mode_line
)
10098 /* We may have to update a tty frame's menu bar or a
10099 tool-bar. Example `M-x C-h C-h C-g'. */
10100 goto finish_menu_bars
;
10102 /* We've already displayed the echo area glyphs in this window. */
10103 goto finish_scroll_bars
;
10105 else if (w
!= XWINDOW (minibuf_window
))
10107 /* W is a mini-buffer window, but it's not the currently
10108 active one, so clear it. */
10109 int yb
= window_text_bottom_y (w
);
10110 struct glyph_row
*row
;
10113 for (y
= 0, row
= w
->desired_matrix
->rows
;
10115 y
+= row
->height
, ++row
)
10116 blank_row (w
, row
, y
);
10117 goto finish_scroll_bars
;
10120 clear_glyph_matrix (w
->desired_matrix
);
10123 /* Otherwise set up data on this window; select its buffer and point
10125 /* Really select the buffer, for the sake of buffer-local
10127 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10128 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10130 current_matrix_up_to_date_p
10131 = (!NILP (w
->window_end_valid
)
10132 && !current_buffer
->clip_changed
10133 && XFASTINT (w
->last_modified
) >= MODIFF
10134 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10136 /* When windows_or_buffers_changed is non-zero, we can't rely on
10137 the window end being valid, so set it to nil there. */
10138 if (windows_or_buffers_changed
)
10140 /* If window starts on a continuation line, maybe adjust the
10141 window start in case the window's width changed. */
10142 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10143 compute_window_start_on_continuation_line (w
);
10145 w
->window_end_valid
= Qnil
;
10148 /* Some sanity checks. */
10149 CHECK_WINDOW_END (w
);
10150 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10152 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10155 /* If %c is in mode line, update it if needed. */
10156 if (!NILP (w
->column_number_displayed
)
10157 /* This alternative quickly identifies a common case
10158 where no change is needed. */
10159 && !(PT
== XFASTINT (w
->last_point
)
10160 && XFASTINT (w
->last_modified
) >= MODIFF
10161 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10162 && XFASTINT (w
->column_number_displayed
) != current_column ())
10163 update_mode_line
= 1;
10165 /* Count number of windows showing the selected buffer. An indirect
10166 buffer counts as its base buffer. */
10167 if (!just_this_one_p
)
10169 struct buffer
*current_base
, *window_base
;
10170 current_base
= current_buffer
;
10171 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10172 if (current_base
->base_buffer
)
10173 current_base
= current_base
->base_buffer
;
10174 if (window_base
->base_buffer
)
10175 window_base
= window_base
->base_buffer
;
10176 if (current_base
== window_base
)
10180 /* Point refers normally to the selected window. For any other
10181 window, set up appropriate value. */
10182 if (!EQ (window
, selected_window
))
10184 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10185 int new_pt_byte
= marker_byte_position (w
->pointm
);
10189 new_pt_byte
= BEGV_BYTE
;
10190 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10192 else if (new_pt
> (ZV
- 1))
10195 new_pt_byte
= ZV_BYTE
;
10196 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10199 /* We don't use SET_PT so that the point-motion hooks don't run. */
10200 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10203 /* If any of the character widths specified in the display table
10204 have changed, invalidate the width run cache. It's true that
10205 this may be a bit late to catch such changes, but the rest of
10206 redisplay goes (non-fatally) haywire when the display table is
10207 changed, so why should we worry about doing any better? */
10208 if (current_buffer
->width_run_cache
)
10210 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10212 if (! disptab_matches_widthtab (disptab
,
10213 XVECTOR (current_buffer
->width_table
)))
10215 invalidate_region_cache (current_buffer
,
10216 current_buffer
->width_run_cache
,
10218 recompute_width_table (current_buffer
, disptab
);
10222 /* If window-start is screwed up, choose a new one. */
10223 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10226 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10228 /* If someone specified a new starting point but did not insist,
10229 check whether it can be used. */
10230 if (!NILP (w
->optional_new_start
)
10231 && CHARPOS (startp
) >= BEGV
10232 && CHARPOS (startp
) <= ZV
)
10234 w
->optional_new_start
= Qnil
;
10235 start_display (&it
, w
, startp
);
10236 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10237 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10238 if (IT_CHARPOS (it
) == PT
)
10239 w
->force_start
= Qt
;
10242 /* Handle case where place to start displaying has been specified,
10243 unless the specified location is outside the accessible range. */
10244 if (!NILP (w
->force_start
)
10245 || w
->frozen_window_start_p
)
10247 w
->force_start
= Qnil
;
10249 w
->window_end_valid
= Qnil
;
10251 /* Forget any recorded base line for line number display. */
10252 if (!current_matrix_up_to_date_p
10253 || current_buffer
->clip_changed
)
10254 w
->base_line_number
= Qnil
;
10256 /* Redisplay the mode line. Select the buffer properly for that.
10257 Also, run the hook window-scroll-functions
10258 because we have scrolled. */
10259 /* Note, we do this after clearing force_start because
10260 if there's an error, it is better to forget about force_start
10261 than to get into an infinite loop calling the hook functions
10262 and having them get more errors. */
10263 if (!update_mode_line
10264 || ! NILP (Vwindow_scroll_functions
))
10266 update_mode_line
= 1;
10267 w
->update_mode_line
= Qt
;
10268 startp
= run_window_scroll_functions (window
, startp
);
10271 w
->last_modified
= make_number (0);
10272 w
->last_overlay_modified
= make_number (0);
10273 if (CHARPOS (startp
) < BEGV
)
10274 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10275 else if (CHARPOS (startp
) > ZV
)
10276 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10278 /* Redisplay, then check if cursor has been set during the
10279 redisplay. Give up if new fonts were loaded. */
10280 if (!try_window (window
, startp
))
10282 w
->force_start
= Qt
;
10283 clear_glyph_matrix (w
->desired_matrix
);
10284 goto finish_scroll_bars
;
10287 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10289 /* If point does not appear, try to move point so it does
10290 appear. The desired matrix has been built above, so we
10291 can use it here. */
10293 struct glyph_row
*row
;
10295 window_height
= window_box_height (w
) / 2;
10296 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10297 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10300 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10301 MATRIX_ROW_START_BYTEPOS (row
));
10303 if (w
!= XWINDOW (selected_window
))
10304 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10305 else if (current_buffer
== old
)
10306 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10308 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10310 /* If we are highlighting the region, then we just changed
10311 the region, so redisplay to show it. */
10312 if (!NILP (Vtransient_mark_mode
)
10313 && !NILP (current_buffer
->mark_active
))
10315 clear_glyph_matrix (w
->desired_matrix
);
10316 if (!try_window (window
, startp
))
10317 goto need_larger_matrices
;
10321 if (!make_cursor_line_fully_visible (w
))
10322 goto need_larger_matrices
;
10324 debug_method_add (w
, "forced window start");
10329 /* Handle case where text has not changed, only point, and it has
10330 not moved off the frame. */
10331 if (current_matrix_up_to_date_p
10332 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10333 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10337 case CURSOR_MOVEMENT_SUCCESS
:
10340 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10341 goto need_larger_matrices
;
10343 case CURSOR_MOVEMENT_MUST_SCROLL
:
10344 goto try_to_scroll
;
10350 /* If current starting point was originally the beginning of a line
10351 but no longer is, find a new starting point. */
10352 else if (!NILP (w
->start_at_line_beg
)
10353 && !(CHARPOS (startp
) <= BEGV
10354 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10357 debug_method_add (w
, "recenter 1");
10362 /* Try scrolling with try_window_id. Value is > 0 if update has
10363 been done, it is -1 if we know that the same window start will
10364 not work. It is 0 if unsuccessful for some other reason. */
10365 else if ((tem
= try_window_id (w
)) != 0)
10368 debug_method_add (w
, "try_window_id %d", tem
);
10371 if (fonts_changed_p
)
10372 goto need_larger_matrices
;
10376 /* Otherwise try_window_id has returned -1 which means that we
10377 don't want the alternative below this comment to execute. */
10379 else if (CHARPOS (startp
) >= BEGV
10380 && CHARPOS (startp
) <= ZV
10381 && PT
>= CHARPOS (startp
)
10382 && (CHARPOS (startp
) < ZV
10383 /* Avoid starting at end of buffer. */
10384 || CHARPOS (startp
) == BEGV
10385 || (XFASTINT (w
->last_modified
) >= MODIFF
10386 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10389 debug_method_add (w
, "same window start");
10392 /* Try to redisplay starting at same place as before.
10393 If point has not moved off frame, accept the results. */
10394 if (!current_matrix_up_to_date_p
10395 /* Don't use try_window_reusing_current_matrix in this case
10396 because a window scroll function can have changed the
10398 || !NILP (Vwindow_scroll_functions
)
10399 || MINI_WINDOW_P (w
)
10400 || !try_window_reusing_current_matrix (w
))
10402 IF_DEBUG (debug_method_add (w
, "1"));
10403 try_window (window
, startp
);
10406 if (fonts_changed_p
)
10407 goto need_larger_matrices
;
10409 if (w
->cursor
.vpos
>= 0)
10411 if (!just_this_one_p
10412 || current_buffer
->clip_changed
10413 || BEG_UNCHANGED
< CHARPOS (startp
))
10414 /* Forget any recorded base line for line number display. */
10415 w
->base_line_number
= Qnil
;
10417 if (!make_cursor_line_fully_visible (w
))
10418 goto need_larger_matrices
;
10422 clear_glyph_matrix (w
->desired_matrix
);
10427 w
->last_modified
= make_number (0);
10428 w
->last_overlay_modified
= make_number (0);
10430 /* Redisplay the mode line. Select the buffer properly for that. */
10431 if (!update_mode_line
)
10433 update_mode_line
= 1;
10434 w
->update_mode_line
= Qt
;
10437 /* Try to scroll by specified few lines. */
10438 if ((scroll_conservatively
10440 || temp_scroll_step
10441 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10442 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10443 && !current_buffer
->clip_changed
10444 && CHARPOS (startp
) >= BEGV
10445 && CHARPOS (startp
) <= ZV
)
10447 /* The function returns -1 if new fonts were loaded, 1 if
10448 successful, 0 if not successful. */
10449 int rc
= try_scrolling (window
, just_this_one_p
,
10450 scroll_conservatively
,
10455 case SCROLLING_SUCCESS
:
10458 case SCROLLING_NEED_LARGER_MATRICES
:
10459 goto need_larger_matrices
;
10461 case SCROLLING_FAILED
:
10469 /* Finally, just choose place to start which centers point */
10474 debug_method_add (w
, "recenter");
10477 /* w->vscroll = 0; */
10479 /* Forget any previously recorded base line for line number display. */
10480 if (!current_matrix_up_to_date_p
10481 || current_buffer
->clip_changed
)
10482 w
->base_line_number
= Qnil
;
10484 /* Move backward half the height of the window. */
10485 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10486 it
.current_y
= it
.last_visible_y
;
10487 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10488 xassert (IT_CHARPOS (it
) >= BEGV
);
10490 /* The function move_it_vertically_backward may move over more
10491 than the specified y-distance. If it->w is small, e.g. a
10492 mini-buffer window, we may end up in front of the window's
10493 display area. Start displaying at the start of the line
10494 containing PT in this case. */
10495 if (it
.current_y
<= 0)
10497 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10498 move_it_vertically (&it
, 0);
10499 xassert (IT_CHARPOS (it
) <= PT
);
10503 it
.current_x
= it
.hpos
= 0;
10505 /* Set startp here explicitly in case that helps avoid an infinite loop
10506 in case the window-scroll-functions functions get errors. */
10507 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10509 /* Run scroll hooks. */
10510 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10512 /* Redisplay the window. */
10513 if (!current_matrix_up_to_date_p
10514 || windows_or_buffers_changed
10515 /* Don't use try_window_reusing_current_matrix in this case
10516 because it can have changed the buffer. */
10517 || !NILP (Vwindow_scroll_functions
)
10518 || !just_this_one_p
10519 || MINI_WINDOW_P (w
)
10520 || !try_window_reusing_current_matrix (w
))
10521 try_window (window
, startp
);
10523 /* If new fonts have been loaded (due to fontsets), give up. We
10524 have to start a new redisplay since we need to re-adjust glyph
10526 if (fonts_changed_p
)
10527 goto need_larger_matrices
;
10529 /* If cursor did not appear assume that the middle of the window is
10530 in the first line of the window. Do it again with the next line.
10531 (Imagine a window of height 100, displaying two lines of height
10532 60. Moving back 50 from it->last_visible_y will end in the first
10534 if (w
->cursor
.vpos
< 0)
10536 if (!NILP (w
->window_end_valid
)
10537 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10539 clear_glyph_matrix (w
->desired_matrix
);
10540 move_it_by_lines (&it
, 1, 0);
10541 try_window (window
, it
.current
.pos
);
10543 else if (PT
< IT_CHARPOS (it
))
10545 clear_glyph_matrix (w
->desired_matrix
);
10546 move_it_by_lines (&it
, -1, 0);
10547 try_window (window
, it
.current
.pos
);
10551 /* Not much we can do about it. */
10555 /* Consider the following case: Window starts at BEGV, there is
10556 invisible, intangible text at BEGV, so that display starts at
10557 some point START > BEGV. It can happen that we are called with
10558 PT somewhere between BEGV and START. Try to handle that case. */
10559 if (w
->cursor
.vpos
< 0)
10561 struct glyph_row
*row
= w
->current_matrix
->rows
;
10562 if (row
->mode_line_p
)
10564 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10567 if (!make_cursor_line_fully_visible (w
))
10568 goto need_larger_matrices
;
10572 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10573 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10574 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10577 /* Display the mode line, if we must. */
10578 if ((update_mode_line
10579 /* If window not full width, must redo its mode line
10580 if (a) the window to its side is being redone and
10581 (b) we do a frame-based redisplay. This is a consequence
10582 of how inverted lines are drawn in frame-based redisplay. */
10583 || (!just_this_one_p
10584 && !FRAME_WINDOW_P (f
)
10585 && !WINDOW_FULL_WIDTH_P (w
))
10586 /* Line number to display. */
10587 || INTEGERP (w
->base_line_pos
)
10588 /* Column number is displayed and different from the one displayed. */
10589 || (!NILP (w
->column_number_displayed
)
10590 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10591 /* This means that the window has a mode line. */
10592 && (WINDOW_WANTS_MODELINE_P (w
)
10593 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10595 display_mode_lines (w
);
10597 /* If mode line height has changed, arrange for a thorough
10598 immediate redisplay using the correct mode line height. */
10599 if (WINDOW_WANTS_MODELINE_P (w
)
10600 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10602 fonts_changed_p
= 1;
10603 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10604 = DESIRED_MODE_LINE_HEIGHT (w
);
10607 /* If top line height has changed, arrange for a thorough
10608 immediate redisplay using the correct mode line height. */
10609 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10610 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10612 fonts_changed_p
= 1;
10613 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10614 = DESIRED_HEADER_LINE_HEIGHT (w
);
10617 if (fonts_changed_p
)
10618 goto need_larger_matrices
;
10621 if (!line_number_displayed
10622 && !BUFFERP (w
->base_line_pos
))
10624 w
->base_line_pos
= Qnil
;
10625 w
->base_line_number
= Qnil
;
10630 /* When we reach a frame's selected window, redo the frame's menu bar. */
10631 if (update_mode_line
10632 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10634 int redisplay_menu_p
= 0;
10636 if (FRAME_WINDOW_P (f
))
10638 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10639 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10641 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10645 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10647 if (redisplay_menu_p
)
10648 display_menu_bar (w
);
10650 #ifdef HAVE_WINDOW_SYSTEM
10651 if (WINDOWP (f
->tool_bar_window
)
10652 && (FRAME_TOOL_BAR_LINES (f
) > 0
10653 || auto_resize_tool_bars_p
))
10654 redisplay_tool_bar (f
);
10658 need_larger_matrices
:
10660 finish_scroll_bars
:
10662 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10664 int start
, end
, whole
;
10666 /* Calculate the start and end positions for the current window.
10667 At some point, it would be nice to choose between scrollbars
10668 which reflect the whole buffer size, with special markers
10669 indicating narrowing, and scrollbars which reflect only the
10672 Note that mini-buffers sometimes aren't displaying any text. */
10673 if (!MINI_WINDOW_P (w
)
10674 || (w
== XWINDOW (minibuf_window
)
10675 && NILP (echo_area_buffer
[0])))
10678 start
= marker_position (w
->start
) - BEGV
;
10679 /* I don't think this is guaranteed to be right. For the
10680 moment, we'll pretend it is. */
10681 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10685 if (whole
< (end
- start
))
10686 whole
= end
- start
;
10689 start
= end
= whole
= 0;
10691 /* Indicate what this scroll bar ought to be displaying now. */
10692 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10694 /* Note that we actually used the scroll bar attached to this
10695 window, so it shouldn't be deleted at the end of redisplay. */
10696 redeem_scroll_bar_hook (w
);
10699 /* Restore current_buffer and value of point in it. */
10700 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10701 set_buffer_internal_1 (old
);
10702 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10704 unbind_to (count
, Qnil
);
10708 /* Build the complete desired matrix of WINDOW with a window start
10709 buffer position POS. Value is non-zero if successful. It is zero
10710 if fonts were loaded during redisplay which makes re-adjusting
10711 glyph matrices necessary. */
10714 try_window (window
, pos
)
10715 Lisp_Object window
;
10716 struct text_pos pos
;
10718 struct window
*w
= XWINDOW (window
);
10720 struct glyph_row
*last_text_row
= NULL
;
10722 /* Make POS the new window start. */
10723 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10725 /* Mark cursor position as unknown. No overlay arrow seen. */
10726 w
->cursor
.vpos
= -1;
10727 overlay_arrow_seen
= 0;
10729 /* Initialize iterator and info to start at POS. */
10730 start_display (&it
, w
, pos
);
10732 /* Display all lines of W. */
10733 while (it
.current_y
< it
.last_visible_y
)
10735 if (display_line (&it
))
10736 last_text_row
= it
.glyph_row
- 1;
10737 if (fonts_changed_p
)
10741 /* If bottom moved off end of frame, change mode line percentage. */
10742 if (XFASTINT (w
->window_end_pos
) <= 0
10743 && Z
!= IT_CHARPOS (it
))
10744 w
->update_mode_line
= Qt
;
10746 /* Set window_end_pos to the offset of the last character displayed
10747 on the window from the end of current_buffer. Set
10748 window_end_vpos to its row number. */
10751 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10752 w
->window_end_bytepos
10753 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10755 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10757 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10758 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10759 ->displays_text_p
);
10763 w
->window_end_bytepos
= 0;
10764 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10767 /* But that is not valid info until redisplay finishes. */
10768 w
->window_end_valid
= Qnil
;
10774 /************************************************************************
10775 Window redisplay reusing current matrix when buffer has not changed
10776 ************************************************************************/
10778 /* Try redisplay of window W showing an unchanged buffer with a
10779 different window start than the last time it was displayed by
10780 reusing its current matrix. Value is non-zero if successful.
10781 W->start is the new window start. */
10784 try_window_reusing_current_matrix (w
)
10787 struct frame
*f
= XFRAME (w
->frame
);
10788 struct glyph_row
*row
, *bottom_row
;
10791 struct text_pos start
, new_start
;
10792 int nrows_scrolled
, i
;
10793 struct glyph_row
*last_text_row
;
10794 struct glyph_row
*last_reused_text_row
;
10795 struct glyph_row
*start_row
;
10796 int start_vpos
, min_y
, max_y
;
10799 if (inhibit_try_window_reusing
)
10803 if (/* This function doesn't handle terminal frames. */
10804 !FRAME_WINDOW_P (f
)
10805 /* Don't try to reuse the display if windows have been split
10807 || windows_or_buffers_changed
)
10810 /* Can't do this if region may have changed. */
10811 if ((!NILP (Vtransient_mark_mode
)
10812 && !NILP (current_buffer
->mark_active
))
10813 || !NILP (w
->region_showing
)
10814 || !NILP (Vshow_trailing_whitespace
))
10817 /* If top-line visibility has changed, give up. */
10818 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10819 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10822 /* Give up if old or new display is scrolled vertically. We could
10823 make this function handle this, but right now it doesn't. */
10824 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10825 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10828 /* The variable new_start now holds the new window start. The old
10829 start `start' can be determined from the current matrix. */
10830 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10831 start
= start_row
->start
.pos
;
10832 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10834 /* Clear the desired matrix for the display below. */
10835 clear_glyph_matrix (w
->desired_matrix
);
10837 if (CHARPOS (new_start
) <= CHARPOS (start
))
10841 /* Don't use this method if the display starts with an ellipsis
10842 displayed for invisible text. It's not easy to handle that case
10843 below, and it's certainly not worth the effort since this is
10844 not a frequent case. */
10845 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10848 IF_DEBUG (debug_method_add (w
, "twu1"));
10850 /* Display up to a row that can be reused. The variable
10851 last_text_row is set to the last row displayed that displays
10852 text. Note that it.vpos == 0 if or if not there is a
10853 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10854 start_display (&it
, w
, new_start
);
10855 first_row_y
= it
.current_y
;
10856 w
->cursor
.vpos
= -1;
10857 last_text_row
= last_reused_text_row
= NULL
;
10859 while (it
.current_y
< it
.last_visible_y
10860 && IT_CHARPOS (it
) < CHARPOS (start
)
10861 && !fonts_changed_p
)
10862 if (display_line (&it
))
10863 last_text_row
= it
.glyph_row
- 1;
10865 /* A value of current_y < last_visible_y means that we stopped
10866 at the previous window start, which in turn means that we
10867 have at least one reusable row. */
10868 if (it
.current_y
< it
.last_visible_y
)
10870 /* IT.vpos always starts from 0; it counts text lines. */
10871 nrows_scrolled
= it
.vpos
;
10873 /* Find PT if not already found in the lines displayed. */
10874 if (w
->cursor
.vpos
< 0)
10876 int dy
= it
.current_y
- first_row_y
;
10878 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10879 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
10881 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10882 dy
, nrows_scrolled
);
10885 clear_glyph_matrix (w
->desired_matrix
);
10890 /* Scroll the display. Do it before the current matrix is
10891 changed. The problem here is that update has not yet
10892 run, i.e. part of the current matrix is not up to date.
10893 scroll_run_hook will clear the cursor, and use the
10894 current matrix to get the height of the row the cursor is
10896 run
.current_y
= first_row_y
;
10897 run
.desired_y
= it
.current_y
;
10898 run
.height
= it
.last_visible_y
- it
.current_y
;
10900 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10903 rif
->update_window_begin_hook (w
);
10904 rif
->clear_mouse_face (w
);
10905 rif
->scroll_run_hook (w
, &run
);
10906 rif
->update_window_end_hook (w
, 0, 0);
10910 /* Shift current matrix down by nrows_scrolled lines. */
10911 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10912 rotate_matrix (w
->current_matrix
,
10914 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10917 /* Disable lines that must be updated. */
10918 for (i
= 0; i
< it
.vpos
; ++i
)
10919 (start_row
+ i
)->enabled_p
= 0;
10921 /* Re-compute Y positions. */
10922 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10923 max_y
= it
.last_visible_y
;
10924 for (row
= start_row
+ nrows_scrolled
;
10928 row
->y
= it
.current_y
;
10929 row
->visible_height
= row
->height
;
10931 if (row
->y
< min_y
)
10932 row
->visible_height
-= min_y
- row
->y
;
10933 if (row
->y
+ row
->height
> max_y
)
10934 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10936 it
.current_y
+= row
->height
;
10938 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10939 last_reused_text_row
= row
;
10940 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10944 /* Disable lines in the current matrix which are now
10945 below the window. */
10946 for (++row
; row
< bottom_row
; ++row
)
10947 row
->enabled_p
= 0;
10950 /* Update window_end_pos etc.; last_reused_text_row is the last
10951 reused row from the current matrix containing text, if any.
10952 The value of last_text_row is the last displayed line
10953 containing text. */
10954 if (last_reused_text_row
)
10956 w
->window_end_bytepos
10957 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10959 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10961 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10962 w
->current_matrix
));
10964 else if (last_text_row
)
10966 w
->window_end_bytepos
10967 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10969 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10971 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10975 /* This window must be completely empty. */
10976 w
->window_end_bytepos
= 0;
10977 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10979 w
->window_end_valid
= Qnil
;
10981 /* Update hint: don't try scrolling again in update_window. */
10982 w
->desired_matrix
->no_scrolling_p
= 1;
10985 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10989 else if (CHARPOS (new_start
) > CHARPOS (start
))
10991 struct glyph_row
*pt_row
, *row
;
10992 struct glyph_row
*first_reusable_row
;
10993 struct glyph_row
*first_row_to_display
;
10995 int yb
= window_text_bottom_y (w
);
10997 /* Find the row starting at new_start, if there is one. Don't
10998 reuse a partially visible line at the end. */
10999 first_reusable_row
= start_row
;
11000 while (first_reusable_row
->enabled_p
11001 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
11002 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11003 < CHARPOS (new_start
)))
11004 ++first_reusable_row
;
11006 /* Give up if there is no row to reuse. */
11007 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
11008 || !first_reusable_row
->enabled_p
11009 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11010 != CHARPOS (new_start
)))
11013 /* We can reuse fully visible rows beginning with
11014 first_reusable_row to the end of the window. Set
11015 first_row_to_display to the first row that cannot be reused.
11016 Set pt_row to the row containing point, if there is any. */
11018 for (first_row_to_display
= first_reusable_row
;
11019 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
11020 ++first_row_to_display
)
11022 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
11023 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
11024 pt_row
= first_row_to_display
;
11027 /* Start displaying at the start of first_row_to_display. */
11028 xassert (first_row_to_display
->y
< yb
);
11029 init_to_row_start (&it
, w
, first_row_to_display
);
11031 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
11033 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
11035 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11036 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11038 /* Display lines beginning with first_row_to_display in the
11039 desired matrix. Set last_text_row to the last row displayed
11040 that displays text. */
11041 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11042 if (pt_row
== NULL
)
11043 w
->cursor
.vpos
= -1;
11044 last_text_row
= NULL
;
11045 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11046 if (display_line (&it
))
11047 last_text_row
= it
.glyph_row
- 1;
11049 /* Give up If point isn't in a row displayed or reused. */
11050 if (w
->cursor
.vpos
< 0)
11052 clear_glyph_matrix (w
->desired_matrix
);
11056 /* If point is in a reused row, adjust y and vpos of the cursor
11060 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11061 w
->current_matrix
);
11062 w
->cursor
.y
-= first_reusable_row
->y
;
11065 /* Scroll the display. */
11066 run
.current_y
= first_reusable_row
->y
;
11067 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11068 run
.height
= it
.last_visible_y
- run
.current_y
;
11069 dy
= run
.current_y
- run
.desired_y
;
11073 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11075 rif
->update_window_begin_hook (w
);
11076 rif
->clear_mouse_face (w
);
11077 rif
->scroll_run_hook (w
, &run
);
11078 rif
->update_window_end_hook (w
, 0, 0);
11082 /* Adjust Y positions of reused rows. */
11083 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11084 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11085 max_y
= it
.last_visible_y
;
11086 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11089 row
->visible_height
= row
->height
;
11090 if (row
->y
< min_y
)
11091 row
->visible_height
-= min_y
- row
->y
;
11092 if (row
->y
+ row
->height
> max_y
)
11093 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11096 /* Scroll the current matrix. */
11097 xassert (nrows_scrolled
> 0);
11098 rotate_matrix (w
->current_matrix
,
11100 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11103 /* Disable rows not reused. */
11104 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11105 row
->enabled_p
= 0;
11107 /* Adjust window end. A null value of last_text_row means that
11108 the window end is in reused rows which in turn means that
11109 only its vpos can have changed. */
11112 w
->window_end_bytepos
11113 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11115 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11117 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11122 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11125 w
->window_end_valid
= Qnil
;
11126 w
->desired_matrix
->no_scrolling_p
= 1;
11129 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11139 /************************************************************************
11140 Window redisplay reusing current matrix when buffer has changed
11141 ************************************************************************/
11143 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11144 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11146 static struct glyph_row
*
11147 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11148 struct glyph_row
*));
11151 /* Return the last row in MATRIX displaying text. If row START is
11152 non-null, start searching with that row. IT gives the dimensions
11153 of the display. Value is null if matrix is empty; otherwise it is
11154 a pointer to the row found. */
11156 static struct glyph_row
*
11157 find_last_row_displaying_text (matrix
, it
, start
)
11158 struct glyph_matrix
*matrix
;
11160 struct glyph_row
*start
;
11162 struct glyph_row
*row
, *row_found
;
11164 /* Set row_found to the last row in IT->w's current matrix
11165 displaying text. The loop looks funny but think of partially
11168 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11169 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11171 xassert (row
->enabled_p
);
11173 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11182 /* Return the last row in the current matrix of W that is not affected
11183 by changes at the start of current_buffer that occurred since W's
11184 current matrix was built. Value is null if no such row exists.
11186 BEG_UNCHANGED us the number of characters unchanged at the start of
11187 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11188 first changed character in current_buffer. Characters at positions <
11189 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11190 when the current matrix was built. */
11192 static struct glyph_row
*
11193 find_last_unchanged_at_beg_row (w
)
11196 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11197 struct glyph_row
*row
;
11198 struct glyph_row
*row_found
= NULL
;
11199 int yb
= window_text_bottom_y (w
);
11201 /* Find the last row displaying unchanged text. */
11202 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11203 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11204 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11206 if (/* If row ends before first_changed_pos, it is unchanged,
11207 except in some case. */
11208 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11209 /* When row ends in ZV and we write at ZV it is not
11211 && !row
->ends_at_zv_p
11212 /* When first_changed_pos is the end of a continued line,
11213 row is not unchanged because it may be no longer
11215 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11216 && row
->continued_p
))
11219 /* Stop if last visible row. */
11220 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11230 /* Find the first glyph row in the current matrix of W that is not
11231 affected by changes at the end of current_buffer since the
11232 time W's current matrix was built.
11234 Return in *DELTA the number of chars by which buffer positions in
11235 unchanged text at the end of current_buffer must be adjusted.
11237 Return in *DELTA_BYTES the corresponding number of bytes.
11239 Value is null if no such row exists, i.e. all rows are affected by
11242 static struct glyph_row
*
11243 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11245 int *delta
, *delta_bytes
;
11247 struct glyph_row
*row
;
11248 struct glyph_row
*row_found
= NULL
;
11250 *delta
= *delta_bytes
= 0;
11252 /* Display must not have been paused, otherwise the current matrix
11253 is not up to date. */
11254 if (NILP (w
->window_end_valid
))
11257 /* A value of window_end_pos >= END_UNCHANGED means that the window
11258 end is in the range of changed text. If so, there is no
11259 unchanged row at the end of W's current matrix. */
11260 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11263 /* Set row to the last row in W's current matrix displaying text. */
11264 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11266 /* If matrix is entirely empty, no unchanged row exists. */
11267 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11269 /* The value of row is the last glyph row in the matrix having a
11270 meaningful buffer position in it. The end position of row
11271 corresponds to window_end_pos. This allows us to translate
11272 buffer positions in the current matrix to current buffer
11273 positions for characters not in changed text. */
11274 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11275 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11276 int last_unchanged_pos
, last_unchanged_pos_old
;
11277 struct glyph_row
*first_text_row
11278 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11280 *delta
= Z
- Z_old
;
11281 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11283 /* Set last_unchanged_pos to the buffer position of the last
11284 character in the buffer that has not been changed. Z is the
11285 index + 1 of the last character in current_buffer, i.e. by
11286 subtracting END_UNCHANGED we get the index of the last
11287 unchanged character, and we have to add BEG to get its buffer
11289 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11290 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11292 /* Search backward from ROW for a row displaying a line that
11293 starts at a minimum position >= last_unchanged_pos_old. */
11294 for (; row
> first_text_row
; --row
)
11296 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11299 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11304 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11311 /* Make sure that glyph rows in the current matrix of window W
11312 reference the same glyph memory as corresponding rows in the
11313 frame's frame matrix. This function is called after scrolling W's
11314 current matrix on a terminal frame in try_window_id and
11315 try_window_reusing_current_matrix. */
11318 sync_frame_with_window_matrix_rows (w
)
11321 struct frame
*f
= XFRAME (w
->frame
);
11322 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11324 /* Preconditions: W must be a leaf window and full-width. Its frame
11325 must have a frame matrix. */
11326 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11327 xassert (WINDOW_FULL_WIDTH_P (w
));
11328 xassert (!FRAME_WINDOW_P (f
));
11330 /* If W is a full-width window, glyph pointers in W's current matrix
11331 have, by definition, to be the same as glyph pointers in the
11332 corresponding frame matrix. */
11333 window_row
= w
->current_matrix
->rows
;
11334 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11335 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11336 while (window_row
< window_row_end
)
11340 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11341 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11343 /* Disable frame rows whose corresponding window rows have
11344 been disabled in try_window_id. */
11345 if (!window_row
->enabled_p
)
11346 frame_row
->enabled_p
= 0;
11348 ++window_row
, ++frame_row
;
11353 /* Find the glyph row in window W containing CHARPOS. Consider all
11354 rows between START and END (not inclusive). END null means search
11355 all rows to the end of the display area of W. Value is the row
11356 containing CHARPOS or null. */
11359 row_containing_pos (w
, charpos
, start
, end
, dy
)
11362 struct glyph_row
*start
, *end
;
11365 struct glyph_row
*row
= start
;
11368 /* If we happen to start on a header-line, skip that. */
11369 if (row
->mode_line_p
)
11372 if ((end
&& row
>= end
) || !row
->enabled_p
)
11375 last_y
= window_text_bottom_y (w
) - dy
;
11377 while ((end
== NULL
|| row
< end
)
11378 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
11379 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11380 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11381 /* The end position of a row equals the start
11382 position of the next row. If CHARPOS is there, we
11383 would rather display it in the next line, except
11384 when this line ends in ZV. */
11385 && !row
->ends_at_zv_p
11386 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))
11389 /* Give up if CHARPOS not found. */
11390 if ((end
&& row
>= end
)
11391 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11392 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11399 /* Try to redisplay window W by reusing its existing display. W's
11400 current matrix must be up to date when this function is called,
11401 i.e. window_end_valid must not be nil.
11405 1 if display has been updated
11406 0 if otherwise unsuccessful
11407 -1 if redisplay with same window start is known not to succeed
11409 The following steps are performed:
11411 1. Find the last row in the current matrix of W that is not
11412 affected by changes at the start of current_buffer. If no such row
11415 2. Find the first row in W's current matrix that is not affected by
11416 changes at the end of current_buffer. Maybe there is no such row.
11418 3. Display lines beginning with the row + 1 found in step 1 to the
11419 row found in step 2 or, if step 2 didn't find a row, to the end of
11422 4. If cursor is not known to appear on the window, give up.
11424 5. If display stopped at the row found in step 2, scroll the
11425 display and current matrix as needed.
11427 6. Maybe display some lines at the end of W, if we must. This can
11428 happen under various circumstances, like a partially visible line
11429 becoming fully visible, or because newly displayed lines are displayed
11430 in smaller font sizes.
11432 7. Update W's window end information. */
11438 struct frame
*f
= XFRAME (w
->frame
);
11439 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11440 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11441 struct glyph_row
*last_unchanged_at_beg_row
;
11442 struct glyph_row
*first_unchanged_at_end_row
;
11443 struct glyph_row
*row
;
11444 struct glyph_row
*bottom_row
;
11447 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11448 struct text_pos start_pos
;
11450 int first_unchanged_at_end_vpos
= 0;
11451 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11452 struct text_pos start
;
11453 int first_changed_charpos
, last_changed_charpos
;
11456 if (inhibit_try_window_id
)
11460 /* This is handy for debugging. */
11462 #define GIVE_UP(X) \
11464 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11468 #define GIVE_UP(X) return 0
11471 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11473 /* Don't use this for mini-windows because these can show
11474 messages and mini-buffers, and we don't handle that here. */
11475 if (MINI_WINDOW_P (w
))
11478 /* This flag is used to prevent redisplay optimizations. */
11479 if (windows_or_buffers_changed
)
11482 /* Verify that narrowing has not changed. This flag is also set to prevent
11483 redisplay optimizations. It would be nice to further
11484 reduce the number of cases where this prevents try_window_id. */
11485 if (current_buffer
->clip_changed
)
11488 /* Window must either use window-based redisplay or be full width. */
11489 if (!FRAME_WINDOW_P (f
)
11490 && (!line_ins_del_ok
11491 || !WINDOW_FULL_WIDTH_P (w
)))
11494 /* Give up if point is not known NOT to appear in W. */
11495 if (PT
< CHARPOS (start
))
11498 /* Another way to prevent redisplay optimizations. */
11499 if (XFASTINT (w
->last_modified
) == 0)
11502 /* Verify that window is not hscrolled. */
11503 if (XFASTINT (w
->hscroll
) != 0)
11506 /* Verify that display wasn't paused. */
11507 if (NILP (w
->window_end_valid
))
11510 /* Can't use this if highlighting a region because a cursor movement
11511 will do more than just set the cursor. */
11512 if (!NILP (Vtransient_mark_mode
)
11513 && !NILP (current_buffer
->mark_active
))
11516 /* Likewise if highlighting trailing whitespace. */
11517 if (!NILP (Vshow_trailing_whitespace
))
11520 /* Likewise if showing a region. */
11521 if (!NILP (w
->region_showing
))
11524 /* Can use this if overlay arrow position and or string have changed. */
11525 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11526 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11530 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11531 only if buffer has really changed. The reason is that the gap is
11532 initially at Z for freshly visited files. The code below would
11533 set end_unchanged to 0 in that case. */
11534 if (MODIFF
> SAVE_MODIFF
11535 /* This seems to happen sometimes after saving a buffer. */
11536 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11538 if (GPT
- BEG
< BEG_UNCHANGED
)
11539 BEG_UNCHANGED
= GPT
- BEG
;
11540 if (Z
- GPT
< END_UNCHANGED
)
11541 END_UNCHANGED
= Z
- GPT
;
11544 /* The position of the first and last character that has been changed. */
11545 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11546 last_changed_charpos
= Z
- END_UNCHANGED
;
11548 /* If window starts after a line end, and the last change is in
11549 front of that newline, then changes don't affect the display.
11550 This case happens with stealth-fontification. Note that although
11551 the display is unchanged, glyph positions in the matrix have to
11552 be adjusted, of course. */
11553 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11554 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11555 && ((last_changed_charpos
< CHARPOS (start
)
11556 && CHARPOS (start
) == BEGV
)
11557 || (last_changed_charpos
< CHARPOS (start
) - 1
11558 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11560 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11561 struct glyph_row
*r0
;
11563 /* Compute how many chars/bytes have been added to or removed
11564 from the buffer. */
11565 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11566 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11568 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11570 /* Give up if PT is not in the window. Note that it already has
11571 been checked at the start of try_window_id that PT is not in
11572 front of the window start. */
11573 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11576 /* If window start is unchanged, we can reuse the whole matrix
11577 as is, after adjusting glyph positions. No need to compute
11578 the window end again, since its offset from Z hasn't changed. */
11579 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11580 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11581 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11583 /* Adjust positions in the glyph matrix. */
11584 if (delta
|| delta_bytes
)
11586 struct glyph_row
*r1
11587 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11588 increment_matrix_positions (w
->current_matrix
,
11589 MATRIX_ROW_VPOS (r0
, current_matrix
),
11590 MATRIX_ROW_VPOS (r1
, current_matrix
),
11591 delta
, delta_bytes
);
11594 /* Set the cursor. */
11595 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11596 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11601 /* Handle the case that changes are all below what is displayed in
11602 the window, and that PT is in the window. This shortcut cannot
11603 be taken if ZV is visible in the window, and text has been added
11604 there that is visible in the window. */
11605 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11606 /* ZV is not visible in the window, or there are no
11607 changes at ZV, actually. */
11608 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11609 || first_changed_charpos
== last_changed_charpos
))
11611 struct glyph_row
*r0
;
11613 /* Give up if PT is not in the window. Note that it already has
11614 been checked at the start of try_window_id that PT is not in
11615 front of the window start. */
11616 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11619 /* If window start is unchanged, we can reuse the whole matrix
11620 as is, without changing glyph positions since no text has
11621 been added/removed in front of the window end. */
11622 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11623 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11625 /* We have to compute the window end anew since text
11626 can have been added/removed after it. */
11628 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11629 w
->window_end_bytepos
11630 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11632 /* Set the cursor. */
11633 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11634 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11639 /* Give up if window start is in the changed area.
11641 The condition used to read
11643 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11645 but why that was tested escapes me at the moment. */
11646 if (CHARPOS (start
) >= first_changed_charpos
11647 && CHARPOS (start
) <= last_changed_charpos
)
11650 /* Check that window start agrees with the start of the first glyph
11651 row in its current matrix. Check this after we know the window
11652 start is not in changed text, otherwise positions would not be
11654 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11655 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11658 /* Give up if the window ends in strings. Overlay strings
11659 at the end are difficult to handle, so don't try. */
11660 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11661 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11664 /* Compute the position at which we have to start displaying new
11665 lines. Some of the lines at the top of the window might be
11666 reusable because they are not displaying changed text. Find the
11667 last row in W's current matrix not affected by changes at the
11668 start of current_buffer. Value is null if changes start in the
11669 first line of window. */
11670 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11671 if (last_unchanged_at_beg_row
)
11673 /* Avoid starting to display in the moddle of a character, a TAB
11674 for instance. This is easier than to set up the iterator
11675 exactly, and it's not a frequent case, so the additional
11676 effort wouldn't really pay off. */
11677 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11678 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11679 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11680 --last_unchanged_at_beg_row
;
11682 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11685 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11687 start_pos
= it
.current
.pos
;
11689 /* Start displaying new lines in the desired matrix at the same
11690 vpos we would use in the current matrix, i.e. below
11691 last_unchanged_at_beg_row. */
11692 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11694 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11695 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11697 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11701 /* There are no reusable lines at the start of the window.
11702 Start displaying in the first line. */
11703 start_display (&it
, w
, start
);
11704 start_pos
= it
.current
.pos
;
11707 /* Find the first row that is not affected by changes at the end of
11708 the buffer. Value will be null if there is no unchanged row, in
11709 which case we must redisplay to the end of the window. delta
11710 will be set to the value by which buffer positions beginning with
11711 first_unchanged_at_end_row have to be adjusted due to text
11713 first_unchanged_at_end_row
11714 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11715 IF_DEBUG (debug_delta
= delta
);
11716 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11718 /* Set stop_pos to the buffer position up to which we will have to
11719 display new lines. If first_unchanged_at_end_row != NULL, this
11720 is the buffer position of the start of the line displayed in that
11721 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11722 that we don't stop at a buffer position. */
11724 if (first_unchanged_at_end_row
)
11726 xassert (last_unchanged_at_beg_row
== NULL
11727 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11729 /* If this is a continuation line, move forward to the next one
11730 that isn't. Changes in lines above affect this line.
11731 Caution: this may move first_unchanged_at_end_row to a row
11732 not displaying text. */
11733 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11734 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11735 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11736 < it
.last_visible_y
))
11737 ++first_unchanged_at_end_row
;
11739 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11740 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11741 >= it
.last_visible_y
))
11742 first_unchanged_at_end_row
= NULL
;
11745 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11747 first_unchanged_at_end_vpos
11748 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11749 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11752 else if (last_unchanged_at_beg_row
== NULL
)
11758 /* Either there is no unchanged row at the end, or the one we have
11759 now displays text. This is a necessary condition for the window
11760 end pos calculation at the end of this function. */
11761 xassert (first_unchanged_at_end_row
== NULL
11762 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11764 debug_last_unchanged_at_beg_vpos
11765 = (last_unchanged_at_beg_row
11766 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11768 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11770 #endif /* GLYPH_DEBUG != 0 */
11773 /* Display new lines. Set last_text_row to the last new line
11774 displayed which has text on it, i.e. might end up as being the
11775 line where the window_end_vpos is. */
11776 w
->cursor
.vpos
= -1;
11777 last_text_row
= NULL
;
11778 overlay_arrow_seen
= 0;
11779 while (it
.current_y
< it
.last_visible_y
11780 && !fonts_changed_p
11781 && (first_unchanged_at_end_row
== NULL
11782 || IT_CHARPOS (it
) < stop_pos
))
11784 if (display_line (&it
))
11785 last_text_row
= it
.glyph_row
- 1;
11788 if (fonts_changed_p
)
11792 /* Compute differences in buffer positions, y-positions etc. for
11793 lines reused at the bottom of the window. Compute what we can
11795 if (first_unchanged_at_end_row
11796 /* No lines reused because we displayed everything up to the
11797 bottom of the window. */
11798 && it
.current_y
< it
.last_visible_y
)
11801 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11803 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11804 run
.current_y
= first_unchanged_at_end_row
->y
;
11805 run
.desired_y
= run
.current_y
+ dy
;
11806 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11810 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11811 first_unchanged_at_end_row
= NULL
;
11813 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11816 /* Find the cursor if not already found. We have to decide whether
11817 PT will appear on this window (it sometimes doesn't, but this is
11818 not a very frequent case.) This decision has to be made before
11819 the current matrix is altered. A value of cursor.vpos < 0 means
11820 that PT is either in one of the lines beginning at
11821 first_unchanged_at_end_row or below the window. Don't care for
11822 lines that might be displayed later at the window end; as
11823 mentioned, this is not a frequent case. */
11824 if (w
->cursor
.vpos
< 0)
11826 /* Cursor in unchanged rows at the top? */
11827 if (PT
< CHARPOS (start_pos
)
11828 && last_unchanged_at_beg_row
)
11830 row
= row_containing_pos (w
, PT
,
11831 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11832 last_unchanged_at_beg_row
+ 1, 0);
11834 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11837 /* Start from first_unchanged_at_end_row looking for PT. */
11838 else if (first_unchanged_at_end_row
)
11840 row
= row_containing_pos (w
, PT
- delta
,
11841 first_unchanged_at_end_row
, NULL
, 0);
11843 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11844 delta_bytes
, dy
, dvpos
);
11847 /* Give up if cursor was not found. */
11848 if (w
->cursor
.vpos
< 0)
11850 clear_glyph_matrix (w
->desired_matrix
);
11855 /* Don't let the cursor end in the scroll margins. */
11857 int this_scroll_margin
, cursor_height
;
11859 this_scroll_margin
= max (0, scroll_margin
);
11860 this_scroll_margin
= min (this_scroll_margin
,
11861 XFASTINT (w
->height
) / 4);
11862 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11863 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11865 if ((w
->cursor
.y
< this_scroll_margin
11866 && CHARPOS (start
) > BEGV
)
11867 /* Don't take scroll margin into account at the bottom because
11868 old redisplay didn't do it either. */
11869 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11871 w
->cursor
.vpos
= -1;
11872 clear_glyph_matrix (w
->desired_matrix
);
11877 /* Scroll the display. Do it before changing the current matrix so
11878 that xterm.c doesn't get confused about where the cursor glyph is
11880 if (dy
&& run
.height
)
11884 if (FRAME_WINDOW_P (f
))
11886 rif
->update_window_begin_hook (w
);
11887 rif
->clear_mouse_face (w
);
11888 rif
->scroll_run_hook (w
, &run
);
11889 rif
->update_window_end_hook (w
, 0, 0);
11893 /* Terminal frame. In this case, dvpos gives the number of
11894 lines to scroll by; dvpos < 0 means scroll up. */
11895 int first_unchanged_at_end_vpos
11896 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11897 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11898 int end
= (XFASTINT (w
->top
)
11899 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11900 + window_internal_height (w
));
11902 /* Perform the operation on the screen. */
11905 /* Scroll last_unchanged_at_beg_row to the end of the
11906 window down dvpos lines. */
11907 set_terminal_window (end
);
11909 /* On dumb terminals delete dvpos lines at the end
11910 before inserting dvpos empty lines. */
11911 if (!scroll_region_ok
)
11912 ins_del_lines (end
- dvpos
, -dvpos
);
11914 /* Insert dvpos empty lines in front of
11915 last_unchanged_at_beg_row. */
11916 ins_del_lines (from
, dvpos
);
11918 else if (dvpos
< 0)
11920 /* Scroll up last_unchanged_at_beg_vpos to the end of
11921 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11922 set_terminal_window (end
);
11924 /* Delete dvpos lines in front of
11925 last_unchanged_at_beg_vpos. ins_del_lines will set
11926 the cursor to the given vpos and emit |dvpos| delete
11928 ins_del_lines (from
+ dvpos
, dvpos
);
11930 /* On a dumb terminal insert dvpos empty lines at the
11932 if (!scroll_region_ok
)
11933 ins_del_lines (end
+ dvpos
, -dvpos
);
11936 set_terminal_window (0);
11942 /* Shift reused rows of the current matrix to the right position.
11943 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11945 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11946 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11949 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11950 bottom_vpos
, dvpos
);
11951 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11954 else if (dvpos
> 0)
11956 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11957 bottom_vpos
, dvpos
);
11958 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11959 first_unchanged_at_end_vpos
+ dvpos
, 0);
11962 /* For frame-based redisplay, make sure that current frame and window
11963 matrix are in sync with respect to glyph memory. */
11964 if (!FRAME_WINDOW_P (f
))
11965 sync_frame_with_window_matrix_rows (w
);
11967 /* Adjust buffer positions in reused rows. */
11969 increment_matrix_positions (current_matrix
,
11970 first_unchanged_at_end_vpos
+ dvpos
,
11971 bottom_vpos
, delta
, delta_bytes
);
11973 /* Adjust Y positions. */
11975 shift_glyph_matrix (w
, current_matrix
,
11976 first_unchanged_at_end_vpos
+ dvpos
,
11979 if (first_unchanged_at_end_row
)
11980 first_unchanged_at_end_row
+= dvpos
;
11982 /* If scrolling up, there may be some lines to display at the end of
11984 last_text_row_at_end
= NULL
;
11987 /* Scrolling up can leave for example a partially visible line
11988 at the end of the window to be redisplayed. */
11989 /* Set last_row to the glyph row in the current matrix where the
11990 window end line is found. It has been moved up or down in
11991 the matrix by dvpos. */
11992 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11993 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11995 /* If last_row is the window end line, it should display text. */
11996 xassert (last_row
->displays_text_p
);
11998 /* If window end line was partially visible before, begin
11999 displaying at that line. Otherwise begin displaying with the
12000 line following it. */
12001 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
12003 init_to_row_start (&it
, w
, last_row
);
12004 it
.vpos
= last_vpos
;
12005 it
.current_y
= last_row
->y
;
12009 init_to_row_end (&it
, w
, last_row
);
12010 it
.vpos
= 1 + last_vpos
;
12011 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
12015 /* We may start in a continuation line. If so, we have to
12016 get the right continuation_lines_width and current_x. */
12017 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
12018 it
.hpos
= it
.current_x
= 0;
12020 /* Display the rest of the lines at the window end. */
12021 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12022 while (it
.current_y
< it
.last_visible_y
12023 && !fonts_changed_p
)
12025 /* Is it always sure that the display agrees with lines in
12026 the current matrix? I don't think so, so we mark rows
12027 displayed invalid in the current matrix by setting their
12028 enabled_p flag to zero. */
12029 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
12030 if (display_line (&it
))
12031 last_text_row_at_end
= it
.glyph_row
- 1;
12035 /* Update window_end_pos and window_end_vpos. */
12036 if (first_unchanged_at_end_row
12037 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12038 && !last_text_row_at_end
)
12040 /* Window end line if one of the preserved rows from the current
12041 matrix. Set row to the last row displaying text in current
12042 matrix starting at first_unchanged_at_end_row, after
12044 xassert (first_unchanged_at_end_row
->displays_text_p
);
12045 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12046 first_unchanged_at_end_row
);
12047 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12049 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12050 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12052 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12053 xassert (w
->window_end_bytepos
>= 0);
12054 IF_DEBUG (debug_method_add (w
, "A"));
12056 else if (last_text_row_at_end
)
12059 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12060 w
->window_end_bytepos
12061 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12063 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12064 xassert (w
->window_end_bytepos
>= 0);
12065 IF_DEBUG (debug_method_add (w
, "B"));
12067 else if (last_text_row
)
12069 /* We have displayed either to the end of the window or at the
12070 end of the window, i.e. the last row with text is to be found
12071 in the desired matrix. */
12073 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12074 w
->window_end_bytepos
12075 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12077 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12078 xassert (w
->window_end_bytepos
>= 0);
12080 else if (first_unchanged_at_end_row
== NULL
12081 && last_text_row
== NULL
12082 && last_text_row_at_end
== NULL
)
12084 /* Displayed to end of window, but no line containing text was
12085 displayed. Lines were deleted at the end of the window. */
12086 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12087 int vpos
= XFASTINT (w
->window_end_vpos
);
12088 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12089 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12092 row
== NULL
&& vpos
>= first_vpos
;
12093 --vpos
, --current_row
, --desired_row
)
12095 if (desired_row
->enabled_p
)
12097 if (desired_row
->displays_text_p
)
12100 else if (current_row
->displays_text_p
)
12104 xassert (row
!= NULL
);
12105 w
->window_end_vpos
= make_number (vpos
+ 1);
12106 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12107 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12108 xassert (w
->window_end_bytepos
>= 0);
12109 IF_DEBUG (debug_method_add (w
, "C"));
12114 #if 0 /* This leads to problems, for instance when the cursor is
12115 at ZV, and the cursor line displays no text. */
12116 /* Disable rows below what's displayed in the window. This makes
12117 debugging easier. */
12118 enable_glyph_matrix_rows (current_matrix
,
12119 XFASTINT (w
->window_end_vpos
) + 1,
12123 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12124 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12126 /* Record that display has not been completed. */
12127 w
->window_end_valid
= Qnil
;
12128 w
->desired_matrix
->no_scrolling_p
= 1;
12136 /***********************************************************************
12137 More debugging support
12138 ***********************************************************************/
12142 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12143 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12144 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12147 /* Dump the contents of glyph matrix MATRIX on stderr.
12149 GLYPHS 0 means don't show glyph contents.
12150 GLYPHS 1 means show glyphs in short form
12151 GLYPHS > 1 means show glyphs in long form. */
12154 dump_glyph_matrix (matrix
, glyphs
)
12155 struct glyph_matrix
*matrix
;
12159 for (i
= 0; i
< matrix
->nrows
; ++i
)
12160 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12164 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12165 the glyph row and area where the glyph comes from. */
12168 dump_glyph (row
, glyph
, area
)
12169 struct glyph_row
*row
;
12170 struct glyph
*glyph
;
12173 if (glyph
->type
== CHAR_GLYPH
)
12176 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12177 glyph
- row
->glyphs
[TEXT_AREA
],
12180 (BUFFERP (glyph
->object
)
12182 : (STRINGP (glyph
->object
)
12185 glyph
->pixel_width
,
12187 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12191 glyph
->left_box_line_p
,
12192 glyph
->right_box_line_p
);
12194 else if (glyph
->type
== STRETCH_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
,
12210 glyph
->left_box_line_p
,
12211 glyph
->right_box_line_p
);
12213 else if (glyph
->type
== IMAGE_GLYPH
)
12216 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12217 glyph
- row
->glyphs
[TEXT_AREA
],
12220 (BUFFERP (glyph
->object
)
12222 : (STRINGP (glyph
->object
)
12225 glyph
->pixel_width
,
12229 glyph
->left_box_line_p
,
12230 glyph
->right_box_line_p
);
12235 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12236 GLYPHS 0 means don't show glyph contents.
12237 GLYPHS 1 means show glyphs in short form
12238 GLYPHS > 1 means show glyphs in long form. */
12241 dump_glyph_row (row
, vpos
, glyphs
)
12242 struct glyph_row
*row
;
12247 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12248 fprintf (stderr
, "=======================================================================\n");
12250 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12251 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12253 MATRIX_ROW_START_CHARPOS (row
),
12254 MATRIX_ROW_END_CHARPOS (row
),
12255 row
->used
[TEXT_AREA
],
12256 row
->contains_overlapping_glyphs_p
,
12258 row
->truncated_on_left_p
,
12259 row
->truncated_on_right_p
,
12260 row
->overlay_arrow_p
,
12262 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12263 row
->displays_text_p
,
12266 row
->ends_in_middle_of_char_p
,
12267 row
->starts_in_middle_of_char_p
,
12273 row
->visible_height
,
12276 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12277 row
->end
.overlay_string_index
,
12278 row
->continuation_lines_width
);
12279 fprintf (stderr
, "%9d %5d\n",
12280 CHARPOS (row
->start
.string_pos
),
12281 CHARPOS (row
->end
.string_pos
));
12282 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12283 row
->end
.dpvec_index
);
12290 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12292 struct glyph
*glyph
= row
->glyphs
[area
];
12293 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12295 /* Glyph for a line end in text. */
12296 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12299 if (glyph
< glyph_end
)
12300 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12302 for (; glyph
< glyph_end
; ++glyph
)
12303 dump_glyph (row
, glyph
, area
);
12306 else if (glyphs
== 1)
12310 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12312 char *s
= (char *) alloca (row
->used
[area
] + 1);
12315 for (i
= 0; i
< row
->used
[area
]; ++i
)
12317 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12318 if (glyph
->type
== CHAR_GLYPH
12319 && glyph
->u
.ch
< 0x80
12320 && glyph
->u
.ch
>= ' ')
12321 s
[i
] = glyph
->u
.ch
;
12327 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12333 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12334 Sdump_glyph_matrix
, 0, 1, "p",
12335 doc
: /* Dump the current matrix of the selected window to stderr.
12336 Shows contents of glyph row structures. With non-nil
12337 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12338 glyphs in short form, otherwise show glyphs in long form. */)
12340 Lisp_Object glyphs
;
12342 struct window
*w
= XWINDOW (selected_window
);
12343 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12345 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12346 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12347 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12348 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12349 fprintf (stderr
, "=============================================\n");
12350 dump_glyph_matrix (w
->current_matrix
,
12351 NILP (glyphs
) ? 0 : XINT (glyphs
));
12356 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12357 doc
: /* Dump glyph row ROW to stderr.
12358 GLYPH 0 means don't dump glyphs.
12359 GLYPH 1 means dump glyphs in short form.
12360 GLYPH > 1 or omitted means dump glyphs in long form. */)
12362 Lisp_Object row
, glyphs
;
12364 struct glyph_matrix
*matrix
;
12367 CHECK_NUMBER (row
);
12368 matrix
= XWINDOW (selected_window
)->current_matrix
;
12370 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12371 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12373 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12378 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12379 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12380 GLYPH 0 means don't dump glyphs.
12381 GLYPH 1 means dump glyphs in short form.
12382 GLYPH > 1 or omitted means dump glyphs in long form. */)
12384 Lisp_Object row
, glyphs
;
12386 struct frame
*sf
= SELECTED_FRAME ();
12387 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12390 CHECK_NUMBER (row
);
12392 if (vpos
>= 0 && vpos
< m
->nrows
)
12393 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12394 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12399 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12400 doc
: /* Toggle tracing of redisplay.
12401 With ARG, turn tracing on if and only if ARG is positive. */)
12406 trace_redisplay_p
= !trace_redisplay_p
;
12409 arg
= Fprefix_numeric_value (arg
);
12410 trace_redisplay_p
= XINT (arg
) > 0;
12417 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12418 doc
: /* Like `format', but print result to stderr. */)
12423 Lisp_Object s
= Fformat (nargs
, args
);
12424 fprintf (stderr
, "%s", XSTRING (s
)->data
);
12428 #endif /* GLYPH_DEBUG */
12432 /***********************************************************************
12433 Building Desired Matrix Rows
12434 ***********************************************************************/
12436 /* Return a temporary glyph row holding the glyphs of an overlay
12437 arrow. Only used for non-window-redisplay windows. */
12439 static struct glyph_row
*
12440 get_overlay_arrow_glyph_row (w
)
12443 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12444 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12445 struct buffer
*old
= current_buffer
;
12446 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
12447 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
12448 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12452 int n_glyphs_before
;
12454 set_buffer_temp (buffer
);
12455 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12456 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12457 SET_TEXT_POS (it
.position
, 0, 0);
12459 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12461 while (p
< arrow_end
)
12463 Lisp_Object face
, ilisp
;
12465 /* Get the next character. */
12467 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12469 it
.c
= *p
, it
.len
= 1;
12472 /* Get its face. */
12473 ilisp
= make_number (p
- arrow_string
);
12474 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12475 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12477 /* Compute its width, get its glyphs. */
12478 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12479 SET_TEXT_POS (it
.position
, -1, -1);
12480 PRODUCE_GLYPHS (&it
);
12482 /* If this character doesn't fit any more in the line, we have
12483 to remove some glyphs. */
12484 if (it
.current_x
> it
.last_visible_x
)
12486 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12491 set_buffer_temp (old
);
12492 return it
.glyph_row
;
12496 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12497 glyphs are only inserted for terminal frames since we can't really
12498 win with truncation glyphs when partially visible glyphs are
12499 involved. Which glyphs to insert is determined by
12500 produce_special_glyphs. */
12503 insert_left_trunc_glyphs (it
)
12506 struct it truncate_it
;
12507 struct glyph
*from
, *end
, *to
, *toend
;
12509 xassert (!FRAME_WINDOW_P (it
->f
));
12511 /* Get the truncation glyphs. */
12513 truncate_it
.current_x
= 0;
12514 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12515 truncate_it
.glyph_row
= &scratch_glyph_row
;
12516 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12517 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12518 truncate_it
.object
= make_number (0);
12519 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12521 /* Overwrite glyphs from IT with truncation glyphs. */
12522 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12523 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12524 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12525 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12530 /* There may be padding glyphs left over. Overwrite them too. */
12531 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12533 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12539 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12543 /* Compute the pixel height and width of IT->glyph_row.
12545 Most of the time, ascent and height of a display line will be equal
12546 to the max_ascent and max_height values of the display iterator
12547 structure. This is not the case if
12549 1. We hit ZV without displaying anything. In this case, max_ascent
12550 and max_height will be zero.
12552 2. We have some glyphs that don't contribute to the line height.
12553 (The glyph row flag contributes_to_line_height_p is for future
12554 pixmap extensions).
12556 The first case is easily covered by using default values because in
12557 these cases, the line height does not really matter, except that it
12558 must not be zero. */
12561 compute_line_metrics (it
)
12564 struct glyph_row
*row
= it
->glyph_row
;
12567 if (FRAME_WINDOW_P (it
->f
))
12569 int i
, min_y
, max_y
;
12571 /* The line may consist of one space only, that was added to
12572 place the cursor on it. If so, the row's height hasn't been
12574 if (row
->height
== 0)
12576 if (it
->max_ascent
+ it
->max_descent
== 0)
12577 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12578 row
->ascent
= it
->max_ascent
;
12579 row
->height
= it
->max_ascent
+ it
->max_descent
;
12580 row
->phys_ascent
= it
->max_phys_ascent
;
12581 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12584 /* Compute the width of this line. */
12585 row
->pixel_width
= row
->x
;
12586 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12587 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12589 xassert (row
->pixel_width
>= 0);
12590 xassert (row
->ascent
>= 0 && row
->height
> 0);
12592 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12593 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12595 /* If first line's physical ascent is larger than its logical
12596 ascent, use the physical ascent, and make the row taller.
12597 This makes accented characters fully visible. */
12598 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12599 && row
->phys_ascent
> row
->ascent
)
12601 row
->height
+= row
->phys_ascent
- row
->ascent
;
12602 row
->ascent
= row
->phys_ascent
;
12605 /* Compute how much of the line is visible. */
12606 row
->visible_height
= row
->height
;
12608 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12609 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12611 if (row
->y
< min_y
)
12612 row
->visible_height
-= min_y
- row
->y
;
12613 if (row
->y
+ row
->height
> max_y
)
12614 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12618 row
->pixel_width
= row
->used
[TEXT_AREA
];
12619 if (row
->continued_p
)
12620 row
->pixel_width
-= it
->continuation_pixel_width
;
12621 else if (row
->truncated_on_right_p
)
12622 row
->pixel_width
-= it
->truncation_pixel_width
;
12623 row
->ascent
= row
->phys_ascent
= 0;
12624 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12627 /* Compute a hash code for this row. */
12629 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12630 for (i
= 0; i
< row
->used
[area
]; ++i
)
12631 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12632 + row
->glyphs
[area
][i
].u
.val
12633 + row
->glyphs
[area
][i
].face_id
12634 + row
->glyphs
[area
][i
].padding_p
12635 + (row
->glyphs
[area
][i
].type
<< 2));
12637 it
->max_ascent
= it
->max_descent
= 0;
12638 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12642 /* Append one space to the glyph row of iterator IT if doing a
12643 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12644 space have the default face, otherwise let it have the same face as
12645 IT->face_id. Value is non-zero if a space was added.
12647 This function is called to make sure that there is always one glyph
12648 at the end of a glyph row that the cursor can be set on under
12649 window-systems. (If there weren't such a glyph we would not know
12650 how wide and tall a box cursor should be displayed).
12652 At the same time this space let's a nicely handle clearing to the
12653 end of the line if the row ends in italic text. */
12656 append_space (it
, default_face_p
)
12658 int default_face_p
;
12660 if (FRAME_WINDOW_P (it
->f
))
12662 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12664 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12665 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12667 /* Save some values that must not be changed.
12668 Must save IT->c and IT->len because otherwise
12669 ITERATOR_AT_END_P wouldn't work anymore after
12670 append_space has been called. */
12671 enum display_element_type saved_what
= it
->what
;
12672 int saved_c
= it
->c
, saved_len
= it
->len
;
12673 int saved_x
= it
->current_x
;
12674 int saved_face_id
= it
->face_id
;
12675 struct text_pos saved_pos
;
12676 Lisp_Object saved_object
;
12679 saved_object
= it
->object
;
12680 saved_pos
= it
->position
;
12682 it
->what
= IT_CHARACTER
;
12683 bzero (&it
->position
, sizeof it
->position
);
12684 it
->object
= make_number (0);
12688 if (default_face_p
)
12689 it
->face_id
= DEFAULT_FACE_ID
;
12690 else if (it
->face_before_selective_p
)
12691 it
->face_id
= it
->saved_face_id
;
12692 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12693 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12695 PRODUCE_GLYPHS (it
);
12697 it
->current_x
= saved_x
;
12698 it
->object
= saved_object
;
12699 it
->position
= saved_pos
;
12700 it
->what
= saved_what
;
12701 it
->face_id
= saved_face_id
;
12702 it
->len
= saved_len
;
12712 /* Extend the face of the last glyph in the text area of IT->glyph_row
12713 to the end of the display line. Called from display_line.
12714 If the glyph row is empty, add a space glyph to it so that we
12715 know the face to draw. Set the glyph row flag fill_line_p. */
12718 extend_face_to_end_of_line (it
)
12722 struct frame
*f
= it
->f
;
12724 /* If line is already filled, do nothing. */
12725 if (it
->current_x
>= it
->last_visible_x
)
12728 /* Face extension extends the background and box of IT->face_id
12729 to the end of the line. If the background equals the background
12730 of the frame, we don't have to do anything. */
12731 if (it
->face_before_selective_p
)
12732 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12734 face
= FACE_FROM_ID (f
, it
->face_id
);
12736 if (FRAME_WINDOW_P (f
)
12737 && face
->box
== FACE_NO_BOX
12738 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12742 /* Set the glyph row flag indicating that the face of the last glyph
12743 in the text area has to be drawn to the end of the text area. */
12744 it
->glyph_row
->fill_line_p
= 1;
12746 /* If current character of IT is not ASCII, make sure we have the
12747 ASCII face. This will be automatically undone the next time
12748 get_next_display_element returns a multibyte character. Note
12749 that the character will always be single byte in unibyte text. */
12750 if (!ASCII_CHAR_P (it
->c
))
12752 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12755 if (FRAME_WINDOW_P (f
))
12757 /* If the row is empty, add a space with the current face of IT,
12758 so that we know which face to draw. */
12759 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12761 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12762 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12763 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12768 /* Save some values that must not be changed. */
12769 int saved_x
= it
->current_x
;
12770 struct text_pos saved_pos
;
12771 Lisp_Object saved_object
;
12772 enum display_element_type saved_what
= it
->what
;
12773 int saved_face_id
= it
->face_id
;
12775 saved_object
= it
->object
;
12776 saved_pos
= it
->position
;
12778 it
->what
= IT_CHARACTER
;
12779 bzero (&it
->position
, sizeof it
->position
);
12780 it
->object
= make_number (0);
12783 it
->face_id
= face
->id
;
12785 PRODUCE_GLYPHS (it
);
12787 while (it
->current_x
<= it
->last_visible_x
)
12788 PRODUCE_GLYPHS (it
);
12790 /* Don't count these blanks really. It would let us insert a left
12791 truncation glyph below and make us set the cursor on them, maybe. */
12792 it
->current_x
= saved_x
;
12793 it
->object
= saved_object
;
12794 it
->position
= saved_pos
;
12795 it
->what
= saved_what
;
12796 it
->face_id
= saved_face_id
;
12801 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12802 trailing whitespace. */
12805 trailing_whitespace_p (charpos
)
12808 int bytepos
= CHAR_TO_BYTE (charpos
);
12811 while (bytepos
< ZV_BYTE
12812 && (c
= FETCH_CHAR (bytepos
),
12813 c
== ' ' || c
== '\t'))
12816 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12818 if (bytepos
!= PT_BYTE
)
12825 /* Highlight trailing whitespace, if any, in ROW. */
12828 highlight_trailing_whitespace (f
, row
)
12830 struct glyph_row
*row
;
12832 int used
= row
->used
[TEXT_AREA
];
12836 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12837 struct glyph
*glyph
= start
+ used
- 1;
12839 /* Skip over glyphs inserted to display the cursor at the
12840 end of a line, for extending the face of the last glyph
12841 to the end of the line on terminals, and for truncation
12842 and continuation glyphs. */
12843 while (glyph
>= start
12844 && glyph
->type
== CHAR_GLYPH
12845 && INTEGERP (glyph
->object
))
12848 /* If last glyph is a space or stretch, and it's trailing
12849 whitespace, set the face of all trailing whitespace glyphs in
12850 IT->glyph_row to `trailing-whitespace'. */
12852 && BUFFERP (glyph
->object
)
12853 && (glyph
->type
== STRETCH_GLYPH
12854 || (glyph
->type
== CHAR_GLYPH
12855 && glyph
->u
.ch
== ' '))
12856 && trailing_whitespace_p (glyph
->charpos
))
12858 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
);
12860 while (glyph
>= start
12861 && BUFFERP (glyph
->object
)
12862 && (glyph
->type
== STRETCH_GLYPH
12863 || (glyph
->type
== CHAR_GLYPH
12864 && glyph
->u
.ch
== ' ')))
12865 (glyph
--)->face_id
= face_id
;
12871 /* Value is non-zero if glyph row ROW in window W should be
12872 used to hold the cursor. */
12875 cursor_row_p (w
, row
)
12877 struct glyph_row
*row
;
12879 int cursor_row_p
= 1;
12881 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12883 /* If the row ends with a newline from a string, we don't want
12884 the cursor there (if the row is continued it doesn't end in a
12886 if (CHARPOS (row
->end
.string_pos
) >= 0
12887 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12888 cursor_row_p
= row
->continued_p
;
12890 /* If the row ends at ZV, display the cursor at the end of that
12891 row instead of at the start of the row below. */
12892 else if (row
->ends_at_zv_p
)
12898 return cursor_row_p
;
12902 /* Construct the glyph row IT->glyph_row in the desired matrix of
12903 IT->w from text at the current position of IT. See dispextern.h
12904 for an overview of struct it. Value is non-zero if
12905 IT->glyph_row displays text, as opposed to a line displaying ZV
12912 struct glyph_row
*row
= it
->glyph_row
;
12914 /* We always start displaying at hpos zero even if hscrolled. */
12915 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12917 /* We must not display in a row that's not a text row. */
12918 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12919 < it
->w
->desired_matrix
->nrows
);
12921 /* Is IT->w showing the region? */
12922 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12924 /* Clear the result glyph row and enable it. */
12925 prepare_desired_row (row
);
12927 row
->y
= it
->current_y
;
12928 row
->start
= it
->current
;
12929 row
->continuation_lines_width
= it
->continuation_lines_width
;
12930 row
->displays_text_p
= 1;
12931 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12932 it
->starts_in_middle_of_char_p
= 0;
12934 /* Arrange the overlays nicely for our purposes. Usually, we call
12935 display_line on only one line at a time, in which case this
12936 can't really hurt too much, or we call it on lines which appear
12937 one after another in the buffer, in which case all calls to
12938 recenter_overlay_lists but the first will be pretty cheap. */
12939 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12941 /* Move over display elements that are not visible because we are
12942 hscrolled. This may stop at an x-position < IT->first_visible_x
12943 if the first glyph is partially visible or if we hit a line end. */
12944 if (it
->current_x
< it
->first_visible_x
)
12945 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12946 MOVE_TO_POS
| MOVE_TO_X
);
12948 /* Get the initial row height. This is either the height of the
12949 text hscrolled, if there is any, or zero. */
12950 row
->ascent
= it
->max_ascent
;
12951 row
->height
= it
->max_ascent
+ it
->max_descent
;
12952 row
->phys_ascent
= it
->max_phys_ascent
;
12953 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12955 /* Loop generating characters. The loop is left with IT on the next
12956 character to display. */
12959 int n_glyphs_before
, hpos_before
, x_before
;
12961 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12963 /* Retrieve the next thing to display. Value is zero if end of
12965 if (!get_next_display_element (it
))
12967 /* Maybe add a space at the end of this line that is used to
12968 display the cursor there under X. Set the charpos of the
12969 first glyph of blank lines not corresponding to any text
12971 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12972 || row
->used
[TEXT_AREA
] == 0)
12974 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12975 row
->displays_text_p
= 0;
12977 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
12978 && (!MINI_WINDOW_P (it
->w
)
12979 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
12980 row
->indicate_empty_line_p
= 1;
12983 it
->continuation_lines_width
= 0;
12984 row
->ends_at_zv_p
= 1;
12988 /* Now, get the metrics of what we want to display. This also
12989 generates glyphs in `row' (which is IT->glyph_row). */
12990 n_glyphs_before
= row
->used
[TEXT_AREA
];
12993 /* Remember the line height so far in case the next element doesn't
12994 fit on the line. */
12995 if (!it
->truncate_lines_p
)
12997 ascent
= it
->max_ascent
;
12998 descent
= it
->max_descent
;
12999 phys_ascent
= it
->max_phys_ascent
;
13000 phys_descent
= it
->max_phys_descent
;
13003 PRODUCE_GLYPHS (it
);
13005 /* If this display element was in marginal areas, continue with
13007 if (it
->area
!= TEXT_AREA
)
13009 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13010 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13011 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13012 row
->phys_height
= max (row
->phys_height
,
13013 it
->max_phys_ascent
+ it
->max_phys_descent
);
13014 set_iterator_to_next (it
, 1);
13018 /* Does the display element fit on the line? If we truncate
13019 lines, we should draw past the right edge of the window. If
13020 we don't truncate, we want to stop so that we can display the
13021 continuation glyph before the right margin. If lines are
13022 continued, there are two possible strategies for characters
13023 resulting in more than 1 glyph (e.g. tabs): Display as many
13024 glyphs as possible in this line and leave the rest for the
13025 continuation line, or display the whole element in the next
13026 line. Original redisplay did the former, so we do it also. */
13027 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
13028 hpos_before
= it
->hpos
;
13031 if (/* Not a newline. */
13033 /* Glyphs produced fit entirely in the line. */
13034 && it
->current_x
< it
->last_visible_x
)
13036 it
->hpos
+= nglyphs
;
13037 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13038 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13039 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13040 row
->phys_height
= max (row
->phys_height
,
13041 it
->max_phys_ascent
+ it
->max_phys_descent
);
13042 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13043 row
->x
= x
- it
->first_visible_x
;
13048 struct glyph
*glyph
;
13050 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13052 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13053 new_x
= x
+ glyph
->pixel_width
;
13055 if (/* Lines are continued. */
13056 !it
->truncate_lines_p
13057 && (/* Glyph doesn't fit on the line. */
13058 new_x
> it
->last_visible_x
13059 /* Or it fits exactly on a window system frame. */
13060 || (new_x
== it
->last_visible_x
13061 && FRAME_WINDOW_P (it
->f
))))
13063 /* End of a continued line. */
13066 || (new_x
== it
->last_visible_x
13067 && FRAME_WINDOW_P (it
->f
)))
13069 /* Current glyph is the only one on the line or
13070 fits exactly on the line. We must continue
13071 the line because we can't draw the cursor
13072 after the glyph. */
13073 row
->continued_p
= 1;
13074 it
->current_x
= new_x
;
13075 it
->continuation_lines_width
+= new_x
;
13077 if (i
== nglyphs
- 1)
13078 set_iterator_to_next (it
, 1);
13080 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13081 && !FRAME_WINDOW_P (it
->f
))
13083 /* A padding glyph that doesn't fit on this line.
13084 This means the whole character doesn't fit
13086 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13088 /* Fill the rest of the row with continuation
13089 glyphs like in 20.x. */
13090 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13091 < row
->glyphs
[1 + TEXT_AREA
])
13092 produce_special_glyphs (it
, IT_CONTINUATION
);
13094 row
->continued_p
= 1;
13095 it
->current_x
= x_before
;
13096 it
->continuation_lines_width
+= x_before
;
13098 /* Restore the height to what it was before the
13099 element not fitting on the line. */
13100 it
->max_ascent
= ascent
;
13101 it
->max_descent
= descent
;
13102 it
->max_phys_ascent
= phys_ascent
;
13103 it
->max_phys_descent
= phys_descent
;
13105 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13107 /* A TAB that extends past the right edge of the
13108 window. This produces a single glyph on
13109 window system frames. We leave the glyph in
13110 this row and let it fill the row, but don't
13111 consume the TAB. */
13112 it
->continuation_lines_width
+= it
->last_visible_x
;
13113 row
->ends_in_middle_of_char_p
= 1;
13114 row
->continued_p
= 1;
13115 glyph
->pixel_width
= it
->last_visible_x
- x
;
13116 it
->starts_in_middle_of_char_p
= 1;
13120 /* Something other than a TAB that draws past
13121 the right edge of the window. Restore
13122 positions to values before the element. */
13123 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13125 /* Display continuation glyphs. */
13126 if (!FRAME_WINDOW_P (it
->f
))
13127 produce_special_glyphs (it
, IT_CONTINUATION
);
13128 row
->continued_p
= 1;
13130 it
->continuation_lines_width
+= x
;
13132 if (nglyphs
> 1 && i
> 0)
13134 row
->ends_in_middle_of_char_p
= 1;
13135 it
->starts_in_middle_of_char_p
= 1;
13138 /* Restore the height to what it was before the
13139 element not fitting on the line. */
13140 it
->max_ascent
= ascent
;
13141 it
->max_descent
= descent
;
13142 it
->max_phys_ascent
= phys_ascent
;
13143 it
->max_phys_descent
= phys_descent
;
13148 else if (new_x
> it
->first_visible_x
)
13150 /* Increment number of glyphs actually displayed. */
13153 if (x
< it
->first_visible_x
)
13154 /* Glyph is partially visible, i.e. row starts at
13155 negative X position. */
13156 row
->x
= x
- it
->first_visible_x
;
13160 /* Glyph is completely off the left margin of the
13161 window. This should not happen because of the
13162 move_it_in_display_line at the start of
13168 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13169 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13170 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13171 row
->phys_height
= max (row
->phys_height
,
13172 it
->max_phys_ascent
+ it
->max_phys_descent
);
13174 /* End of this display line if row is continued. */
13175 if (row
->continued_p
)
13179 /* Is this a line end? If yes, we're also done, after making
13180 sure that a non-default face is extended up to the right
13181 margin of the window. */
13182 if (ITERATOR_AT_END_OF_LINE_P (it
))
13184 int used_before
= row
->used
[TEXT_AREA
];
13186 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13188 /* Add a space at the end of the line that is used to
13189 display the cursor there. */
13190 append_space (it
, 0);
13192 /* Extend the face to the end of the line. */
13193 extend_face_to_end_of_line (it
);
13195 /* Make sure we have the position. */
13196 if (used_before
== 0)
13197 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13199 /* Consume the line end. This skips over invisible lines. */
13200 set_iterator_to_next (it
, 1);
13201 it
->continuation_lines_width
= 0;
13205 /* Proceed with next display element. Note that this skips
13206 over lines invisible because of selective display. */
13207 set_iterator_to_next (it
, 1);
13209 /* If we truncate lines, we are done when the last displayed
13210 glyphs reach past the right margin of the window. */
13211 if (it
->truncate_lines_p
13212 && (FRAME_WINDOW_P (it
->f
)
13213 ? (it
->current_x
>= it
->last_visible_x
)
13214 : (it
->current_x
> it
->last_visible_x
)))
13216 /* Maybe add truncation glyphs. */
13217 if (!FRAME_WINDOW_P (it
->f
))
13221 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13222 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13225 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13227 row
->used
[TEXT_AREA
] = i
;
13228 produce_special_glyphs (it
, IT_TRUNCATION
);
13232 row
->truncated_on_right_p
= 1;
13233 it
->continuation_lines_width
= 0;
13234 reseat_at_next_visible_line_start (it
, 0);
13235 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13236 it
->hpos
= hpos_before
;
13237 it
->current_x
= x_before
;
13242 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13243 at the left window margin. */
13244 if (it
->first_visible_x
13245 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13247 if (!FRAME_WINDOW_P (it
->f
))
13248 insert_left_trunc_glyphs (it
);
13249 row
->truncated_on_left_p
= 1;
13252 /* If the start of this line is the overlay arrow-position, then
13253 mark this glyph row as the one containing the overlay arrow.
13254 This is clearly a mess with variable size fonts. It would be
13255 better to let it be displayed like cursors under X. */
13256 if (MARKERP (Voverlay_arrow_position
)
13257 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13258 && (MATRIX_ROW_START_CHARPOS (row
)
13259 == marker_position (Voverlay_arrow_position
))
13260 && STRINGP (Voverlay_arrow_string
)
13261 && ! overlay_arrow_seen
)
13263 /* Overlay arrow in window redisplay is a fringe bitmap. */
13264 if (!FRAME_WINDOW_P (it
->f
))
13266 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13267 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13268 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13269 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13270 struct glyph
*p2
, *end
;
13272 /* Copy the arrow glyphs. */
13273 while (glyph
< arrow_end
)
13276 /* Throw away padding glyphs. */
13278 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13279 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13285 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13289 overlay_arrow_seen
= 1;
13290 row
->overlay_arrow_p
= 1;
13293 /* Compute pixel dimensions of this line. */
13294 compute_line_metrics (it
);
13296 /* Remember the position at which this line ends. */
13297 row
->end
= it
->current
;
13299 /* Maybe set the cursor. */
13300 if (it
->w
->cursor
.vpos
< 0
13301 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13302 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13303 && cursor_row_p (it
->w
, row
))
13304 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13306 /* Highlight trailing whitespace. */
13307 if (!NILP (Vshow_trailing_whitespace
))
13308 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13310 /* Prepare for the next line. This line starts horizontally at (X
13311 HPOS) = (0 0). Vertical positions are incremented. As a
13312 convenience for the caller, IT->glyph_row is set to the next
13314 it
->current_x
= it
->hpos
= 0;
13315 it
->current_y
+= row
->height
;
13318 return row
->displays_text_p
;
13323 /***********************************************************************
13325 ***********************************************************************/
13327 /* Redisplay the menu bar in the frame for window W.
13329 The menu bar of X frames that don't have X toolkit support is
13330 displayed in a special window W->frame->menu_bar_window.
13332 The menu bar of terminal frames is treated specially as far as
13333 glyph matrices are concerned. Menu bar lines are not part of
13334 windows, so the update is done directly on the frame matrix rows
13335 for the menu bar. */
13338 display_menu_bar (w
)
13341 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13346 /* Don't do all this for graphical frames. */
13348 if (!NILP (Vwindow_system
))
13351 #ifdef USE_X_TOOLKIT
13356 if (FRAME_MAC_P (f
))
13360 #ifdef USE_X_TOOLKIT
13361 xassert (!FRAME_WINDOW_P (f
));
13362 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13363 it
.first_visible_x
= 0;
13364 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13365 #else /* not USE_X_TOOLKIT */
13366 if (FRAME_WINDOW_P (f
))
13368 /* Menu bar lines are displayed in the desired matrix of the
13369 dummy window menu_bar_window. */
13370 struct window
*menu_w
;
13371 xassert (WINDOWP (f
->menu_bar_window
));
13372 menu_w
= XWINDOW (f
->menu_bar_window
);
13373 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13375 it
.first_visible_x
= 0;
13376 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13380 /* This is a TTY frame, i.e. character hpos/vpos are used as
13382 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13384 it
.first_visible_x
= 0;
13385 it
.last_visible_x
= FRAME_WIDTH (f
);
13387 #endif /* not USE_X_TOOLKIT */
13389 if (! mode_line_inverse_video
)
13390 /* Force the menu-bar to be displayed in the default face. */
13391 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13393 /* Clear all rows of the menu bar. */
13394 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13396 struct glyph_row
*row
= it
.glyph_row
+ i
;
13397 clear_glyph_row (row
);
13398 row
->enabled_p
= 1;
13399 row
->full_width_p
= 1;
13402 /* Display all items of the menu bar. */
13403 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13404 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13406 Lisp_Object string
;
13408 /* Stop at nil string. */
13409 string
= AREF (items
, i
+ 1);
13413 /* Remember where item was displayed. */
13414 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13416 /* Display the item, pad with one space. */
13417 if (it
.current_x
< it
.last_visible_x
)
13418 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13419 XSTRING (string
)->size
+ 1, 0, 0, -1);
13422 /* Fill out the line with spaces. */
13423 if (it
.current_x
< it
.last_visible_x
)
13424 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13426 /* Compute the total height of the lines. */
13427 compute_line_metrics (&it
);
13432 /***********************************************************************
13434 ***********************************************************************/
13436 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13437 FORCE is non-zero, redisplay mode lines unconditionally.
13438 Otherwise, redisplay only mode lines that are garbaged. Value is
13439 the number of windows whose mode lines were redisplayed. */
13442 redisplay_mode_lines (window
, force
)
13443 Lisp_Object window
;
13448 while (!NILP (window
))
13450 struct window
*w
= XWINDOW (window
);
13452 if (WINDOWP (w
->hchild
))
13453 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13454 else if (WINDOWP (w
->vchild
))
13455 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13457 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13458 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13460 struct text_pos lpoint
;
13461 struct buffer
*old
= current_buffer
;
13463 /* Set the window's buffer for the mode line display. */
13464 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13465 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13467 /* Point refers normally to the selected window. For any
13468 other window, set up appropriate value. */
13469 if (!EQ (window
, selected_window
))
13471 struct text_pos pt
;
13473 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13474 if (CHARPOS (pt
) < BEGV
)
13475 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13476 else if (CHARPOS (pt
) > (ZV
- 1))
13477 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13479 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13482 /* Display mode lines. */
13483 clear_glyph_matrix (w
->desired_matrix
);
13484 if (display_mode_lines (w
))
13487 w
->must_be_updated_p
= 1;
13490 /* Restore old settings. */
13491 set_buffer_internal_1 (old
);
13492 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13502 /* Display the mode and/or top line of window W. Value is the number
13503 of mode lines displayed. */
13506 display_mode_lines (w
)
13509 Lisp_Object old_selected_window
, old_selected_frame
;
13512 old_selected_frame
= selected_frame
;
13513 selected_frame
= w
->frame
;
13514 old_selected_window
= selected_window
;
13515 XSETWINDOW (selected_window
, w
);
13517 /* These will be set while the mode line specs are processed. */
13518 line_number_displayed
= 0;
13519 w
->column_number_displayed
= Qnil
;
13521 if (WINDOW_WANTS_MODELINE_P (w
))
13523 struct window
*sel_w
= XWINDOW (old_selected_window
);
13525 /* Select mode line face based on the real selected window. */
13526 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
13527 current_buffer
->mode_line_format
);
13531 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13533 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13534 current_buffer
->header_line_format
);
13538 selected_frame
= old_selected_frame
;
13539 selected_window
= old_selected_window
;
13544 /* Display mode or top line of window W. FACE_ID specifies which line
13545 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13546 FORMAT is the mode line format to display. Value is the pixel
13547 height of the mode line displayed. */
13550 display_mode_line (w
, face_id
, format
)
13552 enum face_id face_id
;
13553 Lisp_Object format
;
13558 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13559 prepare_desired_row (it
.glyph_row
);
13561 if (! mode_line_inverse_video
)
13562 /* Force the mode-line to be displayed in the default face. */
13563 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13565 /* Temporarily make frame's keyboard the current kboard so that
13566 kboard-local variables in the mode_line_format will get the right
13568 push_frame_kboard (it
.f
);
13569 display_mode_element (&it
, 0, 0, 0, format
, Qnil
);
13570 pop_frame_kboard ();
13572 /* Fill up with spaces. */
13573 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13575 compute_line_metrics (&it
);
13576 it
.glyph_row
->full_width_p
= 1;
13577 it
.glyph_row
->mode_line_p
= 1;
13578 it
.glyph_row
->continued_p
= 0;
13579 it
.glyph_row
->truncated_on_left_p
= 0;
13580 it
.glyph_row
->truncated_on_right_p
= 0;
13582 /* Make a 3D mode-line have a shadow at its right end. */
13583 face
= FACE_FROM_ID (it
.f
, face_id
);
13584 extend_face_to_end_of_line (&it
);
13585 if (face
->box
!= FACE_NO_BOX
)
13587 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13588 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13589 last
->right_box_line_p
= 1;
13592 return it
.glyph_row
->height
;
13595 /* Alist that caches the results of :propertize.
13596 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
13597 Lisp_Object mode_line_proptrans_alist
;
13599 /* Contribute ELT to the mode line for window IT->w. How it
13600 translates into text depends on its data type.
13602 IT describes the display environment in which we display, as usual.
13604 DEPTH is the depth in recursion. It is used to prevent
13605 infinite recursion here.
13607 FIELD_WIDTH is the number of characters the display of ELT should
13608 occupy in the mode line, and PRECISION is the maximum number of
13609 characters to display from ELT's representation. See
13610 display_string for details.
13612 Returns the hpos of the end of the text generated by ELT. */
13615 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
)
13618 int field_width
, precision
;
13619 Lisp_Object elt
, props
;
13621 int n
= 0, field
, prec
;
13630 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13634 /* A string: output it and check for %-constructs within it. */
13636 unsigned char *this = XSTRING (elt
)->data
;
13637 unsigned char *lisp_string
= this;
13641 Lisp_Object oprops
, aelt
;
13642 oprops
= Ftext_properties_at (make_number (0), elt
);
13643 if (NILP (Fequal (props
, oprops
)))
13645 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
13646 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
13650 elt
= Fcopy_sequence (elt
);
13651 Fset_text_properties (make_number (0), Flength (elt
),
13653 mode_line_proptrans_alist
13654 = Fcons (Fcons (elt
, props
),
13655 mode_line_proptrans_alist
);
13658 this = XSTRING (elt
)->data
;
13659 lisp_string
= this;
13664 prec
= precision
- n
;
13665 if (frame_title_ptr
)
13666 n
+= store_frame_title (XSTRING (elt
)->data
, -1, prec
);
13668 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
13669 0, prec
, 0, STRING_MULTIBYTE (elt
));
13674 while ((precision
<= 0 || n
< precision
)
13676 && (frame_title_ptr
13677 || it
->current_x
< it
->last_visible_x
))
13679 unsigned char *last
= this;
13681 /* Advance to end of string or next format specifier. */
13682 while ((c
= *this++) != '\0' && c
!= '%')
13685 if (this - 1 != last
)
13687 /* Output to end of string or up to '%'. Field width
13688 is length of string. Don't output more than
13689 PRECISION allows us. */
13692 prec
= chars_in_text (last
, this - last
);
13693 if (precision
> 0 && prec
> precision
- n
)
13694 prec
= precision
- n
;
13696 if (frame_title_ptr
)
13697 n
+= store_frame_title (last
, 0, prec
);
13700 int bytepos
= last
- lisp_string
;
13701 int charpos
= string_byte_to_char (elt
, bytepos
);
13702 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13704 STRING_MULTIBYTE (elt
));
13707 else /* c == '%' */
13709 unsigned char *percent_position
= this;
13711 /* Get the specified minimum width. Zero means
13714 while ((c
= *this++) >= '0' && c
<= '9')
13715 field
= field
* 10 + c
- '0';
13717 /* Don't pad beyond the total padding allowed. */
13718 if (field_width
- n
> 0 && field
> field_width
- n
)
13719 field
= field_width
- n
;
13721 /* Note that either PRECISION <= 0 or N < PRECISION. */
13722 prec
= precision
- n
;
13725 n
+= display_mode_element (it
, depth
, field
, prec
,
13726 Vglobal_mode_string
, props
);
13730 unsigned char *spec
13731 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13733 if (frame_title_ptr
)
13734 n
+= store_frame_title (spec
, field
, prec
);
13737 int nglyphs_before
, bytepos
, charpos
, nwritten
;
13739 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13740 bytepos
= percent_position
- lisp_string
;
13741 charpos
= (STRING_MULTIBYTE (elt
)
13742 ? string_byte_to_char (elt
, bytepos
)
13744 nwritten
= display_string (spec
, Qnil
, elt
,
13749 /* Assign to the glyphs written above the
13750 string where the `%x' came from, position
13754 struct glyph
*glyph
13755 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13759 for (i
= 0; i
< nwritten
; ++i
)
13761 glyph
[i
].object
= elt
;
13762 glyph
[i
].charpos
= charpos
;
13777 /* A symbol: process the value of the symbol recursively
13778 as if it appeared here directly. Avoid error if symbol void.
13779 Special case: if value of symbol is a string, output the string
13782 register Lisp_Object tem
;
13783 tem
= Fboundp (elt
);
13786 tem
= Fsymbol_value (elt
);
13787 /* If value is a string, output that string literally:
13788 don't check for % within it. */
13792 if (!EQ (tem
, elt
))
13794 /* Give up right away for nil or t. */
13804 register Lisp_Object car
, tem
;
13806 /* A cons cell: five distinct cases.
13807 If first element is :eval or :propertize, do something special.
13808 If first element is a string or a cons, process all the elements
13809 and effectively concatenate them.
13810 If first element is a negative number, truncate displaying cdr to
13811 at most that many characters. If positive, pad (with spaces)
13812 to at least that many characters.
13813 If first element is a symbol, process the cadr or caddr recursively
13814 according to whether the symbol's value is non-nil or nil. */
13816 if (EQ (car
, QCeval
))
13818 /* An element of the form (:eval FORM) means evaluate FORM
13819 and use the result as mode line elements. */
13821 if (CONSP (XCDR (elt
)))
13824 spec
= safe_eval (XCAR (XCDR (elt
)));
13825 n
+= display_mode_element (it
, depth
, field_width
- n
,
13826 precision
- n
, spec
, props
);
13829 else if (EQ (car
, QCpropertize
))
13831 if (CONSP (XCDR (elt
)))
13833 /* An element of the form (:propertize ELT PROPS...)
13834 means display ELT but applying properties PROPS. */
13835 n
+= display_mode_element (it
, depth
, field_width
- n
,
13836 precision
- n
, XCAR (XCDR (elt
)),
13837 XCDR (XCDR (elt
)));
13840 else if (SYMBOLP (car
))
13842 tem
= Fboundp (car
);
13846 /* elt is now the cdr, and we know it is a cons cell.
13847 Use its car if CAR has a non-nil value. */
13850 tem
= Fsymbol_value (car
);
13857 /* Symbol's value is nil (or symbol is unbound)
13858 Get the cddr of the original list
13859 and if possible find the caddr and use that. */
13863 else if (!CONSP (elt
))
13868 else if (INTEGERP (car
))
13870 register int lim
= XINT (car
);
13874 /* Negative int means reduce maximum width. */
13875 if (precision
<= 0)
13878 precision
= min (precision
, -lim
);
13882 /* Padding specified. Don't let it be more than
13883 current maximum. */
13885 lim
= min (precision
, lim
);
13887 /* If that's more padding than already wanted, queue it.
13888 But don't reduce padding already specified even if
13889 that is beyond the current truncation point. */
13890 field_width
= max (lim
, field_width
);
13894 else if (STRINGP (car
) || CONSP (car
))
13896 register int limit
= 50;
13897 /* Limit is to protect against circular lists. */
13900 && (precision
<= 0 || n
< precision
))
13902 n
+= display_mode_element (it
, depth
, field_width
- n
,
13903 precision
- n
, XCAR (elt
), props
);
13912 if (frame_title_ptr
)
13913 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13915 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13916 precision
- n
, 0, 0);
13920 /* Pad to FIELD_WIDTH. */
13921 if (field_width
> 0 && n
< field_width
)
13923 if (frame_title_ptr
)
13924 n
+= store_frame_title ("", field_width
- n
, 0);
13926 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13934 /* Write a null-terminated, right justified decimal representation of
13935 the positive integer D to BUF using a minimal field width WIDTH. */
13938 pint2str (buf
, width
, d
)
13939 register char *buf
;
13940 register int width
;
13943 register char *p
= buf
;
13951 *p
++ = d
% 10 + '0';
13956 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13967 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13968 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13969 type of CODING_SYSTEM. Return updated pointer into BUF. */
13971 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13974 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13975 Lisp_Object coding_system
;
13976 register char *buf
;
13980 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13981 unsigned char *eol_str
;
13983 /* The EOL conversion we are using. */
13984 Lisp_Object eoltype
;
13986 val
= CODING_SYSTEM_SPEC (coding_system
);
13989 if (!VECTORP (val
)) /* Not yet decided. */
13994 eoltype
= eol_mnemonic_undecided
;
13995 /* Don't mention EOL conversion if it isn't decided. */
14000 Lisp_Object eolvalue
;
14002 attrs
= AREF (val
, 0);
14003 eolvalue
= AREF (val
, 2);
14006 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
14010 /* The EOL conversion that is normal on this system. */
14012 if (NILP (eolvalue
)) /* Not yet decided. */
14013 eoltype
= eol_mnemonic_undecided
;
14014 else if (VECTORP (eolvalue
)) /* Not yet decided. */
14015 eoltype
= eol_mnemonic_undecided
;
14016 else /* eolvalue is Qunix, Qdos, or Qmac. */
14017 eoltype
= (EQ (eolvalue
, Qunix
)
14018 ? eol_mnemonic_unix
14019 : (EQ (eolvalue
, Qdos
) == 1
14020 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
14026 /* Mention the EOL conversion if it is not the usual one. */
14027 if (STRINGP (eoltype
))
14029 eol_str
= XSTRING (eoltype
)->data
;
14030 eol_str_len
= XSTRING (eoltype
)->size
;
14032 else if (CHARACTERP (eoltype
))
14034 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
14035 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
14039 eol_str
= invalid_eol_type
;
14040 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14042 bcopy (eol_str
, buf
, eol_str_len
);
14043 buf
+= eol_str_len
;
14049 /* Return a string for the output of a mode line %-spec for window W,
14050 generated by character C. PRECISION >= 0 means don't return a
14051 string longer than that value. FIELD_WIDTH > 0 means pad the
14052 string returned with spaces to that value. Return 1 in *MULTIBYTE
14053 if the result is multibyte text. */
14055 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14058 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14061 int field_width
, precision
;
14065 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14066 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14067 struct buffer
*b
= XBUFFER (w
->buffer
);
14075 if (!NILP (b
->read_only
))
14077 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14082 /* This differs from %* only for a modified read-only buffer. */
14083 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14085 if (!NILP (b
->read_only
))
14090 /* This differs from %* in ignoring read-only-ness. */
14091 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14103 if (command_loop_level
> 5)
14105 p
= decode_mode_spec_buf
;
14106 for (i
= 0; i
< command_loop_level
; i
++)
14109 return decode_mode_spec_buf
;
14117 if (command_loop_level
> 5)
14119 p
= decode_mode_spec_buf
;
14120 for (i
= 0; i
< command_loop_level
; i
++)
14123 return decode_mode_spec_buf
;
14130 /* Let lots_of_dashes be a string of infinite length. */
14131 if (field_width
<= 0
14132 || field_width
> sizeof (lots_of_dashes
))
14134 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
14135 decode_mode_spec_buf
[i
] = '-';
14136 decode_mode_spec_buf
[i
] = '\0';
14137 return decode_mode_spec_buf
;
14140 return lots_of_dashes
;
14149 int col
= current_column ();
14150 w
->column_number_displayed
= make_number (col
);
14151 pint2str (decode_mode_spec_buf
, field_width
, col
);
14152 return decode_mode_spec_buf
;
14156 /* %F displays the frame name. */
14157 if (!NILP (f
->title
))
14158 return (char *) XSTRING (f
->title
)->data
;
14159 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14160 return (char *) XSTRING (f
->name
)->data
;
14169 int startpos
= XMARKER (w
->start
)->charpos
;
14170 int startpos_byte
= marker_byte_position (w
->start
);
14171 int line
, linepos
, linepos_byte
, topline
;
14173 int height
= XFASTINT (w
->height
);
14175 /* If we decided that this buffer isn't suitable for line numbers,
14176 don't forget that too fast. */
14177 if (EQ (w
->base_line_pos
, w
->buffer
))
14179 /* But do forget it, if the window shows a different buffer now. */
14180 else if (BUFFERP (w
->base_line_pos
))
14181 w
->base_line_pos
= Qnil
;
14183 /* If the buffer is very big, don't waste time. */
14184 if (INTEGERP (Vline_number_display_limit
)
14185 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14187 w
->base_line_pos
= Qnil
;
14188 w
->base_line_number
= Qnil
;
14192 if (!NILP (w
->base_line_number
)
14193 && !NILP (w
->base_line_pos
)
14194 && XFASTINT (w
->base_line_pos
) <= startpos
)
14196 line
= XFASTINT (w
->base_line_number
);
14197 linepos
= XFASTINT (w
->base_line_pos
);
14198 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14203 linepos
= BUF_BEGV (b
);
14204 linepos_byte
= BUF_BEGV_BYTE (b
);
14207 /* Count lines from base line to window start position. */
14208 nlines
= display_count_lines (linepos
, linepos_byte
,
14212 topline
= nlines
+ line
;
14214 /* Determine a new base line, if the old one is too close
14215 or too far away, or if we did not have one.
14216 "Too close" means it's plausible a scroll-down would
14217 go back past it. */
14218 if (startpos
== BUF_BEGV (b
))
14220 w
->base_line_number
= make_number (topline
);
14221 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14223 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14224 || linepos
== BUF_BEGV (b
))
14226 int limit
= BUF_BEGV (b
);
14227 int limit_byte
= BUF_BEGV_BYTE (b
);
14229 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14231 if (startpos
- distance
> limit
)
14233 limit
= startpos
- distance
;
14234 limit_byte
= CHAR_TO_BYTE (limit
);
14237 nlines
= display_count_lines (startpos
, startpos_byte
,
14239 - (height
* 2 + 30),
14241 /* If we couldn't find the lines we wanted within
14242 line_number_display_limit_width chars per line,
14243 give up on line numbers for this window. */
14244 if (position
== limit_byte
&& limit
== startpos
- distance
)
14246 w
->base_line_pos
= w
->buffer
;
14247 w
->base_line_number
= Qnil
;
14251 w
->base_line_number
= make_number (topline
- nlines
);
14252 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14255 /* Now count lines from the start pos to point. */
14256 nlines
= display_count_lines (startpos
, startpos_byte
,
14257 PT_BYTE
, PT
, &junk
);
14259 /* Record that we did display the line number. */
14260 line_number_displayed
= 1;
14262 /* Make the string to show. */
14263 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14264 return decode_mode_spec_buf
;
14267 char* p
= decode_mode_spec_buf
;
14268 int pad
= field_width
- 2;
14274 return decode_mode_spec_buf
;
14280 obj
= b
->mode_name
;
14284 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14290 int pos
= marker_position (w
->start
);
14291 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14293 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14295 if (pos
<= BUF_BEGV (b
))
14300 else if (pos
<= BUF_BEGV (b
))
14304 if (total
> 1000000)
14305 /* Do it differently for a large value, to avoid overflow. */
14306 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14308 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14309 /* We can't normally display a 3-digit number,
14310 so get us a 2-digit number that is close. */
14313 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14314 return decode_mode_spec_buf
;
14318 /* Display percentage of size above the bottom of the screen. */
14321 int toppos
= marker_position (w
->start
);
14322 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14323 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14325 if (botpos
>= BUF_ZV (b
))
14327 if (toppos
<= BUF_BEGV (b
))
14334 if (total
> 1000000)
14335 /* Do it differently for a large value, to avoid overflow. */
14336 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14338 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14339 /* We can't normally display a 3-digit number,
14340 so get us a 2-digit number that is close. */
14343 if (toppos
<= BUF_BEGV (b
))
14344 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14346 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14347 return decode_mode_spec_buf
;
14352 /* status of process */
14353 obj
= Fget_buffer_process (w
->buffer
);
14355 return "no process";
14356 #ifdef subprocesses
14357 obj
= Fsymbol_name (Fprocess_status (obj
));
14361 case 't': /* indicate TEXT or BINARY */
14362 #ifdef MODE_LINE_BINARY_TEXT
14363 return MODE_LINE_BINARY_TEXT (b
);
14369 /* coding-system (not including end-of-line format) */
14371 /* coding-system (including end-of-line type) */
14373 int eol_flag
= (c
== 'Z');
14374 char *p
= decode_mode_spec_buf
;
14376 if (! FRAME_WINDOW_P (f
))
14378 /* No need to mention EOL here--the terminal never needs
14379 to do EOL conversion. */
14380 p
= decode_mode_spec_coding (CODING_ID_NAME (keyboard_coding
.id
),
14382 p
= decode_mode_spec_coding (CODING_ID_NAME (terminal_coding
.id
),
14385 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14388 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14389 #ifdef subprocesses
14390 obj
= Fget_buffer_process (Fcurrent_buffer ());
14391 if (PROCESSP (obj
))
14393 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14395 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14398 #endif /* subprocesses */
14401 return decode_mode_spec_buf
;
14407 *multibyte
= STRING_MULTIBYTE (obj
);
14408 return (char *) XSTRING (obj
)->data
;
14415 /* Count up to COUNT lines starting from START / START_BYTE.
14416 But don't go beyond LIMIT_BYTE.
14417 Return the number of lines thus found (always nonnegative).
14419 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14422 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14423 int start
, start_byte
, limit_byte
, count
;
14426 register unsigned char *cursor
;
14427 unsigned char *base
;
14429 register int ceiling
;
14430 register unsigned char *ceiling_addr
;
14431 int orig_count
= count
;
14433 /* If we are not in selective display mode,
14434 check only for newlines. */
14435 int selective_display
= (!NILP (current_buffer
->selective_display
)
14436 && !INTEGERP (current_buffer
->selective_display
));
14440 while (start_byte
< limit_byte
)
14442 ceiling
= BUFFER_CEILING_OF (start_byte
);
14443 ceiling
= min (limit_byte
- 1, ceiling
);
14444 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14445 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14448 if (selective_display
)
14449 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14452 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14455 if (cursor
!= ceiling_addr
)
14459 start_byte
+= cursor
- base
+ 1;
14460 *byte_pos_ptr
= start_byte
;
14464 if (++cursor
== ceiling_addr
)
14470 start_byte
+= cursor
- base
;
14475 while (start_byte
> limit_byte
)
14477 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14478 ceiling
= max (limit_byte
, ceiling
);
14479 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14480 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14483 if (selective_display
)
14484 while (--cursor
!= ceiling_addr
14485 && *cursor
!= '\n' && *cursor
!= 015)
14488 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14491 if (cursor
!= ceiling_addr
)
14495 start_byte
+= cursor
- base
+ 1;
14496 *byte_pos_ptr
= start_byte
;
14497 /* When scanning backwards, we should
14498 not count the newline posterior to which we stop. */
14499 return - orig_count
- 1;
14505 /* Here we add 1 to compensate for the last decrement
14506 of CURSOR, which took it past the valid range. */
14507 start_byte
+= cursor
- base
+ 1;
14511 *byte_pos_ptr
= limit_byte
;
14514 return - orig_count
+ count
;
14515 return orig_count
- count
;
14521 /***********************************************************************
14523 ***********************************************************************/
14525 /* Display a NUL-terminated string, starting with index START.
14527 If STRING is non-null, display that C string. Otherwise, the Lisp
14528 string LISP_STRING is displayed.
14530 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14531 FACE_STRING. Display STRING or LISP_STRING with the face at
14532 FACE_STRING_POS in FACE_STRING:
14534 Display the string in the environment given by IT, but use the
14535 standard display table, temporarily.
14537 FIELD_WIDTH is the minimum number of output glyphs to produce.
14538 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14539 with spaces. If STRING has more characters, more than FIELD_WIDTH
14540 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14542 PRECISION is the maximum number of characters to output from
14543 STRING. PRECISION < 0 means don't truncate the string.
14545 This is roughly equivalent to printf format specifiers:
14547 FIELD_WIDTH PRECISION PRINTF
14548 ----------------------------------------
14554 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14555 display them, and < 0 means obey the current buffer's value of
14556 enable_multibyte_characters.
14558 Value is the number of glyphs produced. */
14561 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14562 start
, it
, field_width
, precision
, max_x
, multibyte
)
14563 unsigned char *string
;
14564 Lisp_Object lisp_string
;
14565 Lisp_Object face_string
;
14566 int face_string_pos
;
14569 int field_width
, precision
, max_x
;
14572 int hpos_at_start
= it
->hpos
;
14573 int saved_face_id
= it
->face_id
;
14574 struct glyph_row
*row
= it
->glyph_row
;
14576 /* Initialize the iterator IT for iteration over STRING beginning
14577 with index START. */
14578 reseat_to_string (it
, string
, lisp_string
, start
,
14579 precision
, field_width
, multibyte
);
14581 /* If displaying STRING, set up the face of the iterator
14582 from LISP_STRING, if that's given. */
14583 if (STRINGP (face_string
))
14589 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14590 0, it
->region_beg_charpos
,
14591 it
->region_end_charpos
,
14592 &endptr
, it
->base_face_id
, 0);
14593 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14594 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14597 /* Set max_x to the maximum allowed X position. Don't let it go
14598 beyond the right edge of the window. */
14600 max_x
= it
->last_visible_x
;
14602 max_x
= min (max_x
, it
->last_visible_x
);
14604 /* Skip over display elements that are not visible. because IT->w is
14606 if (it
->current_x
< it
->first_visible_x
)
14607 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14608 MOVE_TO_POS
| MOVE_TO_X
);
14610 row
->ascent
= it
->max_ascent
;
14611 row
->height
= it
->max_ascent
+ it
->max_descent
;
14612 row
->phys_ascent
= it
->max_phys_ascent
;
14613 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14615 /* This condition is for the case that we are called with current_x
14616 past last_visible_x. */
14617 while (it
->current_x
< max_x
)
14619 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14621 /* Get the next display element. */
14622 if (!get_next_display_element (it
))
14625 /* Produce glyphs. */
14626 x_before
= it
->current_x
;
14627 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14628 PRODUCE_GLYPHS (it
);
14630 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14633 while (i
< nglyphs
)
14635 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14637 if (!it
->truncate_lines_p
14638 && x
+ glyph
->pixel_width
> max_x
)
14640 /* End of continued line or max_x reached. */
14641 if (CHAR_GLYPH_PADDING_P (*glyph
))
14643 /* A wide character is unbreakable. */
14644 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14645 it
->current_x
= x_before
;
14649 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14654 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
14656 /* Glyph is at least partially visible. */
14658 if (x
< it
->first_visible_x
)
14659 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14663 /* Glyph is off the left margin of the display area.
14664 Should not happen. */
14668 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14669 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14670 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14671 row
->phys_height
= max (row
->phys_height
,
14672 it
->max_phys_ascent
+ it
->max_phys_descent
);
14673 x
+= glyph
->pixel_width
;
14677 /* Stop if max_x reached. */
14681 /* Stop at line ends. */
14682 if (ITERATOR_AT_END_OF_LINE_P (it
))
14684 it
->continuation_lines_width
= 0;
14688 set_iterator_to_next (it
, 1);
14690 /* Stop if truncating at the right edge. */
14691 if (it
->truncate_lines_p
14692 && it
->current_x
>= it
->last_visible_x
)
14694 /* Add truncation mark, but don't do it if the line is
14695 truncated at a padding space. */
14696 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14698 if (!FRAME_WINDOW_P (it
->f
))
14702 if (it
->current_x
> it
->last_visible_x
)
14704 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14705 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14707 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14709 row
->used
[TEXT_AREA
] = i
;
14710 produce_special_glyphs (it
, IT_TRUNCATION
);
14713 produce_special_glyphs (it
, IT_TRUNCATION
);
14715 it
->glyph_row
->truncated_on_right_p
= 1;
14721 /* Maybe insert a truncation at the left. */
14722 if (it
->first_visible_x
14723 && IT_CHARPOS (*it
) > 0)
14725 if (!FRAME_WINDOW_P (it
->f
))
14726 insert_left_trunc_glyphs (it
);
14727 it
->glyph_row
->truncated_on_left_p
= 1;
14730 it
->face_id
= saved_face_id
;
14732 /* Value is number of columns displayed. */
14733 return it
->hpos
- hpos_at_start
;
14738 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
14739 appears as an element of LIST or as the car of an element of LIST.
14740 If PROPVAL is a list, compare each element against LIST in that
14741 way, and return 1/2 if any element of PROPVAL is found in LIST.
14742 Otherwise return 0. This function cannot quit.
14743 The return value is 2 if the text is invisible but with an ellipsis
14744 and 1 if it's invisible and without an ellipsis. */
14747 invisible_p (propval
, list
)
14748 register Lisp_Object propval
;
14751 register Lisp_Object tail
, proptail
;
14753 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14755 register Lisp_Object tem
;
14757 if (EQ (propval
, tem
))
14759 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14760 return NILP (XCDR (tem
)) ? 1 : 2;
14763 if (CONSP (propval
))
14765 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14767 Lisp_Object propelt
;
14768 propelt
= XCAR (proptail
);
14769 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14771 register Lisp_Object tem
;
14773 if (EQ (propelt
, tem
))
14775 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14776 return NILP (XCDR (tem
)) ? 1 : 2;
14785 /***********************************************************************
14787 ***********************************************************************/
14792 Vwith_echo_area_save_vector
= Qnil
;
14793 staticpro (&Vwith_echo_area_save_vector
);
14795 Vmessage_stack
= Qnil
;
14796 staticpro (&Vmessage_stack
);
14798 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14799 staticpro (&Qinhibit_redisplay
);
14801 message_dolog_marker1
= Fmake_marker ();
14802 staticpro (&message_dolog_marker1
);
14803 message_dolog_marker2
= Fmake_marker ();
14804 staticpro (&message_dolog_marker2
);
14805 message_dolog_marker3
= Fmake_marker ();
14806 staticpro (&message_dolog_marker3
);
14809 defsubr (&Sdump_glyph_matrix
);
14810 defsubr (&Sdump_glyph_row
);
14811 defsubr (&Sdump_tool_bar_row
);
14812 defsubr (&Strace_redisplay
);
14813 defsubr (&Strace_to_stderr
);
14815 #ifdef HAVE_WINDOW_SYSTEM
14816 defsubr (&Stool_bar_lines_needed
);
14819 staticpro (&Qmenu_bar_update_hook
);
14820 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14822 staticpro (&Qoverriding_terminal_local_map
);
14823 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14825 staticpro (&Qoverriding_local_map
);
14826 Qoverriding_local_map
= intern ("overriding-local-map");
14828 staticpro (&Qwindow_scroll_functions
);
14829 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14831 staticpro (&Qredisplay_end_trigger_functions
);
14832 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14834 staticpro (&Qinhibit_point_motion_hooks
);
14835 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14837 QCdata
= intern (":data");
14838 staticpro (&QCdata
);
14839 Qdisplay
= intern ("display");
14840 staticpro (&Qdisplay
);
14841 Qspace_width
= intern ("space-width");
14842 staticpro (&Qspace_width
);
14843 Qraise
= intern ("raise");
14844 staticpro (&Qraise
);
14845 Qspace
= intern ("space");
14846 staticpro (&Qspace
);
14847 Qmargin
= intern ("margin");
14848 staticpro (&Qmargin
);
14849 Qleft_margin
= intern ("left-margin");
14850 staticpro (&Qleft_margin
);
14851 Qright_margin
= intern ("right-margin");
14852 staticpro (&Qright_margin
);
14853 Qalign_to
= intern ("align-to");
14854 staticpro (&Qalign_to
);
14855 QCalign_to
= intern (":align-to");
14856 staticpro (&QCalign_to
);
14857 Qrelative_width
= intern ("relative-width");
14858 staticpro (&Qrelative_width
);
14859 QCrelative_width
= intern (":relative-width");
14860 staticpro (&QCrelative_width
);
14861 QCrelative_height
= intern (":relative-height");
14862 staticpro (&QCrelative_height
);
14863 QCeval
= intern (":eval");
14864 staticpro (&QCeval
);
14865 QCpropertize
= intern (":propertize");
14866 staticpro (&QCpropertize
);
14867 Qwhen
= intern ("when");
14868 staticpro (&Qwhen
);
14869 QCfile
= intern (":file");
14870 staticpro (&QCfile
);
14871 Qfontified
= intern ("fontified");
14872 staticpro (&Qfontified
);
14873 Qfontification_functions
= intern ("fontification-functions");
14874 staticpro (&Qfontification_functions
);
14875 Qtrailing_whitespace
= intern ("trailing-whitespace");
14876 staticpro (&Qtrailing_whitespace
);
14877 Qimage
= intern ("image");
14878 staticpro (&Qimage
);
14879 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14880 staticpro (&Qmessage_truncate_lines
);
14881 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
14882 staticpro (&Qcursor_in_non_selected_windows
);
14883 Qgrow_only
= intern ("grow-only");
14884 staticpro (&Qgrow_only
);
14885 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14886 staticpro (&Qinhibit_menubar_update
);
14887 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14888 staticpro (&Qinhibit_eval_during_redisplay
);
14889 Qposition
= intern ("position");
14890 staticpro (&Qposition
);
14891 Qbuffer_position
= intern ("buffer-position");
14892 staticpro (&Qbuffer_position
);
14893 Qobject
= intern ("object");
14894 staticpro (&Qobject
);
14896 last_arrow_position
= Qnil
;
14897 last_arrow_string
= Qnil
;
14898 staticpro (&last_arrow_position
);
14899 staticpro (&last_arrow_string
);
14901 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14902 staticpro (&echo_buffer
[0]);
14903 staticpro (&echo_buffer
[1]);
14905 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14906 staticpro (&echo_area_buffer
[0]);
14907 staticpro (&echo_area_buffer
[1]);
14909 Vmessages_buffer_name
= build_string ("*Messages*");
14910 staticpro (&Vmessages_buffer_name
);
14912 mode_line_proptrans_alist
= Qnil
;
14913 staticpro (&mode_line_proptrans_alist
);
14915 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14916 doc
: /* Non-nil means highlight trailing whitespace.
14917 The face used for trailing whitespace is `trailing-whitespace'. */);
14918 Vshow_trailing_whitespace
= Qnil
;
14920 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14921 doc
: /* Non-nil means don't actually do any redisplay.
14922 This is used for internal purposes. */);
14923 Vinhibit_redisplay
= Qnil
;
14925 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14926 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
14927 Vglobal_mode_string
= Qnil
;
14929 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14930 doc
: /* Marker for where to display an arrow on top of the buffer text.
14931 This must be the beginning of a line in order to work.
14932 See also `overlay-arrow-string'. */);
14933 Voverlay_arrow_position
= Qnil
;
14935 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14936 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
14937 Voverlay_arrow_string
= Qnil
;
14939 DEFVAR_INT ("scroll-step", &scroll_step
,
14940 doc
: /* *The number of lines to try scrolling a window by when point moves out.
14941 If that fails to bring point back on frame, point is centered instead.
14942 If this is zero, point is always centered after it moves off frame.
14943 If you want scrolling to always be a line at a time, you should set
14944 `scroll-conservatively' to a large value rather than set this to 1. */);
14946 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14947 doc
: /* *Scroll up to this many lines, to bring point back on screen.
14948 A value of zero means to scroll the text to center point vertically
14949 in the window. */);
14950 scroll_conservatively
= 0;
14952 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14953 doc
: /* *Number of lines of margin at the top and bottom of a window.
14954 Recenter the window whenever point gets within this many lines
14955 of the top or bottom of the window. */);
14959 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
14962 DEFVAR_BOOL ("truncate-partial-width-windows",
14963 &truncate_partial_width_windows
,
14964 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
14965 truncate_partial_width_windows
= 1;
14967 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14968 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
14969 Any other value means to use the appropriate face, `mode-line',
14970 `header-line', or `menu' respectively.
14972 This variable is deprecated; please change the above faces instead. */);
14973 mode_line_inverse_video
= 1;
14975 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14976 doc
: /* *Maximum buffer size for which line number should be displayed.
14977 If the buffer is bigger than this, the line number does not appear
14978 in the mode line. A value of nil means no limit. */);
14979 Vline_number_display_limit
= Qnil
;
14981 DEFVAR_INT ("line-number-display-limit-width",
14982 &line_number_display_limit_width
,
14983 doc
: /* *Maximum line width (in characters) for line number display.
14984 If the average length of the lines near point is bigger than this, then the
14985 line number may be omitted from the mode line. */);
14986 line_number_display_limit_width
= 200;
14988 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14989 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
14990 highlight_nonselected_windows
= 0;
14992 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14993 doc
: /* Non-nil if more than one frame is visible on this display.
14994 Minibuffer-only frames don't count, but iconified frames do.
14995 This variable is not guaranteed to be accurate except while processing
14996 `frame-title-format' and `icon-title-format'. */);
14998 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14999 doc
: /* Template for displaying the title bar of visible frames.
15000 \(Assuming the window manager supports this feature.)
15001 This variable has the same structure as `mode-line-format' (which see),
15002 and is used only on frames for which no explicit name has been set
15003 \(see `modify-frame-parameters'). */);
15004 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
15005 doc
: /* Template for displaying the title bar of an iconified frame.
15006 \(Assuming the window manager supports this feature.)
15007 This variable has the same structure as `mode-line-format' (which see),
15008 and is used only on frames for which no explicit name has been set
15009 \(see `modify-frame-parameters'). */);
15011 = Vframe_title_format
15012 = Fcons (intern ("multiple-frames"),
15013 Fcons (build_string ("%b"),
15014 Fcons (Fcons (empty_string
,
15015 Fcons (intern ("invocation-name"),
15016 Fcons (build_string ("@"),
15017 Fcons (intern ("system-name"),
15021 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
15022 doc
: /* Maximum number of lines to keep in the message log buffer.
15023 If nil, disable message logging. If t, log messages but don't truncate
15024 the buffer when it becomes large. */);
15025 Vmessage_log_max
= make_number (50);
15027 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
15028 doc
: /* Functions called before redisplay, if window sizes have changed.
15029 The value should be a list of functions that take one argument.
15030 Just before redisplay, for each frame, if any of its windows have changed
15031 size since the last redisplay, or have been split or deleted,
15032 all the functions in the list are called, with the frame as argument. */);
15033 Vwindow_size_change_functions
= Qnil
;
15035 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
15036 doc
: /* List of Functions to call before redisplaying a window with scrolling.
15037 Each function is called with two arguments, the window
15038 and its new display-start position. Note that the value of `window-end'
15039 is not valid when these functions are called. */);
15040 Vwindow_scroll_functions
= Qnil
;
15042 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
15043 doc
: /* *Non-nil means automatically resize tool-bars.
15044 This increases a tool-bar's height if not all tool-bar items are visible.
15045 It decreases a tool-bar's height when it would display blank lines
15047 auto_resize_tool_bars_p
= 1;
15049 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
15050 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
15051 auto_raise_tool_bar_buttons_p
= 1;
15053 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
15054 doc
: /* *Margin around tool-bar buttons in pixels.
15055 If an integer, use that for both horizontal and vertical margins.
15056 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
15057 HORZ specifying the horizontal margin, and VERT specifying the
15058 vertical margin. */);
15059 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
15061 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
15062 doc
: /* *Relief thickness of tool-bar buttons. */);
15063 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
15065 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
15066 doc
: /* List of functions to call to fontify regions of text.
15067 Each function is called with one argument POS. Functions must
15068 fontify a region starting at POS in the current buffer, and give
15069 fontified regions the property `fontified'. */);
15070 Vfontification_functions
= Qnil
;
15071 Fmake_variable_buffer_local (Qfontification_functions
);
15073 DEFVAR_BOOL ("unibyte-display-via-language-environment",
15074 &unibyte_display_via_language_environment
,
15075 doc
: /* *Non-nil means display unibyte text according to language environment.
15076 Specifically this means that unibyte non-ASCII characters
15077 are displayed by converting them to the equivalent multibyte characters
15078 according to the current language environment. As a result, they are
15079 displayed according to the current fontset. */);
15080 unibyte_display_via_language_environment
= 0;
15082 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
15083 doc
: /* *Maximum height for resizing mini-windows.
15084 If a float, it specifies a fraction of the mini-window frame's height.
15085 If an integer, it specifies a number of lines. */);
15086 Vmax_mini_window_height
= make_float (0.25);
15088 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
15089 doc
: /* *How to resize mini-windows.
15090 A value of nil means don't automatically resize mini-windows.
15091 A value of t means resize them to fit the text displayed in them.
15092 A value of `grow-only', the default, means let mini-windows grow
15093 only, until their display becomes empty, at which point the windows
15094 go back to their normal size. */);
15095 Vresize_mini_windows
= Qgrow_only
;
15097 DEFVAR_BOOL ("cursor-in-non-selected-windows",
15098 &cursor_in_non_selected_windows
,
15099 doc
: /* *Non-nil means display a hollow cursor in non-selected windows.
15100 nil means don't display a cursor there. */);
15101 cursor_in_non_selected_windows
= 1;
15103 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
15104 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
15105 automatic_hscrolling_p
= 1;
15107 DEFVAR_INT ("automatic-hscroll-margin", &automatic_hscroll_margin
,
15108 doc
: /* *How many columns away from the window edge point is allowed to get
15109 before automatic hscrolling will horizontally scroll the window. */);
15110 automatic_hscroll_margin
= 5;
15112 DEFVAR_LISP ("automatic-hscroll-step", &Vautomatic_hscroll_step
,
15113 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
15114 When point is less than `automatic-hscroll-margin' columns from the window
15115 edge, automatic hscrolling will scroll the window by the amount of columns
15116 determined by this variable. If its value is a positive integer, scroll that
15117 many columns. If it's a positive floating-point number, it specifies the
15118 fraction of the window's width to scroll. If it's nil or zero, point will be
15119 centered horizontally after the scroll. Any other value, including negative
15120 numbers, are treated as if the value were zero.
15122 Automatic hscrolling always moves point outside the scroll margin, so if
15123 point was more than scroll step columns inside the margin, the window will
15124 scroll more than the value given by the scroll step.
15126 Note that the lower bound for automatic hscrolling specified by `scroll-left'
15127 and `scroll-right' overrides this variable's effect. */);
15128 Vautomatic_hscroll_step
= make_number (0);
15130 DEFVAR_LISP ("image-types", &Vimage_types
,
15131 doc
: /* List of supported image types.
15132 Each element of the list is a symbol for a supported image type. */);
15133 Vimage_types
= Qnil
;
15135 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
15136 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
15137 Bind this around calls to `message' to let it take effect. */);
15138 message_truncate_lines
= 0;
15140 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
15141 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
15142 Can be used to update submenus whose contents should vary. */);
15143 Vmenu_bar_update_hook
= Qnil
;
15145 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
15146 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
15147 inhibit_menubar_update
= 0;
15149 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
15150 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
15151 inhibit_eval_during_redisplay
= 0;
15154 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
15155 doc
: /* Inhibit try_window_id display optimization. */);
15156 inhibit_try_window_id
= 0;
15158 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
15159 doc
: /* Inhibit try_window_reusing display optimization. */);
15160 inhibit_try_window_reusing
= 0;
15162 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
15163 doc
: /* Inhibit try_cursor_movement display optimization. */);
15164 inhibit_try_cursor_movement
= 0;
15165 #endif /* GLYPH_DEBUG */
15169 /* Initialize this module when Emacs starts. */
15174 Lisp_Object root_window
;
15175 struct window
*mini_w
;
15177 current_header_line_height
= current_mode_line_height
= -1;
15179 CHARPOS (this_line_start_pos
) = 0;
15181 mini_w
= XWINDOW (minibuf_window
);
15182 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
15184 if (!noninteractive
)
15186 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
15189 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
15190 set_window_height (root_window
,
15191 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
15193 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
15194 set_window_height (minibuf_window
, 1, 0);
15196 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
15197 mini_w
->width
= make_number (FRAME_WIDTH (f
));
15199 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
15200 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
15201 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
15203 /* The default ellipsis glyphs `...'. */
15204 for (i
= 0; i
< 3; ++i
)
15205 default_invis_vector
[i
] = make_number ('.');
15208 #ifdef HAVE_WINDOW_SYSTEM
15210 /* Allocate the buffer for frame titles. */
15212 frame_title_buf
= (char *) xmalloc (size
);
15213 frame_title_buf_end
= frame_title_buf
+ size
;
15214 frame_title_ptr
= NULL
;
15216 #endif /* HAVE_WINDOW_SYSTEM */
15218 help_echo_showing_p
= 0;