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;
4231 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4234 /* It's an invalid character, which
4235 shouldn't happen actually, but due to
4236 bugs it may happen. Let's print the char
4237 as is, there's not much meaningful we can
4240 str
[1] = it
->c
>> 8;
4241 str
[2] = it
->c
>> 16;
4242 str
[3] = it
->c
>> 24;
4247 for (i
= 0; i
< len
; i
++)
4249 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4250 /* Insert three more glyphs into IT->ctl_chars for
4251 the octal display of the character. */
4252 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4253 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4254 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4255 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4256 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4257 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4260 /* Set up IT->dpvec and return the first character
4262 it
->dpvec_char_len
= it
->len
;
4263 it
->dpvec
= it
->ctl_chars
;
4264 it
->dpend
= it
->dpvec
+ len
* 4;
4265 it
->current
.dpvec_index
= 0;
4266 it
->method
= next_element_from_display_vector
;
4267 get_next_display_element (it
);
4272 /* Adjust face id for a multibyte character. There are no
4273 multibyte character in unibyte text. */
4276 && FRAME_WINDOW_P (it
->f
))
4278 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4279 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4283 /* Is this character the last one of a run of characters with
4284 box? If yes, set IT->end_of_box_run_p to 1. */
4291 it
->end_of_box_run_p
4292 = ((face_id
= face_after_it_pos (it
),
4293 face_id
!= it
->face_id
)
4294 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4295 face
->box
== FACE_NO_BOX
));
4298 /* Value is 0 if end of buffer or string reached. */
4303 /* Move IT to the next display element.
4305 RESEAT_P non-zero means if called on a newline in buffer text,
4306 skip to the next visible line start.
4308 Functions get_next_display_element and set_iterator_to_next are
4309 separate because I find this arrangement easier to handle than a
4310 get_next_display_element function that also increments IT's
4311 position. The way it is we can first look at an iterator's current
4312 display element, decide whether it fits on a line, and if it does,
4313 increment the iterator position. The other way around we probably
4314 would either need a flag indicating whether the iterator has to be
4315 incremented the next time, or we would have to implement a
4316 decrement position function which would not be easy to write. */
4319 set_iterator_to_next (it
, reseat_p
)
4323 /* Reset flags indicating start and end of a sequence of characters
4324 with box. Reset them at the start of this function because
4325 moving the iterator to a new position might set them. */
4326 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4328 if (it
->method
== next_element_from_buffer
)
4330 /* The current display element of IT is a character from
4331 current_buffer. Advance in the buffer, and maybe skip over
4332 invisible lines that are so because of selective display. */
4333 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4334 reseat_at_next_visible_line_start (it
, 0);
4337 xassert (it
->len
!= 0);
4338 IT_BYTEPOS (*it
) += it
->len
;
4339 IT_CHARPOS (*it
) += 1;
4340 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4343 else if (it
->method
== next_element_from_composition
)
4345 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4346 if (STRINGP (it
->string
))
4348 IT_STRING_BYTEPOS (*it
) += it
->len
;
4349 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4350 it
->method
= next_element_from_string
;
4351 goto consider_string_end
;
4355 IT_BYTEPOS (*it
) += it
->len
;
4356 IT_CHARPOS (*it
) += it
->cmp_len
;
4357 it
->method
= next_element_from_buffer
;
4360 else if (it
->method
== next_element_from_c_string
)
4362 /* Current display element of IT is from a C string. */
4363 IT_BYTEPOS (*it
) += it
->len
;
4364 IT_CHARPOS (*it
) += 1;
4366 else if (it
->method
== next_element_from_display_vector
)
4368 /* Current display element of IT is from a display table entry.
4369 Advance in the display table definition. Reset it to null if
4370 end reached, and continue with characters from buffers/
4372 ++it
->current
.dpvec_index
;
4374 /* Restore face of the iterator to what they were before the
4375 display vector entry (these entries may contain faces). */
4376 it
->face_id
= it
->saved_face_id
;
4378 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4381 it
->method
= next_element_from_c_string
;
4382 else if (STRINGP (it
->string
))
4383 it
->method
= next_element_from_string
;
4385 it
->method
= next_element_from_buffer
;
4388 it
->current
.dpvec_index
= -1;
4390 /* Skip over characters which were displayed via IT->dpvec. */
4391 if (it
->dpvec_char_len
< 0)
4392 reseat_at_next_visible_line_start (it
, 1);
4393 else if (it
->dpvec_char_len
> 0)
4395 it
->len
= it
->dpvec_char_len
;
4396 set_iterator_to_next (it
, reseat_p
);
4400 else if (it
->method
== next_element_from_string
)
4402 /* Current display element is a character from a Lisp string. */
4403 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4404 IT_STRING_BYTEPOS (*it
) += it
->len
;
4405 IT_STRING_CHARPOS (*it
) += 1;
4407 consider_string_end
:
4409 if (it
->current
.overlay_string_index
>= 0)
4411 /* IT->string is an overlay string. Advance to the
4412 next, if there is one. */
4413 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4414 next_overlay_string (it
);
4418 /* IT->string is not an overlay string. If we reached
4419 its end, and there is something on IT->stack, proceed
4420 with what is on the stack. This can be either another
4421 string, this time an overlay string, or a buffer. */
4422 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4426 if (!STRINGP (it
->string
))
4427 it
->method
= next_element_from_buffer
;
4429 goto consider_string_end
;
4433 else if (it
->method
== next_element_from_image
4434 || it
->method
== next_element_from_stretch
)
4436 /* The position etc with which we have to proceed are on
4437 the stack. The position may be at the end of a string,
4438 if the `display' property takes up the whole string. */
4441 if (STRINGP (it
->string
))
4443 it
->method
= next_element_from_string
;
4444 goto consider_string_end
;
4447 it
->method
= next_element_from_buffer
;
4450 /* There are no other methods defined, so this should be a bug. */
4453 xassert (it
->method
!= next_element_from_string
4454 || (STRINGP (it
->string
)
4455 && IT_STRING_CHARPOS (*it
) >= 0));
4459 /* Load IT's display element fields with information about the next
4460 display element which comes from a display table entry or from the
4461 result of translating a control character to one of the forms `^C'
4462 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4465 next_element_from_display_vector (it
)
4469 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4471 /* Remember the current face id in case glyphs specify faces.
4472 IT's face is restored in set_iterator_to_next. */
4473 it
->saved_face_id
= it
->face_id
;
4475 if (INTEGERP (*it
->dpvec
)
4476 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4481 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4482 it
->c
= FAST_GLYPH_CHAR (g
);
4483 it
->len
= CHAR_BYTES (it
->c
);
4485 /* The entry may contain a face id to use. Such a face id is
4486 the id of a Lisp face, not a realized face. A face id of
4487 zero means no face is specified. */
4488 lface_id
= FAST_GLYPH_FACE (g
);
4491 /* The function returns -1 if lface_id is invalid. */
4492 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4494 it
->face_id
= face_id
;
4498 /* Display table entry is invalid. Return a space. */
4499 it
->c
= ' ', it
->len
= 1;
4501 /* Don't change position and object of the iterator here. They are
4502 still the values of the character that had this display table
4503 entry or was translated, and that's what we want. */
4504 it
->what
= IT_CHARACTER
;
4509 /* Load IT with the next display element from Lisp string IT->string.
4510 IT->current.string_pos is the current position within the string.
4511 If IT->current.overlay_string_index >= 0, the Lisp string is an
4515 next_element_from_string (it
)
4518 struct text_pos position
;
4520 xassert (STRINGP (it
->string
));
4521 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4522 position
= it
->current
.string_pos
;
4524 /* Time to check for invisible text? */
4525 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4526 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4530 /* Since a handler may have changed IT->method, we must
4532 return get_next_display_element (it
);
4535 if (it
->current
.overlay_string_index
>= 0)
4537 /* Get the next character from an overlay string. In overlay
4538 strings, There is no field width or padding with spaces to
4540 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4545 else if (STRING_MULTIBYTE (it
->string
))
4547 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4548 - IT_STRING_BYTEPOS (*it
));
4549 unsigned char *s
= (XSTRING (it
->string
)->data
4550 + IT_STRING_BYTEPOS (*it
));
4551 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4555 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4561 /* Get the next character from a Lisp string that is not an
4562 overlay string. Such strings come from the mode line, for
4563 example. We may have to pad with spaces, or truncate the
4564 string. See also next_element_from_c_string. */
4565 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4570 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4572 /* Pad with spaces. */
4573 it
->c
= ' ', it
->len
= 1;
4574 CHARPOS (position
) = BYTEPOS (position
) = -1;
4576 else if (STRING_MULTIBYTE (it
->string
))
4578 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4579 - IT_STRING_BYTEPOS (*it
));
4580 unsigned char *s
= (XSTRING (it
->string
)->data
4581 + IT_STRING_BYTEPOS (*it
));
4582 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4586 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4591 /* Record what we have and where it came from. Note that we store a
4592 buffer position in IT->position although it could arguably be a
4594 it
->what
= IT_CHARACTER
;
4595 it
->object
= it
->string
;
4596 it
->position
= position
;
4601 /* Load IT with next display element from C string IT->s.
4602 IT->string_nchars is the maximum number of characters to return
4603 from the string. IT->end_charpos may be greater than
4604 IT->string_nchars when this function is called, in which case we
4605 may have to return padding spaces. Value is zero if end of string
4606 reached, including padding spaces. */
4609 next_element_from_c_string (it
)
4615 it
->what
= IT_CHARACTER
;
4616 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4619 /* IT's position can be greater IT->string_nchars in case a field
4620 width or precision has been specified when the iterator was
4622 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4624 /* End of the game. */
4628 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4630 /* Pad with spaces. */
4631 it
->c
= ' ', it
->len
= 1;
4632 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4634 else if (it
->multibyte_p
)
4636 /* Implementation note: The calls to strlen apparently aren't a
4637 performance problem because there is no noticeable performance
4638 difference between Emacs running in unibyte or multibyte mode. */
4639 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4640 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4644 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4650 /* Set up IT to return characters from an ellipsis, if appropriate.
4651 The definition of the ellipsis glyphs may come from a display table
4652 entry. This function Fills IT with the first glyph from the
4653 ellipsis if an ellipsis is to be displayed. */
4656 next_element_from_ellipsis (it
)
4659 if (it
->selective_display_ellipsis_p
)
4661 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4663 /* Use the display table definition for `...'. Invalid glyphs
4664 will be handled by the method returning elements from dpvec. */
4665 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4666 it
->dpvec_char_len
= it
->len
;
4667 it
->dpvec
= v
->contents
;
4668 it
->dpend
= v
->contents
+ v
->size
;
4669 it
->current
.dpvec_index
= 0;
4670 it
->method
= next_element_from_display_vector
;
4674 /* Use default `...' which is stored in default_invis_vector. */
4675 it
->dpvec_char_len
= it
->len
;
4676 it
->dpvec
= default_invis_vector
;
4677 it
->dpend
= default_invis_vector
+ 3;
4678 it
->current
.dpvec_index
= 0;
4679 it
->method
= next_element_from_display_vector
;
4684 /* The face at the current position may be different from the
4685 face we find after the invisible text. Remember what it
4686 was in IT->saved_face_id, and signal that it's there by
4687 setting face_before_selective_p. */
4688 it
->saved_face_id
= it
->face_id
;
4689 it
->method
= next_element_from_buffer
;
4690 reseat_at_next_visible_line_start (it
, 1);
4691 it
->face_before_selective_p
= 1;
4694 return get_next_display_element (it
);
4698 /* Deliver an image display element. The iterator IT is already
4699 filled with image information (done in handle_display_prop). Value
4704 next_element_from_image (it
)
4707 it
->what
= IT_IMAGE
;
4712 /* Fill iterator IT with next display element from a stretch glyph
4713 property. IT->object is the value of the text property. Value is
4717 next_element_from_stretch (it
)
4720 it
->what
= IT_STRETCH
;
4725 /* Load IT with the next display element from current_buffer. Value
4726 is zero if end of buffer reached. IT->stop_charpos is the next
4727 position at which to stop and check for text properties or buffer
4731 next_element_from_buffer (it
)
4736 /* Check this assumption, otherwise, we would never enter the
4737 if-statement, below. */
4738 xassert (IT_CHARPOS (*it
) >= BEGV
4739 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4741 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4743 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4745 int overlay_strings_follow_p
;
4747 /* End of the game, except when overlay strings follow that
4748 haven't been returned yet. */
4749 if (it
->overlay_strings_at_end_processed_p
)
4750 overlay_strings_follow_p
= 0;
4753 it
->overlay_strings_at_end_processed_p
= 1;
4754 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4757 if (overlay_strings_follow_p
)
4758 success_p
= get_next_display_element (it
);
4762 it
->position
= it
->current
.pos
;
4769 return get_next_display_element (it
);
4774 /* No face changes, overlays etc. in sight, so just return a
4775 character from current_buffer. */
4778 /* Maybe run the redisplay end trigger hook. Performance note:
4779 This doesn't seem to cost measurable time. */
4780 if (it
->redisplay_end_trigger_charpos
4782 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4783 run_redisplay_end_trigger_hook (it
);
4785 /* Get the next character, maybe multibyte. */
4786 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4787 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4789 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4790 - IT_BYTEPOS (*it
));
4791 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4794 it
->c
= *p
, it
->len
= 1;
4796 /* Record what we have and where it came from. */
4797 it
->what
= IT_CHARACTER
;;
4798 it
->object
= it
->w
->buffer
;
4799 it
->position
= it
->current
.pos
;
4801 /* Normally we return the character found above, except when we
4802 really want to return an ellipsis for selective display. */
4807 /* A value of selective > 0 means hide lines indented more
4808 than that number of columns. */
4809 if (it
->selective
> 0
4810 && IT_CHARPOS (*it
) + 1 < ZV
4811 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4812 IT_BYTEPOS (*it
) + 1,
4815 success_p
= next_element_from_ellipsis (it
);
4816 it
->dpvec_char_len
= -1;
4819 else if (it
->c
== '\r' && it
->selective
== -1)
4821 /* A value of selective == -1 means that everything from the
4822 CR to the end of the line is invisible, with maybe an
4823 ellipsis displayed for it. */
4824 success_p
= next_element_from_ellipsis (it
);
4825 it
->dpvec_char_len
= -1;
4830 /* Value is zero if end of buffer reached. */
4831 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4836 /* Run the redisplay end trigger hook for IT. */
4839 run_redisplay_end_trigger_hook (it
)
4842 Lisp_Object args
[3];
4844 /* IT->glyph_row should be non-null, i.e. we should be actually
4845 displaying something, or otherwise we should not run the hook. */
4846 xassert (it
->glyph_row
);
4848 /* Set up hook arguments. */
4849 args
[0] = Qredisplay_end_trigger_functions
;
4850 args
[1] = it
->window
;
4851 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4852 it
->redisplay_end_trigger_charpos
= 0;
4854 /* Since we are *trying* to run these functions, don't try to run
4855 them again, even if they get an error. */
4856 it
->w
->redisplay_end_trigger
= Qnil
;
4857 Frun_hook_with_args (3, args
);
4859 /* Notice if it changed the face of the character we are on. */
4860 handle_face_prop (it
);
4864 /* Deliver a composition display element. The iterator IT is already
4865 filled with composition information (done in
4866 handle_composition_prop). Value is always 1. */
4869 next_element_from_composition (it
)
4872 it
->what
= IT_COMPOSITION
;
4873 it
->position
= (STRINGP (it
->string
)
4874 ? it
->current
.string_pos
4881 /***********************************************************************
4882 Moving an iterator without producing glyphs
4883 ***********************************************************************/
4885 /* Move iterator IT to a specified buffer or X position within one
4886 line on the display without producing glyphs.
4888 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4889 whichever is reached first.
4891 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4893 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4894 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4895 TO_X includes the amount by which a window is horizontally
4900 MOVE_POS_MATCH_OR_ZV
4901 - when TO_POS or ZV was reached.
4904 -when TO_X was reached before TO_POS or ZV were reached.
4907 - when we reached the end of the display area and the line must
4911 - when we reached the end of the display area and the line is
4915 - when we stopped at a line end, i.e. a newline or a CR and selective
4918 static enum move_it_result
4919 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4921 int to_charpos
, to_x
, op
;
4923 enum move_it_result result
= MOVE_UNDEFINED
;
4924 struct glyph_row
*saved_glyph_row
;
4926 /* Don't produce glyphs in produce_glyphs. */
4927 saved_glyph_row
= it
->glyph_row
;
4928 it
->glyph_row
= NULL
;
4932 int x
, i
, ascent
= 0, descent
= 0;
4934 /* Stop when ZV or TO_CHARPOS reached. */
4935 if (!get_next_display_element (it
)
4936 || ((op
& MOVE_TO_POS
) != 0
4937 && BUFFERP (it
->object
)
4938 && IT_CHARPOS (*it
) >= to_charpos
))
4940 result
= MOVE_POS_MATCH_OR_ZV
;
4944 /* The call to produce_glyphs will get the metrics of the
4945 display element IT is loaded with. We record in x the
4946 x-position before this display element in case it does not
4950 /* Remember the line height so far in case the next element doesn't
4952 if (!it
->truncate_lines_p
)
4954 ascent
= it
->max_ascent
;
4955 descent
= it
->max_descent
;
4958 PRODUCE_GLYPHS (it
);
4960 if (it
->area
!= TEXT_AREA
)
4962 set_iterator_to_next (it
, 1);
4966 /* The number of glyphs we get back in IT->nglyphs will normally
4967 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4968 character on a terminal frame, or (iii) a line end. For the
4969 second case, IT->nglyphs - 1 padding glyphs will be present
4970 (on X frames, there is only one glyph produced for a
4971 composite character.
4973 The behavior implemented below means, for continuation lines,
4974 that as many spaces of a TAB as fit on the current line are
4975 displayed there. For terminal frames, as many glyphs of a
4976 multi-glyph character are displayed in the current line, too.
4977 This is what the old redisplay code did, and we keep it that
4978 way. Under X, the whole shape of a complex character must
4979 fit on the line or it will be completely displayed in the
4982 Note that both for tabs and padding glyphs, all glyphs have
4986 /* More than one glyph or glyph doesn't fit on line. All
4987 glyphs have the same width. */
4988 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4991 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4993 new_x
= x
+ single_glyph_width
;
4995 /* We want to leave anything reaching TO_X to the caller. */
4996 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4999 result
= MOVE_X_REACHED
;
5002 else if (/* Lines are continued. */
5003 !it
->truncate_lines_p
5004 && (/* And glyph doesn't fit on the line. */
5005 new_x
> it
->last_visible_x
5006 /* Or it fits exactly and we're on a window
5008 || (new_x
== it
->last_visible_x
5009 && FRAME_WINDOW_P (it
->f
))))
5011 if (/* IT->hpos == 0 means the very first glyph
5012 doesn't fit on the line, e.g. a wide image. */
5014 || (new_x
== it
->last_visible_x
5015 && FRAME_WINDOW_P (it
->f
)))
5018 it
->current_x
= new_x
;
5019 if (i
== it
->nglyphs
- 1)
5020 set_iterator_to_next (it
, 1);
5025 it
->max_ascent
= ascent
;
5026 it
->max_descent
= descent
;
5029 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5031 result
= MOVE_LINE_CONTINUED
;
5034 else if (new_x
> it
->first_visible_x
)
5036 /* Glyph is visible. Increment number of glyphs that
5037 would be displayed. */
5042 /* Glyph is completely off the left margin of the display
5043 area. Nothing to do. */
5047 if (result
!= MOVE_UNDEFINED
)
5050 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5052 /* Stop when TO_X specified and reached. This check is
5053 necessary here because of lines consisting of a line end,
5054 only. The line end will not produce any glyphs and we
5055 would never get MOVE_X_REACHED. */
5056 xassert (it
->nglyphs
== 0);
5057 result
= MOVE_X_REACHED
;
5061 /* Is this a line end? If yes, we're done. */
5062 if (ITERATOR_AT_END_OF_LINE_P (it
))
5064 result
= MOVE_NEWLINE_OR_CR
;
5068 /* The current display element has been consumed. Advance
5070 set_iterator_to_next (it
, 1);
5072 /* Stop if lines are truncated and IT's current x-position is
5073 past the right edge of the window now. */
5074 if (it
->truncate_lines_p
5075 && it
->current_x
>= it
->last_visible_x
)
5077 result
= MOVE_LINE_TRUNCATED
;
5082 /* Restore the iterator settings altered at the beginning of this
5084 it
->glyph_row
= saved_glyph_row
;
5089 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5090 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5091 the description of enum move_operation_enum.
5093 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5094 screen line, this function will set IT to the next position >
5098 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5100 int to_charpos
, to_x
, to_y
, to_vpos
;
5103 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5109 if (op
& MOVE_TO_VPOS
)
5111 /* If no TO_CHARPOS and no TO_X specified, stop at the
5112 start of the line TO_VPOS. */
5113 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5115 if (it
->vpos
== to_vpos
)
5121 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5125 /* TO_VPOS >= 0 means stop at TO_X in the line at
5126 TO_VPOS, or at TO_POS, whichever comes first. */
5127 if (it
->vpos
== to_vpos
)
5133 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5135 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5140 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5142 /* We have reached TO_X but not in the line we want. */
5143 skip
= move_it_in_display_line_to (it
, to_charpos
,
5145 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5153 else if (op
& MOVE_TO_Y
)
5155 struct it it_backup
;
5157 /* TO_Y specified means stop at TO_X in the line containing
5158 TO_Y---or at TO_CHARPOS if this is reached first. The
5159 problem is that we can't really tell whether the line
5160 contains TO_Y before we have completely scanned it, and
5161 this may skip past TO_X. What we do is to first scan to
5164 If TO_X is not specified, use a TO_X of zero. The reason
5165 is to make the outcome of this function more predictable.
5166 If we didn't use TO_X == 0, we would stop at the end of
5167 the line which is probably not what a caller would expect
5169 skip
= move_it_in_display_line_to (it
, to_charpos
,
5173 | (op
& MOVE_TO_POS
)));
5175 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5176 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5182 /* If TO_X was reached, we would like to know whether TO_Y
5183 is in the line. This can only be said if we know the
5184 total line height which requires us to scan the rest of
5186 if (skip
== MOVE_X_REACHED
)
5189 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5190 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5192 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5195 /* Now, decide whether TO_Y is in this line. */
5196 line_height
= it
->max_ascent
+ it
->max_descent
;
5197 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5199 if (to_y
>= it
->current_y
5200 && to_y
< it
->current_y
+ line_height
)
5202 if (skip
== MOVE_X_REACHED
)
5203 /* If TO_Y is in this line and TO_X was reached above,
5204 we scanned too far. We have to restore IT's settings
5205 to the ones before skipping. */
5209 else if (skip
== MOVE_X_REACHED
)
5212 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5220 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5224 case MOVE_POS_MATCH_OR_ZV
:
5228 case MOVE_NEWLINE_OR_CR
:
5229 set_iterator_to_next (it
, 1);
5230 it
->continuation_lines_width
= 0;
5233 case MOVE_LINE_TRUNCATED
:
5234 it
->continuation_lines_width
= 0;
5235 reseat_at_next_visible_line_start (it
, 0);
5236 if ((op
& MOVE_TO_POS
) != 0
5237 && IT_CHARPOS (*it
) > to_charpos
)
5244 case MOVE_LINE_CONTINUED
:
5245 it
->continuation_lines_width
+= it
->current_x
;
5252 /* Reset/increment for the next run. */
5253 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5254 it
->current_x
= it
->hpos
= 0;
5255 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5257 last_height
= it
->max_ascent
+ it
->max_descent
;
5258 last_max_ascent
= it
->max_ascent
;
5259 it
->max_ascent
= it
->max_descent
= 0;
5264 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5268 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5270 If DY > 0, move IT backward at least that many pixels. DY = 0
5271 means move IT backward to the preceding line start or BEGV. This
5272 function may move over more than DY pixels if IT->current_y - DY
5273 ends up in the middle of a line; in this case IT->current_y will be
5274 set to the top of the line moved to. */
5277 move_it_vertically_backward (it
, dy
)
5281 int nlines
, h
, line_height
;
5283 int start_pos
= IT_CHARPOS (*it
);
5287 /* Estimate how many newlines we must move back. */
5288 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5290 /* Set the iterator's position that many lines back. */
5291 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5292 back_to_previous_visible_line_start (it
);
5294 /* Reseat the iterator here. When moving backward, we don't want
5295 reseat to skip forward over invisible text, set up the iterator
5296 to deliver from overlay strings at the new position etc. So,
5297 use reseat_1 here. */
5298 reseat_1 (it
, it
->current
.pos
, 1);
5300 /* We are now surely at a line start. */
5301 it
->current_x
= it
->hpos
= 0;
5303 /* Move forward and see what y-distance we moved. First move to the
5304 start of the next line so that we get its height. We need this
5305 height to be able to tell whether we reached the specified
5308 it2
.max_ascent
= it2
.max_descent
= 0;
5309 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5310 MOVE_TO_POS
| MOVE_TO_VPOS
);
5311 xassert (IT_CHARPOS (*it
) >= BEGV
);
5312 line_height
= it2
.max_ascent
+ it2
.max_descent
;
5314 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5315 xassert (IT_CHARPOS (*it
) >= BEGV
);
5316 h
= it2
.current_y
- it
->current_y
;
5317 nlines
= it2
.vpos
- it
->vpos
;
5319 /* Correct IT's y and vpos position. */
5325 /* DY == 0 means move to the start of the screen line. The
5326 value of nlines is > 0 if continuation lines were involved. */
5328 move_it_by_lines (it
, nlines
, 1);
5329 xassert (IT_CHARPOS (*it
) <= start_pos
);
5333 /* The y-position we try to reach. Note that h has been
5334 subtracted in front of the if-statement. */
5335 int target_y
= it
->current_y
+ h
- dy
;
5337 /* If we did not reach target_y, try to move further backward if
5338 we can. If we moved too far backward, try to move forward. */
5339 if (target_y
< it
->current_y
5340 && IT_CHARPOS (*it
) > BEGV
)
5342 move_it_vertically (it
, target_y
- it
->current_y
);
5343 xassert (IT_CHARPOS (*it
) >= BEGV
);
5345 else if (target_y
>= it
->current_y
+ line_height
5346 && IT_CHARPOS (*it
) < ZV
)
5348 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5349 xassert (IT_CHARPOS (*it
) >= BEGV
);
5355 /* Move IT by a specified amount of pixel lines DY. DY negative means
5356 move backwards. DY = 0 means move to start of screen line. At the
5357 end, IT will be on the start of a screen line. */
5360 move_it_vertically (it
, dy
)
5365 move_it_vertically_backward (it
, -dy
);
5368 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5369 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5370 MOVE_TO_POS
| MOVE_TO_Y
);
5371 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5373 /* If buffer ends in ZV without a newline, move to the start of
5374 the line to satisfy the post-condition. */
5375 if (IT_CHARPOS (*it
) == ZV
5376 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5377 move_it_by_lines (it
, 0, 0);
5382 /* Move iterator IT past the end of the text line it is in. */
5385 move_it_past_eol (it
)
5388 enum move_it_result rc
;
5390 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5391 if (rc
== MOVE_NEWLINE_OR_CR
)
5392 set_iterator_to_next (it
, 0);
5396 #if 0 /* Currently not used. */
5398 /* Return non-zero if some text between buffer positions START_CHARPOS
5399 and END_CHARPOS is invisible. IT->window is the window for text
5403 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5405 int start_charpos
, end_charpos
;
5407 Lisp_Object prop
, limit
;
5408 int invisible_found_p
;
5410 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5412 /* Is text at START invisible? */
5413 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5415 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5416 invisible_found_p
= 1;
5419 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5421 make_number (end_charpos
));
5422 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5425 return invisible_found_p
;
5431 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5432 negative means move up. DVPOS == 0 means move to the start of the
5433 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5434 NEED_Y_P is zero, IT->current_y will be left unchanged.
5436 Further optimization ideas: If we would know that IT->f doesn't use
5437 a face with proportional font, we could be faster for
5438 truncate-lines nil. */
5441 move_it_by_lines (it
, dvpos
, need_y_p
)
5443 int dvpos
, need_y_p
;
5445 struct position pos
;
5447 if (!FRAME_WINDOW_P (it
->f
))
5449 struct text_pos textpos
;
5451 /* We can use vmotion on frames without proportional fonts. */
5452 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5453 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5454 reseat (it
, textpos
, 1);
5455 it
->vpos
+= pos
.vpos
;
5456 it
->current_y
+= pos
.vpos
;
5458 else if (dvpos
== 0)
5460 /* DVPOS == 0 means move to the start of the screen line. */
5461 move_it_vertically_backward (it
, 0);
5462 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5465 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5469 int start_charpos
, i
;
5471 /* Go back -DVPOS visible lines and reseat the iterator there. */
5472 start_charpos
= IT_CHARPOS (*it
);
5473 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5474 back_to_previous_visible_line_start (it
);
5475 reseat (it
, it
->current
.pos
, 1);
5476 it
->current_x
= it
->hpos
= 0;
5478 /* Above call may have moved too far if continuation lines
5479 are involved. Scan forward and see if it did. */
5481 it2
.vpos
= it2
.current_y
= 0;
5482 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5483 it
->vpos
-= it2
.vpos
;
5484 it
->current_y
-= it2
.current_y
;
5485 it
->current_x
= it
->hpos
= 0;
5487 /* If we moved too far, move IT some lines forward. */
5488 if (it2
.vpos
> -dvpos
)
5490 int delta
= it2
.vpos
+ dvpos
;
5491 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5498 /***********************************************************************
5500 ***********************************************************************/
5503 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5507 add_to_log (format
, arg1
, arg2
)
5509 Lisp_Object arg1
, arg2
;
5511 Lisp_Object args
[3];
5512 Lisp_Object msg
, fmt
;
5515 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5517 /* Do nothing if called asynchronously. Inserting text into
5518 a buffer may call after-change-functions and alike and
5519 that would means running Lisp asynchronously. */
5520 if (handling_signal
)
5524 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5526 args
[0] = fmt
= build_string (format
);
5529 msg
= Fformat (3, args
);
5531 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5532 buffer
= (char *) alloca (len
);
5533 strcpy (buffer
, XSTRING (msg
)->data
);
5535 message_dolog (buffer
, len
- 1, 1, 0);
5540 /* Output a newline in the *Messages* buffer if "needs" one. */
5543 message_log_maybe_newline ()
5545 if (message_log_need_newline
)
5546 message_dolog ("", 0, 1, 0);
5550 /* Add a string M of length NBYTES to the message log, optionally
5551 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5552 nonzero, means interpret the contents of M as multibyte. This
5553 function calls low-level routines in order to bypass text property
5554 hooks, etc. which might not be safe to run. */
5557 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5559 int nbytes
, nlflag
, multibyte
;
5561 if (!NILP (Vmessage_log_max
))
5563 struct buffer
*oldbuf
;
5564 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5565 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5566 int point_at_end
= 0;
5568 Lisp_Object old_deactivate_mark
, tem
;
5569 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5571 old_deactivate_mark
= Vdeactivate_mark
;
5572 oldbuf
= current_buffer
;
5573 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5574 current_buffer
->undo_list
= Qt
;
5576 oldpoint
= Fpoint_marker ();
5577 oldbegv
= Fpoint_min_marker ();
5578 oldzv
= Fpoint_max_marker ();
5579 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5587 BEGV_BYTE
= BEG_BYTE
;
5590 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5592 /* Insert the string--maybe converting multibyte to single byte
5593 or vice versa, so that all the text fits the buffer. */
5595 && NILP (current_buffer
->enable_multibyte_characters
))
5597 int i
, c
, char_bytes
;
5598 unsigned char work
[1];
5600 /* Convert a multibyte string to single-byte
5601 for the *Message* buffer. */
5602 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5604 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5605 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5607 : multibyte_char_to_unibyte (c
, Qnil
));
5608 insert_1_both (work
, 1, 1, 1, 0, 0);
5611 else if (! multibyte
5612 && ! NILP (current_buffer
->enable_multibyte_characters
))
5614 int i
, c
, char_bytes
;
5615 unsigned char *msg
= (unsigned char *) m
;
5616 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5617 /* Convert a single-byte string to multibyte
5618 for the *Message* buffer. */
5619 for (i
= 0; i
< nbytes
; i
++)
5621 c
= unibyte_char_to_multibyte (msg
[i
]);
5622 char_bytes
= CHAR_STRING (c
, str
);
5623 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5627 insert_1 (m
, nbytes
, 1, 0, 0);
5631 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5632 insert_1 ("\n", 1, 1, 0, 0);
5634 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5636 this_bol_byte
= PT_BYTE
;
5640 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5642 prev_bol_byte
= PT_BYTE
;
5644 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5645 this_bol
, this_bol_byte
);
5648 del_range_both (prev_bol
, prev_bol_byte
,
5649 this_bol
, this_bol_byte
, 0);
5655 /* If you change this format, don't forget to also
5656 change message_log_check_duplicate. */
5657 sprintf (dupstr
, " [%d times]", dup
);
5658 duplen
= strlen (dupstr
);
5659 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5660 insert_1 (dupstr
, duplen
, 1, 0, 1);
5665 if (NATNUMP (Vmessage_log_max
))
5667 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5668 -XFASTINT (Vmessage_log_max
) - 1, 0);
5669 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5672 BEGV
= XMARKER (oldbegv
)->charpos
;
5673 BEGV_BYTE
= marker_byte_position (oldbegv
);
5682 ZV
= XMARKER (oldzv
)->charpos
;
5683 ZV_BYTE
= marker_byte_position (oldzv
);
5687 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5689 /* We can't do Fgoto_char (oldpoint) because it will run some
5691 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5692 XMARKER (oldpoint
)->bytepos
);
5695 free_marker (oldpoint
);
5696 free_marker (oldbegv
);
5697 free_marker (oldzv
);
5699 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5700 set_buffer_internal (oldbuf
);
5702 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5703 message_log_need_newline
= !nlflag
;
5704 Vdeactivate_mark
= old_deactivate_mark
;
5709 /* We are at the end of the buffer after just having inserted a newline.
5710 (Note: We depend on the fact we won't be crossing the gap.)
5711 Check to see if the most recent message looks a lot like the previous one.
5712 Return 0 if different, 1 if the new one should just replace it, or a
5713 value N > 1 if we should also append " [N times]". */
5716 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5717 int prev_bol
, this_bol
;
5718 int prev_bol_byte
, this_bol_byte
;
5721 int len
= Z_BYTE
- 1 - this_bol_byte
;
5723 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5724 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5726 for (i
= 0; i
< len
; i
++)
5728 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5736 if (*p1
++ == ' ' && *p1
++ == '[')
5739 while (*p1
>= '0' && *p1
<= '9')
5740 n
= n
* 10 + *p1
++ - '0';
5741 if (strncmp (p1
, " times]\n", 8) == 0)
5748 /* Display an echo area message M with a specified length of NBYTES
5749 bytes. The string may include null characters. If M is 0, clear
5750 out any existing message, and let the mini-buffer text show
5753 The buffer M must continue to exist until after the echo area gets
5754 cleared or some other message gets displayed there. This means do
5755 not pass text that is stored in a Lisp string; do not pass text in
5756 a buffer that was alloca'd. */
5759 message2 (m
, nbytes
, multibyte
)
5764 /* First flush out any partial line written with print. */
5765 message_log_maybe_newline ();
5767 message_dolog (m
, nbytes
, 1, multibyte
);
5768 message2_nolog (m
, nbytes
, multibyte
);
5772 /* The non-logging counterpart of message2. */
5775 message2_nolog (m
, nbytes
, multibyte
)
5779 struct frame
*sf
= SELECTED_FRAME ();
5780 message_enable_multibyte
= multibyte
;
5784 if (noninteractive_need_newline
)
5785 putc ('\n', stderr
);
5786 noninteractive_need_newline
= 0;
5788 fwrite (m
, nbytes
, 1, stderr
);
5789 if (cursor_in_echo_area
== 0)
5790 fprintf (stderr
, "\n");
5793 /* A null message buffer means that the frame hasn't really been
5794 initialized yet. Error messages get reported properly by
5795 cmd_error, so this must be just an informative message; toss it. */
5796 else if (INTERACTIVE
5797 && sf
->glyphs_initialized_p
5798 && FRAME_MESSAGE_BUF (sf
))
5800 Lisp_Object mini_window
;
5803 /* Get the frame containing the mini-buffer
5804 that the selected frame is using. */
5805 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5806 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5808 FRAME_SAMPLE_VISIBILITY (f
);
5809 if (FRAME_VISIBLE_P (sf
)
5810 && ! FRAME_VISIBLE_P (f
))
5811 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5815 set_message (m
, Qnil
, nbytes
, multibyte
);
5816 if (minibuffer_auto_raise
)
5817 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5820 clear_message (1, 1);
5822 do_pending_window_change (0);
5823 echo_area_display (1);
5824 do_pending_window_change (0);
5825 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5826 (*frame_up_to_date_hook
) (f
);
5831 /* Display an echo area message M with a specified length of NBYTES
5832 bytes. The string may include null characters. If M is not a
5833 string, clear out any existing message, and let the mini-buffer
5834 text show through. */
5837 message3 (m
, nbytes
, multibyte
)
5842 struct gcpro gcpro1
;
5846 /* First flush out any partial line written with print. */
5847 message_log_maybe_newline ();
5849 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5850 message3_nolog (m
, nbytes
, multibyte
);
5856 /* The non-logging version of message3. */
5859 message3_nolog (m
, nbytes
, multibyte
)
5861 int nbytes
, multibyte
;
5863 struct frame
*sf
= SELECTED_FRAME ();
5864 message_enable_multibyte
= multibyte
;
5868 if (noninteractive_need_newline
)
5869 putc ('\n', stderr
);
5870 noninteractive_need_newline
= 0;
5872 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5873 if (cursor_in_echo_area
== 0)
5874 fprintf (stderr
, "\n");
5877 /* A null message buffer means that the frame hasn't really been
5878 initialized yet. Error messages get reported properly by
5879 cmd_error, so this must be just an informative message; toss it. */
5880 else if (INTERACTIVE
5881 && sf
->glyphs_initialized_p
5882 && FRAME_MESSAGE_BUF (sf
))
5884 Lisp_Object mini_window
;
5888 /* Get the frame containing the mini-buffer
5889 that the selected frame is using. */
5890 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5891 frame
= XWINDOW (mini_window
)->frame
;
5894 FRAME_SAMPLE_VISIBILITY (f
);
5895 if (FRAME_VISIBLE_P (sf
)
5896 && !FRAME_VISIBLE_P (f
))
5897 Fmake_frame_visible (frame
);
5899 if (STRINGP (m
) && XSTRING (m
)->size
)
5901 set_message (NULL
, m
, nbytes
, multibyte
);
5902 if (minibuffer_auto_raise
)
5903 Fraise_frame (frame
);
5906 clear_message (1, 1);
5908 do_pending_window_change (0);
5909 echo_area_display (1);
5910 do_pending_window_change (0);
5911 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5912 (*frame_up_to_date_hook
) (f
);
5917 /* Display a null-terminated echo area message M. If M is 0, clear
5918 out any existing message, and let the mini-buffer text show through.
5920 The buffer M must continue to exist until after the echo area gets
5921 cleared or some other message gets displayed there. Do not pass
5922 text that is stored in a Lisp string. Do not pass text in a buffer
5923 that was alloca'd. */
5929 message2 (m
, (m
? strlen (m
) : 0), 0);
5933 /* The non-logging counterpart of message1. */
5939 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5942 /* Display a message M which contains a single %s
5943 which gets replaced with STRING. */
5946 message_with_string (m
, string
, log
)
5955 if (noninteractive_need_newline
)
5956 putc ('\n', stderr
);
5957 noninteractive_need_newline
= 0;
5958 fprintf (stderr
, m
, XSTRING (string
)->data
);
5959 if (cursor_in_echo_area
== 0)
5960 fprintf (stderr
, "\n");
5964 else if (INTERACTIVE
)
5966 /* The frame whose minibuffer we're going to display the message on.
5967 It may be larger than the selected frame, so we need
5968 to use its buffer, not the selected frame's buffer. */
5969 Lisp_Object mini_window
;
5970 struct frame
*f
, *sf
= SELECTED_FRAME ();
5972 /* Get the frame containing the minibuffer
5973 that the selected frame is using. */
5974 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5975 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5977 /* A null message buffer means that the frame hasn't really been
5978 initialized yet. Error messages get reported properly by
5979 cmd_error, so this must be just an informative message; toss it. */
5980 if (FRAME_MESSAGE_BUF (f
))
5984 a
[0] = (char *) XSTRING (string
)->data
;
5986 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5987 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5990 message2 (FRAME_MESSAGE_BUF (f
), len
,
5991 STRING_MULTIBYTE (string
));
5993 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5994 STRING_MULTIBYTE (string
));
5996 /* Print should start at the beginning of the message
5997 buffer next time. */
5998 message_buf_print
= 0;
6004 /* Dump an informative message to the minibuf. If M is 0, clear out
6005 any existing message, and let the mini-buffer text show through. */
6009 message (m
, a1
, a2
, a3
)
6011 EMACS_INT a1
, a2
, a3
;
6017 if (noninteractive_need_newline
)
6018 putc ('\n', stderr
);
6019 noninteractive_need_newline
= 0;
6020 fprintf (stderr
, m
, a1
, a2
, a3
);
6021 if (cursor_in_echo_area
== 0)
6022 fprintf (stderr
, "\n");
6026 else if (INTERACTIVE
)
6028 /* The frame whose mini-buffer we're going to display the message
6029 on. It may be larger than the selected frame, so we need to
6030 use its buffer, not the selected frame's buffer. */
6031 Lisp_Object mini_window
;
6032 struct frame
*f
, *sf
= SELECTED_FRAME ();
6034 /* Get the frame containing the mini-buffer
6035 that the selected frame is using. */
6036 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6037 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6039 /* A null message buffer means that the frame hasn't really been
6040 initialized yet. Error messages get reported properly by
6041 cmd_error, so this must be just an informative message; toss
6043 if (FRAME_MESSAGE_BUF (f
))
6054 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6055 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6057 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6058 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6060 #endif /* NO_ARG_ARRAY */
6062 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6067 /* Print should start at the beginning of the message
6068 buffer next time. */
6069 message_buf_print
= 0;
6075 /* The non-logging version of message. */
6078 message_nolog (m
, a1
, a2
, a3
)
6080 EMACS_INT a1
, a2
, a3
;
6082 Lisp_Object old_log_max
;
6083 old_log_max
= Vmessage_log_max
;
6084 Vmessage_log_max
= Qnil
;
6085 message (m
, a1
, a2
, a3
);
6086 Vmessage_log_max
= old_log_max
;
6090 /* Display the current message in the current mini-buffer. This is
6091 only called from error handlers in process.c, and is not time
6097 if (!NILP (echo_area_buffer
[0]))
6100 string
= Fcurrent_message ();
6101 message3 (string
, XSTRING (string
)->size
,
6102 !NILP (current_buffer
->enable_multibyte_characters
));
6107 /* Make sure echo area buffers in echo_buffers[] are life. If they
6108 aren't, make new ones. */
6111 ensure_echo_area_buffers ()
6115 for (i
= 0; i
< 2; ++i
)
6116 if (!BUFFERP (echo_buffer
[i
])
6117 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6120 Lisp_Object old_buffer
;
6123 old_buffer
= echo_buffer
[i
];
6124 sprintf (name
, " *Echo Area %d*", i
);
6125 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6126 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6128 for (j
= 0; j
< 2; ++j
)
6129 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6130 echo_area_buffer
[j
] = echo_buffer
[i
];
6135 /* Call FN with args A1..A4 with either the current or last displayed
6136 echo_area_buffer as current buffer.
6138 WHICH zero means use the current message buffer
6139 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6140 from echo_buffer[] and clear it.
6142 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6143 suitable buffer from echo_buffer[] and clear it.
6145 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6146 that the current message becomes the last displayed one, make
6147 choose a suitable buffer for echo_area_buffer[0], and clear it.
6149 Value is what FN returns. */
6152 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6155 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6161 int this_one
, the_other
, clear_buffer_p
, rc
;
6162 int count
= BINDING_STACK_SIZE ();
6164 /* If buffers aren't life, make new ones. */
6165 ensure_echo_area_buffers ();
6170 this_one
= 0, the_other
= 1;
6172 this_one
= 1, the_other
= 0;
6175 this_one
= 0, the_other
= 1;
6178 /* We need a fresh one in case the current echo buffer equals
6179 the one containing the last displayed echo area message. */
6180 if (!NILP (echo_area_buffer
[this_one
])
6181 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6182 echo_area_buffer
[this_one
] = Qnil
;
6185 /* Choose a suitable buffer from echo_buffer[] is we don't
6187 if (NILP (echo_area_buffer
[this_one
]))
6189 echo_area_buffer
[this_one
]
6190 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6191 ? echo_buffer
[the_other
]
6192 : echo_buffer
[this_one
]);
6196 buffer
= echo_area_buffer
[this_one
];
6198 /* Don't get confused by reusing the buffer used for echoing
6199 for a different purpose. */
6200 if (!echoing
&& EQ (buffer
, echo_message_buffer
))
6203 record_unwind_protect (unwind_with_echo_area_buffer
,
6204 with_echo_area_buffer_unwind_data (w
));
6206 /* Make the echo area buffer current. Note that for display
6207 purposes, it is not necessary that the displayed window's buffer
6208 == current_buffer, except for text property lookup. So, let's
6209 only set that buffer temporarily here without doing a full
6210 Fset_window_buffer. We must also change w->pointm, though,
6211 because otherwise an assertions in unshow_buffer fails, and Emacs
6213 set_buffer_internal_1 (XBUFFER (buffer
));
6217 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6220 current_buffer
->undo_list
= Qt
;
6221 current_buffer
->read_only
= Qnil
;
6222 specbind (Qinhibit_read_only
, Qt
);
6224 if (clear_buffer_p
&& Z
> BEG
)
6227 xassert (BEGV
>= BEG
);
6228 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6230 rc
= fn (a1
, a2
, a3
, a4
);
6232 xassert (BEGV
>= BEG
);
6233 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6235 unbind_to (count
, Qnil
);
6240 /* Save state that should be preserved around the call to the function
6241 FN called in with_echo_area_buffer. */
6244 with_echo_area_buffer_unwind_data (w
)
6250 /* Reduce consing by keeping one vector in
6251 Vwith_echo_area_save_vector. */
6252 vector
= Vwith_echo_area_save_vector
;
6253 Vwith_echo_area_save_vector
= Qnil
;
6256 vector
= Fmake_vector (make_number (7), Qnil
);
6258 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6259 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6260 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6264 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6265 AREF (vector
, i
) = w
->buffer
; ++i
;
6266 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6267 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6272 for (; i
< end
; ++i
)
6273 AREF (vector
, i
) = Qnil
;
6276 xassert (i
== ASIZE (vector
));
6281 /* Restore global state from VECTOR which was created by
6282 with_echo_area_buffer_unwind_data. */
6285 unwind_with_echo_area_buffer (vector
)
6288 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6289 Vdeactivate_mark
= AREF (vector
, 1);
6290 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6292 if (WINDOWP (AREF (vector
, 3)))
6295 Lisp_Object buffer
, charpos
, bytepos
;
6297 w
= XWINDOW (AREF (vector
, 3));
6298 buffer
= AREF (vector
, 4);
6299 charpos
= AREF (vector
, 5);
6300 bytepos
= AREF (vector
, 6);
6303 set_marker_both (w
->pointm
, buffer
,
6304 XFASTINT (charpos
), XFASTINT (bytepos
));
6307 Vwith_echo_area_save_vector
= vector
;
6312 /* Set up the echo area for use by print functions. MULTIBYTE_P
6313 non-zero means we will print multibyte. */
6316 setup_echo_area_for_printing (multibyte_p
)
6319 ensure_echo_area_buffers ();
6321 if (!message_buf_print
)
6323 /* A message has been output since the last time we printed.
6324 Choose a fresh echo area buffer. */
6325 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6326 echo_area_buffer
[0] = echo_buffer
[1];
6328 echo_area_buffer
[0] = echo_buffer
[0];
6330 /* Switch to that buffer and clear it. */
6331 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6332 current_buffer
->truncate_lines
= Qnil
;
6336 int count
= BINDING_STACK_SIZE ();
6337 specbind (Qinhibit_read_only
, Qt
);
6339 unbind_to (count
, Qnil
);
6341 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6343 /* Set up the buffer for the multibyteness we need. */
6345 != !NILP (current_buffer
->enable_multibyte_characters
))
6346 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6348 /* Raise the frame containing the echo area. */
6349 if (minibuffer_auto_raise
)
6351 struct frame
*sf
= SELECTED_FRAME ();
6352 Lisp_Object mini_window
;
6353 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6354 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6357 message_log_maybe_newline ();
6358 message_buf_print
= 1;
6362 if (NILP (echo_area_buffer
[0]))
6364 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6365 echo_area_buffer
[0] = echo_buffer
[1];
6367 echo_area_buffer
[0] = echo_buffer
[0];
6370 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6372 /* Someone switched buffers between print requests. */
6373 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6374 current_buffer
->truncate_lines
= Qnil
;
6380 /* Display an echo area message in window W. Value is non-zero if W's
6381 height is changed. If display_last_displayed_message_p is
6382 non-zero, display the message that was last displayed, otherwise
6383 display the current message. */
6386 display_echo_area (w
)
6389 int i
, no_message_p
, window_height_changed_p
, count
;
6391 /* Temporarily disable garbage collections while displaying the echo
6392 area. This is done because a GC can print a message itself.
6393 That message would modify the echo area buffer's contents while a
6394 redisplay of the buffer is going on, and seriously confuse
6396 count
= inhibit_garbage_collection ();
6398 /* If there is no message, we must call display_echo_area_1
6399 nevertheless because it resizes the window. But we will have to
6400 reset the echo_area_buffer in question to nil at the end because
6401 with_echo_area_buffer will sets it to an empty buffer. */
6402 i
= display_last_displayed_message_p
? 1 : 0;
6403 no_message_p
= NILP (echo_area_buffer
[i
]);
6405 window_height_changed_p
6406 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6407 display_echo_area_1
,
6408 (EMACS_INT
) w
, Qnil
, 0, 0);
6411 echo_area_buffer
[i
] = Qnil
;
6413 unbind_to (count
, Qnil
);
6414 return window_height_changed_p
;
6418 /* Helper for display_echo_area. Display the current buffer which
6419 contains the current echo area message in window W, a mini-window,
6420 a pointer to which is passed in A1. A2..A4 are currently not used.
6421 Change the height of W so that all of the message is displayed.
6422 Value is non-zero if height of W was changed. */
6425 display_echo_area_1 (a1
, a2
, a3
, a4
)
6430 struct window
*w
= (struct window
*) a1
;
6432 struct text_pos start
;
6433 int window_height_changed_p
= 0;
6435 /* Do this before displaying, so that we have a large enough glyph
6436 matrix for the display. */
6437 window_height_changed_p
= resize_mini_window (w
, 0);
6440 clear_glyph_matrix (w
->desired_matrix
);
6441 XSETWINDOW (window
, w
);
6442 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6443 try_window (window
, start
);
6445 return window_height_changed_p
;
6449 /* Resize the echo area window to exactly the size needed for the
6450 currently displayed message, if there is one. */
6453 resize_echo_area_axactly ()
6455 if (BUFFERP (echo_area_buffer
[0])
6456 && WINDOWP (echo_area_window
))
6458 struct window
*w
= XWINDOW (echo_area_window
);
6461 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6462 (EMACS_INT
) w
, Qnil
, 0, 0);
6465 ++windows_or_buffers_changed
;
6466 ++update_mode_lines
;
6467 redisplay_internal (0);
6473 /* Callback function for with_echo_area_buffer, when used from
6474 resize_echo_area_axactly. A1 contains a pointer to the window to
6475 resize, A2 to A4 are not used. Value is what resize_mini_window
6479 resize_mini_window_1 (a1
, a2
, a3
, a4
)
6484 return resize_mini_window ((struct window
*) a1
, 1);
6488 /* Resize mini-window W to fit the size of its contents. EXACT:P
6489 means size the window exactly to the size needed. Otherwise, it's
6490 only enlarged until W's buffer is empty. Value is non-zero if
6491 the window height has been changed. */
6494 resize_mini_window (w
, exact_p
)
6498 struct frame
*f
= XFRAME (w
->frame
);
6499 int window_height_changed_p
= 0;
6501 xassert (MINI_WINDOW_P (w
));
6503 /* Nil means don't try to resize. */
6504 if (NILP (Vresize_mini_windows
)
6505 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6508 if (!FRAME_MINIBUF_ONLY_P (f
))
6511 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6512 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6513 int height
, max_height
;
6514 int unit
= CANON_Y_UNIT (f
);
6515 struct text_pos start
;
6516 struct buffer
*old_current_buffer
= NULL
;
6518 if (current_buffer
!= XBUFFER (w
->buffer
))
6520 old_current_buffer
= current_buffer
;
6521 set_buffer_internal (XBUFFER (w
->buffer
));
6524 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6526 /* Compute the max. number of lines specified by the user. */
6527 if (FLOATP (Vmax_mini_window_height
))
6528 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
6529 else if (INTEGERP (Vmax_mini_window_height
))
6530 max_height
= XINT (Vmax_mini_window_height
);
6532 max_height
= total_height
/ 4;
6534 /* Correct that max. height if it's bogus. */
6535 max_height
= max (1, max_height
);
6536 max_height
= min (total_height
, max_height
);
6538 /* Find out the height of the text in the window. */
6539 if (it
.truncate_lines_p
)
6544 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6545 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6546 height
= it
.current_y
+ last_height
;
6548 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6549 height
-= it
.extra_line_spacing
;
6550 height
= (height
+ unit
- 1) / unit
;
6553 /* Compute a suitable window start. */
6554 if (height
> max_height
)
6556 height
= max_height
;
6557 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6558 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6559 start
= it
.current
.pos
;
6562 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6563 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6565 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6567 /* Let it grow only, until we display an empty message, in which
6568 case the window shrinks again. */
6569 if (height
> XFASTINT (w
->height
))
6571 int old_height
= XFASTINT (w
->height
);
6572 freeze_window_starts (f
, 1);
6573 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6574 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6576 else if (height
< XFASTINT (w
->height
)
6577 && (exact_p
|| BEGV
== ZV
))
6579 int old_height
= XFASTINT (w
->height
);
6580 freeze_window_starts (f
, 0);
6581 shrink_mini_window (w
);
6582 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6587 /* Always resize to exact size needed. */
6588 if (height
> XFASTINT (w
->height
))
6590 int old_height
= XFASTINT (w
->height
);
6591 freeze_window_starts (f
, 1);
6592 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6593 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6595 else if (height
< XFASTINT (w
->height
))
6597 int old_height
= XFASTINT (w
->height
);
6598 freeze_window_starts (f
, 0);
6599 shrink_mini_window (w
);
6603 freeze_window_starts (f
, 1);
6604 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6607 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6611 if (old_current_buffer
)
6612 set_buffer_internal (old_current_buffer
);
6615 return window_height_changed_p
;
6619 /* Value is the current message, a string, or nil if there is no
6627 if (NILP (echo_area_buffer
[0]))
6631 with_echo_area_buffer (0, 0, current_message_1
,
6632 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6634 echo_area_buffer
[0] = Qnil
;
6642 current_message_1 (a1
, a2
, a3
, a4
)
6647 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6650 *msg
= make_buffer_string (BEG
, Z
, 1);
6657 /* Push the current message on Vmessage_stack for later restauration
6658 by restore_message. Value is non-zero if the current message isn't
6659 empty. This is a relatively infrequent operation, so it's not
6660 worth optimizing. */
6666 msg
= current_message ();
6667 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6668 return STRINGP (msg
);
6672 /* Handler for record_unwind_protect calling pop_message. */
6675 push_message_unwind (dummy
)
6683 /* Restore message display from the top of Vmessage_stack. */
6690 xassert (CONSP (Vmessage_stack
));
6691 msg
= XCAR (Vmessage_stack
);
6693 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6695 message3_nolog (msg
, 0, 0);
6699 /* Pop the top-most entry off Vmessage_stack. */
6704 xassert (CONSP (Vmessage_stack
));
6705 Vmessage_stack
= XCDR (Vmessage_stack
);
6709 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6710 exits. If the stack is not empty, we have a missing pop_message
6714 check_message_stack ()
6716 if (!NILP (Vmessage_stack
))
6721 /* Truncate to NCHARS what will be displayed in the echo area the next
6722 time we display it---but don't redisplay it now. */
6725 truncate_echo_area (nchars
)
6729 echo_area_buffer
[0] = Qnil
;
6730 /* A null message buffer means that the frame hasn't really been
6731 initialized yet. Error messages get reported properly by
6732 cmd_error, so this must be just an informative message; toss it. */
6733 else if (!noninteractive
6735 && !NILP (echo_area_buffer
[0]))
6737 struct frame
*sf
= SELECTED_FRAME ();
6738 if (FRAME_MESSAGE_BUF (sf
))
6739 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6744 /* Helper function for truncate_echo_area. Truncate the current
6745 message to at most NCHARS characters. */
6748 truncate_message_1 (nchars
, a2
, a3
, a4
)
6753 if (BEG
+ nchars
< Z
)
6754 del_range (BEG
+ nchars
, Z
);
6756 echo_area_buffer
[0] = Qnil
;
6761 /* Set the current message to a substring of S or STRING.
6763 If STRING is a Lisp string, set the message to the first NBYTES
6764 bytes from STRING. NBYTES zero means use the whole string. If
6765 STRING is multibyte, the message will be displayed multibyte.
6767 If S is not null, set the message to the first LEN bytes of S. LEN
6768 zero means use the whole string. MULTIBYTE_P non-zero means S is
6769 multibyte. Display the message multibyte in that case. */
6772 set_message (s
, string
, nbytes
, multibyte_p
)
6777 message_enable_multibyte
6778 = ((s
&& multibyte_p
)
6779 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6781 with_echo_area_buffer (0, -1, set_message_1
,
6782 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6783 message_buf_print
= 0;
6784 help_echo_showing_p
= 0;
6788 /* Helper function for set_message. Arguments have the same meaning
6789 as there, with A1 corresponding to S and A2 corresponding to STRING
6790 This function is called with the echo area buffer being
6794 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6797 EMACS_INT nbytes
, multibyte_p
;
6799 char *s
= (char *) a1
;
6800 Lisp_Object string
= a2
;
6804 /* Change multibyteness of the echo buffer appropriately. */
6805 if (message_enable_multibyte
6806 != !NILP (current_buffer
->enable_multibyte_characters
))
6807 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6809 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6811 /* Insert new message at BEG. */
6812 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6814 if (STRINGP (string
))
6819 nbytes
= XSTRING (string
)->size_byte
;
6820 nchars
= string_byte_to_char (string
, nbytes
);
6822 /* This function takes care of single/multibyte conversion. We
6823 just have to ensure that the echo area buffer has the right
6824 setting of enable_multibyte_characters. */
6825 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6830 nbytes
= strlen (s
);
6832 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6834 /* Convert from multi-byte to single-byte. */
6836 unsigned char work
[1];
6838 /* Convert a multibyte string to single-byte. */
6839 for (i
= 0; i
< nbytes
; i
+= n
)
6841 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6842 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6844 : multibyte_char_to_unibyte (c
, Qnil
));
6845 insert_1_both (work
, 1, 1, 1, 0, 0);
6848 else if (!multibyte_p
6849 && !NILP (current_buffer
->enable_multibyte_characters
))
6851 /* Convert from single-byte to multi-byte. */
6853 unsigned char *msg
= (unsigned char *) s
;
6854 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6856 /* Convert a single-byte string to multibyte. */
6857 for (i
= 0; i
< nbytes
; i
++)
6859 c
= unibyte_char_to_multibyte (msg
[i
]);
6860 n
= CHAR_STRING (c
, str
);
6861 insert_1_both (str
, 1, n
, 1, 0, 0);
6865 insert_1 (s
, nbytes
, 1, 0, 0);
6872 /* Clear messages. CURRENT_P non-zero means clear the current
6873 message. LAST_DISPLAYED_P non-zero means clear the message
6877 clear_message (current_p
, last_displayed_p
)
6878 int current_p
, last_displayed_p
;
6881 echo_area_buffer
[0] = Qnil
;
6883 if (last_displayed_p
)
6884 echo_area_buffer
[1] = Qnil
;
6886 message_buf_print
= 0;
6889 /* Clear garbaged frames.
6891 This function is used where the old redisplay called
6892 redraw_garbaged_frames which in turn called redraw_frame which in
6893 turn called clear_frame. The call to clear_frame was a source of
6894 flickering. I believe a clear_frame is not necessary. It should
6895 suffice in the new redisplay to invalidate all current matrices,
6896 and ensure a complete redisplay of all windows. */
6899 clear_garbaged_frames ()
6903 Lisp_Object tail
, frame
;
6905 FOR_EACH_FRAME (tail
, frame
)
6907 struct frame
*f
= XFRAME (frame
);
6909 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6911 clear_current_matrices (f
);
6917 ++windows_or_buffers_changed
;
6922 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6923 is non-zero update selected_frame. Value is non-zero if the
6924 mini-windows height has been changed. */
6927 echo_area_display (update_frame_p
)
6930 Lisp_Object mini_window
;
6933 int window_height_changed_p
= 0;
6934 struct frame
*sf
= SELECTED_FRAME ();
6936 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6937 w
= XWINDOW (mini_window
);
6938 f
= XFRAME (WINDOW_FRAME (w
));
6940 /* Don't display if frame is invisible or not yet initialized. */
6941 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6944 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6946 #ifdef HAVE_WINDOW_SYSTEM
6947 /* When Emacs starts, selected_frame may be a visible terminal
6948 frame, even if we run under a window system. If we let this
6949 through, a message would be displayed on the terminal. */
6950 if (EQ (selected_frame
, Vterminal_frame
)
6951 && !NILP (Vwindow_system
))
6953 #endif /* HAVE_WINDOW_SYSTEM */
6956 /* Redraw garbaged frames. */
6958 clear_garbaged_frames ();
6960 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6962 echo_area_window
= mini_window
;
6963 window_height_changed_p
= display_echo_area (w
);
6964 w
->must_be_updated_p
= 1;
6966 /* Update the display, unless called from redisplay_internal.
6967 Also don't update the screen during redisplay itself. The
6968 update will happen at the end of redisplay, and an update
6969 here could cause confusion. */
6970 if (update_frame_p
&& !redisplaying_p
)
6974 /* If the display update has been interrupted by pending
6975 input, update mode lines in the frame. Due to the
6976 pending input, it might have been that redisplay hasn't
6977 been called, so that mode lines above the echo area are
6978 garbaged. This looks odd, so we prevent it here. */
6979 if (!display_completed
)
6980 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6982 if (window_height_changed_p
6983 /* Don't do this if Emacs is shutting down. Redisplay
6984 needs to run hooks. */
6985 && !NILP (Vrun_hooks
))
6987 /* Must update other windows. Likewise as in other
6988 cases, don't let this update be interrupted by
6990 int count
= BINDING_STACK_SIZE ();
6991 specbind (Qredisplay_dont_pause
, Qt
);
6992 windows_or_buffers_changed
= 1;
6993 redisplay_internal (0);
6994 unbind_to (count
, Qnil
);
6996 else if (FRAME_WINDOW_P (f
) && n
== 0)
6998 /* Window configuration is the same as before.
6999 Can do with a display update of the echo area,
7000 unless we displayed some mode lines. */
7001 update_single_window (w
, 1);
7002 rif
->flush_display (f
);
7005 update_frame (f
, 1, 1);
7007 /* If cursor is in the echo area, make sure that the next
7008 redisplay displays the minibuffer, so that the cursor will
7009 be replaced with what the minibuffer wants. */
7010 if (cursor_in_echo_area
)
7011 ++windows_or_buffers_changed
;
7014 else if (!EQ (mini_window
, selected_window
))
7015 windows_or_buffers_changed
++;
7017 /* Last displayed message is now the current message. */
7018 echo_area_buffer
[1] = echo_area_buffer
[0];
7020 /* Prevent redisplay optimization in redisplay_internal by resetting
7021 this_line_start_pos. This is done because the mini-buffer now
7022 displays the message instead of its buffer text. */
7023 if (EQ (mini_window
, selected_window
))
7024 CHARPOS (this_line_start_pos
) = 0;
7026 return window_height_changed_p
;
7031 /***********************************************************************
7033 ***********************************************************************/
7036 #ifdef HAVE_WINDOW_SYSTEM
7038 /* A buffer for constructing frame titles in it; allocated from the
7039 heap in init_xdisp and resized as needed in store_frame_title_char. */
7041 static char *frame_title_buf
;
7043 /* The buffer's end, and a current output position in it. */
7045 static char *frame_title_buf_end
;
7046 static char *frame_title_ptr
;
7049 /* Store a single character C for the frame title in frame_title_buf.
7050 Re-allocate frame_title_buf if necessary. */
7053 store_frame_title_char (c
)
7056 /* If output position has reached the end of the allocated buffer,
7057 double the buffer's size. */
7058 if (frame_title_ptr
== frame_title_buf_end
)
7060 int len
= frame_title_ptr
- frame_title_buf
;
7061 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7062 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7063 frame_title_buf_end
= frame_title_buf
+ new_size
;
7064 frame_title_ptr
= frame_title_buf
+ len
;
7067 *frame_title_ptr
++ = c
;
7071 /* Store part of a frame title in frame_title_buf, beginning at
7072 frame_title_ptr. STR is the string to store. Do not copy
7073 characters that yield more columns than PRECISION; PRECISION <= 0
7074 means copy the whole string. Pad with spaces until FIELD_WIDTH
7075 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7076 pad. Called from display_mode_element when it is used to build a
7080 store_frame_title (str
, field_width
, precision
)
7082 int field_width
, precision
;
7085 int dummy
, nbytes
, width
;
7087 /* Copy at most PRECISION chars from STR. */
7088 nbytes
= strlen (str
);
7089 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7091 store_frame_title_char (*str
++);
7093 /* Fill up with spaces until FIELD_WIDTH reached. */
7094 while (field_width
> 0
7097 store_frame_title_char (' ');
7105 /* Set the title of FRAME, if it has changed. The title format is
7106 Vicon_title_format if FRAME is iconified, otherwise it is
7107 frame_title_format. */
7110 x_consider_frame_title (frame
)
7113 struct frame
*f
= XFRAME (frame
);
7115 if (FRAME_WINDOW_P (f
)
7116 || FRAME_MINIBUF_ONLY_P (f
)
7117 || f
->explicit_name
)
7119 /* Do we have more than one visible frame on this X display? */
7122 struct buffer
*obuf
;
7126 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7128 struct frame
*tf
= XFRAME (XCAR (tail
));
7131 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7132 && !FRAME_MINIBUF_ONLY_P (tf
)
7133 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7137 /* Set global variable indicating that multiple frames exist. */
7138 multiple_frames
= CONSP (tail
);
7140 /* Switch to the buffer of selected window of the frame. Set up
7141 frame_title_ptr so that display_mode_element will output into it;
7142 then display the title. */
7143 obuf
= current_buffer
;
7144 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
7145 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7146 frame_title_ptr
= frame_title_buf
;
7147 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7148 NULL
, DEFAULT_FACE_ID
);
7149 display_mode_element (&it
, 0, -1, -1, fmt
);
7150 len
= frame_title_ptr
- frame_title_buf
;
7151 frame_title_ptr
= NULL
;
7152 set_buffer_internal (obuf
);
7154 /* Set the title only if it's changed. This avoids consing in
7155 the common case where it hasn't. (If it turns out that we've
7156 already wasted too much time by walking through the list with
7157 display_mode_element, then we might need to optimize at a
7158 higher level than this.) */
7159 if (! STRINGP (f
->name
)
7160 || STRING_BYTES (XSTRING (f
->name
)) != len
7161 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7162 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7166 #else /* not HAVE_WINDOW_SYSTEM */
7168 #define frame_title_ptr ((char *)0)
7169 #define store_frame_title(str, mincol, maxcol) 0
7171 #endif /* not HAVE_WINDOW_SYSTEM */
7176 /***********************************************************************
7178 ***********************************************************************/
7181 /* Prepare for redisplay by updating menu-bar item lists when
7182 appropriate. This can call eval. */
7185 prepare_menu_bars ()
7188 struct gcpro gcpro1
, gcpro2
;
7190 Lisp_Object tooltip_frame
;
7192 #ifdef HAVE_X_WINDOWS
7193 tooltip_frame
= tip_frame
;
7195 tooltip_frame
= Qnil
;
7198 /* Update all frame titles based on their buffer names, etc. We do
7199 this before the menu bars so that the buffer-menu will show the
7200 up-to-date frame titles. */
7201 #ifdef HAVE_WINDOW_SYSTEM
7202 if (windows_or_buffers_changed
|| update_mode_lines
)
7204 Lisp_Object tail
, frame
;
7206 FOR_EACH_FRAME (tail
, frame
)
7209 if (!EQ (frame
, tooltip_frame
)
7210 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7211 x_consider_frame_title (frame
);
7214 #endif /* HAVE_WINDOW_SYSTEM */
7216 /* Update the menu bar item lists, if appropriate. This has to be
7217 done before any actual redisplay or generation of display lines. */
7218 all_windows
= (update_mode_lines
7219 || buffer_shared
> 1
7220 || windows_or_buffers_changed
);
7223 Lisp_Object tail
, frame
;
7224 int count
= BINDING_STACK_SIZE ();
7226 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7228 FOR_EACH_FRAME (tail
, frame
)
7232 /* Ignore tooltip frame. */
7233 if (EQ (frame
, tooltip_frame
))
7236 /* If a window on this frame changed size, report that to
7237 the user and clear the size-change flag. */
7238 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7240 Lisp_Object functions
;
7242 /* Clear flag first in case we get an error below. */
7243 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7244 functions
= Vwindow_size_change_functions
;
7245 GCPRO2 (tail
, functions
);
7247 while (CONSP (functions
))
7249 call1 (XCAR (functions
), frame
);
7250 functions
= XCDR (functions
);
7256 update_menu_bar (f
, 0);
7257 #ifdef HAVE_WINDOW_SYSTEM
7258 update_tool_bar (f
, 0);
7263 unbind_to (count
, Qnil
);
7267 struct frame
*sf
= SELECTED_FRAME ();
7268 update_menu_bar (sf
, 1);
7269 #ifdef HAVE_WINDOW_SYSTEM
7270 update_tool_bar (sf
, 1);
7274 /* Motif needs this. See comment in xmenu.c. Turn it off when
7275 pending_menu_activation is not defined. */
7276 #ifdef USE_X_TOOLKIT
7277 pending_menu_activation
= 0;
7282 /* Update the menu bar item list for frame F. This has to be done
7283 before we start to fill in any display lines, because it can call
7286 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7289 update_menu_bar (f
, save_match_data
)
7291 int save_match_data
;
7294 register struct window
*w
;
7296 /* If called recursively during a menu update, do nothing. This can
7297 happen when, for instance, an activate-menubar-hook causes a
7299 if (inhibit_menubar_update
)
7302 window
= FRAME_SELECTED_WINDOW (f
);
7303 w
= XWINDOW (window
);
7305 if (update_mode_lines
)
7306 w
->update_mode_line
= Qt
;
7308 if (FRAME_WINDOW_P (f
)
7310 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7311 FRAME_EXTERNAL_MENU_BAR (f
)
7313 FRAME_MENU_BAR_LINES (f
) > 0
7315 : FRAME_MENU_BAR_LINES (f
) > 0)
7317 /* If the user has switched buffers or windows, we need to
7318 recompute to reflect the new bindings. But we'll
7319 recompute when update_mode_lines is set too; that means
7320 that people can use force-mode-line-update to request
7321 that the menu bar be recomputed. The adverse effect on
7322 the rest of the redisplay algorithm is about the same as
7323 windows_or_buffers_changed anyway. */
7324 if (windows_or_buffers_changed
7325 || !NILP (w
->update_mode_line
)
7326 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7327 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7328 != !NILP (w
->last_had_star
))
7329 || ((!NILP (Vtransient_mark_mode
)
7330 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7331 != !NILP (w
->region_showing
)))
7333 struct buffer
*prev
= current_buffer
;
7334 int count
= BINDING_STACK_SIZE ();
7336 specbind (Qinhibit_menubar_update
, Qt
);
7338 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7339 if (save_match_data
)
7340 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7341 if (NILP (Voverriding_local_map_menu_flag
))
7343 specbind (Qoverriding_terminal_local_map
, Qnil
);
7344 specbind (Qoverriding_local_map
, Qnil
);
7347 /* Run the Lucid hook. */
7348 safe_run_hooks (Qactivate_menubar_hook
);
7350 /* If it has changed current-menubar from previous value,
7351 really recompute the menu-bar from the value. */
7352 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7353 call0 (Qrecompute_lucid_menubar
);
7355 safe_run_hooks (Qmenu_bar_update_hook
);
7356 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7358 /* Redisplay the menu bar in case we changed it. */
7359 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7360 if (FRAME_WINDOW_P (f
)
7361 #if defined (macintosh)
7362 /* All frames on Mac OS share the same menubar. So only the
7363 selected frame should be allowed to set it. */
7364 && f
== SELECTED_FRAME ()
7367 set_frame_menubar (f
, 0, 0);
7369 /* On a terminal screen, the menu bar is an ordinary screen
7370 line, and this makes it get updated. */
7371 w
->update_mode_line
= Qt
;
7372 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7373 /* In the non-toolkit version, the menu bar is an ordinary screen
7374 line, and this makes it get updated. */
7375 w
->update_mode_line
= Qt
;
7376 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7378 unbind_to (count
, Qnil
);
7379 set_buffer_internal_1 (prev
);
7386 /***********************************************************************
7388 ***********************************************************************/
7390 #ifdef HAVE_WINDOW_SYSTEM
7392 /* Update the tool-bar item list for frame F. This has to be done
7393 before we start to fill in any display lines. Called from
7394 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7395 and restore it here. */
7398 update_tool_bar (f
, save_match_data
)
7400 int save_match_data
;
7402 if (WINDOWP (f
->tool_bar_window
)
7403 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7408 window
= FRAME_SELECTED_WINDOW (f
);
7409 w
= XWINDOW (window
);
7411 /* If the user has switched buffers or windows, we need to
7412 recompute to reflect the new bindings. But we'll
7413 recompute when update_mode_lines is set too; that means
7414 that people can use force-mode-line-update to request
7415 that the menu bar be recomputed. The adverse effect on
7416 the rest of the redisplay algorithm is about the same as
7417 windows_or_buffers_changed anyway. */
7418 if (windows_or_buffers_changed
7419 || !NILP (w
->update_mode_line
)
7420 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7421 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7422 != !NILP (w
->last_had_star
))
7423 || ((!NILP (Vtransient_mark_mode
)
7424 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7425 != !NILP (w
->region_showing
)))
7427 struct buffer
*prev
= current_buffer
;
7428 int count
= BINDING_STACK_SIZE ();
7430 /* Set current_buffer to the buffer of the selected
7431 window of the frame, so that we get the right local
7433 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7435 /* Save match data, if we must. */
7436 if (save_match_data
)
7437 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7439 /* Make sure that we don't accidentally use bogus keymaps. */
7440 if (NILP (Voverriding_local_map_menu_flag
))
7442 specbind (Qoverriding_terminal_local_map
, Qnil
);
7443 specbind (Qoverriding_local_map
, Qnil
);
7446 /* Build desired tool-bar items from keymaps. */
7448 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7450 /* Redisplay the tool-bar in case we changed it. */
7451 w
->update_mode_line
= Qt
;
7453 unbind_to (count
, Qnil
);
7454 set_buffer_internal_1 (prev
);
7460 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7461 F's desired tool-bar contents. F->tool_bar_items must have
7462 been set up previously by calling prepare_menu_bars. */
7465 build_desired_tool_bar_string (f
)
7468 int i
, size
, size_needed
;
7469 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7470 Lisp_Object image
, plist
, props
;
7472 image
= plist
= props
= Qnil
;
7473 GCPRO3 (image
, plist
, props
);
7475 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7476 Otherwise, make a new string. */
7478 /* The size of the string we might be able to reuse. */
7479 size
= (STRINGP (f
->desired_tool_bar_string
)
7480 ? XSTRING (f
->desired_tool_bar_string
)->size
7483 /* We need one space in the string for each image. */
7484 size_needed
= f
->n_tool_bar_items
;
7486 /* Reuse f->desired_tool_bar_string, if possible. */
7487 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7488 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7492 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7493 Fremove_text_properties (make_number (0), make_number (size
),
7494 props
, f
->desired_tool_bar_string
);
7497 /* Put a `display' property on the string for the images to display,
7498 put a `menu_item' property on tool-bar items with a value that
7499 is the index of the item in F's tool-bar item vector. */
7500 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7502 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7504 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7505 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7506 int hmargin
, vmargin
, relief
, idx
, end
;
7507 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7508 extern Lisp_Object Qlaplace
;
7510 /* If image is a vector, choose the image according to the
7512 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7513 if (VECTORP (image
))
7517 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7518 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7521 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7522 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7524 xassert (ASIZE (image
) >= idx
);
7525 image
= AREF (image
, idx
);
7530 /* Ignore invalid image specifications. */
7531 if (!valid_image_p (image
))
7534 /* Display the tool-bar button pressed, or depressed. */
7535 plist
= Fcopy_sequence (XCDR (image
));
7537 /* Compute margin and relief to draw. */
7538 relief
= (tool_bar_button_relief
> 0
7539 ? tool_bar_button_relief
7540 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7541 hmargin
= vmargin
= relief
;
7543 if (INTEGERP (Vtool_bar_button_margin
)
7544 && XINT (Vtool_bar_button_margin
) > 0)
7546 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7547 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7549 else if (CONSP (Vtool_bar_button_margin
))
7551 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7552 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7553 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7555 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7556 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7557 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7560 if (auto_raise_tool_bar_buttons_p
)
7562 /* Add a `:relief' property to the image spec if the item is
7566 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7573 /* If image is selected, display it pressed, i.e. with a
7574 negative relief. If it's not selected, display it with a
7576 plist
= Fplist_put (plist
, QCrelief
,
7578 ? make_number (-relief
)
7579 : make_number (relief
)));
7584 /* Put a margin around the image. */
7585 if (hmargin
|| vmargin
)
7587 if (hmargin
== vmargin
)
7588 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7590 plist
= Fplist_put (plist
, QCmargin
,
7591 Fcons (make_number (hmargin
),
7592 make_number (vmargin
)));
7595 /* If button is not enabled, and we don't have special images
7596 for the disabled state, make the image appear disabled by
7597 applying an appropriate algorithm to it. */
7598 if (!enabled_p
&& idx
< 0)
7599 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7601 /* Put a `display' text property on the string for the image to
7602 display. Put a `menu-item' property on the string that gives
7603 the start of this item's properties in the tool-bar items
7605 image
= Fcons (Qimage
, plist
);
7606 props
= list4 (Qdisplay
, image
,
7607 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7609 /* Let the last image hide all remaining spaces in the tool bar
7610 string. The string can be longer than needed when we reuse a
7612 if (i
+ 1 == f
->n_tool_bar_items
)
7613 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7616 Fadd_text_properties (make_number (i
), make_number (end
),
7617 props
, f
->desired_tool_bar_string
);
7625 /* Display one line of the tool-bar of frame IT->f. */
7628 display_tool_bar_line (it
)
7631 struct glyph_row
*row
= it
->glyph_row
;
7632 int max_x
= it
->last_visible_x
;
7635 prepare_desired_row (row
);
7636 row
->y
= it
->current_y
;
7638 /* Note that this isn't made use of if the face hasn't a box,
7639 so there's no need to check the face here. */
7640 it
->start_of_box_run_p
= 1;
7642 while (it
->current_x
< max_x
)
7644 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7646 /* Get the next display element. */
7647 if (!get_next_display_element (it
))
7650 /* Produce glyphs. */
7651 x_before
= it
->current_x
;
7652 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7653 PRODUCE_GLYPHS (it
);
7655 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7660 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7662 if (x
+ glyph
->pixel_width
> max_x
)
7664 /* Glyph doesn't fit on line. */
7665 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7671 x
+= glyph
->pixel_width
;
7675 /* Stop at line ends. */
7676 if (ITERATOR_AT_END_OF_LINE_P (it
))
7679 set_iterator_to_next (it
, 1);
7684 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7685 extend_face_to_end_of_line (it
);
7686 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7687 last
->right_box_line_p
= 1;
7688 if (last
== row
->glyphs
[TEXT_AREA
])
7689 last
->left_box_line_p
= 1;
7690 compute_line_metrics (it
);
7692 /* If line is empty, make it occupy the rest of the tool-bar. */
7693 if (!row
->displays_text_p
)
7695 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7696 row
->ascent
= row
->phys_ascent
= 0;
7699 row
->full_width_p
= 1;
7700 row
->continued_p
= 0;
7701 row
->truncated_on_left_p
= 0;
7702 row
->truncated_on_right_p
= 0;
7704 it
->current_x
= it
->hpos
= 0;
7705 it
->current_y
+= row
->height
;
7711 /* Value is the number of screen lines needed to make all tool-bar
7712 items of frame F visible. */
7715 tool_bar_lines_needed (f
)
7718 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7721 /* Initialize an iterator for iteration over
7722 F->desired_tool_bar_string in the tool-bar window of frame F. */
7723 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7724 it
.first_visible_x
= 0;
7725 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7726 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7728 while (!ITERATOR_AT_END_P (&it
))
7730 it
.glyph_row
= w
->desired_matrix
->rows
;
7731 clear_glyph_row (it
.glyph_row
);
7732 display_tool_bar_line (&it
);
7735 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7739 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7741 "Return the number of lines occupied by the tool bar of FRAME.")
7750 frame
= selected_frame
;
7752 CHECK_FRAME (frame
, 0);
7755 if (WINDOWP (f
->tool_bar_window
)
7756 || (w
= XWINDOW (f
->tool_bar_window
),
7757 XFASTINT (w
->height
) > 0))
7759 update_tool_bar (f
, 1);
7760 if (f
->n_tool_bar_items
)
7762 build_desired_tool_bar_string (f
);
7763 nlines
= tool_bar_lines_needed (f
);
7767 return make_number (nlines
);
7771 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7772 height should be changed. */
7775 redisplay_tool_bar (f
)
7780 struct glyph_row
*row
;
7781 int change_height_p
= 0;
7783 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7784 do anything. This means you must start with tool-bar-lines
7785 non-zero to get the auto-sizing effect. Or in other words, you
7786 can turn off tool-bars by specifying tool-bar-lines zero. */
7787 if (!WINDOWP (f
->tool_bar_window
)
7788 || (w
= XWINDOW (f
->tool_bar_window
),
7789 XFASTINT (w
->height
) == 0))
7792 /* Set up an iterator for the tool-bar window. */
7793 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7794 it
.first_visible_x
= 0;
7795 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7798 /* Build a string that represents the contents of the tool-bar. */
7799 build_desired_tool_bar_string (f
);
7800 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7802 /* Display as many lines as needed to display all tool-bar items. */
7803 while (it
.current_y
< it
.last_visible_y
)
7804 display_tool_bar_line (&it
);
7806 /* It doesn't make much sense to try scrolling in the tool-bar
7807 window, so don't do it. */
7808 w
->desired_matrix
->no_scrolling_p
= 1;
7809 w
->must_be_updated_p
= 1;
7811 if (auto_resize_tool_bars_p
)
7815 /* If we couldn't display everything, change the tool-bar's
7817 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7818 change_height_p
= 1;
7820 /* If there are blank lines at the end, except for a partially
7821 visible blank line at the end that is smaller than
7822 CANON_Y_UNIT, change the tool-bar's height. */
7823 row
= it
.glyph_row
- 1;
7824 if (!row
->displays_text_p
7825 && row
->height
>= CANON_Y_UNIT (f
))
7826 change_height_p
= 1;
7828 /* If row displays tool-bar items, but is partially visible,
7829 change the tool-bar's height. */
7830 if (row
->displays_text_p
7831 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7832 change_height_p
= 1;
7834 /* Resize windows as needed by changing the `tool-bar-lines'
7837 && (nlines
= tool_bar_lines_needed (f
),
7838 nlines
!= XFASTINT (w
->height
)))
7840 extern Lisp_Object Qtool_bar_lines
;
7842 int old_height
= XFASTINT (w
->height
);
7844 XSETFRAME (frame
, f
);
7845 clear_glyph_matrix (w
->desired_matrix
);
7846 Fmodify_frame_parameters (frame
,
7847 Fcons (Fcons (Qtool_bar_lines
,
7848 make_number (nlines
)),
7850 if (XFASTINT (w
->height
) != old_height
)
7851 fonts_changed_p
= 1;
7855 return change_height_p
;
7859 /* Get information about the tool-bar item which is displayed in GLYPH
7860 on frame F. Return in *PROP_IDX the index where tool-bar item
7861 properties start in F->tool_bar_items. Value is zero if
7862 GLYPH doesn't display a tool-bar item. */
7865 tool_bar_item_info (f
, glyph
, prop_idx
)
7867 struct glyph
*glyph
;
7873 /* Get the text property `menu-item' at pos. The value of that
7874 property is the start index of this item's properties in
7875 F->tool_bar_items. */
7876 prop
= Fget_text_property (make_number (glyph
->charpos
),
7877 Qmenu_item
, f
->current_tool_bar_string
);
7878 if (INTEGERP (prop
))
7880 *prop_idx
= XINT (prop
);
7889 #endif /* HAVE_WINDOW_SYSTEM */
7893 /************************************************************************
7894 Horizontal scrolling
7895 ************************************************************************/
7897 static int hscroll_window_tree
P_ ((Lisp_Object
));
7898 static int hscroll_windows
P_ ((Lisp_Object
));
7900 /* For all leaf windows in the window tree rooted at WINDOW, set their
7901 hscroll value so that PT is (i) visible in the window, and (ii) so
7902 that it is not within a certain margin at the window's left and
7903 right border. Value is non-zero if any window's hscroll has been
7907 hscroll_window_tree (window
)
7910 int hscrolled_p
= 0;
7912 while (WINDOWP (window
))
7914 struct window
*w
= XWINDOW (window
);
7916 if (WINDOWP (w
->hchild
))
7917 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7918 else if (WINDOWP (w
->vchild
))
7919 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7920 else if (w
->cursor
.vpos
>= 0)
7922 int hscroll_margin
, text_area_x
, text_area_y
;
7923 int text_area_width
, text_area_height
;
7924 struct glyph_row
*current_cursor_row
7925 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7926 struct glyph_row
*desired_cursor_row
7927 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7928 struct glyph_row
*cursor_row
7929 = (desired_cursor_row
->enabled_p
7930 ? desired_cursor_row
7931 : current_cursor_row
);
7933 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7934 &text_area_width
, &text_area_height
);
7936 /* Scroll when cursor is inside this scroll margin. */
7937 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7939 if ((XFASTINT (w
->hscroll
)
7940 && w
->cursor
.x
< hscroll_margin
)
7941 || (cursor_row
->enabled_p
7942 && cursor_row
->truncated_on_right_p
7943 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7947 struct buffer
*saved_current_buffer
;
7950 /* Find point in a display of infinite width. */
7951 saved_current_buffer
= current_buffer
;
7952 current_buffer
= XBUFFER (w
->buffer
);
7954 if (w
== XWINDOW (selected_window
))
7955 pt
= BUF_PT (current_buffer
);
7958 pt
= marker_position (w
->pointm
);
7959 pt
= max (BEGV
, pt
);
7963 /* Move iterator to pt starting at cursor_row->start in
7964 a line with infinite width. */
7965 init_to_row_start (&it
, w
, cursor_row
);
7966 it
.last_visible_x
= INFINITY
;
7967 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7968 current_buffer
= saved_current_buffer
;
7970 /* Center cursor in window. */
7971 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7972 / CANON_X_UNIT (it
.f
));
7973 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
7975 /* Don't call Fset_window_hscroll if value hasn't
7976 changed because it will prevent redisplay
7978 if (XFASTINT (w
->hscroll
) != hscroll
)
7980 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
7981 w
->hscroll
= make_number (hscroll
);
7990 /* Value is non-zero if hscroll of any leaf window has been changed. */
7995 /* Set hscroll so that cursor is visible and not inside horizontal
7996 scroll margins for all windows in the tree rooted at WINDOW. See
7997 also hscroll_window_tree above. Value is non-zero if any window's
7998 hscroll has been changed. If it has, desired matrices on the frame
7999 of WINDOW are cleared. */
8002 hscroll_windows (window
)
8007 if (automatic_hscrolling_p
)
8009 hscrolled_p
= hscroll_window_tree (window
);
8011 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8020 /************************************************************************
8022 ************************************************************************/
8024 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8025 to a non-zero value. This is sometimes handy to have in a debugger
8030 /* First and last unchanged row for try_window_id. */
8032 int debug_first_unchanged_at_end_vpos
;
8033 int debug_last_unchanged_at_beg_vpos
;
8035 /* Delta vpos and y. */
8037 int debug_dvpos
, debug_dy
;
8039 /* Delta in characters and bytes for try_window_id. */
8041 int debug_delta
, debug_delta_bytes
;
8043 /* Values of window_end_pos and window_end_vpos at the end of
8046 int debug_end_pos
, debug_end_vpos
;
8048 /* Append a string to W->desired_matrix->method. FMT is a printf
8049 format string. A1...A9 are a supplement for a variable-length
8050 argument list. If trace_redisplay_p is non-zero also printf the
8051 resulting string to stderr. */
8054 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8057 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8060 char *method
= w
->desired_matrix
->method
;
8061 int len
= strlen (method
);
8062 int size
= sizeof w
->desired_matrix
->method
;
8063 int remaining
= size
- len
- 1;
8065 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8066 if (len
&& remaining
)
8072 strncpy (method
+ len
, buffer
, remaining
);
8074 if (trace_redisplay_p
)
8075 fprintf (stderr
, "%p (%s): %s\n",
8077 ((BUFFERP (w
->buffer
)
8078 && STRINGP (XBUFFER (w
->buffer
)->name
))
8079 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8084 #endif /* GLYPH_DEBUG */
8087 /* This counter is used to clear the face cache every once in a while
8088 in redisplay_internal. It is incremented for each redisplay.
8089 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8092 #define CLEAR_FACE_CACHE_COUNT 10000
8093 static int clear_face_cache_count
;
8095 /* Record the previous terminal frame we displayed. */
8097 static struct frame
*previous_terminal_frame
;
8099 /* Non-zero while redisplay_internal is in progress. */
8104 /* Value is non-zero if all changes in window W, which displays
8105 current_buffer, are in the text between START and END. START is a
8106 buffer position, END is given as a distance from Z. Used in
8107 redisplay_internal for display optimization. */
8110 text_outside_line_unchanged_p (w
, start
, end
)
8114 int unchanged_p
= 1;
8116 /* If text or overlays have changed, see where. */
8117 if (XFASTINT (w
->last_modified
) < MODIFF
8118 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8120 /* Gap in the line? */
8121 if (GPT
< start
|| Z
- GPT
< end
)
8124 /* Changes start in front of the line, or end after it? */
8126 && (BEG_UNCHANGED
< start
- 1
8127 || END_UNCHANGED
< end
))
8130 /* If selective display, can't optimize if changes start at the
8131 beginning of the line. */
8133 && INTEGERP (current_buffer
->selective_display
)
8134 && XINT (current_buffer
->selective_display
) > 0
8135 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8143 /* Do a frame update, taking possible shortcuts into account. This is
8144 the main external entry point for redisplay.
8146 If the last redisplay displayed an echo area message and that message
8147 is no longer requested, we clear the echo area or bring back the
8148 mini-buffer if that is in use. */
8153 redisplay_internal (0);
8156 /* Return 1 if point moved out of or into a composition. Otherwise
8157 return 0. PREV_BUF and PREV_PT are the last point buffer and
8158 position. BUF and PT are the current point buffer and position. */
8161 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8162 struct buffer
*prev_buf
, *buf
;
8169 XSETBUFFER (buffer
, buf
);
8170 /* Check a composition at the last point if point moved within the
8172 if (prev_buf
== buf
)
8175 /* Point didn't move. */
8178 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8179 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8180 && COMPOSITION_VALID_P (start
, end
, prop
)
8181 && start
< prev_pt
&& end
> prev_pt
)
8182 /* The last point was within the composition. Return 1 iff
8183 point moved out of the composition. */
8184 return (pt
<= start
|| pt
>= end
);
8187 /* Check a composition at the current point. */
8188 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8189 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8190 && COMPOSITION_VALID_P (start
, end
, prop
)
8191 && start
< pt
&& end
> pt
);
8194 /* Reconsider the setting of B->clip_changed which is displayed
8198 reconsider_clip_changes (w
, b
)
8202 if (b
->prevent_redisplay_optimizations_p
)
8203 b
->clip_changed
= 1;
8204 else if (b
->clip_changed
8205 && !NILP (w
->window_end_valid
)
8206 && w
->current_matrix
->buffer
== b
8207 && w
->current_matrix
->zv
== BUF_ZV (b
)
8208 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8209 b
->clip_changed
= 0;
8211 /* If display wasn't paused, and W is not a tool bar window, see if
8212 point has been moved into or out of a composition. In that case,
8213 we set b->clip_changed to 1 to force updating the screen. If
8214 b->clip_changed has already been set to 1, we can skip this
8216 if (!b
->clip_changed
8217 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8221 if (w
== XWINDOW (selected_window
))
8222 pt
= BUF_PT (current_buffer
);
8224 pt
= marker_position (w
->pointm
);
8226 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8227 || pt
!= XINT (w
->last_point
))
8228 && check_point_in_composition (w
->current_matrix
->buffer
,
8229 XINT (w
->last_point
),
8230 XBUFFER (w
->buffer
), pt
))
8231 b
->clip_changed
= 1;
8236 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8237 response to any user action; therefore, we should preserve the echo
8238 area. (Actually, our caller does that job.) Perhaps in the future
8239 avoid recentering windows if it is not necessary; currently that
8240 causes some problems. */
8243 redisplay_internal (preserve_echo_area
)
8244 int preserve_echo_area
;
8246 struct window
*w
= XWINDOW (selected_window
);
8247 struct frame
*f
= XFRAME (w
->frame
);
8249 int must_finish
= 0;
8250 struct text_pos tlbufpos
, tlendpos
;
8251 int number_of_visible_frames
;
8253 struct frame
*sf
= SELECTED_FRAME ();
8255 /* Non-zero means redisplay has to consider all windows on all
8256 frames. Zero means, only selected_window is considered. */
8257 int consider_all_windows_p
;
8259 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8261 /* No redisplay if running in batch mode or frame is not yet fully
8262 initialized, or redisplay is explicitly turned off by setting
8263 Vinhibit_redisplay. */
8265 || !NILP (Vinhibit_redisplay
)
8266 || !f
->glyphs_initialized_p
)
8269 /* The flag redisplay_performed_directly_p is set by
8270 direct_output_for_insert when it already did the whole screen
8271 update necessary. */
8272 if (redisplay_performed_directly_p
)
8274 redisplay_performed_directly_p
= 0;
8275 if (!hscroll_windows (selected_window
))
8279 #ifdef USE_X_TOOLKIT
8280 if (popup_activated ())
8284 /* I don't think this happens but let's be paranoid. */
8288 /* Record a function that resets redisplaying_p to its old value
8289 when we leave this function. */
8290 count
= BINDING_STACK_SIZE ();
8291 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8296 reconsider_clip_changes (w
, current_buffer
);
8298 /* If new fonts have been loaded that make a glyph matrix adjustment
8299 necessary, do it. */
8300 if (fonts_changed_p
)
8302 adjust_glyphs (NULL
);
8303 ++windows_or_buffers_changed
;
8304 fonts_changed_p
= 0;
8307 /* If face_change_count is non-zero, init_iterator will free all
8308 realized faces, which includes the faces referenced from current
8309 matrices. So, we can't reuse current matrices in this case. */
8310 if (face_change_count
)
8311 ++windows_or_buffers_changed
;
8313 if (! FRAME_WINDOW_P (sf
)
8314 && previous_terminal_frame
!= sf
)
8316 /* Since frames on an ASCII terminal share the same display
8317 area, displaying a different frame means redisplay the whole
8319 windows_or_buffers_changed
++;
8320 SET_FRAME_GARBAGED (sf
);
8321 XSETFRAME (Vterminal_frame
, sf
);
8323 previous_terminal_frame
= sf
;
8325 /* Set the visible flags for all frames. Do this before checking
8326 for resized or garbaged frames; they want to know if their frames
8327 are visible. See the comment in frame.h for
8328 FRAME_SAMPLE_VISIBILITY. */
8330 Lisp_Object tail
, frame
;
8332 number_of_visible_frames
= 0;
8334 FOR_EACH_FRAME (tail
, frame
)
8336 struct frame
*f
= XFRAME (frame
);
8338 FRAME_SAMPLE_VISIBILITY (f
);
8339 if (FRAME_VISIBLE_P (f
))
8340 ++number_of_visible_frames
;
8341 clear_desired_matrices (f
);
8345 /* Notice any pending interrupt request to change frame size. */
8346 do_pending_window_change (1);
8348 /* Clear frames marked as garbaged. */
8350 clear_garbaged_frames ();
8352 /* Build menubar and tool-bar items. */
8353 prepare_menu_bars ();
8355 if (windows_or_buffers_changed
)
8356 update_mode_lines
++;
8358 /* Detect case that we need to write or remove a star in the mode line. */
8359 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8361 w
->update_mode_line
= Qt
;
8362 if (buffer_shared
> 1)
8363 update_mode_lines
++;
8366 /* If %c is in the mode line, update it if needed. */
8367 if (!NILP (w
->column_number_displayed
)
8368 /* This alternative quickly identifies a common case
8369 where no change is needed. */
8370 && !(PT
== XFASTINT (w
->last_point
)
8371 && XFASTINT (w
->last_modified
) >= MODIFF
8372 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8373 && XFASTINT (w
->column_number_displayed
) != current_column ())
8374 w
->update_mode_line
= Qt
;
8376 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8378 /* The variable buffer_shared is set in redisplay_window and
8379 indicates that we redisplay a buffer in different windows. See
8381 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8383 /* If specs for an arrow have changed, do thorough redisplay
8384 to ensure we remove any arrow that should no longer exist. */
8385 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8386 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8387 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8389 /* Normally the message* functions will have already displayed and
8390 updated the echo area, but the frame may have been trashed, or
8391 the update may have been preempted, so display the echo area
8392 again here. Checking both message buffers captures the case that
8393 the echo area should be cleared. */
8394 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
8396 int window_height_changed_p
= echo_area_display (0);
8399 if (fonts_changed_p
)
8401 else if (window_height_changed_p
)
8403 consider_all_windows_p
= 1;
8404 ++update_mode_lines
;
8405 ++windows_or_buffers_changed
;
8407 /* If window configuration was changed, frames may have been
8408 marked garbaged. Clear them or we will experience
8409 surprises wrt scrolling. */
8411 clear_garbaged_frames ();
8414 else if (EQ (selected_window
, minibuf_window
)
8415 && (current_buffer
->clip_changed
8416 || XFASTINT (w
->last_modified
) < MODIFF
8417 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8418 && resize_mini_window (w
, 0))
8420 /* Resized active mini-window to fit the size of what it is
8421 showing if its contents might have changed. */
8423 consider_all_windows_p
= 1;
8424 ++windows_or_buffers_changed
;
8425 ++update_mode_lines
;
8427 /* If window configuration was changed, frames may have been
8428 marked garbaged. Clear them or we will experience
8429 surprises wrt scrolling. */
8431 clear_garbaged_frames ();
8435 /* If showing the region, and mark has changed, we must redisplay
8436 the whole window. The assignment to this_line_start_pos prevents
8437 the optimization directly below this if-statement. */
8438 if (((!NILP (Vtransient_mark_mode
)
8439 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8440 != !NILP (w
->region_showing
))
8441 || (!NILP (w
->region_showing
)
8442 && !EQ (w
->region_showing
,
8443 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8444 CHARPOS (this_line_start_pos
) = 0;
8446 /* Optimize the case that only the line containing the cursor in the
8447 selected window has changed. Variables starting with this_ are
8448 set in display_line and record information about the line
8449 containing the cursor. */
8450 tlbufpos
= this_line_start_pos
;
8451 tlendpos
= this_line_end_pos
;
8452 if (!consider_all_windows_p
8453 && CHARPOS (tlbufpos
) > 0
8454 && NILP (w
->update_mode_line
)
8455 && !current_buffer
->clip_changed
8456 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8457 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8458 /* Make sure recorded data applies to current buffer, etc. */
8459 && this_line_buffer
== current_buffer
8460 && current_buffer
== XBUFFER (w
->buffer
)
8461 && NILP (w
->force_start
)
8462 /* Point must be on the line that we have info recorded about. */
8463 && PT
>= CHARPOS (tlbufpos
)
8464 && PT
<= Z
- CHARPOS (tlendpos
)
8465 /* All text outside that line, including its final newline,
8466 must be unchanged */
8467 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8468 CHARPOS (tlendpos
)))
8470 if (CHARPOS (tlbufpos
) > BEGV
8471 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8472 && (CHARPOS (tlbufpos
) == ZV
8473 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8474 /* Former continuation line has disappeared by becoming empty */
8476 else if (XFASTINT (w
->last_modified
) < MODIFF
8477 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8478 || MINI_WINDOW_P (w
))
8480 /* We have to handle the case of continuation around a
8481 wide-column character (See the comment in indent.c around
8484 For instance, in the following case:
8486 -------- Insert --------
8487 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8488 J_I_ ==> J_I_ `^^' are cursors.
8492 As we have to redraw the line above, we should goto cancel. */
8495 int line_height_before
= this_line_pixel_height
;
8497 /* Note that start_display will handle the case that the
8498 line starting at tlbufpos is a continuation lines. */
8499 start_display (&it
, w
, tlbufpos
);
8501 /* Implementation note: It this still necessary? */
8502 if (it
.current_x
!= this_line_start_x
)
8505 TRACE ((stderr
, "trying display optimization 1\n"));
8506 w
->cursor
.vpos
= -1;
8507 overlay_arrow_seen
= 0;
8508 it
.vpos
= this_line_vpos
;
8509 it
.current_y
= this_line_y
;
8510 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8513 /* If line contains point, is not continued,
8514 and ends at same distance from eob as before, we win */
8515 if (w
->cursor
.vpos
>= 0
8516 /* Line is not continued, otherwise this_line_start_pos
8517 would have been set to 0 in display_line. */
8518 && CHARPOS (this_line_start_pos
)
8519 /* Line ends as before. */
8520 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8521 /* Line has same height as before. Otherwise other lines
8522 would have to be shifted up or down. */
8523 && this_line_pixel_height
== line_height_before
)
8525 /* If this is not the window's last line, we must adjust
8526 the charstarts of the lines below. */
8527 if (it
.current_y
< it
.last_visible_y
)
8529 struct glyph_row
*row
8530 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8531 int delta
, delta_bytes
;
8533 if (Z
- CHARPOS (tlendpos
) == ZV
)
8535 /* This line ends at end of (accessible part of)
8536 buffer. There is no newline to count. */
8538 - CHARPOS (tlendpos
)
8539 - MATRIX_ROW_START_CHARPOS (row
));
8540 delta_bytes
= (Z_BYTE
8541 - BYTEPOS (tlendpos
)
8542 - MATRIX_ROW_START_BYTEPOS (row
));
8546 /* This line ends in a newline. Must take
8547 account of the newline and the rest of the
8548 text that follows. */
8550 - CHARPOS (tlendpos
)
8551 - MATRIX_ROW_START_CHARPOS (row
));
8552 delta_bytes
= (Z_BYTE
8553 - BYTEPOS (tlendpos
)
8554 - MATRIX_ROW_START_BYTEPOS (row
));
8557 increment_matrix_positions (w
->current_matrix
,
8559 w
->current_matrix
->nrows
,
8560 delta
, delta_bytes
);
8563 /* If this row displays text now but previously didn't,
8564 or vice versa, w->window_end_vpos may have to be
8566 if ((it
.glyph_row
- 1)->displays_text_p
)
8568 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8569 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8571 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8572 && this_line_vpos
> 0)
8573 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8574 w
->window_end_valid
= Qnil
;
8576 /* Update hint: No need to try to scroll in update_window. */
8577 w
->desired_matrix
->no_scrolling_p
= 1;
8580 *w
->desired_matrix
->method
= 0;
8581 debug_method_add (w
, "optimization 1");
8588 else if (/* Cursor position hasn't changed. */
8589 PT
== XFASTINT (w
->last_point
)
8590 /* Make sure the cursor was last displayed
8591 in this window. Otherwise we have to reposition it. */
8592 && 0 <= w
->cursor
.vpos
8593 && XINT (w
->height
) > w
->cursor
.vpos
)
8597 do_pending_window_change (1);
8599 /* We used to always goto end_of_redisplay here, but this
8600 isn't enough if we have a blinking cursor. */
8601 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8602 goto end_of_redisplay
;
8606 /* If highlighting the region, or if the cursor is in the echo area,
8607 then we can't just move the cursor. */
8608 else if (! (!NILP (Vtransient_mark_mode
)
8609 && !NILP (current_buffer
->mark_active
))
8610 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8611 || highlight_nonselected_windows
)
8612 && NILP (w
->region_showing
)
8613 && NILP (Vshow_trailing_whitespace
)
8614 && !cursor_in_echo_area
)
8617 struct glyph_row
*row
;
8619 /* Skip from tlbufpos to PT and see where it is. Note that
8620 PT may be in invisible text. If so, we will end at the
8621 next visible position. */
8622 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8623 NULL
, DEFAULT_FACE_ID
);
8624 it
.current_x
= this_line_start_x
;
8625 it
.current_y
= this_line_y
;
8626 it
.vpos
= this_line_vpos
;
8628 /* The call to move_it_to stops in front of PT, but
8629 moves over before-strings. */
8630 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8632 if (it
.vpos
== this_line_vpos
8633 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8636 xassert (this_line_vpos
== it
.vpos
);
8637 xassert (this_line_y
== it
.current_y
);
8638 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8640 *w
->desired_matrix
->method
= 0;
8641 debug_method_add (w
, "optimization 3");
8650 /* Text changed drastically or point moved off of line. */
8651 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8654 CHARPOS (this_line_start_pos
) = 0;
8655 consider_all_windows_p
|= buffer_shared
> 1;
8656 ++clear_face_cache_count
;
8659 /* Build desired matrices, and update the display. If
8660 consider_all_windows_p is non-zero, do it for all windows on all
8661 frames. Otherwise do it for selected_window, only. */
8663 if (consider_all_windows_p
)
8665 Lisp_Object tail
, frame
;
8666 int i
, n
= 0, size
= 50;
8667 struct frame
**updated
8668 = (struct frame
**) alloca (size
* sizeof *updated
);
8670 /* Clear the face cache eventually. */
8671 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8673 clear_face_cache (0);
8674 clear_face_cache_count
= 0;
8677 /* Recompute # windows showing selected buffer. This will be
8678 incremented each time such a window is displayed. */
8681 FOR_EACH_FRAME (tail
, frame
)
8683 struct frame
*f
= XFRAME (frame
);
8685 if (FRAME_WINDOW_P (f
) || f
== sf
)
8687 /* Mark all the scroll bars to be removed; we'll redeem
8688 the ones we want when we redisplay their windows. */
8689 if (condemn_scroll_bars_hook
)
8690 condemn_scroll_bars_hook (f
);
8692 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8693 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8695 /* Any scroll bars which redisplay_windows should have
8696 nuked should now go away. */
8697 if (judge_scroll_bars_hook
)
8698 judge_scroll_bars_hook (f
);
8700 /* If fonts changed, display again. */
8701 if (fonts_changed_p
)
8704 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8706 /* See if we have to hscroll. */
8707 if (hscroll_windows (f
->root_window
))
8710 /* Prevent various kinds of signals during display
8711 update. stdio is not robust about handling
8712 signals, which can cause an apparent I/O
8714 if (interrupt_input
)
8718 /* Update the display. */
8719 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8720 pause
|= update_frame (f
, 0, 0);
8726 int nbytes
= size
* sizeof *updated
;
8727 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8728 bcopy (updated
, p
, nbytes
);
8737 /* Do the mark_window_display_accurate after all windows have
8738 been redisplayed because this call resets flags in buffers
8739 which are needed for proper redisplay. */
8740 for (i
= 0; i
< n
; ++i
)
8742 struct frame
*f
= updated
[i
];
8743 mark_window_display_accurate (f
->root_window
, 1);
8744 if (frame_up_to_date_hook
)
8745 frame_up_to_date_hook (f
);
8748 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8750 Lisp_Object mini_window
;
8751 struct frame
*mini_frame
;
8753 redisplay_window (selected_window
, 1);
8755 /* Compare desired and current matrices, perform output. */
8758 /* If fonts changed, display again. */
8759 if (fonts_changed_p
)
8762 /* Prevent various kinds of signals during display update.
8763 stdio is not robust about handling signals,
8764 which can cause an apparent I/O error. */
8765 if (interrupt_input
)
8769 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8771 if (hscroll_windows (selected_window
))
8774 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8775 pause
= update_frame (sf
, 0, 0);
8778 /* We may have called echo_area_display at the top of this
8779 function. If the echo area is on another frame, that may
8780 have put text on a frame other than the selected one, so the
8781 above call to update_frame would not have caught it. Catch
8783 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8784 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8786 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8788 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8789 pause
|= update_frame (mini_frame
, 0, 0);
8790 if (!pause
&& hscroll_windows (mini_window
))
8795 /* If display was paused because of pending input, make sure we do a
8796 thorough update the next time. */
8799 /* Prevent the optimization at the beginning of
8800 redisplay_internal that tries a single-line update of the
8801 line containing the cursor in the selected window. */
8802 CHARPOS (this_line_start_pos
) = 0;
8804 /* Let the overlay arrow be updated the next time. */
8805 if (!NILP (last_arrow_position
))
8807 last_arrow_position
= Qt
;
8808 last_arrow_string
= Qt
;
8811 /* If we pause after scrolling, some rows in the current
8812 matrices of some windows are not valid. */
8813 if (!WINDOW_FULL_WIDTH_P (w
)
8814 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8815 update_mode_lines
= 1;
8819 if (!consider_all_windows_p
)
8821 /* This has already been done above if
8822 consider_all_windows_p is set. */
8823 mark_window_display_accurate_1 (w
, 1);
8825 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8826 last_arrow_string
= Voverlay_arrow_string
;
8828 if (frame_up_to_date_hook
!= 0)
8829 frame_up_to_date_hook (sf
);
8832 update_mode_lines
= 0;
8833 windows_or_buffers_changed
= 0;
8836 /* Start SIGIO interrupts coming again. Having them off during the
8837 code above makes it less likely one will discard output, but not
8838 impossible, since there might be stuff in the system buffer here.
8839 But it is much hairier to try to do anything about that. */
8840 if (interrupt_input
)
8844 /* If a frame has become visible which was not before, redisplay
8845 again, so that we display it. Expose events for such a frame
8846 (which it gets when becoming visible) don't call the parts of
8847 redisplay constructing glyphs, so simply exposing a frame won't
8848 display anything in this case. So, we have to display these
8849 frames here explicitly. */
8852 Lisp_Object tail
, frame
;
8855 FOR_EACH_FRAME (tail
, frame
)
8857 int this_is_visible
= 0;
8859 if (XFRAME (frame
)->visible
)
8860 this_is_visible
= 1;
8861 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8862 if (XFRAME (frame
)->visible
)
8863 this_is_visible
= 1;
8865 if (this_is_visible
)
8869 if (new_count
!= number_of_visible_frames
)
8870 windows_or_buffers_changed
++;
8873 /* Change frame size now if a change is pending. */
8874 do_pending_window_change (1);
8876 /* If we just did a pending size change, or have additional
8877 visible frames, redisplay again. */
8878 if (windows_or_buffers_changed
&& !pause
)
8883 unbind_to (count
, Qnil
);
8887 /* Redisplay, but leave alone any recent echo area message unless
8888 another message has been requested in its place.
8890 This is useful in situations where you need to redisplay but no
8891 user action has occurred, making it inappropriate for the message
8892 area to be cleared. See tracking_off and
8893 wait_reading_process_input for examples of these situations.
8895 FROM_WHERE is an integer saying from where this function was
8896 called. This is useful for debugging. */
8899 redisplay_preserve_echo_area (from_where
)
8902 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
8904 if (!NILP (echo_area_buffer
[1]))
8906 /* We have a previously displayed message, but no current
8907 message. Redisplay the previous message. */
8908 display_last_displayed_message_p
= 1;
8909 redisplay_internal (1);
8910 display_last_displayed_message_p
= 0;
8913 redisplay_internal (1);
8917 /* Function registered with record_unwind_protect in
8918 redisplay_internal. Clears the flag indicating that a redisplay is
8922 unwind_redisplay (old_redisplaying_p
)
8923 Lisp_Object old_redisplaying_p
;
8925 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8930 /* Mark the display of window W as accurate or inaccurate. If
8931 ACCURATE_P is non-zero mark display of W as accurate. If
8932 ACCURATE_P is zero, arrange for W to be redisplayed the next time
8933 redisplay_internal is called. */
8936 mark_window_display_accurate_1 (w
, accurate_p
)
8940 if (BUFFERP (w
->buffer
))
8942 struct buffer
*b
= XBUFFER (w
->buffer
);
8945 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
8946 w
->last_overlay_modified
8947 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8949 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
8953 b
->clip_changed
= 0;
8954 b
->prevent_redisplay_optimizations_p
= 0;
8956 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8957 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8958 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8959 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8961 w
->current_matrix
->buffer
= b
;
8962 w
->current_matrix
->begv
= BUF_BEGV (b
);
8963 w
->current_matrix
->zv
= BUF_ZV (b
);
8965 w
->last_cursor
= w
->cursor
;
8966 w
->last_cursor_off_p
= w
->cursor_off_p
;
8968 if (w
== XWINDOW (selected_window
))
8969 w
->last_point
= make_number (BUF_PT (b
));
8971 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8977 w
->window_end_valid
= w
->buffer
;
8978 w
->update_mode_line
= Qnil
;
8983 /* Mark the display of windows in the window tree rooted at WINDOW as
8984 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
8985 windows as accurate. If ACCURATE_P is zero, arrange for windows to
8986 be redisplayed the next time redisplay_internal is called. */
8989 mark_window_display_accurate (window
, accurate_p
)
8995 for (; !NILP (window
); window
= w
->next
)
8997 w
= XWINDOW (window
);
8998 mark_window_display_accurate_1 (w
, accurate_p
);
9000 if (!NILP (w
->vchild
))
9001 mark_window_display_accurate (w
->vchild
, accurate_p
);
9002 if (!NILP (w
->hchild
))
9003 mark_window_display_accurate (w
->hchild
, accurate_p
);
9008 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9009 last_arrow_string
= Voverlay_arrow_string
;
9013 /* Force a thorough redisplay the next time by setting
9014 last_arrow_position and last_arrow_string to t, which is
9015 unequal to any useful value of Voverlay_arrow_... */
9016 last_arrow_position
= Qt
;
9017 last_arrow_string
= Qt
;
9022 /* Return value in display table DP (Lisp_Char_Table *) for character
9023 C. Since a display table doesn't have any parent, we don't have to
9024 follow parent. Do not call this function directly but use the
9025 macro DISP_CHAR_VECTOR. */
9028 disp_char_vector (dp
, c
)
9029 struct Lisp_Char_Table
*dp
;
9035 if (SINGLE_BYTE_CHAR_P (c
))
9036 return (dp
->contents
[c
]);
9038 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9041 else if (code
[2] < 32)
9044 /* Here, the possible range of code[0] (== charset ID) is
9045 128..max_charset. Since the top level char table contains data
9046 for multibyte characters after 256th element, we must increment
9047 code[0] by 128 to get a correct index. */
9049 code
[3] = -1; /* anchor */
9051 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9053 val
= dp
->contents
[code
[i
]];
9054 if (!SUB_CHAR_TABLE_P (val
))
9055 return (NILP (val
) ? dp
->defalt
: val
);
9058 /* Here, val is a sub char table. We return the default value of
9060 return (dp
->defalt
);
9065 /***********************************************************************
9067 ***********************************************************************/
9069 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9072 redisplay_windows (window
)
9075 while (!NILP (window
))
9077 struct window
*w
= XWINDOW (window
);
9079 if (!NILP (w
->hchild
))
9080 redisplay_windows (w
->hchild
);
9081 else if (!NILP (w
->vchild
))
9082 redisplay_windows (w
->vchild
);
9084 redisplay_window (window
, 0);
9091 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9092 DELTA is the number of bytes by which positions recorded in ROW
9093 differ from current buffer positions. */
9096 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9098 struct glyph_row
*row
;
9099 struct glyph_matrix
*matrix
;
9100 int delta
, delta_bytes
, dy
, dvpos
;
9102 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9103 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9105 int pt_old
= PT
- delta
;
9107 /* Skip over glyphs not having an object at the start of the row.
9108 These are special glyphs like truncation marks on terminal
9110 if (row
->displays_text_p
)
9112 && INTEGERP (glyph
->object
)
9113 && glyph
->charpos
< 0)
9115 x
+= glyph
->pixel_width
;
9120 && !INTEGERP (glyph
->object
)
9121 && (!BUFFERP (glyph
->object
)
9122 || glyph
->charpos
< pt_old
))
9124 x
+= glyph
->pixel_width
;
9128 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9130 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9131 w
->cursor
.y
= row
->y
+ dy
;
9133 if (w
== XWINDOW (selected_window
))
9135 if (!row
->continued_p
9136 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9139 this_line_buffer
= XBUFFER (w
->buffer
);
9141 CHARPOS (this_line_start_pos
)
9142 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9143 BYTEPOS (this_line_start_pos
)
9144 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9146 CHARPOS (this_line_end_pos
)
9147 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9148 BYTEPOS (this_line_end_pos
)
9149 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9151 this_line_y
= w
->cursor
.y
;
9152 this_line_pixel_height
= row
->height
;
9153 this_line_vpos
= w
->cursor
.vpos
;
9154 this_line_start_x
= row
->x
;
9157 CHARPOS (this_line_start_pos
) = 0;
9162 /* Run window scroll functions, if any, for WINDOW with new window
9163 start STARTP. Sets the window start of WINDOW to that position.
9165 We assume that the window's buffer is really current. */
9167 static INLINE
struct text_pos
9168 run_window_scroll_functions (window
, startp
)
9170 struct text_pos startp
;
9172 struct window
*w
= XWINDOW (window
);
9173 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9175 if (current_buffer
!= XBUFFER (w
->buffer
))
9178 if (!NILP (Vwindow_scroll_functions
))
9180 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9181 make_number (CHARPOS (startp
)));
9182 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9183 /* In case the hook functions switch buffers. */
9184 if (current_buffer
!= XBUFFER (w
->buffer
))
9185 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9192 /* Modify the desired matrix of window W and W->vscroll so that the
9193 line containing the cursor is fully visible. */
9196 make_cursor_line_fully_visible (w
)
9199 struct glyph_matrix
*matrix
;
9200 struct glyph_row
*row
;
9203 /* It's not always possible to find the cursor, e.g, when a window
9204 is full of overlay strings. Don't do anything in that case. */
9205 if (w
->cursor
.vpos
< 0)
9208 matrix
= w
->desired_matrix
;
9209 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9211 /* If the cursor row is not partially visible, there's nothing
9213 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9216 /* If the row the cursor is in is taller than the window's height,
9217 it's not clear what to do, so do nothing. */
9218 window_height
= window_box_height (w
);
9219 if (row
->height
>= window_height
)
9222 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9224 int dy
= row
->height
- row
->visible_height
;
9227 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9229 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9231 int dy
= - (row
->height
- row
->visible_height
);
9234 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9237 /* When we change the cursor y-position of the selected window,
9238 change this_line_y as well so that the display optimization for
9239 the cursor line of the selected window in redisplay_internal uses
9240 the correct y-position. */
9241 if (w
== XWINDOW (selected_window
))
9242 this_line_y
= w
->cursor
.y
;
9246 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9247 non-zero means only WINDOW is redisplayed in redisplay_internal.
9248 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9249 in redisplay_window to bring a partially visible line into view in
9250 the case that only the cursor has moved.
9254 1 if scrolling succeeded
9256 0 if scrolling didn't find point.
9258 -1 if new fonts have been loaded so that we must interrupt
9259 redisplay, adjust glyph matrices, and try again. */
9262 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9263 scroll_step
, temp_scroll_step
)
9265 int just_this_one_p
;
9266 int scroll_conservatively
, scroll_step
;
9267 int temp_scroll_step
;
9269 struct window
*w
= XWINDOW (window
);
9270 struct frame
*f
= XFRAME (w
->frame
);
9271 struct text_pos scroll_margin_pos
;
9272 struct text_pos pos
;
9273 struct text_pos startp
;
9275 Lisp_Object window_end
;
9276 int this_scroll_margin
;
9280 int amount_to_scroll
= 0;
9281 Lisp_Object aggressive
;
9285 debug_method_add (w
, "try_scrolling");
9288 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9290 /* Compute scroll margin height in pixels. We scroll when point is
9291 within this distance from the top or bottom of the window. */
9292 if (scroll_margin
> 0)
9294 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9295 this_scroll_margin
*= CANON_Y_UNIT (f
);
9298 this_scroll_margin
= 0;
9300 /* Compute how much we should try to scroll maximally to bring point
9302 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9303 scroll_max
= max (scroll_step
,
9304 max (scroll_conservatively
, temp_scroll_step
));
9305 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9306 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9307 /* We're trying to scroll because of aggressive scrolling
9308 but no scroll_step is set. Choose an arbitrary one. Maybe
9309 there should be a variable for this. */
9313 scroll_max
*= CANON_Y_UNIT (f
);
9315 /* Decide whether we have to scroll down. Start at the window end
9316 and move this_scroll_margin up to find the position of the scroll
9318 window_end
= Fwindow_end (window
, Qt
);
9319 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9320 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9321 if (this_scroll_margin
)
9323 start_display (&it
, w
, scroll_margin_pos
);
9324 move_it_vertically (&it
, - this_scroll_margin
);
9325 scroll_margin_pos
= it
.current
.pos
;
9328 if (PT
>= CHARPOS (scroll_margin_pos
))
9332 /* Point is in the scroll margin at the bottom of the window, or
9333 below. Compute a new window start that makes point visible. */
9335 /* Compute the distance from the scroll margin to PT.
9336 Give up if the distance is greater than scroll_max. */
9337 start_display (&it
, w
, scroll_margin_pos
);
9339 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9340 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9342 /* With a scroll_margin of 0, scroll_margin_pos is at the window
9343 end, which is one line below the window. The iterator's
9344 current_y will be same as y0 in that case, but we have to
9345 scroll a line to make PT visible. That's the reason why 1 is
9347 dy
= 1 + it
.current_y
- y0
;
9349 if (dy
> scroll_max
)
9352 /* Move the window start down. If scrolling conservatively,
9353 move it just enough down to make point visible. If
9354 scroll_step is set, move it down by scroll_step. */
9355 start_display (&it
, w
, startp
);
9357 if (scroll_conservatively
)
9359 = max (max (dy
, CANON_Y_UNIT (f
)),
9360 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9361 else if (scroll_step
|| temp_scroll_step
)
9362 amount_to_scroll
= scroll_max
;
9365 aggressive
= current_buffer
->scroll_down_aggressively
;
9366 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9367 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9368 if (NUMBERP (aggressive
))
9369 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9372 if (amount_to_scroll
<= 0)
9375 move_it_vertically (&it
, amount_to_scroll
);
9376 startp
= it
.current
.pos
;
9380 /* See if point is inside the scroll margin at the top of the
9382 scroll_margin_pos
= startp
;
9383 if (this_scroll_margin
)
9385 start_display (&it
, w
, startp
);
9386 move_it_vertically (&it
, this_scroll_margin
);
9387 scroll_margin_pos
= it
.current
.pos
;
9390 if (PT
< CHARPOS (scroll_margin_pos
))
9392 /* Point is in the scroll margin at the top of the window or
9393 above what is displayed in the window. */
9396 /* Compute the vertical distance from PT to the scroll
9397 margin position. Give up if distance is greater than
9399 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9400 start_display (&it
, w
, pos
);
9402 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9403 it
.last_visible_y
, -1,
9404 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9405 dy
= it
.current_y
- y0
;
9406 if (dy
> scroll_max
)
9409 /* Compute new window start. */
9410 start_display (&it
, w
, startp
);
9412 if (scroll_conservatively
)
9414 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9415 else if (scroll_step
|| temp_scroll_step
)
9416 amount_to_scroll
= scroll_max
;
9419 aggressive
= current_buffer
->scroll_up_aggressively
;
9420 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9421 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9422 if (NUMBERP (aggressive
))
9423 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9426 if (amount_to_scroll
<= 0)
9429 move_it_vertically (&it
, - amount_to_scroll
);
9430 startp
= it
.current
.pos
;
9434 /* Run window scroll functions. */
9435 startp
= run_window_scroll_functions (window
, startp
);
9437 /* Display the window. Give up if new fonts are loaded, or if point
9439 if (!try_window (window
, startp
))
9441 else if (w
->cursor
.vpos
< 0)
9443 clear_glyph_matrix (w
->desired_matrix
);
9448 /* Maybe forget recorded base line for line number display. */
9449 if (!just_this_one_p
9450 || current_buffer
->clip_changed
9451 || BEG_UNCHANGED
< CHARPOS (startp
))
9452 w
->base_line_number
= Qnil
;
9454 /* If cursor ends up on a partially visible line, shift display
9455 lines up or down. */
9456 make_cursor_line_fully_visible (w
);
9464 /* Compute a suitable window start for window W if display of W starts
9465 on a continuation line. Value is non-zero if a new window start
9468 The new window start will be computed, based on W's width, starting
9469 from the start of the continued line. It is the start of the
9470 screen line with the minimum distance from the old start W->start. */
9473 compute_window_start_on_continuation_line (w
)
9476 struct text_pos pos
, start_pos
;
9477 int window_start_changed_p
= 0;
9479 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9481 /* If window start is on a continuation line... Window start may be
9482 < BEGV in case there's invisible text at the start of the
9483 buffer (M-x rmail, for example). */
9484 if (CHARPOS (start_pos
) > BEGV
9485 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9488 struct glyph_row
*row
;
9490 /* Handle the case that the window start is out of range. */
9491 if (CHARPOS (start_pos
) < BEGV
)
9492 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9493 else if (CHARPOS (start_pos
) > ZV
)
9494 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9496 /* Find the start of the continued line. This should be fast
9497 because scan_buffer is fast (newline cache). */
9498 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9499 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9500 row
, DEFAULT_FACE_ID
);
9501 reseat_at_previous_visible_line_start (&it
);
9503 /* If the line start is "too far" away from the window start,
9504 say it takes too much time to compute a new window start. */
9505 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9506 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9508 int min_distance
, distance
;
9510 /* Move forward by display lines to find the new window
9511 start. If window width was enlarged, the new start can
9512 be expected to be > the old start. If window width was
9513 decreased, the new window start will be < the old start.
9514 So, we're looking for the display line start with the
9515 minimum distance from the old window start. */
9516 pos
= it
.current
.pos
;
9517 min_distance
= INFINITY
;
9518 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9519 distance
< min_distance
)
9521 min_distance
= distance
;
9522 pos
= it
.current
.pos
;
9523 move_it_by_lines (&it
, 1, 0);
9526 /* Set the window start there. */
9527 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9528 window_start_changed_p
= 1;
9532 return window_start_changed_p
;
9536 /* Try cursor movement in case text has not changes in window WINDOW,
9537 with window start STARTP. Value is
9541 0 if this method cannot be used
9543 -1 if we know we have to scroll the display. *SCROLL_STEP is
9544 set to 1, under certain circumstances, if we want to scroll as
9545 if scroll-step were set to 1. See the code. */
9548 try_cursor_movement (window
, startp
, scroll_step
)
9550 struct text_pos startp
;
9553 struct window
*w
= XWINDOW (window
);
9554 struct frame
*f
= XFRAME (w
->frame
);
9557 /* Handle case where text has not changed, only point, and it has
9558 not moved off the frame. */
9559 if (/* Point may be in this window. */
9560 PT
>= CHARPOS (startp
)
9561 /* Selective display hasn't changed. */
9562 && !current_buffer
->clip_changed
9563 /* Function force-mode-line-update is used to force a thorough
9564 redisplay. It sets either windows_or_buffers_changed or
9565 update_mode_lines. So don't take a shortcut here for these
9567 && !update_mode_lines
9568 && !windows_or_buffers_changed
9569 /* Can't use this case if highlighting a region. When a
9570 region exists, cursor movement has to do more than just
9572 && !(!NILP (Vtransient_mark_mode
)
9573 && !NILP (current_buffer
->mark_active
))
9574 && NILP (w
->region_showing
)
9575 && NILP (Vshow_trailing_whitespace
)
9576 /* Right after splitting windows, last_point may be nil. */
9577 && INTEGERP (w
->last_point
)
9578 /* This code is not used for mini-buffer for the sake of the case
9579 of redisplaying to replace an echo area message; since in
9580 that case the mini-buffer contents per se are usually
9581 unchanged. This code is of no real use in the mini-buffer
9582 since the handling of this_line_start_pos, etc., in redisplay
9583 handles the same cases. */
9584 && !EQ (window
, minibuf_window
)
9585 /* When splitting windows or for new windows, it happens that
9586 redisplay is called with a nil window_end_vpos or one being
9587 larger than the window. This should really be fixed in
9588 window.c. I don't have this on my list, now, so we do
9589 approximately the same as the old redisplay code. --gerd. */
9590 && INTEGERP (w
->window_end_vpos
)
9591 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9592 && (FRAME_WINDOW_P (f
)
9593 || !MARKERP (Voverlay_arrow_position
)
9594 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9596 int this_scroll_margin
;
9597 struct glyph_row
*row
= NULL
;
9600 debug_method_add (w
, "cursor movement");
9603 /* Scroll if point within this distance from the top or bottom
9604 of the window. This is a pixel value. */
9605 this_scroll_margin
= max (0, scroll_margin
);
9606 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9607 this_scroll_margin
*= CANON_Y_UNIT (f
);
9609 /* Start with the row the cursor was displayed during the last
9610 not paused redisplay. Give up if that row is not valid. */
9611 if (w
->last_cursor
.vpos
< 0
9612 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9616 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9617 if (row
->mode_line_p
)
9619 if (!row
->enabled_p
)
9626 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9628 if (PT
> XFASTINT (w
->last_point
))
9630 /* Point has moved forward. */
9631 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9632 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9634 xassert (row
->enabled_p
);
9638 /* The end position of a row equals the start position
9639 of the next row. If PT is there, we would rather
9640 display it in the next line. */
9641 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9642 && MATRIX_ROW_END_CHARPOS (row
) == PT
9643 && !cursor_row_p (w
, row
))
9646 /* If within the scroll margin, scroll. Note that
9647 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9648 the next line would be drawn, and that
9649 this_scroll_margin can be zero. */
9650 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9651 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9652 /* Line is completely visible last line in window
9653 and PT is to be set in the next line. */
9654 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9655 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9656 && !row
->ends_at_zv_p
9657 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9660 else if (PT
< XFASTINT (w
->last_point
))
9662 /* Cursor has to be moved backward. Note that PT >=
9663 CHARPOS (startp) because of the outer
9665 while (!row
->mode_line_p
9666 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9667 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9668 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9669 && (row
->y
> this_scroll_margin
9670 || CHARPOS (startp
) == BEGV
))
9672 xassert (row
->enabled_p
);
9676 /* Consider the following case: Window starts at BEGV,
9677 there is invisible, intangible text at BEGV, so that
9678 display starts at some point START > BEGV. It can
9679 happen that we are called with PT somewhere between
9680 BEGV and START. Try to handle that case. */
9681 if (row
< w
->current_matrix
->rows
9682 || row
->mode_line_p
)
9684 row
= w
->current_matrix
->rows
;
9685 if (row
->mode_line_p
)
9689 /* Due to newlines in overlay strings, we may have to
9690 skip forward over overlay strings. */
9691 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9692 && MATRIX_ROW_END_CHARPOS (row
) == PT
9693 && !cursor_row_p (w
, row
))
9696 /* If within the scroll margin, scroll. */
9697 if (row
->y
< this_scroll_margin
9698 && CHARPOS (startp
) != BEGV
)
9702 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9703 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9705 /* if PT is not in the glyph row, give up. */
9708 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9710 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9711 && !row
->ends_at_zv_p
9712 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9714 else if (row
->height
> window_box_height (w
))
9716 /* If we end up in a partially visible line, let's
9717 make it fully visible, except when it's taller
9718 than the window, in which case we can't do much
9725 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9726 try_window (window
, startp
);
9727 make_cursor_line_fully_visible (w
);
9735 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9745 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9746 selected_window is redisplayed. */
9749 redisplay_window (window
, just_this_one_p
)
9751 int just_this_one_p
;
9753 struct window
*w
= XWINDOW (window
);
9754 struct frame
*f
= XFRAME (w
->frame
);
9755 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9756 struct buffer
*old
= current_buffer
;
9757 struct text_pos lpoint
, opoint
, startp
;
9758 int update_mode_line
;
9761 /* Record it now because it's overwritten. */
9762 int current_matrix_up_to_date_p
= 0;
9763 int temp_scroll_step
= 0;
9764 int count
= BINDING_STACK_SIZE ();
9767 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9770 /* W must be a leaf window here. */
9771 xassert (!NILP (w
->buffer
));
9773 *w
->desired_matrix
->method
= 0;
9776 specbind (Qinhibit_point_motion_hooks
, Qt
);
9778 reconsider_clip_changes (w
, buffer
);
9780 /* Has the mode line to be updated? */
9781 update_mode_line
= (!NILP (w
->update_mode_line
)
9782 || update_mode_lines
9783 || buffer
->clip_changed
);
9785 if (MINI_WINDOW_P (w
))
9787 if (w
== XWINDOW (echo_area_window
)
9788 && !NILP (echo_area_buffer
[0]))
9790 if (update_mode_line
)
9791 /* We may have to update a tty frame's menu bar or a
9792 tool-bar. Example `M-x C-h C-h C-g'. */
9793 goto finish_menu_bars
;
9795 /* We've already displayed the echo area glyphs in this window. */
9796 goto finish_scroll_bars
;
9798 else if (w
!= XWINDOW (minibuf_window
))
9800 /* W is a mini-buffer window, but it's not the currently
9801 active one, so clear it. */
9802 int yb
= window_text_bottom_y (w
);
9803 struct glyph_row
*row
;
9806 for (y
= 0, row
= w
->desired_matrix
->rows
;
9808 y
+= row
->height
, ++row
)
9809 blank_row (w
, row
, y
);
9810 goto finish_scroll_bars
;
9813 clear_glyph_matrix (w
->desired_matrix
);
9816 /* Otherwise set up data on this window; select its buffer and point
9818 /* Really select the buffer, for the sake of buffer-local
9820 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9821 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9823 current_matrix_up_to_date_p
9824 = (!NILP (w
->window_end_valid
)
9825 && !current_buffer
->clip_changed
9826 && XFASTINT (w
->last_modified
) >= MODIFF
9827 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9829 /* When windows_or_buffers_changed is non-zero, we can't rely on
9830 the window end being valid, so set it to nil there. */
9831 if (windows_or_buffers_changed
)
9833 /* If window starts on a continuation line, maybe adjust the
9834 window start in case the window's width changed. */
9835 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9836 compute_window_start_on_continuation_line (w
);
9838 w
->window_end_valid
= Qnil
;
9841 /* Some sanity checks. */
9842 CHECK_WINDOW_END (w
);
9843 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9845 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9848 /* If %c is in mode line, update it if needed. */
9849 if (!NILP (w
->column_number_displayed
)
9850 /* This alternative quickly identifies a common case
9851 where no change is needed. */
9852 && !(PT
== XFASTINT (w
->last_point
)
9853 && XFASTINT (w
->last_modified
) >= MODIFF
9854 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9855 && XFASTINT (w
->column_number_displayed
) != current_column ())
9856 update_mode_line
= 1;
9858 /* Count number of windows showing the selected buffer. An indirect
9859 buffer counts as its base buffer. */
9860 if (!just_this_one_p
)
9862 struct buffer
*current_base
, *window_base
;
9863 current_base
= current_buffer
;
9864 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9865 if (current_base
->base_buffer
)
9866 current_base
= current_base
->base_buffer
;
9867 if (window_base
->base_buffer
)
9868 window_base
= window_base
->base_buffer
;
9869 if (current_base
== window_base
)
9873 /* Point refers normally to the selected window. For any other
9874 window, set up appropriate value. */
9875 if (!EQ (window
, selected_window
))
9877 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9878 int new_pt_byte
= marker_byte_position (w
->pointm
);
9882 new_pt_byte
= BEGV_BYTE
;
9883 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9885 else if (new_pt
> (ZV
- 1))
9888 new_pt_byte
= ZV_BYTE
;
9889 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9892 /* We don't use SET_PT so that the point-motion hooks don't run. */
9893 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9896 /* If any of the character widths specified in the display table
9897 have changed, invalidate the width run cache. It's true that
9898 this may be a bit late to catch such changes, but the rest of
9899 redisplay goes (non-fatally) haywire when the display table is
9900 changed, so why should we worry about doing any better? */
9901 if (current_buffer
->width_run_cache
)
9903 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9905 if (! disptab_matches_widthtab (disptab
,
9906 XVECTOR (current_buffer
->width_table
)))
9908 invalidate_region_cache (current_buffer
,
9909 current_buffer
->width_run_cache
,
9911 recompute_width_table (current_buffer
, disptab
);
9915 /* If window-start is screwed up, choose a new one. */
9916 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9919 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9921 /* If someone specified a new starting point but did not insist,
9922 check whether it can be used. */
9923 if (!NILP (w
->optional_new_start
)
9924 && CHARPOS (startp
) >= BEGV
9925 && CHARPOS (startp
) <= ZV
)
9927 w
->optional_new_start
= Qnil
;
9928 start_display (&it
, w
, startp
);
9929 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9930 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9931 if (IT_CHARPOS (it
) == PT
)
9932 w
->force_start
= Qt
;
9935 /* Handle case where place to start displaying has been specified,
9936 unless the specified location is outside the accessible range. */
9937 if (!NILP (w
->force_start
)
9938 || w
->frozen_window_start_p
)
9940 w
->force_start
= Qnil
;
9942 w
->window_end_valid
= Qnil
;
9944 /* Forget any recorded base line for line number display. */
9945 if (!current_matrix_up_to_date_p
9946 || current_buffer
->clip_changed
)
9947 w
->base_line_number
= Qnil
;
9949 /* Redisplay the mode line. Select the buffer properly for that.
9950 Also, run the hook window-scroll-functions
9951 because we have scrolled. */
9952 /* Note, we do this after clearing force_start because
9953 if there's an error, it is better to forget about force_start
9954 than to get into an infinite loop calling the hook functions
9955 and having them get more errors. */
9956 if (!update_mode_line
9957 || ! NILP (Vwindow_scroll_functions
))
9959 update_mode_line
= 1;
9960 w
->update_mode_line
= Qt
;
9961 startp
= run_window_scroll_functions (window
, startp
);
9964 w
->last_modified
= make_number (0);
9965 w
->last_overlay_modified
= make_number (0);
9966 if (CHARPOS (startp
) < BEGV
)
9967 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9968 else if (CHARPOS (startp
) > ZV
)
9969 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9971 /* Redisplay, then check if cursor has been set during the
9972 redisplay. Give up if new fonts were loaded. */
9973 if (!try_window (window
, startp
))
9975 w
->force_start
= Qt
;
9976 clear_glyph_matrix (w
->desired_matrix
);
9977 goto finish_scroll_bars
;
9980 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9982 /* If point does not appear, try to move point so it does
9983 appear. The desired matrix has been built above, so we
9986 struct glyph_row
*row
;
9988 window_height
= window_box_height (w
) / 2;
9989 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9990 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9993 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9994 MATRIX_ROW_START_BYTEPOS (row
));
9996 if (w
!= XWINDOW (selected_window
))
9997 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9998 else if (current_buffer
== old
)
9999 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10001 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10003 /* If we are highlighting the region, then we just changed
10004 the region, so redisplay to show it. */
10005 if (!NILP (Vtransient_mark_mode
)
10006 && !NILP (current_buffer
->mark_active
))
10008 clear_glyph_matrix (w
->desired_matrix
);
10009 if (!try_window (window
, startp
))
10010 goto finish_scroll_bars
;
10014 make_cursor_line_fully_visible (w
);
10016 debug_method_add (w
, "forced window start");
10021 /* Handle case where text has not changed, only point, and it has
10022 not moved off the frame. */
10023 if (current_matrix_up_to_date_p
10024 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10028 goto try_to_scroll
;
10032 /* If current starting point was originally the beginning of a line
10033 but no longer is, find a new starting point. */
10034 else if (!NILP (w
->start_at_line_beg
)
10035 && !(CHARPOS (startp
) <= BEGV
10036 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10039 debug_method_add (w
, "recenter 1");
10044 /* Try scrolling with try_window_id. Value is > 0 if update has
10045 been done, it is -1 if we know that the same window start will
10046 not work. It is 0 if unsuccessful for some other reason. */
10047 else if ((tem
= try_window_id (w
)) != 0)
10050 debug_method_add (w
, "try_window_id %d", tem
);
10053 if (fonts_changed_p
)
10054 goto finish_scroll_bars
;
10058 /* Otherwise try_window_id has returned -1 which means that we
10059 don't want the alternative below this comment to execute. */
10061 else if (CHARPOS (startp
) >= BEGV
10062 && CHARPOS (startp
) <= ZV
10063 && PT
>= CHARPOS (startp
)
10064 && (CHARPOS (startp
) < ZV
10065 /* Avoid starting at end of buffer. */
10066 || CHARPOS (startp
) == BEGV
10067 || (XFASTINT (w
->last_modified
) >= MODIFF
10068 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10071 debug_method_add (w
, "same window start");
10074 /* Try to redisplay starting at same place as before.
10075 If point has not moved off frame, accept the results. */
10076 if (!current_matrix_up_to_date_p
10077 /* Don't use try_window_reusing_current_matrix in this case
10078 because a window scroll function can have changed the
10080 || !NILP (Vwindow_scroll_functions
)
10081 || MINI_WINDOW_P (w
)
10082 || !try_window_reusing_current_matrix (w
))
10084 IF_DEBUG (debug_method_add (w
, "1"));
10085 try_window (window
, startp
);
10088 if (fonts_changed_p
)
10089 goto finish_scroll_bars
;
10091 if (w
->cursor
.vpos
>= 0)
10093 if (!just_this_one_p
10094 || current_buffer
->clip_changed
10095 || BEG_UNCHANGED
< CHARPOS (startp
))
10096 /* Forget any recorded base line for line number display. */
10097 w
->base_line_number
= Qnil
;
10099 make_cursor_line_fully_visible (w
);
10103 clear_glyph_matrix (w
->desired_matrix
);
10108 w
->last_modified
= make_number (0);
10109 w
->last_overlay_modified
= make_number (0);
10111 /* Redisplay the mode line. Select the buffer properly for that. */
10112 if (!update_mode_line
)
10114 update_mode_line
= 1;
10115 w
->update_mode_line
= Qt
;
10118 /* Try to scroll by specified few lines. */
10119 if ((scroll_conservatively
10121 || temp_scroll_step
10122 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10123 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10124 && !current_buffer
->clip_changed
10125 && CHARPOS (startp
) >= BEGV
10126 && CHARPOS (startp
) <= ZV
)
10128 /* The function returns -1 if new fonts were loaded, 1 if
10129 successful, 0 if not successful. */
10130 int rc
= try_scrolling (window
, just_this_one_p
,
10131 scroll_conservatively
,
10137 goto finish_scroll_bars
;
10140 /* Finally, just choose place to start which centers point */
10145 debug_method_add (w
, "recenter");
10148 /* w->vscroll = 0; */
10150 /* Forget any previously recorded base line for line number display. */
10151 if (!current_matrix_up_to_date_p
10152 || current_buffer
->clip_changed
)
10153 w
->base_line_number
= Qnil
;
10155 /* Move backward half the height of the window. */
10156 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10157 it
.current_y
= it
.last_visible_y
;
10158 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10159 xassert (IT_CHARPOS (it
) >= BEGV
);
10161 /* The function move_it_vertically_backward may move over more
10162 than the specified y-distance. If it->w is small, e.g. a
10163 mini-buffer window, we may end up in front of the window's
10164 display area. Start displaying at the start of the line
10165 containing PT in this case. */
10166 if (it
.current_y
<= 0)
10168 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10169 move_it_vertically (&it
, 0);
10170 xassert (IT_CHARPOS (it
) <= PT
);
10174 it
.current_x
= it
.hpos
= 0;
10176 /* Set startp here explicitly in case that helps avoid an infinite loop
10177 in case the window-scroll-functions functions get errors. */
10178 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10180 /* Run scroll hooks. */
10181 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10183 /* Redisplay the window. */
10184 if (!current_matrix_up_to_date_p
10185 || windows_or_buffers_changed
10186 /* Don't use try_window_reusing_current_matrix in this case
10187 because it can have changed the buffer. */
10188 || !NILP (Vwindow_scroll_functions
)
10189 || !just_this_one_p
10190 || MINI_WINDOW_P (w
)
10191 || !try_window_reusing_current_matrix (w
))
10192 try_window (window
, startp
);
10194 /* If new fonts have been loaded (due to fontsets), give up. We
10195 have to start a new redisplay since we need to re-adjust glyph
10197 if (fonts_changed_p
)
10198 goto finish_scroll_bars
;
10200 /* If cursor did not appear assume that the middle of the window is
10201 in the first line of the window. Do it again with the next line.
10202 (Imagine a window of height 100, displaying two lines of height
10203 60. Moving back 50 from it->last_visible_y will end in the first
10205 if (w
->cursor
.vpos
< 0)
10207 if (!NILP (w
->window_end_valid
)
10208 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10210 clear_glyph_matrix (w
->desired_matrix
);
10211 move_it_by_lines (&it
, 1, 0);
10212 try_window (window
, it
.current
.pos
);
10214 else if (PT
< IT_CHARPOS (it
))
10216 clear_glyph_matrix (w
->desired_matrix
);
10217 move_it_by_lines (&it
, -1, 0);
10218 try_window (window
, it
.current
.pos
);
10222 /* Not much we can do about it. */
10226 /* Consider the following case: Window starts at BEGV, there is
10227 invisible, intangible text at BEGV, so that display starts at
10228 some point START > BEGV. It can happen that we are called with
10229 PT somewhere between BEGV and START. Try to handle that case. */
10230 if (w
->cursor
.vpos
< 0)
10232 struct glyph_row
*row
= w
->current_matrix
->rows
;
10233 if (row
->mode_line_p
)
10235 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10238 make_cursor_line_fully_visible (w
);
10242 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10243 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10244 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10247 /* Display the mode line, if we must. */
10248 if ((update_mode_line
10249 /* If window not full width, must redo its mode line
10250 if (a) the window to its side is being redone and
10251 (b) we do a frame-based redisplay. This is a consequence
10252 of how inverted lines are drawn in frame-based redisplay. */
10253 || (!just_this_one_p
10254 && !FRAME_WINDOW_P (f
)
10255 && !WINDOW_FULL_WIDTH_P (w
))
10256 /* Line number to display. */
10257 || INTEGERP (w
->base_line_pos
)
10258 /* Column number is displayed and different from the one displayed. */
10259 || (!NILP (w
->column_number_displayed
)
10260 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10261 /* This means that the window has a mode line. */
10262 && (WINDOW_WANTS_MODELINE_P (w
)
10263 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10265 Lisp_Object old_selected_frame
;
10267 old_selected_frame
= selected_frame
;
10269 XSETFRAME (selected_frame
, f
);
10270 display_mode_lines (w
);
10271 selected_frame
= old_selected_frame
;
10273 /* If mode line height has changed, arrange for a thorough
10274 immediate redisplay using the correct mode line height. */
10275 if (WINDOW_WANTS_MODELINE_P (w
)
10276 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10278 fonts_changed_p
= 1;
10279 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10280 = DESIRED_MODE_LINE_HEIGHT (w
);
10283 /* If top line height has changed, arrange for a thorough
10284 immediate redisplay using the correct mode line height. */
10285 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10286 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10288 fonts_changed_p
= 1;
10289 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10290 = DESIRED_HEADER_LINE_HEIGHT (w
);
10293 if (fonts_changed_p
)
10294 goto finish_scroll_bars
;
10297 if (!line_number_displayed
10298 && !BUFFERP (w
->base_line_pos
))
10300 w
->base_line_pos
= Qnil
;
10301 w
->base_line_number
= Qnil
;
10306 /* When we reach a frame's selected window, redo the frame's menu bar. */
10307 if (update_mode_line
10308 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10310 int redisplay_menu_p
= 0;
10312 if (FRAME_WINDOW_P (f
))
10314 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10315 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10317 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10321 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10323 if (redisplay_menu_p
)
10324 display_menu_bar (w
);
10326 #ifdef HAVE_WINDOW_SYSTEM
10327 if (WINDOWP (f
->tool_bar_window
)
10328 && (FRAME_TOOL_BAR_LINES (f
) > 0
10329 || auto_resize_tool_bars_p
))
10330 redisplay_tool_bar (f
);
10334 finish_scroll_bars
:
10336 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10338 int start
, end
, whole
;
10340 /* Calculate the start and end positions for the current window.
10341 At some point, it would be nice to choose between scrollbars
10342 which reflect the whole buffer size, with special markers
10343 indicating narrowing, and scrollbars which reflect only the
10346 Note that mini-buffers sometimes aren't displaying any text. */
10347 if (!MINI_WINDOW_P (w
)
10348 || (w
== XWINDOW (minibuf_window
)
10349 && NILP (echo_area_buffer
[0])))
10352 start
= marker_position (w
->start
) - BEGV
;
10353 /* I don't think this is guaranteed to be right. For the
10354 moment, we'll pretend it is. */
10355 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10359 if (whole
< (end
- start
))
10360 whole
= end
- start
;
10363 start
= end
= whole
= 0;
10365 /* Indicate what this scroll bar ought to be displaying now. */
10366 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10368 /* Note that we actually used the scroll bar attached to this
10369 window, so it shouldn't be deleted at the end of redisplay. */
10370 redeem_scroll_bar_hook (w
);
10373 /* Restore current_buffer and value of point in it. */
10374 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10375 set_buffer_internal_1 (old
);
10376 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10378 unbind_to (count
, Qnil
);
10382 /* Build the complete desired matrix of WINDOW with a window start
10383 buffer position POS. Value is non-zero if successful. It is zero
10384 if fonts were loaded during redisplay which makes re-adjusting
10385 glyph matrices necessary. */
10388 try_window (window
, pos
)
10389 Lisp_Object window
;
10390 struct text_pos pos
;
10392 struct window
*w
= XWINDOW (window
);
10394 struct glyph_row
*last_text_row
= NULL
;
10396 /* Make POS the new window start. */
10397 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10399 /* Mark cursor position as unknown. No overlay arrow seen. */
10400 w
->cursor
.vpos
= -1;
10401 overlay_arrow_seen
= 0;
10403 /* Initialize iterator and info to start at POS. */
10404 start_display (&it
, w
, pos
);
10406 /* Display all lines of W. */
10407 while (it
.current_y
< it
.last_visible_y
)
10409 if (display_line (&it
))
10410 last_text_row
= it
.glyph_row
- 1;
10411 if (fonts_changed_p
)
10415 /* If bottom moved off end of frame, change mode line percentage. */
10416 if (XFASTINT (w
->window_end_pos
) <= 0
10417 && Z
!= IT_CHARPOS (it
))
10418 w
->update_mode_line
= Qt
;
10420 /* Set window_end_pos to the offset of the last character displayed
10421 on the window from the end of current_buffer. Set
10422 window_end_vpos to its row number. */
10425 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10426 w
->window_end_bytepos
10427 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10429 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10431 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10432 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10433 ->displays_text_p
);
10437 w
->window_end_bytepos
= 0;
10438 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10441 /* But that is not valid info until redisplay finishes. */
10442 w
->window_end_valid
= Qnil
;
10448 /************************************************************************
10449 Window redisplay reusing current matrix when buffer has not changed
10450 ************************************************************************/
10452 /* Try redisplay of window W showing an unchanged buffer with a
10453 different window start than the last time it was displayed by
10454 reusing its current matrix. Value is non-zero if successful.
10455 W->start is the new window start. */
10458 try_window_reusing_current_matrix (w
)
10461 struct frame
*f
= XFRAME (w
->frame
);
10462 struct glyph_row
*row
, *bottom_row
;
10465 struct text_pos start
, new_start
;
10466 int nrows_scrolled
, i
;
10467 struct glyph_row
*last_text_row
;
10468 struct glyph_row
*last_reused_text_row
;
10469 struct glyph_row
*start_row
;
10470 int start_vpos
, min_y
, max_y
;
10472 if (/* This function doesn't handle terminal frames. */
10473 !FRAME_WINDOW_P (f
)
10474 /* Don't try to reuse the display if windows have been split
10476 || windows_or_buffers_changed
)
10479 /* Can't do this if region may have changed. */
10480 if ((!NILP (Vtransient_mark_mode
)
10481 && !NILP (current_buffer
->mark_active
))
10482 || !NILP (w
->region_showing
)
10483 || !NILP (Vshow_trailing_whitespace
))
10486 /* If top-line visibility has changed, give up. */
10487 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10488 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10491 /* Give up if old or new display is scrolled vertically. We could
10492 make this function handle this, but right now it doesn't. */
10493 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10494 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10497 /* The variable new_start now holds the new window start. The old
10498 start `start' can be determined from the current matrix. */
10499 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10500 start
= start_row
->start
.pos
;
10501 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10503 /* Clear the desired matrix for the display below. */
10504 clear_glyph_matrix (w
->desired_matrix
);
10506 if (CHARPOS (new_start
) <= CHARPOS (start
))
10510 /* Don't use this method if the display starts with an ellipsis
10511 displayed for invisible text. It's not easy to handle that case
10512 below, and it's certainly not worth the effort since this is
10513 not a frequent case. */
10514 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10517 IF_DEBUG (debug_method_add (w
, "twu1"));
10519 /* Display up to a row that can be reused. The variable
10520 last_text_row is set to the last row displayed that displays
10521 text. Note that it.vpos == 0 if or if not there is a
10522 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10523 start_display (&it
, w
, new_start
);
10524 first_row_y
= it
.current_y
;
10525 w
->cursor
.vpos
= -1;
10526 last_text_row
= last_reused_text_row
= NULL
;
10528 while (it
.current_y
< it
.last_visible_y
10529 && IT_CHARPOS (it
) < CHARPOS (start
)
10530 && !fonts_changed_p
)
10531 if (display_line (&it
))
10532 last_text_row
= it
.glyph_row
- 1;
10534 /* A value of current_y < last_visible_y means that we stopped
10535 at the previous window start, which in turn means that we
10536 have at least one reusable row. */
10537 if (it
.current_y
< it
.last_visible_y
)
10539 /* IT.vpos always starts from 0; it counts text lines. */
10540 nrows_scrolled
= it
.vpos
;
10542 /* Find PT if not already found in the lines displayed. */
10543 if (w
->cursor
.vpos
< 0)
10545 int dy
= it
.current_y
- first_row_y
;
10547 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10548 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10550 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
10551 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10553 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10554 dy
, nrows_scrolled
);
10558 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10564 /* Give up if point was not found. This shouldn't
10565 happen often; not more often than with try_window
10567 if (w
->cursor
.vpos
< 0)
10569 clear_glyph_matrix (w
->desired_matrix
);
10574 /* Scroll the display. Do it before the current matrix is
10575 changed. The problem here is that update has not yet
10576 run, i.e. part of the current matrix is not up to date.
10577 scroll_run_hook will clear the cursor, and use the
10578 current matrix to get the height of the row the cursor is
10580 run
.current_y
= first_row_y
;
10581 run
.desired_y
= it
.current_y
;
10582 run
.height
= it
.last_visible_y
- it
.current_y
;
10584 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10587 rif
->update_window_begin_hook (w
);
10588 rif
->clear_mouse_face (w
);
10589 rif
->scroll_run_hook (w
, &run
);
10590 rif
->update_window_end_hook (w
, 0, 0);
10594 /* Shift current matrix down by nrows_scrolled lines. */
10595 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10596 rotate_matrix (w
->current_matrix
,
10598 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10601 /* Disable lines that must be updated. */
10602 for (i
= 0; i
< it
.vpos
; ++i
)
10603 (start_row
+ i
)->enabled_p
= 0;
10605 /* Re-compute Y positions. */
10606 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10607 max_y
= it
.last_visible_y
;
10608 for (row
= start_row
+ nrows_scrolled
;
10612 row
->y
= it
.current_y
;
10614 if (row
->y
< min_y
)
10615 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10616 else if (row
->y
+ row
->height
> max_y
)
10617 row
->visible_height
10618 = row
->height
- (row
->y
+ row
->height
- max_y
);
10620 row
->visible_height
= row
->height
;
10622 it
.current_y
+= row
->height
;
10624 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10625 last_reused_text_row
= row
;
10626 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10630 /* Disable lines in the current matrix which are now
10631 below the window. */
10632 for (++row
; row
< bottom_row
; ++row
)
10633 row
->enabled_p
= 0;
10636 /* Update window_end_pos etc.; last_reused_text_row is the last
10637 reused row from the current matrix containing text, if any.
10638 The value of last_text_row is the last displayed line
10639 containing text. */
10640 if (last_reused_text_row
)
10642 w
->window_end_bytepos
10643 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10645 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10647 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10648 w
->current_matrix
));
10650 else if (last_text_row
)
10652 w
->window_end_bytepos
10653 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10655 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10657 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10661 /* This window must be completely empty. */
10662 w
->window_end_bytepos
= 0;
10663 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10665 w
->window_end_valid
= Qnil
;
10667 /* Update hint: don't try scrolling again in update_window. */
10668 w
->desired_matrix
->no_scrolling_p
= 1;
10671 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10675 else if (CHARPOS (new_start
) > CHARPOS (start
))
10677 struct glyph_row
*pt_row
, *row
;
10678 struct glyph_row
*first_reusable_row
;
10679 struct glyph_row
*first_row_to_display
;
10681 int yb
= window_text_bottom_y (w
);
10683 /* Find the row starting at new_start, if there is one. Don't
10684 reuse a partially visible line at the end. */
10685 first_reusable_row
= start_row
;
10686 while (first_reusable_row
->enabled_p
10687 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10688 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10689 < CHARPOS (new_start
)))
10690 ++first_reusable_row
;
10692 /* Give up if there is no row to reuse. */
10693 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10694 || !first_reusable_row
->enabled_p
10695 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10696 != CHARPOS (new_start
)))
10699 /* We can reuse fully visible rows beginning with
10700 first_reusable_row to the end of the window. Set
10701 first_row_to_display to the first row that cannot be reused.
10702 Set pt_row to the row containing point, if there is any. */
10704 for (first_row_to_display
= first_reusable_row
;
10705 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10706 ++first_row_to_display
)
10708 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10709 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10710 pt_row
= first_row_to_display
;
10713 /* Start displaying at the start of first_row_to_display. */
10714 xassert (first_row_to_display
->y
< yb
);
10715 init_to_row_start (&it
, w
, first_row_to_display
);
10717 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10719 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10721 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10722 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10724 /* Display lines beginning with first_row_to_display in the
10725 desired matrix. Set last_text_row to the last row displayed
10726 that displays text. */
10727 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10728 if (pt_row
== NULL
)
10729 w
->cursor
.vpos
= -1;
10730 last_text_row
= NULL
;
10731 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10732 if (display_line (&it
))
10733 last_text_row
= it
.glyph_row
- 1;
10735 /* Give up If point isn't in a row displayed or reused. */
10736 if (w
->cursor
.vpos
< 0)
10738 clear_glyph_matrix (w
->desired_matrix
);
10742 /* If point is in a reused row, adjust y and vpos of the cursor
10746 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10747 w
->current_matrix
);
10748 w
->cursor
.y
-= first_reusable_row
->y
;
10751 /* Scroll the display. */
10752 run
.current_y
= first_reusable_row
->y
;
10753 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10754 run
.height
= it
.last_visible_y
- run
.current_y
;
10755 dy
= run
.current_y
- run
.desired_y
;
10759 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10761 rif
->update_window_begin_hook (w
);
10762 rif
->clear_mouse_face (w
);
10763 rif
->scroll_run_hook (w
, &run
);
10764 rif
->update_window_end_hook (w
, 0, 0);
10768 /* Adjust Y positions of reused rows. */
10769 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10770 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10771 max_y
= it
.last_visible_y
;
10772 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10775 if (row
->y
< min_y
)
10776 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10777 else if (row
->y
+ row
->height
> max_y
)
10778 row
->visible_height
10779 = row
->height
- (row
->y
+ row
->height
- max_y
);
10781 row
->visible_height
= row
->height
;
10784 /* Scroll the current matrix. */
10785 xassert (nrows_scrolled
> 0);
10786 rotate_matrix (w
->current_matrix
,
10788 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10791 /* Disable rows not reused. */
10792 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
10793 row
->enabled_p
= 0;
10795 /* Adjust window end. A null value of last_text_row means that
10796 the window end is in reused rows which in turn means that
10797 only its vpos can have changed. */
10800 w
->window_end_bytepos
10801 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10803 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10805 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10810 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10813 w
->window_end_valid
= Qnil
;
10814 w
->desired_matrix
->no_scrolling_p
= 1;
10817 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10827 /************************************************************************
10828 Window redisplay reusing current matrix when buffer has changed
10829 ************************************************************************/
10831 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10832 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10834 static struct glyph_row
*
10835 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10836 struct glyph_row
*));
10839 /* Return the last row in MATRIX displaying text. If row START is
10840 non-null, start searching with that row. IT gives the dimensions
10841 of the display. Value is null if matrix is empty; otherwise it is
10842 a pointer to the row found. */
10844 static struct glyph_row
*
10845 find_last_row_displaying_text (matrix
, it
, start
)
10846 struct glyph_matrix
*matrix
;
10848 struct glyph_row
*start
;
10850 struct glyph_row
*row
, *row_found
;
10852 /* Set row_found to the last row in IT->w's current matrix
10853 displaying text. The loop looks funny but think of partially
10856 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10857 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10859 xassert (row
->enabled_p
);
10861 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10870 /* Return the last row in the current matrix of W that is not affected
10871 by changes at the start of current_buffer that occurred since W's
10872 current matrix was built. Value is null if no such row exists.
10874 BEG_UNCHANGED us the number of characters unchanged at the start of
10875 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
10876 first changed character in current_buffer. Characters at positions <
10877 BEG + BEG_UNCHANGED are at the same buffer positions as they were
10878 when the current matrix was built. */
10880 static struct glyph_row
*
10881 find_last_unchanged_at_beg_row (w
)
10884 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10885 struct glyph_row
*row
;
10886 struct glyph_row
*row_found
= NULL
;
10887 int yb
= window_text_bottom_y (w
);
10889 /* Find the last row displaying unchanged text. */
10890 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10891 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10892 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10894 if (/* If row ends before first_changed_pos, it is unchanged,
10895 except in some case. */
10896 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10897 /* When row ends in ZV and we write at ZV it is not
10899 && !row
->ends_at_zv_p
10900 /* When first_changed_pos is the end of a continued line,
10901 row is not unchanged because it may be no longer
10903 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10904 && row
->continued_p
))
10907 /* Stop if last visible row. */
10908 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10918 /* Find the first glyph row in the current matrix of W that is not
10919 affected by changes at the end of current_buffer since the
10920 time W's current matrix was built.
10922 Return in *DELTA the number of chars by which buffer positions in
10923 unchanged text at the end of current_buffer must be adjusted.
10925 Return in *DELTA_BYTES the corresponding number of bytes.
10927 Value is null if no such row exists, i.e. all rows are affected by
10930 static struct glyph_row
*
10931 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10933 int *delta
, *delta_bytes
;
10935 struct glyph_row
*row
;
10936 struct glyph_row
*row_found
= NULL
;
10938 *delta
= *delta_bytes
= 0;
10940 /* Display must not have been paused, otherwise the current matrix
10941 is not up to date. */
10942 if (NILP (w
->window_end_valid
))
10945 /* A value of window_end_pos >= END_UNCHANGED means that the window
10946 end is in the range of changed text. If so, there is no
10947 unchanged row at the end of W's current matrix. */
10948 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10951 /* Set row to the last row in W's current matrix displaying text. */
10952 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10954 /* If matrix is entirely empty, no unchanged row exists. */
10955 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10957 /* The value of row is the last glyph row in the matrix having a
10958 meaningful buffer position in it. The end position of row
10959 corresponds to window_end_pos. This allows us to translate
10960 buffer positions in the current matrix to current buffer
10961 positions for characters not in changed text. */
10962 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10963 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10964 int last_unchanged_pos
, last_unchanged_pos_old
;
10965 struct glyph_row
*first_text_row
10966 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10968 *delta
= Z
- Z_old
;
10969 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10971 /* Set last_unchanged_pos to the buffer position of the last
10972 character in the buffer that has not been changed. Z is the
10973 index + 1 of the last character in current_buffer, i.e. by
10974 subtracting END_UNCHANGED we get the index of the last
10975 unchanged character, and we have to add BEG to get its buffer
10977 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10978 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10980 /* Search backward from ROW for a row displaying a line that
10981 starts at a minimum position >= last_unchanged_pos_old. */
10982 for (; row
> first_text_row
; --row
)
10984 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10987 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10992 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
10999 /* Make sure that glyph rows in the current matrix of window W
11000 reference the same glyph memory as corresponding rows in the
11001 frame's frame matrix. This function is called after scrolling W's
11002 current matrix on a terminal frame in try_window_id and
11003 try_window_reusing_current_matrix. */
11006 sync_frame_with_window_matrix_rows (w
)
11009 struct frame
*f
= XFRAME (w
->frame
);
11010 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11012 /* Preconditions: W must be a leaf window and full-width. Its frame
11013 must have a frame matrix. */
11014 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11015 xassert (WINDOW_FULL_WIDTH_P (w
));
11016 xassert (!FRAME_WINDOW_P (f
));
11018 /* If W is a full-width window, glyph pointers in W's current matrix
11019 have, by definition, to be the same as glyph pointers in the
11020 corresponding frame matrix. */
11021 window_row
= w
->current_matrix
->rows
;
11022 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11023 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11024 while (window_row
< window_row_end
)
11028 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11029 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11031 /* Disable frame rows whose corresponding window rows have
11032 been disabled in try_window_id. */
11033 if (!window_row
->enabled_p
)
11034 frame_row
->enabled_p
= 0;
11036 ++window_row
, ++frame_row
;
11041 /* Find the glyph row in window W containing CHARPOS. Consider all
11042 rows between START and END (not inclusive). END null means search
11043 all rows to the end of the display area of W. Value is the row
11044 containing CHARPOS or null. */
11046 static struct glyph_row
*
11047 row_containing_pos (w
, charpos
, start
, end
)
11050 struct glyph_row
*start
, *end
;
11052 struct glyph_row
*row
= start
;
11055 /* If we happen to start on a header-line, skip that. */
11056 if (row
->mode_line_p
)
11059 if ((end
&& row
>= end
) || !row
->enabled_p
)
11062 last_y
= window_text_bottom_y (w
);
11064 while ((end
== NULL
|| row
< end
)
11065 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11066 /* The end position of a row equals the start
11067 position of the next row. If CHARPOS is there, we
11068 would rather display it in the next line, except
11069 when this line ends in ZV. */
11070 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11071 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11072 || !row
->ends_at_zv_p
)))
11073 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11076 /* Give up if CHARPOS not found. */
11077 if ((end
&& row
>= end
)
11078 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11079 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11086 /* Try to redisplay window W by reusing its existing display. W's
11087 current matrix must be up to date when this function is called,
11088 i.e. window_end_valid must not be nil.
11092 1 if display has been updated
11093 0 if otherwise unsuccessful
11094 -1 if redisplay with same window start is known not to succeed
11096 The following steps are performed:
11098 1. Find the last row in the current matrix of W that is not
11099 affected by changes at the start of current_buffer. If no such row
11102 2. Find the first row in W's current matrix that is not affected by
11103 changes at the end of current_buffer. Maybe there is no such row.
11105 3. Display lines beginning with the row + 1 found in step 1 to the
11106 row found in step 2 or, if step 2 didn't find a row, to the end of
11109 4. If cursor is not known to appear on the window, give up.
11111 5. If display stopped at the row found in step 2, scroll the
11112 display and current matrix as needed.
11114 6. Maybe display some lines at the end of W, if we must. This can
11115 happen under various circumstances, like a partially visible line
11116 becoming fully visible, or because newly displayed lines are displayed
11117 in smaller font sizes.
11119 7. Update W's window end information. */
11125 struct frame
*f
= XFRAME (w
->frame
);
11126 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11127 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11128 struct glyph_row
*last_unchanged_at_beg_row
;
11129 struct glyph_row
*first_unchanged_at_end_row
;
11130 struct glyph_row
*row
;
11131 struct glyph_row
*bottom_row
;
11134 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11135 struct text_pos start_pos
;
11137 int first_unchanged_at_end_vpos
= 0;
11138 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11139 struct text_pos start
;
11140 int first_changed_charpos
, last_changed_charpos
;
11142 /* This is handy for debugging. */
11144 #define GIVE_UP(X) \
11146 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11150 #define GIVE_UP(X) return 0
11153 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11155 /* Don't use this for mini-windows because these can show
11156 messages and mini-buffers, and we don't handle that here. */
11157 if (MINI_WINDOW_P (w
))
11160 /* This flag is used to prevent redisplay optimizations. */
11161 if (windows_or_buffers_changed
)
11164 /* Verify that narrowing has not changed. This flag is also set to prevent
11165 redisplay optimizations. It would be nice to further
11166 reduce the number of cases where this prevents try_window_id. */
11167 if (current_buffer
->clip_changed
)
11170 /* Window must either use window-based redisplay or be full width. */
11171 if (!FRAME_WINDOW_P (f
)
11172 && (!line_ins_del_ok
11173 || !WINDOW_FULL_WIDTH_P (w
)))
11176 /* Give up if point is not known NOT to appear in W. */
11177 if (PT
< CHARPOS (start
))
11180 /* Another way to prevent redisplay optimizations. */
11181 if (XFASTINT (w
->last_modified
) == 0)
11184 /* Verify that window is not hscrolled. */
11185 if (XFASTINT (w
->hscroll
) != 0)
11188 /* Verify that display wasn't paused. */
11189 if (NILP (w
->window_end_valid
))
11192 /* Can't use this if highlighting a region because a cursor movement
11193 will do more than just set the cursor. */
11194 if (!NILP (Vtransient_mark_mode
)
11195 && !NILP (current_buffer
->mark_active
))
11198 /* Likewise if highlighting trailing whitespace. */
11199 if (!NILP (Vshow_trailing_whitespace
))
11202 /* Likewise if showing a region. */
11203 if (!NILP (w
->region_showing
))
11206 /* Can use this if overlay arrow position and or string have changed. */
11207 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11208 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11212 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11213 only if buffer has really changed. The reason is that the gap is
11214 initially at Z for freshly visited files. The code below would
11215 set end_unchanged to 0 in that case. */
11216 if (MODIFF
> SAVE_MODIFF
11217 /* This seems to happen sometimes after saving a buffer. */
11218 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11220 if (GPT
- BEG
< BEG_UNCHANGED
)
11221 BEG_UNCHANGED
= GPT
- BEG
;
11222 if (Z
- GPT
< END_UNCHANGED
)
11223 END_UNCHANGED
= Z
- GPT
;
11226 /* The position of the first and last character that has been changed. */
11227 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11228 last_changed_charpos
= Z
- END_UNCHANGED
;
11230 /* If window starts after a line end, and the last change is in
11231 front of that newline, then changes don't affect the display.
11232 This case happens with stealth-fontification. Note that although
11233 the display is unchanged, glyph positions in the matrix have to
11234 be adjusted, of course. */
11235 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11236 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11237 && ((last_changed_charpos
< CHARPOS (start
)
11238 && CHARPOS (start
) == BEGV
)
11239 || (last_changed_charpos
< CHARPOS (start
) - 1
11240 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11242 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11243 struct glyph_row
*r0
;
11245 /* Compute how many chars/bytes have been added to or removed
11246 from the buffer. */
11247 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11248 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11250 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11252 /* Give up if PT is not in the window. Note that it already has
11253 been checked at the start of try_window_id that PT is not in
11254 front of the window start. */
11255 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11258 /* If window start is unchanged, we can reuse the whole matrix
11259 as is, after adjusting glyph positions. No need to compute
11260 the window end again, since its offset from Z hasn't changed. */
11261 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11262 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11263 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11265 /* Adjust positions in the glyph matrix. */
11266 if (delta
|| delta_bytes
)
11268 struct glyph_row
*r1
11269 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11270 increment_matrix_positions (w
->current_matrix
,
11271 MATRIX_ROW_VPOS (r0
, current_matrix
),
11272 MATRIX_ROW_VPOS (r1
, current_matrix
),
11273 delta
, delta_bytes
);
11276 /* Set the cursor. */
11277 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11278 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11283 /* Handle the case that changes are all below what is displayed in
11284 the window, and that PT is in the window. This shortcut cannot
11285 be taken if ZV is visible in the window, and text has been added
11286 there that is visible in the window. */
11287 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11288 /* ZV is not visible in the window, or there are no
11289 changes at ZV, actually. */
11290 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11291 || first_changed_charpos
== last_changed_charpos
))
11293 struct glyph_row
*r0
;
11295 /* Give up if PT is not in the window. Note that it already has
11296 been checked at the start of try_window_id that PT is not in
11297 front of the window start. */
11298 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11301 /* If window start is unchanged, we can reuse the whole matrix
11302 as is, without changing glyph positions since no text has
11303 been added/removed in front of the window end. */
11304 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11305 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11307 /* We have to compute the window end anew since text
11308 can have been added/removed after it. */
11310 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11311 w
->window_end_bytepos
11312 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11314 /* Set the cursor. */
11315 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11316 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11321 /* Give up if window start is in the changed area.
11323 The condition used to read
11325 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11327 but why that was tested escapes me at the moment. */
11328 if (CHARPOS (start
) >= first_changed_charpos
11329 && CHARPOS (start
) <= last_changed_charpos
)
11332 /* Check that window start agrees with the start of the first glyph
11333 row in its current matrix. Check this after we know the window
11334 start is not in changed text, otherwise positions would not be
11336 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11337 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11340 /* Compute the position at which we have to start displaying new
11341 lines. Some of the lines at the top of the window might be
11342 reusable because they are not displaying changed text. Find the
11343 last row in W's current matrix not affected by changes at the
11344 start of current_buffer. Value is null if changes start in the
11345 first line of window. */
11346 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11347 if (last_unchanged_at_beg_row
)
11349 /* Avoid starting to display in the moddle of a character, a TAB
11350 for instance. This is easier than to set up the iterator
11351 exactly, and it's not a frequent case, so the additional
11352 effort wouldn't really pay off. */
11353 while (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11354 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11355 --last_unchanged_at_beg_row
;
11357 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11360 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
11361 start_pos
= it
.current
.pos
;
11363 /* Start displaying new lines in the desired matrix at the same
11364 vpos we would use in the current matrix, i.e. below
11365 last_unchanged_at_beg_row. */
11366 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11368 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11369 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11371 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11375 /* There are no reusable lines at the start of the window.
11376 Start displaying in the first line. */
11377 start_display (&it
, w
, start
);
11378 start_pos
= it
.current
.pos
;
11381 /* Find the first row that is not affected by changes at the end of
11382 the buffer. Value will be null if there is no unchanged row, in
11383 which case we must redisplay to the end of the window. delta
11384 will be set to the value by which buffer positions beginning with
11385 first_unchanged_at_end_row have to be adjusted due to text
11387 first_unchanged_at_end_row
11388 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11389 IF_DEBUG (debug_delta
= delta
);
11390 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11392 /* Set stop_pos to the buffer position up to which we will have to
11393 display new lines. If first_unchanged_at_end_row != NULL, this
11394 is the buffer position of the start of the line displayed in that
11395 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11396 that we don't stop at a buffer position. */
11398 if (first_unchanged_at_end_row
)
11400 xassert (last_unchanged_at_beg_row
== NULL
11401 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11403 /* If this is a continuation line, move forward to the next one
11404 that isn't. Changes in lines above affect this line.
11405 Caution: this may move first_unchanged_at_end_row to a row
11406 not displaying text. */
11407 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11408 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11409 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11410 < it
.last_visible_y
))
11411 ++first_unchanged_at_end_row
;
11413 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11414 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11415 >= it
.last_visible_y
))
11416 first_unchanged_at_end_row
= NULL
;
11419 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11421 first_unchanged_at_end_vpos
11422 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11423 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11426 else if (last_unchanged_at_beg_row
== NULL
)
11432 /* Either there is no unchanged row at the end, or the one we have
11433 now displays text. This is a necessary condition for the window
11434 end pos calculation at the end of this function. */
11435 xassert (first_unchanged_at_end_row
== NULL
11436 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11438 debug_last_unchanged_at_beg_vpos
11439 = (last_unchanged_at_beg_row
11440 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11442 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11444 #endif /* GLYPH_DEBUG != 0 */
11447 /* Display new lines. Set last_text_row to the last new line
11448 displayed which has text on it, i.e. might end up as being the
11449 line where the window_end_vpos is. */
11450 w
->cursor
.vpos
= -1;
11451 last_text_row
= NULL
;
11452 overlay_arrow_seen
= 0;
11453 while (it
.current_y
< it
.last_visible_y
11454 && !fonts_changed_p
11455 && (first_unchanged_at_end_row
== NULL
11456 || IT_CHARPOS (it
) < stop_pos
))
11458 if (display_line (&it
))
11459 last_text_row
= it
.glyph_row
- 1;
11462 if (fonts_changed_p
)
11466 /* Compute differences in buffer positions, y-positions etc. for
11467 lines reused at the bottom of the window. Compute what we can
11469 if (first_unchanged_at_end_row
11470 /* No lines reused because we displayed everything up to the
11471 bottom of the window. */
11472 && it
.current_y
< it
.last_visible_y
)
11475 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11477 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11478 run
.current_y
= first_unchanged_at_end_row
->y
;
11479 run
.desired_y
= run
.current_y
+ dy
;
11480 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11484 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11485 first_unchanged_at_end_row
= NULL
;
11487 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11490 /* Find the cursor if not already found. We have to decide whether
11491 PT will appear on this window (it sometimes doesn't, but this is
11492 not a very frequent case.) This decision has to be made before
11493 the current matrix is altered. A value of cursor.vpos < 0 means
11494 that PT is either in one of the lines beginning at
11495 first_unchanged_at_end_row or below the window. Don't care for
11496 lines that might be displayed later at the window end; as
11497 mentioned, this is not a frequent case. */
11498 if (w
->cursor
.vpos
< 0)
11500 /* Cursor in unchanged rows at the top? */
11501 if (PT
< CHARPOS (start_pos
)
11502 && last_unchanged_at_beg_row
)
11504 row
= row_containing_pos (w
, PT
,
11505 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11506 last_unchanged_at_beg_row
+ 1);
11508 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11511 /* Start from first_unchanged_at_end_row looking for PT. */
11512 else if (first_unchanged_at_end_row
)
11514 row
= row_containing_pos (w
, PT
- delta
,
11515 first_unchanged_at_end_row
, NULL
);
11517 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11518 delta_bytes
, dy
, dvpos
);
11521 /* Give up if cursor was not found. */
11522 if (w
->cursor
.vpos
< 0)
11524 clear_glyph_matrix (w
->desired_matrix
);
11529 /* Don't let the cursor end in the scroll margins. */
11531 int this_scroll_margin
, cursor_height
;
11533 this_scroll_margin
= max (0, scroll_margin
);
11534 this_scroll_margin
= min (this_scroll_margin
,
11535 XFASTINT (w
->height
) / 4);
11536 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11537 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11539 if ((w
->cursor
.y
< this_scroll_margin
11540 && CHARPOS (start
) > BEGV
)
11541 /* Don't take scroll margin into account at the bottom because
11542 old redisplay didn't do it either. */
11543 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11545 w
->cursor
.vpos
= -1;
11546 clear_glyph_matrix (w
->desired_matrix
);
11551 /* Scroll the display. Do it before changing the current matrix so
11552 that xterm.c doesn't get confused about where the cursor glyph is
11554 if (dy
&& run
.height
)
11558 if (FRAME_WINDOW_P (f
))
11560 rif
->update_window_begin_hook (w
);
11561 rif
->clear_mouse_face (w
);
11562 rif
->scroll_run_hook (w
, &run
);
11563 rif
->update_window_end_hook (w
, 0, 0);
11567 /* Terminal frame. In this case, dvpos gives the number of
11568 lines to scroll by; dvpos < 0 means scroll up. */
11569 int first_unchanged_at_end_vpos
11570 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11571 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11572 int end
= (XFASTINT (w
->top
)
11573 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11574 + window_internal_height (w
));
11576 /* Perform the operation on the screen. */
11579 /* Scroll last_unchanged_at_beg_row to the end of the
11580 window down dvpos lines. */
11581 set_terminal_window (end
);
11583 /* On dumb terminals delete dvpos lines at the end
11584 before inserting dvpos empty lines. */
11585 if (!scroll_region_ok
)
11586 ins_del_lines (end
- dvpos
, -dvpos
);
11588 /* Insert dvpos empty lines in front of
11589 last_unchanged_at_beg_row. */
11590 ins_del_lines (from
, dvpos
);
11592 else if (dvpos
< 0)
11594 /* Scroll up last_unchanged_at_beg_vpos to the end of
11595 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11596 set_terminal_window (end
);
11598 /* Delete dvpos lines in front of
11599 last_unchanged_at_beg_vpos. ins_del_lines will set
11600 the cursor to the given vpos and emit |dvpos| delete
11602 ins_del_lines (from
+ dvpos
, dvpos
);
11604 /* On a dumb terminal insert dvpos empty lines at the
11606 if (!scroll_region_ok
)
11607 ins_del_lines (end
+ dvpos
, -dvpos
);
11610 set_terminal_window (0);
11616 /* Shift reused rows of the current matrix to the right position.
11617 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11619 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11620 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11623 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11624 bottom_vpos
, dvpos
);
11625 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11628 else if (dvpos
> 0)
11630 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11631 bottom_vpos
, dvpos
);
11632 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11633 first_unchanged_at_end_vpos
+ dvpos
, 0);
11636 /* For frame-based redisplay, make sure that current frame and window
11637 matrix are in sync with respect to glyph memory. */
11638 if (!FRAME_WINDOW_P (f
))
11639 sync_frame_with_window_matrix_rows (w
);
11641 /* Adjust buffer positions in reused rows. */
11643 increment_matrix_positions (current_matrix
,
11644 first_unchanged_at_end_vpos
+ dvpos
,
11645 bottom_vpos
, delta
, delta_bytes
);
11647 /* Adjust Y positions. */
11649 shift_glyph_matrix (w
, current_matrix
,
11650 first_unchanged_at_end_vpos
+ dvpos
,
11653 if (first_unchanged_at_end_row
)
11654 first_unchanged_at_end_row
+= dvpos
;
11656 /* If scrolling up, there may be some lines to display at the end of
11658 last_text_row_at_end
= NULL
;
11661 /* Set last_row to the glyph row in the current matrix where the
11662 window end line is found. It has been moved up or down in
11663 the matrix by dvpos. */
11664 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11665 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11667 /* If last_row is the window end line, it should display text. */
11668 xassert (last_row
->displays_text_p
);
11670 /* If window end line was partially visible before, begin
11671 displaying at that line. Otherwise begin displaying with the
11672 line following it. */
11673 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11675 init_to_row_start (&it
, w
, last_row
);
11676 it
.vpos
= last_vpos
;
11677 it
.current_y
= last_row
->y
;
11681 init_to_row_end (&it
, w
, last_row
);
11682 it
.vpos
= 1 + last_vpos
;
11683 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11687 /* We may start in a continuation line. If so, we have to get
11688 the right continuation_lines_width and current_x. */
11689 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11690 it
.hpos
= it
.current_x
= 0;
11692 /* Display the rest of the lines at the window end. */
11693 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11694 while (it
.current_y
< it
.last_visible_y
11695 && !fonts_changed_p
)
11697 /* Is it always sure that the display agrees with lines in
11698 the current matrix? I don't think so, so we mark rows
11699 displayed invalid in the current matrix by setting their
11700 enabled_p flag to zero. */
11701 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11702 if (display_line (&it
))
11703 last_text_row_at_end
= it
.glyph_row
- 1;
11707 /* Update window_end_pos and window_end_vpos. */
11708 if (first_unchanged_at_end_row
11709 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11710 && !last_text_row_at_end
)
11712 /* Window end line if one of the preserved rows from the current
11713 matrix. Set row to the last row displaying text in current
11714 matrix starting at first_unchanged_at_end_row, after
11716 xassert (first_unchanged_at_end_row
->displays_text_p
);
11717 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11718 first_unchanged_at_end_row
);
11719 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11721 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11722 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11724 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11725 xassert (w
->window_end_bytepos
>= 0);
11726 IF_DEBUG (debug_method_add (w
, "A"));
11728 else if (last_text_row_at_end
)
11731 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11732 w
->window_end_bytepos
11733 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11735 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11736 xassert (w
->window_end_bytepos
>= 0);
11737 IF_DEBUG (debug_method_add (w
, "B"));
11739 else if (last_text_row
)
11741 /* We have displayed either to the end of the window or at the
11742 end of the window, i.e. the last row with text is to be found
11743 in the desired matrix. */
11745 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11746 w
->window_end_bytepos
11747 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11749 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11750 xassert (w
->window_end_bytepos
>= 0);
11752 else if (first_unchanged_at_end_row
== NULL
11753 && last_text_row
== NULL
11754 && last_text_row_at_end
== NULL
)
11756 /* Displayed to end of window, but no line containing text was
11757 displayed. Lines were deleted at the end of the window. */
11758 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11759 int vpos
= XFASTINT (w
->window_end_vpos
);
11760 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
11761 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
11764 row
== NULL
&& vpos
>= first_vpos
;
11765 --vpos
, --current_row
, --desired_row
)
11767 if (desired_row
->enabled_p
)
11769 if (desired_row
->displays_text_p
)
11772 else if (current_row
->displays_text_p
)
11776 xassert (row
!= NULL
);
11777 w
->window_end_vpos
= make_number (vpos
+ 1);
11778 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11779 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11780 xassert (w
->window_end_bytepos
>= 0);
11781 IF_DEBUG (debug_method_add (w
, "C"));
11786 #if 0 /* This leads to problems, for instance when the cursor is
11787 at ZV, and the cursor line displays no text. */
11788 /* Disable rows below what's displayed in the window. This makes
11789 debugging easier. */
11790 enable_glyph_matrix_rows (current_matrix
,
11791 XFASTINT (w
->window_end_vpos
) + 1,
11795 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11796 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11798 /* Record that display has not been completed. */
11799 w
->window_end_valid
= Qnil
;
11800 w
->desired_matrix
->no_scrolling_p
= 1;
11808 /***********************************************************************
11809 More debugging support
11810 ***********************************************************************/
11814 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11815 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11816 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
11819 /* Dump the contents of glyph matrix MATRIX on stderr.
11821 GLYPHS 0 means don't show glyph contents.
11822 GLYPHS 1 means show glyphs in short form
11823 GLYPHS > 1 means show glyphs in long form. */
11826 dump_glyph_matrix (matrix
, glyphs
)
11827 struct glyph_matrix
*matrix
;
11831 for (i
= 0; i
< matrix
->nrows
; ++i
)
11832 dump_glyph_row (matrix
, i
, glyphs
);
11836 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
11837 the glyph row and area where the glyph comes from. */
11840 dump_glyph (row
, glyph
, area
)
11841 struct glyph_row
*row
;
11842 struct glyph
*glyph
;
11845 if (glyph
->type
== CHAR_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
,
11859 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11863 glyph
->left_box_line_p
,
11864 glyph
->right_box_line_p
);
11866 else if (glyph
->type
== STRETCH_GLYPH
)
11869 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11870 glyph
- row
->glyphs
[TEXT_AREA
],
11873 (BUFFERP (glyph
->object
)
11875 : (STRINGP (glyph
->object
)
11878 glyph
->pixel_width
,
11882 glyph
->left_box_line_p
,
11883 glyph
->right_box_line_p
);
11885 else if (glyph
->type
== IMAGE_GLYPH
)
11888 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11889 glyph
- row
->glyphs
[TEXT_AREA
],
11892 (BUFFERP (glyph
->object
)
11894 : (STRINGP (glyph
->object
)
11897 glyph
->pixel_width
,
11901 glyph
->left_box_line_p
,
11902 glyph
->right_box_line_p
);
11907 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11908 GLYPHS 0 means don't show glyph contents.
11909 GLYPHS 1 means show glyphs in short form
11910 GLYPHS > 1 means show glyphs in long form. */
11913 dump_glyph_row (matrix
, vpos
, glyphs
)
11914 struct glyph_matrix
*matrix
;
11917 struct glyph_row
*row
;
11919 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11922 row
= MATRIX_ROW (matrix
, vpos
);
11926 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
11927 fprintf (stderr
, "=======================================================================\n");
11929 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11930 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11931 row
- matrix
->rows
,
11932 MATRIX_ROW_START_CHARPOS (row
),
11933 MATRIX_ROW_END_CHARPOS (row
),
11934 row
->used
[TEXT_AREA
],
11935 row
->contains_overlapping_glyphs_p
,
11938 row
->truncated_on_left_p
,
11939 row
->truncated_on_right_p
,
11940 row
->overlay_arrow_p
,
11942 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11943 row
->displays_text_p
,
11946 row
->ends_in_middle_of_char_p
,
11947 row
->starts_in_middle_of_char_p
,
11953 row
->visible_height
,
11956 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
11957 row
->end
.overlay_string_index
,
11958 row
->continuation_lines_width
);
11959 fprintf (stderr
, "%9d %5d\n",
11960 CHARPOS (row
->start
.string_pos
),
11961 CHARPOS (row
->end
.string_pos
));
11962 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
11963 row
->end
.dpvec_index
);
11970 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11972 struct glyph
*glyph
= row
->glyphs
[area
];
11973 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
11975 /* Glyph for a line end in text. */
11976 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
11979 if (glyph
< glyph_end
)
11980 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11982 for (; glyph
< glyph_end
; ++glyph
)
11983 dump_glyph (row
, glyph
, area
);
11986 else if (glyphs
== 1)
11990 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11992 char *s
= (char *) alloca (row
->used
[area
] + 1);
11995 for (i
= 0; i
< row
->used
[area
]; ++i
)
11997 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
11998 if (glyph
->type
== CHAR_GLYPH
11999 && glyph
->u
.ch
< 0x80
12000 && glyph
->u
.ch
>= ' ')
12001 s
[i
] = glyph
->u
.ch
;
12007 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12013 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12014 Sdump_glyph_matrix
, 0, 1, "p",
12015 "Dump the current matrix of the selected window to stderr.\n\
12016 Shows contents of glyph row structures. With non-nil\n\
12017 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show\n\
12018 glyphs in short form, otherwise show glyphs in long form.")
12020 Lisp_Object glyphs
;
12022 struct window
*w
= XWINDOW (selected_window
);
12023 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12025 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12026 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12027 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12028 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12029 fprintf (stderr
, "=============================================\n");
12030 dump_glyph_matrix (w
->current_matrix
,
12031 NILP (glyphs
) ? 0 : XINT (glyphs
));
12036 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12037 "Dump glyph row ROW to stderr.\n\
12038 GLYPH 0 means don't dump glyphs.\n\
12039 GLYPH 1 means dump glyphs in short form.\n\
12040 GLYPH > 1 or omitted means dump glyphs in long form.")
12042 Lisp_Object row
, glyphs
;
12044 CHECK_NUMBER (row
, 0);
12045 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
,
12047 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12052 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12053 "Dump glyph row ROW of the tool-bar of the current frame to stderr.\n\
12054 GLYPH 0 means don't dump glyphs.\n\
12055 GLYPH 1 means dump glyphs in short form.\n\
12056 GLYPH > 1 or omitted means dump glyphs in long form.")
12058 Lisp_Object row
, glyphs
;
12060 struct frame
*sf
= SELECTED_FRAME ();
12061 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)->current_matrix
);
12062 dump_glyph_row (m
, XINT (row
), INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12067 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12068 "Toggle tracing of redisplay.\n\
12069 With ARG, turn tracing on if and only if ARG is positive.")
12074 trace_redisplay_p
= !trace_redisplay_p
;
12077 arg
= Fprefix_numeric_value (arg
);
12078 trace_redisplay_p
= XINT (arg
) > 0;
12085 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
12086 "Print STRING to stderr.")
12088 Lisp_Object string
;
12090 CHECK_STRING (string
, 0);
12091 fprintf (stderr
, "%s", XSTRING (string
)->data
);
12095 #endif /* GLYPH_DEBUG */
12099 /***********************************************************************
12100 Building Desired Matrix Rows
12101 ***********************************************************************/
12103 /* Return a temporary glyph row holding the glyphs of an overlay
12104 arrow. Only used for non-window-redisplay windows. */
12106 static struct glyph_row
*
12107 get_overlay_arrow_glyph_row (w
)
12110 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12111 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12112 struct buffer
*old
= current_buffer
;
12113 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
12114 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
12115 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12119 int n_glyphs_before
;
12121 set_buffer_temp (buffer
);
12122 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12123 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12124 SET_TEXT_POS (it
.position
, 0, 0);
12126 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12128 while (p
< arrow_end
)
12130 Lisp_Object face
, ilisp
;
12132 /* Get the next character. */
12134 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12136 it
.c
= *p
, it
.len
= 1;
12139 /* Get its face. */
12140 ilisp
= make_number (p
- arrow_string
);
12141 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12142 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12144 /* Compute its width, get its glyphs. */
12145 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12146 SET_TEXT_POS (it
.position
, -1, -1);
12147 PRODUCE_GLYPHS (&it
);
12149 /* If this character doesn't fit any more in the line, we have
12150 to remove some glyphs. */
12151 if (it
.current_x
> it
.last_visible_x
)
12153 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12158 set_buffer_temp (old
);
12159 return it
.glyph_row
;
12163 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12164 glyphs are only inserted for terminal frames since we can't really
12165 win with truncation glyphs when partially visible glyphs are
12166 involved. Which glyphs to insert is determined by
12167 produce_special_glyphs. */
12170 insert_left_trunc_glyphs (it
)
12173 struct it truncate_it
;
12174 struct glyph
*from
, *end
, *to
, *toend
;
12176 xassert (!FRAME_WINDOW_P (it
->f
));
12178 /* Get the truncation glyphs. */
12180 truncate_it
.current_x
= 0;
12181 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12182 truncate_it
.glyph_row
= &scratch_glyph_row
;
12183 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12184 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12185 truncate_it
.object
= make_number (0);
12186 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12188 /* Overwrite glyphs from IT with truncation glyphs. */
12189 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12190 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12191 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12192 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12197 /* There may be padding glyphs left over. Overwrite them too. */
12198 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12200 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12206 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12210 /* Compute the pixel height and width of IT->glyph_row.
12212 Most of the time, ascent and height of a display line will be equal
12213 to the max_ascent and max_height values of the display iterator
12214 structure. This is not the case if
12216 1. We hit ZV without displaying anything. In this case, max_ascent
12217 and max_height will be zero.
12219 2. We have some glyphs that don't contribute to the line height.
12220 (The glyph row flag contributes_to_line_height_p is for future
12221 pixmap extensions).
12223 The first case is easily covered by using default values because in
12224 these cases, the line height does not really matter, except that it
12225 must not be zero. */
12228 compute_line_metrics (it
)
12231 struct glyph_row
*row
= it
->glyph_row
;
12234 if (FRAME_WINDOW_P (it
->f
))
12236 int i
, header_line_height
;
12238 /* The line may consist of one space only, that was added to
12239 place the cursor on it. If so, the row's height hasn't been
12241 if (row
->height
== 0)
12243 if (it
->max_ascent
+ it
->max_descent
== 0)
12244 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12245 row
->ascent
= it
->max_ascent
;
12246 row
->height
= it
->max_ascent
+ it
->max_descent
;
12247 row
->phys_ascent
= it
->max_phys_ascent
;
12248 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12251 /* Compute the width of this line. */
12252 row
->pixel_width
= row
->x
;
12253 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12254 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12256 xassert (row
->pixel_width
>= 0);
12257 xassert (row
->ascent
>= 0 && row
->height
> 0);
12259 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12260 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12262 /* If first line's physical ascent is larger than its logical
12263 ascent, use the physical ascent, and make the row taller.
12264 This makes accented characters fully visible. */
12265 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12266 && row
->phys_ascent
> row
->ascent
)
12268 row
->height
+= row
->phys_ascent
- row
->ascent
;
12269 row
->ascent
= row
->phys_ascent
;
12272 /* Compute how much of the line is visible. */
12273 row
->visible_height
= row
->height
;
12275 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12276 if (row
->y
< header_line_height
)
12277 row
->visible_height
-= header_line_height
- row
->y
;
12280 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12281 if (row
->y
+ row
->height
> max_y
)
12282 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12287 row
->pixel_width
= row
->used
[TEXT_AREA
];
12288 if (row
->continued_p
)
12289 row
->pixel_width
-= it
->continuation_pixel_width
;
12290 else if (row
->truncated_on_right_p
)
12291 row
->pixel_width
-= it
->truncation_pixel_width
;
12292 row
->ascent
= row
->phys_ascent
= 0;
12293 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12296 /* Compute a hash code for this row. */
12298 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12299 for (i
= 0; i
< row
->used
[area
]; ++i
)
12300 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12301 + row
->glyphs
[area
][i
].u
.val
12302 + row
->glyphs
[area
][i
].face_id
12303 + row
->glyphs
[area
][i
].padding_p
12304 + (row
->glyphs
[area
][i
].type
<< 2));
12306 it
->max_ascent
= it
->max_descent
= 0;
12307 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12311 /* Append one space to the glyph row of iterator IT if doing a
12312 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12313 space have the default face, otherwise let it have the same face as
12314 IT->face_id. Value is non-zero if a space was added.
12316 This function is called to make sure that there is always one glyph
12317 at the end of a glyph row that the cursor can be set on under
12318 window-systems. (If there weren't such a glyph we would not know
12319 how wide and tall a box cursor should be displayed).
12321 At the same time this space let's a nicely handle clearing to the
12322 end of the line if the row ends in italic text. */
12325 append_space (it
, default_face_p
)
12327 int default_face_p
;
12329 if (FRAME_WINDOW_P (it
->f
))
12331 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12333 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12334 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12336 /* Save some values that must not be changed.
12337 Must save IT->c and IT->len because otherwise
12338 ITERATOR_AT_END_P wouldn't work anymore after
12339 append_space has been called. */
12340 enum display_element_type saved_what
= it
->what
;
12341 int saved_c
= it
->c
, saved_len
= it
->len
;
12342 int saved_x
= it
->current_x
;
12343 int saved_face_id
= it
->face_id
;
12344 struct text_pos saved_pos
;
12345 Lisp_Object saved_object
;
12348 saved_object
= it
->object
;
12349 saved_pos
= it
->position
;
12351 it
->what
= IT_CHARACTER
;
12352 bzero (&it
->position
, sizeof it
->position
);
12353 it
->object
= make_number (0);
12357 if (default_face_p
)
12358 it
->face_id
= DEFAULT_FACE_ID
;
12359 else if (it
->face_before_selective_p
)
12360 it
->face_id
= it
->saved_face_id
;
12361 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12362 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12364 PRODUCE_GLYPHS (it
);
12366 it
->current_x
= saved_x
;
12367 it
->object
= saved_object
;
12368 it
->position
= saved_pos
;
12369 it
->what
= saved_what
;
12370 it
->face_id
= saved_face_id
;
12371 it
->len
= saved_len
;
12381 /* Extend the face of the last glyph in the text area of IT->glyph_row
12382 to the end of the display line. Called from display_line.
12383 If the glyph row is empty, add a space glyph to it so that we
12384 know the face to draw. Set the glyph row flag fill_line_p. */
12387 extend_face_to_end_of_line (it
)
12391 struct frame
*f
= it
->f
;
12393 /* If line is already filled, do nothing. */
12394 if (it
->current_x
>= it
->last_visible_x
)
12397 /* Face extension extends the background and box of IT->face_id
12398 to the end of the line. If the background equals the background
12399 of the frame, we don't have to do anything. */
12400 if (it
->face_before_selective_p
)
12401 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12403 face
= FACE_FROM_ID (f
, it
->face_id
);
12405 if (FRAME_WINDOW_P (f
)
12406 && face
->box
== FACE_NO_BOX
12407 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12411 /* Set the glyph row flag indicating that the face of the last glyph
12412 in the text area has to be drawn to the end of the text area. */
12413 it
->glyph_row
->fill_line_p
= 1;
12415 /* If current character of IT is not ASCII, make sure we have the
12416 ASCII face. This will be automatically undone the next time
12417 get_next_display_element returns a multibyte character. Note
12418 that the character will always be single byte in unibyte text. */
12419 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12421 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12424 if (FRAME_WINDOW_P (f
))
12426 /* If the row is empty, add a space with the current face of IT,
12427 so that we know which face to draw. */
12428 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12430 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12431 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12432 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12437 /* Save some values that must not be changed. */
12438 int saved_x
= it
->current_x
;
12439 struct text_pos saved_pos
;
12440 Lisp_Object saved_object
;
12441 enum display_element_type saved_what
= it
->what
;
12442 int saved_face_id
= it
->face_id
;
12444 saved_object
= it
->object
;
12445 saved_pos
= it
->position
;
12447 it
->what
= IT_CHARACTER
;
12448 bzero (&it
->position
, sizeof it
->position
);
12449 it
->object
= make_number (0);
12452 it
->face_id
= face
->id
;
12454 PRODUCE_GLYPHS (it
);
12456 while (it
->current_x
<= it
->last_visible_x
)
12457 PRODUCE_GLYPHS (it
);
12459 /* Don't count these blanks really. It would let us insert a left
12460 truncation glyph below and make us set the cursor on them, maybe. */
12461 it
->current_x
= saved_x
;
12462 it
->object
= saved_object
;
12463 it
->position
= saved_pos
;
12464 it
->what
= saved_what
;
12465 it
->face_id
= saved_face_id
;
12470 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12471 trailing whitespace. */
12474 trailing_whitespace_p (charpos
)
12477 int bytepos
= CHAR_TO_BYTE (charpos
);
12480 while (bytepos
< ZV_BYTE
12481 && (c
= FETCH_CHAR (bytepos
),
12482 c
== ' ' || c
== '\t'))
12485 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12487 if (bytepos
!= PT_BYTE
)
12494 /* Highlight trailing whitespace, if any, in ROW. */
12497 highlight_trailing_whitespace (f
, row
)
12499 struct glyph_row
*row
;
12501 int used
= row
->used
[TEXT_AREA
];
12505 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12506 struct glyph
*glyph
= start
+ used
- 1;
12508 /* Skip over glyphs inserted to display the cursor at the
12509 end of a line, for extending the face of the last glyph
12510 to the end of the line on terminals, and for truncation
12511 and continuation glyphs. */
12512 while (glyph
>= start
12513 && glyph
->type
== CHAR_GLYPH
12514 && INTEGERP (glyph
->object
))
12517 /* If last glyph is a space or stretch, and it's trailing
12518 whitespace, set the face of all trailing whitespace glyphs in
12519 IT->glyph_row to `trailing-whitespace'. */
12521 && BUFFERP (glyph
->object
)
12522 && (glyph
->type
== STRETCH_GLYPH
12523 || (glyph
->type
== CHAR_GLYPH
12524 && glyph
->u
.ch
== ' '))
12525 && trailing_whitespace_p (glyph
->charpos
))
12527 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12529 while (glyph
>= start
12530 && BUFFERP (glyph
->object
)
12531 && (glyph
->type
== STRETCH_GLYPH
12532 || (glyph
->type
== CHAR_GLYPH
12533 && glyph
->u
.ch
== ' ')))
12534 (glyph
--)->face_id
= face_id
;
12540 /* Value is non-zero if glyph row ROW in window W should be
12541 used to hold the cursor. */
12544 cursor_row_p (w
, row
)
12546 struct glyph_row
*row
;
12548 int cursor_row_p
= 1;
12550 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12552 /* If the row ends with a newline from a string, we don't want
12553 the cursor there (if the row is continued it doesn't end in a
12555 if (CHARPOS (row
->end
.string_pos
) >= 0
12556 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12557 cursor_row_p
= row
->continued_p
;
12559 /* If the row ends at ZV, display the cursor at the end of that
12560 row instead of at the start of the row below. */
12561 else if (row
->ends_at_zv_p
)
12567 return cursor_row_p
;
12571 /* Construct the glyph row IT->glyph_row in the desired matrix of
12572 IT->w from text at the current position of IT. See dispextern.h
12573 for an overview of struct it. Value is non-zero if
12574 IT->glyph_row displays text, as opposed to a line displaying ZV
12581 struct glyph_row
*row
= it
->glyph_row
;
12583 /* We always start displaying at hpos zero even if hscrolled. */
12584 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12586 /* We must not display in a row that's not a text row. */
12587 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12588 < it
->w
->desired_matrix
->nrows
);
12590 /* Is IT->w showing the region? */
12591 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12593 /* Clear the result glyph row and enable it. */
12594 prepare_desired_row (row
);
12596 row
->y
= it
->current_y
;
12597 row
->start
= it
->current
;
12598 row
->continuation_lines_width
= it
->continuation_lines_width
;
12599 row
->displays_text_p
= 1;
12600 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12601 it
->starts_in_middle_of_char_p
= 0;
12603 /* Arrange the overlays nicely for our purposes. Usually, we call
12604 display_line on only one line at a time, in which case this
12605 can't really hurt too much, or we call it on lines which appear
12606 one after another in the buffer, in which case all calls to
12607 recenter_overlay_lists but the first will be pretty cheap. */
12608 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12610 /* Move over display elements that are not visible because we are
12611 hscrolled. This may stop at an x-position < IT->first_visible_x
12612 if the first glyph is partially visible or if we hit a line end. */
12613 if (it
->current_x
< it
->first_visible_x
)
12614 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12615 MOVE_TO_POS
| MOVE_TO_X
);
12617 /* Get the initial row height. This is either the height of the
12618 text hscrolled, if there is any, or zero. */
12619 row
->ascent
= it
->max_ascent
;
12620 row
->height
= it
->max_ascent
+ it
->max_descent
;
12621 row
->phys_ascent
= it
->max_phys_ascent
;
12622 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12624 /* Loop generating characters. The loop is left with IT on the next
12625 character to display. */
12628 int n_glyphs_before
, hpos_before
, x_before
;
12630 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12632 /* Retrieve the next thing to display. Value is zero if end of
12634 if (!get_next_display_element (it
))
12636 /* Maybe add a space at the end of this line that is used to
12637 display the cursor there under X. Set the charpos of the
12638 first glyph of blank lines not corresponding to any text
12640 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12641 || row
->used
[TEXT_AREA
] == 0)
12643 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12644 row
->displays_text_p
= 0;
12646 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
12647 row
->indicate_empty_line_p
= 1;
12650 it
->continuation_lines_width
= 0;
12651 row
->ends_at_zv_p
= 1;
12655 /* Now, get the metrics of what we want to display. This also
12656 generates glyphs in `row' (which is IT->glyph_row). */
12657 n_glyphs_before
= row
->used
[TEXT_AREA
];
12660 /* Remember the line height so far in case the next element doesn't
12661 fit on the line. */
12662 if (!it
->truncate_lines_p
)
12664 ascent
= it
->max_ascent
;
12665 descent
= it
->max_descent
;
12666 phys_ascent
= it
->max_phys_ascent
;
12667 phys_descent
= it
->max_phys_descent
;
12670 PRODUCE_GLYPHS (it
);
12672 /* If this display element was in marginal areas, continue with
12674 if (it
->area
!= TEXT_AREA
)
12676 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12677 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12678 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12679 row
->phys_height
= max (row
->phys_height
,
12680 it
->max_phys_ascent
+ it
->max_phys_descent
);
12681 set_iterator_to_next (it
, 1);
12685 /* Does the display element fit on the line? If we truncate
12686 lines, we should draw past the right edge of the window. If
12687 we don't truncate, we want to stop so that we can display the
12688 continuation glyph before the right margin. If lines are
12689 continued, there are two possible strategies for characters
12690 resulting in more than 1 glyph (e.g. tabs): Display as many
12691 glyphs as possible in this line and leave the rest for the
12692 continuation line, or display the whole element in the next
12693 line. Original redisplay did the former, so we do it also. */
12694 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12695 hpos_before
= it
->hpos
;
12698 if (/* Not a newline. */
12700 /* Glyphs produced fit entirely in the line. */
12701 && it
->current_x
< it
->last_visible_x
)
12703 it
->hpos
+= nglyphs
;
12704 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12705 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12706 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12707 row
->phys_height
= max (row
->phys_height
,
12708 it
->max_phys_ascent
+ it
->max_phys_descent
);
12709 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12710 row
->x
= x
- it
->first_visible_x
;
12715 struct glyph
*glyph
;
12717 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12719 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12720 new_x
= x
+ glyph
->pixel_width
;
12722 if (/* Lines are continued. */
12723 !it
->truncate_lines_p
12724 && (/* Glyph doesn't fit on the line. */
12725 new_x
> it
->last_visible_x
12726 /* Or it fits exactly on a window system frame. */
12727 || (new_x
== it
->last_visible_x
12728 && FRAME_WINDOW_P (it
->f
))))
12730 /* End of a continued line. */
12733 || (new_x
== it
->last_visible_x
12734 && FRAME_WINDOW_P (it
->f
)))
12736 /* Current glyph is the only one on the line or
12737 fits exactly on the line. We must continue
12738 the line because we can't draw the cursor
12739 after the glyph. */
12740 row
->continued_p
= 1;
12741 it
->current_x
= new_x
;
12742 it
->continuation_lines_width
+= new_x
;
12744 if (i
== nglyphs
- 1)
12745 set_iterator_to_next (it
, 1);
12747 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12748 && !FRAME_WINDOW_P (it
->f
))
12750 /* A padding glyph that doesn't fit on this line.
12751 This means the whole character doesn't fit
12753 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12755 /* Fill the rest of the row with continuation
12756 glyphs like in 20.x. */
12757 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12758 < row
->glyphs
[1 + TEXT_AREA
])
12759 produce_special_glyphs (it
, IT_CONTINUATION
);
12761 row
->continued_p
= 1;
12762 it
->current_x
= x_before
;
12763 it
->continuation_lines_width
+= x_before
;
12765 /* Restore the height to what it was before the
12766 element not fitting on the line. */
12767 it
->max_ascent
= ascent
;
12768 it
->max_descent
= descent
;
12769 it
->max_phys_ascent
= phys_ascent
;
12770 it
->max_phys_descent
= phys_descent
;
12774 /* Display element draws past the right edge of
12775 the window. Restore positions to values
12776 before the element. The next line starts
12777 with current_x before the glyph that could
12778 not be displayed, so that TAB works right. */
12779 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12781 /* Display continuation glyphs. */
12782 if (!FRAME_WINDOW_P (it
->f
))
12783 produce_special_glyphs (it
, IT_CONTINUATION
);
12784 row
->continued_p
= 1;
12787 it
->continuation_lines_width
+= x
;
12788 if (nglyphs
> 1 && i
> 0)
12790 row
->ends_in_middle_of_char_p
= 1;
12791 it
->starts_in_middle_of_char_p
= 1;
12794 /* Restore the height to what it was before the
12795 element not fitting on the line. */
12796 it
->max_ascent
= ascent
;
12797 it
->max_descent
= descent
;
12798 it
->max_phys_ascent
= phys_ascent
;
12799 it
->max_phys_descent
= phys_descent
;
12804 else if (new_x
> it
->first_visible_x
)
12806 /* Increment number of glyphs actually displayed. */
12809 if (x
< it
->first_visible_x
)
12810 /* Glyph is partially visible, i.e. row starts at
12811 negative X position. */
12812 row
->x
= x
- it
->first_visible_x
;
12816 /* Glyph is completely off the left margin of the
12817 window. This should not happen because of the
12818 move_it_in_display_line at the start of
12824 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12825 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12826 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12827 row
->phys_height
= max (row
->phys_height
,
12828 it
->max_phys_ascent
+ it
->max_phys_descent
);
12830 /* End of this display line if row is continued. */
12831 if (row
->continued_p
)
12835 /* Is this a line end? If yes, we're also done, after making
12836 sure that a non-default face is extended up to the right
12837 margin of the window. */
12838 if (ITERATOR_AT_END_OF_LINE_P (it
))
12840 int used_before
= row
->used
[TEXT_AREA
];
12842 /* Add a space at the end of the line that is used to
12843 display the cursor there. */
12844 append_space (it
, 0);
12846 /* Extend the face to the end of the line. */
12847 extend_face_to_end_of_line (it
);
12849 /* Make sure we have the position. */
12850 if (used_before
== 0)
12851 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12853 /* Consume the line end. This skips over invisible lines. */
12854 set_iterator_to_next (it
, 1);
12855 it
->continuation_lines_width
= 0;
12859 /* Proceed with next display element. Note that this skips
12860 over lines invisible because of selective display. */
12861 set_iterator_to_next (it
, 1);
12863 /* If we truncate lines, we are done when the last displayed
12864 glyphs reach past the right margin of the window. */
12865 if (it
->truncate_lines_p
12866 && (FRAME_WINDOW_P (it
->f
)
12867 ? (it
->current_x
>= it
->last_visible_x
)
12868 : (it
->current_x
> it
->last_visible_x
)))
12870 /* Maybe add truncation glyphs. */
12871 if (!FRAME_WINDOW_P (it
->f
))
12875 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
12876 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
12879 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
12881 row
->used
[TEXT_AREA
] = i
;
12882 produce_special_glyphs (it
, IT_TRUNCATION
);
12886 row
->truncated_on_right_p
= 1;
12887 it
->continuation_lines_width
= 0;
12888 reseat_at_next_visible_line_start (it
, 0);
12889 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12890 it
->hpos
= hpos_before
;
12891 it
->current_x
= x_before
;
12896 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12897 at the left window margin. */
12898 if (it
->first_visible_x
12899 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12901 if (!FRAME_WINDOW_P (it
->f
))
12902 insert_left_trunc_glyphs (it
);
12903 row
->truncated_on_left_p
= 1;
12906 /* If the start of this line is the overlay arrow-position, then
12907 mark this glyph row as the one containing the overlay arrow.
12908 This is clearly a mess with variable size fonts. It would be
12909 better to let it be displayed like cursors under X. */
12910 if (MARKERP (Voverlay_arrow_position
)
12911 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12912 && (MATRIX_ROW_START_CHARPOS (row
)
12913 == marker_position (Voverlay_arrow_position
))
12914 && STRINGP (Voverlay_arrow_string
)
12915 && ! overlay_arrow_seen
)
12917 /* Overlay arrow in window redisplay is a bitmap. */
12918 if (!FRAME_WINDOW_P (it
->f
))
12920 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12921 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12922 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12923 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12924 struct glyph
*p2
, *end
;
12926 /* Copy the arrow glyphs. */
12927 while (glyph
< arrow_end
)
12930 /* Throw away padding glyphs. */
12932 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12933 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12939 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12943 overlay_arrow_seen
= 1;
12944 row
->overlay_arrow_p
= 1;
12947 /* Compute pixel dimensions of this line. */
12948 compute_line_metrics (it
);
12950 /* Remember the position at which this line ends. */
12951 row
->end
= it
->current
;
12953 /* Maybe set the cursor. */
12954 if (it
->w
->cursor
.vpos
< 0
12955 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12956 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12957 && cursor_row_p (it
->w
, row
))
12958 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
12960 /* Highlight trailing whitespace. */
12961 if (!NILP (Vshow_trailing_whitespace
))
12962 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
12964 /* Prepare for the next line. This line starts horizontally at (X
12965 HPOS) = (0 0). Vertical positions are incremented. As a
12966 convenience for the caller, IT->glyph_row is set to the next
12968 it
->current_x
= it
->hpos
= 0;
12969 it
->current_y
+= row
->height
;
12972 return row
->displays_text_p
;
12977 /***********************************************************************
12979 ***********************************************************************/
12981 /* Redisplay the menu bar in the frame for window W.
12983 The menu bar of X frames that don't have X toolkit support is
12984 displayed in a special window W->frame->menu_bar_window.
12986 The menu bar of terminal frames is treated specially as far as
12987 glyph matrices are concerned. Menu bar lines are not part of
12988 windows, so the update is done directly on the frame matrix rows
12989 for the menu bar. */
12992 display_menu_bar (w
)
12995 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13000 /* Don't do all this for graphical frames. */
13002 if (!NILP (Vwindow_system
))
13005 #ifdef USE_X_TOOLKIT
13010 if (FRAME_MAC_P (f
))
13014 #ifdef USE_X_TOOLKIT
13015 xassert (!FRAME_WINDOW_P (f
));
13016 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13017 it
.first_visible_x
= 0;
13018 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13019 #else /* not USE_X_TOOLKIT */
13020 if (FRAME_WINDOW_P (f
))
13022 /* Menu bar lines are displayed in the desired matrix of the
13023 dummy window menu_bar_window. */
13024 struct window
*menu_w
;
13025 xassert (WINDOWP (f
->menu_bar_window
));
13026 menu_w
= XWINDOW (f
->menu_bar_window
);
13027 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13029 it
.first_visible_x
= 0;
13030 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13034 /* This is a TTY frame, i.e. character hpos/vpos are used as
13036 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13038 it
.first_visible_x
= 0;
13039 it
.last_visible_x
= FRAME_WIDTH (f
);
13041 #endif /* not USE_X_TOOLKIT */
13043 if (! mode_line_inverse_video
)
13044 /* Force the menu-bar to be displayed in the default face. */
13045 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13047 /* Clear all rows of the menu bar. */
13048 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13050 struct glyph_row
*row
= it
.glyph_row
+ i
;
13051 clear_glyph_row (row
);
13052 row
->enabled_p
= 1;
13053 row
->full_width_p
= 1;
13056 /* Display all items of the menu bar. */
13057 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13058 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13060 Lisp_Object string
;
13062 /* Stop at nil string. */
13063 string
= AREF (items
, i
+ 1);
13067 /* Remember where item was displayed. */
13068 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13070 /* Display the item, pad with one space. */
13071 if (it
.current_x
< it
.last_visible_x
)
13072 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13073 XSTRING (string
)->size
+ 1, 0, 0, -1);
13076 /* Fill out the line with spaces. */
13077 if (it
.current_x
< it
.last_visible_x
)
13078 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13080 /* Compute the total height of the lines. */
13081 compute_line_metrics (&it
);
13086 /***********************************************************************
13088 ***********************************************************************/
13090 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13091 FORCE is non-zero, redisplay mode lines unconditionally.
13092 Otherwise, redisplay only mode lines that are garbaged. Value is
13093 the number of windows whose mode lines were redisplayed. */
13096 redisplay_mode_lines (window
, force
)
13097 Lisp_Object window
;
13102 while (!NILP (window
))
13104 struct window
*w
= XWINDOW (window
);
13106 if (WINDOWP (w
->hchild
))
13107 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13108 else if (WINDOWP (w
->vchild
))
13109 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13111 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13112 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13114 Lisp_Object old_selected_frame
;
13115 struct text_pos lpoint
;
13116 struct buffer
*old
= current_buffer
;
13118 /* Set the window's buffer for the mode line display. */
13119 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13120 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13122 /* Point refers normally to the selected window. For any
13123 other window, set up appropriate value. */
13124 if (!EQ (window
, selected_window
))
13126 struct text_pos pt
;
13128 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13129 if (CHARPOS (pt
) < BEGV
)
13130 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13131 else if (CHARPOS (pt
) > (ZV
- 1))
13132 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13134 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13137 /* Temporarily set up the selected frame. */
13138 old_selected_frame
= selected_frame
;
13139 selected_frame
= w
->frame
;
13141 /* Display mode lines. */
13142 clear_glyph_matrix (w
->desired_matrix
);
13143 if (display_mode_lines (w
))
13146 w
->must_be_updated_p
= 1;
13149 /* Restore old settings. */
13150 selected_frame
= old_selected_frame
;
13151 set_buffer_internal_1 (old
);
13152 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13162 /* Display the mode and/or top line of window W. Value is the number
13163 of mode lines displayed. */
13166 display_mode_lines (w
)
13171 /* These will be set while the mode line specs are processed. */
13172 line_number_displayed
= 0;
13173 w
->column_number_displayed
= Qnil
;
13175 if (WINDOW_WANTS_MODELINE_P (w
))
13177 display_mode_line (w
, MODE_LINE_FACE_ID
,
13178 current_buffer
->mode_line_format
);
13182 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13184 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13185 current_buffer
->header_line_format
);
13193 /* Display mode or top line of window W. FACE_ID specifies which line
13194 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13195 FORMAT is the mode line format to display. Value is the pixel
13196 height of the mode line displayed. */
13199 display_mode_line (w
, face_id
, format
)
13201 enum face_id face_id
;
13202 Lisp_Object format
;
13207 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13208 prepare_desired_row (it
.glyph_row
);
13210 if (! mode_line_inverse_video
)
13211 /* Force the mode-line to be displayed in the default face. */
13212 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13214 /* Temporarily make frame's keyboard the current kboard so that
13215 kboard-local variables in the mode_line_format will get the right
13217 push_frame_kboard (it
.f
);
13218 display_mode_element (&it
, 0, 0, 0, format
);
13219 pop_frame_kboard ();
13221 /* Fill up with spaces. */
13222 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13224 compute_line_metrics (&it
);
13225 it
.glyph_row
->full_width_p
= 1;
13226 it
.glyph_row
->mode_line_p
= 1;
13227 it
.glyph_row
->inverse_p
= 0;
13228 it
.glyph_row
->continued_p
= 0;
13229 it
.glyph_row
->truncated_on_left_p
= 0;
13230 it
.glyph_row
->truncated_on_right_p
= 0;
13232 /* Make a 3D mode-line have a shadow at its right end. */
13233 face
= FACE_FROM_ID (it
.f
, face_id
);
13234 extend_face_to_end_of_line (&it
);
13235 if (face
->box
!= FACE_NO_BOX
)
13237 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13238 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13239 last
->right_box_line_p
= 1;
13242 return it
.glyph_row
->height
;
13246 /* Contribute ELT to the mode line for window IT->w. How it
13247 translates into text depends on its data type.
13249 IT describes the display environment in which we display, as usual.
13251 DEPTH is the depth in recursion. It is used to prevent
13252 infinite recursion here.
13254 FIELD_WIDTH is the number of characters the display of ELT should
13255 occupy in the mode line, and PRECISION is the maximum number of
13256 characters to display from ELT's representation. See
13257 display_string for details. *
13259 Returns the hpos of the end of the text generated by ELT. */
13262 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13265 int field_width
, precision
;
13268 int n
= 0, field
, prec
;
13276 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13280 /* A string: output it and check for %-constructs within it. */
13282 unsigned char *this = XSTRING (elt
)->data
;
13283 unsigned char *lisp_string
= this;
13285 while ((precision
<= 0 || n
< precision
)
13287 && (frame_title_ptr
13288 || it
->current_x
< it
->last_visible_x
))
13290 unsigned char *last
= this;
13292 /* Advance to end of string or next format specifier. */
13293 while ((c
= *this++) != '\0' && c
!= '%')
13296 if (this - 1 != last
)
13298 /* Output to end of string or up to '%'. Field width
13299 is length of string. Don't output more than
13300 PRECISION allows us. */
13302 prec
= strwidth (last
, this - last
);
13303 if (precision
> 0 && prec
> precision
- n
)
13304 prec
= precision
- n
;
13306 if (frame_title_ptr
)
13307 n
+= store_frame_title (last
, 0, prec
);
13309 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
13310 it
, 0, prec
, 0, -1);
13312 else /* c == '%' */
13314 unsigned char *percent_position
= this;
13316 /* Get the specified minimum width. Zero means
13319 while ((c
= *this++) >= '0' && c
<= '9')
13320 field
= field
* 10 + c
- '0';
13322 /* Don't pad beyond the total padding allowed. */
13323 if (field_width
- n
> 0 && field
> field_width
- n
)
13324 field
= field_width
- n
;
13326 /* Note that either PRECISION <= 0 or N < PRECISION. */
13327 prec
= precision
- n
;
13330 n
+= display_mode_element (it
, depth
, field
, prec
,
13331 Vglobal_mode_string
);
13334 unsigned char *spec
13335 = decode_mode_spec (it
->w
, c
, field
, prec
);
13337 if (frame_title_ptr
)
13338 n
+= store_frame_title (spec
, field
, prec
);
13342 = it
->glyph_row
->used
[TEXT_AREA
];
13344 = percent_position
- XSTRING (elt
)->data
;
13346 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
13347 field
, prec
, 0, -1);
13349 /* Assign to the glyphs written above the
13350 string where the `%x' came from, position
13354 struct glyph
*glyph
13355 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13359 for (i
= 0; i
< nwritten
; ++i
)
13361 glyph
[i
].object
= elt
;
13362 glyph
[i
].charpos
= charpos
;
13375 /* A symbol: process the value of the symbol recursively
13376 as if it appeared here directly. Avoid error if symbol void.
13377 Special case: if value of symbol is a string, output the string
13380 register Lisp_Object tem
;
13381 tem
= Fboundp (elt
);
13384 tem
= Fsymbol_value (elt
);
13385 /* If value is a string, output that string literally:
13386 don't check for % within it. */
13389 prec
= precision
- n
;
13390 if (frame_title_ptr
)
13391 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13393 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13396 else if (!EQ (tem
, elt
))
13398 /* Give up right away for nil or t. */
13408 register Lisp_Object car
, tem
;
13410 /* A cons cell: three distinct cases.
13411 If first element is a string or a cons, process all the elements
13412 and effectively concatenate them.
13413 If first element is a negative number, truncate displaying cdr to
13414 at most that many characters. If positive, pad (with spaces)
13415 to at least that many characters.
13416 If first element is a symbol, process the cadr or caddr recursively
13417 according to whether the symbol's value is non-nil or nil. */
13419 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13421 /* An element of the form (:eval FORM) means evaluate FORM
13422 and use the result as mode line elements. */
13423 struct gcpro gcpro1
;
13426 spec
= safe_eval (XCAR (XCDR (elt
)));
13428 n
+= display_mode_element (it
, depth
, field_width
- n
,
13429 precision
- n
, spec
);
13432 else if (SYMBOLP (car
))
13434 tem
= Fboundp (car
);
13438 /* elt is now the cdr, and we know it is a cons cell.
13439 Use its car if CAR has a non-nil value. */
13442 tem
= Fsymbol_value (car
);
13449 /* Symbol's value is nil (or symbol is unbound)
13450 Get the cddr of the original list
13451 and if possible find the caddr and use that. */
13455 else if (!CONSP (elt
))
13460 else if (INTEGERP (car
))
13462 register int lim
= XINT (car
);
13466 /* Negative int means reduce maximum width. */
13467 if (precision
<= 0)
13470 precision
= min (precision
, -lim
);
13474 /* Padding specified. Don't let it be more than
13475 current maximum. */
13477 lim
= min (precision
, lim
);
13479 /* If that's more padding than already wanted, queue it.
13480 But don't reduce padding already specified even if
13481 that is beyond the current truncation point. */
13482 field_width
= max (lim
, field_width
);
13486 else if (STRINGP (car
) || CONSP (car
))
13488 register int limit
= 50;
13489 /* Limit is to protect against circular lists. */
13492 && (precision
<= 0 || n
< precision
))
13494 n
+= display_mode_element (it
, depth
, field_width
- n
,
13495 precision
- n
, XCAR (elt
));
13504 if (frame_title_ptr
)
13505 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13507 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13508 precision
- n
, 0, 0);
13512 /* Pad to FIELD_WIDTH. */
13513 if (field_width
> 0 && n
< field_width
)
13515 if (frame_title_ptr
)
13516 n
+= store_frame_title ("", field_width
- n
, 0);
13518 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13526 /* Write a null-terminated, right justified decimal representation of
13527 the positive integer D to BUF using a minimal field width WIDTH. */
13530 pint2str (buf
, width
, d
)
13531 register char *buf
;
13532 register int width
;
13535 register char *p
= buf
;
13543 *p
++ = d
% 10 + '0';
13548 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13559 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13560 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13561 type of CODING_SYSTEM. Return updated pointer into BUF. */
13563 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13566 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13567 Lisp_Object coding_system
;
13568 register char *buf
;
13572 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13573 unsigned char *eol_str
;
13575 /* The EOL conversion we are using. */
13576 Lisp_Object eoltype
;
13578 val
= Fget (coding_system
, Qcoding_system
);
13581 if (!VECTORP (val
)) /* Not yet decided. */
13586 eoltype
= eol_mnemonic_undecided
;
13587 /* Don't mention EOL conversion if it isn't decided. */
13591 Lisp_Object eolvalue
;
13593 eolvalue
= Fget (coding_system
, Qeol_type
);
13596 *buf
++ = XFASTINT (AREF (val
, 1));
13600 /* The EOL conversion that is normal on this system. */
13602 if (NILP (eolvalue
)) /* Not yet decided. */
13603 eoltype
= eol_mnemonic_undecided
;
13604 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13605 eoltype
= eol_mnemonic_undecided
;
13606 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13607 eoltype
= (XFASTINT (eolvalue
) == 0
13608 ? eol_mnemonic_unix
13609 : (XFASTINT (eolvalue
) == 1
13610 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13616 /* Mention the EOL conversion if it is not the usual one. */
13617 if (STRINGP (eoltype
))
13619 eol_str
= XSTRING (eoltype
)->data
;
13620 eol_str_len
= XSTRING (eoltype
)->size
;
13622 else if (INTEGERP (eoltype
)
13623 && CHAR_VALID_P (XINT (eoltype
), 0))
13625 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13626 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13630 eol_str
= invalid_eol_type
;
13631 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13633 bcopy (eol_str
, buf
, eol_str_len
);
13634 buf
+= eol_str_len
;
13640 /* Return a string for the output of a mode line %-spec for window W,
13641 generated by character C. PRECISION >= 0 means don't return a
13642 string longer than that value. FIELD_WIDTH > 0 means pad the
13643 string returned with spaces to that value. */
13645 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13648 decode_mode_spec (w
, c
, field_width
, precision
)
13651 int field_width
, precision
;
13654 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13655 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13656 struct buffer
*b
= XBUFFER (w
->buffer
);
13663 if (!NILP (b
->read_only
))
13665 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13670 /* This differs from %* only for a modified read-only buffer. */
13671 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13673 if (!NILP (b
->read_only
))
13678 /* This differs from %* in ignoring read-only-ness. */
13679 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13691 if (command_loop_level
> 5)
13693 p
= decode_mode_spec_buf
;
13694 for (i
= 0; i
< command_loop_level
; i
++)
13697 return decode_mode_spec_buf
;
13705 if (command_loop_level
> 5)
13707 p
= decode_mode_spec_buf
;
13708 for (i
= 0; i
< command_loop_level
; i
++)
13711 return decode_mode_spec_buf
;
13718 /* Let lots_of_dashes be a string of infinite length. */
13719 if (field_width
<= 0
13720 || field_width
> sizeof (lots_of_dashes
))
13722 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13723 decode_mode_spec_buf
[i
] = '-';
13724 decode_mode_spec_buf
[i
] = '\0';
13725 return decode_mode_spec_buf
;
13728 return lots_of_dashes
;
13737 int col
= current_column ();
13738 w
->column_number_displayed
= make_number (col
);
13739 pint2str (decode_mode_spec_buf
, field_width
, col
);
13740 return decode_mode_spec_buf
;
13744 /* %F displays the frame name. */
13745 if (!NILP (f
->title
))
13746 return (char *) XSTRING (f
->title
)->data
;
13747 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13748 return (char *) XSTRING (f
->name
)->data
;
13757 int startpos
= XMARKER (w
->start
)->charpos
;
13758 int startpos_byte
= marker_byte_position (w
->start
);
13759 int line
, linepos
, linepos_byte
, topline
;
13761 int height
= XFASTINT (w
->height
);
13763 /* If we decided that this buffer isn't suitable for line numbers,
13764 don't forget that too fast. */
13765 if (EQ (w
->base_line_pos
, w
->buffer
))
13767 /* But do forget it, if the window shows a different buffer now. */
13768 else if (BUFFERP (w
->base_line_pos
))
13769 w
->base_line_pos
= Qnil
;
13771 /* If the buffer is very big, don't waste time. */
13772 if (INTEGERP (Vline_number_display_limit
)
13773 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13775 w
->base_line_pos
= Qnil
;
13776 w
->base_line_number
= Qnil
;
13780 if (!NILP (w
->base_line_number
)
13781 && !NILP (w
->base_line_pos
)
13782 && XFASTINT (w
->base_line_pos
) <= startpos
)
13784 line
= XFASTINT (w
->base_line_number
);
13785 linepos
= XFASTINT (w
->base_line_pos
);
13786 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13791 linepos
= BUF_BEGV (b
);
13792 linepos_byte
= BUF_BEGV_BYTE (b
);
13795 /* Count lines from base line to window start position. */
13796 nlines
= display_count_lines (linepos
, linepos_byte
,
13800 topline
= nlines
+ line
;
13802 /* Determine a new base line, if the old one is too close
13803 or too far away, or if we did not have one.
13804 "Too close" means it's plausible a scroll-down would
13805 go back past it. */
13806 if (startpos
== BUF_BEGV (b
))
13808 w
->base_line_number
= make_number (topline
);
13809 w
->base_line_pos
= make_number (BUF_BEGV (b
));
13811 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13812 || linepos
== BUF_BEGV (b
))
13814 int limit
= BUF_BEGV (b
);
13815 int limit_byte
= BUF_BEGV_BYTE (b
);
13817 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13819 if (startpos
- distance
> limit
)
13821 limit
= startpos
- distance
;
13822 limit_byte
= CHAR_TO_BYTE (limit
);
13825 nlines
= display_count_lines (startpos
, startpos_byte
,
13827 - (height
* 2 + 30),
13829 /* If we couldn't find the lines we wanted within
13830 line_number_display_limit_width chars per line,
13831 give up on line numbers for this window. */
13832 if (position
== limit_byte
&& limit
== startpos
- distance
)
13834 w
->base_line_pos
= w
->buffer
;
13835 w
->base_line_number
= Qnil
;
13839 w
->base_line_number
= make_number (topline
- nlines
);
13840 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
13843 /* Now count lines from the start pos to point. */
13844 nlines
= display_count_lines (startpos
, startpos_byte
,
13845 PT_BYTE
, PT
, &junk
);
13847 /* Record that we did display the line number. */
13848 line_number_displayed
= 1;
13850 /* Make the string to show. */
13851 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13852 return decode_mode_spec_buf
;
13855 char* p
= decode_mode_spec_buf
;
13856 int pad
= field_width
- 2;
13862 return decode_mode_spec_buf
;
13868 obj
= b
->mode_name
;
13872 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13878 int pos
= marker_position (w
->start
);
13879 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13881 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13883 if (pos
<= BUF_BEGV (b
))
13888 else if (pos
<= BUF_BEGV (b
))
13892 if (total
> 1000000)
13893 /* Do it differently for a large value, to avoid overflow. */
13894 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13896 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13897 /* We can't normally display a 3-digit number,
13898 so get us a 2-digit number that is close. */
13901 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13902 return decode_mode_spec_buf
;
13906 /* Display percentage of size above the bottom of the screen. */
13909 int toppos
= marker_position (w
->start
);
13910 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13911 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13913 if (botpos
>= BUF_ZV (b
))
13915 if (toppos
<= BUF_BEGV (b
))
13922 if (total
> 1000000)
13923 /* Do it differently for a large value, to avoid overflow. */
13924 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13926 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13927 /* We can't normally display a 3-digit number,
13928 so get us a 2-digit number that is close. */
13931 if (toppos
<= BUF_BEGV (b
))
13932 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13934 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13935 return decode_mode_spec_buf
;
13940 /* status of process */
13941 obj
= Fget_buffer_process (w
->buffer
);
13943 return "no process";
13944 #ifdef subprocesses
13945 obj
= Fsymbol_name (Fprocess_status (obj
));
13949 case 't': /* indicate TEXT or BINARY */
13950 #ifdef MODE_LINE_BINARY_TEXT
13951 return MODE_LINE_BINARY_TEXT (b
);
13957 /* coding-system (not including end-of-line format) */
13959 /* coding-system (including end-of-line type) */
13961 int eol_flag
= (c
== 'Z');
13962 char *p
= decode_mode_spec_buf
;
13964 if (! FRAME_WINDOW_P (f
))
13966 /* No need to mention EOL here--the terminal never needs
13967 to do EOL conversion. */
13968 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
13969 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
13971 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
13974 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
13975 #ifdef subprocesses
13976 obj
= Fget_buffer_process (Fcurrent_buffer ());
13977 if (PROCESSP (obj
))
13979 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
13981 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
13984 #endif /* subprocesses */
13987 return decode_mode_spec_buf
;
13992 return (char *) XSTRING (obj
)->data
;
13998 /* Count up to COUNT lines starting from START / START_BYTE.
13999 But don't go beyond LIMIT_BYTE.
14000 Return the number of lines thus found (always nonnegative).
14002 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14005 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14006 int start
, start_byte
, limit_byte
, count
;
14009 register unsigned char *cursor
;
14010 unsigned char *base
;
14012 register int ceiling
;
14013 register unsigned char *ceiling_addr
;
14014 int orig_count
= count
;
14016 /* If we are not in selective display mode,
14017 check only for newlines. */
14018 int selective_display
= (!NILP (current_buffer
->selective_display
)
14019 && !INTEGERP (current_buffer
->selective_display
));
14023 while (start_byte
< limit_byte
)
14025 ceiling
= BUFFER_CEILING_OF (start_byte
);
14026 ceiling
= min (limit_byte
- 1, ceiling
);
14027 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14028 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14031 if (selective_display
)
14032 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14035 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14038 if (cursor
!= ceiling_addr
)
14042 start_byte
+= cursor
- base
+ 1;
14043 *byte_pos_ptr
= start_byte
;
14047 if (++cursor
== ceiling_addr
)
14053 start_byte
+= cursor
- base
;
14058 while (start_byte
> limit_byte
)
14060 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14061 ceiling
= max (limit_byte
, ceiling
);
14062 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14063 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14066 if (selective_display
)
14067 while (--cursor
!= ceiling_addr
14068 && *cursor
!= '\n' && *cursor
!= 015)
14071 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14074 if (cursor
!= ceiling_addr
)
14078 start_byte
+= cursor
- base
+ 1;
14079 *byte_pos_ptr
= start_byte
;
14080 /* When scanning backwards, we should
14081 not count the newline posterior to which we stop. */
14082 return - orig_count
- 1;
14088 /* Here we add 1 to compensate for the last decrement
14089 of CURSOR, which took it past the valid range. */
14090 start_byte
+= cursor
- base
+ 1;
14094 *byte_pos_ptr
= limit_byte
;
14097 return - orig_count
+ count
;
14098 return orig_count
- count
;
14104 /***********************************************************************
14106 ***********************************************************************/
14108 /* Display a NUL-terminated string, starting with index START.
14110 If STRING is non-null, display that C string. Otherwise, the Lisp
14111 string LISP_STRING is displayed.
14113 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14114 FACE_STRING. Display STRING or LISP_STRING with the face at
14115 FACE_STRING_POS in FACE_STRING:
14117 Display the string in the environment given by IT, but use the
14118 standard display table, temporarily.
14120 FIELD_WIDTH is the minimum number of output glyphs to produce.
14121 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14122 with spaces. If STRING has more characters, more than FIELD_WIDTH
14123 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14125 PRECISION is the maximum number of characters to output from
14126 STRING. PRECISION < 0 means don't truncate the string.
14128 This is roughly equivalent to printf format specifiers:
14130 FIELD_WIDTH PRECISION PRINTF
14131 ----------------------------------------
14137 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14138 display them, and < 0 means obey the current buffer's value of
14139 enable_multibyte_characters.
14141 Value is the number of glyphs produced. */
14144 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14145 start
, it
, field_width
, precision
, max_x
, multibyte
)
14146 unsigned char *string
;
14147 Lisp_Object lisp_string
;
14148 Lisp_Object face_string
;
14149 int face_string_pos
;
14152 int field_width
, precision
, max_x
;
14155 int hpos_at_start
= it
->hpos
;
14156 int saved_face_id
= it
->face_id
;
14157 struct glyph_row
*row
= it
->glyph_row
;
14159 /* Initialize the iterator IT for iteration over STRING beginning
14160 with index START. */
14161 reseat_to_string (it
, string
, lisp_string
, start
,
14162 precision
, field_width
, multibyte
);
14164 /* If displaying STRING, set up the face of the iterator
14165 from LISP_STRING, if that's given. */
14166 if (STRINGP (face_string
))
14172 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14173 0, it
->region_beg_charpos
,
14174 it
->region_end_charpos
,
14175 &endptr
, it
->base_face_id
, 0);
14176 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14177 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14180 /* Set max_x to the maximum allowed X position. Don't let it go
14181 beyond the right edge of the window. */
14183 max_x
= it
->last_visible_x
;
14185 max_x
= min (max_x
, it
->last_visible_x
);
14187 /* Skip over display elements that are not visible. because IT->w is
14189 if (it
->current_x
< it
->first_visible_x
)
14190 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14191 MOVE_TO_POS
| MOVE_TO_X
);
14193 row
->ascent
= it
->max_ascent
;
14194 row
->height
= it
->max_ascent
+ it
->max_descent
;
14195 row
->phys_ascent
= it
->max_phys_ascent
;
14196 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14198 /* This condition is for the case that we are called with current_x
14199 past last_visible_x. */
14200 while (it
->current_x
< max_x
)
14202 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14204 /* Get the next display element. */
14205 if (!get_next_display_element (it
))
14208 /* Produce glyphs. */
14209 x_before
= it
->current_x
;
14210 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14211 PRODUCE_GLYPHS (it
);
14213 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14216 while (i
< nglyphs
)
14218 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14220 if (!it
->truncate_lines_p
14221 && x
+ glyph
->pixel_width
> max_x
)
14223 /* End of continued line or max_x reached. */
14224 if (CHAR_GLYPH_PADDING_P (*glyph
))
14226 /* A wide character is unbreakable. */
14227 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14228 it
->current_x
= x_before
;
14232 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14237 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14239 /* Glyph is at least partially visible. */
14241 if (x
< it
->first_visible_x
)
14242 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14246 /* Glyph is off the left margin of the display area.
14247 Should not happen. */
14251 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14252 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14253 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14254 row
->phys_height
= max (row
->phys_height
,
14255 it
->max_phys_ascent
+ it
->max_phys_descent
);
14256 x
+= glyph
->pixel_width
;
14260 /* Stop if max_x reached. */
14264 /* Stop at line ends. */
14265 if (ITERATOR_AT_END_OF_LINE_P (it
))
14267 it
->continuation_lines_width
= 0;
14271 set_iterator_to_next (it
, 1);
14273 /* Stop if truncating at the right edge. */
14274 if (it
->truncate_lines_p
14275 && it
->current_x
>= it
->last_visible_x
)
14277 /* Add truncation mark, but don't do it if the line is
14278 truncated at a padding space. */
14279 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14281 if (!FRAME_WINDOW_P (it
->f
))
14285 if (it
->current_x
> it
->last_visible_x
)
14287 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14288 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14290 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14292 row
->used
[TEXT_AREA
] = i
;
14293 produce_special_glyphs (it
, IT_TRUNCATION
);
14296 produce_special_glyphs (it
, IT_TRUNCATION
);
14298 it
->glyph_row
->truncated_on_right_p
= 1;
14304 /* Maybe insert a truncation at the left. */
14305 if (it
->first_visible_x
14306 && IT_CHARPOS (*it
) > 0)
14308 if (!FRAME_WINDOW_P (it
->f
))
14309 insert_left_trunc_glyphs (it
);
14310 it
->glyph_row
->truncated_on_left_p
= 1;
14313 it
->face_id
= saved_face_id
;
14315 /* Value is number of columns displayed. */
14316 return it
->hpos
- hpos_at_start
;
14321 /* This is like a combination of memq and assq. Return 1 if PROPVAL
14322 appears as an element of LIST or as the car of an element of LIST.
14323 If PROPVAL is a list, compare each element against LIST in that
14324 way, and return 1 if any element of PROPVAL is found in LIST.
14325 Otherwise return 0. This function cannot quit. */
14328 invisible_p (propval
, list
)
14329 register Lisp_Object propval
;
14332 register Lisp_Object tail
, proptail
;
14334 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14336 register Lisp_Object tem
;
14338 if (EQ (propval
, tem
))
14340 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14344 if (CONSP (propval
))
14346 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14348 Lisp_Object propelt
;
14349 propelt
= XCAR (proptail
);
14350 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14352 register Lisp_Object tem
;
14354 if (EQ (propelt
, tem
))
14356 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14366 /* Return 1 if PROPVAL appears as the car of an element of LIST and
14367 the cdr of that element is non-nil. If PROPVAL is a list, check
14368 each element of PROPVAL in that way, and the first time some
14369 element is found, return 1 if the cdr of that element is non-nil.
14370 Otherwise return 0. This function cannot quit. */
14373 invisible_ellipsis_p (propval
, list
)
14374 register Lisp_Object propval
;
14377 register Lisp_Object tail
, proptail
;
14379 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14381 register Lisp_Object tem
;
14383 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14384 return ! NILP (XCDR (tem
));
14387 if (CONSP (propval
))
14388 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14390 Lisp_Object propelt
;
14391 propelt
= XCAR (proptail
);
14392 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14394 register Lisp_Object tem
;
14396 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14397 return ! NILP (XCDR (tem
));
14406 /***********************************************************************
14408 ***********************************************************************/
14413 Vwith_echo_area_save_vector
= Qnil
;
14414 staticpro (&Vwith_echo_area_save_vector
);
14416 Vmessage_stack
= Qnil
;
14417 staticpro (&Vmessage_stack
);
14419 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14420 staticpro (&Qinhibit_redisplay
);
14423 defsubr (&Sdump_glyph_matrix
);
14424 defsubr (&Sdump_glyph_row
);
14425 defsubr (&Sdump_tool_bar_row
);
14426 defsubr (&Strace_redisplay
);
14427 defsubr (&Strace_to_stderr
);
14429 #ifdef HAVE_WINDOW_SYSTEM
14430 defsubr (&Stool_bar_lines_needed
);
14433 staticpro (&Qmenu_bar_update_hook
);
14434 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14436 staticpro (&Qoverriding_terminal_local_map
);
14437 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14439 staticpro (&Qoverriding_local_map
);
14440 Qoverriding_local_map
= intern ("overriding-local-map");
14442 staticpro (&Qwindow_scroll_functions
);
14443 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14445 staticpro (&Qredisplay_end_trigger_functions
);
14446 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14448 staticpro (&Qinhibit_point_motion_hooks
);
14449 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14451 QCdata
= intern (":data");
14452 staticpro (&QCdata
);
14453 Qdisplay
= intern ("display");
14454 staticpro (&Qdisplay
);
14455 Qspace_width
= intern ("space-width");
14456 staticpro (&Qspace_width
);
14457 Qraise
= intern ("raise");
14458 staticpro (&Qraise
);
14459 Qspace
= intern ("space");
14460 staticpro (&Qspace
);
14461 Qmargin
= intern ("margin");
14462 staticpro (&Qmargin
);
14463 Qleft_margin
= intern ("left-margin");
14464 staticpro (&Qleft_margin
);
14465 Qright_margin
= intern ("right-margin");
14466 staticpro (&Qright_margin
);
14467 Qalign_to
= intern ("align-to");
14468 staticpro (&Qalign_to
);
14469 QCalign_to
= intern (":align-to");
14470 staticpro (&QCalign_to
);
14471 Qrelative_width
= intern ("relative-width");
14472 staticpro (&Qrelative_width
);
14473 QCrelative_width
= intern (":relative-width");
14474 staticpro (&QCrelative_width
);
14475 QCrelative_height
= intern (":relative-height");
14476 staticpro (&QCrelative_height
);
14477 QCeval
= intern (":eval");
14478 staticpro (&QCeval
);
14479 Qwhen
= intern ("when");
14480 staticpro (&Qwhen
);
14481 QCfile
= intern (":file");
14482 staticpro (&QCfile
);
14483 Qfontified
= intern ("fontified");
14484 staticpro (&Qfontified
);
14485 Qfontification_functions
= intern ("fontification-functions");
14486 staticpro (&Qfontification_functions
);
14487 Qtrailing_whitespace
= intern ("trailing-whitespace");
14488 staticpro (&Qtrailing_whitespace
);
14489 Qimage
= intern ("image");
14490 staticpro (&Qimage
);
14491 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14492 staticpro (&Qmessage_truncate_lines
);
14493 Qgrow_only
= intern ("grow-only");
14494 staticpro (&Qgrow_only
);
14495 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14496 staticpro (&Qinhibit_menubar_update
);
14497 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14498 staticpro (&Qinhibit_eval_during_redisplay
);
14500 last_arrow_position
= Qnil
;
14501 last_arrow_string
= Qnil
;
14502 staticpro (&last_arrow_position
);
14503 staticpro (&last_arrow_string
);
14505 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14506 staticpro (&echo_buffer
[0]);
14507 staticpro (&echo_buffer
[1]);
14509 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14510 staticpro (&echo_area_buffer
[0]);
14511 staticpro (&echo_area_buffer
[1]);
14513 Vmessages_buffer_name
= build_string ("*Messages*");
14514 staticpro (&Vmessages_buffer_name
);
14516 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14517 "Non-nil means highlight trailing whitespace.\n\
14518 The face used for trailing whitespace is `trailing-whitespace'.");
14519 Vshow_trailing_whitespace
= Qnil
;
14521 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14522 "Non-nil means don't actually do any redisplay.\n\
14523 This is used for internal purposes.");
14524 Vinhibit_redisplay
= Qnil
;
14526 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14527 "String (or mode line construct) included (normally) in `mode-line-format'.");
14528 Vglobal_mode_string
= Qnil
;
14530 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14531 "Marker for where to display an arrow on top of the buffer text.\n\
14532 This must be the beginning of a line in order to work.\n\
14533 See also `overlay-arrow-string'.");
14534 Voverlay_arrow_position
= Qnil
;
14536 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14537 "String to display as an arrow. See also `overlay-arrow-position'.");
14538 Voverlay_arrow_string
= Qnil
;
14540 DEFVAR_INT ("scroll-step", &scroll_step
,
14541 "*The number of lines to try scrolling a window by when point moves out.\n\
14542 If that fails to bring point back on frame, point is centered instead.\n\
14543 If this is zero, point is always centered after it moves off frame.\n\
14544 If you want scrolling to always be a line at a time, you should set\n\
14545 `scroll-conservatively' to a large value rather than set this to 1.");
14547 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14548 "*Scroll up to this many lines, to bring point back on screen.\n\
14549 A value of zero means to scroll the text to center point vertically\n\
14551 scroll_conservatively
= 0;
14553 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14554 "*Number of lines of margin at the top and bottom of a window.\n\
14555 Recenter the window whenever point gets within this many lines\n\
14556 of the top or bottom of the window.");
14560 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
14563 DEFVAR_BOOL ("truncate-partial-width-windows",
14564 &truncate_partial_width_windows
,
14565 "*Non-nil means truncate lines in all windows less than full frame wide.");
14566 truncate_partial_width_windows
= 1;
14568 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14569 "nil means display the mode-line/header-line/menu-bar in the default face.\n\
14570 Any other value means to use the appropriate face, `mode-line',\n\
14571 `header-line', or `menu' respectively.\n\
14573 This variable is deprecated; please change the above faces instead.");
14574 mode_line_inverse_video
= 1;
14576 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14577 "*Maximum buffer size for which line number should be displayed.\n\
14578 If the buffer is bigger than this, the line number does not appear\n\
14579 in the mode line. A value of nil means no limit.");
14580 Vline_number_display_limit
= Qnil
;
14582 DEFVAR_INT ("line-number-display-limit-width",
14583 &line_number_display_limit_width
,
14584 "*Maximum line width (in characters) for line number display.\n\
14585 If the average length of the lines near point is bigger than this, then the\n\
14586 line number may be omitted from the mode line.");
14587 line_number_display_limit_width
= 200;
14589 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14590 "*Non-nil means highlight region even in nonselected windows.");
14591 highlight_nonselected_windows
= 0;
14593 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14594 "Non-nil if more than one frame is visible on this display.\n\
14595 Minibuffer-only frames don't count, but iconified frames do.\n\
14596 This variable is not guaranteed to be accurate except while processing\n\
14597 `frame-title-format' and `icon-title-format'.");
14599 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14600 "Template for displaying the title bar of visible frames.\n\
14601 \(Assuming the window manager supports this feature.)\n\
14602 This variable has the same structure as `mode-line-format' (which see),\n\
14603 and is used only on frames for which no explicit name has been set\n\
14604 \(see `modify-frame-parameters').");
14605 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14606 "Template for displaying the title bar of an iconified frame.\n\
14607 \(Assuming the window manager supports this feature.)\n\
14608 This variable has the same structure as `mode-line-format' (which see),\n\
14609 and is used only on frames for which no explicit name has been set\n\
14610 \(see `modify-frame-parameters').");
14612 = Vframe_title_format
14613 = Fcons (intern ("multiple-frames"),
14614 Fcons (build_string ("%b"),
14615 Fcons (Fcons (build_string (""),
14616 Fcons (intern ("invocation-name"),
14617 Fcons (build_string ("@"),
14618 Fcons (intern ("system-name"),
14622 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14623 "Maximum number of lines to keep in the message log buffer.\n\
14624 If nil, disable message logging. If t, log messages but don't truncate\n\
14625 the buffer when it becomes large.");
14626 Vmessage_log_max
= make_number (50);
14628 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14629 "Functions called before redisplay, if window sizes have changed.\n\
14630 The value should be a list of functions that take one argument.\n\
14631 Just before redisplay, for each frame, if any of its windows have changed\n\
14632 size since the last redisplay, or have been split or deleted,\n\
14633 all the functions in the list are called, with the frame as argument.");
14634 Vwindow_size_change_functions
= Qnil
;
14636 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14637 "List of Functions to call before redisplaying a window with scrolling.\n\
14638 Each function is called with two arguments, the window\n\
14639 and its new display-start position. Note that the value of `window-end'\n\
14640 is not valid when these functions are called.");
14641 Vwindow_scroll_functions
= Qnil
;
14643 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14644 "*Non-nil means automatically resize tool-bars.\n\
14645 This increases a tool-bar's height if not all tool-bar items are visible.\n\
14646 It decreases a tool-bar's height when it would display blank lines\n\
14648 auto_resize_tool_bars_p
= 1;
14650 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14651 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
14652 auto_raise_tool_bar_buttons_p
= 1;
14654 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14655 "*Margin around tool-bar buttons in pixels.\n\
14656 If an integer, use that for both horizontal and vertical margins.\n\
14657 Otherwise, value should be a pair of integers `(HORZ : VERT)' with\n\
14658 HORZ specifying the horizontal margin, and VERT specifying the\n\
14659 vertical margin.");
14660 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14662 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14663 "Relief thickness of tool-bar buttons.");
14664 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14666 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14667 "List of functions to call to fontify regions of text.\n\
14668 Each function is called with one argument POS. Functions must\n\
14669 fontify a region starting at POS in the current buffer, and give\n\
14670 fontified regions the property `fontified'.\n\
14671 This variable automatically becomes buffer-local when set.");
14672 Vfontification_functions
= Qnil
;
14673 Fmake_variable_buffer_local (Qfontification_functions
);
14675 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14676 &unibyte_display_via_language_environment
,
14677 "*Non-nil means display unibyte text according to language environment.\n\
14678 Specifically this means that unibyte non-ASCII characters\n\
14679 are displayed by converting them to the equivalent multibyte characters\n\
14680 according to the current language environment. As a result, they are\n\
14681 displayed according to the current fontset.");
14682 unibyte_display_via_language_environment
= 0;
14684 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14685 "*Maximum height for resizing mini-windows.\n\
14686 If a float, it specifies a fraction of the mini-window frame's height.\n\
14687 If an integer, it specifies a number of lines.");
14688 Vmax_mini_window_height
= make_float (0.25);
14690 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14691 "*How to resize mini-windows.\n\
14692 A value of nil means don't automatically resize mini-windows.\n\
14693 A value of t means resize them to fit the text displayed in them.\n\
14694 A value of `grow-only', the default, means let mini-windows grow\n\
14695 only, until their display becomes empty, at which point the windows\n\
14696 go back to their normal size.");
14697 Vresize_mini_windows
= Qgrow_only
;
14699 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14700 &cursor_in_non_selected_windows
,
14701 "*Non-nil means display a hollow cursor in non-selected windows.\n\
14702 Nil means don't display a cursor there.");
14703 cursor_in_non_selected_windows
= 1;
14705 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14706 "*Non-nil means scroll the display automatically to make point visible.");
14707 automatic_hscrolling_p
= 1;
14709 DEFVAR_LISP ("image-types", &Vimage_types
,
14710 "List of supported image types.\n\
14711 Each element of the list is a symbol for a supported image type.");
14712 Vimage_types
= Qnil
;
14714 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14715 "If non-nil, messages are truncated instead of resizing the echo area.\n\
14716 Bind this around calls to `message' to let it take effect.");
14717 message_truncate_lines
= 0;
14719 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14720 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
14721 Can be used to update submenus whose contents should vary.");
14722 Vmenu_bar_update_hook
= Qnil
;
14724 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14725 "Non-nil means don't update menu bars. Internal use only.");
14726 inhibit_menubar_update
= 0;
14728 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
14729 "Non-nil means don't eval Lisp during redisplay.");
14730 inhibit_eval_during_redisplay
= 0;
14734 /* Initialize this module when Emacs starts. */
14739 Lisp_Object root_window
;
14740 struct window
*mini_w
;
14742 current_header_line_height
= current_mode_line_height
= -1;
14744 CHARPOS (this_line_start_pos
) = 0;
14746 mini_w
= XWINDOW (minibuf_window
);
14747 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14749 if (!noninteractive
)
14751 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14754 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
14755 set_window_height (root_window
,
14756 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14758 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
14759 set_window_height (minibuf_window
, 1, 0);
14761 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
14762 mini_w
->width
= make_number (FRAME_WIDTH (f
));
14764 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14765 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14766 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14768 /* The default ellipsis glyphs `...'. */
14769 for (i
= 0; i
< 3; ++i
)
14770 default_invis_vector
[i
] = make_number ('.');
14773 #ifdef HAVE_WINDOW_SYSTEM
14775 /* Allocate the buffer for frame titles. */
14777 frame_title_buf
= (char *) xmalloc (size
);
14778 frame_title_buf_end
= frame_title_buf
+ size
;
14779 frame_title_ptr
= NULL
;
14781 #endif /* HAVE_WINDOW_SYSTEM */
14783 help_echo_showing_p
= 0;