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 /* Non-zero means we want a hollow cursor in windows that are not
514 selected. Zero means there's no cursor in such windows. */
516 int cursor_in_non_selected_windows
;
518 /* A scratch glyph row with contents used for generating truncation
519 glyphs. Also used in direct_output_for_insert. */
521 #define MAX_SCRATCH_GLYPHS 100
522 struct glyph_row scratch_glyph_row
;
523 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
525 /* Ascent and height of the last line processed by move_it_to. */
527 static int last_max_ascent
, last_height
;
529 /* Non-zero if there's a help-echo in the echo area. */
531 int help_echo_showing_p
;
533 /* If >= 0, computed, exact values of mode-line and header-line height
534 to use in the macros CURRENT_MODE_LINE_HEIGHT and
535 CURRENT_HEADER_LINE_HEIGHT. */
537 int current_mode_line_height
, current_header_line_height
;
539 /* The maximum distance to look ahead for text properties. Values
540 that are too small let us call compute_char_face and similar
541 functions too often which is expensive. Values that are too large
542 let us call compute_char_face and alike too often because we
543 might not be interested in text properties that far away. */
545 #define TEXT_PROP_DISTANCE_LIMIT 100
549 /* Non-zero means print traces of redisplay if compiled with
552 int trace_redisplay_p
;
554 #endif /* GLYPH_DEBUG */
556 #ifdef DEBUG_TRACE_MOVE
557 /* Non-zero means trace with TRACE_MOVE to stderr. */
560 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
562 #define TRACE_MOVE(x) (void) 0
565 /* Non-zero means automatically scroll windows horizontally to make
568 int automatic_hscrolling_p
;
570 /* A list of symbols, one for each supported image type. */
572 Lisp_Object Vimage_types
;
574 /* The variable `resize-mini-windows'. If nil, don't resize
575 mini-windows. If t, always resize them to fit the text they
576 display. If `grow-only', let mini-windows grow only until they
579 Lisp_Object Vresize_mini_windows
;
581 /* Value returned from text property handlers (see below). */
586 HANDLED_RECOMPUTE_PROPS
,
587 HANDLED_OVERLAY_STRING_CONSUMED
,
591 /* A description of text properties that redisplay is interested
596 /* The name of the property. */
599 /* A unique index for the property. */
602 /* A handler function called to set up iterator IT from the property
603 at IT's current position. Value is used to steer handle_stop. */
604 enum prop_handled (*handler
) P_ ((struct it
*it
));
607 static enum prop_handled handle_face_prop
P_ ((struct it
*));
608 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
609 static enum prop_handled handle_display_prop
P_ ((struct it
*));
610 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
611 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
612 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
614 /* Properties handled by iterators. */
616 static struct props it_props
[] =
618 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
619 /* Handle `face' before `display' because some sub-properties of
620 `display' need to know the face. */
621 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
622 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
623 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
624 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
628 /* Value is the position described by X. If X is a marker, value is
629 the marker_position of X. Otherwise, value is X. */
631 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
633 /* Enumeration returned by some move_it_.* functions internally. */
637 /* Not used. Undefined value. */
640 /* Move ended at the requested buffer position or ZV. */
641 MOVE_POS_MATCH_OR_ZV
,
643 /* Move ended at the requested X pixel position. */
646 /* Move within a line ended at the end of a line that must be
650 /* Move within a line ended at the end of a line that would
651 be displayed truncated. */
654 /* Move within a line ended at a line end. */
660 /* Function prototypes. */
662 static void setup_for_ellipsis
P_ ((struct it
*));
663 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
664 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
665 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
666 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
667 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
668 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
669 static int invisible_text_between_p
P_ ((struct it
*, int, int));
670 static int next_element_from_ellipsis
P_ ((struct it
*));
671 static void pint2str
P_ ((char *, int, int));
672 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
674 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
675 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
676 static void store_frame_title_char
P_ ((char));
677 static int store_frame_title
P_ ((unsigned char *, int, int));
678 static void x_consider_frame_title
P_ ((Lisp_Object
));
679 static void handle_stop
P_ ((struct it
*));
680 static int tool_bar_lines_needed
P_ ((struct frame
*));
681 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
682 static void ensure_echo_area_buffers
P_ ((void));
683 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
685 struct glyph_row
*));
686 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
687 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
688 static int with_echo_area_buffer
P_ ((struct window
*, int,
689 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
690 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
691 static void clear_garbaged_frames
P_ ((void));
692 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
693 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
694 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
695 static int display_echo_area
P_ ((struct window
*));
696 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
697 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
698 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
699 static int string_char_and_length
P_ ((unsigned char *, int, int *));
700 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
702 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
703 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
704 static void insert_left_trunc_glyphs
P_ ((struct it
*));
705 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
706 static void extend_face_to_end_of_line
P_ ((struct it
*));
707 static int append_space
P_ ((struct it
*, int));
708 static void make_cursor_line_fully_visible
P_ ((struct window
*));
709 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
710 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
711 static int trailing_whitespace_p
P_ ((int));
712 static int message_log_check_duplicate
P_ ((int, int, int, int));
713 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
714 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
715 static void push_it
P_ ((struct it
*));
716 static void pop_it
P_ ((struct it
*));
717 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
718 static void redisplay_internal
P_ ((int));
719 static int echo_area_display
P_ ((int));
720 static void redisplay_windows
P_ ((Lisp_Object
));
721 static void redisplay_window
P_ ((Lisp_Object
, int));
722 static void update_menu_bar
P_ ((struct frame
*, int));
723 static int try_window_reusing_current_matrix
P_ ((struct window
*));
724 static int try_window_id
P_ ((struct window
*));
725 static int display_line
P_ ((struct it
*));
726 static int display_mode_lines
P_ ((struct window
*));
727 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
728 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
729 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
730 static void display_menu_bar
P_ ((struct window
*));
731 static int display_count_lines
P_ ((int, int, int, int, int *));
732 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
733 int, int, struct it
*, int, int, int, int));
734 static void compute_line_metrics
P_ ((struct it
*));
735 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
736 static int get_overlay_strings
P_ ((struct it
*, int));
737 static void next_overlay_string
P_ ((struct it
*));
738 static void reseat
P_ ((struct it
*, struct text_pos
, int));
739 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
740 static void back_to_previous_visible_line_start
P_ ((struct it
*));
741 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
742 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
743 static int next_element_from_display_vector
P_ ((struct it
*));
744 static int next_element_from_string
P_ ((struct it
*));
745 static int next_element_from_c_string
P_ ((struct it
*));
746 static int next_element_from_buffer
P_ ((struct it
*));
747 static int next_element_from_composition
P_ ((struct it
*));
748 static int next_element_from_image
P_ ((struct it
*));
749 static int next_element_from_stretch
P_ ((struct it
*));
750 static void load_overlay_strings
P_ ((struct it
*, int));
751 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
752 struct display_pos
*));
753 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
754 Lisp_Object
, int, int, int, int));
755 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
757 void move_it_vertically_backward
P_ ((struct it
*, int));
758 static void init_to_row_start
P_ ((struct it
*, struct window
*,
759 struct glyph_row
*));
760 static void init_to_row_end
P_ ((struct it
*, struct window
*,
761 struct glyph_row
*));
762 static void back_to_previous_line_start
P_ ((struct it
*));
763 static int forward_to_next_line_start
P_ ((struct it
*, int *));
764 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
766 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
767 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
768 static int number_of_chars
P_ ((unsigned char *, int));
769 static void compute_stop_pos
P_ ((struct it
*));
770 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
772 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
773 static int next_overlay_change
P_ ((int));
774 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
775 Lisp_Object
, struct text_pos
*,
777 static int underlying_face_id
P_ ((struct it
*));
778 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
781 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
782 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
784 #ifdef HAVE_WINDOW_SYSTEM
786 static void update_tool_bar
P_ ((struct frame
*, int));
787 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
788 static int redisplay_tool_bar
P_ ((struct frame
*));
789 static void display_tool_bar_line
P_ ((struct it
*));
791 #endif /* HAVE_WINDOW_SYSTEM */
794 /***********************************************************************
795 Window display dimensions
796 ***********************************************************************/
798 /* Return the window-relative maximum y + 1 for glyph rows displaying
799 text in window W. This is the height of W minus the height of a
800 mode line, if any. */
803 window_text_bottom_y (w
)
806 struct frame
*f
= XFRAME (w
->frame
);
807 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
809 if (WINDOW_WANTS_MODELINE_P (w
))
810 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
815 /* Return the pixel width of display area AREA of window W. AREA < 0
816 means return the total width of W, not including bitmap areas to
817 the left and right of the window. */
820 window_box_width (w
, area
)
824 struct frame
*f
= XFRAME (w
->frame
);
825 int width
= XFASTINT (w
->width
);
827 if (!w
->pseudo_window_p
)
829 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
831 if (area
== TEXT_AREA
)
833 if (INTEGERP (w
->left_margin_width
))
834 width
-= XFASTINT (w
->left_margin_width
);
835 if (INTEGERP (w
->right_margin_width
))
836 width
-= XFASTINT (w
->right_margin_width
);
838 else if (area
== LEFT_MARGIN_AREA
)
839 width
= (INTEGERP (w
->left_margin_width
)
840 ? XFASTINT (w
->left_margin_width
) : 0);
841 else if (area
== RIGHT_MARGIN_AREA
)
842 width
= (INTEGERP (w
->right_margin_width
)
843 ? XFASTINT (w
->right_margin_width
) : 0);
846 return width
* CANON_X_UNIT (f
);
850 /* Return the pixel height of the display area of window W, not
851 including mode lines of W, if any.. */
854 window_box_height (w
)
857 struct frame
*f
= XFRAME (w
->frame
);
858 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
860 xassert (height
>= 0);
862 /* Note: the code below that determines the mode-line/header-line
863 height is essentially the same as that contained in the macro
864 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
865 the appropriate glyph row has its `mode_line_p' flag set,
866 and if it doesn't, uses estimate_mode_line_height instead. */
868 if (WINDOW_WANTS_MODELINE_P (w
))
870 struct glyph_row
*ml_row
871 = (w
->current_matrix
&& w
->current_matrix
->rows
872 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
874 if (ml_row
&& ml_row
->mode_line_p
)
875 height
-= ml_row
->height
;
877 height
-= estimate_mode_line_height (f
, MODE_LINE_FACE_ID
);
880 if (WINDOW_WANTS_HEADER_LINE_P (w
))
882 struct glyph_row
*hl_row
883 = (w
->current_matrix
&& w
->current_matrix
->rows
884 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
886 if (hl_row
&& hl_row
->mode_line_p
)
887 height
-= hl_row
->height
;
889 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
896 /* Return the frame-relative coordinate of the left edge of display
897 area AREA of window W. AREA < 0 means return the left edge of the
898 whole window, to the right of any bitmap area at the left side of
902 window_box_left (w
, area
)
906 struct frame
*f
= XFRAME (w
->frame
);
907 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
909 if (!w
->pseudo_window_p
)
911 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
912 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
914 if (area
== TEXT_AREA
)
915 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
916 else if (area
== RIGHT_MARGIN_AREA
)
917 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
918 + window_box_width (w
, TEXT_AREA
));
925 /* Return the frame-relative coordinate of the right edge of display
926 area AREA of window W. AREA < 0 means return the left edge of the
927 whole window, to the left of any bitmap area at the right side of
931 window_box_right (w
, area
)
935 return window_box_left (w
, area
) + window_box_width (w
, area
);
939 /* Get the bounding box of the display area AREA of window W, without
940 mode lines, in frame-relative coordinates. AREA < 0 means the
941 whole window, not including bitmap areas to the left and right of
942 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
943 coordinates of the upper-left corner of the box. Return in
944 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
947 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
950 int *box_x
, *box_y
, *box_width
, *box_height
;
952 struct frame
*f
= XFRAME (w
->frame
);
954 *box_width
= window_box_width (w
, area
);
955 *box_height
= window_box_height (w
);
956 *box_x
= window_box_left (w
, area
);
957 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
958 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
959 if (WINDOW_WANTS_HEADER_LINE_P (w
))
960 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
964 /* Get the bounding box of the display area AREA of window W, without
965 mode lines. AREA < 0 means the whole window, not including bitmap
966 areas to the left and right of the window. Return in *TOP_LEFT_X
967 and TOP_LEFT_Y the frame-relative pixel coordinates of the
968 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
969 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
973 window_box_edges (w
, area
, top_left_x
, top_left_y
,
974 bottom_right_x
, bottom_right_y
)
977 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
979 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
981 *bottom_right_x
+= *top_left_x
;
982 *bottom_right_y
+= *top_left_y
;
987 /***********************************************************************
989 ***********************************************************************/
991 /* Return the bottom y-position of the line the iterator IT is in.
992 This can modify IT's settings. */
998 int line_height
= it
->max_ascent
+ it
->max_descent
;
999 int line_top_y
= it
->current_y
;
1001 if (line_height
== 0)
1004 line_height
= last_height
;
1005 else if (IT_CHARPOS (*it
) < ZV
)
1007 move_it_by_lines (it
, 1, 1);
1008 line_height
= (it
->max_ascent
|| it
->max_descent
1009 ? it
->max_ascent
+ it
->max_descent
1014 struct glyph_row
*row
= it
->glyph_row
;
1016 /* Use the default character height. */
1017 it
->glyph_row
= NULL
;
1018 it
->what
= IT_CHARACTER
;
1021 PRODUCE_GLYPHS (it
);
1022 line_height
= it
->ascent
+ it
->descent
;
1023 it
->glyph_row
= row
;
1027 return line_top_y
+ line_height
;
1031 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1032 1 if POS is visible and the line containing POS is fully visible.
1033 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1034 and header-lines heights. */
1037 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1039 int charpos
, *fully
, exact_mode_line_heights_p
;
1042 struct text_pos top
;
1044 struct buffer
*old_buffer
= NULL
;
1046 if (XBUFFER (w
->buffer
) != current_buffer
)
1048 old_buffer
= current_buffer
;
1049 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1052 *fully
= visible_p
= 0;
1053 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1055 /* Compute exact mode line heights, if requested. */
1056 if (exact_mode_line_heights_p
)
1058 if (WINDOW_WANTS_MODELINE_P (w
))
1059 current_mode_line_height
1060 = display_mode_line (w
, MODE_LINE_FACE_ID
,
1061 current_buffer
->mode_line_format
);
1063 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1064 current_header_line_height
1065 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1066 current_buffer
->header_line_format
);
1069 start_display (&it
, w
, top
);
1070 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1071 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1073 /* Note that we may overshoot because of invisible text. */
1074 if (IT_CHARPOS (it
) >= charpos
)
1076 int top_y
= it
.current_y
;
1077 int bottom_y
= line_bottom_y (&it
);
1078 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1080 if (top_y
< window_top_y
)
1081 visible_p
= bottom_y
> window_top_y
;
1082 else if (top_y
< it
.last_visible_y
)
1085 *fully
= bottom_y
<= it
.last_visible_y
;
1088 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1090 move_it_by_lines (&it
, 1, 0);
1091 if (charpos
< IT_CHARPOS (it
))
1099 set_buffer_internal_1 (old_buffer
);
1101 current_header_line_height
= current_mode_line_height
= -1;
1106 /* Return the next character from STR which is MAXLEN bytes long.
1107 Return in *LEN the length of the character. This is like
1108 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1109 we find one, we return a `?', but with the length of the invalid
1113 string_char_and_length (str
, maxlen
, len
)
1119 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1120 if (!CHAR_VALID_P (c
, 1))
1121 /* We may not change the length here because other places in Emacs
1122 don't use this function, i.e. they silently accept invalid
1131 /* Given a position POS containing a valid character and byte position
1132 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1134 static struct text_pos
1135 string_pos_nchars_ahead (pos
, string
, nchars
)
1136 struct text_pos pos
;
1140 xassert (STRINGP (string
) && nchars
>= 0);
1142 if (STRING_MULTIBYTE (string
))
1144 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1145 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1150 string_char_and_length (p
, rest
, &len
);
1151 p
+= len
, rest
-= len
;
1152 xassert (rest
>= 0);
1154 BYTEPOS (pos
) += len
;
1158 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1164 /* Value is the text position, i.e. character and byte position,
1165 for character position CHARPOS in STRING. */
1167 static INLINE
struct text_pos
1168 string_pos (charpos
, string
)
1172 struct text_pos pos
;
1173 xassert (STRINGP (string
));
1174 xassert (charpos
>= 0);
1175 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1180 /* Value is a text position, i.e. character and byte position, for
1181 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1182 means recognize multibyte characters. */
1184 static struct text_pos
1185 c_string_pos (charpos
, s
, multibyte_p
)
1190 struct text_pos pos
;
1192 xassert (s
!= NULL
);
1193 xassert (charpos
>= 0);
1197 int rest
= strlen (s
), len
;
1199 SET_TEXT_POS (pos
, 0, 0);
1202 string_char_and_length (s
, rest
, &len
);
1203 s
+= len
, rest
-= len
;
1204 xassert (rest
>= 0);
1206 BYTEPOS (pos
) += len
;
1210 SET_TEXT_POS (pos
, charpos
, charpos
);
1216 /* Value is the number of characters in C string S. MULTIBYTE_P
1217 non-zero means recognize multibyte characters. */
1220 number_of_chars (s
, multibyte_p
)
1228 int rest
= strlen (s
), len
;
1229 unsigned char *p
= (unsigned char *) s
;
1231 for (nchars
= 0; rest
> 0; ++nchars
)
1233 string_char_and_length (p
, rest
, &len
);
1234 rest
-= len
, p
+= len
;
1238 nchars
= strlen (s
);
1244 /* Compute byte position NEWPOS->bytepos corresponding to
1245 NEWPOS->charpos. POS is a known position in string STRING.
1246 NEWPOS->charpos must be >= POS.charpos. */
1249 compute_string_pos (newpos
, pos
, string
)
1250 struct text_pos
*newpos
, pos
;
1253 xassert (STRINGP (string
));
1254 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1256 if (STRING_MULTIBYTE (string
))
1257 *newpos
= string_pos_nchars_ahead (pos
, string
,
1258 CHARPOS (*newpos
) - CHARPOS (pos
));
1260 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1265 /***********************************************************************
1266 Lisp form evaluation
1267 ***********************************************************************/
1269 /* Error handler for safe_eval and safe_call. */
1272 safe_eval_handler (arg
)
1275 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1280 /* Evaluate SEXPR and return the result, or nil if something went
1289 if (inhibit_eval_during_redisplay
)
1293 int count
= BINDING_STACK_SIZE ();
1294 struct gcpro gcpro1
;
1297 specbind (Qinhibit_redisplay
, Qt
);
1298 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
1301 val
= unbind_to (count
, val
);
1308 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1309 Return the result, or nil if something went wrong. */
1312 safe_call (nargs
, args
)
1318 if (inhibit_eval_during_redisplay
)
1322 int count
= BINDING_STACK_SIZE ();
1323 struct gcpro gcpro1
;
1326 gcpro1
.nvars
= nargs
;
1327 specbind (Qinhibit_redisplay
, Qt
);
1328 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1331 val
= unbind_to (count
, val
);
1338 /* Call function FN with one argument ARG.
1339 Return the result, or nil if something went wrong. */
1342 safe_call1 (fn
, arg
)
1343 Lisp_Object fn
, arg
;
1345 Lisp_Object args
[2];
1348 return safe_call (2, args
);
1353 /***********************************************************************
1355 ***********************************************************************/
1359 /* Define CHECK_IT to perform sanity checks on iterators.
1360 This is for debugging. It is too slow to do unconditionally. */
1366 if (it
->method
== next_element_from_string
)
1368 xassert (STRINGP (it
->string
));
1369 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1371 else if (it
->method
== next_element_from_buffer
)
1373 /* Check that character and byte positions agree. */
1374 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1378 xassert (it
->current
.dpvec_index
>= 0);
1380 xassert (it
->current
.dpvec_index
< 0);
1383 #define CHECK_IT(IT) check_it ((IT))
1387 #define CHECK_IT(IT) (void) 0
1394 /* Check that the window end of window W is what we expect it
1395 to be---the last row in the current matrix displaying text. */
1398 check_window_end (w
)
1401 if (!MINI_WINDOW_P (w
)
1402 && !NILP (w
->window_end_valid
))
1404 struct glyph_row
*row
;
1405 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1406 XFASTINT (w
->window_end_vpos
)),
1408 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1409 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1413 #define CHECK_WINDOW_END(W) check_window_end ((W))
1415 #else /* not GLYPH_DEBUG */
1417 #define CHECK_WINDOW_END(W) (void) 0
1419 #endif /* not GLYPH_DEBUG */
1423 /***********************************************************************
1424 Iterator initialization
1425 ***********************************************************************/
1427 /* Initialize IT for displaying current_buffer in window W, starting
1428 at character position CHARPOS. CHARPOS < 0 means that no buffer
1429 position is specified which is useful when the iterator is assigned
1430 a position later. BYTEPOS is the byte position corresponding to
1431 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1433 If ROW is not null, calls to produce_glyphs with IT as parameter
1434 will produce glyphs in that row.
1436 BASE_FACE_ID is the id of a base face to use. It must be one of
1437 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1438 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1439 displaying the tool-bar.
1441 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1442 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1443 corresponding mode line glyph row of the desired matrix of W. */
1446 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1449 int charpos
, bytepos
;
1450 struct glyph_row
*row
;
1451 enum face_id base_face_id
;
1453 int highlight_region_p
;
1455 /* Some precondition checks. */
1456 xassert (w
!= NULL
&& it
!= NULL
);
1457 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1459 /* If face attributes have been changed since the last redisplay,
1460 free realized faces now because they depend on face definitions
1461 that might have changed. */
1462 if (face_change_count
)
1464 face_change_count
= 0;
1465 free_all_realized_faces (Qnil
);
1468 /* Use one of the mode line rows of W's desired matrix if
1472 if (base_face_id
== MODE_LINE_FACE_ID
)
1473 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1474 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1475 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1479 bzero (it
, sizeof *it
);
1480 it
->current
.overlay_string_index
= -1;
1481 it
->current
.dpvec_index
= -1;
1482 it
->base_face_id
= base_face_id
;
1484 /* The window in which we iterate over current_buffer: */
1485 XSETWINDOW (it
->window
, w
);
1487 it
->f
= XFRAME (w
->frame
);
1489 /* Extra space between lines (on window systems only). */
1490 if (base_face_id
== DEFAULT_FACE_ID
1491 && FRAME_WINDOW_P (it
->f
))
1493 if (NATNUMP (current_buffer
->extra_line_spacing
))
1494 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1495 else if (it
->f
->extra_line_spacing
> 0)
1496 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1499 /* If realized faces have been removed, e.g. because of face
1500 attribute changes of named faces, recompute them. When running
1501 in batch mode, the face cache of Vterminal_frame is null. If
1502 we happen to get called, make a dummy face cache. */
1507 FRAME_FACE_CACHE (it
->f
) == NULL
)
1508 init_frame_faces (it
->f
);
1509 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1510 recompute_basic_faces (it
->f
);
1512 /* Current value of the `space-width', and 'height' properties. */
1513 it
->space_width
= Qnil
;
1514 it
->font_height
= Qnil
;
1516 /* Are control characters displayed as `^C'? */
1517 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1519 /* -1 means everything between a CR and the following line end
1520 is invisible. >0 means lines indented more than this value are
1522 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1523 ? XFASTINT (current_buffer
->selective_display
)
1524 : (!NILP (current_buffer
->selective_display
)
1526 it
->selective_display_ellipsis_p
1527 = !NILP (current_buffer
->selective_display_ellipses
);
1529 /* Display table to use. */
1530 it
->dp
= window_display_table (w
);
1532 /* Are multibyte characters enabled in current_buffer? */
1533 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1535 /* Non-zero if we should highlight the region. */
1537 = (!NILP (Vtransient_mark_mode
)
1538 && !NILP (current_buffer
->mark_active
)
1539 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1541 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1542 start and end of a visible region in window IT->w. Set both to
1543 -1 to indicate no region. */
1544 if (highlight_region_p
1545 /* Maybe highlight only in selected window. */
1546 && (/* Either show region everywhere. */
1547 highlight_nonselected_windows
1548 /* Or show region in the selected window. */
1549 || w
== XWINDOW (selected_window
)
1550 /* Or show the region if we are in the mini-buffer and W is
1551 the window the mini-buffer refers to. */
1552 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1553 && WINDOWP (Vminibuf_scroll_window
)
1554 && w
== XWINDOW (Vminibuf_scroll_window
))))
1556 int charpos
= marker_position (current_buffer
->mark
);
1557 it
->region_beg_charpos
= min (PT
, charpos
);
1558 it
->region_end_charpos
= max (PT
, charpos
);
1561 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1563 /* Get the position at which the redisplay_end_trigger hook should
1564 be run, if it is to be run at all. */
1565 if (MARKERP (w
->redisplay_end_trigger
)
1566 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1567 it
->redisplay_end_trigger_charpos
1568 = marker_position (w
->redisplay_end_trigger
);
1569 else if (INTEGERP (w
->redisplay_end_trigger
))
1570 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1572 /* Correct bogus values of tab_width. */
1573 it
->tab_width
= XINT (current_buffer
->tab_width
);
1574 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1577 /* Are lines in the display truncated? */
1578 it
->truncate_lines_p
1579 = (base_face_id
!= DEFAULT_FACE_ID
1580 || XINT (it
->w
->hscroll
)
1581 || (truncate_partial_width_windows
1582 && !WINDOW_FULL_WIDTH_P (it
->w
))
1583 || !NILP (current_buffer
->truncate_lines
));
1585 /* Get dimensions of truncation and continuation glyphs. These are
1586 displayed as bitmaps under X, so we don't need them for such
1588 if (!FRAME_WINDOW_P (it
->f
))
1590 if (it
->truncate_lines_p
)
1592 /* We will need the truncation glyph. */
1593 xassert (it
->glyph_row
== NULL
);
1594 produce_special_glyphs (it
, IT_TRUNCATION
);
1595 it
->truncation_pixel_width
= it
->pixel_width
;
1599 /* We will need the continuation glyph. */
1600 xassert (it
->glyph_row
== NULL
);
1601 produce_special_glyphs (it
, IT_CONTINUATION
);
1602 it
->continuation_pixel_width
= it
->pixel_width
;
1605 /* Reset these values to zero becaue the produce_special_glyphs
1606 above has changed them. */
1607 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1608 it
->phys_ascent
= it
->phys_descent
= 0;
1611 /* Set this after getting the dimensions of truncation and
1612 continuation glyphs, so that we don't produce glyphs when calling
1613 produce_special_glyphs, above. */
1614 it
->glyph_row
= row
;
1615 it
->area
= TEXT_AREA
;
1617 /* Get the dimensions of the display area. The display area
1618 consists of the visible window area plus a horizontally scrolled
1619 part to the left of the window. All x-values are relative to the
1620 start of this total display area. */
1621 if (base_face_id
!= DEFAULT_FACE_ID
)
1623 /* Mode lines, menu bar in terminal frames. */
1624 it
->first_visible_x
= 0;
1625 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1630 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1631 it
->last_visible_x
= (it
->first_visible_x
1632 + window_box_width (w
, TEXT_AREA
));
1634 /* If we truncate lines, leave room for the truncator glyph(s) at
1635 the right margin. Otherwise, leave room for the continuation
1636 glyph(s). Truncation and continuation glyphs are not inserted
1637 for window-based redisplay. */
1638 if (!FRAME_WINDOW_P (it
->f
))
1640 if (it
->truncate_lines_p
)
1641 it
->last_visible_x
-= it
->truncation_pixel_width
;
1643 it
->last_visible_x
-= it
->continuation_pixel_width
;
1646 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1647 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1650 /* Leave room for a border glyph. */
1651 if (!FRAME_WINDOW_P (it
->f
)
1652 && !WINDOW_RIGHTMOST_P (it
->w
))
1653 it
->last_visible_x
-= 1;
1655 it
->last_visible_y
= window_text_bottom_y (w
);
1657 /* For mode lines and alike, arrange for the first glyph having a
1658 left box line if the face specifies a box. */
1659 if (base_face_id
!= DEFAULT_FACE_ID
)
1663 it
->face_id
= base_face_id
;
1665 /* If we have a boxed mode line, make the first character appear
1666 with a left box line. */
1667 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1668 if (face
->box
!= FACE_NO_BOX
)
1669 it
->start_of_box_run_p
= 1;
1672 /* If a buffer position was specified, set the iterator there,
1673 getting overlays and face properties from that position. */
1676 it
->end_charpos
= ZV
;
1678 IT_CHARPOS (*it
) = charpos
;
1680 /* Compute byte position if not specified. */
1682 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1684 IT_BYTEPOS (*it
) = bytepos
;
1686 /* Compute faces etc. */
1687 reseat (it
, it
->current
.pos
, 1);
1694 /* Initialize IT for the display of window W with window start POS. */
1697 start_display (it
, w
, pos
)
1700 struct text_pos pos
;
1702 int start_at_line_beg_p
;
1703 struct glyph_row
*row
;
1704 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1707 row
= w
->desired_matrix
->rows
+ first_vpos
;
1708 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1709 first_y
= it
->current_y
;
1711 /* If window start is not at a line start, move back to the line
1712 start. This makes sure that we take continuation lines into
1714 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1715 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1716 if (!start_at_line_beg_p
)
1717 reseat_at_previous_visible_line_start (it
);
1719 /* If window start is not at a line start, skip forward to POS to
1720 get the correct continuation_lines_width and current_x. */
1721 if (!start_at_line_beg_p
)
1723 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1725 /* If lines are continued, this line may end in the middle of a
1726 multi-glyph character (e.g. a control character displayed as
1727 \003, or in the middle of an overlay string). In this case
1728 move_it_to above will not have taken us to the start of
1729 the continuation line but to the end of the continued line. */
1730 if (!it
->truncate_lines_p
)
1732 if (it
->current_x
> 0)
1734 if (it
->current
.dpvec_index
>= 0
1735 || it
->current
.overlay_string_index
>= 0)
1737 set_iterator_to_next (it
, 1);
1738 move_it_in_display_line_to (it
, -1, -1, 0);
1741 it
->continuation_lines_width
+= it
->current_x
;
1744 /* We're starting a new display line, not affected by the
1745 height of the continued line, so clear the appropriate
1746 fields in the iterator structure. */
1747 it
->max_ascent
= it
->max_descent
= 0;
1748 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1751 it
->current_y
= first_y
;
1753 it
->current_x
= it
->hpos
= 0;
1756 #if 0 /* Don't assert the following because start_display is sometimes
1757 called intentionally with a window start that is not at a
1758 line start. Please leave this code in as a comment. */
1760 /* Window start should be on a line start, now. */
1761 xassert (it
->continuation_lines_width
1762 || IT_CHARPOS (it
) == BEGV
1763 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1768 /* Return 1 if POS is a position in ellipses displayed for invisible
1769 text. W is the window we display, for text property lookup. */
1772 in_ellipses_for_invisible_text_p (pos
, w
)
1773 struct display_pos
*pos
;
1776 Lisp_Object prop
, window
;
1778 int charpos
= CHARPOS (pos
->pos
);
1780 /* If POS specifies a position in a display vector, this might
1781 be for an ellipsis displayed for invisible text. We won't
1782 get the iterator set up for delivering that ellipsis unless
1783 we make sure that it gets aware of the invisible text. */
1784 if (pos
->dpvec_index
>= 0
1785 && pos
->overlay_string_index
< 0
1786 && CHARPOS (pos
->string_pos
) < 0
1788 && (XSETWINDOW (window
, w
),
1789 prop
= Fget_char_property (make_number (charpos
),
1790 Qinvisible
, window
),
1791 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1793 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1795 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
1796 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
))
1804 /* Initialize IT for stepping through current_buffer in window W,
1805 starting at position POS that includes overlay string and display
1806 vector/ control character translation position information. */
1809 init_from_display_pos (it
, w
, pos
)
1812 struct display_pos
*pos
;
1814 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1816 /* If POS specifies a position in a display vector, this might
1817 be for an ellipsis displayed for invisible text. We won't
1818 get the iterator set up for delivering that ellipsis unless
1819 we make sure that it gets aware of the invisible text. */
1820 if (in_ellipses_for_invisible_text_p (pos
, w
))
1826 /* Keep in mind: the call to reseat in init_iterator skips invisible
1827 text, so we might end up at a position different from POS. This
1828 is only a problem when POS is a row start after a newline and an
1829 overlay starts there with an after-string, and the overlay has an
1830 invisible property. Since we don't skip invisible text in
1831 display_line and elsewhere immediately after consuming the
1832 newline before the row start, such a POS will not be in a string,
1833 but the call to init_iterator below will move us to the
1835 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1837 /* If position is within an overlay string, set up IT to
1838 the right overlay string. */
1839 if (pos
->overlay_string_index
>= 0)
1843 /* We already have the first chunk of overlay strings in
1844 IT->overlay_strings. Load more until the one for
1845 pos->overlay_string_index is in IT->overlay_strings. */
1846 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1848 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1849 it
->current
.overlay_string_index
= 0;
1852 load_overlay_strings (it
, 0);
1853 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1857 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1858 relative_index
= (it
->current
.overlay_string_index
1859 % OVERLAY_STRING_CHUNK_SIZE
);
1860 it
->string
= it
->overlay_strings
[relative_index
];
1861 xassert (STRINGP (it
->string
));
1862 it
->current
.string_pos
= pos
->string_pos
;
1863 it
->method
= next_element_from_string
;
1865 else if (it
->current
.overlay_string_index
>= 0)
1867 /* If POS says we're already after an overlay string ending at
1868 POS, make sure to pop the iterator because it will be in
1869 front of that overlay string. When POS is ZV, we've thereby
1870 also ``processed'' overlay strings at ZV. */
1873 it
->current
.overlay_string_index
= -1;
1874 it
->method
= next_element_from_buffer
;
1875 if (CHARPOS (pos
->pos
) == ZV
)
1876 it
->overlay_strings_at_end_processed_p
= 1;
1879 if (CHARPOS (pos
->string_pos
) >= 0)
1881 /* Recorded position is not in an overlay string, but in another
1882 string. This can only be a string from a `display' property.
1883 IT should already be filled with that string. */
1884 it
->current
.string_pos
= pos
->string_pos
;
1885 xassert (STRINGP (it
->string
));
1888 /* Restore position in display vector translations, control
1889 character translations or ellipses. */
1890 if (pos
->dpvec_index
>= 0)
1892 if (it
->dpvec
== NULL
)
1893 get_next_display_element (it
);
1894 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1895 it
->current
.dpvec_index
= pos
->dpvec_index
;
1902 /* Initialize IT for stepping through current_buffer in window W
1903 starting at ROW->start. */
1906 init_to_row_start (it
, w
, row
)
1909 struct glyph_row
*row
;
1911 init_from_display_pos (it
, w
, &row
->start
);
1912 it
->continuation_lines_width
= row
->continuation_lines_width
;
1917 /* Initialize IT for stepping through current_buffer in window W
1918 starting in the line following ROW, i.e. starting at ROW->end. */
1921 init_to_row_end (it
, w
, row
)
1924 struct glyph_row
*row
;
1926 init_from_display_pos (it
, w
, &row
->end
);
1928 if (row
->continued_p
)
1929 it
->continuation_lines_width
= (row
->continuation_lines_width
1930 + row
->pixel_width
);
1937 /***********************************************************************
1939 ***********************************************************************/
1941 /* Called when IT reaches IT->stop_charpos. Handle text property and
1942 overlay changes. Set IT->stop_charpos to the next position where
1949 enum prop_handled handled
;
1950 int handle_overlay_change_p
= 1;
1954 it
->current
.dpvec_index
= -1;
1958 handled
= HANDLED_NORMALLY
;
1960 /* Call text property handlers. */
1961 for (p
= it_props
; p
->handler
; ++p
)
1963 handled
= p
->handler (it
);
1965 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1967 else if (handled
== HANDLED_RETURN
)
1969 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1970 handle_overlay_change_p
= 0;
1973 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1975 /* Don't check for overlay strings below when set to deliver
1976 characters from a display vector. */
1977 if (it
->method
== next_element_from_display_vector
)
1978 handle_overlay_change_p
= 0;
1980 /* Handle overlay changes. */
1981 if (handle_overlay_change_p
)
1982 handled
= handle_overlay_change (it
);
1984 /* Determine where to stop next. */
1985 if (handled
== HANDLED_NORMALLY
)
1986 compute_stop_pos (it
);
1989 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1993 /* Compute IT->stop_charpos from text property and overlay change
1994 information for IT's current position. */
1997 compute_stop_pos (it
)
2000 register INTERVAL iv
, next_iv
;
2001 Lisp_Object object
, limit
, position
;
2003 /* If nowhere else, stop at the end. */
2004 it
->stop_charpos
= it
->end_charpos
;
2006 if (STRINGP (it
->string
))
2008 /* Strings are usually short, so don't limit the search for
2010 object
= it
->string
;
2012 position
= make_number (IT_STRING_CHARPOS (*it
));
2018 /* If next overlay change is in front of the current stop pos
2019 (which is IT->end_charpos), stop there. Note: value of
2020 next_overlay_change is point-max if no overlay change
2022 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2023 if (charpos
< it
->stop_charpos
)
2024 it
->stop_charpos
= charpos
;
2026 /* If showing the region, we have to stop at the region
2027 start or end because the face might change there. */
2028 if (it
->region_beg_charpos
> 0)
2030 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2031 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2032 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2033 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2036 /* Set up variables for computing the stop position from text
2037 property changes. */
2038 XSETBUFFER (object
, current_buffer
);
2039 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2040 position
= make_number (IT_CHARPOS (*it
));
2044 /* Get the interval containing IT's position. Value is a null
2045 interval if there isn't such an interval. */
2046 iv
= validate_interval_range (object
, &position
, &position
, 0);
2047 if (!NULL_INTERVAL_P (iv
))
2049 Lisp_Object values_here
[LAST_PROP_IDX
];
2052 /* Get properties here. */
2053 for (p
= it_props
; p
->handler
; ++p
)
2054 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2056 /* Look for an interval following iv that has different
2058 for (next_iv
= next_interval (iv
);
2059 (!NULL_INTERVAL_P (next_iv
)
2061 || XFASTINT (limit
) > next_iv
->position
));
2062 next_iv
= next_interval (next_iv
))
2064 for (p
= it_props
; p
->handler
; ++p
)
2066 Lisp_Object new_value
;
2068 new_value
= textget (next_iv
->plist
, *p
->name
);
2069 if (!EQ (values_here
[p
->idx
], new_value
))
2077 if (!NULL_INTERVAL_P (next_iv
))
2079 if (INTEGERP (limit
)
2080 && next_iv
->position
>= XFASTINT (limit
))
2081 /* No text property change up to limit. */
2082 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2084 /* Text properties change in next_iv. */
2085 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2089 xassert (STRINGP (it
->string
)
2090 || (it
->stop_charpos
>= BEGV
2091 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2095 /* Return the position of the next overlay change after POS in
2096 current_buffer. Value is point-max if no overlay change
2097 follows. This is like `next-overlay-change' but doesn't use
2101 next_overlay_change (pos
)
2106 Lisp_Object
*overlays
;
2110 /* Get all overlays at the given position. */
2112 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2113 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2114 if (noverlays
> len
)
2117 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2118 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2121 /* If any of these overlays ends before endpos,
2122 use its ending point instead. */
2123 for (i
= 0; i
< noverlays
; ++i
)
2128 oend
= OVERLAY_END (overlays
[i
]);
2129 oendpos
= OVERLAY_POSITION (oend
);
2130 endpos
= min (endpos
, oendpos
);
2138 /***********************************************************************
2140 ***********************************************************************/
2142 /* Handle changes in the `fontified' property of the current buffer by
2143 calling hook functions from Qfontification_functions to fontify
2146 static enum prop_handled
2147 handle_fontified_prop (it
)
2150 Lisp_Object prop
, pos
;
2151 enum prop_handled handled
= HANDLED_NORMALLY
;
2153 /* Get the value of the `fontified' property at IT's current buffer
2154 position. (The `fontified' property doesn't have a special
2155 meaning in strings.) If the value is nil, call functions from
2156 Qfontification_functions. */
2157 if (!STRINGP (it
->string
)
2159 && !NILP (Vfontification_functions
)
2160 && !NILP (Vrun_hooks
)
2161 && (pos
= make_number (IT_CHARPOS (*it
)),
2162 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2165 int count
= BINDING_STACK_SIZE ();
2168 val
= Vfontification_functions
;
2169 specbind (Qfontification_functions
, Qnil
);
2170 specbind (Qafter_change_functions
, Qnil
);
2172 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2173 safe_call1 (val
, pos
);
2176 Lisp_Object globals
, fn
;
2177 struct gcpro gcpro1
, gcpro2
;
2180 GCPRO2 (val
, globals
);
2182 for (; CONSP (val
); val
= XCDR (val
))
2188 /* A value of t indicates this hook has a local
2189 binding; it means to run the global binding too.
2190 In a global value, t should not occur. If it
2191 does, we must ignore it to avoid an endless
2193 for (globals
= Fdefault_value (Qfontification_functions
);
2195 globals
= XCDR (globals
))
2197 fn
= XCAR (globals
);
2199 safe_call1 (fn
, pos
);
2203 safe_call1 (fn
, pos
);
2209 unbind_to (count
, Qnil
);
2211 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2212 something. This avoids an endless loop if they failed to
2213 fontify the text for which reason ever. */
2214 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2215 handled
= HANDLED_RECOMPUTE_PROPS
;
2223 /***********************************************************************
2225 ***********************************************************************/
2227 /* Set up iterator IT from face properties at its current position.
2228 Called from handle_stop. */
2230 static enum prop_handled
2231 handle_face_prop (it
)
2234 int new_face_id
, next_stop
;
2236 if (!STRINGP (it
->string
))
2239 = face_at_buffer_position (it
->w
,
2241 it
->region_beg_charpos
,
2242 it
->region_end_charpos
,
2245 + TEXT_PROP_DISTANCE_LIMIT
),
2248 /* Is this a start of a run of characters with box face?
2249 Caveat: this can be called for a freshly initialized
2250 iterator; face_id is -1 is this case. We know that the new
2251 face will not change until limit, i.e. if the new face has a
2252 box, all characters up to limit will have one. But, as
2253 usual, we don't know whether limit is really the end. */
2254 if (new_face_id
!= it
->face_id
)
2256 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2258 /* If new face has a box but old face has not, this is
2259 the start of a run of characters with box, i.e. it has
2260 a shadow on the left side. The value of face_id of the
2261 iterator will be -1 if this is the initial call that gets
2262 the face. In this case, we have to look in front of IT's
2263 position and see whether there is a face != new_face_id. */
2264 it
->start_of_box_run_p
2265 = (new_face
->box
!= FACE_NO_BOX
2266 && (it
->face_id
>= 0
2267 || IT_CHARPOS (*it
) == BEG
2268 || new_face_id
!= face_before_it_pos (it
)));
2269 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2274 int base_face_id
, bufpos
;
2276 if (it
->current
.overlay_string_index
>= 0)
2277 bufpos
= IT_CHARPOS (*it
);
2281 /* For strings from a buffer, i.e. overlay strings or strings
2282 from a `display' property, use the face at IT's current
2283 buffer position as the base face to merge with, so that
2284 overlay strings appear in the same face as surrounding
2285 text, unless they specify their own faces. */
2286 base_face_id
= underlying_face_id (it
);
2288 new_face_id
= face_at_string_position (it
->w
,
2290 IT_STRING_CHARPOS (*it
),
2292 it
->region_beg_charpos
,
2293 it
->region_end_charpos
,
2297 #if 0 /* This shouldn't be neccessary. Let's check it. */
2298 /* If IT is used to display a mode line we would really like to
2299 use the mode line face instead of the frame's default face. */
2300 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2301 && new_face_id
== DEFAULT_FACE_ID
)
2302 new_face_id
= MODE_LINE_FACE_ID
;
2305 /* Is this a start of a run of characters with box? Caveat:
2306 this can be called for a freshly allocated iterator; face_id
2307 is -1 is this case. We know that the new face will not
2308 change until the next check pos, i.e. if the new face has a
2309 box, all characters up to that position will have a
2310 box. But, as usual, we don't know whether that position
2311 is really the end. */
2312 if (new_face_id
!= it
->face_id
)
2314 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2315 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2317 /* If new face has a box but old face hasn't, this is the
2318 start of a run of characters with box, i.e. it has a
2319 shadow on the left side. */
2320 it
->start_of_box_run_p
2321 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2322 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2326 it
->face_id
= new_face_id
;
2327 return HANDLED_NORMALLY
;
2331 /* Return the ID of the face ``underlying'' IT's current position,
2332 which is in a string. If the iterator is associated with a
2333 buffer, return the face at IT's current buffer position.
2334 Otherwise, use the iterator's base_face_id. */
2337 underlying_face_id (it
)
2340 int face_id
= it
->base_face_id
, i
;
2342 xassert (STRINGP (it
->string
));
2344 for (i
= it
->sp
- 1; i
>= 0; --i
)
2345 if (NILP (it
->stack
[i
].string
))
2346 face_id
= it
->stack
[i
].face_id
;
2352 /* Compute the face one character before or after the current position
2353 of IT. BEFORE_P non-zero means get the face in front of IT's
2354 position. Value is the id of the face. */
2357 face_before_or_after_it_pos (it
, before_p
)
2362 int next_check_charpos
;
2363 struct text_pos pos
;
2365 xassert (it
->s
== NULL
);
2367 if (STRINGP (it
->string
))
2369 int bufpos
, base_face_id
;
2371 /* No face change past the end of the string (for the case
2372 we are padding with spaces). No face change before the
2374 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2375 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2378 /* Set pos to the position before or after IT's current position. */
2380 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2382 /* For composition, we must check the character after the
2384 pos
= (it
->what
== IT_COMPOSITION
2385 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2386 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2388 if (it
->current
.overlay_string_index
>= 0)
2389 bufpos
= IT_CHARPOS (*it
);
2393 base_face_id
= underlying_face_id (it
);
2395 /* Get the face for ASCII, or unibyte. */
2396 face_id
= face_at_string_position (it
->w
,
2400 it
->region_beg_charpos
,
2401 it
->region_end_charpos
,
2402 &next_check_charpos
,
2405 /* Correct the face for charsets different from ASCII. Do it
2406 for the multibyte case only. The face returned above is
2407 suitable for unibyte text if IT->string is unibyte. */
2408 if (STRING_MULTIBYTE (it
->string
))
2410 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2411 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2413 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2415 c
= string_char_and_length (p
, rest
, &len
);
2416 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2421 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2422 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2425 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2426 pos
= it
->current
.pos
;
2429 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2432 if (it
->what
== IT_COMPOSITION
)
2433 /* For composition, we must check the position after the
2435 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2437 INC_TEXT_POS (pos
, it
->multibyte_p
);
2440 /* Determine face for CHARSET_ASCII, or unibyte. */
2441 face_id
= face_at_buffer_position (it
->w
,
2443 it
->region_beg_charpos
,
2444 it
->region_end_charpos
,
2445 &next_check_charpos
,
2448 /* Correct the face for charsets different from ASCII. Do it
2449 for the multibyte case only. The face returned above is
2450 suitable for unibyte text if current_buffer is unibyte. */
2451 if (it
->multibyte_p
)
2453 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2454 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2455 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2464 /***********************************************************************
2466 ***********************************************************************/
2468 /* Set up iterator IT from invisible properties at its current
2469 position. Called from handle_stop. */
2471 static enum prop_handled
2472 handle_invisible_prop (it
)
2475 enum prop_handled handled
= HANDLED_NORMALLY
;
2477 if (STRINGP (it
->string
))
2479 extern Lisp_Object Qinvisible
;
2480 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2482 /* Get the value of the invisible text property at the
2483 current position. Value will be nil if there is no such
2485 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2486 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2489 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2491 handled
= HANDLED_RECOMPUTE_PROPS
;
2493 /* Get the position at which the next change of the
2494 invisible text property can be found in IT->string.
2495 Value will be nil if the property value is the same for
2496 all the rest of IT->string. */
2497 XSETINT (limit
, XSTRING (it
->string
)->size
);
2498 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2501 /* Text at current position is invisible. The next
2502 change in the property is at position end_charpos.
2503 Move IT's current position to that position. */
2504 if (INTEGERP (end_charpos
)
2505 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2507 struct text_pos old
;
2508 old
= it
->current
.string_pos
;
2509 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2510 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2514 /* The rest of the string is invisible. If this is an
2515 overlay string, proceed with the next overlay string
2516 or whatever comes and return a character from there. */
2517 if (it
->current
.overlay_string_index
>= 0)
2519 next_overlay_string (it
);
2520 /* Don't check for overlay strings when we just
2521 finished processing them. */
2522 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2526 struct Lisp_String
*s
= XSTRING (it
->string
);
2527 IT_STRING_CHARPOS (*it
) = s
->size
;
2528 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2535 int visible_p
, newpos
, next_stop
, start_charpos
;
2536 Lisp_Object pos
, prop
, overlay
;
2538 /* First of all, is there invisible text at this position? */
2539 start_charpos
= IT_CHARPOS (*it
);
2540 pos
= make_number (IT_CHARPOS (*it
));
2541 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2544 /* If we are on invisible text, skip over it. */
2545 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2546 && IT_CHARPOS (*it
) < it
->end_charpos
)
2548 /* Record whether we have to display an ellipsis for the
2550 int display_ellipsis_p
2551 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2553 handled
= HANDLED_RECOMPUTE_PROPS
;
2555 /* Loop skipping over invisible text. The loop is left at
2556 ZV or with IT on the first char being visible again. */
2559 /* Try to skip some invisible text. Return value is the
2560 position reached which can be equal to IT's position
2561 if there is nothing invisible here. This skips both
2562 over invisible text properties and overlays with
2563 invisible property. */
2564 newpos
= skip_invisible (IT_CHARPOS (*it
),
2565 &next_stop
, ZV
, it
->window
);
2567 /* If we skipped nothing at all we weren't at invisible
2568 text in the first place. If everything to the end of
2569 the buffer was skipped, end the loop. */
2570 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2574 /* We skipped some characters but not necessarily
2575 all there are. Check if we ended up on visible
2576 text. Fget_char_property returns the property of
2577 the char before the given position, i.e. if we
2578 get visible_p = 1, this means that the char at
2579 newpos is visible. */
2580 pos
= make_number (newpos
);
2581 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2582 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2585 /* If we ended up on invisible text, proceed to
2586 skip starting with next_stop. */
2588 IT_CHARPOS (*it
) = next_stop
;
2592 /* The position newpos is now either ZV or on visible text. */
2593 IT_CHARPOS (*it
) = newpos
;
2594 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2596 /* If there are before-strings at the start of invisible
2597 text, and the text is invisible because of a text
2598 property, arrange to show before-strings because 20.x did
2599 it that way. (If the text is invisible because of an
2600 overlay property instead of a text property, this is
2601 already handled in the overlay code.) */
2603 && get_overlay_strings (it
, start_charpos
))
2605 handled
= HANDLED_RECOMPUTE_PROPS
;
2606 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2608 else if (display_ellipsis_p
)
2609 setup_for_ellipsis (it
);
2617 /* Make iterator IT return `...' next. */
2620 setup_for_ellipsis (it
)
2624 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2626 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2627 it
->dpvec
= v
->contents
;
2628 it
->dpend
= v
->contents
+ v
->size
;
2632 /* Default `...'. */
2633 it
->dpvec
= default_invis_vector
;
2634 it
->dpend
= default_invis_vector
+ 3;
2637 /* The ellipsis display does not replace the display of the
2638 character at the new position. Indicate this by setting
2639 IT->dpvec_char_len to zero. */
2640 it
->dpvec_char_len
= 0;
2642 it
->current
.dpvec_index
= 0;
2643 it
->method
= next_element_from_display_vector
;
2648 /***********************************************************************
2650 ***********************************************************************/
2652 /* Set up iterator IT from `display' property at its current position.
2653 Called from handle_stop. */
2655 static enum prop_handled
2656 handle_display_prop (it
)
2659 Lisp_Object prop
, object
;
2660 struct text_pos
*position
;
2661 int display_replaced_p
= 0;
2663 if (STRINGP (it
->string
))
2665 object
= it
->string
;
2666 position
= &it
->current
.string_pos
;
2670 object
= it
->w
->buffer
;
2671 position
= &it
->current
.pos
;
2674 /* Reset those iterator values set from display property values. */
2675 it
->font_height
= Qnil
;
2676 it
->space_width
= Qnil
;
2679 /* We don't support recursive `display' properties, i.e. string
2680 values that have a string `display' property, that have a string
2681 `display' property etc. */
2682 if (!it
->string_from_display_prop_p
)
2683 it
->area
= TEXT_AREA
;
2685 prop
= Fget_char_property (make_number (position
->charpos
),
2688 return HANDLED_NORMALLY
;
2691 /* Simple properties. */
2692 && !EQ (XCAR (prop
), Qimage
)
2693 && !EQ (XCAR (prop
), Qspace
)
2694 && !EQ (XCAR (prop
), Qwhen
)
2695 && !EQ (XCAR (prop
), Qspace_width
)
2696 && !EQ (XCAR (prop
), Qheight
)
2697 && !EQ (XCAR (prop
), Qraise
)
2698 /* Marginal area specifications. */
2699 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2700 && !NILP (XCAR (prop
)))
2702 for (; CONSP (prop
); prop
= XCDR (prop
))
2704 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2705 position
, display_replaced_p
))
2706 display_replaced_p
= 1;
2709 else if (VECTORP (prop
))
2712 for (i
= 0; i
< ASIZE (prop
); ++i
)
2713 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2714 position
, display_replaced_p
))
2715 display_replaced_p
= 1;
2719 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2720 display_replaced_p
= 1;
2723 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2727 /* Value is the position of the end of the `display' property starting
2728 at START_POS in OBJECT. */
2730 static struct text_pos
2731 display_prop_end (it
, object
, start_pos
)
2734 struct text_pos start_pos
;
2737 struct text_pos end_pos
;
2739 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2740 Qdisplay
, object
, Qnil
);
2741 CHARPOS (end_pos
) = XFASTINT (end
);
2742 if (STRINGP (object
))
2743 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2745 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2751 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2752 is the object in which the `display' property was found. *POSITION
2753 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2754 means that we previously saw a display sub-property which already
2755 replaced text display with something else, for example an image;
2756 ignore such properties after the first one has been processed.
2758 If PROP is a `space' or `image' sub-property, set *POSITION to the
2759 end position of the `display' property.
2761 Value is non-zero something was found which replaces the display
2762 of buffer or string text. */
2765 handle_single_display_prop (it
, prop
, object
, position
,
2766 display_replaced_before_p
)
2770 struct text_pos
*position
;
2771 int display_replaced_before_p
;
2774 int replaces_text_display_p
= 0;
2777 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2778 evaluated. If the result is nil, VALUE is ignored. */
2780 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2789 if (!NILP (form
) && !EQ (form
, Qt
))
2791 struct gcpro gcpro1
;
2792 struct text_pos end_pos
, pt
;
2795 end_pos
= display_prop_end (it
, object
, *position
);
2797 /* Temporarily set point to the end position, and then evaluate
2798 the form. This makes `(eolp)' work as FORM. */
2799 if (BUFFERP (object
))
2802 BYTEPOS (pt
) = PT_BYTE
;
2803 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2806 form
= safe_eval (form
);
2808 if (BUFFERP (object
))
2809 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2817 && EQ (XCAR (prop
), Qheight
)
2818 && CONSP (XCDR (prop
)))
2820 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2823 /* `(height HEIGHT)'. */
2824 it
->font_height
= XCAR (XCDR (prop
));
2825 if (!NILP (it
->font_height
))
2827 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2828 int new_height
= -1;
2830 if (CONSP (it
->font_height
)
2831 && (EQ (XCAR (it
->font_height
), Qplus
)
2832 || EQ (XCAR (it
->font_height
), Qminus
))
2833 && CONSP (XCDR (it
->font_height
))
2834 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2836 /* `(+ N)' or `(- N)' where N is an integer. */
2837 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2838 if (EQ (XCAR (it
->font_height
), Qplus
))
2840 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2842 else if (FUNCTIONP (it
->font_height
))
2844 /* Call function with current height as argument.
2845 Value is the new height. */
2847 height
= safe_call1 (it
->font_height
,
2848 face
->lface
[LFACE_HEIGHT_INDEX
]);
2849 if (NUMBERP (height
))
2850 new_height
= XFLOATINT (height
);
2852 else if (NUMBERP (it
->font_height
))
2854 /* Value is a multiple of the canonical char height. */
2857 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2858 new_height
= (XFLOATINT (it
->font_height
)
2859 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2863 /* Evaluate IT->font_height with `height' bound to the
2864 current specified height to get the new height. */
2866 int count
= BINDING_STACK_SIZE ();
2868 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2869 value
= safe_eval (it
->font_height
);
2870 unbind_to (count
, Qnil
);
2872 if (NUMBERP (value
))
2873 new_height
= XFLOATINT (value
);
2877 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2880 else if (CONSP (prop
)
2881 && EQ (XCAR (prop
), Qspace_width
)
2882 && CONSP (XCDR (prop
)))
2884 /* `(space_width WIDTH)'. */
2885 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2888 value
= XCAR (XCDR (prop
));
2889 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2890 it
->space_width
= value
;
2892 else if (CONSP (prop
)
2893 && EQ (XCAR (prop
), Qraise
)
2894 && CONSP (XCDR (prop
)))
2896 /* `(raise FACTOR)'. */
2897 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2900 #ifdef HAVE_WINDOW_SYSTEM
2901 value
= XCAR (XCDR (prop
));
2902 if (NUMBERP (value
))
2904 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2905 it
->voffset
= - (XFLOATINT (value
)
2906 * (FONT_HEIGHT (face
->font
)));
2908 #endif /* HAVE_WINDOW_SYSTEM */
2910 else if (!it
->string_from_display_prop_p
)
2912 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2913 VALUE) or `((margin nil) VALUE)' or VALUE. */
2914 Lisp_Object location
, value
;
2915 struct text_pos start_pos
;
2918 /* Characters having this form of property are not displayed, so
2919 we have to find the end of the property. */
2920 start_pos
= *position
;
2921 *position
= display_prop_end (it
, object
, start_pos
);
2924 /* Let's stop at the new position and assume that all
2925 text properties change there. */
2926 it
->stop_charpos
= position
->charpos
;
2928 location
= Qunbound
;
2929 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2933 value
= XCDR (prop
);
2935 value
= XCAR (value
);
2938 if (EQ (XCAR (tem
), Qmargin
)
2939 && (tem
= XCDR (tem
),
2940 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2942 || EQ (tem
, Qleft_margin
)
2943 || EQ (tem
, Qright_margin
))))
2947 if (EQ (location
, Qunbound
))
2953 #ifdef HAVE_WINDOW_SYSTEM
2954 if (FRAME_TERMCAP_P (it
->f
))
2955 valid_p
= STRINGP (value
);
2957 valid_p
= (STRINGP (value
)
2958 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2959 || valid_image_p (value
));
2960 #else /* not HAVE_WINDOW_SYSTEM */
2961 valid_p
= STRINGP (value
);
2962 #endif /* not HAVE_WINDOW_SYSTEM */
2964 if ((EQ (location
, Qleft_margin
)
2965 || EQ (location
, Qright_margin
)
2968 && !display_replaced_before_p
)
2970 replaces_text_display_p
= 1;
2972 /* Save current settings of IT so that we can restore them
2973 when we are finished with the glyph property value. */
2976 if (NILP (location
))
2977 it
->area
= TEXT_AREA
;
2978 else if (EQ (location
, Qleft_margin
))
2979 it
->area
= LEFT_MARGIN_AREA
;
2981 it
->area
= RIGHT_MARGIN_AREA
;
2983 if (STRINGP (value
))
2986 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2987 it
->current
.overlay_string_index
= -1;
2988 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2989 it
->end_charpos
= it
->string_nchars
2990 = XSTRING (it
->string
)->size
;
2991 it
->method
= next_element_from_string
;
2992 it
->stop_charpos
= 0;
2993 it
->string_from_display_prop_p
= 1;
2994 /* Say that we haven't consumed the characters with
2995 `display' property yet. The call to pop_it in
2996 set_iterator_to_next will clean this up. */
2997 *position
= start_pos
;
2999 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3001 it
->method
= next_element_from_stretch
;
3003 it
->current
.pos
= it
->position
= start_pos
;
3005 #ifdef HAVE_WINDOW_SYSTEM
3008 it
->what
= IT_IMAGE
;
3009 it
->image_id
= lookup_image (it
->f
, value
);
3010 it
->position
= start_pos
;
3011 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3012 it
->method
= next_element_from_image
;
3014 /* Say that we haven't consumed the characters with
3015 `display' property yet. The call to pop_it in
3016 set_iterator_to_next will clean this up. */
3017 *position
= start_pos
;
3019 #endif /* HAVE_WINDOW_SYSTEM */
3022 /* Invalid property or property not supported. Restore
3023 the position to what it was before. */
3024 *position
= start_pos
;
3027 return replaces_text_display_p
;
3031 /* Check if PROP is a display sub-property value whose text should be
3032 treated as intangible. */
3035 single_display_prop_intangible_p (prop
)
3038 /* Skip over `when FORM'. */
3039 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3050 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3051 we don't need to treat text as intangible. */
3052 if (EQ (XCAR (prop
), Qmargin
))
3060 || EQ (XCAR (prop
), Qleft_margin
)
3061 || EQ (XCAR (prop
), Qright_margin
))
3065 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3069 /* Check if PROP is a display property value whose text should be
3070 treated as intangible. */
3073 display_prop_intangible_p (prop
)
3077 && CONSP (XCAR (prop
))
3078 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3080 /* A list of sub-properties. */
3081 while (CONSP (prop
))
3083 if (single_display_prop_intangible_p (XCAR (prop
)))
3088 else if (VECTORP (prop
))
3090 /* A vector of sub-properties. */
3092 for (i
= 0; i
< ASIZE (prop
); ++i
)
3093 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3097 return single_display_prop_intangible_p (prop
);
3103 /* Return 1 if PROP is a display sub-property value containing STRING. */
3106 single_display_prop_string_p (prop
, string
)
3107 Lisp_Object prop
, string
;
3109 extern Lisp_Object Qwhen
, Qmargin
;
3111 if (EQ (string
, prop
))
3114 /* Skip over `when FORM'. */
3115 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3124 /* Skip over `margin LOCATION'. */
3125 if (EQ (XCAR (prop
), Qmargin
))
3136 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3140 /* Return 1 if STRING appears in the `display' property PROP. */
3143 display_prop_string_p (prop
, string
)
3144 Lisp_Object prop
, string
;
3146 extern Lisp_Object Qwhen
, Qmargin
;
3149 && CONSP (XCAR (prop
))
3150 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3152 /* A list of sub-properties. */
3153 while (CONSP (prop
))
3155 if (single_display_prop_string_p (XCAR (prop
), string
))
3160 else if (VECTORP (prop
))
3162 /* A vector of sub-properties. */
3164 for (i
= 0; i
< ASIZE (prop
); ++i
)
3165 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3169 return single_display_prop_string_p (prop
, string
);
3175 /* Determine from which buffer position in W's buffer STRING comes
3176 from. AROUND_CHARPOS is an approximate position where it could
3177 be from. Value is the buffer position or 0 if it couldn't be
3180 W's buffer must be current.
3182 This function is necessary because we don't record buffer positions
3183 in glyphs generated from strings (to keep struct glyph small).
3184 This function may only use code that doesn't eval because it is
3185 called asynchronously from note_mouse_highlight. */
3188 string_buffer_position (w
, string
, around_charpos
)
3193 Lisp_Object around
= make_number (around_charpos
);
3194 Lisp_Object limit
, prop
, pos
;
3195 const int MAX_DISTANCE
= 1000;
3198 pos
= make_number (around_charpos
);
3199 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3200 while (!found
&& !EQ (pos
, limit
))
3202 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3203 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3206 pos
= Fnext_single_property_change (pos
, Qdisplay
, Qnil
, limit
);
3211 pos
= make_number (around_charpos
);
3212 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3213 while (!found
&& !EQ (pos
, limit
))
3215 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3216 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3219 pos
= Fprevious_single_property_change (pos
, Qdisplay
, Qnil
,
3224 return found
? XINT (pos
) : 0;
3229 /***********************************************************************
3230 `composition' property
3231 ***********************************************************************/
3233 /* Set up iterator IT from `composition' property at its current
3234 position. Called from handle_stop. */
3236 static enum prop_handled
3237 handle_composition_prop (it
)
3240 Lisp_Object prop
, string
;
3241 int pos
, pos_byte
, end
;
3242 enum prop_handled handled
= HANDLED_NORMALLY
;
3244 if (STRINGP (it
->string
))
3246 pos
= IT_STRING_CHARPOS (*it
);
3247 pos_byte
= IT_STRING_BYTEPOS (*it
);
3248 string
= it
->string
;
3252 pos
= IT_CHARPOS (*it
);
3253 pos_byte
= IT_BYTEPOS (*it
);
3257 /* If there's a valid composition and point is not inside of the
3258 composition (in the case that the composition is from the current
3259 buffer), draw a glyph composed from the composition components. */
3260 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3261 && COMPOSITION_VALID_P (pos
, end
, prop
)
3262 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3264 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3268 it
->method
= next_element_from_composition
;
3270 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3271 /* For a terminal, draw only the first character of the
3273 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3274 it
->len
= (STRINGP (it
->string
)
3275 ? string_char_to_byte (it
->string
, end
)
3276 : CHAR_TO_BYTE (end
)) - pos_byte
;
3277 it
->stop_charpos
= end
;
3278 handled
= HANDLED_RETURN
;
3287 /***********************************************************************
3289 ***********************************************************************/
3291 /* The following structure is used to record overlay strings for
3292 later sorting in load_overlay_strings. */
3294 struct overlay_entry
3296 Lisp_Object overlay
;
3303 /* Set up iterator IT from overlay strings at its current position.
3304 Called from handle_stop. */
3306 static enum prop_handled
3307 handle_overlay_change (it
)
3310 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3311 return HANDLED_RECOMPUTE_PROPS
;
3313 return HANDLED_NORMALLY
;
3317 /* Set up the next overlay string for delivery by IT, if there is an
3318 overlay string to deliver. Called by set_iterator_to_next when the
3319 end of the current overlay string is reached. If there are more
3320 overlay strings to display, IT->string and
3321 IT->current.overlay_string_index are set appropriately here.
3322 Otherwise IT->string is set to nil. */
3325 next_overlay_string (it
)
3328 ++it
->current
.overlay_string_index
;
3329 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3331 /* No more overlay strings. Restore IT's settings to what
3332 they were before overlay strings were processed, and
3333 continue to deliver from current_buffer. */
3334 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3337 xassert (it
->stop_charpos
>= BEGV
3338 && it
->stop_charpos
<= it
->end_charpos
);
3340 it
->current
.overlay_string_index
= -1;
3341 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3342 it
->n_overlay_strings
= 0;
3343 it
->method
= next_element_from_buffer
;
3345 /* If we're at the end of the buffer, record that we have
3346 processed the overlay strings there already, so that
3347 next_element_from_buffer doesn't try it again. */
3348 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3349 it
->overlay_strings_at_end_processed_p
= 1;
3351 /* If we have to display `...' for invisible text, set
3352 the iterator up for that. */
3353 if (display_ellipsis_p
)
3354 setup_for_ellipsis (it
);
3358 /* There are more overlay strings to process. If
3359 IT->current.overlay_string_index has advanced to a position
3360 where we must load IT->overlay_strings with more strings, do
3362 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3364 if (it
->current
.overlay_string_index
&& i
== 0)
3365 load_overlay_strings (it
, 0);
3367 /* Initialize IT to deliver display elements from the overlay
3369 it
->string
= it
->overlay_strings
[i
];
3370 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3371 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3372 it
->method
= next_element_from_string
;
3373 it
->stop_charpos
= 0;
3380 /* Compare two overlay_entry structures E1 and E2. Used as a
3381 comparison function for qsort in load_overlay_strings. Overlay
3382 strings for the same position are sorted so that
3384 1. All after-strings come in front of before-strings, except
3385 when they come from the same overlay.
3387 2. Within after-strings, strings are sorted so that overlay strings
3388 from overlays with higher priorities come first.
3390 2. Within before-strings, strings are sorted so that overlay
3391 strings from overlays with higher priorities come last.
3393 Value is analogous to strcmp. */
3397 compare_overlay_entries (e1
, e2
)
3400 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3401 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3404 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3406 /* Let after-strings appear in front of before-strings if
3407 they come from different overlays. */
3408 if (EQ (entry1
->overlay
, entry2
->overlay
))
3409 result
= entry1
->after_string_p
? 1 : -1;
3411 result
= entry1
->after_string_p
? -1 : 1;
3413 else if (entry1
->after_string_p
)
3414 /* After-strings sorted in order of decreasing priority. */
3415 result
= entry2
->priority
- entry1
->priority
;
3417 /* Before-strings sorted in order of increasing priority. */
3418 result
= entry1
->priority
- entry2
->priority
;
3424 /* Load the vector IT->overlay_strings with overlay strings from IT's
3425 current buffer position, or from CHARPOS if that is > 0. Set
3426 IT->n_overlays to the total number of overlay strings found.
3428 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3429 a time. On entry into load_overlay_strings,
3430 IT->current.overlay_string_index gives the number of overlay
3431 strings that have already been loaded by previous calls to this
3434 IT->add_overlay_start contains an additional overlay start
3435 position to consider for taking overlay strings from, if non-zero.
3436 This position comes into play when the overlay has an `invisible'
3437 property, and both before and after-strings. When we've skipped to
3438 the end of the overlay, because of its `invisible' property, we
3439 nevertheless want its before-string to appear.
3440 IT->add_overlay_start will contain the overlay start position
3443 Overlay strings are sorted so that after-string strings come in
3444 front of before-string strings. Within before and after-strings,
3445 strings are sorted by overlay priority. See also function
3446 compare_overlay_entries. */
3449 load_overlay_strings (it
, charpos
)
3453 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3454 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3457 int n
= 0, i
, j
, invis_p
;
3458 struct overlay_entry
*entries
3459 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3462 charpos
= IT_CHARPOS (*it
);
3464 /* Append the overlay string STRING of overlay OVERLAY to vector
3465 `entries' which has size `size' and currently contains `n'
3466 elements. AFTER_P non-zero means STRING is an after-string of
3468 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3471 Lisp_Object priority; \
3475 int new_size = 2 * size; \
3476 struct overlay_entry *old = entries; \
3478 (struct overlay_entry *) alloca (new_size \
3479 * sizeof *entries); \
3480 bcopy (old, entries, size * sizeof *entries); \
3484 entries[n].string = (STRING); \
3485 entries[n].overlay = (OVERLAY); \
3486 priority = Foverlay_get ((OVERLAY), Qpriority); \
3487 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3488 entries[n].after_string_p = (AFTER_P); \
3493 /* Process overlay before the overlay center. */
3494 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3496 overlay
= XCAR (ov
);
3497 xassert (OVERLAYP (overlay
));
3498 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3499 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3504 /* Skip this overlay if it doesn't start or end at IT's current
3506 if (end
!= charpos
&& start
!= charpos
)
3509 /* Skip this overlay if it doesn't apply to IT->w. */
3510 window
= Foverlay_get (overlay
, Qwindow
);
3511 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3514 /* If the text ``under'' the overlay is invisible, both before-
3515 and after-strings from this overlay are visible; start and
3516 end position are indistinguishable. */
3517 invisible
= Foverlay_get (overlay
, Qinvisible
);
3518 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3520 /* If overlay has a non-empty before-string, record it. */
3521 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3522 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3523 && XSTRING (str
)->size
)
3524 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3526 /* If overlay has a non-empty after-string, record it. */
3527 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3528 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3529 && XSTRING (str
)->size
)
3530 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3533 /* Process overlays after the overlay center. */
3534 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3536 overlay
= XCAR (ov
);
3537 xassert (OVERLAYP (overlay
));
3538 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3539 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3541 if (start
> charpos
)
3544 /* Skip this overlay if it doesn't start or end at IT's current
3546 if (end
!= charpos
&& start
!= charpos
)
3549 /* Skip this overlay if it doesn't apply to IT->w. */
3550 window
= Foverlay_get (overlay
, Qwindow
);
3551 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3554 /* If the text ``under'' the overlay is invisible, it has a zero
3555 dimension, and both before- and after-strings apply. */
3556 invisible
= Foverlay_get (overlay
, Qinvisible
);
3557 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3559 /* If overlay has a non-empty before-string, record it. */
3560 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3561 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3562 && XSTRING (str
)->size
)
3563 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3565 /* If overlay has a non-empty after-string, record it. */
3566 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3567 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3568 && XSTRING (str
)->size
)
3569 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3572 #undef RECORD_OVERLAY_STRING
3576 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3578 /* Record the total number of strings to process. */
3579 it
->n_overlay_strings
= n
;
3581 /* IT->current.overlay_string_index is the number of overlay strings
3582 that have already been consumed by IT. Copy some of the
3583 remaining overlay strings to IT->overlay_strings. */
3585 j
= it
->current
.overlay_string_index
;
3586 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3587 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3593 /* Get the first chunk of overlay strings at IT's current buffer
3594 position, or at CHARPOS if that is > 0. Value is non-zero if at
3595 least one overlay string was found. */
3598 get_overlay_strings (it
, charpos
)
3602 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3603 process. This fills IT->overlay_strings with strings, and sets
3604 IT->n_overlay_strings to the total number of strings to process.
3605 IT->pos.overlay_string_index has to be set temporarily to zero
3606 because load_overlay_strings needs this; it must be set to -1
3607 when no overlay strings are found because a zero value would
3608 indicate a position in the first overlay string. */
3609 it
->current
.overlay_string_index
= 0;
3610 load_overlay_strings (it
, charpos
);
3612 /* If we found overlay strings, set up IT to deliver display
3613 elements from the first one. Otherwise set up IT to deliver
3614 from current_buffer. */
3615 if (it
->n_overlay_strings
)
3617 /* Make sure we know settings in current_buffer, so that we can
3618 restore meaningful values when we're done with the overlay
3620 compute_stop_pos (it
);
3621 xassert (it
->face_id
>= 0);
3623 /* Save IT's settings. They are restored after all overlay
3624 strings have been processed. */
3625 xassert (it
->sp
== 0);
3628 /* Set up IT to deliver display elements from the first overlay
3630 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3631 it
->string
= it
->overlay_strings
[0];
3632 it
->stop_charpos
= 0;
3633 it
->end_charpos
= XSTRING (it
->string
)->size
;
3634 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3635 xassert (STRINGP (it
->string
));
3636 it
->method
= next_element_from_string
;
3641 it
->current
.overlay_string_index
= -1;
3642 it
->method
= next_element_from_buffer
;
3647 /* Value is non-zero if we found at least one overlay string. */
3648 return STRINGP (it
->string
);
3653 /***********************************************************************
3654 Saving and restoring state
3655 ***********************************************************************/
3657 /* Save current settings of IT on IT->stack. Called, for example,
3658 before setting up IT for an overlay string, to be able to restore
3659 IT's settings to what they were after the overlay string has been
3666 struct iterator_stack_entry
*p
;
3668 xassert (it
->sp
< 2);
3669 p
= it
->stack
+ it
->sp
;
3671 p
->stop_charpos
= it
->stop_charpos
;
3672 xassert (it
->face_id
>= 0);
3673 p
->face_id
= it
->face_id
;
3674 p
->string
= it
->string
;
3675 p
->pos
= it
->current
;
3676 p
->end_charpos
= it
->end_charpos
;
3677 p
->string_nchars
= it
->string_nchars
;
3679 p
->multibyte_p
= it
->multibyte_p
;
3680 p
->space_width
= it
->space_width
;
3681 p
->font_height
= it
->font_height
;
3682 p
->voffset
= it
->voffset
;
3683 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3684 p
->display_ellipsis_p
= 0;
3689 /* Restore IT's settings from IT->stack. Called, for example, when no
3690 more overlay strings must be processed, and we return to delivering
3691 display elements from a buffer, or when the end of a string from a
3692 `display' property is reached and we return to delivering display
3693 elements from an overlay string, or from a buffer. */
3699 struct iterator_stack_entry
*p
;
3701 xassert (it
->sp
> 0);
3703 p
= it
->stack
+ it
->sp
;
3704 it
->stop_charpos
= p
->stop_charpos
;
3705 it
->face_id
= p
->face_id
;
3706 it
->string
= p
->string
;
3707 it
->current
= p
->pos
;
3708 it
->end_charpos
= p
->end_charpos
;
3709 it
->string_nchars
= p
->string_nchars
;
3711 it
->multibyte_p
= p
->multibyte_p
;
3712 it
->space_width
= p
->space_width
;
3713 it
->font_height
= p
->font_height
;
3714 it
->voffset
= p
->voffset
;
3715 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3720 /***********************************************************************
3722 ***********************************************************************/
3724 /* Set IT's current position to the previous line start. */
3727 back_to_previous_line_start (it
)
3730 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3731 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3735 /* Move IT to the next line start.
3737 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3738 we skipped over part of the text (as opposed to moving the iterator
3739 continuously over the text). Otherwise, don't change the value
3742 Newlines may come from buffer text, overlay strings, or strings
3743 displayed via the `display' property. That's the reason we can't
3744 simply use find_next_newline_no_quit.
3746 Note that this function may not skip over invisible text that is so
3747 because of text properties and immediately follows a newline. If
3748 it would, function reseat_at_next_visible_line_start, when called
3749 from set_iterator_to_next, would effectively make invisible
3750 characters following a newline part of the wrong glyph row, which
3751 leads to wrong cursor motion. */
3754 forward_to_next_line_start (it
, skipped_p
)
3758 int old_selective
, newline_found_p
, n
;
3759 const int MAX_NEWLINE_DISTANCE
= 500;
3761 /* If already on a newline, just consume it to avoid unintended
3762 skipping over invisible text below. */
3763 if (it
->what
== IT_CHARACTER
3765 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3767 set_iterator_to_next (it
, 0);
3772 /* Don't handle selective display in the following. It's (a)
3773 unnecessary because it's done by the caller, and (b) leads to an
3774 infinite recursion because next_element_from_ellipsis indirectly
3775 calls this function. */
3776 old_selective
= it
->selective
;
3779 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3780 from buffer text. */
3781 for (n
= newline_found_p
= 0;
3782 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3783 n
+= STRINGP (it
->string
) ? 0 : 1)
3785 if (!get_next_display_element (it
))
3787 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3788 set_iterator_to_next (it
, 0);
3791 /* If we didn't find a newline near enough, see if we can use a
3793 if (n
== MAX_NEWLINE_DISTANCE
)
3795 int start
= IT_CHARPOS (*it
);
3796 int limit
= find_next_newline_no_quit (start
, 1);
3799 xassert (!STRINGP (it
->string
));
3801 /* If there isn't any `display' property in sight, and no
3802 overlays, we can just use the position of the newline in
3804 if (it
->stop_charpos
>= limit
3805 || ((pos
= Fnext_single_property_change (make_number (start
),
3807 Qnil
, make_number (limit
)),
3809 && next_overlay_change (start
) == ZV
))
3811 IT_CHARPOS (*it
) = limit
;
3812 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3813 *skipped_p
= newline_found_p
= 1;
3817 while (get_next_display_element (it
)
3818 && !newline_found_p
)
3820 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3821 set_iterator_to_next (it
, 0);
3826 it
->selective
= old_selective
;
3827 return newline_found_p
;
3831 /* Set IT's current position to the previous visible line start. Skip
3832 invisible text that is so either due to text properties or due to
3833 selective display. Caution: this does not change IT->current_x and
3837 back_to_previous_visible_line_start (it
)
3842 /* Go back one newline if not on BEGV already. */
3843 if (IT_CHARPOS (*it
) > BEGV
)
3844 back_to_previous_line_start (it
);
3846 /* Move over lines that are invisible because of selective display
3847 or text properties. */
3848 while (IT_CHARPOS (*it
) > BEGV
3853 /* If selective > 0, then lines indented more than that values
3855 if (it
->selective
> 0
3856 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3863 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3864 Qinvisible
, it
->window
);
3865 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3869 /* Back one more newline if the current one is invisible. */
3871 back_to_previous_line_start (it
);
3874 xassert (IT_CHARPOS (*it
) >= BEGV
);
3875 xassert (IT_CHARPOS (*it
) == BEGV
3876 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3881 /* Reseat iterator IT at the previous visible line start. Skip
3882 invisible text that is so either due to text properties or due to
3883 selective display. At the end, update IT's overlay information,
3884 face information etc. */
3887 reseat_at_previous_visible_line_start (it
)
3890 back_to_previous_visible_line_start (it
);
3891 reseat (it
, it
->current
.pos
, 1);
3896 /* Reseat iterator IT on the next visible line start in the current
3897 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3898 preceding the line start. Skip over invisible text that is so
3899 because of selective display. Compute faces, overlays etc at the
3900 new position. Note that this function does not skip over text that
3901 is invisible because of text properties. */
3904 reseat_at_next_visible_line_start (it
, on_newline_p
)
3908 int newline_found_p
, skipped_p
= 0;
3910 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3912 /* Skip over lines that are invisible because they are indented
3913 more than the value of IT->selective. */
3914 if (it
->selective
> 0)
3915 while (IT_CHARPOS (*it
) < ZV
3916 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3919 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3920 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3923 /* Position on the newline if that's what's requested. */
3924 if (on_newline_p
&& newline_found_p
)
3926 if (STRINGP (it
->string
))
3928 if (IT_STRING_CHARPOS (*it
) > 0)
3930 --IT_STRING_CHARPOS (*it
);
3931 --IT_STRING_BYTEPOS (*it
);
3934 else if (IT_CHARPOS (*it
) > BEGV
)
3938 reseat (it
, it
->current
.pos
, 0);
3942 reseat (it
, it
->current
.pos
, 0);
3949 /***********************************************************************
3950 Changing an iterator's position
3951 ***********************************************************************/
3953 /* Change IT's current position to POS in current_buffer. If FORCE_P
3954 is non-zero, always check for text properties at the new position.
3955 Otherwise, text properties are only looked up if POS >=
3956 IT->check_charpos of a property. */
3959 reseat (it
, pos
, force_p
)
3961 struct text_pos pos
;
3964 int original_pos
= IT_CHARPOS (*it
);
3966 reseat_1 (it
, pos
, 0);
3968 /* Determine where to check text properties. Avoid doing it
3969 where possible because text property lookup is very expensive. */
3971 || CHARPOS (pos
) > it
->stop_charpos
3972 || CHARPOS (pos
) < original_pos
)
3979 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3980 IT->stop_pos to POS, also. */
3983 reseat_1 (it
, pos
, set_stop_p
)
3985 struct text_pos pos
;
3988 /* Don't call this function when scanning a C string. */
3989 xassert (it
->s
== NULL
);
3991 /* POS must be a reasonable value. */
3992 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3994 it
->current
.pos
= it
->position
= pos
;
3995 XSETBUFFER (it
->object
, current_buffer
);
3996 it
->end_charpos
= ZV
;
3998 it
->current
.dpvec_index
= -1;
3999 it
->current
.overlay_string_index
= -1;
4000 IT_STRING_CHARPOS (*it
) = -1;
4001 IT_STRING_BYTEPOS (*it
) = -1;
4003 it
->method
= next_element_from_buffer
;
4005 it
->face_before_selective_p
= 0;
4008 it
->stop_charpos
= CHARPOS (pos
);
4012 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4013 If S is non-null, it is a C string to iterate over. Otherwise,
4014 STRING gives a Lisp string to iterate over.
4016 If PRECISION > 0, don't return more then PRECISION number of
4017 characters from the string.
4019 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4020 characters have been returned. FIELD_WIDTH < 0 means an infinite
4023 MULTIBYTE = 0 means disable processing of multibyte characters,
4024 MULTIBYTE > 0 means enable it,
4025 MULTIBYTE < 0 means use IT->multibyte_p.
4027 IT must be initialized via a prior call to init_iterator before
4028 calling this function. */
4031 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4036 int precision
, field_width
, multibyte
;
4038 /* No region in strings. */
4039 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4041 /* No text property checks performed by default, but see below. */
4042 it
->stop_charpos
= -1;
4044 /* Set iterator position and end position. */
4045 bzero (&it
->current
, sizeof it
->current
);
4046 it
->current
.overlay_string_index
= -1;
4047 it
->current
.dpvec_index
= -1;
4048 xassert (charpos
>= 0);
4050 /* If STRING is specified, use its multibyteness, otherwise use the
4051 setting of MULTIBYTE, if specified. */
4053 it
->multibyte_p
= multibyte
> 0;
4057 xassert (STRINGP (string
));
4058 it
->string
= string
;
4060 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
4061 it
->method
= next_element_from_string
;
4062 it
->current
.string_pos
= string_pos (charpos
, string
);
4069 /* Note that we use IT->current.pos, not it->current.string_pos,
4070 for displaying C strings. */
4071 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4072 if (it
->multibyte_p
)
4074 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4075 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4079 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4080 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4083 it
->method
= next_element_from_c_string
;
4086 /* PRECISION > 0 means don't return more than PRECISION characters
4088 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4089 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4091 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4092 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4093 FIELD_WIDTH < 0 means infinite field width. This is useful for
4094 padding with `-' at the end of a mode line. */
4095 if (field_width
< 0)
4096 field_width
= INFINITY
;
4097 if (field_width
> it
->end_charpos
- charpos
)
4098 it
->end_charpos
= charpos
+ field_width
;
4100 /* Use the standard display table for displaying strings. */
4101 if (DISP_TABLE_P (Vstandard_display_table
))
4102 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4104 it
->stop_charpos
= charpos
;
4110 /***********************************************************************
4112 ***********************************************************************/
4114 /* Load IT's display element fields with information about the next
4115 display element from the current position of IT. Value is zero if
4116 end of buffer (or C string) is reached. */
4119 get_next_display_element (it
)
4122 /* Non-zero means that we found an display element. Zero means that
4123 we hit the end of what we iterate over. Performance note: the
4124 function pointer `method' used here turns out to be faster than
4125 using a sequence of if-statements. */
4126 int success_p
= (*it
->method
) (it
);
4128 if (it
->what
== IT_CHARACTER
)
4130 /* Map via display table or translate control characters.
4131 IT->c, IT->len etc. have been set to the next character by
4132 the function call above. If we have a display table, and it
4133 contains an entry for IT->c, translate it. Don't do this if
4134 IT->c itself comes from a display table, otherwise we could
4135 end up in an infinite recursion. (An alternative could be to
4136 count the recursion depth of this function and signal an
4137 error when a certain maximum depth is reached.) Is it worth
4139 if (success_p
&& it
->dpvec
== NULL
)
4144 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4147 struct Lisp_Vector
*v
= XVECTOR (dv
);
4149 /* Return the first character from the display table
4150 entry, if not empty. If empty, don't display the
4151 current character. */
4154 it
->dpvec_char_len
= it
->len
;
4155 it
->dpvec
= v
->contents
;
4156 it
->dpend
= v
->contents
+ v
->size
;
4157 it
->current
.dpvec_index
= 0;
4158 it
->method
= next_element_from_display_vector
;
4159 success_p
= get_next_display_element (it
);
4163 set_iterator_to_next (it
, 0);
4164 success_p
= get_next_display_element (it
);
4168 /* Translate control characters into `\003' or `^C' form.
4169 Control characters coming from a display table entry are
4170 currently not translated because we use IT->dpvec to hold
4171 the translation. This could easily be changed but I
4172 don't believe that it is worth doing.
4174 Non-printable multibyte characters are also translated
4176 else if ((it
->c
< ' '
4177 && (it
->area
!= TEXT_AREA
4178 || (it
->c
!= '\n' && it
->c
!= '\t')))
4181 || !CHAR_PRINTABLE_P (it
->c
))
4183 /* IT->c is a control character which must be displayed
4184 either as '\003' or as `^C' where the '\\' and '^'
4185 can be defined in the display table. Fill
4186 IT->ctl_chars with glyphs for what we have to
4187 display. Then, set IT->dpvec to these glyphs. */
4190 if (it
->c
< 128 && it
->ctl_arrow_p
)
4192 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4194 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4195 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4196 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4198 g
= FAST_MAKE_GLYPH ('^', 0);
4199 XSETINT (it
->ctl_chars
[0], g
);
4201 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4202 XSETINT (it
->ctl_chars
[1], g
);
4204 /* Set up IT->dpvec and return first character from it. */
4205 it
->dpvec_char_len
= it
->len
;
4206 it
->dpvec
= it
->ctl_chars
;
4207 it
->dpend
= it
->dpvec
+ 2;
4208 it
->current
.dpvec_index
= 0;
4209 it
->method
= next_element_from_display_vector
;
4210 get_next_display_element (it
);
4214 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4219 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4221 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4222 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4223 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4225 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4227 if (SINGLE_BYTE_CHAR_P (it
->c
))
4228 str
[0] = it
->c
, len
= 1;
4230 len
= CHAR_STRING (it
->c
, str
);
4232 for (i
= 0; i
< len
; i
++)
4234 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4235 /* Insert three more glyphs into IT->ctl_chars for
4236 the octal display of the character. */
4237 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4238 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4239 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4240 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4241 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4242 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4245 /* Set up IT->dpvec and return the first character
4247 it
->dpvec_char_len
= it
->len
;
4248 it
->dpvec
= it
->ctl_chars
;
4249 it
->dpend
= it
->dpvec
+ len
* 4;
4250 it
->current
.dpvec_index
= 0;
4251 it
->method
= next_element_from_display_vector
;
4252 get_next_display_element (it
);
4257 /* Adjust face id for a multibyte character. There are no
4258 multibyte character in unibyte text. */
4261 && FRAME_WINDOW_P (it
->f
))
4263 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4264 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4268 /* Is this character the last one of a run of characters with
4269 box? If yes, set IT->end_of_box_run_p to 1. */
4276 it
->end_of_box_run_p
4277 = ((face_id
= face_after_it_pos (it
),
4278 face_id
!= it
->face_id
)
4279 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4280 face
->box
== FACE_NO_BOX
));
4283 /* Value is 0 if end of buffer or string reached. */
4288 /* Move IT to the next display element.
4290 RESEAT_P non-zero means if called on a newline in buffer text,
4291 skip to the next visible line start.
4293 Functions get_next_display_element and set_iterator_to_next are
4294 separate because I find this arrangement easier to handle than a
4295 get_next_display_element function that also increments IT's
4296 position. The way it is we can first look at an iterator's current
4297 display element, decide whether it fits on a line, and if it does,
4298 increment the iterator position. The other way around we probably
4299 would either need a flag indicating whether the iterator has to be
4300 incremented the next time, or we would have to implement a
4301 decrement position function which would not be easy to write. */
4304 set_iterator_to_next (it
, reseat_p
)
4308 /* Reset flags indicating start and end of a sequence of characters
4309 with box. Reset them at the start of this function because
4310 moving the iterator to a new position might set them. */
4311 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4313 if (it
->method
== next_element_from_buffer
)
4315 /* The current display element of IT is a character from
4316 current_buffer. Advance in the buffer, and maybe skip over
4317 invisible lines that are so because of selective display. */
4318 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4319 reseat_at_next_visible_line_start (it
, 0);
4322 xassert (it
->len
!= 0);
4323 IT_BYTEPOS (*it
) += it
->len
;
4324 IT_CHARPOS (*it
) += 1;
4325 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4328 else if (it
->method
== next_element_from_composition
)
4330 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4331 if (STRINGP (it
->string
))
4333 IT_STRING_BYTEPOS (*it
) += it
->len
;
4334 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4335 it
->method
= next_element_from_string
;
4336 goto consider_string_end
;
4340 IT_BYTEPOS (*it
) += it
->len
;
4341 IT_CHARPOS (*it
) += it
->cmp_len
;
4342 it
->method
= next_element_from_buffer
;
4345 else if (it
->method
== next_element_from_c_string
)
4347 /* Current display element of IT is from a C string. */
4348 IT_BYTEPOS (*it
) += it
->len
;
4349 IT_CHARPOS (*it
) += 1;
4351 else if (it
->method
== next_element_from_display_vector
)
4353 /* Current display element of IT is from a display table entry.
4354 Advance in the display table definition. Reset it to null if
4355 end reached, and continue with characters from buffers/
4357 ++it
->current
.dpvec_index
;
4359 /* Restore face of the iterator to what they were before the
4360 display vector entry (these entries may contain faces). */
4361 it
->face_id
= it
->saved_face_id
;
4363 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4366 it
->method
= next_element_from_c_string
;
4367 else if (STRINGP (it
->string
))
4368 it
->method
= next_element_from_string
;
4370 it
->method
= next_element_from_buffer
;
4373 it
->current
.dpvec_index
= -1;
4375 /* Skip over characters which were displayed via IT->dpvec. */
4376 if (it
->dpvec_char_len
< 0)
4377 reseat_at_next_visible_line_start (it
, 1);
4378 else if (it
->dpvec_char_len
> 0)
4380 it
->len
= it
->dpvec_char_len
;
4381 set_iterator_to_next (it
, reseat_p
);
4385 else if (it
->method
== next_element_from_string
)
4387 /* Current display element is a character from a Lisp string. */
4388 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4389 IT_STRING_BYTEPOS (*it
) += it
->len
;
4390 IT_STRING_CHARPOS (*it
) += 1;
4392 consider_string_end
:
4394 if (it
->current
.overlay_string_index
>= 0)
4396 /* IT->string is an overlay string. Advance to the
4397 next, if there is one. */
4398 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4399 next_overlay_string (it
);
4403 /* IT->string is not an overlay string. If we reached
4404 its end, and there is something on IT->stack, proceed
4405 with what is on the stack. This can be either another
4406 string, this time an overlay string, or a buffer. */
4407 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4411 if (!STRINGP (it
->string
))
4412 it
->method
= next_element_from_buffer
;
4414 goto consider_string_end
;
4418 else if (it
->method
== next_element_from_image
4419 || it
->method
== next_element_from_stretch
)
4421 /* The position etc with which we have to proceed are on
4422 the stack. The position may be at the end of a string,
4423 if the `display' property takes up the whole string. */
4426 if (STRINGP (it
->string
))
4428 it
->method
= next_element_from_string
;
4429 goto consider_string_end
;
4432 it
->method
= next_element_from_buffer
;
4435 /* There are no other methods defined, so this should be a bug. */
4438 xassert (it
->method
!= next_element_from_string
4439 || (STRINGP (it
->string
)
4440 && IT_STRING_CHARPOS (*it
) >= 0));
4444 /* Load IT's display element fields with information about the next
4445 display element which comes from a display table entry or from the
4446 result of translating a control character to one of the forms `^C'
4447 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4450 next_element_from_display_vector (it
)
4454 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4456 /* Remember the current face id in case glyphs specify faces.
4457 IT's face is restored in set_iterator_to_next. */
4458 it
->saved_face_id
= it
->face_id
;
4460 if (INTEGERP (*it
->dpvec
)
4461 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4466 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4467 it
->c
= FAST_GLYPH_CHAR (g
);
4468 it
->len
= CHAR_BYTES (it
->c
);
4470 /* The entry may contain a face id to use. Such a face id is
4471 the id of a Lisp face, not a realized face. A face id of
4472 zero means no face is specified. */
4473 lface_id
= FAST_GLYPH_FACE (g
);
4476 /* The function returns -1 if lface_id is invalid. */
4477 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4479 it
->face_id
= face_id
;
4483 /* Display table entry is invalid. Return a space. */
4484 it
->c
= ' ', it
->len
= 1;
4486 /* Don't change position and object of the iterator here. They are
4487 still the values of the character that had this display table
4488 entry or was translated, and that's what we want. */
4489 it
->what
= IT_CHARACTER
;
4494 /* Load IT with the next display element from Lisp string IT->string.
4495 IT->current.string_pos is the current position within the string.
4496 If IT->current.overlay_string_index >= 0, the Lisp string is an
4500 next_element_from_string (it
)
4503 struct text_pos position
;
4505 xassert (STRINGP (it
->string
));
4506 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4507 position
= it
->current
.string_pos
;
4509 /* Time to check for invisible text? */
4510 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4511 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4515 /* Since a handler may have changed IT->method, we must
4517 return get_next_display_element (it
);
4520 if (it
->current
.overlay_string_index
>= 0)
4522 /* Get the next character from an overlay string. In overlay
4523 strings, There is no field width or padding with spaces to
4525 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4530 else if (STRING_MULTIBYTE (it
->string
))
4532 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4533 - IT_STRING_BYTEPOS (*it
));
4534 unsigned char *s
= (XSTRING (it
->string
)->data
4535 + IT_STRING_BYTEPOS (*it
));
4536 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4540 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4546 /* Get the next character from a Lisp string that is not an
4547 overlay string. Such strings come from the mode line, for
4548 example. We may have to pad with spaces, or truncate the
4549 string. See also next_element_from_c_string. */
4550 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4555 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4557 /* Pad with spaces. */
4558 it
->c
= ' ', it
->len
= 1;
4559 CHARPOS (position
) = BYTEPOS (position
) = -1;
4561 else if (STRING_MULTIBYTE (it
->string
))
4563 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4564 - IT_STRING_BYTEPOS (*it
));
4565 unsigned char *s
= (XSTRING (it
->string
)->data
4566 + IT_STRING_BYTEPOS (*it
));
4567 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4571 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4576 /* Record what we have and where it came from. Note that we store a
4577 buffer position in IT->position although it could arguably be a
4579 it
->what
= IT_CHARACTER
;
4580 it
->object
= it
->string
;
4581 it
->position
= position
;
4586 /* Load IT with next display element from C string IT->s.
4587 IT->string_nchars is the maximum number of characters to return
4588 from the string. IT->end_charpos may be greater than
4589 IT->string_nchars when this function is called, in which case we
4590 may have to return padding spaces. Value is zero if end of string
4591 reached, including padding spaces. */
4594 next_element_from_c_string (it
)
4600 it
->what
= IT_CHARACTER
;
4601 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4604 /* IT's position can be greater IT->string_nchars in case a field
4605 width or precision has been specified when the iterator was
4607 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4609 /* End of the game. */
4613 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4615 /* Pad with spaces. */
4616 it
->c
= ' ', it
->len
= 1;
4617 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4619 else if (it
->multibyte_p
)
4621 /* Implementation note: The calls to strlen apparently aren't a
4622 performance problem because there is no noticeable performance
4623 difference between Emacs running in unibyte or multibyte mode. */
4624 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4625 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4629 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4635 /* Set up IT to return characters from an ellipsis, if appropriate.
4636 The definition of the ellipsis glyphs may come from a display table
4637 entry. This function Fills IT with the first glyph from the
4638 ellipsis if an ellipsis is to be displayed. */
4641 next_element_from_ellipsis (it
)
4644 if (it
->selective_display_ellipsis_p
)
4646 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4648 /* Use the display table definition for `...'. Invalid glyphs
4649 will be handled by the method returning elements from dpvec. */
4650 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4651 it
->dpvec_char_len
= it
->len
;
4652 it
->dpvec
= v
->contents
;
4653 it
->dpend
= v
->contents
+ v
->size
;
4654 it
->current
.dpvec_index
= 0;
4655 it
->method
= next_element_from_display_vector
;
4659 /* Use default `...' which is stored in default_invis_vector. */
4660 it
->dpvec_char_len
= it
->len
;
4661 it
->dpvec
= default_invis_vector
;
4662 it
->dpend
= default_invis_vector
+ 3;
4663 it
->current
.dpvec_index
= 0;
4664 it
->method
= next_element_from_display_vector
;
4669 /* The face at the current position may be different from the
4670 face we find after the invisible text. Remember what it
4671 was in IT->saved_face_id, and signal that it's there by
4672 setting face_before_selective_p. */
4673 it
->saved_face_id
= it
->face_id
;
4674 it
->method
= next_element_from_buffer
;
4675 reseat_at_next_visible_line_start (it
, 1);
4676 it
->face_before_selective_p
= 1;
4679 return get_next_display_element (it
);
4683 /* Deliver an image display element. The iterator IT is already
4684 filled with image information (done in handle_display_prop). Value
4689 next_element_from_image (it
)
4692 it
->what
= IT_IMAGE
;
4697 /* Fill iterator IT with next display element from a stretch glyph
4698 property. IT->object is the value of the text property. Value is
4702 next_element_from_stretch (it
)
4705 it
->what
= IT_STRETCH
;
4710 /* Load IT with the next display element from current_buffer. Value
4711 is zero if end of buffer reached. IT->stop_charpos is the next
4712 position at which to stop and check for text properties or buffer
4716 next_element_from_buffer (it
)
4721 /* Check this assumption, otherwise, we would never enter the
4722 if-statement, below. */
4723 xassert (IT_CHARPOS (*it
) >= BEGV
4724 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4726 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4728 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4730 int overlay_strings_follow_p
;
4732 /* End of the game, except when overlay strings follow that
4733 haven't been returned yet. */
4734 if (it
->overlay_strings_at_end_processed_p
)
4735 overlay_strings_follow_p
= 0;
4738 it
->overlay_strings_at_end_processed_p
= 1;
4739 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4742 if (overlay_strings_follow_p
)
4743 success_p
= get_next_display_element (it
);
4747 it
->position
= it
->current
.pos
;
4754 return get_next_display_element (it
);
4759 /* No face changes, overlays etc. in sight, so just return a
4760 character from current_buffer. */
4763 /* Maybe run the redisplay end trigger hook. Performance note:
4764 This doesn't seem to cost measurable time. */
4765 if (it
->redisplay_end_trigger_charpos
4767 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4768 run_redisplay_end_trigger_hook (it
);
4770 /* Get the next character, maybe multibyte. */
4771 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4772 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4774 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4775 - IT_BYTEPOS (*it
));
4776 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4779 it
->c
= *p
, it
->len
= 1;
4781 /* Record what we have and where it came from. */
4782 it
->what
= IT_CHARACTER
;;
4783 it
->object
= it
->w
->buffer
;
4784 it
->position
= it
->current
.pos
;
4786 /* Normally we return the character found above, except when we
4787 really want to return an ellipsis for selective display. */
4792 /* A value of selective > 0 means hide lines indented more
4793 than that number of columns. */
4794 if (it
->selective
> 0
4795 && IT_CHARPOS (*it
) + 1 < ZV
4796 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4797 IT_BYTEPOS (*it
) + 1,
4800 success_p
= next_element_from_ellipsis (it
);
4801 it
->dpvec_char_len
= -1;
4804 else if (it
->c
== '\r' && it
->selective
== -1)
4806 /* A value of selective == -1 means that everything from the
4807 CR to the end of the line is invisible, with maybe an
4808 ellipsis displayed for it. */
4809 success_p
= next_element_from_ellipsis (it
);
4810 it
->dpvec_char_len
= -1;
4815 /* Value is zero if end of buffer reached. */
4816 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4821 /* Run the redisplay end trigger hook for IT. */
4824 run_redisplay_end_trigger_hook (it
)
4827 Lisp_Object args
[3];
4829 /* IT->glyph_row should be non-null, i.e. we should be actually
4830 displaying something, or otherwise we should not run the hook. */
4831 xassert (it
->glyph_row
);
4833 /* Set up hook arguments. */
4834 args
[0] = Qredisplay_end_trigger_functions
;
4835 args
[1] = it
->window
;
4836 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4837 it
->redisplay_end_trigger_charpos
= 0;
4839 /* Since we are *trying* to run these functions, don't try to run
4840 them again, even if they get an error. */
4841 it
->w
->redisplay_end_trigger
= Qnil
;
4842 Frun_hook_with_args (3, args
);
4844 /* Notice if it changed the face of the character we are on. */
4845 handle_face_prop (it
);
4849 /* Deliver a composition display element. The iterator IT is already
4850 filled with composition information (done in
4851 handle_composition_prop). Value is always 1. */
4854 next_element_from_composition (it
)
4857 it
->what
= IT_COMPOSITION
;
4858 it
->position
= (STRINGP (it
->string
)
4859 ? it
->current
.string_pos
4866 /***********************************************************************
4867 Moving an iterator without producing glyphs
4868 ***********************************************************************/
4870 /* Move iterator IT to a specified buffer or X position within one
4871 line on the display without producing glyphs.
4873 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4874 whichever is reached first.
4876 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4878 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4879 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4880 TO_X includes the amount by which a window is horizontally
4885 MOVE_POS_MATCH_OR_ZV
4886 - when TO_POS or ZV was reached.
4889 -when TO_X was reached before TO_POS or ZV were reached.
4892 - when we reached the end of the display area and the line must
4896 - when we reached the end of the display area and the line is
4900 - when we stopped at a line end, i.e. a newline or a CR and selective
4903 static enum move_it_result
4904 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4906 int to_charpos
, to_x
, op
;
4908 enum move_it_result result
= MOVE_UNDEFINED
;
4909 struct glyph_row
*saved_glyph_row
;
4911 /* Don't produce glyphs in produce_glyphs. */
4912 saved_glyph_row
= it
->glyph_row
;
4913 it
->glyph_row
= NULL
;
4917 int x
, i
, ascent
= 0, descent
= 0;
4919 /* Stop when ZV or TO_CHARPOS reached. */
4920 if (!get_next_display_element (it
)
4921 || ((op
& MOVE_TO_POS
) != 0
4922 && BUFFERP (it
->object
)
4923 && IT_CHARPOS (*it
) >= to_charpos
))
4925 result
= MOVE_POS_MATCH_OR_ZV
;
4929 /* The call to produce_glyphs will get the metrics of the
4930 display element IT is loaded with. We record in x the
4931 x-position before this display element in case it does not
4935 /* Remember the line height so far in case the next element doesn't
4937 if (!it
->truncate_lines_p
)
4939 ascent
= it
->max_ascent
;
4940 descent
= it
->max_descent
;
4943 PRODUCE_GLYPHS (it
);
4945 if (it
->area
!= TEXT_AREA
)
4947 set_iterator_to_next (it
, 1);
4951 /* The number of glyphs we get back in IT->nglyphs will normally
4952 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4953 character on a terminal frame, or (iii) a line end. For the
4954 second case, IT->nglyphs - 1 padding glyphs will be present
4955 (on X frames, there is only one glyph produced for a
4956 composite character.
4958 The behavior implemented below means, for continuation lines,
4959 that as many spaces of a TAB as fit on the current line are
4960 displayed there. For terminal frames, as many glyphs of a
4961 multi-glyph character are displayed in the current line, too.
4962 This is what the old redisplay code did, and we keep it that
4963 way. Under X, the whole shape of a complex character must
4964 fit on the line or it will be completely displayed in the
4967 Note that both for tabs and padding glyphs, all glyphs have
4971 /* More than one glyph or glyph doesn't fit on line. All
4972 glyphs have the same width. */
4973 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4976 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4978 new_x
= x
+ single_glyph_width
;
4980 /* We want to leave anything reaching TO_X to the caller. */
4981 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4984 result
= MOVE_X_REACHED
;
4987 else if (/* Lines are continued. */
4988 !it
->truncate_lines_p
4989 && (/* And glyph doesn't fit on the line. */
4990 new_x
> it
->last_visible_x
4991 /* Or it fits exactly and we're on a window
4993 || (new_x
== it
->last_visible_x
4994 && FRAME_WINDOW_P (it
->f
))))
4996 if (/* IT->hpos == 0 means the very first glyph
4997 doesn't fit on the line, e.g. a wide image. */
4999 || (new_x
== it
->last_visible_x
5000 && FRAME_WINDOW_P (it
->f
)))
5003 it
->current_x
= new_x
;
5004 if (i
== it
->nglyphs
- 1)
5005 set_iterator_to_next (it
, 1);
5010 it
->max_ascent
= ascent
;
5011 it
->max_descent
= descent
;
5014 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5016 result
= MOVE_LINE_CONTINUED
;
5019 else if (new_x
> it
->first_visible_x
)
5021 /* Glyph is visible. Increment number of glyphs that
5022 would be displayed. */
5027 /* Glyph is completely off the left margin of the display
5028 area. Nothing to do. */
5032 if (result
!= MOVE_UNDEFINED
)
5035 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5037 /* Stop when TO_X specified and reached. This check is
5038 necessary here because of lines consisting of a line end,
5039 only. The line end will not produce any glyphs and we
5040 would never get MOVE_X_REACHED. */
5041 xassert (it
->nglyphs
== 0);
5042 result
= MOVE_X_REACHED
;
5046 /* Is this a line end? If yes, we're done. */
5047 if (ITERATOR_AT_END_OF_LINE_P (it
))
5049 result
= MOVE_NEWLINE_OR_CR
;
5053 /* The current display element has been consumed. Advance
5055 set_iterator_to_next (it
, 1);
5057 /* Stop if lines are truncated and IT's current x-position is
5058 past the right edge of the window now. */
5059 if (it
->truncate_lines_p
5060 && it
->current_x
>= it
->last_visible_x
)
5062 result
= MOVE_LINE_TRUNCATED
;
5067 /* Restore the iterator settings altered at the beginning of this
5069 it
->glyph_row
= saved_glyph_row
;
5074 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5075 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5076 the description of enum move_operation_enum.
5078 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5079 screen line, this function will set IT to the next position >
5083 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5085 int to_charpos
, to_x
, to_y
, to_vpos
;
5088 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5094 if (op
& MOVE_TO_VPOS
)
5096 /* If no TO_CHARPOS and no TO_X specified, stop at the
5097 start of the line TO_VPOS. */
5098 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5100 if (it
->vpos
== to_vpos
)
5106 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5110 /* TO_VPOS >= 0 means stop at TO_X in the line at
5111 TO_VPOS, or at TO_POS, whichever comes first. */
5112 if (it
->vpos
== to_vpos
)
5118 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5120 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5125 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5127 /* We have reached TO_X but not in the line we want. */
5128 skip
= move_it_in_display_line_to (it
, to_charpos
,
5130 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5138 else if (op
& MOVE_TO_Y
)
5140 struct it it_backup
;
5142 /* TO_Y specified means stop at TO_X in the line containing
5143 TO_Y---or at TO_CHARPOS if this is reached first. The
5144 problem is that we can't really tell whether the line
5145 contains TO_Y before we have completely scanned it, and
5146 this may skip past TO_X. What we do is to first scan to
5149 If TO_X is not specified, use a TO_X of zero. The reason
5150 is to make the outcome of this function more predictable.
5151 If we didn't use TO_X == 0, we would stop at the end of
5152 the line which is probably not what a caller would expect
5154 skip
= move_it_in_display_line_to (it
, to_charpos
,
5158 | (op
& MOVE_TO_POS
)));
5160 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5161 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5167 /* If TO_X was reached, we would like to know whether TO_Y
5168 is in the line. This can only be said if we know the
5169 total line height which requires us to scan the rest of
5171 if (skip
== MOVE_X_REACHED
)
5174 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5175 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5177 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5180 /* Now, decide whether TO_Y is in this line. */
5181 line_height
= it
->max_ascent
+ it
->max_descent
;
5182 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5184 if (to_y
>= it
->current_y
5185 && to_y
< it
->current_y
+ line_height
)
5187 if (skip
== MOVE_X_REACHED
)
5188 /* If TO_Y is in this line and TO_X was reached above,
5189 we scanned too far. We have to restore IT's settings
5190 to the ones before skipping. */
5194 else if (skip
== MOVE_X_REACHED
)
5197 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5205 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5209 case MOVE_POS_MATCH_OR_ZV
:
5213 case MOVE_NEWLINE_OR_CR
:
5214 set_iterator_to_next (it
, 1);
5215 it
->continuation_lines_width
= 0;
5218 case MOVE_LINE_TRUNCATED
:
5219 it
->continuation_lines_width
= 0;
5220 reseat_at_next_visible_line_start (it
, 0);
5221 if ((op
& MOVE_TO_POS
) != 0
5222 && IT_CHARPOS (*it
) > to_charpos
)
5229 case MOVE_LINE_CONTINUED
:
5230 it
->continuation_lines_width
+= it
->current_x
;
5237 /* Reset/increment for the next run. */
5238 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5239 it
->current_x
= it
->hpos
= 0;
5240 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5242 last_height
= it
->max_ascent
+ it
->max_descent
;
5243 last_max_ascent
= it
->max_ascent
;
5244 it
->max_ascent
= it
->max_descent
= 0;
5249 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5253 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5255 If DY > 0, move IT backward at least that many pixels. DY = 0
5256 means move IT backward to the preceding line start or BEGV. This
5257 function may move over more than DY pixels if IT->current_y - DY
5258 ends up in the middle of a line; in this case IT->current_y will be
5259 set to the top of the line moved to. */
5262 move_it_vertically_backward (it
, dy
)
5266 int nlines
, h
, line_height
;
5268 int start_pos
= IT_CHARPOS (*it
);
5272 /* Estimate how many newlines we must move back. */
5273 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5275 /* Set the iterator's position that many lines back. */
5276 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5277 back_to_previous_visible_line_start (it
);
5279 /* Reseat the iterator here. When moving backward, we don't want
5280 reseat to skip forward over invisible text, set up the iterator
5281 to deliver from overlay strings at the new position etc. So,
5282 use reseat_1 here. */
5283 reseat_1 (it
, it
->current
.pos
, 1);
5285 /* We are now surely at a line start. */
5286 it
->current_x
= it
->hpos
= 0;
5288 /* Move forward and see what y-distance we moved. First move to the
5289 start of the next line so that we get its height. We need this
5290 height to be able to tell whether we reached the specified
5293 it2
.max_ascent
= it2
.max_descent
= 0;
5294 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5295 MOVE_TO_POS
| MOVE_TO_VPOS
);
5296 xassert (IT_CHARPOS (*it
) >= BEGV
);
5297 line_height
= it2
.max_ascent
+ it2
.max_descent
;
5299 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5300 xassert (IT_CHARPOS (*it
) >= BEGV
);
5301 h
= it2
.current_y
- it
->current_y
;
5302 nlines
= it2
.vpos
- it
->vpos
;
5304 /* Correct IT's y and vpos position. */
5310 /* DY == 0 means move to the start of the screen line. The
5311 value of nlines is > 0 if continuation lines were involved. */
5313 move_it_by_lines (it
, nlines
, 1);
5314 xassert (IT_CHARPOS (*it
) <= start_pos
);
5318 /* The y-position we try to reach. Note that h has been
5319 subtracted in front of the if-statement. */
5320 int target_y
= it
->current_y
+ h
- dy
;
5322 /* If we did not reach target_y, try to move further backward if
5323 we can. If we moved too far backward, try to move forward. */
5324 if (target_y
< it
->current_y
5325 && IT_CHARPOS (*it
) > BEGV
)
5327 move_it_vertically (it
, target_y
- it
->current_y
);
5328 xassert (IT_CHARPOS (*it
) >= BEGV
);
5330 else if (target_y
>= it
->current_y
+ line_height
5331 && IT_CHARPOS (*it
) < ZV
)
5333 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5334 xassert (IT_CHARPOS (*it
) >= BEGV
);
5340 /* Move IT by a specified amount of pixel lines DY. DY negative means
5341 move backwards. DY = 0 means move to start of screen line. At the
5342 end, IT will be on the start of a screen line. */
5345 move_it_vertically (it
, dy
)
5350 move_it_vertically_backward (it
, -dy
);
5353 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5354 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5355 MOVE_TO_POS
| MOVE_TO_Y
);
5356 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5358 /* If buffer ends in ZV without a newline, move to the start of
5359 the line to satisfy the post-condition. */
5360 if (IT_CHARPOS (*it
) == ZV
5361 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5362 move_it_by_lines (it
, 0, 0);
5367 /* Move iterator IT past the end of the text line it is in. */
5370 move_it_past_eol (it
)
5373 enum move_it_result rc
;
5375 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5376 if (rc
== MOVE_NEWLINE_OR_CR
)
5377 set_iterator_to_next (it
, 0);
5381 #if 0 /* Currently not used. */
5383 /* Return non-zero if some text between buffer positions START_CHARPOS
5384 and END_CHARPOS is invisible. IT->window is the window for text
5388 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5390 int start_charpos
, end_charpos
;
5392 Lisp_Object prop
, limit
;
5393 int invisible_found_p
;
5395 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5397 /* Is text at START invisible? */
5398 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5400 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5401 invisible_found_p
= 1;
5404 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5406 make_number (end_charpos
));
5407 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5410 return invisible_found_p
;
5416 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5417 negative means move up. DVPOS == 0 means move to the start of the
5418 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5419 NEED_Y_P is zero, IT->current_y will be left unchanged.
5421 Further optimization ideas: If we would know that IT->f doesn't use
5422 a face with proportional font, we could be faster for
5423 truncate-lines nil. */
5426 move_it_by_lines (it
, dvpos
, need_y_p
)
5428 int dvpos
, need_y_p
;
5430 struct position pos
;
5432 if (!FRAME_WINDOW_P (it
->f
))
5434 struct text_pos textpos
;
5436 /* We can use vmotion on frames without proportional fonts. */
5437 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5438 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5439 reseat (it
, textpos
, 1);
5440 it
->vpos
+= pos
.vpos
;
5441 it
->current_y
+= pos
.vpos
;
5443 else if (dvpos
== 0)
5445 /* DVPOS == 0 means move to the start of the screen line. */
5446 move_it_vertically_backward (it
, 0);
5447 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5450 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5454 int start_charpos
, i
;
5456 /* Go back -DVPOS visible lines and reseat the iterator there. */
5457 start_charpos
= IT_CHARPOS (*it
);
5458 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5459 back_to_previous_visible_line_start (it
);
5460 reseat (it
, it
->current
.pos
, 1);
5461 it
->current_x
= it
->hpos
= 0;
5463 /* Above call may have moved too far if continuation lines
5464 are involved. Scan forward and see if it did. */
5466 it2
.vpos
= it2
.current_y
= 0;
5467 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5468 it
->vpos
-= it2
.vpos
;
5469 it
->current_y
-= it2
.current_y
;
5470 it
->current_x
= it
->hpos
= 0;
5472 /* If we moved too far, move IT some lines forward. */
5473 if (it2
.vpos
> -dvpos
)
5475 int delta
= it2
.vpos
+ dvpos
;
5476 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5483 /***********************************************************************
5485 ***********************************************************************/
5488 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5492 add_to_log (format
, arg1
, arg2
)
5494 Lisp_Object arg1
, arg2
;
5496 Lisp_Object args
[3];
5497 Lisp_Object msg
, fmt
;
5500 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5503 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5505 args
[0] = fmt
= build_string (format
);
5508 msg
= Fformat (3, args
);
5510 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5511 buffer
= (char *) alloca (len
);
5512 strcpy (buffer
, XSTRING (msg
)->data
);
5514 message_dolog (buffer
, len
- 1, 1, 0);
5519 /* Output a newline in the *Messages* buffer if "needs" one. */
5522 message_log_maybe_newline ()
5524 if (message_log_need_newline
)
5525 message_dolog ("", 0, 1, 0);
5529 /* Add a string M of length NBYTES to the message log, optionally
5530 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5531 nonzero, means interpret the contents of M as multibyte. This
5532 function calls low-level routines in order to bypass text property
5533 hooks, etc. which might not be safe to run. */
5536 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5538 int nbytes
, nlflag
, multibyte
;
5540 if (!NILP (Vmessage_log_max
))
5542 struct buffer
*oldbuf
;
5543 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5544 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5545 int point_at_end
= 0;
5547 Lisp_Object old_deactivate_mark
, tem
;
5548 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5550 old_deactivate_mark
= Vdeactivate_mark
;
5551 oldbuf
= current_buffer
;
5552 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5553 current_buffer
->undo_list
= Qt
;
5555 oldpoint
= Fpoint_marker ();
5556 oldbegv
= Fpoint_min_marker ();
5557 oldzv
= Fpoint_max_marker ();
5558 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5566 BEGV_BYTE
= BEG_BYTE
;
5569 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5571 /* Insert the string--maybe converting multibyte to single byte
5572 or vice versa, so that all the text fits the buffer. */
5574 && NILP (current_buffer
->enable_multibyte_characters
))
5576 int i
, c
, char_bytes
;
5577 unsigned char work
[1];
5579 /* Convert a multibyte string to single-byte
5580 for the *Message* buffer. */
5581 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5583 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5584 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5586 : multibyte_char_to_unibyte (c
, Qnil
));
5587 insert_1_both (work
, 1, 1, 1, 0, 0);
5590 else if (! multibyte
5591 && ! NILP (current_buffer
->enable_multibyte_characters
))
5593 int i
, c
, char_bytes
;
5594 unsigned char *msg
= (unsigned char *) m
;
5595 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5596 /* Convert a single-byte string to multibyte
5597 for the *Message* buffer. */
5598 for (i
= 0; i
< nbytes
; i
++)
5600 c
= unibyte_char_to_multibyte (msg
[i
]);
5601 char_bytes
= CHAR_STRING (c
, str
);
5602 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5606 insert_1 (m
, nbytes
, 1, 0, 0);
5610 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5611 insert_1 ("\n", 1, 1, 0, 0);
5613 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5615 this_bol_byte
= PT_BYTE
;
5619 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5621 prev_bol_byte
= PT_BYTE
;
5623 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5624 this_bol
, this_bol_byte
);
5627 del_range_both (prev_bol
, prev_bol_byte
,
5628 this_bol
, this_bol_byte
, 0);
5634 /* If you change this format, don't forget to also
5635 change message_log_check_duplicate. */
5636 sprintf (dupstr
, " [%d times]", dup
);
5637 duplen
= strlen (dupstr
);
5638 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5639 insert_1 (dupstr
, duplen
, 1, 0, 1);
5644 if (NATNUMP (Vmessage_log_max
))
5646 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5647 -XFASTINT (Vmessage_log_max
) - 1, 0);
5648 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5651 BEGV
= XMARKER (oldbegv
)->charpos
;
5652 BEGV_BYTE
= marker_byte_position (oldbegv
);
5661 ZV
= XMARKER (oldzv
)->charpos
;
5662 ZV_BYTE
= marker_byte_position (oldzv
);
5666 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5668 /* We can't do Fgoto_char (oldpoint) because it will run some
5670 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5671 XMARKER (oldpoint
)->bytepos
);
5674 free_marker (oldpoint
);
5675 free_marker (oldbegv
);
5676 free_marker (oldzv
);
5678 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5679 set_buffer_internal (oldbuf
);
5681 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5682 message_log_need_newline
= !nlflag
;
5683 Vdeactivate_mark
= old_deactivate_mark
;
5688 /* We are at the end of the buffer after just having inserted a newline.
5689 (Note: We depend on the fact we won't be crossing the gap.)
5690 Check to see if the most recent message looks a lot like the previous one.
5691 Return 0 if different, 1 if the new one should just replace it, or a
5692 value N > 1 if we should also append " [N times]". */
5695 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5696 int prev_bol
, this_bol
;
5697 int prev_bol_byte
, this_bol_byte
;
5700 int len
= Z_BYTE
- 1 - this_bol_byte
;
5702 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5703 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5705 for (i
= 0; i
< len
; i
++)
5707 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5715 if (*p1
++ == ' ' && *p1
++ == '[')
5718 while (*p1
>= '0' && *p1
<= '9')
5719 n
= n
* 10 + *p1
++ - '0';
5720 if (strncmp (p1
, " times]\n", 8) == 0)
5727 /* Display an echo area message M with a specified length of NBYTES
5728 bytes. The string may include null characters. If M is 0, clear
5729 out any existing message, and let the mini-buffer text show
5732 The buffer M must continue to exist until after the echo area gets
5733 cleared or some other message gets displayed there. This means do
5734 not pass text that is stored in a Lisp string; do not pass text in
5735 a buffer that was alloca'd. */
5738 message2 (m
, nbytes
, multibyte
)
5743 /* First flush out any partial line written with print. */
5744 message_log_maybe_newline ();
5746 message_dolog (m
, nbytes
, 1, multibyte
);
5747 message2_nolog (m
, nbytes
, multibyte
);
5751 /* The non-logging counterpart of message2. */
5754 message2_nolog (m
, nbytes
, multibyte
)
5758 struct frame
*sf
= SELECTED_FRAME ();
5759 message_enable_multibyte
= multibyte
;
5763 if (noninteractive_need_newline
)
5764 putc ('\n', stderr
);
5765 noninteractive_need_newline
= 0;
5767 fwrite (m
, nbytes
, 1, stderr
);
5768 if (cursor_in_echo_area
== 0)
5769 fprintf (stderr
, "\n");
5772 /* A null message buffer means that the frame hasn't really been
5773 initialized yet. Error messages get reported properly by
5774 cmd_error, so this must be just an informative message; toss it. */
5775 else if (INTERACTIVE
5776 && sf
->glyphs_initialized_p
5777 && FRAME_MESSAGE_BUF (sf
))
5779 Lisp_Object mini_window
;
5782 /* Get the frame containing the mini-buffer
5783 that the selected frame is using. */
5784 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5785 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5787 FRAME_SAMPLE_VISIBILITY (f
);
5788 if (FRAME_VISIBLE_P (sf
)
5789 && ! FRAME_VISIBLE_P (f
))
5790 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5794 set_message (m
, Qnil
, nbytes
, multibyte
);
5795 if (minibuffer_auto_raise
)
5796 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5799 clear_message (1, 1);
5801 do_pending_window_change (0);
5802 echo_area_display (1);
5803 do_pending_window_change (0);
5804 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5805 (*frame_up_to_date_hook
) (f
);
5810 /* Display an echo area message M with a specified length of NBYTES
5811 bytes. The string may include null characters. If M is not a
5812 string, clear out any existing message, and let the mini-buffer
5813 text show through. */
5816 message3 (m
, nbytes
, multibyte
)
5821 struct gcpro gcpro1
;
5825 /* First flush out any partial line written with print. */
5826 message_log_maybe_newline ();
5828 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5829 message3_nolog (m
, nbytes
, multibyte
);
5835 /* The non-logging version of message3. */
5838 message3_nolog (m
, nbytes
, multibyte
)
5840 int nbytes
, multibyte
;
5842 struct frame
*sf
= SELECTED_FRAME ();
5843 message_enable_multibyte
= multibyte
;
5847 if (noninteractive_need_newline
)
5848 putc ('\n', stderr
);
5849 noninteractive_need_newline
= 0;
5851 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5852 if (cursor_in_echo_area
== 0)
5853 fprintf (stderr
, "\n");
5856 /* A null message buffer means that the frame hasn't really been
5857 initialized yet. Error messages get reported properly by
5858 cmd_error, so this must be just an informative message; toss it. */
5859 else if (INTERACTIVE
5860 && sf
->glyphs_initialized_p
5861 && FRAME_MESSAGE_BUF (sf
))
5863 Lisp_Object mini_window
;
5867 /* Get the frame containing the mini-buffer
5868 that the selected frame is using. */
5869 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5870 frame
= XWINDOW (mini_window
)->frame
;
5873 FRAME_SAMPLE_VISIBILITY (f
);
5874 if (FRAME_VISIBLE_P (sf
)
5875 && !FRAME_VISIBLE_P (f
))
5876 Fmake_frame_visible (frame
);
5878 if (STRINGP (m
) && XSTRING (m
)->size
)
5880 set_message (NULL
, m
, nbytes
, multibyte
);
5881 if (minibuffer_auto_raise
)
5882 Fraise_frame (frame
);
5885 clear_message (1, 1);
5887 do_pending_window_change (0);
5888 echo_area_display (1);
5889 do_pending_window_change (0);
5890 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5891 (*frame_up_to_date_hook
) (f
);
5896 /* Display a null-terminated echo area message M. If M is 0, clear
5897 out any existing message, and let the mini-buffer text show through.
5899 The buffer M must continue to exist until after the echo area gets
5900 cleared or some other message gets displayed there. Do not pass
5901 text that is stored in a Lisp string. Do not pass text in a buffer
5902 that was alloca'd. */
5908 message2 (m
, (m
? strlen (m
) : 0), 0);
5912 /* The non-logging counterpart of message1. */
5918 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5921 /* Display a message M which contains a single %s
5922 which gets replaced with STRING. */
5925 message_with_string (m
, string
, log
)
5934 if (noninteractive_need_newline
)
5935 putc ('\n', stderr
);
5936 noninteractive_need_newline
= 0;
5937 fprintf (stderr
, m
, XSTRING (string
)->data
);
5938 if (cursor_in_echo_area
== 0)
5939 fprintf (stderr
, "\n");
5943 else if (INTERACTIVE
)
5945 /* The frame whose minibuffer we're going to display the message on.
5946 It may be larger than the selected frame, so we need
5947 to use its buffer, not the selected frame's buffer. */
5948 Lisp_Object mini_window
;
5949 struct frame
*f
, *sf
= SELECTED_FRAME ();
5951 /* Get the frame containing the minibuffer
5952 that the selected frame is using. */
5953 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5954 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5956 /* A null message buffer means that the frame hasn't really been
5957 initialized yet. Error messages get reported properly by
5958 cmd_error, so this must be just an informative message; toss it. */
5959 if (FRAME_MESSAGE_BUF (f
))
5963 a
[0] = (char *) XSTRING (string
)->data
;
5965 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5966 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5969 message2 (FRAME_MESSAGE_BUF (f
), len
,
5970 STRING_MULTIBYTE (string
));
5972 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5973 STRING_MULTIBYTE (string
));
5975 /* Print should start at the beginning of the message
5976 buffer next time. */
5977 message_buf_print
= 0;
5983 /* Dump an informative message to the minibuf. If M is 0, clear out
5984 any existing message, and let the mini-buffer text show through. */
5988 message (m
, a1
, a2
, a3
)
5990 EMACS_INT a1
, a2
, a3
;
5996 if (noninteractive_need_newline
)
5997 putc ('\n', stderr
);
5998 noninteractive_need_newline
= 0;
5999 fprintf (stderr
, m
, a1
, a2
, a3
);
6000 if (cursor_in_echo_area
== 0)
6001 fprintf (stderr
, "\n");
6005 else if (INTERACTIVE
)
6007 /* The frame whose mini-buffer we're going to display the message
6008 on. It may be larger than the selected frame, so we need to
6009 use its buffer, not the selected frame's buffer. */
6010 Lisp_Object mini_window
;
6011 struct frame
*f
, *sf
= SELECTED_FRAME ();
6013 /* Get the frame containing the mini-buffer
6014 that the selected frame is using. */
6015 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6016 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6018 /* A null message buffer means that the frame hasn't really been
6019 initialized yet. Error messages get reported properly by
6020 cmd_error, so this must be just an informative message; toss
6022 if (FRAME_MESSAGE_BUF (f
))
6033 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6034 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6036 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6037 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6039 #endif /* NO_ARG_ARRAY */
6041 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6046 /* Print should start at the beginning of the message
6047 buffer next time. */
6048 message_buf_print
= 0;
6054 /* The non-logging version of message. */
6057 message_nolog (m
, a1
, a2
, a3
)
6059 EMACS_INT a1
, a2
, a3
;
6061 Lisp_Object old_log_max
;
6062 old_log_max
= Vmessage_log_max
;
6063 Vmessage_log_max
= Qnil
;
6064 message (m
, a1
, a2
, a3
);
6065 Vmessage_log_max
= old_log_max
;
6069 /* Display the current message in the current mini-buffer. This is
6070 only called from error handlers in process.c, and is not time
6076 if (!NILP (echo_area_buffer
[0]))
6079 string
= Fcurrent_message ();
6080 message3 (string
, XSTRING (string
)->size
,
6081 !NILP (current_buffer
->enable_multibyte_characters
));
6086 /* Make sure echo area buffers in echo_buffers[] are life. If they
6087 aren't, make new ones. */
6090 ensure_echo_area_buffers ()
6094 for (i
= 0; i
< 2; ++i
)
6095 if (!BUFFERP (echo_buffer
[i
])
6096 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6099 Lisp_Object old_buffer
;
6102 old_buffer
= echo_buffer
[i
];
6103 sprintf (name
, " *Echo Area %d*", i
);
6104 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6105 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6107 for (j
= 0; j
< 2; ++j
)
6108 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6109 echo_area_buffer
[j
] = echo_buffer
[i
];
6114 /* Call FN with args A1..A4 with either the current or last displayed
6115 echo_area_buffer as current buffer.
6117 WHICH zero means use the current message buffer
6118 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6119 from echo_buffer[] and clear it.
6121 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6122 suitable buffer from echo_buffer[] and clear it.
6124 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6125 that the current message becomes the last displayed one, make
6126 choose a suitable buffer for echo_area_buffer[0], and clear it.
6128 Value is what FN returns. */
6131 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6134 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6140 int this_one
, the_other
, clear_buffer_p
, rc
;
6141 int count
= BINDING_STACK_SIZE ();
6143 /* If buffers aren't life, make new ones. */
6144 ensure_echo_area_buffers ();
6149 this_one
= 0, the_other
= 1;
6151 this_one
= 1, the_other
= 0;
6154 this_one
= 0, the_other
= 1;
6157 /* We need a fresh one in case the current echo buffer equals
6158 the one containing the last displayed echo area message. */
6159 if (!NILP (echo_area_buffer
[this_one
])
6160 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6161 echo_area_buffer
[this_one
] = Qnil
;
6164 /* Choose a suitable buffer from echo_buffer[] is we don't
6166 if (NILP (echo_area_buffer
[this_one
]))
6168 echo_area_buffer
[this_one
]
6169 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6170 ? echo_buffer
[the_other
]
6171 : echo_buffer
[this_one
]);
6175 buffer
= echo_area_buffer
[this_one
];
6177 /* Don't get confused by reusing the buffer used for echoing
6178 for a different purpose. */
6179 if (!echoing
&& EQ (buffer
, echo_message_buffer
))
6182 record_unwind_protect (unwind_with_echo_area_buffer
,
6183 with_echo_area_buffer_unwind_data (w
));
6185 /* Make the echo area buffer current. Note that for display
6186 purposes, it is not necessary that the displayed window's buffer
6187 == current_buffer, except for text property lookup. So, let's
6188 only set that buffer temporarily here without doing a full
6189 Fset_window_buffer. We must also change w->pointm, though,
6190 because otherwise an assertions in unshow_buffer fails, and Emacs
6192 set_buffer_internal_1 (XBUFFER (buffer
));
6196 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6199 current_buffer
->undo_list
= Qt
;
6200 current_buffer
->read_only
= Qnil
;
6201 specbind (Qinhibit_read_only
, Qt
);
6203 if (clear_buffer_p
&& Z
> BEG
)
6206 xassert (BEGV
>= BEG
);
6207 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6209 rc
= fn (a1
, a2
, a3
, a4
);
6211 xassert (BEGV
>= BEG
);
6212 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6214 unbind_to (count
, Qnil
);
6219 /* Save state that should be preserved around the call to the function
6220 FN called in with_echo_area_buffer. */
6223 with_echo_area_buffer_unwind_data (w
)
6229 /* Reduce consing by keeping one vector in
6230 Vwith_echo_area_save_vector. */
6231 vector
= Vwith_echo_area_save_vector
;
6232 Vwith_echo_area_save_vector
= Qnil
;
6235 vector
= Fmake_vector (make_number (7), Qnil
);
6237 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6238 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6239 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6243 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6244 AREF (vector
, i
) = w
->buffer
; ++i
;
6245 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6246 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6251 for (; i
< end
; ++i
)
6252 AREF (vector
, i
) = Qnil
;
6255 xassert (i
== ASIZE (vector
));
6260 /* Restore global state from VECTOR which was created by
6261 with_echo_area_buffer_unwind_data. */
6264 unwind_with_echo_area_buffer (vector
)
6267 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6268 Vdeactivate_mark
= AREF (vector
, 1);
6269 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6271 if (WINDOWP (AREF (vector
, 3)))
6274 Lisp_Object buffer
, charpos
, bytepos
;
6276 w
= XWINDOW (AREF (vector
, 3));
6277 buffer
= AREF (vector
, 4);
6278 charpos
= AREF (vector
, 5);
6279 bytepos
= AREF (vector
, 6);
6282 set_marker_both (w
->pointm
, buffer
,
6283 XFASTINT (charpos
), XFASTINT (bytepos
));
6286 Vwith_echo_area_save_vector
= vector
;
6291 /* Set up the echo area for use by print functions. MULTIBYTE_P
6292 non-zero means we will print multibyte. */
6295 setup_echo_area_for_printing (multibyte_p
)
6298 ensure_echo_area_buffers ();
6300 if (!message_buf_print
)
6302 /* A message has been output since the last time we printed.
6303 Choose a fresh echo area buffer. */
6304 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6305 echo_area_buffer
[0] = echo_buffer
[1];
6307 echo_area_buffer
[0] = echo_buffer
[0];
6309 /* Switch to that buffer and clear it. */
6310 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6311 current_buffer
->truncate_lines
= Qnil
;
6315 int count
= BINDING_STACK_SIZE ();
6316 specbind (Qinhibit_read_only
, Qt
);
6318 unbind_to (count
, Qnil
);
6320 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6322 /* Set up the buffer for the multibyteness we need. */
6324 != !NILP (current_buffer
->enable_multibyte_characters
))
6325 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6327 /* Raise the frame containing the echo area. */
6328 if (minibuffer_auto_raise
)
6330 struct frame
*sf
= SELECTED_FRAME ();
6331 Lisp_Object mini_window
;
6332 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6333 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6336 message_log_maybe_newline ();
6337 message_buf_print
= 1;
6341 if (NILP (echo_area_buffer
[0]))
6343 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6344 echo_area_buffer
[0] = echo_buffer
[1];
6346 echo_area_buffer
[0] = echo_buffer
[0];
6349 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6351 /* Someone switched buffers between print requests. */
6352 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6353 current_buffer
->truncate_lines
= Qnil
;
6359 /* Display an echo area message in window W. Value is non-zero if W's
6360 height is changed. If display_last_displayed_message_p is
6361 non-zero, display the message that was last displayed, otherwise
6362 display the current message. */
6365 display_echo_area (w
)
6368 int i
, no_message_p
, window_height_changed_p
, count
;
6370 /* Temporarily disable garbage collections while displaying the echo
6371 area. This is done because a GC can print a message itself.
6372 That message would modify the echo area buffer's contents while a
6373 redisplay of the buffer is going on, and seriously confuse
6375 count
= inhibit_garbage_collection ();
6377 /* If there is no message, we must call display_echo_area_1
6378 nevertheless because it resizes the window. But we will have to
6379 reset the echo_area_buffer in question to nil at the end because
6380 with_echo_area_buffer will sets it to an empty buffer. */
6381 i
= display_last_displayed_message_p
? 1 : 0;
6382 no_message_p
= NILP (echo_area_buffer
[i
]);
6384 window_height_changed_p
6385 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6386 display_echo_area_1
,
6387 (EMACS_INT
) w
, Qnil
, 0, 0);
6390 echo_area_buffer
[i
] = Qnil
;
6392 unbind_to (count
, Qnil
);
6393 return window_height_changed_p
;
6397 /* Helper for display_echo_area. Display the current buffer which
6398 contains the current echo area message in window W, a mini-window,
6399 a pointer to which is passed in A1. A2..A4 are currently not used.
6400 Change the height of W so that all of the message is displayed.
6401 Value is non-zero if height of W was changed. */
6404 display_echo_area_1 (a1
, a2
, a3
, a4
)
6409 struct window
*w
= (struct window
*) a1
;
6411 struct text_pos start
;
6412 int window_height_changed_p
= 0;
6414 /* Do this before displaying, so that we have a large enough glyph
6415 matrix for the display. */
6416 window_height_changed_p
= resize_mini_window (w
, 0);
6419 clear_glyph_matrix (w
->desired_matrix
);
6420 XSETWINDOW (window
, w
);
6421 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6422 try_window (window
, start
);
6424 return window_height_changed_p
;
6428 /* Resize the echo area window to exactly the size needed for the
6429 currently displayed message, if there is one. */
6432 resize_echo_area_axactly ()
6434 if (BUFFERP (echo_area_buffer
[0])
6435 && WINDOWP (echo_area_window
))
6437 struct window
*w
= XWINDOW (echo_area_window
);
6440 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6441 (EMACS_INT
) w
, Qnil
, 0, 0);
6444 ++windows_or_buffers_changed
;
6445 ++update_mode_lines
;
6446 redisplay_internal (0);
6452 /* Callback function for with_echo_area_buffer, when used from
6453 resize_echo_area_axactly. A1 contains a pointer to the window to
6454 resize, A2 to A4 are not used. Value is what resize_mini_window
6458 resize_mini_window_1 (a1
, a2
, a3
, a4
)
6463 return resize_mini_window ((struct window
*) a1
, 1);
6467 /* Resize mini-window W to fit the size of its contents. EXACT:P
6468 means size the window exactly to the size needed. Otherwise, it's
6469 only enlarged until W's buffer is empty. Value is non-zero if
6470 the window height has been changed. */
6473 resize_mini_window (w
, exact_p
)
6477 struct frame
*f
= XFRAME (w
->frame
);
6478 int window_height_changed_p
= 0;
6480 xassert (MINI_WINDOW_P (w
));
6482 /* Nil means don't try to resize. */
6483 if (NILP (Vresize_mini_windows
)
6484 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6487 if (!FRAME_MINIBUF_ONLY_P (f
))
6490 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6491 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6492 int height
, max_height
;
6493 int unit
= CANON_Y_UNIT (f
);
6494 struct text_pos start
;
6495 struct buffer
*old_current_buffer
= NULL
;
6497 if (current_buffer
!= XBUFFER (w
->buffer
))
6499 old_current_buffer
= current_buffer
;
6500 set_buffer_internal (XBUFFER (w
->buffer
));
6503 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6505 /* Compute the max. number of lines specified by the user. */
6506 if (FLOATP (Vmax_mini_window_height
))
6507 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
6508 else if (INTEGERP (Vmax_mini_window_height
))
6509 max_height
= XINT (Vmax_mini_window_height
);
6511 max_height
= total_height
/ 4;
6513 /* Correct that max. height if it's bogus. */
6514 max_height
= max (1, max_height
);
6515 max_height
= min (total_height
, max_height
);
6517 /* Find out the height of the text in the window. */
6518 if (it
.truncate_lines_p
)
6523 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6524 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6525 height
= it
.current_y
+ last_height
;
6527 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6528 height
-= it
.extra_line_spacing
;
6529 height
= (height
+ unit
- 1) / unit
;
6532 /* Compute a suitable window start. */
6533 if (height
> max_height
)
6535 height
= max_height
;
6536 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6537 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6538 start
= it
.current
.pos
;
6541 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6542 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6544 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6546 /* Let it grow only, until we display an empty message, in which
6547 case the window shrinks again. */
6548 if (height
> XFASTINT (w
->height
))
6550 int old_height
= XFASTINT (w
->height
);
6551 freeze_window_starts (f
, 1);
6552 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6553 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6555 else if (height
< XFASTINT (w
->height
)
6556 && (exact_p
|| BEGV
== ZV
))
6558 int old_height
= XFASTINT (w
->height
);
6559 freeze_window_starts (f
, 0);
6560 shrink_mini_window (w
);
6561 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6566 /* Always resize to exact size needed. */
6567 if (height
> XFASTINT (w
->height
))
6569 int old_height
= XFASTINT (w
->height
);
6570 freeze_window_starts (f
, 1);
6571 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6572 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6574 else if (height
< XFASTINT (w
->height
))
6576 int old_height
= XFASTINT (w
->height
);
6577 freeze_window_starts (f
, 0);
6578 shrink_mini_window (w
);
6582 freeze_window_starts (f
, 1);
6583 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6586 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6590 if (old_current_buffer
)
6591 set_buffer_internal (old_current_buffer
);
6594 return window_height_changed_p
;
6598 /* Value is the current message, a string, or nil if there is no
6606 if (NILP (echo_area_buffer
[0]))
6610 with_echo_area_buffer (0, 0, current_message_1
,
6611 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6613 echo_area_buffer
[0] = Qnil
;
6621 current_message_1 (a1
, a2
, a3
, a4
)
6626 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6629 *msg
= make_buffer_string (BEG
, Z
, 1);
6636 /* Push the current message on Vmessage_stack for later restauration
6637 by restore_message. Value is non-zero if the current message isn't
6638 empty. This is a relatively infrequent operation, so it's not
6639 worth optimizing. */
6645 msg
= current_message ();
6646 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6647 return STRINGP (msg
);
6651 /* Handler for record_unwind_protect calling pop_message. */
6654 push_message_unwind (dummy
)
6662 /* Restore message display from the top of Vmessage_stack. */
6669 xassert (CONSP (Vmessage_stack
));
6670 msg
= XCAR (Vmessage_stack
);
6672 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6674 message3_nolog (msg
, 0, 0);
6678 /* Pop the top-most entry off Vmessage_stack. */
6683 xassert (CONSP (Vmessage_stack
));
6684 Vmessage_stack
= XCDR (Vmessage_stack
);
6688 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6689 exits. If the stack is not empty, we have a missing pop_message
6693 check_message_stack ()
6695 if (!NILP (Vmessage_stack
))
6700 /* Truncate to NCHARS what will be displayed in the echo area the next
6701 time we display it---but don't redisplay it now. */
6704 truncate_echo_area (nchars
)
6708 echo_area_buffer
[0] = Qnil
;
6709 /* A null message buffer means that the frame hasn't really been
6710 initialized yet. Error messages get reported properly by
6711 cmd_error, so this must be just an informative message; toss it. */
6712 else if (!noninteractive
6714 && !NILP (echo_area_buffer
[0]))
6716 struct frame
*sf
= SELECTED_FRAME ();
6717 if (FRAME_MESSAGE_BUF (sf
))
6718 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6723 /* Helper function for truncate_echo_area. Truncate the current
6724 message to at most NCHARS characters. */
6727 truncate_message_1 (nchars
, a2
, a3
, a4
)
6732 if (BEG
+ nchars
< Z
)
6733 del_range (BEG
+ nchars
, Z
);
6735 echo_area_buffer
[0] = Qnil
;
6740 /* Set the current message to a substring of S or STRING.
6742 If STRING is a Lisp string, set the message to the first NBYTES
6743 bytes from STRING. NBYTES zero means use the whole string. If
6744 STRING is multibyte, the message will be displayed multibyte.
6746 If S is not null, set the message to the first LEN bytes of S. LEN
6747 zero means use the whole string. MULTIBYTE_P non-zero means S is
6748 multibyte. Display the message multibyte in that case. */
6751 set_message (s
, string
, nbytes
, multibyte_p
)
6756 message_enable_multibyte
6757 = ((s
&& multibyte_p
)
6758 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6760 with_echo_area_buffer (0, -1, set_message_1
,
6761 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6762 message_buf_print
= 0;
6763 help_echo_showing_p
= 0;
6767 /* Helper function for set_message. Arguments have the same meaning
6768 as there, with A1 corresponding to S and A2 corresponding to STRING
6769 This function is called with the echo area buffer being
6773 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6776 EMACS_INT nbytes
, multibyte_p
;
6778 char *s
= (char *) a1
;
6779 Lisp_Object string
= a2
;
6783 /* Change multibyteness of the echo buffer appropriately. */
6784 if (message_enable_multibyte
6785 != !NILP (current_buffer
->enable_multibyte_characters
))
6786 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6788 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6790 /* Insert new message at BEG. */
6791 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6793 if (STRINGP (string
))
6798 nbytes
= XSTRING (string
)->size_byte
;
6799 nchars
= string_byte_to_char (string
, nbytes
);
6801 /* This function takes care of single/multibyte conversion. We
6802 just have to ensure that the echo area buffer has the right
6803 setting of enable_multibyte_characters. */
6804 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6809 nbytes
= strlen (s
);
6811 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6813 /* Convert from multi-byte to single-byte. */
6815 unsigned char work
[1];
6817 /* Convert a multibyte string to single-byte. */
6818 for (i
= 0; i
< nbytes
; i
+= n
)
6820 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6821 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6823 : multibyte_char_to_unibyte (c
, Qnil
));
6824 insert_1_both (work
, 1, 1, 1, 0, 0);
6827 else if (!multibyte_p
6828 && !NILP (current_buffer
->enable_multibyte_characters
))
6830 /* Convert from single-byte to multi-byte. */
6832 unsigned char *msg
= (unsigned char *) s
;
6833 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6835 /* Convert a single-byte string to multibyte. */
6836 for (i
= 0; i
< nbytes
; i
++)
6838 c
= unibyte_char_to_multibyte (msg
[i
]);
6839 n
= CHAR_STRING (c
, str
);
6840 insert_1_both (str
, 1, n
, 1, 0, 0);
6844 insert_1 (s
, nbytes
, 1, 0, 0);
6851 /* Clear messages. CURRENT_P non-zero means clear the current
6852 message. LAST_DISPLAYED_P non-zero means clear the message
6856 clear_message (current_p
, last_displayed_p
)
6857 int current_p
, last_displayed_p
;
6860 echo_area_buffer
[0] = Qnil
;
6862 if (last_displayed_p
)
6863 echo_area_buffer
[1] = Qnil
;
6865 message_buf_print
= 0;
6868 /* Clear garbaged frames.
6870 This function is used where the old redisplay called
6871 redraw_garbaged_frames which in turn called redraw_frame which in
6872 turn called clear_frame. The call to clear_frame was a source of
6873 flickering. I believe a clear_frame is not necessary. It should
6874 suffice in the new redisplay to invalidate all current matrices,
6875 and ensure a complete redisplay of all windows. */
6878 clear_garbaged_frames ()
6882 Lisp_Object tail
, frame
;
6884 FOR_EACH_FRAME (tail
, frame
)
6886 struct frame
*f
= XFRAME (frame
);
6888 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6890 clear_current_matrices (f
);
6896 ++windows_or_buffers_changed
;
6901 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6902 is non-zero update selected_frame. Value is non-zero if the
6903 mini-windows height has been changed. */
6906 echo_area_display (update_frame_p
)
6909 Lisp_Object mini_window
;
6912 int window_height_changed_p
= 0;
6913 struct frame
*sf
= SELECTED_FRAME ();
6915 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6916 w
= XWINDOW (mini_window
);
6917 f
= XFRAME (WINDOW_FRAME (w
));
6919 /* Don't display if frame is invisible or not yet initialized. */
6920 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6923 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6925 #ifdef HAVE_WINDOW_SYSTEM
6926 /* When Emacs starts, selected_frame may be a visible terminal
6927 frame, even if we run under a window system. If we let this
6928 through, a message would be displayed on the terminal. */
6929 if (EQ (selected_frame
, Vterminal_frame
)
6930 && !NILP (Vwindow_system
))
6932 #endif /* HAVE_WINDOW_SYSTEM */
6935 /* Redraw garbaged frames. */
6937 clear_garbaged_frames ();
6939 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6941 echo_area_window
= mini_window
;
6942 window_height_changed_p
= display_echo_area (w
);
6943 w
->must_be_updated_p
= 1;
6945 /* Update the display, unless called from redisplay_internal.
6946 Also don't update the screen during redisplay itself. The
6947 update will happen at the end of redisplay, and an update
6948 here could cause confusion. */
6949 if (update_frame_p
&& !redisplaying_p
)
6953 /* If the display update has been interrupted by pending
6954 input, update mode lines in the frame. Due to the
6955 pending input, it might have been that redisplay hasn't
6956 been called, so that mode lines above the echo area are
6957 garbaged. This looks odd, so we prevent it here. */
6958 if (!display_completed
)
6959 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6961 if (window_height_changed_p
6962 /* Don't do this if Emacs is shutting down. Redisplay
6963 needs to run hooks. */
6964 && !NILP (Vrun_hooks
))
6966 /* Must update other windows. Likewise as in other
6967 cases, don't let this update be interrupted by
6969 int count
= BINDING_STACK_SIZE ();
6970 specbind (Qredisplay_dont_pause
, Qt
);
6971 windows_or_buffers_changed
= 1;
6972 redisplay_internal (0);
6973 unbind_to (count
, Qnil
);
6975 else if (FRAME_WINDOW_P (f
) && n
== 0)
6977 /* Window configuration is the same as before.
6978 Can do with a display update of the echo area,
6979 unless we displayed some mode lines. */
6980 update_single_window (w
, 1);
6981 rif
->flush_display (f
);
6984 update_frame (f
, 1, 1);
6986 /* If cursor is in the echo area, make sure that the next
6987 redisplay displays the minibuffer, so that the cursor will
6988 be replaced with what the minibuffer wants. */
6989 if (cursor_in_echo_area
)
6990 ++windows_or_buffers_changed
;
6993 else if (!EQ (mini_window
, selected_window
))
6994 windows_or_buffers_changed
++;
6996 /* Last displayed message is now the current message. */
6997 echo_area_buffer
[1] = echo_area_buffer
[0];
6999 /* Prevent redisplay optimization in redisplay_internal by resetting
7000 this_line_start_pos. This is done because the mini-buffer now
7001 displays the message instead of its buffer text. */
7002 if (EQ (mini_window
, selected_window
))
7003 CHARPOS (this_line_start_pos
) = 0;
7005 return window_height_changed_p
;
7010 /***********************************************************************
7012 ***********************************************************************/
7015 #ifdef HAVE_WINDOW_SYSTEM
7017 /* A buffer for constructing frame titles in it; allocated from the
7018 heap in init_xdisp and resized as needed in store_frame_title_char. */
7020 static char *frame_title_buf
;
7022 /* The buffer's end, and a current output position in it. */
7024 static char *frame_title_buf_end
;
7025 static char *frame_title_ptr
;
7028 /* Store a single character C for the frame title in frame_title_buf.
7029 Re-allocate frame_title_buf if necessary. */
7032 store_frame_title_char (c
)
7035 /* If output position has reached the end of the allocated buffer,
7036 double the buffer's size. */
7037 if (frame_title_ptr
== frame_title_buf_end
)
7039 int len
= frame_title_ptr
- frame_title_buf
;
7040 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7041 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7042 frame_title_buf_end
= frame_title_buf
+ new_size
;
7043 frame_title_ptr
= frame_title_buf
+ len
;
7046 *frame_title_ptr
++ = c
;
7050 /* Store part of a frame title in frame_title_buf, beginning at
7051 frame_title_ptr. STR is the string to store. Do not copy
7052 characters that yield more columns than PRECISION; PRECISION <= 0
7053 means copy the whole string. Pad with spaces until FIELD_WIDTH
7054 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7055 pad. Called from display_mode_element when it is used to build a
7059 store_frame_title (str
, field_width
, precision
)
7061 int field_width
, precision
;
7064 int dummy
, nbytes
, width
;
7066 /* Copy at most PRECISION chars from STR. */
7067 nbytes
= strlen (str
);
7068 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7070 store_frame_title_char (*str
++);
7072 /* Fill up with spaces until FIELD_WIDTH reached. */
7073 while (field_width
> 0
7076 store_frame_title_char (' ');
7084 /* Set the title of FRAME, if it has changed. The title format is
7085 Vicon_title_format if FRAME is iconified, otherwise it is
7086 frame_title_format. */
7089 x_consider_frame_title (frame
)
7092 struct frame
*f
= XFRAME (frame
);
7094 if (FRAME_WINDOW_P (f
)
7095 || FRAME_MINIBUF_ONLY_P (f
)
7096 || f
->explicit_name
)
7098 /* Do we have more than one visible frame on this X display? */
7101 struct buffer
*obuf
;
7105 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7107 struct frame
*tf
= XFRAME (XCAR (tail
));
7110 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7111 && !FRAME_MINIBUF_ONLY_P (tf
)
7112 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7116 /* Set global variable indicating that multiple frames exist. */
7117 multiple_frames
= CONSP (tail
);
7119 /* Switch to the buffer of selected window of the frame. Set up
7120 frame_title_ptr so that display_mode_element will output into it;
7121 then display the title. */
7122 obuf
= current_buffer
;
7123 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
7124 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7125 frame_title_ptr
= frame_title_buf
;
7126 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7127 NULL
, DEFAULT_FACE_ID
);
7128 display_mode_element (&it
, 0, -1, -1, fmt
);
7129 len
= frame_title_ptr
- frame_title_buf
;
7130 frame_title_ptr
= NULL
;
7131 set_buffer_internal (obuf
);
7133 /* Set the title only if it's changed. This avoids consing in
7134 the common case where it hasn't. (If it turns out that we've
7135 already wasted too much time by walking through the list with
7136 display_mode_element, then we might need to optimize at a
7137 higher level than this.) */
7138 if (! STRINGP (f
->name
)
7139 || STRING_BYTES (XSTRING (f
->name
)) != len
7140 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7141 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7145 #else /* not HAVE_WINDOW_SYSTEM */
7147 #define frame_title_ptr ((char *)0)
7148 #define store_frame_title(str, mincol, maxcol) 0
7150 #endif /* not HAVE_WINDOW_SYSTEM */
7155 /***********************************************************************
7157 ***********************************************************************/
7160 /* Prepare for redisplay by updating menu-bar item lists when
7161 appropriate. This can call eval. */
7164 prepare_menu_bars ()
7167 struct gcpro gcpro1
, gcpro2
;
7169 Lisp_Object tooltip_frame
;
7171 #ifdef HAVE_X_WINDOWS
7172 tooltip_frame
= tip_frame
;
7174 tooltip_frame
= Qnil
;
7177 /* Update all frame titles based on their buffer names, etc. We do
7178 this before the menu bars so that the buffer-menu will show the
7179 up-to-date frame titles. */
7180 #ifdef HAVE_WINDOW_SYSTEM
7181 if (windows_or_buffers_changed
|| update_mode_lines
)
7183 Lisp_Object tail
, frame
;
7185 FOR_EACH_FRAME (tail
, frame
)
7188 if (!EQ (frame
, tooltip_frame
)
7189 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7190 x_consider_frame_title (frame
);
7193 #endif /* HAVE_WINDOW_SYSTEM */
7195 /* Update the menu bar item lists, if appropriate. This has to be
7196 done before any actual redisplay or generation of display lines. */
7197 all_windows
= (update_mode_lines
7198 || buffer_shared
> 1
7199 || windows_or_buffers_changed
);
7202 Lisp_Object tail
, frame
;
7203 int count
= BINDING_STACK_SIZE ();
7205 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7207 FOR_EACH_FRAME (tail
, frame
)
7211 /* Ignore tooltip frame. */
7212 if (EQ (frame
, tooltip_frame
))
7215 /* If a window on this frame changed size, report that to
7216 the user and clear the size-change flag. */
7217 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7219 Lisp_Object functions
;
7221 /* Clear flag first in case we get an error below. */
7222 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7223 functions
= Vwindow_size_change_functions
;
7224 GCPRO2 (tail
, functions
);
7226 while (CONSP (functions
))
7228 call1 (XCAR (functions
), frame
);
7229 functions
= XCDR (functions
);
7235 update_menu_bar (f
, 0);
7236 #ifdef HAVE_WINDOW_SYSTEM
7237 update_tool_bar (f
, 0);
7242 unbind_to (count
, Qnil
);
7246 struct frame
*sf
= SELECTED_FRAME ();
7247 update_menu_bar (sf
, 1);
7248 #ifdef HAVE_WINDOW_SYSTEM
7249 update_tool_bar (sf
, 1);
7253 /* Motif needs this. See comment in xmenu.c. Turn it off when
7254 pending_menu_activation is not defined. */
7255 #ifdef USE_X_TOOLKIT
7256 pending_menu_activation
= 0;
7261 /* Update the menu bar item list for frame F. This has to be done
7262 before we start to fill in any display lines, because it can call
7265 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7268 update_menu_bar (f
, save_match_data
)
7270 int save_match_data
;
7273 register struct window
*w
;
7275 /* If called recursively during a menu update, do nothing. This can
7276 happen when, for instance, an activate-menubar-hook causes a
7278 if (inhibit_menubar_update
)
7281 window
= FRAME_SELECTED_WINDOW (f
);
7282 w
= XWINDOW (window
);
7284 if (update_mode_lines
)
7285 w
->update_mode_line
= Qt
;
7287 if (FRAME_WINDOW_P (f
)
7289 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7290 FRAME_EXTERNAL_MENU_BAR (f
)
7292 FRAME_MENU_BAR_LINES (f
) > 0
7294 : FRAME_MENU_BAR_LINES (f
) > 0)
7296 /* If the user has switched buffers or windows, we need to
7297 recompute to reflect the new bindings. But we'll
7298 recompute when update_mode_lines is set too; that means
7299 that people can use force-mode-line-update to request
7300 that the menu bar be recomputed. The adverse effect on
7301 the rest of the redisplay algorithm is about the same as
7302 windows_or_buffers_changed anyway. */
7303 if (windows_or_buffers_changed
7304 || !NILP (w
->update_mode_line
)
7305 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7306 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7307 != !NILP (w
->last_had_star
))
7308 || ((!NILP (Vtransient_mark_mode
)
7309 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7310 != !NILP (w
->region_showing
)))
7312 struct buffer
*prev
= current_buffer
;
7313 int count
= BINDING_STACK_SIZE ();
7315 specbind (Qinhibit_menubar_update
, Qt
);
7317 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7318 if (save_match_data
)
7319 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7320 if (NILP (Voverriding_local_map_menu_flag
))
7322 specbind (Qoverriding_terminal_local_map
, Qnil
);
7323 specbind (Qoverriding_local_map
, Qnil
);
7326 /* Run the Lucid hook. */
7327 safe_run_hooks (Qactivate_menubar_hook
);
7329 /* If it has changed current-menubar from previous value,
7330 really recompute the menu-bar from the value. */
7331 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7332 call0 (Qrecompute_lucid_menubar
);
7334 safe_run_hooks (Qmenu_bar_update_hook
);
7335 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7337 /* Redisplay the menu bar in case we changed it. */
7338 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7339 if (FRAME_WINDOW_P (f
)
7340 #if defined (macintosh)
7341 /* All frames on Mac OS share the same menubar. So only the
7342 selected frame should be allowed to set it. */
7343 && f
== SELECTED_FRAME ()
7346 set_frame_menubar (f
, 0, 0);
7348 /* On a terminal screen, the menu bar is an ordinary screen
7349 line, and this makes it get updated. */
7350 w
->update_mode_line
= Qt
;
7351 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7352 /* In the non-toolkit version, the menu bar is an ordinary screen
7353 line, and this makes it get updated. */
7354 w
->update_mode_line
= Qt
;
7355 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7357 unbind_to (count
, Qnil
);
7358 set_buffer_internal_1 (prev
);
7365 /***********************************************************************
7367 ***********************************************************************/
7369 #ifdef HAVE_WINDOW_SYSTEM
7371 /* Update the tool-bar item list for frame F. This has to be done
7372 before we start to fill in any display lines. Called from
7373 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7374 and restore it here. */
7377 update_tool_bar (f
, save_match_data
)
7379 int save_match_data
;
7381 if (WINDOWP (f
->tool_bar_window
)
7382 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7387 window
= FRAME_SELECTED_WINDOW (f
);
7388 w
= XWINDOW (window
);
7390 /* If the user has switched buffers or windows, we need to
7391 recompute to reflect the new bindings. But we'll
7392 recompute when update_mode_lines is set too; that means
7393 that people can use force-mode-line-update to request
7394 that the menu bar be recomputed. The adverse effect on
7395 the rest of the redisplay algorithm is about the same as
7396 windows_or_buffers_changed anyway. */
7397 if (windows_or_buffers_changed
7398 || !NILP (w
->update_mode_line
)
7399 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7400 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7401 != !NILP (w
->last_had_star
))
7402 || ((!NILP (Vtransient_mark_mode
)
7403 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7404 != !NILP (w
->region_showing
)))
7406 struct buffer
*prev
= current_buffer
;
7407 int count
= BINDING_STACK_SIZE ();
7409 /* Set current_buffer to the buffer of the selected
7410 window of the frame, so that we get the right local
7412 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7414 /* Save match data, if we must. */
7415 if (save_match_data
)
7416 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7418 /* Make sure that we don't accidentally use bogus keymaps. */
7419 if (NILP (Voverriding_local_map_menu_flag
))
7421 specbind (Qoverriding_terminal_local_map
, Qnil
);
7422 specbind (Qoverriding_local_map
, Qnil
);
7425 /* Build desired tool-bar items from keymaps. */
7427 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7429 /* Redisplay the tool-bar in case we changed it. */
7430 w
->update_mode_line
= Qt
;
7432 unbind_to (count
, Qnil
);
7433 set_buffer_internal_1 (prev
);
7439 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7440 F's desired tool-bar contents. F->tool_bar_items must have
7441 been set up previously by calling prepare_menu_bars. */
7444 build_desired_tool_bar_string (f
)
7447 int i
, size
, size_needed
;
7448 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7449 Lisp_Object image
, plist
, props
;
7451 image
= plist
= props
= Qnil
;
7452 GCPRO3 (image
, plist
, props
);
7454 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7455 Otherwise, make a new string. */
7457 /* The size of the string we might be able to reuse. */
7458 size
= (STRINGP (f
->desired_tool_bar_string
)
7459 ? XSTRING (f
->desired_tool_bar_string
)->size
7462 /* We need one space in the string for each image. */
7463 size_needed
= f
->n_tool_bar_items
;
7465 /* Reuse f->desired_tool_bar_string, if possible. */
7466 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7467 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7471 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7472 Fremove_text_properties (make_number (0), make_number (size
),
7473 props
, f
->desired_tool_bar_string
);
7476 /* Put a `display' property on the string for the images to display,
7477 put a `menu_item' property on tool-bar items with a value that
7478 is the index of the item in F's tool-bar item vector. */
7479 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7481 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7483 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7484 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7485 int hmargin
, vmargin
, relief
, idx
, end
;
7486 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7487 extern Lisp_Object Qlaplace
;
7489 /* If image is a vector, choose the image according to the
7491 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7492 if (VECTORP (image
))
7496 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7497 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7500 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7501 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7503 xassert (ASIZE (image
) >= idx
);
7504 image
= AREF (image
, idx
);
7509 /* Ignore invalid image specifications. */
7510 if (!valid_image_p (image
))
7513 /* Display the tool-bar button pressed, or depressed. */
7514 plist
= Fcopy_sequence (XCDR (image
));
7516 /* Compute margin and relief to draw. */
7517 relief
= (tool_bar_button_relief
> 0
7518 ? tool_bar_button_relief
7519 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7520 hmargin
= vmargin
= relief
;
7522 if (INTEGERP (Vtool_bar_button_margin
)
7523 && XINT (Vtool_bar_button_margin
) > 0)
7525 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7526 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7528 else if (CONSP (Vtool_bar_button_margin
))
7530 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7531 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7532 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7534 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7535 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7536 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7539 if (auto_raise_tool_bar_buttons_p
)
7541 /* Add a `:relief' property to the image spec if the item is
7545 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7552 /* If image is selected, display it pressed, i.e. with a
7553 negative relief. If it's not selected, display it with a
7555 plist
= Fplist_put (plist
, QCrelief
,
7557 ? make_number (-relief
)
7558 : make_number (relief
)));
7563 /* Put a margin around the image. */
7564 if (hmargin
|| vmargin
)
7566 if (hmargin
== vmargin
)
7567 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7569 plist
= Fplist_put (plist
, QCmargin
,
7570 Fcons (make_number (hmargin
),
7571 make_number (vmargin
)));
7574 /* If button is not enabled, and we don't have special images
7575 for the disabled state, make the image appear disabled by
7576 applying an appropriate algorithm to it. */
7577 if (!enabled_p
&& idx
< 0)
7578 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7580 /* Put a `display' text property on the string for the image to
7581 display. Put a `menu-item' property on the string that gives
7582 the start of this item's properties in the tool-bar items
7584 image
= Fcons (Qimage
, plist
);
7585 props
= list4 (Qdisplay
, image
,
7586 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7588 /* Let the last image hide all remaining spaces in the tool bar
7589 string. The string can be longer than needed when we reuse a
7591 if (i
+ 1 == f
->n_tool_bar_items
)
7592 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7595 Fadd_text_properties (make_number (i
), make_number (end
),
7596 props
, f
->desired_tool_bar_string
);
7604 /* Display one line of the tool-bar of frame IT->f. */
7607 display_tool_bar_line (it
)
7610 struct glyph_row
*row
= it
->glyph_row
;
7611 int max_x
= it
->last_visible_x
;
7614 prepare_desired_row (row
);
7615 row
->y
= it
->current_y
;
7617 /* Note that this isn't made use of if the face hasn't a box,
7618 so there's no need to check the face here. */
7619 it
->start_of_box_run_p
= 1;
7621 while (it
->current_x
< max_x
)
7623 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7625 /* Get the next display element. */
7626 if (!get_next_display_element (it
))
7629 /* Produce glyphs. */
7630 x_before
= it
->current_x
;
7631 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7632 PRODUCE_GLYPHS (it
);
7634 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7639 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7641 if (x
+ glyph
->pixel_width
> max_x
)
7643 /* Glyph doesn't fit on line. */
7644 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7650 x
+= glyph
->pixel_width
;
7654 /* Stop at line ends. */
7655 if (ITERATOR_AT_END_OF_LINE_P (it
))
7658 set_iterator_to_next (it
, 1);
7663 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7664 extend_face_to_end_of_line (it
);
7665 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7666 last
->right_box_line_p
= 1;
7667 if (last
== row
->glyphs
[TEXT_AREA
])
7668 last
->left_box_line_p
= 1;
7669 compute_line_metrics (it
);
7671 /* If line is empty, make it occupy the rest of the tool-bar. */
7672 if (!row
->displays_text_p
)
7674 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7675 row
->ascent
= row
->phys_ascent
= 0;
7678 row
->full_width_p
= 1;
7679 row
->continued_p
= 0;
7680 row
->truncated_on_left_p
= 0;
7681 row
->truncated_on_right_p
= 0;
7683 it
->current_x
= it
->hpos
= 0;
7684 it
->current_y
+= row
->height
;
7690 /* Value is the number of screen lines needed to make all tool-bar
7691 items of frame F visible. */
7694 tool_bar_lines_needed (f
)
7697 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7700 /* Initialize an iterator for iteration over
7701 F->desired_tool_bar_string in the tool-bar window of frame F. */
7702 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7703 it
.first_visible_x
= 0;
7704 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7705 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7707 while (!ITERATOR_AT_END_P (&it
))
7709 it
.glyph_row
= w
->desired_matrix
->rows
;
7710 clear_glyph_row (it
.glyph_row
);
7711 display_tool_bar_line (&it
);
7714 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7718 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7720 "Return the number of lines occupied by the tool bar of FRAME.")
7729 frame
= selected_frame
;
7731 CHECK_FRAME (frame
, 0);
7734 if (WINDOWP (f
->tool_bar_window
)
7735 || (w
= XWINDOW (f
->tool_bar_window
),
7736 XFASTINT (w
->height
) > 0))
7738 update_tool_bar (f
, 1);
7739 if (f
->n_tool_bar_items
)
7741 build_desired_tool_bar_string (f
);
7742 nlines
= tool_bar_lines_needed (f
);
7746 return make_number (nlines
);
7750 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7751 height should be changed. */
7754 redisplay_tool_bar (f
)
7759 struct glyph_row
*row
;
7760 int change_height_p
= 0;
7762 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7763 do anything. This means you must start with tool-bar-lines
7764 non-zero to get the auto-sizing effect. Or in other words, you
7765 can turn off tool-bars by specifying tool-bar-lines zero. */
7766 if (!WINDOWP (f
->tool_bar_window
)
7767 || (w
= XWINDOW (f
->tool_bar_window
),
7768 XFASTINT (w
->height
) == 0))
7771 /* Set up an iterator for the tool-bar window. */
7772 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7773 it
.first_visible_x
= 0;
7774 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7777 /* Build a string that represents the contents of the tool-bar. */
7778 build_desired_tool_bar_string (f
);
7779 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7781 /* Display as many lines as needed to display all tool-bar items. */
7782 while (it
.current_y
< it
.last_visible_y
)
7783 display_tool_bar_line (&it
);
7785 /* It doesn't make much sense to try scrolling in the tool-bar
7786 window, so don't do it. */
7787 w
->desired_matrix
->no_scrolling_p
= 1;
7788 w
->must_be_updated_p
= 1;
7790 if (auto_resize_tool_bars_p
)
7794 /* If we couldn't display everything, change the tool-bar's
7796 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7797 change_height_p
= 1;
7799 /* If there are blank lines at the end, except for a partially
7800 visible blank line at the end that is smaller than
7801 CANON_Y_UNIT, change the tool-bar's height. */
7802 row
= it
.glyph_row
- 1;
7803 if (!row
->displays_text_p
7804 && row
->height
>= CANON_Y_UNIT (f
))
7805 change_height_p
= 1;
7807 /* If row displays tool-bar items, but is partially visible,
7808 change the tool-bar's height. */
7809 if (row
->displays_text_p
7810 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7811 change_height_p
= 1;
7813 /* Resize windows as needed by changing the `tool-bar-lines'
7816 && (nlines
= tool_bar_lines_needed (f
),
7817 nlines
!= XFASTINT (w
->height
)))
7819 extern Lisp_Object Qtool_bar_lines
;
7821 int old_height
= XFASTINT (w
->height
);
7823 XSETFRAME (frame
, f
);
7824 clear_glyph_matrix (w
->desired_matrix
);
7825 Fmodify_frame_parameters (frame
,
7826 Fcons (Fcons (Qtool_bar_lines
,
7827 make_number (nlines
)),
7829 if (XFASTINT (w
->height
) != old_height
)
7830 fonts_changed_p
= 1;
7834 return change_height_p
;
7838 /* Get information about the tool-bar item which is displayed in GLYPH
7839 on frame F. Return in *PROP_IDX the index where tool-bar item
7840 properties start in F->tool_bar_items. Value is zero if
7841 GLYPH doesn't display a tool-bar item. */
7844 tool_bar_item_info (f
, glyph
, prop_idx
)
7846 struct glyph
*glyph
;
7852 /* Get the text property `menu-item' at pos. The value of that
7853 property is the start index of this item's properties in
7854 F->tool_bar_items. */
7855 prop
= Fget_text_property (make_number (glyph
->charpos
),
7856 Qmenu_item
, f
->current_tool_bar_string
);
7857 if (INTEGERP (prop
))
7859 *prop_idx
= XINT (prop
);
7868 #endif /* HAVE_WINDOW_SYSTEM */
7872 /************************************************************************
7873 Horizontal scrolling
7874 ************************************************************************/
7876 static int hscroll_window_tree
P_ ((Lisp_Object
));
7877 static int hscroll_windows
P_ ((Lisp_Object
));
7879 /* For all leaf windows in the window tree rooted at WINDOW, set their
7880 hscroll value so that PT is (i) visible in the window, and (ii) so
7881 that it is not within a certain margin at the window's left and
7882 right border. Value is non-zero if any window's hscroll has been
7886 hscroll_window_tree (window
)
7889 int hscrolled_p
= 0;
7891 while (WINDOWP (window
))
7893 struct window
*w
= XWINDOW (window
);
7895 if (WINDOWP (w
->hchild
))
7896 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7897 else if (WINDOWP (w
->vchild
))
7898 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7899 else if (w
->cursor
.vpos
>= 0)
7901 int hscroll_margin
, text_area_x
, text_area_y
;
7902 int text_area_width
, text_area_height
;
7903 struct glyph_row
*current_cursor_row
7904 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7905 struct glyph_row
*desired_cursor_row
7906 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7907 struct glyph_row
*cursor_row
7908 = (desired_cursor_row
->enabled_p
7909 ? desired_cursor_row
7910 : current_cursor_row
);
7912 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7913 &text_area_width
, &text_area_height
);
7915 /* Scroll when cursor is inside this scroll margin. */
7916 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7918 if ((XFASTINT (w
->hscroll
)
7919 && w
->cursor
.x
< hscroll_margin
)
7920 || (cursor_row
->enabled_p
7921 && cursor_row
->truncated_on_right_p
7922 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7926 struct buffer
*saved_current_buffer
;
7929 /* Find point in a display of infinite width. */
7930 saved_current_buffer
= current_buffer
;
7931 current_buffer
= XBUFFER (w
->buffer
);
7933 if (w
== XWINDOW (selected_window
))
7934 pt
= BUF_PT (current_buffer
);
7937 pt
= marker_position (w
->pointm
);
7938 pt
= max (BEGV
, pt
);
7942 /* Move iterator to pt starting at cursor_row->start in
7943 a line with infinite width. */
7944 init_to_row_start (&it
, w
, cursor_row
);
7945 it
.last_visible_x
= INFINITY
;
7946 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7947 current_buffer
= saved_current_buffer
;
7949 /* Center cursor in window. */
7950 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7951 / CANON_X_UNIT (it
.f
));
7952 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
7954 /* Don't call Fset_window_hscroll if value hasn't
7955 changed because it will prevent redisplay
7957 if (XFASTINT (w
->hscroll
) != hscroll
)
7959 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
7960 w
->hscroll
= make_number (hscroll
);
7969 /* Value is non-zero if hscroll of any leaf window has been changed. */
7974 /* Set hscroll so that cursor is visible and not inside horizontal
7975 scroll margins for all windows in the tree rooted at WINDOW. See
7976 also hscroll_window_tree above. Value is non-zero if any window's
7977 hscroll has been changed. If it has, desired matrices on the frame
7978 of WINDOW are cleared. */
7981 hscroll_windows (window
)
7986 if (automatic_hscrolling_p
)
7988 hscrolled_p
= hscroll_window_tree (window
);
7990 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7999 /************************************************************************
8001 ************************************************************************/
8003 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8004 to a non-zero value. This is sometimes handy to have in a debugger
8009 /* First and last unchanged row for try_window_id. */
8011 int debug_first_unchanged_at_end_vpos
;
8012 int debug_last_unchanged_at_beg_vpos
;
8014 /* Delta vpos and y. */
8016 int debug_dvpos
, debug_dy
;
8018 /* Delta in characters and bytes for try_window_id. */
8020 int debug_delta
, debug_delta_bytes
;
8022 /* Values of window_end_pos and window_end_vpos at the end of
8025 int debug_end_pos
, debug_end_vpos
;
8027 /* Append a string to W->desired_matrix->method. FMT is a printf
8028 format string. A1...A9 are a supplement for a variable-length
8029 argument list. If trace_redisplay_p is non-zero also printf the
8030 resulting string to stderr. */
8033 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8036 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8039 char *method
= w
->desired_matrix
->method
;
8040 int len
= strlen (method
);
8041 int size
= sizeof w
->desired_matrix
->method
;
8042 int remaining
= size
- len
- 1;
8044 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8045 if (len
&& remaining
)
8051 strncpy (method
+ len
, buffer
, remaining
);
8053 if (trace_redisplay_p
)
8054 fprintf (stderr
, "%p (%s): %s\n",
8056 ((BUFFERP (w
->buffer
)
8057 && STRINGP (XBUFFER (w
->buffer
)->name
))
8058 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8063 #endif /* GLYPH_DEBUG */
8066 /* This counter is used to clear the face cache every once in a while
8067 in redisplay_internal. It is incremented for each redisplay.
8068 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8071 #define CLEAR_FACE_CACHE_COUNT 10000
8072 static int clear_face_cache_count
;
8074 /* Record the previous terminal frame we displayed. */
8076 static struct frame
*previous_terminal_frame
;
8078 /* Non-zero while redisplay_internal is in progress. */
8083 /* Value is non-zero if all changes in window W, which displays
8084 current_buffer, are in the text between START and END. START is a
8085 buffer position, END is given as a distance from Z. Used in
8086 redisplay_internal for display optimization. */
8089 text_outside_line_unchanged_p (w
, start
, end
)
8093 int unchanged_p
= 1;
8095 /* If text or overlays have changed, see where. */
8096 if (XFASTINT (w
->last_modified
) < MODIFF
8097 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8099 /* Gap in the line? */
8100 if (GPT
< start
|| Z
- GPT
< end
)
8103 /* Changes start in front of the line, or end after it? */
8105 && (BEG_UNCHANGED
< start
- 1
8106 || END_UNCHANGED
< end
))
8109 /* If selective display, can't optimize if changes start at the
8110 beginning of the line. */
8112 && INTEGERP (current_buffer
->selective_display
)
8113 && XINT (current_buffer
->selective_display
) > 0
8114 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8122 /* Do a frame update, taking possible shortcuts into account. This is
8123 the main external entry point for redisplay.
8125 If the last redisplay displayed an echo area message and that message
8126 is no longer requested, we clear the echo area or bring back the
8127 mini-buffer if that is in use. */
8132 redisplay_internal (0);
8135 /* Return 1 if point moved out of or into a composition. Otherwise
8136 return 0. PREV_BUF and PREV_PT are the last point buffer and
8137 position. BUF and PT are the current point buffer and position. */
8140 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8141 struct buffer
*prev_buf
, *buf
;
8148 XSETBUFFER (buffer
, buf
);
8149 /* Check a composition at the last point if point moved within the
8151 if (prev_buf
== buf
)
8154 /* Point didn't move. */
8157 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8158 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8159 && COMPOSITION_VALID_P (start
, end
, prop
)
8160 && start
< prev_pt
&& end
> prev_pt
)
8161 /* The last point was within the composition. Return 1 iff
8162 point moved out of the composition. */
8163 return (pt
<= start
|| pt
>= end
);
8166 /* Check a composition at the current point. */
8167 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8168 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8169 && COMPOSITION_VALID_P (start
, end
, prop
)
8170 && start
< pt
&& end
> pt
);
8173 /* Reconsider the setting of B->clip_changed which is displayed
8177 reconsider_clip_changes (w
, b
)
8181 if (b
->prevent_redisplay_optimizations_p
)
8182 b
->clip_changed
= 1;
8183 else if (b
->clip_changed
8184 && !NILP (w
->window_end_valid
)
8185 && w
->current_matrix
->buffer
== b
8186 && w
->current_matrix
->zv
== BUF_ZV (b
)
8187 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8188 b
->clip_changed
= 0;
8190 /* If display wasn't paused, and W is not a tool bar window, see if
8191 point has been moved into or out of a composition. In that case,
8192 we set b->clip_changed to 1 to force updating the screen. If
8193 b->clip_changed has already been set to 1, we can skip this
8195 if (!b
->clip_changed
8196 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8200 if (w
== XWINDOW (selected_window
))
8201 pt
= BUF_PT (current_buffer
);
8203 pt
= marker_position (w
->pointm
);
8205 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8206 || pt
!= XINT (w
->last_point
))
8207 && check_point_in_composition (w
->current_matrix
->buffer
,
8208 XINT (w
->last_point
),
8209 XBUFFER (w
->buffer
), pt
))
8210 b
->clip_changed
= 1;
8215 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8216 response to any user action; therefore, we should preserve the echo
8217 area. (Actually, our caller does that job.) Perhaps in the future
8218 avoid recentering windows if it is not necessary; currently that
8219 causes some problems. */
8222 redisplay_internal (preserve_echo_area
)
8223 int preserve_echo_area
;
8225 struct window
*w
= XWINDOW (selected_window
);
8226 struct frame
*f
= XFRAME (w
->frame
);
8228 int must_finish
= 0;
8229 struct text_pos tlbufpos
, tlendpos
;
8230 int number_of_visible_frames
;
8232 struct frame
*sf
= SELECTED_FRAME ();
8234 /* Non-zero means redisplay has to consider all windows on all
8235 frames. Zero means, only selected_window is considered. */
8236 int consider_all_windows_p
;
8238 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8240 /* No redisplay if running in batch mode or frame is not yet fully
8241 initialized, or redisplay is explicitly turned off by setting
8242 Vinhibit_redisplay. */
8244 || !NILP (Vinhibit_redisplay
)
8245 || !f
->glyphs_initialized_p
)
8248 /* The flag redisplay_performed_directly_p is set by
8249 direct_output_for_insert when it already did the whole screen
8250 update necessary. */
8251 if (redisplay_performed_directly_p
)
8253 redisplay_performed_directly_p
= 0;
8254 if (!hscroll_windows (selected_window
))
8258 #ifdef USE_X_TOOLKIT
8259 if (popup_activated ())
8263 /* I don't think this happens but let's be paranoid. */
8267 /* Record a function that resets redisplaying_p to its old value
8268 when we leave this function. */
8269 count
= BINDING_STACK_SIZE ();
8270 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8275 reconsider_clip_changes (w
, current_buffer
);
8277 /* If new fonts have been loaded that make a glyph matrix adjustment
8278 necessary, do it. */
8279 if (fonts_changed_p
)
8281 adjust_glyphs (NULL
);
8282 ++windows_or_buffers_changed
;
8283 fonts_changed_p
= 0;
8286 /* If face_change_count is non-zero, init_iterator will free all
8287 realized faces, which includes the faces referenced from current
8288 matrices. So, we can't reuse current matrices in this case. */
8289 if (face_change_count
)
8290 ++windows_or_buffers_changed
;
8292 if (! FRAME_WINDOW_P (sf
)
8293 && previous_terminal_frame
!= sf
)
8295 /* Since frames on an ASCII terminal share the same display
8296 area, displaying a different frame means redisplay the whole
8298 windows_or_buffers_changed
++;
8299 SET_FRAME_GARBAGED (sf
);
8300 XSETFRAME (Vterminal_frame
, sf
);
8302 previous_terminal_frame
= sf
;
8304 /* Set the visible flags for all frames. Do this before checking
8305 for resized or garbaged frames; they want to know if their frames
8306 are visible. See the comment in frame.h for
8307 FRAME_SAMPLE_VISIBILITY. */
8309 Lisp_Object tail
, frame
;
8311 number_of_visible_frames
= 0;
8313 FOR_EACH_FRAME (tail
, frame
)
8315 struct frame
*f
= XFRAME (frame
);
8317 FRAME_SAMPLE_VISIBILITY (f
);
8318 if (FRAME_VISIBLE_P (f
))
8319 ++number_of_visible_frames
;
8320 clear_desired_matrices (f
);
8324 /* Notice any pending interrupt request to change frame size. */
8325 do_pending_window_change (1);
8327 /* Clear frames marked as garbaged. */
8329 clear_garbaged_frames ();
8331 /* Build menubar and tool-bar items. */
8332 prepare_menu_bars ();
8334 if (windows_or_buffers_changed
)
8335 update_mode_lines
++;
8337 /* Detect case that we need to write or remove a star in the mode line. */
8338 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8340 w
->update_mode_line
= Qt
;
8341 if (buffer_shared
> 1)
8342 update_mode_lines
++;
8345 /* If %c is in the mode line, update it if needed. */
8346 if (!NILP (w
->column_number_displayed
)
8347 /* This alternative quickly identifies a common case
8348 where no change is needed. */
8349 && !(PT
== XFASTINT (w
->last_point
)
8350 && XFASTINT (w
->last_modified
) >= MODIFF
8351 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8352 && XFASTINT (w
->column_number_displayed
) != current_column ())
8353 w
->update_mode_line
= Qt
;
8355 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8357 /* The variable buffer_shared is set in redisplay_window and
8358 indicates that we redisplay a buffer in different windows. See
8360 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8362 /* If specs for an arrow have changed, do thorough redisplay
8363 to ensure we remove any arrow that should no longer exist. */
8364 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8365 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8366 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8368 /* Normally the message* functions will have already displayed and
8369 updated the echo area, but the frame may have been trashed, or
8370 the update may have been preempted, so display the echo area
8371 again here. Checking both message buffers captures the case that
8372 the echo area should be cleared. */
8373 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
8375 int window_height_changed_p
= echo_area_display (0);
8378 if (fonts_changed_p
)
8380 else if (window_height_changed_p
)
8382 consider_all_windows_p
= 1;
8383 ++update_mode_lines
;
8384 ++windows_or_buffers_changed
;
8386 /* If window configuration was changed, frames may have been
8387 marked garbaged. Clear them or we will experience
8388 surprises wrt scrolling. */
8390 clear_garbaged_frames ();
8393 else if (EQ (selected_window
, minibuf_window
)
8394 && (current_buffer
->clip_changed
8395 || XFASTINT (w
->last_modified
) < MODIFF
8396 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8397 && resize_mini_window (w
, 0))
8399 /* Resized active mini-window to fit the size of what it is
8400 showing if its contents might have changed. */
8402 consider_all_windows_p
= 1;
8403 ++windows_or_buffers_changed
;
8404 ++update_mode_lines
;
8406 /* If window configuration was changed, frames may have been
8407 marked garbaged. Clear them or we will experience
8408 surprises wrt scrolling. */
8410 clear_garbaged_frames ();
8414 /* If showing the region, and mark has changed, we must redisplay
8415 the whole window. The assignment to this_line_start_pos prevents
8416 the optimization directly below this if-statement. */
8417 if (((!NILP (Vtransient_mark_mode
)
8418 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8419 != !NILP (w
->region_showing
))
8420 || (!NILP (w
->region_showing
)
8421 && !EQ (w
->region_showing
,
8422 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8423 CHARPOS (this_line_start_pos
) = 0;
8425 /* Optimize the case that only the line containing the cursor in the
8426 selected window has changed. Variables starting with this_ are
8427 set in display_line and record information about the line
8428 containing the cursor. */
8429 tlbufpos
= this_line_start_pos
;
8430 tlendpos
= this_line_end_pos
;
8431 if (!consider_all_windows_p
8432 && CHARPOS (tlbufpos
) > 0
8433 && NILP (w
->update_mode_line
)
8434 && !current_buffer
->clip_changed
8435 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8436 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8437 /* Make sure recorded data applies to current buffer, etc. */
8438 && this_line_buffer
== current_buffer
8439 && current_buffer
== XBUFFER (w
->buffer
)
8440 && NILP (w
->force_start
)
8441 /* Point must be on the line that we have info recorded about. */
8442 && PT
>= CHARPOS (tlbufpos
)
8443 && PT
<= Z
- CHARPOS (tlendpos
)
8444 /* All text outside that line, including its final newline,
8445 must be unchanged */
8446 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8447 CHARPOS (tlendpos
)))
8449 if (CHARPOS (tlbufpos
) > BEGV
8450 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8451 && (CHARPOS (tlbufpos
) == ZV
8452 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8453 /* Former continuation line has disappeared by becoming empty */
8455 else if (XFASTINT (w
->last_modified
) < MODIFF
8456 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8457 || MINI_WINDOW_P (w
))
8459 /* We have to handle the case of continuation around a
8460 wide-column character (See the comment in indent.c around
8463 For instance, in the following case:
8465 -------- Insert --------
8466 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8467 J_I_ ==> J_I_ `^^' are cursors.
8471 As we have to redraw the line above, we should goto cancel. */
8474 int line_height_before
= this_line_pixel_height
;
8476 /* Note that start_display will handle the case that the
8477 line starting at tlbufpos is a continuation lines. */
8478 start_display (&it
, w
, tlbufpos
);
8480 /* Implementation note: It this still necessary? */
8481 if (it
.current_x
!= this_line_start_x
)
8484 TRACE ((stderr
, "trying display optimization 1\n"));
8485 w
->cursor
.vpos
= -1;
8486 overlay_arrow_seen
= 0;
8487 it
.vpos
= this_line_vpos
;
8488 it
.current_y
= this_line_y
;
8489 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8492 /* If line contains point, is not continued,
8493 and ends at same distance from eob as before, we win */
8494 if (w
->cursor
.vpos
>= 0
8495 /* Line is not continued, otherwise this_line_start_pos
8496 would have been set to 0 in display_line. */
8497 && CHARPOS (this_line_start_pos
)
8498 /* Line ends as before. */
8499 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8500 /* Line has same height as before. Otherwise other lines
8501 would have to be shifted up or down. */
8502 && this_line_pixel_height
== line_height_before
)
8504 /* If this is not the window's last line, we must adjust
8505 the charstarts of the lines below. */
8506 if (it
.current_y
< it
.last_visible_y
)
8508 struct glyph_row
*row
8509 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8510 int delta
, delta_bytes
;
8512 if (Z
- CHARPOS (tlendpos
) == ZV
)
8514 /* This line ends at end of (accessible part of)
8515 buffer. There is no newline to count. */
8517 - CHARPOS (tlendpos
)
8518 - MATRIX_ROW_START_CHARPOS (row
));
8519 delta_bytes
= (Z_BYTE
8520 - BYTEPOS (tlendpos
)
8521 - MATRIX_ROW_START_BYTEPOS (row
));
8525 /* This line ends in a newline. Must take
8526 account of the newline and the rest of the
8527 text that follows. */
8529 - CHARPOS (tlendpos
)
8530 - MATRIX_ROW_START_CHARPOS (row
));
8531 delta_bytes
= (Z_BYTE
8532 - BYTEPOS (tlendpos
)
8533 - MATRIX_ROW_START_BYTEPOS (row
));
8536 increment_matrix_positions (w
->current_matrix
,
8538 w
->current_matrix
->nrows
,
8539 delta
, delta_bytes
);
8542 /* If this row displays text now but previously didn't,
8543 or vice versa, w->window_end_vpos may have to be
8545 if ((it
.glyph_row
- 1)->displays_text_p
)
8547 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8548 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8550 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8551 && this_line_vpos
> 0)
8552 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8553 w
->window_end_valid
= Qnil
;
8555 /* Update hint: No need to try to scroll in update_window. */
8556 w
->desired_matrix
->no_scrolling_p
= 1;
8559 *w
->desired_matrix
->method
= 0;
8560 debug_method_add (w
, "optimization 1");
8567 else if (/* Cursor position hasn't changed. */
8568 PT
== XFASTINT (w
->last_point
)
8569 /* Make sure the cursor was last displayed
8570 in this window. Otherwise we have to reposition it. */
8571 && 0 <= w
->cursor
.vpos
8572 && XINT (w
->height
) > w
->cursor
.vpos
)
8576 do_pending_window_change (1);
8578 /* We used to always goto end_of_redisplay here, but this
8579 isn't enough if we have a blinking cursor. */
8580 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8581 goto end_of_redisplay
;
8585 /* If highlighting the region, or if the cursor is in the echo area,
8586 then we can't just move the cursor. */
8587 else if (! (!NILP (Vtransient_mark_mode
)
8588 && !NILP (current_buffer
->mark_active
))
8589 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8590 || highlight_nonselected_windows
)
8591 && NILP (w
->region_showing
)
8592 && NILP (Vshow_trailing_whitespace
)
8593 && !cursor_in_echo_area
)
8596 struct glyph_row
*row
;
8598 /* Skip from tlbufpos to PT and see where it is. Note that
8599 PT may be in invisible text. If so, we will end at the
8600 next visible position. */
8601 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8602 NULL
, DEFAULT_FACE_ID
);
8603 it
.current_x
= this_line_start_x
;
8604 it
.current_y
= this_line_y
;
8605 it
.vpos
= this_line_vpos
;
8607 /* The call to move_it_to stops in front of PT, but
8608 moves over before-strings. */
8609 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8611 if (it
.vpos
== this_line_vpos
8612 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8615 xassert (this_line_vpos
== it
.vpos
);
8616 xassert (this_line_y
== it
.current_y
);
8617 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8619 *w
->desired_matrix
->method
= 0;
8620 debug_method_add (w
, "optimization 3");
8629 /* Text changed drastically or point moved off of line. */
8630 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8633 CHARPOS (this_line_start_pos
) = 0;
8634 consider_all_windows_p
|= buffer_shared
> 1;
8635 ++clear_face_cache_count
;
8638 /* Build desired matrices, and update the display. If
8639 consider_all_windows_p is non-zero, do it for all windows on all
8640 frames. Otherwise do it for selected_window, only. */
8642 if (consider_all_windows_p
)
8644 Lisp_Object tail
, frame
;
8645 int i
, n
= 0, size
= 50;
8646 struct frame
**updated
8647 = (struct frame
**) alloca (size
* sizeof *updated
);
8649 /* Clear the face cache eventually. */
8650 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8652 clear_face_cache (0);
8653 clear_face_cache_count
= 0;
8656 /* Recompute # windows showing selected buffer. This will be
8657 incremented each time such a window is displayed. */
8660 FOR_EACH_FRAME (tail
, frame
)
8662 struct frame
*f
= XFRAME (frame
);
8664 if (FRAME_WINDOW_P (f
) || f
== sf
)
8666 /* Mark all the scroll bars to be removed; we'll redeem
8667 the ones we want when we redisplay their windows. */
8668 if (condemn_scroll_bars_hook
)
8669 condemn_scroll_bars_hook (f
);
8671 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8672 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8674 /* Any scroll bars which redisplay_windows should have
8675 nuked should now go away. */
8676 if (judge_scroll_bars_hook
)
8677 judge_scroll_bars_hook (f
);
8679 /* If fonts changed, display again. */
8680 if (fonts_changed_p
)
8683 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8685 /* See if we have to hscroll. */
8686 if (hscroll_windows (f
->root_window
))
8689 /* Prevent various kinds of signals during display
8690 update. stdio is not robust about handling
8691 signals, which can cause an apparent I/O
8693 if (interrupt_input
)
8697 /* Update the display. */
8698 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8699 pause
|= update_frame (f
, 0, 0);
8705 int nbytes
= size
* sizeof *updated
;
8706 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8707 bcopy (updated
, p
, nbytes
);
8716 /* Do the mark_window_display_accurate after all windows have
8717 been redisplayed because this call resets flags in buffers
8718 which are needed for proper redisplay. */
8719 for (i
= 0; i
< n
; ++i
)
8721 struct frame
*f
= updated
[i
];
8722 mark_window_display_accurate (f
->root_window
, 1);
8723 if (frame_up_to_date_hook
)
8724 frame_up_to_date_hook (f
);
8727 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8729 Lisp_Object mini_window
;
8730 struct frame
*mini_frame
;
8732 redisplay_window (selected_window
, 1);
8734 /* Compare desired and current matrices, perform output. */
8737 /* If fonts changed, display again. */
8738 if (fonts_changed_p
)
8741 /* Prevent various kinds of signals during display update.
8742 stdio is not robust about handling signals,
8743 which can cause an apparent I/O error. */
8744 if (interrupt_input
)
8748 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8750 if (hscroll_windows (selected_window
))
8753 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8754 pause
= update_frame (sf
, 0, 0);
8757 /* We may have called echo_area_display at the top of this
8758 function. If the echo area is on another frame, that may
8759 have put text on a frame other than the selected one, so the
8760 above call to update_frame would not have caught it. Catch
8762 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8763 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8765 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8767 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8768 pause
|= update_frame (mini_frame
, 0, 0);
8769 if (!pause
&& hscroll_windows (mini_window
))
8774 /* If display was paused because of pending input, make sure we do a
8775 thorough update the next time. */
8778 /* Prevent the optimization at the beginning of
8779 redisplay_internal that tries a single-line update of the
8780 line containing the cursor in the selected window. */
8781 CHARPOS (this_line_start_pos
) = 0;
8783 /* Let the overlay arrow be updated the next time. */
8784 if (!NILP (last_arrow_position
))
8786 last_arrow_position
= Qt
;
8787 last_arrow_string
= Qt
;
8790 /* If we pause after scrolling, some rows in the current
8791 matrices of some windows are not valid. */
8792 if (!WINDOW_FULL_WIDTH_P (w
)
8793 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8794 update_mode_lines
= 1;
8798 if (!consider_all_windows_p
)
8800 /* This has already been done above if
8801 consider_all_windows_p is set. */
8802 mark_window_display_accurate_1 (w
, 1);
8804 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8805 last_arrow_string
= Voverlay_arrow_string
;
8807 if (frame_up_to_date_hook
!= 0)
8808 frame_up_to_date_hook (sf
);
8811 update_mode_lines
= 0;
8812 windows_or_buffers_changed
= 0;
8815 /* Start SIGIO interrupts coming again. Having them off during the
8816 code above makes it less likely one will discard output, but not
8817 impossible, since there might be stuff in the system buffer here.
8818 But it is much hairier to try to do anything about that. */
8819 if (interrupt_input
)
8823 /* If a frame has become visible which was not before, redisplay
8824 again, so that we display it. Expose events for such a frame
8825 (which it gets when becoming visible) don't call the parts of
8826 redisplay constructing glyphs, so simply exposing a frame won't
8827 display anything in this case. So, we have to display these
8828 frames here explicitly. */
8831 Lisp_Object tail
, frame
;
8834 FOR_EACH_FRAME (tail
, frame
)
8836 int this_is_visible
= 0;
8838 if (XFRAME (frame
)->visible
)
8839 this_is_visible
= 1;
8840 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8841 if (XFRAME (frame
)->visible
)
8842 this_is_visible
= 1;
8844 if (this_is_visible
)
8848 if (new_count
!= number_of_visible_frames
)
8849 windows_or_buffers_changed
++;
8852 /* Change frame size now if a change is pending. */
8853 do_pending_window_change (1);
8855 /* If we just did a pending size change, or have additional
8856 visible frames, redisplay again. */
8857 if (windows_or_buffers_changed
&& !pause
)
8862 unbind_to (count
, Qnil
);
8866 /* Redisplay, but leave alone any recent echo area message unless
8867 another message has been requested in its place.
8869 This is useful in situations where you need to redisplay but no
8870 user action has occurred, making it inappropriate for the message
8871 area to be cleared. See tracking_off and
8872 wait_reading_process_input for examples of these situations.
8874 FROM_WHERE is an integer saying from where this function was
8875 called. This is useful for debugging. */
8878 redisplay_preserve_echo_area (from_where
)
8881 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
8883 if (!NILP (echo_area_buffer
[1]))
8885 /* We have a previously displayed message, but no current
8886 message. Redisplay the previous message. */
8887 display_last_displayed_message_p
= 1;
8888 redisplay_internal (1);
8889 display_last_displayed_message_p
= 0;
8892 redisplay_internal (1);
8896 /* Function registered with record_unwind_protect in
8897 redisplay_internal. Clears the flag indicating that a redisplay is
8901 unwind_redisplay (old_redisplaying_p
)
8902 Lisp_Object old_redisplaying_p
;
8904 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8909 /* Mark the display of window W as accurate or inaccurate. If
8910 ACCURATE_P is non-zero mark display of W as accurate. If
8911 ACCURATE_P is zero, arrange for W to be redisplayed the next time
8912 redisplay_internal is called. */
8915 mark_window_display_accurate_1 (w
, accurate_p
)
8919 if (BUFFERP (w
->buffer
))
8921 struct buffer
*b
= XBUFFER (w
->buffer
);
8924 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
8925 w
->last_overlay_modified
8926 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8928 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
8932 b
->clip_changed
= 0;
8933 b
->prevent_redisplay_optimizations_p
= 0;
8935 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8936 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8937 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8938 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8940 w
->current_matrix
->buffer
= b
;
8941 w
->current_matrix
->begv
= BUF_BEGV (b
);
8942 w
->current_matrix
->zv
= BUF_ZV (b
);
8944 w
->last_cursor
= w
->cursor
;
8945 w
->last_cursor_off_p
= w
->cursor_off_p
;
8947 if (w
== XWINDOW (selected_window
))
8948 w
->last_point
= make_number (BUF_PT (b
));
8950 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8956 w
->window_end_valid
= w
->buffer
;
8957 w
->update_mode_line
= Qnil
;
8962 /* Mark the display of windows in the window tree rooted at WINDOW as
8963 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
8964 windows as accurate. If ACCURATE_P is zero, arrange for windows to
8965 be redisplayed the next time redisplay_internal is called. */
8968 mark_window_display_accurate (window
, accurate_p
)
8974 for (; !NILP (window
); window
= w
->next
)
8976 w
= XWINDOW (window
);
8977 mark_window_display_accurate_1 (w
, accurate_p
);
8979 if (!NILP (w
->vchild
))
8980 mark_window_display_accurate (w
->vchild
, accurate_p
);
8981 if (!NILP (w
->hchild
))
8982 mark_window_display_accurate (w
->hchild
, accurate_p
);
8987 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8988 last_arrow_string
= Voverlay_arrow_string
;
8992 /* Force a thorough redisplay the next time by setting
8993 last_arrow_position and last_arrow_string to t, which is
8994 unequal to any useful value of Voverlay_arrow_... */
8995 last_arrow_position
= Qt
;
8996 last_arrow_string
= Qt
;
9001 /* Return value in display table DP (Lisp_Char_Table *) for character
9002 C. Since a display table doesn't have any parent, we don't have to
9003 follow parent. Do not call this function directly but use the
9004 macro DISP_CHAR_VECTOR. */
9007 disp_char_vector (dp
, c
)
9008 struct Lisp_Char_Table
*dp
;
9014 if (SINGLE_BYTE_CHAR_P (c
))
9015 return (dp
->contents
[c
]);
9017 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9020 else if (code
[2] < 32)
9023 /* Here, the possible range of code[0] (== charset ID) is
9024 128..max_charset. Since the top level char table contains data
9025 for multibyte characters after 256th element, we must increment
9026 code[0] by 128 to get a correct index. */
9028 code
[3] = -1; /* anchor */
9030 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9032 val
= dp
->contents
[code
[i
]];
9033 if (!SUB_CHAR_TABLE_P (val
))
9034 return (NILP (val
) ? dp
->defalt
: val
);
9037 /* Here, val is a sub char table. We return the default value of
9039 return (dp
->defalt
);
9044 /***********************************************************************
9046 ***********************************************************************/
9048 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9051 redisplay_windows (window
)
9054 while (!NILP (window
))
9056 struct window
*w
= XWINDOW (window
);
9058 if (!NILP (w
->hchild
))
9059 redisplay_windows (w
->hchild
);
9060 else if (!NILP (w
->vchild
))
9061 redisplay_windows (w
->vchild
);
9063 redisplay_window (window
, 0);
9070 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9071 DELTA is the number of bytes by which positions recorded in ROW
9072 differ from current buffer positions. */
9075 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9077 struct glyph_row
*row
;
9078 struct glyph_matrix
*matrix
;
9079 int delta
, delta_bytes
, dy
, dvpos
;
9081 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9082 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9084 int pt_old
= PT
- delta
;
9086 /* Skip over glyphs not having an object at the start of the row.
9087 These are special glyphs like truncation marks on terminal
9089 if (row
->displays_text_p
)
9091 && INTEGERP (glyph
->object
)
9092 && glyph
->charpos
< 0)
9094 x
+= glyph
->pixel_width
;
9099 && !INTEGERP (glyph
->object
)
9100 && (!BUFFERP (glyph
->object
)
9101 || glyph
->charpos
< pt_old
))
9103 x
+= glyph
->pixel_width
;
9107 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9109 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9110 w
->cursor
.y
= row
->y
+ dy
;
9112 if (w
== XWINDOW (selected_window
))
9114 if (!row
->continued_p
9115 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9118 this_line_buffer
= XBUFFER (w
->buffer
);
9120 CHARPOS (this_line_start_pos
)
9121 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9122 BYTEPOS (this_line_start_pos
)
9123 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9125 CHARPOS (this_line_end_pos
)
9126 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9127 BYTEPOS (this_line_end_pos
)
9128 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9130 this_line_y
= w
->cursor
.y
;
9131 this_line_pixel_height
= row
->height
;
9132 this_line_vpos
= w
->cursor
.vpos
;
9133 this_line_start_x
= row
->x
;
9136 CHARPOS (this_line_start_pos
) = 0;
9141 /* Run window scroll functions, if any, for WINDOW with new window
9142 start STARTP. Sets the window start of WINDOW to that position.
9144 We assume that the window's buffer is really current. */
9146 static INLINE
struct text_pos
9147 run_window_scroll_functions (window
, startp
)
9149 struct text_pos startp
;
9151 struct window
*w
= XWINDOW (window
);
9152 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9154 if (current_buffer
!= XBUFFER (w
->buffer
))
9157 if (!NILP (Vwindow_scroll_functions
))
9159 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9160 make_number (CHARPOS (startp
)));
9161 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9162 /* In case the hook functions switch buffers. */
9163 if (current_buffer
!= XBUFFER (w
->buffer
))
9164 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9171 /* Modify the desired matrix of window W and W->vscroll so that the
9172 line containing the cursor is fully visible. */
9175 make_cursor_line_fully_visible (w
)
9178 struct glyph_matrix
*matrix
;
9179 struct glyph_row
*row
;
9182 /* It's not always possible to find the cursor, e.g, when a window
9183 is full of overlay strings. Don't do anything in that case. */
9184 if (w
->cursor
.vpos
< 0)
9187 matrix
= w
->desired_matrix
;
9188 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9190 /* If the cursor row is not partially visible, there's nothing
9192 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9195 /* If the row the cursor is in is taller than the window's height,
9196 it's not clear what to do, so do nothing. */
9197 window_height
= window_box_height (w
);
9198 if (row
->height
>= window_height
)
9201 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9203 int dy
= row
->height
- row
->visible_height
;
9206 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9208 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9210 int dy
= - (row
->height
- row
->visible_height
);
9213 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9216 /* When we change the cursor y-position of the selected window,
9217 change this_line_y as well so that the display optimization for
9218 the cursor line of the selected window in redisplay_internal uses
9219 the correct y-position. */
9220 if (w
== XWINDOW (selected_window
))
9221 this_line_y
= w
->cursor
.y
;
9225 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9226 non-zero means only WINDOW is redisplayed in redisplay_internal.
9227 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9228 in redisplay_window to bring a partially visible line into view in
9229 the case that only the cursor has moved.
9233 1 if scrolling succeeded
9235 0 if scrolling didn't find point.
9237 -1 if new fonts have been loaded so that we must interrupt
9238 redisplay, adjust glyph matrices, and try again. */
9241 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9242 scroll_step
, temp_scroll_step
)
9244 int just_this_one_p
;
9245 int scroll_conservatively
, scroll_step
;
9246 int temp_scroll_step
;
9248 struct window
*w
= XWINDOW (window
);
9249 struct frame
*f
= XFRAME (w
->frame
);
9250 struct text_pos scroll_margin_pos
;
9251 struct text_pos pos
;
9252 struct text_pos startp
;
9254 Lisp_Object window_end
;
9255 int this_scroll_margin
;
9259 int amount_to_scroll
= 0;
9260 Lisp_Object aggressive
;
9264 debug_method_add (w
, "try_scrolling");
9267 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9269 /* Compute scroll margin height in pixels. We scroll when point is
9270 within this distance from the top or bottom of the window. */
9271 if (scroll_margin
> 0)
9273 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9274 this_scroll_margin
*= CANON_Y_UNIT (f
);
9277 this_scroll_margin
= 0;
9279 /* Compute how much we should try to scroll maximally to bring point
9281 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9282 scroll_max
= max (scroll_step
,
9283 max (scroll_conservatively
, temp_scroll_step
));
9284 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9285 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9286 /* We're trying to scroll because of aggressive scrolling
9287 but no scroll_step is set. Choose an arbitrary one. Maybe
9288 there should be a variable for this. */
9292 scroll_max
*= CANON_Y_UNIT (f
);
9294 /* Decide whether we have to scroll down. Start at the window end
9295 and move this_scroll_margin up to find the position of the scroll
9297 window_end
= Fwindow_end (window
, Qt
);
9298 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9299 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9300 if (this_scroll_margin
)
9302 start_display (&it
, w
, scroll_margin_pos
);
9303 move_it_vertically (&it
, - this_scroll_margin
);
9304 scroll_margin_pos
= it
.current
.pos
;
9307 if (PT
>= CHARPOS (scroll_margin_pos
))
9311 /* Point is in the scroll margin at the bottom of the window, or
9312 below. Compute a new window start that makes point visible. */
9314 /* Compute the distance from the scroll margin to PT.
9315 Give up if the distance is greater than scroll_max. */
9316 start_display (&it
, w
, scroll_margin_pos
);
9318 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9319 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9321 /* With a scroll_margin of 0, scroll_margin_pos is at the window
9322 end, which is one line below the window. The iterator's
9323 current_y will be same as y0 in that case, but we have to
9324 scroll a line to make PT visible. That's the reason why 1 is
9326 dy
= 1 + it
.current_y
- y0
;
9328 if (dy
> scroll_max
)
9331 /* Move the window start down. If scrolling conservatively,
9332 move it just enough down to make point visible. If
9333 scroll_step is set, move it down by scroll_step. */
9334 start_display (&it
, w
, startp
);
9336 if (scroll_conservatively
)
9338 = max (max (dy
, CANON_Y_UNIT (f
)),
9339 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9340 else if (scroll_step
|| temp_scroll_step
)
9341 amount_to_scroll
= scroll_max
;
9344 aggressive
= current_buffer
->scroll_down_aggressively
;
9345 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9346 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9347 if (NUMBERP (aggressive
))
9348 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9351 if (amount_to_scroll
<= 0)
9354 move_it_vertically (&it
, amount_to_scroll
);
9355 startp
= it
.current
.pos
;
9359 /* See if point is inside the scroll margin at the top of the
9361 scroll_margin_pos
= startp
;
9362 if (this_scroll_margin
)
9364 start_display (&it
, w
, startp
);
9365 move_it_vertically (&it
, this_scroll_margin
);
9366 scroll_margin_pos
= it
.current
.pos
;
9369 if (PT
< CHARPOS (scroll_margin_pos
))
9371 /* Point is in the scroll margin at the top of the window or
9372 above what is displayed in the window. */
9375 /* Compute the vertical distance from PT to the scroll
9376 margin position. Give up if distance is greater than
9378 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9379 start_display (&it
, w
, pos
);
9381 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9382 it
.last_visible_y
, -1,
9383 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9384 dy
= it
.current_y
- y0
;
9385 if (dy
> scroll_max
)
9388 /* Compute new window start. */
9389 start_display (&it
, w
, startp
);
9391 if (scroll_conservatively
)
9393 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9394 else if (scroll_step
|| temp_scroll_step
)
9395 amount_to_scroll
= scroll_max
;
9398 aggressive
= current_buffer
->scroll_up_aggressively
;
9399 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9400 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9401 if (NUMBERP (aggressive
))
9402 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9405 if (amount_to_scroll
<= 0)
9408 move_it_vertically (&it
, - amount_to_scroll
);
9409 startp
= it
.current
.pos
;
9413 /* Run window scroll functions. */
9414 startp
= run_window_scroll_functions (window
, startp
);
9416 /* Display the window. Give up if new fonts are loaded, or if point
9418 if (!try_window (window
, startp
))
9420 else if (w
->cursor
.vpos
< 0)
9422 clear_glyph_matrix (w
->desired_matrix
);
9427 /* Maybe forget recorded base line for line number display. */
9428 if (!just_this_one_p
9429 || current_buffer
->clip_changed
9430 || BEG_UNCHANGED
< CHARPOS (startp
))
9431 w
->base_line_number
= Qnil
;
9433 /* If cursor ends up on a partially visible line, shift display
9434 lines up or down. */
9435 make_cursor_line_fully_visible (w
);
9443 /* Compute a suitable window start for window W if display of W starts
9444 on a continuation line. Value is non-zero if a new window start
9447 The new window start will be computed, based on W's width, starting
9448 from the start of the continued line. It is the start of the
9449 screen line with the minimum distance from the old start W->start. */
9452 compute_window_start_on_continuation_line (w
)
9455 struct text_pos pos
, start_pos
;
9456 int window_start_changed_p
= 0;
9458 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9460 /* If window start is on a continuation line... Window start may be
9461 < BEGV in case there's invisible text at the start of the
9462 buffer (M-x rmail, for example). */
9463 if (CHARPOS (start_pos
) > BEGV
9464 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9467 struct glyph_row
*row
;
9469 /* Handle the case that the window start is out of range. */
9470 if (CHARPOS (start_pos
) < BEGV
)
9471 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9472 else if (CHARPOS (start_pos
) > ZV
)
9473 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9475 /* Find the start of the continued line. This should be fast
9476 because scan_buffer is fast (newline cache). */
9477 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9478 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9479 row
, DEFAULT_FACE_ID
);
9480 reseat_at_previous_visible_line_start (&it
);
9482 /* If the line start is "too far" away from the window start,
9483 say it takes too much time to compute a new window start. */
9484 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9485 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9487 int min_distance
, distance
;
9489 /* Move forward by display lines to find the new window
9490 start. If window width was enlarged, the new start can
9491 be expected to be > the old start. If window width was
9492 decreased, the new window start will be < the old start.
9493 So, we're looking for the display line start with the
9494 minimum distance from the old window start. */
9495 pos
= it
.current
.pos
;
9496 min_distance
= INFINITY
;
9497 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9498 distance
< min_distance
)
9500 min_distance
= distance
;
9501 pos
= it
.current
.pos
;
9502 move_it_by_lines (&it
, 1, 0);
9505 /* Set the window start there. */
9506 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9507 window_start_changed_p
= 1;
9511 return window_start_changed_p
;
9515 /* Try cursor movement in case text has not changes in window WINDOW,
9516 with window start STARTP. Value is
9520 0 if this method cannot be used
9522 -1 if we know we have to scroll the display. *SCROLL_STEP is
9523 set to 1, under certain circumstances, if we want to scroll as
9524 if scroll-step were set to 1. See the code. */
9527 try_cursor_movement (window
, startp
, scroll_step
)
9529 struct text_pos startp
;
9532 struct window
*w
= XWINDOW (window
);
9533 struct frame
*f
= XFRAME (w
->frame
);
9536 /* Handle case where text has not changed, only point, and it has
9537 not moved off the frame. */
9538 if (/* Point may be in this window. */
9539 PT
>= CHARPOS (startp
)
9540 /* Selective display hasn't changed. */
9541 && !current_buffer
->clip_changed
9542 /* Function force-mode-line-update is used to force a thorough
9543 redisplay. It sets either windows_or_buffers_changed or
9544 update_mode_lines. So don't take a shortcut here for these
9546 && !update_mode_lines
9547 && !windows_or_buffers_changed
9548 /* Can't use this case if highlighting a region. When a
9549 region exists, cursor movement has to do more than just
9551 && !(!NILP (Vtransient_mark_mode
)
9552 && !NILP (current_buffer
->mark_active
))
9553 && NILP (w
->region_showing
)
9554 && NILP (Vshow_trailing_whitespace
)
9555 /* Right after splitting windows, last_point may be nil. */
9556 && INTEGERP (w
->last_point
)
9557 /* This code is not used for mini-buffer for the sake of the case
9558 of redisplaying to replace an echo area message; since in
9559 that case the mini-buffer contents per se are usually
9560 unchanged. This code is of no real use in the mini-buffer
9561 since the handling of this_line_start_pos, etc., in redisplay
9562 handles the same cases. */
9563 && !EQ (window
, minibuf_window
)
9564 /* When splitting windows or for new windows, it happens that
9565 redisplay is called with a nil window_end_vpos or one being
9566 larger than the window. This should really be fixed in
9567 window.c. I don't have this on my list, now, so we do
9568 approximately the same as the old redisplay code. --gerd. */
9569 && INTEGERP (w
->window_end_vpos
)
9570 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9571 && (FRAME_WINDOW_P (f
)
9572 || !MARKERP (Voverlay_arrow_position
)
9573 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9575 int this_scroll_margin
;
9576 struct glyph_row
*row
;
9579 debug_method_add (w
, "cursor movement");
9582 /* Scroll if point within this distance from the top or bottom
9583 of the window. This is a pixel value. */
9584 this_scroll_margin
= max (0, scroll_margin
);
9585 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9586 this_scroll_margin
*= CANON_Y_UNIT (f
);
9588 /* Start with the row the cursor was displayed during the last
9589 not paused redisplay. Give up if that row is not valid. */
9590 if (w
->last_cursor
.vpos
< 0
9591 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9595 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9596 if (row
->mode_line_p
)
9598 if (!row
->enabled_p
)
9605 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9607 if (PT
> XFASTINT (w
->last_point
))
9609 /* Point has moved forward. */
9610 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9611 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9613 xassert (row
->enabled_p
);
9617 /* The end position of a row equals the start position
9618 of the next row. If PT is there, we would rather
9619 display it in the next line. */
9620 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9621 && MATRIX_ROW_END_CHARPOS (row
) == PT
9622 && !cursor_row_p (w
, row
))
9625 /* If within the scroll margin, scroll. Note that
9626 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9627 the next line would be drawn, and that
9628 this_scroll_margin can be zero. */
9629 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9630 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9631 /* Line is completely visible last line in window
9632 and PT is to be set in the next line. */
9633 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9634 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9635 && !row
->ends_at_zv_p
9636 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9639 else if (PT
< XFASTINT (w
->last_point
))
9641 /* Cursor has to be moved backward. Note that PT >=
9642 CHARPOS (startp) because of the outer
9644 while (!row
->mode_line_p
9645 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9646 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9647 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9648 && (row
->y
> this_scroll_margin
9649 || CHARPOS (startp
) == BEGV
))
9651 xassert (row
->enabled_p
);
9655 /* Consider the following case: Window starts at BEGV,
9656 there is invisible, intangible text at BEGV, so that
9657 display starts at some point START > BEGV. It can
9658 happen that we are called with PT somewhere between
9659 BEGV and START. Try to handle that case. */
9660 if (row
< w
->current_matrix
->rows
9661 || row
->mode_line_p
)
9663 row
= w
->current_matrix
->rows
;
9664 if (row
->mode_line_p
)
9668 /* Due to newlines in overlay strings, we may have to
9669 skip forward over overlay strings. */
9670 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9671 && MATRIX_ROW_END_CHARPOS (row
) == PT
9672 && !cursor_row_p (w
, row
))
9675 /* If within the scroll margin, scroll. */
9676 if (row
->y
< this_scroll_margin
9677 && CHARPOS (startp
) != BEGV
)
9681 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9682 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9684 /* if PT is not in the glyph row, give up. */
9687 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9689 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9690 && !row
->ends_at_zv_p
9691 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9693 else if (row
->height
> window_box_height (w
))
9695 /* If we end up in a partially visible line, let's
9696 make it fully visible, except when it's taller
9697 than the window, in which case we can't do much
9704 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9705 try_window (window
, startp
);
9706 make_cursor_line_fully_visible (w
);
9714 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9724 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9725 selected_window is redisplayed. */
9728 redisplay_window (window
, just_this_one_p
)
9730 int just_this_one_p
;
9732 struct window
*w
= XWINDOW (window
);
9733 struct frame
*f
= XFRAME (w
->frame
);
9734 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9735 struct buffer
*old
= current_buffer
;
9736 struct text_pos lpoint
, opoint
, startp
;
9737 int update_mode_line
;
9740 /* Record it now because it's overwritten. */
9741 int current_matrix_up_to_date_p
= 0;
9742 int temp_scroll_step
= 0;
9743 int count
= BINDING_STACK_SIZE ();
9746 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9749 /* W must be a leaf window here. */
9750 xassert (!NILP (w
->buffer
));
9752 *w
->desired_matrix
->method
= 0;
9755 specbind (Qinhibit_point_motion_hooks
, Qt
);
9757 reconsider_clip_changes (w
, buffer
);
9759 /* Has the mode line to be updated? */
9760 update_mode_line
= (!NILP (w
->update_mode_line
)
9761 || update_mode_lines
9762 || buffer
->clip_changed
);
9764 if (MINI_WINDOW_P (w
))
9766 if (w
== XWINDOW (echo_area_window
)
9767 && !NILP (echo_area_buffer
[0]))
9769 if (update_mode_line
)
9770 /* We may have to update a tty frame's menu bar or a
9771 tool-bar. Example `M-x C-h C-h C-g'. */
9772 goto finish_menu_bars
;
9774 /* We've already displayed the echo area glyphs in this window. */
9775 goto finish_scroll_bars
;
9777 else if (w
!= XWINDOW (minibuf_window
))
9779 /* W is a mini-buffer window, but it's not the currently
9780 active one, so clear it. */
9781 int yb
= window_text_bottom_y (w
);
9782 struct glyph_row
*row
;
9785 for (y
= 0, row
= w
->desired_matrix
->rows
;
9787 y
+= row
->height
, ++row
)
9788 blank_row (w
, row
, y
);
9789 goto finish_scroll_bars
;
9792 clear_glyph_matrix (w
->desired_matrix
);
9795 /* Otherwise set up data on this window; select its buffer and point
9797 /* Really select the buffer, for the sake of buffer-local
9799 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9800 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9802 current_matrix_up_to_date_p
9803 = (!NILP (w
->window_end_valid
)
9804 && !current_buffer
->clip_changed
9805 && XFASTINT (w
->last_modified
) >= MODIFF
9806 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9808 /* When windows_or_buffers_changed is non-zero, we can't rely on
9809 the window end being valid, so set it to nil there. */
9810 if (windows_or_buffers_changed
)
9812 /* If window starts on a continuation line, maybe adjust the
9813 window start in case the window's width changed. */
9814 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9815 compute_window_start_on_continuation_line (w
);
9817 w
->window_end_valid
= Qnil
;
9820 /* Some sanity checks. */
9821 CHECK_WINDOW_END (w
);
9822 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9824 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9827 /* If %c is in mode line, update it if needed. */
9828 if (!NILP (w
->column_number_displayed
)
9829 /* This alternative quickly identifies a common case
9830 where no change is needed. */
9831 && !(PT
== XFASTINT (w
->last_point
)
9832 && XFASTINT (w
->last_modified
) >= MODIFF
9833 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9834 && XFASTINT (w
->column_number_displayed
) != current_column ())
9835 update_mode_line
= 1;
9837 /* Count number of windows showing the selected buffer. An indirect
9838 buffer counts as its base buffer. */
9839 if (!just_this_one_p
)
9841 struct buffer
*current_base
, *window_base
;
9842 current_base
= current_buffer
;
9843 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9844 if (current_base
->base_buffer
)
9845 current_base
= current_base
->base_buffer
;
9846 if (window_base
->base_buffer
)
9847 window_base
= window_base
->base_buffer
;
9848 if (current_base
== window_base
)
9852 /* Point refers normally to the selected window. For any other
9853 window, set up appropriate value. */
9854 if (!EQ (window
, selected_window
))
9856 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9857 int new_pt_byte
= marker_byte_position (w
->pointm
);
9861 new_pt_byte
= BEGV_BYTE
;
9862 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9864 else if (new_pt
> (ZV
- 1))
9867 new_pt_byte
= ZV_BYTE
;
9868 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9871 /* We don't use SET_PT so that the point-motion hooks don't run. */
9872 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9875 /* If any of the character widths specified in the display table
9876 have changed, invalidate the width run cache. It's true that
9877 this may be a bit late to catch such changes, but the rest of
9878 redisplay goes (non-fatally) haywire when the display table is
9879 changed, so why should we worry about doing any better? */
9880 if (current_buffer
->width_run_cache
)
9882 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9884 if (! disptab_matches_widthtab (disptab
,
9885 XVECTOR (current_buffer
->width_table
)))
9887 invalidate_region_cache (current_buffer
,
9888 current_buffer
->width_run_cache
,
9890 recompute_width_table (current_buffer
, disptab
);
9894 /* If window-start is screwed up, choose a new one. */
9895 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9898 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9900 /* If someone specified a new starting point but did not insist,
9901 check whether it can be used. */
9902 if (!NILP (w
->optional_new_start
)
9903 && CHARPOS (startp
) >= BEGV
9904 && CHARPOS (startp
) <= ZV
)
9906 w
->optional_new_start
= Qnil
;
9907 start_display (&it
, w
, startp
);
9908 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9909 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9910 if (IT_CHARPOS (it
) == PT
)
9911 w
->force_start
= Qt
;
9914 /* Handle case where place to start displaying has been specified,
9915 unless the specified location is outside the accessible range. */
9916 if (!NILP (w
->force_start
)
9917 || w
->frozen_window_start_p
)
9919 w
->force_start
= Qnil
;
9921 w
->window_end_valid
= Qnil
;
9923 /* Forget any recorded base line for line number display. */
9924 if (!current_matrix_up_to_date_p
9925 || current_buffer
->clip_changed
)
9926 w
->base_line_number
= Qnil
;
9928 /* Redisplay the mode line. Select the buffer properly for that.
9929 Also, run the hook window-scroll-functions
9930 because we have scrolled. */
9931 /* Note, we do this after clearing force_start because
9932 if there's an error, it is better to forget about force_start
9933 than to get into an infinite loop calling the hook functions
9934 and having them get more errors. */
9935 if (!update_mode_line
9936 || ! NILP (Vwindow_scroll_functions
))
9938 update_mode_line
= 1;
9939 w
->update_mode_line
= Qt
;
9940 startp
= run_window_scroll_functions (window
, startp
);
9943 w
->last_modified
= make_number (0);
9944 w
->last_overlay_modified
= make_number (0);
9945 if (CHARPOS (startp
) < BEGV
)
9946 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9947 else if (CHARPOS (startp
) > ZV
)
9948 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9950 /* Redisplay, then check if cursor has been set during the
9951 redisplay. Give up if new fonts were loaded. */
9952 if (!try_window (window
, startp
))
9954 w
->force_start
= Qt
;
9955 clear_glyph_matrix (w
->desired_matrix
);
9956 goto finish_scroll_bars
;
9959 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9961 /* If point does not appear, try to move point so it does
9962 appear. The desired matrix has been built above, so we
9965 struct glyph_row
*row
;
9967 window_height
= window_box_height (w
) / 2;
9968 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9969 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9972 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9973 MATRIX_ROW_START_BYTEPOS (row
));
9975 if (w
!= XWINDOW (selected_window
))
9976 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9977 else if (current_buffer
== old
)
9978 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9980 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
9982 /* If we are highlighting the region, then we just changed
9983 the region, so redisplay to show it. */
9984 if (!NILP (Vtransient_mark_mode
)
9985 && !NILP (current_buffer
->mark_active
))
9987 clear_glyph_matrix (w
->desired_matrix
);
9988 if (!try_window (window
, startp
))
9989 goto finish_scroll_bars
;
9993 make_cursor_line_fully_visible (w
);
9995 debug_method_add (w
, "forced window start");
10000 /* Handle case where text has not changed, only point, and it has
10001 not moved off the frame. */
10002 if (current_matrix_up_to_date_p
10003 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10007 goto try_to_scroll
;
10011 /* If current starting point was originally the beginning of a line
10012 but no longer is, find a new starting point. */
10013 else if (!NILP (w
->start_at_line_beg
)
10014 && !(CHARPOS (startp
) <= BEGV
10015 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10018 debug_method_add (w
, "recenter 1");
10023 /* Try scrolling with try_window_id. Value is > 0 if update has
10024 been done, it is -1 if we know that the same window start will
10025 not work. It is 0 if unsuccessful for some other reason. */
10026 else if ((tem
= try_window_id (w
)) != 0)
10029 debug_method_add (w
, "try_window_id %d", tem
);
10032 if (fonts_changed_p
)
10033 goto finish_scroll_bars
;
10037 /* Otherwise try_window_id has returned -1 which means that we
10038 don't want the alternative below this comment to execute. */
10040 else if (CHARPOS (startp
) >= BEGV
10041 && CHARPOS (startp
) <= ZV
10042 && PT
>= CHARPOS (startp
)
10043 && (CHARPOS (startp
) < ZV
10044 /* Avoid starting at end of buffer. */
10045 || CHARPOS (startp
) == BEGV
10046 || (XFASTINT (w
->last_modified
) >= MODIFF
10047 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10050 debug_method_add (w
, "same window start");
10053 /* Try to redisplay starting at same place as before.
10054 If point has not moved off frame, accept the results. */
10055 if (!current_matrix_up_to_date_p
10056 /* Don't use try_window_reusing_current_matrix in this case
10057 because a window scroll function can have changed the
10059 || !NILP (Vwindow_scroll_functions
)
10060 || MINI_WINDOW_P (w
)
10061 || !try_window_reusing_current_matrix (w
))
10063 IF_DEBUG (debug_method_add (w
, "1"));
10064 try_window (window
, startp
);
10067 if (fonts_changed_p
)
10068 goto finish_scroll_bars
;
10070 if (w
->cursor
.vpos
>= 0)
10072 if (!just_this_one_p
10073 || current_buffer
->clip_changed
10074 || BEG_UNCHANGED
< CHARPOS (startp
))
10075 /* Forget any recorded base line for line number display. */
10076 w
->base_line_number
= Qnil
;
10078 make_cursor_line_fully_visible (w
);
10082 clear_glyph_matrix (w
->desired_matrix
);
10087 w
->last_modified
= make_number (0);
10088 w
->last_overlay_modified
= make_number (0);
10090 /* Redisplay the mode line. Select the buffer properly for that. */
10091 if (!update_mode_line
)
10093 update_mode_line
= 1;
10094 w
->update_mode_line
= Qt
;
10097 /* Try to scroll by specified few lines. */
10098 if ((scroll_conservatively
10100 || temp_scroll_step
10101 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10102 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10103 && !current_buffer
->clip_changed
10104 && CHARPOS (startp
) >= BEGV
10105 && CHARPOS (startp
) <= ZV
)
10107 /* The function returns -1 if new fonts were loaded, 1 if
10108 successful, 0 if not successful. */
10109 int rc
= try_scrolling (window
, just_this_one_p
,
10110 scroll_conservatively
,
10116 goto finish_scroll_bars
;
10119 /* Finally, just choose place to start which centers point */
10124 debug_method_add (w
, "recenter");
10127 /* w->vscroll = 0; */
10129 /* Forget any previously recorded base line for line number display. */
10130 if (!current_matrix_up_to_date_p
10131 || current_buffer
->clip_changed
)
10132 w
->base_line_number
= Qnil
;
10134 /* Move backward half the height of the window. */
10135 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10136 it
.current_y
= it
.last_visible_y
;
10137 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10138 xassert (IT_CHARPOS (it
) >= BEGV
);
10140 /* The function move_it_vertically_backward may move over more
10141 than the specified y-distance. If it->w is small, e.g. a
10142 mini-buffer window, we may end up in front of the window's
10143 display area. Start displaying at the start of the line
10144 containing PT in this case. */
10145 if (it
.current_y
<= 0)
10147 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10148 move_it_vertically (&it
, 0);
10149 xassert (IT_CHARPOS (it
) <= PT
);
10153 it
.current_x
= it
.hpos
= 0;
10155 /* Set startp here explicitly in case that helps avoid an infinite loop
10156 in case the window-scroll-functions functions get errors. */
10157 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10159 /* Run scroll hooks. */
10160 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10162 /* Redisplay the window. */
10163 if (!current_matrix_up_to_date_p
10164 || windows_or_buffers_changed
10165 /* Don't use try_window_reusing_current_matrix in this case
10166 because it can have changed the buffer. */
10167 || !NILP (Vwindow_scroll_functions
)
10168 || !just_this_one_p
10169 || MINI_WINDOW_P (w
)
10170 || !try_window_reusing_current_matrix (w
))
10171 try_window (window
, startp
);
10173 /* If new fonts have been loaded (due to fontsets), give up. We
10174 have to start a new redisplay since we need to re-adjust glyph
10176 if (fonts_changed_p
)
10177 goto finish_scroll_bars
;
10179 /* If cursor did not appear assume that the middle of the window is
10180 in the first line of the window. Do it again with the next line.
10181 (Imagine a window of height 100, displaying two lines of height
10182 60. Moving back 50 from it->last_visible_y will end in the first
10184 if (w
->cursor
.vpos
< 0)
10186 if (!NILP (w
->window_end_valid
)
10187 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10189 clear_glyph_matrix (w
->desired_matrix
);
10190 move_it_by_lines (&it
, 1, 0);
10191 try_window (window
, it
.current
.pos
);
10193 else if (PT
< IT_CHARPOS (it
))
10195 clear_glyph_matrix (w
->desired_matrix
);
10196 move_it_by_lines (&it
, -1, 0);
10197 try_window (window
, it
.current
.pos
);
10201 /* Not much we can do about it. */
10205 /* Consider the following case: Window starts at BEGV, there is
10206 invisible, intangible text at BEGV, so that display starts at
10207 some point START > BEGV. It can happen that we are called with
10208 PT somewhere between BEGV and START. Try to handle that case. */
10209 if (w
->cursor
.vpos
< 0)
10211 struct glyph_row
*row
= w
->current_matrix
->rows
;
10212 if (row
->mode_line_p
)
10214 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10217 make_cursor_line_fully_visible (w
);
10221 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10222 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10223 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10226 /* Display the mode line, if we must. */
10227 if ((update_mode_line
10228 /* If window not full width, must redo its mode line
10229 if (a) the window to its side is being redone and
10230 (b) we do a frame-based redisplay. This is a consequence
10231 of how inverted lines are drawn in frame-based redisplay. */
10232 || (!just_this_one_p
10233 && !FRAME_WINDOW_P (f
)
10234 && !WINDOW_FULL_WIDTH_P (w
))
10235 /* Line number to display. */
10236 || INTEGERP (w
->base_line_pos
)
10237 /* Column number is displayed and different from the one displayed. */
10238 || (!NILP (w
->column_number_displayed
)
10239 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10240 /* This means that the window has a mode line. */
10241 && (WINDOW_WANTS_MODELINE_P (w
)
10242 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10244 Lisp_Object old_selected_frame
;
10246 old_selected_frame
= selected_frame
;
10248 XSETFRAME (selected_frame
, f
);
10249 display_mode_lines (w
);
10250 selected_frame
= old_selected_frame
;
10252 /* If mode line height has changed, arrange for a thorough
10253 immediate redisplay using the correct mode line height. */
10254 if (WINDOW_WANTS_MODELINE_P (w
)
10255 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10257 fonts_changed_p
= 1;
10258 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10259 = DESIRED_MODE_LINE_HEIGHT (w
);
10262 /* If top line height has changed, arrange for a thorough
10263 immediate redisplay using the correct mode line height. */
10264 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10265 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10267 fonts_changed_p
= 1;
10268 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10269 = DESIRED_HEADER_LINE_HEIGHT (w
);
10272 if (fonts_changed_p
)
10273 goto finish_scroll_bars
;
10276 if (!line_number_displayed
10277 && !BUFFERP (w
->base_line_pos
))
10279 w
->base_line_pos
= Qnil
;
10280 w
->base_line_number
= Qnil
;
10285 /* When we reach a frame's selected window, redo the frame's menu bar. */
10286 if (update_mode_line
10287 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10289 int redisplay_menu_p
= 0;
10291 if (FRAME_WINDOW_P (f
))
10293 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10294 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10296 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10300 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10302 if (redisplay_menu_p
)
10303 display_menu_bar (w
);
10305 #ifdef HAVE_WINDOW_SYSTEM
10306 if (WINDOWP (f
->tool_bar_window
)
10307 && (FRAME_TOOL_BAR_LINES (f
) > 0
10308 || auto_resize_tool_bars_p
))
10309 redisplay_tool_bar (f
);
10313 finish_scroll_bars
:
10315 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10317 int start
, end
, whole
;
10319 /* Calculate the start and end positions for the current window.
10320 At some point, it would be nice to choose between scrollbars
10321 which reflect the whole buffer size, with special markers
10322 indicating narrowing, and scrollbars which reflect only the
10325 Note that mini-buffers sometimes aren't displaying any text. */
10326 if (!MINI_WINDOW_P (w
)
10327 || (w
== XWINDOW (minibuf_window
)
10328 && NILP (echo_area_buffer
[0])))
10331 start
= marker_position (w
->start
) - BEGV
;
10332 /* I don't think this is guaranteed to be right. For the
10333 moment, we'll pretend it is. */
10334 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10338 if (whole
< (end
- start
))
10339 whole
= end
- start
;
10342 start
= end
= whole
= 0;
10344 /* Indicate what this scroll bar ought to be displaying now. */
10345 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10347 /* Note that we actually used the scroll bar attached to this
10348 window, so it shouldn't be deleted at the end of redisplay. */
10349 redeem_scroll_bar_hook (w
);
10352 /* Restore current_buffer and value of point in it. */
10353 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10354 set_buffer_internal_1 (old
);
10355 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10357 unbind_to (count
, Qnil
);
10361 /* Build the complete desired matrix of WINDOW with a window start
10362 buffer position POS. Value is non-zero if successful. It is zero
10363 if fonts were loaded during redisplay which makes re-adjusting
10364 glyph matrices necessary. */
10367 try_window (window
, pos
)
10368 Lisp_Object window
;
10369 struct text_pos pos
;
10371 struct window
*w
= XWINDOW (window
);
10373 struct glyph_row
*last_text_row
= NULL
;
10375 /* Make POS the new window start. */
10376 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10378 /* Mark cursor position as unknown. No overlay arrow seen. */
10379 w
->cursor
.vpos
= -1;
10380 overlay_arrow_seen
= 0;
10382 /* Initialize iterator and info to start at POS. */
10383 start_display (&it
, w
, pos
);
10385 /* Display all lines of W. */
10386 while (it
.current_y
< it
.last_visible_y
)
10388 if (display_line (&it
))
10389 last_text_row
= it
.glyph_row
- 1;
10390 if (fonts_changed_p
)
10394 /* If bottom moved off end of frame, change mode line percentage. */
10395 if (XFASTINT (w
->window_end_pos
) <= 0
10396 && Z
!= IT_CHARPOS (it
))
10397 w
->update_mode_line
= Qt
;
10399 /* Set window_end_pos to the offset of the last character displayed
10400 on the window from the end of current_buffer. Set
10401 window_end_vpos to its row number. */
10404 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10405 w
->window_end_bytepos
10406 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10408 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10410 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10411 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10412 ->displays_text_p
);
10416 w
->window_end_bytepos
= 0;
10417 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10420 /* But that is not valid info until redisplay finishes. */
10421 w
->window_end_valid
= Qnil
;
10427 /************************************************************************
10428 Window redisplay reusing current matrix when buffer has not changed
10429 ************************************************************************/
10431 /* Try redisplay of window W showing an unchanged buffer with a
10432 different window start than the last time it was displayed by
10433 reusing its current matrix. Value is non-zero if successful.
10434 W->start is the new window start. */
10437 try_window_reusing_current_matrix (w
)
10440 struct frame
*f
= XFRAME (w
->frame
);
10441 struct glyph_row
*row
, *bottom_row
;
10444 struct text_pos start
, new_start
;
10445 int nrows_scrolled
, i
;
10446 struct glyph_row
*last_text_row
;
10447 struct glyph_row
*last_reused_text_row
;
10448 struct glyph_row
*start_row
;
10449 int start_vpos
, min_y
, max_y
;
10451 if (/* This function doesn't handle terminal frames. */
10452 !FRAME_WINDOW_P (f
)
10453 /* Don't try to reuse the display if windows have been split
10455 || windows_or_buffers_changed
)
10458 /* Can't do this if region may have changed. */
10459 if ((!NILP (Vtransient_mark_mode
)
10460 && !NILP (current_buffer
->mark_active
))
10461 || !NILP (w
->region_showing
)
10462 || !NILP (Vshow_trailing_whitespace
))
10465 /* If top-line visibility has changed, give up. */
10466 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10467 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10470 /* Give up if old or new display is scrolled vertically. We could
10471 make this function handle this, but right now it doesn't. */
10472 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10473 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10476 /* The variable new_start now holds the new window start. The old
10477 start `start' can be determined from the current matrix. */
10478 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10479 start
= start_row
->start
.pos
;
10480 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10482 /* Clear the desired matrix for the display below. */
10483 clear_glyph_matrix (w
->desired_matrix
);
10485 if (CHARPOS (new_start
) <= CHARPOS (start
))
10489 /* Don't use this method if the display starts with an ellipsis
10490 displayed for invisible text. It's not easy to handle that case
10491 below, and it's certainly not worth the effort since this is
10492 not a frequent case. */
10493 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10496 IF_DEBUG (debug_method_add (w
, "twu1"));
10498 /* Display up to a row that can be reused. The variable
10499 last_text_row is set to the last row displayed that displays
10500 text. Note that it.vpos == 0 if or if not there is a
10501 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10502 start_display (&it
, w
, new_start
);
10503 first_row_y
= it
.current_y
;
10504 w
->cursor
.vpos
= -1;
10505 last_text_row
= last_reused_text_row
= NULL
;
10507 while (it
.current_y
< it
.last_visible_y
10508 && IT_CHARPOS (it
) < CHARPOS (start
)
10509 && !fonts_changed_p
)
10510 if (display_line (&it
))
10511 last_text_row
= it
.glyph_row
- 1;
10513 /* A value of current_y < last_visible_y means that we stopped
10514 at the previous window start, which in turn means that we
10515 have at least one reusable row. */
10516 if (it
.current_y
< it
.last_visible_y
)
10518 /* IT.vpos always starts from 0; it counts text lines. */
10519 nrows_scrolled
= it
.vpos
;
10521 /* Find PT if not already found in the lines displayed. */
10522 if (w
->cursor
.vpos
< 0)
10524 int dy
= it
.current_y
- first_row_y
;
10526 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10527 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10529 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
10530 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10532 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10533 dy
, nrows_scrolled
);
10537 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10543 /* Give up if point was not found. This shouldn't
10544 happen often; not more often than with try_window
10546 if (w
->cursor
.vpos
< 0)
10548 clear_glyph_matrix (w
->desired_matrix
);
10553 /* Scroll the display. Do it before the current matrix is
10554 changed. The problem here is that update has not yet
10555 run, i.e. part of the current matrix is not up to date.
10556 scroll_run_hook will clear the cursor, and use the
10557 current matrix to get the height of the row the cursor is
10559 run
.current_y
= first_row_y
;
10560 run
.desired_y
= it
.current_y
;
10561 run
.height
= it
.last_visible_y
- it
.current_y
;
10563 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10566 rif
->update_window_begin_hook (w
);
10567 rif
->clear_mouse_face (w
);
10568 rif
->scroll_run_hook (w
, &run
);
10569 rif
->update_window_end_hook (w
, 0, 0);
10573 /* Shift current matrix down by nrows_scrolled lines. */
10574 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10575 rotate_matrix (w
->current_matrix
,
10577 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10580 /* Disable lines that must be updated. */
10581 for (i
= 0; i
< it
.vpos
; ++i
)
10582 (start_row
+ i
)->enabled_p
= 0;
10584 /* Re-compute Y positions. */
10585 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10586 max_y
= it
.last_visible_y
;
10587 for (row
= start_row
+ nrows_scrolled
;
10591 row
->y
= it
.current_y
;
10593 if (row
->y
< min_y
)
10594 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10595 else if (row
->y
+ row
->height
> max_y
)
10596 row
->visible_height
10597 = row
->height
- (row
->y
+ row
->height
- max_y
);
10599 row
->visible_height
= row
->height
;
10601 it
.current_y
+= row
->height
;
10603 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10604 last_reused_text_row
= row
;
10605 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10609 /* Disable lines in the current matrix which are now
10610 below the window. */
10611 for (++row
; row
< bottom_row
; ++row
)
10612 row
->enabled_p
= 0;
10615 /* Update window_end_pos etc.; last_reused_text_row is the last
10616 reused row from the current matrix containing text, if any.
10617 The value of last_text_row is the last displayed line
10618 containing text. */
10619 if (last_reused_text_row
)
10621 w
->window_end_bytepos
10622 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10624 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10626 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10627 w
->current_matrix
));
10629 else if (last_text_row
)
10631 w
->window_end_bytepos
10632 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10634 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10636 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10640 /* This window must be completely empty. */
10641 w
->window_end_bytepos
= 0;
10642 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10644 w
->window_end_valid
= Qnil
;
10646 /* Update hint: don't try scrolling again in update_window. */
10647 w
->desired_matrix
->no_scrolling_p
= 1;
10650 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10654 else if (CHARPOS (new_start
) > CHARPOS (start
))
10656 struct glyph_row
*pt_row
, *row
;
10657 struct glyph_row
*first_reusable_row
;
10658 struct glyph_row
*first_row_to_display
;
10660 int yb
= window_text_bottom_y (w
);
10662 /* Find the row starting at new_start, if there is one. Don't
10663 reuse a partially visible line at the end. */
10664 first_reusable_row
= start_row
;
10665 while (first_reusable_row
->enabled_p
10666 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10667 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10668 < CHARPOS (new_start
)))
10669 ++first_reusable_row
;
10671 /* Give up if there is no row to reuse. */
10672 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10673 || !first_reusable_row
->enabled_p
10674 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10675 != CHARPOS (new_start
)))
10678 /* We can reuse fully visible rows beginning with
10679 first_reusable_row to the end of the window. Set
10680 first_row_to_display to the first row that cannot be reused.
10681 Set pt_row to the row containing point, if there is any. */
10683 for (first_row_to_display
= first_reusable_row
;
10684 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10685 ++first_row_to_display
)
10687 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10688 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10689 pt_row
= first_row_to_display
;
10692 /* Start displaying at the start of first_row_to_display. */
10693 xassert (first_row_to_display
->y
< yb
);
10694 init_to_row_start (&it
, w
, first_row_to_display
);
10696 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10698 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10700 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10701 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10703 /* Display lines beginning with first_row_to_display in the
10704 desired matrix. Set last_text_row to the last row displayed
10705 that displays text. */
10706 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10707 if (pt_row
== NULL
)
10708 w
->cursor
.vpos
= -1;
10709 last_text_row
= NULL
;
10710 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10711 if (display_line (&it
))
10712 last_text_row
= it
.glyph_row
- 1;
10714 /* Give up If point isn't in a row displayed or reused. */
10715 if (w
->cursor
.vpos
< 0)
10717 clear_glyph_matrix (w
->desired_matrix
);
10721 /* If point is in a reused row, adjust y and vpos of the cursor
10725 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10726 w
->current_matrix
);
10727 w
->cursor
.y
-= first_reusable_row
->y
;
10730 /* Scroll the display. */
10731 run
.current_y
= first_reusable_row
->y
;
10732 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10733 run
.height
= it
.last_visible_y
- run
.current_y
;
10734 dy
= run
.current_y
- run
.desired_y
;
10738 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10740 rif
->update_window_begin_hook (w
);
10741 rif
->clear_mouse_face (w
);
10742 rif
->scroll_run_hook (w
, &run
);
10743 rif
->update_window_end_hook (w
, 0, 0);
10747 /* Adjust Y positions of reused rows. */
10748 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10749 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10750 max_y
= it
.last_visible_y
;
10751 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10754 if (row
->y
< min_y
)
10755 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10756 else if (row
->y
+ row
->height
> max_y
)
10757 row
->visible_height
10758 = row
->height
- (row
->y
+ row
->height
- max_y
);
10760 row
->visible_height
= row
->height
;
10763 /* Scroll the current matrix. */
10764 xassert (nrows_scrolled
> 0);
10765 rotate_matrix (w
->current_matrix
,
10767 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10770 /* Disable rows not reused. */
10771 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
10772 row
->enabled_p
= 0;
10774 /* Adjust window end. A null value of last_text_row means that
10775 the window end is in reused rows which in turn means that
10776 only its vpos can have changed. */
10779 w
->window_end_bytepos
10780 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10782 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10784 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10789 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10792 w
->window_end_valid
= Qnil
;
10793 w
->desired_matrix
->no_scrolling_p
= 1;
10796 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10806 /************************************************************************
10807 Window redisplay reusing current matrix when buffer has changed
10808 ************************************************************************/
10810 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10811 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10813 static struct glyph_row
*
10814 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10815 struct glyph_row
*));
10818 /* Return the last row in MATRIX displaying text. If row START is
10819 non-null, start searching with that row. IT gives the dimensions
10820 of the display. Value is null if matrix is empty; otherwise it is
10821 a pointer to the row found. */
10823 static struct glyph_row
*
10824 find_last_row_displaying_text (matrix
, it
, start
)
10825 struct glyph_matrix
*matrix
;
10827 struct glyph_row
*start
;
10829 struct glyph_row
*row
, *row_found
;
10831 /* Set row_found to the last row in IT->w's current matrix
10832 displaying text. The loop looks funny but think of partially
10835 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10836 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10838 xassert (row
->enabled_p
);
10840 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10849 /* Return the last row in the current matrix of W that is not affected
10850 by changes at the start of current_buffer that occurred since W's
10851 current matrix was built. Value is null if no such row exists.
10853 BEG_UNCHANGED us the number of characters unchanged at the start of
10854 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
10855 first changed character in current_buffer. Characters at positions <
10856 BEG + BEG_UNCHANGED are at the same buffer positions as they were
10857 when the current matrix was built. */
10859 static struct glyph_row
*
10860 find_last_unchanged_at_beg_row (w
)
10863 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10864 struct glyph_row
*row
;
10865 struct glyph_row
*row_found
= NULL
;
10866 int yb
= window_text_bottom_y (w
);
10868 /* Find the last row displaying unchanged text. */
10869 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10870 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10871 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10873 if (/* If row ends before first_changed_pos, it is unchanged,
10874 except in some case. */
10875 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10876 /* When row ends in ZV and we write at ZV it is not
10878 && !row
->ends_at_zv_p
10879 /* When first_changed_pos is the end of a continued line,
10880 row is not unchanged because it may be no longer
10882 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10883 && row
->continued_p
))
10886 /* Stop if last visible row. */
10887 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10897 /* Find the first glyph row in the current matrix of W that is not
10898 affected by changes at the end of current_buffer since the
10899 time W's current matrix was built.
10901 Return in *DELTA the number of chars by which buffer positions in
10902 unchanged text at the end of current_buffer must be adjusted.
10904 Return in *DELTA_BYTES the corresponding number of bytes.
10906 Value is null if no such row exists, i.e. all rows are affected by
10909 static struct glyph_row
*
10910 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10912 int *delta
, *delta_bytes
;
10914 struct glyph_row
*row
;
10915 struct glyph_row
*row_found
= NULL
;
10917 *delta
= *delta_bytes
= 0;
10919 /* Display must not have been paused, otherwise the current matrix
10920 is not up to date. */
10921 if (NILP (w
->window_end_valid
))
10924 /* A value of window_end_pos >= END_UNCHANGED means that the window
10925 end is in the range of changed text. If so, there is no
10926 unchanged row at the end of W's current matrix. */
10927 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10930 /* Set row to the last row in W's current matrix displaying text. */
10931 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10933 /* If matrix is entirely empty, no unchanged row exists. */
10934 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10936 /* The value of row is the last glyph row in the matrix having a
10937 meaningful buffer position in it. The end position of row
10938 corresponds to window_end_pos. This allows us to translate
10939 buffer positions in the current matrix to current buffer
10940 positions for characters not in changed text. */
10941 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10942 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10943 int last_unchanged_pos
, last_unchanged_pos_old
;
10944 struct glyph_row
*first_text_row
10945 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10947 *delta
= Z
- Z_old
;
10948 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10950 /* Set last_unchanged_pos to the buffer position of the last
10951 character in the buffer that has not been changed. Z is the
10952 index + 1 of the last character in current_buffer, i.e. by
10953 subtracting END_UNCHANGED we get the index of the last
10954 unchanged character, and we have to add BEG to get its buffer
10956 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10957 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10959 /* Search backward from ROW for a row displaying a line that
10960 starts at a minimum position >= last_unchanged_pos_old. */
10961 for (; row
> first_text_row
; --row
)
10963 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10966 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10971 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
10978 /* Make sure that glyph rows in the current matrix of window W
10979 reference the same glyph memory as corresponding rows in the
10980 frame's frame matrix. This function is called after scrolling W's
10981 current matrix on a terminal frame in try_window_id and
10982 try_window_reusing_current_matrix. */
10985 sync_frame_with_window_matrix_rows (w
)
10988 struct frame
*f
= XFRAME (w
->frame
);
10989 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10991 /* Preconditions: W must be a leaf window and full-width. Its frame
10992 must have a frame matrix. */
10993 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10994 xassert (WINDOW_FULL_WIDTH_P (w
));
10995 xassert (!FRAME_WINDOW_P (f
));
10997 /* If W is a full-width window, glyph pointers in W's current matrix
10998 have, by definition, to be the same as glyph pointers in the
10999 corresponding frame matrix. */
11000 window_row
= w
->current_matrix
->rows
;
11001 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11002 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11003 while (window_row
< window_row_end
)
11007 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11008 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11010 /* Disable frame rows whose corresponding window rows have
11011 been disabled in try_window_id. */
11012 if (!window_row
->enabled_p
)
11013 frame_row
->enabled_p
= 0;
11015 ++window_row
, ++frame_row
;
11020 /* Find the glyph row in window W containing CHARPOS. Consider all
11021 rows between START and END (not inclusive). END null means search
11022 all rows to the end of the display area of W. Value is the row
11023 containing CHARPOS or null. */
11025 static struct glyph_row
*
11026 row_containing_pos (w
, charpos
, start
, end
)
11029 struct glyph_row
*start
, *end
;
11031 struct glyph_row
*row
= start
;
11034 /* If we happen to start on a header-line, skip that. */
11035 if (row
->mode_line_p
)
11038 if ((end
&& row
>= end
) || !row
->enabled_p
)
11041 last_y
= window_text_bottom_y (w
);
11043 while ((end
== NULL
|| row
< end
)
11044 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11045 /* The end position of a row equals the start
11046 position of the next row. If CHARPOS is there, we
11047 would rather display it in the next line, except
11048 when this line ends in ZV. */
11049 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11050 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11051 || !row
->ends_at_zv_p
)))
11052 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11055 /* Give up if CHARPOS not found. */
11056 if ((end
&& row
>= end
)
11057 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11058 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11065 /* Try to redisplay window W by reusing its existing display. W's
11066 current matrix must be up to date when this function is called,
11067 i.e. window_end_valid must not be nil.
11071 1 if display has been updated
11072 0 if otherwise unsuccessful
11073 -1 if redisplay with same window start is known not to succeed
11075 The following steps are performed:
11077 1. Find the last row in the current matrix of W that is not
11078 affected by changes at the start of current_buffer. If no such row
11081 2. Find the first row in W's current matrix that is not affected by
11082 changes at the end of current_buffer. Maybe there is no such row.
11084 3. Display lines beginning with the row + 1 found in step 1 to the
11085 row found in step 2 or, if step 2 didn't find a row, to the end of
11088 4. If cursor is not known to appear on the window, give up.
11090 5. If display stopped at the row found in step 2, scroll the
11091 display and current matrix as needed.
11093 6. Maybe display some lines at the end of W, if we must. This can
11094 happen under various circumstances, like a partially visible line
11095 becoming fully visible, or because newly displayed lines are displayed
11096 in smaller font sizes.
11098 7. Update W's window end information. */
11104 struct frame
*f
= XFRAME (w
->frame
);
11105 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11106 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11107 struct glyph_row
*last_unchanged_at_beg_row
;
11108 struct glyph_row
*first_unchanged_at_end_row
;
11109 struct glyph_row
*row
;
11110 struct glyph_row
*bottom_row
;
11113 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11114 struct text_pos start_pos
;
11116 int first_unchanged_at_end_vpos
= 0;
11117 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11118 struct text_pos start
;
11119 int first_changed_charpos
, last_changed_charpos
;
11121 /* This is handy for debugging. */
11123 #define GIVE_UP(X) \
11125 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11129 #define GIVE_UP(X) return 0
11132 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11134 /* Don't use this for mini-windows because these can show
11135 messages and mini-buffers, and we don't handle that here. */
11136 if (MINI_WINDOW_P (w
))
11139 /* This flag is used to prevent redisplay optimizations. */
11140 if (windows_or_buffers_changed
)
11143 /* Verify that narrowing has not changed. This flag is also set to prevent
11144 redisplay optimizations. It would be nice to further
11145 reduce the number of cases where this prevents try_window_id. */
11146 if (current_buffer
->clip_changed
)
11149 /* Window must either use window-based redisplay or be full width. */
11150 if (!FRAME_WINDOW_P (f
)
11151 && (!line_ins_del_ok
11152 || !WINDOW_FULL_WIDTH_P (w
)))
11155 /* Give up if point is not known NOT to appear in W. */
11156 if (PT
< CHARPOS (start
))
11159 /* Another way to prevent redisplay optimizations. */
11160 if (XFASTINT (w
->last_modified
) == 0)
11163 /* Verify that window is not hscrolled. */
11164 if (XFASTINT (w
->hscroll
) != 0)
11167 /* Verify that display wasn't paused. */
11168 if (NILP (w
->window_end_valid
))
11171 /* Can't use this if highlighting a region because a cursor movement
11172 will do more than just set the cursor. */
11173 if (!NILP (Vtransient_mark_mode
)
11174 && !NILP (current_buffer
->mark_active
))
11177 /* Likewise if highlighting trailing whitespace. */
11178 if (!NILP (Vshow_trailing_whitespace
))
11181 /* Likewise if showing a region. */
11182 if (!NILP (w
->region_showing
))
11185 /* Can use this if overlay arrow position and or string have changed. */
11186 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11187 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11191 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11192 only if buffer has really changed. The reason is that the gap is
11193 initially at Z for freshly visited files. The code below would
11194 set end_unchanged to 0 in that case. */
11195 if (MODIFF
> SAVE_MODIFF
11196 /* This seems to happen sometimes after saving a buffer. */
11197 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11199 if (GPT
- BEG
< BEG_UNCHANGED
)
11200 BEG_UNCHANGED
= GPT
- BEG
;
11201 if (Z
- GPT
< END_UNCHANGED
)
11202 END_UNCHANGED
= Z
- GPT
;
11205 /* The position of the first and last character that has been changed. */
11206 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11207 last_changed_charpos
= Z
- END_UNCHANGED
;
11209 /* If window starts after a line end, and the last change is in
11210 front of that newline, then changes don't affect the display.
11211 This case happens with stealth-fontification. Note that although
11212 the display is unchanged, glyph positions in the matrix have to
11213 be adjusted, of course. */
11214 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11215 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11216 && ((last_changed_charpos
< CHARPOS (start
)
11217 && CHARPOS (start
) == BEGV
)
11218 || (last_changed_charpos
< CHARPOS (start
) - 1
11219 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11221 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11222 struct glyph_row
*r0
;
11224 /* Compute how many chars/bytes have been added to or removed
11225 from the buffer. */
11226 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11227 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11229 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11231 /* Give up if PT is not in the window. Note that it already has
11232 been checked at the start of try_window_id that PT is not in
11233 front of the window start. */
11234 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11237 /* If window start is unchanged, we can reuse the whole matrix
11238 as is, after adjusting glyph positions. No need to compute
11239 the window end again, since its offset from Z hasn't changed. */
11240 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11241 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11242 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11244 /* Adjust positions in the glyph matrix. */
11245 if (delta
|| delta_bytes
)
11247 struct glyph_row
*r1
11248 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11249 increment_matrix_positions (w
->current_matrix
,
11250 MATRIX_ROW_VPOS (r0
, current_matrix
),
11251 MATRIX_ROW_VPOS (r1
, current_matrix
),
11252 delta
, delta_bytes
);
11255 /* Set the cursor. */
11256 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11257 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11262 /* Handle the case that changes are all below what is displayed in
11263 the window, and that PT is in the window. This shortcut cannot
11264 be taken if ZV is visible in the window, and text has been added
11265 there that is visible in the window. */
11266 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11267 /* ZV is not visible in the window, or there are no
11268 changes at ZV, actually. */
11269 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11270 || first_changed_charpos
== last_changed_charpos
))
11272 struct glyph_row
*r0
;
11274 /* Give up if PT is not in the window. Note that it already has
11275 been checked at the start of try_window_id that PT is not in
11276 front of the window start. */
11277 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11280 /* If window start is unchanged, we can reuse the whole matrix
11281 as is, without changing glyph positions since no text has
11282 been added/removed in front of the window end. */
11283 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11284 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11286 /* We have to compute the window end anew since text
11287 can have been added/removed after it. */
11289 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11290 w
->window_end_bytepos
11291 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11293 /* Set the cursor. */
11294 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11295 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11300 /* Give up if window start is in the changed area.
11302 The condition used to read
11304 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11306 but why that was tested escapes me at the moment. */
11307 if (CHARPOS (start
) >= first_changed_charpos
11308 && CHARPOS (start
) <= last_changed_charpos
)
11311 /* Check that window start agrees with the start of the first glyph
11312 row in its current matrix. Check this after we know the window
11313 start is not in changed text, otherwise positions would not be
11315 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11316 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11319 /* Compute the position at which we have to start displaying new
11320 lines. Some of the lines at the top of the window might be
11321 reusable because they are not displaying changed text. Find the
11322 last row in W's current matrix not affected by changes at the
11323 start of current_buffer. Value is null if changes start in the
11324 first line of window. */
11325 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11326 if (last_unchanged_at_beg_row
)
11328 /* Avoid starting to display in the moddle of a character, a TAB
11329 for instance. This is easier than to set up the iterator
11330 exactly, and it's not a frequent case, so the additional
11331 effort wouldn't really pay off. */
11332 while (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11333 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11334 --last_unchanged_at_beg_row
;
11336 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11339 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
11340 start_pos
= it
.current
.pos
;
11342 /* Start displaying new lines in the desired matrix at the same
11343 vpos we would use in the current matrix, i.e. below
11344 last_unchanged_at_beg_row. */
11345 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11347 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11348 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11350 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11354 /* There are no reusable lines at the start of the window.
11355 Start displaying in the first line. */
11356 start_display (&it
, w
, start
);
11357 start_pos
= it
.current
.pos
;
11360 /* Find the first row that is not affected by changes at the end of
11361 the buffer. Value will be null if there is no unchanged row, in
11362 which case we must redisplay to the end of the window. delta
11363 will be set to the value by which buffer positions beginning with
11364 first_unchanged_at_end_row have to be adjusted due to text
11366 first_unchanged_at_end_row
11367 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11368 IF_DEBUG (debug_delta
= delta
);
11369 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11371 /* Set stop_pos to the buffer position up to which we will have to
11372 display new lines. If first_unchanged_at_end_row != NULL, this
11373 is the buffer position of the start of the line displayed in that
11374 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11375 that we don't stop at a buffer position. */
11377 if (first_unchanged_at_end_row
)
11379 xassert (last_unchanged_at_beg_row
== NULL
11380 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11382 /* If this is a continuation line, move forward to the next one
11383 that isn't. Changes in lines above affect this line.
11384 Caution: this may move first_unchanged_at_end_row to a row
11385 not displaying text. */
11386 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11387 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11388 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11389 < it
.last_visible_y
))
11390 ++first_unchanged_at_end_row
;
11392 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11393 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11394 >= it
.last_visible_y
))
11395 first_unchanged_at_end_row
= NULL
;
11398 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11400 first_unchanged_at_end_vpos
11401 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11402 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11405 else if (last_unchanged_at_beg_row
== NULL
)
11411 /* Either there is no unchanged row at the end, or the one we have
11412 now displays text. This is a necessary condition for the window
11413 end pos calculation at the end of this function. */
11414 xassert (first_unchanged_at_end_row
== NULL
11415 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11417 debug_last_unchanged_at_beg_vpos
11418 = (last_unchanged_at_beg_row
11419 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11421 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11423 #endif /* GLYPH_DEBUG != 0 */
11426 /* Display new lines. Set last_text_row to the last new line
11427 displayed which has text on it, i.e. might end up as being the
11428 line where the window_end_vpos is. */
11429 w
->cursor
.vpos
= -1;
11430 last_text_row
= NULL
;
11431 overlay_arrow_seen
= 0;
11432 while (it
.current_y
< it
.last_visible_y
11433 && !fonts_changed_p
11434 && (first_unchanged_at_end_row
== NULL
11435 || IT_CHARPOS (it
) < stop_pos
))
11437 if (display_line (&it
))
11438 last_text_row
= it
.glyph_row
- 1;
11441 if (fonts_changed_p
)
11445 /* Compute differences in buffer positions, y-positions etc. for
11446 lines reused at the bottom of the window. Compute what we can
11448 if (first_unchanged_at_end_row
11449 /* No lines reused because we displayed everything up to the
11450 bottom of the window. */
11451 && it
.current_y
< it
.last_visible_y
)
11454 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11456 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11457 run
.current_y
= first_unchanged_at_end_row
->y
;
11458 run
.desired_y
= run
.current_y
+ dy
;
11459 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11463 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11464 first_unchanged_at_end_row
= NULL
;
11466 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11469 /* Find the cursor if not already found. We have to decide whether
11470 PT will appear on this window (it sometimes doesn't, but this is
11471 not a very frequent case.) This decision has to be made before
11472 the current matrix is altered. A value of cursor.vpos < 0 means
11473 that PT is either in one of the lines beginning at
11474 first_unchanged_at_end_row or below the window. Don't care for
11475 lines that might be displayed later at the window end; as
11476 mentioned, this is not a frequent case. */
11477 if (w
->cursor
.vpos
< 0)
11479 /* Cursor in unchanged rows at the top? */
11480 if (PT
< CHARPOS (start_pos
)
11481 && last_unchanged_at_beg_row
)
11483 row
= row_containing_pos (w
, PT
,
11484 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11485 last_unchanged_at_beg_row
+ 1);
11487 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11490 /* Start from first_unchanged_at_end_row looking for PT. */
11491 else if (first_unchanged_at_end_row
)
11493 row
= row_containing_pos (w
, PT
- delta
,
11494 first_unchanged_at_end_row
, NULL
);
11496 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11497 delta_bytes
, dy
, dvpos
);
11500 /* Give up if cursor was not found. */
11501 if (w
->cursor
.vpos
< 0)
11503 clear_glyph_matrix (w
->desired_matrix
);
11508 /* Don't let the cursor end in the scroll margins. */
11510 int this_scroll_margin
, cursor_height
;
11512 this_scroll_margin
= max (0, scroll_margin
);
11513 this_scroll_margin
= min (this_scroll_margin
,
11514 XFASTINT (w
->height
) / 4);
11515 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11516 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11518 if ((w
->cursor
.y
< this_scroll_margin
11519 && CHARPOS (start
) > BEGV
)
11520 /* Don't take scroll margin into account at the bottom because
11521 old redisplay didn't do it either. */
11522 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11524 w
->cursor
.vpos
= -1;
11525 clear_glyph_matrix (w
->desired_matrix
);
11530 /* Scroll the display. Do it before changing the current matrix so
11531 that xterm.c doesn't get confused about where the cursor glyph is
11533 if (dy
&& run
.height
)
11537 if (FRAME_WINDOW_P (f
))
11539 rif
->update_window_begin_hook (w
);
11540 rif
->clear_mouse_face (w
);
11541 rif
->scroll_run_hook (w
, &run
);
11542 rif
->update_window_end_hook (w
, 0, 0);
11546 /* Terminal frame. In this case, dvpos gives the number of
11547 lines to scroll by; dvpos < 0 means scroll up. */
11548 int first_unchanged_at_end_vpos
11549 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11550 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11551 int end
= (XFASTINT (w
->top
)
11552 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11553 + window_internal_height (w
));
11555 /* Perform the operation on the screen. */
11558 /* Scroll last_unchanged_at_beg_row to the end of the
11559 window down dvpos lines. */
11560 set_terminal_window (end
);
11562 /* On dumb terminals delete dvpos lines at the end
11563 before inserting dvpos empty lines. */
11564 if (!scroll_region_ok
)
11565 ins_del_lines (end
- dvpos
, -dvpos
);
11567 /* Insert dvpos empty lines in front of
11568 last_unchanged_at_beg_row. */
11569 ins_del_lines (from
, dvpos
);
11571 else if (dvpos
< 0)
11573 /* Scroll up last_unchanged_at_beg_vpos to the end of
11574 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11575 set_terminal_window (end
);
11577 /* Delete dvpos lines in front of
11578 last_unchanged_at_beg_vpos. ins_del_lines will set
11579 the cursor to the given vpos and emit |dvpos| delete
11581 ins_del_lines (from
+ dvpos
, dvpos
);
11583 /* On a dumb terminal insert dvpos empty lines at the
11585 if (!scroll_region_ok
)
11586 ins_del_lines (end
+ dvpos
, -dvpos
);
11589 set_terminal_window (0);
11595 /* Shift reused rows of the current matrix to the right position.
11596 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11598 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11599 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11602 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11603 bottom_vpos
, dvpos
);
11604 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11607 else if (dvpos
> 0)
11609 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11610 bottom_vpos
, dvpos
);
11611 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11612 first_unchanged_at_end_vpos
+ dvpos
, 0);
11615 /* For frame-based redisplay, make sure that current frame and window
11616 matrix are in sync with respect to glyph memory. */
11617 if (!FRAME_WINDOW_P (f
))
11618 sync_frame_with_window_matrix_rows (w
);
11620 /* Adjust buffer positions in reused rows. */
11622 increment_matrix_positions (current_matrix
,
11623 first_unchanged_at_end_vpos
+ dvpos
,
11624 bottom_vpos
, delta
, delta_bytes
);
11626 /* Adjust Y positions. */
11628 shift_glyph_matrix (w
, current_matrix
,
11629 first_unchanged_at_end_vpos
+ dvpos
,
11632 if (first_unchanged_at_end_row
)
11633 first_unchanged_at_end_row
+= dvpos
;
11635 /* If scrolling up, there may be some lines to display at the end of
11637 last_text_row_at_end
= NULL
;
11640 /* Set last_row to the glyph row in the current matrix where the
11641 window end line is found. It has been moved up or down in
11642 the matrix by dvpos. */
11643 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11644 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11646 /* If last_row is the window end line, it should display text. */
11647 xassert (last_row
->displays_text_p
);
11649 /* If window end line was partially visible before, begin
11650 displaying at that line. Otherwise begin displaying with the
11651 line following it. */
11652 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11654 init_to_row_start (&it
, w
, last_row
);
11655 it
.vpos
= last_vpos
;
11656 it
.current_y
= last_row
->y
;
11660 init_to_row_end (&it
, w
, last_row
);
11661 it
.vpos
= 1 + last_vpos
;
11662 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11666 /* We may start in a continuation line. If so, we have to get
11667 the right continuation_lines_width and current_x. */
11668 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11669 it
.hpos
= it
.current_x
= 0;
11671 /* Display the rest of the lines at the window end. */
11672 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11673 while (it
.current_y
< it
.last_visible_y
11674 && !fonts_changed_p
)
11676 /* Is it always sure that the display agrees with lines in
11677 the current matrix? I don't think so, so we mark rows
11678 displayed invalid in the current matrix by setting their
11679 enabled_p flag to zero. */
11680 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11681 if (display_line (&it
))
11682 last_text_row_at_end
= it
.glyph_row
- 1;
11686 /* Update window_end_pos and window_end_vpos. */
11687 if (first_unchanged_at_end_row
11688 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11689 && !last_text_row_at_end
)
11691 /* Window end line if one of the preserved rows from the current
11692 matrix. Set row to the last row displaying text in current
11693 matrix starting at first_unchanged_at_end_row, after
11695 xassert (first_unchanged_at_end_row
->displays_text_p
);
11696 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11697 first_unchanged_at_end_row
);
11698 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11700 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11701 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11703 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11704 xassert (w
->window_end_bytepos
>= 0);
11705 IF_DEBUG (debug_method_add (w
, "A"));
11707 else if (last_text_row_at_end
)
11710 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11711 w
->window_end_bytepos
11712 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11714 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11715 xassert (w
->window_end_bytepos
>= 0);
11716 IF_DEBUG (debug_method_add (w
, "B"));
11718 else if (last_text_row
)
11720 /* We have displayed either to the end of the window or at the
11721 end of the window, i.e. the last row with text is to be found
11722 in the desired matrix. */
11724 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11725 w
->window_end_bytepos
11726 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11728 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11729 xassert (w
->window_end_bytepos
>= 0);
11731 else if (first_unchanged_at_end_row
== NULL
11732 && last_text_row
== NULL
11733 && last_text_row_at_end
== NULL
)
11735 /* Displayed to end of window, but no line containing text was
11736 displayed. Lines were deleted at the end of the window. */
11737 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11738 int vpos
= XFASTINT (w
->window_end_vpos
);
11739 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
11740 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
11743 row
== NULL
&& vpos
>= first_vpos
;
11744 --vpos
, --current_row
, --desired_row
)
11746 if (desired_row
->enabled_p
)
11748 if (desired_row
->displays_text_p
)
11751 else if (current_row
->displays_text_p
)
11755 xassert (row
!= NULL
);
11756 w
->window_end_vpos
= make_number (vpos
+ 1);
11757 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11758 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11759 xassert (w
->window_end_bytepos
>= 0);
11760 IF_DEBUG (debug_method_add (w
, "C"));
11765 #if 0 /* This leads to problems, for instance when the cursor is
11766 at ZV, and the cursor line displays no text. */
11767 /* Disable rows below what's displayed in the window. This makes
11768 debugging easier. */
11769 enable_glyph_matrix_rows (current_matrix
,
11770 XFASTINT (w
->window_end_vpos
) + 1,
11774 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11775 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11777 /* Record that display has not been completed. */
11778 w
->window_end_valid
= Qnil
;
11779 w
->desired_matrix
->no_scrolling_p
= 1;
11787 /***********************************************************************
11788 More debugging support
11789 ***********************************************************************/
11793 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11794 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11795 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
11798 /* Dump the contents of glyph matrix MATRIX on stderr.
11800 GLYPHS 0 means don't show glyph contents.
11801 GLYPHS 1 means show glyphs in short form
11802 GLYPHS > 1 means show glyphs in long form. */
11805 dump_glyph_matrix (matrix
, glyphs
)
11806 struct glyph_matrix
*matrix
;
11810 for (i
= 0; i
< matrix
->nrows
; ++i
)
11811 dump_glyph_row (matrix
, i
, glyphs
);
11815 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
11816 the glyph row and area where the glyph comes from. */
11819 dump_glyph (row
, glyph
, area
)
11820 struct glyph_row
*row
;
11821 struct glyph
*glyph
;
11824 if (glyph
->type
== CHAR_GLYPH
)
11827 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11828 glyph
- row
->glyphs
[TEXT_AREA
],
11831 (BUFFERP (glyph
->object
)
11833 : (STRINGP (glyph
->object
)
11836 glyph
->pixel_width
,
11838 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11842 glyph
->left_box_line_p
,
11843 glyph
->right_box_line_p
);
11845 else if (glyph
->type
== STRETCH_GLYPH
)
11848 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11849 glyph
- row
->glyphs
[TEXT_AREA
],
11852 (BUFFERP (glyph
->object
)
11854 : (STRINGP (glyph
->object
)
11857 glyph
->pixel_width
,
11861 glyph
->left_box_line_p
,
11862 glyph
->right_box_line_p
);
11864 else if (glyph
->type
== IMAGE_GLYPH
)
11867 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11868 glyph
- row
->glyphs
[TEXT_AREA
],
11871 (BUFFERP (glyph
->object
)
11873 : (STRINGP (glyph
->object
)
11876 glyph
->pixel_width
,
11880 glyph
->left_box_line_p
,
11881 glyph
->right_box_line_p
);
11886 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11887 GLYPHS 0 means don't show glyph contents.
11888 GLYPHS 1 means show glyphs in short form
11889 GLYPHS > 1 means show glyphs in long form. */
11892 dump_glyph_row (matrix
, vpos
, glyphs
)
11893 struct glyph_matrix
*matrix
;
11896 struct glyph_row
*row
;
11898 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11901 row
= MATRIX_ROW (matrix
, vpos
);
11905 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
11906 fprintf (stderr
, "=======================================================================\n");
11908 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11909 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11910 row
- matrix
->rows
,
11911 MATRIX_ROW_START_CHARPOS (row
),
11912 MATRIX_ROW_END_CHARPOS (row
),
11913 row
->used
[TEXT_AREA
],
11914 row
->contains_overlapping_glyphs_p
,
11917 row
->truncated_on_left_p
,
11918 row
->truncated_on_right_p
,
11919 row
->overlay_arrow_p
,
11921 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11922 row
->displays_text_p
,
11925 row
->ends_in_middle_of_char_p
,
11926 row
->starts_in_middle_of_char_p
,
11932 row
->visible_height
,
11935 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
11936 row
->end
.overlay_string_index
,
11937 row
->continuation_lines_width
);
11938 fprintf (stderr
, "%9d %5d\n",
11939 CHARPOS (row
->start
.string_pos
),
11940 CHARPOS (row
->end
.string_pos
));
11941 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
11942 row
->end
.dpvec_index
);
11949 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11951 struct glyph
*glyph
= row
->glyphs
[area
];
11952 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
11954 /* Glyph for a line end in text. */
11955 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
11958 if (glyph
< glyph_end
)
11959 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11961 for (; glyph
< glyph_end
; ++glyph
)
11962 dump_glyph (row
, glyph
, area
);
11965 else if (glyphs
== 1)
11969 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11971 char *s
= (char *) alloca (row
->used
[area
] + 1);
11974 for (i
= 0; i
< row
->used
[area
]; ++i
)
11976 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
11977 if (glyph
->type
== CHAR_GLYPH
11978 && glyph
->u
.ch
< 0x80
11979 && glyph
->u
.ch
>= ' ')
11980 s
[i
] = glyph
->u
.ch
;
11986 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
11992 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
11993 Sdump_glyph_matrix
, 0, 1, "p",
11994 "Dump the current matrix of the selected window to stderr.\n\
11995 Shows contents of glyph row structures. With non-nil\n\
11996 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show\n\
11997 glyphs in short form, otherwise show glyphs in long form.")
11999 Lisp_Object glyphs
;
12001 struct window
*w
= XWINDOW (selected_window
);
12002 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12004 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12005 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12006 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12007 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12008 fprintf (stderr
, "=============================================\n");
12009 dump_glyph_matrix (w
->current_matrix
,
12010 NILP (glyphs
) ? 0 : XINT (glyphs
));
12015 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12016 "Dump glyph row ROW to stderr.\n\
12017 GLYPH 0 means don't dump glyphs.\n\
12018 GLYPH 1 means dump glyphs in short form.\n\
12019 GLYPH > 1 or omitted means dump glyphs in long form.")
12021 Lisp_Object row
, glyphs
;
12023 CHECK_NUMBER (row
, 0);
12024 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
,
12026 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12031 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12032 "Dump glyph row ROW of the tool-bar of the current frame to stderr.\n\
12033 GLYPH 0 means don't dump glyphs.\n\
12034 GLYPH 1 means dump glyphs in short form.\n\
12035 GLYPH > 1 or omitted means dump glyphs in long form.")
12037 Lisp_Object row
, glyphs
;
12039 struct frame
*sf
= SELECTED_FRAME ();
12040 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)->current_matrix
);
12041 dump_glyph_row (m
, XINT (row
), INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12046 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12047 "Toggle tracing of redisplay.\n\
12048 With ARG, turn tracing on if and only if ARG is positive.")
12053 trace_redisplay_p
= !trace_redisplay_p
;
12056 arg
= Fprefix_numeric_value (arg
);
12057 trace_redisplay_p
= XINT (arg
) > 0;
12064 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
12065 "Print STRING to stderr.")
12067 Lisp_Object string
;
12069 CHECK_STRING (string
, 0);
12070 fprintf (stderr
, "%s", XSTRING (string
)->data
);
12074 #endif /* GLYPH_DEBUG */
12078 /***********************************************************************
12079 Building Desired Matrix Rows
12080 ***********************************************************************/
12082 /* Return a temporary glyph row holding the glyphs of an overlay
12083 arrow. Only used for non-window-redisplay windows. */
12085 static struct glyph_row
*
12086 get_overlay_arrow_glyph_row (w
)
12089 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12090 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12091 struct buffer
*old
= current_buffer
;
12092 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
12093 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
12094 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12098 int n_glyphs_before
;
12100 set_buffer_temp (buffer
);
12101 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12102 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12103 SET_TEXT_POS (it
.position
, 0, 0);
12105 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12107 while (p
< arrow_end
)
12109 Lisp_Object face
, ilisp
;
12111 /* Get the next character. */
12113 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12115 it
.c
= *p
, it
.len
= 1;
12118 /* Get its face. */
12119 ilisp
= make_number (p
- arrow_string
);
12120 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12121 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12123 /* Compute its width, get its glyphs. */
12124 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12125 SET_TEXT_POS (it
.position
, -1, -1);
12126 PRODUCE_GLYPHS (&it
);
12128 /* If this character doesn't fit any more in the line, we have
12129 to remove some glyphs. */
12130 if (it
.current_x
> it
.last_visible_x
)
12132 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12137 set_buffer_temp (old
);
12138 return it
.glyph_row
;
12142 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12143 glyphs are only inserted for terminal frames since we can't really
12144 win with truncation glyphs when partially visible glyphs are
12145 involved. Which glyphs to insert is determined by
12146 produce_special_glyphs. */
12149 insert_left_trunc_glyphs (it
)
12152 struct it truncate_it
;
12153 struct glyph
*from
, *end
, *to
, *toend
;
12155 xassert (!FRAME_WINDOW_P (it
->f
));
12157 /* Get the truncation glyphs. */
12159 truncate_it
.current_x
= 0;
12160 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12161 truncate_it
.glyph_row
= &scratch_glyph_row
;
12162 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12163 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12164 truncate_it
.object
= make_number (0);
12165 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12167 /* Overwrite glyphs from IT with truncation glyphs. */
12168 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12169 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12170 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12171 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12176 /* There may be padding glyphs left over. Overwrite them too. */
12177 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12179 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12185 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12189 /* Compute the pixel height and width of IT->glyph_row.
12191 Most of the time, ascent and height of a display line will be equal
12192 to the max_ascent and max_height values of the display iterator
12193 structure. This is not the case if
12195 1. We hit ZV without displaying anything. In this case, max_ascent
12196 and max_height will be zero.
12198 2. We have some glyphs that don't contribute to the line height.
12199 (The glyph row flag contributes_to_line_height_p is for future
12200 pixmap extensions).
12202 The first case is easily covered by using default values because in
12203 these cases, the line height does not really matter, except that it
12204 must not be zero. */
12207 compute_line_metrics (it
)
12210 struct glyph_row
*row
= it
->glyph_row
;
12213 if (FRAME_WINDOW_P (it
->f
))
12215 int i
, header_line_height
;
12217 /* The line may consist of one space only, that was added to
12218 place the cursor on it. If so, the row's height hasn't been
12220 if (row
->height
== 0)
12222 if (it
->max_ascent
+ it
->max_descent
== 0)
12223 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12224 row
->ascent
= it
->max_ascent
;
12225 row
->height
= it
->max_ascent
+ it
->max_descent
;
12226 row
->phys_ascent
= it
->max_phys_ascent
;
12227 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12230 /* Compute the width of this line. */
12231 row
->pixel_width
= row
->x
;
12232 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12233 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12235 xassert (row
->pixel_width
>= 0);
12236 xassert (row
->ascent
>= 0 && row
->height
> 0);
12238 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12239 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12241 /* If first line's physical ascent is larger than its logical
12242 ascent, use the physical ascent, and make the row taller.
12243 This makes accented characters fully visible. */
12244 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12245 && row
->phys_ascent
> row
->ascent
)
12247 row
->height
+= row
->phys_ascent
- row
->ascent
;
12248 row
->ascent
= row
->phys_ascent
;
12251 /* Compute how much of the line is visible. */
12252 row
->visible_height
= row
->height
;
12254 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12255 if (row
->y
< header_line_height
)
12256 row
->visible_height
-= header_line_height
- row
->y
;
12259 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12260 if (row
->y
+ row
->height
> max_y
)
12261 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12266 row
->pixel_width
= row
->used
[TEXT_AREA
];
12267 if (row
->continued_p
)
12268 row
->pixel_width
-= it
->continuation_pixel_width
;
12269 else if (row
->truncated_on_right_p
)
12270 row
->pixel_width
-= it
->truncation_pixel_width
;
12271 row
->ascent
= row
->phys_ascent
= 0;
12272 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12275 /* Compute a hash code for this row. */
12277 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12278 for (i
= 0; i
< row
->used
[area
]; ++i
)
12279 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12280 + row
->glyphs
[area
][i
].u
.val
12281 + row
->glyphs
[area
][i
].face_id
12282 + row
->glyphs
[area
][i
].padding_p
12283 + (row
->glyphs
[area
][i
].type
<< 2));
12285 it
->max_ascent
= it
->max_descent
= 0;
12286 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12290 /* Append one space to the glyph row of iterator IT if doing a
12291 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12292 space have the default face, otherwise let it have the same face as
12293 IT->face_id. Value is non-zero if a space was added.
12295 This function is called to make sure that there is always one glyph
12296 at the end of a glyph row that the cursor can be set on under
12297 window-systems. (If there weren't such a glyph we would not know
12298 how wide and tall a box cursor should be displayed).
12300 At the same time this space let's a nicely handle clearing to the
12301 end of the line if the row ends in italic text. */
12304 append_space (it
, default_face_p
)
12306 int default_face_p
;
12308 if (FRAME_WINDOW_P (it
->f
))
12310 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12312 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12313 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12315 /* Save some values that must not be changed.
12316 Must save IT->c and IT->len because otherwise
12317 ITERATOR_AT_END_P wouldn't work anymore after
12318 append_space has been called. */
12319 enum display_element_type saved_what
= it
->what
;
12320 int saved_c
= it
->c
, saved_len
= it
->len
;
12321 int saved_x
= it
->current_x
;
12322 int saved_face_id
= it
->face_id
;
12323 struct text_pos saved_pos
;
12324 Lisp_Object saved_object
;
12327 saved_object
= it
->object
;
12328 saved_pos
= it
->position
;
12330 it
->what
= IT_CHARACTER
;
12331 bzero (&it
->position
, sizeof it
->position
);
12332 it
->object
= make_number (0);
12336 if (default_face_p
)
12337 it
->face_id
= DEFAULT_FACE_ID
;
12338 else if (it
->face_before_selective_p
)
12339 it
->face_id
= it
->saved_face_id
;
12340 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12341 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12343 PRODUCE_GLYPHS (it
);
12345 it
->current_x
= saved_x
;
12346 it
->object
= saved_object
;
12347 it
->position
= saved_pos
;
12348 it
->what
= saved_what
;
12349 it
->face_id
= saved_face_id
;
12350 it
->len
= saved_len
;
12360 /* Extend the face of the last glyph in the text area of IT->glyph_row
12361 to the end of the display line. Called from display_line.
12362 If the glyph row is empty, add a space glyph to it so that we
12363 know the face to draw. Set the glyph row flag fill_line_p. */
12366 extend_face_to_end_of_line (it
)
12370 struct frame
*f
= it
->f
;
12372 /* If line is already filled, do nothing. */
12373 if (it
->current_x
>= it
->last_visible_x
)
12376 /* Face extension extends the background and box of IT->face_id
12377 to the end of the line. If the background equals the background
12378 of the frame, we don't have to do anything. */
12379 if (it
->face_before_selective_p
)
12380 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12382 face
= FACE_FROM_ID (f
, it
->face_id
);
12384 if (FRAME_WINDOW_P (f
)
12385 && face
->box
== FACE_NO_BOX
12386 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12390 /* Set the glyph row flag indicating that the face of the last glyph
12391 in the text area has to be drawn to the end of the text area. */
12392 it
->glyph_row
->fill_line_p
= 1;
12394 /* If current character of IT is not ASCII, make sure we have the
12395 ASCII face. This will be automatically undone the next time
12396 get_next_display_element returns a multibyte character. Note
12397 that the character will always be single byte in unibyte text. */
12398 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12400 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12403 if (FRAME_WINDOW_P (f
))
12405 /* If the row is empty, add a space with the current face of IT,
12406 so that we know which face to draw. */
12407 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12409 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12410 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12411 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12416 /* Save some values that must not be changed. */
12417 int saved_x
= it
->current_x
;
12418 struct text_pos saved_pos
;
12419 Lisp_Object saved_object
;
12420 enum display_element_type saved_what
= it
->what
;
12421 int saved_face_id
= it
->face_id
;
12423 saved_object
= it
->object
;
12424 saved_pos
= it
->position
;
12426 it
->what
= IT_CHARACTER
;
12427 bzero (&it
->position
, sizeof it
->position
);
12428 it
->object
= make_number (0);
12431 it
->face_id
= face
->id
;
12433 PRODUCE_GLYPHS (it
);
12435 while (it
->current_x
<= it
->last_visible_x
)
12436 PRODUCE_GLYPHS (it
);
12438 /* Don't count these blanks really. It would let us insert a left
12439 truncation glyph below and make us set the cursor on them, maybe. */
12440 it
->current_x
= saved_x
;
12441 it
->object
= saved_object
;
12442 it
->position
= saved_pos
;
12443 it
->what
= saved_what
;
12444 it
->face_id
= saved_face_id
;
12449 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12450 trailing whitespace. */
12453 trailing_whitespace_p (charpos
)
12456 int bytepos
= CHAR_TO_BYTE (charpos
);
12459 while (bytepos
< ZV_BYTE
12460 && (c
= FETCH_CHAR (bytepos
),
12461 c
== ' ' || c
== '\t'))
12464 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12466 if (bytepos
!= PT_BYTE
)
12473 /* Highlight trailing whitespace, if any, in ROW. */
12476 highlight_trailing_whitespace (f
, row
)
12478 struct glyph_row
*row
;
12480 int used
= row
->used
[TEXT_AREA
];
12484 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12485 struct glyph
*glyph
= start
+ used
- 1;
12487 /* Skip over glyphs inserted to display the cursor at the
12488 end of a line, for extending the face of the last glyph
12489 to the end of the line on terminals, and for truncation
12490 and continuation glyphs. */
12491 while (glyph
>= start
12492 && glyph
->type
== CHAR_GLYPH
12493 && INTEGERP (glyph
->object
))
12496 /* If last glyph is a space or stretch, and it's trailing
12497 whitespace, set the face of all trailing whitespace glyphs in
12498 IT->glyph_row to `trailing-whitespace'. */
12500 && BUFFERP (glyph
->object
)
12501 && (glyph
->type
== STRETCH_GLYPH
12502 || (glyph
->type
== CHAR_GLYPH
12503 && glyph
->u
.ch
== ' '))
12504 && trailing_whitespace_p (glyph
->charpos
))
12506 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12508 while (glyph
>= start
12509 && BUFFERP (glyph
->object
)
12510 && (glyph
->type
== STRETCH_GLYPH
12511 || (glyph
->type
== CHAR_GLYPH
12512 && glyph
->u
.ch
== ' ')))
12513 (glyph
--)->face_id
= face_id
;
12519 /* Value is non-zero if glyph row ROW in window W should be
12520 used to hold the cursor. */
12523 cursor_row_p (w
, row
)
12525 struct glyph_row
*row
;
12527 int cursor_row_p
= 1;
12529 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12531 /* If the row ends with a newline from a string, we don't want
12532 the cursor there (if the row is continued it doesn't end in a
12534 if (CHARPOS (row
->end
.string_pos
) >= 0
12535 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12536 cursor_row_p
= row
->continued_p
;
12538 /* If the row ends at ZV, display the cursor at the end of that
12539 row instead of at the start of the row below. */
12540 else if (row
->ends_at_zv_p
)
12546 return cursor_row_p
;
12550 /* Construct the glyph row IT->glyph_row in the desired matrix of
12551 IT->w from text at the current position of IT. See dispextern.h
12552 for an overview of struct it. Value is non-zero if
12553 IT->glyph_row displays text, as opposed to a line displaying ZV
12560 struct glyph_row
*row
= it
->glyph_row
;
12562 /* We always start displaying at hpos zero even if hscrolled. */
12563 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12565 /* We must not display in a row that's not a text row. */
12566 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12567 < it
->w
->desired_matrix
->nrows
);
12569 /* Is IT->w showing the region? */
12570 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12572 /* Clear the result glyph row and enable it. */
12573 prepare_desired_row (row
);
12575 row
->y
= it
->current_y
;
12576 row
->start
= it
->current
;
12577 row
->continuation_lines_width
= it
->continuation_lines_width
;
12578 row
->displays_text_p
= 1;
12579 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12580 it
->starts_in_middle_of_char_p
= 0;
12582 /* Arrange the overlays nicely for our purposes. Usually, we call
12583 display_line on only one line at a time, in which case this
12584 can't really hurt too much, or we call it on lines which appear
12585 one after another in the buffer, in which case all calls to
12586 recenter_overlay_lists but the first will be pretty cheap. */
12587 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12589 /* Move over display elements that are not visible because we are
12590 hscrolled. This may stop at an x-position < IT->first_visible_x
12591 if the first glyph is partially visible or if we hit a line end. */
12592 if (it
->current_x
< it
->first_visible_x
)
12593 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12594 MOVE_TO_POS
| MOVE_TO_X
);
12596 /* Get the initial row height. This is either the height of the
12597 text hscrolled, if there is any, or zero. */
12598 row
->ascent
= it
->max_ascent
;
12599 row
->height
= it
->max_ascent
+ it
->max_descent
;
12600 row
->phys_ascent
= it
->max_phys_ascent
;
12601 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12603 /* Loop generating characters. The loop is left with IT on the next
12604 character to display. */
12607 int n_glyphs_before
, hpos_before
, x_before
;
12609 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12611 /* Retrieve the next thing to display. Value is zero if end of
12613 if (!get_next_display_element (it
))
12615 /* Maybe add a space at the end of this line that is used to
12616 display the cursor there under X. Set the charpos of the
12617 first glyph of blank lines not corresponding to any text
12619 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12620 || row
->used
[TEXT_AREA
] == 0)
12622 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12623 row
->displays_text_p
= 0;
12625 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
12626 row
->indicate_empty_line_p
= 1;
12629 it
->continuation_lines_width
= 0;
12630 row
->ends_at_zv_p
= 1;
12634 /* Now, get the metrics of what we want to display. This also
12635 generates glyphs in `row' (which is IT->glyph_row). */
12636 n_glyphs_before
= row
->used
[TEXT_AREA
];
12639 /* Remember the line height so far in case the next element doesn't
12640 fit on the line. */
12641 if (!it
->truncate_lines_p
)
12643 ascent
= it
->max_ascent
;
12644 descent
= it
->max_descent
;
12645 phys_ascent
= it
->max_phys_ascent
;
12646 phys_descent
= it
->max_phys_descent
;
12649 PRODUCE_GLYPHS (it
);
12651 /* If this display element was in marginal areas, continue with
12653 if (it
->area
!= TEXT_AREA
)
12655 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12656 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12657 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12658 row
->phys_height
= max (row
->phys_height
,
12659 it
->max_phys_ascent
+ it
->max_phys_descent
);
12660 set_iterator_to_next (it
, 1);
12664 /* Does the display element fit on the line? If we truncate
12665 lines, we should draw past the right edge of the window. If
12666 we don't truncate, we want to stop so that we can display the
12667 continuation glyph before the right margin. If lines are
12668 continued, there are two possible strategies for characters
12669 resulting in more than 1 glyph (e.g. tabs): Display as many
12670 glyphs as possible in this line and leave the rest for the
12671 continuation line, or display the whole element in the next
12672 line. Original redisplay did the former, so we do it also. */
12673 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12674 hpos_before
= it
->hpos
;
12677 if (/* Not a newline. */
12679 /* Glyphs produced fit entirely in the line. */
12680 && it
->current_x
< it
->last_visible_x
)
12682 it
->hpos
+= nglyphs
;
12683 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12684 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12685 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12686 row
->phys_height
= max (row
->phys_height
,
12687 it
->max_phys_ascent
+ it
->max_phys_descent
);
12688 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12689 row
->x
= x
- it
->first_visible_x
;
12694 struct glyph
*glyph
;
12696 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12698 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12699 new_x
= x
+ glyph
->pixel_width
;
12701 if (/* Lines are continued. */
12702 !it
->truncate_lines_p
12703 && (/* Glyph doesn't fit on the line. */
12704 new_x
> it
->last_visible_x
12705 /* Or it fits exactly on a window system frame. */
12706 || (new_x
== it
->last_visible_x
12707 && FRAME_WINDOW_P (it
->f
))))
12709 /* End of a continued line. */
12712 || (new_x
== it
->last_visible_x
12713 && FRAME_WINDOW_P (it
->f
)))
12715 /* Current glyph is the only one on the line or
12716 fits exactly on the line. We must continue
12717 the line because we can't draw the cursor
12718 after the glyph. */
12719 row
->continued_p
= 1;
12720 it
->current_x
= new_x
;
12721 it
->continuation_lines_width
+= new_x
;
12723 if (i
== nglyphs
- 1)
12724 set_iterator_to_next (it
, 1);
12726 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12727 && !FRAME_WINDOW_P (it
->f
))
12729 /* A padding glyph that doesn't fit on this line.
12730 This means the whole character doesn't fit
12732 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12734 /* Fill the rest of the row with continuation
12735 glyphs like in 20.x. */
12736 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12737 < row
->glyphs
[1 + TEXT_AREA
])
12738 produce_special_glyphs (it
, IT_CONTINUATION
);
12740 row
->continued_p
= 1;
12741 it
->current_x
= x_before
;
12742 it
->continuation_lines_width
+= x_before
;
12744 /* Restore the height to what it was before the
12745 element not fitting on the line. */
12746 it
->max_ascent
= ascent
;
12747 it
->max_descent
= descent
;
12748 it
->max_phys_ascent
= phys_ascent
;
12749 it
->max_phys_descent
= phys_descent
;
12753 /* Display element draws past the right edge of
12754 the window. Restore positions to values
12755 before the element. The next line starts
12756 with current_x before the glyph that could
12757 not be displayed, so that TAB works right. */
12758 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12760 /* Display continuation glyphs. */
12761 if (!FRAME_WINDOW_P (it
->f
))
12762 produce_special_glyphs (it
, IT_CONTINUATION
);
12763 row
->continued_p
= 1;
12766 it
->continuation_lines_width
+= x
;
12767 if (nglyphs
> 1 && i
> 0)
12769 row
->ends_in_middle_of_char_p
= 1;
12770 it
->starts_in_middle_of_char_p
= 1;
12773 /* Restore the height to what it was before the
12774 element not fitting on the line. */
12775 it
->max_ascent
= ascent
;
12776 it
->max_descent
= descent
;
12777 it
->max_phys_ascent
= phys_ascent
;
12778 it
->max_phys_descent
= phys_descent
;
12783 else if (new_x
> it
->first_visible_x
)
12785 /* Increment number of glyphs actually displayed. */
12788 if (x
< it
->first_visible_x
)
12789 /* Glyph is partially visible, i.e. row starts at
12790 negative X position. */
12791 row
->x
= x
- it
->first_visible_x
;
12795 /* Glyph is completely off the left margin of the
12796 window. This should not happen because of the
12797 move_it_in_display_line at the start of
12803 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12804 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12805 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12806 row
->phys_height
= max (row
->phys_height
,
12807 it
->max_phys_ascent
+ it
->max_phys_descent
);
12809 /* End of this display line if row is continued. */
12810 if (row
->continued_p
)
12814 /* Is this a line end? If yes, we're also done, after making
12815 sure that a non-default face is extended up to the right
12816 margin of the window. */
12817 if (ITERATOR_AT_END_OF_LINE_P (it
))
12819 int used_before
= row
->used
[TEXT_AREA
];
12821 /* Add a space at the end of the line that is used to
12822 display the cursor there. */
12823 append_space (it
, 0);
12825 /* Extend the face to the end of the line. */
12826 extend_face_to_end_of_line (it
);
12828 /* Make sure we have the position. */
12829 if (used_before
== 0)
12830 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12832 /* Consume the line end. This skips over invisible lines. */
12833 set_iterator_to_next (it
, 1);
12834 it
->continuation_lines_width
= 0;
12838 /* Proceed with next display element. Note that this skips
12839 over lines invisible because of selective display. */
12840 set_iterator_to_next (it
, 1);
12842 /* If we truncate lines, we are done when the last displayed
12843 glyphs reach past the right margin of the window. */
12844 if (it
->truncate_lines_p
12845 && (FRAME_WINDOW_P (it
->f
)
12846 ? (it
->current_x
>= it
->last_visible_x
)
12847 : (it
->current_x
> it
->last_visible_x
)))
12849 /* Maybe add truncation glyphs. */
12850 if (!FRAME_WINDOW_P (it
->f
))
12854 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
12855 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
12858 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
12860 row
->used
[TEXT_AREA
] = i
;
12861 produce_special_glyphs (it
, IT_TRUNCATION
);
12865 row
->truncated_on_right_p
= 1;
12866 it
->continuation_lines_width
= 0;
12867 reseat_at_next_visible_line_start (it
, 0);
12868 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12869 it
->hpos
= hpos_before
;
12870 it
->current_x
= x_before
;
12875 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12876 at the left window margin. */
12877 if (it
->first_visible_x
12878 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12880 if (!FRAME_WINDOW_P (it
->f
))
12881 insert_left_trunc_glyphs (it
);
12882 row
->truncated_on_left_p
= 1;
12885 /* If the start of this line is the overlay arrow-position, then
12886 mark this glyph row as the one containing the overlay arrow.
12887 This is clearly a mess with variable size fonts. It would be
12888 better to let it be displayed like cursors under X. */
12889 if (MARKERP (Voverlay_arrow_position
)
12890 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12891 && (MATRIX_ROW_START_CHARPOS (row
)
12892 == marker_position (Voverlay_arrow_position
))
12893 && STRINGP (Voverlay_arrow_string
)
12894 && ! overlay_arrow_seen
)
12896 /* Overlay arrow in window redisplay is a bitmap. */
12897 if (!FRAME_WINDOW_P (it
->f
))
12899 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12900 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12901 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12902 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12903 struct glyph
*p2
, *end
;
12905 /* Copy the arrow glyphs. */
12906 while (glyph
< arrow_end
)
12909 /* Throw away padding glyphs. */
12911 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12912 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12918 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12922 overlay_arrow_seen
= 1;
12923 row
->overlay_arrow_p
= 1;
12926 /* Compute pixel dimensions of this line. */
12927 compute_line_metrics (it
);
12929 /* Remember the position at which this line ends. */
12930 row
->end
= it
->current
;
12932 /* Maybe set the cursor. */
12933 if (it
->w
->cursor
.vpos
< 0
12934 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12935 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12936 && cursor_row_p (it
->w
, row
))
12937 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
12939 /* Highlight trailing whitespace. */
12940 if (!NILP (Vshow_trailing_whitespace
))
12941 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
12943 /* Prepare for the next line. This line starts horizontally at (X
12944 HPOS) = (0 0). Vertical positions are incremented. As a
12945 convenience for the caller, IT->glyph_row is set to the next
12947 it
->current_x
= it
->hpos
= 0;
12948 it
->current_y
+= row
->height
;
12951 return row
->displays_text_p
;
12956 /***********************************************************************
12958 ***********************************************************************/
12960 /* Redisplay the menu bar in the frame for window W.
12962 The menu bar of X frames that don't have X toolkit support is
12963 displayed in a special window W->frame->menu_bar_window.
12965 The menu bar of terminal frames is treated specially as far as
12966 glyph matrices are concerned. Menu bar lines are not part of
12967 windows, so the update is done directly on the frame matrix rows
12968 for the menu bar. */
12971 display_menu_bar (w
)
12974 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12979 /* Don't do all this for graphical frames. */
12981 if (!NILP (Vwindow_system
))
12984 #ifdef USE_X_TOOLKIT
12989 if (FRAME_MAC_P (f
))
12993 #ifdef USE_X_TOOLKIT
12994 xassert (!FRAME_WINDOW_P (f
));
12995 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
12996 it
.first_visible_x
= 0;
12997 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12998 #else /* not USE_X_TOOLKIT */
12999 if (FRAME_WINDOW_P (f
))
13001 /* Menu bar lines are displayed in the desired matrix of the
13002 dummy window menu_bar_window. */
13003 struct window
*menu_w
;
13004 xassert (WINDOWP (f
->menu_bar_window
));
13005 menu_w
= XWINDOW (f
->menu_bar_window
);
13006 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13008 it
.first_visible_x
= 0;
13009 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13013 /* This is a TTY frame, i.e. character hpos/vpos are used as
13015 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13017 it
.first_visible_x
= 0;
13018 it
.last_visible_x
= FRAME_WIDTH (f
);
13020 #endif /* not USE_X_TOOLKIT */
13022 if (! mode_line_inverse_video
)
13023 /* Force the menu-bar to be displayed in the default face. */
13024 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13026 /* Clear all rows of the menu bar. */
13027 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13029 struct glyph_row
*row
= it
.glyph_row
+ i
;
13030 clear_glyph_row (row
);
13031 row
->enabled_p
= 1;
13032 row
->full_width_p
= 1;
13035 /* Display all items of the menu bar. */
13036 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13037 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13039 Lisp_Object string
;
13041 /* Stop at nil string. */
13042 string
= AREF (items
, i
+ 1);
13046 /* Remember where item was displayed. */
13047 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13049 /* Display the item, pad with one space. */
13050 if (it
.current_x
< it
.last_visible_x
)
13051 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13052 XSTRING (string
)->size
+ 1, 0, 0, -1);
13055 /* Fill out the line with spaces. */
13056 if (it
.current_x
< it
.last_visible_x
)
13057 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13059 /* Compute the total height of the lines. */
13060 compute_line_metrics (&it
);
13065 /***********************************************************************
13067 ***********************************************************************/
13069 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13070 FORCE is non-zero, redisplay mode lines unconditionally.
13071 Otherwise, redisplay only mode lines that are garbaged. Value is
13072 the number of windows whose mode lines were redisplayed. */
13075 redisplay_mode_lines (window
, force
)
13076 Lisp_Object window
;
13081 while (!NILP (window
))
13083 struct window
*w
= XWINDOW (window
);
13085 if (WINDOWP (w
->hchild
))
13086 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13087 else if (WINDOWP (w
->vchild
))
13088 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13090 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13091 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13093 Lisp_Object old_selected_frame
;
13094 struct text_pos lpoint
;
13095 struct buffer
*old
= current_buffer
;
13097 /* Set the window's buffer for the mode line display. */
13098 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13099 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13101 /* Point refers normally to the selected window. For any
13102 other window, set up appropriate value. */
13103 if (!EQ (window
, selected_window
))
13105 struct text_pos pt
;
13107 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13108 if (CHARPOS (pt
) < BEGV
)
13109 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13110 else if (CHARPOS (pt
) > (ZV
- 1))
13111 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13113 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13116 /* Temporarily set up the selected frame. */
13117 old_selected_frame
= selected_frame
;
13118 selected_frame
= w
->frame
;
13120 /* Display mode lines. */
13121 clear_glyph_matrix (w
->desired_matrix
);
13122 if (display_mode_lines (w
))
13125 w
->must_be_updated_p
= 1;
13128 /* Restore old settings. */
13129 selected_frame
= old_selected_frame
;
13130 set_buffer_internal_1 (old
);
13131 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13141 /* Display the mode and/or top line of window W. Value is the number
13142 of mode lines displayed. */
13145 display_mode_lines (w
)
13150 /* These will be set while the mode line specs are processed. */
13151 line_number_displayed
= 0;
13152 w
->column_number_displayed
= Qnil
;
13154 if (WINDOW_WANTS_MODELINE_P (w
))
13156 display_mode_line (w
, MODE_LINE_FACE_ID
,
13157 current_buffer
->mode_line_format
);
13161 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13163 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13164 current_buffer
->header_line_format
);
13172 /* Display mode or top line of window W. FACE_ID specifies which line
13173 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13174 FORMAT is the mode line format to display. Value is the pixel
13175 height of the mode line displayed. */
13178 display_mode_line (w
, face_id
, format
)
13180 enum face_id face_id
;
13181 Lisp_Object format
;
13186 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13187 prepare_desired_row (it
.glyph_row
);
13189 if (! mode_line_inverse_video
)
13190 /* Force the mode-line to be displayed in the default face. */
13191 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13193 /* Temporarily make frame's keyboard the current kboard so that
13194 kboard-local variables in the mode_line_format will get the right
13196 push_frame_kboard (it
.f
);
13197 display_mode_element (&it
, 0, 0, 0, format
);
13198 pop_frame_kboard ();
13200 /* Fill up with spaces. */
13201 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13203 compute_line_metrics (&it
);
13204 it
.glyph_row
->full_width_p
= 1;
13205 it
.glyph_row
->mode_line_p
= 1;
13206 it
.glyph_row
->inverse_p
= 0;
13207 it
.glyph_row
->continued_p
= 0;
13208 it
.glyph_row
->truncated_on_left_p
= 0;
13209 it
.glyph_row
->truncated_on_right_p
= 0;
13211 /* Make a 3D mode-line have a shadow at its right end. */
13212 face
= FACE_FROM_ID (it
.f
, face_id
);
13213 extend_face_to_end_of_line (&it
);
13214 if (face
->box
!= FACE_NO_BOX
)
13216 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13217 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13218 last
->right_box_line_p
= 1;
13221 return it
.glyph_row
->height
;
13225 /* Contribute ELT to the mode line for window IT->w. How it
13226 translates into text depends on its data type.
13228 IT describes the display environment in which we display, as usual.
13230 DEPTH is the depth in recursion. It is used to prevent
13231 infinite recursion here.
13233 FIELD_WIDTH is the number of characters the display of ELT should
13234 occupy in the mode line, and PRECISION is the maximum number of
13235 characters to display from ELT's representation. See
13236 display_string for details. *
13238 Returns the hpos of the end of the text generated by ELT. */
13241 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13244 int field_width
, precision
;
13247 int n
= 0, field
, prec
;
13255 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13259 /* A string: output it and check for %-constructs within it. */
13261 unsigned char *this = XSTRING (elt
)->data
;
13262 unsigned char *lisp_string
= this;
13264 while ((precision
<= 0 || n
< precision
)
13266 && (frame_title_ptr
13267 || it
->current_x
< it
->last_visible_x
))
13269 unsigned char *last
= this;
13271 /* Advance to end of string or next format specifier. */
13272 while ((c
= *this++) != '\0' && c
!= '%')
13275 if (this - 1 != last
)
13277 /* Output to end of string or up to '%'. Field width
13278 is length of string. Don't output more than
13279 PRECISION allows us. */
13281 prec
= strwidth (last
, this - last
);
13282 if (precision
> 0 && prec
> precision
- n
)
13283 prec
= precision
- n
;
13285 if (frame_title_ptr
)
13286 n
+= store_frame_title (last
, 0, prec
);
13288 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
13289 it
, 0, prec
, 0, -1);
13291 else /* c == '%' */
13293 unsigned char *percent_position
= this;
13295 /* Get the specified minimum width. Zero means
13298 while ((c
= *this++) >= '0' && c
<= '9')
13299 field
= field
* 10 + c
- '0';
13301 /* Don't pad beyond the total padding allowed. */
13302 if (field_width
- n
> 0 && field
> field_width
- n
)
13303 field
= field_width
- n
;
13305 /* Note that either PRECISION <= 0 or N < PRECISION. */
13306 prec
= precision
- n
;
13309 n
+= display_mode_element (it
, depth
, field
, prec
,
13310 Vglobal_mode_string
);
13313 unsigned char *spec
13314 = decode_mode_spec (it
->w
, c
, field
, prec
);
13316 if (frame_title_ptr
)
13317 n
+= store_frame_title (spec
, field
, prec
);
13321 = it
->glyph_row
->used
[TEXT_AREA
];
13323 = percent_position
- XSTRING (elt
)->data
;
13325 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
13326 field
, prec
, 0, -1);
13328 /* Assign to the glyphs written above the
13329 string where the `%x' came from, position
13333 struct glyph
*glyph
13334 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13338 for (i
= 0; i
< nwritten
; ++i
)
13340 glyph
[i
].object
= elt
;
13341 glyph
[i
].charpos
= charpos
;
13354 /* A symbol: process the value of the symbol recursively
13355 as if it appeared here directly. Avoid error if symbol void.
13356 Special case: if value of symbol is a string, output the string
13359 register Lisp_Object tem
;
13360 tem
= Fboundp (elt
);
13363 tem
= Fsymbol_value (elt
);
13364 /* If value is a string, output that string literally:
13365 don't check for % within it. */
13368 prec
= precision
- n
;
13369 if (frame_title_ptr
)
13370 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13372 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13375 else if (!EQ (tem
, elt
))
13377 /* Give up right away for nil or t. */
13387 register Lisp_Object car
, tem
;
13389 /* A cons cell: three distinct cases.
13390 If first element is a string or a cons, process all the elements
13391 and effectively concatenate them.
13392 If first element is a negative number, truncate displaying cdr to
13393 at most that many characters. If positive, pad (with spaces)
13394 to at least that many characters.
13395 If first element is a symbol, process the cadr or caddr recursively
13396 according to whether the symbol's value is non-nil or nil. */
13398 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13400 /* An element of the form (:eval FORM) means evaluate FORM
13401 and use the result as mode line elements. */
13402 struct gcpro gcpro1
;
13405 spec
= safe_eval (XCAR (XCDR (elt
)));
13407 n
+= display_mode_element (it
, depth
, field_width
- n
,
13408 precision
- n
, spec
);
13411 else if (SYMBOLP (car
))
13413 tem
= Fboundp (car
);
13417 /* elt is now the cdr, and we know it is a cons cell.
13418 Use its car if CAR has a non-nil value. */
13421 tem
= Fsymbol_value (car
);
13428 /* Symbol's value is nil (or symbol is unbound)
13429 Get the cddr of the original list
13430 and if possible find the caddr and use that. */
13434 else if (!CONSP (elt
))
13439 else if (INTEGERP (car
))
13441 register int lim
= XINT (car
);
13445 /* Negative int means reduce maximum width. */
13446 if (precision
<= 0)
13449 precision
= min (precision
, -lim
);
13453 /* Padding specified. Don't let it be more than
13454 current maximum. */
13456 lim
= min (precision
, lim
);
13458 /* If that's more padding than already wanted, queue it.
13459 But don't reduce padding already specified even if
13460 that is beyond the current truncation point. */
13461 field_width
= max (lim
, field_width
);
13465 else if (STRINGP (car
) || CONSP (car
))
13467 register int limit
= 50;
13468 /* Limit is to protect against circular lists. */
13471 && (precision
<= 0 || n
< precision
))
13473 n
+= display_mode_element (it
, depth
, field_width
- n
,
13474 precision
- n
, XCAR (elt
));
13483 if (frame_title_ptr
)
13484 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13486 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13487 precision
- n
, 0, 0);
13491 /* Pad to FIELD_WIDTH. */
13492 if (field_width
> 0 && n
< field_width
)
13494 if (frame_title_ptr
)
13495 n
+= store_frame_title ("", field_width
- n
, 0);
13497 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13505 /* Write a null-terminated, right justified decimal representation of
13506 the positive integer D to BUF using a minimal field width WIDTH. */
13509 pint2str (buf
, width
, d
)
13510 register char *buf
;
13511 register int width
;
13514 register char *p
= buf
;
13522 *p
++ = d
% 10 + '0';
13527 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13538 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13539 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13540 type of CODING_SYSTEM. Return updated pointer into BUF. */
13542 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13545 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13546 Lisp_Object coding_system
;
13547 register char *buf
;
13551 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13552 unsigned char *eol_str
;
13554 /* The EOL conversion we are using. */
13555 Lisp_Object eoltype
;
13557 val
= Fget (coding_system
, Qcoding_system
);
13560 if (!VECTORP (val
)) /* Not yet decided. */
13565 eoltype
= eol_mnemonic_undecided
;
13566 /* Don't mention EOL conversion if it isn't decided. */
13570 Lisp_Object eolvalue
;
13572 eolvalue
= Fget (coding_system
, Qeol_type
);
13575 *buf
++ = XFASTINT (AREF (val
, 1));
13579 /* The EOL conversion that is normal on this system. */
13581 if (NILP (eolvalue
)) /* Not yet decided. */
13582 eoltype
= eol_mnemonic_undecided
;
13583 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13584 eoltype
= eol_mnemonic_undecided
;
13585 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13586 eoltype
= (XFASTINT (eolvalue
) == 0
13587 ? eol_mnemonic_unix
13588 : (XFASTINT (eolvalue
) == 1
13589 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13595 /* Mention the EOL conversion if it is not the usual one. */
13596 if (STRINGP (eoltype
))
13598 eol_str
= XSTRING (eoltype
)->data
;
13599 eol_str_len
= XSTRING (eoltype
)->size
;
13601 else if (INTEGERP (eoltype
)
13602 && CHAR_VALID_P (XINT (eoltype
), 0))
13604 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13605 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13609 eol_str
= invalid_eol_type
;
13610 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13612 bcopy (eol_str
, buf
, eol_str_len
);
13613 buf
+= eol_str_len
;
13619 /* Return a string for the output of a mode line %-spec for window W,
13620 generated by character C. PRECISION >= 0 means don't return a
13621 string longer than that value. FIELD_WIDTH > 0 means pad the
13622 string returned with spaces to that value. */
13624 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13627 decode_mode_spec (w
, c
, field_width
, precision
)
13630 int field_width
, precision
;
13633 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13634 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13635 struct buffer
*b
= XBUFFER (w
->buffer
);
13642 if (!NILP (b
->read_only
))
13644 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13649 /* This differs from %* only for a modified read-only buffer. */
13650 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13652 if (!NILP (b
->read_only
))
13657 /* This differs from %* in ignoring read-only-ness. */
13658 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13670 if (command_loop_level
> 5)
13672 p
= decode_mode_spec_buf
;
13673 for (i
= 0; i
< command_loop_level
; i
++)
13676 return decode_mode_spec_buf
;
13684 if (command_loop_level
> 5)
13686 p
= decode_mode_spec_buf
;
13687 for (i
= 0; i
< command_loop_level
; i
++)
13690 return decode_mode_spec_buf
;
13697 /* Let lots_of_dashes be a string of infinite length. */
13698 if (field_width
<= 0
13699 || field_width
> sizeof (lots_of_dashes
))
13701 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13702 decode_mode_spec_buf
[i
] = '-';
13703 decode_mode_spec_buf
[i
] = '\0';
13704 return decode_mode_spec_buf
;
13707 return lots_of_dashes
;
13716 int col
= current_column ();
13717 w
->column_number_displayed
= make_number (col
);
13718 pint2str (decode_mode_spec_buf
, field_width
, col
);
13719 return decode_mode_spec_buf
;
13723 /* %F displays the frame name. */
13724 if (!NILP (f
->title
))
13725 return (char *) XSTRING (f
->title
)->data
;
13726 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13727 return (char *) XSTRING (f
->name
)->data
;
13736 int startpos
= XMARKER (w
->start
)->charpos
;
13737 int startpos_byte
= marker_byte_position (w
->start
);
13738 int line
, linepos
, linepos_byte
, topline
;
13740 int height
= XFASTINT (w
->height
);
13742 /* If we decided that this buffer isn't suitable for line numbers,
13743 don't forget that too fast. */
13744 if (EQ (w
->base_line_pos
, w
->buffer
))
13746 /* But do forget it, if the window shows a different buffer now. */
13747 else if (BUFFERP (w
->base_line_pos
))
13748 w
->base_line_pos
= Qnil
;
13750 /* If the buffer is very big, don't waste time. */
13751 if (INTEGERP (Vline_number_display_limit
)
13752 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13754 w
->base_line_pos
= Qnil
;
13755 w
->base_line_number
= Qnil
;
13759 if (!NILP (w
->base_line_number
)
13760 && !NILP (w
->base_line_pos
)
13761 && XFASTINT (w
->base_line_pos
) <= startpos
)
13763 line
= XFASTINT (w
->base_line_number
);
13764 linepos
= XFASTINT (w
->base_line_pos
);
13765 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13770 linepos
= BUF_BEGV (b
);
13771 linepos_byte
= BUF_BEGV_BYTE (b
);
13774 /* Count lines from base line to window start position. */
13775 nlines
= display_count_lines (linepos
, linepos_byte
,
13779 topline
= nlines
+ line
;
13781 /* Determine a new base line, if the old one is too close
13782 or too far away, or if we did not have one.
13783 "Too close" means it's plausible a scroll-down would
13784 go back past it. */
13785 if (startpos
== BUF_BEGV (b
))
13787 w
->base_line_number
= make_number (topline
);
13788 w
->base_line_pos
= make_number (BUF_BEGV (b
));
13790 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13791 || linepos
== BUF_BEGV (b
))
13793 int limit
= BUF_BEGV (b
);
13794 int limit_byte
= BUF_BEGV_BYTE (b
);
13796 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13798 if (startpos
- distance
> limit
)
13800 limit
= startpos
- distance
;
13801 limit_byte
= CHAR_TO_BYTE (limit
);
13804 nlines
= display_count_lines (startpos
, startpos_byte
,
13806 - (height
* 2 + 30),
13808 /* If we couldn't find the lines we wanted within
13809 line_number_display_limit_width chars per line,
13810 give up on line numbers for this window. */
13811 if (position
== limit_byte
&& limit
== startpos
- distance
)
13813 w
->base_line_pos
= w
->buffer
;
13814 w
->base_line_number
= Qnil
;
13818 w
->base_line_number
= make_number (topline
- nlines
);
13819 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
13822 /* Now count lines from the start pos to point. */
13823 nlines
= display_count_lines (startpos
, startpos_byte
,
13824 PT_BYTE
, PT
, &junk
);
13826 /* Record that we did display the line number. */
13827 line_number_displayed
= 1;
13829 /* Make the string to show. */
13830 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13831 return decode_mode_spec_buf
;
13834 char* p
= decode_mode_spec_buf
;
13835 int pad
= field_width
- 2;
13841 return decode_mode_spec_buf
;
13847 obj
= b
->mode_name
;
13851 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13857 int pos
= marker_position (w
->start
);
13858 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13860 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13862 if (pos
<= BUF_BEGV (b
))
13867 else if (pos
<= BUF_BEGV (b
))
13871 if (total
> 1000000)
13872 /* Do it differently for a large value, to avoid overflow. */
13873 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13875 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13876 /* We can't normally display a 3-digit number,
13877 so get us a 2-digit number that is close. */
13880 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13881 return decode_mode_spec_buf
;
13885 /* Display percentage of size above the bottom of the screen. */
13888 int toppos
= marker_position (w
->start
);
13889 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13890 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13892 if (botpos
>= BUF_ZV (b
))
13894 if (toppos
<= BUF_BEGV (b
))
13901 if (total
> 1000000)
13902 /* Do it differently for a large value, to avoid overflow. */
13903 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13905 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13906 /* We can't normally display a 3-digit number,
13907 so get us a 2-digit number that is close. */
13910 if (toppos
<= BUF_BEGV (b
))
13911 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13913 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13914 return decode_mode_spec_buf
;
13919 /* status of process */
13920 obj
= Fget_buffer_process (w
->buffer
);
13922 return "no process";
13923 #ifdef subprocesses
13924 obj
= Fsymbol_name (Fprocess_status (obj
));
13928 case 't': /* indicate TEXT or BINARY */
13929 #ifdef MODE_LINE_BINARY_TEXT
13930 return MODE_LINE_BINARY_TEXT (b
);
13936 /* coding-system (not including end-of-line format) */
13938 /* coding-system (including end-of-line type) */
13940 int eol_flag
= (c
== 'Z');
13941 char *p
= decode_mode_spec_buf
;
13943 if (! FRAME_WINDOW_P (f
))
13945 /* No need to mention EOL here--the terminal never needs
13946 to do EOL conversion. */
13947 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
13948 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
13950 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
13953 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
13954 #ifdef subprocesses
13955 obj
= Fget_buffer_process (Fcurrent_buffer ());
13956 if (PROCESSP (obj
))
13958 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
13960 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
13963 #endif /* subprocesses */
13966 return decode_mode_spec_buf
;
13971 return (char *) XSTRING (obj
)->data
;
13977 /* Count up to COUNT lines starting from START / START_BYTE.
13978 But don't go beyond LIMIT_BYTE.
13979 Return the number of lines thus found (always nonnegative).
13981 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
13984 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
13985 int start
, start_byte
, limit_byte
, count
;
13988 register unsigned char *cursor
;
13989 unsigned char *base
;
13991 register int ceiling
;
13992 register unsigned char *ceiling_addr
;
13993 int orig_count
= count
;
13995 /* If we are not in selective display mode,
13996 check only for newlines. */
13997 int selective_display
= (!NILP (current_buffer
->selective_display
)
13998 && !INTEGERP (current_buffer
->selective_display
));
14002 while (start_byte
< limit_byte
)
14004 ceiling
= BUFFER_CEILING_OF (start_byte
);
14005 ceiling
= min (limit_byte
- 1, ceiling
);
14006 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14007 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14010 if (selective_display
)
14011 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14014 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14017 if (cursor
!= ceiling_addr
)
14021 start_byte
+= cursor
- base
+ 1;
14022 *byte_pos_ptr
= start_byte
;
14026 if (++cursor
== ceiling_addr
)
14032 start_byte
+= cursor
- base
;
14037 while (start_byte
> limit_byte
)
14039 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14040 ceiling
= max (limit_byte
, ceiling
);
14041 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14042 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14045 if (selective_display
)
14046 while (--cursor
!= ceiling_addr
14047 && *cursor
!= '\n' && *cursor
!= 015)
14050 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14053 if (cursor
!= ceiling_addr
)
14057 start_byte
+= cursor
- base
+ 1;
14058 *byte_pos_ptr
= start_byte
;
14059 /* When scanning backwards, we should
14060 not count the newline posterior to which we stop. */
14061 return - orig_count
- 1;
14067 /* Here we add 1 to compensate for the last decrement
14068 of CURSOR, which took it past the valid range. */
14069 start_byte
+= cursor
- base
+ 1;
14073 *byte_pos_ptr
= limit_byte
;
14076 return - orig_count
+ count
;
14077 return orig_count
- count
;
14083 /***********************************************************************
14085 ***********************************************************************/
14087 /* Display a NUL-terminated string, starting with index START.
14089 If STRING is non-null, display that C string. Otherwise, the Lisp
14090 string LISP_STRING is displayed.
14092 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14093 FACE_STRING. Display STRING or LISP_STRING with the face at
14094 FACE_STRING_POS in FACE_STRING:
14096 Display the string in the environment given by IT, but use the
14097 standard display table, temporarily.
14099 FIELD_WIDTH is the minimum number of output glyphs to produce.
14100 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14101 with spaces. If STRING has more characters, more than FIELD_WIDTH
14102 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14104 PRECISION is the maximum number of characters to output from
14105 STRING. PRECISION < 0 means don't truncate the string.
14107 This is roughly equivalent to printf format specifiers:
14109 FIELD_WIDTH PRECISION PRINTF
14110 ----------------------------------------
14116 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14117 display them, and < 0 means obey the current buffer's value of
14118 enable_multibyte_characters.
14120 Value is the number of glyphs produced. */
14123 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14124 start
, it
, field_width
, precision
, max_x
, multibyte
)
14125 unsigned char *string
;
14126 Lisp_Object lisp_string
;
14127 Lisp_Object face_string
;
14128 int face_string_pos
;
14131 int field_width
, precision
, max_x
;
14134 int hpos_at_start
= it
->hpos
;
14135 int saved_face_id
= it
->face_id
;
14136 struct glyph_row
*row
= it
->glyph_row
;
14138 /* Initialize the iterator IT for iteration over STRING beginning
14139 with index START. */
14140 reseat_to_string (it
, string
, lisp_string
, start
,
14141 precision
, field_width
, multibyte
);
14143 /* If displaying STRING, set up the face of the iterator
14144 from LISP_STRING, if that's given. */
14145 if (STRINGP (face_string
))
14151 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14152 0, it
->region_beg_charpos
,
14153 it
->region_end_charpos
,
14154 &endptr
, it
->base_face_id
, 0);
14155 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14156 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14159 /* Set max_x to the maximum allowed X position. Don't let it go
14160 beyond the right edge of the window. */
14162 max_x
= it
->last_visible_x
;
14164 max_x
= min (max_x
, it
->last_visible_x
);
14166 /* Skip over display elements that are not visible. because IT->w is
14168 if (it
->current_x
< it
->first_visible_x
)
14169 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14170 MOVE_TO_POS
| MOVE_TO_X
);
14172 row
->ascent
= it
->max_ascent
;
14173 row
->height
= it
->max_ascent
+ it
->max_descent
;
14174 row
->phys_ascent
= it
->max_phys_ascent
;
14175 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14177 /* This condition is for the case that we are called with current_x
14178 past last_visible_x. */
14179 while (it
->current_x
< max_x
)
14181 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14183 /* Get the next display element. */
14184 if (!get_next_display_element (it
))
14187 /* Produce glyphs. */
14188 x_before
= it
->current_x
;
14189 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14190 PRODUCE_GLYPHS (it
);
14192 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14195 while (i
< nglyphs
)
14197 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14199 if (!it
->truncate_lines_p
14200 && x
+ glyph
->pixel_width
> max_x
)
14202 /* End of continued line or max_x reached. */
14203 if (CHAR_GLYPH_PADDING_P (*glyph
))
14205 /* A wide character is unbreakable. */
14206 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14207 it
->current_x
= x_before
;
14211 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14216 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14218 /* Glyph is at least partially visible. */
14220 if (x
< it
->first_visible_x
)
14221 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14225 /* Glyph is off the left margin of the display area.
14226 Should not happen. */
14230 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14231 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14232 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14233 row
->phys_height
= max (row
->phys_height
,
14234 it
->max_phys_ascent
+ it
->max_phys_descent
);
14235 x
+= glyph
->pixel_width
;
14239 /* Stop if max_x reached. */
14243 /* Stop at line ends. */
14244 if (ITERATOR_AT_END_OF_LINE_P (it
))
14246 it
->continuation_lines_width
= 0;
14250 set_iterator_to_next (it
, 1);
14252 /* Stop if truncating at the right edge. */
14253 if (it
->truncate_lines_p
14254 && it
->current_x
>= it
->last_visible_x
)
14256 /* Add truncation mark, but don't do it if the line is
14257 truncated at a padding space. */
14258 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14260 if (!FRAME_WINDOW_P (it
->f
))
14264 if (it
->current_x
> it
->last_visible_x
)
14266 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14267 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14269 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14271 row
->used
[TEXT_AREA
] = i
;
14272 produce_special_glyphs (it
, IT_TRUNCATION
);
14275 produce_special_glyphs (it
, IT_TRUNCATION
);
14277 it
->glyph_row
->truncated_on_right_p
= 1;
14283 /* Maybe insert a truncation at the left. */
14284 if (it
->first_visible_x
14285 && IT_CHARPOS (*it
) > 0)
14287 if (!FRAME_WINDOW_P (it
->f
))
14288 insert_left_trunc_glyphs (it
);
14289 it
->glyph_row
->truncated_on_left_p
= 1;
14292 it
->face_id
= saved_face_id
;
14294 /* Value is number of columns displayed. */
14295 return it
->hpos
- hpos_at_start
;
14300 /* This is like a combination of memq and assq. Return 1 if PROPVAL
14301 appears as an element of LIST or as the car of an element of LIST.
14302 If PROPVAL is a list, compare each element against LIST in that
14303 way, and return 1 if any element of PROPVAL is found in LIST.
14304 Otherwise return 0. This function cannot quit. */
14307 invisible_p (propval
, list
)
14308 register Lisp_Object propval
;
14311 register Lisp_Object tail
, proptail
;
14313 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14315 register Lisp_Object tem
;
14317 if (EQ (propval
, tem
))
14319 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14323 if (CONSP (propval
))
14325 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14327 Lisp_Object propelt
;
14328 propelt
= XCAR (proptail
);
14329 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14331 register Lisp_Object tem
;
14333 if (EQ (propelt
, tem
))
14335 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14345 /* Return 1 if PROPVAL appears as the car of an element of LIST and
14346 the cdr of that element is non-nil. If PROPVAL is a list, check
14347 each element of PROPVAL in that way, and the first time some
14348 element is found, return 1 if the cdr of that element is non-nil.
14349 Otherwise return 0. This function cannot quit. */
14352 invisible_ellipsis_p (propval
, list
)
14353 register Lisp_Object propval
;
14356 register Lisp_Object tail
, proptail
;
14358 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14360 register Lisp_Object tem
;
14362 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14363 return ! NILP (XCDR (tem
));
14366 if (CONSP (propval
))
14367 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14369 Lisp_Object propelt
;
14370 propelt
= XCAR (proptail
);
14371 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14373 register Lisp_Object tem
;
14375 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14376 return ! NILP (XCDR (tem
));
14385 /***********************************************************************
14387 ***********************************************************************/
14392 Vwith_echo_area_save_vector
= Qnil
;
14393 staticpro (&Vwith_echo_area_save_vector
);
14395 Vmessage_stack
= Qnil
;
14396 staticpro (&Vmessage_stack
);
14398 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14399 staticpro (&Qinhibit_redisplay
);
14402 defsubr (&Sdump_glyph_matrix
);
14403 defsubr (&Sdump_glyph_row
);
14404 defsubr (&Sdump_tool_bar_row
);
14405 defsubr (&Strace_redisplay
);
14406 defsubr (&Strace_to_stderr
);
14408 #ifdef HAVE_WINDOW_SYSTEM
14409 defsubr (&Stool_bar_lines_needed
);
14412 staticpro (&Qmenu_bar_update_hook
);
14413 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14415 staticpro (&Qoverriding_terminal_local_map
);
14416 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14418 staticpro (&Qoverriding_local_map
);
14419 Qoverriding_local_map
= intern ("overriding-local-map");
14421 staticpro (&Qwindow_scroll_functions
);
14422 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14424 staticpro (&Qredisplay_end_trigger_functions
);
14425 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14427 staticpro (&Qinhibit_point_motion_hooks
);
14428 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14430 QCdata
= intern (":data");
14431 staticpro (&QCdata
);
14432 Qdisplay
= intern ("display");
14433 staticpro (&Qdisplay
);
14434 Qspace_width
= intern ("space-width");
14435 staticpro (&Qspace_width
);
14436 Qraise
= intern ("raise");
14437 staticpro (&Qraise
);
14438 Qspace
= intern ("space");
14439 staticpro (&Qspace
);
14440 Qmargin
= intern ("margin");
14441 staticpro (&Qmargin
);
14442 Qleft_margin
= intern ("left-margin");
14443 staticpro (&Qleft_margin
);
14444 Qright_margin
= intern ("right-margin");
14445 staticpro (&Qright_margin
);
14446 Qalign_to
= intern ("align-to");
14447 staticpro (&Qalign_to
);
14448 QCalign_to
= intern (":align-to");
14449 staticpro (&QCalign_to
);
14450 Qrelative_width
= intern ("relative-width");
14451 staticpro (&Qrelative_width
);
14452 QCrelative_width
= intern (":relative-width");
14453 staticpro (&QCrelative_width
);
14454 QCrelative_height
= intern (":relative-height");
14455 staticpro (&QCrelative_height
);
14456 QCeval
= intern (":eval");
14457 staticpro (&QCeval
);
14458 Qwhen
= intern ("when");
14459 staticpro (&Qwhen
);
14460 QCfile
= intern (":file");
14461 staticpro (&QCfile
);
14462 Qfontified
= intern ("fontified");
14463 staticpro (&Qfontified
);
14464 Qfontification_functions
= intern ("fontification-functions");
14465 staticpro (&Qfontification_functions
);
14466 Qtrailing_whitespace
= intern ("trailing-whitespace");
14467 staticpro (&Qtrailing_whitespace
);
14468 Qimage
= intern ("image");
14469 staticpro (&Qimage
);
14470 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14471 staticpro (&Qmessage_truncate_lines
);
14472 Qgrow_only
= intern ("grow-only");
14473 staticpro (&Qgrow_only
);
14474 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14475 staticpro (&Qinhibit_menubar_update
);
14476 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14477 staticpro (&Qinhibit_eval_during_redisplay
);
14479 last_arrow_position
= Qnil
;
14480 last_arrow_string
= Qnil
;
14481 staticpro (&last_arrow_position
);
14482 staticpro (&last_arrow_string
);
14484 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14485 staticpro (&echo_buffer
[0]);
14486 staticpro (&echo_buffer
[1]);
14488 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14489 staticpro (&echo_area_buffer
[0]);
14490 staticpro (&echo_area_buffer
[1]);
14492 Vmessages_buffer_name
= build_string ("*Messages*");
14493 staticpro (&Vmessages_buffer_name
);
14495 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14496 "Non-nil means highlight trailing whitespace.\n\
14497 The face used for trailing whitespace is `trailing-whitespace'.");
14498 Vshow_trailing_whitespace
= Qnil
;
14500 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14501 "Non-nil means don't actually do any redisplay.\n\
14502 This is used for internal purposes.");
14503 Vinhibit_redisplay
= Qnil
;
14505 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14506 "String (or mode line construct) included (normally) in `mode-line-format'.");
14507 Vglobal_mode_string
= Qnil
;
14509 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14510 "Marker for where to display an arrow on top of the buffer text.\n\
14511 This must be the beginning of a line in order to work.\n\
14512 See also `overlay-arrow-string'.");
14513 Voverlay_arrow_position
= Qnil
;
14515 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14516 "String to display as an arrow. See also `overlay-arrow-position'.");
14517 Voverlay_arrow_string
= Qnil
;
14519 DEFVAR_INT ("scroll-step", &scroll_step
,
14520 "*The number of lines to try scrolling a window by when point moves out.\n\
14521 If that fails to bring point back on frame, point is centered instead.\n\
14522 If this is zero, point is always centered after it moves off frame.\n\
14523 If you want scrolling to always be a line at a time, you should set\n\
14524 `scroll-conservatively' to a large value rather than set this to 1.");
14526 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14527 "*Scroll up to this many lines, to bring point back on screen.\n\
14528 A value of zero means to scroll the text to center point vertically\n\
14530 scroll_conservatively
= 0;
14532 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14533 "*Number of lines of margin at the top and bottom of a window.\n\
14534 Recenter the window whenever point gets within this many lines\n\
14535 of the top or bottom of the window.");
14539 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
14542 DEFVAR_BOOL ("truncate-partial-width-windows",
14543 &truncate_partial_width_windows
,
14544 "*Non-nil means truncate lines in all windows less than full frame wide.");
14545 truncate_partial_width_windows
= 1;
14547 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14548 "nil means display the mode-line/header-line/menu-bar in the default face.\n\
14549 Any other value means to use the appropriate face, `mode-line',\n\
14550 `header-line', or `menu' respectively.\n\
14552 This variable is deprecated; please change the above faces instead.");
14553 mode_line_inverse_video
= 1;
14555 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14556 "*Maximum buffer size for which line number should be displayed.\n\
14557 If the buffer is bigger than this, the line number does not appear\n\
14558 in the mode line. A value of nil means no limit.");
14559 Vline_number_display_limit
= Qnil
;
14561 DEFVAR_INT ("line-number-display-limit-width",
14562 &line_number_display_limit_width
,
14563 "*Maximum line width (in characters) for line number display.\n\
14564 If the average length of the lines near point is bigger than this, then the\n\
14565 line number may be omitted from the mode line.");
14566 line_number_display_limit_width
= 200;
14568 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14569 "*Non-nil means highlight region even in nonselected windows.");
14570 highlight_nonselected_windows
= 0;
14572 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14573 "Non-nil if more than one frame is visible on this display.\n\
14574 Minibuffer-only frames don't count, but iconified frames do.\n\
14575 This variable is not guaranteed to be accurate except while processing\n\
14576 `frame-title-format' and `icon-title-format'.");
14578 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14579 "Template for displaying the title bar of visible frames.\n\
14580 \(Assuming the window manager supports this feature.)\n\
14581 This variable has the same structure as `mode-line-format' (which see),\n\
14582 and is used only on frames for which no explicit name has been set\n\
14583 \(see `modify-frame-parameters').");
14584 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14585 "Template for displaying the title bar of an iconified frame.\n\
14586 \(Assuming the window manager supports this feature.)\n\
14587 This variable has the same structure as `mode-line-format' (which see),\n\
14588 and is used only on frames for which no explicit name has been set\n\
14589 \(see `modify-frame-parameters').");
14591 = Vframe_title_format
14592 = Fcons (intern ("multiple-frames"),
14593 Fcons (build_string ("%b"),
14594 Fcons (Fcons (build_string (""),
14595 Fcons (intern ("invocation-name"),
14596 Fcons (build_string ("@"),
14597 Fcons (intern ("system-name"),
14601 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14602 "Maximum number of lines to keep in the message log buffer.\n\
14603 If nil, disable message logging. If t, log messages but don't truncate\n\
14604 the buffer when it becomes large.");
14605 Vmessage_log_max
= make_number (50);
14607 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14608 "Functions called before redisplay, if window sizes have changed.\n\
14609 The value should be a list of functions that take one argument.\n\
14610 Just before redisplay, for each frame, if any of its windows have changed\n\
14611 size since the last redisplay, or have been split or deleted,\n\
14612 all the functions in the list are called, with the frame as argument.");
14613 Vwindow_size_change_functions
= Qnil
;
14615 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14616 "List of Functions to call before redisplaying a window with scrolling.\n\
14617 Each function is called with two arguments, the window\n\
14618 and its new display-start position. Note that the value of `window-end'\n\
14619 is not valid when these functions are called.");
14620 Vwindow_scroll_functions
= Qnil
;
14622 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14623 "*Non-nil means automatically resize tool-bars.\n\
14624 This increases a tool-bar's height if not all tool-bar items are visible.\n\
14625 It decreases a tool-bar's height when it would display blank lines\n\
14627 auto_resize_tool_bars_p
= 1;
14629 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14630 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
14631 auto_raise_tool_bar_buttons_p
= 1;
14633 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14634 "*Margin around tool-bar buttons in pixels.\n\
14635 If an integer, use that for both horizontal and vertical margins.\n\
14636 Otherwise, value should be a pair of integers `(HORZ : VERT)' with\n\
14637 HORZ specifying the horizontal margin, and VERT specifying the\n\
14638 vertical margin.");
14639 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14641 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14642 "Relief thickness of tool-bar buttons.");
14643 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14645 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14646 "List of functions to call to fontify regions of text.\n\
14647 Each function is called with one argument POS. Functions must\n\
14648 fontify a region starting at POS in the current buffer, and give\n\
14649 fontified regions the property `fontified'.\n\
14650 This variable automatically becomes buffer-local when set.");
14651 Vfontification_functions
= Qnil
;
14652 Fmake_variable_buffer_local (Qfontification_functions
);
14654 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14655 &unibyte_display_via_language_environment
,
14656 "*Non-nil means display unibyte text according to language environment.\n\
14657 Specifically this means that unibyte non-ASCII characters\n\
14658 are displayed by converting them to the equivalent multibyte characters\n\
14659 according to the current language environment. As a result, they are\n\
14660 displayed according to the current fontset.");
14661 unibyte_display_via_language_environment
= 0;
14663 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14664 "*Maximum height for resizing mini-windows.\n\
14665 If a float, it specifies a fraction of the mini-window frame's height.\n\
14666 If an integer, it specifies a number of lines.");
14667 Vmax_mini_window_height
= make_float (0.25);
14669 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14670 "*How to resize mini-windows.\n\
14671 A value of nil means don't automatically resize mini-windows.\n\
14672 A value of t means resize them to fit the text displayed in them.\n\
14673 A value of `grow-only', the default, means let mini-windows grow\n\
14674 only, until their display becomes empty, at which point the windows\n\
14675 go back to their normal size.");
14676 Vresize_mini_windows
= Qgrow_only
;
14678 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14679 &cursor_in_non_selected_windows
,
14680 "*Non-nil means display a hollow cursor in non-selected windows.\n\
14681 Nil means don't display a cursor there.");
14682 cursor_in_non_selected_windows
= 1;
14684 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14685 "*Non-nil means scroll the display automatically to make point visible.");
14686 automatic_hscrolling_p
= 1;
14688 DEFVAR_LISP ("image-types", &Vimage_types
,
14689 "List of supported image types.\n\
14690 Each element of the list is a symbol for a supported image type.");
14691 Vimage_types
= Qnil
;
14693 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14694 "If non-nil, messages are truncated instead of resizing the echo area.\n\
14695 Bind this around calls to `message' to let it take effect.");
14696 message_truncate_lines
= 0;
14698 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14699 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
14700 Can be used to update submenus whose contents should vary.");
14701 Vmenu_bar_update_hook
= Qnil
;
14703 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14704 "Non-nil means don't update menu bars. Internal use only.");
14705 inhibit_menubar_update
= 0;
14707 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
14708 "Non-nil means don't eval Lisp during redisplay.");
14709 inhibit_eval_during_redisplay
= 0;
14713 /* Initialize this module when Emacs starts. */
14718 Lisp_Object root_window
;
14719 struct window
*mini_w
;
14721 current_header_line_height
= current_mode_line_height
= -1;
14723 CHARPOS (this_line_start_pos
) = 0;
14725 mini_w
= XWINDOW (minibuf_window
);
14726 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14728 if (!noninteractive
)
14730 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14733 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
14734 set_window_height (root_window
,
14735 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14737 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
14738 set_window_height (minibuf_window
, 1, 0);
14740 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
14741 mini_w
->width
= make_number (FRAME_WIDTH (f
));
14743 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14744 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14745 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14747 /* The default ellipsis glyphs `...'. */
14748 for (i
= 0; i
< 3; ++i
)
14749 default_invis_vector
[i
] = make_number ('.');
14752 #ifdef HAVE_WINDOW_SYSTEM
14754 /* Allocate the buffer for frame titles. */
14756 frame_title_buf
= (char *) xmalloc (size
);
14757 frame_title_buf_end
= frame_title_buf
+ size
;
14758 frame_title_ptr
= NULL
;
14760 #endif /* HAVE_WINDOW_SYSTEM */
14762 help_echo_showing_p
= 0;