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 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 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 be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator
128 (or init_string_iterator for that matter). Calls to
129 get_next_display_element fill the iterator structure with relevant
130 information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define min(a, b) ((a) < (b) ? (a) : (b))
202 #define max(a, b) ((a) > (b) ? (a) : (b))
204 #define INFINITY 10000000
206 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
207 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
208 extern int pending_menu_activation
;
211 extern int interrupt_input
;
212 extern int command_loop_level
;
214 extern int minibuffer_auto_raise
;
216 extern Lisp_Object Qface
;
218 extern Lisp_Object Voverriding_local_map
;
219 extern Lisp_Object Voverriding_local_map_menu_flag
;
220 extern Lisp_Object Qmenu_item
;
222 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
223 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
224 Lisp_Object Qredisplay_end_trigger_functions
;
225 Lisp_Object Qinhibit_point_motion_hooks
;
226 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
227 Lisp_Object Qfontified
;
228 Lisp_Object Qgrow_only
;
229 Lisp_Object Qinhibit_eval_during_redisplay
;
231 /* Functions called to fontify regions of text. */
233 Lisp_Object Vfontification_functions
;
234 Lisp_Object Qfontification_functions
;
236 /* Non-zero means draw tool bar buttons raised when the mouse moves
239 int auto_raise_tool_bar_buttons_p
;
241 /* Margin around tool bar buttons in pixels. */
243 Lisp_Object Vtool_bar_button_margin
;
245 /* Thickness of shadow to draw around tool bar buttons. */
247 int tool_bar_button_relief
;
249 /* Non-zero means automatically resize tool-bars so that all tool-bar
250 items are visible, and no blank lines remain. */
252 int auto_resize_tool_bars_p
;
254 /* Non-nil means don't actually do any redisplay. */
256 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
258 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
260 int inhibit_eval_during_redisplay
;
262 /* Names of text properties relevant for redisplay. */
264 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
265 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
267 /* Symbols used in text property values. */
269 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
270 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
272 extern Lisp_Object Qheight
;
274 /* Non-nil means highlight trailing whitespace. */
276 Lisp_Object Vshow_trailing_whitespace
;
278 /* Name of the face used to highlight trailing whitespace. */
280 Lisp_Object Qtrailing_whitespace
;
282 /* The symbol `image' which is the car of the lists used to represent
287 /* Non-zero means print newline to stdout before next mini-buffer
290 int noninteractive_need_newline
;
292 /* Non-zero means print newline to message log before next message. */
294 static int message_log_need_newline
;
297 /* The buffer position of the first character appearing entirely or
298 partially on the line of the selected window which contains the
299 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
300 redisplay optimization in redisplay_internal. */
302 static struct text_pos this_line_start_pos
;
304 /* Number of characters past the end of the line above, including the
305 terminating newline. */
307 static struct text_pos this_line_end_pos
;
309 /* The vertical positions and the height of this line. */
311 static int this_line_vpos
;
312 static int this_line_y
;
313 static int this_line_pixel_height
;
315 /* X position at which this display line starts. Usually zero;
316 negative if first character is partially visible. */
318 static int this_line_start_x
;
320 /* Buffer that this_line_.* variables are referring to. */
322 static struct buffer
*this_line_buffer
;
324 /* Nonzero means truncate lines in all windows less wide than the
327 int truncate_partial_width_windows
;
329 /* A flag to control how to display unibyte 8-bit character. */
331 int unibyte_display_via_language_environment
;
333 /* Nonzero means we have more than one non-mini-buffer-only frame.
334 Not guaranteed to be accurate except while parsing
335 frame-title-format. */
339 Lisp_Object Vglobal_mode_string
;
341 /* Marker for where to display an arrow on top of the buffer text. */
343 Lisp_Object Voverlay_arrow_position
;
345 /* String to display for the arrow. Only used on terminal frames. */
347 Lisp_Object Voverlay_arrow_string
;
349 /* Values of those variables at last redisplay. However, if
350 Voverlay_arrow_position is a marker, last_arrow_position is its
351 numerical position. */
353 static Lisp_Object last_arrow_position
, last_arrow_string
;
355 /* Like mode-line-format, but for the title bar on a visible frame. */
357 Lisp_Object Vframe_title_format
;
359 /* Like mode-line-format, but for the title bar on an iconified frame. */
361 Lisp_Object Vicon_title_format
;
363 /* List of functions to call when a window's size changes. These
364 functions get one arg, a frame on which one or more windows' sizes
367 static Lisp_Object Vwindow_size_change_functions
;
369 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
371 /* Nonzero if overlay arrow has been displayed once in this window. */
373 static int overlay_arrow_seen
;
375 /* Nonzero means highlight the region even in nonselected windows. */
377 int highlight_nonselected_windows
;
379 /* If cursor motion alone moves point off frame, try scrolling this
380 many lines up or down if that will bring it back. */
382 static int scroll_step
;
384 /* Non-0 means scroll just far enough to bring point back on the
385 screen, when appropriate. */
387 static int scroll_conservatively
;
389 /* Recenter the window whenever point gets within this many lines of
390 the top or bottom of the window. This value is translated into a
391 pixel value by multiplying it with CANON_Y_UNIT, which means that
392 there is really a fixed pixel height scroll margin. */
396 /* Number of windows showing the buffer of the selected window (or
397 another buffer with the same base buffer). keyboard.c refers to
402 /* Vector containing glyphs for an ellipsis `...'. */
404 static Lisp_Object default_invis_vector
[3];
406 /* Zero means display the mode-line/header-line/menu-bar in the default face
407 (this slightly odd definition is for compatibility with previous versions
408 of emacs), non-zero means display them using their respective faces.
410 This variable is deprecated. */
412 int mode_line_inverse_video
;
414 /* Prompt to display in front of the mini-buffer contents. */
416 Lisp_Object minibuf_prompt
;
418 /* Width of current mini-buffer prompt. Only set after display_line
419 of the line that contains the prompt. */
421 int minibuf_prompt_width
;
422 int minibuf_prompt_pixel_width
;
424 /* This is the window where the echo area message was displayed. It
425 is always a mini-buffer window, but it may not be the same window
426 currently active as a mini-buffer. */
428 Lisp_Object echo_area_window
;
430 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
431 pushes the current message and the value of
432 message_enable_multibyte on the stack, the function restore_message
433 pops the stack and displays MESSAGE again. */
435 Lisp_Object Vmessage_stack
;
437 /* Nonzero means multibyte characters were enabled when the echo area
438 message was specified. */
440 int message_enable_multibyte
;
442 /* True if we should redraw the mode lines on the next redisplay. */
444 int update_mode_lines
;
446 /* Nonzero if window sizes or contents have changed since last
447 redisplay that finished */
449 int windows_or_buffers_changed
;
451 /* Nonzero after display_mode_line if %l was used and it displayed a
454 int line_number_displayed
;
456 /* Maximum buffer size for which to display line numbers. */
458 Lisp_Object Vline_number_display_limit
;
460 /* line width to consider when repostioning for line number display */
462 static int line_number_display_limit_width
;
464 /* Number of lines to keep in the message log buffer. t means
465 infinite. nil means don't log at all. */
467 Lisp_Object Vmessage_log_max
;
469 /* The name of the *Messages* buffer, a string. */
471 static Lisp_Object Vmessages_buffer_name
;
473 /* Current, index 0, and last displayed echo area message. Either
474 buffers from echo_buffers, or nil to indicate no message. */
476 Lisp_Object echo_area_buffer
[2];
478 /* The buffers referenced from echo_area_buffer. */
480 static Lisp_Object echo_buffer
[2];
482 /* A vector saved used in with_area_buffer to reduce consing. */
484 static Lisp_Object Vwith_echo_area_save_vector
;
486 /* Non-zero means display_echo_area should display the last echo area
487 message again. Set by redisplay_preserve_echo_area. */
489 static int display_last_displayed_message_p
;
491 /* Nonzero if echo area is being used by print; zero if being used by
494 int message_buf_print
;
496 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
498 Lisp_Object Qinhibit_menubar_update
;
499 int inhibit_menubar_update
;
501 /* Maximum height for resizing mini-windows. Either a float
502 specifying a fraction of the available height, or an integer
503 specifying a number of lines. */
505 Lisp_Object Vmax_mini_window_height
;
507 /* Non-zero means messages should be displayed with truncated
508 lines instead of being continued. */
510 int message_truncate_lines
;
511 Lisp_Object Qmessage_truncate_lines
;
513 /* Set to 1 in clear_message to make redisplay_internal aware
514 of an emptied echo area. */
516 static int message_cleared_p
;
518 /* Non-zero means we want a hollow cursor in windows that are not
519 selected. Zero means there's no cursor in such windows. */
521 int cursor_in_non_selected_windows
;
523 /* A scratch glyph row with contents used for generating truncation
524 glyphs. Also used in direct_output_for_insert. */
526 #define MAX_SCRATCH_GLYPHS 100
527 struct glyph_row scratch_glyph_row
;
528 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
530 /* Ascent and height of the last line processed by move_it_to. */
532 static int last_max_ascent
, last_height
;
534 /* Non-zero if there's a help-echo in the echo area. */
536 int help_echo_showing_p
;
538 /* If >= 0, computed, exact values of mode-line and header-line height
539 to use in the macros CURRENT_MODE_LINE_HEIGHT and
540 CURRENT_HEADER_LINE_HEIGHT. */
542 int current_mode_line_height
, current_header_line_height
;
544 /* The maximum distance to look ahead for text properties. Values
545 that are too small let us call compute_char_face and similar
546 functions too often which is expensive. Values that are too large
547 let us call compute_char_face and alike too often because we
548 might not be interested in text properties that far away. */
550 #define TEXT_PROP_DISTANCE_LIMIT 100
554 /* Non-zero means print traces of redisplay if compiled with
557 int trace_redisplay_p
;
559 #endif /* GLYPH_DEBUG */
561 #ifdef DEBUG_TRACE_MOVE
562 /* Non-zero means trace with TRACE_MOVE to stderr. */
565 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
567 #define TRACE_MOVE(x) (void) 0
570 /* Non-zero means automatically scroll windows horizontally to make
573 int automatic_hscrolling_p
;
575 /* A list of symbols, one for each supported image type. */
577 Lisp_Object Vimage_types
;
579 /* The variable `resize-mini-windows'. If nil, don't resize
580 mini-windows. If t, always resize them to fit the text they
581 display. If `grow-only', let mini-windows grow only until they
584 Lisp_Object Vresize_mini_windows
;
586 /* Value returned from text property handlers (see below). */
591 HANDLED_RECOMPUTE_PROPS
,
592 HANDLED_OVERLAY_STRING_CONSUMED
,
596 /* A description of text properties that redisplay is interested
601 /* The name of the property. */
604 /* A unique index for the property. */
607 /* A handler function called to set up iterator IT from the property
608 at IT's current position. Value is used to steer handle_stop. */
609 enum prop_handled (*handler
) P_ ((struct it
*it
));
612 static enum prop_handled handle_face_prop
P_ ((struct it
*));
613 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
614 static enum prop_handled handle_display_prop
P_ ((struct it
*));
615 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
616 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
617 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
619 /* Properties handled by iterators. */
621 static struct props it_props
[] =
623 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
624 /* Handle `face' before `display' because some sub-properties of
625 `display' need to know the face. */
626 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
627 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
628 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
629 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
633 /* Value is the position described by X. If X is a marker, value is
634 the marker_position of X. Otherwise, value is X. */
636 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
638 /* Enumeration returned by some move_it_.* functions internally. */
642 /* Not used. Undefined value. */
645 /* Move ended at the requested buffer position or ZV. */
646 MOVE_POS_MATCH_OR_ZV
,
648 /* Move ended at the requested X pixel position. */
651 /* Move within a line ended at the end of a line that must be
655 /* Move within a line ended at the end of a line that would
656 be displayed truncated. */
659 /* Move within a line ended at a line end. */
665 /* Function prototypes. */
667 static void setup_for_ellipsis
P_ ((struct it
*));
668 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
669 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
670 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
671 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
672 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
673 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
674 static int invisible_text_between_p
P_ ((struct it
*, int, int));
675 static int next_element_from_ellipsis
P_ ((struct it
*));
676 static void pint2str
P_ ((char *, int, int));
677 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
679 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
680 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
681 static void store_frame_title_char
P_ ((char));
682 static int store_frame_title
P_ ((unsigned char *, int, int));
683 static void x_consider_frame_title
P_ ((Lisp_Object
));
684 static void handle_stop
P_ ((struct it
*));
685 static int tool_bar_lines_needed
P_ ((struct frame
*));
686 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
687 static void ensure_echo_area_buffers
P_ ((void));
688 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
690 struct glyph_row
*));
691 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
692 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
693 static int with_echo_area_buffer
P_ ((struct window
*, int,
694 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
695 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
696 static void clear_garbaged_frames
P_ ((void));
697 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
698 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
699 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
700 static int display_echo_area
P_ ((struct window
*));
701 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
702 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
703 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
704 static int string_char_and_length
P_ ((unsigned char *, int, int *));
705 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
707 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
708 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
709 static void insert_left_trunc_glyphs
P_ ((struct it
*));
710 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
711 static void extend_face_to_end_of_line
P_ ((struct it
*));
712 static int append_space
P_ ((struct it
*, int));
713 static void make_cursor_line_fully_visible
P_ ((struct window
*));
714 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
715 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
716 static int trailing_whitespace_p
P_ ((int));
717 static int message_log_check_duplicate
P_ ((int, int, int, int));
718 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
719 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
720 static void push_it
P_ ((struct it
*));
721 static void pop_it
P_ ((struct it
*));
722 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
723 static void redisplay_internal
P_ ((int));
724 static int echo_area_display
P_ ((int));
725 static void redisplay_windows
P_ ((Lisp_Object
));
726 static void redisplay_window
P_ ((Lisp_Object
, int));
727 static void update_menu_bar
P_ ((struct frame
*, int));
728 static int try_window_reusing_current_matrix
P_ ((struct window
*));
729 static int try_window_id
P_ ((struct window
*));
730 static int display_line
P_ ((struct it
*));
731 static int display_mode_lines
P_ ((struct window
*));
732 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
733 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
734 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
735 static void display_menu_bar
P_ ((struct window
*));
736 static int display_count_lines
P_ ((int, int, int, int, int *));
737 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
738 int, int, struct it
*, int, int, int, int));
739 static void compute_line_metrics
P_ ((struct it
*));
740 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
741 static int get_overlay_strings
P_ ((struct it
*, int));
742 static void next_overlay_string
P_ ((struct it
*));
743 static void reseat
P_ ((struct it
*, struct text_pos
, int));
744 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
745 static void back_to_previous_visible_line_start
P_ ((struct it
*));
746 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
747 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
748 static int next_element_from_display_vector
P_ ((struct it
*));
749 static int next_element_from_string
P_ ((struct it
*));
750 static int next_element_from_c_string
P_ ((struct it
*));
751 static int next_element_from_buffer
P_ ((struct it
*));
752 static int next_element_from_composition
P_ ((struct it
*));
753 static int next_element_from_image
P_ ((struct it
*));
754 static int next_element_from_stretch
P_ ((struct it
*));
755 static void load_overlay_strings
P_ ((struct it
*, int));
756 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
757 struct display_pos
*));
758 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
759 Lisp_Object
, int, int, int, int));
760 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
762 void move_it_vertically_backward
P_ ((struct it
*, int));
763 static void init_to_row_start
P_ ((struct it
*, struct window
*,
764 struct glyph_row
*));
765 static void init_to_row_end
P_ ((struct it
*, struct window
*,
766 struct glyph_row
*));
767 static void back_to_previous_line_start
P_ ((struct it
*));
768 static int forward_to_next_line_start
P_ ((struct it
*, int *));
769 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
771 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
772 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
773 static int number_of_chars
P_ ((unsigned char *, int));
774 static void compute_stop_pos
P_ ((struct it
*));
775 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
777 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
778 static int next_overlay_change
P_ ((int));
779 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
780 Lisp_Object
, struct text_pos
*,
782 static int underlying_face_id
P_ ((struct it
*));
783 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
786 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
787 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
789 #ifdef HAVE_WINDOW_SYSTEM
791 static void update_tool_bar
P_ ((struct frame
*, int));
792 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
793 static int redisplay_tool_bar
P_ ((struct frame
*));
794 static void display_tool_bar_line
P_ ((struct it
*));
796 #endif /* HAVE_WINDOW_SYSTEM */
799 /***********************************************************************
800 Window display dimensions
801 ***********************************************************************/
803 /* Return the window-relative maximum y + 1 for glyph rows displaying
804 text in window W. This is the height of W minus the height of a
805 mode line, if any. */
808 window_text_bottom_y (w
)
811 struct frame
*f
= XFRAME (w
->frame
);
812 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
814 if (WINDOW_WANTS_MODELINE_P (w
))
815 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
820 /* Return the pixel width of display area AREA of window W. AREA < 0
821 means return the total width of W, not including bitmap areas to
822 the left and right of the window. */
825 window_box_width (w
, area
)
829 struct frame
*f
= XFRAME (w
->frame
);
830 int width
= XFASTINT (w
->width
);
832 if (!w
->pseudo_window_p
)
834 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
836 if (area
== TEXT_AREA
)
838 if (INTEGERP (w
->left_margin_width
))
839 width
-= XFASTINT (w
->left_margin_width
);
840 if (INTEGERP (w
->right_margin_width
))
841 width
-= XFASTINT (w
->right_margin_width
);
843 else if (area
== LEFT_MARGIN_AREA
)
844 width
= (INTEGERP (w
->left_margin_width
)
845 ? XFASTINT (w
->left_margin_width
) : 0);
846 else if (area
== RIGHT_MARGIN_AREA
)
847 width
= (INTEGERP (w
->right_margin_width
)
848 ? XFASTINT (w
->right_margin_width
) : 0);
851 return width
* CANON_X_UNIT (f
);
855 /* Return the pixel height of the display area of window W, not
856 including mode lines of W, if any.. */
859 window_box_height (w
)
862 struct frame
*f
= XFRAME (w
->frame
);
863 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
865 xassert (height
>= 0);
867 /* Note: the code below that determines the mode-line/header-line
868 height is essentially the same as that contained in the macro
869 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
870 the appropriate glyph row has its `mode_line_p' flag set,
871 and if it doesn't, uses estimate_mode_line_height instead. */
873 if (WINDOW_WANTS_MODELINE_P (w
))
875 struct glyph_row
*ml_row
876 = (w
->current_matrix
&& w
->current_matrix
->rows
877 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
879 if (ml_row
&& ml_row
->mode_line_p
)
880 height
-= ml_row
->height
;
882 height
-= estimate_mode_line_height (f
, MODE_LINE_FACE_ID
);
885 if (WINDOW_WANTS_HEADER_LINE_P (w
))
887 struct glyph_row
*hl_row
888 = (w
->current_matrix
&& w
->current_matrix
->rows
889 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
891 if (hl_row
&& hl_row
->mode_line_p
)
892 height
-= hl_row
->height
;
894 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
901 /* Return the frame-relative coordinate of the left edge of display
902 area AREA of window W. AREA < 0 means return the left edge of the
903 whole window, to the right of any bitmap area at the left side of
907 window_box_left (w
, area
)
911 struct frame
*f
= XFRAME (w
->frame
);
912 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
914 if (!w
->pseudo_window_p
)
916 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
917 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
919 if (area
== TEXT_AREA
)
920 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
921 else if (area
== RIGHT_MARGIN_AREA
)
922 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
923 + window_box_width (w
, TEXT_AREA
));
930 /* Return the frame-relative coordinate of the right edge of display
931 area AREA of window W. AREA < 0 means return the left edge of the
932 whole window, to the left of any bitmap area at the right side of
936 window_box_right (w
, area
)
940 return window_box_left (w
, area
) + window_box_width (w
, area
);
944 /* Get the bounding box of the display area AREA of window W, without
945 mode lines, in frame-relative coordinates. AREA < 0 means the
946 whole window, not including bitmap areas to the left and right of
947 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
948 coordinates of the upper-left corner of the box. Return in
949 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
952 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
955 int *box_x
, *box_y
, *box_width
, *box_height
;
957 struct frame
*f
= XFRAME (w
->frame
);
959 *box_width
= window_box_width (w
, area
);
960 *box_height
= window_box_height (w
);
961 *box_x
= window_box_left (w
, area
);
962 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
963 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
964 if (WINDOW_WANTS_HEADER_LINE_P (w
))
965 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
969 /* Get the bounding box of the display area AREA of window W, without
970 mode lines. AREA < 0 means the whole window, not including bitmap
971 areas to the left and right of the window. Return in *TOP_LEFT_X
972 and TOP_LEFT_Y the frame-relative pixel coordinates of the
973 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
974 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
978 window_box_edges (w
, area
, top_left_x
, top_left_y
,
979 bottom_right_x
, bottom_right_y
)
982 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
984 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
986 *bottom_right_x
+= *top_left_x
;
987 *bottom_right_y
+= *top_left_y
;
992 /***********************************************************************
994 ***********************************************************************/
996 /* Return the bottom y-position of the line the iterator IT is in.
997 This can modify IT's settings. */
1003 int line_height
= it
->max_ascent
+ it
->max_descent
;
1004 int line_top_y
= it
->current_y
;
1006 if (line_height
== 0)
1009 line_height
= last_height
;
1010 else if (IT_CHARPOS (*it
) < ZV
)
1012 move_it_by_lines (it
, 1, 1);
1013 line_height
= (it
->max_ascent
|| it
->max_descent
1014 ? it
->max_ascent
+ it
->max_descent
1019 struct glyph_row
*row
= it
->glyph_row
;
1021 /* Use the default character height. */
1022 it
->glyph_row
= NULL
;
1023 it
->what
= IT_CHARACTER
;
1026 PRODUCE_GLYPHS (it
);
1027 line_height
= it
->ascent
+ it
->descent
;
1028 it
->glyph_row
= row
;
1032 return line_top_y
+ line_height
;
1036 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1037 1 if POS is visible and the line containing POS is fully visible.
1038 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1039 and header-lines heights. */
1042 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1044 int charpos
, *fully
, exact_mode_line_heights_p
;
1047 struct text_pos top
;
1049 struct buffer
*old_buffer
= NULL
;
1051 if (XBUFFER (w
->buffer
) != current_buffer
)
1053 old_buffer
= current_buffer
;
1054 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1057 *fully
= visible_p
= 0;
1058 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1060 /* Compute exact mode line heights, if requested. */
1061 if (exact_mode_line_heights_p
)
1063 if (WINDOW_WANTS_MODELINE_P (w
))
1064 current_mode_line_height
1065 = display_mode_line (w
, MODE_LINE_FACE_ID
,
1066 current_buffer
->mode_line_format
);
1068 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1069 current_header_line_height
1070 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1071 current_buffer
->header_line_format
);
1074 start_display (&it
, w
, top
);
1075 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1076 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1078 /* Note that we may overshoot because of invisible text. */
1079 if (IT_CHARPOS (it
) >= charpos
)
1081 int top_y
= it
.current_y
;
1082 int bottom_y
= line_bottom_y (&it
);
1083 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1085 if (top_y
< window_top_y
)
1086 visible_p
= bottom_y
> window_top_y
;
1087 else if (top_y
< it
.last_visible_y
)
1090 *fully
= bottom_y
<= it
.last_visible_y
;
1093 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1095 move_it_by_lines (&it
, 1, 0);
1096 if (charpos
< IT_CHARPOS (it
))
1104 set_buffer_internal_1 (old_buffer
);
1106 current_header_line_height
= current_mode_line_height
= -1;
1111 /* Return the next character from STR which is MAXLEN bytes long.
1112 Return in *LEN the length of the character. This is like
1113 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1114 we find one, we return a `?', but with the length of the invalid
1118 string_char_and_length (str
, maxlen
, len
)
1124 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1125 if (!CHAR_VALID_P (c
, 1))
1126 /* We may not change the length here because other places in Emacs
1127 don't use this function, i.e. they silently accept invalid
1136 /* Given a position POS containing a valid character and byte position
1137 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1139 static struct text_pos
1140 string_pos_nchars_ahead (pos
, string
, nchars
)
1141 struct text_pos pos
;
1145 xassert (STRINGP (string
) && nchars
>= 0);
1147 if (STRING_MULTIBYTE (string
))
1149 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1150 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1155 string_char_and_length (p
, rest
, &len
);
1156 p
+= len
, rest
-= len
;
1157 xassert (rest
>= 0);
1159 BYTEPOS (pos
) += len
;
1163 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1169 /* Value is the text position, i.e. character and byte position,
1170 for character position CHARPOS in STRING. */
1172 static INLINE
struct text_pos
1173 string_pos (charpos
, string
)
1177 struct text_pos pos
;
1178 xassert (STRINGP (string
));
1179 xassert (charpos
>= 0);
1180 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1185 /* Value is a text position, i.e. character and byte position, for
1186 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1187 means recognize multibyte characters. */
1189 static struct text_pos
1190 c_string_pos (charpos
, s
, multibyte_p
)
1195 struct text_pos pos
;
1197 xassert (s
!= NULL
);
1198 xassert (charpos
>= 0);
1202 int rest
= strlen (s
), len
;
1204 SET_TEXT_POS (pos
, 0, 0);
1207 string_char_and_length (s
, rest
, &len
);
1208 s
+= len
, rest
-= len
;
1209 xassert (rest
>= 0);
1211 BYTEPOS (pos
) += len
;
1215 SET_TEXT_POS (pos
, charpos
, charpos
);
1221 /* Value is the number of characters in C string S. MULTIBYTE_P
1222 non-zero means recognize multibyte characters. */
1225 number_of_chars (s
, multibyte_p
)
1233 int rest
= strlen (s
), len
;
1234 unsigned char *p
= (unsigned char *) s
;
1236 for (nchars
= 0; rest
> 0; ++nchars
)
1238 string_char_and_length (p
, rest
, &len
);
1239 rest
-= len
, p
+= len
;
1243 nchars
= strlen (s
);
1249 /* Compute byte position NEWPOS->bytepos corresponding to
1250 NEWPOS->charpos. POS is a known position in string STRING.
1251 NEWPOS->charpos must be >= POS.charpos. */
1254 compute_string_pos (newpos
, pos
, string
)
1255 struct text_pos
*newpos
, pos
;
1258 xassert (STRINGP (string
));
1259 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1261 if (STRING_MULTIBYTE (string
))
1262 *newpos
= string_pos_nchars_ahead (pos
, string
,
1263 CHARPOS (*newpos
) - CHARPOS (pos
));
1265 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1270 /***********************************************************************
1271 Lisp form evaluation
1272 ***********************************************************************/
1274 /* Error handler for safe_eval and safe_call. */
1277 safe_eval_handler (arg
)
1280 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1285 /* Evaluate SEXPR and return the result, or nil if something went
1286 wrong. Prevent redisplay during the evaluation. */
1294 if (inhibit_eval_during_redisplay
)
1298 int count
= BINDING_STACK_SIZE ();
1299 struct gcpro gcpro1
;
1302 specbind (Qinhibit_redisplay
, Qt
);
1303 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
1306 val
= unbind_to (count
, val
);
1313 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1314 Return the result, or nil if something went wrong. Prevent
1315 redisplay during the evaluation. */
1318 safe_call (nargs
, args
)
1324 if (inhibit_eval_during_redisplay
)
1328 int count
= BINDING_STACK_SIZE ();
1329 struct gcpro gcpro1
;
1332 gcpro1
.nvars
= nargs
;
1333 specbind (Qinhibit_redisplay
, Qt
);
1334 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1337 val
= unbind_to (count
, val
);
1344 /* Call function FN with one argument ARG.
1345 Return the result, or nil if something went wrong. */
1348 safe_call1 (fn
, arg
)
1349 Lisp_Object fn
, arg
;
1351 Lisp_Object args
[2];
1354 return safe_call (2, args
);
1359 /***********************************************************************
1361 ***********************************************************************/
1365 /* Define CHECK_IT to perform sanity checks on iterators.
1366 This is for debugging. It is too slow to do unconditionally. */
1372 if (it
->method
== next_element_from_string
)
1374 xassert (STRINGP (it
->string
));
1375 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1377 else if (it
->method
== next_element_from_buffer
)
1379 /* Check that character and byte positions agree. */
1380 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1384 xassert (it
->current
.dpvec_index
>= 0);
1386 xassert (it
->current
.dpvec_index
< 0);
1389 #define CHECK_IT(IT) check_it ((IT))
1393 #define CHECK_IT(IT) (void) 0
1400 /* Check that the window end of window W is what we expect it
1401 to be---the last row in the current matrix displaying text. */
1404 check_window_end (w
)
1407 if (!MINI_WINDOW_P (w
)
1408 && !NILP (w
->window_end_valid
))
1410 struct glyph_row
*row
;
1411 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1412 XFASTINT (w
->window_end_vpos
)),
1414 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1415 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1419 #define CHECK_WINDOW_END(W) check_window_end ((W))
1421 #else /* not GLYPH_DEBUG */
1423 #define CHECK_WINDOW_END(W) (void) 0
1425 #endif /* not GLYPH_DEBUG */
1429 /***********************************************************************
1430 Iterator initialization
1431 ***********************************************************************/
1433 /* Initialize IT for displaying current_buffer in window W, starting
1434 at character position CHARPOS. CHARPOS < 0 means that no buffer
1435 position is specified which is useful when the iterator is assigned
1436 a position later. BYTEPOS is the byte position corresponding to
1437 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1439 If ROW is not null, calls to produce_glyphs with IT as parameter
1440 will produce glyphs in that row.
1442 BASE_FACE_ID is the id of a base face to use. It must be one of
1443 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1444 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1445 displaying the tool-bar.
1447 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1448 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1449 corresponding mode line glyph row of the desired matrix of W. */
1452 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1455 int charpos
, bytepos
;
1456 struct glyph_row
*row
;
1457 enum face_id base_face_id
;
1459 int highlight_region_p
;
1461 /* Some precondition checks. */
1462 xassert (w
!= NULL
&& it
!= NULL
);
1463 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1465 /* If face attributes have been changed since the last redisplay,
1466 free realized faces now because they depend on face definitions
1467 that might have changed. */
1468 if (face_change_count
)
1470 face_change_count
= 0;
1471 free_all_realized_faces (Qnil
);
1474 /* Use one of the mode line rows of W's desired matrix if
1478 if (base_face_id
== MODE_LINE_FACE_ID
)
1479 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1480 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1481 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1485 bzero (it
, sizeof *it
);
1486 it
->current
.overlay_string_index
= -1;
1487 it
->current
.dpvec_index
= -1;
1488 it
->base_face_id
= base_face_id
;
1490 /* The window in which we iterate over current_buffer: */
1491 XSETWINDOW (it
->window
, w
);
1493 it
->f
= XFRAME (w
->frame
);
1495 /* Extra space between lines (on window systems only). */
1496 if (base_face_id
== DEFAULT_FACE_ID
1497 && FRAME_WINDOW_P (it
->f
))
1499 if (NATNUMP (current_buffer
->extra_line_spacing
))
1500 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1501 else if (it
->f
->extra_line_spacing
> 0)
1502 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1505 /* If realized faces have been removed, e.g. because of face
1506 attribute changes of named faces, recompute them. When running
1507 in batch mode, the face cache of Vterminal_frame is null. If
1508 we happen to get called, make a dummy face cache. */
1513 FRAME_FACE_CACHE (it
->f
) == NULL
)
1514 init_frame_faces (it
->f
);
1515 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1516 recompute_basic_faces (it
->f
);
1518 /* Current value of the `space-width', and 'height' properties. */
1519 it
->space_width
= Qnil
;
1520 it
->font_height
= Qnil
;
1522 /* Are control characters displayed as `^C'? */
1523 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1525 /* -1 means everything between a CR and the following line end
1526 is invisible. >0 means lines indented more than this value are
1528 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1529 ? XFASTINT (current_buffer
->selective_display
)
1530 : (!NILP (current_buffer
->selective_display
)
1532 it
->selective_display_ellipsis_p
1533 = !NILP (current_buffer
->selective_display_ellipses
);
1535 /* Display table to use. */
1536 it
->dp
= window_display_table (w
);
1538 /* Are multibyte characters enabled in current_buffer? */
1539 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1541 /* Non-zero if we should highlight the region. */
1543 = (!NILP (Vtransient_mark_mode
)
1544 && !NILP (current_buffer
->mark_active
)
1545 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1547 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1548 start and end of a visible region in window IT->w. Set both to
1549 -1 to indicate no region. */
1550 if (highlight_region_p
1551 /* Maybe highlight only in selected window. */
1552 && (/* Either show region everywhere. */
1553 highlight_nonselected_windows
1554 /* Or show region in the selected window. */
1555 || w
== XWINDOW (selected_window
)
1556 /* Or show the region if we are in the mini-buffer and W is
1557 the window the mini-buffer refers to. */
1558 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1559 && WINDOWP (Vminibuf_scroll_window
)
1560 && w
== XWINDOW (Vminibuf_scroll_window
))))
1562 int charpos
= marker_position (current_buffer
->mark
);
1563 it
->region_beg_charpos
= min (PT
, charpos
);
1564 it
->region_end_charpos
= max (PT
, charpos
);
1567 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1569 /* Get the position at which the redisplay_end_trigger hook should
1570 be run, if it is to be run at all. */
1571 if (MARKERP (w
->redisplay_end_trigger
)
1572 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1573 it
->redisplay_end_trigger_charpos
1574 = marker_position (w
->redisplay_end_trigger
);
1575 else if (INTEGERP (w
->redisplay_end_trigger
))
1576 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1578 /* Correct bogus values of tab_width. */
1579 it
->tab_width
= XINT (current_buffer
->tab_width
);
1580 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1583 /* Are lines in the display truncated? */
1584 it
->truncate_lines_p
1585 = (base_face_id
!= DEFAULT_FACE_ID
1586 || XINT (it
->w
->hscroll
)
1587 || (truncate_partial_width_windows
1588 && !WINDOW_FULL_WIDTH_P (it
->w
))
1589 || !NILP (current_buffer
->truncate_lines
));
1591 /* Get dimensions of truncation and continuation glyphs. These are
1592 displayed as bitmaps under X, so we don't need them for such
1594 if (!FRAME_WINDOW_P (it
->f
))
1596 if (it
->truncate_lines_p
)
1598 /* We will need the truncation glyph. */
1599 xassert (it
->glyph_row
== NULL
);
1600 produce_special_glyphs (it
, IT_TRUNCATION
);
1601 it
->truncation_pixel_width
= it
->pixel_width
;
1605 /* We will need the continuation glyph. */
1606 xassert (it
->glyph_row
== NULL
);
1607 produce_special_glyphs (it
, IT_CONTINUATION
);
1608 it
->continuation_pixel_width
= it
->pixel_width
;
1611 /* Reset these values to zero becaue the produce_special_glyphs
1612 above has changed them. */
1613 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1614 it
->phys_ascent
= it
->phys_descent
= 0;
1617 /* Set this after getting the dimensions of truncation and
1618 continuation glyphs, so that we don't produce glyphs when calling
1619 produce_special_glyphs, above. */
1620 it
->glyph_row
= row
;
1621 it
->area
= TEXT_AREA
;
1623 /* Get the dimensions of the display area. The display area
1624 consists of the visible window area plus a horizontally scrolled
1625 part to the left of the window. All x-values are relative to the
1626 start of this total display area. */
1627 if (base_face_id
!= DEFAULT_FACE_ID
)
1629 /* Mode lines, menu bar in terminal frames. */
1630 it
->first_visible_x
= 0;
1631 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1636 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1637 it
->last_visible_x
= (it
->first_visible_x
1638 + window_box_width (w
, TEXT_AREA
));
1640 /* If we truncate lines, leave room for the truncator glyph(s) at
1641 the right margin. Otherwise, leave room for the continuation
1642 glyph(s). Truncation and continuation glyphs are not inserted
1643 for window-based redisplay. */
1644 if (!FRAME_WINDOW_P (it
->f
))
1646 if (it
->truncate_lines_p
)
1647 it
->last_visible_x
-= it
->truncation_pixel_width
;
1649 it
->last_visible_x
-= it
->continuation_pixel_width
;
1652 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1653 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1656 /* Leave room for a border glyph. */
1657 if (!FRAME_WINDOW_P (it
->f
)
1658 && !WINDOW_RIGHTMOST_P (it
->w
))
1659 it
->last_visible_x
-= 1;
1661 it
->last_visible_y
= window_text_bottom_y (w
);
1663 /* For mode lines and alike, arrange for the first glyph having a
1664 left box line if the face specifies a box. */
1665 if (base_face_id
!= DEFAULT_FACE_ID
)
1669 it
->face_id
= base_face_id
;
1671 /* If we have a boxed mode line, make the first character appear
1672 with a left box line. */
1673 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1674 if (face
->box
!= FACE_NO_BOX
)
1675 it
->start_of_box_run_p
= 1;
1678 /* If a buffer position was specified, set the iterator there,
1679 getting overlays and face properties from that position. */
1682 it
->end_charpos
= ZV
;
1684 IT_CHARPOS (*it
) = charpos
;
1686 /* Compute byte position if not specified. */
1688 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1690 IT_BYTEPOS (*it
) = bytepos
;
1692 /* Compute faces etc. */
1693 reseat (it
, it
->current
.pos
, 1);
1700 /* Initialize IT for the display of window W with window start POS. */
1703 start_display (it
, w
, pos
)
1706 struct text_pos pos
;
1708 struct glyph_row
*row
;
1709 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1711 row
= w
->desired_matrix
->rows
+ first_vpos
;
1712 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1714 if (!it
->truncate_lines_p
)
1716 int start_at_line_beg_p
;
1717 int first_y
= it
->current_y
;
1719 /* If window start is not at a line start, skip forward to POS to
1720 get the correct continuation lines width. */
1721 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1722 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1723 if (!start_at_line_beg_p
)
1725 reseat_at_previous_visible_line_start (it
);
1726 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1728 /* If lines are continued, this line may end in the middle
1729 of a multi-glyph character (e.g. a control character
1730 displayed as \003, or in the middle of an overlay
1731 string). In this case move_it_to above will not have
1732 taken us to the start of the continuation line but to the
1733 end of the continued line. */
1734 if (it
->current_x
> 0)
1736 if (it
->current
.dpvec_index
>= 0
1737 || it
->current
.overlay_string_index
>= 0)
1739 set_iterator_to_next (it
, 1);
1740 move_it_in_display_line_to (it
, -1, -1, 0);
1743 it
->continuation_lines_width
+= it
->current_x
;
1746 /* We're starting a new display line, not affected by the
1747 height of the continued line, so clear the appropriate
1748 fields in the iterator structure. */
1749 it
->max_ascent
= it
->max_descent
= 0;
1750 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1752 it
->current_y
= first_y
;
1754 it
->current_x
= it
->hpos
= 0;
1758 #if 0 /* Don't assert the following because start_display is sometimes
1759 called intentionally with a window start that is not at a
1760 line start. Please leave this code in as a comment. */
1762 /* Window start should be on a line start, now. */
1763 xassert (it
->continuation_lines_width
1764 || IT_CHARPOS (it
) == BEGV
1765 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1770 /* Return 1 if POS is a position in ellipses displayed for invisible
1771 text. W is the window we display, for text property lookup. */
1774 in_ellipses_for_invisible_text_p (pos
, w
)
1775 struct display_pos
*pos
;
1778 Lisp_Object prop
, window
;
1780 int charpos
= CHARPOS (pos
->pos
);
1782 /* If POS specifies a position in a display vector, this might
1783 be for an ellipsis displayed for invisible text. We won't
1784 get the iterator set up for delivering that ellipsis unless
1785 we make sure that it gets aware of the invisible text. */
1786 if (pos
->dpvec_index
>= 0
1787 && pos
->overlay_string_index
< 0
1788 && CHARPOS (pos
->string_pos
) < 0
1790 && (XSETWINDOW (window
, w
),
1791 prop
= Fget_char_property (make_number (charpos
),
1792 Qinvisible
, window
),
1793 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1795 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1797 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
1798 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
))
1806 /* Initialize IT for stepping through current_buffer in window W,
1807 starting at position POS that includes overlay string and display
1808 vector/ control character translation position information. */
1811 init_from_display_pos (it
, w
, pos
)
1814 struct display_pos
*pos
;
1816 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1818 /* If POS specifies a position in a display vector, this might
1819 be for an ellipsis displayed for invisible text. We won't
1820 get the iterator set up for delivering that ellipsis unless
1821 we make sure that it gets aware of the invisible text. */
1822 if (in_ellipses_for_invisible_text_p (pos
, w
))
1828 /* Keep in mind: the call to reseat in init_iterator skips invisible
1829 text, so we might end up at a position different from POS. This
1830 is only a problem when POS is a row start after a newline and an
1831 overlay starts there with an after-string, and the overlay has an
1832 invisible property. Since we don't skip invisible text in
1833 display_line and elsewhere immediately after consuming the
1834 newline before the row start, such a POS will not be in a string,
1835 but the call to init_iterator below will move us to the
1837 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1839 /* If position is within an overlay string, set up IT to the right
1841 if (pos
->overlay_string_index
>= 0)
1845 /* If the first overlay string happens to have a `display'
1846 property for an image, the iterator will be set up for that
1847 image, and we have to undo that setup first before we can
1848 correct the overlay string index. */
1849 if (it
->method
== next_element_from_image
)
1852 /* We already have the first chunk of overlay strings in
1853 IT->overlay_strings. Load more until the one for
1854 pos->overlay_string_index is in IT->overlay_strings. */
1855 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1857 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1858 it
->current
.overlay_string_index
= 0;
1861 load_overlay_strings (it
, 0);
1862 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1866 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1867 relative_index
= (it
->current
.overlay_string_index
1868 % OVERLAY_STRING_CHUNK_SIZE
);
1869 it
->string
= it
->overlay_strings
[relative_index
];
1870 xassert (STRINGP (it
->string
));
1871 it
->current
.string_pos
= pos
->string_pos
;
1872 it
->method
= next_element_from_string
;
1874 else if (it
->current
.overlay_string_index
>= 0)
1876 /* If POS says we're already after an overlay string ending at
1877 POS, make sure to pop the iterator because it will be in
1878 front of that overlay string. When POS is ZV, we've thereby
1879 also ``processed'' overlay strings at ZV. */
1882 it
->current
.overlay_string_index
= -1;
1883 it
->method
= next_element_from_buffer
;
1884 if (CHARPOS (pos
->pos
) == ZV
)
1885 it
->overlay_strings_at_end_processed_p
= 1;
1888 if (CHARPOS (pos
->string_pos
) >= 0)
1890 /* Recorded position is not in an overlay string, but in another
1891 string. This can only be a string from a `display' property.
1892 IT should already be filled with that string. */
1893 it
->current
.string_pos
= pos
->string_pos
;
1894 xassert (STRINGP (it
->string
));
1897 /* Restore position in display vector translations, control
1898 character translations or ellipses. */
1899 if (pos
->dpvec_index
>= 0)
1901 if (it
->dpvec
== NULL
)
1902 get_next_display_element (it
);
1903 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1904 it
->current
.dpvec_index
= pos
->dpvec_index
;
1911 /* Initialize IT for stepping through current_buffer in window W
1912 starting at ROW->start. */
1915 init_to_row_start (it
, w
, row
)
1918 struct glyph_row
*row
;
1920 init_from_display_pos (it
, w
, &row
->start
);
1921 it
->continuation_lines_width
= row
->continuation_lines_width
;
1926 /* Initialize IT for stepping through current_buffer in window W
1927 starting in the line following ROW, i.e. starting at ROW->end. */
1930 init_to_row_end (it
, w
, row
)
1933 struct glyph_row
*row
;
1935 init_from_display_pos (it
, w
, &row
->end
);
1937 if (row
->continued_p
)
1938 it
->continuation_lines_width
= (row
->continuation_lines_width
1939 + row
->pixel_width
);
1946 /***********************************************************************
1948 ***********************************************************************/
1950 /* Called when IT reaches IT->stop_charpos. Handle text property and
1951 overlay changes. Set IT->stop_charpos to the next position where
1958 enum prop_handled handled
;
1959 int handle_overlay_change_p
= 1;
1963 it
->current
.dpvec_index
= -1;
1967 handled
= HANDLED_NORMALLY
;
1969 /* Call text property handlers. */
1970 for (p
= it_props
; p
->handler
; ++p
)
1972 handled
= p
->handler (it
);
1974 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1976 else if (handled
== HANDLED_RETURN
)
1978 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1979 handle_overlay_change_p
= 0;
1982 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1984 /* Don't check for overlay strings below when set to deliver
1985 characters from a display vector. */
1986 if (it
->method
== next_element_from_display_vector
)
1987 handle_overlay_change_p
= 0;
1989 /* Handle overlay changes. */
1990 if (handle_overlay_change_p
)
1991 handled
= handle_overlay_change (it
);
1993 /* Determine where to stop next. */
1994 if (handled
== HANDLED_NORMALLY
)
1995 compute_stop_pos (it
);
1998 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2002 /* Compute IT->stop_charpos from text property and overlay change
2003 information for IT's current position. */
2006 compute_stop_pos (it
)
2009 register INTERVAL iv
, next_iv
;
2010 Lisp_Object object
, limit
, position
;
2012 /* If nowhere else, stop at the end. */
2013 it
->stop_charpos
= it
->end_charpos
;
2015 if (STRINGP (it
->string
))
2017 /* Strings are usually short, so don't limit the search for
2019 object
= it
->string
;
2021 position
= make_number (IT_STRING_CHARPOS (*it
));
2027 /* If next overlay change is in front of the current stop pos
2028 (which is IT->end_charpos), stop there. Note: value of
2029 next_overlay_change is point-max if no overlay change
2031 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2032 if (charpos
< it
->stop_charpos
)
2033 it
->stop_charpos
= charpos
;
2035 /* If showing the region, we have to stop at the region
2036 start or end because the face might change there. */
2037 if (it
->region_beg_charpos
> 0)
2039 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2040 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2041 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2042 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2045 /* Set up variables for computing the stop position from text
2046 property changes. */
2047 XSETBUFFER (object
, current_buffer
);
2048 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2049 position
= make_number (IT_CHARPOS (*it
));
2053 /* Get the interval containing IT's position. Value is a null
2054 interval if there isn't such an interval. */
2055 iv
= validate_interval_range (object
, &position
, &position
, 0);
2056 if (!NULL_INTERVAL_P (iv
))
2058 Lisp_Object values_here
[LAST_PROP_IDX
];
2061 /* Get properties here. */
2062 for (p
= it_props
; p
->handler
; ++p
)
2063 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2065 /* Look for an interval following iv that has different
2067 for (next_iv
= next_interval (iv
);
2068 (!NULL_INTERVAL_P (next_iv
)
2070 || XFASTINT (limit
) > next_iv
->position
));
2071 next_iv
= next_interval (next_iv
))
2073 for (p
= it_props
; p
->handler
; ++p
)
2075 Lisp_Object new_value
;
2077 new_value
= textget (next_iv
->plist
, *p
->name
);
2078 if (!EQ (values_here
[p
->idx
], new_value
))
2086 if (!NULL_INTERVAL_P (next_iv
))
2088 if (INTEGERP (limit
)
2089 && next_iv
->position
>= XFASTINT (limit
))
2090 /* No text property change up to limit. */
2091 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2093 /* Text properties change in next_iv. */
2094 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2098 xassert (STRINGP (it
->string
)
2099 || (it
->stop_charpos
>= BEGV
2100 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2104 /* Return the position of the next overlay change after POS in
2105 current_buffer. Value is point-max if no overlay change
2106 follows. This is like `next-overlay-change' but doesn't use
2110 next_overlay_change (pos
)
2115 Lisp_Object
*overlays
;
2119 /* Get all overlays at the given position. */
2121 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2122 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2123 if (noverlays
> len
)
2126 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2127 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2130 /* If any of these overlays ends before endpos,
2131 use its ending point instead. */
2132 for (i
= 0; i
< noverlays
; ++i
)
2137 oend
= OVERLAY_END (overlays
[i
]);
2138 oendpos
= OVERLAY_POSITION (oend
);
2139 endpos
= min (endpos
, oendpos
);
2147 /***********************************************************************
2149 ***********************************************************************/
2151 /* Handle changes in the `fontified' property of the current buffer by
2152 calling hook functions from Qfontification_functions to fontify
2155 static enum prop_handled
2156 handle_fontified_prop (it
)
2159 Lisp_Object prop
, pos
;
2160 enum prop_handled handled
= HANDLED_NORMALLY
;
2162 /* Get the value of the `fontified' property at IT's current buffer
2163 position. (The `fontified' property doesn't have a special
2164 meaning in strings.) If the value is nil, call functions from
2165 Qfontification_functions. */
2166 if (!STRINGP (it
->string
)
2168 && !NILP (Vfontification_functions
)
2169 && !NILP (Vrun_hooks
)
2170 && (pos
= make_number (IT_CHARPOS (*it
)),
2171 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2174 int count
= BINDING_STACK_SIZE ();
2177 val
= Vfontification_functions
;
2178 specbind (Qfontification_functions
, Qnil
);
2179 specbind (Qafter_change_functions
, Qnil
);
2181 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2182 safe_call1 (val
, pos
);
2185 Lisp_Object globals
, fn
;
2186 struct gcpro gcpro1
, gcpro2
;
2189 GCPRO2 (val
, globals
);
2191 for (; CONSP (val
); val
= XCDR (val
))
2197 /* A value of t indicates this hook has a local
2198 binding; it means to run the global binding too.
2199 In a global value, t should not occur. If it
2200 does, we must ignore it to avoid an endless
2202 for (globals
= Fdefault_value (Qfontification_functions
);
2204 globals
= XCDR (globals
))
2206 fn
= XCAR (globals
);
2208 safe_call1 (fn
, pos
);
2212 safe_call1 (fn
, pos
);
2218 unbind_to (count
, Qnil
);
2220 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2221 something. This avoids an endless loop if they failed to
2222 fontify the text for which reason ever. */
2223 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2224 handled
= HANDLED_RECOMPUTE_PROPS
;
2232 /***********************************************************************
2234 ***********************************************************************/
2236 /* Set up iterator IT from face properties at its current position.
2237 Called from handle_stop. */
2239 static enum prop_handled
2240 handle_face_prop (it
)
2243 int new_face_id
, next_stop
;
2245 if (!STRINGP (it
->string
))
2248 = face_at_buffer_position (it
->w
,
2250 it
->region_beg_charpos
,
2251 it
->region_end_charpos
,
2254 + TEXT_PROP_DISTANCE_LIMIT
),
2257 /* Is this a start of a run of characters with box face?
2258 Caveat: this can be called for a freshly initialized
2259 iterator; face_id is -1 is this case. We know that the new
2260 face will not change until limit, i.e. if the new face has a
2261 box, all characters up to limit will have one. But, as
2262 usual, we don't know whether limit is really the end. */
2263 if (new_face_id
!= it
->face_id
)
2265 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2267 /* If new face has a box but old face has not, this is
2268 the start of a run of characters with box, i.e. it has
2269 a shadow on the left side. The value of face_id of the
2270 iterator will be -1 if this is the initial call that gets
2271 the face. In this case, we have to look in front of IT's
2272 position and see whether there is a face != new_face_id. */
2273 it
->start_of_box_run_p
2274 = (new_face
->box
!= FACE_NO_BOX
2275 && (it
->face_id
>= 0
2276 || IT_CHARPOS (*it
) == BEG
2277 || new_face_id
!= face_before_it_pos (it
)));
2278 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2283 int base_face_id
, bufpos
;
2285 if (it
->current
.overlay_string_index
>= 0)
2286 bufpos
= IT_CHARPOS (*it
);
2290 /* For strings from a buffer, i.e. overlay strings or strings
2291 from a `display' property, use the face at IT's current
2292 buffer position as the base face to merge with, so that
2293 overlay strings appear in the same face as surrounding
2294 text, unless they specify their own faces. */
2295 base_face_id
= underlying_face_id (it
);
2297 new_face_id
= face_at_string_position (it
->w
,
2299 IT_STRING_CHARPOS (*it
),
2301 it
->region_beg_charpos
,
2302 it
->region_end_charpos
,
2306 #if 0 /* This shouldn't be neccessary. Let's check it. */
2307 /* If IT is used to display a mode line we would really like to
2308 use the mode line face instead of the frame's default face. */
2309 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2310 && new_face_id
== DEFAULT_FACE_ID
)
2311 new_face_id
= MODE_LINE_FACE_ID
;
2314 /* Is this a start of a run of characters with box? Caveat:
2315 this can be called for a freshly allocated iterator; face_id
2316 is -1 is this case. We know that the new face will not
2317 change until the next check pos, i.e. if the new face has a
2318 box, all characters up to that position will have a
2319 box. But, as usual, we don't know whether that position
2320 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
);
2324 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2326 /* If new face has a box but old face hasn't, this is the
2327 start of a run of characters with box, i.e. it has a
2328 shadow on the left side. */
2329 it
->start_of_box_run_p
2330 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2331 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2335 it
->face_id
= new_face_id
;
2336 return HANDLED_NORMALLY
;
2340 /* Return the ID of the face ``underlying'' IT's current position,
2341 which is in a string. If the iterator is associated with a
2342 buffer, return the face at IT's current buffer position.
2343 Otherwise, use the iterator's base_face_id. */
2346 underlying_face_id (it
)
2349 int face_id
= it
->base_face_id
, i
;
2351 xassert (STRINGP (it
->string
));
2353 for (i
= it
->sp
- 1; i
>= 0; --i
)
2354 if (NILP (it
->stack
[i
].string
))
2355 face_id
= it
->stack
[i
].face_id
;
2361 /* Compute the face one character before or after the current position
2362 of IT. BEFORE_P non-zero means get the face in front of IT's
2363 position. Value is the id of the face. */
2366 face_before_or_after_it_pos (it
, before_p
)
2371 int next_check_charpos
;
2372 struct text_pos pos
;
2374 xassert (it
->s
== NULL
);
2376 if (STRINGP (it
->string
))
2378 int bufpos
, base_face_id
;
2380 /* No face change past the end of the string (for the case
2381 we are padding with spaces). No face change before the
2383 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2384 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2387 /* Set pos to the position before or after IT's current position. */
2389 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2391 /* For composition, we must check the character after the
2393 pos
= (it
->what
== IT_COMPOSITION
2394 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2395 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2397 if (it
->current
.overlay_string_index
>= 0)
2398 bufpos
= IT_CHARPOS (*it
);
2402 base_face_id
= underlying_face_id (it
);
2404 /* Get the face for ASCII, or unibyte. */
2405 face_id
= face_at_string_position (it
->w
,
2409 it
->region_beg_charpos
,
2410 it
->region_end_charpos
,
2411 &next_check_charpos
,
2414 /* Correct the face for charsets different from ASCII. Do it
2415 for the multibyte case only. The face returned above is
2416 suitable for unibyte text if IT->string is unibyte. */
2417 if (STRING_MULTIBYTE (it
->string
))
2419 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2420 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2422 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2424 c
= string_char_and_length (p
, rest
, &len
);
2425 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2430 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2431 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2434 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2435 pos
= it
->current
.pos
;
2438 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2441 if (it
->what
== IT_COMPOSITION
)
2442 /* For composition, we must check the position after the
2444 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2446 INC_TEXT_POS (pos
, it
->multibyte_p
);
2449 /* Determine face for CHARSET_ASCII, or unibyte. */
2450 face_id
= face_at_buffer_position (it
->w
,
2452 it
->region_beg_charpos
,
2453 it
->region_end_charpos
,
2454 &next_check_charpos
,
2457 /* Correct the face for charsets different from ASCII. Do it
2458 for the multibyte case only. The face returned above is
2459 suitable for unibyte text if current_buffer is unibyte. */
2460 if (it
->multibyte_p
)
2462 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2463 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2464 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2473 /***********************************************************************
2475 ***********************************************************************/
2477 /* Set up iterator IT from invisible properties at its current
2478 position. Called from handle_stop. */
2480 static enum prop_handled
2481 handle_invisible_prop (it
)
2484 enum prop_handled handled
= HANDLED_NORMALLY
;
2486 if (STRINGP (it
->string
))
2488 extern Lisp_Object Qinvisible
;
2489 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2491 /* Get the value of the invisible text property at the
2492 current position. Value will be nil if there is no such
2494 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2495 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2498 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2500 handled
= HANDLED_RECOMPUTE_PROPS
;
2502 /* Get the position at which the next change of the
2503 invisible text property can be found in IT->string.
2504 Value will be nil if the property value is the same for
2505 all the rest of IT->string. */
2506 XSETINT (limit
, XSTRING (it
->string
)->size
);
2507 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2510 /* Text at current position is invisible. The next
2511 change in the property is at position end_charpos.
2512 Move IT's current position to that position. */
2513 if (INTEGERP (end_charpos
)
2514 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2516 struct text_pos old
;
2517 old
= it
->current
.string_pos
;
2518 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2519 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2523 /* The rest of the string is invisible. If this is an
2524 overlay string, proceed with the next overlay string
2525 or whatever comes and return a character from there. */
2526 if (it
->current
.overlay_string_index
>= 0)
2528 next_overlay_string (it
);
2529 /* Don't check for overlay strings when we just
2530 finished processing them. */
2531 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2535 struct Lisp_String
*s
= XSTRING (it
->string
);
2536 IT_STRING_CHARPOS (*it
) = s
->size
;
2537 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2544 int visible_p
, newpos
, next_stop
, start_charpos
;
2545 Lisp_Object pos
, prop
, overlay
;
2547 /* First of all, is there invisible text at this position? */
2548 start_charpos
= IT_CHARPOS (*it
);
2549 pos
= make_number (IT_CHARPOS (*it
));
2550 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2553 /* If we are on invisible text, skip over it. */
2554 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2555 && IT_CHARPOS (*it
) < it
->end_charpos
)
2557 /* Record whether we have to display an ellipsis for the
2559 int display_ellipsis_p
2560 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2562 handled
= HANDLED_RECOMPUTE_PROPS
;
2564 /* Loop skipping over invisible text. The loop is left at
2565 ZV or with IT on the first char being visible again. */
2568 /* Try to skip some invisible text. Return value is the
2569 position reached which can be equal to IT's position
2570 if there is nothing invisible here. This skips both
2571 over invisible text properties and overlays with
2572 invisible property. */
2573 newpos
= skip_invisible (IT_CHARPOS (*it
),
2574 &next_stop
, ZV
, it
->window
);
2576 /* If we skipped nothing at all we weren't at invisible
2577 text in the first place. If everything to the end of
2578 the buffer was skipped, end the loop. */
2579 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2583 /* We skipped some characters but not necessarily
2584 all there are. Check if we ended up on visible
2585 text. Fget_char_property returns the property of
2586 the char before the given position, i.e. if we
2587 get visible_p = 1, this means that the char at
2588 newpos is visible. */
2589 pos
= make_number (newpos
);
2590 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2591 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2594 /* If we ended up on invisible text, proceed to
2595 skip starting with next_stop. */
2597 IT_CHARPOS (*it
) = next_stop
;
2601 /* The position newpos is now either ZV or on visible text. */
2602 IT_CHARPOS (*it
) = newpos
;
2603 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2605 /* If there are before-strings at the start of invisible
2606 text, and the text is invisible because of a text
2607 property, arrange to show before-strings because 20.x did
2608 it that way. (If the text is invisible because of an
2609 overlay property instead of a text property, this is
2610 already handled in the overlay code.) */
2612 && get_overlay_strings (it
, start_charpos
))
2614 handled
= HANDLED_RECOMPUTE_PROPS
;
2615 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2617 else if (display_ellipsis_p
)
2618 setup_for_ellipsis (it
);
2626 /* Make iterator IT return `...' next. */
2629 setup_for_ellipsis (it
)
2633 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2635 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2636 it
->dpvec
= v
->contents
;
2637 it
->dpend
= v
->contents
+ v
->size
;
2641 /* Default `...'. */
2642 it
->dpvec
= default_invis_vector
;
2643 it
->dpend
= default_invis_vector
+ 3;
2646 /* The ellipsis display does not replace the display of the
2647 character at the new position. Indicate this by setting
2648 IT->dpvec_char_len to zero. */
2649 it
->dpvec_char_len
= 0;
2651 it
->current
.dpvec_index
= 0;
2652 it
->method
= next_element_from_display_vector
;
2657 /***********************************************************************
2659 ***********************************************************************/
2661 /* Set up iterator IT from `display' property at its current position.
2662 Called from handle_stop. */
2664 static enum prop_handled
2665 handle_display_prop (it
)
2668 Lisp_Object prop
, object
;
2669 struct text_pos
*position
;
2670 int display_replaced_p
= 0;
2672 if (STRINGP (it
->string
))
2674 object
= it
->string
;
2675 position
= &it
->current
.string_pos
;
2679 object
= it
->w
->buffer
;
2680 position
= &it
->current
.pos
;
2683 /* Reset those iterator values set from display property values. */
2684 it
->font_height
= Qnil
;
2685 it
->space_width
= Qnil
;
2688 /* We don't support recursive `display' properties, i.e. string
2689 values that have a string `display' property, that have a string
2690 `display' property etc. */
2691 if (!it
->string_from_display_prop_p
)
2692 it
->area
= TEXT_AREA
;
2694 prop
= Fget_char_property (make_number (position
->charpos
),
2697 return HANDLED_NORMALLY
;
2700 /* Simple properties. */
2701 && !EQ (XCAR (prop
), Qimage
)
2702 && !EQ (XCAR (prop
), Qspace
)
2703 && !EQ (XCAR (prop
), Qwhen
)
2704 && !EQ (XCAR (prop
), Qspace_width
)
2705 && !EQ (XCAR (prop
), Qheight
)
2706 && !EQ (XCAR (prop
), Qraise
)
2707 /* Marginal area specifications. */
2708 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2709 && !NILP (XCAR (prop
)))
2711 for (; CONSP (prop
); prop
= XCDR (prop
))
2713 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2714 position
, display_replaced_p
))
2715 display_replaced_p
= 1;
2718 else if (VECTORP (prop
))
2721 for (i
= 0; i
< ASIZE (prop
); ++i
)
2722 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2723 position
, display_replaced_p
))
2724 display_replaced_p
= 1;
2728 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2729 display_replaced_p
= 1;
2732 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2736 /* Value is the position of the end of the `display' property starting
2737 at START_POS in OBJECT. */
2739 static struct text_pos
2740 display_prop_end (it
, object
, start_pos
)
2743 struct text_pos start_pos
;
2746 struct text_pos end_pos
;
2748 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2749 Qdisplay
, object
, Qnil
);
2750 CHARPOS (end_pos
) = XFASTINT (end
);
2751 if (STRINGP (object
))
2752 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2754 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2760 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2761 is the object in which the `display' property was found. *POSITION
2762 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2763 means that we previously saw a display sub-property which already
2764 replaced text display with something else, for example an image;
2765 ignore such properties after the first one has been processed.
2767 If PROP is a `space' or `image' sub-property, set *POSITION to the
2768 end position of the `display' property.
2770 Value is non-zero something was found which replaces the display
2771 of buffer or string text. */
2774 handle_single_display_prop (it
, prop
, object
, position
,
2775 display_replaced_before_p
)
2779 struct text_pos
*position
;
2780 int display_replaced_before_p
;
2783 int replaces_text_display_p
= 0;
2786 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2787 evaluated. If the result is nil, VALUE is ignored. */
2789 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2798 if (!NILP (form
) && !EQ (form
, Qt
))
2800 struct gcpro gcpro1
;
2801 struct text_pos end_pos
, pt
;
2804 end_pos
= display_prop_end (it
, object
, *position
);
2806 /* Temporarily set point to the end position, and then evaluate
2807 the form. This makes `(eolp)' work as FORM. */
2808 if (BUFFERP (object
))
2811 BYTEPOS (pt
) = PT_BYTE
;
2812 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2815 form
= safe_eval (form
);
2817 if (BUFFERP (object
))
2818 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2826 && EQ (XCAR (prop
), Qheight
)
2827 && CONSP (XCDR (prop
)))
2829 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2832 /* `(height HEIGHT)'. */
2833 it
->font_height
= XCAR (XCDR (prop
));
2834 if (!NILP (it
->font_height
))
2836 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2837 int new_height
= -1;
2839 if (CONSP (it
->font_height
)
2840 && (EQ (XCAR (it
->font_height
), Qplus
)
2841 || EQ (XCAR (it
->font_height
), Qminus
))
2842 && CONSP (XCDR (it
->font_height
))
2843 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2845 /* `(+ N)' or `(- N)' where N is an integer. */
2846 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2847 if (EQ (XCAR (it
->font_height
), Qplus
))
2849 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2851 else if (FUNCTIONP (it
->font_height
))
2853 /* Call function with current height as argument.
2854 Value is the new height. */
2856 height
= safe_call1 (it
->font_height
,
2857 face
->lface
[LFACE_HEIGHT_INDEX
]);
2858 if (NUMBERP (height
))
2859 new_height
= XFLOATINT (height
);
2861 else if (NUMBERP (it
->font_height
))
2863 /* Value is a multiple of the canonical char height. */
2866 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2867 new_height
= (XFLOATINT (it
->font_height
)
2868 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2872 /* Evaluate IT->font_height with `height' bound to the
2873 current specified height to get the new height. */
2875 int count
= BINDING_STACK_SIZE ();
2877 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2878 value
= safe_eval (it
->font_height
);
2879 unbind_to (count
, Qnil
);
2881 if (NUMBERP (value
))
2882 new_height
= XFLOATINT (value
);
2886 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2889 else if (CONSP (prop
)
2890 && EQ (XCAR (prop
), Qspace_width
)
2891 && CONSP (XCDR (prop
)))
2893 /* `(space_width WIDTH)'. */
2894 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2897 value
= XCAR (XCDR (prop
));
2898 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2899 it
->space_width
= value
;
2901 else if (CONSP (prop
)
2902 && EQ (XCAR (prop
), Qraise
)
2903 && CONSP (XCDR (prop
)))
2905 /* `(raise FACTOR)'. */
2906 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2909 #ifdef HAVE_WINDOW_SYSTEM
2910 value
= XCAR (XCDR (prop
));
2911 if (NUMBERP (value
))
2913 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2914 it
->voffset
= - (XFLOATINT (value
)
2915 * (FONT_HEIGHT (face
->font
)));
2917 #endif /* HAVE_WINDOW_SYSTEM */
2919 else if (!it
->string_from_display_prop_p
)
2921 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2922 VALUE) or `((margin nil) VALUE)' or VALUE. */
2923 Lisp_Object location
, value
;
2924 struct text_pos start_pos
;
2927 /* Characters having this form of property are not displayed, so
2928 we have to find the end of the property. */
2929 start_pos
= *position
;
2930 *position
= display_prop_end (it
, object
, start_pos
);
2933 /* Let's stop at the new position and assume that all
2934 text properties change there. */
2935 it
->stop_charpos
= position
->charpos
;
2937 location
= Qunbound
;
2938 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2942 value
= XCDR (prop
);
2944 value
= XCAR (value
);
2947 if (EQ (XCAR (tem
), Qmargin
)
2948 && (tem
= XCDR (tem
),
2949 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2951 || EQ (tem
, Qleft_margin
)
2952 || EQ (tem
, Qright_margin
))))
2956 if (EQ (location
, Qunbound
))
2962 #ifdef HAVE_WINDOW_SYSTEM
2963 if (FRAME_TERMCAP_P (it
->f
))
2964 valid_p
= STRINGP (value
);
2966 valid_p
= (STRINGP (value
)
2967 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2968 || valid_image_p (value
));
2969 #else /* not HAVE_WINDOW_SYSTEM */
2970 valid_p
= STRINGP (value
);
2971 #endif /* not HAVE_WINDOW_SYSTEM */
2973 if ((EQ (location
, Qleft_margin
)
2974 || EQ (location
, Qright_margin
)
2977 && !display_replaced_before_p
)
2979 replaces_text_display_p
= 1;
2981 /* Save current settings of IT so that we can restore them
2982 when we are finished with the glyph property value. */
2985 if (NILP (location
))
2986 it
->area
= TEXT_AREA
;
2987 else if (EQ (location
, Qleft_margin
))
2988 it
->area
= LEFT_MARGIN_AREA
;
2990 it
->area
= RIGHT_MARGIN_AREA
;
2992 if (STRINGP (value
))
2995 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2996 it
->current
.overlay_string_index
= -1;
2997 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2998 it
->end_charpos
= it
->string_nchars
2999 = XSTRING (it
->string
)->size
;
3000 it
->method
= next_element_from_string
;
3001 it
->stop_charpos
= 0;
3002 it
->string_from_display_prop_p
= 1;
3003 /* Say that we haven't consumed the characters with
3004 `display' property yet. The call to pop_it in
3005 set_iterator_to_next will clean this up. */
3006 *position
= start_pos
;
3008 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3010 it
->method
= next_element_from_stretch
;
3012 it
->current
.pos
= it
->position
= start_pos
;
3014 #ifdef HAVE_WINDOW_SYSTEM
3017 it
->what
= IT_IMAGE
;
3018 it
->image_id
= lookup_image (it
->f
, value
);
3019 it
->position
= start_pos
;
3020 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3021 it
->method
= next_element_from_image
;
3023 /* Say that we haven't consumed the characters with
3024 `display' property yet. The call to pop_it in
3025 set_iterator_to_next will clean this up. */
3026 *position
= start_pos
;
3028 #endif /* HAVE_WINDOW_SYSTEM */
3031 /* Invalid property or property not supported. Restore
3032 the position to what it was before. */
3033 *position
= start_pos
;
3036 return replaces_text_display_p
;
3040 /* Check if PROP is a display sub-property value whose text should be
3041 treated as intangible. */
3044 single_display_prop_intangible_p (prop
)
3047 /* Skip over `when FORM'. */
3048 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3059 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3060 we don't need to treat text as intangible. */
3061 if (EQ (XCAR (prop
), Qmargin
))
3069 || EQ (XCAR (prop
), Qleft_margin
)
3070 || EQ (XCAR (prop
), Qright_margin
))
3074 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3078 /* Check if PROP is a display property value whose text should be
3079 treated as intangible. */
3082 display_prop_intangible_p (prop
)
3086 && CONSP (XCAR (prop
))
3087 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3089 /* A list of sub-properties. */
3090 while (CONSP (prop
))
3092 if (single_display_prop_intangible_p (XCAR (prop
)))
3097 else if (VECTORP (prop
))
3099 /* A vector of sub-properties. */
3101 for (i
= 0; i
< ASIZE (prop
); ++i
)
3102 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3106 return single_display_prop_intangible_p (prop
);
3112 /* Return 1 if PROP is a display sub-property value containing STRING. */
3115 single_display_prop_string_p (prop
, string
)
3116 Lisp_Object prop
, string
;
3118 extern Lisp_Object Qwhen
, Qmargin
;
3120 if (EQ (string
, prop
))
3123 /* Skip over `when FORM'. */
3124 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3133 /* Skip over `margin LOCATION'. */
3134 if (EQ (XCAR (prop
), Qmargin
))
3145 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3149 /* Return 1 if STRING appears in the `display' property PROP. */
3152 display_prop_string_p (prop
, string
)
3153 Lisp_Object prop
, string
;
3155 extern Lisp_Object Qwhen
, Qmargin
;
3158 && CONSP (XCAR (prop
))
3159 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3161 /* A list of sub-properties. */
3162 while (CONSP (prop
))
3164 if (single_display_prop_string_p (XCAR (prop
), string
))
3169 else if (VECTORP (prop
))
3171 /* A vector of sub-properties. */
3173 for (i
= 0; i
< ASIZE (prop
); ++i
)
3174 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3178 return single_display_prop_string_p (prop
, string
);
3184 /* Determine from which buffer position in W's buffer STRING comes
3185 from. AROUND_CHARPOS is an approximate position where it could
3186 be from. Value is the buffer position or 0 if it couldn't be
3189 W's buffer must be current.
3191 This function is necessary because we don't record buffer positions
3192 in glyphs generated from strings (to keep struct glyph small).
3193 This function may only use code that doesn't eval because it is
3194 called asynchronously from note_mouse_highlight. */
3197 string_buffer_position (w
, string
, around_charpos
)
3202 Lisp_Object around
= make_number (around_charpos
);
3203 Lisp_Object limit
, prop
, pos
;
3204 const int MAX_DISTANCE
= 1000;
3207 pos
= make_number (around_charpos
);
3208 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3209 while (!found
&& !EQ (pos
, limit
))
3211 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3212 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3215 pos
= Fnext_single_property_change (pos
, Qdisplay
, Qnil
, limit
);
3220 pos
= make_number (around_charpos
);
3221 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3222 while (!found
&& !EQ (pos
, limit
))
3224 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3225 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3228 pos
= Fprevious_single_property_change (pos
, Qdisplay
, Qnil
,
3233 return found
? XINT (pos
) : 0;
3238 /***********************************************************************
3239 `composition' property
3240 ***********************************************************************/
3242 /* Set up iterator IT from `composition' property at its current
3243 position. Called from handle_stop. */
3245 static enum prop_handled
3246 handle_composition_prop (it
)
3249 Lisp_Object prop
, string
;
3250 int pos
, pos_byte
, end
;
3251 enum prop_handled handled
= HANDLED_NORMALLY
;
3253 if (STRINGP (it
->string
))
3255 pos
= IT_STRING_CHARPOS (*it
);
3256 pos_byte
= IT_STRING_BYTEPOS (*it
);
3257 string
= it
->string
;
3261 pos
= IT_CHARPOS (*it
);
3262 pos_byte
= IT_BYTEPOS (*it
);
3266 /* If there's a valid composition and point is not inside of the
3267 composition (in the case that the composition is from the current
3268 buffer), draw a glyph composed from the composition components. */
3269 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3270 && COMPOSITION_VALID_P (pos
, end
, prop
)
3271 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3273 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3277 it
->method
= next_element_from_composition
;
3279 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3280 /* For a terminal, draw only the first character of the
3282 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3283 it
->len
= (STRINGP (it
->string
)
3284 ? string_char_to_byte (it
->string
, end
)
3285 : CHAR_TO_BYTE (end
)) - pos_byte
;
3286 it
->stop_charpos
= end
;
3287 handled
= HANDLED_RETURN
;
3296 /***********************************************************************
3298 ***********************************************************************/
3300 /* The following structure is used to record overlay strings for
3301 later sorting in load_overlay_strings. */
3303 struct overlay_entry
3305 Lisp_Object overlay
;
3312 /* Set up iterator IT from overlay strings at its current position.
3313 Called from handle_stop. */
3315 static enum prop_handled
3316 handle_overlay_change (it
)
3319 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3320 return HANDLED_RECOMPUTE_PROPS
;
3322 return HANDLED_NORMALLY
;
3326 /* Set up the next overlay string for delivery by IT, if there is an
3327 overlay string to deliver. Called by set_iterator_to_next when the
3328 end of the current overlay string is reached. If there are more
3329 overlay strings to display, IT->string and
3330 IT->current.overlay_string_index are set appropriately here.
3331 Otherwise IT->string is set to nil. */
3334 next_overlay_string (it
)
3337 ++it
->current
.overlay_string_index
;
3338 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3340 /* No more overlay strings. Restore IT's settings to what
3341 they were before overlay strings were processed, and
3342 continue to deliver from current_buffer. */
3343 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3346 xassert (it
->stop_charpos
>= BEGV
3347 && it
->stop_charpos
<= it
->end_charpos
);
3349 it
->current
.overlay_string_index
= -1;
3350 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3351 it
->n_overlay_strings
= 0;
3352 it
->method
= next_element_from_buffer
;
3354 /* If we're at the end of the buffer, record that we have
3355 processed the overlay strings there already, so that
3356 next_element_from_buffer doesn't try it again. */
3357 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3358 it
->overlay_strings_at_end_processed_p
= 1;
3360 /* If we have to display `...' for invisible text, set
3361 the iterator up for that. */
3362 if (display_ellipsis_p
)
3363 setup_for_ellipsis (it
);
3367 /* There are more overlay strings to process. If
3368 IT->current.overlay_string_index has advanced to a position
3369 where we must load IT->overlay_strings with more strings, do
3371 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3373 if (it
->current
.overlay_string_index
&& i
== 0)
3374 load_overlay_strings (it
, 0);
3376 /* Initialize IT to deliver display elements from the overlay
3378 it
->string
= it
->overlay_strings
[i
];
3379 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3380 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3381 it
->method
= next_element_from_string
;
3382 it
->stop_charpos
= 0;
3389 /* Compare two overlay_entry structures E1 and E2. Used as a
3390 comparison function for qsort in load_overlay_strings. Overlay
3391 strings for the same position are sorted so that
3393 1. All after-strings come in front of before-strings, except
3394 when they come from the same overlay.
3396 2. Within after-strings, strings are sorted so that overlay strings
3397 from overlays with higher priorities come first.
3399 2. Within before-strings, strings are sorted so that overlay
3400 strings from overlays with higher priorities come last.
3402 Value is analogous to strcmp. */
3406 compare_overlay_entries (e1
, e2
)
3409 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3410 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3413 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3415 /* Let after-strings appear in front of before-strings if
3416 they come from different overlays. */
3417 if (EQ (entry1
->overlay
, entry2
->overlay
))
3418 result
= entry1
->after_string_p
? 1 : -1;
3420 result
= entry1
->after_string_p
? -1 : 1;
3422 else if (entry1
->after_string_p
)
3423 /* After-strings sorted in order of decreasing priority. */
3424 result
= entry2
->priority
- entry1
->priority
;
3426 /* Before-strings sorted in order of increasing priority. */
3427 result
= entry1
->priority
- entry2
->priority
;
3433 /* Load the vector IT->overlay_strings with overlay strings from IT's
3434 current buffer position, or from CHARPOS if that is > 0. Set
3435 IT->n_overlays to the total number of overlay strings found.
3437 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3438 a time. On entry into load_overlay_strings,
3439 IT->current.overlay_string_index gives the number of overlay
3440 strings that have already been loaded by previous calls to this
3443 IT->add_overlay_start contains an additional overlay start
3444 position to consider for taking overlay strings from, if non-zero.
3445 This position comes into play when the overlay has an `invisible'
3446 property, and both before and after-strings. When we've skipped to
3447 the end of the overlay, because of its `invisible' property, we
3448 nevertheless want its before-string to appear.
3449 IT->add_overlay_start will contain the overlay start position
3452 Overlay strings are sorted so that after-string strings come in
3453 front of before-string strings. Within before and after-strings,
3454 strings are sorted by overlay priority. See also function
3455 compare_overlay_entries. */
3458 load_overlay_strings (it
, charpos
)
3462 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3463 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3466 int n
= 0, i
, j
, invis_p
;
3467 struct overlay_entry
*entries
3468 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3471 charpos
= IT_CHARPOS (*it
);
3473 /* Append the overlay string STRING of overlay OVERLAY to vector
3474 `entries' which has size `size' and currently contains `n'
3475 elements. AFTER_P non-zero means STRING is an after-string of
3477 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3480 Lisp_Object priority; \
3484 int new_size = 2 * size; \
3485 struct overlay_entry *old = entries; \
3487 (struct overlay_entry *) alloca (new_size \
3488 * sizeof *entries); \
3489 bcopy (old, entries, size * sizeof *entries); \
3493 entries[n].string = (STRING); \
3494 entries[n].overlay = (OVERLAY); \
3495 priority = Foverlay_get ((OVERLAY), Qpriority); \
3496 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3497 entries[n].after_string_p = (AFTER_P); \
3502 /* Process overlay before the overlay center. */
3503 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3505 overlay
= XCAR (ov
);
3506 xassert (OVERLAYP (overlay
));
3507 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3508 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3513 /* Skip this overlay if it doesn't start or end at IT's current
3515 if (end
!= charpos
&& start
!= charpos
)
3518 /* Skip this overlay if it doesn't apply to IT->w. */
3519 window
= Foverlay_get (overlay
, Qwindow
);
3520 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3523 /* If the text ``under'' the overlay is invisible, both before-
3524 and after-strings from this overlay are visible; start and
3525 end position are indistinguishable. */
3526 invisible
= Foverlay_get (overlay
, Qinvisible
);
3527 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3529 /* If overlay has a non-empty before-string, record it. */
3530 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3531 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3532 && XSTRING (str
)->size
)
3533 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3535 /* If overlay has a non-empty after-string, record it. */
3536 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3537 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3538 && XSTRING (str
)->size
)
3539 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3542 /* Process overlays after the overlay center. */
3543 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3545 overlay
= XCAR (ov
);
3546 xassert (OVERLAYP (overlay
));
3547 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3548 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3550 if (start
> charpos
)
3553 /* Skip this overlay if it doesn't start or end at IT's current
3555 if (end
!= charpos
&& start
!= charpos
)
3558 /* Skip this overlay if it doesn't apply to IT->w. */
3559 window
= Foverlay_get (overlay
, Qwindow
);
3560 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3563 /* If the text ``under'' the overlay is invisible, it has a zero
3564 dimension, and both before- and after-strings apply. */
3565 invisible
= Foverlay_get (overlay
, Qinvisible
);
3566 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3568 /* If overlay has a non-empty before-string, record it. */
3569 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3570 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3571 && XSTRING (str
)->size
)
3572 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3574 /* If overlay has a non-empty after-string, record it. */
3575 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3576 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3577 && XSTRING (str
)->size
)
3578 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3581 #undef RECORD_OVERLAY_STRING
3585 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3587 /* Record the total number of strings to process. */
3588 it
->n_overlay_strings
= n
;
3590 /* IT->current.overlay_string_index is the number of overlay strings
3591 that have already been consumed by IT. Copy some of the
3592 remaining overlay strings to IT->overlay_strings. */
3594 j
= it
->current
.overlay_string_index
;
3595 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3596 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3602 /* Get the first chunk of overlay strings at IT's current buffer
3603 position, or at CHARPOS if that is > 0. Value is non-zero if at
3604 least one overlay string was found. */
3607 get_overlay_strings (it
, charpos
)
3611 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3612 process. This fills IT->overlay_strings with strings, and sets
3613 IT->n_overlay_strings to the total number of strings to process.
3614 IT->pos.overlay_string_index has to be set temporarily to zero
3615 because load_overlay_strings needs this; it must be set to -1
3616 when no overlay strings are found because a zero value would
3617 indicate a position in the first overlay string. */
3618 it
->current
.overlay_string_index
= 0;
3619 load_overlay_strings (it
, charpos
);
3621 /* If we found overlay strings, set up IT to deliver display
3622 elements from the first one. Otherwise set up IT to deliver
3623 from current_buffer. */
3624 if (it
->n_overlay_strings
)
3626 /* Make sure we know settings in current_buffer, so that we can
3627 restore meaningful values when we're done with the overlay
3629 compute_stop_pos (it
);
3630 xassert (it
->face_id
>= 0);
3632 /* Save IT's settings. They are restored after all overlay
3633 strings have been processed. */
3634 xassert (it
->sp
== 0);
3637 /* Set up IT to deliver display elements from the first overlay
3639 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3640 it
->string
= it
->overlay_strings
[0];
3641 it
->stop_charpos
= 0;
3642 it
->end_charpos
= XSTRING (it
->string
)->size
;
3643 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3644 xassert (STRINGP (it
->string
));
3645 it
->method
= next_element_from_string
;
3650 it
->current
.overlay_string_index
= -1;
3651 it
->method
= next_element_from_buffer
;
3656 /* Value is non-zero if we found at least one overlay string. */
3657 return STRINGP (it
->string
);
3662 /***********************************************************************
3663 Saving and restoring state
3664 ***********************************************************************/
3666 /* Save current settings of IT on IT->stack. Called, for example,
3667 before setting up IT for an overlay string, to be able to restore
3668 IT's settings to what they were after the overlay string has been
3675 struct iterator_stack_entry
*p
;
3677 xassert (it
->sp
< 2);
3678 p
= it
->stack
+ it
->sp
;
3680 p
->stop_charpos
= it
->stop_charpos
;
3681 xassert (it
->face_id
>= 0);
3682 p
->face_id
= it
->face_id
;
3683 p
->string
= it
->string
;
3684 p
->pos
= it
->current
;
3685 p
->end_charpos
= it
->end_charpos
;
3686 p
->string_nchars
= it
->string_nchars
;
3688 p
->multibyte_p
= it
->multibyte_p
;
3689 p
->space_width
= it
->space_width
;
3690 p
->font_height
= it
->font_height
;
3691 p
->voffset
= it
->voffset
;
3692 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3693 p
->display_ellipsis_p
= 0;
3698 /* Restore IT's settings from IT->stack. Called, for example, when no
3699 more overlay strings must be processed, and we return to delivering
3700 display elements from a buffer, or when the end of a string from a
3701 `display' property is reached and we return to delivering display
3702 elements from an overlay string, or from a buffer. */
3708 struct iterator_stack_entry
*p
;
3710 xassert (it
->sp
> 0);
3712 p
= it
->stack
+ it
->sp
;
3713 it
->stop_charpos
= p
->stop_charpos
;
3714 it
->face_id
= p
->face_id
;
3715 it
->string
= p
->string
;
3716 it
->current
= p
->pos
;
3717 it
->end_charpos
= p
->end_charpos
;
3718 it
->string_nchars
= p
->string_nchars
;
3720 it
->multibyte_p
= p
->multibyte_p
;
3721 it
->space_width
= p
->space_width
;
3722 it
->font_height
= p
->font_height
;
3723 it
->voffset
= p
->voffset
;
3724 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3729 /***********************************************************************
3731 ***********************************************************************/
3733 /* Set IT's current position to the previous line start. */
3736 back_to_previous_line_start (it
)
3739 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3740 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3744 /* Move IT to the next line start.
3746 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3747 we skipped over part of the text (as opposed to moving the iterator
3748 continuously over the text). Otherwise, don't change the value
3751 Newlines may come from buffer text, overlay strings, or strings
3752 displayed via the `display' property. That's the reason we can't
3753 simply use find_next_newline_no_quit.
3755 Note that this function may not skip over invisible text that is so
3756 because of text properties and immediately follows a newline. If
3757 it would, function reseat_at_next_visible_line_start, when called
3758 from set_iterator_to_next, would effectively make invisible
3759 characters following a newline part of the wrong glyph row, which
3760 leads to wrong cursor motion. */
3763 forward_to_next_line_start (it
, skipped_p
)
3767 int old_selective
, newline_found_p
, n
;
3768 const int MAX_NEWLINE_DISTANCE
= 500;
3770 /* If already on a newline, just consume it to avoid unintended
3771 skipping over invisible text below. */
3772 if (it
->what
== IT_CHARACTER
3774 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3776 set_iterator_to_next (it
, 0);
3781 /* Don't handle selective display in the following. It's (a)
3782 unnecessary because it's done by the caller, and (b) leads to an
3783 infinite recursion because next_element_from_ellipsis indirectly
3784 calls this function. */
3785 old_selective
= it
->selective
;
3788 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3789 from buffer text. */
3790 for (n
= newline_found_p
= 0;
3791 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3792 n
+= STRINGP (it
->string
) ? 0 : 1)
3794 if (!get_next_display_element (it
))
3796 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3797 set_iterator_to_next (it
, 0);
3800 /* If we didn't find a newline near enough, see if we can use a
3802 if (n
== MAX_NEWLINE_DISTANCE
)
3804 int start
= IT_CHARPOS (*it
);
3805 int limit
= find_next_newline_no_quit (start
, 1);
3808 xassert (!STRINGP (it
->string
));
3810 /* If there isn't any `display' property in sight, and no
3811 overlays, we can just use the position of the newline in
3813 if (it
->stop_charpos
>= limit
3814 || ((pos
= Fnext_single_property_change (make_number (start
),
3816 Qnil
, make_number (limit
)),
3818 && next_overlay_change (start
) == ZV
))
3820 IT_CHARPOS (*it
) = limit
;
3821 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3822 *skipped_p
= newline_found_p
= 1;
3826 while (get_next_display_element (it
)
3827 && !newline_found_p
)
3829 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3830 set_iterator_to_next (it
, 0);
3835 it
->selective
= old_selective
;
3836 return newline_found_p
;
3840 /* Set IT's current position to the previous visible line start. Skip
3841 invisible text that is so either due to text properties or due to
3842 selective display. Caution: this does not change IT->current_x and
3846 back_to_previous_visible_line_start (it
)
3851 /* Go back one newline if not on BEGV already. */
3852 if (IT_CHARPOS (*it
) > BEGV
)
3853 back_to_previous_line_start (it
);
3855 /* Move over lines that are invisible because of selective display
3856 or text properties. */
3857 while (IT_CHARPOS (*it
) > BEGV
3862 /* If selective > 0, then lines indented more than that values
3864 if (it
->selective
> 0
3865 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3872 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3873 Qinvisible
, it
->window
);
3874 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3878 /* Back one more newline if the current one is invisible. */
3880 back_to_previous_line_start (it
);
3883 xassert (IT_CHARPOS (*it
) >= BEGV
);
3884 xassert (IT_CHARPOS (*it
) == BEGV
3885 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3890 /* Reseat iterator IT at the previous visible line start. Skip
3891 invisible text that is so either due to text properties or due to
3892 selective display. At the end, update IT's overlay information,
3893 face information etc. */
3896 reseat_at_previous_visible_line_start (it
)
3899 back_to_previous_visible_line_start (it
);
3900 reseat (it
, it
->current
.pos
, 1);
3905 /* Reseat iterator IT on the next visible line start in the current
3906 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3907 preceding the line start. Skip over invisible text that is so
3908 because of selective display. Compute faces, overlays etc at the
3909 new position. Note that this function does not skip over text that
3910 is invisible because of text properties. */
3913 reseat_at_next_visible_line_start (it
, on_newline_p
)
3917 int newline_found_p
, skipped_p
= 0;
3919 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3921 /* Skip over lines that are invisible because they are indented
3922 more than the value of IT->selective. */
3923 if (it
->selective
> 0)
3924 while (IT_CHARPOS (*it
) < ZV
3925 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3928 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3929 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3932 /* Position on the newline if that's what's requested. */
3933 if (on_newline_p
&& newline_found_p
)
3935 if (STRINGP (it
->string
))
3937 if (IT_STRING_CHARPOS (*it
) > 0)
3939 --IT_STRING_CHARPOS (*it
);
3940 --IT_STRING_BYTEPOS (*it
);
3943 else if (IT_CHARPOS (*it
) > BEGV
)
3947 reseat (it
, it
->current
.pos
, 0);
3951 reseat (it
, it
->current
.pos
, 0);
3958 /***********************************************************************
3959 Changing an iterator's position
3960 ***********************************************************************/
3962 /* Change IT's current position to POS in current_buffer. If FORCE_P
3963 is non-zero, always check for text properties at the new position.
3964 Otherwise, text properties are only looked up if POS >=
3965 IT->check_charpos of a property. */
3968 reseat (it
, pos
, force_p
)
3970 struct text_pos pos
;
3973 int original_pos
= IT_CHARPOS (*it
);
3975 reseat_1 (it
, pos
, 0);
3977 /* Determine where to check text properties. Avoid doing it
3978 where possible because text property lookup is very expensive. */
3980 || CHARPOS (pos
) > it
->stop_charpos
3981 || CHARPOS (pos
) < original_pos
)
3988 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3989 IT->stop_pos to POS, also. */
3992 reseat_1 (it
, pos
, set_stop_p
)
3994 struct text_pos pos
;
3997 /* Don't call this function when scanning a C string. */
3998 xassert (it
->s
== NULL
);
4000 /* POS must be a reasonable value. */
4001 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4003 it
->current
.pos
= it
->position
= pos
;
4004 XSETBUFFER (it
->object
, current_buffer
);
4005 it
->end_charpos
= ZV
;
4007 it
->current
.dpvec_index
= -1;
4008 it
->current
.overlay_string_index
= -1;
4009 IT_STRING_CHARPOS (*it
) = -1;
4010 IT_STRING_BYTEPOS (*it
) = -1;
4012 it
->method
= next_element_from_buffer
;
4014 it
->face_before_selective_p
= 0;
4017 it
->stop_charpos
= CHARPOS (pos
);
4021 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4022 If S is non-null, it is a C string to iterate over. Otherwise,
4023 STRING gives a Lisp string to iterate over.
4025 If PRECISION > 0, don't return more then PRECISION number of
4026 characters from the string.
4028 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4029 characters have been returned. FIELD_WIDTH < 0 means an infinite
4032 MULTIBYTE = 0 means disable processing of multibyte characters,
4033 MULTIBYTE > 0 means enable it,
4034 MULTIBYTE < 0 means use IT->multibyte_p.
4036 IT must be initialized via a prior call to init_iterator before
4037 calling this function. */
4040 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4045 int precision
, field_width
, multibyte
;
4047 /* No region in strings. */
4048 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4050 /* No text property checks performed by default, but see below. */
4051 it
->stop_charpos
= -1;
4053 /* Set iterator position and end position. */
4054 bzero (&it
->current
, sizeof it
->current
);
4055 it
->current
.overlay_string_index
= -1;
4056 it
->current
.dpvec_index
= -1;
4057 xassert (charpos
>= 0);
4059 /* If STRING is specified, use its multibyteness, otherwise use the
4060 setting of MULTIBYTE, if specified. */
4062 it
->multibyte_p
= multibyte
> 0;
4066 xassert (STRINGP (string
));
4067 it
->string
= string
;
4069 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
4070 it
->method
= next_element_from_string
;
4071 it
->current
.string_pos
= string_pos (charpos
, string
);
4078 /* Note that we use IT->current.pos, not it->current.string_pos,
4079 for displaying C strings. */
4080 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4081 if (it
->multibyte_p
)
4083 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4084 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4088 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4089 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4092 it
->method
= next_element_from_c_string
;
4095 /* PRECISION > 0 means don't return more than PRECISION characters
4097 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4098 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4100 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4101 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4102 FIELD_WIDTH < 0 means infinite field width. This is useful for
4103 padding with `-' at the end of a mode line. */
4104 if (field_width
< 0)
4105 field_width
= INFINITY
;
4106 if (field_width
> it
->end_charpos
- charpos
)
4107 it
->end_charpos
= charpos
+ field_width
;
4109 /* Use the standard display table for displaying strings. */
4110 if (DISP_TABLE_P (Vstandard_display_table
))
4111 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4113 it
->stop_charpos
= charpos
;
4119 /***********************************************************************
4121 ***********************************************************************/
4123 /* Load IT's display element fields with information about the next
4124 display element from the current position of IT. Value is zero if
4125 end of buffer (or C string) is reached. */
4128 get_next_display_element (it
)
4131 /* Non-zero means that we found an display element. Zero means that
4132 we hit the end of what we iterate over. Performance note: the
4133 function pointer `method' used here turns out to be faster than
4134 using a sequence of if-statements. */
4135 int success_p
= (*it
->method
) (it
);
4137 if (it
->what
== IT_CHARACTER
)
4139 /* Map via display table or translate control characters.
4140 IT->c, IT->len etc. have been set to the next character by
4141 the function call above. If we have a display table, and it
4142 contains an entry for IT->c, translate it. Don't do this if
4143 IT->c itself comes from a display table, otherwise we could
4144 end up in an infinite recursion. (An alternative could be to
4145 count the recursion depth of this function and signal an
4146 error when a certain maximum depth is reached.) Is it worth
4148 if (success_p
&& it
->dpvec
== NULL
)
4153 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4156 struct Lisp_Vector
*v
= XVECTOR (dv
);
4158 /* Return the first character from the display table
4159 entry, if not empty. If empty, don't display the
4160 current character. */
4163 it
->dpvec_char_len
= it
->len
;
4164 it
->dpvec
= v
->contents
;
4165 it
->dpend
= v
->contents
+ v
->size
;
4166 it
->current
.dpvec_index
= 0;
4167 it
->method
= next_element_from_display_vector
;
4168 success_p
= get_next_display_element (it
);
4172 set_iterator_to_next (it
, 0);
4173 success_p
= get_next_display_element (it
);
4177 /* Translate control characters into `\003' or `^C' form.
4178 Control characters coming from a display table entry are
4179 currently not translated because we use IT->dpvec to hold
4180 the translation. This could easily be changed but I
4181 don't believe that it is worth doing.
4183 Non-printable multibyte characters are also translated
4185 else if ((it
->c
< ' '
4186 && (it
->area
!= TEXT_AREA
4187 || (it
->c
!= '\n' && it
->c
!= '\t')))
4190 || !CHAR_PRINTABLE_P (it
->c
))
4192 /* IT->c is a control character which must be displayed
4193 either as '\003' or as `^C' where the '\\' and '^'
4194 can be defined in the display table. Fill
4195 IT->ctl_chars with glyphs for what we have to
4196 display. Then, set IT->dpvec to these glyphs. */
4199 if (it
->c
< 128 && it
->ctl_arrow_p
)
4201 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4203 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4204 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4205 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4207 g
= FAST_MAKE_GLYPH ('^', 0);
4208 XSETINT (it
->ctl_chars
[0], g
);
4210 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4211 XSETINT (it
->ctl_chars
[1], g
);
4213 /* Set up IT->dpvec and return first character from it. */
4214 it
->dpvec_char_len
= it
->len
;
4215 it
->dpvec
= it
->ctl_chars
;
4216 it
->dpend
= it
->dpvec
+ 2;
4217 it
->current
.dpvec_index
= 0;
4218 it
->method
= next_element_from_display_vector
;
4219 get_next_display_element (it
);
4223 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4228 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4230 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4231 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4232 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4234 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4236 if (SINGLE_BYTE_CHAR_P (it
->c
))
4237 str
[0] = it
->c
, len
= 1;
4240 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4243 /* It's an invalid character, which
4244 shouldn't happen actually, but due to
4245 bugs it may happen. Let's print the char
4246 as is, there's not much meaningful we can
4249 str
[1] = it
->c
>> 8;
4250 str
[2] = it
->c
>> 16;
4251 str
[3] = it
->c
>> 24;
4256 for (i
= 0; i
< len
; i
++)
4258 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4259 /* Insert three more glyphs into IT->ctl_chars for
4260 the octal display of the character. */
4261 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4262 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4263 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4264 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4265 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4266 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4269 /* Set up IT->dpvec and return the first character
4271 it
->dpvec_char_len
= it
->len
;
4272 it
->dpvec
= it
->ctl_chars
;
4273 it
->dpend
= it
->dpvec
+ len
* 4;
4274 it
->current
.dpvec_index
= 0;
4275 it
->method
= next_element_from_display_vector
;
4276 get_next_display_element (it
);
4281 /* Adjust face id for a multibyte character. There are no
4282 multibyte character in unibyte text. */
4285 && FRAME_WINDOW_P (it
->f
))
4287 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4288 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4292 /* Is this character the last one of a run of characters with
4293 box? If yes, set IT->end_of_box_run_p to 1. */
4300 it
->end_of_box_run_p
4301 = ((face_id
= face_after_it_pos (it
),
4302 face_id
!= it
->face_id
)
4303 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4304 face
->box
== FACE_NO_BOX
));
4307 /* Value is 0 if end of buffer or string reached. */
4312 /* Move IT to the next display element.
4314 RESEAT_P non-zero means if called on a newline in buffer text,
4315 skip to the next visible line start.
4317 Functions get_next_display_element and set_iterator_to_next are
4318 separate because I find this arrangement easier to handle than a
4319 get_next_display_element function that also increments IT's
4320 position. The way it is we can first look at an iterator's current
4321 display element, decide whether it fits on a line, and if it does,
4322 increment the iterator position. The other way around we probably
4323 would either need a flag indicating whether the iterator has to be
4324 incremented the next time, or we would have to implement a
4325 decrement position function which would not be easy to write. */
4328 set_iterator_to_next (it
, reseat_p
)
4332 /* Reset flags indicating start and end of a sequence of characters
4333 with box. Reset them at the start of this function because
4334 moving the iterator to a new position might set them. */
4335 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4337 if (it
->method
== next_element_from_buffer
)
4339 /* The current display element of IT is a character from
4340 current_buffer. Advance in the buffer, and maybe skip over
4341 invisible lines that are so because of selective display. */
4342 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4343 reseat_at_next_visible_line_start (it
, 0);
4346 xassert (it
->len
!= 0);
4347 IT_BYTEPOS (*it
) += it
->len
;
4348 IT_CHARPOS (*it
) += 1;
4349 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4352 else if (it
->method
== next_element_from_composition
)
4354 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4355 if (STRINGP (it
->string
))
4357 IT_STRING_BYTEPOS (*it
) += it
->len
;
4358 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4359 it
->method
= next_element_from_string
;
4360 goto consider_string_end
;
4364 IT_BYTEPOS (*it
) += it
->len
;
4365 IT_CHARPOS (*it
) += it
->cmp_len
;
4366 it
->method
= next_element_from_buffer
;
4369 else if (it
->method
== next_element_from_c_string
)
4371 /* Current display element of IT is from a C string. */
4372 IT_BYTEPOS (*it
) += it
->len
;
4373 IT_CHARPOS (*it
) += 1;
4375 else if (it
->method
== next_element_from_display_vector
)
4377 /* Current display element of IT is from a display table entry.
4378 Advance in the display table definition. Reset it to null if
4379 end reached, and continue with characters from buffers/
4381 ++it
->current
.dpvec_index
;
4383 /* Restore face of the iterator to what they were before the
4384 display vector entry (these entries may contain faces). */
4385 it
->face_id
= it
->saved_face_id
;
4387 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4390 it
->method
= next_element_from_c_string
;
4391 else if (STRINGP (it
->string
))
4392 it
->method
= next_element_from_string
;
4394 it
->method
= next_element_from_buffer
;
4397 it
->current
.dpvec_index
= -1;
4399 /* Skip over characters which were displayed via IT->dpvec. */
4400 if (it
->dpvec_char_len
< 0)
4401 reseat_at_next_visible_line_start (it
, 1);
4402 else if (it
->dpvec_char_len
> 0)
4404 it
->len
= it
->dpvec_char_len
;
4405 set_iterator_to_next (it
, reseat_p
);
4409 else if (it
->method
== next_element_from_string
)
4411 /* Current display element is a character from a Lisp string. */
4412 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4413 IT_STRING_BYTEPOS (*it
) += it
->len
;
4414 IT_STRING_CHARPOS (*it
) += 1;
4416 consider_string_end
:
4418 if (it
->current
.overlay_string_index
>= 0)
4420 /* IT->string is an overlay string. Advance to the
4421 next, if there is one. */
4422 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4423 next_overlay_string (it
);
4427 /* IT->string is not an overlay string. If we reached
4428 its end, and there is something on IT->stack, proceed
4429 with what is on the stack. This can be either another
4430 string, this time an overlay string, or a buffer. */
4431 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4435 if (!STRINGP (it
->string
))
4436 it
->method
= next_element_from_buffer
;
4438 goto consider_string_end
;
4442 else if (it
->method
== next_element_from_image
4443 || it
->method
== next_element_from_stretch
)
4445 /* The position etc with which we have to proceed are on
4446 the stack. The position may be at the end of a string,
4447 if the `display' property takes up the whole string. */
4450 if (STRINGP (it
->string
))
4452 it
->method
= next_element_from_string
;
4453 goto consider_string_end
;
4456 it
->method
= next_element_from_buffer
;
4459 /* There are no other methods defined, so this should be a bug. */
4462 xassert (it
->method
!= next_element_from_string
4463 || (STRINGP (it
->string
)
4464 && IT_STRING_CHARPOS (*it
) >= 0));
4468 /* Load IT's display element fields with information about the next
4469 display element which comes from a display table entry or from the
4470 result of translating a control character to one of the forms `^C'
4471 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4474 next_element_from_display_vector (it
)
4478 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4480 /* Remember the current face id in case glyphs specify faces.
4481 IT's face is restored in set_iterator_to_next. */
4482 it
->saved_face_id
= it
->face_id
;
4484 if (INTEGERP (*it
->dpvec
)
4485 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4490 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4491 it
->c
= FAST_GLYPH_CHAR (g
);
4492 it
->len
= CHAR_BYTES (it
->c
);
4494 /* The entry may contain a face id to use. Such a face id is
4495 the id of a Lisp face, not a realized face. A face id of
4496 zero means no face is specified. */
4497 lface_id
= FAST_GLYPH_FACE (g
);
4500 /* The function returns -1 if lface_id is invalid. */
4501 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4503 it
->face_id
= face_id
;
4507 /* Display table entry is invalid. Return a space. */
4508 it
->c
= ' ', it
->len
= 1;
4510 /* Don't change position and object of the iterator here. They are
4511 still the values of the character that had this display table
4512 entry or was translated, and that's what we want. */
4513 it
->what
= IT_CHARACTER
;
4518 /* Load IT with the next display element from Lisp string IT->string.
4519 IT->current.string_pos is the current position within the string.
4520 If IT->current.overlay_string_index >= 0, the Lisp string is an
4524 next_element_from_string (it
)
4527 struct text_pos position
;
4529 xassert (STRINGP (it
->string
));
4530 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4531 position
= it
->current
.string_pos
;
4533 /* Time to check for invisible text? */
4534 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4535 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4539 /* Since a handler may have changed IT->method, we must
4541 return get_next_display_element (it
);
4544 if (it
->current
.overlay_string_index
>= 0)
4546 /* Get the next character from an overlay string. In overlay
4547 strings, There is no field width or padding with spaces to
4549 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4554 else if (STRING_MULTIBYTE (it
->string
))
4556 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4557 - IT_STRING_BYTEPOS (*it
));
4558 unsigned char *s
= (XSTRING (it
->string
)->data
4559 + IT_STRING_BYTEPOS (*it
));
4560 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4564 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4570 /* Get the next character from a Lisp string that is not an
4571 overlay string. Such strings come from the mode line, for
4572 example. We may have to pad with spaces, or truncate the
4573 string. See also next_element_from_c_string. */
4574 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4579 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4581 /* Pad with spaces. */
4582 it
->c
= ' ', it
->len
= 1;
4583 CHARPOS (position
) = BYTEPOS (position
) = -1;
4585 else if (STRING_MULTIBYTE (it
->string
))
4587 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4588 - IT_STRING_BYTEPOS (*it
));
4589 unsigned char *s
= (XSTRING (it
->string
)->data
4590 + IT_STRING_BYTEPOS (*it
));
4591 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4595 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4600 /* Record what we have and where it came from. Note that we store a
4601 buffer position in IT->position although it could arguably be a
4603 it
->what
= IT_CHARACTER
;
4604 it
->object
= it
->string
;
4605 it
->position
= position
;
4610 /* Load IT with next display element from C string IT->s.
4611 IT->string_nchars is the maximum number of characters to return
4612 from the string. IT->end_charpos may be greater than
4613 IT->string_nchars when this function is called, in which case we
4614 may have to return padding spaces. Value is zero if end of string
4615 reached, including padding spaces. */
4618 next_element_from_c_string (it
)
4624 it
->what
= IT_CHARACTER
;
4625 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4628 /* IT's position can be greater IT->string_nchars in case a field
4629 width or precision has been specified when the iterator was
4631 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4633 /* End of the game. */
4637 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4639 /* Pad with spaces. */
4640 it
->c
= ' ', it
->len
= 1;
4641 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4643 else if (it
->multibyte_p
)
4645 /* Implementation note: The calls to strlen apparently aren't a
4646 performance problem because there is no noticeable performance
4647 difference between Emacs running in unibyte or multibyte mode. */
4648 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4649 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4653 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4659 /* Set up IT to return characters from an ellipsis, if appropriate.
4660 The definition of the ellipsis glyphs may come from a display table
4661 entry. This function Fills IT with the first glyph from the
4662 ellipsis if an ellipsis is to be displayed. */
4665 next_element_from_ellipsis (it
)
4668 if (it
->selective_display_ellipsis_p
)
4670 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4672 /* Use the display table definition for `...'. Invalid glyphs
4673 will be handled by the method returning elements from dpvec. */
4674 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4675 it
->dpvec_char_len
= it
->len
;
4676 it
->dpvec
= v
->contents
;
4677 it
->dpend
= v
->contents
+ v
->size
;
4678 it
->current
.dpvec_index
= 0;
4679 it
->method
= next_element_from_display_vector
;
4683 /* Use default `...' which is stored in default_invis_vector. */
4684 it
->dpvec_char_len
= it
->len
;
4685 it
->dpvec
= default_invis_vector
;
4686 it
->dpend
= default_invis_vector
+ 3;
4687 it
->current
.dpvec_index
= 0;
4688 it
->method
= next_element_from_display_vector
;
4693 /* The face at the current position may be different from the
4694 face we find after the invisible text. Remember what it
4695 was in IT->saved_face_id, and signal that it's there by
4696 setting face_before_selective_p. */
4697 it
->saved_face_id
= it
->face_id
;
4698 it
->method
= next_element_from_buffer
;
4699 reseat_at_next_visible_line_start (it
, 1);
4700 it
->face_before_selective_p
= 1;
4703 return get_next_display_element (it
);
4707 /* Deliver an image display element. The iterator IT is already
4708 filled with image information (done in handle_display_prop). Value
4713 next_element_from_image (it
)
4716 it
->what
= IT_IMAGE
;
4721 /* Fill iterator IT with next display element from a stretch glyph
4722 property. IT->object is the value of the text property. Value is
4726 next_element_from_stretch (it
)
4729 it
->what
= IT_STRETCH
;
4734 /* Load IT with the next display element from current_buffer. Value
4735 is zero if end of buffer reached. IT->stop_charpos is the next
4736 position at which to stop and check for text properties or buffer
4740 next_element_from_buffer (it
)
4745 /* Check this assumption, otherwise, we would never enter the
4746 if-statement, below. */
4747 xassert (IT_CHARPOS (*it
) >= BEGV
4748 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4750 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4752 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4754 int overlay_strings_follow_p
;
4756 /* End of the game, except when overlay strings follow that
4757 haven't been returned yet. */
4758 if (it
->overlay_strings_at_end_processed_p
)
4759 overlay_strings_follow_p
= 0;
4762 it
->overlay_strings_at_end_processed_p
= 1;
4763 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4766 if (overlay_strings_follow_p
)
4767 success_p
= get_next_display_element (it
);
4771 it
->position
= it
->current
.pos
;
4778 return get_next_display_element (it
);
4783 /* No face changes, overlays etc. in sight, so just return a
4784 character from current_buffer. */
4787 /* Maybe run the redisplay end trigger hook. Performance note:
4788 This doesn't seem to cost measurable time. */
4789 if (it
->redisplay_end_trigger_charpos
4791 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4792 run_redisplay_end_trigger_hook (it
);
4794 /* Get the next character, maybe multibyte. */
4795 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4796 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4798 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4799 - IT_BYTEPOS (*it
));
4800 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4803 it
->c
= *p
, it
->len
= 1;
4805 /* Record what we have and where it came from. */
4806 it
->what
= IT_CHARACTER
;;
4807 it
->object
= it
->w
->buffer
;
4808 it
->position
= it
->current
.pos
;
4810 /* Normally we return the character found above, except when we
4811 really want to return an ellipsis for selective display. */
4816 /* A value of selective > 0 means hide lines indented more
4817 than that number of columns. */
4818 if (it
->selective
> 0
4819 && IT_CHARPOS (*it
) + 1 < ZV
4820 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4821 IT_BYTEPOS (*it
) + 1,
4824 success_p
= next_element_from_ellipsis (it
);
4825 it
->dpvec_char_len
= -1;
4828 else if (it
->c
== '\r' && it
->selective
== -1)
4830 /* A value of selective == -1 means that everything from the
4831 CR to the end of the line is invisible, with maybe an
4832 ellipsis displayed for it. */
4833 success_p
= next_element_from_ellipsis (it
);
4834 it
->dpvec_char_len
= -1;
4839 /* Value is zero if end of buffer reached. */
4840 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4845 /* Run the redisplay end trigger hook for IT. */
4848 run_redisplay_end_trigger_hook (it
)
4851 Lisp_Object args
[3];
4853 /* IT->glyph_row should be non-null, i.e. we should be actually
4854 displaying something, or otherwise we should not run the hook. */
4855 xassert (it
->glyph_row
);
4857 /* Set up hook arguments. */
4858 args
[0] = Qredisplay_end_trigger_functions
;
4859 args
[1] = it
->window
;
4860 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4861 it
->redisplay_end_trigger_charpos
= 0;
4863 /* Since we are *trying* to run these functions, don't try to run
4864 them again, even if they get an error. */
4865 it
->w
->redisplay_end_trigger
= Qnil
;
4866 Frun_hook_with_args (3, args
);
4868 /* Notice if it changed the face of the character we are on. */
4869 handle_face_prop (it
);
4873 /* Deliver a composition display element. The iterator IT is already
4874 filled with composition information (done in
4875 handle_composition_prop). Value is always 1. */
4878 next_element_from_composition (it
)
4881 it
->what
= IT_COMPOSITION
;
4882 it
->position
= (STRINGP (it
->string
)
4883 ? it
->current
.string_pos
4890 /***********************************************************************
4891 Moving an iterator without producing glyphs
4892 ***********************************************************************/
4894 /* Move iterator IT to a specified buffer or X position within one
4895 line on the display without producing glyphs.
4897 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4898 whichever is reached first.
4900 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4902 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4903 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4904 TO_X includes the amount by which a window is horizontally
4909 MOVE_POS_MATCH_OR_ZV
4910 - when TO_POS or ZV was reached.
4913 -when TO_X was reached before TO_POS or ZV were reached.
4916 - when we reached the end of the display area and the line must
4920 - when we reached the end of the display area and the line is
4924 - when we stopped at a line end, i.e. a newline or a CR and selective
4927 static enum move_it_result
4928 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4930 int to_charpos
, to_x
, op
;
4932 enum move_it_result result
= MOVE_UNDEFINED
;
4933 struct glyph_row
*saved_glyph_row
;
4935 /* Don't produce glyphs in produce_glyphs. */
4936 saved_glyph_row
= it
->glyph_row
;
4937 it
->glyph_row
= NULL
;
4941 int x
, i
, ascent
= 0, descent
= 0;
4943 /* Stop when ZV or TO_CHARPOS reached. */
4944 if (!get_next_display_element (it
)
4945 || ((op
& MOVE_TO_POS
) != 0
4946 && BUFFERP (it
->object
)
4947 && IT_CHARPOS (*it
) >= to_charpos
))
4949 result
= MOVE_POS_MATCH_OR_ZV
;
4953 /* The call to produce_glyphs will get the metrics of the
4954 display element IT is loaded with. We record in x the
4955 x-position before this display element in case it does not
4959 /* Remember the line height so far in case the next element doesn't
4961 if (!it
->truncate_lines_p
)
4963 ascent
= it
->max_ascent
;
4964 descent
= it
->max_descent
;
4967 PRODUCE_GLYPHS (it
);
4969 if (it
->area
!= TEXT_AREA
)
4971 set_iterator_to_next (it
, 1);
4975 /* The number of glyphs we get back in IT->nglyphs will normally
4976 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4977 character on a terminal frame, or (iii) a line end. For the
4978 second case, IT->nglyphs - 1 padding glyphs will be present
4979 (on X frames, there is only one glyph produced for a
4980 composite character.
4982 The behavior implemented below means, for continuation lines,
4983 that as many spaces of a TAB as fit on the current line are
4984 displayed there. For terminal frames, as many glyphs of a
4985 multi-glyph character are displayed in the current line, too.
4986 This is what the old redisplay code did, and we keep it that
4987 way. Under X, the whole shape of a complex character must
4988 fit on the line or it will be completely displayed in the
4991 Note that both for tabs and padding glyphs, all glyphs have
4995 /* More than one glyph or glyph doesn't fit on line. All
4996 glyphs have the same width. */
4997 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5000 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5002 new_x
= x
+ single_glyph_width
;
5004 /* We want to leave anything reaching TO_X to the caller. */
5005 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5008 result
= MOVE_X_REACHED
;
5011 else if (/* Lines are continued. */
5012 !it
->truncate_lines_p
5013 && (/* And glyph doesn't fit on the line. */
5014 new_x
> it
->last_visible_x
5015 /* Or it fits exactly and we're on a window
5017 || (new_x
== it
->last_visible_x
5018 && FRAME_WINDOW_P (it
->f
))))
5020 if (/* IT->hpos == 0 means the very first glyph
5021 doesn't fit on the line, e.g. a wide image. */
5023 || (new_x
== it
->last_visible_x
5024 && FRAME_WINDOW_P (it
->f
)))
5027 it
->current_x
= new_x
;
5028 if (i
== it
->nglyphs
- 1)
5029 set_iterator_to_next (it
, 1);
5034 it
->max_ascent
= ascent
;
5035 it
->max_descent
= descent
;
5038 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5040 result
= MOVE_LINE_CONTINUED
;
5043 else if (new_x
> it
->first_visible_x
)
5045 /* Glyph is visible. Increment number of glyphs that
5046 would be displayed. */
5051 /* Glyph is completely off the left margin of the display
5052 area. Nothing to do. */
5056 if (result
!= MOVE_UNDEFINED
)
5059 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5061 /* Stop when TO_X specified and reached. This check is
5062 necessary here because of lines consisting of a line end,
5063 only. The line end will not produce any glyphs and we
5064 would never get MOVE_X_REACHED. */
5065 xassert (it
->nglyphs
== 0);
5066 result
= MOVE_X_REACHED
;
5070 /* Is this a line end? If yes, we're done. */
5071 if (ITERATOR_AT_END_OF_LINE_P (it
))
5073 result
= MOVE_NEWLINE_OR_CR
;
5077 /* The current display element has been consumed. Advance
5079 set_iterator_to_next (it
, 1);
5081 /* Stop if lines are truncated and IT's current x-position is
5082 past the right edge of the window now. */
5083 if (it
->truncate_lines_p
5084 && it
->current_x
>= it
->last_visible_x
)
5086 result
= MOVE_LINE_TRUNCATED
;
5091 /* Restore the iterator settings altered at the beginning of this
5093 it
->glyph_row
= saved_glyph_row
;
5098 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5099 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5100 the description of enum move_operation_enum.
5102 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5103 screen line, this function will set IT to the next position >
5107 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5109 int to_charpos
, to_x
, to_y
, to_vpos
;
5112 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5118 if (op
& MOVE_TO_VPOS
)
5120 /* If no TO_CHARPOS and no TO_X specified, stop at the
5121 start of the line TO_VPOS. */
5122 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5124 if (it
->vpos
== to_vpos
)
5130 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5134 /* TO_VPOS >= 0 means stop at TO_X in the line at
5135 TO_VPOS, or at TO_POS, whichever comes first. */
5136 if (it
->vpos
== to_vpos
)
5142 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5144 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5149 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5151 /* We have reached TO_X but not in the line we want. */
5152 skip
= move_it_in_display_line_to (it
, to_charpos
,
5154 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5162 else if (op
& MOVE_TO_Y
)
5164 struct it it_backup
;
5166 /* TO_Y specified means stop at TO_X in the line containing
5167 TO_Y---or at TO_CHARPOS if this is reached first. The
5168 problem is that we can't really tell whether the line
5169 contains TO_Y before we have completely scanned it, and
5170 this may skip past TO_X. What we do is to first scan to
5173 If TO_X is not specified, use a TO_X of zero. The reason
5174 is to make the outcome of this function more predictable.
5175 If we didn't use TO_X == 0, we would stop at the end of
5176 the line which is probably not what a caller would expect
5178 skip
= move_it_in_display_line_to (it
, to_charpos
,
5182 | (op
& MOVE_TO_POS
)));
5184 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5185 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5191 /* If TO_X was reached, we would like to know whether TO_Y
5192 is in the line. This can only be said if we know the
5193 total line height which requires us to scan the rest of
5195 if (skip
== MOVE_X_REACHED
)
5198 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5199 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5201 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5204 /* Now, decide whether TO_Y is in this line. */
5205 line_height
= it
->max_ascent
+ it
->max_descent
;
5206 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5208 if (to_y
>= it
->current_y
5209 && to_y
< it
->current_y
+ line_height
)
5211 if (skip
== MOVE_X_REACHED
)
5212 /* If TO_Y is in this line and TO_X was reached above,
5213 we scanned too far. We have to restore IT's settings
5214 to the ones before skipping. */
5218 else if (skip
== MOVE_X_REACHED
)
5221 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5229 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5233 case MOVE_POS_MATCH_OR_ZV
:
5237 case MOVE_NEWLINE_OR_CR
:
5238 set_iterator_to_next (it
, 1);
5239 it
->continuation_lines_width
= 0;
5242 case MOVE_LINE_TRUNCATED
:
5243 it
->continuation_lines_width
= 0;
5244 reseat_at_next_visible_line_start (it
, 0);
5245 if ((op
& MOVE_TO_POS
) != 0
5246 && IT_CHARPOS (*it
) > to_charpos
)
5253 case MOVE_LINE_CONTINUED
:
5254 it
->continuation_lines_width
+= it
->current_x
;
5261 /* Reset/increment for the next run. */
5262 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5263 it
->current_x
= it
->hpos
= 0;
5264 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5266 last_height
= it
->max_ascent
+ it
->max_descent
;
5267 last_max_ascent
= it
->max_ascent
;
5268 it
->max_ascent
= it
->max_descent
= 0;
5273 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5277 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5279 If DY > 0, move IT backward at least that many pixels. DY = 0
5280 means move IT backward to the preceding line start or BEGV. This
5281 function may move over more than DY pixels if IT->current_y - DY
5282 ends up in the middle of a line; in this case IT->current_y will be
5283 set to the top of the line moved to. */
5286 move_it_vertically_backward (it
, dy
)
5290 int nlines
, h
, line_height
;
5292 int start_pos
= IT_CHARPOS (*it
);
5296 /* Estimate how many newlines we must move back. */
5297 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5299 /* Set the iterator's position that many lines back. */
5300 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5301 back_to_previous_visible_line_start (it
);
5303 /* Reseat the iterator here. When moving backward, we don't want
5304 reseat to skip forward over invisible text, set up the iterator
5305 to deliver from overlay strings at the new position etc. So,
5306 use reseat_1 here. */
5307 reseat_1 (it
, it
->current
.pos
, 1);
5309 /* We are now surely at a line start. */
5310 it
->current_x
= it
->hpos
= 0;
5312 /* Move forward and see what y-distance we moved. First move to the
5313 start of the next line so that we get its height. We need this
5314 height to be able to tell whether we reached the specified
5317 it2
.max_ascent
= it2
.max_descent
= 0;
5318 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5319 MOVE_TO_POS
| MOVE_TO_VPOS
);
5320 xassert (IT_CHARPOS (*it
) >= BEGV
);
5321 line_height
= it2
.max_ascent
+ it2
.max_descent
;
5323 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5324 xassert (IT_CHARPOS (*it
) >= BEGV
);
5325 h
= it2
.current_y
- it
->current_y
;
5326 nlines
= it2
.vpos
- it
->vpos
;
5328 /* Correct IT's y and vpos position. */
5334 /* DY == 0 means move to the start of the screen line. The
5335 value of nlines is > 0 if continuation lines were involved. */
5337 move_it_by_lines (it
, nlines
, 1);
5338 xassert (IT_CHARPOS (*it
) <= start_pos
);
5342 /* The y-position we try to reach. Note that h has been
5343 subtracted in front of the if-statement. */
5344 int target_y
= it
->current_y
+ h
- dy
;
5346 /* If we did not reach target_y, try to move further backward if
5347 we can. If we moved too far backward, try to move forward. */
5348 if (target_y
< it
->current_y
5349 && IT_CHARPOS (*it
) > BEGV
)
5351 move_it_vertically (it
, target_y
- it
->current_y
);
5352 xassert (IT_CHARPOS (*it
) >= BEGV
);
5354 else if (target_y
>= it
->current_y
+ line_height
5355 && IT_CHARPOS (*it
) < ZV
)
5357 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5358 xassert (IT_CHARPOS (*it
) >= BEGV
);
5364 /* Move IT by a specified amount of pixel lines DY. DY negative means
5365 move backwards. DY = 0 means move to start of screen line. At the
5366 end, IT will be on the start of a screen line. */
5369 move_it_vertically (it
, dy
)
5374 move_it_vertically_backward (it
, -dy
);
5377 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5378 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5379 MOVE_TO_POS
| MOVE_TO_Y
);
5380 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5382 /* If buffer ends in ZV without a newline, move to the start of
5383 the line to satisfy the post-condition. */
5384 if (IT_CHARPOS (*it
) == ZV
5385 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5386 move_it_by_lines (it
, 0, 0);
5391 /* Move iterator IT past the end of the text line it is in. */
5394 move_it_past_eol (it
)
5397 enum move_it_result rc
;
5399 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5400 if (rc
== MOVE_NEWLINE_OR_CR
)
5401 set_iterator_to_next (it
, 0);
5405 #if 0 /* Currently not used. */
5407 /* Return non-zero if some text between buffer positions START_CHARPOS
5408 and END_CHARPOS is invisible. IT->window is the window for text
5412 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5414 int start_charpos
, end_charpos
;
5416 Lisp_Object prop
, limit
;
5417 int invisible_found_p
;
5419 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5421 /* Is text at START invisible? */
5422 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5424 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5425 invisible_found_p
= 1;
5428 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5430 make_number (end_charpos
));
5431 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5434 return invisible_found_p
;
5440 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5441 negative means move up. DVPOS == 0 means move to the start of the
5442 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5443 NEED_Y_P is zero, IT->current_y will be left unchanged.
5445 Further optimization ideas: If we would know that IT->f doesn't use
5446 a face with proportional font, we could be faster for
5447 truncate-lines nil. */
5450 move_it_by_lines (it
, dvpos
, need_y_p
)
5452 int dvpos
, need_y_p
;
5454 struct position pos
;
5456 if (!FRAME_WINDOW_P (it
->f
))
5458 struct text_pos textpos
;
5460 /* We can use vmotion on frames without proportional fonts. */
5461 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5462 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5463 reseat (it
, textpos
, 1);
5464 it
->vpos
+= pos
.vpos
;
5465 it
->current_y
+= pos
.vpos
;
5467 else if (dvpos
== 0)
5469 /* DVPOS == 0 means move to the start of the screen line. */
5470 move_it_vertically_backward (it
, 0);
5471 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5474 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5478 int start_charpos
, i
;
5480 /* Start at the beginning of the screen line containing IT's
5482 move_it_vertically_backward (it
, 0);
5484 /* Go back -DVPOS visible lines and reseat the iterator there. */
5485 start_charpos
= IT_CHARPOS (*it
);
5486 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5487 back_to_previous_visible_line_start (it
);
5488 reseat (it
, it
->current
.pos
, 1);
5489 it
->current_x
= it
->hpos
= 0;
5491 /* Above call may have moved too far if continuation lines
5492 are involved. Scan forward and see if it did. */
5494 it2
.vpos
= it2
.current_y
= 0;
5495 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5496 it
->vpos
-= it2
.vpos
;
5497 it
->current_y
-= it2
.current_y
;
5498 it
->current_x
= it
->hpos
= 0;
5500 /* If we moved too far, move IT some lines forward. */
5501 if (it2
.vpos
> -dvpos
)
5503 int delta
= it2
.vpos
+ dvpos
;
5504 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5511 /***********************************************************************
5513 ***********************************************************************/
5516 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5520 add_to_log (format
, arg1
, arg2
)
5522 Lisp_Object arg1
, arg2
;
5524 Lisp_Object args
[3];
5525 Lisp_Object msg
, fmt
;
5528 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5530 /* Do nothing if called asynchronously. Inserting text into
5531 a buffer may call after-change-functions and alike and
5532 that would means running Lisp asynchronously. */
5533 if (handling_signal
)
5537 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5539 args
[0] = fmt
= build_string (format
);
5542 msg
= Fformat (3, args
);
5544 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5545 buffer
= (char *) alloca (len
);
5546 strcpy (buffer
, XSTRING (msg
)->data
);
5548 message_dolog (buffer
, len
- 1, 1, 0);
5553 /* Output a newline in the *Messages* buffer if "needs" one. */
5556 message_log_maybe_newline ()
5558 if (message_log_need_newline
)
5559 message_dolog ("", 0, 1, 0);
5563 /* Add a string M of length NBYTES to the message log, optionally
5564 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5565 nonzero, means interpret the contents of M as multibyte. This
5566 function calls low-level routines in order to bypass text property
5567 hooks, etc. which might not be safe to run. */
5570 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5572 int nbytes
, nlflag
, multibyte
;
5574 if (!NILP (Vmessage_log_max
))
5576 struct buffer
*oldbuf
;
5577 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5578 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5579 int point_at_end
= 0;
5581 Lisp_Object old_deactivate_mark
, tem
;
5582 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5584 old_deactivate_mark
= Vdeactivate_mark
;
5585 oldbuf
= current_buffer
;
5586 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5587 current_buffer
->undo_list
= Qt
;
5589 oldpoint
= Fpoint_marker ();
5590 oldbegv
= Fpoint_min_marker ();
5591 oldzv
= Fpoint_max_marker ();
5592 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5600 BEGV_BYTE
= BEG_BYTE
;
5603 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5605 /* Insert the string--maybe converting multibyte to single byte
5606 or vice versa, so that all the text fits the buffer. */
5608 && NILP (current_buffer
->enable_multibyte_characters
))
5610 int i
, c
, char_bytes
;
5611 unsigned char work
[1];
5613 /* Convert a multibyte string to single-byte
5614 for the *Message* buffer. */
5615 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5617 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5618 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5620 : multibyte_char_to_unibyte (c
, Qnil
));
5621 insert_1_both (work
, 1, 1, 1, 0, 0);
5624 else if (! multibyte
5625 && ! NILP (current_buffer
->enable_multibyte_characters
))
5627 int i
, c
, char_bytes
;
5628 unsigned char *msg
= (unsigned char *) m
;
5629 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5630 /* Convert a single-byte string to multibyte
5631 for the *Message* buffer. */
5632 for (i
= 0; i
< nbytes
; i
++)
5634 c
= unibyte_char_to_multibyte (msg
[i
]);
5635 char_bytes
= CHAR_STRING (c
, str
);
5636 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5640 insert_1 (m
, nbytes
, 1, 0, 0);
5644 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5645 insert_1 ("\n", 1, 1, 0, 0);
5647 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5649 this_bol_byte
= PT_BYTE
;
5653 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5655 prev_bol_byte
= PT_BYTE
;
5657 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5658 this_bol
, this_bol_byte
);
5661 del_range_both (prev_bol
, prev_bol_byte
,
5662 this_bol
, this_bol_byte
, 0);
5668 /* If you change this format, don't forget to also
5669 change message_log_check_duplicate. */
5670 sprintf (dupstr
, " [%d times]", dup
);
5671 duplen
= strlen (dupstr
);
5672 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5673 insert_1 (dupstr
, duplen
, 1, 0, 1);
5678 if (NATNUMP (Vmessage_log_max
))
5680 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5681 -XFASTINT (Vmessage_log_max
) - 1, 0);
5682 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5685 BEGV
= XMARKER (oldbegv
)->charpos
;
5686 BEGV_BYTE
= marker_byte_position (oldbegv
);
5695 ZV
= XMARKER (oldzv
)->charpos
;
5696 ZV_BYTE
= marker_byte_position (oldzv
);
5700 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5702 /* We can't do Fgoto_char (oldpoint) because it will run some
5704 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5705 XMARKER (oldpoint
)->bytepos
);
5708 free_marker (oldpoint
);
5709 free_marker (oldbegv
);
5710 free_marker (oldzv
);
5712 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5713 set_buffer_internal (oldbuf
);
5715 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5716 message_log_need_newline
= !nlflag
;
5717 Vdeactivate_mark
= old_deactivate_mark
;
5722 /* We are at the end of the buffer after just having inserted a newline.
5723 (Note: We depend on the fact we won't be crossing the gap.)
5724 Check to see if the most recent message looks a lot like the previous one.
5725 Return 0 if different, 1 if the new one should just replace it, or a
5726 value N > 1 if we should also append " [N times]". */
5729 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5730 int prev_bol
, this_bol
;
5731 int prev_bol_byte
, this_bol_byte
;
5734 int len
= Z_BYTE
- 1 - this_bol_byte
;
5736 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5737 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5739 for (i
= 0; i
< len
; i
++)
5741 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5749 if (*p1
++ == ' ' && *p1
++ == '[')
5752 while (*p1
>= '0' && *p1
<= '9')
5753 n
= n
* 10 + *p1
++ - '0';
5754 if (strncmp (p1
, " times]\n", 8) == 0)
5761 /* Display an echo area message M with a specified length of NBYTES
5762 bytes. The string may include null characters. If M is 0, clear
5763 out any existing message, and let the mini-buffer text show
5766 The buffer M must continue to exist until after the echo area gets
5767 cleared or some other message gets displayed there. This means do
5768 not pass text that is stored in a Lisp string; do not pass text in
5769 a buffer that was alloca'd. */
5772 message2 (m
, nbytes
, multibyte
)
5777 /* First flush out any partial line written with print. */
5778 message_log_maybe_newline ();
5780 message_dolog (m
, nbytes
, 1, multibyte
);
5781 message2_nolog (m
, nbytes
, multibyte
);
5785 /* The non-logging counterpart of message2. */
5788 message2_nolog (m
, nbytes
, multibyte
)
5792 struct frame
*sf
= SELECTED_FRAME ();
5793 message_enable_multibyte
= multibyte
;
5797 if (noninteractive_need_newline
)
5798 putc ('\n', stderr
);
5799 noninteractive_need_newline
= 0;
5801 fwrite (m
, nbytes
, 1, stderr
);
5802 if (cursor_in_echo_area
== 0)
5803 fprintf (stderr
, "\n");
5806 /* A null message buffer means that the frame hasn't really been
5807 initialized yet. Error messages get reported properly by
5808 cmd_error, so this must be just an informative message; toss it. */
5809 else if (INTERACTIVE
5810 && sf
->glyphs_initialized_p
5811 && FRAME_MESSAGE_BUF (sf
))
5813 Lisp_Object mini_window
;
5816 /* Get the frame containing the mini-buffer
5817 that the selected frame is using. */
5818 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5819 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5821 FRAME_SAMPLE_VISIBILITY (f
);
5822 if (FRAME_VISIBLE_P (sf
)
5823 && ! FRAME_VISIBLE_P (f
))
5824 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5828 set_message (m
, Qnil
, nbytes
, multibyte
);
5829 if (minibuffer_auto_raise
)
5830 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5833 clear_message (1, 1);
5835 do_pending_window_change (0);
5836 echo_area_display (1);
5837 do_pending_window_change (0);
5838 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5839 (*frame_up_to_date_hook
) (f
);
5844 /* Display an echo area message M with a specified length of NBYTES
5845 bytes. The string may include null characters. If M is not a
5846 string, clear out any existing message, and let the mini-buffer
5847 text show through. */
5850 message3 (m
, nbytes
, multibyte
)
5855 struct gcpro gcpro1
;
5859 /* First flush out any partial line written with print. */
5860 message_log_maybe_newline ();
5862 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5863 message3_nolog (m
, nbytes
, multibyte
);
5869 /* The non-logging version of message3. */
5872 message3_nolog (m
, nbytes
, multibyte
)
5874 int nbytes
, multibyte
;
5876 struct frame
*sf
= SELECTED_FRAME ();
5877 message_enable_multibyte
= multibyte
;
5881 if (noninteractive_need_newline
)
5882 putc ('\n', stderr
);
5883 noninteractive_need_newline
= 0;
5885 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5886 if (cursor_in_echo_area
== 0)
5887 fprintf (stderr
, "\n");
5890 /* A null message buffer means that the frame hasn't really been
5891 initialized yet. Error messages get reported properly by
5892 cmd_error, so this must be just an informative message; toss it. */
5893 else if (INTERACTIVE
5894 && sf
->glyphs_initialized_p
5895 && FRAME_MESSAGE_BUF (sf
))
5897 Lisp_Object mini_window
;
5901 /* Get the frame containing the mini-buffer
5902 that the selected frame is using. */
5903 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5904 frame
= XWINDOW (mini_window
)->frame
;
5907 FRAME_SAMPLE_VISIBILITY (f
);
5908 if (FRAME_VISIBLE_P (sf
)
5909 && !FRAME_VISIBLE_P (f
))
5910 Fmake_frame_visible (frame
);
5912 if (STRINGP (m
) && XSTRING (m
)->size
)
5914 set_message (NULL
, m
, nbytes
, multibyte
);
5915 if (minibuffer_auto_raise
)
5916 Fraise_frame (frame
);
5919 clear_message (1, 1);
5921 do_pending_window_change (0);
5922 echo_area_display (1);
5923 do_pending_window_change (0);
5924 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5925 (*frame_up_to_date_hook
) (f
);
5930 /* Display a null-terminated echo area message M. If M is 0, clear
5931 out any existing message, and let the mini-buffer text show through.
5933 The buffer M must continue to exist until after the echo area gets
5934 cleared or some other message gets displayed there. Do not pass
5935 text that is stored in a Lisp string. Do not pass text in a buffer
5936 that was alloca'd. */
5942 message2 (m
, (m
? strlen (m
) : 0), 0);
5946 /* The non-logging counterpart of message1. */
5952 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5955 /* Display a message M which contains a single %s
5956 which gets replaced with STRING. */
5959 message_with_string (m
, string
, log
)
5968 if (noninteractive_need_newline
)
5969 putc ('\n', stderr
);
5970 noninteractive_need_newline
= 0;
5971 fprintf (stderr
, m
, XSTRING (string
)->data
);
5972 if (cursor_in_echo_area
== 0)
5973 fprintf (stderr
, "\n");
5977 else if (INTERACTIVE
)
5979 /* The frame whose minibuffer we're going to display the message on.
5980 It may be larger than the selected frame, so we need
5981 to use its buffer, not the selected frame's buffer. */
5982 Lisp_Object mini_window
;
5983 struct frame
*f
, *sf
= SELECTED_FRAME ();
5985 /* Get the frame containing the minibuffer
5986 that the selected frame is using. */
5987 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5988 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5990 /* A null message buffer means that the frame hasn't really been
5991 initialized yet. Error messages get reported properly by
5992 cmd_error, so this must be just an informative message; toss it. */
5993 if (FRAME_MESSAGE_BUF (f
))
5997 a
[0] = (char *) XSTRING (string
)->data
;
5999 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6000 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6003 message2 (FRAME_MESSAGE_BUF (f
), len
,
6004 STRING_MULTIBYTE (string
));
6006 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
6007 STRING_MULTIBYTE (string
));
6009 /* Print should start at the beginning of the message
6010 buffer next time. */
6011 message_buf_print
= 0;
6017 /* Dump an informative message to the minibuf. If M is 0, clear out
6018 any existing message, and let the mini-buffer text show through. */
6022 message (m
, a1
, a2
, a3
)
6024 EMACS_INT a1
, a2
, a3
;
6030 if (noninteractive_need_newline
)
6031 putc ('\n', stderr
);
6032 noninteractive_need_newline
= 0;
6033 fprintf (stderr
, m
, a1
, a2
, a3
);
6034 if (cursor_in_echo_area
== 0)
6035 fprintf (stderr
, "\n");
6039 else if (INTERACTIVE
)
6041 /* The frame whose mini-buffer we're going to display the message
6042 on. It may be larger than the selected frame, so we need to
6043 use its buffer, not the selected frame's buffer. */
6044 Lisp_Object mini_window
;
6045 struct frame
*f
, *sf
= SELECTED_FRAME ();
6047 /* Get the frame containing the mini-buffer
6048 that the selected frame is using. */
6049 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6050 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6052 /* A null message buffer means that the frame hasn't really been
6053 initialized yet. Error messages get reported properly by
6054 cmd_error, so this must be just an informative message; toss
6056 if (FRAME_MESSAGE_BUF (f
))
6067 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6068 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6070 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6071 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6073 #endif /* NO_ARG_ARRAY */
6075 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6080 /* Print should start at the beginning of the message
6081 buffer next time. */
6082 message_buf_print
= 0;
6088 /* The non-logging version of message. */
6091 message_nolog (m
, a1
, a2
, a3
)
6093 EMACS_INT a1
, a2
, a3
;
6095 Lisp_Object old_log_max
;
6096 old_log_max
= Vmessage_log_max
;
6097 Vmessage_log_max
= Qnil
;
6098 message (m
, a1
, a2
, a3
);
6099 Vmessage_log_max
= old_log_max
;
6103 /* Display the current message in the current mini-buffer. This is
6104 only called from error handlers in process.c, and is not time
6110 if (!NILP (echo_area_buffer
[0]))
6113 string
= Fcurrent_message ();
6114 message3 (string
, XSTRING (string
)->size
,
6115 !NILP (current_buffer
->enable_multibyte_characters
));
6120 /* Make sure echo area buffers in echo_buffers[] are life. If they
6121 aren't, make new ones. */
6124 ensure_echo_area_buffers ()
6128 for (i
= 0; i
< 2; ++i
)
6129 if (!BUFFERP (echo_buffer
[i
])
6130 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6133 Lisp_Object old_buffer
;
6136 old_buffer
= echo_buffer
[i
];
6137 sprintf (name
, " *Echo Area %d*", i
);
6138 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6139 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6141 for (j
= 0; j
< 2; ++j
)
6142 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6143 echo_area_buffer
[j
] = echo_buffer
[i
];
6148 /* Call FN with args A1..A4 with either the current or last displayed
6149 echo_area_buffer as current buffer.
6151 WHICH zero means use the current message buffer
6152 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6153 from echo_buffer[] and clear it.
6155 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6156 suitable buffer from echo_buffer[] and clear it.
6158 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6159 that the current message becomes the last displayed one, make
6160 choose a suitable buffer for echo_area_buffer[0], and clear it.
6162 Value is what FN returns. */
6165 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6168 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6174 int this_one
, the_other
, clear_buffer_p
, rc
;
6175 int count
= BINDING_STACK_SIZE ();
6177 /* If buffers aren't life, make new ones. */
6178 ensure_echo_area_buffers ();
6183 this_one
= 0, the_other
= 1;
6185 this_one
= 1, the_other
= 0;
6188 this_one
= 0, the_other
= 1;
6191 /* We need a fresh one in case the current echo buffer equals
6192 the one containing the last displayed echo area message. */
6193 if (!NILP (echo_area_buffer
[this_one
])
6194 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6195 echo_area_buffer
[this_one
] = Qnil
;
6198 /* Choose a suitable buffer from echo_buffer[] is we don't
6200 if (NILP (echo_area_buffer
[this_one
]))
6202 echo_area_buffer
[this_one
]
6203 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6204 ? echo_buffer
[the_other
]
6205 : echo_buffer
[this_one
]);
6209 buffer
= echo_area_buffer
[this_one
];
6211 /* Don't get confused by reusing the buffer used for echoing
6212 for a different purpose. */
6213 if (!echoing
&& EQ (buffer
, echo_message_buffer
))
6216 record_unwind_protect (unwind_with_echo_area_buffer
,
6217 with_echo_area_buffer_unwind_data (w
));
6219 /* Make the echo area buffer current. Note that for display
6220 purposes, it is not necessary that the displayed window's buffer
6221 == current_buffer, except for text property lookup. So, let's
6222 only set that buffer temporarily here without doing a full
6223 Fset_window_buffer. We must also change w->pointm, though,
6224 because otherwise an assertions in unshow_buffer fails, and Emacs
6226 set_buffer_internal_1 (XBUFFER (buffer
));
6230 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6233 current_buffer
->undo_list
= Qt
;
6234 current_buffer
->read_only
= Qnil
;
6235 specbind (Qinhibit_read_only
, Qt
);
6237 if (clear_buffer_p
&& Z
> BEG
)
6240 xassert (BEGV
>= BEG
);
6241 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6243 rc
= fn (a1
, a2
, a3
, a4
);
6245 xassert (BEGV
>= BEG
);
6246 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6248 unbind_to (count
, Qnil
);
6253 /* Save state that should be preserved around the call to the function
6254 FN called in with_echo_area_buffer. */
6257 with_echo_area_buffer_unwind_data (w
)
6263 /* Reduce consing by keeping one vector in
6264 Vwith_echo_area_save_vector. */
6265 vector
= Vwith_echo_area_save_vector
;
6266 Vwith_echo_area_save_vector
= Qnil
;
6269 vector
= Fmake_vector (make_number (7), Qnil
);
6271 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6272 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6273 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6277 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6278 AREF (vector
, i
) = w
->buffer
; ++i
;
6279 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6280 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6285 for (; i
< end
; ++i
)
6286 AREF (vector
, i
) = Qnil
;
6289 xassert (i
== ASIZE (vector
));
6294 /* Restore global state from VECTOR which was created by
6295 with_echo_area_buffer_unwind_data. */
6298 unwind_with_echo_area_buffer (vector
)
6301 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6302 Vdeactivate_mark
= AREF (vector
, 1);
6303 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6305 if (WINDOWP (AREF (vector
, 3)))
6308 Lisp_Object buffer
, charpos
, bytepos
;
6310 w
= XWINDOW (AREF (vector
, 3));
6311 buffer
= AREF (vector
, 4);
6312 charpos
= AREF (vector
, 5);
6313 bytepos
= AREF (vector
, 6);
6316 set_marker_both (w
->pointm
, buffer
,
6317 XFASTINT (charpos
), XFASTINT (bytepos
));
6320 Vwith_echo_area_save_vector
= vector
;
6325 /* Set up the echo area for use by print functions. MULTIBYTE_P
6326 non-zero means we will print multibyte. */
6329 setup_echo_area_for_printing (multibyte_p
)
6332 ensure_echo_area_buffers ();
6334 if (!message_buf_print
)
6336 /* A message has been output since the last time we printed.
6337 Choose a fresh echo area buffer. */
6338 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6339 echo_area_buffer
[0] = echo_buffer
[1];
6341 echo_area_buffer
[0] = echo_buffer
[0];
6343 /* Switch to that buffer and clear it. */
6344 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6345 current_buffer
->truncate_lines
= Qnil
;
6349 int count
= BINDING_STACK_SIZE ();
6350 specbind (Qinhibit_read_only
, Qt
);
6352 unbind_to (count
, Qnil
);
6354 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6356 /* Set up the buffer for the multibyteness we need. */
6358 != !NILP (current_buffer
->enable_multibyte_characters
))
6359 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6361 /* Raise the frame containing the echo area. */
6362 if (minibuffer_auto_raise
)
6364 struct frame
*sf
= SELECTED_FRAME ();
6365 Lisp_Object mini_window
;
6366 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6367 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6370 message_log_maybe_newline ();
6371 message_buf_print
= 1;
6375 if (NILP (echo_area_buffer
[0]))
6377 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6378 echo_area_buffer
[0] = echo_buffer
[1];
6380 echo_area_buffer
[0] = echo_buffer
[0];
6383 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6385 /* Someone switched buffers between print requests. */
6386 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6387 current_buffer
->truncate_lines
= Qnil
;
6393 /* Display an echo area message in window W. Value is non-zero if W's
6394 height is changed. If display_last_displayed_message_p is
6395 non-zero, display the message that was last displayed, otherwise
6396 display the current message. */
6399 display_echo_area (w
)
6402 int i
, no_message_p
, window_height_changed_p
, count
;
6404 /* Temporarily disable garbage collections while displaying the echo
6405 area. This is done because a GC can print a message itself.
6406 That message would modify the echo area buffer's contents while a
6407 redisplay of the buffer is going on, and seriously confuse
6409 count
= inhibit_garbage_collection ();
6411 /* If there is no message, we must call display_echo_area_1
6412 nevertheless because it resizes the window. But we will have to
6413 reset the echo_area_buffer in question to nil at the end because
6414 with_echo_area_buffer will sets it to an empty buffer. */
6415 i
= display_last_displayed_message_p
? 1 : 0;
6416 no_message_p
= NILP (echo_area_buffer
[i
]);
6418 window_height_changed_p
6419 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6420 display_echo_area_1
,
6421 (EMACS_INT
) w
, Qnil
, 0, 0);
6424 echo_area_buffer
[i
] = Qnil
;
6426 unbind_to (count
, Qnil
);
6427 return window_height_changed_p
;
6431 /* Helper for display_echo_area. Display the current buffer which
6432 contains the current echo area message in window W, a mini-window,
6433 a pointer to which is passed in A1. A2..A4 are currently not used.
6434 Change the height of W so that all of the message is displayed.
6435 Value is non-zero if height of W was changed. */
6438 display_echo_area_1 (a1
, a2
, a3
, a4
)
6443 struct window
*w
= (struct window
*) a1
;
6445 struct text_pos start
;
6446 int window_height_changed_p
= 0;
6448 /* Do this before displaying, so that we have a large enough glyph
6449 matrix for the display. */
6450 window_height_changed_p
= resize_mini_window (w
, 0);
6453 clear_glyph_matrix (w
->desired_matrix
);
6454 XSETWINDOW (window
, w
);
6455 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6456 try_window (window
, start
);
6458 return window_height_changed_p
;
6462 /* Resize the echo area window to exactly the size needed for the
6463 currently displayed message, if there is one. If a mini-buffer
6464 is active, don't shrink it. */
6467 resize_echo_area_exactly ()
6469 if (BUFFERP (echo_area_buffer
[0])
6470 && WINDOWP (echo_area_window
))
6472 struct window
*w
= XWINDOW (echo_area_window
);
6474 Lisp_Object resize_exactly
;
6476 if (minibuf_level
== 0)
6477 resize_exactly
= Qt
;
6479 resize_exactly
= Qnil
;
6481 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6482 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6485 ++windows_or_buffers_changed
;
6486 ++update_mode_lines
;
6487 redisplay_internal (0);
6493 /* Callback function for with_echo_area_buffer, when used from
6494 resize_echo_area_exactly. A1 contains a pointer to the window to
6495 resize, EXACTLY non-nil means resize the mini-window exactly to the
6496 size of the text displayed. A3 and A4 are not used. Value is what
6497 resize_mini_window returns. */
6500 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6502 Lisp_Object exactly
;
6505 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6509 /* Resize mini-window W to fit the size of its contents. EXACT:P
6510 means size the window exactly to the size needed. Otherwise, it's
6511 only enlarged until W's buffer is empty. Value is non-zero if
6512 the window height has been changed. */
6515 resize_mini_window (w
, exact_p
)
6519 struct frame
*f
= XFRAME (w
->frame
);
6520 int window_height_changed_p
= 0;
6522 xassert (MINI_WINDOW_P (w
));
6524 /* Don't resize windows while redisplaying a window; it would
6525 confuse redisplay functions when the size of the window they are
6526 displaying changes from under them. Such a resizing can happen,
6527 for instance, when which-func prints a long message while
6528 we are running fontification-functions. We're running these
6529 functions with safe_call which binds inhibit-redisplay to t. */
6530 if (!NILP (Vinhibit_redisplay
))
6533 /* Nil means don't try to resize. */
6534 if (NILP (Vresize_mini_windows
)
6535 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6538 if (!FRAME_MINIBUF_ONLY_P (f
))
6541 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6542 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6543 int height
, max_height
;
6544 int unit
= CANON_Y_UNIT (f
);
6545 struct text_pos start
;
6546 struct buffer
*old_current_buffer
= NULL
;
6548 if (current_buffer
!= XBUFFER (w
->buffer
))
6550 old_current_buffer
= current_buffer
;
6551 set_buffer_internal (XBUFFER (w
->buffer
));
6554 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6556 /* Compute the max. number of lines specified by the user. */
6557 if (FLOATP (Vmax_mini_window_height
))
6558 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6559 else if (INTEGERP (Vmax_mini_window_height
))
6560 max_height
= XINT (Vmax_mini_window_height
);
6562 max_height
= total_height
/ 4;
6564 /* Correct that max. height if it's bogus. */
6565 max_height
= max (1, max_height
);
6566 max_height
= min (total_height
, max_height
);
6568 /* Find out the height of the text in the window. */
6569 if (it
.truncate_lines_p
)
6574 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6575 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6576 height
= it
.current_y
+ last_height
;
6578 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6579 height
-= it
.extra_line_spacing
;
6580 height
= (height
+ unit
- 1) / unit
;
6583 /* Compute a suitable window start. */
6584 if (height
> max_height
)
6586 height
= max_height
;
6587 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6588 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6589 start
= it
.current
.pos
;
6592 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6593 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6595 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6597 /* Let it grow only, until we display an empty message, in which
6598 case the window shrinks again. */
6599 if (height
> XFASTINT (w
->height
))
6601 int old_height
= XFASTINT (w
->height
);
6602 freeze_window_starts (f
, 1);
6603 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6604 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6606 else if (height
< XFASTINT (w
->height
)
6607 && (exact_p
|| BEGV
== ZV
))
6609 int old_height
= XFASTINT (w
->height
);
6610 freeze_window_starts (f
, 0);
6611 shrink_mini_window (w
);
6612 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6617 /* Always resize to exact size needed. */
6618 if (height
> XFASTINT (w
->height
))
6620 int old_height
= XFASTINT (w
->height
);
6621 freeze_window_starts (f
, 1);
6622 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6623 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6625 else if (height
< XFASTINT (w
->height
))
6627 int old_height
= XFASTINT (w
->height
);
6628 freeze_window_starts (f
, 0);
6629 shrink_mini_window (w
);
6633 freeze_window_starts (f
, 1);
6634 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6637 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6641 if (old_current_buffer
)
6642 set_buffer_internal (old_current_buffer
);
6645 return window_height_changed_p
;
6649 /* Value is the current message, a string, or nil if there is no
6657 if (NILP (echo_area_buffer
[0]))
6661 with_echo_area_buffer (0, 0, current_message_1
,
6662 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6664 echo_area_buffer
[0] = Qnil
;
6672 current_message_1 (a1
, a2
, a3
, a4
)
6677 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6680 *msg
= make_buffer_string (BEG
, Z
, 1);
6687 /* Push the current message on Vmessage_stack for later restauration
6688 by restore_message. Value is non-zero if the current message isn't
6689 empty. This is a relatively infrequent operation, so it's not
6690 worth optimizing. */
6696 msg
= current_message ();
6697 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6698 return STRINGP (msg
);
6702 /* Handler for record_unwind_protect calling pop_message. */
6705 push_message_unwind (dummy
)
6713 /* Restore message display from the top of Vmessage_stack. */
6720 xassert (CONSP (Vmessage_stack
));
6721 msg
= XCAR (Vmessage_stack
);
6723 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6725 message3_nolog (msg
, 0, 0);
6729 /* Pop the top-most entry off Vmessage_stack. */
6734 xassert (CONSP (Vmessage_stack
));
6735 Vmessage_stack
= XCDR (Vmessage_stack
);
6739 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6740 exits. If the stack is not empty, we have a missing pop_message
6744 check_message_stack ()
6746 if (!NILP (Vmessage_stack
))
6751 /* Truncate to NCHARS what will be displayed in the echo area the next
6752 time we display it---but don't redisplay it now. */
6755 truncate_echo_area (nchars
)
6759 echo_area_buffer
[0] = Qnil
;
6760 /* A null message buffer means that the frame hasn't really been
6761 initialized yet. Error messages get reported properly by
6762 cmd_error, so this must be just an informative message; toss it. */
6763 else if (!noninteractive
6765 && !NILP (echo_area_buffer
[0]))
6767 struct frame
*sf
= SELECTED_FRAME ();
6768 if (FRAME_MESSAGE_BUF (sf
))
6769 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6774 /* Helper function for truncate_echo_area. Truncate the current
6775 message to at most NCHARS characters. */
6778 truncate_message_1 (nchars
, a2
, a3
, a4
)
6783 if (BEG
+ nchars
< Z
)
6784 del_range (BEG
+ nchars
, Z
);
6786 echo_area_buffer
[0] = Qnil
;
6791 /* Set the current message to a substring of S or STRING.
6793 If STRING is a Lisp string, set the message to the first NBYTES
6794 bytes from STRING. NBYTES zero means use the whole string. If
6795 STRING is multibyte, the message will be displayed multibyte.
6797 If S is not null, set the message to the first LEN bytes of S. LEN
6798 zero means use the whole string. MULTIBYTE_P non-zero means S is
6799 multibyte. Display the message multibyte in that case. */
6802 set_message (s
, string
, nbytes
, multibyte_p
)
6807 message_enable_multibyte
6808 = ((s
&& multibyte_p
)
6809 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6811 with_echo_area_buffer (0, -1, set_message_1
,
6812 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6813 message_buf_print
= 0;
6814 help_echo_showing_p
= 0;
6818 /* Helper function for set_message. Arguments have the same meaning
6819 as there, with A1 corresponding to S and A2 corresponding to STRING
6820 This function is called with the echo area buffer being
6824 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6827 EMACS_INT nbytes
, multibyte_p
;
6829 char *s
= (char *) a1
;
6830 Lisp_Object string
= a2
;
6834 /* Change multibyteness of the echo buffer appropriately. */
6835 if (message_enable_multibyte
6836 != !NILP (current_buffer
->enable_multibyte_characters
))
6837 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6839 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6841 /* Insert new message at BEG. */
6842 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6844 if (STRINGP (string
))
6849 nbytes
= XSTRING (string
)->size_byte
;
6850 nchars
= string_byte_to_char (string
, nbytes
);
6852 /* This function takes care of single/multibyte conversion. We
6853 just have to ensure that the echo area buffer has the right
6854 setting of enable_multibyte_characters. */
6855 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6860 nbytes
= strlen (s
);
6862 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6864 /* Convert from multi-byte to single-byte. */
6866 unsigned char work
[1];
6868 /* Convert a multibyte string to single-byte. */
6869 for (i
= 0; i
< nbytes
; i
+= n
)
6871 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6872 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6874 : multibyte_char_to_unibyte (c
, Qnil
));
6875 insert_1_both (work
, 1, 1, 1, 0, 0);
6878 else if (!multibyte_p
6879 && !NILP (current_buffer
->enable_multibyte_characters
))
6881 /* Convert from single-byte to multi-byte. */
6883 unsigned char *msg
= (unsigned char *) s
;
6884 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6886 /* Convert a single-byte string to multibyte. */
6887 for (i
= 0; i
< nbytes
; i
++)
6889 c
= unibyte_char_to_multibyte (msg
[i
]);
6890 n
= CHAR_STRING (c
, str
);
6891 insert_1_both (str
, 1, n
, 1, 0, 0);
6895 insert_1 (s
, nbytes
, 1, 0, 0);
6902 /* Clear messages. CURRENT_P non-zero means clear the current
6903 message. LAST_DISPLAYED_P non-zero means clear the message
6907 clear_message (current_p
, last_displayed_p
)
6908 int current_p
, last_displayed_p
;
6912 echo_area_buffer
[0] = Qnil
;
6913 message_cleared_p
= 1;
6916 if (last_displayed_p
)
6917 echo_area_buffer
[1] = Qnil
;
6919 message_buf_print
= 0;
6922 /* Clear garbaged frames.
6924 This function is used where the old redisplay called
6925 redraw_garbaged_frames which in turn called redraw_frame which in
6926 turn called clear_frame. The call to clear_frame was a source of
6927 flickering. I believe a clear_frame is not necessary. It should
6928 suffice in the new redisplay to invalidate all current matrices,
6929 and ensure a complete redisplay of all windows. */
6932 clear_garbaged_frames ()
6936 Lisp_Object tail
, frame
;
6938 FOR_EACH_FRAME (tail
, frame
)
6940 struct frame
*f
= XFRAME (frame
);
6942 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6944 clear_current_matrices (f
);
6950 ++windows_or_buffers_changed
;
6955 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6956 is non-zero update selected_frame. Value is non-zero if the
6957 mini-windows height has been changed. */
6960 echo_area_display (update_frame_p
)
6963 Lisp_Object mini_window
;
6966 int window_height_changed_p
= 0;
6967 struct frame
*sf
= SELECTED_FRAME ();
6969 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6970 w
= XWINDOW (mini_window
);
6971 f
= XFRAME (WINDOW_FRAME (w
));
6973 /* Don't display if frame is invisible or not yet initialized. */
6974 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6977 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6979 #ifdef HAVE_WINDOW_SYSTEM
6980 /* When Emacs starts, selected_frame may be a visible terminal
6981 frame, even if we run under a window system. If we let this
6982 through, a message would be displayed on the terminal. */
6983 if (EQ (selected_frame
, Vterminal_frame
)
6984 && !NILP (Vwindow_system
))
6986 #endif /* HAVE_WINDOW_SYSTEM */
6989 /* Redraw garbaged frames. */
6991 clear_garbaged_frames ();
6993 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6995 echo_area_window
= mini_window
;
6996 window_height_changed_p
= display_echo_area (w
);
6997 w
->must_be_updated_p
= 1;
6999 /* Update the display, unless called from redisplay_internal.
7000 Also don't update the screen during redisplay itself. The
7001 update will happen at the end of redisplay, and an update
7002 here could cause confusion. */
7003 if (update_frame_p
&& !redisplaying_p
)
7007 /* If the display update has been interrupted by pending
7008 input, update mode lines in the frame. Due to the
7009 pending input, it might have been that redisplay hasn't
7010 been called, so that mode lines above the echo area are
7011 garbaged. This looks odd, so we prevent it here. */
7012 if (!display_completed
)
7013 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7015 if (window_height_changed_p
7016 /* Don't do this if Emacs is shutting down. Redisplay
7017 needs to run hooks. */
7018 && !NILP (Vrun_hooks
))
7020 /* Must update other windows. Likewise as in other
7021 cases, don't let this update be interrupted by
7023 int count
= BINDING_STACK_SIZE ();
7024 specbind (Qredisplay_dont_pause
, Qt
);
7025 windows_or_buffers_changed
= 1;
7026 redisplay_internal (0);
7027 unbind_to (count
, Qnil
);
7029 else if (FRAME_WINDOW_P (f
) && n
== 0)
7031 /* Window configuration is the same as before.
7032 Can do with a display update of the echo area,
7033 unless we displayed some mode lines. */
7034 update_single_window (w
, 1);
7035 rif
->flush_display (f
);
7038 update_frame (f
, 1, 1);
7040 /* If cursor is in the echo area, make sure that the next
7041 redisplay displays the minibuffer, so that the cursor will
7042 be replaced with what the minibuffer wants. */
7043 if (cursor_in_echo_area
)
7044 ++windows_or_buffers_changed
;
7047 else if (!EQ (mini_window
, selected_window
))
7048 windows_or_buffers_changed
++;
7050 /* Last displayed message is now the current message. */
7051 echo_area_buffer
[1] = echo_area_buffer
[0];
7053 /* Prevent redisplay optimization in redisplay_internal by resetting
7054 this_line_start_pos. This is done because the mini-buffer now
7055 displays the message instead of its buffer text. */
7056 if (EQ (mini_window
, selected_window
))
7057 CHARPOS (this_line_start_pos
) = 0;
7059 return window_height_changed_p
;
7064 /***********************************************************************
7066 ***********************************************************************/
7069 #ifdef HAVE_WINDOW_SYSTEM
7071 /* A buffer for constructing frame titles in it; allocated from the
7072 heap in init_xdisp and resized as needed in store_frame_title_char. */
7074 static char *frame_title_buf
;
7076 /* The buffer's end, and a current output position in it. */
7078 static char *frame_title_buf_end
;
7079 static char *frame_title_ptr
;
7082 /* Store a single character C for the frame title in frame_title_buf.
7083 Re-allocate frame_title_buf if necessary. */
7086 store_frame_title_char (c
)
7089 /* If output position has reached the end of the allocated buffer,
7090 double the buffer's size. */
7091 if (frame_title_ptr
== frame_title_buf_end
)
7093 int len
= frame_title_ptr
- frame_title_buf
;
7094 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7095 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7096 frame_title_buf_end
= frame_title_buf
+ new_size
;
7097 frame_title_ptr
= frame_title_buf
+ len
;
7100 *frame_title_ptr
++ = c
;
7104 /* Store part of a frame title in frame_title_buf, beginning at
7105 frame_title_ptr. STR is the string to store. Do not copy
7106 characters that yield more columns than PRECISION; PRECISION <= 0
7107 means copy the whole string. Pad with spaces until FIELD_WIDTH
7108 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7109 pad. Called from display_mode_element when it is used to build a
7113 store_frame_title (str
, field_width
, precision
)
7115 int field_width
, precision
;
7118 int dummy
, nbytes
, width
;
7120 /* Copy at most PRECISION chars from STR. */
7121 nbytes
= strlen (str
);
7122 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7124 store_frame_title_char (*str
++);
7126 /* Fill up with spaces until FIELD_WIDTH reached. */
7127 while (field_width
> 0
7130 store_frame_title_char (' ');
7138 /* Set the title of FRAME, if it has changed. The title format is
7139 Vicon_title_format if FRAME is iconified, otherwise it is
7140 frame_title_format. */
7143 x_consider_frame_title (frame
)
7146 struct frame
*f
= XFRAME (frame
);
7148 if (FRAME_WINDOW_P (f
)
7149 || FRAME_MINIBUF_ONLY_P (f
)
7150 || f
->explicit_name
)
7152 /* Do we have more than one visible frame on this X display? */
7155 struct buffer
*obuf
;
7159 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7161 struct frame
*tf
= XFRAME (XCAR (tail
));
7164 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7165 && !FRAME_MINIBUF_ONLY_P (tf
)
7166 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7170 /* Set global variable indicating that multiple frames exist. */
7171 multiple_frames
= CONSP (tail
);
7173 /* Switch to the buffer of selected window of the frame. Set up
7174 frame_title_ptr so that display_mode_element will output into it;
7175 then display the title. */
7176 obuf
= current_buffer
;
7177 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
7178 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7179 frame_title_ptr
= frame_title_buf
;
7180 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7181 NULL
, DEFAULT_FACE_ID
);
7182 display_mode_element (&it
, 0, -1, -1, fmt
);
7183 len
= frame_title_ptr
- frame_title_buf
;
7184 frame_title_ptr
= NULL
;
7185 set_buffer_internal (obuf
);
7187 /* Set the title only if it's changed. This avoids consing in
7188 the common case where it hasn't. (If it turns out that we've
7189 already wasted too much time by walking through the list with
7190 display_mode_element, then we might need to optimize at a
7191 higher level than this.) */
7192 if (! STRINGP (f
->name
)
7193 || STRING_BYTES (XSTRING (f
->name
)) != len
7194 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7195 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7199 #else /* not HAVE_WINDOW_SYSTEM */
7201 #define frame_title_ptr ((char *)0)
7202 #define store_frame_title(str, mincol, maxcol) 0
7204 #endif /* not HAVE_WINDOW_SYSTEM */
7209 /***********************************************************************
7211 ***********************************************************************/
7214 /* Prepare for redisplay by updating menu-bar item lists when
7215 appropriate. This can call eval. */
7218 prepare_menu_bars ()
7221 struct gcpro gcpro1
, gcpro2
;
7223 Lisp_Object tooltip_frame
;
7225 #ifdef HAVE_X_WINDOWS
7226 tooltip_frame
= tip_frame
;
7228 tooltip_frame
= Qnil
;
7231 /* Update all frame titles based on their buffer names, etc. We do
7232 this before the menu bars so that the buffer-menu will show the
7233 up-to-date frame titles. */
7234 #ifdef HAVE_WINDOW_SYSTEM
7235 if (windows_or_buffers_changed
|| update_mode_lines
)
7237 Lisp_Object tail
, frame
;
7239 FOR_EACH_FRAME (tail
, frame
)
7242 if (!EQ (frame
, tooltip_frame
)
7243 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7244 x_consider_frame_title (frame
);
7247 #endif /* HAVE_WINDOW_SYSTEM */
7249 /* Update the menu bar item lists, if appropriate. This has to be
7250 done before any actual redisplay or generation of display lines. */
7251 all_windows
= (update_mode_lines
7252 || buffer_shared
> 1
7253 || windows_or_buffers_changed
);
7256 Lisp_Object tail
, frame
;
7257 int count
= BINDING_STACK_SIZE ();
7259 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7261 FOR_EACH_FRAME (tail
, frame
)
7265 /* Ignore tooltip frame. */
7266 if (EQ (frame
, tooltip_frame
))
7269 /* If a window on this frame changed size, report that to
7270 the user and clear the size-change flag. */
7271 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7273 Lisp_Object functions
;
7275 /* Clear flag first in case we get an error below. */
7276 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7277 functions
= Vwindow_size_change_functions
;
7278 GCPRO2 (tail
, functions
);
7280 while (CONSP (functions
))
7282 call1 (XCAR (functions
), frame
);
7283 functions
= XCDR (functions
);
7289 update_menu_bar (f
, 0);
7290 #ifdef HAVE_WINDOW_SYSTEM
7291 update_tool_bar (f
, 0);
7296 unbind_to (count
, Qnil
);
7300 struct frame
*sf
= SELECTED_FRAME ();
7301 update_menu_bar (sf
, 1);
7302 #ifdef HAVE_WINDOW_SYSTEM
7303 update_tool_bar (sf
, 1);
7307 /* Motif needs this. See comment in xmenu.c. Turn it off when
7308 pending_menu_activation is not defined. */
7309 #ifdef USE_X_TOOLKIT
7310 pending_menu_activation
= 0;
7315 /* Update the menu bar item list for frame F. This has to be done
7316 before we start to fill in any display lines, because it can call
7319 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7322 update_menu_bar (f
, save_match_data
)
7324 int save_match_data
;
7327 register struct window
*w
;
7329 /* If called recursively during a menu update, do nothing. This can
7330 happen when, for instance, an activate-menubar-hook causes a
7332 if (inhibit_menubar_update
)
7335 window
= FRAME_SELECTED_WINDOW (f
);
7336 w
= XWINDOW (window
);
7338 if (update_mode_lines
)
7339 w
->update_mode_line
= Qt
;
7341 if (FRAME_WINDOW_P (f
)
7343 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7344 FRAME_EXTERNAL_MENU_BAR (f
)
7346 FRAME_MENU_BAR_LINES (f
) > 0
7348 : FRAME_MENU_BAR_LINES (f
) > 0)
7350 /* If the user has switched buffers or windows, we need to
7351 recompute to reflect the new bindings. But we'll
7352 recompute when update_mode_lines is set too; that means
7353 that people can use force-mode-line-update to request
7354 that the menu bar be recomputed. The adverse effect on
7355 the rest of the redisplay algorithm is about the same as
7356 windows_or_buffers_changed anyway. */
7357 if (windows_or_buffers_changed
7358 || !NILP (w
->update_mode_line
)
7359 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7360 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7361 != !NILP (w
->last_had_star
))
7362 || ((!NILP (Vtransient_mark_mode
)
7363 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7364 != !NILP (w
->region_showing
)))
7366 struct buffer
*prev
= current_buffer
;
7367 int count
= BINDING_STACK_SIZE ();
7369 specbind (Qinhibit_menubar_update
, Qt
);
7371 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7372 if (save_match_data
)
7373 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7374 if (NILP (Voverriding_local_map_menu_flag
))
7376 specbind (Qoverriding_terminal_local_map
, Qnil
);
7377 specbind (Qoverriding_local_map
, Qnil
);
7380 /* Run the Lucid hook. */
7381 safe_run_hooks (Qactivate_menubar_hook
);
7383 /* If it has changed current-menubar from previous value,
7384 really recompute the menu-bar from the value. */
7385 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7386 call0 (Qrecompute_lucid_menubar
);
7388 safe_run_hooks (Qmenu_bar_update_hook
);
7389 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7391 /* Redisplay the menu bar in case we changed it. */
7392 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7393 if (FRAME_WINDOW_P (f
)
7394 #if defined (macintosh)
7395 /* All frames on Mac OS share the same menubar. So only the
7396 selected frame should be allowed to set it. */
7397 && f
== SELECTED_FRAME ()
7400 set_frame_menubar (f
, 0, 0);
7402 /* On a terminal screen, the menu bar is an ordinary screen
7403 line, and this makes it get updated. */
7404 w
->update_mode_line
= Qt
;
7405 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7406 /* In the non-toolkit version, the menu bar is an ordinary screen
7407 line, and this makes it get updated. */
7408 w
->update_mode_line
= Qt
;
7409 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7411 unbind_to (count
, Qnil
);
7412 set_buffer_internal_1 (prev
);
7419 /***********************************************************************
7421 ***********************************************************************/
7423 #ifdef HAVE_WINDOW_SYSTEM
7425 /* Update the tool-bar item list for frame F. This has to be done
7426 before we start to fill in any display lines. Called from
7427 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7428 and restore it here. */
7431 update_tool_bar (f
, save_match_data
)
7433 int save_match_data
;
7435 if (WINDOWP (f
->tool_bar_window
)
7436 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7441 window
= FRAME_SELECTED_WINDOW (f
);
7442 w
= XWINDOW (window
);
7444 /* If the user has switched buffers or windows, we need to
7445 recompute to reflect the new bindings. But we'll
7446 recompute when update_mode_lines is set too; that means
7447 that people can use force-mode-line-update to request
7448 that the menu bar be recomputed. The adverse effect on
7449 the rest of the redisplay algorithm is about the same as
7450 windows_or_buffers_changed anyway. */
7451 if (windows_or_buffers_changed
7452 || !NILP (w
->update_mode_line
)
7453 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7454 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7455 != !NILP (w
->last_had_star
))
7456 || ((!NILP (Vtransient_mark_mode
)
7457 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7458 != !NILP (w
->region_showing
)))
7460 struct buffer
*prev
= current_buffer
;
7461 int count
= BINDING_STACK_SIZE ();
7463 /* Set current_buffer to the buffer of the selected
7464 window of the frame, so that we get the right local
7466 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7468 /* Save match data, if we must. */
7469 if (save_match_data
)
7470 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7472 /* Make sure that we don't accidentally use bogus keymaps. */
7473 if (NILP (Voverriding_local_map_menu_flag
))
7475 specbind (Qoverriding_terminal_local_map
, Qnil
);
7476 specbind (Qoverriding_local_map
, Qnil
);
7479 /* Build desired tool-bar items from keymaps. */
7481 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7483 /* Redisplay the tool-bar in case we changed it. */
7484 w
->update_mode_line
= Qt
;
7486 unbind_to (count
, Qnil
);
7487 set_buffer_internal_1 (prev
);
7493 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7494 F's desired tool-bar contents. F->tool_bar_items must have
7495 been set up previously by calling prepare_menu_bars. */
7498 build_desired_tool_bar_string (f
)
7501 int i
, size
, size_needed
;
7502 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7503 Lisp_Object image
, plist
, props
;
7505 image
= plist
= props
= Qnil
;
7506 GCPRO3 (image
, plist
, props
);
7508 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7509 Otherwise, make a new string. */
7511 /* The size of the string we might be able to reuse. */
7512 size
= (STRINGP (f
->desired_tool_bar_string
)
7513 ? XSTRING (f
->desired_tool_bar_string
)->size
7516 /* We need one space in the string for each image. */
7517 size_needed
= f
->n_tool_bar_items
;
7519 /* Reuse f->desired_tool_bar_string, if possible. */
7520 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7521 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7525 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7526 Fremove_text_properties (make_number (0), make_number (size
),
7527 props
, f
->desired_tool_bar_string
);
7530 /* Put a `display' property on the string for the images to display,
7531 put a `menu_item' property on tool-bar items with a value that
7532 is the index of the item in F's tool-bar item vector. */
7533 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7535 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7537 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7538 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7539 int hmargin
, vmargin
, relief
, idx
, end
;
7540 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7541 extern Lisp_Object Qlaplace
;
7543 /* If image is a vector, choose the image according to the
7545 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7546 if (VECTORP (image
))
7550 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7551 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7554 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7555 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7557 xassert (ASIZE (image
) >= idx
);
7558 image
= AREF (image
, idx
);
7563 /* Ignore invalid image specifications. */
7564 if (!valid_image_p (image
))
7567 /* Display the tool-bar button pressed, or depressed. */
7568 plist
= Fcopy_sequence (XCDR (image
));
7570 /* Compute margin and relief to draw. */
7571 relief
= (tool_bar_button_relief
> 0
7572 ? tool_bar_button_relief
7573 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7574 hmargin
= vmargin
= relief
;
7576 if (INTEGERP (Vtool_bar_button_margin
)
7577 && XINT (Vtool_bar_button_margin
) > 0)
7579 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7580 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7582 else if (CONSP (Vtool_bar_button_margin
))
7584 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7585 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7586 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7588 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7589 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7590 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7593 if (auto_raise_tool_bar_buttons_p
)
7595 /* Add a `:relief' property to the image spec if the item is
7599 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7606 /* If image is selected, display it pressed, i.e. with a
7607 negative relief. If it's not selected, display it with a
7609 plist
= Fplist_put (plist
, QCrelief
,
7611 ? make_number (-relief
)
7612 : make_number (relief
)));
7617 /* Put a margin around the image. */
7618 if (hmargin
|| vmargin
)
7620 if (hmargin
== vmargin
)
7621 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7623 plist
= Fplist_put (plist
, QCmargin
,
7624 Fcons (make_number (hmargin
),
7625 make_number (vmargin
)));
7628 /* If button is not enabled, and we don't have special images
7629 for the disabled state, make the image appear disabled by
7630 applying an appropriate algorithm to it. */
7631 if (!enabled_p
&& idx
< 0)
7632 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7634 /* Put a `display' text property on the string for the image to
7635 display. Put a `menu-item' property on the string that gives
7636 the start of this item's properties in the tool-bar items
7638 image
= Fcons (Qimage
, plist
);
7639 props
= list4 (Qdisplay
, image
,
7640 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7642 /* Let the last image hide all remaining spaces in the tool bar
7643 string. The string can be longer than needed when we reuse a
7645 if (i
+ 1 == f
->n_tool_bar_items
)
7646 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7649 Fadd_text_properties (make_number (i
), make_number (end
),
7650 props
, f
->desired_tool_bar_string
);
7658 /* Display one line of the tool-bar of frame IT->f. */
7661 display_tool_bar_line (it
)
7664 struct glyph_row
*row
= it
->glyph_row
;
7665 int max_x
= it
->last_visible_x
;
7668 prepare_desired_row (row
);
7669 row
->y
= it
->current_y
;
7671 /* Note that this isn't made use of if the face hasn't a box,
7672 so there's no need to check the face here. */
7673 it
->start_of_box_run_p
= 1;
7675 while (it
->current_x
< max_x
)
7677 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7679 /* Get the next display element. */
7680 if (!get_next_display_element (it
))
7683 /* Produce glyphs. */
7684 x_before
= it
->current_x
;
7685 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7686 PRODUCE_GLYPHS (it
);
7688 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7693 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7695 if (x
+ glyph
->pixel_width
> max_x
)
7697 /* Glyph doesn't fit on line. */
7698 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7704 x
+= glyph
->pixel_width
;
7708 /* Stop at line ends. */
7709 if (ITERATOR_AT_END_OF_LINE_P (it
))
7712 set_iterator_to_next (it
, 1);
7717 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7718 extend_face_to_end_of_line (it
);
7719 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7720 last
->right_box_line_p
= 1;
7721 if (last
== row
->glyphs
[TEXT_AREA
])
7722 last
->left_box_line_p
= 1;
7723 compute_line_metrics (it
);
7725 /* If line is empty, make it occupy the rest of the tool-bar. */
7726 if (!row
->displays_text_p
)
7728 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7729 row
->ascent
= row
->phys_ascent
= 0;
7732 row
->full_width_p
= 1;
7733 row
->continued_p
= 0;
7734 row
->truncated_on_left_p
= 0;
7735 row
->truncated_on_right_p
= 0;
7737 it
->current_x
= it
->hpos
= 0;
7738 it
->current_y
+= row
->height
;
7744 /* Value is the number of screen lines needed to make all tool-bar
7745 items of frame F visible. */
7748 tool_bar_lines_needed (f
)
7751 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7754 /* Initialize an iterator for iteration over
7755 F->desired_tool_bar_string in the tool-bar window of frame F. */
7756 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7757 it
.first_visible_x
= 0;
7758 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7759 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7761 while (!ITERATOR_AT_END_P (&it
))
7763 it
.glyph_row
= w
->desired_matrix
->rows
;
7764 clear_glyph_row (it
.glyph_row
);
7765 display_tool_bar_line (&it
);
7768 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7772 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7774 "Return the number of lines occupied by the tool bar of FRAME.")
7783 frame
= selected_frame
;
7785 CHECK_FRAME (frame
, 0);
7788 if (WINDOWP (f
->tool_bar_window
)
7789 || (w
= XWINDOW (f
->tool_bar_window
),
7790 XFASTINT (w
->height
) > 0))
7792 update_tool_bar (f
, 1);
7793 if (f
->n_tool_bar_items
)
7795 build_desired_tool_bar_string (f
);
7796 nlines
= tool_bar_lines_needed (f
);
7800 return make_number (nlines
);
7804 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7805 height should be changed. */
7808 redisplay_tool_bar (f
)
7813 struct glyph_row
*row
;
7814 int change_height_p
= 0;
7816 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7817 do anything. This means you must start with tool-bar-lines
7818 non-zero to get the auto-sizing effect. Or in other words, you
7819 can turn off tool-bars by specifying tool-bar-lines zero. */
7820 if (!WINDOWP (f
->tool_bar_window
)
7821 || (w
= XWINDOW (f
->tool_bar_window
),
7822 XFASTINT (w
->height
) == 0))
7825 /* Set up an iterator for the tool-bar window. */
7826 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7827 it
.first_visible_x
= 0;
7828 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7831 /* Build a string that represents the contents of the tool-bar. */
7832 build_desired_tool_bar_string (f
);
7833 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7835 /* Display as many lines as needed to display all tool-bar items. */
7836 while (it
.current_y
< it
.last_visible_y
)
7837 display_tool_bar_line (&it
);
7839 /* It doesn't make much sense to try scrolling in the tool-bar
7840 window, so don't do it. */
7841 w
->desired_matrix
->no_scrolling_p
= 1;
7842 w
->must_be_updated_p
= 1;
7844 if (auto_resize_tool_bars_p
)
7848 /* If we couldn't display everything, change the tool-bar's
7850 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7851 change_height_p
= 1;
7853 /* If there are blank lines at the end, except for a partially
7854 visible blank line at the end that is smaller than
7855 CANON_Y_UNIT, change the tool-bar's height. */
7856 row
= it
.glyph_row
- 1;
7857 if (!row
->displays_text_p
7858 && row
->height
>= CANON_Y_UNIT (f
))
7859 change_height_p
= 1;
7861 /* If row displays tool-bar items, but is partially visible,
7862 change the tool-bar's height. */
7863 if (row
->displays_text_p
7864 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7865 change_height_p
= 1;
7867 /* Resize windows as needed by changing the `tool-bar-lines'
7870 && (nlines
= tool_bar_lines_needed (f
),
7871 nlines
!= XFASTINT (w
->height
)))
7873 extern Lisp_Object Qtool_bar_lines
;
7875 int old_height
= XFASTINT (w
->height
);
7877 XSETFRAME (frame
, f
);
7878 clear_glyph_matrix (w
->desired_matrix
);
7879 Fmodify_frame_parameters (frame
,
7880 Fcons (Fcons (Qtool_bar_lines
,
7881 make_number (nlines
)),
7883 if (XFASTINT (w
->height
) != old_height
)
7884 fonts_changed_p
= 1;
7888 return change_height_p
;
7892 /* Get information about the tool-bar item which is displayed in GLYPH
7893 on frame F. Return in *PROP_IDX the index where tool-bar item
7894 properties start in F->tool_bar_items. Value is zero if
7895 GLYPH doesn't display a tool-bar item. */
7898 tool_bar_item_info (f
, glyph
, prop_idx
)
7900 struct glyph
*glyph
;
7906 /* Get the text property `menu-item' at pos. The value of that
7907 property is the start index of this item's properties in
7908 F->tool_bar_items. */
7909 prop
= Fget_text_property (make_number (glyph
->charpos
),
7910 Qmenu_item
, f
->current_tool_bar_string
);
7911 if (INTEGERP (prop
))
7913 *prop_idx
= XINT (prop
);
7922 #endif /* HAVE_WINDOW_SYSTEM */
7926 /************************************************************************
7927 Horizontal scrolling
7928 ************************************************************************/
7930 static int hscroll_window_tree
P_ ((Lisp_Object
));
7931 static int hscroll_windows
P_ ((Lisp_Object
));
7933 /* For all leaf windows in the window tree rooted at WINDOW, set their
7934 hscroll value so that PT is (i) visible in the window, and (ii) so
7935 that it is not within a certain margin at the window's left and
7936 right border. Value is non-zero if any window's hscroll has been
7940 hscroll_window_tree (window
)
7943 int hscrolled_p
= 0;
7945 while (WINDOWP (window
))
7947 struct window
*w
= XWINDOW (window
);
7949 if (WINDOWP (w
->hchild
))
7950 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7951 else if (WINDOWP (w
->vchild
))
7952 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7953 else if (w
->cursor
.vpos
>= 0)
7955 int hscroll_margin
, text_area_x
, text_area_y
;
7956 int text_area_width
, text_area_height
;
7957 struct glyph_row
*current_cursor_row
7958 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7959 struct glyph_row
*desired_cursor_row
7960 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7961 struct glyph_row
*cursor_row
7962 = (desired_cursor_row
->enabled_p
7963 ? desired_cursor_row
7964 : current_cursor_row
);
7966 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7967 &text_area_width
, &text_area_height
);
7969 /* Scroll when cursor is inside this scroll margin. */
7970 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7972 if ((XFASTINT (w
->hscroll
)
7973 && w
->cursor
.x
< hscroll_margin
)
7974 || (cursor_row
->enabled_p
7975 && cursor_row
->truncated_on_right_p
7976 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7980 struct buffer
*saved_current_buffer
;
7983 /* Find point in a display of infinite width. */
7984 saved_current_buffer
= current_buffer
;
7985 current_buffer
= XBUFFER (w
->buffer
);
7987 if (w
== XWINDOW (selected_window
))
7988 pt
= BUF_PT (current_buffer
);
7991 pt
= marker_position (w
->pointm
);
7992 pt
= max (BEGV
, pt
);
7996 /* Move iterator to pt starting at cursor_row->start in
7997 a line with infinite width. */
7998 init_to_row_start (&it
, w
, cursor_row
);
7999 it
.last_visible_x
= INFINITY
;
8000 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8001 current_buffer
= saved_current_buffer
;
8003 /* Center cursor in window. */
8004 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
8005 / CANON_X_UNIT (it
.f
));
8006 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8008 /* Don't call Fset_window_hscroll if value hasn't
8009 changed because it will prevent redisplay
8011 if (XFASTINT (w
->hscroll
) != hscroll
)
8013 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8014 w
->hscroll
= make_number (hscroll
);
8023 /* Value is non-zero if hscroll of any leaf window has been changed. */
8028 /* Set hscroll so that cursor is visible and not inside horizontal
8029 scroll margins for all windows in the tree rooted at WINDOW. See
8030 also hscroll_window_tree above. Value is non-zero if any window's
8031 hscroll has been changed. If it has, desired matrices on the frame
8032 of WINDOW are cleared. */
8035 hscroll_windows (window
)
8040 if (automatic_hscrolling_p
)
8042 hscrolled_p
= hscroll_window_tree (window
);
8044 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8053 /************************************************************************
8055 ************************************************************************/
8057 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8058 to a non-zero value. This is sometimes handy to have in a debugger
8063 /* First and last unchanged row for try_window_id. */
8065 int debug_first_unchanged_at_end_vpos
;
8066 int debug_last_unchanged_at_beg_vpos
;
8068 /* Delta vpos and y. */
8070 int debug_dvpos
, debug_dy
;
8072 /* Delta in characters and bytes for try_window_id. */
8074 int debug_delta
, debug_delta_bytes
;
8076 /* Values of window_end_pos and window_end_vpos at the end of
8079 int debug_end_pos
, debug_end_vpos
;
8081 /* Append a string to W->desired_matrix->method. FMT is a printf
8082 format string. A1...A9 are a supplement for a variable-length
8083 argument list. If trace_redisplay_p is non-zero also printf the
8084 resulting string to stderr. */
8087 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8090 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8093 char *method
= w
->desired_matrix
->method
;
8094 int len
= strlen (method
);
8095 int size
= sizeof w
->desired_matrix
->method
;
8096 int remaining
= size
- len
- 1;
8098 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8099 if (len
&& remaining
)
8105 strncpy (method
+ len
, buffer
, remaining
);
8107 if (trace_redisplay_p
)
8108 fprintf (stderr
, "%p (%s): %s\n",
8110 ((BUFFERP (w
->buffer
)
8111 && STRINGP (XBUFFER (w
->buffer
)->name
))
8112 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8117 #endif /* GLYPH_DEBUG */
8120 /* This counter is used to clear the face cache every once in a while
8121 in redisplay_internal. It is incremented for each redisplay.
8122 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8125 #define CLEAR_FACE_CACHE_COUNT 10000
8126 static int clear_face_cache_count
;
8128 /* Record the previous terminal frame we displayed. */
8130 static struct frame
*previous_terminal_frame
;
8132 /* Non-zero while redisplay_internal is in progress. */
8137 /* Value is non-zero if all changes in window W, which displays
8138 current_buffer, are in the text between START and END. START is a
8139 buffer position, END is given as a distance from Z. Used in
8140 redisplay_internal for display optimization. */
8143 text_outside_line_unchanged_p (w
, start
, end
)
8147 int unchanged_p
= 1;
8149 /* If text or overlays have changed, see where. */
8150 if (XFASTINT (w
->last_modified
) < MODIFF
8151 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8153 /* Gap in the line? */
8154 if (GPT
< start
|| Z
- GPT
< end
)
8157 /* Changes start in front of the line, or end after it? */
8159 && (BEG_UNCHANGED
< start
- 1
8160 || END_UNCHANGED
< end
))
8163 /* If selective display, can't optimize if changes start at the
8164 beginning of the line. */
8166 && INTEGERP (current_buffer
->selective_display
)
8167 && XINT (current_buffer
->selective_display
) > 0
8168 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8176 /* Do a frame update, taking possible shortcuts into account. This is
8177 the main external entry point for redisplay.
8179 If the last redisplay displayed an echo area message and that message
8180 is no longer requested, we clear the echo area or bring back the
8181 mini-buffer if that is in use. */
8186 redisplay_internal (0);
8189 /* Return 1 if point moved out of or into a composition. Otherwise
8190 return 0. PREV_BUF and PREV_PT are the last point buffer and
8191 position. BUF and PT are the current point buffer and position. */
8194 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8195 struct buffer
*prev_buf
, *buf
;
8202 XSETBUFFER (buffer
, buf
);
8203 /* Check a composition at the last point if point moved within the
8205 if (prev_buf
== buf
)
8208 /* Point didn't move. */
8211 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8212 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8213 && COMPOSITION_VALID_P (start
, end
, prop
)
8214 && start
< prev_pt
&& end
> prev_pt
)
8215 /* The last point was within the composition. Return 1 iff
8216 point moved out of the composition. */
8217 return (pt
<= start
|| pt
>= end
);
8220 /* Check a composition at the current point. */
8221 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8222 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8223 && COMPOSITION_VALID_P (start
, end
, prop
)
8224 && start
< pt
&& end
> pt
);
8227 /* Reconsider the setting of B->clip_changed which is displayed
8231 reconsider_clip_changes (w
, b
)
8235 if (b
->prevent_redisplay_optimizations_p
)
8236 b
->clip_changed
= 1;
8237 else if (b
->clip_changed
8238 && !NILP (w
->window_end_valid
)
8239 && w
->current_matrix
->buffer
== b
8240 && w
->current_matrix
->zv
== BUF_ZV (b
)
8241 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8242 b
->clip_changed
= 0;
8244 /* If display wasn't paused, and W is not a tool bar window, see if
8245 point has been moved into or out of a composition. In that case,
8246 we set b->clip_changed to 1 to force updating the screen. If
8247 b->clip_changed has already been set to 1, we can skip this
8249 if (!b
->clip_changed
8250 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8254 if (w
== XWINDOW (selected_window
))
8255 pt
= BUF_PT (current_buffer
);
8257 pt
= marker_position (w
->pointm
);
8259 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8260 || pt
!= XINT (w
->last_point
))
8261 && check_point_in_composition (w
->current_matrix
->buffer
,
8262 XINT (w
->last_point
),
8263 XBUFFER (w
->buffer
), pt
))
8264 b
->clip_changed
= 1;
8269 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8270 response to any user action; therefore, we should preserve the echo
8271 area. (Actually, our caller does that job.) Perhaps in the future
8272 avoid recentering windows if it is not necessary; currently that
8273 causes some problems. */
8276 redisplay_internal (preserve_echo_area
)
8277 int preserve_echo_area
;
8279 struct window
*w
= XWINDOW (selected_window
);
8280 struct frame
*f
= XFRAME (w
->frame
);
8282 int must_finish
= 0;
8283 struct text_pos tlbufpos
, tlendpos
;
8284 int number_of_visible_frames
;
8286 struct frame
*sf
= SELECTED_FRAME ();
8288 /* Non-zero means redisplay has to consider all windows on all
8289 frames. Zero means, only selected_window is considered. */
8290 int consider_all_windows_p
;
8292 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8294 /* No redisplay if running in batch mode or frame is not yet fully
8295 initialized, or redisplay is explicitly turned off by setting
8296 Vinhibit_redisplay. */
8298 || !NILP (Vinhibit_redisplay
)
8299 || !f
->glyphs_initialized_p
)
8302 /* The flag redisplay_performed_directly_p is set by
8303 direct_output_for_insert when it already did the whole screen
8304 update necessary. */
8305 if (redisplay_performed_directly_p
)
8307 redisplay_performed_directly_p
= 0;
8308 if (!hscroll_windows (selected_window
))
8312 #ifdef USE_X_TOOLKIT
8313 if (popup_activated ())
8317 /* I don't think this happens but let's be paranoid. */
8321 /* Record a function that resets redisplaying_p to its old value
8322 when we leave this function. */
8323 count
= BINDING_STACK_SIZE ();
8324 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8329 reconsider_clip_changes (w
, current_buffer
);
8331 /* If new fonts have been loaded that make a glyph matrix adjustment
8332 necessary, do it. */
8333 if (fonts_changed_p
)
8335 adjust_glyphs (NULL
);
8336 ++windows_or_buffers_changed
;
8337 fonts_changed_p
= 0;
8340 /* If face_change_count is non-zero, init_iterator will free all
8341 realized faces, which includes the faces referenced from current
8342 matrices. So, we can't reuse current matrices in this case. */
8343 if (face_change_count
)
8344 ++windows_or_buffers_changed
;
8346 if (! FRAME_WINDOW_P (sf
)
8347 && previous_terminal_frame
!= sf
)
8349 /* Since frames on an ASCII terminal share the same display
8350 area, displaying a different frame means redisplay the whole
8352 windows_or_buffers_changed
++;
8353 SET_FRAME_GARBAGED (sf
);
8354 XSETFRAME (Vterminal_frame
, sf
);
8356 previous_terminal_frame
= sf
;
8358 /* Set the visible flags for all frames. Do this before checking
8359 for resized or garbaged frames; they want to know if their frames
8360 are visible. See the comment in frame.h for
8361 FRAME_SAMPLE_VISIBILITY. */
8363 Lisp_Object tail
, frame
;
8365 number_of_visible_frames
= 0;
8367 FOR_EACH_FRAME (tail
, frame
)
8369 struct frame
*f
= XFRAME (frame
);
8371 FRAME_SAMPLE_VISIBILITY (f
);
8372 if (FRAME_VISIBLE_P (f
))
8373 ++number_of_visible_frames
;
8374 clear_desired_matrices (f
);
8378 /* Notice any pending interrupt request to change frame size. */
8379 do_pending_window_change (1);
8381 /* Clear frames marked as garbaged. */
8383 clear_garbaged_frames ();
8385 /* Build menubar and tool-bar items. */
8386 prepare_menu_bars ();
8388 if (windows_or_buffers_changed
)
8389 update_mode_lines
++;
8391 /* Detect case that we need to write or remove a star in the mode line. */
8392 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8394 w
->update_mode_line
= Qt
;
8395 if (buffer_shared
> 1)
8396 update_mode_lines
++;
8399 /* If %c is in the mode line, update it if needed. */
8400 if (!NILP (w
->column_number_displayed
)
8401 /* This alternative quickly identifies a common case
8402 where no change is needed. */
8403 && !(PT
== XFASTINT (w
->last_point
)
8404 && XFASTINT (w
->last_modified
) >= MODIFF
8405 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8406 && XFASTINT (w
->column_number_displayed
) != current_column ())
8407 w
->update_mode_line
= Qt
;
8409 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8411 /* The variable buffer_shared is set in redisplay_window and
8412 indicates that we redisplay a buffer in different windows. See
8414 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8416 /* If specs for an arrow have changed, do thorough redisplay
8417 to ensure we remove any arrow that should no longer exist. */
8418 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8419 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8420 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8422 /* Normally the message* functions will have already displayed and
8423 updated the echo area, but the frame may have been trashed, or
8424 the update may have been preempted, so display the echo area
8425 again here. Checking message_cleared_p captures the case that
8426 the echo area should be cleared. */
8427 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8428 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8429 || (message_cleared_p
&& minibuf_level
== 0))
8431 int window_height_changed_p
= echo_area_display (0);
8434 /* If we don't display the current message, don't clear the
8435 message_cleared_p flag, because, if we did, we wouldn't clear
8436 the echo area in the next redisplay which doesn't preserve
8438 if (!display_last_displayed_message_p
)
8439 message_cleared_p
= 0;
8441 if (fonts_changed_p
)
8443 else if (window_height_changed_p
)
8445 consider_all_windows_p
= 1;
8446 ++update_mode_lines
;
8447 ++windows_or_buffers_changed
;
8449 /* If window configuration was changed, frames may have been
8450 marked garbaged. Clear them or we will experience
8451 surprises wrt scrolling. */
8453 clear_garbaged_frames ();
8456 else if (EQ (selected_window
, minibuf_window
)
8457 && (current_buffer
->clip_changed
8458 || XFASTINT (w
->last_modified
) < MODIFF
8459 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8460 && resize_mini_window (w
, 0))
8462 /* Resized active mini-window to fit the size of what it is
8463 showing if its contents might have changed. */
8465 consider_all_windows_p
= 1;
8466 ++windows_or_buffers_changed
;
8467 ++update_mode_lines
;
8469 /* If window configuration was changed, frames may have been
8470 marked garbaged. Clear them or we will experience
8471 surprises wrt scrolling. */
8473 clear_garbaged_frames ();
8477 /* If showing the region, and mark has changed, we must redisplay
8478 the whole window. The assignment to this_line_start_pos prevents
8479 the optimization directly below this if-statement. */
8480 if (((!NILP (Vtransient_mark_mode
)
8481 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8482 != !NILP (w
->region_showing
))
8483 || (!NILP (w
->region_showing
)
8484 && !EQ (w
->region_showing
,
8485 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8486 CHARPOS (this_line_start_pos
) = 0;
8488 /* Optimize the case that only the line containing the cursor in the
8489 selected window has changed. Variables starting with this_ are
8490 set in display_line and record information about the line
8491 containing the cursor. */
8492 tlbufpos
= this_line_start_pos
;
8493 tlendpos
= this_line_end_pos
;
8494 if (!consider_all_windows_p
8495 && CHARPOS (tlbufpos
) > 0
8496 && NILP (w
->update_mode_line
)
8497 && !current_buffer
->clip_changed
8498 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8499 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8500 /* Make sure recorded data applies to current buffer, etc. */
8501 && this_line_buffer
== current_buffer
8502 && current_buffer
== XBUFFER (w
->buffer
)
8503 && NILP (w
->force_start
)
8504 /* Point must be on the line that we have info recorded about. */
8505 && PT
>= CHARPOS (tlbufpos
)
8506 && PT
<= Z
- CHARPOS (tlendpos
)
8507 /* All text outside that line, including its final newline,
8508 must be unchanged */
8509 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8510 CHARPOS (tlendpos
)))
8512 if (CHARPOS (tlbufpos
) > BEGV
8513 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8514 && (CHARPOS (tlbufpos
) == ZV
8515 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8516 /* Former continuation line has disappeared by becoming empty */
8518 else if (XFASTINT (w
->last_modified
) < MODIFF
8519 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8520 || MINI_WINDOW_P (w
))
8522 /* We have to handle the case of continuation around a
8523 wide-column character (See the comment in indent.c around
8526 For instance, in the following case:
8528 -------- Insert --------
8529 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8530 J_I_ ==> J_I_ `^^' are cursors.
8534 As we have to redraw the line above, we should goto cancel. */
8537 int line_height_before
= this_line_pixel_height
;
8539 /* Note that start_display will handle the case that the
8540 line starting at tlbufpos is a continuation lines. */
8541 start_display (&it
, w
, tlbufpos
);
8543 /* Implementation note: It this still necessary? */
8544 if (it
.current_x
!= this_line_start_x
)
8547 TRACE ((stderr
, "trying display optimization 1\n"));
8548 w
->cursor
.vpos
= -1;
8549 overlay_arrow_seen
= 0;
8550 it
.vpos
= this_line_vpos
;
8551 it
.current_y
= this_line_y
;
8552 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8555 /* If line contains point, is not continued,
8556 and ends at same distance from eob as before, we win */
8557 if (w
->cursor
.vpos
>= 0
8558 /* Line is not continued, otherwise this_line_start_pos
8559 would have been set to 0 in display_line. */
8560 && CHARPOS (this_line_start_pos
)
8561 /* Line ends as before. */
8562 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8563 /* Line has same height as before. Otherwise other lines
8564 would have to be shifted up or down. */
8565 && this_line_pixel_height
== line_height_before
)
8567 /* If this is not the window's last line, we must adjust
8568 the charstarts of the lines below. */
8569 if (it
.current_y
< it
.last_visible_y
)
8571 struct glyph_row
*row
8572 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8573 int delta
, delta_bytes
;
8575 if (Z
- CHARPOS (tlendpos
) == ZV
)
8577 /* This line ends at end of (accessible part of)
8578 buffer. There is no newline to count. */
8580 - CHARPOS (tlendpos
)
8581 - MATRIX_ROW_START_CHARPOS (row
));
8582 delta_bytes
= (Z_BYTE
8583 - BYTEPOS (tlendpos
)
8584 - MATRIX_ROW_START_BYTEPOS (row
));
8588 /* This line ends in a newline. Must take
8589 account of the newline and the rest of the
8590 text that follows. */
8592 - CHARPOS (tlendpos
)
8593 - MATRIX_ROW_START_CHARPOS (row
));
8594 delta_bytes
= (Z_BYTE
8595 - BYTEPOS (tlendpos
)
8596 - MATRIX_ROW_START_BYTEPOS (row
));
8599 increment_matrix_positions (w
->current_matrix
,
8601 w
->current_matrix
->nrows
,
8602 delta
, delta_bytes
);
8605 /* If this row displays text now but previously didn't,
8606 or vice versa, w->window_end_vpos may have to be
8608 if ((it
.glyph_row
- 1)->displays_text_p
)
8610 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8611 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8613 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8614 && this_line_vpos
> 0)
8615 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8616 w
->window_end_valid
= Qnil
;
8618 /* Update hint: No need to try to scroll in update_window. */
8619 w
->desired_matrix
->no_scrolling_p
= 1;
8622 *w
->desired_matrix
->method
= 0;
8623 debug_method_add (w
, "optimization 1");
8630 else if (/* Cursor position hasn't changed. */
8631 PT
== XFASTINT (w
->last_point
)
8632 /* Make sure the cursor was last displayed
8633 in this window. Otherwise we have to reposition it. */
8634 && 0 <= w
->cursor
.vpos
8635 && XINT (w
->height
) > w
->cursor
.vpos
)
8639 do_pending_window_change (1);
8641 /* We used to always goto end_of_redisplay here, but this
8642 isn't enough if we have a blinking cursor. */
8643 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8644 goto end_of_redisplay
;
8648 /* If highlighting the region, or if the cursor is in the echo area,
8649 then we can't just move the cursor. */
8650 else if (! (!NILP (Vtransient_mark_mode
)
8651 && !NILP (current_buffer
->mark_active
))
8652 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8653 || highlight_nonselected_windows
)
8654 && NILP (w
->region_showing
)
8655 && NILP (Vshow_trailing_whitespace
)
8656 && !cursor_in_echo_area
)
8659 struct glyph_row
*row
;
8661 /* Skip from tlbufpos to PT and see where it is. Note that
8662 PT may be in invisible text. If so, we will end at the
8663 next visible position. */
8664 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8665 NULL
, DEFAULT_FACE_ID
);
8666 it
.current_x
= this_line_start_x
;
8667 it
.current_y
= this_line_y
;
8668 it
.vpos
= this_line_vpos
;
8670 /* The call to move_it_to stops in front of PT, but
8671 moves over before-strings. */
8672 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8674 if (it
.vpos
== this_line_vpos
8675 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8678 xassert (this_line_vpos
== it
.vpos
);
8679 xassert (this_line_y
== it
.current_y
);
8680 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8682 *w
->desired_matrix
->method
= 0;
8683 debug_method_add (w
, "optimization 3");
8692 /* Text changed drastically or point moved off of line. */
8693 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8696 CHARPOS (this_line_start_pos
) = 0;
8697 consider_all_windows_p
|= buffer_shared
> 1;
8698 ++clear_face_cache_count
;
8701 /* Build desired matrices, and update the display. If
8702 consider_all_windows_p is non-zero, do it for all windows on all
8703 frames. Otherwise do it for selected_window, only. */
8705 if (consider_all_windows_p
)
8707 Lisp_Object tail
, frame
;
8708 int i
, n
= 0, size
= 50;
8709 struct frame
**updated
8710 = (struct frame
**) alloca (size
* sizeof *updated
);
8712 /* Clear the face cache eventually. */
8713 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8715 clear_face_cache (0);
8716 clear_face_cache_count
= 0;
8719 /* Recompute # windows showing selected buffer. This will be
8720 incremented each time such a window is displayed. */
8723 FOR_EACH_FRAME (tail
, frame
)
8725 struct frame
*f
= XFRAME (frame
);
8727 if (FRAME_WINDOW_P (f
) || f
== sf
)
8729 /* Mark all the scroll bars to be removed; we'll redeem
8730 the ones we want when we redisplay their windows. */
8731 if (condemn_scroll_bars_hook
)
8732 condemn_scroll_bars_hook (f
);
8734 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8735 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8737 /* Any scroll bars which redisplay_windows should have
8738 nuked should now go away. */
8739 if (judge_scroll_bars_hook
)
8740 judge_scroll_bars_hook (f
);
8742 /* If fonts changed, display again. */
8743 if (fonts_changed_p
)
8746 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8748 /* See if we have to hscroll. */
8749 if (hscroll_windows (f
->root_window
))
8752 /* Prevent various kinds of signals during display
8753 update. stdio is not robust about handling
8754 signals, which can cause an apparent I/O
8756 if (interrupt_input
)
8760 /* Update the display. */
8761 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8762 pause
|= update_frame (f
, 0, 0);
8768 int nbytes
= size
* sizeof *updated
;
8769 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8770 bcopy (updated
, p
, nbytes
);
8779 /* Do the mark_window_display_accurate after all windows have
8780 been redisplayed because this call resets flags in buffers
8781 which are needed for proper redisplay. */
8782 for (i
= 0; i
< n
; ++i
)
8784 struct frame
*f
= updated
[i
];
8785 mark_window_display_accurate (f
->root_window
, 1);
8786 if (frame_up_to_date_hook
)
8787 frame_up_to_date_hook (f
);
8790 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8792 Lisp_Object mini_window
;
8793 struct frame
*mini_frame
;
8795 redisplay_window (selected_window
, 1);
8797 /* Compare desired and current matrices, perform output. */
8800 /* If fonts changed, display again. */
8801 if (fonts_changed_p
)
8804 /* Prevent various kinds of signals during display update.
8805 stdio is not robust about handling signals,
8806 which can cause an apparent I/O error. */
8807 if (interrupt_input
)
8811 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8813 if (hscroll_windows (selected_window
))
8816 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8817 pause
= update_frame (sf
, 0, 0);
8820 /* We may have called echo_area_display at the top of this
8821 function. If the echo area is on another frame, that may
8822 have put text on a frame other than the selected one, so the
8823 above call to update_frame would not have caught it. Catch
8825 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8826 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8828 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8830 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8831 pause
|= update_frame (mini_frame
, 0, 0);
8832 if (!pause
&& hscroll_windows (mini_window
))
8837 /* If display was paused because of pending input, make sure we do a
8838 thorough update the next time. */
8841 /* Prevent the optimization at the beginning of
8842 redisplay_internal that tries a single-line update of the
8843 line containing the cursor in the selected window. */
8844 CHARPOS (this_line_start_pos
) = 0;
8846 /* Let the overlay arrow be updated the next time. */
8847 if (!NILP (last_arrow_position
))
8849 last_arrow_position
= Qt
;
8850 last_arrow_string
= Qt
;
8853 /* If we pause after scrolling, some rows in the current
8854 matrices of some windows are not valid. */
8855 if (!WINDOW_FULL_WIDTH_P (w
)
8856 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8857 update_mode_lines
= 1;
8861 if (!consider_all_windows_p
)
8863 /* This has already been done above if
8864 consider_all_windows_p is set. */
8865 mark_window_display_accurate_1 (w
, 1);
8867 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8868 last_arrow_string
= Voverlay_arrow_string
;
8870 if (frame_up_to_date_hook
!= 0)
8871 frame_up_to_date_hook (sf
);
8874 update_mode_lines
= 0;
8875 windows_or_buffers_changed
= 0;
8878 /* Start SIGIO interrupts coming again. Having them off during the
8879 code above makes it less likely one will discard output, but not
8880 impossible, since there might be stuff in the system buffer here.
8881 But it is much hairier to try to do anything about that. */
8882 if (interrupt_input
)
8886 /* If a frame has become visible which was not before, redisplay
8887 again, so that we display it. Expose events for such a frame
8888 (which it gets when becoming visible) don't call the parts of
8889 redisplay constructing glyphs, so simply exposing a frame won't
8890 display anything in this case. So, we have to display these
8891 frames here explicitly. */
8894 Lisp_Object tail
, frame
;
8897 FOR_EACH_FRAME (tail
, frame
)
8899 int this_is_visible
= 0;
8901 if (XFRAME (frame
)->visible
)
8902 this_is_visible
= 1;
8903 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8904 if (XFRAME (frame
)->visible
)
8905 this_is_visible
= 1;
8907 if (this_is_visible
)
8911 if (new_count
!= number_of_visible_frames
)
8912 windows_or_buffers_changed
++;
8915 /* Change frame size now if a change is pending. */
8916 do_pending_window_change (1);
8918 /* If we just did a pending size change, or have additional
8919 visible frames, redisplay again. */
8920 if (windows_or_buffers_changed
&& !pause
)
8925 unbind_to (count
, Qnil
);
8929 /* Redisplay, but leave alone any recent echo area message unless
8930 another message has been requested in its place.
8932 This is useful in situations where you need to redisplay but no
8933 user action has occurred, making it inappropriate for the message
8934 area to be cleared. See tracking_off and
8935 wait_reading_process_input for examples of these situations.
8937 FROM_WHERE is an integer saying from where this function was
8938 called. This is useful for debugging. */
8941 redisplay_preserve_echo_area (from_where
)
8944 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
8946 if (!NILP (echo_area_buffer
[1]))
8948 /* We have a previously displayed message, but no current
8949 message. Redisplay the previous message. */
8950 display_last_displayed_message_p
= 1;
8951 redisplay_internal (1);
8952 display_last_displayed_message_p
= 0;
8955 redisplay_internal (1);
8959 /* Function registered with record_unwind_protect in
8960 redisplay_internal. Clears the flag indicating that a redisplay is
8964 unwind_redisplay (old_redisplaying_p
)
8965 Lisp_Object old_redisplaying_p
;
8967 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8972 /* Mark the display of window W as accurate or inaccurate. If
8973 ACCURATE_P is non-zero mark display of W as accurate. If
8974 ACCURATE_P is zero, arrange for W to be redisplayed the next time
8975 redisplay_internal is called. */
8978 mark_window_display_accurate_1 (w
, accurate_p
)
8982 if (BUFFERP (w
->buffer
))
8984 struct buffer
*b
= XBUFFER (w
->buffer
);
8987 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
8988 w
->last_overlay_modified
8989 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8991 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
8995 b
->clip_changed
= 0;
8996 b
->prevent_redisplay_optimizations_p
= 0;
8998 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8999 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9000 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9001 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9003 w
->current_matrix
->buffer
= b
;
9004 w
->current_matrix
->begv
= BUF_BEGV (b
);
9005 w
->current_matrix
->zv
= BUF_ZV (b
);
9007 w
->last_cursor
= w
->cursor
;
9008 w
->last_cursor_off_p
= w
->cursor_off_p
;
9010 if (w
== XWINDOW (selected_window
))
9011 w
->last_point
= make_number (BUF_PT (b
));
9013 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9019 w
->window_end_valid
= w
->buffer
;
9020 #if 0 /* This is incorrect with variable-height lines. */
9021 xassert (XINT (w
->window_end_vpos
)
9023 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9025 w
->update_mode_line
= Qnil
;
9030 /* Mark the display of windows in the window tree rooted at WINDOW as
9031 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9032 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9033 be redisplayed the next time redisplay_internal is called. */
9036 mark_window_display_accurate (window
, accurate_p
)
9042 for (; !NILP (window
); window
= w
->next
)
9044 w
= XWINDOW (window
);
9045 mark_window_display_accurate_1 (w
, accurate_p
);
9047 if (!NILP (w
->vchild
))
9048 mark_window_display_accurate (w
->vchild
, accurate_p
);
9049 if (!NILP (w
->hchild
))
9050 mark_window_display_accurate (w
->hchild
, accurate_p
);
9055 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9056 last_arrow_string
= Voverlay_arrow_string
;
9060 /* Force a thorough redisplay the next time by setting
9061 last_arrow_position and last_arrow_string to t, which is
9062 unequal to any useful value of Voverlay_arrow_... */
9063 last_arrow_position
= Qt
;
9064 last_arrow_string
= Qt
;
9069 /* Return value in display table DP (Lisp_Char_Table *) for character
9070 C. Since a display table doesn't have any parent, we don't have to
9071 follow parent. Do not call this function directly but use the
9072 macro DISP_CHAR_VECTOR. */
9075 disp_char_vector (dp
, c
)
9076 struct Lisp_Char_Table
*dp
;
9082 if (SINGLE_BYTE_CHAR_P (c
))
9083 return (dp
->contents
[c
]);
9085 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9088 else if (code
[2] < 32)
9091 /* Here, the possible range of code[0] (== charset ID) is
9092 128..max_charset. Since the top level char table contains data
9093 for multibyte characters after 256th element, we must increment
9094 code[0] by 128 to get a correct index. */
9096 code
[3] = -1; /* anchor */
9098 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9100 val
= dp
->contents
[code
[i
]];
9101 if (!SUB_CHAR_TABLE_P (val
))
9102 return (NILP (val
) ? dp
->defalt
: val
);
9105 /* Here, val is a sub char table. We return the default value of
9107 return (dp
->defalt
);
9112 /***********************************************************************
9114 ***********************************************************************/
9116 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9119 redisplay_windows (window
)
9122 while (!NILP (window
))
9124 struct window
*w
= XWINDOW (window
);
9126 if (!NILP (w
->hchild
))
9127 redisplay_windows (w
->hchild
);
9128 else if (!NILP (w
->vchild
))
9129 redisplay_windows (w
->vchild
);
9131 redisplay_window (window
, 0);
9138 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9139 DELTA is the number of bytes by which positions recorded in ROW
9140 differ from current buffer positions. */
9143 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9145 struct glyph_row
*row
;
9146 struct glyph_matrix
*matrix
;
9147 int delta
, delta_bytes
, dy
, dvpos
;
9149 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9150 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9152 int pt_old
= PT
- delta
;
9154 /* Skip over glyphs not having an object at the start of the row.
9155 These are special glyphs like truncation marks on terminal
9157 if (row
->displays_text_p
)
9159 && INTEGERP (glyph
->object
)
9160 && glyph
->charpos
< 0)
9162 x
+= glyph
->pixel_width
;
9167 && !INTEGERP (glyph
->object
)
9168 && (!BUFFERP (glyph
->object
)
9169 || glyph
->charpos
< pt_old
))
9171 x
+= glyph
->pixel_width
;
9175 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9177 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9178 w
->cursor
.y
= row
->y
+ dy
;
9180 if (w
== XWINDOW (selected_window
))
9182 if (!row
->continued_p
9183 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9186 this_line_buffer
= XBUFFER (w
->buffer
);
9188 CHARPOS (this_line_start_pos
)
9189 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9190 BYTEPOS (this_line_start_pos
)
9191 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9193 CHARPOS (this_line_end_pos
)
9194 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9195 BYTEPOS (this_line_end_pos
)
9196 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9198 this_line_y
= w
->cursor
.y
;
9199 this_line_pixel_height
= row
->height
;
9200 this_line_vpos
= w
->cursor
.vpos
;
9201 this_line_start_x
= row
->x
;
9204 CHARPOS (this_line_start_pos
) = 0;
9209 /* Run window scroll functions, if any, for WINDOW with new window
9210 start STARTP. Sets the window start of WINDOW to that position.
9212 We assume that the window's buffer is really current. */
9214 static INLINE
struct text_pos
9215 run_window_scroll_functions (window
, startp
)
9217 struct text_pos startp
;
9219 struct window
*w
= XWINDOW (window
);
9220 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9222 if (current_buffer
!= XBUFFER (w
->buffer
))
9225 if (!NILP (Vwindow_scroll_functions
))
9227 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9228 make_number (CHARPOS (startp
)));
9229 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9230 /* In case the hook functions switch buffers. */
9231 if (current_buffer
!= XBUFFER (w
->buffer
))
9232 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9239 /* Modify the desired matrix of window W and W->vscroll so that the
9240 line containing the cursor is fully visible. */
9243 make_cursor_line_fully_visible (w
)
9246 struct glyph_matrix
*matrix
;
9247 struct glyph_row
*row
;
9250 /* It's not always possible to find the cursor, e.g, when a window
9251 is full of overlay strings. Don't do anything in that case. */
9252 if (w
->cursor
.vpos
< 0)
9255 matrix
= w
->desired_matrix
;
9256 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9258 /* If the cursor row is not partially visible, there's nothing
9260 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9263 /* If the row the cursor is in is taller than the window's height,
9264 it's not clear what to do, so do nothing. */
9265 window_height
= window_box_height (w
);
9266 if (row
->height
>= window_height
)
9269 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9271 int dy
= row
->height
- row
->visible_height
;
9274 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9276 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9278 int dy
= - (row
->height
- row
->visible_height
);
9281 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9284 /* When we change the cursor y-position of the selected window,
9285 change this_line_y as well so that the display optimization for
9286 the cursor line of the selected window in redisplay_internal uses
9287 the correct y-position. */
9288 if (w
== XWINDOW (selected_window
))
9289 this_line_y
= w
->cursor
.y
;
9293 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9294 non-zero means only WINDOW is redisplayed in redisplay_internal.
9295 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9296 in redisplay_window to bring a partially visible line into view in
9297 the case that only the cursor has moved.
9301 1 if scrolling succeeded
9303 0 if scrolling didn't find point.
9305 -1 if new fonts have been loaded so that we must interrupt
9306 redisplay, adjust glyph matrices, and try again. */
9309 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9310 scroll_step
, temp_scroll_step
)
9312 int just_this_one_p
;
9313 int scroll_conservatively
, scroll_step
;
9314 int temp_scroll_step
;
9316 struct window
*w
= XWINDOW (window
);
9317 struct frame
*f
= XFRAME (w
->frame
);
9318 struct text_pos scroll_margin_pos
;
9319 struct text_pos pos
;
9320 struct text_pos startp
;
9322 Lisp_Object window_end
;
9323 int this_scroll_margin
;
9327 int amount_to_scroll
= 0;
9328 Lisp_Object aggressive
;
9332 debug_method_add (w
, "try_scrolling");
9335 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9337 /* Compute scroll margin height in pixels. We scroll when point is
9338 within this distance from the top or bottom of the window. */
9339 if (scroll_margin
> 0)
9341 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9342 this_scroll_margin
*= CANON_Y_UNIT (f
);
9345 this_scroll_margin
= 0;
9347 /* Compute how much we should try to scroll maximally to bring point
9349 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9350 scroll_max
= max (scroll_step
,
9351 max (scroll_conservatively
, temp_scroll_step
));
9352 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9353 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9354 /* We're trying to scroll because of aggressive scrolling
9355 but no scroll_step is set. Choose an arbitrary one. Maybe
9356 there should be a variable for this. */
9360 scroll_max
*= CANON_Y_UNIT (f
);
9362 /* Decide whether we have to scroll down. Start at the window end
9363 and move this_scroll_margin up to find the position of the scroll
9365 window_end
= Fwindow_end (window
, Qt
);
9366 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9367 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9368 if (this_scroll_margin
)
9370 start_display (&it
, w
, scroll_margin_pos
);
9371 move_it_vertically (&it
, - this_scroll_margin
);
9372 scroll_margin_pos
= it
.current
.pos
;
9375 if (PT
>= CHARPOS (scroll_margin_pos
))
9379 /* Point is in the scroll margin at the bottom of the window, or
9380 below. Compute a new window start that makes point visible. */
9382 /* Compute the distance from the scroll margin to PT.
9383 Give up if the distance is greater than scroll_max. */
9384 start_display (&it
, w
, scroll_margin_pos
);
9386 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9387 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9389 /* With a scroll_margin of 0, scroll_margin_pos is at the window
9390 end, which is one line below the window. The iterator's
9391 current_y will be same as y0 in that case, but we have to
9392 scroll a line to make PT visible. That's the reason why 1 is
9394 dy
= 1 + it
.current_y
- y0
;
9396 if (dy
> scroll_max
)
9399 /* Move the window start down. If scrolling conservatively,
9400 move it just enough down to make point visible. If
9401 scroll_step is set, move it down by scroll_step. */
9402 start_display (&it
, w
, startp
);
9404 if (scroll_conservatively
)
9406 = max (max (dy
, CANON_Y_UNIT (f
)),
9407 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9408 else if (scroll_step
|| temp_scroll_step
)
9409 amount_to_scroll
= scroll_max
;
9412 aggressive
= current_buffer
->scroll_down_aggressively
;
9413 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9414 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9415 if (NUMBERP (aggressive
))
9416 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9419 if (amount_to_scroll
<= 0)
9422 move_it_vertically (&it
, amount_to_scroll
);
9423 startp
= it
.current
.pos
;
9427 /* See if point is inside the scroll margin at the top of the
9429 scroll_margin_pos
= startp
;
9430 if (this_scroll_margin
)
9432 start_display (&it
, w
, startp
);
9433 move_it_vertically (&it
, this_scroll_margin
);
9434 scroll_margin_pos
= it
.current
.pos
;
9437 if (PT
< CHARPOS (scroll_margin_pos
))
9439 /* Point is in the scroll margin at the top of the window or
9440 above what is displayed in the window. */
9443 /* Compute the vertical distance from PT to the scroll
9444 margin position. Give up if distance is greater than
9446 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9447 start_display (&it
, w
, pos
);
9449 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9450 it
.last_visible_y
, -1,
9451 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9452 dy
= it
.current_y
- y0
;
9453 if (dy
> scroll_max
)
9456 /* Compute new window start. */
9457 start_display (&it
, w
, startp
);
9459 if (scroll_conservatively
)
9461 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9462 else if (scroll_step
|| temp_scroll_step
)
9463 amount_to_scroll
= scroll_max
;
9466 aggressive
= current_buffer
->scroll_up_aggressively
;
9467 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9468 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9469 if (NUMBERP (aggressive
))
9470 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9473 if (amount_to_scroll
<= 0)
9476 move_it_vertically (&it
, - amount_to_scroll
);
9477 startp
= it
.current
.pos
;
9481 /* Run window scroll functions. */
9482 startp
= run_window_scroll_functions (window
, startp
);
9484 /* Display the window. Give up if new fonts are loaded, or if point
9486 if (!try_window (window
, startp
))
9488 else if (w
->cursor
.vpos
< 0)
9490 clear_glyph_matrix (w
->desired_matrix
);
9495 /* Maybe forget recorded base line for line number display. */
9496 if (!just_this_one_p
9497 || current_buffer
->clip_changed
9498 || BEG_UNCHANGED
< CHARPOS (startp
))
9499 w
->base_line_number
= Qnil
;
9501 /* If cursor ends up on a partially visible line, shift display
9502 lines up or down. */
9503 make_cursor_line_fully_visible (w
);
9511 /* Compute a suitable window start for window W if display of W starts
9512 on a continuation line. Value is non-zero if a new window start
9515 The new window start will be computed, based on W's width, starting
9516 from the start of the continued line. It is the start of the
9517 screen line with the minimum distance from the old start W->start. */
9520 compute_window_start_on_continuation_line (w
)
9523 struct text_pos pos
, start_pos
;
9524 int window_start_changed_p
= 0;
9526 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9528 /* If window start is on a continuation line... Window start may be
9529 < BEGV in case there's invisible text at the start of the
9530 buffer (M-x rmail, for example). */
9531 if (CHARPOS (start_pos
) > BEGV
9532 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9535 struct glyph_row
*row
;
9537 /* Handle the case that the window start is out of range. */
9538 if (CHARPOS (start_pos
) < BEGV
)
9539 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9540 else if (CHARPOS (start_pos
) > ZV
)
9541 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9543 /* Find the start of the continued line. This should be fast
9544 because scan_buffer is fast (newline cache). */
9545 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9546 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9547 row
, DEFAULT_FACE_ID
);
9548 reseat_at_previous_visible_line_start (&it
);
9550 /* If the line start is "too far" away from the window start,
9551 say it takes too much time to compute a new window start. */
9552 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9553 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9555 int min_distance
, distance
;
9557 /* Move forward by display lines to find the new window
9558 start. If window width was enlarged, the new start can
9559 be expected to be > the old start. If window width was
9560 decreased, the new window start will be < the old start.
9561 So, we're looking for the display line start with the
9562 minimum distance from the old window start. */
9563 pos
= it
.current
.pos
;
9564 min_distance
= INFINITY
;
9565 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9566 distance
< min_distance
)
9568 min_distance
= distance
;
9569 pos
= it
.current
.pos
;
9570 move_it_by_lines (&it
, 1, 0);
9573 /* Set the window start there. */
9574 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9575 window_start_changed_p
= 1;
9579 return window_start_changed_p
;
9583 /* Try cursor movement in case text has not changes in window WINDOW,
9584 with window start STARTP. Value is
9588 0 if this method cannot be used
9590 -1 if we know we have to scroll the display. *SCROLL_STEP is
9591 set to 1, under certain circumstances, if we want to scroll as
9592 if scroll-step were set to 1. See the code. */
9595 try_cursor_movement (window
, startp
, scroll_step
)
9597 struct text_pos startp
;
9600 struct window
*w
= XWINDOW (window
);
9601 struct frame
*f
= XFRAME (w
->frame
);
9604 /* Handle case where text has not changed, only point, and it has
9605 not moved off the frame. */
9606 if (/* Point may be in this window. */
9607 PT
>= CHARPOS (startp
)
9608 /* Selective display hasn't changed. */
9609 && !current_buffer
->clip_changed
9610 /* Function force-mode-line-update is used to force a thorough
9611 redisplay. It sets either windows_or_buffers_changed or
9612 update_mode_lines. So don't take a shortcut here for these
9614 && !update_mode_lines
9615 && !windows_or_buffers_changed
9616 /* Can't use this case if highlighting a region. When a
9617 region exists, cursor movement has to do more than just
9619 && !(!NILP (Vtransient_mark_mode
)
9620 && !NILP (current_buffer
->mark_active
))
9621 && NILP (w
->region_showing
)
9622 && NILP (Vshow_trailing_whitespace
)
9623 /* Right after splitting windows, last_point may be nil. */
9624 && INTEGERP (w
->last_point
)
9625 /* This code is not used for mini-buffer for the sake of the case
9626 of redisplaying to replace an echo area message; since in
9627 that case the mini-buffer contents per se are usually
9628 unchanged. This code is of no real use in the mini-buffer
9629 since the handling of this_line_start_pos, etc., in redisplay
9630 handles the same cases. */
9631 && !EQ (window
, minibuf_window
)
9632 /* When splitting windows or for new windows, it happens that
9633 redisplay is called with a nil window_end_vpos or one being
9634 larger than the window. This should really be fixed in
9635 window.c. I don't have this on my list, now, so we do
9636 approximately the same as the old redisplay code. --gerd. */
9637 && INTEGERP (w
->window_end_vpos
)
9638 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9639 && (FRAME_WINDOW_P (f
)
9640 || !MARKERP (Voverlay_arrow_position
)
9641 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9643 int this_scroll_margin
;
9644 struct glyph_row
*row
= NULL
;
9647 debug_method_add (w
, "cursor movement");
9650 /* Scroll if point within this distance from the top or bottom
9651 of the window. This is a pixel value. */
9652 this_scroll_margin
= max (0, scroll_margin
);
9653 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9654 this_scroll_margin
*= CANON_Y_UNIT (f
);
9656 /* Start with the row the cursor was displayed during the last
9657 not paused redisplay. Give up if that row is not valid. */
9658 if (w
->last_cursor
.vpos
< 0
9659 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9663 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9664 if (row
->mode_line_p
)
9666 if (!row
->enabled_p
)
9673 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9675 if (PT
> XFASTINT (w
->last_point
))
9677 /* Point has moved forward. */
9678 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9679 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9681 xassert (row
->enabled_p
);
9685 /* The end position of a row equals the start position
9686 of the next row. If PT is there, we would rather
9687 display it in the next line. */
9688 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9689 && MATRIX_ROW_END_CHARPOS (row
) == PT
9690 && !cursor_row_p (w
, row
))
9693 /* If within the scroll margin, scroll. Note that
9694 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9695 the next line would be drawn, and that
9696 this_scroll_margin can be zero. */
9697 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9698 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9699 /* Line is completely visible last line in window
9700 and PT is to be set in the next line. */
9701 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9702 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9703 && !row
->ends_at_zv_p
9704 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9707 else if (PT
< XFASTINT (w
->last_point
))
9709 /* Cursor has to be moved backward. Note that PT >=
9710 CHARPOS (startp) because of the outer
9712 while (!row
->mode_line_p
9713 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9714 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9715 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9716 && (row
->y
> this_scroll_margin
9717 || CHARPOS (startp
) == BEGV
))
9719 xassert (row
->enabled_p
);
9723 /* Consider the following case: Window starts at BEGV,
9724 there is invisible, intangible text at BEGV, so that
9725 display starts at some point START > BEGV. It can
9726 happen that we are called with PT somewhere between
9727 BEGV and START. Try to handle that case. */
9728 if (row
< w
->current_matrix
->rows
9729 || row
->mode_line_p
)
9731 row
= w
->current_matrix
->rows
;
9732 if (row
->mode_line_p
)
9736 /* Due to newlines in overlay strings, we may have to
9737 skip forward over overlay strings. */
9738 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9739 && MATRIX_ROW_END_CHARPOS (row
) == PT
9740 && !cursor_row_p (w
, row
))
9743 /* If within the scroll margin, scroll. */
9744 if (row
->y
< this_scroll_margin
9745 && CHARPOS (startp
) != BEGV
)
9749 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9750 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9752 /* if PT is not in the glyph row, give up. */
9755 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9757 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9758 && !row
->ends_at_zv_p
9759 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9761 else if (row
->height
> window_box_height (w
))
9763 /* If we end up in a partially visible line, let's
9764 make it fully visible, except when it's taller
9765 than the window, in which case we can't do much
9772 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9773 try_window (window
, startp
);
9774 make_cursor_line_fully_visible (w
);
9782 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9792 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9793 selected_window is redisplayed. */
9796 redisplay_window (window
, just_this_one_p
)
9798 int just_this_one_p
;
9800 struct window
*w
= XWINDOW (window
);
9801 struct frame
*f
= XFRAME (w
->frame
);
9802 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9803 struct buffer
*old
= current_buffer
;
9804 struct text_pos lpoint
, opoint
, startp
;
9805 int update_mode_line
;
9808 /* Record it now because it's overwritten. */
9809 int current_matrix_up_to_date_p
= 0;
9810 int temp_scroll_step
= 0;
9811 int count
= BINDING_STACK_SIZE ();
9814 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9817 /* W must be a leaf window here. */
9818 xassert (!NILP (w
->buffer
));
9820 *w
->desired_matrix
->method
= 0;
9823 specbind (Qinhibit_point_motion_hooks
, Qt
);
9825 reconsider_clip_changes (w
, buffer
);
9827 /* Has the mode line to be updated? */
9828 update_mode_line
= (!NILP (w
->update_mode_line
)
9829 || update_mode_lines
9830 || buffer
->clip_changed
);
9832 if (MINI_WINDOW_P (w
))
9834 if (w
== XWINDOW (echo_area_window
)
9835 && !NILP (echo_area_buffer
[0]))
9837 if (update_mode_line
)
9838 /* We may have to update a tty frame's menu bar or a
9839 tool-bar. Example `M-x C-h C-h C-g'. */
9840 goto finish_menu_bars
;
9842 /* We've already displayed the echo area glyphs in this window. */
9843 goto finish_scroll_bars
;
9845 else if (w
!= XWINDOW (minibuf_window
))
9847 /* W is a mini-buffer window, but it's not the currently
9848 active one, so clear it. */
9849 int yb
= window_text_bottom_y (w
);
9850 struct glyph_row
*row
;
9853 for (y
= 0, row
= w
->desired_matrix
->rows
;
9855 y
+= row
->height
, ++row
)
9856 blank_row (w
, row
, y
);
9857 goto finish_scroll_bars
;
9860 clear_glyph_matrix (w
->desired_matrix
);
9863 /* Otherwise set up data on this window; select its buffer and point
9865 /* Really select the buffer, for the sake of buffer-local
9867 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9868 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9870 current_matrix_up_to_date_p
9871 = (!NILP (w
->window_end_valid
)
9872 && !current_buffer
->clip_changed
9873 && XFASTINT (w
->last_modified
) >= MODIFF
9874 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9876 /* When windows_or_buffers_changed is non-zero, we can't rely on
9877 the window end being valid, so set it to nil there. */
9878 if (windows_or_buffers_changed
)
9880 /* If window starts on a continuation line, maybe adjust the
9881 window start in case the window's width changed. */
9882 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9883 compute_window_start_on_continuation_line (w
);
9885 w
->window_end_valid
= Qnil
;
9888 /* Some sanity checks. */
9889 CHECK_WINDOW_END (w
);
9890 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9892 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9895 /* If %c is in mode line, update it if needed. */
9896 if (!NILP (w
->column_number_displayed
)
9897 /* This alternative quickly identifies a common case
9898 where no change is needed. */
9899 && !(PT
== XFASTINT (w
->last_point
)
9900 && XFASTINT (w
->last_modified
) >= MODIFF
9901 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9902 && XFASTINT (w
->column_number_displayed
) != current_column ())
9903 update_mode_line
= 1;
9905 /* Count number of windows showing the selected buffer. An indirect
9906 buffer counts as its base buffer. */
9907 if (!just_this_one_p
)
9909 struct buffer
*current_base
, *window_base
;
9910 current_base
= current_buffer
;
9911 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9912 if (current_base
->base_buffer
)
9913 current_base
= current_base
->base_buffer
;
9914 if (window_base
->base_buffer
)
9915 window_base
= window_base
->base_buffer
;
9916 if (current_base
== window_base
)
9920 /* Point refers normally to the selected window. For any other
9921 window, set up appropriate value. */
9922 if (!EQ (window
, selected_window
))
9924 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9925 int new_pt_byte
= marker_byte_position (w
->pointm
);
9929 new_pt_byte
= BEGV_BYTE
;
9930 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9932 else if (new_pt
> (ZV
- 1))
9935 new_pt_byte
= ZV_BYTE
;
9936 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9939 /* We don't use SET_PT so that the point-motion hooks don't run. */
9940 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9943 /* If any of the character widths specified in the display table
9944 have changed, invalidate the width run cache. It's true that
9945 this may be a bit late to catch such changes, but the rest of
9946 redisplay goes (non-fatally) haywire when the display table is
9947 changed, so why should we worry about doing any better? */
9948 if (current_buffer
->width_run_cache
)
9950 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9952 if (! disptab_matches_widthtab (disptab
,
9953 XVECTOR (current_buffer
->width_table
)))
9955 invalidate_region_cache (current_buffer
,
9956 current_buffer
->width_run_cache
,
9958 recompute_width_table (current_buffer
, disptab
);
9962 /* If window-start is screwed up, choose a new one. */
9963 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9966 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9968 /* If someone specified a new starting point but did not insist,
9969 check whether it can be used. */
9970 if (!NILP (w
->optional_new_start
)
9971 && CHARPOS (startp
) >= BEGV
9972 && CHARPOS (startp
) <= ZV
)
9974 w
->optional_new_start
= Qnil
;
9975 start_display (&it
, w
, startp
);
9976 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9977 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9978 if (IT_CHARPOS (it
) == PT
)
9979 w
->force_start
= Qt
;
9982 /* Handle case where place to start displaying has been specified,
9983 unless the specified location is outside the accessible range. */
9984 if (!NILP (w
->force_start
)
9985 || w
->frozen_window_start_p
)
9987 w
->force_start
= Qnil
;
9989 w
->window_end_valid
= Qnil
;
9991 /* Forget any recorded base line for line number display. */
9992 if (!current_matrix_up_to_date_p
9993 || current_buffer
->clip_changed
)
9994 w
->base_line_number
= Qnil
;
9996 /* Redisplay the mode line. Select the buffer properly for that.
9997 Also, run the hook window-scroll-functions
9998 because we have scrolled. */
9999 /* Note, we do this after clearing force_start because
10000 if there's an error, it is better to forget about force_start
10001 than to get into an infinite loop calling the hook functions
10002 and having them get more errors. */
10003 if (!update_mode_line
10004 || ! NILP (Vwindow_scroll_functions
))
10006 update_mode_line
= 1;
10007 w
->update_mode_line
= Qt
;
10008 startp
= run_window_scroll_functions (window
, startp
);
10011 w
->last_modified
= make_number (0);
10012 w
->last_overlay_modified
= make_number (0);
10013 if (CHARPOS (startp
) < BEGV
)
10014 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10015 else if (CHARPOS (startp
) > ZV
)
10016 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10018 /* Redisplay, then check if cursor has been set during the
10019 redisplay. Give up if new fonts were loaded. */
10020 if (!try_window (window
, startp
))
10022 w
->force_start
= Qt
;
10023 clear_glyph_matrix (w
->desired_matrix
);
10024 goto finish_scroll_bars
;
10027 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10029 /* If point does not appear, try to move point so it does
10030 appear. The desired matrix has been built above, so we
10031 can use it here. */
10033 struct glyph_row
*row
;
10035 window_height
= window_box_height (w
) / 2;
10036 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10037 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10040 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10041 MATRIX_ROW_START_BYTEPOS (row
));
10043 if (w
!= XWINDOW (selected_window
))
10044 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10045 else if (current_buffer
== old
)
10046 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10048 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10050 /* If we are highlighting the region, then we just changed
10051 the region, so redisplay to show it. */
10052 if (!NILP (Vtransient_mark_mode
)
10053 && !NILP (current_buffer
->mark_active
))
10055 clear_glyph_matrix (w
->desired_matrix
);
10056 if (!try_window (window
, startp
))
10057 goto finish_scroll_bars
;
10061 make_cursor_line_fully_visible (w
);
10063 debug_method_add (w
, "forced window start");
10068 /* Handle case where text has not changed, only point, and it has
10069 not moved off the frame. */
10070 if (current_matrix_up_to_date_p
10071 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10075 goto try_to_scroll
;
10079 /* If current starting point was originally the beginning of a line
10080 but no longer is, find a new starting point. */
10081 else if (!NILP (w
->start_at_line_beg
)
10082 && !(CHARPOS (startp
) <= BEGV
10083 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10086 debug_method_add (w
, "recenter 1");
10091 /* Try scrolling with try_window_id. Value is > 0 if update has
10092 been done, it is -1 if we know that the same window start will
10093 not work. It is 0 if unsuccessful for some other reason. */
10094 else if ((tem
= try_window_id (w
)) != 0)
10097 debug_method_add (w
, "try_window_id %d", tem
);
10100 if (fonts_changed_p
)
10101 goto finish_scroll_bars
;
10105 /* Otherwise try_window_id has returned -1 which means that we
10106 don't want the alternative below this comment to execute. */
10108 else if (CHARPOS (startp
) >= BEGV
10109 && CHARPOS (startp
) <= ZV
10110 && PT
>= CHARPOS (startp
)
10111 && (CHARPOS (startp
) < ZV
10112 /* Avoid starting at end of buffer. */
10113 || CHARPOS (startp
) == BEGV
10114 || (XFASTINT (w
->last_modified
) >= MODIFF
10115 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10118 debug_method_add (w
, "same window start");
10121 /* Try to redisplay starting at same place as before.
10122 If point has not moved off frame, accept the results. */
10123 if (!current_matrix_up_to_date_p
10124 /* Don't use try_window_reusing_current_matrix in this case
10125 because a window scroll function can have changed the
10127 || !NILP (Vwindow_scroll_functions
)
10128 || MINI_WINDOW_P (w
)
10129 || !try_window_reusing_current_matrix (w
))
10131 IF_DEBUG (debug_method_add (w
, "1"));
10132 try_window (window
, startp
);
10135 if (fonts_changed_p
)
10136 goto finish_scroll_bars
;
10138 if (w
->cursor
.vpos
>= 0)
10140 if (!just_this_one_p
10141 || current_buffer
->clip_changed
10142 || BEG_UNCHANGED
< CHARPOS (startp
))
10143 /* Forget any recorded base line for line number display. */
10144 w
->base_line_number
= Qnil
;
10146 make_cursor_line_fully_visible (w
);
10150 clear_glyph_matrix (w
->desired_matrix
);
10155 w
->last_modified
= make_number (0);
10156 w
->last_overlay_modified
= make_number (0);
10158 /* Redisplay the mode line. Select the buffer properly for that. */
10159 if (!update_mode_line
)
10161 update_mode_line
= 1;
10162 w
->update_mode_line
= Qt
;
10165 /* Try to scroll by specified few lines. */
10166 if ((scroll_conservatively
10168 || temp_scroll_step
10169 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10170 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10171 && !current_buffer
->clip_changed
10172 && CHARPOS (startp
) >= BEGV
10173 && CHARPOS (startp
) <= ZV
)
10175 /* The function returns -1 if new fonts were loaded, 1 if
10176 successful, 0 if not successful. */
10177 int rc
= try_scrolling (window
, just_this_one_p
,
10178 scroll_conservatively
,
10184 goto finish_scroll_bars
;
10187 /* Finally, just choose place to start which centers point */
10192 debug_method_add (w
, "recenter");
10195 /* w->vscroll = 0; */
10197 /* Forget any previously recorded base line for line number display. */
10198 if (!current_matrix_up_to_date_p
10199 || current_buffer
->clip_changed
)
10200 w
->base_line_number
= Qnil
;
10202 /* Move backward half the height of the window. */
10203 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10204 it
.current_y
= it
.last_visible_y
;
10205 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10206 xassert (IT_CHARPOS (it
) >= BEGV
);
10208 /* The function move_it_vertically_backward may move over more
10209 than the specified y-distance. If it->w is small, e.g. a
10210 mini-buffer window, we may end up in front of the window's
10211 display area. Start displaying at the start of the line
10212 containing PT in this case. */
10213 if (it
.current_y
<= 0)
10215 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10216 move_it_vertically (&it
, 0);
10217 xassert (IT_CHARPOS (it
) <= PT
);
10221 it
.current_x
= it
.hpos
= 0;
10223 /* Set startp here explicitly in case that helps avoid an infinite loop
10224 in case the window-scroll-functions functions get errors. */
10225 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10227 /* Run scroll hooks. */
10228 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10230 /* Redisplay the window. */
10231 if (!current_matrix_up_to_date_p
10232 || windows_or_buffers_changed
10233 /* Don't use try_window_reusing_current_matrix in this case
10234 because it can have changed the buffer. */
10235 || !NILP (Vwindow_scroll_functions
)
10236 || !just_this_one_p
10237 || MINI_WINDOW_P (w
)
10238 || !try_window_reusing_current_matrix (w
))
10239 try_window (window
, startp
);
10241 /* If new fonts have been loaded (due to fontsets), give up. We
10242 have to start a new redisplay since we need to re-adjust glyph
10244 if (fonts_changed_p
)
10245 goto finish_scroll_bars
;
10247 /* If cursor did not appear assume that the middle of the window is
10248 in the first line of the window. Do it again with the next line.
10249 (Imagine a window of height 100, displaying two lines of height
10250 60. Moving back 50 from it->last_visible_y will end in the first
10252 if (w
->cursor
.vpos
< 0)
10254 if (!NILP (w
->window_end_valid
)
10255 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10257 clear_glyph_matrix (w
->desired_matrix
);
10258 move_it_by_lines (&it
, 1, 0);
10259 try_window (window
, it
.current
.pos
);
10261 else if (PT
< IT_CHARPOS (it
))
10263 clear_glyph_matrix (w
->desired_matrix
);
10264 move_it_by_lines (&it
, -1, 0);
10265 try_window (window
, it
.current
.pos
);
10269 /* Not much we can do about it. */
10273 /* Consider the following case: Window starts at BEGV, there is
10274 invisible, intangible text at BEGV, so that display starts at
10275 some point START > BEGV. It can happen that we are called with
10276 PT somewhere between BEGV and START. Try to handle that case. */
10277 if (w
->cursor
.vpos
< 0)
10279 struct glyph_row
*row
= w
->current_matrix
->rows
;
10280 if (row
->mode_line_p
)
10282 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10285 make_cursor_line_fully_visible (w
);
10289 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10290 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10291 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10294 /* Display the mode line, if we must. */
10295 if ((update_mode_line
10296 /* If window not full width, must redo its mode line
10297 if (a) the window to its side is being redone and
10298 (b) we do a frame-based redisplay. This is a consequence
10299 of how inverted lines are drawn in frame-based redisplay. */
10300 || (!just_this_one_p
10301 && !FRAME_WINDOW_P (f
)
10302 && !WINDOW_FULL_WIDTH_P (w
))
10303 /* Line number to display. */
10304 || INTEGERP (w
->base_line_pos
)
10305 /* Column number is displayed and different from the one displayed. */
10306 || (!NILP (w
->column_number_displayed
)
10307 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10308 /* This means that the window has a mode line. */
10309 && (WINDOW_WANTS_MODELINE_P (w
)
10310 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10312 Lisp_Object old_selected_frame
;
10314 old_selected_frame
= selected_frame
;
10316 XSETFRAME (selected_frame
, f
);
10317 display_mode_lines (w
);
10318 selected_frame
= old_selected_frame
;
10320 /* If mode line height has changed, arrange for a thorough
10321 immediate redisplay using the correct mode line height. */
10322 if (WINDOW_WANTS_MODELINE_P (w
)
10323 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10325 fonts_changed_p
= 1;
10326 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10327 = DESIRED_MODE_LINE_HEIGHT (w
);
10330 /* If top line height has changed, arrange for a thorough
10331 immediate redisplay using the correct mode line height. */
10332 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10333 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10335 fonts_changed_p
= 1;
10336 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10337 = DESIRED_HEADER_LINE_HEIGHT (w
);
10340 if (fonts_changed_p
)
10341 goto finish_scroll_bars
;
10344 if (!line_number_displayed
10345 && !BUFFERP (w
->base_line_pos
))
10347 w
->base_line_pos
= Qnil
;
10348 w
->base_line_number
= Qnil
;
10353 /* When we reach a frame's selected window, redo the frame's menu bar. */
10354 if (update_mode_line
10355 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10357 int redisplay_menu_p
= 0;
10359 if (FRAME_WINDOW_P (f
))
10361 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10362 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10364 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10368 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10370 if (redisplay_menu_p
)
10371 display_menu_bar (w
);
10373 #ifdef HAVE_WINDOW_SYSTEM
10374 if (WINDOWP (f
->tool_bar_window
)
10375 && (FRAME_TOOL_BAR_LINES (f
) > 0
10376 || auto_resize_tool_bars_p
))
10377 redisplay_tool_bar (f
);
10381 finish_scroll_bars
:
10383 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10385 int start
, end
, whole
;
10387 /* Calculate the start and end positions for the current window.
10388 At some point, it would be nice to choose between scrollbars
10389 which reflect the whole buffer size, with special markers
10390 indicating narrowing, and scrollbars which reflect only the
10393 Note that mini-buffers sometimes aren't displaying any text. */
10394 if (!MINI_WINDOW_P (w
)
10395 || (w
== XWINDOW (minibuf_window
)
10396 && NILP (echo_area_buffer
[0])))
10399 start
= marker_position (w
->start
) - BEGV
;
10400 /* I don't think this is guaranteed to be right. For the
10401 moment, we'll pretend it is. */
10402 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10406 if (whole
< (end
- start
))
10407 whole
= end
- start
;
10410 start
= end
= whole
= 0;
10412 /* Indicate what this scroll bar ought to be displaying now. */
10413 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10415 /* Note that we actually used the scroll bar attached to this
10416 window, so it shouldn't be deleted at the end of redisplay. */
10417 redeem_scroll_bar_hook (w
);
10420 /* Restore current_buffer and value of point in it. */
10421 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10422 set_buffer_internal_1 (old
);
10423 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10425 unbind_to (count
, Qnil
);
10429 /* Build the complete desired matrix of WINDOW with a window start
10430 buffer position POS. Value is non-zero if successful. It is zero
10431 if fonts were loaded during redisplay which makes re-adjusting
10432 glyph matrices necessary. */
10435 try_window (window
, pos
)
10436 Lisp_Object window
;
10437 struct text_pos pos
;
10439 struct window
*w
= XWINDOW (window
);
10441 struct glyph_row
*last_text_row
= NULL
;
10443 /* Make POS the new window start. */
10444 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10446 /* Mark cursor position as unknown. No overlay arrow seen. */
10447 w
->cursor
.vpos
= -1;
10448 overlay_arrow_seen
= 0;
10450 /* Initialize iterator and info to start at POS. */
10451 start_display (&it
, w
, pos
);
10453 /* Display all lines of W. */
10454 while (it
.current_y
< it
.last_visible_y
)
10456 if (display_line (&it
))
10457 last_text_row
= it
.glyph_row
- 1;
10458 if (fonts_changed_p
)
10462 /* If bottom moved off end of frame, change mode line percentage. */
10463 if (XFASTINT (w
->window_end_pos
) <= 0
10464 && Z
!= IT_CHARPOS (it
))
10465 w
->update_mode_line
= Qt
;
10467 /* Set window_end_pos to the offset of the last character displayed
10468 on the window from the end of current_buffer. Set
10469 window_end_vpos to its row number. */
10472 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10473 w
->window_end_bytepos
10474 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10476 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10478 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10479 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10480 ->displays_text_p
);
10484 w
->window_end_bytepos
= 0;
10485 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10488 /* But that is not valid info until redisplay finishes. */
10489 w
->window_end_valid
= Qnil
;
10495 /************************************************************************
10496 Window redisplay reusing current matrix when buffer has not changed
10497 ************************************************************************/
10499 /* Try redisplay of window W showing an unchanged buffer with a
10500 different window start than the last time it was displayed by
10501 reusing its current matrix. Value is non-zero if successful.
10502 W->start is the new window start. */
10505 try_window_reusing_current_matrix (w
)
10508 struct frame
*f
= XFRAME (w
->frame
);
10509 struct glyph_row
*row
, *bottom_row
;
10512 struct text_pos start
, new_start
;
10513 int nrows_scrolled
, i
;
10514 struct glyph_row
*last_text_row
;
10515 struct glyph_row
*last_reused_text_row
;
10516 struct glyph_row
*start_row
;
10517 int start_vpos
, min_y
, max_y
;
10519 if (/* This function doesn't handle terminal frames. */
10520 !FRAME_WINDOW_P (f
)
10521 /* Don't try to reuse the display if windows have been split
10523 || windows_or_buffers_changed
)
10526 /* Can't do this if region may have changed. */
10527 if ((!NILP (Vtransient_mark_mode
)
10528 && !NILP (current_buffer
->mark_active
))
10529 || !NILP (w
->region_showing
)
10530 || !NILP (Vshow_trailing_whitespace
))
10533 /* If top-line visibility has changed, give up. */
10534 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10535 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10538 /* Give up if old or new display is scrolled vertically. We could
10539 make this function handle this, but right now it doesn't. */
10540 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10541 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10544 /* The variable new_start now holds the new window start. The old
10545 start `start' can be determined from the current matrix. */
10546 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10547 start
= start_row
->start
.pos
;
10548 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10550 /* Clear the desired matrix for the display below. */
10551 clear_glyph_matrix (w
->desired_matrix
);
10553 if (CHARPOS (new_start
) <= CHARPOS (start
))
10557 /* Don't use this method if the display starts with an ellipsis
10558 displayed for invisible text. It's not easy to handle that case
10559 below, and it's certainly not worth the effort since this is
10560 not a frequent case. */
10561 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10564 IF_DEBUG (debug_method_add (w
, "twu1"));
10566 /* Display up to a row that can be reused. The variable
10567 last_text_row is set to the last row displayed that displays
10568 text. Note that it.vpos == 0 if or if not there is a
10569 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10570 start_display (&it
, w
, new_start
);
10571 first_row_y
= it
.current_y
;
10572 w
->cursor
.vpos
= -1;
10573 last_text_row
= last_reused_text_row
= NULL
;
10575 while (it
.current_y
< it
.last_visible_y
10576 && IT_CHARPOS (it
) < CHARPOS (start
)
10577 && !fonts_changed_p
)
10578 if (display_line (&it
))
10579 last_text_row
= it
.glyph_row
- 1;
10581 /* A value of current_y < last_visible_y means that we stopped
10582 at the previous window start, which in turn means that we
10583 have at least one reusable row. */
10584 if (it
.current_y
< it
.last_visible_y
)
10586 /* IT.vpos always starts from 0; it counts text lines. */
10587 nrows_scrolled
= it
.vpos
;
10589 /* Find PT if not already found in the lines displayed. */
10590 if (w
->cursor
.vpos
< 0)
10592 int dy
= it
.current_y
- first_row_y
;
10594 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10595 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10597 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
10598 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10600 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10601 dy
, nrows_scrolled
);
10605 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10611 /* Give up if point was not found. This shouldn't
10612 happen often; not more often than with try_window
10614 if (w
->cursor
.vpos
< 0)
10616 clear_glyph_matrix (w
->desired_matrix
);
10621 /* Scroll the display. Do it before the current matrix is
10622 changed. The problem here is that update has not yet
10623 run, i.e. part of the current matrix is not up to date.
10624 scroll_run_hook will clear the cursor, and use the
10625 current matrix to get the height of the row the cursor is
10627 run
.current_y
= first_row_y
;
10628 run
.desired_y
= it
.current_y
;
10629 run
.height
= it
.last_visible_y
- it
.current_y
;
10631 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10634 rif
->update_window_begin_hook (w
);
10635 rif
->clear_mouse_face (w
);
10636 rif
->scroll_run_hook (w
, &run
);
10637 rif
->update_window_end_hook (w
, 0, 0);
10641 /* Shift current matrix down by nrows_scrolled lines. */
10642 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10643 rotate_matrix (w
->current_matrix
,
10645 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10648 /* Disable lines that must be updated. */
10649 for (i
= 0; i
< it
.vpos
; ++i
)
10650 (start_row
+ i
)->enabled_p
= 0;
10652 /* Re-compute Y positions. */
10653 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10654 max_y
= it
.last_visible_y
;
10655 for (row
= start_row
+ nrows_scrolled
;
10659 row
->y
= it
.current_y
;
10660 row
->visible_height
= row
->height
;
10662 if (row
->y
< min_y
)
10663 row
->visible_height
-= min_y
- row
->y
;
10664 if (row
->y
+ row
->height
> max_y
)
10665 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10667 it
.current_y
+= row
->height
;
10669 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10670 last_reused_text_row
= row
;
10671 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10675 /* Disable lines in the current matrix which are now
10676 below the window. */
10677 for (++row
; row
< bottom_row
; ++row
)
10678 row
->enabled_p
= 0;
10681 /* Update window_end_pos etc.; last_reused_text_row is the last
10682 reused row from the current matrix containing text, if any.
10683 The value of last_text_row is the last displayed line
10684 containing text. */
10685 if (last_reused_text_row
)
10687 w
->window_end_bytepos
10688 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10690 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10692 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10693 w
->current_matrix
));
10695 else if (last_text_row
)
10697 w
->window_end_bytepos
10698 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10700 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10702 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10706 /* This window must be completely empty. */
10707 w
->window_end_bytepos
= 0;
10708 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10710 w
->window_end_valid
= Qnil
;
10712 /* Update hint: don't try scrolling again in update_window. */
10713 w
->desired_matrix
->no_scrolling_p
= 1;
10716 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10720 else if (CHARPOS (new_start
) > CHARPOS (start
))
10722 struct glyph_row
*pt_row
, *row
;
10723 struct glyph_row
*first_reusable_row
;
10724 struct glyph_row
*first_row_to_display
;
10726 int yb
= window_text_bottom_y (w
);
10728 /* Find the row starting at new_start, if there is one. Don't
10729 reuse a partially visible line at the end. */
10730 first_reusable_row
= start_row
;
10731 while (first_reusable_row
->enabled_p
10732 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10733 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10734 < CHARPOS (new_start
)))
10735 ++first_reusable_row
;
10737 /* Give up if there is no row to reuse. */
10738 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10739 || !first_reusable_row
->enabled_p
10740 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10741 != CHARPOS (new_start
)))
10744 /* We can reuse fully visible rows beginning with
10745 first_reusable_row to the end of the window. Set
10746 first_row_to_display to the first row that cannot be reused.
10747 Set pt_row to the row containing point, if there is any. */
10749 for (first_row_to_display
= first_reusable_row
;
10750 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10751 ++first_row_to_display
)
10753 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10754 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10755 pt_row
= first_row_to_display
;
10758 /* Start displaying at the start of first_row_to_display. */
10759 xassert (first_row_to_display
->y
< yb
);
10760 init_to_row_start (&it
, w
, first_row_to_display
);
10762 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10764 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10766 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10767 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10769 /* Display lines beginning with first_row_to_display in the
10770 desired matrix. Set last_text_row to the last row displayed
10771 that displays text. */
10772 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10773 if (pt_row
== NULL
)
10774 w
->cursor
.vpos
= -1;
10775 last_text_row
= NULL
;
10776 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10777 if (display_line (&it
))
10778 last_text_row
= it
.glyph_row
- 1;
10780 /* Give up If point isn't in a row displayed or reused. */
10781 if (w
->cursor
.vpos
< 0)
10783 clear_glyph_matrix (w
->desired_matrix
);
10787 /* If point is in a reused row, adjust y and vpos of the cursor
10791 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10792 w
->current_matrix
);
10793 w
->cursor
.y
-= first_reusable_row
->y
;
10796 /* Scroll the display. */
10797 run
.current_y
= first_reusable_row
->y
;
10798 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10799 run
.height
= it
.last_visible_y
- run
.current_y
;
10800 dy
= run
.current_y
- run
.desired_y
;
10804 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10806 rif
->update_window_begin_hook (w
);
10807 rif
->clear_mouse_face (w
);
10808 rif
->scroll_run_hook (w
, &run
);
10809 rif
->update_window_end_hook (w
, 0, 0);
10813 /* Adjust Y positions of reused rows. */
10814 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10815 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10816 max_y
= it
.last_visible_y
;
10817 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10820 row
->visible_height
= row
->height
;
10821 if (row
->y
< min_y
)
10822 row
->visible_height
-= min_y
- row
->y
;
10823 if (row
->y
+ row
->height
> max_y
)
10824 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10827 /* Scroll the current matrix. */
10828 xassert (nrows_scrolled
> 0);
10829 rotate_matrix (w
->current_matrix
,
10831 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10834 /* Disable rows not reused. */
10835 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
10836 row
->enabled_p
= 0;
10838 /* Adjust window end. A null value of last_text_row means that
10839 the window end is in reused rows which in turn means that
10840 only its vpos can have changed. */
10843 w
->window_end_bytepos
10844 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10846 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10848 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10853 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10856 w
->window_end_valid
= Qnil
;
10857 w
->desired_matrix
->no_scrolling_p
= 1;
10860 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10870 /************************************************************************
10871 Window redisplay reusing current matrix when buffer has changed
10872 ************************************************************************/
10874 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10875 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10877 static struct glyph_row
*
10878 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10879 struct glyph_row
*));
10882 /* Return the last row in MATRIX displaying text. If row START is
10883 non-null, start searching with that row. IT gives the dimensions
10884 of the display. Value is null if matrix is empty; otherwise it is
10885 a pointer to the row found. */
10887 static struct glyph_row
*
10888 find_last_row_displaying_text (matrix
, it
, start
)
10889 struct glyph_matrix
*matrix
;
10891 struct glyph_row
*start
;
10893 struct glyph_row
*row
, *row_found
;
10895 /* Set row_found to the last row in IT->w's current matrix
10896 displaying text. The loop looks funny but think of partially
10899 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10900 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10902 xassert (row
->enabled_p
);
10904 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10913 /* Return the last row in the current matrix of W that is not affected
10914 by changes at the start of current_buffer that occurred since W's
10915 current matrix was built. Value is null if no such row exists.
10917 BEG_UNCHANGED us the number of characters unchanged at the start of
10918 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
10919 first changed character in current_buffer. Characters at positions <
10920 BEG + BEG_UNCHANGED are at the same buffer positions as they were
10921 when the current matrix was built. */
10923 static struct glyph_row
*
10924 find_last_unchanged_at_beg_row (w
)
10927 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10928 struct glyph_row
*row
;
10929 struct glyph_row
*row_found
= NULL
;
10930 int yb
= window_text_bottom_y (w
);
10932 /* Find the last row displaying unchanged text. */
10933 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10934 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10935 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10937 if (/* If row ends before first_changed_pos, it is unchanged,
10938 except in some case. */
10939 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10940 /* When row ends in ZV and we write at ZV it is not
10942 && !row
->ends_at_zv_p
10943 /* When first_changed_pos is the end of a continued line,
10944 row is not unchanged because it may be no longer
10946 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10947 && row
->continued_p
))
10950 /* Stop if last visible row. */
10951 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10961 /* Find the first glyph row in the current matrix of W that is not
10962 affected by changes at the end of current_buffer since the
10963 time W's current matrix was built.
10965 Return in *DELTA the number of chars by which buffer positions in
10966 unchanged text at the end of current_buffer must be adjusted.
10968 Return in *DELTA_BYTES the corresponding number of bytes.
10970 Value is null if no such row exists, i.e. all rows are affected by
10973 static struct glyph_row
*
10974 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10976 int *delta
, *delta_bytes
;
10978 struct glyph_row
*row
;
10979 struct glyph_row
*row_found
= NULL
;
10981 *delta
= *delta_bytes
= 0;
10983 /* Display must not have been paused, otherwise the current matrix
10984 is not up to date. */
10985 if (NILP (w
->window_end_valid
))
10988 /* A value of window_end_pos >= END_UNCHANGED means that the window
10989 end is in the range of changed text. If so, there is no
10990 unchanged row at the end of W's current matrix. */
10991 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10994 /* Set row to the last row in W's current matrix displaying text. */
10995 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10997 /* If matrix is entirely empty, no unchanged row exists. */
10998 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11000 /* The value of row is the last glyph row in the matrix having a
11001 meaningful buffer position in it. The end position of row
11002 corresponds to window_end_pos. This allows us to translate
11003 buffer positions in the current matrix to current buffer
11004 positions for characters not in changed text. */
11005 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11006 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11007 int last_unchanged_pos
, last_unchanged_pos_old
;
11008 struct glyph_row
*first_text_row
11009 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11011 *delta
= Z
- Z_old
;
11012 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11014 /* Set last_unchanged_pos to the buffer position of the last
11015 character in the buffer that has not been changed. Z is the
11016 index + 1 of the last character in current_buffer, i.e. by
11017 subtracting END_UNCHANGED we get the index of the last
11018 unchanged character, and we have to add BEG to get its buffer
11020 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11021 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11023 /* Search backward from ROW for a row displaying a line that
11024 starts at a minimum position >= last_unchanged_pos_old. */
11025 for (; row
> first_text_row
; --row
)
11027 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11030 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11035 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11042 /* Make sure that glyph rows in the current matrix of window W
11043 reference the same glyph memory as corresponding rows in the
11044 frame's frame matrix. This function is called after scrolling W's
11045 current matrix on a terminal frame in try_window_id and
11046 try_window_reusing_current_matrix. */
11049 sync_frame_with_window_matrix_rows (w
)
11052 struct frame
*f
= XFRAME (w
->frame
);
11053 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11055 /* Preconditions: W must be a leaf window and full-width. Its frame
11056 must have a frame matrix. */
11057 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11058 xassert (WINDOW_FULL_WIDTH_P (w
));
11059 xassert (!FRAME_WINDOW_P (f
));
11061 /* If W is a full-width window, glyph pointers in W's current matrix
11062 have, by definition, to be the same as glyph pointers in the
11063 corresponding frame matrix. */
11064 window_row
= w
->current_matrix
->rows
;
11065 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11066 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11067 while (window_row
< window_row_end
)
11071 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11072 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11074 /* Disable frame rows whose corresponding window rows have
11075 been disabled in try_window_id. */
11076 if (!window_row
->enabled_p
)
11077 frame_row
->enabled_p
= 0;
11079 ++window_row
, ++frame_row
;
11084 /* Find the glyph row in window W containing CHARPOS. Consider all
11085 rows between START and END (not inclusive). END null means search
11086 all rows to the end of the display area of W. Value is the row
11087 containing CHARPOS or null. */
11089 static struct glyph_row
*
11090 row_containing_pos (w
, charpos
, start
, end
)
11093 struct glyph_row
*start
, *end
;
11095 struct glyph_row
*row
= start
;
11098 /* If we happen to start on a header-line, skip that. */
11099 if (row
->mode_line_p
)
11102 if ((end
&& row
>= end
) || !row
->enabled_p
)
11105 last_y
= window_text_bottom_y (w
);
11107 while ((end
== NULL
|| row
< end
)
11108 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11109 /* The end position of a row equals the start
11110 position of the next row. If CHARPOS is there, we
11111 would rather display it in the next line, except
11112 when this line ends in ZV. */
11113 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11114 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11115 || !row
->ends_at_zv_p
)))
11116 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11119 /* Give up if CHARPOS not found. */
11120 if ((end
&& row
>= end
)
11121 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11122 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11129 /* Try to redisplay window W by reusing its existing display. W's
11130 current matrix must be up to date when this function is called,
11131 i.e. window_end_valid must not be nil.
11135 1 if display has been updated
11136 0 if otherwise unsuccessful
11137 -1 if redisplay with same window start is known not to succeed
11139 The following steps are performed:
11141 1. Find the last row in the current matrix of W that is not
11142 affected by changes at the start of current_buffer. If no such row
11145 2. Find the first row in W's current matrix that is not affected by
11146 changes at the end of current_buffer. Maybe there is no such row.
11148 3. Display lines beginning with the row + 1 found in step 1 to the
11149 row found in step 2 or, if step 2 didn't find a row, to the end of
11152 4. If cursor is not known to appear on the window, give up.
11154 5. If display stopped at the row found in step 2, scroll the
11155 display and current matrix as needed.
11157 6. Maybe display some lines at the end of W, if we must. This can
11158 happen under various circumstances, like a partially visible line
11159 becoming fully visible, or because newly displayed lines are displayed
11160 in smaller font sizes.
11162 7. Update W's window end information. */
11168 struct frame
*f
= XFRAME (w
->frame
);
11169 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11170 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11171 struct glyph_row
*last_unchanged_at_beg_row
;
11172 struct glyph_row
*first_unchanged_at_end_row
;
11173 struct glyph_row
*row
;
11174 struct glyph_row
*bottom_row
;
11177 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11178 struct text_pos start_pos
;
11180 int first_unchanged_at_end_vpos
= 0;
11181 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11182 struct text_pos start
;
11183 int first_changed_charpos
, last_changed_charpos
;
11185 /* This is handy for debugging. */
11187 #define GIVE_UP(X) \
11189 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11193 #define GIVE_UP(X) return 0
11196 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11198 /* Don't use this for mini-windows because these can show
11199 messages and mini-buffers, and we don't handle that here. */
11200 if (MINI_WINDOW_P (w
))
11203 /* This flag is used to prevent redisplay optimizations. */
11204 if (windows_or_buffers_changed
)
11207 /* Verify that narrowing has not changed. This flag is also set to prevent
11208 redisplay optimizations. It would be nice to further
11209 reduce the number of cases where this prevents try_window_id. */
11210 if (current_buffer
->clip_changed
)
11213 /* Window must either use window-based redisplay or be full width. */
11214 if (!FRAME_WINDOW_P (f
)
11215 && (!line_ins_del_ok
11216 || !WINDOW_FULL_WIDTH_P (w
)))
11219 /* Give up if point is not known NOT to appear in W. */
11220 if (PT
< CHARPOS (start
))
11223 /* Another way to prevent redisplay optimizations. */
11224 if (XFASTINT (w
->last_modified
) == 0)
11227 /* Verify that window is not hscrolled. */
11228 if (XFASTINT (w
->hscroll
) != 0)
11231 /* Verify that display wasn't paused. */
11232 if (NILP (w
->window_end_valid
))
11235 /* Can't use this if highlighting a region because a cursor movement
11236 will do more than just set the cursor. */
11237 if (!NILP (Vtransient_mark_mode
)
11238 && !NILP (current_buffer
->mark_active
))
11241 /* Likewise if highlighting trailing whitespace. */
11242 if (!NILP (Vshow_trailing_whitespace
))
11245 /* Likewise if showing a region. */
11246 if (!NILP (w
->region_showing
))
11249 /* Can use this if overlay arrow position and or string have changed. */
11250 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11251 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11255 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11256 only if buffer has really changed. The reason is that the gap is
11257 initially at Z for freshly visited files. The code below would
11258 set end_unchanged to 0 in that case. */
11259 if (MODIFF
> SAVE_MODIFF
11260 /* This seems to happen sometimes after saving a buffer. */
11261 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11263 if (GPT
- BEG
< BEG_UNCHANGED
)
11264 BEG_UNCHANGED
= GPT
- BEG
;
11265 if (Z
- GPT
< END_UNCHANGED
)
11266 END_UNCHANGED
= Z
- GPT
;
11269 /* The position of the first and last character that has been changed. */
11270 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11271 last_changed_charpos
= Z
- END_UNCHANGED
;
11273 /* If window starts after a line end, and the last change is in
11274 front of that newline, then changes don't affect the display.
11275 This case happens with stealth-fontification. Note that although
11276 the display is unchanged, glyph positions in the matrix have to
11277 be adjusted, of course. */
11278 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11279 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11280 && ((last_changed_charpos
< CHARPOS (start
)
11281 && CHARPOS (start
) == BEGV
)
11282 || (last_changed_charpos
< CHARPOS (start
) - 1
11283 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11285 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11286 struct glyph_row
*r0
;
11288 /* Compute how many chars/bytes have been added to or removed
11289 from the buffer. */
11290 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11291 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11293 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11295 /* Give up if PT is not in the window. Note that it already has
11296 been checked at the start of try_window_id that PT is not in
11297 front of the window start. */
11298 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11301 /* If window start is unchanged, we can reuse the whole matrix
11302 as is, after adjusting glyph positions. No need to compute
11303 the window end again, since its offset from Z hasn't changed. */
11304 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11305 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11306 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11308 /* Adjust positions in the glyph matrix. */
11309 if (delta
|| delta_bytes
)
11311 struct glyph_row
*r1
11312 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11313 increment_matrix_positions (w
->current_matrix
,
11314 MATRIX_ROW_VPOS (r0
, current_matrix
),
11315 MATRIX_ROW_VPOS (r1
, current_matrix
),
11316 delta
, delta_bytes
);
11319 /* Set the cursor. */
11320 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11321 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11326 /* Handle the case that changes are all below what is displayed in
11327 the window, and that PT is in the window. This shortcut cannot
11328 be taken if ZV is visible in the window, and text has been added
11329 there that is visible in the window. */
11330 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11331 /* ZV is not visible in the window, or there are no
11332 changes at ZV, actually. */
11333 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11334 || first_changed_charpos
== last_changed_charpos
))
11336 struct glyph_row
*r0
;
11338 /* Give up if PT is not in the window. Note that it already has
11339 been checked at the start of try_window_id that PT is not in
11340 front of the window start. */
11341 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11344 /* If window start is unchanged, we can reuse the whole matrix
11345 as is, without changing glyph positions since no text has
11346 been added/removed in front of the window end. */
11347 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11348 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11350 /* We have to compute the window end anew since text
11351 can have been added/removed after it. */
11353 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11354 w
->window_end_bytepos
11355 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11357 /* Set the cursor. */
11358 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11359 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11364 /* Give up if window start is in the changed area.
11366 The condition used to read
11368 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11370 but why that was tested escapes me at the moment. */
11371 if (CHARPOS (start
) >= first_changed_charpos
11372 && CHARPOS (start
) <= last_changed_charpos
)
11375 /* Check that window start agrees with the start of the first glyph
11376 row in its current matrix. Check this after we know the window
11377 start is not in changed text, otherwise positions would not be
11379 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11380 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11383 /* Compute the position at which we have to start displaying new
11384 lines. Some of the lines at the top of the window might be
11385 reusable because they are not displaying changed text. Find the
11386 last row in W's current matrix not affected by changes at the
11387 start of current_buffer. Value is null if changes start in the
11388 first line of window. */
11389 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11390 if (last_unchanged_at_beg_row
)
11392 /* Avoid starting to display in the moddle of a character, a TAB
11393 for instance. This is easier than to set up the iterator
11394 exactly, and it's not a frequent case, so the additional
11395 effort wouldn't really pay off. */
11396 while (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11397 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11398 --last_unchanged_at_beg_row
;
11400 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11403 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
11404 start_pos
= it
.current
.pos
;
11406 /* Start displaying new lines in the desired matrix at the same
11407 vpos we would use in the current matrix, i.e. below
11408 last_unchanged_at_beg_row. */
11409 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11411 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11412 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11414 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11418 /* There are no reusable lines at the start of the window.
11419 Start displaying in the first line. */
11420 start_display (&it
, w
, start
);
11421 start_pos
= it
.current
.pos
;
11424 /* Find the first row that is not affected by changes at the end of
11425 the buffer. Value will be null if there is no unchanged row, in
11426 which case we must redisplay to the end of the window. delta
11427 will be set to the value by which buffer positions beginning with
11428 first_unchanged_at_end_row have to be adjusted due to text
11430 first_unchanged_at_end_row
11431 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11432 IF_DEBUG (debug_delta
= delta
);
11433 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11435 /* Set stop_pos to the buffer position up to which we will have to
11436 display new lines. If first_unchanged_at_end_row != NULL, this
11437 is the buffer position of the start of the line displayed in that
11438 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11439 that we don't stop at a buffer position. */
11441 if (first_unchanged_at_end_row
)
11443 xassert (last_unchanged_at_beg_row
== NULL
11444 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11446 /* If this is a continuation line, move forward to the next one
11447 that isn't. Changes in lines above affect this line.
11448 Caution: this may move first_unchanged_at_end_row to a row
11449 not displaying text. */
11450 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11451 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11452 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11453 < it
.last_visible_y
))
11454 ++first_unchanged_at_end_row
;
11456 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11457 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11458 >= it
.last_visible_y
))
11459 first_unchanged_at_end_row
= NULL
;
11462 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11464 first_unchanged_at_end_vpos
11465 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11466 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11469 else if (last_unchanged_at_beg_row
== NULL
)
11475 /* Either there is no unchanged row at the end, or the one we have
11476 now displays text. This is a necessary condition for the window
11477 end pos calculation at the end of this function. */
11478 xassert (first_unchanged_at_end_row
== NULL
11479 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11481 debug_last_unchanged_at_beg_vpos
11482 = (last_unchanged_at_beg_row
11483 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11485 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11487 #endif /* GLYPH_DEBUG != 0 */
11490 /* Display new lines. Set last_text_row to the last new line
11491 displayed which has text on it, i.e. might end up as being the
11492 line where the window_end_vpos is. */
11493 w
->cursor
.vpos
= -1;
11494 last_text_row
= NULL
;
11495 overlay_arrow_seen
= 0;
11496 while (it
.current_y
< it
.last_visible_y
11497 && !fonts_changed_p
11498 && (first_unchanged_at_end_row
== NULL
11499 || IT_CHARPOS (it
) < stop_pos
))
11501 if (display_line (&it
))
11502 last_text_row
= it
.glyph_row
- 1;
11505 if (fonts_changed_p
)
11509 /* Compute differences in buffer positions, y-positions etc. for
11510 lines reused at the bottom of the window. Compute what we can
11512 if (first_unchanged_at_end_row
11513 /* No lines reused because we displayed everything up to the
11514 bottom of the window. */
11515 && it
.current_y
< it
.last_visible_y
)
11518 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11520 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11521 run
.current_y
= first_unchanged_at_end_row
->y
;
11522 run
.desired_y
= run
.current_y
+ dy
;
11523 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11527 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11528 first_unchanged_at_end_row
= NULL
;
11530 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11533 /* Find the cursor if not already found. We have to decide whether
11534 PT will appear on this window (it sometimes doesn't, but this is
11535 not a very frequent case.) This decision has to be made before
11536 the current matrix is altered. A value of cursor.vpos < 0 means
11537 that PT is either in one of the lines beginning at
11538 first_unchanged_at_end_row or below the window. Don't care for
11539 lines that might be displayed later at the window end; as
11540 mentioned, this is not a frequent case. */
11541 if (w
->cursor
.vpos
< 0)
11543 /* Cursor in unchanged rows at the top? */
11544 if (PT
< CHARPOS (start_pos
)
11545 && last_unchanged_at_beg_row
)
11547 row
= row_containing_pos (w
, PT
,
11548 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11549 last_unchanged_at_beg_row
+ 1);
11551 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11554 /* Start from first_unchanged_at_end_row looking for PT. */
11555 else if (first_unchanged_at_end_row
)
11557 row
= row_containing_pos (w
, PT
- delta
,
11558 first_unchanged_at_end_row
, NULL
);
11560 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11561 delta_bytes
, dy
, dvpos
);
11564 /* Give up if cursor was not found. */
11565 if (w
->cursor
.vpos
< 0)
11567 clear_glyph_matrix (w
->desired_matrix
);
11572 /* Don't let the cursor end in the scroll margins. */
11574 int this_scroll_margin
, cursor_height
;
11576 this_scroll_margin
= max (0, scroll_margin
);
11577 this_scroll_margin
= min (this_scroll_margin
,
11578 XFASTINT (w
->height
) / 4);
11579 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11580 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11582 if ((w
->cursor
.y
< this_scroll_margin
11583 && CHARPOS (start
) > BEGV
)
11584 /* Don't take scroll margin into account at the bottom because
11585 old redisplay didn't do it either. */
11586 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11588 w
->cursor
.vpos
= -1;
11589 clear_glyph_matrix (w
->desired_matrix
);
11594 /* Scroll the display. Do it before changing the current matrix so
11595 that xterm.c doesn't get confused about where the cursor glyph is
11597 if (dy
&& run
.height
)
11601 if (FRAME_WINDOW_P (f
))
11603 rif
->update_window_begin_hook (w
);
11604 rif
->clear_mouse_face (w
);
11605 rif
->scroll_run_hook (w
, &run
);
11606 rif
->update_window_end_hook (w
, 0, 0);
11610 /* Terminal frame. In this case, dvpos gives the number of
11611 lines to scroll by; dvpos < 0 means scroll up. */
11612 int first_unchanged_at_end_vpos
11613 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11614 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11615 int end
= (XFASTINT (w
->top
)
11616 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11617 + window_internal_height (w
));
11619 /* Perform the operation on the screen. */
11622 /* Scroll last_unchanged_at_beg_row to the end of the
11623 window down dvpos lines. */
11624 set_terminal_window (end
);
11626 /* On dumb terminals delete dvpos lines at the end
11627 before inserting dvpos empty lines. */
11628 if (!scroll_region_ok
)
11629 ins_del_lines (end
- dvpos
, -dvpos
);
11631 /* Insert dvpos empty lines in front of
11632 last_unchanged_at_beg_row. */
11633 ins_del_lines (from
, dvpos
);
11635 else if (dvpos
< 0)
11637 /* Scroll up last_unchanged_at_beg_vpos to the end of
11638 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11639 set_terminal_window (end
);
11641 /* Delete dvpos lines in front of
11642 last_unchanged_at_beg_vpos. ins_del_lines will set
11643 the cursor to the given vpos and emit |dvpos| delete
11645 ins_del_lines (from
+ dvpos
, dvpos
);
11647 /* On a dumb terminal insert dvpos empty lines at the
11649 if (!scroll_region_ok
)
11650 ins_del_lines (end
+ dvpos
, -dvpos
);
11653 set_terminal_window (0);
11659 /* Shift reused rows of the current matrix to the right position.
11660 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11662 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11663 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11666 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11667 bottom_vpos
, dvpos
);
11668 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11671 else if (dvpos
> 0)
11673 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11674 bottom_vpos
, dvpos
);
11675 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11676 first_unchanged_at_end_vpos
+ dvpos
, 0);
11679 /* For frame-based redisplay, make sure that current frame and window
11680 matrix are in sync with respect to glyph memory. */
11681 if (!FRAME_WINDOW_P (f
))
11682 sync_frame_with_window_matrix_rows (w
);
11684 /* Adjust buffer positions in reused rows. */
11686 increment_matrix_positions (current_matrix
,
11687 first_unchanged_at_end_vpos
+ dvpos
,
11688 bottom_vpos
, delta
, delta_bytes
);
11690 /* Adjust Y positions. */
11692 shift_glyph_matrix (w
, current_matrix
,
11693 first_unchanged_at_end_vpos
+ dvpos
,
11696 if (first_unchanged_at_end_row
)
11697 first_unchanged_at_end_row
+= dvpos
;
11699 /* If scrolling up, there may be some lines to display at the end of
11701 last_text_row_at_end
= NULL
;
11704 /* Set last_row to the glyph row in the current matrix where the
11705 window end line is found. It has been moved up or down in
11706 the matrix by dvpos. */
11707 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11708 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11710 /* If last_row is the window end line, it should display text. */
11711 xassert (last_row
->displays_text_p
);
11713 /* If window end line was partially visible before, begin
11714 displaying at that line. Otherwise begin displaying with the
11715 line following it. */
11716 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11718 init_to_row_start (&it
, w
, last_row
);
11719 it
.vpos
= last_vpos
;
11720 it
.current_y
= last_row
->y
;
11724 init_to_row_end (&it
, w
, last_row
);
11725 it
.vpos
= 1 + last_vpos
;
11726 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11730 /* We may start in a continuation line. If so, we have to get
11731 the right continuation_lines_width and current_x. */
11732 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11733 it
.hpos
= it
.current_x
= 0;
11735 /* Display the rest of the lines at the window end. */
11736 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11737 while (it
.current_y
< it
.last_visible_y
11738 && !fonts_changed_p
)
11740 /* Is it always sure that the display agrees with lines in
11741 the current matrix? I don't think so, so we mark rows
11742 displayed invalid in the current matrix by setting their
11743 enabled_p flag to zero. */
11744 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11745 if (display_line (&it
))
11746 last_text_row_at_end
= it
.glyph_row
- 1;
11750 /* Update window_end_pos and window_end_vpos. */
11751 if (first_unchanged_at_end_row
11752 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11753 && !last_text_row_at_end
)
11755 /* Window end line if one of the preserved rows from the current
11756 matrix. Set row to the last row displaying text in current
11757 matrix starting at first_unchanged_at_end_row, after
11759 xassert (first_unchanged_at_end_row
->displays_text_p
);
11760 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11761 first_unchanged_at_end_row
);
11762 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11764 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11765 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11767 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11768 xassert (w
->window_end_bytepos
>= 0);
11769 IF_DEBUG (debug_method_add (w
, "A"));
11771 else if (last_text_row_at_end
)
11774 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11775 w
->window_end_bytepos
11776 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11778 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11779 xassert (w
->window_end_bytepos
>= 0);
11780 IF_DEBUG (debug_method_add (w
, "B"));
11782 else if (last_text_row
)
11784 /* We have displayed either to the end of the window or at the
11785 end of the window, i.e. the last row with text is to be found
11786 in the desired matrix. */
11788 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11789 w
->window_end_bytepos
11790 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11792 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11793 xassert (w
->window_end_bytepos
>= 0);
11795 else if (first_unchanged_at_end_row
== NULL
11796 && last_text_row
== NULL
11797 && last_text_row_at_end
== NULL
)
11799 /* Displayed to end of window, but no line containing text was
11800 displayed. Lines were deleted at the end of the window. */
11801 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11802 int vpos
= XFASTINT (w
->window_end_vpos
);
11803 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
11804 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
11807 row
== NULL
&& vpos
>= first_vpos
;
11808 --vpos
, --current_row
, --desired_row
)
11810 if (desired_row
->enabled_p
)
11812 if (desired_row
->displays_text_p
)
11815 else if (current_row
->displays_text_p
)
11819 xassert (row
!= NULL
);
11820 w
->window_end_vpos
= make_number (vpos
+ 1);
11821 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11822 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11823 xassert (w
->window_end_bytepos
>= 0);
11824 IF_DEBUG (debug_method_add (w
, "C"));
11829 #if 0 /* This leads to problems, for instance when the cursor is
11830 at ZV, and the cursor line displays no text. */
11831 /* Disable rows below what's displayed in the window. This makes
11832 debugging easier. */
11833 enable_glyph_matrix_rows (current_matrix
,
11834 XFASTINT (w
->window_end_vpos
) + 1,
11838 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11839 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11841 /* Record that display has not been completed. */
11842 w
->window_end_valid
= Qnil
;
11843 w
->desired_matrix
->no_scrolling_p
= 1;
11851 /***********************************************************************
11852 More debugging support
11853 ***********************************************************************/
11857 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11858 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11859 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
11862 /* Dump the contents of glyph matrix MATRIX on stderr.
11864 GLYPHS 0 means don't show glyph contents.
11865 GLYPHS 1 means show glyphs in short form
11866 GLYPHS > 1 means show glyphs in long form. */
11869 dump_glyph_matrix (matrix
, glyphs
)
11870 struct glyph_matrix
*matrix
;
11874 for (i
= 0; i
< matrix
->nrows
; ++i
)
11875 dump_glyph_row (matrix
, i
, glyphs
);
11879 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
11880 the glyph row and area where the glyph comes from. */
11883 dump_glyph (row
, glyph
, area
)
11884 struct glyph_row
*row
;
11885 struct glyph
*glyph
;
11888 if (glyph
->type
== CHAR_GLYPH
)
11891 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11892 glyph
- row
->glyphs
[TEXT_AREA
],
11895 (BUFFERP (glyph
->object
)
11897 : (STRINGP (glyph
->object
)
11900 glyph
->pixel_width
,
11902 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11906 glyph
->left_box_line_p
,
11907 glyph
->right_box_line_p
);
11909 else if (glyph
->type
== STRETCH_GLYPH
)
11912 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11913 glyph
- row
->glyphs
[TEXT_AREA
],
11916 (BUFFERP (glyph
->object
)
11918 : (STRINGP (glyph
->object
)
11921 glyph
->pixel_width
,
11925 glyph
->left_box_line_p
,
11926 glyph
->right_box_line_p
);
11928 else if (glyph
->type
== IMAGE_GLYPH
)
11931 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11932 glyph
- row
->glyphs
[TEXT_AREA
],
11935 (BUFFERP (glyph
->object
)
11937 : (STRINGP (glyph
->object
)
11940 glyph
->pixel_width
,
11944 glyph
->left_box_line_p
,
11945 glyph
->right_box_line_p
);
11950 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11951 GLYPHS 0 means don't show glyph contents.
11952 GLYPHS 1 means show glyphs in short form
11953 GLYPHS > 1 means show glyphs in long form. */
11956 dump_glyph_row (matrix
, vpos
, glyphs
)
11957 struct glyph_matrix
*matrix
;
11960 struct glyph_row
*row
;
11962 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11965 row
= MATRIX_ROW (matrix
, vpos
);
11969 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
11970 fprintf (stderr
, "=======================================================================\n");
11972 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11973 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11974 row
- matrix
->rows
,
11975 MATRIX_ROW_START_CHARPOS (row
),
11976 MATRIX_ROW_END_CHARPOS (row
),
11977 row
->used
[TEXT_AREA
],
11978 row
->contains_overlapping_glyphs_p
,
11981 row
->truncated_on_left_p
,
11982 row
->truncated_on_right_p
,
11983 row
->overlay_arrow_p
,
11985 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11986 row
->displays_text_p
,
11989 row
->ends_in_middle_of_char_p
,
11990 row
->starts_in_middle_of_char_p
,
11996 row
->visible_height
,
11999 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12000 row
->end
.overlay_string_index
,
12001 row
->continuation_lines_width
);
12002 fprintf (stderr
, "%9d %5d\n",
12003 CHARPOS (row
->start
.string_pos
),
12004 CHARPOS (row
->end
.string_pos
));
12005 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12006 row
->end
.dpvec_index
);
12013 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12015 struct glyph
*glyph
= row
->glyphs
[area
];
12016 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12018 /* Glyph for a line end in text. */
12019 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12022 if (glyph
< glyph_end
)
12023 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12025 for (; glyph
< glyph_end
; ++glyph
)
12026 dump_glyph (row
, glyph
, area
);
12029 else if (glyphs
== 1)
12033 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12035 char *s
= (char *) alloca (row
->used
[area
] + 1);
12038 for (i
= 0; i
< row
->used
[area
]; ++i
)
12040 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12041 if (glyph
->type
== CHAR_GLYPH
12042 && glyph
->u
.ch
< 0x80
12043 && glyph
->u
.ch
>= ' ')
12044 s
[i
] = glyph
->u
.ch
;
12050 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12056 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12057 Sdump_glyph_matrix
, 0, 1, "p",
12058 "Dump the current matrix of the selected window to stderr.\n\
12059 Shows contents of glyph row structures. With non-nil\n\
12060 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show\n\
12061 glyphs in short form, otherwise show glyphs in long form.")
12063 Lisp_Object glyphs
;
12065 struct window
*w
= XWINDOW (selected_window
);
12066 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12068 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12069 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12070 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12071 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12072 fprintf (stderr
, "=============================================\n");
12073 dump_glyph_matrix (w
->current_matrix
,
12074 NILP (glyphs
) ? 0 : XINT (glyphs
));
12079 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12080 "Dump glyph row ROW to stderr.\n\
12081 GLYPH 0 means don't dump glyphs.\n\
12082 GLYPH 1 means dump glyphs in short form.\n\
12083 GLYPH > 1 or omitted means dump glyphs in long form.")
12085 Lisp_Object row
, glyphs
;
12087 CHECK_NUMBER (row
, 0);
12088 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
,
12090 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12095 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12096 "Dump glyph row ROW of the tool-bar of the current frame to stderr.\n\
12097 GLYPH 0 means don't dump glyphs.\n\
12098 GLYPH 1 means dump glyphs in short form.\n\
12099 GLYPH > 1 or omitted means dump glyphs in long form.")
12101 Lisp_Object row
, glyphs
;
12103 struct frame
*sf
= SELECTED_FRAME ();
12104 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)->current_matrix
);
12105 dump_glyph_row (m
, XINT (row
), INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12110 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12111 "Toggle tracing of redisplay.\n\
12112 With ARG, turn tracing on if and only if ARG is positive.")
12117 trace_redisplay_p
= !trace_redisplay_p
;
12120 arg
= Fprefix_numeric_value (arg
);
12121 trace_redisplay_p
= XINT (arg
) > 0;
12128 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
12129 "Print STRING to stderr.")
12131 Lisp_Object string
;
12133 CHECK_STRING (string
, 0);
12134 fprintf (stderr
, "%s", XSTRING (string
)->data
);
12138 #endif /* GLYPH_DEBUG */
12142 /***********************************************************************
12143 Building Desired Matrix Rows
12144 ***********************************************************************/
12146 /* Return a temporary glyph row holding the glyphs of an overlay
12147 arrow. Only used for non-window-redisplay windows. */
12149 static struct glyph_row
*
12150 get_overlay_arrow_glyph_row (w
)
12153 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12154 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12155 struct buffer
*old
= current_buffer
;
12156 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
12157 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
12158 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12162 int n_glyphs_before
;
12164 set_buffer_temp (buffer
);
12165 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12166 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12167 SET_TEXT_POS (it
.position
, 0, 0);
12169 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12171 while (p
< arrow_end
)
12173 Lisp_Object face
, ilisp
;
12175 /* Get the next character. */
12177 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12179 it
.c
= *p
, it
.len
= 1;
12182 /* Get its face. */
12183 ilisp
= make_number (p
- arrow_string
);
12184 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12185 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12187 /* Compute its width, get its glyphs. */
12188 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12189 SET_TEXT_POS (it
.position
, -1, -1);
12190 PRODUCE_GLYPHS (&it
);
12192 /* If this character doesn't fit any more in the line, we have
12193 to remove some glyphs. */
12194 if (it
.current_x
> it
.last_visible_x
)
12196 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12201 set_buffer_temp (old
);
12202 return it
.glyph_row
;
12206 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12207 glyphs are only inserted for terminal frames since we can't really
12208 win with truncation glyphs when partially visible glyphs are
12209 involved. Which glyphs to insert is determined by
12210 produce_special_glyphs. */
12213 insert_left_trunc_glyphs (it
)
12216 struct it truncate_it
;
12217 struct glyph
*from
, *end
, *to
, *toend
;
12219 xassert (!FRAME_WINDOW_P (it
->f
));
12221 /* Get the truncation glyphs. */
12223 truncate_it
.current_x
= 0;
12224 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12225 truncate_it
.glyph_row
= &scratch_glyph_row
;
12226 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12227 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12228 truncate_it
.object
= make_number (0);
12229 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12231 /* Overwrite glyphs from IT with truncation glyphs. */
12232 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12233 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12234 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12235 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12240 /* There may be padding glyphs left over. Overwrite them too. */
12241 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12243 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12249 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12253 /* Compute the pixel height and width of IT->glyph_row.
12255 Most of the time, ascent and height of a display line will be equal
12256 to the max_ascent and max_height values of the display iterator
12257 structure. This is not the case if
12259 1. We hit ZV without displaying anything. In this case, max_ascent
12260 and max_height will be zero.
12262 2. We have some glyphs that don't contribute to the line height.
12263 (The glyph row flag contributes_to_line_height_p is for future
12264 pixmap extensions).
12266 The first case is easily covered by using default values because in
12267 these cases, the line height does not really matter, except that it
12268 must not be zero. */
12271 compute_line_metrics (it
)
12274 struct glyph_row
*row
= it
->glyph_row
;
12277 if (FRAME_WINDOW_P (it
->f
))
12279 int i
, min_y
, max_y
;
12281 /* The line may consist of one space only, that was added to
12282 place the cursor on it. If so, the row's height hasn't been
12284 if (row
->height
== 0)
12286 if (it
->max_ascent
+ it
->max_descent
== 0)
12287 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12288 row
->ascent
= it
->max_ascent
;
12289 row
->height
= it
->max_ascent
+ it
->max_descent
;
12290 row
->phys_ascent
= it
->max_phys_ascent
;
12291 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12294 /* Compute the width of this line. */
12295 row
->pixel_width
= row
->x
;
12296 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12297 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12299 xassert (row
->pixel_width
>= 0);
12300 xassert (row
->ascent
>= 0 && row
->height
> 0);
12302 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12303 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12305 /* If first line's physical ascent is larger than its logical
12306 ascent, use the physical ascent, and make the row taller.
12307 This makes accented characters fully visible. */
12308 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12309 && row
->phys_ascent
> row
->ascent
)
12311 row
->height
+= row
->phys_ascent
- row
->ascent
;
12312 row
->ascent
= row
->phys_ascent
;
12315 /* Compute how much of the line is visible. */
12316 row
->visible_height
= row
->height
;
12318 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12319 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12321 if (row
->y
< min_y
)
12322 row
->visible_height
-= min_y
- row
->y
;
12323 if (row
->y
+ row
->height
> max_y
)
12324 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12328 row
->pixel_width
= row
->used
[TEXT_AREA
];
12329 if (row
->continued_p
)
12330 row
->pixel_width
-= it
->continuation_pixel_width
;
12331 else if (row
->truncated_on_right_p
)
12332 row
->pixel_width
-= it
->truncation_pixel_width
;
12333 row
->ascent
= row
->phys_ascent
= 0;
12334 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12337 /* Compute a hash code for this row. */
12339 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12340 for (i
= 0; i
< row
->used
[area
]; ++i
)
12341 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12342 + row
->glyphs
[area
][i
].u
.val
12343 + row
->glyphs
[area
][i
].face_id
12344 + row
->glyphs
[area
][i
].padding_p
12345 + (row
->glyphs
[area
][i
].type
<< 2));
12347 it
->max_ascent
= it
->max_descent
= 0;
12348 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12352 /* Append one space to the glyph row of iterator IT if doing a
12353 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12354 space have the default face, otherwise let it have the same face as
12355 IT->face_id. Value is non-zero if a space was added.
12357 This function is called to make sure that there is always one glyph
12358 at the end of a glyph row that the cursor can be set on under
12359 window-systems. (If there weren't such a glyph we would not know
12360 how wide and tall a box cursor should be displayed).
12362 At the same time this space let's a nicely handle clearing to the
12363 end of the line if the row ends in italic text. */
12366 append_space (it
, default_face_p
)
12368 int default_face_p
;
12370 if (FRAME_WINDOW_P (it
->f
))
12372 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12374 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12375 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12377 /* Save some values that must not be changed.
12378 Must save IT->c and IT->len because otherwise
12379 ITERATOR_AT_END_P wouldn't work anymore after
12380 append_space has been called. */
12381 enum display_element_type saved_what
= it
->what
;
12382 int saved_c
= it
->c
, saved_len
= it
->len
;
12383 int saved_x
= it
->current_x
;
12384 int saved_face_id
= it
->face_id
;
12385 struct text_pos saved_pos
;
12386 Lisp_Object saved_object
;
12389 saved_object
= it
->object
;
12390 saved_pos
= it
->position
;
12392 it
->what
= IT_CHARACTER
;
12393 bzero (&it
->position
, sizeof it
->position
);
12394 it
->object
= make_number (0);
12398 if (default_face_p
)
12399 it
->face_id
= DEFAULT_FACE_ID
;
12400 else if (it
->face_before_selective_p
)
12401 it
->face_id
= it
->saved_face_id
;
12402 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12403 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12405 PRODUCE_GLYPHS (it
);
12407 it
->current_x
= saved_x
;
12408 it
->object
= saved_object
;
12409 it
->position
= saved_pos
;
12410 it
->what
= saved_what
;
12411 it
->face_id
= saved_face_id
;
12412 it
->len
= saved_len
;
12422 /* Extend the face of the last glyph in the text area of IT->glyph_row
12423 to the end of the display line. Called from display_line.
12424 If the glyph row is empty, add a space glyph to it so that we
12425 know the face to draw. Set the glyph row flag fill_line_p. */
12428 extend_face_to_end_of_line (it
)
12432 struct frame
*f
= it
->f
;
12434 /* If line is already filled, do nothing. */
12435 if (it
->current_x
>= it
->last_visible_x
)
12438 /* Face extension extends the background and box of IT->face_id
12439 to the end of the line. If the background equals the background
12440 of the frame, we don't have to do anything. */
12441 if (it
->face_before_selective_p
)
12442 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12444 face
= FACE_FROM_ID (f
, it
->face_id
);
12446 if (FRAME_WINDOW_P (f
)
12447 && face
->box
== FACE_NO_BOX
12448 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12452 /* Set the glyph row flag indicating that the face of the last glyph
12453 in the text area has to be drawn to the end of the text area. */
12454 it
->glyph_row
->fill_line_p
= 1;
12456 /* If current character of IT is not ASCII, make sure we have the
12457 ASCII face. This will be automatically undone the next time
12458 get_next_display_element returns a multibyte character. Note
12459 that the character will always be single byte in unibyte text. */
12460 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12462 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12465 if (FRAME_WINDOW_P (f
))
12467 /* If the row is empty, add a space with the current face of IT,
12468 so that we know which face to draw. */
12469 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12471 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12472 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12473 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12478 /* Save some values that must not be changed. */
12479 int saved_x
= it
->current_x
;
12480 struct text_pos saved_pos
;
12481 Lisp_Object saved_object
;
12482 enum display_element_type saved_what
= it
->what
;
12483 int saved_face_id
= it
->face_id
;
12485 saved_object
= it
->object
;
12486 saved_pos
= it
->position
;
12488 it
->what
= IT_CHARACTER
;
12489 bzero (&it
->position
, sizeof it
->position
);
12490 it
->object
= make_number (0);
12493 it
->face_id
= face
->id
;
12495 PRODUCE_GLYPHS (it
);
12497 while (it
->current_x
<= it
->last_visible_x
)
12498 PRODUCE_GLYPHS (it
);
12500 /* Don't count these blanks really. It would let us insert a left
12501 truncation glyph below and make us set the cursor on them, maybe. */
12502 it
->current_x
= saved_x
;
12503 it
->object
= saved_object
;
12504 it
->position
= saved_pos
;
12505 it
->what
= saved_what
;
12506 it
->face_id
= saved_face_id
;
12511 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12512 trailing whitespace. */
12515 trailing_whitespace_p (charpos
)
12518 int bytepos
= CHAR_TO_BYTE (charpos
);
12521 while (bytepos
< ZV_BYTE
12522 && (c
= FETCH_CHAR (bytepos
),
12523 c
== ' ' || c
== '\t'))
12526 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12528 if (bytepos
!= PT_BYTE
)
12535 /* Highlight trailing whitespace, if any, in ROW. */
12538 highlight_trailing_whitespace (f
, row
)
12540 struct glyph_row
*row
;
12542 int used
= row
->used
[TEXT_AREA
];
12546 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12547 struct glyph
*glyph
= start
+ used
- 1;
12549 /* Skip over glyphs inserted to display the cursor at the
12550 end of a line, for extending the face of the last glyph
12551 to the end of the line on terminals, and for truncation
12552 and continuation glyphs. */
12553 while (glyph
>= start
12554 && glyph
->type
== CHAR_GLYPH
12555 && INTEGERP (glyph
->object
))
12558 /* If last glyph is a space or stretch, and it's trailing
12559 whitespace, set the face of all trailing whitespace glyphs in
12560 IT->glyph_row to `trailing-whitespace'. */
12562 && BUFFERP (glyph
->object
)
12563 && (glyph
->type
== STRETCH_GLYPH
12564 || (glyph
->type
== CHAR_GLYPH
12565 && glyph
->u
.ch
== ' '))
12566 && trailing_whitespace_p (glyph
->charpos
))
12568 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12570 while (glyph
>= start
12571 && BUFFERP (glyph
->object
)
12572 && (glyph
->type
== STRETCH_GLYPH
12573 || (glyph
->type
== CHAR_GLYPH
12574 && glyph
->u
.ch
== ' ')))
12575 (glyph
--)->face_id
= face_id
;
12581 /* Value is non-zero if glyph row ROW in window W should be
12582 used to hold the cursor. */
12585 cursor_row_p (w
, row
)
12587 struct glyph_row
*row
;
12589 int cursor_row_p
= 1;
12591 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12593 /* If the row ends with a newline from a string, we don't want
12594 the cursor there (if the row is continued it doesn't end in a
12596 if (CHARPOS (row
->end
.string_pos
) >= 0
12597 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12598 cursor_row_p
= row
->continued_p
;
12600 /* If the row ends at ZV, display the cursor at the end of that
12601 row instead of at the start of the row below. */
12602 else if (row
->ends_at_zv_p
)
12608 return cursor_row_p
;
12612 /* Construct the glyph row IT->glyph_row in the desired matrix of
12613 IT->w from text at the current position of IT. See dispextern.h
12614 for an overview of struct it. Value is non-zero if
12615 IT->glyph_row displays text, as opposed to a line displaying ZV
12622 struct glyph_row
*row
= it
->glyph_row
;
12624 /* We always start displaying at hpos zero even if hscrolled. */
12625 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12627 /* We must not display in a row that's not a text row. */
12628 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12629 < it
->w
->desired_matrix
->nrows
);
12631 /* Is IT->w showing the region? */
12632 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12634 /* Clear the result glyph row and enable it. */
12635 prepare_desired_row (row
);
12637 row
->y
= it
->current_y
;
12638 row
->start
= it
->current
;
12639 row
->continuation_lines_width
= it
->continuation_lines_width
;
12640 row
->displays_text_p
= 1;
12641 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12642 it
->starts_in_middle_of_char_p
= 0;
12644 /* Arrange the overlays nicely for our purposes. Usually, we call
12645 display_line on only one line at a time, in which case this
12646 can't really hurt too much, or we call it on lines which appear
12647 one after another in the buffer, in which case all calls to
12648 recenter_overlay_lists but the first will be pretty cheap. */
12649 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12651 /* Move over display elements that are not visible because we are
12652 hscrolled. This may stop at an x-position < IT->first_visible_x
12653 if the first glyph is partially visible or if we hit a line end. */
12654 if (it
->current_x
< it
->first_visible_x
)
12655 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12656 MOVE_TO_POS
| MOVE_TO_X
);
12658 /* Get the initial row height. This is either the height of the
12659 text hscrolled, if there is any, or zero. */
12660 row
->ascent
= it
->max_ascent
;
12661 row
->height
= it
->max_ascent
+ it
->max_descent
;
12662 row
->phys_ascent
= it
->max_phys_ascent
;
12663 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12665 /* Loop generating characters. The loop is left with IT on the next
12666 character to display. */
12669 int n_glyphs_before
, hpos_before
, x_before
;
12671 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12673 /* Retrieve the next thing to display. Value is zero if end of
12675 if (!get_next_display_element (it
))
12677 /* Maybe add a space at the end of this line that is used to
12678 display the cursor there under X. Set the charpos of the
12679 first glyph of blank lines not corresponding to any text
12681 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12682 || row
->used
[TEXT_AREA
] == 0)
12684 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12685 row
->displays_text_p
= 0;
12687 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
12688 row
->indicate_empty_line_p
= 1;
12691 it
->continuation_lines_width
= 0;
12692 row
->ends_at_zv_p
= 1;
12696 /* Now, get the metrics of what we want to display. This also
12697 generates glyphs in `row' (which is IT->glyph_row). */
12698 n_glyphs_before
= row
->used
[TEXT_AREA
];
12701 /* Remember the line height so far in case the next element doesn't
12702 fit on the line. */
12703 if (!it
->truncate_lines_p
)
12705 ascent
= it
->max_ascent
;
12706 descent
= it
->max_descent
;
12707 phys_ascent
= it
->max_phys_ascent
;
12708 phys_descent
= it
->max_phys_descent
;
12711 PRODUCE_GLYPHS (it
);
12713 /* If this display element was in marginal areas, continue with
12715 if (it
->area
!= TEXT_AREA
)
12717 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12718 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12719 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12720 row
->phys_height
= max (row
->phys_height
,
12721 it
->max_phys_ascent
+ it
->max_phys_descent
);
12722 set_iterator_to_next (it
, 1);
12726 /* Does the display element fit on the line? If we truncate
12727 lines, we should draw past the right edge of the window. If
12728 we don't truncate, we want to stop so that we can display the
12729 continuation glyph before the right margin. If lines are
12730 continued, there are two possible strategies for characters
12731 resulting in more than 1 glyph (e.g. tabs): Display as many
12732 glyphs as possible in this line and leave the rest for the
12733 continuation line, or display the whole element in the next
12734 line. Original redisplay did the former, so we do it also. */
12735 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12736 hpos_before
= it
->hpos
;
12739 if (/* Not a newline. */
12741 /* Glyphs produced fit entirely in the line. */
12742 && it
->current_x
< it
->last_visible_x
)
12744 it
->hpos
+= nglyphs
;
12745 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12746 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12747 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12748 row
->phys_height
= max (row
->phys_height
,
12749 it
->max_phys_ascent
+ it
->max_phys_descent
);
12750 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12751 row
->x
= x
- it
->first_visible_x
;
12756 struct glyph
*glyph
;
12758 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12760 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12761 new_x
= x
+ glyph
->pixel_width
;
12763 if (/* Lines are continued. */
12764 !it
->truncate_lines_p
12765 && (/* Glyph doesn't fit on the line. */
12766 new_x
> it
->last_visible_x
12767 /* Or it fits exactly on a window system frame. */
12768 || (new_x
== it
->last_visible_x
12769 && FRAME_WINDOW_P (it
->f
))))
12771 /* End of a continued line. */
12774 || (new_x
== it
->last_visible_x
12775 && FRAME_WINDOW_P (it
->f
)))
12777 /* Current glyph is the only one on the line or
12778 fits exactly on the line. We must continue
12779 the line because we can't draw the cursor
12780 after the glyph. */
12781 row
->continued_p
= 1;
12782 it
->current_x
= new_x
;
12783 it
->continuation_lines_width
+= new_x
;
12785 if (i
== nglyphs
- 1)
12786 set_iterator_to_next (it
, 1);
12788 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12789 && !FRAME_WINDOW_P (it
->f
))
12791 /* A padding glyph that doesn't fit on this line.
12792 This means the whole character doesn't fit
12794 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12796 /* Fill the rest of the row with continuation
12797 glyphs like in 20.x. */
12798 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12799 < row
->glyphs
[1 + TEXT_AREA
])
12800 produce_special_glyphs (it
, IT_CONTINUATION
);
12802 row
->continued_p
= 1;
12803 it
->current_x
= x_before
;
12804 it
->continuation_lines_width
+= x_before
;
12806 /* Restore the height to what it was before the
12807 element not fitting on the line. */
12808 it
->max_ascent
= ascent
;
12809 it
->max_descent
= descent
;
12810 it
->max_phys_ascent
= phys_ascent
;
12811 it
->max_phys_descent
= phys_descent
;
12815 /* Display element draws past the right edge of
12816 the window. Restore positions to values
12817 before the element. The next line starts
12818 with current_x before the glyph that could
12819 not be displayed, so that TAB works right. */
12820 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12822 /* Display continuation glyphs. */
12823 if (!FRAME_WINDOW_P (it
->f
))
12824 produce_special_glyphs (it
, IT_CONTINUATION
);
12825 row
->continued_p
= 1;
12828 it
->continuation_lines_width
+= x
;
12829 if (nglyphs
> 1 && i
> 0)
12831 row
->ends_in_middle_of_char_p
= 1;
12832 it
->starts_in_middle_of_char_p
= 1;
12835 /* Restore the height to what it was before the
12836 element not fitting on the line. */
12837 it
->max_ascent
= ascent
;
12838 it
->max_descent
= descent
;
12839 it
->max_phys_ascent
= phys_ascent
;
12840 it
->max_phys_descent
= phys_descent
;
12845 else if (new_x
> it
->first_visible_x
)
12847 /* Increment number of glyphs actually displayed. */
12850 if (x
< it
->first_visible_x
)
12851 /* Glyph is partially visible, i.e. row starts at
12852 negative X position. */
12853 row
->x
= x
- it
->first_visible_x
;
12857 /* Glyph is completely off the left margin of the
12858 window. This should not happen because of the
12859 move_it_in_display_line at the start of
12865 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12866 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12867 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12868 row
->phys_height
= max (row
->phys_height
,
12869 it
->max_phys_ascent
+ it
->max_phys_descent
);
12871 /* End of this display line if row is continued. */
12872 if (row
->continued_p
)
12876 /* Is this a line end? If yes, we're also done, after making
12877 sure that a non-default face is extended up to the right
12878 margin of the window. */
12879 if (ITERATOR_AT_END_OF_LINE_P (it
))
12881 int used_before
= row
->used
[TEXT_AREA
];
12883 /* Add a space at the end of the line that is used to
12884 display the cursor there. */
12885 append_space (it
, 0);
12887 /* Extend the face to the end of the line. */
12888 extend_face_to_end_of_line (it
);
12890 /* Make sure we have the position. */
12891 if (used_before
== 0)
12892 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12894 /* Consume the line end. This skips over invisible lines. */
12895 set_iterator_to_next (it
, 1);
12896 it
->continuation_lines_width
= 0;
12900 /* Proceed with next display element. Note that this skips
12901 over lines invisible because of selective display. */
12902 set_iterator_to_next (it
, 1);
12904 /* If we truncate lines, we are done when the last displayed
12905 glyphs reach past the right margin of the window. */
12906 if (it
->truncate_lines_p
12907 && (FRAME_WINDOW_P (it
->f
)
12908 ? (it
->current_x
>= it
->last_visible_x
)
12909 : (it
->current_x
> it
->last_visible_x
)))
12911 /* Maybe add truncation glyphs. */
12912 if (!FRAME_WINDOW_P (it
->f
))
12916 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
12917 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
12920 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
12922 row
->used
[TEXT_AREA
] = i
;
12923 produce_special_glyphs (it
, IT_TRUNCATION
);
12927 row
->truncated_on_right_p
= 1;
12928 it
->continuation_lines_width
= 0;
12929 reseat_at_next_visible_line_start (it
, 0);
12930 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12931 it
->hpos
= hpos_before
;
12932 it
->current_x
= x_before
;
12937 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12938 at the left window margin. */
12939 if (it
->first_visible_x
12940 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12942 if (!FRAME_WINDOW_P (it
->f
))
12943 insert_left_trunc_glyphs (it
);
12944 row
->truncated_on_left_p
= 1;
12947 /* If the start of this line is the overlay arrow-position, then
12948 mark this glyph row as the one containing the overlay arrow.
12949 This is clearly a mess with variable size fonts. It would be
12950 better to let it be displayed like cursors under X. */
12951 if (MARKERP (Voverlay_arrow_position
)
12952 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12953 && (MATRIX_ROW_START_CHARPOS (row
)
12954 == marker_position (Voverlay_arrow_position
))
12955 && STRINGP (Voverlay_arrow_string
)
12956 && ! overlay_arrow_seen
)
12958 /* Overlay arrow in window redisplay is a bitmap. */
12959 if (!FRAME_WINDOW_P (it
->f
))
12961 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12962 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12963 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12964 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12965 struct glyph
*p2
, *end
;
12967 /* Copy the arrow glyphs. */
12968 while (glyph
< arrow_end
)
12971 /* Throw away padding glyphs. */
12973 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12974 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12980 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12984 overlay_arrow_seen
= 1;
12985 row
->overlay_arrow_p
= 1;
12988 /* Compute pixel dimensions of this line. */
12989 compute_line_metrics (it
);
12991 /* Remember the position at which this line ends. */
12992 row
->end
= it
->current
;
12994 /* Maybe set the cursor. */
12995 if (it
->w
->cursor
.vpos
< 0
12996 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12997 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12998 && cursor_row_p (it
->w
, row
))
12999 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13001 /* Highlight trailing whitespace. */
13002 if (!NILP (Vshow_trailing_whitespace
))
13003 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13005 /* Prepare for the next line. This line starts horizontally at (X
13006 HPOS) = (0 0). Vertical positions are incremented. As a
13007 convenience for the caller, IT->glyph_row is set to the next
13009 it
->current_x
= it
->hpos
= 0;
13010 it
->current_y
+= row
->height
;
13013 return row
->displays_text_p
;
13018 /***********************************************************************
13020 ***********************************************************************/
13022 /* Redisplay the menu bar in the frame for window W.
13024 The menu bar of X frames that don't have X toolkit support is
13025 displayed in a special window W->frame->menu_bar_window.
13027 The menu bar of terminal frames is treated specially as far as
13028 glyph matrices are concerned. Menu bar lines are not part of
13029 windows, so the update is done directly on the frame matrix rows
13030 for the menu bar. */
13033 display_menu_bar (w
)
13036 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13041 /* Don't do all this for graphical frames. */
13043 if (!NILP (Vwindow_system
))
13046 #ifdef USE_X_TOOLKIT
13051 if (FRAME_MAC_P (f
))
13055 #ifdef USE_X_TOOLKIT
13056 xassert (!FRAME_WINDOW_P (f
));
13057 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13058 it
.first_visible_x
= 0;
13059 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13060 #else /* not USE_X_TOOLKIT */
13061 if (FRAME_WINDOW_P (f
))
13063 /* Menu bar lines are displayed in the desired matrix of the
13064 dummy window menu_bar_window. */
13065 struct window
*menu_w
;
13066 xassert (WINDOWP (f
->menu_bar_window
));
13067 menu_w
= XWINDOW (f
->menu_bar_window
);
13068 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13070 it
.first_visible_x
= 0;
13071 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13075 /* This is a TTY frame, i.e. character hpos/vpos are used as
13077 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13079 it
.first_visible_x
= 0;
13080 it
.last_visible_x
= FRAME_WIDTH (f
);
13082 #endif /* not USE_X_TOOLKIT */
13084 if (! mode_line_inverse_video
)
13085 /* Force the menu-bar to be displayed in the default face. */
13086 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13088 /* Clear all rows of the menu bar. */
13089 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13091 struct glyph_row
*row
= it
.glyph_row
+ i
;
13092 clear_glyph_row (row
);
13093 row
->enabled_p
= 1;
13094 row
->full_width_p
= 1;
13097 /* Display all items of the menu bar. */
13098 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13099 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13101 Lisp_Object string
;
13103 /* Stop at nil string. */
13104 string
= AREF (items
, i
+ 1);
13108 /* Remember where item was displayed. */
13109 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13111 /* Display the item, pad with one space. */
13112 if (it
.current_x
< it
.last_visible_x
)
13113 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13114 XSTRING (string
)->size
+ 1, 0, 0, -1);
13117 /* Fill out the line with spaces. */
13118 if (it
.current_x
< it
.last_visible_x
)
13119 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13121 /* Compute the total height of the lines. */
13122 compute_line_metrics (&it
);
13127 /***********************************************************************
13129 ***********************************************************************/
13131 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13132 FORCE is non-zero, redisplay mode lines unconditionally.
13133 Otherwise, redisplay only mode lines that are garbaged. Value is
13134 the number of windows whose mode lines were redisplayed. */
13137 redisplay_mode_lines (window
, force
)
13138 Lisp_Object window
;
13143 while (!NILP (window
))
13145 struct window
*w
= XWINDOW (window
);
13147 if (WINDOWP (w
->hchild
))
13148 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13149 else if (WINDOWP (w
->vchild
))
13150 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13152 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13153 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13155 Lisp_Object old_selected_frame
;
13156 struct text_pos lpoint
;
13157 struct buffer
*old
= current_buffer
;
13159 /* Set the window's buffer for the mode line display. */
13160 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13161 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13163 /* Point refers normally to the selected window. For any
13164 other window, set up appropriate value. */
13165 if (!EQ (window
, selected_window
))
13167 struct text_pos pt
;
13169 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13170 if (CHARPOS (pt
) < BEGV
)
13171 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13172 else if (CHARPOS (pt
) > (ZV
- 1))
13173 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13175 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13178 /* Temporarily set up the selected frame. */
13179 old_selected_frame
= selected_frame
;
13180 selected_frame
= w
->frame
;
13182 /* Display mode lines. */
13183 clear_glyph_matrix (w
->desired_matrix
);
13184 if (display_mode_lines (w
))
13187 w
->must_be_updated_p
= 1;
13190 /* Restore old settings. */
13191 selected_frame
= old_selected_frame
;
13192 set_buffer_internal_1 (old
);
13193 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13203 /* Display the mode and/or top line of window W. Value is the number
13204 of mode lines displayed. */
13207 display_mode_lines (w
)
13212 /* These will be set while the mode line specs are processed. */
13213 line_number_displayed
= 0;
13214 w
->column_number_displayed
= Qnil
;
13216 if (WINDOW_WANTS_MODELINE_P (w
))
13218 display_mode_line (w
, MODE_LINE_FACE_ID
,
13219 current_buffer
->mode_line_format
);
13223 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13225 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13226 current_buffer
->header_line_format
);
13234 /* Display mode or top line of window W. FACE_ID specifies which line
13235 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13236 FORMAT is the mode line format to display. Value is the pixel
13237 height of the mode line displayed. */
13240 display_mode_line (w
, face_id
, format
)
13242 enum face_id face_id
;
13243 Lisp_Object format
;
13248 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13249 prepare_desired_row (it
.glyph_row
);
13251 if (! mode_line_inverse_video
)
13252 /* Force the mode-line to be displayed in the default face. */
13253 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13255 /* Temporarily make frame's keyboard the current kboard so that
13256 kboard-local variables in the mode_line_format will get the right
13258 push_frame_kboard (it
.f
);
13259 display_mode_element (&it
, 0, 0, 0, format
);
13260 pop_frame_kboard ();
13262 /* Fill up with spaces. */
13263 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13265 compute_line_metrics (&it
);
13266 it
.glyph_row
->full_width_p
= 1;
13267 it
.glyph_row
->mode_line_p
= 1;
13268 it
.glyph_row
->inverse_p
= 0;
13269 it
.glyph_row
->continued_p
= 0;
13270 it
.glyph_row
->truncated_on_left_p
= 0;
13271 it
.glyph_row
->truncated_on_right_p
= 0;
13273 /* Make a 3D mode-line have a shadow at its right end. */
13274 face
= FACE_FROM_ID (it
.f
, face_id
);
13275 extend_face_to_end_of_line (&it
);
13276 if (face
->box
!= FACE_NO_BOX
)
13278 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13279 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13280 last
->right_box_line_p
= 1;
13283 return it
.glyph_row
->height
;
13287 /* Contribute ELT to the mode line for window IT->w. How it
13288 translates into text depends on its data type.
13290 IT describes the display environment in which we display, as usual.
13292 DEPTH is the depth in recursion. It is used to prevent
13293 infinite recursion here.
13295 FIELD_WIDTH is the number of characters the display of ELT should
13296 occupy in the mode line, and PRECISION is the maximum number of
13297 characters to display from ELT's representation. See
13298 display_string for details. *
13300 Returns the hpos of the end of the text generated by ELT. */
13303 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13306 int field_width
, precision
;
13309 int n
= 0, field
, prec
;
13317 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13321 /* A string: output it and check for %-constructs within it. */
13323 unsigned char *this = XSTRING (elt
)->data
;
13324 unsigned char *lisp_string
= this;
13326 while ((precision
<= 0 || n
< precision
)
13328 && (frame_title_ptr
13329 || it
->current_x
< it
->last_visible_x
))
13331 unsigned char *last
= this;
13333 /* Advance to end of string or next format specifier. */
13334 while ((c
= *this++) != '\0' && c
!= '%')
13337 if (this - 1 != last
)
13339 /* Output to end of string or up to '%'. Field width
13340 is length of string. Don't output more than
13341 PRECISION allows us. */
13343 prec
= strwidth (last
, this - last
);
13344 if (precision
> 0 && prec
> precision
- n
)
13345 prec
= precision
- n
;
13347 if (frame_title_ptr
)
13348 n
+= store_frame_title (last
, 0, prec
);
13350 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
13351 it
, 0, prec
, 0, -1);
13353 else /* c == '%' */
13355 unsigned char *percent_position
= this;
13357 /* Get the specified minimum width. Zero means
13360 while ((c
= *this++) >= '0' && c
<= '9')
13361 field
= field
* 10 + c
- '0';
13363 /* Don't pad beyond the total padding allowed. */
13364 if (field_width
- n
> 0 && field
> field_width
- n
)
13365 field
= field_width
- n
;
13367 /* Note that either PRECISION <= 0 or N < PRECISION. */
13368 prec
= precision
- n
;
13371 n
+= display_mode_element (it
, depth
, field
, prec
,
13372 Vglobal_mode_string
);
13375 unsigned char *spec
13376 = decode_mode_spec (it
->w
, c
, field
, prec
);
13378 if (frame_title_ptr
)
13379 n
+= store_frame_title (spec
, field
, prec
);
13383 = it
->glyph_row
->used
[TEXT_AREA
];
13385 = percent_position
- XSTRING (elt
)->data
;
13387 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
13388 field
, prec
, 0, -1);
13390 /* Assign to the glyphs written above the
13391 string where the `%x' came from, position
13395 struct glyph
*glyph
13396 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13400 for (i
= 0; i
< nwritten
; ++i
)
13402 glyph
[i
].object
= elt
;
13403 glyph
[i
].charpos
= charpos
;
13416 /* A symbol: process the value of the symbol recursively
13417 as if it appeared here directly. Avoid error if symbol void.
13418 Special case: if value of symbol is a string, output the string
13421 register Lisp_Object tem
;
13422 tem
= Fboundp (elt
);
13425 tem
= Fsymbol_value (elt
);
13426 /* If value is a string, output that string literally:
13427 don't check for % within it. */
13430 prec
= precision
- n
;
13431 if (frame_title_ptr
)
13432 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13434 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13437 else if (!EQ (tem
, elt
))
13439 /* Give up right away for nil or t. */
13449 register Lisp_Object car
, tem
;
13451 /* A cons cell: three distinct cases.
13452 If first element is a string or a cons, process all the elements
13453 and effectively concatenate them.
13454 If first element is a negative number, truncate displaying cdr to
13455 at most that many characters. If positive, pad (with spaces)
13456 to at least that many characters.
13457 If first element is a symbol, process the cadr or caddr recursively
13458 according to whether the symbol's value is non-nil or nil. */
13460 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13462 /* An element of the form (:eval FORM) means evaluate FORM
13463 and use the result as mode line elements. */
13464 struct gcpro gcpro1
;
13467 spec
= safe_eval (XCAR (XCDR (elt
)));
13469 n
+= display_mode_element (it
, depth
, field_width
- n
,
13470 precision
- n
, spec
);
13473 else if (SYMBOLP (car
))
13475 tem
= Fboundp (car
);
13479 /* elt is now the cdr, and we know it is a cons cell.
13480 Use its car if CAR has a non-nil value. */
13483 tem
= Fsymbol_value (car
);
13490 /* Symbol's value is nil (or symbol is unbound)
13491 Get the cddr of the original list
13492 and if possible find the caddr and use that. */
13496 else if (!CONSP (elt
))
13501 else if (INTEGERP (car
))
13503 register int lim
= XINT (car
);
13507 /* Negative int means reduce maximum width. */
13508 if (precision
<= 0)
13511 precision
= min (precision
, -lim
);
13515 /* Padding specified. Don't let it be more than
13516 current maximum. */
13518 lim
= min (precision
, lim
);
13520 /* If that's more padding than already wanted, queue it.
13521 But don't reduce padding already specified even if
13522 that is beyond the current truncation point. */
13523 field_width
= max (lim
, field_width
);
13527 else if (STRINGP (car
) || CONSP (car
))
13529 register int limit
= 50;
13530 /* Limit is to protect against circular lists. */
13533 && (precision
<= 0 || n
< precision
))
13535 n
+= display_mode_element (it
, depth
, field_width
- n
,
13536 precision
- n
, XCAR (elt
));
13545 if (frame_title_ptr
)
13546 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13548 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13549 precision
- n
, 0, 0);
13553 /* Pad to FIELD_WIDTH. */
13554 if (field_width
> 0 && n
< field_width
)
13556 if (frame_title_ptr
)
13557 n
+= store_frame_title ("", field_width
- n
, 0);
13559 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13567 /* Write a null-terminated, right justified decimal representation of
13568 the positive integer D to BUF using a minimal field width WIDTH. */
13571 pint2str (buf
, width
, d
)
13572 register char *buf
;
13573 register int width
;
13576 register char *p
= buf
;
13584 *p
++ = d
% 10 + '0';
13589 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13600 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13601 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13602 type of CODING_SYSTEM. Return updated pointer into BUF. */
13604 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13607 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13608 Lisp_Object coding_system
;
13609 register char *buf
;
13613 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13614 unsigned char *eol_str
;
13616 /* The EOL conversion we are using. */
13617 Lisp_Object eoltype
;
13619 val
= Fget (coding_system
, Qcoding_system
);
13622 if (!VECTORP (val
)) /* Not yet decided. */
13627 eoltype
= eol_mnemonic_undecided
;
13628 /* Don't mention EOL conversion if it isn't decided. */
13632 Lisp_Object eolvalue
;
13634 eolvalue
= Fget (coding_system
, Qeol_type
);
13637 *buf
++ = XFASTINT (AREF (val
, 1));
13641 /* The EOL conversion that is normal on this system. */
13643 if (NILP (eolvalue
)) /* Not yet decided. */
13644 eoltype
= eol_mnemonic_undecided
;
13645 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13646 eoltype
= eol_mnemonic_undecided
;
13647 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13648 eoltype
= (XFASTINT (eolvalue
) == 0
13649 ? eol_mnemonic_unix
13650 : (XFASTINT (eolvalue
) == 1
13651 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13657 /* Mention the EOL conversion if it is not the usual one. */
13658 if (STRINGP (eoltype
))
13660 eol_str
= XSTRING (eoltype
)->data
;
13661 eol_str_len
= XSTRING (eoltype
)->size
;
13663 else if (INTEGERP (eoltype
)
13664 && CHAR_VALID_P (XINT (eoltype
), 0))
13666 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13667 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13671 eol_str
= invalid_eol_type
;
13672 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13674 bcopy (eol_str
, buf
, eol_str_len
);
13675 buf
+= eol_str_len
;
13681 /* Return a string for the output of a mode line %-spec for window W,
13682 generated by character C. PRECISION >= 0 means don't return a
13683 string longer than that value. FIELD_WIDTH > 0 means pad the
13684 string returned with spaces to that value. */
13686 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13689 decode_mode_spec (w
, c
, field_width
, precision
)
13692 int field_width
, precision
;
13695 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13696 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13697 struct buffer
*b
= XBUFFER (w
->buffer
);
13704 if (!NILP (b
->read_only
))
13706 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13711 /* This differs from %* only for a modified read-only buffer. */
13712 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13714 if (!NILP (b
->read_only
))
13719 /* This differs from %* in ignoring read-only-ness. */
13720 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13732 if (command_loop_level
> 5)
13734 p
= decode_mode_spec_buf
;
13735 for (i
= 0; i
< command_loop_level
; i
++)
13738 return decode_mode_spec_buf
;
13746 if (command_loop_level
> 5)
13748 p
= decode_mode_spec_buf
;
13749 for (i
= 0; i
< command_loop_level
; i
++)
13752 return decode_mode_spec_buf
;
13759 /* Let lots_of_dashes be a string of infinite length. */
13760 if (field_width
<= 0
13761 || field_width
> sizeof (lots_of_dashes
))
13763 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13764 decode_mode_spec_buf
[i
] = '-';
13765 decode_mode_spec_buf
[i
] = '\0';
13766 return decode_mode_spec_buf
;
13769 return lots_of_dashes
;
13778 int col
= current_column ();
13779 w
->column_number_displayed
= make_number (col
);
13780 pint2str (decode_mode_spec_buf
, field_width
, col
);
13781 return decode_mode_spec_buf
;
13785 /* %F displays the frame name. */
13786 if (!NILP (f
->title
))
13787 return (char *) XSTRING (f
->title
)->data
;
13788 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13789 return (char *) XSTRING (f
->name
)->data
;
13798 int startpos
= XMARKER (w
->start
)->charpos
;
13799 int startpos_byte
= marker_byte_position (w
->start
);
13800 int line
, linepos
, linepos_byte
, topline
;
13802 int height
= XFASTINT (w
->height
);
13804 /* If we decided that this buffer isn't suitable for line numbers,
13805 don't forget that too fast. */
13806 if (EQ (w
->base_line_pos
, w
->buffer
))
13808 /* But do forget it, if the window shows a different buffer now. */
13809 else if (BUFFERP (w
->base_line_pos
))
13810 w
->base_line_pos
= Qnil
;
13812 /* If the buffer is very big, don't waste time. */
13813 if (INTEGERP (Vline_number_display_limit
)
13814 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13816 w
->base_line_pos
= Qnil
;
13817 w
->base_line_number
= Qnil
;
13821 if (!NILP (w
->base_line_number
)
13822 && !NILP (w
->base_line_pos
)
13823 && XFASTINT (w
->base_line_pos
) <= startpos
)
13825 line
= XFASTINT (w
->base_line_number
);
13826 linepos
= XFASTINT (w
->base_line_pos
);
13827 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13832 linepos
= BUF_BEGV (b
);
13833 linepos_byte
= BUF_BEGV_BYTE (b
);
13836 /* Count lines from base line to window start position. */
13837 nlines
= display_count_lines (linepos
, linepos_byte
,
13841 topline
= nlines
+ line
;
13843 /* Determine a new base line, if the old one is too close
13844 or too far away, or if we did not have one.
13845 "Too close" means it's plausible a scroll-down would
13846 go back past it. */
13847 if (startpos
== BUF_BEGV (b
))
13849 w
->base_line_number
= make_number (topline
);
13850 w
->base_line_pos
= make_number (BUF_BEGV (b
));
13852 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13853 || linepos
== BUF_BEGV (b
))
13855 int limit
= BUF_BEGV (b
);
13856 int limit_byte
= BUF_BEGV_BYTE (b
);
13858 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13860 if (startpos
- distance
> limit
)
13862 limit
= startpos
- distance
;
13863 limit_byte
= CHAR_TO_BYTE (limit
);
13866 nlines
= display_count_lines (startpos
, startpos_byte
,
13868 - (height
* 2 + 30),
13870 /* If we couldn't find the lines we wanted within
13871 line_number_display_limit_width chars per line,
13872 give up on line numbers for this window. */
13873 if (position
== limit_byte
&& limit
== startpos
- distance
)
13875 w
->base_line_pos
= w
->buffer
;
13876 w
->base_line_number
= Qnil
;
13880 w
->base_line_number
= make_number (topline
- nlines
);
13881 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
13884 /* Now count lines from the start pos to point. */
13885 nlines
= display_count_lines (startpos
, startpos_byte
,
13886 PT_BYTE
, PT
, &junk
);
13888 /* Record that we did display the line number. */
13889 line_number_displayed
= 1;
13891 /* Make the string to show. */
13892 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13893 return decode_mode_spec_buf
;
13896 char* p
= decode_mode_spec_buf
;
13897 int pad
= field_width
- 2;
13903 return decode_mode_spec_buf
;
13909 obj
= b
->mode_name
;
13913 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13919 int pos
= marker_position (w
->start
);
13920 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13922 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13924 if (pos
<= BUF_BEGV (b
))
13929 else if (pos
<= BUF_BEGV (b
))
13933 if (total
> 1000000)
13934 /* Do it differently for a large value, to avoid overflow. */
13935 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13937 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13938 /* We can't normally display a 3-digit number,
13939 so get us a 2-digit number that is close. */
13942 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13943 return decode_mode_spec_buf
;
13947 /* Display percentage of size above the bottom of the screen. */
13950 int toppos
= marker_position (w
->start
);
13951 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13952 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13954 if (botpos
>= BUF_ZV (b
))
13956 if (toppos
<= BUF_BEGV (b
))
13963 if (total
> 1000000)
13964 /* Do it differently for a large value, to avoid overflow. */
13965 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13967 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13968 /* We can't normally display a 3-digit number,
13969 so get us a 2-digit number that is close. */
13972 if (toppos
<= BUF_BEGV (b
))
13973 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13975 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13976 return decode_mode_spec_buf
;
13981 /* status of process */
13982 obj
= Fget_buffer_process (w
->buffer
);
13984 return "no process";
13985 #ifdef subprocesses
13986 obj
= Fsymbol_name (Fprocess_status (obj
));
13990 case 't': /* indicate TEXT or BINARY */
13991 #ifdef MODE_LINE_BINARY_TEXT
13992 return MODE_LINE_BINARY_TEXT (b
);
13998 /* coding-system (not including end-of-line format) */
14000 /* coding-system (including end-of-line type) */
14002 int eol_flag
= (c
== 'Z');
14003 char *p
= decode_mode_spec_buf
;
14005 if (! FRAME_WINDOW_P (f
))
14007 /* No need to mention EOL here--the terminal never needs
14008 to do EOL conversion. */
14009 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14010 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14012 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14015 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14016 #ifdef subprocesses
14017 obj
= Fget_buffer_process (Fcurrent_buffer ());
14018 if (PROCESSP (obj
))
14020 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14022 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14025 #endif /* subprocesses */
14028 return decode_mode_spec_buf
;
14033 return (char *) XSTRING (obj
)->data
;
14039 /* Count up to COUNT lines starting from START / START_BYTE.
14040 But don't go beyond LIMIT_BYTE.
14041 Return the number of lines thus found (always nonnegative).
14043 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14046 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14047 int start
, start_byte
, limit_byte
, count
;
14050 register unsigned char *cursor
;
14051 unsigned char *base
;
14053 register int ceiling
;
14054 register unsigned char *ceiling_addr
;
14055 int orig_count
= count
;
14057 /* If we are not in selective display mode,
14058 check only for newlines. */
14059 int selective_display
= (!NILP (current_buffer
->selective_display
)
14060 && !INTEGERP (current_buffer
->selective_display
));
14064 while (start_byte
< limit_byte
)
14066 ceiling
= BUFFER_CEILING_OF (start_byte
);
14067 ceiling
= min (limit_byte
- 1, ceiling
);
14068 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14069 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14072 if (selective_display
)
14073 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14076 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14079 if (cursor
!= ceiling_addr
)
14083 start_byte
+= cursor
- base
+ 1;
14084 *byte_pos_ptr
= start_byte
;
14088 if (++cursor
== ceiling_addr
)
14094 start_byte
+= cursor
- base
;
14099 while (start_byte
> limit_byte
)
14101 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14102 ceiling
= max (limit_byte
, ceiling
);
14103 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14104 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14107 if (selective_display
)
14108 while (--cursor
!= ceiling_addr
14109 && *cursor
!= '\n' && *cursor
!= 015)
14112 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14115 if (cursor
!= ceiling_addr
)
14119 start_byte
+= cursor
- base
+ 1;
14120 *byte_pos_ptr
= start_byte
;
14121 /* When scanning backwards, we should
14122 not count the newline posterior to which we stop. */
14123 return - orig_count
- 1;
14129 /* Here we add 1 to compensate for the last decrement
14130 of CURSOR, which took it past the valid range. */
14131 start_byte
+= cursor
- base
+ 1;
14135 *byte_pos_ptr
= limit_byte
;
14138 return - orig_count
+ count
;
14139 return orig_count
- count
;
14145 /***********************************************************************
14147 ***********************************************************************/
14149 /* Display a NUL-terminated string, starting with index START.
14151 If STRING is non-null, display that C string. Otherwise, the Lisp
14152 string LISP_STRING is displayed.
14154 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14155 FACE_STRING. Display STRING or LISP_STRING with the face at
14156 FACE_STRING_POS in FACE_STRING:
14158 Display the string in the environment given by IT, but use the
14159 standard display table, temporarily.
14161 FIELD_WIDTH is the minimum number of output glyphs to produce.
14162 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14163 with spaces. If STRING has more characters, more than FIELD_WIDTH
14164 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14166 PRECISION is the maximum number of characters to output from
14167 STRING. PRECISION < 0 means don't truncate the string.
14169 This is roughly equivalent to printf format specifiers:
14171 FIELD_WIDTH PRECISION PRINTF
14172 ----------------------------------------
14178 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14179 display them, and < 0 means obey the current buffer's value of
14180 enable_multibyte_characters.
14182 Value is the number of glyphs produced. */
14185 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14186 start
, it
, field_width
, precision
, max_x
, multibyte
)
14187 unsigned char *string
;
14188 Lisp_Object lisp_string
;
14189 Lisp_Object face_string
;
14190 int face_string_pos
;
14193 int field_width
, precision
, max_x
;
14196 int hpos_at_start
= it
->hpos
;
14197 int saved_face_id
= it
->face_id
;
14198 struct glyph_row
*row
= it
->glyph_row
;
14200 /* Initialize the iterator IT for iteration over STRING beginning
14201 with index START. */
14202 reseat_to_string (it
, string
, lisp_string
, start
,
14203 precision
, field_width
, multibyte
);
14205 /* If displaying STRING, set up the face of the iterator
14206 from LISP_STRING, if that's given. */
14207 if (STRINGP (face_string
))
14213 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14214 0, it
->region_beg_charpos
,
14215 it
->region_end_charpos
,
14216 &endptr
, it
->base_face_id
, 0);
14217 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14218 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14221 /* Set max_x to the maximum allowed X position. Don't let it go
14222 beyond the right edge of the window. */
14224 max_x
= it
->last_visible_x
;
14226 max_x
= min (max_x
, it
->last_visible_x
);
14228 /* Skip over display elements that are not visible. because IT->w is
14230 if (it
->current_x
< it
->first_visible_x
)
14231 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14232 MOVE_TO_POS
| MOVE_TO_X
);
14234 row
->ascent
= it
->max_ascent
;
14235 row
->height
= it
->max_ascent
+ it
->max_descent
;
14236 row
->phys_ascent
= it
->max_phys_ascent
;
14237 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14239 /* This condition is for the case that we are called with current_x
14240 past last_visible_x. */
14241 while (it
->current_x
< max_x
)
14243 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14245 /* Get the next display element. */
14246 if (!get_next_display_element (it
))
14249 /* Produce glyphs. */
14250 x_before
= it
->current_x
;
14251 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14252 PRODUCE_GLYPHS (it
);
14254 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14257 while (i
< nglyphs
)
14259 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14261 if (!it
->truncate_lines_p
14262 && x
+ glyph
->pixel_width
> max_x
)
14264 /* End of continued line or max_x reached. */
14265 if (CHAR_GLYPH_PADDING_P (*glyph
))
14267 /* A wide character is unbreakable. */
14268 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14269 it
->current_x
= x_before
;
14273 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14278 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14280 /* Glyph is at least partially visible. */
14282 if (x
< it
->first_visible_x
)
14283 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14287 /* Glyph is off the left margin of the display area.
14288 Should not happen. */
14292 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14293 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14294 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14295 row
->phys_height
= max (row
->phys_height
,
14296 it
->max_phys_ascent
+ it
->max_phys_descent
);
14297 x
+= glyph
->pixel_width
;
14301 /* Stop if max_x reached. */
14305 /* Stop at line ends. */
14306 if (ITERATOR_AT_END_OF_LINE_P (it
))
14308 it
->continuation_lines_width
= 0;
14312 set_iterator_to_next (it
, 1);
14314 /* Stop if truncating at the right edge. */
14315 if (it
->truncate_lines_p
14316 && it
->current_x
>= it
->last_visible_x
)
14318 /* Add truncation mark, but don't do it if the line is
14319 truncated at a padding space. */
14320 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14322 if (!FRAME_WINDOW_P (it
->f
))
14326 if (it
->current_x
> it
->last_visible_x
)
14328 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14329 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14331 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14333 row
->used
[TEXT_AREA
] = i
;
14334 produce_special_glyphs (it
, IT_TRUNCATION
);
14337 produce_special_glyphs (it
, IT_TRUNCATION
);
14339 it
->glyph_row
->truncated_on_right_p
= 1;
14345 /* Maybe insert a truncation at the left. */
14346 if (it
->first_visible_x
14347 && IT_CHARPOS (*it
) > 0)
14349 if (!FRAME_WINDOW_P (it
->f
))
14350 insert_left_trunc_glyphs (it
);
14351 it
->glyph_row
->truncated_on_left_p
= 1;
14354 it
->face_id
= saved_face_id
;
14356 /* Value is number of columns displayed. */
14357 return it
->hpos
- hpos_at_start
;
14362 /* This is like a combination of memq and assq. Return 1 if PROPVAL
14363 appears as an element of LIST or as the car of an element of LIST.
14364 If PROPVAL is a list, compare each element against LIST in that
14365 way, and return 1 if any element of PROPVAL is found in LIST.
14366 Otherwise return 0. This function cannot quit. */
14369 invisible_p (propval
, list
)
14370 register Lisp_Object propval
;
14373 register Lisp_Object tail
, proptail
;
14375 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14377 register Lisp_Object tem
;
14379 if (EQ (propval
, tem
))
14381 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14385 if (CONSP (propval
))
14387 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14389 Lisp_Object propelt
;
14390 propelt
= XCAR (proptail
);
14391 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14393 register Lisp_Object tem
;
14395 if (EQ (propelt
, tem
))
14397 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14407 /* Return 1 if PROPVAL appears as the car of an element of LIST and
14408 the cdr of that element is non-nil. If PROPVAL is a list, check
14409 each element of PROPVAL in that way, and the first time some
14410 element is found, return 1 if the cdr of that element is non-nil.
14411 Otherwise return 0. This function cannot quit. */
14414 invisible_ellipsis_p (propval
, list
)
14415 register Lisp_Object propval
;
14418 register Lisp_Object tail
, proptail
;
14420 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14422 register Lisp_Object tem
;
14424 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14425 return ! NILP (XCDR (tem
));
14428 if (CONSP (propval
))
14429 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14431 Lisp_Object propelt
;
14432 propelt
= XCAR (proptail
);
14433 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14435 register Lisp_Object tem
;
14437 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14438 return ! NILP (XCDR (tem
));
14447 /***********************************************************************
14449 ***********************************************************************/
14454 Vwith_echo_area_save_vector
= Qnil
;
14455 staticpro (&Vwith_echo_area_save_vector
);
14457 Vmessage_stack
= Qnil
;
14458 staticpro (&Vmessage_stack
);
14460 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14461 staticpro (&Qinhibit_redisplay
);
14464 defsubr (&Sdump_glyph_matrix
);
14465 defsubr (&Sdump_glyph_row
);
14466 defsubr (&Sdump_tool_bar_row
);
14467 defsubr (&Strace_redisplay
);
14468 defsubr (&Strace_to_stderr
);
14470 #ifdef HAVE_WINDOW_SYSTEM
14471 defsubr (&Stool_bar_lines_needed
);
14474 staticpro (&Qmenu_bar_update_hook
);
14475 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14477 staticpro (&Qoverriding_terminal_local_map
);
14478 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14480 staticpro (&Qoverriding_local_map
);
14481 Qoverriding_local_map
= intern ("overriding-local-map");
14483 staticpro (&Qwindow_scroll_functions
);
14484 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14486 staticpro (&Qredisplay_end_trigger_functions
);
14487 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14489 staticpro (&Qinhibit_point_motion_hooks
);
14490 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14492 QCdata
= intern (":data");
14493 staticpro (&QCdata
);
14494 Qdisplay
= intern ("display");
14495 staticpro (&Qdisplay
);
14496 Qspace_width
= intern ("space-width");
14497 staticpro (&Qspace_width
);
14498 Qraise
= intern ("raise");
14499 staticpro (&Qraise
);
14500 Qspace
= intern ("space");
14501 staticpro (&Qspace
);
14502 Qmargin
= intern ("margin");
14503 staticpro (&Qmargin
);
14504 Qleft_margin
= intern ("left-margin");
14505 staticpro (&Qleft_margin
);
14506 Qright_margin
= intern ("right-margin");
14507 staticpro (&Qright_margin
);
14508 Qalign_to
= intern ("align-to");
14509 staticpro (&Qalign_to
);
14510 QCalign_to
= intern (":align-to");
14511 staticpro (&QCalign_to
);
14512 Qrelative_width
= intern ("relative-width");
14513 staticpro (&Qrelative_width
);
14514 QCrelative_width
= intern (":relative-width");
14515 staticpro (&QCrelative_width
);
14516 QCrelative_height
= intern (":relative-height");
14517 staticpro (&QCrelative_height
);
14518 QCeval
= intern (":eval");
14519 staticpro (&QCeval
);
14520 Qwhen
= intern ("when");
14521 staticpro (&Qwhen
);
14522 QCfile
= intern (":file");
14523 staticpro (&QCfile
);
14524 Qfontified
= intern ("fontified");
14525 staticpro (&Qfontified
);
14526 Qfontification_functions
= intern ("fontification-functions");
14527 staticpro (&Qfontification_functions
);
14528 Qtrailing_whitespace
= intern ("trailing-whitespace");
14529 staticpro (&Qtrailing_whitespace
);
14530 Qimage
= intern ("image");
14531 staticpro (&Qimage
);
14532 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14533 staticpro (&Qmessage_truncate_lines
);
14534 Qgrow_only
= intern ("grow-only");
14535 staticpro (&Qgrow_only
);
14536 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14537 staticpro (&Qinhibit_menubar_update
);
14538 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14539 staticpro (&Qinhibit_eval_during_redisplay
);
14541 last_arrow_position
= Qnil
;
14542 last_arrow_string
= Qnil
;
14543 staticpro (&last_arrow_position
);
14544 staticpro (&last_arrow_string
);
14546 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14547 staticpro (&echo_buffer
[0]);
14548 staticpro (&echo_buffer
[1]);
14550 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14551 staticpro (&echo_area_buffer
[0]);
14552 staticpro (&echo_area_buffer
[1]);
14554 Vmessages_buffer_name
= build_string ("*Messages*");
14555 staticpro (&Vmessages_buffer_name
);
14557 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14558 "Non-nil means highlight trailing whitespace.\n\
14559 The face used for trailing whitespace is `trailing-whitespace'.");
14560 Vshow_trailing_whitespace
= Qnil
;
14562 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14563 "Non-nil means don't actually do any redisplay.\n\
14564 This is used for internal purposes.");
14565 Vinhibit_redisplay
= Qnil
;
14567 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14568 "String (or mode line construct) included (normally) in `mode-line-format'.");
14569 Vglobal_mode_string
= Qnil
;
14571 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14572 "Marker for where to display an arrow on top of the buffer text.\n\
14573 This must be the beginning of a line in order to work.\n\
14574 See also `overlay-arrow-string'.");
14575 Voverlay_arrow_position
= Qnil
;
14577 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14578 "String to display as an arrow. See also `overlay-arrow-position'.");
14579 Voverlay_arrow_string
= Qnil
;
14581 DEFVAR_INT ("scroll-step", &scroll_step
,
14582 "*The number of lines to try scrolling a window by when point moves out.\n\
14583 If that fails to bring point back on frame, point is centered instead.\n\
14584 If this is zero, point is always centered after it moves off frame.\n\
14585 If you want scrolling to always be a line at a time, you should set\n\
14586 `scroll-conservatively' to a large value rather than set this to 1.");
14588 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14589 "*Scroll up to this many lines, to bring point back on screen.\n\
14590 A value of zero means to scroll the text to center point vertically\n\
14592 scroll_conservatively
= 0;
14594 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14595 "*Number of lines of margin at the top and bottom of a window.\n\
14596 Recenter the window whenever point gets within this many lines\n\
14597 of the top or bottom of the window.");
14601 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
14604 DEFVAR_BOOL ("truncate-partial-width-windows",
14605 &truncate_partial_width_windows
,
14606 "*Non-nil means truncate lines in all windows less than full frame wide.");
14607 truncate_partial_width_windows
= 1;
14609 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14610 "nil means display the mode-line/header-line/menu-bar in the default face.\n\
14611 Any other value means to use the appropriate face, `mode-line',\n\
14612 `header-line', or `menu' respectively.\n\
14614 This variable is deprecated; please change the above faces instead.");
14615 mode_line_inverse_video
= 1;
14617 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14618 "*Maximum buffer size for which line number should be displayed.\n\
14619 If the buffer is bigger than this, the line number does not appear\n\
14620 in the mode line. A value of nil means no limit.");
14621 Vline_number_display_limit
= Qnil
;
14623 DEFVAR_INT ("line-number-display-limit-width",
14624 &line_number_display_limit_width
,
14625 "*Maximum line width (in characters) for line number display.\n\
14626 If the average length of the lines near point is bigger than this, then the\n\
14627 line number may be omitted from the mode line.");
14628 line_number_display_limit_width
= 200;
14630 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14631 "*Non-nil means highlight region even in nonselected windows.");
14632 highlight_nonselected_windows
= 0;
14634 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14635 "Non-nil if more than one frame is visible on this display.\n\
14636 Minibuffer-only frames don't count, but iconified frames do.\n\
14637 This variable is not guaranteed to be accurate except while processing\n\
14638 `frame-title-format' and `icon-title-format'.");
14640 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14641 "Template for displaying the title bar of visible frames.\n\
14642 \(Assuming the window manager supports this feature.)\n\
14643 This variable has the same structure as `mode-line-format' (which see),\n\
14644 and is used only on frames for which no explicit name has been set\n\
14645 \(see `modify-frame-parameters').");
14646 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14647 "Template for displaying the title bar of an iconified frame.\n\
14648 \(Assuming the window manager supports this feature.)\n\
14649 This variable has the same structure as `mode-line-format' (which see),\n\
14650 and is used only on frames for which no explicit name has been set\n\
14651 \(see `modify-frame-parameters').");
14653 = Vframe_title_format
14654 = Fcons (intern ("multiple-frames"),
14655 Fcons (build_string ("%b"),
14656 Fcons (Fcons (build_string (""),
14657 Fcons (intern ("invocation-name"),
14658 Fcons (build_string ("@"),
14659 Fcons (intern ("system-name"),
14663 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14664 "Maximum number of lines to keep in the message log buffer.\n\
14665 If nil, disable message logging. If t, log messages but don't truncate\n\
14666 the buffer when it becomes large.");
14667 Vmessage_log_max
= make_number (50);
14669 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14670 "Functions called before redisplay, if window sizes have changed.\n\
14671 The value should be a list of functions that take one argument.\n\
14672 Just before redisplay, for each frame, if any of its windows have changed\n\
14673 size since the last redisplay, or have been split or deleted,\n\
14674 all the functions in the list are called, with the frame as argument.");
14675 Vwindow_size_change_functions
= Qnil
;
14677 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14678 "List of Functions to call before redisplaying a window with scrolling.\n\
14679 Each function is called with two arguments, the window\n\
14680 and its new display-start position. Note that the value of `window-end'\n\
14681 is not valid when these functions are called.");
14682 Vwindow_scroll_functions
= Qnil
;
14684 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14685 "*Non-nil means automatically resize tool-bars.\n\
14686 This increases a tool-bar's height if not all tool-bar items are visible.\n\
14687 It decreases a tool-bar's height when it would display blank lines\n\
14689 auto_resize_tool_bars_p
= 1;
14691 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14692 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
14693 auto_raise_tool_bar_buttons_p
= 1;
14695 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14696 "*Margin around tool-bar buttons in pixels.\n\
14697 If an integer, use that for both horizontal and vertical margins.\n\
14698 Otherwise, value should be a pair of integers `(HORZ : VERT)' with\n\
14699 HORZ specifying the horizontal margin, and VERT specifying the\n\
14700 vertical margin.");
14701 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14703 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14704 "Relief thickness of tool-bar buttons.");
14705 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14707 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14708 "List of functions to call to fontify regions of text.\n\
14709 Each function is called with one argument POS. Functions must\n\
14710 fontify a region starting at POS in the current buffer, and give\n\
14711 fontified regions the property `fontified'.\n\
14712 This variable automatically becomes buffer-local when set.");
14713 Vfontification_functions
= Qnil
;
14714 Fmake_variable_buffer_local (Qfontification_functions
);
14716 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14717 &unibyte_display_via_language_environment
,
14718 "*Non-nil means display unibyte text according to language environment.\n\
14719 Specifically this means that unibyte non-ASCII characters\n\
14720 are displayed by converting them to the equivalent multibyte characters\n\
14721 according to the current language environment. As a result, they are\n\
14722 displayed according to the current fontset.");
14723 unibyte_display_via_language_environment
= 0;
14725 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14726 "*Maximum height for resizing mini-windows.\n\
14727 If a float, it specifies a fraction of the mini-window frame's height.\n\
14728 If an integer, it specifies a number of lines.");
14729 Vmax_mini_window_height
= make_float (0.25);
14731 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14732 "*How to resize mini-windows.\n\
14733 A value of nil means don't automatically resize mini-windows.\n\
14734 A value of t means resize them to fit the text displayed in them.\n\
14735 A value of `grow-only', the default, means let mini-windows grow\n\
14736 only, until their display becomes empty, at which point the windows\n\
14737 go back to their normal size.");
14738 Vresize_mini_windows
= Qgrow_only
;
14740 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14741 &cursor_in_non_selected_windows
,
14742 "*Non-nil means display a hollow cursor in non-selected windows.\n\
14743 Nil means don't display a cursor there.");
14744 cursor_in_non_selected_windows
= 1;
14746 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14747 "*Non-nil means scroll the display automatically to make point visible.");
14748 automatic_hscrolling_p
= 1;
14750 DEFVAR_LISP ("image-types", &Vimage_types
,
14751 "List of supported image types.\n\
14752 Each element of the list is a symbol for a supported image type.");
14753 Vimage_types
= Qnil
;
14755 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14756 "If non-nil, messages are truncated instead of resizing the echo area.\n\
14757 Bind this around calls to `message' to let it take effect.");
14758 message_truncate_lines
= 0;
14760 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14761 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
14762 Can be used to update submenus whose contents should vary.");
14763 Vmenu_bar_update_hook
= Qnil
;
14765 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14766 "Non-nil means don't update menu bars. Internal use only.");
14767 inhibit_menubar_update
= 0;
14769 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
14770 "Non-nil means don't eval Lisp during redisplay.");
14771 inhibit_eval_during_redisplay
= 0;
14775 /* Initialize this module when Emacs starts. */
14780 Lisp_Object root_window
;
14781 struct window
*mini_w
;
14783 current_header_line_height
= current_mode_line_height
= -1;
14785 CHARPOS (this_line_start_pos
) = 0;
14787 mini_w
= XWINDOW (minibuf_window
);
14788 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14790 if (!noninteractive
)
14792 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14795 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
14796 set_window_height (root_window
,
14797 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14799 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
14800 set_window_height (minibuf_window
, 1, 0);
14802 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
14803 mini_w
->width
= make_number (FRAME_WIDTH (f
));
14805 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14806 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14807 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14809 /* The default ellipsis glyphs `...'. */
14810 for (i
= 0; i
< 3; ++i
)
14811 default_invis_vector
[i
] = make_number ('.');
14814 #ifdef HAVE_WINDOW_SYSTEM
14816 /* Allocate the buffer for frame titles. */
14818 frame_title_buf
= (char *) xmalloc (size
);
14819 frame_title_buf_end
= frame_title_buf
+ size
;
14820 frame_title_ptr
= NULL
;
14822 #endif /* HAVE_WINDOW_SYSTEM */
14824 help_echo_showing_p
= 0;